🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(lobe-agent): guard todo defaultItems against non-array tool-call args (#16782)
Arvin Xu7db054313790
diff --git a/packages/builtin-tool-lobe-agent/src/client/Intervention/AddTodo.tsx b/packages/builtin-tool-lobe-agent/src/client/Intervention/AddTodo.tsxindex ea4e065f6f2..b7b7c4cbeca 100644--- a/packages/builtin-tool-lobe-agent/src/client/Intervention/AddTodo.tsx+++ b/packages/builtin-tool-lobe-agent/src/client/Intervention/AddTodo.tsx@@ -16,14 +16,18 @@ const AddTodoIntervention = memo<BuiltinInterventionProps<CreateTodosParams>>(// Handle both formats:// - Initial AI input: { adds: string[] } (from AI)// - After user edit: { items: TodoItem[] } (saved format)- const defaultItems: TodoItem[] =- args?.items || args?.adds?.map((text) => ({ status: 'todo', text })) || [];+ // `args` originates from model tool-call output (and may be a partial parse+ // while streaming), so guard on Array.isArray rather than truthiness — a+ // truthy non-array value would otherwise flow through and crash `.map`.+ const defaultItems: TodoItem[] = Array.isArray(args?.items)+ ? args.items+ : Array.isArray(args?.adds)+ ? args.adds.map((text) => ({ status: 'todo', text }))+ : [];const handleSave = useCallback(async (items: TodoItem[]) => {- console.info('[AddTodoIntervention] handleSave called with', items.length, 'items');await onArgsChange?.({ items });- console.info('[AddTodoIntervention] onArgsChange completed');},[onArgsChange],);diff --git a/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/index.tsx b/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/index.tsxindex 2670240b7c1..b1301d7ec86 100644--- a/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/index.tsx+++ b/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/index.tsx@@ -42,9 +42,7 @@ const SortableTodoList = memo<SortableTodoListProps>(useEffect(() => {if (registerBeforeApprove) {const unregister = registerBeforeApprove('sortable-todo-list', async () => {- console.info('trigger save');await store.getState().saveNow();- console.info('trigger save successful');});// Cleanup: unregister on unmountreturn unregister;diff --git a/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/store/actions.ts b/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/store/actions.tsindex c1decdffe6b..7ad62daf0e1 100644--- a/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/store/actions.ts+++ b/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/store/actions.ts@@ -27,11 +27,9 @@ export const createActions = (): TodoListStore => {// Save implementation (used by both debounced and immediate save)const performSave = async () => {- console.info('[performSave] called, onSave:', !!internals.onSave);if (!internals.onSave) return;const { items, isDirty } = get();- console.info('[performSave] isDirty:', isDirty, 'items:', items.length);if (!isDirty) return;set({ saveStatus: 'saving' });@@ -39,9 +37,7 @@ export const createActions = (try {// Convert TodoListItem[] to TodoItem[] (remove id)const todoItems: TodoItem[] = items.map(({ status, text }) => ({ status, text }));- console.info('[performSave] calling onSave with', todoItems.length, 'items');await internals.onSave(todoItems);- console.info('[performSave] onSave completed');set({ isDirty: false, saveStatus: 'saved' });// Match saveNow: ease the indicator back to `idle` so the UI doesn't@@ -68,7 +64,13 @@ export const createActions = (return {...initialState,- items: defaultItems.map((item) => ({ ...item, id: generateId() })),+ // Defensive: `defaultItems` ultimately derives from untrusted model tool-call+ // args, so fall back to an empty list rather than throwing during store init+ // (which would crash the whole Conversation render tree).+ items: (Array.isArray(defaultItems) ? defaultItems : []).map((item) => ({+ ...item,+ id: generateId(),+ })),addItem: () => {const { items, newItemText } = get();@@ -104,9 +106,7 @@ export const createActions = (try {const todoItems: TodoItem[] = items.map(({ status, text }) => ({ status, text }));- console.info('[saveNow] force saving', todoItems.length, 'items');await internals.onSave(todoItems);- console.info('[saveNow] save completed');set({ isDirty: false, saveStatus: 'saved' });setTimeout(() => {diff --git a/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/store/store.test.ts b/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/store/store.test.tsindex 50eadefba0d..94f68c7ad73 100644--- a/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/store/store.test.ts+++ b/packages/builtin-tool-lobe-agent/src/client/components/SortableTodoList/store/store.test.ts@@ -49,6 +49,15 @@ describe('TodoListStore', () => {expect(state.items[0].id).not.toBe(state.items[1].id);});++ it('should fall back to empty items when defaultItems is not an array', () => {+ // `defaultItems` ultimately derives from untrusted model tool-call args+ // (and may be a partial parse while streaming), so a non-array value must+ // not crash store init.+ const store = createTodoListStore({ foo: 'bar' } as unknown as TodoItem[]);++ expect(store.getState().items).toEqual([]);+ });});describe('addItem', () => {