stitchkit 0.59.4 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +7 -3
  2. package/dist/agent-runtime/admission-lanes.d.ts +35 -0
  3. package/dist/agent-runtime/admission-lanes.d.ts.map +1 -0
  4. package/dist/agent-runtime/coordinator.d.ts +36 -2
  5. package/dist/agent-runtime/coordinator.d.ts.map +1 -1
  6. package/dist/agent-runtime/events.d.ts +7 -0
  7. package/dist/agent-runtime/events.d.ts.map +1 -1
  8. package/dist/agent-runtime/history.d.ts +7 -0
  9. package/dist/agent-runtime/history.d.ts.map +1 -1
  10. package/dist/agent-runtime/models.d.ts +2 -3
  11. package/dist/agent-runtime/models.d.ts.map +1 -1
  12. package/dist/agent-runtime/observability.d.ts.map +1 -1
  13. package/dist/agent-runtime/run-execution.d.ts +31 -0
  14. package/dist/agent-runtime/run-execution.d.ts.map +1 -0
  15. package/dist/agent-runtime/runtime-internals.d.ts +25 -0
  16. package/dist/agent-runtime/runtime-internals.d.ts.map +1 -0
  17. package/dist/agent-runtime/runtime-result.d.ts +11 -0
  18. package/dist/agent-runtime/runtime-result.d.ts.map +1 -0
  19. package/dist/agent-runtime/runtime.d.ts +16 -15
  20. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  21. package/dist/agent-runtime/schemas.d.ts.map +1 -1
  22. package/dist/agent-runtime/store-driver.d.ts.map +1 -1
  23. package/dist/agent-runtime/store.d.ts +9 -2
  24. package/dist/agent-runtime/store.d.ts.map +1 -1
  25. package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
  26. package/dist/agent-runtime/terminal-status.d.ts +13 -0
  27. package/dist/agent-runtime/terminal-status.d.ts.map +1 -0
  28. package/dist/agent-runtime.d.ts +5 -3
  29. package/dist/agent-runtime.d.ts.map +1 -1
  30. package/dist/agent-runtime.js +211 -156
  31. package/dist/application/activity.d.ts +7 -2
  32. package/dist/application/activity.d.ts.map +1 -1
  33. package/dist/application/grammy.d.ts +6 -0
  34. package/dist/application/grammy.d.ts.map +1 -1
  35. package/dist/application/health.d.ts +9 -2
  36. package/dist/application/health.d.ts.map +1 -1
  37. package/dist/application/kernel.d.ts +49 -3
  38. package/dist/application/kernel.d.ts.map +1 -1
  39. package/dist/application/schemas.d.ts +42 -0
  40. package/dist/application/schemas.d.ts.map +1 -1
  41. package/dist/application-opentelemetry.js +2 -2
  42. package/dist/application.d.ts +3 -3
  43. package/dist/application.d.ts.map +1 -1
  44. package/dist/application.js +16 -8
  45. package/dist/cli.js +6 -6
  46. package/dist/contract/errors.d.ts +6 -0
  47. package/dist/contract/errors.d.ts.map +1 -1
  48. package/dist/contract/index.js +1 -1
  49. package/dist/declaration.d.ts +345 -0
  50. package/dist/declaration.d.ts.map +1 -0
  51. package/dist/declaration.js +183 -0
  52. package/dist/{index-5c8n2123.js → index-1zencgcb.js} +64 -30
  53. package/dist/{index-sa2mbwa7.js → index-2akar0rq.js} +2 -2
  54. package/dist/{index-41wm56v0.js → index-3hn10n4c.js} +1 -1
  55. package/dist/{index-f6pymtqe.js → index-3w74r08v.js} +2 -2
  56. package/dist/{index-7c0gkyvj.js → index-6fbp58g8.js} +2 -2
  57. package/dist/{index-gnvzyw0k.js → index-8es1hrv4.js} +2 -2
  58. package/dist/{index-mgf6cdkm.js → index-8eywc9zv.js} +35 -1
  59. package/dist/{index-3nwng7hs.js → index-8pc5s3pz.js} +4 -4
  60. package/dist/{index-28cqssm3.js → index-9h1vba8n.js} +6 -0
  61. package/dist/{index-0nc0cddp.js → index-a59da114.js} +17 -28
  62. package/dist/{index-s8w2y7kr.js → index-f7521k0x.js} +22 -16
  63. package/dist/{index-y2rb7dwx.js → index-pzyt11ch.js} +5 -1
  64. package/dist/{index-mr617n62.js → index-svqhcrrj.js} +1 -1
  65. package/dist/{index-ps5pxp3h.js → index-v6e8hnkx.js} +7 -1
  66. package/dist/{index-1tkyng3g.js → index-vkk06pv1.js} +1 -9
  67. package/dist/{index-2nzpcfbp.js → index-x8v8b7rc.js} +2 -2
  68. package/dist/index.js +1 -1
  69. package/dist/internal/observability-sink.d.ts.map +1 -1
  70. package/dist/internal/route-pattern.d.ts +9 -0
  71. package/dist/internal/route-pattern.d.ts.map +1 -1
  72. package/dist/node.d.ts +1 -1
  73. package/dist/node.d.ts.map +1 -1
  74. package/dist/node.js +5 -5
  75. package/dist/observability/index.js +5 -5
  76. package/dist/observability/sanitize.d.ts +3 -1
  77. package/dist/observability/sanitize.d.ts.map +1 -1
  78. package/dist/remote.js +3 -3
  79. package/dist/server/error-hook.d.ts +10 -3
  80. package/dist/server/error-hook.d.ts.map +1 -1
  81. package/dist/server/index.d.ts +1 -1
  82. package/dist/server/index.d.ts.map +1 -1
  83. package/dist/server/index.js +9 -12
  84. package/dist/server/middleware/cors.d.ts +5 -2
  85. package/dist/server/middleware/cors.d.ts.map +1 -1
  86. package/dist/server/openapi.d.ts.map +1 -1
  87. package/dist/server/router.d.ts.map +1 -1
  88. package/dist/server/socket-io-config.d.ts +68 -3
  89. package/dist/server/socket-io-config.d.ts.map +1 -1
  90. package/dist/server/socket-io-node.d.ts +1 -1
  91. package/dist/server/socket-io-node.d.ts.map +1 -1
  92. package/dist/server/socket-io.d.ts +1 -1
  93. package/dist/server/socket-io.d.ts.map +1 -1
  94. package/dist/testing/surface-manifest.d.ts.map +1 -1
  95. package/dist/testing.js +8 -10
  96. package/dist/tools/flatten-join.d.ts +2 -0
  97. package/dist/tools/flatten-join.d.ts.map +1 -1
  98. package/dist/tools/flatten.d.ts.map +1 -1
  99. package/dist/tools/mcp-prepare.d.ts +0 -2
  100. package/dist/tools/mcp-prepare.d.ts.map +1 -1
  101. package/dist/tools/runtime-tool.d.ts +0 -3
  102. package/dist/tools/runtime-tool.d.ts.map +1 -1
  103. package/dist/tools/schema.d.ts +0 -4
  104. package/dist/tools/schema.d.ts.map +1 -1
  105. package/dist/tools.js +9 -9
  106. package/llms-full.txt +924 -68
  107. package/llms.txt +1 -0
  108. package/package.json +6 -2
@@ -2,7 +2,7 @@ import {
2
2
  ApplicationIdSchema,
3
3
  ApplicationShutdownResultSchema,
4
4
  ApplicationSnapshotSchema
5
- } from "./index-mgf6cdkm.js";
5
+ } from "./index-8eywc9zv.js";
6
6
  import {
7
7
  ShutdownOptionsSchema
8
8
  } from "./index-dk6e56g0.js";
@@ -61,6 +61,18 @@ class ResourceCompletionBeforeReadyError extends Error {
61
61
  }
62
62
  }
63
63
 
64
+ class ApplicationStartupInterruptedError extends Error {
65
+ constructor() {
66
+ super("[stitchkit] application startup interrupted by shutdown");
67
+ this.name = "ApplicationStartupInterruptedError";
68
+ }
69
+ }
70
+ var ApplicationShutdownOptionsSchema = ShutdownOptionsSchema.pick({
71
+ gracePeriodMs: true,
72
+ forceTimeoutMs: true,
73
+ signal: true
74
+ });
75
+
64
76
  class ApplicationAdmissionError extends Error {
65
77
  code = "APPLICATION_NOT_ACCEPTING";
66
78
  constructor() {
@@ -87,6 +99,15 @@ function createApplication(config) {
87
99
  const id = ApplicationIdSchema.parse(config.id);
88
100
  const ordered = resolveResourceGraph(config.resources ?? []);
89
101
  const reverse = [...ordered].reverse();
102
+ const reportFailure = (resourceId, phase, error) => {
103
+ if (!config.onResourceFailure)
104
+ return;
105
+ try {
106
+ Promise.resolve(config.onResourceFailure({ resourceId, phase, error })).catch(() => {
107
+ return;
108
+ });
109
+ } catch {}
110
+ };
90
111
  const records = new Map;
91
112
  for (const entry of ordered) {
92
113
  records.set(entry.id, {
@@ -187,8 +208,10 @@ function createApplication(config) {
187
208
  const markLateCompletion = (record, failure) => {
188
209
  if (shutdownRequested || record.state === "stopping" || record.state === "stopped")
189
210
  return;
190
- if (failure)
211
+ if (failure) {
191
212
  record.failures.push("completion");
213
+ reportFailure(record.entry.id, "completion", failure.error);
214
+ }
192
215
  record.state = "failed";
193
216
  record.health = "unhealthy";
194
217
  accepting = activationComplete && isReady();
@@ -209,6 +232,7 @@ function createApplication(config) {
209
232
  } catch (error) {
210
233
  record.failures.push("close");
211
234
  record.state = "failed";
235
+ reportFailure(entry.id, "close", error);
212
236
  errors.push(error);
213
237
  }
214
238
  publish();
@@ -222,7 +246,7 @@ function createApplication(config) {
222
246
  try {
223
247
  for (const entry of ordered) {
224
248
  if (shutdownRequested || startupAbort.signal.aborted) {
225
- throw new Error("[stitchkit] application startup interrupted by shutdown");
249
+ throw new ApplicationStartupInterruptedError;
226
250
  }
227
251
  const record = records.get(entry.id);
228
252
  if (!record)
@@ -244,7 +268,7 @@ function createApplication(config) {
244
268
  try {
245
269
  const started = await entry.resource.start(contextFor(record, { signal: startupAbort.signal }));
246
270
  if (shutdownRequested || startupAbort.signal.aborted) {
247
- throw new Error("[stitchkit] application startup interrupted by shutdown");
271
+ throw new ApplicationStartupInterruptedError;
248
272
  }
249
273
  if (isStartResult(started)) {
250
274
  record.runtime = started;
@@ -254,12 +278,12 @@ function createApplication(config) {
254
278
  const completion = started.completion?.then(() => {
255
279
  completionSettled = true;
256
280
  if (resourceReady)
257
- markLateCompletion(record, false);
281
+ markLateCompletion(record);
258
282
  }, (error) => {
259
283
  completionSettled = true;
260
284
  completionFailure = error;
261
285
  if (resourceReady)
262
- markLateCompletion(record, true);
286
+ markLateCompletion(record, { error });
263
287
  });
264
288
  if (started.ready && completion) {
265
289
  const readiness = started.ready.then(() => "ready");
@@ -278,19 +302,21 @@ function createApplication(config) {
278
302
  } else if (completion) {}
279
303
  }
280
304
  if (shutdownRequested || startupAbort.signal.aborted) {
281
- throw new Error("[stitchkit] application startup interrupted by shutdown");
305
+ throw new ApplicationStartupInterruptedError;
282
306
  }
283
307
  record.state = "ready";
284
308
  record.health = "healthy";
285
309
  publish();
286
310
  } catch (error) {
287
- if (shutdownRequested || startupAbort.signal.aborted)
288
- throw error;
289
- record.failures.push(error instanceof ResourceCompletionBeforeReadyError ? "completion" : record.runtime?.ready ? "ready" : "start");
290
- record.state = "failed";
291
- record.health = "unhealthy";
292
- publish();
293
- if (entry.required)
311
+ const interrupted = shutdownRequested || startupAbort.signal.aborted;
312
+ if (!(error instanceof ApplicationStartupInterruptedError)) {
313
+ record.failures.push(error instanceof ResourceCompletionBeforeReadyError ? "completion" : record.runtime?.ready ? "ready" : "start");
314
+ record.state = "failed";
315
+ record.health = "unhealthy";
316
+ reportFailure(entry.id, record.failures[record.failures.length - 1] ?? "start", error);
317
+ publish();
318
+ }
319
+ if (interrupted || entry.required)
294
320
  throw error;
295
321
  }
296
322
  }
@@ -298,7 +324,7 @@ function createApplication(config) {
298
324
  publish();
299
325
  for (const entry of ordered) {
300
326
  if (shutdownRequested || startupAbort.signal.aborted) {
301
- throw new Error("[stitchkit] application startup interrupted by shutdown");
327
+ throw new ApplicationStartupInterruptedError;
302
328
  }
303
329
  const record = records.get(entry.id);
304
330
  if (record?.state !== "ready")
@@ -320,25 +346,27 @@ function createApplication(config) {
320
346
  try {
321
347
  await entry.resource.activate?.(contextFor(record));
322
348
  if (shutdownRequested || startupAbort.signal.aborted) {
323
- throw new Error("[stitchkit] application startup interrupted by shutdown");
349
+ throw new ApplicationStartupInterruptedError;
324
350
  }
325
351
  record.activated = true;
326
352
  if (entry.required && (record.state !== "ready" || record.health !== "healthy")) {
327
353
  throw new Error(`[stitchkit] required resource "${entry.id}" lost readiness during activation`);
328
354
  }
329
355
  } catch (error) {
330
- if (shutdownRequested || startupAbort.signal.aborted)
331
- throw error;
332
- record.failures.push("start");
333
- record.state = "failed";
334
- record.health = "unhealthy";
335
- publish();
336
- if (entry.required)
356
+ const interrupted = shutdownRequested || startupAbort.signal.aborted;
357
+ if (!(error instanceof ApplicationStartupInterruptedError)) {
358
+ record.failures.push("start");
359
+ record.state = "failed";
360
+ record.health = "unhealthy";
361
+ reportFailure(entry.id, "start", error);
362
+ publish();
363
+ }
364
+ if (interrupted || entry.required)
337
365
  throw error;
338
366
  }
339
367
  }
340
368
  if (shutdownRequested) {
341
- throw new Error("[stitchkit] application startup interrupted by shutdown");
369
+ throw new ApplicationStartupInterruptedError;
342
370
  }
343
371
  if (!isReady()) {
344
372
  throw new Error("[stitchkit] a required resource lost readiness during startup");
@@ -417,7 +445,7 @@ function createApplication(config) {
417
445
  const shutdown = (options) => {
418
446
  if (shutdownPromise)
419
447
  return shutdownPromise;
420
- const parsed = ShutdownOptionsSchema.parse(options ?? {});
448
+ const parsed = ApplicationShutdownOptionsSchema.parse(options ?? {});
421
449
  const startedAt = performance.now();
422
450
  const graceDeadlineAt = startedAt + parsed.gracePeriodMs;
423
451
  const forceDeadlineAt = graceDeadlineAt + parsed.forceTimeoutMs;
@@ -464,8 +492,9 @@ function createApplication(config) {
464
492
  break;
465
493
  if (result.error !== undefined)
466
494
  throw result.error;
467
- } catch {
495
+ } catch (error) {
468
496
  record.failures.push("admission");
497
+ reportFailure(entry.id, "admission", error);
469
498
  gracefulFailed = true;
470
499
  lifetimeAbort.abort();
471
500
  }
@@ -491,8 +520,9 @@ function createApplication(config) {
491
520
  }
492
521
  if (drained.error !== undefined)
493
522
  throw drained.error;
494
- } catch {
523
+ } catch (error) {
495
524
  record.failures.push("drain");
525
+ reportFailure(entry.id, "drain", error);
496
526
  gracefulFailed = true;
497
527
  lifetimeAbort.abort();
498
528
  break;
@@ -518,8 +548,9 @@ function createApplication(config) {
518
548
  record.closed = true;
519
549
  record.state = "stopped";
520
550
  publish();
521
- } catch {
551
+ } catch (error) {
522
552
  record.failures.push("close");
553
+ reportFailure(entry.id, "close", error);
523
554
  record.state = "failed";
524
555
  gracefulFailed = true;
525
556
  lifetimeAbort.abort();
@@ -556,17 +587,20 @@ function createApplication(config) {
556
587
  })));
557
588
  } else if (entry.resource.close) {
558
589
  record.failures.push("force");
590
+ reportFailure(entry.id, "force", new Error(`[stitchkit] resource "${entry.id}" was already closing and did not settle before the force deadline`));
559
591
  return;
560
592
  }
561
593
  const forced = await untilDeadline(cleanup ?? Promise.resolve(), forceAbort.signal);
562
594
  if (!forced.settled || forced.error !== undefined) {
563
595
  record.failures.push("force");
596
+ reportFailure(entry.id, "force", forced.settled ? forced.error : new Error("[stitchkit] forced cleanup did not settle in time"));
564
597
  return;
565
598
  }
566
599
  record.closed = true;
567
600
  record.state = "stopped";
568
- } catch {
601
+ } catch (error) {
569
602
  record.failures.push("force");
603
+ reportFailure(entry.id, "force", error);
570
604
  }
571
605
  }));
572
606
  clearTimeout(forceTimer);
@@ -614,4 +648,4 @@ function createApplication(config) {
614
648
  };
615
649
  }
616
650
 
617
- export { ApplicationAdmissionError, createApplication };
651
+ export { ApplicationShutdownOptionsSchema, ApplicationAdmissionError, createApplication };
@@ -7,14 +7,14 @@ import {
7
7
  normalizeError,
8
8
  runWithRequestContext,
9
9
  validateDeclaredOutput
10
- } from "./index-7c0gkyvj.js";
10
+ } from "./index-6fbp58g8.js";
11
11
  import {
12
12
  AppError,
13
13
  STITCH_ERROR_STATUS,
14
14
  isStitchErrorCode,
15
15
  isUnsafeKey,
16
16
  safeJsonParse
17
- } from "./index-ps5pxp3h.js";
17
+ } from "./index-v6e8hnkx.js";
18
18
  import {
19
19
  isRecord
20
20
  } from "./index-smpbdg6k.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isUnsafeKey,
3
3
  mergeMeta
4
- } from "./index-ps5pxp3h.js";
4
+ } from "./index-v6e8hnkx.js";
5
5
  import {
6
6
  callRuntimeHandler,
7
7
  isRecord,
@@ -2,7 +2,7 @@ import {
2
2
  contextContributionDelta,
3
3
  mergeContextContribution,
4
4
  prepareContextContribution
5
- } from "./index-41wm56v0.js";
5
+ } from "./index-3hn10n4c.js";
6
6
  import {
7
7
  base64UrlToBytes,
8
8
  bytesToBase64Url,
@@ -10,7 +10,7 @@ import {
10
10
  isUnsafeKey,
11
11
  safeJsonParse,
12
12
  unauthorized
13
- } from "./index-ps5pxp3h.js";
13
+ } from "./index-v6e8hnkx.js";
14
14
  import {
15
15
  isRecord
16
16
  } from "./index-smpbdg6k.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  AppError,
3
3
  isUnsafeKey
4
- } from "./index-ps5pxp3h.js";
4
+ } from "./index-v6e8hnkx.js";
5
5
  import {
6
6
  resolveTraceContext
7
- } from "./index-y2rb7dwx.js";
7
+ } from "./index-pzyt11ch.js";
8
8
  import {
9
9
  isRecord
10
10
  } from "./index-smpbdg6k.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isUnsafeKey
3
- } from "./index-ps5pxp3h.js";
3
+ } from "./index-v6e8hnkx.js";
4
4
  import {
5
5
  isRecord
6
6
  } from "./index-smpbdg6k.js";
@@ -83,7 +83,7 @@ function redact(value, options = {}) {
83
83
  ancestors.add(input);
84
84
  const result = [...input.entries()].map(([key, value2]) => [
85
85
  walk(key, depth + 1),
86
- walk(value2, depth + 1)
86
+ typeof key === "string" && isSensitive(key) ? MASK : walk(value2, depth + 1)
87
87
  ]);
88
88
  ancestors.delete(input);
89
89
  return { _type: "map", entries: result };
@@ -46,6 +46,40 @@ var ApplicationSnapshotSchema = z.object({
46
46
  admission: ApplicationAdmissionSnapshotSchema,
47
47
  resources: z.array(ManagedResourceSnapshotSchema).readonly()
48
48
  }).readonly();
49
+ var ApplicationStatusProjectionSchema = z.object({
50
+ id: ApplicationIdSchema,
51
+ lifecycle: ApplicationLifecycleSchema,
52
+ health: ApplicationHealthSchema,
53
+ ready: z.boolean(),
54
+ capturedAt: z.string().datetime({ offset: true }),
55
+ resources: z.object({
56
+ total: NonNegativeIntegerSchema,
57
+ ready: NonNegativeIntegerSchema,
58
+ degraded: NonNegativeIntegerSchema,
59
+ failed: NonNegativeIntegerSchema
60
+ }).readonly()
61
+ }).readonly();
62
+ function projectApplicationStatus(snapshot) {
63
+ let ready = 0;
64
+ let degraded = 0;
65
+ let failed = 0;
66
+ for (const resource of snapshot.resources) {
67
+ if (resource.ready)
68
+ ready += 1;
69
+ if (resource.health === "degraded")
70
+ degraded += 1;
71
+ if (resource.state === "failed")
72
+ failed += 1;
73
+ }
74
+ return {
75
+ id: snapshot.id,
76
+ lifecycle: snapshot.lifecycle,
77
+ health: snapshot.health,
78
+ ready: snapshot.ready,
79
+ capturedAt: snapshot.capturedAt,
80
+ resources: { total: snapshot.resources.length, ready, degraded, failed }
81
+ };
82
+ }
49
83
  var ApplicationResourceShutdownSchema = z.object({
50
84
  id: ApplicationIdSchema,
51
85
  state: z.enum(["not-started", "closed", "force-failed"]),
@@ -63,4 +97,4 @@ var ApplicationShutdownResultSchema = z.object({
63
97
  durationMs: z.number().nonnegative()
64
98
  }).readonly();
65
99
 
66
- export { ApplicationIdSchema, ApplicationLifecycleSchema, ApplicationHealthSchema, ManagedResourceStateSchema, ApplicationAdmissionSnapshotSchema, ManagedResourceSnapshotSchema, ApplicationSnapshotSchema, ApplicationResourceShutdownSchema, ApplicationShutdownResultSchema };
100
+ export { ApplicationIdSchema, ApplicationLifecycleSchema, ApplicationHealthSchema, ManagedResourceStateSchema, ApplicationAdmissionSnapshotSchema, ManagedResourceSnapshotSchema, ApplicationSnapshotSchema, ApplicationStatusProjectionSchema, projectApplicationStatus, ApplicationResourceShutdownSchema, ApplicationShutdownResultSchema };
@@ -2,7 +2,7 @@ import {
2
2
  coerceJsonArgs,
3
3
  executeToolMethod,
4
4
  toolResultFromError
5
- } from "./index-sa2mbwa7.js";
5
+ } from "./index-2akar0rq.js";
6
6
  import {
7
7
  isWithinDir
8
8
  } from "./index-sbdmyz75.js";
@@ -12,7 +12,7 @@ import {
12
12
  buildToolPresentationSchema,
13
13
  projectRuntimeTool,
14
14
  projectToolSurface
15
- } from "./index-1tkyng3g.js";
15
+ } from "./index-vkk06pv1.js";
16
16
  import {
17
17
  mergeSchemas,
18
18
  objectShapeKeys,
@@ -24,11 +24,11 @@ import {
24
24
  import {
25
25
  formatZodError,
26
26
  validateDeclaredOutput
27
- } from "./index-7c0gkyvj.js";
27
+ } from "./index-6fbp58g8.js";
28
28
  import {
29
29
  isUnsafeKey,
30
30
  safeJsonParse
31
- } from "./index-ps5pxp3h.js";
31
+ } from "./index-v6e8hnkx.js";
32
32
  import {
33
33
  isRecord
34
34
  } from "./index-smpbdg6k.js";
@@ -284,6 +284,12 @@ var STITCH_ERROR_STATUS = {
284
284
  FILE_TOO_LARGE: 413,
285
285
  FILE_EXISTS: 409,
286
286
  REALTIME_CONTRACT_VIOLATION: 500,
287
+ APPLICATION_NOT_ACCEPTING: 503,
288
+ WAIT_TIMEOUT: 408,
289
+ WAIT_FAILED: 409,
290
+ DOWNLOAD_NOT_FOUND: 404,
291
+ VIEW_HTTP_ERROR: 502,
292
+ OPERATION_NOT_SUCCEEDED: 409,
287
293
  INTERNAL_SERVER_ERROR: 500
288
294
  };
289
295
  function isStitchErrorCode(code) {
@@ -138,41 +138,30 @@ function createBoundedSinkManager(config) {
138
138
  flush() {
139
139
  return awaitGeneration(sequence);
140
140
  },
141
- getStatus() {
142
- return ObservabilitySinkStatusSchema.parse({
143
- capacity: maxPending,
144
- received,
145
- accepted,
146
- filtered,
147
- completed,
148
- dropped,
149
- failed,
150
- preparationFailed,
151
- preparing: preparing.size,
152
- pending: writes.size,
153
- closed
154
- });
155
- },
141
+ getStatus,
156
142
  close() {
157
143
  if (closePromise)
158
144
  return closePromise;
159
145
  closed = true;
160
- closePromise = awaitGeneration(sequence).then(() => ObservabilitySinkStatusSchema.parse({
161
- capacity: maxPending,
162
- received,
163
- accepted,
164
- filtered,
165
- completed,
166
- dropped,
167
- failed,
168
- preparationFailed,
169
- preparing: preparing.size,
170
- pending: writes.size,
171
- closed
172
- }));
146
+ closePromise = awaitGeneration(sequence).then(getStatus);
173
147
  return closePromise;
174
148
  }
175
149
  };
150
+ function getStatus() {
151
+ return ObservabilitySinkStatusSchema.parse({
152
+ capacity: maxPending,
153
+ received,
154
+ accepted,
155
+ filtered,
156
+ completed,
157
+ dropped,
158
+ failed,
159
+ preparationFailed,
160
+ preparing: preparing.size,
161
+ pending: writes.size,
162
+ closed
163
+ });
164
+ }
176
165
  }
177
166
 
178
167
  export { ObservabilitySinkStatusSchema, ObservabilityStatusSchema, ObservabilityDrainReportSchema, aggregateObservabilityStatus, createBoundedSinkManager };
@@ -7,7 +7,7 @@ import {
7
7
  defaultSignalSource,
8
8
  guardSignalCallback,
9
9
  reportSignalError
10
- } from "./index-41wm56v0.js";
10
+ } from "./index-3hn10n4c.js";
11
11
  import {
12
12
  ShutdownOptionsSchema
13
13
  } from "./index-dk6e56g0.js";
@@ -26,17 +26,18 @@ import {
26
26
  setRequestError,
27
27
  validateDeclaredOutput,
28
28
  zodIssues
29
- } from "./index-7c0gkyvj.js";
29
+ } from "./index-6fbp58g8.js";
30
30
  import {
31
31
  AppError,
32
32
  badRequest,
33
33
  isUnsafeKey,
34
34
  safeJsonParse
35
- } from "./index-ps5pxp3h.js";
35
+ } from "./index-v6e8hnkx.js";
36
36
  import {
37
+ joinRoutePath,
37
38
  parseTrailingWildcard,
38
39
  resolveTraceContext
39
- } from "./index-y2rb7dwx.js";
40
+ } from "./index-pzyt11ch.js";
40
41
  import {
41
42
  isRecord,
42
43
  transportResult
@@ -827,10 +828,6 @@ function applyResponseMetadata(target, metadata, endpointIdentity) {
827
828
  }
828
829
 
829
830
  // src/server/router.ts
830
- function joinPath(...parts) {
831
- const joined = parts.filter(Boolean).map((part) => part.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
832
- return `/${joined}`;
833
- }
834
831
  function routeSegments(path) {
835
832
  return path.split("/").filter(Boolean);
836
833
  }
@@ -914,8 +911,8 @@ function buildRouteMap(groups) {
914
911
  for (const [, method] of Object.entries(service.methods)) {
915
912
  if (method.expose && !method.expose.includes("HTTP"))
916
913
  continue;
917
- const servicePath = joinPath("/", service.prefix, method.path === "/" ? "" : method.path);
918
- const fullPath = prefix ? joinPath(prefix, servicePath) : servicePath;
914
+ const servicePath = joinRoutePath("/", service.prefix, method.path === "/" ? "" : method.path);
915
+ const fullPath = prefix ? joinRoutePath(prefix, servicePath) : servicePath;
919
916
  const segments = routeSegments(fullPath);
920
917
  const entries = map.get(method.method) ?? [];
921
918
  entries.push({ method, pattern: fullPath, segments, groupHooks: hooks });
@@ -1853,16 +1850,19 @@ function isModuleNotFound(err) {
1853
1850
  const message = "message" in err && typeof err.message === "string" ? err.message : "";
1854
1851
  return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || message.includes("Cannot find module") || message.includes("Cannot find package");
1855
1852
  }
1856
- async function importPeer(load, pkg) {
1853
+ async function importPeer(load, pkg, injected) {
1857
1854
  try {
1858
1855
  return await load();
1859
1856
  } catch (err) {
1860
1857
  if (isModuleNotFound(err)) {
1861
- throw new Error(`[stitchkit] createSocketIOServer needs the optional peer "${pkg}" — install it: bun add ${pkg}`, { cause: err });
1858
+ throw new Error(injected ? `[stitchkit] createSocketIOServer could not load the optional peer "${pkg}" through the loader passed in \`peers\` — the artifact does not contain it. Check that the loader is a literal \`import('${pkg}')\` your bundler can follow, and that "${pkg}" is a dependency of the package being bundled.` : `[stitchkit] createSocketIOServer needs the optional peer "${pkg}" — install it: bun add ${pkg}. Shipping one self-contained artifact instead? Pass \`peers: { … }\` so your bundler puts it inside.`, { cause: err });
1862
1859
  }
1863
1860
  throw err;
1864
1861
  }
1865
1862
  }
1863
+ function isBunEngineModule(value) {
1864
+ return typeof value === "object" && value !== null && typeof Reflect.get(value, "Server") === "function";
1865
+ }
1866
1866
  function handshakeRejection(message) {
1867
1867
  const error = new Error(message);
1868
1868
  error.data = { code: "handshake_rejected" };
@@ -1906,11 +1906,11 @@ async function createSocketIOServer(config) {
1906
1906
  const transports = config.transports ?? (onBun ? ["websocket", "polling"] : ["websocket"]);
1907
1907
  const pingTimeout = config.pingTimeout ?? 20000;
1908
1908
  const pingInterval = config.pingInterval ?? 1e4;
1909
- const cors = {
1909
+ const cors = config.cors ? {
1910
1910
  origin: config.cors.origin,
1911
1911
  credentials: config.cors.credentials ?? true,
1912
1912
  methods: ["GET", "POST"]
1913
- };
1913
+ } : undefined;
1914
1914
  let accepting = true;
1915
1915
  let attached = false;
1916
1916
  let closePromise;
@@ -1939,7 +1939,8 @@ async function createSocketIOServer(config) {
1939
1939
  });
1940
1940
  checkRequest(webRequest).then(() => done(null, true), (error) => done(error instanceof Error ? error.message : "Request rejected", false));
1941
1941
  };
1942
- const { Server } = await importPeer(() => import(SOCKET_IO_SERVER).then((module) => module), SOCKET_IO_SERVER);
1942
+ const injectedServer = config.peers?.server;
1943
+ const { Server } = await importPeer(injectedServer ?? (() => import(SOCKET_IO_SERVER).then((module) => module)), SOCKET_IO_SERVER, injectedServer !== undefined);
1943
1944
  const io = new Server({
1944
1945
  ...config.serverOptions,
1945
1946
  path,
@@ -1966,7 +1967,12 @@ async function createSocketIOServer(config) {
1966
1967
  }
1967
1968
  };
1968
1969
  if (onBun) {
1969
- const { Server: Engine } = await importPeer(() => import(SOCKET_IO_BUN_ENGINE).then((module) => module), SOCKET_IO_BUN_ENGINE);
1970
+ const injectedEngine = config.peers?.bunEngine;
1971
+ const engineModule = await importPeer(injectedEngine ?? (() => import(SOCKET_IO_BUN_ENGINE).then((module) => module)), SOCKET_IO_BUN_ENGINE, injectedEngine !== undefined);
1972
+ if (!isBunEngineModule(engineModule)) {
1973
+ throw new Error(`[stitchkit] the loader passed in \`peers.bunEngine\` did not return the "${SOCKET_IO_BUN_ENGINE}" module — it must resolve to the module itself, as \`() => import('${SOCKET_IO_BUN_ENGINE}')\`.`);
1974
+ }
1975
+ const { Server: Engine } = engineModule;
1970
1976
  const engineOpts = {
1971
1977
  path,
1972
1978
  cors,
@@ -80,6 +80,10 @@ function resolvePropagationContext(metadata, fallback) {
80
80
 
81
81
  // src/internal/route-pattern.ts
82
82
  var PARAM_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
83
+ function joinRoutePath(...parts) {
84
+ const joined = parts.filter((part) => Boolean(part)).map((part) => part.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
85
+ return `/${joined}`;
86
+ }
83
87
  function parseTrailingWildcard(path) {
84
88
  const segments = path.split("/").filter(Boolean);
85
89
  const paramNames = new Set;
@@ -120,4 +124,4 @@ function parseTrailingWildcard(path) {
120
124
  return wildcard;
121
125
  }
122
126
 
123
- export { parseTrailingWildcard, createTraceContext, parseTraceparent, formatTraceparent, resolveTraceContext, childSpan, resolvePropagationContext };
127
+ export { joinRoutePath, parseTrailingWildcard, createTraceContext, parseTraceparent, formatTraceparent, resolveTraceContext, childSpan, resolvePropagationContext };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-48ffdxgk.js";
4
4
  import {
5
5
  parseTrailingWildcard
6
- } from "./index-y2rb7dwx.js";
6
+ } from "./index-pzyt11ch.js";
7
7
  import {
8
8
  isRecord,
9
9
  mapObject,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseTrailingWildcard
3
- } from "./index-y2rb7dwx.js";
3
+ } from "./index-pzyt11ch.js";
4
4
 
5
5
  // src/contract/errors.ts
6
6
  var APP_ERROR_BRAND = Symbol.for("stitchkit.AppError");
@@ -70,6 +70,12 @@ var STITCH_ERROR_STATUS = {
70
70
  FILE_TOO_LARGE: 413,
71
71
  FILE_EXISTS: 409,
72
72
  REALTIME_CONTRACT_VIOLATION: 500,
73
+ APPLICATION_NOT_ACCEPTING: 503,
74
+ WAIT_TIMEOUT: 408,
75
+ WAIT_FAILED: 409,
76
+ DOWNLOAD_NOT_FOUND: 404,
77
+ VIEW_HTTP_ERROR: 502,
78
+ OPERATION_NOT_SUCCEEDED: 409,
73
79
  INTERNAL_SERVER_ERROR: 500
74
80
  };
75
81
  function isStitchErrorCode(code) {
@@ -338,14 +338,6 @@ function rebuild(value) {
338
338
  node[key] = rebuild(child);
339
339
  return flattenNode(node);
340
340
  }
341
- function stringValues2(schema) {
342
- if (typeof schema.const === "string")
343
- return [schema.const];
344
- if (!Array.isArray(schema.enum))
345
- return null;
346
- const values = schema.enum.filter((value) => typeof value === "string");
347
- return values.length === schema.enum.length ? values : null;
348
- }
349
341
  function objectVariants(node) {
350
342
  if (!Array.isArray(node.oneOf) || node.oneOf.length < 2)
351
343
  return null;
@@ -372,7 +364,7 @@ function findDiscriminator(variants) {
372
364
  }
373
365
  const properties = variant.properties;
374
366
  const field = isRecord(properties) ? properties[key] : undefined;
375
- const branchValues = isRecord(field) ? stringValues2(field) : null;
367
+ const branchValues = isRecord(field) ? stringValues(field) : null;
376
368
  if (!branchValues || branchValues.length === 0) {
377
369
  valid = false;
378
370
  break;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ApplicationIdSchema
3
- } from "./index-mgf6cdkm.js";
3
+ } from "./index-8eywc9zv.js";
4
4
 
5
5
  // src/application/latest-sink.ts
6
6
  import { z } from "zod";
@@ -557,4 +557,4 @@ function createManagedSchedule(config) {
557
557
  };
558
558
  }
559
559
 
560
- export { ApplicationSnapshotSinkStatusSchema, createApplicationSnapshotSink, ActivityIdSchema, ActivityStageIdSchema, ActivityStageSnapshotSchema, ActivitySnapshotSchema, ActivityLiveStateSchema, createActivityProjection, ManagedScheduleOverlapSchema, ManagedScheduleErrorPolicySchema, ManagedScheduleDescriptorSchema, ManagedScheduleStatusSchema, createManagedSchedule };
560
+ export { ApplicationSnapshotSinkStatusSchema, createApplicationSnapshotSink, ActivityIdSchema, ActivityStageIdSchema, ActivityStageSnapshotSchema, ActivitySnapshotSchema, ActivityLiveStateSchema, ActivityTokenBrand, createActivityProjection, ManagedScheduleOverlapSchema, ManagedScheduleErrorPolicySchema, ManagedScheduleDescriptorSchema, ManagedScheduleStatusSchema, createManagedSchedule };