Skip to content

An AI-powered search engine with a generative UI

fix: address critical code review issues

Yoshiki Miurae2c95f2f0eda
diff --git a/components/artifact/todo-invocation-content.tsx b/components/artifact/todo-invocation-content.tsx
index 5e7193f5..ca1a39cc 100644
--- a/components/artifact/todo-invocation-content.tsx
+++ b/components/artifact/todo-invocation-content.tsx
@@ -65,7 +65,7 @@ export function TodoInvocationContent({ part }: TodoInvocationContentProps) {
<div className="space-y-4">
{/* Summary */}
<div className="flex items-center justify-between text-sm text-muted-foreground">
- <span className="truncate">{part.output?.message || 'Todo List'}</span>
+ <span>{part.output?.message || 'Todo List'}</span>
<span className="font-medium whitespace-nowrap">
({completedCount}/{totalCount})
</span>
diff --git a/components/tool-todo-display.tsx b/components/tool-todo-display.tsx
index 5f4a7425..3b0fc837 100644
--- a/components/tool-todo-display.tsx
+++ b/components/tool-todo-display.tsx
@@ -1,6 +1,6 @@
import { Check, ListTodo } from 'lucide-react'
-import { TodoItem } from '@/lib/types/ai'
+import { Part, TodoItem } from '@/lib/types/ai'
import { useArtifact } from './artifact/artifact-context'
@@ -44,14 +44,15 @@ export function ToolTodoDisplay({
const handleClick = () => {
if (state === 'output-available' && output) {
- openArtifact({
- type:
- tool === 'todoWrite' ? 'tool-todoWrite' : ('tool-todoRead' as any),
+ const partType = tool === 'todoWrite' ? 'tool-todoWrite' : 'tool-todoRead'
+ const part: Part = {
+ type: partType as 'tool-todoWrite' | 'tool-todoRead',
toolCallId: toolCallId,
- state: state as any,
+ state: state,
input: { todos: output.todos || [] },
output: output
- })
+ }
+ openArtifact(part)
}
}
diff --git a/lib/tools/todo.ts b/lib/tools/todo.ts
index e9b03fb6..afed331f 100644
--- a/lib/tools/todo.ts
+++ b/lib/tools/todo.ts
@@ -17,9 +17,6 @@ export const todoItemSchema = z.object({
export type TodoItem = z.infer<typeof todoItemSchema>
-// Global todos storage (persists during the session)
-let globalTodos: TodoItem[] = []
-
// Schema for todo write tool
export const todoWriteInputSchema = z.object({
todos: z.array(todoItemSchema).describe('The complete list of todos'),
@@ -37,15 +34,17 @@ export const todoReadOutputSchema = z.object({
totalCount: z.number()
})
-// Create todo tools
+// Create todo tools with session-scoped storage
export function createTodoTools() {
+ // Session-scoped todos storage - isolated per tool instance
+ let sessionTodos: TodoItem[] = []
const todoWrite = tool({
description:
'Create or update todos to track progress on complex tasks. Use this to maintain a list of action items.',
inputSchema: todoWriteInputSchema,
execute: async ({ todos, progressMessage }) => {
- // Update global todos - ensure priority is always set
- globalTodos = todos.map(todo => ({
+ // Update session todos - ensure priority is always set
+ sessionTodos = todos.map(todo => ({
...todo,
priority: todo.priority || 'medium'
}))
@@ -59,7 +58,7 @@ export function createTodoTools() {
message: progressMessage || `Updated ${totalCount} todos`,
completedCount,
totalCount,
- todos: globalTodos
+ todos: sessionTodos
}
}
})
@@ -68,13 +67,13 @@ export function createTodoTools() {
description: 'Read the current list of todos and their status',
inputSchema: z.object({}),
execute: async () => {
- const completedCount = globalTodos.filter(
- t => t.status === 'completed'
+ const completedCount = sessionTodos.filter(
+ (t: TodoItem) => t.status === 'completed'
).length
- const totalCount = globalTodos.length
+ const totalCount = sessionTodos.length
return {
- todos: globalTodos,
+ todos: sessionTodos,
summary:
totalCount > 0
? `${completedCount} of ${totalCount} tasks completed`