stitchkit 0.134.0 → 0.134.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 (120) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +6 -6
  3. package/dist/agent-executor/claude/cli-driver.d.ts +6 -0
  4. package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
  5. package/dist/agent-executor/claude/session.d.ts +2 -0
  6. package/dist/agent-executor/claude/session.d.ts.map +1 -1
  7. package/dist/agent-executor/claude-sdk/driver.d.ts +9 -1
  8. package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
  9. package/dist/agent-executor/claude-sdk/engine-spawn.d.ts +18 -5
  10. package/dist/agent-executor/claude-sdk/engine-spawn.d.ts.map +1 -1
  11. package/dist/agent-executor/claude-sdk/probe.d.ts.map +1 -1
  12. package/dist/agent-executor/claude-sdk/query-manager.d.ts.map +1 -1
  13. package/dist/agent-executor/claude-sdk/query-options.d.ts +16 -0
  14. package/dist/agent-executor/claude-sdk/query-options.d.ts.map +1 -1
  15. package/dist/agent-executor/claude-sdk/session.d.ts +1 -0
  16. package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
  17. package/dist/agent-runtime/harness-contract.d.ts +5 -5
  18. package/dist/agent-runtime/harness-contract.d.ts.map +1 -1
  19. package/dist/agent-runtime/runtime.d.ts +13 -13
  20. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  21. package/dist/agent-runtime/sandbox-process-macos.d.ts +5 -4
  22. package/dist/agent-runtime/sandbox-process-macos.d.ts.map +1 -1
  23. package/dist/agent-runtime/sandbox-process-spec.d.ts +6 -0
  24. package/dist/agent-runtime/sandbox-process-spec.d.ts.map +1 -1
  25. package/dist/agent-runtime/sandbox-process-wrapper.d.ts +2 -1
  26. package/dist/agent-runtime/sandbox-process-wrapper.d.ts.map +1 -1
  27. package/dist/agent-runtime/sql-rows.d.ts +10 -10
  28. package/dist/agent-runtime/sqlite-schema.d.ts +2 -2
  29. package/dist/agent-runtime/sqlite.d.ts +1 -1
  30. package/dist/agent-runtime/store-conformance-lifecycle.d.ts +20 -20
  31. package/dist/agent-runtime/store-conformance-support.d.ts +10 -10
  32. package/dist/agent-runtime/terminal-commit.d.ts +10 -10
  33. package/dist/application/grammy.d.ts +1 -1
  34. package/dist/browser/contract-identity.d.ts +1 -1
  35. package/dist/browser/http-fetch.d.ts +1 -1
  36. package/dist/browser/socket-io-contract.d.ts +1 -1
  37. package/dist/contract/bridge-envelope.d.ts +1 -1
  38. package/dist/contract/client-types.d.ts +1 -1
  39. package/dist/contract/define.d.ts +2 -2
  40. package/dist/contract/errors-factory.d.ts +1 -1
  41. package/dist/contract/fingerprint.d.ts +1 -1
  42. package/dist/device-relay/hub.d.ts +1 -1
  43. package/dist/entrypoints/agent-executor/claude-sdk.js +323 -153
  44. package/dist/entrypoints/agent-executor/claude.js +40 -26
  45. package/dist/entrypoints/agent-runtime/postgres.js +3 -3
  46. package/dist/entrypoints/agent-runtime/sandbox.js +21 -16
  47. package/dist/entrypoints/agent-runtime/sqlite/bun.js +1 -1
  48. package/dist/entrypoints/agent-runtime/sqlite/node.js +1 -1
  49. package/dist/entrypoints/bin/upgrade-cli.js +1 -1
  50. package/dist/entrypoints/files/packaging.js +2 -2
  51. package/dist/entrypoints/handler.js +2 -2
  52. package/dist/entrypoints/node.js +2 -2
  53. package/dist/entrypoints/server.js +2 -2
  54. package/dist/entrypoints/tools/mcp.js +3 -3
  55. package/dist/entrypoints/tools/toolkit.js +3 -3
  56. package/dist/entrypoints/tools.js +2 -2
  57. package/dist/files/native-packaging-layout.d.ts +1 -1
  58. package/dist/{index-654rhe5d.js → index-7mjsb7zv.js} +5 -1
  59. package/dist/{index-kdw0n92g.js → index-a09r9ff0.js} +1 -1
  60. package/dist/{index-epyj7ptp.js → index-a84wj6y8.js} +4 -4
  61. package/dist/{index-qymek778.js → index-m2b49tvc.js} +76 -22
  62. package/dist/{index-mrng24wq.js → index-zag9sjpd.js} +1 -1
  63. package/dist/internal/postgres-query.d.ts +1 -1
  64. package/dist/react/query-client.d.ts +1 -1
  65. package/dist/server/bridge-host.d.ts +1 -1
  66. package/dist/server/bun.d.ts +1 -1
  67. package/dist/server/endpoint-dispatch.d.ts.map +1 -1
  68. package/dist/server/middleware/cors.d.ts +3 -3
  69. package/dist/server/middleware/cors.d.ts.map +1 -1
  70. package/dist/server/socket-io-config.d.ts +1 -1
  71. package/dist/service-host/identity.d.ts +1 -1
  72. package/dist/service-host/systemd-inspect.d.ts +1 -1
  73. package/dist/testing/manual-clock.d.ts +1 -1
  74. package/dist/tools/connections/types.d.ts +1 -1
  75. package/dist/tools/mcp/handler.d.ts +1 -1
  76. package/dist/tools/mcp/lazy-discovery.d.ts +1 -1
  77. package/dist/tools/mcp/mount.d.ts +1 -1
  78. package/dist/tools/mcp/stdio.d.ts +1 -1
  79. package/llms/agent-executor-claude-sdk.txt +1 -1
  80. package/llms/agent-executor-claude.txt +1 -1
  81. package/llms/agent-runtime-browser.txt +1 -1
  82. package/llms/agent-runtime-sandbox.txt +12 -8
  83. package/llms/agent-runtime-sqlite-bun.txt +1 -1
  84. package/llms/agent-runtime.2.txt +1 -1
  85. package/llms/agent-runtime.3.txt +4 -4
  86. package/llms/agent-runtime.txt +3 -3
  87. package/llms/application.2.txt +4 -4
  88. package/llms/application.txt +4 -4
  89. package/llms/cli.2.txt +27 -6
  90. package/llms/cli.txt +2 -2
  91. package/llms/contract.txt +1 -1
  92. package/llms/files-packaging.txt +1 -1
  93. package/llms/geo.txt +1 -1
  94. package/llms/live.txt +1 -1
  95. package/llms/oauth.txt +4 -4
  96. package/llms/observability.txt +3 -3
  97. package/llms/primitives.txt +1 -1
  98. package/llms/process.2.txt +7 -7
  99. package/llms/react.txt +4 -4
  100. package/llms/server.2.txt +7 -7
  101. package/llms/server.3.txt +5 -5
  102. package/llms/server.4.txt +6 -6
  103. package/llms/server.txt +13 -5
  104. package/llms/stitchkit.2.txt +3 -3
  105. package/llms/stitchkit.3.txt +1 -1
  106. package/llms/stitchkit.txt +4 -4
  107. package/llms/telegram.txt +1 -1
  108. package/llms/testing.txt +4 -4
  109. package/llms/tools-connections.txt +1 -1
  110. package/llms/tools-toolkit.txt +3 -1
  111. package/llms/tools.2.txt +6 -6
  112. package/llms/tools.3.txt +8 -8
  113. package/llms/upgrading-0.106.0-0.126.0.txt +1 -1
  114. package/llms/upgrading-0.128.0-0.134.0.txt +7 -1
  115. package/llms/upgrading-0.37.0-0.53.0.txt +7 -7
  116. package/llms/upgrading-0.69.0-0.95.0.txt +1 -1
  117. package/llms/upgrading-0.96.0-0.105.0.txt +1 -1
  118. package/llms-full.txt +163 -122
  119. package/llms.txt +8 -8
  120. package/package.json +1 -1
@@ -1,7 +1,12 @@
1
+ import"../../index-tgehj4bp.js";
2
+ import"../../index-5c4m8zdf.js";
3
+ import"../../index-6kec3b14.js";
1
4
  import"../../index-tav72wz5.js";
2
5
  import"../../index-6kwdfb9m.js";
3
6
  import {
4
7
  ENGINE_LINE_BYTES,
8
+ assertEngineWrapCommand,
9
+ resolveWrappedEngineCommand,
5
10
  spawnEngineProcess2,
6
11
  engineProfile,
7
12
  engineEnvironment2,
@@ -13,9 +18,6 @@ import {
13
18
  emitStartupPhase
14
19
  } from "../../index-aacwkve4.js";
15
20
  import"../../index-02kdtrcd.js";
16
- import"../../index-tgehj4bp.js";
17
- import"../../index-5c4m8zdf.js";
18
- import"../../index-6kec3b14.js";
19
21
  import {
20
22
  claudeUserContent,
21
23
  claudeUserMessage,
@@ -146,30 +148,33 @@ async function openClaudeSession(config, input) {
146
148
  let engine;
147
149
  emitStartupPhase(input.onStartupPhase, "spawning", config.onObserverError);
148
150
  try {
151
+ linked.signal.throwIfAborted();
152
+ const rawArgs = [
153
+ ...prefix,
154
+ "-p",
155
+ "--input-format",
156
+ "stream-json",
157
+ "--output-format",
158
+ "stream-json",
159
+ "--include-partial-messages",
160
+ "--replay-user-messages",
161
+ "--verbose",
162
+ "--permission-prompts",
163
+ "host",
164
+ "--permission-prompt-tool",
165
+ "stdio",
166
+ "--permission-mode",
167
+ config.permissionMode,
168
+ ...resume ? ["--resume", sessionId] : ["--session-id", sessionId],
169
+ ...config.model !== undefined ? ["--model", config.model] : []
170
+ ];
171
+ const wrapped = await resolveWrappedEngineCommand({ executable, args: rawArgs, cwd: input.cwd, env, signal: linked.signal }, config.wrapCommand, "createClaudeCliDriver", linked.signal);
149
172
  linked.signal.throwIfAborted();
150
173
  engine = spawnEngineProcess2({
151
- executable,
152
- args: [
153
- ...prefix,
154
- "-p",
155
- "--input-format",
156
- "stream-json",
157
- "--output-format",
158
- "stream-json",
159
- "--include-partial-messages",
160
- "--replay-user-messages",
161
- "--verbose",
162
- "--permission-prompts",
163
- "host",
164
- "--permission-prompt-tool",
165
- "stdio",
166
- "--permission-mode",
167
- config.permissionMode,
168
- ...resume ? ["--resume", sessionId] : ["--session-id", sessionId],
169
- ...config.model !== undefined ? ["--model", config.model] : []
170
- ],
171
- cwd: input.cwd,
172
- env,
174
+ executable: wrapped.executable,
175
+ args: wrapped.args,
176
+ cwd: wrapped.cwd,
177
+ env: wrapped.env,
173
178
  signal: linked.signal,
174
179
  maxLineBytes: CLAUDE_CLI_MAX_LINE_BYTES
175
180
  });
@@ -281,6 +286,7 @@ function loginExpiryState(loginExpiresAt, nowMs) {
281
286
  }
282
287
  function createClaudeCliDriver(config = {}) {
283
288
  validateImageOptions(config);
289
+ assertEngineWrapCommand(config.wrapCommand, "createClaudeCliDriver");
284
290
  const executable = config.executable ?? "claude";
285
291
  const prefix = config.prefixArgs ?? [];
286
292
  const ambient = config.ambient ?? process.env;
@@ -301,7 +307,14 @@ function createClaudeCliDriver(config = {}) {
301
307
  images: config.resolveFile !== undefined,
302
308
  planLimits: "passive"
303
309
  };
304
- const cli = (profile, args) => runEngineCli({ executable, prefix, args, profile, ambient });
310
+ const cli = (profile, args) => runEngineCli({
311
+ executable,
312
+ prefix,
313
+ args,
314
+ profile,
315
+ ambient,
316
+ ...config.wrapCommand !== undefined && { wrapCommand: config.wrapCommand }
317
+ });
305
318
  return {
306
319
  engine: "claude-cli",
307
320
  reconcile: "client-id",
@@ -362,6 +375,7 @@ function createClaudeCliDriver(config = {}) {
362
375
  limits,
363
376
  ...config.resolveFile !== undefined && { resolveFile: config.resolveFile },
364
377
  ...config.maxImageBytes !== undefined && { maxImageBytes: config.maxImageBytes },
378
+ ...config.wrapCommand !== undefined && { wrapCommand: config.wrapCommand },
365
379
  ...config.onObserverError !== undefined && {
366
380
  onObserverError: config.onObserverError
367
381
  }
@@ -241,16 +241,16 @@ async function initializePostgresAgentStore(session, prefix, createTables) {
241
241
  return;
242
242
  }
243
243
  if (!present.includes(tables.meta)) {
244
- throw new Error(`Refusing an unversioned partial Stitchkit agent store schema under prefix "${checked}"`);
244
+ throw new Error(`Refusing an unversioned partial StitchKit agent store schema under prefix "${checked}"`);
245
245
  }
246
246
  const versionRow = await session.get(`SELECT value FROM ${tables.meta} WHERE key = 'schema_version'`);
247
247
  const version = versionRow === undefined ? undefined : Number(VersionRowSchema.parse(versionRow).value);
248
248
  if (version !== POSTGRES_AGENT_STORE_SCHEMA_VERSION) {
249
- throw new Error(`Unsupported Stitchkit agent store schema version ${version ?? "none"} under prefix "${checked}"; expected ${POSTGRES_AGENT_STORE_SCHEMA_VERSION}`);
249
+ throw new Error(`Unsupported StitchKit agent store schema version ${version ?? "none"} under prefix "${checked}"; expected ${POSTGRES_AGENT_STORE_SCHEMA_VERSION}`);
250
250
  }
251
251
  const missingTables = expected.filter((table) => !present.includes(table));
252
252
  if (missingTables.length > 0) {
253
- throw new Error(`Refusing a partial Stitchkit agent store schema under prefix "${checked}"; missing ${missingTables.join(", ")}`);
253
+ throw new Error(`Refusing a partial StitchKit agent store schema under prefix "${checked}"; missing ${missingTables.join(", ")}`);
254
254
  }
255
255
  }
256
256
 
@@ -767,7 +767,6 @@ async function createBubblewrapSandboxBackend(config) {
767
767
  };
768
768
  }
769
769
  // src/agent-runtime/sandbox-process-macos.ts
770
- import { realpathSync as realpathSync2 } from "node:fs";
771
770
  import { posix as posix4 } from "node:path";
772
771
 
773
772
  // src/agent-runtime/sandbox-process-spec.ts
@@ -784,7 +783,8 @@ var ProcessSandboxUnixSocketSchema = z4.object({
784
783
  mountPath: AbsolutePathSchema.optional()
785
784
  }).strict();
786
785
  function normalizeAbsolute(path) {
787
- return posix3.normalize(path);
786
+ const normalized = posix3.normalize(path);
787
+ return normalized.length > 1 && normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
788
788
  }
789
789
  function resolveRealOrAncestor(path) {
790
790
  const normalized = normalizeAbsolute(path);
@@ -907,12 +907,11 @@ function escapeSeatbeltString(value) {
907
907
  return value.replaceAll("\\", "\\\\").replaceAll('"', "\\\"");
908
908
  }
909
909
  function uniqueVariants(path) {
910
- const set = new Set([path]);
911
- try {
912
- const resolved = realpathSync2(path);
913
- if (resolved.length > 0)
914
- set.add(resolved);
915
- } catch {}
910
+ const raw = normalizeAbsolute(path);
911
+ const set = new Set([raw]);
912
+ const resolved = resolveRealOrAncestor(raw);
913
+ if (resolved.length > 0)
914
+ set.add(normalizeAbsolute(resolved));
916
915
  return [...set];
917
916
  }
918
917
  function allowWriteSubpaths(lines, paths, emitted) {
@@ -963,14 +962,6 @@ function buildSeatbeltProfile(spec) {
963
962
  }
964
963
  }
965
964
  }
966
- if (parsed.denyPaths !== undefined && parsed.denyPaths.length > 0) {
967
- for (const denied of parsed.denyPaths) {
968
- for (const variant of uniqueVariants(denied)) {
969
- const escaped = escapeSeatbeltString(variant);
970
- lines.push(`(deny file-read* file-write* (literal "${escaped}") (subpath "${escaped}"))`);
971
- }
972
- }
973
- }
974
965
  if ((parsed.network ?? "deny") === "deny") {
975
966
  lines.push("(deny network*)");
976
967
  if (parsed.unixSockets !== undefined && parsed.unixSockets.length > 0) {
@@ -981,6 +972,20 @@ function buildSeatbeltProfile(spec) {
981
972
  }
982
973
  }
983
974
  }
975
+ if (parsed.denyPaths !== undefined && parsed.denyPaths.length > 0) {
976
+ const deniedEmitted = new Set;
977
+ for (const denied of parsed.denyPaths) {
978
+ for (const variant of uniqueVariants(denied)) {
979
+ if (deniedEmitted.has(variant))
980
+ continue;
981
+ deniedEmitted.add(variant);
982
+ const escaped = escapeSeatbeltString(variant);
983
+ lines.push(`(deny file-read* file-write* (literal "${escaped}") (subpath "${escaped}"))`);
984
+ lines.push(`(deny network-outbound (remote unix-socket (path-literal "${escaped}")) (remote unix-socket (subpath "${escaped}")))`);
985
+ lines.push(`(deny network-bind network-inbound (local unix-socket (path-literal "${escaped}")) (local unix-socket (subpath "${escaped}")))`);
986
+ }
987
+ }
988
+ }
984
989
  return `${lines.join(`
985
990
  `)}
986
991
  `;
@@ -11,7 +11,7 @@ import"../../../index-79vqbjcz.js";
11
11
  import {
12
12
  initializeAgentRuntimeSqlite2,
13
13
  createSqliteAgentRuntimeStore2
14
- } from "../../../index-epyj7ptp.js";
14
+ } from "../../../index-a84wj6y8.js";
15
15
  import"../../../index-werjqesf.js";
16
16
  import"../../../index-6kec3b14.js";
17
17
  import"../../../index-tgehj4bp.js";
@@ -11,7 +11,7 @@ import"../../../index-79vqbjcz.js";
11
11
  import {
12
12
  initializeAgentRuntimeSqlite2,
13
13
  createSqliteAgentRuntimeStore2
14
- } from "../../../index-epyj7ptp.js";
14
+ } from "../../../index-a84wj6y8.js";
15
15
  import"../../../index-werjqesf.js";
16
16
  import"../../../index-6kec3b14.js";
17
17
  import"../../../index-tgehj4bp.js";
@@ -288,7 +288,7 @@ function planFixes(changelog, from, to) {
288
288
  };
289
289
  }
290
290
  function renderUpgradePlan(changes, from, to) {
291
- const header = `# Stitchkit upgrade ${from} → ${to}`;
291
+ const header = `# StitchKit upgrade ${from} → ${to}`;
292
292
  if (changes.length === 0)
293
293
  return `${header}
294
294
 
@@ -1025,7 +1025,7 @@ var NativeAssetEntrySchema = z4.strictObject({
1025
1025
  });
1026
1026
  var NativeAssetManifestSchema = z4.strictObject({
1027
1027
  formatVersion: z4.literal(2, {
1028
- error: "Native asset manifest formatVersion must be 2 for this Stitchkit"
1028
+ error: "Native asset manifest formatVersion must be 2 for this StitchKit"
1029
1029
  }),
1030
1030
  loader: RelativePathSchema,
1031
1031
  assets: z4.strictObject({
@@ -1298,7 +1298,7 @@ function installedPackageRoot() {
1298
1298
  break;
1299
1299
  directory = parent;
1300
1300
  }
1301
- throw new Error("Native packaging must run from its installed Stitchkit package");
1301
+ throw new Error("Native packaging must run from its installed StitchKit package");
1302
1302
  }
1303
1303
  function readVerifiedAsset(root, published, platform, architecture) {
1304
1304
  const missing = {
@@ -5,7 +5,7 @@ import {
5
5
  bridgeBodyKind,
6
6
  readBridgeBodyText
7
7
  } from "../index-w3s79kcb.js";
8
- import"../index-654rhe5d.js";
8
+ import"../index-7mjsb7zv.js";
9
9
  import"../index-m38ej7e5.js";
10
10
  import"../index-78da4g74.js";
11
11
  import"../index-yrhw10ef.js";
@@ -16,7 +16,7 @@ import {
16
16
  import {
17
17
  isTrustProxyHandler,
18
18
  createHandler2
19
- } from "../index-qymek778.js";
19
+ } from "../index-m2b49tvc.js";
20
20
  import {
21
21
  secretsEqual
22
22
  } from "../index-apv5xfef.js";
@@ -1,6 +1,6 @@
1
1
  import"../index-78da4g74.js";
2
2
  import"../index-yrhw10ef.js";
3
- import"../index-654rhe5d.js";
3
+ import"../index-7mjsb7zv.js";
4
4
  import"../index-m38ej7e5.js";
5
5
  import"../index-yt1gg11x.js";
6
6
  import {
@@ -35,7 +35,7 @@ import {
35
35
  } from "../index-y68gavb5.js";
36
36
  import {
37
37
  createHandler2
38
- } from "../index-qymek778.js";
38
+ } from "../index-m2b49tvc.js";
39
39
  import {
40
40
  createMultipartStream2,
41
41
  implement2,
@@ -13,7 +13,7 @@ import {
13
13
  DEFAULT_CORS_EXPOSE_HEADERS2,
14
14
  corsHeaders2,
15
15
  corsPreflightResponse2
16
- } from "../index-654rhe5d.js";
16
+ } from "../index-7mjsb7zv.js";
17
17
  import {
18
18
  joinRoutePath,
19
19
  parseTrailingWildcard
@@ -89,7 +89,7 @@ import {
89
89
  ndjsonRoute2,
90
90
  sseRoute2,
91
91
  createHandler2
92
- } from "../index-qymek778.js";
92
+ } from "../index-m2b49tvc.js";
93
93
  import {
94
94
  secretsEqual
95
95
  } from "../index-apv5xfef.js";
@@ -1,4 +1,4 @@
1
- import"../../index-654rhe5d.js";
1
+ import"../../index-7mjsb7zv.js";
2
2
  import"../../index-78da4g74.js";
3
3
  import"../../index-dsa676h8.js";
4
4
  import"../../index-27hck3z2.js";
@@ -21,7 +21,7 @@ import {
21
21
  createMcpHandler2,
22
22
  createMcpHttpRoute2,
23
23
  createStdioMcpServer2
24
- } from "../../index-mrng24wq.js";
24
+ } from "../../index-zag9sjpd.js";
25
25
  import {
26
26
  DEFAULT_PROCESS_SIGNALS,
27
27
  defaultSignalSource,
@@ -29,7 +29,7 @@ import {
29
29
  guardSignalCallback
30
30
  } from "../../index-3prvb42w.js";
31
31
  import"../../index-67pnt4bh.js";
32
- import"../../index-kdw0n92g.js";
32
+ import"../../index-a09r9ff0.js";
33
33
  import"../../index-k9g061ma.js";
34
34
  import {
35
35
  MCP_CATALOG_META_KEY2,
@@ -19,15 +19,15 @@ import"../../index-0x4mnwg5.js";
19
19
  import"../../index-6kec3b14.js";
20
20
  import"../../index-gy9x38a2.js";
21
21
  import"../../index-yrhw10ef.js";
22
- import"../../index-654rhe5d.js";
22
+ import"../../index-7mjsb7zv.js";
23
23
  import {
24
24
  mountMcp2,
25
25
  buildMcpServer2,
26
26
  createMcpHandler2,
27
27
  createStdioMcpServer2
28
- } from "../../index-mrng24wq.js";
28
+ } from "../../index-zag9sjpd.js";
29
29
  import"../../index-67pnt4bh.js";
30
- import"../../index-kdw0n92g.js";
30
+ import"../../index-a09r9ff0.js";
31
31
  import"../../index-k9g061ma.js";
32
32
  import {
33
33
  mountAgentTools2
@@ -6,7 +6,7 @@ import {
6
6
  } from "../index-xrsryvd2.js";
7
7
  import {
8
8
  DEFAULT_CORS_ALLOW_HEADERS2
9
- } from "../index-654rhe5d.js";
9
+ } from "../index-7mjsb7zv.js";
10
10
  import"../index-27hck3z2.js";
11
11
  import"../index-ngwf1s3c.js";
12
12
  import {
@@ -75,7 +75,7 @@ import {
75
75
  wwwAuthenticateHeader2,
76
76
  oauthProtectedResourceRoute2,
77
77
  createMcpProgressReporter
78
- } from "../index-kdw0n92g.js";
78
+ } from "../index-a09r9ff0.js";
79
79
  import {
80
80
  PORTABLE_JSON_SCHEMA_FORMATS2,
81
81
  findNonPortableFormats2,
@@ -12,7 +12,7 @@ export declare const NativeLayoutSchema: z.ZodObject<{
12
12
  x64: z.ZodString;
13
13
  }, z.core.$strict>;
14
14
  }, z.core.$strict>;
15
- /** One published addon: its package path and the size and SHA256 of the bytes Stitchkit built. */
15
+ /** One published addon: its package path and the size and SHA256 of the bytes StitchKit built. */
16
16
  export declare const NativeAssetEntrySchema: z.ZodObject<{
17
17
  path: z.ZodString;
18
18
  size: z.ZodInt;
@@ -1,3 +1,7 @@
1
+ import {
2
+ DEADLINE_BUDGET_HEADER2
3
+ } from "./index-k137ezb6.js";
4
+
1
5
  // src/server/middleware/cors.ts
2
6
  import { z } from "zod";
3
7
  var CorsOriginDecisionSchema = z.union([
@@ -47,7 +51,7 @@ function deniedRequestCors(config) {
47
51
  safelistedBody: "refused"
48
52
  };
49
53
  }
50
- var DEFAULT_CORS_ALLOW_HEADERS2 = "Content-Type, Authorization, X-Trace-Id, traceparent, tracestate, X-Stitchkit-Timeout-Ms";
54
+ var DEFAULT_CORS_ALLOW_HEADERS2 = `Content-Type, Authorization, X-Trace-Id, traceparent, tracestate, ${DEADLINE_BUDGET_HEADER2}`;
51
55
  var DEFAULT_CORS_EXPOSE_HEADERS2 = "Content-Disposition, Content-Length, Content-Range, Accept-Ranges, ETag, Last-Modified, X-Request-Id, X-Build-Id";
52
56
  function assertCorsConfig(config) {
53
57
  if (isOriginPolicy(config)) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_CORS_ALLOW_HEADERS2
3
- } from "./index-654rhe5d.js";
3
+ } from "./index-7mjsb7zv.js";
4
4
 
5
5
  // src/server/oauth/metadata.ts
6
6
  var PROTECTED_RESOURCE_PATH2 = "/.well-known/oauth-protected-resource";
@@ -297,7 +297,7 @@ function initializeAgentRuntimeSqlite2(database) {
297
297
  const existing = database.prepare(`SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE 'stitchkit_agent_runtime_%' ORDER BY name`).all().map((row) => TableRowSchema.parse(row).name);
298
298
  const hasMeta = existing.includes("stitchkit_agent_runtime_meta");
299
299
  if (!hasMeta && existing.length > 0) {
300
- throw new Error("Refusing an unversioned partial Stitchkit agent-runtime SQLite schema");
300
+ throw new Error("Refusing an unversioned partial StitchKit agent-runtime SQLite schema");
301
301
  }
302
302
  database.exec(`
303
303
  CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_meta (
@@ -330,18 +330,18 @@ function initializeAgentRuntimeSqlite2(database) {
330
330
  return;
331
331
  }
332
332
  if (version !== SCHEMA_VERSION) {
333
- throw new Error(`Unsupported Stitchkit agent-runtime SQLite schema version ${version}; expected ${SCHEMA_VERSION}`);
333
+ throw new Error(`Unsupported StitchKit agent-runtime SQLite schema version ${version}; expected ${SCHEMA_VERSION}`);
334
334
  }
335
335
  const missingTables = TABLES2.filter((table) => !existing.includes(table));
336
336
  if (missingTables.length > 0) {
337
- throw new Error(`Refusing a partial Stitchkit agent-runtime SQLite schema; missing ${missingTables.join(", ")}`);
337
+ throw new Error(`Refusing a partial StitchKit agent-runtime SQLite schema; missing ${missingTables.join(", ")}`);
338
338
  }
339
339
  initializeSqliteConversationPurge(database);
340
340
  database.exec("COMMIT");
341
341
  return;
342
342
  }
343
343
  if (existing.some((table) => table !== "stitchkit_agent_runtime_meta")) {
344
- throw new Error("Refusing an unversioned partial Stitchkit agent-runtime SQLite schema");
344
+ throw new Error("Refusing an unversioned partial StitchKit agent-runtime SQLite schema");
345
345
  }
346
346
  database.exec(`
347
347
  CREATE TABLE stitchkit_agent_runtime_heads (
@@ -4,7 +4,7 @@ import {
4
4
  assertCorsConfig,
5
5
  requestCorsHeaders,
6
6
  applyCors
7
- } from "./index-654rhe5d.js";
7
+ } from "./index-7mjsb7zv.js";
8
8
  import {
9
9
  joinRoutePath,
10
10
  parseTrailingWildcard
@@ -1670,6 +1670,29 @@ async function dataEndpointResponse(state, request, {
1670
1670
  }
1671
1671
 
1672
1672
  // src/server/endpoint-dispatch.ts
1673
+ function forwardAbortSignal(sourceSignal, target) {
1674
+ if (sourceSignal.aborted) {
1675
+ target.abort(sourceSignal.reason);
1676
+ return () => {
1677
+ return;
1678
+ };
1679
+ }
1680
+ const onAbort = () => {
1681
+ target.abort(sourceSignal.reason);
1682
+ };
1683
+ sourceSignal.addEventListener("abort", onAbort, { once: true });
1684
+ return () => sourceSignal.removeEventListener("abort", onAbort);
1685
+ }
1686
+ function closeLateStreamSource(value) {
1687
+ if (!isAsyncIterable(value))
1688
+ return;
1689
+ try {
1690
+ const iterator = value[Symbol.asyncIterator]();
1691
+ Promise.resolve(iterator.return?.(undefined)).catch(() => {
1692
+ return;
1693
+ });
1694
+ } catch {}
1695
+ }
1673
1696
  async function dispatchEndpoint(state, request, match) {
1674
1697
  const { hooks, config } = state;
1675
1698
  const { req, url, traceId, clientIp } = request;
@@ -1682,14 +1705,25 @@ async function dispatchEndpoint(state, request, match) {
1682
1705
  }
1683
1706
  let deadlineTimer;
1684
1707
  let deadlineLink;
1685
- let deadlineOwnedByStream = false;
1686
- const releaseDeadline = () => {
1708
+ let deadlineController;
1709
+ let releaseStreamReq;
1710
+ let releaseStreamOpenDeadline;
1711
+ let streamOpened = false;
1712
+ let keepRawBodySignalLink = false;
1713
+ const disarmDeadlineTimer = () => {
1687
1714
  if (deadlineTimer !== undefined) {
1688
1715
  clearTimeout(deadlineTimer);
1689
1716
  deadlineTimer = undefined;
1690
1717
  }
1691
- deadlineLink?.release();
1692
- deadlineLink = undefined;
1718
+ };
1719
+ const releaseOpenDeadline = () => {
1720
+ disarmDeadlineTimer();
1721
+ if (!keepRawBodySignalLink) {
1722
+ deadlineLink?.release();
1723
+ deadlineLink = undefined;
1724
+ }
1725
+ releaseStreamOpenDeadline?.();
1726
+ releaseStreamOpenDeadline = undefined;
1693
1727
  };
1694
1728
  let multipartLifecycle;
1695
1729
  try {
@@ -1697,22 +1731,22 @@ async function dispatchEndpoint(state, request, match) {
1697
1731
  headerValue: req.headers.get(DEADLINE_BUDGET_HEADER2),
1698
1732
  endpointTimeoutMs: method.timeout
1699
1733
  });
1734
+ let activeDeadlineReader;
1700
1735
  if (budget.kind === "bounded") {
1701
1736
  const deadlineAt = performance.now() + budget.budgetMs;
1702
- const deadlineController = new AbortController;
1737
+ deadlineController = new AbortController;
1703
1738
  deadlineTimer = setTimeout(() => {
1704
- deadlineController.abort(abortError("Request deadline exceeded", "TimeoutError"));
1739
+ deadlineController?.abort(abortError("Request deadline exceeded", "TimeoutError"));
1705
1740
  }, budget.budgetMs);
1706
1741
  deadlineTimer.unref?.();
1707
1742
  deadlineLink = linkAbortSignals(req.signal, deadlineController.signal);
1708
1743
  ctx.signal = deadlineLink.signal;
1709
- ctx.remainingTimeoutMs = createRemainingTimeoutReader(deadlineAt);
1744
+ activeDeadlineReader = createRemainingTimeoutReader(deadlineAt);
1745
+ ctx.remainingTimeoutMs = (reserveMs) => activeDeadlineReader?.(reserveMs);
1710
1746
  } else if (budget.kind === "expired") {
1711
1747
  ctx.remainingTimeoutMs = () => 0;
1712
1748
  } else {
1713
- ctx.remainingTimeoutMs = () => {
1714
- return;
1715
- };
1749
+ ctx.remainingTimeoutMs = (reserveMs) => activeDeadlineReader?.(reserveMs);
1716
1750
  }
1717
1751
  parsePathParamsInto(ctx, method);
1718
1752
  if (hooks?.authorize) {
@@ -1746,18 +1780,30 @@ async function dispatchEndpoint(state, request, match) {
1746
1780
  ctx.response = responseMetadata;
1747
1781
  const streamAbort = method.stream ? new AbortController : undefined;
1748
1782
  if (streamAbort) {
1749
- const signal = ctx.signal ?? req.signal;
1750
- if (signal.aborted)
1751
- streamAbort.abort(signal.reason);
1752
- else {
1753
- signal.addEventListener("abort", () => streamAbort.abort(signal.reason), {
1754
- once: true
1755
- });
1783
+ releaseStreamReq = forwardAbortSignal(req.signal, streamAbort);
1784
+ if (deadlineController && !streamAbort.signal.aborted) {
1785
+ releaseStreamOpenDeadline = forwardAbortSignal(deadlineController.signal, streamAbort);
1756
1786
  }
1757
- streamAbort.signal.addEventListener("abort", releaseDeadline, { once: true });
1787
+ streamAbort.signal.addEventListener("abort", () => {
1788
+ releaseStreamReq?.();
1789
+ releaseStreamReq = undefined;
1790
+ releaseStreamOpenDeadline?.();
1791
+ releaseStreamOpenDeadline = undefined;
1792
+ }, { once: true });
1758
1793
  ctx.signal = streamAbort.signal;
1759
1794
  }
1760
1795
  const result = await method.handler(ctx);
1796
+ if (method.stream) {
1797
+ if (deadlineController?.signal.aborted && !req.signal.aborted) {
1798
+ closeLateStreamSource(result);
1799
+ throw new AppError2("REQUEST_TIMEOUT", {
1800
+ status: 408,
1801
+ message: "Request deadline exceeded"
1802
+ });
1803
+ }
1804
+ releaseOpenDeadline();
1805
+ activeDeadlineReader = method.stream.lifetimeMs !== undefined ? createRemainingTimeoutReader(performance.now() + method.stream.lifetimeMs) : undefined;
1806
+ }
1761
1807
  const response = await endpointResponse(state, request, {
1762
1808
  ctx,
1763
1809
  match,
@@ -1766,15 +1812,23 @@ async function dispatchEndpoint(state, request, match) {
1766
1812
  streamAbort
1767
1813
  });
1768
1814
  if (streamAbort && !streamAbort.signal.aborted) {
1769
- deadlineOwnedByStream = true;
1815
+ streamOpened = true;
1816
+ }
1817
+ if (method.rawResponse && response.body !== null && !req.signal.aborted && !deadlineController?.signal.aborted) {
1818
+ disarmDeadlineTimer();
1819
+ activeDeadlineReader = undefined;
1820
+ keepRawBodySignalLink = true;
1770
1821
  }
1771
1822
  return response;
1772
1823
  } catch (err) {
1773
1824
  await multipartLifecycle?.rollback();
1774
1825
  return request.respondError(err, ctx, method, groupHooks);
1775
1826
  } finally {
1776
- if (!deadlineOwnedByStream)
1777
- releaseDeadline();
1827
+ releaseOpenDeadline();
1828
+ if (!streamOpened) {
1829
+ releaseStreamReq?.();
1830
+ releaseStreamReq = undefined;
1831
+ }
1778
1832
  }
1779
1833
  }
1780
1834
 
@@ -40,7 +40,7 @@ import {
40
40
  wwwAuthenticateHeader2,
41
41
  mcpProgressToken,
42
42
  createMcpProgressReporter
43
- } from "./index-kdw0n92g.js";
43
+ } from "./index-a09r9ff0.js";
44
44
  import {
45
45
  MCP_CATALOG_HEADER,
46
46
  mcpCatalogMeta2,
@@ -2,7 +2,7 @@
2
2
  * The one Postgres boundary the stores type against: run one statement with
3
3
  * `$1…$n` parameters in the caller's transaction, resolve with its rows.
4
4
  *
5
- * Stitchkit never opens a connection or imports a client. The application
5
+ * StitchKit never opens a connection or imports a client. The application
6
6
  * hands a store its transaction and this function, so Bun's SQL client,
7
7
  * Prisma and `pg` all fit without an adapter of ours:
8
8
  *
@@ -9,7 +9,7 @@ export interface ApiErrorRetryConfig {
9
9
  /** Whether an unclassified non-API error is treated as a network failure. */
10
10
  network?: boolean;
11
11
  }
12
- /** Build a React Query retry predicate from Stitchkit's cross-bundle API error model. */
12
+ /** Build a React Query retry predicate from StitchKit's cross-bundle API error model. */
13
13
  export declare function apiErrorRetry(config?: ApiErrorRetryConfig): (failureCount: number, error: unknown) => boolean;
14
14
  export type QueryClientServerCache = (factory: () => QueryClient) => () => QueryClient;
15
15
  export type QueryRetryValue = NonNullable<NonNullable<QueryClientConfig['defaultOptions']>['queries']>['retry'];
@@ -42,7 +42,7 @@ export interface BridgeHostHandle {
42
42
  readonly hostInstance: string;
43
43
  }
44
44
  /**
45
- * Serve a Stitchkit `FetchHandler` over a string-only `postMessage` bridge.
45
+ * Serve a StitchKit `FetchHandler` over a string-only `postMessage` bridge.
46
46
  *
47
47
  * Announces a `hello` frame on startup so a reconnecting window drops stale
48
48
  * in-flight calls and applies normal idempotency replay rules.
@@ -48,7 +48,7 @@ export interface BunServerConfig extends BunHandlerConfig, BunFetchComposition {
48
48
  */
49
49
  unix?: UnixListenConfig;
50
50
  websocket?: BunWebSocketHandlers;
51
- /** Full Stitchkit Socket.IO lifecycle; route and default websocket are mounted automatically. */
51
+ /** Full StitchKit Socket.IO lifecycle; route and default websocket are mounted automatically. */
52
52
  socket?: SocketIOServerLifecycle;
53
53
  development?: BunDevelopmentOptions;
54
54
  bun?: ServerPassthrough;
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-dispatch.d.ts","sourceRoot":"","sources":["../../src/server/endpoint-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAsB,gBAAgB,CAAC,OAAO,EAC5C,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,EAC5B,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAC9B,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC,QAAQ,CAAC,CA8HnB"}
1
+ {"version":3,"file":"endpoint-dispatch.d.ts","sourceRoot":"","sources":["../../src/server/endpoint-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA0B3C,wBAAsB,gBAAgB,CAAC,OAAO,EAC5C,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,EAC5B,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAC9B,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC,QAAQ,CAAC,CAyLnB"}