Skip to content

HistoryManager

Defined in: packages/engine/src/lib/history/history-manager.ts:104

Per-session conversation history coordinator. Wraps a HistoryStore with the session-scoped policy the engine pipeline needs:

  • recordTurn writes a completed chart_request turn under a per-session async mutex, then truncates the session against the maxEntries / maxChars budgets.
  • addAssistantMessage persists a developer-supplied assistant message lock-free; idempotency is delegated to the store.
  • getLLMContext projects retained entries into the slim LLMContextMessage[] shape the prompt builder consumes.

createEngine constructs one of these internally when HistoryConfig is supplied; consumers building a custom engine pipeline can construct it directly via createHistoryManager.

Concurrency note: the per-session mutex is process-local. Distributed deployments must serialize chart_request turns externally (sticky routing, distributed lease, etc.) — see the README’s Concurrency section.

TMeta = unknown

addAssistantMessage(input): Promise<{ inserted: boolean; }>

Defined in: packages/engine/src/lib/history/history-manager.ts:122

Persist a developer-supplied assistant message into history.

Ordering. The store append is lock-free, so addAssistantMessage does not queue behind a long-running recordTurn. Callers that need an injection to be visible to the next chart_request must await the returned promise before issuing that request — the await is the ordering primitive, not internal serialization. Concurrent unawaited calls have no ordering guarantee against recordTurn reads.

Truncation, separately, runs under the per-session mutex so injection truncation and turn truncation cannot race their store.replace calls.

AssistantInjectionMessage

Promise<{ inserted: boolean; }>


clear(sessionId): Promise<void>

Defined in: packages/engine/src/lib/history/history-manager.ts:127

SessionId

Promise<void>


getHistory(sessionId): Promise<readonly HistoryEntry<TMeta>[]>

Defined in: packages/engine/src/lib/history/history-manager.ts:125

SessionId

Promise<readonly HistoryEntry<TMeta>[]>


getLLMContext(sessionId): Promise<readonly LLMContextMessage[]>

Defined in: packages/engine/src/lib/history/history-manager.ts:126

SessionId

Promise<readonly LLMContextMessage[]>


getResponseById(sessionId, messageId): Promise<GetResponseByIdResult>

Defined in: packages/engine/src/lib/history/history-manager.ts:134

Point-lookup of a previously recorded turn’s response. Pure passthrough to HistoryStore.getResponseById; lock-free read. See GetResponseByIdResult for the three outcomes (hit, miss, kind-mismatch).

SessionId

MessageId

Promise<GetResponseByIdResult>


recordTurn(input, output): Promise<void>

Defined in: packages/engine/src/lib/history/history-manager.ts:105

ChartRequestMessage

ChartResponseOutput

Promise<void>