|
| 1 | +import { z } from 'zod' |
| 2 | +import type { TodoistTool } from '../todoist-tool' |
| 3 | +import { mapTask } from './shared' |
| 4 | + |
| 5 | +const ArgsSchema = { |
| 6 | + getBy: z |
| 7 | + .enum(['completion', 'due']) |
| 8 | + .default('completion') |
| 9 | + .describe( |
| 10 | + 'The method to use to get the tasks: "completion" to get tasks by completion date (ie, when the task was actually completed), "due" to get tasks by due date (ie, when the task was due to be completed by).', |
| 11 | + ), |
| 12 | + since: z |
| 13 | + .string() |
| 14 | + .date() |
| 15 | + .regex(/^\d{4}-\d{2}-\d{2}$/) |
| 16 | + .describe('The start date to get the tasks for. Format: YYYY-MM-DD.'), |
| 17 | + until: z |
| 18 | + .string() |
| 19 | + .date() |
| 20 | + .regex(/^\d{4}-\d{2}-\d{2}$/) |
| 21 | + .describe('The start date to get the tasks for. Format: YYYY-MM-DD.'), |
| 22 | + workspaceId: z.string().optional().describe('The ID of the workspace to get the tasks for.'), |
| 23 | + projectId: z.string().optional().describe('The ID of the project to get the tasks for.'), |
| 24 | + sectionId: z.string().optional().describe('The ID of the section to get the tasks for.'), |
| 25 | + parentId: z.string().optional().describe('The ID of the parent task to get the tasks for.'), |
| 26 | + limit: z |
| 27 | + .number() |
| 28 | + .int() |
| 29 | + .min(1) |
| 30 | + .max(200) |
| 31 | + .default(50) |
| 32 | + .describe('The maximum number of tasks to return. Default is 50, maximum is 200.'), |
| 33 | + cursor: z |
| 34 | + .string() |
| 35 | + .optional() |
| 36 | + .describe( |
| 37 | + 'The cursor to get the next page of tasks (cursor is obtained from the previous call to this tool, with the same parameters).', |
| 38 | + ), |
| 39 | +} |
| 40 | + |
| 41 | +const tasksListCompleted = { |
| 42 | + name: 'tasks-list-completed', |
| 43 | + description: 'Get completed tasks.', |
| 44 | + parameters: ArgsSchema, |
| 45 | + async execute(args, client) { |
| 46 | + const { getBy, ...rest } = args |
| 47 | + const { items, nextCursor } = |
| 48 | + getBy === 'completion' |
| 49 | + ? await client.getCompletedTasksByCompletionDate(rest) |
| 50 | + : await client.getCompletedTasksByDueDate(rest) |
| 51 | + return { |
| 52 | + tasks: items.map(mapTask), |
| 53 | + nextCursor, |
| 54 | + } |
| 55 | + }, |
| 56 | +} satisfies TodoistTool<typeof ArgsSchema> |
| 57 | + |
| 58 | +export { tasksListCompleted } |
0 commit comments