agents 0.16.2 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -8
- package/dist/{agent-tool-types-CTw3UJUP.d.ts → agent-tool-types-CNyE1iz_.d.ts} +671 -138
- package/dist/agent-tool-types.d.ts +34 -18
- package/dist/agent-tool-types.js +20 -1
- package/dist/agent-tool-types.js.map +1 -0
- package/dist/agent-tools-BXlsuX0d.js +304 -0
- package/dist/agent-tools-BXlsuX0d.js.map +1 -0
- package/dist/agent-tools-CSnyGvJ2.d.ts +119 -0
- package/dist/agent-tools.d.ts +24 -18
- package/dist/agent-tools.js.map +1 -1
- package/dist/ai-chat-agent.d.ts +1 -1
- package/dist/ai-chat-agent.js +1 -2
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.d.ts +1 -1
- package/dist/ai-chat-v5-migration.js +1 -2
- package/dist/ai-chat-v5-migration.js.map +1 -1
- package/dist/ai-react.d.ts +1 -1
- package/dist/ai-react.js +1 -2
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.d.ts +1 -7
- package/dist/ai-types.js +2 -8
- package/dist/ai-types.js.map +1 -1
- package/dist/browser/ai.js +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/chat/index.d.ts +2033 -77
- package/dist/chat/index.js +1828 -245
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +602 -0
- package/dist/chat/react.js +1506 -0
- package/dist/chat/react.js.map +1 -0
- package/dist/chat-sdk/index.d.ts +4 -4
- package/dist/{classPrivateFieldGet2-CZ7QjTXN.js → classPrivateFieldGet2-DZBYAB34.js} +5 -5
- package/dist/{classPrivateMethodInitSpec-D-0__zd9.js → classPrivateMethodInitSpec-qMjJ6sHQ.js} +2 -2
- package/dist/{client-BXJ9n2f7.js → client-BZ-B3NhC.js} +2 -2
- package/dist/client-BZ-B3NhC.js.map +1 -0
- package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
- package/dist/client.d.ts +76 -57
- package/dist/client.js +33 -5
- package/dist/client.js.map +1 -1
- package/dist/{connector-CrKhowfD.js → connector-CdldGF3h.js} +5 -5
- package/dist/{connector-CrKhowfD.js.map → connector-CdldGF3h.js.map} +1 -1
- package/dist/email.js +1 -1
- package/dist/email.js.map +1 -1
- package/dist/{index-B7IbEeze.d.ts → index-BRnybD6X.d.ts} +197 -14
- package/dist/index.d.ts +95 -73
- package/dist/index.js +694 -25
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +18 -14
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/index.d.ts +30 -30
- package/dist/mcp/index.js +7 -7
- package/dist/mcp/index.js.map +1 -1
- package/dist/{agent-tools-3zLG7MgA.js → message-builder-BymO4N_D.js} +45 -126
- package/dist/message-builder-BymO4N_D.js.map +1 -0
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.js +4 -2
- package/dist/observability/index.js.map +1 -1
- package/dist/react.d.ts +123 -110
- package/dist/react.js +44 -11
- package/dist/react.js.map +1 -1
- package/dist/{retries-CwlpAGet.d.ts → retries-CvHJwSuh.d.ts} +15 -6
- package/dist/retries.d.ts +8 -6
- package/dist/retries.js +44 -1
- package/dist/retries.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/skills/compile.js +1 -1
- package/dist/skills/compile.js.map +1 -1
- package/dist/skills/index.js +5 -5
- package/dist/skills/index.js.map +1 -1
- package/dist/sub-routing.d.ts +6 -6
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/vite.js +5 -5
- package/dist/vite.js.map +1 -1
- package/dist/wire-types-nflOzNuU.js +240 -0
- package/dist/wire-types-nflOzNuU.js.map +1 -0
- package/dist/{workflow-types-SrZK_o9p.d.ts → workflow-types-Baz_PO5v.d.ts} +42 -22
- package/dist/workflow-types.d.ts +25 -21
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +22 -21
- package/dist/workflows.js +31 -7
- package/dist/workflows.js.map +1 -1
- package/docs/adding-to-existing-project.md +450 -0
- package/docs/agent-class.md +503 -0
- package/docs/agent-tools.md +552 -0
- package/docs/browse-the-web.md +430 -0
- package/docs/callable-methods.md +627 -0
- package/docs/chat-agents.md +1696 -0
- package/docs/chat-sdk.md +181 -0
- package/docs/client-sdk.md +520 -0
- package/docs/client-tools-continuation.md +177 -0
- package/docs/codemode.md +440 -0
- package/docs/configuration.md +775 -0
- package/docs/cross-domain-authentication.md +171 -0
- package/docs/durable-execution.md +537 -0
- package/docs/email.md +663 -0
- package/docs/get-current-agent.md +204 -0
- package/docs/getting-started.md +305 -0
- package/docs/http-websockets.md +668 -0
- package/docs/human-in-the-loop.md +661 -0
- package/docs/index.md +151 -0
- package/docs/long-running-agents.md +730 -0
- package/docs/mcp-client.md +620 -0
- package/docs/mcp-servers.md +526 -0
- package/docs/mcp-transports.md +308 -0
- package/docs/migration-to-ai-sdk-v5.md +96 -0
- package/docs/migration-to-ai-sdk-v6.md +163 -0
- package/docs/observability.md +261 -0
- package/docs/push-notifications.md +367 -0
- package/docs/queue.md +329 -0
- package/docs/readonly-connections.md +278 -0
- package/docs/resumable-streaming.md +127 -0
- package/docs/retries.md +444 -0
- package/docs/routing.md +749 -0
- package/docs/scheduling.md +898 -0
- package/docs/securing-mcp-servers.md +359 -0
- package/docs/server-driven-messages.md +477 -0
- package/docs/sessions.md +1024 -0
- package/docs/state.md +512 -0
- package/docs/sub-agents.md +389 -0
- package/docs/webhooks.md +604 -0
- package/docs/workflows.md +877 -0
- package/package.json +41 -14
- package/dist/agent-tools-3zLG7MgA.js.map +0 -1
- package/dist/agent-tools-DZhI5F6Q.d.ts +0 -14
- package/dist/client-BXJ9n2f7.js.map +0 -1
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { n as AgentEmail } from "./internal_context-Dg4Cgjcu.js";
|
|
2
|
-
import { t as RetryOptions } from "./retries-
|
|
2
|
+
import { t as RetryOptions } from "./retries-CvHJwSuh.js";
|
|
3
3
|
import {
|
|
4
4
|
n as Observability,
|
|
5
5
|
r as ObservabilityEvent,
|
|
6
6
|
s as MCPObservabilityEvent
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-BRnybD6X.js";
|
|
8
8
|
import { t as AgentMcpOAuthProvider } from "./do-oauth-client-provider-D4ZwyBDu.js";
|
|
9
9
|
import {
|
|
10
|
-
_ as
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
y as
|
|
16
|
-
} from "./workflow-types-
|
|
10
|
+
_ as WorkflowEventPayload,
|
|
11
|
+
d as WorkflowCallback,
|
|
12
|
+
l as RunWorkflowOptions,
|
|
13
|
+
v as WorkflowInfo,
|
|
14
|
+
x as WorkflowQueryCriteria,
|
|
15
|
+
y as WorkflowPage
|
|
16
|
+
} from "./workflow-types-Baz_PO5v.js";
|
|
17
17
|
import { t as MessageType } from "./types-6Zo2zfoO.js";
|
|
18
18
|
import { r as EmailResolver } from "./email-CL27preh.js";
|
|
19
|
-
import { ToolSet, UIMessage } from "ai";
|
|
20
19
|
import { RpcTarget } from "cloudflare:workers";
|
|
21
20
|
import {
|
|
22
21
|
Connection,
|
|
@@ -29,6 +28,7 @@ import {
|
|
|
29
28
|
WSMessage,
|
|
30
29
|
WSMessage as WSMessage$1
|
|
31
30
|
} from "partyserver";
|
|
31
|
+
import { z } from "zod";
|
|
32
32
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
33
33
|
import {
|
|
34
34
|
SSEClientTransport,
|
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
Resource,
|
|
58
58
|
ResourceTemplate,
|
|
59
59
|
ServerCapabilities,
|
|
60
|
-
Tool
|
|
60
|
+
Tool
|
|
61
61
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
62
62
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
63
63
|
import {
|
|
@@ -819,7 +819,7 @@ declare class MCPClientConnection {
|
|
|
819
819
|
connectionError: string | null;
|
|
820
820
|
lastConnectedTransport: BaseTransportType | undefined;
|
|
821
821
|
instructions?: string;
|
|
822
|
-
tools: Tool
|
|
822
|
+
tools: Tool[];
|
|
823
823
|
private _transport?;
|
|
824
824
|
/**
|
|
825
825
|
* Transport that received the 401 during the initial connect attempt.
|
|
@@ -892,7 +892,7 @@ declare class MCPClientConnection {
|
|
|
892
892
|
* Notification handler registration for tools
|
|
893
893
|
* Should only be called if serverCapabilities.tools exists
|
|
894
894
|
*/
|
|
895
|
-
registerTools(): Promise<Tool
|
|
895
|
+
registerTools(): Promise<Tool[]>;
|
|
896
896
|
/**
|
|
897
897
|
* Notification handler registration for resources
|
|
898
898
|
* Should only be called if serverCapabilities.resources exists
|
|
@@ -1082,6 +1082,22 @@ type MCPServerRow = {
|
|
|
1082
1082
|
};
|
|
1083
1083
|
//#endregion
|
|
1084
1084
|
//#region src/mcp/client.d.ts
|
|
1085
|
+
type MCPAITool = {
|
|
1086
|
+
description?: string;
|
|
1087
|
+
title?: string;
|
|
1088
|
+
execute: (
|
|
1089
|
+
args: Record<string, unknown>,
|
|
1090
|
+
options?: unknown
|
|
1091
|
+
) => Promise<unknown>;
|
|
1092
|
+
inputSchema: z.ZodType;
|
|
1093
|
+
outputSchema?: z.ZodType;
|
|
1094
|
+
};
|
|
1095
|
+
/**
|
|
1096
|
+
* Structural tool set returned by {@link MCPClientManager.getAITools}.
|
|
1097
|
+
* Compatible with the AI SDK without importing its types into the core
|
|
1098
|
+
* `agents` declaration graph.
|
|
1099
|
+
*/
|
|
1100
|
+
type MCPAIToolSet = Record<string, MCPAITool>;
|
|
1085
1101
|
/** Maximum length of a normalized MCP server id. */
|
|
1086
1102
|
declare const MCP_SERVER_ID_MAX_LENGTH = 64;
|
|
1087
1103
|
/**
|
|
@@ -1443,13 +1459,13 @@ declare class MCPClientManager {
|
|
|
1443
1459
|
* @param filter - Optional filter to scope results to specific servers
|
|
1444
1460
|
* @returns a set of tools that you can use with the AI SDK
|
|
1445
1461
|
*/
|
|
1446
|
-
getAITools(filter?: MCPServerFilter):
|
|
1462
|
+
getAITools(filter?: MCPServerFilter): MCPAIToolSet;
|
|
1447
1463
|
/**
|
|
1448
1464
|
* @deprecated this has been renamed to getAITools(), and unstable_getAITools will be removed in the next major version
|
|
1449
1465
|
* @param filter - Optional filter to scope results to specific servers
|
|
1450
1466
|
* @returns a set of tools that you can use with the AI SDK
|
|
1451
1467
|
*/
|
|
1452
|
-
unstable_getAITools(filter?: MCPServerFilter):
|
|
1468
|
+
unstable_getAITools(filter?: MCPServerFilter): MCPAIToolSet;
|
|
1453
1469
|
/**
|
|
1454
1470
|
* Closes all active in-memory connections to MCP servers.
|
|
1455
1471
|
*
|
|
@@ -1727,7 +1743,9 @@ declare class MCPClientManager {
|
|
|
1727
1743
|
uri: string;
|
|
1728
1744
|
text: string;
|
|
1729
1745
|
mimeType?: string | undefined;
|
|
1730
|
-
_meta
|
|
1746
|
+
_meta /** Include only connections matching this server ID (or IDs). */?/** Include only connections matching this server ID (or IDs). */ :
|
|
1747
|
+
| Record<string, unknown>
|
|
1748
|
+
| undefined;
|
|
1731
1749
|
}
|
|
1732
1750
|
| {
|
|
1733
1751
|
uri: string;
|
|
@@ -1766,7 +1784,11 @@ declare class MCPClientManager {
|
|
|
1766
1784
|
icons?:
|
|
1767
1785
|
| {
|
|
1768
1786
|
src: string;
|
|
1769
|
-
mimeType
|
|
1787
|
+
mimeType?/**
|
|
1788
|
+
* Event that fires whenever any MCP server state changes (registered, connected, removed, etc.)
|
|
1789
|
+
* This is useful for broadcasting server state to clients.
|
|
1790
|
+
*/
|
|
1791
|
+
: string | undefined;
|
|
1770
1792
|
sizes?: string[] | undefined;
|
|
1771
1793
|
theme?: "light" | "dark" | undefined;
|
|
1772
1794
|
}[]
|
|
@@ -1789,7 +1811,7 @@ declare class MCPClientManager {
|
|
|
1789
1811
|
}>;
|
|
1790
1812
|
}
|
|
1791
1813
|
type NamespacedData = {
|
|
1792
|
-
tools: (Tool
|
|
1814
|
+
tools: (Tool & {
|
|
1793
1815
|
serverId: string;
|
|
1794
1816
|
})[];
|
|
1795
1817
|
prompts: (Prompt & {
|
|
@@ -2077,6 +2099,9 @@ type ScheduleStorageRow = {
|
|
|
2077
2099
|
owner_path?: string | null;
|
|
2078
2100
|
owner_path_key?: string | null;
|
|
2079
2101
|
};
|
|
2102
|
+
type DetachedReconcilePayload = {
|
|
2103
|
+
cadenceIndex?: number;
|
|
2104
|
+
};
|
|
2080
2105
|
type ScheduleCriteria = {
|
|
2081
2106
|
id?: string;
|
|
2082
2107
|
type?: "scheduled" | "delayed" | "cron" | "interval";
|
|
@@ -2205,7 +2230,7 @@ type MCPServersState = {
|
|
|
2205
2230
|
servers: {
|
|
2206
2231
|
[id: string]: MCPServer;
|
|
2207
2232
|
};
|
|
2208
|
-
tools: (Tool
|
|
2233
|
+
tools: (Tool & {
|
|
2209
2234
|
serverId: string;
|
|
2210
2235
|
})[];
|
|
2211
2236
|
prompts: (Prompt & {
|
|
@@ -2322,6 +2347,17 @@ declare const DEFAULT_AGENT_STATIC_OPTIONS: {
|
|
|
2322
2347
|
* wall-clock cap (which also tears the child down on `window-exceeded`).
|
|
2323
2348
|
*/
|
|
2324
2349
|
agentToolReattachMaxWindowMs: number;
|
|
2350
|
+
detachedMaxBudgetMs: number;
|
|
2351
|
+
detachedNoProgressBudgetMs: number;
|
|
2352
|
+
/**
|
|
2353
|
+
* Consecutive alarm invocations that may end in a Durable Object memory-limit
|
|
2354
|
+
* reset (the isolate exceeded its 128 MB limit) before the alarm-boundary
|
|
2355
|
+
* circuit breaker stops the platform's auto-retry loop and seals the looping
|
|
2356
|
+
* work (#1825). A small budget tolerates a genuinely transient memory spike;
|
|
2357
|
+
* a deterministic OOM (the work's footprint, not the platform, is the cause)
|
|
2358
|
+
* is bounded here regardless of whether the in-DO recovery budgets could run.
|
|
2359
|
+
*/
|
|
2360
|
+
maxAlarmMemoryLimitStrikes: number;
|
|
2325
2361
|
};
|
|
2326
2362
|
/**
|
|
2327
2363
|
* Configuration options for the Agent.
|
|
@@ -2385,6 +2421,44 @@ interface AgentStaticOptions {
|
|
|
2385
2421
|
* also disables the ceiling.
|
|
2386
2422
|
*/
|
|
2387
2423
|
agentToolReattachMaxWindowMs?: number;
|
|
2424
|
+
/**
|
|
2425
|
+
* Absolute safety ceiling in milliseconds for a DETACHED ("background")
|
|
2426
|
+
* agent-tool run dispatched via `runAgentTool(cls, { detached: ... })`
|
|
2427
|
+
* (rfc-detached-agent-tools). A detached run has no awaiting parent turn, so
|
|
2428
|
+
* on expiry the parent gives up watching — delivers the completion hook with
|
|
2429
|
+
* `interrupted` / `budget-exceeded` and tears the child down — rather than
|
|
2430
|
+
* holding a concurrency slot + live facet forever. Unlike the re-attach
|
|
2431
|
+
* window this defaults to a FINITE value (24h) precisely because an abandoned
|
|
2432
|
+
* detached run has no observer to notice the leak. Override per-run via
|
|
2433
|
+
* `detached: { maxBudgetMs }`.
|
|
2434
|
+
*/
|
|
2435
|
+
detachedMaxBudgetMs?: number;
|
|
2436
|
+
/**
|
|
2437
|
+
* Resetting no-progress window in milliseconds for a DETACHED agent-tool run
|
|
2438
|
+
* (rfc-detached-agent-tools §progress). Once the child has emitted at least
|
|
2439
|
+
* one `reportProgress` signal, the parent gives up if the run then goes
|
|
2440
|
+
* silent for this long; the window resets on every subsequent signal. A child
|
|
2441
|
+
* that never reports progress is bounded only by `detachedMaxBudgetMs` — we
|
|
2442
|
+
* never give up on a run merely for taking a long time, only for going silent
|
|
2443
|
+
* after it began reporting. Default: 1h. Set `0`/`Infinity` to disable (rely
|
|
2444
|
+
* on the absolute ceiling only). Override per-run via
|
|
2445
|
+
* `detached: { noProgressBudgetMs }`.
|
|
2446
|
+
*/
|
|
2447
|
+
detachedNoProgressBudgetMs?: number;
|
|
2448
|
+
/**
|
|
2449
|
+
* Consecutive alarm invocations that may end in a Durable Object memory-limit
|
|
2450
|
+
* reset (the isolate exceeded its 128 MB limit) before the alarm-boundary
|
|
2451
|
+
* circuit breaker stops the platform's auto-retry loop and seals the looping
|
|
2452
|
+
* recovery work (#1825). Default: 3. Set to `0` to seal on the first such
|
|
2453
|
+
* reset. This is the universal backstop for the case where the in-DO recovery
|
|
2454
|
+
* budgets (`chatRecovery.maxOomRetries` / `maxRecoveryWork`) can't engage
|
|
2455
|
+
* because the OOM bypasses them — e.g. it is thrown before the budget code
|
|
2456
|
+
* runs, or its own writes also OOM. The boundary handler runs at the outermost
|
|
2457
|
+
* alarm frame, after the heavy turn has unwound and GC has reclaimed its
|
|
2458
|
+
* footprint, so its small seal/purge writes can land where mid-turn writes
|
|
2459
|
+
* could not.
|
|
2460
|
+
*/
|
|
2461
|
+
maxAlarmMemoryLimitStrikes?: number;
|
|
2388
2462
|
}
|
|
2389
2463
|
declare function getCurrentAgent<
|
|
2390
2464
|
T extends Agent<Cloudflare.Env> = Agent<Cloudflare.Env>
|
|
@@ -2492,6 +2566,10 @@ declare class Agent<
|
|
|
2492
2566
|
private _recoveryNoProgressScans;
|
|
2493
2567
|
/** @internal Single-flight background recovery for parent agent-tool rows. */
|
|
2494
2568
|
private _agentToolRunRecoveryPromise;
|
|
2569
|
+
/** @internal Serializes detached-backbone arming against concurrent dispatch. */
|
|
2570
|
+
private _detachedBackboneArming;
|
|
2571
|
+
/** @internal Edge-trigger latch for the live-detached-count warning. */
|
|
2572
|
+
private _detachedLiveCountWarned;
|
|
2495
2573
|
private _ParentClass;
|
|
2496
2574
|
readonly mcp: MCPClientManager;
|
|
2497
2575
|
/**
|
|
@@ -3302,6 +3380,17 @@ declare class Agent<
|
|
|
3302
3380
|
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
3303
3381
|
row: ScheduleStorageRow
|
|
3304
3382
|
): Promise<boolean>;
|
|
3383
|
+
/**
|
|
3384
|
+
* Invoke an RPC method on this Agent or a descendant facet identified
|
|
3385
|
+
* by a root-first path. Used by AgentWorkflow to route callbacks and
|
|
3386
|
+
* `this.agent` calls back to the exact sub-agent that started a workflow.
|
|
3387
|
+
* @internal
|
|
3388
|
+
*/
|
|
3389
|
+
_cf_invokeAgentPath(
|
|
3390
|
+
targetPath: ReadonlyArray<AgentPathStep>,
|
|
3391
|
+
method: string,
|
|
3392
|
+
args: unknown[]
|
|
3393
|
+
): Promise<unknown>;
|
|
3305
3394
|
/**
|
|
3306
3395
|
* Recursively destroy a descendant facet identified by
|
|
3307
3396
|
* `targetPath`. Walks down from `selfPath` until reaching the
|
|
@@ -3354,6 +3443,66 @@ declare class Agent<
|
|
|
3354
3443
|
* See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
|
|
3355
3444
|
*/
|
|
3356
3445
|
alarm(): Promise<void>;
|
|
3446
|
+
/**
|
|
3447
|
+
* The alarm body: PartyServer init + due-schedule processing + housekeeping +
|
|
3448
|
+
* next-alarm arm. Extracted from {@link alarm} so the memory-limit circuit
|
|
3449
|
+
* breaker can wrap it at the outermost frame (see {@link alarm}).
|
|
3450
|
+
*/
|
|
3451
|
+
private _cf_runAlarmBody;
|
|
3452
|
+
/**
|
|
3453
|
+
* Durable storage key for the alarm memory-limit strike counter (#1825).
|
|
3454
|
+
*/
|
|
3455
|
+
private static readonly _CF_OOM_ALARM_STRIKES_KEY;
|
|
3456
|
+
/**
|
|
3457
|
+
* The schedule row id currently executing in the alarm loop, so the
|
|
3458
|
+
* memory-limit circuit breaker can purge the exact looping row (#1825).
|
|
3459
|
+
* `undefined` outside a callback (e.g. an OOM from `super.alarm()`/onStart).
|
|
3460
|
+
*/
|
|
3461
|
+
private _cf_executingScheduleRowId?;
|
|
3462
|
+
/**
|
|
3463
|
+
* The schedule-callback names whose alarm rows drive a recovery loop that can
|
|
3464
|
+
* deterministically OOM. The base agent has none; chat hosts (`Think`,
|
|
3465
|
+
* `AIChatAgent`) override this to return their recovery continuation callbacks
|
|
3466
|
+
* so the circuit breaker can surgically back them off / purge them WITHOUT
|
|
3467
|
+
* disturbing unrelated scheduled tasks. See {@link _cf_handleAlarmMemoryLimitReset}.
|
|
3468
|
+
*/
|
|
3469
|
+
protected _cf_recoveryAlarmCallbacks(): string[];
|
|
3470
|
+
/**
|
|
3471
|
+
* Hook for a host to terminalize ("seal") any in-flight recovery work as an
|
|
3472
|
+
* out-of-memory exhaustion when the alarm circuit breaker trips at its strike
|
|
3473
|
+
* budget (#1825). Runs at the outermost alarm frame (post-unwind, so writes
|
|
3474
|
+
* can land). Default: no-op. Chat hosts override to fire `onExhausted` + the
|
|
3475
|
+
* terminal banner and persist the sealed incident.
|
|
3476
|
+
*/
|
|
3477
|
+
protected _cf_sealMemoryLimitedRecovery(): Promise<void>;
|
|
3478
|
+
/**
|
|
3479
|
+
* Clear the durable memory-limit strike counter after a clean alarm so the
|
|
3480
|
+
* circuit breaker counts CONSECUTIVE resets rather than lifetime ones
|
|
3481
|
+
* (#1825). Reads first (cheap, usually cached) and only writes when a strike
|
|
3482
|
+
* is actually recorded, so the common no-strike path costs no write.
|
|
3483
|
+
* Best-effort: a stale strike only costs one extra tolerated spike later.
|
|
3484
|
+
*/
|
|
3485
|
+
private _cf_clearAlarmMemoryLimitStrikes;
|
|
3486
|
+
/**
|
|
3487
|
+
* Alarm-boundary circuit breaker for Durable Object memory-limit resets
|
|
3488
|
+
* (#1825). The in-DO recovery budgets (`chatRecovery.maxOomRetries` /
|
|
3489
|
+
* `maxRecoveryWork`) only engage if their code runs AND its writes land; a
|
|
3490
|
+
* severe OOM can defeat both — thrown before the budget runs (boot hydration),
|
|
3491
|
+
* or its own small writes also OOM under memory pressure. In that case the
|
|
3492
|
+
* error reaches {@link alarm} and, unhandled, the platform auto-retries the
|
|
3493
|
+
* alarm indefinitely (re-running the doomed, billable turn each cycle).
|
|
3494
|
+
*
|
|
3495
|
+
* This runs at the OUTERMOST frame: the heavy turn has unwound and GC has
|
|
3496
|
+
* reclaimed its footprint, so the small writes here can land where mid-turn
|
|
3497
|
+
* ones (e.g. give-up's incident read) OOMed. A durable strike counter tolerates
|
|
3498
|
+
* a few resets (a transient spike may clear), backing off the recovery rows so
|
|
3499
|
+
* the retry is not a hot loop. At the `maxAlarmMemoryLimitStrikes` budget it
|
|
3500
|
+
* seals the recovery work and purges the looping rows so the loop — and the
|
|
3501
|
+
* bill — stops. Each step is best-effort: even these tiny writes can OOM, but
|
|
3502
|
+
* swallowing (not re-throwing) still halts the platform's auto-retry, and a
|
|
3503
|
+
* later wake re-arms legitimate schedules.
|
|
3504
|
+
*/
|
|
3505
|
+
private _cf_handleAlarmMemoryLimitReset;
|
|
3357
3506
|
/**
|
|
3358
3507
|
* Intercept incoming HTTP/WS requests whose URL contains a
|
|
3359
3508
|
* `/sub/{child-class}/{child-name}` marker and forward them to
|
|
@@ -3674,10 +3823,132 @@ declare class Agent<
|
|
|
3674
3823
|
_run: AgentToolRunInfo,
|
|
3675
3824
|
_result: AgentToolLifecycleResult
|
|
3676
3825
|
): Promise<void>;
|
|
3826
|
+
/**
|
|
3827
|
+
* Parent hook fired (best-effort) whenever a child agent-tool run emits a
|
|
3828
|
+
* `reportProgress` signal that is forwarded through this parent's tail. Use it
|
|
3829
|
+
* to meter / steer / surface progress server-side. Fires for both awaited and
|
|
3830
|
+
* detached runs; it is NOT durable — after eviction a detached run's latest
|
|
3831
|
+
* snapshot is read from `inspectAgentToolRun().progress` on reconcile instead.
|
|
3832
|
+
*/
|
|
3833
|
+
onProgress(
|
|
3834
|
+
_run: AgentToolRunInfo,
|
|
3835
|
+
_progress: AgentToolProgressSnapshot
|
|
3836
|
+
): Promise<void>;
|
|
3837
|
+
/**
|
|
3838
|
+
* Emit an ephemeral progress signal from a sub-agent that is currently running
|
|
3839
|
+
* as an agent tool. Rides the child's active turn stream as a transient
|
|
3840
|
+
* `data-agent-progress` part (re-broadcast to the parent's clients + surfaced
|
|
3841
|
+
* in `useAgentToolEvents`) and persists a latest-wins snapshot for recovery /
|
|
3842
|
+
* inspection. A no-op (with a dev warning) on the base `Agent`, which has no
|
|
3843
|
+
* streaming turn — overridden by chat hosts (`@cloudflare/think`,
|
|
3844
|
+
* `AIChatAgent`). See `design/rfc-detached-agent-tools.md`.
|
|
3845
|
+
*/
|
|
3846
|
+
reportProgress<T = unknown>(
|
|
3847
|
+
_progress: AgentToolProgress<T>,
|
|
3848
|
+
_options?: {
|
|
3849
|
+
persist?: boolean;
|
|
3850
|
+
}
|
|
3851
|
+
): Promise<void>;
|
|
3852
|
+
runAgentTool<Input = unknown>(
|
|
3853
|
+
cls: ChatCapableAgentClass,
|
|
3854
|
+
options: RunAgentToolOptions<Input> & {
|
|
3855
|
+
detached: true | DetachedAgentToolConfig;
|
|
3856
|
+
}
|
|
3857
|
+
): Promise<DetachedRunAgentToolResult>;
|
|
3677
3858
|
runAgentTool<Input = unknown, Output = unknown>(
|
|
3678
3859
|
cls: ChatCapableAgentClass,
|
|
3679
3860
|
options: RunAgentToolOptions<Input>
|
|
3680
3861
|
): Promise<RunAgentToolResult<Output>>;
|
|
3862
|
+
/**
|
|
3863
|
+
* Cancel an agent-tool run by id. Idempotent: cancelling an already-terminal
|
|
3864
|
+
* run is a no-op. Detached runs deliver through the guarded ledger so a wired
|
|
3865
|
+
* `onFinish` fires once with `status: "aborted"`; awaited runs leave terminal
|
|
3866
|
+
* observation to the awaiting/recovery path, avoiding duplicate finish hooks.
|
|
3867
|
+
*/
|
|
3868
|
+
cancelAgentTool(runId: string, reason?: unknown): Promise<void>;
|
|
3869
|
+
/**
|
|
3870
|
+
* Parse + validate the `detached` option. Returns `null` for a non-detached
|
|
3871
|
+
* run, or the normalized config (with the validated `onFinish` method name)
|
|
3872
|
+
* for a detached one. Throws if `onFinish` does not name a method on this
|
|
3873
|
+
* agent — closures cannot survive Durable Object eviction, so the durable
|
|
3874
|
+
* hook is referenced by method name (the same contract as `schedule`).
|
|
3875
|
+
*/
|
|
3876
|
+
private _parseDetachedOption;
|
|
3877
|
+
private _isAgentToolRowHardTerminal;
|
|
3878
|
+
private _hasOutstandingDetachedRuns;
|
|
3879
|
+
/** Detached runs still holding a concurrency slot (non-terminal). */
|
|
3880
|
+
private _liveDetachedRunCount;
|
|
3881
|
+
/**
|
|
3882
|
+
* Edge-triggered warning when live detached runs cross
|
|
3883
|
+
* `DETACHED_LIVE_COUNT_WARN_THRESHOLD`. Fires once on the up-crossing and
|
|
3884
|
+
* re-arms only after the count falls back below the threshold, so a parent
|
|
3885
|
+
* accumulating long-lived background runs surfaces a signal without spamming.
|
|
3886
|
+
*/
|
|
3887
|
+
private _maybeWarnDetachedLiveCount;
|
|
3888
|
+
/**
|
|
3889
|
+
* Warm fast path for a detached run: tail the child to terminal (so the
|
|
3890
|
+
* parent re-broadcasts its live stream to clients) and deliver the completion
|
|
3891
|
+
* with low latency while the isolate stays alive. Best-effort — the durable
|
|
3892
|
+
* `_cfDetachedReconcileTick` backbone is the guarantee; anything this misses
|
|
3893
|
+
* (eviction, a child that has not yet reached terminal) the backbone collects.
|
|
3894
|
+
*/
|
|
3895
|
+
private _detachedFastPath;
|
|
3896
|
+
/**
|
|
3897
|
+
* Single delivery funnel for a detached terminal. Both the warm fast path and
|
|
3898
|
+
* the durable backbone route through here, with INDEPENDENT ledger slots for
|
|
3899
|
+
* `finish` (the real terminal) vs `give_up` (budget exhausted). Each slot is
|
|
3900
|
+
* delivered at-least-once via a claim + lease:
|
|
3901
|
+
*
|
|
3902
|
+
* - Concurrent double-fire is prevented by the guarded CAS claim (RETURNING
|
|
3903
|
+
* yields the row only to the winner).
|
|
3904
|
+
* - A crash after the side effect but before `*_delivered_at` is written lets
|
|
3905
|
+
* the lease expire so a later reconcile re-delivers — hence handlers must be
|
|
3906
|
+
* idempotent.
|
|
3907
|
+
* - Two slots, not one, because `interrupted` is SOFT: a give-up followed by a
|
|
3908
|
+
* real completion is legitimate, and a single shared "delivered" bit would
|
|
3909
|
+
* dedupe the child's real late result away (the #1752 production incident).
|
|
3910
|
+
*/
|
|
3911
|
+
private _deliverDetachedTerminal;
|
|
3912
|
+
private _safeRunOnError;
|
|
3913
|
+
/**
|
|
3914
|
+
* Run a detached terminal delivery (the `onAgentToolFinish` + per-run
|
|
3915
|
+
* `onFinish` callbacks) in an appropriate execution context. The base `Agent`
|
|
3916
|
+
* has no turn queue, so it only establishes `agentContext` — a handler that
|
|
3917
|
+
* calls `runAgentTool` / `setState` therefore works regardless of where the
|
|
3918
|
+
* delivery fired from.
|
|
3919
|
+
*
|
|
3920
|
+
* Chat-layer subclasses (`@cloudflare/think`, `@cloudflare/ai-chat`) override
|
|
3921
|
+
* this to additionally serialize delivery against their turn queue when
|
|
3922
|
+
* `serialize` is set: a fast-path push or backbone tick can land mid-turn, and
|
|
3923
|
+
* a state-mutating `onFinish` running concurrently with an active LLM turn is a
|
|
3924
|
+
* data race. The fast path and backbone never run synchronously inside a turn
|
|
3925
|
+
* (they fire from `waitUntil` / a scheduled alarm), so enqueuing them on the
|
|
3926
|
+
* turn queue is deadlock-free. An explicit `cancelAgentTool` runs with
|
|
3927
|
+
* `serialize` unset because it may be called from inside the very turn that
|
|
3928
|
+
* triggers it, where enqueuing would self-deadlock.
|
|
3929
|
+
*/
|
|
3930
|
+
protected _runDetachedDelivery(
|
|
3931
|
+
invoke: () => Promise<void>,
|
|
3932
|
+
_options?: {
|
|
3933
|
+
serialize?: boolean;
|
|
3934
|
+
}
|
|
3935
|
+
): Promise<void>;
|
|
3936
|
+
/**
|
|
3937
|
+
* Arm the self-scheduling detached reconcile backbone. Existing schedules are
|
|
3938
|
+
* reused for recovery/startup calls, but a fresh detached dispatch resets the
|
|
3939
|
+
* pending cadence to the fast end so new work is noticed promptly.
|
|
3940
|
+
*/
|
|
3941
|
+
private _armDetachedBackbone;
|
|
3942
|
+
private _armDetachedBackboneInner;
|
|
3943
|
+
/**
|
|
3944
|
+
* Durable backbone for detached runs. Runs on a self-rescheduling alarm:
|
|
3945
|
+
* collects any detached run that has reached terminal but was not yet
|
|
3946
|
+
* delivered (e.g. the parent was evicted before the fast path landed), gives
|
|
3947
|
+
* up on any run past its absolute budget (tearing the child down), and
|
|
3948
|
+
* reschedules itself while any detached run remains undelivered — cancelling
|
|
3949
|
+
* itself once everything has settled (zero steady-state cost).
|
|
3950
|
+
*/
|
|
3951
|
+
_cfDetachedReconcileTick(payload?: DetachedReconcilePayload): Promise<void>;
|
|
3681
3952
|
hasAgentToolRun<T extends Agent>(
|
|
3682
3953
|
cls: SubAgentClass<T>,
|
|
3683
3954
|
runId: string
|
|
@@ -3734,6 +4005,34 @@ declare class Agent<
|
|
|
3734
4005
|
* called repeatedly while a child streams.
|
|
3735
4006
|
*/
|
|
3736
4007
|
protected _onAgentToolStreamProgress(): Promise<void>;
|
|
4008
|
+
/**
|
|
4009
|
+
* Best-effort observation of a forwarded child chunk: if it is a reserved
|
|
4010
|
+
* `data-agent-progress` frame, refresh the cached liveness timestamp on the
|
|
4011
|
+
* run row (a hint for a still-warm parent) and fire the public `onProgress`
|
|
4012
|
+
* hook. Never throws into the forward loop — the child's own persisted
|
|
4013
|
+
* snapshot (read via `inspectAgentToolRun`) remains authoritative for the
|
|
4014
|
+
* resetting no-progress budget after eviction.
|
|
4015
|
+
*/
|
|
4016
|
+
private _observeForwardedProgress;
|
|
4017
|
+
/**
|
|
4018
|
+
* Deliver a milestone notification IF this run opted into it via
|
|
4019
|
+
* `detached: { onMilestones }` and the milestone name is in that set. Routes
|
|
4020
|
+
* to the overridable `_deliverDetachedMilestone` seam (a no-op on the base
|
|
4021
|
+
* `Agent`; chat hosts inject an idempotent synthetic chat message).
|
|
4022
|
+
*/
|
|
4023
|
+
private _maybeDeliverDetachedMilestone;
|
|
4024
|
+
/**
|
|
4025
|
+
* Overridable seam for the `detached: { onMilestones }` convenience. The base
|
|
4026
|
+
* `Agent` has no chat surface, so this is a no-op; chat hosts
|
|
4027
|
+
* (`@cloudflare/think`, `AIChatAgent`) override it to submit an idempotent
|
|
4028
|
+
* synthetic message keyed on `(runId, milestone.name)`. Called from both the
|
|
4029
|
+
* warm tail and the backbone reconcile, so it MUST be idempotent.
|
|
4030
|
+
*/
|
|
4031
|
+
protected _deliverDetachedMilestone(
|
|
4032
|
+
_run: AgentToolRunInfo,
|
|
4033
|
+
_milestone: AgentToolMilestone,
|
|
4034
|
+
_mode: "react" | "narrate"
|
|
4035
|
+
): Promise<void>;
|
|
3737
4036
|
private _broadcastAgentToolTerminal;
|
|
3738
4037
|
private _asAgentToolChildAdapter;
|
|
3739
4038
|
private _agentToolClassByName;
|
|
@@ -3939,10 +4238,29 @@ declare class Agent<
|
|
|
3939
4238
|
* Start a workflow and track it in this Agent's database.
|
|
3940
4239
|
* Automatically injects agent identity into the workflow params.
|
|
3941
4240
|
*
|
|
4241
|
+
* The originating Agent identity is persisted in the workflow params so
|
|
4242
|
+
* callbacks (`this.agent` RPC, progress/completion/error, state updates)
|
|
4243
|
+
* route back to the exact Agent or sub-agent facet that started the run.
|
|
4244
|
+
* Note the following constraints:
|
|
4245
|
+
*
|
|
4246
|
+
* - **Resolution is by name.** Callbacks re-resolve the originating Agent via
|
|
4247
|
+
* `getAgentByName(...)`. Agents addressed by a raw Durable Object id
|
|
4248
|
+
* (`idFromString`/`get(id)`) rather than by name will not receive
|
|
4249
|
+
* callbacks on the same instance.
|
|
4250
|
+
* - **Sub-agent runs are facet-local.** A workflow started from a sub-agent
|
|
4251
|
+
* is tracked in that facet's own storage; the parent's `getWorkflows()` /
|
|
4252
|
+
* `getWorkflowById()` do not see it. Aggregate across facets yourself if
|
|
4253
|
+
* you need a combined view.
|
|
4254
|
+
* - **Class names must survive bundling.** The originating path is keyed by
|
|
4255
|
+
* `constructor.name`. Ensure your bundler preserves class names
|
|
4256
|
+
* (e.g. esbuild `keepNames: true`) so callbacks can be routed.
|
|
4257
|
+
*
|
|
3942
4258
|
* @template P - Type of params to pass to the workflow
|
|
3943
4259
|
* @param workflowName - Name of the workflow binding in env (e.g., 'MY_WORKFLOW')
|
|
3944
4260
|
* @param params - Params to pass to the workflow
|
|
3945
|
-
* @param options - Optional workflow options
|
|
4261
|
+
* @param options - Optional workflow options. For sub-agents, pass
|
|
4262
|
+
* `agentBinding` as the **root** Agent's Durable Object binding name, not a
|
|
4263
|
+
* child binding.
|
|
3946
4264
|
* @returns The workflow instance ID
|
|
3947
4265
|
*
|
|
3948
4266
|
* @example
|
|
@@ -4212,16 +4530,15 @@ declare class Agent<
|
|
|
4212
4530
|
* Convert a database row to WorkflowInfo
|
|
4213
4531
|
*/
|
|
4214
4532
|
private _rowToWorkflowInfo;
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
* Returns undefined if no match found - use options.agentBinding as fallback.
|
|
4218
|
-
*/
|
|
4219
|
-
private _findAgentBindingName;
|
|
4533
|
+
private _workflowOrigin;
|
|
4534
|
+
private _findAgentBindingNameForClass;
|
|
4220
4535
|
private _findBindingNameForNamespace;
|
|
4221
4536
|
private _restoreRpcMcpServers;
|
|
4222
4537
|
/**
|
|
4223
4538
|
* Handle a callback from a workflow.
|
|
4224
|
-
*
|
|
4539
|
+
* Invoked via the internal `_workflow_handleCallback` RPC whenever an
|
|
4540
|
+
* {@link AgentWorkflow} reports progress, completion, an error, or a custom
|
|
4541
|
+
* event back to its originating Agent (or sub-agent facet).
|
|
4225
4542
|
* Override this to handle all callback types in one place.
|
|
4226
4543
|
*
|
|
4227
4544
|
* @param callback - The callback payload
|
|
@@ -4540,6 +4857,10 @@ type AgentToolTerminalStatus = Extract<
|
|
|
4540
4857
|
* - `inspect-failed` — inspecting the child failed during parent recovery.
|
|
4541
4858
|
* - `recovery-deadline` — the overall parent-recovery deadline elapsed before
|
|
4542
4859
|
* this run could be reconciled.
|
|
4860
|
+
* - `budget-exceeded` — a detached run's absolute `maxBudgetMs` ceiling elapsed
|
|
4861
|
+
* before it reached a terminal. The parent gave up watching and tore the
|
|
4862
|
+
* child down. Like `window-exceeded` this is a soft seal: a child that
|
|
4863
|
+
* completes anyway can still repair the run and re-fire the completion hook.
|
|
4543
4864
|
*/
|
|
4544
4865
|
type AgentToolInterruptedReason =
|
|
4545
4866
|
| "no-progress"
|
|
@@ -4547,7 +4868,8 @@ type AgentToolInterruptedReason =
|
|
|
4547
4868
|
| "not-tailable"
|
|
4548
4869
|
| "inspect-timeout"
|
|
4549
4870
|
| "inspect-failed"
|
|
4550
|
-
| "recovery-deadline"
|
|
4871
|
+
| "recovery-deadline"
|
|
4872
|
+
| "budget-exceeded";
|
|
4551
4873
|
/**
|
|
4552
4874
|
* Structured failure envelope an `agentTool()` returns when a sub-agent run
|
|
4553
4875
|
* does not complete. Instead of an opaque error string the parent model would
|
|
@@ -4580,6 +4902,70 @@ type AgentToolDisplayMetadata = {
|
|
|
4580
4902
|
name?: string;
|
|
4581
4903
|
icon?: string;
|
|
4582
4904
|
} & Record<string, unknown>;
|
|
4905
|
+
/**
|
|
4906
|
+
* Reserved chunk type a sub-agent emits via `reportProgress` while it runs.
|
|
4907
|
+
* Rides the child's own UI-message stream as a **transient** data part, so it
|
|
4908
|
+
* re-broadcasts to the parent's clients (via the parent's tail) and surfaces in
|
|
4909
|
+
* `useAgentToolEvents` without persisting into the child's stored message parts.
|
|
4910
|
+
* See `design/rfc-detached-agent-tools.md` §"Progress and milestone signaling".
|
|
4911
|
+
*/
|
|
4912
|
+
declare const AGENT_TOOL_PROGRESS_PART = "data-agent-progress";
|
|
4913
|
+
/**
|
|
4914
|
+
* Reserved chunk type a sub-agent emits via `reportProgress({ milestone })`.
|
|
4915
|
+
* Unlike the ephemeral progress part this rides the child's stream as a
|
|
4916
|
+
* **persisted** data part, so it survives eviction, replays on drill-in, and
|
|
4917
|
+
* re-resolves milestone waiters. See `design/rfc-detached-agent-tools.md`.
|
|
4918
|
+
*/
|
|
4919
|
+
declare const AGENT_TOOL_MILESTONE_PART = "data-agent-milestone";
|
|
4920
|
+
/**
|
|
4921
|
+
* Ephemeral progress signal a running sub-agent emits with `reportProgress`. The
|
|
4922
|
+
* well-known fields drive generic UI (a bar + status line) with no per-app
|
|
4923
|
+
* convention; `data` is an app-specific escape hatch that is **live-only** by
|
|
4924
|
+
* default (not persisted) unless `reportProgress(p, { persist: true })`. Naming a
|
|
4925
|
+
* `milestone` promotes the signal to the **durable** tier: it persists as one row
|
|
4926
|
+
* per milestone, replays, and (with `data`) is retained.
|
|
4927
|
+
*/
|
|
4928
|
+
type AgentToolProgress<T = unknown> = {
|
|
4929
|
+
/** 0..1 — drives a progress bar. */ fraction?: number /** Human-readable status line, e.g. "Ingested 40k/80k rows". */;
|
|
4930
|
+
message?: string /** Coarse stage label, e.g. "scaffolding" | "deploying". */;
|
|
4931
|
+
phase?: string;
|
|
4932
|
+
/**
|
|
4933
|
+
* Present ⇒ a **durable** milestone: persisted, replayable, and surfaced as a
|
|
4934
|
+
* distinct row in `AgentToolRunState.milestones` / `inspectAgentToolRun`. Use
|
|
4935
|
+
* for named phase boundaries ("schema-ready", "preview-ready", "deployed").
|
|
4936
|
+
*/
|
|
4937
|
+
milestone?: string /** App-specific payload; live-only for progress, persisted for milestones. */;
|
|
4938
|
+
data?: T;
|
|
4939
|
+
};
|
|
4940
|
+
/**
|
|
4941
|
+
* A durable milestone a sub-agent reached, projected onto `AgentToolRunState`
|
|
4942
|
+
* and `inspectAgentToolRun`. `sequence` is monotonic per run so replay/live
|
|
4943
|
+
* races dedupe on `(runId, sequence)`.
|
|
4944
|
+
*/
|
|
4945
|
+
type AgentToolMilestone = {
|
|
4946
|
+
name: string /** Monotonic per-run ordinal; dedupe key for replay vs live races. */;
|
|
4947
|
+
sequence: number /** Epoch ms the milestone was reached. */;
|
|
4948
|
+
at: number /** App-specific payload carried with the milestone (persisted). */;
|
|
4949
|
+
data?: unknown;
|
|
4950
|
+
};
|
|
4951
|
+
/**
|
|
4952
|
+
* Latest progress snapshot persisted on the child run row and surfaced through
|
|
4953
|
+
* `inspectAgentToolRun` + `AgentToolRunState`. Only the safe-to-inspect fields
|
|
4954
|
+
* are retained by default; `at` is the emit timestamp (drives the resetting
|
|
4955
|
+
* no-progress budget).
|
|
4956
|
+
*/
|
|
4957
|
+
type AgentToolProgressSnapshot = {
|
|
4958
|
+
fraction?: number;
|
|
4959
|
+
message?: string;
|
|
4960
|
+
phase?: string;
|
|
4961
|
+
/**
|
|
4962
|
+
* Set when this signal was a durable milestone (`reportProgress({ milestone })`).
|
|
4963
|
+
* Lets an `onProgress` consumer branch on milestone vs. ephemeral progress.
|
|
4964
|
+
*/
|
|
4965
|
+
milestone?: string /** Epoch ms of the latest signal. */;
|
|
4966
|
+
at: number /** Present only when the emitter opted into persisting `data`. */;
|
|
4967
|
+
data?: unknown;
|
|
4968
|
+
};
|
|
4583
4969
|
type AgentToolRunInfo = {
|
|
4584
4970
|
runId: string;
|
|
4585
4971
|
parentToolCallId?: string;
|
|
@@ -4587,6 +4973,11 @@ type AgentToolRunInfo = {
|
|
|
4587
4973
|
inputPreview?: unknown;
|
|
4588
4974
|
status: AgentToolRunStatus;
|
|
4589
4975
|
display?: AgentToolDisplayMetadata;
|
|
4976
|
+
/**
|
|
4977
|
+
* Caller-controlled `metadata.source` for chat-agent `detached.notify`
|
|
4978
|
+
* completions. Present only for detached notify runs that supplied one.
|
|
4979
|
+
*/
|
|
4980
|
+
notifySource?: string;
|
|
4590
4981
|
displayOrder: number;
|
|
4591
4982
|
startedAt: number;
|
|
4592
4983
|
completedAt?: number;
|
|
@@ -4602,7 +4993,80 @@ type AgentToolLifecycleResult = {
|
|
|
4602
4993
|
*/
|
|
4603
4994
|
childStillRunning?: boolean;
|
|
4604
4995
|
};
|
|
4605
|
-
|
|
4996
|
+
/**
|
|
4997
|
+
* Configuration for a detached ("background") agent-tool run. See
|
|
4998
|
+
* `design/rfc-detached-agent-tools.md`.
|
|
4999
|
+
*
|
|
5000
|
+
* Callbacks are referenced by **method name** on the dispatching agent (the same
|
|
5001
|
+
* durable, eviction-surviving pattern as `Agent.schedule`) — never closures,
|
|
5002
|
+
* which cannot be rehydrated after the Durable Object is evicted.
|
|
5003
|
+
*
|
|
5004
|
+
* `Self` is threaded from `runAgentTool(cls, options)` so the method names are
|
|
5005
|
+
* type-checked against the calling agent's own methods.
|
|
5006
|
+
*/
|
|
5007
|
+
type DetachedAgentToolConfig<Self = Record<string, unknown>> = {
|
|
5008
|
+
/**
|
|
5009
|
+
* Method invoked once per terminal delivery. Branch on `result.status`:
|
|
5010
|
+
* `"completed" | "error" | "aborted" | "interrupted"`. A budget give-up
|
|
5011
|
+
* arrives as `status: "interrupted"` with `reason: "budget-exceeded"`; because
|
|
5012
|
+
* `interrupted` is soft, a child that later completes can fire the hook again
|
|
5013
|
+
* with `"completed"`, so a give-up never hides a late real result. Make the
|
|
5014
|
+
* handler idempotent.
|
|
5015
|
+
*/
|
|
5016
|
+
onFinish?: Extract<keyof Self, string>;
|
|
5017
|
+
/**
|
|
5018
|
+
* Absolute safety ceiling — a backstop against a child that runs forever. On
|
|
5019
|
+
* expiry the parent gives up watching (delivers `onFinish` with
|
|
5020
|
+
* `interrupted` / `budget-exceeded`) and tears the child down. Defaults to the
|
|
5021
|
+
* parent-level `detachedMaxBudgetMs`.
|
|
5022
|
+
*/
|
|
5023
|
+
maxBudgetMs?: number;
|
|
5024
|
+
/**
|
|
5025
|
+
* Per-run override of the resetting no-progress window (ms). Once the child
|
|
5026
|
+
* emits its first `reportProgress`, the parent gives up if it then goes silent
|
|
5027
|
+
* for this long (resets on each signal). Defaults to the parent-level
|
|
5028
|
+
* `detachedNoProgressBudgetMs` (1h). `0`/`Infinity` disables it.
|
|
5029
|
+
*/
|
|
5030
|
+
noProgressBudgetMs?: number;
|
|
5031
|
+
/**
|
|
5032
|
+
* Chat-agent convenience (`@cloudflare/think` / `AIChatAgent`): when the run
|
|
5033
|
+
* finishes, inject a message into the chat so the model can react to the
|
|
5034
|
+
* result, instead of you wiring `onFinish` by hand. Sugar that auto-targets
|
|
5035
|
+
* the agent's `_cfDetachedNotifyFinish` hook; ignored on a base `Agent` that
|
|
5036
|
+
* does not implement it, and ignored when `onFinish` is also set (an explicit
|
|
5037
|
+
* `onFinish` wins). Pass `{ source }` to fit the injected message into your
|
|
5038
|
+
* app's existing metadata taxonomy. Override `formatDetachedCompletion()` to
|
|
5039
|
+
* customize the injected text.
|
|
5040
|
+
*/
|
|
5041
|
+
notify?:
|
|
5042
|
+
| boolean
|
|
5043
|
+
| {
|
|
5044
|
+
source?: string;
|
|
5045
|
+
};
|
|
5046
|
+
/**
|
|
5047
|
+
* Chat-agent convenience: milestone names that, when the detached run reaches
|
|
5048
|
+
* them, surface an idempotent synthetic message in the chat BEFORE the run
|
|
5049
|
+
* finishes. Each `(runId, name)` fires at most once (idempotency-keyed),
|
|
5050
|
+
* whether observed live or reconciled after eviction. Override the wording via
|
|
5051
|
+
* `formatDetachedMilestone()`. Requires a chat host (`@cloudflare/think`); a
|
|
5052
|
+
* no-op on a base `Agent`.
|
|
5053
|
+
*
|
|
5054
|
+
* Two delivery modes (the string-array shorthand defaults to `"narrate"`):
|
|
5055
|
+
* - `"narrate"` (default) — inject a synthetic **assistant** message directly
|
|
5056
|
+
* (no inference): a cheap, honest status line ("Found 2 sources…") that does
|
|
5057
|
+
* not trigger a model turn. Best for pure progress narration.
|
|
5058
|
+
* - `"react"` — inject a **user-role** turn so the model responds to the
|
|
5059
|
+
* milestone (steer, start dependent work, narrate with context). Costs a
|
|
5060
|
+
* model turn. Opt in for milestones the agent should *act on*.
|
|
5061
|
+
*/
|
|
5062
|
+
onMilestones?:
|
|
5063
|
+
| string[]
|
|
5064
|
+
| {
|
|
5065
|
+
names: string[];
|
|
5066
|
+
mode?: "react" | "narrate";
|
|
5067
|
+
};
|
|
5068
|
+
};
|
|
5069
|
+
type RunAgentToolOptions<Input = unknown, Self = Record<string, unknown>> = {
|
|
4606
5070
|
input: Input;
|
|
4607
5071
|
runId?: string;
|
|
4608
5072
|
parentToolCallId?: string;
|
|
@@ -4610,6 +5074,30 @@ type RunAgentToolOptions<Input = unknown> = {
|
|
|
4610
5074
|
signal?: AbortSignal;
|
|
4611
5075
|
inputPreview?: unknown;
|
|
4612
5076
|
display?: AgentToolDisplayMetadata;
|
|
5077
|
+
/**
|
|
5078
|
+
* Run the sub-agent **detached**: dispatch it, let the current turn continue,
|
|
5079
|
+
* and (optionally) get a durable callback when it finishes. `true` is
|
|
5080
|
+
* fire-and-forget (observe via `agent-tool-event` frames + the global
|
|
5081
|
+
* `onAgentToolFinish` hook); an object adds the targeted, eviction-surviving
|
|
5082
|
+
* `onFinish` callback. A detached run does NOT inherit `options.signal` — it
|
|
5083
|
+
* must outlive the spawning turn; cancel it explicitly via `cancelAgentTool`.
|
|
5084
|
+
*/
|
|
5085
|
+
detached?: boolean | DetachedAgentToolConfig<Self>;
|
|
5086
|
+
};
|
|
5087
|
+
/**
|
|
5088
|
+
* Result of dispatching a detached run. Returns immediately after dispatch
|
|
5089
|
+
* rather than after completion.
|
|
5090
|
+
*/
|
|
5091
|
+
type DetachedRunAgentToolResult = {
|
|
5092
|
+
runId: string;
|
|
5093
|
+
agentType: string;
|
|
5094
|
+
/**
|
|
5095
|
+
* `"running"` on a successful dispatch; `"error"` if dispatch itself failed
|
|
5096
|
+
* (e.g. the `maxConcurrentAgentTools` cap was exceeded — rejected
|
|
5097
|
+
* synchronously, no child started, no callback wired).
|
|
5098
|
+
*/
|
|
5099
|
+
status: "running" | "error";
|
|
5100
|
+
error?: string;
|
|
4613
5101
|
};
|
|
4614
5102
|
type RunAgentToolResult<Output = unknown> = {
|
|
4615
5103
|
runId: string;
|
|
@@ -4642,6 +5130,19 @@ type AgentToolRunInspection<Output = unknown> = {
|
|
|
4642
5130
|
error?: string;
|
|
4643
5131
|
startedAt: number;
|
|
4644
5132
|
completedAt?: number;
|
|
5133
|
+
/**
|
|
5134
|
+
* Latest progress snapshot the child has persisted, so a rehydrated parent
|
|
5135
|
+
* (recovery / backbone reconcile) can reconstruct "where is this run" and
|
|
5136
|
+
* reset the resetting no-progress budget without having tailed the live
|
|
5137
|
+
* stream. Absent until the child emits its first `reportProgress`.
|
|
5138
|
+
*/
|
|
5139
|
+
progress?: AgentToolProgressSnapshot;
|
|
5140
|
+
/**
|
|
5141
|
+
* Durable milestones the child has persisted, ordered by `sequence`. Lets a
|
|
5142
|
+
* rehydrated parent (recovery / backbone reconcile) replay milestone-gated
|
|
5143
|
+
* work and milestone notifications without having observed the live stream.
|
|
5144
|
+
*/
|
|
5145
|
+
milestones?: AgentToolMilestone[];
|
|
4645
5146
|
};
|
|
4646
5147
|
type AgentToolStoredChunk = {
|
|
4647
5148
|
sequence: number;
|
|
@@ -4721,7 +5222,10 @@ type AgentToolEventMessage = {
|
|
|
4721
5222
|
replay?: true;
|
|
4722
5223
|
event: AgentToolEvent;
|
|
4723
5224
|
};
|
|
4724
|
-
type
|
|
5225
|
+
type AgentToolRunPart = {
|
|
5226
|
+
type: string;
|
|
5227
|
+
};
|
|
5228
|
+
type AgentToolRunState<Part extends AgentToolRunPart = AgentToolRunPart> = {
|
|
4725
5229
|
runId: string;
|
|
4726
5230
|
agentType: string;
|
|
4727
5231
|
parentToolCallId?: string;
|
|
@@ -4729,7 +5233,15 @@ type AgentToolRunState = {
|
|
|
4729
5233
|
order: number;
|
|
4730
5234
|
display?: AgentToolDisplayMetadata;
|
|
4731
5235
|
status: "running" | "completed" | "error" | "aborted" | "interrupted";
|
|
4732
|
-
|
|
5236
|
+
/**
|
|
5237
|
+
* Message parts reconstructed from the child agent's streamed chunks.
|
|
5238
|
+
*
|
|
5239
|
+
* The default stays framework-neutral so importing `agents` does not require
|
|
5240
|
+
* an AI SDK peer. AI SDK consumers can use
|
|
5241
|
+
* `AgentToolRunState<UIMessage["parts"][number]>` when they need its exact
|
|
5242
|
+
* discriminated union.
|
|
5243
|
+
*/
|
|
5244
|
+
parts: Part[];
|
|
4733
5245
|
summary?: string;
|
|
4734
5246
|
error?: string;
|
|
4735
5247
|
/**
|
|
@@ -4739,120 +5251,141 @@ type AgentToolRunState = {
|
|
|
4739
5251
|
*/
|
|
4740
5252
|
reason?: AgentToolInterruptedReason;
|
|
4741
5253
|
childStillRunning?: boolean;
|
|
5254
|
+
/**
|
|
5255
|
+
* Latest progress snapshot, projected from the child's transient
|
|
5256
|
+
* `data-agent-progress` signals so a UI can render a bar / ETA / phase label
|
|
5257
|
+
* for a running (especially detached / background) run without drilling in.
|
|
5258
|
+
*/
|
|
5259
|
+
progress?: AgentToolProgressSnapshot;
|
|
5260
|
+
/**
|
|
5261
|
+
* Durable milestones the run has reached, ordered by `sequence` (deduped
|
|
5262
|
+
* across replay/live races). Drives milestone chips / a phase timeline.
|
|
5263
|
+
*/
|
|
5264
|
+
milestones?: AgentToolMilestone[];
|
|
4742
5265
|
subAgent: {
|
|
4743
5266
|
agent: string;
|
|
4744
5267
|
name: string;
|
|
4745
5268
|
};
|
|
4746
5269
|
};
|
|
4747
|
-
type AgentToolEventState = {
|
|
4748
|
-
runsById: Record<string, AgentToolRunState
|
|
4749
|
-
runsByToolCallId: Record<string, AgentToolRunState[]>;
|
|
4750
|
-
unboundRuns: AgentToolRunState[];
|
|
5270
|
+
type AgentToolEventState<Part extends AgentToolRunPart = AgentToolRunPart> = {
|
|
5271
|
+
runsById: Record<string, AgentToolRunState<Part>>;
|
|
5272
|
+
runsByToolCallId: Record<string, AgentToolRunState<Part>[]>;
|
|
5273
|
+
unboundRuns: AgentToolRunState<Part>[];
|
|
4751
5274
|
};
|
|
4752
5275
|
//#endregion
|
|
4753
5276
|
export {
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
getAgentByName as
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
5277
|
+
RoutingRetryOptions as $,
|
|
5278
|
+
McpClientOptions as $t,
|
|
5279
|
+
AgentGetOptions as A,
|
|
5280
|
+
getNamespacedData as At,
|
|
5281
|
+
EmailSendBinding as B,
|
|
5282
|
+
McpAgent as Bt,
|
|
5283
|
+
DetachedRunAgentToolResult as C,
|
|
5284
|
+
MCPConnectionResult as Ct,
|
|
5285
|
+
AddRpcMcpServerOptions as D,
|
|
5286
|
+
MCPServerOptions as Dt,
|
|
5287
|
+
AddMcpServerOptions as E,
|
|
5288
|
+
MCPServerFilter as Et,
|
|
5289
|
+
Connection$1 as F,
|
|
5290
|
+
RPCServerTransportOptions as Ft,
|
|
5291
|
+
FiberStatus as G,
|
|
5292
|
+
experimental_createMcpHandler as Gt,
|
|
5293
|
+
FiberInspection as H,
|
|
5294
|
+
DurableObjectEventStore as Ht,
|
|
5295
|
+
ConnectionContext$1 as I,
|
|
5296
|
+
RPC_DO_PREFIX as It,
|
|
5297
|
+
MCPServerMessage as J,
|
|
5298
|
+
TransportState as Jt,
|
|
5299
|
+
ListFibersOptions as K,
|
|
5300
|
+
McpAuthContext as Kt,
|
|
5301
|
+
DEFAULT_AGENT_STATIC_OPTIONS as L,
|
|
5302
|
+
ElicitRequest$1 as Lt,
|
|
5303
|
+
AgentOptions as M,
|
|
5304
|
+
RPCClientTransport as Mt,
|
|
5305
|
+
AgentStaticOptions as N,
|
|
5306
|
+
RPCClientTransportOptions as Nt,
|
|
5307
|
+
Agent as O,
|
|
5308
|
+
MCP_SERVER_ID_MAX_LENGTH as Ot,
|
|
5309
|
+
CallableMetadata as P,
|
|
5310
|
+
RPCServerTransport as Pt,
|
|
5311
|
+
RPCResponse as Q,
|
|
5312
|
+
StreamableHTTPEdgeClientTransport as Qt,
|
|
5313
|
+
DeleteFibersOptions as R,
|
|
5314
|
+
ElicitRequestSchema$1 as Rt,
|
|
5315
|
+
DetachedAgentToolConfig as S,
|
|
5316
|
+
MCPClientOAuthResult as St,
|
|
5317
|
+
RunAgentToolResult as T,
|
|
5318
|
+
MCPOAuthCallbackResult as Tt,
|
|
5319
|
+
FiberRecoveryContext as U,
|
|
5320
|
+
CreateMcpHandlerOptions as Ut,
|
|
5321
|
+
FiberContext as V,
|
|
5322
|
+
ClearableEventStore as Vt,
|
|
5323
|
+
FiberRecoveryResult as W,
|
|
5324
|
+
createMcpHandler as Wt,
|
|
5325
|
+
QueueItem as X,
|
|
5326
|
+
WorkerTransportOptions as Xt,
|
|
5327
|
+
MCPServersState as Y,
|
|
5328
|
+
WorkerTransport as Yt,
|
|
5329
|
+
RPCRequest as Z,
|
|
5330
|
+
SSEEdgeClientTransport as Zt,
|
|
5331
|
+
AgentToolRunState as _,
|
|
5332
|
+
MCPAITool as _t,
|
|
5333
|
+
AgentToolEvent as a,
|
|
5334
|
+
routeSubAgentRequest as an,
|
|
5335
|
+
StartFiberResult as at,
|
|
5336
|
+
AgentToolTerminalStatus as b,
|
|
5337
|
+
MCPClientManagerOptions as bt,
|
|
5338
|
+
AgentToolFailure as c,
|
|
5339
|
+
SubAgentClass as ct,
|
|
5340
|
+
AgentToolMilestone as d,
|
|
5341
|
+
callable as dt,
|
|
5342
|
+
TransportType as en,
|
|
5343
|
+
Schedule as et,
|
|
5344
|
+
AgentToolProgress as f,
|
|
5345
|
+
getAgentByName as ft,
|
|
5346
|
+
AgentToolRunPart as g,
|
|
5347
|
+
unstable_callable as gt,
|
|
5348
|
+
AgentToolRunInspection as h,
|
|
5349
|
+
routeAgentRequest as ht,
|
|
5350
|
+
AgentToolDisplayMetadata as i,
|
|
5351
|
+
parseSubAgentPath as in,
|
|
5352
|
+
StartFiberOptions as it,
|
|
5353
|
+
AgentNamespace as j,
|
|
5354
|
+
normalizeServerId as jt,
|
|
5355
|
+
AgentContext as k,
|
|
5356
|
+
RegisterServerOptions as kt,
|
|
5357
|
+
AgentToolInterruptedReason as l,
|
|
5358
|
+
SubAgentStub as lt,
|
|
5359
|
+
AgentToolRunInfo as m,
|
|
5360
|
+
routeAgentEmail as mt,
|
|
5361
|
+
AGENT_TOOL_PROGRESS_PART as n,
|
|
5362
|
+
SubAgentPathMatch as nn,
|
|
5363
|
+
SendEmailOptions as nt,
|
|
5364
|
+
AgentToolEventMessage as o,
|
|
5365
|
+
StateUpdateMessage as ot,
|
|
5366
|
+
AgentToolProgressSnapshot as p,
|
|
5367
|
+
getCurrentAgent as pt,
|
|
5368
|
+
MCPServer as q,
|
|
5369
|
+
getMcpAuthContext as qt,
|
|
5370
|
+
AgentToolChildAdapter as r,
|
|
5371
|
+
getSubAgentByName as rn,
|
|
5372
|
+
SqlError as rt,
|
|
5373
|
+
AgentToolEventState as s,
|
|
5374
|
+
StreamingResponse as st,
|
|
5375
|
+
AGENT_TOOL_MILESTONE_PART as t,
|
|
5376
|
+
SUB_PREFIX as tn,
|
|
5377
|
+
ScheduleCriteria as tt,
|
|
5378
|
+
AgentToolLifecycleResult as u,
|
|
5379
|
+
WSMessage$1 as ut,
|
|
5380
|
+
AgentToolRunStatus as v,
|
|
5381
|
+
MCPAIToolSet as vt,
|
|
5382
|
+
RunAgentToolOptions as w,
|
|
5383
|
+
MCPDiscoverResult as wt,
|
|
5384
|
+
ChatCapableAgentClass as x,
|
|
5385
|
+
MCPClientOAuthCallbackConfig as xt,
|
|
5386
|
+
AgentToolStoredChunk as y,
|
|
5387
|
+
MCPClientManager as yt,
|
|
5388
|
+
EmailRoutingOptions as z,
|
|
5389
|
+
ElicitResult$1 as zt
|
|
4857
5390
|
};
|
|
4858
|
-
//# sourceMappingURL=agent-tool-types-
|
|
5391
|
+
//# sourceMappingURL=agent-tool-types-CNyE1iz_.d.ts.map
|