import { CONVEX_VALUE_SCHEMA, runConvexFunction, } from "@automate.ax/integration-contracts/convex" import * as z from "zod" import { defineAction } from "../../automation/actions" const CONVEX_ACCOUNT_REQUIREMENT = { connections: [ { connectionMethodId: "oauth" }, { connectionMethodId: "deployment-key" }, ], } as const const CONVEX_FUNCTION_INPUT_SCHEMA = z.object({ /** Convex function arguments. */ arguments: z.record(z.string(), CONVEX_VALUE_SCHEMA.optional()).optional(), /** Deployment reference for project OAuth accounts. Defaults to `prod`. */ deployment: z.string().min(1).optional(), /** Exported HTTP API path, such as `messages:list` or `reports:run`. */ functionName: z.string().min(1), }) /** Runs a Convex query, including an internal query authorized by the account. */ export const runConvexQuery = defineAction("Run Convex query") .describe("Runs a named query against a connected Convex deployment.") .account("convex", CONVEX_ACCOUNT_REQUIREMENT) .input(CONVEX_FUNCTION_INPUT_SCHEMA) .output(CONVEX_VALUE_SCHEMA) .retry({ replaySafety: "safe" }) .handler(({ account, input }) => runConvexFunction("query", account.secret, input), ) /** Runs a Convex mutation, including an internal mutation when authorized. */ export const runConvexMutation = defineAction("Run Convex mutation") .describe("Runs a named mutation against a connected Convex deployment.") .account("convex", CONVEX_ACCOUNT_REQUIREMENT) .input(CONVEX_FUNCTION_INPUT_SCHEMA) .output(CONVEX_VALUE_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(({ account, input }) => runConvexFunction("mutation", account.secret, input), ) /** Runs a Convex action, including an internal action when authorized. */ export const runConvexAction = defineAction("Run Convex action") .describe("Runs a named action against a connected Convex deployment.") .account("convex", CONVEX_ACCOUNT_REQUIREMENT) .input(CONVEX_FUNCTION_INPUT_SCHEMA) .output(CONVEX_VALUE_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(({ account, input }) => runConvexFunction("action", account.secret, input), )