stitchkit 0.78.0 → 0.79.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/dist/agent-runtime-browser.js +53 -581
- package/dist/agent-runtime-coding-tools.js +6 -5
- package/dist/agent-runtime-harness.js +21 -94
- package/dist/agent-runtime-openrouter.js +1 -1
- package/dist/agent-runtime.js +68 -64
- package/dist/application/kernel.d.ts.map +1 -1
- package/dist/application/schemas.d.ts +2 -0
- package/dist/application/schemas.d.ts.map +1 -1
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/application-diagnostic-journal.js +14 -96
- package/dist/application-opentelemetry.js +6 -92
- package/dist/application-schemas.js +2 -1
- package/dist/application.js +158 -1802
- package/dist/cli.js +13 -11
- package/dist/contract/index.js +7 -4
- package/dist/index-2qzskm8h.js +63 -0
- package/dist/{index-93xp5tgg.js → index-2rwwmr7v.js} +3 -3
- package/dist/{index-kw12fsbc.js → index-3gye9wzb.js} +7 -3
- package/dist/{index-1ckavx4h.js → index-3z73fh2c.js} +1 -49
- package/dist/index-4fpa9dy2.js +51 -0
- package/dist/{index-cwp38wxn.js → index-5mtc969c.js} +2 -2
- package/dist/index-5s3zajp8.js +192 -0
- package/dist/index-6s7n2v50.js +583 -0
- package/dist/{index-qaajjfp6.js → index-758zx2ha.js} +15 -94
- package/dist/{index-qyrqwr4c.js → index-77fekveh.js} +4 -1
- package/dist/{index-k45qqrdh.js → index-7ag81v2f.js} +13 -166
- package/dist/{index-n1g2xm6a.js → index-7gnkny4z.js} +124 -1
- package/dist/index-7zbps32p.js +89 -0
- package/dist/index-85vfqd7m.js +135 -0
- package/dist/{index-4ntp63ps.js → index-9s6z8vgf.js} +18 -142
- package/dist/index-a916km3r.js +45 -0
- package/dist/index-b9aefrqd.js +20 -0
- package/dist/index-dre2ywck.js +48 -0
- package/dist/{index-s5tn4kdv.js → index-dwf1f2ap.js} +3 -3
- package/dist/{index-wwst0td5.js → index-dx9xehwt.js} +1 -1
- package/dist/{index-5r0ak8fr.js → index-dxesg10d.js} +4 -4
- package/dist/{index-aczggrty.js → index-dxjjv399.js} +2 -2
- package/dist/{index-j6mfaw26.js → index-egaabxkz.js} +3 -3
- package/dist/index-evcnmsc3.js +866 -0
- package/dist/{index-efm026pw.js → index-fxz0v7vg.js} +86 -86
- package/dist/{index-56fm73re.js → index-hb5pf3s4.js} +1 -1
- package/dist/{index-n7apa6sy.js → index-k9ay6v6d.js} +24 -275
- package/dist/index-kzfs85xp.js +9 -0
- package/dist/{index-vbf2p6me.js → index-m9kzax52.js} +91 -89
- package/dist/{index-22by16v6.js → index-mgtxfe6b.js} +1 -1
- package/dist/index-p7hgdyhb.js +22 -0
- package/dist/index-pq95qkbf.js +0 -0
- package/dist/index-t0z5p5w6.js +318 -0
- package/dist/{index-31k1ns1s.js → index-vwp69871.js} +13 -11
- package/dist/index-wc4x00bn.js +103 -0
- package/dist/{index-aewy3x5j.js → index-xcetq6j3.js} +10 -8
- package/dist/{index-7z69kyrh.js → index-y01f4223.js} +24 -40
- package/dist/{index-dmfn9m4x.js → index-ywd0y6m1.js} +20 -341
- package/dist/index.js +46 -407
- package/dist/live.js +6 -3
- package/dist/node.js +17 -14
- package/dist/observability/index.js +8 -7
- package/dist/primitives.js +4 -2
- package/dist/react.js +1 -1
- package/dist/remote.js +7 -3
- package/dist/server/index.js +32 -45
- package/dist/telegram.js +1 -1
- package/dist/testing.js +90 -1576
- package/dist/tool-invoker.js +11 -9
- package/dist/tools/async-operation-contract.d.ts +61 -0
- package/dist/tools/async-operation-contract.d.ts.map +1 -0
- package/dist/tools/async-operation.d.ts +2 -47
- package/dist/tools/async-operation.d.ts.map +1 -1
- package/dist/tools/view-file-contract.d.ts +98 -0
- package/dist/tools/view-file-contract.d.ts.map +1 -0
- package/dist/tools/view-file.d.ts +4 -83
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools-contract.d.ts +29 -0
- package/dist/tools-contract.d.ts.map +1 -0
- package/dist/tools-contract.js +24 -0
- package/dist/tools.d.ts +3 -3
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +61 -140
- package/llms-full.txt +38 -3
- package/package.json +9 -6
- package/dist/index-anyqnqcv.js +0 -79
- package/dist/index-ksp6e2ye.js +0 -24
- package/dist/index-vj3vvpaa.js +0 -307
- package/dist/index-wfq8zerm.js +0 -92
|
@@ -1,589 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var AgentJsonObjectSchema = z.record(z.string(), z.json());
|
|
13
|
-
var AgentProviderEnvelopeSchema = z.object({
|
|
14
|
-
schemaVersion: z.int().positive(),
|
|
15
|
-
provider: z.string().min(1),
|
|
16
|
-
data: AgentJsonObjectSchema
|
|
17
|
-
});
|
|
18
|
-
var AgentTextPartSchema = z.object({
|
|
19
|
-
type: z.literal("text"),
|
|
20
|
-
text: z.string()
|
|
21
|
-
});
|
|
22
|
-
var AgentReasoningPartSchema = z.object({
|
|
23
|
-
type: z.literal("reasoning"),
|
|
24
|
-
text: z.string(),
|
|
25
|
-
provider: AgentProviderEnvelopeSchema.optional()
|
|
26
|
-
});
|
|
27
|
-
var AgentFilePartSchema = z.object({
|
|
28
|
-
type: z.literal("file"),
|
|
29
|
-
mediaType: z.string().min(1),
|
|
30
|
-
reference: z.string().min(1),
|
|
31
|
-
filename: z.string().min(1).optional()
|
|
32
|
-
});
|
|
33
|
-
var AgentSourcePartSchema = z.object({
|
|
34
|
-
type: z.literal("source"),
|
|
35
|
-
sourceId: z.string().min(1),
|
|
36
|
-
url: z.url().optional(),
|
|
37
|
-
title: z.string().optional()
|
|
38
|
-
});
|
|
39
|
-
var AgentToolCallPartSchema = z.object({
|
|
40
|
-
type: z.literal("tool-call"),
|
|
41
|
-
callId: z.string().min(1),
|
|
42
|
-
toolName: z.string().min(1),
|
|
43
|
-
input: z.json(),
|
|
44
|
-
provider: AgentProviderEnvelopeSchema.optional()
|
|
45
|
-
});
|
|
46
|
-
var AgentToolResultPartSchema = z.object({
|
|
47
|
-
type: z.literal("tool-result"),
|
|
48
|
-
callId: z.string().min(1),
|
|
49
|
-
toolName: z.string().min(1),
|
|
50
|
-
outcome: z.enum(["success", "error", "interrupted"]),
|
|
51
|
-
output: z.json().optional()
|
|
52
|
-
});
|
|
53
|
-
var AgentToolApprovalRequestPartSchema = z.object({
|
|
54
|
-
type: z.literal("tool-approval-request"),
|
|
55
|
-
approvalId: z.string().min(1),
|
|
56
|
-
callId: z.string().min(1),
|
|
57
|
-
isAutomatic: z.boolean().optional(),
|
|
58
|
-
signature: z.string().min(1).optional()
|
|
59
|
-
});
|
|
60
|
-
var AgentToolApprovalResponsePartSchema = z.object({
|
|
61
|
-
type: z.literal("tool-approval-response"),
|
|
62
|
-
approvalId: z.string().min(1),
|
|
63
|
-
approved: z.boolean(),
|
|
64
|
-
reason: z.string().min(1).optional()
|
|
65
|
-
});
|
|
66
|
-
var AgentOpaquePartSchema = z.object({
|
|
67
|
-
type: z.literal("provider"),
|
|
68
|
-
envelope: AgentProviderEnvelopeSchema
|
|
69
|
-
});
|
|
70
|
-
var AgentControlPartSchema = z.object({
|
|
71
|
-
type: z.literal("control"),
|
|
72
|
-
reason: z.enum(["run-interrupted", "stale-run"])
|
|
73
|
-
});
|
|
74
|
-
var AgentMessagePartSchema = z.discriminatedUnion("type", [
|
|
75
|
-
AgentTextPartSchema,
|
|
76
|
-
AgentReasoningPartSchema,
|
|
77
|
-
AgentFilePartSchema,
|
|
78
|
-
AgentSourcePartSchema,
|
|
79
|
-
AgentToolCallPartSchema,
|
|
80
|
-
AgentToolResultPartSchema,
|
|
81
|
-
AgentToolApprovalRequestPartSchema,
|
|
82
|
-
AgentToolApprovalResponsePartSchema,
|
|
83
|
-
AgentOpaquePartSchema,
|
|
84
|
-
AgentControlPartSchema
|
|
85
|
-
]);
|
|
86
|
-
var AgentMessageRoleSchema = z.enum([
|
|
87
|
-
"user",
|
|
88
|
-
"assistant",
|
|
89
|
-
"tool",
|
|
90
|
-
"system",
|
|
91
|
-
"summary"
|
|
92
|
-
]);
|
|
93
|
-
var AgentMessageStatusSchema = z.enum([
|
|
94
|
-
"committed",
|
|
95
|
-
"streaming",
|
|
96
|
-
"completed",
|
|
97
|
-
"interrupted",
|
|
98
|
-
"superseded",
|
|
99
|
-
"failed"
|
|
100
|
-
]);
|
|
101
|
-
var AgentMessageSchema = z.object({
|
|
102
|
-
schemaVersion: z.literal(1),
|
|
103
|
-
id: AgentRecordIdSchema,
|
|
104
|
-
conversationId: AgentRecordIdSchema,
|
|
105
|
-
runId: AgentRecordIdSchema.optional(),
|
|
106
|
-
role: AgentMessageRoleSchema,
|
|
107
|
-
status: AgentMessageStatusSchema,
|
|
108
|
-
parts: z.array(AgentMessagePartSchema),
|
|
109
|
-
metadata: AgentJsonObjectSchema.optional(),
|
|
110
|
-
createdAt: AgentTimestampSchema,
|
|
111
|
-
updatedAt: AgentTimestampSchema
|
|
112
|
-
});
|
|
113
|
-
var AgentAssistantPlaceholderSchema = z.object({
|
|
114
|
-
schemaVersion: z.literal(1),
|
|
115
|
-
id: AgentRecordIdSchema,
|
|
116
|
-
conversationId: AgentRecordIdSchema,
|
|
117
|
-
runId: AgentRecordIdSchema,
|
|
118
|
-
status: z.literal("pending"),
|
|
119
|
-
createdAt: AgentTimestampSchema,
|
|
120
|
-
updatedAt: AgentTimestampSchema
|
|
121
|
-
});
|
|
122
|
-
var AgentRunStateSchema = z.enum([
|
|
123
|
-
"queued",
|
|
124
|
-
"running",
|
|
125
|
-
"interrupt_requested",
|
|
126
|
-
"completed",
|
|
127
|
-
"interrupted",
|
|
128
|
-
"superseded",
|
|
129
|
-
"failed",
|
|
130
|
-
"cancelled",
|
|
131
|
-
"abandoned"
|
|
132
|
-
]);
|
|
133
|
-
var AgentRunQueuePrioritySchema = z.enum(["interrupt-next"]);
|
|
134
|
-
var AgentTerminalReasonSchema = z.enum([
|
|
135
|
-
"success",
|
|
136
|
-
"policy_stop",
|
|
137
|
-
"provider_stop",
|
|
138
|
-
"interrupted",
|
|
139
|
-
"superseded",
|
|
140
|
-
"cancelled",
|
|
141
|
-
"timeout",
|
|
142
|
-
"shutdown",
|
|
143
|
-
"provider_failure",
|
|
144
|
-
"context_overflow",
|
|
145
|
-
"absorbed",
|
|
146
|
-
"abandoned"
|
|
147
|
-
]);
|
|
148
|
-
function runStateForTerminalReason(reason) {
|
|
149
|
-
if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
|
|
150
|
-
return "completed";
|
|
151
|
-
}
|
|
152
|
-
if (reason === "interrupted")
|
|
153
|
-
return "interrupted";
|
|
154
|
-
if (reason === "superseded" || reason === "absorbed")
|
|
155
|
-
return "superseded";
|
|
156
|
-
if (reason === "cancelled" || reason === "shutdown" || reason === "timeout") {
|
|
157
|
-
return "cancelled";
|
|
158
|
-
}
|
|
159
|
-
if (reason === "abandoned")
|
|
160
|
-
return "abandoned";
|
|
161
|
-
return "failed";
|
|
162
|
-
}
|
|
163
|
-
var AgentProvenanceSchema = z.enum([
|
|
164
|
-
"provider-reported",
|
|
165
|
-
"measured",
|
|
166
|
-
"computed",
|
|
167
|
-
"estimated",
|
|
168
|
-
"unavailable"
|
|
169
|
-
]);
|
|
170
|
-
var AgentUsageValueSchema = z.object({
|
|
171
|
-
value: z.int().nonnegative().optional(),
|
|
172
|
-
provenance: AgentProvenanceSchema.extract([
|
|
173
|
-
"provider-reported",
|
|
174
|
-
"computed",
|
|
175
|
-
"estimated",
|
|
176
|
-
"unavailable"
|
|
177
|
-
])
|
|
178
|
-
});
|
|
179
|
-
var AgentCostValueSchema = z.object({
|
|
180
|
-
value: z.number().nonnegative().optional(),
|
|
181
|
-
currency: z.string().length(3).optional(),
|
|
182
|
-
provenance: AgentProvenanceSchema.extract([
|
|
183
|
-
"provider-reported",
|
|
184
|
-
"computed",
|
|
185
|
-
"estimated",
|
|
186
|
-
"unavailable"
|
|
187
|
-
])
|
|
188
|
-
});
|
|
189
|
-
var AgentUsageSchema = z.object({
|
|
190
|
-
inputTokens: AgentUsageValueSchema,
|
|
191
|
-
outputTokens: AgentUsageValueSchema,
|
|
192
|
-
reasoningTokens: AgentUsageValueSchema.optional(),
|
|
193
|
-
cacheReadTokens: AgentUsageValueSchema.optional(),
|
|
194
|
-
cacheWriteTokens: AgentUsageValueSchema.optional(),
|
|
195
|
-
cost: AgentCostValueSchema.optional()
|
|
196
|
-
});
|
|
197
|
-
var AgentRunFieldsSchema = z.object({
|
|
198
|
-
schemaVersion: z.literal(1),
|
|
199
|
-
id: AgentRecordIdSchema,
|
|
200
|
-
conversationId: AgentRecordIdSchema,
|
|
201
|
-
inputMessageIds: z.array(AgentRecordIdSchema).min(1),
|
|
202
|
-
assistantMessageId: AgentRecordIdSchema,
|
|
203
|
-
state: AgentRunStateSchema,
|
|
204
|
-
revision: AgentRecordVersionSchema,
|
|
205
|
-
queuePriority: AgentRunQueuePrioritySchema.optional(),
|
|
206
|
-
executionSequence: AgentRecordVersionSchema.optional(),
|
|
207
|
-
ownerId: z.string().min(1).optional(),
|
|
208
|
-
fencingToken: AgentRecordVersionSchema.optional(),
|
|
209
|
-
terminalReason: AgentTerminalReasonSchema.optional(),
|
|
210
|
-
terminalPolicyName: z.string().min(1).optional(),
|
|
211
|
-
absorbedIntoRunId: AgentRecordIdSchema.optional(),
|
|
212
|
-
usage: AgentUsageSchema.optional(),
|
|
213
|
-
createdAt: AgentTimestampSchema,
|
|
214
|
-
updatedAt: AgentTimestampSchema
|
|
215
|
-
});
|
|
216
|
-
var AgentRunSchema = AgentRunFieldsSchema.superRefine((run, ctx) => {
|
|
217
|
-
if (run.terminalReason !== "absorbed" && run.absorbedIntoRunId !== undefined) {
|
|
218
|
-
ctx.addIssue({
|
|
219
|
-
code: "custom",
|
|
220
|
-
path: ["absorbedIntoRunId"],
|
|
221
|
-
message: "Only an absorbed run names the run that answered it"
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
if (run.terminalReason === undefined) {
|
|
225
|
-
if (TERMINAL_RUN_STATES.has(run.state)) {
|
|
226
|
-
ctx.addIssue({
|
|
227
|
-
code: "custom",
|
|
228
|
-
path: ["terminalReason"],
|
|
229
|
-
message: `A run in terminal state "${run.state}" must say why it ended`
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
const expected = runStateForTerminalReason(run.terminalReason);
|
|
235
|
-
if (run.state !== expected) {
|
|
236
|
-
ctx.addIssue({
|
|
237
|
-
code: "custom",
|
|
238
|
-
path: ["state"],
|
|
239
|
-
message: `Terminal reason "${run.terminalReason}" ends a run in state "${expected}", not "${run.state}"`
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
if (run.terminalReason === "policy_stop" && run.terminalPolicyName === undefined) {
|
|
243
|
-
ctx.addIssue({
|
|
244
|
-
code: "custom",
|
|
245
|
-
path: ["terminalPolicyName"],
|
|
246
|
-
message: "A policy stop names the policy that stopped the run"
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
if (run.terminalReason === "absorbed" && run.absorbedIntoRunId === undefined) {
|
|
250
|
-
ctx.addIssue({
|
|
251
|
-
code: "custom",
|
|
252
|
-
path: ["absorbedIntoRunId"],
|
|
253
|
-
message: "An absorbed run names the run that answered its input"
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
if (run.absorbedIntoRunId === run.id) {
|
|
257
|
-
ctx.addIssue({
|
|
258
|
-
code: "custom",
|
|
259
|
-
path: ["absorbedIntoRunId"],
|
|
260
|
-
message: "A run cannot absorb itself"
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
var TERMINAL_RUN_STATES = new Set([
|
|
265
|
-
"completed",
|
|
266
|
-
"interrupted",
|
|
267
|
-
"superseded",
|
|
268
|
-
"cancelled",
|
|
269
|
-
"abandoned",
|
|
270
|
-
"failed"
|
|
271
|
-
]);
|
|
272
|
-
var AgentSnapshotSchema = z.object({
|
|
273
|
-
schemaVersion: z.literal(1),
|
|
274
|
-
conversationId: AgentRecordIdSchema,
|
|
275
|
-
version: AgentRecordVersionSchema,
|
|
276
|
-
messages: z.array(AgentMessageSchema),
|
|
277
|
-
runs: z.array(AgentRunSchema)
|
|
278
|
-
});
|
|
279
|
-
var AgentRunMetricsSchema = z.object({
|
|
280
|
-
partial: z.boolean(),
|
|
281
|
-
usage: AgentUsageSchema,
|
|
282
|
-
durationMs: z.number().nonnegative().optional(),
|
|
283
|
-
ttftMs: z.number().nonnegative().optional()
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// src/agent-runtime/event-schema.ts
|
|
287
|
-
var AgentAdmissionEventSchema = z2.object({
|
|
288
|
-
type: z2.literal("admission"),
|
|
289
|
-
eventId: AgentRecordIdSchema,
|
|
290
|
-
conversationId: AgentRecordIdSchema,
|
|
291
|
-
runId: AgentRecordIdSchema,
|
|
292
|
-
snapshotVersion: AgentRecordVersionSchema,
|
|
293
|
-
input: AgentMessageSchema,
|
|
294
|
-
run: AgentRunSchema,
|
|
295
|
-
assistant: z2.union([AgentAssistantPlaceholderSchema, AgentMessageSchema]),
|
|
296
|
-
emittedAt: AgentTimestampSchema
|
|
297
|
-
});
|
|
298
|
-
var EventIdentitySchema = z2.object({
|
|
299
|
-
conversationId: AgentRecordIdSchema,
|
|
300
|
-
runId: AgentRecordIdSchema,
|
|
301
|
-
emittedAt: AgentTimestampSchema
|
|
302
|
-
});
|
|
303
|
-
var AgentTransientDeltaEventSchema = EventIdentitySchema.extend({
|
|
304
|
-
type: z2.literal("assistant-delta"),
|
|
305
|
-
runtimeEpoch: z2.string().min(1),
|
|
306
|
-
sequence: z2.int().nonnegative(),
|
|
307
|
-
textDelta: z2.string()
|
|
308
|
-
});
|
|
309
|
-
var AgentTransientReasoningIdentitySchema = EventIdentitySchema.extend({
|
|
310
|
-
runtimeEpoch: z2.string().min(1),
|
|
311
|
-
sequence: z2.int().nonnegative(),
|
|
312
|
-
provider: AgentProviderEnvelopeSchema.optional()
|
|
313
|
-
});
|
|
314
|
-
var AgentReasoningStartEventSchema = AgentTransientReasoningIdentitySchema.extend({
|
|
315
|
-
type: z2.literal("reasoning-start")
|
|
316
|
-
});
|
|
317
|
-
var AgentReasoningDeltaEventSchema = AgentTransientReasoningIdentitySchema.extend({
|
|
318
|
-
type: z2.literal("reasoning-delta"),
|
|
319
|
-
textDelta: z2.string()
|
|
320
|
-
});
|
|
321
|
-
var AgentReasoningEndEventSchema = AgentTransientReasoningIdentitySchema.extend({
|
|
322
|
-
type: z2.literal("reasoning-end")
|
|
323
|
-
});
|
|
324
|
-
var AgentCheckpointEventSchema = EventIdentitySchema.extend({
|
|
325
|
-
type: z2.literal("assistant-checkpoint"),
|
|
326
|
-
eventId: AgentRecordIdSchema,
|
|
327
|
-
snapshotVersion: AgentRecordVersionSchema,
|
|
328
|
-
message: AgentMessageSchema,
|
|
329
|
-
metrics: AgentRunMetricsSchema.optional()
|
|
330
|
-
});
|
|
331
|
-
var AgentRunStateEventSchema = EventIdentitySchema.extend({
|
|
332
|
-
type: z2.literal("run-state"),
|
|
333
|
-
eventId: AgentRecordIdSchema,
|
|
334
|
-
snapshotVersion: AgentRecordVersionSchema,
|
|
335
|
-
state: AgentRunStateSchema
|
|
336
|
-
});
|
|
337
|
-
var AgentToolStatusEventSchema = EventIdentitySchema.extend({
|
|
338
|
-
type: z2.literal("tool-status"),
|
|
339
|
-
runtimeEpoch: z2.string().min(1),
|
|
340
|
-
sequence: z2.int().nonnegative(),
|
|
341
|
-
callId: AgentRecordIdSchema,
|
|
342
|
-
toolName: z2.string().min(1),
|
|
343
|
-
status: z2.enum(["started", "completed", "failed", "interrupted"]),
|
|
344
|
-
input: z2.json().optional(),
|
|
345
|
-
output: z2.json().optional()
|
|
346
|
-
});
|
|
347
|
-
var AgentTerminalEventSchema = EventIdentitySchema.extend({
|
|
348
|
-
type: z2.literal("terminal"),
|
|
349
|
-
eventId: AgentRecordIdSchema,
|
|
350
|
-
snapshotVersion: AgentRecordVersionSchema,
|
|
351
|
-
reason: AgentTerminalReasonSchema,
|
|
352
|
-
policyName: z2.string().min(1).optional(),
|
|
353
|
-
message: AgentMessageSchema,
|
|
354
|
-
metrics: AgentRunMetricsSchema.optional()
|
|
355
|
-
});
|
|
356
|
-
var AgentRuntimeEventSchema = z2.discriminatedUnion("type", [
|
|
1
|
+
import {
|
|
2
|
+
AgentControlDeliverySchema,
|
|
3
|
+
AgentControlRequestSchema,
|
|
4
|
+
AgentControlResponseSchema,
|
|
5
|
+
AgentMultiSessionCursorSchema,
|
|
6
|
+
advanceAgentMultiSessionCursor,
|
|
7
|
+
createAgentControlView,
|
|
8
|
+
reduceAgentControlEvent,
|
|
9
|
+
reduceAgentControlSnapshot
|
|
10
|
+
} from "./index-5s3zajp8.js";
|
|
11
|
+
import {
|
|
357
12
|
AgentAdmissionEventSchema,
|
|
358
|
-
|
|
359
|
-
AgentReasoningStartEventSchema,
|
|
13
|
+
AgentCheckpointEventSchema,
|
|
360
14
|
AgentReasoningDeltaEventSchema,
|
|
361
15
|
AgentReasoningEndEventSchema,
|
|
362
|
-
|
|
16
|
+
AgentReasoningStartEventSchema,
|
|
363
17
|
AgentRunStateEventSchema,
|
|
18
|
+
AgentRuntimeEventCursorSchema,
|
|
19
|
+
AgentRuntimeEventSchema,
|
|
20
|
+
AgentTerminalEventSchema,
|
|
364
21
|
AgentToolStatusEventSchema,
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
function agentDurableEventId(type, runId, snapshotVersion) {
|
|
403
|
-
return `${runId}:${type}:${snapshotVersion}`;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// src/agent-runtime/control-schema.ts
|
|
407
|
-
var AgentControlIdentitySchema = z3.object({ schemaVersion: z3.literal(1), requestId: z3.string().min(1) }).strict();
|
|
408
|
-
var AgentControlRequestSchema = z3.discriminatedUnion("operation", [
|
|
409
|
-
AgentControlIdentitySchema.extend({
|
|
410
|
-
operation: z3.literal("attach"),
|
|
411
|
-
conversationId: z3.string().min(1),
|
|
412
|
-
access: z3.enum(["observe", "control"])
|
|
413
|
-
}),
|
|
414
|
-
AgentControlIdentitySchema.extend({
|
|
415
|
-
operation: z3.literal("detach"),
|
|
416
|
-
conversationId: z3.string().min(1)
|
|
417
|
-
}),
|
|
418
|
-
AgentControlIdentitySchema.extend({
|
|
419
|
-
operation: z3.literal("snapshot"),
|
|
420
|
-
conversationId: z3.string().min(1)
|
|
421
|
-
}),
|
|
422
|
-
AgentControlIdentitySchema.extend({
|
|
423
|
-
operation: z3.literal("submit"),
|
|
424
|
-
conversationId: z3.string().min(1),
|
|
425
|
-
idempotencyKey: z3.string().min(1),
|
|
426
|
-
context: z3.unknown(),
|
|
427
|
-
parts: z3.array(AgentMessagePartSchema).min(1),
|
|
428
|
-
metadata: z3.unknown().optional()
|
|
429
|
-
}),
|
|
430
|
-
AgentControlIdentitySchema.extend({
|
|
431
|
-
operation: z3.literal("interrupt"),
|
|
432
|
-
conversationId: z3.string().min(1),
|
|
433
|
-
runId: z3.string().min(1)
|
|
434
|
-
}),
|
|
435
|
-
AgentControlIdentitySchema.extend({
|
|
436
|
-
operation: z3.literal("respond-approval"),
|
|
437
|
-
conversationId: z3.string().min(1),
|
|
438
|
-
approvalId: z3.string().min(1),
|
|
439
|
-
approved: z3.boolean(),
|
|
440
|
-
reason: z3.string().min(1).optional(),
|
|
441
|
-
context: z3.unknown(),
|
|
442
|
-
metadata: z3.unknown().optional()
|
|
443
|
-
})
|
|
444
|
-
]);
|
|
445
|
-
var AgentControlResponseIdentitySchema = z3.object({
|
|
446
|
-
schemaVersion: z3.literal(1),
|
|
447
|
-
requestId: z3.string().min(1)
|
|
448
|
-
});
|
|
449
|
-
var AgentControlResponseSchema = z3.discriminatedUnion("outcome", [
|
|
450
|
-
AgentControlResponseIdentitySchema.extend({
|
|
451
|
-
outcome: z3.literal("ok"),
|
|
452
|
-
snapshot: AgentSnapshotSchema.optional(),
|
|
453
|
-
runId: z3.string().min(1).optional()
|
|
454
|
-
}).strict(),
|
|
455
|
-
AgentControlResponseIdentitySchema.extend({
|
|
456
|
-
outcome: z3.literal("error"),
|
|
457
|
-
error: z3.object({ code: z3.string().min(1), message: z3.string().min(1) }).strict()
|
|
458
|
-
}).strict()
|
|
459
|
-
]);
|
|
460
|
-
var AgentControlDeliverySchema = z3.discriminatedUnion("type", [
|
|
461
|
-
z3.object({
|
|
462
|
-
schemaVersion: z3.literal(1),
|
|
463
|
-
type: z3.literal("event"),
|
|
464
|
-
event: AgentRuntimeEventSchema
|
|
465
|
-
}).strict(),
|
|
466
|
-
z3.object({
|
|
467
|
-
schemaVersion: z3.literal(1),
|
|
468
|
-
type: z3.literal("resync-required"),
|
|
469
|
-
conversationId: z3.string().min(1),
|
|
470
|
-
reason: z3.literal("overflow")
|
|
471
|
-
}).strict()
|
|
472
|
-
]);
|
|
473
|
-
var AgentMultiSessionCursorSchema = z3.object({
|
|
474
|
-
conversations: z3.record(z3.string(), z3.object({
|
|
475
|
-
snapshotVersion: z3.int().nonnegative().optional(),
|
|
476
|
-
durableEventIds: z3.array(z3.string().min(1)).optional(),
|
|
477
|
-
runs: z3.record(z3.string(), z3.object({ runtimeEpoch: z3.string().min(1), sequence: z3.int().nonnegative() }).strict())
|
|
478
|
-
}).strict())
|
|
479
|
-
}).strict();
|
|
480
|
-
function durable(event) {
|
|
481
|
-
return ["admission", "assistant-checkpoint", "run-state", "terminal"].includes(event.type);
|
|
482
|
-
}
|
|
483
|
-
function advanceAgentMultiSessionCursor(raw, event) {
|
|
484
|
-
const cursor = AgentMultiSessionCursorSchema.parse(raw);
|
|
485
|
-
const previous = cursor.conversations[event.conversationId] ?? { runs: {} };
|
|
486
|
-
if (durable(event)) {
|
|
487
|
-
const ids = previous.snapshotVersion === event.snapshotVersion ? previous.durableEventIds ?? [] : [];
|
|
488
|
-
if (previous.snapshotVersion !== undefined && event.snapshotVersion < previous.snapshotVersion || ids.includes(event.eventId)) {
|
|
489
|
-
return { status: "duplicate", cursor };
|
|
490
|
-
}
|
|
491
|
-
return {
|
|
492
|
-
status: "accepted",
|
|
493
|
-
cursor: {
|
|
494
|
-
conversations: {
|
|
495
|
-
...cursor.conversations,
|
|
496
|
-
[event.conversationId]: {
|
|
497
|
-
...previous,
|
|
498
|
-
snapshotVersion: event.snapshotVersion,
|
|
499
|
-
durableEventIds: [...ids, event.eventId]
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
const run = previous.runs[event.runId];
|
|
506
|
-
const sequence = run?.runtimeEpoch === event.runtimeEpoch ? run.sequence : undefined;
|
|
507
|
-
if (sequence !== undefined && event.sequence <= sequence)
|
|
508
|
-
return { status: "duplicate", cursor };
|
|
509
|
-
const expected = sequence === undefined ? 1 : sequence + 1;
|
|
510
|
-
return {
|
|
511
|
-
status: event.sequence === expected ? "accepted" : "gap",
|
|
512
|
-
cursor: {
|
|
513
|
-
conversations: {
|
|
514
|
-
...cursor.conversations,
|
|
515
|
-
[event.conversationId]: {
|
|
516
|
-
...previous,
|
|
517
|
-
runs: {
|
|
518
|
-
...previous.runs,
|
|
519
|
-
[event.runId]: { runtimeEpoch: event.runtimeEpoch, sequence: event.sequence }
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
function createAgentControlView() {
|
|
527
|
-
return { cursor: { conversations: {} }, conversations: {} };
|
|
528
|
-
}
|
|
529
|
-
function reduceAgentControlSnapshot(view, rawSnapshot) {
|
|
530
|
-
const snapshot = AgentSnapshotSchema.parse(rawSnapshot);
|
|
531
|
-
const previous = view.cursor.conversations[snapshot.conversationId] ?? { runs: {} };
|
|
532
|
-
return {
|
|
533
|
-
cursor: {
|
|
534
|
-
conversations: {
|
|
535
|
-
...view.cursor.conversations,
|
|
536
|
-
[snapshot.conversationId]: {
|
|
537
|
-
...previous,
|
|
538
|
-
snapshotVersion: snapshot.version,
|
|
539
|
-
durableEventIds: []
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
},
|
|
543
|
-
conversations: {
|
|
544
|
-
...view.conversations,
|
|
545
|
-
[snapshot.conversationId]: {
|
|
546
|
-
snapshot,
|
|
547
|
-
resyncRequired: false,
|
|
548
|
-
transientByRun: {}
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
function reduceAgentControlEvent(view, rawEvent) {
|
|
554
|
-
const event = AgentRuntimeEventSchema.parse(rawEvent);
|
|
555
|
-
const advanced = advanceAgentMultiSessionCursor(view.cursor, event);
|
|
556
|
-
if (advanced.status === "duplicate")
|
|
557
|
-
return view;
|
|
558
|
-
const current = view.conversations[event.conversationId] ?? {
|
|
559
|
-
resyncRequired: false,
|
|
560
|
-
transientByRun: {}
|
|
561
|
-
};
|
|
562
|
-
if (advanced.status === "gap") {
|
|
563
|
-
return {
|
|
564
|
-
cursor: advanced.cursor,
|
|
565
|
-
conversations: {
|
|
566
|
-
...view.conversations,
|
|
567
|
-
[event.conversationId]: { ...current, resyncRequired: true }
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
const transient = current.transientByRun[event.runId] ?? { text: "", reasoning: "" };
|
|
572
|
-
const nextTransient = event.type === "assistant-delta" ? { ...transient, text: transient.text + event.textDelta } : event.type === "reasoning-delta" ? { ...transient, reasoning: transient.reasoning + event.textDelta } : transient;
|
|
573
|
-
const snapshotStale = durable(event) && current.snapshot?.version !== event.snapshotVersion;
|
|
574
|
-
const transientByRun = event.type === "terminal" ? Object.fromEntries(Object.entries(current.transientByRun).filter(([runId]) => runId !== event.runId)) : { ...current.transientByRun, [event.runId]: nextTransient };
|
|
575
|
-
return {
|
|
576
|
-
cursor: advanced.cursor,
|
|
577
|
-
conversations: {
|
|
578
|
-
...view.conversations,
|
|
579
|
-
[event.conversationId]: {
|
|
580
|
-
...current,
|
|
581
|
-
resyncRequired: current.resyncRequired || snapshotStale,
|
|
582
|
-
transientByRun
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
}
|
|
22
|
+
AgentTransientDeltaEventSchema,
|
|
23
|
+
advanceAgentRuntimeEventCursor,
|
|
24
|
+
agentDurableEventId
|
|
25
|
+
} from "./index-85vfqd7m.js";
|
|
26
|
+
import {
|
|
27
|
+
AgentAssistantPlaceholderSchema,
|
|
28
|
+
AgentControlPartSchema,
|
|
29
|
+
AgentCostValueSchema,
|
|
30
|
+
AgentFilePartSchema,
|
|
31
|
+
AgentJsonObjectSchema,
|
|
32
|
+
AgentMessagePartSchema,
|
|
33
|
+
AgentMessageRoleSchema,
|
|
34
|
+
AgentMessageSchema,
|
|
35
|
+
AgentMessageStatusSchema,
|
|
36
|
+
AgentOpaquePartSchema,
|
|
37
|
+
AgentProvenanceSchema,
|
|
38
|
+
AgentProviderEnvelopeSchema,
|
|
39
|
+
AgentReasoningPartSchema,
|
|
40
|
+
AgentRecordIdSchema,
|
|
41
|
+
AgentRecordVersionSchema,
|
|
42
|
+
AgentRunMetricsSchema,
|
|
43
|
+
AgentRunQueuePrioritySchema,
|
|
44
|
+
AgentRunSchema,
|
|
45
|
+
AgentRunStateSchema,
|
|
46
|
+
AgentSnapshotSchema,
|
|
47
|
+
AgentSourcePartSchema,
|
|
48
|
+
AgentTerminalReasonSchema,
|
|
49
|
+
AgentTextPartSchema,
|
|
50
|
+
AgentTimestampSchema,
|
|
51
|
+
AgentToolApprovalRequestPartSchema,
|
|
52
|
+
AgentToolApprovalResponsePartSchema,
|
|
53
|
+
AgentToolCallPartSchema,
|
|
54
|
+
AgentToolResultPartSchema,
|
|
55
|
+
AgentUsageSchema,
|
|
56
|
+
AgentUsageValueSchema,
|
|
57
|
+
runStateForTerminalReason
|
|
58
|
+
} from "./index-x1th9s8c.js";
|
|
587
59
|
export {
|
|
588
60
|
runStateForTerminalReason,
|
|
589
61
|
reduceAgentControlSnapshot,
|
|
@@ -13,17 +13,18 @@ import {
|
|
|
13
13
|
} from "./index-rqpdar1e.js";
|
|
14
14
|
import {
|
|
15
15
|
defineRuntimeTool
|
|
16
|
-
} from "./index-
|
|
17
|
-
import"./index-
|
|
16
|
+
} from "./index-dx9xehwt.js";
|
|
17
|
+
import"./index-mgtxfe6b.js";
|
|
18
18
|
import"./index-cby4ar3v.js";
|
|
19
|
-
import"./index-
|
|
20
|
-
import"./index-
|
|
19
|
+
import"./index-y01f4223.js";
|
|
20
|
+
import"./index-6k1937bx.js";
|
|
21
21
|
import {
|
|
22
22
|
AppError,
|
|
23
23
|
conflict,
|
|
24
24
|
forbidden
|
|
25
25
|
} from "./index-0w9abg87.js";
|
|
26
|
-
import"./index-
|
|
26
|
+
import"./index-kzfs85xp.js";
|
|
27
|
+
import"./index-77fekveh.js";
|
|
27
28
|
|
|
28
29
|
// src/agent-runtime/coding-tools.ts
|
|
29
30
|
import path4 from "node:path";
|