{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/chunk-QBWIMSJD.cjs","../src/core/providers/anthropic.provider.ts"],"names":["anthropicModelIds","anthropicModels","name","anthropicProvider","streamWithAnthropic","credentials","prompt","settings","apiKey","baseURL","createAnthropic","result","streamText","error"],"mappings":"AAAA;AACA,wDAAwC,8CCDM,wBAEP,IAoBjCA,CAAAA,CAAoB,CACxB,wBAAA,CACA,0BAAA,CACA,4BAAA,CACA,0BAAA,CACA,4BAAA,CACA,4BAAA,CACA,yBAAA,CACA,2BAAA,CACA,sBAAA,CACA,wBAAA,CACA,0BAAA,CACA,yBACF,CAAA,CAEaC,CAAAA,aAA+BD,CAAAA,CAAkB,GAAA,CAAKE,CAAAA,EAAAA,CAAU,CAC3E,IAAA,CAAAA,CAAAA,CACA,WAAA,CAAaA,CACf,CAAA,CAAE,CAAA,CAEWC,CAAAA,aAAoB,CAC/B,IAAA,CAAM,WAAA,CACN,WAAA,CAAa,8BAAA,CACb,MAAA,CAAQF,CACV,CAAA,CAEaG,CAAAA,aAAsB,KAAA,CACjCC,CAAAA,CACAC,CAAAA,CAAAA,EAC+B,CAC/B,GAAI,CACF,IAAMC,CAAAA,CAAWF,CAAAA,CAAY,gBAAA,CAIvBG,CAAAA,iBAASD,CAAAA,2BAAU,QAAA,EAAUF,CAAAA,CAAY,MAAA,CAE/C,EAAA,CAAI,CAACG,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,mCAAmC,CAAA,CAGrD,IAAMC,CAAAA,iBAAUF,CAAAA,6BAAU,SAAA,EAAW,2BAAA,CAE/BJ,CAAAA,CAAoBO,wCAAAA,CACxB,MAAA,CAAQF,CAAAA,CACR,OAAA,CAASC,CACX,CAAC,CAAA,CAEKE,CAAAA,CAASC,4BAAAA,CACb,KAAA,CAAOT,CAAAA,CAAkBE,CAAAA,CAAY,KAAK,CAAA,CAC1C,MAAA,CAAAC,CAAAA,CACA,WAAA,CAAaD,CAAAA,CAAY,WAAA,EAAe,EAAA,CACxC,eAAA,CAAiBA,CAAAA,CAAY,SAAA,EAAa,IAC5C,CAAC,CAAA,CAED,MAAO,CACL,UAAA,CAAYM,CAAAA,CAAO,UAAA,CACnB,YAAA,CAAcA,CAAAA,CAAO,IACvB,CACF,CAAA,KAAA,CAASE,CAAAA,CAAO,CACd,MAAM,IAAI,KAAA,CACR,CAAA,uCAAA,EACEA,EAAAA,WAAiB,KAAA,CAAQA,CAAAA,CAAM,OAAA,CAAU,MAAA,CAAOA,CAAK,CACvD,CAAA,CAAA;ADnFogC","file":"/home/mkabumattar/work/withrawi/rawi/dist/chunk-QBWIMSJD.cjs","sourcesContent":[null,"import {type anthropic, createAnthropic} from '@ai-sdk/anthropic';\nimport type {ModelMessage} from 'ai';\nimport {generateText, streamText} from 'ai';\nimport {parseCommandFromResponse} from '../exec/parser.js';\nimport type {\n  AnthropicSettings,\n  LooseToStrict,\n  ModelInfo,\n  RawiCredentials,\n  StreamingResponse,\n} from '../shared/index.js';\nimport type {\n  ChatCredentials,\n  ChatProvider,\n  ChatStreamOptions,\n  ExecGenerationOptions,\n  ExecGenerationResult,\n} from './types.js';\n\ntype LooseAnthropicModelId = Parameters<typeof anthropic>[0];\nexport type AnthropicModelId = LooseToStrict<LooseAnthropicModelId>;\n\nconst anthropicModelIds = [\n  'claude-opus-4-20250514',\n  'claude-sonnet-4-20250514',\n  'claude-3-7-sonnet-20250219',\n  'claude-3-5-sonnet-latest',\n  'claude-3-5-sonnet-20241022',\n  'claude-3-5-sonnet-20240620',\n  'claude-3-5-haiku-latest',\n  'claude-3-5-haiku-20241022',\n  'claude-3-opus-latest',\n  'claude-3-opus-20240229',\n  'claude-3-sonnet-20240229',\n  'claude-3-haiku-20240307',\n] as const;\n\nexport const anthropicModels: ModelInfo[] = anthropicModelIds.map((name) => ({\n  name,\n  displayName: name,\n}));\n\nexport const anthropicProvider = {\n  name: 'anthropic' as const,\n  displayName: '🟣 Anthropic (Claude)',\n  models: anthropicModels,\n};\n\nexport const streamWithAnthropic = async (\n  credentials: RawiCredentials,\n  prompt: string,\n): Promise<StreamingResponse> => {\n  try {\n    const settings = credentials.providerSettings as\n      | AnthropicSettings\n      | undefined;\n\n    const apiKey = settings?.apiKey || credentials.apiKey;\n\n    if (!apiKey) {\n      throw new Error('API key is required for Anthropic');\n    }\n\n    const baseURL = settings?.baseURL || 'https://api.anthropic.com';\n\n    const anthropicProvider = createAnthropic({\n      apiKey: apiKey,\n      baseURL: baseURL,\n    });\n\n    const result = streamText({\n      model: anthropicProvider(credentials.model),\n      prompt,\n      temperature: credentials.temperature || 0.7,\n      maxOutputTokens: credentials.maxTokens || 2048,\n    });\n\n    return {\n      textStream: result.textStream,\n      fullResponse: result.text,\n    };\n  } catch (error) {\n    throw new Error(\n      `Error calling Anthropic streaming API: ${\n        error instanceof Error ? error.message : String(error)\n      }`,\n    );\n  }\n};\n\nexport const anthropicChatProvider: ChatProvider = {\n  name: 'anthropic',\n  displayName: '🟠 Anthropic (Claude)',\n\n  async streamChat(\n    credentials: ChatCredentials,\n    messages: ModelMessage[],\n    options: ChatStreamOptions = {},\n  ): Promise<AsyncIterable<string>> {\n    const settings = credentials.providerSettings || {};\n    const apiKey = settings.apiKey || credentials.apiKey;\n\n    if (!apiKey) {\n      throw new Error('API key is required for Anthropic');\n    }\n\n    const anthropicProvider = createAnthropic({\n      apiKey: apiKey,\n    });\n\n    const result = streamText({\n      model: anthropicProvider(credentials.model),\n      messages,\n      temperature: credentials.temperature || options.temperature || 0.7,\n      maxOutputTokens: credentials.maxTokens || options.maxTokens || 2048,\n    });\n\n    return result.textStream;\n  },\n};\n\nexport const generateWithAnthropic = async (\n  options: ExecGenerationOptions,\n): Promise<ExecGenerationResult> => {\n  const startTime = Date.now();\n\n  try {\n    const anthropicSettings = options.credentials\n      .providerSettings as AnthropicSettings;\n\n    const anthropicProvider = createAnthropic({\n      apiKey: options.credentials.apiKey,\n      baseURL: anthropicSettings?.baseURL,\n    });\n\n    const result = await generateText({\n      model: anthropicProvider(options.credentials.model),\n      system: options.systemPrompt,\n      prompt: options.userPrompt,\n    });\n\n    const generationTime = Date.now() - startTime;\n\n    const command = parseCommandFromResponse(result.text);\n\n    return {\n      command,\n      generationTime,\n    };\n  } catch (error) {\n    throw new Error(`Anthropic exec generation failed: ${error}`);\n  }\n};\n"]}