@nhtio/adk/batteries/llm/transformers_js/adapter
Dual-environment (Node + browser) executor adapter for transformers.js (@huggingface/transformers).
Remarks
On-device text generation via ONNX Runtime — onnxruntime-node (native) in Node, onnxruntime-web (WASM + WebGPU) in the browser, auto-selected by the package. So this battery is environment-neutral: it does NOT gate on WebGPU.
transformers.js is text-in / text-out. It injects tool definitions into the chat template but does NOT return structured tool calls or reasoning — the model emits both as family-specific raw text. This adapter parses them out via the shared, configurable parser layer (toolCallParser / reasoningParser, both defaulting to 'auto'): after generation, the reasoning parser pulls thinking into ADK Thoughts and the tool-call parser pulls calls into ADK ToolCalls, leaving clean prose as the assistant Message.
Three pluggable layers mirror the other LLM batteries: swappable translation helpers, three-layer options merging (constructor → executor() overrides → ctx.stash.transformersJs), and an injectable/lazy pipeline (pipeline or createPipeline, defaulting to a dynamic import).
Classes
| Class | Description |
|---|---|
| TransformersJsAdapter | Dual-environment executor adapter for transformers.js text generation. |
Functions
| Function | Description |
|---|---|
| __extractGeneratedText | Pull the newly-generated assistant text out of a transformers.js text-generation result. |