stitchkit 0.127.0 → 0.128.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.
Files changed (233) hide show
  1. package/CHANGELOG.md +137 -6
  2. package/dist/agent-executor/acp/v1-connect.d.ts +9 -1
  3. package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
  4. package/dist/agent-executor/acp/v1-driver.d.ts +8 -2
  5. package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
  6. package/dist/agent-executor/acp/v1-map.d.ts.map +1 -1
  7. package/dist/agent-executor/acp/v1-session.d.ts +8 -0
  8. package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
  9. package/dist/agent-executor/claude/cli-driver.d.ts +4 -0
  10. package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
  11. package/dist/agent-executor/claude/protocol.d.ts +20 -2
  12. package/dist/agent-executor/claude/protocol.d.ts.map +1 -1
  13. package/dist/agent-executor/claude/session.d.ts +2 -1
  14. package/dist/agent-executor/claude/session.d.ts.map +1 -1
  15. package/dist/agent-executor/claude/transcript.d.ts +7 -4
  16. package/dist/agent-executor/claude/transcript.d.ts.map +1 -1
  17. package/dist/agent-executor/claude-sdk/driver.d.ts +4 -0
  18. package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
  19. package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
  20. package/dist/agent-executor/codex/driver.d.ts +4 -0
  21. package/dist/agent-executor/codex/driver.d.ts.map +1 -1
  22. package/dist/agent-executor/codex/protocol.d.ts +26 -2
  23. package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
  24. package/dist/agent-executor/codex/session.d.ts +3 -1
  25. package/dist/agent-executor/codex/session.d.ts.map +1 -1
  26. package/dist/agent-executor/image-input.d.ts +71 -0
  27. package/dist/agent-executor/image-input.d.ts.map +1 -0
  28. package/dist/agent-executor/session-primitives.d.ts +0 -3
  29. package/dist/agent-executor/session-primitives.d.ts.map +1 -1
  30. package/dist/agent-runtime/agent-tool.d.ts +21 -7
  31. package/dist/agent-runtime/agent-tool.d.ts.map +1 -1
  32. package/dist/agent-runtime/branch-contract.d.ts +1 -0
  33. package/dist/agent-runtime/branch-contract.d.ts.map +1 -1
  34. package/dist/agent-runtime/branch-identities.d.ts +5 -2
  35. package/dist/agent-runtime/branch-identities.d.ts.map +1 -1
  36. package/dist/agent-runtime/branch-messages.d.ts +9 -9
  37. package/dist/agent-runtime/branch-messages.d.ts.map +1 -1
  38. package/dist/agent-runtime/branch-observations.d.ts +45 -32
  39. package/dist/agent-runtime/branch-observations.d.ts.map +1 -1
  40. package/dist/agent-runtime/branch-provider.d.ts +12 -6
  41. package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
  42. package/dist/agent-runtime/branch-source.d.ts +13 -1
  43. package/dist/agent-runtime/branch-source.d.ts.map +1 -1
  44. package/dist/agent-runtime/child-tools.d.ts +64 -0
  45. package/dist/agent-runtime/child-tools.d.ts.map +1 -1
  46. package/dist/agent-runtime/event-search-tools.d.ts +82 -5
  47. package/dist/agent-runtime/event-search-tools.d.ts.map +1 -1
  48. package/dist/agent-runtime/invocation-attempt.d.ts +1 -1
  49. package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -1
  50. package/dist/agent-runtime/invocation-payload.d.ts +12 -0
  51. package/dist/agent-runtime/invocation-payload.d.ts.map +1 -1
  52. package/dist/agent-runtime/invocation-read.d.ts +6 -3
  53. package/dist/agent-runtime/invocation-read.d.ts.map +1 -1
  54. package/dist/agent-runtime/invocation-schema.d.ts +50 -8
  55. package/dist/agent-runtime/invocation-schema.d.ts.map +1 -1
  56. package/dist/agent-runtime/invocations.d.ts +20 -9
  57. package/dist/agent-runtime/invocations.d.ts.map +1 -1
  58. package/dist/agent-runtime/postgres.d.ts.map +1 -1
  59. package/dist/agent-runtime/schedule-tools.d.ts +30 -0
  60. package/dist/agent-runtime/schedule-tools.d.ts.map +1 -1
  61. package/dist/agent-runtime/schemas-invocation-payload.d.ts +48 -0
  62. package/dist/agent-runtime/schemas-invocation-payload.d.ts.map +1 -0
  63. package/dist/agent-runtime/sql-events.d.ts.map +1 -1
  64. package/dist/agent-runtime/sql-session.d.ts +11 -0
  65. package/dist/agent-runtime/sql-session.d.ts.map +1 -1
  66. package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -1
  67. package/dist/agent-runtime/state-tools.d.ts +55 -0
  68. package/dist/agent-runtime/state-tools.d.ts.map +1 -1
  69. package/dist/agent-runtime/store-branch.d.ts.map +1 -1
  70. package/dist/agent-runtime/store-conformance-lifecycle.d.ts +20 -20
  71. package/dist/agent-runtime/store-conformance-support.d.ts +10 -10
  72. package/dist/agent-runtime/store-create.d.ts.map +1 -1
  73. package/dist/agent-runtime/store-driver-contract.d.ts +12 -0
  74. package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
  75. package/dist/agent-runtime/store-memory-events.d.ts.map +1 -1
  76. package/dist/agent-runtime/store.d.ts +7 -0
  77. package/dist/agent-runtime/store.d.ts.map +1 -1
  78. package/dist/declaration/declaration.d.ts +6 -3
  79. package/dist/declaration/declaration.d.ts.map +1 -1
  80. package/dist/entrypoints/agent-executor/acp.d.ts +1 -1
  81. package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
  82. package/dist/entrypoints/agent-executor/acp.js +23 -12
  83. package/dist/entrypoints/agent-executor/claude-sdk.js +26 -10
  84. package/dist/entrypoints/agent-executor/claude.js +35 -16
  85. package/dist/entrypoints/agent-executor/codex.js +81 -21
  86. package/dist/entrypoints/agent-executor.js +1 -1
  87. package/dist/entrypoints/agent-runtime/harness.js +5 -6
  88. package/dist/entrypoints/agent-runtime/openrouter.js +2 -2
  89. package/dist/entrypoints/agent-runtime/postgres.js +8 -3
  90. package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
  91. package/dist/entrypoints/agent-runtime/sqlite/bun.js +4 -4
  92. package/dist/entrypoints/agent-runtime/sqlite/node.js +4 -4
  93. package/dist/entrypoints/agent-runtime/testing.js +6 -6
  94. package/dist/entrypoints/agent-runtime.d.ts +9 -7
  95. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  96. package/dist/entrypoints/agent-runtime.js +246 -199
  97. package/dist/entrypoints/application/diagnostic-journal.js +4 -4
  98. package/dist/entrypoints/application/directory-inbox.js +8 -8
  99. package/dist/entrypoints/cli/publish.js +8 -8
  100. package/dist/entrypoints/cli.js +10 -9
  101. package/dist/entrypoints/declaration.js +0 -1
  102. package/dist/entrypoints/files.js +40 -17
  103. package/dist/entrypoints/node.js +4 -4
  104. package/dist/entrypoints/observability.js +1 -1
  105. package/dist/entrypoints/process.js +1 -1
  106. package/dist/entrypoints/server.js +7 -7
  107. package/dist/entrypoints/service-host/macos.js +4 -4
  108. package/dist/entrypoints/service-host.d.ts +4 -1
  109. package/dist/entrypoints/service-host.d.ts.map +1 -1
  110. package/dist/entrypoints/service-host.js +831 -220
  111. package/dist/entrypoints/spend.js +1 -1
  112. package/dist/entrypoints/telegram.js +4 -4
  113. package/dist/entrypoints/tools/agent.js +4 -3
  114. package/dist/entrypoints/tools/invoker.js +3 -2
  115. package/dist/entrypoints/tools/mcp.js +4 -3
  116. package/dist/entrypoints/tools/toolkit.js +6 -5
  117. package/dist/entrypoints/tools.d.ts +1 -1
  118. package/dist/entrypoints/tools.d.ts.map +1 -1
  119. package/dist/entrypoints/tools.js +10 -8
  120. package/dist/files/directory-appearance.d.ts +20 -9
  121. package/dist/files/directory-appearance.d.ts.map +1 -1
  122. package/dist/files/polled-json.d.ts.map +1 -1
  123. package/dist/files/regular-file.d.ts +15 -5
  124. package/dist/files/regular-file.d.ts.map +1 -1
  125. package/dist/{index-z4k0hqp9.js → index-0gqs8ght.js} +106 -24
  126. package/dist/{index-caywx1c0.js → index-13dnv6d0.js} +107 -10
  127. package/dist/{index-a725ayvz.js → index-1qwrczr1.js} +1 -1
  128. package/dist/{index-xtkw9866.js → index-2c5w2d1d.js} +1 -1
  129. package/dist/{index-g1q7fwn9.js → index-2nwvn7m2.js} +1 -1
  130. package/dist/{index-4s2w4g37.js → index-3tnwtz38.js} +80 -2
  131. package/dist/{index-5e0zsbf7.js → index-4j8efqr3.js} +1 -1
  132. package/dist/{index-p1m9djt6.js → index-5v5vg85s.js} +1 -1
  133. package/dist/{index-x90w78yz.js → index-673drwkn.js} +23 -8
  134. package/dist/{index-7xp05h20.js → index-6wp4dn9d.js} +6 -6
  135. package/dist/{index-0hdm5sx6.js → index-8x22nprv.js} +6 -2
  136. package/dist/{index-j13gzgdv.js → index-bz3gn6cs.js} +8 -4
  137. package/dist/{index-d96c1n1q.js → index-c5gp2gh6.js} +20 -19
  138. package/dist/{index-wbnpa8z6.js → index-d54npte7.js} +4 -4
  139. package/dist/{index-kmbpej2y.js → index-emgrmavr.js} +102 -61
  140. package/dist/{index-bbzvrq66.js → index-g3e57qj6.js} +455 -202
  141. package/dist/index-gf92hc87.js +100 -0
  142. package/dist/{index-3djgv3ch.js → index-gzny6zsw.js} +25 -10
  143. package/dist/{index-3b31z0pc.js → index-hj1zq7mh.js} +12 -6
  144. package/dist/{index-8xr2eq99.js → index-jfecdk1e.js} +3 -3
  145. package/dist/{index-dvd1qdwa.js → index-ke02kxsr.js} +3 -3
  146. package/dist/{index-83n766x4.js → index-m18xm96h.js} +15 -9
  147. package/dist/{index-qnzhmk2s.js → index-n7f89hjw.js} +90 -47
  148. package/dist/{index-3agqmmrg.js → index-pn5b11ce.js} +7 -9
  149. package/dist/{index-3gwp8ez6.js → index-pwskmywy.js} +12 -17
  150. package/dist/{index-9wh98cpa.js → index-rxnyygke.js} +130 -90
  151. package/dist/{index-0djnptn8.js → index-rzeezh79.js} +10 -3
  152. package/dist/{index-nbv44x0x.js → index-s2e3h616.js} +137 -36
  153. package/dist/{index-5zwac8ft.js → index-t7wa7k12.js} +2 -2
  154. package/dist/{index-xypxnzhp.js → index-v1mxss62.js} +2 -2
  155. package/dist/index-vgzhw2zk.js +304 -0
  156. package/dist/{index-jrka9029.js → index-vmbxj75t.js} +2 -2
  157. package/dist/{index-j516jaaz.js → index-waa6t4zx.js} +49 -2
  158. package/dist/{index-fcw255hd.js → index-xv9jb84s.js} +2 -2
  159. package/dist/{index-dwa6pskj.js → index-y065r8g5.js} +82 -43
  160. package/dist/internal/bounded-file-confirm.d.ts +32 -0
  161. package/dist/internal/bounded-file-confirm.d.ts.map +1 -0
  162. package/dist/internal/bounded-file-read.d.ts +10 -7
  163. package/dist/internal/bounded-file-read.d.ts.map +1 -1
  164. package/dist/internal/file-observation.d.ts +5 -1
  165. package/dist/internal/file-observation.d.ts.map +1 -1
  166. package/dist/internal/process-instance.d.ts +8 -0
  167. package/dist/internal/process-instance.d.ts.map +1 -1
  168. package/dist/internal/unix-socket.d.ts +3 -1
  169. package/dist/internal/unix-socket.d.ts.map +1 -1
  170. package/dist/server/unix-client.d.ts +7 -0
  171. package/dist/server/unix-client.d.ts.map +1 -1
  172. package/dist/service-host/systemd-inspect.d.ts +3 -1
  173. package/dist/service-host/systemd-inspect.d.ts.map +1 -1
  174. package/dist/service-host/systemd-render-shared.d.ts +64 -0
  175. package/dist/service-host/systemd-render-shared.d.ts.map +1 -0
  176. package/dist/service-host/systemd-render.d.ts +31 -26
  177. package/dist/service-host/systemd-render.d.ts.map +1 -1
  178. package/dist/service-host/systemd-timer-render.d.ts +31 -0
  179. package/dist/service-host/systemd-timer-render.d.ts.map +1 -0
  180. package/dist/service-host/systemd-timer-rollback.d.ts +26 -0
  181. package/dist/service-host/systemd-timer-rollback.d.ts.map +1 -0
  182. package/dist/service-host/systemd-timer.d.ts +82 -0
  183. package/dist/service-host/systemd-timer.d.ts.map +1 -0
  184. package/dist/service-host/systemd-unit-ops.d.ts +26 -0
  185. package/dist/service-host/systemd-unit-ops.d.ts.map +1 -0
  186. package/dist/service-host/systemd.d.ts +1 -1
  187. package/dist/service-host/systemd.d.ts.map +1 -1
  188. package/dist/tools/access.d.ts +30 -1
  189. package/dist/tools/access.d.ts.map +1 -1
  190. package/dist/tools/agent.d.ts +2 -2
  191. package/dist/tools/agent.d.ts.map +1 -1
  192. package/dist/tools/cli/args-scan.d.ts +5 -0
  193. package/dist/tools/cli/args-scan.d.ts.map +1 -1
  194. package/dist/tools/cli/args.d.ts +11 -5
  195. package/dist/tools/cli/args.d.ts.map +1 -1
  196. package/dist/tools/cli/invoke.d.ts +2 -1
  197. package/dist/tools/cli/invoke.d.ts.map +1 -1
  198. package/dist/tools/cli/notices.d.ts.map +1 -1
  199. package/dist/tools/cli/run-managed.d.ts.map +1 -1
  200. package/dist/tools/cli/session.d.ts.map +1 -1
  201. package/dist/tools/execute.d.ts.map +1 -1
  202. package/dist/tools/invoker.d.ts +2 -1
  203. package/dist/tools/invoker.d.ts.map +1 -1
  204. package/dist/tools/list-names.d.ts +2 -3
  205. package/dist/tools/list-names.d.ts.map +1 -1
  206. package/dist/tools/manifest.d.ts +2 -3
  207. package/dist/tools/manifest.d.ts.map +1 -1
  208. package/dist/tools/mcp/mount.d.ts +5 -5
  209. package/dist/tools/mcp/mount.d.ts.map +1 -1
  210. package/dist/tools/mcp/register.d.ts +2 -1
  211. package/dist/tools/mcp/register.d.ts.map +1 -1
  212. package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
  213. package/llms/agent-executor-acp.txt +10 -6
  214. package/llms/agent-executor-claude-sdk.txt +1 -1
  215. package/llms/agent-executor-claude.txt +1 -1
  216. package/llms/agent-executor-codex.txt +1 -1
  217. package/llms/agent-runtime.4.txt +21 -9
  218. package/llms/cli.3.txt +4 -4
  219. package/llms/cli.txt +1 -0
  220. package/llms/declaration.txt +2 -2
  221. package/llms/files.txt +1 -1
  222. package/llms/node.txt +2 -2
  223. package/llms/server.5.txt +2 -2
  224. package/llms/service-host.txt +5 -5
  225. package/llms/stitchkit.txt +81 -77
  226. package/llms/tools.3.txt +3 -2
  227. package/llms/upgrading-0.128.0.txt +147 -0
  228. package/llms/upgrading.txt +1 -0
  229. package/llms-full.txt +272 -113
  230. package/llms.txt +14 -13
  231. package/package.json +1 -1
  232. package/dist/index-ajmtxsky.js +0 -193
  233. package/dist/index-ax3wns1a.js +0 -93
@@ -11,10 +11,10 @@ import {
11
11
  AgentProviderResponseSchema2
12
12
  } from "./index-97rp94ff.js";
13
13
  import {
14
- ModelInvocationTraceSchema2,
15
14
  InvocationPayloadSchema,
15
+ ModelInvocationTraceSchema2,
16
16
  assistantStatus
17
- } from "./index-ajmtxsky.js";
17
+ } from "./index-vgzhw2zk.js";
18
18
  import {
19
19
  agentDurableEventId2
20
20
  } from "./index-paff5y0r.js";
@@ -688,6 +688,19 @@ function invocationJson(value) {
688
688
  function invocationHash(value) {
689
689
  return createHash("sha256").update(serializeCanonicalJson(invocationJson(value))).digest("hex");
690
690
  }
691
+
692
+ class InvocationPayloadTooLargeError2 extends RangeError {
693
+ bytes;
694
+ maxBytes;
695
+ sha256;
696
+ constructor(bytes, maxBytes, sha256) {
697
+ super(`Invocation payload (${bytes} bytes) exceeds maxPayloadBytes (${maxBytes})`);
698
+ this.name = "InvocationPayloadTooLargeError";
699
+ this.bytes = bytes;
700
+ this.maxBytes = maxBytes;
701
+ this.sha256 = sha256;
702
+ }
703
+ }
691
704
  function createInvocationPayloads(store, key, maxBytes) {
692
705
  if (key.byteLength !== 32)
693
706
  throw new TypeError("Invocation payload key must contain 32 bytes");
@@ -696,10 +709,11 @@ function createInvocationPayloads(store, key, maxBytes) {
696
709
  maxBytes,
697
710
  async write(identity, value) {
698
711
  const data = Buffer.from(serializeCanonicalJson(invocationJson(value)));
699
- if (data.byteLength > maxBytes)
700
- throw new RangeError("Invocation payload exceeds maxPayloadBytes");
701
- const artifactId = randomUUID();
702
712
  const sha256 = createHash("sha256").update(data).digest("hex");
713
+ if (data.byteLength > maxBytes) {
714
+ throw new InvocationPayloadTooLargeError2(data.byteLength, maxBytes, sha256);
715
+ }
716
+ const artifactId = randomUUID();
703
717
  const iv = randomBytes(12);
704
718
  const cipher = createCipheriv("aes-256-gcm", encryptionKey, iv);
705
719
  cipher.setAAD(Buffer.from(JSON.stringify([identity.conversationId, identity.invocationId, artifactId])));
@@ -794,7 +808,16 @@ function wrapInvocationModel(writer, selected, step, model = selected.model) {
794
808
  const begin = async (params) => invocationAudit(async () => {
795
809
  const context = { ...writer.identity, step, attemptId: randomUUID2() };
796
810
  const { headers: _headers, abortSignal: _signal, ...payload } = params;
797
- const artifact = await writer.payloads.write(writer.identity, payload);
811
+ let artifact;
812
+ let omittedSha256;
813
+ try {
814
+ artifact = await writer.payloads.write(writer.identity, payload);
815
+ } catch (error) {
816
+ if (!(error instanceof InvocationPayloadTooLargeError2))
817
+ throw error;
818
+ writer.receiptErrors.push(error);
819
+ omittedSha256 = error.sha256;
820
+ }
798
821
  await writer.append({
799
822
  ...writer.identity,
800
823
  type: "provider/request",
@@ -808,8 +831,8 @@ function wrapInvocationModel(writer, selected, step, model = selected.model) {
808
831
  sent: {
809
832
  modelId: model.modelId,
810
833
  provider: model.provider,
811
- payloadSha256: artifact.sha256,
812
- artifactId: artifact.artifactId,
834
+ payloadSha256: artifact ? artifact.sha256 : omittedSha256 ?? "",
835
+ ...artifact ? { artifactId: artifact.artifactId } : { payloadOmitted: "max-payload-bytes" },
813
836
  tools: params.tools?.length ?? 0
814
837
  }
815
838
  });
@@ -825,7 +848,16 @@ function wrapInvocationModel(writer, selected, step, model = selected.model) {
825
848
  writer.receiptErrors.push(error);
826
849
  });
827
850
  const recordResponse = async (context, status, payload, usage, response, providerMetadata) => invocationAudit(async () => {
828
- const artifact = await writer.payloads.write(writer.identity, boundedEvidence(payload, Math.floor(writer.payloads.maxBytes / 2)));
851
+ let artifact;
852
+ let omittedSha256;
853
+ try {
854
+ artifact = await writer.payloads.write(writer.identity, boundedEvidence(payload, Math.floor(writer.payloads.maxBytes / 2)));
855
+ } catch (error) {
856
+ if (!(error instanceof InvocationPayloadTooLargeError2))
857
+ throw error;
858
+ writer.receiptErrors.push(error);
859
+ omittedSha256 = error.sha256;
860
+ }
829
861
  await writer.append({
830
862
  ...writer.identity,
831
863
  type: "provider/response",
@@ -838,8 +870,8 @@ function wrapInvocationModel(writer, selected, step, model = selected.model) {
838
870
  responseId: response?.id ?? null
839
871
  },
840
872
  usage: reportedUsage(selected, usage, providerMetadata),
841
- artifactId: artifact.artifactId,
842
- payloadSha256: artifact.sha256
873
+ ...artifact ? { artifactId: artifact.artifactId } : { payloadOmitted: "max-payload-bytes" },
874
+ payloadSha256: artifact ? artifact.sha256 : omittedSha256 ?? ""
843
875
  });
844
876
  });
845
877
  return wrapLanguageModel({
@@ -879,59 +911,68 @@ function wrapInvocationModel(writer, selected, step, model = selected.model) {
879
911
  });
880
912
  throw markProviderOrigin(error);
881
913
  }
882
- const reader = result.stream.getReader();
883
- let ended = false;
884
- let failed = false;
885
- let response;
886
- const evidence = streamEvidence(Math.floor(writer.payloads.maxBytes / 2));
887
- const end = async (status, value, usage, metadata) => {
888
- if (ended)
889
- return;
890
- ended = true;
891
- await finish(context, status, evidence.payload(value), usage, response, metadata);
892
- };
893
- return {
894
- ...result,
895
- stream: new ReadableStream({
896
- async pull(controller) {
897
- let next;
898
- try {
899
- next = await currentAttempt.run(context, () => reader.read());
900
- } catch (error) {
901
- await end(params.abortSignal?.aborted ? "cancelled" : "failed", { error });
902
- controller.error(markProviderOrigin(error));
903
- return;
904
- }
905
- if (next.done) {
906
- await end("failed", { reason: "stream-ended-without-finish" });
907
- controller.close();
908
- return;
909
- }
910
- const part = next.value;
911
- if (part.type === "response-metadata")
912
- response = part;
913
- if (part.type === "finish") {
914
- await end(failed || part.finishReason.unified === "error" ? "failed" : "succeeded", part, part.usage, part.providerMetadata);
915
- } else {
916
- if (part.type === "error")
917
- failed = true;
918
- evidence.record(part);
919
- }
920
- controller.enqueue(part);
921
- },
922
- async cancel(reason) {
923
- try {
924
- await currentAttempt.run(context, () => reader.cancel(reason));
925
- } finally {
926
- await end("cancelled", { reason: "consumer-cancelled" });
927
- }
928
- }
929
- })
930
- };
914
+ return wrapInvocationStreamResult(result, {
915
+ context,
916
+ abortSignal: params.abortSignal,
917
+ maxEvidenceBytes: Math.floor(writer.payloads.maxBytes / 2),
918
+ finish
919
+ });
931
920
  }
932
921
  }
933
922
  });
934
923
  }
924
+ function wrapInvocationStreamResult(result, options) {
925
+ const { context, abortSignal, maxEvidenceBytes, finish } = options;
926
+ const reader = result.stream.getReader();
927
+ let ended = false;
928
+ let failed = false;
929
+ let response;
930
+ const evidence = streamEvidence(maxEvidenceBytes);
931
+ const end = async (status, value, usage, metadata) => {
932
+ if (ended)
933
+ return;
934
+ ended = true;
935
+ await finish(context, status, evidence.payload(value), usage, response, metadata);
936
+ };
937
+ return {
938
+ ...result,
939
+ stream: new ReadableStream({
940
+ async pull(controller) {
941
+ let next;
942
+ try {
943
+ next = await currentAttempt.run(context, () => reader.read());
944
+ } catch (error) {
945
+ await end(abortSignal?.aborted ? "cancelled" : "failed", { error });
946
+ controller.error(markProviderOrigin(error));
947
+ return;
948
+ }
949
+ if (next.done) {
950
+ await end("failed", { reason: "stream-ended-without-finish" });
951
+ controller.close();
952
+ return;
953
+ }
954
+ const part = next.value;
955
+ if (part.type === "response-metadata")
956
+ response = part;
957
+ if (part.type === "finish") {
958
+ await end(failed || part.finishReason.unified === "error" ? "failed" : "succeeded", part, part.usage, part.providerMetadata);
959
+ } else {
960
+ if (part.type === "error")
961
+ failed = true;
962
+ evidence.record(part);
963
+ }
964
+ controller.enqueue(part);
965
+ },
966
+ async cancel(reason) {
967
+ try {
968
+ await currentAttempt.run(context, () => reader.cancel(reason));
969
+ } finally {
970
+ await end("cancelled", { reason: "consumer-cancelled" });
971
+ }
972
+ }
973
+ })
974
+ };
975
+ }
935
976
  function boundedEvidence(payload, limit) {
936
977
  const serialized = JSON.stringify(invocationJson(payload));
937
978
  const bytes = Buffer.byteLength(serialized);
@@ -1149,4 +1190,4 @@ function validateAgentModelSnapshot2(input, policy) {
1149
1190
  return snapshot;
1150
1191
  }
1151
1192
 
1152
- export { withStoreRetries, AgentRuntimeConflictError2, AgentRunUnsettledError2, appliedSnapshot, terminalOfSnapshot, terminalOfRunView, commitAgentRunTerminal, findRun, jsonValue, providerEnvelope, providerResponseIdentity, appendText, abortTerminalReason, addUsage, mergeModelTotals, statedUsage, unknownUsage, normalizeSdkUsage, createIdleDeadline, adoptSnapshot, transientSequence, runUsage, updateReasoning, checkpoint, DEFAULT_STEP_SPEND_TIMEOUT_MS, AgentStepSpendPhaseSchema2, AgentStepSpendProviderSchema, AgentStepSpendSchema2, normalizeStepUsage, recordStepSpend, InvocationReceiptError, invocationHash, createInvocationPayloads, isOwnInputRefusal, markProviderOrigin, hasProviderOrigin, markProviderStream, currentModelInvocationAttempt2, wrapInvocationModel, AgentModelCapabilitySchema2, AgentModelDescriptorSchema2, AgentModelRegistrySnapshotSchema2, AgentModelPriceSchema2, AgentModelMetricSchema2, AgentModelPopularitySchema2, AgentModelCatalogEntrySchema2, AgentModelCatalogSchema2, AgentModelSelectionSchema2, AgentModelSearchInputSchema2, AgentModelSearchResultSchema2, searchAgentModelCatalog2, createMemoryAgentModelSelectionStore2, defineModelRegistry2, validateAgentModelSnapshot2 };
1193
+ export { withStoreRetries, AgentRuntimeConflictError2, AgentRunUnsettledError2, appliedSnapshot, terminalOfSnapshot, terminalOfRunView, commitAgentRunTerminal, findRun, jsonValue, providerEnvelope, providerResponseIdentity, appendText, abortTerminalReason, addUsage, mergeModelTotals, statedUsage, unknownUsage, normalizeSdkUsage, createIdleDeadline, adoptSnapshot, transientSequence, runUsage, updateReasoning, checkpoint, DEFAULT_STEP_SPEND_TIMEOUT_MS, AgentStepSpendPhaseSchema2, AgentStepSpendProviderSchema, AgentStepSpendSchema2, normalizeStepUsage, recordStepSpend, InvocationReceiptError, invocationHash, InvocationPayloadTooLargeError2, createInvocationPayloads, isOwnInputRefusal, markProviderOrigin, hasProviderOrigin, markProviderStream, currentModelInvocationAttempt2, wrapInvocationModel, AgentModelCapabilitySchema2, AgentModelDescriptorSchema2, AgentModelRegistrySnapshotSchema2, AgentModelPriceSchema2, AgentModelMetricSchema2, AgentModelPopularitySchema2, AgentModelCatalogEntrySchema2, AgentModelCatalogSchema2, AgentModelSelectionSchema2, AgentModelSearchInputSchema2, AgentModelSearchResultSchema2, searchAgentModelCatalog2, createMemoryAgentModelSelectionStore2, defineModelRegistry2, validateAgentModelSnapshot2 };