feat(agents): 完善恢复费用与云资源交互

This commit is contained in:
2026-09-10 22:29:24 +08:00
parent f8f39f39de
commit 303f26294e
24 changed files with 1170 additions and 127 deletions

View File

@@ -1,11 +1,18 @@
import { hostApiFetch, createHostEventSource, ensureHostApiToken } from './host-api';
import type { CloudAgentOperations, CloudUpload, CloudKnowledgeFile } from '../../shared/cloud-agents';
import type { CloudAgentOperations, CloudUpload, CloudKnowledgeFile, CloudRecoveryState, CloudRecent, CloudSkillDraft } 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) =>
recovery: () => hostApiFetch<CloudRecoveryState>(CLOUD_AGENTS_PATH + '/recovery'),
remember: (recent: CloudRecent | null) => hostApiFetch(CLOUD_AGENTS_PATH + '/recovery/recent', {
method: 'PUT', body: JSON.stringify(recent),
}),
resolvePending: (id: string, discard = false) => hostApiFetch<{ result?: unknown; operation?: string; input?: Record<string, unknown>; discarded?: boolean }>(
CLOUD_AGENTS_PATH + '/recovery/pending', { method: 'POST', body: JSON.stringify({ id, discard }) }),
uploadSkill: () => hostApiFetch<CloudSkillDraft | null>(CLOUD_AGENTS_PATH + '/skills/pick', { method: 'POST' }),
uploadKnowledge: (slug: string, kb_id: string, operation_id: string, replaces_file_id?: string) =>
hostApiFetch<CloudKnowledgeFile | null>(CLOUD_AGENTS_PATH + '/knowledge/pick', {
method: 'POST', body: JSON.stringify({ slug, kb_id, operation_id }),
method: 'POST', body: JSON.stringify({ slug, kb_id, operation_id, replaces_file_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', {
@@ -19,8 +26,8 @@ export const cloudAgentsApi = {
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)}` : ''),
list: (cursor: string | null = null, archived = false) => hostApiFetch<CloudAgentPage>(
CLOUD_AGENTS_PATH + '/agents' + ((cursor || archived) ? '?' + new URLSearchParams({ ...(cursor ? { cursor } : {}), ...(archived ? { archived: 'true' } : {}) }) : ''),
),
get: (slug: string) => hostApiFetch<CloudAgentDraft>(`${CLOUD_AGENTS_PATH}/agents/${encodeURIComponent(slug)}`),
create: (input: CreateCloudAgent) => hostApiFetch<CloudAgentDraft>(CLOUD_AGENTS_PATH + '/agents', {