agents 0.22.0 → 0.23.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 (186) hide show
  1. package/README.md +20 -1
  2. package/dist/{agent-routing-CnkaHb-v.d.ts → agent-routing-DE5zmCQ8.d.ts} +1038 -394
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +26 -26
  5. package/dist/{agent-tools-C0XJqWzB.d.ts → agent-tools-DtXMTDGM.d.ts} +7 -7
  6. package/dist/agent-tools.d.ts +21 -21
  7. package/dist/browser/ai.js +4 -1
  8. package/dist/browser/ai.js.map +1 -1
  9. package/dist/browser/tanstack-ai.js.map +1 -1
  10. package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
  11. package/dist/callable-decorator.d.ts +18 -0
  12. package/dist/callable-decorator.js +71 -0
  13. package/dist/callable-decorator.js.map +1 -0
  14. package/dist/capability-BjSKYpzg.js.map +1 -1
  15. package/dist/capability-runner-Be_-PLR1.d.ts +459 -0
  16. package/dist/channel-Bnm4S7T2.d.ts +491 -0
  17. package/dist/channels/ai-sdk.d.ts +46 -0
  18. package/dist/channels/ai-sdk.js +120 -0
  19. package/dist/channels/ai-sdk.js.map +1 -0
  20. package/dist/channels/email.d.ts +95 -0
  21. package/dist/channels/email.js +323 -0
  22. package/dist/channels/email.js.map +1 -0
  23. package/dist/channels/index.d.ts +233 -0
  24. package/dist/channels/index.js +608 -0
  25. package/dist/channels/index.js.map +1 -0
  26. package/dist/channels/slack.d.ts +140 -0
  27. package/dist/channels/slack.js +614 -0
  28. package/dist/channels/slack.js.map +1 -0
  29. package/dist/channels/tanstack-ai.d.ts +39 -0
  30. package/dist/channels/tanstack-ai.js +17 -0
  31. package/dist/channels/tanstack-ai.js.map +1 -0
  32. package/dist/channels/telegram.d.ts +106 -0
  33. package/dist/channels/telegram.js +427 -0
  34. package/dist/channels/telegram.js.map +1 -0
  35. package/dist/channels/voice.d.ts +45 -0
  36. package/dist/channels/voice.js +122 -0
  37. package/dist/channels/voice.js.map +1 -0
  38. package/dist/chat/index.d.ts +2325 -2019
  39. package/dist/chat/index.js +888 -518
  40. package/dist/chat/index.js.map +1 -1
  41. package/dist/chat-sdk/index.d.ts +7 -7
  42. package/dist/chat-sdk/index.js +1 -1
  43. package/dist/client.d.ts +1 -1
  44. package/dist/context/index.d.ts +216 -0
  45. package/dist/context/index.js +454 -0
  46. package/dist/context/index.js.map +1 -0
  47. package/dist/{current-agent-CuMErtly.d.ts → current-agent-Da_C9a3b.d.ts} +90 -107
  48. package/dist/current-agent-DhoDkSnH.js.map +1 -1
  49. package/dist/{diagnostics-CaBjfz4J.js → diagnostics-BzvaX2UT.js} +5 -1
  50. package/dist/diagnostics-BzvaX2UT.js.map +1 -0
  51. package/dist/diagnostics-C4jcz3VK.js +360 -0
  52. package/dist/diagnostics-C4jcz3VK.js.map +1 -0
  53. package/dist/index-BB0kqhIz.d.ts +101 -0
  54. package/dist/index-BVVgDSdq.d.ts +1 -0
  55. package/dist/index-XDkuQ7zm.d.ts +89 -0
  56. package/dist/{index-DcSAZKsB.d.ts → index-YSKgfgg9.d.ts} +3 -1
  57. package/dist/index.d.ts +91 -82
  58. package/dist/index.js +3 -2
  59. package/dist/ingress-BfetZbMO.js +83 -0
  60. package/dist/ingress-BfetZbMO.js.map +1 -0
  61. package/dist/internal-CYlgHl1l.js +59 -0
  62. package/dist/internal-CYlgHl1l.js.map +1 -0
  63. package/dist/internal_context.d.ts +1 -1
  64. package/dist/lifecycle/index.d.ts +35 -17
  65. package/dist/lifecycle/index.js +1 -1
  66. package/dist/lifecycle-CMRGjZdw.js +1299 -0
  67. package/dist/lifecycle-CMRGjZdw.js.map +1 -0
  68. package/dist/mcp/client/index.d.ts +20 -20
  69. package/dist/mcp/index.d.ts +35 -35
  70. package/dist/mcp/index.js +1 -1
  71. package/dist/observability/index.d.ts +1 -1
  72. package/dist/observability/index.js +1 -1
  73. package/dist/react.d.ts +4 -4
  74. package/dist/{retries-CAvxtG9d.d.ts → retries-D9Ds-1lz.d.ts} +17 -6
  75. package/dist/retries.d.ts +8 -6
  76. package/dist/retries.js +13 -1
  77. package/dist/retries.js.map +1 -1
  78. package/dist/routing/index.d.ts +137 -0
  79. package/dist/routing/index.js +244 -0
  80. package/dist/routing/index.js.map +1 -0
  81. package/dist/sanitize-D9TujEK8.js +79 -0
  82. package/dist/sanitize-D9TujEK8.js.map +1 -0
  83. package/dist/scheduler-DD9NdYbF.js +665 -0
  84. package/dist/scheduler-DD9NdYbF.js.map +1 -0
  85. package/dist/{scheduler-DQoTGoAW.d.ts → scheduler-Dwh85ZGl.d.ts} +21 -22
  86. package/dist/schedules/index.d.ts +1 -1
  87. package/dist/schedules/index.js +1 -1
  88. package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
  89. package/dist/serializable.d.ts +1 -1
  90. package/dist/sessions/index.d.ts +441 -0
  91. package/dist/sessions/index.js +2063 -0
  92. package/dist/sessions/index.js.map +1 -0
  93. package/dist/skills/index.d.ts +99 -0
  94. package/dist/skills/index.js +254 -5
  95. package/dist/skills/index.js.map +1 -1
  96. package/dist/{src-5W6JNKVb.js → src-DlSHshb2.js} +1460 -1110
  97. package/dist/src-DlSHshb2.js.map +1 -0
  98. package/dist/streams/index.d.ts +120 -0
  99. package/dist/streams/index.js +107 -0
  100. package/dist/streams/index.js.map +1 -0
  101. package/dist/streams-D6tJ0NN9.d.ts +370 -0
  102. package/dist/streams-DZKgAj9b.js +709 -0
  103. package/dist/streams-DZKgAj9b.js.map +1 -0
  104. package/dist/sub-routing.d.ts +12 -12
  105. package/dist/surface-bZZJqBka.js +17 -0
  106. package/dist/surface-bZZJqBka.js.map +1 -0
  107. package/dist/tasks/index.d.ts +64 -0
  108. package/dist/tasks/index.js +2 -0
  109. package/dist/tasks-BRJ5zgya.d.ts +517 -0
  110. package/dist/tasks-ylZgBjhj.js +1656 -0
  111. package/dist/tasks-ylZgBjhj.js.map +1 -0
  112. package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
  113. package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
  114. package/dist/text-stream-CpdiKrJB.js +272 -0
  115. package/dist/text-stream-CpdiKrJB.js.map +1 -0
  116. package/dist/tokens-nHAKcN6M.js +52 -0
  117. package/dist/tokens-nHAKcN6M.js.map +1 -0
  118. package/dist/tool-schema-CBjGPrsQ.js +31 -0
  119. package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
  120. package/dist/types-B7LojTe4.d.ts +202 -0
  121. package/dist/types-_Faxb570.d.ts +439 -0
  122. package/dist/voice/client.d.ts +226 -0
  123. package/dist/voice/client.js +932 -0
  124. package/dist/voice/client.js.map +1 -0
  125. package/dist/voice/errors.d.ts +43 -0
  126. package/dist/voice/errors.js +41 -0
  127. package/dist/voice/errors.js.map +1 -0
  128. package/dist/voice/index.d.ts +271 -0
  129. package/dist/voice/index.js +1812 -0
  130. package/dist/voice/index.js.map +1 -0
  131. package/dist/voice/react.d.ts +167 -0
  132. package/dist/voice/react.js +234 -0
  133. package/dist/voice/react.js.map +1 -0
  134. package/dist/voice/sfu.d.ts +71 -0
  135. package/dist/voice/sfu.js +157 -0
  136. package/dist/voice/sfu.js.map +1 -0
  137. package/dist/voice/text.d.ts +6 -0
  138. package/dist/voice/text.js +2 -0
  139. package/dist/voice/types.d.ts +58 -0
  140. package/dist/voice/types.js +18 -0
  141. package/dist/voice/types.js.map +1 -0
  142. package/dist/voice/workers-ai.d.ts +136 -0
  143. package/dist/voice/workers-ai.js +568 -0
  144. package/dist/voice/workers-ai.js.map +1 -0
  145. package/dist/websockets/index.d.ts +192 -0
  146. package/dist/websockets/index.js +2 -0
  147. package/dist/websockets-DUfRHPRq.js +502 -0
  148. package/dist/websockets-DUfRHPRq.js.map +1 -0
  149. package/dist/workflow-types.d.ts +25 -25
  150. package/dist/workflows.d.ts +21 -21
  151. package/dist/workflows.js +1 -1
  152. package/docs/agent-class.md +2 -2
  153. package/docs/agent-tools.md +2 -1
  154. package/docs/channels.md +323 -0
  155. package/docs/chat-agents.md +6 -13
  156. package/docs/context.md +131 -0
  157. package/docs/index.md +15 -12
  158. package/docs/lifecycle.md +102 -55
  159. package/docs/long-running-agents.md +2 -2
  160. package/docs/mcp-servers.md +5 -1
  161. package/docs/resumable-streaming.md +1 -1
  162. package/docs/routing.md +105 -0
  163. package/docs/sessions.md +237 -871
  164. package/docs/streams.md +213 -0
  165. package/docs/sub-agents.md +184 -124
  166. package/docs/tasks.md +246 -0
  167. package/docs/voice.md +745 -0
  168. package/package.json +115 -13
  169. package/dist/capability-runner-CvHGZqUu.d.ts +0 -150
  170. package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
  171. package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
  172. package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
  173. package/dist/diagnostics-CaBjfz4J.js.map +0 -1
  174. package/dist/durable-object-lifecycle-D6nNQJJd.js +0 -862
  175. package/dist/durable-object-lifecycle-D6nNQJJd.js.map +0 -1
  176. package/dist/experimental/memory/session/index.d.ts +0 -671
  177. package/dist/experimental/memory/session/index.js +0 -2379
  178. package/dist/experimental/memory/session/index.js.map +0 -1
  179. package/dist/experimental/memory/utils/index.d.ts +0 -96
  180. package/dist/experimental/memory/utils/index.js +0 -79
  181. package/dist/experimental/memory/utils/index.js.map +0 -1
  182. package/dist/scheduler-CR9RHGos.js +0 -857
  183. package/dist/scheduler-CR9RHGos.js.map +0 -1
  184. package/dist/src-5W6JNKVb.js.map +0 -1
  185. package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
  186. package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
@@ -1,25 +1,27 @@
1
1
  import {
2
- l as LifecycleRouteAddress,
3
- n as CapabilityRequestContext,
2
+ _ as LifecycleJobOutcome,
3
+ b as Connection,
4
+ g as LifecycleJobContext,
5
+ o as MemoryLimitContext,
4
6
  s as LifecycleCapability,
5
- t as AlarmContribution
6
- } from "./capability-runner-CvHGZqUu.js";
7
+ t as CapabilityRequestContext,
8
+ u as LifecycleRouteAddress,
9
+ w as WSMessage,
10
+ x as ConnectionContext
11
+ } from "./capability-runner-Be_-PLR1.js";
12
+ import { t as RetryOptions } from "./retries-D9Ds-1lz.js";
7
13
  import {
8
- c as WSMessage,
9
- l as Connection,
14
+ c as LifecycleRouteEnvelope,
10
15
  n as CurrentAgentContext,
11
- o as Lifecycle,
12
- s as LifecycleRouteEnvelope,
13
- u as ConnectionContext
14
- } from "./current-agent-CuMErtly.js";
16
+ o as Lifecycle
17
+ } from "./current-agent-Da_C9a3b.js";
15
18
  import { t as AgentEmail } from "./internal_context-BlxFEWfn.js";
16
19
  import { r as EmailResolver, s as SendEmailOptions } from "./email-7TatiTnl.js";
17
- import { t as RetryOptions } from "./retries-CAvxtG9d.js";
18
20
  import {
19
21
  n as Observability,
20
22
  r as ObservabilityEvent,
21
23
  s as MCPObservabilityEvent
22
- } from "./index-DcSAZKsB.js";
24
+ } from "./index-YSKgfgg9.js";
23
25
  import { t as AgentMcpOAuthProvider } from "./do-oauth-client-provider-Tmf1vgKz.js";
24
26
  import {
25
27
  a as McpAuthContext,
@@ -37,8 +39,12 @@ import { t as MessageType } from "./types-6Zo2zfoO.js";
37
39
  import {
38
40
  a as ScheduleCriteria,
39
41
  i as Schedule,
42
+ o as ScheduleOptions,
40
43
  t as Scheduler
41
- } from "./scheduler-DQoTGoAW.js";
44
+ } from "./scheduler-Dwh85ZGl.js";
45
+ import { l as TaskHandlers, r as Tasks } from "./tasks-BRJ5zgya.js";
46
+ import { t as CallableMetadata } from "./callable-decorator-DP__HhBA.js";
47
+ import { AsyncLocalStorage } from "node:async_hooks";
42
48
  import {
43
49
  DurableObject,
44
50
  RpcTarget,
@@ -286,9 +292,731 @@ declare function routeSubAgentRequest(
286
292
  */
287
293
  declare function getSubAgentByName<T extends Agent>(
288
294
  parent: unknown,
289
- cls: SubAgentClass<T>,
295
+ cls: DynamicAgentClass<T>,
290
296
  name: string
291
- ): Promise<SubAgentStub<T>>;
297
+ ): Promise<DynamicAgentStub<T>>;
298
+ //#endregion
299
+ //#region src/dynamic-agents/types.d.ts
300
+ type DynamicAgentConnectionMeta = {
301
+ id: string;
302
+ uri: string | null;
303
+ tags: string[];
304
+ state: unknown;
305
+ requestHeaders?: [string, string][];
306
+ };
307
+ type DynamicAgentConnectionBridgeLike = {
308
+ send(message: string | ArrayBuffer | ArrayBufferView): void | Promise<void>;
309
+ close(code?: number, reason?: string): void | Promise<void>;
310
+ setState(state: unknown): unknown | Promise<unknown>;
311
+ broadcast(
312
+ ownerPath: ReadonlyArray<{
313
+ className: string;
314
+ name: string;
315
+ }>,
316
+ message: string | ArrayBuffer | ArrayBufferView,
317
+ without?: string[]
318
+ ): void | Promise<void>;
319
+ };
320
+ type DynamicAgentConnectionOperationName = "send" | "setState" | "close";
321
+ /**
322
+ * Constructor type for a dynamic agent (facet-backed child) class.
323
+ * Used by {@link Agent.dynamicAgents} to reference the child class
324
+ * via `ctx.exports`.
325
+ *
326
+ * The class name (`cls.name`) must match the export name in the
327
+ * worker entry point — re-exports under a different name
328
+ * (e.g. `export { Foo as Bar }`) are not supported.
329
+ */
330
+ type DynamicAgentClass<T extends Agent = Agent> = {
331
+ new (ctx: DurableObjectState, env: never): T;
332
+ };
333
+ /**
334
+ * Wraps `T` in a `Promise` unless it already is one.
335
+ */
336
+ type Promisify<T> = T extends Promise<unknown> ? T : Promise<T>;
337
+ /**
338
+ * A typed RPC stub for a dynamic agent. Exposes all public instance
339
+ * methods as callable RPC methods with Promise-wrapped return types.
340
+ *
341
+ * Methods owned by `Agent`, its lifecycle, or `DurableObject` internals
342
+ * are excluded — only user-defined methods on the subclass are exposed.
343
+ */
344
+ type DynamicAgentStub<T extends Agent> = {
345
+ [K in keyof T as K extends keyof Agent
346
+ ? never
347
+ : T[K] extends (...args: never[]) => unknown
348
+ ? K
349
+ : never]: T[K] extends (...args: infer A) => infer R
350
+ ? (...args: A) => Promisify<R>
351
+ : never;
352
+ };
353
+ type FacetRunStorageRow = {
354
+ owner_path: string;
355
+ owner_path_key: string;
356
+ run_id: string;
357
+ created_at: number;
358
+ };
359
+ /**
360
+ * Internal RPC surface exposed by the root agent for facets to
361
+ * delegate alarm-owning operations (schedules + facet teardown).
362
+ * @internal
363
+ */
364
+ type RootFacetRpcSurface = {
365
+ _cf_routeLifecycle(
366
+ target: LifecycleRouteAddress | undefined,
367
+ envelope: LifecycleRouteEnvelope
368
+ ): Promise<unknown>;
369
+ _cf_cleanupFacetPrefix(
370
+ ownerPath: ReadonlyArray<AgentPathStep>
371
+ ): Promise<void>;
372
+ _cf_destroyDescendantFacet(
373
+ targetPath: ReadonlyArray<AgentPathStep>
374
+ ): Promise<void>;
375
+ _cf_acquireFacetKeepAlive(
376
+ ownerPath: ReadonlyArray<AgentPathStep>
377
+ ): Promise<string>;
378
+ _cf_releaseFacetKeepAlive(token: string): Promise<void>;
379
+ _cf_registerFacetRun(
380
+ ownerPath: ReadonlyArray<AgentPathStep>,
381
+ runId: string
382
+ ): Promise<void>;
383
+ _cf_unregisterFacetRun(
384
+ ownerPath: ReadonlyArray<AgentPathStep>,
385
+ runId: string
386
+ ): Promise<void>;
387
+ _cf_broadcastToSubAgent(
388
+ ownerPath: ReadonlyArray<AgentPathStep>,
389
+ message: string | ArrayBuffer | ArrayBufferView,
390
+ without?: string[]
391
+ ): Promise<void>;
392
+ _cf_subAgentConnectionMetas(
393
+ ownerPath: ReadonlyArray<AgentPathStep>
394
+ ): Promise<DynamicAgentConnectionMeta[]>;
395
+ _cf_sendToSubAgentConnection(
396
+ connectionId: string,
397
+ message: string | ArrayBuffer | ArrayBufferView
398
+ ): Promise<void>;
399
+ _cf_closeSubAgentConnection(
400
+ connectionId: string,
401
+ code?: number,
402
+ reason?: string
403
+ ): Promise<void>;
404
+ _cf_setSubAgentConnectionState(
405
+ connectionId: string,
406
+ state: unknown
407
+ ): Promise<unknown>;
408
+ };
409
+ //#endregion
410
+ //#region src/dynamic-agents/bridges.d.ts
411
+ /**
412
+ * Parent-side bridge handed to a facet over RPC: wraps a live root-owned
413
+ * `Connection` so the facet can send/close/setState on it, and carries
414
+ * the root's broadcast entry point for facet-scoped broadcasts.
415
+ */
416
+ declare class DynamicAgentConnectionBridge
417
+ extends RpcTarget
418
+ implements DynamicAgentConnectionBridgeLike
419
+ {
420
+ #private;
421
+ constructor(
422
+ connection: Connection,
423
+ broadcast?: (
424
+ ownerPath: ReadonlyArray<{
425
+ className: string;
426
+ name: string;
427
+ }>,
428
+ message: string | ArrayBuffer | ArrayBufferView,
429
+ without?: string[]
430
+ ) => void | Promise<void>
431
+ );
432
+ send(message: string | ArrayBuffer | ArrayBufferView): void;
433
+ close(code?: number, reason?: string): void;
434
+ setState(state: unknown): unknown;
435
+ broadcast(
436
+ ownerPath: ReadonlyArray<{
437
+ className: string;
438
+ name: string;
439
+ }>,
440
+ message: string | ArrayBuffer | ArrayBufferView,
441
+ without?: string[]
442
+ ): void | Promise<void>;
443
+ }
444
+ //#endregion
445
+ //#region src/dynamic-agents/identity.d.ts
446
+ declare const SUB_AGENT_IDENTITY_VERSION_LEGACY = "legacy";
447
+ declare const SUB_AGENT_IDENTITY_VERSION_PATH_V2 = "path-v2";
448
+ type SubAgentIdentityVersion =
449
+ | typeof SUB_AGENT_IDENTITY_VERSION_LEGACY
450
+ | typeof SUB_AGENT_IDENTITY_VERSION_PATH_V2;
451
+ //#endregion
452
+ //#region src/dynamic-agents/registry.d.ts
453
+ /**
454
+ * SQL access the registry needs from its owning Agent: the tagged
455
+ * template helper plus raw DDL execution (for additive column
456
+ * migrations whose errors must be inspected).
457
+ */
458
+ type DynamicAgentRegistrySqlHost = {
459
+ sql<T = Record<string, string | number | boolean | null>>(
460
+ strings: TemplateStringsArray,
461
+ ...values: (string | number | boolean | null)[]
462
+ ): T[];
463
+ execRawSql(sql: string): void;
464
+ };
465
+ /**
466
+ * The parent-side registry of spawned dynamic agents (facets), stored
467
+ * in the parent's own SQLite. Backs `hasSubAgent` / `listSubAgents`
468
+ * and the identity-versioning decision (legacy bare-name facets vs
469
+ * path-scoped v2 identities).
470
+ *
471
+ * Table and column names are storage-frozen — never rename them.
472
+ */
473
+ declare class DynamicAgentRegistry {
474
+ #private;
475
+ constructor(host: DynamicAgentRegistrySqlHost);
476
+ ensure(): void;
477
+ record(
478
+ className: string,
479
+ name: string,
480
+ identity: {
481
+ version: SubAgentIdentityVersion;
482
+ name: string;
483
+ }
484
+ ): void;
485
+ row(
486
+ className: string,
487
+ name: string
488
+ ): {
489
+ identity_version: string | null;
490
+ identity_name: string | null;
491
+ } | null;
492
+ identity(
493
+ className: string,
494
+ name: string,
495
+ childPath: ReadonlyArray<AgentPathStep>
496
+ ): Promise<{
497
+ version: SubAgentIdentityVersion;
498
+ name: string;
499
+ existing: boolean;
500
+ }>;
501
+ forget(className: string, name: string): void;
502
+ has(className: string, name: string): boolean;
503
+ list(className?: string): Array<{
504
+ className: string;
505
+ name: string;
506
+ createdAt: number;
507
+ }>;
508
+ }
509
+ //#endregion
510
+ //#region src/dynamic-agents/host.d.ts
511
+ /**
512
+ * The Agent internals the dynamic-agents (facet) machinery reaches
513
+ * into. Agent implements this structurally and passes itself at
514
+ * construction — the interface exists to make the coupling explicit
515
+ * and reviewable, and is the seam a later capability refactor would
516
+ * shrink.
517
+ *
518
+ * Members named `_cf_*` are cross-facet RPC entry points that must
519
+ * stay on the Agent prototype; the module calls back into them when
520
+ * traversal continues on another agent instance.
521
+ *
522
+ * @internal
523
+ */
524
+ interface DynamicAgentHostPort {
525
+ readonly ctx: DurableObjectState;
526
+ readonly lifecycle: {
527
+ route(envelope: LifecycleRouteEnvelope): Promise<unknown>;
528
+ readonly name: string;
529
+ };
530
+ sql<T = Record<string, string | number | boolean | null>>(
531
+ strings: TemplateStringsArray,
532
+ ...values: (string | number | boolean | null)[]
533
+ ): T[];
534
+ /** Facet identity — written by `initAsFacet` and startup restore. */
535
+ _isFacet: boolean;
536
+ _facetName?: string;
537
+ _parentPath: ReadonlyArray<AgentPathStep>;
538
+ readonly name: string;
539
+ readonly _ParentClass: {
540
+ readonly name: string;
541
+ };
542
+ readonly selfPath: AgentPathStep[];
543
+ _keepAliveRefs: number;
544
+ _isSameAgentPathPrefix(
545
+ prefix: ReadonlyArray<AgentPathStep>,
546
+ path: ReadonlyArray<AgentPathStep>
547
+ ): boolean;
548
+ hasSubAgent(className: string, name: string): boolean;
549
+ _cf_resolveSubAgent(className: string, name: string): Promise<unknown>;
550
+ _cf_cleanupFacetPrefix(
551
+ ownerPath: ReadonlyArray<AgentPathStep>
552
+ ): Promise<void>;
553
+ _cf_routeLifecycle(
554
+ target: LifecycleRouteAddress | undefined,
555
+ envelope: LifecycleRouteEnvelope
556
+ ): Promise<unknown>;
557
+ _syncHostJobs(): Promise<void>;
558
+ readonly scheduler: {
559
+ __DO_NOT_USE_WILL_BREAK__cleanupRoutePrefix(prefix: string): Promise<void>;
560
+ };
561
+ readonly tasks: {
562
+ __DO_NOT_USE_WILL_BREAK__cleanupRoutePrefix(prefix: string): Promise<void>;
563
+ };
564
+ /** Local (non-facet-index) durable fiber recovery pass. */
565
+ _checkRunFibers(): Promise<void>;
566
+ /** Overridable RPC entry points — call via the host so subclass overrides intercept. */
567
+ _cf_broadcastToSubAgent(
568
+ ownerPath: ReadonlyArray<AgentPathStep>,
569
+ message: string | ArrayBuffer | ArrayBufferView,
570
+ without?: string[]
571
+ ): Promise<void>;
572
+ _cf_checkRunFibersForFacet(
573
+ ownerPath: ReadonlyArray<AgentPathStep>
574
+ ): Promise<number>;
575
+ /** Ensure constructor-time async initialization has completed. */
576
+ __unsafe_ensureInitialized(): Promise<void>;
577
+ /**
578
+ * Run `body` in a fresh invocation scope with no native request/
579
+ * connection context attached, so a child-facet RPC never sees
580
+ * parent-owned I/O handles.
581
+ */
582
+ _runFacetInitInvocation<T>(body: () => Promise<T>): Promise<T>;
583
+ readonly _webSockets: {
584
+ getConnection<TState = unknown>(id: string): Connection<TState> | undefined;
585
+ getConnections<TState = unknown>(
586
+ tag?: string
587
+ ): Iterable<Connection<TState>>;
588
+ };
589
+ _ensureConnectionWrapped(connection: Connection): void;
590
+ _unsafe_getConnectionFlag(connection: Connection, key: string): unknown;
591
+ _unsafe_setConnectionFlag(
592
+ connection: Connection,
593
+ key: string,
594
+ value: unknown
595
+ ): void;
596
+ readonly _rawStateAccessors: {
597
+ get(connection: Connection):
598
+ | {
599
+ getRaw(): unknown;
600
+ }
601
+ | undefined;
602
+ };
603
+ shouldConnectionBeReadonly(
604
+ connection: Connection,
605
+ context: {
606
+ request: Request;
607
+ }
608
+ ): boolean;
609
+ setConnectionReadonly(connection: Connection, readonly: boolean): void;
610
+ shouldSendProtocolMessages(
611
+ connection: Connection,
612
+ context: {
613
+ request: Request;
614
+ }
615
+ ): boolean;
616
+ _setConnectionNoProtocol(connection: Connection): void;
617
+ getConnectionTags(
618
+ connection: Connection,
619
+ context: {
620
+ request: Request;
621
+ }
622
+ ): Promise<string[]> | string[];
623
+ onConnect(
624
+ connection: Connection,
625
+ context: {
626
+ request: Request;
627
+ }
628
+ ): unknown | Promise<unknown>;
629
+ onMessage(
630
+ connection: Connection,
631
+ message: WSMessage
632
+ ): unknown | Promise<unknown>;
633
+ onClose(
634
+ connection: Connection,
635
+ code: number,
636
+ reason: string,
637
+ wasClean: boolean
638
+ ): unknown | Promise<unknown>;
639
+ onBeforeSubAgent(
640
+ request: Request,
641
+ child: {
642
+ className: string;
643
+ name: string;
644
+ }
645
+ ): Promise<Request | Response | void>;
646
+ }
647
+ //#endregion
648
+ //#region src/dynamic-agents/dynamic-agents.d.ts
649
+ /**
650
+ * The facet-backed dynamic-agent machinery, extracted from the Agent
651
+ * class. One instance per Agent, installed as a Lifecycle capability
652
+ * (`capabilityId: "dynamic-agents"`); the host port documents exactly
653
+ * which Agent internals it touches.
654
+ *
655
+ * The capability claims no runner hooks — four integration points are
656
+ * deliberately wired directly through the Agent composition root
657
+ * instead, because the runner's dispatch contract cannot express them:
658
+ * the `/sub/` upgrade path rewrites the request and *continues* into
659
+ * `lifecycle.fetch` (onRequest can only claim), forwarded WS frames run
660
+ * inside the host's onMessage wrapper *after* the WebSockets capability
661
+ * has claimed the wake, this module *implements* the lifecycle route
662
+ * transport rather than consuming it, and facet-context restore has
663
+ * load-bearing startup ordering inside the host's startup span.
664
+ *
665
+ * Nothing here renames any wire- or storage-visible identifier: the
666
+ * `cf_agents_facet_runs` table, `_cf_*` RPC method names, and route
667
+ * key formats are frozen.
668
+ *
669
+ * @internal
670
+ */
671
+ declare class DynamicAgentsInternal extends LifecycleCapability {
672
+ #private;
673
+ /** The parent-side registry of spawned dynamic agents. */
674
+ readonly registry: DynamicAgentRegistry;
675
+ constructor(host: DynamicAgentHostPort);
676
+ runRowsForPrefix(
677
+ ownerPath: ReadonlyArray<AgentPathStep>
678
+ ): FacetRunStorageRow[];
679
+ deleteRunRowsForPrefix(ownerPath: ReadonlyArray<AgentPathStep>): void;
680
+ lifecycleRouteAddress(): LifecycleRouteAddress | undefined;
681
+ routeLifecycleToRoot(envelope: LifecycleRouteEnvelope): Promise<unknown>;
682
+ routeLifecycleToTarget(
683
+ target: LifecycleRouteAddress,
684
+ envelope: LifecycleRouteEnvelope
685
+ ): Promise<unknown>;
686
+ /** Body of the single native-RPC aperture for routed Lifecycle capabilities. */
687
+ routeLifecycle(
688
+ target: LifecycleRouteAddress | undefined,
689
+ envelope: LifecycleRouteEnvelope
690
+ ): Promise<unknown>;
691
+ rootAlarmOwner(): Promise<RootFacetRpcSurface>;
692
+ rootResolvesToSelf(): boolean;
693
+ /**
694
+ * Clean root-owned bookkeeping for a sub-tree of facets: bulk-cancel
695
+ * schedules and routed Task wake mirrors under the owner-path prefix,
696
+ * and delete root-side facet fiber recovery leases for the same sub-tree.
697
+ */
698
+ cleanupPrefix(ownerPath: ReadonlyArray<AgentPathStep>): Promise<void>;
699
+ /**
700
+ * Acquire a root-owned keepAlive ref on behalf of a descendant facet.
701
+ */
702
+ acquireKeepAlive(ownerPath: ReadonlyArray<AgentPathStep>): Promise<string>;
703
+ /**
704
+ * Release a root-owned keepAlive ref previously acquired for a facet.
705
+ * Idempotent so disposer calls can safely race or run twice.
706
+ */
707
+ releaseKeepAlive(token: string): Promise<void>;
708
+ /**
709
+ * Register a facet's durable run row in the root-side index so root
710
+ * alarm housekeeping can dispatch recovery checks into idle facets.
711
+ */
712
+ registerRun(
713
+ ownerPath: ReadonlyArray<AgentPathStep>,
714
+ runId: string
715
+ ): Promise<void>;
716
+ /**
717
+ * Root-side scan for durable fibers owned by descendant facets.
718
+ * `cf_agents_facet_runs` is only an index; actual snapshots and
719
+ * recovery hooks live in each facet's own `cf_agents_runs` table.
720
+ */
721
+ checkRunFibers(): Promise<void>;
722
+ /**
723
+ * Dispatch a runFiber recovery check into the facet identified by
724
+ * `ownerPath`. Returns the number of remaining local `cf_agents_runs`
725
+ * rows on the target facet after recovery.
726
+ */
727
+ checkRunFibersAtPath(
728
+ ownerPath: ReadonlyArray<AgentPathStep>
729
+ ): Promise<number>;
730
+ /**
731
+ * Invoke an RPC method on the host Agent or a descendant facet
732
+ * identified by a root-first path. Used by AgentWorkflow to route
733
+ * callbacks and `this.agent` calls back to the exact sub-agent that
734
+ * started a workflow.
735
+ */
736
+ invokeAgentPath(
737
+ targetPath: ReadonlyArray<AgentPathStep>,
738
+ method: string,
739
+ args: unknown[]
740
+ ): Promise<unknown>;
741
+ /**
742
+ * Recursively destroy a descendant facet identified by `targetPath`.
743
+ * Walks down from `selfPath` until reaching the target's immediate
744
+ * parent, where it cancels the target's parent-owned schedules (and
745
+ * any descendants), removes the target from the registry, and calls
746
+ * `ctx.facets.delete` to wipe the target's storage.
747
+ */
748
+ destroyDescendant(targetPath: ReadonlyArray<AgentPathStep>): Promise<void>;
749
+ /**
750
+ * Shared facet resolution — takes a CamelCase class name string
751
+ * (matching `ctx.exports`) rather than a class reference. Both
752
+ * `subAgent(cls, name)` and `_cf_invokeSubAgent(className, ...)`
753
+ * funnel through here so registry bookkeeping and the
754
+ * `_cf_initAsFacet` handshake are consistent.
755
+ */
756
+ resolve(className: string, name: string): Promise<unknown>;
757
+ /**
758
+ * Forcefully abort a running facet. Transitively aborts the child's
759
+ * own children; storage is preserved.
760
+ */
761
+ abort(className: string, name: string, reason?: unknown): void;
762
+ /**
763
+ * Delete a facet: abort it if running, then permanently wipe its
764
+ * storage. Transitively deletes the child's own children.
765
+ */
766
+ delete(className: string, name: string): Promise<void>;
767
+ /** Drop all facet-side virtual connections (test/rehydration hook). */
768
+ clearVirtualConnections(): void;
769
+ /** Facet-side lookup of a virtual connection by id. */
770
+ getVirtualConnection(id: string): Connection | undefined;
771
+ /** Facet-side iteration over virtual connections, optionally by tag. */
772
+ getVirtualConnections(tag?: string): Iterable<Connection>;
773
+ activeBridge(
774
+ connectionId?: string
775
+ ): DynamicAgentConnectionBridgeLike | undefined;
776
+ /**
777
+ * Route a virtual sub-agent connection operation through its live frame
778
+ * bridge, or through the durable root Agent after that frame completes.
779
+ * All operations share one per-connection queue. Facet broadcasts wait for
780
+ * older queued operations; failures do not block later work.
781
+ */
782
+ routeConnectionOperation(
783
+ connectionId: string,
784
+ operationName: DynamicAgentConnectionOperationName,
785
+ operation: (bridge: DynamicAgentConnectionBridgeLike) => unknown
786
+ ): void;
787
+ /**
788
+ * Route a facet broadcast after every older connection operation.
789
+ *
790
+ * This barrier is intentionally one-way: facet startup can broadcast before
791
+ * a child connection has finished initializing its tags and protocol flags.
792
+ * Making those later connection operations wait would let the next frame
793
+ * observe stale root-owned metadata.
794
+ */
795
+ routeBroadcast(
796
+ ownerPath: ReadonlyArray<AgentPathStep>,
797
+ message: string | ArrayBuffer | ArrayBufferView,
798
+ without?: string[],
799
+ upstreamBridge?: DynamicAgentConnectionBridgeLike
800
+ ): Promise<void>;
801
+ broadcastToParent(
802
+ message: string | ArrayBuffer | ArrayBufferView,
803
+ without?: string[]
804
+ ): Promise<void>;
805
+ broadcastToPath(
806
+ ownerPath: ReadonlyArray<AgentPathStep>,
807
+ message: string | ArrayBuffer | ArrayBufferView,
808
+ without?: string[]
809
+ ): Promise<void>;
810
+ connectionMetas(
811
+ ownerPath: ReadonlyArray<AgentPathStep>
812
+ ): Promise<DynamicAgentConnectionMeta[]>;
813
+ sendToConnection(
814
+ connectionId: string,
815
+ message: string | ArrayBuffer | ArrayBufferView
816
+ ): Promise<void>;
817
+ closeConnection(
818
+ connectionId: string,
819
+ code?: number,
820
+ reason?: string
821
+ ): Promise<void>;
822
+ setConnectionState(connectionId: string, state: unknown): Promise<unknown>;
823
+ connectionTargetPath(
824
+ connection: Connection
825
+ ): ReadonlyArray<AgentPathStep> | null;
826
+ isSameAgentPath(
827
+ a: ReadonlyArray<AgentPathStep>,
828
+ b: ReadonlyArray<AgentPathStep>
829
+ ): boolean;
830
+ connectionHasChildTarget(connection: Connection): boolean;
831
+ connectionTargetsChild(connection: Connection): boolean;
832
+ requestTargetsChild(request: Request): boolean;
833
+ forwardWebSocketConnect(
834
+ connection: Connection,
835
+ request: Request,
836
+ options: {
837
+ gate: boolean;
838
+ }
839
+ ): Promise<boolean>;
840
+ forwardWebSocketMessage(
841
+ connection: Connection,
842
+ message: WSMessage,
843
+ replyBridge?: DynamicAgentConnectionBridge
844
+ ): Promise<boolean>;
845
+ forwardWebSocketClose(
846
+ connection: Connection,
847
+ code: number,
848
+ reason: string,
849
+ wasClean: boolean
850
+ ): Promise<boolean>;
851
+ handleWebSocketConnect(
852
+ bridge: DynamicAgentConnectionBridge,
853
+ meta: DynamicAgentConnectionMeta
854
+ ): Promise<void>;
855
+ handleWebSocketMessage(
856
+ message: WSMessage,
857
+ bridge: DynamicAgentConnectionBridge,
858
+ meta: DynamicAgentConnectionMeta,
859
+ replyBridge?: DynamicAgentConnectionBridge
860
+ ): Promise<void>;
861
+ handleWebSocketClose(
862
+ code: number,
863
+ reason: string,
864
+ wasClean: boolean,
865
+ bridge: DynamicAgentConnectionBridge,
866
+ meta: DynamicAgentConnectionMeta
867
+ ): Promise<void>;
868
+ runWithBridge<T>(
869
+ bridge: DynamicAgentConnectionBridgeLike,
870
+ connectionId: string,
871
+ fn: () => Promise<T> | T
872
+ ): Promise<T>;
873
+ createBridgeConnection(meta: DynamicAgentConnectionMeta): Connection;
874
+ storeVirtualConnection(connection: Connection): void;
875
+ /**
876
+ * Restore the facet identity persisted by `init` (wake after
877
+ * hibernation), then best-effort hydrate the virtual connections
878
+ * from the root's WebSocket state.
879
+ */
880
+ restoreFacetContext(): Promise<void>;
881
+ hydrateConnectionsFromRoot(): Promise<void>;
882
+ getRawConnectionState(connection: Connection): unknown;
883
+ getForwardedState(connection: Connection): unknown;
884
+ /**
885
+ * Resolve the facet Fetcher for the match and forward the request to
886
+ * it with `/sub/{class}/{name}` stripped.
887
+ */
888
+ forward(
889
+ req: Request,
890
+ match: {
891
+ childClass: string;
892
+ childName: string;
893
+ remainingPath: string;
894
+ }
895
+ ): Promise<Response>;
896
+ /**
897
+ * Bridge used by `getSubAgentByName`: resolve the facet and dispatch
898
+ * one RPC method. Stateless — no cached references.
899
+ */
900
+ invoke(
901
+ className: string,
902
+ name: string,
903
+ method: string,
904
+ args: unknown[]
905
+ ): Promise<unknown>;
906
+ /**
907
+ * Bridge used by `parentAgent()` when the requested parent is itself
908
+ * a facet (and therefore has no top-level env namespace). The root
909
+ * receives the full root-first target path, then each hop delegates
910
+ * to the next facet using that facet's own `ctx.facets`.
911
+ */
912
+ invokePath(
913
+ path: ReadonlyArray<{
914
+ className: string;
915
+ name: string;
916
+ }>,
917
+ method: string,
918
+ args: unknown[]
919
+ ): Promise<unknown>;
920
+ invokeStubMethod(
921
+ stub: unknown,
922
+ className: string,
923
+ method: string,
924
+ args: unknown[]
925
+ ): Promise<unknown>;
926
+ /**
927
+ * Initialize the host agent as a facet in a single RPC. Runs entirely
928
+ * inside the child's isolate, so every storage write and `onStart()`
929
+ * I/O is owned by the child DO.
930
+ */
931
+ init(
932
+ name: string,
933
+ parentPath?: ReadonlyArray<{
934
+ className: string;
935
+ name: string;
936
+ }>,
937
+ identityName?: string
938
+ ): Promise<void>;
939
+ /** Remove a completed facet fiber from the root-side index. */
940
+ unregisterRun(
941
+ ownerPath: ReadonlyArray<AgentPathStep>,
942
+ runId: string
943
+ ): Promise<void>;
944
+ }
945
+ //#endregion
946
+ //#region src/dynamic-agents/api.d.ts
947
+ /**
948
+ * The public dynamic-agents capability surface, reached via
949
+ * `this.dynamicAgents` on an Agent.
950
+ *
951
+ * A dynamic agent is a facet-backed child: it runs in its own isolate
952
+ * with its own SQLite database, colocated with — and supervised by —
953
+ * its parent Agent. Use dynamic agents for code whose class or
954
+ * lifecycle the parent owns (dynamically-loaded/generated code,
955
+ * per-run tool agents, sandboxed components). For independent peers
956
+ * such as one-DO-per-chat, use `getAgentByName` instead.
957
+ *
958
+ * @experimental The API surface may change before stabilizing.
959
+ */
960
+ declare class DynamicAgents {
961
+ #private;
962
+ /** @internal Constructed by Agent; do not instantiate directly. */
963
+ constructor(internal: DynamicAgentsInternal);
964
+ /**
965
+ * Get (creating or waking if needed) the dynamic agent of the given
966
+ * class and name, as a typed RPC stub. Idempotent — repeated calls
967
+ * with the same class and name return the same child.
968
+ *
969
+ * @experimental
970
+ */
971
+ get<T extends Agent>(
972
+ cls: DynamicAgentClass<T>,
973
+ name: string
974
+ ): Promise<DynamicAgentStub<T>>;
975
+ /**
976
+ * Forcefully abort a running dynamic agent. The child stops
977
+ * executing immediately and restarts on the next {@link get} call;
978
+ * its storage is preserved. Transitively aborts the child's own
979
+ * children. Pending RPC calls receive the reason as an error.
980
+ *
981
+ * @experimental
982
+ */
983
+ abort(cls: DynamicAgentClass, name: string, reason?: unknown): void;
984
+ /**
985
+ * Delete a dynamic agent: abort it if running, then permanently wipe
986
+ * its storage. Transitively deletes the child's own children.
987
+ *
988
+ * @experimental
989
+ */
990
+ delete(cls: DynamicAgentClass, name: string): Promise<void>;
991
+ /**
992
+ * Whether this agent has previously spawned (and not deleted) a
993
+ * dynamic agent of the given class and name. Backed by an
994
+ * auto-maintained SQLite registry in the parent's storage.
995
+ *
996
+ * @experimental
997
+ */
998
+ has<T extends Agent>(cls: DynamicAgentClass<T>, name: string): boolean;
999
+ has(className: string, name: string): boolean;
1000
+ /**
1001
+ * List known dynamic agents, optionally filtered by class. Reflects
1002
+ * the registry rows written by {@link get} and removed by
1003
+ * {@link delete}.
1004
+ *
1005
+ * @experimental
1006
+ */
1007
+ list<T extends Agent>(
1008
+ cls: DynamicAgentClass<T>
1009
+ ): Array<{
1010
+ className: string;
1011
+ name: string;
1012
+ createdAt: number;
1013
+ }>;
1014
+ list(className?: string): Array<{
1015
+ className: string;
1016
+ name: string;
1017
+ createdAt: number;
1018
+ }>;
1019
+ }
292
1020
  //#endregion
293
1021
  //#region src/core/events.d.ts
294
1022
  interface Disposable {
@@ -3162,7 +3890,7 @@ type RunAgentToolResult<Output = unknown> = {
3162
3890
  */
3163
3891
  childStillRunning?: boolean;
3164
3892
  };
3165
- type ChatCapableAgentClass<T extends Agent = Agent> = SubAgentClass<T>;
3893
+ type ChatCapableAgentClass<T extends Agent = Agent> = DynamicAgentClass<T>;
3166
3894
  type AgentToolRunInspection<Output = unknown> = {
3167
3895
  runId: string;
3168
3896
  status: Exclude<AgentToolRunStatus, "interrupted">;
@@ -3355,114 +4083,6 @@ type RPCResponse = {
3355
4083
  error: string;
3356
4084
  }
3357
4085
  );
3358
- /**
3359
- * Metadata for a callable method
3360
- */
3361
- type CallableMetadata = {
3362
- /** Optional description of what the method does */ description?: string /** Whether the method supports streaming responses */;
3363
- streaming?: boolean;
3364
- };
3365
- type SubAgentConnectionMeta = {
3366
- id: string;
3367
- uri: string | null;
3368
- tags: string[];
3369
- state: unknown;
3370
- requestHeaders?: [string, string][];
3371
- };
3372
- type SubAgentConnectionBridgeLike = {
3373
- send(message: string | ArrayBuffer | ArrayBufferView): void | Promise<void>;
3374
- close(code?: number, reason?: string): void | Promise<void>;
3375
- setState(state: unknown): unknown | Promise<unknown>;
3376
- broadcast(
3377
- ownerPath: ReadonlyArray<{
3378
- className: string;
3379
- name: string;
3380
- }>,
3381
- message: string | ArrayBuffer | ArrayBufferView,
3382
- without?: string[]
3383
- ): void | Promise<void>;
3384
- };
3385
- declare class SubAgentConnectionBridge
3386
- extends RpcTarget
3387
- implements SubAgentConnectionBridgeLike
3388
- {
3389
- #private;
3390
- constructor(
3391
- connection: Connection,
3392
- broadcast?: (
3393
- ownerPath: ReadonlyArray<{
3394
- className: string;
3395
- name: string;
3396
- }>,
3397
- message: string | ArrayBuffer | ArrayBufferView,
3398
- without?: string[]
3399
- ) => void | Promise<void>
3400
- );
3401
- send(message: string | ArrayBuffer | ArrayBufferView): void;
3402
- close(code?: number, reason?: string): void;
3403
- setState(state: unknown): unknown;
3404
- broadcast(
3405
- ownerPath: ReadonlyArray<{
3406
- className: string;
3407
- name: string;
3408
- }>,
3409
- message: string | ArrayBuffer | ArrayBufferView,
3410
- without?: string[]
3411
- ): void | Promise<void>;
3412
- }
3413
- /**
3414
- * Constructor type for a sub-agent class.
3415
- * Used by {@link Agent.subAgent} to reference the child class
3416
- * via `ctx.exports`.
3417
- *
3418
- * The class name (`cls.name`) must match the export name in the
3419
- * worker entry point — re-exports under a different name
3420
- * (e.g. `export { Foo as Bar }`) are not supported.
3421
- */
3422
- type SubAgentClass<T extends Agent = Agent> = {
3423
- new (ctx: DurableObjectState, env: never): T;
3424
- };
3425
- /**
3426
- * Wraps `T` in a `Promise` unless it already is one.
3427
- */
3428
- type Promisify<T> = T extends Promise<unknown> ? T : Promise<T>;
3429
- /**
3430
- * A typed RPC stub for a sub-agent. Exposes all public instance methods
3431
- * as callable RPC methods with Promise-wrapped return types.
3432
- *
3433
- * Methods owned by `Agent`, its lifecycle, or `DurableObject` internals
3434
- * are excluded — only user-defined methods on the subclass are exposed.
3435
- */
3436
- type SubAgentStub<T extends Agent> = {
3437
- [K in keyof T as K extends keyof Agent
3438
- ? never
3439
- : T[K] extends (...args: never[]) => unknown
3440
- ? K
3441
- : never]: T[K] extends (...args: infer A) => infer R
3442
- ? (...args: A) => Promisify<R>
3443
- : never;
3444
- };
3445
- /**
3446
- * Decorator that marks a method as callable by clients
3447
- * @param metadata Optional metadata about the callable method
3448
- */
3449
- declare function callable(
3450
- metadata?: CallableMetadata
3451
- ): <This, Args extends unknown[], Return>(
3452
- target: (this: This, ...args: Args) => Return,
3453
- _context: ClassMethodDecoratorContext
3454
- ) => (this: This, ...args: Args) => Return;
3455
- /**
3456
- * Decorator that marks a method as callable by clients
3457
- * @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
3458
- * @param metadata Optional metadata about the callable method
3459
- */
3460
- declare const unstable_callable: (
3461
- metadata?: CallableMetadata
3462
- ) => <This, Args extends unknown[], Return>(
3463
- target: (this: This, ...args: Args) => Return,
3464
- _context: ClassMethodDecoratorContext
3465
- ) => (this: This, ...args: Args) => Return;
3466
4086
  type QueueItem<T = string> = {
3467
4087
  id: string;
3468
4088
  payload: T;
@@ -3859,6 +4479,17 @@ declare class Agent<
3859
4479
  * @experimental The API surface may change before stabilizing.
3860
4480
  */
3861
4481
  readonly lifecycle: Lifecycle<Env, Props>;
4482
+ /**
4483
+ * WebSocket connection subsystem. Constructed as a field initializer
4484
+ * so it exists before the constructor installs it; the handler arrows
4485
+ * defer to `this.*`, so they always hit the framework-wrapped hooks.
4486
+ * Those wrappers still open their own invocation scope even though
4487
+ * the capability's dispatch already entered one via the host invoker
4488
+ * — the inner wrap is kept because the wrapped hooks are also invoked
4489
+ * from paths that do not pass through the capability (facet bridging,
4490
+ * direct calls).
4491
+ */
4492
+ private readonly _webSockets;
3862
4493
  /** Run user initialization after lifecycle components have started. */
3863
4494
  onStart(_props?: Props): void | Promise<void>;
3864
4495
  /** Handle an HTTP request not claimed by a lifecycle component. */
@@ -3903,10 +4534,6 @@ declare class Agent<
3903
4534
  /** True when this agent runs as a facet (sub-agent) inside a parent. */
3904
4535
  private _isFacet;
3905
4536
  private _protocolBroadcastExcludeIds;
3906
- private _cf_subAgentBridgeContext;
3907
- private _cf_virtualSubAgentConnections;
3908
- private _cf_subAgentConnectionOperationTails;
3909
- private _cf_subAgentBroadcastOperationTail?;
3910
4537
  /**
3911
4538
  * User-facing facet name. For legacy facets this is the same as
3912
4539
  * `ctx.id.name`; path-scoped facets use an internal routing id and
@@ -3924,20 +4551,39 @@ declare class Agent<
3924
4551
  /** Warn-once guard: `chatRecovery` reassigned during onStart() (too late for wake recovery). */
3925
4552
  private _warnedChatRecoveryInOnStart;
3926
4553
  /**
3927
- * Number of active keepAlive() callers. When > 0, `_rearmAlarm()`
4554
+ * Number of active keepAlive() callers. When > 0, `_syncHostJobs()`
3928
4555
  * caps the next alarm at `keepAliveIntervalMs` so the DO stays alive.
3929
4556
  * Purely in-memory — lost on eviction, which is correct because the
3930
4557
  * in-memory work keepAlive was protecting is also lost.
3931
4558
  * @internal
3932
4559
  */
3933
4560
  _keepAliveRefs: number;
4561
+ /** @internal The extracted dynamic-agent (facet) machinery. */
4562
+ private _dynamicAgentsInstance;
4563
+ /** @internal */
4564
+ private get _dynamicAgents();
4565
+ /** @internal */
4566
+ private _dynamicAgentsApi;
3934
4567
  /**
3935
- * In-memory tokens for keepAlive leases acquired by facets and held
3936
- * on the root alarm owner. Lost on eviction, like `_keepAliveRefs`,
3937
- * because the in-memory work those leases were protecting is also gone.
3938
- * @internal
4568
+ * The dynamic-agents capability: facet-backed child agents that run
4569
+ * in their own isolate with their own SQLite database, colocated
4570
+ * with and supervised by this agent.
4571
+ *
4572
+ * Use dynamic agents for code whose class or lifecycle this agent
4573
+ * owns: dynamically-loaded or AI-generated code, per-run tool
4574
+ * agents, sandboxed components. For independent peers (for example
4575
+ * one Durable Object per chat), use `getAgentByName` instead.
4576
+ *
4577
+ * ```ts
4578
+ * const child = await this.dynamicAgents.get(Researcher, id);
4579
+ * await child.doWork();
4580
+ * this.dynamicAgents.abort(Researcher, id, reason);
4581
+ * await this.dynamicAgents.delete(Researcher, id);
4582
+ * ```
4583
+ *
4584
+ * @experimental The API surface may change before stabilizing.
3939
4585
  */
3940
- private _facetKeepAliveTokens;
4586
+ get dynamicAgents(): DynamicAgents;
3941
4587
  /** @internal In-memory set of fiber IDs running in this process. */
3942
4588
  private _runFiberActiveFibers;
3943
4589
  /** @internal In-memory abort controllers for managed running fibers. */
@@ -3970,6 +4616,32 @@ declare class Agent<
3970
4616
  * cancelSchedule() methods are the stable surface.
3971
4617
  */
3972
4618
  readonly scheduler: Scheduler;
4619
+ /**
4620
+ * Durable replayable execution capability installed into this Agent's
4621
+ * Lifecycle. Declare definitions on the overridable
4622
+ * {@link taskDefinitions} property and start runs with
4623
+ * `this.tasks.run(name, input, options)`.
4624
+ *
4625
+ * @experimental The API surface may change before stabilizing.
4626
+ */
4627
+ readonly tasks: Tasks;
4628
+ /**
4629
+ * Named Task definitions for this Agent, resolved lazily on every
4630
+ * dispatch. Declare as a field so the map is rebuilt on every Durable
4631
+ * Object wake — that is what lets in-flight runs resolve their persisted
4632
+ * definition names after a restart:
4633
+ *
4634
+ * ```ts
4635
+ * readonly taskDefinitions = {
4636
+ * "build-report@v1": async (input: ReportInput, step: TaskStep) => {
4637
+ * // ...
4638
+ * }
4639
+ * } satisfies TaskHandlers;
4640
+ * ```
4641
+ *
4642
+ * @experimental The API surface may change before stabilizing.
4643
+ */
4644
+ readonly taskDefinitions?: TaskHandlers;
3973
4645
  readonly mcp: MCPClientManager;
3974
4646
  /**
3975
4647
  * Initial state for the Agent
@@ -4345,8 +5017,6 @@ declare class Agent<
4345
5017
  * @returns Array of matching QueueItem objects
4346
5018
  */
4347
5019
  getQueues(key: string, value: string): QueueItem<string>[];
4348
- private _facetRunRowsForPrefix;
4349
- private _deleteFacetRunRowsForPrefix;
4350
5020
  private _lifecycleRouteAddress;
4351
5021
  private _routeLifecycleToRoot;
4352
5022
  private _routeLifecycleToTarget;
@@ -4356,7 +5026,6 @@ declare class Agent<
4356
5026
  envelope: LifecycleRouteEnvelope
4357
5027
  ): Promise<unknown>;
4358
5028
  private _rootAlarmOwner;
4359
- private _cf_rootResolvesToSelf;
4360
5029
  /**
4361
5030
  * Clean root-owned bookkeeping for a sub-tree of facets. This
4362
5031
  * bulk-cancels schedules whose `owner_path` starts with the given
@@ -4372,8 +5041,8 @@ declare class Agent<
4372
5041
  ): Promise<void>;
4373
5042
  /**
4374
5043
  * Acquire a root-owned keepAlive ref on behalf of a descendant facet.
4375
- * Facets share the root isolate but cannot set their own physical
4376
- * alarm, so this lets facet work use the root alarm heartbeat.
5044
+ * Facets run in separate colocated isolates but cannot set their own
5045
+ * physical alarm, so this lets facet work use the root alarm heartbeat.
4377
5046
  * @internal
4378
5047
  */
4379
5048
  _cf_acquireFacetKeepAlive(
@@ -4429,10 +5098,7 @@ declare class Agent<
4429
5098
  when: Date | string | number,
4430
5099
  callback: keyof this,
4431
5100
  payload?: T,
4432
- options?: {
4433
- retry?: RetryOptions;
4434
- idempotent?: boolean;
4435
- }
5101
+ options?: ScheduleOptions
4436
5102
  ): Promise<Schedule<T>>;
4437
5103
  /**
4438
5104
  * Schedule a task to run repeatedly at a fixed interval.
@@ -4636,6 +5302,20 @@ declare class Agent<
4636
5302
  * Throws if called outside a `runFiber` callback.
4637
5303
  */
4638
5304
  stash(data: unknown): void;
5305
+ /**
5306
+ * Run `fn` inside the fiber stash context so `this.stash()` keeps working
5307
+ * for turns executing on the `tasks` capability exactly as it does inside
5308
+ * legacy `runFiber()` closures.
5309
+ * @internal
5310
+ */
5311
+ protected _withFiberStash<T>(
5312
+ context: {
5313
+ id: string;
5314
+ signal: AbortSignal;
5315
+ stash: (data: unknown) => void;
5316
+ },
5317
+ fn: () => Promise<T>
5318
+ ): Promise<T>;
4639
5319
  /**
4640
5320
  * Called when an interrupted fiber is detected after restart.
4641
5321
  * Override to implement recovery (re-invoke work, notify clients, etc.).
@@ -4710,80 +5390,71 @@ declare class Agent<
4710
5390
  * executing in memory, which already hold a keepAlive ref) or managed
4711
5391
  * ledger fibers stuck in a non-terminal state with no live run row.
4712
5392
  *
4713
- * Used by `_rearmAlarm` to arm a follow-up alarm so multi-pass
5393
+ * Used by `_syncHostJobs` to arm a follow-up alarm so multi-pass
4714
5394
  * recovery (e.g. after a scan-deadline yield, or while retrying a throwing
4715
5395
  * recovery hook) resumes instead of starving.
4716
5396
  * @internal
4717
5397
  */
4718
5398
  private _hasPendingFiberRecovery;
4719
- private _rearmAlarm;
4720
- /**
4721
- * Contribute Agent-owned alarm work that has not yet been extracted into its
4722
- * own capability. Scheduler contributes independently.
4723
- * @internal
4724
- */
4725
- getNextAlarm(): Promise<AlarmContribution>;
4726
- /** @internal Transitional alarm contribution for Agent subclasses. */
4727
- protected _getExtensionAlarm(): number | null | Promise<number | null>;
4728
- /** Lifecycle alarm callback; Agent housekeeping runs after user alarm work. */
4729
- onAlarm(): void;
4730
5399
  /**
4731
- * Run Lifecycle's alarm phase inside Agent's memory-limit circuit breaker.
5400
+ * Synchronize Agent-owned host jobs with current durable state.
4732
5401
  *
4733
- * @remarks Use `this.schedule()` for named Agent callbacks. Reusable durable
4734
- * work belongs in a capability with `getNextAlarm()` and `onAlarm()`.
5402
+ * Replaces the old pull-based `getNextAlarm()` contribution: keep-alive
5403
+ * refs hold a `cf:keep-alive` job, and fiber-recovery / facet-run state
5404
+ * holds a `cf:housekeeping` job. Every state change that used to trigger
5405
+ * an alarm recalculation now re-pushes or cancels these jobs; queue
5406
+ * mutations re-arm the physical alarm automatically.
5407
+ * @internal
4735
5408
  */
4736
- alarm(): Promise<void>;
4737
- /** Run the Lifecycle alarm phase inside Agent's OOM circuit breaker. */
4738
- private _cf_runAlarmBody;
5409
+ private _syncHostJobs;
4739
5410
  /**
4740
- * Durable storage key for the alarm memory-limit strike counter (#1825).
5411
+ * The next wake fiber-recovery or facet-run housekeeping needs, or `null`
5412
+ * when neither has pending durable state.
4741
5413
  */
4742
- private static readonly _CF_OOM_ALARM_STRIKES_KEY;
5414
+ private _nextHousekeepingWakeMs;
5415
+ /** Lifecycle alarm callback; Agent housekeeping runs after user alarm work. */
5416
+ onAlarm(): void;
4743
5417
  /**
4744
- * The schedule-callback names whose alarm rows drive a recovery loop that can
4745
- * deterministically OOM. The base agent has none; chat hosts (`Think`,
4746
- * `AIChatAgent`) override this to return their recovery continuation callbacks
4747
- * so the circuit breaker can surgically back them off / purge them WITHOUT
4748
- * disturbing unrelated scheduled tasks. See {@link _cf_handleAlarmMemoryLimitReset}.
5418
+ * Drive one Agent-owned host job from the Lifecycle queue.
5419
+ * @internal Dispatched by Lifecycle's alarm event loop; extensions add
5420
+ * job fns through {@link _onHostJob}.
4749
5421
  */
4750
- protected _cf_recoveryAlarmCallbacks(): string[];
5422
+ onJob(
5423
+ context: LifecycleJobContext
5424
+ ): LifecycleJobOutcome | void | Promise<LifecycleJobOutcome | void>;
4751
5425
  /**
4752
- * Hook for a host to terminalize ("seal") any in-flight recovery work as an
4753
- * out-of-memory exhaustion when the alarm circuit breaker trips at its strike
4754
- * budget (#1825). Runs at the outermost alarm frame (post-unwind, so writes
4755
- * can land). Default: no-op. Chat hosts override to fire `onExhausted` + the
4756
- * terminal banner and persist the sealed incident.
5426
+ * @internal Dispatch one host job fn. Agent extensions (Think) override
5427
+ * this to add fns and delegate unknown ones to `super`.
4757
5428
  */
4758
- protected _cf_sealMemoryLimitedRecovery(): Promise<void>;
5429
+ protected _onHostJob(
5430
+ fn: string,
5431
+ _context: LifecycleJobContext
5432
+ ): LifecycleJobOutcome | void | Promise<LifecycleJobOutcome | void>;
4759
5433
  /**
4760
- * Clear the durable memory-limit strike counter after a clean alarm so the
4761
- * circuit breaker counts CONSECUTIVE resets rather than lifetime ones
4762
- * (#1825). Reads first (cheap, usually cached) and only writes when a strike
4763
- * is actually recorded, so the common no-strike path costs no write.
4764
- * Best-effort: a stale strike only costs one extra tolerated spike later.
5434
+ * Apply host policy after the alarm memory-limit breaker records a strike.
5435
+ *
5436
+ * New chat hosts override this hook directly. The sealed-only fallback keeps
5437
+ * `agents` 0.23 compatible with already-published chat packages whose peer
5438
+ * ranges accept it but which implement only the former
5439
+ * `_cf_sealMemoryLimitedRecovery` template method. Queue membership remains
5440
+ * job-row policy; this invokes terminalization only and can be removed once
5441
+ * old chat releases no longer accept the current `agents` range.
5442
+ *
5443
+ * @internal
4765
5444
  */
4766
- private _cf_clearAlarmMemoryLimitStrikes;
5445
+ protected onAlarmMemoryLimit(context: MemoryLimitContext): Promise<void>;
4767
5446
  /**
4768
- * Alarm-boundary circuit breaker for Durable Object memory-limit resets
4769
- * (#1825). The in-DO recovery budgets (`chatRecovery.maxOomRetries` /
4770
- * `maxRecoveryWork`) only engage if their code runs AND its writes land; a
4771
- * severe OOM can defeat both — thrown before the budget runs (boot hydration),
4772
- * or its own small writes also OOM under memory pressure. In that case the
4773
- * error reaches {@link alarm} and, unhandled, the platform auto-retries the
4774
- * alarm indefinitely (re-running the doomed, billable turn each cycle).
5447
+ * Run Lifecycle's alarm event loop after the pending-destroy preamble.
4775
5448
  *
4776
- * This runs at the OUTERMOST frame: the heavy turn has unwound and GC has
4777
- * reclaimed its footprint, so the small writes here can land where mid-turn
4778
- * ones (e.g. give-up's incident read) OOMed. A durable strike counter tolerates
4779
- * a few resets (a transient spike may clear), backing off the recovery rows so
4780
- * the retry is not a hot loop. At the `maxAlarmMemoryLimitStrikes` budget it
4781
- * seals the recovery work and purges the looping rows so the loop — and the
4782
- * bill stops. Each step is best-effort: even these tiny writes can OOM, but
4783
- * swallowing (not re-throwing) still halts the platform's auto-retry, and a
4784
- * later wake re-arms legitimate schedules.
5449
+ * The alarm memory-limit circuit breaker (#1825) lives inside
5450
+ * `Lifecycle.alarm()`; capabilities and hosts opt into extra domain
5451
+ * policy via their `onMemoryLimit` / `onAlarmMemoryLimit` hooks and the
5452
+ * `recoveryLoop` schedule option.
5453
+ *
5454
+ * @remarks Use `this.schedule()` for named Agent callbacks. Reusable durable
5455
+ * work belongs in a capability that pushes jobs and implements `onJob()`.
4785
5456
  */
4786
- private _cf_handleAlarmMemoryLimitReset;
5457
+ alarm(): Promise<void>;
4787
5458
  /**
4788
5459
  * Intercept incoming HTTP/WS requests whose URL contains a
4789
5460
  * `/sub/{child-class}/{child-name}` marker and forward them to
@@ -4792,9 +5463,9 @@ declare class Agent<
4792
5463
  * Response, the framework resolves the facet and hands the
4793
5464
  * request off.
4794
5465
  *
4795
- * After a WebSocket upgrade completes, subsequent frames route
4796
- * directly to the child the parent is only on the path for the
4797
- * initial request.
5466
+ * The parent owns an upgraded WebSocket for its lifetime. Subsequent
5467
+ * frames wake the root parent, which forwards them to the child over
5468
+ * RPC and routes replies back to the native socket.
4798
5469
  *
4799
5470
  * @experimental The API surface may change before stabilizing.
4800
5471
  */
@@ -4805,25 +5476,6 @@ declare class Agent<
4805
5476
  ): void;
4806
5477
  getConnection<TState = unknown>(id: string): Connection<TState> | undefined;
4807
5478
  getConnections<TState = unknown>(tag?: string): Iterable<Connection<TState>>;
4808
- private _cf_activeSubAgentBridge;
4809
- /**
4810
- * Route a virtual sub-agent connection operation through its live frame
4811
- * bridge, or through the durable root Agent after that frame completes.
4812
- * All operations share one per-connection queue. Facet broadcasts wait for
4813
- * older queued operations; failures do not block later work.
4814
- */
4815
- private _cf_routeSubAgentConnectionOperation;
4816
- /**
4817
- * Route a facet broadcast after every older connection operation.
4818
- *
4819
- * This barrier is intentionally one-way: facet startup can broadcast before
4820
- * a child connection has finished initializing its tags and protocol flags.
4821
- * Making those later connection operations wait would let the next frame
4822
- * observe stale root-owned metadata.
4823
- */
4824
- private _cf_routeSubAgentBroadcast;
4825
- private _cf_reportSubAgentConnectionOperationFailure;
4826
- private _cf_broadcastToParentSubAgent;
4827
5479
  _cf_broadcastToSubAgent(
4828
5480
  ownerPath: ReadonlyArray<AgentPathStep>,
4829
5481
  message: string | ArrayBuffer | ArrayBufferView,
@@ -4831,7 +5483,7 @@ declare class Agent<
4831
5483
  ): Promise<void>;
4832
5484
  _cf_subAgentConnectionMetas(
4833
5485
  ownerPath: ReadonlyArray<AgentPathStep>
4834
- ): Promise<SubAgentConnectionMeta[]>;
5486
+ ): Promise<DynamicAgentConnectionMeta[]>;
4835
5487
  _cf_sendToSubAgentConnection(
4836
5488
  connectionId: string,
4837
5489
  message: string | ArrayBuffer | ArrayBufferView
@@ -4845,11 +5497,6 @@ declare class Agent<
4845
5497
  connectionId: string,
4846
5498
  state: unknown
4847
5499
  ): Promise<unknown>;
4848
- private _cf_subAgentConnectionMetaForPath;
4849
- private _cf_subAgentTargetPath;
4850
- private _cf_subAgentPathFromOuterUri;
4851
- private _isSameAgentPath;
4852
- private _cf_connectionHasSubAgentTarget;
4853
5500
  protected _cf_connectionTargetsSubAgent(connection: Connection): boolean;
4854
5501
  /**
4855
5502
  * Returns true when the current request is addressed to a child facet of
@@ -4861,33 +5508,26 @@ declare class Agent<
4861
5508
  */
4862
5509
  protected _cf_requestTargetsSubAgent(request: Request): boolean;
4863
5510
  private _cf_forwardSubAgentWebSocketConnect;
4864
- private _cf_createSubAgentConnectionBridge;
4865
5511
  private _cf_forwardSubAgentWebSocketMessage;
4866
5512
  private _cf_forwardSubAgentWebSocketClose;
4867
- private _cf_resolveSubAgentConnection;
4868
5513
  _cf_handleSubAgentWebSocketConnect(
4869
- bridge: SubAgentConnectionBridge,
4870
- meta: SubAgentConnectionMeta
5514
+ bridge: DynamicAgentConnectionBridge,
5515
+ meta: DynamicAgentConnectionMeta
4871
5516
  ): Promise<void>;
4872
5517
  _cf_handleSubAgentWebSocketMessage(
4873
5518
  message: WSMessage,
4874
- bridge: SubAgentConnectionBridge,
4875
- meta: SubAgentConnectionMeta,
4876
- replyBridge?: SubAgentConnectionBridge
5519
+ bridge: DynamicAgentConnectionBridge,
5520
+ meta: DynamicAgentConnectionMeta,
5521
+ replyBridge?: DynamicAgentConnectionBridge
4877
5522
  ): Promise<void>;
4878
5523
  _cf_handleSubAgentWebSocketClose(
4879
5524
  code: number,
4880
5525
  reason: string,
4881
5526
  wasClean: boolean,
4882
- bridge: SubAgentConnectionBridge,
4883
- meta: SubAgentConnectionMeta
5527
+ bridge: DynamicAgentConnectionBridge,
5528
+ meta: DynamicAgentConnectionMeta
4884
5529
  ): Promise<void>;
4885
- private _cf_runWithSubAgentBridge;
4886
- private _cf_createSubAgentBridgeConnection;
4887
- private _cf_storeVirtualSubAgentConnection;
4888
5530
  protected _cf_hydrateSubAgentConnectionsFromRoot(): Promise<void>;
4889
- private _cf_getRawConnectionState;
4890
- private _cf_getForwardedSubAgentState;
4891
5531
  /**
4892
5532
  * Parent-side middleware hook. Fires before a request is
4893
5533
  * forwarded into a facet sub-agent. Mirrors `onBeforeConnect` /
@@ -4923,7 +5563,7 @@ declare class Agent<
4923
5563
  * class Inbox extends Agent {
4924
5564
  * override async onBeforeSubAgent(req, { className, name }) {
4925
5565
  * // Strict registry gate
4926
- * if (!this.hasSubAgent(className, name)) {
5566
+ * if (!this.dynamicAgents.has(className, name)) {
4927
5567
  * return new Response("Not found", { status: 404 });
4928
5568
  * }
4929
5569
  * }
@@ -4973,7 +5613,6 @@ declare class Agent<
4973
5613
  method: string,
4974
5614
  args: unknown[]
4975
5615
  ): Promise<unknown>;
4976
- private _cf_invokeStubMethod;
4977
5616
  /**
4978
5617
  * Initialize this agent as a facet in a single RPC.
4979
5618
  *
@@ -5080,7 +5719,7 @@ declare class Agent<
5080
5719
  * ```
5081
5720
  */
5082
5721
  parentAgent<T extends Agent>(
5083
- cls: SubAgentClass<T>
5722
+ cls: DynamicAgentClass<T>
5084
5723
  ): Promise<DurableObjectStub<T>>;
5085
5724
  private _cf_getTopLevelNamespaceByClassName;
5086
5725
  private _cf_asDurableObjectNamespace;
@@ -5105,11 +5744,13 @@ declare class Agent<
5105
5744
  * const searcher = await this.subAgent(SearchAgent, "main-search");
5106
5745
  * const results = await searcher.search("cloudflare agents");
5107
5746
  * ```
5747
+ *
5748
+ * @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.get()} instead.
5108
5749
  */
5109
5750
  subAgent<T extends Agent>(
5110
- cls: SubAgentClass<T>,
5751
+ cls: DynamicAgentClass<T>,
5111
5752
  name: string
5112
- ): Promise<SubAgentStub<T>>;
5753
+ ): Promise<DynamicAgentStub<T>>;
5113
5754
  /** Maximum number of non-terminal agent-tool runs this parent may own at once. */
5114
5755
  maxConcurrentAgentTools: number;
5115
5756
  onAgentToolStart(_run: AgentToolRunInfo): Promise<void>;
@@ -5244,7 +5885,7 @@ declare class Agent<
5244
5885
  */
5245
5886
  _cfDetachedReconcileTick(payload?: DetachedReconcilePayload): Promise<void>;
5246
5887
  hasAgentToolRun<T extends Agent>(
5247
- cls: SubAgentClass<T>,
5888
+ cls: DynamicAgentClass<T>,
5248
5889
  runId: string
5249
5890
  ): boolean;
5250
5891
  hasAgentToolRun(agentType: string, runId: string): boolean;
@@ -5398,6 +6039,13 @@ declare class Agent<
5398
6039
  * @internal
5399
6040
  */
5400
6041
  private _cf_resolveSubAgent;
6042
+ /**
6043
+ * Run `body` in a fresh invocation scope with no native request/
6044
+ * connection context attached, so a child-facet RPC never sees
6045
+ * parent-owned I/O handles.
6046
+ * @internal
6047
+ */
6048
+ private _runFacetInitInvocation;
5401
6049
  /**
5402
6050
  * Forcefully abort a running sub-agent. The child stops executing
5403
6051
  * immediately and will be restarted on next {@link subAgent} call.
@@ -5409,8 +6057,10 @@ declare class Agent<
5409
6057
  * @param cls The Agent subclass used when creating the child
5410
6058
  * @param name Name of the child to abort
5411
6059
  * @param reason Error thrown to pending/future RPC callers
6060
+ *
6061
+ * @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.abort()} instead.
5412
6062
  */
5413
- abortSubAgent(cls: SubAgentClass, name: string, reason?: unknown): void;
6063
+ abortSubAgent(cls: DynamicAgentClass, name: string, reason?: unknown): void;
5414
6064
  /**
5415
6065
  * Delete a sub-agent: abort it if running, then permanently wipe its
5416
6066
  * storage. Transitively deletes the child's own children.
@@ -5419,20 +6069,10 @@ declare class Agent<
5419
6069
  *
5420
6070
  * @param cls The Agent subclass used when creating the child
5421
6071
  * @param name Name of the child to delete
6072
+ *
6073
+ * @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.delete()} instead.
5422
6074
  */
5423
- deleteSubAgent(cls: SubAgentClass, name: string): Promise<void>;
5424
- /** @internal */
5425
- private _subAgentRegistryReady;
5426
- private _addColumnIfNotExists;
5427
- /** @internal */
5428
- private _ensureSubAgentRegistry;
5429
- /** @internal */
5430
- private _recordSubAgent;
5431
- /** @internal */
5432
- private _subAgentRegistryRow;
5433
- private _cf_subAgentIdentity;
5434
- /** @internal */
5435
- private _forgetSubAgent;
6075
+ deleteSubAgent(cls: DynamicAgentClass, name: string): Promise<void>;
5436
6076
  /**
5437
6077
  * Whether this agent has previously spawned (and not deleted) a
5438
6078
  * sub-agent of the given class and name. Backed by an
@@ -5451,8 +6091,13 @@ declare class Agent<
5451
6091
  * }
5452
6092
  * }
5453
6093
  * ```
6094
+ *
6095
+ * @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.has()} instead.
5454
6096
  */
5455
- hasSubAgent<T extends Agent>(cls: SubAgentClass<T>, name: string): boolean;
6097
+ hasSubAgent<T extends Agent>(
6098
+ cls: DynamicAgentClass<T>,
6099
+ name: string
6100
+ ): boolean;
5456
6101
  hasSubAgent(className: string, name: string): boolean;
5457
6102
  /**
5458
6103
  * List known sub-agents, optionally filtered by class. Reflects
@@ -5460,9 +6105,11 @@ declare class Agent<
5460
6105
  * {@link deleteSubAgent}.
5461
6106
  *
5462
6107
  * @experimental The API surface may change before stabilizing.
6108
+ *
6109
+ * @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.list()} instead.
5463
6110
  */
5464
6111
  listSubAgents<T extends Agent>(
5465
- cls: SubAgentClass<T>
6112
+ cls: DynamicAgentClass<T>
5466
6113
  ): Array<{
5467
6114
  className: string;
5468
6115
  name: string;
@@ -6168,147 +6815,144 @@ declare function getAgentByName<
6168
6815
  ): Promise<DurableObjectStub<T>>;
6169
6816
  //#endregion
6170
6817
  export {
6171
- AgentToolRunPart as $,
6172
- MCPElicitationHandlers as $t,
6173
- StateUpdateMessage as A,
6174
- buildSubAgentPathUnchecked as An,
6175
- WorkflowRejectedError as At,
6176
- AgentToolChildAdapter as B,
6177
- MCPClientManagerOptions as Bt,
6178
- MCPServerMessage as C,
6179
- AgentPathStep as Cn,
6180
- WorkflowErrorCallback as Ct,
6181
- RPCResponse as D,
6182
- buildAgentPath as Dn,
6183
- WorkflowPage as Dt,
6184
- RPCRequest as E,
6185
- SubAgentPathMatch as En,
6186
- WorkflowInfo as Et,
6187
- getCurrentAgent as F,
6188
- MCPAITool as Ft,
6189
- AgentToolFailure as G,
6190
- MCPOAuthCallbackResult as Gt,
6191
- AgentToolEvent as H,
6192
- MCPClientOAuthResult as Ht,
6193
- routeAgentEmail as I,
6194
- MCPAIToolSet as It,
6195
- AgentToolMilestone as J,
6196
- MCP_SERVER_ID_MAX_LENGTH as Jt,
6197
- AgentToolInterruptedReason as K,
6198
- MCPServerFilter as Kt,
6199
- unstable_callable as L,
6200
- MCPClientElicitationHandler as Lt,
6201
- SubAgentClass as M,
6202
- parseSubAgentPath as Mn,
6203
- WorkflowTrackingRow as Mt,
6204
- SubAgentStub as N,
6205
- routeSubAgentRequest as Nn,
6206
- ElicitRequest$1 as Nt,
6207
- StartFiberOptions as O,
6208
- buildAgentUrl as On,
6209
- WorkflowProgressCallback as Ot,
6210
- callable as P,
6211
- withInvocationScope as Pn,
6212
- ElicitResult$2 as Pt,
6213
- AgentToolRunInspection as Q,
6214
- MCPElicitationHandler as Qt,
6215
- AGENT_TOOL_MILESTONE_PART as R,
6216
- MCPClientElicitationHandlers as Rt,
6217
- MCPServer as S,
6218
- StreamableHTTPEdgeClientTransport as Sn,
6219
- WorkflowCompleteCallback as St,
6220
- QueueItem as T,
6221
- SUB_PREFIX as Tn,
6222
- WorkflowEventPayload as Tt,
6223
- AgentToolEventMessage as U,
6224
- MCPConnectionResult as Ut,
6225
- AgentToolDisplayMetadata as V,
6226
- MCPClientOAuthCallbackConfig as Vt,
6227
- AgentToolEventState as W,
6228
- MCPDiscoverResult as Wt,
6229
- AgentToolProgressSnapshot as X,
6230
- getNamespacedData as Xt,
6231
- AgentToolProgress as Y,
6232
- RegisterServerOptions as Yt,
6233
- AgentToolRunInfo as Z,
6234
- normalizeServerId as Zt,
6235
- FiberInspection as _,
6236
- MCPStorageApi as _n,
6237
- RunWorkflowOptions as _t,
6818
+ ChatCapableAgentClass as $,
6819
+ RPC_DO_PREFIX as $t,
6820
+ StreamingResponse as A,
6821
+ routeSubAgentRequest as An,
6822
+ MCPAITool as At,
6823
+ AgentToolFailure as B,
6824
+ MCPOAuthCallbackResult as Bt,
6825
+ MCPServersState as C,
6826
+ SubAgentPathMatch as Cn,
6827
+ WorkflowProgressCallback as Ct,
6828
+ StartFiberOptions as D,
6829
+ buildSubAgentPathUnchecked as Dn,
6830
+ WorkflowTrackingRow as Dt,
6831
+ RPCResponse as E,
6832
+ buildSubAgentPath as En,
6833
+ WorkflowStatus as Et,
6834
+ AgentToolChildAdapter as F,
6835
+ MCPClientManagerOptions as Ft,
6836
+ AgentToolProgressSnapshot as G,
6837
+ getNamespacedData as Gt,
6838
+ AgentToolLifecycleResult as H,
6839
+ MCPServerOptions as Ht,
6840
+ AgentToolDisplayMetadata as I,
6841
+ MCPClientOAuthCallbackConfig as It,
6842
+ AgentToolRunPart as J,
6843
+ MCPElicitationHandlers as Jt,
6844
+ AgentToolRunInfo as K,
6845
+ normalizeServerId as Kt,
6846
+ AgentToolEvent as L,
6847
+ MCPClientOAuthResult as Lt,
6848
+ routeAgentEmail as M,
6849
+ MCPClientElicitationHandler as Mt,
6850
+ AGENT_TOOL_MILESTONE_PART as N,
6851
+ MCPClientElicitationHandlers as Nt,
6852
+ StartFiberResult as O,
6853
+ getSubAgentByName as On,
6854
+ ElicitRequest$1 as Ot,
6855
+ AGENT_TOOL_PROGRESS_PART as P,
6856
+ MCPClientManager as Pt,
6857
+ AgentToolTerminalStatus as Q,
6858
+ RPCServerTransportOptions as Qt,
6859
+ AgentToolEventMessage as R,
6860
+ MCPConnectionResult as Rt,
6861
+ MCPServerMessage as S,
6862
+ SUB_PREFIX as Sn,
6863
+ WorkflowPage as St,
6864
+ RPCRequest as T,
6865
+ buildAgentUrl as Tn,
6866
+ WorkflowRejectedError as Tt,
6867
+ AgentToolMilestone as U,
6868
+ MCP_SERVER_ID_MAX_LENGTH as Ut,
6869
+ AgentToolInterruptedReason as V,
6870
+ MCPServerFilter as Vt,
6871
+ AgentToolProgress as W,
6872
+ RegisterServerOptions as Wt,
6873
+ AgentToolRunStatus as X,
6874
+ RPCClientTransportOptions as Xt,
6875
+ AgentToolRunState as Y,
6876
+ RPCClientTransport as Yt,
6877
+ AgentToolStoredChunk as Z,
6878
+ RPCServerTransport as Zt,
6879
+ FiberRecoveryContext as _,
6880
+ StreamableHTTPEdgeClientTransport as _n,
6881
+ WorkflowCompleteCallback as _t,
6238
6882
  routeAgentRequest as a,
6239
- ElicitRequest$2 as an,
6240
- DetachedAgentToolConfig as at,
6241
- FiberStatus as b,
6242
- WorkerTransportOptions as bn,
6243
- WorkflowCallbackBase as bt,
6883
+ DurableObjectEventStore as an,
6884
+ AgentWorkflowInternalParams as at,
6885
+ ListFibersOptions as b,
6886
+ AgentPathStep as bn,
6887
+ WorkflowEventPayload as bt,
6244
6888
  Agent as c,
6245
- McpAgent as cn,
6246
- RunAgentToolResult as ct,
6889
+ CreateLegacyMcpHandlerOptions as cn,
6890
+ AgentWorkflowPathStep as ct,
6247
6891
  AgentStaticOptions as d,
6248
- createMcpHandler$1 as dn,
6249
- AgentWorkflowOrigin as dt,
6250
- RPCClientTransport as en,
6251
- AgentToolRunState as et,
6252
- CallableMetadata as f,
6253
- experimental_createMcpHandler as fn,
6254
- AgentWorkflowParams as ft,
6255
- FiberContext as g,
6256
- createLegacyMcpHandler as gn,
6257
- DefaultProgress as gt,
6258
- EmailRoutingOptions as h,
6259
- LegacyMcpHandler as hn,
6260
- ApprovalEventPayload as ht,
6892
+ createLegacyMcpHandler as dn,
6893
+ DefaultProgress as dt,
6894
+ ElicitRequest$2 as en,
6895
+ DetachedAgentToolConfig as et,
6896
+ DEFAULT_AGENT_STATIC_OPTIONS as f,
6897
+ MCPStorageApi as fn,
6898
+ RunWorkflowOptions as ft,
6899
+ FiberInspection as g,
6900
+ SSEEdgeClientTransport as gn,
6901
+ WorkflowCallbackType as gt,
6902
+ FiberContext as h,
6903
+ WorkerTransportOptions as hn,
6904
+ WorkflowCallbackBase as ht,
6261
6905
  getAgentByName as i,
6262
- RPC_DO_PREFIX as in,
6263
- ChatCapableAgentClass as it,
6264
- StreamingResponse as j,
6265
- getSubAgentByName as jn,
6266
- WorkflowStatus as jt,
6267
- StartFiberResult as k,
6268
- buildSubAgentPath as kn,
6269
- WorkflowQueryCriteria as kt,
6906
+ ClearableEventStore as in,
6907
+ AgentWorkflowEvent as it,
6908
+ getCurrentAgent as j,
6909
+ withInvocationScope as jn,
6910
+ MCPAIToolSet as jt,
6911
+ StateUpdateMessage as k,
6912
+ parseSubAgentPath as kn,
6913
+ ElicitResult$2 as kt,
6270
6914
  AgentContext as l,
6271
- ClearableEventStore as ln,
6272
- AgentWorkflowEvent as lt,
6273
- DeleteFibersOptions as m,
6274
- CreateMcpHandlerOptions$1 as mn,
6275
- AgentWorkflowStep as mt,
6915
+ CreateMcpHandlerOptions$1 as ln,
6916
+ AgentWorkflowStep as lt,
6917
+ EmailRoutingOptions as m,
6918
+ WorkerTransport as mn,
6919
+ WorkflowCallback as mt,
6276
6920
  AgentOptions as n,
6277
- RPCServerTransport as nn,
6278
- AgentToolStoredChunk as nt,
6921
+ ElicitResult$3 as nn,
6922
+ RunAgentToolOptions as nt,
6279
6923
  AddMcpServerOptions as o,
6280
- ElicitRequestSchema as on,
6281
- DetachedRunAgentToolResult as ot,
6282
- DEFAULT_AGENT_STATIC_OPTIONS as p,
6283
- CreateLegacyMcpHandlerOptions as pn,
6284
- AgentWorkflowPathStep as pt,
6285
- AgentToolLifecycleResult as q,
6286
- MCPServerOptions as qt,
6924
+ createMcpHandler$1 as on,
6925
+ AgentWorkflowOrigin as ot,
6926
+ DeleteFibersOptions as p,
6927
+ TransportState as pn,
6928
+ WaitForApprovalOptions as pt,
6929
+ AgentToolRunInspection as q,
6930
+ MCPElicitationHandler as qt,
6287
6931
  RoutingRetryOptions as r,
6288
- RPCServerTransportOptions as rn,
6289
- AgentToolTerminalStatus as rt,
6932
+ McpAgent as rn,
6933
+ RunAgentToolResult as rt,
6290
6934
  AddRpcMcpServerOptions as s,
6291
- ElicitResult$3 as sn,
6292
- RunAgentToolOptions as st,
6935
+ experimental_createMcpHandler as sn,
6936
+ AgentWorkflowParams as st,
6293
6937
  AgentGetOptions as t,
6294
- RPCClientTransportOptions as tn,
6295
- AgentToolRunStatus as tt,
6938
+ ElicitRequestSchema as tn,
6939
+ DetachedRunAgentToolResult as tt,
6296
6940
  AgentNamespace as u,
6297
- DurableObjectEventStore as un,
6298
- AgentWorkflowInternalParams as ut,
6299
- FiberRecoveryContext as v,
6300
- TransportState as vn,
6301
- WaitForApprovalOptions as vt,
6302
- MCPServersState as w,
6303
- BuildAgentPathOptions as wn,
6304
- WorkflowEventCallback as wt,
6305
- ListFibersOptions as x,
6306
- SSEEdgeClientTransport as xn,
6307
- WorkflowCallbackType as xt,
6308
- FiberRecoveryResult as y,
6309
- WorkerTransport as yn,
6310
- WorkflowCallback as yt,
6311
- AGENT_TOOL_PROGRESS_PART as z,
6312
- MCPClientManager as zt
6941
+ LegacyMcpHandler as un,
6942
+ ApprovalEventPayload as ut,
6943
+ FiberRecoveryResult as v,
6944
+ DynamicAgentClass as vn,
6945
+ WorkflowErrorCallback as vt,
6946
+ QueueItem as w,
6947
+ buildAgentPath as wn,
6948
+ WorkflowQueryCriteria as wt,
6949
+ MCPServer as x,
6950
+ BuildAgentPathOptions as xn,
6951
+ WorkflowInfo as xt,
6952
+ FiberStatus as y,
6953
+ DynamicAgentStub as yn,
6954
+ WorkflowEventCallback as yt,
6955
+ AgentToolEventState as z,
6956
+ MCPDiscoverResult as zt
6313
6957
  };
6314
- //# sourceMappingURL=agent-routing-CnkaHb-v.d.ts.map
6958
+ //# sourceMappingURL=agent-routing-DE5zmCQ8.d.ts.map