Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/app/src/flow-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const jobInputSchema = z.object({
export const jobIdSchema = z.object({ jobId: z.string().min(1) });
export const manualInvocationSchema = z.object({
prompt: z.string().max(50_000).default(""),
data: z.record(z.string(), z.unknown()).optional(),
idempotencyKey: z.string().trim().min(1).max(200).refine(key => !key.startsWith("manual:"), {
message: "idempotencyKey must not include the reserved manual: claim-key prefix",
}).optional(),
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/protected-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function createMcpServer(service: ApiService): McpServer {
tool("delete_job", "Delete a job and its queued invocation history", jobIdSchema, ({ jobId }: any) => service.deleteJob(jobId));
tool("enable_job", "Enable a job", jobIdSchema, ({ jobId }: any) => service.setJobEnabled(jobId, true));
tool("disable_job", "Disable a job", jobIdSchema, ({ jobId }: any) => service.setJobEnabled(jobId, false));
tool("invoke_job", "Invoke a job's manual trigger with a prompt exposed beneath that trigger's stable slug. Manual invocations are never coalesced. idempotencyKey is a client value and must not include the internal manual: claim-key prefix; reuse invocation.idempotency_key from get_run.", manualInvocationSchema.extend({ jobId: z.string().min(1) }), ({ jobId, ...input }: any) => service.invokeJob(jobId, input));
tool("invoke_job", "Invoke a job's manual trigger with a prompt and optional JSON data exposed beneath that trigger's stable slug. Manual invocations are never coalesced. idempotencyKey is a client value and must not include the internal manual: claim-key prefix; reuse invocation.idempotency_key from get_run.", manualInvocationSchema.extend({ jobId: z.string().min(1) }), ({ jobId, ...input }: any) => service.invokeJob(jobId, input));
tool("list_job_webhook_activity", "List matching, rejected, duplicate, and accepted webhook activity for a job", z.object({ jobId: z.string().min(1), limit: z.number().int().min(1).max(100).default(50) }), ({ jobId, limit }: any) => service.listJobEvents(jobId, limit));
tool("test_job_webhook_handler", "Test an isolated synchronous Job webhook handler without creating a run. Returns the decision and never accepts credentials.", jobHandlerTestSchema, (input: any) => service.testJobHandler(input));
tool("list_execution_targets", "List non-secret execution target metadata and capabilities", z.object({}), () => service.listExecutionTargets());
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ export class TenantV2 extends DurableObject<Env> {
if (!Boolean(job.enabled)) return Response.json({ error: "Job is disabled" }, { status: 409 });
const trigger = this.one("SELECT id,slug FROM triggers WHERE job_id=? AND kind='manual' AND enabled=1 ORDER BY created_at,id LIMIT 1", jobId) as Row | undefined;
if (!trigger) return Response.json({ error: "The manual trigger is disabled" }, { status: 409 });
const result = await this.invokeCanonicalJob(jobId, "manual", String(trigger.id), input.idempotencyKey ? `manual:${input.idempotencyKey}` : `manual:${id()}`, { [String(trigger.slug)]: { prompt: String(input.prompt ?? "") } });
const result = await this.invokeCanonicalJob(jobId, "manual", String(trigger.id), input.idempotencyKey ? `manual:${input.idempotencyKey}` : `manual:${id()}`, { [String(trigger.slug)]: { prompt: String(input.prompt ?? ""), data: input.data ?? {} } });
if (!result) return Response.json({ error: "Job is disabled" }, { status: 409 });
return json(result);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/app/test/flow-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ describe("shared API schemas", () => {
expect(() => jobInputSchema.parse({ ...job, apiToken: "secret" })).toThrow();
expect(() => jobInputSchema.parse({ ...job, parameterDefaults: {} })).toThrow();
expect(() => manualInvocationSchema.parse({ parameters: {} })).toThrow();
expect(manualInvocationSchema.parse({ prompt: "ticket" })).toMatchObject({ prompt: "ticket" });
expect(manualInvocationSchema.parse({ prompt: "ticket", data: { name: "Ticket run", nested: { priority: 1 } } })).toMatchObject({ prompt: "ticket", data: { name: "Ticket run", nested: { priority: 1 } } });
expect(manualInvocationSchema.parse({})).toMatchObject({ prompt: "" });
expect(() => manualInvocationSchema.parse({ data: [] })).toThrow();
expect(manualInvocationSchema.parse({ idempotencyKey: "dev-dispatch-gen-2032" })).toMatchObject({ idempotencyKey: "dev-dispatch-gen-2032" });
expect(() => manualInvocationSchema.parse({ idempotencyKey: "manual:dev-dispatch-gen-2032" })).toThrow(/reserved manual: claim-key prefix/);
});
Expand Down
1 change: 1 addition & 0 deletions packages/app/test/job-domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("job invocation domain", () => {
it("renders structured trigger paths and empty missing values", () => {
expect(renderJobPrompt(job(), { "trigger-1": { prompt: "Fix it" }, "trigger-2": { issue: { title: "Bug" } } })).toBe("Fix it · Bug");
expect(renderJobPrompt(job(), { "trigger-1": { prompt: "Fix it" } })).toBe("Fix it · ");
expect(renderJobPrompt({ promptTemplate: "{{trigger-1.data.name}} ({{trigger-1.data.priority}})" }, { "trigger-1": { prompt: "", data: { name: "Ticket run", priority: 1 } } })).toBe("Ticket run (1)");
});

it("queues one encrypted run for a claim regardless of source retries", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/api/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ All paths are relative to `APP_ORIGIN` and require a bearer token or browser own
| POST | `/api/v1/runs/{runId}/stop` | runs:write | Stop an active run |
| POST | `/api/v1/schedules/preview` | flows:read | `{nextRunAt}` for `{cron,timezone}` |

Job creation requires `name` (1–120), `slug` (lowercase, up to 30), `promptTemplate` (1–50,000), `executionTargetId`, and optional `model`, `effort`, `concurrencyLimit`, and `triggers`. Manual invocation accepts `prompt` (default empty) and an optional unique `idempotencyKey` (1–200; never prefix it with reserved `manual:`). Run states are `queued`, `starting`, `running`, `recovering`, `done`, `blocked`, `failed`, and `ignored`.
Job creation requires `name` (1–120), `slug` (lowercase, up to 30), `promptTemplate` (1–50,000), `executionTargetId`, and optional `model`, `effort`, `concurrencyLimit`, and `triggers`. Manual invocation accepts `prompt` (default empty), an optional JSON object `data` (default `{}`), and an optional unique `idempotencyKey` (1–200; never prefix it with reserved `manual:`). Both values are exposed under the manual trigger slug, for example `{{trigger-1.data.name}}`. Run states are `queued`, `starting`, `running`, `recovering`, `done`, `blocked`, `failed`, and `ignored`.
9 changes: 8 additions & 1 deletion packages/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ components:
effort: { type: string, maxLength: 40 }
triggers: { type: array, maxItems: 50, items: { type: object } }
RunPage: { type: object, required: [items], properties: { items: { type: array, items: { type: object } }, nextCursor: { type: string, nullable: true } } }
ManualInvocation:
type: object
additionalProperties: false
properties:
prompt: { type: string, maxLength: 50000, default: '' }
data: { type: object, additionalProperties: true, default: {} }
idempotencyKey: { type: string, minLength: 1, maxLength: 200 }
paths:
/api/health: { get: { summary: Worker health check, security: [], responses: { '200': { description: OK, content: { application/json: { example: { ok: true } } } } } } }
/api/v1/exe-connections: { get: { summary: List exe connections, responses: { '200': { description: Safe metadata } } } }
Expand All @@ -42,7 +49,7 @@ paths:
delete: { summary: Delete job, responses: { '200': { description: Deleted } } }
/api/v1/jobs/{jobId}/enable: { post: { summary: Enable job, responses: { '200': { description: Enabled } } } }
/api/v1/jobs/{jobId}/disable: { post: { summary: Disable job, responses: { '200': { description: Disabled } } } }
/api/v1/jobs/{jobId}/invocations: { post: { summary: Invoke job, responses: { '202': { description: Accepted } } } }
/api/v1/jobs/{jobId}/invocations: { post: { summary: Invoke job, requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ManualInvocation' } } } }, responses: { '202': { description: Accepted } } } }
/api/v1/jobs/{jobId}/events: { get: { summary: List webhook activity, responses: { '200': { description: Activity } } } }
/api/v1/job-handlers/test: { post: { summary: Test webhook handler, responses: { '200': { description: Decision } } } }
/api/v1/runs:
Expand Down