stitchkit 0.136.2 → 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 (56) hide show
  1. package/CHANGELOG.md +7 -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.js +1 -1
  19. package/dist/entrypoints/handler.js +4 -4
  20. package/dist/entrypoints/http.js +6 -6
  21. package/dist/entrypoints/index.js +6 -5
  22. package/dist/entrypoints/node.js +3 -3
  23. package/dist/entrypoints/react.js +1 -1
  24. package/dist/entrypoints/realtime.js +3 -2
  25. package/dist/entrypoints/remote.js +2 -2
  26. package/dist/entrypoints/server.js +3 -3
  27. package/dist/entrypoints/sync.js +3 -3
  28. package/dist/entrypoints/testing.js +2 -2
  29. package/dist/entrypoints/tools/agent.js +3 -3
  30. package/dist/entrypoints/tools/invoker.js +2 -2
  31. package/dist/entrypoints/tools/mcp.js +3 -3
  32. package/dist/entrypoints/tools/toolkit.js +5 -5
  33. package/dist/entrypoints/tools.js +4 -4
  34. package/dist/{index-63ctzjp4.js → index-18qdpbcq.js} +2 -2
  35. package/dist/{index-8cnfgwg8.js → index-2331y2tf.js} +2 -2
  36. package/dist/{index-c7fj4yw9.js → index-2tgmggcm.js} +1 -1
  37. package/dist/{index-bjrcbcn2.js → index-2zrx0nzv.js} +1 -1
  38. package/dist/{index-yjx5jna7.js → index-3shdhzt6.js} +1 -1
  39. package/dist/{index-ta0e2daw.js → index-cmqvf0dz.js} +2 -2
  40. package/dist/{index-252den5a.js → index-ezwsqyad.js} +2 -2
  41. package/dist/{index-f0dzyskg.js → index-nne3yxew.js} +1 -1
  42. package/dist/{index-n2t87ggz.js → index-rr94xcj6.js} +137 -34
  43. package/dist/{index-y6wzzk2e.js → index-rw31t8sj.js} +1 -1
  44. package/dist/{index-k5azb3v3.js → index-vwg0n3e6.js} +2 -2
  45. package/llms/server.2.txt +1 -1
  46. package/llms/server.3.txt +18 -55
  47. package/llms/server.4.txt +56 -1
  48. package/llms/server.5.txt +1 -1
  49. package/llms/server.txt +1 -1
  50. package/llms-full.txt +17 -3
  51. package/llms.txt +1 -1
  52. package/package.json +1 -1
  53. package/dist/{index-b9mj31q7.js → index-9118dw8d.js} +0 -0
  54. package/dist/{index-kp1j7cc8.js → index-ca1v40d3.js} +3 -3
  55. /package/dist/{index-cgjtj8zh.js → index-mhgkzwxz.js} +0 -0
  56. /package/dist/{index-h08xqfw9.js → index-qqd979f7.js} +0 -0
@@ -4,7 +4,7 @@ import"../../index-ha1tv70k.js";
4
4
  import"../../index-d1pdv8qc.js";
5
5
  import"../../index-dm50x3by.js";
6
6
  import"../../index-qj0sq69b.js";
7
- import"../../index-b9mj31q7.js";
7
+ import"../../index-9118dw8d.js";
8
8
  import"../../index-yt1gg11x.js";
9
9
  import"../../index-edpkm3k7.js";
10
10
  import"../../index-0x4mnwg5.js";
@@ -20,7 +20,7 @@ import {
20
20
  createMcpHandler2,
21
21
  createMcpHttpRoute2,
22
22
  createStdioMcpServer2
23
- } from "../../index-252den5a.js";
23
+ } from "../../index-ezwsqyad.js";
24
24
  import {
25
25
  DEFAULT_PROCESS_SIGNALS,
26
26
  defaultSignalSource,
@@ -34,7 +34,7 @@ import {
34
34
  mcpCatalogMeta2,
35
35
  readMcpCatalogStamp2
36
36
  } from "../../index-5t4fpdct.js";
37
- import"../../index-bjrcbcn2.js";
37
+ import"../../index-2zrx0nzv.js";
38
38
  import"../../index-7csn6pva.js";
39
39
  // src/tools/mcp/stdio-signals.ts
40
40
  var bound = new WeakSet;
@@ -3,13 +3,13 @@ import"../../index-d1pdv8qc.js";
3
3
  import"../../index-dsa676h8.js";
4
4
  import"../../index-dm50x3by.js";
5
5
  import"../../index-qj0sq69b.js";
6
- import"../../index-b9mj31q7.js";
6
+ import"../../index-9118dw8d.js";
7
7
  import"../../index-yt1gg11x.js";
8
8
  import"../../index-edpkm3k7.js";
9
9
  import"../../index-werjqesf.js";
10
10
  import {
11
11
  createCli2
12
- } from "../../index-63ctzjp4.js";
12
+ } from "../../index-18qdpbcq.js";
13
13
  import"../../index-0x4mnwg5.js";
14
14
  import"../../index-6kec3b14.js";
15
15
  import"../../index-gy9x38a2.js";
@@ -20,15 +20,15 @@ import {
20
20
  buildMcpServer2,
21
21
  createMcpHandler2,
22
22
  createStdioMcpServer2
23
- } from "../../index-252den5a.js";
23
+ } from "../../index-ezwsqyad.js";
24
24
  import"../../index-efbzm2se.js";
25
25
  import"../../index-a09r9ff0.js";
26
26
  import {
27
27
  mountAgentTools2
28
- } from "../../index-k5azb3v3.js";
28
+ } from "../../index-vwg0n3e6.js";
29
29
  import"../../index-rjs94dny.js";
30
30
  import"../../index-xrgn784x.js";
31
- import"../../index-bjrcbcn2.js";
31
+ import"../../index-2zrx0nzv.js";
32
32
  import"../../index-7csn6pva.js";
33
33
 
34
34
  // src/tools/toolkit.ts
@@ -18,7 +18,7 @@ import {
18
18
  ToolExecutionControlError2,
19
19
  isToolExecutionControlError2,
20
20
  collectTools2
21
- } from "../index-b9mj31q7.js";
21
+ } from "../index-9118dw8d.js";
22
22
  import {
23
23
  ALL_TRANSPORTS2,
24
24
  TOOL_TRANSPORTS2
@@ -81,14 +81,14 @@ import {
81
81
  import {
82
82
  defineAgentTool2,
83
83
  mountAgentTools2
84
- } from "../index-k5azb3v3.js";
84
+ } from "../index-vwg0n3e6.js";
85
85
  import {
86
86
  AgentToolError2,
87
87
  isAgentToolError2
88
88
  } from "../index-1psbyyhj.js";
89
89
  import {
90
90
  createToolInvoker2
91
- } from "../index-yjx5jna7.js";
91
+ } from "../index-3shdhzt6.js";
92
92
  import {
93
93
  WaitTimeoutError,
94
94
  runWaitOperation,
@@ -101,7 +101,7 @@ import {
101
101
  } from "../index-dz6tstcp.js";
102
102
  import {
103
103
  collectToolSurface
104
- } from "../index-bjrcbcn2.js";
104
+ } from "../index-2zrx0nzv.js";
105
105
  import {
106
106
  getTraceId2
107
107
  } from "../index-q4tr9vnf.js";
@@ -32,7 +32,7 @@ import {
32
32
  toolCauseFromResult,
33
33
  createToolRunner,
34
34
  formatToolError
35
- } from "./index-b9mj31q7.js";
35
+ } from "./index-9118dw8d.js";
36
36
  import {
37
37
  isRepeatableRead
38
38
  } from "./index-0x4mnwg5.js";
@@ -67,7 +67,7 @@ import {
67
67
  } from "./index-9vj869rx.js";
68
68
  import {
69
69
  collectToolSurface
70
- } from "./index-bjrcbcn2.js";
70
+ } from "./index-2zrx0nzv.js";
71
71
  import {
72
72
  validateDeclaredOutput
73
73
  } from "./index-dwq6a6sq.js";
@@ -46,7 +46,7 @@ import {
46
46
  import {
47
47
  ToolExecutionControlError2,
48
48
  isToolExecutionControlError2
49
- } from "./index-b9mj31q7.js";
49
+ } from "./index-9118dw8d.js";
50
50
  import {
51
51
  AGENT_TOOL_PROGRESS_MESSAGE_MAX2,
52
52
  agentDurableEventId2
@@ -96,7 +96,7 @@ import {
96
96
  } from "./index-fatke81t.js";
97
97
  import {
98
98
  finalizeAgentToolOutput
99
- } from "./index-k5azb3v3.js";
99
+ } from "./index-vwg0n3e6.js";
100
100
  import {
101
101
  AgentToolError2,
102
102
  isAgentToolError2
@@ -2,7 +2,7 @@ import {
2
2
  assertUnixSocketPathLength,
3
3
  assertExpectedOwnerUid,
4
4
  unixSocketDirectoryViolation
5
- } from "./index-kp1j7cc8.js";
5
+ } from "./index-ca1v40d3.js";
6
6
  import {
7
7
  errnoOf
8
8
  } from "./index-jj9228tt.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-edpkm3k7.js";
4
4
  import {
5
5
  contractToolMountable
6
- } from "./index-b9mj31q7.js";
6
+ } from "./index-9118dw8d.js";
7
7
  import {
8
8
  runtimeToolMountable
9
9
  } from "./index-7csn6pva.js";
@@ -3,7 +3,7 @@ import {
3
3
  toolErrorFromResult,
4
4
  collectTools2,
5
5
  createToolRunner
6
- } from "./index-b9mj31q7.js";
6
+ } from "./index-9118dw8d.js";
7
7
  import {
8
8
  assertUniqueToolName
9
9
  } from "./index-edpkm3k7.js";
@@ -5,10 +5,10 @@ import {
5
5
  assertUnixSocketPathLength,
6
6
  assertExpectedOwnerUid,
7
7
  assertUnixSocketClientTarget
8
- } from "./index-kp1j7cc8.js";
8
+ } from "./index-ca1v40d3.js";
9
9
  import {
10
10
  DEFAULT_REQUEST_BODY_BYTES
11
- } from "./index-h08xqfw9.js";
11
+ } from "./index-qqd979f7.js";
12
12
  import {
13
13
  secretsEqual
14
14
  } from "./index-apv5xfef.js";
@@ -13,7 +13,7 @@ import {
13
13
  collectTools2,
14
14
  createToolRunner,
15
15
  formatToolError
16
- } from "./index-b9mj31q7.js";
16
+ } from "./index-9118dw8d.js";
17
17
  import {
18
18
  toolSurfaceOutputSchema,
19
19
  presentationMetadata
@@ -51,7 +51,7 @@ import {
51
51
  } from "./index-9vj869rx.js";
52
52
  import {
53
53
  collectToolSurface
54
- } from "./index-bjrcbcn2.js";
54
+ } from "./index-2zrx0nzv.js";
55
55
  import {
56
56
  runWithRequestContext2,
57
57
  getRequestContext2
@@ -20,7 +20,7 @@ import {
20
20
  isAbortLikeError,
21
21
  classifyUnixTransportRetry,
22
22
  parseApiErrorBody
23
- } from "./index-cgjtj8zh.js";
23
+ } from "./index-mhgkzwxz.js";
24
24
  import {
25
25
  DEFAULT_STREAM_LINE_BYTES,
26
26
  createBoundedLineDecoder,
@@ -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";
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.