stitchkit 0.136.2 → 0.136.4
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.
- package/CHANGELOG.md +14 -0
- package/dist/browser/http-fetch.d.ts +6 -0
- package/dist/browser/http-fetch.d.ts.map +1 -1
- package/dist/browser/http-helpers.d.ts +21 -0
- package/dist/browser/http-helpers.d.ts.map +1 -1
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/socket-io-client.d.ts.map +1 -1
- package/dist/browser/socket-io-connection.d.ts +18 -15
- package/dist/browser/socket-io-connection.d.ts.map +1 -1
- package/dist/browser/socket-io-contract.d.ts +26 -13
- package/dist/browser/socket-io-contract.d.ts.map +1 -1
- package/dist/browser/socket-io-default-peer.d.ts +1 -1
- package/dist/browser/socket-io-default-peer.d.ts.map +1 -1
- package/dist/browser/socket-io-explicit-peer.d.ts.map +1 -1
- package/dist/browser/socket-io-peer.d.ts +10 -0
- package/dist/browser/socket-io-peer.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/codex.js +2 -2
- package/dist/entrypoints/agent-executor/testing.js +2 -2
- package/dist/entrypoints/agent-runtime/harness.js +4 -4
- package/dist/entrypoints/agent-runtime/sandbox.js +1 -1
- package/dist/entrypoints/agent-runtime.js +4 -4
- package/dist/entrypoints/cli.js +3 -3
- package/dist/entrypoints/files.js +1 -1
- package/dist/entrypoints/handler.js +4 -4
- package/dist/entrypoints/http.js +6 -6
- package/dist/entrypoints/index.js +6 -5
- package/dist/entrypoints/node.js +3 -3
- package/dist/entrypoints/react.js +1 -1
- package/dist/entrypoints/realtime.js +3 -2
- package/dist/entrypoints/remote.js +2 -2
- package/dist/entrypoints/server.js +3 -3
- package/dist/entrypoints/sync.js +3 -3
- package/dist/entrypoints/testing.js +2 -2
- package/dist/entrypoints/tools/agent.js +3 -3
- package/dist/entrypoints/tools/invoker.js +2 -2
- package/dist/entrypoints/tools/mcp.js +3 -3
- package/dist/entrypoints/tools/toolkit.js +5 -5
- package/dist/entrypoints/tools.js +4 -4
- package/dist/{index-63ctzjp4.js → index-18qdpbcq.js} +2 -2
- package/dist/{index-8cnfgwg8.js → index-2331y2tf.js} +2 -2
- package/dist/{index-c7fj4yw9.js → index-2tgmggcm.js} +1 -1
- package/dist/{index-bjrcbcn2.js → index-2zrx0nzv.js} +1 -1
- package/dist/{index-yjx5jna7.js → index-3shdhzt6.js} +1 -1
- package/dist/{index-f0dzyskg.js → index-6f4fjygr.js} +1 -1
- package/dist/{index-y6wzzk2e.js → index-9fzjgg86.js} +1 -1
- package/dist/{index-ta0e2daw.js → index-cmqvf0dz.js} +2 -2
- package/dist/{index-cgjtj8zh.js → index-d01akj5n.js} +134 -25
- package/dist/{index-252den5a.js → index-ezwsqyad.js} +2 -2
- package/dist/{index-n2t87ggz.js → index-rr94xcj6.js} +137 -34
- package/dist/{index-k5azb3v3.js → index-vwg0n3e6.js} +2 -2
- package/llms/server.2.txt +1 -1
- package/llms/server.3.txt +18 -55
- package/llms/server.4.txt +56 -1
- package/llms/server.5.txt +1 -1
- package/llms/server.txt +1 -1
- package/llms/stitchkit.txt +10 -2
- package/llms-full.txt +27 -5
- package/llms.txt +2 -2
- package/package.json +1 -1
- package/dist/{index-b9mj31q7.js → index-9118dw8d.js} +0 -0
- package/dist/{index-kp1j7cc8.js → index-ca1v40d3.js} +3 -3
- /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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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 };
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
isToolExecutionControlError2,
|
|
13
13
|
createToolRunner,
|
|
14
14
|
formatToolError
|
|
15
|
-
} from "./index-
|
|
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-
|
|
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`, `
|
|
435
|
-
(handshake/connection failures — see
|
|
436
|
-
(observability for emits dropped while
|
|
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/stitchkit.txt
CHANGED
|
@@ -519,5 +519,13 @@ StitchKit passes that retry's current `Request.signal` in the second fetch
|
|
|
519
519
|
argument and materializes the current Request as URL + init. Next 16.3 otherwise
|
|
520
520
|
merges `init` into a Request before its dedupe layer and loses the explicit
|
|
521
521
|
signal opt-out. The retry therefore performs a new network attempt instead of
|
|
522
|
-
returning the cached rejection.
|
|
523
|
-
|
|
522
|
+
returning the cached rejection. When a retried request carries a body (for
|
|
523
|
+
example an `idempotent: true` `POST` or `PUT` with JSON or `FormData`),
|
|
524
|
+
StitchKit copies its headers and buffers the body into concrete `ArrayBuffer`
|
|
525
|
+
bytes instead of forwarding `Request.body` as a `ReadableStream` with
|
|
526
|
+
`duplex: 'half'`, so browser HTTP/1.1 transports (Chromium, WebKit) deliver the
|
|
527
|
+
retry intact. Calls whose method is not retried pass `retry: { limit: 0 }` so Ky
|
|
528
|
+
does not clone the `Request`, keeping the body as direct bytes in browser
|
|
529
|
+
DevTools Protocol and Playwright `request.postData()`. This adapter does not broaden retry policy: POST,
|
|
530
|
+
unconfigured HTTP statuses, cancellation and exhausted budgets retain the rules
|
|
531
|
+
above.
|
package/llms-full.txt
CHANGED
|
@@ -3367,8 +3367,16 @@ StitchKit passes that retry's current `Request.signal` in the second fetch
|
|
|
3367
3367
|
argument and materializes the current Request as URL + init. Next 16.3 otherwise
|
|
3368
3368
|
merges `init` into a Request before its dedupe layer and loses the explicit
|
|
3369
3369
|
signal opt-out. The retry therefore performs a new network attempt instead of
|
|
3370
|
-
returning the cached rejection.
|
|
3371
|
-
|
|
3370
|
+
returning the cached rejection. When a retried request carries a body (for
|
|
3371
|
+
example an `idempotent: true` `POST` or `PUT` with JSON or `FormData`),
|
|
3372
|
+
StitchKit copies its headers and buffers the body into concrete `ArrayBuffer`
|
|
3373
|
+
bytes instead of forwarding `Request.body` as a `ReadableStream` with
|
|
3374
|
+
`duplex: 'half'`, so browser HTTP/1.1 transports (Chromium, WebKit) deliver the
|
|
3375
|
+
retry intact. Calls whose method is not retried pass `retry: { limit: 0 }` so Ky
|
|
3376
|
+
does not clone the `Request`, keeping the body as direct bytes in browser
|
|
3377
|
+
DevTools Protocol and Playwright `request.postData()`. This adapter does not broaden retry policy: POST,
|
|
3378
|
+
unconfigured HTTP statuses, cancellation and exhausted budgets retain the rules
|
|
3379
|
+
above.
|
|
3372
3380
|
|
|
3373
3381
|
## `createClient`
|
|
3374
3382
|
|
|
@@ -14750,9 +14758,10 @@ subscribe once; reconnection is the wrapper's problem, not yours.
|
|
|
14750
14758
|
|
|
14751
14759
|
`SocketIOClientConfig` takes `url`, `path`, `withCredentials` (cookies on the
|
|
14752
14760
|
handshake — default `true`), `auth`, `query`, `extraHeaders`, `transports`,
|
|
14753
|
-
`reconnectionAttempts`, `reconnectionDelay`, `
|
|
14754
|
-
(handshake/connection failures — see
|
|
14755
|
-
(observability for emits dropped while
|
|
14761
|
+
`reconnectionAttempts`, `reconnectionDelay`, `reconnectionDelayMax`, `retain`
|
|
14762
|
+
(below), `onConnectError` (handshake/connection and peer-loader failures — see
|
|
14763
|
+
the auth section) and `onDroppedEmit` (observability for emits dropped while
|
|
14764
|
+
disconnected — see below).
|
|
14756
14765
|
|
|
14757
14766
|
### Honest emit — what happens while disconnected
|
|
14758
14767
|
|
|
@@ -14904,6 +14913,19 @@ If an auth producer throws or rejects, the wrapper sends an empty auth object
|
|
|
14904
14913
|
the server gate then rejects it visibly (via `onConnectError`) instead of
|
|
14905
14914
|
leaving the handshake waiting forever.
|
|
14906
14915
|
|
|
14916
|
+
**Peer-loader failures (`peers.client`) follow the same `terminal` split.** A
|
|
14917
|
+
permanent packaging or wiring defect — the `socket.io-client` package is absent
|
|
14918
|
+
from the artifact (`MODULE_NOT_FOUND` / `ERR_MODULE_NOT_FOUND` / `Cannot find
|
|
14919
|
+
package` / `Cannot find module`), the loader resolves to an object without a
|
|
14920
|
+
callable `io`, a required `peers.client` is omitted on `stitchkit/realtime`, the
|
|
14921
|
+
default bare-specifier loader fails on root `stitchkit`, or
|
|
14922
|
+
`reconnectionAttempts` is exhausted — reports `terminal: true` and stops
|
|
14923
|
+
retrying. A transient loader failure (such as a chunk-load or network error on a
|
|
14924
|
+
dynamic `import()`) reports `terminal: false` and retries automatically with
|
|
14925
|
+
exponential backoff bounded by `reconnectionDelay`, `reconnectionDelayMax`, and
|
|
14926
|
+
`reconnectionAttempts`. Calling `disconnect()` discards any in-flight load and
|
|
14927
|
+
cancels any pending peer-load retry.
|
|
14928
|
+
|
|
14907
14929
|
## Cache bridge
|
|
14908
14930
|
|
|
14909
14931
|
**Using a validated realtime contract? Use `createRealtimeCacheBridge`.** A
|
package/llms.txt
CHANGED
|
@@ -9,7 +9,7 @@ Build with stitchkit: define a contract once, then `implement` it and serve it (
|
|
|
9
9
|
Load the slice for each entrypoint your code imports — `import … from 'stitchkit/server'` → `llms/server.txt`; the root `stitchkit` import → `llms/stitchkit.txt`. A slice holds that entrypoint's API reference section and the guide pages whose home it is; every guide lives in exactly one slice, and a slice that needs another's guide names it under "Also read". Each file is at most 50.0 KB; a longer one continues in numbered parts, each naming the next at its top. Moving across versions: load `llms/upgrading.txt` and the range slices it lists between your version and the target. `llms-full.txt` inlines everything; it is far larger than a context window, so do not read it whole.
|
|
10
10
|
|
|
11
11
|
## Entrypoint slices
|
|
12
|
-
- **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt)
|
|
12
|
+
- **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt) 44.4 KB → [llms/stitchkit.2.txt](llms/stitchkit.2.txt) 47.2 KB → [llms/stitchkit.3.txt](llms/stitchkit.3.txt) 29.4 KB
|
|
13
13
|
- **stitchkit/live**: [llms/live.txt](llms/live.txt) 22.9 KB
|
|
14
14
|
- **stitchkit/react**: [llms/react.txt](llms/react.txt) 8.7 KB
|
|
15
15
|
- **stitchkit/react/keyboard**: [llms/react-keyboard.txt](llms/react-keyboard.txt) 22.7 KB
|
|
@@ -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)
|
|
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
|
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
|