stitchkit 0.136.0 → 0.136.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 (128) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +12 -0
  3. package/dist/agent-executor/executor-contract.d.ts.map +1 -1
  4. package/dist/agent-executor/vocabulary.d.ts +80 -0
  5. package/dist/agent-executor/vocabulary.d.ts.map +1 -1
  6. package/dist/agent-parts/model.d.ts +94 -0
  7. package/dist/agent-parts/model.d.ts.map +1 -1
  8. package/dist/agent-parts/parts.d.ts +176 -0
  9. package/dist/agent-parts/parts.d.ts.map +1 -1
  10. package/dist/agent-runtime/browser/browser-control-contract.d.ts +440 -0
  11. package/dist/agent-runtime/browser/browser-control-contract.d.ts.map +1 -1
  12. package/dist/agent-runtime/browser/control-schema.d.ts +528 -0
  13. package/dist/agent-runtime/browser/control-schema.d.ts.map +1 -1
  14. package/dist/agent-runtime/event-schema.d.ts +704 -0
  15. package/dist/agent-runtime/event-schema.d.ts.map +1 -1
  16. package/dist/agent-runtime/history/run-history-parts.d.ts.map +1 -1
  17. package/dist/agent-runtime/loop/provider-stream-parts.d.ts.map +1 -1
  18. package/dist/agent-runtime/loop/provider-stream-segments.d.ts +0 -2
  19. package/dist/agent-runtime/loop/provider-stream-segments.d.ts.map +1 -1
  20. package/dist/agent-runtime/loop/run-approval-signature.d.ts +5 -1
  21. package/dist/agent-runtime/loop/run-approval-signature.d.ts.map +1 -1
  22. package/dist/agent-runtime/loop/run-loop-events.d.ts +6 -1
  23. package/dist/agent-runtime/loop/run-loop-events.d.ts.map +1 -1
  24. package/dist/agent-runtime/loop/run-stream-parts.d.ts.map +1 -1
  25. package/dist/agent-runtime/loop/run-stream-recorded.d.ts.map +1 -1
  26. package/dist/agent-runtime/loop/run-tool-call.d.ts +11 -3
  27. package/dist/agent-runtime/loop/run-tool-call.d.ts.map +1 -1
  28. package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts +4 -0
  29. package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts.map +1 -1
  30. package/dist/agent-runtime/providers/ai-sdk-tools.d.ts.map +1 -1
  31. package/dist/agent-runtime/runtime-internals.d.ts +1 -3
  32. package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
  33. package/dist/agent-runtime/schemas-json-projection.d.ts +29 -0
  34. package/dist/agent-runtime/schemas-json-projection.d.ts.map +1 -0
  35. package/dist/agent-runtime/schemas-message.d.ts +88 -0
  36. package/dist/agent-runtime/schemas-message.d.ts.map +1 -1
  37. package/dist/agent-runtime/schemas-run.d.ts +88 -0
  38. package/dist/agent-runtime/schemas-run.d.ts.map +1 -1
  39. package/dist/agent-runtime/stores/branch-messages.d.ts.map +1 -1
  40. package/dist/agent-runtime/stores/branch-replay.d.ts +264 -0
  41. package/dist/agent-runtime/stores/branch-replay.d.ts.map +1 -1
  42. package/dist/agent-runtime/stores/conversations.d.ts +88 -0
  43. package/dist/agent-runtime/stores/conversations.d.ts.map +1 -1
  44. package/dist/agent-runtime/stores/sql-rows.d.ts +64 -0
  45. package/dist/agent-runtime/stores/sql-rows.d.ts.map +1 -1
  46. package/dist/agent-runtime/stores/store-driver-contract.d.ts +616 -0
  47. package/dist/agent-runtime/stores/store-driver-contract.d.ts.map +1 -1
  48. package/dist/agent-runtime/stores/store-events.d.ts +1056 -0
  49. package/dist/agent-runtime/stores/store-events.d.ts.map +1 -1
  50. package/dist/agent-runtime/stores/store.d.ts +1232 -0
  51. package/dist/agent-runtime/stores/store.d.ts.map +1 -1
  52. package/dist/agent-runtime/terminal-commit.d.ts +69 -5
  53. package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
  54. package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +164 -36
  55. package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts.map +1 -1
  56. package/dist/agent-runtime/testing/store-conformance-support.d.ts +82 -18
  57. package/dist/agent-runtime/testing/store-conformance-support.d.ts.map +1 -1
  58. package/dist/application/diagnostic-journal-manager.d.ts +1 -1
  59. package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
  60. package/dist/application/notification-delivery.d.ts.map +1 -1
  61. package/dist/entrypoints/agent-executor/acp.js +5 -4
  62. package/dist/entrypoints/agent-executor/claude-sdk.js +7 -6
  63. package/dist/entrypoints/agent-executor/claude.js +7 -6
  64. package/dist/entrypoints/agent-executor/codex.js +6 -5
  65. package/dist/entrypoints/agent-executor/testing/claude-sdk.js +4 -3
  66. package/dist/entrypoints/agent-executor/testing.js +7 -6
  67. package/dist/entrypoints/agent-executor.js +7 -7
  68. package/dist/entrypoints/agent-runtime/ai-sdk.js +30 -24
  69. package/dist/entrypoints/agent-runtime/anthropic.js +3 -3
  70. package/dist/entrypoints/agent-runtime/browser.js +8 -7
  71. package/dist/entrypoints/agent-runtime/harness.js +14 -14
  72. package/dist/entrypoints/agent-runtime/openai.js +3 -3
  73. package/dist/entrypoints/agent-runtime/openrouter.js +3 -3
  74. package/dist/entrypoints/agent-runtime/postgres.js +9 -9
  75. package/dist/entrypoints/agent-runtime/realtime.js +9 -8
  76. package/dist/entrypoints/agent-runtime/sqlite/bun.js +10 -10
  77. package/dist/entrypoints/agent-runtime/sqlite/node.js +10 -10
  78. package/dist/entrypoints/agent-runtime/testing.js +8 -8
  79. package/dist/entrypoints/agent-runtime.js +21 -21
  80. package/dist/entrypoints/application/diagnostic-journal.js +14 -10
  81. package/dist/entrypoints/application.js +16 -4
  82. package/dist/entrypoints/files/packaging.js +72 -36
  83. package/dist/entrypoints/tools/agent.js +2 -2
  84. package/dist/entrypoints/tools/toolkit.js +1 -1
  85. package/dist/entrypoints/tools.js +5 -3
  86. package/dist/files/client-declarations.d.ts +11 -3
  87. package/dist/files/client-declarations.d.ts.map +1 -1
  88. package/dist/files/client-package.d.ts.map +1 -1
  89. package/dist/index-1psbyyhj.js +21 -0
  90. package/dist/{index-kzsetgh9.js → index-26v8hjqm.js} +4 -4
  91. package/dist/{index-4243301z.js → index-2wm9b9vs.js} +5 -5
  92. package/dist/{index-tb36xawm.js → index-32ew02z1.js} +1 -1
  93. package/dist/{index-1en7k3q5.js → index-4q9tmzea.js} +3 -3
  94. package/dist/{index-shte29pg.js → index-8cnfgwg8.js} +148 -106
  95. package/dist/{index-mkmep637.js → index-9m1m92rg.js} +1 -1
  96. package/dist/index-a1rjr381.js +114 -0
  97. package/dist/{index-6kwdfb9m.js → index-akesakvj.js} +23 -4
  98. package/dist/{index-rg08syp1.js → index-d5mhgx72.js} +7 -5
  99. package/dist/{index-36mtj8xm.js → index-e4w0sfm1.js} +2 -2
  100. package/dist/{index-jperyn0c.js → index-gj4wdts6.js} +1 -1
  101. package/dist/{index-pd9e8rz4.js → index-gvv7y0s4.js} +1 -1
  102. package/dist/{index-vebzvse6.js → index-jy907kcs.js} +24 -1
  103. package/dist/{index-54wp467c.js → index-k5azb3v3.js} +4 -21
  104. package/dist/{index-qcy8et93.js → index-kaq9nb7h.js} +6 -6
  105. package/dist/{index-vse7x1qt.js → index-knqye3gv.js} +1 -1
  106. package/dist/{index-tav72wz5.js → index-ks4rhtcc.js} +5 -0
  107. package/dist/{index-xnqab06h.js → index-mtpcax6d.js} +3 -3
  108. package/dist/{index-7qza24g1.js → index-px9r6wv1.js} +1 -1
  109. package/dist/{index-epwvp88y.js → index-r9w7wfgn.js} +1 -1
  110. package/dist/{index-aacwkve4.js → index-sjq4akrx.js} +3 -5
  111. package/dist/{index-5dxgx3yj.js → index-tcv71frn.js} +1 -1
  112. package/dist/{index-1zy31r3b.js → index-v92djygb.js} +1 -1
  113. package/dist/{index-9f60gnfn.js → index-xaa3603f.js} +4 -11
  114. package/dist/{index-j3r7r1mh.js → index-yv7d6tav.js} +1 -1
  115. package/dist/{index-hberxns4.js → index-zagc12j1.js} +5 -5
  116. package/dist/{index-j5vzhj3d.js → index-zqc64g69.js} +3 -3
  117. package/dist/{index-hpzhz1vm.js → index-zthekmrt.js} +2 -2
  118. package/dist/internal/json-stringify.d.ts +37 -0
  119. package/dist/internal/json-stringify.d.ts.map +1 -0
  120. package/llms/agent-runtime.5.txt +1 -1
  121. package/llms/agent-runtime.txt +14 -0
  122. package/llms/application.2.txt +6 -3
  123. package/llms/application.3.txt +2 -1
  124. package/llms/application.txt +4 -1
  125. package/llms/process.2.txt +2 -3
  126. package/llms-full.txt +29 -9
  127. package/llms.txt +2 -2
  128. package/package.json +1 -1
@@ -13,7 +13,7 @@ import {
13
13
  AgentModelAssistantMessageSchema2,
14
14
  AgentModelToolMessageSchema2,
15
15
  AgentModelMessageSchema2
16
- } from "../index-vebzvse6.js";
16
+ } from "../index-jy907kcs.js";
17
17
  import {
18
18
  createBoundedSinkManager
19
19
  } from "../index-7an2fs5h.js";
@@ -35,7 +35,7 @@ import {
35
35
  AgentUsageValueSchema2,
36
36
  AgentCostValueSchema2,
37
37
  AgentUsageSchema2
38
- } from "../index-j3r7r1mh.js";
38
+ } from "../index-yv7d6tav.js";
39
39
  import {
40
40
  AgentProviderEnvelopeSchema2,
41
41
  AgentTextPartSchema2,
@@ -49,10 +49,10 @@ import {
49
49
  AgentOpaquePartSchema2,
50
50
  AgentControlPartSchema2,
51
51
  AgentMessagePartSchema2
52
- } from "../index-tav72wz5.js";
52
+ } from "../index-ks4rhtcc.js";
53
53
  import {
54
54
  AgentProviderResponseSchema2
55
- } from "../index-7qza24g1.js";
55
+ } from "../index-px9r6wv1.js";
56
56
  import {
57
57
  AgentRunStateSchema2,
58
58
  AgentRunQueuePrioritySchema2,
@@ -64,7 +64,7 @@ import {
64
64
  AgentRunSchema2,
65
65
  AgentSnapshotSchema2,
66
66
  AgentRunMetricsSchema2
67
- } from "../index-pd9e8rz4.js";
67
+ } from "../index-gvv7y0s4.js";
68
68
  import {
69
69
  AgentAdmissionEventSchema2,
70
70
  AgentTransientDeltaEventSchema2,
@@ -82,14 +82,7 @@ import {
82
82
  AgentRuntimeEventCursorSchema2,
83
83
  advanceAgentRuntimeEventCursor2,
84
84
  agentDurableEventId2
85
- } from "../index-1en7k3q5.js";
86
- import {
87
- AgentRuntimeConflictError2,
88
- AgentRunUnsettledError2,
89
- parseOptionalAgentUsage,
90
- addUsage,
91
- createIdleDeadline
92
- } from "../index-9f60gnfn.js";
85
+ } from "../index-4q9tmzea.js";
93
86
  import {
94
87
  PurgeInvocationPayloadsInputSchema2,
95
88
  PurgeInvocationPayloadsResultSchema2,
@@ -131,7 +124,7 @@ import {
131
124
  AgentSeedReceiptSchema2,
132
125
  AgentHistoryMutationSchema2,
133
126
  ACTIVE_AGENT_RUN_STATES2
134
- } from "../index-qcy8et93.js";
127
+ } from "../index-kaq9nb7h.js";
135
128
  import"../index-ha1tv70k.js";
136
129
  import"../index-d1pdv8qc.js";
137
130
  import"../index-dsa676h8.js";
@@ -178,7 +171,7 @@ import {
178
171
  createAgentEventSearchTools2,
179
172
  AgentStoreUnsupportedCapabilityError2,
180
173
  createAgentRuntimeStore2
181
- } from "../index-rg08syp1.js";
174
+ } from "../index-d5mhgx72.js";
182
175
  import {
183
176
  AgentContextOverflowError2,
184
177
  unknownUsage,
@@ -224,7 +217,7 @@ import {
224
217
  AgentTokenCountSchema2,
225
218
  selectAgentHistory2,
226
219
  composeAgentPrompt2
227
- } from "../index-shte29pg.js";
220
+ } from "../index-8cnfgwg8.js";
228
221
  import"../index-m38ej7e5.js";
229
222
  import"../index-dmrx8xma.js";
230
223
  import {
@@ -262,13 +255,20 @@ import {
262
255
  AgentConversationSummarySchema2,
263
256
  AgentConversationPageSchema2,
264
257
  AgentConversationMessagePageSchema2
265
- } from "../index-1zy31r3b.js";
258
+ } from "../index-v92djygb.js";
266
259
  import"../index-6kec3b14.js";
267
260
  import"../index-tgehj4bp.js";
268
261
  import"../index-5c4m8zdf.js";
269
262
  import {
270
263
  createMemoryAgentRuntimeStore2
271
- } from "../index-j5vzhj3d.js";
264
+ } from "../index-zqc64g69.js";
265
+ import {
266
+ AgentRuntimeConflictError2,
267
+ AgentRunUnsettledError2,
268
+ parseOptionalAgentUsage,
269
+ addUsage,
270
+ createIdleDeadline
271
+ } from "../index-xaa3603f.js";
272
272
  import {
273
273
  isAssistantHistoryEvidence2,
274
274
  isCompleteAgentHistoryTurn
@@ -276,7 +276,7 @@ import {
276
276
  import"../index-p9cab61p.js";
277
277
  import {
278
278
  createAgentRuntimeEventSink2
279
- } from "../index-jperyn0c.js";
279
+ } from "../index-gj4wdts6.js";
280
280
  import {
281
281
  isObjectSchemaType,
282
282
  stripStrictOptionalNulls
@@ -287,7 +287,7 @@ import {
287
287
  isAgentProviderError2,
288
288
  classifyProviderFailure2,
289
289
  isToolResultFailure2
290
- } from "../index-vse7x1qt.js";
290
+ } from "../index-knqye3gv.js";
291
291
  import {
292
292
  buildToolManifest2
293
293
  } from "../index-08a3qfr8.js";
@@ -300,7 +300,7 @@ import {
300
300
  import {
301
301
  zodToAgentInputJsonSchema,
302
302
  mountAgentTools2
303
- } from "../index-54wp467c.js";
303
+ } from "../index-k5azb3v3.js";
304
304
  import"../index-rjs94dny.js";
305
305
  import"../index-xrgn784x.js";
306
306
  import"../index-bjrcbcn2.js";
@@ -20,6 +20,9 @@ import {
20
20
  import"../../index-6kec3b14.js";
21
21
  import"../../index-673drwkn.js";
22
22
  import"../../index-jwtmw39p.js";
23
+ import {
24
+ projectJson
25
+ } from "../../index-a1rjr381.js";
23
26
  import {
24
27
  attemptExclusiveLock
25
28
  } from "../../index-43k180c2.js";
@@ -41,9 +44,6 @@ import {
41
44
  // src/application/diagnostic-journal.ts
42
45
  import { randomUUID } from "node:crypto";
43
46
 
44
- // src/application/diagnostic-journal-manager.ts
45
- import { z as z5 } from "zod";
46
-
47
47
  // src/application/diagnostic-journal-storage.ts
48
48
  import { constants } from "node:fs";
49
49
  import { lstat as lstat2, open, realpath, rename as rename2, unlink } from "node:fs/promises";
@@ -663,6 +663,13 @@ function waitForProgress(progressWaiters, predicate, options) {
663
663
  onProgress();
664
664
  });
665
665
  }
666
+ function admittedEventJson(schema, event) {
667
+ const parsed = schema.safeParse(event);
668
+ if (!parsed.success)
669
+ return;
670
+ const json = projectJson(parsed.data);
671
+ return json.ok && schema.safeParse(json.value).success ? json.value : undefined;
672
+ }
666
673
  function createDiagnosticJournalManager(config, storage) {
667
674
  const limits = DiagnosticJournalLimitsSchema2.parse(config.limits);
668
675
  const encoder = new TextEncoder;
@@ -789,13 +796,10 @@ function createDiagnosticJournalManager(config, storage) {
789
796
  return refuse("failed");
790
797
  if (state !== "open")
791
798
  return refuse("closed");
792
- const parsed = config.eventSchema.safeParse(event);
793
- if (!parsed.success)
794
- return refuse("invalid");
795
- const json = z5.json().safeParse(parsed.data);
796
- if (!json.success)
799
+ const json = admittedEventJson(config.eventSchema, event);
800
+ if (json === undefined)
797
801
  return refuse("invalid");
798
- const payload = encoder.encode(JSON.stringify(json.data));
802
+ const payload = encoder.encode(JSON.stringify(json));
799
803
  if (payload.byteLength > limits.maxEventBytes)
800
804
  return refuse("oversized");
801
805
  if (pendingItems >= limits.maxPendingItems)
@@ -805,7 +809,7 @@ function createDiagnosticJournalManager(config, storage) {
805
809
  schemaVersion: 1,
806
810
  epoch: config.epoch,
807
811
  sequence,
808
- event: json.data
812
+ event: json
809
813
  });
810
814
  const bytes = encoder.encode(`${JSON.stringify(frame)}
811
815
  `);
@@ -93,6 +93,10 @@ import {
93
93
  managedResourceDependencyId2,
94
94
  defineManagedResource2
95
95
  } from "../index-50ejfz75.js";
96
+ import {
97
+ describeJsonRefusal,
98
+ projectJson
99
+ } from "../index-a1rjr381.js";
96
100
  import {
97
101
  jsonResponse
98
102
  } from "../index-kyejf658.js";
@@ -1325,8 +1329,12 @@ function projectionFor(config, version) {
1325
1329
  return config.retiredVersions && Object.hasOwn(config.retiredVersions, version) ? config.retiredVersions[version] : undefined;
1326
1330
  }
1327
1331
  function recordable(result) {
1328
- const parsed = z7.json().safeParse(result ?? null);
1329
- return parsed.success ? { receipt: parsed.data } : { receipt: null, unrecorded: "not-json" };
1332
+ const projected = projectJson(result);
1333
+ return projected.ok ? { receipt: projected.value } : {
1334
+ receipt: null,
1335
+ unrecorded: "not-json",
1336
+ refusal: describeJsonRefusal(projected.refusal)
1337
+ };
1330
1338
  }
1331
1339
  function notificationDeliveryPlan(config, payload) {
1332
1340
  return NotificationDeliveryStateSchema.parse({
@@ -1381,7 +1389,11 @@ async function deliverNotification(input) {
1381
1389
  let confirmed;
1382
1390
  let dropped;
1383
1391
  try {
1384
- confirmed = await confirm({ action, ...entry });
1392
+ confirmed = await confirm({
1393
+ action,
1394
+ receipt: entry.receipt,
1395
+ ...entry.unrecorded && { unrecorded: entry.unrecorded }
1396
+ });
1385
1397
  } catch (error) {
1386
1398
  if (entry.unrecorded || !(error instanceof OutboxStateLimitError))
1387
1399
  throw error;
@@ -1391,7 +1403,7 @@ async function deliverNotification(input) {
1391
1403
  if (dropped)
1392
1404
  await input.report(dropped);
1393
1405
  if (entry.unrecorded) {
1394
- await input.report(new Error(`Notification action "${action}" returned a receipt that is not JSON`));
1406
+ await input.report(new Error(`Notification action "${action}" returned a receipt that is not JSON: ${entry.refusal}`));
1395
1407
  }
1396
1408
  if (!confirmed)
1397
1409
  return false;
@@ -157,13 +157,12 @@ async function buildClientArtifact(options) {
157
157
  // src/files/client-package.ts
158
158
  import { createHash as createHash3 } from "node:crypto";
159
159
  import { existsSync as existsSync3 } from "node:fs";
160
- import { copyFile as copyFile2, mkdir as mkdir3, mkdtemp as mkdtemp2, readFile as readFile4, realpath as realpath3, rm as rm3, writeFile as writeFile5 } from "node:fs/promises";
160
+ import { copyFile as copyFile2, mkdir as mkdir4, mkdtemp as mkdtemp3, readFile as readFile4, realpath as realpath4, rm as rm3, writeFile as writeFile5 } from "node:fs/promises";
161
161
  import { tmpdir as tmpdir2 } from "node:os";
162
162
  import { dirname as dirname5, extname, isAbsolute, join as join6, normalize, relative as relative3, resolve as resolve4 } from "node:path";
163
163
 
164
164
  // src/files/client-declarations.ts
165
- import { randomUUID } from "node:crypto";
166
- import { rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
165
+ import { mkdir as mkdir2, mkdtemp as mkdtemp2, realpath, rm as rm2, stat, symlink, writeFile as writeFile2 } from "node:fs/promises";
167
166
  import { builtinModules } from "node:module";
168
167
  import { dirname as dirname3, join as join3, relative } from "node:path";
169
168
 
@@ -412,34 +411,70 @@ function rewriteDeclarationTree(directory, rewrite) {
412
411
  }
413
412
 
414
413
  // src/files/client-declarations.ts
414
+ async function ancestorNodeModules(from) {
415
+ const nearestFirst = [];
416
+ const seen = new Set;
417
+ for (let directory = from;; directory = dirname3(directory)) {
418
+ const candidate = join3(directory, "node_modules");
419
+ const info = await stat(candidate).catch(() => {
420
+ return;
421
+ });
422
+ if (info?.isDirectory()) {
423
+ const target = await realpath(candidate).catch(() => {
424
+ return;
425
+ });
426
+ if (target !== undefined && !seen.has(target)) {
427
+ seen.add(target);
428
+ nearestFirst.push(target);
429
+ }
430
+ }
431
+ const parent = dirname3(directory);
432
+ if (parent === directory)
433
+ break;
434
+ }
435
+ return nearestFirst.reverse();
436
+ }
437
+ async function prepareDeclarationConfigHost(hostRoot, root) {
438
+ const targets = await ancestorNodeModules(root);
439
+ const linkType = process.platform === "win32" ? "junction" : "dir";
440
+ let current = hostRoot;
441
+ for (const [index, target] of targets.entries()) {
442
+ current = join3(current, `d${index}`);
443
+ await mkdir2(current);
444
+ await symlink(target, join3(current, "node_modules"), linkType);
445
+ }
446
+ return current;
447
+ }
415
448
  async function emitClientDeclarations(input) {
416
449
  const root = dirname3(input.tsconfig);
417
- const generated = join3(root, `.client-package-${randomUUID()}.tsconfig.json`);
418
- await writeFile2(generated, `${JSON.stringify({
419
- extends: input.tsconfig,
420
- compilerOptions: {
421
- noEmit: false,
422
- declaration: true,
423
- emitDeclarationOnly: true,
424
- declarationMap: false,
425
- composite: false,
426
- incremental: false,
427
- rootDir: root,
428
- outDir: input.outDir,
429
- declarationDir: input.outDir
430
- },
431
- files: input.entries,
432
- include: []
433
- }, null, 2)}
434
- `);
450
+ const hostRoot = await mkdtemp2(join3(input.work, "declarations-"));
435
451
  try {
452
+ const configHost = await prepareDeclarationConfigHost(hostRoot, root);
453
+ const generated = join3(configHost, "tsconfig.json");
454
+ await writeFile2(generated, `${JSON.stringify({
455
+ extends: input.tsconfig,
456
+ compilerOptions: {
457
+ noEmit: false,
458
+ declaration: true,
459
+ emitDeclarationOnly: true,
460
+ declarationMap: false,
461
+ composite: false,
462
+ incremental: false,
463
+ rootDir: root,
464
+ outDir: input.outDir,
465
+ declarationDir: input.outDir
466
+ },
467
+ files: input.entries,
468
+ include: []
469
+ }, null, 2)}
470
+ `);
436
471
  const [compiler, ...leading] = input.tsc;
437
472
  const emitted = await runClientTool(input.step, compiler, [...leading, "-p", generated], root);
438
473
  if (!emitted.ok) {
439
474
  throw new ClientPackageError("declarations", `Client package declarations failed (exit ${emitted.exit}): ${emitted.output}`, { output: emitted.output });
440
475
  }
441
476
  } finally {
442
- await rm2(generated, { force: true });
477
+ await rm2(hostRoot, { recursive: true, force: true });
443
478
  }
444
479
  }
445
480
  function packageOf(specifier) {
@@ -481,7 +516,7 @@ function undeclared(file, specifier, name) {
481
516
 
482
517
  // src/files/client-package-bundle.ts
483
518
  import { realpathSync } from "node:fs";
484
- import { realpath, writeFile as writeFile3 } from "node:fs/promises";
519
+ import { realpath as realpath2, writeFile as writeFile3 } from "node:fs/promises";
485
520
  import { join as join4 } from "node:path";
486
521
  var REPLACEMENT_LOADERS = {
487
522
  ".json": "json",
@@ -562,7 +597,7 @@ async function bundleClientPackage(input) {
562
597
  const graph = await readClientBuildGraph(metafile, input.root);
563
598
  const bundled = new Set;
564
599
  for (const module of graph.modules.keys())
565
- bundled.add(await realpath(module).catch(() => module));
600
+ bundled.add(await realpath2(module).catch(() => module));
566
601
  for (const module of input.replacements.keys()) {
567
602
  if (bundled.has(realpathSync(module)))
568
603
  continue;
@@ -574,7 +609,7 @@ async function bundleClientPackage(input) {
574
609
  // src/files/client-package-proof.ts
575
610
  import { createHash as createHash2 } from "node:crypto";
576
611
  import { existsSync as existsSync2 } from "node:fs";
577
- import { copyFile, mkdir as mkdir2, readdir, readFile as readFile3, realpath as realpath2, writeFile as writeFile4 } from "node:fs/promises";
612
+ import { copyFile, mkdir as mkdir3, readdir, readFile as readFile3, realpath as realpath3, writeFile as writeFile4 } from "node:fs/promises";
578
613
  import { basename as basename2, dirname as dirname4, join as join5, relative as relative2 } from "node:path";
579
614
  import { z as z3 } from "zod";
580
615
  var InstalledManifestSchema = z3.object({ version: z3.string() });
@@ -582,7 +617,7 @@ async function resolveExternalPackage(from, name) {
582
617
  for (let directory = from;; directory = dirname4(directory)) {
583
618
  const candidate = join5(directory, "node_modules", name);
584
619
  if (existsSync2(join5(candidate, "package.json"))) {
585
- const real = await realpath2(candidate);
620
+ const real = await realpath3(candidate);
586
621
  const manifest = InstalledManifestSchema.parse(safeJsonParse(await readFile3(join5(real, "package.json"), "utf8")));
587
622
  return { directory: real, version: manifest.version };
588
623
  }
@@ -765,7 +800,7 @@ async function proveTypes(input) {
765
800
  export { J${index} };
766
801
  `;
767
802
  })).join(""));
768
- await mkdir2(join5(consumer, "typecheck"));
803
+ await mkdir3(join5(consumer, "typecheck"));
769
804
  for (const [index, source] of (options.proof?.typecheck ?? []).entries()) {
770
805
  const copy = `typecheck/${index}-${basename2(source)}`;
771
806
  await copyFile(source, join5(consumer, copy));
@@ -895,7 +930,7 @@ function planReplacements(options) {
895
930
  }
896
931
  async function refuseBundledExternals(graph, externals) {
897
932
  for (const module of graph.modules.keys()) {
898
- const real = await realpath3(module);
933
+ const real = await realpath4(module);
899
934
  for (const [name, external] of externals) {
900
935
  if (!real.startsWith(`${external.directory}/`))
901
936
  continue;
@@ -916,7 +951,7 @@ async function stage(options, planned, graph, staged) {
916
951
  for (const [subpath, path] of planned.exportedFiles)
917
952
  exported[subpath] = path;
918
953
  for (const [target, source] of planned.files) {
919
- await mkdir3(dirname5(join6(staged, target)), { recursive: true });
954
+ await mkdir4(dirname5(join6(staged, target)), { recursive: true });
920
955
  await copyFile2(source, join6(staged, target));
921
956
  }
922
957
  const present = (record) => record !== undefined && Object.keys(record).length > 0 ? record : undefined;
@@ -939,7 +974,7 @@ async function buildClientPackage(options) {
939
974
  signal: options.signal
940
975
  };
941
976
  const bun = options.executables?.bun ?? "bun";
942
- const work = await mkdtemp2(join6(tmpdir2(), "stitchkit-client-package-"));
977
+ const work = await mkdtemp3(join6(tmpdir2(), "stitchkit-client-package-"));
943
978
  await rm3(planned.tarball, { force: true });
944
979
  try {
945
980
  const externals = new Map;
@@ -970,6 +1005,7 @@ async function buildClientPackage(options) {
970
1005
  tsc,
971
1006
  tsconfig: planned.tsconfig,
972
1007
  entries: [...planned.entries.values()],
1008
+ work,
973
1009
  outDir: join6(staged, "dist")
974
1010
  });
975
1011
  normalizeClientDeclarations(join6(staged, "dist"), {
@@ -977,13 +1013,13 @@ async function buildClientPackage(options) {
977
1013
  runtime: options.runtime ?? "node"
978
1014
  });
979
1015
  await stage(options, planned, graph, staged);
980
- await mkdir3(dirname5(planned.tarball), { recursive: true });
1016
+ await mkdir4(dirname5(planned.tarball), { recursive: true });
981
1017
  const packed = await runClientTool(step, bun, ["pm", "pack", "--filename", planned.tarball, "--ignore-scripts", "--quiet"], staged);
982
1018
  if (!packed.ok) {
983
1019
  throw new ClientPackageError("install", `Client package pack failed (exit ${packed.exit}): ${packed.output}`, { output: packed.output });
984
1020
  }
985
1021
  const consumer = join6(work, "consumer");
986
- await mkdir3(consumer);
1022
+ await mkdir4(consumer);
987
1023
  const proven = await proveClientPackage({
988
1024
  options,
989
1025
  step,
@@ -1101,7 +1137,7 @@ import { z as z5 } from "zod";
1101
1137
  // src/files/native-packaging-plugin.ts
1102
1138
  import { existsSync as existsSync4, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
1103
1139
  import { basename as basename3, join as join7 } from "node:path";
1104
- var realpath4 = (path) => {
1140
+ var realpath5 = (path) => {
1105
1141
  try {
1106
1142
  return realpathSync2(path);
1107
1143
  } catch {
@@ -1132,7 +1168,7 @@ function loaderInstallation(path, loaderName) {
1132
1168
  function nativePlugin(owner, specifiers, embedded, companionEntry) {
1133
1169
  const contents = nativeLoaderSource(specifiers, "static");
1134
1170
  const external = new Set(Object.values(specifiers));
1135
- const ownLoader = realpath4(owner.loaderPath);
1171
+ const ownLoader = realpath5(owner.loaderPath);
1136
1172
  const loaderFile = basename3(owner.loaderName);
1137
1173
  return {
1138
1174
  name: "stitchkit-native-packaging",
@@ -1152,7 +1188,7 @@ function nativePlugin(owner, specifiers, embedded, companionEntry) {
1152
1188
  return { contents, loader: "js" };
1153
1189
  if (basename3(args.path) !== loaderFile)
1154
1190
  return;
1155
- if (realpath4(args.path) === ownLoader)
1191
+ if (realpath5(args.path) === ownLoader)
1156
1192
  return { contents, loader: "js" };
1157
1193
  const foreign = loaderInstallation(args.path, owner.loaderName);
1158
1194
  if (!foreign)
@@ -1165,7 +1201,7 @@ function nativePlugin(owner, specifiers, embedded, companionEntry) {
1165
1201
  return bytes ? { contents: bytes, loader: "napi" } : undefined;
1166
1202
  });
1167
1203
  if (companionEntry !== undefined)
1168
- build.onResolve({ filter: /./ }, (args) => (args.importer === owner.loaderPath || realpath4(args.importer) === ownLoader) && external.has(args.path) ? { path: args.path, external: true } : undefined);
1204
+ build.onResolve({ filter: /./ }, (args) => (args.importer === owner.loaderPath || realpath5(args.importer) === ownLoader) && external.has(args.path) ? { path: args.path, external: true } : undefined);
1169
1205
  }
1170
1206
  };
1171
1207
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentModelProviderOptionsSchema2,
3
3
  AgentModelMessageSchema2
4
- } from "../../index-vebzvse6.js";
4
+ } from "../../index-jy907kcs.js";
5
5
  import"../../index-ha1tv70k.js";
6
6
  import"../../index-d1pdv8qc.js";
7
7
  import"../../index-dsa676h8.js";
@@ -16,7 +16,7 @@ import {
16
16
  } from "../../index-125ks2ec.js";
17
17
  import {
18
18
  buildAgentTools
19
- } from "../../index-54wp467c.js";
19
+ } from "../../index-k5azb3v3.js";
20
20
  import"../../index-bjrcbcn2.js";
21
21
  import"../../index-7csn6pva.js";
22
22
  import {
@@ -25,7 +25,7 @@ import"../../index-efbzm2se.js";
25
25
  import"../../index-a09r9ff0.js";
26
26
  import {
27
27
  mountAgentTools2
28
- } from "../../index-54wp467c.js";
28
+ } from "../../index-k5azb3v3.js";
29
29
  import"../../index-rjs94dny.js";
30
30
  import"../../index-xrgn784x.js";
31
31
  import"../../index-bjrcbcn2.js";
@@ -79,11 +79,13 @@ import {
79
79
  findUntypedProperties2
80
80
  } from "../index-3kb8dw48.js";
81
81
  import {
82
- AgentToolError2,
83
- isAgentToolError2,
84
82
  defineAgentTool2,
85
83
  mountAgentTools2
86
- } from "../index-54wp467c.js";
84
+ } from "../index-k5azb3v3.js";
85
+ import {
86
+ AgentToolError2,
87
+ isAgentToolError2
88
+ } from "../index-1psbyyhj.js";
87
89
  import {
88
90
  createToolInvoker2
89
91
  } from "../index-yjx5jna7.js";
@@ -7,6 +7,8 @@ export interface ClientDeclarationsInput {
7
7
  tsconfig: string;
8
8
  /** Absolute paths of the entry modules. */
9
9
  entries: readonly string[];
10
+ /** Temporary build directory that hosts the generated tsconfig outside the project tree. */
11
+ work: string;
10
12
  /** Where the declaration tree is written, mirroring the tsconfig's directory. */
11
13
  outDir: string;
12
14
  }
@@ -14,9 +16,15 @@ export interface ClientDeclarationsInput {
14
16
  * Emit declarations for the entries and what they import, and nothing else of
15
17
  * the project: an unrelated file with a type error does not fail a client.
16
18
  *
17
- * The generated config sits beside the project's own for the length of the
18
- * run. Anywhere else, the type roots and `types` the project relies on would be
19
- * looked up from the wrong directory.
19
+ * The generated config lives inside `input.work`, never in the project tree.
20
+ * Because TypeScript resolves default `typeRoots` and non-`@types` `types`
21
+ * entries by walking `node_modules` upward from the config's directory, the
22
+ * config is nested under symlinks mirroring the project's ancestor
23
+ * `node_modules` chain while `extends` preserves every relative path declared
24
+ * in the project tsconfig. Known boundaries: `${configDir}` in non-overridden
25
+ * base-config options resolves to the temporary host directory, `preserveSymlinks`
26
+ * exposes symlinked type paths separately from imported modules, and an ambient
27
+ * `node_modules` above `input.work` remains reachable after the mirrored chain.
20
28
  */
21
29
  export declare function emitClientDeclarations(input: ClientDeclarationsInput): Promise<void>;
22
30
  /** What the declarations of a package may name besides their own files. */
@@ -1 +1 @@
1
- {"version":3,"file":"client-declarations.d.ts","sourceRoot":"","sources":["../../src/files/client-declarations.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAiB,MAAM,gBAAgB,CAAC;AAQ7F,sDAAsD;AACtD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,EAAE,iBAAiB,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6C1F;AAQD,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;CACrC;AAOD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,GAC1B,IAAI,CAgCN"}
1
+ {"version":3,"file":"client-declarations.d.ts","sourceRoot":"","sources":["../../src/files/client-declarations.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAiB,MAAM,gBAAgB,CAAC;AAQ7F,sDAAsD;AACtD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,EAAE,iBAAiB,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,4FAA4F;IAC5F,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;CAChB;AA6CD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+C1F;AAQD,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;CACrC;AAOD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,GAC1B,IAAI,CAgCN"}
@@ -1 +1 @@
1
- {"version":3,"file":"client-package.d.ts","sourceRoot":"","sources":["../../src/files/client-package.ts"],"names":[],"mappings":"AA8BA,OAAO,EAEL,KAAK,aAAa,EAGlB,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AAwNnC;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,aAAa,CAAC,CAkGxB"}
1
+ {"version":3,"file":"client-package.d.ts","sourceRoot":"","sources":["../../src/files/client-package.ts"],"names":[],"mappings":"AA8BA,OAAO,EAEL,KAAK,aAAa,EAGlB,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AAwNnC;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,aAAa,CAAC,CAmGxB"}
@@ -0,0 +1,21 @@
1
+ // src/tools/agent-tool-error.ts
2
+ var AGENT_TOOL_ERROR_BRAND = Symbol.for("stitchkit.AgentToolError");
3
+
4
+ class AgentToolError2 extends Error {
5
+ output;
6
+ constructor(output, cause) {
7
+ let message = "Tool execution failed";
8
+ try {
9
+ message = JSON.stringify(output);
10
+ } catch {}
11
+ super(message, cause === undefined ? undefined : { cause });
12
+ this.name = "AgentToolError";
13
+ this.output = output;
14
+ Object.defineProperty(this, AGENT_TOOL_ERROR_BRAND, { value: true });
15
+ }
16
+ }
17
+ function isAgentToolError2(value) {
18
+ return typeof value === "object" && value !== null && AGENT_TOOL_ERROR_BRAND in value;
19
+ }
20
+
21
+ export { AgentToolError2, isAgentToolError2 };
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  AgentTimestampSchema2
3
- } from "./index-j3r7r1mh.js";
3
+ } from "./index-yv7d6tav.js";
4
4
  import {
5
5
  AgentMessagePartSchema2
6
- } from "./index-tav72wz5.js";
6
+ } from "./index-ks4rhtcc.js";
7
7
  import {
8
8
  AgentSnapshotSchema2
9
- } from "./index-pd9e8rz4.js";
9
+ } from "./index-gvv7y0s4.js";
10
10
  import {
11
11
  isDurableAgentRuntimeEvent,
12
12
  AgentRuntimeEventSchema2
13
- } from "./index-1en7k3q5.js";
13
+ } from "./index-4q9tmzea.js";
14
14
 
15
15
  // src/agent-runtime/browser/control-schema.ts
16
16
  import { z as z2 } from "zod";
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  AgentMessageSchema2
3
- } from "./index-j3r7r1mh.js";
3
+ } from "./index-yv7d6tav.js";
4
4
  import {
5
5
  AgentRunSchema2
6
- } from "./index-pd9e8rz4.js";
6
+ } from "./index-gvv7y0s4.js";
7
7
  import {
8
8
  missing,
9
9
  nextEventSeqByMaximum,
10
10
  agentSqlTables,
11
11
  createAgentRuntimeStore2
12
- } from "./index-rg08syp1.js";
12
+ } from "./index-d5mhgx72.js";
13
13
  import {
14
14
  canonicalAgentJson2
15
- } from "./index-qcy8et93.js";
15
+ } from "./index-kaq9nb7h.js";
16
16
  import {
17
17
  createCompanionHost,
18
18
  conversationTables,
@@ -24,7 +24,7 @@ import {
24
24
  scanSqlRecoverable,
25
25
  listSqlConversations,
26
26
  pageSqlConversationMessages
27
- } from "./index-hberxns4.js";
27
+ } from "./index-zagc12j1.js";
28
28
  import {
29
29
  rollbackSqliteFailure
30
30
  } from "./index-ttexdtjj.js";
@@ -2,7 +2,7 @@ import {
2
2
  sanitizeSurrogates,
3
3
  AgentProviderError2,
4
4
  AgentProviderStreamCutError2
5
- } from "./index-vse7x1qt.js";
5
+ } from "./index-knqye3gv.js";
6
6
  import {
7
7
  isSecretKeyName,
8
8
  maskSecretShapes
@@ -4,17 +4,17 @@ import {
4
4
  AgentTimestampSchema2,
5
5
  AgentMessageSchema2,
6
6
  AgentAssistantPlaceholderSchema2
7
- } from "./index-j3r7r1mh.js";
7
+ } from "./index-yv7d6tav.js";
8
8
  import {
9
9
  AgentProviderEnvelopeSchema2
10
- } from "./index-tav72wz5.js";
10
+ } from "./index-ks4rhtcc.js";
11
11
  import {
12
12
  AgentRunStateSchema2,
13
13
  AgentRunOperationSchema2,
14
14
  AgentTerminalReasonSchema2,
15
15
  AgentRunSchema2,
16
16
  AgentRunMetricsSchema2
17
- } from "./index-pd9e8rz4.js";
17
+ } from "./index-gvv7y0s4.js";
18
18
 
19
19
  // src/agent-runtime/event-schema.ts
20
20
  import { z } from "zod";