FluxbaseAIChat
AI Chat client for WebSocket-based chat with AI chatbots
Example
Section titled “Example”const chat = new FluxbaseAIChat({ wsUrl: 'ws://localhost:8080/ai/ws', token: 'my-jwt-token', onContent: (delta, convId) => { process.stdout.write(delta) }, onProgress: (step, message) => { console.log(`[${step}] ${message}`) }, onQueryResult: (query, summary, rowCount, data) => { console.log(`Query: ${query}`) console.log(`Result: ${summary} (${rowCount} rows)`) }, onDone: (usage) => { console.log(`\nTokens: ${usage?.total_tokens}`) }, onError: (error, code) => { console.error(`Error: ${error} (${code})`) },})
await chat.connect()const convId = await chat.startChat('sql-assistant')await chat.sendMessage(convId, 'Show me the top 10 users by order count')Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FluxbaseAIChat(
options):FluxbaseAIChat
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
AIChatOptions |
Returns
Section titled “Returns”FluxbaseAIChat
Methods
Section titled “Methods”cancel()
Section titled “cancel()”cancel(
conversationId):void
Cancel an ongoing message generation
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
conversationId |
string |
Conversation ID |
Returns
Section titled “Returns”void
connect()
Section titled “connect()”connect():
Promise<void>
Connect to the AI chat WebSocket
Returns
Section titled “Returns”Promise<void>
Promise that resolves when connected
disconnect()
Section titled “disconnect()”disconnect():
void
Disconnect from the AI chat WebSocket
Returns
Section titled “Returns”void
getAccumulatedContent()
Section titled “getAccumulatedContent()”getAccumulatedContent(
conversationId):string
Get the full accumulated response content for a conversation
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
conversationId |
string |
Conversation ID |
Returns
Section titled “Returns”string
Accumulated content string
isConnected()
Section titled “isConnected()”isConnected():
boolean
Check if connected
Returns
Section titled “Returns”boolean
sendMessage()
Section titled “sendMessage()”sendMessage(
conversationId,content,options?):void
Send a message in a conversation
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
conversationId |
string |
Conversation ID |
content |
string |
Message content |
options? |
{ pageContext?: string; } |
Optional per-message options |
options.pageContext? |
string |
Page context string for page-aware chatbots. The supervisor looks up the matching PageProfile (if any) and uses it to bias routing and override per-page config. Missing or unknown values fall back to the chatbot’s global config. |
Returns
Section titled “Returns”void
startChat()
Section titled “startChat()”startChat(
chatbot,namespace?,conversationId?,impersonateUserId?):Promise<string>
Start a new chat session with a chatbot
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
chatbot |
string |
Chatbot name |
namespace? |
string |
Optional namespace. If not provided and a lookup function is available, performs smart resolution: - If exactly one chatbot with this name exists, uses it - If multiple exist, tries “default” namespace - If ambiguous and not in default, throws error with available namespaces If no lookup function, falls back to “default” namespace. |
conversationId? |
string |
Optional conversation ID to resume |
impersonateUserId? |
string |
Optional user ID to impersonate (admin only) |
Returns
Section titled “Returns”Promise<string>
Promise resolving to conversation ID