Skip to content
5 min read · 901 words

@nhtio/adk/batteries/llm/litert_lm ​

LiteRT-LM adapter battery — browser/WebGPU on-device inference with swappable translation helpers.

Remarks ​

Opinionated LLM battery wrapping Google's @litert-lm/core — on-device inference in the browser via WebGPU + a bundled wasm runtime, driving .litertlm models. Ships a LiteRtLmAdapter that targets LiteRT-LM's native Engine → Conversation API and translates the ADK's primitives into LiteRT's Message / Tool / tool_response / Preface wire shapes.

Unlike the WebLLM battery (a thin extension of the OpenAI Chat Completions wire shape), this is a standalone battery: it reuses the format-agnostic render helpers but maps history, tools, and results to LiteRT's own shapes, where tool-call arguments arrive as a parsed object (not a JSON string) and "thinking" surfaces via Message.channels.

The published @litert-lm/core docs lag the library. Every wire field here is mapped against the installed package's type declarations — the source of truth. The dependency is young (pinned exact); re-verify on upgrade.

Re-exports the adapter class, every translation helper (each under its unprefixed name AND a default*-prefixed alias so consumers can compose partial overrides against the bundled defaults), the LiteRT-native mappers, every option / wire-shape type alias, the validation schema + validateOptions wrapper, and the five battery-scoped exception classes.

References ​

Backend ​

Re-exports Backend


BatteryLifecycleBattery ​

Re-exports BatteryLifecycleBattery


BatteryLifecycleCallback ​

Re-exports BatteryLifecycleCallback


BatteryLifecycleHooks ​

Re-exports BatteryLifecycleHooks


BatteryLifecyclePhase ​

Re-exports BatteryLifecyclePhase


BatteryLifecycleReport ​

Re-exports BatteryLifecycleReport


buildBundledReasoningParsers ​

Re-exports buildBundledReasoningParsers


buildLiteRtConversationInput ​

Re-exports buildLiteRtConversationInput


BUNDLED_REASONING_PARSERS ​

Re-exports BUNDLED_REASONING_PARSERS


BUNDLED_TOOL_CALL_PARSERS ​

Re-exports BUNDLED_TOOL_CALL_PARSERS


ChatGenerationOptions ​

Re-exports ChatGenerationOptions


ChatSampler ​

Re-exports ChatSampler


createAutoReasoningParser ​

Re-exports createAutoReasoningParser


createAutoToolCallParser ​

Re-exports createAutoToolCallParser


CreateLiteRtLmEngine ​

Re-exports CreateLiteRtLmEngine


createLiteRtStreamAccumulator ​

Re-exports createLiteRtStreamAccumulator


DEFAULT_REASONING_PARSER_ORDER ​

Re-exports DEFAULT_REASONING_PARSER_ORDER


DEFAULT_TOOL_CALL_PARSER_ORDER ​

Re-exports DEFAULT_TOOL_CALL_PARSER_ORDER


defaultBuildLiteRtConversationInput ​

Re-exports defaultBuildLiteRtConversationInput


defaultCreateLiteRtStreamAccumulator ​

Re-exports defaultCreateLiteRtStreamAccumulator


defaultDescriptionToChatCompletionsJsonSchema ​

Re-exports defaultDescriptionToChatCompletionsJsonSchema


defaultEmitLifecycle ​

Re-exports defaultEmitLifecycle


defaultFilterThoughts ​

Re-exports defaultFilterThoughts


defaultRenderChatCompletionsSystemPrompt ​

Re-exports defaultRenderChatCompletionsSystemPrompt


defaultRenderFirstPartyRetrievables ​

Re-exports defaultRenderFirstPartyRetrievables


defaultRenderLiteRtToolResult ​

Re-exports defaultRenderLiteRtToolResult


defaultRenderMemories ​

Re-exports defaultRenderMemories


defaultRenderRetrievables ​

Re-exports defaultRenderRetrievables


defaultRenderRetrievableSafetyDirective ​

Re-exports defaultRenderRetrievableSafetyDirective


defaultRenderStandingInstructions ​

Re-exports defaultRenderStandingInstructions


defaultRenderThirdPartyPrivateRetrievables ​

Re-exports defaultRenderThirdPartyPrivateRetrievables


defaultRenderThirdPartyPublicRetrievables ​

Re-exports defaultRenderThirdPartyPublicRetrievables


defaultRenderThought ​

Re-exports defaultRenderThought


defaultRenderToolsAsPromptText ​

Re-exports defaultRenderToolsAsPromptText


defaultRenderTrustedContent ​

Re-exports defaultRenderTrustedContent


defaultRenderUntrustedContent ​

Re-exports defaultRenderUntrustedContent


defaultResolveGenerationOptions ​

Re-exports defaultResolveGenerationOptions


defaultToolsToLiteRtTools ​

Re-exports defaultToolsToLiteRtTools


DescriptionLike ​

Re-exports DescriptionLike


descriptionToChatCompletionsJsonSchema ​

Re-exports descriptionToChatCompletionsJsonSchema


E_INVALID_LITERT_LM_OPTIONS ​

Re-exports E_INVALID_LITERT_LM_OPTIONS


E_LITERT_LM_CONTEXT_OVERFLOW ​

Re-exports E_LITERT_LM_CONTEXT_OVERFLOW


E_LITERT_LM_INVALID_TOOL_CALL_ARGS ​

Re-exports E_LITERT_LM_INVALID_TOOL_CALL_ARGS


E_LITERT_LM_STREAM_ERROR ​

Re-exports E_LITERT_LM_STREAM_ERROR


E_LLM_GPU_OUT_OF_MEMORY ​

Re-exports E_LLM_GPU_OUT_OF_MEMORY


E_UNSUPPORTED_MEDIA_MODALITY ​

Re-exports E_UNSUPPORTED_MEDIA_MODALITY


emitLifecycle ​

Re-exports emitLifecycle


extractReasoningFields ​

Re-exports extractReasoningFields


filterThoughts ​

Re-exports filterThoughts


gemmaChannelReasoningParser ​

Re-exports gemmaChannelReasoningParser


gemmaToolCallParser ​

Re-exports gemmaToolCallParser


GeneratedMediaOutput ​

Re-exports GeneratedMediaOutput


GENERATION_DEFAULTS ​

Re-exports GENERATION_DEFAULTS


gptOssToolCallParser ​

Re-exports gptOssToolCallParser


GpuBudget ​

Re-exports GpuBudget


GpuBufferInstrument ​

Re-exports GpuBufferInstrument


GpuBufferSample ​

Re-exports GpuBufferSample


harmonyAnalysisReasoningParser ​

Re-exports harmonyAnalysisReasoningParser


hermesToolCallParser ​

Re-exports hermesToolCallParser


instrumentGpuBuffers ​

Re-exports instrumentGpuBuffers


isEngineContextOverflowMessage ​

Re-exports isEngineContextOverflowMessage


isGpuOutOfMemoryError ​

Re-exports isGpuOutOfMemoryError


JsonSchema ​

Re-exports JsonSchema


LiteRtConversationConfig ​

Re-exports LiteRtConversationConfig


LiteRtEngineSettings ​

Re-exports LiteRtEngineSettings


LiteRtLlmExecutorSettings ​

Re-exports LiteRtLlmExecutorSettings


LiteRtLmAdapter ​

Re-exports LiteRtLmAdapter


LiteRtLmAdapterOptions ​

Re-exports LiteRtLmAdapterOptions


LiteRtLmBucketOrder ​

Renames and re-exports ChatCompletionsBucketOrder


LiteRtLmChatEngine ​

Re-exports LiteRtLmChatEngine


LiteRtLmConversation ​

Re-exports LiteRtLmConversation


LiteRtLmDescriptionLike ​

Re-exports LiteRtLmDescriptionLike


LiteRtLmEngine ​

Re-exports LiteRtLmEngine


LiteRtLmHelpers ​

Renames and re-exports ChatCompletionsHelpers


LiteRtLmInitProgressReport ​

Re-exports LiteRtLmInitProgressReport


LiteRtLmJsonSchema ​

Re-exports LiteRtLmJsonSchema


liteRtLmOptionsSchema ​

Re-exports liteRtLmOptionsSchema


LiteRtMessage ​

Re-exports LiteRtMessage


LiteRtMessageContentItem ​

Re-exports LiteRtMessageContentItem


LiteRtMessageLike ​

Re-exports LiteRtMessageLike


LiteRtPreface ​

Re-exports LiteRtPreface


LiteRtSamplerParameters ​

Re-exports LiteRtSamplerParameters


LiteRtSamplerParametersOption ​

Re-exports LiteRtSamplerParametersOption


LiteRtSessionConfig ​

Re-exports LiteRtSessionConfig


LiteRtStreamAccumulator ​

Re-exports LiteRtStreamAccumulator


LiteRtTool ​

Re-exports LiteRtTool


LiteRtToolCall ​

Re-exports LiteRtToolCall


LiteRtToolCallFunction ​

Re-exports LiteRtToolCallFunction


LiteRtToolParameters ​

Re-exports LiteRtToolParameters


LiteRtToolResponseValue ​

Re-exports LiteRtToolResponseValue


llama3JsonToolCallParser ​

Re-exports llama3JsonToolCallParser


looksLikeSpooledArtifact ​

Re-exports looksLikeSpooledArtifact


makeGemmaChannelReasoningParser ​

Re-exports makeGemmaChannelReasoningParser


makeHarmonyAnalysisReasoningParser ​

Re-exports makeHarmonyAnalysisReasoningParser


makeThinkTagReasoningParser ​

Re-exports makeThinkTagReasoningParser


MediaOutputExtractorFn ​

Re-exports MediaOutputExtractorFn


mistralToolCallParser ​

Re-exports mistralToolCallParser


noneReasoningParser ​

Re-exports noneReasoningParser


noneToolCallParser ​

Re-exports noneToolCallParser


ParsedToolCall ​

Re-exports ParsedToolCall


phiToolCallParser ​

Re-exports phiToolCallParser


probeGpuBudget ​

Re-exports probeGpuBudget


PromptAssembledObservation ​

Re-exports PromptAssembledObservation


PromptAssembledObserverFn ​

Re-exports PromptAssembledObserverFn


pythonicToolCallParser ​

Re-exports pythonicToolCallParser


qwen3CoderToolCallParser ​

Re-exports qwen3CoderToolCallParser


RawGenerationObservation ​

Re-exports RawGenerationObservation


RawGenerationObserverFn ​

Re-exports RawGenerationObserverFn


ReasoningParseResult ​

Re-exports ReasoningParseResult


ReasoningParserFn ​

Re-exports ReasoningParserFn


ReasoningParserName ​

Re-exports ReasoningParserName


ReasoningParserOptions ​

Re-exports ReasoningParserOptions


renderArtifactHandleBody ​

Re-exports renderArtifactHandleBody


renderChatCompletionsSystemPrompt ​

Re-exports renderChatCompletionsSystemPrompt


renderFirstPartyRetrievables ​

Re-exports renderFirstPartyRetrievables


renderLiteRtToolResult ​

Re-exports renderLiteRtToolResult


renderMediaToLiteRtContent ​

Re-exports renderMediaToLiteRtContent


renderMemories ​

Re-exports renderMemories


renderRetrievables ​

Re-exports renderRetrievables


renderRetrievableSafetyDirective ​

Re-exports renderRetrievableSafetyDirective


renderStandingInstructions ​

Re-exports renderStandingInstructions


renderThirdPartyPrivateRetrievables ​

Re-exports renderThirdPartyPrivateRetrievables


renderThirdPartyPublicRetrievables ​

Re-exports renderThirdPartyPublicRetrievables


renderThought ​

Re-exports renderThought


renderToolsAsPromptText ​

Re-exports renderToolsAsPromptText


renderTrustedContent ​

Re-exports renderTrustedContent


renderUntrustedContent ​

Re-exports renderUntrustedContent


ResolvedGenerationOptions ​

Re-exports ResolvedGenerationOptions


resolveGenerationOptions ​

Re-exports resolveGenerationOptions


resolveReasoningParser ​

Re-exports resolveReasoningParser


resolveToolCallParser ​

Re-exports resolveToolCallParser


SamplerType ​

Re-exports SamplerType


thinkTagReasoningParser ​

Re-exports thinkTagReasoningParser


ToolCallParserContext ​

Re-exports ToolCallParserContext


ToolCallParseResult ​

Re-exports ToolCallParseResult


ToolCallParserFn ​

Re-exports ToolCallParserFn


ToolCallParserName ​

Re-exports ToolCallParserName


toolsToLiteRtTools ​

Re-exports toolsToLiteRtTools


UnsupportedMediaPolicy ​

Re-exports UnsupportedMediaPolicy


validateOptions ​

Re-exports validateOptions