stitchkit 0.54.0 → 0.56.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 (120) hide show
  1. package/README.md +4 -1
  2. package/dist/browser/socket-io.d.ts +25 -7
  3. package/dist/browser/socket-io.d.ts.map +1 -1
  4. package/dist/cli.js +14 -9
  5. package/dist/contract/errors.d.ts +7 -0
  6. package/dist/contract/errors.d.ts.map +1 -1
  7. package/dist/contract/file-ref.d.ts +13 -0
  8. package/dist/contract/file-ref.d.ts.map +1 -0
  9. package/dist/contract/index.d.ts +1 -0
  10. package/dist/contract/index.d.ts.map +1 -1
  11. package/dist/contract/index.js +21 -17
  12. package/dist/files/boundary.d.ts +55 -0
  13. package/dist/files/boundary.d.ts.map +1 -0
  14. package/dist/files.d.ts +3 -0
  15. package/dist/files.d.ts.map +1 -0
  16. package/dist/files.js +16 -0
  17. package/dist/index-1bx83sw4.js +4 -0
  18. package/dist/{index-pfqjb5xy.js → index-28cqssm3.js} +30 -5
  19. package/dist/index-557by2db.js +34 -0
  20. package/dist/index-5r13htq1.js +283 -0
  21. package/dist/index-6k1937bx.js +20 -0
  22. package/dist/index-6y759j86.js +1031 -0
  23. package/dist/{index-bmnhqtya.js → index-7eq9va6e.js} +1 -4
  24. package/dist/index-bfcpjw20.js +363 -0
  25. package/dist/{index-yxpe3phd.js → index-cby4ar3v.js} +1 -18
  26. package/dist/{index-7vb44hy8.js → index-escqg10p.js} +193 -751
  27. package/dist/{index-173tvqcp.js → index-j3dem06f.js} +9 -114
  28. package/dist/{index-gvha32jh.js → index-jcc611vh.js} +2 -2
  29. package/dist/{index-z7761jk2.js → index-n4nfa7gh.js} +16 -22
  30. package/dist/{index-e1es808r.js → index-qh4xevf5.js} +1 -1
  31. package/dist/index-sbdmyz75.js +18 -0
  32. package/dist/{index-b15rtha1.js → index-sm2tjx06.js} +98 -3
  33. package/dist/{index-yez419px.js → index-xy8fmh6w.js} +99 -7
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +188 -40
  37. package/dist/node.js +31 -27
  38. package/dist/observability/index.js +28 -25
  39. package/dist/react.js +2 -2
  40. package/dist/realtime/contract.d.ts +9 -0
  41. package/dist/realtime/contract.d.ts.map +1 -1
  42. package/dist/realtime/index.d.ts +2 -1
  43. package/dist/realtime/index.d.ts.map +1 -1
  44. package/dist/realtime/request.d.ts +21 -0
  45. package/dist/realtime/request.d.ts.map +1 -0
  46. package/dist/realtime/socket.d.ts +3 -0
  47. package/dist/realtime/socket.d.ts.map +1 -1
  48. package/dist/remote.d.ts +9 -0
  49. package/dist/remote.d.ts.map +1 -0
  50. package/dist/remote.js +79 -0
  51. package/dist/server/context-contribution.d.ts +18 -0
  52. package/dist/server/context-contribution.d.ts.map +1 -0
  53. package/dist/server/context.d.ts.map +1 -1
  54. package/dist/server/index.d.ts +2 -1
  55. package/dist/server/index.d.ts.map +1 -1
  56. package/dist/server/index.js +136 -88
  57. package/dist/server/lifecycle.d.ts +4 -0
  58. package/dist/server/lifecycle.d.ts.map +1 -0
  59. package/dist/server/middleware/auth.d.ts +64 -9
  60. package/dist/server/middleware/auth.d.ts.map +1 -1
  61. package/dist/server/types.d.ts +1 -1
  62. package/dist/server/types.d.ts.map +1 -1
  63. package/dist/testing/surface-conformance.d.ts +180 -0
  64. package/dist/testing/surface-conformance.d.ts.map +1 -0
  65. package/dist/testing/surface-manifest.d.ts +255 -0
  66. package/dist/testing/surface-manifest.d.ts.map +1 -0
  67. package/dist/testing.d.ts +2 -0
  68. package/dist/testing.d.ts.map +1 -1
  69. package/dist/testing.js +714 -3
  70. package/dist/tools/agent.d.ts.map +1 -1
  71. package/dist/tools/async-operation.d.ts +360 -0
  72. package/dist/tools/async-operation.d.ts.map +1 -0
  73. package/dist/tools/cli-args.d.ts +1 -1
  74. package/dist/tools/cli-args.d.ts.map +1 -1
  75. package/dist/tools/cli-format.d.ts +2 -2
  76. package/dist/tools/cli-format.d.ts.map +1 -1
  77. package/dist/tools/cli-wait.d.ts +11 -2
  78. package/dist/tools/cli-wait.d.ts.map +1 -1
  79. package/dist/tools/cli.d.ts +2 -0
  80. package/dist/tools/cli.d.ts.map +1 -1
  81. package/dist/tools/define-download-tool.d.ts +6 -5
  82. package/dist/tools/define-download-tool.d.ts.map +1 -1
  83. package/dist/tools/define-upload-tool.d.ts +3 -1
  84. package/dist/tools/define-upload-tool.d.ts.map +1 -1
  85. package/dist/tools/define-wait-tool.d.ts +1 -1
  86. package/dist/tools/define-wait-tool.d.ts.map +1 -1
  87. package/dist/tools/download-core.d.ts +5 -10
  88. package/dist/tools/download-core.d.ts.map +1 -1
  89. package/dist/tools/internal/surface-projector.d.ts +101 -0
  90. package/dist/tools/internal/surface-projector.d.ts.map +1 -0
  91. package/dist/tools/lifecycle.d.ts +4 -0
  92. package/dist/tools/lifecycle.d.ts.map +1 -0
  93. package/dist/tools/managed-file-error.d.ts +6 -0
  94. package/dist/tools/managed-file-error.d.ts.map +1 -0
  95. package/dist/tools/mcp-prepare.d.ts +3 -21
  96. package/dist/tools/mcp-prepare.d.ts.map +1 -1
  97. package/dist/tools/mcp-round-policy.d.ts +9 -0
  98. package/dist/tools/mcp-round-policy.d.ts.map +1 -0
  99. package/dist/tools/mcp-round.d.ts +0 -4
  100. package/dist/tools/mcp-round.d.ts.map +1 -1
  101. package/dist/tools/mount-download.d.ts +5 -4
  102. package/dist/tools/mount-download.d.ts.map +1 -1
  103. package/dist/tools/mount-upload.d.ts +4 -2
  104. package/dist/tools/mount-upload.d.ts.map +1 -1
  105. package/dist/tools/mount.d.ts +5 -9
  106. package/dist/tools/mount.d.ts.map +1 -1
  107. package/dist/tools/runtime-tool.d.ts.map +1 -1
  108. package/dist/tools/surface.d.ts +7 -0
  109. package/dist/tools/surface.d.ts.map +1 -1
  110. package/dist/tools/upload-core.d.ts +3 -2
  111. package/dist/tools/upload-core.d.ts.map +1 -1
  112. package/dist/tools/view-file.d.ts +4 -3
  113. package/dist/tools/view-file.d.ts.map +1 -1
  114. package/dist/tools/wait-core.d.ts +6 -1
  115. package/dist/tools/wait-core.d.ts.map +1 -1
  116. package/dist/tools.d.ts +3 -2
  117. package/dist/tools.d.ts.map +1 -1
  118. package/dist/tools.js +705 -599
  119. package/llms-full.txt +727 -34
  120. package/package.json +10 -2
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  ALL_TRANSPORTS,
3
3
  AppError,
4
+ ManagedFilePathSchema,
5
+ ManagedFileRefSchema,
4
6
  STITCH_ERROR_STATUS,
5
7
  appError,
6
8
  badRequest,
@@ -17,7 +19,7 @@ import {
17
19
  parseTrailingWildcard,
18
20
  rateLimited,
19
21
  unauthorized
20
- } from "./index-pfqjb5xy.js";
22
+ } from "./index-28cqssm3.js";
21
23
  import {
22
24
  isRecord,
23
25
  mapObject,
@@ -806,6 +808,39 @@ function createUrlBuilders(contracts, source, contractConfig) {
806
808
  function createScopedUrlBuilders(contracts, source, scopeConfigs) {
807
809
  return buildScopedRegistry(contracts, scopeConfigs, "URL builder", (contract, config) => createUrlBuilder(contract, source, config));
808
810
  }
811
+ // src/realtime/request.ts
812
+ class RealtimeRequestTimeoutError extends Error {
813
+ code = "REALTIME_REQUEST_TIMEOUT";
814
+ event;
815
+ timeoutMs;
816
+ constructor(event, timeoutMs) {
817
+ super(`Realtime request "${event}" timed out after ${timeoutMs}ms`);
818
+ this.name = "RealtimeRequestTimeoutError";
819
+ this.event = event;
820
+ this.timeoutMs = timeoutMs;
821
+ }
822
+ }
823
+
824
+ class RealtimeRequestDisconnectedError extends Error {
825
+ code = "REALTIME_REQUEST_DISCONNECTED";
826
+ event;
827
+ constructor(event) {
828
+ super(`Realtime request "${event}" was interrupted by disconnect`);
829
+ this.name = "RealtimeRequestDisconnectedError";
830
+ this.event = event;
831
+ }
832
+ }
833
+
834
+ class RealtimeRequestInvalidAcknowledgementError extends Error {
835
+ code = "REALTIME_REQUEST_INVALID_ACKNOWLEDGEMENT";
836
+ event;
837
+ constructor(event, cause) {
838
+ super(`Realtime request "${event}" received an invalid acknowledgement`, { cause });
839
+ this.name = "RealtimeRequestInvalidAcknowledgementError";
840
+ this.event = event;
841
+ }
842
+ }
843
+
809
844
  // src/realtime/rejection.ts
810
845
  import { z as z2 } from "zod";
811
846
 
@@ -884,6 +919,45 @@ function reportRejected(rejected, hook, logger) {
884
919
  console.error("[stitchkit] realtime rejection hook failed", error);
885
920
  });
886
921
  }
922
+ function parseRealtimeRequestArguments(registry, event, direction, args) {
923
+ const definition = eventDefinition(registry, event, direction);
924
+ const parsed = definition.args.safeParse(args);
925
+ if (!parsed.success) {
926
+ throw realtimeContractViolation({
927
+ event,
928
+ direction,
929
+ phase: "arguments",
930
+ reason: "invalid-arguments",
931
+ fault: "local",
932
+ cause: parsed.error
933
+ }).error;
934
+ }
935
+ if (!definition.ack) {
936
+ throw realtimeContractViolation({
937
+ event,
938
+ direction,
939
+ phase: "acknowledgement",
940
+ reason: "missing-acknowledgement",
941
+ fault: "local"
942
+ }).error;
943
+ }
944
+ return parsed.data;
945
+ }
946
+ function parseRealtimeRequestAcknowledgement(schema, event, direction, value, hook, logger) {
947
+ const parsed = schema.safeParse(value);
948
+ if (parsed.success)
949
+ return parsed.data;
950
+ const rejected = realtimeContractViolation({
951
+ event,
952
+ direction,
953
+ phase: "acknowledgement",
954
+ reason: "invalid-acknowledgement-value",
955
+ fault: "peer",
956
+ cause: parsed.error
957
+ });
958
+ reportRejected(rejected, hook, logger);
959
+ throw new RealtimeRequestInvalidAcknowledgementError(event, rejected.error);
960
+ }
887
961
  function createValidatedRealtimeSocket({
888
962
  target,
889
963
  inbound,
@@ -1046,8 +1120,18 @@ function toIoAuth(auth) {
1046
1120
  Promise.resolve().then(auth).then(cb, () => cb({}));
1047
1121
  };
1048
1122
  }
1049
- function createRealtimeClient(contract, { onRejected, logger, ...config }) {
1050
- const transport = createSocketIOClient(config);
1123
+ function assertRealtimeClientTransport(transport) {
1124
+ for (const capability of ["on", "emit", "emitWithAck", "onConnectionChange"]) {
1125
+ if (typeof Reflect.get(transport, capability) !== "function") {
1126
+ throw new TypeError(`Realtime client transport does not implement ${capability}()`);
1127
+ }
1128
+ }
1129
+ if (typeof transport.connected !== "boolean") {
1130
+ throw new TypeError("Realtime client transport does not expose boolean connected");
1131
+ }
1132
+ }
1133
+ function bindRealtimeClient(contract, transport, { onRejected, logger } = {}) {
1134
+ assertRealtimeClientTransport(transport);
1051
1135
  const events = createValidatedRealtimeSocket({
1052
1136
  target: transport,
1053
1137
  inbound: contract.serverToClient,
@@ -1070,20 +1154,51 @@ function createRealtimeClient(contract, { onRejected, logger, ...config }) {
1070
1154
  };
1071
1155
  }
1072
1156
  });
1157
+ async function request(event, ...args) {
1158
+ const options = args.at(-1);
1159
+ if (!options || typeof options !== "object" || !("timeoutMs" in options)) {
1160
+ throw new TypeError(`Realtime request "${event}" requires { timeoutMs }`);
1161
+ }
1162
+ const timeoutMs = options.timeoutMs;
1163
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
1164
+ throw new RangeError(`Realtime request "${event}" timeoutMs must be finite and > 0`);
1165
+ }
1166
+ const values = args.slice(0, -1);
1167
+ const parsedArgs = parseRealtimeRequestArguments(contract.clientToServer, event, "client-outbound", values);
1168
+ const definition = contract.clientToServer[event];
1169
+ if (!definition?.ack) {
1170
+ throw new Error(`Realtime request "${event}" has no acknowledgement schema`);
1171
+ }
1172
+ const value = await transport.emitWithAck(event, parsedArgs, { timeoutMs });
1173
+ const acknowledgement = parseRealtimeRequestAcknowledgement(definition.ack, event, "client-inbound", value, onRejected, logger);
1174
+ return acknowledgement;
1175
+ }
1073
1176
  return {
1074
1177
  ...events,
1075
- connect: transport.connect,
1076
- disconnect: transport.disconnect,
1077
1178
  get connected() {
1078
1179
  return transport.connected;
1079
1180
  },
1080
- onConnectionChange: transport.onConnectionChange
1181
+ request,
1182
+ onConnectionChange: (listener) => transport.onConnectionChange(listener)
1183
+ };
1184
+ }
1185
+ function createRealtimeClient(contract, { onRejected, logger, ...config }) {
1186
+ const transport = createSocketIOClient(config);
1187
+ const bound = bindRealtimeClient(contract, transport, { onRejected, logger });
1188
+ return {
1189
+ ...bound,
1190
+ get connected() {
1191
+ return bound.connected;
1192
+ },
1193
+ connect: transport.connect,
1194
+ disconnect: transport.disconnect
1081
1195
  };
1082
1196
  }
1083
1197
  function createSocketIOClient(config) {
1084
1198
  let socket = null;
1085
1199
  let desiredConnected = false;
1086
1200
  let reconnectTimer = null;
1201
+ const pendingRequestDisconnects = new Set;
1087
1202
  const serverDisconnectDelay = config.reconnectOnServerDisconnect ?? 1000;
1088
1203
  const connectionListeners = new Set;
1089
1204
  const subscriptions = new Set;
@@ -1169,6 +1284,8 @@ function createSocketIOClient(config) {
1169
1284
  disconnect() {
1170
1285
  desiredConnected = false;
1171
1286
  clearReconnectTimer();
1287
+ for (const reject of [...pendingRequestDisconnects])
1288
+ reject();
1172
1289
  if (!socket)
1173
1290
  return;
1174
1291
  const wasConnected = socket.connected;
@@ -1204,6 +1321,31 @@ function createSocketIOClient(config) {
1204
1321
  socket.emit(name, ...args);
1205
1322
  return true;
1206
1323
  },
1324
+ emitWithAck(event, args, options) {
1325
+ const active = socket;
1326
+ if (!active?.connected) {
1327
+ return Promise.reject(new RealtimeRequestDisconnectedError(event));
1328
+ }
1329
+ return new Promise((resolve, reject) => {
1330
+ let settled = false;
1331
+ const finish = (result) => {
1332
+ if (settled)
1333
+ return;
1334
+ settled = true;
1335
+ pendingRequestDisconnects.delete(onDisconnect);
1336
+ active.off("disconnect", onDisconnect);
1337
+ result();
1338
+ };
1339
+ const onDisconnect = () => {
1340
+ finish(() => reject(new RealtimeRequestDisconnectedError(event)));
1341
+ };
1342
+ pendingRequestDisconnects.add(onDisconnect);
1343
+ active.on("disconnect", onDisconnect);
1344
+ active.timeout(options.timeoutMs).emitWithAck(event, ...args).then((value) => finish(() => resolve(value)), () => {
1345
+ finish(() => reject(active.connected ? new RealtimeRequestTimeoutError(event, options.timeoutMs) : new RealtimeRequestDisconnectedError(event)));
1346
+ });
1347
+ });
1348
+ },
1207
1349
  onConnectionChange(listener) {
1208
1350
  connectionListeners.add(listener);
1209
1351
  return () => connectionListeners.delete(listener);
@@ -1249,39 +1391,45 @@ function defineRealtimeContract(contract) {
1249
1391
  return contract;
1250
1392
  }
1251
1393
  export {
1252
- unauthorized,
1253
- rateLimited,
1254
- parseTraceparent,
1255
- parseSSE,
1256
- paginatedSchema,
1257
- notFound,
1258
- isStitchErrorCode,
1259
- formatTraceparent,
1260
- forbidden,
1261
- encodeCursor,
1262
- defineRealtimeContract,
1263
- defineErrors,
1264
- defineContract,
1265
- decodeCursor,
1266
- createUrlBuilders,
1267
- createUrlBuilder,
1268
- createTraceContext,
1269
- createSocketIOClient,
1270
- createScopedUrlBuilders,
1271
- createScopedClients,
1272
- createRetainedTopics,
1273
- createRealtimeClient,
1274
- createHttpClient,
1275
- createContractFactory,
1276
- createClients,
1277
- createClient,
1278
- contractEndpointMatchers,
1279
- conflict,
1280
- childSpan,
1281
- badRequest,
1282
- appError,
1283
- STITCH_ERROR_STATUS,
1284
- AppError,
1394
+ ALL_TRANSPORTS,
1285
1395
  ApiError,
1286
- ALL_TRANSPORTS
1396
+ AppError,
1397
+ ManagedFilePathSchema,
1398
+ ManagedFileRefSchema,
1399
+ RealtimeRequestDisconnectedError,
1400
+ RealtimeRequestInvalidAcknowledgementError,
1401
+ RealtimeRequestTimeoutError,
1402
+ STITCH_ERROR_STATUS,
1403
+ appError,
1404
+ badRequest,
1405
+ bindRealtimeClient,
1406
+ childSpan,
1407
+ conflict,
1408
+ contractEndpointMatchers,
1409
+ createClient,
1410
+ createClients,
1411
+ createContractFactory,
1412
+ createHttpClient,
1413
+ createRealtimeClient,
1414
+ createRetainedTopics,
1415
+ createScopedClients,
1416
+ createScopedUrlBuilders,
1417
+ createSocketIOClient,
1418
+ createTraceContext,
1419
+ createUrlBuilder,
1420
+ createUrlBuilders,
1421
+ decodeCursor,
1422
+ defineContract,
1423
+ defineErrors,
1424
+ defineRealtimeContract,
1425
+ encodeCursor,
1426
+ forbidden,
1427
+ formatTraceparent,
1428
+ isStitchErrorCode,
1429
+ notFound,
1430
+ paginatedSchema,
1431
+ parseSSE,
1432
+ parseTraceparent,
1433
+ rateLimited,
1434
+ unauthorized
1287
1435
  };
package/dist/node.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  createHandler,
9
9
  createServerLifecycle,
10
10
  createSocketIOServer
11
- } from "./index-z7761jk2.js";
11
+ } from "./index-n4nfa7gh.js";
12
12
  import {
13
13
  createImplement,
14
14
  createImplementRegistry,
@@ -17,7 +17,9 @@ import {
17
17
  createScopedImplementRegistry,
18
18
  implement,
19
19
  implementRegistry
20
- } from "./index-b15rtha1.js";
20
+ } from "./index-sm2tjx06.js";
21
+ import"./index-557by2db.js";
22
+ import"./index-j3dem06f.js";
21
23
  import {
22
24
  AppError,
23
25
  appError,
@@ -27,8 +29,10 @@ import {
27
29
  notFound,
28
30
  rateLimited,
29
31
  unauthorized
30
- } from "./index-173tvqcp.js";
31
- import"./index-bmnhqtya.js";
32
+ } from "./index-5r13htq1.js";
33
+ import"./index-6k1937bx.js";
34
+ import"./index-7eq9va6e.js";
35
+ import"./index-1bx83sw4.js";
32
36
  // src/server/node.ts
33
37
  import { serve } from "srvx/node";
34
38
  async function serveNode(config) {
@@ -139,28 +143,28 @@ async function createNodeSocketIOServer(config) {
139
143
  return createSocketIOServer(config);
140
144
  }
141
145
  export {
142
- unauthorized,
143
- serveNode,
144
- rateLimited,
145
- notFound,
146
- implementRegistry,
147
- implement,
148
- forbidden,
149
- createNodeSocketIOServer as createSocketIOServer,
150
- createScopedImplementRegistry,
151
- createScopedImplement,
152
- createMultipartStream,
153
- createImplementRegistry,
154
- createImplement,
155
- createHandler,
156
- conflict,
157
- bindRealtimeServer,
158
- bindProcessSignals,
159
- badRequest,
160
- appError,
161
- ShutdownStatusSchema,
162
- ShutdownStateSchema,
163
- ShutdownResultSchema,
146
+ AppError,
164
147
  ShutdownOptionsSchema,
165
- AppError
148
+ ShutdownResultSchema,
149
+ ShutdownStateSchema,
150
+ ShutdownStatusSchema,
151
+ appError,
152
+ badRequest,
153
+ bindProcessSignals,
154
+ bindRealtimeServer,
155
+ conflict,
156
+ createHandler,
157
+ createImplement,
158
+ createImplementRegistry,
159
+ createMultipartStream,
160
+ createScopedImplement,
161
+ createScopedImplementRegistry,
162
+ createNodeSocketIOServer as createSocketIOServer,
163
+ forbidden,
164
+ implement,
165
+ implementRegistry,
166
+ notFound,
167
+ rateLimited,
168
+ serveNode,
169
+ unauthorized
166
170
  };
@@ -3,7 +3,7 @@ import {
3
3
  redact,
4
4
  sanitizePayload,
5
5
  truncatePreview
6
- } from "../index-gvha32jh.js";
6
+ } from "../index-jcc611vh.js";
7
7
  import {
8
8
  getRequestContext,
9
9
  getTraceId,
@@ -15,7 +15,9 @@ import {
15
15
  setRequestError,
16
16
  setRequestUser,
17
17
  wrapInRequestContext
18
- } from "../index-173tvqcp.js";
18
+ } from "../index-j3dem06f.js";
19
+ import"../index-5r13htq1.js";
20
+ import"../index-6k1937bx.js";
19
21
  import {
20
22
  childSpan,
21
23
  createTraceContext,
@@ -24,7 +26,8 @@ import {
24
26
  parseTraceparent,
25
27
  resolvePropagationContext,
26
28
  resolveTraceContext
27
- } from "../index-bmnhqtya.js";
29
+ } from "../index-7eq9va6e.js";
30
+ import"../index-1bx83sw4.js";
28
31
 
29
32
  // src/observability/status.ts
30
33
  import { z } from "zod";
@@ -376,27 +379,27 @@ function createObservability(config) {
376
379
  };
377
380
  }
378
381
  export {
379
- wrapInRequestContext,
380
- truncatePreview,
381
- setRequestUser,
382
- setRequestError,
383
- setRequestEndpoint,
384
- setRequestDimensions,
385
- sanitizePayload,
386
- runWithRequestContext,
387
- resolveTraceContext,
388
- resolvePropagationContext,
389
- redact,
390
- parseTraceparent,
391
- measureSize,
392
- getUserId,
393
- getTraceId,
394
- getRequestContext,
395
- formatTraceparent,
396
- createTraceContext,
397
- createObservability,
398
- childSpan,
399
- ObservabilityStatusSchema,
382
+ ObservabilityDrainReportSchema,
400
383
  ObservabilitySinkStatusSchema,
401
- ObservabilityDrainReportSchema
384
+ ObservabilityStatusSchema,
385
+ childSpan,
386
+ createObservability,
387
+ createTraceContext,
388
+ formatTraceparent,
389
+ getRequestContext,
390
+ getTraceId,
391
+ getUserId,
392
+ measureSize,
393
+ parseTraceparent,
394
+ redact,
395
+ resolvePropagationContext,
396
+ resolveTraceContext,
397
+ runWithRequestContext,
398
+ sanitizePayload,
399
+ setRequestDimensions,
400
+ setRequestEndpoint,
401
+ setRequestError,
402
+ setRequestUser,
403
+ truncatePreview,
404
+ wrapInRequestContext
402
405
  };
package/dist/react.js CHANGED
@@ -213,7 +213,7 @@ function idOf(payload, getId) {
213
213
  return hasStringId(payload) ? payload.id : getId(payload);
214
214
  }
215
215
  export {
216
- createEntityCacheHandlers,
216
+ createCacheBridge,
217
217
  createCursorQuery,
218
- createCacheBridge
218
+ createEntityCacheHandlers
219
219
  };
@@ -23,6 +23,15 @@ export type RealtimeEmitArguments<TDefinition extends RealtimeEventDefinition> =
23
23
  } ? [(value: z.output<TAck>) => void] : [])
24
24
  ];
25
25
  export type RealtimeEventHandler<TDefinition extends RealtimeEventDefinition> = (...args: RealtimeEventArguments<TDefinition>) => void;
26
+ export type RealtimeAcknowledgedEvent<TRegistry extends RealtimeEventRegistry> = {
27
+ [TEvent in keyof TRegistry]: TRegistry[TEvent] extends {
28
+ ack: z.ZodType;
29
+ } ? TEvent : never;
30
+ }[keyof TRegistry] & string;
31
+ export type RealtimeRequestArguments<TDefinition extends RealtimeEventDefinition> = z.input<TDefinition['args']> extends unknown[] ? z.input<TDefinition['args']> : never;
32
+ export type RealtimeAcknowledgement<TDefinition extends RealtimeEventDefinition> = TDefinition extends {
33
+ ack: infer TAck extends z.ZodType;
34
+ } ? z.output<TAck> : never;
26
35
  export type InferRealtimeEventMap<TRegistry extends RealtimeEventRegistry> = {
27
36
  [TEvent in keyof TRegistry]: RealtimeEventHandler<TRegistry[TEvent]>;
28
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/realtime/contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,WAAW,uBAAuB,CACtC,KAAK,SAAS,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EACzD,IAAI,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,CAAC,CAAC,OAAO,GAAG,SAAS;IAE1D,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;AAE5E,MAAM,WAAW,gBAAgB,CAC/B,eAAe,SAAS,qBAAqB,EAC7C,eAAe,SAAS,qBAAqB;IAE7C,cAAc,EAAE,eAAe,CAAC;IAChC,cAAc,EAAE,eAAe,CAAC;CACjC;AAED,wBAAgB,sBAAsB,CACpC,KAAK,CAAC,eAAe,SAAS,qBAAqB,EACnD,KAAK,CAAC,eAAe,SAAS,qBAAqB,EACnD,QAAQ,EAAE,gBAAgB,CAAC,eAAe,EAAE,eAAe,CAAC,sDAE7D;AAED,MAAM,MAAM,sBAAsB,CAAC,WAAW,SAAS,uBAAuB,IAAI;IAChF,GAAG,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,GAAG,CAAC,WAAW,SAAS;QAAE,GAAG,EAAE,MAAM,IAAI,SAAS,CAAC,CAAC,OAAO,CAAA;KAAE,GACzD,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,IAA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AErF,MAAM,MAAM,qBAAqB,CAAC,SAAS,SAAS,qBAAqB,IAAI;KAC1E,MAAM,IAAI,MAAM,SAAS,GAAG,oBAAoB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;CACrE,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAC/B,gBAAgB,GAChB,iBAAiB,GACjB,gBAAgB,GAChB,iBAAiB,CAAC;AAEtB,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,uBAAuB,CAAC;IACnC,KAAK,EAAE,WAAW,GAAG,iBAAiB,CAAC;IACvC,MAAM,EACF,eAAe,GACf,mBAAmB,GACnB,+BAA+B,GAC/B,yBAAyB,CAAC;IAC9B,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,KAAK,EAAE,QAAQ,CAAC,6BAA6B,CAAC,CAAC;CAChD;AAED,MAAM,MAAM,yBAAyB,GAAG,CACtC,QAAQ,EAAE,qBAAqB,KAC5B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -1,3 +1,4 @@
1
- export { defineRealtimeContract, type InferRealtimeEventMap, type RealtimeContract, type RealtimeEmitArguments, type RealtimeEventArguments, type RealtimeEventDefinition, type RealtimeEventHandler, type RealtimeEventRegistry, type RealtimeRejectDirection, type RealtimeRejectedEvent, type RealtimeRejectedEventHook, } from './contract';
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';
2
+ export { RealtimeRequestDisconnectedError, RealtimeRequestInvalidAcknowledgementError, type RealtimeRequestOptions, RealtimeRequestTimeoutError, } from './request';
2
3
  export type { ValidatedRealtimeSocket } from './socket';
3
4
  //# 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,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,GAC/B,MAAM,YAAY,CAAC;AACpB,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,gCAAgC,EAChC,0CAA0C,EAC1C,KAAK,sBAAsB,EAC3B,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,21 @@
1
+ export interface RealtimeRequestOptions {
2
+ /** Maximum acknowledgement wait in milliseconds. Must be finite and > 0. */
3
+ timeoutMs: number;
4
+ }
5
+ export declare class RealtimeRequestTimeoutError extends Error {
6
+ readonly code = "REALTIME_REQUEST_TIMEOUT";
7
+ readonly event: string;
8
+ readonly timeoutMs: number;
9
+ constructor(event: string, timeoutMs: number);
10
+ }
11
+ export declare class RealtimeRequestDisconnectedError extends Error {
12
+ readonly code = "REALTIME_REQUEST_DISCONNECTED";
13
+ readonly event: string;
14
+ constructor(event: string);
15
+ }
16
+ export declare class RealtimeRequestInvalidAcknowledgementError extends Error {
17
+ readonly code = "REALTIME_REQUEST_INVALID_ACKNOWLEDGEMENT";
18
+ readonly event: string;
19
+ constructor(event: string, cause: unknown);
20
+ }
21
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/realtime/request.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,IAAI,8BAA8B;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,YAAY,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAK3C;CACF;AAED,qBAAa,gCAAiC,SAAQ,KAAK;IACzD,QAAQ,CAAC,IAAI,mCAAmC;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,YAAY,KAAK,EAAE,MAAM,EAIxB;CACF;AAED,qBAAa,0CAA2C,SAAQ,KAAK;IACnE,QAAQ,CAAC,IAAI,8CAA8C;IAC3D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,YAAY,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAIxC;CACF"}
@@ -1,3 +1,4 @@
1
+ import type { z } from 'zod';
1
2
  import type { StitchLogger } from '../logger';
2
3
  import type { RealtimeEmitArguments, RealtimeEventHandler, RealtimeEventRegistry, RealtimeRejectDirection, RealtimeRejectedEventHook } from './contract';
3
4
  interface ValidatedRealtimeSocketOptions<TInbound extends RealtimeEventRegistry, TOutbound extends RealtimeEventRegistry> {
@@ -32,6 +33,8 @@ export interface ValidatedRealtimeSocket<TInbound extends RealtimeEventRegistry,
32
33
  */
33
34
  emit<TEvent extends keyof TOutbound & string>(event: TEvent, ...args: RealtimeEmitArguments<TOutbound[TEvent]>): boolean;
34
35
  }
36
+ export declare function parseRealtimeRequestArguments(registry: RealtimeEventRegistry, event: string, direction: RealtimeRejectDirection, args: unknown[]): unknown[];
37
+ export declare function parseRealtimeRequestAcknowledgement<TAck extends z.ZodType>(schema: TAck, event: string, direction: RealtimeRejectDirection, value: unknown, hook: RealtimeRejectedEventHook | undefined, logger: StitchLogger | undefined): z.output<TAck>;
35
38
  export declare function createValidatedRealtimeSocket<const TInbound extends RealtimeEventRegistry, const TOutbound extends RealtimeEventRegistry>({ target, inbound, outbound, inboundDirection, outboundDirection, onRejected, logger, subscribe, }: ValidatedRealtimeSocketOptions<TInbound, TOutbound>): ValidatedRealtimeSocket<TInbound, TOutbound>;
36
39
  export {};
37
40
  //# sourceMappingURL=socket.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/realtime/socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EACV,qBAAqB,EAErB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EAEvB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAGpB,UAAU,8BAA8B,CACtC,QAAQ,SAAS,qBAAqB,EACtC,SAAS,SAAS,qBAAqB;IAEvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;IACpB,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,iBAAiB,EAAE,uBAAuB,CAAC;IAC3C,UAAU,CAAC,EAAE,yBAAyB,CAAC;IACvC,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,E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,EAAE,OAAO,EACd,IAAI,EAAE,yBAAyB,GAAG,SAAS,EAC3C,MAAM,EAAE,YAAY,GAAG,SAAS,GAC/B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAahB;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,CAAC,QAAQ,SAAS,qBAAqB,EAC5C,KAAK,CAAC,SAAS,SAAS,qBAAqB,EAC7C,EACA,MAAM,EACN,OAAO,EACP,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,MAAM,EACN,SAAS,GACV,EAAE,8BAA8B,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,uBAAuB,CAC9E,QAAQ,EACR,SAAS,CACV,CA+HA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `stitchkit/remote` — peer-free remote service implementation.
3
+ *
4
+ * `implementRemote` needs only the contract and HTTP client. Keeping it in its
5
+ * own entrypoint lets CLI and other thin processes proxy a deployed API without
6
+ * importing the MCP SDK or the AI SDK through the broad tools barrel.
7
+ */
8
+ export { type ImplementRemoteOptions, implementRemote } from './tools/remote';
9
+ //# sourceMappingURL=remote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,sBAAsB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/remote.js ADDED
@@ -0,0 +1,79 @@
1
+ import {
2
+ ApiError,
3
+ createClient
4
+ } from "./index-qh4xevf5.js";
5
+ import"./index-48ffdxgk.js";
6
+ import {
7
+ AppError,
8
+ mergeMeta
9
+ } from "./index-5r13htq1.js";
10
+ import"./index-6k1937bx.js";
11
+ import {
12
+ isRecord
13
+ } from "./index-7eq9va6e.js";
14
+ import"./index-1bx83sw4.js";
15
+
16
+ // src/tools/remote.ts
17
+ var HTTP_ONLY = Object.freeze(["HTTP"]);
18
+ function toArgs(ctx) {
19
+ const { params, input } = ctx;
20
+ return {
21
+ ...isRecord(params) ? params : {},
22
+ ...isRecord(input) ? input : {}
23
+ };
24
+ }
25
+ function implementRemote(contract, http, options) {
26
+ const client = createClient(contract, http);
27
+ const groupScope = contract.meta.scope ?? "public";
28
+ const methods = {};
29
+ for (const [key, endpoint] of Object.entries(contract.endpoints)) {
30
+ methods[key] = {
31
+ method: endpoint.method,
32
+ path: endpoint.path,
33
+ desc: endpoint.desc,
34
+ serviceName: contract.meta.prefix,
35
+ key,
36
+ toolName: "toolName" in endpoint ? endpoint.toolName : undefined,
37
+ expose: endpoint.rawResponse || endpoint.rawBody || endpoint.responseMeta ? HTTP_ONLY : endpoint.expose,
38
+ ui: "ui" in endpoint ? endpoint.ui : undefined,
39
+ annotations: "annotations" in endpoint ? endpoint.annotations : undefined,
40
+ meta: mergeMeta(contract.meta.meta, endpoint.meta),
41
+ scope: endpoint.scope ?? groupScope,
42
+ paramsSchema: endpoint.params,
43
+ inputSchema: endpoint.input,
44
+ outputSchema: endpoint.output,
45
+ multipart: endpoint.multipart,
46
+ maxJsonBodyBytes: endpoint.maxJsonBodyBytes,
47
+ idempotent: endpoint.idempotent,
48
+ rawResponse: endpoint.rawResponse,
49
+ rawBody: endpoint.rawBody,
50
+ responseMeta: endpoint.responseMeta,
51
+ contentType: "contentType" in endpoint ? endpoint.contentType : undefined,
52
+ handler: async (ctx) => {
53
+ const call = client[key];
54
+ if (!call) {
55
+ throw new Error(`implementRemote: endpoint "${key}" is not exposed over HTTP`);
56
+ }
57
+ const args = toArgs(ctx);
58
+ try {
59
+ const finalArgs = options?.transformArgs ? await options.transformArgs(key, args) : args;
60
+ return await call(finalArgs);
61
+ } catch (err) {
62
+ if (ApiError.is(err)) {
63
+ throw new AppError(err.code, err.message, err.status, isRecord(err.details) ? err.details : undefined, err.hint, err.traceId);
64
+ }
65
+ throw err;
66
+ }
67
+ }
68
+ };
69
+ }
70
+ return {
71
+ name: contract.meta.prefix,
72
+ prefix: contract.meta.prefix,
73
+ scope: groupScope,
74
+ methods
75
+ };
76
+ }
77
+ export {
78
+ implementRemote
79
+ };
@@ -0,0 +1,18 @@
1
+ import type { RuntimeContext } from '../contract';
2
+ /** Keys whose value is owned by a transport/runtime boundary, never by application enrichment. */
3
+ export declare const RUNTIME_CONTEXT_RESERVED_KEYS: Set<string>;
4
+ /**
5
+ * Return the application-owned fields changed on an isolated context. The
6
+ * descriptors are preserved so the regular contribution validator can reject
7
+ * accessors and symbols without invoking consumer code.
8
+ */
9
+ export declare function contextContributionDelta(original: RuntimeContext, shadow: RuntimeContext, scope: string): Record<string, unknown>;
10
+ /** Validate and copy a contribution without mutating a runtime context. */
11
+ export declare function prepareContextContribution(value: unknown, scope: string): Record<string, unknown>;
12
+ /**
13
+ * Validate the complete contribution before mutating the runtime context.
14
+ * Accessors, exotic prototypes and transport-owned keys fail closed so a
15
+ * rejected contribution can never leave a partial or poisoned context.
16
+ */
17
+ export declare function mergeContextContribution(ctx: RuntimeContext, value: unknown, scope: string): void;
18
+ //# sourceMappingURL=context-contribution.d.ts.map