Chat Backends
chat/backends
Section titled “chat/backends”Classes
Section titled “Classes”abstract ResumableChatAdapter
Section titled “abstract ResumableChatAdapter”Defined in: chat/backends/resumable.ts:28
Abstract base for backend adapters that support session resume. Handles backendSessionId tracking, canResume(), resume(), captureSessionId(). Subclasses only define constructor (with backend-specific options) and createService().
Extends
Section titled “Extends”Extended by
Section titled “Extended by”Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ResumableChatAdapter(
name,options):ResumableChatAdapter
Defined in: chat/backends/resumable.ts:31
Parameters
Section titled “Parameters”string
options
Section titled “options”Returns
Section titled “Returns”Overrides
Section titled “Overrides”BaseBackendAdapter.constructor
Properties
Section titled “Properties”_agentConfig
Section titled “_agentConfig”
protectedreadonly_agentConfig:FullAgentConfig
Defined in: chat/backends/base.ts:39
Inherited from
Section titled “Inherited from”BaseBackendAdapter._agentConfig
readonlyname:string
Defined in: chat/backends/base.ts:35
Backend name (e.g. “copilot”, “claude”, “vercel-ai”)
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”Accessors
Section titled “Accessors”agentService
Section titled “agentService”Get Signature
Section titled “Get Signature”get agentService():
IAgentService
Defined in: chat/backends/base.ts:64
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”BaseBackendAdapter.agentService
backendSessionId
Section titled “backendSessionId”Get Signature
Section titled “Get Signature”get backendSessionId():
string|null
Defined in: chat/backends/resumable.ts:40
The backend session ID from the last stream, or null if not yet streamed
Returns
Section titled “Returns”string | null
The backend session ID from the last stream, or null if not yet streamed
Implementation of
Section titled “Implementation of”IResumableBackend.backendSessionId
currentModel
Section titled “currentModel”Get Signature
Section titled “Get Signature”get currentModel():
string|undefined
Defined in: chat/backends/base.ts:78
Current effective model
Returns
Section titled “Returns”string | undefined
Current effective model
Implementation of
Section titled “Implementation of”IResumableBackend.currentModel
Inherited from
Section titled “Inherited from”BaseBackendAdapter.currentModel
Methods
Section titled “Methods”assertNotDisposed()
Section titled “assertNotDisposed()”
protectedassertNotDisposed():void
Defined in: chat/backends/base.ts:244
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”BaseBackendAdapter.assertNotDisposed
canResume()
Section titled “canResume()”canResume():
boolean
Defined in: chat/backends/resumable.ts:44
Whether this adapter supports session resume
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”captureSessionId()
Section titled “captureSessionId()”
protectedcaptureSessionId(agent):void
Defined in: chat/backends/resumable.ts:82
Subclasses capture backend session ID from agent after streaming
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”BaseBackendAdapter.captureSessionId
createService()
Section titled “createService()”
abstractprotectedcreateService():IAgentService
Defined in: chat/backends/base.ts:62
Subclasses create their specific IAgentService
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”BaseBackendAdapter.createService
dispose()
Section titled “dispose()”dispose():
Promise<void>
Defined in: chat/backends/base.ts:196
Dispose resources
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”getOrCreateAgent()
Section titled “getOrCreateAgent()”
protectedgetOrCreateAgent(options?):IAgent
Defined in: chat/backends/base.ts:211
Get or create an agent. Model is passed per-call via RunOptions. Tools are passed per-call via SendMessageOptions — not baked into config. For persistent sessions, reuses agent when model matches.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”BaseBackendAdapter.getOrCreateAgent
listModels()
Section titled “listModels()”listModels():
Promise<ModelInfo[]>
Defined in: chat/backends/base.ts:186
List available models
Returns
Section titled “Returns”Promise<ModelInfo[]>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”resume()
Section titled “resume()”resume(
session,backendSessionId,options?):AsyncIterable<ChatEvent>
Defined in: chat/backends/resumable.ts:48
Resume a previous session by its backend session ID. Streams events from the resumed session.
Parameters
Section titled “Parameters”session
Section titled “session”backendSessionId
Section titled “backendSessionId”string
options?
Section titled “options?”Returns
Section titled “Returns”AsyncIterable<ChatEvent>
Throws
Section titled “Throws”ChatError with SESSION_EXPIRED if session is no longer valid
Throws
Section titled “Throws”ChatError with SESSION_NOT_FOUND if session ID is unknown
Implementation of
Section titled “Implementation of”sendMessage()
Section titled “sendMessage()”sendMessage(
session,message,options?):Promise<ChatMessage<unknown>>
Defined in: chat/backends/base.ts:90
Send a message and receive a complete response
Parameters
Section titled “Parameters”session
Section titled “session”message
Section titled “message”string
options?
Section titled “options?”Returns
Section titled “Returns”Promise<ChatMessage<unknown>>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”BaseBackendAdapter.sendMessage
setTools()
Section titled “setTools()”setTools():
void
Defined in: chat/backends/base.ts:86
Returns
Section titled “Returns”void
Deprecated
Section titled “Deprecated”No-op. Tools are passed per-call via SendMessageOptions.tools. Kept for backward compatibility with code that calls setTools() directly.
Inherited from
Section titled “Inherited from”streamAgentEvents()
Section titled “streamAgentEvents()”
protectedstreamAgentEvents(agent,messages,options?):AsyncIterable<ChatEvent>
Defined in: chat/backends/base.ts:144
Shared streaming helper: bridges agent events to chat events. Used by both streamMessage() and resume() to avoid duplication.
Parameters
Section titled “Parameters”messages
Section titled “messages”Message[]
options?
Section titled “options?”Returns
Section titled “Returns”AsyncIterable<ChatEvent>
Inherited from
Section titled “Inherited from”BaseBackendAdapter.streamAgentEvents
streamMessage()
Section titled “streamMessage()”streamMessage(
session,message,options?):AsyncIterable<ChatEvent>
Defined in: chat/backends/base.ts:124
Stream a message response as ChatEvents
Parameters
Section titled “Parameters”session
Section titled “session”message
Section titled “message”string
options?
Section titled “options?”Returns
Section titled “Returns”AsyncIterable<ChatEvent>
Implementation of
Section titled “Implementation of”IResumableBackend.streamMessage
Inherited from
Section titled “Inherited from”BaseBackendAdapter.streamMessage
validate()
Section titled “validate()”validate():
Promise<{errors:string[];valid:boolean; }>
Defined in: chat/backends/base.ts:191
Validate backend configuration/credentials
Returns
Section titled “Returns”Promise<{ errors: string[]; valid: boolean; }>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”Interfaces
Section titled “Interfaces”ClaudeChatAdapterOptions
Section titled “ClaudeChatAdapterOptions”Defined in: chat/backends/claude.ts:18
Options for creating a ClaudeChatAdapter
Extends
Section titled “Extends”Properties
Section titled “Properties”agentConfig
Section titled “agentConfig”agentConfig:
FullAgentConfig
Defined in: chat/backends/types.ts:25
Agent configuration (model, systemPrompt, tools, etc.)
Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentConfig
agentService?
Section titled “agentService?”
optionalagentService:IAgentService
Defined in: chat/backends/types.ts:27
Pre-created agent service (if adapter should not own lifecycle)
Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentService
agentServiceFactory()?
Section titled “agentServiceFactory()?”
optionalagentServiceFactory: () =>IAgentService
Defined in: chat/backends/types.ts:29
Factory for lazy service creation (called on first use, not at construction)
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentServiceFactory
claudeOptions?
Section titled “claudeOptions?”
optionalclaudeOptions:ClaudeBackendOptions
Defined in: chat/backends/claude.ts:20
Claude backend options (cliPath, model, etc.)
CloseDetectable
Section titled “CloseDetectable”Defined in: chat/backends/transport.ts:42
Minimal interface for detecting client disconnection
Methods
Section titled “Methods”on(
event,listener):void
Defined in: chat/backends/transport.ts:43
Parameters
Section titled “Parameters”"close"
listener
Section titled “listener”() => void
Returns
Section titled “Returns”void
CopilotChatAdapterOptions
Section titled “CopilotChatAdapterOptions”Defined in: chat/backends/copilot.ts:18
Options for creating a CopilotChatAdapter
Extends
Section titled “Extends”Properties
Section titled “Properties”agentConfig
Section titled “agentConfig”agentConfig:
FullAgentConfig
Defined in: chat/backends/types.ts:25
Agent configuration (model, systemPrompt, tools, etc.)
Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentConfig
agentService?
Section titled “agentService?”
optionalagentService:IAgentService
Defined in: chat/backends/types.ts:27
Pre-created agent service (if adapter should not own lifecycle)
Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentService
agentServiceFactory()?
Section titled “agentServiceFactory()?”
optionalagentServiceFactory: () =>IAgentService
Defined in: chat/backends/types.ts:29
Factory for lazy service creation (called on first use, not at construction)
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentServiceFactory
copilotOptions?
Section titled “copilotOptions?”
optionalcopilotOptions:CopilotBackendOptions
Defined in: chat/backends/copilot.ts:20
Copilot backend options (cliPath, token, etc.)
InterceptorContext
Section titled “InterceptorContext”Defined in: chat/backends/interceptors.ts:24
Context passed to interceptor hooks
Properties
Section titled “Properties”event:
ChatEvent
Defined in: chat/backends/interceptors.ts:26
The event being intercepted (mutable for beforeSend)
transport
Section titled “transport”transport:
IChatTransport
Defined in: chat/backends/interceptors.ts:28
The underlying transport being wrapped
MockLLMChatAdapterOptions
Section titled “MockLLMChatAdapterOptions”Defined in: chat/backends/mock-llm.ts:16
Options for creating a MockLLMChatAdapter
Extends
Section titled “Extends”Properties
Section titled “Properties”agentConfig
Section titled “agentConfig”agentConfig:
FullAgentConfig
Defined in: chat/backends/types.ts:25
Agent configuration (model, systemPrompt, tools, etc.)
Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentConfig
agentService?
Section titled “agentService?”
optionalagentService:IAgentService
Defined in: chat/backends/types.ts:27
Pre-created agent service (if adapter should not own lifecycle)
Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentService
agentServiceFactory()?
Section titled “agentServiceFactory()?”
optionalagentServiceFactory: () =>IAgentService
Defined in: chat/backends/types.ts:29
Factory for lazy service creation (called on first use, not at construction)
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentServiceFactory
mockOptions?
Section titled “mockOptions?”
optionalmockOptions:MockLLMBackendOptions
Defined in: chat/backends/mock-llm.ts:18
MockLLM backend options (mode, latency, streaming, etc.)
SSETransportOptions
Section titled “SSETransportOptions”Defined in: chat/backends/transport.ts:47
Configuration options for SSEChatTransport
Properties
Section titled “Properties”heartbeatMs?
Section titled “heartbeatMs?”
optionalheartbeatMs:number
Defined in: chat/backends/transport.ts:49
Heartbeat interval in milliseconds. 0 or undefined disables heartbeat.
request?
Section titled “request?”
optionalrequest:CloseDetectable
Defined in: chat/backends/transport.ts:51
Request object for detecting client disconnection (listens for ‘close’ event)
TransportInterceptor
Section titled “TransportInterceptor”Defined in: chat/backends/interceptors.ts:35
Transport interceptor with lifecycle hooks. All hooks are optional — implement only what you need.
Properties
Section titled “Properties”
optionalname:string
Defined in: chat/backends/interceptors.ts:37
Optional name for debugging
Methods
Section titled “Methods”afterSend()?
Section titled “afterSend()?”
optionalafterSend(event,transport):void
Defined in: chat/backends/interceptors.ts:46
Called after each event is sent to the transport
Parameters
Section titled “Parameters”transport
Section titled “transport”Returns
Section titled “Returns”void
beforeClose()?
Section titled “beforeClose()?”
optionalbeforeClose(transport):void
Defined in: chat/backends/interceptors.ts:49
Called before the transport is closed
Parameters
Section titled “Parameters”transport
Section titled “transport”Returns
Section titled “Returns”void
beforeSend()?
Section titled “beforeSend()?”
optionalbeforeSend(event,transport):ChatEvent|null
Defined in: chat/backends/interceptors.ts:43
Called before each event is sent to the transport. Return the event to send, a modified event, or null to suppress.
Parameters
Section titled “Parameters”transport
Section titled “transport”Returns
Section titled “Returns”ChatEvent | null
onError()?
Section titled “onError()?”
optionalonError(error,transport):void
Defined in: chat/backends/interceptors.ts:52
Called when an error is signaled on the transport
Parameters
Section titled “Parameters”Error
transport
Section titled “transport”Returns
Section titled “Returns”void
VercelAIChatAdapterOptions
Section titled “VercelAIChatAdapterOptions”Defined in: chat/backends/vercel-ai.ts:20
Options for creating a VercelAIChatAdapter
Extends
Section titled “Extends”Properties
Section titled “Properties”agentConfig
Section titled “agentConfig”agentConfig:
FullAgentConfig
Defined in: chat/backends/types.ts:25
Agent configuration (model, systemPrompt, tools, etc.)
Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentConfig
agentService?
Section titled “agentService?”
optionalagentService:IAgentService
Defined in: chat/backends/types.ts:27
Pre-created agent service (if adapter should not own lifecycle)
Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentService
agentServiceFactory()?
Section titled “agentServiceFactory()?”
optionalagentServiceFactory: () =>IAgentService
Defined in: chat/backends/types.ts:29
Factory for lazy service creation (called on first use, not at construction)
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”BackendAdapterOptions.agentServiceFactory
vercelOptions?
Section titled “vercelOptions?”
optionalvercelOptions:VercelAIBackendOptions
Defined in: chat/backends/vercel-ai.ts:22
Vercel AI backend options (baseURL, apiKey, provider, etc.)
WebSocketLike
Section titled “WebSocketLike”Defined in: chat/backends/ws-transport.ts:25
Minimal WebSocket interface compatible with ws, browser WebSocket, Deno, Bun.
Only the methods/properties used by WsChatTransport.
Properties
Section titled “Properties”readyState
Section titled “readyState”
readonlyreadyState:number
Defined in: chat/backends/ws-transport.ts:26
Methods
Section titled “Methods”addEventListener()
Section titled “addEventListener()”Call Signature
Section titled “Call Signature”addEventListener(
type,listener):void
Defined in: chat/backends/ws-transport.ts:29
Parameters
Section titled “Parameters”"close"
listener
Section titled “listener”() => void
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”addEventListener(
type,listener):void
Defined in: chat/backends/ws-transport.ts:30
Parameters
Section titled “Parameters”"error"
listener
Section titled “listener”(err) => void
Returns
Section titled “Returns”void
close()
Section titled “close()”close(
code?,reason?):void
Defined in: chat/backends/ws-transport.ts:28
Parameters
Section titled “Parameters”number
reason?
Section titled “reason?”string
Returns
Section titled “Returns”void
send()
Section titled “send()”send(
data):void
Defined in: chat/backends/ws-transport.ts:27
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
WritableResponse
Section titled “WritableResponse”Defined in: chat/backends/transport.ts:33
Writable HTTP response interface — minimal type satisfied by Express, Fastify (raw), and Node http.ServerResponse without casts.
Properties
Section titled “Properties”writableEnded
Section titled “writableEnded”
readonlywritableEnded:boolean
Defined in: chat/backends/transport.ts:38
Methods
Section titled “Methods”end(
body?):unknown
Defined in: chat/backends/transport.ts:37
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”unknown
setHeader()
Section titled “setHeader()”setHeader(
name,value):unknown
Defined in: chat/backends/transport.ts:35
Parameters
Section titled “Parameters”string
string
Returns
Section titled “Returns”unknown
write()
Section titled “write()”write(
chunk):boolean
Defined in: chat/backends/transport.ts:36
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
writeHead()
Section titled “writeHead()”writeHead(
statusCode,headers?):unknown
Defined in: chat/backends/transport.ts:34
Parameters
Section titled “Parameters”statusCode
Section titled “statusCode”number
headers?
Section titled “headers?”Record<string, string | string[]>
Returns
Section titled “Returns”unknown
WsTransportOptions
Section titled “WsTransportOptions”Defined in: chat/backends/ws-transport.ts:34
Configuration options for WsChatTransport
Properties
Section titled “Properties”heartbeatMs?
Section titled “heartbeatMs?”
optionalheartbeatMs:number
Defined in: chat/backends/ws-transport.ts:36
Heartbeat interval in ms. 0 or undefined disables heartbeat.
serialize()?
Section titled “serialize()?”
optionalserialize: (event) =>string
Defined in: chat/backends/ws-transport.ts:38
Custom JSON serializer (defaults to JSON.stringify)
Parameters
Section titled “Parameters”Returns
Section titled “Returns”string
Variables
Section titled “Variables”WS_READY_STATE
Section titled “WS_READY_STATE”
constWS_READY_STATE:object
Defined in: chat/backends/ws-transport.ts:14
Ready states matching the WebSocket spec (ws, browser, Deno, Bun)
Type Declaration
Section titled “Type Declaration”CLOSED
Section titled “CLOSED”
readonlyCLOSED:3=3
CLOSING
Section titled “CLOSING”
readonlyCLOSING:2=2
CONNECTING
Section titled “CONNECTING”
readonlyCONNECTING:0=0
readonlyOPEN:1=1
Functions
Section titled “Functions”withInterceptors()
Section titled “withInterceptors()”withInterceptors(
transport,interceptors):IChatTransport
Defined in: chat/backends/interceptors.ts:128
Wrap a transport with one or more interceptors. Interceptors are applied in order: first interceptor’s beforeSend runs first.
Parameters
Section titled “Parameters”transport
Section titled “transport”Base transport to wrap
interceptors
Section titled “interceptors”Array of interceptors to apply
Returns
Section titled “Returns”Wrapped transport with interceptor hooks
References
Section titled “References”BackendAdapterOptions
Section titled “BackendAdapterOptions”Re-exports BackendAdapterOptions
BaseBackendAdapter
Section titled “BaseBackendAdapter”Re-exports BaseBackendAdapter
ClaudeChatAdapter
Section titled “ClaudeChatAdapter”Re-exports ClaudeChatAdapter
CopilotChatAdapter
Section titled “CopilotChatAdapter”Re-exports CopilotChatAdapter
IChatBackend
Section titled “IChatBackend”Re-exports IChatBackend
IChatTransport
Section titled “IChatTransport”Re-exports IChatTransport
InProcessChatTransport
Section titled “InProcessChatTransport”Re-exports InProcessChatTransport
IResumableBackend
Section titled “IResumableBackend”Re-exports IResumableBackend
isResumableBackend
Section titled “isResumableBackend”Re-exports isResumableBackend
MockLLMChatAdapter
Section titled “MockLLMChatAdapter”Re-exports MockLLMChatAdapter
SSEChatTransport
Section titled “SSEChatTransport”Re-exports SSEChatTransport
streamToTransport
Section titled “streamToTransport”Re-exports streamToTransport
VercelAIChatAdapter
Section titled “VercelAIChatAdapter”Re-exports VercelAIChatAdapter
WsChatTransport
Section titled “WsChatTransport”Re-exports WsChatTransport