UNPKG

rawi

Version:

Rawi (راوي) is the developer-friendly AI CLI that brings the power of 12 major AI providers directly to your terminal. With seamless shell integration, persistent conversations, and 200+ specialized prompt templates, Rawi transforms your command line into

1 lines 3.77 kB
{"version":3,"sources":["/home/mkabumattar/withrawi/rawi/dist/chunk-PGLADL2H.cjs","../src/core/providers/anthropic.provider.ts"],"names":["anthropicModelIds","anthropicModels","name","anthropicProvider","streamWithAnthropic","credentials","prompt","settings","apiKey","baseURL","createAnthropic","result","streamText","error"],"mappings":"AAAA;ACCA,8CAA8B,wBACL,IAYnBA,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,SAAA,CAAWA,CAAAA,CAAY,SAAA,EAAa,IACtC,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;AD3Em8B","file":"/home/mkabumattar/withrawi/rawi/dist/chunk-PGLADL2H.cjs","sourcesContent":[null,"import type {anthropic} from '@ai-sdk/anthropic';\nimport {createAnthropic} from '@ai-sdk/anthropic';\nimport {streamText} from 'ai';\nimport type {\n AnthropicSettings,\n LooseToStrict,\n ModelInfo,\n RawiCredentials,\n StreamingResponse,\n} from '../shared/index.js';\n\ntype LooseAnthropicModelId = Parameters<typeof anthropic>[0];\nexport type AnthropicModelId = LooseToStrict<LooseAnthropicModelId>;\n\nconst anthropicModelIds = [\n 'claude-4-opus-20250514',\n 'claude-4-sonnet-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 maxTokens: 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"]}