diff --git a/src/main/resources/static/js/chat.js b/src/main/resources/static/js/chat.js index 8af69ea..831bacb 100644 --- a/src/main/resources/static/js/chat.js +++ b/src/main/resources/static/js/chat.js @@ -326,16 +326,73 @@ function createAssistantMessageWithoutLoading() { // 添加 TodoWrite 工具调用展示 function appendTodoWriteCall(arguments) { - const todoCallDiv = document.createElement('div'); - todoCallDiv.className = 'todo-write-call'; + try { + // 解析参数中的 todos + let todos = []; + if (typeof arguments === 'string') { + const data = JSON.parse(arguments); + todos = data.todos || []; + } else if (arguments.todos) { + todos = arguments.todos; + } - const headerDiv = document.createElement('div'); - headerDiv.className = 'todo-write-header'; - headerDiv.innerHTML = '📋 创建任务列表'; + if (todos.length === 0) { + // 如果无法解析,显示简单标题 + const todoCallDiv = document.createElement('div'); + todoCallDiv.className = 'todo-write-call'; + const headerDiv = document.createElement('div'); + headerDiv.className = 'todo-write-header'; + headerDiv.innerHTML = '📋 任务列表'; + todoCallDiv.appendChild(headerDiv); + messagesContainer.appendChild(todoCallDiv); + scrollToBottom(); + return; + } - todoCallDiv.appendChild(headerDiv); - messagesContainer.appendChild(todoCallDiv); - scrollToBottom(); + // 创建任务列表展示 + const todoCallDiv = document.createElement('div'); + todoCallDiv.className = 'todo-write-call'; + + const headerDiv = document.createElement('div'); + headerDiv.className = 'todo-write-header'; + headerDiv.innerHTML = '📋 任务列表'; + + // 任务列表 + const todoListDiv = document.createElement('div'); + todoListDiv.className = 'todo-list'; + + todos.forEach(todo => { + const todoItem = document.createElement('div'); + todoItem.className = `todo-item todo-${todo.status}`; + + let statusIcon = '[ ]'; + if (todo.status === 'completed') { + statusIcon = '[✓]'; + } else if (todo.status === 'in_progress') { + statusIcon = '[→]'; + } + + todoItem.innerHTML = `${statusIcon} ${todo.content}`; + todoListDiv.appendChild(todoItem); + }); + + todoCallDiv.appendChild(headerDiv); + todoCallDiv.appendChild(todoListDiv); + messagesContainer.appendChild(todoCallDiv); + scrollToBottom(); + + } catch (error) { + console.error('解析 TodoWrite 参数失败:', error); + // 降级到简单展示 + const todoCallDiv = document.createElement('div'); + todoCallDiv.className = 'todo-write-call'; + const headerDiv = document.createElement('div'); + headerDiv.className = 'todo-write-header'; + headerDiv.innerHTML = '📋 任务列表'; + todoCallDiv.appendChild(headerDiv); + messagesContainer.appendChild(todoCallDiv); + scrollToBottom(); + } } // 添加 TodoWrite 进度展示