"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClaudeSDKClient = void 0;
/**
 * Claude SDK Client - Fallback provider using Claude API
 *
 * This is a simplified client that uses the Claude API directly
 * as a fallback when MyContext AI is not available.
 */
class ClaudeSDKClient {
    constructor() {
        this.clientType = "direct-api";
        this.supportsTools = false;
        this.supportsStreaming = false;
        this.apiKey = null;
        this.baseUrl = "https://api.anthropic.com/v1";
        this.apiKey = process.env.ANTHROPIC_API_KEY || null;
    }
    /**
     * Check if API key is available
     */
    hasApiKey() {
        return !!this.apiKey;
    }
    /**
     * Set API key for Claude API
     */
    setApiKey(apiKey) {
        this.apiKey = apiKey;
    }
    /**
     * Check connection to Claude API
     */
    async checkConnection() {
        if (!this.apiKey) {
            return false;
        }
        try {
            const response = await fetch(`${this.baseUrl}/messages`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    "x-api-key": this.apiKey,
                    "anthropic-version": "2023-06-01",
                },
                body: JSON.stringify({
                    model: "claude-3-haiku-20240307",
                    max_tokens: 10,
                    messages: [
                        {
                            role: "user",
                            content: "test",
                        },
                    ],
                }),
            });
            return response.ok;
        }
        catch (error) {
            console.warn("Claude SDK connection check failed:", error);
            return false;
        }
    }
    /**
     * Generate text using Claude API
     */
    async generateText(prompt, options = {}) {
        if (!this.apiKey) {
            throw new Error("Anthropic API key not configured for Claude SDK");
        }
        try {
            const response = await fetch(`${this.baseUrl}/messages`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    "x-api-key": this.apiKey,
                    "anthropic-version": "2023-06-01",
                },
                body: JSON.stringify({
                    model: options.model || "claude-3-haiku-20240307",
                    max_tokens: options.maxTokens || 4000,
                    temperature: options.temperature || 0.7,
                    messages: [
                        {
                            role: "user",
                            content: prompt,
                        },
                    ],
                }),
            });
            if (!response.ok) {
                throw new Error(`Claude API error: ${response.status} ${response.statusText}`);
            }
            const data = await response.json();
            return data.content[0].text || "";
        }
        catch (error) {
            throw new Error(`Claude SDK generation failed: ${error}`);
        }
    }
    /**
     * Generate React component using Claude API
     */
    async generateComponent(prompt, context, options = {}) {
        const systemPrompt = `You are a React component generator. Generate production-ready React components with TypeScript.

Requirements:
- Use functional components with hooks
- Include proper TypeScript types
- Add accessibility attributes
- Use Tailwind CSS for styling
- Include proper imports and exports
- Generate complete, runnable code

${context?.prd ? `Project Requirements: ${context.prd}` : ""}
${context?.types ? `Type Definitions: ${context.types}` : ""}
${context?.brand ? `Brand Guidelines: ${context.brand}` : ""}`;
        const fullPrompt = `${systemPrompt}\n\nGenerate a React component for: ${prompt}`;
        return this.generateText(fullPrompt, options);
    }
    /**
     * Generate component refinement using Claude API
     */
    async generateComponentRefinement(componentCode, prompt, context, options = {}) {
        const systemPrompt = `You are a React component refiner. Improve and modify existing React components.

Requirements:
- Maintain existing functionality
- Preserve TypeScript types
- Keep accessibility attributes
- Follow React best practices
- Provide complete refined component

${context?.prd ? `Project Requirements: ${context.prd}` : ""}
${context?.types ? `Type Definitions: ${context.types}` : ""}
${context?.brand ? `Brand Guidelines: ${context.brand}` : ""}`;
        const fullPrompt = `${systemPrompt}\n\nComponent to refine:\n\`\`\`tsx\n${componentCode}\n\`\`\n\nRefinement request: ${prompt}`;
        return this.generateText(fullPrompt, options);
    }
    /**
     * Generate text from image using Claude API (Multimodal)
     */
    async generateVisionText(prompt, imagePath, options = {}) {
        // Claude vision models are handled through the Claude Agent SDK or specific message formats
        // For now we'll throw an error to trigger fallback in AICore
        throw new Error("Claude SDK vision generation not yet implemented in this client");
    }
    async generateImage(prompt, outputPath, options = {}) {
        throw new Error("Claude SDK image generation not yet implemented in this client");
    }
    /**
     * List available models
     */
    async listModels() {
        return [
            "claude-3-haiku-20240307",
            "claude-3-sonnet-20240229",
            "claude-3-opus-20240229",
        ];
    }
    /**
     * Cleanup resources
     */
    async cleanup() {
        // No cleanup needed for fetch-based client
    }
}
exports.ClaudeSDKClient = ClaudeSDKClient;
//# sourceMappingURL=ClaudeSDKClient.js.map