const x="/aiui/",y=`${x}api/claude/v1/messages`;async function*h(r,o,g){const s={model:o.model,messages:r.filter(e=>e.role!=="system").map(e=>({role:e.role,content:typeof e.content=="string"?e.content:e.content.map(c=>c.text??"").join("")})),stream:o.stream??!0},n=r.find(e=>e.role==="system");n&&(s.system=typeof n.content=="string"?n.content:n.content.map(e=>e.text??"").join("")),o.maxTokens&&(s.max_tokens=o.maxTokens),o.temperature!==void 0&&(s.temperature=o.temperature);const a=await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!a.ok){const e=await a.text().catch(()=>"Could not read error body");yield{type:"error",error:`Claude proxy error ${a.status}: ${e}`};return}const i=a.body?.getReader();if(!i){yield{type:"error",error:"No response body"};return}const m=new TextDecoder;let d="";try{for(;;){const{done:e,value:c}=await i.read();if(e)break;d+=m.decode(c,{stream:!0});const p=d.split(`
`);d=p.pop()??"";for(const f of p){const u=f.trim();if(!u||!u.startsWith("data: "))continue;const l=u.slice(6);if(l==="[DONE]"){yield{type:"done"};return}try{const t=JSON.parse(l);t.type==="content_block_delta"&&t.delta?.text?yield{type:"text",text:t.delta.text}:t.type==="message_stop"?yield{type:"done",usage:t.usage?{promptTokens:t.usage.input_tokens??0,completionTokens:t.usage.output_tokens??0}:void 0}:t.type==="error"&&(yield{type:"error",error:t.error?.message??"Claude stream error"})}catch{}}}}finally{i.cancel().catch(()=>{})}yield{type:"done"}}const k={id:"claude",name:"Claude (Anthropic)",version:"1.0.0",type:"ai-provider",description:"Anthropic Claude AI via proxy server",supportsStreaming:!0,supportsVision:!0,supportsTools:!0,async init(r){},async destroy(){},async isAvailable(){try{const r=await fetch(y,{method:"OPTIONS"});return r.ok||r.status===405}catch{return!1}},chat(r,o){return h(r,o)},async models(){return[{id:"claude-haiku-4.5",name:"Claude 4.5 Haiku",provider:"claude",supportsVision:!0,supportsTools:!0,contextWindow:2e5},{id:"claude-sonnet-4",name:"Claude Sonnet 4",provider:"claude",supportsVision:!0,supportsTools:!0,contextWindow:2e5},{id:"claude-opus-4",name:"Claude Opus 4",provider:"claude",supportsVision:!0,supportsTools:!0,contextWindow:2e5}]}};export{k as claudeProvider};
