@langchain/quickjs 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +665 -339
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +206 -50
- package/dist/index.d.ts +206 -50
- package/dist/index.js +654 -336
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/utils.ts","../src/transform.ts","../src/session.ts","../src/middleware.ts"],"sourcesContent":["import { compile } from \"json-schema-to-typescript\";\nimport { toJsonSchema } from \"@langchain/core/utils/json_schema\";\nimport dedent from \"dedent\";\nimport type { ReplResult } from \"./types.js\";\n\n/**\n * Convert a snake_case or kebab-case string to camelCase.\n */\nexport function toCamelCase(name: string): string {\n return name.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase());\n}\n\n/**\n * Recursively collect all string values from an object, array, or primitive.\n */\nexport function collectStrings(obj: unknown): string[] {\n const result: string[] = [];\n function walk(val: unknown) {\n if (typeof val === \"string\") {\n result.push(val);\n } else if (Array.isArray(val)) {\n for (const item of val) walk(item);\n } else if (typeof val === \"object\" && val !== null) {\n for (const v of Object.values(val)) walk(v);\n }\n }\n walk(obj);\n return result;\n}\n\n/**\n * Format the result of a REPL evaluation for the agent.\n */\nexport function formatReplResult(result: ReplResult): string {\n const parts: string[] = [];\n\n if (result.logs.length > 0) {\n parts.push(result.logs.join(\"\\n\"));\n }\n\n if (result.ok) {\n if (result.value !== undefined) {\n const formatted =\n typeof result.value === \"string\"\n ? result.value\n : JSON.stringify(result.value, null, 2);\n parts.push(`→ ${formatted}`);\n }\n } else if (result.error) {\n const errName = result.error.name || \"Error\";\n const errMsg = result.error.message || \"Unknown error\";\n parts.push(`${errName}: ${errMsg}`);\n if (result.error.stack) {\n parts.push(result.error.stack);\n }\n }\n\n return parts.join(\"\\n\") || \"(no output)\";\n}\n\nexport function safeToJsonSchema(\n schema: unknown,\n): Record<string, unknown> | undefined {\n try {\n return toJsonSchema(schema as Parameters<typeof toJsonSchema>[0]) as Record<\n string,\n unknown\n >;\n } catch {\n return undefined;\n }\n}\n\nasync function schemaToInterface(\n jsonSchema: Record<string, unknown>,\n interfaceName: string,\n): Promise<string> {\n const compiled = await compile(\n { ...jsonSchema, additionalProperties: false },\n interfaceName,\n { bannerComment: \"\", additionalProperties: false },\n );\n return compiled.replace(/^export /, \"\").trimEnd();\n}\n\nexport function capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\nexport async function toolToTypeSignature(\n name: string,\n description: string,\n jsonSchema: Record<string, unknown> | undefined,\n): Promise<string> {\n const inputType = `${capitalize(name)}Input`;\n\n if (!jsonSchema || !jsonSchema.properties) {\n return dedent`\n /**\n * ${description}\n */\n async tools.${name}(input: Record<string, unknown>): Promise<string>\n `;\n }\n\n const iface = await schemaToInterface(jsonSchema, inputType);\n return dedent`\n ${iface}\n\n /**\n * ${description}\n */\n async tools.${name}(input: ${inputType}): Promise<string>\n `;\n}\n","/**\n * AST-based code transform pipeline for the REPL.\n *\n * Transforms TypeScript/JavaScript code into plain JS that can be\n * evaluated inside QuickJS with proper state persistence:\n *\n * 1. Parse with acorn + acorn-typescript (handles TS syntax)\n * 2. Strip TypeScript-only nodes (type annotations, interfaces, etc.)\n * 3. Hoist top-level declarations to globalThis for cross-eval persistence\n * 4. Auto-return the last expression\n * 5. Wrap in async IIFE so top-level await works\n */\n\nimport { Parser } from \"acorn\";\nimport { tsPlugin } from \"@sveltejs/acorn-typescript\";\nimport { walk } from \"estree-walker\";\nimport MagicString from \"magic-string\";\nimport type {\n Node,\n Identifier,\n VariableDeclaration as EstreeVariableDeclaration,\n VariableDeclarator as EstreeVariableDeclarator,\n} from \"estree\";\n\nconst TSParser = Parser.extend(tsPlugin());\n\ntype AcornNode = Node & { start: number; end: number };\ntype AcornExpressionStatement = AcornNode & {\n type: \"ExpressionStatement\";\n expression: AcornNode;\n};\ntype AcornVariableDeclaration = EstreeVariableDeclaration & {\n start: number;\n end: number;\n declarations: AcornVariableDeclarator[];\n};\ntype AcornVariableDeclarator = EstreeVariableDeclarator & {\n start: number;\n end: number;\n id: AcornNode;\n init: AcornNode | null;\n};\n\n/**\n * Transform code for REPL evaluation.\n *\n * - Strips TypeScript syntax\n * - Hoists top-level variable declarations to globalThis\n * - Auto-returns the last expression\n * - Wraps in async IIFE for top-level await support\n */\nexport function transformForEval(code: string): string {\n let ast: AcornNode;\n try {\n ast = TSParser.parse(code, {\n ecmaVersion: \"latest\" as any,\n sourceType: \"module\",\n locations: true,\n }) as unknown as AcornNode;\n } catch {\n // If parsing fails, return the code as-is and let QuickJS report the error\n return `(async () => {\\n${code}\\n})()`;\n }\n\n const s = new MagicString(code);\n const program = ast as unknown as { body: AcornNode[] };\n const topLevelNodes = program.body;\n for (let i = 0; i < topLevelNodes.length; i++) {\n const node = topLevelNodes[i];\n\n // Remove TypeScript-only top-level declarations\n if (isTSOnlyNode(node)) {\n s.remove(node.start, node.end);\n continue;\n }\n\n // Remove import/export declarations (not supported in QuickJS eval)\n if (\n node.type === \"ImportDeclaration\" ||\n node.type === \"ExportNamedDeclaration\" ||\n node.type === \"ExportDefaultDeclaration\" ||\n node.type === \"ExportAllDeclaration\"\n ) {\n s.remove(node.start, node.end);\n continue;\n }\n\n // Hoist top-level variable declarations\n if (node.type === \"VariableDeclaration\") {\n hoistDeclaration(s, node as unknown as AcornVariableDeclaration);\n continue;\n }\n\n // Hoist function/class declarations to globalThis for cross-eval persistence\n if (\n node.type === \"FunctionDeclaration\" ||\n node.type === \"ClassDeclaration\"\n ) {\n stripTypeAnnotations(s, node);\n const name = (node as any).id?.name;\n if (name) {\n s.appendRight(node.end, `\\nglobalThis.${name} = ${name};`);\n }\n continue;\n }\n }\n\n // Strip type annotations from within expressions/statements\n for (const node of topLevelNodes) {\n if (isTSOnlyNode(node)) continue;\n if (\n node.type === \"ImportDeclaration\" ||\n node.type === \"ExportNamedDeclaration\" ||\n node.type === \"ExportDefaultDeclaration\" ||\n node.type === \"ExportAllDeclaration\"\n )\n continue;\n if (node.type !== \"VariableDeclaration\") {\n walk(node as any, {\n enter(n: any) {\n stripTypeAnnotationFromNode(s, n);\n },\n });\n }\n }\n\n // Auto-return the last expression. We insert `return (` before the\n // ExpressionStatement (to preserve any grouping parens like `({...})`),\n // but close `)` after the inner expression — not after the statement —\n // so any trailing semicolon stays outside: `return (expr);` not `return (expr;)`.\n const lastNode = findLastNonEmptyNode(topLevelNodes, s);\n if (lastNode && isExpression(lastNode)) {\n const { expression } = lastNode as AcornExpressionStatement;\n s.prependLeft(lastNode.start, \"return (\");\n s.appendRight(expression.end, \")\");\n }\n\n // Wrap in async IIFE\n s.prepend(\"(async () => {\\n\");\n s.append(\"\\n})()\");\n\n return s.toString();\n}\n\nfunction isTSOnlyNode(node: AcornNode): boolean {\n const t = node.type as string;\n return (\n t === \"TSTypeAliasDeclaration\" ||\n t === \"TSInterfaceDeclaration\" ||\n t === \"TSEnumDeclaration\" ||\n t === \"TSModuleDeclaration\" ||\n t === \"TSDeclareFunction\" ||\n t.startsWith(\"TS\")\n );\n}\n\n/**\n * Rewrite a top-level VariableDeclaration to globalThis assignments.\n *\n * `const x = 1, y = 2` → `globalThis.x = 1; globalThis.y = 2`\n *\n */\nfunction hoistDeclaration(\n s: MagicString,\n decl: AcornVariableDeclaration,\n): void {\n const parts: string[] = [];\n\n for (const d of decl.declarations) {\n const id = d.id as AcornNode;\n if (id.type === \"Identifier\") {\n const initCode = d.init ? extractCleanInit(s, d) : \"undefined\";\n parts.push(\n `globalThis.${(id as unknown as Identifier).name} = ${initCode}`,\n );\n } else if (id.type === \"ObjectPattern\" || id.type === \"ArrayPattern\") {\n const bindings = extractBindingNames(d.id as any);\n const initCode = d.init ? extractCleanInit(s, d) : \"undefined\";\n const patternCode = extractCleanSource(s, d.id as AcornNode);\n parts.push(`var ${patternCode} = ${initCode}`);\n for (const name of bindings) {\n parts.push(`globalThis.${name} = ${name}`);\n }\n }\n }\n\n s.overwrite(decl.start, decl.end, parts.join(\"; \") + \";\");\n}\n\n/**\n * Extract the initializer code, stripping TypeScript annotations from\n * within the expression (e.g. `as Type`, generics, parameter types in\n * arrow functions).\n */\nfunction extractCleanInit(s: MagicString, d: AcornVariableDeclarator): string {\n if (!d.init) return \"undefined\";\n return extractCleanSource(s, d.init as AcornNode);\n}\n\nfunction extractBindingNames(pattern: any): string[] {\n const names: string[] = [];\n if (pattern.type === \"Identifier\") {\n if (pattern.name) names.push(pattern.name);\n } else if (pattern.type === \"ObjectPattern\") {\n for (const prop of pattern.properties || []) {\n if (prop.type === \"RestElement\") {\n names.push(...extractBindingNames(prop.argument));\n } else {\n names.push(...extractBindingNames(prop.value));\n }\n }\n } else if (pattern.type === \"ArrayPattern\") {\n for (const el of pattern.elements || []) {\n if (el) names.push(...extractBindingNames(el));\n }\n } else if (pattern.type === \"RestElement\") {\n names.push(...extractBindingNames(pattern.argument));\n } else if (pattern.type === \"AssignmentPattern\") {\n names.push(...extractBindingNames(pattern.left));\n }\n return names;\n}\n\nfunction stripTypeAnnotations(s: MagicString, node: AcornNode): void {\n walk(node as any, {\n enter(n: any) {\n stripTypeAnnotationFromNode(s, n);\n },\n });\n}\n\nfunction stripTypeAnnotationFromNode(s: MagicString, n: any, offset = 0): void {\n // Type annotations on parameters, variables, return types\n if (n.typeAnnotation && n.typeAnnotation.start != null) {\n s.remove(n.typeAnnotation.start - offset, n.typeAnnotation.end - offset);\n }\n // Return type on functions\n if (n.returnType && n.returnType.start != null) {\n s.remove(n.returnType.start - offset, n.returnType.end - offset);\n }\n // Type parameters (generics)\n if (n.typeParameters && n.typeParameters.start != null) {\n s.remove(n.typeParameters.start - offset, n.typeParameters.end - offset);\n }\n // Type arguments on calls\n if (n.typeArguments && n.typeArguments.start != null) {\n s.remove(n.typeArguments.start - offset, n.typeArguments.end - offset);\n }\n // `as` expressions: keep the expression, remove `as Type`\n if (n.type === \"TSAsExpression\" && n.expression) {\n s.remove(n.expression.end - offset, n.end - offset);\n }\n // Non-null assertion: `x!` → `x`\n if (n.type === \"TSNonNullExpression\" && n.expression) {\n s.remove(n.expression.end - offset, n.end - offset);\n }\n // Satisfies expression: `x satisfies Type` → `x`\n if (n.type === \"TSSatisfiesExpression\" && n.expression) {\n s.remove(n.expression.end - offset, n.end - offset);\n }\n}\n\n/**\n * Extract a clean JS source string from an AST node, stripping all\n * TypeScript annotations. Works on a copy so the main MagicString is\n * not mutated.\n */\nfunction extractCleanSource(s: MagicString, node: AcornNode): string {\n const offset = node.start;\n const source = new MagicString(s.slice(node.start, node.end));\n walk(node as any, {\n enter(n: any) {\n stripTypeAnnotationFromNode(source, n, offset);\n },\n });\n return source.toString();\n}\n\nfunction findLastNonEmptyNode(\n nodes: AcornNode[],\n s: MagicString,\n): AcornNode | null {\n for (let i = nodes.length - 1; i >= 0; i--) {\n const node = nodes[i];\n // Skip nodes that were fully removed\n const slice = s.slice(node.start, node.end).trim();\n if (slice === \"\" || slice === \";\") continue;\n return node;\n }\n return null;\n}\n\nfunction isExpression(node: AcornNode): boolean {\n return node.type === \"ExpressionStatement\";\n}\n","/**\n * Core REPL engine built on quickjs-emscripten (asyncify variant).\n *\n * Host async functions (backend I/O, PTC tools) are exposed as\n * promise-returning functions inside the QuickJS guest. Guest code\n * uses `await` to consume them, enabling real concurrency via\n * `Promise.all`, `Promise.race`, etc.\n *\n * We still use the asyncify WASM variant because `evalCodeAsync` is\n * required to drive promise resolution from the host side.\n *\n * ## Architecture\n *\n * `ReplSession` is a serializable handle that can live in LangGraph state.\n * It holds an `id` that keys into a static session map. The heavy QuickJS\n * runtime is lazily started on the first `.eval()` call, making the session\n * safe across graph interrupts and checkpointing.\n *\n * File writes inside the REPL are buffered (`pendingWrites`) and only\n * flushed to the backend after a script finishes executing. Call\n * `session.flushWrites(backend)` after eval to persist them.\n */\n\nimport { shouldInterruptAfterDeadline } from \"quickjs-emscripten\";\nimport type { QuickJSHandle } from \"quickjs-emscripten\";\nimport { newQuickJSAsyncWASMModuleFromVariant } from \"quickjs-emscripten-core\";\nimport type {\n QuickJSAsyncContext,\n QuickJSAsyncRuntime,\n} from \"quickjs-emscripten-core\";\nimport type { AnyBackendProtocol, BackendProtocolV2 } from \"deepagents\";\nimport { adaptBackendProtocol } from \"deepagents\";\nimport type { StructuredToolInterface } from \"@langchain/core/tools\";\n\nimport type { ReplSessionOptions, ReplResult } from \"./types.js\";\nimport { toCamelCase } from \"./utils.js\";\nimport { transformForEval } from \"./transform.js\";\n\nexport const DEFAULT_MEMORY_LIMIT = 50 * 1024 * 1024;\nexport const DEFAULT_MAX_STACK_SIZE = 320 * 1024;\nexport const DEFAULT_EXECUTION_TIMEOUT = 30_000;\nexport const DEFAULT_SESSION_ID = \"__default__\";\n\nlet asyncModulePromise: Promise<any> | undefined;\n\nasync function getAsyncModule() {\n if (!asyncModulePromise) {\n asyncModulePromise = (async () => {\n const variant =\n await import(\"@jitl/quickjs-ng-wasmfile-release-asyncify\");\n return newQuickJSAsyncWASMModuleFromVariant(\n (variant.default ?? variant) as any,\n );\n })();\n }\n return asyncModulePromise;\n}\n\nexport interface PendingWrite {\n path: string;\n content: string;\n}\n\n/**\n * Sandboxed JavaScript REPL session backed by QuickJS WASM.\n *\n * Serializable — holds an `id` that keys into a static session map.\n * The QuickJS runtime is lazily started on the first `.eval()` call\n * and reconnected if a session with the same id already exists.\n * This makes it safe to store in LangGraph state across interrupts.\n *\n * File writes are buffered during execution and flushed via\n * `flushWrites(backend)` after eval completes.\n */\nexport class ReplSession {\n private static sessions = new Map<string, ReplSession>();\n\n readonly id: string;\n readonly pendingWrites: PendingWrite[] = [];\n\n private runtime: QuickJSAsyncRuntime | null = null;\n private context: QuickJSAsyncContext | null = null;\n private logs: string[] = [];\n private _options: ReplSessionOptions;\n\n private _backend: BackendProtocolV2 | null = null;\n\n constructor(id: string, options: ReplSessionOptions = {}) {\n this.id = id;\n this._options = options;\n }\n\n get backend(): BackendProtocolV2 | null {\n return this._backend;\n }\n\n set backend(b: AnyBackendProtocol | null) {\n this._backend = b ? adaptBackendProtocol(b) : null;\n }\n\n private async ensureStarted(): Promise<void> {\n if (this.runtime) return;\n\n const {\n memoryLimitBytes = DEFAULT_MEMORY_LIMIT,\n maxStackSizeBytes = DEFAULT_MAX_STACK_SIZE,\n backend,\n tools,\n } = this._options;\n\n const asyncModule = await getAsyncModule();\n const runtime: QuickJSAsyncRuntime = asyncModule.newRuntime();\n runtime.setMemoryLimit(memoryLimitBytes);\n runtime.setMaxStackSize(maxStackSizeBytes);\n\n const context: QuickJSAsyncContext = runtime.newContext();\n this.runtime = runtime;\n this.context = context;\n\n this.setupConsole();\n\n if (backend) {\n this._backend = adaptBackendProtocol(backend);\n }\n this.injectVfs();\n if (tools && tools.length > 0) {\n this.injectTools(tools);\n }\n }\n\n /**\n * Get or create a session for the given id.\n *\n * Sessions are deduped by id — calling `getOrCreate` twice with the\n * same id returns the same instance. The QuickJS runtime is lazily\n * started on the first `.eval()` call.\n */\n static getOrCreate(\n id: string,\n options: ReplSessionOptions = {},\n ): ReplSession {\n const existing = ReplSession.sessions.get(id);\n if (existing) {\n if (options.backend) {\n existing._backend = adaptBackendProtocol(options.backend);\n }\n return existing;\n }\n\n const session = new ReplSession(id, options);\n ReplSession.sessions.set(id, session);\n return session;\n }\n\n /**\n * Retrieve an existing session by id, or null if none exists.\n */\n static get(id: string): ReplSession | null {\n return ReplSession.sessions.get(id) ?? null;\n }\n\n /**\n * Evaluate code in this session.\n *\n * Lazily starts the QuickJS runtime on the first call. Code is\n * transformed via an AST pipeline that strips TypeScript syntax,\n * hoists top-level declarations to globalThis for cross-eval\n * persistence, auto-returns the last expression, and wraps in an\n * async IIFE.\n */\n async eval(code: string, timeoutMs: number): Promise<ReplResult> {\n await this.ensureStarted();\n const runtime = this.runtime!;\n const context = this.context!;\n\n this.logs.length = 0;\n\n if (timeoutMs >= 0) {\n runtime.setInterruptHandler(\n shouldInterruptAfterDeadline(Date.now() + timeoutMs),\n );\n } else {\n runtime.setInterruptHandler(() => false);\n }\n\n const transformed = transformForEval(code);\n const result = await context.evalCodeAsync(transformed);\n\n if (result.error) {\n const error = context.dump(result.error);\n result.error.dispose();\n return { ok: false, error, logs: [...this.logs] };\n }\n\n const promiseState = context.getPromiseState(result.value);\n\n if (promiseState.type === \"fulfilled\") {\n if (promiseState.notAPromise) {\n const value = context.dump(result.value);\n result.value.dispose();\n return { ok: true, value, logs: [...this.logs] };\n }\n const value = context.dump(promiseState.value);\n promiseState.value.dispose();\n result.value.dispose();\n return { ok: true, value, logs: [...this.logs] };\n }\n\n if (promiseState.type === \"rejected\") {\n const error = context.dump(promiseState.error);\n promiseState.error.dispose();\n result.value.dispose();\n return { ok: false, error, logs: [...this.logs] };\n }\n\n const noTimeout = timeoutMs < 0;\n const deadline = noTimeout ? Infinity : Date.now() + timeoutMs;\n while (noTimeout || Date.now() < deadline) {\n context.runtime.executePendingJobs();\n const state = context.getPromiseState(result.value);\n if (state.type === \"fulfilled\") {\n const value = context.dump(state.value);\n state.value.dispose();\n result.value.dispose();\n return { ok: true, value, logs: [...this.logs] };\n }\n if (state.type === \"rejected\") {\n const error = context.dump(state.error);\n state.error.dispose();\n result.value.dispose();\n return { ok: false, error, logs: [...this.logs] };\n }\n await new Promise((r) => setTimeout(r, 1));\n }\n\n result.value.dispose();\n return {\n ok: false,\n error: { message: \"Promise timed out — execution interrupted\" },\n logs: [...this.logs],\n };\n }\n\n async flushWrites(backend: AnyBackendProtocol): Promise<void> {\n const adapted = adaptBackendProtocol(backend);\n const writes = this.pendingWrites.splice(0);\n for (const { path, content } of writes) {\n await adapted.write(path, content);\n }\n }\n\n dispose(): void {\n try {\n this.context?.dispose();\n } catch {\n /* may already be disposed */\n }\n try {\n this.runtime?.dispose();\n } catch {\n /* may already be disposed */\n }\n this.runtime = null;\n this.context = null;\n ReplSession.sessions.delete(this.id);\n }\n\n toJSON(): { id: string } {\n return { id: this.id };\n }\n\n static fromJSON(data: { id: string }): ReplSession {\n return ReplSession.sessions.get(data.id) ?? new ReplSession(data.id);\n }\n\n /**\n * Clear the static session cache. Useful for testing.\n * @internal\n */\n static clearCache(): void {\n for (const session of ReplSession.sessions.values()) {\n session.dispose();\n }\n ReplSession.sessions.clear();\n }\n\n private setupConsole(): void {\n const context = this.context!;\n const logs = this.logs;\n const consoleHandle = context.newObject();\n for (const method of [\"log\", \"warn\", \"error\", \"info\", \"debug\"] as const) {\n const fnHandle = context.newFunction(\n method,\n (...args: QuickJSHandle[]) => {\n const nativeArgs = args.map((a: QuickJSHandle) => context.dump(a));\n const formatted = nativeArgs\n .map((a: unknown) =>\n typeof a === \"object\" && a !== null\n ? JSON.stringify(a)\n : String(a),\n )\n .join(\" \");\n logs.push(\n method === \"log\" || method === \"info\" || method === \"debug\"\n ? formatted\n : `[${method}] ${formatted}`,\n );\n },\n );\n context.setProp(consoleHandle, method, fnHandle);\n fnHandle.dispose();\n }\n context.setProp(context.global, \"console\", consoleHandle);\n consoleHandle.dispose();\n }\n\n private injectVfs(): void {\n const context = this.context!;\n const getBackend = () => this._backend;\n const { pendingWrites } = this;\n\n const readFileHandle = context.newFunction(\n \"readFile\",\n (pathHandle: QuickJSHandle) => {\n const backend = getBackend();\n if (!backend) {\n const promise = context.newPromise();\n const err = context.newError(\"Backend not available\");\n promise.reject(err);\n err.dispose();\n promise.settled.then(context.runtime.executePendingJobs);\n return promise.handle;\n }\n const path = context.getString(pathHandle);\n const promise = context.newPromise();\n (async () => {\n try {\n const result = await backend.readRaw(path);\n if (result.error || !result.data) {\n const err = context.newError(\n `ENOENT: no such file or directory '${path}'.`,\n );\n promise.reject(err);\n err.dispose();\n } else {\n const content = Array.isArray(result.data.content)\n ? result.data.content.join(\"\\n\")\n : typeof result.data.content === \"string\"\n ? result.data.content\n : null;\n if (content === null) {\n const err = context.newError(\n `Cannot read binary file '${path}' as text.`,\n );\n promise.reject(err);\n err.dispose();\n return;\n }\n const val = context.newString(content);\n promise.resolve(val);\n val.dispose();\n }\n } catch {\n const err = context.newError(\n `ENOENT: no such file or directory '${path}'.`,\n );\n promise.reject(err);\n err.dispose();\n }\n promise.settled.then(context.runtime.executePendingJobs);\n })();\n return promise.handle;\n },\n );\n context.setProp(context.global, \"readFile\", readFileHandle);\n readFileHandle.dispose();\n\n const writeFileHandle = context.newFunction(\n \"writeFile\",\n (pathHandle: QuickJSHandle, contentHandle: QuickJSHandle) => {\n const path = context.getString(pathHandle);\n const content = context.getString(contentHandle);\n const promise = context.newPromise();\n pendingWrites.push({ path, content });\n promise.resolve(context.undefined);\n promise.settled.then(context.runtime.executePendingJobs);\n return promise.handle;\n },\n );\n context.setProp(context.global, \"writeFile\", writeFileHandle);\n writeFileHandle.dispose();\n }\n\n private injectTools(tools: StructuredToolInterface[]): void {\n const context = this.context!;\n const toolsNs = context.newObject();\n\n for (const t of tools) {\n const camelName = toCamelCase(t.name);\n const fnHandle = context.newFunction(\n camelName,\n (inputHandle: QuickJSHandle) => {\n const input = context.dump(inputHandle);\n const promise = context.newPromise();\n (async () => {\n try {\n const rawInput =\n typeof input === \"object\" && input !== null ? input : {};\n const result = await t.invoke(rawInput);\n const val = context.newString(\n typeof result === \"string\" ? result : JSON.stringify(result),\n );\n promise.resolve(val);\n val.dispose();\n } catch (e: unknown) {\n const msg =\n e != null && typeof (e as Error).message === \"string\"\n ? (e as Error).message\n : String(e);\n const err = context.newError(`Tool '${t.name}' failed: ${msg}`);\n promise.reject(err);\n err.dispose();\n }\n promise.settled.then(context.runtime.executePendingJobs);\n })();\n return promise.handle;\n },\n );\n context.setProp(toolsNs, camelName, fnHandle);\n fnHandle.dispose();\n }\n\n context.setProp(context.global, \"tools\", toolsNs);\n toolsNs.dispose();\n }\n}\n","/**\n * QuickJS REPL middleware for deepagents.\n *\n * Provides a `js_eval` tool that runs JavaScript in a WASM-sandboxed QuickJS\n * interpreter. Supports:\n * - Persistent state across evaluations (true REPL)\n * - VFS integration via readFile/writeFile\n * - Programmatic tool calling (PTC)\n */\n\nimport {\n createMiddleware,\n tool,\n type AgentMiddleware as _AgentMiddleware,\n} from \"langchain\";\nimport { z } from \"zod/v4\";\nimport type { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { StateBackend, type BackendRuntime, resolveBackend } from \"deepagents\";\n\nimport dedent from \"dedent\";\nimport type { QuickJSMiddlewareOptions } from \"./types.js\";\nimport {\n ReplSession,\n DEFAULT_EXECUTION_TIMEOUT,\n DEFAULT_MEMORY_LIMIT,\n DEFAULT_MAX_STACK_SIZE,\n DEFAULT_SESSION_ID,\n} from \"./session.js\";\nimport {\n formatReplResult,\n toCamelCase,\n toolToTypeSignature,\n safeToJsonSchema,\n} from \"./utils.js\";\n\n/**\n * These type-only imports are required for TypeScript's type inference to work\n * correctly with the langchain/langgraph middleware system. Without them, certain\n * generic type parameters fail to resolve properly, causing runtime issues with\n * tool schemas and message types.\n */\nimport type * as _zodTypes from \"@langchain/core/utils/types\";\nimport type * as _zodMeta from \"@langchain/langgraph/zod\";\nimport type * as _messages from \"@langchain/core/messages\";\nimport {\n getCurrentTaskInput,\n LangGraphRunnableConfig,\n} from \"@langchain/langgraph\";\n\n/**\n * Backend-provided tools excluded from PTC by default.\n * These are redundant inside the REPL since VFS helpers (readFile/writeFile)\n * already cover file I/O against the agent's in-memory working set.\n */\nexport const DEFAULT_PTC_EXCLUDED_TOOLS = [\n \"ls\",\n \"read_file\",\n \"write_file\",\n \"edit_file\",\n \"glob\",\n \"grep\",\n \"execute\",\n] as const;\n\nconst REPL_SYSTEM_PROMPT = dedent`\n ## TypeScript/JavaScript REPL (\\`js_eval\\`)\n\n You have access to a sandboxed TypeScript/JavaScript REPL running in an isolated interpreter.\n TypeScript syntax (type annotations, interfaces, generics, \\`as\\` casts) is supported and stripped at evaluation time.\n Variables, functions, and closures persist across calls within the same session.\n\n ### Hard rules\n\n - **No network, no filesystem** — only the helpers below. Do not attempt \\`fetch\\`, \\`require\\`, or \\`import\\`.\n - **Cite your sources** — when reporting values from files, include the path and key/index so the user can verify.\n - **Use console.log()** for output — it is captured and returned. \\`console.warn()\\` and \\`console.error()\\` are also available.\n - **Reuse state from previous cells** — variables, functions, and results from earlier \\`js_eval\\` calls persist across calls. Reference them by name in follow-up cells instead of re-embedding data as inline JSON literals.\n\n ### First-time usage\n\n \\`\\`\\`typescript\n // Read a file from the agent's virtual filesystem\n const raw: string = await readFile(\"/data.json\");\n const data = JSON.parse(raw) as { n: number };\n console.log(data);\n\n // Write results back\n await writeFile(\"/output.txt\", JSON.stringify({ result: data.n }));\n \\`\\`\\`\n\n ### API Reference — built-in globals\n\n \\`\\`\\`typescript\n /**\n * Read a file from the agent's virtual filesystem. Throws if the file does not exist.\n */\n async readFile(path: string): Promise<string>\n\n /**\n * Write a file to the agent's virtual filesystem.\n */\n async writeFile(path: string, content: string): Promise<void>\n \\`\\`\\`\n\n ### Limitations\n\n - ES2023+ syntax with TypeScript support. No Node.js APIs, no \\`require\\`, no \\`import\\`.\n - Output is truncated beyond a fixed character limit — be selective about what you log.\n - Execution timeout per call (default 30 s).\n`;\n\n/**\n * Generate the PTC API Reference section for the system prompt.\n */\nexport async function generatePtcPrompt(\n tools: StructuredToolInterface[],\n): Promise<string> {\n if (tools.length === 0) return \"\";\n\n const signatures = await Promise.all(\n tools.map((t) => {\n const jsonSchema = t.schema ? safeToJsonSchema(t.schema) : undefined;\n return toolToTypeSignature(\n toCamelCase(t.name),\n t.description,\n jsonSchema,\n );\n }),\n );\n\n return dedent`\n\n ### API Reference — \\`tools\\` namespace\n\n The following agent tools are callable as async functions inside the REPL.\n Each takes a single object argument and returns a Promise that resolves to a string.\n Use \\`await\\` to call them. Promise APIs like \\`Promise.all\\` are also available.\n\n **Example usage:**\n \\`\\`\\`javascript\n // Call a tool\n const result = await tools.searchWeb({ query: \"QuickJS tutorial\" });\n console.log(result);\n\n // Concurrent calls\n const [a, b] = await Promise.all([\n tools.fetchData({ url: \"https://api.example.com/a\" }),\n tools.fetchData({ url: \"https://api.example.com/b\" }),\n ]);\n \\`\\`\\`\n\n **Available functions:**\n \\`\\`\\`typescript\n ${signatures.join(\"\\n\\n\")}\n \\`\\`\\`\n `;\n}\n\n/**\n * Create the QuickJS REPL middleware.\n */\nexport function createQuickJSMiddleware(\n options: QuickJSMiddlewareOptions = {},\n) {\n const {\n backend = (runtime: BackendRuntime) => new StateBackend(runtime),\n ptc = false,\n memoryLimitBytes = DEFAULT_MEMORY_LIMIT,\n maxStackSizeBytes = DEFAULT_MAX_STACK_SIZE,\n executionTimeoutMs = DEFAULT_EXECUTION_TIMEOUT,\n systemPrompt: customSystemPrompt = null,\n } = options;\n\n const usePtc = ptc !== false;\n const baseSystemPrompt = customSystemPrompt || REPL_SYSTEM_PROMPT;\n\n let cachedPtcPrompt: string | null = null;\n\n let ptcTools: StructuredToolInterface[] = [];\n\n function filterToolsForPtc(\n allTools: StructuredToolInterface[],\n ): StructuredToolInterface[] {\n if (ptc === false) return [];\n\n const candidates = allTools.filter((t) => t.name !== \"js_eval\");\n\n if (ptc === true) {\n const excluded = new Set<string>(DEFAULT_PTC_EXCLUDED_TOOLS);\n return candidates.filter((t) => !excluded.has(t.name));\n }\n\n if (Array.isArray(ptc)) {\n const included = new Set(ptc);\n return candidates.filter((t) => included.has(t.name));\n }\n\n if (\"include\" in ptc) {\n const included = new Set(ptc.include);\n return candidates.filter((t) => included.has(t.name));\n }\n\n if (\"exclude\" in ptc) {\n const excluded = new Set([...DEFAULT_PTC_EXCLUDED_TOOLS, ...ptc.exclude]);\n return candidates.filter((t) => !excluded.has(t.name));\n }\n\n return [];\n }\n\n const jsEvalTool = tool(\n async (input, config: LangGraphRunnableConfig) => {\n const threadId = config.configurable?.thread_id || DEFAULT_SESSION_ID;\n\n const runtime: BackendRuntime = {\n ...config,\n state: getCurrentTaskInput(config) || {},\n } as BackendRuntime;\n const resolvedBackend = await resolveBackend(backend, runtime);\n\n const session = ReplSession.getOrCreate(threadId, {\n memoryLimitBytes,\n maxStackSizeBytes,\n backend: resolvedBackend,\n tools: ptcTools,\n });\n\n const result = await session.eval(input.code, executionTimeoutMs);\n await session.flushWrites(resolvedBackend);\n\n return formatReplResult(result);\n },\n {\n name: \"js_eval\",\n description: dedent`\n Evaluate TypeScript/JavaScript code in a sandboxed REPL. State persists across calls.\n Use readFile(path) and writeFile(path, content) for file access.\n Use console.log() for output. Returns the result of the last expression.\n `,\n schema: z.object({\n code: z\n .string()\n .describe(\n \"TypeScript/JavaScript code to evaluate in the sandboxed REPL\",\n ),\n }),\n },\n );\n\n return createMiddleware({\n name: \"QuickJSMiddleware\",\n tools: [jsEvalTool],\n wrapModelCall: async (request, handler) => {\n const agentTools = (request.tools || []) as StructuredToolInterface[];\n ptcTools = usePtc ? filterToolsForPtc(agentTools) : [];\n\n if (ptcTools.length > 0 && !cachedPtcPrompt) {\n cachedPtcPrompt = await generatePtcPrompt(ptcTools);\n }\n\n const systemMessage = request.systemMessage\n .concat(baseSystemPrompt)\n .concat(cachedPtcPrompt || \"\");\n return handler({ ...request, systemMessage });\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAQA,SAAgB,YAAY,MAAsB;AAChD,QAAO,KAAK,QAAQ,iBAAiB,GAAG,MAAM,EAAE,aAAa,CAAC;;;;;AAwBhE,SAAgB,iBAAiB,QAA4B;CAC3D,MAAM,QAAkB,EAAE;AAE1B,KAAI,OAAO,KAAK,SAAS,EACvB,OAAM,KAAK,OAAO,KAAK,KAAK,KAAK,CAAC;AAGpC,KAAI,OAAO;MACL,OAAO,UAAU,KAAA,GAAW;GAC9B,MAAM,YACJ,OAAO,OAAO,UAAU,WACpB,OAAO,QACP,KAAK,UAAU,OAAO,OAAO,MAAM,EAAE;AAC3C,SAAM,KAAK,KAAK,YAAY;;YAErB,OAAO,OAAO;EACvB,MAAM,UAAU,OAAO,MAAM,QAAQ;EACrC,MAAM,SAAS,OAAO,MAAM,WAAW;AACvC,QAAM,KAAK,GAAG,QAAQ,IAAI,SAAS;AACnC,MAAI,OAAO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iB;EACtB,MAAM;EACN,OAAO,CAzCU,KACjB,OAAO,OAAO,WAAoC;GAChD,MAAM,WAAW,OAAO,cAAc,aAAA;GAMtC,MAAM,kBAAkB,MAAM,eAAe,SAJb;IAC9B,GAAG;IACH,OAAO,oBAAoB,OAAO,IAAI,EAAE;IACzC,CAC6D;GAE9D,MAAM,UAAU,YAAY,YAAY,UAAU;IAChD;IACA;IACA,SAAS;IACT,OAAO;IACR,CAAC;GAEF,MAAM,SAAS,MAAM,QAAQ,KAAK,MAAM,MAAM,mBAAmB;AACjE,SAAM,QAAQ,YAAY,gBAAgB;AAE1C,UAAO,iBAAiB,OAAO;KAEjC;GACE,MAAM;GACN,aAAa,MAAM;;;;;GAKnB,QAAQ,EAAE,OAAO,EACf,MAAM,EACH,QAAQ,CACR,SACC,+DACD,EACJ,CAAC;GACH,CACF,CAIoB;EACnB,eAAe,OAAO,SAAS,YAAY;GACzC,MAAM,aAAc,QAAQ,SAAS,EAAE;AACvC,cAAW,SAAS,kBAAkB,WAAW,GAAG,EAAE;AAEtD,OAAI,SAAS,SAAS,KAAK,CAAC,gBAC1B,mBAAkB,MAAM,kBAAkB,SAAS;GAGrD,MAAM,gBAAgB,QAAQ,cAC3B,OAAO,iBAAiB,CACxB,OAAO,mBAAmB,GAAG;AAChC,UAAO,QAAQ;IAAE,GAAG;IAAS;IAAe,CAAC;;EAEhD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["program"],"sources":["../src/transform.ts","../src/skills.ts","../src/errors.ts","../src/utils.ts","../src/session.ts","../src/middleware.ts"],"sourcesContent":["/**\n * AST-based code transform pipeline for the REPL.\n *\n * Transforms TypeScript/JavaScript code into plain JS that can be\n * evaluated inside QuickJS with proper state persistence:\n *\n * 1. Parse with acorn + acorn-typescript (handles TS syntax)\n * 2. Strip TypeScript-only nodes (type annotations, interfaces, etc.)\n * 3. Hoist top-level declarations to globalThis for cross-eval persistence\n * 4. Auto-return the last expression\n * 5. Wrap in async IIFE so top-level await works\n */\n\nimport { Parser } from \"acorn\";\nimport { tsPlugin } from \"@sveltejs/acorn-typescript\";\nimport { walk } from \"estree-walker\";\nimport MagicString from \"magic-string\";\nimport type {\n Node,\n Identifier,\n VariableDeclaration as EstreeVariableDeclaration,\n VariableDeclarator as EstreeVariableDeclarator,\n} from \"estree\";\n\nconst TSParser = Parser.extend(tsPlugin());\n\ntype AcornNode = Node & { start: number; end: number };\ntype AcornExpressionStatement = AcornNode & {\n type: \"ExpressionStatement\";\n expression: AcornNode;\n};\ntype AcornVariableDeclaration = EstreeVariableDeclaration & {\n start: number;\n end: number;\n declarations: AcornVariableDeclarator[];\n};\ntype AcornVariableDeclarator = EstreeVariableDeclarator & {\n start: number;\n end: number;\n id: AcornNode;\n init: AcornNode | null;\n};\n\n/**\n * Transform code for REPL evaluation.\n *\n * - Strips TypeScript syntax\n * - Hoists top-level variable declarations to globalThis\n * - Auto-returns the last expression\n * - Wraps in async IIFE for top-level await support\n */\nexport function transformForEval(code: string): string {\n let ast: AcornNode;\n try {\n ast = TSParser.parse(code, {\n ecmaVersion: \"latest\" as any,\n sourceType: \"module\",\n locations: true,\n }) as unknown as AcornNode;\n } catch {\n // If parsing fails, return the code as-is and let QuickJS report the error\n return `(async () => {\\n${code}\\n})()`;\n }\n\n const s = new MagicString(code);\n const program = ast as unknown as { body: AcornNode[] };\n const topLevelNodes = program.body;\n for (let i = 0; i < topLevelNodes.length; i++) {\n const node = topLevelNodes[i];\n\n // Remove TypeScript-only top-level declarations\n if (isTSOnlyNode(node)) {\n s.remove(node.start, node.end);\n continue;\n }\n\n // Remove import/export declarations (not supported in QuickJS eval)\n if (\n node.type === \"ImportDeclaration\" ||\n node.type === \"ExportNamedDeclaration\" ||\n node.type === \"ExportDefaultDeclaration\" ||\n node.type === \"ExportAllDeclaration\"\n ) {\n s.remove(node.start, node.end);\n continue;\n }\n\n // Hoist top-level variable declarations\n if (node.type === \"VariableDeclaration\") {\n hoistDeclaration(s, node as unknown as AcornVariableDeclaration);\n continue;\n }\n\n // Hoist function/class declarations to globalThis for cross-eval persistence\n if (\n node.type === \"FunctionDeclaration\" ||\n node.type === \"ClassDeclaration\"\n ) {\n stripTypeAnnotations(s, node);\n const name = (node as any).id?.name;\n if (name) {\n s.appendRight(node.end, `\\nglobalThis.${name} = ${name};`);\n }\n continue;\n }\n }\n\n // Strip type annotations from within expressions/statements\n for (const node of topLevelNodes) {\n if (isTSOnlyNode(node)) continue;\n if (\n node.type === \"ImportDeclaration\" ||\n node.type === \"ExportNamedDeclaration\" ||\n node.type === \"ExportDefaultDeclaration\" ||\n node.type === \"ExportAllDeclaration\"\n )\n continue;\n if (node.type !== \"VariableDeclaration\") {\n walk(node as any, {\n enter(n: any) {\n stripTypeAnnotationFromNode(s, n);\n },\n });\n }\n }\n\n // Auto-return the last expression. We insert `return (` before the\n // ExpressionStatement (to preserve any grouping parens like `({...})`),\n // but close `)` after the inner expression — not after the statement —\n // so any trailing semicolon stays outside: `return (expr);` not `return (expr;)`.\n const lastNode = findLastNonEmptyNode(topLevelNodes, s);\n if (lastNode && isExpression(lastNode)) {\n const { expression } = lastNode as AcornExpressionStatement;\n s.prependLeft(lastNode.start, \"return (\");\n s.appendRight(expression.end, \")\");\n }\n\n // Wrap in async IIFE\n s.prepend(\"(async () => {\\n\");\n s.append(\"\\n})()\");\n\n return s.toString();\n}\n\nfunction isTSOnlyNode(node: AcornNode): boolean {\n const t = node.type as string;\n return (\n t === \"TSTypeAliasDeclaration\" ||\n t === \"TSInterfaceDeclaration\" ||\n t === \"TSEnumDeclaration\" ||\n t === \"TSModuleDeclaration\" ||\n t === \"TSDeclareFunction\" ||\n t.startsWith(\"TS\")\n );\n}\n\n/**\n * Rewrite a top-level VariableDeclaration to globalThis assignments.\n *\n * `const x = 1, y = 2` → `globalThis.x = 1; globalThis.y = 2`\n *\n */\nfunction hoistDeclaration(\n s: MagicString,\n decl: AcornVariableDeclaration,\n): void {\n const parts: string[] = [];\n\n for (const d of decl.declarations) {\n const id = d.id as AcornNode;\n if (id.type === \"Identifier\") {\n const initCode = d.init ? extractCleanInit(s, d) : \"undefined\";\n parts.push(\n `globalThis.${(id as unknown as Identifier).name} = ${initCode}`,\n );\n } else if (id.type === \"ObjectPattern\" || id.type === \"ArrayPattern\") {\n const bindings = extractBindingNames(d.id as any);\n const initCode = d.init ? extractCleanInit(s, d) : \"undefined\";\n const patternCode = extractCleanSource(s, d.id as AcornNode);\n parts.push(`var ${patternCode} = ${initCode}`);\n for (const name of bindings) {\n parts.push(`globalThis.${name} = ${name}`);\n }\n }\n }\n\n s.overwrite(decl.start, decl.end, parts.join(\"; \") + \";\");\n}\n\n/**\n * Extract the initializer code, stripping TypeScript annotations from\n * within the expression (e.g. `as Type`, generics, parameter types in\n * arrow functions).\n */\nfunction extractCleanInit(s: MagicString, d: AcornVariableDeclarator): string {\n if (!d.init) return \"undefined\";\n return extractCleanSource(s, d.init as AcornNode);\n}\n\nfunction extractBindingNames(pattern: any): string[] {\n const names: string[] = [];\n if (pattern.type === \"Identifier\") {\n if (pattern.name) names.push(pattern.name);\n } else if (pattern.type === \"ObjectPattern\") {\n for (const prop of pattern.properties || []) {\n if (prop.type === \"RestElement\") {\n names.push(...extractBindingNames(prop.argument));\n } else {\n names.push(...extractBindingNames(prop.value));\n }\n }\n } else if (pattern.type === \"ArrayPattern\") {\n for (const el of pattern.elements || []) {\n if (el) names.push(...extractBindingNames(el));\n }\n } else if (pattern.type === \"RestElement\") {\n names.push(...extractBindingNames(pattern.argument));\n } else if (pattern.type === \"AssignmentPattern\") {\n names.push(...extractBindingNames(pattern.left));\n }\n return names;\n}\n\nfunction stripTypeAnnotations(s: MagicString, node: AcornNode): void {\n walk(node as any, {\n enter(n: any) {\n stripTypeAnnotationFromNode(s, n);\n },\n });\n}\n\nfunction stripTypeAnnotationFromNode(s: MagicString, n: any, offset = 0): void {\n // Type annotations on parameters, variables, return types\n if (n.typeAnnotation && n.typeAnnotation.start != null) {\n s.remove(n.typeAnnotation.start - offset, n.typeAnnotation.end - offset);\n }\n // Return type on functions\n if (n.returnType && n.returnType.start != null) {\n s.remove(n.returnType.start - offset, n.returnType.end - offset);\n }\n // Type parameters (generics)\n if (n.typeParameters && n.typeParameters.start != null) {\n s.remove(n.typeParameters.start - offset, n.typeParameters.end - offset);\n }\n // Type arguments on calls\n if (n.typeArguments && n.typeArguments.start != null) {\n s.remove(n.typeArguments.start - offset, n.typeArguments.end - offset);\n }\n // `as` expressions: keep the expression, remove `as Type`\n if (n.type === \"TSAsExpression\" && n.expression) {\n s.remove(n.expression.end - offset, n.end - offset);\n }\n // Non-null assertion: `x!` → `x`\n if (n.type === \"TSNonNullExpression\" && n.expression) {\n s.remove(n.expression.end - offset, n.end - offset);\n }\n // Satisfies expression: `x satisfies Type` → `x`\n if (n.type === \"TSSatisfiesExpression\" && n.expression) {\n s.remove(n.expression.end - offset, n.end - offset);\n }\n}\n\n/**\n * Extract a clean JS source string from an AST node, stripping all\n * TypeScript annotations. Works on a copy so the main MagicString is\n * not mutated.\n */\nfunction extractCleanSource(s: MagicString, node: AcornNode): string {\n const offset = node.start;\n const source = new MagicString(s.slice(node.start, node.end));\n walk(node as any, {\n enter(n: any) {\n stripTypeAnnotationFromNode(source, n, offset);\n },\n });\n return source.toString();\n}\n\nfunction findLastNonEmptyNode(\n nodes: AcornNode[],\n s: MagicString,\n): AcornNode | null {\n for (let i = nodes.length - 1; i >= 0; i--) {\n const node = nodes[i];\n // Skip nodes that were fully removed\n const slice = s.slice(node.start, node.end).trim();\n if (slice === \"\" || slice === \";\") continue;\n return node;\n }\n return null;\n}\n\nfunction isExpression(node: AcornNode): boolean {\n return node.type === \"ExpressionStatement\";\n}\n\n/**\n * Strip TypeScript type syntax from an ES-module source so QuickJS can\n * evaluate it as a standard JS module.\n *\n * Unlike `transformForEval`, this keeps `import`/`export` declarations,\n * does not hoist to `globalThis`, and does not wrap in an IIFE.\n * On parse failure the original source is returned unchanged.\n */\nexport function stripTypeSyntax(code: string): string {\n let ast: AcornNode;\n try {\n ast = TSParser.parse(code, {\n ecmaVersion: \"latest\",\n sourceType: \"module\",\n locations: true,\n }) as unknown as AcornNode;\n } catch {\n // Return the original source unchanged rather than throwing or returning an empty string.\n // We don't know why the parse failed - it could be a valid plain-JS file that hit an\n // acorn-typescript incompatibility, in which case returning it unchanged lets QuickJS\n // evaluate it correctly. If it's genuinely broken TS, QuickJS will surface the parse error\n // at evaluation time with a useful line/column.\n return code;\n }\n\n const magicString = new MagicString(code);\n const program = ast as unknown as { body: AcornNode[] };\n\n for (const node of program.body) {\n if (isTSOnlyNode(node)) {\n magicString.remove(node.start, node.end);\n continue;\n }\n\n walk(node as any, {\n enter(n: any) {\n stripTypeAnnotationFromNode(magicString, n);\n },\n });\n }\n\n return magicString.toString();\n}\n","import * as posix from \"node:path/posix\";\n\nimport {\n adaptBackendProtocol,\n BackendProtocolV2,\n type AnyBackendProtocol,\n type FileDownloadResponse,\n type FileInfo,\n type SkillMetadata,\n} from \"deepagents\";\n\nimport { stripTypeSyntax } from \"./transform.js\";\n\n/**\n * File extensions the loader will enumerate from a skill directory.\n */\nexport const SKILL_MODULE_EXTENSIONS = [\n \".js\",\n \".mjs\",\n \".cjs\",\n \".ts\",\n \".mts\",\n \".cts\",\n \".jsx\",\n \".tsx\",\n];\n\n/**\n * Hard cap on total bytes pulled for one skill's bundle (1 MiB).\n */\nexport const MAX_SKILL_BUNDLE_BYTES = 1 * 1024 * 1024;\n\n/**\n * Validates a skill name against the spec's kebab-case rule.\n */\nconst SKILL_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n/**\n * Matches `\"@/skills/<name>\"` or `'@/skills/<name>'` references in source.\n * Template literals and computed specifiers are not caught.\n */\nconst SKILL_SPECIFIER_RE = /[\"']@\\/skills\\/([a-z0-9]+(?:-[a-z0-9]+)*)[\"']/g;\n\n/**\n * Install-ready state for a single skill, produced by `loadSkill`.\n */\nexport interface LoadedSkill {\n /**\n * Spec-validated kebab-case skill name.\n */\n name: string;\n\n /**\n * Bare specifier the skill installs under: `\"@/skills/<name>\"`.\n */\n specifier: string;\n\n /**\n * Relative POSIX path of the entrypoint file (e.g. `\"index.ts\"`).\n */\n entryRel: string;\n\n /**\n * File contents keyed by relative POSIX path, with TS syntax stripped.\n */\n files: Map<string, string>;\n}\n\n/**\n * List every code-extension file under `skillDir` (recursive).\n */\nasync function enumerateCodeFiles(\n backend: BackendProtocolV2,\n skillDir: string,\n skillName: string,\n): Promise<string[]> {\n const seen = new Set<string>();\n for (const ext of SKILL_MODULE_EXTENSIONS) {\n const result = await backend.glob(`**/*${ext}`, skillDir);\n if (result.error !== undefined) {\n throw new Error(\n `Skill '${skillName}': failed to list '${skillDir}': ${result.error}`,\n );\n }\n\n const matches: FileInfo[] = result.files ?? [];\n for (const match of matches) {\n seen.add(match.path);\n }\n }\n\n return [...seen].sort();\n}\n\n/**\n * Decode download responses into [path, source] pairs.\n */\nfunction decodeFiles(\n responses: FileDownloadResponse[],\n skillName: string,\n): Array<[string, string]> {\n const decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\n const pairs: Array<[string, string]> = [];\n for (const response of responses) {\n if (response.error !== null || response.content === null) {\n throw new Error(\n `Skill '${skillName}': failed to download '${response.path}': ${response.error ?? \"no content\"}`,\n );\n }\n\n let source: string;\n try {\n source = decoder.decode(response.content);\n } catch {\n throw new Error(\n `Skill '${skillName}': file '${response.path}' is not valid UTF-8`,\n );\n }\n\n pairs.push([response.path, source]);\n }\n\n return pairs;\n}\n\n/**\n * Throws an Error when the total decoded size of all files exceeds\n * `MAX_SKILL_BUNDLE_BYTES`. Counts characters rather than bytes, which\n * over-counts multi-byte UTF-8. Intentionally errs toward rejection.\n */\nfunction validateBundleSize(\n pairs: Array<[string, string]>,\n skillName: string,\n): void {\n let total = 0;\n for (const [, source] of pairs) {\n total += source.length;\n }\n\n if (total > MAX_SKILL_BUNDLE_BYTES) {\n throw new Error(\n `Skill '${skillName}': bundle exceeds ${MAX_SKILL_BUNDLE_BYTES} bytes (total ${total})`,\n );\n }\n}\n\n/**\n * Express `absolutePath` as a POSIX-relative path under `skillDir`.\n * Throws an Error if the path escapes the skill directory which indicates\n * a backend bug, not a user error.\n */\nfunction relativeUnder(\n skillDir: string,\n absolutePath: string,\n skillName: string,\n): string {\n const rel = posix.relative(skillDir, absolutePath);\n if (rel === \"\" || rel.startsWith(\"..\")) {\n throw new Error(\n `Skill '${skillName}': file ${absolutePath} is not under '${skillDir}'`,\n );\n }\n return rel;\n}\n\n/**\n * Build the relative-path → source map, applying `stripTypeSyntax` to each file.\n */\nfunction buildFilesMap(\n skillDir: string,\n entryRel: string,\n pairs: Array<[string, string]>,\n skillName: string,\n): Map<string, string> {\n const files = new Map<string, string>();\n let entryPresent = false;\n\n for (const [absPath, source] of pairs) {\n const rel = relativeUnder(skillDir, absPath, skillName);\n files.set(rel, stripTypeSyntax(source));\n if (rel === entryRel) {\n entryPresent = true;\n }\n }\n\n if (!entryPresent) {\n throw new Error(\n `Skill '${skillName}': module path '${entryRel}' did not match any file in the skill directory`,\n );\n }\n\n return files;\n}\n\n/**\n * Build a `LoadedSkill` from a skill's metadata and a backend handle.\n *\n * Enumerates code files under the skill directory, downloads them,\n * strips TypeScript syntax, and validates the entrypoint is present.\n */\nexport async function loadSkill(\n metadata: SkillMetadata,\n backend: AnyBackendProtocol,\n): Promise<LoadedSkill> {\n const name = metadata.name;\n\n if (!SKILL_NAME_RE.test(name)) {\n throw new Error(\n `Skill name '${name}' is not a valid kebab-case identifier`,\n );\n }\n\n const entryRel = metadata.module;\n if (entryRel === undefined || entryRel === \"\") {\n throw new Error(\n `Skill '${name}' has no 'module' frontmatter key - only skills with a declared entrypoint are installable`,\n );\n }\n\n const adapted = adaptBackendProtocol(backend);\n if (adapted.downloadFiles === undefined) {\n throw new Error(\n `Skill '${name}': backend does not implement downloadFiles`,\n );\n }\n\n const skillDir = posix.dirname(metadata.path);\n const codeFiles = await enumerateCodeFiles(adapted, skillDir, name);\n if (codeFiles.length === 0) {\n throw new Error(`Skill '${name}': no JS/TS files under '${skillDir}'`);\n }\n\n const responses = await adapted.downloadFiles(codeFiles);\n const filePairs = decodeFiles(responses, name);\n validateBundleSize(filePairs, name);\n\n const files = buildFilesMap(skillDir, entryRel, filePairs, name);\n return {\n name,\n specifier: `@/skills/${name}`,\n entryRel,\n files,\n };\n}\n\n/**\n * Extract skill names referenced by `\"@/skills/<name>\"` literals in source.\n *\n * Used as a pre-eval scan so the middleware can surface `SkillNotAvailable`\n * before evaluation starts. Dynamic imports with computed specifiers are\n * not detected.\n */\nexport function scanSkillReferences(source: string): Set<string> {\n const names = new Set<string>();\n\n const matches = source.matchAll(SKILL_SPECIFIER_RE);\n for (const match of matches) {\n names.add(match[1]);\n }\n\n return names;\n}\n","/**\n * Options for constructing a {@link PTCCallBudgetExceededError}.\n */\ninterface PTCCallBudgetExceededOptions {\n /**\n * The configured per-eval PTC call limit.\n */\n limit: number;\n\n /**\n * The call number that triggered the violation (always `limit + 1`).\n */\n attempted: number;\n\n /**\n * The name of the tool function that was called over budget.\n */\n functionName: string;\n}\n\n/**\n * Thrown when a single eval exhausts its configured PTC call budget.\n */\nexport class PTCCallBudgetExceededError extends Error {\n readonly limit: number;\n readonly attempted: number;\n readonly functionName: string;\n\n constructor(options: PTCCallBudgetExceededOptions) {\n super(\n `PTC call budget exceeded (limit=${options.limit}, attempted=${options.attempted}, function=${options.functionName})`,\n );\n this.name = \"PTCCallBudgetExceededError\";\n this.limit = options.limit;\n this.attempted = options.attempted;\n this.functionName = options.functionName;\n }\n}\n","import { compile } from \"json-schema-to-typescript\";\nimport { toJsonSchema } from \"@langchain/core/utils/json_schema\";\nimport dedent from \"dedent\";\nimport type { ReplResult } from \"./types.js\";\n\n/**\n * Convert a snake_case or kebab-case string to camelCase.\n */\nexport function toCamelCase(name: string): string {\n return name.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase());\n}\n\n/**\n * Recursively collect all string values from an object, array, or primitive.\n */\nexport function collectStrings(obj: unknown): string[] {\n const result: string[] = [];\n function walk(val: unknown) {\n if (typeof val === \"string\") {\n result.push(val);\n } else if (Array.isArray(val)) {\n for (const item of val) walk(item);\n } else if (typeof val === \"object\" && val !== null) {\n for (const v of Object.values(val)) walk(v);\n }\n }\n walk(obj);\n return result;\n}\n\n/**\n * Format the result of a REPL evaluation for the agent.\n */\nexport function formatReplResult(result: ReplResult): string {\n const parts: string[] = [];\n\n if (result.logs.length > 0) {\n let logsText = result.logs.join(\"\\n\");\n if (result.logsDroppedChars > 0) {\n logsText += `\\n[truncated ${result.logsDroppedChars} chars]`;\n }\n parts.push(logsText);\n }\n\n if (result.ok) {\n if (result.value !== undefined) {\n const formatted =\n typeof result.value === \"string\"\n ? result.value\n : JSON.stringify(result.value, null, 2);\n parts.push(`→ ${formatted}`);\n }\n } else if (result.error) {\n const errName = result.error.name || \"Error\";\n const errMsg = result.error.message || \"Unknown error\";\n parts.push(`${errName}: ${errMsg}`);\n if (result.error.stack) {\n parts.push(result.error.stack);\n }\n }\n\n return parts.join(\"\\n\") || \"(no output)\";\n}\n\nexport function safeToJsonSchema(\n schema: unknown,\n): Record<string, unknown> | undefined {\n try {\n return toJsonSchema(schema as Parameters<typeof toJsonSchema>[0]) as Record<\n string,\n unknown\n >;\n } catch {\n return undefined;\n }\n}\n\nasync function schemaToInterface(\n jsonSchema: Record<string, unknown>,\n interfaceName: string,\n): Promise<string> {\n const compiled = await compile(\n { ...jsonSchema, additionalProperties: false },\n interfaceName,\n { bannerComment: \"\", additionalProperties: false },\n );\n return compiled.replace(/^export /, \"\").trimEnd();\n}\n\nexport function capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\nexport async function toolToTypeSignature(\n name: string,\n description: string,\n jsonSchema: Record<string, unknown> | undefined,\n): Promise<string> {\n const inputType = `${capitalize(name)}Input`;\n\n if (!jsonSchema || !jsonSchema.properties) {\n return dedent`\n /**\n * ${description}\n */\n async tools.${name}(input: Record<string, unknown>): Promise<string>\n `;\n }\n\n const iface = await schemaToInterface(jsonSchema, inputType);\n return dedent`\n ${iface}\n\n /**\n * ${description}\n */\n async tools.${name}(input: ${inputType}): Promise<string>\n `;\n}\n\n/**\n * Render a pre-eval error when referenced skills are not available on the agent.\n */\nexport function formatSkillNotAvailable(missing: readonly string[]): string {\n const list = [...missing].sort().join(\", \");\n return `Skills unavailable: ${list}`;\n}\n","/**\n * Core REPL engine built on quickjs-emscripten (asyncify variant).\n *\n * Host async functions (backend I/O, PTC tools) are exposed as\n * promise-returning functions inside the QuickJS guest. Guest code\n * uses `await` to consume them, enabling real concurrency via\n * `Promise.all`, `Promise.race`, etc.\n *\n * We still use the asyncify WASM variant because `evalCodeAsync` is\n * required to drive promise resolution from the host side.\n *\n * ## Architecture\n *\n * `ReplSession` is a serializable handle that can live in LangGraph state.\n * It holds an `id` that keys into a static session map. The heavy QuickJS\n * runtime is lazily started on the first `.eval()` call, making the session\n * safe across graph interrupts and checkpointing.\n */\n\nimport { shouldInterruptAfterDeadline } from \"quickjs-emscripten\";\nimport type { QuickJSHandle } from \"quickjs-emscripten\";\nimport { newQuickJSAsyncWASMModuleFromVariant } from \"quickjs-emscripten-core\";\nimport type {\n QuickJSAsyncContext,\n QuickJSAsyncRuntime,\n} from \"quickjs-emscripten-core\";\nimport type { StructuredToolInterface } from \"@langchain/core/tools\";\n\nimport { loadSkill, type LoadedSkill } from \"./skills.js\";\nimport { PTCCallBudgetExceededError } from \"./errors.js\";\nimport type { ReplSessionOptions, ReplResult, SkillsContext } from \"./types.js\";\nimport { toCamelCase } from \"./utils.js\";\nimport { transformForEval } from \"./transform.js\";\n\nexport const DEFAULT_MEMORY_LIMIT = 64 * 1024 * 1024;\nexport const DEFAULT_MAX_STACK_SIZE = 320 * 1024;\nexport const DEFAULT_EXECUTION_TIMEOUT = 5_000;\nexport const DEFAULT_SESSION_ID = \"__default__\";\nexport const DEFAULT_MAX_PTC_CALLS = 256;\nexport const DEFAULT_MAX_RESULTS_CHARS = 4000;\n\n// The variant descriptor (WASM binary + glue) is safe to share across sessions;\n// only the instantiated module carries asyncify state. Import once, instantiate per session.\nconst variantImport = import(\"@jitl/quickjs-ng-wasmfile-release-asyncify\");\n\n// Each ReplSession needs its own WASM module. The asyncify WASM variant allows only one\n// concurrent async call per module instance, and multi-file skill imports (2+ unwind/rewind\n// cycles inside a single evalCodeAsync) leave the module's asyncify state corrupted after\n// the owning runtime is disposed — new runtimes on the same module silently skip module\n// loader callbacks. A fresh instantiation per session gives each session clean asyncify state.\nasync function newAsyncModule() {\n const variant = await variantImport;\n return newQuickJSAsyncWASMModuleFromVariant(\n (variant.default ?? variant) as any,\n );\n}\n\n// After a successful asyncify unwind/rewind cycle, a rejected module loader\n// Promise causes a WASM crash (\"memory access out of bounds\"). The rejection\n// path in quickjs-emscripten's `maybeAsyncFn` catch block calls\n// `context.throw(error)` — a WASM FFI call while the asyncify stack is still\n// unwound — which corrupts memory. To avoid this, the module loader must never\n// reject. This helper returns source code that throws at evaluation time inside\n// the VM instead.\n//\n// The thrown value is a plain object (not `new Error()`) because QuickJS stores\n// Error's `name` and `message` as non-enumerable properties (per spec), which\n// causes `context.dump()` (JSON.stringify) to return `{}`.\nfunction makeErrorSource(message: string): string {\n return `throw { name: \"Error\", message: ${JSON.stringify(message)} };`;\n}\n\n/**\n * Parse a canonicalized skill specifier into `{ name, rel }`.\n * Returns `undefined` for anything that isn't a valid `@/skills/<name>` or\n * `@/skills/<name>/<rel>` shape. `rel` is absent for the bare form.\n */\nfunction parseSkillSpecifier(\n specifier: string,\n): { name: string; rel?: string } | undefined {\n const prefix = \"@/skills/\";\n if (!specifier.startsWith(prefix)) {\n return;\n }\n\n const tail = specifier.slice(prefix.length);\n const slashIdx = tail.indexOf(\"/\");\n const name = slashIdx === -1 ? tail : tail.slice(0, slashIdx);\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name)) {\n return;\n }\n\n const rel = slashIdx === -1 ? undefined : tail.slice(slashIdx + 1);\n if (rel !== undefined && rel === \"\") {\n return;\n }\n\n return { name, rel };\n}\n\n/**\n * Return the `@/skills/<name>` prefix for the skill that owns `base`, or `undefined`.\n */\nfunction matchSkillPrefix(base: string): string | undefined {\n const parsed = parseSkillSpecifier(base);\n if (parsed === undefined) {\n return;\n }\n return `@/skills/${parsed.name}`;\n}\n\n/**\n * Return the directory portion of a slash-separated specifier path.\n */\nfunction posixDirname(p: string): string {\n const idx = p.lastIndexOf(\"/\");\n if (idx === -1) {\n return \"\";\n }\n return p.slice(0, idx);\n}\n\n/**\n * POSIX join for slash-separated specifiers. Avoids `node:path/posix`\n * since session.ts is consumed in browser bundles.\n */\nfunction posixJoin(base: string, rel: string): string {\n const out: string[] = [];\n\n const segments = `${base}/${rel}`.split(\"/\");\n for (const segment of segments) {\n if (segment === \"\" || segment === \".\") {\n continue;\n }\n\n if (segment === \"..\") {\n out.pop();\n continue;\n }\n\n out.push(segment);\n }\n\n return out.join(\"/\");\n}\n\n/**\n * Fixed-size character buffer for capturing console output from the QuickJS VM.\n *\n * Lines are accumulated up to `maxChars`. Once the cap is reached, excess\n * characters are counted as dropped rather than silently discarded without\n * attribution, so callers can surface a truncation notice to the user.\n */\nclass ConsoleBuffer {\n private readonly maxChars: number;\n private buffer: string = \"\";\n private droppedChars: number = 0;\n\n constructor(maxChars: number) {\n this.maxChars = Math.max(maxChars, 0);\n }\n\n /**\n * Append `line` to the buffer.\n *\n * If the buffer is already full the entire line is counted as dropped.\n * If `line` partially fits, the fitting prefix is stored and the remainder\n * is counted as dropped.\n */\n append(line: string): void {\n const remaining = this.maxChars - this.buffer.length;\n if (remaining <= 0) {\n this.droppedChars += line.length;\n return;\n }\n\n if (line.length <= remaining) {\n this.buffer += line;\n } else {\n this.buffer += line.slice(0, remaining);\n this.droppedChars += line.length - remaining;\n }\n }\n\n /**\n * Return the buffered output and dropped-character count as `[buffered,\n * droppedChars]`, then reset both to zero.\n */\n drain(): [string, number] {\n const out = this.buffer;\n const dropped = this.droppedChars;\n\n this.buffer = \"\";\n this.droppedChars = 0;\n\n return [out, dropped];\n }\n}\n\n/**\n * Sandboxed JavaScript REPL session backed by QuickJS WASM.\n *\n * Serializable — holds an `id` that keys into a static session map.\n * The QuickJS runtime is lazily started on the first `.eval()` call\n * and reconnected if a session with the same id already exists.\n * This makes it safe to store in LangGraph state across interrupts.\n */\nexport class ReplSession {\n private static sessions = new Map<string, ReplSession>();\n\n readonly id: string;\n\n private runtime: QuickJSAsyncRuntime | null = null;\n private context: QuickJSAsyncContext | null = null;\n private consoleBuffer: ConsoleBuffer = new ConsoleBuffer(\n DEFAULT_MAX_RESULTS_CHARS,\n );\n private options: ReplSessionOptions;\n private skillsContext: SkillsContext | undefined;\n private skillsLoaded: Map<string, LoadedSkill> = new Map();\n private skillsFailed: Map<string, Error> = new Map();\n private readonly maxPtcCalls: number | null;\n private ptcCallsRemaining: number | null = null;\n\n constructor(id: string, options: ReplSessionOptions = {}) {\n this.id = id;\n this.options = options;\n this.maxPtcCalls =\n options.maxPtcCalls !== undefined\n ? options.maxPtcCalls\n : DEFAULT_MAX_PTC_CALLS;\n }\n\n private async ensureStarted(): Promise<void> {\n if (this.runtime) return;\n\n const {\n memoryLimitBytes = DEFAULT_MEMORY_LIMIT,\n maxStackSizeBytes = DEFAULT_MAX_STACK_SIZE,\n tools,\n skillsEnabled = false,\n maxResultChars = DEFAULT_MAX_RESULTS_CHARS,\n captureConsole = true,\n } = this.options;\n\n const asyncModule = await newAsyncModule();\n const runtime: QuickJSAsyncRuntime = asyncModule.newRuntime();\n runtime.setMemoryLimit(memoryLimitBytes);\n runtime.setMaxStackSize(maxStackSizeBytes);\n\n const context: QuickJSAsyncContext = runtime.newContext();\n this.runtime = runtime;\n this.context = context;\n\n this.consoleBuffer = new ConsoleBuffer(maxResultChars);\n if (captureConsole) {\n this.setupConsole();\n }\n\n if (tools !== undefined && tools.length > 0) {\n this.injectTools(tools);\n }\n\n if (skillsEnabled) {\n this.installModuleLoader();\n }\n }\n\n /**\n * Load the skill into cache on first access and replay cached errors.\n */\n private async ensureSkillLoaded(name: string): Promise<LoadedSkill> {\n const cached = this.skillsLoaded.get(name);\n if (cached !== undefined) {\n return cached;\n }\n\n const cachedError = this.skillsFailed.get(name);\n if (cachedError !== undefined) {\n throw cachedError;\n }\n\n const ctx = this.skillsContext;\n if (ctx === undefined) {\n throw new Error(\n `Skill '${name}' referenced but skills are not configured for this session`,\n );\n }\n\n const metadata = ctx.metadata.find((m) => m.name === name);\n if (metadata === undefined) {\n throw new Error(\n `Skill '${name}' referenced but not available on this agent`,\n );\n }\n\n try {\n const loaded = await loadSkill(metadata, ctx.backend);\n this.skillsLoaded.set(name, loaded);\n return loaded;\n } catch (err) {\n this.skillsFailed.set(name, err as Error);\n throw err;\n }\n }\n\n private async resolveSpecifier(specifier: string): Promise<string> {\n const parsed = parseSkillSpecifier(specifier);\n if (parsed === undefined) {\n return makeErrorSource(`Module not found: ${specifier}`);\n }\n\n let loaded: LoadedSkill;\n try {\n loaded = await this.ensureSkillLoaded(parsed.name);\n } catch (err) {\n return makeErrorSource((err as Error).message ?? String(err));\n }\n\n if (parsed.rel === undefined) {\n const source = loaded.files.get(loaded.entryRel);\n if (source === undefined) {\n return makeErrorSource(\n `Skill '${parsed.name}': entrypoint '${loaded.entryRel}' missing from bundle`,\n );\n }\n return source;\n }\n\n const source = loaded.files.get(parsed.rel);\n if (source === undefined) {\n return makeErrorSource(\n `Skill '${parsed.name}': '${parsed.rel}' not found in bundle`,\n );\n }\n\n return source;\n }\n\n /**\n * Canonicalize an `import` specifier. Bare specifiers pass through;\n * relative specifiers are resolved against the importing module's path.\n * Traversal out of a skill's `@/skills/<name>/` namespace is rejected.\n */\n private normalizeSpecifier(base: string, requested: string): string {\n const isRelative =\n requested.startsWith(\"./\") || requested.startsWith(\"../\");\n if (!isRelative) {\n return requested;\n }\n\n // A bare skill specifier like \"@/skills/my-skill\" has no file component, so\n // posixDirname would return \"@/skills\". Treat the bare specifier itself as\n // the directory so that \"./lib/math.js\" resolves to \"@/skills/my-skill/lib/math.js\".\n const parsed = parseSkillSpecifier(base);\n const baseDir =\n parsed !== undefined && parsed.rel === undefined\n ? base\n : posixDirname(base);\n const resolved = posixJoin(baseDir, requested);\n\n const skillPrefix = matchSkillPrefix(base);\n if (skillPrefix === undefined) {\n return resolved;\n }\n\n if (!resolved.startsWith(`${skillPrefix}/`)) {\n return `__resolve_error__:${requested} escapes ${skillPrefix}`;\n }\n\n return resolved;\n }\n\n /**\n * Wire the QuickJS module loader and normalizer on this session's runtime.\n */\n private installModuleLoader(): void {\n if (this.runtime === null) {\n return;\n }\n\n this.runtime.setModuleLoader(\n async (specifier: string) => this.resolveSpecifier(specifier),\n (base: string, requested: string) =>\n this.normalizeSpecifier(base, requested),\n );\n }\n\n /**\n * Initialise the per-eval PTC counter. Called at the top of every `eval()`.\n */\n private resetPtcBudget(): void {\n this.ptcCallsRemaining =\n this.maxPtcCalls === null ? null : this.maxPtcCalls;\n }\n\n /**\n * Decrement the PTC call counter and throw if the budget is exhausted.\n * `null` budget means unlimited — returns immediately without decrementing.\n */\n private consumePtcBudget(functionName: string): void {\n if (this.ptcCallsRemaining === null) {\n return;\n }\n\n if (this.ptcCallsRemaining > 0) {\n this.ptcCallsRemaining--;\n return;\n }\n\n const limit = this.maxPtcCalls ?? 0;\n throw new PTCCallBudgetExceededError({\n limit,\n attempted: limit + 1,\n functionName,\n });\n }\n\n /**\n * Get or create a session for the given id.\n *\n * Sessions are deduped by id — calling `getOrCreate` twice with the\n * same id returns the same instance. The QuickJS runtime is lazily\n * started on the first `.eval()` call.\n */\n static getOrCreate(\n id: string,\n options: ReplSessionOptions = {},\n ): ReplSession {\n const existing = ReplSession.sessions.get(id);\n if (existing) {\n return existing;\n }\n\n const session = new ReplSession(id, options);\n ReplSession.sessions.set(id, session);\n return session;\n }\n\n /**\n * Retrieve an existing session by id, or null if none exists.\n */\n static get(id: string): ReplSession | null {\n return ReplSession.sessions.get(id) ?? null;\n }\n\n /**\n * Returns true if any session exists whose key equals `threadId` or starts\n * with `threadId:`. Useful for tests that need to confirm a session was\n * created without knowing the full `threadId:middlewareId` key.\n */\n static hasAnyForThread(threadId: string): boolean {\n const prefix = `${threadId}:`;\n for (const key of ReplSession.sessions.keys()) {\n if (key === threadId || key.startsWith(prefix)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Dispose and remove the session with the given key, if it exists.\n */\n static deleteSession(key: string): void {\n const session = ReplSession.sessions.get(key);\n if (session) {\n session.dispose();\n }\n }\n\n /**\n * Push the current skills metadata + backend into the session.\n * Called by the middleware once per `eval` invocation, before eval runs.\n * Pass `undefined` to clear the context (no skill imports will resolve).\n */\n setSkillsContext(ctx?: SkillsContext): void {\n this.skillsContext = ctx;\n }\n\n /**\n * Evaluate code in this session.\n *\n * Lazily starts the QuickJS runtime on the first call. Code is\n * transformed via an AST pipeline that strips TypeScript syntax,\n * hoists top-level declarations to globalThis for cross-eval\n * persistence, auto-returns the last expression, and wraps in an\n * async IIFE.\n */\n async eval(code: string, timeoutMs: number): Promise<ReplResult> {\n await this.ensureStarted();\n const runtime = this.runtime!;\n const context = this.context!;\n\n const drainLogs = (): { logs: string[]; logsDroppedChars: number } => {\n const [raw, dropped] = this.consoleBuffer.drain();\n return {\n logs: raw.length > 0 ? raw.split(\"\\n\").filter((l) => l.length > 0) : [],\n logsDroppedChars: dropped,\n };\n };\n\n this.resetPtcBudget();\n try {\n if (timeoutMs >= 0) {\n runtime.setInterruptHandler(\n shouldInterruptAfterDeadline(Date.now() + timeoutMs),\n );\n } else {\n runtime.setInterruptHandler(() => false);\n }\n\n const transformed = transformForEval(code);\n const result = await context.evalCodeAsync(transformed);\n\n if (result.error) {\n const error = context.dump(result.error);\n result.error.dispose();\n return { ok: false, error, ...drainLogs() };\n }\n\n const promiseState = context.getPromiseState(result.value);\n\n if (promiseState.type === \"fulfilled\") {\n if (promiseState.notAPromise) {\n const value = context.dump(result.value);\n result.value.dispose();\n return { ok: true, value, ...drainLogs() };\n }\n const value = context.dump(promiseState.value);\n promiseState.value.dispose();\n result.value.dispose();\n return { ok: true, value, ...drainLogs() };\n }\n\n if (promiseState.type === \"rejected\") {\n const error = context.dump(promiseState.error);\n promiseState.error.dispose();\n result.value.dispose();\n return { ok: false, error, ...drainLogs() };\n }\n\n const noTimeout = timeoutMs < 0;\n const deadline = noTimeout ? Infinity : Date.now() + timeoutMs;\n while (noTimeout || Date.now() < deadline) {\n context.runtime.executePendingJobs();\n const state = context.getPromiseState(result.value);\n if (state.type === \"fulfilled\") {\n const value = context.dump(state.value);\n state.value.dispose();\n result.value.dispose();\n return { ok: true, value, ...drainLogs() };\n }\n if (state.type === \"rejected\") {\n const error = context.dump(state.error);\n state.error.dispose();\n result.value.dispose();\n return { ok: false, error, ...drainLogs() };\n }\n await new Promise((r) => setTimeout(r, 1));\n }\n\n result.value.dispose();\n return {\n ok: false,\n error: { message: \"Promise timed out — execution interrupted\" },\n ...drainLogs(),\n };\n } finally {\n this.ptcCallsRemaining = null;\n }\n }\n\n dispose(): void {\n try {\n this.context?.dispose();\n } catch {\n /* may already be disposed */\n }\n try {\n this.runtime?.dispose();\n } catch {\n /* may already be disposed */\n }\n this.runtime = null;\n this.context = null;\n ReplSession.sessions.delete(this.id);\n }\n\n toJSON(): { id: string } {\n return { id: this.id };\n }\n\n static fromJSON(data: { id: string }): ReplSession {\n return ReplSession.sessions.get(data.id) ?? new ReplSession(data.id);\n }\n\n /**\n * Clear the static session cache. Useful for testing.\n * @internal\n */\n static clearCache(): void {\n for (const session of ReplSession.sessions.values()) {\n session.dispose();\n }\n ReplSession.sessions.clear();\n }\n\n private setupConsole(): void {\n const context = this.context!;\n const consoleHandle = context.newObject();\n for (const method of [\"log\", \"warn\", \"error\", \"info\", \"debug\"] as const) {\n const fnHandle = context.newFunction(\n method,\n (...args: QuickJSHandle[]) => {\n const nativeArgs = args.map((a: QuickJSHandle) => context.dump(a));\n const formatted = nativeArgs\n .map((a: unknown) =>\n typeof a === \"object\" && a !== null\n ? JSON.stringify(a)\n : String(a),\n )\n .join(\" \");\n const line =\n method === \"log\" || method === \"info\" || method === \"debug\"\n ? formatted\n : `[${method}] ${formatted}`;\n this.consoleBuffer.append(line + \"\\n\");\n },\n );\n context.setProp(consoleHandle, method, fnHandle);\n fnHandle.dispose();\n }\n context.setProp(context.global, \"console\", consoleHandle);\n consoleHandle.dispose();\n }\n\n private injectTools(tools: StructuredToolInterface[]): void {\n const context = this.context!;\n const toolsNs = context.newObject();\n\n for (const t of tools) {\n const camelName = toCamelCase(t.name);\n const fnHandle = context.newFunction(\n camelName,\n (inputHandle: QuickJSHandle) => {\n const input = context.dump(inputHandle);\n const promise = context.newPromise();\n (async () => {\n try {\n this.consumePtcBudget(camelName);\n const rawInput =\n typeof input === \"object\" && input !== null ? input : {};\n const result = await t.invoke(rawInput);\n const val = context.newString(\n typeof result === \"string\" ? result : JSON.stringify(result),\n );\n promise.resolve(val);\n val.dispose();\n } catch (e: unknown) {\n const msg =\n e != null && typeof (e as Error).message === \"string\"\n ? (e as Error).message\n : String(e);\n const err = context.newError(`Tool '${t.name}' failed: ${msg}`);\n promise.reject(err);\n err.dispose();\n }\n promise.settled.then(context.runtime.executePendingJobs);\n })();\n return promise.handle;\n },\n );\n context.setProp(toolsNs, camelName, fnHandle);\n fnHandle.dispose();\n }\n\n context.setProp(context.global, \"tools\", toolsNs);\n toolsNs.dispose();\n }\n}\n","/**\n * REPL middleware for deepagents.\n *\n * Provides an `eval` tool that runs JavaScript in a WASM-sandboxed QuickJS\n * interpreter. Supports:\n * - Persistent state across evaluations (true REPL)\n * - Programmatic tool calling (PTC) — expose agent or custom tools inside the REPL\n */\n\nimport {\n createMiddleware,\n tool,\n type AgentMiddleware as _AgentMiddleware,\n} from \"langchain\";\nimport { z } from \"zod/v4\";\nimport type { StructuredToolInterface } from \"@langchain/core/tools\";\n\nimport dedent from \"dedent\";\nimport { getCurrentTaskInput } from \"@langchain/langgraph\";\nimport {\n resolveBackend,\n type AnyBackendProtocol,\n type BackendFactory,\n type SkillMetadata,\n} from \"deepagents\";\nimport type { REPLMiddlewareOptions } from \"./types.js\";\nimport {\n ReplSession,\n DEFAULT_EXECUTION_TIMEOUT,\n DEFAULT_MEMORY_LIMIT,\n DEFAULT_MAX_STACK_SIZE,\n DEFAULT_SESSION_ID,\n DEFAULT_MAX_PTC_CALLS,\n DEFAULT_MAX_RESULTS_CHARS,\n} from \"./session.js\";\nimport {\n formatReplResult,\n formatSkillNotAvailable,\n toCamelCase,\n toolToTypeSignature,\n safeToJsonSchema,\n} from \"./utils.js\";\nimport { scanSkillReferences } from \"./skills.js\";\n\n/**\n * These type-only imports are required for TypeScript's type inference to work\n * correctly with the langchain/langgraph middleware system. Without them, certain\n * generic type parameters fail to resolve properly, causing runtime issues with\n * tool schemas and message types.\n */\nimport type * as _zodTypes from \"@langchain/core/utils/types\";\nimport type * as _zodMeta from \"@langchain/langgraph/zod\";\nimport type * as _messages from \"@langchain/core/messages\";\nimport { LangGraphRunnableConfig } from \"@langchain/langgraph\";\n\nconst DEFAULT_TOOL_NAME = \"eval\";\n\nfunction renderReplSystemPrompt(opts: {\n toolName: string;\n timeout: number;\n memoryLimitMb: number;\n}): string {\n return dedent`\n ### Interpreter\n\n An \\`${opts.toolName}\\` tool is available. It runs JavaScript in a persistent REPL.\n - State (variables, functions) persists across tool calls within a single turn of conversation. They DO NOT persist across multiple turns.\n - Top-level \\`await\\` works; Promises resolve before the call returns.\n - Sandboxed: no filesystem, no stdlib, no network, no real clock, no \\`fetch\\`, no \\`require\\`.\n - Timeout: ${opts.timeout}s per call. Memory: ${opts.memoryLimitMb} MB total.\n - \\`console.log\\` output is captured and returned alongside the result.\n `;\n}\n\n/**\n * Generate the PTC API Reference section for the system prompt.\n */\nexport async function generatePtcPrompt(\n tools: StructuredToolInterface[],\n): Promise<string> {\n if (tools.length === 0) return \"\";\n\n const signatures = await Promise.all(\n tools.map((t) => {\n const jsonSchema = t.schema ? safeToJsonSchema(t.schema) : undefined;\n return toolToTypeSignature(\n toCamelCase(t.name),\n t.description,\n jsonSchema,\n );\n }),\n );\n\n return dedent`\n\n ### API Reference — \\`tools\\` namespace\n\n The following agent tools are callable as async functions inside the REPL.\n Each takes a single object argument and returns a Promise that resolves to a string.\n Use \\`await\\` to call them. Promise APIs like \\`Promise.all\\` are also available.\n\n **Example usage:**\n \\`\\`\\`javascript\n // Call a tool\n const result = await tools.searchWeb({ query: \"QuickJS tutorial\" });\n console.log(result);\n\n // Concurrent calls\n const [a, b] = await Promise.all([\n tools.fetchData({ url: \"https://api.example.com/a\" }),\n tools.fetchData({ url: \"https://api.example.com/b\" }),\n ]);\n \\`\\`\\`\n\n **Available functions:**\n \\`\\`\\`typescript\n ${signatures.join(\"\\n\\n\")}\n \\`\\`\\`\n `;\n}\n\n/**\n * Resolves a mixed list of tool names and tool instances into a flat list of\n * StructuredToolInterface objects. Strings are looked up by name in agentTools;\n * instances are included directly without requiring agent registration. Strings\n * that don't match any agent tool are silently omitted.\n */\nexport function resolveToolList(\n items: (string | StructuredToolInterface)[],\n agentTools: StructuredToolInterface[],\n): StructuredToolInterface[] {\n const agentByName = new Map(agentTools.map((t) => [t.name, t]));\n return items.flatMap((item) => {\n if (typeof item === \"string\") {\n const found = agentByName.get(item);\n return found ? [found] : [];\n }\n return [item];\n });\n}\n\n/**\n * Pull `skillsMetadata` from the task input, resolve the backend, and push\n * both into the session. Short-circuits with a `SkillNotAvailable` error if\n * the source references skills the agent doesn't have.\n */\nasync function prepareSkillsForEval(\n session: ReplSession,\n skillsBackend: AnyBackendProtocol | BackendFactory,\n code: string,\n): Promise<string | undefined> {\n const taskInput = getCurrentTaskInput<{ skillsMetadata?: SkillMetadata[] }>();\n const metadata: SkillMetadata[] = taskInput?.skillsMetadata ?? [];\n\n const referenced = scanSkillReferences(code);\n if (referenced.size > 0) {\n const known = new Set(metadata.map((m) => m.name));\n const missing: string[] = [];\n for (const name of referenced) {\n if (!known.has(name)) {\n missing.push(name);\n }\n }\n if (missing.length > 0) {\n session.setSkillsContext(undefined);\n return formatSkillNotAvailable(missing);\n }\n }\n\n const resolved = await resolveBackend(skillsBackend, { state: taskInput });\n session.setSkillsContext({ metadata, backend: resolved });\n return undefined;\n}\n\n/**\n * Create the REPL middleware.\n */\nexport function createREPLMiddleware(options: REPLMiddlewareOptions = {}) {\n const {\n ptc,\n memoryLimitBytes = DEFAULT_MEMORY_LIMIT,\n maxStackSizeBytes = DEFAULT_MAX_STACK_SIZE,\n executionTimeoutMs = DEFAULT_EXECUTION_TIMEOUT,\n systemPrompt: customSystemPrompt = null,\n skillsBackend,\n maxPtcCalls = DEFAULT_MAX_PTC_CALLS,\n maxResultChars = DEFAULT_MAX_RESULTS_CHARS,\n toolName = DEFAULT_TOOL_NAME,\n captureConsole = true,\n } = options;\n\n if (maxPtcCalls !== null && maxPtcCalls !== undefined && maxPtcCalls < 1) {\n throw new Error(\"`maxPtcCalls` must be >= 1 or null\");\n }\n\n const baseSystemPrompt =\n customSystemPrompt ||\n renderReplSystemPrompt({\n toolName,\n timeout: executionTimeoutMs / 1000,\n memoryLimitMb: Math.floor(memoryLimitBytes / (1024 * 1024)),\n });\n\n const middlewareId = crypto.randomUUID();\n\n let cachedPtcPrompt: string | null = null;\n\n let ptcTools: StructuredToolInterface[] = [];\n\n function filterToolsForPtc(\n allTools: StructuredToolInterface[],\n ): StructuredToolInterface[] {\n if (!ptc) return [];\n\n const candidates = allTools.filter((t) => t.name !== toolName);\n\n return resolveToolList(ptc, candidates);\n }\n\n const evalTool = tool(\n async (input, config: LangGraphRunnableConfig) => {\n const threadId = config.configurable?.thread_id || DEFAULT_SESSION_ID;\n const sessionKey = `${threadId}:${middlewareId}`;\n\n const session = ReplSession.getOrCreate(sessionKey, {\n memoryLimitBytes,\n maxStackSizeBytes,\n maxPtcCalls,\n tools: ptcTools,\n skillsEnabled: skillsBackend !== undefined,\n maxResultChars,\n captureConsole,\n });\n\n if (skillsBackend !== undefined) {\n const setupError = await prepareSkillsForEval(\n session,\n skillsBackend,\n input.code,\n );\n if (setupError !== undefined) {\n return setupError;\n }\n }\n\n const result = await session.eval(input.code, executionTimeoutMs);\n return formatReplResult(result);\n },\n {\n name: toolName,\n description: dedent`\n Evaluate TypeScript/JavaScript code in a sandboxed REPL. State persists across calls.\n Use console.log() for output. Returns the result of the last expression.\n If file or other tools are available, call them via the tools namespace: await tools.readFile({ path }).\n If skills are configured, dynamically import them: await import(\"@/skills/<name>\").\n `,\n metadata: { ls_code_input_language: \"javascript\" },\n schema: z.object({\n code: z\n .string()\n .describe(\n \"TypeScript/JavaScript code to evaluate in the sandboxed REPL\",\n ),\n }),\n },\n );\n\n return createMiddleware({\n name: \"REPLMiddleware\",\n tools: [evalTool],\n wrapModelCall: async (request, handler) => {\n const agentTools = (request.tools || []) as StructuredToolInterface[];\n ptcTools = filterToolsForPtc(agentTools);\n\n if (ptcTools.length > 0 && !cachedPtcPrompt) {\n cachedPtcPrompt = await generatePtcPrompt(ptcTools);\n }\n\n const systemMessage = request.systemMessage\n .concat(baseSystemPrompt)\n .concat(cachedPtcPrompt || \"\");\n return handler({ ...request, systemMessage });\n },\n afterAgent: async (_state, runtime) => {\n const threadId = runtime.configurable?.thread_id ?? DEFAULT_SESSION_ID;\n const sessionKey = `${threadId}:${middlewareId}`;\n ReplSession.deleteSession(sessionKey);\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,WAAW,OAAO,OAAO,UAAU,CAAC;;;;;;;;;AA2B1C,SAAgB,iBAAiB,MAAsB;CACrD,IAAI;AACJ,KAAI;AACF,QAAM,SAAS,MAAM,MAAM;GACzB,aAAa;GACb,YAAY;GACZ,WAAW;GACZ,CAAC;SACI;AAEN,SAAO,mBAAmB,KAAK;;CAGjC,MAAM,IAAI,IAAI,YAAY,KAAK;CAE/B,MAAM,gBAAgBA,IAAQ;AAC9B,MAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;EAC7C,MAAM,OAAO,cAAc;AAG3B,MAAI,aAAa,KAAK,EAAE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{
|
|
2
2
|
"name": "@langchain/quickjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Sandboxed JavaScript REPL for deepagents using QuickJS (WASM)",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"deepagents": ">=1.9.0-alpha.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@langchain/core": "^1.1.
|
|
46
|
-
"@langchain/langgraph": "^1.2.
|
|
45
|
+
"@langchain/core": "^1.1.42",
|
|
46
|
+
"@langchain/langgraph": "^1.2.9",
|
|
47
47
|
"@tsconfig/recommended": "^1.0.13",
|
|
48
48
|
"@types/dedent": "^0.7.2",
|
|
49
49
|
"@types/estree": "^1.0.8",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"typescript": "^6.0.2",
|
|
57
57
|
"vitest": "^4.0.18",
|
|
58
58
|
"zod": "^4.3.6",
|
|
59
|
-
"deepagents": "1.
|
|
59
|
+
"deepagents": "1.10.0"
|
|
60
60
|
},
|
|
61
61
|
"exports": {
|
|
62
62
|
".": {
|