feat(agents): 完成云智能体工作台与交互流程

This commit is contained in:
2026-09-10 19:25:12 +08:00
parent 46fbae9dec
commit 64a3cf4934
26 changed files with 1955 additions and 49 deletions

View File

@@ -1,7 +1,24 @@
import { hostApiFetch } from './host-api';
import { hostApiFetch, createHostEventSource, ensureHostApiToken } from './host-api';
import type { CloudAgentOperations, CloudUpload, CloudKnowledgeFile } from '../../shared/cloud-agents';
import { CLOUD_AGENTS_PATH, type CloudAgentDraft, type CloudAgentPage, type CreateCloudAgent, type SaveCloudAgentDraft } from '../../shared/cloud-agents';
export const cloudAgentsApi = {
uploadKnowledge: (slug: string, kb_id: string, operation_id: string) =>
hostApiFetch<CloudKnowledgeFile | null>(CLOUD_AGENTS_PATH + '/knowledge/pick', {
method: 'POST', body: JSON.stringify({ slug, kb_id, operation_id }),
}),
upload: () => hostApiFetch<CloudUpload | null>(CLOUD_AGENTS_PATH + '/attachments/pick', { method: 'POST' }),
download: (thread_id: string, path: string) => hostApiFetch<{ saved: boolean }>(CLOUD_AGENTS_PATH + '/files/save', {
method: 'POST', body: JSON.stringify({ thread_id, path }),
}),
call: <K extends keyof CloudAgentOperations>(operation: K, input: CloudAgentOperations[K]['input']) =>
hostApiFetch<CloudAgentOperations[K]['output']>(CLOUD_AGENTS_PATH + '/actions', {
method: 'POST', body: JSON.stringify({ operation, input }),
}),
events: async (runId: string, after = '0-0') => {
await ensureHostApiToken();
return createHostEventSource(CLOUD_AGENTS_PATH + '/runs/' + encodeURIComponent(runId) + '/events?after_seq=' + encodeURIComponent(after));
},
list: (cursor: string | null = null) => hostApiFetch<CloudAgentPage>(
CLOUD_AGENTS_PATH + '/agents' + (cursor ? `?cursor=${encodeURIComponent(cursor)}` : ''),
),