Skip to content
1 min read · 266 words

Interface: BatteryLifecycleHooks

Defined in: src/batteries/llm/chat_common/lifecycle.ts:78

The opt-in lifecycle option block mixed into each battery's options interface. Every phase transition fires onLifecycle (the firehose) AND the matching per-phase hook; subscribe to either or both. All optional — omitting them leaves behavior byte-for-byte unchanged.

Extended by

Properties

PropertyTypeDescriptionDefined in
onCompiling?BatteryLifecycleCallbackEngine/graph/shader compilation after download, before the first token. A COARSE marker: the on-device runtimes (LiteRT Engine.create, transformers.js from_pretrained) expose the boundary — download done, opaque WebGPU/WASM graph build about to run — but NOT a progress stream, so progress is usually absent. Often the slowest part of a cold start; without this it was invisible.src/batteries/llm/chat_common/lifecycle.ts:89
onComplete?BatteryLifecycleCallbackAfter the turn's output is parsed + persisted, before ack (fires per turn).src/batteries/llm/chat_common/lifecycle.ts:95
onError?BatteryLifecycleCallbackA load or generation failure (paired with nack).src/batteries/llm/chat_common/lifecycle.ts:97
onGenerating?BatteryLifecycleCallbackImmediately before the provider generate call (fires per turn).src/batteries/llm/chat_common/lifecycle.ts:93
onLifecycle?BatteryLifecycleCallbackFires on EVERY phase transition (the firehose).src/batteries/llm/chat_common/lifecycle.ts:80
onLoading?BatteryLifecycleCallbackWeights/runtime loading — may fire repeatedly with progress as the provider reports it.src/batteries/llm/chat_common/lifecycle.ts:82
onReady?BatteryLifecycleCallbackEngine/pipeline resolved and cached, before the first generation.src/batteries/llm/chat_common/lifecycle.ts:91