refactor: enhance write_todos tool and system prompt

- Updated the write_todos tool to include an optional description field for todo items, improving task detail management.
- Enhanced the system prompt with clearer guidelines on using the write_todos tool, including refined usage patterns and examples for various user scenarios.
- Improved UI components to support the new description feature, ensuring better visibility of task details during planning and execution.
- Streamlined the code for better readability and maintainability, aligning with recent refactoring efforts.
This commit is contained in:
Anish Sarkar 2025-12-26 19:24:32 +05:30
parent ebc04f590e
commit 8a3ab3dfac
5 changed files with 197 additions and 235 deletions

View file

@ -172,10 +172,15 @@ export const Plan: FC<PlanProps> = ({
].filter(Boolean) as Action[];
}, [responseActions]);
// Get default expanded items (in_progress items with descriptions)
const defaultExpandedIds = useMemo(() => {
return todos.filter((t) => t.description && t.status === "in_progress").map((t) => t.id);
}, [todos]);
const TodoList: FC<{ items: PlanTodo[] }> = ({ items }) => {
if (hasDescriptions) {
return (
<Accordion type="single" collapsible className="w-full">
<Accordion type="multiple" defaultValue={defaultExpandedIds} className="w-full">
{items.map((todo) => (
<TodoItem key={todo.id} todo={todo} isStreaming={isStreaming} />
))}

View file

@ -19,39 +19,59 @@ import { Plan, PlanErrorBoundary, parseSerializablePlan, TodoStatusSchema } from
/**
* Schema for a single todo item in the args
* Note: Using nullish() with transform to convert null undefined for Plan compatibility
*/
const WriteTodosArgsTodoSchema = z.object({
id: z.string(),
content: z.string(),
status: TodoStatusSchema,
description: z
.string()
.nullish()
.transform((v) => v ?? undefined),
});
/**
* Schema for write_todos tool arguments
* Note: Using nullish() with transform to convert null undefined for Plan compatibility
*/
const WriteTodosArgsSchema = z.object({
title: z.string().nullish(),
description: z.string().nullish(),
title: z
.string()
.nullish()
.transform((v) => v ?? undefined),
description: z
.string()
.nullish()
.transform((v) => v ?? undefined),
todos: z.array(WriteTodosArgsTodoSchema).nullish(),
});
/**
* Schema for a single todo item in the result
* Note: Using nullish() with transform to convert null undefined for Plan compatibility
*/
const WriteTodosResultTodoSchema = z.object({
id: z.string(),
label: z.string(),
status: TodoStatusSchema,
description: z.string().nullish(),
description: z
.string()
.nullish()
.transform((v) => v ?? undefined),
});
/**
* Schema for write_todos tool result
* Note: Using nullish() with transform to convert null undefined for Plan compatibility
*/
const WriteTodosResultSchema = z.object({
id: z.string(),
title: z.string(),
description: z.string().nullish(),
description: z
.string()
.nullish()
.transform((v) => v ?? undefined),
todos: z.array(WriteTodosResultTodoSchema),
});
@ -93,6 +113,7 @@ function transformArgsToResult(args: WriteTodosArgs): WriteTodosResult | null {
id: todo.id || `todo-${index}`,
label: todo.content || "Task",
status: todo.status || "pending",
description: todo.description,
})),
};
}