@lunora/agent 1.0.0-alpha.1 → 1.0.0-alpha.10
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 +2 -0
- package/dist/channels.d.mts +42 -22
- package/dist/channels.d.ts +42 -22
- package/dist/channels.mjs +1 -1
- package/dist/component.d.mts +59 -56
- package/dist/component.d.ts +59 -56
- package/dist/component.mjs +20 -9
- package/dist/inbound.d.mts +21 -16
- package/dist/inbound.d.ts +21 -16
- package/dist/index.d.mts +500 -408
- package/dist/index.d.ts +500 -408
- package/dist/index.mjs +6 -6
- package/dist/naming.d.mts +23 -10
- package/dist/naming.d.ts +23 -10
- package/dist/packem_shared/{VoiceSessionDO-DLoXsHGF.mjs → VoiceSessionDO-BdwlLaXC.mjs} +2 -2
- package/dist/packem_shared/{agentAsTool-Dt8NlU6k.mjs → agentAsTool-CUHlWsmt.mjs} +5 -1
- package/dist/packem_shared/{braintrustTelemetry-wuGDErob.mjs → braintrustTelemetry-TP7Kwuuj.mjs} +1 -1
- package/dist/packem_shared/{common-DAeFCot5.mjs → common-DQXayow6.mjs} +29 -1
- package/dist/packem_shared/compileAgentWorkflow-DYFFyx7i.mjs +78 -0
- package/dist/packem_shared/{consoleTelemetry-z2MiP1jt.mjs → consoleTelemetry--3sWfu1R.mjs} +1 -1
- package/dist/packem_shared/{createAgentGenerate-BQv9YJ01.mjs → createAgentGenerate-DO7Z96zX.mjs} +1 -1
- package/dist/packem_shared/{defineAgent-D6maSbVc.mjs → defineAgent-DAwAZC9P.mjs} +1 -1
- package/dist/packem_shared/{graph-component-aoUwO-f0.mjs → graph-component-Bbaxxymp.mjs} +3 -2
- package/dist/packem_shared/{normalizeEntityName-CyEEWFkR.mjs → normalizeEntityName-BouctxLC.mjs} +1 -1
- package/dist/packem_shared/otlpTelemetry-DU5ZmoEV.mjs +177 -0
- package/dist/packem_shared/{runAgentLoop-Dhg4ZNvw.mjs → runAgentLoop-M8PKbtWT.mjs} +2 -2
- package/dist/packem_shared/{sentryTelemetry-CgqFJyLO.mjs → sentryTelemetry-A4F5ndh9.mjs} +1 -1
- package/dist/packem_shared/types.d-boAM2Yi1.d.mts +1114 -0
- package/dist/packem_shared/types.d-boAM2Yi1.d.ts +1114 -0
- package/dist/sandbox.d.mts +129 -110
- package/dist/sandbox.d.ts +129 -110
- package/dist/sandbox.mjs +5 -1
- package/dist/telemetry/index.d.mts +190 -86
- package/dist/telemetry/index.d.ts +190 -86
- package/dist/telemetry/index.mjs +4 -3
- package/package.json +8 -8
- package/dist/packem_shared/compileAgentWorkflow-BxJjHgtD.mjs +0 -55
- package/dist/packem_shared/types.d-BWG0uUtX.d.mts +0 -1015
- package/dist/packem_shared/types.d-BWG0uUtX.d.ts +0 -1015
package/dist/sandbox.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { a as AgentToolContext, b as AgentToolDefinition } from "./packem_shared/types.d-
|
|
1
|
+
import { a as AgentToolContext, b as AgentToolDefinition } from "./packem_shared/types.d-boAM2Yi1.mjs";
|
|
2
2
|
import '@lunora/mail/inbound';
|
|
3
3
|
import 'ai';
|
|
4
4
|
/**
|
|
5
|
-
* The model-provided input to a {@link browserTool} call — a discriminated
|
|
6
|
-
* union on `op` so one tool exposes every headless-browser capability.
|
|
7
|
-
|
|
5
|
+
* The model-provided input to a {@link browserTool} call — a discriminated
|
|
6
|
+
* union on `op` so one tool exposes every headless-browser capability.
|
|
7
|
+
* @experimental
|
|
8
|
+
*/
|
|
8
9
|
type BrowserToolInput = {
|
|
9
10
|
fullPage?: boolean;
|
|
10
11
|
op: "screenshot";
|
|
@@ -22,11 +23,12 @@ type BrowserToolInput = {
|
|
|
22
23
|
url: string;
|
|
23
24
|
};
|
|
24
25
|
/**
|
|
25
|
-
* The model-provided input to a {@link containerTool} call — a discriminated
|
|
26
|
-
* union on `op`. `fetch` sends an HTTP request to the container; `exec` asks it
|
|
27
|
-
* to run a command (routed as a POST to `/exec`, since the container surface
|
|
28
|
-
* exposes no first-class exec RPC — the container app must serve that route).
|
|
29
|
-
|
|
26
|
+
* The model-provided input to a {@link containerTool} call — a discriminated
|
|
27
|
+
* union on `op`. `fetch` sends an HTTP request to the container; `exec` asks it
|
|
28
|
+
* to run a command (routed as a POST to `/exec`, since the container surface
|
|
29
|
+
* exposes no first-class exec RPC — the container app must serve that route).
|
|
30
|
+
* @experimental
|
|
31
|
+
*/
|
|
30
32
|
type ContainerToolInput = {
|
|
31
33
|
args?: string[];
|
|
32
34
|
command?: string;
|
|
@@ -37,25 +39,29 @@ type ContainerToolInput = {
|
|
|
37
39
|
op: "fetch";
|
|
38
40
|
path: string;
|
|
39
41
|
};
|
|
40
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Author-supplied config for `browserTool`.
|
|
44
|
+
* @experimental
|
|
45
|
+
*/
|
|
41
46
|
interface BrowserToolOptions {
|
|
42
47
|
/** Override the model-facing description (what the tool does). */
|
|
43
48
|
description?: string;
|
|
44
49
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
* Gate a call behind a human approval. Defaults to **unattended** (no gate),
|
|
51
|
+
* matching the AI SDK. `browserTool` fetches a model-chosen `url` with no
|
|
52
|
+
* allowlist, so it is an SSRF surface: a prompt-injected model can point it at
|
|
53
|
+
* an internal/link-local address and read the response back into context. Pass
|
|
54
|
+
* a boolean or a predicate to gate it (evaluated from replay-stable input, so
|
|
55
|
+
* keep it deterministic).
|
|
56
|
+
*/
|
|
52
57
|
needsApproval?: ((input: BrowserToolInput) => boolean) | boolean;
|
|
53
58
|
}
|
|
54
59
|
/**
|
|
55
|
-
* The model-provided input to a {@link fsTool} call — a discriminated union on
|
|
56
|
-
* `op` over an R2-backed virtual filesystem. Paths are relative to the tool's
|
|
57
|
-
* pinned `root`; a `..` that escapes the root is rejected server-side.
|
|
58
|
-
|
|
60
|
+
* The model-provided input to a {@link fsTool} call — a discriminated union on
|
|
61
|
+
* `op` over an R2-backed virtual filesystem. Paths are relative to the tool's
|
|
62
|
+
* pinned `root`; a `..` that escapes the root is rejected server-side.
|
|
63
|
+
* @experimental
|
|
64
|
+
*/
|
|
59
65
|
type FsToolInput = {
|
|
60
66
|
op: "ls";
|
|
61
67
|
path?: string;
|
|
@@ -73,113 +79,126 @@ type FsToolInput = {
|
|
|
73
79
|
op: "write";
|
|
74
80
|
path: string;
|
|
75
81
|
};
|
|
76
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Author-supplied config for `fsTool`.
|
|
84
|
+
* @experimental
|
|
85
|
+
*/
|
|
77
86
|
interface FsToolOptions {
|
|
78
87
|
/** Override the model-facing description (what the tool does). */
|
|
79
88
|
description?: string;
|
|
80
89
|
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
* Gate a call behind a human approval. Defaults to gating the WRITING ops
|
|
91
|
+
* (`write`, `rm`) — a prompt-injected model shouldn't silently overwrite or
|
|
92
|
+
* delete the sandbox — while `ls`/`read`/`stat` run unattended. Pass a boolean
|
|
93
|
+
* or a predicate (evaluated from replay-stable input, so keep it deterministic).
|
|
94
|
+
*/
|
|
86
95
|
needsApproval?: ((input: FsToolInput) => boolean) | boolean;
|
|
87
96
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
* The key prefix every path is scoped under, isolating this tool's files from
|
|
98
|
+
* the rest of the bucket. Either a fixed string (e.g. `"agents/support"`) or a
|
|
99
|
+
* function of the tool context — return `` `agents/${ctx.threadKey}` `` (or an
|
|
100
|
+
* owner-derived prefix) to give each run/user its OWN namespace in a
|
|
101
|
+
* multi-tenant agent. Default: the bucket root (shared — set a root for
|
|
102
|
+
* multi-tenant use). The server rejects any `..` that would escape it.
|
|
103
|
+
*/
|
|
95
104
|
root?: ((context: AgentToolContext) => string) | string;
|
|
96
105
|
}
|
|
97
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Author-supplied config for `containerTool`.
|
|
108
|
+
* @experimental
|
|
109
|
+
*/
|
|
98
110
|
interface ContainerToolOptions {
|
|
99
111
|
/** Override the model-facing description (what the tool does). */
|
|
100
112
|
description?: string;
|
|
101
113
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
* Gate a call behind a human approval. Defaults to gating any command
|
|
115
|
+
* execution: an `exec`, AND a `fetch` whose path resolves to the privileged
|
|
116
|
+
* `/exec` route (both reach the same command-execution path in the container,
|
|
117
|
+
* so gating on the `op` name alone would let a `fetch` to `/exec` run a
|
|
118
|
+
* command unattended). A plain `fetch` to any other route runs unattended.
|
|
119
|
+
* Pass a boolean or your own predicate to change that. Evaluated from
|
|
120
|
+
* replay-stable input, so keep it deterministic.
|
|
121
|
+
*/
|
|
110
122
|
needsApproval?: ((input: ContainerToolInput) => boolean) | boolean;
|
|
111
123
|
}
|
|
112
124
|
/**
|
|
113
|
-
* A batteries-included agent tool that drives Cloudflare Browser Rendering. One
|
|
114
|
-
* tool exposes every browser op (screenshot / pdf / content / scrape); the model
|
|
115
|
-
* picks via `op`. The call dispatches to the auto-registered `sandbox:invoke`
|
|
116
|
-
* action — which runs on an action ctx carrying `ctx.browser`. Importing the tool
|
|
117
|
-
* makes codegen register the dispatcher and provision the `BROWSER` binding; like
|
|
118
|
-
* any `ctx.browser` user, the app still supplies a `config.browser` thunk
|
|
119
|
-
* (`createBrowser({ binding: env.BROWSER, launch })` with the optional
|
|
120
|
-
* `@cloudflare/playwright` `launch` peer) to `createShardDO()` — codegen never
|
|
121
|
-
* injects that peer, so the browser op throws a directed error until it is wired.
|
|
122
|
-
*
|
|
123
|
-
* Security: the model chooses the `url` with no allowlist, so this is an SSRF
|
|
124
|
-
* surface — pass `opts.needsApproval` to gate calls a prompt-injected model
|
|
125
|
-
* could aim at internal/link-local endpoints.
|
|
126
|
-
*
|
|
127
|
-
* ```ts
|
|
128
|
-
* import { browserTool, defineAgent } from "@lunora/agent/sandbox";
|
|
129
|
-
*
|
|
130
|
-
* export const researcher = defineAgent({
|
|
131
|
-
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
132
|
-
* tools: { browser: browserTool() },
|
|
133
|
-
* });
|
|
134
|
-
* ```
|
|
135
|
-
|
|
125
|
+
* A batteries-included agent tool that drives Cloudflare Browser Rendering. One
|
|
126
|
+
* tool exposes every browser op (screenshot / pdf / content / scrape); the model
|
|
127
|
+
* picks via `op`. The call dispatches to the auto-registered `sandbox:invoke`
|
|
128
|
+
* action — which runs on an action ctx carrying `ctx.browser`. Importing the tool
|
|
129
|
+
* makes codegen register the dispatcher and provision the `BROWSER` binding; like
|
|
130
|
+
* any `ctx.browser` user, the app still supplies a `config.browser` thunk
|
|
131
|
+
* (`createBrowser({ binding: env.BROWSER, launch })` with the optional
|
|
132
|
+
* `@cloudflare/playwright` `launch` peer) to `createShardDO()` — codegen never
|
|
133
|
+
* injects that peer, so the browser op throws a directed error until it is wired.
|
|
134
|
+
*
|
|
135
|
+
* Security: the model chooses the `url` with no allowlist, so this is an SSRF
|
|
136
|
+
* surface — pass `opts.needsApproval` to gate calls a prompt-injected model
|
|
137
|
+
* could aim at internal/link-local endpoints.
|
|
138
|
+
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { browserTool, defineAgent } from "@lunora/agent/sandbox";
|
|
141
|
+
*
|
|
142
|
+
* export const researcher = defineAgent({
|
|
143
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
144
|
+
* tools: { browser: browserTool() },
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
* @experimental
|
|
148
|
+
*/
|
|
136
149
|
declare const browserTool: (options?: BrowserToolOptions) => AgentToolDefinition<BrowserToolInput, string>;
|
|
137
150
|
/**
|
|
138
|
-
* A batteries-included agent tool that talks to a declared Cloudflare
|
|
139
|
-
* Container. `name` is the `ctx.containers.<name>` key (the `lunora/containers.ts`
|
|
140
|
-
* export). One tool exposes `fetch` (HTTP request) and `exec` (run a command);
|
|
141
|
-
* the model picks via `op`. The call dispatches to the auto-registered
|
|
142
|
-
* `sandbox:invoke` action, which carries `ctx.containers`.
|
|
143
|
-
*
|
|
144
|
-
* By default a `fetch` runs
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
|
|
151
|
+
* A batteries-included agent tool that talks to a declared Cloudflare
|
|
152
|
+
* Container. `name` is the `ctx.containers.<name>` key (the `lunora/containers.ts`
|
|
153
|
+
* export). One tool exposes `fetch` (HTTP request) and `exec` (run a command);
|
|
154
|
+
* the model picks via `op`. The call dispatches to the auto-registered
|
|
155
|
+
* `sandbox:invoke` action, which carries `ctx.containers`.
|
|
156
|
+
*
|
|
157
|
+
* By default a read-only (GET/HEAD/OPTIONS, or method-omitted) `fetch` runs
|
|
158
|
+
* unattended while everything else is gated behind a human approval — an
|
|
159
|
+
* `exec`; a `fetch` whose path resolves to the privileged `/exec` route (both
|
|
160
|
+
* reach the same command-execution path in the container, so gating on the
|
|
161
|
+
* `op` name alone would let a `fetch` to `/exec` run a command unattended);
|
|
162
|
+
* and a `fetch` using a non-idempotent method (POST/PUT/PATCH/DELETE) to ANY
|
|
163
|
+
* route, since a prompt-injected model could otherwise mutate container state
|
|
164
|
+
* through some other privileged route just by avoiding the literal `/exec`
|
|
165
|
+
* path. A `fetch` can still reach any *other read* route unattended, so scope
|
|
166
|
+
* the container's GET routes accordingly. Pass `opts.needsApproval` to widen
|
|
167
|
+
* or disable the gate.
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* import { containerTool, defineAgent } from "@lunora/agent/sandbox";
|
|
171
|
+
*
|
|
172
|
+
* export const ops = defineAgent({
|
|
173
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
174
|
+
* tools: { sandbox: containerTool("sandbox") },
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
* @experimental
|
|
178
|
+
*/
|
|
161
179
|
declare const containerTool: (name: string, options?: ContainerToolOptions) => AgentToolDefinition<ContainerToolInput, string>;
|
|
162
180
|
/**
|
|
163
|
-
* A batteries-included agent tool exposing a persistent, R2-backed virtual
|
|
164
|
-
* filesystem. `bucket` is the R2 binding name; every path is scoped under the
|
|
165
|
-
* pinned `opts.root` (a `..` that would escape it is rejected). One tool exposes
|
|
166
|
-
* `ls`/`read`/`write`/`rm`/`stat`; the model picks via `op`. The call dispatches
|
|
167
|
-
* to the auto-registered `sandbox:invoke` action, which reads the bucket from
|
|
168
|
-
* `ctx.env`. workerd has no real shell — this is object-store-backed file I/O.
|
|
169
|
-
*
|
|
170
|
-
* By default the writing ops (`write`/`rm`) pause for a human approval while
|
|
171
|
-
* reads run unattended; pass `opts.needsApproval` to change that. Importing the
|
|
172
|
-
* tool registers the dispatcher; the app must declare the `r2_bucket` binding in
|
|
173
|
-
* `wrangler.jsonc` (the fs op throws a directed error until it is wired).
|
|
174
|
-
*
|
|
175
|
-
* ```ts
|
|
176
|
-
* import { defineAgent, fsTool } from "@lunora/agent/sandbox";
|
|
177
|
-
*
|
|
178
|
-
* export const coder = defineAgent({
|
|
179
|
-
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
180
|
-
* tools: { fs: fsTool("SANDBOX_BUCKET", { root: "agents/coder" }) },
|
|
181
|
-
* });
|
|
182
|
-
* ```
|
|
183
|
-
|
|
181
|
+
* A batteries-included agent tool exposing a persistent, R2-backed virtual
|
|
182
|
+
* filesystem. `bucket` is the R2 binding name; every path is scoped under the
|
|
183
|
+
* pinned `opts.root` (a `..` that would escape it is rejected). One tool exposes
|
|
184
|
+
* `ls`/`read`/`write`/`rm`/`stat`; the model picks via `op`. The call dispatches
|
|
185
|
+
* to the auto-registered `sandbox:invoke` action, which reads the bucket from
|
|
186
|
+
* `ctx.env`. workerd has no real shell — this is object-store-backed file I/O.
|
|
187
|
+
*
|
|
188
|
+
* By default the writing ops (`write`/`rm`) pause for a human approval while
|
|
189
|
+
* reads run unattended; pass `opts.needsApproval` to change that. Importing the
|
|
190
|
+
* tool registers the dispatcher; the app must declare the `r2_bucket` binding in
|
|
191
|
+
* `wrangler.jsonc` (the fs op throws a directed error until it is wired).
|
|
192
|
+
*
|
|
193
|
+
* ```ts
|
|
194
|
+
* import { defineAgent, fsTool } from "@lunora/agent/sandbox";
|
|
195
|
+
*
|
|
196
|
+
* export const coder = defineAgent({
|
|
197
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
198
|
+
* tools: { fs: fsTool("SANDBOX_BUCKET", { root: "agents/coder" }) },
|
|
199
|
+
* });
|
|
200
|
+
* ```
|
|
201
|
+
* @experimental
|
|
202
|
+
*/
|
|
184
203
|
declare const fsTool: (bucket: string, options?: FsToolOptions) => AgentToolDefinition<FsToolInput>;
|
|
185
204
|
export { type BrowserToolInput, type BrowserToolOptions, type ContainerToolInput, type ContainerToolOptions, type FsToolInput, type FsToolOptions, browserTool, containerTool, fsTool };
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { a as AgentToolContext, b as AgentToolDefinition } from "./packem_shared/types.d-
|
|
1
|
+
import { a as AgentToolContext, b as AgentToolDefinition } from "./packem_shared/types.d-boAM2Yi1.js";
|
|
2
2
|
import '@lunora/mail/inbound';
|
|
3
3
|
import 'ai';
|
|
4
4
|
/**
|
|
5
|
-
* The model-provided input to a {@link browserTool} call — a discriminated
|
|
6
|
-
* union on `op` so one tool exposes every headless-browser capability.
|
|
7
|
-
|
|
5
|
+
* The model-provided input to a {@link browserTool} call — a discriminated
|
|
6
|
+
* union on `op` so one tool exposes every headless-browser capability.
|
|
7
|
+
* @experimental
|
|
8
|
+
*/
|
|
8
9
|
type BrowserToolInput = {
|
|
9
10
|
fullPage?: boolean;
|
|
10
11
|
op: "screenshot";
|
|
@@ -22,11 +23,12 @@ type BrowserToolInput = {
|
|
|
22
23
|
url: string;
|
|
23
24
|
};
|
|
24
25
|
/**
|
|
25
|
-
* The model-provided input to a {@link containerTool} call — a discriminated
|
|
26
|
-
* union on `op`. `fetch` sends an HTTP request to the container; `exec` asks it
|
|
27
|
-
* to run a command (routed as a POST to `/exec`, since the container surface
|
|
28
|
-
* exposes no first-class exec RPC — the container app must serve that route).
|
|
29
|
-
|
|
26
|
+
* The model-provided input to a {@link containerTool} call — a discriminated
|
|
27
|
+
* union on `op`. `fetch` sends an HTTP request to the container; `exec` asks it
|
|
28
|
+
* to run a command (routed as a POST to `/exec`, since the container surface
|
|
29
|
+
* exposes no first-class exec RPC — the container app must serve that route).
|
|
30
|
+
* @experimental
|
|
31
|
+
*/
|
|
30
32
|
type ContainerToolInput = {
|
|
31
33
|
args?: string[];
|
|
32
34
|
command?: string;
|
|
@@ -37,25 +39,29 @@ type ContainerToolInput = {
|
|
|
37
39
|
op: "fetch";
|
|
38
40
|
path: string;
|
|
39
41
|
};
|
|
40
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Author-supplied config for `browserTool`.
|
|
44
|
+
* @experimental
|
|
45
|
+
*/
|
|
41
46
|
interface BrowserToolOptions {
|
|
42
47
|
/** Override the model-facing description (what the tool does). */
|
|
43
48
|
description?: string;
|
|
44
49
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
* Gate a call behind a human approval. Defaults to **unattended** (no gate),
|
|
51
|
+
* matching the AI SDK. `browserTool` fetches a model-chosen `url` with no
|
|
52
|
+
* allowlist, so it is an SSRF surface: a prompt-injected model can point it at
|
|
53
|
+
* an internal/link-local address and read the response back into context. Pass
|
|
54
|
+
* a boolean or a predicate to gate it (evaluated from replay-stable input, so
|
|
55
|
+
* keep it deterministic).
|
|
56
|
+
*/
|
|
52
57
|
needsApproval?: ((input: BrowserToolInput) => boolean) | boolean;
|
|
53
58
|
}
|
|
54
59
|
/**
|
|
55
|
-
* The model-provided input to a {@link fsTool} call — a discriminated union on
|
|
56
|
-
* `op` over an R2-backed virtual filesystem. Paths are relative to the tool's
|
|
57
|
-
* pinned `root`; a `..` that escapes the root is rejected server-side.
|
|
58
|
-
|
|
60
|
+
* The model-provided input to a {@link fsTool} call — a discriminated union on
|
|
61
|
+
* `op` over an R2-backed virtual filesystem. Paths are relative to the tool's
|
|
62
|
+
* pinned `root`; a `..` that escapes the root is rejected server-side.
|
|
63
|
+
* @experimental
|
|
64
|
+
*/
|
|
59
65
|
type FsToolInput = {
|
|
60
66
|
op: "ls";
|
|
61
67
|
path?: string;
|
|
@@ -73,113 +79,126 @@ type FsToolInput = {
|
|
|
73
79
|
op: "write";
|
|
74
80
|
path: string;
|
|
75
81
|
};
|
|
76
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Author-supplied config for `fsTool`.
|
|
84
|
+
* @experimental
|
|
85
|
+
*/
|
|
77
86
|
interface FsToolOptions {
|
|
78
87
|
/** Override the model-facing description (what the tool does). */
|
|
79
88
|
description?: string;
|
|
80
89
|
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
* Gate a call behind a human approval. Defaults to gating the WRITING ops
|
|
91
|
+
* (`write`, `rm`) — a prompt-injected model shouldn't silently overwrite or
|
|
92
|
+
* delete the sandbox — while `ls`/`read`/`stat` run unattended. Pass a boolean
|
|
93
|
+
* or a predicate (evaluated from replay-stable input, so keep it deterministic).
|
|
94
|
+
*/
|
|
86
95
|
needsApproval?: ((input: FsToolInput) => boolean) | boolean;
|
|
87
96
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
* The key prefix every path is scoped under, isolating this tool's files from
|
|
98
|
+
* the rest of the bucket. Either a fixed string (e.g. `"agents/support"`) or a
|
|
99
|
+
* function of the tool context — return `` `agents/${ctx.threadKey}` `` (or an
|
|
100
|
+
* owner-derived prefix) to give each run/user its OWN namespace in a
|
|
101
|
+
* multi-tenant agent. Default: the bucket root (shared — set a root for
|
|
102
|
+
* multi-tenant use). The server rejects any `..` that would escape it.
|
|
103
|
+
*/
|
|
95
104
|
root?: ((context: AgentToolContext) => string) | string;
|
|
96
105
|
}
|
|
97
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Author-supplied config for `containerTool`.
|
|
108
|
+
* @experimental
|
|
109
|
+
*/
|
|
98
110
|
interface ContainerToolOptions {
|
|
99
111
|
/** Override the model-facing description (what the tool does). */
|
|
100
112
|
description?: string;
|
|
101
113
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
* Gate a call behind a human approval. Defaults to gating any command
|
|
115
|
+
* execution: an `exec`, AND a `fetch` whose path resolves to the privileged
|
|
116
|
+
* `/exec` route (both reach the same command-execution path in the container,
|
|
117
|
+
* so gating on the `op` name alone would let a `fetch` to `/exec` run a
|
|
118
|
+
* command unattended). A plain `fetch` to any other route runs unattended.
|
|
119
|
+
* Pass a boolean or your own predicate to change that. Evaluated from
|
|
120
|
+
* replay-stable input, so keep it deterministic.
|
|
121
|
+
*/
|
|
110
122
|
needsApproval?: ((input: ContainerToolInput) => boolean) | boolean;
|
|
111
123
|
}
|
|
112
124
|
/**
|
|
113
|
-
* A batteries-included agent tool that drives Cloudflare Browser Rendering. One
|
|
114
|
-
* tool exposes every browser op (screenshot / pdf / content / scrape); the model
|
|
115
|
-
* picks via `op`. The call dispatches to the auto-registered `sandbox:invoke`
|
|
116
|
-
* action — which runs on an action ctx carrying `ctx.browser`. Importing the tool
|
|
117
|
-
* makes codegen register the dispatcher and provision the `BROWSER` binding; like
|
|
118
|
-
* any `ctx.browser` user, the app still supplies a `config.browser` thunk
|
|
119
|
-
* (`createBrowser({ binding: env.BROWSER, launch })` with the optional
|
|
120
|
-
* `@cloudflare/playwright` `launch` peer) to `createShardDO()` — codegen never
|
|
121
|
-
* injects that peer, so the browser op throws a directed error until it is wired.
|
|
122
|
-
*
|
|
123
|
-
* Security: the model chooses the `url` with no allowlist, so this is an SSRF
|
|
124
|
-
* surface — pass `opts.needsApproval` to gate calls a prompt-injected model
|
|
125
|
-
* could aim at internal/link-local endpoints.
|
|
126
|
-
*
|
|
127
|
-
* ```ts
|
|
128
|
-
* import { browserTool, defineAgent } from "@lunora/agent/sandbox";
|
|
129
|
-
*
|
|
130
|
-
* export const researcher = defineAgent({
|
|
131
|
-
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
132
|
-
* tools: { browser: browserTool() },
|
|
133
|
-
* });
|
|
134
|
-
* ```
|
|
135
|
-
|
|
125
|
+
* A batteries-included agent tool that drives Cloudflare Browser Rendering. One
|
|
126
|
+
* tool exposes every browser op (screenshot / pdf / content / scrape); the model
|
|
127
|
+
* picks via `op`. The call dispatches to the auto-registered `sandbox:invoke`
|
|
128
|
+
* action — which runs on an action ctx carrying `ctx.browser`. Importing the tool
|
|
129
|
+
* makes codegen register the dispatcher and provision the `BROWSER` binding; like
|
|
130
|
+
* any `ctx.browser` user, the app still supplies a `config.browser` thunk
|
|
131
|
+
* (`createBrowser({ binding: env.BROWSER, launch })` with the optional
|
|
132
|
+
* `@cloudflare/playwright` `launch` peer) to `createShardDO()` — codegen never
|
|
133
|
+
* injects that peer, so the browser op throws a directed error until it is wired.
|
|
134
|
+
*
|
|
135
|
+
* Security: the model chooses the `url` with no allowlist, so this is an SSRF
|
|
136
|
+
* surface — pass `opts.needsApproval` to gate calls a prompt-injected model
|
|
137
|
+
* could aim at internal/link-local endpoints.
|
|
138
|
+
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { browserTool, defineAgent } from "@lunora/agent/sandbox";
|
|
141
|
+
*
|
|
142
|
+
* export const researcher = defineAgent({
|
|
143
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
144
|
+
* tools: { browser: browserTool() },
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
* @experimental
|
|
148
|
+
*/
|
|
136
149
|
declare const browserTool: (options?: BrowserToolOptions) => AgentToolDefinition<BrowserToolInput, string>;
|
|
137
150
|
/**
|
|
138
|
-
* A batteries-included agent tool that talks to a declared Cloudflare
|
|
139
|
-
* Container. `name` is the `ctx.containers.<name>` key (the `lunora/containers.ts`
|
|
140
|
-
* export). One tool exposes `fetch` (HTTP request) and `exec` (run a command);
|
|
141
|
-
* the model picks via `op`. The call dispatches to the auto-registered
|
|
142
|
-
* `sandbox:invoke` action, which carries `ctx.containers`.
|
|
143
|
-
*
|
|
144
|
-
* By default a `fetch` runs
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
|
|
151
|
+
* A batteries-included agent tool that talks to a declared Cloudflare
|
|
152
|
+
* Container. `name` is the `ctx.containers.<name>` key (the `lunora/containers.ts`
|
|
153
|
+
* export). One tool exposes `fetch` (HTTP request) and `exec` (run a command);
|
|
154
|
+
* the model picks via `op`. The call dispatches to the auto-registered
|
|
155
|
+
* `sandbox:invoke` action, which carries `ctx.containers`.
|
|
156
|
+
*
|
|
157
|
+
* By default a read-only (GET/HEAD/OPTIONS, or method-omitted) `fetch` runs
|
|
158
|
+
* unattended while everything else is gated behind a human approval — an
|
|
159
|
+
* `exec`; a `fetch` whose path resolves to the privileged `/exec` route (both
|
|
160
|
+
* reach the same command-execution path in the container, so gating on the
|
|
161
|
+
* `op` name alone would let a `fetch` to `/exec` run a command unattended);
|
|
162
|
+
* and a `fetch` using a non-idempotent method (POST/PUT/PATCH/DELETE) to ANY
|
|
163
|
+
* route, since a prompt-injected model could otherwise mutate container state
|
|
164
|
+
* through some other privileged route just by avoiding the literal `/exec`
|
|
165
|
+
* path. A `fetch` can still reach any *other read* route unattended, so scope
|
|
166
|
+
* the container's GET routes accordingly. Pass `opts.needsApproval` to widen
|
|
167
|
+
* or disable the gate.
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* import { containerTool, defineAgent } from "@lunora/agent/sandbox";
|
|
171
|
+
*
|
|
172
|
+
* export const ops = defineAgent({
|
|
173
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
174
|
+
* tools: { sandbox: containerTool("sandbox") },
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
* @experimental
|
|
178
|
+
*/
|
|
161
179
|
declare const containerTool: (name: string, options?: ContainerToolOptions) => AgentToolDefinition<ContainerToolInput, string>;
|
|
162
180
|
/**
|
|
163
|
-
* A batteries-included agent tool exposing a persistent, R2-backed virtual
|
|
164
|
-
* filesystem. `bucket` is the R2 binding name; every path is scoped under the
|
|
165
|
-
* pinned `opts.root` (a `..` that would escape it is rejected). One tool exposes
|
|
166
|
-
* `ls`/`read`/`write`/`rm`/`stat`; the model picks via `op`. The call dispatches
|
|
167
|
-
* to the auto-registered `sandbox:invoke` action, which reads the bucket from
|
|
168
|
-
* `ctx.env`. workerd has no real shell — this is object-store-backed file I/O.
|
|
169
|
-
*
|
|
170
|
-
* By default the writing ops (`write`/`rm`) pause for a human approval while
|
|
171
|
-
* reads run unattended; pass `opts.needsApproval` to change that. Importing the
|
|
172
|
-
* tool registers the dispatcher; the app must declare the `r2_bucket` binding in
|
|
173
|
-
* `wrangler.jsonc` (the fs op throws a directed error until it is wired).
|
|
174
|
-
*
|
|
175
|
-
* ```ts
|
|
176
|
-
* import { defineAgent, fsTool } from "@lunora/agent/sandbox";
|
|
177
|
-
*
|
|
178
|
-
* export const coder = defineAgent({
|
|
179
|
-
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
180
|
-
* tools: { fs: fsTool("SANDBOX_BUCKET", { root: "agents/coder" }) },
|
|
181
|
-
* });
|
|
182
|
-
* ```
|
|
183
|
-
|
|
181
|
+
* A batteries-included agent tool exposing a persistent, R2-backed virtual
|
|
182
|
+
* filesystem. `bucket` is the R2 binding name; every path is scoped under the
|
|
183
|
+
* pinned `opts.root` (a `..` that would escape it is rejected). One tool exposes
|
|
184
|
+
* `ls`/`read`/`write`/`rm`/`stat`; the model picks via `op`. The call dispatches
|
|
185
|
+
* to the auto-registered `sandbox:invoke` action, which reads the bucket from
|
|
186
|
+
* `ctx.env`. workerd has no real shell — this is object-store-backed file I/O.
|
|
187
|
+
*
|
|
188
|
+
* By default the writing ops (`write`/`rm`) pause for a human approval while
|
|
189
|
+
* reads run unattended; pass `opts.needsApproval` to change that. Importing the
|
|
190
|
+
* tool registers the dispatcher; the app must declare the `r2_bucket` binding in
|
|
191
|
+
* `wrangler.jsonc` (the fs op throws a directed error until it is wired).
|
|
192
|
+
*
|
|
193
|
+
* ```ts
|
|
194
|
+
* import { defineAgent, fsTool } from "@lunora/agent/sandbox";
|
|
195
|
+
*
|
|
196
|
+
* export const coder = defineAgent({
|
|
197
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
198
|
+
* tools: { fs: fsTool("SANDBOX_BUCKET", { root: "agents/coder" }) },
|
|
199
|
+
* });
|
|
200
|
+
* ```
|
|
201
|
+
* @experimental
|
|
202
|
+
*/
|
|
184
203
|
declare const fsTool: (bucket: string, options?: FsToolOptions) => AgentToolDefinition<FsToolInput>;
|
|
185
204
|
export { type BrowserToolInput, type BrowserToolOptions, type ContainerToolInput, type ContainerToolOptions, type FsToolInput, type FsToolOptions, browserTool, containerTool, fsTool };
|
package/dist/sandbox.mjs
CHANGED
|
@@ -44,11 +44,15 @@ const normalizeContainerPath = (path) => {
|
|
|
44
44
|
}
|
|
45
45
|
return `/${segments.join("/")}`;
|
|
46
46
|
};
|
|
47
|
+
const NON_IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["DELETE", "PATCH", "POST", "PUT"]);
|
|
47
48
|
const defaultContainerGate = (input) => {
|
|
48
49
|
if (input.op === "exec") {
|
|
49
50
|
return true;
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
if (normalizeContainerPath(input.path) === CONTAINER_EXEC_ROUTE) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return NON_IDEMPOTENT_METHODS.has((input.method ?? "GET").toUpperCase());
|
|
52
56
|
};
|
|
53
57
|
const CONTAINER_TOOL_SCHEMA = jsonSchema({
|
|
54
58
|
properties: {
|