@cloudflare/think 0.8.8 → 0.9.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/cli/index.js +4 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/{codegen-CauNNguA.js → codegen-KnFnKp0C.js} +2 -1
- package/dist/codegen-KnFnKp0C.js.map +1 -0
- package/dist/extensions/index.js +1 -1
- package/dist/framework/index.d.ts +4 -4
- package/dist/framework/index.js +2 -2
- 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/server-entry.d.ts +2 -0
- package/dist/server-entry.js +2 -1
- package/dist/server-entry.js.map +1 -1
- package/dist/think-CK0xW_QY.js +6429 -0
- package/dist/think-CK0xW_QY.js.map +1 -0
- package/dist/{think-8jik2oZ5.d.ts → think-Cike7VBF.d.ts} +550 -133
- package/dist/think.d.ts +2 -2
- package/dist/think.js +1 -5825
- package/dist/tools/browser.d.ts +28 -44
- package/dist/tools/browser.js +20 -40
- 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 +1 -1
- 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,32 @@
|
|
|
1
1
|
import { ToolSet } from "ai";
|
|
2
|
+
import {
|
|
3
|
+
BrowserRuntime,
|
|
4
|
+
CreateBrowserToolsOptions,
|
|
5
|
+
createBrowserRuntime
|
|
6
|
+
} from "agents/browser/ai";
|
|
2
7
|
|
|
3
8
|
//#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
9
|
/**
|
|
39
10
|
* Create browser automation tools for Think agents.
|
|
40
11
|
*
|
|
41
|
-
* Returns a `ToolSet` with
|
|
12
|
+
* Returns a `ToolSet` with a single durable `browser_execute` tool backed by
|
|
13
|
+
* a codemode runtime: the model writes TypeScript against the `cdp`
|
|
14
|
+
* connector (`cdp.send`, `cdp.attachToTarget`, `cdp.spec`, …). Executions
|
|
15
|
+
* are recorded for abort-and-replay, and browser sessions are keyed by
|
|
16
|
+
* execution — they survive pauses and, in `reuse`/`dynamic` session modes,
|
|
17
|
+
* span executions.
|
|
42
18
|
*
|
|
43
|
-
*
|
|
44
|
-
* to discover commands, events, and types. The LLM writes JavaScript
|
|
45
|
-
* that runs against a cached, normalized copy of the protocol.
|
|
19
|
+
* Setup checklist:
|
|
46
20
|
*
|
|
47
|
-
* -
|
|
48
|
-
*
|
|
49
|
-
*
|
|
21
|
+
* - `"browser": { "binding": "BROWSER" }` in wrangler.jsonc
|
|
22
|
+
* - `"worker_loaders": [{ "binding": "LOADER" }]` in wrangler.jsonc
|
|
23
|
+
* - export the runtime class from your worker entry:
|
|
24
|
+
* `export { CodemodeRuntime } from "@cloudflare/codemode"`
|
|
25
|
+
* (the `@cloudflare/codemode/vite` plugin does this automatically)
|
|
50
26
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
27
|
+
* Use {@link createBrowserRuntime} instead when you also need the runtime
|
|
28
|
+
* handle (approvals, audit, `expirePaused`) or the connector's host-side
|
|
29
|
+
* session helpers (`sessionInfo`, `closeSession`, `sweep`).
|
|
53
30
|
*
|
|
54
31
|
* @example
|
|
55
32
|
* ```ts
|
|
@@ -64,8 +41,10 @@ interface CreateBrowserToolsOptions {
|
|
|
64
41
|
* getTools() {
|
|
65
42
|
* return {
|
|
66
43
|
* ...createBrowserTools({
|
|
44
|
+
* ctx: this.ctx,
|
|
67
45
|
* browser: this.env.BROWSER,
|
|
68
46
|
* loader: this.env.LOADER,
|
|
47
|
+
* session: { mode: "dynamic" }
|
|
69
48
|
* }),
|
|
70
49
|
* };
|
|
71
50
|
* }
|
|
@@ -76,5 +55,10 @@ declare function createBrowserTools(
|
|
|
76
55
|
options: CreateBrowserToolsOptions
|
|
77
56
|
): ToolSet;
|
|
78
57
|
//#endregion
|
|
79
|
-
export {
|
|
58
|
+
export {
|
|
59
|
+
type BrowserRuntime,
|
|
60
|
+
type CreateBrowserToolsOptions,
|
|
61
|
+
createBrowserRuntime,
|
|
62
|
+
createBrowserTools
|
|
63
|
+
};
|
|
80
64
|
//# sourceMappingURL=browser.d.ts.map
|
package/dist/tools/browser.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { EXECUTE_DESCRIPTION, SEARCH_DESCRIPTION, createBrowserToolHandlers } from "agents/browser";
|
|
1
|
+
import { createBrowserRuntime, createBrowserTools as createBrowserTools$1 } from "agents/browser/ai";
|
|
4
2
|
//#region src/tools/browser.ts
|
|
5
3
|
/**
|
|
6
4
|
* Create browser automation tools for Think agents.
|
|
7
5
|
*
|
|
8
|
-
* Returns a `ToolSet` with
|
|
6
|
+
* Returns a `ToolSet` with a single durable `browser_execute` tool backed by
|
|
7
|
+
* a codemode runtime: the model writes TypeScript against the `cdp`
|
|
8
|
+
* connector (`cdp.send`, `cdp.attachToTarget`, `cdp.spec`, …). Executions
|
|
9
|
+
* are recorded for abort-and-replay, and browser sessions are keyed by
|
|
10
|
+
* execution — they survive pauses and, in `reuse`/`dynamic` session modes,
|
|
11
|
+
* span executions.
|
|
9
12
|
*
|
|
10
|
-
*
|
|
11
|
-
* to discover commands, events, and types. The LLM writes JavaScript
|
|
12
|
-
* that runs against a cached, normalized copy of the protocol.
|
|
13
|
+
* Setup checklist:
|
|
13
14
|
*
|
|
14
|
-
* -
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* - `"browser": { "binding": "BROWSER" }` in wrangler.jsonc
|
|
16
|
+
* - `"worker_loaders": [{ "binding": "LOADER" }]` in wrangler.jsonc
|
|
17
|
+
* - export the runtime class from your worker entry:
|
|
18
|
+
* `export { CodemodeRuntime } from "@cloudflare/codemode"`
|
|
19
|
+
* (the `@cloudflare/codemode/vite` plugin does this automatically)
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
21
|
+
* Use {@link createBrowserRuntime} instead when you also need the runtime
|
|
22
|
+
* handle (approvals, audit, `expirePaused`) or the connector's host-side
|
|
23
|
+
* session helpers (`sessionInfo`, `closeSession`, `sweep`).
|
|
20
24
|
*
|
|
21
25
|
* @example
|
|
22
26
|
* ```ts
|
|
@@ -31,8 +35,10 @@ import { EXECUTE_DESCRIPTION, SEARCH_DESCRIPTION, createBrowserToolHandlers } fr
|
|
|
31
35
|
* getTools() {
|
|
32
36
|
* return {
|
|
33
37
|
* ...createBrowserTools({
|
|
38
|
+
* ctx: this.ctx,
|
|
34
39
|
* browser: this.env.BROWSER,
|
|
35
40
|
* loader: this.env.LOADER,
|
|
41
|
+
* session: { mode: "dynamic" }
|
|
36
42
|
* }),
|
|
37
43
|
* };
|
|
38
44
|
* }
|
|
@@ -40,35 +46,9 @@ import { EXECUTE_DESCRIPTION, SEARCH_DESCRIPTION, createBrowserToolHandlers } fr
|
|
|
40
46
|
* ```
|
|
41
47
|
*/
|
|
42
48
|
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
|
-
};
|
|
49
|
+
return createBrowserTools$1(options);
|
|
70
50
|
}
|
|
71
51
|
//#endregion
|
|
72
|
-
export { createBrowserTools };
|
|
52
|
+
export { createBrowserRuntime, createBrowserTools };
|
|
73
53
|
|
|
74
54
|
//# 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 type BrowserRuntime,\n type CreateBrowserToolsOptions\n} from \"agents/browser/ai\";\n\nexport {\n createBrowserRuntime,\n type BrowserRuntime,\n type CreateBrowserToolsOptions\n};\n\n/**\n * Create browser automation tools for Think agents.\n *\n * Returns a `ToolSet` with a single durable `browser_execute` tool backed by\n * a codemode runtime: the model writes TypeScript against the `cdp`\n * connector (`cdp.send`, `cdp.attachToTarget`, `cdp.spec`, …). Executions\n * are recorded for abort-and-replay, and browser sessions are keyed by\n * execution — they survive pauses and, in `reuse`/`dynamic` session modes,\n * span executions.\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.6\");\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,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
|