agents 0.17.4 → 0.19.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.
- package/dist/{agent-tool-types-OhWqAbCp.d.ts → agent-tool-types-BNUGGBzQ.d.ts} +30 -11
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-LdNKGZT9.d.ts → agent-tools-BFbzVLFc.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/browser/tanstack-ai.js +3 -2
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/chat/index.d.ts +29 -9
- package/dist/chat/index.js +32 -42
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +25 -1
- package/dist/chat/react.js +249 -93
- package/dist/chat/react.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/{client-C7F0MaVz.js → client-CcjiFpTf.js} +176 -42
- package/dist/client-CcjiFpTf.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/cloudflare-BldFV0Pa.js +117 -0
- package/dist/cloudflare-BldFV0Pa.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +118 -43
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/observability/ai/index.d.ts +155 -0
- package/dist/observability/ai/index.js +1848 -0
- package/dist/observability/ai/index.js.map +1 -0
- package/dist/react.d.ts +1 -1
- package/dist/{retries-CvHJwSuh.d.ts → retries-CAvxtG9d.d.ts} +16 -7
- package/dist/retries.d.ts +8 -6
- package/dist/retries.js +20 -2
- package/dist/retries.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/sub-routing.d.ts +1 -1
- package/dist/vite.d.ts +4 -4
- package/dist/vite.js +4 -2
- package/dist/vite.js.map +1 -1
- package/dist/{wire-types-nflOzNuU.js → wire-types-CU9rLoeS.js} +33 -2
- package/dist/wire-types-CU9rLoeS.js.map +1 -0
- package/dist/workflows.d.ts +1 -1
- package/docs/agent-class.md +9 -1
- package/docs/configuration.md +20 -0
- package/docs/mcp-client.md +13 -4
- package/docs/observability.md +282 -0
- package/package.json +11 -6
- package/dist/client-C7F0MaVz.js.map +0 -1
- package/dist/wire-types-nflOzNuU.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
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-CAvxtG9d.js";
|
|
3
3
|
import {
|
|
4
4
|
n as Observability,
|
|
5
5
|
r as ObservabilityEvent,
|
|
@@ -800,15 +800,16 @@ type MCPTransportOptions = (
|
|
|
800
800
|
authProvider?: AgentMcpOAuthProvider;
|
|
801
801
|
type?: TransportType;
|
|
802
802
|
};
|
|
803
|
-
/**
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
803
|
+
/** Result of discovering server capabilities. */
|
|
804
|
+
type MCPDiscoveryResult =
|
|
805
|
+
| {
|
|
806
|
+
success: true;
|
|
807
|
+
}
|
|
808
|
+
| {
|
|
809
|
+
success: false;
|
|
810
|
+
reason: "error" | "stale-session";
|
|
811
|
+
error: string;
|
|
812
|
+
};
|
|
812
813
|
/**
|
|
813
814
|
* Handler for server-initiated `elicitation/create` requests.
|
|
814
815
|
* Held in memory only — never persisted — so it must be re-supplied when a
|
|
@@ -1104,6 +1105,8 @@ declare class MCPClientConnection {
|
|
|
1104
1105
|
handleElicitationRequest(request: ElicitRequest): Promise<ElicitResult>;
|
|
1105
1106
|
private isResumedStreamableHttpSession;
|
|
1106
1107
|
get sessionId(): string | undefined;
|
|
1108
|
+
/** @internal Clear a restored session before reconnecting. */
|
|
1109
|
+
clearResumedSession(): void;
|
|
1107
1110
|
private getTransportName;
|
|
1108
1111
|
close(): Promise<void>;
|
|
1109
1112
|
/**
|
|
@@ -1296,6 +1299,8 @@ declare class MCPClientManager {
|
|
|
1296
1299
|
private _name;
|
|
1297
1300
|
private _version;
|
|
1298
1301
|
mcpConnections: Record<string, MCPClientConnection>;
|
|
1302
|
+
/** Cache only the current catalog so old schema graphs are not retained. */
|
|
1303
|
+
private readonly _aiToolSchemas;
|
|
1299
1304
|
private _didWarnAboutUnstableGetAITools;
|
|
1300
1305
|
private _oauthCallbackConfig?;
|
|
1301
1306
|
private _connectionDisposables;
|
|
@@ -1382,6 +1387,8 @@ declare class MCPClientManager {
|
|
|
1382
1387
|
private isAuthAcceptedConnection;
|
|
1383
1388
|
private oauthCallbackSuccess;
|
|
1384
1389
|
private runWithCodeVerifierState;
|
|
1390
|
+
private hasRedeemableOAuthState;
|
|
1391
|
+
private ignoreUnverifiedCallback;
|
|
1385
1392
|
private consumeStaleOAuthState;
|
|
1386
1393
|
private completeAuthorizationAndCleanupVerifier;
|
|
1387
1394
|
/**
|
|
@@ -1433,6 +1440,7 @@ declare class MCPClientManager {
|
|
|
1433
1440
|
* `undefined` (default) waits indefinitely.
|
|
1434
1441
|
*/
|
|
1435
1442
|
waitForConnections(options?: { timeout?: number }): Promise<void>;
|
|
1443
|
+
private _connectWithRetry;
|
|
1436
1444
|
/**
|
|
1437
1445
|
* Internal method to restore a single server connection and discovery
|
|
1438
1446
|
*/
|
|
@@ -1516,6 +1524,8 @@ declare class MCPClientManager {
|
|
|
1516
1524
|
timeoutMs?: number;
|
|
1517
1525
|
}
|
|
1518
1526
|
): Promise<MCPDiscoverResult | undefined>;
|
|
1527
|
+
private _toDiscoverResult;
|
|
1528
|
+
private _recoverStaleSession;
|
|
1519
1529
|
/**
|
|
1520
1530
|
* Establish connection in the background after OAuth completion.
|
|
1521
1531
|
* This method connects to the server and discovers its capabilities.
|
|
@@ -1568,6 +1578,10 @@ declare class MCPClientManager {
|
|
|
1568
1578
|
*/
|
|
1569
1579
|
listTools(filter?: MCPServerFilter): NamespacedData["tools"];
|
|
1570
1580
|
/**
|
|
1581
|
+
* Convert connected MCP tools for the AI SDK. Converted schemas are reused
|
|
1582
|
+
* while a live connection retains the same catalog array and schema-source
|
|
1583
|
+
* identities; tool records and execute closures are rebuilt on every call.
|
|
1584
|
+
*
|
|
1571
1585
|
* @param filter - Optional filter to scope results to specific servers
|
|
1572
1586
|
* @returns a set of tools that you can use with the AI SDK
|
|
1573
1587
|
*/
|
|
@@ -2733,6 +2747,8 @@ declare class Agent<
|
|
|
2733
2747
|
type: ObservabilityEvent["type"],
|
|
2734
2748
|
payload?: Record<string, unknown>
|
|
2735
2749
|
): void;
|
|
2750
|
+
/** Run SDK work under a stable parent for platform child spans. */
|
|
2751
|
+
private _withAgentSpan;
|
|
2736
2752
|
/**
|
|
2737
2753
|
* Execute SQL queries against the Agent's database
|
|
2738
2754
|
* @template T Type of the returned rows
|
|
@@ -2744,6 +2760,7 @@ declare class Agent<
|
|
|
2744
2760
|
strings: TemplateStringsArray,
|
|
2745
2761
|
...values: (string | number | boolean | null)[]
|
|
2746
2762
|
): T[];
|
|
2763
|
+
private _schemaInitialization;
|
|
2747
2764
|
/**
|
|
2748
2765
|
* Create all internal tables and run migrations if needed.
|
|
2749
2766
|
* Called by the constructor on every wake. Idempotent — skips DDL when
|
|
@@ -3527,6 +3544,7 @@ declare class Agent<
|
|
|
3527
3544
|
*/
|
|
3528
3545
|
private _hasPendingFiberRecovery;
|
|
3529
3546
|
private _scheduleNextAlarm;
|
|
3547
|
+
private _scheduleNextAlarmBody;
|
|
3530
3548
|
/**
|
|
3531
3549
|
* Override PartyServer's onAlarm hook as a no-op.
|
|
3532
3550
|
* Agent handles alarm logic directly in the alarm() method override,
|
|
@@ -4769,6 +4787,7 @@ declare class Agent<
|
|
|
4769
4787
|
state: typeof MCPConnectionState.READY;
|
|
4770
4788
|
}
|
|
4771
4789
|
>;
|
|
4790
|
+
private _redeemableAuthUrl;
|
|
4772
4791
|
private _isAbsoluteHttpUrl;
|
|
4773
4792
|
removeMcpServer(id: string): Promise<void>;
|
|
4774
4793
|
getMcpServers(): MCPServersState;
|
|
@@ -5499,4 +5518,4 @@ export {
|
|
|
5499
5518
|
EmailRoutingOptions as z,
|
|
5500
5519
|
RPCServerTransportOptions as zt
|
|
5501
5520
|
};
|
|
5502
|
-
//# sourceMappingURL=agent-tool-types-
|
|
5521
|
+
//# sourceMappingURL=agent-tool-types-BNUGGBzQ.d.ts.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
o as AgentToolEventMessage,
|
|
5
5
|
s as AgentToolEventState,
|
|
6
6
|
y as AgentToolStoredChunk
|
|
7
|
-
} from "./agent-tool-types-
|
|
7
|
+
} from "./agent-tool-types-BNUGGBzQ.js";
|
|
8
8
|
|
|
9
9
|
//#region src/chat/agent-tools.d.ts
|
|
10
10
|
type AgentToolProgressEmitResult = "emitted" | "coalesced" | "inactive";
|
|
@@ -130,4 +130,4 @@ export {
|
|
|
130
130
|
interceptAgentToolBroadcast as s,
|
|
131
131
|
AgentToolBroadcastHooks as t
|
|
132
132
|
};
|
|
133
|
-
//# sourceMappingURL=agent-tools-
|
|
133
|
+
//# sourceMappingURL=agent-tools-BFbzVLFc.d.ts.map
|
package/dist/agent-tools.d.ts
CHANGED
|
@@ -41,13 +41,14 @@ function createBrowserTools(options) {
|
|
|
41
41
|
const executeTool = tools.browser_execute;
|
|
42
42
|
return [toolDefinition({
|
|
43
43
|
name: "browser_execute",
|
|
44
|
-
description: executeTool.description ?? "",
|
|
44
|
+
description: typeof executeTool.description === "function" ? "" : executeTool.description ?? "",
|
|
45
45
|
inputSchema: z.object({ code: z.string().meta({ description: "TypeScript async arrow function that uses the cdp connector" }) })
|
|
46
46
|
}).server(async ({ code }) => {
|
|
47
47
|
if (!executeTool.execute) throw new Error("browser_execute tool is not executable");
|
|
48
48
|
return await executeTool.execute({ code }, {
|
|
49
49
|
toolCallId: crypto.randomUUID(),
|
|
50
|
-
messages: []
|
|
50
|
+
messages: [],
|
|
51
|
+
context: {}
|
|
51
52
|
});
|
|
52
53
|
})];
|
|
53
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-ai.js","names":[],"sources":["../../src/browser/tanstack-ai.ts"],"sourcesContent":["import { toolDefinition } from \"@tanstack/ai\";\nimport type { ServerTool } from \"@tanstack/ai\";\nimport type { ProxyToolOutput } from \"@cloudflare/codemode\";\nimport { z } from \"zod\";\nimport { createBrowserRuntime, type CreateBrowserToolsOptions } from \"./ai\";\n\nexport type { CreateBrowserToolsOptions } from \"./ai\";\n\n/**\n * Create TanStack AI tools for browser automation via CDP code mode.\n *\n * Returns an array with a single durable `browser_execute` `ServerTool`\n * backed by the same codemode runtime as `agents/browser/ai` — the model\n * writes TypeScript against the `cdp` connector and browser sessions\n * survive pauses.\n *\n * The stateless Quick Action tools are not surfaced through this TanStack\n * wrapper (it exposes only `browser_execute`); use `createQuickActionTools`\n * from `agents/browser/ai` if you want them.\n *\n * @example\n * ```ts\n * import { createBrowserTools } from \"agents/browser/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * // inside a Durable Object / Agent:\n * const browserTools = createBrowserTools({\n * ctx: this.ctx,\n * browser: this.env.BROWSER,\n * loader: this.env.LOADER,\n * });\n *\n * const stream = chat({\n * adapter: openaiText(\"gpt-4o\"),\n * tools: [...browserTools, ...otherTools],\n * messages,\n * });\n * ```\n */\nexport function createBrowserTools(\n options: CreateBrowserToolsOptions\n): ServerTool[] {\n // This wrapper only surfaces `browser_execute`, so don't build the default-on\n // Quick Action tools just to discard them.\n const { tools } = createBrowserRuntime({ ...options, quickActions: false });\n const executeTool = tools.browser_execute;\n\n const execute = toolDefinition({\n name: \"browser_execute\" as const,\n description: executeTool.description ?? \"\",\n inputSchema: z.object({\n code: z.string().meta({\n description:\n \"TypeScript async arrow function that uses the cdp connector\"\n })\n })\n }).server(async ({ code }) => {\n if (!executeTool.execute) {\n throw new Error(\"browser_execute tool is not executable\");\n }\n const result = (await executeTool.execute(
|
|
1
|
+
{"version":3,"file":"tanstack-ai.js","names":[],"sources":["../../src/browser/tanstack-ai.ts"],"sourcesContent":["import { toolDefinition } from \"@tanstack/ai\";\nimport type { ServerTool } from \"@tanstack/ai\";\nimport type { ProxyToolOutput } from \"@cloudflare/codemode\";\nimport { z } from \"zod\";\nimport { createBrowserRuntime, type CreateBrowserToolsOptions } from \"./ai\";\n\nexport type { CreateBrowserToolsOptions } from \"./ai\";\n\n/**\n * Create TanStack AI tools for browser automation via CDP code mode.\n *\n * Returns an array with a single durable `browser_execute` `ServerTool`\n * backed by the same codemode runtime as `agents/browser/ai` — the model\n * writes TypeScript against the `cdp` connector and browser sessions\n * survive pauses.\n *\n * The stateless Quick Action tools are not surfaced through this TanStack\n * wrapper (it exposes only `browser_execute`); use `createQuickActionTools`\n * from `agents/browser/ai` if you want them.\n *\n * @example\n * ```ts\n * import { createBrowserTools } from \"agents/browser/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * // inside a Durable Object / Agent:\n * const browserTools = createBrowserTools({\n * ctx: this.ctx,\n * browser: this.env.BROWSER,\n * loader: this.env.LOADER,\n * });\n *\n * const stream = chat({\n * adapter: openaiText(\"gpt-4o\"),\n * tools: [...browserTools, ...otherTools],\n * messages,\n * });\n * ```\n */\nexport function createBrowserTools(\n options: CreateBrowserToolsOptions\n): ServerTool[] {\n // This wrapper only surfaces `browser_execute`, so don't build the default-on\n // Quick Action tools just to discard them.\n const { tools } = createBrowserRuntime({ ...options, quickActions: false });\n const executeTool = tools.browser_execute;\n\n const execute = toolDefinition({\n name: \"browser_execute\" as const,\n description:\n typeof executeTool.description === \"function\"\n ? \"\"\n : (executeTool.description ?? \"\"),\n inputSchema: z.object({\n code: z.string().meta({\n description:\n \"TypeScript async arrow function that uses the cdp connector\"\n })\n })\n }).server(async ({ code }) => {\n if (!executeTool.execute) {\n throw new Error(\"browser_execute tool is not executable\");\n }\n const result = (await executeTool.execute({ code }, {\n toolCallId: crypto.randomUUID(),\n messages: [],\n context: {}\n } as never)) as ProxyToolOutput;\n return result;\n });\n\n return [execute];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,mBACd,SACc;CAGd,MAAM,EAAE,UAAU,qBAAqB;EAAE,GAAG;EAAS,cAAc;CAAM,CAAC;CAC1E,MAAM,cAAc,MAAM;CA0B1B,OAAO,CAxBS,eAAe;EAC7B,MAAM;EACN,aACE,OAAO,YAAY,gBAAgB,aAC/B,KACC,YAAY,eAAe;EAClC,aAAa,EAAE,OAAO,EACpB,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,EACpB,aACE,8DACJ,CAAC,EACH,CAAC;CACH,CAAC,CAAC,CAAC,OAAO,OAAO,EAAE,WAAW;EAC5B,IAAI,CAAC,YAAY,SACf,MAAM,IAAI,MAAM,wCAAwC;EAO1D,OAAO,MALe,YAAY,QAAQ,EAAE,KAAK,GAAG;GAClD,YAAY,OAAO,WAAW;GAC9B,UAAU,CAAC;GACX,SAAS,CAAC;EACZ,CAAU;CAEZ,CAEc,CAAC;AACjB"}
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
a as AgentToolEvent,
|
|
5
5
|
o as AgentToolEventMessage,
|
|
6
6
|
s as AgentToolEventState
|
|
7
|
-
} from "../agent-tool-types-
|
|
7
|
+
} from "../agent-tool-types-BNUGGBzQ.js";
|
|
8
8
|
import {
|
|
9
9
|
n as ClientToolSchema,
|
|
10
10
|
r as createToolsFromClientSchemas,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
r as AgentToolProgressEmitResult,
|
|
19
19
|
s as interceptAgentToolBroadcast,
|
|
20
20
|
t as AgentToolBroadcastHooks
|
|
21
|
-
} from "../agent-tools-
|
|
21
|
+
} from "../agent-tools-BFbzVLFc.js";
|
|
22
22
|
import { JSONSchema7, UIMessage } from "ai";
|
|
23
23
|
import { Connection } from "agents";
|
|
24
24
|
|
|
@@ -987,6 +987,12 @@ declare function buildInClauseStrings(
|
|
|
987
987
|
* clients. Both @cloudflare/ai-chat (via its MessageType enum) and
|
|
988
988
|
* @cloudflare/think use these values.
|
|
989
989
|
*/
|
|
990
|
+
declare const STREAM_RESUME_NONE_REASONS: {
|
|
991
|
+
/** No active, pending, or terminal stream exists for this agent. */ readonly IDLE: "idle" /** An active tool continuation is owned by another live connection. */;
|
|
992
|
+
readonly CONTINUATION_OWNED: "continuation-owned";
|
|
993
|
+
};
|
|
994
|
+
type StreamResumeNoneReason =
|
|
995
|
+
(typeof STREAM_RESUME_NONE_REASONS)[keyof typeof STREAM_RESUME_NONE_REASONS];
|
|
990
996
|
declare const CHAT_MESSAGE_TYPES: {
|
|
991
997
|
readonly CHAT_MESSAGES: "cf_agent_chat_messages";
|
|
992
998
|
readonly USE_CHAT_REQUEST: "cf_agent_use_chat_request";
|
|
@@ -1069,14 +1075,21 @@ type OutgoingMessage<ChatMessage extends UIMessage = UIMessage> =
|
|
|
1069
1075
|
}
|
|
1070
1076
|
| {
|
|
1071
1077
|
/** Indicates the server is resuming an active stream */ type: MessageType.CF_AGENT_STREAM_RESUMING /** The request ID of the stream being resumed */;
|
|
1072
|
-
id: string
|
|
1078
|
+
id: string /** Present when this offer directly answers a client resume probe. */;
|
|
1079
|
+
probeId?: string;
|
|
1073
1080
|
}
|
|
1074
1081
|
| {
|
|
1075
1082
|
/** Server notifies client that a message was updated (e.g., tool result applied) */ type: MessageType.CF_AGENT_MESSAGE_UPDATED /** The updated message */;
|
|
1076
1083
|
message: ChatMessage;
|
|
1077
1084
|
}
|
|
1078
1085
|
| {
|
|
1079
|
-
/** Server responds to resume request
|
|
1086
|
+
/** Server responds to a resume request with no stream for this client. */ type: MessageType.CF_AGENT_STREAM_RESUME_NONE;
|
|
1087
|
+
/**
|
|
1088
|
+
* Why no stream was offered. Only `idle` proves global inactivity;
|
|
1089
|
+
* omitted by older servers and by non-authoritative delayed releases.
|
|
1090
|
+
*/
|
|
1091
|
+
reason?: StreamResumeNoneReason /** Correlates an authoritative response to its client resume probe. */;
|
|
1092
|
+
probeId?: string;
|
|
1080
1093
|
}
|
|
1081
1094
|
| {
|
|
1082
1095
|
/**
|
|
@@ -1085,7 +1098,8 @@ type OutgoingMessage<ChatMessage extends UIMessage = UIMessage> =
|
|
|
1085
1098
|
* `STREAM_RESUME_NONE`) rather than give up. See #1784.
|
|
1086
1099
|
*/
|
|
1087
1100
|
type: MessageType.CF_AGENT_STREAM_PENDING /** The accepted request id, when known. */;
|
|
1088
|
-
id?: string
|
|
1101
|
+
id?: string /** Correlates a direct keep-waiting response to its client probe. */;
|
|
1102
|
+
probeId?: string;
|
|
1089
1103
|
}
|
|
1090
1104
|
| {
|
|
1091
1105
|
/**
|
|
@@ -1135,7 +1149,8 @@ type IncomingMessage<ChatMessage extends UIMessage = UIMessage> =
|
|
|
1135
1149
|
id: string;
|
|
1136
1150
|
}
|
|
1137
1151
|
| {
|
|
1138
|
-
/** Client requests stream resume check after message handler is registered */ type: MessageType.CF_AGENT_STREAM_RESUME_REQUEST
|
|
1152
|
+
/** Client requests stream resume check after message handler is registered */ type: MessageType.CF_AGENT_STREAM_RESUME_REQUEST /** Opaque correlation id echoed by direct server responses. */;
|
|
1153
|
+
probeId?: string;
|
|
1139
1154
|
}
|
|
1140
1155
|
| {
|
|
1141
1156
|
/** Client sends tool result to server (for client-side tools) */ type: MessageType.CF_AGENT_TOOL_RESULT /** The tool call ID this result is for */;
|
|
@@ -1299,7 +1314,7 @@ declare class PreStreamTurns<
|
|
|
1299
1314
|
* `pendingResumeConnections` — they must keep receiving any live broadcast —
|
|
1300
1315
|
* until the host flushes them through `notifyStreamResuming` on stream start.
|
|
1301
1316
|
*/
|
|
1302
|
-
park(connection: TConnection): boolean;
|
|
1317
|
+
park(connection: TConnection, probeId?: string): boolean;
|
|
1303
1318
|
/** Drop a single connection (e.g. on socket close) without releasing others. */
|
|
1304
1319
|
release(connectionId: string): void;
|
|
1305
1320
|
/**
|
|
@@ -1774,6 +1789,7 @@ type ChatProtocolEvent =
|
|
|
1774
1789
|
}
|
|
1775
1790
|
| {
|
|
1776
1791
|
type: "stream-resume-request";
|
|
1792
|
+
probeId?: string;
|
|
1777
1793
|
}
|
|
1778
1794
|
| {
|
|
1779
1795
|
type: "stream-resume-ack";
|
|
@@ -3153,14 +3169,16 @@ declare class ResumeHandshake {
|
|
|
3153
3169
|
* `reconnectToStream` hangs to its timeout with no replay), and the proactive
|
|
3154
3170
|
* notify is required for clients that never send a request. The notify is one
|
|
3155
3171
|
* tiny frame; the client dedupes its ACK so the buffer is not replayed twice.
|
|
3172
|
+
* Direct responses echo the opaque probe id; proactive notifications omit it.
|
|
3156
3173
|
*/
|
|
3157
|
-
notifyStreamResuming(connection: Connection): void;
|
|
3174
|
+
notifyStreamResuming(connection: Connection, probeId?: string): void;
|
|
3158
3175
|
/**
|
|
3159
3176
|
* Handle a client `STREAM_RESUME_REQUEST`. The client sends this after its
|
|
3160
3177
|
* message handler is registered, avoiding the race where a proactive
|
|
3161
3178
|
* `STREAM_RESUMING` from onConnect arrives before the handler is ready.
|
|
3162
3179
|
*/
|
|
3163
|
-
handleResumeRequest(connection: Connection): Promise<void>;
|
|
3180
|
+
handleResumeRequest(connection: Connection, probeId?: string): Promise<void>;
|
|
3181
|
+
private _sendResumeNone;
|
|
3164
3182
|
/** Send a keep-waiting `STREAM_PENDING` frame (#1784). */
|
|
3165
3183
|
private _sendStreamPending;
|
|
3166
3184
|
/** Whether the active continuation's owner connection is still present. */
|
|
@@ -3324,6 +3342,7 @@ export {
|
|
|
3324
3342
|
ResumeHandshake,
|
|
3325
3343
|
type ResumeHandshakeHost,
|
|
3326
3344
|
STREAM_CLEANUP_DELAY_SECONDS,
|
|
3345
|
+
STREAM_RESUME_NONE_REASONS,
|
|
3327
3346
|
type SaveMessagesOptions,
|
|
3328
3347
|
type SaveMessagesResult,
|
|
3329
3348
|
type SnapshotMessage,
|
|
@@ -3332,6 +3351,7 @@ export {
|
|
|
3332
3351
|
type StreamAccumulatorOptions,
|
|
3333
3352
|
type StreamChunkData,
|
|
3334
3353
|
StreamProgressCreditThrottle,
|
|
3354
|
+
type StreamResumeNoneReason,
|
|
3335
3355
|
SubmitConcurrencyController,
|
|
3336
3356
|
type SubmitConcurrencyDecision,
|
|
3337
3357
|
TIMED_OUT,
|
package/dist/chat/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as normalizeToolInput, n as getPartialStreamText, r as isReplayChunk, t as applyChunkToParts } from "../message-builder-BymO4N_D.js";
|
|
2
2
|
import { i as interceptAgentToolBroadcast, n as applyAgentToolEvent, r as createAgentToolEventState, t as AgentToolProgressEmitter } from "../agent-tools-y7zLfw4Q.js";
|
|
3
3
|
import { t as truncateToolOutput } from "../tool-output-truncation-CNnnGZQ3.js";
|
|
4
|
-
import {
|
|
4
|
+
import { a as StreamAccumulator, i as transition, n as CHAT_MESSAGE_TYPES, r as STREAM_RESUME_NONE_REASONS, t as MessageType } from "../wire-types-CU9rLoeS.js";
|
|
5
5
|
import { jsonSchema, tool } from "ai";
|
|
6
6
|
import { nanoid } from "nanoid";
|
|
7
7
|
//#region src/chat/sanitize.ts
|
|
@@ -335,31 +335,6 @@ var SubmitConcurrencyController = class {
|
|
|
335
335
|
}
|
|
336
336
|
};
|
|
337
337
|
//#endregion
|
|
338
|
-
//#region src/chat/protocol.ts
|
|
339
|
-
/**
|
|
340
|
-
* Wire protocol message type constants for the cf_agent_chat_* protocol.
|
|
341
|
-
*
|
|
342
|
-
* These are the string values used on the wire between agent servers and
|
|
343
|
-
* clients. Both @cloudflare/ai-chat (via its MessageType enum) and
|
|
344
|
-
* @cloudflare/think use these values.
|
|
345
|
-
*/
|
|
346
|
-
const CHAT_MESSAGE_TYPES = {
|
|
347
|
-
CHAT_MESSAGES: "cf_agent_chat_messages",
|
|
348
|
-
USE_CHAT_REQUEST: "cf_agent_use_chat_request",
|
|
349
|
-
USE_CHAT_RESPONSE: "cf_agent_use_chat_response",
|
|
350
|
-
CHAT_CLEAR: "cf_agent_chat_clear",
|
|
351
|
-
CHAT_REQUEST_CANCEL: "cf_agent_chat_request_cancel",
|
|
352
|
-
STREAM_RESUMING: "cf_agent_stream_resuming",
|
|
353
|
-
STREAM_RESUME_ACK: "cf_agent_stream_resume_ack",
|
|
354
|
-
STREAM_RESUME_REQUEST: "cf_agent_stream_resume_request",
|
|
355
|
-
STREAM_RESUME_NONE: "cf_agent_stream_resume_none",
|
|
356
|
-
STREAM_PENDING: "cf_agent_stream_pending",
|
|
357
|
-
TOOL_RESULT: "cf_agent_tool_result",
|
|
358
|
-
TOOL_APPROVAL: "cf_agent_tool_approval",
|
|
359
|
-
MESSAGE_UPDATED: "cf_agent_message_updated",
|
|
360
|
-
CHAT_RECOVERING: "cf_agent_chat_recovering"
|
|
361
|
-
};
|
|
362
|
-
//#endregion
|
|
363
338
|
//#region src/chat/connection.ts
|
|
364
339
|
/**
|
|
365
340
|
* Send a message on a connection, swallowing the specific
|
|
@@ -1056,7 +1031,7 @@ function createToolsFromClientSchemas(clientTools, options) {
|
|
|
1056
1031
|
const execute = options?.execute;
|
|
1057
1032
|
const createTool = tool;
|
|
1058
1033
|
return Object.fromEntries(clientTools.map((t) => [t.name, createTool({
|
|
1059
|
-
description: t.description ?? "",
|
|
1034
|
+
description: typeof t.description === "function" ? "" : t.description ?? "",
|
|
1060
1035
|
inputSchema: jsonSchema(t.parameters ?? { type: "object" }),
|
|
1061
1036
|
...execute ? { execute: (input, executeOptions) => execute({
|
|
1062
1037
|
toolName: t.name,
|
|
@@ -1245,12 +1220,13 @@ var PreStreamTurns = class {
|
|
|
1245
1220
|
* `pendingResumeConnections` — they must keep receiving any live broadcast —
|
|
1246
1221
|
* until the host flushes them through `notifyStreamResuming` on stream start.
|
|
1247
1222
|
*/
|
|
1248
|
-
park(connection) {
|
|
1223
|
+
park(connection, probeId) {
|
|
1249
1224
|
if (!this.hasInFlight()) return false;
|
|
1250
1225
|
this.awaitingConnections.set(connection.id, connection);
|
|
1251
1226
|
sendIfOpen(connection, JSON.stringify({
|
|
1252
1227
|
type: MSG_STREAM_PENDING,
|
|
1253
|
-
...this._latestRequestId ? { id: this._latestRequestId } : {}
|
|
1228
|
+
...this._latestRequestId ? { id: this._latestRequestId } : {},
|
|
1229
|
+
...probeId ? { probeId } : {}
|
|
1254
1230
|
}));
|
|
1255
1231
|
return true;
|
|
1256
1232
|
}
|
|
@@ -1870,7 +1846,10 @@ function parseProtocolMessage(raw) {
|
|
|
1870
1846
|
approved: data.approved,
|
|
1871
1847
|
autoContinue: data.autoContinue
|
|
1872
1848
|
};
|
|
1873
|
-
case CHAT_MESSAGE_TYPES.STREAM_RESUME_REQUEST: return {
|
|
1849
|
+
case CHAT_MESSAGE_TYPES.STREAM_RESUME_REQUEST: return {
|
|
1850
|
+
type: "stream-resume-request",
|
|
1851
|
+
...typeof data.probeId === "string" ? { probeId: data.probeId } : {}
|
|
1852
|
+
};
|
|
1874
1853
|
case CHAT_MESSAGE_TYPES.STREAM_RESUME_ACK: return {
|
|
1875
1854
|
type: "stream-resume-ack",
|
|
1876
1855
|
id: data.id
|
|
@@ -2327,13 +2306,15 @@ var ResumeHandshake = class {
|
|
|
2327
2306
|
* `reconnectToStream` hangs to its timeout with no replay), and the proactive
|
|
2328
2307
|
* notify is required for clients that never send a request. The notify is one
|
|
2329
2308
|
* tiny frame; the client dedupes its ACK so the buffer is not replayed twice.
|
|
2309
|
+
* Direct responses echo the opaque probe id; proactive notifications omit it.
|
|
2330
2310
|
*/
|
|
2331
|
-
notifyStreamResuming(connection) {
|
|
2311
|
+
notifyStreamResuming(connection, probeId) {
|
|
2332
2312
|
const { resumableStream, pendingResumeConnections } = this.host;
|
|
2333
2313
|
if (!resumableStream.hasActiveStream()) return;
|
|
2334
2314
|
if (sendIfOpen(connection, JSON.stringify({
|
|
2335
2315
|
type: CHAT_MESSAGE_TYPES.STREAM_RESUMING,
|
|
2336
|
-
id: resumableStream.activeRequestId
|
|
2316
|
+
id: resumableStream.activeRequestId,
|
|
2317
|
+
...probeId ? { probeId } : {}
|
|
2337
2318
|
}))) pendingResumeConnections.add(connection.id);
|
|
2338
2319
|
}
|
|
2339
2320
|
/**
|
|
@@ -2341,20 +2322,28 @@ var ResumeHandshake = class {
|
|
|
2341
2322
|
* message handler is registered, avoiding the race where a proactive
|
|
2342
2323
|
* `STREAM_RESUMING` from onConnect arrives before the handler is ready.
|
|
2343
2324
|
*/
|
|
2344
|
-
async handleResumeRequest(connection) {
|
|
2325
|
+
async handleResumeRequest(connection, probeId) {
|
|
2345
2326
|
const { resumableStream, continuation, preStream } = this.host;
|
|
2346
|
-
if (resumableStream.hasActiveStream()) if (continuation.activeRequestId === resumableStream.activeRequestId && continuation.activeConnectionId !== null && continuation.activeConnectionId !== connection.id && this._ownerStillPresent(continuation.activeConnectionId))
|
|
2347
|
-
else this.notifyStreamResuming(connection);
|
|
2327
|
+
if (resumableStream.hasActiveStream()) if (continuation.activeRequestId === resumableStream.activeRequestId && continuation.activeConnectionId !== null && continuation.activeConnectionId !== connection.id && this._ownerStillPresent(continuation.activeConnectionId)) this._sendResumeNone(connection, STREAM_RESUME_NONE_REASONS.CONTINUATION_OWNED, probeId);
|
|
2328
|
+
else this.notifyStreamResuming(connection, probeId);
|
|
2348
2329
|
else if (continuation.pending !== null && (continuation.pending.connectionId === null || continuation.pending.connectionId === connection.id)) {
|
|
2349
2330
|
continuation.awaitingConnections.set(connection.id, connection);
|
|
2350
|
-
this._sendStreamPending(connection, continuation.pending.requestId);
|
|
2351
|
-
} else if (await this._replayTerminalOnResume(connection)) {} else if (preStream?.park(connection)) {} else
|
|
2331
|
+
this._sendStreamPending(connection, continuation.pending.requestId, probeId);
|
|
2332
|
+
} else if (await this._replayTerminalOnResume(connection, probeId)) {} else if (preStream?.park(connection, probeId)) {} else this._sendResumeNone(connection, STREAM_RESUME_NONE_REASONS.IDLE, probeId);
|
|
2333
|
+
}
|
|
2334
|
+
_sendResumeNone(connection, reason, probeId) {
|
|
2335
|
+
sendIfOpen(connection, JSON.stringify({
|
|
2336
|
+
type: CHAT_MESSAGE_TYPES.STREAM_RESUME_NONE,
|
|
2337
|
+
reason,
|
|
2338
|
+
...probeId ? { probeId } : {}
|
|
2339
|
+
}));
|
|
2352
2340
|
}
|
|
2353
2341
|
/** Send a keep-waiting `STREAM_PENDING` frame (#1784). */
|
|
2354
|
-
_sendStreamPending(connection, requestId) {
|
|
2342
|
+
_sendStreamPending(connection, requestId, probeId) {
|
|
2355
2343
|
sendIfOpen(connection, JSON.stringify({
|
|
2356
2344
|
type: CHAT_MESSAGE_TYPES.STREAM_PENDING,
|
|
2357
|
-
...requestId ? { id: requestId } : {}
|
|
2345
|
+
...requestId ? { id: requestId } : {},
|
|
2346
|
+
...probeId ? { probeId } : {}
|
|
2358
2347
|
}));
|
|
2359
2348
|
}
|
|
2360
2349
|
/** Whether the active continuation's owner connection is still present. */
|
|
@@ -2385,12 +2374,13 @@ var ResumeHandshake = class {
|
|
|
2385
2374
|
* error frame once the client ACKs (see {@link _replayTerminalOnAck}). Returns
|
|
2386
2375
|
* `true` if a terminal was pending (and `STREAM_RESUMING` was sent).
|
|
2387
2376
|
*/
|
|
2388
|
-
async _replayTerminalOnResume(connection) {
|
|
2377
|
+
async _replayTerminalOnResume(connection, probeId) {
|
|
2389
2378
|
const pending = await this.host.pendingChatTerminal();
|
|
2390
2379
|
if (!pending) return false;
|
|
2391
2380
|
sendIfOpen(connection, JSON.stringify({
|
|
2392
2381
|
type: CHAT_MESSAGE_TYPES.STREAM_RESUMING,
|
|
2393
|
-
id: pending.requestId
|
|
2382
|
+
id: pending.requestId,
|
|
2383
|
+
...probeId ? { probeId } : {}
|
|
2394
2384
|
}));
|
|
2395
2385
|
return true;
|
|
2396
2386
|
}
|
|
@@ -3403,6 +3393,6 @@ async function* iterateWithStallWatchdog(source, timeoutMs, onStall) {
|
|
|
3403
3393
|
}
|
|
3404
3394
|
}
|
|
3405
3395
|
//#endregion
|
|
3406
|
-
export { AGENT_TOOL_STREAM_PROGRESS_BUMP_THROTTLE_MS, AbortRegistry, AgentToolProgressEmitter, AgentToolStreamProgressThrottle, AutoContinuationController, CHAT_LAST_TERMINAL_KEY, CHAT_MESSAGE_TYPES, CHAT_RECOVERING_FLAG_TTL_MS, CHAT_RECOVERING_KEY, CHAT_RECOVERY_ALARM_DEBOUNCE_MS, CHAT_RECOVERY_INCIDENT_KEY_PREFIX, CHAT_RECOVERY_INCIDENT_TTL_MS, CHAT_RECOVERY_PROGRESS_KEY, CHAT_RECOVERY_STABLE_RETRY_DELAY_SECONDS, CHAT_STREAM_PROGRESS_CREDIT_THROTTLE_MS, ChatRecoveryEngine, ChatStreamStalledError, ContinuationState, DEFAULT_CHAT_RECOVERY_MAX_ATTEMPTS, DEFAULT_CHAT_RECOVERY_MAX_OOM_RETRIES, DEFAULT_CHAT_RECOVERY_MAX_WORK, DEFAULT_CHAT_RECOVERY_NO_PROGRESS_TIMEOUT_MS, DEFAULT_CHAT_RECOVERY_STABLE_TIMEOUT_MS, DEFAULT_CHAT_RECOVERY_TERMINAL_MESSAGE, KV_DELETE_MAX_KEYS, MAX_BOUND_PARAMS, MessageType, PreStreamTurns, ROW_MAX_BYTES, ResumableStream, ResumeHandshake, STREAM_CLEANUP_DELAY_SECONDS, StreamAccumulator, StreamProgressCreditThrottle, SubmitConcurrencyController, TIMED_OUT, TurnQueue, aiSdkRecoveryCodec, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, awaitWithDeadline, transition as broadcastTransition, buildChatRecoveringFrame, buildInClauseStrings, bumpChatRecoveryProgress, byteLength, chatRecoverySchedulePolicy, classifyAgentToolChildRecovery, cleanupStreamBuffers, clearChatTerminal, clientResolvableToolNames, createAgentToolEventState, createChatFiberSnapshot, createToolsFromClientSchemas, crossMessageToolResultUpdate, drainInteractionApplies, enforceRowSizeLimit, hasIncompleteToolBatch, interceptAgentToolBroadcast, isReplayChunk, iterateWithStallWatchdog, listActiveChatRecoveryIncidents, normalizeToolInput, parseProtocolMessage, partAwaitsClientInteraction, pausedExecutionUpdate, pendingChatTerminal, persistReconstructedOrphan, readChatRecoveryProgress, reconcileMessages, reconcileOrphanPartial, recordChatTerminal, repairInterruptedToolParts, resolveChatRecoveryConfig, resolveToolMergeId, runChatRecoveryExhaustion, sanitizeMessage, sendIfOpen, setChatRecovering, shouldCreditStreamProgress, sweepStaleChatRecoveryIncidents, toolApprovalUpdate, toolPartHasSettledResult, toolResultUpdate, unwrapChatFiberSnapshot, wrapChatFiberSnapshot };
|
|
3396
|
+
export { AGENT_TOOL_STREAM_PROGRESS_BUMP_THROTTLE_MS, AbortRegistry, AgentToolProgressEmitter, AgentToolStreamProgressThrottle, AutoContinuationController, CHAT_LAST_TERMINAL_KEY, CHAT_MESSAGE_TYPES, CHAT_RECOVERING_FLAG_TTL_MS, CHAT_RECOVERING_KEY, CHAT_RECOVERY_ALARM_DEBOUNCE_MS, CHAT_RECOVERY_INCIDENT_KEY_PREFIX, CHAT_RECOVERY_INCIDENT_TTL_MS, CHAT_RECOVERY_PROGRESS_KEY, CHAT_RECOVERY_STABLE_RETRY_DELAY_SECONDS, CHAT_STREAM_PROGRESS_CREDIT_THROTTLE_MS, ChatRecoveryEngine, ChatStreamStalledError, ContinuationState, DEFAULT_CHAT_RECOVERY_MAX_ATTEMPTS, DEFAULT_CHAT_RECOVERY_MAX_OOM_RETRIES, DEFAULT_CHAT_RECOVERY_MAX_WORK, DEFAULT_CHAT_RECOVERY_NO_PROGRESS_TIMEOUT_MS, DEFAULT_CHAT_RECOVERY_STABLE_TIMEOUT_MS, DEFAULT_CHAT_RECOVERY_TERMINAL_MESSAGE, KV_DELETE_MAX_KEYS, MAX_BOUND_PARAMS, MessageType, PreStreamTurns, ROW_MAX_BYTES, ResumableStream, ResumeHandshake, STREAM_CLEANUP_DELAY_SECONDS, STREAM_RESUME_NONE_REASONS, StreamAccumulator, StreamProgressCreditThrottle, SubmitConcurrencyController, TIMED_OUT, TurnQueue, aiSdkRecoveryCodec, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, awaitWithDeadline, transition as broadcastTransition, buildChatRecoveringFrame, buildInClauseStrings, bumpChatRecoveryProgress, byteLength, chatRecoverySchedulePolicy, classifyAgentToolChildRecovery, cleanupStreamBuffers, clearChatTerminal, clientResolvableToolNames, createAgentToolEventState, createChatFiberSnapshot, createToolsFromClientSchemas, crossMessageToolResultUpdate, drainInteractionApplies, enforceRowSizeLimit, hasIncompleteToolBatch, interceptAgentToolBroadcast, isReplayChunk, iterateWithStallWatchdog, listActiveChatRecoveryIncidents, normalizeToolInput, parseProtocolMessage, partAwaitsClientInteraction, pausedExecutionUpdate, pendingChatTerminal, persistReconstructedOrphan, readChatRecoveryProgress, reconcileMessages, reconcileOrphanPartial, recordChatTerminal, repairInterruptedToolParts, resolveChatRecoveryConfig, resolveToolMergeId, runChatRecoveryExhaustion, sanitizeMessage, sendIfOpen, setChatRecovering, shouldCreditStreamProgress, sweepStaleChatRecoveryIncidents, toolApprovalUpdate, toolPartHasSettledResult, toolResultUpdate, unwrapChatFiberSnapshot, wrapChatFiberSnapshot };
|
|
3407
3397
|
|
|
3408
3398
|
//# sourceMappingURL=index.js.map
|