buster/packages/ai/src/tools/planning-thinking-tools/todo-write-tool/todo-write-tool.ts

42 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-10-07 01:06:17 +08:00
import { tool } from 'ai';
import { z } from 'zod';
2025-10-07 02:31:54 +08:00
import { TodoItemSchema } from '../../../agents/analytics-engineer-agent/types';
2025-10-07 01:06:17 +08:00
import { createTodoWriteToolExecute } from './todo-write-tool-execute';
export const TODO_WRITE_TOOL_NAME = 'todoWrite';
const TodoWriteToolOutputSchema = z.object({
success: z.boolean().describe('Whether the operation was successful'),
todos: z.array(TodoItemSchema).describe('The full current state of all todos'),
message: z.string().optional().describe('Optional message about the operation'),
});
const TodoWriteToolInputSchema = z.object({
2025-10-07 02:31:54 +08:00
todos: z
.array(TodoItemSchema)
.describe('Array of todo items to write/update. Include all todos with their current state.'),
2025-10-07 01:06:17 +08:00
});
const TodoWriteToolContextSchema = z.object({
chatId: z.string().describe('The chat/conversation ID to associate todos with'),
workingDirectory: z.string().describe('The working directory for the chat'),
2025-10-07 02:31:54 +08:00
todosList: z.array(TodoItemSchema).default([]).describe('In-memory array of todo items to manipulate'),
2025-10-07 01:06:17 +08:00
});
export type TodoWriteToolInput = z.infer<typeof TodoWriteToolInputSchema>;
export type TodoWriteToolOutput = z.infer<typeof TodoWriteToolOutputSchema>;
export type TodoWriteToolContext = z.infer<typeof TodoWriteToolContextSchema>;
2025-10-07 02:31:54 +08:00
export function createTodoWriteTool<
TAgentContext extends TodoWriteToolContext = TodoWriteToolContext,
>(context: TAgentContext) {
2025-10-07 01:06:17 +08:00
const execute = createTodoWriteToolExecute(context);
return tool({
description: `Write and manage todo items for the current chat session. Accepts an array of todo items with their current state (pending, in_progress, or completed). All todos are persisted to disk and associated with the current chat. Returns the full current state of all todos.`,
inputSchema: TodoWriteToolInputSchema,
outputSchema: TodoWriteToolOutputSchema,
execute,
});
}