@cloudflare/codemode 0.3.4 → 0.3.6
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 +21 -2
- package/dist/ai.d.ts +4 -4
- package/dist/ai.js +9 -17
- package/dist/ai.js.map +1 -1
- package/dist/browser.d.ts +142 -0
- package/dist/browser.js +509 -0
- package/dist/browser.js.map +1 -0
- package/dist/{executor-wZjYdqEX.d.ts → executor-BWtTiHBV.d.ts} +37 -36
- package/dist/index.d.ts +13 -37
- package/dist/index.js +120 -13
- package/dist/index.js.map +1 -1
- package/dist/json-schema-types-1OL3uao0.d.ts +38 -0
- package/dist/{json-schema-types-DoQ0VISs.js → json-schema-types-CVt4X9cw.js} +43 -2
- package/dist/json-schema-types-CVt4X9cw.js.map +1 -0
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +72 -39
- package/dist/mcp.js.map +1 -1
- package/dist/{resolve-DULSpsq2.d.ts → resolve-9VUW-grI.d.ts} +4 -4
- package/dist/resolve-BU1FGVYs.js +44 -0
- package/dist/resolve-BU1FGVYs.js.map +1 -0
- package/dist/run-code-5x8S5YWt.js +17 -0
- package/dist/run-code-5x8S5YWt.js.map +1 -0
- package/dist/{shared-Hnh_Idta.d.ts → shared-CcZcDoiO.d.ts} +5 -6
- package/dist/{shared-ra3HW2ti.js → shared-xjl2irqK.js} +1 -1
- package/dist/{shared-ra3HW2ti.js.map → shared-xjl2irqK.js.map} +1 -1
- package/dist/tanstack-ai.d.ts +3 -3
- package/dist/tanstack-ai.js +10 -18
- package/dist/tanstack-ai.js.map +1 -1
- package/package.json +14 -8
- package/dist/json-schema-types-DoQ0VISs.js.map +0 -1
- package/dist/resolve-DIQRkRqQ.js +0 -85
- package/dist/resolve-DIQRkRqQ.js.map +0 -1
package/dist/browser.js
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import { a as sanitizeToolName, s as normalizeCode, t as generateTypesFromJsonSchema } from "./json-schema-types-CVt4X9cw.js";
|
|
2
|
+
import { t as runCode } from "./run-code-5x8S5YWt.js";
|
|
3
|
+
//#region src/messages.ts
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === "object" && value !== null;
|
|
6
|
+
}
|
|
7
|
+
function isSandboxReadyMessage(data) {
|
|
8
|
+
return isRecord(data) && data.type === "sandbox-ready";
|
|
9
|
+
}
|
|
10
|
+
function isToolCallMessage(data) {
|
|
11
|
+
return isRecord(data) && data.type === "tool-call" && typeof data.nonce === "string" && typeof data.id === "number" && typeof data.provider === "string" && typeof data.name === "string";
|
|
12
|
+
}
|
|
13
|
+
function isExecutionResultMessage(data) {
|
|
14
|
+
if (!isRecord(data)) return false;
|
|
15
|
+
if (data.type !== "execution-result") return false;
|
|
16
|
+
if (typeof data.nonce !== "string") return false;
|
|
17
|
+
if (typeof data.result !== "object" || data.result === null) return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/iframe-runtime.ts
|
|
22
|
+
/**
|
|
23
|
+
* Self-contained runtime that boots inside the sandboxed iframe.
|
|
24
|
+
*
|
|
25
|
+
* The `iframeSandboxRuntimeMain` function is serialized via `.toString()`
|
|
26
|
+
* and injected into the iframe's `srcdoc`. It MUST be fully self-contained —
|
|
27
|
+
* no closures over module-level variables, no imported values at runtime.
|
|
28
|
+
* (Type-only imports are safe because they are erased at compile time.)
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* The iframe-side runtime entry point.
|
|
32
|
+
*
|
|
33
|
+
* This function is stringified and injected into the iframe via srcdoc.
|
|
34
|
+
* Everything it needs must be defined inside its own scope.
|
|
35
|
+
*/
|
|
36
|
+
function iframeSandboxRuntimeMain() {
|
|
37
|
+
const runtimeWindow = window;
|
|
38
|
+
if (runtimeWindow.__codemodeIframeInitialized) return;
|
|
39
|
+
runtimeWindow.__codemodeIframeInitialized = true;
|
|
40
|
+
const logs = [];
|
|
41
|
+
const pending = {};
|
|
42
|
+
let nextId = 0;
|
|
43
|
+
let activeNonce;
|
|
44
|
+
function post(message) {
|
|
45
|
+
parent.postMessage(message, "*");
|
|
46
|
+
}
|
|
47
|
+
console.log = (...args) => {
|
|
48
|
+
const values = [];
|
|
49
|
+
for (let i = 0; i < args.length; i++) values.push(String(args[i]));
|
|
50
|
+
logs.push(values.join(" "));
|
|
51
|
+
};
|
|
52
|
+
console.warn = (...args) => {
|
|
53
|
+
const values = [];
|
|
54
|
+
for (let i = 0; i < args.length; i++) values.push(String(args[i]));
|
|
55
|
+
logs.push("[warn] " + values.join(" "));
|
|
56
|
+
};
|
|
57
|
+
console.error = (...args) => {
|
|
58
|
+
const values = [];
|
|
59
|
+
for (let i = 0; i < args.length; i++) values.push(String(args[i]));
|
|
60
|
+
logs.push("[error] " + values.join(" "));
|
|
61
|
+
};
|
|
62
|
+
function createProviderProxy(nonce, provider) {
|
|
63
|
+
return new Proxy({}, { get: (_, toolName) => {
|
|
64
|
+
if (provider.positionalArgs) return (...args) => {
|
|
65
|
+
const id = nextId++;
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
pending[id] = {
|
|
68
|
+
resolve,
|
|
69
|
+
reject
|
|
70
|
+
};
|
|
71
|
+
post({
|
|
72
|
+
type: "tool-call",
|
|
73
|
+
nonce,
|
|
74
|
+
id,
|
|
75
|
+
provider: provider.name,
|
|
76
|
+
name: String(toolName),
|
|
77
|
+
args
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
return (args) => {
|
|
82
|
+
const id = nextId++;
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
pending[id] = {
|
|
85
|
+
resolve,
|
|
86
|
+
reject
|
|
87
|
+
};
|
|
88
|
+
post({
|
|
89
|
+
type: "tool-call",
|
|
90
|
+
nonce,
|
|
91
|
+
id,
|
|
92
|
+
provider: provider.name,
|
|
93
|
+
name: String(toolName),
|
|
94
|
+
args: args ?? {}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
} });
|
|
99
|
+
}
|
|
100
|
+
function isToolResultMessage(message) {
|
|
101
|
+
if (typeof message !== "object" || message === null) return false;
|
|
102
|
+
const candidate = message;
|
|
103
|
+
return candidate.type === "tool-result" && typeof candidate.nonce === "string" && typeof candidate.id === "number";
|
|
104
|
+
}
|
|
105
|
+
function isExecuteRequestMessage(message) {
|
|
106
|
+
if (typeof message !== "object" || message === null) return false;
|
|
107
|
+
const candidate = message;
|
|
108
|
+
return candidate.type === "execute-request" && typeof candidate.nonce === "string" && typeof candidate.code === "string" && Array.isArray(candidate.providers) && candidate.providers.every((provider) => typeof provider === "object" && provider !== null && typeof provider.name === "string" && (provider.positionalArgs === void 0 || typeof provider.positionalArgs === "boolean"));
|
|
109
|
+
}
|
|
110
|
+
function executeCode(nonce, code, providers) {
|
|
111
|
+
try {
|
|
112
|
+
activeNonce = nonce;
|
|
113
|
+
const providerNames = [];
|
|
114
|
+
const providerProxies = [];
|
|
115
|
+
for (const provider of providers) {
|
|
116
|
+
providerNames.push(provider.name);
|
|
117
|
+
providerProxies.push(createProviderProxy(nonce, provider));
|
|
118
|
+
}
|
|
119
|
+
const fn = new Function(...providerNames, "return (" + code + ")")(...providerProxies);
|
|
120
|
+
Promise.resolve(fn()).then((result) => {
|
|
121
|
+
post({
|
|
122
|
+
type: "execution-result",
|
|
123
|
+
nonce,
|
|
124
|
+
result: {
|
|
125
|
+
result,
|
|
126
|
+
logs
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}).catch((err) => {
|
|
130
|
+
post({
|
|
131
|
+
type: "execution-result",
|
|
132
|
+
nonce,
|
|
133
|
+
result: {
|
|
134
|
+
result: void 0,
|
|
135
|
+
error: err.message || String(err),
|
|
136
|
+
logs
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
} catch (err) {
|
|
141
|
+
post({
|
|
142
|
+
type: "execution-result",
|
|
143
|
+
nonce,
|
|
144
|
+
result: {
|
|
145
|
+
result: void 0,
|
|
146
|
+
error: err instanceof Error ? err.message : String(err),
|
|
147
|
+
logs
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
window.addEventListener("message", (event) => {
|
|
153
|
+
if (event.source !== parent) return;
|
|
154
|
+
const message = event.data;
|
|
155
|
+
if (isToolResultMessage(message)) {
|
|
156
|
+
if (message.nonce !== activeNonce) return;
|
|
157
|
+
const request = pending[message.id];
|
|
158
|
+
if (!request) return;
|
|
159
|
+
delete pending[message.id];
|
|
160
|
+
if ("error" in message) request.reject(new Error(message.error));
|
|
161
|
+
else request.resolve(message.result);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (isExecuteRequestMessage(message)) executeCode(message.nonce, message.code, message.providers);
|
|
165
|
+
});
|
|
166
|
+
post({ type: "sandbox-ready" });
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Returns a self-contained script string that boots the codemode iframe runtime.
|
|
170
|
+
*/
|
|
171
|
+
function createIframeSandboxRuntimeScript() {
|
|
172
|
+
return `;(${iframeSandboxRuntimeMain.toString()})();`;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/iframe-executor.ts
|
|
176
|
+
/**
|
|
177
|
+
* IframeSandboxExecutor — a browser-native Executor that runs LLM-generated
|
|
178
|
+
* code in a sandboxed iframe using postMessage for tool dispatch.
|
|
179
|
+
*
|
|
180
|
+
* Zero dependencies — uses only browser APIs (iframe, postMessage, CSP).
|
|
181
|
+
*/
|
|
182
|
+
const DEFAULT_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval';";
|
|
183
|
+
const DEFAULT_TIMEOUT = 3e4;
|
|
184
|
+
function escapeHtmlAttribute(value) {
|
|
185
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
186
|
+
}
|
|
187
|
+
function escapeInlineScript(value) {
|
|
188
|
+
return value.replace(/<\/script/gi, "<\\/script");
|
|
189
|
+
}
|
|
190
|
+
function buildSrcdoc(csp) {
|
|
191
|
+
const runtimeScript = escapeInlineScript(createIframeSandboxRuntimeScript());
|
|
192
|
+
return `<!DOCTYPE html>
|
|
193
|
+
<html>
|
|
194
|
+
<head>
|
|
195
|
+
<meta http-equiv="Content-Security-Policy" content="${escapeHtmlAttribute(csp)}">
|
|
196
|
+
</head>
|
|
197
|
+
<body>
|
|
198
|
+
<script>
|
|
199
|
+
${runtimeScript}
|
|
200
|
+
<\/script>
|
|
201
|
+
</body>
|
|
202
|
+
</html>`;
|
|
203
|
+
}
|
|
204
|
+
function createToolResultMessage(nonce, id, value, isError) {
|
|
205
|
+
if (isError) return {
|
|
206
|
+
type: "tool-result",
|
|
207
|
+
nonce,
|
|
208
|
+
id,
|
|
209
|
+
error: value instanceof Error ? value.message : String(value)
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
type: "tool-result",
|
|
213
|
+
nonce,
|
|
214
|
+
id,
|
|
215
|
+
result: value
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function createExecutionNonce() {
|
|
219
|
+
if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
|
|
220
|
+
const bytes = new Uint8Array(16);
|
|
221
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
222
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Executes LLM-generated code in a browser iframe sandbox.
|
|
226
|
+
*
|
|
227
|
+
* For each execution, a hidden iframe is created with `sandbox="allow-scripts"`,
|
|
228
|
+
* the runtime is injected via `srcdoc`, and the iframe is removed after completion.
|
|
229
|
+
* Tool calls are dispatched via `postMessage`.
|
|
230
|
+
*/
|
|
231
|
+
var IframeSandboxExecutor = class {
|
|
232
|
+
#timeout;
|
|
233
|
+
#csp;
|
|
234
|
+
constructor(options) {
|
|
235
|
+
this.#timeout = options?.timeout ?? DEFAULT_TIMEOUT;
|
|
236
|
+
this.#csp = options?.csp ?? DEFAULT_CSP;
|
|
237
|
+
}
|
|
238
|
+
async execute(code, providersOrFns) {
|
|
239
|
+
let providers;
|
|
240
|
+
if (!Array.isArray(providersOrFns)) {
|
|
241
|
+
console.warn("[@cloudflare/codemode] Passing raw fns to executor.execute() is deprecated. Use ResolvedProvider[] instead. This will be removed in the next major version.");
|
|
242
|
+
providers = [{
|
|
243
|
+
name: "codemode",
|
|
244
|
+
fns: providersOrFns
|
|
245
|
+
}];
|
|
246
|
+
} else providers = providersOrFns;
|
|
247
|
+
const reservedNames = new Set(["__dispatchers", "__logs"]);
|
|
248
|
+
const validIdent = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
249
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
250
|
+
for (const provider of providers) {
|
|
251
|
+
if (reservedNames.has(provider.name)) return {
|
|
252
|
+
result: void 0,
|
|
253
|
+
error: `Provider name "${provider.name}" is reserved`
|
|
254
|
+
};
|
|
255
|
+
if (!validIdent.test(provider.name)) return {
|
|
256
|
+
result: void 0,
|
|
257
|
+
error: `Provider name "${provider.name}" is not a valid JavaScript identifier`
|
|
258
|
+
};
|
|
259
|
+
if (seenNames.has(provider.name)) return {
|
|
260
|
+
result: void 0,
|
|
261
|
+
error: `Duplicate provider name "${provider.name}"`
|
|
262
|
+
};
|
|
263
|
+
seenNames.add(provider.name);
|
|
264
|
+
}
|
|
265
|
+
const normalizedCode = normalizeCode(code);
|
|
266
|
+
const resolvedProviders = [];
|
|
267
|
+
for (const provider of providers) {
|
|
268
|
+
const sanitizedFns = {};
|
|
269
|
+
const sanitizedNames = /* @__PURE__ */ new Map();
|
|
270
|
+
for (const [name, fn] of Object.entries(provider.fns)) {
|
|
271
|
+
const sanitizedName = sanitizeToolName(name);
|
|
272
|
+
const existingName = sanitizedNames.get(sanitizedName);
|
|
273
|
+
if (existingName && existingName !== name) return {
|
|
274
|
+
result: void 0,
|
|
275
|
+
error: `Tool names "${existingName}" and "${name}" both sanitize to "${sanitizedName}" in provider "${provider.name}"`
|
|
276
|
+
};
|
|
277
|
+
sanitizedNames.set(sanitizedName, name);
|
|
278
|
+
sanitizedFns[sanitizedName] = fn;
|
|
279
|
+
}
|
|
280
|
+
const resolved = {
|
|
281
|
+
name: provider.name,
|
|
282
|
+
fns: sanitizedFns
|
|
283
|
+
};
|
|
284
|
+
if (provider.positionalArgs) resolved.positionalArgs = true;
|
|
285
|
+
resolvedProviders.push(resolved);
|
|
286
|
+
}
|
|
287
|
+
const providerMap = new Map(resolvedProviders.map((provider) => [provider.name, provider]));
|
|
288
|
+
const nonce = createExecutionNonce();
|
|
289
|
+
const executeRequest = {
|
|
290
|
+
type: "execute-request",
|
|
291
|
+
nonce,
|
|
292
|
+
code: normalizedCode,
|
|
293
|
+
providers: resolvedProviders.map((provider) => {
|
|
294
|
+
if (provider.positionalArgs) return {
|
|
295
|
+
name: provider.name,
|
|
296
|
+
positionalArgs: true
|
|
297
|
+
};
|
|
298
|
+
return { name: provider.name };
|
|
299
|
+
})
|
|
300
|
+
};
|
|
301
|
+
const invokeProviderTool = async (provider, args, name) => {
|
|
302
|
+
const fn = provider.fns[name];
|
|
303
|
+
if (!fn) throw new Error(`Tool "${name}" not found`);
|
|
304
|
+
if (!provider.positionalArgs) return fn(args);
|
|
305
|
+
return fn(...Array.isArray(args) ? args : [args]);
|
|
306
|
+
};
|
|
307
|
+
const iframe = document.createElement("iframe");
|
|
308
|
+
iframe.sandbox.add("allow-scripts");
|
|
309
|
+
iframe.style.display = "none";
|
|
310
|
+
iframe.style.width = "0";
|
|
311
|
+
iframe.style.height = "0";
|
|
312
|
+
iframe.style.border = "none";
|
|
313
|
+
iframe.srcdoc = buildSrcdoc(this.#csp);
|
|
314
|
+
return new Promise((resolve) => {
|
|
315
|
+
let settled = false;
|
|
316
|
+
let ready = false;
|
|
317
|
+
const warnedInvalidNonceTypes = /* @__PURE__ */ new Set();
|
|
318
|
+
const cleanup = () => {
|
|
319
|
+
if (settled) return;
|
|
320
|
+
settled = true;
|
|
321
|
+
clearTimeout(timer);
|
|
322
|
+
window.removeEventListener("message", handler);
|
|
323
|
+
iframe.removeEventListener("error", handleLoadError);
|
|
324
|
+
iframe.remove();
|
|
325
|
+
};
|
|
326
|
+
const resolveError = (message) => {
|
|
327
|
+
cleanup();
|
|
328
|
+
resolve({
|
|
329
|
+
result: void 0,
|
|
330
|
+
error: message,
|
|
331
|
+
logs: []
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
const postToChild = (message) => {
|
|
335
|
+
const child = iframe.contentWindow;
|
|
336
|
+
if (!child) {
|
|
337
|
+
resolveError("Sandbox iframe is not available");
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
child.postMessage(message, "*");
|
|
342
|
+
return true;
|
|
343
|
+
} catch (err) {
|
|
344
|
+
resolveError(err instanceof Error ? err.message : String(err));
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const warnInvalidNonce = (messageType) => {
|
|
349
|
+
if (warnedInvalidNonceTypes.has(messageType)) return;
|
|
350
|
+
warnedInvalidNonceTypes.add(messageType);
|
|
351
|
+
console.warn(`[@cloudflare/codemode] Ignoring sandbox ${messageType} message with invalid execution nonce`);
|
|
352
|
+
};
|
|
353
|
+
const handler = async (event) => {
|
|
354
|
+
if (event.source !== iframe.contentWindow) return;
|
|
355
|
+
const data = event.data;
|
|
356
|
+
if (isSandboxReadyMessage(data)) {
|
|
357
|
+
if (ready) return;
|
|
358
|
+
ready = true;
|
|
359
|
+
postToChild(executeRequest);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (isToolCallMessage(data)) {
|
|
363
|
+
if (data.nonce !== nonce) {
|
|
364
|
+
warnInvalidNonce("tool-call");
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const provider = providerMap.get(data.provider);
|
|
368
|
+
if (!provider) {
|
|
369
|
+
postToChild(createToolResultMessage(nonce, data.id, `Provider "${data.provider}" not found`, true));
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
const result = await invokeProviderTool(provider, data.args, data.name);
|
|
374
|
+
postToChild(createToolResultMessage(nonce, data.id, result, false));
|
|
375
|
+
} catch (err) {
|
|
376
|
+
postToChild(createToolResultMessage(nonce, data.id, err, true));
|
|
377
|
+
}
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (isExecutionResultMessage(data)) {
|
|
381
|
+
if (data.nonce !== nonce) {
|
|
382
|
+
warnInvalidNonce("execution-result");
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
cleanup();
|
|
386
|
+
resolve(data.result);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const handleLoadError = () => {
|
|
390
|
+
resolveError("Sandbox iframe failed to load");
|
|
391
|
+
};
|
|
392
|
+
window.addEventListener("message", handler);
|
|
393
|
+
iframe.addEventListener("error", handleLoadError);
|
|
394
|
+
const timer = setTimeout(() => {
|
|
395
|
+
cleanup();
|
|
396
|
+
resolve({
|
|
397
|
+
result: void 0,
|
|
398
|
+
error: "Execution timed out",
|
|
399
|
+
logs: []
|
|
400
|
+
});
|
|
401
|
+
}, this.#timeout);
|
|
402
|
+
document.body.appendChild(iframe);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/browser-tool.ts
|
|
408
|
+
/**
|
|
409
|
+
* Zero-dependency browser counterpart to `createCodeTool` from `./ai`.
|
|
410
|
+
*
|
|
411
|
+
* Returns a plain JSON Schema tool descriptor instead of an AI SDK `Tool`.
|
|
412
|
+
* No `ai`, no `zod` — just JSON Schema and browser APIs. JSON Schema is used
|
|
413
|
+
* for generated types only; this helper does not perform runtime validation.
|
|
414
|
+
*/
|
|
415
|
+
const DEFAULT_DESCRIPTION = `Execute code to achieve a goal.
|
|
416
|
+
|
|
417
|
+
Available:
|
|
418
|
+
{{types}}
|
|
419
|
+
|
|
420
|
+
Write an async arrow function in JavaScript that returns the result.
|
|
421
|
+
Do NOT use TypeScript syntax — no type annotations, interfaces, or generics.
|
|
422
|
+
Do NOT define named functions then call them — just write the arrow function body directly.
|
|
423
|
+
|
|
424
|
+
Example: async () => { const r = await codemode.searchWeb({ query: "test" }); return r; }`;
|
|
425
|
+
function toRecord(tools) {
|
|
426
|
+
if (!Array.isArray(tools)) return tools;
|
|
427
|
+
const record = {};
|
|
428
|
+
for (const tool of tools) {
|
|
429
|
+
if (!tool.name) throw new Error("Tool descriptors in array form must have a `name` property");
|
|
430
|
+
record[tool.name] = tool;
|
|
431
|
+
}
|
|
432
|
+
return record;
|
|
433
|
+
}
|
|
434
|
+
function hasNeedsApproval(tool) {
|
|
435
|
+
return tool.needsApproval === true || typeof tool.needsApproval === "function";
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Create a codemode tool descriptor using only JSON Schema and browser APIs.
|
|
439
|
+
*
|
|
440
|
+
* This is the browser counterpart to `createCodeTool` from
|
|
441
|
+
* `@cloudflare/codemode/ai`.
|
|
442
|
+
* It returns a plain object with `{ name, description, inputSchema, outputSchema, execute }`
|
|
443
|
+
* that can be passed to any framework — including
|
|
444
|
+
* `navigator.modelContext.registerTool()`.
|
|
445
|
+
*
|
|
446
|
+
* Tools with `needsApproval` are excluded, matching the current codemode
|
|
447
|
+
* behavior for approval-gated tools. JSON Schema is used for prompt/type
|
|
448
|
+
* generation only and is not enforced at runtime.
|
|
449
|
+
*/
|
|
450
|
+
function createBrowserCodeTool(options) {
|
|
451
|
+
const allTools = toRecord(options.tools);
|
|
452
|
+
const toolMap = {};
|
|
453
|
+
for (const [name, tool] of Object.entries(allTools)) if (!hasNeedsApproval(tool)) toolMap[name] = tool;
|
|
454
|
+
const executor = options.executor ?? new IframeSandboxExecutor();
|
|
455
|
+
const schemaOnly = {};
|
|
456
|
+
for (const [name, tool] of Object.entries(toolMap)) schemaOnly[name] = {
|
|
457
|
+
description: tool.description,
|
|
458
|
+
inputSchema: tool.inputSchema,
|
|
459
|
+
outputSchema: tool.outputSchema
|
|
460
|
+
};
|
|
461
|
+
const types = generateTypesFromJsonSchema(schemaOnly);
|
|
462
|
+
const description = (options.description ?? DEFAULT_DESCRIPTION).replace("{{types}}", types);
|
|
463
|
+
const fns = {};
|
|
464
|
+
const sanitizedNames = /* @__PURE__ */ new Map();
|
|
465
|
+
for (const [name, tool] of Object.entries(toolMap)) if (tool.execute) {
|
|
466
|
+
const sanitizedName = sanitizeToolName(name);
|
|
467
|
+
const existingName = sanitizedNames.get(sanitizedName);
|
|
468
|
+
if (existingName && existingName !== name) throw new Error(`Tool names "${existingName}" and "${name}" both sanitize to "${sanitizedName}"`);
|
|
469
|
+
sanitizedNames.set(sanitizedName, name);
|
|
470
|
+
fns[sanitizedName] = tool.execute;
|
|
471
|
+
}
|
|
472
|
+
const resolvedProviders = [{
|
|
473
|
+
name: "codemode",
|
|
474
|
+
fns
|
|
475
|
+
}];
|
|
476
|
+
return {
|
|
477
|
+
name: "codemode",
|
|
478
|
+
description,
|
|
479
|
+
inputSchema: {
|
|
480
|
+
type: "object",
|
|
481
|
+
properties: { code: {
|
|
482
|
+
type: "string",
|
|
483
|
+
description: "JavaScript async arrow function to execute"
|
|
484
|
+
} },
|
|
485
|
+
required: ["code"]
|
|
486
|
+
},
|
|
487
|
+
outputSchema: {
|
|
488
|
+
type: "object",
|
|
489
|
+
properties: {
|
|
490
|
+
result: { description: "The return value of the executed code" },
|
|
491
|
+
logs: {
|
|
492
|
+
type: "array",
|
|
493
|
+
items: { type: "string" },
|
|
494
|
+
description: "Console output captured during execution"
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
required: ["result"]
|
|
498
|
+
},
|
|
499
|
+
execute: async ({ code }) => runCode({
|
|
500
|
+
code,
|
|
501
|
+
executor,
|
|
502
|
+
providers: resolvedProviders
|
|
503
|
+
})
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
//#endregion
|
|
507
|
+
export { IframeSandboxExecutor, createBrowserCodeTool };
|
|
508
|
+
|
|
509
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","names":["#timeout","#csp"],"sources":["../src/messages.ts","../src/iframe-runtime.ts","../src/iframe-executor.ts","../src/browser-tool.ts"],"sourcesContent":["/**\n * Typed postMessage protocol for host ↔ iframe sandbox communication.\n *\n * Messages flow in two directions:\n * - Sandbox → Host: tool calls and execution results\n * - Host → Sandbox: tool results and execute requests\n */\n\nimport type { ExecuteResult } from \"./executor-types\";\n\n// -- Helpers --\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\n// -- Sandbox → Host messages --\n\nexport interface ToolCallMessage {\n type: \"tool-call\";\n nonce: string;\n id: number;\n provider: string;\n name: string;\n args: unknown;\n}\n\nexport interface ExecutionResultMessage {\n type: \"execution-result\";\n nonce: string;\n result: ExecuteResult;\n}\n\nexport interface SandboxReadyMessage {\n type: \"sandbox-ready\";\n}\n\n// -- Host → Sandbox messages --\n\nexport interface ToolResultSuccessMessage {\n type: \"tool-result\";\n nonce: string;\n id: number;\n result: unknown;\n}\n\nexport interface ToolResultErrorMessage {\n type: \"tool-result\";\n nonce: string;\n id: number;\n error: string;\n}\n\nexport interface ExecuteRequestMessage {\n type: \"execute-request\";\n nonce: string;\n code: string;\n providers: { name: string; positionalArgs?: boolean }[];\n}\n\n// -- Type guards --\n\nexport function isSandboxReadyMessage(\n data: unknown\n): data is SandboxReadyMessage {\n return isRecord(data) && data.type === \"sandbox-ready\";\n}\n\nexport function isToolCallMessage(data: unknown): data is ToolCallMessage {\n return (\n isRecord(data) &&\n data.type === \"tool-call\" &&\n typeof data.nonce === \"string\" &&\n typeof data.id === \"number\" &&\n typeof data.provider === \"string\" &&\n typeof data.name === \"string\"\n );\n}\n\nexport function isExecutionResultMessage(\n data: unknown\n): data is ExecutionResultMessage {\n if (!isRecord(data)) return false;\n if (data.type !== \"execution-result\") return false;\n if (typeof data.nonce !== \"string\") return false;\n if (typeof data.result !== \"object\" || data.result === null) return false;\n return true;\n}\n\nexport function isExecuteRequestMessageShape(\n data: unknown\n): data is ExecuteRequestMessage {\n return (\n isRecord(data) &&\n data.type === \"execute-request\" &&\n typeof data.nonce === \"string\" &&\n typeof data.code === \"string\" &&\n Array.isArray(data.providers) &&\n data.providers.every(\n (provider) =>\n isRecord(provider) &&\n typeof provider.name === \"string\" &&\n (provider.positionalArgs === undefined ||\n typeof provider.positionalArgs === \"boolean\")\n )\n );\n}\n","/**\n * Self-contained runtime that boots inside the sandboxed iframe.\n *\n * The `iframeSandboxRuntimeMain` function is serialized via `.toString()`\n * and injected into the iframe's `srcdoc`. It MUST be fully self-contained —\n * no closures over module-level variables, no imported values at runtime.\n * (Type-only imports are safe because they are erased at compile time.)\n */\n\n/**\n * The iframe-side runtime entry point.\n *\n * This function is stringified and injected into the iframe via srcdoc.\n * Everything it needs must be defined inside its own scope.\n */\nfunction iframeSandboxRuntimeMain(): void {\n const runtimeWindow = window as Window &\n typeof globalThis & { __codemodeIframeInitialized?: boolean };\n\n if (runtimeWindow.__codemodeIframeInitialized) {\n return;\n }\n\n runtimeWindow.__codemodeIframeInitialized = true;\n\n const logs: string[] = [];\n const pending: Record<\n number,\n { resolve: (value: unknown) => void; reject: (reason: Error) => void }\n > = {};\n let nextId = 0;\n let activeNonce: string | undefined;\n\n function post(message: unknown) {\n parent.postMessage(message, \"*\");\n }\n\n // Capture console output\n console.log = (...args: unknown[]) => {\n const values = [];\n for (let i = 0; i < args.length; i++) values.push(String(args[i]));\n logs.push(values.join(\" \"));\n };\n console.warn = (...args: unknown[]) => {\n const values = [];\n for (let i = 0; i < args.length; i++) values.push(String(args[i]));\n logs.push(\"[warn] \" + values.join(\" \"));\n };\n console.error = (...args: unknown[]) => {\n const values = [];\n for (let i = 0; i < args.length; i++) values.push(String(args[i]));\n logs.push(\"[error] \" + values.join(\" \"));\n };\n\n function createProviderProxy(\n nonce: string,\n provider: {\n name: string;\n positionalArgs?: boolean;\n }\n ) {\n return new Proxy(\n {},\n {\n get: (_, toolName) => {\n if (provider.positionalArgs) {\n return (...args: unknown[]) => {\n const id = nextId++;\n return new Promise((resolve, reject) => {\n pending[id] = { resolve, reject };\n post({\n type: \"tool-call\",\n nonce,\n id,\n provider: provider.name,\n name: String(toolName),\n args\n });\n });\n };\n }\n\n return (args: unknown) => {\n const id = nextId++;\n return new Promise((resolve, reject) => {\n pending[id] = { resolve, reject };\n post({\n type: \"tool-call\",\n nonce,\n id,\n provider: provider.name,\n name: String(toolName),\n args: args ?? {}\n });\n });\n };\n }\n }\n );\n }\n\n function isToolResultMessage(message: unknown): message is {\n type: \"tool-result\";\n nonce: string;\n id: number;\n result?: unknown;\n error?: string;\n } {\n if (typeof message !== \"object\" || message === null) return false;\n const candidate = message as Record<string, unknown>;\n return (\n candidate.type === \"tool-result\" &&\n typeof candidate.nonce === \"string\" &&\n typeof candidate.id === \"number\"\n );\n }\n\n function isExecuteRequestMessage(message: unknown): message is {\n type: \"execute-request\";\n nonce: string;\n code: string;\n providers: { name: string; positionalArgs?: boolean }[];\n } {\n if (typeof message !== \"object\" || message === null) return false;\n const candidate = message as Record<string, unknown>;\n return (\n candidate.type === \"execute-request\" &&\n typeof candidate.nonce === \"string\" &&\n typeof candidate.code === \"string\" &&\n Array.isArray(candidate.providers) &&\n candidate.providers.every(\n (provider) =>\n typeof provider === \"object\" &&\n provider !== null &&\n typeof (provider as { name?: unknown }).name === \"string\" &&\n ((provider as { positionalArgs?: unknown }).positionalArgs ===\n undefined ||\n typeof (provider as { positionalArgs?: unknown }).positionalArgs ===\n \"boolean\")\n )\n );\n }\n\n function executeCode(\n nonce: string,\n code: string,\n providers: { name: string; positionalArgs?: boolean }[]\n ) {\n try {\n activeNonce = nonce;\n const providerNames: string[] = [];\n const providerProxies: unknown[] = [];\n for (const provider of providers) {\n providerNames.push(provider.name);\n providerProxies.push(createProviderProxy(nonce, provider));\n }\n\n const fn = new Function(...providerNames, \"return (\" + code + \")\")(\n ...providerProxies\n );\n Promise.resolve(fn())\n .then((result: unknown) => {\n post({ type: \"execution-result\", nonce, result: { result, logs } });\n })\n .catch((err: Error) => {\n post({\n type: \"execution-result\",\n nonce,\n result: {\n result: undefined,\n error: err.message || String(err),\n logs\n }\n });\n });\n } catch (err) {\n post({\n type: \"execution-result\",\n nonce,\n result: {\n result: undefined,\n error: err instanceof Error ? err.message : String(err),\n logs\n }\n });\n }\n }\n\n window.addEventListener(\"message\", (event) => {\n if (event.source !== parent) return;\n\n const message = event.data;\n\n if (isToolResultMessage(message)) {\n if (message.nonce !== activeNonce) return;\n const request = pending[message.id];\n if (!request) return;\n\n delete pending[message.id];\n if (\"error\" in message)\n request.reject(new Error(message.error as string));\n else request.resolve(message.result);\n return;\n }\n\n if (isExecuteRequestMessage(message)) {\n executeCode(message.nonce, message.code, message.providers);\n }\n });\n\n post({ type: \"sandbox-ready\" });\n}\n\n/**\n * Returns a self-contained script string that boots the codemode iframe runtime.\n */\nexport function createIframeSandboxRuntimeScript(): string {\n return `;(${iframeSandboxRuntimeMain.toString()})();`;\n}\n","/**\n * IframeSandboxExecutor — a browser-native Executor that runs LLM-generated\n * code in a sandboxed iframe using postMessage for tool dispatch.\n *\n * Zero dependencies — uses only browser APIs (iframe, postMessage, CSP).\n */\n\nimport {\n type ExecuteRequestMessage,\n isExecutionResultMessage,\n isSandboxReadyMessage,\n isToolCallMessage,\n type ToolResultErrorMessage,\n type ToolResultSuccessMessage\n} from \"./messages\";\nimport type {\n ExecuteResult,\n Executor,\n ResolvedProvider\n} from \"./executor-types\";\nimport { createIframeSandboxRuntimeScript } from \"./iframe-runtime\";\nimport { normalizeCode } from \"./normalize\";\nimport { sanitizeToolName } from \"./utils\";\n\nexport interface IframeSandboxExecutorOptions {\n /** Maximum execution time in milliseconds. Defaults to `30000`. */\n timeout?: number;\n /**\n * Content Security Policy applied to the iframe document.\n *\n * When omitted, defaults to a restrictive policy that only allows\n * inline scripts and eval (needed for code execution).\n */\n csp?: string;\n}\n\nconst DEFAULT_CSP =\n \"default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval';\";\nconst DEFAULT_TIMEOUT = 30000;\n\nfunction escapeHtmlAttribute(value: string): string {\n return value.replace(/&/g, \"&\").replace(/\"/g, \""\");\n}\n\nfunction escapeInlineScript(value: string): string {\n return value.replace(/<\\/script/gi, \"<\\\\/script\");\n}\n\nfunction buildSrcdoc(csp: string): string {\n const runtimeScript = escapeInlineScript(createIframeSandboxRuntimeScript());\n const safeCsp = escapeHtmlAttribute(csp);\n\n return `<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv=\"Content-Security-Policy\" content=\"${safeCsp}\">\n</head>\n<body>\n<script>\n${runtimeScript}\n</script>\n</body>\n</html>`;\n}\n\nfunction createToolResultMessage(\n nonce: string,\n id: number,\n value: unknown,\n isError: boolean\n): ToolResultSuccessMessage | ToolResultErrorMessage {\n if (isError) {\n return {\n type: \"tool-result\",\n nonce,\n id,\n error: value instanceof Error ? value.message : String(value)\n };\n }\n return { type: \"tool-result\", nonce, id, result: value };\n}\n\nfunction createExecutionNonce(): string {\n if (globalThis.crypto?.randomUUID) {\n return globalThis.crypto.randomUUID();\n }\n\n const bytes = new Uint8Array(16);\n globalThis.crypto.getRandomValues(bytes);\n return Array.from(bytes, (byte) => byte.toString(16).padStart(2, \"0\")).join(\n \"\"\n );\n}\n\n/**\n * Executes LLM-generated code in a browser iframe sandbox.\n *\n * For each execution, a hidden iframe is created with `sandbox=\"allow-scripts\"`,\n * the runtime is injected via `srcdoc`, and the iframe is removed after completion.\n * Tool calls are dispatched via `postMessage`.\n */\nexport class IframeSandboxExecutor implements Executor {\n #timeout: number;\n #csp: string;\n\n constructor(options?: IframeSandboxExecutorOptions) {\n this.#timeout = options?.timeout ?? DEFAULT_TIMEOUT;\n this.#csp = options?.csp ?? DEFAULT_CSP;\n }\n\n async execute(\n code: string,\n providersOrFns:\n | ResolvedProvider[]\n | Record<string, (...args: unknown[]) => Promise<unknown>>\n ): Promise<ExecuteResult> {\n let providers: ResolvedProvider[];\n if (!Array.isArray(providersOrFns)) {\n console.warn(\n \"[@cloudflare/codemode] Passing raw fns to executor.execute() is deprecated. \" +\n \"Use ResolvedProvider[] instead. This will be removed in the next major version.\"\n );\n providers = [{ name: \"codemode\", fns: providersOrFns }];\n } else {\n providers = providersOrFns;\n }\n\n const reservedNames = new Set([\"__dispatchers\", \"__logs\"]);\n const validIdent = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n const seenNames = new Set<string>();\n for (const provider of providers) {\n if (reservedNames.has(provider.name)) {\n return {\n result: undefined,\n error: `Provider name \"${provider.name}\" is reserved`\n };\n }\n if (!validIdent.test(provider.name)) {\n return {\n result: undefined,\n error: `Provider name \"${provider.name}\" is not a valid JavaScript identifier`\n };\n }\n if (seenNames.has(provider.name)) {\n return {\n result: undefined,\n error: `Duplicate provider name \"${provider.name}\"`\n };\n }\n seenNames.add(provider.name);\n }\n\n const normalizedCode = normalizeCode(code);\n const resolvedProviders: ResolvedProvider[] = [];\n for (const provider of providers) {\n const sanitizedFns: Record<\n string,\n (...args: unknown[]) => Promise<unknown>\n > = {};\n const sanitizedNames = new Map<string, string>();\n for (const [name, fn] of Object.entries(provider.fns)) {\n const sanitizedName = sanitizeToolName(name);\n const existingName = sanitizedNames.get(sanitizedName);\n if (existingName && existingName !== name) {\n return {\n result: undefined,\n error:\n `Tool names \"${existingName}\" and \"${name}\" both sanitize to ` +\n `\"${sanitizedName}\" in provider \"${provider.name}\"`\n };\n }\n sanitizedNames.set(sanitizedName, name);\n sanitizedFns[sanitizedName] = fn;\n }\n const resolved: ResolvedProvider = {\n name: provider.name,\n fns: sanitizedFns\n };\n if (provider.positionalArgs) resolved.positionalArgs = true;\n resolvedProviders.push(resolved);\n }\n const providerMap = new Map(\n resolvedProviders.map((provider) => [provider.name, provider] as const)\n );\n const nonce = createExecutionNonce();\n\n const executeRequest: ExecuteRequestMessage = {\n type: \"execute-request\",\n nonce,\n code: normalizedCode,\n providers: resolvedProviders.map((provider) => {\n if (provider.positionalArgs) {\n return { name: provider.name, positionalArgs: true };\n }\n return { name: provider.name };\n })\n };\n\n const invokeProviderTool = async (\n provider: ResolvedProvider,\n args: unknown,\n name: string\n ) => {\n const fn = provider.fns[name];\n if (!fn) {\n throw new Error(`Tool \"${name}\" not found`);\n }\n if (!provider.positionalArgs) {\n return fn(args);\n }\n const positionalArgs = Array.isArray(args) ? args : [args];\n return fn(...positionalArgs);\n };\n\n const iframe = document.createElement(\"iframe\");\n iframe.sandbox.add(\"allow-scripts\");\n iframe.style.display = \"none\";\n iframe.style.width = \"0\";\n iframe.style.height = \"0\";\n iframe.style.border = \"none\";\n iframe.srcdoc = buildSrcdoc(this.#csp);\n\n return new Promise<ExecuteResult>((resolve) => {\n let settled = false;\n let ready = false;\n const warnedInvalidNonceTypes = new Set<string>();\n\n const cleanup = () => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n window.removeEventListener(\"message\", handler);\n iframe.removeEventListener(\"error\", handleLoadError);\n iframe.remove();\n };\n\n const resolveError = (message: string) => {\n cleanup();\n resolve({ result: undefined, error: message, logs: [] });\n };\n\n const postToChild = (\n message:\n | ToolResultSuccessMessage\n | ToolResultErrorMessage\n | ExecuteRequestMessage\n ): boolean => {\n const child = iframe.contentWindow;\n if (!child) {\n resolveError(\"Sandbox iframe is not available\");\n return false;\n }\n\n try {\n child.postMessage(message, \"*\");\n return true;\n } catch (err) {\n resolveError(err instanceof Error ? err.message : String(err));\n return false;\n }\n };\n\n const warnInvalidNonce = (messageType: string) => {\n if (warnedInvalidNonceTypes.has(messageType)) return;\n warnedInvalidNonceTypes.add(messageType);\n console.warn(\n `[@cloudflare/codemode] Ignoring sandbox ${messageType} message with invalid execution nonce`\n );\n };\n\n const handler = async (event: MessageEvent) => {\n if (event.source !== iframe.contentWindow) return;\n\n const data: unknown = event.data;\n\n if (isSandboxReadyMessage(data)) {\n if (ready) return;\n ready = true;\n postToChild(executeRequest);\n return;\n }\n\n if (isToolCallMessage(data)) {\n if (data.nonce !== nonce) {\n warnInvalidNonce(\"tool-call\");\n return;\n }\n const provider = providerMap.get(data.provider);\n if (!provider) {\n postToChild(\n createToolResultMessage(\n nonce,\n data.id,\n `Provider \"${data.provider}\" not found`,\n true\n )\n );\n return;\n }\n try {\n const result = await invokeProviderTool(\n provider,\n data.args,\n data.name\n );\n postToChild(createToolResultMessage(nonce, data.id, result, false));\n } catch (err) {\n postToChild(createToolResultMessage(nonce, data.id, err, true));\n }\n return;\n }\n\n if (isExecutionResultMessage(data)) {\n if (data.nonce !== nonce) {\n warnInvalidNonce(\"execution-result\");\n return;\n }\n cleanup();\n resolve(data.result);\n }\n };\n\n const handleLoadError = () => {\n resolveError(\"Sandbox iframe failed to load\");\n };\n\n window.addEventListener(\"message\", handler);\n iframe.addEventListener(\"error\", handleLoadError);\n\n const timer = setTimeout(() => {\n cleanup();\n resolve({ result: undefined, error: \"Execution timed out\", logs: [] });\n }, this.#timeout);\n\n document.body.appendChild(iframe);\n });\n }\n}\n","/**\n * Zero-dependency browser counterpart to `createCodeTool` from `./ai`.\n *\n * Returns a plain JSON Schema tool descriptor instead of an AI SDK `Tool`.\n * No `ai`, no `zod` — just JSON Schema and browser APIs. JSON Schema is used\n * for generated types only; this helper does not perform runtime validation.\n */\n\nimport {\n generateTypesFromJsonSchema,\n type JsonSchemaToolDescriptor,\n type JsonSchemaToolDescriptors\n} from \"./json-schema-types\";\nimport { runCode } from \"./run-code\";\nimport { sanitizeToolName } from \"./utils\";\nimport type { Executor, ResolvedProvider } from \"./executor-types\";\nimport type { CodeInput, CodeOutput } from \"./shared\";\nimport { IframeSandboxExecutor } from \"./iframe-executor\";\n\n// -- Types --\n\n/**\n * A JSON Schema tool descriptor with an execute function attached.\n */\nexport interface JsonSchemaExecutableToolDescriptor extends JsonSchemaToolDescriptor {\n name?: string;\n execute: (args: Record<string, unknown>) => Promise<unknown>;\n}\n\nexport type JsonSchemaExecutableToolDescriptors = Record<\n string,\n JsonSchemaExecutableToolDescriptor\n>;\n\ninterface ApprovalAwareJsonSchemaExecutableToolDescriptor extends JsonSchemaExecutableToolDescriptor {\n needsApproval?: boolean | ((...args: unknown[]) => unknown);\n}\n\ntype ApprovalAwareJsonSchemaExecutableToolDescriptors = Record<\n string,\n ApprovalAwareJsonSchemaExecutableToolDescriptor\n>;\n\nexport interface BrowserCodeToolDescriptor {\n name: string;\n description: string;\n inputSchema: {\n type: \"object\";\n properties: {\n code: { type: \"string\"; description: string };\n };\n required: [\"code\"];\n };\n outputSchema: {\n type: \"object\";\n properties: {\n result: { description: string };\n logs: {\n type: \"array\";\n items: { type: \"string\" };\n description: string;\n };\n };\n required: [\"result\"];\n };\n execute: (args: CodeInput) => Promise<CodeOutput>;\n}\n\nexport interface CreateBrowserCodeToolOptions {\n /**\n * Tools available inside the sandbox via `codemode.*`.\n *\n * Accepts either an array (like `listTools()` returns) with `name` on each item,\n * or an object keyed by tool name (like `createCodeTool` expects).\n */\n tools:\n | ApprovalAwareJsonSchemaExecutableToolDescriptor[]\n | ApprovalAwareJsonSchemaExecutableToolDescriptors;\n /**\n * Executor to use. Defaults to a new `IframeSandboxExecutor`.\n */\n executor?: Executor;\n /**\n * Custom tool description. Use `{{types}}` as a placeholder for generated type definitions.\n */\n description?: string;\n}\n\n// -- Implementation --\n\nconst DEFAULT_DESCRIPTION = `Execute code to achieve a goal.\n\nAvailable:\n{{types}}\n\nWrite an async arrow function in JavaScript that returns the result.\nDo NOT use TypeScript syntax — no type annotations, interfaces, or generics.\nDo NOT define named functions then call them — just write the arrow function body directly.\n\nExample: async () => { const r = await codemode.searchWeb({ query: \"test\" }); return r; }`;\n\nfunction toRecord(\n tools:\n | ApprovalAwareJsonSchemaExecutableToolDescriptor[]\n | ApprovalAwareJsonSchemaExecutableToolDescriptors\n): ApprovalAwareJsonSchemaExecutableToolDescriptors {\n if (!Array.isArray(tools)) return tools;\n\n const record: ApprovalAwareJsonSchemaExecutableToolDescriptors = {};\n for (const tool of tools) {\n if (!tool.name) {\n throw new Error(\n \"Tool descriptors in array form must have a `name` property\"\n );\n }\n record[tool.name] = tool;\n }\n return record;\n}\n\nfunction hasNeedsApproval(tool: Record<string, unknown>): boolean {\n return (\n tool.needsApproval === true || typeof tool.needsApproval === \"function\"\n );\n}\n\n/**\n * Create a codemode tool descriptor using only JSON Schema and browser APIs.\n *\n * This is the browser counterpart to `createCodeTool` from\n * `@cloudflare/codemode/ai`.\n * It returns a plain object with `{ name, description, inputSchema, outputSchema, execute }`\n * that can be passed to any framework — including\n * `navigator.modelContext.registerTool()`.\n *\n * Tools with `needsApproval` are excluded, matching the current codemode\n * behavior for approval-gated tools. JSON Schema is used for prompt/type\n * generation only and is not enforced at runtime.\n */\nexport function createBrowserCodeTool(\n options: CreateBrowserCodeToolOptions\n): BrowserCodeToolDescriptor {\n const allTools = toRecord(options.tools);\n const toolMap: JsonSchemaExecutableToolDescriptors = {};\n for (const [name, tool] of Object.entries(allTools)) {\n if (!hasNeedsApproval(tool as unknown as Record<string, unknown>)) {\n toolMap[name] = tool;\n }\n }\n const executor = options.executor ?? new IframeSandboxExecutor();\n\n // Generate TypeScript type descriptions for the LLM prompt\n const schemaOnly: JsonSchemaToolDescriptors = {};\n for (const [name, tool] of Object.entries(toolMap)) {\n schemaOnly[name] = {\n description: tool.description,\n inputSchema: tool.inputSchema,\n outputSchema: tool.outputSchema\n };\n }\n const types = generateTypesFromJsonSchema(schemaOnly);\n\n const description = (options.description ?? DEFAULT_DESCRIPTION).replace(\n \"{{types}}\",\n types\n );\n\n // Extract execute functions, keyed by sanitized name\n const fns: Record<string, (...args: unknown[]) => Promise<unknown>> = {};\n const sanitizedNames = new Map<string, string>();\n for (const [name, tool] of Object.entries(toolMap)) {\n if (tool.execute) {\n const sanitizedName = sanitizeToolName(name);\n const existingName = sanitizedNames.get(sanitizedName);\n if (existingName && existingName !== name) {\n throw new Error(\n `Tool names \"${existingName}\" and \"${name}\" both sanitize to \"${sanitizedName}\"`\n );\n }\n sanitizedNames.set(sanitizedName, name);\n fns[sanitizedName] = tool.execute as (args: unknown) => Promise<unknown>;\n }\n }\n const resolvedProviders: ResolvedProvider[] = [{ name: \"codemode\", fns }];\n\n return {\n name: \"codemode\",\n description,\n inputSchema: {\n type: \"object\",\n properties: {\n code: {\n type: \"string\",\n description: \"JavaScript async arrow function to execute\"\n }\n },\n required: [\"code\"]\n },\n outputSchema: {\n type: \"object\",\n properties: {\n result: {\n description: \"The return value of the executed code\"\n },\n logs: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Console output captured during execution\"\n }\n },\n required: [\"result\"]\n },\n execute: async ({ code }) =>\n runCode({ code, executor, providers: resolvedProviders })\n };\n}\n"],"mappings":";;;AAYA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU;;AAiDhD,SAAgB,sBACd,MAC6B;CAC7B,OAAO,SAAS,KAAK,IAAI,KAAK,SAAS;;AAGzC,SAAgB,kBAAkB,MAAwC;CACxE,OACE,SAAS,KAAK,IACd,KAAK,SAAS,eACd,OAAO,KAAK,UAAU,YACtB,OAAO,KAAK,OAAO,YACnB,OAAO,KAAK,aAAa,YACzB,OAAO,KAAK,SAAS;;AAIzB,SAAgB,yBACd,MACgC;CAChC,IAAI,CAAC,SAAS,KAAK,EAAE,OAAO;CAC5B,IAAI,KAAK,SAAS,oBAAoB,OAAO;CAC7C,IAAI,OAAO,KAAK,UAAU,UAAU,OAAO;CAC3C,IAAI,OAAO,KAAK,WAAW,YAAY,KAAK,WAAW,MAAM,OAAO;CACpE,OAAO;;;;;;;;;;;;;;;;;;ACvET,SAAS,2BAAiC;CACxC,MAAM,gBAAgB;CAGtB,IAAI,cAAc,6BAChB;CAGF,cAAc,8BAA8B;CAE5C,MAAM,OAAiB,EAAE;CACzB,MAAM,UAGF,EAAE;CACN,IAAI,SAAS;CACb,IAAI;CAEJ,SAAS,KAAK,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