From 84b90d1e66ba297ce0d4b812f60b3656ba0bf3dc Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 23 十月 2026 17:01:18 +0800
Subject: [PATCH] feat(ai): 更新AI功能配置和数据补录界面

---
 src/api/agent/conversation.ts |  317 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 317 insertions(+), 0 deletions(-)

diff --git a/src/api/agent/conversation.ts b/src/api/agent/conversation.ts
index 9ecd557..8c173ab 100644
--- a/src/api/agent/conversation.ts
+++ b/src/api/agent/conversation.ts
@@ -68,6 +68,38 @@
     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 {
@@ -138,6 +170,7 @@
     revision?: number;
     issues?: Issue[];
     warnings?: Issue[];
+    repair_guidance?: Array<{ field?: string; guidance: string }>;
     summary?: Summary;
     can_commit?: boolean;
     side_effects?: string[];
@@ -176,6 +209,12 @@
     warnings: unknown[];
   }
 
+  export interface ConversationAttachment {
+    attachment_id: string;
+    /** 浠呮渶鏂伴檮浠惰В鏋愬嚭鏂囦欢鍚嶏紱鍘嗗彶闄勪欢鍙兘涓虹┖銆� */
+    filename: string;
+  }
+
   export interface Conversation {
     conversation_id: string;
     title: string;
@@ -183,6 +222,9 @@
     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;
@@ -192,6 +234,9 @@
     warnings: Issue[];
     missing_fields: string[];
     columns: string[];
+    /** 鍊欓�夎瀹為檯鏈夊�肩殑瀛楁锛岀敤浜庢覆鏌撴槑缁嗚〃銆� */
+    row_fields: Array<{ name: string; label: string }>;
+    attachments: ConversationAttachment[];
     messages: Message[];
     interrupts: Interrupt[];
     /** 鏈彁浜ゆ椂鍚庣杩斿洖绌哄璞� {}锛屾彁浜ゅ悗鎵嶆湁瀹屾暣鍥炴墽銆� */
@@ -223,11 +268,40 @@
     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 {
@@ -235,17 +309,177 @@
     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(`浠诲姟浜嬩欢杩炴帴澶辫触锛圚TTP ${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;
 }
 
 /** 浼氳瘽鍒楄〃 */
@@ -275,6 +509,89 @@
   );
 }
 
+/** 鍒犻櫎浼氳瘽锛氬悓鏃舵竻鐞嗘鏌ョ偣銆佷簨浠朵笌 Java 渚цˉ褰曢檮浠� */
+export function deleteAgentConversation(conversationId: string) {
+  return agentClient.delete<{
+    attachments_deleted: number;
+    conversation_id: string;
+    deleted: boolean;
+  }>(`/v1/conversations/${conversationId}`);
+}
+
+/**
+ * 璇诲彇浼氳瘽闄勪欢銆俶ode 涓� 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銆侲ventSource 涓嶈兘璁剧疆 Authorization锛屼笉鑳界敤浜庢湰鎺ュ彛銆�
+ * 鏈嶅姟绔細涓诲姩缁撴潫鐭繛鎺ワ紱璋冪敤鏂硅礋璐f惡甯﹁繑鍥炴父鏍囬噸杩炪��
+ */
+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(`浜嬩欢杩炴帴澶辫触锛圚TTP ${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,

--
Gitblit v1.9.3