feat(agent): 抽屉与会话页统一成一个对话界面,子会话在父会话里实时可见
- 抽屉和会话页渲染同一套 GoalComposer / AgentRunPanel;抽屉标题即最近会话切换, 头部只有新对话、在页面打开、关闭;去掉右下角悬浮按钮和最小化小窗 - 会话列表合一:对话与巡检混排带类型小标签,搜索 + 一个状态下拉,只列顶层会话 (GET /agent/runs?roots=true,新增可选参数) - 子会话卡片:由镜像的 subagent_* 事件折成,显示任务、状态、当前步骤、用时、调用次数、费用, 可展开看过程、可打开;顶部「N 个子会话运行中」跳到卡片;subagent_completed 加可选 durationMs - 回答去内部字段:汇报规则禁止照抄键值与字段表;展示层 stripInternalFields 把字段行 / 字段表移进技术信息 - 开场建议按页面给 2 条完整问法、点了直接发;指令只留 /先给方案,/重跑 改成「重新运行」按钮 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
1 parent
dd0f6e2c09
commit
3692793dff
35 files changed
+1454
-1137
No files matched your search
@@ -33,6 +33,7 @@ export type StreamItem =
|
||||
| { kind: "compaction"; key: string; at: string; reason: string; status: string | null; done: boolean }
|
||||
| { kind: "options"; key: string; at: string; view: OptionsView }
|
||||
| { kind: "approval"; key: string; at: string; view: ApprovalView }
|
||||
| { kind: "subagent"; key: string; at: string; view: SubagentView }
|
||||
| {
|
||||
kind: "end";
|
||||
key: string;
|
||||
@@ -75,6 +76,28 @@ export type ApprovalView = {
|
||||
resolved: { status: string; reason: string | null; decidedBy: string | null } | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 一个子会话(subagent_spawned + 镜像的 subagent_event + subagent_completed):父会话事件流里就有,
|
||||
* 不用另读子会话。状态在镜像结束前按运行中算;会话页再用快照里的子会话状态(等待、已停止)校正。
|
||||
*/
|
||||
export type SubagentView = {
|
||||
childRunId: string;
|
||||
goal: string;
|
||||
startedAt: string;
|
||||
endedAt: string | null;
|
||||
/** subagent_completed 的状态(agent_run.status);没结束为 null */
|
||||
status: string | null;
|
||||
/** 正在调用的能力(最近一次 tool_call_start 还没有对应的 end) */
|
||||
currentTool: string | null;
|
||||
/** 已结束的工具调用数(失败的算,被拒绝的不算) */
|
||||
toolCalls: number;
|
||||
usage: AgentUsageTotals | null;
|
||||
/** 结束时的汇报摘要 */
|
||||
summary: string | null;
|
||||
/** 可选:运行时长(毫秒);没有时按起止时间算 */
|
||||
durationMs: number | null;
|
||||
};
|
||||
|
||||
export type AgentStreamState = {
|
||||
events: AgentRunEvent[];
|
||||
items: StreamItem[];
|
||||
@@ -103,6 +126,7 @@ export function foldEvents(events: AgentRunEvent[]): StreamItem[] {
|
||||
const tools = new Map<string, ToolCallView>();
|
||||
const asks = new Map<string, OptionsView>();
|
||||
const approvals = new Map<string, ApprovalView>();
|
||||
const subs = new Map<string, SubagentView & { open: Set<string> }>();
|
||||
for (const e of events) {
|
||||
const last = items[items.length - 1];
|
||||
if (
|
||||
@@ -255,6 +279,60 @@ export function foldEvents(events: AgentRunEvent[]): StreamItem[] {
|
||||
if (v) v.resolved = { status: e.status, reason: e.reason, decidedBy: e.decidedBy };
|
||||
break;
|
||||
}
|
||||
case "subagent_spawned": {
|
||||
if (subs.has(e.childRunId)) break;
|
||||
const view = {
|
||||
childRunId: e.childRunId,
|
||||
goal: e.goal,
|
||||
startedAt: e.at,
|
||||
endedAt: null,
|
||||
status: null,
|
||||
currentTool: null,
|
||||
toolCalls: 0,
|
||||
usage: null,
|
||||
summary: null,
|
||||
durationMs: null,
|
||||
open: new Set<string>(),
|
||||
};
|
||||
subs.set(e.childRunId, view);
|
||||
items.push({ kind: "subagent", key: `sa${e.childRunId}`, at: e.at, view });
|
||||
break;
|
||||
}
|
||||
case "subagent_event": {
|
||||
const v = subs.get(e.childRunId);
|
||||
if (!v) break;
|
||||
// 镜像事件只带能力 ID,没有 toolCallId:同一能力的开始 / 结束按次数配对
|
||||
const cap = e.capabilityId ?? "";
|
||||
if (e.childType === "tool_call_start" && cap) {
|
||||
v.open.add(`${cap}#${e.childSeq}`);
|
||||
v.currentTool = cap;
|
||||
} else if (e.childType === "tool_call_end" || e.childType === "tool_call_rejected") {
|
||||
const hit = [...v.open].find((k) => k.startsWith(`${cap}#`));
|
||||
if (hit) v.open.delete(hit);
|
||||
if (e.childType === "tool_call_end") v.toolCalls++;
|
||||
const last = [...v.open].at(-1);
|
||||
v.currentTool = last ? last.slice(0, last.lastIndexOf("#")) : null;
|
||||
} else if (e.childType === "run_completed" || e.childType === "run_failed") {
|
||||
v.open.clear();
|
||||
v.currentTool = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "subagent_completed": {
|
||||
const v = subs.get(e.childRunId);
|
||||
if (!v) break;
|
||||
Object.assign(v, {
|
||||
status: e.status,
|
||||
endedAt: e.at,
|
||||
currentTool: null,
|
||||
toolCalls: Math.max(v.toolCalls, e.toolCalls),
|
||||
usage: e.usage,
|
||||
summary: e.summary || null,
|
||||
durationMs: e.durationMs ?? null,
|
||||
});
|
||||
v.open.clear();
|
||||
break;
|
||||
}
|
||||
case "run_completed":
|
||||
items.push({
|
||||
kind: "end",
|
||||
|
||||
Reference in new issue
Block a user