Skip to content

sessions / Exports / SimpleConversationHistory

Class: SimpleConversationHistory

Simple in-memory conversation history implementation for session management

Provides basic conversation storage with optional message limiting. Suitable for lightweight session scenarios where conversation persistence is not required beyond the current session lifecycle.

See

../../../apps/examples/04-sessions | Session Examples

Implements

Table of contents

Constructors

Methods

Constructors

constructor

new SimpleConversationHistory(maxMessages?): SimpleConversationHistory

Create a new simple conversation history instance

Parameters

NameTypeDescription
maxMessages?numberOptional maximum number of messages to retain. When exceeded, oldest messages are automatically removed.

Returns

SimpleConversationHistory

Defined in

packages/sessions/src/conversation-history/simple-conversation-history.ts:28

Methods

addMessage

addMessage(message): void

Add a message to the conversation history

Automatically applies message limiting if configured.

Parameters

NameTypeDescription
messageUniversalMessageUniversal message to add to the conversation

Returns

void

Implementation of

ConversationHistoryInterface.addMessage

Defined in

packages/sessions/src/conversation-history/simple-conversation-history.ts:39


getMessages

getMessages(): UniversalMessage[]

Get all messages in the conversation

Returns

UniversalMessage[]

Copy of all messages in chronological order

Implementation of

ConversationHistoryInterface.getMessages

Defined in

packages/sessions/src/conversation-history/simple-conversation-history.ts:52


getMessageCount

getMessageCount(): number

Get the total number of messages in the conversation

Returns

number

Current message count

Implementation of

ConversationHistoryInterface.getMessageCount

Defined in

packages/sessions/src/conversation-history/simple-conversation-history.ts:61


clear

clear(): void

Clear all messages from the conversation history

Returns

void

Implementation of

ConversationHistoryInterface.clear

Defined in

packages/sessions/src/conversation-history/simple-conversation-history.ts:68


getLastMessage

getLastMessage(): any

Get the most recent message in the conversation

Returns

any

Last message or null if conversation is empty

Implementation of

ConversationHistoryInterface.getLastMessage

Defined in

packages/sessions/src/conversation-history/simple-conversation-history.ts:77


getLastUserMessage

getLastUserMessage(): any

Get the most recent user message in the conversation

Searches backwards through the conversation to find the latest user message.

Returns

any

Last user message or null if no user messages exist

Implementation of

ConversationHistoryInterface.getLastUserMessage

Defined in

packages/sessions/src/conversation-history/simple-conversation-history.ts:88


getLastAssistantMessage

getLastAssistantMessage(): any

Get the most recent assistant message in the conversation

Searches backwards through the conversation to find the latest assistant message.

Returns

any

Last assistant message or null if no assistant messages exist

Implementation of

ConversationHistoryInterface.getLastAssistantMessage

Defined in

packages/sessions/src/conversation-history/simple-conversation-history.ts:104

Released under the MIT License.