) => string
): string {
const query = result.query || args.query || '';
const filters = result.filters || {};
const totalResults = result.total_results || 0;
const results = result.results || [];
let html = '';
if (results.length > 0) {
html += '';
results.forEach((item: any) => {
html += '
';
html += `
${escapeHtml(item.title || '无标题')}
`;
html += '
';
});
html += '
';
} else {
html += '未返回详细的搜索结果。
';
}
return html;
}
function renderExtractWebpage(result: any, args: any): string {
const url = args.url || result.url || '';
const status = formatToolStatusLabel(result, '✓ 成功');
const content = result.content || result.text || '';
let html = '';
if (content) {
html += '';
html += `
${escapeHtml(content)}`;
html += '
';
}
return html;
}
function renderSaveWebpage(result: any, args: any): string {
const url = args.url || result.url || '';
const path = result.path || args.save_path || '';
const status = formatToolStatusLabel(result, '✓ 已保存');
let html = '';
return html;
}
// 文件编辑类渲染函数
function renderCreateFile(result: any, args: any): string {
const path = args.path || result.path || '';
const status = formatToolStatusLabel(result, '✓ 已创建');
let html = '';
return html;
}
function renderWriteFile(result: any, args: any): string {
const path = args.file_path || args.path || result.path || '';
const status = formatToolStatusLabel(result, '✓ 已写入');
const appendFlag = typeof args.append === 'boolean' ? args.append : null;
const modeRaw = String(result.mode || '').toLowerCase();
const writeMode =
appendFlag === true || modeRaw === 'a'
? '追加'
: appendFlag === false || modeRaw === 'w'
? '覆盖'
: '无';
const content =
appendFlag === true || modeRaw === 'a'
? args.content || ''
: (result.new_file ?? args.content ?? '');
let html = '';
// 显示写入的内容
if (result.success && content) {
html += '';
}
return html;
}
function renderEditFile(result: any, args: any): string {
const path = args.file_path || args.path || result.path || '';
const status = formatToolStatusLabel(result, '✓ 已编辑');
const foundCount =
typeof result.found_matches === 'number'
? result.found_matches
: typeof result.replacements === 'number'
? result.replacements
: null;
const replacedCount = typeof result.replacements === 'number' ? result.replacements : null;
const details = Array.isArray(result.details)
? result.details.filter((d: any) => d && d.status === 'success')
: [];
let html = '';
if (!result.success) {
return html;
}
if (details.length > 0) {
html += '';
}
return html;
}
function renderDeleteFile(result: any, args: any): string {
const path = args.path || result.path || '';
const status = formatToolStatusLabel(result, '✓ 已删除');
let html = '';
return html;
}
function renderRenameFile(result: any, args: any): string {
const oldPath = args.old_path || args.source || result.old_path || '';
const newPath = args.new_path || args.destination || result.new_path || '';
const status = formatToolStatusLabel(result, '✓ 已重命名');
let html = '';
return html;
}
// 阅读聚焦类渲染函数
function renderReadFile(result: any, args: any): string {
const path = args.path || result.path || '';
const status = formatToolStatusLabel(result, '✓ 成功');
const size = result.size || result.file_size || 0;
const readType = result.type || 'read';
let html = '';
// 处理普通读取模式
if (readType === 'read') {
const content = result.content || result.text || '';
if (content) {
html += '';
html += `
${escapeHtml(content)}`;
html += '
';
}
}
// 处理搜索模式
else if (readType === 'search') {
const matches = result.matches || [];
const query = result.query || args.query || '';
if (query) {
html += '';
}
if (matches.length > 0) {
html += '';
matches.forEach((match: any, idx: number) => {
if (idx > 0) html += '
⋯
';
html += '
';
const lineLabel = match.line_start === match.line_end ? `${match.line_start}` : `${match.line_start}-${match.line_end}`;
html += `
行 ${lineLabel}
`;
html += `
${escapeHtml(match.snippet || match.content || '')}`;
html += '
';
});
html += '
';
} else {
html += '未找到匹配内容
';
}
}
// 处理提取模式
else if (readType === 'extract') {
const segments = result.segments || [];
if (segments.length > 0) {
html += '';
html += '';
segments.forEach((segment: any, idx: number) => {
if (idx > 0) html += '
⋯
';
html += '
';
const startLine = segment.start_line || segment.line_start || '?';
const endLine = segment.end_line || segment.line_end || '?';
html += `
行 ${startLine}-${endLine}
`;
html += `
${escapeHtml(segment.content || segment.text || '')}`;
html += '
';
});
html += '
';
} else {
html += '未提取到内容
';
}
}
return html;
}
function renderVlmAnalyze(result: any, args: any): string {
const path = args.image_path || args.path || result.path || '';
const status = formatToolStatusLabel(result, '✓ 成功');
const analysis = result.analysis || result.result || '';
let html = '';
if (analysis) {
html += '';
html += '
分析结果:
';
html += `
${escapeHtml(analysis)}`;
html += '
';
}
return html;
}
function renderOcrImage(result: any, args: any): string {
const path = args.image_path || args.path || result.path || '';
const status = formatToolStatusLabel(result, '✓ 成功');
const size = result.size || result.file_size || 0;
const text = result.text || result.ocr_text || '';
const imageUrl = result.image_url || result.url || '';
let html = '';
if (imageUrl) {
html += ``;
}
if (text) {
html += '';
html += '
识别文本:
';
html += `
${escapeHtml(text)}`;
html += '
';
}
return html;
}
function renderViewImage(result: any, args: any): string {
const path = args.image_path || args.path || result.path || '';
const status = formatToolStatusLabel(result, '✓ 成功');
const size = result.size || result.file_size || 0;
const imageUrl = result.image_url || result.url || '';
let html = '';
if (imageUrl) {
html += ``;
}
return html;
}
// 终端类渲染函数
function renderTerminalSession(result: any, args: any): string {
const operation = args.operation || args.action || 'start';
const sessionName = args.session_name || args.name || result.session_name || '';
const status = formatToolStatusLabel(result, '✓ 成功');
let html = '';
return html;
}
function renderTerminalInput(result: any, args: any): string {
const command = args.command || args.input || '';
const outputWait = args.output_wait || 30;
const output = result.output || result.result || '';
let html = '';
if (output) {
html += '';
html += '
输出:
';
html += `
${escapeHtml(output)}`;
html += '
';
}
return html;
}
function renderTerminalSnapshot(result: any, args: any): string {
const sessionName = args.session_name || args.name || result.session_name || '';
const status = formatToolStatusLabel(result, '✓ 成功');
const startLine = args.start_line || 0;
const endLine = args.end_line || 0;
const content = result.content || result.output || '';
let html = '';
if (content) {
html += '';
html += '
获取的内容:
';
html += `
${escapeHtml(content)}`;
html += '
';
}
return html;
}
function renderSleep(result: any, args: any): string {
const seconds = args.seconds || args.duration || 0;
const status = formatToolStatusLabel(result, '✓ 完成');
let html = '';
return html;
}
// 终端指令类渲染函数
function renderRunCommand(result: any, args: any): string {
const command = args.command || '';
const timeout = args.timeout || 30;
const output = result.output || result.stdout || '';
const exitCode = result.exit_code !== undefined ? result.exit_code : result.returncode;
let html = '';
if (output) {
html += '';
html += '
输出:
';
html += `
${escapeHtml(output)}`;
html += '
';
}
return html;
}
// 记忆类渲染函数
function renderUpdateMemory(result: any, args: any): string {
const operation = args.operation || result.operation || '';
const content = args.content || '';
const index = args.index || result.index;
const count = result.count || 0;
let html = '';
return html;
}
function renderRecallProjectMemory(result: any, args: any): string {
const name = args.name || result.memory_name || '';
const status = formatToolStatusLabel(result, '✓ 已读取');
const content = result.content || result.text || '';
let html = '';
if (result.success && content) {
html += '';
html += `
${escapeHtml(content)}`;
html += '
';
} else if (!result.success && result.error) {
html += `${escapeHtml(String(result.error))}
`;
}
return html;
}
function renderUpdateProjectMemory(result: any, args: any): string {
const name = args.name || result.memory_name || '';
const description = args.description || '';
const content = args.content || '';
const status = formatToolStatusLabel(result, '✓ 已更新');
let html = '';
if (result.success && content) {
html += '';
html += '
记忆内容:
';
html += `
${escapeHtml(content)}`;
html += '
';
}
return html;
}
function renderConversationSearch(result: any, args: any): string {
const results = Array.isArray(result?.results) ? result.results : [];
const keywords = Array.isArray(result?.keywords)
? result.keywords
: (Array.isArray(args?.keywords) ? args.keywords : []);
const keywordText = keywords.length
? keywords.join(' / ')
: (result?.query || args?.query || '(未指定)');
let html = '';
if (!results.length) {
html += '未找到匹配对话。
';
return html;
}
html += '';
results.forEach((item: any) => {
html += '
';
html += `
${escapeHtml(item.title || '未命名对话')}
`;
html += `
ID:${escapeHtml(item.id || '')}
`;
html += `
规模:${escapeHtml(String(item.total_messages || 0))} 条消息,${escapeHtml(String(item.total_tools || 0))} 个工具
`;
if (item.first_user_message) {
html += `
首条用户消息:${escapeHtml(item.first_user_message)}
`;
}
if (item.updated_at) {
html += `
更新时间:${escapeHtml(item.updated_at)}
`;
}
html += '
';
});
html += '
';
return html;
}
function renderConversationReview(result: any, args: any): string {
const status = formatToolStatusLabel(result, result?.mode === 'read' ? '✓ 已返回' : '✓ 已生成');
let html = '';
if (!result?.success && result?.error) {
html += `${escapeHtml(result.error)}
`;
}
if (result?.too_long && result?.path) {
html += '内容太长,已保存到文件,请分段或查找阅读。
';
}
if (result?.content) {
html += '';
html += '
回顾内容:
';
html += `
${escapeHtml(result.content)}`;
html += '
';
}
return html;
}
function renderCreateSkill(result: any, args: any): string {
const status = formatToolStatusLabel(result, '✓ 已归档');
let html = '';
if (!result?.success && result?.error) {
html += `${escapeHtml(result.error)}
`;
}
if (result?.sync_warning) {
html += `${escapeHtml(result.sync_warning)}
`;
}
return html;
}
function formatPersonalizationFieldLabel(field: string): string {
const labelMap: Record = {
self_identify: 'AI 自称',
user_name: '用户称呼',
profession: '用户职业',
tone: '交流语气',
considerations: '注意事项',
theme: '主题',
communication_style: '交流风格',
conversation_continuity: '对话连续性',
enabled: '个性化开关'
};
return labelMap[field] || field;
}
function formatPersonalizationFieldValue(field: string, value: any): string {
if (value === null || value === undefined || value === '') {
return '未设置';
}
if (field === 'enabled') {
return value ? '开启' : '关闭';
}
if (field === 'considerations') {
if (!Array.isArray(value) || value.length === 0) {
return '未设置';
}
return value.map((item) => String(item)).join('、');
}
if (field === 'communication_style') {
const styleMap: Record = {
default: 'default(标准 AI 风格)',
human_like: 'human_like(拟人聊天风格)',
auto: 'auto(自动)'
};
return styleMap[String(value)] || String(value);
}
if (field === 'conversation_continuity') {
const independenceMap: Record = {
low: 'low(低)',
medium: 'medium(中)',
high: 'high(高)'
};
return independenceMap[String(value)] || String(value);
}
return String(value);
}
function renderAskUser(result: any, args: any): string {
const question = args.question || result.question || '';
const context = args.context || result.context || '';
const status = formatToolStatusLabel(result, '✓ 已回答');
const answerText = result.status === 'answered' ? String(result.answer_text || result.message || '').trim() : '';
let html = '';
const options = Array.isArray(args.options) ? args.options : [];
if (options.length > 0) {
html += '';
}
if (answerText) {
html += '';
}
return html;
}
function renderManagePersonalization(result: any, args: any): string {
const action = String(args.action || result.action || 'read');
const status = formatToolStatusLabel(result, action === 'update' ? '✓ 已更新' : '✓ 已读取');
const field = String(result.updated_field || args.field || '');
const newValue = result.updated_value ?? args.value;
let html = '';
return html;
}
if (action === 'update' && field) {
html += `修改项:${escapeHtml(formatPersonalizationFieldLabel(field))}
`;
html += `修改后:${escapeHtml(formatPersonalizationFieldValue(field, newValue))}
`;
}
html += '';
return html;
}
// 待办事项类渲染函数
function renderTodoCreate(result: any, args: any): string {
const status = formatToolStatusLabel(result, '✓ 已创建');
const todoList = result.todo_list || {};
const title = todoList.title || args.title || '';
const tasks = todoList.tasks || args.tasks || [];
let html = '';
if (tasks.length > 0) {
html += '';
html += '
';
tasks.forEach((task: any) => {
const taskText =
typeof task === 'string' ? task : task.text || task.title || task.content || '';
html += `
${escapeHtml(taskText)}
`;
});
html += '
';
html += '
';
}
return html;
}
function renderTodoUpdate(result: any): string {
const status = formatToolStatusLabel(result, '✓ 已更新');
const todoList = result.todo_list || {};
const title = todoList.title || '';
const tasks = todoList.tasks || [];
let html = '';
if (tasks.length > 0) {
html += '';
html += '
';
tasks.forEach((task: any) => {
const taskText =
typeof task === 'string' ? task : task.text || task.title || task.content || '';
const completed =
typeof task === 'object' &&
(task.status === 'done' || task.completed || task.done || task.checked);
html += `
${escapeHtml(taskText)}
`;
});
html += '
';
html += '
';
}
return html;
}
// 彩蛋类渲染函数
function renderEasterEgg(result: any, args: any): string {
const status = formatToolStatusLabel(result, '✓ 已触发');
const type = result.type || args.type || '';
const content = result.content || result.message || '';
let html = '';
if (content) {
html += '';
html += `
${escapeHtml(content)}
`;
html += '
';
}
return html;
}
// 子智能体类渲染函数
function renderCreateSubAgent(result: any, args: any): string {
const status = formatToolStatusLabel(result, '✓ 已创建', '✗ 创建失败');
const agentId = result.agent_id ?? args.agent_id ?? '';
const taskId = result.task_id ?? '';
const deliverablesDir = result.deliverables_dir ?? '';
const taskDescription = args.task ?? '';
const message = result.message ?? result.summary ?? '';
const stats = result.stats || {};
const runtimeSeconds = result.runtime_seconds ?? result.elapsed_seconds ?? stats.runtime_seconds ?? 0;
const apiCalls = stats.api_calls ?? stats.turn_count ?? 0;
const toolCount =
(stats.files_read || 0) +
(stats.write_files || 0) +
(stats.edit_files || 0) +
(stats.searches || 0) +
(stats.web_pages || 0) +
(stats.commands || 0);
const hasStats = runtimeSeconds > 0 || apiCalls > 0 || toolCount > 0;
let html = '';
if (message || hasStats) {
html += '';
if (hasStats) {
html += '
执行统计
';
if (runtimeSeconds > 0) {
html += `
工作时间:${formatDuration(runtimeSeconds)}
`;
}
if (apiCalls > 0) {
html += `
调用次数:${apiCalls} 次
`;
}
if (toolCount > 0) {
html += `
工具次数:${toolCount} 次
`;
}
}
if (message) {
if (hasStats) {
html += '
最终回复
';
}
html += `
${escapeHtml(String(message))}
`;
}
html += '
';
}
return html;
}
function renderTerminateSubAgent(result: any, args: any): string {
const status = formatToolStatusLabel(result, '✓ 已关闭', '✗ 关闭失败');
const agentId = result.agent_id ?? args.agent_id ?? '';
const taskId = result.task_id ?? '';
const message = result.message ?? result.system_message ?? '';
let html = '';
if (message) {
html += '';
html += `
${escapeHtml(String(message))}
`;
html += '
';
}
return html;
}
function renderGetSubAgentStatus(result: any, args: any): string {
if (!result.success) {
const error = result.error ?? '查询失败';
return `⚠️ ${escapeHtml(String(error))}
`;
}
const results = Array.isArray(result.results) ? result.results : [];
if (results.length === 0) {
return '未返回子智能体状态。
';
}
let html = '';
results.forEach((item: any) => {
const agentId = item.agent_id ?? '';
const found = item.found !== false;
const status = String(item.status || '');
const taskId = item.task_id ?? '';
const summary = item.summary ?? (item.final_result?.message) ?? (item.final_result?.summary) ?? '';
html += '
';
html += ``;
if (!found) {
html += '
';
} else {
html += '
';
if (summary) {
html += '
';
html += `
${escapeHtml(String(summary))}
`;
html += '
';
}
}
html += '
';
});
html += '
';
return html;
}