@catamorphic/fastify-plugin 0.0.0-stage → 0.1.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +202 -0
- package/NOTICE.txt +32 -0
- package/README.md +143 -2
- package/dist/app-presentation-tools.d.ts +4 -0
- package/dist/app-presentation-tools.d.ts.map +1 -0
- package/dist/app.d.ts +27 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/chunk-baagvvm3.js +164 -0
- package/dist/chunk-baagvvm3.js.map +10 -0
- package/dist/http-identity.d.ts +52 -0
- package/dist/http-identity.d.ts.map +1 -0
- package/dist/hung-up.d.ts +7 -0
- package/dist/hung-up.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10884 -0
- package/dist/index.js.map +56 -0
- package/dist/mcp-shared.d.ts +117 -0
- package/dist/mcp-shared.d.ts.map +1 -0
- package/dist/mcp.d.ts +6 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +13 -0
- package/dist/mcp.js.map +9 -0
- package/dist/plugin.d.ts +113 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/project-capabilities.d.ts +25 -0
- package/dist/project-capabilities.d.ts.map +1 -0
- package/dist/project-mcp-program.d.ts +15 -0
- package/dist/project-mcp-program.d.ts.map +1 -0
- package/dist/project-mcp-surface.d.ts +16 -0
- package/dist/project-mcp-surface.d.ts.map +1 -0
- package/dist/request-logging.d.ts +18 -0
- package/dist/request-logging.d.ts.map +1 -0
- package/dist/routes/agent-capabilities.d.ts +4 -0
- package/dist/routes/agent-capabilities.d.ts.map +1 -0
- package/dist/routes/agent.d.ts +4 -0
- package/dist/routes/agent.d.ts.map +1 -0
- package/dist/routes/apps-mcp.d.ts +4 -0
- package/dist/routes/apps-mcp.d.ts.map +1 -0
- package/dist/routes/apps.d.ts +12 -0
- package/dist/routes/apps.d.ts.map +1 -0
- package/dist/routes/client-runners.d.ts +11 -0
- package/dist/routes/client-runners.d.ts.map +1 -0
- package/dist/routes/code-hosts.d.ts +11 -0
- package/dist/routes/code-hosts.d.ts.map +1 -0
- package/dist/routes/connection-mcp.d.ts +10 -0
- package/dist/routes/connection-mcp.d.ts.map +1 -0
- package/dist/routes/connections.d.ts +4 -0
- package/dist/routes/connections.d.ts.map +1 -0
- package/dist/routes/documents.d.ts +11 -0
- package/dist/routes/documents.d.ts.map +1 -0
- package/dist/routes/environments.d.ts +4 -0
- package/dist/routes/environments.d.ts.map +1 -0
- package/dist/routes/git-gateway.d.ts +21 -0
- package/dist/routes/git-gateway.d.ts.map +1 -0
- package/dist/routes/http-gateway.d.ts +13 -0
- package/dist/routes/http-gateway.d.ts.map +1 -0
- package/dist/routes/me.d.ts +12 -0
- package/dist/routes/me.d.ts.map +1 -0
- package/dist/routes/memberships.d.ts +12 -0
- package/dist/routes/memberships.d.ts.map +1 -0
- package/dist/routes/model-gateway.d.ts +12 -0
- package/dist/routes/model-gateway.d.ts.map +1 -0
- package/dist/routes/notifications.d.ts +4 -0
- package/dist/routes/notifications.d.ts.map +1 -0
- package/dist/routes/parse.d.ts +5 -0
- package/dist/routes/parse.d.ts.map +1 -0
- package/dist/routes/personal-environment.d.ts +13 -0
- package/dist/routes/personal-environment.d.ts.map +1 -0
- package/dist/routes/plugins.d.ts +4 -0
- package/dist/routes/plugins.d.ts.map +1 -0
- package/dist/routes/project-mcp.d.ts +25 -0
- package/dist/routes/project-mcp.d.ts.map +1 -0
- package/dist/routes/projects.d.ts +4 -0
- package/dist/routes/projects.d.ts.map +1 -0
- package/dist/routes/publications.d.ts +15 -0
- package/dist/routes/publications.d.ts.map +1 -0
- package/dist/routes/run-errors.d.ts +8 -0
- package/dist/routes/run-errors.d.ts.map +1 -0
- package/dist/routes/runs.d.ts +4 -0
- package/dist/routes/runs.d.ts.map +1 -0
- package/dist/routes/session-artifacts.d.ts +27 -0
- package/dist/routes/session-artifacts.d.ts.map +1 -0
- package/dist/routes/session-mailboxes.d.ts +4 -0
- package/dist/routes/session-mailboxes.d.ts.map +1 -0
- package/dist/routes/session-previews.d.ts +40 -0
- package/dist/routes/session-previews.d.ts.map +1 -0
- package/dist/routes/session-terminals.d.ts +15 -0
- package/dist/routes/session-terminals.d.ts.map +1 -0
- package/dist/routes/triggers.d.ts +20 -0
- package/dist/routes/triggers.d.ts.map +1 -0
- package/dist/routes/watchers.d.ts +4 -0
- package/dist/routes/watchers.d.ts.map +1 -0
- package/dist/routes/webhooks.d.ts +11 -0
- package/dist/routes/webhooks.d.ts.map +1 -0
- package/dist/routes/workflow-enablements.d.ts +4 -0
- package/dist/routes/workflow-enablements.d.ts.map +1 -0
- package/dist/routes/workflows.d.ts +4 -0
- package/dist/routes/workflows.d.ts.map +1 -0
- package/dist/schemas.d.ts +17776 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/session-artifact-tools.d.ts +5 -0
- package/dist/session-artifact-tools.d.ts.map +1 -0
- package/dist/session-event-stream.d.ts +45 -0
- package/dist/session-event-stream.d.ts.map +1 -0
- package/dist/spa.d.ts +24 -0
- package/dist/spa.d.ts.map +1 -0
- package/dist/telemetry.d.ts +4 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/package.json +73 -4
- package/src/app-presentation-tools.ts +46 -0
- package/src/app.ts +115 -0
- package/src/http-identity.ts +145 -0
- package/src/hung-up.ts +13 -0
- package/src/index.ts +25 -0
- package/src/mcp-shared.ts +331 -0
- package/src/mcp.ts +10 -0
- package/src/plugin.ts +332 -0
- package/src/project-capabilities.ts +153 -0
- package/src/project-mcp-program.ts +607 -0
- package/src/project-mcp-surface.ts +881 -0
- package/src/request-logging.ts +47 -0
- package/src/routes/agent-capabilities.ts +109 -0
- package/src/routes/agent.ts +1566 -0
- package/src/routes/apps-mcp.ts +303 -0
- package/src/routes/apps.ts +692 -0
- package/src/routes/client-runners.ts +251 -0
- package/src/routes/code-hosts.ts +247 -0
- package/src/routes/connection-mcp.ts +135 -0
- package/src/routes/connections.ts +494 -0
- package/src/routes/documents.ts +538 -0
- package/src/routes/environments.ts +72 -0
- package/src/routes/git-gateway.ts +106 -0
- package/src/routes/http-gateway.ts +141 -0
- package/src/routes/me.ts +122 -0
- package/src/routes/memberships.ts +173 -0
- package/src/routes/model-gateway.ts +134 -0
- package/src/routes/notifications.ts +101 -0
- package/src/routes/parse.ts +32 -0
- package/src/routes/personal-environment.ts +146 -0
- package/src/routes/plugins.ts +341 -0
- package/src/routes/project-mcp.ts +394 -0
- package/src/routes/projects.ts +708 -0
- package/src/routes/publications.ts +222 -0
- package/src/routes/run-errors.ts +86 -0
- package/src/routes/runs.ts +253 -0
- package/src/routes/session-artifacts.ts +293 -0
- package/src/routes/session-mailboxes.ts +80 -0
- package/src/routes/session-previews.ts +224 -0
- package/src/routes/session-terminals.ts +209 -0
- package/src/routes/triggers.ts +241 -0
- package/src/routes/watchers.ts +94 -0
- package/src/routes/webhooks.ts +171 -0
- package/src/routes/workflow-enablements.ts +331 -0
- package/src/routes/workflows.ts +323 -0
- package/src/schemas.ts +2735 -0
- package/src/session-artifact-tools.ts +170 -0
- package/src/session-event-stream.ts +122 -0
- package/src/spa.ts +135 -0
- package/src/telemetry.ts +93 -0
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,2735 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AgentTurnUsage,
|
|
3
|
+
type Attempt,
|
|
4
|
+
agentQuestionSchema,
|
|
5
|
+
attachmentSchema,
|
|
6
|
+
type CommandReceipt,
|
|
7
|
+
type DispatchMode,
|
|
8
|
+
dispatchModeSchema,
|
|
9
|
+
IMPORTED_HARNESSES,
|
|
10
|
+
type ImportedSession,
|
|
11
|
+
type InboundSender,
|
|
12
|
+
type InputSource,
|
|
13
|
+
type Item,
|
|
14
|
+
inboundSenderSchema,
|
|
15
|
+
inputSourceSchema,
|
|
16
|
+
type JsonObject,
|
|
17
|
+
jsonValueSchema,
|
|
18
|
+
type NativeRef,
|
|
19
|
+
type ProviderThread,
|
|
20
|
+
questionAnswerSchema,
|
|
21
|
+
type RuntimeRequest,
|
|
22
|
+
type RuntimeRequestResponse,
|
|
23
|
+
SESSION_METADATA_KEY_PATTERN,
|
|
24
|
+
SESSION_METADATA_LIMITS,
|
|
25
|
+
SESSION_PROTOCOL_VERSION,
|
|
26
|
+
type SessionCommand,
|
|
27
|
+
type SessionEvent,
|
|
28
|
+
type SessionFields,
|
|
29
|
+
type SessionInput,
|
|
30
|
+
type SessionMessageAuthor,
|
|
31
|
+
type SessionMetadata,
|
|
32
|
+
type SessionSnapshot,
|
|
33
|
+
type SessionStreamMessage,
|
|
34
|
+
type StoredSessionEvent,
|
|
35
|
+
sessionCommandSchema,
|
|
36
|
+
sessionInputSchema,
|
|
37
|
+
sessionMessageAuthorSchema,
|
|
38
|
+
settledAlertSchema,
|
|
39
|
+
type Turn,
|
|
40
|
+
type TurnError,
|
|
41
|
+
type TurnOutcome,
|
|
42
|
+
taskNotificationStatusSchema,
|
|
43
|
+
} from "@catamorphic/agent-protocol";
|
|
44
|
+
import { RUNNER_PROTOCOL_VERSION } from "@catamorphic/agent-protocol/runner";
|
|
45
|
+
import { APP_ICON_NAMES } from "@catamorphic/app";
|
|
46
|
+
import {
|
|
47
|
+
RoleDefinitionSchema as CoreRoleDefinitionSchema,
|
|
48
|
+
PROJECT_PERMISSION_PATTERN,
|
|
49
|
+
type SessionMailboxItem,
|
|
50
|
+
} from "@catamorphic/core";
|
|
51
|
+
import {
|
|
52
|
+
CLAUDE_CODE_PERMISSION_MODES,
|
|
53
|
+
CODEX_APPROVAL_POLICIES,
|
|
54
|
+
CODEX_SANDBOX_MODES,
|
|
55
|
+
SANDBOXING_LEVELS,
|
|
56
|
+
} from "@catamorphic/sandbox";
|
|
57
|
+
import { z } from "zod";
|
|
58
|
+
|
|
59
|
+
// --- Params ---
|
|
60
|
+
export const ProjectIdParamsSchema = z.object({
|
|
61
|
+
projectId: z.string().uuid(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const WorkflowNameParamsSchema = ProjectIdParamsSchema.extend({
|
|
65
|
+
name: z.string().min(1),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export const ProjectFileParamsSchema = ProjectIdParamsSchema.extend({
|
|
69
|
+
"*": z.string().min(1),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const RunIdParamsSchema = z.object({
|
|
73
|
+
runId: z.string().uuid(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const RunPauseParamsSchema = RunIdParamsSchema.extend({
|
|
77
|
+
pauseId: z.string().uuid(),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export const RunStepAttemptParamsSchema = RunIdParamsSchema.extend({
|
|
81
|
+
workflowStepAttemptId: z.string().uuid(),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const RunItemParamsSchema = RunStepAttemptParamsSchema.extend({
|
|
85
|
+
itemId: z.string().uuid(),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// --- Query ---
|
|
89
|
+
export const RefQuerySchema = z.object({
|
|
90
|
+
ref: z.string().optional(),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export const PaginationQuerySchema = z.object({
|
|
94
|
+
limit: z.coerce.number().int().min(1).max(100).default(20),
|
|
95
|
+
offset: z.coerce.number().int().min(0).default(0),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// --- Apps ---
|
|
99
|
+
export const ProjectAppParamsSchema = ProjectIdParamsSchema.extend({
|
|
100
|
+
appName: z.string().regex(/^[a-z0-9][a-z0-9-]*$/),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export const ProjectAppVersionParamsSchema = ProjectIdParamsSchema.extend({
|
|
104
|
+
versionId: z.string().uuid(),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export const AppPresentationSchema = z.object({
|
|
108
|
+
name: z.string(),
|
|
109
|
+
title: z.string(),
|
|
110
|
+
icon: z.enum(APP_ICON_NAMES),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/** Host data an app version declares it reads (ADR 0148). */
|
|
114
|
+
export const AppAccessSchema = z.object({
|
|
115
|
+
sessions: z.literal("read").optional(),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export const AppSummarySchema = z.object({
|
|
119
|
+
name: z.string(),
|
|
120
|
+
title: z.string(),
|
|
121
|
+
id: z.string().uuid().nullable(),
|
|
122
|
+
activeVersionId: z.string().uuid().nullable(),
|
|
123
|
+
publishedAt: z.string().datetime().nullable(),
|
|
124
|
+
icon: z.enum(APP_ICON_NAMES),
|
|
125
|
+
access: AppAccessSchema,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export const AppVersionSchema = z.object({
|
|
129
|
+
id: z.string().uuid(),
|
|
130
|
+
appId: z.string().uuid(),
|
|
131
|
+
appName: z.string(),
|
|
132
|
+
kind: z.enum(["preview", "published"]),
|
|
133
|
+
status: z.enum(["building", "ready", "failed"]),
|
|
134
|
+
commitSha: z.string().nullable(),
|
|
135
|
+
bundleBytes: z.number().nullable(),
|
|
136
|
+
allowedWorkflows: z.array(z.string()).nullable(),
|
|
137
|
+
access: AppAccessSchema,
|
|
138
|
+
error: z.string().nullable(),
|
|
139
|
+
isActive: z.boolean(),
|
|
140
|
+
createdAt: z.string().datetime(),
|
|
141
|
+
readyAt: z.string().datetime().nullable(),
|
|
142
|
+
publishedAt: z.string().datetime().nullable(),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export const AppViewStateSchema = z.discriminatedUnion("state", [
|
|
146
|
+
z.object({ state: z.literal("not_found") }),
|
|
147
|
+
z.object({ state: z.literal("not_published") }),
|
|
148
|
+
z.object({
|
|
149
|
+
state: z.literal("ready"),
|
|
150
|
+
appId: z.string().uuid(),
|
|
151
|
+
versionId: z.string().uuid(),
|
|
152
|
+
// Absolute URL of the guest document for this channel. The mount points
|
|
153
|
+
// its iframe here rather than inlining the bundle: a network-scheme
|
|
154
|
+
// document carries its own CSP, where a srcdoc one would inherit the
|
|
155
|
+
// host shell's and could be blocked by it.
|
|
156
|
+
guestUrl: z.string(),
|
|
157
|
+
}),
|
|
158
|
+
]);
|
|
159
|
+
|
|
160
|
+
export const BuildAppSchema = z.object({
|
|
161
|
+
kind: z.enum(["preview", "published"]),
|
|
162
|
+
commitSha: z
|
|
163
|
+
.string()
|
|
164
|
+
.regex(/^[0-9a-f]{7,64}$/i)
|
|
165
|
+
.optional(),
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// --- Workflows (discovered, not stored) ---
|
|
169
|
+
export const WorkflowCapabilitiesSchema = z.object({
|
|
170
|
+
batchProcessing: z.boolean(),
|
|
171
|
+
cancellation: z.boolean(),
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export const JsonValueSchema = z.json().meta({ id: "JsonValue" });
|
|
175
|
+
// Response-side JSON is untyped, like `Run.input`: the tagged JsonValue
|
|
176
|
+
// component is io-differentiated (input-only) and recursive z.json() emits
|
|
177
|
+
// $refs the spec bundler cannot resolve in responses.
|
|
178
|
+
const JsonOutSchema = z.unknown();
|
|
179
|
+
|
|
180
|
+
export const SourceRangeSchema = z.object({
|
|
181
|
+
start: z.number(),
|
|
182
|
+
end: z.number(),
|
|
183
|
+
startLine: z.number(),
|
|
184
|
+
startColumn: z.number(),
|
|
185
|
+
endLine: z.number(),
|
|
186
|
+
endColumn: z.number(),
|
|
187
|
+
file: z.string().optional(),
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
export const ParameterInfoSchema = z.object({
|
|
191
|
+
name: z.string(),
|
|
192
|
+
type: z.string(),
|
|
193
|
+
optional: z.boolean(),
|
|
194
|
+
displayName: z.string().optional(),
|
|
195
|
+
description: z.string().optional(),
|
|
196
|
+
defaultValue: z.string().optional(),
|
|
197
|
+
schema: JsonOutSchema.optional(),
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// --- Triggers ---
|
|
201
|
+
export const TriggerModeSchema = z.enum(["sync", "async"]);
|
|
202
|
+
|
|
203
|
+
export const TriggerKindDisplaySchema = z.object({
|
|
204
|
+
label: z.string().optional(),
|
|
205
|
+
icon: z.string().optional(),
|
|
206
|
+
color: z.string().optional(),
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
/** A binding as attached to the graph's entry node, display resolved. */
|
|
210
|
+
export const NodeTriggerBindingSchema = z.object({
|
|
211
|
+
kind: z.string(),
|
|
212
|
+
config: JsonOutSchema,
|
|
213
|
+
where: JsonOutSchema.optional(),
|
|
214
|
+
display: TriggerKindDisplaySchema.optional(),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
/** A binding as written: a host kind or a project trigger kind (ADR 0171). */
|
|
218
|
+
export const WorkflowTriggerBindingSchema = z.object({
|
|
219
|
+
kind: z.string(),
|
|
220
|
+
config: JsonOutSchema,
|
|
221
|
+
where: JsonOutSchema.optional(),
|
|
222
|
+
sourceRange: SourceRangeSchema,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
export const TriggerKindInfoSchema = z.object({
|
|
226
|
+
name: z.string(),
|
|
227
|
+
description: z.string().optional(),
|
|
228
|
+
display: TriggerKindDisplaySchema.optional(),
|
|
229
|
+
modes: z.array(TriggerModeSchema),
|
|
230
|
+
payloadJsonSchema: JsonOutSchema,
|
|
231
|
+
configJsonSchema: JsonOutSchema,
|
|
232
|
+
outputJsonSchema: JsonOutSchema.optional(),
|
|
233
|
+
/** Permissions a workflow must declare to bind the kind (ADR 0210). */
|
|
234
|
+
requiredPermissions: z.array(z.string()).optional(),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export const TriggerBindingInfoSchema = z.object({
|
|
238
|
+
workflowName: z.string(),
|
|
239
|
+
/** The host kind that fires the binding. */
|
|
240
|
+
kind: z.string(),
|
|
241
|
+
config: JsonOutSchema,
|
|
242
|
+
/** Filters the payload must satisfy, all of them (ADR 0171). */
|
|
243
|
+
where: z.array(JsonOutSchema),
|
|
244
|
+
/** The project trigger kind the workflow bound. */
|
|
245
|
+
projectKind: z.string().optional(),
|
|
246
|
+
canSuspend: z.boolean(),
|
|
247
|
+
inputParameters: z.array(ParameterInfoSchema),
|
|
248
|
+
inputSchema: JsonOutSchema,
|
|
249
|
+
outputSchema: JsonOutSchema,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
export const WorkflowEnablementOwnerSchema = z.discriminatedUnion("type", [
|
|
253
|
+
z.object({ type: z.literal("member"), externalUserId: z.string().min(1) }),
|
|
254
|
+
z.object({ type: z.literal("project") }),
|
|
255
|
+
]);
|
|
256
|
+
|
|
257
|
+
export const WorkflowEnablementConnectionSchema = z.object({
|
|
258
|
+
alias: z.string(),
|
|
259
|
+
connectionId: z.string().uuid(),
|
|
260
|
+
providerKind: z.string(),
|
|
261
|
+
principalKind: z.enum(["member", "project_service", "tenant_service"]),
|
|
262
|
+
capabilities: z.array(z.string()),
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
export const WorkflowEnablementTriggerSchema = z.object({
|
|
266
|
+
id: z.string().uuid(),
|
|
267
|
+
definitionId: z.string().uuid(),
|
|
268
|
+
kind: z.string(),
|
|
269
|
+
config: JsonOutSchema,
|
|
270
|
+
projectKind: z.string().optional(),
|
|
271
|
+
status: z.enum(["active", "paused"]),
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const WorkflowEnablementTargetSchema = z.object({
|
|
275
|
+
projectId: z.string().uuid(),
|
|
276
|
+
workflowName: z.string(),
|
|
277
|
+
deploymentArtifactId: z.string().uuid(),
|
|
278
|
+
commitSha: z.string(),
|
|
279
|
+
remoteBranch: z.string(),
|
|
280
|
+
environment: z.string(),
|
|
281
|
+
owner: WorkflowEnablementOwnerSchema,
|
|
282
|
+
connections: z.array(WorkflowEnablementConnectionSchema),
|
|
283
|
+
capabilities: z.array(z.string()),
|
|
284
|
+
/** Project permissions the workflow declares (ADR 0158). */
|
|
285
|
+
permissions: z.array(z.string()),
|
|
286
|
+
consentDigest: z.string().length(64),
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
export const WorkflowEnablementPreviewSchema =
|
|
290
|
+
WorkflowEnablementTargetSchema.extend({
|
|
291
|
+
deploymentArtifactDigest: z.string(),
|
|
292
|
+
triggerCount: z.number().int().nonnegative(),
|
|
293
|
+
triggers: z.array(
|
|
294
|
+
z.object({
|
|
295
|
+
kind: z.string(),
|
|
296
|
+
config: JsonOutSchema,
|
|
297
|
+
projectKind: z.string().optional(),
|
|
298
|
+
}),
|
|
299
|
+
),
|
|
300
|
+
connectionLabels: z.record(z.string(), z.string()),
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
export const WorkflowEnablementSchema = WorkflowEnablementTargetSchema.extend({
|
|
304
|
+
id: z.string().uuid(),
|
|
305
|
+
status: z.enum(["active", "suspended", "disabled"]),
|
|
306
|
+
suspensionReason: z.string().nullable(),
|
|
307
|
+
updateAvailable: z.boolean(),
|
|
308
|
+
temporary: z.boolean(),
|
|
309
|
+
expiresAt: z.string().datetime().nullable(),
|
|
310
|
+
revision: z.number().int().positive(),
|
|
311
|
+
triggers: z.array(WorkflowEnablementTriggerSchema),
|
|
312
|
+
createdAt: z.string().datetime(),
|
|
313
|
+
updatedAt: z.string().datetime(),
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
export const WorkflowSummarySchema = z.object({
|
|
317
|
+
name: z.string(),
|
|
318
|
+
capabilities: WorkflowCapabilitiesSchema,
|
|
319
|
+
displayName: z.string().nullable(),
|
|
320
|
+
description: z.string().nullable(),
|
|
321
|
+
filePath: z.string(),
|
|
322
|
+
parameterCount: z.number(),
|
|
323
|
+
triggers: z.array(WorkflowTriggerBindingSchema),
|
|
324
|
+
canSuspend: z.boolean(),
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// --- Projects ---
|
|
328
|
+
export const ProjectSchema = z.object({
|
|
329
|
+
id: z.string().uuid(),
|
|
330
|
+
name: z.string(),
|
|
331
|
+
storageType: z.enum(["managed", "remote"]),
|
|
332
|
+
remoteUrl: z.string().nullable(),
|
|
333
|
+
/**
|
|
334
|
+
* Who created the linked remote (ADR 0170). `attached`: Work only pushes
|
|
335
|
+
* `work/*` branches there and shares changes as pull requests. `owned`:
|
|
336
|
+
* Work created it and sync keeps it converged. `null` when unlinked.
|
|
337
|
+
*/
|
|
338
|
+
remoteOwnership: z.enum(["owned", "attached"]).nullable(),
|
|
339
|
+
/**
|
|
340
|
+
* Since when the project's main has not been a fast-forward of its code
|
|
341
|
+
* host's default branch (ADR 0170): accepted changes stop arriving until
|
|
342
|
+
* the two are reconciled. `null` while they converge.
|
|
343
|
+
*/
|
|
344
|
+
remoteDivergedAt: z.string().datetime().nullable(),
|
|
345
|
+
defaultBranch: z.string(),
|
|
346
|
+
createdAt: z.string().datetime(),
|
|
347
|
+
updatedAt: z.string().datetime(),
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// Deliberately no rootPath/importExisting here: explicit filesystem locations
|
|
351
|
+
// are a library-direct capability for single-machine hosts, never something a
|
|
352
|
+
// remote HTTP client may choose.
|
|
353
|
+
export const CreateProjectSchema = z.object({
|
|
354
|
+
name: z.string().min(1),
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
export const UpdateProjectSchema = z.object({
|
|
358
|
+
name: z.string().min(1).optional(),
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
export const ProjectDetailSchema = ProjectSchema.extend({
|
|
362
|
+
workflows: z.array(WorkflowSummarySchema),
|
|
363
|
+
files: z.array(z.string()),
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// --- Files ---
|
|
367
|
+
export const FileEntrySchema = z.object({
|
|
368
|
+
path: z.string(),
|
|
369
|
+
size: z.number(),
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
export const FileContentSchema = z.object({
|
|
373
|
+
path: z.string(),
|
|
374
|
+
content: z.string(),
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
export const WriteFileSchema = z.object({
|
|
378
|
+
content: z.string(),
|
|
379
|
+
expectedContent: z.string().optional(),
|
|
380
|
+
commitMessage: z.string().optional(),
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// Keep these enums in sync with `@catamorphic/parser`'s `WorkflowNodeType` and
|
|
384
|
+
// edge `type` literal union so the OpenAPI-derived types line up with the
|
|
385
|
+
// parser's in-memory types and `layoutGraph` can consume the response
|
|
386
|
+
// directly with no casts.
|
|
387
|
+
export const WorkflowNodeTypeSchema = z.enum([
|
|
388
|
+
"input",
|
|
389
|
+
"source",
|
|
390
|
+
"sink",
|
|
391
|
+
"step",
|
|
392
|
+
"branch",
|
|
393
|
+
"if-block",
|
|
394
|
+
"loop-block",
|
|
395
|
+
"parallel-block",
|
|
396
|
+
"scope-block",
|
|
397
|
+
"durable-boundary",
|
|
398
|
+
"batch",
|
|
399
|
+
"pause",
|
|
400
|
+
"call-workflow",
|
|
401
|
+
"return",
|
|
402
|
+
]);
|
|
403
|
+
|
|
404
|
+
export const WorkflowEdgeTypeSchema = z.enum([
|
|
405
|
+
"branch-false",
|
|
406
|
+
"branch-true",
|
|
407
|
+
"sequential",
|
|
408
|
+
]);
|
|
409
|
+
|
|
410
|
+
// The graph schemas below mirror `@catamorphic/parser`'s `WorkflowGraph`
|
|
411
|
+
// exactly so that the OpenAPI-derived response types align with the parser's
|
|
412
|
+
// in-memory types and `layoutGraph(...)` can consume responses without any
|
|
413
|
+
// adapter.
|
|
414
|
+
export const StepArgumentSourceSchema = z.object({
|
|
415
|
+
variable: z.string(),
|
|
416
|
+
variableDisplayName: z.string().optional(),
|
|
417
|
+
stepNodeId: z.string().optional(),
|
|
418
|
+
stepLabel: z.string().optional(),
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
export const StepArgumentSchema = z.object({
|
|
422
|
+
name: z.string(),
|
|
423
|
+
displayName: z.string().optional(),
|
|
424
|
+
value: z.string(),
|
|
425
|
+
source: StepArgumentSourceSchema.optional(),
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
export const WorkflowNodeSchema = z.object({
|
|
429
|
+
id: z.string(),
|
|
430
|
+
type: WorkflowNodeTypeSchema,
|
|
431
|
+
label: z.string(),
|
|
432
|
+
description: z.string().optional(),
|
|
433
|
+
sourceRange: SourceRangeSchema,
|
|
434
|
+
metadata: z.record(z.string(), z.string()),
|
|
435
|
+
parameters: z.array(ParameterInfoSchema).optional(),
|
|
436
|
+
arguments: z.array(StepArgumentSchema).optional(),
|
|
437
|
+
condition: z.string().optional(),
|
|
438
|
+
loopVariable: z.string().optional(),
|
|
439
|
+
loopIterable: z.string().optional(),
|
|
440
|
+
duration: z.string().optional(),
|
|
441
|
+
stateExpression: z.string().optional(),
|
|
442
|
+
workflowName: z.string().optional(),
|
|
443
|
+
workflowInputExpression: z.string().optional(),
|
|
444
|
+
returnExpression: z.string().optional(),
|
|
445
|
+
functionName: z.string().optional(),
|
|
446
|
+
parentId: z.string().optional(),
|
|
447
|
+
triggerBindings: z.array(NodeTriggerBindingSchema).optional(),
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
export const WorkflowEdgeSchema = z.object({
|
|
451
|
+
id: z.string(),
|
|
452
|
+
source: z.string(),
|
|
453
|
+
target: z.string(),
|
|
454
|
+
label: z.string().optional(),
|
|
455
|
+
type: WorkflowEdgeTypeSchema,
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
export const WorkflowGraphSchema = z.object({
|
|
459
|
+
name: z.string(),
|
|
460
|
+
capabilities: WorkflowCapabilitiesSchema,
|
|
461
|
+
displayName: z.string().optional(),
|
|
462
|
+
description: z.string().optional(),
|
|
463
|
+
controls: z.object({ cancel: z.literal(true).optional() }).optional(),
|
|
464
|
+
filePath: z.string().optional(),
|
|
465
|
+
input: z.object({ parameters: z.array(ParameterInfoSchema) }),
|
|
466
|
+
inputSchema: JsonOutSchema,
|
|
467
|
+
outputSchema: JsonOutSchema,
|
|
468
|
+
triggers: z.array(WorkflowTriggerBindingSchema),
|
|
469
|
+
connections: z.array(
|
|
470
|
+
z.object({
|
|
471
|
+
alias: z.string(),
|
|
472
|
+
principal: z.enum(["member", "service", "either"]).optional(),
|
|
473
|
+
capabilities: z.array(z.string()).optional(),
|
|
474
|
+
optional: z.boolean().optional(),
|
|
475
|
+
}),
|
|
476
|
+
),
|
|
477
|
+
permissions: z.array(z.string()),
|
|
478
|
+
canSuspend: z.boolean(),
|
|
479
|
+
nodes: z.array(WorkflowNodeSchema),
|
|
480
|
+
edges: z.array(WorkflowEdgeSchema),
|
|
481
|
+
sourceCode: z.string(),
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
export const WorkflowDetailSchema = WorkflowGraphSchema.extend({
|
|
485
|
+
projectFiles: z.array(z.string()),
|
|
486
|
+
allFiles: z.record(z.string(), z.string()),
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
// --- Runs ---
|
|
490
|
+
export const RunStatusSchema = z.enum([
|
|
491
|
+
"pending",
|
|
492
|
+
"running",
|
|
493
|
+
"waiting",
|
|
494
|
+
"paused",
|
|
495
|
+
"canceling",
|
|
496
|
+
"completed",
|
|
497
|
+
"failed",
|
|
498
|
+
"canceled",
|
|
499
|
+
]);
|
|
500
|
+
|
|
501
|
+
export const RunPhaseSchema = z.enum([
|
|
502
|
+
"execute",
|
|
503
|
+
"boundary",
|
|
504
|
+
"source",
|
|
505
|
+
"process",
|
|
506
|
+
"sink",
|
|
507
|
+
"pause",
|
|
508
|
+
"child",
|
|
509
|
+
]);
|
|
510
|
+
|
|
511
|
+
export const RunCapabilitiesSchema = z.object({
|
|
512
|
+
cancel: z.boolean(),
|
|
513
|
+
pauseProcessing: z.boolean(),
|
|
514
|
+
resumeProcessing: z.boolean(),
|
|
515
|
+
submitInput: z.boolean(),
|
|
516
|
+
inspectItems: z.boolean(),
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
export const RunPauseSchema = z.object({
|
|
520
|
+
id: z.string().uuid(),
|
|
521
|
+
status: z.enum(["open", "resumed", "timed_out", "canceled"]),
|
|
522
|
+
state: z.unknown().nullable(),
|
|
523
|
+
timeoutAt: z.string().datetime().nullable(),
|
|
524
|
+
createdAt: z.string().datetime(),
|
|
525
|
+
resolvedAt: z.string().datetime().nullable(),
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
export const BatchProgressSchema = z.object({
|
|
529
|
+
workflowStepAttemptId: z.string().uuid(),
|
|
530
|
+
stepIndex: z.number().int().nonnegative(),
|
|
531
|
+
nodeId: z.string(),
|
|
532
|
+
attempt: z.number().int().positive(),
|
|
533
|
+
status: z.enum([
|
|
534
|
+
"pending",
|
|
535
|
+
"running",
|
|
536
|
+
"waiting",
|
|
537
|
+
"completed",
|
|
538
|
+
"failed",
|
|
539
|
+
"canceled",
|
|
540
|
+
]),
|
|
541
|
+
estimated: z.number().nullable(),
|
|
542
|
+
discovered: z.number(),
|
|
543
|
+
succeeded: z.number(),
|
|
544
|
+
failed: z.number(),
|
|
545
|
+
skipped: z.number(),
|
|
546
|
+
sinkCompletedChunks: z.number(),
|
|
547
|
+
sinkTotalChunks: z.number(),
|
|
548
|
+
artifact: z.unknown().nullable(),
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
export const RunSchema = z.object({
|
|
552
|
+
id: z.string().uuid(),
|
|
553
|
+
projectId: z.string().uuid(),
|
|
554
|
+
workflowName: z.string(),
|
|
555
|
+
correlationKey: z.string().nullable(),
|
|
556
|
+
environment: z.string().nullable(),
|
|
557
|
+
allocationId: z.string().uuid().nullable(),
|
|
558
|
+
capabilities: RunCapabilitiesSchema,
|
|
559
|
+
status: RunStatusSchema,
|
|
560
|
+
phase: RunPhaseSchema,
|
|
561
|
+
currentStepIndex: z.number().int().nonnegative().nullable(),
|
|
562
|
+
activePause: RunPauseSchema.nullable(),
|
|
563
|
+
connectionActionRequired: z
|
|
564
|
+
.object({
|
|
565
|
+
id: z.string().uuid(),
|
|
566
|
+
environment: z.string(),
|
|
567
|
+
alias: z.string(),
|
|
568
|
+
status: z.literal("pending"),
|
|
569
|
+
createdAt: z.string().datetime(),
|
|
570
|
+
})
|
|
571
|
+
.nullable(),
|
|
572
|
+
batchScopes: z.array(BatchProgressSchema),
|
|
573
|
+
provenance: z.object({
|
|
574
|
+
commitSha: z.string().optional(),
|
|
575
|
+
/** The workflow's display name at that commit. */
|
|
576
|
+
displayName: z.string().optional(),
|
|
577
|
+
}),
|
|
578
|
+
artifact: z.object({ deploymentArtifactId: z.string().uuid() }).optional(),
|
|
579
|
+
initiatedBy: z.string().nullable(),
|
|
580
|
+
input: z.unknown().nullable(),
|
|
581
|
+
result: z.unknown().nullable(),
|
|
582
|
+
error: z.string().nullable(),
|
|
583
|
+
parentRunId: z.string().uuid().nullable(),
|
|
584
|
+
createdAt: z.string().datetime(),
|
|
585
|
+
updatedAt: z.string().datetime(),
|
|
586
|
+
startedAt: z.string().datetime().nullable(),
|
|
587
|
+
completedAt: z.string().datetime().nullable(),
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
export const RunStepSchema = z.object({
|
|
591
|
+
id: z.string().uuid(),
|
|
592
|
+
runId: z.string().uuid(),
|
|
593
|
+
nodeId: z.string(),
|
|
594
|
+
occurrence: z.number().int().nonnegative(),
|
|
595
|
+
attempt: z.number().int().positive(),
|
|
596
|
+
name: z.string(),
|
|
597
|
+
status: z.enum(["pending", "running", "completed", "failed", "skipped"]),
|
|
598
|
+
input: z.unknown().nullable(),
|
|
599
|
+
output: z.unknown().nullable(),
|
|
600
|
+
error: z.string().nullable(),
|
|
601
|
+
startedAt: z.string().datetime().nullable(),
|
|
602
|
+
completedAt: z.string().datetime().nullable(),
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
export const WorkflowStepAttemptSchema = z.object({
|
|
606
|
+
id: z.string().uuid(),
|
|
607
|
+
runId: z.string().uuid(),
|
|
608
|
+
stepIndex: z.number().int().nonnegative(),
|
|
609
|
+
nodeId: z.string(),
|
|
610
|
+
executor: z.enum(["boundary", "batch"]),
|
|
611
|
+
attempt: z.number().int().positive(),
|
|
612
|
+
status: z.enum([
|
|
613
|
+
"pending",
|
|
614
|
+
"running",
|
|
615
|
+
"waiting",
|
|
616
|
+
"completed",
|
|
617
|
+
"failed",
|
|
618
|
+
"canceled",
|
|
619
|
+
]),
|
|
620
|
+
input: z.unknown().nullable(),
|
|
621
|
+
output: z.unknown().nullable(),
|
|
622
|
+
error: z.string().nullable(),
|
|
623
|
+
startedAt: z.string().datetime().nullable(),
|
|
624
|
+
completedAt: z.string().datetime().nullable(),
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
export const RunDetailSchema = RunSchema.extend({
|
|
628
|
+
steps: z.array(RunStepSchema),
|
|
629
|
+
workflowStepAttempts: z.array(WorkflowStepAttemptSchema),
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
export const CorrelationKeySchema = z.string().min(1).max(500);
|
|
633
|
+
|
|
634
|
+
export const EnrollmentConflictPolicySchema = z.enum([
|
|
635
|
+
"ignore",
|
|
636
|
+
"error",
|
|
637
|
+
"restart",
|
|
638
|
+
]);
|
|
639
|
+
|
|
640
|
+
export const TriggerRunSchema = z.object({
|
|
641
|
+
input: JsonValueSchema.optional(),
|
|
642
|
+
environment: z.string().min(1).optional(),
|
|
643
|
+
correlationKey: CorrelationKeySchema.optional(),
|
|
644
|
+
onConflict: EnrollmentConflictPolicySchema.optional(),
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
export const EnvironmentListQuerySchema = z.object({
|
|
648
|
+
workload: z.enum(["agent", "workflow"]),
|
|
649
|
+
agentId: z.string().min(1).optional(),
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
export const EnvironmentListSchema = z.object({
|
|
653
|
+
items: z.array(
|
|
654
|
+
z.object({
|
|
655
|
+
name: z.string(),
|
|
656
|
+
label: z.string(),
|
|
657
|
+
description: z.string().optional(),
|
|
658
|
+
available: z.boolean(),
|
|
659
|
+
clientRequired: z.boolean().optional(),
|
|
660
|
+
machineOnline: z
|
|
661
|
+
.boolean()
|
|
662
|
+
.describe(
|
|
663
|
+
"False when no machine for it is online and open to this work, such as a member's computer that is not connected",
|
|
664
|
+
),
|
|
665
|
+
compatible: z.boolean(),
|
|
666
|
+
preferred: z.boolean(),
|
|
667
|
+
allowed: z.boolean(),
|
|
668
|
+
personalCredentials: z
|
|
669
|
+
.boolean()
|
|
670
|
+
.optional()
|
|
671
|
+
.describe(
|
|
672
|
+
"Present when the Environment allows personal credentials (ADR 0184): whether the caller's own chats placed there would carry their files and may run on their own sign-in",
|
|
673
|
+
),
|
|
674
|
+
reasons: z.array(z.string()),
|
|
675
|
+
binding: z
|
|
676
|
+
.object({
|
|
677
|
+
trust: z.enum(["local", "managed"]),
|
|
678
|
+
isolation: z.enum(["none", "process", "sandbox"]),
|
|
679
|
+
capabilities: z.array(z.string()),
|
|
680
|
+
resources: z.record(z.string(), z.union([z.number(), z.boolean()])),
|
|
681
|
+
})
|
|
682
|
+
.optional(),
|
|
683
|
+
}),
|
|
684
|
+
),
|
|
685
|
+
defaultEnvironment: z.string().optional(),
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
export const AuthenticationRequiredSchema = z.object({
|
|
689
|
+
error: z.string(),
|
|
690
|
+
code: z.literal("authentication_required"),
|
|
691
|
+
environment: z.string(),
|
|
692
|
+
requirements: z.array(
|
|
693
|
+
z.object({
|
|
694
|
+
alias: z.string(),
|
|
695
|
+
providerKind: z.string(),
|
|
696
|
+
principalKinds: z.array(
|
|
697
|
+
z.enum(["member", "project_service", "tenant_service"]),
|
|
698
|
+
),
|
|
699
|
+
}),
|
|
700
|
+
),
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
export const ConnectionRecordSchema = z.object({
|
|
704
|
+
id: z.string().uuid(),
|
|
705
|
+
projectId: z.string().uuid().nullable(),
|
|
706
|
+
providerKind: z.string(),
|
|
707
|
+
principalKind: z.enum(["member", "project_service", "tenant_service"]),
|
|
708
|
+
/** A service connection's name; Environment bindings refer to it. */
|
|
709
|
+
name: z.string().nullable(),
|
|
710
|
+
ownerExternalUserId: z.string().nullable(),
|
|
711
|
+
label: z.string(),
|
|
712
|
+
status: z.enum(["pending", "ready", "expired", "revoked"]),
|
|
713
|
+
account: JsonOutSchema,
|
|
714
|
+
scopes: z.array(z.string()),
|
|
715
|
+
capabilities: z.array(z.string()),
|
|
716
|
+
expiresAt: z.string().datetime().nullable(),
|
|
717
|
+
revision: z.number().int(),
|
|
718
|
+
createdAt: z.string().datetime(),
|
|
719
|
+
updatedAt: z.string().datetime(),
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
const ConnectionBindingPrincipalStatusSchema = z.object({
|
|
723
|
+
connectionId: z.string().uuid().nullable(),
|
|
724
|
+
principalKind: z.enum(["member", "project_service", "tenant_service"]),
|
|
725
|
+
label: z.string(),
|
|
726
|
+
status: z.enum(["pending", "ready", "expired", "revoked"]),
|
|
727
|
+
account: JsonOutSchema,
|
|
728
|
+
scopes: z.array(z.string()),
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
/** One alias an Environment commits in `.work/project.json` (ADR 0172). */
|
|
732
|
+
export const ConnectionBindingSchema = z.object({
|
|
733
|
+
environment: z.string(),
|
|
734
|
+
alias: z.string(),
|
|
735
|
+
provider: z.string(),
|
|
736
|
+
principal: z.enum(["member", "service", "either"]),
|
|
737
|
+
/** The service connection's name; shown to connection administrators. */
|
|
738
|
+
service: z.string().nullable(),
|
|
739
|
+
capabilities: z.array(z.string()).nullable(),
|
|
740
|
+
memberConnection: ConnectionBindingPrincipalStatusSchema.nullable(),
|
|
741
|
+
serviceConnection: ConnectionBindingPrincipalStatusSchema.nullable(),
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
export const AuthorizationChallengeSchema = z.discriminatedUnion("kind", [
|
|
745
|
+
z.object({
|
|
746
|
+
kind: z.literal("url"),
|
|
747
|
+
url: z.string().url(),
|
|
748
|
+
expiresAt: z.string().optional(),
|
|
749
|
+
}),
|
|
750
|
+
z.object({
|
|
751
|
+
kind: z.literal("device"),
|
|
752
|
+
verificationUrl: z.string().url(),
|
|
753
|
+
userCode: z.string(),
|
|
754
|
+
expiresAt: z.string().optional(),
|
|
755
|
+
}),
|
|
756
|
+
z.object({
|
|
757
|
+
kind: z.literal("form"),
|
|
758
|
+
fields: z.array(
|
|
759
|
+
z.object({
|
|
760
|
+
name: z.string(),
|
|
761
|
+
label: z.string(),
|
|
762
|
+
secret: z.boolean(),
|
|
763
|
+
required: z.boolean(),
|
|
764
|
+
multiline: z.boolean().optional(),
|
|
765
|
+
}),
|
|
766
|
+
),
|
|
767
|
+
}),
|
|
768
|
+
]);
|
|
769
|
+
|
|
770
|
+
export const FireTriggerSchema = z.object({
|
|
771
|
+
payload: JsonValueSchema,
|
|
772
|
+
environment: z.string().min(1).optional(),
|
|
773
|
+
mode: TriggerModeSchema.optional(),
|
|
774
|
+
workflows: z.array(z.string().min(1)).max(100).optional(),
|
|
775
|
+
correlationKey: CorrelationKeySchema.optional(),
|
|
776
|
+
onConflict: EnrollmentConflictPolicySchema.optional(),
|
|
777
|
+
budgetMs: z.number().int().min(1_000).max(300_000).optional(),
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
export const RunSuspensionReasonSchema = z.enum([
|
|
781
|
+
"pause",
|
|
782
|
+
"child",
|
|
783
|
+
"paused",
|
|
784
|
+
"backoff",
|
|
785
|
+
"batch",
|
|
786
|
+
"budget",
|
|
787
|
+
"queue",
|
|
788
|
+
]);
|
|
789
|
+
export const TriggerSuspensionReasonSchema = RunSuspensionReasonSchema;
|
|
790
|
+
|
|
791
|
+
/** Body of a synchronous call: a trigger plus a wall-clock budget. */
|
|
792
|
+
export const CallRunSchema = TriggerRunSchema.extend({
|
|
793
|
+
budgetMs: z.number().int().min(1_000).max(300_000).optional(),
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* How a synchronous call settled. Discriminated on `status`; `suspended`
|
|
798
|
+
* means the run is still live and can be polled by `runId`.
|
|
799
|
+
*/
|
|
800
|
+
export const RunCallOutcomeSchema = z.discriminatedUnion("status", [
|
|
801
|
+
z.object({
|
|
802
|
+
status: z.literal("completed"),
|
|
803
|
+
runId: z.string(),
|
|
804
|
+
output: JsonOutSchema,
|
|
805
|
+
}),
|
|
806
|
+
z.object({
|
|
807
|
+
status: z.literal("failed"),
|
|
808
|
+
runId: z.string(),
|
|
809
|
+
error: z.string(),
|
|
810
|
+
}),
|
|
811
|
+
z.object({
|
|
812
|
+
status: z.literal("suspended"),
|
|
813
|
+
runId: z.string(),
|
|
814
|
+
suspendedOn: RunSuspensionReasonSchema,
|
|
815
|
+
}),
|
|
816
|
+
]);
|
|
817
|
+
|
|
818
|
+
export const TriggerFireOutcomeSchema = z.object({
|
|
819
|
+
workflowName: z.string(),
|
|
820
|
+
runId: z.string(),
|
|
821
|
+
status: z.enum(["started", "completed", "failed", "suspended"]),
|
|
822
|
+
output: JsonOutSchema.optional(),
|
|
823
|
+
error: z.string().optional(),
|
|
824
|
+
suspendedOn: TriggerSuspensionReasonSchema.optional(),
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
export const TriggerFireResultSchema = z.object({
|
|
828
|
+
kind: z.string(),
|
|
829
|
+
mode: TriggerModeSchema,
|
|
830
|
+
commitSha: z.string().nullable(),
|
|
831
|
+
runs: z.array(TriggerFireOutcomeSchema),
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
export const SyncTriggerTypesResultSchema = z.object({
|
|
835
|
+
paths: z.array(z.string()),
|
|
836
|
+
updated: z.boolean(),
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
export const RunsQuerySchema = PaginationQuerySchema.extend({
|
|
840
|
+
correlationKey: CorrelationKeySchema.optional(),
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
export const SignalRunSchema = z.object({
|
|
844
|
+
correlationKey: CorrelationKeySchema,
|
|
845
|
+
signal: z.string().min(1).max(255),
|
|
846
|
+
idempotencyKey: z.string().min(1).max(255),
|
|
847
|
+
value: JsonValueSchema,
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
export const CancelRunByKeySchema = z.object({
|
|
851
|
+
correlationKey: CorrelationKeySchema,
|
|
852
|
+
reason: z.string().max(1000).optional(),
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
export const TenantExecutionPolicySchema = z.object({
|
|
856
|
+
tenantId: z.string().uuid(),
|
|
857
|
+
maxConcurrentJobs: z.number().int().positive().optional(),
|
|
858
|
+
maxActiveRuns: z.number().int().positive().optional(),
|
|
859
|
+
queueWeight: z.number().int().min(1).max(1000),
|
|
860
|
+
jobsEnabled: z.boolean(),
|
|
861
|
+
rateLimitOverrides: z.record(
|
|
862
|
+
z.string(),
|
|
863
|
+
z.object({
|
|
864
|
+
capacity: z.number().positive().optional(),
|
|
865
|
+
refillRatePerSecond: z.number().positive().optional(),
|
|
866
|
+
}),
|
|
867
|
+
),
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
export const UpsertTenantExecutionPolicySchema = z.object({
|
|
871
|
+
maxConcurrentJobs: z.number().int().positive().optional(),
|
|
872
|
+
maxActiveRuns: z.number().int().positive().optional(),
|
|
873
|
+
queueWeight: z.number().int().min(1).max(1000).optional(),
|
|
874
|
+
jobsEnabled: z.boolean().optional(),
|
|
875
|
+
rateLimitOverrides: z
|
|
876
|
+
.record(
|
|
877
|
+
z.string(),
|
|
878
|
+
z.object({
|
|
879
|
+
capacity: z.number().positive().optional(),
|
|
880
|
+
refillRatePerSecond: z.number().positive().optional(),
|
|
881
|
+
}),
|
|
882
|
+
)
|
|
883
|
+
.optional(),
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
export const BatchItemStatusSchema = z.enum([
|
|
887
|
+
"pending",
|
|
888
|
+
"running",
|
|
889
|
+
"waiting",
|
|
890
|
+
"succeeded",
|
|
891
|
+
"failed",
|
|
892
|
+
"skipped",
|
|
893
|
+
"canceled",
|
|
894
|
+
]);
|
|
895
|
+
|
|
896
|
+
export const BatchItemSchema = z.object({
|
|
897
|
+
id: z.string().uuid(),
|
|
898
|
+
runId: z.string().uuid(),
|
|
899
|
+
workflowStepAttemptId: z.string().uuid(),
|
|
900
|
+
key: z.string(),
|
|
901
|
+
sourceOrder: z.number(),
|
|
902
|
+
status: BatchItemStatusSchema,
|
|
903
|
+
value: z.unknown().nullable(),
|
|
904
|
+
output: z.unknown().nullable(),
|
|
905
|
+
error: z.string().nullable(),
|
|
906
|
+
currentNodeId: z.string().nullable(),
|
|
907
|
+
attempt: z.number().int().nonnegative(),
|
|
908
|
+
createdAt: z.string().datetime(),
|
|
909
|
+
updatedAt: z.string().datetime(),
|
|
910
|
+
completedAt: z.string().datetime().nullable(),
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
export const BatchItemStepSchema = z.object({
|
|
914
|
+
id: z.string().uuid(),
|
|
915
|
+
itemId: z.string().uuid(),
|
|
916
|
+
nodeId: z.string(),
|
|
917
|
+
occurrence: z.number(),
|
|
918
|
+
attempt: z.number(),
|
|
919
|
+
name: z.string(),
|
|
920
|
+
status: z.string(),
|
|
921
|
+
input: z.unknown().nullable(),
|
|
922
|
+
output: z.unknown().nullable(),
|
|
923
|
+
error: z.string().nullable(),
|
|
924
|
+
startedAt: z.string().datetime().nullable(),
|
|
925
|
+
completedAt: z.string().datetime().nullable(),
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
export const CancelRunSchema = z.object({
|
|
929
|
+
reason: z.string().max(1000).optional(),
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
export const ResumeRunPauseSchema = z.object({
|
|
933
|
+
idempotencyKey: z.string().min(1).max(255),
|
|
934
|
+
value: JsonValueSchema,
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
export const RunItemsQuerySchema = z.object({
|
|
938
|
+
limit: z.coerce.number().int().min(1).max(500).default(100),
|
|
939
|
+
offset: z.coerce.number().int().min(0).default(0),
|
|
940
|
+
status: BatchItemStatusSchema.optional(),
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
// --- Git ---
|
|
944
|
+
export const CommitSchema = z.object({
|
|
945
|
+
sha: z.string(),
|
|
946
|
+
message: z.string(),
|
|
947
|
+
author: z.object({ name: z.string(), email: z.string() }),
|
|
948
|
+
timestamp: z.number(),
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
export const SetRemoteSchema = z.object({
|
|
952
|
+
url: z.string().url(),
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
export const RepoStatusSchema = z.object({
|
|
956
|
+
branch: z.string(),
|
|
957
|
+
dirty: z.boolean(),
|
|
958
|
+
modifiedFiles: z.array(z.string()),
|
|
959
|
+
ahead: z.number(),
|
|
960
|
+
behind: z.number(),
|
|
961
|
+
baseCommit: z.string().nullable(),
|
|
962
|
+
remoteHead: z.string().nullable(),
|
|
963
|
+
remoteHeadTimestamp: z.number().nullable(),
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
export const DiffEntrySchema = z.object({
|
|
967
|
+
path: z.string(),
|
|
968
|
+
kind: z.enum(["added", "modified", "deleted"]),
|
|
969
|
+
before: z.string().nullable(),
|
|
970
|
+
after: z.string().nullable(),
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
export const ConflictEntrySchema = z.object({
|
|
974
|
+
path: z.string(),
|
|
975
|
+
base: z.string().nullable(),
|
|
976
|
+
ours: z.string().nullable(),
|
|
977
|
+
theirs: z.string().nullable(),
|
|
978
|
+
/** A file that is not text: its sides are not rendered as text. */
|
|
979
|
+
binary: z.boolean().optional(),
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
export const DeployRequestSchema = z.object({
|
|
983
|
+
message: z.string().min(1).optional(),
|
|
984
|
+
/**
|
|
985
|
+
* Files to publish as one commit on top of the published program, leaving
|
|
986
|
+
* the member's draft untouched (ADR 0191).
|
|
987
|
+
*/
|
|
988
|
+
files: z.record(z.string(), z.string()).optional(),
|
|
989
|
+
/**
|
|
990
|
+
* The published commit `files` were edited from: files changed on the
|
|
991
|
+
* server since merge with them, or come back as conflicts.
|
|
992
|
+
*/
|
|
993
|
+
base: z
|
|
994
|
+
.string()
|
|
995
|
+
.regex(/^[0-9a-f]{40}$/)
|
|
996
|
+
.optional(),
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
export const PullRequestSchema = z.object({
|
|
1000
|
+
/** Files to write into the member's draft before merging. */
|
|
1001
|
+
files: z.record(z.string(), z.string()).optional(),
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
export const DeployResponseSchema = z.object({
|
|
1005
|
+
status: z.enum(["deployed", "nothing-to-deploy", "conflict"]),
|
|
1006
|
+
commitSha: z.string().nullable(),
|
|
1007
|
+
remoteSha: z.string().nullable(),
|
|
1008
|
+
conflicts: z.array(ConflictEntrySchema),
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
export const PullResponseSchema = z.object({
|
|
1012
|
+
status: z.enum(["clean", "conflict", "up-to-date"]),
|
|
1013
|
+
mergeCommit: z.string().nullable(),
|
|
1014
|
+
conflicts: z.array(ConflictEntrySchema),
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
export const DiscardResponseSchema = z.object({
|
|
1018
|
+
discarded: z.boolean(),
|
|
1019
|
+
branch: z.string(),
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
export const ResolveConflictsSchema = z.object({
|
|
1023
|
+
resolutions: z.record(z.string(), z.string()),
|
|
1024
|
+
message: z.string().optional(),
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
// --- Users ---
|
|
1028
|
+
export const UserSchema = z.object({
|
|
1029
|
+
id: z.string().uuid(),
|
|
1030
|
+
email: z.string().email(),
|
|
1031
|
+
displayName: z.string(),
|
|
1032
|
+
createdAt: z.string().datetime(),
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
// --- Project Members ---
|
|
1036
|
+
export const ProjectMemberSchema = z.object({
|
|
1037
|
+
projectId: z.string().uuid(),
|
|
1038
|
+
userId: z.string().uuid(),
|
|
1039
|
+
role: z.enum(["owner", "editor", "viewer"]),
|
|
1040
|
+
createdAt: z.string().datetime(),
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
// --- Sandboxes ---
|
|
1044
|
+
export const SandboxSchema = z.object({
|
|
1045
|
+
id: z.string().uuid(),
|
|
1046
|
+
projectId: z.string().uuid(),
|
|
1047
|
+
provider: z.string(),
|
|
1048
|
+
providerId: z.string(),
|
|
1049
|
+
sandboxType: z.enum(["execution", "dev"]),
|
|
1050
|
+
commitSha: z.string().length(40).nullable(),
|
|
1051
|
+
userId: z.string().uuid().nullable(),
|
|
1052
|
+
status: z.string(),
|
|
1053
|
+
snapshotName: z.string().nullable(),
|
|
1054
|
+
createdAt: z.string().datetime(),
|
|
1055
|
+
lastUsedAt: z.string().datetime(),
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
// --- Agent Sessions ---
|
|
1059
|
+
export const AgentEffortSchema = z.enum([
|
|
1060
|
+
"low",
|
|
1061
|
+
"medium",
|
|
1062
|
+
"high",
|
|
1063
|
+
"xhigh",
|
|
1064
|
+
"max",
|
|
1065
|
+
]);
|
|
1066
|
+
|
|
1067
|
+
export const AgentTodoStatusSchema = z.enum([
|
|
1068
|
+
"pending",
|
|
1069
|
+
"in_progress",
|
|
1070
|
+
"completed",
|
|
1071
|
+
]);
|
|
1072
|
+
|
|
1073
|
+
export const AgentTodoSchema = z.object({
|
|
1074
|
+
id: z.string().uuid(),
|
|
1075
|
+
title: z.string().min(1).max(200),
|
|
1076
|
+
description: z.string().min(1).max(4_000),
|
|
1077
|
+
status: AgentTodoStatusSchema,
|
|
1078
|
+
/** What the agent does while this is in progress ("Reviewing migrations"). */
|
|
1079
|
+
activeForm: z.string().max(200).optional(),
|
|
1080
|
+
});
|
|
1081
|
+
|
|
1082
|
+
export const AgentSessionSourceSchema = z.enum([
|
|
1083
|
+
"desktop",
|
|
1084
|
+
"mobile",
|
|
1085
|
+
"slack",
|
|
1086
|
+
"claude",
|
|
1087
|
+
"mcp",
|
|
1088
|
+
"api",
|
|
1089
|
+
]);
|
|
1090
|
+
|
|
1091
|
+
export const AgentSessionsQuerySchema = PaginationQuerySchema.extend({
|
|
1092
|
+
visibility: z.enum(["promoted", "latent", "archived"]).optional(),
|
|
1093
|
+
parentSessionId: z.string().uuid().optional(),
|
|
1094
|
+
rootsOnly: z
|
|
1095
|
+
.enum(["true", "false"])
|
|
1096
|
+
.transform((value) => value === "true")
|
|
1097
|
+
.optional(),
|
|
1098
|
+
}).refine((value) => !(value.rootsOnly && value.parentSessionId), {
|
|
1099
|
+
message: "Choose rootsOnly or parentSessionId, not both.",
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* A chat named by the project's key (ADR 0173): the caller's own, the
|
|
1104
|
+
* project chat with `audience=project`, or a member's with `member=<id>`.
|
|
1105
|
+
*/
|
|
1106
|
+
export const KeyedChatParamsSchema = ProjectIdParamsSchema.extend({
|
|
1107
|
+
key: z.string().trim().min(1).max(200),
|
|
1108
|
+
});
|
|
1109
|
+
export const KeyedChatQuerySchema = z
|
|
1110
|
+
.object({
|
|
1111
|
+
audience: z.literal("project").optional(),
|
|
1112
|
+
member: z.string().min(1).optional(),
|
|
1113
|
+
})
|
|
1114
|
+
.refine((value) => !(value.audience && value.member), {
|
|
1115
|
+
message: "Choose audience=project or member, not both.",
|
|
1116
|
+
});
|
|
1117
|
+
export const ClosedKeyedChatSchema = z.object({
|
|
1118
|
+
sessionId: z.string().uuid().nullable(),
|
|
1119
|
+
closed: z.boolean(),
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* Where a chat's workspace starts, or moves to (ADR 0178): a branch, tag,
|
|
1124
|
+
* commit, or full ref (`refs/pull/42/head`) of the project's linked remote.
|
|
1125
|
+
*/
|
|
1126
|
+
export const SessionWorkspaceRequestBodySchema = z.strictObject({
|
|
1127
|
+
ref: z.string().trim().min(1).max(255),
|
|
1128
|
+
update: z.enum(["reset", "rebase"]).optional(),
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
/** The base a chat's workspace stands on (ADR 0178). */
|
|
1132
|
+
export const SessionWorkspaceSchema = z.object({
|
|
1133
|
+
ref: z.string(),
|
|
1134
|
+
commit: z.string(),
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
export const AgentSessionPlacementSchema = z.object({
|
|
1138
|
+
environment: z.string(),
|
|
1139
|
+
reason: z.enum([
|
|
1140
|
+
"requested",
|
|
1141
|
+
"agent_preferred",
|
|
1142
|
+
"project_default",
|
|
1143
|
+
"available",
|
|
1144
|
+
]),
|
|
1145
|
+
machine: z.object({ id: z.string(), label: z.string() }),
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
/** Where a session another tool ran was imported from (ADR 0233). */
|
|
1149
|
+
export const ImportedSessionSchema = describes<ImportedSession>()(
|
|
1150
|
+
z
|
|
1151
|
+
.object({
|
|
1152
|
+
harness: z.enum(IMPORTED_HARNESSES),
|
|
1153
|
+
nativeSessionId: z.string(),
|
|
1154
|
+
sourcePath: z.string(),
|
|
1155
|
+
contentSha256: z.string(),
|
|
1156
|
+
sourceModifiedAt: z.string(),
|
|
1157
|
+
})
|
|
1158
|
+
.meta({ id: "ImportedSession" }),
|
|
1159
|
+
);
|
|
1160
|
+
|
|
1161
|
+
export const AgentSessionSchema = z.object({
|
|
1162
|
+
workStatus: z.enum(["open", "completed"]),
|
|
1163
|
+
stateRevision: z.number().int().nonnegative(),
|
|
1164
|
+
childCount: z.number().int().nonnegative().optional(),
|
|
1165
|
+
id: z.string().uuid(),
|
|
1166
|
+
projectId: z.string().uuid(),
|
|
1167
|
+
externalUserId: z.string(),
|
|
1168
|
+
owner: z.enum(["member", "project"]),
|
|
1169
|
+
source: AgentSessionSourceSchema,
|
|
1170
|
+
sandboxId: z.string().uuid().nullable(),
|
|
1171
|
+
environment: z.string().nullable(),
|
|
1172
|
+
allocationId: z.string().uuid().nullable(),
|
|
1173
|
+
agentId: z.string().nullable(),
|
|
1174
|
+
/** The harness used by the latest bound turn; null before it starts. */
|
|
1175
|
+
harness: z.string().nullable(),
|
|
1176
|
+
model: z.string().nullable(),
|
|
1177
|
+
modelEffort: AgentEffortSchema.nullable(),
|
|
1178
|
+
/** Runs in its harness's read-only mode (ADR 0271). */
|
|
1179
|
+
readOnly: z.boolean(),
|
|
1180
|
+
title: z.string().nullable(),
|
|
1181
|
+
icon: z.string().nullable(),
|
|
1182
|
+
forkedFromSessionId: z.string().uuid().nullable(),
|
|
1183
|
+
/** Provenance of a chat imported from another tool (ADR 0233). */
|
|
1184
|
+
imported: ImportedSessionSchema.nullable(),
|
|
1185
|
+
parentSessionId: z.string().uuid().nullable(),
|
|
1186
|
+
visibility: z.enum(["latent", "promoted", "archived"]),
|
|
1187
|
+
archivedAt: z.string().datetime().nullable(),
|
|
1188
|
+
status: z.enum(["active", "closed"]),
|
|
1189
|
+
activity: z.string().nullable(),
|
|
1190
|
+
todos: z.array(AgentTodoSchema).max(50),
|
|
1191
|
+
authorityHostId: z.string().min(1),
|
|
1192
|
+
authorityRevision: z.number().int().positive(),
|
|
1193
|
+
authoritySeenAt: z.string().datetime(),
|
|
1194
|
+
/** The last event sequence a mirror pushed here (ADR 0197). */
|
|
1195
|
+
mirrorSequence: z.number().int().nonnegative(),
|
|
1196
|
+
handoffStatus: z.enum(["none", "pending"]),
|
|
1197
|
+
handoffDestinationHostId: z.string().nullable(),
|
|
1198
|
+
resumable: z.boolean(),
|
|
1199
|
+
pausedAt: z.string().datetime().nullable(),
|
|
1200
|
+
running: z.boolean(),
|
|
1201
|
+
attentionRevision: z.number().int().nonnegative(),
|
|
1202
|
+
attentionSeenRevision: z.number().int().nonnegative(),
|
|
1203
|
+
attentionRequired: z.boolean(),
|
|
1204
|
+
attentionMessage: z
|
|
1205
|
+
.object({ id: z.string().uuid(), content: z.string() })
|
|
1206
|
+
.optional(),
|
|
1207
|
+
/** The project's key for this chat (ADR 0173); closing frees it. */
|
|
1208
|
+
key: z.string().nullable(),
|
|
1209
|
+
/** Workflows that delivered to the chat by its key. */
|
|
1210
|
+
keyWorkflows: z.array(z.string()),
|
|
1211
|
+
/** Where the chat runs and why (ADR 0173). */
|
|
1212
|
+
placement: AgentSessionPlacementSchema.nullable(),
|
|
1213
|
+
/** The base the chat's workspace stands on (ADR 0178). */
|
|
1214
|
+
workspace: SessionWorkspaceSchema.nullable(),
|
|
1215
|
+
baseCommitSha: z.string().length(40).nullable(),
|
|
1216
|
+
createdAt: z.string().datetime(),
|
|
1217
|
+
updatedAt: z.string().datetime(),
|
|
1218
|
+
});
|
|
1219
|
+
|
|
1220
|
+
export const AgentSessionIdParamsSchema = ProjectIdParamsSchema.extend({
|
|
1221
|
+
sessionId: z.string().uuid(),
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
export const AgentSessionPeerSchema = z.object({
|
|
1225
|
+
id: z.string().uuid(),
|
|
1226
|
+
projectId: z.string().uuid(),
|
|
1227
|
+
title: z.string().nullable(),
|
|
1228
|
+
agentId: z.string().nullable(),
|
|
1229
|
+
parentSessionId: z.string().uuid().nullable(),
|
|
1230
|
+
forkedFromSessionId: z.string().uuid().nullable(),
|
|
1231
|
+
visibility: z.enum(["latent", "promoted", "archived"]),
|
|
1232
|
+
status: z.enum(["active", "closed"]),
|
|
1233
|
+
running: z.boolean(),
|
|
1234
|
+
task: z.string().max(240).nullable(),
|
|
1235
|
+
activity: z.string().max(500).nullable(),
|
|
1236
|
+
updatedAt: z.string().datetime(),
|
|
1237
|
+
});
|
|
1238
|
+
|
|
1239
|
+
export const UpdateAgentSessionActivitySchema = z.object({
|
|
1240
|
+
activity: z.string().max(500).nullable(),
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
/** A person's name for their chat; it keeps it (ADR 0247). */
|
|
1244
|
+
export const RenameAgentSessionSchema = z.object({
|
|
1245
|
+
title: z.string().trim().min(1).max(500),
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
export const CreateAgentSessionSchema = z.object({
|
|
1249
|
+
systemPrompt: z.string().optional(),
|
|
1250
|
+
/** Host-registry key of the agent to run this session on. */
|
|
1251
|
+
agentId: z.string().optional(),
|
|
1252
|
+
model: z.string().optional(),
|
|
1253
|
+
effort: AgentEffortSchema.optional(),
|
|
1254
|
+
environment: z.string().min(1).optional(),
|
|
1255
|
+
/** Surface creating the session. Provenance only; never grants access. */
|
|
1256
|
+
source: AgentSessionSourceSchema.optional(),
|
|
1257
|
+
parentSessionId: z.string().uuid().optional(),
|
|
1258
|
+
title: z.string().min(1).max(500).optional(),
|
|
1259
|
+
/** Start the workspace at a ref of the project's linked remote. */
|
|
1260
|
+
workspace: SessionWorkspaceRequestBodySchema.optional(),
|
|
1261
|
+
});
|
|
1262
|
+
|
|
1263
|
+
export const CreateAgentSubsessionSchema = z.object({
|
|
1264
|
+
/** Omitted: a copy of the parent's own agent (ADR 0271). */
|
|
1265
|
+
agentId: z.string().min(1).optional(),
|
|
1266
|
+
/** A model a grant allows and the agent's harness offers. */
|
|
1267
|
+
model: z.string().min(1).optional(),
|
|
1268
|
+
effort: AgentEffortSchema.optional(),
|
|
1269
|
+
/** Run in the harness's read-only mode; always allowed. */
|
|
1270
|
+
readOnly: z.boolean().optional(),
|
|
1271
|
+
/** False keeps the child from starting its own; always allowed. */
|
|
1272
|
+
delegate: z.boolean().optional(),
|
|
1273
|
+
task: z.string().min(1).max(100_000),
|
|
1274
|
+
contextMode: z.enum(["fresh", "inherit"]).optional(),
|
|
1275
|
+
title: z.string().min(1).max(500).optional(),
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
export const AgentSubsessionSchema = z.object({
|
|
1279
|
+
delegationId: z.string().uuid(),
|
|
1280
|
+
/** The grant that admitted it: `self`, `*` or an agent id. */
|
|
1281
|
+
grant: z.string(),
|
|
1282
|
+
task: z.string(),
|
|
1283
|
+
contextMode: z.enum(["fresh", "inherit"]),
|
|
1284
|
+
allowFurtherDelegation: z.boolean(),
|
|
1285
|
+
status: z.enum(["running", "completed", "failed", "interrupted", "archived"]),
|
|
1286
|
+
session: AgentSessionSchema,
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1289
|
+
export const WaitForAgentSubsessionsSchema = z.object({
|
|
1290
|
+
sessionIds: z.array(z.string().uuid()).max(100).optional(),
|
|
1291
|
+
timeoutMs: z.number().int().min(0).max(60_000).optional(),
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
export const ArchiveAgentSessionSchema = z.object({
|
|
1295
|
+
confirmStop: z.boolean().optional(),
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
export const AgentSessionArchiveImpactSchema = z.object({
|
|
1299
|
+
sessionIds: z.array(z.string().uuid()),
|
|
1300
|
+
runningSessionIds: z.array(z.string().uuid()),
|
|
1301
|
+
watchers: z.array(
|
|
1302
|
+
z.object({
|
|
1303
|
+
id: z.string().uuid(),
|
|
1304
|
+
sessionId: z.string().uuid(),
|
|
1305
|
+
name: z.string(),
|
|
1306
|
+
environment: z.string().nullable(),
|
|
1307
|
+
nextRunAt: z.string().nullable(),
|
|
1308
|
+
}),
|
|
1309
|
+
),
|
|
1310
|
+
activeWatcherCount: z.number().int().nonnegative(),
|
|
1311
|
+
activeProcessCount: z.number().int().nonnegative(),
|
|
1312
|
+
requiresConfirmation: z.boolean(),
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1315
|
+
export const AgentSessionArchiveResultSchema = z.object({
|
|
1316
|
+
impact: AgentSessionArchiveImpactSchema,
|
|
1317
|
+
sessions: z.array(AgentSessionSchema),
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
export const AgentSessionArchiveConfirmationSchema = z.object({
|
|
1321
|
+
error: z.string(),
|
|
1322
|
+
code: z.literal("archive_confirmation_required"),
|
|
1323
|
+
impact: AgentSessionArchiveImpactSchema,
|
|
1324
|
+
});
|
|
1325
|
+
|
|
1326
|
+
export const AgentSubsessionIdParamsSchema = AgentSessionIdParamsSchema.extend({
|
|
1327
|
+
childSessionId: z.string().uuid(),
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1330
|
+
export const UpdateAgentSessionSchema = z.object({
|
|
1331
|
+
agentId: z.string().optional(),
|
|
1332
|
+
/** `null` clears the override back to the agent harness's default. */
|
|
1333
|
+
model: z.string().min(1).max(500).nullable().optional(),
|
|
1334
|
+
/** `null` clears the override back to the agent's default. */
|
|
1335
|
+
effort: AgentEffortSchema.nullable().optional(),
|
|
1336
|
+
environment: z.string().min(1).optional(),
|
|
1337
|
+
});
|
|
1338
|
+
|
|
1339
|
+
export const EnvironmentErrorSchema = z.object({
|
|
1340
|
+
error: z.string(),
|
|
1341
|
+
code: z.string(),
|
|
1342
|
+
reasons: z.array(z.string()).optional(),
|
|
1343
|
+
});
|
|
1344
|
+
|
|
1345
|
+
// --- Agent session log (ADR 0197) ---
|
|
1346
|
+
//
|
|
1347
|
+
// The wire shapes of `@catamorphic/agent-protocol`. Each schema is bound to
|
|
1348
|
+
// its protocol type with `describes`, so a change on either side that the
|
|
1349
|
+
// other does not follow fails the typecheck here.
|
|
1350
|
+
|
|
1351
|
+
/** Every member's keys, across a union. */
|
|
1352
|
+
type KeysOf<T> = T extends unknown ? `${Exclude<keyof T, symbol>}` : never;
|
|
1353
|
+
|
|
1354
|
+
/**
|
|
1355
|
+
* Bind a schema to the protocol type it describes: the schema's output must
|
|
1356
|
+
* be assignable to the type, the type to the schema's output, and both name
|
|
1357
|
+
* the same fields (so a new optional field is not silently stripped).
|
|
1358
|
+
*/
|
|
1359
|
+
function describes<T>() {
|
|
1360
|
+
return <S extends z.ZodType<T>>(
|
|
1361
|
+
schema: S &
|
|
1362
|
+
([T] extends [z.output<S>]
|
|
1363
|
+
? [KeysOf<T>] extends [KeysOf<z.output<S>>]
|
|
1364
|
+
? unknown
|
|
1365
|
+
: never
|
|
1366
|
+
: never),
|
|
1367
|
+
): S => schema;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// The protocol's own JSON value (inside a `respond` command) is recursive;
|
|
1371
|
+
// naming it lets the OpenAPI document reference it instead of an anonymous
|
|
1372
|
+
// cycle.
|
|
1373
|
+
z.globalRegistry.add(jsonValueSchema, { id: "ProtocolJsonValue" });
|
|
1374
|
+
// Messages, answers and their history carry attachments: one definition
|
|
1375
|
+
// the document references rather than a copy at each use.
|
|
1376
|
+
z.globalRegistry.add(attachmentSchema, { id: "ProtocolAttachment" });
|
|
1377
|
+
|
|
1378
|
+
export const DispatchModeSchema = describes<DispatchMode>()(
|
|
1379
|
+
dispatchModeSchema.describe(
|
|
1380
|
+
"queue: a new turn after the active one; steer: join the active turn; interrupt: stop the active turn and run this next; message_only: record it without starting a turn",
|
|
1381
|
+
),
|
|
1382
|
+
);
|
|
1383
|
+
|
|
1384
|
+
export const SessionMessageAuthorSchema = describes<SessionMessageAuthor>()(
|
|
1385
|
+
sessionMessageAuthorSchema,
|
|
1386
|
+
);
|
|
1387
|
+
|
|
1388
|
+
export const InboundSenderSchema = describes<InboundSender>()(
|
|
1389
|
+
inboundSenderSchema.meta({ id: "InboundSender" }),
|
|
1390
|
+
);
|
|
1391
|
+
|
|
1392
|
+
const InputSourceSchema = describes<InputSource>()(
|
|
1393
|
+
inputSourceSchema.meta({ id: "InputSource" }),
|
|
1394
|
+
);
|
|
1395
|
+
|
|
1396
|
+
/** What a delivery puts into a session (ADR 0217). */
|
|
1397
|
+
export const SessionInputSchema = describes<SessionInput>()(
|
|
1398
|
+
sessionInputSchema.meta({ id: "SessionInput" }),
|
|
1399
|
+
);
|
|
1400
|
+
|
|
1401
|
+
const JsonObjectSchema = describes<JsonObject>()(
|
|
1402
|
+
z.record(z.string(), JsonValueSchema),
|
|
1403
|
+
);
|
|
1404
|
+
|
|
1405
|
+
const NativeRefSchema = describes<NativeRef>()(
|
|
1406
|
+
z.object({
|
|
1407
|
+
id: z.string(),
|
|
1408
|
+
strength: z.enum(["strong", "weak", "none"]),
|
|
1409
|
+
}),
|
|
1410
|
+
);
|
|
1411
|
+
|
|
1412
|
+
const TurnErrorSchema = describes<TurnError>()(
|
|
1413
|
+
z.object({
|
|
1414
|
+
message: z.string(),
|
|
1415
|
+
kind: z
|
|
1416
|
+
.enum(["auth", "rate_limit", "unavailable", "model_incompat"])
|
|
1417
|
+
.optional(),
|
|
1418
|
+
retrySafe: z.boolean().optional(),
|
|
1419
|
+
}),
|
|
1420
|
+
);
|
|
1421
|
+
|
|
1422
|
+
const AgentTurnUsageSchema = describes<AgentTurnUsage>()(
|
|
1423
|
+
z.object({
|
|
1424
|
+
model: z.string().optional(),
|
|
1425
|
+
inputTokens: z.number().optional(),
|
|
1426
|
+
cachedInputTokens: z.number().optional(),
|
|
1427
|
+
cacheCreationTokens: z.number().optional(),
|
|
1428
|
+
outputTokens: z.number().optional(),
|
|
1429
|
+
reasoningTokens: z.number().optional(),
|
|
1430
|
+
costUsd: z.number().optional(),
|
|
1431
|
+
contextTokens: z.number().optional(),
|
|
1432
|
+
contextWindow: z.number().optional(),
|
|
1433
|
+
}),
|
|
1434
|
+
);
|
|
1435
|
+
|
|
1436
|
+
const TurnOutcomeSchema = describes<TurnOutcome>()(
|
|
1437
|
+
z.object({
|
|
1438
|
+
changedFiles: z.array(
|
|
1439
|
+
z.object({ path: z.string(), kind: z.enum(["modified", "deleted"]) }),
|
|
1440
|
+
),
|
|
1441
|
+
usage: AgentTurnUsageSchema.optional(),
|
|
1442
|
+
storeSync: JsonObjectSchema.optional(),
|
|
1443
|
+
workspaceSync: z.object({ error: z.string() }).optional(),
|
|
1444
|
+
notification: z
|
|
1445
|
+
.object({ title: z.string().optional(), body: z.string().optional() })
|
|
1446
|
+
.optional(),
|
|
1447
|
+
}),
|
|
1448
|
+
);
|
|
1449
|
+
|
|
1450
|
+
export const TurnSchema = describes<Turn>()(
|
|
1451
|
+
z
|
|
1452
|
+
.object({
|
|
1453
|
+
id: z.string(),
|
|
1454
|
+
sessionId: z.string(),
|
|
1455
|
+
ordinal: z.number().int(),
|
|
1456
|
+
status: z.enum([
|
|
1457
|
+
"queued",
|
|
1458
|
+
"held",
|
|
1459
|
+
"preparing",
|
|
1460
|
+
"running",
|
|
1461
|
+
"waiting",
|
|
1462
|
+
"finalizing",
|
|
1463
|
+
"completed",
|
|
1464
|
+
"failed",
|
|
1465
|
+
"interrupted",
|
|
1466
|
+
"cancelled",
|
|
1467
|
+
"rolled_back",
|
|
1468
|
+
]),
|
|
1469
|
+
inputItemId: z.string().nullable(),
|
|
1470
|
+
dispatch: z.enum(["queue", "interrupt"]),
|
|
1471
|
+
priority: z.number(),
|
|
1472
|
+
activity: z.string().nullable(),
|
|
1473
|
+
activityAt: z.string().nullable(),
|
|
1474
|
+
attemptCount: z.number().int(),
|
|
1475
|
+
activeAttemptId: z.string().nullable(),
|
|
1476
|
+
providerThreadId: z.string().nullable(),
|
|
1477
|
+
retryAt: z.string().nullable(),
|
|
1478
|
+
cancellationRequested: z.boolean(),
|
|
1479
|
+
error: TurnErrorSchema.nullable(),
|
|
1480
|
+
outcome: TurnOutcomeSchema.nullable(),
|
|
1481
|
+
checkpoint: z.object({
|
|
1482
|
+
before: z.string().nullable(),
|
|
1483
|
+
after: z.string().nullable(),
|
|
1484
|
+
}),
|
|
1485
|
+
continuationOf: z.string().nullable(),
|
|
1486
|
+
createdAt: z.string(),
|
|
1487
|
+
startedAt: z.string().nullable(),
|
|
1488
|
+
completedAt: z.string().nullable(),
|
|
1489
|
+
updatedAt: z.string(),
|
|
1490
|
+
})
|
|
1491
|
+
.meta({ id: "Turn" }),
|
|
1492
|
+
);
|
|
1493
|
+
|
|
1494
|
+
export const AttemptSchema = describes<Attempt>()(
|
|
1495
|
+
z
|
|
1496
|
+
.object({
|
|
1497
|
+
id: z.string(),
|
|
1498
|
+
turnId: z.string(),
|
|
1499
|
+
sessionId: z.string(),
|
|
1500
|
+
ordinal: z.number().int(),
|
|
1501
|
+
reason: z.enum(["initial", "retry", "steer_restart", "recovery"]),
|
|
1502
|
+
status: z.enum([
|
|
1503
|
+
"preparing",
|
|
1504
|
+
"running",
|
|
1505
|
+
"completed",
|
|
1506
|
+
"failed",
|
|
1507
|
+
"interrupted",
|
|
1508
|
+
"lost",
|
|
1509
|
+
"superseded",
|
|
1510
|
+
]),
|
|
1511
|
+
providerThreadId: z.string().nullable(),
|
|
1512
|
+
nativeTurnRef: NativeRefSchema.nullable(),
|
|
1513
|
+
error: TurnErrorSchema.nullable(),
|
|
1514
|
+
createdAt: z.string(),
|
|
1515
|
+
startedAt: z.string().nullable(),
|
|
1516
|
+
completedAt: z.string().nullable(),
|
|
1517
|
+
})
|
|
1518
|
+
.meta({ id: "Attempt" }),
|
|
1519
|
+
);
|
|
1520
|
+
|
|
1521
|
+
/** The identity and placement Work assigns every item. */
|
|
1522
|
+
const itemCommon = {
|
|
1523
|
+
id: z.string(),
|
|
1524
|
+
sessionId: z.string(),
|
|
1525
|
+
turnId: z.string().nullable(),
|
|
1526
|
+
attemptId: z.string().nullable(),
|
|
1527
|
+
parentItemId: z.string().nullable(),
|
|
1528
|
+
position: z.number().int(),
|
|
1529
|
+
status: z.enum(["in_progress", "completed", "failed", "cancelled"]),
|
|
1530
|
+
nativeRef: NativeRefSchema.nullable(),
|
|
1531
|
+
createdAt: z.string(),
|
|
1532
|
+
updatedAt: z.string(),
|
|
1533
|
+
startedAt: z.string().nullable(),
|
|
1534
|
+
endedAt: z.string().nullable(),
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1537
|
+
/** What every delivered input carries (ADR 0217). */
|
|
1538
|
+
const deliveryFields = {
|
|
1539
|
+
dispatch: DispatchModeSchema,
|
|
1540
|
+
attention: z.literal("required").nullable(),
|
|
1541
|
+
idempotencyKey: z.string().nullable(),
|
|
1542
|
+
deliveredBy: z.string().nullable(),
|
|
1543
|
+
causation: z.array(z.string()),
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
export const ItemSchema = describes<Item>()(
|
|
1547
|
+
z
|
|
1548
|
+
.discriminatedUnion("kind", [
|
|
1549
|
+
z.object({
|
|
1550
|
+
...itemCommon,
|
|
1551
|
+
...deliveryFields,
|
|
1552
|
+
kind: z.literal("user_message"),
|
|
1553
|
+
author: z.object({
|
|
1554
|
+
kind: z.literal("user"),
|
|
1555
|
+
externalUserId: z.string(),
|
|
1556
|
+
}),
|
|
1557
|
+
text: z.string(),
|
|
1558
|
+
attachments: z.array(attachmentSchema),
|
|
1559
|
+
answer: questionAnswerSchema.optional(),
|
|
1560
|
+
}),
|
|
1561
|
+
z.object({
|
|
1562
|
+
...itemCommon,
|
|
1563
|
+
...deliveryFields,
|
|
1564
|
+
kind: z.literal("inbound_message"),
|
|
1565
|
+
from: InboundSenderSchema,
|
|
1566
|
+
text: z.string(),
|
|
1567
|
+
attachments: z.array(attachmentSchema),
|
|
1568
|
+
alert: settledAlertSchema.optional(),
|
|
1569
|
+
}),
|
|
1570
|
+
z.object({
|
|
1571
|
+
...itemCommon,
|
|
1572
|
+
...deliveryFields,
|
|
1573
|
+
kind: z.literal("task_notification"),
|
|
1574
|
+
task: z.object({
|
|
1575
|
+
type: z.string(),
|
|
1576
|
+
id: z.string(),
|
|
1577
|
+
title: z.string(),
|
|
1578
|
+
status: taskNotificationStatusSchema,
|
|
1579
|
+
}),
|
|
1580
|
+
summary: z.string(),
|
|
1581
|
+
detail: z.string(),
|
|
1582
|
+
source: InputSourceSchema.nullable(),
|
|
1583
|
+
}),
|
|
1584
|
+
z.object({
|
|
1585
|
+
...itemCommon,
|
|
1586
|
+
kind: z.literal("assistant_message"),
|
|
1587
|
+
text: z.string(),
|
|
1588
|
+
agentId: z.string().nullable(),
|
|
1589
|
+
}),
|
|
1590
|
+
z.object({
|
|
1591
|
+
...itemCommon,
|
|
1592
|
+
kind: z.literal("reasoning"),
|
|
1593
|
+
text: z.string(),
|
|
1594
|
+
}),
|
|
1595
|
+
z.object({
|
|
1596
|
+
...itemCommon,
|
|
1597
|
+
kind: z.literal("tool_call"),
|
|
1598
|
+
tool: z.string(),
|
|
1599
|
+
server: z.string().nullable(),
|
|
1600
|
+
description: z.string().nullable(),
|
|
1601
|
+
input: JsonValueSchema,
|
|
1602
|
+
result: JsonValueSchema.nullable(),
|
|
1603
|
+
error: z.string().nullable(),
|
|
1604
|
+
}),
|
|
1605
|
+
z.object({
|
|
1606
|
+
...itemCommon,
|
|
1607
|
+
kind: z.literal("command"),
|
|
1608
|
+
command: z.string(),
|
|
1609
|
+
description: z.string().nullable(),
|
|
1610
|
+
output: z.string(),
|
|
1611
|
+
exitCode: z.number().int().nullable(),
|
|
1612
|
+
}),
|
|
1613
|
+
z.object({
|
|
1614
|
+
...itemCommon,
|
|
1615
|
+
kind: z.literal("file_change"),
|
|
1616
|
+
path: z.string(),
|
|
1617
|
+
change: z
|
|
1618
|
+
.enum(["created", "modified", "deleted", "renamed"])
|
|
1619
|
+
.nullable(),
|
|
1620
|
+
previousPath: z.string().nullable(),
|
|
1621
|
+
}),
|
|
1622
|
+
z.object({
|
|
1623
|
+
...itemCommon,
|
|
1624
|
+
kind: z.literal("plan"),
|
|
1625
|
+
steps: z.array(
|
|
1626
|
+
z.object({
|
|
1627
|
+
text: z.string(),
|
|
1628
|
+
status: z.enum(["pending", "in_progress", "completed"]),
|
|
1629
|
+
}),
|
|
1630
|
+
),
|
|
1631
|
+
}),
|
|
1632
|
+
z.object({
|
|
1633
|
+
...itemCommon,
|
|
1634
|
+
kind: z.literal("request"),
|
|
1635
|
+
requestId: z.string(),
|
|
1636
|
+
}),
|
|
1637
|
+
z.object({
|
|
1638
|
+
...itemCommon,
|
|
1639
|
+
kind: z.literal("subagent"),
|
|
1640
|
+
title: z.string(),
|
|
1641
|
+
agentType: z.string().nullable(),
|
|
1642
|
+
childSessionId: z.string().nullable(),
|
|
1643
|
+
result: z.string().nullable(),
|
|
1644
|
+
}),
|
|
1645
|
+
z.object({
|
|
1646
|
+
...itemCommon,
|
|
1647
|
+
kind: z.literal("notice"),
|
|
1648
|
+
code: z.string(),
|
|
1649
|
+
text: z.string(),
|
|
1650
|
+
data: JsonObjectSchema,
|
|
1651
|
+
}),
|
|
1652
|
+
z.object({
|
|
1653
|
+
...itemCommon,
|
|
1654
|
+
kind: z.literal("context_handoff"),
|
|
1655
|
+
strategy: z.enum(["delta", "full"]),
|
|
1656
|
+
fromProviderThreadIds: z.array(z.string()),
|
|
1657
|
+
toProviderThreadId: z.string(),
|
|
1658
|
+
coveredTurnOrdinals: z.object({
|
|
1659
|
+
from: z.number().int(),
|
|
1660
|
+
to: z.number().int(),
|
|
1661
|
+
}),
|
|
1662
|
+
text: z.string(),
|
|
1663
|
+
}),
|
|
1664
|
+
])
|
|
1665
|
+
.meta({ id: "Item" }),
|
|
1666
|
+
);
|
|
1667
|
+
|
|
1668
|
+
/** An answer to a runtime request; the protocol's own schema, typed exactly. */
|
|
1669
|
+
const RuntimeRequestResponseSchema = describes<RuntimeRequestResponse>()(
|
|
1670
|
+
z.discriminatedUnion("kind", [
|
|
1671
|
+
z.object({
|
|
1672
|
+
kind: z.literal("approval"),
|
|
1673
|
+
decision: z.enum(["approved", "denied"]),
|
|
1674
|
+
remember: z.literal("always").optional(),
|
|
1675
|
+
/** Why Work denied it when no person did: told to the agent. */
|
|
1676
|
+
reason: z.string().optional(),
|
|
1677
|
+
}),
|
|
1678
|
+
z.object({
|
|
1679
|
+
kind: z.literal("question"),
|
|
1680
|
+
answers: z.array(z.string()),
|
|
1681
|
+
/** Each answer's pills, in the order of its markers (ADR 0244). */
|
|
1682
|
+
attachments: z.array(z.array(attachmentSchema)).optional(),
|
|
1683
|
+
}),
|
|
1684
|
+
z.object({
|
|
1685
|
+
kind: z.literal("elicitation"),
|
|
1686
|
+
action: z.enum(["accept", "decline", "cancel"]),
|
|
1687
|
+
content: JsonValueSchema.optional(),
|
|
1688
|
+
}),
|
|
1689
|
+
]),
|
|
1690
|
+
);
|
|
1691
|
+
|
|
1692
|
+
export const RuntimeRequestSchema = describes<RuntimeRequest>()(
|
|
1693
|
+
z
|
|
1694
|
+
.object({
|
|
1695
|
+
id: z.string(),
|
|
1696
|
+
sessionId: z.string(),
|
|
1697
|
+
turnId: z.string().nullable(),
|
|
1698
|
+
attemptId: z.string().nullable(),
|
|
1699
|
+
itemId: z.string().nullable(),
|
|
1700
|
+
kind: z.enum(["question", "approval", "elicitation"]),
|
|
1701
|
+
status: z.enum(["pending", "resolved", "expired", "cancelled"]),
|
|
1702
|
+
answerable: z.boolean(),
|
|
1703
|
+
blocking: z.boolean(),
|
|
1704
|
+
title: z.string(),
|
|
1705
|
+
description: z.string().nullable(),
|
|
1706
|
+
origin: z.object({
|
|
1707
|
+
kind: z.enum(["tool", "provider", "mcp", "host"]),
|
|
1708
|
+
id: z.string(),
|
|
1709
|
+
displayName: z.string().optional(),
|
|
1710
|
+
}),
|
|
1711
|
+
questions: z.array(agentQuestionSchema).nullable(),
|
|
1712
|
+
approval: z
|
|
1713
|
+
.object({
|
|
1714
|
+
action: z.string(),
|
|
1715
|
+
details: z.string().optional(),
|
|
1716
|
+
tool: z
|
|
1717
|
+
.object({
|
|
1718
|
+
server: z.string().nullable(),
|
|
1719
|
+
name: z.string(),
|
|
1720
|
+
input: JsonValueSchema,
|
|
1721
|
+
})
|
|
1722
|
+
.optional(),
|
|
1723
|
+
})
|
|
1724
|
+
.nullable(),
|
|
1725
|
+
elicitation: z
|
|
1726
|
+
.object({
|
|
1727
|
+
server: z.string(),
|
|
1728
|
+
message: z.string(),
|
|
1729
|
+
schema: JsonObjectSchema.optional(),
|
|
1730
|
+
url: z.string().optional(),
|
|
1731
|
+
})
|
|
1732
|
+
.nullable(),
|
|
1733
|
+
approvers: z.array(z.string()),
|
|
1734
|
+
expiresAt: z.string().nullable(),
|
|
1735
|
+
response: RuntimeRequestResponseSchema.nullable(),
|
|
1736
|
+
resolvedBy: z.string().nullable(),
|
|
1737
|
+
reason: z.string().nullable(),
|
|
1738
|
+
createdAt: z.string(),
|
|
1739
|
+
resolvedAt: z.string().nullable(),
|
|
1740
|
+
runnerKey: z.string().optional(),
|
|
1741
|
+
})
|
|
1742
|
+
.meta({ id: "RuntimeRequest" }),
|
|
1743
|
+
);
|
|
1744
|
+
|
|
1745
|
+
export const ProviderThreadSchema = describes<ProviderThread>()(
|
|
1746
|
+
z
|
|
1747
|
+
.object({
|
|
1748
|
+
id: z.string(),
|
|
1749
|
+
sessionId: z.string(),
|
|
1750
|
+
harness: z.string(),
|
|
1751
|
+
nativeRef: NativeRefSchema.nullable(),
|
|
1752
|
+
status: z.enum(["active", "unavailable", "closed"]),
|
|
1753
|
+
lastTurnOrdinal: z.number().int().nullable(),
|
|
1754
|
+
portable: z.boolean(),
|
|
1755
|
+
createdAt: z.string(),
|
|
1756
|
+
updatedAt: z.string(),
|
|
1757
|
+
})
|
|
1758
|
+
.meta({ id: "ProviderThread" }),
|
|
1759
|
+
);
|
|
1760
|
+
|
|
1761
|
+
/** A session's metadata (ADR 0226): values by key, each any JSON. */
|
|
1762
|
+
export const SessionMetadataSchema = describes<SessionMetadata>()(
|
|
1763
|
+
z.record(z.string(), JsonValueSchema).meta({ id: "SessionMetadata" }),
|
|
1764
|
+
);
|
|
1765
|
+
|
|
1766
|
+
/** A session's shared fields, what every viewer sees alike. */
|
|
1767
|
+
export const SessionFieldsSchema = describes<SessionFields>()(
|
|
1768
|
+
z
|
|
1769
|
+
.object({
|
|
1770
|
+
id: z.string(),
|
|
1771
|
+
projectId: z.string(),
|
|
1772
|
+
title: z.string().nullable(),
|
|
1773
|
+
icon: z.string().nullable(),
|
|
1774
|
+
agentId: z.string().nullable(),
|
|
1775
|
+
harness: z.string().nullable(),
|
|
1776
|
+
model: z.string().nullable(),
|
|
1777
|
+
modelEffort: AgentEffortSchema.nullable(),
|
|
1778
|
+
status: z.enum(["active", "closed"]),
|
|
1779
|
+
workStatus: z.enum(["open", "completed"]),
|
|
1780
|
+
activity: z.string().nullable(),
|
|
1781
|
+
todos: z.array(AgentTodoSchema),
|
|
1782
|
+
metadata: SessionMetadataSchema,
|
|
1783
|
+
imported: ImportedSessionSchema.nullable().optional(),
|
|
1784
|
+
parentSessionId: z.string().nullable(),
|
|
1785
|
+
forkedFromSessionId: z.string().nullable(),
|
|
1786
|
+
attentionRevision: z.number().int(),
|
|
1787
|
+
environment: z.string().nullable(),
|
|
1788
|
+
authorityHostId: z.string(),
|
|
1789
|
+
authorityRevision: z.number().int(),
|
|
1790
|
+
handoffStatus: z.enum(["none", "pending"]),
|
|
1791
|
+
updatedAt: z.string(),
|
|
1792
|
+
})
|
|
1793
|
+
.meta({ id: "SessionFields" }),
|
|
1794
|
+
);
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* Set named values on a session (ADR 0226): each key takes its value, and
|
|
1798
|
+
* null removes the key. Keys are lowercase words of letters and digits
|
|
1799
|
+
* joined by `_`, `-` or `.`; core bounds the count and sizes.
|
|
1800
|
+
*/
|
|
1801
|
+
export const UpdateAgentSessionMetadataSchema = z.object({
|
|
1802
|
+
metadata: z
|
|
1803
|
+
.record(
|
|
1804
|
+
z
|
|
1805
|
+
.string()
|
|
1806
|
+
.max(SESSION_METADATA_LIMITS.keyLength)
|
|
1807
|
+
.regex(SESSION_METADATA_KEY_PATTERN),
|
|
1808
|
+
JsonValueSchema,
|
|
1809
|
+
)
|
|
1810
|
+
.describe("Values by key; null removes a key"),
|
|
1811
|
+
});
|
|
1812
|
+
|
|
1813
|
+
export const AgentSessionMetadataSchema = z.object({
|
|
1814
|
+
metadata: SessionMetadataSchema,
|
|
1815
|
+
});
|
|
1816
|
+
|
|
1817
|
+
export const SessionEventSchema = describes<SessionEvent>()(
|
|
1818
|
+
z
|
|
1819
|
+
.discriminatedUnion("type", [
|
|
1820
|
+
z.object({
|
|
1821
|
+
type: z.literal("session.changed"),
|
|
1822
|
+
session: SessionFieldsSchema.partial(),
|
|
1823
|
+
}),
|
|
1824
|
+
z.object({ type: z.literal("turn.changed"), turn: TurnSchema }),
|
|
1825
|
+
z.object({ type: z.literal("attempt.changed"), attempt: AttemptSchema }),
|
|
1826
|
+
z.object({ type: z.literal("item.added"), item: ItemSchema }),
|
|
1827
|
+
z.object({ type: z.literal("item.changed"), item: ItemSchema }),
|
|
1828
|
+
z.object({
|
|
1829
|
+
type: z.literal("item.text_appended"),
|
|
1830
|
+
itemId: z.string(),
|
|
1831
|
+
field: z.enum(["text", "output"]),
|
|
1832
|
+
text: z.string(),
|
|
1833
|
+
at: z.string(),
|
|
1834
|
+
}),
|
|
1835
|
+
z.object({
|
|
1836
|
+
type: z.literal("request.changed"),
|
|
1837
|
+
request: RuntimeRequestSchema,
|
|
1838
|
+
}),
|
|
1839
|
+
z.object({
|
|
1840
|
+
type: z.literal("provider_thread.changed"),
|
|
1841
|
+
thread: ProviderThreadSchema,
|
|
1842
|
+
}),
|
|
1843
|
+
])
|
|
1844
|
+
.meta({ id: "SessionEvent" }),
|
|
1845
|
+
);
|
|
1846
|
+
|
|
1847
|
+
export const StoredSessionEventSchema = describes<StoredSessionEvent>()(
|
|
1848
|
+
z
|
|
1849
|
+
.object({
|
|
1850
|
+
sessionId: z.string(),
|
|
1851
|
+
sequence: z.number().int().positive(),
|
|
1852
|
+
at: z.string(),
|
|
1853
|
+
commandId: z.string().nullable(),
|
|
1854
|
+
event: SessionEventSchema,
|
|
1855
|
+
})
|
|
1856
|
+
.meta({ id: "StoredSessionEvent" }),
|
|
1857
|
+
);
|
|
1858
|
+
|
|
1859
|
+
export const SessionSnapshotSchema = describes<SessionSnapshot>()(
|
|
1860
|
+
z
|
|
1861
|
+
.object({
|
|
1862
|
+
sequence: z.number().int().nonnegative(),
|
|
1863
|
+
session: SessionFieldsSchema,
|
|
1864
|
+
turns: z.array(TurnSchema),
|
|
1865
|
+
attempts: z.array(AttemptSchema),
|
|
1866
|
+
items: z.array(ItemSchema),
|
|
1867
|
+
requests: z.array(RuntimeRequestSchema),
|
|
1868
|
+
providerThreads: z.array(ProviderThreadSchema),
|
|
1869
|
+
olderBefore: z.number().int().nullable(),
|
|
1870
|
+
})
|
|
1871
|
+
.meta({ id: "SessionSnapshot" }),
|
|
1872
|
+
);
|
|
1873
|
+
|
|
1874
|
+
/** One server-sent event of `GET …/events`, as its `data:` JSON. */
|
|
1875
|
+
export const SessionStreamMessageSchema = describes<SessionStreamMessage>()(
|
|
1876
|
+
z
|
|
1877
|
+
.discriminatedUnion("type", [
|
|
1878
|
+
z.object({
|
|
1879
|
+
type: z.literal("events"),
|
|
1880
|
+
events: z.array(StoredSessionEventSchema),
|
|
1881
|
+
}),
|
|
1882
|
+
z.object({ type: z.literal("reset"), snapshot: SessionSnapshotSchema }),
|
|
1883
|
+
z.object({
|
|
1884
|
+
type: z.literal("heartbeat"),
|
|
1885
|
+
sequence: z.number().int().nonnegative(),
|
|
1886
|
+
}),
|
|
1887
|
+
])
|
|
1888
|
+
.meta({ id: "SessionStreamMessage" }),
|
|
1889
|
+
);
|
|
1890
|
+
|
|
1891
|
+
export const CommandReceiptSchema = describes<CommandReceipt>()(
|
|
1892
|
+
z
|
|
1893
|
+
.object({
|
|
1894
|
+
commandId: z.string(),
|
|
1895
|
+
status: z.enum(["accepted", "rejected"]),
|
|
1896
|
+
sequence: z.number().int().nonnegative(),
|
|
1897
|
+
result: JsonObjectSchema.nullable(),
|
|
1898
|
+
error: z.object({ code: z.string(), message: z.string() }).nullable(),
|
|
1899
|
+
})
|
|
1900
|
+
.meta({ id: "CommandReceipt" }),
|
|
1901
|
+
);
|
|
1902
|
+
|
|
1903
|
+
/** A command to a session; resending one `commandId` returns its first receipt. */
|
|
1904
|
+
export const SessionCommandSchema =
|
|
1905
|
+
describes<SessionCommand>()(sessionCommandSchema);
|
|
1906
|
+
|
|
1907
|
+
export const AgentSessionDetailSchema = AgentSessionSchema.extend({
|
|
1908
|
+
snapshot: SessionSnapshotSchema,
|
|
1909
|
+
});
|
|
1910
|
+
|
|
1911
|
+
export const SessionItemsQuerySchema = z.object({
|
|
1912
|
+
/** Items before this position: a snapshot's or page's `olderBefore`. */
|
|
1913
|
+
before: z.coerce.number().int().positive(),
|
|
1914
|
+
limit: z.coerce.number().int().min(1).max(500).optional(),
|
|
1915
|
+
});
|
|
1916
|
+
|
|
1917
|
+
export const SessionItemsPageSchema = z.object({
|
|
1918
|
+
items: z.array(ItemSchema),
|
|
1919
|
+
olderBefore: z.number().int().nullable(),
|
|
1920
|
+
});
|
|
1921
|
+
|
|
1922
|
+
export const SessionEventsQuerySchema = z.object({
|
|
1923
|
+
/** Stream events after this sequence: a snapshot's `sequence`. */
|
|
1924
|
+
after: z.coerce.number().int().nonnegative().optional(),
|
|
1925
|
+
});
|
|
1926
|
+
|
|
1927
|
+
export const SessionMirrorQuerySchema = z.object({
|
|
1928
|
+
/** The copy's last sequence; omitted for a copy that does not exist yet. */
|
|
1929
|
+
after: z.coerce.number().int().nonnegative().optional(),
|
|
1930
|
+
});
|
|
1931
|
+
|
|
1932
|
+
/** One workflow-facing session event a mirror carries (ADR 0156). */
|
|
1933
|
+
const MirrorProjectEventSchema = z.object({
|
|
1934
|
+
id: z.string().uuid(),
|
|
1935
|
+
kind: z
|
|
1936
|
+
.string()
|
|
1937
|
+
.regex(/^session\./)
|
|
1938
|
+
.max(100),
|
|
1939
|
+
occurredAt: z.string().datetime(),
|
|
1940
|
+
payload: JsonObjectSchema,
|
|
1941
|
+
});
|
|
1942
|
+
|
|
1943
|
+
/**
|
|
1944
|
+
* One mirror push (ADR 0197): the source's log after this copy's sequence,
|
|
1945
|
+
* or, for a copy that does not exist yet, a full snapshot to start from.
|
|
1946
|
+
*/
|
|
1947
|
+
export const MirrorAgentSessionSchema = z.object({
|
|
1948
|
+
authority: z.object({
|
|
1949
|
+
hostId: z.string().min(1).max(255),
|
|
1950
|
+
revision: z.number().int().positive(),
|
|
1951
|
+
}),
|
|
1952
|
+
title: z.string().max(500).nullable().optional(),
|
|
1953
|
+
icon: z.string().max(100).nullable().optional(),
|
|
1954
|
+
/** The surface that originally created the conversation. */
|
|
1955
|
+
source: AgentSessionSourceSchema.optional(),
|
|
1956
|
+
/**
|
|
1957
|
+
* The source session's project-agent slug: the same agent here when
|
|
1958
|
+
* this server has it and the caller's role covers it, else the default.
|
|
1959
|
+
*/
|
|
1960
|
+
agentSlug: z.string().max(200).optional(),
|
|
1961
|
+
todos: z.array(AgentTodoSchema).max(50).optional(),
|
|
1962
|
+
workStatus: z.enum(["open", "completed"]).optional(),
|
|
1963
|
+
/** Every turn, item, request and thread at `base.sequence`, for a new copy. */
|
|
1964
|
+
base: SessionSnapshotSchema.optional(),
|
|
1965
|
+
events: z.array(StoredSessionEventSchema).max(5_000),
|
|
1966
|
+
projectEvents: z.array(MirrorProjectEventSchema).max(5_000).optional(),
|
|
1967
|
+
});
|
|
1968
|
+
|
|
1969
|
+
export const MirrorAgentSessionResultSchema = z.object({
|
|
1970
|
+
session: AgentSessionSchema,
|
|
1971
|
+
/** The copy's last event sequence after the push. */
|
|
1972
|
+
sequence: z.number().int().nonnegative(),
|
|
1973
|
+
/** Why a newly mirrored chat continues with another agent than the one it ran. */
|
|
1974
|
+
agentNotice: z.string().optional(),
|
|
1975
|
+
});
|
|
1976
|
+
|
|
1977
|
+
export const MirrorExportSchema = z.object({
|
|
1978
|
+
/** The whole session, when the copy is new or too far behind for events. */
|
|
1979
|
+
base: SessionSnapshotSchema.optional(),
|
|
1980
|
+
events: z.array(StoredSessionEventSchema),
|
|
1981
|
+
projectEvents: z.array(MirrorProjectEventSchema).optional(),
|
|
1982
|
+
});
|
|
1983
|
+
|
|
1984
|
+
/**
|
|
1985
|
+
* Why a mirror push was refused: `diverged` (the chat continued here, so
|
|
1986
|
+
* stop pushing), `behind` (the copy ends at `sequence`, so resend from
|
|
1987
|
+
* there), or `turn_in_progress` (a turn runs here; push when it settles).
|
|
1988
|
+
*/
|
|
1989
|
+
export const MirrorConflictSchema = z.discriminatedUnion("code", [
|
|
1990
|
+
z.object({ error: z.string(), code: z.literal("diverged") }),
|
|
1991
|
+
z.object({
|
|
1992
|
+
error: z.string(),
|
|
1993
|
+
code: z.literal("behind"),
|
|
1994
|
+
sequence: z.number().int().nonnegative(),
|
|
1995
|
+
}),
|
|
1996
|
+
z.object({ error: z.string(), code: z.literal("turn_in_progress") }),
|
|
1997
|
+
]);
|
|
1998
|
+
|
|
1999
|
+
/** Continue a mirrored chat here, taking its authority (ADR 0077). */
|
|
2000
|
+
export const ResumeAgentSessionSchema = z.object({
|
|
2001
|
+
expectedAuthorityRevision: z.number().int().positive(),
|
|
2002
|
+
});
|
|
2003
|
+
|
|
2004
|
+
export const ForkAgentSessionSchema = z.object({
|
|
2005
|
+
/**
|
|
2006
|
+
* Fork point: the item (ADR 0197) the transcript is copied through,
|
|
2007
|
+
* with the turn it belongs to. Omitted = every settled turn.
|
|
2008
|
+
*/
|
|
2009
|
+
messageId: z.string().min(1).max(200).optional(),
|
|
2010
|
+
});
|
|
2011
|
+
|
|
2012
|
+
const mailboxCommon = {
|
|
2013
|
+
id: z.string().uuid(),
|
|
2014
|
+
projectId: z.string().uuid(),
|
|
2015
|
+
sessionId: z.string().uuid(),
|
|
2016
|
+
sourceHostId: z.string(),
|
|
2017
|
+
destinationHostId: z.string(),
|
|
2018
|
+
authorityRevision: z.number().int().positive(),
|
|
2019
|
+
/** The item the delivery becomes on the destination (ADR 0197). */
|
|
2020
|
+
messageId: z.string().uuid(),
|
|
2021
|
+
idempotencyKey: z.string().nullable(),
|
|
2022
|
+
causation: z.array(z.string()),
|
|
2023
|
+
createdAt: z.string().datetime(),
|
|
2024
|
+
};
|
|
2025
|
+
|
|
2026
|
+
/** What crosses to a session's authority (ADR 0219): an input, or an action. */
|
|
2027
|
+
export const SessionMailboxItemSchema = describes<SessionMailboxItem>()(
|
|
2028
|
+
z.discriminatedUnion("kind", [
|
|
2029
|
+
z.object({
|
|
2030
|
+
...mailboxCommon,
|
|
2031
|
+
kind: z.literal("input"),
|
|
2032
|
+
input: SessionInputSchema,
|
|
2033
|
+
mode: DispatchModeSchema,
|
|
2034
|
+
attention: z.boolean(),
|
|
2035
|
+
deliveredBy: z.string().nullable(),
|
|
2036
|
+
ownerAuthored: z.boolean(),
|
|
2037
|
+
}),
|
|
2038
|
+
z.object({
|
|
2039
|
+
...mailboxCommon,
|
|
2040
|
+
kind: z.literal("action"),
|
|
2041
|
+
action: z.object({
|
|
2042
|
+
operation: z.string(),
|
|
2043
|
+
args: JsonValueSchema,
|
|
2044
|
+
actor: SessionMessageAuthorSchema,
|
|
2045
|
+
}),
|
|
2046
|
+
}),
|
|
2047
|
+
]),
|
|
2048
|
+
);
|
|
2049
|
+
|
|
2050
|
+
export const SessionMailboxListQuerySchema = z.object({
|
|
2051
|
+
destinationHostId: z.string().min(1).max(255),
|
|
2052
|
+
limit: z.coerce.number().int().min(1).max(500).optional(),
|
|
2053
|
+
});
|
|
2054
|
+
export const SessionMailboxListSchema = z.object({
|
|
2055
|
+
items: z.array(SessionMailboxItemSchema),
|
|
2056
|
+
});
|
|
2057
|
+
|
|
2058
|
+
export const SessionMailboxIdParamsSchema = ProjectIdParamsSchema.extend({
|
|
2059
|
+
mailboxId: z.string().uuid(),
|
|
2060
|
+
});
|
|
2061
|
+
|
|
2062
|
+
export const AcknowledgeSessionMailboxSchema = z.object({
|
|
2063
|
+
destinationHostId: z.string().min(1).max(255),
|
|
2064
|
+
});
|
|
2065
|
+
|
|
2066
|
+
export const WatcherSchema = z.object({
|
|
2067
|
+
lastRun: z
|
|
2068
|
+
.object({
|
|
2069
|
+
id: z.string().uuid(),
|
|
2070
|
+
status: z.string(),
|
|
2071
|
+
error: z.string().nullable(),
|
|
2072
|
+
})
|
|
2073
|
+
.nullable(),
|
|
2074
|
+
id: z.string().uuid(),
|
|
2075
|
+
projectId: z.string().uuid(),
|
|
2076
|
+
sessionId: z.string().uuid(),
|
|
2077
|
+
monitorId: z.string().uuid().nullable(),
|
|
2078
|
+
workflowName: z.string(),
|
|
2079
|
+
sourcePath: z.string(),
|
|
2080
|
+
remoteBranch: z.string(),
|
|
2081
|
+
commitSha: z.string().length(40),
|
|
2082
|
+
deploymentArtifactId: z.string().uuid(),
|
|
2083
|
+
environment: z.string().nullable(),
|
|
2084
|
+
triggerKinds: z.array(z.string()),
|
|
2085
|
+
cursorSequence: z.number().int().nonnegative(),
|
|
2086
|
+
status: z.enum(["active", "paused", "stopped", "expired"]),
|
|
2087
|
+
expiresAt: z.string().datetime().nullable(),
|
|
2088
|
+
nextRunAt: z.string().datetime().nullable(),
|
|
2089
|
+
lastError: z.string().nullable(),
|
|
2090
|
+
createdAt: z.string().datetime(),
|
|
2091
|
+
});
|
|
2092
|
+
|
|
2093
|
+
export const WatcherIdParamsSchema = AgentSessionIdParamsSchema.extend({
|
|
2094
|
+
watcherId: z.string().uuid(),
|
|
2095
|
+
});
|
|
2096
|
+
|
|
2097
|
+
export const OkSchema = z.object({ ok: z.literal(true) });
|
|
2098
|
+
|
|
2099
|
+
// --- Terminals in a chat's workspace (ADR 0209) ---
|
|
2100
|
+
|
|
2101
|
+
const TerminalSizeSchema = z.number().int().min(1).max(1000);
|
|
2102
|
+
|
|
2103
|
+
export const SessionTerminalParamsSchema = AgentSessionIdParamsSchema.extend({
|
|
2104
|
+
/** The terminal's process in the workspace's sandbox. */
|
|
2105
|
+
terminalId: z.string().regex(/^proc-[a-z0-9]{8,32}$/),
|
|
2106
|
+
});
|
|
2107
|
+
|
|
2108
|
+
export const OpenSessionTerminalSchema = z.object({
|
|
2109
|
+
cols: TerminalSizeSchema.default(80),
|
|
2110
|
+
rows: TerminalSizeSchema.default(24),
|
|
2111
|
+
});
|
|
2112
|
+
|
|
2113
|
+
export const SessionTerminalSchema = z.object({
|
|
2114
|
+
terminalId: z.string(),
|
|
2115
|
+
/**
|
|
2116
|
+
* The shell runs on a pseudo-terminal. Without one it is an interactive
|
|
2117
|
+
* shell on a pipe: line by line, and resizing does nothing.
|
|
2118
|
+
*/
|
|
2119
|
+
pty: z.boolean(),
|
|
2120
|
+
});
|
|
2121
|
+
|
|
2122
|
+
export const SessionTerminalOutputQuerySchema = z.object({
|
|
2123
|
+
cursor: z.coerce.number().int().min(0).default(0),
|
|
2124
|
+
/** Answer as soon as there is output, at the latest after this long. */
|
|
2125
|
+
waitMs: z.coerce.number().int().min(0).max(20_000).default(0),
|
|
2126
|
+
});
|
|
2127
|
+
|
|
2128
|
+
export const SessionTerminalOutputSchema = z.object({
|
|
2129
|
+
/** UTF-8 text from `cursor` to `nextCursor`. */
|
|
2130
|
+
data: z.string(),
|
|
2131
|
+
cursor: z.number().int().nonnegative(),
|
|
2132
|
+
nextCursor: z.number().int().nonnegative(),
|
|
2133
|
+
/** More output waits past `nextCursor`; read again at once. */
|
|
2134
|
+
more: z.boolean(),
|
|
2135
|
+
/** The shell ended and all its output has been read. */
|
|
2136
|
+
exited: z.boolean(),
|
|
2137
|
+
exitCode: z.number().int().nullable(),
|
|
2138
|
+
});
|
|
2139
|
+
|
|
2140
|
+
export const SessionTerminalInputSchema = z.object({
|
|
2141
|
+
/** Keys as the terminal sends them, control characters included. */
|
|
2142
|
+
data: z
|
|
2143
|
+
.string()
|
|
2144
|
+
.min(1)
|
|
2145
|
+
.max(1024 * 1024),
|
|
2146
|
+
});
|
|
2147
|
+
|
|
2148
|
+
export const ResizeSessionTerminalSchema = z.object({
|
|
2149
|
+
cols: TerminalSizeSchema,
|
|
2150
|
+
rows: TerminalSizeSchema,
|
|
2151
|
+
});
|
|
2152
|
+
|
|
2153
|
+
/** Why a chat's workspace is not open to a person right now (409). */
|
|
2154
|
+
export const SessionWorkspaceErrorSchema = z.object({
|
|
2155
|
+
error: z.string(),
|
|
2156
|
+
code: z.string(),
|
|
2157
|
+
});
|
|
2158
|
+
|
|
2159
|
+
// --- Skills ---
|
|
2160
|
+
export const SkillSchema = z.object({
|
|
2161
|
+
name: z.string(),
|
|
2162
|
+
/** Human-facing name (frontmatter `title`, else the humanized slug). */
|
|
2163
|
+
title: z.string(),
|
|
2164
|
+
description: z.string(),
|
|
2165
|
+
/** Frontmatter `argument-hint`: what an invocation's instructions say. */
|
|
2166
|
+
argumentHint: z.string().optional(),
|
|
2167
|
+
path: z.string(),
|
|
2168
|
+
source: z.enum(["project", "user", "host"]),
|
|
2169
|
+
});
|
|
2170
|
+
|
|
2171
|
+
/** A harness's own permission settings, in its native values (ADR 0182). */
|
|
2172
|
+
export const HarnessPermissionsSchema = z.object({
|
|
2173
|
+
permissionMode: z.enum(CLAUDE_CODE_PERMISSION_MODES).optional(),
|
|
2174
|
+
sandbox: z.enum(CODEX_SANDBOX_MODES).optional(),
|
|
2175
|
+
approvals: z.enum(CODEX_APPROVAL_POLICIES).optional(),
|
|
2176
|
+
});
|
|
2177
|
+
|
|
2178
|
+
// --- Project agent definitions (ADR 0050) ---
|
|
2179
|
+
// Committed `.work/agents/<slug>.json` files, parsed and validated by core's
|
|
2180
|
+
// AgentDefinitionsService. Broken files come back as invalid entries with
|
|
2181
|
+
// the error — never a failed request.
|
|
2182
|
+
export const ProjectAgentDefinitionSchema = z.object({
|
|
2183
|
+
version: z.number(),
|
|
2184
|
+
name: z.string(),
|
|
2185
|
+
kind: z.string(),
|
|
2186
|
+
model: z.string().optional(),
|
|
2187
|
+
effort: AgentEffortSchema.optional(),
|
|
2188
|
+
/** What may leave the agent's sandbox (ADR 0182). */
|
|
2189
|
+
sandboxing: z.enum(SANDBOXING_LEVELS).optional(),
|
|
2190
|
+
/** The harness's own permission mode, in its native values (ADR 0182). */
|
|
2191
|
+
harnessPermissions: HarnessPermissionsSchema.optional(),
|
|
2192
|
+
memory: z.boolean().optional(),
|
|
2193
|
+
description: z.string().optional(),
|
|
2194
|
+
credentials: z
|
|
2195
|
+
.object({
|
|
2196
|
+
source: z.enum(["profile", "secret", "local", "connection", "personal"]),
|
|
2197
|
+
secret: z.string().optional(),
|
|
2198
|
+
/** The Environment alias of the agent's model connection (ADR 0180). */
|
|
2199
|
+
connection: z.string().optional(),
|
|
2200
|
+
})
|
|
2201
|
+
.optional(),
|
|
2202
|
+
connections: z
|
|
2203
|
+
.array(
|
|
2204
|
+
z.union([
|
|
2205
|
+
z.string(),
|
|
2206
|
+
z.object({
|
|
2207
|
+
alias: z.string(),
|
|
2208
|
+
principal: z.enum(["member", "service", "either"]).optional(),
|
|
2209
|
+
capabilities: z.array(z.string()).optional(),
|
|
2210
|
+
optional: z.boolean().optional(),
|
|
2211
|
+
}),
|
|
2212
|
+
]),
|
|
2213
|
+
)
|
|
2214
|
+
.optional(),
|
|
2215
|
+
skills: z.array(z.string()).optional(),
|
|
2216
|
+
acp: z
|
|
2217
|
+
.object({
|
|
2218
|
+
endpoint: z.string().optional(),
|
|
2219
|
+
command: z.array(z.string()).optional(),
|
|
2220
|
+
})
|
|
2221
|
+
.optional(),
|
|
2222
|
+
});
|
|
2223
|
+
|
|
2224
|
+
export const ProjectAgentEntrySchema = z.object({
|
|
2225
|
+
slug: z.string(),
|
|
2226
|
+
definition: ProjectAgentDefinitionSchema.optional(),
|
|
2227
|
+
/** Content of the sibling `.work/agents/<slug>.md` persona file. */
|
|
2228
|
+
promptFile: z.string().optional(),
|
|
2229
|
+
invalid: z.object({ error: z.string() }).optional(),
|
|
2230
|
+
});
|
|
2231
|
+
|
|
2232
|
+
// --- Roles & memberships (ADR 0055) ---
|
|
2233
|
+
// The role file schema is core's (`RoleDefinitionSchema`): one definition,
|
|
2234
|
+
// so the OpenAPI spec and runtime validation can never disagree.
|
|
2235
|
+
export const RoleDefinitionSchema = CoreRoleDefinitionSchema;
|
|
2236
|
+
|
|
2237
|
+
export const ProjectRoleEntrySchema = z.object({
|
|
2238
|
+
slug: z.string(),
|
|
2239
|
+
definition: RoleDefinitionSchema.optional(),
|
|
2240
|
+
invalid: z.object({ error: z.string() }).optional(),
|
|
2241
|
+
});
|
|
2242
|
+
|
|
2243
|
+
export const MembershipSchema = z.object({
|
|
2244
|
+
projectId: z.string(),
|
|
2245
|
+
externalUserId: z.string(),
|
|
2246
|
+
roles: z.array(z.string()),
|
|
2247
|
+
grants: z.record(z.string(), z.array(z.string())),
|
|
2248
|
+
createdAt: z.string(),
|
|
2249
|
+
updatedAt: z.string(),
|
|
2250
|
+
});
|
|
2251
|
+
|
|
2252
|
+
export const MembershipParamsSchema = ProjectIdParamsSchema.extend({
|
|
2253
|
+
externalUserId: z.string().min(1).max(128),
|
|
2254
|
+
});
|
|
2255
|
+
|
|
2256
|
+
export const GrantMembershipSchema = z.object({
|
|
2257
|
+
roles: z.array(z.string().min(1)),
|
|
2258
|
+
grants: z.record(z.string().min(1), z.array(z.string())).optional(),
|
|
2259
|
+
});
|
|
2260
|
+
|
|
2261
|
+
// --- Documents (ADR 0055) ---
|
|
2262
|
+
export const DocumentEntrySchema = z.object({
|
|
2263
|
+
path: z.string(),
|
|
2264
|
+
source: z.enum(["program", "store"]),
|
|
2265
|
+
contentType: z.string(),
|
|
2266
|
+
size: z.number(),
|
|
2267
|
+
version: z.number().optional(),
|
|
2268
|
+
writtenBy: z.string().optional(),
|
|
2269
|
+
writtenAt: z.string().optional(),
|
|
2270
|
+
digest: z.string().optional(),
|
|
2271
|
+
/** Program only: the published commit the listing read (ADR 0191). */
|
|
2272
|
+
commit: z.string().optional(),
|
|
2273
|
+
});
|
|
2274
|
+
|
|
2275
|
+
export const DocumentContentSchema = DocumentEntrySchema.extend({
|
|
2276
|
+
/** UTF-8 text when the document is text-like; absent for binaries. */
|
|
2277
|
+
text: z.string().optional(),
|
|
2278
|
+
});
|
|
2279
|
+
|
|
2280
|
+
export const DocumentVersionSchema = z.object({
|
|
2281
|
+
version: z.number(),
|
|
2282
|
+
deleted: z.boolean(),
|
|
2283
|
+
contentType: z.string(),
|
|
2284
|
+
size: z.number(),
|
|
2285
|
+
writtenBy: z.string(),
|
|
2286
|
+
writtenAt: z.string(),
|
|
2287
|
+
});
|
|
2288
|
+
|
|
2289
|
+
export const DocumentMatchSchema = z.object({
|
|
2290
|
+
path: z.string(),
|
|
2291
|
+
source: z.enum(["program", "store"]),
|
|
2292
|
+
lines: z.array(z.object({ line: z.number(), text: z.string() })),
|
|
2293
|
+
});
|
|
2294
|
+
|
|
2295
|
+
export const WriteDocumentSchema = z
|
|
2296
|
+
.object({
|
|
2297
|
+
path: z.string().min(1),
|
|
2298
|
+
/** UTF-8 text content — or `base64` for bytes; exactly one. */
|
|
2299
|
+
text: z.string().optional(),
|
|
2300
|
+
base64: z
|
|
2301
|
+
.string()
|
|
2302
|
+
.regex(
|
|
2303
|
+
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,
|
|
2304
|
+
"Invalid base64 file content",
|
|
2305
|
+
)
|
|
2306
|
+
.optional(),
|
|
2307
|
+
contentType: z.string().optional(),
|
|
2308
|
+
/** Write only if the document is at this version (0 = does not exist). */
|
|
2309
|
+
ifVersion: z.number().int().nonnegative().optional(),
|
|
2310
|
+
})
|
|
2311
|
+
.refine((v) => (v.text !== undefined) !== (v.base64 !== undefined), {
|
|
2312
|
+
message: "Provide exactly one of text or base64",
|
|
2313
|
+
});
|
|
2314
|
+
|
|
2315
|
+
// --- Proposals (ADR 0055) ---
|
|
2316
|
+
export const ProposeChangeSchema = z.object({
|
|
2317
|
+
title: z.string().min(1).max(200),
|
|
2318
|
+
body: z.string().max(20_000).optional(),
|
|
2319
|
+
changes: z
|
|
2320
|
+
.array(
|
|
2321
|
+
z.object({
|
|
2322
|
+
path: z.string().min(1),
|
|
2323
|
+
content: z.string().optional(),
|
|
2324
|
+
delete: z.boolean().optional(),
|
|
2325
|
+
}),
|
|
2326
|
+
)
|
|
2327
|
+
.min(1)
|
|
2328
|
+
.max(200),
|
|
2329
|
+
});
|
|
2330
|
+
|
|
2331
|
+
export const ProposalResultSchema = z.object({
|
|
2332
|
+
branch: z.string(),
|
|
2333
|
+
pullRequest: z.object({ url: z.string(), number: z.number() }).optional(),
|
|
2334
|
+
});
|
|
2335
|
+
|
|
2336
|
+
export const ProposalSummarySchema = z.object({
|
|
2337
|
+
number: z.number().int().positive(),
|
|
2338
|
+
title: z.string(),
|
|
2339
|
+
url: z.string(),
|
|
2340
|
+
author: z.string(),
|
|
2341
|
+
head: z.string(),
|
|
2342
|
+
base: z.string(),
|
|
2343
|
+
draft: z.boolean(),
|
|
2344
|
+
updatedAt: z.string(),
|
|
2345
|
+
body: z.string().optional(),
|
|
2346
|
+
headSha: z.string().optional(),
|
|
2347
|
+
});
|
|
2348
|
+
export const ProposalFileSchema = z.object({
|
|
2349
|
+
path: z.string(),
|
|
2350
|
+
status: z.string(),
|
|
2351
|
+
additions: z.number(),
|
|
2352
|
+
deletions: z.number(),
|
|
2353
|
+
patch: z.string().nullable(),
|
|
2354
|
+
previousPath: z.string().optional(),
|
|
2355
|
+
});
|
|
2356
|
+
|
|
2357
|
+
export const ProposalReviewSchema = z.object({
|
|
2358
|
+
proposal: ProposalSummarySchema,
|
|
2359
|
+
files: z.array(ProposalFileSchema),
|
|
2360
|
+
});
|
|
2361
|
+
|
|
2362
|
+
export const ProposalCommentSchema = z.object({
|
|
2363
|
+
id: z.number(),
|
|
2364
|
+
body: z.string(),
|
|
2365
|
+
author: z.object({ login: z.string() }).nullable(),
|
|
2366
|
+
createdAt: z.string(),
|
|
2367
|
+
url: z.string(),
|
|
2368
|
+
state: z.string().optional(),
|
|
2369
|
+
path: z.string().optional(),
|
|
2370
|
+
line: z.number().nullable().optional(),
|
|
2371
|
+
replyToId: z.number().optional(),
|
|
2372
|
+
diffHunk: z.string().optional(),
|
|
2373
|
+
side: z.enum(["LEFT", "RIGHT"]).optional(),
|
|
2374
|
+
});
|
|
2375
|
+
export const ProposalDiscussionSchema = z.object({
|
|
2376
|
+
state: z.string(),
|
|
2377
|
+
reviewDecision: z.string().nullable(),
|
|
2378
|
+
assignees: z.array(z.object({ login: z.string() })),
|
|
2379
|
+
reviewRequests: z.array(z.object({ login: z.string() })),
|
|
2380
|
+
reviews: z.array(ProposalCommentSchema),
|
|
2381
|
+
comments: z.array(ProposalCommentSchema),
|
|
2382
|
+
inlineComments: z.array(ProposalCommentSchema),
|
|
2383
|
+
inlineCommentsUnavailable: z.boolean(),
|
|
2384
|
+
statusCheckRollup: z.array(
|
|
2385
|
+
z.object({
|
|
2386
|
+
name: z.string(),
|
|
2387
|
+
status: z.string(),
|
|
2388
|
+
conclusion: z.string().nullable(),
|
|
2389
|
+
detailsUrl: z.string(),
|
|
2390
|
+
}),
|
|
2391
|
+
),
|
|
2392
|
+
});
|
|
2393
|
+
export const ProposalCommentInputSchema = z.object({
|
|
2394
|
+
body: z.string().trim().min(1).max(60000),
|
|
2395
|
+
replyTo: z.number().int().positive().optional(),
|
|
2396
|
+
});
|
|
2397
|
+
|
|
2398
|
+
// --- Publications (ADR 0055) ---
|
|
2399
|
+
export const PublicationSchema = z.object({
|
|
2400
|
+
slug: z.string(),
|
|
2401
|
+
projectId: z.string(),
|
|
2402
|
+
path: z.string(),
|
|
2403
|
+
audience: z.enum(["public", "members"]),
|
|
2404
|
+
createdBy: z.string(),
|
|
2405
|
+
createdAt: z.string(),
|
|
2406
|
+
revokedAt: z.string().nullable(),
|
|
2407
|
+
/** Where the audience reads it: the public path, or the members path. */
|
|
2408
|
+
url: z.string(),
|
|
2409
|
+
});
|
|
2410
|
+
|
|
2411
|
+
export const PublishSchema = z.object({
|
|
2412
|
+
path: z.string().min(1),
|
|
2413
|
+
audience: z.enum(["public", "members"]),
|
|
2414
|
+
slug: z.string().min(1).max(64).optional(),
|
|
2415
|
+
});
|
|
2416
|
+
|
|
2417
|
+
export const PublicationParamsSchema = ProjectIdParamsSchema.extend({
|
|
2418
|
+
slug: z.string().min(1).max(64),
|
|
2419
|
+
});
|
|
2420
|
+
|
|
2421
|
+
// --- Introspection (ADR 0055) ---
|
|
2422
|
+
export const MeSchema = z.object({
|
|
2423
|
+
version: z.literal(1),
|
|
2424
|
+
identity: z.object({
|
|
2425
|
+
externalUserId: z.string(),
|
|
2426
|
+
root: z.boolean(),
|
|
2427
|
+
/**
|
|
2428
|
+
* Host-issued permissions over the organization's shared resources
|
|
2429
|
+
* (ADR 0172), expanded: `connections:write` also lists `connections:read`.
|
|
2430
|
+
*/
|
|
2431
|
+
controlPlanePermissions: z.array(
|
|
2432
|
+
z.enum(["connections:read", "connections:write"]),
|
|
2433
|
+
),
|
|
2434
|
+
}),
|
|
2435
|
+
projects: z.array(
|
|
2436
|
+
z.object({
|
|
2437
|
+
projectId: z.string(),
|
|
2438
|
+
/** The project's display name, for every member. */
|
|
2439
|
+
name: z.string(),
|
|
2440
|
+
source: z
|
|
2441
|
+
.object({
|
|
2442
|
+
remoteUrl: z.string(),
|
|
2443
|
+
defaultBranch: z.string(),
|
|
2444
|
+
})
|
|
2445
|
+
.nullable(),
|
|
2446
|
+
permissions: z.array(
|
|
2447
|
+
z
|
|
2448
|
+
.string()
|
|
2449
|
+
.regex(
|
|
2450
|
+
PROJECT_PERMISSION_PATTERN,
|
|
2451
|
+
"Expected a namespaced project capability",
|
|
2452
|
+
),
|
|
2453
|
+
),
|
|
2454
|
+
agents: z.array(z.string()),
|
|
2455
|
+
workflows: z.array(z.string()),
|
|
2456
|
+
apps: z.array(z.string()),
|
|
2457
|
+
documents: z.array(
|
|
2458
|
+
z.object({ path: z.string(), access: z.enum(["read", "write"]) }),
|
|
2459
|
+
),
|
|
2460
|
+
/** The caller's roles in this project, described (ADR 0152). */
|
|
2461
|
+
roles: z.array(
|
|
2462
|
+
z.object({ name: z.string(), description: z.string().optional() }),
|
|
2463
|
+
),
|
|
2464
|
+
}),
|
|
2465
|
+
),
|
|
2466
|
+
features: z.object({
|
|
2467
|
+
publications: z.union([z.enum(["public", "members"]), z.literal(false)]),
|
|
2468
|
+
proposals: z.boolean(),
|
|
2469
|
+
/** True when a code host is configured: proposals open pull requests through the service connection. */
|
|
2470
|
+
proposalsOpenPullRequests: z.boolean(),
|
|
2471
|
+
mcp: z.boolean(),
|
|
2472
|
+
agentSessions: z.boolean(),
|
|
2473
|
+
storeUploadMaxBytes: z.number(),
|
|
2474
|
+
}),
|
|
2475
|
+
/**
|
|
2476
|
+
* The protocols this server speaks (ADR 0197, 0198): a client refuses a
|
|
2477
|
+
* server whose session or runner protocol it does not know.
|
|
2478
|
+
*/
|
|
2479
|
+
agentProtocol: z.object({
|
|
2480
|
+
session: z.literal(SESSION_PROTOCOL_VERSION),
|
|
2481
|
+
runner: z.literal(RUNNER_PROTOCOL_VERSION),
|
|
2482
|
+
}),
|
|
2483
|
+
});
|
|
2484
|
+
|
|
2485
|
+
// --- Workflow parse ---
|
|
2486
|
+
// Pure AST parse of in-flight draft files → WorkflowGraph. Browser clients
|
|
2487
|
+
// can't run `@catamorphic/parser` (ts-morph → node:fs) so the server does it.
|
|
2488
|
+
export const ParseWorkflowRequestSchema = z.object({
|
|
2489
|
+
files: z.record(z.string(), z.string()),
|
|
2490
|
+
workflowName: z.string().min(1),
|
|
2491
|
+
preferredFilePath: z.string().optional(),
|
|
2492
|
+
});
|
|
2493
|
+
|
|
2494
|
+
export const ParseWorkflowResponseSchema = WorkflowGraphSchema.nullable();
|
|
2495
|
+
|
|
2496
|
+
// --- Plugins ---
|
|
2497
|
+
export const PluginSecretSchema = z.object({
|
|
2498
|
+
name: z.string(),
|
|
2499
|
+
label: z.string(),
|
|
2500
|
+
description: z.string(),
|
|
2501
|
+
required: z.boolean(),
|
|
2502
|
+
default: z.string().nullable(),
|
|
2503
|
+
});
|
|
2504
|
+
|
|
2505
|
+
export const PluginCapabilityRequirementSchema = z.object({
|
|
2506
|
+
name: z.string(),
|
|
2507
|
+
description: z.string(),
|
|
2508
|
+
optional: z.boolean(),
|
|
2509
|
+
fulfilled: z.boolean(),
|
|
2510
|
+
});
|
|
2511
|
+
|
|
2512
|
+
export const PluginManifestSchema = z.object({
|
|
2513
|
+
packageName: z.string(),
|
|
2514
|
+
version: z.string().nullable(),
|
|
2515
|
+
source: z.enum(["local", "npm", "git"]),
|
|
2516
|
+
displayName: z.string(),
|
|
2517
|
+
description: z.string(),
|
|
2518
|
+
secrets: z.array(PluginSecretSchema),
|
|
2519
|
+
requires: z.array(PluginCapabilityRequirementSchema),
|
|
2520
|
+
});
|
|
2521
|
+
|
|
2522
|
+
export const CatalogPluginSchema = PluginManifestSchema;
|
|
2523
|
+
|
|
2524
|
+
export const AttachedPluginSchema = PluginManifestSchema.extend({
|
|
2525
|
+
attachedAt: z.string().datetime(),
|
|
2526
|
+
secretStatus: z.array(
|
|
2527
|
+
z.object({
|
|
2528
|
+
name: z.string(),
|
|
2529
|
+
hasValue: z.boolean(),
|
|
2530
|
+
required: z.boolean(),
|
|
2531
|
+
}),
|
|
2532
|
+
),
|
|
2533
|
+
});
|
|
2534
|
+
|
|
2535
|
+
export const AttachPluginSchema = z.object({
|
|
2536
|
+
packageName: z.string().min(1),
|
|
2537
|
+
});
|
|
2538
|
+
|
|
2539
|
+
export const PluginPackageParamsSchema = ProjectIdParamsSchema.extend({
|
|
2540
|
+
packageName: z.string().min(1),
|
|
2541
|
+
});
|
|
2542
|
+
|
|
2543
|
+
// --- Secrets (ADR 0206) ---
|
|
2544
|
+
export const SecretMemberValueSchema = z.object({
|
|
2545
|
+
/** The member's external user id. */
|
|
2546
|
+
member: z.string(),
|
|
2547
|
+
updatedAt: z.string().datetime(),
|
|
2548
|
+
setBy: z.string().nullable(),
|
|
2549
|
+
});
|
|
2550
|
+
|
|
2551
|
+
/** One declared secret: where it is declared and which values exist, never a value. */
|
|
2552
|
+
export const SecretStatusSchema = z.object({
|
|
2553
|
+
name: z.string(),
|
|
2554
|
+
label: z.string().optional(),
|
|
2555
|
+
description: z.string().optional(),
|
|
2556
|
+
required: z.boolean(),
|
|
2557
|
+
source: z.enum(["project", "plugin"]),
|
|
2558
|
+
/** Environments whose sandboxes receive it. */
|
|
2559
|
+
environments: z.array(z.string()),
|
|
2560
|
+
/** A shared value is set. */
|
|
2561
|
+
shared: z.boolean(),
|
|
2562
|
+
/** When the shared value was stored, and by whom. */
|
|
2563
|
+
updatedAt: z.string().datetime().nullable(),
|
|
2564
|
+
setBy: z.string().nullable(),
|
|
2565
|
+
/** The caller holds a value of their own. */
|
|
2566
|
+
own: z.boolean(),
|
|
2567
|
+
ownUpdatedAt: z.string().datetime().nullable(),
|
|
2568
|
+
/** Members holding their own value; empty without `secrets:read`. */
|
|
2569
|
+
members: z.array(SecretMemberValueSchema),
|
|
2570
|
+
});
|
|
2571
|
+
|
|
2572
|
+
export const UpsertSecretSchema = z.object({
|
|
2573
|
+
value: z.string(),
|
|
2574
|
+
});
|
|
2575
|
+
|
|
2576
|
+
export const SecretNameParamsSchema = ProjectIdParamsSchema.extend({
|
|
2577
|
+
name: z.string().min(1),
|
|
2578
|
+
});
|
|
2579
|
+
|
|
2580
|
+
export const SecretMemberParamsSchema = SecretNameParamsSchema.extend({
|
|
2581
|
+
/** A member's external user id, or `me`. */
|
|
2582
|
+
member: z.string().min(1),
|
|
2583
|
+
});
|
|
2584
|
+
|
|
2585
|
+
export const SecretValueChangeSchema = z.object({
|
|
2586
|
+
name: z.string(),
|
|
2587
|
+
member: z.string().nullable(),
|
|
2588
|
+
updatedAt: z.string().datetime(),
|
|
2589
|
+
});
|
|
2590
|
+
|
|
2591
|
+
// --- Code hosts (ADR 0177) ---
|
|
2592
|
+
export const CodeHostParamsSchema = z.object({
|
|
2593
|
+
provider: z.string().regex(/^[a-z0-9][a-z0-9._-]*$/),
|
|
2594
|
+
});
|
|
2595
|
+
|
|
2596
|
+
export const CodeHostRepositorySchema = z.object({
|
|
2597
|
+
fullName: z.string(),
|
|
2598
|
+
name: z.string(),
|
|
2599
|
+
owner: z.string(),
|
|
2600
|
+
private: z.boolean(),
|
|
2601
|
+
defaultBranch: z.string(),
|
|
2602
|
+
cloneUrl: z.string(),
|
|
2603
|
+
description: z.string().nullable(),
|
|
2604
|
+
pushedAt: z.string().nullable(),
|
|
2605
|
+
});
|
|
2606
|
+
|
|
2607
|
+
export const CodeHostImportSchema = z.object({
|
|
2608
|
+
/** Host-specific repository path, e.g. `owner/name` on GitHub. */
|
|
2609
|
+
fullName: z.string().regex(/^[\w.-]+\/[\w.-]+$/, "Expected owner/name"),
|
|
2610
|
+
name: z.string().min(1).optional(),
|
|
2611
|
+
});
|
|
2612
|
+
|
|
2613
|
+
/** Publish an unlinked project to a new repository Work creates (ADR 0170). */
|
|
2614
|
+
export const CodeHostPublishSchema = z.object({
|
|
2615
|
+
provider: z.string().regex(/^[a-z0-9][a-z0-9._-]*$/),
|
|
2616
|
+
name: z.string().regex(/^[\w.-]+$/, "Expected a repository name"),
|
|
2617
|
+
/** Organization; the connected account when omitted. */
|
|
2618
|
+
organization: z
|
|
2619
|
+
.string()
|
|
2620
|
+
.regex(/^[\w.-]+$/, "Expected an organization login")
|
|
2621
|
+
.optional(),
|
|
2622
|
+
visibility: z.enum(["private", "public"]).optional(),
|
|
2623
|
+
});
|
|
2624
|
+
|
|
2625
|
+
export const CodeHostPublishResultSchema = z.object({
|
|
2626
|
+
fullName: z.string(),
|
|
2627
|
+
remoteUrl: z.string(),
|
|
2628
|
+
});
|
|
2629
|
+
|
|
2630
|
+
// --- Generic ---
|
|
2631
|
+
export const ErrorSchema = z.object({
|
|
2632
|
+
error: z.string(),
|
|
2633
|
+
});
|
|
2634
|
+
|
|
2635
|
+
/**
|
|
2636
|
+
* Why a session refused a change (409): closed, held by another host (take
|
|
2637
|
+
* it over with `/resume` at `authorityRevision`), or moving between hosts.
|
|
2638
|
+
*/
|
|
2639
|
+
export const SessionConflictSchema = z.object({
|
|
2640
|
+
error: z.string(),
|
|
2641
|
+
code: z.enum(["session_closed", "authority_required", "handoff_pending"]),
|
|
2642
|
+
authorityRevision: z.number().int().optional(),
|
|
2643
|
+
});
|
|
2644
|
+
|
|
2645
|
+
/** A 403 may be project scope denial or a structured Environment denial. */
|
|
2646
|
+
export const EnvironmentAccessErrorSchema = z.union([
|
|
2647
|
+
ErrorSchema,
|
|
2648
|
+
EnvironmentErrorSchema,
|
|
2649
|
+
]);
|
|
2650
|
+
|
|
2651
|
+
export const ListSchema = <T extends z.ZodTypeAny>(item: T) =>
|
|
2652
|
+
z.object({
|
|
2653
|
+
items: z.array(item),
|
|
2654
|
+
total: z.number(),
|
|
2655
|
+
});
|
|
2656
|
+
|
|
2657
|
+
export const AgentCatalogSchema = z.object({
|
|
2658
|
+
items: z.array(
|
|
2659
|
+
z.object({
|
|
2660
|
+
id: z.string(),
|
|
2661
|
+
name: z.string(),
|
|
2662
|
+
description: z.string().optional(),
|
|
2663
|
+
available: z.boolean(),
|
|
2664
|
+
reason: z.string().nullable(),
|
|
2665
|
+
environments: EnvironmentListSchema,
|
|
2666
|
+
/** What may leave the agent's sandbox, when declared (ADR 0182). */
|
|
2667
|
+
sandboxing: z.enum(SANDBOXING_LEVELS).optional(),
|
|
2668
|
+
/** The harness's own permission settings, as declared (ADR 0182). */
|
|
2669
|
+
harnessPermissions: HarnessPermissionsSchema.optional(),
|
|
2670
|
+
}),
|
|
2671
|
+
),
|
|
2672
|
+
defaultAgentId: z.string().optional(),
|
|
2673
|
+
startingActions: z.array(
|
|
2674
|
+
z.object({
|
|
2675
|
+
label: z.string(),
|
|
2676
|
+
prompt: z.string(),
|
|
2677
|
+
agentId: z.string().optional(),
|
|
2678
|
+
}),
|
|
2679
|
+
),
|
|
2680
|
+
});
|
|
2681
|
+
|
|
2682
|
+
// --- Personal environments (ADRs 0184, 0199) ---
|
|
2683
|
+
|
|
2684
|
+
export const PutPersonalEnvironmentSchema = z
|
|
2685
|
+
.strictObject({
|
|
2686
|
+
files: z
|
|
2687
|
+
.array(
|
|
2688
|
+
z.object({
|
|
2689
|
+
path: z
|
|
2690
|
+
.string()
|
|
2691
|
+
.min(1)
|
|
2692
|
+
.max(512)
|
|
2693
|
+
.describe("Repository-relative path, / separated"),
|
|
2694
|
+
content: z.string().describe("The file's bytes, base64"),
|
|
2695
|
+
}),
|
|
2696
|
+
)
|
|
2697
|
+
.max(50)
|
|
2698
|
+
.default([]),
|
|
2699
|
+
setup: z
|
|
2700
|
+
.string()
|
|
2701
|
+
.max(16_384)
|
|
2702
|
+
.optional()
|
|
2703
|
+
.describe(
|
|
2704
|
+
"The caller's own setup command, run after the Environment's in each new workspace of their own chats (ADR 0208); absent or blank for none",
|
|
2705
|
+
),
|
|
2706
|
+
})
|
|
2707
|
+
.describe(
|
|
2708
|
+
"The caller's personal files and setup for this project; replaces what the server holds",
|
|
2709
|
+
);
|
|
2710
|
+
|
|
2711
|
+
export const PersonalEnvironmentSchema = z.object({
|
|
2712
|
+
allowed: z
|
|
2713
|
+
.boolean()
|
|
2714
|
+
.describe(
|
|
2715
|
+
"Some Environment of the project gives the caller's own chats their personal files",
|
|
2716
|
+
),
|
|
2717
|
+
files: z.array(
|
|
2718
|
+
z.object({
|
|
2719
|
+
path: z.string(),
|
|
2720
|
+
fingerprint: z.string(),
|
|
2721
|
+
bytes: z.number().int().nonnegative(),
|
|
2722
|
+
updatedAt: z.string(),
|
|
2723
|
+
}),
|
|
2724
|
+
),
|
|
2725
|
+
setup: z
|
|
2726
|
+
.object({ command: z.string(), updatedAt: z.string() })
|
|
2727
|
+
.nullable()
|
|
2728
|
+
.describe("The caller's own setup command, when they sent one"),
|
|
2729
|
+
});
|
|
2730
|
+
|
|
2731
|
+
export const PersonalEnvironmentInvalidSchema = z.object({
|
|
2732
|
+
error: z.string(),
|
|
2733
|
+
code: z.literal("personal_environment_invalid"),
|
|
2734
|
+
issues: z.array(z.string()),
|
|
2735
|
+
});
|