stitchwire 0.58.0 → 0.59.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.
package/bin/stitchwire CHANGED
@@ -59,7 +59,7 @@ var __esm = (fn, res, err) => () => {
59
59
  };
60
60
  var __require = import.meta.require;
61
61
 
62
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/darwin-native.cjs
62
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/darwin-native.cjs
63
63
  var require_darwin_native = __commonJS(function(exports, module) {
64
64
  module.exports = function loadDarwinAddon() {
65
65
  try {
@@ -18764,7 +18764,7 @@ __export(exports_esm_debug, {
18764
18764
  // package.json
18765
18765
  var package_default = {
18766
18766
  name: "stitchwire",
18767
- version: "0.58.0",
18767
+ version: "0.59.0",
18768
18768
  description: "Broker-mediated typed RPC, bounded streams and volatile events between machines that cannot reach each other directly.",
18769
18769
  license: "MIT",
18770
18770
  author: "Max Listov",
@@ -18837,7 +18837,7 @@ var package_default = {
18837
18837
  "@socket.io/bun-engine": "^0.1.2",
18838
18838
  "socket.io": "^4.8.4",
18839
18839
  "socket.io-client": "^4.8.4",
18840
- stitchkit: "0.132.0",
18840
+ stitchkit: "0.135.0",
18841
18841
  zod: "^4.6.7"
18842
18842
  },
18843
18843
  devDependencies: {
@@ -26878,7 +26878,7 @@ var z = {
26878
26878
  };
26879
26879
  // node_modules/.bun/zod@4.6.7/node_modules/zod/v4/core/visit.js
26880
26880
  var RESOLVING = Symbol("z.visit/resolving");
26881
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-xqhede6x.js
26881
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-xqhede6x.js
26882
26882
  function isManagedFilePath(value) {
26883
26883
  if (value.length === 0 || value.includes("\x00") || value.includes("\\"))
26884
26884
  return false;
@@ -26896,46 +26896,12 @@ var ManagedFileRefSchema2 = object({
26896
26896
  name: string2().min(1).optional()
26897
26897
  });
26898
26898
 
26899
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-ps3djm8d.js
26900
- function typedEntries(value) {
26901
- return Object.entries(value);
26902
- }
26903
- function isRecord(value) {
26904
- return typeof value === "object" && value !== null && !Array.isArray(value);
26905
- }
26906
- function isAsyncIterable(value) {
26907
- if (typeof value !== "object" && typeof value !== "function" || value === null) {
26908
- return false;
26909
- }
26910
- return typeof Reflect.get(value, Symbol.asyncIterator) === "function";
26911
- }
26912
- function callRuntimeHandler(handler, context) {
26913
- if (typeof handler !== "function") {
26914
- throw new TypeError("Runtime handler must be a function");
26915
- }
26916
- return Reflect.apply(handler, undefined, [context]);
26917
- }
26918
- function transportResult(value) {
26919
- return value;
26920
- }
26921
-
26922
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-r9kq5ark.js
26923
- function messageOf(value) {
26924
- if (value instanceof Error)
26925
- return value.message;
26926
- if (typeof value === "string")
26927
- return value;
26928
- if (isRecord(value) && typeof value.message === "string")
26929
- return value.message;
26930
- return "";
26931
- }
26932
-
26933
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-jj9228tt.js
26899
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-jj9228tt.js
26934
26900
  function errnoOf(error) {
26935
26901
  return typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : undefined;
26936
26902
  }
26937
26903
 
26938
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-s2e3h616.js
26904
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-s2e3h616.js
26939
26905
  import {
26940
26906
  closeSync,
26941
26907
  constants,
@@ -27276,7 +27242,41 @@ async function readHandle(handle, maxBytes, signal) {
27276
27242
  return bytes;
27277
27243
  }
27278
27244
 
27279
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-zsarb5xp.js
27245
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-ps3djm8d.js
27246
+ function typedEntries(value) {
27247
+ return Object.entries(value);
27248
+ }
27249
+ function isRecord(value) {
27250
+ return typeof value === "object" && value !== null && !Array.isArray(value);
27251
+ }
27252
+ function isAsyncIterable(value) {
27253
+ if (typeof value !== "object" && typeof value !== "function" || value === null) {
27254
+ return false;
27255
+ }
27256
+ return typeof Reflect.get(value, Symbol.asyncIterator) === "function";
27257
+ }
27258
+ function callRuntimeHandler(handler, context) {
27259
+ if (typeof handler !== "function") {
27260
+ throw new TypeError("Runtime handler must be a function");
27261
+ }
27262
+ return Reflect.apply(handler, undefined, [context]);
27263
+ }
27264
+ function transportResult(value) {
27265
+ return value;
27266
+ }
27267
+
27268
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-r9kq5ark.js
27269
+ function messageOf(value) {
27270
+ if (value instanceof Error)
27271
+ return value.message;
27272
+ if (typeof value === "string")
27273
+ return value;
27274
+ if (isRecord(value) && typeof value.message === "string")
27275
+ return value.message;
27276
+ return "";
27277
+ }
27278
+
27279
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-zsarb5xp.js
27280
27280
  function isUnsafeKey(key) {
27281
27281
  return key === "__proto__";
27282
27282
  }
@@ -27284,7 +27284,7 @@ function safeJsonParse(text) {
27284
27284
  return JSON.parse(text, (key, value) => isUnsafeKey(key) ? undefined : value);
27285
27285
  }
27286
27286
 
27287
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-1eeqpadm.js
27287
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-1eeqpadm.js
27288
27288
  function issuePath(path) {
27289
27289
  return path.length > 0 ? path.map(String).join(".") : "(root)";
27290
27290
  }
@@ -27368,13 +27368,17 @@ function formatZodError2(error) {
27368
27368
  `) + suffix;
27369
27369
  }
27370
27370
 
27371
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-gr0kxymw.js
27371
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-gr0kxymw.js
27372
27372
  function assertSafeIntegerFrom(least, rule, name, value, errorType, options) {
27373
27373
  if (value === undefined && options.absent !== "refused")
27374
27374
  return;
27375
27375
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < least)
27376
27376
  throw new errorType(`${name} ${rule}, received ${value}`);
27377
27377
  }
27378
+ function isPositiveSafeInteger(value) {
27379
+ const least = 1;
27380
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= least;
27381
+ }
27378
27382
  function assertPositiveSafeInteger(name, value, errorType = TypeError, options = {}) {
27379
27383
  assertSafeIntegerFrom(1, "must be a positive safe integer", name, value, errorType, options);
27380
27384
  }
@@ -27382,7 +27386,7 @@ function assertNonNegativeSafeInteger(name, value, errorType = TypeError, option
27382
27386
  assertSafeIntegerFrom(0, "must be a non-negative safe integer", name, value, errorType, options);
27383
27387
  }
27384
27388
 
27385
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-21cfxc4z.js
27389
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-vh4291qh.js
27386
27390
  import { constants as constants2, openSync as openSync2 } from "fs";
27387
27391
  import { open as open3 } from "fs/promises";
27388
27392
  var DEFAULT_JSON_FILE_BYTES2 = 1024 * 1024;
@@ -27557,7 +27561,7 @@ function readJsonFileSync2(path, schema, options) {
27557
27561
  return validateJsonValue(parseJsonText(decodeJsonText(bytes, path), path), schema, path);
27558
27562
  }
27559
27563
 
27560
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-6kec3b14.js
27564
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-6kec3b14.js
27561
27565
  var import___stitchkit_darwin_native = __toESM(require_darwin_native(), 1);
27562
27566
  var NATIVE_NOT_PACKAGED = "STITCHKIT_NATIVE_NOT_PACKAGED";
27563
27567
  var messages = {
@@ -27650,7 +27654,7 @@ function loadDarwinBinding() {
27650
27654
  return darwinBinding;
27651
27655
  }
27652
27656
 
27653
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-wz392jyz.js
27657
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-wz392jyz.js
27654
27658
  function abortError(message, name = "AbortError") {
27655
27659
  if (typeof DOMException === "function")
27656
27660
  return new DOMException(message, name);
@@ -27659,7 +27663,7 @@ function abortError(message, name = "AbortError") {
27659
27663
  return error;
27660
27664
  }
27661
27665
 
27662
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-rptj3qnc.js
27666
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-rptj3qnc.js
27663
27667
  function abortReason(signal) {
27664
27668
  return signal.reason ?? abortError("The operation was aborted");
27665
27669
  }
@@ -27750,7 +27754,7 @@ async function withLinkedAbortSignals(first, second, operation) {
27750
27754
  }
27751
27755
  }
27752
27756
 
27753
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-673drwkn.js
27757
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-673drwkn.js
27754
27758
  import { execFile, spawnSync } from "child_process";
27755
27759
  import { readFileSync } from "fs";
27756
27760
  import { platform } from "os";
@@ -28177,7 +28181,7 @@ function probeProcessOwnerSync(pid, recorded) {
28177
28181
  return probeProcessOwnerSyncWith(pid, recorded);
28178
28182
  }
28179
28183
 
28180
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-vmbxj75t.js
28184
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-jwtmw39p.js
28181
28185
  import { hostname as hostname3 } from "os";
28182
28186
  import { closeSync as closeSync2, constants as constants3, fstatSync as fstatSync2, openSync as openSync3, readdirSync } from "fs";
28183
28187
  var DESCRIPTOR_DIRECTORY = "/dev/fd";
@@ -28331,7 +28335,7 @@ async function readLockRecord(path, {
28331
28335
  }
28332
28336
  }
28333
28337
 
28334
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-fmzg39a8.js
28338
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-fmzg39a8.js
28335
28339
  function compareCodeUnits(left, right) {
28336
28340
  if (left < right)
28337
28341
  return -1;
@@ -28357,7 +28361,7 @@ function serializeCanonicalJson(value) {
28357
28361
  return canonicalText(value) ?? "undefined";
28358
28362
  }
28359
28363
 
28360
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-3dq8466w.js
28364
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-3dq8466w.js
28361
28365
  function mix128(input) {
28362
28366
  let a = 2654435769;
28363
28367
  let b = 2246822507;
@@ -28390,7 +28394,7 @@ function canonicalDigest(value) {
28390
28394
  return lanes.map((lane) => lane.toString(16).padStart(8, "0")).join("");
28391
28395
  }
28392
28396
 
28393
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-j0ef04jw.js
28397
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-nfm15ej7.js
28394
28398
  import { lstatSync as lstatSync2, statSync as statSync2 } from "fs";
28395
28399
  import { lstat as lstat2, stat as stat2 } from "fs/promises";
28396
28400
  var VALUE_REFUSALS = new Set([
@@ -28767,7 +28771,7 @@ class PolledJsonFile2 {
28767
28771
  }
28768
28772
  }
28769
28773
 
28770
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-cv9b7fz2.js
28774
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-cv9b7fz2.js
28771
28775
  var UNIX_CLIENT_TRANSPORT_ERROR_NAME = "UnixClientTransportError";
28772
28776
  class UnixClientTransportError2 extends Error {
28773
28777
  code;
@@ -28789,7 +28793,7 @@ function unixTransportError(socketPath, code, message, delivery = "possibly-disp
28789
28793
  });
28790
28794
  }
28791
28795
 
28792
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-c9d05kvt.js
28796
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-c9d05kvt.js
28793
28797
  function randomHex(bytes) {
28794
28798
  const arr = new Uint8Array(bytes);
28795
28799
  crypto.getRandomValues(arr);
@@ -28799,7 +28803,7 @@ function randomHex(bytes) {
28799
28803
  return hex;
28800
28804
  }
28801
28805
 
28802
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-hab790s6.js
28806
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-kp1j7cc8.js
28803
28807
  import { linkSync as linkSync2, lstatSync as lstatSync22, unlinkSync as unlinkSync2 } from "fs";
28804
28808
  import { dirname as dirname2, join as join2 } from "path";
28805
28809
  import {
@@ -29257,7 +29261,7 @@ function bindUnixSocket2(socket, bind) {
29257
29261
  return bound;
29258
29262
  }
29259
29263
 
29260
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-2c5w2d1d.js
29264
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-2c5w2d1d.js
29261
29265
  import { closeSync as closeSync4, fsyncSync, linkSync as linkSync3, openSync as openSync5, renameSync, unlinkSync as unlinkSync3 } from "fs";
29262
29266
  import { link, open as open4, rename, unlink } from "fs/promises";
29263
29267
  import { dirname as dirname3 } from "path";
@@ -29359,20 +29363,312 @@ function publishAtomicFileSync(staged, target, { replace, durability }, io = nat
29359
29363
  }, publish);
29360
29364
  }
29361
29365
 
29362
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-ke02kxsr.js
29366
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-psye60qn.js
29367
+ import { randomBytes } from "crypto";
29368
+ import { dirname as dirname4, join as join3 } from "path";
29369
+ var PREFIX = ".stitchkit-";
29370
+ var SUFFIX = ".tmp";
29371
+ var RANDOM_BYTES = 12;
29372
+ var literal2 = (text) => text.replaceAll(".", "\\.");
29373
+ var NAME = new RegExp(`^${literal2(PREFIX)}[0-9a-f]{${RANDOM_BYTES * 2}}${literal2(SUFFIX)}$`);
29374
+ function stagingName() {
29375
+ return `${PREFIX}${randomBytes(RANDOM_BYTES).toString("hex")}${SUFFIX}`;
29376
+ }
29377
+ function stagingPath(target) {
29378
+ return join3(dirname4(target), stagingName());
29379
+ }
29380
+
29381
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-pp97q86a.js
29382
+ import { closeSync as closeSync5, fchmodSync as fchmodSync2, fsyncSync as fsyncSync2, openSync as openSync6, unlinkSync as unlinkSync4, writeSync as writeSync2 } from "fs";
29383
+ import { open as open5, unlink as unlink2 } from "fs/promises";
29384
+ import { dirname as dirname5 } from "path";
29385
+ var DEFAULT_MODE = 384;
29386
+ function bytesOf(data) {
29387
+ return typeof data === "string" ? new TextEncoder().encode(data) : data;
29388
+ }
29389
+ function assertWriteOptions(options) {
29390
+ if (options.idempotent === true && options.replace !== false) {
29391
+ throw new TypeError('writeFileAtomic option "idempotent: true" requires "replace: false"');
29392
+ }
29393
+ }
29394
+ function bytesEqual(left, right) {
29395
+ if (left.byteLength !== right.byteLength)
29396
+ return false;
29397
+ for (let index = 0;index < left.byteLength; index += 1) {
29398
+ if (left[index] !== right[index])
29399
+ return false;
29400
+ }
29401
+ return true;
29402
+ }
29403
+ function modeMatches(actualMode, expectedMode) {
29404
+ if (process.platform === "win32")
29405
+ return true;
29406
+ return actualMode !== undefined && (actualMode & 4095) === (expectedMode & 4095);
29407
+ }
29408
+ function syncDirectorySync(dir) {
29409
+ assertDirectoryDurability();
29410
+ const descriptor = openSync6(dir, "r");
29411
+ closeAfterSync(() => closeSync5(descriptor), () => fsyncSync2(descriptor));
29412
+ }
29413
+ async function writeAllBytes(file, bytes) {
29414
+ for (let offset = 0;offset < bytes.byteLength; ) {
29415
+ const { bytesWritten } = await file.write(bytes, offset, bytes.byteLength - offset);
29416
+ if (bytesWritten === 0)
29417
+ throw new Error("zero-byte atomic-file write");
29418
+ offset += bytesWritten;
29419
+ }
29420
+ }
29421
+ async function writeFileAtomic2(target, data, options = {}) {
29422
+ return writeAtomicFileData(target, data, options);
29423
+ }
29424
+ function isMissing(error) {
29425
+ return errnoOf(error) === "ENOENT";
29426
+ }
29427
+ async function publishMaybeIdempotent(staged, target, mode, options, expectedBytes, io) {
29428
+ const publishOptions = {
29429
+ replace: options.replace ?? true,
29430
+ durability: options.durability ?? "file"
29431
+ };
29432
+ try {
29433
+ await io.publish(staged, target, publishOptions);
29434
+ return;
29435
+ } catch (error) {
29436
+ if (options.idempotent !== true || errnoOf(error) !== "EEXIST" || expectedBytes === undefined) {
29437
+ throw error;
29438
+ }
29439
+ const readExisting = io.readExisting ?? ((path, maxBytes) => readBoundedFile(path, maxBytes, { rejectSymlinks: true }));
29440
+ let existing;
29441
+ try {
29442
+ existing = await readExisting(target, expectedBytes.byteLength);
29443
+ } catch (readError) {
29444
+ if (isMissing(readError)) {
29445
+ await io.publish(staged, target, publishOptions);
29446
+ return;
29447
+ }
29448
+ throw error;
29449
+ }
29450
+ if (!modeMatches(existing.mode, mode) || !bytesEqual(existing.bytes, expectedBytes)) {
29451
+ throw error;
29452
+ }
29453
+ try {
29454
+ await io.unlink(staged);
29455
+ } catch (cleanup) {
29456
+ if (!isMissing(cleanup))
29457
+ throw new AtomicFilePublicationError2("cleanup", cleanup);
29458
+ }
29459
+ if (publishOptions.durability === "directory") {
29460
+ try {
29461
+ const syncDir = io.syncDir ?? syncDirectory;
29462
+ await syncDir(dirname5(target));
29463
+ } catch (syncError) {
29464
+ throw new AtomicFilePublicationError2("directory-sync", syncError);
29465
+ }
29466
+ }
29467
+ }
29468
+ }
29469
+ async function writeAtomicFileStaged(target, stage, options, io = { open: open5, unlink: unlink2, publish: publishAtomicFile }) {
29470
+ assertWriteOptions(options);
29471
+ const mode = options.mode ?? DEFAULT_MODE;
29472
+ const staged = stagingPath(target);
29473
+ const file = await io.open(staged, "wx", mode);
29474
+ try {
29475
+ const value = await closeAfter(file, async () => {
29476
+ const filled = await stage.fill(file);
29477
+ await file.chmod(mode);
29478
+ if (options.durability !== "none")
29479
+ await file.sync();
29480
+ return filled;
29481
+ });
29482
+ await publishMaybeIdempotent(staged, target, mode, options, stage.expectedBytes, io);
29483
+ return value;
29484
+ } catch (error) {
29485
+ await io.unlink(staged).catch((cleanup) => {
29486
+ if (!isMissing(cleanup))
29487
+ stage.onCleanupError?.(cleanup);
29488
+ });
29489
+ throw error;
29490
+ }
29491
+ }
29492
+ async function writeAtomicFileData(target, data, options, io) {
29493
+ const bytes = bytesOf(data);
29494
+ await writeAtomicFileStaged(target, { fill: (file) => writeAllBytes(file, bytes), expectedBytes: bytes }, options, io);
29495
+ }
29496
+ var nativeSync2 = {
29497
+ open(path, flags, mode) {
29498
+ const descriptor = openSync6(path, flags, mode);
29499
+ return {
29500
+ write: (bytes, offset, length) => writeSync2(descriptor, bytes, offset, length),
29501
+ chmod: (bits) => fchmodSync2(descriptor, bits),
29502
+ sync: () => fsyncSync2(descriptor),
29503
+ close: () => closeSync5(descriptor)
29504
+ };
29505
+ },
29506
+ unlink: unlinkSync4,
29507
+ publish: publishAtomicFileSync
29508
+ };
29509
+ function publishMaybeIdempotentSync(staged, target, mode, options, expectedBytes, io) {
29510
+ const publishOptions = {
29511
+ replace: options.replace ?? true,
29512
+ durability: options.durability ?? "file"
29513
+ };
29514
+ try {
29515
+ io.publish(staged, target, publishOptions);
29516
+ return;
29517
+ } catch (error) {
29518
+ if (options.idempotent !== true || errnoOf(error) !== "EEXIST") {
29519
+ throw error;
29520
+ }
29521
+ const readExisting = io.readExisting ?? ((path, maxBytes) => readBoundedFileSync(path, maxBytes, { rejectSymlinks: true }));
29522
+ let existing;
29523
+ try {
29524
+ existing = readExisting(target, expectedBytes.byteLength);
29525
+ } catch (readError) {
29526
+ if (isMissing(readError)) {
29527
+ io.publish(staged, target, publishOptions);
29528
+ return;
29529
+ }
29530
+ throw error;
29531
+ }
29532
+ if (!modeMatches(existing.mode, mode) || !bytesEqual(existing.bytes, expectedBytes)) {
29533
+ throw error;
29534
+ }
29535
+ try {
29536
+ io.unlink(staged);
29537
+ } catch (cleanup) {
29538
+ if (!isMissing(cleanup))
29539
+ throw new AtomicFilePublicationError2("cleanup", cleanup);
29540
+ }
29541
+ if (publishOptions.durability === "directory") {
29542
+ try {
29543
+ const syncDir = io.syncDir ?? syncDirectorySync;
29544
+ syncDir(dirname5(target));
29545
+ } catch (syncError) {
29546
+ throw new AtomicFilePublicationError2("directory-sync", syncError);
29547
+ }
29548
+ }
29549
+ }
29550
+ }
29551
+ function writeAtomicFileDataSync(target, data, options, io = nativeSync2) {
29552
+ assertWriteOptions(options);
29553
+ const mode = options.mode ?? DEFAULT_MODE;
29554
+ const bytes = bytesOf(data);
29555
+ const staged = stagingPath(target);
29556
+ const file = io.open(staged, "wx", mode);
29557
+ try {
29558
+ closeAfterSync(() => file.close(), () => {
29559
+ for (let offset = 0;offset < bytes.byteLength; ) {
29560
+ const written = file.write(bytes, offset, bytes.byteLength - offset);
29561
+ if (written === 0)
29562
+ throw new Error("zero-byte atomic-file write");
29563
+ offset += written;
29564
+ }
29565
+ file.chmod(mode);
29566
+ if (options.durability !== "none")
29567
+ file.sync();
29568
+ });
29569
+ publishMaybeIdempotentSync(staged, target, mode, options, bytes, io);
29570
+ } catch (error) {
29571
+ try {
29572
+ io.unlink(staged);
29573
+ } catch {}
29574
+ throw error;
29575
+ }
29576
+ }
29577
+ function writeFileAtomicSync2(target, data, options = {}) {
29578
+ writeAtomicFileDataSync(target, data, options);
29579
+ }
29580
+
29581
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-h20qcyh5.js
29582
+ var MAX_TIMER_MS = 2147483647;
29583
+ function clampTimerMs(ms) {
29584
+ return Math.min(Math.max(0, ms), MAX_TIMER_MS);
29585
+ }
29586
+ var monotonicTimerClock = {
29587
+ now: () => performance.now(),
29588
+ schedule(callback, delayMs) {
29589
+ const timer = setTimeout(callback, delayMs);
29590
+ return { cancel: () => clearTimeout(timer) };
29591
+ }
29592
+ };
29593
+ function scheduleAt(clock, dueAt, onDue) {
29594
+ let step;
29595
+ let cancelled = false;
29596
+ const arm = () => {
29597
+ const delayMs = Math.max(0, dueAt - clock.now());
29598
+ if (cancelled)
29599
+ return;
29600
+ step = clock.schedule(() => {
29601
+ const early = clock.now() < dueAt;
29602
+ if (cancelled)
29603
+ return;
29604
+ if (early)
29605
+ arm();
29606
+ else
29607
+ onDue();
29608
+ }, clampTimerMs(delayMs));
29609
+ };
29610
+ arm();
29611
+ return {
29612
+ cancel() {
29613
+ cancelled = true;
29614
+ step.cancel();
29615
+ }
29616
+ };
29617
+ }
29618
+ function sleep(ms, signal) {
29619
+ return new Promise((resolve, reject) => {
29620
+ if (signal?.aborted) {
29621
+ reject(abortReason(signal));
29622
+ return;
29623
+ }
29624
+ const abort = () => {
29625
+ clearTimeout(timer);
29626
+ if (signal)
29627
+ reject(abortReason(signal));
29628
+ };
29629
+ const timer = setTimeout(() => {
29630
+ signal?.removeEventListener("abort", abort);
29631
+ resolve();
29632
+ }, ms);
29633
+ signal?.addEventListener("abort", abort, { once: true });
29634
+ });
29635
+ }
29636
+
29637
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-e1y74yra.js
29638
+ function assertTimerMs(name, value, options = {}) {
29639
+ if (value === undefined && options.absent !== "refused")
29640
+ return;
29641
+ if (typeof value !== "number") {
29642
+ throw new TypeError(`${name} must be a number of milliseconds, received ${String(value)}`);
29643
+ }
29644
+ const min = options.min ?? 1;
29645
+ if (!Number.isSafeInteger(value) || value < min || value > MAX_TIMER_MS) {
29646
+ throw new RangeError(`${name} must be an integer from ${min} to ${MAX_TIMER_MS} milliseconds, received ${value}`);
29647
+ }
29648
+ }
29649
+
29650
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-x1r7kxzd.js
29651
+ var ManagedFileInspectionSchema = ManagedFileRefSchema2.pick({
29652
+ mediaType: true,
29653
+ name: true
29654
+ });
29655
+ var DEFAULT_MAX_BYTES = 100 * 1024 * 1024;
29656
+ var DEFAULT_INSPECTION_BYTES = 64 * 1024;
29657
+
29658
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-43k180c2.js
29363
29659
  import { randomUUID } from "crypto";
29364
29660
  import { constants as constants5 } from "fs";
29365
- import { lstat as lstat3, open as open5, readdir, unlink as unlink2 } from "fs/promises";
29366
- import { dirname as dirname4, join as join3 } from "path";
29661
+ import { lstat as lstat3, open as open6, readdir, unlink as unlink3 } from "fs/promises";
29662
+ import { dirname as dirname6, join as join4 } from "path";
29367
29663
  var MAX_RECLAIM_DEPTH2 = 16;
29368
29664
  var STALE_GUARD_GRACE_MS = 5000;
29369
29665
  var STAGED_NAME = /^\.lock-[0-9a-f-]{36}\.tmp$/;
29370
29666
  async function stagedSibling(path, ino, dev) {
29371
- const directory = dirname4(path);
29667
+ const directory = dirname6(path);
29372
29668
  for (const name of await readdir(directory)) {
29373
29669
  if (!STAGED_NAME.test(name))
29374
29670
  continue;
29375
- const candidate = join3(directory, name);
29671
+ const candidate = join4(directory, name);
29376
29672
  const info = await lstat3(candidate).catch(() => {
29377
29673
  return;
29378
29674
  });
@@ -29415,7 +29711,7 @@ async function sweepStagedLocks(directory, machine, signal) {
29415
29711
  for (const name of await readdir(directory).catch(() => [])) {
29416
29712
  if (!STAGED_NAME.test(name))
29417
29713
  continue;
29418
- const candidate = join3(directory, name);
29714
+ const candidate = join4(directory, name);
29419
29715
  const state = await readLockFile(candidate, undefined, signal);
29420
29716
  if (!state?.owner)
29421
29717
  continue;
@@ -29429,7 +29725,7 @@ async function unlinkIfSame(path, ino, dev, links = 1) {
29429
29725
  const current = await lstat3(path);
29430
29726
  if (current.ino !== ino || current.dev !== dev || !current.isFile() || current.nlink !== links)
29431
29727
  return;
29432
- await unlink2(path);
29728
+ await unlink3(path);
29433
29729
  } catch (error) {
29434
29730
  if (errnoOf(error) !== "ENOENT")
29435
29731
  throw error;
@@ -29442,8 +29738,8 @@ async function createOwned(path, options, reclaimed) {
29442
29738
  const owner = recordOwner(identity, await readProcessInstance(process.pid));
29443
29739
  const ownedRecord = `${JSON.stringify(owner)}
29444
29740
  `;
29445
- const staged = join3(dirname4(path), `.lock-${randomUUID()}.tmp`);
29446
- const handle = await open5(staged, "wx", options.mode);
29741
+ const staged = join4(dirname6(path), `.lock-${randomUUID()}.tmp`);
29742
+ const handle = await open6(staged, "wx", options.mode);
29447
29743
  let ino;
29448
29744
  let dev;
29449
29745
  let published = false;
@@ -29468,7 +29764,7 @@ async function createOwned(path, options, reclaimed) {
29468
29764
  await handle.close().catch(() => {
29469
29765
  return;
29470
29766
  });
29471
- await unlink2(staged).catch(() => {
29767
+ await unlink3(staged).catch(() => {
29472
29768
  return;
29473
29769
  });
29474
29770
  throw error;
@@ -29502,7 +29798,7 @@ async function createOwned(path, options, reclaimed) {
29502
29798
  };
29503
29799
  }
29504
29800
  async function removeJudgedLock(state) {
29505
- const pin = await open5(state.path, constants5.O_RDONLY | constants5.O_NOFOLLOW | constants5.O_NONBLOCK).catch((error) => {
29801
+ const pin = await open6(state.path, constants5.O_RDONLY | constants5.O_NOFOLLOW | constants5.O_NONBLOCK).catch((error) => {
29506
29802
  if (errnoOf(error) === "ENOENT")
29507
29803
  return null;
29508
29804
  throw error;
@@ -29523,7 +29819,7 @@ async function removeJudgedLock(state) {
29523
29819
  if (current?.info.ino !== state.ino || current.info.dev !== state.dev || current.text !== state.record)
29524
29820
  return "changed";
29525
29821
  if (state.stagedName !== undefined)
29526
- await unlink2(state.stagedName).catch((error) => {
29822
+ await unlink3(state.stagedName).catch((error) => {
29527
29823
  if (errnoOf(error) !== "ENOENT")
29528
29824
  throw error;
29529
29825
  });
@@ -29573,7 +29869,7 @@ async function reclaimUnderGuard(path, options, depth) {
29573
29869
  cause: new LockRecordError("LOCK_RECORD_CHANGED", "The judged lock was replaced before it could be reclaimed")
29574
29870
  };
29575
29871
  }
29576
- await sweepStagedLocks(dirname4(path), options.machineIdentity, options.signal);
29872
+ await sweepStagedLocks(dirname6(path), options.machineIdentity, options.signal);
29577
29873
  return await createOwned(path, options, state !== undefined).catch((error) => {
29578
29874
  if (errnoOf(error) === "EEXIST" || options.signal?.aborted)
29579
29875
  return { refused: true, cause: error };
@@ -29621,60 +29917,7 @@ async function attemptExclusiveLock(path, options, depth = 0) {
29621
29917
  }
29622
29918
  }
29623
29919
 
29624
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-mxt0wfjy.js
29625
- var MAX_TIMER_MS = 2147483647;
29626
- var monotonicTimerClock = {
29627
- now: () => performance.now(),
29628
- schedule(callback, delayMs) {
29629
- const timer = setTimeout(callback, delayMs);
29630
- return { cancel: () => clearTimeout(timer) };
29631
- }
29632
- };
29633
- function scheduleAt(clock, dueAt, onDue) {
29634
- let step;
29635
- let cancelled = false;
29636
- const arm = () => {
29637
- const delayMs = Math.max(0, dueAt - clock.now());
29638
- if (cancelled)
29639
- return;
29640
- step = clock.schedule(() => {
29641
- const early = clock.now() < dueAt;
29642
- if (cancelled)
29643
- return;
29644
- if (early)
29645
- arm();
29646
- else
29647
- onDue();
29648
- }, Math.min(delayMs, MAX_TIMER_MS));
29649
- };
29650
- arm();
29651
- return {
29652
- cancel() {
29653
- cancelled = true;
29654
- step.cancel();
29655
- }
29656
- };
29657
- }
29658
- function sleep(ms, signal) {
29659
- return new Promise((resolve, reject) => {
29660
- if (signal?.aborted) {
29661
- reject(abortReason(signal));
29662
- return;
29663
- }
29664
- const abort = () => {
29665
- clearTimeout(timer);
29666
- if (signal)
29667
- reject(abortReason(signal));
29668
- };
29669
- const timer = setTimeout(() => {
29670
- signal?.removeEventListener("abort", abort);
29671
- resolve();
29672
- }, ms);
29673
- signal?.addEventListener("abort", abort, { once: true });
29674
- });
29675
- }
29676
-
29677
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-2nwvn7m2.js
29920
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-29v1p1f4.js
29678
29921
  class ExclusiveLockError2 extends Error {
29679
29922
  code;
29680
29923
  label;
@@ -29775,243 +30018,7 @@ async function withExclusiveLock2(path, run, options = {}) {
29775
30018
  }
29776
30019
  }
29777
30020
 
29778
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-psye60qn.js
29779
- import { randomBytes } from "crypto";
29780
- import { dirname as dirname5, join as join4 } from "path";
29781
- var PREFIX = ".stitchkit-";
29782
- var SUFFIX = ".tmp";
29783
- var RANDOM_BYTES = 12;
29784
- var literal2 = (text) => text.replaceAll(".", "\\.");
29785
- var NAME = new RegExp(`^${literal2(PREFIX)}[0-9a-f]{${RANDOM_BYTES * 2}}${literal2(SUFFIX)}$`);
29786
- function stagingName() {
29787
- return `${PREFIX}${randomBytes(RANDOM_BYTES).toString("hex")}${SUFFIX}`;
29788
- }
29789
- function stagingPath(target) {
29790
- return join4(dirname5(target), stagingName());
29791
- }
29792
-
29793
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-pp97q86a.js
29794
- import { closeSync as closeSync5, fchmodSync as fchmodSync2, fsyncSync as fsyncSync2, openSync as openSync6, unlinkSync as unlinkSync4, writeSync as writeSync2 } from "fs";
29795
- import { open as open6, unlink as unlink3 } from "fs/promises";
29796
- import { dirname as dirname6 } from "path";
29797
- var DEFAULT_MODE = 384;
29798
- function bytesOf(data) {
29799
- return typeof data === "string" ? new TextEncoder().encode(data) : data;
29800
- }
29801
- function assertWriteOptions(options) {
29802
- if (options.idempotent === true && options.replace !== false) {
29803
- throw new TypeError('writeFileAtomic option "idempotent: true" requires "replace: false"');
29804
- }
29805
- }
29806
- function bytesEqual(left, right) {
29807
- if (left.byteLength !== right.byteLength)
29808
- return false;
29809
- for (let index = 0;index < left.byteLength; index += 1) {
29810
- if (left[index] !== right[index])
29811
- return false;
29812
- }
29813
- return true;
29814
- }
29815
- function modeMatches(actualMode, expectedMode) {
29816
- if (process.platform === "win32")
29817
- return true;
29818
- return actualMode !== undefined && (actualMode & 4095) === (expectedMode & 4095);
29819
- }
29820
- function syncDirectorySync(dir) {
29821
- assertDirectoryDurability();
29822
- const descriptor = openSync6(dir, "r");
29823
- closeAfterSync(() => closeSync5(descriptor), () => fsyncSync2(descriptor));
29824
- }
29825
- async function writeAllBytes(file, bytes) {
29826
- for (let offset = 0;offset < bytes.byteLength; ) {
29827
- const { bytesWritten } = await file.write(bytes, offset, bytes.byteLength - offset);
29828
- if (bytesWritten === 0)
29829
- throw new Error("zero-byte atomic-file write");
29830
- offset += bytesWritten;
29831
- }
29832
- }
29833
- async function writeFileAtomic2(target, data, options = {}) {
29834
- return writeAtomicFileData(target, data, options);
29835
- }
29836
- function isMissing(error) {
29837
- return errnoOf(error) === "ENOENT";
29838
- }
29839
- async function publishMaybeIdempotent(staged, target, mode, options, expectedBytes, io) {
29840
- const publishOptions = {
29841
- replace: options.replace ?? true,
29842
- durability: options.durability ?? "file"
29843
- };
29844
- try {
29845
- await io.publish(staged, target, publishOptions);
29846
- return;
29847
- } catch (error) {
29848
- if (options.idempotent !== true || errnoOf(error) !== "EEXIST" || expectedBytes === undefined) {
29849
- throw error;
29850
- }
29851
- const readExisting = io.readExisting ?? ((path, maxBytes) => readBoundedFile(path, maxBytes, { rejectSymlinks: true }));
29852
- let existing;
29853
- try {
29854
- existing = await readExisting(target, expectedBytes.byteLength);
29855
- } catch (readError) {
29856
- if (isMissing(readError)) {
29857
- await io.publish(staged, target, publishOptions);
29858
- return;
29859
- }
29860
- throw error;
29861
- }
29862
- if (!modeMatches(existing.mode, mode) || !bytesEqual(existing.bytes, expectedBytes)) {
29863
- throw error;
29864
- }
29865
- try {
29866
- await io.unlink(staged);
29867
- } catch (cleanup) {
29868
- if (!isMissing(cleanup))
29869
- throw new AtomicFilePublicationError2("cleanup", cleanup);
29870
- }
29871
- if (publishOptions.durability === "directory") {
29872
- try {
29873
- const syncDir = io.syncDir ?? syncDirectory;
29874
- await syncDir(dirname6(target));
29875
- } catch (syncError) {
29876
- throw new AtomicFilePublicationError2("directory-sync", syncError);
29877
- }
29878
- }
29879
- }
29880
- }
29881
- async function writeAtomicFileStaged(target, stage, options, io = { open: open6, unlink: unlink3, publish: publishAtomicFile }) {
29882
- assertWriteOptions(options);
29883
- const mode = options.mode ?? DEFAULT_MODE;
29884
- const staged = stagingPath(target);
29885
- const file = await io.open(staged, "wx", mode);
29886
- try {
29887
- const value = await closeAfter(file, async () => {
29888
- const filled = await stage.fill(file);
29889
- await file.chmod(mode);
29890
- if (options.durability !== "none")
29891
- await file.sync();
29892
- return filled;
29893
- });
29894
- await publishMaybeIdempotent(staged, target, mode, options, stage.expectedBytes, io);
29895
- return value;
29896
- } catch (error) {
29897
- await io.unlink(staged).catch((cleanup) => {
29898
- if (!isMissing(cleanup))
29899
- stage.onCleanupError?.(cleanup);
29900
- });
29901
- throw error;
29902
- }
29903
- }
29904
- async function writeAtomicFileData(target, data, options, io) {
29905
- const bytes = bytesOf(data);
29906
- await writeAtomicFileStaged(target, { fill: (file) => writeAllBytes(file, bytes), expectedBytes: bytes }, options, io);
29907
- }
29908
- var nativeSync2 = {
29909
- open(path, flags, mode) {
29910
- const descriptor = openSync6(path, flags, mode);
29911
- return {
29912
- write: (bytes, offset, length) => writeSync2(descriptor, bytes, offset, length),
29913
- chmod: (bits) => fchmodSync2(descriptor, bits),
29914
- sync: () => fsyncSync2(descriptor),
29915
- close: () => closeSync5(descriptor)
29916
- };
29917
- },
29918
- unlink: unlinkSync4,
29919
- publish: publishAtomicFileSync
29920
- };
29921
- function publishMaybeIdempotentSync(staged, target, mode, options, expectedBytes, io) {
29922
- const publishOptions = {
29923
- replace: options.replace ?? true,
29924
- durability: options.durability ?? "file"
29925
- };
29926
- try {
29927
- io.publish(staged, target, publishOptions);
29928
- return;
29929
- } catch (error) {
29930
- if (options.idempotent !== true || errnoOf(error) !== "EEXIST") {
29931
- throw error;
29932
- }
29933
- const readExisting = io.readExisting ?? ((path, maxBytes) => readBoundedFileSync(path, maxBytes, { rejectSymlinks: true }));
29934
- let existing;
29935
- try {
29936
- existing = readExisting(target, expectedBytes.byteLength);
29937
- } catch (readError) {
29938
- if (isMissing(readError)) {
29939
- io.publish(staged, target, publishOptions);
29940
- return;
29941
- }
29942
- throw error;
29943
- }
29944
- if (!modeMatches(existing.mode, mode) || !bytesEqual(existing.bytes, expectedBytes)) {
29945
- throw error;
29946
- }
29947
- try {
29948
- io.unlink(staged);
29949
- } catch (cleanup) {
29950
- if (!isMissing(cleanup))
29951
- throw new AtomicFilePublicationError2("cleanup", cleanup);
29952
- }
29953
- if (publishOptions.durability === "directory") {
29954
- try {
29955
- const syncDir = io.syncDir ?? syncDirectorySync;
29956
- syncDir(dirname6(target));
29957
- } catch (syncError) {
29958
- throw new AtomicFilePublicationError2("directory-sync", syncError);
29959
- }
29960
- }
29961
- }
29962
- }
29963
- function writeAtomicFileDataSync(target, data, options, io = nativeSync2) {
29964
- assertWriteOptions(options);
29965
- const mode = options.mode ?? DEFAULT_MODE;
29966
- const bytes = bytesOf(data);
29967
- const staged = stagingPath(target);
29968
- const file = io.open(staged, "wx", mode);
29969
- try {
29970
- closeAfterSync(() => file.close(), () => {
29971
- for (let offset = 0;offset < bytes.byteLength; ) {
29972
- const written = file.write(bytes, offset, bytes.byteLength - offset);
29973
- if (written === 0)
29974
- throw new Error("zero-byte atomic-file write");
29975
- offset += written;
29976
- }
29977
- file.chmod(mode);
29978
- if (options.durability !== "none")
29979
- file.sync();
29980
- });
29981
- publishMaybeIdempotentSync(staged, target, mode, options, bytes, io);
29982
- } catch (error) {
29983
- try {
29984
- io.unlink(staged);
29985
- } catch {}
29986
- throw error;
29987
- }
29988
- }
29989
- function writeFileAtomicSync2(target, data, options = {}) {
29990
- writeAtomicFileDataSync(target, data, options);
29991
- }
29992
-
29993
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-agy5fqgf.js
29994
- function assertTimerMs(name, value, options = {}) {
29995
- if (value === undefined && options.absent !== "refused")
29996
- return;
29997
- if (typeof value !== "number") {
29998
- throw new TypeError(`${name} must be a number of milliseconds, received ${String(value)}`);
29999
- }
30000
- const min = options.min ?? 1;
30001
- if (!Number.isSafeInteger(value) || value < min || value > MAX_TIMER_MS) {
30002
- throw new RangeError(`${name} must be an integer from ${min} to ${MAX_TIMER_MS} milliseconds, received ${value}`);
30003
- }
30004
- }
30005
-
30006
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-r97ppg0g.js
30007
- var ManagedFileInspectionSchema = ManagedFileRefSchema2.pick({
30008
- mediaType: true,
30009
- name: true
30010
- });
30011
- var DEFAULT_MAX_BYTES = 100 * 1024 * 1024;
30012
- var DEFAULT_INSPECTION_BYTES = 64 * 1024;
30013
-
30014
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-9pv126eh.js
30021
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-7fjbdga8.js
30015
30022
  var APP_ERROR_BRAND = Symbol.for("stitchkit.AppError");
30016
30023
 
30017
30024
  class AppError2 extends Error {
@@ -30085,6 +30092,7 @@ var STITCH_ERROR_STATUS2 = {
30085
30092
  CONNECTION_TIMEOUT: 504,
30086
30093
  CONNECTION_RESPONSE_TOO_LARGE: 413,
30087
30094
  CONNECTION_REQUEST_FAILED: 502,
30095
+ HTTP_ERROR: 502,
30088
30096
  UPSTREAM_TOOL_ERROR: 502,
30089
30097
  MCP_STRUCTURED_CONTENT_MISSING: 502,
30090
30098
  OPERATION_NOT_SUCCEEDED: 409,
@@ -30100,11 +30108,19 @@ var STITCH_ERROR_STATUS2 = {
30100
30108
  SPILL_REFERENCE_UNKNOWN: 404,
30101
30109
  INTERNAL_SERVER_ERROR: 500
30102
30110
  };
30111
+ function isRetryableStatus2(status) {
30112
+ return status === 408 || status === 429 || status === 502 || status === 503 || status === 504;
30113
+ }
30114
+ var CLIENT_ERROR_CODES2 = [
30115
+ "UNKNOWN_ERROR",
30116
+ "STREAM_TRUNCATED",
30117
+ "STREAM_PROTOCOL_ERROR"
30118
+ ];
30103
30119
  function isStitchErrorCode2(code) {
30104
30120
  return Object.hasOwn(STITCH_ERROR_STATUS2, code);
30105
30121
  }
30106
30122
 
30107
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/files.js
30123
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/files.js
30108
30124
  import { lstatSync as lstatSync4, statSync as statSync3, watch } from "fs";
30109
30125
  import { dirname as dirname7, resolve } from "path";
30110
30126
  var STATUS = {
@@ -31828,7 +31844,7 @@ function flagValue(argv, name) {
31828
31844
 
31829
31845
  // packages/runtime/src/cli/door.ts
31830
31846
  import { existsSync } from "fs";
31831
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-werjqesf.js
31847
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-werjqesf.js
31832
31848
  var OperationEffectSchema2 = _enum(["read", "write"]);
31833
31849
  function parseEndpointEffect(prefix, key, value) {
31834
31850
  const parsed = OperationEffectSchema2.safeParse(value);
@@ -31842,7 +31858,8 @@ function assertEndpointEffect(prefix, key, ep) {
31842
31858
  return;
31843
31859
  parseEndpointEffect(prefix, key, ep.effect);
31844
31860
  }
31845
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-m38ej7e5.js
31861
+
31862
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-m38ej7e5.js
31846
31863
  var PARAM_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
31847
31864
  function joinRoutePath(...parts) {
31848
31865
  const joined = parts.filter((part) => Boolean(part)).map((part) => part.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
@@ -32395,6 +32412,7 @@ var BrokerAdmissionHealthSchema = strictObject({
32395
32412
  });
32396
32413
  var BrokerHealthContractSchema = strictObject({
32397
32414
  ok: boolean2(),
32415
+ brokerVersion: string2().min(1).max(64),
32398
32416
  nodes: array(PresenceSchema).max(MAX_NODES),
32399
32417
  observingSince: string2(),
32400
32418
  transport: TransportObservationSnapshotSchema,
@@ -32516,6 +32534,7 @@ var brokerFleet = BrokerHealthContractSchema.shape.fleet;
32516
32534
  var brokerEvents = BrokerHealthContractSchema.shape.events;
32517
32535
  var brokerTopic = BrokerHealthContractSchema.shape.topics.element;
32518
32536
  var BrokerHealthSchema = BrokerHealthContractSchema.extend({
32537
+ brokerVersion: BrokerHealthContractSchema.shape.brokerVersion.optional(),
32519
32538
  nodes: array(PresenceReaderSchema),
32520
32539
  transport: TransportObservationReaderSchema.optional(),
32521
32540
  audit: AuditStatusSchema2,
@@ -32543,7 +32562,7 @@ var PeerResultSchema = PeerObservationSchema.extend({
32543
32562
  route: PeerObservationSchema.shape.route.unwrap().strip().nullable()
32544
32563
  }).strip();
32545
32564
 
32546
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-akf0xkrm.js
32565
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-78da4g74.js
32547
32566
  var MAX_DETAIL_ISSUES = 20;
32548
32567
  function errorCode2(err) {
32549
32568
  if (AppError2.is(err))
@@ -32640,7 +32659,7 @@ function validateDeclaredOutput(schema, data, onStripped) {
32640
32659
  return validateHandlerOutput(schema, data, onStripped);
32641
32660
  }
32642
32661
 
32643
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-5y7j383h.js
32662
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-yrhw10ef.js
32644
32663
  var DEFAULT_CONTRACT_STREAM_FRAME_BYTES22 = 256 * 1024;
32645
32664
  var ContractStreamErrorSchema = object({
32646
32665
  code: string2(),
@@ -32697,7 +32716,75 @@ function contractStreamLifetimeExceeded() {
32697
32716
  });
32698
32717
  }
32699
32718
 
32700
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-mbd92r1w.js
32719
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-k137ezb6.js
32720
+ var DEADLINE_BUDGET_HEADER22 = "x-stitchkit-timeout-ms";
32721
+ var POSITIVE_INT_RE = /^[1-9]\d{0,15}$/;
32722
+ function parseDeadlineBudgetHeader(raw) {
32723
+ if (raw === null || raw === undefined)
32724
+ return { kind: "absent" };
32725
+ const trimmed = raw.trim();
32726
+ if (trimmed === "0")
32727
+ return { kind: "expired" };
32728
+ if (!POSITIVE_INT_RE.test(trimmed))
32729
+ return { kind: "invalid" };
32730
+ const parsed = Number(trimmed);
32731
+ if (!isPositiveSafeInteger(parsed))
32732
+ return { kind: "invalid" };
32733
+ return { kind: "ok", timeoutMs: clampTimerMs(parsed) };
32734
+ }
32735
+ function resolveServerDeadlineBudget(input) {
32736
+ const parsed = parseDeadlineBudgetHeader(input.headerValue);
32737
+ if (parsed.kind === "expired")
32738
+ return { kind: "expired" };
32739
+ if (parsed.kind === "ok") {
32740
+ const budgetMs = input.endpointTimeoutMs !== undefined ? Math.min(parsed.timeoutMs, input.endpointTimeoutMs) : parsed.timeoutMs;
32741
+ return { kind: "bounded", budgetMs };
32742
+ }
32743
+ if (input.endpointTimeoutMs !== undefined) {
32744
+ return { kind: "bounded", budgetMs: input.endpointTimeoutMs };
32745
+ }
32746
+ return { kind: "unbounded" };
32747
+ }
32748
+ function createRemainingTimeoutReader(deadlineAt) {
32749
+ return (reserveMs) => {
32750
+ if (reserveMs !== undefined) {
32751
+ assertTimerMs("remainingTimeoutMs reserveMs", reserveMs, { min: 0 });
32752
+ }
32753
+ const remaining = Math.floor(deadlineAt - performance.now()) - (reserveMs ?? 0);
32754
+ return Math.max(0, remaining);
32755
+ };
32756
+ }
32757
+ function outboundDeadlineHeaderValue(deadlineAt) {
32758
+ const remaining = Math.ceil(deadlineAt - performance.now());
32759
+ if (remaining <= 0)
32760
+ return "0";
32761
+ return String(clampTimerMs(remaining));
32762
+ }
32763
+ function applyOutboundDeadlineHeader(input, init, deadlineAt) {
32764
+ if (deadlineAt === undefined)
32765
+ return { input, init };
32766
+ if (input instanceof Request) {
32767
+ if (init?.headers !== undefined) {
32768
+ const headers = new Headers(init.headers);
32769
+ if (headers.has(DEADLINE_BUDGET_HEADER22))
32770
+ return { input, init };
32771
+ headers.set(DEADLINE_BUDGET_HEADER22, outboundDeadlineHeaderValue(deadlineAt));
32772
+ return { input: new Request(input, { headers }), init: { ...init, headers } };
32773
+ }
32774
+ if (input.headers.has(DEADLINE_BUDGET_HEADER22))
32775
+ return { input, init };
32776
+ const headers = new Headers(input.headers);
32777
+ headers.set(DEADLINE_BUDGET_HEADER22, outboundDeadlineHeaderValue(deadlineAt));
32778
+ return { input: new Request(input, { headers }), init };
32779
+ }
32780
+ const headers = new Headers(init?.headers);
32781
+ if (!headers.has(DEADLINE_BUDGET_HEADER22)) {
32782
+ headers.set(DEADLINE_BUDGET_HEADER22, outboundDeadlineHeaderValue(deadlineAt));
32783
+ }
32784
+ return { input, init: { ...init, headers } };
32785
+ }
32786
+
32787
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-7mjsb7zv.js
32701
32788
  var CorsOriginDecisionSchema = union([
32702
32789
  literal(false),
32703
32790
  object({ credentials: boolean2() }).strict()
@@ -32745,7 +32832,7 @@ function deniedRequestCors(config) {
32745
32832
  safelistedBody: "refused"
32746
32833
  };
32747
32834
  }
32748
- var DEFAULT_CORS_ALLOW_HEADERS2 = "Content-Type, Authorization, X-Trace-Id, traceparent, tracestate";
32835
+ var DEFAULT_CORS_ALLOW_HEADERS2 = `Content-Type, Authorization, X-Trace-Id, traceparent, tracestate, ${DEADLINE_BUDGET_HEADER22}`;
32749
32836
  var DEFAULT_CORS_EXPOSE_HEADERS2 = "Content-Disposition, Content-Length, Content-Range, Accept-Ranges, ETag, Last-Modified, X-Request-Id, X-Build-Id";
32750
32837
  function assertCorsConfig(config) {
32751
32838
  if (isOriginPolicy(config)) {
@@ -32848,7 +32935,7 @@ function setCorsHeader(headers, key, value) {
32848
32935
  headers.set("Vary", `${existing}, ${value}`);
32849
32936
  }
32850
32937
 
32851
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-4ynw5ktx.js
32938
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-4ynw5ktx.js
32852
32939
  var requests = new WeakMap;
32853
32940
  function isStreamCancellation(error, signal) {
32854
32941
  return signal.aborted && (error === signal.reason || error instanceof Error && error.name === "AbortError" && error.cause === signal.reason);
@@ -32925,7 +33012,7 @@ function createHttpStreamTracker() {
32925
33012
  };
32926
33013
  }
32927
33014
 
32928
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-kyejf658.js
33015
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-kyejf658.js
32929
33016
  function jsonResponse(body, init) {
32930
33017
  const json = JSON.stringify(body);
32931
33018
  if (json === undefined) {
@@ -32938,7 +33025,7 @@ function jsonResponse(body, init) {
32938
33025
  return new Response(json, { ...init, headers });
32939
33026
  }
32940
33027
 
32941
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-t1a2jrg7.js
33028
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-5xsxvk2x.js
32942
33029
  var ShutdownStateSchema2 = _enum([
32943
33030
  "running",
32944
33031
  "draining-http",
@@ -33183,7 +33270,7 @@ function createServerLifecycle(getAdapter) {
33183
33270
  };
33184
33271
  }
33185
33272
 
33186
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-yt1gg11x.js
33273
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-yt1gg11x.js
33187
33274
  var ALL_TRANSPORTS22 = ["HTTP", "MCP", "AGENT", "CLI"];
33188
33275
  var TOOL_TRANSPORTS22 = ["MCP", "AGENT", "CLI"];
33189
33276
  var HTTP_ONLY_FEATURES = [
@@ -33217,7 +33304,44 @@ function assertEndpointExposure(prefix, key, endpoint) {
33217
33304
  }
33218
33305
  }
33219
33306
 
33220
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-ryxb427v.js
33307
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-dxft2mnm.js
33308
+ function assertEndpointRefusals(where, refuses) {
33309
+ if (refuses === undefined)
33310
+ return;
33311
+ if (!Array.isArray(refuses)) {
33312
+ throw new Error(`${where}.refuses must be an array of error factories from defineErrors`);
33313
+ }
33314
+ const seen = new Set;
33315
+ refuses.forEach((entry, index) => {
33316
+ const code = isDeclaration(entry) ? entry.code : undefined;
33317
+ if (code === undefined) {
33318
+ throw new Error(`${where}.refuses[${index}] is not an error factory from defineErrors \u2014 declare the code there and list its factory`);
33319
+ }
33320
+ if (seen.has(code))
33321
+ throw new Error(`${where}.refuses names "${code}" twice`);
33322
+ seen.add(code);
33323
+ });
33324
+ }
33325
+ function isDeclaration(entry) {
33326
+ if (typeof entry !== "function" && (typeof entry !== "object" || entry === null))
33327
+ return false;
33328
+ const code = Reflect.get(entry, "code");
33329
+ const definition = Reflect.get(entry, "definition");
33330
+ return typeof code === "string" && code.length > 0 && typeof definition === "object" && definition !== null && typeof Reflect.get(definition, "status") === "number";
33331
+ }
33332
+ function describeRefusals(refuses) {
33333
+ if (refuses === undefined)
33334
+ return;
33335
+ return Object.freeze(refuses.map(({ code, definition }) => Object.freeze({
33336
+ code,
33337
+ status: definition.status,
33338
+ retryable: definition.retryable ?? isRetryableStatus2(definition.status),
33339
+ ...definition.message !== undefined && { message: definition.message },
33340
+ ...definition.details !== undefined && { details: definition.details }
33341
+ })));
33342
+ }
33343
+
33344
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-by8w2461.js
33221
33345
  function assertMultipartEndpoint(prefix, key, ep) {
33222
33346
  const where = `Contract "${prefix}": multipart endpoint "${key}"`;
33223
33347
  assertNoToolOptions(where, ep);
@@ -33308,7 +33432,8 @@ var TOOL_OPTION_KEYS = {
33308
33432
  ui: true,
33309
33433
  annotations: true,
33310
33434
  mcp: true,
33311
- inputRecursionDepth: true
33435
+ inputRecursionDepth: true,
33436
+ inputNestingDepth: true
33312
33437
  };
33313
33438
  function assertNoUngroupedToolOptions(prefix, key, ep) {
33314
33439
  const where = `Contract "${prefix}": endpoint "${key}"`;
@@ -33329,10 +33454,21 @@ function assertNoUngroupedToolOptions(prefix, key, ep) {
33329
33454
  function assertInputRecursionDepth(where, depth) {
33330
33455
  if (depth === undefined)
33331
33456
  return;
33332
- if (typeof depth !== "number" || !Number.isSafeInteger(depth) || depth < 1) {
33457
+ if (!isPositiveSafeInteger(depth)) {
33333
33458
  throw new Error(`${where} must be a positive integer \u2014 the number of levels each recursive input definition is written out (got ${String(depth)})`);
33334
33459
  }
33335
33460
  }
33461
+ function assertInputNestingDepth(where, depth) {
33462
+ if (depth === undefined)
33463
+ return;
33464
+ if (!isPositiveSafeInteger(depth)) {
33465
+ throw new Error(`${where} must be a positive integer \u2014 the most levels a provider accepts in one input document (got ${String(depth)})`);
33466
+ }
33467
+ }
33468
+ function assertToolDepthOptions(where, tool) {
33469
+ assertInputRecursionDepth(`${where}.inputRecursionDepth`, tool.inputRecursionDepth);
33470
+ assertInputNestingDepth(`${where}.inputNestingDepth`, tool.inputNestingDepth);
33471
+ }
33336
33472
  function assertNoToolOptions(where, ep) {
33337
33473
  if ("tool" in ep && ep.tool !== undefined) {
33338
33474
  throw new Error(`${where} cannot set tool options \u2014 it never reaches a tool transport`);
@@ -33388,7 +33524,7 @@ function assertResponseMetaEndpoint(prefix, key, ep) {
33388
33524
  assertNoToolOptions(where, ep);
33389
33525
  }
33390
33526
 
33391
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-39c2hj6h.js
33527
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-zyyerdny.js
33392
33528
  var DECLARED_TOOL_VIEW = Symbol.for("stitchkit.toolView");
33393
33529
  function objectKeys(schema) {
33394
33530
  return schema instanceof ZodObject ? new Set(Object.keys(schema.shape)) : new Set;
@@ -33454,6 +33590,7 @@ function defineContract22(meta, endpoints) {
33454
33590
  for (const [key, ep] of Object.entries(materializedEndpoints)) {
33455
33591
  assertEndpointExposure(meta.prefix, key, ep);
33456
33592
  assertEndpointEffect(meta.prefix, key, ep);
33593
+ assertEndpointRefusals(`Contract "${meta.prefix}": endpoint "${key}"`, ep.refuses);
33457
33594
  if (ep.desc.trim() === "") {
33458
33595
  throw new Error(`Contract "${meta.prefix}": endpoint "${key}" has an empty desc`);
33459
33596
  }
@@ -33486,7 +33623,7 @@ function defineContract22(meta, endpoints) {
33486
33623
  }
33487
33624
  if (tool.view !== undefined)
33488
33625
  assertToolView(meta.prefix, key, ep);
33489
- assertInputRecursionDepth(`Contract "${meta.prefix}": endpoint "${key}" tool.inputRecursionDepth`, tool.inputRecursionDepth);
33626
+ assertToolDepthOptions(`Contract "${meta.prefix}": endpoint "${key}" tool`, tool);
33490
33627
  if (!tool.name)
33491
33628
  continue;
33492
33629
  const existing = toolTransports.get(tool.name);
@@ -33504,7 +33641,7 @@ function defineContract22(meta, endpoints) {
33504
33641
  return { meta, endpoints: materializedEndpoints };
33505
33642
  }
33506
33643
 
33507
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-p16q492v.js
33644
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-c0yym4a0.js
33508
33645
  var ContractFingerprintSchema22 = strictObject({
33509
33646
  fingerprint: string2(),
33510
33647
  operations: record(string2(), string2())
@@ -33524,16 +33661,440 @@ var ContractFactoryConfigSchema = strictObject({
33524
33661
  toolExposure: ContractFactoryToolExposureSchema
33525
33662
  });
33526
33663
 
33527
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-sx3g49y2.js
33528
- function isModuleNotFound(error) {
33529
- if (typeof error !== "object" || error === null)
33530
- return false;
33531
- const code = errnoOf(error);
33532
- const message = "message" in error && typeof error.message === "string" ? error.message : "";
33533
- return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || message.includes("Cannot find module") || message.includes("Cannot find package");
33664
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-814xpr6d.js
33665
+ function defineRealtimeContract2(contract) {
33666
+ return contract;
33667
+ }
33668
+ var RealtimeRejectDirectionSchema = _enum([
33669
+ "client-inbound",
33670
+ "client-outbound",
33671
+ "server-inbound",
33672
+ "server-outbound"
33673
+ ]);
33674
+ var RealtimeRejectPhaseSchema = _enum(["arguments", "acknowledgement"]);
33675
+ var RealtimeRejectReasonSchema = _enum([
33676
+ "unknown-event",
33677
+ "invalid-arguments",
33678
+ "invalid-acknowledgement-value",
33679
+ "missing-acknowledgement",
33680
+ "rejected-by-peer"
33681
+ ]);
33682
+ var RealtimeRejectFaultSchema = _enum(["peer", "local"]);
33683
+
33684
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-36dmtzjr.js
33685
+ var DevicePresenceErrorCodeSchema2 = _enum([
33686
+ "DEVICE_OFFLINE",
33687
+ "FORBIDDEN",
33688
+ "TIMEOUT",
33689
+ "UNSUPPORTED_CAPABILITY",
33690
+ "HANDLER_ERROR",
33691
+ "INVALID_COMMAND",
33692
+ "DISCONNECTED"
33693
+ ]);
33694
+ var DevicePresenceIdentitySchema2 = strictObject({
33695
+ deviceId: string2().min(1),
33696
+ name: string2().min(1),
33697
+ platform: string2().min(1)
33698
+ });
33699
+ var DevicePresenceRelayStateSchema2 = strictObject({
33700
+ status: _enum(["idle", "registering", "online", "disconnected", "refused", "closed"]),
33701
+ deviceId: string2().min(1),
33702
+ capabilities: array(string2().min(1)),
33703
+ leaseExpiresAt: number2().int().positive().optional()
33704
+ });
33705
+ var StateUpdateAckSchema = discriminatedUnion("outcome", [
33706
+ strictObject({
33707
+ schemaVersion: literal(1),
33708
+ outcome: literal("ok"),
33709
+ revision: number2().int().nonnegative()
33710
+ }),
33711
+ strictObject({
33712
+ schemaVersion: literal(1),
33713
+ outcome: literal("error"),
33714
+ code: DevicePresenceErrorCodeSchema2,
33715
+ message: string2().min(1)
33716
+ })
33717
+ ]);
33718
+ var CommandResultSchema = discriminatedUnion("outcome", [
33719
+ strictObject({
33720
+ schemaVersion: literal(1),
33721
+ commandId: string2().min(1),
33722
+ outcome: literal("ok"),
33723
+ result: unknown().optional()
33724
+ }),
33725
+ strictObject({
33726
+ schemaVersion: literal(1),
33727
+ commandId: string2().min(1),
33728
+ outcome: literal("error"),
33729
+ code: DevicePresenceErrorCodeSchema2,
33730
+ message: string2().min(1)
33731
+ })
33732
+ ]);
33733
+
33734
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-4s0fep5q.js
33735
+ var RealtimeRequestPhaseSchema2 = _enum([
33736
+ "engine-handoff",
33737
+ "engine-ack-received",
33738
+ "settled",
33739
+ "timeout",
33740
+ "disconnected"
33741
+ ]);
33742
+ var RealtimeRequestPhaseEventSchema2 = object({
33743
+ requestId: string2().min(1),
33744
+ event: string2().min(1),
33745
+ phase: RealtimeRequestPhaseSchema2,
33746
+ elapsedMs: number2().nonnegative()
33747
+ }).strict();
33748
+
33749
+ class RealtimeRequestTimeoutError2 extends Error {
33750
+ code = "REALTIME_REQUEST_TIMEOUT";
33751
+ event;
33752
+ timeoutMs;
33753
+ constructor(event, timeoutMs) {
33754
+ super(`Realtime request "${event}" timed out after ${timeoutMs}ms`);
33755
+ this.name = "RealtimeRequestTimeoutError";
33756
+ this.event = event;
33757
+ this.timeoutMs = timeoutMs;
33758
+ }
33759
+ }
33760
+
33761
+ class RealtimeRequestDisconnectedError2 extends Error {
33762
+ code = "REALTIME_REQUEST_DISCONNECTED";
33763
+ event;
33764
+ constructor(event) {
33765
+ super(`Realtime request "${event}" was interrupted by disconnect`);
33766
+ this.name = "RealtimeRequestDisconnectedError";
33767
+ this.event = event;
33768
+ }
33769
+ }
33770
+
33771
+ class RealtimeRequestInvalidAcknowledgementError2 extends Error {
33772
+ code = "REALTIME_REQUEST_INVALID_ACKNOWLEDGEMENT";
33773
+ event;
33774
+ constructor(event, cause) {
33775
+ super(`Realtime request "${event}" received an invalid acknowledgement`, { cause });
33776
+ this.name = "RealtimeRequestInvalidAcknowledgementError";
33777
+ this.event = event;
33778
+ }
33779
+ }
33780
+
33781
+ class RealtimeRequestRejectedError2 extends Error {
33782
+ code = "REALTIME_REQUEST_REJECTED";
33783
+ event;
33784
+ reason;
33785
+ issues;
33786
+ constructor(event, reason, detail, issues) {
33787
+ super(`Realtime request "${event}" was rejected by the peer (${reason}): ${detail}`);
33788
+ this.name = "RealtimeRequestRejectedError";
33789
+ this.event = event;
33790
+ this.reason = reason;
33791
+ this.issues = issues;
33792
+ }
33793
+ }
33794
+
33795
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-0k1ba0ss.js
33796
+ var REALTIME_REJECTION_KEY2 = "@stitchkit/realtime-rejected";
33797
+ var MAX_REJECTION_ISSUES = 20;
33798
+ function realtimeRejectionEnvelope(report) {
33799
+ return { [REALTIME_REJECTION_KEY2]: report };
33800
+ }
33801
+ function asRealtimeRejection2(value) {
33802
+ if (typeof value !== "object" || value === null)
33803
+ return null;
33804
+ const report = Reflect.get(value, REALTIME_REJECTION_KEY2);
33805
+ if (typeof report !== "object" || report === null)
33806
+ return null;
33807
+ const event = Reflect.get(report, "event");
33808
+ const reason = Reflect.get(report, "reason");
33809
+ const message = Reflect.get(report, "message");
33810
+ if (typeof event !== "string" || typeof reason !== "string" || typeof message !== "string") {
33811
+ return null;
33812
+ }
33813
+ if (reason.length === 0)
33814
+ return null;
33815
+ const issues = parseIssues(Reflect.get(report, "issues"));
33816
+ return { event, reason, message, ...issues !== undefined && { issues } };
33817
+ }
33818
+ function parseIssues(value) {
33819
+ if (!Array.isArray(value))
33820
+ return;
33821
+ const issues = [];
33822
+ for (const entry of value.slice(0, MAX_REJECTION_ISSUES)) {
33823
+ if (typeof entry !== "object" || entry === null)
33824
+ continue;
33825
+ const path = Reflect.get(entry, "path");
33826
+ const code = Reflect.get(entry, "code");
33827
+ const message = Reflect.get(entry, "message");
33828
+ if (typeof path === "string" && typeof code === "string" && typeof message === "string") {
33829
+ const branch = Reflect.get(entry, "branch");
33830
+ issues.push({
33831
+ path,
33832
+ code,
33833
+ message,
33834
+ ...typeof branch === "number" && Number.isInteger(branch) && branch > 0 && { branch }
33835
+ });
33836
+ }
33837
+ }
33838
+ return issues.length > 0 ? issues : undefined;
33839
+ }
33840
+ function realtimeContractViolation(options) {
33841
+ const issues = options.cause instanceof ZodError ? zodIssues2(options.cause) : undefined;
33842
+ const reason = options.reason.replaceAll("-", " ");
33843
+ const error = new AppError2("REALTIME_CONTRACT_VIOLATION", {
33844
+ message: `Realtime event "${options.event}" (${options.direction}, ${options.phase}): ${reason}`,
33845
+ status: 500,
33846
+ details: {
33847
+ event: options.event,
33848
+ direction: options.direction,
33849
+ phase: options.phase,
33850
+ reason: options.reason,
33851
+ fault: options.fault,
33852
+ ...issues !== undefined && { issues }
33853
+ }
33854
+ });
33855
+ if (options.cause !== undefined)
33856
+ error.cause = options.cause;
33857
+ return { ...options, error };
33858
+ }
33859
+ function method(target, name) {
33860
+ const value = Reflect.get(target, name);
33861
+ if (typeof value !== "function") {
33862
+ throw new Error(`Realtime target does not implement ${name}()`);
33863
+ }
33864
+ return (...args) => Reflect.apply(value, target, args);
33865
+ }
33866
+ function splitWireArguments(definition, args) {
33867
+ const trailing = args.at(-1);
33868
+ const replyTo = typeof trailing === "function" ? (...callbackArgs) => Reflect.apply(trailing, undefined, callbackArgs) : undefined;
33869
+ if (!definition.ack || !replyTo)
33870
+ return { values: args, ...replyTo && { replyTo } };
33871
+ return { values: args.slice(0, -1), acknowledgement: replyTo, replyTo };
33872
+ }
33873
+ function eventDefinition(registry, event, direction) {
33874
+ const definition = registry[event];
33875
+ if (!definition) {
33876
+ throw realtimeContractViolation({
33877
+ event,
33878
+ direction,
33879
+ phase: "arguments",
33880
+ reason: "unknown-event",
33881
+ fault: "local"
33882
+ }).error;
33883
+ }
33884
+ return definition;
33885
+ }
33886
+ function reportRejected(rejected, hook, logger) {
33887
+ if (!hook) {
33888
+ if (logger) {
33889
+ logger.warn(rejected.error.message, rejected.error.details);
33890
+ return;
33891
+ }
33892
+ console.warn(`[stitchkit] rejected realtime ${rejected.direction} event "${rejected.event}" (${rejected.phase})`, rejected.error);
33893
+ return;
33894
+ }
33895
+ Promise.resolve(hook(rejected)).catch((error) => {
33896
+ console.error("[stitchkit] realtime rejection hook failed", error);
33897
+ });
33898
+ }
33899
+ function answerWithRejection(acknowledgement, report, logger) {
33900
+ if (!acknowledgement)
33901
+ return;
33902
+ try {
33903
+ acknowledgement(realtimeRejectionEnvelope(report));
33904
+ } catch (error) {
33905
+ const message = "[stitchkit] could not answer a rejected realtime frame";
33906
+ if (logger)
33907
+ logger.warn(message, { error });
33908
+ else
33909
+ console.warn(message, error);
33910
+ }
33911
+ }
33912
+ function parseRealtimeRequestArguments(registry, event, direction, args) {
33913
+ const definition = eventDefinition(registry, event, direction);
33914
+ const parsed = definition.args.safeParse(args);
33915
+ if (!parsed.success) {
33916
+ throw realtimeContractViolation({
33917
+ event,
33918
+ direction,
33919
+ phase: "arguments",
33920
+ reason: "invalid-arguments",
33921
+ fault: "local",
33922
+ cause: parsed.error
33923
+ }).error;
33924
+ }
33925
+ if (!definition.ack) {
33926
+ throw realtimeContractViolation({
33927
+ event,
33928
+ direction,
33929
+ phase: "acknowledgement",
33930
+ reason: "missing-acknowledgement",
33931
+ fault: "local"
33932
+ }).error;
33933
+ }
33934
+ return parsed.data;
33935
+ }
33936
+ function parseRealtimeRequestAcknowledgement(schema, event, direction, value, hook, logger) {
33937
+ const refusal = asRealtimeRejection2(value);
33938
+ if (refusal) {
33939
+ reportRejected(realtimeContractViolation({
33940
+ event,
33941
+ direction,
33942
+ phase: "arguments",
33943
+ reason: "rejected-by-peer",
33944
+ fault: "local"
33945
+ }), hook, logger);
33946
+ throw new RealtimeRequestRejectedError2(event, refusal.reason, refusal.message, refusal.issues);
33947
+ }
33948
+ const parsed = schema.safeParse(value);
33949
+ if (parsed.success)
33950
+ return parsed.data;
33951
+ const rejected = realtimeContractViolation({
33952
+ event,
33953
+ direction,
33954
+ phase: "acknowledgement",
33955
+ reason: "invalid-acknowledgement-value",
33956
+ fault: "peer",
33957
+ cause: parsed.error
33958
+ });
33959
+ reportRejected(rejected, hook, logger);
33960
+ throw new RealtimeRequestInvalidAcknowledgementError2(event, rejected.error);
33961
+ }
33962
+ function createValidatedRealtimeSocket({
33963
+ target,
33964
+ inbound,
33965
+ outbound,
33966
+ inboundDirection,
33967
+ outboundDirection,
33968
+ onRejected,
33969
+ logger,
33970
+ subscribe
33971
+ }) {
33972
+ const emitTarget = method(target, "emit");
33973
+ return {
33974
+ on: (event, handler) => {
33975
+ const definition = eventDefinition(inbound, event, inboundDirection);
33976
+ const wrapped = (...wireArgs) => {
33977
+ const { values, acknowledgement, replyTo } = splitWireArguments(definition, wireArgs);
33978
+ const parsed = definition.args.safeParse(values);
33979
+ if (!parsed.success) {
33980
+ const rejected = realtimeContractViolation({
33981
+ event,
33982
+ direction: inboundDirection,
33983
+ phase: "arguments",
33984
+ reason: "invalid-arguments",
33985
+ fault: "peer",
33986
+ cause: parsed.error
33987
+ });
33988
+ reportRejected(rejected, onRejected, logger);
33989
+ answerWithRejection(replyTo, {
33990
+ event,
33991
+ reason: "invalid-arguments",
33992
+ message: rejected.error.message,
33993
+ issues: zodIssues2(parsed.error).slice(0, MAX_REJECTION_ISSUES)
33994
+ }, logger);
33995
+ return;
33996
+ }
33997
+ if (definition.ack && !acknowledgement) {
33998
+ reportRejected(realtimeContractViolation({
33999
+ event,
34000
+ direction: inboundDirection,
34001
+ phase: "acknowledgement",
34002
+ reason: "missing-acknowledgement",
34003
+ fault: "peer"
34004
+ }), onRejected, logger);
34005
+ return;
34006
+ }
34007
+ const applicationArgs = [...parsed.data];
34008
+ if (definition.ack) {
34009
+ applicationArgs.push((value) => {
34010
+ const ack = definition.ack?.safeParse(value);
34011
+ if (!ack?.success) {
34012
+ if (ack) {
34013
+ reportRejected(realtimeContractViolation({
34014
+ event,
34015
+ direction: outboundDirection,
34016
+ phase: "acknowledgement",
34017
+ reason: "invalid-acknowledgement-value",
34018
+ fault: "local",
34019
+ cause: ack.error
34020
+ }), onRejected, logger);
34021
+ }
34022
+ return;
34023
+ }
34024
+ acknowledgement?.(ack.data);
34025
+ });
34026
+ }
34027
+ Reflect.apply(handler, undefined, applicationArgs);
34028
+ };
34029
+ if (subscribe)
34030
+ return subscribe(event, wrapped);
34031
+ const onTarget = method(target, "on");
34032
+ const offTarget = method(target, "off");
34033
+ onTarget(event, wrapped);
34034
+ return () => {
34035
+ offTarget(event, wrapped);
34036
+ };
34037
+ },
34038
+ emit: (event, ...args) => {
34039
+ const definition = eventDefinition(outbound, event, outboundDirection);
34040
+ const { values, acknowledgement } = splitWireArguments(definition, args);
34041
+ const parsed = definition.args.safeParse(values);
34042
+ if (!parsed.success) {
34043
+ throw realtimeContractViolation({
34044
+ event,
34045
+ direction: outboundDirection,
34046
+ phase: "arguments",
34047
+ reason: "invalid-arguments",
34048
+ fault: "local",
34049
+ cause: parsed.error
34050
+ }).error;
34051
+ }
34052
+ if (definition.ack && !acknowledgement) {
34053
+ throw realtimeContractViolation({
34054
+ event,
34055
+ direction: outboundDirection,
34056
+ phase: "acknowledgement",
34057
+ reason: "missing-acknowledgement",
34058
+ fault: "local"
34059
+ }).error;
34060
+ }
34061
+ const wireArgs = [...parsed.data];
34062
+ if (definition.ack && acknowledgement) {
34063
+ wireArgs.push((value) => {
34064
+ const refusal = asRealtimeRejection2(value);
34065
+ if (refusal) {
34066
+ reportRejected(realtimeContractViolation({
34067
+ event,
34068
+ direction: outboundDirection,
34069
+ phase: "arguments",
34070
+ reason: "rejected-by-peer",
34071
+ fault: "local"
34072
+ }), onRejected, logger);
34073
+ return;
34074
+ }
34075
+ const ack = definition.ack?.safeParse(value);
34076
+ if (!ack?.success) {
34077
+ if (ack) {
34078
+ reportRejected(realtimeContractViolation({
34079
+ event,
34080
+ direction: inboundDirection,
34081
+ phase: "acknowledgement",
34082
+ reason: "invalid-acknowledgement-value",
34083
+ fault: "peer",
34084
+ cause: ack.error
34085
+ }), onRejected, logger);
34086
+ }
34087
+ return;
34088
+ }
34089
+ acknowledgement(ack.data);
34090
+ });
34091
+ }
34092
+ return emitTarget(event, ...wireArgs) !== false;
34093
+ }
34094
+ };
33534
34095
  }
33535
34096
 
33536
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-jb4m241t.js
34097
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-fthw8dwa.js
33537
34098
  function mergeMeta(contractMeta, endpointMeta) {
33538
34099
  if (!contractMeta)
33539
34100
  return endpointMeta;
@@ -33553,6 +34114,7 @@ function contractMethodFields(contract, key, endpoint) {
33553
34114
  expose: endpoint.expose ?? (isHttpOnlyEndpoint(endpoint) ? HTTP_ONLY_EXPOSURE : undefined),
33554
34115
  scope: endpoint.scope ?? groupScope,
33555
34116
  effect: endpoint.effect,
34117
+ refuses: describeRefusals(endpoint.refuses),
33556
34118
  paramsSchema: resolveRouteParamsSchema(endpoint.path, endpoint.params),
33557
34119
  inputSchema: endpoint.input,
33558
34120
  outputSchema: endpoint.output,
@@ -33560,11 +34122,13 @@ function contractMethodFields(contract, key, endpoint) {
33560
34122
  stream: "stream" in endpoint ? endpoint.stream : undefined,
33561
34123
  multipart: endpoint.multipart,
33562
34124
  maxJsonBodyBytes: endpoint.maxJsonBodyBytes,
34125
+ timeout: endpoint.timeout,
33563
34126
  idempotent: endpoint.idempotent,
33564
34127
  ui: endpoint.tool?.ui,
33565
34128
  annotations: endpoint.tool?.annotations,
33566
34129
  mcp: endpoint.tool?.mcp,
33567
34130
  inputRecursionDepth: endpoint.tool?.inputRecursionDepth,
34131
+ inputNestingDepth: endpoint.tool?.inputNestingDepth,
33568
34132
  meta: mergeMeta(contract.meta.meta, endpoint.meta),
33569
34133
  rawResponse: endpoint.rawResponse,
33570
34134
  rawBody: endpoint.rawBody,
@@ -33573,8 +34137,43 @@ function contractMethodFields(contract, key, endpoint) {
33573
34137
  contentType: "contentType" in endpoint ? endpoint.contentType : undefined
33574
34138
  };
33575
34139
  }
34140
+ function isAsyncIterable2(value) {
34141
+ return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
34142
+ }
34143
+ function withDeclaredRefusals(endpoint, label, handler) {
34144
+ const declared = endpoint.refuses;
34145
+ if (declared === undefined)
34146
+ return handler;
34147
+ const codes = new Set(declared.map((refusal) => refusal.code));
34148
+ const held = (error) => {
34149
+ if (!(error instanceof AppError2) || codes.has(error.code) || isStitchErrorCode2(error.code))
34150
+ return error;
34151
+ const refused = new AppError2("INTERNAL_SERVER_ERROR", {
34152
+ message: `Operation ${label} failed with a code it does not declare`,
34153
+ status: 500
34154
+ });
34155
+ refused.cause = error;
34156
+ return refused;
34157
+ };
34158
+ async function* streamed(source) {
34159
+ try {
34160
+ yield* source;
34161
+ } catch (error) {
34162
+ throw held(error);
34163
+ }
34164
+ }
34165
+ return async (ctx) => {
34166
+ let result;
34167
+ try {
34168
+ result = await handler(ctx);
34169
+ } catch (error) {
34170
+ throw held(error);
34171
+ }
34172
+ return "stream" in endpoint && isAsyncIterable2(result) ? streamed(result) : result;
34173
+ };
34174
+ }
33576
34175
 
33577
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-wa6h4tz6.js
34176
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-6nzzj7qr.js
33578
34177
  function isStreamingImplementation(value) {
33579
34178
  return typeof value === "object" && value !== null && "kind" in value && value.kind === "stitchkit.multipart.stream";
33580
34179
  }
@@ -33608,12 +34207,12 @@ function bindContract(contract, handlers, options) {
33608
34207
  methods[String(key)] = {
33609
34208
  ...contractMethodFields(contract, String(key), endpoint),
33610
34209
  multipartReceivers: streamingHandler?.receivers,
33611
- handler: streamingHandler ? (ctx) => streamingHandler.execute(ctx, ctx.files ?? {}) : (ctx) => {
34210
+ handler: withDeclaredRefusals(endpoint, `${contract.meta.prefix}.${String(key)}`, streamingHandler ? (ctx) => streamingHandler.execute(ctx, ctx.files ?? {}) : (ctx) => {
33612
34211
  if (!regularHandler) {
33613
34212
  throw new Error(`[stitchkit] implement: missing handler for "${contract.meta.prefix}.${String(key)}"`);
33614
34213
  }
33615
34214
  return callRuntimeHandler(regularHandler, ctx);
33616
- }
34215
+ })
33617
34216
  };
33618
34217
  }
33619
34218
  return {
@@ -33627,7 +34226,7 @@ function implement2(contract, handlers, options) {
33627
34226
  return bindContract(contract, handlers, options);
33628
34227
  }
33629
34228
 
33630
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-5q0qpw3v.js
34229
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-5q0qpw3v.js
33631
34230
  function generateTraceId2() {
33632
34231
  return `${Date.now().toString(36)}-${randomHex(4)}`;
33633
34232
  }
@@ -33721,7 +34320,7 @@ function parseQueryParams(url) {
33721
34320
  return query;
33722
34321
  }
33723
34322
 
33724
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-y7sy1xdp.js
34323
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-y7sy1xdp.js
33725
34324
  var TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(.*)$/i;
33726
34325
  function createTraceContext2() {
33727
34326
  return { traceId: randomHex(16), spanId: randomHex(8) };
@@ -33750,7 +34349,7 @@ function resolveTraceContext2(req) {
33750
34349
  return parseTraceparent2(req.headers.get("traceparent")) ?? createTraceContext2();
33751
34350
  }
33752
34351
 
33753
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-x6sp5vpa.js
34352
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-x6sp5vpa.js
33754
34353
  var NO_AMBIENT_STORAGE = {
33755
34354
  run: (_store, callback) => callback(),
33756
34355
  getStore: () => {
@@ -33800,7 +34399,16 @@ function setRequestEndpoint2(serviceName, action) {
33800
34399
  }
33801
34400
  }
33802
34401
 
33803
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-877e9y8r.js
34402
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-sx3g49y2.js
34403
+ function isModuleNotFound(error) {
34404
+ if (typeof error !== "object" || error === null)
34405
+ return false;
34406
+ const code = errnoOf(error);
34407
+ const message = "message" in error && typeof error.message === "string" ? error.message : "";
34408
+ return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || message.includes("Cannot find module") || message.includes("Cannot find package");
34409
+ }
34410
+
34411
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-sk03xe0n.js
33804
34412
  function isReadableByteStream(value) {
33805
34413
  return isRecord(value) && typeof value.getReader === "function";
33806
34414
  }
@@ -33877,7 +34485,7 @@ async function* chunksOf(source, signal) {
33877
34485
  }
33878
34486
  }
33879
34487
 
33880
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-827bgv33.js
34488
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-f16b7rze.js
33881
34489
  async function readBoundedChunks(source, options) {
33882
34490
  options.signal?.throwIfAborted();
33883
34491
  const chunks = [];
@@ -33984,7 +34592,7 @@ async function readBoundedText(source, options) {
33984
34592
  return { kind: "complete", text };
33985
34593
  }
33986
34594
 
33987
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-z9d74jmb.js
34595
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-fec05c9k.js
33988
34596
  import { Agent, request as httpRequest } from "http";
33989
34597
  var DEFAULT_PARSE_BODY_BYTES = 1024 * 1024;
33990
34598
  var LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "[::1]"]);
@@ -35036,7 +35644,7 @@ function createUnixClientTransport2(config) {
35036
35644
  };
35037
35645
  }
35038
35646
 
35039
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-27hck3z2.js
35647
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-9be3tf6r.js
35040
35648
  var P = (kind, help, reason, extra) => ({
35041
35649
  kind,
35042
35650
  readMcp: "preserved",
@@ -35187,6 +35795,8 @@ var SCHEMA_MAP_KEYWORDS = entries.filter(([, meta]) => meta.subschema === "map")
35187
35795
  var TYPE_DEFINING_KEYWORDS = entries.filter(([, meta]) => meta.typesValue === true).map(([name]) => name);
35188
35796
  var HELP_SHOWN_KEYWORDS = new Set(entries.filter(([, meta]) => meta.help === "shown").map(([name]) => name));
35189
35797
  var REMOTE_STRIPPED_KEYWORDS = new Set(entries.filter(([, meta]) => meta.stripLocally === true).map(([name]) => name));
35798
+
35799
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-gk6dq9ay.js
35190
35800
  var STANDARD_STRING_FORMATS = new Set([
35191
35801
  "date-time",
35192
35802
  "date",
@@ -35210,373 +35820,10 @@ var STANDARD_STRING_FORMATS = new Set([
35210
35820
  ]);
35211
35821
  var readerExpressions = new Map;
35212
35822
 
35213
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-4s0fep5q.js
35214
- var RealtimeRequestPhaseSchema2 = _enum([
35215
- "engine-handoff",
35216
- "engine-ack-received",
35217
- "settled",
35218
- "timeout",
35219
- "disconnected"
35220
- ]);
35221
- var RealtimeRequestPhaseEventSchema2 = object({
35222
- requestId: string2().min(1),
35223
- event: string2().min(1),
35224
- phase: RealtimeRequestPhaseSchema2,
35225
- elapsedMs: number2().nonnegative()
35226
- }).strict();
35227
-
35228
- class RealtimeRequestTimeoutError2 extends Error {
35229
- code = "REALTIME_REQUEST_TIMEOUT";
35230
- event;
35231
- timeoutMs;
35232
- constructor(event, timeoutMs) {
35233
- super(`Realtime request "${event}" timed out after ${timeoutMs}ms`);
35234
- this.name = "RealtimeRequestTimeoutError";
35235
- this.event = event;
35236
- this.timeoutMs = timeoutMs;
35237
- }
35238
- }
35239
-
35240
- class RealtimeRequestDisconnectedError2 extends Error {
35241
- code = "REALTIME_REQUEST_DISCONNECTED";
35242
- event;
35243
- constructor(event) {
35244
- super(`Realtime request "${event}" was interrupted by disconnect`);
35245
- this.name = "RealtimeRequestDisconnectedError";
35246
- this.event = event;
35247
- }
35248
- }
35249
-
35250
- class RealtimeRequestInvalidAcknowledgementError2 extends Error {
35251
- code = "REALTIME_REQUEST_INVALID_ACKNOWLEDGEMENT";
35252
- event;
35253
- constructor(event, cause) {
35254
- super(`Realtime request "${event}" received an invalid acknowledgement`, { cause });
35255
- this.name = "RealtimeRequestInvalidAcknowledgementError";
35256
- this.event = event;
35257
- }
35258
- }
35259
-
35260
- class RealtimeRequestRejectedError2 extends Error {
35261
- code = "REALTIME_REQUEST_REJECTED";
35262
- event;
35263
- reason;
35264
- issues;
35265
- constructor(event, reason, detail, issues) {
35266
- super(`Realtime request "${event}" was rejected by the peer (${reason}): ${detail}`);
35267
- this.name = "RealtimeRequestRejectedError";
35268
- this.event = event;
35269
- this.reason = reason;
35270
- this.issues = issues;
35271
- }
35272
- }
35273
-
35274
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-0r15pkjq.js
35275
- var REALTIME_REJECTION_KEY2 = "@stitchkit/realtime-rejected";
35276
- var MAX_REJECTION_ISSUES = 20;
35277
- function realtimeRejectionEnvelope(report) {
35278
- return { [REALTIME_REJECTION_KEY2]: report };
35279
- }
35280
- function asRealtimeRejection2(value) {
35281
- if (typeof value !== "object" || value === null)
35282
- return null;
35283
- const report = Reflect.get(value, REALTIME_REJECTION_KEY2);
35284
- if (typeof report !== "object" || report === null)
35285
- return null;
35286
- const event = Reflect.get(report, "event");
35287
- const reason = Reflect.get(report, "reason");
35288
- const message = Reflect.get(report, "message");
35289
- if (typeof event !== "string" || typeof reason !== "string" || typeof message !== "string") {
35290
- return null;
35291
- }
35292
- if (reason.length === 0)
35293
- return null;
35294
- const issues = parseIssues(Reflect.get(report, "issues"));
35295
- return { event, reason, message, ...issues !== undefined && { issues } };
35296
- }
35297
- function parseIssues(value) {
35298
- if (!Array.isArray(value))
35299
- return;
35300
- const issues = [];
35301
- for (const entry of value.slice(0, MAX_REJECTION_ISSUES)) {
35302
- if (typeof entry !== "object" || entry === null)
35303
- continue;
35304
- const path = Reflect.get(entry, "path");
35305
- const code = Reflect.get(entry, "code");
35306
- const message = Reflect.get(entry, "message");
35307
- if (typeof path === "string" && typeof code === "string" && typeof message === "string") {
35308
- const branch = Reflect.get(entry, "branch");
35309
- issues.push({
35310
- path,
35311
- code,
35312
- message,
35313
- ...typeof branch === "number" && Number.isInteger(branch) && branch > 0 && { branch }
35314
- });
35315
- }
35316
- }
35317
- return issues.length > 0 ? issues : undefined;
35318
- }
35319
- function realtimeContractViolation(options) {
35320
- const issues = options.cause instanceof ZodError ? zodIssues2(options.cause) : undefined;
35321
- const reason = options.reason.replaceAll("-", " ");
35322
- const error = new AppError2("REALTIME_CONTRACT_VIOLATION", {
35323
- message: `Realtime event "${options.event}" (${options.direction}, ${options.phase}): ${reason}`,
35324
- status: 500,
35325
- details: {
35326
- event: options.event,
35327
- direction: options.direction,
35328
- phase: options.phase,
35329
- reason: options.reason,
35330
- fault: options.fault,
35331
- ...issues !== undefined && { issues }
35332
- }
35333
- });
35334
- if (options.cause !== undefined)
35335
- error.cause = options.cause;
35336
- return { ...options, error };
35337
- }
35338
- function method(target, name) {
35339
- const value = Reflect.get(target, name);
35340
- if (typeof value !== "function") {
35341
- throw new Error(`Realtime target does not implement ${name}()`);
35342
- }
35343
- return (...args) => Reflect.apply(value, target, args);
35344
- }
35345
- function splitWireArguments(definition, args) {
35346
- const trailing = args.at(-1);
35347
- const replyTo = typeof trailing === "function" ? (...callbackArgs) => Reflect.apply(trailing, undefined, callbackArgs) : undefined;
35348
- if (!definition.ack || !replyTo)
35349
- return { values: args, ...replyTo && { replyTo } };
35350
- return { values: args.slice(0, -1), acknowledgement: replyTo, replyTo };
35351
- }
35352
- function eventDefinition(registry, event, direction) {
35353
- const definition = registry[event];
35354
- if (!definition) {
35355
- throw realtimeContractViolation({
35356
- event,
35357
- direction,
35358
- phase: "arguments",
35359
- reason: "unknown-event",
35360
- fault: "local"
35361
- }).error;
35362
- }
35363
- return definition;
35364
- }
35365
- function reportRejected(rejected, hook, logger) {
35366
- if (!hook) {
35367
- if (logger) {
35368
- logger.warn(rejected.error.message, rejected.error.details);
35369
- return;
35370
- }
35371
- console.warn(`[stitchkit] rejected realtime ${rejected.direction} event "${rejected.event}" (${rejected.phase})`, rejected.error);
35372
- return;
35373
- }
35374
- Promise.resolve(hook(rejected)).catch((error) => {
35375
- console.error("[stitchkit] realtime rejection hook failed", error);
35376
- });
35377
- }
35378
- function answerWithRejection(acknowledgement, report, logger) {
35379
- if (!acknowledgement)
35380
- return;
35381
- try {
35382
- acknowledgement(realtimeRejectionEnvelope(report));
35383
- } catch (error) {
35384
- const message = "[stitchkit] could not answer a rejected realtime frame";
35385
- if (logger)
35386
- logger.warn(message, { error });
35387
- else
35388
- console.warn(message, error);
35389
- }
35390
- }
35391
- function parseRealtimeRequestArguments(registry, event, direction, args) {
35392
- const definition = eventDefinition(registry, event, direction);
35393
- const parsed = definition.args.safeParse(args);
35394
- if (!parsed.success) {
35395
- throw realtimeContractViolation({
35396
- event,
35397
- direction,
35398
- phase: "arguments",
35399
- reason: "invalid-arguments",
35400
- fault: "local",
35401
- cause: parsed.error
35402
- }).error;
35403
- }
35404
- if (!definition.ack) {
35405
- throw realtimeContractViolation({
35406
- event,
35407
- direction,
35408
- phase: "acknowledgement",
35409
- reason: "missing-acknowledgement",
35410
- fault: "local"
35411
- }).error;
35412
- }
35413
- return parsed.data;
35414
- }
35415
- function parseRealtimeRequestAcknowledgement(schema, event, direction, value, hook, logger) {
35416
- const refusal = asRealtimeRejection2(value);
35417
- if (refusal) {
35418
- reportRejected(realtimeContractViolation({
35419
- event,
35420
- direction,
35421
- phase: "arguments",
35422
- reason: "rejected-by-peer",
35423
- fault: "local"
35424
- }), hook, logger);
35425
- throw new RealtimeRequestRejectedError2(event, refusal.reason, refusal.message, refusal.issues);
35426
- }
35427
- const parsed = schema.safeParse(value);
35428
- if (parsed.success)
35429
- return parsed.data;
35430
- const rejected = realtimeContractViolation({
35431
- event,
35432
- direction,
35433
- phase: "acknowledgement",
35434
- reason: "invalid-acknowledgement-value",
35435
- fault: "peer",
35436
- cause: parsed.error
35437
- });
35438
- reportRejected(rejected, hook, logger);
35439
- throw new RealtimeRequestInvalidAcknowledgementError2(event, rejected.error);
35440
- }
35441
- function createValidatedRealtimeSocket({
35442
- target,
35443
- inbound,
35444
- outbound,
35445
- inboundDirection,
35446
- outboundDirection,
35447
- onRejected,
35448
- logger,
35449
- subscribe
35450
- }) {
35451
- const emitTarget = method(target, "emit");
35452
- return {
35453
- on: (event, handler) => {
35454
- const definition = eventDefinition(inbound, event, inboundDirection);
35455
- const wrapped = (...wireArgs) => {
35456
- const { values, acknowledgement, replyTo } = splitWireArguments(definition, wireArgs);
35457
- const parsed = definition.args.safeParse(values);
35458
- if (!parsed.success) {
35459
- const rejected = realtimeContractViolation({
35460
- event,
35461
- direction: inboundDirection,
35462
- phase: "arguments",
35463
- reason: "invalid-arguments",
35464
- fault: "peer",
35465
- cause: parsed.error
35466
- });
35467
- reportRejected(rejected, onRejected, logger);
35468
- answerWithRejection(replyTo, {
35469
- event,
35470
- reason: "invalid-arguments",
35471
- message: rejected.error.message,
35472
- issues: zodIssues2(parsed.error).slice(0, MAX_REJECTION_ISSUES)
35473
- }, logger);
35474
- return;
35475
- }
35476
- if (definition.ack && !acknowledgement) {
35477
- reportRejected(realtimeContractViolation({
35478
- event,
35479
- direction: inboundDirection,
35480
- phase: "acknowledgement",
35481
- reason: "missing-acknowledgement",
35482
- fault: "peer"
35483
- }), onRejected, logger);
35484
- return;
35485
- }
35486
- const applicationArgs = [...parsed.data];
35487
- if (definition.ack) {
35488
- applicationArgs.push((value) => {
35489
- const ack = definition.ack?.safeParse(value);
35490
- if (!ack?.success) {
35491
- if (ack) {
35492
- reportRejected(realtimeContractViolation({
35493
- event,
35494
- direction: outboundDirection,
35495
- phase: "acknowledgement",
35496
- reason: "invalid-acknowledgement-value",
35497
- fault: "local",
35498
- cause: ack.error
35499
- }), onRejected, logger);
35500
- }
35501
- return;
35502
- }
35503
- acknowledgement?.(ack.data);
35504
- });
35505
- }
35506
- Reflect.apply(handler, undefined, applicationArgs);
35507
- };
35508
- if (subscribe)
35509
- return subscribe(event, wrapped);
35510
- const onTarget = method(target, "on");
35511
- const offTarget = method(target, "off");
35512
- onTarget(event, wrapped);
35513
- return () => {
35514
- offTarget(event, wrapped);
35515
- };
35516
- },
35517
- emit: (event, ...args) => {
35518
- const definition = eventDefinition(outbound, event, outboundDirection);
35519
- const { values, acknowledgement } = splitWireArguments(definition, args);
35520
- const parsed = definition.args.safeParse(values);
35521
- if (!parsed.success) {
35522
- throw realtimeContractViolation({
35523
- event,
35524
- direction: outboundDirection,
35525
- phase: "arguments",
35526
- reason: "invalid-arguments",
35527
- fault: "local",
35528
- cause: parsed.error
35529
- }).error;
35530
- }
35531
- if (definition.ack && !acknowledgement) {
35532
- throw realtimeContractViolation({
35533
- event,
35534
- direction: outboundDirection,
35535
- phase: "acknowledgement",
35536
- reason: "missing-acknowledgement",
35537
- fault: "local"
35538
- }).error;
35539
- }
35540
- const wireArgs = [...parsed.data];
35541
- if (definition.ack && acknowledgement) {
35542
- wireArgs.push((value) => {
35543
- const refusal = asRealtimeRejection2(value);
35544
- if (refusal) {
35545
- reportRejected(realtimeContractViolation({
35546
- event,
35547
- direction: outboundDirection,
35548
- phase: "arguments",
35549
- reason: "rejected-by-peer",
35550
- fault: "local"
35551
- }), onRejected, logger);
35552
- return;
35553
- }
35554
- const ack = definition.ack?.safeParse(value);
35555
- if (!ack?.success) {
35556
- if (ack) {
35557
- reportRejected(realtimeContractViolation({
35558
- event,
35559
- direction: inboundDirection,
35560
- phase: "acknowledgement",
35561
- reason: "invalid-acknowledgement-value",
35562
- fault: "peer",
35563
- cause: ack.error
35564
- }), onRejected, logger);
35565
- }
35566
- return;
35567
- }
35568
- acknowledgement(ack.data);
35569
- });
35570
- }
35571
- return emitTarget(event, ...wireArgs) !== false;
35572
- }
35573
- };
35574
- }
35575
-
35576
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-9kpxz49v.js
35823
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-kgkevngs.js
35577
35824
  var DEFAULT_MAX_BYTES2 = 64 * 1024 * 1024;
35578
35825
 
35579
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-sv5svtq7.js
35826
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-y68gavb5.js
35580
35827
  function bindRealtimeServer2(contract, handle, options = {}) {
35581
35828
  const outbound = (target) => createValidatedRealtimeSocket({
35582
35829
  target,
@@ -35625,21 +35872,21 @@ function bindRealtimeServer2(contract, handle, options = {}) {
35625
35872
  };
35626
35873
  }
35627
35874
 
35628
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-n15jny5b.js
35875
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-n15jny5b.js
35629
35876
  var RELEASE_HEADER2 = "X-Build-Id";
35630
35877
 
35631
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-cfnmvcq8.js
35878
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-cfnmvcq8.js
35632
35879
  var protocolOutcomes = new WeakSet;
35633
35880
  function isProtocolOutcome(response) {
35634
35881
  return protocolOutcomes.has(response);
35635
35882
  }
35636
35883
 
35637
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-zs8cze4j.js
35884
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-zs8cze4j.js
35638
35885
  function mediaTypeEssence(contentType) {
35639
35886
  return (contentType ?? "").split(";", 1)[0]?.trim().toLowerCase() ?? "";
35640
35887
  }
35641
35888
 
35642
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-z20pdxeb.js
35889
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-m2b49tvc.js
35643
35890
  var LOGGER_METHODS = ["info", "warn", "error", "debug"];
35644
35891
  function isBareLogger(value) {
35645
35892
  if (value.logger !== undefined || value.skip !== undefined || value.enrich !== undefined) {
@@ -36071,6 +36318,7 @@ var RUNTIME_CONTEXT_RESERVED_KEYS = new Set([
36071
36318
  "ipAddress",
36072
36319
  "userAgent",
36073
36320
  "signal",
36321
+ "remainingTimeoutMs",
36074
36322
  "toolCallId",
36075
36323
  "mcp",
36076
36324
  "reportProgress"
@@ -37105,6 +37353,29 @@ async function dataEndpointResponse(state, request, {
37105
37353
  request.complete(responseStatus);
37106
37354
  return body;
37107
37355
  }
37356
+ function forwardAbortSignal(sourceSignal, target) {
37357
+ if (sourceSignal.aborted) {
37358
+ target.abort(sourceSignal.reason);
37359
+ return () => {
37360
+ return;
37361
+ };
37362
+ }
37363
+ const onAbort = () => {
37364
+ target.abort(sourceSignal.reason);
37365
+ };
37366
+ sourceSignal.addEventListener("abort", onAbort, { once: true });
37367
+ return () => sourceSignal.removeEventListener("abort", onAbort);
37368
+ }
37369
+ function closeLateStreamSource(value) {
37370
+ if (!isAsyncIterable(value))
37371
+ return;
37372
+ try {
37373
+ const iterator = value[Symbol.asyncIterator]();
37374
+ Promise.resolve(iterator.return?.(undefined)).catch(() => {
37375
+ return;
37376
+ });
37377
+ } catch {}
37378
+ }
37108
37379
  async function dispatchEndpoint(state, request, match) {
37109
37380
  const { hooks, config } = state;
37110
37381
  const { req, url, traceId, clientIp } = request;
@@ -37115,8 +37386,51 @@ async function dispatchEndpoint(state, request, match) {
37115
37386
  activeContext.serviceName = method.serviceName;
37116
37387
  activeContext.action = method.key;
37117
37388
  }
37389
+ let deadlineTimer;
37390
+ let deadlineLink;
37391
+ let deadlineController;
37392
+ let releaseStreamReq;
37393
+ let releaseStreamOpenDeadline;
37394
+ let streamOpened = false;
37395
+ let keepRawBodySignalLink = false;
37396
+ const disarmDeadlineTimer = () => {
37397
+ if (deadlineTimer !== undefined) {
37398
+ clearTimeout(deadlineTimer);
37399
+ deadlineTimer = undefined;
37400
+ }
37401
+ };
37402
+ const releaseOpenDeadline = () => {
37403
+ disarmDeadlineTimer();
37404
+ if (!keepRawBodySignalLink) {
37405
+ deadlineLink?.release();
37406
+ deadlineLink = undefined;
37407
+ }
37408
+ releaseStreamOpenDeadline?.();
37409
+ releaseStreamOpenDeadline = undefined;
37410
+ };
37118
37411
  let multipartLifecycle;
37119
37412
  try {
37413
+ const budget = resolveServerDeadlineBudget({
37414
+ headerValue: req.headers.get(DEADLINE_BUDGET_HEADER22),
37415
+ endpointTimeoutMs: method.timeout
37416
+ });
37417
+ let activeDeadlineReader;
37418
+ if (budget.kind === "bounded") {
37419
+ const deadlineAt = performance.now() + budget.budgetMs;
37420
+ deadlineController = new AbortController;
37421
+ deadlineTimer = setTimeout(() => {
37422
+ deadlineController?.abort(abortError("Request deadline exceeded", "TimeoutError"));
37423
+ }, budget.budgetMs);
37424
+ deadlineTimer.unref?.();
37425
+ deadlineLink = linkAbortSignals(req.signal, deadlineController.signal);
37426
+ ctx.signal = deadlineLink.signal;
37427
+ activeDeadlineReader = createRemainingTimeoutReader(deadlineAt);
37428
+ ctx.remainingTimeoutMs = (reserveMs) => activeDeadlineReader?.(reserveMs);
37429
+ } else if (budget.kind === "expired") {
37430
+ ctx.remainingTimeoutMs = () => 0;
37431
+ } else {
37432
+ ctx.remainingTimeoutMs = (reserveMs) => activeDeadlineReader?.(reserveMs);
37433
+ }
37120
37434
  parsePathParamsInto(ctx, method);
37121
37435
  if (hooks?.authorize) {
37122
37436
  await hooks.authorize(ctx, method);
@@ -37124,6 +37438,12 @@ async function dispatchEndpoint(state, request, match) {
37124
37438
  if (groupHooks?.authorize) {
37125
37439
  await groupHooks.authorize(ctx, method);
37126
37440
  }
37441
+ if (budget.kind === "expired") {
37442
+ throw new AppError2("REQUEST_TIMEOUT", {
37443
+ status: 408,
37444
+ message: "Request deadline budget exhausted"
37445
+ });
37446
+ }
37127
37447
  try {
37128
37448
  multipartLifecycle = await parseRequestPayloadInto(ctx, req, url, method, config.maxJsonBodyBytes, request.cors);
37129
37449
  } catch (payloadError) {
@@ -37143,26 +37463,55 @@ async function dispatchEndpoint(state, request, match) {
37143
37463
  ctx.response = responseMetadata;
37144
37464
  const streamAbort = method.stream ? new AbortController : undefined;
37145
37465
  if (streamAbort) {
37146
- if (req.signal.aborted)
37147
- streamAbort.abort(req.signal.reason);
37148
- else {
37149
- req.signal.addEventListener("abort", () => streamAbort.abort(req.signal.reason), {
37150
- once: true
37151
- });
37152
- }
37466
+ releaseStreamReq = forwardAbortSignal(req.signal, streamAbort);
37467
+ if (deadlineController && !streamAbort.signal.aborted) {
37468
+ releaseStreamOpenDeadline = forwardAbortSignal(deadlineController.signal, streamAbort);
37469
+ }
37470
+ streamAbort.signal.addEventListener("abort", () => {
37471
+ releaseStreamReq?.();
37472
+ releaseStreamReq = undefined;
37473
+ releaseStreamOpenDeadline?.();
37474
+ releaseStreamOpenDeadline = undefined;
37475
+ }, { once: true });
37153
37476
  ctx.signal = streamAbort.signal;
37154
37477
  }
37155
37478
  const result = await method.handler(ctx);
37156
- return await endpointResponse(state, request, {
37479
+ if (method.stream) {
37480
+ if (deadlineController?.signal.aborted && !req.signal.aborted) {
37481
+ closeLateStreamSource(result);
37482
+ throw new AppError2("REQUEST_TIMEOUT", {
37483
+ status: 408,
37484
+ message: "Request deadline exceeded"
37485
+ });
37486
+ }
37487
+ releaseOpenDeadline();
37488
+ activeDeadlineReader = method.stream.lifetimeMs !== undefined ? createRemainingTimeoutReader(performance.now() + method.stream.lifetimeMs) : undefined;
37489
+ }
37490
+ const response = await endpointResponse(state, request, {
37157
37491
  ctx,
37158
37492
  match,
37159
37493
  result,
37160
37494
  responseMetadata,
37161
37495
  streamAbort
37162
37496
  });
37497
+ if (streamAbort && !streamAbort.signal.aborted) {
37498
+ streamOpened = true;
37499
+ }
37500
+ if (method.rawResponse && response.body !== null && !req.signal.aborted && !deadlineController?.signal.aborted) {
37501
+ disarmDeadlineTimer();
37502
+ activeDeadlineReader = undefined;
37503
+ keepRawBodySignalLink = true;
37504
+ }
37505
+ return response;
37163
37506
  } catch (err) {
37164
37507
  await multipartLifecycle?.rollback();
37165
37508
  return request.respondError(err, ctx, method, groupHooks);
37509
+ } finally {
37510
+ releaseOpenDeadline();
37511
+ if (!streamOpened) {
37512
+ releaseStreamReq?.();
37513
+ releaseStreamReq = undefined;
37514
+ }
37166
37515
  }
37167
37516
  }
37168
37517
  var MAX_REQUEST_ABORT_CAUSE_DEPTH = 8;
@@ -37666,12 +38015,12 @@ async function dispatch(state, req, url, traceId, server, clientIp, startedAt, c
37666
38015
  return dispatchEndpoint(state, request, match);
37667
38016
  }
37668
38017
 
37669
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-xhzq2qvj.js
38018
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-xhzq2qvj.js
37670
38019
  function inputIsQuery(method) {
37671
38020
  return method === "GET" || method === "DELETE";
37672
38021
  }
37673
38022
 
37674
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/server.js
38023
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/server.js
37675
38024
  import { lstatSync as lstatSync6 } from "fs";
37676
38025
  var authorizedRoom = Symbol("stitchkit.authorized-room");
37677
38026
  var ProtocolSchema = _enum(["http", "https"]);
@@ -38025,6 +38374,7 @@ function createServer(config) {
38025
38374
  shutdown: lifecycle.shutdown
38026
38375
  };
38027
38376
  }
38377
+ var registryAuxIndex = new WeakMap;
38028
38378
  var scopedAuthHookBrand = Symbol("stitchkit.scoped-auth-hook");
38029
38379
  var authOwnershipPlans = new WeakMap;
38030
38380
  var MAX_SIGNED_LINK_SECONDS = 7 * 24 * 60 * 60;
@@ -38052,7 +38402,7 @@ var OpenApiSecuritySchema = strictObject({
38052
38402
  defaultScope: string2().min(1).optional()
38053
38403
  });
38054
38404
 
38055
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-gnjgkecx.js
38405
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-q46b16xz.js
38056
38406
  var RetryPauseSchema = number2().int().positive().max(MAX_TIMER_MS);
38057
38407
  var BackoffPolicySchema2 = object({
38058
38408
  minDelayMs: RetryPauseSchema,
@@ -38067,7 +38417,7 @@ function backoffDelay(policy, attempt, random = Math.random) {
38067
38417
  return Math.max(1, Math.round(exponential - spread));
38068
38418
  }
38069
38419
 
38070
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-kfjkb396.js
38420
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-kfjkb396.js
38071
38421
  var API_ERROR_BRAND = Symbol.for("stitchkit.ApiError");
38072
38422
  function messageForCode(code, message) {
38073
38423
  return message !== undefined && message.length > 0 ? message : `${code} (no message supplied)`;
@@ -40049,7 +40399,25 @@ var createInstance = (defaults) => {
40049
40399
  };
40050
40400
  var ky = createInstance();
40051
40401
 
40052
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-jcge9tx3.js
40402
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-cgjtj8zh.js
40403
+ function searchParamsOf(params) {
40404
+ const searchParams = new URLSearchParams;
40405
+ let hasParams = false;
40406
+ for (const [key, value] of Object.entries(params)) {
40407
+ if (value === undefined)
40408
+ continue;
40409
+ if (Array.isArray(value)) {
40410
+ for (const item of value) {
40411
+ searchParams.append(key, String(item));
40412
+ hasParams = true;
40413
+ }
40414
+ } else {
40415
+ searchParams.set(key, String(value));
40416
+ hasParams = true;
40417
+ }
40418
+ }
40419
+ return hasParams ? searchParams.toString() : undefined;
40420
+ }
40053
40421
  class BridgeFailureError2 extends TypeError {
40054
40422
  code;
40055
40423
  constructor(code, message) {
@@ -40135,6 +40503,10 @@ function createRequestCancellation(caller, timeoutMs) {
40135
40503
  function cancellationError(origin, cause) {
40136
40504
  return new RequestCancellationError(origin, cause);
40137
40505
  }
40506
+ var REQUEST_ID_HEADER = "x-request-id";
40507
+ function responseTraceId(response) {
40508
+ return response?.headers.get(REQUEST_ID_HEADER) ?? undefined;
40509
+ }
40138
40510
  var NATIVE_FETCH_SOURCE = /^function fetch\(\)\s*\{\s*\[native code\]\s*\}$/;
40139
40511
  function isNativeBunFetch(candidate) {
40140
40512
  const bun = Reflect.get(globalThis, "Bun");
@@ -40153,10 +40525,6 @@ function resolveClientFetch(explicitFetch) {
40153
40525
  return transport(input, nativeInit);
40154
40526
  };
40155
40527
  }
40156
- var REQUEST_ID_HEADER = "x-request-id";
40157
- function responseTraceId(response) {
40158
- return response?.headers.get(REQUEST_ID_HEADER) ?? undefined;
40159
- }
40160
40528
  var PIECE_BYTES = 64 * 1024;
40161
40529
  function isReactNative() {
40162
40530
  return Reflect.get(globalThis.navigator ?? {}, "product") === "ReactNative";
@@ -40409,7 +40777,7 @@ function parseApiErrorBody(body) {
40409
40777
  };
40410
40778
  }
40411
40779
 
40412
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-09f7w2qq.js
40780
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-02kdtrcd.js
40413
40781
  var PositiveSafeIntegerSchema = number2().int().positive().safe();
40414
40782
  var BoundedChannelPolicySchema2 = _enum(["ordered", "latest"]);
40415
40783
  var BoundedChannelStateSchema2 = _enum(["open", "draining", "closed", "failed"]);
@@ -40610,7 +40978,7 @@ var CreditWindowSnapshotSchema2 = object({
40610
40978
  waiting: number2().int().nonnegative()
40611
40979
  }).strict().readonly();
40612
40980
 
40613
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-vgytj9wp.js
40981
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-jmaw365j.js
40614
40982
  var PositiveSafeIntegerSchema2 = number2().int().positive().safe();
40615
40983
  var LiveStatePhaseSchema2 = _enum([
40616
40984
  "idle",
@@ -40642,27 +41010,7 @@ var LiveStateControllerStatusSchema2 = object({
40642
41010
  reason: LiveStateStopReasonSchema2.optional()
40643
41011
  }).strict().readonly();
40644
41012
 
40645
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-814xpr6d.js
40646
- function defineRealtimeContract2(contract) {
40647
- return contract;
40648
- }
40649
- var RealtimeRejectDirectionSchema = _enum([
40650
- "client-inbound",
40651
- "client-outbound",
40652
- "server-inbound",
40653
- "server-outbound"
40654
- ]);
40655
- var RealtimeRejectPhaseSchema = _enum(["arguments", "acknowledgement"]);
40656
- var RealtimeRejectReasonSchema = _enum([
40657
- "unknown-event",
40658
- "invalid-arguments",
40659
- "invalid-acknowledgement-value",
40660
- "missing-acknowledgement",
40661
- "rejected-by-peer"
40662
- ]);
40663
- var RealtimeRejectFaultSchema = _enum(["peer", "local"]);
40664
-
40665
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-ycr4pk0z.js
41013
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-42n9jycn.js
40666
41014
  var DEFAULT_REPEAT_WINDOW_MS2 = 60000;
40667
41015
  var DEFAULT_REPEAT_MAX_KINDS2 = 256;
40668
41016
  var MAX_KEY_DEPTH = 4;
@@ -40896,7 +41244,7 @@ function repeatLimited2(logger, options = {}) {
40896
41244
  };
40897
41245
  }
40898
41246
 
40899
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-39rmc00v.js
41247
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-mfe9a266.js
40900
41248
  var DEFAULT_STREAM_LINE_BYTES = 1024 * 1024;
40901
41249
 
40902
41250
  class StreamLineLimitError2 extends RangeError {
@@ -41003,7 +41351,7 @@ async function* readBoundedUtf8Lines(source, maxLineBytes, requireFinalNewline =
41003
41351
  }
41004
41352
  }
41005
41353
 
41006
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-gya4hwh3.js
41354
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-asnd4h2k.js
41007
41355
  function endpointHasArguments(endpoint) {
41008
41356
  return Boolean(endpoint.params || endpoint.input || endpoint.multipart);
41009
41357
  }
@@ -41086,16 +41434,8 @@ function stripConsumedArgs(args, path, scopeKeys) {
41086
41434
  function appendQuery(relativeUrl, params) {
41087
41435
  if (!params)
41088
41436
  return relativeUrl;
41089
- const search = new URLSearchParams;
41090
- for (const [key, value] of Object.entries(params)) {
41091
- if (Array.isArray(value)) {
41092
- for (const item of value)
41093
- search.append(key, String(item));
41094
- } else {
41095
- search.set(key, String(value));
41096
- }
41097
- }
41098
- return search.size > 0 ? `${relativeUrl}?${search}` : relativeUrl;
41437
+ const query = searchParamsOf(params);
41438
+ return query ? `${relativeUrl}?${query}` : relativeUrl;
41099
41439
  }
41100
41440
  function planClientRequest(endpoint, contractPrefix, args, config) {
41101
41441
  let pathPrefix = resolvePathPrefix(config, args);
@@ -41193,12 +41533,26 @@ function readClientRequestArgs(requestArgs) {
41193
41533
  function readClientRequestOptions(endpoint, value) {
41194
41534
  if (!isRecord(value))
41195
41535
  throw new TypeError("Client request options must be an object");
41196
- const { signal, onUploadProgress } = value;
41536
+ const { signal, timeout, propagateDeadline, onUploadProgress } = value;
41197
41537
  if (signal !== undefined && !isAbortSignal(signal)) {
41198
41538
  throw new TypeError("Client request signal must be an AbortSignal");
41199
41539
  }
41540
+ if (timeout !== undefined) {
41541
+ if (typeof timeout !== "number") {
41542
+ throw new TypeError("Client request timeout must be a number");
41543
+ }
41544
+ assertTimerMs("HTTP request timeout", timeout);
41545
+ }
41546
+ if (propagateDeadline !== undefined && typeof propagateDeadline !== "boolean") {
41547
+ throw new TypeError("Client request propagateDeadline must be a boolean");
41548
+ }
41549
+ const base = {
41550
+ ...signal !== undefined && { signal },
41551
+ ...typeof timeout === "number" && { timeout },
41552
+ ...propagateDeadline !== undefined && { propagateDeadline }
41553
+ };
41200
41554
  if (onUploadProgress === undefined)
41201
- return signal === undefined ? {} : { signal };
41555
+ return base;
41202
41556
  if (typeof onUploadProgress !== "function") {
41203
41557
  throw new TypeError("Client request onUploadProgress must be a function");
41204
41558
  }
@@ -41206,7 +41560,7 @@ function readClientRequestOptions(endpoint, value) {
41206
41560
  throw new TypeError(`${endpoint.method} ${endpoint.path}: onUploadProgress needs a request body \u2014 ` + "a GET, HEAD or DELETE sends none, and a streaming endpoint keeps its response live, " + "which the XMLHttpRequest route would buffer.");
41207
41561
  }
41208
41562
  return {
41209
- ...signal !== undefined && { signal },
41563
+ ...base,
41210
41564
  onUploadProgress: (progress) => {
41211
41565
  onUploadProgress(progress);
41212
41566
  }
@@ -41450,11 +41804,12 @@ function contractResponseType(endpoint) {
41450
41804
  function withTimeout2(options, endpoint) {
41451
41805
  const responseType = contractResponseType(endpoint);
41452
41806
  const idempotent = declaredReplay(endpoint);
41453
- if (endpoint.timeout === undefined && responseType === undefined && idempotent === undefined)
41807
+ const effectiveTimeout = options?.timeout ?? endpoint.timeout;
41808
+ if (effectiveTimeout === undefined && responseType === undefined && idempotent === undefined)
41454
41809
  return options;
41455
41810
  return {
41456
41811
  ...options,
41457
- ...endpoint.timeout !== undefined && { timeout: endpoint.timeout },
41812
+ ...effectiveTimeout !== undefined && { timeout: effectiveTimeout },
41458
41813
  ...responseType && { responseType },
41459
41814
  ...idempotent !== undefined && { idempotent }
41460
41815
  };
@@ -41557,16 +41912,23 @@ function createFetchExecutor(endpoint, prefix, config, contractConfig) {
41557
41912
  const progressRoute = options?.onUploadProgress ? uploadProgressRoute(config.fetch !== undefined) : undefined;
41558
41913
  const streamAbort = "stream" in endpoint ? new AbortController : undefined;
41559
41914
  const callerSignal = streamAbort && options?.signal ? linkAbortSignals(options.signal, streamAbort.signal).signal : streamAbort?.signal ?? options?.signal;
41560
- const openTimeoutMs = endpoint.timeout ?? config.timeout ?? 30000;
41915
+ const openTimeoutMs = options?.timeout ?? endpoint.timeout ?? config.timeout ?? 30000;
41561
41916
  const cancellation = createRequestCancellation(callerSignal, openTimeoutMs);
41917
+ const shouldPropagateDeadline = options?.propagateDeadline ?? config.propagateDeadline ?? false;
41918
+ const deadlineAt = shouldPropagateDeadline ? performance.now() + openTimeoutMs : undefined;
41919
+ const hasCallerDeadlineHeader = Object.keys(headers).some((key) => key.toLowerCase() === DEADLINE_BUDGET_HEADER22);
41562
41920
  const bodyLifetime = endpoint.rawResponse || streamAbort ? "handed-out" : "read";
41563
41921
  try {
41564
41922
  const value = await cancellation.run(async (signal) => {
41565
41923
  const body = endpoint.multipart ? buildMultipartForm(endpoint.multipart, plan.remainingArgs) : hasBody ? JSON.stringify(plan.remainingArgs) : undefined;
41566
- const deliver = options?.onUploadProgress && progressRoute ? withUploadProgress(executeFetch, options.onUploadProgress, {
41924
+ const baseDeliver = options?.onUploadProgress && progressRoute ? withUploadProgress(executeFetch, options.onUploadProgress, {
41567
41925
  route: progressRoute,
41568
41926
  responseType: contractResponseType(endpoint)
41569
41927
  }) : executeFetch;
41928
+ const deliver = deadlineAt !== undefined && !hasCallerDeadlineHeader ? (targetUrl, reqInit) => {
41929
+ const next = applyOutboundDeadlineHeader(targetUrl, reqInit, deadlineAt);
41930
+ return baseDeliver(next.input, next.init);
41931
+ } : baseDeliver;
41570
41932
  const res = await deliverWithReplay(deliver, url, {
41571
41933
  method: endpoint.method,
41572
41934
  headers,
@@ -41633,6 +41995,18 @@ async function throwForErrorResponse(res, config, fallbackBody) {
41633
41995
  traceId: responseTraceId(res)
41634
41996
  });
41635
41997
  }
41998
+ var CLIENT_CODES = new Set(CLIENT_ERROR_CODES2);
41999
+ function readOperationRefusal(endpoint, error) {
42000
+ if (!ApiError2.is(error))
42001
+ return;
42002
+ const declared = endpoint.refuses?.find((refusal) => refusal.code === error.code);
42003
+ if (declared === undefined)
42004
+ return isStitchErrorCode2(error.code) || CLIENT_CODES.has(error.code) ? error : undefined;
42005
+ const schema = declared.definition.details;
42006
+ if (schema === undefined)
42007
+ return error;
42008
+ return schema.safeParse(error.details).success ? error : undefined;
42009
+ }
41636
42010
  function isRoutingRefusal(error) {
41637
42011
  if (error.code === "UNKNOWN_OPERATION")
41638
42012
  return true;
@@ -41677,6 +42051,7 @@ function createEndpointMethod(endpoint, execute, bound) {
41677
42051
  });
41678
42052
  const method = (requestArgs) => settle2(execute, readArgs(requestArgs), undefined);
41679
42053
  return Object.assign(method, {
42054
+ refusal: (error) => readOperationRefusal(endpoint, error),
41680
42055
  withOptions: (...args) => {
41681
42056
  refuseExtraWithOptionsArguments(endpoint, args.length, 2);
41682
42057
  return settle2(execute, readArgs(args[0]), readClientRequestOptions(endpoint, args[1]));
@@ -41685,6 +42060,7 @@ function createEndpointMethod(endpoint, execute, bound) {
41685
42060
  }
41686
42061
  const method = () => settle2(execute, { ...bound.values }, undefined);
41687
42062
  return Object.assign(method, {
42063
+ refusal: (error) => readOperationRefusal(endpoint, error),
41688
42064
  withOptions: (...args) => {
41689
42065
  refuseExtraWithOptionsArguments(endpoint, args.length, 1);
41690
42066
  return settle2(execute, { ...bound.values }, readClientRequestOptions(endpoint, args[0]));
@@ -41699,7 +42075,7 @@ function settle2(execute, requestArgs, options) {
41699
42075
  }
41700
42076
  }
41701
42077
 
41702
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-nk0cy9g1.js
42078
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-033tyx59.js
41703
42079
  var realtimeRequestTraces = new WeakMap;
41704
42080
  function observeRealtimeRequestPhase(trace, phase) {
41705
42081
  const observation = {
@@ -41910,7 +42286,7 @@ function bindRealtimeClient2(contract, transport, { onRejected, logger } = {}) {
41910
42286
  };
41911
42287
  }
41912
42288
 
41913
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-xq4s9mka.js
42289
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-n2t87ggz.js
41914
42290
  function createRetainedTopics2() {
41915
42291
  const last = {};
41916
42292
  return {
@@ -42225,7 +42601,7 @@ function createSocketIOClientInternal(config, defaultIo, onRequestPhase) {
42225
42601
  };
42226
42602
  }
42227
42603
 
42228
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/index.js
42604
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/index.js
42229
42605
  var SOCKET_IO_CLIENT = "socket.io-client";
42230
42606
  var ioLoader = null;
42231
42607
  function loadDefaultIo() {
@@ -42289,7 +42665,7 @@ function localError(error, delivery) {
42289
42665
  return new WireClientError("transport", "Local Wire connection failed", delivery, { cause: error });
42290
42666
  }
42291
42667
 
42292
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-t3qcac2a.js
42668
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-w3s79kcb.js
42293
42669
  var DEFAULT_BRIDGE_MAX_FRAME_BYTES2 = 1024 * 1024;
42294
42670
  var BridgeHeaderEntrySchema2 = tuple([string2(), string2()]);
42295
42671
  var BridgeFailureCodeSchema2 = _enum([
@@ -42357,7 +42733,7 @@ var TEXTUAL_APPLICATION_TYPES = new Set([
42357
42733
  ]);
42358
42734
  var STREAMING_TYPES = new Set(["text/event-stream", "application/x-ndjson"]);
42359
42735
 
42360
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/http.js
42736
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/http.js
42361
42737
  var MAX_WINDOW_INSTANCE_LENGTH = 128;
42362
42738
  var MAX_ID_LITERAL = MAX_WINDOW_INSTANCE_LENGTH * 6 + 1 + 16;
42363
42739
  var REPLY_HEAD_PREFIX = '{"v":1,"kind":"response","id":';
@@ -42826,7 +43202,7 @@ function createFeed(session, path, body, parse, terminal, signal, durationMs, co
42826
43202
  return feed;
42827
43203
  }
42828
43204
 
42829
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-13wmzpa6.js
43205
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-7an2fs5h.js
42830
43206
  var NonNegativeIntegerSchema = number2().int().nonnegative();
42831
43207
  var ObservabilitySinkStatusSchema2 = object({
42832
43208
  capacity: NonNegativeIntegerSchema,
@@ -42852,7 +43228,7 @@ var ObservabilityDrainReportSchema2 = ObservabilityStatusObjectSchema.extend({
42852
43228
  drained: boolean2()
42853
43229
  }).readonly();
42854
43230
 
42855
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-w5s3xftz.js
43231
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-w5s3xftz.js
42856
43232
  var ApplicationIdSchema2 = string2().min(1).max(128).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]*$/);
42857
43233
  var ApplicationLifecycleSchema2 = _enum([
42858
43234
  "created",
@@ -42953,7 +43329,7 @@ var ApplicationShutdownResultSchema2 = object({
42953
43329
  durationMs: number2().nonnegative()
42954
43330
  }).readonly();
42955
43331
 
42956
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-yrr3n391.js
43332
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-ry8m2mhg.js
42957
43333
  var SnapshotRevisionSchema = number2().int().nonnegative();
42958
43334
  var ApplicationSnapshotSinkStatusSchema2 = object({
42959
43335
  accepting: boolean2(),
@@ -43037,7 +43413,7 @@ var ManagedScheduleStatusSchema2 = object({
43037
43413
  lastFinishedAt: string2().datetime({ offset: true }).nullable()
43038
43414
  }).readonly();
43039
43415
 
43040
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-6g85s734.js
43416
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-6g85s734.js
43041
43417
  var DiagnosticJournalFrameSchema2 = object({
43042
43418
  schemaVersion: literal(1),
43043
43419
  epoch: uuid2(),
@@ -43210,7 +43586,7 @@ function readDiagnosticJournalLockDiagnosis2(error) {
43210
43586
  return isRecord(diagnosis) ? diagnosis : undefined;
43211
43587
  }
43212
43588
 
43213
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-msfpyy2f.js
43589
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-msfpyy2f.js
43214
43590
  var timestamp2 = string2().datetime({ offset: true });
43215
43591
  var key = string2().min(1).max(255);
43216
43592
  var DirectoryInboxIdentitySchema2 = object({ source: string2().min(1).max(128), key: string2().min(1).max(1024) }).strict();
@@ -43244,7 +43620,7 @@ var DirectoryInboxStateSchema2 = object({
43244
43620
  }).strict())
43245
43621
  }).strict();
43246
43622
 
43247
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-50ejfz75.js
43623
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-50ejfz75.js
43248
43624
  function managedResourceDependencyId2(dependency) {
43249
43625
  return typeof dependency === "string" ? dependency : dependency.id;
43250
43626
  }
@@ -43252,7 +43628,7 @@ function defineManagedResource2(resource) {
43252
43628
  return resource;
43253
43629
  }
43254
43630
 
43255
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-jxtg307y.js
43631
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-6p5pshcd.js
43256
43632
  var ApplicationShutdownOptionsSchema2 = ShutdownOptionsSchema2.pick({
43257
43633
  gracePeriodMs: true,
43258
43634
  forceTimeoutMs: true,
@@ -44208,7 +44584,7 @@ function createApplication2(config) {
44208
44584
  };
44209
44585
  }
44210
44586
 
44211
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-zwgwyvdt.js
44587
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-pdcbjd6a.js
44212
44588
  var WatchDeltaSchema2 = lazy(() => union([
44213
44589
  object({ t: literal("set"), v: unknown() }),
44214
44590
  object({
@@ -44280,7 +44656,7 @@ var watchContract2 = {
44280
44656
  }
44281
44657
  };
44282
44658
 
44283
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-sznqf8fx.js
44659
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-sznqf8fx.js
44284
44660
  var BOT_TOKEN_SECRET = /(?<=\d{5,}:)[A-Za-z0-9_-]{30,}/;
44285
44661
  var URL_PASSWORD = /(\b[a-z][a-z0-9+.-]*:\/\/[^\s/?#@:"'<>]*:)([^\s/?#@"'<>]+)(?=@)/gi;
44286
44662
  var QUERY_PARAMETER = /([?&;])([^=&#\s"'<>]+)=([^&#\s"'<>]*)/g;
@@ -44299,7 +44675,7 @@ function maskSecretShapes(input, mask, isSecretName) {
44299
44675
  });
44300
44676
  }
44301
44677
 
44302
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-xtby8rj3.js
44678
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-xtby8rj3.js
44303
44679
  var SENSITIVE_WORDS = new Set([
44304
44680
  "password",
44305
44681
  "passwords",
@@ -44605,7 +44981,7 @@ function measureSize2(value) {
44605
44981
  return { resultSize: null, responseBytes };
44606
44982
  }
44607
44983
 
44608
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/application.js
44984
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/application.js
44609
44985
  function pruneRate(samples, intervalMs, at) {
44610
44986
  let expired = 0;
44611
44987
  while (expired < samples.length && at - (samples[expired]?.at ?? at) >= intervalMs) {
@@ -46247,7 +46623,7 @@ function readDeclarationSetSync(explicitPaths, dropInDir, maxTotal, parse, maxBy
46247
46623
  // packages/runtime/src/logger.ts
46248
46624
  import { fstatSync as fstatSync4 } from "fs";
46249
46625
 
46250
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-mttkdm5a.js
46626
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-mttkdm5a.js
46251
46627
  var SpoolLineSchema = union([
46252
46628
  strictObject({ k: string2(), e: unknown() }),
46253
46629
  strictObject({ a: string2() })
@@ -46255,7 +46631,7 @@ var SpoolLineSchema = union([
46255
46631
  var READ_CHUNK_BYTES = 64 * 1024;
46256
46632
  var heldBack = new Error("An earlier record of this group is undelivered");
46257
46633
 
46258
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/observability.js
46634
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/observability.js
46259
46635
  var DEFAULT_REDACT_PATHS = Object.freeze([
46260
46636
  "*.password",
46261
46637
  "*.token",
@@ -47454,7 +47830,7 @@ function applicationStatus(status) {
47454
47830
  // packages/runtime/src/broker/audit.ts
47455
47831
  import { chmodSync, existsSync as existsSync4, lstatSync as lstatSync8 } from "fs";
47456
47832
 
47457
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/application/diagnostic-journal.js
47833
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/application/diagnostic-journal.js
47458
47834
  import { randomUUID as randomUUID2 } from "crypto";
47459
47835
  import { constants as constants6 } from "fs";
47460
47836
  import { lstat as lstat22, open as open7, realpath, rename as rename2, unlink as unlink4 } from "fs/promises";
@@ -51224,6 +51600,7 @@ function healthService(input) {
51224
51600
  return implement2(healthContract, {
51225
51601
  get: () => ({
51226
51602
  ok: audit.status().writeFailures === 0 && audit.status().dropped === 0,
51603
+ brokerVersion: RELEASE_VERSION,
51227
51604
  nodes: input.presence(),
51228
51605
  observingSince: registry.observingSince,
51229
51606
  transport: transportObservation.snapshot(),
@@ -57138,7 +57515,7 @@ class TargetLaneSelector {
57138
57515
  import { constants as constants8 } from "os";
57139
57516
  import { dirname as dirname14 } from "path";
57140
57517
 
57141
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-v59pxmf1.js
57518
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-tgehj4bp.js
57142
57519
  import { EventEmitter as EventEmitter4 } from "events";
57143
57520
  import { Readable, Writable } from "stream";
57144
57521
  import { connect } from "net";
@@ -57791,7 +58168,7 @@ function ownerLossGuardEntry() {
57791
58168
  }
57792
58169
  startOwnerLossGuardEntry();
57793
58170
 
57794
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-qa2jjb65.js
58171
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-5c4m8zdf.js
57795
58172
  import { execFile as execFile2 } from "child_process";
57796
58173
  import { Readable as Readable2 } from "stream";
57797
58174
  import { spawn as spawn2 } from "child_process";
@@ -58928,7 +59305,7 @@ function startNativeCommand(input, onSpawn, driver) {
58928
59305
  return owner;
58929
59306
  }
58930
59307
 
58931
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-3fym4j8n.js
59308
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-8cek82ar.js
58932
59309
  function streamNativeCommand2(input) {
58933
59310
  for (const owned of ["capture", "onOutput", "stdio"])
58934
59311
  if (owned in input)
@@ -59000,12 +59377,12 @@ function channel() {
59000
59377
  };
59001
59378
  }
59002
59379
 
59003
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-pzhqydxb.js
59380
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-0sxj3y45.js
59004
59381
  function runNativeCommand2(input) {
59005
59382
  return startNativeCommand(input).result;
59006
59383
  }
59007
59384
 
59008
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/process.js
59385
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/process.js
59009
59386
  var MAX_CALL_BYTES = 64 * 1024 * 1024;
59010
59387
  var OperationCallSchema = strictObject({
59011
59388
  operation: string2().min(1),
@@ -62539,9 +62916,10 @@ var DoctorReportSchema = object({
62539
62916
  capturedAt: exports_iso.datetime(),
62540
62917
  verdict: _enum(["ok", "warn", "fail", "unknown"]),
62541
62918
  exitCode: number2().int().min(0).max(3),
62919
+ brokerVersion: string2().min(1).max(64).optional(),
62542
62920
  checks: array(DiagnosticCheckSchema)
62543
62921
  });
62544
- function doctorReport(scope, checks) {
62922
+ function doctorReport(scope, checks, options) {
62545
62923
  const verdict = checks.some((check) => check.level === "fail") ? "fail" : checks.length === 0 || checks.some((check) => check.level === "unknown") ? "unknown" : checks.some((check) => check.level === "warn") ? "warn" : "ok";
62546
62924
  return DoctorReportSchema.parse({
62547
62925
  v: 1,
@@ -62549,6 +62927,7 @@ function doctorReport(scope, checks) {
62549
62927
  capturedAt: nowIso(),
62550
62928
  verdict,
62551
62929
  exitCode: { ok: 0, warn: 1, fail: 2, unknown: 3 }[verdict],
62930
+ ...options?.brokerVersion === undefined ? {} : { brokerVersion: options.brokerVersion },
62552
62931
  checks
62553
62932
  });
62554
62933
  }
@@ -62674,6 +63053,7 @@ function topicChecks(topic) {
62674
63053
  function brokerChecks(health) {
62675
63054
  return [
62676
63055
  { code: "broker.audit-health", level: health.ok ? "ok" : "fail", detail: `ok=${health.ok}` },
63056
+ ...health.brokerVersion === undefined ? [] : [{ code: "broker.version", level: "ok", detail: `version=${health.brokerVersion}` }],
62677
63057
  applicationCheck(health.application),
62678
63058
  ...auditChecks(health.audit),
62679
63059
  ...transportChecks(health.transport),
@@ -62925,6 +63305,7 @@ function selectedConfig(path) {
62925
63305
  async function runDoctor(argv) {
62926
63306
  const checks = [];
62927
63307
  let broker;
63308
+ let brokerVersion;
62928
63309
  let config;
62929
63310
  let json = false;
62930
63311
  try {
@@ -62945,7 +63326,9 @@ async function runDoctor(argv) {
62945
63326
  const refusal = laneUrlRefusal(broker);
62946
63327
  if (refusal !== null)
62947
63328
  throw new DiagnosticReadError("diagnostic.input", `Refused broker endpoint: ${refusal}`);
62948
- checks.push(...brokerChecks(await readBrokerObservation(broker)));
63329
+ const health = await readBrokerObservation(broker);
63330
+ brokerVersion = health.brokerVersion;
63331
+ checks.push(...brokerChecks(health));
62949
63332
  } else {
62950
63333
  const socket = config ? selectedConfig(config).agentSocket : agentSocketPath();
62951
63334
  try {
@@ -62961,7 +63344,7 @@ async function runDoctor(argv) {
62961
63344
  detail: error instanceof DiagnosticReadError ? error.message : "Invalid diagnostic arguments, endpoint policy or selected configuration"
62962
63345
  });
62963
63346
  }
62964
- const report = doctorReport(broker ? "broker" : "node", checks);
63347
+ const report = doctorReport(broker ? "broker" : "node", checks, brokerVersion === undefined ? undefined : { brokerVersion });
62965
63348
  if (argv.includes("--json"))
62966
63349
  await out(`${JSON.stringify(report)}
62967
63350
  `);
@@ -64036,7 +64419,7 @@ function renderUnit(layout) {
64036
64419
  ];
64037
64420
  return [
64038
64421
  "[Unit]",
64039
- `Description=Stitchwire ${layout.role}`,
64422
+ `Description=StitchWire ${layout.role}`,
64040
64423
  "After=network-online.target",
64041
64424
  "Wants=network-online.target",
64042
64425
  "",
@@ -64201,7 +64584,7 @@ class OwnersLedger {
64201
64584
  // packages/runtime/src/enrollment/supervisor-identity.ts
64202
64585
  import { existsSync as existsSync15 } from "fs";
64203
64586
 
64204
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-9sfhje6y.js
64587
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-b0mh2t9x.js
64205
64588
  import { lstat as lstat6, readlink, realpath as realpath2, unlink as unlink5 } from "fs/promises";
64206
64589
  import { basename as basename5, dirname as dirname18, join as join14, posix } from "path";
64207
64590
  var DEFAULT_ARTIFACT_MAX_FILE_BYTES2 = 256 * 1024 * 1024;
@@ -64264,27 +64647,6 @@ var ArtifactManifestSchema2 = strictObject({
64264
64647
  seen.add(entry.path);
64265
64648
  }
64266
64649
  });
64267
- function isProcessGoneError(error) {
64268
- const code = errnoOf(error);
64269
- return code === "ENOENT" || code === "ESRCH";
64270
- }
64271
- function classifyOwnerEvidence(pid, owner) {
64272
- if (owner.identity === "reused-pid" || owner.identity === "different-boot") {
64273
- return { status: "runtime-conflict", reason: "pid-reused", pid };
64274
- }
64275
- if (owner.identity === "pid-gone" || owner.liveness === "gone") {
64276
- return { status: "runtime-unavailable", reason: "process-gone", pid };
64277
- }
64278
- if (owner.identity !== "matched") {
64279
- return {
64280
- status: "runtime-unavailable",
64281
- reason: "process-unobservable",
64282
- pid,
64283
- cause: owner.cause
64284
- };
64285
- }
64286
- return null;
64287
- }
64288
64650
  var DEFAULT_COMMAND_TIMEOUT_MS = 30000;
64289
64651
  var DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;
64290
64652
  var HOST_COMMAND_PATH = "/usr/sbin:/usr/bin:/sbin:/bin";
@@ -64379,6 +64741,29 @@ function createBaseServiceHostAdapter(adapterOptions) {
64379
64741
  sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
64380
64742
  };
64381
64743
  }
64744
+
64745
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-ke6jtxkd.js
64746
+ function isProcessGoneError(error) {
64747
+ const code = errnoOf(error);
64748
+ return code === "ENOENT" || code === "ESRCH";
64749
+ }
64750
+ function classifyOwnerEvidence(pid, owner) {
64751
+ if (owner.identity === "reused-pid" || owner.identity === "different-boot") {
64752
+ return { status: "runtime-conflict", reason: "pid-reused", pid };
64753
+ }
64754
+ if (owner.identity === "pid-gone" || owner.liveness === "gone") {
64755
+ return { status: "runtime-unavailable", reason: "process-gone", pid };
64756
+ }
64757
+ if (owner.identity !== "matched") {
64758
+ return {
64759
+ status: "runtime-unavailable",
64760
+ reason: "process-unobservable",
64761
+ pid,
64762
+ cause: owner.cause
64763
+ };
64764
+ }
64765
+ return null;
64766
+ }
64382
64767
  var LaunchdKeepAliveSchema2 = strictObject({
64383
64768
  successfulExit: boolean2().optional(),
64384
64769
  crashed: boolean2().optional(),
@@ -64451,10 +64836,127 @@ var LaunchdPlistConfigSchema2 = strictObject({
64451
64836
  });
64452
64837
  var PlistRecordSchema = record(string2(), unknown());
64453
64838
 
64454
- // node_modules/.bun/stitchkit@0.132.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/service-host.js
64839
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/index-05b65gj4.js
64840
+ import { readdir as readdir3 } from "fs/promises";
64841
+ var SystemdScopeSchema2 = _enum(["system", "user"]);
64842
+
64843
+ class SystemdUnitError2 extends Error {
64844
+ code;
64845
+ rolledBack;
64846
+ rollbackError;
64847
+ foreignDropIns;
64848
+ constructor(code, message, options) {
64849
+ super(message, options);
64850
+ this.name = "SystemdUnitError";
64851
+ this.code = code;
64852
+ this.rolledBack = options?.rolledBack ?? false;
64853
+ this.rollbackError = options?.rollbackError;
64854
+ this.foreignDropIns = options?.foreignDropIns;
64855
+ }
64856
+ }
64857
+ var OCTAL_MODE_PATTERN = /^[0-7]{3,4}$/;
64858
+ var EXEC_PREFIX = /^[-@:+!]/;
64859
+ var EXEC_PREFIX_MESSAGE = "the executable must not start with one of systemd's prefixes (-, @, :, +, !): quoting does not disarm them";
64860
+ var SYSTEMD_TIMESPAN_UNIT = "(?:usec|us|msec|ms|seconds|second|sec|s|minutes|minute|min|m|hours|hour|hr|h|days|day|d|weeks|week|w|months|month|M|years|year|y)";
64861
+ var SYSTEMD_TIMESPAN_PATTERN = new RegExp(`^\\d+(?:\\.\\d+)?${SYSTEMD_TIMESPAN_UNIT}?(?:\\s+\\d+(?:\\.\\d+)?${SYSTEMD_TIMESPAN_UNIT}?)*$`);
64862
+ var SYSTEMD_SIGNAL_PATTERN = /^(?:SIG)?(?:HUP|INT|QUIT|ILL|TRAP|ABRT|BUS|FPE|KILL|USR1|SEGV|USR2|PIPE|ALRM|TERM|CHLD|CONT|STOP|TSTP|TTIN|TTOU|URG|XCPU|XFSZ|VTALRM|PROF|WINCH|IO|PWR|SYS)$/;
64863
+ var MAX_SYSTEMD_INTERVAL_SECONDS = 18446744073708;
64864
+ var SystemdIntervalSecondsSchema = number2().nonnegative().max(MAX_SYSTEMD_INTERVAL_SECONDS);
64865
+ var SystemdTimespanSchema = union([
64866
+ SystemdIntervalSecondsSchema,
64867
+ string2().regex(SYSTEMD_TIMESPAN_PATTERN, "must be a valid systemd timespan")
64868
+ ]);
64869
+ var SystemdTimeoutSchema = union([
64870
+ SystemdIntervalSecondsSchema,
64871
+ literal("infinity"),
64872
+ string2().regex(SYSTEMD_TIMESPAN_PATTERN, 'must be a valid systemd timespan or "infinity"')
64873
+ ]);
64874
+ var SystemdBindReadOnlyPathSchema = union([
64875
+ string2().min(1),
64876
+ strictObject({
64877
+ source: string2().min(1),
64878
+ target: string2().min(1).optional(),
64879
+ ignoreMissing: boolean2().optional()
64880
+ })
64881
+ ]);
64882
+ var SystemdSuccessExitStatusItemSchema = union([
64883
+ number2().int().min(0).max(255),
64884
+ string2().regex(SYSTEMD_SIGNAL_PATTERN, "must be an exit code 0..255 or POSIX signal name")
64885
+ ]);
64886
+ var SystemdAddressFamilySchema = union([
64887
+ literal("none"),
64888
+ string2().regex(/^AF_[A-Z0-9_]+$/, 'must be "none" or an AF_* address family')
64889
+ ]);
64890
+ var DEFAULT_SYSTEMD_UNIT_MODE = 420;
64891
+ var SYSTEMCTL_PATH = "/usr/bin/systemctl";
64892
+ function createDefaultSystemdHostAdapter2() {
64893
+ return {
64894
+ ...createBaseServiceHostAdapter({
64895
+ defaultFileMode: DEFAULT_SYSTEMD_UNIT_MODE,
64896
+ nullOnNonRegularFile: true
64897
+ }),
64898
+ async listDir(path) {
64899
+ try {
64900
+ return await readdir3(path);
64901
+ } catch (cause) {
64902
+ if (errnoOf(cause) === "ENOENT")
64903
+ return null;
64904
+ throw cause;
64905
+ }
64906
+ }
64907
+ };
64908
+ }
64909
+ function hasAsciiControlChar(value) {
64910
+ for (let index = 0;index < value.length; index += 1) {
64911
+ const code = value.charCodeAt(index);
64912
+ if (code <= 31 || code === 127)
64913
+ return true;
64914
+ }
64915
+ return false;
64916
+ }
64917
+ function assertValidSystemdUnitName(unitName) {
64918
+ if (unitName.length === 0 || unitName === "." || unitName.startsWith("-") || unitName.includes("/") || unitName.includes("\\") || unitName.includes("..") || /\s/.test(unitName) || hasAsciiControlChar(unitName)) {
64919
+ throw new SystemdUnitError2("INVALID_CONFIG", `Invalid systemd unit name: ${JSON.stringify(unitName)}`);
64920
+ }
64921
+ }
64922
+ function systemdScopeArgs(scope, args) {
64923
+ const parsed = SystemdScopeSchema2.parse(scope);
64924
+ return parsed === "user" ? ["--user", ...args] : [...args];
64925
+ }
64926
+ function parseMainPid(raw) {
64927
+ if (!raw)
64928
+ return null;
64929
+ const trimmed = raw.trim();
64930
+ if (!/^\d+$/.test(trimmed))
64931
+ return null;
64932
+ const pid = Number(trimmed);
64933
+ return Number.isSafeInteger(pid) && pid > 0 ? pid : null;
64934
+ }
64935
+ async function systemdUnitActive2(options) {
64936
+ assertValidSystemdUnitName(options.unitName);
64937
+ const adapter = options.adapter ?? createDefaultSystemdHostAdapter2();
64938
+ const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(options.scope, ["is-active", "--", options.unitName]));
64939
+ return result.exitCode === 0 && result.stdout.trim() === "active";
64940
+ }
64941
+ async function systemdMainPid2(options) {
64942
+ assertValidSystemdUnitName(options.unitName);
64943
+ const adapter = options.adapter ?? createDefaultSystemdHostAdapter2();
64944
+ const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(options.scope, [
64945
+ "show",
64946
+ "--no-pager",
64947
+ "--property=MainPID",
64948
+ "--value",
64949
+ "--",
64950
+ options.unitName
64951
+ ]));
64952
+ if (result.exitCode !== 0)
64953
+ return null;
64954
+ return parseMainPid(result.stdout);
64955
+ }
64956
+
64957
+ // node_modules/.bun/stitchkit@0.135.0+d42cffb2185a445e/node_modules/stitchkit/dist/entrypoints/service-host.js
64455
64958
  import { constants as constants22 } from "fs";
64456
- import { access, readdir as readdir3, readFile as readFile2, readlink as readlink2, realpath as realpath22, stat as stat3 } from "fs/promises";
64457
- import { readdir as readdir22 } from "fs/promises";
64959
+ import { access, readdir as readdir4, readFile as readFile2, readlink as readlink2, realpath as realpath22, stat as stat3 } from "fs/promises";
64458
64960
  var HASH_CHUNK_BYTES = 64 * 1024;
64459
64961
  var SO_ACCEPTCON_FLAG = 65536;
64460
64962
  var PROC_NET_UNIX_LINE = /^[0-9a-fA-F]+:\s+[0-9a-fA-F]+\s+[0-9a-fA-F]+\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+(\d+)(?: (.*))?$/s;
@@ -64729,7 +65231,7 @@ function createProcfsIdentityAdapter(options) {
64729
65231
  readProcessArgv: async (pid) => decodeProcCmdline(await readFile2(`${procRoot}/${pid}/cmdline`)),
64730
65232
  readProcNetUnix: () => readFile2(`${procRoot}/net/unix`, "utf8"),
64731
65233
  async readProcessSocketInodes(pid) {
64732
- const fds = await readdir3(`${procRoot}/${pid}/fd`);
65234
+ const fds = await readdir4(`${procRoot}/${pid}/fd`);
64733
65235
  const inodes = new Set;
64734
65236
  for (const fd of fds) {
64735
65237
  const target = await readlink2(`${procRoot}/${pid}/fd/${fd}`).catch((cause) => {
@@ -64893,124 +65395,9 @@ async function verifySupervisedProcess(options) {
64893
65395
  socketInode: matchedSocketInode
64894
65396
  };
64895
65397
  }
64896
- var SystemdScopeSchema = _enum(["system", "user"]);
64897
-
64898
- class SystemdUnitError extends Error {
64899
- code;
64900
- rolledBack;
64901
- rollbackError;
64902
- foreignDropIns;
64903
- constructor(code, message, options) {
64904
- super(message, options);
64905
- this.name = "SystemdUnitError";
64906
- this.code = code;
64907
- this.rolledBack = options?.rolledBack ?? false;
64908
- this.rollbackError = options?.rollbackError;
64909
- this.foreignDropIns = options?.foreignDropIns;
64910
- }
64911
- }
64912
- var OCTAL_MODE_PATTERN = /^[0-7]{3,4}$/;
64913
- var EXEC_PREFIX = /^[-@:+!]/;
64914
- var EXEC_PREFIX_MESSAGE = "the executable must not start with one of systemd's prefixes (-, @, :, +, !): quoting does not disarm them";
64915
- var SYSTEMD_TIMESPAN_UNIT = "(?:usec|us|msec|ms|seconds|second|sec|s|minutes|minute|min|m|hours|hour|hr|h|days|day|d|weeks|week|w|months|month|M|years|year|y)";
64916
- var SYSTEMD_TIMESPAN_PATTERN = new RegExp(`^\\d+(?:\\.\\d+)?${SYSTEMD_TIMESPAN_UNIT}?(?:\\s+\\d+(?:\\.\\d+)?${SYSTEMD_TIMESPAN_UNIT}?)*$`);
64917
- var SYSTEMD_SIGNAL_PATTERN = /^(?:SIG)?(?:HUP|INT|QUIT|ILL|TRAP|ABRT|BUS|FPE|KILL|USR1|SEGV|USR2|PIPE|ALRM|TERM|CHLD|CONT|STOP|TSTP|TTIN|TTOU|URG|XCPU|XFSZ|VTALRM|PROF|WINCH|IO|PWR|SYS)$/;
64918
- var MAX_SYSTEMD_INTERVAL_SECONDS = 18446744073708;
64919
- var SystemdIntervalSecondsSchema = number2().finite().nonnegative().max(MAX_SYSTEMD_INTERVAL_SECONDS);
64920
- var SystemdTimespanSchema = union([
64921
- SystemdIntervalSecondsSchema,
64922
- string2().regex(SYSTEMD_TIMESPAN_PATTERN, "must be a valid systemd timespan")
64923
- ]);
64924
- var SystemdTimeoutSchema = union([
64925
- SystemdIntervalSecondsSchema,
64926
- literal("infinity"),
64927
- string2().regex(SYSTEMD_TIMESPAN_PATTERN, 'must be a valid systemd timespan or "infinity"')
64928
- ]);
64929
- var SystemdBindReadOnlyPathSchema = union([
64930
- string2().min(1),
64931
- strictObject({
64932
- source: string2().min(1),
64933
- target: string2().min(1).optional(),
64934
- ignoreMissing: boolean2().optional()
64935
- })
64936
- ]);
64937
- var SystemdSuccessExitStatusItemSchema = union([
64938
- number2().int().min(0).max(255),
64939
- string2().regex(SYSTEMD_SIGNAL_PATTERN, "must be an exit code 0..255 or POSIX signal name")
64940
- ]);
64941
- var SystemdAddressFamilySchema = union([
64942
- literal("none"),
64943
- string2().regex(/^AF_[A-Z0-9_]+$/, 'must be "none" or an AF_* address family')
64944
- ]);
64945
- var DEFAULT_SYSTEMD_UNIT_MODE = 420;
64946
- var SYSTEMCTL_PATH = "/usr/bin/systemctl";
64947
- function createDefaultSystemdHostAdapter() {
64948
- return {
64949
- ...createBaseServiceHostAdapter({
64950
- defaultFileMode: DEFAULT_SYSTEMD_UNIT_MODE,
64951
- nullOnNonRegularFile: true
64952
- }),
64953
- async listDir(path) {
64954
- try {
64955
- return await readdir22(path);
64956
- } catch (cause) {
64957
- if (errnoOf(cause) === "ENOENT")
64958
- return null;
64959
- throw cause;
64960
- }
64961
- }
64962
- };
64963
- }
64964
- function hasAsciiControlChar(value) {
64965
- for (let index = 0;index < value.length; index += 1) {
64966
- const code = value.charCodeAt(index);
64967
- if (code <= 31 || code === 127)
64968
- return true;
64969
- }
64970
- return false;
64971
- }
64972
- function assertValidSystemdUnitName(unitName) {
64973
- if (unitName.length === 0 || unitName === "." || unitName.startsWith("-") || unitName.includes("/") || unitName.includes("\\") || unitName.includes("..") || /\s/.test(unitName) || hasAsciiControlChar(unitName)) {
64974
- throw new SystemdUnitError("INVALID_CONFIG", `Invalid systemd unit name: ${JSON.stringify(unitName)}`);
64975
- }
64976
- }
64977
- function systemdScopeArgs(scope, args) {
64978
- const parsed = SystemdScopeSchema.parse(scope);
64979
- return parsed === "user" ? ["--user", ...args] : [...args];
64980
- }
64981
- function parseMainPid(raw) {
64982
- if (!raw)
64983
- return null;
64984
- const trimmed = raw.trim();
64985
- if (!/^\d+$/.test(trimmed))
64986
- return null;
64987
- const pid = Number(trimmed);
64988
- return Number.isSafeInteger(pid) && pid > 0 ? pid : null;
64989
- }
64990
- async function systemdUnitActive(options) {
64991
- assertValidSystemdUnitName(options.unitName);
64992
- const adapter = options.adapter ?? createDefaultSystemdHostAdapter();
64993
- const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(options.scope, ["is-active", "--", options.unitName]));
64994
- return result.exitCode === 0 && result.stdout.trim() === "active";
64995
- }
64996
- async function systemdMainPid(options) {
64997
- assertValidSystemdUnitName(options.unitName);
64998
- const adapter = options.adapter ?? createDefaultSystemdHostAdapter();
64999
- const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(options.scope, [
65000
- "show",
65001
- "--no-pager",
65002
- "--property=MainPID",
65003
- "--value",
65004
- "--",
65005
- options.unitName
65006
- ]));
65007
- if (result.exitCode !== 0)
65008
- return null;
65009
- return parseMainPid(result.stdout);
65010
- }
65011
65398
  var SystemdServiceUnitConfigSchema = strictObject({
65012
65399
  description: string2().min(1),
65013
- scope: SystemdScopeSchema.default("system"),
65400
+ scope: SystemdScopeSchema2.default("system"),
65014
65401
  execStart: array(string2()).min(1),
65015
65402
  execStartPre: array(array(string2()).min(1)).optional(),
65016
65403
  workingDirectory: string2().min(1).optional(),
@@ -65130,7 +65517,7 @@ var SystemdServiceUnitConfigSchema = strictObject({
65130
65517
  var OnCalendarItemSchema = string2().refine((value) => value.trim().length > 0, "onCalendar expression must not be empty");
65131
65518
  var SystemdTimerUnitConfigSchema = strictObject({
65132
65519
  description: string2().min(1),
65133
- scope: SystemdScopeSchema.default("system"),
65520
+ scope: SystemdScopeSchema2.default("system"),
65134
65521
  after: array(string2().min(1)).optional(),
65135
65522
  wants: array(string2().min(1)).optional(),
65136
65523
  unit: string2().min(1).optional(),
@@ -65248,7 +65635,7 @@ async function startUnit(supervision) {
65248
65635
  }
65249
65636
  }
65250
65637
  var adapter = {
65251
- ...createDefaultSystemdHostAdapter(),
65638
+ ...createDefaultSystemdHostAdapter2(),
65252
65639
  async runCommand(executable, args) {
65253
65640
  const result = await command2(executable, [...args]);
65254
65641
  if (result.code === null)
@@ -65257,10 +65644,10 @@ var adapter = {
65257
65644
  }
65258
65645
  };
65259
65646
  function unitActive(unit) {
65260
- return systemdUnitActive({ unitName: unit.unit, scope: unit.scope, adapter });
65647
+ return systemdUnitActive2({ unitName: unit.unit, scope: unit.scope, adapter });
65261
65648
  }
65262
65649
  async function mainPid(unit) {
65263
- const pid = await systemdMainPid({ unitName: unit.unit, scope: unit.scope, adapter });
65650
+ const pid = await systemdMainPid2({ unitName: unit.unit, scope: unit.scope, adapter });
65264
65651
  if (pid === null)
65265
65652
  throw new EnrollmentError("supervisor-failed");
65266
65653
  return pid;