stitchkit 0.68.9 → 0.68.11

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/dist/agent-runtime/deferred-tool-search.d.ts +8 -0
  2. package/dist/agent-runtime/deferred-tool-search.d.ts.map +1 -0
  3. package/dist/agent-runtime/deferred-tool-selection.d.ts +15 -0
  4. package/dist/agent-runtime/deferred-tool-selection.d.ts.map +1 -0
  5. package/dist/agent-runtime/deferred-tool-types.d.ts +131 -0
  6. package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -0
  7. package/dist/agent-runtime/deferred-tools-internal.d.ts +10 -0
  8. package/dist/agent-runtime/deferred-tools-internal.d.ts.map +1 -0
  9. package/dist/agent-runtime/deferred-tools.d.ts +4 -0
  10. package/dist/agent-runtime/deferred-tools.d.ts.map +1 -0
  11. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  12. package/dist/agent-runtime-openrouter.js +1 -1
  13. package/dist/agent-runtime.d.ts +1 -0
  14. package/dist/agent-runtime.d.ts.map +1 -1
  15. package/dist/agent-runtime.js +471 -73
  16. package/dist/browser/socket-io.d.ts +8 -2
  17. package/dist/browser/socket-io.d.ts.map +1 -1
  18. package/dist/cli.js +7 -8
  19. package/dist/contract/index.js +2 -2
  20. package/dist/{index-vkk06pv1.js → index-22by16v6.js} +57 -9
  21. package/dist/{index-hmfpjnh7.js → index-22tjt2rk.js} +2 -2
  22. package/dist/{index-1bmpkhj2.js → index-2t6zt5cg.js} +9 -134
  23. package/dist/{index-557by2db.js → index-7b188kmz.js} +15 -0
  24. package/dist/index-bt5179zb.js +99 -0
  25. package/dist/index-eqqyd9v8.js +130 -0
  26. package/dist/{index-51a19y3v.js → index-f24xg2cw.js} +2 -2
  27. package/dist/{index-j2nq04z6.js → index-f6n5n7nz.js} +1 -1
  28. package/dist/{index-9t2tdk1x.js → index-grgvpbch.js} +3 -5
  29. package/dist/{index-n34x0q5e.js → index-hb0mncmj.js} +3 -3
  30. package/dist/{index-6tqys26z.js → index-hcx9yypn.js} +4 -4
  31. package/dist/{index-z575awm9.js → index-hxh98zbm.js} +2 -2
  32. package/dist/{index-bmmtz6r9.js → index-pgsyp3xh.js} +1 -1
  33. package/dist/index-qyrqwr4c.js +41 -0
  34. package/dist/{index-r5s4wqb5.js → index-t23p2b68.js} +1 -1
  35. package/dist/{index-3ydx9j01.js → index-xyvxez9r.js} +3 -3
  36. package/dist/{index-04agqrs8.js → index-y2ctppmg.js} +72 -6
  37. package/dist/index.js +171 -13
  38. package/dist/internal/typed.d.ts +8 -0
  39. package/dist/internal/typed.d.ts.map +1 -1
  40. package/dist/node.js +6 -6
  41. package/dist/observability/index.js +4 -4
  42. package/dist/react.js +1 -1
  43. package/dist/realtime/index.d.ts +1 -1
  44. package/dist/realtime/index.d.ts.map +1 -1
  45. package/dist/realtime/request.d.ts +25 -0
  46. package/dist/realtime/request.d.ts.map +1 -1
  47. package/dist/remote.js +4 -4
  48. package/dist/server/index.js +8 -8
  49. package/dist/testing.js +6 -7
  50. package/dist/tool-invoker.js +6 -8
  51. package/dist/tools/internal/surface-projector.d.ts +7 -0
  52. package/dist/tools/internal/surface-projector.d.ts.map +1 -1
  53. package/dist/tools.js +34 -115
  54. package/llms-full.txt +127 -2
  55. package/package.json +1 -1
  56. package/dist/index-6djpbnda.js +0 -56
  57. package/dist/index-88yyydag.js +0 -75
  58. package/dist/index-smpbdg6k.js +0 -27
  59. /package/dist/{index-tss6bk5c.js → index-ksp6e2ye.js} +0 -0
@@ -3,17 +3,17 @@ import {
3
3
  inputIsQuery,
4
4
  parseSSE,
5
5
  readBoundedUtf8Lines
6
- } from "./index-r5s4wqb5.js";
6
+ } from "./index-t23p2b68.js";
7
7
  import {
8
8
  ContractStreamFrameSchema,
9
9
  DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
10
10
  parseTrailingWildcard
11
- } from "./index-bmmtz6r9.js";
11
+ } from "./index-pgsyp3xh.js";
12
12
  import {
13
13
  isRecord,
14
14
  mapObject,
15
15
  typedEntries
16
- } from "./index-smpbdg6k.js";
16
+ } from "./index-qyrqwr4c.js";
17
17
 
18
18
  // src/browser/cancellation.ts
19
19
  class RequestCancellationError extends Error {
@@ -7,7 +7,7 @@ import {
7
7
  defaultSignalSource,
8
8
  guardSignalCallback,
9
9
  reportSignalError
10
- } from "./index-z575awm9.js";
10
+ } from "./index-hxh98zbm.js";
11
11
  import {
12
12
  extractIp,
13
13
  getClientInfo,
@@ -18,7 +18,7 @@ import {
18
18
  runWithRequestContext,
19
19
  setRequestEndpoint,
20
20
  setRequestError
21
- } from "./index-51a19y3v.js";
21
+ } from "./index-f24xg2cw.js";
22
22
  import {
23
23
  ShutdownOptionsSchema
24
24
  } from "./index-dk6e56g0.js";
@@ -34,11 +34,11 @@ import {
34
34
  safeJsonParse,
35
35
  validateDeclaredOutput,
36
36
  zodIssues
37
- } from "./index-bmmtz6r9.js";
37
+ } from "./index-pgsyp3xh.js";
38
38
  import {
39
39
  isRecord,
40
40
  transportResult
41
- } from "./index-smpbdg6k.js";
41
+ } from "./index-qyrqwr4c.js";
42
42
  import {
43
43
  AppError,
44
44
  badRequest
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  isUnsafeKey,
3
3
  mergeMeta
4
- } from "./index-bmmtz6r9.js";
4
+ } from "./index-pgsyp3xh.js";
5
5
  import {
6
6
  callRuntimeHandler,
7
7
  isRecord,
8
8
  transportResult,
9
9
  typedEntries
10
- } from "./index-smpbdg6k.js";
10
+ } from "./index-qyrqwr4c.js";
11
11
 
12
12
  // src/server/middleware/cors.ts
13
13
  var DEFAULT_CORS_ALLOW_HEADERS = "Content-Type, Authorization, X-Trace-Id, traceparent, tracestate";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isRecord
3
- } from "./index-smpbdg6k.js";
3
+ } from "./index-qyrqwr4c.js";
4
4
  import {
5
5
  AppError
6
6
  } from "./index-0w9abg87.js";
@@ -0,0 +1,41 @@
1
+ // src/internal/typed.ts
2
+ function typedEntries(value) {
3
+ return Object.entries(value);
4
+ }
5
+ function isRecord(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
8
+ function callRuntimeHandler(handler, context) {
9
+ if (typeof handler !== "function") {
10
+ throw new TypeError("Runtime handler must be a function");
11
+ }
12
+ return Reflect.apply(handler, undefined, [context]);
13
+ }
14
+ function executableAgentRuntimeTools(tools) {
15
+ for (const tool of tools) {
16
+ if (typeof tool.handler !== "function") {
17
+ throw new TypeError(`Runtime tool "${tool.name}" must provide a handler`);
18
+ }
19
+ if (tool.present?.agent !== undefined && typeof tool.present.agent !== "function") {
20
+ throw new TypeError(`Runtime tool "${tool.name}" Agent presenter must be a function`);
21
+ }
22
+ if (tool.present?.agent !== undefined && tool.output === undefined) {
23
+ throw new TypeError(`Runtime tool "${tool.name}" Agent presenter requires an output schema`);
24
+ }
25
+ }
26
+ return tools;
27
+ }
28
+ function transportResult(value) {
29
+ return value;
30
+ }
31
+ function mapObject(source, mapper) {
32
+ const result = {};
33
+ for (const [key, value] of typedEntries(source)) {
34
+ const mapped = mapper(key, value);
35
+ if (mapped !== undefined)
36
+ result[key] = mapped;
37
+ }
38
+ return result;
39
+ }
40
+
41
+ export { typedEntries, isRecord, callRuntimeHandler, executableAgentRuntimeTools, transportResult, mapObject };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  normalizeError
3
- } from "./index-bmmtz6r9.js";
3
+ } from "./index-pgsyp3xh.js";
4
4
 
5
5
  // src/internal/bounded-lines.ts
6
6
  var DEFAULT_STREAM_LINE_BYTES = 1024 * 1024;
@@ -2,16 +2,16 @@ import {
2
2
  contextContributionDelta,
3
3
  mergeContextContribution,
4
4
  prepareContextContribution
5
- } from "./index-z575awm9.js";
5
+ } from "./index-hxh98zbm.js";
6
6
  import {
7
7
  base64UrlToBytes,
8
8
  bytesToBase64Url,
9
9
  isUnsafeKey,
10
10
  safeJsonParse
11
- } from "./index-bmmtz6r9.js";
11
+ } from "./index-pgsyp3xh.js";
12
12
  import {
13
13
  isRecord
14
- } from "./index-smpbdg6k.js";
14
+ } from "./index-qyrqwr4c.js";
15
15
  import {
16
16
  forbidden,
17
17
  unauthorized
@@ -1,20 +1,24 @@
1
1
  import {
2
2
  getRequestContext,
3
3
  runWithRequestContext
4
- } from "./index-51a19y3v.js";
4
+ } from "./index-f24xg2cw.js";
5
5
  import {
6
- objectShapeKeys
7
- } from "./index-6djpbnda.js";
6
+ assertToolExtensionCompatible,
7
+ mergeSchemas,
8
+ objectShapeKeys,
9
+ projectToolSurface,
10
+ rebuildObject
11
+ } from "./index-22by16v6.js";
8
12
  import {
9
13
  formatZodError,
10
14
  isUnsafeKey,
11
15
  normalizeError,
12
16
  safeJsonParse,
13
17
  validateDeclaredOutput
14
- } from "./index-bmmtz6r9.js";
18
+ } from "./index-pgsyp3xh.js";
15
19
  import {
16
20
  isRecord
17
- } from "./index-smpbdg6k.js";
21
+ } from "./index-qyrqwr4c.js";
18
22
  import {
19
23
  AppError,
20
24
  STITCH_ERROR_STATUS,
@@ -335,4 +339,66 @@ async function runToolMethod(method, toolName, rawArgs, context, hooks, lifecycl
335
339
  }
336
340
  }
337
341
 
338
- export { coerceJsonArgs, ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod };
342
+ // src/tools/mount.ts
343
+ import { z as z2 } from "zod";
344
+ function applyExtend(base, extra) {
345
+ if (base instanceof z2.ZodObject) {
346
+ assertToolExtensionCompatible(base, extra);
347
+ return rebuildObject(base, { ...extra, ...base.shape });
348
+ }
349
+ return z2.intersection(z2.object(extra), base);
350
+ }
351
+ function contractToolMountable(projected, extend) {
352
+ const method = projected.source;
353
+ const baseArgumentSchema = mergeSchemas(method.paramsSchema, method.inputSchema);
354
+ const argumentSchema = projected.shouldExtend && extend ? applyExtend(baseArgumentSchema, extend.schema) : baseArgumentSchema;
355
+ return {
356
+ method,
357
+ name: projected.name,
358
+ argumentSchema,
359
+ presentationSchema: projected.presentationSchema,
360
+ shouldExtend: projected.shouldExtend
361
+ };
362
+ }
363
+ function collectTools(service, transport, config = {}) {
364
+ const { extend, flattenUnionInput = false, assertNames = true } = config;
365
+ const tools = [];
366
+ for (const projected of projectToolSurface({ services: [service] }, transport === "HTTP" ? "AGENT" : transport, {
367
+ extend,
368
+ flattenUnionInput,
369
+ assertNames,
370
+ assertUniqueNames: false
371
+ })) {
372
+ if (projected.kind !== "contract")
373
+ continue;
374
+ tools.push(contractToolMountable(projected, extend));
375
+ }
376
+ return tools;
377
+ }
378
+ function createToolRunner(config) {
379
+ const extension = config.extend ? {
380
+ schema: z2.object(config.extend.schema),
381
+ resolve: config.extend.resolve
382
+ } : undefined;
383
+ return async function runOneToolCall(tool, rawArgs, context) {
384
+ return executeToolMethod(tool.method, tool.name, rawArgs, { ...config.context, ...context, source: config.source }, config.hooks, config.lifecycle, config.coerceJsonArgs ?? true, config.onOutputStrip ? (paths) => config.onOutputStrip?.(tool.name, paths) : undefined, tool.shouldExtend ? extension : undefined);
385
+ };
386
+ }
387
+ function formatToolError(result, toolName, errorHint) {
388
+ const err = { error: result.code };
389
+ if (result.details)
390
+ err.details = result.details;
391
+ const hints = [];
392
+ if (result.hint)
393
+ hints.push(result.hint);
394
+ if (errorHint && toolName) {
395
+ const global = errorHint(toolName, result.code);
396
+ if (global)
397
+ hints.push(global);
398
+ }
399
+ if (hints.length > 0)
400
+ err._hint = hints.join(" ");
401
+ return err;
402
+ }
403
+
404
+ export { coerceJsonArgs, ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod, contractToolMountable, collectTools, createToolRunner, formatToolError };
package/dist/index.js CHANGED
@@ -21,13 +21,13 @@ import {
21
21
  parseTrailingWildcard,
22
22
  rateLimited,
23
23
  unauthorized
24
- } from "./index-j2nq04z6.js";
24
+ } from "./index-f6n5n7nz.js";
25
25
  import {
26
26
  isRecord,
27
27
  mapObject,
28
28
  transportResult,
29
29
  typedEntries
30
- } from "./index-tss6bk5c.js";
30
+ } from "./index-ksp6e2ye.js";
31
31
 
32
32
  // src/browser/cancellation.ts
33
33
  class RequestCancellationError extends Error {
@@ -1099,6 +1099,21 @@ function isModuleNotFound(error) {
1099
1099
  }
1100
1100
 
1101
1101
  // src/realtime/request.ts
1102
+ import { z as z2 } from "zod";
1103
+ var RealtimeRequestPhaseSchema = z2.enum([
1104
+ "engine-handoff",
1105
+ "engine-ack-received",
1106
+ "settled",
1107
+ "timeout",
1108
+ "disconnected"
1109
+ ]);
1110
+ var RealtimeRequestPhaseEventSchema = z2.object({
1111
+ requestId: z2.string().min(1),
1112
+ event: z2.string().min(1),
1113
+ phase: RealtimeRequestPhaseSchema,
1114
+ elapsedMs: z2.number().finite().nonnegative()
1115
+ }).strict();
1116
+
1102
1117
  class RealtimeRequestTimeoutError extends Error {
1103
1118
  code = "REALTIME_REQUEST_TIMEOUT";
1104
1119
  event;
@@ -1186,9 +1201,9 @@ function parseIssues(value) {
1186
1201
  }
1187
1202
 
1188
1203
  // src/realtime/rejection.ts
1189
- import { z as z2 } from "zod";
1204
+ import { z as z3 } from "zod";
1190
1205
  function realtimeContractViolation(options) {
1191
- const issues = options.cause instanceof z2.ZodError ? zodIssues(options.cause) : undefined;
1206
+ const issues = options.cause instanceof z3.ZodError ? zodIssues(options.cause) : undefined;
1192
1207
  const reason = options.reason.replaceAll("-", " ");
1193
1208
  const error = new AppError("REALTIME_CONTRACT_VIOLATION", `Realtime event "${options.event}" (${options.direction}, ${options.phase}): ${reason}`, 500, {
1194
1209
  event: options.event,
@@ -1469,6 +1484,63 @@ function createRetainedTopics() {
1469
1484
  }
1470
1485
 
1471
1486
  // src/browser/socket-io.ts
1487
+ var realtimeRequestTraces = new WeakMap;
1488
+ function observeRealtimeRequestPhase(trace, phase) {
1489
+ const observation = {
1490
+ requestId: trace.requestId,
1491
+ event: trace.event,
1492
+ phase,
1493
+ elapsedMs: performance.now() - trace.startedAt
1494
+ };
1495
+ try {
1496
+ const result = trace.observe(observation);
1497
+ if (result)
1498
+ Promise.resolve(result).catch(() => {
1499
+ return;
1500
+ });
1501
+ } catch {}
1502
+ }
1503
+ function socketIoPacketIdentity(data, expected) {
1504
+ if (typeof data !== "string")
1505
+ return null;
1506
+ const type = data.charAt(0);
1507
+ const binary = type === (expected === "event" ? "5" : "6");
1508
+ if (type !== (expected === "event" ? "2" : "3") && !binary)
1509
+ return null;
1510
+ let offset = 1;
1511
+ if (binary) {
1512
+ const separator = data.indexOf("-", offset);
1513
+ if (separator < 0)
1514
+ return null;
1515
+ for (let index = offset;index < separator; index += 1) {
1516
+ const code = data.charCodeAt(index);
1517
+ if (code < 48 || code > 57)
1518
+ return null;
1519
+ }
1520
+ offset = separator + 1;
1521
+ }
1522
+ let namespace = "/";
1523
+ if (data.charAt(offset) === "/") {
1524
+ const separator = data.indexOf(",", offset);
1525
+ if (separator < 0)
1526
+ return null;
1527
+ namespace = data.slice(offset, separator);
1528
+ offset = separator + 1;
1529
+ }
1530
+ const start = offset;
1531
+ while (offset < data.length) {
1532
+ const code = data.charCodeAt(offset);
1533
+ if (code < 48 || code > 57)
1534
+ break;
1535
+ offset += 1;
1536
+ }
1537
+ if (offset === start)
1538
+ return null;
1539
+ return { namespace, id: data.slice(start, offset) };
1540
+ }
1541
+ function packetIdentityKey(identity) {
1542
+ return `${identity.namespace}:${identity.id}`;
1543
+ }
1472
1544
  var SOCKET_IO_CLIENT = "socket.io-client";
1473
1545
  var ioLoader = null;
1474
1546
  function loadIo() {
@@ -1564,8 +1636,20 @@ function bindRealtimeClient(contract, transport, { onRejected, logger } = {}) {
1564
1636
  if (!definition?.ack) {
1565
1637
  throw new Error(`Realtime request "${event}" has no acknowledgement schema`);
1566
1638
  }
1567
- const value = await transport.emitWithAck(event, parsedArgs, { timeoutMs });
1568
- const acknowledgement = parseRealtimeRequestAcknowledgement(definition.ack, event, "client-inbound", value, onRejected, logger);
1639
+ const pending = transport.emitWithAck(event, parsedArgs, { timeoutMs });
1640
+ const trace = realtimeRequestTraces.get(pending);
1641
+ if (trace)
1642
+ realtimeRequestTraces.delete(pending);
1643
+ const value = await pending;
1644
+ let acknowledgement;
1645
+ try {
1646
+ acknowledgement = parseRealtimeRequestAcknowledgement(definition.ack, event, "client-inbound", value, onRejected, logger);
1647
+ } finally {
1648
+ if (trace && !trace.closed) {
1649
+ trace.closed = true;
1650
+ observeRealtimeRequestPhase(trace, "settled");
1651
+ }
1652
+ }
1569
1653
  return acknowledgement;
1570
1654
  }
1571
1655
  return {
@@ -1577,8 +1661,8 @@ function bindRealtimeClient(contract, transport, { onRejected, logger } = {}) {
1577
1661
  onConnectionChange: (listener) => transport.onConnectionChange(listener)
1578
1662
  };
1579
1663
  }
1580
- function createRealtimeClient(contract, { onRejected, logger, ...config }) {
1581
- const transport = createSocketIOClient(config);
1664
+ function createRealtimeClient(contract, { onRejected, logger, onRequestPhase, ...config }) {
1665
+ const transport = createSocketIOClientInternal(config, onRequestPhase);
1582
1666
  const bound = bindRealtimeClient(contract, transport, { onRejected, logger });
1583
1667
  return {
1584
1668
  ...bound,
@@ -1590,12 +1674,17 @@ function createRealtimeClient(contract, { onRejected, logger, ...config }) {
1590
1674
  };
1591
1675
  }
1592
1676
  function createSocketIOClient(config) {
1677
+ return createSocketIOClientInternal(config);
1678
+ }
1679
+ function createSocketIOClientInternal(config, onRequestPhase) {
1593
1680
  let socket = null;
1594
1681
  const resolveIo = createIoResolver(config.peers?.client);
1595
1682
  let desiredConnected = false;
1596
1683
  let loadingPeer = false;
1597
1684
  let reconnectTimer = null;
1598
1685
  const pendingRequestDisconnects = new Set;
1686
+ const requestTracesByNativeKey = new Map;
1687
+ let startingRequestTrace = null;
1599
1688
  const serverDisconnectDelay = config.reconnectOnServerDisconnect ?? 1000;
1600
1689
  const connectionListeners = new Set;
1601
1690
  const subscriptions = new Set;
@@ -1629,6 +1718,37 @@ function createSocketIOClient(config) {
1629
1718
  reconnectionDelayMax: config.reconnectionDelayMax ?? 5000,
1630
1719
  timeout: config.timeout ?? 20000
1631
1720
  });
1721
+ if (onRequestPhase) {
1722
+ socket.io.on("open", () => {
1723
+ const engine = socket?.io.engine;
1724
+ if (!engine)
1725
+ return;
1726
+ engine.on("packetCreate", (packet) => {
1727
+ if (!startingRequestTrace || packet.type !== "message")
1728
+ return;
1729
+ const identity = socketIoPacketIdentity(packet.data, "event");
1730
+ if (!identity)
1731
+ return;
1732
+ const key = packetIdentityKey(identity);
1733
+ startingRequestTrace.nativeKey = key;
1734
+ requestTracesByNativeKey.set(key, startingRequestTrace);
1735
+ observeRealtimeRequestPhase(startingRequestTrace, "engine-handoff");
1736
+ });
1737
+ engine.on("packet", (packet) => {
1738
+ if (packet.type !== "message")
1739
+ return;
1740
+ const identity = socketIoPacketIdentity(packet.data, "ack");
1741
+ if (!identity)
1742
+ return;
1743
+ const key = packetIdentityKey(identity);
1744
+ const trace = requestTracesByNativeKey.get(key);
1745
+ if (!trace || trace.closed)
1746
+ return;
1747
+ observeRealtimeRequestPhase(trace, "engine-ack-received");
1748
+ requestTracesByNativeKey.delete(key);
1749
+ });
1750
+ });
1751
+ }
1632
1752
  socket.on("connect", () => notifyConnection(true));
1633
1753
  socket.on("disconnect", (reason) => {
1634
1754
  notifyConnection(false, reason);
@@ -1738,11 +1858,30 @@ function createSocketIOClient(config) {
1738
1858
  return true;
1739
1859
  },
1740
1860
  emitWithAck(event, args, options) {
1861
+ const trace = onRequestPhase ? {
1862
+ requestId: crypto.randomUUID(),
1863
+ event,
1864
+ startedAt: performance.now(),
1865
+ observe: onRequestPhase,
1866
+ closed: false
1867
+ } : undefined;
1868
+ const closeTrace = (phase) => {
1869
+ if (!trace || trace.closed)
1870
+ return;
1871
+ trace.closed = true;
1872
+ if (trace.nativeKey)
1873
+ requestTracesByNativeKey.delete(trace.nativeKey);
1874
+ observeRealtimeRequestPhase(trace, phase);
1875
+ };
1741
1876
  const active = socket;
1742
1877
  if (!active?.connected) {
1743
- return Promise.reject(new RealtimeRequestDisconnectedError(event));
1878
+ const pending2 = Promise.reject(new RealtimeRequestDisconnectedError(event));
1879
+ closeTrace("disconnected");
1880
+ if (trace)
1881
+ realtimeRequestTraces.set(pending2, trace);
1882
+ return pending2;
1744
1883
  }
1745
- return new Promise((resolve, reject) => {
1884
+ const pending = new Promise((resolve, reject) => {
1746
1885
  let settled = false;
1747
1886
  const finish = (result) => {
1748
1887
  if (settled)
@@ -1753,14 +1892,31 @@ function createSocketIOClient(config) {
1753
1892
  result();
1754
1893
  };
1755
1894
  const onDisconnect = () => {
1756
- finish(() => reject(new RealtimeRequestDisconnectedError(event)));
1895
+ finish(() => {
1896
+ closeTrace("disconnected");
1897
+ reject(new RealtimeRequestDisconnectedError(event));
1898
+ });
1757
1899
  };
1758
1900
  pendingRequestDisconnects.add(onDisconnect);
1759
1901
  active.on("disconnect", onDisconnect);
1760
- active.timeout(options.timeoutMs).emitWithAck(event, ...args).then((value) => finish(() => resolve(value)), () => {
1761
- finish(() => reject(active.connected ? new RealtimeRequestTimeoutError(event, options.timeoutMs) : new RealtimeRequestDisconnectedError(event)));
1902
+ let acknowledgement;
1903
+ startingRequestTrace = trace ?? null;
1904
+ try {
1905
+ acknowledgement = active.timeout(options.timeoutMs).emitWithAck(event, ...args);
1906
+ } finally {
1907
+ startingRequestTrace = null;
1908
+ }
1909
+ acknowledgement.then((value) => finish(() => resolve(value)), () => {
1910
+ finish(() => {
1911
+ const connected = active.connected;
1912
+ closeTrace(connected ? "timeout" : "disconnected");
1913
+ reject(connected ? new RealtimeRequestTimeoutError(event, options.timeoutMs) : new RealtimeRequestDisconnectedError(event));
1914
+ });
1762
1915
  });
1763
1916
  });
1917
+ if (trace)
1918
+ realtimeRequestTraces.set(pending, trace);
1919
+ return pending;
1764
1920
  },
1765
1921
  onConnectionChange(listener) {
1766
1922
  connectionListeners.add(listener);
@@ -1783,6 +1939,8 @@ export {
1783
1939
  REALTIME_REJECTION_KEY,
1784
1940
  RealtimeRequestDisconnectedError,
1785
1941
  RealtimeRequestInvalidAcknowledgementError,
1942
+ RealtimeRequestPhaseEventSchema,
1943
+ RealtimeRequestPhaseSchema,
1786
1944
  RealtimeRequestRejectedError,
1787
1945
  RealtimeRequestTimeoutError,
1788
1946
  STITCH_ERROR_STATUS,
@@ -1,3 +1,5 @@
1
+ import type { SurfaceAgentRuntimeToolDefinition } from '../tools/internal/surface-projector.js';
2
+ import type { RuntimeToolDefinition } from '../tools/runtime-tool.js';
1
3
  export declare function typedEntries<T extends object>(value: T): Array<{
2
4
  [K in keyof T]: [K, T[K]];
3
5
  }[keyof T]>;
@@ -5,6 +7,12 @@ export declare function typedEntries<T extends object>(value: T): Array<{
5
7
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
6
8
  /** Invoke a runtime-discovered handler after a fail-first function check. */
7
9
  export declare function callRuntimeHandler(handler: unknown, context: unknown): unknown;
10
+ /**
11
+ * Agent-only public declarations use a peer-free structural tool definition.
12
+ * Construction validates executable functions before this boundary restores
13
+ * the richer internal definition consumed by the canonical mount.
14
+ */
15
+ export declare function executableAgentRuntimeTools(tools: readonly SurfaceAgentRuntimeToolDefinition[]): readonly RuntimeToolDefinition[];
8
16
  /**
9
17
  * Isolated loose-to-typed adapter boundary for transports whose decoder is
10
18
  * selected at runtime while the contract fixes the generic result type.
@@ -1 +1 @@
1
- {"version":3,"file":"typed.d.ts","sourceRoot":"","sources":["../../src/internal/typed.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC3C,KAAK,EAAE,CAAC,GACP,KAAK,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAE/C;AAED,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAK9E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAEpD;AAED,wBAAgB,SAAS,CACvB,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS;KAAG,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,EAAE,OAAO;CAAE,EAElD,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,GACrF,OAAO,CAOT;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS;KAAG,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,EAAE,OAAO;CAAE,EAElD,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,OAAO,CAAC,KAAK,OAAO,GACrE,OAAO,CAKT"}
1
+ {"version":3,"file":"typed.d.ts","sourceRoot":"","sources":["../../src/internal/typed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC3C,KAAK,EAAE,CAAC,GACP,KAAK,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAE/C;AAED,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAK9E;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,SAAS,iCAAiC,EAAE,GAClD,SAAS,qBAAqB,EAAE,CAelC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAEpD;AAED,wBAAgB,SAAS,CACvB,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS;KAAG,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,EAAE,OAAO;CAAE,EAElD,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,GACrF,OAAO,CAOT;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS;KAAG,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,EAAE,OAAO;CAAE,EAElD,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,OAAO,CAAC,KAAK,OAAO,GACrE,OAAO,CAKT"}
package/dist/node.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createHandler,
6
6
  createSocketIOServer,
7
7
  createUnixClientTransport
8
- } from "./index-6tqys26z.js";
8
+ } from "./index-hcx9yypn.js";
9
9
  import {
10
10
  createImplement,
11
11
  createImplementRegistry,
@@ -14,9 +14,9 @@ import {
14
14
  createScopedImplementRegistry,
15
15
  implement,
16
16
  implementRegistry
17
- } from "./index-z575awm9.js";
18
- import"./index-51a19y3v.js";
19
- import"./index-557by2db.js";
17
+ } from "./index-hxh98zbm.js";
18
+ import"./index-f24xg2cw.js";
19
+ import"./index-7b188kmz.js";
20
20
  import {
21
21
  ShutdownOptionsSchema,
22
22
  ShutdownResultSchema,
@@ -24,8 +24,8 @@ import {
24
24
  ShutdownStatusSchema,
25
25
  createServerLifecycle
26
26
  } from "./index-dk6e56g0.js";
27
- import"./index-bmmtz6r9.js";
28
- import"./index-smpbdg6k.js";
27
+ import"./index-pgsyp3xh.js";
28
+ import"./index-qyrqwr4c.js";
29
29
  import {
30
30
  AppError,
31
31
  appError,
@@ -10,7 +10,7 @@ import {
10
10
  redact,
11
11
  sanitizePayload,
12
12
  truncatePreview
13
- } from "../index-hmfpjnh7.js";
13
+ } from "../index-22tjt2rk.js";
14
14
  import {
15
15
  getRequestContext,
16
16
  getTraceId,
@@ -21,7 +21,7 @@ import {
21
21
  setRequestError,
22
22
  setRequestUser,
23
23
  wrapInRequestContext
24
- } from "../index-51a19y3v.js";
24
+ } from "../index-f24xg2cw.js";
25
25
  import {
26
26
  childSpan,
27
27
  createTraceContext,
@@ -30,10 +30,10 @@ import {
30
30
  recordedErrorMessage,
31
31
  resolvePropagationContext,
32
32
  resolveTraceContext
33
- } from "../index-bmmtz6r9.js";
33
+ } from "../index-pgsyp3xh.js";
34
34
  import {
35
35
  isRecord
36
- } from "../index-smpbdg6k.js";
36
+ } from "../index-qyrqwr4c.js";
37
37
  import"../index-0w9abg87.js";
38
38
  import"../index-6k1937bx.js";
39
39
 
package/dist/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isRecord
3
- } from "./index-tss6bk5c.js";
3
+ } from "./index-ksp6e2ye.js";
4
4
 
5
5
  // src/react/cache-bridge.ts
6
6
  function createCacheBridge(config) {
@@ -1,5 +1,5 @@
1
1
  export { defineRealtimeContract, type InferRealtimeEventMap, type RealtimeAcknowledgedEvent, type RealtimeAcknowledgement, type RealtimeContract, type RealtimeEmitArguments, type RealtimeEventArguments, type RealtimeEventDefinition, type RealtimeEventHandler, type RealtimeEventRegistry, type RealtimeRejectDirection, type RealtimeRejectedEvent, type RealtimeRejectedEventHook, type RealtimeRequestArguments, } from './contract.js';
2
2
  export { asRealtimeRejection, REALTIME_REJECTION_KEY, type RealtimeRejectionEnvelope, type RealtimeRejectionIssue, type RealtimeRejectionReport, } from './rejected-frame.js';
3
- export { RealtimeRequestDisconnectedError, RealtimeRequestInvalidAcknowledgementError, type RealtimeRequestOptions, RealtimeRequestRejectedError, RealtimeRequestTimeoutError, } from './request.js';
3
+ export { RealtimeRequestDisconnectedError, RealtimeRequestInvalidAcknowledgementError, type RealtimeRequestOptions, type RealtimeRequestPhase, type RealtimeRequestPhaseEvent, RealtimeRequestPhaseEventSchema, type RealtimeRequestPhaseHook, RealtimeRequestPhaseSchema, RealtimeRequestRejectedError, RealtimeRequestTimeoutError, } from './request.js';
4
4
  export type { ValidatedRealtimeSocket } from './socket.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gCAAgC,EAChC,0CAA0C,EAC1C,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gCAAgC,EAChC,0CAA0C,EAC1C,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,+BAA+B,EAC/B,KAAK,wBAAwB,EAC7B,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC"}
@@ -1,4 +1,29 @@
1
+ import { z } from 'zod';
1
2
  import type { RealtimeRejectionIssue } from './rejected-frame.js';
3
+ /** Closed lifecycle reported by an opt-in acknowledged-request observer. */
4
+ export declare const RealtimeRequestPhaseSchema: z.ZodEnum<{
5
+ disconnected: "disconnected";
6
+ "engine-ack-received": "engine-ack-received";
7
+ "engine-handoff": "engine-handoff";
8
+ settled: "settled";
9
+ timeout: "timeout";
10
+ }>;
11
+ /** Metadata-only observation: no arguments, acknowledgement or packet bytes. */
12
+ export declare const RealtimeRequestPhaseEventSchema: z.ZodObject<{
13
+ requestId: z.ZodString;
14
+ event: z.ZodString;
15
+ phase: z.ZodEnum<{
16
+ disconnected: "disconnected";
17
+ "engine-ack-received": "engine-ack-received";
18
+ "engine-handoff": "engine-handoff";
19
+ settled: "settled";
20
+ timeout: "timeout";
21
+ }>;
22
+ elapsedMs: z.ZodNumber;
23
+ }, z.core.$strict>;
24
+ export type RealtimeRequestPhase = z.infer<typeof RealtimeRequestPhaseSchema>;
25
+ export type RealtimeRequestPhaseEvent = z.infer<typeof RealtimeRequestPhaseEventSchema>;
26
+ export type RealtimeRequestPhaseHook = (event: RealtimeRequestPhaseEvent) => void | Promise<void>;
2
27
  export interface RealtimeRequestOptions {
3
28
  /** Maximum acknowledgement wait in milliseconds. Must be finite and > 0. */
4
29
  timeoutMs: number;