新增: 无人值守P0任务边界全链
- 任务级授权边界判定与审批旁路单点插桩 - boundary_json 随会话落库(V45 可逆迁移) - 六路非正常终局统一安全停靠与托盘通知 - 每五轮进度事件与会话头部进度条 - 前端边界配置卡侧栏徽标及 UX 校验补齐
This commit is contained in:
+23
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||
import type { AiChatEvent, AiConversationDetail, AiConversationSummary, AiProviderConfig, AiToolMeta, ContentPart, MentionSpan, ModelConfig, SkillInfo } from './types'
|
||||
import type { AiChatEvent, AiConversationDetail, AiConversationSummary, AiProviderConfig, AiToolMeta, ContentPart, MentionSpan, ModelConfig, SkillInfo, TaskBoundary } from './types'
|
||||
|
||||
export const aiApi = {
|
||||
/**
|
||||
@@ -112,6 +112,19 @@ export const aiApi = {
|
||||
return invoke('ai_pending_tool_calls', { conversationId })
|
||||
},
|
||||
|
||||
// ── 无人值守任务边界(设计 §2.3):发起时一次授权,存续期生效,随会话同亡 ──
|
||||
|
||||
/** 读取会话任务边界(配置卡回显/侧栏徽标)。无边界返回 null(幂等读不报错) */
|
||||
getTaskBoundary(conversationId: string): Promise<TaskBoundary | null> {
|
||||
return invoke('ai_task_boundary_get', { conversationId })
|
||||
},
|
||||
|
||||
/** 设置会话任务边界。boundary 传 null = 清除,回退逐次审批;
|
||||
* 后端把 risk_ceiling=high 钳到 medium;对话未落库时内存即生效,首条消息落库随行 */
|
||||
setTaskBoundary(conversationId: string, boundary: TaskBoundary | null): Promise<void> {
|
||||
return invoke('ai_task_boundary_set', { conversationId, boundary })
|
||||
},
|
||||
|
||||
/** 清空对话 */
|
||||
clearChat(): Promise<void> {
|
||||
return invoke('ai_chat_clear')
|
||||
@@ -378,6 +391,15 @@ export const aiApi = {
|
||||
return invoke('ai_conversation_peek', { conversationId })
|
||||
},
|
||||
|
||||
/**
|
||||
* 按父会话反查子代理轨迹精简元数据(P2-2 完成卡回补数据源,只读无副作用)。
|
||||
* 后端按 origin='sub_agent' + id 前缀约定过滤,created_at 升序(轨迹时间线序)。
|
||||
* 重启/分离窗回收后内存完成卡清零,经此按父 conv 重建卡片入口。
|
||||
*/
|
||||
listSubAgents(conversationId: string): Promise<{ conversation_id: string; title: string | null; created_at: string }[]> {
|
||||
return invoke('ai_sub_agent_list', { conversationId })
|
||||
},
|
||||
|
||||
/**
|
||||
* S4 TaskDrawer「关联会话」:按任务 id 反查发起过 create/update/advance_task 的会话。
|
||||
* 后端从 ai_tool_executions 审计表推导(result JSON 顶层 id 精确判等,非 LIKE),
|
||||
|
||||
@@ -480,6 +480,19 @@ export type AiChatEvent = ({
|
||||
// 前端渲染求助卡显 reason + options 按钮供用户选,与 AiApprovalRequired(工具执行前审批)/
|
||||
// AiMaxRoundsReached(达 max 被动截断)语义区分——求助=AI 主动「我搞不定」。
|
||||
type: 'AiHelpRequired'; reason: string; context: string; options: string[]
|
||||
} | {
|
||||
// 无人值守安全停靠(设计 §四,挂起家族终局):六路非正常终局(审批超时取消/挂起后取消/
|
||||
// 熔断/预算耗尽/Fatal/流中断)统一出口。语义:现场已保存、generating 已复位(非死等),reason 即
|
||||
// 待办清单(停止原因+被拒操作提示),前端渲染停靠操作卡(继续续跑/停止归档)。
|
||||
// stop_kind 词表(后端契约钉死,复用 AiAgentFinished 词表扩展):approval_timeout / cancelled /
|
||||
// circuit_breaker / stall_breaker / max_rounds / fatal / midstream;后端新增变体时前端未知值中性兜底。
|
||||
type: 'AiTaskParked'; reason: string; stop_kind?: string
|
||||
} | {
|
||||
// 无人值守进度可观测(设计 §4.3):后端主 loop 每 5 轮 emit,长任务静默期(子代理长跑/
|
||||
// 大工具执行/重入退避)可见「在干活」。round 1 起算;max_rounds=0=不限轮次(进度条只显轮次
|
||||
// 与 token,不显分母)。事件即逝,前端 per-conv Map 存最近快照,终局(AiCompleted/AiError/
|
||||
// AiHelpRequired/AiTaskParked)与会话删除时清理。
|
||||
type: 'AiTaskProgress'; round: number; max_rounds: number; tokens_used: number
|
||||
} | {
|
||||
// L2 统一状态机(批2 1b/1c):ConvState 经 AiChatEvent 推前端,供 status union 消费。
|
||||
// conv_state 值为 idle|generating|stopping|error|compressed(snake_case,对齐后端 ConvState serde)。
|
||||
@@ -806,6 +819,30 @@ export interface AiToolMeta {
|
||||
risk: 'low' | 'medium' | 'high'
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 无人值守长任务(设计 docs/02-架构设计/专项设计/无人值守长任务-设计-2026-10-04.md §二/§2.3)
|
||||
// 与后端 commands/ai/boundary.rs 严格对齐,snake_case 原样不做转译
|
||||
// ============================================================
|
||||
|
||||
/** 任务预算(对齐后端 boundary::TaskBudget;null/缺省=不限,继承后端默认量纲) */
|
||||
export interface TaskBudget {
|
||||
max_rounds: number
|
||||
max_tokens: number
|
||||
wall_secs: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务级授权边界(挂会话,随会话同亡;发起时一次声明,存续期内 AI 全自主)。
|
||||
* risk_ceiling serde lowercase;入口只允许 low/medium(后端 set 把 high 钳到 medium)。
|
||||
* forbid_destructive 恒 true 仅展示,后端判定不读本字段。
|
||||
*/
|
||||
export interface TaskBoundary {
|
||||
risk_ceiling: 'low' | 'medium' | 'high'
|
||||
dir_allowlist: string[]
|
||||
forbid_destructive: boolean
|
||||
budget: TaskBudget | null
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 知识库
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user