Skip to content

JavaScript / @yai-xlai/xlai

The npm package @yai-xlai/xlai is a Vite-friendly TypeScript layer on top of the xlai-wasm crate. It ships a bundled library plus generated wasm bindings under pkg/ during build (not committed).

Scripts (from the repository root)

CommandPurpose
pnpm --filter @yai-xlai/xlai devRebuild wasm and start the Vite dev server
pnpm --filter @yai-xlai/xlai buildRebuild wasm and emit the library bundle
pnpm --filter @yai-xlai/xlai testRebuild wasm and run Vitest
pnpm --filter @yai-xlai/xlai test:e2ePlaywright smoke test against the demo page

Requirements

  • mise for the pinned Node.js, pnpm, Rust, and wasm-pack toolchains
  • The wasm32-unknown-unknown Rust target, installed by mise install

WASM surface

The WebAssembly package mirrors the Rust split between chat and agent APIs (chat, createChatSession, agent, createAgentSession) and supports the same streaming and context-compressor semantics as documented under Rust / Chat, agents, and tools.

Token usage

Chat and embedding responses expose usage.inputTokens, usage.outputTokens, and usage.totalTokens when available. Hosted providers that report prompt-cache accounting may also expose usage.cachedInputTokens and usage.uncachedInputTokens; local tokenizer counts leave those fields unset. usage.source is optional and distinguishes provider_reported, tokenizer_exact, and estimated counts. Use provider-reported counts for billing reconciliation; agent estimatedInputTokens values are context-management estimates only.

Peer dependencies and export maps are defined in packages/xlai/package.json.

For package-local developer notes, see packages/xlai/README.md.

Released under the Apache License 2.0.