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_requestturn under a per-session async mutex, then truncates the session against themaxEntries/maxCharsbudgets. - 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.
Type Parameters
Section titled “Type Parameters”TMeta = unknown
Methods
Section titled “Methods”addAssistantMessage()
Section titled “addAssistantMessage()”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.
Parameters
Section titled “Parameters”AssistantInjectionMessage
Returns
Section titled “Returns”Promise<{ inserted: boolean; }>
clear()
Section titled “clear()”clear(
sessionId):Promise<void>
Defined in: packages/engine/src/lib/history/history-manager.ts:127
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”SessionId
Returns
Section titled “Returns”Promise<void>
getHistory()
Section titled “getHistory()”getHistory(
sessionId):Promise<readonlyHistoryEntry<TMeta>[]>
Defined in: packages/engine/src/lib/history/history-manager.ts:125
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”SessionId
Returns
Section titled “Returns”Promise<readonly HistoryEntry<TMeta>[]>
getLLMContext()
Section titled “getLLMContext()”getLLMContext(
sessionId):Promise<readonlyLLMContextMessage[]>
Defined in: packages/engine/src/lib/history/history-manager.ts:126
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”SessionId
Returns
Section titled “Returns”Promise<readonly LLMContextMessage[]>
getResponseById()
Section titled “getResponseById()”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).
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”SessionId
messageId
Section titled “messageId”MessageId
Returns
Section titled “Returns”Promise<GetResponseByIdResult>
recordTurn()
Section titled “recordTurn()”recordTurn(
input,output):Promise<void>
Defined in: packages/engine/src/lib/history/history-manager.ts:105
Parameters
Section titled “Parameters”ChartRequestMessage
output
Section titled “output”ChartResponseOutput
Returns
Section titled “Returns”Promise<void>