UNPKG

@aituber-onair/core

Version:

Core library for AITuber OnAir providing voice synthesis and chat processing

140 lines (139 loc) 5.14 kB
import { ChatService } from '../../ChatService'; import { Message, MessageWithVision, ToolChatCompletion, ToolDefinition, MCPServerConfig } from '../../../../types'; export interface ClaudeToolResultBlock { type: 'tool_result'; tool_use_id: string; content: string; } /** * Claude implementation of ChatService */ export declare class ClaudeChatService implements ChatService { /** Provider name */ readonly provider: string; private apiKey; private model; private visionModel; private tools; private mcpServers; /** * Constructor * @param apiKey Anthropic API key * @param model Name of the model to use * @param visionModel Name of the vision model * @param tools Array of tool definitions * @param mcpServers Array of MCP server configurations (optional) * @throws Error if the vision model doesn't support vision capabilities */ constructor(apiKey: string, model?: string, visionModel?: string, tools?: ToolDefinition[], mcpServers?: MCPServerConfig[]); /** * Get the current model name * @returns Model name */ getModel(): string; /** * Get the current vision model name * @returns Vision model name */ getVisionModel(): string; /** * Get configured MCP servers * @returns Array of MCP server configurations */ getMCPServers(): MCPServerConfig[]; /** * Add MCP server configuration * @param serverConfig MCP server configuration */ addMCPServer(serverConfig: MCPServerConfig): void; /** * Remove MCP server by name * @param serverName Name of the server to remove */ removeMCPServer(serverName: string): void; /** * Check if MCP servers are configured * @returns True if MCP servers are configured */ hasMCPServers(): boolean; /** * Process chat messages * @param messages Array of messages to send * @param onPartialResponse Callback to receive each part of streaming response * @param onCompleteResponse Callback to execute when response is complete */ processChat(messages: Message[], onPartialResponse: (text: string) => void, onCompleteResponse: (text: string) => Promise<void>): Promise<void>; /** * Process chat messages with images * @param messages Array of messages to send (including images) * @param onPartialResponse Callback to receive each part of streaming response * @param onCompleteResponse Callback to execute when response is complete */ processVisionChat(messages: MessageWithVision[], onPartialResponse: (text: string) => void, onCompleteResponse: (text: string) => Promise<void>): Promise<void>; /** * Convert AITuber OnAir messages to Claude format * @param messages Array of messages * @returns Claude formatted messages */ private convertMessagesToClaudeFormat; /** * Convert AITuber OnAir vision messages to Claude format * @param messages Array of vision messages * @returns Claude formatted vision messages */ private convertVisionMessagesToClaudeFormat; /** * Map AITuber OnAir roles to Claude roles * @param role AITuber OnAir role * @returns Claude role */ private mapRoleToClaude; /** * Get MIME type from URL * @param url Image URL * @returns MIME type */ private getMimeTypeFromUrl; /** * Call Claude API * @param messages Array of messages to send * @param model Model name * @param stream Whether to stream the response * @param maxTokens Maximum tokens for response (optional) * @returns Response */ private callClaude; /** * Parse stream response * @param res Response * @param onPartial Callback to receive each part of streaming response * @returns ClaudeInternalCompletion */ private parseStream; private parsePureStream; private parseOneShot; /** * Process chat messages * @param messages Array of messages to send * @param stream Whether to stream the response * @param onPartial Callback to receive each part of streaming response * @param maxTokens Maximum tokens for response (optional) * @returns ToolChatCompletion */ chatOnce(messages: Message[], stream?: boolean, onPartial?: (t: string) => void, maxTokens?: number): Promise<ToolChatCompletion>; /** * Process vision chat messages * @param messages Array of messages to send * @param stream Whether to stream the response * @param onPartial Callback to receive each part of streaming response * @param maxTokens Maximum tokens for response (optional) * @returns ToolChatCompletion */ visionChatOnce(messages: MessageWithVision[], stream?: boolean, onPartial?: (t: string) => void, maxTokens?: number): Promise<ToolChatCompletion>; /** * Convert internal completion to standard ToolChatCompletion * @param completion Internal completion result * @returns Standard ToolChatCompletion */ private convertToStandardCompletion; }