Skip to content

Chat Sessions

Defined in: chat/sessions.ts:292

File-based session store. Each session is a JSON file on disk. Uses FileStorage internally.

const store = new FileSessionStore({ directory: "./data/sessions" });
const session = await store.createSession({
config: { model: "claude-3", backend: "claude" },
});
  • BaseSessionStore

new FileSessionStore(options): FileSessionStore

Defined in: chat/sessions.ts:293

FileSessionStoreOptions

FileSessionStore

BaseSessionStore.constructor

protected readonly adapter: IStorageAdapter<ChatSession<Record<string, unknown>>>

Defined in: chat/sessions.ts:116

BaseSessionStore.adapter

appendMessage(sessionId, message): Promise<void>

Defined in: chat/sessions.ts:179

ChatId

ChatMessage

Promise<void>

BaseSessionStore.appendMessage

clear(): Promise<void>

Defined in: chat/sessions.ts:247

Promise<void>

BaseSessionStore.clear

count(): Promise<number>

Defined in: chat/sessions.ts:243

Promise<number>

BaseSessionStore.count

createSession(options): Promise<ChatSession<Record<string, unknown>>>

Defined in: chat/sessions.ts:118

CreateSessionOptions

Promise<ChatSession<Record<string, unknown>>>

BaseSessionStore.createSession

deleteSession(id): Promise<void>

Defined in: chat/sessions.ts:175

ChatId

Promise<void>

BaseSessionStore.deleteSession

getSession(id): Promise<ChatSession<Record<string, unknown>> | null>

Defined in: chat/sessions.ts:144

ChatId

Promise<ChatSession<Record<string, unknown>> | null>

BaseSessionStore.getSession

listSessions(options?): Promise<ChatSession<Record<string, unknown>>[]>

Defined in: chat/sessions.ts:148

SessionListOptions

Promise<ChatSession<Record<string, unknown>>[]>

BaseSessionStore.listSessions

loadMessages(sessionId, options?): Promise<PaginatedMessages>

Defined in: chat/sessions.ts:204

ChatId

number

number

Promise<PaginatedMessages>

BaseSessionStore.loadMessages

saveMessages(sessionId, messages): Promise<void>

Defined in: chat/sessions.ts:190

ChatId

ChatMessage<unknown>[]

Promise<void>

BaseSessionStore.saveMessages

searchSessions(options): Promise<ChatSession<Record<string, unknown>>[]>

Defined in: chat/sessions.ts:223

SessionSearchOptions

Promise<ChatSession<Record<string, unknown>>[]>

BaseSessionStore.searchSessions

updateConfig(id, config): Promise<void>

Defined in: chat/sessions.ts:162

ChatId

Partial<ChatSessionConfig>

Promise<void>

BaseSessionStore.updateConfig

updateTitle(id, title): Promise<void>

Defined in: chat/sessions.ts:152

ChatId

string

Promise<void>

BaseSessionStore.updateTitle


Defined in: chat/sessions.ts:266

In-memory session store. Data is lost when the process exits. Uses InMemoryStorage internally.

const store = new InMemorySessionStore();
const session = await store.createSession({
config: { model: "gpt-4", backend: "vercel-ai" },
});
  • BaseSessionStore

new InMemorySessionStore(): InMemorySessionStore

Defined in: chat/sessions.ts:267

InMemorySessionStore

BaseSessionStore.constructor

protected readonly adapter: IStorageAdapter<ChatSession<Record<string, unknown>>>

Defined in: chat/sessions.ts:116

BaseSessionStore.adapter

appendMessage(sessionId, message): Promise<void>

Defined in: chat/sessions.ts:179

ChatId

ChatMessage

Promise<void>

BaseSessionStore.appendMessage

clear(): Promise<void>

Defined in: chat/sessions.ts:247

Promise<void>

BaseSessionStore.clear

count(): Promise<number>

Defined in: chat/sessions.ts:243

Promise<number>

BaseSessionStore.count

createSession(options): Promise<ChatSession<Record<string, unknown>>>

Defined in: chat/sessions.ts:118

CreateSessionOptions

Promise<ChatSession<Record<string, unknown>>>

BaseSessionStore.createSession

deleteSession(id): Promise<void>

Defined in: chat/sessions.ts:175

ChatId

Promise<void>

BaseSessionStore.deleteSession

getSession(id): Promise<ChatSession<Record<string, unknown>> | null>

Defined in: chat/sessions.ts:144

ChatId

Promise<ChatSession<Record<string, unknown>> | null>

BaseSessionStore.getSession

listSessions(options?): Promise<ChatSession<Record<string, unknown>>[]>

Defined in: chat/sessions.ts:148

SessionListOptions

Promise<ChatSession<Record<string, unknown>>[]>

BaseSessionStore.listSessions

loadMessages(sessionId, options?): Promise<PaginatedMessages>

Defined in: chat/sessions.ts:204

ChatId

number

number

Promise<PaginatedMessages>

BaseSessionStore.loadMessages

saveMessages(sessionId, messages): Promise<void>

Defined in: chat/sessions.ts:190

ChatId

ChatMessage<unknown>[]

Promise<void>

BaseSessionStore.saveMessages

searchSessions(options): Promise<ChatSession<Record<string, unknown>>[]>

Defined in: chat/sessions.ts:223

SessionSearchOptions

Promise<ChatSession<Record<string, unknown>>[]>

BaseSessionStore.searchSessions

updateConfig(id, config): Promise<void>

Defined in: chat/sessions.ts:162

ChatId

Partial<ChatSessionConfig>

Promise<void>

BaseSessionStore.updateConfig

updateTitle(id, title): Promise<void>

Defined in: chat/sessions.ts:152

ChatId

string

Promise<void>

BaseSessionStore.updateTitle

Defined in: chat/sessions.ts:23

Options for creating a new session

TCustom extends Record<string, unknown> = Record<string, unknown>

optional config: Partial<ChatSessionConfig>

Defined in: chat/sessions.ts:27

Session configuration (optional — runtime defaults used when omitted)

optional custom: TCustom

Defined in: chat/sessions.ts:31

Custom metadata

optional tags: string[]

Defined in: chat/sessions.ts:29

Initial tags

optional title: string

Defined in: chat/sessions.ts:25

Session title (defaults to “Untitled”)


Defined in: chat/sessions.ts:275

Configuration for FileSessionStore

directory: string

Defined in: chat/sessions.ts:277

Directory to store session JSON files


Defined in: chat/sessions.ts:107

Full session store interface — union of reader and writer. Backward-compatible: all existing implementations continue to work.

const store = new InMemorySessionStore();
const session = await store.createSession({ config: { model: "gpt-4", backend: "vercel-ai" } });
await store.appendMessage(session.id, message);
const page = await store.loadMessages(session.id, { limit: 20, offset: 0 });

appendMessage(sessionId, message): Promise<void>

Defined in: chat/sessions.ts:88

ChatId

ChatMessage

Promise<void>

ISessionWriter.appendMessage

clear(): Promise<void>

Defined in: chat/sessions.ts:90

Promise<void>

ISessionWriter.clear

count(): Promise<number>

Defined in: chat/sessions.ts:76

Promise<number>

ISessionReader.count

createSession(options): Promise<ChatSession<Record<string, unknown>>>

Defined in: chat/sessions.ts:84

CreateSessionOptions

Promise<ChatSession<Record<string, unknown>>>

ISessionWriter.createSession

deleteSession(id): Promise<void>

Defined in: chat/sessions.ts:87

ChatId

Promise<void>

ISessionWriter.deleteSession

optional dispose(): Promise<void>

Defined in: chat/sessions.ts:92

Release any resources held by this store (optional).

Promise<void>

ISessionWriter.dispose

getSession(id): Promise<ChatSession<Record<string, unknown>> | null>

Defined in: chat/sessions.ts:69

ChatId

Promise<ChatSession<Record<string, unknown>> | null>

ISessionReader.getSession

listSessions(options?): Promise<ChatSession<Record<string, unknown>>[]>

Defined in: chat/sessions.ts:70

SessionListOptions

Promise<ChatSession<Record<string, unknown>>[]>

ISessionReader.listSessions

loadMessages(sessionId, options?): Promise<PaginatedMessages>

Defined in: chat/sessions.ts:71

ChatId

number

number

Promise<PaginatedMessages>

ISessionReader.loadMessages

saveMessages(sessionId, messages): Promise<void>

Defined in: chat/sessions.ts:89

ChatId

ChatMessage<unknown>[]

Promise<void>

ISessionWriter.saveMessages

searchSessions(options): Promise<ChatSession<Record<string, unknown>>[]>

Defined in: chat/sessions.ts:75

SessionSearchOptions

Promise<ChatSession<Record<string, unknown>>[]>

ISessionReader.searchSessions

updateConfig(id, config): Promise<void>

Defined in: chat/sessions.ts:86

ChatId

Partial<ChatSessionConfig>

Promise<void>

ISessionWriter.updateConfig

updateTitle(id, title): Promise<void>

Defined in: chat/sessions.ts:85

ChatId

string

Promise<void>

ISessionWriter.updateTitle


Defined in: chat/sessions.ts:68

Read-only session operations. Consumers needing read-only access (dashboards, analytics) implement only this.

count(): Promise<number>

Defined in: chat/sessions.ts:76

Promise<number>

getSession(id): Promise<ChatSession<Record<string, unknown>> | null>

Defined in: chat/sessions.ts:69

ChatId

Promise<ChatSession<Record<string, unknown>> | null>

listSessions(options?): Promise<ChatSession<Record<string, unknown>>[]>

Defined in: chat/sessions.ts:70

SessionListOptions

Promise<ChatSession<Record<string, unknown>>[]>

loadMessages(sessionId, options?): Promise<PaginatedMessages>

Defined in: chat/sessions.ts:71

ChatId

number

number

Promise<PaginatedMessages>

searchSessions(options): Promise<ChatSession<Record<string, unknown>>[]>

Defined in: chat/sessions.ts:75

SessionSearchOptions

Promise<ChatSession<Record<string, unknown>>[]>


Defined in: chat/sessions.ts:83

Write/mutate session operations. Consumers needing full access implement both ISessionReader & ISessionWriter.

appendMessage(sessionId, message): Promise<void>

Defined in: chat/sessions.ts:88

ChatId

ChatMessage

Promise<void>

clear(): Promise<void>

Defined in: chat/sessions.ts:90

Promise<void>

createSession(options): Promise<ChatSession<Record<string, unknown>>>

Defined in: chat/sessions.ts:84

CreateSessionOptions

Promise<ChatSession<Record<string, unknown>>>

deleteSession(id): Promise<void>

Defined in: chat/sessions.ts:87

ChatId

Promise<void>

optional dispose(): Promise<void>

Defined in: chat/sessions.ts:92

Release any resources held by this store (optional).

Promise<void>

saveMessages(sessionId, messages): Promise<void>

Defined in: chat/sessions.ts:89

ChatId

ChatMessage<unknown>[]

Promise<void>

updateConfig(id, config): Promise<void>

Defined in: chat/sessions.ts:86

ChatId

Partial<ChatSessionConfig>

Promise<void>

updateTitle(id, title): Promise<void>

Defined in: chat/sessions.ts:85

ChatId

string

Promise<void>


Defined in: chat/sessions.ts:35

Paginated result of messages

hasMore: boolean

Defined in: chat/sessions.ts:41

Whether there are more messages after this page

messages: ChatMessage<unknown>[]

Defined in: chat/sessions.ts:37

Messages in this page

total: number

Defined in: chat/sessions.ts:39

Total number of messages in session


Defined in: chat/sessions.ts:45

Options for listing sessions

optional filter: (session) => boolean

Defined in: chat/sessions.ts:47

Filter predicate

ChatSession

boolean

optional limit: number

Defined in: chat/sessions.ts:51

Maximum number of sessions to return

optional offset: number

Defined in: chat/sessions.ts:53

Number of sessions to skip

optional sort: (a, b) => number

Defined in: chat/sessions.ts:49

Sort comparator

ChatSession

ChatSession

number


Defined in: chat/sessions.ts:57

Search options for finding sessions

optional limit: number

Defined in: chat/sessions.ts:61

Maximum results (default: 20)

query: string

Defined in: chat/sessions.ts:59

Text query to match against title and message content

Re-exports StorageError