import {c,e as e$1,a,b,d as d$1,f,h,g}from'./chunk-265ZKXYE.js';import {d,e}from'./chunk-W6WZBQER.js';var K={"claude-sonnet-4-5-20250929":{input:3,output:15},"claude-sonnet-4-20250514":{input:3,output:15},"claude-haiku-4-5-20250514":{input:.8,output:4},"claude-haiku-3-5-20241022":{input:.8,output:4},"claude-opus-4-20250514":{input:15,output:75}};function L(h){let{apiKey:i,model:k="claude-sonnet-4-5-20250929",maxTokens:d$1=4096,baseURL:u="https://api.anthropic.com/v1",fetch:f=globalThis.fetch,timeoutMs:r,hooks:m,temperature:p,topP:c$1,stopSequences:o}=h;return d(u),c(i,"createAnthropicRunner"),e({fetch:f,hooks:m,buildRequest:(n,s,a)=>({url:`${u}/messages`,init:{method:"POST",headers:{"Content-Type":"application/json","x-api-key":i,"anthropic-version":"2023-06-01"},body:JSON.stringify({model:n.model??k,max_tokens:d$1,...p!=null?{temperature:p}:{},...c$1!=null?{top_p:c$1}:{},...o!=null?{stop_sequences:o}:{},system:n.instructions??"",messages:a.map(e=>({role:e.role,content:e.content}))}),...r!=null?{signal:AbortSignal.timeout(r)}:{}}}),parseResponse:async n=>{let s=await n.json(),a=s.content?.[0]?.text??"",e=s.usage?.input_tokens??0,l=s.usage?.output_tokens??0;return {text:a,totalTokens:e+l,inputTokens:e,outputTokens:l}}})}function N(h$1){let{apiKey:i,model:k="claude-sonnet-4-5-20250929",maxTokens:d$2=4096,baseURL:u="https://api.anthropic.com/v1",fetch:f$1=globalThis.fetch,hooks:r,temperature:m,topP:p,stopSequences:c$1}=h$1;return d(u),c(i,"createAnthropicStreamingRunner"),async(o,n,s)=>{let a$1=e$1(r,o,n);try{let e=await f$1(`${u}/messages`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":i,"anthropic-version":"2023-06-01"},body:JSON.stringify({model:o.model??k,max_tokens:d$2,...m!=null?{temperature:m}:{},...p!=null?{top_p:p}:{},...c$1!=null?{stop_sequences:c$1}:{},system:o.instructions??"",messages:[{role:"user",content:n}],stream:!0}),signal:s.signal});e.ok||await a(e,"Anthropic");let l=b(e),{fullText:R,inputTokens:b$1,outputTokens:S}=await d$1(l,s.onToken,t=>{if(t.type==="error")throw new Error(`[Directive] Anthropic stream error: ${t.error?.message??JSON.stringify(t.error)}`);let g={};return t.type==="content_block_delta"&&t.delta?.type==="text_delta"&&(g.text=t.delta.text),t.type==="message_delta"&&t.usage&&(g.outputTokens=t.usage.output_tokens??0),t.type==="message_start"&&t.message?.usage&&(g.inputTokens=t.message.usage.input_tokens??0),g},"Anthropic"),x={inputTokens:b$1,outputTokens:S},A=b$1+S;return s.onMessage?.({role:"assistant",content:R}),f(r,o,n,R,A,x,a$1),h(n,R,A,x)}catch(e){throw g(r,o,n,e,a$1),e}}}
export{K as ANTHROPIC_PRICING,L as createAnthropicRunner,N as createAnthropicStreamingRunner};//# sourceMappingURL=anthropic.js.map
//# sourceMappingURL=anthropic.js.map