UNPKG

@agentman/chat-widget

Version:

Agentman Chat Widget for easy integration with web applications

80 lines (79 loc) 2.1 kB
import type { ClientMetadata } from '../types/types'; import { StreamingCallbacks } from './StreamingClient'; export interface SendMessageParams { agentToken: string; conversationId: string; userInput: string; clientMetadata?: ClientMetadata; forceLoad?: boolean; attachmentFileIds?: string[]; attachmentUrls?: string[]; streaming?: boolean; debug?: boolean; } export interface ApiResponse { response: any[]; metadata?: any; } export interface FileUploadResponse { success: boolean; fileId?: string; error?: string; } /** * ApiService - Handles all API communication with the Agentman backend * * Responsibilities: * - Send messages to agent API * - Handle file uploads * - Process API responses * - Centralized error handling * - Request/response formatting */ export declare class ApiService { private logger; private apiUrl; private streamingClient; constructor(apiUrl: string, debug?: boolean | import('../types/types').DebugConfig); /** * Send message to the agent API * Routes to streaming or non-streaming based on params */ sendMessage(params: SendMessageParams, streamCallbacks?: StreamingCallbacks): Promise<ApiResponse>; /** * Send message with streaming */ private sendMessageStreaming; /** * Upload file to the API */ uploadFile(file: File, agentToken: string, conversationId: string): Promise<FileUploadResponse>; /** * Get agent capabilities and metadata */ getAgentCapabilities(agentToken: string): Promise<any>; /** * Handle API errors with user-friendly messages */ private handleApiError; /** * Get user-friendly error message */ private getErrorMessage; /** * Update API URL (for dynamic configuration) */ updateApiUrl(newApiUrl: string): void; /** * Get current API URL */ getApiUrl(): string; /** * Abort any active streaming */ abortStreaming(): void; /** * Check if currently streaming */ isStreaming(): boolean; }