stitchkit 0.69.0 → 0.70.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +4 -4
  2. package/dist/agent-runtime/coding-tool-contract.d.ts +1 -0
  3. package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
  4. package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -1
  5. package/dist/agent-runtime/coding-tool-paths.d.ts +1 -1
  6. package/dist/agent-runtime/coding-tool-paths.d.ts.map +1 -1
  7. package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -1
  8. package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -1
  9. package/dist/agent-runtime/contained-files.d.ts +52 -4
  10. package/dist/agent-runtime/contained-files.d.ts.map +1 -1
  11. package/dist/agent-runtime/harness-file-resources.d.ts.map +1 -1
  12. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  13. package/dist/agent-runtime-coding-tools.js +202 -145
  14. package/dist/agent-runtime-harness.js +12 -8
  15. package/dist/agent-runtime.js +9 -7
  16. package/dist/application/server-resource.d.ts +1 -0
  17. package/dist/application/server-resource.d.ts.map +1 -1
  18. package/dist/application.js +5 -2
  19. package/dist/cli.js +7 -6
  20. package/dist/{index-t4dpby6e.js → index-0yphgata.js} +1 -1
  21. package/dist/index-1z5xxfst.js +397 -0
  22. package/dist/index-3xnq72rz.js +21 -0
  23. package/dist/{index-444747ww.js → index-4g196jmf.js} +14 -9
  24. package/dist/{index-kg9xx84n.js → index-7rey2b8s.js} +1 -1
  25. package/dist/{index-dk6e56g0.js → index-7wpgrqa8.js} +37 -2
  26. package/dist/{index-zh459sfj.js → index-aczggrty.js} +1 -1
  27. package/dist/index-bd17ytae.js +192 -0
  28. package/dist/{index-q7gdep2c.js → index-da1aqnhb.js} +2 -2
  29. package/dist/{index-p1be103g.js → index-ktsps64f.js} +4 -2
  30. package/dist/{index-mbxds404.js → index-mjx0wt4c.js} +8 -6
  31. package/dist/{index-h8vn1jcr.js → index-qzbg46b6.js} +6 -4
  32. package/dist/{index-h7ctj1kp.js → index-s8nt8c22.js} +14 -11
  33. package/dist/{index-d1jsvkyk.js → index-vbf2p6me.js} +1 -1
  34. package/dist/{index-xxsq3ca1.js → index-vc498pst.js} +1 -1
  35. package/dist/{index-x18ndp4p.js → index-vj3vvpaa.js} +1 -192
  36. package/dist/{index-3eqrkqhg.js → index-vy5bjy07.js} +7 -3
  37. package/dist/{index-6wzr93cg.js → index-w0445741.js} +1 -1
  38. package/dist/{index-kxxyvkka.js → index-wc80at9n.js} +2 -2
  39. package/dist/{index-gqdfpv4n.js → index-y3w12g8d.js} +2 -2
  40. package/dist/node.js +26 -5
  41. package/dist/observability/index.js +4 -3
  42. package/dist/remote.js +4 -3
  43. package/dist/server/bun.d.ts.map +1 -1
  44. package/dist/server/index.js +20 -10
  45. package/dist/server/node.d.ts.map +1 -1
  46. package/dist/server/process-signals.d.ts.map +1 -1
  47. package/dist/server/shutdown.d.ts +2 -0
  48. package/dist/server/shutdown.d.ts.map +1 -1
  49. package/dist/testing.js +6 -5
  50. package/dist/tool-invoker.js +6 -5
  51. package/dist/tools/agent-tool-error.d.ts +14 -0
  52. package/dist/tools/agent-tool-error.d.ts.map +1 -0
  53. package/dist/tools/agent.d.ts.map +1 -1
  54. package/dist/tools.js +15 -12
  55. package/llms-full.txt +73 -22
  56. package/native/darwin-arm64.node +0 -0
  57. package/native/darwin-x64.node +0 -0
  58. package/package.json +3 -1
  59. package/dist/index-v3dpzpjw.js +0 -92
@@ -0,0 +1,192 @@
1
+ import {
2
+ AppError
3
+ } from "./index-0w9abg87.js";
4
+ import {
5
+ isRecord
6
+ } from "./index-qyrqwr4c.js";
7
+
8
+ // src/internal/errors.ts
9
+ import { z } from "zod";
10
+ function issuePath(path) {
11
+ return path.length > 0 ? path.map(String).join(".") : "(root)";
12
+ }
13
+ function formatZodError(error) {
14
+ const issues = error.issues.slice(0, 5);
15
+ const lines = issues.map((issue) => `${issuePath(issue.path)}: ${issue.message}`);
16
+ const suffix = error.issues.length > 5 ? `
17
+ ...and ${error.issues.length - 5} more issues` : "";
18
+ return lines.join(`
19
+ `) + suffix;
20
+ }
21
+ function zodIssues(error) {
22
+ return error.issues.map((issue) => ({
23
+ path: issuePath(issue.path),
24
+ code: issue.code,
25
+ message: issue.message
26
+ }));
27
+ }
28
+ var MAX_DETAIL_ISSUES = 20;
29
+ function errorCode(err) {
30
+ if (AppError.is(err))
31
+ return err.code;
32
+ if (err instanceof z.ZodError)
33
+ return "VALIDATION_ERROR";
34
+ return;
35
+ }
36
+ function recordedErrorMessage(code, envelopeMessage, thrown) {
37
+ if ((code === "INTERNAL_SERVER_ERROR" || code === "REALTIME_CONTRACT_VIOLATION") && thrown !== undefined) {
38
+ if (thrown instanceof Error)
39
+ return thrown.message;
40
+ if (typeof thrown === "string")
41
+ return thrown;
42
+ }
43
+ return envelopeMessage;
44
+ }
45
+ function normalizeError(err) {
46
+ if (AppError.is(err)) {
47
+ if (err.code === "REALTIME_CONTRACT_VIOLATION") {
48
+ return new AppError("REALTIME_CONTRACT_VIOLATION", "Realtime contract violation", 500);
49
+ }
50
+ return err;
51
+ }
52
+ if (err instanceof z.ZodError) {
53
+ return new AppError("VALIDATION_ERROR", formatZodError(err), 400, {
54
+ issues: zodIssues(err).slice(0, MAX_DETAIL_ISSUES)
55
+ });
56
+ }
57
+ console.error("[stitchkit] unhandled error:", err);
58
+ return new AppError("INTERNAL_SERVER_ERROR", "Internal server error", 500);
59
+ }
60
+ function strippedPaths(before, after, prefix) {
61
+ if (Array.isArray(before)) {
62
+ if (!Array.isArray(after))
63
+ return [];
64
+ return before.flatMap((item, i) => strippedPaths(item, after[i], `${prefix}[${i}]`));
65
+ }
66
+ if (!isRecord(before) || !isRecord(after))
67
+ return [];
68
+ const paths = [];
69
+ for (const [key, value] of Object.entries(before)) {
70
+ const path = prefix ? `${prefix}.${key}` : key;
71
+ if (!(key in after)) {
72
+ paths.push(path);
73
+ continue;
74
+ }
75
+ paths.push(...strippedPaths(value, after[key], path));
76
+ }
77
+ return paths;
78
+ }
79
+ function validateHandlerOutput(schema, data, onStripped) {
80
+ const parsed = schema.safeParse(data);
81
+ if (parsed.success) {
82
+ if (onStripped) {
83
+ const paths = strippedPaths(data, parsed.data, "");
84
+ if (paths.length > 0)
85
+ onStripped(paths);
86
+ }
87
+ return { ok: true, data: parsed.data };
88
+ }
89
+ return {
90
+ ok: false,
91
+ message: `Handler output does not match the contract: ${formatZodError(parsed.error)}`
92
+ };
93
+ }
94
+ function validateDeclaredOutput(schema, data, onStripped) {
95
+ if (!schema) {
96
+ if (data === undefined || data === null)
97
+ return { ok: true, data };
98
+ return {
99
+ ok: false,
100
+ message: "Handler returned data but the contract declares no output"
101
+ };
102
+ }
103
+ if (data === undefined) {
104
+ return {
105
+ ok: false,
106
+ message: "Handler returned undefined but the contract declares an output"
107
+ };
108
+ }
109
+ return validateHandlerOutput(schema, data, onStripped);
110
+ }
111
+
112
+ // src/observability/trace.ts
113
+ var TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(.*)$/i;
114
+ function randomHex(bytes) {
115
+ const arr = new Uint8Array(bytes);
116
+ crypto.getRandomValues(arr);
117
+ let hex = "";
118
+ for (const byte of arr)
119
+ hex += byte.toString(16).padStart(2, "0");
120
+ return hex;
121
+ }
122
+ function createTraceContext() {
123
+ return { traceId: randomHex(16), spanId: randomHex(8) };
124
+ }
125
+ function parseTraceparent(header) {
126
+ if (!header)
127
+ return null;
128
+ const match = TRACEPARENT_RE.exec(header.trim());
129
+ if (!match?.[1] || !match[2] || !match[3] || !match[4] || match[5] === undefined)
130
+ return null;
131
+ const version = match[1].toLowerCase();
132
+ if (version === "ff")
133
+ return null;
134
+ const suffix = match[5];
135
+ if (version === "00" ? suffix !== "" : suffix !== "" && !/^(?:-[0-9a-f]{2,})+$/i.test(suffix)) {
136
+ return null;
137
+ }
138
+ const traceId = match[2].toLowerCase();
139
+ const parentSpanId = match[3].toLowerCase();
140
+ const traceFlags = match[4].toLowerCase();
141
+ if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId))
142
+ return null;
143
+ return { traceId, spanId: randomHex(8), parentSpanId, traceFlags };
144
+ }
145
+ function formatTraceparent(ctx) {
146
+ return `00-${ctx.traceId}-${ctx.spanId}-${ctx.traceFlags ?? "01"}`;
147
+ }
148
+ function resolveTraceContext(req) {
149
+ return parseTraceparent(req.headers.get("traceparent")) ?? createTraceContext();
150
+ }
151
+ function childSpan(parent) {
152
+ return {
153
+ traceId: parent.traceId,
154
+ spanId: randomHex(8),
155
+ parentSpanId: parent.spanId,
156
+ ...parent.tracestate !== undefined && { tracestate: parent.tracestate },
157
+ ...parent.baggage !== undefined && { baggage: parent.baggage },
158
+ ...parent.traceFlags !== undefined && { traceFlags: parent.traceFlags }
159
+ };
160
+ }
161
+ var encoder = new TextEncoder;
162
+ function boundedPropagationValue(value, maxBytes, maxMembers) {
163
+ if (typeof value !== "string")
164
+ return;
165
+ const trimmed = value.trim();
166
+ if (!trimmed || encoder.encode(trimmed).byteLength > maxBytes)
167
+ return;
168
+ for (const character of trimmed) {
169
+ const code = character.charCodeAt(0);
170
+ if (code <= 31 || code === 127)
171
+ return;
172
+ }
173
+ const members = trimmed.split(",");
174
+ if (members.length > maxMembers || members.some((member) => !member.trim())) {
175
+ return;
176
+ }
177
+ return trimmed;
178
+ }
179
+ function resolvePropagationContext(metadata, fallback) {
180
+ const traceparent = metadata?.traceparent;
181
+ const parsed = typeof traceparent === "string" ? parseTraceparent(traceparent) : null;
182
+ const trace = traceparent === undefined ? fallback ?? createTraceContext() : parsed ?? createTraceContext();
183
+ const tracestate = parsed ? boundedPropagationValue(metadata?.tracestate, 512, 32) : undefined;
184
+ const baggage = boundedPropagationValue(metadata?.baggage, 8192, 180);
185
+ return {
186
+ ...trace,
187
+ ...tracestate !== undefined && { tracestate },
188
+ ...baggage !== undefined && { baggage }
189
+ };
190
+ }
191
+
192
+ export { formatZodError, zodIssues, errorCode, recordedErrorMessage, normalizeError, validateDeclaredOutput, createTraceContext, parseTraceparent, formatTraceparent, resolveTraceContext, childSpan, resolvePropagationContext };
@@ -2,13 +2,13 @@ import {
2
2
  contextContributionDelta,
3
3
  mergeContextContribution,
4
4
  prepareContextContribution
5
- } from "./index-d1jsvkyk.js";
5
+ } from "./index-vbf2p6me.js";
6
6
  import {
7
7
  base64UrlToBytes,
8
8
  bytesToBase64Url,
9
9
  isUnsafeKey,
10
10
  safeJsonParse
11
- } from "./index-x18ndp4p.js";
11
+ } from "./index-vj3vvpaa.js";
12
12
  import {
13
13
  forbidden,
14
14
  unauthorized
@@ -1,7 +1,9 @@
1
1
  import {
2
- isUnsafeKey,
3
2
  resolveTraceContext
4
- } from "./index-x18ndp4p.js";
3
+ } from "./index-bd17ytae.js";
4
+ import {
5
+ isUnsafeKey
6
+ } from "./index-vj3vvpaa.js";
5
7
  import {
6
8
  isRecord
7
9
  } from "./index-qyrqwr4c.js";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  collectToolSurface
3
- } from "./index-xxsq3ca1.js";
3
+ } from "./index-vc498pst.js";
4
4
  import {
5
5
  createToolRunner,
6
6
  formatToolError
7
- } from "./index-kg9xx84n.js";
7
+ } from "./index-7rey2b8s.js";
8
8
  import {
9
9
  coerceJsonArgs,
10
10
  toolResultFromError
11
- } from "./index-h8vn1jcr.js";
11
+ } from "./index-qzbg46b6.js";
12
12
  import {
13
13
  isWithinDir
14
14
  } from "./index-sbdmyz75.js";
@@ -22,10 +22,12 @@ import {
22
22
  } from "./index-cby4ar3v.js";
23
23
  import {
24
24
  formatZodError,
25
- isUnsafeKey,
26
- safeJsonParse,
27
25
  validateDeclaredOutput
28
- } from "./index-x18ndp4p.js";
26
+ } from "./index-bd17ytae.js";
27
+ import {
28
+ isUnsafeKey,
29
+ safeJsonParse
30
+ } from "./index-vj3vvpaa.js";
29
31
  import {
30
32
  isRecord
31
33
  } from "./index-qyrqwr4c.js";
@@ -1,17 +1,19 @@
1
1
  import {
2
2
  getRequestContext,
3
3
  runWithRequestContext
4
- } from "./index-p1be103g.js";
4
+ } from "./index-ktsps64f.js";
5
5
  import {
6
6
  objectShapeKeys
7
7
  } from "./index-22by16v6.js";
8
8
  import {
9
9
  formatZodError,
10
- isUnsafeKey,
11
10
  normalizeError,
12
- safeJsonParse,
13
11
  validateDeclaredOutput
14
- } from "./index-x18ndp4p.js";
12
+ } from "./index-bd17ytae.js";
13
+ import {
14
+ isUnsafeKey,
15
+ safeJsonParse
16
+ } from "./index-vj3vvpaa.js";
15
17
  import {
16
18
  AppError,
17
19
  STITCH_ERROR_STATUS,
@@ -1,14 +1,17 @@
1
+ import {
2
+ AgentToolError
3
+ } from "./index-3xnq72rz.js";
1
4
  import {
2
5
  collectToolSurface
3
- } from "./index-xxsq3ca1.js";
6
+ } from "./index-vc498pst.js";
4
7
  import {
5
8
  createToolRunner,
6
9
  formatToolError
7
- } from "./index-kg9xx84n.js";
10
+ } from "./index-7rey2b8s.js";
8
11
  import {
9
12
  isToolExecutionControlError,
10
13
  toolResultFromError
11
- } from "./index-h8vn1jcr.js";
14
+ } from "./index-qzbg46b6.js";
12
15
  import {
13
16
  isRecord
14
17
  } from "./index-qyrqwr4c.js";
@@ -40,16 +43,16 @@ function mountAgent(services, config = {}) {
40
43
  });
41
44
  const execute = async (rawArgs, options) => {
42
45
  const args = isRecord(rawArgs) ? rawArgs : {};
43
- try {
44
- const result = await runTool(mountable, args, { signal: options.abortSignal });
45
- if (result.ok)
46
- return result.data;
47
- return formatToolError(result, mountable.name, config.errorHint);
48
- } catch (err) {
46
+ const result = await runTool(mountable, args, {
47
+ signal: options.abortSignal
48
+ }).catch((err) => {
49
49
  if (isToolExecutionControlError(err))
50
50
  throw err;
51
- return formatToolError(toolResultFromError(err), mountable.name, config.errorHint);
52
- }
51
+ throw new AgentToolError(formatToolError(toolResultFromError(err), mountable.name, config.errorHint), err);
52
+ });
53
+ if (result.ok)
54
+ return result.data;
55
+ throw new AgentToolError(formatToolError(result, mountable.name, config.errorHint));
53
56
  };
54
57
  const presenter = entry.kind === "runtime" ? entry.definition.present?.agent : undefined;
55
58
  if (entry.kind === "runtime" && presenter) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isUnsafeKey,
3
3
  mergeMeta
4
- } from "./index-x18ndp4p.js";
4
+ } from "./index-vj3vvpaa.js";
5
5
  import {
6
6
  callRuntimeHandler,
7
7
  isRecord,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-wwst0td5.js";
4
4
  import {
5
5
  contractToolMountable
6
- } from "./index-kg9xx84n.js";
6
+ } from "./index-7rey2b8s.js";
7
7
  import {
8
8
  projectToolSurface
9
9
  } from "./index-22by16v6.js";
@@ -1,10 +1,3 @@
1
- import {
2
- AppError
3
- } from "./index-0w9abg87.js";
4
- import {
5
- isRecord
6
- } from "./index-qyrqwr4c.js";
7
-
8
1
  // src/contract/define.ts
9
2
  import { z } from "zod";
10
3
 
@@ -311,188 +304,4 @@ var ContractStreamFrameSchema = z4.discriminatedUnion("type", [
311
304
  }).strict(),
312
305
  z4.object({ type: z4.literal("end") }).strict()
313
306
  ]);
314
- // src/internal/errors.ts
315
- import { z as z5 } from "zod";
316
- function issuePath(path) {
317
- return path.length > 0 ? path.map(String).join(".") : "(root)";
318
- }
319
- function formatZodError(error) {
320
- const issues = error.issues.slice(0, 5);
321
- const lines = issues.map((issue) => `${issuePath(issue.path)}: ${issue.message}`);
322
- const suffix = error.issues.length > 5 ? `
323
- ...and ${error.issues.length - 5} more issues` : "";
324
- return lines.join(`
325
- `) + suffix;
326
- }
327
- function zodIssues(error) {
328
- return error.issues.map((issue) => ({
329
- path: issuePath(issue.path),
330
- code: issue.code,
331
- message: issue.message
332
- }));
333
- }
334
- var MAX_DETAIL_ISSUES = 20;
335
- function errorCode(err) {
336
- if (AppError.is(err))
337
- return err.code;
338
- if (err instanceof z5.ZodError)
339
- return "VALIDATION_ERROR";
340
- return;
341
- }
342
- function recordedErrorMessage(code, envelopeMessage, thrown) {
343
- if ((code === "INTERNAL_SERVER_ERROR" || code === "REALTIME_CONTRACT_VIOLATION") && thrown !== undefined) {
344
- if (thrown instanceof Error)
345
- return thrown.message;
346
- if (typeof thrown === "string")
347
- return thrown;
348
- }
349
- return envelopeMessage;
350
- }
351
- function normalizeError(err) {
352
- if (AppError.is(err)) {
353
- if (err.code === "REALTIME_CONTRACT_VIOLATION") {
354
- return new AppError("REALTIME_CONTRACT_VIOLATION", "Realtime contract violation", 500);
355
- }
356
- return err;
357
- }
358
- if (err instanceof z5.ZodError) {
359
- return new AppError("VALIDATION_ERROR", formatZodError(err), 400, {
360
- issues: zodIssues(err).slice(0, MAX_DETAIL_ISSUES)
361
- });
362
- }
363
- console.error("[stitchkit] unhandled error:", err);
364
- return new AppError("INTERNAL_SERVER_ERROR", "Internal server error", 500);
365
- }
366
- function strippedPaths(before, after, prefix) {
367
- if (Array.isArray(before)) {
368
- if (!Array.isArray(after))
369
- return [];
370
- return before.flatMap((item, i) => strippedPaths(item, after[i], `${prefix}[${i}]`));
371
- }
372
- if (!isRecord(before) || !isRecord(after))
373
- return [];
374
- const paths = [];
375
- for (const [key, value] of Object.entries(before)) {
376
- const path = prefix ? `${prefix}.${key}` : key;
377
- if (!(key in after)) {
378
- paths.push(path);
379
- continue;
380
- }
381
- paths.push(...strippedPaths(value, after[key], path));
382
- }
383
- return paths;
384
- }
385
- function validateHandlerOutput(schema, data, onStripped) {
386
- const parsed = schema.safeParse(data);
387
- if (parsed.success) {
388
- if (onStripped) {
389
- const paths = strippedPaths(data, parsed.data, "");
390
- if (paths.length > 0)
391
- onStripped(paths);
392
- }
393
- return { ok: true, data: parsed.data };
394
- }
395
- return {
396
- ok: false,
397
- message: `Handler output does not match the contract: ${formatZodError(parsed.error)}`
398
- };
399
- }
400
- function validateDeclaredOutput(schema, data, onStripped) {
401
- if (!schema) {
402
- if (data === undefined || data === null)
403
- return { ok: true, data };
404
- return {
405
- ok: false,
406
- message: "Handler returned data but the contract declares no output"
407
- };
408
- }
409
- if (data === undefined) {
410
- return {
411
- ok: false,
412
- message: "Handler returned undefined but the contract declares an output"
413
- };
414
- }
415
- return validateHandlerOutput(schema, data, onStripped);
416
- }
417
-
418
- // src/observability/trace.ts
419
- var TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(.*)$/i;
420
- function randomHex(bytes) {
421
- const arr = new Uint8Array(bytes);
422
- crypto.getRandomValues(arr);
423
- let hex = "";
424
- for (const byte of arr)
425
- hex += byte.toString(16).padStart(2, "0");
426
- return hex;
427
- }
428
- function createTraceContext() {
429
- return { traceId: randomHex(16), spanId: randomHex(8) };
430
- }
431
- function parseTraceparent(header) {
432
- if (!header)
433
- return null;
434
- const match = TRACEPARENT_RE.exec(header.trim());
435
- if (!match?.[1] || !match[2] || !match[3] || !match[4] || match[5] === undefined)
436
- return null;
437
- const version = match[1].toLowerCase();
438
- if (version === "ff")
439
- return null;
440
- const suffix = match[5];
441
- if (version === "00" ? suffix !== "" : suffix !== "" && !/^(?:-[0-9a-f]{2,})+$/i.test(suffix)) {
442
- return null;
443
- }
444
- const traceId = match[2].toLowerCase();
445
- const parentSpanId = match[3].toLowerCase();
446
- const traceFlags = match[4].toLowerCase();
447
- if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId))
448
- return null;
449
- return { traceId, spanId: randomHex(8), parentSpanId, traceFlags };
450
- }
451
- function formatTraceparent(ctx) {
452
- return `00-${ctx.traceId}-${ctx.spanId}-${ctx.traceFlags ?? "01"}`;
453
- }
454
- function resolveTraceContext(req) {
455
- return parseTraceparent(req.headers.get("traceparent")) ?? createTraceContext();
456
- }
457
- function childSpan(parent) {
458
- return {
459
- traceId: parent.traceId,
460
- spanId: randomHex(8),
461
- parentSpanId: parent.spanId,
462
- ...parent.tracestate !== undefined && { tracestate: parent.tracestate },
463
- ...parent.baggage !== undefined && { baggage: parent.baggage },
464
- ...parent.traceFlags !== undefined && { traceFlags: parent.traceFlags }
465
- };
466
- }
467
- var encoder = new TextEncoder;
468
- function boundedPropagationValue(value, maxBytes, maxMembers) {
469
- if (typeof value !== "string")
470
- return;
471
- const trimmed = value.trim();
472
- if (!trimmed || encoder.encode(trimmed).byteLength > maxBytes)
473
- return;
474
- for (const character of trimmed) {
475
- const code = character.charCodeAt(0);
476
- if (code <= 31 || code === 127)
477
- return;
478
- }
479
- const members = trimmed.split(",");
480
- if (members.length > maxMembers || members.some((member) => !member.trim())) {
481
- return;
482
- }
483
- return trimmed;
484
- }
485
- function resolvePropagationContext(metadata, fallback) {
486
- const traceparent = metadata?.traceparent;
487
- const parsed = typeof traceparent === "string" ? parseTraceparent(traceparent) : null;
488
- const trace = traceparent === undefined ? fallback ?? createTraceContext() : parsed ?? createTraceContext();
489
- const tracestate = parsed ? boundedPropagationValue(metadata?.tracestate, 512, 32) : undefined;
490
- const baggage = boundedPropagationValue(metadata?.baggage, 8192, 180);
491
- return {
492
- ...trace,
493
- ...tracestate !== undefined && { tracestate },
494
- ...baggage !== undefined && { baggage }
495
- };
496
- }
497
-
498
- export { joinRoutePath, parseTrailingWildcard, isUnsafeKey, safeJsonParse, defineContract, mergeMeta, bytesToBase64Url, base64UrlToBytes, DEFAULT_CONTRACT_STREAM_FRAME_BYTES, ContractStreamFrameSchema, formatZodError, zodIssues, errorCode, recordedErrorMessage, normalizeError, validateDeclaredOutput, createTraceContext, parseTraceparent, formatTraceparent, resolveTraceContext, childSpan, resolvePropagationContext };
307
+ export { joinRoutePath, parseTrailingWildcard, isUnsafeKey, safeJsonParse, defineContract, mergeMeta, bytesToBase64Url, base64UrlToBytes, DEFAULT_CONTRACT_STREAM_FRAME_BYTES, ContractStreamFrameSchema };
@@ -6,10 +6,13 @@ import {
6
6
  import {
7
7
  createBoundedSinkManager
8
8
  } from "./index-a59da114.js";
9
+ import {
10
+ isAgentToolError
11
+ } from "./index-3xnq72rz.js";
9
12
  import {
10
13
  ToolExecutionControlError,
11
14
  isToolExecutionControlError
12
- } from "./index-h8vn1jcr.js";
15
+ } from "./index-qzbg46b6.js";
13
16
  import {
14
17
  AgentAssistantPlaceholderSchema,
15
18
  AgentJsonObjectSchema,
@@ -1678,12 +1681,13 @@ function createRunExecutor(dependencies) {
1678
1681
  });
1679
1682
  throw part.error;
1680
1683
  }
1684
+ const output = isAgentToolError(part.error) ? jsonValue(part.error.output) : { message: "Tool execution failed" };
1681
1685
  parts.push(AgentMessagePartSchema.parse({
1682
1686
  type: "tool-result",
1683
1687
  callId: part.toolCallId,
1684
1688
  toolName: part.toolName,
1685
1689
  outcome: "error",
1686
- output: { message: "Tool execution failed" }
1690
+ output
1687
1691
  }));
1688
1692
  await publish({
1689
1693
  type: "tool-status",
@@ -1694,7 +1698,7 @@ function createRunExecutor(dependencies) {
1694
1698
  callId: part.toolCallId,
1695
1699
  toolName: part.toolName,
1696
1700
  status: "failed",
1697
- output: { message: "Tool execution failed" },
1701
+ output,
1698
1702
  emittedAt: now().toISOString()
1699
1703
  });
1700
1704
  } else if (part.type === "tool-output-denied") {
@@ -8,7 +8,7 @@ import {
8
8
  } from "./index-8eywc9zv.js";
9
9
  import {
10
10
  ShutdownOptionsSchema
11
- } from "./index-dk6e56g0.js";
11
+ } from "./index-7wpgrqa8.js";
12
12
  import {
13
13
  AppError
14
14
  } from "./index-0w9abg87.js";
@@ -3,12 +3,12 @@ import {
3
3
  inputIsQuery,
4
4
  parseSSE,
5
5
  readBoundedUtf8Lines
6
- } from "./index-t4dpby6e.js";
6
+ } from "./index-0yphgata.js";
7
7
  import {
8
8
  ContractStreamFrameSchema,
9
9
  DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
10
10
  parseTrailingWildcard
11
- } from "./index-x18ndp4p.js";
11
+ } from "./index-vj3vvpaa.js";
12
12
  import {
13
13
  isRecord,
14
14
  mapObject,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  collectTools,
3
3
  createToolRunner
4
- } from "./index-kg9xx84n.js";
4
+ } from "./index-7rey2b8s.js";
5
5
  import {
6
6
  toolErrorFromResult
7
- } from "./index-h8vn1jcr.js";
7
+ } from "./index-qzbg46b6.js";
8
8
  import {
9
9
  assertUniqueToolName
10
10
  } from "./index-22by16v6.js";
package/dist/node.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createHandler,
6
6
  createSocketIOServer,
7
7
  createUnixClientTransport
8
- } from "./index-444747ww.js";
8
+ } from "./index-4g196jmf.js";
9
9
  import {
10
10
  createImplement,
11
11
  createImplementRegistry,
@@ -14,8 +14,8 @@ import {
14
14
  createScopedImplementRegistry,
15
15
  implement,
16
16
  implementRegistry
17
- } from "./index-d1jsvkyk.js";
18
- import"./index-p1be103g.js";
17
+ } from "./index-vbf2p6me.js";
18
+ import"./index-ktsps64f.js";
19
19
  import"./index-7b188kmz.js";
20
20
  import {
21
21
  ShutdownOptionsSchema,
@@ -23,8 +23,9 @@ import {
23
23
  ShutdownStateSchema,
24
24
  ShutdownStatusSchema,
25
25
  createServerLifecycle
26
- } from "./index-dk6e56g0.js";
27
- import"./index-x18ndp4p.js";
26
+ } from "./index-7wpgrqa8.js";
27
+ import"./index-bd17ytae.js";
28
+ import"./index-vj3vvpaa.js";
28
29
  import {
29
30
  AppError,
30
31
  appError,
@@ -151,6 +152,18 @@ async function serveNode(config) {
151
152
  return Promise.resolve();
152
153
  return new Promise((resolve) => socketDrainWaiters.add(resolve));
153
154
  };
155
+ const waitForUpgradedSocketDrain = () => {
156
+ if (upgradedSockets.size === 0)
157
+ return Promise.resolve();
158
+ return Promise.all([...upgradedSockets].map((activeSocket) => new Promise((resolve) => {
159
+ if (activeSocket.closed)
160
+ resolve();
161
+ else
162
+ activeSocket.once("close", () => resolve());
163
+ }))).then(() => {
164
+ return;
165
+ });
166
+ };
154
167
  const requireRuntime = () => {
155
168
  if (!runtime)
156
169
  throw new Error("[stitchkit] Node server lifecycle started before srvx");
@@ -166,6 +179,14 @@ async function serveNode(config) {
166
179
  pendingRequests: () => responses.size,
167
180
  pendingWebSockets: () => upgradedSockets.size,
168
181
  closeRealtime: () => socket?.close() ?? Promise.resolve(),
182
+ async terminateRealtime() {
183
+ const count = upgradedSockets.size;
184
+ const physicalClose = waitForUpgradedSocketDrain();
185
+ for (const activeSocket of [...upgradedSockets])
186
+ activeSocket.destroy();
187
+ await physicalClose;
188
+ return count;
189
+ },
169
190
  async stopGracefully() {
170
191
  const runtimeClose = socket ? Promise.resolve() : requireRuntime().close(false);
171
192
  requireNodeServer().closeIdleConnections?.();