fix: 修复 TodoWrite 嵌套结构解析问题
问题:
- TodoWrite 返回的结构是 {todos: {todos: [...]}}
- 之前的代码只处理了 {todos: [...]} 格式
修复:
- 同时支持嵌套结构和直接数组两种格式
- appendTodoWriteCall 和 appendTodoWriteProgress 都已更新
- 添加详细的错误处理和降级逻辑
新增文档:
- DEMO_GUIDE.md: 完整的功能演示指南
- 包含所有功能的详细演示步骤
- 视觉效果说明和最佳实践
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b431eff477
commit
0a05f42774
2 files changed
+694
-4
No files matched your search
@@ -331,9 +331,24 @@ function appendTodoWriteCall(arguments) {
|
||||
let todos = [];
|
||||
if (typeof arguments === 'string') {
|
||||
const data = JSON.parse(arguments);
|
||||
todos = data.todos || [];
|
||||
// 处理嵌套结构:{todos: {todos: [...]}} 或 {todos: [...]}
|
||||
if (data.todos) {
|
||||
if (data.todos.todos) {
|
||||
// 嵌套结构
|
||||
todos = data.todos.todos;
|
||||
} else if (Array.isArray(data.todos)) {
|
||||
// 直接数组
|
||||
todos = data.todos;
|
||||
}
|
||||
}
|
||||
} else if (arguments.todos) {
|
||||
todos = arguments.todos;
|
||||
if (arguments.todos.todos) {
|
||||
// 嵌套结构
|
||||
todos = arguments.todos.todos;
|
||||
} else if (Array.isArray(arguments.todos)) {
|
||||
// 直接数组
|
||||
todos = arguments.todos;
|
||||
}
|
||||
}
|
||||
|
||||
if (todos.length === 0) {
|
||||
@@ -405,10 +420,25 @@ function appendTodoWriteProgress(response) {
|
||||
const jsonMatch = response.match(/\{[\s\S]*"todos"[\s\S]*\}/);
|
||||
if (jsonMatch) {
|
||||
const data = JSON.parse(jsonMatch[0]);
|
||||
todos = data.todos || [];
|
||||
// 处理嵌套结构:{todos: {todos: [...]}} 或 {todos: [...]}
|
||||
if (data.todos) {
|
||||
if (data.todos.todos) {
|
||||
// 嵌套结构
|
||||
todos = data.todos.todos;
|
||||
} else if (Array.isArray(data.todos)) {
|
||||
// 直接数组
|
||||
todos = data.todos;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (response.todos) {
|
||||
todos = response.todos;
|
||||
if (response.todos.todos) {
|
||||
// 嵌套结构
|
||||
todos = response.todos.todos;
|
||||
} else if (Array.isArray(response.todos)) {
|
||||
// 直接数组
|
||||
todos = response.todos;
|
||||
}
|
||||
}
|
||||
|
||||
if (todos.length === 0) {
|
||||
|
||||
Reference in new issue
Block a user