agents 0.11.9 → 0.12.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 (43) hide show
  1. package/README.md +37 -1
  2. package/dist/{index-DSwOzhhd.d.ts → agent-tool-types-tBGRsPm0.d.ts} +584 -99
  3. package/dist/agent-tool-types.d.ts +34 -0
  4. package/dist/agent-tool-types.js +1 -0
  5. package/dist/agent-tools-BAdX1vdI.js +425 -0
  6. package/dist/agent-tools-BAdX1vdI.js.map +1 -0
  7. package/dist/agent-tools-CIO14miM.d.ts +14 -0
  8. package/dist/agent-tools.d.ts +68 -0
  9. package/dist/agent-tools.js +51 -0
  10. package/dist/agent-tools.js.map +1 -0
  11. package/dist/browser/ai.d.ts +1 -1
  12. package/dist/browser/ai.js +2 -2
  13. package/dist/browser/index.d.ts +1 -1
  14. package/dist/browser/index.js +1 -1
  15. package/dist/browser/tanstack-ai.d.ts +1 -1
  16. package/dist/browser/tanstack-ai.js +1 -1
  17. package/dist/chat/index.d.ts +3 -1
  18. package/dist/chat/index.js +3 -300
  19. package/dist/chat/index.js.map +1 -1
  20. package/dist/client.d.ts +2 -2
  21. package/dist/{compaction-helpers-C_cN3z55.js → compaction-helpers-CSaqCmdE.js} +1 -1
  22. package/dist/{compaction-helpers-C_cN3z55.js.map → compaction-helpers-CSaqCmdE.js.map} +1 -1
  23. package/dist/{compaction-helpers-YzCLvunJ.d.ts → compaction-helpers-D92Ipstp.d.ts} +1 -1
  24. package/dist/experimental/memory/session/index.d.ts +1 -1
  25. package/dist/experimental/memory/session/index.js +1 -1
  26. package/dist/experimental/memory/utils/index.d.ts +1 -1
  27. package/dist/experimental/memory/utils/index.js +1 -1
  28. package/dist/index.d.ts +74 -42
  29. package/dist/index.js +1393 -296
  30. package/dist/index.js.map +1 -1
  31. package/dist/mcp/client.d.ts +1 -1
  32. package/dist/mcp/index.d.ts +1 -1
  33. package/dist/react.d.ts +16 -2
  34. package/dist/react.js +42 -1
  35. package/dist/react.js.map +1 -1
  36. package/dist/{serializable-Bg8ARWlN.d.ts → serializable-Brg7fRds.d.ts} +1 -1
  37. package/dist/serializable.d.ts +1 -1
  38. package/dist/{shared-mfBbxjS1.js → shared-C6l4ZKRN.js} +1 -1
  39. package/dist/{shared-mfBbxjS1.js.map → shared-C6l4ZKRN.js.map} +1 -1
  40. package/dist/{shared-BUHZFGTk.d.ts → shared-Ch9slKdI.d.ts} +1 -1
  41. package/dist/sub-routing.d.ts +6 -6
  42. package/dist/workflows.d.ts +1 -1
  43. package/package.json +9 -4
@@ -16,6 +16,7 @@ import {
16
16
  } from "./workflow-types-DHs0L0KP.js";
17
17
  import { t as MessageType } from "./types-DAHCZC_W.js";
18
18
  import { r as EmailResolver } from "./email-X72-zjuq.js";
19
+ import { ToolSet, UIMessage } from "ai";
19
20
  import { RpcTarget } from "cloudflare:workers";
20
21
  import {
21
22
  Connection,
@@ -54,9 +55,8 @@ import {
54
55
  Resource,
55
56
  ResourceTemplate,
56
57
  ServerCapabilities,
57
- Tool
58
+ Tool as Tool$1
58
59
  } from "@modelcontextprotocol/sdk/types.js";
59
- import { ToolSet } from "ai";
60
60
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
61
61
  import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
62
62
  import {
@@ -615,7 +615,7 @@ declare class MCPClientConnection {
615
615
  connectionError: string | null;
616
616
  lastConnectedTransport: BaseTransportType | undefined;
617
617
  instructions?: string;
618
- tools: Tool[];
618
+ tools: Tool$1[];
619
619
  private _transport?;
620
620
  prompts: Prompt[];
621
621
  resources: Resource[];
@@ -675,7 +675,7 @@ declare class MCPClientConnection {
675
675
  * Notification handler registration for tools
676
676
  * Should only be called if serverCapabilities.tools exists
677
677
  */
678
- registerTools(): Promise<Tool[]>;
678
+ registerTools(): Promise<Tool$1[]>;
679
679
  /**
680
680
  * Notification handler registration for resources
681
681
  * Should only be called if serverCapabilities.resources exists
@@ -1517,7 +1517,7 @@ declare class MCPClientManager {
1517
1517
  }>;
1518
1518
  }
1519
1519
  type NamespacedData = {
1520
- tools: (Tool & {
1520
+ tools: (Tool$1 & {
1521
1521
  serverId: string;
1522
1522
  })[];
1523
1523
  prompts: (Prompt & {
@@ -1737,6 +1737,34 @@ type Schedule<T = string> = {
1737
1737
  intervalSeconds: number;
1738
1738
  }
1739
1739
  );
1740
+ type AgentPathStep = {
1741
+ className: string;
1742
+ name: string;
1743
+ };
1744
+ type ScheduleStorageRow = {
1745
+ id: string;
1746
+ callback: string;
1747
+ payload: string;
1748
+ type: "scheduled" | "delayed" | "cron" | "interval";
1749
+ time: number;
1750
+ delayInSeconds?: number;
1751
+ cron?: string;
1752
+ intervalSeconds?: number;
1753
+ retry?: RetryOptions;
1754
+ running?: number;
1755
+ execution_started_at?: number | null;
1756
+ retry_options?: string | null;
1757
+ owner_path?: string | null;
1758
+ owner_path_key?: string | null;
1759
+ };
1760
+ type ScheduleCriteria = {
1761
+ id?: string;
1762
+ type?: "scheduled" | "delayed" | "cron" | "interval";
1763
+ timeRange?: {
1764
+ start?: Date;
1765
+ end?: Date;
1766
+ };
1767
+ };
1740
1768
  /**
1741
1769
  * Context passed to the `runFiber` callback. Provides checkpoint
1742
1770
  * and identity for durable execution.
@@ -1774,7 +1802,7 @@ type MCPServersState = {
1774
1802
  servers: {
1775
1803
  [id: string]: MCPServer;
1776
1804
  };
1777
- tools: (Tool & {
1805
+ tools: (Tool$1 & {
1778
1806
  serverId: string;
1779
1807
  })[];
1780
1808
  prompts: (Prompt & {
@@ -1912,6 +1940,13 @@ declare class Agent<
1912
1940
  private _persistenceHookMode;
1913
1941
  /** True when this agent runs as a facet (sub-agent) inside a parent. */
1914
1942
  private _isFacet;
1943
+ /**
1944
+ * True only while the internal facet bootstrap RPC runs startup.
1945
+ * Startup may happen while the parent is handling a WebSocket
1946
+ * message, so protocol broadcasts must not touch any ambient
1947
+ * parent-owned WebSocket handles during this window.
1948
+ */
1949
+ private _suppressProtocolBroadcasts;
1915
1950
  /**
1916
1951
  * Ancestor chain, root-first. Empty for top-level DOs; populated at
1917
1952
  * facet init time from the parent's own `selfPath`. Exposed publicly
@@ -1931,6 +1966,13 @@ declare class Agent<
1931
1966
  * @internal
1932
1967
  */
1933
1968
  _keepAliveRefs: number;
1969
+ /**
1970
+ * In-memory tokens for keepAlive leases acquired by facets and held
1971
+ * on the root alarm owner. Lost on eviction, like `_keepAliveRefs`,
1972
+ * because the in-memory work those leases were protecting is also gone.
1973
+ * @internal
1974
+ */
1975
+ private _facetKeepAliveTokens;
1934
1976
  /** @internal In-memory set of fiber IDs running in this process. */
1935
1977
  private _runFiberActiveFibers;
1936
1978
  /** @internal Prevents re-entrant recovery from overlapping alarm ticks. */
@@ -2301,6 +2343,152 @@ declare class Agent<
2301
2343
  * @returns Array of matching QueueItem objects
2302
2344
  */
2303
2345
  getQueues(key: string, value: string): QueueItem<string>[];
2346
+ private _scheduleOwnerPathKey;
2347
+ private _facetRunRowsForPrefix;
2348
+ private _deleteFacetRunRowsForPrefix;
2349
+ private _rootAlarmOwner;
2350
+ private _validateScheduleCallback;
2351
+ /**
2352
+ * Insert (or, for idempotent calls, return the existing row for) a
2353
+ * schedule owned by either this top-level agent (`ownerPath === null`)
2354
+ * or a descendant facet. Returns `{ schedule, created }` — `created`
2355
+ * is `false` when an idempotent insert deduplicates onto an existing
2356
+ * row, so callers can suppress the `schedule:create` event in that
2357
+ * case to match historic semantics.
2358
+ * @internal
2359
+ */
2360
+ private _insertScheduleForOwner;
2361
+ /**
2362
+ * Insert a schedule row owned by a descendant facet. Called via RPC
2363
+ * from the facet's `schedule()`. Returns `{ schedule, created }`
2364
+ * so the originating facet can suppress `schedule:create` on
2365
+ * idempotent dedup. This method does not emit observability
2366
+ * events itself.
2367
+ * @internal
2368
+ */
2369
+ _cf_scheduleForFacet<T = string>(
2370
+ ownerPath: ReadonlyArray<AgentPathStep>,
2371
+ when: Date | string | number,
2372
+ callback: string,
2373
+ payload?: T,
2374
+ options?: {
2375
+ retry?: RetryOptions;
2376
+ idempotent?: boolean;
2377
+ }
2378
+ ): Promise<{
2379
+ schedule: Schedule<T>;
2380
+ created: boolean;
2381
+ }>;
2382
+ /**
2383
+ * Insert (or, for idempotent calls, return the existing row for) an
2384
+ * interval schedule. Mirrors {@link _insertScheduleForOwner} —
2385
+ * returns `{ schedule, created }` so callers can suppress
2386
+ * `schedule:create` on dedup.
2387
+ * @internal
2388
+ */
2389
+ private _insertIntervalScheduleForOwner;
2390
+ /**
2391
+ * Insert an interval schedule row owned by a descendant facet.
2392
+ * Called via RPC from the facet's `scheduleEvery()`. Returns
2393
+ * `{ schedule, created }` so the originating facet can suppress
2394
+ * `schedule:create` on idempotent dedup. This method does not
2395
+ * emit observability events itself.
2396
+ * @internal
2397
+ */
2398
+ _cf_scheduleEveryForFacet<T = string>(
2399
+ ownerPath: ReadonlyArray<AgentPathStep>,
2400
+ intervalSeconds: number,
2401
+ callback: string,
2402
+ payload?: T,
2403
+ options?: {
2404
+ retry?: RetryOptions;
2405
+ _idempotent?: boolean;
2406
+ }
2407
+ ): Promise<{
2408
+ schedule: Schedule<T>;
2409
+ created: boolean;
2410
+ }>;
2411
+ /**
2412
+ * Cancel a schedule row owned by a descendant facet, scoped by
2413
+ * `owner_path_key` so siblings can't reach each other's rows.
2414
+ * Returns the canceled row's callback name so the originating
2415
+ * facet can emit `schedule:cancel`. This method does not emit
2416
+ * observability events itself.
2417
+ * @internal
2418
+ */
2419
+ _cf_cancelScheduleForFacet(
2420
+ ownerPath: ReadonlyArray<AgentPathStep>,
2421
+ id: string
2422
+ ): Promise<{
2423
+ ok: boolean;
2424
+ callback?: string;
2425
+ }>;
2426
+ /**
2427
+ * Clean root-owned bookkeeping for a sub-tree of facets. This
2428
+ * bulk-cancels schedules whose `owner_path` starts with the given
2429
+ * prefix and deletes root-side facet fiber recovery leases for the
2430
+ * same sub-tree. Used by `deleteSubAgent` and recursive facet
2431
+ * destroy. Emits `schedule:cancel` on this agent (the alarm-owning
2432
+ * root) for each schedule row removed — the facets being torn down
2433
+ * may not be alive to receive the events themselves.
2434
+ * @internal
2435
+ */
2436
+ _cf_cleanupFacetPrefix(
2437
+ ownerPath: ReadonlyArray<AgentPathStep>
2438
+ ): Promise<void>;
2439
+ private _scheduleRowToSchedule;
2440
+ private _getScheduleForOwner;
2441
+ private _listSchedulesForOwner;
2442
+ /**
2443
+ * Read a single schedule row owned by a descendant facet.
2444
+ * @internal
2445
+ */
2446
+ _cf_getScheduleForFacet(
2447
+ ownerPath: ReadonlyArray<AgentPathStep>,
2448
+ id: string
2449
+ ): Promise<Schedule<unknown> | undefined>;
2450
+ /**
2451
+ * List schedule rows owned by a descendant facet, scoped by
2452
+ * `owner_path_key` so siblings remain isolated from each other.
2453
+ * @internal
2454
+ */
2455
+ _cf_listSchedulesForFacet(
2456
+ ownerPath: ReadonlyArray<AgentPathStep>,
2457
+ criteria?: ScheduleCriteria
2458
+ ): Promise<Schedule<unknown>[]>;
2459
+ /**
2460
+ * Acquire a root-owned keepAlive ref on behalf of a descendant facet.
2461
+ * Facets share the root isolate but cannot set their own physical
2462
+ * alarm, so this lets facet work use the root alarm heartbeat.
2463
+ * @internal
2464
+ */
2465
+ _cf_acquireFacetKeepAlive(
2466
+ ownerPath: ReadonlyArray<AgentPathStep>
2467
+ ): Promise<string>;
2468
+ /**
2469
+ * Release a root-owned keepAlive ref previously acquired for a facet.
2470
+ * Idempotent so disposer calls can safely race or run twice.
2471
+ * @internal
2472
+ */
2473
+ _cf_releaseFacetKeepAlive(token: string): Promise<void>;
2474
+ /**
2475
+ * Register a facet's durable run row in the root-side index so root
2476
+ * alarm housekeeping can dispatch recovery checks into idle facets.
2477
+ * The facet remains authoritative for snapshots and recovery hooks.
2478
+ * @internal
2479
+ */
2480
+ _cf_registerFacetRun(
2481
+ ownerPath: ReadonlyArray<AgentPathStep>,
2482
+ runId: string
2483
+ ): Promise<void>;
2484
+ /**
2485
+ * Remove a completed facet fiber from the root-side index.
2486
+ * @internal
2487
+ */
2488
+ _cf_unregisterFacetRun(
2489
+ ownerPath: ReadonlyArray<AgentPathStep>,
2490
+ runId: string
2491
+ ): Promise<void>;
2304
2492
  /**
2305
2493
  * Schedule a task to be executed in the future
2306
2494
  *
@@ -2372,24 +2560,52 @@ declare class Agent<
2372
2560
  * @template T Type of the payload data
2373
2561
  * @param id ID of the scheduled task
2374
2562
  * @returns The Schedule object or undefined if not found
2563
+ * @deprecated Use {@link getScheduleById}. This synchronous API cannot cross
2564
+ * Durable Object boundaries and throws inside sub-agents.
2375
2565
  */
2376
2566
  getSchedule<T = string>(id: string): Schedule<T> | undefined;
2567
+ /**
2568
+ * Get a scheduled task by ID.
2569
+ *
2570
+ * Unlike the deprecated synchronous {@link getSchedule}, this works inside
2571
+ * sub-agents by delegating to the top-level parent that owns the alarm.
2572
+ *
2573
+ * @template T Type of the payload data
2574
+ * @param id ID of the scheduled task
2575
+ * @returns The Schedule object or undefined if not found
2576
+ */
2577
+ getScheduleById(id: string): Promise<Schedule<unknown> | undefined>;
2377
2578
  /**
2378
2579
  * Get scheduled tasks matching the given criteria
2379
2580
  * @template T Type of the payload data
2380
2581
  * @param criteria Criteria to filter schedules
2381
2582
  * @returns Array of matching Schedule objects
2583
+ * @deprecated Use {@link listSchedules}. This synchronous API cannot cross
2584
+ * Durable Object boundaries and throws inside sub-agents.
2382
2585
  */
2383
- getSchedules<T = string>(criteria?: {
2384
- id?: string;
2385
- type?: "scheduled" | "delayed" | "cron" | "interval";
2386
- timeRange?: {
2387
- start?: Date;
2388
- end?: Date;
2389
- };
2390
- }): Schedule<T>[];
2586
+ getSchedules<T = string>(criteria?: ScheduleCriteria): Schedule<T>[];
2587
+ /**
2588
+ * List scheduled tasks matching the given criteria.
2589
+ *
2590
+ * Unlike the deprecated synchronous {@link getSchedules}, this works inside
2591
+ * sub-agents by delegating to the top-level parent that owns the alarm.
2592
+ *
2593
+ * @template T Type of the payload data
2594
+ * @param criteria Criteria to filter schedules
2595
+ * @returns Array of matching Schedule objects
2596
+ */
2597
+ listSchedules(criteria?: ScheduleCriteria): Promise<Schedule<unknown>[]>;
2391
2598
  /**
2392
- * Cancel a scheduled task
2599
+ * Cancel a scheduled task.
2600
+ *
2601
+ * Schedules are isolated by owner: a top-level agent's
2602
+ * `cancelSchedule(id)` only matches its own schedules, and a
2603
+ * sub-agent's `cancelSchedule(id)` only matches schedules it
2604
+ * created. To clear every schedule under a sub-agent (and its
2605
+ * descendants), call `parent.deleteSubAgent(Cls, name)` from the
2606
+ * parent — that bulk-cleans root-owned bookkeeping via
2607
+ * {@link _cf_cleanupFacetPrefix}.
2608
+ *
2393
2609
  * @param id ID of the task to cancel
2394
2610
  * @returns true if the task was cancelled, false if the task was not found
2395
2611
  */
@@ -2404,11 +2620,8 @@ declare class Agent<
2404
2620
  * alarm system, without creating schedule rows or emitting observability
2405
2621
  * events. Configure via `static options = { keepAliveIntervalMs: 5000 }`.
2406
2622
  *
2407
- * No-op on facets. Facets share the parent's isolate and don't
2408
- * need a separate alarm heartbeat the parent's own activity,
2409
- * any open WebSocket to the facet, and any in-flight Promise
2410
- * already keep the shared machine alive for the duration of
2411
- * real work.
2623
+ * In facets, delegates the physical heartbeat to the root parent
2624
+ * because facets do not have independent alarm slots.
2412
2625
  *
2413
2626
  * @example
2414
2627
  * ```ts
@@ -2482,6 +2695,55 @@ declare class Agent<
2482
2695
  private _checkRunFibers;
2483
2696
  /** @internal */
2484
2697
  _onAlarmHousekeeping(): Promise<void>;
2698
+ private _isSameAgentPathPrefix;
2699
+ /**
2700
+ * Root-side scan for durable fibers owned by descendant facets.
2701
+ * `cf_agents_facet_runs` is only an index; actual snapshots and
2702
+ * recovery hooks live in each facet's own `cf_agents_runs` table.
2703
+ * @internal
2704
+ */
2705
+ private _checkFacetRunFibers;
2706
+ /**
2707
+ * Dispatch a runFiber recovery check into the facet identified by
2708
+ * `ownerPath`. Returns the number of remaining local `cf_agents_runs`
2709
+ * rows on the target facet after recovery.
2710
+ * @internal
2711
+ */
2712
+ _cf_checkRunFibersForFacet(
2713
+ ownerPath: ReadonlyArray<AgentPathStep>
2714
+ ): Promise<number>;
2715
+ /**
2716
+ * Dispatch a scheduled callback into the facet identified by
2717
+ * `ownerPath`. Walks one step at a time: if `ownerPath` matches
2718
+ * `selfPath`, executes the callback locally; otherwise resolves
2719
+ * the next descendant facet and recurses through its own RPC.
2720
+ *
2721
+ * Called by the root's `alarm()` (which owns the physical alarm
2722
+ * for facet-owned schedules) and by intermediate facets while
2723
+ * walking down the chain.
2724
+ * @internal
2725
+ */
2726
+ _cf_dispatchScheduledCallback(
2727
+ ownerPath: ReadonlyArray<AgentPathStep>,
2728
+ row: ScheduleStorageRow
2729
+ ): Promise<void>;
2730
+ /**
2731
+ * Recursively destroy a descendant facet identified by
2732
+ * `targetPath`. Walks down from `selfPath` until reaching the
2733
+ * target's immediate parent, where it cancels the target's
2734
+ * parent-owned schedules (and any descendants), removes the
2735
+ * target from the registry, and calls `ctx.facets.delete` to
2736
+ * wipe the target's storage.
2737
+ *
2738
+ * Called by a facet's own `destroy()` (via the root) so that
2739
+ * `this.destroy()` inside a sub-agent results in the same
2740
+ * cleanup as `parent.deleteSubAgent(Cls, name)` from the parent.
2741
+ * @internal
2742
+ */
2743
+ _cf_destroyDescendantFacet(
2744
+ targetPath: ReadonlyArray<AgentPathStep>
2745
+ ): Promise<void>;
2746
+ private _executeScheduleCallback;
2485
2747
  private _scheduleNextAlarm;
2486
2748
  /**
2487
2749
  * Override PartyServer's onAlarm hook as a no-op.
@@ -2602,10 +2864,10 @@ declare class Agent<
2602
2864
  * We set `_isFacet` eagerly (before `__unsafe_ensureInitialized`
2603
2865
  * runs `onStart()`) so any code that legitimately branches on it
2604
2866
  * — e.g. skipping parent-owned alarms in schedule guards — sees
2605
- * the flag during the first `onStart()` run. Broadcast paths no
2606
- * longer special-case facets, since facets can be directly
2607
- * addressed via sub-agent routing and have their own WebSocket
2608
- * connections.
2867
+ * the flag during the first `onStart()` run. Protocol broadcasts are
2868
+ * suppressed only during this bootstrap window; afterward, facets can
2869
+ * broadcast to their own WebSocket clients reached via sub-agent
2870
+ * routing.
2609
2871
  *
2610
2872
  * The facet's name (and `this.name` getter) is handled entirely by
2611
2873
  * partyserver via `ctx.id.name`, which is populated because the
@@ -2721,6 +2983,45 @@ declare class Agent<
2721
2983
  cls: SubAgentClass<T>,
2722
2984
  name: string
2723
2985
  ): Promise<SubAgentStub<T>>;
2986
+ /** Maximum number of non-terminal agent-tool runs this parent may own at once. */
2987
+ maxConcurrentAgentTools: number;
2988
+ onAgentToolStart(_run: AgentToolRunInfo): Promise<void>;
2989
+ onAgentToolFinish(
2990
+ _run: AgentToolRunInfo,
2991
+ _result: AgentToolLifecycleResult
2992
+ ): Promise<void>;
2993
+ runAgentTool<Input = unknown, Output = unknown>(
2994
+ cls: ChatCapableAgentClass,
2995
+ options: RunAgentToolOptions<Input>
2996
+ ): Promise<RunAgentToolResult<Output>>;
2997
+ hasAgentToolRun<T extends Agent>(
2998
+ cls: SubAgentClass<T>,
2999
+ runId: string
3000
+ ): boolean;
3001
+ hasAgentToolRun(agentType: string, runId: string): boolean;
3002
+ clearAgentToolRuns(options?: {
3003
+ olderThan?: number;
3004
+ status?: AgentToolRunStatus[];
3005
+ }): Promise<void>;
3006
+ private _isAgentToolTerminal;
3007
+ private _activeAgentToolRunCount;
3008
+ private _defaultAgentToolPreview;
3009
+ private _readAgentToolRun;
3010
+ private _resultFromAgentToolRow;
3011
+ private _terminalResultFromInspection;
3012
+ private _updateAgentToolTerminal;
3013
+ private _markAgentToolRunning;
3014
+ private _parseAgentToolJson;
3015
+ private _stringifyAgentToolOutput;
3016
+ private _broadcastAgentToolEvent;
3017
+ private _broadcastAgentToolChunks;
3018
+ private _forwardAgentToolStream;
3019
+ private _broadcastAgentToolTerminal;
3020
+ private _asAgentToolChildAdapter;
3021
+ private _agentToolClassByName;
3022
+ private _replayAndInterruptAgentToolRun;
3023
+ private _replayAgentToolRuns;
3024
+ private _reconcileAgentToolRuns;
2724
3025
  /**
2725
3026
  * Shared facet resolution — takes a CamelCase class name string
2726
3027
  * (matching `ctx.exports`) rather than a class reference. Both
@@ -2753,7 +3054,7 @@ declare class Agent<
2753
3054
  * @param cls The Agent subclass used when creating the child
2754
3055
  * @param name Name of the child to delete
2755
3056
  */
2756
- deleteSubAgent(cls: SubAgentClass, name: string): void;
3057
+ deleteSubAgent(cls: SubAgentClass, name: string): Promise<void>;
2757
3058
  /** @internal */
2758
3059
  private _subAgentRegistryReady;
2759
3060
  /** @internal */
@@ -2803,9 +3104,23 @@ declare class Agent<
2803
3104
  createdAt: number;
2804
3105
  }>;
2805
3106
  /**
2806
- * Destroy the Agent, removing all state and scheduled tasks
3107
+ * Destroy the Agent, removing all state and scheduled tasks.
3108
+ *
3109
+ * On a top-level agent: drops every table, clears the alarm, and
3110
+ * aborts the isolate.
3111
+ *
3112
+ * On a sub-agent (facet): delegates teardown to the immediate
3113
+ * parent so the parent-owned schedule rows for this sub-agent
3114
+ * (and any of its descendants) are cancelled, the parent's
3115
+ * `cf_agents_sub_agents` registry entry is cleared, and
3116
+ * `ctx.facets.delete` wipes the facet's own storage. The
3117
+ * `ctx.facets.delete` call aborts this isolate, so this method
3118
+ * may not return cleanly when invoked from inside the facet —
3119
+ * callers should treat it as fire-and-forget.
2807
3120
  */
2808
3121
  destroy(): Promise<void>;
3122
+ /** @internal Drop every internal Agents SDK table during top-level destroy. */
3123
+ protected _dropInternalTablesForDestroy(): void;
2809
3124
  /**
2810
3125
  * Check if a method is callable
2811
3126
  * @param method The method name to check
@@ -3391,78 +3706,248 @@ declare class StreamingResponse {
3391
3706
  error(message: string): boolean;
3392
3707
  }
3393
3708
  //#endregion
3709
+ //#region src/agent-tool-types.d.ts
3710
+ type AgentToolRunStatus =
3711
+ | "starting"
3712
+ | "running"
3713
+ | "completed"
3714
+ | "error"
3715
+ | "aborted"
3716
+ | "interrupted";
3717
+ type AgentToolTerminalStatus = Extract<
3718
+ AgentToolRunStatus,
3719
+ "completed" | "error" | "aborted" | "interrupted"
3720
+ >;
3721
+ type AgentToolDisplayMetadata = {
3722
+ name?: string;
3723
+ icon?: string;
3724
+ } & Record<string, unknown>;
3725
+ type AgentToolRunInfo = {
3726
+ runId: string;
3727
+ parentToolCallId?: string;
3728
+ agentType: string;
3729
+ inputPreview?: unknown;
3730
+ status: AgentToolRunStatus;
3731
+ display?: AgentToolDisplayMetadata;
3732
+ displayOrder: number;
3733
+ startedAt: number;
3734
+ completedAt?: number;
3735
+ };
3736
+ type AgentToolLifecycleResult = {
3737
+ status: AgentToolTerminalStatus;
3738
+ summary?: string;
3739
+ error?: string;
3740
+ };
3741
+ type RunAgentToolOptions<Input = unknown> = {
3742
+ input: Input;
3743
+ runId?: string;
3744
+ parentToolCallId?: string;
3745
+ displayOrder?: number;
3746
+ signal?: AbortSignal;
3747
+ inputPreview?: unknown;
3748
+ display?: AgentToolDisplayMetadata;
3749
+ };
3750
+ type RunAgentToolResult<Output = unknown> = {
3751
+ runId: string;
3752
+ agentType: string;
3753
+ status: AgentToolTerminalStatus;
3754
+ output?: Output;
3755
+ summary?: string;
3756
+ error?: string;
3757
+ };
3758
+ type ChatCapableAgentClass<T extends Agent = Agent> = SubAgentClass<T>;
3759
+ type AgentToolRunInspection<Output = unknown> = {
3760
+ runId: string;
3761
+ status: Exclude<AgentToolRunStatus, "interrupted">;
3762
+ requestId?: string;
3763
+ streamId?: string;
3764
+ output?: Output;
3765
+ summary?: string;
3766
+ error?: string;
3767
+ startedAt: number;
3768
+ completedAt?: number;
3769
+ };
3770
+ type AgentToolStoredChunk = {
3771
+ sequence: number;
3772
+ body: string;
3773
+ };
3774
+ type AgentToolChildAdapter<Input = unknown, Output = unknown> = {
3775
+ startAgentToolRun(
3776
+ input: Input,
3777
+ options: {
3778
+ runId: string;
3779
+ signal?: AbortSignal;
3780
+ }
3781
+ ): Promise<AgentToolRunInspection<Output>>;
3782
+ cancelAgentToolRun(runId: string, reason?: unknown): Promise<void>;
3783
+ inspectAgentToolRun(
3784
+ runId: string
3785
+ ): Promise<AgentToolRunInspection<Output> | null>;
3786
+ getAgentToolChunks(
3787
+ runId: string,
3788
+ options?: {
3789
+ afterSequence?: number;
3790
+ }
3791
+ ): Promise<AgentToolStoredChunk[]>;
3792
+ tailAgentToolRun?(
3793
+ runId: string,
3794
+ options?: {
3795
+ afterSequence?: number;
3796
+ signal?: AbortSignal;
3797
+ }
3798
+ ): Promise<ReadableStream<AgentToolStoredChunk>>;
3799
+ };
3800
+ type AgentToolEvent =
3801
+ | {
3802
+ kind: "started";
3803
+ runId: string;
3804
+ agentType: string;
3805
+ inputPreview?: unknown;
3806
+ order: number;
3807
+ display?: AgentToolDisplayMetadata;
3808
+ }
3809
+ | {
3810
+ kind: "chunk";
3811
+ runId: string;
3812
+ body: string;
3813
+ }
3814
+ | {
3815
+ kind: "finished";
3816
+ runId: string;
3817
+ summary: string;
3818
+ }
3819
+ | {
3820
+ kind: "error";
3821
+ runId: string;
3822
+ error: string;
3823
+ }
3824
+ | {
3825
+ kind: "aborted";
3826
+ runId: string;
3827
+ reason?: string;
3828
+ }
3829
+ | {
3830
+ kind: "interrupted";
3831
+ runId: string;
3832
+ error: string;
3833
+ };
3834
+ type AgentToolEventMessage = {
3835
+ type: "agent-tool-event";
3836
+ parentToolCallId?: string;
3837
+ sequence: number;
3838
+ replay?: true;
3839
+ event: AgentToolEvent;
3840
+ };
3841
+ type AgentToolRunState = {
3842
+ runId: string;
3843
+ agentType: string;
3844
+ parentToolCallId?: string;
3845
+ inputPreview?: unknown;
3846
+ order: number;
3847
+ display?: AgentToolDisplayMetadata;
3848
+ status: "running" | "completed" | "error" | "aborted" | "interrupted";
3849
+ parts: UIMessage["parts"];
3850
+ summary?: string;
3851
+ error?: string;
3852
+ subAgent: {
3853
+ agent: string;
3854
+ name: string;
3855
+ };
3856
+ };
3857
+ type AgentToolEventState = {
3858
+ runsById: Record<string, AgentToolRunState>;
3859
+ runsByToolCallId: Record<string, AgentToolRunState[]>;
3860
+ unboundRuns: AgentToolRunState[];
3861
+ };
3862
+ //#endregion
3394
3863
  export {
3395
- ElicitRequestSchema$1 as $,
3396
- callable as A,
3397
- MCPConnectionResult as B,
3398
- SendEmailOptions as C,
3399
- SubAgentClass as D,
3400
- StreamingResponse as E,
3401
- unstable_callable as F,
3402
- RegisterServerOptions as G,
3403
- MCPOAuthCallbackResult as H,
3404
- MCPClientManager as I,
3405
- RPCClientTransportOptions as J,
3406
- getNamespacedData as K,
3407
- MCPClientManagerOptions as L,
3408
- getCurrentAgent as M,
3409
- routeAgentEmail as N,
3410
- SubAgentStub as O,
3411
- routeAgentRequest as P,
3412
- ElicitRequest$1 as Q,
3413
- MCPClientOAuthCallbackConfig as R,
3414
- Schedule as S,
3415
- StateUpdateMessage as T,
3416
- MCPServerFilter as U,
3417
- MCPDiscoverResult as V,
3418
- MCPServerOptions as W,
3419
- RPCServerTransportOptions as X,
3420
- RPCServerTransport as Y,
3421
- RPC_DO_PREFIX as Z,
3422
- MCPServerMessage as _,
3423
- parseSubAgentPath as _t,
3424
- AgentNamespace as a,
3425
- McpAuthContext as at,
3426
- RPCRequest as b,
3427
- CallableMetadata as c,
3428
- WorkerTransport as ct,
3429
- DEFAULT_AGENT_STATIC_OPTIONS as d,
3430
- StreamableHTTPEdgeClientTransport as dt,
3431
- ElicitResult$1 as et,
3432
- EmailRoutingOptions as f,
3433
- McpClientOptions as ft,
3434
- MCPServer as g,
3435
- getSubAgentByName as gt,
3436
- FiberRecoveryContext as h,
3437
- SubAgentPathMatch as ht,
3438
- AgentContext as i,
3439
- experimental_createMcpHandler as it,
3440
- getAgentByName as j,
3441
- WSMessage as k,
3442
- Connection$1 as l,
3443
- WorkerTransportOptions as lt,
3444
- FiberContext as m,
3445
- SUB_PREFIX as mt,
3446
- AddRpcMcpServerOptions as n,
3447
- CreateMcpHandlerOptions as nt,
3448
- AgentOptions as o,
3449
- getMcpAuthContext as ot,
3450
- EmailSendBinding as p,
3451
- TransportType as pt,
3452
- RPCClientTransport as q,
3453
- Agent as r,
3454
- createMcpHandler as rt,
3455
- AgentStaticOptions as s,
3456
- TransportState as st,
3457
- AddMcpServerOptions as t,
3458
- McpAgent as tt,
3459
- ConnectionContext$1 as u,
3460
- SSEEdgeClientTransport as ut,
3461
- MCPServersState as v,
3462
- routeSubAgentRequest as vt,
3463
- SqlError as w,
3464
- RPCResponse as x,
3465
- QueueItem as y,
3466
- MCPClientOAuthResult as z
3864
+ MCPClientManagerOptions as $,
3865
+ FiberRecoveryContext as A,
3866
+ SUB_PREFIX as At,
3867
+ SqlError as B,
3868
+ CallableMetadata as C,
3869
+ TransportState as Ct,
3870
+ EmailRoutingOptions as D,
3871
+ StreamableHTTPEdgeClientTransport as Dt,
3872
+ DEFAULT_AGENT_STATIC_OPTIONS as E,
3873
+ SSEEdgeClientTransport as Et,
3874
+ RPCRequest as F,
3875
+ WSMessage as G,
3876
+ StreamingResponse as H,
3877
+ RPCResponse as I,
3878
+ getCurrentAgent as J,
3879
+ callable as K,
3880
+ Schedule as L,
3881
+ MCPServerMessage as M,
3882
+ getSubAgentByName as Mt,
3883
+ MCPServersState as N,
3884
+ parseSubAgentPath as Nt,
3885
+ EmailSendBinding as O,
3886
+ McpClientOptions as Ot,
3887
+ QueueItem as P,
3888
+ routeSubAgentRequest as Pt,
3889
+ MCPClientManager as Q,
3890
+ ScheduleCriteria as R,
3891
+ AgentStaticOptions as S,
3892
+ getMcpAuthContext as St,
3893
+ ConnectionContext$1 as T,
3894
+ WorkerTransportOptions as Tt,
3895
+ SubAgentClass as U,
3896
+ StateUpdateMessage as V,
3897
+ SubAgentStub as W,
3898
+ routeAgentRequest as X,
3899
+ routeAgentEmail as Y,
3900
+ unstable_callable as Z,
3901
+ AddRpcMcpServerOptions as _,
3902
+ McpAgent as _t,
3903
+ AgentToolEventState as a,
3904
+ MCPServerFilter as at,
3905
+ AgentNamespace as b,
3906
+ experimental_createMcpHandler as bt,
3907
+ AgentToolRunInspection as c,
3908
+ getNamespacedData as ct,
3909
+ AgentToolStoredChunk as d,
3910
+ RPCServerTransport as dt,
3911
+ MCPClientOAuthCallbackConfig as et,
3912
+ AgentToolTerminalStatus as f,
3913
+ RPCServerTransportOptions as ft,
3914
+ AddMcpServerOptions as g,
3915
+ ElicitResult$1 as gt,
3916
+ RunAgentToolResult as h,
3917
+ ElicitRequestSchema$1 as ht,
3918
+ AgentToolEventMessage as i,
3919
+ MCPOAuthCallbackResult as it,
3920
+ MCPServer as j,
3921
+ SubAgentPathMatch as jt,
3922
+ FiberContext as k,
3923
+ TransportType as kt,
3924
+ AgentToolRunState as l,
3925
+ RPCClientTransport as lt,
3926
+ RunAgentToolOptions as m,
3927
+ ElicitRequest$1 as mt,
3928
+ AgentToolDisplayMetadata as n,
3929
+ MCPConnectionResult as nt,
3930
+ AgentToolLifecycleResult as o,
3931
+ MCPServerOptions as ot,
3932
+ ChatCapableAgentClass as p,
3933
+ RPC_DO_PREFIX as pt,
3934
+ getAgentByName as q,
3935
+ AgentToolEvent as r,
3936
+ MCPDiscoverResult as rt,
3937
+ AgentToolRunInfo as s,
3938
+ RegisterServerOptions as st,
3939
+ AgentToolChildAdapter as t,
3940
+ MCPClientOAuthResult as tt,
3941
+ AgentToolRunStatus as u,
3942
+ RPCClientTransportOptions as ut,
3943
+ Agent as v,
3944
+ CreateMcpHandlerOptions as vt,
3945
+ Connection$1 as w,
3946
+ WorkerTransport as wt,
3947
+ AgentOptions as x,
3948
+ McpAuthContext as xt,
3949
+ AgentContext as y,
3950
+ createMcpHandler as yt,
3951
+ SendEmailOptions as z
3467
3952
  };
3468
- //# sourceMappingURL=index-DSwOzhhd.d.ts.map
3953
+ //# sourceMappingURL=agent-tool-types-tBGRsPm0.d.ts.map