| | |
| | | import_modes: string[]; |
| | | notes: string[]; |
| | | modules: ModuleSpec[]; |
| | | durable_tasks?: { |
| | | enabled: boolean; |
| | | events: string; |
| | | fact_source: string; |
| | | transport: string; |
| | | }; |
| | | } |
| | | |
| | | export interface AuthorizedCapability { |
| | | tool: string; |
| | | module: string; |
| | | operation: string; |
| | | allowed_fields: string[]; |
| | | scope_summary: string; |
| | | can_execute: boolean; |
| | | } |
| | | |
| | | export interface AuthorizedCapabilityCatalog { |
| | | policy_revision: string; |
| | | authorization_scope: string; |
| | | scope_summary: string; |
| | | capabilities: AuthorizedCapability[]; |
| | | } |
| | | |
| | | export interface BusinessModelInfo { |
| | | id: number; |
| | | name: string; |
| | | model: string; |
| | | platform: string; |
| | | temperature?: number | null; |
| | | max_tokens?: number | null; |
| | | max_contexts?: number | null; |
| | | } |
| | | |
| | | export interface Issue { |
| | |
| | | revision?: number; |
| | | issues?: Issue[]; |
| | | warnings?: Issue[]; |
| | | repair_guidance?: Array<{ field?: string; guidance: string }>; |
| | | summary?: Summary; |
| | | can_commit?: boolean; |
| | | side_effects?: string[]; |
| | |
| | | warnings: unknown[]; |
| | | } |
| | | |
| | | export interface ConversationAttachment { |
| | | attachment_id: string; |
| | | /** 仅最新附件解析出文件名;历史附件可能为空。 */ |
| | | filename: string; |
| | | } |
| | | |
| | | export interface Conversation { |
| | | conversation_id: string; |
| | | title: string; |
| | |
| | | module_id: string; |
| | | module_title: string; |
| | | capability: string; |
| | | data_scope_summary: string; |
| | | model_id?: number | null; |
| | | policy_revision: string; |
| | | revision: number; |
| | | validation_revision?: number | null; |
| | | sync_mes?: boolean; |
| | |
| | | warnings: Issue[]; |
| | | missing_fields: string[]; |
| | | columns: string[]; |
| | | /** 候选行实际有值的字段,用于渲染明细表。 */ |
| | | row_fields: Array<{ name: string; label: string }>; |
| | | attachments: ConversationAttachment[]; |
| | | messages: Message[]; |
| | | interrupts: Interrupt[]; |
| | | /** 未提交时后端返回空对象 {},提交后才有完整回执。 */ |
| | |
| | | page_size: number; |
| | | } |
| | | |
| | | export interface ConversationEvent { |
| | | conversation_id: string; |
| | | payload: Record<string, unknown>; |
| | | seq: number; |
| | | type: |
| | | | 'card' |
| | | | 'error' |
| | | | 'message' |
| | | | 'progress' |
| | | | 'receipt' |
| | | | 'resync' |
| | | | 'status'; |
| | | } |
| | | |
| | | export interface CreateReq { |
| | | title?: string; |
| | | text?: string; |
| | | attachment_id?: string; |
| | | module_id?: string; |
| | | model_id?: number; |
| | | constraints?: ConversationConstraints; |
| | | } |
| | | |
| | | export interface ConversationConstraints { |
| | | scenario_paths: string[]; |
| | | time_start?: string; |
| | | time_end?: string; |
| | | record_limit?: number; |
| | | industry?: string; |
| | | skip_rest_days?: boolean; |
| | | rest_day_description?: string; |
| | | region?: string; |
| | | instruction?: string; |
| | | priority_fields: string[]; |
| | | } |
| | | |
| | | export interface ActionReq { |
| | |
| | | revision: number; |
| | | action: string; |
| | | payload: Record<string, unknown>; |
| | | model_id?: number; |
| | | } |
| | | |
| | | export interface MessageReq { |
| | | text?: string; |
| | | attachment_id?: string; |
| | | model_id?: number; |
| | | } |
| | | } |
| | | |
| | | export namespace AgentTaskApi { |
| | | export interface Progress { |
| | | mode: 'determinate' | 'indeterminate'; |
| | | completed: number; |
| | | total: null | number; |
| | | percent: null | number; |
| | | unit?: string; |
| | | } |
| | | |
| | | export interface Result { |
| | | attachment_id?: number; |
| | | attachment_ids?: number[]; |
| | | candidate_count?: number; |
| | | continuation_supported?: boolean; |
| | | evidence_ref?: { |
| | | backend: string; |
| | | candidate_count?: number; |
| | | revision: string; |
| | | task_id: string; |
| | | } | null; |
| | | filename?: string; |
| | | filenames?: string[]; |
| | | module_id?: string; |
| | | module_title?: string; |
| | | result_kind?: string; |
| | | source_sha256?: string; |
| | | source_sha256s?: string[]; |
| | | review_summary?: { |
| | | conflict_groups: number; |
| | | exact_duplicates_merged: number; |
| | | incomplete_keys: number; |
| | | requires_review: boolean; |
| | | }; |
| | | warnings?: string[]; |
| | | } |
| | | |
| | | export interface Task { |
| | | task_id: string; |
| | | owner_id: string; |
| | | kind: string; |
| | | status: string; |
| | | stage: string; |
| | | attempt: number; |
| | | sequence: number; |
| | | progress: Progress; |
| | | message: string; |
| | | result: null | Result; |
| | | error: null | { code?: string; message?: string }; |
| | | allowed_actions: string[]; |
| | | created_at: null | string; |
| | | updated_at: null | string; |
| | | started_at: null | string; |
| | | finished_at: null | string; |
| | | } |
| | | |
| | | export interface PageResult { |
| | | items: Task[]; |
| | | total: number; |
| | | page: number; |
| | | page_size: number; |
| | | } |
| | | |
| | | export interface CreateReq { |
| | | attachment_id?: number; |
| | | attachment_ids?: number[]; |
| | | module_id?: string; |
| | | constraints?: AgentConversationApi.ConversationConstraints; |
| | | } |
| | | } |
| | | |
| | | /** 能力声明:支持的格式、模块与限制 */ |
| | | export function getAgentCapabilities() { |
| | | return agentClient.get<AgentConversationApi.Capabilities>('/v1/capabilities'); |
| | | } |
| | | |
| | | /** 读取当前登录用户经 Java 后端裁剪后的可查询、可操作能力。 */ |
| | | export function getAuthorizedAgentCapabilities() { |
| | | return agentClient.get<AgentConversationApi.AuthorizedCapabilityCatalog>( |
| | | '/v1/authorization/capabilities', |
| | | ); |
| | | } |
| | | |
| | | /** 当前数据补录链路实际使用的业务模型;不返回 API 密钥或服务地址。 */ |
| | | export function getActiveBusinessModel() { |
| | | return agentClient.get<AgentConversationApi.BusinessModelInfo>('/v1/model'); |
| | | } |
| | | |
| | | /** 可切换的业务模型列表,按后端排序返回,默认使用第一个。 */ |
| | | export function getAgentModels() { |
| | | return agentClient.get<AgentConversationApi.BusinessModelInfo[]>('/v1/models'); |
| | | } |
| | | |
| | | /** 分页读取当前用户的持久后台任务。 */ |
| | | export function listAgentTasks(params?: { |
| | | page?: number; |
| | | page_size?: number; |
| | | status?: string; |
| | | }) { |
| | | return agentClient.get<AgentTaskApi.PageResult>('/v1/tasks', { params }); |
| | | } |
| | | |
| | | /** 创建文档后台分析任务,服务端立即返回 HTTP 202 快照。 */ |
| | | export function createDocumentTask(data: AgentTaskApi.CreateReq) { |
| | | return agentClient.post<AgentTaskApi.Task>('/v1/tasks/document-onboarding', data); |
| | | } |
| | | |
| | | /** 读取任务事实快照。 */ |
| | | export function getAgentTask(taskId: string) { |
| | | return agentClient.get<AgentTaskApi.Task>(`/v1/tasks/${taskId}`); |
| | | } |
| | | |
| | | /** 取消任务并撤销短期委托票据。 */ |
| | | export function cancelAgentTask(taskId: string) { |
| | | return agentClient.delete<AgentTaskApi.Task>(`/v1/tasks/${taskId}`); |
| | | } |
| | | |
| | | /** 使用认证请求读取任务 SSE;游标用于断线续传。 */ |
| | | export async function streamAgentTaskEvents( |
| | | taskId: string, |
| | | since: number, |
| | | signal: AbortSignal, |
| | | onEvent: (event: AgentTaskApi.Task) => void, |
| | | ) { |
| | | const token = useAccessStore().accessToken; |
| | | const response = await fetch( |
| | | `/agent-api/v1/tasks/${encodeURIComponent(taskId)}/events?since=${since}`, |
| | | { |
| | | credentials: 'same-origin', |
| | | headers: { |
| | | Accept: 'text/event-stream', |
| | | ...(token ? { Authorization: `Bearer ${token}` } : {}), |
| | | }, |
| | | signal, |
| | | }, |
| | | ); |
| | | if (!response.ok) throw new Error(`任务事件连接失败(HTTP ${response.status})`); |
| | | if (!response.body) throw new Error('当前浏览器不支持流式事件'); |
| | | const reader = response.body.getReader(); |
| | | const decoder = new TextDecoder(); |
| | | let buffer = ''; |
| | | let cursor = since; |
| | | while (true) { |
| | | const { done, value } = await reader.read(); |
| | | buffer += decoder.decode(value, { stream: !done }).replaceAll('\r\n', '\n'); |
| | | const frames = buffer.split('\n\n'); |
| | | buffer = frames.pop() ?? ''; |
| | | for (const frame of frames) { |
| | | const data = frame |
| | | .split('\n') |
| | | .filter((line) => line.startsWith('data:')) |
| | | .map((line) => line.slice(5).trimStart()) |
| | | .join('\n'); |
| | | if (!data) continue; |
| | | const event = JSON.parse(data) as AgentTaskApi.Task; |
| | | if (!Number.isSafeInteger(event.sequence) || event.sequence <= cursor) continue; |
| | | cursor = event.sequence; |
| | | onEvent(event); |
| | | } |
| | | if (done) break; |
| | | } |
| | | return cursor; |
| | | } |
| | | |
| | | /** 会话列表 */ |
| | |
| | | ); |
| | | } |
| | | |
| | | /** 删除会话:同时清理检查点、事件与 Java 侧补录附件 */ |
| | | export function deleteAgentConversation(conversationId: string) { |
| | | return agentClient.delete<{ |
| | | attachments_deleted: number; |
| | | conversation_id: string; |
| | | deleted: boolean; |
| | | }>(`/v1/conversations/${conversationId}`); |
| | | } |
| | | |
| | | /** |
| | | * 读取会话附件。mode 为 inline 时 PDF/图片由浏览器直接预览, |
| | | * 其余类型服务端会自动降级为下载。 |
| | | */ |
| | | export function downloadAgentConversationAttachment( |
| | | conversationId: string, |
| | | attachmentId: string, |
| | | mode: 'download' | 'inline', |
| | | ) { |
| | | return agentClient.download<{ |
| | | data: Blob; |
| | | headers: Record<string, string>; |
| | | }>(`/v1/conversations/${conversationId}/attachment`, { |
| | | params: { attachment_id: attachmentId, mode }, |
| | | responseReturn: 'raw', |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 使用 fetch 读取带认证头的 SSE。EventSource 不能设置 Authorization,不能用于本接口。 |
| | | * 服务端会主动结束短连接;调用方负责携带返回游标重连。 |
| | | */ |
| | | export async function streamAgentConversationEvents( |
| | | conversationId: string, |
| | | since: number, |
| | | signal: AbortSignal, |
| | | onEvent: (event: AgentConversationApi.ConversationEvent) => void, |
| | | onOpen?: () => void, |
| | | ) { |
| | | const token = useAccessStore().accessToken; |
| | | const response = await fetch( |
| | | `/agent-api/v1/conversations/${encodeURIComponent(conversationId)}/events?since=${since}`, |
| | | { |
| | | credentials: 'same-origin', |
| | | headers: { |
| | | Accept: 'text/event-stream', |
| | | ...(token ? { Authorization: `Bearer ${token}` } : {}), |
| | | }, |
| | | signal, |
| | | }, |
| | | ); |
| | | if (!response.ok) { |
| | | throw new Error(`事件连接失败(HTTP ${response.status})`); |
| | | } |
| | | if (!response.body) { |
| | | throw new Error('当前浏览器不支持流式事件'); |
| | | } |
| | | onOpen?.(); |
| | | const reader = response.body.getReader(); |
| | | const decoder = new TextDecoder(); |
| | | let buffer = ''; |
| | | let cursor = since; |
| | | while (true) { |
| | | const { done, value } = await reader.read(); |
| | | buffer += decoder.decode(value, { stream: !done }).replaceAll('\r\n', '\n'); |
| | | const frames = buffer.split('\n\n'); |
| | | buffer = frames.pop() ?? ''; |
| | | for (const frame of frames) { |
| | | const data = frame |
| | | .split('\n') |
| | | .filter((line) => line.startsWith('data:')) |
| | | .map((line) => line.slice(5).trimStart()) |
| | | .join('\n'); |
| | | if (!data) continue; |
| | | const event = JSON.parse(data) as AgentConversationApi.ConversationEvent; |
| | | if (!Number.isSafeInteger(event.seq) || event.seq <= cursor) continue; |
| | | cursor = event.seq; |
| | | onEvent(event); |
| | | } |
| | | if (done) break; |
| | | } |
| | | return cursor; |
| | | } |
| | | |
| | | /** 发送文本或附件(用于补充上传文件) */ |
| | | export function sendAgentMessage( |
| | | conversationId: string, |