UNPKG

cline-sdk

Version:

Comprehensive SDK for Cline - AI-powered development assistant with database integration, execution modes, and custom functions

85 lines (81 loc) 3.04 kB
"use strict"; /** * Anthropic API Client for Cline SDK * Handles real Claude API calls with tool usage */ Object.defineProperty(exports, "__esModule", { value: true }); exports.AnthropicClient = void 0; class AnthropicClient { constructor(config) { if (!config.apiKey) { throw new Error("Anthropic API key is required"); } this.apiKey = config.apiKey; this.model = config.model || "claude-3-sonnet-20240229"; this.baseUrl = config.apiBaseUrl || "https://api.anthropic.com"; } async sendMessage(messages, tools, systemPrompt) { const requestBody = { model: this.model, max_tokens: 4000, temperature: 0.7, system: systemPrompt || this.getDefaultSystemPrompt(), messages: this.formatMessages(messages), tools: tools.map((tool) => ({ name: tool.name, description: tool.description, input_schema: tool.inputSchema, })), }; const response = await fetch(`${this.baseUrl}/v1/messages`, { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": this.apiKey, "anthropic-version": "2023-06-01", }, body: JSON.stringify(requestBody), }); if (!response.ok) { const errorText = await response.text(); throw new Error(`Anthropic API error: ${response.status} ${errorText}`); } return (await response.json()); } formatMessages(messages) { return messages.map((msg) => ({ role: msg.role, content: typeof msg.content === "string" ? msg.content : msg.content, })); } getDefaultSystemPrompt() { return `You are Cline, an AI assistant that can read and write files, run commands, and help with software development tasks. You have access to the following tools: - Write: Create or overwrite files with content - Read: Read file contents - Bash: Execute shell commands When the user asks you to create or modify files, always use the appropriate tools. Be precise and helpful. Current working directory: ${process.cwd()} Always use tools to accomplish tasks that require file operations or command execution.`; } // Helper method to create tool use content static createToolUseContent(toolName, input, toolUseId) { return { type: "tool_use", name: toolName, input: input, id: toolUseId, }; } // Helper method to create tool result content static createToolResultContent(toolUseId, result, isError = false) { return { type: "tool_result", tool_use_id: toolUseId, content: typeof result === "string" ? result : JSON.stringify(result), is_error: isError, }; } } exports.AnthropicClient = AnthropicClient; //# sourceMappingURL=anthropic-client.js.map