Skip to content
1 min read · 155 words

Function: emitLifecycle()

ts
function emitLifecycle(
  hooks: BatteryLifecycleHooks | undefined,
  battery: BatteryLifecycleBattery,
  model: string,
  phase: BatteryLifecyclePhase,
  extra?: Partial<
    Pick<
      BatteryLifecycleReport,
      "error" | "raw" | "detail" | "progress" | "gpuBudget"
    >
  >,
  now?: () => string,
): void;

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

Build a BatteryLifecycleReport (stamping at) and dispatch it to the firehose (BatteryLifecycleHooks.onLifecycle) AND the per-phase hook for phase. A no-op when hooks is undefined or carries no relevant callbacks. Defensive: each callback is invoked through safeInvoke, so a throwing consumer never disrupts the battery.

Parameters

ParameterTypeDescription
hooks| BatteryLifecycleHooks | undefinedThe merged lifecycle hooks (may be undefined).
batteryBatteryLifecycleBatteryWhich battery is emitting.
modelstringBest-effort model id string.
phaseBatteryLifecyclePhaseThe phase being entered.
extra?Partial<Pick<BatteryLifecycleReport, "error" | "raw" | "detail" | "progress" | "gpuBudget">>Optional detail / progress / raw / error fields.
now?() => stringInjectable clock for tests; defaults to luxon DateTime.now().toISO().

Returns

void