stitchkit 0.106.1 → 0.108.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 (147) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/README.md +2 -0
  3. package/darwin-native.cjs +17 -4
  4. package/dist/agent-runtime/deferred-tool-types.d.ts +6 -27
  5. package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
  6. package/dist/browser/stream.d.ts +38 -12
  7. package/dist/browser/stream.d.ts.map +1 -1
  8. package/dist/entrypoints/agent-runtime/browser.js +2 -3
  9. package/dist/entrypoints/agent-runtime/coding-tools.js +6 -8
  10. package/dist/entrypoints/agent-runtime/harness.js +7 -11
  11. package/dist/entrypoints/agent-runtime/realtime.js +2 -3
  12. package/dist/entrypoints/agent-runtime/sandbox.js +6 -8
  13. package/dist/entrypoints/agent-runtime.d.ts +2 -1
  14. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  15. package/dist/entrypoints/agent-runtime.js +20 -23
  16. package/dist/entrypoints/application/diagnostic-journal.js +3 -3
  17. package/dist/entrypoints/application/directory-inbox.js +8 -9
  18. package/dist/entrypoints/application/grammy.js +3 -3
  19. package/dist/entrypoints/application.js +7 -8
  20. package/dist/entrypoints/bin/upgrade-cli.d.ts +32 -0
  21. package/dist/entrypoints/bin/upgrade-cli.d.ts.map +1 -1
  22. package/dist/entrypoints/bin/upgrade-cli.js +451 -8
  23. package/dist/entrypoints/cli/publish.js +10 -11
  24. package/dist/entrypoints/cli.js +12 -16
  25. package/dist/entrypoints/contract.js +1 -1
  26. package/dist/entrypoints/files/packaging.d.ts +3 -1
  27. package/dist/entrypoints/files/packaging.d.ts.map +1 -1
  28. package/dist/entrypoints/files/packaging.js +171 -55
  29. package/dist/entrypoints/files.js +16 -16
  30. package/dist/entrypoints/index.d.ts +1 -1
  31. package/dist/entrypoints/index.d.ts.map +1 -1
  32. package/dist/entrypoints/index.js +47 -41
  33. package/dist/entrypoints/node.js +27 -29
  34. package/dist/entrypoints/observability.js +10 -12
  35. package/dist/entrypoints/process.js +2 -2
  36. package/dist/entrypoints/react.js +3 -4
  37. package/dist/entrypoints/remote.js +8 -9
  38. package/dist/entrypoints/server.js +48 -51
  39. package/dist/entrypoints/telegram/html.js +3 -3
  40. package/dist/entrypoints/telegram/screens.js +6 -6
  41. package/dist/entrypoints/telegram.d.ts +2 -0
  42. package/dist/entrypoints/telegram.d.ts.map +1 -1
  43. package/dist/entrypoints/telegram.js +344 -11
  44. package/dist/entrypoints/testing.d.ts +1 -0
  45. package/dist/entrypoints/testing.d.ts.map +1 -1
  46. package/dist/entrypoints/testing.js +138 -11
  47. package/dist/entrypoints/tools/connections.js +11 -11
  48. package/dist/entrypoints/tools/invoker.js +5 -9
  49. package/dist/entrypoints/tools/mcp.js +8 -14
  50. package/dist/entrypoints/tools.js +19 -25
  51. package/dist/entrypoints/tracking.js +3 -3
  52. package/dist/files/native-artifact.d.ts +14 -0
  53. package/dist/files/native-artifact.d.ts.map +1 -0
  54. package/dist/files/native-packaging-layout.d.ts +11 -2
  55. package/dist/files/native-packaging-layout.d.ts.map +1 -1
  56. package/dist/files/native-packaging-plugin.d.ts +53 -0
  57. package/dist/files/native-packaging-plugin.d.ts.map +1 -0
  58. package/dist/files/native-packaging.d.ts +44 -43
  59. package/dist/files/native-packaging.d.ts.map +1 -1
  60. package/dist/{index-v5ee8ath.js → index-1h2zv8rx.js} +10 -40
  61. package/dist/index-2kbysk9s.js +42 -0
  62. package/dist/{index-wbhdzxar.js → index-2s6fpehp.js} +5 -5
  63. package/dist/{index-ksfagmyz.js → index-4qh90tyw.js} +8 -8
  64. package/dist/{index-yvfk3y36.js → index-636mggad.js} +4 -3
  65. package/dist/{index-f199nfq5.js → index-6y9t2fwz.js} +7 -7
  66. package/dist/{index-w8etpm8j.js → index-9j2atjte.js} +1 -1
  67. package/dist/index-a5qr2rj6.js +26 -0
  68. package/dist/{index-azx12jgv.js → index-bh2ht9y5.js} +13 -7
  69. package/dist/{index-pz3y6b6g.js → index-cx2nh595.js} +3 -3
  70. package/dist/{index-2k91mewf.js → index-dm2fv45z.js} +9 -9
  71. package/dist/{index-9bskshe3.js → index-dwf0gymy.js} +10 -10
  72. package/dist/{index-qaqbdm7s.js → index-h7qms8f9.js} +8 -8
  73. package/dist/{index-drs41arz.js → index-ktjmgq9p.js} +1 -1
  74. package/dist/{index-916yh4e2.js → index-mep4sb48.js} +14 -14
  75. package/dist/{index-wdy68sh6.js → index-njs9gvrh.js} +17 -17
  76. package/dist/{index-1ptj98e0.js → index-nx49x0tw.js} +2 -2
  77. package/dist/{index-1pwwan01.js → index-p5kx5vqd.js} +214 -59
  78. package/dist/{index-sj28htvf.js → index-pvh3z03x.js} +1 -1
  79. package/dist/{index-r393tnfp.js → index-q6crhe1n.js} +4 -4
  80. package/dist/{index-dsnjzb62.js → index-t2bsd0hm.js} +1 -1
  81. package/dist/{index-4vsby8n8.js → index-w9mqgnz9.js} +1 -1
  82. package/dist/{index-z23rfxhj.js → index-xmgjtkvr.js} +1 -1
  83. package/dist/{index-e05cjgtf.js → index-xvj9h8yh.js} +28 -1
  84. package/dist/{index-gr5g3xfw.js → index-yz8x0hbx.js} +1 -1
  85. package/dist/{index-gxm9rc97.js → index-zrtrjkbf.js} +1 -1
  86. package/dist/internal/bounded-lines.d.ts +46 -2
  87. package/dist/internal/bounded-lines.d.ts.map +1 -1
  88. package/dist/internal/darwin-binding-error.d.ts +9 -1
  89. package/dist/internal/darwin-binding-error.d.ts.map +1 -1
  90. package/dist/internal/darwin-binding.d.ts.map +1 -1
  91. package/dist/internal/process-identity.d.ts.map +1 -1
  92. package/dist/internal/until-aborted.d.ts +9 -0
  93. package/dist/internal/until-aborted.d.ts.map +1 -0
  94. package/dist/internal/upgrade-affects.d.ts +58 -0
  95. package/dist/internal/upgrade-affects.d.ts.map +1 -0
  96. package/dist/internal/upgrade-plan.d.ts +20 -0
  97. package/dist/internal/upgrade-plan.d.ts.map +1 -1
  98. package/dist/internal/upgrade-usage.d.ts +61 -0
  99. package/dist/internal/upgrade-usage.d.ts.map +1 -0
  100. package/dist/telegram/bot-api.d.ts +10 -4
  101. package/dist/telegram/bot-api.d.ts.map +1 -1
  102. package/dist/telegram/broadcast.d.ts +2 -1
  103. package/dist/telegram/broadcast.d.ts.map +1 -1
  104. package/dist/telegram/not-dispatched.d.ts +26 -0
  105. package/dist/telegram/not-dispatched.d.ts.map +1 -0
  106. package/dist/telegram/operator-channel.d.ts +2 -1
  107. package/dist/telegram/operator-channel.d.ts.map +1 -1
  108. package/dist/telegram/send-failure.d.ts +4 -3
  109. package/dist/telegram/send-failure.d.ts.map +1 -1
  110. package/dist/telegram/transport-connect.d.ts +38 -0
  111. package/dist/telegram/transport-connect.d.ts.map +1 -0
  112. package/dist/telegram/transport.d.ts +43 -0
  113. package/dist/telegram/transport.d.ts.map +1 -0
  114. package/dist/telegram/webhook.d.ts +2 -1
  115. package/dist/telegram/webhook.d.ts.map +1 -1
  116. package/dist/testing/manual-clock.d.ts +82 -0
  117. package/dist/testing/manual-clock.d.ts.map +1 -0
  118. package/dist/tools/internal/surface-projector.d.ts +0 -7
  119. package/dist/tools/internal/surface-projector.d.ts.map +1 -1
  120. package/dist/tools/runtime-tool-declaration.d.ts +11 -0
  121. package/dist/tools/runtime-tool-declaration.d.ts.map +1 -1
  122. package/dist/tools/runtime-tool.d.ts +2 -3
  123. package/dist/tools/runtime-tool.d.ts.map +1 -1
  124. package/llms/files-packaging.txt +13 -6
  125. package/llms/process.txt +71 -15
  126. package/llms/stitchkit.2.txt +211 -628
  127. package/llms/stitchkit.txt +635 -10
  128. package/llms/telegram.txt +36 -3
  129. package/llms/testing.txt +47 -0
  130. package/llms/{upgrading-0.96.0-0.106.0.txt → upgrading-0.100.0-0.108.0.txt} +112 -144
  131. package/llms/{upgrading-0.37.0-0.53.0.txt → upgrading-0.37.0-0.58.0.txt} +209 -3
  132. package/llms/{upgrading-0.55.0-0.68.0.txt → upgrading-0.59.0-0.71.0.txt} +149 -209
  133. package/llms/{upgrading-0.69.0-0.95.0.txt → upgrading-0.72.0-0.99.0.txt} +137 -149
  134. package/llms/upgrading.txt +36 -4
  135. package/llms-full.txt +360 -39
  136. package/llms.txt +10 -10
  137. package/package.json +2 -1
  138. package/llms/stitchkit.3.txt +0 -177
  139. package/dist/{index-cazts87s.js → index-07dcf2yn.js} +3 -3
  140. package/dist/{index-n1nszyk0.js → index-7jvwrjqa.js} +3 -3
  141. package/dist/{index-cmzvhhtd.js → index-85qve8mq.js} +3 -3
  142. package/dist/{index-rpzewktb.js → index-fynr93w4.js} +3 -3
  143. package/dist/{index-37asdw3a.js → index-k7qdkh3n.js} +3 -3
  144. package/dist/{index-x7w1z6pf.js → index-q4hjtyye.js} +4 -4
  145. package/dist/{index-7n68nmc6.js → index-y3nemndz.js} +3 -3
  146. package/dist/{index-12zsej7b.js → index-y70v24cw.js} +3 -3
  147. package/dist/{index-pzb63z66.js → index-ykdcnq1f.js} +3 -3
@@ -1,12 +1,6 @@
1
1
  import {
2
2
  toJsonSchema
3
3
  } from "./index-ct75c3at.js";
4
- import {
5
- AppError2
6
- } from "./index-j9gxbztg.js";
7
- import {
8
- resolvePropagationContext2
9
- } from "./index-yex7eg1v.js";
10
4
  import {
11
5
  toolSurfaceOutputSchema,
12
6
  staticInputRounds,
@@ -14,23 +8,20 @@ import {
14
8
  validateResolvedInputRounds,
15
9
  presentationMetadata,
16
10
  prepareProjectedMcpTools
17
- } from "./index-r393tnfp.js";
11
+ } from "./index-q6crhe1n.js";
18
12
  import {
19
13
  parseToolCallArguments,
20
14
  toolResultFromError,
21
15
  observed
22
- } from "./index-2k91mewf.js";
16
+ } from "./index-dm2fv45z.js";
23
17
  import {
24
18
  collectTools2,
25
19
  createToolRunner,
26
20
  formatToolError
27
- } from "./index-wbhdzxar.js";
28
- import {
29
- redact2
30
- } from "./index-e6c2spsd.js";
21
+ } from "./index-2s6fpehp.js";
31
22
  import {
32
23
  collectToolSurface
33
- } from "./index-pz3y6b6g.js";
24
+ } from "./index-cx2nh595.js";
34
25
  import {
35
26
  DEFAULT_CORS_ALLOW_HEADERS2,
36
27
  DEFAULT_PROCESS_SIGNALS,
@@ -38,17 +29,26 @@ import {
38
29
  reportSignalError,
39
30
  guardSignalCallback
40
31
  } from "./index-yk4g8805.js";
32
+ import {
33
+ redact2
34
+ } from "./index-e6c2spsd.js";
41
35
  import {
42
36
  argumentsDigest
43
37
  } from "./index-r7a7r7ha.js";
44
38
  import {
45
39
  runWithRequestContext2,
46
40
  getRequestContext2
47
- } from "./index-7n68nmc6.js";
41
+ } from "./index-y3nemndz.js";
42
+ import {
43
+ AppError2
44
+ } from "./index-j9gxbztg.js";
48
45
  import {
49
46
  compareCodeUnits,
50
47
  serializeCanonicalJson
51
48
  } from "./index-zsvzhjtk.js";
49
+ import {
50
+ resolvePropagationContext2
51
+ } from "./index-yex7eg1v.js";
52
52
  import {
53
53
  isRecord
54
54
  } from "./index-9jfdm5tg.js";
@@ -1,23 +1,9 @@
1
- import {
2
- AppError2,
3
- badRequest2,
4
- forbidden2
5
- } from "./index-j9gxbztg.js";
6
- import {
7
- isStreamCancellation,
8
- ownHttpStream,
9
- settleStreamCleanup,
10
- ShutdownOptionsSchema2
11
- } from "./index-q0th8q0z.js";
12
1
  import {
13
2
  errorCode2,
14
3
  recordedErrorMessage,
15
4
  normalizeError2,
16
5
  validateDeclaredOutput
17
- } from "./index-rpzewktb.js";
18
- import {
19
- resolveTraceContext2
20
- } from "./index-yex7eg1v.js";
6
+ } from "./index-fynr93w4.js";
21
7
  import {
22
8
  DEFAULT_CONTRACT_STREAM_FRAME_BYTES2
23
9
  } from "./index-h2fhjqy7.js";
@@ -25,6 +11,12 @@ import {
25
11
  joinRoutePath,
26
12
  parseTrailingWildcard
27
13
  } from "./index-m38ej7e5.js";
14
+ import {
15
+ isStreamCancellation,
16
+ ownHttpStream,
17
+ settleStreamCleanup,
18
+ ShutdownOptionsSchema2
19
+ } from "./index-q0th8q0z.js";
28
20
  import {
29
21
  RELEASE_HEADER2
30
22
  } from "./index-n15jny5b.js";
@@ -34,7 +26,7 @@ import {
34
26
  import {
35
27
  bindContract,
36
28
  mediaTypeEssence
37
- } from "./index-cmzvhhtd.js";
29
+ } from "./index-85qve8mq.js";
38
30
  import {
39
31
  assertPositiveSafeInteger
40
32
  } from "./index-0s4xebbg.js";
@@ -54,7 +46,7 @@ import {
54
46
  getRequestContext2,
55
47
  setRequestEndpoint2,
56
48
  setRequestError2
57
- } from "./index-7n68nmc6.js";
49
+ } from "./index-y3nemndz.js";
58
50
  import {
59
51
  resolveTraceId2,
60
52
  resolveSocketIp2,
@@ -62,6 +54,14 @@ import {
62
54
  getClientInfo2,
63
55
  parseQueryParams
64
56
  } from "./index-kw1ws0cs.js";
57
+ import {
58
+ AppError2,
59
+ badRequest2,
60
+ forbidden2
61
+ } from "./index-j9gxbztg.js";
62
+ import {
63
+ resolveTraceContext2
64
+ } from "./index-yex7eg1v.js";
65
65
  import {
66
66
  isUnsafeKey,
67
67
  safeJsonParse
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  withExclusiveLock2
3
- } from "./index-4vsby8n8.js";
3
+ } from "./index-w9mqgnz9.js";
4
4
  import {
5
5
  readBoundedFile
6
6
  } from "./index-m616f0yz.js";
7
7
  import {
8
8
  writeAtomicFileData
9
- } from "./index-cazts87s.js";
9
+ } from "./index-07dcf2yn.js";
10
10
  import {
11
11
  publishAtomicFile
12
12
  } from "./index-b56nnscm.js";
@@ -1,7 +1,3 @@
1
- import {
2
- ApiError2,
3
- refuseLocally
4
- } from "./index-kfjkb396.js";
5
1
  import {
6
2
  parseTrailingWildcard
7
3
  } from "./index-m38ej7e5.js";
@@ -17,10 +13,18 @@ import {
17
13
  uploadProgressRoute,
18
14
  withUploadProgress,
19
15
  parseApiErrorBody
20
- } from "./index-n1nszyk0.js";
16
+ } from "./index-7jvwrjqa.js";
17
+ import {
18
+ abortReason,
19
+ untilAborted
20
+ } from "./index-a5qr2rj6.js";
21
21
  import {
22
22
  inputIsQuery
23
23
  } from "./index-xhzq2qvj.js";
24
+ import {
25
+ ApiError2,
26
+ refuseLocally
27
+ } from "./index-kfjkb396.js";
24
28
  import {
25
29
  assertPositiveSafeInteger
26
30
  } from "./index-0s4xebbg.js";
@@ -32,108 +36,259 @@ import {
32
36
 
33
37
  // src/internal/bounded-lines.ts
34
38
  var DEFAULT_STREAM_LINE_BYTES = 1024 * 1024;
39
+
40
+ class StreamLineLimitError2 extends RangeError {
41
+ limitBytes;
42
+ lineBytes;
43
+ name = "StreamLineLimitError";
44
+ constructor(limitBytes, lineBytes) {
45
+ super(`Stream line exceeds the ${limitBytes} byte limit (${lineBytes} bytes so far)`);
46
+ this.limitBytes = limitBytes;
47
+ this.lineBytes = lineBytes;
48
+ }
49
+ }
50
+
51
+ class StreamTruncatedLineError2 extends SyntaxError {
52
+ lineBytes;
53
+ name = "StreamTruncatedLineError";
54
+ constructor(lineBytes) {
55
+ super(`Stream ended with an unterminated final line (${lineBytes} bytes)`);
56
+ this.lineBytes = lineBytes;
57
+ }
58
+ }
35
59
  function lineLimit(value) {
36
60
  const resolved = value ?? DEFAULT_STREAM_LINE_BYTES;
37
61
  assertPositiveSafeInteger("maxLineBytes", resolved);
38
62
  return resolved;
39
63
  }
40
- function joinBytes(left, right) {
41
- if (left.byteLength === 0)
42
- return right.slice();
43
- const result = new Uint8Array(left.byteLength + right.byteLength);
44
- result.set(left);
45
- result.set(right, left.byteLength);
46
- return result;
47
- }
48
- async function* readBoundedUtf8Lines(response, maxLineBytes, requireFinalNewline = false) {
49
- const reader = response.body?.getReader();
50
- if (!reader)
51
- return;
64
+ function createLineSplitter(maxLineBytes, requireFinalNewline = false) {
52
65
  const limit = lineLimit(maxLineBytes);
53
66
  const decoder = new TextDecoder("utf-8", { fatal: true });
54
- let pending = new Uint8Array;
55
- try {
56
- for (;; ) {
57
- const chunk = await reader.read();
58
- if (chunk.done)
59
- break;
67
+ let parts = [];
68
+ let pendingBytes = 0;
69
+ let ended = false;
70
+ let failed = false;
71
+ const drop = () => {
72
+ parts = [];
73
+ pendingBytes = 0;
74
+ };
75
+ const retain = (bytes) => {
76
+ if (bytes.byteLength === 0)
77
+ return;
78
+ pendingBytes += bytes.byteLength;
79
+ if (pendingBytes > limit) {
80
+ const seen = pendingBytes;
81
+ drop();
82
+ throw new StreamLineLimitError2(limit, seen);
83
+ }
84
+ parts.push(new Uint8Array(bytes));
85
+ };
86
+ const take = () => {
87
+ const line = new Uint8Array(pendingBytes);
88
+ let at = 0;
89
+ for (const part of parts) {
90
+ line.set(part, at);
91
+ at += part.byteLength;
92
+ }
93
+ drop();
94
+ return decoder.decode(line);
95
+ };
96
+ function* lines(chunk) {
97
+ if (ended)
98
+ throw new Error("Line decoder received bytes after end()");
99
+ if (failed)
100
+ throw new Error("Line decoder stopped at an earlier error; read the source again");
101
+ try {
60
102
  let start = 0;
61
- for (let index = 0;index < chunk.value.byteLength; index += 1) {
62
- if (chunk.value[index] !== 10)
63
- continue;
64
- const lineBytes = joinBytes(pending, chunk.value.slice(start, index));
65
- if (lineBytes.byteLength > limit) {
66
- throw new RangeError(`Stream line exceeds the ${limit} byte limit`);
67
- }
68
- yield decoder.decode(lineBytes);
69
- pending = new Uint8Array;
103
+ for (let index = chunk.indexOf(10);index !== -1; index = chunk.indexOf(10, start)) {
104
+ retain(chunk.subarray(start, index));
105
+ yield take();
70
106
  start = index + 1;
71
107
  }
72
- pending = joinBytes(pending, chunk.value.slice(start));
73
- if (pending.byteLength > limit) {
74
- throw new RangeError(`Stream line exceeds the ${limit} byte limit`);
75
- }
108
+ retain(chunk.subarray(start));
109
+ } catch (error) {
110
+ failed = true;
111
+ throw error;
76
112
  }
77
- if (pending.byteLength > 0) {
113
+ }
114
+ return {
115
+ lines,
116
+ push: (chunk) => [...lines(chunk)],
117
+ end() {
118
+ ended = true;
119
+ if (pendingBytes === 0)
120
+ return [];
78
121
  if (requireFinalNewline) {
79
- throw new SyntaxError("Stream ended with an unterminated final line");
122
+ const seen = pendingBytes;
123
+ drop();
124
+ throw new StreamTruncatedLineError2(seen);
125
+ }
126
+ return [take()];
127
+ }
128
+ };
129
+ }
130
+ function createBoundedLineDecoder(maxLineBytes, requireFinalNewline = false) {
131
+ const { push, end } = createLineSplitter(maxLineBytes, requireFinalNewline);
132
+ return { push, end };
133
+ }
134
+ async function* chunksOf(source, signal) {
135
+ signal?.throwIfAborted();
136
+ const stream = source instanceof Response ? source.body : source;
137
+ if (stream === null)
138
+ return;
139
+ if (stream instanceof ReadableStream) {
140
+ const reader = stream.getReader();
141
+ const abort = () => {
142
+ if (signal)
143
+ reader.cancel(abortReason(signal)).catch(() => {
144
+ return;
145
+ });
146
+ };
147
+ signal?.addEventListener("abort", abort, { once: true });
148
+ try {
149
+ for (;; ) {
150
+ const chunk = await reader.read();
151
+ signal?.throwIfAborted();
152
+ if (chunk.done)
153
+ return;
154
+ yield chunk.value;
80
155
  }
81
- yield decoder.decode(pending);
156
+ } finally {
157
+ signal?.removeEventListener("abort", abort);
158
+ await reader.cancel().catch(() => {
159
+ return;
160
+ });
161
+ reader.releaseLock();
162
+ }
163
+ }
164
+ const iterator = stream[Symbol.asyncIterator]();
165
+ let finished = false;
166
+ try {
167
+ for (;; ) {
168
+ const pending = iterator.next();
169
+ const next = await (signal ? untilAborted(pending, signal) : pending);
170
+ if (next.done) {
171
+ finished = true;
172
+ return;
173
+ }
174
+ yield next.value;
82
175
  }
83
176
  } finally {
84
- await reader.cancel().catch(() => {
85
- return;
86
- });
87
- reader.releaseLock();
177
+ if (!finished && signal?.aborted)
178
+ iterator.return?.().catch(() => {
179
+ return;
180
+ });
181
+ else if (!finished)
182
+ await iterator.return?.().catch(() => {
183
+ return;
184
+ });
185
+ }
186
+ }
187
+ async function* readBoundedUtf8Lines(source, maxLineBytes, requireFinalNewline = false, signal) {
188
+ const splitter = createLineSplitter(maxLineBytes, requireFinalNewline);
189
+ for await (const chunk of chunksOf(source, signal)) {
190
+ for (const line of splitter.lines(chunk)) {
191
+ signal?.throwIfAborted();
192
+ yield line;
193
+ }
194
+ }
195
+ for (const line of splitter.end()) {
196
+ signal?.throwIfAborted();
197
+ yield line;
88
198
  }
89
199
  }
90
200
 
91
201
  // src/browser/stream.ts
202
+ function ndjsonLine(rawLine) {
203
+ return (rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine).trim();
204
+ }
92
205
  function parseFailure(raw, error, onParseError) {
93
206
  const failure = error instanceof Error ? error : new Error(String(error));
94
207
  if (!onParseError)
95
208
  throw failure;
96
209
  onParseError(raw, failure);
97
210
  }
98
- async function* parseNDJSON2(response, options) {
211
+ async function* parseNDJSON2(source, options) {
212
+ let reporting = false;
99
213
  try {
100
- for await (const rawLine of readBoundedUtf8Lines(response, options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES, options?.finalLine === "require-newline")) {
101
- const line = (rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine).trim();
214
+ for await (const rawLine of readBoundedUtf8Lines(source, options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES, options?.finalLine === "require-newline", options?.signal)) {
215
+ const line = ndjsonLine(rawLine);
102
216
  if (line === "")
103
217
  continue;
218
+ let value;
104
219
  try {
105
- yield JSON.parse(line);
220
+ value = JSON.parse(line);
106
221
  } catch (error) {
222
+ reporting = true;
107
223
  parseFailure(line, error, options?.onParseError);
224
+ reporting = false;
225
+ continue;
108
226
  }
227
+ yield value;
109
228
  }
110
229
  } catch (error) {
230
+ if (reporting || options?.signal?.aborted)
231
+ throw error;
111
232
  parseFailure("", error, options?.onParseError);
112
233
  }
113
234
  }
114
- async function* parseSSE2(response, options) {
235
+ function createNDJSONDecoder2(options) {
236
+ const lines = createBoundedLineDecoder(options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES, options?.finalLine === "require-newline");
237
+ let failed = false;
238
+ const values = (rawLines) => {
239
+ const parsed = [];
240
+ for (const rawLine of rawLines) {
241
+ const line = ndjsonLine(rawLine);
242
+ if (line === "")
243
+ continue;
244
+ try {
245
+ parsed.push(JSON.parse(line));
246
+ } catch (error) {
247
+ parseFailure(line, error, options?.onParseError);
248
+ }
249
+ }
250
+ return parsed;
251
+ };
252
+ const guarded = (step) => {
253
+ if (failed)
254
+ throw new Error("NDJSON decoder stopped at an earlier error; read the source again");
255
+ try {
256
+ return values(step());
257
+ } catch (error) {
258
+ failed = true;
259
+ throw error;
260
+ }
261
+ };
262
+ return {
263
+ push: (chunk) => guarded(() => lines.push(chunk)),
264
+ end: () => guarded(() => lines.end())
265
+ };
266
+ }
267
+ async function* parseSSE2(source, options) {
268
+ let reporting = false;
115
269
  try {
116
- for await (const rawLine of readBoundedUtf8Lines(response, options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES)) {
270
+ for await (const rawLine of readBoundedUtf8Lines(source, options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES, false, options?.signal)) {
117
271
  const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
118
272
  if (!line.startsWith("data:"))
119
273
  continue;
120
274
  const data = line.slice(5).replace(/^ /, "");
121
275
  if (data === "[DONE]")
122
276
  return;
277
+ let value;
123
278
  try {
124
- yield JSON.parse(data);
279
+ value = JSON.parse(data);
125
280
  } catch (error) {
126
- const failure = error instanceof Error ? error : new Error(String(error));
127
- if (!options?.onParseError)
128
- throw failure;
129
- options.onParseError(data, failure);
281
+ reporting = true;
282
+ parseFailure(data, error, options?.onParseError);
283
+ reporting = false;
284
+ continue;
130
285
  }
286
+ yield value;
131
287
  }
132
288
  } catch (error) {
133
- const failure = error instanceof Error ? error : new Error(String(error));
134
- if (!options?.onParseError)
135
- throw failure;
136
- options.onParseError("", failure);
289
+ if (reporting || options?.signal?.aborted)
290
+ throw error;
291
+ parseFailure("", error, options?.onParseError);
137
292
  }
138
293
  }
139
294
 
@@ -797,4 +952,4 @@ function createScopedUrlBuilders2(contracts, source, scopeConfigs) {
797
952
  return buildScopedRegistry(contracts, scopeConfigs, "URL builder", (contract, config) => createUrlBuilder2(contract, source, config));
798
953
  }
799
954
 
800
- export { endpointHasArguments, parseNDJSON2, parseSSE2, contractEndpointMatchers2, createClient2, createClients2, createScopedClients2, createUrlBuilder2, createUrlBuilders2, createScopedUrlBuilders2 };
955
+ export { endpointHasArguments, StreamLineLimitError2, StreamTruncatedLineError2, parseNDJSON2, createNDJSONDecoder2, parseSSE2, contractEndpointMatchers2, createClient2, createClients2, createScopedClients2, createUrlBuilder2, createUrlBuilders2, createScopedUrlBuilders2 };
@@ -2,7 +2,7 @@ import {
2
2
  parseRealtimeRequestArguments,
3
3
  parseRealtimeRequestAcknowledgement,
4
4
  createValidatedRealtimeSocket
5
- } from "./index-pzb63z66.js";
5
+ } from "./index-ykdcnq1f.js";
6
6
  import {
7
7
  randomHex
8
8
  } from "./index-c9d05kvt.js";
@@ -1,12 +1,12 @@
1
- import {
2
- AppError2
3
- } from "./index-j9gxbztg.js";
4
1
  import {
5
2
  validateDeclaredOutput
6
- } from "./index-rpzewktb.js";
3
+ } from "./index-fynr93w4.js";
7
4
  import {
8
5
  toJsonSchema
9
6
  } from "./index-ct75c3at.js";
7
+ import {
8
+ AppError2
9
+ } from "./index-j9gxbztg.js";
10
10
  import {
11
11
  serializeCanonicalJson
12
12
  } from "./index-zsvzhjtk.js";
@@ -3,7 +3,7 @@ import {
3
3
  ProcessInstanceSchema2,
4
4
  readProcessInstance,
5
5
  probeProcessOwner2
6
- } from "./index-azx12jgv.js";
6
+ } from "./index-bh2ht9y5.js";
7
7
  import {
8
8
  BoundedFileReadError,
9
9
  readBoundedFile
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  attemptExclusiveLock
3
- } from "./index-dsnjzb62.js";
3
+ } from "./index-t2bsd0hm.js";
4
4
  import {
5
5
  sleep
6
6
  } from "./index-eemvahkc.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createValidatedRealtimeSocket
3
- } from "./index-pzb63z66.js";
3
+ } from "./index-ykdcnq1f.js";
4
4
 
5
5
  // src/server/realtime.ts
6
6
  function bindRealtimeServer2(contract, handle, options = {}) {
@@ -2,6 +2,30 @@ import {
2
2
  isRecord
3
3
  } from "./index-9jfdm5tg.js";
4
4
 
5
+ // src/telegram/not-dispatched.ts
6
+ class TelegramNotDispatchedError2 extends Error {
7
+ stage;
8
+ name = "TelegramNotDispatchedError";
9
+ code = "TELEGRAM_NOT_DISPATCHED";
10
+ constructor(stage, message, options) {
11
+ super(message, options);
12
+ this.stage = stage;
13
+ }
14
+ }
15
+ function isTelegramNotDispatchedError(error) {
16
+ return error instanceof TelegramNotDispatchedError2 || error instanceof Error && error.name === "TelegramNotDispatchedError" && Reflect.get(error, "code") === "TELEGRAM_NOT_DISPATCHED";
17
+ }
18
+ function isTelegramNotDispatched(error, depth = 0) {
19
+ if (error instanceof TelegramNotDispatchedError2)
20
+ return true;
21
+ if (typeof error !== "object" || error === null || depth > 4)
22
+ return false;
23
+ if (Reflect.get(error, "code") === "TELEGRAM_NOT_DISPATCHED")
24
+ return true;
25
+ const nested = Reflect.get(error, "cause") ?? Reflect.get(error, "error");
26
+ return nested !== error && isTelegramNotDispatched(nested, depth + 1);
27
+ }
28
+
5
29
  // src/telegram/send-failure.ts
6
30
  var BY_DESCRIPTION = [
7
31
  [/bot was blocked by the user|bot was kicked/i, "blocked-by-user"],
@@ -22,6 +46,7 @@ var TRAITS = {
22
46
  "rate-limited": { retryable: true, recipientUnreachable: false },
23
47
  "message-invalid": { retryable: false, recipientUnreachable: false },
24
48
  "server-error": { retryable: true, recipientUnreachable: false },
49
+ "not-dispatched": { retryable: true, recipientUnreachable: false },
25
50
  unknown: { retryable: false, recipientUnreachable: false }
26
51
  };
27
52
  function isSendFailureReason(value) {
@@ -71,6 +96,8 @@ function descriptionOf(value, depth = 0) {
71
96
  return [own, message, nested].filter(Boolean).join(" ");
72
97
  }
73
98
  function classifyTelegramSendFailure2(error) {
99
+ if (isTelegramNotDispatched(error))
100
+ return { reason: "not-dispatched", ...TRAITS["not-dispatched"], evidence: "transport" };
74
101
  const status = statusOf(error);
75
102
  const retryAfterSeconds = retryAfterOf(error);
76
103
  const description = descriptionOf(error);
@@ -141,4 +168,4 @@ function classifyTelegramEditRefusal(error) {
141
168
  return "other";
142
169
  }
143
170
 
144
- export { TELEGRAM_SEND_FAILURE_REASONS2, classifyTelegramSendFailure2, classifyTelegramEditRefusal };
171
+ export { TelegramNotDispatchedError2, isTelegramNotDispatchedError, TELEGRAM_SEND_FAILURE_REASONS2, classifyTelegramSendFailure2, classifyTelegramEditRefusal };
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  ToolExecutionControlError2,
16
16
  isToolExecutionControlError2
17
- } from "./index-2k91mewf.js";
17
+ } from "./index-dm2fv45z.js";
18
18
  import {
19
19
  agentDurableEventId2
20
20
  } from "./index-mnkk1ffz.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  loadDarwinBinding
3
- } from "./index-v5ee8ath.js";
3
+ } from "./index-2kbysk9s.js";
4
4
 
5
5
  // src/agent-runtime/contained-scan.ts
6
6
  import path2 from "node:path";
@@ -1,4 +1,48 @@
1
1
  export declare const DEFAULT_STREAM_LINE_BYTES: number;
2
- /** Bounded, fatal-UTF-8 line reader shared by NDJSON and SSE parsers. */
3
- export declare function readBoundedUtf8Lines(response: Response, maxLineBytes?: number, requireFinalNewline?: boolean): AsyncGenerator<string>;
2
+ /**
3
+ * A line grew past its byte limit. The reader throws as soon as the retained bytes cross the
4
+ * limit, so memory stays bounded by the limit plus the chunk being read.
5
+ */
6
+ export declare class StreamLineLimitError extends RangeError {
7
+ /** The configured `maxLineBytes`. */
8
+ readonly limitBytes: number;
9
+ /** Bytes of the line seen when it crossed the limit; the line itself is longer still. */
10
+ readonly lineBytes: number;
11
+ readonly name = "StreamLineLimitError";
12
+ constructor(
13
+ /** The configured `maxLineBytes`. */
14
+ limitBytes: number,
15
+ /** Bytes of the line seen when it crossed the limit; the line itself is longer still. */
16
+ lineBytes: number);
17
+ }
18
+ /** The source ended inside a line while `finalLine: 'require-newline'` asked for a delimiter. */
19
+ export declare class StreamTruncatedLineError extends SyntaxError {
20
+ /** Bytes of the unterminated final line. */
21
+ readonly lineBytes: number;
22
+ readonly name = "StreamTruncatedLineError";
23
+ constructor(
24
+ /** Bytes of the unterminated final line. */
25
+ lineBytes: number);
26
+ }
27
+ /** Bytes a line reader accepts: a `Response` body, a web stream, or any async byte iterable. */
28
+ export type StreamByteSource = Response | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
29
+ /**
30
+ * Push-driven bounded line splitter for sources that deliver bytes through a callback, such as
31
+ * a `Bun.listen`/`Bun.connect` socket's `data` handler. Lines are split on `\n` in bytes and
32
+ * decoded as fatal UTF-8 only once complete, so a character split across chunks is never torn.
33
+ * An error (a line past the limit, invalid UTF-8) fails the whole `push` and stops the decoder:
34
+ * the bytes after it belong to the failed line, so every later `push` throws.
35
+ */
36
+ export interface BoundedLineDecoder {
37
+ /** Feed one chunk; returns the lines it completed, without their `\n`. */
38
+ push(chunk: Uint8Array): string[];
39
+ /**
40
+ * The source ended. Returns the unterminated final line, if any, as one more line, or throws
41
+ * `StreamTruncatedLineError` when a final newline is required.
42
+ */
43
+ end(): string[];
44
+ }
45
+ export declare function createBoundedLineDecoder(maxLineBytes?: number, requireFinalNewline?: boolean): BoundedLineDecoder;
46
+ /** Bounded, fatal-UTF-8 line reader shared by the NDJSON and SSE parsers. */
47
+ export declare function readBoundedUtf8Lines(source: StreamByteSource, maxLineBytes?: number, requireFinalNewline?: boolean, signal?: AbortSignal): AsyncGenerator<string>;
4
48
  //# sourceMappingURL=bounded-lines.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bounded-lines.d.ts","sourceRoot":"","sources":["../../src/internal/bounded-lines.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,yBAAyB,QAAc,CAAC;AAgBrD,yEAAyE;AACzE,wBAAuB,oBAAoB,CACzC,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,EACrB,mBAAmB,UAAQ,GAC1B,cAAc,CAAC,MAAM,CAAC,CAqCxB"}
1
+ {"version":3,"file":"bounded-lines.d.ts","sourceRoot":"","sources":["../../src/internal/bounded-lines.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,yBAAyB,QAAc,CAAC;AAErD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;IAGhD,qCAAqC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,MAAM;IAL5B,SAAkB,IAAI,0BAA0B;IAChD;IACE,qCAAqC;IAC5B,UAAU,EAAE,MAAM;IAC3B,yFAAyF;IAChF,SAAS,EAAE,MAAM,EAG3B;CACF;AAED,iGAAiG;AACjG,qBAAa,wBAAyB,SAAQ,WAAW;IAGrD,4CAA4C;IAC5C,QAAQ,CAAC,SAAS,EAAE,MAAM;IAH5B,SAAkB,IAAI,8BAA8B;IACpD;IACE,4CAA4C;IACnC,SAAS,EAAE,MAAM,EAG3B;CACF;AAED,gGAAgG;AAChG,MAAM,MAAM,gBAAgB,GACxB,QAAQ,GACR,cAAc,CAAC,UAAU,CAAC,GAC1B,aAAa,CAAC,UAAU,CAAC,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,CAAC;IAClC;;;OAGG;IACH,GAAG,IAAI,MAAM,EAAE,CAAC;CACjB;AAiFD,wBAAgB,wBAAwB,CACtC,YAAY,CAAC,EAAE,MAAM,EACrB,mBAAmB,UAAQ,GAC1B,kBAAkB,CAGpB;AAkDD,6EAA6E;AAC7E,wBAAuB,oBAAoB,CACzC,MAAM,EAAE,gBAAgB,EACxB,YAAY,CAAC,EAAE,MAAM,EACrB,mBAAmB,UAAQ,EAC3B,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,MAAM,CAAC,CAcxB"}