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 $={"gemini-2.5-pro":{input:1.25,output:10},"gemini-2.5-flash":{input:.15,output:.6},"gemini-2.0-flash":{input:.1,output:.4},"gemini-2.0-flash-lite":{input:.025,output:.1}};function v(h){let{apiKey:u,model:T="gemini-2.0-flash",maxOutputTokens:p,baseURL:m="https://generativelanguage.googleapis.com/v1beta",fetch:b=globalThis.fetch,timeoutMs:i,hooks:g,temperature:c$1,topP:l,stopSequences:n}=h;d(m),c(u,"createGeminiRunner");let o={};p!=null&&(o.maxOutputTokens=p),c$1!=null&&(o.temperature=c$1),l!=null&&(o.topP=l),n!=null&&(o.stopSequences=n);let s=Object.keys(o).length>0;return e({fetch:b,hooks:g,buildRequest:(t,r,a)=>({url:`${m}/models/${t.model??T}:generateContent`,init:{method:"POST",headers:{"Content-Type":"application/json","x-goog-api-key":u},body:JSON.stringify({...t.instructions?{systemInstruction:{parts:[{text:t.instructions}]}}:{},contents:a.map(e=>({role:e.role==="assistant"?"model":"user",parts:[{text:e.content}]})),...s?{generationConfig:o}:{}}),...i!=null?{signal:AbortSignal.timeout(i)}:{}}}),parseResponse:async t=>{let r=await t.json(),a=r.candidates?.[0]?.content?.parts?.[0]?.text??"",e=r.usageMetadata?.promptTokenCount??0,f=r.usageMetadata?.candidatesTokenCount??0;return {text:a,totalTokens:e+f,inputTokens:e,outputTokens:f}}})}function B(h$1){let{apiKey:u,model:T="gemini-2.0-flash",maxOutputTokens:p,baseURL:m="https://generativelanguage.googleapis.com/v1beta",fetch:b$1=globalThis.fetch,hooks:i,temperature:g$1,topP:c$1,stopSequences:l}=h$1;d(m),c(u,"createGeminiStreamingRunner");let n={};p!=null&&(n.maxOutputTokens=p),g$1!=null&&(n.temperature=g$1),c$1!=null&&(n.topP=c$1),l!=null&&(n.stopSequences=l);let o=Object.keys(n).length>0;return async(s,t,r)=>{let a$1=e$1(i,s,t);try{let e=await b$1(`${m}/models/${s.model??T}:streamGenerateContent?alt=sse`,{method:"POST",headers:{"Content-Type":"application/json","x-goog-api-key":u},body:JSON.stringify({...s.instructions?{systemInstruction:{parts:[{text:s.instructions}]}}:{},contents:[{role:"user",parts:[{text:t}]}],...o?{generationConfig:n}:{}}),signal:r.signal});e.ok||await a(e,"Gemini");let f$1=b(e),{fullText:R,inputTokens:C,outputTokens:O}=await d$1(f$1,r.onToken,y=>{let d={},A=y.candidates?.[0]?.content?.parts?.[0]?.text;if(A&&(d.text=A),y.usageMetadata){let k=y.usageMetadata;k.promptTokenCount!==void 0&&(d.inputTokens=k.promptTokenCount),k.candidatesTokenCount!==void 0&&(d.outputTokens=k.candidatesTokenCount);}return d},"Gemini"),G={inputTokens:C,outputTokens:O},w=C+O;return r.onMessage?.({role:"assistant",content:R}),f(i,s,t,R,w,G,a$1),h(t,R,w,G)}catch(e){throw g(i,s,t,e,a$1),e}}}
export{$ as GEMINI_PRICING,v as createGeminiRunner,B as createGeminiStreamingRunner};//# sourceMappingURL=gemini.js.map
//# sourceMappingURL=gemini.js.map