agents 0.23.0 → 0.24.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 (98) hide show
  1. package/dist/{agent-routing-DE5zmCQ8.d.ts → agent-routing-B2XLNMxq.d.ts} +196 -189
  2. package/dist/agent-routing.d.ts +1 -1
  3. package/dist/agent-tool-types.d.ts +26 -26
  4. package/dist/{agent-tools-DtXMTDGM.d.ts → agent-tools-Dj5Mzlw7.d.ts} +7 -7
  5. package/dist/agent-tools.d.ts +21 -21
  6. package/dist/{capability-BjSKYpzg.js → capability-B4WbF81e.js} +2 -1
  7. package/dist/capability-B4WbF81e.js.map +1 -0
  8. package/dist/{capability-runner-Be_-PLR1.d.ts → capability-runner-BUBa6Ake.d.ts} +40 -15
  9. package/dist/chat/index.d.ts +14 -11
  10. package/dist/chat/index.js +11 -7
  11. package/dist/chat/index.js.map +1 -1
  12. package/dist/chat-sdk/index.d.ts +3 -3
  13. package/dist/chat-sdk/index.js +1 -1
  14. package/dist/client-BxdkCuVy.d.ts +411 -0
  15. package/dist/client-C9DAjZIY.js +518 -0
  16. package/dist/client-C9DAjZIY.js.map +1 -0
  17. package/dist/{client-jagG8a9_.js → client-fyQrLGkD.js} +2 -2
  18. package/dist/{client-jagG8a9_.js.map → client-fyQrLGkD.js.map} +1 -1
  19. package/dist/client.d.ts +27 -283
  20. package/dist/client.js +2 -274
  21. package/dist/current-agent-C4w86kcN.d.ts +93 -0
  22. package/dist/{current-agent-Da_C9a3b.d.ts → durable-object-lifecycle-ei7M7lqB.d.ts} +13 -122
  23. package/dist/index-Dlgtd3Mj.d.ts +78 -0
  24. package/dist/index.d.ts +59 -59
  25. package/dist/index.js +2 -2
  26. package/dist/internal_context.d.ts +1 -1
  27. package/dist/lifecycle/index.d.ts +19 -17
  28. package/dist/lifecycle/index.js +2 -2
  29. package/dist/{lifecycle-CMRGjZdw.js → lifecycle-Mm_jQh7r.js} +36 -21
  30. package/dist/lifecycle-Mm_jQh7r.js.map +1 -0
  31. package/dist/mcp/client/index.d.ts +20 -20
  32. package/dist/mcp/client/index.js +1 -1
  33. package/dist/mcp/index.d.ts +35 -35
  34. package/dist/mcp/index.js +2 -2
  35. package/dist/queue/index.d.ts +123 -0
  36. package/dist/queue/index.js +2 -0
  37. package/dist/queue-BC9F5cUo.js +406 -0
  38. package/dist/queue-BC9F5cUo.js.map +1 -0
  39. package/dist/react.d.ts +33 -15
  40. package/dist/react.js +31 -8
  41. package/dist/react.js.map +1 -1
  42. package/dist/{retries-D9Ds-1lz.d.ts → retries-D9B2UCq3.d.ts} +9 -3
  43. package/dist/retries.d.ts +5 -3
  44. package/dist/retries.js +9 -1
  45. package/dist/retries.js.map +1 -1
  46. package/dist/routing/index.d.ts +2 -2
  47. package/dist/routing/index.js +1 -1
  48. package/dist/{scheduler-Dwh85ZGl.d.ts → scheduler-BGq6M5Kd.d.ts} +6 -6
  49. package/dist/{scheduler-DD9NdYbF.js → scheduler-D_KHqxBa.js} +4 -11
  50. package/dist/scheduler-D_KHqxBa.js.map +1 -0
  51. package/dist/schedules/index.d.ts +1 -1
  52. package/dist/schedules/index.js +1 -1
  53. package/dist/serializable.d.ts +1 -1
  54. package/dist/sessions/index.d.ts +1 -1
  55. package/dist/sessions/index.js +1 -1
  56. package/dist/{src-DlSHshb2.js → src-BNU3ZiJM.js} +126 -393
  57. package/dist/src-BNU3ZiJM.js.map +1 -0
  58. package/dist/state/index.d.ts +6 -0
  59. package/dist/state/index.js +137 -0
  60. package/dist/state/index.js.map +1 -0
  61. package/dist/streams/index.d.ts +1 -1
  62. package/dist/streams/index.js +1 -1
  63. package/dist/{streams-D6tJ0NN9.d.ts → streams-BcE8JP2X.d.ts} +2 -2
  64. package/dist/{streams-DZKgAj9b.js → streams-CCPRV6dt.js} +2 -2
  65. package/dist/{streams-DZKgAj9b.js.map → streams-CCPRV6dt.js.map} +1 -1
  66. package/dist/sub-routing.d.ts +12 -12
  67. package/dist/tasks/index.d.ts +1 -1
  68. package/dist/tasks/index.js +1 -1
  69. package/dist/{tasks-ylZgBjhj.js → tasks-D4nLqVSI.js} +3 -3
  70. package/dist/{tasks-ylZgBjhj.js.map → tasks-D4nLqVSI.js.map} +1 -1
  71. package/dist/{tasks-BRJ5zgya.d.ts → tasks-V2lCT8ZV.d.ts} +5 -5
  72. package/dist/transport-protocol-BxyngQ_R.js +25 -0
  73. package/dist/transport-protocol-BxyngQ_R.js.map +1 -0
  74. package/dist/transport-protocol-ZTew5Wso.d.ts +27 -0
  75. package/dist/types-DCD6BNZH.d.ts +70 -0
  76. package/dist/voice/index.d.ts +2 -2
  77. package/dist/websockets/index.d.ts +178 -69
  78. package/dist/websockets/index.js +3 -2
  79. package/dist/websockets-D7IzWbZb.js +1005 -0
  80. package/dist/websockets-D7IzWbZb.js.map +1 -0
  81. package/dist/workflow-types.d.ts +25 -25
  82. package/dist/workflows.d.ts +21 -21
  83. package/dist/workflows.js +1 -1
  84. package/docs/agent-class.md +2 -2
  85. package/docs/client-sdk.md +30 -0
  86. package/docs/index.md +1 -1
  87. package/docs/lifecycle.md +97 -22
  88. package/docs/queue.md +135 -241
  89. package/docs/retries.md +1 -1
  90. package/docs/sub-agents.md +3 -3
  91. package/package.json +12 -2
  92. package/dist/capability-BjSKYpzg.js.map +0 -1
  93. package/dist/client.js.map +0 -1
  94. package/dist/lifecycle-CMRGjZdw.js.map +0 -1
  95. package/dist/scheduler-DD9NdYbF.js.map +0 -1
  96. package/dist/src-DlSHshb2.js.map +0 -1
  97. package/dist/websockets-DUfRHPRq.js +0 -502
  98. package/dist/websockets-DUfRHPRq.js.map +0 -1
@@ -1,14 +1,9 @@
1
1
  import {
2
- _ as LifecycleJobOutcome,
3
- b as Connection,
4
- g as LifecycleJobContext,
2
+ T as WSMessage,
3
+ b as LifecycleJobs,
5
4
  i as DurableObjectCapability,
6
- o as MemoryLimitContext,
7
- u as LifecycleRouteAddress,
8
- w as WSMessage,
9
- y as LifecycleJobs
10
- } from "./capability-runner-Be_-PLR1.js";
11
- import { AsyncLocalStorage } from "node:async_hooks";
5
+ u as LifecycleRouteAddress
6
+ } from "./capability-runner-BUBa6Ake.js";
12
7
  import { DurableObject } from "cloudflare:workers";
13
8
 
14
9
  //#region src/lifecycle/durable-object-lifecycle.d.ts
@@ -27,25 +22,6 @@ type LifecycleOptions = {
27
22
  */
28
23
  readonly maxAlarmMemoryLimitStrikes?: number;
29
24
  };
30
- /** Placement of a capability in the dispatch order. */
31
- type LifecycleUseOptions = {
32
- /**
33
- * Dispatch after every non-fallback capability, whenever it was
34
- * installed. For a host's catch-all, such as a WebSockets capability
35
- * that claims every upgrade, so middleware installed later still runs
36
- * first.
37
- */
38
- readonly fallback?: boolean;
39
- };
40
- /**
41
- * Installs and coordinates the runtime lifecycle for a Durable Object.
42
- *
43
- * Construct this as an instance field on a class that directly extends
44
- * `DurableObject`, then call {@link Lifecycle.installHandlers}
45
- * from that class's constructor.
46
- *
47
- * @experimental The API surface may change before stabilizing.
48
- */
49
25
  declare class Lifecycle<
50
26
  Env extends object = Cloudflare.Env,
51
27
  Props extends Record<string, unknown> = Record<string, unknown>
@@ -82,17 +58,17 @@ declare class Lifecycle<
82
58
  /**
83
59
  * Add a reusable capability before this lifecycle starts.
84
60
  *
85
- * Capabilities dispatch in registration order, except that fallbacks
86
- * always come after non-fallbacks.
61
+ * Capabilities dispatch in registration order, except that a capability
62
+ * declaring `claims: "catch-all"` always comes last, whenever it was
63
+ * installed. Catch-alls are unique per dispatch hook: two may coexist
64
+ * when they claim disjoint traffic (one `onRequest`, one
65
+ * `onWebSocketUpgrade`), but a second catch-all for the same hook could
66
+ * never be reached and is refused.
87
67
  *
88
68
  * @param capability - The capability to add.
89
- * @param options - Dispatch placement.
90
69
  * @returns This lifecycle.
91
70
  */
92
- use(
93
- capability: DurableObjectCapability<Props>,
94
- options?: LifecycleUseOptions
95
- ): this;
71
+ use(capability: DurableObjectCapability<Props>): this;
96
72
  /** @internal Deliver a generic capability envelope to this Lifecycle. */
97
73
  route(envelope: LifecycleRouteEnvelope): Promise<unknown>;
98
74
  /**
@@ -177,90 +153,5 @@ declare class Lifecycle<
177
153
  alarm(): Promise<void>;
178
154
  }
179
155
  //#endregion
180
- //#region src/lifecycle/current-agent.d.ts
181
- /**
182
- * A Durable Object that has installed the Agents SDK Lifecycle.
183
- *
184
- * Pass a more specific Lifecycle Object type to {@link getCurrentAgent} when
185
- * shared host code needs APIs implemented by a particular object.
186
- *
187
- * @experimental The API surface may change before stabilizing.
188
- */
189
- interface LifecycleObject<
190
- Env extends object = Cloudflare.Env,
191
- Props extends Record<string, unknown> = Record<string, unknown>
192
- > extends DurableObject<Env> {
193
- readonly lifecycle: Lifecycle<Env, Props>;
194
- onStart?(props?: Props): void | Promise<void>;
195
- onRequest?(request: Request): Response | Promise<Response>;
196
- onAlarm?(): void | Promise<void>;
197
- onJob?(
198
- context: LifecycleJobContext
199
- ): LifecycleJobOutcome | void | Promise<LifecycleJobOutcome | void>;
200
- /**
201
- * Host domain policy applied when the alarm memory-limit circuit breaker
202
- * records a strike (#1825), after every capability's `onMemoryLimit` hook.
203
- *
204
- * Lifecycle dispatches host hooks structurally through its internal host
205
- * cast, so TS visibility is the host's to choose: a framework host whose
206
- * implementation is internal machinery declares the hook `protected` (the
207
- * pattern — see `AIChatAgent`/`Think`) and keeps the real work in a
208
- * `private _cf_`-prefixed method, without falling out of this contract at
209
- * runtime.
210
- */
211
- onAlarmMemoryLimit?(context: MemoryLimitContext): void | Promise<void>;
212
- }
213
- /** Values associated with the currently executing Lifecycle host. */
214
- type AgentContextStore = {
215
- /** Lifecycle host selected for this invocation. */ agent: unknown /** WebSocket connection selected for this invocation, when applicable. */;
216
- connection:
217
- | Connection
218
- | undefined /** HTTP request selected for this invocation, when applicable. */;
219
- request:
220
- | Request
221
- | undefined /** Extension-owned value selected for this invocation, when applicable. */;
222
- email: unknown;
223
- };
224
- /** Values returned by {@link getCurrentAgent}. */
225
- type CurrentAgentContext<
226
- Host extends DurableObject = LifecycleObject,
227
- Email = unknown
228
- > = {
229
- agent: Host | undefined;
230
- connection: Connection | undefined;
231
- request: Request | undefined;
232
- email: Email | undefined;
233
- };
234
- /**
235
- * Shared invocation context for Lifecycle, Agent, AIChatAgent, and Think.
236
- *
237
- * @internal Importing or relying on this symbol will break your code in a
238
- * future release. Use {@link getCurrentAgent} to read the public context.
239
- */
240
- declare const __DO_NOT_USE_WILL_BREAK__agentContext: AsyncLocalStorage<AgentContextStore>;
241
- /**
242
- * Return the current Agent or Lifecycle Object and invocation-specific values.
243
- *
244
- * Lifecycle host startup and alarm hooks receive the current object with no
245
- * request. Request hooks additionally receive the request being handled.
246
- * Lifecycle-managed WebSocket hooks receive their connection and, during
247
- * connect, its upgrade request. Agent extensions may also establish context
248
- * for email, chat turns, callable methods, and detached work. Capability hooks
249
- * do not run in this ambient context.
250
- */
251
- declare function getCurrentAgent<
252
- Host extends DurableObject = LifecycleObject
253
- >(): CurrentAgentContext<Host>;
254
- //#endregion
255
- export {
256
- getCurrentAgent as a,
257
- LifecycleRouteEnvelope as c,
258
- __DO_NOT_USE_WILL_BREAK__agentContext as i,
259
- LifecycleUseOptions as l,
260
- CurrentAgentContext as n,
261
- Lifecycle as o,
262
- LifecycleObject as r,
263
- LifecycleOptions as s,
264
- AgentContextStore as t
265
- };
266
- //# sourceMappingURL=current-agent-Da_C9a3b.d.ts.map
156
+ export { LifecycleOptions as n, LifecycleRouteEnvelope as r, Lifecycle as t };
157
+ //# sourceMappingURL=durable-object-lifecycle-ei7M7lqB.d.ts.map
@@ -0,0 +1,78 @@
1
+ import {
2
+ s as LifecycleCapability,
3
+ x as Connection
4
+ } from "./capability-runner-BUBa6Ake.js";
5
+ //#region src/state/index.d.ts
6
+ /**
7
+ * Source of a state change: `"server"` for host code (e.g. `setState()`), or
8
+ * the {@link Connection} the change arrived from. Hosts use it to exclude the
9
+ * originating connection from a broadcast.
10
+ */
11
+ type StateChangeSource = Connection | "server";
12
+ /**
13
+ * Options for a {@link State} capability. Validation and the post-change hook
14
+ * stay on the host, which passes them in; the capability owns storage and
15
+ * change ordering.
16
+ *
17
+ * @experimental The API surface may change before stabilizing.
18
+ */
19
+ interface StateOptions<T = unknown> {
20
+ /** Seeded on first access when nothing is stored. `undefined` seeds nothing. */
21
+ readonly initialState?: T;
22
+ /** Called after a change is validated and persisted. May be async. */
23
+ readonly onChanged?: (
24
+ state: T,
25
+ source: StateChangeSource
26
+ ) => void | Promise<void>;
27
+ /**
28
+ * Synchronous gating hook run before a change is persisted. Throw to reject
29
+ * the change; the throw propagates to the caller of {@link State.set}.
30
+ */
31
+ readonly validateStateChange?: (
32
+ nextState: T,
33
+ source: StateChangeSource
34
+ ) => void;
35
+ }
36
+ /**
37
+ * Durable state storage for a Lifecycle Object.
38
+ *
39
+ * Owns the `cf_agents_state` state row, lazy load with an in-memory cache, and
40
+ * validated persistence. Install the instance with `Lifecycle.use()`. State
41
+ * validation and the post-change notification hook stay on the host, which
42
+ * injects both callbacks. This capability never touches connections.
43
+ *
44
+ * @experimental The API surface may change before stabilizing.
45
+ */
46
+ declare class State<T = unknown> extends LifecycleCapability {
47
+ #private;
48
+ /**
49
+ * Create a durable state capability.
50
+ *
51
+ * @param options - Optional initial state and a synchronous validation hook
52
+ * injected by the host.
53
+ */
54
+ constructor(options?: StateOptions<T>);
55
+ /** Initialize state storage during Lifecycle startup. */
56
+ onStart(): Promise<void>;
57
+ /**
58
+ * Current state.
59
+ *
60
+ * Loads lazily from storage on first access and caches in memory. Row
61
+ * existence in `cf_agents_state` is the signal that state was previously
62
+ * set, so falsy values persist correctly. On a corrupt row, falls back to
63
+ * the initial state (re-persisting it) or clears the row.
64
+ */
65
+ get(): T | undefined;
66
+ /**
67
+ * Validate and persist a state change, then call the change hook.
68
+ *
69
+ * @param nextState - The new state to persist.
70
+ * @param source - `"server"` for host-originated changes, or the originating
71
+ * connection for client-originated changes.
72
+ * @throws Whatever the injected `validateStateChange` throws.
73
+ */
74
+ set(nextState: T, source?: StateChangeSource): void;
75
+ }
76
+ //#endregion
77
+ export { StateChangeSource as n, StateOptions as r, State as t };
78
+ //# sourceMappingURL=index-Dlgtd3Mj.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,92 +1,91 @@
1
1
  /// <reference path="../skills-module.d.ts" />
2
2
  import {
3
- b as Connection,
4
- w as WSMessage,
5
- x as ConnectionContext
6
- } from "./capability-runner-Be_-PLR1.js";
3
+ S as ConnectionContext,
4
+ T as WSMessage,
5
+ x as Connection
6
+ } from "./capability-runner-BUBa6Ake.js";
7
7
  import {
8
8
  i as isDurableObjectStorageReset,
9
9
  n as isDurableObjectCodeUpdateReset,
10
10
  r as isDurableObjectMemoryLimitReset,
11
11
  s as isPlatformTransientError,
12
12
  t as RetryOptions
13
- } from "./retries-D9Ds-1lz.js";
14
- import { i as __DO_NOT_USE_WILL_BREAK__agentContext } from "./current-agent-Da_C9a3b.js";
13
+ } from "./retries-D9B2UCq3.js";
14
+ import { i as __DO_NOT_USE_WILL_BREAK__agentContext } from "./current-agent-C4w86kcN.js";
15
15
  import {
16
- $ as ChatCapableAgentClass,
17
- A as StreamingResponse,
18
- An as routeSubAgentRequest,
19
- At as MCPAITool,
20
- B as AgentToolFailure,
16
+ $ as DetachedAgentToolConfig,
17
+ A as getCurrentAgent,
18
+ An as withInvocationScope,
19
+ At as MCPAIToolSet,
20
+ B as AgentToolInterruptedReason,
21
21
  C as MCPServersState,
22
- Cn as SubAgentPathMatch,
23
- D as StartFiberOptions,
24
- E as RPCResponse,
25
- F as AgentToolChildAdapter,
26
- G as AgentToolProgressSnapshot,
27
- H as AgentToolLifecycleResult,
28
- I as AgentToolDisplayMetadata,
29
- J as AgentToolRunPart,
30
- K as AgentToolRunInfo,
31
- Kt as normalizeServerId,
32
- L as AgentToolEvent,
33
- M as routeAgentEmail,
34
- N as AGENT_TOOL_MILESTONE_PART,
35
- O as StartFiberResult,
36
- On as getSubAgentByName,
37
- P as AGENT_TOOL_PROGRESS_PART,
38
- Q as AgentToolTerminalStatus,
39
- R as AgentToolEventMessage,
22
+ Cn as buildAgentPath,
23
+ D as StartFiberResult,
24
+ Dn as getSubAgentByName,
25
+ E as StartFiberOptions,
26
+ F as AgentToolDisplayMetadata,
27
+ G as AgentToolRunInfo,
28
+ Gt as normalizeServerId,
29
+ H as AgentToolMilestone,
30
+ Ht as MCP_SERVER_ID_MAX_LENGTH,
31
+ I as AgentToolEvent,
32
+ J as AgentToolRunState,
33
+ K as AgentToolRunInspection,
34
+ L as AgentToolEventMessage,
35
+ M as AGENT_TOOL_MILESTONE_PART,
36
+ N as AGENT_TOOL_PROGRESS_PART,
37
+ O as StateUpdateMessage,
38
+ On as parseSubAgentPath,
39
+ P as AgentToolChildAdapter,
40
+ Q as ChatCapableAgentClass,
41
+ R as AgentToolEventState,
40
42
  S as MCPServerMessage,
41
- Sn as SUB_PREFIX,
42
- T as RPCRequest,
43
- Tn as buildAgentUrl,
44
- U as AgentToolMilestone,
45
- Ut as MCP_SERVER_ID_MAX_LENGTH,
46
- V as AgentToolInterruptedReason,
47
- W as AgentToolProgress,
48
- X as AgentToolRunStatus,
49
- Y as AgentToolRunState,
50
- Z as AgentToolStoredChunk,
43
+ Sn as SubAgentPathMatch,
44
+ T as RPCResponse,
45
+ U as AgentToolProgress,
46
+ V as AgentToolLifecycleResult,
47
+ W as AgentToolProgressSnapshot,
48
+ X as AgentToolStoredChunk,
49
+ Y as AgentToolRunStatus,
50
+ Z as AgentToolTerminalStatus,
51
51
  _ as FiberRecoveryContext,
52
+ _n as DynamicAgentClass,
52
53
  a as routeAgentRequest,
53
54
  b as ListFibersOptions,
54
- bn as AgentPathStep,
55
+ bn as BuildAgentPathOptions,
55
56
  c as Agent,
56
57
  d as AgentStaticOptions,
57
- et as DetachedAgentToolConfig,
58
+ et as DetachedRunAgentToolResult,
58
59
  f as DEFAULT_AGENT_STATIC_OPTIONS,
59
60
  g as FiberInspection,
60
61
  h as FiberContext,
61
62
  i as getAgentByName,
62
- j as getCurrentAgent,
63
- jn as withInvocationScope,
64
- jt as MCPAIToolSet,
65
- k as StateUpdateMessage,
66
- kn as parseSubAgentPath,
63
+ j as routeAgentEmail,
64
+ k as StreamingResponse,
65
+ kn as routeSubAgentRequest,
66
+ kt as MCPAITool,
67
67
  l as AgentContext,
68
68
  m as EmailRoutingOptions,
69
69
  n as AgentOptions,
70
- nt as RunAgentToolOptions,
70
+ nt as RunAgentToolResult,
71
71
  o as AddMcpServerOptions,
72
72
  p as DeleteFibersOptions,
73
- q as AgentToolRunInspection,
73
+ q as AgentToolRunPart,
74
74
  r as RoutingRetryOptions,
75
- rt as RunAgentToolResult,
76
75
  s as AddRpcMcpServerOptions,
77
76
  t as AgentGetOptions,
78
- tt as DetachedRunAgentToolResult,
77
+ tt as RunAgentToolOptions,
79
78
  u as AgentNamespace,
80
79
  v as FiberRecoveryResult,
81
- vn as DynamicAgentClass,
82
- w as QueueItem,
83
- wn as buildAgentPath,
80
+ vn as DynamicAgentStub,
81
+ w as RPCRequest,
82
+ wn as buildAgentUrl,
84
83
  x as MCPServer,
85
- xn as BuildAgentPathOptions,
84
+ xn as SUB_PREFIX,
86
85
  y as FiberStatus,
87
- yn as DynamicAgentStub,
88
- z as AgentToolEventState
89
- } from "./agent-routing-DE5zmCQ8.js";
86
+ yn as AgentPathStep,
87
+ z as AgentToolFailure
88
+ } from "./agent-routing-B2XLNMxq.js";
90
89
  import {
91
90
  a as EmailSendBinding,
92
91
  d as createHeaderBasedEmailResolver,
@@ -104,7 +103,8 @@ import {
104
103
  a as ScheduleCriteria,
105
104
  i as Schedule,
106
105
  o as ScheduleOptions
107
- } from "./scheduler-Dwh85ZGl.js";
106
+ } from "./scheduler-BGq6M5Kd.js";
107
+ import { i as QueueItem } from "./types-DCD6BNZH.js";
108
108
  import {
109
109
  n as callable,
110
110
  s as unstable_callable,
@@ -172,7 +172,7 @@ export {
172
172
  MCPServersState,
173
173
  MCP_SERVER_ID_MAX_LENGTH,
174
174
  MessageType,
175
- QueueItem,
175
+ type QueueItem,
176
176
  RPCRequest,
177
177
  RPCResponse,
178
178
  type RetryOptions,
package/dist/index.js CHANGED
@@ -7,9 +7,9 @@ import { MessageType } from "./types.js";
7
7
  import { createHeaderBasedEmailResolver } from "./email.js";
8
8
  import { n as withInvocationScope } from "./cloudflare-Dzvc7V2N.js";
9
9
  import { SUB_PREFIX, buildAgentPath, buildAgentUrl, getSubAgentByName, parseSubAgentPath, routeSubAgentRequest } from "./sub-routing.js";
10
- import { a as routeAgentEmail, i as getCurrentAgent, n as DEFAULT_AGENT_STATIC_OPTIONS, r as StreamingResponse, t as Agent } from "./src-DlSHshb2.js";
10
+ import { a as routeAgentEmail, i as getCurrentAgent, n as DEFAULT_AGENT_STATIC_OPTIONS, r as StreamingResponse, t as Agent } from "./src-BNU3ZiJM.js";
11
11
  import { isDurableObjectCodeUpdateReset, isDurableObjectMemoryLimitReset, isDurableObjectStorageReset, isPlatformTransientError } from "./retries.js";
12
12
  import { SqlError } from "./sql-error.js";
13
- import { i as normalizeServerId, n as MCP_SERVER_ID_MAX_LENGTH } from "./client-jagG8a9_.js";
13
+ import { i as normalizeServerId, n as MCP_SERVER_ID_MAX_LENGTH } from "./client-fyQrLGkD.js";
14
14
  import { DurableObjectOAuthClientProvider } from "./mcp/client/do-oauth-client-provider.js";
15
15
  export { AGENT_TOOL_MILESTONE_PART, AGENT_TOOL_PROGRESS_PART, Agent, DEFAULT_AGENT_STATIC_OPTIONS, DurableObjectOAuthClientProvider, MCP_SERVER_ID_MAX_LENGTH, MessageType, SUB_PREFIX, SqlError, StreamingResponse, __DO_NOT_USE_WILL_BREAK__agentContext, withInvocationScope as __DO_NOT_USE_WILL_BREAK__withInvocationScope, buildAgentPath, buildAgentUrl, callable, camelCaseToKebabCase, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, getSubAgentByName, isDurableObjectCodeUpdateReset, isDurableObjectMemoryLimitReset, isDurableObjectStorageReset, isPlatformTransientError, normalizeServerId, parseSubAgentPath, routeAgentEmail, routeAgentRequest, routeSubAgentRequest, unstable_callable };
@@ -2,7 +2,7 @@ import {
2
2
  i as __DO_NOT_USE_WILL_BREAK__agentContext,
3
3
  n as CurrentAgentContext,
4
4
  t as AgentContextStore
5
- } from "./current-agent-Da_C9a3b.js";
5
+ } from "./current-agent-C4w86kcN.js";
6
6
  import { t as AgentEmail } from "./internal_context-BlxFEWfn.js";
7
7
  export {
8
8
  type AgentContextStore,
@@ -1,14 +1,15 @@
1
1
  import {
2
- C as ConnectionState,
3
- S as ConnectionSetStateFn,
4
- _ as LifecycleJobOutcome,
2
+ C as ConnectionSetStateFn,
3
+ S as ConnectionContext,
4
+ T as WSMessage,
5
+ _ as LifecycleJobContext,
5
6
  a as LifecycleEvent,
6
- b as Connection,
7
+ b as LifecycleJobs,
7
8
  c as LifecycleEvents,
8
9
  d as LifecycleRouteContext,
9
10
  f as LifecycleRoutes,
10
- g as LifecycleJobContext,
11
- h as LifecycleJob,
11
+ g as LifecycleJob,
12
+ h as LifecycleStatus,
12
13
  i as DurableObjectCapability,
13
14
  l as LifecycleHostContextScope,
14
15
  m as LifecycleSockets,
@@ -19,19 +20,20 @@ import {
19
20
  s as LifecycleCapability,
20
21
  t as CapabilityRequestContext,
21
22
  u as LifecycleRouteAddress,
22
- v as LifecycleJobPushOptions,
23
- w as WSMessage,
24
- x as ConnectionContext,
25
- y as LifecycleJobs
26
- } from "../capability-runner-Be_-PLR1.js";
23
+ v as LifecycleJobOutcome,
24
+ w as ConnectionState,
25
+ x as Connection,
26
+ y as LifecycleJobPushOptions
27
+ } from "../capability-runner-BUBa6Ake.js";
28
+ import {
29
+ n as LifecycleOptions,
30
+ t as Lifecycle
31
+ } from "../durable-object-lifecycle-ei7M7lqB.js";
27
32
  import {
28
33
  a as getCurrentAgent,
29
- l as LifecycleUseOptions,
30
34
  n as CurrentAgentContext,
31
- o as Lifecycle,
32
- r as LifecycleObject,
33
- s as LifecycleOptions
34
- } from "../current-agent-Da_C9a3b.js";
35
+ r as LifecycleObject
36
+ } from "../current-agent-C4w86kcN.js";
35
37
  export {
36
38
  type CapabilityRequestContext,
37
39
  type CapabilityStartContext,
@@ -59,7 +61,7 @@ export {
59
61
  type LifecycleRoutes,
60
62
  type LifecycleServices,
61
63
  type LifecycleSockets,
62
- type LifecycleUseOptions,
64
+ type LifecycleStatus,
63
65
  type MemoryLimitContext,
64
66
  type WSMessage,
65
67
  getCurrentAgent
@@ -1,4 +1,4 @@
1
1
  import { n as getCurrentAgent } from "../current-agent-DhoDkSnH.js";
2
- import { t as LifecycleCapability } from "../capability-BjSKYpzg.js";
3
- import { t as Lifecycle } from "../lifecycle-CMRGjZdw.js";
2
+ import { t as LifecycleCapability } from "../capability-B4WbF81e.js";
3
+ import { t as Lifecycle } from "../lifecycle-Mm_jQh7r.js";
4
4
  export { Lifecycle, LifecycleCapability, getCurrentAgent };
@@ -1,6 +1,6 @@
1
1
  import { i as runWithoutCurrentAgent, r as runInLifecycleHostContext } from "./current-agent-DhoDkSnH.js";
2
2
  import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-DZBYAB34.js";
3
- import { n as bindLifecycleCapability, r as lifecycleCapabilityId, t as LifecycleCapability } from "./capability-BjSKYpzg.js";
3
+ import { n as bindLifecycleCapability, r as lifecycleCapabilityId, t as LifecycleCapability } from "./capability-B4WbF81e.js";
4
4
  import { t as _classPrivateMethodInitSpec } from "./classPrivateMethodInitSpec-qMjJ6sHQ.js";
5
5
  import { n as publishDiagnosticsEvent } from "./diagnostics-BzvaX2UT.js";
6
6
  import { isDurableObjectCodeUpdateReset, isDurableObjectMemoryLimitReset, isPlatformFailure, tryN } from "./retries.js";
@@ -818,6 +818,17 @@ function setLifecycleRouteTransport(lifecycle, transport) {
818
818
  function setLifecycleEventSink(lifecycle, sink) {
819
819
  lifecycleEventSinks.set(lifecycle, sink);
820
820
  }
821
+ /**
822
+ * Installs and coordinates the runtime lifecycle for a Durable Object.
823
+ *
824
+ * Construct this as an instance field on a class that directly extends
825
+ * `DurableObject`, then call {@link Lifecycle.installHandlers}
826
+ * from that class's constructor.
827
+ *
828
+ * @experimental The API surface may change before stabilizing.
829
+ */
830
+ /** The dispatch hooks a catch-all can monopolize; uniqueness is per hook. */
831
+ const CATCH_ALL_HOOKS = ["onRequest", "onWebSocketUpgrade"];
821
832
  var _host = /* @__PURE__ */ new WeakMap();
822
833
  var _ctx = /* @__PURE__ */ new WeakMap();
823
834
  var _parentClassName = /* @__PURE__ */ new WeakMap();
@@ -831,20 +842,10 @@ var _rearmRequestedDuringStart = /* @__PURE__ */ new WeakMap();
831
842
  var _pendingEvents = /* @__PURE__ */ new WeakMap();
832
843
  var _alarmsDisabled = /* @__PURE__ */ new WeakMap();
833
844
  var _capabilitiesLocked = /* @__PURE__ */ new WeakMap();
834
- var _fallbacks = /* @__PURE__ */ new WeakMap();
835
845
  var _handlersInstalled = /* @__PURE__ */ new WeakMap();
836
846
  var _Lifecycle_brand = /* @__PURE__ */ new WeakSet();
837
847
  var _legacyName = /* @__PURE__ */ new WeakMap();
838
848
  var _props = /* @__PURE__ */ new WeakMap();
839
- /**
840
- * Installs and coordinates the runtime lifecycle for a Durable Object.
841
- *
842
- * Construct this as an instance field on a class that directly extends
843
- * `DurableObject`, then call {@link Lifecycle.installHandlers}
844
- * from that class's constructor.
845
- *
846
- * @experimental The API surface may change before stabilizing.
847
- */
848
849
  var Lifecycle = class Lifecycle {
849
850
  /**
850
851
  * Construct and install a lifecycle in one explicit operation.
@@ -878,7 +879,6 @@ var Lifecycle = class Lifecycle {
878
879
  _classPrivateFieldInitSpec(this, _pendingEvents, []);
879
880
  _classPrivateFieldInitSpec(this, _alarmsDisabled, false);
880
881
  _classPrivateFieldInitSpec(this, _capabilitiesLocked, false);
881
- _classPrivateFieldInitSpec(this, _fallbacks, /* @__PURE__ */ new Set());
882
882
  _classPrivateFieldInitSpec(this, _handlersInstalled, false);
883
883
  _classPrivateFieldInitSpec(this, _legacyName, void 0);
884
884
  _classPrivateFieldInitSpec(this, _props, void 0);
@@ -935,20 +935,31 @@ var Lifecycle = class Lifecycle {
935
935
  /**
936
936
  * Add a reusable capability before this lifecycle starts.
937
937
  *
938
- * Capabilities dispatch in registration order, except that fallbacks
939
- * always come after non-fallbacks.
938
+ * Capabilities dispatch in registration order, except that a capability
939
+ * declaring `claims: "catch-all"` always comes last, whenever it was
940
+ * installed. Catch-alls are unique per dispatch hook: two may coexist
941
+ * when they claim disjoint traffic (one `onRequest`, one
942
+ * `onWebSocketUpgrade`), but a second catch-all for the same hook could
943
+ * never be reached and is refused.
940
944
  *
941
945
  * @param capability - The capability to add.
942
- * @param options - Dispatch placement.
943
946
  * @returns This lifecycle.
944
947
  */
945
- use(capability, options) {
948
+ use(capability) {
946
949
  if (_classPrivateFieldGet2(_capabilitiesLocked, this)) throw new Error("Lifecycle capabilities must be added before startup");
947
950
  const capabilityId = lifecycleCapabilityId(capability);
948
951
  if (capabilityId && _classPrivateFieldGet2(_capabilities, this).some((candidate) => lifecycleCapabilityId(candidate) === capabilityId)) throw new Error(`Lifecycle capability ${JSON.stringify(capabilityId)} is already installed`);
949
- const firstFallback = _classPrivateFieldGet2(_capabilities, this).findIndex((candidate) => _classPrivateFieldGet2(_fallbacks, this).has(candidate));
950
- if (options?.fallback) _classPrivateFieldGet2(_fallbacks, this).add(capability);
951
- _classPrivateFieldGet2(_capabilities, this).splice(options?.fallback || firstFallback === -1 ? _classPrivateFieldGet2(_capabilities, this).length : firstFallback, 0, capability);
952
+ const catchAllIndex = _classPrivateFieldGet2(_capabilities, this).findIndex((candidate) => candidate.claims === "catch-all");
953
+ if (capability.claims === "catch-all") {
954
+ for (const hook of CATCH_ALL_HOOKS) {
955
+ if (!capability[hook]) continue;
956
+ const rival = _classPrivateFieldGet2(_capabilities, this).find((candidate) => candidate.claims === "catch-all" && candidate[hook]);
957
+ if (!rival) continue;
958
+ const installed = lifecycleCapabilityId(rival);
959
+ throw new Error(`Lifecycle already has a catch-all for ${hook}${installed ? ` (${JSON.stringify(installed)})` : ""}; a second one could never be reached`);
960
+ }
961
+ _classPrivateFieldGet2(_capabilities, this).push(capability);
962
+ } else _classPrivateFieldGet2(_capabilities, this).splice(catchAllIndex === -1 ? _classPrivateFieldGet2(_capabilities, this).length : catchAllIndex, 0, capability);
952
963
  if (capability instanceof LifecycleCapability) bindLifecycleCapability(capability, _assertClassBrand(_Lifecycle_brand, this, _servicesForCapability).call(this, capability.capabilityId));
953
964
  return this;
954
965
  }
@@ -1139,13 +1150,17 @@ function _servicesForCapability(capabilityId) {
1139
1150
  payload
1140
1151
  });
1141
1152
  return Object.freeze({
1153
+ get name() {
1154
+ return lifecycle.name;
1155
+ },
1156
+ className: _classPrivateFieldGet2(_parentClassName, this),
1142
1157
  storage: _classPrivateFieldGet2(_ctx, this).storage,
1143
1158
  sockets: Object.freeze({
1144
1159
  accept: (ws, tags) => _classPrivateFieldGet2(_ctx, this).acceptWebSocket(ws, tags),
1145
1160
  get: (tag) => _classPrivateFieldGet2(_ctx, this).getWebSockets(tag)
1146
1161
  }),
1147
1162
  ready: () => _assertClassBrand(_Lifecycle_brand, this, _readyForCapabilityOperation).call(this),
1148
- starting: () => _classPrivateFieldGet2(_status, this) === "starting",
1163
+ status: () => _classPrivateFieldGet2(_status, this),
1149
1164
  jobs: _assertClassBrand(_Lifecycle_brand, this, _jobsForOwner).call(this, capabilityId),
1150
1165
  trackAlarmWork: (work) => _classPrivateFieldGet2(_jobDriver, this).trackAlarmWork(work),
1151
1166
  runInHostContext: async (fn, scope) => _assertClassBrand(_Lifecycle_brand, this, _runInHostBoundary).call(this, fn, scope),
@@ -1296,4 +1311,4 @@ async function _resolveJobDispatch(owner) {
1296
1311
  //#endregion
1297
1312
  export { abortWithoutAlarmRetry as a, setLifecycleRouteTransport as i, setLifecycleEventSink as n, setLifecycleHostInvoker as r, Lifecycle as t };
1298
1313
 
1299
- //# sourceMappingURL=lifecycle-CMRGjZdw.js.map
1314
+ //# sourceMappingURL=lifecycle-Mm_jQh7r.js.map