/** * @license * Copyright 2023 Nuraly, Laabidi Aymen * SPDX-License-Identifier: MIT */ import type { ChatbotProvider, ProviderCapabilities, ProviderConfig, ChatbotContext } from '../core/types.js'; /** * Custom API provider for any REST/HTTP backend * Can be extended for custom implementations * * @example Basic usage * ```typescript * const provider = new CustomAPIProvider(); * await provider.connect({ * apiUrl: 'https://api.example.com/chat', * apiKey: 'your-api-key' * }); * ``` * * @example Extending with conversation loading * To enable automatic conversation loading on connect, override the * `loadConversations` and optionally `loadConversation` methods: * * ```typescript * class MyAPIProvider extends CustomAPIProvider { * async loadConversations(): Promise> { * const response = await fetch('/api/conversations'); * const data = await response.json(); * return data.conversations; * } * * async loadConversation(id: string): Promise<{id: string, title: string, messages: ChatbotMessage[]}> { * const response = await fetch(`/api/conversations/${id}`); * return await response.json(); * } * } * ``` * * When the ChatbotCoreController connects a provider with these methods, * it will automatically load existing conversations into the thread sidebar. */ export declare class CustomAPIProvider implements ChatbotProvider { readonly id = "custom-api"; readonly name = "Custom API"; readonly capabilities: ProviderCapabilities; protected apiUrl: string; protected headers: Record; protected connected: boolean; connect(config: ProviderConfig): Promise; disconnect(): Promise; isConnected(): boolean; sendMessage(text: string, context: ChatbotContext): AsyncIterator; protected handleStreamResponse(response: Response): AsyncIterator; protected buildPayload(text: string, context: ChatbotContext): any; protected extractMessage(data: any): string; /** * Format error messages with title and description * Wrapped in a special marker that can be styled by the chatbot component */ protected formatError(title: string, description: string): string; onError(error: Error): void; } //# sourceMappingURL=custom-api-provider.d.ts.map