stitchkit 0.110.0 → 0.110.2

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 (142) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/agent-runtime/archive-spill.d.ts +61 -0
  3. package/dist/agent-runtime/archive-spill.d.ts.map +1 -0
  4. package/dist/agent-runtime/branch-contract.d.ts +102 -0
  5. package/dist/agent-runtime/branch-contract.d.ts.map +1 -0
  6. package/dist/agent-runtime/branch-events.d.ts +18 -0
  7. package/dist/agent-runtime/branch-events.d.ts.map +1 -0
  8. package/dist/agent-runtime/branch-identities.d.ts +20 -0
  9. package/dist/agent-runtime/branch-identities.d.ts.map +1 -0
  10. package/dist/agent-runtime/branch-messages.d.ts +32 -0
  11. package/dist/agent-runtime/branch-messages.d.ts.map +1 -0
  12. package/dist/agent-runtime/branch-observations.d.ts +104 -0
  13. package/dist/agent-runtime/branch-observations.d.ts.map +1 -0
  14. package/dist/agent-runtime/branch-provider.d.ts +130 -0
  15. package/dist/agent-runtime/branch-provider.d.ts.map +1 -0
  16. package/dist/agent-runtime/branch-replay.d.ts +426 -0
  17. package/dist/agent-runtime/branch-replay.d.ts.map +1 -0
  18. package/dist/agent-runtime/branch-source.d.ts +16 -0
  19. package/dist/agent-runtime/branch-source.d.ts.map +1 -0
  20. package/dist/agent-runtime/branch-transitions.d.ts +6 -0
  21. package/dist/agent-runtime/branch-transitions.d.ts.map +1 -0
  22. package/dist/agent-runtime/sqlite-history.d.ts.map +1 -1
  23. package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -1
  24. package/dist/agent-runtime/store-archive.d.ts +1 -0
  25. package/dist/agent-runtime/store-archive.d.ts.map +1 -1
  26. package/dist/agent-runtime/store-branch.d.ts +5 -0
  27. package/dist/agent-runtime/store-branch.d.ts.map +1 -0
  28. package/dist/agent-runtime/store-conformance-branch.d.ts +4 -0
  29. package/dist/agent-runtime/store-conformance-branch.d.ts.map +1 -0
  30. package/dist/agent-runtime/store-conformance-lifecycle.d.ts +10 -10
  31. package/dist/agent-runtime/store-conformance.d.ts.map +1 -1
  32. package/dist/agent-runtime/store-create.d.ts +1 -1
  33. package/dist/agent-runtime/store-create.d.ts.map +1 -1
  34. package/dist/agent-runtime/store-driver-contract.d.ts +6 -0
  35. package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
  36. package/dist/agent-runtime/store-events.d.ts +90 -0
  37. package/dist/agent-runtime/store-events.d.ts.map +1 -1
  38. package/dist/agent-runtime/store-memory-archive.d.ts +8 -0
  39. package/dist/agent-runtime/store-memory-archive.d.ts.map +1 -0
  40. package/dist/agent-runtime/store-memory-events.d.ts +7 -0
  41. package/dist/agent-runtime/store-memory-events.d.ts.map +1 -0
  42. package/dist/agent-runtime/store-memory.d.ts +1 -1
  43. package/dist/agent-runtime/store-memory.d.ts.map +1 -1
  44. package/dist/agent-runtime/store-purge.d.ts +2 -0
  45. package/dist/agent-runtime/store-purge.d.ts.map +1 -1
  46. package/dist/agent-runtime/store-reduce-run.d.ts +2 -2
  47. package/dist/agent-runtime/store-reduce-run.d.ts.map +1 -1
  48. package/dist/agent-runtime/store-reduce-shared.d.ts +1 -0
  49. package/dist/agent-runtime/store-reduce-shared.d.ts.map +1 -1
  50. package/dist/agent-runtime/store-reducer.d.ts +2 -2
  51. package/dist/agent-runtime/store-reducer.d.ts.map +1 -1
  52. package/dist/agent-runtime/store.d.ts +3 -0
  53. package/dist/agent-runtime/store.d.ts.map +1 -1
  54. package/dist/browser/socket-io-client.d.ts +6 -0
  55. package/dist/browser/socket-io-client.d.ts.map +1 -0
  56. package/dist/browser/socket-io-contract.d.ts +183 -0
  57. package/dist/browser/socket-io-contract.d.ts.map +1 -0
  58. package/dist/browser/socket-io-default-peer.d.ts +3 -0
  59. package/dist/browser/socket-io-default-peer.d.ts.map +1 -0
  60. package/dist/browser/socket-io-explicit-peer.d.ts +12 -0
  61. package/dist/browser/socket-io-explicit-peer.d.ts.map +1 -0
  62. package/dist/browser/socket-io-peer.d.ts +2 -11
  63. package/dist/browser/socket-io-peer.d.ts.map +1 -1
  64. package/dist/browser/socket-io.d.ts +5 -224
  65. package/dist/browser/socket-io.d.ts.map +1 -1
  66. package/dist/durability/events.d.ts +4 -0
  67. package/dist/durability/events.d.ts.map +1 -1
  68. package/dist/entrypoints/agent-runtime/coding-tools.js +2 -3
  69. package/dist/entrypoints/agent-runtime/harness.js +5 -4
  70. package/dist/entrypoints/agent-runtime/realtime.js +3 -3
  71. package/dist/entrypoints/agent-runtime/sandbox.js +4 -6
  72. package/dist/entrypoints/agent-runtime/sqlite/bun.js +13 -3
  73. package/dist/entrypoints/agent-runtime/sqlite/node.js +13 -3
  74. package/dist/entrypoints/agent-runtime/testing.js +89 -5
  75. package/dist/entrypoints/agent-runtime.d.ts +1 -0
  76. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  77. package/dist/entrypoints/agent-runtime.js +28 -18
  78. package/dist/entrypoints/application/directory-inbox.js +6 -6
  79. package/dist/entrypoints/application.js +1 -1
  80. package/dist/entrypoints/cli/publish.js +2 -2
  81. package/dist/entrypoints/cli.js +8 -8
  82. package/dist/entrypoints/contract.js +1 -1
  83. package/dist/entrypoints/files.js +1 -1
  84. package/dist/entrypoints/http.d.ts +1 -0
  85. package/dist/entrypoints/http.d.ts.map +1 -1
  86. package/dist/entrypoints/http.js +6 -2
  87. package/dist/entrypoints/index.js +20 -411
  88. package/dist/entrypoints/node.js +3 -3
  89. package/dist/entrypoints/observability.js +1 -1
  90. package/dist/entrypoints/process.js +1 -1
  91. package/dist/entrypoints/realtime.d.ts +6 -0
  92. package/dist/entrypoints/realtime.d.ts.map +1 -0
  93. package/dist/entrypoints/realtime.js +25 -0
  94. package/dist/entrypoints/remote.js +1 -1
  95. package/dist/entrypoints/server.js +11 -11
  96. package/dist/entrypoints/telegram/screens.js +9 -9
  97. package/dist/entrypoints/telegram.js +3 -3
  98. package/dist/entrypoints/testing.js +2 -2
  99. package/dist/entrypoints/tools/connections.js +3 -3
  100. package/dist/entrypoints/tools/invoker.js +3 -3
  101. package/dist/entrypoints/tools/mcp.js +4 -4
  102. package/dist/entrypoints/tools.js +26 -24
  103. package/dist/{index-61m15a18.js → index-0d8m0kee.js} +1 -1
  104. package/dist/{index-dmfr2cg5.js → index-2tazbwhv.js} +6 -6
  105. package/dist/{index-c17xcx4k.js → index-56yx8dxp.js} +19 -96
  106. package/dist/{index-0gs4ymfj.js → index-6qeqdz0z.js} +7 -1
  107. package/dist/{index-064zxbwj.js → index-79zxnh52.js} +3 -3
  108. package/dist/{index-2pevnh0x.js → index-7c046kxr.js} +4 -4
  109. package/dist/index-86sxnvpr.js +336 -0
  110. package/dist/{index-jyw90rps.js → index-bm180f2d.js} +204 -84
  111. package/dist/{index-mnhtbqrb.js → index-dd1z5kxb.js} +2 -2
  112. package/dist/{index-7a1xhhdx.js → index-e1sjcjfy.js} +31 -11
  113. package/dist/{index-5p55xreg.js → index-e9rbhw1s.js} +67 -29
  114. package/dist/{index-p6mvqcbq.js → index-ghwntn9n.js} +1 -1
  115. package/dist/index-hqsbtvta.js +92 -0
  116. package/dist/{index-73cz22ds.js → index-mha6b4vk.js} +6 -6
  117. package/dist/index-s2bgwsyr.js +2280 -0
  118. package/dist/{index-fnra8n1j.js → index-s2eybn7b.js} +9 -9
  119. package/dist/{index-njs9gvrh.js → index-s6d8zsha.js} +6 -6
  120. package/dist/index-snef22zr.js +94 -0
  121. package/dist/{index-c0hffcmj.js → index-zbssway3.js} +19 -2
  122. package/dist/process/group-presence.d.ts +3 -0
  123. package/dist/process/group-presence.d.ts.map +1 -0
  124. package/dist/process/group-settlement.d.ts.map +1 -1
  125. package/dist/process/group.d.ts.map +1 -1
  126. package/llms/agent-runtime.3.txt +3 -0
  127. package/llms/agent-runtime.txt +60 -0
  128. package/llms/realtime.txt +31 -0
  129. package/llms/stitchkit.txt +1 -0
  130. package/llms-full.txt +85 -0
  131. package/llms.txt +3 -2
  132. package/package.json +5 -1
  133. package/dist/index-8ks9b85e.js +0 -129
  134. package/dist/index-d2h99n7d.js +0 -1071
  135. package/dist/{index-9j2atjte.js → index-2f9r0jgr.js} +3 -3
  136. package/dist/{index-y70v24cw.js → index-8asb62xn.js} +0 -0
  137. package/dist/{index-k7qdkh3n.js → index-h1spd9kv.js} +3 -3
  138. package/dist/{index-zgwkwr1g.js → index-jk44mbqb.js} +0 -0
  139. package/dist/{index-qd8x73e8.js → index-k8fbzggr.js} +0 -0
  140. package/dist/{index-85qve8mq.js → index-pzw0fpek.js} +0 -0
  141. package/dist/{index-y3nemndz.js → index-r6v4mc67.js} +3 -3
  142. package/dist/{index-ktjmgq9p.js → index-s0xbnpfh.js} +3 -3
@@ -44,7 +44,7 @@ import {
44
44
  paginatedSchema2,
45
45
  encodeCursor2,
46
46
  decodeCursor2
47
- } from "../index-qd8x73e8.js";
47
+ } from "../index-k8fbzggr.js";
48
48
  import {
49
49
  ManagedFilePathSchema2,
50
50
  ManagedFileRefSchema2
@@ -52,17 +52,12 @@ import {
52
52
  import {
53
53
  createMutationQueue
54
54
  } from "../index-sykb5ag7.js";
55
- import {
56
- realtimeRequestTraces,
57
- createRequestTracer,
58
- bindRealtimeClient2
59
- } from "../index-pvh3z03x.js";
60
- import {
61
- isModuleNotFound
62
- } from "../index-srs8hj9c.js";
63
55
  import {
64
56
  withDeadline
65
57
  } from "../index-9tqbxv5p.js";
58
+ import {
59
+ uploadInChunks2
60
+ } from "../index-hqsbtvta.js";
66
61
  import {
67
62
  StreamLineLimitError2,
68
63
  StreamTruncatedLineError2,
@@ -76,7 +71,15 @@ import {
76
71
  createUrlBuilder2,
77
72
  createUrlBuilders2,
78
73
  createScopedUrlBuilders2
79
- } from "../index-zgwkwr1g.js";
74
+ } from "../index-jk44mbqb.js";
75
+ import {
76
+ createRetainedTopics2,
77
+ createRealtimeClientWithPeer,
78
+ createSocketIOClientWithPeer
79
+ } from "../index-86sxnvpr.js";
80
+ import {
81
+ bindRealtimeClient2
82
+ } from "../index-pvh3z03x.js";
80
83
  import {
81
84
  ApiError2
82
85
  } from "../index-kfjkb396.js";
@@ -106,89 +109,6 @@ import {
106
109
  formatTraceparent2,
107
110
  childSpan2
108
111
  } from "../index-yex7eg1v.js";
109
- // src/browser/chunked-upload.ts
110
- function isRetryableUploadFailure(error) {
111
- if (ApiError2.is(error)) {
112
- if (error.status === 0)
113
- return error.code === "UNKNOWN_ERROR" || error.code === "REQUEST_TIMEOUT";
114
- return error.status === 429 || error.status >= 500;
115
- }
116
- return error instanceof TypeError;
117
- }
118
- async function uploadInChunks(config) {
119
- const { file, chunkBytes, signal } = config;
120
- if (!Number.isSafeInteger(chunkBytes) || chunkBytes <= 0) {
121
- throw new TypeError("uploadInChunks: chunkBytes must be a positive integer");
122
- }
123
- if (!Number.isSafeInteger(file.size) || file.size < 0) {
124
- throw new TypeError("uploadInChunks: the file size must be a whole number of bytes");
125
- }
126
- if (file.size === 0)
127
- throw new TypeError("uploadInChunks: the file is empty");
128
- const totalBytes = file.size;
129
- const chunkCount = Math.ceil(totalBytes / chunkBytes);
130
- const uploadId = config.uploadId ?? crypto.randomUUID();
131
- const retries = config.retries ?? 3;
132
- const retryDelayMs = config.retryDelayMs ?? 1000;
133
- const report = (sentBytes, index, attempt) => {
134
- if (!config.onProgress)
135
- return;
136
- try {
137
- config.onProgress({ sentBytes, totalBytes, index, chunkCount, attempt });
138
- } catch {}
139
- };
140
- throwIfAborted(signal);
141
- const opened = await repeating(() => config.init({ uploadId, totalBytes, chunkBytes, chunkCount }, { signal }), { retries, retryDelayMs, signal });
142
- if (opened) {
143
- report(totalBytes, chunkCount, 1);
144
- return opened.finished;
145
- }
146
- report(0, 0, 1);
147
- for (let index = 0;index < chunkCount; index += 1) {
148
- throwIfAborted(signal);
149
- const start = index * chunkBytes;
150
- const end = Math.min(totalBytes, start + chunkBytes);
151
- const partBytes = end - start;
152
- const bytes = file.slice(start, end);
153
- await repeating((attempt) => config.chunk({ uploadId, index, bytes }, {
154
- ...signal && { signal },
155
- onUploadProgress: (progress) => report(start + fileShare(progress, partBytes), index, attempt)
156
- }), { retries, retryDelayMs, signal });
157
- report(end, index + 1, 1);
158
- }
159
- throwIfAborted(signal);
160
- return config.finalize({ uploadId }, { signal });
161
- }
162
- function fileShare(progress, partBytes) {
163
- if (progress.totalBytes === 0)
164
- return 0;
165
- return Math.floor(partBytes * progress.sentBytes / progress.totalBytes);
166
- }
167
- async function repeating(call, {
168
- retries,
169
- retryDelayMs,
170
- signal
171
- }) {
172
- for (let attempt = 1;; attempt += 1) {
173
- try {
174
- return await call(attempt);
175
- } catch (error) {
176
- if (signal?.aborted || attempt > retries || !isRetryableUploadFailure(error))
177
- throw error;
178
- try {
179
- await sleep(retryDelayMs * 2 ** (attempt - 1), signal);
180
- } catch (aborted) {
181
- throwIfAborted(signal);
182
- throw aborted;
183
- }
184
- }
185
- }
186
- }
187
- function throwIfAborted(signal) {
188
- if (signal?.aborted) {
189
- throw new ApiError2("REQUEST_ABORTED", { status: 0, message: "Request was aborted" });
190
- }
191
- }
192
112
  // src/browser/resumable.ts
193
113
  var DEFAULT_RETRY = { minDelayMs: 100, maxDelayMs: 30000, jitter: 0.5 };
194
114
  async function* resumableIterator(config) {
@@ -225,31 +145,6 @@ async function* resumableIterator(config) {
225
145
  }
226
146
  }
227
147
  }
228
- // src/browser/retained.ts
229
- function createRetainedTopics() {
230
- const last = {};
231
- return {
232
- record(topic, payload) {
233
- last[topic] = payload;
234
- },
235
- replay(topic, handler) {
236
- const value = last[topic];
237
- if (value !== undefined)
238
- handler(value);
239
- },
240
- get(topic) {
241
- return last[topic];
242
- },
243
- clear(topic) {
244
- if (topic !== undefined) {
245
- delete last[topic];
246
- return;
247
- }
248
- for (const key of Object.keys(last))
249
- Reflect.deleteProperty(last, key);
250
- }
251
- };
252
- }
253
148
  // src/browser/session.ts
254
149
  class SessionExpiredError extends Error {
255
150
  constructor(options) {
@@ -440,120 +335,10 @@ function createSessionCredentials(config) {
440
335
  }
441
336
  };
442
337
  }
443
- // src/browser/socket-io-connection.ts
444
- function toIoAuth(auth) {
445
- if (typeof auth !== "function")
446
- return auth;
447
- return (cb) => {
448
- Promise.resolve().then(auth).then(cb, () => cb({}));
449
- };
450
- }
451
- function ioOptions(config) {
452
- return {
453
- path: config.path ?? "/socket.io/",
454
- withCredentials: config.withCredentials ?? true,
455
- auth: toIoAuth(config.auth),
456
- ...config.query && { query: config.query },
457
- ...config.extraHeaders && { extraHeaders: config.extraHeaders },
458
- transports: config.transports ?? ["websocket", "polling"],
459
- autoConnect: false,
460
- reconnection: true,
461
- reconnectionAttempts: config.reconnectionAttempts ?? Infinity,
462
- reconnectionDelay: config.reconnectionDelay ?? 1000,
463
- reconnectionDelayMax: config.reconnectionDelayMax ?? 5000,
464
- timeout: config.timeout ?? 20000
465
- };
466
- }
467
- function reportPeerFailure(config, error) {
468
- if (!config.onConnectError)
469
- throw error;
470
- config.onConnectError({
471
- message: error instanceof Error ? error.message : String(error),
472
- data: error,
473
- terminal: true
474
- });
475
- }
476
- function awaitAcknowledgement(input) {
477
- const { active, event } = input;
478
- return new Promise((resolve, reject) => {
479
- let settled = false;
480
- const finish = (result) => {
481
- if (settled)
482
- return;
483
- settled = true;
484
- input.pendingRequestDisconnects.delete(onDisconnect);
485
- active.off("disconnect", onDisconnect);
486
- result();
487
- };
488
- const onDisconnect = () => {
489
- finish(() => {
490
- input.closeTrace("disconnected");
491
- reject(new RealtimeRequestDisconnectedError2(event));
492
- });
493
- };
494
- input.pendingRequestDisconnects.add(onDisconnect);
495
- active.on("disconnect", onDisconnect);
496
- const acknowledgement = input.emit();
497
- acknowledgement.then((value) => finish(() => resolve(value)), () => {
498
- finish(() => {
499
- const connected = active.connected;
500
- input.closeTrace(connected ? "timeout" : "disconnected");
501
- reject(connected ? new RealtimeRequestTimeoutError2(event, input.timeoutMs) : new RealtimeRequestDisconnectedError2(event));
502
- });
503
- });
504
- });
505
- }
506
- function createStickyEvents(retain) {
507
- const names = retain ? retain.map(String) : [];
508
- const known = new Set(names);
509
- const retained = names.length > 0 ? createRetainedTopics() : null;
510
- return {
511
- record(socket) {
512
- if (!retained)
513
- return;
514
- for (const name of names) {
515
- socket.on(name, (payload) => retained.record(name, payload));
516
- }
517
- },
518
- replay(name, handler) {
519
- if (retained && known.has(name))
520
- retained.replay(name, (payload) => handler(payload));
521
- }
522
- };
523
- }
524
- function createRecycle(delay) {
525
- let timer = null;
526
- const clear = () => {
527
- if (timer === null)
528
- return;
529
- clearTimeout(timer);
530
- timer = null;
531
- };
532
- return {
533
- clear,
534
- schedule(run) {
535
- if (delay === false)
536
- return;
537
- clear();
538
- timer = setTimeout(() => {
539
- timer = null;
540
- run();
541
- }, delay);
542
- }
543
- };
544
- }
545
- function connectErrorReport(error, socket) {
546
- return {
547
- message: error.message,
548
- data: Reflect.get(error, "data"),
549
- terminal: socket !== null && !socket.active
550
- };
551
- }
552
-
553
- // src/browser/socket-io-peer.ts
338
+ // src/browser/socket-io-default-peer.ts
554
339
  var SOCKET_IO_CLIENT = "socket.io-client";
555
340
  var ioLoader = null;
556
- function loadIo() {
341
+ function loadDefaultIo() {
557
342
  if (!ioLoader) {
558
343
  ioLoader = import(/* webpackIgnore: true */ SOCKET_IO_CLIENT).then((mod) => mod.io, (cause) => {
559
344
  ioLoader = null;
@@ -562,189 +347,13 @@ function loadIo() {
562
347
  }
563
348
  return ioLoader;
564
349
  }
565
- function isIoModule(module) {
566
- if (typeof module !== "object" || module === null)
567
- return false;
568
- return typeof Reflect.get(module, "io") === "function";
569
- }
570
- function createIoResolver(injected) {
571
- if (!injected)
572
- return loadIo;
573
- let pending = null;
574
- return () => {
575
- if (!pending) {
576
- pending = injected().then((module) => {
577
- const io = isIoModule(module) ? module.io : null;
578
- if (!io) {
579
- pending = null;
580
- 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')`.");
581
- }
582
- return io;
583
- }, (cause) => {
584
- pending = null;
585
- if (!isModuleNotFound(cause))
586
- throw cause;
587
- 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 });
588
- });
589
- }
590
- return pending;
591
- };
592
- }
593
350
 
594
351
  // src/browser/socket-io.ts
595
- function createRealtimeClient(contract, { onRejected, logger, onRequestPhase, ...config }) {
596
- const transport = createSocketIOClientInternal(config, onRequestPhase);
597
- const bound = bindRealtimeClient2(contract, transport, { onRejected, logger });
598
- return {
599
- ...bound,
600
- get connected() {
601
- return bound.connected;
602
- },
603
- connect: transport.connect,
604
- disconnect: transport.disconnect
605
- };
352
+ function createRealtimeClient(contract, config) {
353
+ return createRealtimeClientWithPeer(contract, config, loadDefaultIo);
606
354
  }
607
355
  function createSocketIOClient(config) {
608
- return createSocketIOClientInternal(config);
609
- }
610
- function createSocketIOClientInternal(config, onRequestPhase) {
611
- let socket = null;
612
- const resolveIo = createIoResolver(config.peers?.client);
613
- let desiredConnected = false;
614
- let loadingPeer = false;
615
- const recycle = createRecycle(config.reconnectOnServerDisconnect ?? 1000);
616
- const pendingRequestDisconnects = new Set;
617
- const tracer = createRequestTracer(onRequestPhase);
618
- const connectionListeners = new Set;
619
- const subscriptions = new Set;
620
- const sticky = createStickyEvents(config.retain);
621
- function notifyConnection(connected, reason) {
622
- for (const listener of connectionListeners)
623
- listener(connected, reason);
624
- }
625
- function openSocket(io) {
626
- if (!desiredConnected || socket)
627
- return;
628
- socket = io(config.url, ioOptions(config));
629
- tracer.observeEachOpen(socket, () => socket);
630
- socket.on("connect", () => notifyConnection(true));
631
- socket.on("disconnect", (reason) => {
632
- notifyConnection(false, reason);
633
- if (reason === "io server disconnect") {
634
- const current = socket;
635
- recycle.schedule(() => {
636
- if (socket === current && current && !current.connected)
637
- current.connect();
638
- });
639
- }
640
- });
641
- socket.io.on("reconnect_failed", () => {
642
- desiredConnected = false;
643
- });
644
- socket.on("connect_error", (error) => {
645
- const report = connectErrorReport(error, socket);
646
- if (report.terminal)
647
- desiredConnected = false;
648
- config.onConnectError?.(report);
649
- });
650
- sticky.record(socket);
651
- for (const attach of subscriptions)
652
- attach(socket);
653
- socket.connect();
654
- }
655
- return {
656
- get connected() {
657
- return socket?.connected ?? false;
658
- },
659
- connect() {
660
- if (socket?.connected || desiredConnected)
661
- return;
662
- desiredConnected = true;
663
- if (socket) {
664
- socket.connect();
665
- return;
666
- }
667
- if (loadingPeer)
668
- return;
669
- loadingPeer = true;
670
- resolveIo().then((io) => {
671
- loadingPeer = false;
672
- openSocket(io);
673
- }, (error) => {
674
- loadingPeer = false;
675
- desiredConnected = false;
676
- reportPeerFailure(config, error);
677
- });
678
- },
679
- disconnect() {
680
- desiredConnected = false;
681
- recycle.clear();
682
- for (const reject of [...pendingRequestDisconnects])
683
- reject();
684
- if (!socket)
685
- return;
686
- const wasConnected = socket.connected;
687
- socket.removeAllListeners();
688
- socket.disconnect();
689
- socket = null;
690
- if (wasConnected)
691
- notifyConnection(false);
692
- },
693
- on(event, handler) {
694
- const name = event;
695
- const attach = (s) => {
696
- s.on(name, handler);
697
- };
698
- subscriptions.add(attach);
699
- if (socket)
700
- attach(socket);
701
- const fn = handler;
702
- sticky.replay(name, fn);
703
- return () => {
704
- subscriptions.delete(attach);
705
- socket?.off(name, handler);
706
- };
707
- },
708
- emit(event, ...args) {
709
- const name = event;
710
- if (!socket?.connected) {
711
- config.onDroppedEmit?.({ event: name, args });
712
- return false;
713
- }
714
- socket.emit(name, ...args);
715
- return true;
716
- },
717
- emitWithAck(event, args, options) {
718
- const trace = tracer.start(event, options.onPhase);
719
- const closeTrace = (phase) => tracer.close(trace, phase);
720
- const active = socket;
721
- if (!active?.connected) {
722
- const pending = Promise.reject(new RealtimeRequestDisconnectedError2(event));
723
- closeTrace("disconnected");
724
- if (trace)
725
- realtimeRequestTraces.set(pending, trace);
726
- return pending;
727
- }
728
- if (trace)
729
- tracer.observe(active);
730
- const pending = awaitAcknowledgement({
731
- active,
732
- event,
733
- args,
734
- timeoutMs: options.timeoutMs,
735
- pendingRequestDisconnects,
736
- closeTrace,
737
- emit: () => tracer.starting(trace, () => active.timeout(options.timeoutMs).emitWithAck(event, ...args))
738
- });
739
- if (trace)
740
- realtimeRequestTraces.set(pending, trace);
741
- return pending;
742
- },
743
- onConnectionChange(listener) {
744
- connectionListeners.add(listener);
745
- return () => connectionListeners.delete(listener);
746
- }
747
- };
356
+ return createSocketIOClientWithPeer(config, loadDefaultIo);
748
357
  }
749
358
  export {
750
359
  ALL_TRANSPORTS2 as ALL_TRANSPORTS,
@@ -785,7 +394,7 @@ export {
785
394
  createLiveStateController2 as createLiveStateController,
786
395
  createNDJSONDecoder2 as createNDJSONDecoder,
787
396
  createRealtimeClient,
788
- createRetainedTopics,
397
+ createRetainedTopics2 as createRetainedTopics,
789
398
  createScopedClients2 as createScopedClients,
790
399
  createScopedUrlBuilders2 as createScopedUrlBuilders,
791
400
  createSessionCredentials,
@@ -812,7 +421,7 @@ export {
812
421
  rateLimited2 as rateLimited,
813
422
  resumableIterator,
814
423
  unauthorized2 as unauthorized,
815
- uploadInChunks,
424
+ uploadInChunks2 as uploadInChunks,
816
425
  withToolView2 as withToolView,
817
426
  zodIssues2 as zodIssues
818
427
  };
@@ -11,7 +11,7 @@ import {
11
11
  import"../index-ykdcnq1f.js";
12
12
  import"../index-4s0fep5q.js";
13
13
  import"../index-fsw1ybf3.js";
14
- import"../index-qd8x73e8.js";
14
+ import"../index-k8fbzggr.js";
15
15
  import"../index-xqhede6x.js";
16
16
  import {
17
17
  createHandler2,
@@ -22,7 +22,7 @@ import {
22
22
  createSocketIOServer2,
23
23
  UnixClientTransportError2,
24
24
  createUnixClientTransport2
25
- } from "../index-njs9gvrh.js";
25
+ } from "../index-s6d8zsha.js";
26
26
  import {
27
27
  bindRealtimeServer2
28
28
  } from "../index-xmgjtkvr.js";
@@ -31,7 +31,7 @@ import {
31
31
  implement2,
32
32
  createImplement2,
33
33
  createScopedImplement2
34
- } from "../index-85qve8mq.js";
34
+ } from "../index-pzw0fpek.js";
35
35
  import"../index-1bx1xv1k.js";
36
36
  import {
37
37
  AppError2,
@@ -26,7 +26,7 @@ import {
26
26
  setRequestDimensions2,
27
27
  setRequestError2,
28
28
  wrapInRequestContext2
29
- } from "../index-y3nemndz.js";
29
+ } from "../index-r6v4mc67.js";
30
30
  import {
31
31
  createTraceContext2,
32
32
  parseTraceparent2,
@@ -9,7 +9,7 @@ import {
9
9
  } from "../index-84bf5spd.js";
10
10
  import {
11
11
  startNativeCommand
12
- } from "../index-7a1xhhdx.js";
12
+ } from "../index-e1sjcjfy.js";
13
13
  // src/process/command.ts
14
14
  function runNativeCommand(input) {
15
15
  return startNativeCommand(input).result;
@@ -0,0 +1,6 @@
1
+ /** Realtime clients for native bundles: the caller supplies a literal Socket.IO peer loader. */
2
+ export { createRetainedTopics, type RetainedTopics } from '../browser/retained.js';
3
+ export type { RealtimeClient, RealtimeClientOptions, SocketEventMap, SocketIOClient, SocketIOClientConfig, SocketIOClientPeerLoaders, } from '../browser/socket-io-contract.js';
4
+ export { createRealtimeClient, createSocketIOClient, } from '../browser/socket-io-explicit-peer.js';
5
+ export { defineRealtimeContract, type InferRealtimeEventMap, type RealtimeContract, type RealtimeEventRegistry, } from '../realtime/contract.js';
6
+ //# sourceMappingURL=realtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../../src/entrypoints/realtime.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,OAAO,EAAE,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChF,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import"../index-4s0fep5q.js";
2
+ import"../index-ykdcnq1f.js";
3
+ import {
4
+ defineRealtimeContract2
5
+ } from "../index-814xpr6d.js";
6
+ import {
7
+ createRetainedTopics2,
8
+ createRealtimeClientWithPeer,
9
+ createSocketIOClientWithPeer
10
+ } from "../index-86sxnvpr.js";
11
+ import"../index-pvh3z03x.js";
12
+ // src/browser/socket-io-explicit-peer.ts
13
+ var missingPeer = () => Promise.reject(new Error("stitchkit/realtime requires peers.client: () => import('socket.io-client') so the native bundler includes its transport."));
14
+ function createRealtimeClient(contract, config) {
15
+ return createRealtimeClientWithPeer(contract, config, missingPeer);
16
+ }
17
+ function createSocketIOClient(config) {
18
+ return createSocketIOClientWithPeer(config, missingPeer);
19
+ }
20
+ export {
21
+ createRealtimeClient,
22
+ createRetainedTopics2 as createRetainedTopics,
23
+ createSocketIOClient,
24
+ defineRealtimeContract2 as defineRealtimeContract
25
+ };
@@ -4,7 +4,7 @@ import"../index-p6apg0jg.js";
4
4
  import {
5
5
  endpointHasArguments,
6
6
  createClient2
7
- } from "../index-zgwkwr1g.js";
7
+ } from "../index-jk44mbqb.js";
8
8
  import {
9
9
  ApiError2
10
10
  } from "../index-kfjkb396.js";
@@ -26,7 +26,7 @@ import {
26
26
  import"../index-ykdcnq1f.js";
27
27
  import"../index-4s0fep5q.js";
28
28
  import"../index-fsw1ybf3.js";
29
- import"../index-qd8x73e8.js";
29
+ import"../index-k8fbzggr.js";
30
30
  import"../index-xqhede6x.js";
31
31
  import {
32
32
  contextContributionDelta,
@@ -48,13 +48,13 @@ import {
48
48
  socketIoLane2,
49
49
  UnixClientTransportError2,
50
50
  createUnixClientTransport2
51
- } from "../index-njs9gvrh.js";
52
- import {
53
- bindRealtimeServer2
54
- } from "../index-xmgjtkvr.js";
51
+ } from "../index-s6d8zsha.js";
55
52
  import {
56
53
  createFileStateStore2
57
54
  } from "../index-nx49x0tw.js";
55
+ import {
56
+ bindRealtimeServer2
57
+ } from "../index-xmgjtkvr.js";
58
58
  import"../index-w9mqgnz9.js";
59
59
  import {
60
60
  withDeadline
@@ -66,14 +66,14 @@ import {
66
66
  verifyJwt2,
67
67
  signJwt2,
68
68
  verifyPkce2
69
- } from "../index-k7qdkh3n.js";
69
+ } from "../index-h1spd9kv.js";
70
70
  import {
71
71
  defineMultipartStream2,
72
72
  createMultipartStream2,
73
73
  implement2,
74
74
  createImplement2,
75
75
  createScopedImplement2
76
- } from "../index-85qve8mq.js";
76
+ } from "../index-pzw0fpek.js";
77
77
  import {
78
78
  deriveCodeChallenge2
79
79
  } from "../index-ap3gqe56.js";
@@ -90,7 +90,7 @@ import {
90
90
  } from "../index-yk4g8805.js";
91
91
  import {
92
92
  getTraceId2
93
- } from "../index-y3nemndz.js";
93
+ } from "../index-r6v4mc67.js";
94
94
  import {
95
95
  generateTraceId2,
96
96
  resolveTraceId2,
@@ -99,6 +99,9 @@ import {
99
99
  getClientInfo2,
100
100
  isPublicIp2
101
101
  } from "../index-kw1ws0cs.js";
102
+ import {
103
+ isUnsafeKey
104
+ } from "../index-zsarb5xp.js";
102
105
  import {
103
106
  zodIssues2,
104
107
  formatZodError2
@@ -115,9 +118,6 @@ import {
115
118
  isStitchErrorCode2,
116
119
  appError2
117
120
  } from "../index-j9gxbztg.js";
118
- import {
119
- isUnsafeKey
120
- } from "../index-zsarb5xp.js";
121
121
  import {
122
122
  isRecord
123
123
  } from "../index-9jfdm5tg.js";