Lines 4329-4369javascript
4329 ["setImmediate", /\bsetImmediate\b/],
4330 ["Atomics", /\bAtomics\b/],
4331 ["SharedArrayBuffer", /\bSharedArrayBuffer\b/],
4332 ["WebAssembly", /\bWebAssembly\b/],
4333 ["Reflect", /\bReflect\b/],
4334 ["Proxy", /\bProxy\b/],
4335 ["Buffer", /\bBuffer\b/],
4336 ["while(true)", /while\s*\(\s*true\s*\)/],
4337 ["for(;;)", /for\s*\(\s*;\s*;\s*\)/],
4338 // escape sequences can smuggle a denied identifier past the substring check
4339 // (e.g. `process` parses as `process`), so forbid them outright.
4340 ["\\u escape", /\\u/],
4341 ["\\x escape", /\\x/]
4343 const violations = DENY.filter(([, re]) => re.test(code)).map(([name]) => name);
4344 return { ok: violations.length === 0, violations };
4346function compileSynthesizedTool(spec) {
4347 const v = validateToolCode(spec.code);
4348 if (!v.ok) throw new Error(`unsafe synthesized tool '${spec.name}': blocked tokens [${v.violations.join(", ")}]`);
4349 if (!/^[A-Za-z_]\w{0,39}$/.test(spec.name)) throw new Error(`invalid tool name '${spec.name}'`);
4350 const fn = new Function("args", "ctx", `"use strict"; return (async (args, ctx) => { ${spec.code} })(args, ctx);`);
4351 return {
LowEval
Package source references a known benign dynamic code generation pattern.
dist/index.jsView on unpkg · L4349 4353 description: spec.description,
4354 parameters: spec.parameters ?? { type: "object", properties: {} },
4355 async run(args, ctx) {
4356 const r = await fn(args, ctx);
4357 return typeof r === "string" ? r : JSON.stringify(r ?? "");
4362// src/FakeAIClient.ts
4363var FakeAIClient = class {
4366 constructor(script) {
4367 this.script = [...script];
4369 async chat(options) {