071faa482c
纳入 AGC Cargo workspace 的统一 rustfmt 检查与格式化入口 完成项目 TypeScript/Prettier 与 Rust 全量格式化 修复 Pingora expected executable 门禁的空白敏感误报 同步开发运维文档与 AGC skill pack 格式化忽略规则
104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import type {
|
|
ExternalGenerationJobStatus,
|
|
ExternalGenerationJobStatusResponse,
|
|
ExternalGenerationQueueOverviewResponse,
|
|
ExternalGenerationTaskAcknowledgeRequest,
|
|
ExternalGenerationTaskAcknowledgeResponse,
|
|
ExternalGenerationTaskListResponse,
|
|
} from '../../../packages/shared/src/contracts/externalGeneration';
|
|
import { BACKGROUND_AUTH_REQUEST_OPTIONS, requestJson } from '../apiClient';
|
|
|
|
const EXTERNAL_GENERATION_API_BASE = '/api/runtime/external-generation';
|
|
const EXTERNAL_GENERATION_READ_OPTIONS = {
|
|
...BACKGROUND_AUTH_REQUEST_OPTIONS,
|
|
retry: {
|
|
maxRetries: 1,
|
|
baseDelayMs: 200,
|
|
maxDelayMs: 600,
|
|
},
|
|
} as const;
|
|
|
|
export async function getExternalGenerationQueueOverview(signal?: AbortSignal) {
|
|
return requestJson<ExternalGenerationQueueOverviewResponse>(
|
|
`${EXTERNAL_GENERATION_API_BASE}/queue-overview`,
|
|
{
|
|
method: 'GET',
|
|
signal,
|
|
},
|
|
'读取生成队列状态失败',
|
|
EXTERNAL_GENERATION_READ_OPTIONS,
|
|
);
|
|
}
|
|
|
|
export async function getExternalGenerationJobStatus(
|
|
jobId: string,
|
|
signal?: AbortSignal,
|
|
) {
|
|
return requestJson<ExternalGenerationJobStatusResponse>(
|
|
`${EXTERNAL_GENERATION_API_BASE}/jobs/${encodeURIComponent(jobId)}`,
|
|
{
|
|
method: 'GET',
|
|
signal,
|
|
},
|
|
'读取生成任务状态失败',
|
|
EXTERNAL_GENERATION_READ_OPTIONS,
|
|
);
|
|
}
|
|
|
|
export async function listExternalGenerationTasks(
|
|
options: {
|
|
limit?: number;
|
|
includeAcknowledgedTerminal?: boolean;
|
|
statuses?: ExternalGenerationJobStatus[];
|
|
signal?: AbortSignal;
|
|
} = {},
|
|
) {
|
|
const params = new URLSearchParams();
|
|
if (typeof options.limit === 'number') {
|
|
params.set('limit', String(options.limit));
|
|
}
|
|
if (typeof options.includeAcknowledgedTerminal === 'boolean') {
|
|
params.set(
|
|
'includeAcknowledgedTerminal',
|
|
options.includeAcknowledgedTerminal ? 'true' : 'false',
|
|
);
|
|
}
|
|
if (options.statuses?.length) {
|
|
params.set('statuses', options.statuses.join(','));
|
|
}
|
|
const query = params.toString();
|
|
return requestJson<ExternalGenerationTaskListResponse>(
|
|
`${EXTERNAL_GENERATION_API_BASE}/jobs${query ? `?${query}` : ''}`,
|
|
{
|
|
method: 'GET',
|
|
signal: options.signal,
|
|
},
|
|
'读取生成任务列表失败',
|
|
EXTERNAL_GENERATION_READ_OPTIONS,
|
|
);
|
|
}
|
|
|
|
export async function acknowledgeExternalGenerationTasks(
|
|
payload: ExternalGenerationTaskAcknowledgeRequest,
|
|
signal?: AbortSignal,
|
|
) {
|
|
return requestJson<ExternalGenerationTaskAcknowledgeResponse>(
|
|
`${EXTERNAL_GENERATION_API_BASE}/jobs/acknowledge`,
|
|
{
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
signal,
|
|
},
|
|
'确认生成任务通知失败',
|
|
EXTERNAL_GENERATION_READ_OPTIONS,
|
|
);
|
|
}
|
|
|
|
export const externalGenerationClient = {
|
|
getQueueOverview: getExternalGenerationQueueOverview,
|
|
getJobStatus: getExternalGenerationJobStatus,
|
|
listTasks: listExternalGenerationTasks,
|
|
acknowledgeTasks: acknowledgeExternalGenerationTasks,
|
|
};
|