@cloudflare/think 0.8.8 → 0.9.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 +1 -1
- package/dist/cli/index.js +7 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/{codegen-CauNNguA.js → codegen-CuPdJRpV.js} +3 -2
- package/dist/codegen-CuPdJRpV.js.map +1 -0
- package/dist/extensions/index.js +1 -1
- package/dist/framework/index.d.ts +4 -4
- package/dist/framework/index.js +3 -3
- package/dist/{manager-EBL4uMVp.js → manager-BPndMP_6.js} +7 -7
- package/dist/{manager-EBL4uMVp.js.map → manager-BPndMP_6.js.map} +1 -1
- package/dist/messengers/index.d.ts +54 -54
- package/dist/messengers/telegram.d.ts +4 -4
- package/dist/{project-D1o1-3dN.js → project-BHurFdu4.js} +2 -2
- package/dist/{project-D1o1-3dN.js.map → project-BHurFdu4.js.map} +1 -1
- package/dist/server-entry.d.ts +2 -0
- package/dist/server-entry.js +2 -1
- package/dist/server-entry.js.map +1 -1
- package/dist/think-2nHHEcY3.js +6446 -0
- package/dist/think-2nHHEcY3.js.map +1 -0
- package/dist/{think-8jik2oZ5.d.ts → think-CwxWGsX1.d.ts} +563 -133
- package/dist/think.d.ts +2 -2
- package/dist/think.js +1 -5825
- package/dist/tools/browser.d.ts +80 -45
- package/dist/tools/browser.js +25 -41
- package/dist/tools/browser.js.map +1 -1
- package/dist/tools/execute.d.ts +145 -75
- package/dist/tools/execute.js +180 -54
- package/dist/tools/execute.js.map +1 -1
- package/dist/tools/extensions.js +2 -2
- package/dist/tools/extensions.js.map +1 -1
- package/dist/tools/workspace.js +10 -8
- package/dist/tools/workspace.js.map +1 -1
- package/dist/vite.js +2 -2
- package/dist/workflows.d.ts +1 -1
- package/package.json +8 -8
- package/dist/codegen-CauNNguA.js.map +0 -1
- package/dist/think.js.map +0 -1
package/dist/tools/browser.d.ts
CHANGED
|
@@ -1,55 +1,60 @@
|
|
|
1
1
|
import { ToolSet } from "ai";
|
|
2
|
+
import {
|
|
3
|
+
QuickAction,
|
|
4
|
+
QuickActionBinary,
|
|
5
|
+
QuickActionBinding,
|
|
6
|
+
QuickActionCommonOptions,
|
|
7
|
+
QuickActionExtractInput,
|
|
8
|
+
QuickActionInput,
|
|
9
|
+
QuickActionPage,
|
|
10
|
+
QuickActionScrapeInput,
|
|
11
|
+
QuickActionScrapeResult,
|
|
12
|
+
QuickActionScreenshotInput,
|
|
13
|
+
QuickActionSnapshot,
|
|
14
|
+
browserContent,
|
|
15
|
+
browserExtract,
|
|
16
|
+
browserLinks,
|
|
17
|
+
browserMarkdown,
|
|
18
|
+
browserPdf,
|
|
19
|
+
browserScrape,
|
|
20
|
+
browserScreenshot,
|
|
21
|
+
browserSnapshot,
|
|
22
|
+
runQuickAction
|
|
23
|
+
} from "agents/browser";
|
|
24
|
+
import {
|
|
25
|
+
BrowserRuntime,
|
|
26
|
+
CreateBrowserToolsOptions,
|
|
27
|
+
CreateQuickActionToolsOptions,
|
|
28
|
+
QuickActionToolName,
|
|
29
|
+
createBrowserRuntime,
|
|
30
|
+
createQuickActionTools
|
|
31
|
+
} from "agents/browser/ai";
|
|
2
32
|
|
|
3
33
|
//#region src/tools/browser.d.ts
|
|
4
|
-
interface CreateBrowserToolsOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Browser Rendering binding (Fetcher).
|
|
7
|
-
*
|
|
8
|
-
* This is the primary way to connect — works both locally in
|
|
9
|
-
* `wrangler dev` and when deployed to Cloudflare Workers.
|
|
10
|
-
*
|
|
11
|
-
* Requires `"browser": { "binding": "BROWSER" }` in wrangler.jsonc.
|
|
12
|
-
*/
|
|
13
|
-
browser?: Fetcher;
|
|
14
|
-
/**
|
|
15
|
-
* Optional CDP base URL override (e.g. `http://localhost:9222`).
|
|
16
|
-
*
|
|
17
|
-
* Use when connecting to a manually managed Chrome instance or
|
|
18
|
-
* a remote CDP endpoint behind a tunnel.
|
|
19
|
-
*/
|
|
20
|
-
cdpUrl?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Headers to send with CDP URL discovery requests.
|
|
23
|
-
* Useful when the CDP endpoint requires authentication
|
|
24
|
-
* (e.g. Cloudflare Access headers).
|
|
25
|
-
*/
|
|
26
|
-
cdpHeaders?: Record<string, string>;
|
|
27
|
-
/**
|
|
28
|
-
* WorkerLoader binding for sandboxed code execution.
|
|
29
|
-
*
|
|
30
|
-
* Requires `"worker_loaders": [{ "binding": "LOADER" }]` in wrangler.jsonc.
|
|
31
|
-
*/
|
|
32
|
-
loader: WorkerLoader;
|
|
33
|
-
/**
|
|
34
|
-
* Execution timeout in milliseconds. Defaults to 30000 (30s).
|
|
35
|
-
*/
|
|
36
|
-
timeout?: number;
|
|
37
|
-
}
|
|
38
34
|
/**
|
|
39
35
|
* Create browser automation tools for Think agents.
|
|
40
36
|
*
|
|
41
|
-
* Returns
|
|
37
|
+
* Returns the durable `browser_execute` tool backed by a codemode runtime —
|
|
38
|
+
* the model writes TypeScript against the `cdp` connector (`cdp.send`,
|
|
39
|
+
* `cdp.attachToTarget`, `cdp.spec`, …); executions are recorded for
|
|
40
|
+
* abort-and-replay, and browser sessions are keyed by execution (they survive
|
|
41
|
+
* pauses and, in `reuse`/`dynamic` modes, span executions) — plus the stateless
|
|
42
|
+
* {@link createQuickActionTools | Quick Action} tools (`browser_markdown`,
|
|
43
|
+
* `browser_extract`, …) by default whenever a `browser` binding is present.
|
|
44
|
+
* Pass `quickActions: false` to omit them, or use `createQuickActionTools`
|
|
45
|
+
* directly for the stateless tools alone (no Worker Loader required).
|
|
42
46
|
*
|
|
43
|
-
*
|
|
44
|
-
* to discover commands, events, and types. The LLM writes JavaScript
|
|
45
|
-
* that runs against a cached, normalized copy of the protocol.
|
|
47
|
+
* Setup checklist:
|
|
46
48
|
*
|
|
47
|
-
* -
|
|
48
|
-
*
|
|
49
|
-
*
|
|
49
|
+
* - `"browser": { "binding": "BROWSER" }` in wrangler.jsonc
|
|
50
|
+
* - `"worker_loaders": [{ "binding": "LOADER" }]` in wrangler.jsonc
|
|
51
|
+
* - export the runtime class from your worker entry:
|
|
52
|
+
* `export { CodemodeRuntime } from "@cloudflare/codemode"`
|
|
53
|
+
* (the `@cloudflare/codemode/vite` plugin does this automatically)
|
|
50
54
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
55
|
+
* Use {@link createBrowserRuntime} instead when you also need the runtime
|
|
56
|
+
* handle (approvals, audit, `expirePaused`) or the connector's host-side
|
|
57
|
+
* session helpers (`sessionInfo`, `closeSession`, `sweep`).
|
|
53
58
|
*
|
|
54
59
|
* @example
|
|
55
60
|
* ```ts
|
|
@@ -58,14 +63,16 @@ interface CreateBrowserToolsOptions {
|
|
|
58
63
|
*
|
|
59
64
|
* export class MyAgent extends Think<Env> {
|
|
60
65
|
* getModel() {
|
|
61
|
-
* return createWorkersAI({ binding: this.env.AI })("@cf/moonshotai/kimi-k2.
|
|
66
|
+
* return createWorkersAI({ binding: this.env.AI })("@cf/moonshotai/kimi-k2.7-code");
|
|
62
67
|
* }
|
|
63
68
|
*
|
|
64
69
|
* getTools() {
|
|
65
70
|
* return {
|
|
66
71
|
* ...createBrowserTools({
|
|
72
|
+
* ctx: this.ctx,
|
|
67
73
|
* browser: this.env.BROWSER,
|
|
68
74
|
* loader: this.env.LOADER,
|
|
75
|
+
* session: { mode: "dynamic" }
|
|
69
76
|
* }),
|
|
70
77
|
* };
|
|
71
78
|
* }
|
|
@@ -76,5 +83,33 @@ declare function createBrowserTools(
|
|
|
76
83
|
options: CreateBrowserToolsOptions
|
|
77
84
|
): ToolSet;
|
|
78
85
|
//#endregion
|
|
79
|
-
export {
|
|
86
|
+
export {
|
|
87
|
+
type BrowserRuntime,
|
|
88
|
+
type CreateBrowserToolsOptions,
|
|
89
|
+
type CreateQuickActionToolsOptions,
|
|
90
|
+
type QuickAction,
|
|
91
|
+
type QuickActionBinary,
|
|
92
|
+
type QuickActionBinding,
|
|
93
|
+
type QuickActionCommonOptions,
|
|
94
|
+
type QuickActionExtractInput,
|
|
95
|
+
type QuickActionInput,
|
|
96
|
+
type QuickActionPage,
|
|
97
|
+
type QuickActionScrapeInput,
|
|
98
|
+
type QuickActionScrapeResult,
|
|
99
|
+
type QuickActionScreenshotInput,
|
|
100
|
+
type QuickActionSnapshot,
|
|
101
|
+
type QuickActionToolName,
|
|
102
|
+
browserContent,
|
|
103
|
+
browserExtract,
|
|
104
|
+
browserLinks,
|
|
105
|
+
browserMarkdown,
|
|
106
|
+
browserPdf,
|
|
107
|
+
browserScrape,
|
|
108
|
+
browserScreenshot,
|
|
109
|
+
browserSnapshot,
|
|
110
|
+
createBrowserRuntime,
|
|
111
|
+
createBrowserTools,
|
|
112
|
+
createQuickActionTools,
|
|
113
|
+
runQuickAction
|
|
114
|
+
};
|
|
80
115
|
//# sourceMappingURL=browser.d.ts.map
|
package/dist/tools/browser.js
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { EXECUTE_DESCRIPTION, SEARCH_DESCRIPTION, createBrowserToolHandlers } from "agents/browser";
|
|
1
|
+
import { browserContent, browserExtract, browserLinks, browserMarkdown, browserPdf, browserScrape, browserScreenshot, browserSnapshot, runQuickAction } from "agents/browser";
|
|
2
|
+
import { createBrowserRuntime, createBrowserTools as createBrowserTools$1, createQuickActionTools } from "agents/browser/ai";
|
|
4
3
|
//#region src/tools/browser.ts
|
|
5
4
|
/**
|
|
6
5
|
* Create browser automation tools for Think agents.
|
|
7
6
|
*
|
|
8
|
-
* Returns
|
|
7
|
+
* Returns the durable `browser_execute` tool backed by a codemode runtime —
|
|
8
|
+
* the model writes TypeScript against the `cdp` connector (`cdp.send`,
|
|
9
|
+
* `cdp.attachToTarget`, `cdp.spec`, …); executions are recorded for
|
|
10
|
+
* abort-and-replay, and browser sessions are keyed by execution (they survive
|
|
11
|
+
* pauses and, in `reuse`/`dynamic` modes, span executions) — plus the stateless
|
|
12
|
+
* {@link createQuickActionTools | Quick Action} tools (`browser_markdown`,
|
|
13
|
+
* `browser_extract`, …) by default whenever a `browser` binding is present.
|
|
14
|
+
* Pass `quickActions: false` to omit them, or use `createQuickActionTools`
|
|
15
|
+
* directly for the stateless tools alone (no Worker Loader required).
|
|
9
16
|
*
|
|
10
|
-
*
|
|
11
|
-
* to discover commands, events, and types. The LLM writes JavaScript
|
|
12
|
-
* that runs against a cached, normalized copy of the protocol.
|
|
17
|
+
* Setup checklist:
|
|
13
18
|
*
|
|
14
|
-
* -
|
|
15
|
-
*
|
|
16
|
-
*
|
|
19
|
+
* - `"browser": { "binding": "BROWSER" }` in wrangler.jsonc
|
|
20
|
+
* - `"worker_loaders": [{ "binding": "LOADER" }]` in wrangler.jsonc
|
|
21
|
+
* - export the runtime class from your worker entry:
|
|
22
|
+
* `export { CodemodeRuntime } from "@cloudflare/codemode"`
|
|
23
|
+
* (the `@cloudflare/codemode/vite` plugin does this automatically)
|
|
17
24
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
25
|
+
* Use {@link createBrowserRuntime} instead when you also need the runtime
|
|
26
|
+
* handle (approvals, audit, `expirePaused`) or the connector's host-side
|
|
27
|
+
* session helpers (`sessionInfo`, `closeSession`, `sweep`).
|
|
20
28
|
*
|
|
21
29
|
* @example
|
|
22
30
|
* ```ts
|
|
@@ -25,14 +33,16 @@ import { EXECUTE_DESCRIPTION, SEARCH_DESCRIPTION, createBrowserToolHandlers } fr
|
|
|
25
33
|
*
|
|
26
34
|
* export class MyAgent extends Think<Env> {
|
|
27
35
|
* getModel() {
|
|
28
|
-
* return createWorkersAI({ binding: this.env.AI })("@cf/moonshotai/kimi-k2.
|
|
36
|
+
* return createWorkersAI({ binding: this.env.AI })("@cf/moonshotai/kimi-k2.7-code");
|
|
29
37
|
* }
|
|
30
38
|
*
|
|
31
39
|
* getTools() {
|
|
32
40
|
* return {
|
|
33
41
|
* ...createBrowserTools({
|
|
42
|
+
* ctx: this.ctx,
|
|
34
43
|
* browser: this.env.BROWSER,
|
|
35
44
|
* loader: this.env.LOADER,
|
|
45
|
+
* session: { mode: "dynamic" }
|
|
36
46
|
* }),
|
|
37
47
|
* };
|
|
38
48
|
* }
|
|
@@ -40,35 +50,9 @@ import { EXECUTE_DESCRIPTION, SEARCH_DESCRIPTION, createBrowserToolHandlers } fr
|
|
|
40
50
|
* ```
|
|
41
51
|
*/
|
|
42
52
|
function createBrowserTools(options) {
|
|
43
|
-
|
|
44
|
-
browser: options.browser,
|
|
45
|
-
cdpUrl: options.cdpUrl,
|
|
46
|
-
cdpHeaders: options.cdpHeaders,
|
|
47
|
-
loader: options.loader,
|
|
48
|
-
timeout: options.timeout
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
browser_search: tool({
|
|
52
|
-
description: SEARCH_DESCRIPTION,
|
|
53
|
-
inputSchema: z.object({ code: z.string().describe("JavaScript async arrow function that queries the CDP spec") }),
|
|
54
|
-
execute: async ({ code }) => {
|
|
55
|
-
const result = await handlers.search(code);
|
|
56
|
-
if (result.isError) throw new Error(result.text);
|
|
57
|
-
return result.text;
|
|
58
|
-
}
|
|
59
|
-
}),
|
|
60
|
-
browser_execute: tool({
|
|
61
|
-
description: EXECUTE_DESCRIPTION,
|
|
62
|
-
inputSchema: z.object({ code: z.string().describe("JavaScript async arrow function that uses the cdp helper") }),
|
|
63
|
-
execute: async ({ code }) => {
|
|
64
|
-
const result = await handlers.execute(code);
|
|
65
|
-
if (result.isError) throw new Error(result.text);
|
|
66
|
-
return result.text;
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
};
|
|
53
|
+
return createBrowserTools$1(options);
|
|
70
54
|
}
|
|
71
55
|
//#endregion
|
|
72
|
-
export { createBrowserTools };
|
|
56
|
+
export { browserContent, browserExtract, browserLinks, browserMarkdown, browserPdf, browserScrape, browserScreenshot, browserSnapshot, createBrowserRuntime, createBrowserTools, createQuickActionTools, runQuickAction };
|
|
73
57
|
|
|
74
58
|
//# sourceMappingURL=browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","names":[],"sources":["../../src/tools/browser.ts"],"sourcesContent":["import type { ToolSet } from \"ai\";\nimport {\n
|
|
1
|
+
{"version":3,"file":"browser.js","names":["createBrowserToolsForAi"],"sources":["../../src/tools/browser.ts"],"sourcesContent":["import type { ToolSet } from \"ai\";\nimport {\n createBrowserRuntime,\n createBrowserTools as createBrowserToolsForAi,\n createQuickActionTools,\n type BrowserRuntime,\n type CreateBrowserToolsOptions,\n type CreateQuickActionToolsOptions,\n type QuickActionToolName\n} from \"agents/browser/ai\";\n\nexport {\n createBrowserRuntime,\n type BrowserRuntime,\n type CreateBrowserToolsOptions\n};\n\n// Stateless Quick Action tools — re-exported so a Think agent can expose them\n// from `getTools()` with a single import, including the loader-free path\n// (`createQuickActionTools`) that needs only the `browser` binding.\nexport {\n createQuickActionTools,\n type CreateQuickActionToolsOptions,\n type QuickActionToolName\n};\nexport {\n browserContent,\n browserExtract,\n browserLinks,\n browserMarkdown,\n browserPdf,\n browserScrape,\n browserScreenshot,\n browserSnapshot,\n runQuickAction,\n type QuickAction,\n type QuickActionBinary,\n type QuickActionBinding,\n type QuickActionCommonOptions,\n type QuickActionExtractInput,\n type QuickActionInput,\n type QuickActionPage,\n type QuickActionScrapeInput,\n type QuickActionScrapeResult,\n type QuickActionScreenshotInput,\n type QuickActionSnapshot\n} from \"agents/browser\";\n\n/**\n * Create browser automation tools for Think agents.\n *\n * Returns the durable `browser_execute` tool backed by a codemode runtime —\n * the model writes TypeScript against the `cdp` connector (`cdp.send`,\n * `cdp.attachToTarget`, `cdp.spec`, …); executions are recorded for\n * abort-and-replay, and browser sessions are keyed by execution (they survive\n * pauses and, in `reuse`/`dynamic` modes, span executions) — plus the stateless\n * {@link createQuickActionTools | Quick Action} tools (`browser_markdown`,\n * `browser_extract`, …) by default whenever a `browser` binding is present.\n * Pass `quickActions: false` to omit them, or use `createQuickActionTools`\n * directly for the stateless tools alone (no Worker Loader required).\n *\n * Setup checklist:\n *\n * - `\"browser\": { \"binding\": \"BROWSER\" }` in wrangler.jsonc\n * - `\"worker_loaders\": [{ \"binding\": \"LOADER\" }]` in wrangler.jsonc\n * - export the runtime class from your worker entry:\n * `export { CodemodeRuntime } from \"@cloudflare/codemode\"`\n * (the `@cloudflare/codemode/vite` plugin does this automatically)\n *\n * Use {@link createBrowserRuntime} instead when you also need the runtime\n * handle (approvals, audit, `expirePaused`) or the connector's host-side\n * session helpers (`sessionInfo`, `closeSession`, `sweep`).\n *\n * @example\n * ```ts\n * import { Think } from \"@cloudflare/think\";\n * import { createBrowserTools } from \"@cloudflare/think/tools/browser\";\n *\n * export class MyAgent extends Think<Env> {\n * getModel() {\n * return createWorkersAI({ binding: this.env.AI })(\"@cf/moonshotai/kimi-k2.7-code\");\n * }\n *\n * getTools() {\n * return {\n * ...createBrowserTools({\n * ctx: this.ctx,\n * browser: this.env.BROWSER,\n * loader: this.env.LOADER,\n * session: { mode: \"dynamic\" }\n * }),\n * };\n * }\n * }\n * ```\n */\nexport function createBrowserTools(\n options: CreateBrowserToolsOptions\n): ToolSet {\n return createBrowserToolsForAi(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,mBACd,SACS;CACT,OAAOA,qBAAwB,OAAO;AACxC"}
|
package/dist/tools/execute.d.ts
CHANGED
|
@@ -1,58 +1,81 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as WorkspaceLike } from "../workspace-BZXdZcuw.js";
|
|
2
|
+
import { Tool, ToolSet } from "ai";
|
|
2
3
|
import { StateBackend } from "@cloudflare/shell";
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CodemodeConnector,
|
|
6
|
+
CodemodeRuntimeHandle,
|
|
7
|
+
Executor
|
|
8
|
+
} from "@cloudflare/codemode";
|
|
9
|
+
import { BrowserBinding, BrowserConnectorSessionOptions } from "agents/browser";
|
|
4
10
|
|
|
5
11
|
//#region src/tools/execute.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* The minimum agent surface for the `createExecuteTool(this)` one-liner.
|
|
14
|
+
* Any Think agent satisfies it. The agent must be a Durable Object — its
|
|
15
|
+
* `ctx` hosts the codemode runtime facet, and its `env` provides the
|
|
16
|
+
* LOADER/BROWSER bindings. (`ctx` and `env` are not declared here because
|
|
17
|
+
* they are `protected` on the DO base class in some type configurations,
|
|
18
|
+
* which would break structural assignability of `this`.)
|
|
19
|
+
*/
|
|
20
|
+
interface ExecuteToolAgent {
|
|
21
|
+
workspace?: WorkspaceLike;
|
|
22
|
+
/** Set by `createExecuteRuntime(agent)` so callables can reach the runtime. */
|
|
23
|
+
codemode?: CodemodeRuntimeHandle;
|
|
24
|
+
}
|
|
6
25
|
interface CreateExecuteToolOptions {
|
|
7
26
|
/**
|
|
8
|
-
* The
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* but can include any AI SDK tools with `execute` functions.
|
|
27
|
+
* Durable Object state. The codemode runtime that backs the execute tool
|
|
28
|
+
* lives in a facet of this DO — the tool must be created from inside a
|
|
29
|
+
* Durable Object (e.g. a Think agent: pass `this.ctx`).
|
|
12
30
|
*/
|
|
13
|
-
|
|
31
|
+
ctx: DurableObjectState;
|
|
14
32
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
* AI SDK tools exposed inside the sandbox as `tools.*`. Tools with
|
|
34
|
+
* `needsApproval` get the runtime's durable pause/approve/resume flow:
|
|
35
|
+
* calling one pauses the execution until `approveExecution` /
|
|
36
|
+
* `rejectExecution`. A function-valued `needsApproval` can't be evaluated
|
|
37
|
+
* against sandbox arguments ahead of time, so it conservatively always
|
|
38
|
+
* requires approval. Tools without an `execute` function (client-side /
|
|
39
|
+
* provider-executed) are skipped — the sandbox can't call them.
|
|
40
|
+
*/
|
|
41
|
+
tools?: ToolSet;
|
|
42
|
+
/**
|
|
43
|
+
* StateBackend exposed as `state.*` inside the sandbox — the full
|
|
44
|
+
* filesystem API (readFile, writeFile, glob, searchFiles, replaceInFiles,
|
|
45
|
+
* planEdits, …). Every method takes a single object argument.
|
|
24
46
|
*
|
|
25
47
|
* @example
|
|
26
48
|
* ```ts
|
|
27
49
|
* import { createWorkspaceStateBackend } from "@cloudflare/shell";
|
|
28
|
-
*
|
|
29
|
-
* createExecuteTool({
|
|
30
|
-
* tools: myDomainTools,
|
|
31
|
-
* state: createWorkspaceStateBackend(this.workspace),
|
|
32
|
-
* loader: this.env.LOADER,
|
|
33
|
-
* });
|
|
34
|
-
* // sandbox: codemode.myTool() AND state.readFile() AND state.planEdits()
|
|
50
|
+
* state: createWorkspaceStateBackend(this.workspace)
|
|
35
51
|
* ```
|
|
36
52
|
*/
|
|
37
53
|
state?: StateBackend;
|
|
38
54
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
55
|
+
* Browser Rendering binding. When provided, the sandbox gets the `cdp.*`
|
|
56
|
+
* connector (cdp.send, cdp.attachToTarget, cdp.spec, …) — a live browser
|
|
57
|
+
* over the Chrome DevTools Protocol.
|
|
58
|
+
*
|
|
59
|
+
* Requires `"browser": { "binding": "BROWSER" }` in wrangler.jsonc.
|
|
41
60
|
*/
|
|
42
|
-
|
|
61
|
+
browser?: BrowserBinding;
|
|
43
62
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
63
|
+
* Browser session lifecycle (only with `browser`). Defaults to `dynamic`:
|
|
64
|
+
* one-shot sessions the model can promote with `cdp.startSession()`.
|
|
65
|
+
*/
|
|
66
|
+
session?: BrowserConnectorSessionOptions;
|
|
67
|
+
/**
|
|
68
|
+
* Additional connectors for the sandbox beyond `tools`, `state`, and `cdp`.
|
|
69
|
+
* Each adds its own named namespace.
|
|
70
|
+
*/
|
|
71
|
+
connectors?: CodemodeConnector[];
|
|
72
|
+
/**
|
|
73
|
+
* The executor that runs the generated code. If not provided, a
|
|
74
|
+
* `DynamicWorkerExecutor` is created from `loader`.
|
|
51
75
|
*/
|
|
52
76
|
executor?: Executor;
|
|
53
77
|
/**
|
|
54
78
|
* WorkerLoader binding for creating a `DynamicWorkerExecutor`.
|
|
55
|
-
* This is a convenience alternative to passing a full `executor`.
|
|
56
79
|
*
|
|
57
80
|
* Requires `"worker_loaders": [{ "binding": "LOADER" }]` in wrangler.jsonc.
|
|
58
81
|
*/
|
|
@@ -72,67 +95,114 @@ interface CreateExecuteToolOptions {
|
|
|
72
95
|
*/
|
|
73
96
|
globalOutbound?: Fetcher | null;
|
|
74
97
|
/**
|
|
75
|
-
* Custom tool description.
|
|
76
|
-
*
|
|
98
|
+
* Custom tool description. Replaces the generated default entirely — the
|
|
99
|
+
* default explains the codemode workflow and lists each configured
|
|
100
|
+
* namespace (`tools.*`, `state.*`, `cdp.*`) with a usage hint.
|
|
77
101
|
*/
|
|
78
102
|
description?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Codemode runtime name — the durable identity of the tool's executions
|
|
105
|
+
* and snippets. Defaults to `"execute"`. Adding or removing connectors
|
|
106
|
+
* does NOT change the identity, so histories survive configuration
|
|
107
|
+
* changes.
|
|
108
|
+
*/
|
|
109
|
+
name?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The execute tool's moving parts, for hosts that need more than the tool:
|
|
113
|
+
*
|
|
114
|
+
* - `runtime` — the codemode runtime handle (approve/reject paused runs,
|
|
115
|
+
* `expirePaused`, audit via `executions()`, snippets).
|
|
116
|
+
* - `connectors` — the connector set backing the runtime (e.g. the
|
|
117
|
+
* `BrowserConnector` for host-side `sessionInfo()` / `closeSession()` /
|
|
118
|
+
* `sweep()`).
|
|
119
|
+
* - `tool` — what `createExecuteTool` returns.
|
|
120
|
+
*/
|
|
121
|
+
interface ExecuteRuntime {
|
|
122
|
+
runtime: CodemodeRuntimeHandle;
|
|
123
|
+
connectors: CodemodeConnector[];
|
|
124
|
+
tool: Tool;
|
|
79
125
|
}
|
|
80
126
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
127
|
+
* Build the codemode runtime behind the execute tool, returning the runtime
|
|
128
|
+
* handle and connectors alongside the tool. Use this instead of
|
|
129
|
+
* {@link createExecuteTool} when the host needs approvals, the audit trail,
|
|
130
|
+
* snippets, or browser session management.
|
|
131
|
+
*
|
|
132
|
+
* When called with an agent, the runtime handle is also assigned to
|
|
133
|
+
* `agent.codemode` so callables (and Think's built-in approval flow) can
|
|
134
|
+
* reach it.
|
|
135
|
+
*/
|
|
136
|
+
declare function createExecuteRuntime(
|
|
137
|
+
source: CreateExecuteToolOptions | ExecuteToolAgent,
|
|
138
|
+
overrides?: Partial<Omit<CreateExecuteToolOptions, "ctx">>
|
|
139
|
+
): ExecuteRuntime;
|
|
140
|
+
/**
|
|
141
|
+
* Truncate the `pending[].args` of a paused execution output for transcript /
|
|
142
|
+
* model consumption. The full args stay on the runtime facet (used by the
|
|
143
|
+
* actual resume); only the model-facing copy is bounded. Non-paused outputs
|
|
144
|
+
* pass through unchanged.
|
|
145
|
+
*/
|
|
146
|
+
declare function truncatePausedExecutionOutput(output: unknown): unknown;
|
|
147
|
+
/**
|
|
148
|
+
* Create a code execution tool that lets the LLM write and run TypeScript
|
|
149
|
+
* against your tools, the workspace filesystem, and (optionally) a live
|
|
150
|
+
* browser — all inside a sandboxed Worker, recorded on a durable codemode
|
|
151
|
+
* runtime (abort-and-replay, approvals, snippets).
|
|
83
152
|
*
|
|
84
|
-
* The
|
|
85
|
-
*
|
|
86
|
-
*
|
|
153
|
+
* The model sees typed namespaces: `tools.*` for your AI SDK tools,
|
|
154
|
+
* `state.*` for the filesystem (object args: `state.readFile({ path })`),
|
|
155
|
+
* and `cdp.*` for the browser.
|
|
87
156
|
*
|
|
88
|
-
*
|
|
89
|
-
* `codemode.*`:
|
|
157
|
+
* Setup checklist:
|
|
90
158
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
159
|
+
* - `"worker_loaders": [{ "binding": "LOADER" }]` in wrangler.jsonc
|
|
160
|
+
* - `"browser": { "binding": "BROWSER" }` in wrangler.jsonc (for `cdp.*`)
|
|
161
|
+
* - export the runtime class from your worker entry:
|
|
162
|
+
* `export { CodemodeRuntime } from "@cloudflare/codemode"`
|
|
163
|
+
* (the `@cloudflare/codemode/vite` plugin does this automatically)
|
|
95
164
|
*
|
|
165
|
+
* @example One-liner — defaults from the agent
|
|
166
|
+
* ```ts
|
|
96
167
|
* getTools() {
|
|
97
|
-
* const workspaceTools = createWorkspaceTools(this.workspace);
|
|
98
|
-
* const backend = createWorkspaceStateBackend(this.workspace);
|
|
99
168
|
* return {
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* state: backend, // state.* — full filesystem API
|
|
104
|
-
* loader: this.env.LOADER,
|
|
105
|
-
* }),
|
|
169
|
+
* // state.* from this.workspace, cdp.* if env.BROWSER is bound,
|
|
170
|
+
* // executor from env.LOADER
|
|
171
|
+
* execute: createExecuteTool(this)
|
|
106
172
|
* };
|
|
107
173
|
* }
|
|
108
174
|
* ```
|
|
109
175
|
*
|
|
110
|
-
* @example
|
|
176
|
+
* @example Agent defaults plus overrides (e.g. custom tools.*)
|
|
111
177
|
* ```ts
|
|
112
|
-
* createExecuteTool({
|
|
113
|
-
* tools: myTools,
|
|
114
|
-
* loader: this.env.LOADER,
|
|
115
|
-
* });
|
|
178
|
+
* execute: createExecuteTool(this, { tools: myDomainTools })
|
|
116
179
|
* ```
|
|
117
180
|
*
|
|
118
|
-
* @example
|
|
181
|
+
* @example Explicit options
|
|
119
182
|
* ```ts
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* createExecuteTool({ tools: myTools, executor });
|
|
183
|
+
* execute: createExecuteTool({
|
|
184
|
+
* ctx: this.ctx,
|
|
185
|
+
* tools: myDomainTools, // tools.*
|
|
186
|
+
* state: createWorkspaceStateBackend(this.workspace), // state.*
|
|
187
|
+
* browser: this.env.BROWSER, // cdp.*
|
|
188
|
+
* loader: this.env.LOADER
|
|
189
|
+
* })
|
|
128
190
|
* ```
|
|
191
|
+
*
|
|
192
|
+
* Use {@link createExecuteRuntime} to also get the runtime handle
|
|
193
|
+
* (approvals, audit, snippets) and the connector set.
|
|
129
194
|
*/
|
|
130
195
|
declare function createExecuteTool(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
import("@cloudflare/codemode/ai").CodeOutput
|
|
135
|
-
>;
|
|
196
|
+
source: CreateExecuteToolOptions | ExecuteToolAgent,
|
|
197
|
+
overrides?: Partial<Omit<CreateExecuteToolOptions, "ctx">>
|
|
198
|
+
): Tool;
|
|
136
199
|
//#endregion
|
|
137
|
-
export {
|
|
200
|
+
export {
|
|
201
|
+
CreateExecuteToolOptions,
|
|
202
|
+
ExecuteRuntime,
|
|
203
|
+
ExecuteToolAgent,
|
|
204
|
+
createExecuteRuntime,
|
|
205
|
+
createExecuteTool,
|
|
206
|
+
truncatePausedExecutionOutput
|
|
207
|
+
};
|
|
138
208
|
//# sourceMappingURL=execute.d.ts.map
|