stitchkit 0.122.2 → 0.123.1

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 (202) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/browser/client.d.ts.map +1 -1
  3. package/dist/browser/contract-identity.d.ts +21 -0
  4. package/dist/browser/contract-identity.d.ts.map +1 -0
  5. package/dist/browser/unknown-operation.d.ts +3 -0
  6. package/dist/browser/unknown-operation.d.ts.map +1 -0
  7. package/dist/contract/define.d.ts +6 -2
  8. package/dist/contract/define.d.ts.map +1 -1
  9. package/dist/contract/endpoint-capabilities.d.ts.map +1 -1
  10. package/dist/contract/errors.d.ts +4 -0
  11. package/dist/contract/errors.d.ts.map +1 -1
  12. package/dist/contract/fingerprint.d.ts +51 -0
  13. package/dist/contract/fingerprint.d.ts.map +1 -0
  14. package/dist/contract/identity.d.ts +21 -0
  15. package/dist/contract/identity.d.ts.map +1 -0
  16. package/dist/contract/stream.d.ts +32 -0
  17. package/dist/contract/stream.d.ts.map +1 -1
  18. package/dist/entrypoints/agent-runtime/browser.js +2 -2
  19. package/dist/entrypoints/agent-runtime/coding-tools.js +11 -11
  20. package/dist/entrypoints/agent-runtime/harness.js +12 -12
  21. package/dist/entrypoints/agent-runtime/openrouter.js +1 -1
  22. package/dist/entrypoints/agent-runtime/realtime.js +2 -2
  23. package/dist/entrypoints/agent-runtime/sandbox.js +11 -11
  24. package/dist/entrypoints/agent-runtime/sqlite/bun.js +15 -15
  25. package/dist/entrypoints/agent-runtime/sqlite/node.js +15 -15
  26. package/dist/entrypoints/agent-runtime/testing.js +15 -15
  27. package/dist/entrypoints/agent-runtime.js +22 -22
  28. package/dist/entrypoints/application/diagnostic-journal.js +5 -5
  29. package/dist/entrypoints/application/directory-inbox.js +5 -5
  30. package/dist/entrypoints/application/grammy.js +1 -1
  31. package/dist/entrypoints/application.js +7 -7
  32. package/dist/entrypoints/cli/publish.js +5 -5
  33. package/dist/entrypoints/cli.d.ts +1 -1
  34. package/dist/entrypoints/cli.d.ts.map +1 -1
  35. package/dist/entrypoints/cli.js +20 -17
  36. package/dist/entrypoints/contract.d.ts +2 -0
  37. package/dist/entrypoints/contract.d.ts.map +1 -1
  38. package/dist/entrypoints/contract.js +11 -5
  39. package/dist/entrypoints/files/packaging.d.ts +1 -0
  40. package/dist/entrypoints/files/packaging.d.ts.map +1 -1
  41. package/dist/entrypoints/files/packaging.js +230 -61
  42. package/dist/entrypoints/files.js +5 -5
  43. package/dist/entrypoints/geo.js +3 -3
  44. package/dist/entrypoints/http.js +3 -3
  45. package/dist/entrypoints/index.d.ts +1 -0
  46. package/dist/entrypoints/index.d.ts.map +1 -1
  47. package/dist/entrypoints/index.js +45 -24
  48. package/dist/entrypoints/live.js +2 -2
  49. package/dist/entrypoints/node.js +11 -11
  50. package/dist/entrypoints/observability.js +4 -4
  51. package/dist/entrypoints/primitives.js +1 -1
  52. package/dist/entrypoints/process/owner-loss.js +2 -2
  53. package/dist/entrypoints/process.d.ts +6 -1
  54. package/dist/entrypoints/process.d.ts.map +1 -1
  55. package/dist/entrypoints/process.js +370 -9
  56. package/dist/entrypoints/react.js +2 -2
  57. package/dist/entrypoints/realtime.js +3 -3
  58. package/dist/entrypoints/remote.js +20 -10
  59. package/dist/entrypoints/server.d.ts +1 -0
  60. package/dist/entrypoints/server.d.ts.map +1 -1
  61. package/dist/entrypoints/server.js +56 -20
  62. package/dist/entrypoints/telegram/screens.js +4 -4
  63. package/dist/entrypoints/telegram.js +6 -6
  64. package/dist/entrypoints/testing.js +10 -10
  65. package/dist/entrypoints/tools/agent.js +9 -9
  66. package/dist/entrypoints/tools/connections.js +7 -7
  67. package/dist/entrypoints/tools/contract.js +1 -1
  68. package/dist/entrypoints/tools/invoker.js +7 -7
  69. package/dist/entrypoints/tools/mcp.js +9 -9
  70. package/dist/entrypoints/tools/toolkit.js +15 -14
  71. package/dist/entrypoints/tools.js +17 -17
  72. package/dist/entrypoints/tracking/contract.js +2 -2
  73. package/dist/entrypoints/tracking.js +1 -1
  74. package/dist/files/client-artifact.d.ts +75 -0
  75. package/dist/files/client-artifact.d.ts.map +1 -0
  76. package/dist/{index-am1h8c9v.js → index-0d3sm0m9.js} +5 -5
  77. package/dist/{index-72xtvcvr.js → index-0ndz5r8z.js} +1 -1
  78. package/dist/index-0v9xb8pz.js +66 -0
  79. package/dist/{index-qcn84byh.js → index-0w0hxp7n.js} +4 -0
  80. package/dist/{index-3za04re9.js → index-1c945ten.js} +1 -1
  81. package/dist/{index-r6v4mc67.js → index-1d7s7da0.js} +1 -1
  82. package/dist/{index-zsvzhjtk.js → index-20hn8pbh.js} +1 -1
  83. package/dist/{index-f6pw75e1.js → index-2x2ch0bt.js} +2 -2
  84. package/dist/{index-61hve0ez.js → index-303qne11.js} +1 -1
  85. package/dist/{index-g149e9pk.js → index-3bzk2645.js} +1 -1
  86. package/dist/index-45dyex0j.js +119 -0
  87. package/dist/{index-aqwg2dm5.js → index-6k47xdtt.js} +2 -2
  88. package/dist/{index-nwm3ww60.js → index-73dappvg.js} +1 -1
  89. package/dist/index-7q05ag0z.js +10 -0
  90. package/dist/{index-kz9734jc.js → index-96yjwwgf.js} +6 -5
  91. package/dist/{index-ff39f9dr.js → index-993vtv1w.js} +3 -3
  92. package/dist/{index-4jpykzvw.js → index-99nnsz39.js} +2 -2
  93. package/dist/{index-pfvde2fz.js → index-9ypczvpj.js} +1 -1
  94. package/dist/{index-qch1vcaa.js → index-a7ebd769.js} +2 -2
  95. package/dist/{index-98hv3sba.js → index-aw6kx2e6.js} +1 -1
  96. package/dist/{index-gq3fnq3f.js → index-bqzgaj57.js} +103 -16
  97. package/dist/{index-yj6saztf.js → index-bz9cmnqq.js} +96 -14
  98. package/dist/{index-gtx3eknx.js → index-chz7c830.js} +13 -9
  99. package/dist/{index-mtwh9hyp.js → index-cjzaj7ev.js} +1 -1
  100. package/dist/{index-6j15ktag.js → index-d9cg0gen.js} +1 -1
  101. package/dist/{index-sa99p98w.js → index-eabx6qjh.js} +3 -3
  102. package/dist/{index-8yxgcyt6.js → index-egg0yp2j.js} +1 -1
  103. package/dist/{index-h1j71dr1.js → index-enkc9pem.js} +1 -1
  104. package/dist/{index-aqmadanx.js → index-fa53vygr.js} +2 -2
  105. package/dist/{index-e6c2spsd.js → index-fpwbskp2.js} +1 -1
  106. package/dist/{index-m8a44e64.js → index-ftk3838x.js} +1 -1
  107. package/dist/{index-j95jp7ee.js → index-gdqawggb.js} +1 -1
  108. package/dist/{index-9dyd8xzf.js → index-hkw233vx.js} +2 -2
  109. package/dist/{index-9jfdm5tg.js → index-hkxgennw.js} +7 -1
  110. package/dist/{index-qaqxdbxf.js → index-j8rda9n6.js} +7 -7
  111. package/dist/{index-4tyt1qya.js → index-jc5xgkpk.js} +2 -2
  112. package/dist/{index-s9a0fjh3.js → index-kffm4r8w.js} +1 -1
  113. package/dist/{index-5w6t91ze.js → index-m8ddk770.js} +1 -1
  114. package/dist/{index-2fc1k9k2.js → index-mdyhr36s.js} +32 -122
  115. package/dist/{index-r7a7r7ha.js → index-mfntvj58.js} +6 -3
  116. package/dist/{index-k42ckyzx.js → index-ndjzbt2v.js} +2 -2
  117. package/dist/{index-ycqhyars.js → index-qc7tq0za.js} +3 -3
  118. package/dist/{index-9frf01t9.js → index-r0xr7y4m.js} +1 -1
  119. package/dist/{index-s3yxw6kt.js → index-s512scra.js} +9 -7
  120. package/dist/{index-1h2zv8rx.js → index-sqc6ezrb.js} +41 -1
  121. package/dist/{index-2bqf0a74.js → index-sqkttz7z.js} +1 -1
  122. package/dist/{index-rbzq0q16.js → index-t8jz0e20.js} +1 -1
  123. package/dist/{index-8ryydawp.js → index-tt3ej8r3.js} +1 -1
  124. package/dist/{index-x4p3kw1p.js → index-tynna0n4.js} +6 -6
  125. package/dist/{index-72r9k0av.js → index-v62cpkx3.js} +1 -1
  126. package/dist/{index-10rg78vf.js → index-v8xm2s9v.js} +2 -2
  127. package/dist/{index-y6ye582c.js → index-w0wy05gr.js} +10 -10
  128. package/dist/{index-kw1ws0cs.js → index-w3nv6kr8.js} +1 -1
  129. package/dist/{index-eeahxwvg.js → index-ww3gss55.js} +1 -1
  130. package/dist/{index-aswegq1r.js → index-xjb131sc.js} +367 -131
  131. package/dist/{index-1fyea34p.js → index-yebkpytc.js} +5 -5
  132. package/dist/{index-bgcwxhxh.js → index-yfpt7sxr.js} +24 -46
  133. package/dist/{index-69t14s4a.js → index-yt1gg11x.js} +3 -2
  134. package/dist/{index-jk29rwkr.js → index-zfncctjp.js} +1 -1
  135. package/dist/internal/bun-command.d.ts +14 -0
  136. package/dist/internal/bun-command.d.ts.map +1 -0
  137. package/dist/internal/exclusive-lock-owner.d.ts +1 -1
  138. package/dist/internal/exclusive-lock-owner.d.ts.map +1 -1
  139. package/dist/internal/exclusive-lock.d.ts +1 -1
  140. package/dist/internal/exclusive-lock.d.ts.map +1 -1
  141. package/dist/internal/process-identity.d.ts +24 -5
  142. package/dist/internal/process-identity.d.ts.map +1 -1
  143. package/dist/internal/stable-digest.d.ts +5 -0
  144. package/dist/internal/stable-digest.d.ts.map +1 -1
  145. package/dist/internal/typed.d.ts +2 -0
  146. package/dist/internal/typed.d.ts.map +1 -1
  147. package/dist/process/operation-child.d.ts +38 -0
  148. package/dist/process/operation-child.d.ts.map +1 -0
  149. package/dist/process/operation-wire.d.ts +68 -0
  150. package/dist/process/operation-wire.d.ts.map +1 -0
  151. package/dist/process/operation.d.ts +74 -0
  152. package/dist/process/operation.d.ts.map +1 -0
  153. package/dist/server/contract-identity.d.ts +10 -0
  154. package/dist/server/contract-identity.d.ts.map +1 -0
  155. package/dist/server/contract-stream.d.ts.map +1 -1
  156. package/dist/server/endpoint-response.d.ts.map +1 -1
  157. package/dist/server/error-hook.d.ts +1 -0
  158. package/dist/server/error-hook.d.ts.map +1 -1
  159. package/dist/tools/cli/args-route.d.ts.map +1 -1
  160. package/dist/tools/cli/args-tokens.d.ts.map +1 -1
  161. package/dist/tools/cli/command.d.ts +39 -18
  162. package/dist/tools/cli/command.d.ts.map +1 -1
  163. package/dist/tools/cli/format.d.ts.map +1 -1
  164. package/dist/tools/cli/help.d.ts.map +1 -1
  165. package/dist/tools/cli/invoke.d.ts +3 -1
  166. package/dist/tools/cli/invoke.d.ts.map +1 -1
  167. package/dist/tools/cli/io.d.ts +6 -0
  168. package/dist/tools/cli/io.d.ts.map +1 -1
  169. package/dist/tools/cli/managed-surface.d.ts +2 -0
  170. package/dist/tools/cli/managed-surface.d.ts.map +1 -1
  171. package/dist/tools/cli/policy.d.ts +14 -0
  172. package/dist/tools/cli/policy.d.ts.map +1 -1
  173. package/dist/tools/cli/run-managed.d.ts.map +1 -1
  174. package/dist/tools/cli/run-native.d.ts.map +1 -1
  175. package/dist/tools/cli/run-stream.d.ts +23 -0
  176. package/dist/tools/cli/run-stream.d.ts.map +1 -0
  177. package/dist/tools/cli/session.d.ts +8 -0
  178. package/dist/tools/cli/session.d.ts.map +1 -1
  179. package/dist/tools/cli/stream-surface.d.ts +17 -0
  180. package/dist/tools/cli/stream-surface.d.ts.map +1 -0
  181. package/dist/tools/execute.d.ts +7 -1
  182. package/dist/tools/execute.d.ts.map +1 -1
  183. package/dist/tools/invoker.d.ts.map +1 -1
  184. package/dist/tools/remote.d.ts.map +1 -1
  185. package/llms/cli.2.txt +56 -1
  186. package/llms/cli.txt +68 -1
  187. package/llms/contract.txt +4 -1
  188. package/llms/files-packaging.txt +10 -0
  189. package/llms/process.2.txt +75 -1
  190. package/llms/process.txt +59 -25
  191. package/llms/server.4.txt +8 -4
  192. package/llms/server.5.txt +1 -0
  193. package/llms/stitchkit.2.txt +74 -0
  194. package/llms/stitchkit.txt +5 -5
  195. package/llms/tools.txt +1 -1
  196. package/llms/{upgrading-0.106.0-0.122.0.txt → upgrading-0.106.0-0.123.0.txt} +50 -3
  197. package/llms/upgrading.txt +1 -1
  198. package/llms-full.txt +379 -13
  199. package/llms.txt +7 -7
  200. package/package.json +1 -1
  201. package/dist/index-h2fhjqy7.js +0 -19
  202. package/dist/index-m5m9rmvt.js +0 -44
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  ToolExecutionControlError2,
16
16
  isToolExecutionControlError2
17
- } from "./index-s3yxw6kt.js";
17
+ } from "./index-s512scra.js";
18
18
  import {
19
19
  AGENT_TOOL_PROGRESS_MESSAGE_MAX2,
20
20
  agentDurableEventId2
@@ -34,10 +34,10 @@ import {
34
34
  ProviderJournalRequestSchema,
35
35
  ProviderJournalResponseSchema,
36
36
  isActiveRunState
37
- } from "./index-8yxgcyt6.js";
37
+ } from "./index-egg0yp2j.js";
38
38
  import {
39
39
  messageOf
40
- } from "./index-g149e9pk.js";
40
+ } from "./index-3bzk2645.js";
41
41
  import {
42
42
  createRuntimeToolContext
43
43
  } from "./index-eh71zr32.js";
@@ -52,11 +52,11 @@ import {
52
52
  } from "./index-0s4xebbg.js";
53
53
  import {
54
54
  serializeCanonicalJson
55
- } from "./index-zsvzhjtk.js";
55
+ } from "./index-20hn8pbh.js";
56
56
  import {
57
57
  isRecord,
58
58
  transportResult
59
- } from "./index-9jfdm5tg.js";
59
+ } from "./index-hkxgennw.js";
60
60
 
61
61
  // src/agent-runtime/runtime-internals.ts
62
62
  import { z } from "zod";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  loadDarwinBinding
3
- } from "./index-m5m9rmvt.js";
3
+ } from "./index-sqc6ezrb.js";
4
4
  import {
5
5
  errnoOf
6
6
  } from "./index-jj9228tt.js";
@@ -0,0 +1,66 @@
1
+ import {
2
+ untilAborted
3
+ } from "./index-a5qr2rj6.js";
4
+ import {
5
+ AppError2
6
+ } from "./index-0w0hxp7n.js";
7
+
8
+ // src/contract/stream.ts
9
+ import { z } from "zod";
10
+ var DEFAULT_CONTRACT_STREAM_FRAME_BYTES2 = 256 * 1024;
11
+ var ContractStreamErrorSchema = z.object({
12
+ code: z.string(),
13
+ message: z.string().optional(),
14
+ details: z.unknown().optional(),
15
+ hint: z.string().optional(),
16
+ retryable: z.boolean().optional()
17
+ }).strict();
18
+ var ContractStreamFrameSchema2 = z.discriminatedUnion("type", [
19
+ z.object({ type: z.literal("data"), data: z.unknown() }).strict(),
20
+ z.object({ type: z.literal("error"), error: ContractStreamErrorSchema }).strict(),
21
+ z.object({ type: z.literal("end") }).strict()
22
+ ]);
23
+ function checkContractStreamItem(descriptor, value) {
24
+ const parsed = descriptor.item.safeParse(value);
25
+ if (!parsed.success) {
26
+ console.error("[stitchkit] contract stream item failed validation:", parsed.error);
27
+ throw new AppError2("STREAM_ITEM_INVALID", {
28
+ message: "Stream item did not match its contract",
29
+ status: 500
30
+ });
31
+ }
32
+ return {
33
+ item: parsed.data,
34
+ terminal: descriptor.terminal?.safeParse(parsed.data).success ?? false
35
+ };
36
+ }
37
+ async function* readContractStreamItems(iterator, descriptor, signal, observe) {
38
+ let terminalSeen = descriptor.terminal === undefined;
39
+ for (;; ) {
40
+ const pending = Promise.resolve(iterator.next());
41
+ observe?.(pending);
42
+ const next = await untilAborted(pending, signal);
43
+ if (next.done)
44
+ break;
45
+ const checked = checkContractStreamItem(descriptor, next.value);
46
+ if (checked.terminal)
47
+ terminalSeen = true;
48
+ yield checked;
49
+ if (checked.terminal && descriptor.completion === "terminal")
50
+ return;
51
+ }
52
+ if (!terminalSeen) {
53
+ throw new AppError2("STREAM_TERMINAL_MISSING", {
54
+ message: "Stream completed before its declared terminal item",
55
+ status: 500
56
+ });
57
+ }
58
+ }
59
+ function contractStreamLifetimeExceeded() {
60
+ return new AppError2("STREAM_LIFETIME_EXCEEDED", {
61
+ message: "Stream exceeded its declared lifetime",
62
+ status: 408
63
+ });
64
+ }
65
+
66
+ export { DEFAULT_CONTRACT_STREAM_FRAME_BYTES2, ContractStreamErrorSchema, ContractStreamFrameSchema2, readContractStreamItems, contractStreamLifetimeExceeded };
@@ -57,6 +57,7 @@ var STITCH_ERROR_STATUS2 = {
57
57
  UNAUTHORIZED: 401,
58
58
  FORBIDDEN: 403,
59
59
  NOT_FOUND: 404,
60
+ UNKNOWN_OPERATION: 404,
60
61
  METHOD_NOT_ALLOWED: 405,
61
62
  CONFLICT: 409,
62
63
  RATE_LIMITED: 429,
@@ -85,6 +86,9 @@ var STITCH_ERROR_STATUS2 = {
85
86
  CONNECTION_REQUEST_FAILED: 502,
86
87
  UPSTREAM_TOOL_ERROR: 502,
87
88
  OPERATION_NOT_SUCCEEDED: 409,
89
+ OPERATION_BUSY: 503,
90
+ OPERATION_RESPONSE_TOO_LARGE: 500,
91
+ OPERATION_PROCESS_FAILED: 500,
88
92
  STREAM_ITEM_INVALID: 500,
89
93
  STREAM_FRAME_TOO_LARGE: 500,
90
94
  STREAM_TERMINAL_MISSING: 500,
@@ -7,7 +7,7 @@ import {
7
7
  } from "./index-1eeqpadm.js";
8
8
  import {
9
9
  AppError2
10
- } from "./index-qcn84byh.js";
10
+ } from "./index-0w0hxp7n.js";
11
11
 
12
12
  // src/realtime/rejected-frame.ts
13
13
  var REALTIME_REJECTION_KEY2 = "@stitchkit/realtime-rejected";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  resolveSocketIp2,
3
3
  getClientInfo2
4
- } from "./index-kw1ws0cs.js";
4
+ } from "./index-w3nv6kr8.js";
5
5
  import {
6
6
  isUnsafeKey
7
7
  } from "./index-zsarb5xp.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isRecord
3
- } from "./index-9jfdm5tg.js";
3
+ } from "./index-hkxgennw.js";
4
4
 
5
5
  // src/internal/canonical-json.ts
6
6
  function compareCodeUnits(left, right) {
@@ -8,7 +8,7 @@ import {
8
8
  AgentSeedReceiptSchema2,
9
9
  AgentHistoryMutationSchema2,
10
10
  isActiveRunState
11
- } from "./index-8yxgcyt6.js";
11
+ } from "./index-egg0yp2j.js";
12
12
  import {
13
13
  AgentRecordIdSchema2,
14
14
  AgentMessageSchema2
@@ -17,7 +17,7 @@ import {
17
17
  replaceMessage,
18
18
  ArchiveSpillSchema,
19
19
  createAgentRuntimeStore2
20
- } from "./index-10rg78vf.js";
20
+ } from "./index-v8xm2s9v.js";
21
21
 
22
22
  // src/agent-runtime/store-memory.ts
23
23
  import { z as z2 } from "zod";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-6j725ez5.js";
4
4
  import {
5
5
  isRecord
6
- } from "./index-9jfdm5tg.js";
6
+ } from "./index-hkxgennw.js";
7
7
 
8
8
  // src/telegram/send-failure.ts
9
9
  var BY_DESCRIPTION = [
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isRecord
3
- } from "./index-9jfdm5tg.js";
3
+ } from "./index-hkxgennw.js";
4
4
 
5
5
  // src/internal/error-message.ts
6
6
  function messageOf(value) {
@@ -0,0 +1,119 @@
1
+ import {
2
+ chunksOf
3
+ } from "./index-cjbn98zt.js";
4
+ import {
5
+ assertPositiveSafeInteger
6
+ } from "./index-0s4xebbg.js";
7
+
8
+ // src/internal/bounded-lines.ts
9
+ var DEFAULT_STREAM_LINE_BYTES = 1024 * 1024;
10
+
11
+ class StreamLineLimitError2 extends RangeError {
12
+ limitBytes;
13
+ lineBytes;
14
+ name = "StreamLineLimitError";
15
+ constructor(limitBytes, lineBytes) {
16
+ super(`Stream line exceeds the ${limitBytes} byte limit (${lineBytes} bytes so far)`);
17
+ this.limitBytes = limitBytes;
18
+ this.lineBytes = lineBytes;
19
+ }
20
+ }
21
+
22
+ class StreamTruncatedLineError2 extends SyntaxError {
23
+ lineBytes;
24
+ name = "StreamTruncatedLineError";
25
+ constructor(lineBytes) {
26
+ super(`Stream ended with an unterminated final line (${lineBytes} bytes)`);
27
+ this.lineBytes = lineBytes;
28
+ }
29
+ }
30
+ function lineLimit(value) {
31
+ const resolved = value ?? DEFAULT_STREAM_LINE_BYTES;
32
+ assertPositiveSafeInteger("maxLineBytes", resolved);
33
+ return resolved;
34
+ }
35
+ function createLineSplitter(maxLineBytes, requireFinalNewline = false) {
36
+ const limit = lineLimit(maxLineBytes);
37
+ const decoder = new TextDecoder("utf-8", { fatal: true });
38
+ let parts = [];
39
+ let pendingBytes = 0;
40
+ let ended = false;
41
+ let failed = false;
42
+ const drop = () => {
43
+ parts = [];
44
+ pendingBytes = 0;
45
+ };
46
+ const retain = (bytes) => {
47
+ if (bytes.byteLength === 0)
48
+ return;
49
+ pendingBytes += bytes.byteLength;
50
+ if (pendingBytes > limit) {
51
+ const seen = pendingBytes;
52
+ drop();
53
+ throw new StreamLineLimitError2(limit, seen);
54
+ }
55
+ parts.push(new Uint8Array(bytes));
56
+ };
57
+ const take = () => {
58
+ const line = new Uint8Array(pendingBytes);
59
+ let at = 0;
60
+ for (const part of parts) {
61
+ line.set(part, at);
62
+ at += part.byteLength;
63
+ }
64
+ drop();
65
+ return decoder.decode(line);
66
+ };
67
+ function* lines(chunk) {
68
+ if (ended)
69
+ throw new Error("Line decoder received bytes after end()");
70
+ if (failed)
71
+ throw new Error("Line decoder stopped at an earlier error; read the source again");
72
+ try {
73
+ let start = 0;
74
+ for (let index = chunk.indexOf(10);index !== -1; index = chunk.indexOf(10, start)) {
75
+ retain(chunk.subarray(start, index));
76
+ yield take();
77
+ start = index + 1;
78
+ }
79
+ retain(chunk.subarray(start));
80
+ } catch (error) {
81
+ failed = true;
82
+ throw error;
83
+ }
84
+ }
85
+ return {
86
+ lines,
87
+ push: (chunk) => [...lines(chunk)],
88
+ end() {
89
+ ended = true;
90
+ if (pendingBytes === 0)
91
+ return [];
92
+ if (requireFinalNewline) {
93
+ const seen = pendingBytes;
94
+ drop();
95
+ throw new StreamTruncatedLineError2(seen);
96
+ }
97
+ return [take()];
98
+ }
99
+ };
100
+ }
101
+ function createBoundedLineDecoder(maxLineBytes, requireFinalNewline = false) {
102
+ const { push, end } = createLineSplitter(maxLineBytes, requireFinalNewline);
103
+ return { push, end };
104
+ }
105
+ async function* readBoundedUtf8Lines(source, maxLineBytes, requireFinalNewline = false, signal) {
106
+ const splitter = createLineSplitter(maxLineBytes, requireFinalNewline);
107
+ for await (const chunk of chunksOf(source, signal)) {
108
+ for (const line of splitter.lines(chunk)) {
109
+ signal?.throwIfAborted();
110
+ yield line;
111
+ }
112
+ }
113
+ for (const line of splitter.end()) {
114
+ signal?.throwIfAborted();
115
+ yield line;
116
+ }
117
+ }
118
+
119
+ export { DEFAULT_STREAM_LINE_BYTES, StreamLineLimitError2, StreamTruncatedLineError2, createBoundedLineDecoder, readBoundedUtf8Lines };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  projectRuntimeTool
3
- } from "./index-x4p3kw1p.js";
3
+ } from "./index-tynna0n4.js";
4
4
  import {
5
5
  isRecord
6
- } from "./index-9jfdm5tg.js";
6
+ } from "./index-hkxgennw.js";
7
7
 
8
8
  // src/tools/runtime-tool.ts
9
9
  function defineRuntimeTool2(definition) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  attemptExclusiveLock
3
- } from "./index-gtx3eknx.js";
3
+ } from "./index-chz7c830.js";
4
4
  import {
5
5
  sleep
6
6
  } from "./index-eemvahkc.js";
@@ -0,0 +1,10 @@
1
+ import {
2
+ startNativeCommand
3
+ } from "./index-gdqawggb.js";
4
+
5
+ // src/process/command.ts
6
+ function runNativeCommand2(input) {
7
+ return startNativeCommand(input).result;
8
+ }
9
+
10
+ export { runNativeCommand2 };
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  assertUniqueToolName
3
- } from "./index-x4p3kw1p.js";
3
+ } from "./index-tynna0n4.js";
4
4
  import {
5
5
  toolErrorFromResult
6
- } from "./index-s3yxw6kt.js";
6
+ } from "./index-s512scra.js";
7
7
  import {
8
8
  collectTools2,
9
9
  createToolRunner
10
- } from "./index-ycqhyars.js";
10
+ } from "./index-qc7tq0za.js";
11
11
  import {
12
12
  AppError2
13
- } from "./index-qcn84byh.js";
13
+ } from "./index-0w0hxp7n.js";
14
14
 
15
15
  // src/tools/invoker.ts
16
16
  function createToolInvoker2(services, config) {
@@ -30,10 +30,11 @@ function createToolInvoker2(services, config) {
30
30
  const tool = tools.get(name);
31
31
  if (tool)
32
32
  return tool;
33
- throw new AppError2("NOT_FOUND", {
33
+ throw new AppError2("UNKNOWN_OPERATION", {
34
34
  message: `Unknown tool: ${name}`,
35
35
  status: 404,
36
36
  details: {
37
+ operation: name,
37
38
  available: names
38
39
  }
39
40
  });
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  projectToolSurface
3
- } from "./index-x4p3kw1p.js";
3
+ } from "./index-tynna0n4.js";
4
4
  import {
5
5
  contractToolMountable
6
- } from "./index-ycqhyars.js";
6
+ } from "./index-qc7tq0za.js";
7
7
  import {
8
8
  runtimeToolMountable
9
- } from "./index-aqwg2dm5.js";
9
+ } from "./index-6k47xdtt.js";
10
10
 
11
11
  // src/tools/surface.ts
12
12
  function collectToolSurface({
@@ -5,7 +5,7 @@ import {
5
5
  TOOL_TRANSPORTS2,
6
6
  isHttpOnlyEndpoint,
7
7
  assertEndpointExposure
8
- } from "./index-69t14s4a.js";
8
+ } from "./index-yt1gg11x.js";
9
9
  import {
10
10
  isUnsafeKey
11
11
  } from "./index-zsarb5xp.js";
@@ -14,7 +14,7 @@ import {
14
14
  } from "./index-0s4xebbg.js";
15
15
  import {
16
16
  isRecord
17
- } from "./index-9jfdm5tg.js";
17
+ } from "./index-hkxgennw.js";
18
18
 
19
19
  // src/contract/define-validation.ts
20
20
  function assertMultipartEndpoint(prefix, key, ep) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  HTTP_ONLY_EXPOSURE,
3
3
  isHttpOnlyEndpoint
4
- } from "./index-69t14s4a.js";
4
+ } from "./index-yt1gg11x.js";
5
5
  import {
6
6
  resolveRouteParamsSchema
7
7
  } from "./index-m38ej7e5.js";
@@ -4,10 +4,10 @@ import {
4
4
  } from "./index-rfkh44ss.js";
5
5
  import {
6
6
  serializeCanonicalJson
7
- } from "./index-zsvzhjtk.js";
7
+ } from "./index-20hn8pbh.js";
8
8
  import {
9
9
  isRecord
10
- } from "./index-9jfdm5tg.js";
10
+ } from "./index-hkxgennw.js";
11
11
 
12
12
  // src/live/watch-contract.ts
13
13
  import { z as z2 } from "zod";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AppError2
3
- } from "./index-qcn84byh.js";
3
+ } from "./index-0w0hxp7n.js";
4
4
 
5
5
  // src/tools/internal/tool-error-projection.ts
6
6
  var TOOL_ERROR_PROJECTION = Symbol.for("stitchkit.toolErrorProjection");
@@ -1,17 +1,48 @@
1
1
  import {
2
2
  loadDarwinBinding
3
- } from "./index-m5m9rmvt.js";
3
+ } from "./index-sqc6ezrb.js";
4
4
  import {
5
5
  errnoOf
6
6
  } from "./index-jj9228tt.js";
7
7
  import {
8
8
  isRecord
9
- } from "./index-9jfdm5tg.js";
9
+ } from "./index-hkxgennw.js";
10
10
 
11
11
  // src/internal/process-identity.ts
12
12
  import { execFile } from "node:child_process";
13
13
  import { readFile } from "node:fs/promises";
14
14
  import { platform } from "node:os";
15
+
16
+ // src/internal/bun-command.ts
17
+ var spawnWithBun = (file, args, maxBuffer) => {
18
+ const child = Bun.spawn([file, ...args], {
19
+ stdin: "ignore",
20
+ stdout: "pipe",
21
+ stderr: "ignore"
22
+ });
23
+ const read = async () => {
24
+ const decoder = new TextDecoder;
25
+ let text = "";
26
+ let bytes = 0;
27
+ for await (const chunk of child.stdout) {
28
+ bytes += chunk.byteLength;
29
+ if (bytes > maxBuffer) {
30
+ child.kill("SIGKILL");
31
+ throw new Error(`${file} wrote more than ${maxBuffer} bytes`);
32
+ }
33
+ text += decoder.decode(chunk, { stream: true });
34
+ }
35
+ text += decoder.decode();
36
+ const exitCode = await child.exited;
37
+ if (exitCode !== 0)
38
+ throw new Error(`${file} ended with ${exitCode}`);
39
+ return text;
40
+ };
41
+ return { stdout: read(), stop: () => child.kill("SIGKILL") };
42
+ };
43
+ var launchWithBun = typeof Bun === "undefined" ? undefined : spawnWithBun;
44
+
45
+ // src/internal/process-identity.ts
15
46
  var detectedIdentity;
16
47
  async function firstReadableLine(paths) {
17
48
  for (const path of paths) {
@@ -23,37 +54,92 @@ async function firstReadableLine(paths) {
23
54
  }
24
55
  return null;
25
56
  }
26
- function run(file, args, options) {
27
- return new Promise((resolve, reject) => {
28
- execFile(file, args, { ...options, encoding: "utf8" }, (error, stdout) => {
57
+ var launchWithNode = (file, args, maxBuffer) => {
58
+ let stop = () => {
59
+ return;
60
+ };
61
+ const stdout = new Promise((resolve, reject) => {
62
+ const child = execFile(file, args, { maxBuffer, encoding: "utf8" }, (error, text) => {
29
63
  if (error)
30
64
  reject(error);
31
65
  else
32
- resolve({ stdout });
66
+ resolve(text);
67
+ });
68
+ stop = () => {
69
+ child.kill("SIGKILL");
70
+ };
71
+ });
72
+ return { stdout, stop: () => stop() };
73
+ };
74
+ function run(file, args, limits) {
75
+ const { timeout, maxBuffer, signal } = limits;
76
+ const launch = limits.launch ?? launchWithBun ?? launchWithNode;
77
+ return new Promise((resolve, reject) => {
78
+ if (signal?.aborted) {
79
+ reject(signal.reason);
80
+ return;
81
+ }
82
+ let command;
83
+ try {
84
+ command = launch(file, args, maxBuffer);
85
+ } catch (error) {
86
+ reject(error);
87
+ return;
88
+ }
89
+ const abandon = (reason) => {
90
+ clearTimeout(timer);
91
+ signal?.removeEventListener("abort", onAbort);
92
+ command.stop();
93
+ reject(reason);
94
+ };
95
+ const onAbort = () => abandon(signal?.reason);
96
+ const timer = setTimeout(() => abandon(new Error(`${file} did not answer within ${timeout} ms`)), timeout);
97
+ signal?.addEventListener("abort", onAbort, { once: true });
98
+ command.stdout.then((text) => {
99
+ clearTimeout(timer);
100
+ signal?.removeEventListener("abort", onAbort);
101
+ resolve(text);
102
+ }, (error) => {
103
+ clearTimeout(timer);
104
+ signal?.removeEventListener("abort", onAbort);
105
+ reject(error);
33
106
  });
34
107
  });
35
108
  }
36
109
  function parsePlatformUuid(dump) {
37
110
  return /"IOPlatformUUID"\s*=\s*"([^"]+)"/.exec(dump)?.[1] ?? null;
38
111
  }
39
- async function readDarwinPlatformUuid(command = "ioreg") {
112
+ async function readDarwinPlatformUuid(command = "ioreg", signal, seam = {}) {
40
113
  try {
41
- const { stdout } = await run(command, ["-rd1", "-c", "IOPlatformExpertDevice"], {
42
- timeout: 2000,
43
- maxBuffer: 1 << 20
114
+ const stdout = await run(command, ["-rd1", "-c", "IOPlatformExpertDevice"], {
115
+ timeout: seam.timeoutMs ?? 2000,
116
+ maxBuffer: 1 << 20,
117
+ ...signal !== undefined && { signal },
118
+ ...seam.launch !== undefined && { launch: seam.launch }
44
119
  });
45
120
  return parsePlatformUuid(stdout);
46
121
  } catch {
47
122
  return null;
48
123
  }
49
124
  }
50
- async function machineIdentity(declared) {
125
+ var identitySource = {
126
+ detect(signal) {
127
+ return platform() === "darwin" ? readDarwinPlatformUuid("ioreg", signal) : firstReadableLine(["/etc/machine-id", "/var/lib/dbus/machine-id"]);
128
+ },
129
+ forget() {
130
+ detectedIdentity = undefined;
131
+ }
132
+ };
133
+ async function machineIdentity(declared, signal) {
51
134
  if (declared !== undefined)
52
135
  return declared;
53
136
  if (detectedIdentity !== undefined)
54
137
  return detectedIdentity;
55
- detectedIdentity = platform() === "darwin" ? await readDarwinPlatformUuid() : await firstReadableLine(["/etc/machine-id", "/var/lib/dbus/machine-id"]);
56
- return detectedIdentity;
138
+ const detected = await identitySource.detect(signal);
139
+ if (signal?.aborted)
140
+ return null;
141
+ detectedIdentity = detected;
142
+ return detected;
57
143
  }
58
144
  async function probeLiveness(pid, reach = (target) => process.kill(target, 0)) {
59
145
  try {
@@ -70,9 +156,10 @@ async function isZombieProcess(pid, seam = {}) {
70
156
  return stat.slice(stat.lastIndexOf(")") + 1).trimStart().startsWith("Z");
71
157
  } catch {}
72
158
  try {
73
- const { stdout } = await run(psCommand, ["-o", "state=", "-p", String(pid)], {
74
- timeout: 2000,
75
- maxBuffer: 1 << 16
159
+ const stdout = await run(psCommand, ["-o", "state=", "-p", String(pid)], {
160
+ timeout: seam.timeoutMs ?? 2000,
161
+ maxBuffer: 1 << 16,
162
+ ...seam.launch !== undefined && { launch: seam.launch }
76
163
  });
77
164
  return stdout.trim().startsWith("Z");
78
165
  } catch {