stitchkit 0.103.0 → 0.103.2

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/agent-runtime/browser-control-contract.d.ts +1118 -0
  3. package/dist/agent-runtime/browser-control-contract.d.ts.map +1 -0
  4. package/dist/agent-runtime/browser-controller.d.ts +31 -0
  5. package/dist/agent-runtime/browser-controller.d.ts.map +1 -0
  6. package/dist/agent-runtime/harness-control.d.ts.map +1 -1
  7. package/dist/agent-runtime/harness-realtime.d.ts +25 -0
  8. package/dist/agent-runtime/harness-realtime.d.ts.map +1 -0
  9. package/dist/agent-runtime/harness-tools.d.ts +11 -0
  10. package/dist/agent-runtime/harness-tools.d.ts.map +1 -0
  11. package/dist/agent-runtime/react.d.ts +4 -0
  12. package/dist/agent-runtime/react.d.ts.map +1 -0
  13. package/dist/agent-runtime/run-assertions.d.ts +63 -0
  14. package/dist/agent-runtime/run-assertions.d.ts.map +1 -0
  15. package/dist/entrypoints/agent-runtime/browser.d.ts +2 -0
  16. package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
  17. package/dist/entrypoints/agent-runtime/browser.js +235 -0
  18. package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
  19. package/dist/entrypoints/agent-runtime/harness-tools.d.ts +2 -0
  20. package/dist/entrypoints/agent-runtime/harness-tools.d.ts.map +1 -0
  21. package/dist/entrypoints/agent-runtime/harness-tools.js +32 -0
  22. package/dist/entrypoints/agent-runtime/harness.js +13 -228
  23. package/dist/entrypoints/agent-runtime/react.d.ts +2 -0
  24. package/dist/entrypoints/agent-runtime/react.d.ts.map +1 -0
  25. package/dist/entrypoints/agent-runtime/react.js +8 -0
  26. package/dist/entrypoints/agent-runtime/realtime.d.ts +2 -0
  27. package/dist/entrypoints/agent-runtime/realtime.d.ts.map +1 -0
  28. package/dist/entrypoints/agent-runtime/realtime.js +159 -0
  29. package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
  30. package/dist/entrypoints/agent-runtime/testing.d.ts +1 -0
  31. package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -1
  32. package/dist/entrypoints/agent-runtime/testing.js +67 -2
  33. package/dist/entrypoints/agent-runtime.js +25 -20
  34. package/dist/entrypoints/cli.js +8 -8
  35. package/dist/entrypoints/index.js +15 -226
  36. package/dist/entrypoints/node.js +7 -5
  37. package/dist/entrypoints/observability.js +2 -2
  38. package/dist/entrypoints/react.js +2 -2
  39. package/dist/entrypoints/remote.js +3 -3
  40. package/dist/entrypoints/server.js +10 -8
  41. package/dist/entrypoints/testing.js +4 -4
  42. package/dist/entrypoints/tools/connections.js +2 -2
  43. package/dist/entrypoints/tools/invoker.js +6 -6
  44. package/dist/entrypoints/tools.js +25 -36
  45. package/dist/entrypoints/tracking.js +2 -2
  46. package/dist/{index-d82d3xg4.js → index-0c419yx7.js} +1 -1
  47. package/dist/{index-c6aagrbd.js → index-1br6gwhf.js} +4 -4
  48. package/dist/{index-xkhk5d6g.js → index-1khy8y7n.js} +5 -48
  49. package/dist/index-20yvtn9a.js +38 -0
  50. package/dist/{index-a9pd417t.js → index-5vyd0fkb.js} +1 -34
  51. package/dist/{index-r1z0rd9c.js → index-7n68nmc6.js} +1 -1
  52. package/dist/{index-zs4ms3th.js → index-90ppdx3q.js} +7 -30
  53. package/dist/{index-djjhhgjk.js → index-a4ajxwmb.js} +1 -1
  54. package/dist/index-c9d05kvt.js +11 -0
  55. package/dist/{index-ewbaywk5.js → index-dnn9z96q.js} +3 -3
  56. package/dist/index-jn9g8xdt.js +246 -0
  57. package/dist/index-kmpzj1cq.js +48 -0
  58. package/dist/{index-dvwj1f43.js → index-m2xqkv55.js} +2 -2
  59. package/dist/{index-m9fndta6.js → index-n2gre124.js} +3 -3
  60. package/dist/index-nggfa2yn.js +34 -0
  61. package/dist/{index-m79yr938.js → index-pw99k9h5.js} +1 -10
  62. package/dist/index-qapzv4p5.js +54 -0
  63. package/dist/index-r34mvse1.js +225 -0
  64. package/dist/{index-n9tyz8z3.js → index-r956rndn.js} +2 -2
  65. package/dist/index-srs8hj9c.js +10 -0
  66. package/dist/{index-jzczzcsb.js → index-tgzhq07n.js} +1 -1
  67. package/dist/index-vgkbcnkc.js +29 -0
  68. package/dist/{index-7z9ym7t8.js → index-x87j7csh.js} +35 -14
  69. package/dist/{index-3ct7hhq6.js → index-xwq9j1sf.js} +6 -56
  70. package/dist/{index-hby4qhax.js → index-yex7eg1v.js} +4 -10
  71. package/dist/{index-1h6gtdrj.js → index-ygkka6zn.js} +1 -1
  72. package/dist/index-ze1eph1k.js +20 -0
  73. package/dist/tools/schema/flatten-join.d.ts +1 -1
  74. package/dist/tools/schema/flatten-join.d.ts.map +1 -1
  75. package/dist/tools/schema/flatten.d.ts.map +1 -1
  76. package/llms/agent-runtime-browser.txt +26 -0
  77. package/llms/agent-runtime-harness-tools.txt +25 -0
  78. package/llms/agent-runtime-harness.txt +140 -1
  79. package/llms/agent-runtime-react.txt +21 -0
  80. package/llms/agent-runtime-realtime.txt +30 -0
  81. package/llms/agent-runtime-testing.txt +6 -0
  82. package/llms/stitchkit.txt +5 -1
  83. package/llms/tools.3.txt +1 -1
  84. package/llms/tools.txt +19 -1
  85. package/llms-full.txt +229 -3
  86. package/llms.txt +9 -5
  87. package/package.json +13 -1
@@ -3,32 +3,33 @@ import {
3
3
  } from "../../index-nx6eazt0.js";
4
4
  import"../../index-8kzct1d6.js";
5
5
  import {
6
- createAgentRuntimeEventSink2,
7
6
  composeAgentPrompt2,
8
7
  createAgentRuntime2
9
- } from "../../index-zs4ms3th.js";
8
+ } from "../../index-90ppdx3q.js";
10
9
  import"../../index-h97tqqp1.js";
11
10
  import"../../index-mnkk1ffz.js";
12
11
  import"../../index-n53mswt3.js";
13
12
  import"../../index-b2bz0kdm.js";
14
- import"../../index-hby4qhax.js";
13
+ import"../../index-yex7eg1v.js";
15
14
  import"../../index-9pw0a51a.js";
16
15
  import"../../index-ct75c3at.js";
17
- import"../../index-7z9ym7t8.js";
18
- import"../../index-dvwj1f43.js";
19
- import"../../index-a9pd417t.js";
16
+ import"../../index-x87j7csh.js";
17
+ import"../../index-m2xqkv55.js";
18
+ import"../../index-5vyd0fkb.js";
19
+ import"../../index-nggfa2yn.js";
20
20
  import"../../index-r5hsgkz5.js";
21
+ import"../../index-n5yqxd3d.js";
21
22
  import {
22
- AgentControlRequestSchema2,
23
- AgentControlResponseSchema2
24
- } from "../../index-n5yqxd3d.js";
23
+ createAgentHarnessControlServer2
24
+ } from "../../index-jn9g8xdt.js";
25
+ import"../../index-vgkbcnkc.js";
25
26
  import {
26
27
  walkContainedFiles
27
28
  } from "../../index-ej331hah.js";
28
- import"../../index-r1z0rd9c.js";
29
+ import"../../index-7n68nmc6.js";
29
30
  import {
30
31
  defineRuntimeTool2
31
- } from "../../index-jzczzcsb.js";
32
+ } from "../../index-tgzhq07n.js";
32
33
 
33
34
  // src/agent-runtime/harness-contract.ts
34
35
  import { z } from "zod";
@@ -264,222 +265,6 @@ function createAgentHarnessFileResources(config) {
264
265
  });
265
266
  return { load, runtimeTools: [readResource] };
266
267
  }
267
- // src/agent-runtime/harness-control.ts
268
- async function runControlledOperation(harness, request) {
269
- if (request.operation === "interrupt") {
270
- await harness.interrupt({
271
- conversationId: request.conversationId,
272
- runId: request.runId
273
- });
274
- return AgentControlResponseSchema2.parse({
275
- schemaVersion: 1,
276
- requestId: request.requestId,
277
- outcome: "ok",
278
- snapshot: await harness.snapshot(request.conversationId)
279
- });
280
- }
281
- if (request.operation === "respond-approval") {
282
- const ticket = await harness.respondToApproval({
283
- conversationId: request.conversationId,
284
- approvalId: request.approvalId,
285
- approved: request.approved,
286
- ...request.reason && { reason: request.reason },
287
- context: request.context,
288
- ...request.metadata !== undefined && { metadata: request.metadata }
289
- });
290
- const admission = await ticket.admission;
291
- return AgentControlResponseSchema2.parse({
292
- schemaVersion: 1,
293
- requestId: request.requestId,
294
- outcome: "ok",
295
- runId: admission.runId,
296
- snapshot: await harness.snapshot(request.conversationId)
297
- });
298
- }
299
- const ticket = harness.submit({
300
- conversationId: request.conversationId,
301
- idempotencyKey: request.idempotencyKey,
302
- context: request.context,
303
- parts: request.parts,
304
- ...request.metadata !== undefined && { metadata: request.metadata }
305
- });
306
- const admission = await ticket.admission;
307
- return AgentControlResponseSchema2.parse({
308
- schemaVersion: 1,
309
- requestId: request.requestId,
310
- outcome: "ok",
311
- runId: admission.runId,
312
- snapshot: await harness.snapshot(request.conversationId)
313
- });
314
- }
315
- function createAgentHarnessControlServer(harness, config = {}) {
316
- const maxPendingAttachments = config.maxPendingAttachments ?? 32;
317
- if (!Number.isSafeInteger(maxPendingAttachments) || maxPendingAttachments <= 0) {
318
- throw new TypeError("maxPendingAttachments must be a positive safe integer");
319
- }
320
- const connections = new Map;
321
- const controllers = new Map;
322
- let pendingAttachments = 0;
323
- let closed = false;
324
- const unsubscribe = harness.subscribe((event) => {
325
- for (const connection of connections.values()) {
326
- if (connection.attached.has(event.conversationId) && !connection.overflowed) {
327
- connection.sink.publish(event);
328
- }
329
- }
330
- });
331
- const detach = (connectionId) => {
332
- const connection = connections.get(connectionId);
333
- if (!connection)
334
- return;
335
- for (const conversationId of connection.attached.keys()) {
336
- if (controllers.get(conversationId) === connectionId) {
337
- controllers.delete(conversationId);
338
- }
339
- }
340
- connection.sink.close();
341
- connections.delete(connectionId);
342
- };
343
- return {
344
- connect({ id, deliver, onOverflow }) {
345
- if (closed)
346
- throw new Error("Agent harness control server is closed");
347
- if (connections.has(id))
348
- throw new Error("Agent harness control connection id is duplicate");
349
- const state = {
350
- attached: new Map,
351
- pendingAttachments: new Set,
352
- overflowed: false,
353
- sink: createAgentRuntimeEventSink2({
354
- write: (event) => deliver({ schemaVersion: 1, type: "event", event }),
355
- maxPending: config.maxPendingEvents ?? 128,
356
- onDrop: ({ event }) => {
357
- if (state.overflowed)
358
- return;
359
- state.overflowed = true;
360
- onOverflow({
361
- schemaVersion: 1,
362
- type: "resync-required",
363
- conversationId: event.conversationId,
364
- reason: "overflow"
365
- });
366
- detach(id);
367
- }
368
- })
369
- };
370
- connections.set(id, state);
371
- return {
372
- async request(raw) {
373
- const request = AgentControlRequestSchema2.parse(raw);
374
- const fail = (code, message) => AgentControlResponseSchema2.parse({
375
- schemaVersion: 1,
376
- requestId: request.requestId,
377
- outcome: "error",
378
- error: { code, message }
379
- });
380
- if (closed || connections.get(id) !== state)
381
- return fail("CONNECTION_CLOSED", "Connection is closed");
382
- try {
383
- if (request.operation === "attach") {
384
- if (state.pendingAttachments.has(request.conversationId)) {
385
- return fail("ATTACH_IN_PROGRESS", "Wait for the current attachment request to settle");
386
- }
387
- if (pendingAttachments >= maxPendingAttachments) {
388
- return fail("ATTACHMENT_CAPACITY", "Too many attachment snapshots are pending on this control server");
389
- }
390
- const owner = controllers.get(request.conversationId);
391
- if (request.access === "control" && owner && owner !== id) {
392
- return fail("LEASE_CONFLICT", "Conversation already has a controller");
393
- }
394
- const previousAccess = state.attached.get(request.conversationId);
395
- const previousController = controllers.get(request.conversationId);
396
- pendingAttachments += 1;
397
- state.pendingAttachments.add(request.conversationId);
398
- if (!previousAccess)
399
- state.attached.set(request.conversationId, request.access);
400
- if (request.access === "control")
401
- controllers.set(request.conversationId, id);
402
- let snapshot;
403
- try {
404
- snapshot = await harness.snapshot(request.conversationId);
405
- } catch (error) {
406
- if (connections.get(id) === state) {
407
- if (previousAccess)
408
- state.attached.set(request.conversationId, previousAccess);
409
- else
410
- state.attached.delete(request.conversationId);
411
- if (request.access === "control" && controllers.get(request.conversationId) === id && previousController) {
412
- controllers.set(request.conversationId, previousController);
413
- } else if (request.access === "control" && controllers.get(request.conversationId) === id) {
414
- controllers.delete(request.conversationId);
415
- }
416
- }
417
- throw error;
418
- } finally {
419
- pendingAttachments -= 1;
420
- state.pendingAttachments.delete(request.conversationId);
421
- }
422
- if (closed || connections.get(id) !== state) {
423
- return fail("CONNECTION_CLOSED", "Connection is closed");
424
- }
425
- state.attached.set(request.conversationId, request.access);
426
- if (request.access === "observe" && controllers.get(request.conversationId) === id) {
427
- controllers.delete(request.conversationId);
428
- }
429
- return AgentControlResponseSchema2.parse({
430
- schemaVersion: 1,
431
- requestId: request.requestId,
432
- outcome: "ok",
433
- snapshot
434
- });
435
- }
436
- if (state.pendingAttachments.has(request.conversationId)) {
437
- return fail("ATTACH_IN_PROGRESS", "Wait for the current attachment request to settle");
438
- }
439
- if (request.operation === "detach") {
440
- if (controllers.get(request.conversationId) === id)
441
- controllers.delete(request.conversationId);
442
- state.attached.delete(request.conversationId);
443
- return AgentControlResponseSchema2.parse({
444
- schemaVersion: 1,
445
- requestId: request.requestId,
446
- outcome: "ok"
447
- });
448
- }
449
- if (!state.attached.has(request.conversationId))
450
- return fail("NOT_ATTACHED", "Attach before requesting conversation state");
451
- if (request.operation === "snapshot") {
452
- const snapshot = await harness.snapshot(request.conversationId);
453
- return AgentControlResponseSchema2.parse({
454
- schemaVersion: 1,
455
- requestId: request.requestId,
456
- outcome: "ok",
457
- snapshot
458
- });
459
- }
460
- if (state.attached.get(request.conversationId) !== "control" || controllers.get(request.conversationId) !== id) {
461
- return fail("LEASE_REQUIRED", "An active controller lease is required");
462
- }
463
- return await runControlledOperation(harness, request);
464
- } catch {
465
- return fail("REQUEST_REJECTED", "Control request was rejected");
466
- }
467
- },
468
- close() {
469
- detach(id);
470
- }
471
- };
472
- },
473
- close() {
474
- if (closed)
475
- return;
476
- closed = true;
477
- unsubscribe();
478
- for (const id of [...connections.keys()])
479
- detach(id);
480
- }
481
- };
482
- }
483
268
 
484
269
  // src/agent-runtime/harness.ts
485
270
  class AgentHarnessApprovalRejectedError extends Error {
@@ -727,7 +512,7 @@ export {
727
512
  AgentHarnessResourceDiagnosticSchema,
728
513
  AgentHarnessResourceKindSchema,
729
514
  AgentHarnessResourceSchema,
730
- createAgentHarnessControlServer,
515
+ createAgentHarnessControlServer2 as createAgentHarnessControlServer,
731
516
  createAgentHarnessFileResources,
732
517
  createHeadlessAgentHarness
733
518
  };
@@ -0,0 +1,2 @@
1
+ export { useAgent } from '../../agent-runtime/react.js';
2
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/agent-runtime/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,8 @@
1
+ // src/agent-runtime/react.ts
2
+ import { useSyncExternalStore } from "react";
3
+ function useAgent(controller) {
4
+ return useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
5
+ }
6
+ export {
7
+ useAgent
8
+ };
@@ -0,0 +1,2 @@
1
+ export { type AgentHarnessRealtimeConfig, bindAgentHarnessRealtime, } from '../../agent-runtime/harness-realtime.js';
2
+ //# sourceMappingURL=realtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/agent-runtime/realtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,wBAAwB,GACzB,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,159 @@
1
+ import"../../index-n53mswt3.js";
2
+ import"../../index-pw99k9h5.js";
3
+ import"../../index-4s0fep5q.js";
4
+ import"../../index-814xpr6d.js";
5
+ import"../../index-8kzct1d6.js";
6
+ import"../../index-mnkk1ffz.js";
7
+ import"../../index-n5yqxd3d.js";
8
+ import {
9
+ agentControlRealtimeContract2
10
+ } from "../../index-20yvtn9a.js";
11
+ import"../../index-h97tqqp1.js";
12
+ import {
13
+ createAgentHarnessControlServer2
14
+ } from "../../index-jn9g8xdt.js";
15
+ import {
16
+ bindRealtimeServer2
17
+ } from "../../index-qapzv4p5.js";
18
+ import"../../index-vgkbcnkc.js";
19
+
20
+ // src/agent-runtime/harness-realtime.ts
21
+ function bindAgentHarnessRealtime(harness, handle, config) {
22
+ const control = createAgentHarnessControlServer2(harness, config);
23
+ const realtime = bindRealtimeServer2(agentControlRealtimeContract2, handle);
24
+ const cleanups = new Set;
25
+ const maxPending = config.maxPendingRequests ?? 32;
26
+ const authTimeout = config.authorizationTimeoutMs ?? 1e4;
27
+ for (const [name, value] of Object.entries({ maxPending, authTimeout })) {
28
+ if (!Number.isSafeInteger(value) || value < 1)
29
+ throw new TypeError(`${name} must be a positive safe integer`);
30
+ }
31
+ const unsubscribe = realtime.onConnection(({ raw, events }) => {
32
+ let closed = false;
33
+ const pending = new Set;
34
+ const report = (error) => {
35
+ try {
36
+ if (config.onError)
37
+ config.onError(error);
38
+ else
39
+ console.error("[stitchkit] agent control authorization failed", error);
40
+ } catch (observerError) {
41
+ console.error("[stitchkit] agent control error observer failed", {
42
+ error,
43
+ observerError
44
+ });
45
+ }
46
+ };
47
+ const authorize = async (request) => {
48
+ let timer;
49
+ const abort = new AbortController;
50
+ try {
51
+ return await Promise.race([
52
+ Promise.resolve().then(() => config.authorize({ identity: raw.data, request, signal: abort.signal })),
53
+ new Promise((_resolve, reject) => {
54
+ timer = setTimeout(() => reject(new Error("Agent authorization timed out")), authTimeout);
55
+ })
56
+ ]);
57
+ } catch (error) {
58
+ report(error);
59
+ return null;
60
+ } finally {
61
+ abort.abort();
62
+ if (timer !== undefined)
63
+ clearTimeout(timer);
64
+ }
65
+ };
66
+ const connection = control.connect({
67
+ id: raw.id,
68
+ async deliver(delivery) {
69
+ const allowed = await authorize({
70
+ schemaVersion: 1,
71
+ requestId: crypto.randomUUID(),
72
+ operation: "snapshot",
73
+ conversationId: delivery.event.conversationId
74
+ });
75
+ if (!allowed) {
76
+ await connection.request({
77
+ schemaVersion: 1,
78
+ requestId: crypto.randomUUID(),
79
+ operation: "detach",
80
+ conversationId: delivery.event.conversationId
81
+ });
82
+ return;
83
+ }
84
+ if (!closed)
85
+ events.emit("agent:delivery", delivery);
86
+ },
87
+ onOverflow(delivery) {
88
+ events.emit("agent:delivery", delivery);
89
+ raw.disconnect(true);
90
+ }
91
+ });
92
+ const offRequest = events.on("agent:control", (request, ack) => {
93
+ const fail = (code, message) => ({
94
+ schemaVersion: 1,
95
+ requestId: request.requestId,
96
+ outcome: "error",
97
+ error: { code, message }
98
+ });
99
+ if (request.operation === "detach") {
100
+ for (const entry of pending)
101
+ if (entry.conversationId === request.conversationId)
102
+ entry.cancelled = true;
103
+ connection.request(request);
104
+ }
105
+ if (pending.size >= maxPending) {
106
+ ack(fail("REQUEST_CAPACITY", "Too many agent requests are pending"));
107
+ return;
108
+ }
109
+ const entry = { conversationId: request.conversationId, cancelled: false };
110
+ pending.add(entry);
111
+ const execute = async () => {
112
+ const allowed = await authorize(request);
113
+ if (entry.cancelled)
114
+ return fail("REQUEST_CANCELLED", "Agent request was detached");
115
+ if (!allowed || closed) {
116
+ if (!allowed)
117
+ await connection.request({
118
+ schemaVersion: 1,
119
+ requestId: crypto.randomUUID(),
120
+ operation: "detach",
121
+ conversationId: request.conversationId
122
+ });
123
+ return {
124
+ schemaVersion: 1,
125
+ requestId: request.requestId,
126
+ outcome: "error",
127
+ error: { code: "ACCESS_DENIED", message: "Agent access denied" }
128
+ };
129
+ }
130
+ return connection.request(request.operation === "submit" || request.operation === "respond-approval" ? { ...request, context: allowed.context } : request);
131
+ };
132
+ execute().then(ack).catch(report).finally(() => {
133
+ pending.delete(entry);
134
+ });
135
+ });
136
+ const close = () => {
137
+ if (closed)
138
+ return;
139
+ closed = true;
140
+ offRequest();
141
+ raw.off("disconnect", close);
142
+ connection.close();
143
+ cleanups.delete(close);
144
+ };
145
+ raw.on("disconnect", close);
146
+ cleanups.add(close);
147
+ });
148
+ return {
149
+ close() {
150
+ unsubscribe();
151
+ for (const close of cleanups)
152
+ close();
153
+ control.close();
154
+ }
155
+ };
156
+ }
157
+ export {
158
+ bindAgentHarnessRealtime
159
+ };
@@ -5,12 +5,12 @@ import {
5
5
  } from "../../index-ahvsksw5.js";
6
6
  import"../../index-n53mswt3.js";
7
7
  import"../../index-ct75c3at.js";
8
- import"../../index-7z9ym7t8.js";
8
+ import"../../index-x87j7csh.js";
9
9
  import"../../index-b2bz0kdm.js";
10
10
  import {
11
11
  createAgentCodingTools2
12
- } from "../../index-djjhhgjk.js";
13
- import"../../index-jzczzcsb.js";
12
+ } from "../../index-a4ajxwmb.js";
13
+ import"../../index-tgzhq07n.js";
14
14
 
15
15
  // src/agent-runtime/sandbox-bubblewrap.ts
16
16
  import { mkdir as mkdir2, mkdtemp, realpath, rm as rm2 } from "node:fs/promises";
@@ -1,4 +1,5 @@
1
1
  export { type AgentFaultStep, AgentFaultStepSchema, createFaultProviderServer, createReplayAgentProvider, defineAgentFaultPlan, } from '../../agent-runtime/fault-bench.js';
2
+ export { inspectAgentRun } from '../../agent-runtime/run-assertions.js';
2
3
  export { type AgentStoreConformanceConfig, type AgentStoreConformanceContext, runAgentStoreConformance, } from '../../agent-runtime/store-conformance.js';
3
4
  export { type AgentRaceBarrier, type AgentRaceDriver, type AgentRaceTrace, type AgentRaceTraceEntry, createAgentRaceBarrier, createAgentRaceDriver, createAgentRaceTrace, } from '../../agent-runtime/testing.js';
4
5
  //# sourceMappingURL=testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/agent-runtime/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,oBAAoB,EACpB,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,wBAAwB,GACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/agent-runtime/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,oBAAoB,EACpB,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,wBAAwB,GACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC"}
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  AgentMessageSchema2,
3
- AgentRunSchema2
3
+ AgentRunSchema2,
4
+ AgentSnapshotSchema2
4
5
  } from "../../index-8kzct1d6.js";
5
6
  import {
6
- decodeAgentConversationArchive2
7
+ decodeAgentConversationArchive2,
8
+ createToolChronology,
9
+ advanceToolChronology
7
10
  } from "../../index-r5hsgkz5.js";
8
11
  import"../../index-ssmd41kh.js";
9
12
  import {
@@ -151,6 +154,67 @@ function createReplayAgentProvider(input) {
151
154
  calls: (modelId) => calls.get(modelId) ?? 0
152
155
  };
153
156
  }
157
+ // src/agent-runtime/run-assertions.ts
158
+ function continuedCalls(snapshot, run) {
159
+ let chronology = createToolChronology();
160
+ const calls = [];
161
+ for (const message of snapshot.messages) {
162
+ if (message.role === "user" && chronology.pending === 0)
163
+ chronology = createToolChronology();
164
+ if (message.conversationId !== run.conversationId || !["assistant", "tool"].includes(message.role))
165
+ continue;
166
+ const next = advanceToolChronology(chronology, message.parts);
167
+ if (!next)
168
+ continue;
169
+ if (message.role === "tool" && run.inputMessageIds.includes(message.id)) {
170
+ for (const part of message.parts) {
171
+ if (part.type !== "tool-approval-response" || !part.approved)
172
+ continue;
173
+ const callId = next.approvals.get(part.approvalId);
174
+ const call = callId === undefined ? undefined : next.calls.get(callId);
175
+ if (callId !== undefined && call?.phase === "approved")
176
+ calls.push({ callId, toolName: call.toolName });
177
+ }
178
+ }
179
+ chronology = next;
180
+ }
181
+ return calls;
182
+ }
183
+ function inspectAgentRun(rawSnapshot, runId) {
184
+ const snapshot = AgentSnapshotSchema2.parse(rawSnapshot);
185
+ const run = snapshot.runs.find((candidate) => candidate.id === runId);
186
+ if (!run)
187
+ throw new Error(`Agent run ${runId} is absent from the snapshot`);
188
+ const parts = snapshot.messages.filter((message) => message.runId === runId && ["assistant", "tool"].includes(message.role)).flatMap((message) => message.parts);
189
+ const results = parts.filter((part) => part.type === "tool-result");
190
+ const calls = [
191
+ ...parts.filter((part) => part.type === "tool-call"),
192
+ ...continuedCalls(snapshot, run).filter((call) => results.some((result) => result.callId === call.callId && result.toolName === call.toolName))
193
+ ];
194
+ const fail = (message) => {
195
+ throw new Error(`Agent run ${runId}: ${message}`);
196
+ };
197
+ return {
198
+ run,
199
+ completed() {
200
+ const pending = parts.some((part) => part.type === "tool-approval-request" && !parts.some((response) => response.type === "tool-approval-response" && response.approvalId === part.approvalId));
201
+ if (run.state !== "completed" || run.terminalReason !== "success" || pending)
202
+ fail(`expected completed output; received ${run.state}/${run.terminalReason ?? "pending"}${pending ? " with pending approval" : ""}`);
203
+ },
204
+ calledTool(name) {
205
+ if (!calls.some((call) => call.toolName === name))
206
+ fail(`expected tool call ${name}`);
207
+ },
208
+ notCalledTool(name) {
209
+ if (calls.some((call) => call.toolName === name))
210
+ fail(`unexpected tool call ${name}`);
211
+ },
212
+ toolSucceeded(name) {
213
+ if (!calls.some((call) => call.toolName === name && results.some((result) => result.callId === call.callId && result.toolName === name && result.outcome === "success")))
214
+ fail(`expected successful result for tool ${name}`);
215
+ }
216
+ };
217
+ }
154
218
  // src/agent-runtime/store-conformance-support.ts
155
219
  function userMessage(conversationId, id) {
156
220
  return AgentMessageSchema2.parse({
@@ -1110,5 +1174,6 @@ export {
1110
1174
  createFaultProviderServer,
1111
1175
  createReplayAgentProvider,
1112
1176
  defineAgentFaultPlan,
1177
+ inspectAgentRun,
1113
1178
  runAgentStoreConformance
1114
1179
  };
@@ -89,7 +89,6 @@ import {
89
89
  registerDeferredToolCatalog,
90
90
  deferredToolCatalog,
91
91
  repairedSearchCall,
92
- createAgentRuntimeEventSink2,
93
92
  projectAgentHistoryDetailed2,
94
93
  projectAgentHistory2,
95
94
  ModelInvocationTraceSchema2,
@@ -111,35 +110,27 @@ import {
111
110
  agentGoalStateSlot2,
112
111
  agentTodoStateSlot2,
113
112
  createAgentRuntime2
114
- } from "../index-zs4ms3th.js";
113
+ } from "../index-90ppdx3q.js";
115
114
  import {
116
115
  AgentConversationSummarySchema2,
117
116
  AgentConversationPageSchema2,
118
117
  AgentConversationMessagePageSchema2
119
118
  } from "../index-kqnd6a85.js";
120
- import {
121
- DURABILITY_STEP_EVENT_KIND2,
122
- StepResultDecodeError2,
123
- StepResultNotSerializableError2,
124
- StepAbortedError2,
125
- ParkRecordDecodeError2,
126
- ParkAbortedError2
127
- } from "../index-a9pd417t.js";
119
+ import"../index-nggfa2yn.js";
128
120
  import"../index-n53mswt3.js";
129
121
  import"../index-b2bz0kdm.js";
130
122
  import {
131
123
  createTraceContext2,
132
124
  childSpan2
133
- } from "../index-hby4qhax.js";
125
+ } from "../index-yex7eg1v.js";
134
126
  import"../index-9pw0a51a.js";
135
127
  import"../index-ct75c3at.js";
136
- import"../index-7z9ym7t8.js";
137
- import"../index-dvwj1f43.js";
138
- import"../index-n9tyz8z3.js";
128
+ import"../index-x87j7csh.js";
129
+ import"../index-m2xqkv55.js";
130
+ import"../index-r956rndn.js";
139
131
  import {
140
- mountAgent2,
141
- buildToolManifest2
142
- } from "../index-xkhk5d6g.js";
132
+ mountAgent2
133
+ } from "../index-1khy8y7n.js";
143
134
  import {
144
135
  createBoundedSinkManager
145
136
  } from "../index-h97tqqp1.js";
@@ -177,6 +168,14 @@ import {
177
168
  defineModelRegistry2,
178
169
  validateAgentModelSnapshot2
179
170
  } from "../index-nx6eazt0.js";
171
+ import {
172
+ DURABILITY_STEP_EVENT_KIND2,
173
+ StepResultDecodeError2,
174
+ StepResultNotSerializableError2,
175
+ StepAbortedError2,
176
+ ParkRecordDecodeError2,
177
+ ParkAbortedError2
178
+ } from "../index-5vyd0fkb.js";
180
179
  import {
181
180
  AgentSandboxRestrictionSchema2,
182
181
  AgentSandboxGradeSchema2,
@@ -188,12 +187,18 @@ import {
188
187
  import {
189
188
  createMemoryAgentRuntimeStore2
190
189
  } from "../index-adhgd4pe.js";
191
- import"../index-ewbaywk5.js";
192
- import"../index-r1z0rd9c.js";
190
+ import {
191
+ createAgentRuntimeEventSink2
192
+ } from "../index-vgkbcnkc.js";
193
+ import {
194
+ buildToolManifest2
195
+ } from "../index-kmpzj1cq.js";
196
+ import"../index-dnn9z96q.js";
197
+ import"../index-7n68nmc6.js";
193
198
  import {
194
199
  defineRuntimeTool2,
195
200
  executableAgentRuntimeTools
196
- } from "../index-jzczzcsb.js";
201
+ } from "../index-tgzhq07n.js";
197
202
 
198
203
  // src/agent-runtime/child-tools.ts
199
204
  import { z as z2 } from "zod";