import { defineAction } from "@agent-native/core/action"; import { z } from "zod"; import { UserInputError } from "../server/errors.js"; import { requireUserEmail, updateTasks } from "../server/tasks/store.js"; import { BULK_ID_LIMIT } from "../shared/bulk-limits.js"; export const bulkUpdateTasksSchema = z.object({ taskIds: z .array(z.string()) .min(1) .max(BULK_ID_LIMIT) .describe("Task ids to update"), title: z.string().min(1).optional().describe("New title for every task"), done: z.boolean().optional().describe("Completion state for every task"), }); export default defineAction({ description: "Apply the same title and/or completion state to multiple tasks. Use update-task for one task or custom field values.", schema: bulkUpdateTasksSchema, run: async (args, ctx) => { const ownerEmail = requireUserEmail(ctx?.userEmail); if (args.title === undefined && args.done === undefined) { throw new UserInputError("Provide at least one of title or done."); } const tasks = await updateTasks({ ownerEmail, ids: args.taskIds, title: args.title, done: args.done, }); return { tasks }; }, });