stitchkit 0.98.2 → 0.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/agent-runtime/contained-darwin.d.ts +0 -17
  3. package/dist/agent-runtime/contained-darwin.d.ts.map +1 -1
  4. package/dist/agent-runtime/contained-write.d.ts.map +1 -1
  5. package/dist/agent-runtime/invocation-attempt.d.ts +22 -0
  6. package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -0
  7. package/dist/agent-runtime/invocation-failure.d.ts +6 -0
  8. package/dist/agent-runtime/invocation-failure.d.ts.map +1 -0
  9. package/dist/agent-runtime/invocation-payload.d.ts +18 -0
  10. package/dist/agent-runtime/invocation-payload.d.ts.map +1 -0
  11. package/dist/agent-runtime/invocation-read.d.ts +131 -0
  12. package/dist/agent-runtime/invocation-read.d.ts.map +1 -0
  13. package/dist/agent-runtime/invocation-schema.d.ts +378 -0
  14. package/dist/agent-runtime/invocation-schema.d.ts.map +1 -0
  15. package/dist/agent-runtime/invocations.d.ts +46 -0
  16. package/dist/agent-runtime/invocations.d.ts.map +1 -0
  17. package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
  18. package/dist/agent-runtime/run-execution-state.d.ts +4 -2
  19. package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
  20. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  21. package/dist/agent-runtime/run-failure.d.ts.map +1 -1
  22. package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
  23. package/dist/agent-runtime/run-operation-lifecycle.d.ts +2 -2
  24. package/dist/agent-runtime/run-operation-lifecycle.d.ts.map +1 -1
  25. package/dist/agent-runtime/run-provider-ledger.d.ts +1 -0
  26. package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -1
  27. package/dist/agent-runtime/runtime.d.ts +11 -0
  28. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  29. package/dist/agent-runtime/store-create.d.ts.map +1 -1
  30. package/dist/agent-runtime/store-event-once.d.ts +29 -0
  31. package/dist/agent-runtime/store-event-once.d.ts.map +1 -0
  32. package/dist/agent-runtime/store.d.ts +5 -0
  33. package/dist/agent-runtime/store.d.ts.map +1 -1
  34. package/dist/application/change-subscription.d.ts +36 -0
  35. package/dist/application/change-subscription.d.ts.map +1 -0
  36. package/dist/application/diagnostic-journal-contract.d.ts +3 -6
  37. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
  38. package/dist/application/notification-delivery.d.ts +32 -0
  39. package/dist/application/notification-delivery.d.ts.map +1 -0
  40. package/dist/application/notification-outbox-state.d.ts +37 -0
  41. package/dist/application/notification-outbox-state.d.ts.map +1 -0
  42. package/dist/application/notification-outbox.d.ts +7 -1
  43. package/dist/application/notification-outbox.d.ts.map +1 -1
  44. package/dist/application/watch-hub-core.d.ts +10 -15
  45. package/dist/application/watch-hub-core.d.ts.map +1 -1
  46. package/dist/application/watch-hub.d.ts +10 -2
  47. package/dist/application/watch-hub.d.ts.map +1 -1
  48. package/dist/browser/session-credentials.d.ts +20 -0
  49. package/dist/browser/session-credentials.d.ts.map +1 -0
  50. package/dist/browser/session.d.ts +31 -0
  51. package/dist/browser/session.d.ts.map +1 -0
  52. package/dist/durability/events.d.ts +6 -0
  53. package/dist/durability/events.d.ts.map +1 -1
  54. package/dist/entrypoints/agent-runtime/coding-tools.js +5 -4
  55. package/dist/entrypoints/agent-runtime/harness.js +8 -6
  56. package/dist/entrypoints/agent-runtime/sandbox.js +5 -4
  57. package/dist/entrypoints/agent-runtime/sqlite/bun.js +3 -3
  58. package/dist/entrypoints/agent-runtime/sqlite/node.js +3 -3
  59. package/dist/entrypoints/agent-runtime/testing.js +3 -3
  60. package/dist/entrypoints/agent-runtime.d.ts +3 -0
  61. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  62. package/dist/entrypoints/agent-runtime.js +21 -10
  63. package/dist/entrypoints/application/diagnostic-journal.js +2 -1
  64. package/dist/entrypoints/application.d.ts +3 -1
  65. package/dist/entrypoints/application.d.ts.map +1 -1
  66. package/dist/entrypoints/application.js +629 -189
  67. package/dist/entrypoints/cli.js +6 -6
  68. package/dist/entrypoints/files.js +2 -1
  69. package/dist/entrypoints/index.d.ts +2 -0
  70. package/dist/entrypoints/index.d.ts.map +1 -1
  71. package/dist/entrypoints/index.js +172 -0
  72. package/dist/entrypoints/live.js +68 -13
  73. package/dist/entrypoints/react.d.ts +1 -1
  74. package/dist/entrypoints/react.d.ts.map +1 -1
  75. package/dist/entrypoints/react.js +59 -16
  76. package/dist/entrypoints/testing.js +1 -1
  77. package/dist/entrypoints/tools/connections.js +2 -2
  78. package/dist/entrypoints/tools/invoker.js +4 -4
  79. package/dist/entrypoints/tools.js +8 -8
  80. package/dist/{index-wsm5w4ee.js → index-0b1cnze2.js} +35 -3
  81. package/dist/{index-np4m8hd3.js → index-0r0fbk7z.js} +9 -7
  82. package/dist/{index-p9sh0xx4.js → index-5p2m7we1.js} +3 -3
  83. package/dist/{index-55hkhm67.js → index-8qt2m66q.js} +1 -1
  84. package/dist/{index-hmp4800j.js → index-9t3dffv2.js} +3 -3
  85. package/dist/{index-khtgb21r.js → index-bm5rx7n6.js} +2 -2
  86. package/dist/{index-gxrt5h6v.js → index-cyktc4bp.js} +3 -0
  87. package/dist/{index-xw3s75nj.js → index-d8m8zpd8.js} +1 -1
  88. package/dist/{index-px2gm2jp.js → index-fhwqwxe0.js} +17 -55
  89. package/dist/{index-het2he5g.js → index-gw8bmyaj.js} +5 -3
  90. package/dist/{index-8p52kd5p.js → index-js7gqrb1.js} +96 -14
  91. package/dist/{index-wt743f7f.js → index-k6gpggb9.js} +2 -1
  92. package/dist/index-q3pyb9n0.js +22 -0
  93. package/dist/{index-f1nb70ae.js → index-r066jx76.js} +4 -4
  94. package/dist/{index-sp1tzwnb.js → index-s84he4v7.js} +2 -2
  95. package/dist/{index-863ea9jb.js → index-sh3s86na.js} +3 -3
  96. package/dist/{index-nts4a2br.js → index-xwhjjw2x.js} +879 -280
  97. package/dist/{index-1m2thnq0.js → index-y9qn426m.js} +2 -2
  98. package/dist/index-zjjyynm3.js +42 -0
  99. package/dist/internal/coalesced-task.d.ts +15 -0
  100. package/dist/internal/coalesced-task.d.ts.map +1 -0
  101. package/dist/internal/darwin-binding.d.ts +19 -0
  102. package/dist/internal/darwin-binding.d.ts.map +1 -0
  103. package/dist/internal/exclusive-lock.d.ts +20 -7
  104. package/dist/internal/exclusive-lock.d.ts.map +1 -1
  105. package/dist/internal/mutation-queue.d.ts +4 -0
  106. package/dist/internal/mutation-queue.d.ts.map +1 -0
  107. package/dist/internal/process-identity.d.ts +1 -1
  108. package/dist/internal/process-identity.d.ts.map +1 -1
  109. package/dist/internal/process-instance.d.ts +26 -0
  110. package/dist/internal/process-instance.d.ts.map +1 -0
  111. package/dist/live/watch-client-state.d.ts +71 -0
  112. package/dist/live/watch-client-state.d.ts.map +1 -0
  113. package/dist/live/watch-client.d.ts +5 -1
  114. package/dist/live/watch-client.d.ts.map +1 -1
  115. package/dist/live/watch-contract.d.ts +12 -0
  116. package/dist/live/watch-contract.d.ts.map +1 -1
  117. package/dist/react/cache-bridge.d.ts +10 -0
  118. package/dist/react/cache-bridge.d.ts.map +1 -1
  119. package/dist/tools/schema/flatten-join.d.ts.map +1 -1
  120. package/llms/agent-runtime.2.txt +94 -0
  121. package/llms/agent-runtime.3.txt +24 -0
  122. package/llms/application.2.txt +68 -2
  123. package/llms/application.txt +32 -2
  124. package/llms/files.txt +1 -1
  125. package/llms/live.txt +7 -0
  126. package/llms/react.txt +8 -0
  127. package/llms/server.3.txt +35 -0
  128. package/llms/stitchkit.2.txt +41 -0
  129. package/llms/stitchkit.3.txt +22 -0
  130. package/llms/stitchkit.txt +3 -3
  131. package/llms/tools.txt +9 -8
  132. package/llms/upgrading-0.37.0.txt +176 -0
  133. package/llms/{upgrading-0.37.0-0.58.0.txt → upgrading-0.44.0-0.60.0.txt} +229 -169
  134. package/llms/{upgrading-0.59.0-0.71.0.txt → upgrading-0.61.0-0.73.0.txt} +122 -229
  135. package/llms/{upgrading-0.72.0-0.98.0.txt → upgrading-0.74.0-0.100.0.txt} +96 -122
  136. package/llms/upgrading.txt +4 -3
  137. package/llms-full.txt +431 -14
  138. package/llms.txt +11 -10
  139. package/native/darwin-arm64.node +0 -0
  140. package/native/darwin-x64.node +0 -0
  141. package/package.json +1 -1
  142. package/dist/agent-runtime/run-mutation-queue.d.ts +0 -21
  143. package/dist/agent-runtime/run-mutation-queue.d.ts.map +0 -1
@@ -18,22 +18,22 @@ import {
18
18
  readCapped,
19
19
  renderCliView,
20
20
  routeCliArgv
21
- } from "../index-f1nb70ae.js";
21
+ } from "../index-r066jx76.js";
22
22
  import"../index-sbdmyz75.js";
23
- import"../index-hmp4800j.js";
23
+ import"../index-9t3dffv2.js";
24
24
  import {
25
25
  argumentsDigest
26
26
  } from "../index-0b1ess5e.js";
27
- import"../index-khtgb21r.js";
28
- import"../index-55hkhm67.js";
27
+ import"../index-bm5rx7n6.js";
28
+ import"../index-8qt2m66q.js";
29
29
  import"../index-zfrhfn82.js";
30
30
  import"../index-35mh5bhj.js";
31
31
  import"../index-zcgf3gqf.js";
32
32
  import {
33
33
  coerceJsonArgs
34
34
  } from "../index-1zbbzgfh.js";
35
- import"../index-xw3s75nj.js";
36
- import"../index-np4m8hd3.js";
35
+ import"../index-d8m8zpd8.js";
36
+ import"../index-0r0fbk7z.js";
37
37
  import"../index-eqqvgdb3.js";
38
38
  import"../index-znfs20ss.js";
39
39
  import"../index-p5r7qpdd.js";
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  attemptExclusiveLock
3
- } from "../index-8p52kd5p.js";
3
+ } from "../index-js7gqrb1.js";
4
+ import"../index-zjjyynm3.js";
4
5
  import {
5
6
  ManagedFileError,
6
7
  createManagedFileBoundary
@@ -5,6 +5,8 @@ export type { BindRealtimeClientOptions, BoundRealtimeClient, RealtimeClientTran
5
5
  export { bindRealtimeClient } from '../browser/realtime-client.js';
6
6
  export { type ResumableAttempt, type ResumableIteratorConfig, resumableIterator, } from '../browser/resumable.js';
7
7
  export { createRetainedTopics, type RetainedTopics } from '../browser/retained.js';
8
+ export { createSessionScope, SessionExpiredError, type SessionOperation, type SessionScope, } from '../browser/session.js';
9
+ export { createSessionCredentials, type SessionCredentials, type SessionCredentialsConfig, } from '../browser/session-credentials.js';
8
10
  export type { RealtimeClient, RealtimeClientOptions, SocketEventMap, SocketIOClient, SocketIOClientConfig, SocketIOClientPeerLoaders, } from '../browser/socket-io.js';
9
11
  export { createRealtimeClient, createSocketIOClient } from '../browser/socket-io.js';
10
12
  export { type ParseNDJSONOptions, type ParseSSEOptions, parseNDJSON, parseSSE, } from '../browser/stream.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entrypoints/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,QAAQ,EACR,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,yBAAyB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qBAAqB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,GAC9B,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,WAAW,EACX,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,mBAAmB,EACnB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKvD,OAAO,EAAE,cAAc,EAAE,KAAK,eAAe,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGzF,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -44,6 +44,9 @@ import {
44
44
  ContractStreamFrameSchema,
45
45
  DEFAULT_CONTRACT_STREAM_FRAME_BYTES
46
46
  } from "../index-wqgjfstn.js";
47
+ import {
48
+ createMutationQueue
49
+ } from "../index-q3pyb9n0.js";
47
50
  import {
48
51
  LiveStateControllerStatusSchema,
49
52
  LiveStatePhaseSchema,
@@ -393,6 +396,172 @@ function createRetainedTopics() {
393
396
  }
394
397
  };
395
398
  }
399
+ // src/browser/session.ts
400
+ class SessionExpiredError extends Error {
401
+ constructor() {
402
+ super("The originating session is no longer active");
403
+ this.name = "SessionExpiredError";
404
+ }
405
+ }
406
+ function createSessionScope() {
407
+ let generation = 0;
408
+ let stopped = false;
409
+ let active;
410
+ let abort;
411
+ const invalidate = () => {
412
+ const previous = abort;
413
+ generation += 1;
414
+ active = undefined;
415
+ abort = undefined;
416
+ previous?.abort(new SessionExpiredError);
417
+ };
418
+ return {
419
+ get generation() {
420
+ return generation;
421
+ },
422
+ replace(context) {
423
+ if (stopped)
424
+ throw new SessionExpiredError;
425
+ const previous = abort;
426
+ generation += 1;
427
+ const controller = new AbortController;
428
+ abort = controller;
429
+ const id = generation;
430
+ const current = () => !stopped && generation === id && !controller.signal.aborted;
431
+ const assertCurrent = () => {
432
+ if (!current())
433
+ throw new SessionExpiredError;
434
+ };
435
+ const operation = {
436
+ context,
437
+ id: crypto.randomUUID(),
438
+ generation: id,
439
+ signal: controller.signal,
440
+ current,
441
+ assertCurrent,
442
+ async run(work) {
443
+ assertCurrent();
444
+ try {
445
+ const result = await work();
446
+ assertCurrent();
447
+ return result;
448
+ } catch (error) {
449
+ assertCurrent();
450
+ throw error;
451
+ }
452
+ },
453
+ deliver(delivery) {
454
+ if (!current())
455
+ return false;
456
+ delivery();
457
+ return true;
458
+ },
459
+ bindFetch(fetch, headers) {
460
+ return async (input, init) => {
461
+ assertCurrent();
462
+ const request = new Request(input, init);
463
+ const extra = headers?.();
464
+ assertCurrent();
465
+ if (extra)
466
+ new Headers(extra).forEach((value, key) => {
467
+ request.headers.set(key, value);
468
+ });
469
+ const signal = AbortSignal.any([controller.signal, request.signal]);
470
+ return operation.run(() => fetch(new Request(request, { signal })));
471
+ };
472
+ }
473
+ };
474
+ active = Object.freeze(operation);
475
+ previous?.abort(new SessionExpiredError);
476
+ return operation;
477
+ },
478
+ clear: invalidate,
479
+ stop() {
480
+ stopped = true;
481
+ invalidate();
482
+ },
483
+ capture() {
484
+ if (!active)
485
+ throw new SessionExpiredError;
486
+ return active;
487
+ },
488
+ owns(operation) {
489
+ return active === operation && operation.current();
490
+ }
491
+ };
492
+ }
493
+ // src/browser/session-credentials.ts
494
+ function createSessionCredentials(config) {
495
+ const capacity = config.maxPendingWrites ?? 128;
496
+ if (!Number.isSafeInteger(capacity) || capacity < 1 || capacity > 65536)
497
+ throw new RangeError("maxPendingWrites must be between 1 and 65536");
498
+ const serialize = createMutationQueue(capacity);
499
+ const timeout = config.refreshTimeoutMs ?? 30000;
500
+ if (!Number.isInteger(timeout) || timeout < 1 || timeout > 3600000) {
501
+ throw new RangeError("refreshTimeoutMs must be between 1 and 3600000");
502
+ }
503
+ let state;
504
+ let flight;
505
+ const read = (operation) => {
506
+ if (!config.scope.owns(operation) || state?.operation !== operation)
507
+ throw new SessionExpiredError;
508
+ return state.credentials;
509
+ };
510
+ const write = (operation, credentials) => serialize(async () => {
511
+ read(operation);
512
+ await config.storage.write(operation.context, credentials);
513
+ operation.assertCurrent();
514
+ });
515
+ return {
516
+ async login(session, credentials) {
517
+ const operation = config.scope.replace(session);
518
+ operation.assertCurrent();
519
+ state = { operation, credentials };
520
+ await write(operation, credentials);
521
+ return operation;
522
+ },
523
+ logout() {
524
+ config.scope.clear();
525
+ state = undefined;
526
+ const generation = config.scope.generation;
527
+ return serialize(async () => {
528
+ if (config.scope.generation === generation)
529
+ await config.storage.clear();
530
+ });
531
+ },
532
+ read,
533
+ refresh(operation) {
534
+ const credentials = read(operation);
535
+ if (flight?.operation === operation)
536
+ return flight.result;
537
+ const controller = new AbortController;
538
+ const signal = AbortSignal.any([operation.signal, controller.signal]);
539
+ const timer = setTimeout(() => controller.abort(new DOMException("Refresh timed out", "TimeoutError")), timeout);
540
+ let onAbort = () => {
541
+ return;
542
+ };
543
+ const abortPromise = new Promise((_, reject) => {
544
+ onAbort = () => reject(signal.reason);
545
+ signal.addEventListener("abort", onAbort, { once: true });
546
+ });
547
+ const result = operation.run(async () => {
548
+ const next = await Promise.race([config.refresh(credentials, signal), abortPromise]);
549
+ read(operation);
550
+ await write(operation, next);
551
+ read(operation);
552
+ state = { operation, credentials: next };
553
+ return next;
554
+ }).finally(() => {
555
+ clearTimeout(timer);
556
+ signal.removeEventListener("abort", onAbort);
557
+ if (flight?.result === result)
558
+ flight = undefined;
559
+ });
560
+ flight = { operation, result };
561
+ return result;
562
+ }
563
+ };
564
+ }
396
565
  // src/browser/socket-io-connection.ts
397
566
  function toIoAuth(auth) {
398
567
  if (typeof auth !== "function")
@@ -724,6 +893,8 @@ export {
724
893
  createUrlBuilder,
725
894
  createTraceContext,
726
895
  createSocketIOClient,
896
+ createSessionScope,
897
+ createSessionCredentials,
727
898
  createScopedUrlBuilders,
728
899
  createScopedClients,
729
900
  createRetainedTopics,
@@ -742,6 +913,7 @@ export {
742
913
  asRealtimeRejection,
743
914
  appError,
744
915
  TOOL_TRANSPORTS,
916
+ SessionExpiredError,
745
917
  STITCH_ERROR_STATUS,
746
918
  RealtimeRequestTimeoutError,
747
919
  RealtimeRequestRejectedError,
@@ -14,7 +14,7 @@ import {
14
14
  diff,
15
15
  watchContract,
16
16
  watchKeyString
17
- } from "../index-wt743f7f.js";
17
+ } from "../index-k6gpggb9.js";
18
18
  import"../index-1j8pm5t0.js";
19
19
  import"../index-d9pk3td4.js";
20
20
  import {
@@ -73,23 +73,23 @@ function toRealtimeContract(declaration) {
73
73
  }
74
74
  return { serverToClient, clientToServer: {} };
75
75
  }
76
- // src/live/watch-client.ts
77
- function watchTransport(client) {
78
- return client;
79
- }
76
+ // src/live/watch-client-state.ts
80
77
  function publishState(entry, state) {
81
78
  entry.state = state;
82
79
  for (const listener of [...entry.listeners])
83
80
  listener.state?.(state);
84
81
  }
85
82
  async function openWatch(config, openTimeoutMs, entry) {
86
- if (entry.opened)
83
+ if (entry.opened || entry.released || config.session && !config.session.current())
87
84
  return;
85
+ const epoch = ++entry.epoch;
88
86
  entry.opened = true;
89
87
  entry.answered = false;
90
88
  try {
91
89
  const have = entry.hasValue && entry.fingerprint !== undefined ? { revision: entry.revision, fingerprint: entry.fingerprint } : undefined;
92
90
  const acknowledgement = await config.transport.request(WATCH_OPEN, { key: entry.key, args: entry.args, ...have !== undefined && { have } }, { timeoutMs: openTimeoutMs });
91
+ if (epoch !== entry.epoch || entry.released || config.session && !config.session.current())
92
+ return;
93
93
  if (!acknowledgement.accepted) {
94
94
  const reason = acknowledgement.reason ?? "the server refused this watch";
95
95
  config.onRefused?.(entry.key, reason);
@@ -101,6 +101,8 @@ async function openWatch(config, openTimeoutMs, entry) {
101
101
  });
102
102
  }
103
103
  } catch (error) {
104
+ if (epoch !== entry.epoch || entry.released || config.session && !config.session.current())
105
+ return;
104
106
  entry.opened = false;
105
107
  const code = typeof error === "object" && error !== null && "code" in error ? String(Reflect.get(error, "code")) : undefined;
106
108
  publishState(entry, {
@@ -160,8 +162,19 @@ function applyWatchFrame(entry, frame) {
160
162
  entry.answered = true;
161
163
  return { kind: "value", value };
162
164
  }
165
+
166
+ // src/live/watch-client.ts
167
+ function watchTransport(client) {
168
+ return client;
169
+ }
163
170
  function createWatchClient(contract, config) {
164
171
  const entries = new Map;
172
+ const valid = () => !config.session || config.session.current();
173
+ const maxKeys = config.maxKeys ?? 1024;
174
+ const maxListeners = config.maxListenersPerKey ?? 128;
175
+ for (const bound of [maxKeys, maxListeners])
176
+ if (!Number.isInteger(bound) || bound < 1)
177
+ throw new RangeError("Watch capacity must be positive");
165
178
  const holdMs = config.holdMs ?? 0;
166
179
  const openTimeoutMs = config.openTimeoutMs ?? 1e4;
167
180
  const service = contract.meta.prefix;
@@ -175,7 +188,9 @@ function createWatchClient(contract, config) {
175
188
  config.transport.emit(WATCH_CLOSE, { key: entry.key });
176
189
  openWatch(config, openTimeoutMs, entry);
177
190
  }
178
- config.transport.on(WATCH_VALUE, (frame) => {
191
+ const offValue = config.transport.on(WATCH_VALUE, (frame) => {
192
+ if (!valid())
193
+ return;
179
194
  const entry = entries.get(watchKeyString(frame.key));
180
195
  if (!entry)
181
196
  return;
@@ -189,16 +204,21 @@ function createWatchClient(contract, config) {
189
204
  for (const listener of [...entry.listeners])
190
205
  listener.value(outcome.value);
191
206
  });
192
- config.transport.on(WATCH_STATE, (frame) => {
207
+ const offState = config.transport.on(WATCH_STATE, (frame) => {
208
+ if (!valid())
209
+ return;
193
210
  const entry = entries.get(watchKeyString(frame.key));
194
211
  if (!entry)
195
212
  return;
196
213
  publishState(entry, frame);
197
214
  });
198
- config.transport.onConnectionChange((connected, reason) => {
215
+ const offConnection = config.transport.onConnectionChange((connected, reason) => {
216
+ if (!valid())
217
+ return;
199
218
  if (!connected) {
200
219
  for (const entry of entries.values()) {
201
220
  entry.opened = false;
221
+ entry.epoch += 1;
202
222
  publishState(entry, {
203
223
  key: entry.key,
204
224
  phase: "unavailable",
@@ -215,6 +235,25 @@ function createWatchClient(contract, config) {
215
235
  openWatch(config, openTimeoutMs, entry);
216
236
  }
217
237
  });
238
+ const shutdown = () => {
239
+ offValue();
240
+ offState();
241
+ offConnection();
242
+ for (const entry of entries.values()) {
243
+ entry.released = true;
244
+ entry.epoch++;
245
+ clearTimeout(entry.release);
246
+ entry.listeners.clear();
247
+ entry.value = undefined;
248
+ entry.hasValue = false;
249
+ config.transport.emit(WATCH_CLOSE, { key: entry.key });
250
+ }
251
+ entries.clear();
252
+ };
253
+ if (config.session?.signal.aborted)
254
+ shutdown();
255
+ else
256
+ config.session?.signal.addEventListener("abort", shutdown, { once: true });
218
257
  function entryFor(key, args) {
219
258
  const id = watchKeyString(key);
220
259
  const existing = entries.get(id);
@@ -223,7 +262,11 @@ function createWatchClient(contract, config) {
223
262
  existing.release = undefined;
224
263
  return existing;
225
264
  }
265
+ if (entries.size >= maxKeys)
266
+ throw new Error("Watch key capacity exceeded");
226
267
  const entry = {
268
+ epoch: 0,
269
+ released: false,
227
270
  key,
228
271
  args,
229
272
  listeners: new Set,
@@ -236,12 +279,14 @@ function createWatchClient(contract, config) {
236
279
  entries.set(id, entry);
237
280
  return entry;
238
281
  }
239
- function releaseEntry(entry) {
282
+ function releaseWatchClientEntry(entry) {
240
283
  if (entry.listeners.size > 0)
241
284
  return;
242
285
  const drop = () => {
243
286
  if (entry.listeners.size > 0)
244
287
  return;
288
+ entry.released = true;
289
+ entry.epoch++;
245
290
  entries.delete(watchKeyString(entry.key));
246
291
  config.transport.emit(WATCH_CLOSE, { key: entry.key });
247
292
  };
@@ -254,9 +299,19 @@ function createWatchClient(contract, config) {
254
299
  }
255
300
  function handleFor(action, args) {
256
301
  const mine = new Set;
257
- const entry = entryFor({ service, action, digest: argumentsDigest(args) }, args);
302
+ let entry = entryFor({
303
+ service,
304
+ action,
305
+ digest: argumentsDigest(args),
306
+ ...config.session && { instance: config.session.id }
307
+ }, args);
258
308
  return {
259
309
  subscribe(listeners) {
310
+ config.session?.assertCurrent();
311
+ if (entry.released)
312
+ entry = entryFor(entry.key, args);
313
+ if (entry.listeners.size >= maxListeners)
314
+ throw new Error("Watch listener capacity exceeded");
260
315
  const registered = listeners;
261
316
  mine.add(registered);
262
317
  entry.listeners.add(registered);
@@ -267,14 +322,14 @@ function createWatchClient(contract, config) {
267
322
  return () => {
268
323
  mine.delete(registered);
269
324
  entry.listeners.delete(registered);
270
- releaseEntry(entry);
325
+ releaseWatchClientEntry(entry);
271
326
  };
272
327
  },
273
328
  close() {
274
329
  for (const listener of mine)
275
330
  entry.listeners.delete(listener);
276
331
  mine.clear();
277
- releaseEntry(entry);
332
+ releaseWatchClientEntry(entry);
278
333
  }
279
334
  };
280
335
  }
@@ -1,4 +1,4 @@
1
- export { type CacheBridge, type CacheBridgeConfig, type CacheBridgeContext, type CacheBridgeHandler, type CacheBridgeHandlers, type CacheBridgeSocket, createCacheBridge, createRealtimeCacheBridge, type RealtimeCacheBridgeConfig, } from '../react/cache-bridge.js';
1
+ export { type CacheBridge, type CacheBridgeConfig, type CacheBridgeContext, type CacheBridgeHandler, type CacheBridgeHandlers, type CacheBridgeSocket, createCacheBridge, createRealtimeCacheBridge, type RealtimeCacheBridgeConfig, type WatchCacheBinding, } from '../react/cache-bridge.js';
2
2
  export { type CursorQueryConfig, createCursorQuery } from '../react/cursor-query.js';
3
3
  export { createEntityCacheHandlers, type DeletedPayload, type EntityCacheConfig, type EntityCacheEvent, type EntityCacheHandlers, type EntityCacheKey, type EntityCacheListConfig, type EntityCacheListShape, type EntityCacheMembership, type EntityCacheMembershipPolicy, type EntityCacheTotalDeltaInput, type EntityCacheTotalPolicy, } from '../react/entity-cache.js';
4
4
  export { type ApiErrorRetryConfig, apiErrorRetry, createQueryClientFactory, type QueryClientFactoryConfig, type QueryClientServerCache, type QueryRetryValue, } from '../react/query-client.js';
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/entrypoints/react.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,yBAAyB,EACzB,KAAK,yBAAyB,GAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EACL,yBAAyB,EACzB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,mBAAmB,EACxB,aAAa,EACb,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/entrypoints/react.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,yBAAyB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EACL,yBAAyB,EACzB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,mBAAmB,EACxB,aAAa,EACb,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC"}
@@ -36,28 +36,71 @@ function createCacheBridge(config) {
36
36
  expiryTimers.clear();
37
37
  freshAt.clear();
38
38
  };
39
+ let connected = false;
40
+ let clearWatched;
41
+ const disconnect = () => {
42
+ for (const off of unsubscribers)
43
+ off();
44
+ unsubscribers = [];
45
+ connected = false;
46
+ clearFresh();
47
+ config.session?.signal.removeEventListener("abort", invalidateSession);
48
+ };
49
+ const invalidateSession = () => {
50
+ disconnect();
51
+ clearWatched?.();
52
+ };
39
53
  return {
40
54
  connect() {
41
- if (unsubscribers.length > 0)
55
+ config.session?.assertCurrent();
56
+ if (connected)
42
57
  return;
43
58
  const queryClient = typeof config.queryClient === "function" ? config.queryClient() : config.queryClient;
44
- const ctx = { queryClient, isFresh };
45
- const handlers = config.handlers;
46
- const socket = config.socket;
47
- for (const event of Object.keys(handlers)) {
48
- const handler = handlers[event];
49
- if (!handler)
50
- continue;
51
- const off = socket.on(event, (data) => handler(data, ctx));
52
- unsubscribers.push(off);
59
+ connected = true;
60
+ try {
61
+ clearWatched = () => {
62
+ for (const binding of config.watched ?? [])
63
+ queryClient.removeQueries({ queryKey: binding.queryKey, exact: true });
64
+ };
65
+ config.session?.signal.addEventListener("abort", invalidateSession, { once: true });
66
+ for (const binding of config.watched ?? []) {
67
+ unsubscribers.push(binding.handle.subscribe({
68
+ value(value) {
69
+ if (!config.session || config.session.current())
70
+ queryClient.setQueryData(binding.queryKey, value);
71
+ },
72
+ state(state) {
73
+ if (config.session && !config.session.current())
74
+ return;
75
+ if (state.phase !== "live")
76
+ queryClient.invalidateQueries({
77
+ queryKey: binding.queryKey,
78
+ exact: true,
79
+ refetchType: "none"
80
+ });
81
+ binding.state?.(state);
82
+ }
83
+ }));
84
+ }
85
+ const ctx = { queryClient, isFresh };
86
+ const handlers = config.handlers;
87
+ const socket = config.socket;
88
+ for (const event of Object.keys(handlers)) {
89
+ const handler = handlers[event];
90
+ if (!handler)
91
+ continue;
92
+ const off = socket.on(event, (data) => {
93
+ if (!config.session || config.session.current())
94
+ handler(data, ctx);
95
+ });
96
+ unsubscribers.push(off);
97
+ }
98
+ } catch (error) {
99
+ disconnect();
100
+ throw error;
53
101
  }
54
102
  },
55
- disconnect() {
56
- for (const off of unsubscribers)
57
- off();
58
- unsubscribers = [];
59
- clearFresh();
60
- },
103
+ disconnect,
61
104
  markFresh(key) {
62
105
  const serialised = JSON.stringify(key);
63
106
  const existingTimer = expiryTimers.get(serialised);
@@ -34,7 +34,7 @@ import {
34
34
  prepareProjectedMcpTools,
35
35
  projectToolSurface,
36
36
  staticInputRounds
37
- } from "../index-np4m8hd3.js";
37
+ } from "../index-0r0fbk7z.js";
38
38
  import {
39
39
  toJsonSchema
40
40
  } from "../index-eqqvgdb3.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  defineRuntimeTool
3
- } from "../../index-xw3s75nj.js";
3
+ } from "../../index-d8m8zpd8.js";
4
4
  import {
5
5
  declaresDraft07,
6
6
  withDefsDialect
7
- } from "../../index-np4m8hd3.js";
7
+ } from "../../index-0r0fbk7z.js";
8
8
  import"../../index-eqqvgdb3.js";
9
9
  import"../../index-znfs20ss.js";
10
10
  import"../../index-p5r7qpdd.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  createToolInvoker
3
- } from "../../index-p9sh0xx4.js";
4
- import"../../index-khtgb21r.js";
5
- import"../../index-55hkhm67.js";
3
+ } from "../../index-5p2m7we1.js";
4
+ import"../../index-bm5rx7n6.js";
5
+ import"../../index-8qt2m66q.js";
6
6
  import"../../index-zfrhfn82.js";
7
7
  import"../../index-35mh5bhj.js";
8
8
  import"../../index-zcgf3gqf.js";
9
9
  import"../../index-1zbbzgfh.js";
10
- import"../../index-np4m8hd3.js";
10
+ import"../../index-0r0fbk7z.js";
11
11
  import"../../index-eqqvgdb3.js";
12
12
  import"../../index-znfs20ss.js";
13
13
  import"../../index-p5r7qpdd.js";
@@ -23,7 +23,7 @@ import {
23
23
  buildToolManifest,
24
24
  describeToolCatalog,
25
25
  mountAgent
26
- } from "../index-863ea9jb.js";
26
+ } from "../index-sh3s86na.js";
27
27
  import {
28
28
  AgentToolError,
29
29
  EffectUnresolvedError,
@@ -52,7 +52,7 @@ import {
52
52
  } from "../index-m9zn6cpq.js";
53
53
  import {
54
54
  createToolInvoker
55
- } from "../index-p9sh0xx4.js";
55
+ } from "../index-5p2m7we1.js";
56
56
  import {
57
57
  WaitTimeoutError,
58
58
  createCli,
@@ -60,11 +60,11 @@ import {
60
60
  fetchPinnedDocument,
61
61
  readCapped,
62
62
  runWaitOperation
63
- } from "../index-f1nb70ae.js";
63
+ } from "../index-r066jx76.js";
64
64
  import"../index-sbdmyz75.js";
65
65
  import {
66
66
  collectToolSurface
67
- } from "../index-hmp4800j.js";
67
+ } from "../index-9t3dffv2.js";
68
68
  import {
69
69
  argumentsDigest
70
70
  } from "../index-0b1ess5e.js";
@@ -72,13 +72,13 @@ import {
72
72
  collectTools,
73
73
  createToolRunner,
74
74
  formatToolError
75
- } from "../index-khtgb21r.js";
75
+ } from "../index-bm5rx7n6.js";
76
76
  import {
77
77
  ToolExecutionControlError,
78
78
  isToolExecutionControlError,
79
79
  parseToolCallArguments,
80
80
  toolResultFromError
81
- } from "../index-55hkhm67.js";
81
+ } from "../index-8qt2m66q.js";
82
82
  import {
83
83
  getRequestContext,
84
84
  getTraceId,
@@ -94,7 +94,7 @@ import {
94
94
  import {
95
95
  createRuntimeToolFactory,
96
96
  defineRuntimeTool
97
- } from "../index-xw3s75nj.js";
97
+ } from "../index-d8m8zpd8.js";
98
98
  import {
99
99
  PORTABLE_JSON_SCHEMA_FORMATS,
100
100
  assertToolName,
@@ -108,7 +108,7 @@ import {
108
108
  toolSurfaceOutputSchema,
109
109
  validateMcpRoundPolicy,
110
110
  validateResolvedInputRounds
111
- } from "../index-np4m8hd3.js";
111
+ } from "../index-0r0fbk7z.js";
112
112
  import {
113
113
  toJsonSchema
114
114
  } from "../index-eqqvgdb3.js";