Skip to content
2 min read · 302 words

Interface: BatteryLifecycleHooks

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

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:95
onComplete?BatteryLifecycleCallbackAfter the turn's output is parsed + persisted, before ack (fires per turn).src/batteries/llm/chat_common/lifecycle.ts:105
onError?BatteryLifecycleCallbackA load or generation failure (paired with nack).src/batteries/llm/chat_common/lifecycle.ts:107
onGenerating?BatteryLifecycleCallbackThe generate call is in progress (fires per turn). Fires once immediately before the provider call for most engines; engines that stream per-step generation progress (e.g. a diffusion denoise loop) fire it REPEATEDLY during generation, each carrying a progress in 0..1.src/batteries/llm/chat_common/lifecycle.ts:103
onLifecycle?BatteryLifecycleCallbackFires on EVERY phase transition (the firehose).src/batteries/llm/chat_common/lifecycle.ts:86
onLoading?BatteryLifecycleCallbackWeights/runtime loading — may fire repeatedly with progress as the provider reports it.src/batteries/llm/chat_common/lifecycle.ts:88
onReady?BatteryLifecycleCallbackEngine/pipeline resolved and cached, before the first generation.src/batteries/llm/chat_common/lifecycle.ts:97