agents 0.23.0 → 0.25.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 (187) hide show
  1. package/dist/{agent-routing-DE5zmCQ8.d.ts → agent-routing-0DR0Tk2v.d.ts} +270 -190
  2. package/dist/agent-routing.d.ts +1 -1
  3. package/dist/agent-routing.js.map +1 -1
  4. package/dist/agent-tool-types.d.ts +13 -7
  5. package/dist/agent-tool-types.js +23 -1
  6. package/dist/agent-tool-types.js.map +1 -1
  7. package/dist/{agent-tools-y7zLfw4Q.js → agent-tools-CdJC-8Dc.js} +72 -9
  8. package/dist/agent-tools-CdJC-8Dc.js.map +1 -0
  9. package/dist/{agent-tools-DtXMTDGM.d.ts → agent-tools-YrATZJu2.d.ts} +29 -15
  10. package/dist/agent-tools.d.ts +6 -4
  11. package/dist/agent-tools.js.map +1 -1
  12. package/dist/ai-fm7xx1BK.js +312 -0
  13. package/dist/ai-fm7xx1BK.js.map +1 -0
  14. package/dist/base64-redaction-C1Uu29t5.js +59 -0
  15. package/dist/base64-redaction-C1Uu29t5.js.map +1 -0
  16. package/dist/browser/ai-sdk.d.ts +90 -0
  17. package/dist/browser/ai-sdk.js +51 -0
  18. package/dist/browser/ai-sdk.js.map +1 -0
  19. package/dist/browser/ai.d.ts +4 -4
  20. package/dist/browser/ai.js +1 -347
  21. package/dist/browser/index.d.ts +81 -79
  22. package/dist/browser/index.js +361 -2
  23. package/dist/browser/index.js.map +1 -0
  24. package/dist/browser/tanstack-ai.d.ts +96 -1
  25. package/dist/browser/tanstack-ai.js +62 -2
  26. package/dist/browser/tanstack-ai.js.map +1 -1
  27. package/dist/browser-DE3d-RLk.d.ts +275 -0
  28. package/dist/browser-tool-CQ10e6Kj.js +480 -0
  29. package/dist/browser-tool-CQ10e6Kj.js.map +1 -0
  30. package/dist/browser-tool-DuNdlwZ9.d.ts +73 -0
  31. package/dist/{capability-BjSKYpzg.js → capability-B4WbF81e.js} +2 -1
  32. package/dist/capability-B4WbF81e.js.map +1 -0
  33. package/dist/{capability-runner-Be_-PLR1.d.ts → capability-runner-DBAnGr6L.d.ts} +45 -15
  34. package/dist/chat/index.d.ts +341 -232
  35. package/dist/chat/index.js +602 -72
  36. package/dist/chat/index.js.map +1 -1
  37. package/dist/chat/react.d.ts +42 -2
  38. package/dist/chat/react.js +191 -35
  39. package/dist/chat/react.js.map +1 -1
  40. package/dist/chat/transport.d.ts +1 -1
  41. package/dist/chat/transport.js +1 -1
  42. package/dist/chat-sdk/index.d.ts +17 -3
  43. package/dist/chat-sdk/index.js +28 -2
  44. package/dist/chat-sdk/index.js.map +1 -1
  45. package/dist/client-4OlMIJx-.js +591 -0
  46. package/dist/client-4OlMIJx-.js.map +1 -0
  47. package/dist/{client-jagG8a9_.js → client-fyQrLGkD.js} +2 -2
  48. package/dist/{client-jagG8a9_.js.map → client-fyQrLGkD.js.map} +1 -1
  49. package/dist/client-je3koD9Z.d.ts +446 -0
  50. package/dist/client.d.ts +29 -283
  51. package/dist/client.js +2 -274
  52. package/dist/{connector-CptFKzRh.js → connector-58XDGvc3.js} +251 -120
  53. package/dist/connector-58XDGvc3.js.map +1 -0
  54. package/dist/{connector-CkQD4MK3.d.ts → connector-Cl-VqPmA.d.ts} +244 -146
  55. package/dist/context/index.d.ts +29 -0
  56. package/dist/context/index.js +64 -17
  57. package/dist/context/index.js.map +1 -1
  58. package/dist/current-agent-DhoDkSnH.js.map +1 -1
  59. package/dist/current-agent-vAk_5JMt.d.ts +93 -0
  60. package/dist/{current-agent-Da_C9a3b.d.ts → durable-object-lifecycle-HhgOMWq9.d.ts} +26 -127
  61. package/dist/harnesses/pi/index.d.ts +348 -0
  62. package/dist/harnesses/pi/index.js +754 -0
  63. package/dist/harnesses/pi/index.js.map +1 -0
  64. package/dist/images-iiTDSyRu.js +1631 -0
  65. package/dist/images-iiTDSyRu.js.map +1 -0
  66. package/dist/index-BreL0YrQ.d.ts +78 -0
  67. package/dist/index-kbSUIer3.d.ts +343 -0
  68. package/dist/index.d.ts +43 -41
  69. package/dist/index.js +2 -2
  70. package/dist/internal_context.d.ts +1 -1
  71. package/dist/lifecycle/index.d.ts +19 -17
  72. package/dist/lifecycle/index.js +2 -2
  73. package/dist/{lifecycle-CMRGjZdw.js → lifecycle-CFu6OV03.js} +73 -29
  74. package/dist/lifecycle-CFu6OV03.js.map +1 -0
  75. package/dist/mcp/client/index.d.ts +20 -20
  76. package/dist/mcp/client/index.js +1 -1
  77. package/dist/mcp/client/x402.js +21 -19
  78. package/dist/mcp/client/x402.js.map +1 -1
  79. package/dist/mcp/index.d.ts +35 -35
  80. package/dist/mcp/index.js +2 -2
  81. package/dist/{message-builder-BymO4N_D.js → message-builder-DAl9AhHH.js} +89 -4
  82. package/dist/message-builder-DAl9AhHH.js.map +1 -0
  83. package/dist/models/ai-sdk/index.d.ts +353 -0
  84. package/dist/models/ai-sdk/index.js +2443 -0
  85. package/dist/models/ai-sdk/index.js.map +1 -0
  86. package/dist/models/pi-ai/index.d.ts +313 -0
  87. package/dist/models/pi-ai/index.js +1795 -0
  88. package/dist/models/pi-ai/index.js.map +1 -0
  89. package/dist/observability/ai/index.js +20 -4
  90. package/dist/observability/ai/index.js.map +1 -1
  91. package/dist/{protocol-B0nh6KNf.js → protocol-kHsr-f0X.js} +26 -12
  92. package/dist/{protocol-B0nh6KNf.js.map → protocol-kHsr-f0X.js.map} +1 -1
  93. package/dist/queue/index.d.ts +123 -0
  94. package/dist/queue/index.js +2 -0
  95. package/dist/queue-BB-zfIYF.js +406 -0
  96. package/dist/queue-BB-zfIYF.js.map +1 -0
  97. package/dist/react.d.ts +31 -13
  98. package/dist/react.js +190 -71
  99. package/dist/react.js.map +1 -1
  100. package/dist/{retries-D9Ds-1lz.d.ts → retries-CV6AkXmQ.d.ts} +23 -8
  101. package/dist/retries.d.ts +12 -8
  102. package/dist/retries.js +19 -1
  103. package/dist/retries.js.map +1 -1
  104. package/dist/routing/index.d.ts +2 -2
  105. package/dist/routing/index.js +1 -1
  106. package/dist/{scheduler-DD9NdYbF.js → scheduler-DZ3xQfeK.js} +4 -11
  107. package/dist/scheduler-DZ3xQfeK.js.map +1 -0
  108. package/dist/{scheduler-Dwh85ZGl.d.ts → scheduler-RdACNXDP.d.ts} +6 -6
  109. package/dist/schedules/index.d.ts +1 -1
  110. package/dist/schedules/index.js +1 -1
  111. package/dist/serializable.d.ts +1 -1
  112. package/dist/sessions/index.d.ts +70 -3
  113. package/dist/sessions/index.js +276 -67
  114. package/dist/sessions/index.js.map +1 -1
  115. package/dist/skills/index.d.ts +29 -314
  116. package/dist/socket-address.d.ts +16 -0
  117. package/dist/socket-address.js +19 -0
  118. package/dist/socket-address.js.map +1 -0
  119. package/dist/{src-DlSHshb2.js → src-BZeu-SCD.js} +541 -500
  120. package/dist/src-BZeu-SCD.js.map +1 -0
  121. package/dist/state/index.d.ts +6 -0
  122. package/dist/state/index.js +137 -0
  123. package/dist/state/index.js.map +1 -0
  124. package/dist/streams/index.d.ts +1 -1
  125. package/dist/streams/index.js +1 -1
  126. package/dist/{streams-D6tJ0NN9.d.ts → streams-Cmkj9QfW.d.ts} +4 -2
  127. package/dist/{streams-DZKgAj9b.js → streams-DW-UCOUc.js} +9 -2
  128. package/dist/streams-DW-UCOUc.js.map +1 -0
  129. package/dist/sub-routing.d.ts +12 -12
  130. package/dist/tasks/index.d.ts +1 -1
  131. package/dist/tasks/index.js +1 -1
  132. package/dist/{tasks-ylZgBjhj.js → tasks-68DESxf0.js} +3 -3
  133. package/dist/{tasks-ylZgBjhj.js.map → tasks-68DESxf0.js.map} +1 -1
  134. package/dist/{tasks-BRJ5zgya.d.ts → tasks-9YxYtByh.d.ts} +5 -5
  135. package/dist/transport-PfFnt-Ld.d.ts +525 -0
  136. package/dist/transport-protocol-BxyngQ_R.js +25 -0
  137. package/dist/transport-protocol-BxyngQ_R.js.map +1 -0
  138. package/dist/transport-protocol-ZTew5Wso.d.ts +27 -0
  139. package/dist/types-BA4anrjI.d.ts +70 -0
  140. package/dist/voice/index.d.ts +2 -2
  141. package/dist/websockets/index.d.ts +195 -69
  142. package/dist/websockets/index.js +3 -2
  143. package/dist/websockets-Ci-LZFHH.js +1030 -0
  144. package/dist/websockets-Ci-LZFHH.js.map +1 -0
  145. package/dist/wire-types-CnMt6_HR.js.map +1 -1
  146. package/dist/wire-types-CrjKvDyi.d.ts +300 -0
  147. package/dist/workflow-types.d.ts +25 -25
  148. package/dist/workflows.d.ts +21 -21
  149. package/dist/workflows.js +1 -1
  150. package/dist/{ws-chat-transport-UNRIS2xl.d.ts → ws-chat-transport-BbT1A5Lc.d.ts} +51 -2
  151. package/dist/{ws-chat-transport-rWwta645.js → ws-chat-transport-cqMKq3IY.js} +143 -16
  152. package/dist/ws-chat-transport-cqMKq3IY.js.map +1 -0
  153. package/docs/agent-class.md +2 -2
  154. package/docs/agent-tools.md +29 -4
  155. package/docs/browse-the-web.md +87 -5
  156. package/docs/chat-agents.md +124 -16
  157. package/docs/client-sdk.md +30 -0
  158. package/docs/context.md +27 -0
  159. package/docs/durable-execution.md +2 -0
  160. package/docs/harnesses/pi.md +91 -0
  161. package/docs/human-in-the-loop.md +4 -0
  162. package/docs/index.md +4 -1
  163. package/docs/lifecycle.md +114 -23
  164. package/docs/models-pi-ai.md +325 -0
  165. package/docs/models.md +504 -0
  166. package/docs/queue.md +135 -241
  167. package/docs/resumable-streaming.md +2 -0
  168. package/docs/retries.md +1 -1
  169. package/docs/routing.md +13 -13
  170. package/docs/sessions.md +36 -1
  171. package/docs/state.md +1 -0
  172. package/docs/sub-agents.md +12 -3
  173. package/package.json +51 -3
  174. package/dist/agent-tools-y7zLfw4Q.js.map +0 -1
  175. package/dist/browser/ai.js.map +0 -1
  176. package/dist/capability-BjSKYpzg.js.map +0 -1
  177. package/dist/client-tools-aIBO0Fk7.d.ts +0 -53
  178. package/dist/client.js.map +0 -1
  179. package/dist/connector-CptFKzRh.js.map +0 -1
  180. package/dist/lifecycle-CMRGjZdw.js.map +0 -1
  181. package/dist/message-builder-BymO4N_D.js.map +0 -1
  182. package/dist/scheduler-DD9NdYbF.js.map +0 -1
  183. package/dist/src-DlSHshb2.js.map +0 -1
  184. package/dist/streams-DZKgAj9b.js.map +0 -1
  185. package/dist/websockets-DUfRHPRq.js +0 -502
  186. package/dist/websockets-DUfRHPRq.js.map +0 -1
  187. package/dist/ws-chat-transport-rWwta645.js.map +0 -1
@@ -0,0 +1,406 @@
1
+ import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-DZBYAB34.js";
2
+ import { t as _classPrivateMethodInitSpec } from "./classPrivateMethodInitSpec-qMjJ6sHQ.js";
3
+ import { t as LifecycleCapability } from "./capability-B4WbF81e.js";
4
+ import { isDurableObjectCodeUpdateReset, isPlatformFailure, resolveRetryConfig, tryN, validateRetryOptions } from "./retries.js";
5
+ //#region src/queue/queue.ts
6
+ /**
7
+ * Lifecycle background-work vocabulary. Queue validates items, resolves
8
+ * named callbacks, and pushes jobs due immediately into the Lifecycle-owned
9
+ * job queue; Lifecycle runs the alarm event loop, retry policy, and physical
10
+ * alarm arming. Queue owns no storage of its own — each item is one job
11
+ * whose `fn` is the callback name and whose payload carries the item's
12
+ * payload and owner.
13
+ */
14
+ const queueCallbackResolvers = /* @__PURE__ */ new WeakMap();
15
+ /**
16
+ * @internal Supply a composition-root fallback for callback names outside the
17
+ * registered map. Agent uses this to keep its historical name-based queue
18
+ * API (`this.queue("methodName", payload)`) working: the resolver looks the
19
+ * method up on the Agent, and the resolved handler still runs inside the
20
+ * Lifecycle host boundary.
21
+ */
22
+ function setQueueCallbackResolver(queue, resolver) {
23
+ queueCallbackResolvers.set(queue, resolver);
24
+ }
25
+ const QUEUE_SCHEMA_VERSION_KEY = "cf_agents:queue_schema_version";
26
+ /** Version 1: queue items live in the Lifecycle job queue. */
27
+ const CURRENT_QUEUE_SCHEMA_VERSION = 1;
28
+ const DEFAULT_RETRY = {
29
+ maxAttempts: 3,
30
+ baseDelayMs: 100,
31
+ maxDelayMs: 3e3
32
+ };
33
+ function isQueueJobPayload(value) {
34
+ return typeof value === "object" && value !== null && "owner_path" in value;
35
+ }
36
+ var _handlers = /* @__PURE__ */ new WeakMap();
37
+ var _retryDefaults = /* @__PURE__ */ new WeakMap();
38
+ var _onError = /* @__PURE__ */ new WeakMap();
39
+ var _lastTime = /* @__PURE__ */ new WeakMap();
40
+ var _Queue_brand = /* @__PURE__ */ new WeakSet();
41
+ /**
42
+ * Durable background work for a Lifecycle Object.
43
+ *
44
+ * Register callbacks in the constructor and install the instance with
45
+ * `Lifecycle.use()`. Each pushed item becomes a job due immediately in the
46
+ * Lifecycle job queue; Lifecycle owns the physical alarm and the alarm event
47
+ * loop, drives items one at a time in push order, retries a throwing
48
+ * callback per its retry policy, and Queue runs registered callbacks through
49
+ * Lifecycle's host invocation boundary. An item that still fails after its
50
+ * last attempt is dropped after `queue:error` and the `onError` hook.
51
+ *
52
+ * Items survive the Durable Object leaving memory: an isolate that dies mid
53
+ * callback wakes again on the Lifecycle deadman alarm and resumes the queue.
54
+ * Callbacks should therefore be idempotent.
55
+ *
56
+ * @experimental The API surface may change before stabilizing.
57
+ */
58
+ var Queue = class extends LifecycleCapability {
59
+ /**
60
+ * Create a durable Queue.
61
+ *
62
+ * @param options - Registered callbacks plus optional retry and error
63
+ * policy. Registering `callbacks` types {@link push} against the map —
64
+ * names and payloads are checked where the handlers are declared and where
65
+ * they are pushed. Names outside the map are rejected unless a
66
+ * composition-root resolver supplies them — the internal aperture behind
67
+ * `Agent`'s name-based queue API.
68
+ */
69
+ constructor(options = {}) {
70
+ super("queue");
71
+ _classPrivateMethodInitSpec(this, _Queue_brand);
72
+ _classPrivateFieldInitSpec(this, _handlers, void 0);
73
+ _classPrivateFieldInitSpec(this, _retryDefaults, void 0);
74
+ _classPrivateFieldInitSpec(this, _onError, void 0);
75
+ _classPrivateFieldInitSpec(this, _lastTime, null);
76
+ _classPrivateFieldSet2(_handlers, this, options.callbacks ?? {});
77
+ _classPrivateFieldSet2(_retryDefaults, this, resolveRetryConfig(options.retry, DEFAULT_RETRY));
78
+ _classPrivateFieldSet2(_onError, this, options.onError);
79
+ }
80
+ /** Migrate legacy `cf_agents_queues` rows into the Lifecycle job queue. */
81
+ async onStart() {
82
+ const storage = this.lifecycle.storage;
83
+ if ((await storage.get(QUEUE_SCHEMA_VERSION_KEY) ?? 0) >= CURRENT_QUEUE_SCHEMA_VERSION) return;
84
+ await _assertClassBrand(_Queue_brand, this, _migrateLegacyQueueTable).call(this, storage);
85
+ await storage.put(QUEUE_SCHEMA_VERSION_KEY, CURRENT_QUEUE_SCHEMA_VERSION);
86
+ }
87
+ /** Drive one due item dispatched by the Lifecycle event loop. */
88
+ async onJob(context) {
89
+ const { job, attempt } = context;
90
+ if (!isQueueJobPayload(job.payload)) {
91
+ console.error(`Malformed queue item ${job.id}; dropping it`);
92
+ return;
93
+ }
94
+ const item = _assertClassBrand(_Queue_brand, this, _jobToItem).call(this, job, job.payload);
95
+ if (attempt > 1) _assertClassBrand(_Queue_brand, this, _emit).call(this, "queue:retry", {
96
+ callback: job.fn,
97
+ id: job.id,
98
+ attempt,
99
+ maxAttempts: resolveRetryConfig(job.retry, _classPrivateFieldGet2(_retryDefaults, this)).maxAttempts
100
+ });
101
+ if (job.payload.owner_path) {
102
+ try {
103
+ await this.lifecycle.routes.to({
104
+ key: job.payload.owner_path_key ?? job.payload.owner_path,
105
+ data: job.payload.owner_path
106
+ }, {
107
+ type: "dispatch",
108
+ item
109
+ });
110
+ } catch (error) {
111
+ if (isPlatformFailure(error)) throw error;
112
+ console.error(`error dispatching queue callback "${job.fn}"`, error);
113
+ _assertClassBrand(_Queue_brand, this, _emit).call(this, "queue:error", {
114
+ callback: job.fn,
115
+ id: job.id,
116
+ error: error instanceof Error ? error.message : String(error),
117
+ attempts: 0
118
+ });
119
+ try {
120
+ await _classPrivateFieldGet2(_onError, this)?.call(this, error);
121
+ } catch {}
122
+ return "yield";
123
+ }
124
+ return;
125
+ }
126
+ const handler = _assertClassBrand(_Queue_brand, this, _resolveCallback).call(this, job.fn);
127
+ if (!handler) {
128
+ console.error(`callback ${job.fn} not found`);
129
+ return;
130
+ }
131
+ await this.lifecycle.runInHostContext(() => handler(item.payload, item));
132
+ }
133
+ /** Observe one item's terminal application failure; the item is dropped. */
134
+ async onJobError(context, error) {
135
+ const { job } = context;
136
+ const { maxAttempts } = resolveRetryConfig(job.retry, _classPrivateFieldGet2(_retryDefaults, this));
137
+ console.error(`queue callback "${job.fn}" failed after ${maxAttempts} attempts`, error);
138
+ _assertClassBrand(_Queue_brand, this, _emit).call(this, "queue:error", {
139
+ callback: job.fn,
140
+ id: job.id,
141
+ error: error instanceof Error ? error.message : String(error),
142
+ attempts: maxAttempts
143
+ });
144
+ try {
145
+ await _classPrivateFieldGet2(_onError, this)?.call(this, error);
146
+ } catch {}
147
+ }
148
+ /** Handle Queue protocol messages routed by another Lifecycle. */
149
+ async onRoute(context) {
150
+ const message = context.payload;
151
+ const owner = context.source ?? null;
152
+ switch (message.type) {
153
+ case "push": return _assertClassBrand(_Queue_brand, this, _insert).call(this, owner, message.callback, message.payload, message.options);
154
+ case "get": return _assertClassBrand(_Queue_brand, this, _getForOwner).call(this, owner, message.id);
155
+ case "list": return _assertClassBrand(_Queue_brand, this, _listForOwner).call(this, owner, message.criteria);
156
+ case "cancel": return _assertClassBrand(_Queue_brand, this, _cancelForOwner).call(this, owner, message.id);
157
+ case "cancelAll": return _assertClassBrand(_Queue_brand, this, _cancelAllForOwner).call(this, owner, message.callback);
158
+ case "dispatch":
159
+ await _assertClassBrand(_Queue_brand, this, _executeRouted).call(this, message.item);
160
+ return true;
161
+ default: throw new Error("Unknown routed Queue message");
162
+ }
163
+ }
164
+ /**
165
+ * Push one item for a registered callback. The item is due immediately;
166
+ * the Lifecycle alarm event loop runs it in push order after this call
167
+ * returns.
168
+ *
169
+ * Once the Lifecycle has started (and this Queue is not routed through
170
+ * another Lifecycle), the item row is written synchronously before this
171
+ * method's promise is even returned, so a caller may pair a push with its
172
+ * own writes in one synchronous block — the item then commits atomically
173
+ * with them.
174
+ */
175
+ async push(callback, payload, options) {
176
+ if (this.lifecycle.status() !== "started") await this.lifecycle.ready();
177
+ _assertClassBrand(_Queue_brand, this, _validatePush).call(this, callback, options);
178
+ const item = this.lifecycle.routes.source ? await this.lifecycle.routes.toRoot({
179
+ type: "push",
180
+ callback,
181
+ payload,
182
+ options
183
+ }) : await _assertClassBrand(_Queue_brand, this, _insert).call(this, null, callback, payload, options);
184
+ _assertClassBrand(_Queue_brand, this, _emit).call(this, "queue:create", {
185
+ callback,
186
+ id: item.id
187
+ });
188
+ return item;
189
+ }
190
+ /** Cancel one pending item. Returns false when no item matched. */
191
+ async cancel(id) {
192
+ await this.lifecycle.ready();
193
+ if (this.lifecycle.routes.source) return await this.lifecycle.routes.toRoot({
194
+ type: "cancel",
195
+ id
196
+ });
197
+ return _assertClassBrand(_Queue_brand, this, _cancelForOwner).call(this, null, id);
198
+ }
199
+ /** Cancel every pending item, or every item for one callback. Returns the count. */
200
+ async cancelAll(callback) {
201
+ await this.lifecycle.ready();
202
+ if (this.lifecycle.routes.source) return await this.lifecycle.routes.toRoot({
203
+ type: "cancelAll",
204
+ callback
205
+ });
206
+ return _assertClassBrand(_Queue_brand, this, _cancelAllForOwner).call(this, null, callback);
207
+ }
208
+ /** Read one pending item. */
209
+ async get(id) {
210
+ await this.lifecycle.ready();
211
+ if (this.lifecycle.routes.source) return await this.lifecycle.routes.toRoot({
212
+ type: "get",
213
+ id
214
+ });
215
+ return _assertClassBrand(_Queue_brand, this, _getForOwner).call(this, null, id);
216
+ }
217
+ /** List pending items in push order, optionally filtered by callback. */
218
+ async list(criteria) {
219
+ await this.lifecycle.ready();
220
+ if (this.lifecycle.routes.source) return await this.lifecycle.routes.toRoot({
221
+ type: "list",
222
+ criteria
223
+ });
224
+ return _assertClassBrand(_Queue_brand, this, _listForOwner).call(this, null, criteria);
225
+ }
226
+ /** @internal Remove items owned by one routed Lifecycle subtree. */
227
+ async __DO_NOT_USE_WILL_BREAK__cleanupRoutePrefix(prefix) {
228
+ for (const { job, envelope } of _assertClassBrand(_Queue_brand, this, _ownedJobs).call(this)) {
229
+ const ownerKey = envelope.owner_path_key ?? envelope.owner_path;
230
+ if (!envelope.owner_path || ownerKey === null) continue;
231
+ if (ownerKey !== prefix && !ownerKey.startsWith(`${prefix}/`)) continue;
232
+ await this.lifecycle.jobs.cancel(job.id);
233
+ }
234
+ }
235
+ };
236
+ /**
237
+ * Move every `cf_agents_queues` row into the job queue and drop the
238
+ * table. Idempotent: a missing table means a fresh object or a completed
239
+ * migration. Rows keep their insertion order.
240
+ *
241
+ * TEMPORARY: one-shot upgrade path for objects that had queued items when
242
+ * this release landed. Remove in the next minor release (with the schema
243
+ * version bump that gates it), once every deployed object has migrated.
244
+ */
245
+ async function _migrateLegacyQueueTable(storage) {
246
+ if (storage.sql.exec("SELECT name FROM sqlite_master WHERE type='table' AND name='cf_agents_queues'").toArray().length === 0) return;
247
+ const rows = storage.sql.exec("SELECT * FROM cf_agents_queues ORDER BY created_at ASC, rowid ASC").toArray();
248
+ for (const row of rows) {
249
+ let payload;
250
+ try {
251
+ payload = typeof row.payload === "string" ? JSON.parse(row.payload) : void 0;
252
+ } catch (error) {
253
+ console.error(`Skipping queue item "${row.id}" during job-queue migration: its payload is not valid JSON`, error);
254
+ continue;
255
+ }
256
+ let retry;
257
+ try {
258
+ retry = typeof row.retry_options === "string" ? JSON.parse(row.retry_options) : void 0;
259
+ } catch {
260
+ retry = void 0;
261
+ }
262
+ await this.lifecycle.jobs.push({
263
+ id: row.id,
264
+ fn: row.callback,
265
+ time: _assertClassBrand(_Queue_brand, this, _nextTime).call(this),
266
+ payload: {
267
+ payload,
268
+ owner_path: null,
269
+ owner_path_key: null
270
+ },
271
+ retry: resolveRetryConfig(retry, _classPrivateFieldGet2(_retryDefaults, this))
272
+ });
273
+ }
274
+ storage.sql.exec("DROP TABLE cf_agents_queues");
275
+ }
276
+ /**
277
+ * Execute a routed item locally with the historical retry handling. Runs
278
+ * on the owning (facet) Queue, outside the root's event loop, so it applies
279
+ * its own in-process retry budget. Platform-class failures re-throw so the
280
+ * root preserves the item and the durable alarm retries on a fresh
281
+ * invocation.
282
+ */
283
+ async function _executeRouted(item) {
284
+ const handler = _assertClassBrand(_Queue_brand, this, _resolveCallback).call(this, item.callback);
285
+ if (!handler) {
286
+ console.error(`callback ${item.callback} not found`);
287
+ return;
288
+ }
289
+ const { maxAttempts, baseDelayMs, maxDelayMs } = resolveRetryConfig(item.retry, _classPrivateFieldGet2(_retryDefaults, this));
290
+ try {
291
+ await tryN(maxAttempts, async (attempt) => {
292
+ if (attempt > 1) _assertClassBrand(_Queue_brand, this, _emit).call(this, "queue:retry", {
293
+ callback: item.callback,
294
+ id: item.id,
295
+ attempt,
296
+ maxAttempts
297
+ });
298
+ await this.lifecycle.runInHostContext(() => handler(item.payload, item));
299
+ }, {
300
+ baseDelayMs,
301
+ maxDelayMs,
302
+ shouldRetry: (error) => !isDurableObjectCodeUpdateReset(error)
303
+ });
304
+ } catch (error) {
305
+ if (isPlatformFailure(error)) throw error;
306
+ console.error(`queue callback "${item.callback}" failed after ${maxAttempts} attempts`, error);
307
+ _assertClassBrand(_Queue_brand, this, _emit).call(this, "queue:error", {
308
+ callback: item.callback,
309
+ id: item.id,
310
+ error: error instanceof Error ? error.message : String(error),
311
+ attempts: maxAttempts
312
+ });
313
+ try {
314
+ await _classPrivateFieldGet2(_onError, this)?.call(this, error);
315
+ } catch {}
316
+ }
317
+ }
318
+ function _validatePush(callback, options) {
319
+ if (typeof callback !== "string") throw new Error("Callback must be a string");
320
+ if (!_assertClassBrand(_Queue_brand, this, _hasCallback).call(this, callback)) throw new Error(`Unknown queue callback "${callback}": not registered on this Queue`);
321
+ if (options?.retry) validateRetryOptions(options.retry, _classPrivateFieldGet2(_retryDefaults, this));
322
+ if (options?.id !== void 0 && options.id.trim() === "") throw new Error("Queue item ids must be non-empty");
323
+ }
324
+ /** Resolve a name to its registered or composition-root-supplied handler. */
325
+ function _resolveCallback(name) {
326
+ const handler = _classPrivateFieldGet2(_handlers, this)[name];
327
+ if (handler) return handler;
328
+ return queueCallbackResolvers.get(this)?.(name);
329
+ }
330
+ function _hasCallback(name) {
331
+ return _assertClassBrand(_Queue_brand, this, _resolveCallback).call(this, name) !== void 0;
332
+ }
333
+ /** The next strictly increasing due time, never before now. */
334
+ function _nextTime() {
335
+ if (_classPrivateFieldGet2(_lastTime, this) === null) _classPrivateFieldSet2(_lastTime, this, _assertClassBrand(_Queue_brand, this, _ownedJobs).call(this).reduce((lastTime, { job }) => Math.max(lastTime, job.time), 0));
336
+ const time = Math.max(Date.now(), _classPrivateFieldGet2(_lastTime, this) + 1);
337
+ _classPrivateFieldSet2(_lastTime, this, time);
338
+ return time;
339
+ }
340
+ async function _insert(owner, callback, payload, options) {
341
+ const existing = options?.id !== void 0 ? this.lifecycle.jobs.get(options.id) : void 0;
342
+ const keepTime = existing !== void 0 && _assertClassBrand(_Queue_brand, this, _getForOwner).call(this, owner, existing.id) !== void 0;
343
+ const job = await this.lifecycle.jobs.push({
344
+ id: options?.id,
345
+ fn: callback,
346
+ time: keepTime ? existing.time : _assertClassBrand(_Queue_brand, this, _nextTime).call(this),
347
+ payload: {
348
+ payload,
349
+ owner_path: owner?.data ?? null,
350
+ owner_path_key: owner?.key ?? null
351
+ },
352
+ retry: resolveRetryConfig(options?.retry, _classPrivateFieldGet2(_retryDefaults, this))
353
+ });
354
+ return _assertClassBrand(_Queue_brand, this, _jobToItem).call(this, job, job.payload);
355
+ }
356
+ function _jobToItem(job, envelope) {
357
+ return {
358
+ id: job.id,
359
+ callback: job.fn,
360
+ payload: envelope.payload,
361
+ createdAt: job.createdAt,
362
+ retry: job.retry
363
+ };
364
+ }
365
+ /** Every queue job this Queue owns, in push order. */
366
+ function _ownedJobs() {
367
+ const owned = [];
368
+ for (const job of this.lifecycle.jobs.list()) if (isQueueJobPayload(job.payload)) owned.push({
369
+ job,
370
+ envelope: job.payload
371
+ });
372
+ return owned;
373
+ }
374
+ function _getForOwner(owner, id) {
375
+ const ownerKey = owner?.key ?? null;
376
+ const job = this.lifecycle.jobs.get(id);
377
+ if (!job || !isQueueJobPayload(job.payload)) return void 0;
378
+ if ((job.payload.owner_path_key ?? null) !== ownerKey) return void 0;
379
+ return _assertClassBrand(_Queue_brand, this, _jobToItem).call(this, job, job.payload);
380
+ }
381
+ function _listForOwner(owner, criteria = {}) {
382
+ const ownerKey = owner?.key ?? null;
383
+ const items = [];
384
+ for (const { job, envelope } of _assertClassBrand(_Queue_brand, this, _ownedJobs).call(this)) {
385
+ if ((envelope.owner_path_key ?? null) !== ownerKey) continue;
386
+ if (criteria.callback && job.fn !== criteria.callback) continue;
387
+ items.push(_assertClassBrand(_Queue_brand, this, _jobToItem).call(this, job, envelope));
388
+ }
389
+ return items;
390
+ }
391
+ async function _cancelForOwner(owner, id) {
392
+ if (!_assertClassBrand(_Queue_brand, this, _getForOwner).call(this, owner, id)) return false;
393
+ return this.lifecycle.jobs.cancel(id);
394
+ }
395
+ async function _cancelAllForOwner(owner, callback) {
396
+ let cancelled = 0;
397
+ for (const item of _assertClassBrand(_Queue_brand, this, _listForOwner).call(this, owner, { callback })) if (await this.lifecycle.jobs.cancel(item.id)) cancelled++;
398
+ return cancelled;
399
+ }
400
+ function _emit(type, payload) {
401
+ this.lifecycle.events.emit(type, payload);
402
+ }
403
+ //#endregion
404
+ export { setQueueCallbackResolver as n, Queue as t };
405
+
406
+ //# sourceMappingURL=queue-BB-zfIYF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-BB-zfIYF.js","names":[],"sources":["../src/queue/queue.ts"],"sourcesContent":["/**\n * Lifecycle background-work vocabulary. Queue validates items, resolves\n * named callbacks, and pushes jobs due immediately into the Lifecycle-owned\n * job queue; Lifecycle runs the alarm event loop, retry policy, and physical\n * alarm arming. Queue owns no storage of its own — each item is one job\n * whose `fn` is the callback name and whose payload carries the item's\n * payload and owner.\n */\n\nimport {\n LifecycleCapability,\n type LifecycleRouteAddress,\n type LifecycleRouteContext\n} from \"../lifecycle/capability\";\nimport type {\n LifecycleJob,\n LifecycleJobContext,\n LifecycleJobOutcome\n} from \"../lifecycle/job-queue\";\nimport {\n isDurableObjectCodeUpdateReset,\n isPlatformFailure,\n resolveRetryConfig,\n tryN,\n validateRetryOptions\n} from \"../retries\";\nimport type { RetryOptions } from \"../retries\";\nimport type { QueueEventType, QueueOptions } from \"./options\";\nimport type {\n QueueCallbacks,\n QueueCriteria,\n QueueHandlers,\n QueueItem,\n QueuePayload,\n QueuePushOptions,\n QueueStorageRow\n} from \"./types\";\n\n/** A resolved fallback handler for a callback name outside the registered map. */\ntype ResolvedQueueCallback = (\n payload: unknown,\n item: QueueItem<unknown>\n) => unknown;\n\nconst queueCallbackResolvers = new WeakMap<\n object,\n (name: string) => ResolvedQueueCallback | undefined\n>();\n\n/**\n * @internal Supply a composition-root fallback for callback names outside the\n * registered map. Agent uses this to keep its historical name-based queue\n * API (`this.queue(\"methodName\", payload)`) working: the resolver looks the\n * method up on the Agent, and the resolved handler still runs inside the\n * Lifecycle host boundary.\n */\nexport function setQueueCallbackResolver(\n queue: Queue<never>,\n resolver: (name: string) => ResolvedQueueCallback | undefined\n): void {\n queueCallbackResolvers.set(queue, resolver);\n}\n\nconst QUEUE_SCHEMA_VERSION_KEY = \"cf_agents:queue_schema_version\";\n/** Version 1: queue items live in the Lifecycle job queue. */\nconst CURRENT_QUEUE_SCHEMA_VERSION = 1;\n\nconst DEFAULT_RETRY: Required<RetryOptions> = {\n maxAttempts: 3,\n baseDelayMs: 100,\n maxDelayMs: 3000\n};\n\n/** What a Queue job's payload carries: the item payload and its owner. */\ntype QueueJobPayload = {\n readonly payload: unknown;\n readonly owner_path: string | null;\n readonly owner_path_key: string | null;\n};\n\ntype QueueRouteMessage =\n | {\n readonly type: \"push\";\n readonly callback: string;\n readonly payload: unknown;\n readonly options?: QueuePushOptions;\n }\n | { readonly type: \"get\" | \"cancel\"; readonly id: string }\n | { readonly type: \"list\"; readonly criteria?: QueueCriteria }\n | { readonly type: \"cancelAll\"; readonly callback?: string }\n | {\n readonly type: \"dispatch\";\n readonly item: QueueItem<unknown>;\n };\n\nfunction isQueueJobPayload(value: unknown): value is QueueJobPayload {\n // `payload` is absent after a JSON round trip when the item carried none.\n return typeof value === \"object\" && value !== null && \"owner_path\" in value;\n}\n\n/**\n * Durable background work for a Lifecycle Object.\n *\n * Register callbacks in the constructor and install the instance with\n * `Lifecycle.use()`. Each pushed item becomes a job due immediately in the\n * Lifecycle job queue; Lifecycle owns the physical alarm and the alarm event\n * loop, drives items one at a time in push order, retries a throwing\n * callback per its retry policy, and Queue runs registered callbacks through\n * Lifecycle's host invocation boundary. An item that still fails after its\n * last attempt is dropped after `queue:error` and the `onError` hook.\n *\n * Items survive the Durable Object leaving memory: an isolate that dies mid\n * callback wakes again on the Lifecycle deadman alarm and resumes the queue.\n * Callbacks should therefore be idempotent.\n *\n * @experimental The API surface may change before stabilizing.\n */\nexport class Queue<\n Handlers extends QueueHandlers = QueueCallbacks\n> extends LifecycleCapability {\n readonly #handlers: QueueHandlers;\n readonly #retryDefaults: Required<RetryOptions>;\n readonly #onError: ((error: unknown) => void | Promise<void>) | undefined;\n /**\n * Last due time handed to a job. The Lifecycle driver dispatches due jobs\n * in due-time order, so pushes get strictly increasing times to keep push\n * order (FIFO) even within one millisecond. Seeded from the persisted\n * queue tail on first use so a fresh instance never sorts a new item ahead\n * of items an earlier instance already queued.\n */\n #lastTime: number | null = null;\n\n /**\n * Create a durable Queue.\n *\n * @param options - Registered callbacks plus optional retry and error\n * policy. Registering `callbacks` types {@link push} against the map —\n * names and payloads are checked where the handlers are declared and where\n * they are pushed. Names outside the map are rejected unless a\n * composition-root resolver supplies them — the internal aperture behind\n * `Agent`'s name-based queue API.\n */\n constructor(options: QueueOptions<Handlers> = {}) {\n super(\"queue\");\n this.#handlers = options.callbacks ?? {};\n // Retry defaults are resolved, not validated, here: invalid defaults\n // surface per execution as queue:error instead of bricking the object at\n // construction. Per-item retry overrides are validated when pushed.\n this.#retryDefaults = resolveRetryConfig(options.retry, DEFAULT_RETRY);\n this.#onError = options.onError;\n }\n\n // ── Lifecycle capability hooks ───────────────────────────────────────────\n\n /** Migrate legacy `cf_agents_queues` rows into the Lifecycle job queue. */\n async onStart(): Promise<void> {\n const storage = this.lifecycle.storage;\n const version = (await storage.get<number>(QUEUE_SCHEMA_VERSION_KEY)) ?? 0;\n if (version >= CURRENT_QUEUE_SCHEMA_VERSION) return;\n\n await this.#migrateLegacyQueueTable(storage);\n await storage.put(QUEUE_SCHEMA_VERSION_KEY, CURRENT_QUEUE_SCHEMA_VERSION);\n }\n\n /**\n * Move every `cf_agents_queues` row into the job queue and drop the\n * table. Idempotent: a missing table means a fresh object or a completed\n * migration. Rows keep their insertion order.\n *\n * TEMPORARY: one-shot upgrade path for objects that had queued items when\n * this release landed. Remove in the next minor release (with the schema\n * version bump that gates it), once every deployed object has migrated.\n */\n async #migrateLegacyQueueTable(storage: DurableObjectStorage): Promise<void> {\n const tables = storage.sql\n .exec(\n \"SELECT name FROM sqlite_master WHERE type='table' AND name='cf_agents_queues'\"\n )\n .toArray();\n if (tables.length === 0) return;\n\n const rows = storage.sql\n .exec(\"SELECT * FROM cf_agents_queues ORDER BY created_at ASC, rowid ASC\")\n .toArray() as unknown as QueueStorageRow[];\n for (const row of rows) {\n let payload: unknown;\n try {\n payload =\n typeof row.payload === \"string\" ? JSON.parse(row.payload) : undefined;\n } catch (error) {\n console.error(\n `Skipping queue item \"${row.id}\" during job-queue migration: ` +\n \"its payload is not valid JSON\",\n error\n );\n continue;\n }\n let retry: RetryOptions | undefined;\n try {\n retry =\n typeof row.retry_options === \"string\"\n ? (JSON.parse(row.retry_options) as RetryOptions)\n : undefined;\n } catch {\n retry = undefined;\n }\n await this.lifecycle.jobs.push({\n id: row.id,\n fn: row.callback,\n time: this.#nextTime(),\n payload: {\n payload,\n owner_path: null,\n owner_path_key: null\n } satisfies QueueJobPayload,\n retry: resolveRetryConfig(retry, this.#retryDefaults)\n });\n }\n storage.sql.exec(\"DROP TABLE cf_agents_queues\");\n }\n\n /** Drive one due item dispatched by the Lifecycle event loop. */\n async onJob(\n context: LifecycleJobContext\n ): Promise<LifecycleJobOutcome | void> {\n const { job, attempt } = context;\n if (!isQueueJobPayload(job.payload)) {\n console.error(`Malformed queue item ${job.id}; dropping it`);\n return undefined;\n }\n const item = this.#jobToItem(job, job.payload);\n\n if (attempt > 1) {\n this.#emit(\"queue:retry\", {\n callback: job.fn,\n id: job.id,\n attempt,\n maxAttempts: resolveRetryConfig(job.retry, this.#retryDefaults)\n .maxAttempts\n });\n }\n\n if (job.payload.owner_path) {\n // A routed item executes inside its owning Lifecycle; retries run\n // there too, so this dispatch is a single routed attempt.\n try {\n await this.lifecycle.routes.to(\n {\n key: job.payload.owner_path_key ?? job.payload.owner_path,\n data: job.payload.owner_path\n },\n { type: \"dispatch\", item } satisfies QueueRouteMessage\n );\n } catch (error) {\n if (isPlatformFailure(error)) {\n // Preserve the item; Lifecycle defers platform-class failures to\n // a fresh invocation or the memory-limit breaker.\n throw error;\n }\n console.error(`error dispatching queue callback \"${job.fn}\"`, error);\n this.#emit(\"queue:error\", {\n callback: job.fn,\n id: job.id,\n error: error instanceof Error ? error.message : String(error),\n attempts: 0\n });\n try {\n await this.#onError?.(error);\n } catch {\n // swallow onError errors\n }\n // Leave the item due so a later alarm cycle can retry dispatch, for\n // example once a transport can resolve its owner again.\n return \"yield\";\n }\n return undefined;\n }\n\n const handler = this.#resolveCallback(job.fn);\n if (!handler) {\n console.error(`callback ${job.fn} not found`);\n return undefined;\n }\n await this.lifecycle.runInHostContext(() => handler(item.payload, item));\n return undefined;\n }\n\n /** Observe one item's terminal application failure; the item is dropped. */\n async onJobError(\n context: LifecycleJobContext,\n error: unknown\n ): Promise<LifecycleJobOutcome | void> {\n const { job } = context;\n const { maxAttempts } = resolveRetryConfig(job.retry, this.#retryDefaults);\n console.error(\n `queue callback \"${job.fn}\" failed after ${maxAttempts} attempts`,\n error\n );\n this.#emit(\"queue:error\", {\n callback: job.fn,\n id: job.id,\n error: error instanceof Error ? error.message : String(error),\n attempts: maxAttempts\n });\n try {\n await this.#onError?.(error);\n } catch {\n // swallow onError errors\n }\n return undefined;\n }\n\n /** Handle Queue protocol messages routed by another Lifecycle. */\n async onRoute(context: LifecycleRouteContext): Promise<unknown> {\n const message = context.payload as QueueRouteMessage;\n const owner = context.source ?? null;\n switch (message.type) {\n case \"push\":\n return this.#insert(\n owner,\n message.callback,\n message.payload,\n message.options\n );\n case \"get\":\n return this.#getForOwner(owner, message.id);\n case \"list\":\n return this.#listForOwner(owner, message.criteria);\n case \"cancel\":\n return this.#cancelForOwner(owner, message.id);\n case \"cancelAll\":\n return this.#cancelAllForOwner(owner, message.callback);\n case \"dispatch\":\n await this.#executeRouted(message.item);\n return true;\n default:\n throw new Error(\"Unknown routed Queue message\");\n }\n }\n\n /**\n * Execute a routed item locally with the historical retry handling. Runs\n * on the owning (facet) Queue, outside the root's event loop, so it applies\n * its own in-process retry budget. Platform-class failures re-throw so the\n * root preserves the item and the durable alarm retries on a fresh\n * invocation.\n */\n async #executeRouted(item: QueueItem<unknown>): Promise<void> {\n const handler = this.#resolveCallback(item.callback);\n if (!handler) {\n console.error(`callback ${item.callback} not found`);\n return;\n }\n const { maxAttempts, baseDelayMs, maxDelayMs } = resolveRetryConfig(\n item.retry,\n this.#retryDefaults\n );\n try {\n await tryN(\n maxAttempts,\n async (attempt) => {\n if (attempt > 1) {\n this.#emit(\"queue:retry\", {\n callback: item.callback,\n id: item.id,\n attempt,\n maxAttempts\n });\n }\n await this.lifecycle.runInHostContext(() =>\n handler(item.payload, item)\n );\n },\n {\n baseDelayMs,\n maxDelayMs,\n shouldRetry: (error) => !isDurableObjectCodeUpdateReset(error)\n }\n );\n } catch (error) {\n if (isPlatformFailure(error)) {\n throw error;\n }\n console.error(\n `queue callback \"${item.callback}\" failed after ${maxAttempts} attempts`,\n error\n );\n this.#emit(\"queue:error\", {\n callback: item.callback,\n id: item.id,\n error: error instanceof Error ? error.message : String(error),\n attempts: maxAttempts\n });\n try {\n await this.#onError?.(error);\n } catch {\n // swallow onError errors\n }\n }\n }\n\n // ── Queue API ────────────────────────────────────────────────────────────\n\n /**\n * Push one item for a registered callback. The item is due immediately;\n * the Lifecycle alarm event loop runs it in push order after this call\n * returns.\n *\n * Once the Lifecycle has started (and this Queue is not routed through\n * another Lifecycle), the item row is written synchronously before this\n * method's promise is even returned, so a caller may pair a push with its\n * own writes in one synchronous block — the item then commits atomically\n * with them.\n */\n async push<Name extends keyof Handlers & string>(\n callback: Name,\n payload?: QueuePayload<Handlers[Name]>,\n options?: QueuePushOptions\n ): Promise<QueueItem<QueuePayload<Handlers[Name]>>> {\n if (this.lifecycle.status() !== \"started\") await this.lifecycle.ready();\n this.#validatePush(callback, options);\n const item = this.lifecycle.routes.source\n ? ((await this.lifecycle.routes.toRoot({\n type: \"push\",\n callback,\n payload,\n options\n } satisfies QueueRouteMessage)) as QueueItem<\n QueuePayload<Handlers[Name]>\n >)\n : await this.#insert<QueuePayload<Handlers[Name]>>(\n null,\n callback,\n payload,\n options\n );\n this.#emit(\"queue:create\", { callback, id: item.id });\n return item;\n }\n\n /** Cancel one pending item. Returns false when no item matched. */\n async cancel(id: string): Promise<boolean> {\n await this.lifecycle.ready();\n if (this.lifecycle.routes.source) {\n return (await this.lifecycle.routes.toRoot({\n type: \"cancel\",\n id\n } satisfies QueueRouteMessage)) as boolean;\n }\n return this.#cancelForOwner(null, id);\n }\n\n /** Cancel every pending item, or every item for one callback. Returns the count. */\n async cancelAll(callback?: string): Promise<number> {\n await this.lifecycle.ready();\n if (this.lifecycle.routes.source) {\n return (await this.lifecycle.routes.toRoot({\n type: \"cancelAll\",\n callback\n } satisfies QueueRouteMessage)) as number;\n }\n return this.#cancelAllForOwner(null, callback);\n }\n\n /** Read one pending item. */\n async get<T = unknown>(id: string): Promise<QueueItem<T> | undefined> {\n await this.lifecycle.ready();\n if (this.lifecycle.routes.source) {\n return (await this.lifecycle.routes.toRoot({\n type: \"get\",\n id\n } satisfies QueueRouteMessage)) as QueueItem<T> | undefined;\n }\n return this.#getForOwner<T>(null, id);\n }\n\n /** List pending items in push order, optionally filtered by callback. */\n async list<T = unknown>(criteria?: QueueCriteria): Promise<QueueItem<T>[]> {\n await this.lifecycle.ready();\n if (this.lifecycle.routes.source) {\n return (await this.lifecycle.routes.toRoot({\n type: \"list\",\n criteria\n } satisfies QueueRouteMessage)) as QueueItem<T>[];\n }\n return this.#listForOwner<T>(null, criteria);\n }\n\n // ── Internals ────────────────────────────────────────────────────────────\n\n #validatePush(callback: string, options?: QueuePushOptions): void {\n if (typeof callback !== \"string\") {\n throw new Error(\"Callback must be a string\");\n }\n if (!this.#hasCallback(callback)) {\n throw new Error(\n `Unknown queue callback \"${callback}\": not registered on this Queue`\n );\n }\n if (options?.retry)\n validateRetryOptions(options.retry, this.#retryDefaults);\n if (options?.id !== undefined && options.id.trim() === \"\") {\n throw new Error(\"Queue item ids must be non-empty\");\n }\n }\n\n /** Resolve a name to its registered or composition-root-supplied handler. */\n #resolveCallback(name: string): ResolvedQueueCallback | undefined {\n const handler = this.#handlers[name];\n if (handler) {\n // SAFETY: registered handlers are constrained with `never` parameters\n // so concrete handler types satisfy the map under contravariance; the\n // payload passed at dispatch was persisted with this handler's name.\n return handler as ResolvedQueueCallback;\n }\n return queueCallbackResolvers.get(this)?.(name);\n }\n\n #hasCallback(name: string): boolean {\n return this.#resolveCallback(name) !== undefined;\n }\n\n /** The next strictly increasing due time, never before now. */\n #nextTime(): number {\n if (this.#lastTime === null) {\n this.#lastTime = this.#ownedJobs().reduce(\n (lastTime, { job }) => Math.max(lastTime, job.time),\n 0\n );\n }\n const time = Math.max(Date.now(), this.#lastTime + 1);\n this.#lastTime = time;\n return time;\n }\n\n async #insert<T>(\n owner: LifecycleRouteAddress | null,\n callback: string,\n payload: unknown,\n options?: QueuePushOptions\n ): Promise<QueueItem<T>> {\n // A stable-id push replaces the item in place: it keeps the existing\n // item's due time, and so its position in the queue.\n const existing =\n options?.id !== undefined\n ? this.lifecycle.jobs.get(options.id)\n : undefined;\n const keepTime =\n existing !== undefined &&\n this.#getForOwner(owner, existing.id) !== undefined;\n const job = await this.lifecycle.jobs.push({\n id: options?.id,\n fn: callback,\n time: keepTime ? existing.time : this.#nextTime(),\n payload: {\n payload,\n owner_path: owner?.data ?? null,\n owner_path_key: owner?.key ?? null\n } satisfies QueueJobPayload,\n retry: resolveRetryConfig(options?.retry, this.#retryDefaults)\n });\n return this.#jobToItem<T>(job, job.payload as QueueJobPayload);\n }\n\n #jobToItem<T>(job: LifecycleJob, envelope: QueueJobPayload): QueueItem<T> {\n return {\n id: job.id,\n callback: job.fn,\n payload: envelope.payload as T,\n createdAt: job.createdAt,\n retry: job.retry\n };\n }\n\n /** Every queue job this Queue owns, in push order. */\n #ownedJobs(): Array<{ job: LifecycleJob; envelope: QueueJobPayload }> {\n const owned: Array<{ job: LifecycleJob; envelope: QueueJobPayload }> = [];\n for (const job of this.lifecycle.jobs.list()) {\n if (isQueueJobPayload(job.payload)) {\n owned.push({ job, envelope: job.payload });\n }\n }\n return owned;\n }\n\n #getForOwner<T>(\n owner: LifecycleRouteAddress | null,\n id: string\n ): QueueItem<T> | undefined {\n const ownerKey = owner?.key ?? null;\n const job = this.lifecycle.jobs.get(id);\n if (!job || !isQueueJobPayload(job.payload)) return undefined;\n if ((job.payload.owner_path_key ?? null) !== ownerKey) return undefined;\n return this.#jobToItem<T>(job, job.payload);\n }\n\n #listForOwner<T>(\n owner: LifecycleRouteAddress | null,\n criteria: QueueCriteria = {}\n ): QueueItem<T>[] {\n const ownerKey = owner?.key ?? null;\n const items: QueueItem<T>[] = [];\n for (const { job, envelope } of this.#ownedJobs()) {\n if ((envelope.owner_path_key ?? null) !== ownerKey) continue;\n if (criteria.callback && job.fn !== criteria.callback) continue;\n items.push(this.#jobToItem<T>(job, envelope));\n }\n return items;\n }\n\n async #cancelForOwner(\n owner: LifecycleRouteAddress | null,\n id: string\n ): Promise<boolean> {\n if (!this.#getForOwner(owner, id)) return false;\n return this.lifecycle.jobs.cancel(id);\n }\n\n async #cancelAllForOwner(\n owner: LifecycleRouteAddress | null,\n callback?: string\n ): Promise<number> {\n let cancelled = 0;\n for (const item of this.#listForOwner(owner, { callback })) {\n if (await this.lifecycle.jobs.cancel(item.id)) cancelled++;\n }\n return cancelled;\n }\n\n /** @internal Remove items owned by one routed Lifecycle subtree. */\n async __DO_NOT_USE_WILL_BREAK__cleanupRoutePrefix(\n prefix: string\n ): Promise<void> {\n for (const { job, envelope } of this.#ownedJobs()) {\n const ownerKey = envelope.owner_path_key ?? envelope.owner_path;\n if (!envelope.owner_path || ownerKey === null) continue;\n if (ownerKey !== prefix && !ownerKey.startsWith(`${prefix}/`)) continue;\n await this.lifecycle.jobs.cancel(job.id);\n }\n }\n\n // ── Events ───────────────────────────────────────────────────────────────\n\n #emit(type: QueueEventType, payload: Record<string, unknown>): void {\n this.lifecycle.events.emit(type, payload);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,yCAAyB,IAAI,QAGjC;;;;;;;;AASF,SAAgB,yBACd,OACA,UACM;CACN,uBAAuB,IAAI,OAAO,QAAQ;AAC5C;AAEA,MAAM,2BAA2B;;AAEjC,MAAM,+BAA+B;AAErC,MAAM,gBAAwC;CAC5C,aAAa;CACb,aAAa;CACb,YAAY;AACd;AAwBA,SAAS,kBAAkB,OAA0C;CAEnE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,gBAAgB;AACxE;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,QAAb,cAEU,oBAAoB;;;;;;;;;;;CAuB5B,YAAY,UAAkC,CAAC,GAAG;EAChD,MAAM,OAAO;;;;;8CAbY,IAAA;EAczB,uBAAA,WAAA,MAAiB,QAAQ,aAAa,CAAC,CAAA;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;CAC9D,OAAA,kBAAA,cAAO,MAAA,UAAA,CAAA,CAAA,KAAA,MAAmB,KAAK,IAAI,OAAO;AAC5C;AAEA,SAAA,cACE,OACA,WAA0B,CAAC,GACX;CAChB,MAAM,WAAW,OAAO,OAAO;CAC/B,MAAM,QAAwB,CAAC;CAC/B,KAAK,MAAM,EAAE,KAAK,cAAA,kBAAA,cAAc,MAAA,UAAA,CAAA,CAAA,KAAA,IAAgB,GAAG;EACjD,KAAK,SAAS,kBAAkB,UAAU,UAAU;EACpD,IAAI,SAAS,YAAY,IAAI,OAAO,SAAS,UAAU;EACvD,MAAM,KAAA,kBAAA,cAAK,MAAA,UAAA,CAAA,CAAA,KAAA,MAAmB,KAAK,QAAQ,CAAC;CAC9C;CACA,OAAO;AACT;AAEA,eAAA,gBACE,OACA,IACkB;CAClB,IAAI,CAAA,kBAAA,cAAC,MAAA,YAAA,CAAA,CAAA,KAAA,MAAkB,OAAO,EAAE,GAAG,OAAO;CAC1C,OAAO,KAAK,UAAU,KAAK,OAAO,EAAE;AACtC;AAEA,eAAA,mBACE,OACA,UACiB;CACjB,IAAI,YAAY;CAChB,KAAK,MAAM,QAAA,kBAAA,cAAQ,MAAA,aAAA,CAAA,CAAA,KAAA,MAAmB,OAAO,EAAE,SAAS,CAAC,GACvD,IAAI,MAAM,KAAK,UAAU,KAAK,OAAO,KAAK,EAAE,GAAG;CAEjD,OAAO;AACT;AAgBA,SAAA,MAAM,MAAsB,SAAwC;CAClE,KAAK,UAAU,OAAO,KAAK,MAAM,OAAO;AAC1C"}
package/dist/react.d.ts CHANGED
@@ -2,19 +2,20 @@ import {
2
2
  C as MCPServersState,
3
3
  J as AgentToolRunPart,
4
4
  Y as AgentToolRunState
5
- } from "./agent-routing-DE5zmCQ8.js";
5
+ } from "./agent-routing-0DR0Tk2v.js";
6
6
  import { ClientParameters } from "./serializable.js";
7
+ import { t as AgentTransport } from "./transport-protocol-ZTew5Wso.js";
7
8
  import {
8
- AgentConnectionError,
9
- AgentPromiseReturnType,
10
- AgentStub,
11
- CallOptions,
12
- OptionalAgentMethods,
13
- RequiredAgentMethods,
14
- StreamOptions,
15
- UntypedAgentStub,
16
- createStubProxy
17
- } from "./client.js";
9
+ c as CallOptions,
10
+ d as OptionalAgentMethods,
11
+ h as UntypedAgentStub,
12
+ i as AgentConnectionError,
13
+ m as StreamOptions,
14
+ o as AgentPromiseReturnType,
15
+ p as RequiredAgentMethods,
16
+ s as AgentStub,
17
+ v as createStubProxy
18
+ } from "./client-je3koD9Z.js";
18
19
  import { PartySocket } from "partysocket";
19
20
  import { usePartySocket } from "partysocket/react";
20
21
 
@@ -73,7 +74,18 @@ type UseAgentOptions<State = unknown> = Omit<
73
74
  * // Client connects to /user, server routes based on session
74
75
  * useAgent({ agent: "UserAgent", basePath: "user" })
75
76
  */
76
- basePath?: string /** Query parameters - can be static object or async function */;
77
+ basePath?: string;
78
+ /**
79
+ * Wire the connection travels on. `"cf-websocket"` (default) is a
80
+ * hibernating WebSocket where `call()` sends JSON `rpc` frames.
81
+ * `"capnweb"` carries protocol frames over a Cap'n Web session whose
82
+ * root also serves the host's `callables` natively, so `call()` and
83
+ * `stub` invoke them directly and an `RpcTarget` result is a live stub.
84
+ * The Durable Object stays in memory while a capnweb connection is open.
85
+ * Identity, state, and reconnection behave the same on both.
86
+ * @experimental The `"capnweb"` transport is experimental.
87
+ */
88
+ transport?: AgentTransport /** Query parameters - can be static object or async function */;
77
89
  query?:
78
90
  | QueryObject
79
91
  | (() => Promise<QueryObject>) /** Dependencies for async query caching */;
@@ -246,5 +258,11 @@ declare function useAgentToolEvents<
246
258
  resetLocalState(): void;
247
259
  };
248
260
  //#endregion
249
- export { UseAgentOptions, _testUtils, useAgent, useAgentToolEvents };
261
+ export {
262
+ type AgentTransport,
263
+ UseAgentOptions,
264
+ _testUtils,
265
+ useAgent,
266
+ useAgentToolEvents
267
+ };
250
268
  //# sourceMappingURL=react.d.ts.map