|
| 1 | +// GENERATED — do not edit. Source of truth: mothership worker packages/contracts/src/sim-transport.ts |
| 2 | +// Regenerate with `bun run contracts:sync` in the worker. |
| 3 | + |
| 4 | +import { z } from "zod"; |
| 5 | +import { RunControlRequest } from "./run-control"; |
| 6 | +import { TaskWakeRequest, WorkflowWatchRequest } from "./tasks"; |
| 7 | + |
| 8 | +export const SimConnection = z.discriminatedUnion("mode", [ |
| 9 | + z.object({ mode: z.literal("direct") }), |
| 10 | + z.object({ mode: z.literal("checkpoint"), channelId: z.string().regex(/^[a-f0-9]{64}$/) }), |
| 11 | +]); |
| 12 | +export type SimConnection = z.infer<typeof SimConnection>; |
| 13 | + |
| 14 | +export const SimScope = z.object({ |
| 15 | + userId: z.string().min(1), |
| 16 | + workspaceId: z.uuid(), |
| 17 | + chatId: z.uuid(), |
| 18 | +}); |
| 19 | +export type SimScope = z.infer<typeof SimScope>; |
| 20 | + |
| 21 | +/** Only idempotent controls use the idle channel; tool effects use the run event log. */ |
| 22 | +export const SimControlOperation = z.discriminatedUnion("kind", [ |
| 23 | + z.object({ kind: z.literal("run_control"), input: RunControlRequest }), |
| 24 | + z.object({ kind: z.literal("workflow_status"), input: WorkflowWatchRequest }), |
| 25 | + z.object({ kind: z.literal("wake"), input: TaskWakeRequest }), |
| 26 | +]); |
| 27 | +export type SimControlOperation = z.infer<typeof SimControlOperation>; |
| 28 | + |
| 29 | +export const SimControlRequest = z.object({ |
| 30 | + id: z.uuid(), |
| 31 | + scope: SimScope, |
| 32 | + operation: SimControlOperation, |
| 33 | + expiresAt: z.number().int().positive(), |
| 34 | +}); |
| 35 | +export type SimControlRequest = z.infer<typeof SimControlRequest>; |
| 36 | + |
| 37 | +/** HTTP and outbound delivery preserve the same status and JSON response bytes. */ |
| 38 | +export const SimControlResult = z.object({ |
| 39 | + status: z.number().int().min(200).max(599), |
| 40 | + body: z.string().max(16_000_000), |
| 41 | +}); |
| 42 | +export type SimControlResult = z.infer<typeof SimControlResult>; |
| 43 | + |
| 44 | +export const SimChannelPoll = z.object({ channelId: z.string().regex(/^[a-f0-9]{64}$/) }); |
| 45 | +export const SimChannelBatch = z.object({ requests: z.array(SimControlRequest).max(16) }); |
| 46 | +export const SimChannelReply = SimChannelPoll.extend({ |
| 47 | + id: z.uuid(), |
| 48 | + result: SimControlResult, |
| 49 | +}); |
0 commit comments