feat(agent): 助手交互 - 优化推理展示、工具分组与审批反馈

This commit is contained in:
ddCat committed 2026-09-15 13:38:31 +08:00
1 parent 788a298004
commit eb7344f92a
10 files changed
+457 -38

No files matched your search

@@ -41,7 +41,7 @@ function fieldLabel(key: string, nodeType: string): string {
}
function operation(value: unknown): AgentApprovalPreviewOperation | null {
return value === "add_node" || value === "update_node" || value === "connect_nodes" || value === "generate_media" ? value : null;
return value === "add_node" || value === "update_node" || value === "connect_nodes" || value === "generate_media" || value === "create_storyboard" || value === "edit_storyboard" ? value : null;
}
function normalizeServerPreview(value: unknown): AgentApprovalPresentation | null {
@@ -127,4 +127,4 @@ export function agentApprovalPresentation(detail: unknown): AgentApprovalPresent
if (name === "canvas_apply_ops") return canvasFallback(args);
if (name === "generate_media") return mediaFallback(args, payload);
return { source: "fallback", kind: "agent_approval", title: "确认执行操作", description: "Agent 请求执行一项操作,但审批参数无法识别;请重新读取画布后再申请审批。", items: [] };
}
}
@@ -7,6 +7,42 @@ export const AGENT_TOOL_METADATA: Record<string, { summary: string | ((context:
generate_media: { summary: ({ pending, detail }) => pending ? "准备创建媒体节点并生成" : field(detail, "eventType") === "tool_completed" ? "生成结果已回写画布节点" : "媒体节点已创建,生成任务已提交", failureMessage: "媒体生成未完成" },
};
export type AgentToolCategory = "read" | "create" | "operate";
function record(value: unknown): Record<string, unknown> {
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
}
function toolArguments(detail?: unknown) {
const value = record(detail).arguments;
if (typeof value !== "string") return record(value);
try { return record(JSON.parse(value)); } catch { return {}; }
}
/**
* Keeps the activity feed semantic instead of presenting every tool call as
* the same check-mark row. This is intentionally based on the tool contract,
* not on translated copy, so the visual grouping remains stable as messages
* change or get localized.
*/
export function agentToolCategory(toolName: string, detail?: unknown): AgentToolCategory {
if (["canvas_get_state", "canvas_list_node_types", "model_list", "task_get", "skills_load", "skill_read_file"].includes(toolName)) return "read";
if (toolName === "generate_media") return "create";
if (toolName === "canvas_apply_ops") {
const actions = record(detail).actions;
if (Array.isArray(actions) && actions.some((item) => record(item).action === "created" || record(item).action === "generating")) return "create";
const ops = toolArguments(detail).ops;
if (Array.isArray(ops) && ops.some((item) => record(item).type === "add_node")) return "create";
}
return "operate";
}
export function agentToolCategoryLabel(toolName: string, category: AgentToolCategory): string {
if (category === "read") return toolName === "canvas_get_state" ? "读取节点" : "读取信息";
if (category === "create") return "创建节点";
return "操作画布";
}
type ToolStatus = "completed" | "failed" | "noop" | "rejected" | "pending";
function field(value: unknown, key: string): unknown {