Chat Sessions
chat/sessions
Section titled “chat/sessions”Classes
Section titled “Classes”FileSessionStore
Section titled “FileSessionStore”Defined in: chat/sessions.ts:292
File-based session store. Each session is a JSON file on disk.
Uses FileStorage internally.
Example
Section titled “Example”const store = new FileSessionStore({ directory: "./data/sessions" });const session = await store.createSession({ config: { model: "claude-3", backend: "claude" },});Extends
Section titled “Extends”BaseSessionStore
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FileSessionStore(
options):FileSessionStore
Defined in: chat/sessions.ts:293
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Overrides
Section titled “Overrides”BaseSessionStore.constructor
Properties
Section titled “Properties”adapter
Section titled “adapter”
protectedreadonlyadapter:IStorageAdapter<ChatSession<Record<string,unknown>>>
Defined in: chat/sessions.ts:116
Inherited from
Section titled “Inherited from”BaseSessionStore.adapter
Methods
Section titled “Methods”appendMessage()
Section titled “appendMessage()”appendMessage(
sessionId,message):Promise<void>
Defined in: chat/sessions.ts:179
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”message
Section titled “message”Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.appendMessage
clear()
Section titled “clear()”clear():
Promise<void>
Defined in: chat/sessions.ts:247
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.clear
count()
Section titled “count()”count():
Promise<number>
Defined in: chat/sessions.ts:243
Returns
Section titled “Returns”Promise<number>
Inherited from
Section titled “Inherited from”BaseSessionStore.count
createSession()
Section titled “createSession()”createSession(
options):Promise<ChatSession<Record<string,unknown>>>
Defined in: chat/sessions.ts:118
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>>
Inherited from
Section titled “Inherited from”BaseSessionStore.createSession
deleteSession()
Section titled “deleteSession()”deleteSession(
id):Promise<void>
Defined in: chat/sessions.ts:175
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.deleteSession
getSession()
Section titled “getSession()”getSession(
id):Promise<ChatSession<Record<string,unknown>> |null>
Defined in: chat/sessions.ts:144
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>> | null>
Inherited from
Section titled “Inherited from”BaseSessionStore.getSession
listSessions()
Section titled “listSessions()”listSessions(
options?):Promise<ChatSession<Record<string,unknown>>[]>
Defined in: chat/sessions.ts:148
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>[]>
Inherited from
Section titled “Inherited from”BaseSessionStore.listSessions
loadMessages()
Section titled “loadMessages()”loadMessages(
sessionId,options?):Promise<PaginatedMessages>
Defined in: chat/sessions.ts:204
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”options?
Section titled “options?”limit?
Section titled “limit?”number
offset?
Section titled “offset?”number
Returns
Section titled “Returns”Promise<PaginatedMessages>
Inherited from
Section titled “Inherited from”BaseSessionStore.loadMessages
saveMessages()
Section titled “saveMessages()”saveMessages(
sessionId,messages):Promise<void>
Defined in: chat/sessions.ts:190
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”messages
Section titled “messages”ChatMessage<unknown>[]
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.saveMessages
searchSessions()
Section titled “searchSessions()”searchSessions(
options):Promise<ChatSession<Record<string,unknown>>[]>
Defined in: chat/sessions.ts:223
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>[]>
Inherited from
Section titled “Inherited from”BaseSessionStore.searchSessions
updateConfig()
Section titled “updateConfig()”updateConfig(
id,config):Promise<void>
Defined in: chat/sessions.ts:162
Parameters
Section titled “Parameters”config
Section titled “config”Partial<ChatSessionConfig>
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.updateConfig
updateTitle()
Section titled “updateTitle()”updateTitle(
id,title):Promise<void>
Defined in: chat/sessions.ts:152
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.updateTitle
InMemorySessionStore
Section titled “InMemorySessionStore”Defined in: chat/sessions.ts:266
In-memory session store. Data is lost when the process exits.
Uses InMemoryStorage internally.
Example
Section titled “Example”const store = new InMemorySessionStore();const session = await store.createSession({ config: { model: "gpt-4", backend: "vercel-ai" },});Extends
Section titled “Extends”BaseSessionStore
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new InMemorySessionStore():
InMemorySessionStore
Defined in: chat/sessions.ts:267
Returns
Section titled “Returns”Overrides
Section titled “Overrides”BaseSessionStore.constructor
Properties
Section titled “Properties”adapter
Section titled “adapter”
protectedreadonlyadapter:IStorageAdapter<ChatSession<Record<string,unknown>>>
Defined in: chat/sessions.ts:116
Inherited from
Section titled “Inherited from”BaseSessionStore.adapter
Methods
Section titled “Methods”appendMessage()
Section titled “appendMessage()”appendMessage(
sessionId,message):Promise<void>
Defined in: chat/sessions.ts:179
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”message
Section titled “message”Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.appendMessage
clear()
Section titled “clear()”clear():
Promise<void>
Defined in: chat/sessions.ts:247
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.clear
count()
Section titled “count()”count():
Promise<number>
Defined in: chat/sessions.ts:243
Returns
Section titled “Returns”Promise<number>
Inherited from
Section titled “Inherited from”BaseSessionStore.count
createSession()
Section titled “createSession()”createSession(
options):Promise<ChatSession<Record<string,unknown>>>
Defined in: chat/sessions.ts:118
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>>
Inherited from
Section titled “Inherited from”BaseSessionStore.createSession
deleteSession()
Section titled “deleteSession()”deleteSession(
id):Promise<void>
Defined in: chat/sessions.ts:175
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.deleteSession
getSession()
Section titled “getSession()”getSession(
id):Promise<ChatSession<Record<string,unknown>> |null>
Defined in: chat/sessions.ts:144
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>> | null>
Inherited from
Section titled “Inherited from”BaseSessionStore.getSession
listSessions()
Section titled “listSessions()”listSessions(
options?):Promise<ChatSession<Record<string,unknown>>[]>
Defined in: chat/sessions.ts:148
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>[]>
Inherited from
Section titled “Inherited from”BaseSessionStore.listSessions
loadMessages()
Section titled “loadMessages()”loadMessages(
sessionId,options?):Promise<PaginatedMessages>
Defined in: chat/sessions.ts:204
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”options?
Section titled “options?”limit?
Section titled “limit?”number
offset?
Section titled “offset?”number
Returns
Section titled “Returns”Promise<PaginatedMessages>
Inherited from
Section titled “Inherited from”BaseSessionStore.loadMessages
saveMessages()
Section titled “saveMessages()”saveMessages(
sessionId,messages):Promise<void>
Defined in: chat/sessions.ts:190
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”messages
Section titled “messages”ChatMessage<unknown>[]
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.saveMessages
searchSessions()
Section titled “searchSessions()”searchSessions(
options):Promise<ChatSession<Record<string,unknown>>[]>
Defined in: chat/sessions.ts:223
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>[]>
Inherited from
Section titled “Inherited from”BaseSessionStore.searchSessions
updateConfig()
Section titled “updateConfig()”updateConfig(
id,config):Promise<void>
Defined in: chat/sessions.ts:162
Parameters
Section titled “Parameters”config
Section titled “config”Partial<ChatSessionConfig>
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.updateConfig
updateTitle()
Section titled “updateTitle()”updateTitle(
id,title):Promise<void>
Defined in: chat/sessions.ts:152
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”BaseSessionStore.updateTitle
Interfaces
Section titled “Interfaces”CreateSessionOptions
Section titled “CreateSessionOptions”Defined in: chat/sessions.ts:23
Options for creating a new session
Type Parameters
Section titled “Type Parameters”TCustom
Section titled “TCustom”TCustom extends Record<string, unknown> = Record<string, unknown>
Properties
Section titled “Properties”config?
Section titled “config?”
optionalconfig:Partial<ChatSessionConfig>
Defined in: chat/sessions.ts:27
Session configuration (optional — runtime defaults used when omitted)
custom?
Section titled “custom?”
optionalcustom:TCustom
Defined in: chat/sessions.ts:31
Custom metadata
optionaltags:string[]
Defined in: chat/sessions.ts:29
Initial tags
title?
Section titled “title?”
optionaltitle:string
Defined in: chat/sessions.ts:25
Session title (defaults to “Untitled”)
FileSessionStoreOptions
Section titled “FileSessionStoreOptions”Defined in: chat/sessions.ts:275
Configuration for FileSessionStore
Properties
Section titled “Properties”directory
Section titled “directory”directory:
string
Defined in: chat/sessions.ts:277
Directory to store session JSON files
IChatSessionStore
Section titled “IChatSessionStore”Defined in: chat/sessions.ts:107
Full session store interface — union of reader and writer. Backward-compatible: all existing implementations continue to work.
Example
Section titled “Example”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 });Extends
Section titled “Extends”Methods
Section titled “Methods”appendMessage()
Section titled “appendMessage()”appendMessage(
sessionId,message):Promise<void>
Defined in: chat/sessions.ts:88
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”message
Section titled “message”Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”clear()
Section titled “clear()”clear():
Promise<void>
Defined in: chat/sessions.ts:90
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”count()
Section titled “count()”count():
Promise<number>
Defined in: chat/sessions.ts:76
Returns
Section titled “Returns”Promise<number>
Inherited from
Section titled “Inherited from”createSession()
Section titled “createSession()”createSession(
options):Promise<ChatSession<Record<string,unknown>>>
Defined in: chat/sessions.ts:84
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>>
Inherited from
Section titled “Inherited from”deleteSession()
Section titled “deleteSession()”deleteSession(
id):Promise<void>
Defined in: chat/sessions.ts:87
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”dispose()?
Section titled “dispose()?”
optionaldispose():Promise<void>
Defined in: chat/sessions.ts:92
Release any resources held by this store (optional).
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”getSession()
Section titled “getSession()”getSession(
id):Promise<ChatSession<Record<string,unknown>> |null>
Defined in: chat/sessions.ts:69
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>> | null>
Inherited from
Section titled “Inherited from”listSessions()
Section titled “listSessions()”listSessions(
options?):Promise<ChatSession<Record<string,unknown>>[]>
Defined in: chat/sessions.ts:70
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>[]>
Inherited from
Section titled “Inherited from”loadMessages()
Section titled “loadMessages()”loadMessages(
sessionId,options?):Promise<PaginatedMessages>
Defined in: chat/sessions.ts:71
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”options?
Section titled “options?”limit?
Section titled “limit?”number
offset?
Section titled “offset?”number
Returns
Section titled “Returns”Promise<PaginatedMessages>
Inherited from
Section titled “Inherited from”saveMessages()
Section titled “saveMessages()”saveMessages(
sessionId,messages):Promise<void>
Defined in: chat/sessions.ts:89
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”messages
Section titled “messages”ChatMessage<unknown>[]
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”searchSessions()
Section titled “searchSessions()”searchSessions(
options):Promise<ChatSession<Record<string,unknown>>[]>
Defined in: chat/sessions.ts:75
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>[]>
Inherited from
Section titled “Inherited from”updateConfig()
Section titled “updateConfig()”updateConfig(
id,config):Promise<void>
Defined in: chat/sessions.ts:86
Parameters
Section titled “Parameters”config
Section titled “config”Partial<ChatSessionConfig>
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”updateTitle()
Section titled “updateTitle()”updateTitle(
id,title):Promise<void>
Defined in: chat/sessions.ts:85
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”ISessionReader
Section titled “ISessionReader”Defined in: chat/sessions.ts:68
Read-only session operations. Consumers needing read-only access (dashboards, analytics) implement only this.
Extended by
Section titled “Extended by”Methods
Section titled “Methods”count()
Section titled “count()”count():
Promise<number>
Defined in: chat/sessions.ts:76
Returns
Section titled “Returns”Promise<number>
getSession()
Section titled “getSession()”getSession(
id):Promise<ChatSession<Record<string,unknown>> |null>
Defined in: chat/sessions.ts:69
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>> | null>
listSessions()
Section titled “listSessions()”listSessions(
options?):Promise<ChatSession<Record<string,unknown>>[]>
Defined in: chat/sessions.ts:70
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>[]>
loadMessages()
Section titled “loadMessages()”loadMessages(
sessionId,options?):Promise<PaginatedMessages>
Defined in: chat/sessions.ts:71
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”options?
Section titled “options?”limit?
Section titled “limit?”number
offset?
Section titled “offset?”number
Returns
Section titled “Returns”Promise<PaginatedMessages>
searchSessions()
Section titled “searchSessions()”searchSessions(
options):Promise<ChatSession<Record<string,unknown>>[]>
Defined in: chat/sessions.ts:75
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>[]>
ISessionWriter
Section titled “ISessionWriter”Defined in: chat/sessions.ts:83
Write/mutate session operations. Consumers needing full access implement both ISessionReader & ISessionWriter.
Extended by
Section titled “Extended by”Methods
Section titled “Methods”appendMessage()
Section titled “appendMessage()”appendMessage(
sessionId,message):Promise<void>
Defined in: chat/sessions.ts:88
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”message
Section titled “message”Returns
Section titled “Returns”Promise<void>
clear()
Section titled “clear()”clear():
Promise<void>
Defined in: chat/sessions.ts:90
Returns
Section titled “Returns”Promise<void>
createSession()
Section titled “createSession()”createSession(
options):Promise<ChatSession<Record<string,unknown>>>
Defined in: chat/sessions.ts:84
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Promise<ChatSession<Record<string, unknown>>>
deleteSession()
Section titled “deleteSession()”deleteSession(
id):Promise<void>
Defined in: chat/sessions.ts:87
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<void>
dispose()?
Section titled “dispose()?”
optionaldispose():Promise<void>
Defined in: chat/sessions.ts:92
Release any resources held by this store (optional).
Returns
Section titled “Returns”Promise<void>
saveMessages()
Section titled “saveMessages()”saveMessages(
sessionId,messages):Promise<void>
Defined in: chat/sessions.ts:89
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”messages
Section titled “messages”ChatMessage<unknown>[]
Returns
Section titled “Returns”Promise<void>
updateConfig()
Section titled “updateConfig()”updateConfig(
id,config):Promise<void>
Defined in: chat/sessions.ts:86
Parameters
Section titled “Parameters”config
Section titled “config”Partial<ChatSessionConfig>
Returns
Section titled “Returns”Promise<void>
updateTitle()
Section titled “updateTitle()”updateTitle(
id,title):Promise<void>
Defined in: chat/sessions.ts:85
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
PaginatedMessages
Section titled “PaginatedMessages”Defined in: chat/sessions.ts:35
Paginated result of messages
Properties
Section titled “Properties”hasMore
Section titled “hasMore”hasMore:
boolean
Defined in: chat/sessions.ts:41
Whether there are more messages after this page
messages
Section titled “messages”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
SessionListOptions
Section titled “SessionListOptions”Defined in: chat/sessions.ts:45
Options for listing sessions
Properties
Section titled “Properties”filter()?
Section titled “filter()?”
optionalfilter: (session) =>boolean
Defined in: chat/sessions.ts:47
Filter predicate
Parameters
Section titled “Parameters”session
Section titled “session”Returns
Section titled “Returns”boolean
limit?
Section titled “limit?”
optionallimit:number
Defined in: chat/sessions.ts:51
Maximum number of sessions to return
offset?
Section titled “offset?”
optionaloffset:number
Defined in: chat/sessions.ts:53
Number of sessions to skip
sort()?
Section titled “sort()?”
optionalsort: (a,b) =>number
Defined in: chat/sessions.ts:49
Sort comparator
Parameters
Section titled “Parameters”Returns
Section titled “Returns”number
SessionSearchOptions
Section titled “SessionSearchOptions”Defined in: chat/sessions.ts:57
Search options for finding sessions
Properties
Section titled “Properties”limit?
Section titled “limit?”
optionallimit: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
References
Section titled “References”StorageError
Section titled “StorageError”Re-exports StorageError