WebAssembly
Run the fx agent in the browser with your own interface, or use the fx terminal. Both run through WebAssembly.
For a complete HTML page and server route, start with the browser example. On Node.js, use the native SDK.
npm install libfx@0.0.12
Check runtime support
The SDK requires JavaScript Promise Integration (JSPI). Call supportsJspi() before creating the agent so you can show an unsupported-browser message instead of failing during startup. In Node.js 24, enable JSPI with --experimental-wasm-jspi; the native Node agent does not need it.
Run a headless agent
In a browser project with a bundler, this example asks for a key and streams a reply to the console. It uses the same model connection as the Node agent:
import { createFxAgent, supportsJspi } from 'libfx/browser'
if (!supportsJspi()) {
throw new Error('fx requires JSPI support')
}
const agent = await createFxAgent({
apiKey: window.prompt('AI Gateway API key'),
})
try {
const turn = agent.prompt('Explain closures in two sentences.')
for await (const event of turn) {
if (event.type === 'text_delta') console.log(event.delta)
}
const { stopReason, usage } = await turn.result
console.log(stopReason, usage)
} finally {
await agent.close()
}
The key entered here goes directly to AI Gateway. Keep a shared application key on the server and proxy requests through your backend. The browser example includes both routes.
The browser entry point resolves fx-core.wasm relative to the installed package. If your bundler does not serve it, copy it to a public asset directory and pass its URL as wasm.
Save conversations and add tools
Use checkpoints to save and restore a conversation. Add JavaScript tools, MCP tools, and skills when creating the agent.
An embedded agent does not inherit the CLI’s shell, filesystem, or stored credentials. Its tools run in your application and have only the access you give them.
WebAssembly runtime limits
WebAssembly cannot start native processes or access a native keychain or filesystem. Each agent has its own memory and conversation. When agents reuse the same source URL or object, the SDK compiles the module once.
Embed the terminal
createFxTerminal() runs the fx terminal using fx-term.wasm. It handles prompts and output through a terminal interface instead of a UI you build around agent events.
Follow the web terminal guide to connect xterm.js, save sessions, and add login and workspace adapters.