experimental-a2 0.18.0 → 0.18.1

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 (114) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{actor-Bjce9_5U.d.ts → actor-C7b-1arn.d.ts} +3 -3
  3. package/dist/{actor-Bjce9_5U.d.ts.map → actor-C7b-1arn.d.ts.map} +1 -1
  4. package/dist/actor-client.d.ts +1 -1
  5. package/dist/actor-react.d.ts +1 -1
  6. package/dist/actor-react.js +1 -1
  7. package/dist/actor.d.ts +1 -1
  8. package/dist/actor.js +2 -2
  9. package/dist/{ai-DrUaMyRt.d.ts → ai-BMLlI2Ff.d.ts} +2 -2
  10. package/dist/{ai-DrUaMyRt.d.ts.map → ai-BMLlI2Ff.d.ts.map} +1 -1
  11. package/dist/{ai-BpOGm-zB.js → ai-D6mGlO8j.js} +2 -2
  12. package/dist/{ai-BpOGm-zB.js.map → ai-D6mGlO8j.js.map} +1 -1
  13. package/dist/ai-client.d.ts +1 -1
  14. package/dist/ai-client.js +2 -2
  15. package/dist/ai-fx.d.ts +1 -1
  16. package/dist/ai-fx.d.ts.map +1 -1
  17. package/dist/ai-fx.js +92 -34
  18. package/dist/ai-fx.js.map +1 -1
  19. package/dist/{ai-harness-DvsPeJeB.d.ts → ai-harness-B2suP2Qh.d.ts} +2 -2
  20. package/dist/{ai-harness-DvsPeJeB.d.ts.map → ai-harness-B2suP2Qh.d.ts.map} +1 -1
  21. package/dist/ai-pi.d.ts +1 -1
  22. package/dist/ai-pi.d.ts.map +1 -1
  23. package/dist/ai-pi.js +59 -13
  24. package/dist/ai-pi.js.map +1 -1
  25. package/dist/ai-react.d.ts +1 -1
  26. package/dist/ai-react.js +2 -2
  27. package/dist/ai-server.d.ts +3 -3
  28. package/dist/ai-server.d.ts.map +1 -1
  29. package/dist/ai-server.js +10 -6
  30. package/dist/ai-server.js.map +1 -1
  31. package/dist/ai-tool-input-DmSqMUQi.js +40 -0
  32. package/dist/ai-tool-input-DmSqMUQi.js.map +1 -0
  33. package/dist/ai.d.ts +1 -1
  34. package/dist/ai.js +1 -1
  35. package/dist/{client-BReKqwZC.js → client-BhHLoNKF.js} +3 -3
  36. package/dist/{client-BReKqwZC.js.map → client-BhHLoNKF.js.map} +1 -1
  37. package/dist/client.js +1 -1
  38. package/dist/index.d.ts +2 -2
  39. package/dist/{internal-B2T3U4Rq.js → internal-CscSY7K_.js} +4 -2
  40. package/dist/{internal-B2T3U4Rq.js.map → internal-CscSY7K_.js.map} +1 -1
  41. package/dist/react.js +1 -1
  42. package/dist/scheduler-qstash.d.ts +2 -2
  43. package/dist/scheduler-qstash.js +3 -3
  44. package/dist/scheduler-qstash.js.map +1 -1
  45. package/dist/scheduler-vercel.d.ts +7 -7
  46. package/dist/scheduler-vercel.d.ts.map +1 -1
  47. package/dist/scheduler-vercel.js +9 -10
  48. package/dist/scheduler-vercel.js.map +1 -1
  49. package/dist/{server-Dw_k_7kO.js → server-D-Y4pqwu.js} +37 -11
  50. package/dist/server-D-Y4pqwu.js.map +1 -0
  51. package/dist/{server-En7cbi3v.d.ts → server-DYAATFuT.d.ts} +11 -5
  52. package/dist/server-DYAATFuT.d.ts.map +1 -0
  53. package/dist/server.d.ts +2 -2
  54. package/dist/server.js +1 -1
  55. package/dist/{session-clear-Bo-XTFEy.d.ts → session-clear-C-QwTXV1.d.ts} +2 -2
  56. package/dist/session-clear-C-QwTXV1.d.ts.map +1 -0
  57. package/dist/{store-Djdv0bnZ.d.ts → store-CyLUy86v.d.ts} +23 -4
  58. package/dist/store-CyLUy86v.d.ts.map +1 -0
  59. package/dist/store-N8PXxDAS.js.map +1 -1
  60. package/dist/store-memory.d.ts +1 -1
  61. package/dist/store-memory.js +25 -6
  62. package/dist/store-memory.js.map +1 -1
  63. package/dist/{store-polling-B5FcwJfo.js → store-polling-7WJV0YWP.js} +2 -2
  64. package/dist/{store-polling-B5FcwJfo.js.map → store-polling-7WJV0YWP.js.map} +1 -1
  65. package/dist/store-postgres.d.ts +1 -1
  66. package/dist/store-postgres.d.ts.map +1 -1
  67. package/dist/store-postgres.js +55 -25
  68. package/dist/store-postgres.js.map +1 -1
  69. package/dist/{store-presence-polling-BAwS8RWn.js → store-presence-polling-B1ixeqIS.js} +3 -3
  70. package/dist/{store-presence-polling-BAwS8RWn.js.map → store-presence-polling-B1ixeqIS.js.map} +1 -1
  71. package/dist/store-redis-http.d.ts +1 -1
  72. package/dist/store-redis-http.js +3 -3
  73. package/dist/{store-redis-notify-BRITti_o.js → store-redis-notify-CM0AfLY0.js} +88 -37
  74. package/dist/store-redis-notify-CM0AfLY0.js.map +1 -0
  75. package/dist/store-redis.d.ts +1 -1
  76. package/dist/store-redis.js +1 -1
  77. package/dist/store-sqlite.d.ts +1 -1
  78. package/dist/store-sqlite.js +35 -20
  79. package/dist/store-sqlite.js.map +1 -1
  80. package/dist/{wire-rSUglYo8.js → wire-BKxH1vbP.js} +2 -2
  81. package/dist/{wire-rSUglYo8.js.map → wire-BKxH1vbP.js.map} +1 -1
  82. package/docs/agents/03-conversations.mdx +2 -2
  83. package/docs/index.mdx +3 -3
  84. package/docs/reference/02-server.mdx +12 -7
  85. package/docs/reference/04-ai.mdx +16 -7
  86. package/docs/reference/05-adapters.mdx +4 -4
  87. package/docs/server/01-handlers.mdx +1 -1
  88. package/docs/server/03-cancellation.mdx +3 -2
  89. package/docs/server/05-production.mdx +2 -1
  90. package/docs/server/06-guarantees.mdx +20 -11
  91. package/examples/playground/DEPLOY.md +2 -4
  92. package/examples/playground/app/a0/[appId]/page.tsx +2 -8
  93. package/examples/playground/app/a0/devtools.tsx +2 -8
  94. package/examples/playground/app/a0/server.ts +8 -19
  95. package/examples/playground/package.json +1 -1
  96. package/package.json +1 -1
  97. package/src/ai-agent.ts +10 -3
  98. package/src/ai-fx.ts +126 -47
  99. package/src/ai-pi.ts +74 -15
  100. package/src/ai-tool-input.ts +45 -0
  101. package/src/internal.ts +6 -0
  102. package/src/scheduler-qstash.ts +5 -5
  103. package/src/scheduler-vercel.ts +14 -15
  104. package/src/server.ts +58 -12
  105. package/src/store-memory.ts +50 -9
  106. package/src/store-postgres.ts +79 -28
  107. package/src/store-redis-core.ts +112 -31
  108. package/src/store-sqlite.ts +61 -28
  109. package/src/store.ts +22 -3
  110. package/dist/server-Dw_k_7kO.js.map +0 -1
  111. package/dist/server-En7cbi3v.d.ts.map +0 -1
  112. package/dist/session-clear-Bo-XTFEy.d.ts.map +0 -1
  113. package/dist/store-Djdv0bnZ.d.ts.map +0 -1
  114. package/dist/store-redis-notify-BRITti_o.js.map +0 -1
@@ -1,12 +1,12 @@
1
1
  import { a as NonRetriableError, i as A2Error, n as isSessionCleared, o as asStoreUnavailable, r as sessionClearedError } from "./session-clear-DGI4jTQ5.js";
2
2
  import { n as foldEvent, s as validateSync, t as cloneInitial } from "./reducer-BAXc8JyF.js";
3
3
  import { n as encodeState, t as decodeState } from "./reducer-runtime-DQwz_J59.js";
4
- import { _ as nullProtoRecord, c as STATE_CACHE, g as markSchedulerSendFailure, i as POLL_TIMINGS, l as STREAM_TIMINGS, m as failedPreviousAttempt, o as RESERVED_PARTICIPANT_IDS, s as SOCKET_TIMINGS, t as DRAIN_TIMINGS, v as serverInternals, y as stateTailReaders } from "./internal-B2T3U4Rq.js";
4
+ import { _ as nullProtoRecord, c as STATE_CACHE, g as markSchedulerSendFailure, i as POLL_TIMINGS, l as STREAM_TIMINGS, m as failedPreviousAttempt, o as RESERVED_PARTICIPANT_IDS, s as SOCKET_TIMINGS, t as DRAIN_TIMINGS, v as serverInternals, y as stateTailReaders } from "./internal-CscSY7K_.js";
5
5
  import { t as boundedCache } from "./bounded-cache-CPHWF-8h.js";
6
- import { i as streamActivities, r as createStreamActivity, t as defaultSleep } from "./store-polling-B5FcwJfo.js";
6
+ import { i as streamActivities, r as createStreamActivity, t as defaultSleep } from "./store-polling-7WJV0YWP.js";
7
7
  import { i as takeBuffered, n as isSerializedEvent, r as parseSerializedEvent, t as bufferedEvents } from "./stream-buffer-Cx7AAPGq.js";
8
8
  import { r as platformWaitUntil, t as invocationDeadlineMs } from "./platform-B4TnJtWu.js";
9
- import { A as stateSnapshotToWire, C as serializedEventToWireJson, D as socketFrameFor, E as socketEventsFor, O as socketSubscribedFor, S as presenceSnapshotToWire, T as socketErrorAckFor, b as presencePatchToWire, d as heldEventBatch, i as compactEventJson, j as wireVersion, k as socketUnsubscribedFor, m as isStreamEvent, n as SOCKET_PING_FRAME, o as errorStatus, r as asA2Error, s as errorToWire, t as EVENT_WRITE_CHARS, u as eventToWire, w as socketAckFor } from "./wire-rSUglYo8.js";
9
+ import { A as stateSnapshotToWire, C as serializedEventToWireJson, D as socketFrameFor, E as socketEventsFor, O as socketSubscribedFor, S as presenceSnapshotToWire, T as socketErrorAckFor, b as presencePatchToWire, d as heldEventBatch, i as compactEventJson, j as wireVersion, k as socketUnsubscribedFor, m as isStreamEvent, n as SOCKET_PING_FRAME, o as errorStatus, r as asA2Error, s as errorToWire, t as EVENT_WRITE_CHARS, u as eventToWire, w as socketAckFor } from "./wire-BKxH1vbP.js";
10
10
  import { t as retryableLazy } from "./retryable-lazy-DZWmHpii.js";
11
11
  //#region src/push-envelope.ts
12
12
  /**
@@ -1105,6 +1105,8 @@ function handler(entry) {
1105
1105
  return typeof entry === "function" ? { handler: entry } : entry;
1106
1106
  }
1107
1107
  const MAX_FAILURES = 10;
1108
+ /** How long an event waits after its `failureCount`th failed attempt. */
1109
+ const failureRetryDelayMs = (failureCount) => Math.min(DRAIN_TIMINGS.failureRetryBaseMs * 2 ** Math.max(failureCount - 1, 0), DRAIN_TIMINGS.failureRetryMaxMs);
1108
1110
  /** Abort a lost attempt's handler and release its drain slot. */
1109
1111
  function endSuperseded(entry, message) {
1110
1112
  entry.supersede.abort(new A2Error("SUPERSEDED_ATTEMPT", message));
@@ -1165,9 +1167,11 @@ function pruneAbortHub(hub) {
1165
1167
  for (const [index, event] of hub.seen) if (index <= minimum || !types.has(event.type)) hub.seen.delete(index);
1166
1168
  }
1167
1169
  /**
1168
- * Deadlines tighten the claim/watchdog window; they never decide whether a
1169
- * handler starts. A platform timeout therefore follows the same path as any
1170
- * other process death: the in-flight event remains pending and is retried.
1170
+ * Deadlines tighten the claim/watchdog window, and a passed deadline ends
1171
+ * claiming: a claim then could not run, only lapse and be claimed again until
1172
+ * the platform ends the process. A platform timeout otherwise follows the
1173
+ * same path as any other process death: the in-flight event remains pending
1174
+ * and a fresh invocation retries it.
1171
1175
  */
1172
1176
  function nextClaimWindow() {
1173
1177
  const nowMs = Date.now();
@@ -1180,7 +1184,8 @@ function nextClaimWindow() {
1180
1184
  ttlMs,
1181
1185
  expiresAtMs,
1182
1186
  watchdogAtMs: expiresAtMs + DRAIN_TIMINGS.watchdogGraceMs,
1183
- deadlineCapped
1187
+ deadlineCapped,
1188
+ pastDeadline: deadlineMs !== null && deadlineTtlMs <= 0
1184
1189
  };
1185
1190
  }
1186
1191
  function schedulerSlot(dueAt) {
@@ -2639,6 +2644,19 @@ function createServer(options) {
2639
2644
  renewal = tracked;
2640
2645
  return tracked;
2641
2646
  };
2647
+ /** Records an event the store dead-lettered on takeover; it never runs. */
2648
+ const reportExhausted = (event) => telemetry.span("a2.event", {
2649
+ "a2.contract": name,
2650
+ "a2.session_id": sessionId,
2651
+ "a2.event.type": event.type,
2652
+ "a2.event.index": event.index,
2653
+ "a2.event.id": event.id,
2654
+ "a2.event.attempt": event.attemptCount,
2655
+ "a2.event.handled": handlers.has(event.type),
2656
+ ...event.lane === null ? {} : { "a2.event.lane": event.lane }
2657
+ }, async (eventSpan) => {
2658
+ eventSpan.setAttribute("a2.event.outcome", "dead_lettered");
2659
+ });
2642
2660
  const runEvent = async (event, supersedeSignal, endAttempt) => {
2643
2661
  const registration = handlers.get(event.type);
2644
2662
  return telemetry.span("a2.event", {
@@ -2688,7 +2706,8 @@ function createServer(options) {
2688
2706
  index: event.index,
2689
2707
  attempt: event.attemptCount,
2690
2708
  error: describeError(err),
2691
- maxFailures: err instanceof NonRetriableError ? 1 : MAX_FAILURES
2709
+ maxFailures: err instanceof NonRetriableError ? 1 : MAX_FAILURES,
2710
+ retryAfterMs: failureRetryDelayMs(event.failureCount + 1)
2692
2711
  });
2693
2712
  commitSpan.setAttribute("a2.commit.outcome", result.outcome);
2694
2713
  return result;
@@ -2780,6 +2799,10 @@ function createServer(options) {
2780
2799
  let claim;
2781
2800
  if (shouldClaim) {
2782
2801
  const window = nextClaimWindow();
2802
+ if (window.pastDeadline) {
2803
+ outcome = "busy";
2804
+ break;
2805
+ }
2783
2806
  claim = await telemetry.span("a2.claim", {
2784
2807
  "a2.contract": name,
2785
2808
  "a2.session_id": sessionId
@@ -2788,6 +2811,7 @@ function createServer(options) {
2788
2811
  sessionId: ns,
2789
2812
  holder,
2790
2813
  ttlMs: window.ttlMs,
2814
+ maxFailures: MAX_FAILURES,
2791
2815
  ...window.deadlineCapped ? { expiresAtMs: window.expiresAtMs } : {},
2792
2816
  ...excluded.size === 0 ? {} : { excludeIndexes: [...excluded] }
2793
2817
  });
@@ -2796,9 +2820,11 @@ function createServer(options) {
2796
2820
  return result;
2797
2821
  });
2798
2822
  if (claim.outcome === "claimed") {
2799
- requestWatchdog(window.watchdogAtMs);
2823
+ const runnable = claim.events.filter((event) => event.failedAt === null);
2824
+ for (const event of claim.events) if (event.failedAt !== null) await reportExhausted(event);
2825
+ if (runnable.length > 0) requestWatchdog(window.watchdogAtMs);
2800
2826
  if (window.deadlineCapped) stopRenewing = true;
2801
- for (const event of claim.events) start(event, window.expiresAtMs);
2827
+ for (const event of runnable) start(event, window.expiresAtMs);
2802
2828
  shouldClaim = false;
2803
2829
  }
2804
2830
  }
@@ -3023,4 +3049,4 @@ const stateCacheKey = (sessionId, reducerName) => `${sessionId}\u0000${reducerNa
3023
3049
  //#endregion
3024
3050
  export { CONSOLE_TELEMETRY as a, parsePresenceSibling as c, handler as i, deliverSchedulerAppend as n, setServerFetchHooks as o, deliverSchedulerClear as r, sseResponse as s, createServer as t };
3025
3051
 
3026
- //# sourceMappingURL=server-Dw_k_7kO.js.map
3052
+ //# sourceMappingURL=server-D-Y4pqwu.js.map