import { z } from 'zod';
const todoItem = z.object({
    content: z.string().min(1),
    status: z.enum(['pending', 'in_progress', 'completed']),
});
const schema = z.object({
    todos: z.array(todoItem),
});
const MARK = { pending: '[ ]', in_progress: '[>]', completed: '[x]' };
/**
 * Session-scoped todo list. The model replaces the whole list each call and
 * gets the rendered state back, which keeps it anchored on multi-step tasks.
 */
export function createTodoTool() {
    let current = [];
    return {
        name: 'todo_write',
        description: 'Maintain your task list for multi-step work. Pass the COMPLETE list each time ' +
            '(it replaces the previous one) with each item as {content, status} where status is ' +
            'pending | in_progress | completed. Keep at most one item in_progress. ' +
            'Use for tasks with 3+ steps; skip it for trivial requests.',
        schema,
        jsonSchema: {
            type: 'object',
            properties: {
                todos: {
                    type: 'array',
                    description: 'The complete task list (replaces the previous list)',
                    items: {
                        type: 'object',
                        properties: {
                            content: { type: 'string', description: 'The task description' },
                            status: {
                                type: 'string',
                                enum: ['pending', 'in_progress', 'completed'],
                                description: 'Current status of this task',
                            },
                        },
                        required: ['content', 'status'],
                    },
                },
            },
            required: ['todos'],
        },
        readOnly: true, // only mutates in-memory session state
        summarize: (i) => {
            const done = i.todos.filter((t) => t.status === 'completed').length;
            return `${done}/${i.todos.length} done`;
        },
        run: async (input) => {
            current = input.todos;
            if (current.length === 0)
                return 'Todo list cleared.';
            return current.map((t) => `${MARK[t.status]} ${t.content}`).join('\n');
        },
    };
}
