UNPKG

@aptos-labs/ai-chatbot-client

Version:

Aptos AI Developer Assistant - A React-based chatbot interface for the Aptos Developer Assistant API

196 lines (189 loc) 6.12 kB
import React from 'react'; declare enum RagProvider { DEVELOPER_DOCS = "developer-docs", APTOS_LEARN = "aptos-learn" } interface Message { id: string; content: string; role: 'user' | 'assistant'; timestamp: string; feedback?: 'positive' | 'negative'; } interface Chat { id: string | null; title: string; timestamp: string; lastMessage?: string; messages: Message[]; metadata?: { client_id: string; rag_provider?: RagProvider; [key: string]: any; }; } interface ChatbotConfig { apiKey?: string; apiUrl: string; clientId?: string; ragProvider?: RagProvider; githubRepo?: string; fastMode?: boolean; onRateLimitExceeded?: () => void; } interface ChatMessageRequest { content: string; client_id: string; message_id?: string; chat_id?: string; shared_chat_id?: string; role?: 'user' | 'assistant'; rag_provider?: RagProvider; temperature?: number; } interface ChatHistoriesResponse { histories: Chat[]; totalCount: number; } interface StatusResponse { success: boolean; message: string; } type SendMessageOptions = { signal?: AbortSignal; onProgress?: (content: string) => void; messageId?: string; }; interface ChatResponse { message: Message; isComplete: boolean; } interface ChatHistory { messages: Message[]; hasMore: boolean; } interface SharedChat { share_id: string; title: string; messages: Message[]; created_at: string; expires_at?: string; metadata?: { rag_provider?: RagProvider; [key: string]: any; }; } interface ShareChatRequest { client_id: string; title?: string; expires_in_hours?: number; } interface ShareChatResponse { share_id: string; share_url: string; expires_at?: string; } declare class ChatbotClient { private config; constructor(config: ChatbotConfig); createChat(): Promise<Chat>; getChat(chatId: string): Promise<Chat>; listChats(): Promise<Chat[]>; deleteChat(chatId: string): Promise<void>; updateChatTitle(chatId: string, title: string): Promise<void>; sendMessage(chatId: string | null, content: string, options?: SendMessageOptions & { sharedChatId?: string; }): Promise<Response>; getMessages(chatId: string, before?: string): Promise<{ messages: Message[]; hasMore: boolean; }>; provideFeedback(messageId: string, feedback: 'positive' | 'negative'): Promise<void>; deleteFeedback(messageId: string): Promise<void>; shareChat(chatId: string, options?: { title?: string; expiresInHours?: number; }): Promise<ShareChatResponse>; getSharedChat(shareId: string): Promise<SharedChat>; updateConfig(newConfig: Partial<ChatbotConfig>): void; getConfig(): ChatbotConfig; private fetch; } interface ChatWidgetProps { messages: Message[]; isLoading?: boolean; isGenerating?: boolean; isTyping?: boolean; hasMoreMessages?: boolean; onSendMessage: (message: string) => void; onStopGenerating?: () => void; onLoadMore?: () => void; onCopyMessage?: (messageId: string) => void; onMessageFeedback?: (messageId: string, feedback: 'positive' | 'negative') => void; onNewChat?: () => void; className?: string; inputClassName?: string; messageClassName?: string; fastMode?: boolean; showSidebar?: boolean; chats?: Chat[]; currentChatId?: string | null; onSelectChat?: (chatId: string) => void; onDeleteChat?: (chatId: string) => void; onUpdateChatTitle?: (chatId: string, title: string) => void; onToggleFastMode?: (enabled: boolean) => void; } interface ChatContextState$1 { fastMode?: boolean; } interface ChatContextState { isLoading: boolean; error: Error | null; isLoadingChats: boolean; isLoadingMoreMessages: boolean; currentChatId: string | null; chats: Chat[]; messages: Message[]; isGenerating: boolean; isTyping: boolean; hasMoreMessages: boolean; fastMode: boolean; isOpen: boolean; openChat: () => void; closeChat: () => void; createNewChat: () => Promise<void>; selectChat: (chatId: string) => void; deleteChat: (chatId: string) => Promise<void>; updateChatTitle: (chatId: string, title: string) => Promise<void>; sendMessage: (content: string) => Promise<void>; stopGenerating: () => void; retryLastMessage: () => Promise<void>; clearHistory: () => void; copyMessage: (messageId: string) => void; provideFeedback: (messageId: string, feedback: 'positive' | 'negative') => Promise<void>; loadPreviousMessages: () => Promise<void>; loadChats: () => Promise<void>; config: ChatbotConfig; updateConfig: (newConfig: Partial<ChatbotConfig>) => void; setFastMode: (enabled: boolean) => void; shareChat: (chatId: string, options?: { title?: string; expiresInHours?: number; }) => Promise<ShareChatResponse>; getSharedChat: (shareId: string) => Promise<SharedChat>; loadSharedChat: (shareId: string) => Promise<void>; isSharedChatMode: boolean; sharedChatId: string | null; } declare const ChatbotContext: React.Context<ChatContextState>; interface ChatbotProviderProps { config: ChatbotConfig & { onRateLimitExceeded?: () => void; }; children: React.ReactNode; onError?: (error: Error) => void; } declare const ChatbotProvider: React.FC<ChatbotProviderProps>; declare function useChatbot(): ChatContextState; declare function useChatHistory(): Pick<ChatContextState, 'chats' | 'createNewChat' | 'selectChat' | 'deleteChat' | 'updateChatTitle'>; export { type Chat, type ChatContextState$1 as ChatContextState, type ChatHistoriesResponse, type ChatHistory, type ChatMessageRequest, type ChatResponse, type ChatWidgetProps, ChatbotClient, type ChatbotConfig, ChatbotContext, ChatbotProvider, type Message, RagProvider, type SendMessageOptions, type ShareChatRequest, type ShareChatResponse, type SharedChat, type StatusResponse, useChatHistory, useChatbot };