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”new FluxbaseAIChat()
Section titled “new FluxbaseAIChat()”new FluxbaseAIChat(
options):FluxbaseAIChat
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options | AIChatOptions |
Returns
Section titled “Returns”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):void
Send a message in a conversation
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
conversationId | string | Conversation ID |
content | string | Message content |
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 (defaults to ‘default’) |
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