internal library

Classes

BenchmarkInfo
What LiteRT-LM's benchmark reports about a conversation: its tokens over every turn so far, the last decode's speed, the first token's latency and the engine's load time. LiteRT-LM's Kotlin/Swift BenchmarkInfo, summed over the conversation rather than its last turn.
BundleInfo
What a .litertlm file says about itself, read before any engine exists: its container version, its system metadata, and its sections with their declared constraints and the NPU each compiled section targets.
BundleSampler
The sampler a .litertlm file declares: each value null when the file does not set it.
BundleSection
One section of a .litertlm container.
CancelSignal
A cancel the runtime can check and wait for. The adapter passes core's CancelToken through it.
ConversationHandle
Per-conversation operations a session needs from the FFI layer.
EmbedderInfo
What a loaded embedder reports.
EmbedderInput
One embedding request: text, images and audio, embedded as one vector.
EngineSamplerLatch
LiteRT-LM builds an engine's sampler at its first generation and keeps it for every later conversation (google-ai-edge/LiteRT-LM#2080), so a later session that asks for another sampler does not get it. This records the first and says what a later generation should report.
LibraryLoadFailure
An error thrown while libLiteRtLm, or a library it needs, loads or is checked: what Engine.create reports as a LiteRtLmLibraryException. Each keeps the type the load threw (the Flutter adapter's backend fallback tells an Exception from an Error), so this marks it instead of replacing it.
LiteRtLmPageLease
One holder's turn on a LiteRtLmPageLock.
LiteRtLmPageLock
A FIFO async lock: acquire queues the caller behind every earlier caller, at the moment it is called.
LiteRtLmWebAudio
An encoded audio clip (WAV, MP3 or FLAC), decoded, mixed down to mono and resampled to 16 kHz by the engine.
LiteRtLmWebEmbedder
The .litertlm embedder on the web: text, images when declared on a bundle with a vision encoder, audio when declared on a bundle with an audio encoder, and any combination of them in one vector.
LiteRtLmWebEmbedderConfig
What the web LiteRtEmbeddingBackend.describe hands core for a .litertlm embedder. Hosted inline on the page, never sent across an isolate.
LiteRtLmWebEmbeddingOptions
EmbeddingOptions for one computeEmbedding call.
LiteRtLmWebEngine
One EmbeddingEngine.
LiteRtLmWebEngineSettings
What the pass hands EmbeddingEngine.create (EmbeddingEngineSettings). A null field is left out of the settings object, so the runtime applies its own rule — for visionBackend and audioBackend, that tower disabled.
LiteRtLmWebImage
An encoded image (JPEG, PNG, GIF or BMP), decoded by the engine.
LiteRtLmWebInput
What one computeEmbedding call embeds: one part — a string, an encoded image or an encoded audio clip — or several of them in one vector (LiteRtLmWebParts).
LiteRtLmWebParts
Several parts embedded as one vector (a combined input), in the order the engine reads them: the text, then the images, then the audio. Each part is a LiteRtLmWebText, LiteRtLmWebImage or LiteRtLmWebAudio, never another LiteRtLmWebParts.
LiteRtLmWebRuntime
The page's @litert-lm/core embedding runtime, as the pass uses it.
LiteRtLmWebText
A text part, exactly as the engine tokenizes it (prefix included).
MediaOrder
Where a message's images and audio go relative to its text.
NpuStamp
The SoC a .litertlm bundle's compiled sections target: the LiteRtStamp the AOT compiler writes into each section it compiles, with the vendor and SoC spelled as the compiler stamped them.
Sampler
The sampler sent to LiteRT-LM, every value set.
ScoringRun
What one option-scoring run returned.
SendOptions
One send's optional args beyond thinking and the constraint.

Enums

ActivationDataType
The numeric type of a GPU model's activations, LiteRT-LM's ActivationDataType without I16/I8.
BackendKind
Where LiteRT-LM runs a model's main graph, or one of its encoders. Its name is LiteRT-LM's wire name (cpu, gpu, npu).
EmbedderModality
A kind of input an embedder takes.
LiteRtLmBundleProblem
Why a .litertlm file cannot be read or loaded as asked.
LiteRtLmEg2Bundle
The generic EmbeddingGemma 2 bundles, told apart by the towers their container carries (readLiteRtLmMediaTowers).
LiteRtLmLogLevel
The minimum severity of LiteRT-LM's own native log: LiteRtLmLogSeverity of its C API (litert_lm_set_min_log_level).
LiteRtLmWebBackend
The @litert-lm/core backends the pass can ask for (Backend.CPU, Backend.GPU).
LiteRtLmWebGpuSupport
Whether the browser can give the runtime a WebGPU device.
LiteRtLmWebOverflowStrategy
InputOverflowStrategy of @litert-lm/core.
LiteRtLmWebRuntimeState
What the page offers when the pass asks.
MediaSide
Which side of a message's text a kind of media goes.
NativeLastTurnEnd
How native's last send ended (LiteRtLmTurnEnd in the patched c/conversation.h), as litert_lm_conversation_get_last_turn_end reports it after a send (§23) and litert_lm_conversation_rewind_cancelled_turn after waiting for one (§16). In the C enum's order: the index is the code.
NpuStack
A vendor whose NPU this package dispatches to.
RuntimeLogLevel
How much runtimeLog lets through: nothing, info messages, or info and verbose ones (model output, prompts, native log contents).
StoppedTurnRewind
What ConversationHandle.rewindStoppedTurn did.

Constants

googleTensorNpuLibs → const List<String>
The complete app-bundled Google Tensor stack: the bridge only.
liteRtLmAudioBundle → const String
The bundle with an audio encoder.
liteRtLmDefaultVisionTokensPerImage → const int
The vision budget an engine is created with unless the app asks for 70.
liteRtLmEmbeddingGpuAbis → const Set<String>
The hosts, in Abi.current() spelling, where a generic EmbeddingGemma 2 bundle runs on the GPU when preferredBackend: gpu asks for it: LiteRT-LM's GPU executor, over the WebGPU accelerator these archives ship on Linux and Windows and the Metal accelerator linked into libLiteRtLm on macOS.
liteRtLmEmbeddingGpuMeasured → const Map<String, Set<LiteRtLmEg2Bundle>>
Which generic EmbeddingGemma 2 bundles have run with their text tower on the GPU of each liteRtLmEmbeddingGpuAbis host; a gpu request for any other is refused there, naming the missing run. Linux x64: all three since litertlm 1.19.0 (measured on the 270m; the others run the same text tower with their media towers on CPU). Windows x64: the 270m on Panther Lake and Lunar Lake (L1, 2026-11-04). macOS: the 270m and the 740m text towers on Metal (L1 C probe; the 270m and 740m through this pass, L2).
liteRtLmEmbeddingGpuRefusedAbis → const Set<String>
The hosts where preferredBackend: gpu for a generic EmbeddingGemma 2 bundle is refused with an EmbeddingLoadException (liteRtLmEmbeddingGpuRefusal) instead of running anywhere: a host whose GPU path ends the process, which no Dart code can catch, so the request is refused rather than run on the CPU (the app asked for the GPU). None on native-v0.19.0-a: Windows x64 was here on native-v0.18.0-h (#744, an access violation in webgpu_dawn.dll at the first EmbeddingGemma 2 GPU load) and runs on 0.19 (liteRtLmEmbeddingGpuAbis).
liteRtLmMaxInputLength → const int
The input length every EmbeddingGemma 2 engine is created with, in tokens.
liteRtLmNativeAbis → const Set<String>
The hosts, in Abi.current() spelling, the native archive is published for (hook/build.dart, one litertlm-<host>.tar.gz each; the iOS simulator's ios_sim_arm64 archive reports ios_arm64). Anywhere else the app builds without libLiteRtLm, and nothing of this package loads.
liteRtLmVisionTokenBudgets → const List<int>
The vision budgets EmbeddingGemma 2 has signatures for.
liteRtLmWebAudioBackend → const LiteRtLmWebBackend
The backend of the audio tower on the web: WebGPU, as the text and vision towers. Both work; WebGPU is about 65 times faster. Measured on the 740m, Chrome 155, Tesla T4 (2.6-3.6 s clips of speech):
liteRtLmWebModuleUrl → const String
The ES module the page imports, pinned to liteRtLmWebRuntimeVersion.
liteRtLmWebRuntime → const String
@litert-lm/core with its version, as messages name it.
liteRtLmWebRuntimeVersion → const String
The @litert-lm/core version the web arm drives.
liteRtLmWebShimLine → const String
The index.html line the page needs for EmbeddingGemma 2, word for word.
samplerTypeTopP → const int
SamplerType.TOP_P in @litert-lm/core.
webMediaPathMessage → const String
The message refusing an image or audio file path on the web.

Properties

liteRtLmPageLock → LiteRtLmPageLock
The page's lock, shared by the LLM web session and the EmbeddingGemma 2 web pass.
final
runtimeLogLevelSetByApp ↔ bool
The app set the level through LiteRtLmLog.level on this isolate: the Flutter adapter then leaves runtimeLogLevelSource alone.
getter/setter pair
runtimeLogLevelSource ↔ RuntimeLogLevel Function()?
Where currentRuntimeLogLevel reads the level from, when not runtimeLogLevel: the adapter points it at core's edgeAiLogLevel.
getter/setter pair
runtimeLogSink ↔ RuntimeLogSink
The sink runtimeLog writes to in this isolate; print, filtered by currentRuntimeLogLevel, unless replaced.
getter/setter pair
runtimeLogSinkSetByApp ↔ bool
The app set the sink through LiteRtLmLog.sink on this isolate: the Flutter adapter then leaves runtimeLogSink alone.
getter/setter pair

Functions

androidLibFileName(String name) → String
The file name name gets on Android and Linux (lib<name>.so).
checkEmbeddingRequest(List<Content> contents, {required Set<EmbedderModality> modalities, required bool hasText, required bool hasImages, required bool hasAudio}) → void
Refuses, as an ArgumentError, contents with no part, or with images or audio an engine of modalities was not loaded for.
conversationConfig(Conversation conversation) → ConversationConfig
The config conversation was created with, for the adapter's tests.
conversationForTest(ConversationHandle handle, {ConversationConfig? config, bool engineClosed()?, Set<void Function()>? engineCloseListeners}) → Conversation
A conversation over handle, for tests that drive it with a fake; a test calls engineCloseListeners as an engine's close would.
conversationHandle(Conversation conversation) → ConversationHandle
The handle under conversation.
embedderInputOfContents(List<Content> contents, Set<EmbedderModality> modalities) → EmbedderInput
contents as one embedder request: at most one text part, any image parts and at most one audio part. Throws ArgumentError for contents an engine of modalities does not take (checkEmbeddingRequest).
litertlmHasAudioEncoder(Iterable<String> modelTypes) → bool
Whether a bundle whose TFLiteModel sections have modelTypes carries an audio encoder.
litertlmHasAudioTower(Iterable<String> modelTypes) → bool
Whether a bundle whose TFLiteModel sections have modelTypes carries an audio tower: a tf_lite_audio_encoder_hw section, the one key LiteRT-LM builds its audio executor for (ModelType::kTfLiteAudioEncoderHw); only the 740m has it, beside tf_lite_audio_adapter and tf_lite_end_of_audio. Compiled at create like the vision tower (litertlmHasVisionTower).
litertlmHasVisionTower(Iterable<String> modelTypes) → bool
Whether a bundle whose TFLiteModel sections have modelTypes carries a vision tower: a tf_lite_vision_encoder section, the one key LiteRT-LM builds its vision executor for (runtime/core/embedding_engine_impl.cc, ModelType::kTfLiteVisionEncoder). The 440m and the 740m have it beside tf_lite_vision_adapter and tf_lite_end_of_vision, neither of which gets an executor of its own; the 270m has only tf_lite_text_encoder and tf_lite_embedder. LiteRT-LM compiles a present tower at create, declared or not: on its own backend when one is named, else on the main one.
liteRtLmNoAudioEncoderMessage(String file) → String
Why file cannot embed audio.
liteRtLmUnreadableContainerMessage(String file, String reason, {String looking = 'its audio encoder'}) → String
Why file's container could not be read to find looking.
markLibraryLoadFailure(Object error) → Object
error, thrown while a library loaded, marked as a LibraryLoadFailure of the same kind; anything else (an Error that is no load failure) as it is.
messageJson(Message message) → Map<String, Object?>
message as the Conversation API JSON object native reads.
messageRawJson(Message message) → String?
The JSON native wrote for message, when it was parsed from a reply chunk: the Flutter adapter hands it to core's own parser, which reads what Message does not keep (a call's id).
nativeAssetId(String name) → String
The asset id the build hook registers name under — the key Flutter writes into NativeAssetsManifest.json.
npuSentenceList(Iterable<String> items) → String
items joined for a sentence: A, A and B, A, B and C.
npuStackLibs(NpuStack vendor, String operatingSystem) → List<String>
Every library of vendor's stack on operatingSystem (Platform.operatingSystem spelling), as CodeAsset names: what NativeAssetsManifest.json lists when the build carries the stack, and what Android hands LiteRT as the dispatch directory.
npuVendorOf(NpuStamp target) → NpuStack?
The vendor this package dispatches a bundle stamped target to, or null when it has no dispatch for that vendor. Internal: not in the package's show list, so NpuStack stays out of the public API.
readLitertlmModelTypesFrom(Future<Uint8List> prefix(int length)) → Future<List<String>>
The model_type of every TFLiteModel section of a .litertlm file, lowercased, in file order, from prefix — a reader of the file's first length bytes (fewer when the file is shorter). It is asked for the 32-byte preamble, then for everything up to the header end.
requireLiteRtLmWebAudioEncoder(LiteRtLmWebRuntime runtime, String url, {required String fileName}) → Future<void>
Throws EmbedderLoadException unless the .litertlm bundle at url has an audio encoder, read from its container header through runtime's readPrefix (a few KB) — D23, the native rule (litertlm_container.dart): ModelInfo claims audio on the 270m and the 440m, and the web has no ModelInfo at all. A header that cannot be read or parsed is a load failure naming fileName, never "no audio".
requireLiteRtLmWebAudioEncoderFor(LiteRtLmWebEmbedderConfig config) → Future<void>
requireLiteRtLmWebAudioEncoder for the bundle config names, as describe() runs it before core closes the embedder it holds: the opfs:// path resolved to a blob: URL for the read, and that URL revoked after it, whatever the outcome.
runtimeLog(String message, {bool verbose = false}) → void
Logs message through runtimeLogSink, in debug builds only: the constant check lets a release build drop the call and its message.
samplerFor(SamplerConfig? config, BundleSampler bundle) → Sampler
The sampler native gets for config, or for the model file's bundle sampler completed with 0.8 / 40 / 0.95 / seed 1 when config is null.
thinkingContext(bool enableThinking) → Map<String, Object>
The extra_context that sets thinking for a LiteRT-LM conversation, the one source for the native and the web path.
toolsJson(List<Tool> tools) → String?
The tools_json native reads for tools, or null for none.
turnFailureCause(TurnFailedException e) → Object?
What failed under e, for the Flutter adapter, which hands core the error core's apps always caught; null when nothing did.
webSessionConfig(Sampler sampling, {int? maxOutputTokens}) → Map<String, Object>
The SessionConfig a web conversation is created with, as the map that is handed to @litert-lm/core: {samplerParams, maxOutputTokens?}.

Typedefs

LiteRtLmWebEmbedderInfo = ({int dimension, int? maxInputTokens, Set<EmbedderModality> modalities, int? visionTokensPerImage})
What a loaded LiteRtLmWebEmbedder reports.
LiteRtLmWebEmbedding = ({List<double> embedding, int inputLength, int numChunks, int? truncatedLength})
EmbeddingResponse: the vector and what the engine counted.
NativeBenchmark = ({List<NativeBenchmarkTurn> decode, double initSeconds, int maxNumTokens, List<NativeBenchmarkTurn> prefill, double timeToFirstTokenSeconds})
LiteRT-LM's benchmark record of a conversation (LiteRtLmBenchmarkInfo), turn by turn: the engine's init time, the first token's latency, every prefill and decode turn, and the context window the executor uses (0 before the first prefill).
NativeBenchmarkTurn = ({int tokens, double tokensPerSecond})
One prefill or decode turn of LiteRT-LM's benchmark record: its tokens and its speed (0 when the turn has no measurable duration).
RuntimeLogSink = void Function(String message, {bool verbose})
Where runtimeLog sends a message. verbose marks model output, prompts and native log contents; everything else is info.

Exceptions / Errors

ConstraintUnsupportedException
LiteRT-LM refused a response constraint (a JSON schema LLGuidance cannot compile). Core: ResponseFormatUnsupportedException.
EmbedderEngineException
A loaded embedder failed a request. Core: EmbeddingEngineException.
EmbedderInputTooLongException
An input longer than the embedder takes; never truncated. Core: EmbeddingInputTooLongException.
EmbedderLoadException
The embedder could not load. Core: EmbeddingLoadException.
LibraryLoadArgumentError
LibraryLoadFailedException
LibraryLoadStateError
LibraryLoadUnsupportedError
LiteRtLmBundleException
A .litertlm file that cannot be read, or cannot run as asked — thrown before any engine is created.
LiteRtLmEngineCreateException
LiteRT-LM's engine_settings_create or engine_create returned NULL for a backend.
LiteRtLmPagePoisonedError
The page's @litert-lm/core module may still be suspended in a call that never ended, so litertlm_dart runs nothing more on this page: reload it.
LiteRtLmTurnCancelledException
Native cancelled a turn that nobody on this side asked to cancel: the turn depended on an earlier cancelled one, so the conversation is poisoned and has to be rebuilt.
LiteRtLmTurnClosedException
A turn ended by closing its session or model before anyone asked to stop it (B90): a StateError, so a consumer of getResponseAsync sees one, and a type of its own, so the session's startTurn can report the close as TurnEnd.closed and end the text cleanly instead.
NpuDispatchUnavailableException
The NPU cannot be reached on this device: no dispatch stack in the build, no Qualcomm FastRPC or DSP on the device, or a dispatch directory that could not be prepared. message says which.
ScoringCancelledException
An option-scoring run was cancelled. Core: DeciderCancelledException.
StoppedTurnRewindException
The stopped turn could not be rewound, so the conversation must be rebuilt. code is the absl status code native returned (-1 when the call itself failed), lastTurnEnd how native's last send had ended.