|
| 1 | +// Gateway Protocol schema module defines durable runtime control-plane shapes. |
| 2 | +import { Type } from "typebox"; |
| 3 | +import { NonEmptyString } from "./primitives.js"; |
| 4 | + |
| 5 | +const TimestampMsSchema = Type.Integer({ minimum: 0 }); |
| 6 | + |
| 7 | +export const DurableRuntimeRunStatusSchema = Type.Union([ |
| 8 | + Type.Literal("accepted"), |
| 9 | + Type.Literal("received"), |
| 10 | + Type.Literal("queued"), |
| 11 | + Type.Literal("running"), |
| 12 | + Type.Literal("waiting"), |
| 13 | + Type.Literal("waiting_signal"), |
| 14 | + Type.Literal("waiting_timer"), |
| 15 | + Type.Literal("waiting_child"), |
| 16 | + Type.Literal("blocked"), |
| 17 | + Type.Literal("retrying"), |
| 18 | + Type.Literal("retry_scheduled"), |
| 19 | + Type.Literal("canceling"), |
| 20 | + Type.Literal("unknown_after_side_effect"), |
| 21 | + Type.Literal("succeeded"), |
| 22 | + Type.Literal("failed"), |
| 23 | + Type.Literal("cancelled"), |
| 24 | + Type.Literal("lost"), |
| 25 | +]); |
| 26 | + |
| 27 | +export const DurableRecoveryStateSchema = Type.Union([ |
| 28 | + Type.Literal("runnable"), |
| 29 | + Type.Literal("claimed"), |
| 30 | + Type.Literal("running"), |
| 31 | + Type.Literal("waiting_signal"), |
| 32 | + Type.Literal("waiting_timer"), |
| 33 | + Type.Literal("waiting_child"), |
| 34 | + Type.Literal("retry_scheduled"), |
| 35 | + Type.Literal("reconciling"), |
| 36 | + Type.Literal("unknown_after_side_effect"), |
| 37 | + Type.Literal("lost"), |
| 38 | + Type.Literal("terminal"), |
| 39 | +]); |
| 40 | + |
| 41 | +export const DurableCoordinationWaitingReasonSchema = Type.Union([ |
| 42 | + Type.Literal("signal"), |
| 43 | + Type.Literal("timer"), |
| 44 | + Type.Literal("child"), |
| 45 | + Type.Literal("retry"), |
| 46 | + Type.Literal("worker"), |
| 47 | + Type.Literal("unknown"), |
| 48 | +]); |
| 49 | + |
| 50 | +export const DurableCoordinationGetParamsSchema = Type.Object( |
| 51 | + { |
| 52 | + runtimeRunId: NonEmptyString, |
| 53 | + }, |
| 54 | + { additionalProperties: false }, |
| 55 | +); |
| 56 | + |
| 57 | +export const DurableCoordinationExternalRefsSchema = Type.Object( |
| 58 | + { |
| 59 | + workUnitId: Type.Optional(Type.String()), |
| 60 | + reportRouteId: Type.Optional(Type.String()), |
| 61 | + taskId: Type.Optional(Type.String()), |
| 62 | + taskFlowId: Type.Optional(Type.String()), |
| 63 | + sessionKey: Type.Optional(Type.String()), |
| 64 | + childSessionKey: Type.Optional(Type.String()), |
| 65 | + runId: Type.Optional(Type.String()), |
| 66 | + agentId: Type.Optional(Type.String()), |
| 67 | + requesterAgentId: Type.Optional(Type.String()), |
| 68 | + }, |
| 69 | + { additionalProperties: false }, |
| 70 | +); |
| 71 | + |
| 72 | +export const DurableCoordinationChildCountsSchema = Type.Object( |
| 73 | + { |
| 74 | + total: Type.Integer({ minimum: 0 }), |
| 75 | + pending: Type.Integer({ minimum: 0 }), |
| 76 | + running: Type.Integer({ minimum: 0 }), |
| 77 | + succeeded: Type.Integer({ minimum: 0 }), |
| 78 | + failed: Type.Integer({ minimum: 0 }), |
| 79 | + cancelled: Type.Integer({ minimum: 0 }), |
| 80 | + lost: Type.Integer({ minimum: 0 }), |
| 81 | + terminal: Type.Integer({ minimum: 0 }), |
| 82 | + open: Type.Integer({ minimum: 0 }), |
| 83 | + }, |
| 84 | + { additionalProperties: false }, |
| 85 | +); |
| 86 | + |
| 87 | +export const DurableCoordinationRefsSchema = Type.Object( |
| 88 | + { |
| 89 | + inputRef: Type.Optional(Type.String()), |
| 90 | + checkpointRef: Type.Optional(Type.String()), |
| 91 | + outputRefs: Type.Array(Type.String()), |
| 92 | + errorRefs: Type.Array(Type.String()), |
| 93 | + artifactRefs: Type.Array(Type.String()), |
| 94 | + }, |
| 95 | + { additionalProperties: false }, |
| 96 | +); |
| 97 | + |
| 98 | +export const DurableCoordinationControlsSchema = Type.Object( |
| 99 | + { |
| 100 | + canCancel: Type.Boolean(), |
| 101 | + canRetry: Type.Boolean(), |
| 102 | + canResume: Type.Boolean(), |
| 103 | + canSignal: Type.Boolean(), |
| 104 | + canOpenTimeline: Type.Boolean(), |
| 105 | + }, |
| 106 | + { additionalProperties: false }, |
| 107 | +); |
| 108 | + |
| 109 | +export const DurableCoordinationRecoveryDiagnosticSchema = Type.Object( |
| 110 | + { |
| 111 | + state: Type.Union([Type.Literal("lost"), Type.Literal("unknown_after_side_effect")]), |
| 112 | + severity: Type.Union([Type.Literal("warning"), Type.Literal("error")]), |
| 113 | + reportable: Type.Boolean(), |
| 114 | + retryable: Type.Boolean(), |
| 115 | + reason: Type.Optional(Type.String()), |
| 116 | + message: Type.String(), |
| 117 | + nextAction: Type.String(), |
| 118 | + safeRecoveryActions: Type.Optional(Type.Array(Type.String())), |
| 119 | + input: Type.Optional( |
| 120 | + Type.Object( |
| 121 | + { |
| 122 | + inputRef: Type.Optional(Type.String()), |
| 123 | + inputAvailability: Type.Optional(Type.String()), |
| 124 | + canReplay: Type.Optional(Type.Boolean()), |
| 125 | + reason: Type.Optional(Type.String()), |
| 126 | + messageLength: Type.Optional(Type.Integer({ minimum: 0 })), |
| 127 | + messageHash: Type.Optional(Type.String()), |
| 128 | + }, |
| 129 | + { additionalProperties: false }, |
| 130 | + ), |
| 131 | + ), |
| 132 | + detectedAt: Type.Optional(TimestampMsSchema), |
| 133 | + processInstanceId: Type.Optional(Type.String()), |
| 134 | + }, |
| 135 | + { additionalProperties: false }, |
| 136 | +); |
| 137 | + |
| 138 | +export const DurableCoordinationProjectionSchema = Type.Object( |
| 139 | + { |
| 140 | + runtimeRunId: NonEmptyString, |
| 141 | + operationKind: NonEmptyString, |
| 142 | + operationVersion: NonEmptyString, |
| 143 | + status: DurableRuntimeRunStatusSchema, |
| 144 | + recoveryState: DurableRecoveryStateSchema, |
| 145 | + sourceType: Type.Optional(Type.String()), |
| 146 | + sourceRef: Type.Optional(Type.String()), |
| 147 | + parentRuntimeRunId: Type.Optional(Type.String()), |
| 148 | + parentStepId: Type.Optional(Type.String()), |
| 149 | + workUnitId: Type.Optional(Type.String()), |
| 150 | + reportRouteId: Type.Optional(Type.String()), |
| 151 | + currentStepId: Type.Optional(Type.String()), |
| 152 | + waitingReason: Type.Optional(DurableCoordinationWaitingReasonSchema), |
| 153 | + heartbeatAt: Type.Optional(TimestampMsSchema), |
| 154 | + updatedAt: TimestampMsSchema, |
| 155 | + completedAt: Type.Optional(TimestampMsSchema), |
| 156 | + refs: DurableCoordinationRefsSchema, |
| 157 | + external: DurableCoordinationExternalRefsSchema, |
| 158 | + children: DurableCoordinationChildCountsSchema, |
| 159 | + controls: DurableCoordinationControlsSchema, |
| 160 | + recovery: Type.Optional(DurableCoordinationRecoveryDiagnosticSchema), |
| 161 | + }, |
| 162 | + { additionalProperties: false }, |
| 163 | +); |
| 164 | + |
| 165 | +export const DurableCoordinationGetResultSchema = Type.Object( |
| 166 | + { |
| 167 | + projection: DurableCoordinationProjectionSchema, |
| 168 | + }, |
| 169 | + { additionalProperties: false }, |
| 170 | +); |
0 commit comments