Skip to content

bodhi-realtime-agent / ConversationHistoryWriter

Class: ConversationHistoryWriter ​

Defined in: src/core/conversation-history-writer.ts:38

EventBus-driven writer that persists conversation items to a ConversationHistoryStore.

Subscribes to session lifecycle events and flushes incremental batches of conversation items (since the last checkpoint) to the store. Tracks session analytics counters and writes a final SessionReport on session close.

Ordered persistence: store writes run through a serial queue (start → flushes → close in order). drain() awaits the queue — VoiceSession.start() awaits it after the start-phase (so a resumed record reads active before start resolves) and VoiceSession.close() awaits it before tearing down the event bus (so the final report always lands).

Call dispose() to unsubscribe from all events.

Constructors ​

Constructor ​

new ConversationHistoryWriter(sessionId, userId, initialAgentName, eventBus, conversationContext, store, sessionMetadata?, resume?): ConversationHistoryWriter

Defined in: src/core/conversation-history-writer.ts:53

Parameters ​

sessionId ​

string

userId ​

string

initialAgentName ​

string

eventBus ​

IEventBus

conversationContext ​

ConversationContext

store ​

ConversationHistoryStore

sessionMetadata? ​

Record<string, unknown>

resume? ​

HistoryWriterResumeOptions

Returns ​

ConversationHistoryWriter

Methods ​

dispose() ​

dispose(): void

Defined in: src/core/conversation-history-writer.ts:108

Returns ​

void


drain() ​

drain(): Promise<void>

Defined in: src/core/conversation-history-writer.ts:116

Await all queued store writes (start-phase, flushes, close report). Never rejects.

Returns ​

Promise<void>


flushNow() ​

flushNow(): void

Defined in: src/core/conversation-history-writer.ts:128

Persist the items added since the last checkpoint now, instead of waiting for the next turn.end, agent.transfer or session.close. The write joins the serial queue (so drain() awaits it) and the checkpoint advances at once, so a later flush does not persist the same items again. Items behind a still-pending reserved user message stay unflushed, as with every other flush.

Returns ​

void

Built with VitePress