@lunora/agent 1.0.0-alpha.16 → 1.0.0-alpha.160
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/channels.d.mts +23 -12
- package/dist/channels.d.ts +23 -12
- package/dist/channels.mjs +1 -1
- package/dist/component.d.mts +2 -0
- package/dist/component.d.ts +2 -0
- package/dist/component.mjs +2 -2
- package/dist/inbound.d.mts +9 -7
- package/dist/inbound.d.ts +9 -7
- package/dist/inbound.mjs +1 -1
- package/dist/index.d.mts +62 -15
- package/dist/index.d.ts +62 -15
- package/dist/index.mjs +1 -1
- package/dist/naming.d.mts +3 -7
- package/dist/naming.d.ts +3 -7
- package/dist/naming.mjs +1 -1
- package/dist/packem_shared/AGENT_MODULE-M4D1EejI.mjs +1 -0
- package/dist/packem_shared/DEFAULT_DISPATCH_TIMEOUT_MS-DRXZ0uJJ-CzPOpA2g.mjs +1 -0
- package/dist/packem_shared/VoiceSessionDO-Dc09ClZz.mjs +1 -0
- package/dist/packem_shared/adaptMcpResult-CVlq-_TO.mjs +2 -0
- package/dist/packem_shared/agent-loop-CQUKMFWA.mjs +3 -0
- package/dist/packem_shared/agentAsTool-1Gwq45M3.mjs +1 -0
- package/dist/packem_shared/braintrustTelemetry-Byne8uPK.mjs +1 -0
- package/dist/packem_shared/branch-marker-boZ00zmk.mjs +1 -0
- package/dist/packem_shared/buildModelMessages-Y4tGo1T9.mjs +5 -0
- package/dist/packem_shared/codeTool-BQb-K3my.mjs +1 -0
- package/dist/packem_shared/collectAgenticMemoryTools-BeMWT2qt.mjs +1 -0
- package/dist/packem_shared/combineTelemetry-DgE9W9G8.mjs +1 -0
- package/dist/packem_shared/common-CJSjtsfv.mjs +1 -0
- package/dist/packem_shared/compileAgentWorkflow-Dijgn4Cz.mjs +1 -0
- package/dist/packem_shared/component-shared-G8ngerkU.mjs +1 -0
- package/dist/packem_shared/consoleTelemetry-BZY3Y-Ly.mjs +1 -0
- package/dist/packem_shared/createAgentContext-D3mf7LEU.mjs +1 -0
- package/dist/packem_shared/createAgentGenerate-BOILDUZj.mjs +3 -0
- package/dist/packem_shared/defineAgent-CK3CpiOr.mjs +3 -0
- package/dist/packem_shared/defineSkill-DGGvDWNq.mjs +1 -0
- package/dist/packem_shared/fnv1a-BNN96GYb.mjs +1 -0
- package/dist/packem_shared/functionTool-D3CP4f8-.mjs +1 -0
- package/dist/packem_shared/in-flight-calls-GH1A_1P3.mjs +1 -0
- package/dist/packem_shared/jsCodeTool-BLOvjXGF.mjs +18 -0
- package/dist/packem_shared/normalizeEntityName-k3fjicAG.mjs +2 -0
- package/dist/packem_shared/otlpTelemetry-ByqrB-72.mjs +1 -0
- package/dist/packem_shared/positive-integer-ztHqqpBk.mjs +1 -0
- package/dist/packem_shared/runAgentLoop-DFDJPAyk.mjs +1 -0
- package/dist/packem_shared/runVoiceTurn-xFvfDZ2Q.mjs +1 -0
- package/dist/packem_shared/sandbox-budgets-DDvj4Orr.mjs +1 -0
- package/dist/packem_shared/sandboxComponent-CKX-iNXC.mjs +7 -0
- package/dist/packem_shared/sentryTelemetry-BHeydiAB.mjs +1 -0
- package/dist/packem_shared/tool-output-Cmk3JWMG.mjs +1 -0
- package/dist/packem_shared/{types.d-boAM2Yi1.d.mts → types.d-CbYtFBw9.d.mts} +289 -27
- package/dist/packem_shared/{types.d-boAM2Yi1.d.ts → types.d-CbYtFBw9.d.ts} +289 -27
- package/dist/packem_shared/voice-turn-BiDZeZwp.mjs +1 -0
- package/dist/packem_shared/workflow-binding-Dm9hBzx_.mjs +1 -0
- package/dist/reply.d.mts +40 -0
- package/dist/reply.d.ts +40 -0
- package/dist/reply.mjs +1 -0
- package/dist/sandbox.d.mts +114 -16
- package/dist/sandbox.d.ts +114 -16
- package/dist/sandbox.mjs +1 -1
- package/dist/skill-markdown.d.mts +36 -0
- package/dist/skill-markdown.d.ts +36 -0
- package/dist/skill-markdown.mjs +1 -0
- package/dist/telemetry/index.d.mts +152 -33
- package/dist/telemetry/index.d.ts +152 -33
- package/dist/telemetry/index.mjs +1 -1
- package/package.json +18 -9
- package/dist/packem_shared/AGENT_MODULE-BXx-tSCe.mjs +0 -1
- package/dist/packem_shared/VoiceSessionDO-CTaBSdXk.mjs +0 -1
- package/dist/packem_shared/adaptMcpResult-18G7zpFo.mjs +0 -2
- package/dist/packem_shared/agentAsTool-CJCTyAQG.mjs +0 -1
- package/dist/packem_shared/base64-jU-Ci6Tu.mjs +0 -1
- package/dist/packem_shared/braintrustTelemetry-CnOI5WAw.mjs +0 -1
- package/dist/packem_shared/buildModelMessages-Dm2wVNQy.mjs +0 -5
- package/dist/packem_shared/codeTool-DYJVy-bH.mjs +0 -1
- package/dist/packem_shared/collectAgenticMemoryTools-DBcP8dUa.mjs +0 -1
- package/dist/packem_shared/combineTelemetry-oLCV_EPV.mjs +0 -1
- package/dist/packem_shared/common-Dck97z3Y.mjs +0 -1
- package/dist/packem_shared/compileAgentWorkflow-C4xqSw82.mjs +0 -1
- package/dist/packem_shared/consoleTelemetry-CaoI-NGg.mjs +0 -1
- package/dist/packem_shared/createAgentContext-B1IfI7ro.mjs +0 -1
- package/dist/packem_shared/createAgentGenerate-BUVImo85.mjs +0 -3
- package/dist/packem_shared/createDispatchRunner-CQ8HXscn-BrqT0bIG.mjs +0 -1
- package/dist/packem_shared/defineAgent-CKhzzmys.mjs +0 -3
- package/dist/packem_shared/defineSkill-DfJxCwfZ.mjs +0 -1
- package/dist/packem_shared/functionTool-CWHhkYqd.mjs +0 -1
- package/dist/packem_shared/graph-component-B2YmC2eL.mjs +0 -2
- package/dist/packem_shared/memory-DNRyyp1b.mjs +0 -1
- package/dist/packem_shared/normalizeEntityName-BQpyssvL.mjs +0 -1
- package/dist/packem_shared/otlpTelemetry-DcW9mOLV.mjs +0 -1
- package/dist/packem_shared/runAgentLoop-DNAt-pGz.mjs +0 -3
- package/dist/packem_shared/runVoiceTurn-PkMsfG_v.mjs +0 -1
- package/dist/packem_shared/sandboxComponent-BhaGHsQZ.mjs +0 -1
- package/dist/packem_shared/sentryTelemetry-Dr2aPuvl.mjs +0 -1
package/dist/sandbox.d.mts
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as AgentToolDefinition, d as AgentToolContext } from "./packem_shared/types.d-CbYtFBw9.mjs";
|
|
2
2
|
import '@lunora/mail/inbound';
|
|
3
3
|
import 'ai';
|
|
4
|
+
/**
|
|
5
|
+
* The model-provided input to a {@link jsCodeTool} call.
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
interface JsCodeToolInput {
|
|
9
|
+
/** The body of an `async` function. Its `return` value is the result. */
|
|
10
|
+
code: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What a {@link jsCodeTool} call resolves to. `error` is set instead of `value`
|
|
14
|
+
* when the script threw, did not parse, returned something that is not JSON,
|
|
15
|
+
* or ran out of time.
|
|
16
|
+
* @experimental
|
|
17
|
+
*/
|
|
18
|
+
interface JsCodeToolResult {
|
|
19
|
+
error?: string;
|
|
20
|
+
/** `console.*` output, one entry per call, at most {@link MAX_LOG_ENTRIES}. */
|
|
21
|
+
logs: string[];
|
|
22
|
+
value?: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** Options for {@link jsCodeTool}. */
|
|
25
|
+
interface JsCodeToolOptions {
|
|
26
|
+
/** CPU budget per run, enforced by the loader. Default 1000 ms. */
|
|
27
|
+
cpuMs?: number;
|
|
28
|
+
/** Tool description shown to the model. */
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A batteries-included agent tool that runs model-written JavaScript in a
|
|
33
|
+
* Worker Loader isolate — Cloudflare's Dynamic Workers, which celld implements
|
|
34
|
+
* too. The script gets no network (`globalOutbound: null`), no bindings, no
|
|
35
|
+
* tools and a CPU budget, so it is for computation: arithmetic, parsing,
|
|
36
|
+
* reshaping data the model already has. It returns the script's JSON result
|
|
37
|
+
* and its `console` output. A failure comes back as a result with `error` set,
|
|
38
|
+
* not a throw, so the durable step does not retry a script that will fail the
|
|
39
|
+
* same way again.
|
|
40
|
+
*
|
|
41
|
+
* Importing the tool makes codegen provision the `worker_loaders` binding
|
|
42
|
+
* (`LOADER`) and refuse a target whose matrix rates `workerLoaders`
|
|
43
|
+
* `unsupported`.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { defineAgent, jsCodeTool } from "@lunora/agent";
|
|
47
|
+
*
|
|
48
|
+
* export const analyst = defineAgent({
|
|
49
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
50
|
+
* tools: { js: jsCodeTool() },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
* @experimental
|
|
54
|
+
*/
|
|
55
|
+
declare const jsCodeTool: (options?: JsCodeToolOptions) => AgentToolDefinition<JsCodeToolInput, JsCodeToolResult>;
|
|
56
|
+
/**
|
|
57
|
+
* What a byte-returning browser op resolves to. The render is written to R2 and
|
|
58
|
+
* its key comes back — never the bytes, which would be truncated to the model's
|
|
59
|
+
* output cap and billed for nothing.
|
|
60
|
+
* @experimental
|
|
61
|
+
*/
|
|
62
|
+
interface BrowserRenderResult {
|
|
63
|
+
/** Size of the stored object. */
|
|
64
|
+
bytes: number;
|
|
65
|
+
/** The absolute R2 key the render was written to. */
|
|
66
|
+
key: string;
|
|
67
|
+
/** The render's content type, e.g. `image/jpeg`. */
|
|
68
|
+
mediaType: string;
|
|
69
|
+
}
|
|
4
70
|
/**
|
|
5
71
|
* The model-provided input to a {@link browserTool} call — a discriminated
|
|
6
72
|
* union on `op` so one tool exposes every headless-browser capability.
|
|
@@ -25,8 +91,8 @@ type BrowserToolInput = {
|
|
|
25
91
|
/**
|
|
26
92
|
* The model-provided input to a {@link containerTool} call — a discriminated
|
|
27
93
|
* union on `op`. `fetch` sends an HTTP request to the container; `exec` asks it
|
|
28
|
-
* to run a command (
|
|
29
|
-
*
|
|
94
|
+
* to run a command (delegated to `ctx.containers.<name>.exec`, the first-class
|
|
95
|
+
* exec contract in `@lunora/container`; the container app serves its route).
|
|
30
96
|
* @experimental
|
|
31
97
|
*/
|
|
32
98
|
type ContainerToolInput = {
|
|
@@ -44,6 +110,17 @@ type ContainerToolInput = {
|
|
|
44
110
|
* @experimental
|
|
45
111
|
*/
|
|
46
112
|
interface BrowserToolOptions {
|
|
113
|
+
/**
|
|
114
|
+
* R2 binding name the byte-returning ops (`screenshot`, `pdf`) write their
|
|
115
|
+
* render to. REQUIRED for those two: a render is billed, and a tool result
|
|
116
|
+
* is capped at `MAX_TOOL_OUTPUT_CHARS`, so base64 bytes inline would be
|
|
117
|
+
* truncated mid-string and unusable by the model — paid for and thrown
|
|
118
|
+
* away. With a bucket the op returns `{ bytes, key, mediaType }` and the
|
|
119
|
+
* app serves or post-processes the object by key. `content`/`scrape`
|
|
120
|
+
* return text and need no bucket; without one, a `screenshot`/`pdf` call is
|
|
121
|
+
* refused as a tool result (never dispatched) so nothing is billed.
|
|
122
|
+
*/
|
|
123
|
+
bucket?: string;
|
|
47
124
|
/** Override the model-facing description (what the tool does). */
|
|
48
125
|
description?: string;
|
|
49
126
|
/**
|
|
@@ -55,6 +132,14 @@ interface BrowserToolOptions {
|
|
|
55
132
|
* keep it deterministic).
|
|
56
133
|
*/
|
|
57
134
|
needsApproval?: ((input: BrowserToolInput) => boolean) | boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Key prefix inside {@link BrowserToolOptions.bucket} that renders are
|
|
137
|
+
* written under, isolating them from the rest of the bucket. Default: the
|
|
138
|
+
* bucket root. Each render lands at `<root>/<threadKey>/<toolCallId>.<ext>`
|
|
139
|
+
* — derived only from replay-stable identifiers, so a retried step
|
|
140
|
+
* overwrites its own object rather than accumulating one per attempt.
|
|
141
|
+
*/
|
|
142
|
+
root?: string;
|
|
58
143
|
}
|
|
59
144
|
/**
|
|
60
145
|
* The model-provided input to a {@link fsTool} call — a discriminated union on
|
|
@@ -112,12 +197,13 @@ interface ContainerToolOptions {
|
|
|
112
197
|
description?: string;
|
|
113
198
|
/**
|
|
114
199
|
* Gate a call behind a human approval. Defaults to gating any command
|
|
115
|
-
* execution
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* Pass a boolean or your own
|
|
120
|
-
* replay-stable input, so keep it
|
|
200
|
+
* execution — an `exec` — plus any `fetch` using a non-idempotent method
|
|
201
|
+
* (POST/PUT/PATCH/DELETE), so a prompt-injected model cannot reach some
|
|
202
|
+
* other mutating route unattended. A read-only `fetch` runs unattended. The
|
|
203
|
+
* exec route itself needs no special case: `@lunora/container` reserves
|
|
204
|
+
* `/__lunora/*` and refuses a `fetch` into it. Pass a boolean or your own
|
|
205
|
+
* predicate to change that. Evaluated from replay-stable input, so keep it
|
|
206
|
+
* deterministic.
|
|
121
207
|
*/
|
|
122
208
|
needsApproval?: ((input: ContainerToolInput) => boolean) | boolean;
|
|
123
209
|
}
|
|
@@ -132,6 +218,12 @@ interface ContainerToolOptions {
|
|
|
132
218
|
* `@cloudflare/playwright` `launch` peer) to `createShardDO()` — codegen never
|
|
133
219
|
* injects that peer, so the browser op throws a directed error until it is wired.
|
|
134
220
|
*
|
|
221
|
+
* `content`/`scrape` return text. `screenshot`/`pdf` write the render to
|
|
222
|
+
* `opts.bucket` and return `{ bytes, key, mediaType }` — never the bytes
|
|
223
|
+
* themselves, which a 4000-char tool-output cap would truncate into something
|
|
224
|
+
* unusable after paying for the render. Without a bucket those two ops are
|
|
225
|
+
* refused as a tool result and never dispatched.
|
|
226
|
+
*
|
|
135
227
|
* Security: the model chooses the `url` with no allowlist, so this is an SSRF
|
|
136
228
|
* surface — pass `opts.needsApproval` to gate calls a prompt-injected model
|
|
137
229
|
* could aim at internal/link-local endpoints.
|
|
@@ -141,27 +233,33 @@ interface ContainerToolOptions {
|
|
|
141
233
|
*
|
|
142
234
|
* export const researcher = defineAgent({
|
|
143
235
|
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
144
|
-
* tools: { browser: browserTool() },
|
|
236
|
+
* tools: { browser: browserTool({ bucket: "SANDBOX_BUCKET", root: "renders" }) },
|
|
145
237
|
* });
|
|
146
238
|
* ```
|
|
147
239
|
* @experimental
|
|
148
240
|
*/
|
|
149
|
-
declare const browserTool: (options?: BrowserToolOptions) => AgentToolDefinition<BrowserToolInput, string>;
|
|
241
|
+
declare const browserTool: (options?: BrowserToolOptions) => AgentToolDefinition<BrowserToolInput, BrowserRenderResult | string>;
|
|
150
242
|
/**
|
|
151
243
|
* A batteries-included agent tool that talks to a declared Cloudflare
|
|
152
|
-
* Container. `name` is the `ctx.containers
|
|
244
|
+
* Container. `name` is the `ctx.containers.<name>` key (the `lunora/containers.ts`
|
|
153
245
|
* export). One tool exposes `fetch` (HTTP request) and `exec` (run a command);
|
|
154
246
|
* the model picks via `op`. The call dispatches to the auto-registered
|
|
155
247
|
* `sandbox:invoke` action, which carries `ctx.containers`.
|
|
156
248
|
*
|
|
249
|
+
* Every call is addressed to ONE instance per thread (`ctx.containers.<name>
|
|
250
|
+
* .get(threadKey)`), not a random pool member, so a multi-step session shares a
|
|
251
|
+
* filesystem — size the container's `maxInstances` for the number of live
|
|
252
|
+
* threads. See `sandbox-budgets.ts` for the time budgets and the re-execution
|
|
253
|
+
* ceiling that remains.
|
|
254
|
+
*
|
|
157
255
|
* By default a read-only (GET/HEAD/OPTIONS, or method-omitted) `fetch` runs
|
|
158
256
|
* unattended while everything else is gated behind a human approval — an
|
|
159
|
-
* `exec`; a `fetch` whose path resolves to the privileged
|
|
257
|
+
* `exec`; a `fetch` whose path resolves to the privileged exec route (both
|
|
160
258
|
* reach the same command-execution path in the container, so gating on the
|
|
161
|
-
* `op` name alone would let a `fetch` to
|
|
259
|
+
* `op` name alone would let a `fetch` to it run a command unattended);
|
|
162
260
|
* and a `fetch` using a non-idempotent method (POST/PUT/PATCH/DELETE) to ANY
|
|
163
261
|
* route, since a prompt-injected model could otherwise mutate container state
|
|
164
|
-
* through some other privileged route just by avoiding the literal
|
|
262
|
+
* through some other privileged route just by avoiding the literal exec
|
|
165
263
|
* path. A `fetch` can still reach any *other read* route unattended, so scope
|
|
166
264
|
* the container's GET routes accordingly. Pass `opts.needsApproval` to widen
|
|
167
265
|
* or disable the gate.
|
|
@@ -201,4 +299,4 @@ declare const containerTool: (name: string, options?: ContainerToolOptions) => A
|
|
|
201
299
|
* @experimental
|
|
202
300
|
*/
|
|
203
301
|
declare const fsTool: (bucket: string, options?: FsToolOptions) => AgentToolDefinition<FsToolInput>;
|
|
204
|
-
export { type BrowserToolInput, type BrowserToolOptions, type ContainerToolInput, type ContainerToolOptions, type FsToolInput, type FsToolOptions, browserTool, containerTool, fsTool };
|
|
302
|
+
export { type BrowserRenderResult, type BrowserToolInput, type BrowserToolOptions, type ContainerToolInput, type ContainerToolOptions, type FsToolInput, type FsToolOptions, type JsCodeToolInput, type JsCodeToolOptions, type JsCodeToolResult, browserTool, containerTool, fsTool, jsCodeTool };
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as AgentToolDefinition, d as AgentToolContext } from "./packem_shared/types.d-CbYtFBw9.js";
|
|
2
2
|
import '@lunora/mail/inbound';
|
|
3
3
|
import 'ai';
|
|
4
|
+
/**
|
|
5
|
+
* The model-provided input to a {@link jsCodeTool} call.
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
interface JsCodeToolInput {
|
|
9
|
+
/** The body of an `async` function. Its `return` value is the result. */
|
|
10
|
+
code: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What a {@link jsCodeTool} call resolves to. `error` is set instead of `value`
|
|
14
|
+
* when the script threw, did not parse, returned something that is not JSON,
|
|
15
|
+
* or ran out of time.
|
|
16
|
+
* @experimental
|
|
17
|
+
*/
|
|
18
|
+
interface JsCodeToolResult {
|
|
19
|
+
error?: string;
|
|
20
|
+
/** `console.*` output, one entry per call, at most {@link MAX_LOG_ENTRIES}. */
|
|
21
|
+
logs: string[];
|
|
22
|
+
value?: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** Options for {@link jsCodeTool}. */
|
|
25
|
+
interface JsCodeToolOptions {
|
|
26
|
+
/** CPU budget per run, enforced by the loader. Default 1000 ms. */
|
|
27
|
+
cpuMs?: number;
|
|
28
|
+
/** Tool description shown to the model. */
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A batteries-included agent tool that runs model-written JavaScript in a
|
|
33
|
+
* Worker Loader isolate — Cloudflare's Dynamic Workers, which celld implements
|
|
34
|
+
* too. The script gets no network (`globalOutbound: null`), no bindings, no
|
|
35
|
+
* tools and a CPU budget, so it is for computation: arithmetic, parsing,
|
|
36
|
+
* reshaping data the model already has. It returns the script's JSON result
|
|
37
|
+
* and its `console` output. A failure comes back as a result with `error` set,
|
|
38
|
+
* not a throw, so the durable step does not retry a script that will fail the
|
|
39
|
+
* same way again.
|
|
40
|
+
*
|
|
41
|
+
* Importing the tool makes codegen provision the `worker_loaders` binding
|
|
42
|
+
* (`LOADER`) and refuse a target whose matrix rates `workerLoaders`
|
|
43
|
+
* `unsupported`.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { defineAgent, jsCodeTool } from "@lunora/agent";
|
|
47
|
+
*
|
|
48
|
+
* export const analyst = defineAgent({
|
|
49
|
+
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
50
|
+
* tools: { js: jsCodeTool() },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
* @experimental
|
|
54
|
+
*/
|
|
55
|
+
declare const jsCodeTool: (options?: JsCodeToolOptions) => AgentToolDefinition<JsCodeToolInput, JsCodeToolResult>;
|
|
56
|
+
/**
|
|
57
|
+
* What a byte-returning browser op resolves to. The render is written to R2 and
|
|
58
|
+
* its key comes back — never the bytes, which would be truncated to the model's
|
|
59
|
+
* output cap and billed for nothing.
|
|
60
|
+
* @experimental
|
|
61
|
+
*/
|
|
62
|
+
interface BrowserRenderResult {
|
|
63
|
+
/** Size of the stored object. */
|
|
64
|
+
bytes: number;
|
|
65
|
+
/** The absolute R2 key the render was written to. */
|
|
66
|
+
key: string;
|
|
67
|
+
/** The render's content type, e.g. `image/jpeg`. */
|
|
68
|
+
mediaType: string;
|
|
69
|
+
}
|
|
4
70
|
/**
|
|
5
71
|
* The model-provided input to a {@link browserTool} call — a discriminated
|
|
6
72
|
* union on `op` so one tool exposes every headless-browser capability.
|
|
@@ -25,8 +91,8 @@ type BrowserToolInput = {
|
|
|
25
91
|
/**
|
|
26
92
|
* The model-provided input to a {@link containerTool} call — a discriminated
|
|
27
93
|
* union on `op`. `fetch` sends an HTTP request to the container; `exec` asks it
|
|
28
|
-
* to run a command (
|
|
29
|
-
*
|
|
94
|
+
* to run a command (delegated to `ctx.containers.<name>.exec`, the first-class
|
|
95
|
+
* exec contract in `@lunora/container`; the container app serves its route).
|
|
30
96
|
* @experimental
|
|
31
97
|
*/
|
|
32
98
|
type ContainerToolInput = {
|
|
@@ -44,6 +110,17 @@ type ContainerToolInput = {
|
|
|
44
110
|
* @experimental
|
|
45
111
|
*/
|
|
46
112
|
interface BrowserToolOptions {
|
|
113
|
+
/**
|
|
114
|
+
* R2 binding name the byte-returning ops (`screenshot`, `pdf`) write their
|
|
115
|
+
* render to. REQUIRED for those two: a render is billed, and a tool result
|
|
116
|
+
* is capped at `MAX_TOOL_OUTPUT_CHARS`, so base64 bytes inline would be
|
|
117
|
+
* truncated mid-string and unusable by the model — paid for and thrown
|
|
118
|
+
* away. With a bucket the op returns `{ bytes, key, mediaType }` and the
|
|
119
|
+
* app serves or post-processes the object by key. `content`/`scrape`
|
|
120
|
+
* return text and need no bucket; without one, a `screenshot`/`pdf` call is
|
|
121
|
+
* refused as a tool result (never dispatched) so nothing is billed.
|
|
122
|
+
*/
|
|
123
|
+
bucket?: string;
|
|
47
124
|
/** Override the model-facing description (what the tool does). */
|
|
48
125
|
description?: string;
|
|
49
126
|
/**
|
|
@@ -55,6 +132,14 @@ interface BrowserToolOptions {
|
|
|
55
132
|
* keep it deterministic).
|
|
56
133
|
*/
|
|
57
134
|
needsApproval?: ((input: BrowserToolInput) => boolean) | boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Key prefix inside {@link BrowserToolOptions.bucket} that renders are
|
|
137
|
+
* written under, isolating them from the rest of the bucket. Default: the
|
|
138
|
+
* bucket root. Each render lands at `<root>/<threadKey>/<toolCallId>.<ext>`
|
|
139
|
+
* — derived only from replay-stable identifiers, so a retried step
|
|
140
|
+
* overwrites its own object rather than accumulating one per attempt.
|
|
141
|
+
*/
|
|
142
|
+
root?: string;
|
|
58
143
|
}
|
|
59
144
|
/**
|
|
60
145
|
* The model-provided input to a {@link fsTool} call — a discriminated union on
|
|
@@ -112,12 +197,13 @@ interface ContainerToolOptions {
|
|
|
112
197
|
description?: string;
|
|
113
198
|
/**
|
|
114
199
|
* Gate a call behind a human approval. Defaults to gating any command
|
|
115
|
-
* execution
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* Pass a boolean or your own
|
|
120
|
-
* replay-stable input, so keep it
|
|
200
|
+
* execution — an `exec` — plus any `fetch` using a non-idempotent method
|
|
201
|
+
* (POST/PUT/PATCH/DELETE), so a prompt-injected model cannot reach some
|
|
202
|
+
* other mutating route unattended. A read-only `fetch` runs unattended. The
|
|
203
|
+
* exec route itself needs no special case: `@lunora/container` reserves
|
|
204
|
+
* `/__lunora/*` and refuses a `fetch` into it. Pass a boolean or your own
|
|
205
|
+
* predicate to change that. Evaluated from replay-stable input, so keep it
|
|
206
|
+
* deterministic.
|
|
121
207
|
*/
|
|
122
208
|
needsApproval?: ((input: ContainerToolInput) => boolean) | boolean;
|
|
123
209
|
}
|
|
@@ -132,6 +218,12 @@ interface ContainerToolOptions {
|
|
|
132
218
|
* `@cloudflare/playwright` `launch` peer) to `createShardDO()` — codegen never
|
|
133
219
|
* injects that peer, so the browser op throws a directed error until it is wired.
|
|
134
220
|
*
|
|
221
|
+
* `content`/`scrape` return text. `screenshot`/`pdf` write the render to
|
|
222
|
+
* `opts.bucket` and return `{ bytes, key, mediaType }` — never the bytes
|
|
223
|
+
* themselves, which a 4000-char tool-output cap would truncate into something
|
|
224
|
+
* unusable after paying for the render. Without a bucket those two ops are
|
|
225
|
+
* refused as a tool result and never dispatched.
|
|
226
|
+
*
|
|
135
227
|
* Security: the model chooses the `url` with no allowlist, so this is an SSRF
|
|
136
228
|
* surface — pass `opts.needsApproval` to gate calls a prompt-injected model
|
|
137
229
|
* could aim at internal/link-local endpoints.
|
|
@@ -141,27 +233,33 @@ interface ContainerToolOptions {
|
|
|
141
233
|
*
|
|
142
234
|
* export const researcher = defineAgent({
|
|
143
235
|
* model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
|
|
144
|
-
* tools: { browser: browserTool() },
|
|
236
|
+
* tools: { browser: browserTool({ bucket: "SANDBOX_BUCKET", root: "renders" }) },
|
|
145
237
|
* });
|
|
146
238
|
* ```
|
|
147
239
|
* @experimental
|
|
148
240
|
*/
|
|
149
|
-
declare const browserTool: (options?: BrowserToolOptions) => AgentToolDefinition<BrowserToolInput, string>;
|
|
241
|
+
declare const browserTool: (options?: BrowserToolOptions) => AgentToolDefinition<BrowserToolInput, BrowserRenderResult | string>;
|
|
150
242
|
/**
|
|
151
243
|
* A batteries-included agent tool that talks to a declared Cloudflare
|
|
152
|
-
* Container. `name` is the `ctx.containers
|
|
244
|
+
* Container. `name` is the `ctx.containers.<name>` key (the `lunora/containers.ts`
|
|
153
245
|
* export). One tool exposes `fetch` (HTTP request) and `exec` (run a command);
|
|
154
246
|
* the model picks via `op`. The call dispatches to the auto-registered
|
|
155
247
|
* `sandbox:invoke` action, which carries `ctx.containers`.
|
|
156
248
|
*
|
|
249
|
+
* Every call is addressed to ONE instance per thread (`ctx.containers.<name>
|
|
250
|
+
* .get(threadKey)`), not a random pool member, so a multi-step session shares a
|
|
251
|
+
* filesystem — size the container's `maxInstances` for the number of live
|
|
252
|
+
* threads. See `sandbox-budgets.ts` for the time budgets and the re-execution
|
|
253
|
+
* ceiling that remains.
|
|
254
|
+
*
|
|
157
255
|
* By default a read-only (GET/HEAD/OPTIONS, or method-omitted) `fetch` runs
|
|
158
256
|
* unattended while everything else is gated behind a human approval — an
|
|
159
|
-
* `exec`; a `fetch` whose path resolves to the privileged
|
|
257
|
+
* `exec`; a `fetch` whose path resolves to the privileged exec route (both
|
|
160
258
|
* reach the same command-execution path in the container, so gating on the
|
|
161
|
-
* `op` name alone would let a `fetch` to
|
|
259
|
+
* `op` name alone would let a `fetch` to it run a command unattended);
|
|
162
260
|
* and a `fetch` using a non-idempotent method (POST/PUT/PATCH/DELETE) to ANY
|
|
163
261
|
* route, since a prompt-injected model could otherwise mutate container state
|
|
164
|
-
* through some other privileged route just by avoiding the literal
|
|
262
|
+
* through some other privileged route just by avoiding the literal exec
|
|
165
263
|
* path. A `fetch` can still reach any *other read* route unattended, so scope
|
|
166
264
|
* the container's GET routes accordingly. Pass `opts.needsApproval` to widen
|
|
167
265
|
* or disable the gate.
|
|
@@ -201,4 +299,4 @@ declare const containerTool: (name: string, options?: ContainerToolOptions) => A
|
|
|
201
299
|
* @experimental
|
|
202
300
|
*/
|
|
203
301
|
declare const fsTool: (bucket: string, options?: FsToolOptions) => AgentToolDefinition<FsToolInput>;
|
|
204
|
-
export { type BrowserToolInput, type BrowserToolOptions, type ContainerToolInput, type ContainerToolOptions, type FsToolInput, type FsToolOptions, browserTool, containerTool, fsTool };
|
|
302
|
+
export { type BrowserRenderResult, type BrowserToolInput, type BrowserToolOptions, type ContainerToolInput, type ContainerToolOptions, type FsToolInput, type FsToolOptions, type JsCodeToolInput, type JsCodeToolOptions, type JsCodeToolResult, browserTool, containerTool, fsTool, jsCodeTool };
|
package/dist/sandbox.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as
|
|
1
|
+
import{LunoraError as a}from"@lunora/errors";import{jsonSchema as s}from"ai";import{toFunctionReference as h,SANDBOX_INVOKE_PATH as u}from"./packem_shared/AGENT_MODULE-M4D1EejI.mjs";import{S as l,a as T}from"./packem_shared/sandbox-budgets-DDvj4Orr.mjs";import{jsCodeTool as k}from"./packem_shared/jsCodeTool-BLOvjXGF.mjs";const i=h(u),f=e=>{if(e.op==="pdf")return"pdf";if(e.op==="screenshot")return e.type==="jpeg"?"jpeg":"png"},m=new Set(["bucket","path","root"]),g='Drive a headless browser: screenshot a page, render it to PDF, read its HTML content, or scrape it. Set `op` to "screenshot" | "pdf" | "content" | "scrape" and pass the target `url`.',E='Talk to a sandboxed container: `fetch` an HTTP path on it, or `exec` a command inside it. Set `op` to "fetch" (with `path`) or "exec" (with `command`).',y='Read and write files in a persistent sandbox filesystem. Set `op` to "ls" (list a directory), "read", "write" (with `content`), "rm", or "stat", and pass `path`.',S=e=>e.op==="write"||e.op==="rm",A=s({properties:{content:{description:"write: the file contents.",type:"string"},op:{description:"The filesystem operation to run.",enum:["ls","read","write","rm","stat"],type:"string"},path:{description:"The file or directory path, relative to the sandbox root.",type:"string"}},required:["op"],type:"object"}),O=s({properties:{fullPage:{description:"screenshot: capture the full scrollable page rather than just the viewport.",type:"boolean"},op:{description:"The browser operation to run.",enum:["screenshot","scrape","pdf","content"],type:"string"},selector:{description:"scrape: optional CSS selector hint to narrow the extraction.",type:"string"},type:{description:"screenshot: image encoding (default png).",enum:["png","jpeg"],type:"string"},url:{description:"The URL to operate on.",type:"string"}},required:["op","url"],type:"object"}),_=new Set(["DELETE","PATCH","POST","PUT"]),b=e=>e.op==="exec"||_.has((e.method??"GET").toUpperCase()),w=s({properties:{args:{description:"exec: command arguments.",items:{type:"string"},type:"array"},body:{description:"fetch: request body.",type:"string"},command:{description:"exec: the command to run.",type:"string"},method:{description:"fetch: HTTP method (default GET).",type:"string"},op:{description:"The container operation to run.",enum:["fetch","exec"],type:"string"},path:{description:"fetch: request path on the container (e.g. /health).",type:"string"}},required:["op"],type:"object"}),v=(e={})=>{const t=e.bucket!==void 0&&e.bucket.length>0?e.bucket:void 0;return{description:e.description??g,execute:async(n,o)=>{const r=f(n);if(r!==void 0&&t===void 0)return`Cannot run a "${n.op}": this browser tool has no \`bucket\` configured, so the render has nowhere to go. Use "content" or "scrape" for page text, or ask the operator to pass \`browserTool({ bucket })\`.`;const c=r===void 0?{}:{bucket:t,path:`${o.threadKey}/${o.toolCallId}.${r}`,...e.root===void 0?{}:{root:e.root}},p=Object.fromEntries(Object.entries(n).filter(([d])=>!m.has(d)));return await o.run(i,{...p,...c,kind:"browser"},{timeoutMs:l})},inputSchema:O,isLunoraAgentTool:!0,...e.needsApproval===void 0?{}:{needsApproval:e.needsApproval}}},C=(e,t={})=>{if(typeof e!="string"||e.length===0)throw new a("INTERNAL","@lunora/agent: containerTool requires a container `name` (the ctx.containers.<name> key from lunora/containers.ts)");const n=t.needsApproval??b;return{description:t.description??E,execute:(o,r)=>r.run(i,{...o,instance:r.threadKey,kind:"container",name:e},{timeoutMs:T}),inputSchema:w,isLunoraAgentTool:!0,needsApproval:n}},x=(e,t={})=>{if(typeof e!="string"||e.length===0)throw new a("INTERNAL","@lunora/agent: fsTool requires an R2 `bucket` binding name (the r2_bucket declared in wrangler.jsonc)");return{description:t.description??y,execute:(n,o)=>{const r=typeof t.root=="function"?t.root(o):t.root??"";return o.run(i,{...n,bucket:e,kind:"fs",root:r})},inputSchema:A,isLunoraAgentTool:!0,needsApproval:t.needsApproval??S}};export{v as browserTool,C as containerTool,x as fsTool,k as jsCodeTool};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { S as SkillMarkdownExtras, b as SkillDefinition } from "./packem_shared/types.d-CbYtFBw9.mjs";
|
|
2
|
+
import '@lunora/mail/inbound';
|
|
3
|
+
import 'ai';
|
|
4
|
+
/**
|
|
5
|
+
* Declare a skill whose prose lives in a markdown file.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import triage from "./skills/triage/SKILL.md?raw";
|
|
9
|
+
* import { functionTool } from "@lunora/agent";
|
|
10
|
+
* import { skillFromMarkdown } from "@lunora/agent/skill-markdown";
|
|
11
|
+
*
|
|
12
|
+
* export const triageSkill = skillFromMarkdown(triage, {
|
|
13
|
+
* tools: { searchCode: functionTool(api.code.search, { ... }) },
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* ```md
|
|
18
|
+
* ---
|
|
19
|
+
* name: triage
|
|
20
|
+
* ---
|
|
21
|
+
* Reproduce the report before proposing a cause. Cite the failing test.
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The split is the point: the instructions are the part a non-author reads,
|
|
25
|
+
* reviews and copies between projects, so they belong in a file that is legible
|
|
26
|
+
* on its own — and the `name` travels WITH that file, so a skill can move
|
|
27
|
+
* without a matching TypeScript wrapper. Tools and `knowledge` stay in code,
|
|
28
|
+
* because they are code.
|
|
29
|
+
*
|
|
30
|
+
* Getting the markdown here is the caller's job (`?raw` under Vite, a build-time
|
|
31
|
+
* import elsewhere) — a Worker has no filesystem to read it from at runtime, so
|
|
32
|
+
* this takes the string rather than a path.
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
35
|
+
declare const skillFromMarkdown: (markdown: string, extras?: SkillMarkdownExtras) => SkillDefinition;
|
|
36
|
+
export { type SkillMarkdownExtras, skillFromMarkdown };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { S as SkillMarkdownExtras, b as SkillDefinition } from "./packem_shared/types.d-CbYtFBw9.js";
|
|
2
|
+
import '@lunora/mail/inbound';
|
|
3
|
+
import 'ai';
|
|
4
|
+
/**
|
|
5
|
+
* Declare a skill whose prose lives in a markdown file.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import triage from "./skills/triage/SKILL.md?raw";
|
|
9
|
+
* import { functionTool } from "@lunora/agent";
|
|
10
|
+
* import { skillFromMarkdown } from "@lunora/agent/skill-markdown";
|
|
11
|
+
*
|
|
12
|
+
* export const triageSkill = skillFromMarkdown(triage, {
|
|
13
|
+
* tools: { searchCode: functionTool(api.code.search, { ... }) },
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* ```md
|
|
18
|
+
* ---
|
|
19
|
+
* name: triage
|
|
20
|
+
* ---
|
|
21
|
+
* Reproduce the report before proposing a cause. Cite the failing test.
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The split is the point: the instructions are the part a non-author reads,
|
|
25
|
+
* reviews and copies between projects, so they belong in a file that is legible
|
|
26
|
+
* on its own — and the `name` travels WITH that file, so a skill can move
|
|
27
|
+
* without a matching TypeScript wrapper. Tools and `knowledge` stay in code,
|
|
28
|
+
* because they are code.
|
|
29
|
+
*
|
|
30
|
+
* Getting the markdown here is the caller's job (`?raw` under Vite, a build-time
|
|
31
|
+
* import elsewhere) — a Worker has no filesystem to read it from at runtime, so
|
|
32
|
+
* this takes the string rather than a path.
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
35
|
+
declare const skillFromMarkdown: (markdown: string, extras?: SkillMarkdownExtras) => SkillDefinition;
|
|
36
|
+
export { type SkillMarkdownExtras, skillFromMarkdown };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as o}from"@lunora/errors";import{parse as s}from"yaml";import{defineSkill as l}from"./packem_shared/defineSkill-DGGvDWNq.mjs";const m=/^\uFEFF?[ \t]*---[ \t]*\r?\n/u,h=/^---[ \t]*$/mu,c=t=>{const r=m.exec(t);if(!r)return{body:t.trim(),data:{}};const n=t.slice(r[0].length),e=h.exec(n);if(!e)throw new o("INTERNAL","@lunora/agent: the skill markdown opens with `---` but never closes the frontmatter block. Add a closing `---` on its own line.");let a;try{a=s(n.slice(0,e.index))}catch(i){throw new o("INTERNAL",`@lunora/agent: the skill markdown has invalid YAML frontmatter — ${i instanceof Error?i.message:String(i)}`)}return{body:n.slice(e.index+e[0].length).trim(),data:typeof a=="object"&&a!==null?a:{}}},w=(t,r={})=>{if(typeof t!="string")throw new o("INTERNAL",`@lunora/agent: skillFromMarkdown expects the markdown SOURCE as a string, got ${typeof t}`);const{body:n,data:e}=c(t);if(e.name!==void 0&&typeof e.name!="string")throw new o("INTERNAL",`@lunora/agent: the skill markdown's \`name\` must be a string, got ${Array.isArray(e.name)?"array":typeof e.name}. Quote it if the value looks like a number or a boolean (\`name: "2fa"\`).`);if(typeof e.name!="string")throw new o("INTERNAL","@lunora/agent: skillFromMarkdown found no `name` in the markdown frontmatter. Open the file with a `---` line, put `name: <identifier>` on its own line, and close it with `---`. Other keys are parsed and ignored — only `name` is read here.");if(n==="")throw new o("INTERNAL",`@lunora/agent: the skill markdown for "${e.name}" has no body — the instructions below the closing \`---\` are what the skill contributes.`);return l({...r,instructions:n,name:e.name})};export{w as skillFromMarkdown};
|