v1.2.1: 修复交互选项渲染并增强答复输入体验

修复 AskUserQuestion 选项在 Web 端无法展示的问题,补齐前后端结构化数据处理,并支持点击选项一键填充输入框,提升交互效率。
This commit is contained in:
Daniel
2026-03-09 12:36:04 +00:00
parent e3337c8d1b
commit b24a3c74b2
4 changed files with 199 additions and 9 deletions

View File

@@ -1155,7 +1155,8 @@ function processClaudeEvent(entry, event, sessionId) {
entry.fullText += block.text;
wsSend(entry.ws, { type: 'text_delta', text: block.text });
} else if (block.type === 'tool_use') {
const tc = { name: block.name, id: block.id, input: truncateObj(block.input, 500), done: false };
const toolInput = sanitizeToolInput(block.name, block.input);
const tc = { name: block.name, id: block.id, input: toolInput, done: false };
entry.toolCalls.push(tc);
wsSend(entry.ws, { type: 'tool_start', name: block.name, toolUseId: block.id, input: tc.input });
} else if (block.type === 'tool_result') {
@@ -1202,6 +1203,29 @@ function truncateObj(obj, maxLen) {
return s.slice(0, maxLen) + '...';
}
function safeJsonParse(input) {
if (input === null || input === undefined) return input;
if (typeof input !== 'string') return input;
const trimmed = input.trim();
if (!trimmed) return input;
if (!((trimmed.startsWith('{') && trimmed.endsWith('}')) || (trimmed.startsWith('[') && trimmed.endsWith(']')))) {
return input;
}
try {
return JSON.parse(trimmed);
} catch {
return input;
}
}
function sanitizeToolInput(toolName, input) {
const parsed = safeJsonParse(input);
if (toolName === 'AskUserQuestion') {
return parsed;
}
return truncateObj(parsed, 500);
}
// === Startup ===
recoverProcesses();