agents 0.15.0 → 0.16.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-VPsjVYL0.d.ts → agent-tool-types-NofdbL9X.d.ts} +57 -4
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-BGpgfpJT.d.ts → agent-tools-DLquv-dp.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/browser/ai.d.ts +126 -7
- package/dist/browser/ai.js +73 -29
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +81 -69
- package/dist/browser/index.js +3 -2
- package/dist/browser/tanstack-ai.d.ts +13 -7
- package/dist/browser/tanstack-ai.js +18 -19
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/chat/index.d.ts +111 -5
- package/dist/chat/index.js +207 -35
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/{classPrivateFieldGet2-Beqsfu2Z.js → classPrivateFieldGet2-CZ7QjTXN.js} +5 -5
- package/dist/{classPrivateMethodInitSpec-B5ko1s2R.js → classPrivateMethodInitSpec-D-0__zd9.js} +2 -2
- package/dist/client.d.ts +19 -2
- package/dist/client.js +31 -11
- package/dist/client.js.map +1 -1
- package/dist/{compaction-helpers-BEUILPss.d.ts → compaction-helpers-DVcu5lPN.d.ts} +91 -12
- package/dist/connector-D6yYzYHg.js +1080 -0
- package/dist/connector-D6yYzYHg.js.map +1 -0
- package/dist/connector-DXursxV5.d.ts +340 -0
- package/dist/experimental/memory/session/index.d.ts +75 -12
- package/dist/experimental/memory/session/index.js +226 -21
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/memory/utils/index.d.ts +2 -2
- package/dist/{index-CPe1OtI0.d.ts → index-B7IbEeze.d.ts} +32 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +116 -45
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/react.d.ts +12 -1
- package/dist/react.js +101 -30
- package/dist/react.js.map +1 -1
- package/dist/{retries-CF_HKSlJ.d.ts → retries-CwlpAGet.d.ts} +35 -5
- package/dist/retries.d.ts +9 -5
- package/dist/retries.js +87 -1
- package/dist/retries.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/skills/index.js +2 -2
- package/dist/sub-routing.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/package.json +10 -10
- package/dist/shared-4CAYLCTO.d.ts +0 -34
- package/dist/shared-wyII629d.js +0 -432
- package/dist/shared-wyII629d.js.map +0 -1
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createBrowserRuntime } from "./ai.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { toolDefinition } from "@tanstack/ai";
|
|
4
4
|
//#region src/browser/tanstack-ai.ts
|
|
5
5
|
/**
|
|
6
6
|
* Create TanStack AI tools for browser automation via CDP code mode.
|
|
7
7
|
*
|
|
8
|
-
* Returns an array
|
|
9
|
-
*
|
|
8
|
+
* Returns an array with a single durable `browser_execute` `ServerTool`
|
|
9
|
+
* backed by the same codemode runtime as `agents/browser/ai` — the model
|
|
10
|
+
* writes TypeScript against the `cdp` connector and browser sessions
|
|
11
|
+
* survive pauses.
|
|
10
12
|
*
|
|
11
13
|
* @example
|
|
12
14
|
* ```ts
|
|
13
15
|
* import { createBrowserTools } from "agents/browser/tanstack-ai";
|
|
14
16
|
* import { chat } from "@tanstack/ai";
|
|
15
17
|
*
|
|
18
|
+
* // inside a Durable Object / Agent:
|
|
16
19
|
* const browserTools = createBrowserTools({
|
|
17
|
-
*
|
|
18
|
-
*
|
|
20
|
+
* ctx: this.ctx,
|
|
21
|
+
* browser: this.env.BROWSER,
|
|
22
|
+
* loader: this.env.LOADER,
|
|
19
23
|
* });
|
|
20
24
|
*
|
|
21
25
|
* const stream = chat({
|
|
@@ -26,23 +30,18 @@ import { toolDefinition } from "@tanstack/ai";
|
|
|
26
30
|
* ```
|
|
27
31
|
*/
|
|
28
32
|
function createBrowserTools(options) {
|
|
29
|
-
const
|
|
33
|
+
const { tools } = createBrowserRuntime(options);
|
|
34
|
+
const executeTool = tools.browser_execute;
|
|
30
35
|
return [toolDefinition({
|
|
31
|
-
name: "browser_search",
|
|
32
|
-
description: SEARCH_DESCRIPTION,
|
|
33
|
-
inputSchema: z.object({ code: z.string().meta({ description: "JavaScript async arrow function that queries the CDP spec" }) })
|
|
34
|
-
}).server(async ({ code }) => {
|
|
35
|
-
const result = await handlers.search(code);
|
|
36
|
-
if (result.isError) throw new Error(result.text);
|
|
37
|
-
return { text: result.text };
|
|
38
|
-
}), toolDefinition({
|
|
39
36
|
name: "browser_execute",
|
|
40
|
-
description:
|
|
41
|
-
inputSchema: z.object({ code: z.string().meta({ description: "
|
|
37
|
+
description: executeTool.description ?? "",
|
|
38
|
+
inputSchema: z.object({ code: z.string().meta({ description: "TypeScript async arrow function that uses the cdp connector" }) })
|
|
42
39
|
}).server(async ({ code }) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
if (!executeTool.execute) throw new Error("browser_execute tool is not executable");
|
|
41
|
+
return await executeTool.execute({ code }, {
|
|
42
|
+
toolCallId: crypto.randomUUID(),
|
|
43
|
+
messages: []
|
|
44
|
+
});
|
|
46
45
|
})];
|
|
47
46
|
}
|
|
48
47
|
//#endregion
|
|
@@ -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 { z } from \"zod\";\nimport {
|
|
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 * @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 const { tools } = createBrowserRuntime(options);\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(\n { code },\n { toolCallId: crypto.randomUUID(), messages: [] }\n )) as ProxyToolOutput;\n return result;\n });\n\n return [execute];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,mBACd,SACc;CACd,MAAM,EAAE,UAAU,qBAAqB,OAAO;CAC9C,MAAM,cAAc,MAAM;CAsB1B,OAAO,CApBS,eAAe;EAC7B,MAAM;EACN,aAAa,YAAY,eAAe;EACxC,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;EAM1D,OAAO,MAJe,YAAY,QAChC,EAAE,KAAK,GACP;GAAE,YAAY,OAAO,WAAW;GAAG,UAAU,CAAC;EAAE,CAClD;CAEF,CAEc,CAAC;AACjB"}
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
d as AgentToolRunState,
|
|
4
4
|
i as AgentToolEventMessage,
|
|
5
5
|
r as AgentToolEvent
|
|
6
|
-
} from "../agent-tool-types-
|
|
6
|
+
} from "../agent-tool-types-NofdbL9X.js";
|
|
7
7
|
import {
|
|
8
8
|
n as createAgentToolEventState,
|
|
9
9
|
t as applyAgentToolEvent
|
|
10
|
-
} from "../agent-tools-
|
|
10
|
+
} from "../agent-tools-DLquv-dp.js";
|
|
11
11
|
import { JSONSchema7, Tool, ToolSet, UIMessage } from "ai";
|
|
12
12
|
import { Connection } from "agents";
|
|
13
13
|
|
|
@@ -277,17 +277,38 @@ type ClientToolSchema = {
|
|
|
277
277
|
description?: Tool["description"] /** JSON Schema defining the tool's input parameters */;
|
|
278
278
|
parameters?: JSONSchema7;
|
|
279
279
|
};
|
|
280
|
+
/**
|
|
281
|
+
* Executes a client-defined tool and returns its output.
|
|
282
|
+
*
|
|
283
|
+
* Used for the RPC path (e.g. a parent agent delegating to a Think sub-agent)
|
|
284
|
+
* where the caller can run the client tools itself, rather than the
|
|
285
|
+
* browser/WebSocket path where results are sent back asynchronously.
|
|
286
|
+
*/
|
|
287
|
+
type ClientToolExecutor = (call: {
|
|
288
|
+
/** The name of the client tool the model called. */ toolName: string /** The model-generated input for the tool call. */;
|
|
289
|
+
input: unknown /** The AI SDK tool-call id for the invocation. */;
|
|
290
|
+
toolCallId: string;
|
|
291
|
+
}) => unknown | Promise<unknown>;
|
|
280
292
|
/**
|
|
281
293
|
* Converts client tool schemas to AI SDK tool format.
|
|
282
294
|
*
|
|
283
|
-
*
|
|
284
|
-
* the tool call is sent back to the client for execution.
|
|
295
|
+
* By default these tools have no `execute` function — when the AI model calls
|
|
296
|
+
* them, the tool call is sent back to the client for execution.
|
|
297
|
+
*
|
|
298
|
+
* When `options.execute` is provided, each tool is built WITH an `execute` that
|
|
299
|
+
* delegates to it. This is used by the RPC path (e.g. a parent agent driving a
|
|
300
|
+
* Think sub-agent) so the model's client-tool call is resolved inline within
|
|
301
|
+
* the same turn.
|
|
285
302
|
*
|
|
286
303
|
* @param clientTools - Array of tool schemas from the client
|
|
304
|
+
* @param options - Optional `execute` delegate to run the tools inline
|
|
287
305
|
* @returns Record of AI SDK tools that can be spread into your tools object
|
|
288
306
|
*/
|
|
289
307
|
declare function createToolsFromClientSchemas(
|
|
290
|
-
clientTools?: ClientToolSchema[]
|
|
308
|
+
clientTools?: ClientToolSchema[],
|
|
309
|
+
options?: {
|
|
310
|
+
execute?: ClientToolExecutor;
|
|
311
|
+
}
|
|
291
312
|
): ToolSet;
|
|
292
313
|
//#endregion
|
|
293
314
|
//#region src/chat/lifecycle.d.ts
|
|
@@ -672,6 +693,12 @@ declare class ResumableStream {
|
|
|
672
693
|
* DO was evicted.
|
|
673
694
|
*/
|
|
674
695
|
private _isLive;
|
|
696
|
+
/**
|
|
697
|
+
* Whether the active stream is a continuation. Mirrors the durable
|
|
698
|
+
* `is_continuation` column so replay frames can carry the flag without a
|
|
699
|
+
* per-replay query; restored from SQLite after hibernation in restore().
|
|
700
|
+
*/
|
|
701
|
+
private _activeIsContinuation;
|
|
675
702
|
private _chunkBuffer;
|
|
676
703
|
private _chunkBufferBytes;
|
|
677
704
|
private _isFlushingChunks;
|
|
@@ -702,6 +729,7 @@ declare class ResumableStream {
|
|
|
702
729
|
requestId: string,
|
|
703
730
|
options?: {
|
|
704
731
|
messageId?: string;
|
|
732
|
+
continuation?: boolean;
|
|
705
733
|
}
|
|
706
734
|
): string;
|
|
707
735
|
/**
|
|
@@ -768,6 +796,33 @@ declare class ResumableStream {
|
|
|
768
796
|
connection: Connection,
|
|
769
797
|
requestId: string
|
|
770
798
|
): boolean;
|
|
799
|
+
/**
|
|
800
|
+
* Replay the stored chunks of an errored stream for a request, WITHOUT a
|
|
801
|
+
* terminal frame — the caller follows up with the `done: true, error: true`
|
|
802
|
+
* frame carrying the durable terminal record's error text, mirroring what a
|
|
803
|
+
* live client observed (content chunks, then the error). Without this, a
|
|
804
|
+
* client that missed broadcast frames while disconnected has no other
|
|
805
|
+
* channel to the pre-error partial content: the server does not push
|
|
806
|
+
* messages on connect, and {@link replayCompletedChunksByRequestId} only
|
|
807
|
+
* serves `completed` streams (#1575).
|
|
808
|
+
*
|
|
809
|
+
* Returns true when the caller should proceed to send its terminal frame:
|
|
810
|
+
* either no errored stream existed (nothing to replay) or its chunks were
|
|
811
|
+
* replayed successfully. Returns false only when a send failed mid-replay,
|
|
812
|
+
* signalling the caller to skip the terminal frame — the connection is gone
|
|
813
|
+
* and the next reconnect retries the whole sequence.
|
|
814
|
+
*/
|
|
815
|
+
replayErroredChunksByRequestId(
|
|
816
|
+
connection: Connection,
|
|
817
|
+
requestId: string
|
|
818
|
+
): boolean;
|
|
819
|
+
/** Latest stream row for a request with the given terminal status. */
|
|
820
|
+
private _latestStreamForRequest;
|
|
821
|
+
/**
|
|
822
|
+
* Send a finished stream's stored chunks to a connection as replay frames.
|
|
823
|
+
* Returns false if the connection closed mid-replay.
|
|
824
|
+
*/
|
|
825
|
+
private _replayStoredChunks;
|
|
771
826
|
/**
|
|
772
827
|
* Restore active stream state if the agent was restarted during streaming.
|
|
773
828
|
* All streams are restored regardless of age — stale cleanup happens
|
|
@@ -782,7 +837,26 @@ declare class ResumableStream {
|
|
|
782
837
|
* Drop all stream tables (called on destroy).
|
|
783
838
|
*/
|
|
784
839
|
destroy(): void;
|
|
840
|
+
/**
|
|
841
|
+
* Force a sweep of aged stream buffers now, bypassing the lazy interval
|
|
842
|
+
* gate used by {@link _maybeCleanupOldStreams}. Intended to be driven by an
|
|
843
|
+
* alarm so idle/hibernated chat DOs still reclaim buffers even when no
|
|
844
|
+
* further stream ever completes to trigger the lazy path.
|
|
845
|
+
*/
|
|
846
|
+
cleanup(now?: number): void;
|
|
847
|
+
/**
|
|
848
|
+
* True if any stream rows remain at all. Used by alarm-driven cleanup to
|
|
849
|
+
* decide whether to re-arm: once no rows remain there is nothing left to
|
|
850
|
+
* sweep, so the DO can stop waking itself.
|
|
851
|
+
*/
|
|
852
|
+
hasReclaimableStreams(): boolean;
|
|
785
853
|
private _maybeCleanupOldStreams;
|
|
854
|
+
/** Delete completed/errored buffers past the completion grace window, plus
|
|
855
|
+
* abandoned "streaming" rows past the stale-in-flight window. The two use
|
|
856
|
+
* different retentions: a completed buffer is redundant with the persisted
|
|
857
|
+
* message and needs only a brief replay grace, whereas an in-flight buffer
|
|
858
|
+
* must outlive resume/recovery before it is presumed dead. */
|
|
859
|
+
private _sweepOldStreams;
|
|
786
860
|
/**
|
|
787
861
|
* Return the stored chunks for a stream as individual chunk bodies in order,
|
|
788
862
|
* unpacking packed segment rows. The returned `chunk_index` is a running
|
|
@@ -807,6 +881,13 @@ declare class ResumableStream {
|
|
|
807
881
|
}>;
|
|
808
882
|
/** @internal For testing only */
|
|
809
883
|
insertStaleStream(streamId: string, requestId: string, ageMs: number): void;
|
|
884
|
+
/**
|
|
885
|
+
* Append a chunk to a stream dated `ageMs` in the past. Used to exercise the
|
|
886
|
+
* last-activity sweep threshold: a long-running streaming row with a *recent*
|
|
887
|
+
* chunk must survive even when its start time is older than the cutoff.
|
|
888
|
+
* @internal For testing only
|
|
889
|
+
*/
|
|
890
|
+
insertChunkAt(streamId: string, body: string, ageMs: number): void;
|
|
810
891
|
}
|
|
811
892
|
//#endregion
|
|
812
893
|
//#region src/chat/sql-batch.d.ts
|
|
@@ -1083,6 +1164,29 @@ declare function crossMessageToolResultUpdate(
|
|
|
1083
1164
|
errorText?: string,
|
|
1084
1165
|
preliminary?: boolean
|
|
1085
1166
|
): ToolPartUpdate;
|
|
1167
|
+
/**
|
|
1168
|
+
* Build an update descriptor that replaces the output of a *paused durable
|
|
1169
|
+
* execution* tool part (e.g. a codemode runtime tool that paused for
|
|
1170
|
+
* approval).
|
|
1171
|
+
*
|
|
1172
|
+
* A paused execution completes its tool call normally — the part is already
|
|
1173
|
+
* `output-available` with an output of `{ status: "paused", executionId }`.
|
|
1174
|
+
* When the host later approves/rejects the execution, the new outcome
|
|
1175
|
+
* (completed / rejected / paused-again) must replace that output in place.
|
|
1176
|
+
*
|
|
1177
|
+
* Matching is deliberately narrow and idempotent:
|
|
1178
|
+
*
|
|
1179
|
+
* - only `output-available` parts are considered;
|
|
1180
|
+
* - the existing output must be a paused-execution object carrying the same
|
|
1181
|
+
* `executionId` — anything else (already replaced, different execution)
|
|
1182
|
+
* returns the *same part reference*, which callers treat as a no-op signal
|
|
1183
|
+
* (skip persist + broadcast), mirroring {@link crossMessageToolResultUpdate}.
|
|
1184
|
+
*/
|
|
1185
|
+
declare function pausedExecutionUpdate(
|
|
1186
|
+
toolCallId: string,
|
|
1187
|
+
executionId: string,
|
|
1188
|
+
output: unknown
|
|
1189
|
+
): ToolPartUpdate;
|
|
1086
1190
|
/**
|
|
1087
1191
|
* Build an update descriptor for applying a tool approval.
|
|
1088
1192
|
*
|
|
@@ -1278,6 +1382,7 @@ export {
|
|
|
1278
1382
|
type ChatResponseResult,
|
|
1279
1383
|
type ChunkAction,
|
|
1280
1384
|
type ChunkResult,
|
|
1385
|
+
type ClientToolExecutor,
|
|
1281
1386
|
type ClientToolSchema,
|
|
1282
1387
|
type ContinuationConnection,
|
|
1283
1388
|
type ContinuationDeferred,
|
|
@@ -1318,6 +1423,7 @@ export {
|
|
|
1318
1423
|
isReplayChunk,
|
|
1319
1424
|
normalizeToolInput,
|
|
1320
1425
|
parseProtocolMessage,
|
|
1426
|
+
pausedExecutionUpdate,
|
|
1321
1427
|
reconcileMessages,
|
|
1322
1428
|
resolveToolMergeId,
|
|
1323
1429
|
sanitizeMessage,
|