TypeScript quickstart
Install the Node.js SDK preview, run a Codex turn, and recover the reply after reopening.
Start in a TypeScript project with a Git working tree and a signed-in Codex CLI on your PATH. The example sends one prompt using that account. Use Node.js 22.14 or later in the 22 series, 24.x, or 26.x on Apple Silicon macOS or Linux x64 with glibc.
Install the preview
Install the preview from two local tarballs. Copy the SDK tarball and its matching native package into your project directory. To produce the files yourself, see Build the tarballs.
On Apple Silicon macOS, run
npm install --ignore-scripts ./huggler-sdk-0.0.1-preview.0.tgz ./huggler-sdk-darwin-arm64-0.0.1-preview.0.tgzOn Linux x64 with glibc, run
npm install --ignore-scripts ./huggler-sdk-0.0.1-preview.0.tgz ./huggler-sdk-linux-x64-gnu-0.0.1-preview.0.tgzRun one turn
Save this as first-turn.mts in the project root. Huggler stores the conversation under ~/.huggler-example by default. Pass a directory to store it elsewhere.
import { Huggler, commandId, threadId } from "@huggler/sdk"
const stateDir = process.argv[2]
const options = { name: "Huggler Example", ...(stateDir ? { stateDir } : {}) }
const thread = threadId("first-conversation")
const host = await Huggler.open(options)
let completedRunId
try {
const project = await host.openProject(".")
await host.launch({
commandId: commandId("launch-first-conversation"),
threadId: thread,
projectId: project.id,
providerInstanceId: "codex",
name: "First conversation",
})
const receipt = await host.send({
commandId: commandId("first-prompt"),
threadId: thread,
text: "Explain what a package-lock.json file is in one sentence.",
})
const signal = AbortSignal.timeout(120_000)
const run = await host.wait(thread, receipt.runId, { signal })
if (run.status !== "completed") throw new Error(run.error ?? run.status)
completedRunId = run.id
} finally {
await host.close()
}
const reopened = await Huggler.open(options)
try {
const { messages } = await reopened.readThread(thread)
for (const message of messages) {
if (message.runId === completedRunId && message.role === "assistant") {
console.log(message.text)
}
}
} finally {
await reopened.close()
}Compile and run the example from the project root.
npm install --save-dev typescript@5.9 @types/node@22
npx tsc --strict --target ES2022 --module NodeNext first-turn.mts
state_dir=$(mktemp -d)
node first-turn.mjs "$state_dir"The program prints the reply from the reopened database. Run the last command again with the same directory to recover the original receipts and reply. For a follow-up, keep the thread ID and give the next send a fresh command ID. For an interactive prompt, your host can show pending approvals and questions while the turn runs. Control threads
Build the tarballs
From a Huggler checkout containing bindings/node, build on the same platform as the consuming Node.js process. You’ll need Rust 1.94.1, a C toolchain, Git, Python 3.11+, and a supported Node.js version.
cd bindings/node
rustup component add rust-docs
cargo install --locked cargo-about --version 0.9.1 --features cli
npm ci --ignore-scripts
npm run pack:localCopy the two files from bindings/node/packages/ into the consuming project, then follow the install step above. On macOS with Xcode 27, the bundled Rust linker needs a compatible macOS SDK. The build detects the Command Line Tools macOS 26 SDK or accepts its path through SDKROOT.
Next steps
Configure a named provider or explore the TypeScript API.