fix: 消除会话列表解析阻塞并按需加载工具详情

This commit is contained in:
shiyue
2026-10-19 10:58:22 +08:00
parent fb2c3360c9
commit 99cc807f4b
35 changed files with 1468 additions and 214 deletions

View File

@@ -0,0 +1,38 @@
'use strict';
const crypto = require('node:crypto');
function toolSignature(tool) {
return crypto.createHash('sha256').update(JSON.stringify(tool)).digest('hex');
}
function inlineTool(tool) {
const kind = tool?.kind || tool?.meta?.kind;
const name = String(tool?.name || '');
const target = String(tool?.input?.tool || tool?.input?.name || tool?.meta?.subtitle || '');
return ['todo_list', 'collab_agent_tool_call', 'subAgentActivity'].includes(kind)
|| ['AskUserQuestion', 'subAgentActivity'].includes(name)
|| /(?:^|[./])ccweb_display_image$/.test(target);
}
// 折叠工具只传显示摘要;原始输入、输出仍由详情接口完整读取。
function summarizeTools(tools, reference) {
return (Array.isArray(tools) ? tools : []).map((tool, index) => {
if (!tool || typeof tool !== 'object' || inlineTool(tool)) return tool;
const input = {};
for (const key of ['command', 'path', 'file_path', 'tool', 'name', 'kind']) {
if (typeof tool.input?.[key] === 'string') input[key] = tool.input[key].slice(0, 240);
}
const meta = {};
for (const key of ['title', 'subtitle', 'kind', 'exitCode', 'status']) {
const value = tool.meta?.[key];
if (typeof value === 'string') meta[key] = value.slice(0, 240);
else if (typeof value === 'number' || typeof value === 'boolean') meta[key] = value;
}
return { id: tool.id, name: tool.name, kind: tool.kind, done: tool.done, input, meta,
detailRef: { ...reference, index, toolId: tool.id || null,
...(reference.scope ? {} : { signature: toolSignature(tool) }) } };
});
}
module.exports = { summarizeTools, toolSignature };