FluxbaseAI
Fluxbase AI client for listing chatbots and managing conversations
Example
Section titled “Example”const ai = new FluxbaseAI(fetchClient, 'ws://localhost:8080')
// List available chatbotsconst { data, error } = await ai.listChatbots()
// Create a chat connectionconst chat = ai.createChat({ token: 'my-jwt-token', onContent: (delta) => process.stdout.write(delta),})
await chat.connect()const convId = await chat.startChat('sql-assistant')chat.sendMessage(convId, 'Show me recent orders')Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FluxbaseAI(
fetch,wsBaseUrl):FluxbaseAI
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fetch | { delete: (path) => Promise<void>; get: <T>(path) => Promise<T>; patch: <T>(path, body?) => Promise<T>; } |
fetch.delete | (path) => Promise<void> |
fetch.get | <T>(path) => Promise<T> |
fetch.patch | <T>(path, body?) => Promise<T> |
wsBaseUrl | string |
Returns
Section titled “Returns”FluxbaseAI
Methods
Section titled “Methods”createChat()
Section titled “createChat()”createChat(
options):FluxbaseAIChat
Create a new AI chat connection
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options | Omit<AIChatOptions, "wsUrl" | "_lookupChatbot"> | Chat connection options |
Returns
Section titled “Returns”FluxbaseAIChat instance
deleteConversation()
Section titled “deleteConversation()”deleteConversation(
id):Promise<{error:Error|null; }>
Delete a conversation
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Conversation ID |
Returns
Section titled “Returns”Promise<{ error: Error | null; }>
Promise resolving to { error } (null on success)
Example
Section titled “Example”const { error } = await ai.deleteConversation('conv-uuid-123')if (!error) { console.log('Conversation deleted')}getChatbot()
Section titled “getChatbot()”getChatbot(
id):Promise<{data:AIChatbotSummary|null;error:Error|null; }>
Get details of a specific chatbot
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Chatbot ID |
Returns
Section titled “Returns”Promise<{ data: AIChatbotSummary | null; error: Error | null; }>
Promise resolving to { data, error } tuple with chatbot details
getConversation()
Section titled “getConversation()”getConversation(
id):Promise<{data:AIUserConversationDetail|null;error:Error|null; }>
Get a single conversation with all messages
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Conversation ID |
Returns
Section titled “Returns”Promise<{ data: AIUserConversationDetail | null; error: Error | null; }>
Promise resolving to { data, error } tuple with conversation detail
Example
Section titled “Example”const { data, error } = await ai.getConversation('conv-uuid-123')if (data) { console.log(`Title: ${data.title}`) console.log(`Messages: ${data.messages.length}`)}listChatbots()
Section titled “listChatbots()”listChatbots():
Promise<{data:AIChatbotSummary[] |null;error:Error|null; }>
List available chatbots (public, enabled)
Returns
Section titled “Returns”Promise<{ data: AIChatbotSummary[] | null; error: Error | null; }>
Promise resolving to { data, error } tuple with array of chatbot summaries
listConversations()
Section titled “listConversations()”listConversations(
options?):Promise<{data:ListConversationsResult|null;error:Error|null; }>
List the authenticated user’s conversations
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options? | ListConversationsOptions | Optional filters and pagination |
Returns
Section titled “Returns”Promise<{ data: ListConversationsResult | null; error: Error | null; }>
Promise resolving to { data, error } tuple with conversations
Example
Section titled “Example”// List all conversationsconst { data, error } = await ai.listConversations()
// Filter by chatbotconst { data, error } = await ai.listConversations({ chatbot: 'sql-assistant' })
// With paginationconst { data, error } = await ai.listConversations({ limit: 20, offset: 0 })lookupChatbot()
Section titled “lookupChatbot()”lookupChatbot(
name):Promise<{data:AIChatbotLookupResponse|null;error:Error|null; }>
Lookup a chatbot by name with smart namespace resolution
Resolution logic:
- If exactly one chatbot with this name exists -> returns it
- If multiple exist -> tries “default” namespace first
- If multiple exist and none in “default” -> returns ambiguous=true with namespaces list
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
name | string | Chatbot name |
Returns
Section titled “Returns”Promise<{ data: AIChatbotLookupResponse | null; error: Error | null; }>
Promise resolving to { data, error } tuple with lookup result
Example
Section titled “Example”// Lookup chatbot by nameconst { data, error } = await ai.lookupChatbot('sql-assistant')if (data?.chatbot) { console.log(`Found in namespace: ${data.chatbot.namespace}`)} else if (data?.ambiguous) { console.log(`Chatbot exists in: ${data.namespaces?.join(', ')}`)}updateConversation()
Section titled “updateConversation()”updateConversation(
id,updates):Promise<{data:AIUserConversationDetail|null;error:Error|null; }>
Update a conversation (currently supports title update only)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Conversation ID |
updates | UpdateConversationOptions | Fields to update |
Returns
Section titled “Returns”Promise<{ data: AIUserConversationDetail | null; error: Error | null; }>
Promise resolving to { data, error } tuple with updated conversation
Example
Section titled “Example”const { data, error } = await ai.updateConversation('conv-uuid-123', { title: 'My custom conversation title'})