stitchkit 0.136.1 → 0.136.3

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 (61) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/browser/socket-io-client.d.ts.map +1 -1
  3. package/dist/browser/socket-io-connection.d.ts +18 -15
  4. package/dist/browser/socket-io-connection.d.ts.map +1 -1
  5. package/dist/browser/socket-io-contract.d.ts +26 -13
  6. package/dist/browser/socket-io-contract.d.ts.map +1 -1
  7. package/dist/browser/socket-io-default-peer.d.ts +1 -1
  8. package/dist/browser/socket-io-default-peer.d.ts.map +1 -1
  9. package/dist/browser/socket-io-explicit-peer.d.ts.map +1 -1
  10. package/dist/browser/socket-io-peer.d.ts +10 -0
  11. package/dist/browser/socket-io-peer.d.ts.map +1 -1
  12. package/dist/entrypoints/agent-executor/codex.js +2 -2
  13. package/dist/entrypoints/agent-executor/testing.js +2 -2
  14. package/dist/entrypoints/agent-runtime/harness.js +4 -4
  15. package/dist/entrypoints/agent-runtime/sandbox.js +1 -1
  16. package/dist/entrypoints/agent-runtime.js +4 -4
  17. package/dist/entrypoints/cli.js +3 -3
  18. package/dist/entrypoints/files/packaging.js +72 -36
  19. package/dist/entrypoints/files.js +1 -1
  20. package/dist/entrypoints/handler.js +4 -4
  21. package/dist/entrypoints/http.js +6 -6
  22. package/dist/entrypoints/index.js +6 -5
  23. package/dist/entrypoints/node.js +3 -3
  24. package/dist/entrypoints/react.js +1 -1
  25. package/dist/entrypoints/realtime.js +3 -2
  26. package/dist/entrypoints/remote.js +2 -2
  27. package/dist/entrypoints/server.js +3 -3
  28. package/dist/entrypoints/sync.js +3 -3
  29. package/dist/entrypoints/testing.js +2 -2
  30. package/dist/entrypoints/tools/agent.js +3 -3
  31. package/dist/entrypoints/tools/invoker.js +2 -2
  32. package/dist/entrypoints/tools/mcp.js +3 -3
  33. package/dist/entrypoints/tools/toolkit.js +5 -5
  34. package/dist/entrypoints/tools.js +4 -4
  35. package/dist/files/client-declarations.d.ts +11 -3
  36. package/dist/files/client-declarations.d.ts.map +1 -1
  37. package/dist/files/client-package.d.ts.map +1 -1
  38. package/dist/{index-63ctzjp4.js → index-18qdpbcq.js} +2 -2
  39. package/dist/{index-8cnfgwg8.js → index-2331y2tf.js} +2 -2
  40. package/dist/{index-c7fj4yw9.js → index-2tgmggcm.js} +1 -1
  41. package/dist/{index-bjrcbcn2.js → index-2zrx0nzv.js} +1 -1
  42. package/dist/{index-yjx5jna7.js → index-3shdhzt6.js} +1 -1
  43. package/dist/{index-ta0e2daw.js → index-cmqvf0dz.js} +2 -2
  44. package/dist/{index-252den5a.js → index-ezwsqyad.js} +2 -2
  45. package/dist/{index-f0dzyskg.js → index-nne3yxew.js} +1 -1
  46. package/dist/{index-n2t87ggz.js → index-rr94xcj6.js} +137 -34
  47. package/dist/{index-y6wzzk2e.js → index-rw31t8sj.js} +1 -1
  48. package/dist/{index-k5azb3v3.js → index-vwg0n3e6.js} +2 -2
  49. package/llms/process.2.txt +2 -3
  50. package/llms/server.2.txt +1 -1
  51. package/llms/server.3.txt +18 -55
  52. package/llms/server.4.txt +56 -1
  53. package/llms/server.5.txt +1 -1
  54. package/llms/server.txt +1 -1
  55. package/llms-full.txt +19 -6
  56. package/llms.txt +1 -1
  57. package/package.json +1 -1
  58. package/dist/{index-b9mj31q7.js → index-9118dw8d.js} +0 -0
  59. package/dist/{index-kp1j7cc8.js → index-ca1v40d3.js} +3 -3
  60. /package/dist/{index-cgjtj8zh.js → index-mhgkzwxz.js} +0 -0
  61. /package/dist/{index-h08xqfw9.js → index-qqd979f7.js} +0 -0
@@ -10,6 +10,9 @@ import {
10
10
  createRequestTracer,
11
11
  bindRealtimeClient2
12
12
  } from "./index-033tyx59.js";
13
+ import {
14
+ assertNonNegativeSafeInteger
15
+ } from "./index-gr0kxymw.js";
13
16
  import {
14
17
  assertTimerMs
15
18
  } from "./index-e1y74yra.js";
@@ -41,6 +44,34 @@ function createRetainedTopics2() {
41
44
  }
42
45
 
43
46
  // src/browser/socket-io-connection.ts
47
+ function assertReconnectionAttempts(value) {
48
+ if (value === undefined || value === Infinity)
49
+ return Infinity;
50
+ if (typeof value !== "number") {
51
+ throw new TypeError(`reconnectionAttempts must be a non-negative safe integer or Infinity, received ${String(value)}`);
52
+ }
53
+ assertNonNegativeSafeInteger("reconnectionAttempts", value, RangeError);
54
+ return value;
55
+ }
56
+ function createOneShotTimer() {
57
+ let timer = null;
58
+ const clear = () => {
59
+ if (timer === null)
60
+ return;
61
+ clearTimeout(timer);
62
+ timer = null;
63
+ };
64
+ return {
65
+ clear,
66
+ schedule(delay, run) {
67
+ clear();
68
+ timer = setTimeout(() => {
69
+ timer = null;
70
+ run();
71
+ }, delay);
72
+ }
73
+ };
74
+ }
44
75
  function toIoAuth(auth) {
45
76
  if (typeof auth !== "function")
46
77
  return auth;
@@ -49,6 +80,7 @@ function toIoAuth(auth) {
49
80
  };
50
81
  }
51
82
  function ioOptions(config) {
83
+ const reconnectionDelay = config.reconnectionDelay ?? 1000;
52
84
  return {
53
85
  path: config.path ?? "/socket.io/",
54
86
  withCredentials: config.withCredentials ?? true,
@@ -59,18 +91,21 @@ function ioOptions(config) {
59
91
  autoConnect: false,
60
92
  reconnection: true,
61
93
  reconnectionAttempts: config.reconnectionAttempts ?? Infinity,
62
- reconnectionDelay: config.reconnectionDelay ?? 1000,
63
- reconnectionDelayMax: config.reconnectionDelayMax ?? 5000,
94
+ reconnectionDelay,
95
+ reconnectionDelayMax: config.reconnectionDelayMax ?? Math.max(5000, reconnectionDelay),
64
96
  timeout: config.timeout ?? 20000
65
97
  };
66
98
  }
67
- function reportPeerFailure(config, error) {
68
- if (!config.onConnectError)
69
- throw error;
99
+ function reportPeerFailure(config, error, terminal) {
100
+ if (!config.onConnectError) {
101
+ if (terminal)
102
+ throw error;
103
+ return;
104
+ }
70
105
  config.onConnectError({
71
106
  message: error instanceof Error ? error.message : String(error),
72
107
  data: error,
73
- terminal: true
108
+ terminal
74
109
  });
75
110
  }
76
111
  function awaitAcknowledgement(input) {
@@ -124,23 +159,42 @@ function createStickyEvents(retain) {
124
159
  function createRecycle(delay) {
125
160
  if (delay !== false)
126
161
  assertTimerMs("reconnectOnServerDisconnect", delay, { min: 0 });
127
- let timer = null;
128
- const clear = () => {
129
- if (timer === null)
130
- return;
131
- clearTimeout(timer);
132
- timer = null;
133
- };
162
+ const slot = createOneShotTimer();
134
163
  return {
135
- clear,
164
+ clear: slot.clear,
136
165
  schedule(run) {
137
166
  if (delay === false)
138
167
  return;
139
- clear();
140
- timer = setTimeout(() => {
141
- timer = null;
142
- run();
143
- }, delay);
168
+ slot.schedule(delay, run);
169
+ }
170
+ };
171
+ }
172
+ function createPeerRetry(config) {
173
+ assertTimerMs("reconnectionDelay", config.reconnectionDelay, { min: 0 });
174
+ assertTimerMs("reconnectionDelayMax", config.reconnectionDelayMax, { min: 0 });
175
+ const maxAttempts = assertReconnectionAttempts(config.reconnectionAttempts);
176
+ const baseDelay = config.reconnectionDelay ?? 1000;
177
+ const maxDelay = config.reconnectionDelayMax ?? Math.max(5000, baseDelay);
178
+ const initialDelay = Math.min(baseDelay, maxDelay);
179
+ const slot = createOneShotTimer();
180
+ let retriesUsed = 0;
181
+ let nextDelay = initialDelay;
182
+ return {
183
+ reset() {
184
+ slot.clear();
185
+ retriesUsed = 0;
186
+ nextDelay = initialDelay;
187
+ },
188
+ nextRetryDelay() {
189
+ if (retriesUsed >= maxAttempts)
190
+ return null;
191
+ const wait = nextDelay;
192
+ retriesUsed += 1;
193
+ nextDelay = Math.min(nextDelay * 2, maxDelay);
194
+ return wait;
195
+ },
196
+ schedule(wait, run) {
197
+ slot.schedule(wait, run);
144
198
  }
145
199
  };
146
200
  }
@@ -153,6 +207,15 @@ function connectErrorReport(error, socket) {
153
207
  }
154
208
 
155
209
  // src/browser/socket-io-peer.ts
210
+ class TerminalPeerLoadError extends Error {
211
+ constructor(message, options) {
212
+ super(message, options);
213
+ this.name = "TerminalPeerLoadError";
214
+ }
215
+ }
216
+ function isTerminalPeerLoadError(error) {
217
+ return error instanceof TerminalPeerLoadError;
218
+ }
156
219
  function isIoModule(module) {
157
220
  if (typeof module !== "object" || module === null)
158
221
  return false;
@@ -168,14 +231,14 @@ function createIoResolver(injected, defaultIo) {
168
231
  const io = isIoModule(module) ? module.io : null;
169
232
  if (!io) {
170
233
  pending = null;
171
- throw new Error("stitchkit: the loader passed in `peers.client` did not return the \"socket.io-client\" module — it must resolve to the module itself, as `() => import('socket.io-client')`.");
234
+ throw new TerminalPeerLoadError("stitchkit: the loader passed in `peers.client` did not return the \"socket.io-client\" module — it must resolve to the module itself, as `() => import('socket.io-client')`.");
172
235
  }
173
236
  return io;
174
237
  }, (cause) => {
175
238
  pending = null;
176
239
  if (!isModuleNotFound(cause))
177
240
  throw cause;
178
- throw new Error('stitchkit: createSocketIOClient could not load "socket.io-client" through the loader passed in `peers` — the artifact does not contain it. Check that the loader is a literal `import(\'socket.io-client\')` your bundler can follow, and that "socket.io-client" is a dependency of the package being bundled.', { cause });
241
+ throw new TerminalPeerLoadError('stitchkit: createSocketIOClient could not load "socket.io-client" through the loader passed in `peers` — the artifact does not contain it. Check that the loader is a literal `import(\'socket.io-client\')` your bundler can follow, and that "socket.io-client" is a dependency of the package being bundled.', { cause });
179
242
  });
180
243
  }
181
244
  return pending;
@@ -198,11 +261,51 @@ function createRealtimeClientWithPeer(contract, { onRejected, logger, onRequestP
198
261
  function createSocketIOClientWithPeer(config, defaultIo) {
199
262
  return createSocketIOClientInternal(config, defaultIo);
200
263
  }
264
+ function createPeerLoadController(input) {
265
+ const retry = createPeerRetry(input.config);
266
+ let loading = false;
267
+ let epoch = 0;
268
+ function load() {
269
+ if (!input.isWanted() || loading)
270
+ return;
271
+ loading = true;
272
+ input.resolveIo().then((io) => {
273
+ loading = false;
274
+ retry.reset();
275
+ input.onLoaded(io);
276
+ }, (error) => {
277
+ loading = false;
278
+ if (!input.isWanted())
279
+ return;
280
+ const wait = isTerminalPeerLoadError(error) ? null : retry.nextRetryDelay();
281
+ if (wait === null) {
282
+ retry.reset();
283
+ input.onTerminal();
284
+ reportPeerFailure(input.config, error, true);
285
+ return;
286
+ }
287
+ const epochBefore = epoch;
288
+ try {
289
+ reportPeerFailure(input.config, error, false);
290
+ } finally {
291
+ if (input.isWanted() && !loading && epoch === epochBefore) {
292
+ retry.schedule(wait, load);
293
+ }
294
+ }
295
+ });
296
+ }
297
+ return {
298
+ load,
299
+ cancel() {
300
+ epoch += 1;
301
+ retry.reset();
302
+ }
303
+ };
304
+ }
201
305
  function createSocketIOClientInternal(config, defaultIo, onRequestPhase) {
202
306
  let socket = null;
203
307
  const resolveIo = createIoResolver(config.peers?.client, defaultIo);
204
308
  let desiredConnected = false;
205
- let loadingPeer = false;
206
309
  const recycle = createRecycle(config.reconnectOnServerDisconnect ?? 1000);
207
310
  const pendingRequestDisconnects = new Set;
208
311
  const tracer = createRequestTracer(onRequestPhase);
@@ -243,6 +346,15 @@ function createSocketIOClientInternal(config, defaultIo, onRequestPhase) {
243
346
  attach(socket);
244
347
  socket.connect();
245
348
  }
349
+ const peerLoader = createPeerLoadController({
350
+ config,
351
+ resolveIo,
352
+ isWanted: () => desiredConnected && socket === null,
353
+ onTerminal: () => {
354
+ desiredConnected = false;
355
+ },
356
+ onLoaded: openSocket
357
+ });
246
358
  return {
247
359
  get connected() {
248
360
  return socket?.connected ?? false;
@@ -255,20 +367,11 @@ function createSocketIOClientInternal(config, defaultIo, onRequestPhase) {
255
367
  socket.connect();
256
368
  return;
257
369
  }
258
- if (loadingPeer)
259
- return;
260
- loadingPeer = true;
261
- resolveIo().then((io) => {
262
- loadingPeer = false;
263
- openSocket(io);
264
- }, (error) => {
265
- loadingPeer = false;
266
- desiredConnected = false;
267
- reportPeerFailure(config, error);
268
- });
370
+ peerLoader.load();
269
371
  },
270
372
  disconnect() {
271
373
  desiredConnected = false;
374
+ peerLoader.cancel();
272
375
  recycle.clear();
273
376
  for (const reject of [...pendingRequestDisconnects])
274
377
  reject();
@@ -338,4 +441,4 @@ function createSocketIOClientInternal(config, defaultIo, onRequestPhase) {
338
441
  };
339
442
  }
340
443
 
341
- export { createRetainedTopics2, createRealtimeClientWithPeer, createSocketIOClientWithPeer };
444
+ export { createRetainedTopics2, TerminalPeerLoadError, createRealtimeClientWithPeer, createSocketIOClientWithPeer };
@@ -4,7 +4,7 @@ import {
4
4
  } from "./index-gvgtmt7a.js";
5
5
  import {
6
6
  createClient2
7
- } from "./index-f0dzyskg.js";
7
+ } from "./index-nne3yxew.js";
8
8
  import {
9
9
  ApiError2
10
10
  } from "./index-kfjkb396.js";
@@ -12,7 +12,7 @@ import {
12
12
  isToolExecutionControlError2,
13
13
  createToolRunner,
14
14
  formatToolError
15
- } from "./index-b9mj31q7.js";
15
+ } from "./index-9118dw8d.js";
16
16
  import {
17
17
  flattenToolJsonSchema2
18
18
  } from "./index-edpkm3k7.js";
@@ -21,7 +21,7 @@ import {
21
21
  } from "./index-1psbyyhj.js";
22
22
  import {
23
23
  collectToolSurface
24
- } from "./index-bjrcbcn2.js";
24
+ } from "./index-2zrx0nzv.js";
25
25
  import {
26
26
  agentPresenterOf
27
27
  } from "./index-7csn6pva.js";
@@ -316,9 +316,8 @@ version is outside the range you declared.
316
316
  Declarations are emitted with `tsconfig`, for the entries and what they import — nothing else of
317
317
  the project is typechecked or shipped. The tsconfig's directory is the root: every entry lies
318
318
  under it, and `dist/` in the archive mirrors it. A `typescript` package must be installed in the
319
- project; the build runs its compiler with the runtime that runs the build (Bun or Node), and
320
- writes a temporary `.client-package-*.tsconfig.json` beside your tsconfig for the length of the
321
- emit.
319
+ project; the build runs its compiler with the runtime that runs the build (Bun or Node) from a
320
+ generated tsconfig inside the build's temporary directory, leaving the project tree untouched.
322
321
 
323
322
  The compiler leaves relative specifiers in a declaration as the source wrote them, and a
324
323
  consumer under `moduleResolution: NodeNext` cannot resolve an extensionless one. The build
package/llms/server.2.txt CHANGED
@@ -8,7 +8,7 @@ Parts of this slice:
8
8
  - `llms/server.txt`: Guide: HTTP server (docs/guide/server.md)
9
9
  - `llms/server.2.txt`: Guide: HTTP server (docs/guide/server.md) · Guide: Realtime (docs/guide/realtime.md)
10
10
  - `llms/server.3.txt`: Guide: Realtime (docs/guide/realtime.md)
11
- - `llms/server.4.txt`: Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
11
+ - `llms/server.4.txt`: Guide: Realtime (docs/guide/realtime.md) · Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
12
12
  - `llms/server.5.txt`: API reference: `stitchkit/server` (docs/api/reference.md)
13
13
 
14
14
  Also read:
package/llms/server.3.txt CHANGED
@@ -8,7 +8,7 @@ Parts of this slice:
8
8
  - `llms/server.txt`: Guide: HTTP server (docs/guide/server.md)
9
9
  - `llms/server.2.txt`: Guide: HTTP server (docs/guide/server.md) · Guide: Realtime (docs/guide/realtime.md)
10
10
  - `llms/server.3.txt`: Guide: Realtime (docs/guide/realtime.md)
11
- - `llms/server.4.txt`: Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
11
+ - `llms/server.4.txt`: Guide: Realtime (docs/guide/realtime.md) · Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
12
12
  - `llms/server.5.txt`: API reference: `stitchkit/server` (docs/api/reference.md)
13
13
 
14
14
  Also read:
@@ -431,9 +431,10 @@ subscribe once; reconnection is the wrapper's problem, not yours.
431
431
 
432
432
  `SocketIOClientConfig` takes `url`, `path`, `withCredentials` (cookies on the
433
433
  handshake — default `true`), `auth`, `query`, `extraHeaders`, `transports`,
434
- `reconnectionAttempts`, `reconnectionDelay`, `retain` (below), `onConnectError`
435
- (handshake/connection failures — see the auth section) and `onDroppedEmit`
436
- (observability for emits dropped while disconnected — see below).
434
+ `reconnectionAttempts`, `reconnectionDelay`, `reconnectionDelayMax`, `retain`
435
+ (below), `onConnectError` (handshake/connection and peer-loader failures — see
436
+ the auth section) and `onDroppedEmit` (observability for emits dropped while
437
+ disconnected — see below).
437
438
 
438
439
  ### Honest emit — what happens while disconnected
439
440
 
@@ -585,6 +586,19 @@ If an auth producer throws or rejects, the wrapper sends an empty auth object
585
586
  the server gate then rejects it visibly (via `onConnectError`) instead of
586
587
  leaving the handshake waiting forever.
587
588
 
589
+ **Peer-loader failures (`peers.client`) follow the same `terminal` split.** A
590
+ permanent packaging or wiring defect — the `socket.io-client` package is absent
591
+ from the artifact (`MODULE_NOT_FOUND` / `ERR_MODULE_NOT_FOUND` / `Cannot find
592
+ package` / `Cannot find module`), the loader resolves to an object without a
593
+ callable `io`, a required `peers.client` is omitted on `stitchkit/realtime`, the
594
+ default bare-specifier loader fails on root `stitchkit`, or
595
+ `reconnectionAttempts` is exhausted — reports `terminal: true` and stops
596
+ retrying. A transient loader failure (such as a chunk-load or network error on a
597
+ dynamic `import()`) reports `terminal: false` and retries automatically with
598
+ exponential backoff bounded by `reconnectionDelay`, `reconnectionDelayMax`, and
599
+ `reconnectionAttempts`. Calling `disconnect()` discards any in-flight load and
600
+ cancels any pending peer-load retry.
601
+
588
602
  ## Cache bridge
589
603
 
590
604
  **Using a validated realtime contract? Use `createRealtimeCacheBridge`.** A
@@ -1056,54 +1070,3 @@ Each account's online device list is versioned (`revision`), capacity-bounded
1056
1070
  states are republished automatically after reconnect (`publishState(capability, state | null)`),
1057
1071
  and `createDevicePresenceRelayAdapter` in `stitchkit/realtime` can mirror a `DeviceRelayAgent`'s
1058
1072
  liveness into a `DevicePresenceRelayStateSchema` capability slot.
1059
-
1060
- ## User Device Relay (`stitchkit/device-relay`)
1061
-
1062
- `stitchkit/device-relay` is a peer-free evolving entrypoint for reaching a user-owned device behind
1063
- NAT over an outbound realtime connection — multiplexing Fetch-compatible unary RPCs and
1064
- credit-paced cursor streams without exposing inbound device ports:
1065
-
1066
- ```ts
1067
- // server (stitchkit/server + stitchkit/device-relay)
1068
- import { bindRealtimeServer } from 'stitchkit/server'
1069
- import {
1070
- createDeviceRelayHub,
1071
- createMemoryRelayBroker,
1072
- DEVICE_RELAY_ORIGIN,
1073
- deviceRelayRealtimeContract,
1074
- } from 'stitchkit/device-relay'
1075
-
1076
- const hub = createDeviceRelayHub<SocketIdentity>({
1077
- broker: createMemoryRelayBroker(),
1078
- authenticateDevice: ({ identity }) =>
1079
- identity.userId ? { accountId: identity.userId, deviceId: identity.deviceId } : null,
1080
- })
1081
- const unbindRelay = hub.bindRealtime(bindRealtimeServer(deviceRelayRealtimeContract, socket))
1082
-
1083
- const relayFetch = hub.createRelayFetch({ accountId: 'user-1', deviceId: 'mac-1' })
1084
- // DEVICE_RELAY_ORIGIN is 'http://device-relay.invalid' (relative paths like '/local/status' also work):
1085
- const response = await relayFetch(`${DEVICE_RELAY_ORIGIN}/local/status`)
1086
-
1087
- // device agent (stitchkit/device-relay)
1088
- import { createDeviceRelayAgent } from 'stitchkit/device-relay'
1089
-
1090
- const agent = createDeviceRelayAgent({
1091
- transport,
1092
- deviceId: 'mac-1',
1093
- capabilities: ['rpc'],
1094
- allowRpc: [{ methods: ['GET'], pathPrefix: '/local/' }],
1095
- fetch: (input, init) => localHandler(input, init),
1096
- })
1097
- ```
1098
-
1099
- - **Fail-closed routing and bounds:** unknown/offline devices, unauthorized callers, unallowlisted
1100
- paths or topics, oversized payloads, and RPC/stream capacity limits reject with typed
1101
- `DeviceRelayError` codes (`UNAUTHORIZED`, `FORBIDDEN`, `IDENTITY_MISMATCH`,
1102
- `OPERATION_NOT_ALLOWED`, `INVALID_REQUEST`, `PAYLOAD_TOO_LARGE`, `DEVICE_OFFLINE`,
1103
- `DELIVERY_UNKNOWN`, `DEVICE_BUSY`, `STREAM_CAPACITY`, `STREAM_UNAVAILABLE`, `STREAM_OVERFLOW`,
1104
- `FRAME_UNREPRESENTABLE`, `TIMEOUT`, `TRANSPORT_ERROR`, `BROKER_UNAVAILABLE`, `CLOSED`).
1105
- - **Backpressure and resume:** `hub.openRelayStream({ accountId, deviceId, topic, cursor?, share? })`
1106
- issues explicit credit frames (`DeviceRelayStreamCredit`) and carries opaque cursors so a
1107
- reconnected consumer can resume without unbounded hub buffering.
1108
- - **Horizontal scale:** replace `createMemoryRelayBroker()` with your own `RelayBrokerPort` (for
1109
- example over Redis or Postgres pub/sub) when multiple server instances hold device sockets.
package/llms/server.4.txt CHANGED
@@ -8,12 +8,67 @@ Parts of this slice:
8
8
  - `llms/server.txt`: Guide: HTTP server (docs/guide/server.md)
9
9
  - `llms/server.2.txt`: Guide: HTTP server (docs/guide/server.md) · Guide: Realtime (docs/guide/realtime.md)
10
10
  - `llms/server.3.txt`: Guide: Realtime (docs/guide/realtime.md)
11
- - `llms/server.4.txt`: Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
11
+ - `llms/server.4.txt`: Guide: Realtime (docs/guide/realtime.md) · Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
12
12
  - `llms/server.5.txt`: API reference: `stitchkit/server` (docs/api/reference.md)
13
13
 
14
14
  Also read:
15
15
  - see `llms/testing.txt` for the Testing & deployment guide
16
16
 
17
+ ==============================================================================
18
+ # Guide: Realtime (docs/guide/realtime.md) (continued)
19
+ ==============================================================================
20
+
21
+ ## User Device Relay (`stitchkit/device-relay`)
22
+
23
+ `stitchkit/device-relay` is a peer-free evolving entrypoint for reaching a user-owned device behind
24
+ NAT over an outbound realtime connection — multiplexing Fetch-compatible unary RPCs and
25
+ credit-paced cursor streams without exposing inbound device ports:
26
+
27
+ ```ts
28
+ // server (stitchkit/server + stitchkit/device-relay)
29
+ import { bindRealtimeServer } from 'stitchkit/server'
30
+ import {
31
+ createDeviceRelayHub,
32
+ createMemoryRelayBroker,
33
+ DEVICE_RELAY_ORIGIN,
34
+ deviceRelayRealtimeContract,
35
+ } from 'stitchkit/device-relay'
36
+
37
+ const hub = createDeviceRelayHub<SocketIdentity>({
38
+ broker: createMemoryRelayBroker(),
39
+ authenticateDevice: ({ identity }) =>
40
+ identity.userId ? { accountId: identity.userId, deviceId: identity.deviceId } : null,
41
+ })
42
+ const unbindRelay = hub.bindRealtime(bindRealtimeServer(deviceRelayRealtimeContract, socket))
43
+
44
+ const relayFetch = hub.createRelayFetch({ accountId: 'user-1', deviceId: 'mac-1' })
45
+ // DEVICE_RELAY_ORIGIN is 'http://device-relay.invalid' (relative paths like '/local/status' also work):
46
+ const response = await relayFetch(`${DEVICE_RELAY_ORIGIN}/local/status`)
47
+
48
+ // device agent (stitchkit/device-relay)
49
+ import { createDeviceRelayAgent } from 'stitchkit/device-relay'
50
+
51
+ const agent = createDeviceRelayAgent({
52
+ transport,
53
+ deviceId: 'mac-1',
54
+ capabilities: ['rpc'],
55
+ allowRpc: [{ methods: ['GET'], pathPrefix: '/local/' }],
56
+ fetch: (input, init) => localHandler(input, init),
57
+ })
58
+ ```
59
+
60
+ - **Fail-closed routing and bounds:** unknown/offline devices, unauthorized callers, unallowlisted
61
+ paths or topics, oversized payloads, and RPC/stream capacity limits reject with typed
62
+ `DeviceRelayError` codes (`UNAUTHORIZED`, `FORBIDDEN`, `IDENTITY_MISMATCH`,
63
+ `OPERATION_NOT_ALLOWED`, `INVALID_REQUEST`, `PAYLOAD_TOO_LARGE`, `DEVICE_OFFLINE`,
64
+ `DELIVERY_UNKNOWN`, `DEVICE_BUSY`, `STREAM_CAPACITY`, `STREAM_UNAVAILABLE`, `STREAM_OVERFLOW`,
65
+ `FRAME_UNREPRESENTABLE`, `TIMEOUT`, `TRANSPORT_ERROR`, `BROKER_UNAVAILABLE`, `CLOSED`).
66
+ - **Backpressure and resume:** `hub.openRelayStream({ accountId, deviceId, topic, cursor?, share? })`
67
+ issues explicit credit frames (`DeviceRelayStreamCredit`) and carries opaque cursors so a
68
+ reconnected consumer can resume without unbounded hub buffering.
69
+ - **Horizontal scale:** replace `createMemoryRelayBroker()` with your own `RelayBrokerPort` (for
70
+ example over Redis or Postgres pub/sub) when multiple server instances hold device sockets.
71
+
17
72
  ==============================================================================
18
73
  # Guide: Auth & errors (docs/guide/auth-and-errors.md)
19
74
  ==============================================================================
package/llms/server.5.txt CHANGED
@@ -7,7 +7,7 @@ Parts of this slice:
7
7
  - `llms/server.txt`: Guide: HTTP server (docs/guide/server.md)
8
8
  - `llms/server.2.txt`: Guide: HTTP server (docs/guide/server.md) · Guide: Realtime (docs/guide/realtime.md)
9
9
  - `llms/server.3.txt`: Guide: Realtime (docs/guide/realtime.md)
10
- - `llms/server.4.txt`: Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
10
+ - `llms/server.4.txt`: Guide: Realtime (docs/guide/realtime.md) · Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
11
11
  - `llms/server.5.txt`: API reference: `stitchkit/server` (docs/api/reference.md)
12
12
 
13
13
  Also read:
package/llms/server.txt CHANGED
@@ -8,7 +8,7 @@ Parts of this slice:
8
8
  - `llms/server.txt`: Guide: HTTP server (docs/guide/server.md)
9
9
  - `llms/server.2.txt`: Guide: HTTP server (docs/guide/server.md) · Guide: Realtime (docs/guide/realtime.md)
10
10
  - `llms/server.3.txt`: Guide: Realtime (docs/guide/realtime.md)
11
- - `llms/server.4.txt`: Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
11
+ - `llms/server.4.txt`: Guide: Realtime (docs/guide/realtime.md) · Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
12
12
  - `llms/server.5.txt`: API reference: `stitchkit/server` (docs/api/reference.md)
13
13
 
14
14
  Also read:
package/llms-full.txt CHANGED
@@ -11757,9 +11757,8 @@ version is outside the range you declared.
11757
11757
  Declarations are emitted with `tsconfig`, for the entries and what they import — nothing else of
11758
11758
  the project is typechecked or shipped. The tsconfig's directory is the root: every entry lies
11759
11759
  under it, and `dist/` in the archive mirrors it. A `typescript` package must be installed in the
11760
- project; the build runs its compiler with the runtime that runs the build (Bun or Node), and
11761
- writes a temporary `.client-package-*.tsconfig.json` beside your tsconfig for the length of the
11762
- emit.
11760
+ project; the build runs its compiler with the runtime that runs the build (Bun or Node) from a
11761
+ generated tsconfig inside the build's temporary directory, leaving the project tree untouched.
11763
11762
 
11764
11763
  The compiler leaves relative specifiers in a declaration as the source wrote them, and a
11765
11764
  consumer under `moduleResolution: NodeNext` cannot resolve an extensionless one. The build
@@ -14751,9 +14750,10 @@ subscribe once; reconnection is the wrapper's problem, not yours.
14751
14750
 
14752
14751
  `SocketIOClientConfig` takes `url`, `path`, `withCredentials` (cookies on the
14753
14752
  handshake — default `true`), `auth`, `query`, `extraHeaders`, `transports`,
14754
- `reconnectionAttempts`, `reconnectionDelay`, `retain` (below), `onConnectError`
14755
- (handshake/connection failures — see the auth section) and `onDroppedEmit`
14756
- (observability for emits dropped while disconnected — see below).
14753
+ `reconnectionAttempts`, `reconnectionDelay`, `reconnectionDelayMax`, `retain`
14754
+ (below), `onConnectError` (handshake/connection and peer-loader failures — see
14755
+ the auth section) and `onDroppedEmit` (observability for emits dropped while
14756
+ disconnected — see below).
14757
14757
 
14758
14758
  ### Honest emit — what happens while disconnected
14759
14759
 
@@ -14905,6 +14905,19 @@ If an auth producer throws or rejects, the wrapper sends an empty auth object
14905
14905
  the server gate then rejects it visibly (via `onConnectError`) instead of
14906
14906
  leaving the handshake waiting forever.
14907
14907
 
14908
+ **Peer-loader failures (`peers.client`) follow the same `terminal` split.** A
14909
+ permanent packaging or wiring defect — the `socket.io-client` package is absent
14910
+ from the artifact (`MODULE_NOT_FOUND` / `ERR_MODULE_NOT_FOUND` / `Cannot find
14911
+ package` / `Cannot find module`), the loader resolves to an object without a
14912
+ callable `io`, a required `peers.client` is omitted on `stitchkit/realtime`, the
14913
+ default bare-specifier loader fails on root `stitchkit`, or
14914
+ `reconnectionAttempts` is exhausted — reports `terminal: true` and stops
14915
+ retrying. A transient loader failure (such as a chunk-load or network error on a
14916
+ dynamic `import()`) reports `terminal: false` and retries automatically with
14917
+ exponential backoff bounded by `reconnectionDelay`, `reconnectionDelayMax`, and
14918
+ `reconnectionAttempts`. Calling `disconnect()` discards any in-flight load and
14919
+ cancels any pending peer-load retry.
14920
+
14908
14921
  ## Cache bridge
14909
14922
 
14910
14923
  **Using a validated realtime contract? Use `createRealtimeCacheBridge`.** A
package/llms.txt CHANGED
@@ -27,7 +27,7 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
27
27
  - **stitchkit/contract**: [llms/contract.txt](llms/contract.txt) 36.5 KB
28
28
  - **stitchkit/primitives**: [llms/primitives.txt](llms/primitives.txt) 15.2 KB
29
29
  - **stitchkit/handler**: [llms/handler.txt](llms/handler.txt) 2.3 KB
30
- - **stitchkit/server**: [llms/server.txt](llms/server.txt) 47.7 KB → [llms/server.2.txt](llms/server.2.txt) 46.4 KB → [llms/server.3.txt](llms/server.3.txt) 47.1 KB → [llms/server.4.txt](llms/server.4.txt) 43.9 KB → [llms/server.5.txt](llms/server.5.txt) 26.7 KB
30
+ - **stitchkit/server**: [llms/server.txt](llms/server.txt) 47.7 KB → [llms/server.2.txt](llms/server.2.txt) 46.4 KB → [llms/server.3.txt](llms/server.3.txt) 45.6 KB → [llms/server.4.txt](llms/server.4.txt) 46.5 KB → [llms/server.5.txt](llms/server.5.txt) 26.8 KB
31
31
  - **stitchkit/observability**: [llms/observability.txt](llms/observability.txt) 40.3 KB → [llms/observability.2.txt](llms/observability.2.txt) 10.1 KB
32
32
  - **stitchkit/agent-runtime**: [llms/agent-runtime.txt](llms/agent-runtime.txt) 37.0 KB → [llms/agent-runtime.2.txt](llms/agent-runtime.2.txt) 44.2 KB → [llms/agent-runtime.3.txt](llms/agent-runtime.3.txt) 38.2 KB → [llms/agent-runtime.4.txt](llms/agent-runtime.4.txt) 34.1 KB → [llms/agent-runtime.5.txt](llms/agent-runtime.5.txt) 44.5 KB → [llms/agent-runtime.6.txt](llms/agent-runtime.6.txt) 17.5 KB
33
33
  - **stitchkit/agent-runtime/testing**: [llms/agent-runtime-testing.txt](llms/agent-runtime-testing.txt) 3.8 KB
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stitchkit",
3
- "version": "0.136.1",
3
+ "version": "0.136.3",
4
4
  "description": "Contract-first backend framework — one defineContract() into an HTTP API, MCP tools, AI-agent tools and a typed client. Bun and Node.",
5
5
  "keywords": [
6
6
  "bun",
File without changes
@@ -15,12 +15,12 @@ import {
15
15
  import {
16
16
  UnixClientTransportError2
17
17
  } from "./index-cv9b7fz2.js";
18
- import {
19
- assertNonNegativeSafeInteger
20
- } from "./index-gr0kxymw.js";
21
18
  import {
22
19
  randomHex
23
20
  } from "./index-c9d05kvt.js";
21
+ import {
22
+ assertNonNegativeSafeInteger
23
+ } from "./index-gr0kxymw.js";
24
24
 
25
25
  // src/internal/unix-socket.ts
26
26
  import { linkSync as linkSync2, lstatSync as lstatSync2, unlinkSync as unlinkSync2 } from "node:fs";
File without changes
File without changes