@drisp/protocol 0.6.0
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 +21 -0
- package/README.md +125 -0
- package/dist/index.d.ts +3188 -0
- package/dist/index.js +613 -0
- package/package.json +53 -0
- package/schema/canonical-frame.json +973 -0
- package/schema/feed-envelope.json +145 -0
- package/schema/feed-event.json +105 -0
- package/schema/frame.json +1385 -0
- package/schema/hello.json +134 -0
- package/schema/installed-workflow.json +89 -0
- package/schema/interruption.json +120 -0
- package/schema/legacy-frame.json +578 -0
- package/schema/phase-event.json +33 -0
- package/schema/phase-feed-event.json +134 -0
- package/schema/run-spec.json +61 -0
- package/schema/run-stream-event.json +26 -0
- package/schema/run.json +57 -0
- package/schema/runtime-decision.json +125 -0
- package/schema/turn.json +135 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
// src/version.ts
|
|
2
|
+
var PROTOCOL_VERSION = 1;
|
|
3
|
+
|
|
4
|
+
// src/domain.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var RunStatusSchema = z.enum([
|
|
7
|
+
"running",
|
|
8
|
+
"awaiting_attention",
|
|
9
|
+
"completed",
|
|
10
|
+
"blocked",
|
|
11
|
+
"exhausted",
|
|
12
|
+
"failed",
|
|
13
|
+
"cancelled"
|
|
14
|
+
]);
|
|
15
|
+
var RunSchema = z.object({
|
|
16
|
+
runId: z.string(),
|
|
17
|
+
/** The durable Athena Session this Run belongs to. */
|
|
18
|
+
athenaSessionId: z.string(),
|
|
19
|
+
workflowName: z.string().optional(),
|
|
20
|
+
/** What the Run was asked to do — the `**Goal**` its Run section records. */
|
|
21
|
+
goal: z.string().optional(),
|
|
22
|
+
/** Index of the most recent Turn (0 before Turn 1). */
|
|
23
|
+
iteration: z.int().nonnegative(),
|
|
24
|
+
maxIterations: z.int().positive().optional(),
|
|
25
|
+
status: RunStatusSchema,
|
|
26
|
+
stopReason: z.string().optional(),
|
|
27
|
+
/** Vendor session id of the Run's most recent Agent Session (ADR 0014). */
|
|
28
|
+
adapterSessionId: z.string().optional(),
|
|
29
|
+
startedAt: z.number(),
|
|
30
|
+
endedAt: z.number().optional()
|
|
31
|
+
});
|
|
32
|
+
var TurnContinuationSchema = z.discriminatedUnion("mode", [
|
|
33
|
+
z.object({ mode: z.literal("fresh") }),
|
|
34
|
+
z.object({ mode: z.literal("resume"), handle: z.string() }),
|
|
35
|
+
z.object({ mode: z.literal("reuse-current") })
|
|
36
|
+
]);
|
|
37
|
+
var TurnOutcomeSchema = z.discriminatedUnion("kind", [
|
|
38
|
+
z.object({ kind: z.literal("continue") }),
|
|
39
|
+
z.object({
|
|
40
|
+
kind: z.literal("stop"),
|
|
41
|
+
status: RunStatusSchema,
|
|
42
|
+
stopReason: z.string().optional()
|
|
43
|
+
}),
|
|
44
|
+
z.object({
|
|
45
|
+
kind: z.literal("suspend"),
|
|
46
|
+
status: RunStatusSchema,
|
|
47
|
+
stopReason: z.string()
|
|
48
|
+
})
|
|
49
|
+
]);
|
|
50
|
+
var TurnSchema = z.object({
|
|
51
|
+
runId: z.string(),
|
|
52
|
+
/** 1-based Iteration of this Turn within its Run. */
|
|
53
|
+
iteration: z.int().positive(),
|
|
54
|
+
continuation: TurnContinuationSchema,
|
|
55
|
+
/** Vendor session id of the Agent Session this Turn ran in, once known. */
|
|
56
|
+
adapterSessionId: z.string().optional(),
|
|
57
|
+
startedAt: z.number(),
|
|
58
|
+
endedAt: z.number().optional(),
|
|
59
|
+
outcome: TurnOutcomeSchema.optional()
|
|
60
|
+
});
|
|
61
|
+
var HardFailureCodeSchema = z.enum([
|
|
62
|
+
"auth",
|
|
63
|
+
"billing",
|
|
64
|
+
"invalid_request",
|
|
65
|
+
"model_not_found",
|
|
66
|
+
"unclassified"
|
|
67
|
+
]);
|
|
68
|
+
var ExhaustedCapSchema = z.enum([
|
|
69
|
+
"retry",
|
|
70
|
+
"nudge",
|
|
71
|
+
"iterations",
|
|
72
|
+
"handover",
|
|
73
|
+
"tokens"
|
|
74
|
+
]);
|
|
75
|
+
var interruptionBase = {
|
|
76
|
+
/** Human-readable summary of why the Run parked. */
|
|
77
|
+
message: z.string()
|
|
78
|
+
};
|
|
79
|
+
var InterruptionSchema = z.discriminatedUnion("kind", [
|
|
80
|
+
z.object({
|
|
81
|
+
...interruptionBase,
|
|
82
|
+
kind: z.literal("blocked"),
|
|
83
|
+
/** The `: reason` suffix of `NEEDS_HUMAN[: reason]`, when given. */
|
|
84
|
+
reason: z.string().optional()
|
|
85
|
+
}),
|
|
86
|
+
z.object({
|
|
87
|
+
...interruptionBase,
|
|
88
|
+
kind: z.literal("question"),
|
|
89
|
+
/**
|
|
90
|
+
* The pending request an `answer` frame must address. Absent when the
|
|
91
|
+
* runner interrupted the Turn instead of leaving the question waiting
|
|
92
|
+
* (an unattended Workflow Run kills the Agent Session on a question,
|
|
93
|
+
* so there is no request left to answer); such a Run is woken with a
|
|
94
|
+
* `steer` carrying the human's guidance.
|
|
95
|
+
*/
|
|
96
|
+
requestId: z.string().optional(),
|
|
97
|
+
question: z.string().optional()
|
|
98
|
+
}),
|
|
99
|
+
z.object({
|
|
100
|
+
...interruptionBase,
|
|
101
|
+
kind: z.literal("hard_failure"),
|
|
102
|
+
code: HardFailureCodeSchema
|
|
103
|
+
}),
|
|
104
|
+
z.object({
|
|
105
|
+
...interruptionBase,
|
|
106
|
+
kind: z.literal("cap_exhausted"),
|
|
107
|
+
cap: ExhaustedCapSchema,
|
|
108
|
+
limit: z.int().positive().optional(),
|
|
109
|
+
/** Structured policy decision. Older senders may supply only cap/message. */
|
|
110
|
+
resource: z.object({
|
|
111
|
+
cause: z.enum(["tokens", "iterations", "context", "restart"]),
|
|
112
|
+
limit: z.number().nonnegative(),
|
|
113
|
+
used: z.number().nonnegative(),
|
|
114
|
+
detail: z.string().optional(),
|
|
115
|
+
checkpointPath: z.string().optional(),
|
|
116
|
+
fresh: z.boolean()
|
|
117
|
+
}).optional()
|
|
118
|
+
})
|
|
119
|
+
]);
|
|
120
|
+
var RunSpecSchema = z.looseObject({
|
|
121
|
+
prompt: z.string().optional(),
|
|
122
|
+
athenaSessionId: z.string().optional(),
|
|
123
|
+
adapterResumeSessionId: z.string().optional(),
|
|
124
|
+
sessionId: z.string().optional(),
|
|
125
|
+
projectDir: z.string().optional(),
|
|
126
|
+
workflow: z.looseObject({
|
|
127
|
+
source: z.string().optional(),
|
|
128
|
+
ref: z.string().optional(),
|
|
129
|
+
version: z.string().optional()
|
|
130
|
+
}).optional(),
|
|
131
|
+
harness: z.string().optional(),
|
|
132
|
+
env: z.record(z.string(), z.string()).optional(),
|
|
133
|
+
timeoutSec: z.number().optional(),
|
|
134
|
+
/** Per-run callback channel minted by the hub; both or neither. */
|
|
135
|
+
callbackWsUrl: z.string().optional(),
|
|
136
|
+
callbackToken: z.string().optional()
|
|
137
|
+
});
|
|
138
|
+
var RuntimeIntentSchema = z.discriminatedUnion("kind", [
|
|
139
|
+
z.object({ kind: z.literal("permission_allow") }),
|
|
140
|
+
z.object({ kind: z.literal("permission_deny"), reason: z.string() }),
|
|
141
|
+
z.object({
|
|
142
|
+
kind: z.literal("question_answer"),
|
|
143
|
+
answers: z.record(z.string(), z.string())
|
|
144
|
+
}),
|
|
145
|
+
z.object({ kind: z.literal("pre_tool_allow") }),
|
|
146
|
+
z.object({ kind: z.literal("pre_tool_deny"), reason: z.string() }),
|
|
147
|
+
z.object({ kind: z.literal("stop_block"), reason: z.string() }),
|
|
148
|
+
z.object({ kind: z.literal("compact_block"), reason: z.string() })
|
|
149
|
+
]);
|
|
150
|
+
var RuntimeDecisionSchema = z.object({
|
|
151
|
+
type: z.enum(["passthrough", "block", "json"]),
|
|
152
|
+
source: z.enum(["user", "timeout", "rule"]),
|
|
153
|
+
intent: RuntimeIntentSchema.optional(),
|
|
154
|
+
reason: z.string().optional(),
|
|
155
|
+
data: z.unknown().optional()
|
|
156
|
+
});
|
|
157
|
+
var AttachmentSchema = z.object({
|
|
158
|
+
runnerId: z.string(),
|
|
159
|
+
name: z.string().optional(),
|
|
160
|
+
slug: z.string().optional(),
|
|
161
|
+
executionTarget: z.string().optional(),
|
|
162
|
+
remoteInstanceId: z.string().optional()
|
|
163
|
+
});
|
|
164
|
+
var InstalledWorkflowSourceSchema = z.discriminatedUnion("kind", [
|
|
165
|
+
z.object({ kind: z.literal("builtin") }),
|
|
166
|
+
z.object({ kind: z.literal("marketplace-remote"), ref: z.string() }),
|
|
167
|
+
z.object({
|
|
168
|
+
kind: z.literal("marketplace-local"),
|
|
169
|
+
repoDir: z.string(),
|
|
170
|
+
workflowName: z.string()
|
|
171
|
+
}),
|
|
172
|
+
z.object({ kind: z.literal("filesystem"), path: z.string() }),
|
|
173
|
+
z.object({ kind: z.literal("unknown") })
|
|
174
|
+
]);
|
|
175
|
+
var InstalledWorkflowSchema = z.object({
|
|
176
|
+
name: z.string().min(1),
|
|
177
|
+
version: z.string().optional(),
|
|
178
|
+
source: InstalledWorkflowSourceSchema
|
|
179
|
+
});
|
|
180
|
+
var AssignmentRejectedReasonSchema = z.enum([
|
|
181
|
+
"local_capacity",
|
|
182
|
+
"duplicate",
|
|
183
|
+
"malformed_assignment",
|
|
184
|
+
"workspace_unresolved",
|
|
185
|
+
"workspace_invalid"
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
// src/events.ts
|
|
189
|
+
import { z as z2 } from "zod";
|
|
190
|
+
var RunStreamEventSchema = z2.object({
|
|
191
|
+
runId: z2.string(),
|
|
192
|
+
/** Runner-local order within the Run. */
|
|
193
|
+
seq: z2.int().nonnegative(),
|
|
194
|
+
ts: z2.number(),
|
|
195
|
+
kind: z2.string(),
|
|
196
|
+
payload: z2.unknown().optional()
|
|
197
|
+
});
|
|
198
|
+
var FeedEventLevelSchema = z2.enum(["debug", "info", "warn", "error"]);
|
|
199
|
+
var FeedEventCauseSchema = z2.object({
|
|
200
|
+
parent_event_id: z2.string().optional(),
|
|
201
|
+
hook_request_id: z2.string().optional(),
|
|
202
|
+
tool_use_id: z2.string().optional(),
|
|
203
|
+
transcript_path: z2.string().optional()
|
|
204
|
+
});
|
|
205
|
+
var FeedEventSchema = z2.looseObject({
|
|
206
|
+
event_id: z2.string(),
|
|
207
|
+
seq: z2.int().nonnegative(),
|
|
208
|
+
ts: z2.number(),
|
|
209
|
+
session_id: z2.string(),
|
|
210
|
+
/** A Feed Run id (`{session_id}:R{n}`) — unrelated to a Workflow Run id. */
|
|
211
|
+
run_id: z2.string(),
|
|
212
|
+
prompt_id: z2.string().optional(),
|
|
213
|
+
effort_level: z2.string().optional(),
|
|
214
|
+
kind: z2.string(),
|
|
215
|
+
level: FeedEventLevelSchema,
|
|
216
|
+
actor_id: z2.string(),
|
|
217
|
+
cause: FeedEventCauseSchema.optional(),
|
|
218
|
+
title: z2.string(),
|
|
219
|
+
body: z2.string().optional(),
|
|
220
|
+
ui: z2.object({
|
|
221
|
+
collapsed_default: z2.boolean().optional(),
|
|
222
|
+
pin: z2.boolean().optional(),
|
|
223
|
+
badge: z2.string().optional()
|
|
224
|
+
}).optional(),
|
|
225
|
+
display: z2.object({ title: z2.string().optional() }).optional(),
|
|
226
|
+
data: z2.unknown(),
|
|
227
|
+
raw: z2.unknown().optional()
|
|
228
|
+
});
|
|
229
|
+
var PHASE_FEED_EVENT_KIND = "phase";
|
|
230
|
+
var PhaseEventSchema = z2.object({
|
|
231
|
+
/** The Workflow Run id (not a Feed Run id). */
|
|
232
|
+
runId: z2.string(),
|
|
233
|
+
/** 1-based Iteration of the Turn whose Journal named this step. */
|
|
234
|
+
turn: z2.int().positive(),
|
|
235
|
+
step: z2.string().min(1),
|
|
236
|
+
stepIndex: z2.int().positive().optional(),
|
|
237
|
+
stepTotal: z2.int().positive().optional()
|
|
238
|
+
});
|
|
239
|
+
var PhaseFeedEventSchema = FeedEventSchema.extend({
|
|
240
|
+
kind: z2.literal(PHASE_FEED_EVENT_KIND),
|
|
241
|
+
data: PhaseEventSchema
|
|
242
|
+
});
|
|
243
|
+
var FeedOriginSchema = z2.enum(["local", "dashboard"]);
|
|
244
|
+
var FeedEnvelopeSchema = z2.object({
|
|
245
|
+
instanceId: z2.string(),
|
|
246
|
+
athenaSessionId: z2.string(),
|
|
247
|
+
runId: z2.string(),
|
|
248
|
+
origin: FeedOriginSchema,
|
|
249
|
+
eventId: z2.string(),
|
|
250
|
+
feedSeq: z2.int().nonnegative(),
|
|
251
|
+
emittedAt: z2.number(),
|
|
252
|
+
feedEvent: FeedEventSchema
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// src/frames.ts
|
|
256
|
+
import { z as z3 } from "zod";
|
|
257
|
+
var runStartBody = {
|
|
258
|
+
runId: z3.string(),
|
|
259
|
+
runSpec: RunSpecSchema.optional(),
|
|
260
|
+
/**
|
|
261
|
+
* The runner this assignment is bound to — top-level so the CLI can route
|
|
262
|
+
* to the right Attachment without inspecting `runSpec`. Absent from hubs
|
|
263
|
+
* that use single-runtime semantics.
|
|
264
|
+
*/
|
|
265
|
+
runnerId: z3.string().optional()
|
|
266
|
+
};
|
|
267
|
+
var answerBody = {
|
|
268
|
+
athenaSessionId: z3.string(),
|
|
269
|
+
requestId: z3.string(),
|
|
270
|
+
decision: RuntimeDecisionSchema
|
|
271
|
+
};
|
|
272
|
+
var stopBody = {
|
|
273
|
+
runId: z3.string(),
|
|
274
|
+
runnerId: z3.string().optional()
|
|
275
|
+
};
|
|
276
|
+
var PingFrameSchema = z3.object({
|
|
277
|
+
type: z3.literal("ping"),
|
|
278
|
+
ts: z3.number()
|
|
279
|
+
});
|
|
280
|
+
var PongFrameSchema = z3.object({
|
|
281
|
+
type: z3.literal("pong"),
|
|
282
|
+
ts: z3.number()
|
|
283
|
+
});
|
|
284
|
+
var AssignmentAcceptedFrameSchema = z3.object({
|
|
285
|
+
type: z3.literal("assignment_accepted"),
|
|
286
|
+
runId: z3.string()
|
|
287
|
+
});
|
|
288
|
+
var AssignmentRejectedFrameSchema = z3.object({
|
|
289
|
+
type: z3.literal("assignment_rejected"),
|
|
290
|
+
runId: z3.string(),
|
|
291
|
+
reason: AssignmentRejectedReasonSchema,
|
|
292
|
+
message: z3.string().optional()
|
|
293
|
+
});
|
|
294
|
+
var DecisionAckFrameSchema = z3.object({
|
|
295
|
+
type: z3.literal("decision_ack"),
|
|
296
|
+
athenaSessionId: z3.string(),
|
|
297
|
+
requestId: z3.string()
|
|
298
|
+
});
|
|
299
|
+
var FeedAckFrameSchema = z3.object({
|
|
300
|
+
type: z3.literal("feed_ack"),
|
|
301
|
+
deliverySeq: z3.int().nonnegative().optional(),
|
|
302
|
+
eventId: z3.string().optional()
|
|
303
|
+
});
|
|
304
|
+
var AttachmentsChangedFrameSchema = z3.object({
|
|
305
|
+
type: z3.literal("attachments.changed"),
|
|
306
|
+
attachments: z3.array(AttachmentSchema)
|
|
307
|
+
});
|
|
308
|
+
var ErrorFrameSchema = z3.object({
|
|
309
|
+
type: z3.literal("error"),
|
|
310
|
+
code: z3.string(),
|
|
311
|
+
message: z3.string().optional()
|
|
312
|
+
});
|
|
313
|
+
var JobAssignmentFrameSchema = z3.object({
|
|
314
|
+
type: z3.literal("job_assignment"),
|
|
315
|
+
...runStartBody
|
|
316
|
+
});
|
|
317
|
+
var DashboardDecisionFrameSchema = z3.object({
|
|
318
|
+
type: z3.literal("dashboard_decision"),
|
|
319
|
+
...answerBody
|
|
320
|
+
});
|
|
321
|
+
var CancelFrameSchema = z3.object({
|
|
322
|
+
type: z3.literal("cancel"),
|
|
323
|
+
...stopBody
|
|
324
|
+
});
|
|
325
|
+
var RunEventFrameSchema = z3.object({
|
|
326
|
+
type: z3.literal("run_event"),
|
|
327
|
+
...RunStreamEventSchema.shape
|
|
328
|
+
});
|
|
329
|
+
var FeedEventFrameSchema = z3.object({
|
|
330
|
+
type: z3.literal("feed_event"),
|
|
331
|
+
/** Runner-local outbox order, used only for delivery retry. */
|
|
332
|
+
deliverySeq: z3.int().nonnegative(),
|
|
333
|
+
envelope: FeedEnvelopeSchema
|
|
334
|
+
});
|
|
335
|
+
var HelloFrameSchema = z3.object({
|
|
336
|
+
type: z3.literal("hello"),
|
|
337
|
+
protocolVersion: z3.int().positive(),
|
|
338
|
+
role: z3.enum(["runner", "hub"]).optional(),
|
|
339
|
+
instanceId: z3.string().optional(),
|
|
340
|
+
agent: z3.object({ name: z3.string(), version: z3.string().optional() }).optional(),
|
|
341
|
+
capabilities: z3.array(z3.string()).optional(),
|
|
342
|
+
workflows: z3.array(InstalledWorkflowSchema).optional()
|
|
343
|
+
});
|
|
344
|
+
var WorkflowsChangedFrameSchema = z3.object({
|
|
345
|
+
type: z3.literal("workflows.changed"),
|
|
346
|
+
workflows: z3.array(InstalledWorkflowSchema)
|
|
347
|
+
});
|
|
348
|
+
var RunStartFrameSchema = z3.object({
|
|
349
|
+
type: z3.literal("run.start"),
|
|
350
|
+
...runStartBody
|
|
351
|
+
});
|
|
352
|
+
var AnswerFrameSchema = z3.object({
|
|
353
|
+
type: z3.literal("answer"),
|
|
354
|
+
...answerBody
|
|
355
|
+
});
|
|
356
|
+
var StopFrameSchema = z3.object({
|
|
357
|
+
type: z3.literal("stop"),
|
|
358
|
+
...stopBody
|
|
359
|
+
});
|
|
360
|
+
var SteerFrameSchema = z3.object({
|
|
361
|
+
type: z3.literal("steer"),
|
|
362
|
+
runId: z3.string(),
|
|
363
|
+
athenaSessionId: z3.string().optional(),
|
|
364
|
+
text: z3.string().min(1)
|
|
365
|
+
});
|
|
366
|
+
var NeedsHumanFrameSchema = z3.object({
|
|
367
|
+
type: z3.literal("needs_human"),
|
|
368
|
+
runId: z3.string(),
|
|
369
|
+
athenaSessionId: z3.string().optional(),
|
|
370
|
+
interruption: InterruptionSchema
|
|
371
|
+
});
|
|
372
|
+
var RunStreamEventFrameSchema = z3.object({
|
|
373
|
+
type: z3.literal("event"),
|
|
374
|
+
stream: z3.literal("run"),
|
|
375
|
+
...RunStreamEventSchema.shape
|
|
376
|
+
});
|
|
377
|
+
var FeedStreamEventFrameSchema = z3.object({
|
|
378
|
+
type: z3.literal("event"),
|
|
379
|
+
stream: z3.literal("feed"),
|
|
380
|
+
deliverySeq: z3.int().nonnegative(),
|
|
381
|
+
envelope: FeedEnvelopeSchema
|
|
382
|
+
});
|
|
383
|
+
var EventFrameSchema = z3.discriminatedUnion("stream", [
|
|
384
|
+
RunStreamEventFrameSchema,
|
|
385
|
+
FeedStreamEventFrameSchema
|
|
386
|
+
]);
|
|
387
|
+
var unchangedFrames = [
|
|
388
|
+
PingFrameSchema,
|
|
389
|
+
PongFrameSchema,
|
|
390
|
+
AssignmentAcceptedFrameSchema,
|
|
391
|
+
AssignmentRejectedFrameSchema,
|
|
392
|
+
DecisionAckFrameSchema,
|
|
393
|
+
FeedAckFrameSchema,
|
|
394
|
+
AttachmentsChangedFrameSchema,
|
|
395
|
+
ErrorFrameSchema
|
|
396
|
+
];
|
|
397
|
+
var LegacyFrameSchema = z3.discriminatedUnion("type", [
|
|
398
|
+
JobAssignmentFrameSchema,
|
|
399
|
+
DashboardDecisionFrameSchema,
|
|
400
|
+
CancelFrameSchema,
|
|
401
|
+
RunEventFrameSchema,
|
|
402
|
+
FeedEventFrameSchema,
|
|
403
|
+
...unchangedFrames
|
|
404
|
+
]);
|
|
405
|
+
var CanonicalFrameSchema = z3.discriminatedUnion("type", [
|
|
406
|
+
HelloFrameSchema,
|
|
407
|
+
RunStartFrameSchema,
|
|
408
|
+
AnswerFrameSchema,
|
|
409
|
+
StopFrameSchema,
|
|
410
|
+
SteerFrameSchema,
|
|
411
|
+
NeedsHumanFrameSchema,
|
|
412
|
+
WorkflowsChangedFrameSchema,
|
|
413
|
+
EventFrameSchema,
|
|
414
|
+
...unchangedFrames
|
|
415
|
+
]);
|
|
416
|
+
var FrameSchema = z3.discriminatedUnion("type", [
|
|
417
|
+
JobAssignmentFrameSchema,
|
|
418
|
+
DashboardDecisionFrameSchema,
|
|
419
|
+
CancelFrameSchema,
|
|
420
|
+
RunEventFrameSchema,
|
|
421
|
+
FeedEventFrameSchema,
|
|
422
|
+
HelloFrameSchema,
|
|
423
|
+
RunStartFrameSchema,
|
|
424
|
+
AnswerFrameSchema,
|
|
425
|
+
StopFrameSchema,
|
|
426
|
+
SteerFrameSchema,
|
|
427
|
+
NeedsHumanFrameSchema,
|
|
428
|
+
WorkflowsChangedFrameSchema,
|
|
429
|
+
EventFrameSchema,
|
|
430
|
+
...unchangedFrames
|
|
431
|
+
]);
|
|
432
|
+
function hello(input = {}) {
|
|
433
|
+
return { type: "hello", protocolVersion: PROTOCOL_VERSION, ...input };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// src/normalize.ts
|
|
437
|
+
var FRAME_NAME_MAP = {
|
|
438
|
+
job_assignment: "run.start",
|
|
439
|
+
dashboard_decision: "answer",
|
|
440
|
+
cancel: "stop",
|
|
441
|
+
run_event: "event",
|
|
442
|
+
feed_event: "event",
|
|
443
|
+
ping: "ping",
|
|
444
|
+
pong: "pong",
|
|
445
|
+
assignment_accepted: "assignment_accepted",
|
|
446
|
+
assignment_rejected: "assignment_rejected",
|
|
447
|
+
decision_ack: "decision_ack",
|
|
448
|
+
feed_ack: "feed_ack",
|
|
449
|
+
"attachments.changed": "attachments.changed",
|
|
450
|
+
error: "error"
|
|
451
|
+
};
|
|
452
|
+
function normalizeFrame(input) {
|
|
453
|
+
return canonicalize(FrameSchema.parse(input));
|
|
454
|
+
}
|
|
455
|
+
function safeNormalizeFrame(input) {
|
|
456
|
+
const parsed = FrameSchema.safeParse(input);
|
|
457
|
+
if (!parsed.success) return { success: false, error: parsed.error };
|
|
458
|
+
return { success: true, frame: canonicalize(parsed.data) };
|
|
459
|
+
}
|
|
460
|
+
function canonicalize(frame) {
|
|
461
|
+
switch (frame.type) {
|
|
462
|
+
case "job_assignment": {
|
|
463
|
+
const { type: _type, ...body } = frame;
|
|
464
|
+
return { type: "run.start", ...body };
|
|
465
|
+
}
|
|
466
|
+
case "dashboard_decision": {
|
|
467
|
+
const { type: _type, ...body } = frame;
|
|
468
|
+
return { type: "answer", ...body };
|
|
469
|
+
}
|
|
470
|
+
case "cancel": {
|
|
471
|
+
const { type: _type, ...body } = frame;
|
|
472
|
+
return { type: "stop", ...body };
|
|
473
|
+
}
|
|
474
|
+
case "run_event": {
|
|
475
|
+
const { type: _type, ...body } = frame;
|
|
476
|
+
return { type: "event", stream: "run", ...body };
|
|
477
|
+
}
|
|
478
|
+
case "feed_event": {
|
|
479
|
+
const { type: _type, ...body } = frame;
|
|
480
|
+
return { type: "event", stream: "feed", ...body };
|
|
481
|
+
}
|
|
482
|
+
default:
|
|
483
|
+
return frame;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function toLegacyFrame(frame) {
|
|
487
|
+
switch (frame.type) {
|
|
488
|
+
case "run.start": {
|
|
489
|
+
const { type: _type, ...body } = frame;
|
|
490
|
+
return { type: "job_assignment", ...body };
|
|
491
|
+
}
|
|
492
|
+
case "answer": {
|
|
493
|
+
const { type: _type, ...body } = frame;
|
|
494
|
+
return { type: "dashboard_decision", ...body };
|
|
495
|
+
}
|
|
496
|
+
case "stop": {
|
|
497
|
+
const { type: _type, ...body } = frame;
|
|
498
|
+
return { type: "cancel", ...body };
|
|
499
|
+
}
|
|
500
|
+
case "event": {
|
|
501
|
+
if (frame.stream === "run") {
|
|
502
|
+
const { type: _type2, stream: _stream2, ...body2 } = frame;
|
|
503
|
+
return { type: "run_event", ...body2 };
|
|
504
|
+
}
|
|
505
|
+
const { type: _type, stream: _stream, ...body } = frame;
|
|
506
|
+
return { type: "feed_event", ...body };
|
|
507
|
+
}
|
|
508
|
+
default:
|
|
509
|
+
return frame;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/jsonSchema.ts
|
|
514
|
+
import { z as z4 } from "zod";
|
|
515
|
+
var JSON_SCHEMA_SOURCES = {
|
|
516
|
+
frame: FrameSchema,
|
|
517
|
+
"canonical-frame": CanonicalFrameSchema,
|
|
518
|
+
"legacy-frame": LegacyFrameSchema,
|
|
519
|
+
hello: HelloFrameSchema,
|
|
520
|
+
run: RunSchema,
|
|
521
|
+
turn: TurnSchema,
|
|
522
|
+
interruption: InterruptionSchema,
|
|
523
|
+
"installed-workflow": InstalledWorkflowSchema,
|
|
524
|
+
"run-spec": RunSpecSchema,
|
|
525
|
+
"runtime-decision": RuntimeDecisionSchema,
|
|
526
|
+
"run-stream-event": RunStreamEventSchema,
|
|
527
|
+
"feed-event": FeedEventSchema,
|
|
528
|
+
"feed-envelope": FeedEnvelopeSchema,
|
|
529
|
+
"phase-event": PhaseEventSchema,
|
|
530
|
+
"phase-feed-event": PhaseFeedEventSchema
|
|
531
|
+
};
|
|
532
|
+
function jsonSchemaId(name) {
|
|
533
|
+
return `https://raw.githubusercontent.com/drisplabs/cli/main/packages/protocol/schema/${name}.json`;
|
|
534
|
+
}
|
|
535
|
+
function buildJsonSchemas() {
|
|
536
|
+
const out = {};
|
|
537
|
+
for (const name of Object.keys(JSON_SCHEMA_SOURCES)) {
|
|
538
|
+
const generated = z4.toJSONSchema(JSON_SCHEMA_SOURCES[name], {
|
|
539
|
+
target: "draft-2020-12",
|
|
540
|
+
unrepresentable: "any"
|
|
541
|
+
});
|
|
542
|
+
out[name] = {
|
|
543
|
+
$schema: generated.$schema,
|
|
544
|
+
$id: jsonSchemaId(name),
|
|
545
|
+
title: name,
|
|
546
|
+
"x-protocol-version": PROTOCOL_VERSION,
|
|
547
|
+
...generated
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
return out;
|
|
551
|
+
}
|
|
552
|
+
export {
|
|
553
|
+
AnswerFrameSchema,
|
|
554
|
+
AssignmentAcceptedFrameSchema,
|
|
555
|
+
AssignmentRejectedFrameSchema,
|
|
556
|
+
AssignmentRejectedReasonSchema,
|
|
557
|
+
AttachmentSchema,
|
|
558
|
+
AttachmentsChangedFrameSchema,
|
|
559
|
+
CancelFrameSchema,
|
|
560
|
+
CanonicalFrameSchema,
|
|
561
|
+
DashboardDecisionFrameSchema,
|
|
562
|
+
DecisionAckFrameSchema,
|
|
563
|
+
ErrorFrameSchema,
|
|
564
|
+
EventFrameSchema,
|
|
565
|
+
ExhaustedCapSchema,
|
|
566
|
+
FRAME_NAME_MAP,
|
|
567
|
+
FeedAckFrameSchema,
|
|
568
|
+
FeedEnvelopeSchema,
|
|
569
|
+
FeedEventCauseSchema,
|
|
570
|
+
FeedEventFrameSchema,
|
|
571
|
+
FeedEventLevelSchema,
|
|
572
|
+
FeedEventSchema,
|
|
573
|
+
FeedOriginSchema,
|
|
574
|
+
FeedStreamEventFrameSchema,
|
|
575
|
+
FrameSchema,
|
|
576
|
+
HardFailureCodeSchema,
|
|
577
|
+
HelloFrameSchema,
|
|
578
|
+
InstalledWorkflowSchema,
|
|
579
|
+
InstalledWorkflowSourceSchema,
|
|
580
|
+
InterruptionSchema,
|
|
581
|
+
JSON_SCHEMA_SOURCES,
|
|
582
|
+
JobAssignmentFrameSchema,
|
|
583
|
+
LegacyFrameSchema,
|
|
584
|
+
NeedsHumanFrameSchema,
|
|
585
|
+
PHASE_FEED_EVENT_KIND,
|
|
586
|
+
PROTOCOL_VERSION,
|
|
587
|
+
PhaseEventSchema,
|
|
588
|
+
PhaseFeedEventSchema,
|
|
589
|
+
PingFrameSchema,
|
|
590
|
+
PongFrameSchema,
|
|
591
|
+
RunEventFrameSchema,
|
|
592
|
+
RunSchema,
|
|
593
|
+
RunSpecSchema,
|
|
594
|
+
RunStartFrameSchema,
|
|
595
|
+
RunStatusSchema,
|
|
596
|
+
RunStreamEventFrameSchema,
|
|
597
|
+
RunStreamEventSchema,
|
|
598
|
+
RuntimeDecisionSchema,
|
|
599
|
+
RuntimeIntentSchema,
|
|
600
|
+
SteerFrameSchema,
|
|
601
|
+
StopFrameSchema,
|
|
602
|
+
TurnContinuationSchema,
|
|
603
|
+
TurnOutcomeSchema,
|
|
604
|
+
TurnSchema,
|
|
605
|
+
WorkflowsChangedFrameSchema,
|
|
606
|
+
buildJsonSchemas,
|
|
607
|
+
hello,
|
|
608
|
+
jsonSchemaId,
|
|
609
|
+
normalizeFrame,
|
|
610
|
+
safeNormalizeFrame,
|
|
611
|
+
toLegacyFrame
|
|
612
|
+
};
|
|
613
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@drisp/protocol",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Wire contract between a drisp runner and the hub: zod schemas, inferred types, and JSON Schema for the instance-socket frames, Run, Turn, Interruption, and the event stream",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/drisplabs/cli.git",
|
|
8
|
+
"directory": "packages/protocol"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/drisplabs/cli/tree/main/packages/protocol#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/drisplabs/cli/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"drisp",
|
|
16
|
+
"protocol",
|
|
17
|
+
"zod",
|
|
18
|
+
"json-schema"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"source": "./src/index.ts",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./schema/*.json": "./schema/*.json",
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"!dist/**/*.js.map",
|
|
42
|
+
"schema"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"schema:generate": "vite-node scripts/generate-schema.ts",
|
|
48
|
+
"prepublishOnly": "npm run build"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"zod": "^4.3.6"
|
|
52
|
+
}
|
|
53
|
+
}
|