module.exports=[629173,e=>{"use strict";e.s(["sanitizeSurrogates",0,function(e){return e.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,"")}])},266214,e=>{"use strict";e.s(["headersToRecord",0,function(e){let t={};for(let[a,s]of e.entries())t[a]=s;return t}])},91601,e=>{"use strict";var t=e.i(88045);e.s(["default",()=>t.OpenAI])},709565,e=>{"use strict";e.i(889228);var t=e.i(91601),a=e.i(678713),s=e.i(266214),r=e.i(629173);let o=async(e,o,i)=>{let u={api:e.api,provider:e.provider,model:e.id,output:[],stopReason:"stop",timestamp:Date.now()};try{var n,c,p,l,d,m;let g,h,f,y,R,x,_,v,w=i?.apiKey||(0,a.getEnvApiKey)(e.provider);if(!w)throw Error(`No API key available for provider: ${e.provider}`);let F=(n=e,c=w,p=i?.headers,new t.default({apiKey:c,baseURL:n.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:{...n.headers,...p}})),D=(l=e,g=o.input.map(e=>"text"===e.type?{type:"text",text:(0,r.sanitizeSurrogates)(e.text)}:{type:"image_url",image_url:{url:`data:${e.mimeType};base64,${e.data}`}}),{model:l.id,messages:[{role:"user",content:g}],stream:!1,modalities:l.output.includes("text")?["image","text"]:["image"]}),k=await i?.onPayload?.(D,e);void 0!==k&&(D=k);let b={...i?.signal?{signal:i.signal}:{},...i?.timeoutMs!==void 0?{timeout:i.timeoutMs}:{},...i?.maxRetries!==void 0?{maxRetries:i.maxRetries}:{}},{data:M,response:T}=await F.chat.completions.create(D,b).withResponse();await i?.onResponse?.({status:T.status,headers:(0,s.headersToRecord)(T.headers)},e);u.responseId=M.id,M.usage&&(d=M.usage,m=e,h=d.prompt_tokens||0,f=d.prompt_tokens_details?.cached_tokens||0,R=(y=d.prompt_tokens_details?.cache_write_tokens||0)>0?Math.max(0,f-y):f,x=Math.max(0,h-R-y),_=d.completion_tokens||0,(v={input:x,output:_,cacheRead:R,cacheWrite:y,totalTokens:x+_+R+y,cost:{input:m.cost.input/1e6*x,output:m.cost.output/1e6*_,cacheRead:m.cost.cacheRead/1e6*R,cacheWrite:m.cost.cacheWrite/1e6*y,total:0}}).cost.total=v.cost.input+v.cost.output+v.cost.cacheRead+v.cost.cacheWrite,u.usage=v);let W=M.choices[0];if(W){let e=W.message.content;for(let t of("string"==typeof e&&e.length>0&&u.output.push({type:"text",text:e}),W.message.images??[])){let e="string"==typeof t.image_url?t.image_url:t.image_url?.url;if(!e?.startsWith("data:"))continue;let a=e.match(/^data:([^;]+);base64,(.+)$/);a&&u.output.push({type:"image",mimeType:a[1],data:a[2]})}}return u}catch(e){return u.stopReason=i?.signal?.aborted?"aborted":"error",u.errorMessage=e instanceof Error?e.message:JSON.stringify(e),u}};e.s(["generateImagesOpenRouter",0,o])}];

//# sourceMappingURL=node_modules_0kmd0wu._.js.map