@silviomollov/ai-isolate-quickjs
v0.1.46-fork.3
Published
Temporary fork of @tanstack/ai-isolate-quickjs (0.1.45) with promise-bridge host functions replacing asyncify (fixes quickjs-emscripten#258 refcount corruption on sequential tool awaits). Use until the upstream fix is released.
Downloads
248
Maintainers
Readme
@silviomollov/ai-isolate-quickjs
Temporary fork of
@tanstack/ai-isolate-quickjs0.1.45(MIT, © TanStack). Host tool functions are bridged as QuickJS promises instead of asyncify suspensions, fixing refcount corruption / WASM aborts on sequential awaits of the same tool binding (quickjs-emscripten#258), and enabling concurrent tool calls viaPromise.all. The fix uses the plain (non-asyncify) QuickJS build — if you bundle the wasm yourself, ship@jitl/quickjs-wasmfile-release-sync/wasm. This package will be deprecated once the fix lands upstream.Drop-in usage via npm alias:
"@tanstack/ai-isolate-quickjs": "npm:@silviomollov/[email protected]"
QuickJS WASM driver for TanStack AI Code Mode. Runs everywhere — Node.js, browsers, and edge runtimes — with zero native dependencies.
Installation
pnpm add @tanstack/ai-isolate-quickjsUsage
import { createQuickJSIsolateDriver } from "@tanstack/ai-isolate-quickjs";
import { createCodeModeTool } from "@tanstack/ai-code-mode";
const driver = createQuickJSIsolateDriver({
timeout: 30000, // execution timeout in ms (default: 30000)
memoryLimit: 128, // memory limit in MB (default: 128)
maxStackSize: 512 * 1024, // max stack size in bytes (default: 512 KiB)
});
const executeTypescript = createCodeModeTool({
driver,
tools: [myTool],
});Config Options
timeout— Default execution timeout in milliseconds (default: 30000)memoryLimit— Default QuickJS runtime memory limit in MB (default: 128)maxStackSize— Default QuickJS runtime max stack size in bytes (default: 524288)
Tradeoffs vs Node Driver
| | QuickJS (WASM) | Node (isolated-vm) |
| --------------- | -------------------------- | ----------------------- |
| Native deps | None | Yes (C++ addon) |
| Browser support | Yes | No |
| Performance | Slower (interpreted) | Faster (V8 JIT) |
| Memory limit | Configurable | Configurable |
| Best for | Browser, edge, portability | Server-side performance |
How It Works
Uses QuickJS compiled to WebAssembly via quickjs-emscripten. Each execution creates a fresh async QuickJS context with tool bindings injected as global async functions.
Runtime Limits and Errors
- QuickJS enforces runtime memory and stack limits for each context.
- Exceeding limits can produce normalized errors such as
MemoryLimitErrororStackOverflowError. - Certain fatal limit conditions may dispose the underlying VM; create a fresh context before running more code after disposal.
Refreshing the Fork
From Git Bash, refresh the staged sources and set the next package version with:
./refresh.sh 0.1.46-fork.2The source repository defaults to the sibling ../ai directory. Set REPO_DIR if it is elsewhere.
License
MIT
