@adaline/google 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,25 +4,25 @@ var zod = require('zod');
4
4
  var provider = require('@adaline/provider');
5
5
  var types = require('@adaline/types');
6
6
 
7
- var pt=Object.defineProperty,ct=Object.defineProperties;var gt=Object.getOwnPropertyDescriptors;var Co=Object.getOwnPropertySymbols;var ht=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var W=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),ut=r=>{throw TypeError(r)};var To=(r,e,t)=>e in r?pt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_=(r,e)=>{for(var t in e||(e={}))ht.call(e,t)&&To(r,t,e[t]);if(Co)for(var t of Co(e))ft.call(e,t)&&To(r,t,e[t]);return r},N=(r,e)=>ct(r,gt(e));var S=(r,e,t)=>new Promise((o,i)=>{var l=a=>{try{n(t.next(a));}catch(s){i(s);}},m=a=>{try{n(t.throw(a));}catch(s){i(s);}},n=a=>a.done?o(a.value):Promise.resolve(a.value).then(l,m);n((t=t.apply(r,e)).next());}),Mo=function(r,e){this[0]=r,this[1]=e;},je=(r,e,t)=>{var o=(m,n,a,s)=>{try{var d=t[m](n),g=(n=d.value)instanceof Mo,C=d.done;Promise.resolve(g?n[0]:n).then(f=>g?o(m==="return"?m:"next",n[1]?{done:f.done,value:f.value}:f,a,s):a({value:f,done:C})).catch(f=>o("throw",f,a,s));}catch(f){s(f);}},i=m=>l[m]=n=>new Promise((a,s)=>o(m,n,a,s)),l={};return t=t.apply(r,e),l[W("asyncIterator")]=()=>l,i("next"),i("throw"),i("return"),l},bo=r=>{var e=r[W("asyncIterator")],t=!1,o,i={};return e==null?(e=r[W("iterator")](),o=l=>i[l]=m=>e[l](m)):(e=e.call(r),o=l=>i[l]=m=>{if(t){if(t=!1,l==="throw")throw m;return m}return t=!0,{done:!1,value:new Mo(new Promise(n=>{var a=e[l](m);a instanceof Object||ut("Object expected"),n(a);}),1)}}),i[W("iterator")]=()=>i,o("next"),"throw"in e?o("throw"):i.throw=l=>{throw l},"return"in e&&o("return"),i};var Be=(r,e)=>provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:0,max:r,step:.01,default:e}),qe=r=>provider.RangeConfigItem({param:"maxOutputTokens",title:provider.CHAT_CONFIG.MAX_TOKENS.title,description:provider.CHAT_CONFIG.MAX_TOKENS.description,min:0,max:r,step:1,default:0}),ze=r=>provider.MultiStringConfigItem({param:"stopSequences",title:provider.CHAT_CONFIG.STOP(r).title,description:provider.CHAT_CONFIG.STOP(r).description,max:r}),Ae=r=>provider.RangeConfigItem({param:"topP",title:provider.CHAT_CONFIG.TOP_P.title,description:provider.CHAT_CONFIG.TOP_P.description,min:0,max:1,step:.01,default:r}),jn=r=>provider.RangeConfigItem({param:"topK",title:provider.CHAT_CONFIG.TOP_K.title,description:provider.CHAT_CONFIG.TOP_K.description,min:1,max:40,step:1,default:r}),Bn=provider.RangeConfigItem({param:"frequencyPenalty",title:provider.CHAT_CONFIG.FREQUENCY_PENALTY.title,description:provider.CHAT_CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),qn=provider.RangeConfigItem({param:"presencePenalty",title:provider.CHAT_CONFIG.PRESENCE_PENALTY.title,description:provider.CHAT_CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),zn=provider.RangeConfigItem({param:"seed",title:provider.CHAT_CONFIG.SEED.title,description:provider.CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),He=provider.SelectStringConfigItem({param:"toolChoice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'none' means the model will not call a function. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","any","none"]}),Ke=provider.ObjectSchemaConfigItem({param:"safetySettings",title:"Safety settings",description:"The safety rating contains the category of harm and the harm probability level in that category for a piece of content.",objectSchema:zod.z.array(zod.z.object({threshold:zod.z.enum(["HARM_BLOCK_THRESHOLD_UNSPECIFIED","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH","BLOCK_NONE","OFF"]),category:zod.z.enum(["HARM_CATEGORY_UNSPECIFIED","HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT","HARM_CATEGORY_CIVIC_INTEGRITY"])}))}),Ye=provider.SelectBooleanConfigItem({param:"reasoningEnabled",title:"Reasoning Enabled",description:"Controls whether the model is allowed to think for a longer period of time before generating a response. This can be useful for complex tasks that require more time to think.",default:!1});var Q=(r,e,t,o,i)=>zod.z.object({temperature:Be(r,e).schema,maxTokens:qe(t).schema,stop:ze(o).schema,topP:Ae(i).schema,toolChoice:He.schema,safetySettings:Ke.schema}),ee=(r,e,t,o,i)=>({temperature:Be(r,e).def,maxTokens:qe(t).def,stop:ze(o).def,topP:Ae(i).def,toolChoice:He.def,safetySettings:Ke.def});var Go=provider.ObjectSchemaConfigItem({param:"response_schema",title:provider.CHAT_CONFIG.RESPONSE_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_SCHEMA.description,objectSchema:types.ResponseSchema}),Po=provider.SelectStringConfigItem({param:"response_format",title:provider.CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_schema"]}),te=(r,e,t,o,i)=>N(_({},ee(r,e,t,o,i)),{responseFormat:Po.def,responseSchema:Go.def}),ne=(r,e,t,o,i)=>Q(r,e,t,o,i).extend({responseFormat:Po.schema,responseSchema:Go.schema});var _o=(r,e,t,o,i)=>ne(r,e,t,o,i).extend({reasoningEnabled:Ye.schema}),So=(r,e,t,o,i)=>N(_({},te(r,e,t,o,i)),{reasoningEnabled:Ye.def});var Ve=r=>provider.RangeConfigItem({param:"outputDimensionality",title:provider.EMBEDDING_CONFIG.DIMENSIONS.title,description:provider.EMBEDDING_CONFIG.DIMENSIONS.description,min:1,max:r,step:1,default:r});var Ro=r=>zod.z.object({dimensions:Ve(r).schema}),Oo=r=>({dimensions:Ve(r).def});var h={base:(r,e,t,o,i)=>({def:ee(r,e,t,o,i),schema:Q(r,e,t,o,i)}),responseSchema:(r,e,t,o,i)=>({def:te(r,e,t,o,i),schema:ne(r,e,t,o,i)}),reasoning:(r,e,t,o,i)=>({def:So(r,e,t,o,i),schema:_o(r,e,t,o,i)})},j={base:r=>({def:Oo(r),schema:Ro(r)})};var Rt="google",$=class{constructor(){this.version="v1";this.name=Rt;this.chatModelFactories={[ie]:{model:se,modelOptions:xo,modelSchema:Je},[ae]:{model:re,modelOptions:ko,modelSchema:Xe},[le]:{model:me,modelOptions:vo,modelSchema:We},[de]:{model:pe,modelOptions:Fo,modelSchema:Ze},[ce]:{model:ge,modelOptions:No,modelSchema:Qe},[he]:{model:fe,modelOptions:Io,modelSchema:eo},[ue]:{model:ye,modelOptions:Do,modelSchema:oo},[Ce]:{model:Te,modelOptions:Lo,modelSchema:to},[Me]:{model:be,modelOptions:Uo,modelSchema:no},[Ge]:{model:Pe,modelOptions:$o,modelSchema:io},[_e]:{model:Se,modelOptions:jo,modelSchema:so},[Ee]:{model:Re,modelOptions:Bo,modelSchema:ao},[Oe]:{model:we,modelOptions:qo,modelSchema:ro}};this.embeddingModelFactories={[lo]:{model:xe,modelOptions:zo,modelSchema:mo},[po]:{model:ke,modelOptions:Ao,modelSchema:co}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,t)=>(e[t]=this.chatModelFactories[t].modelSchema,e),{})}chatModel(e){let t=e.modelName;if(!(t in this.chatModelFactories))throw new provider.ProviderError({info:`Google chat model: ${t} not found`,cause:new Error(`Google chat model: ${t} not found, available chat models:
7
+ var ct=Object.defineProperty,gt=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var Co=Object.getOwnPropertySymbols;var ft=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var W=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),yt=r=>{throw TypeError(r)};var To=(r,e,t)=>e in r?ct(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,P=(r,e)=>{for(var t in e||(e={}))ft.call(e,t)&&To(r,t,e[t]);if(Co)for(var t of Co(e))ut.call(e,t)&&To(r,t,e[t]);return r},N=(r,e)=>gt(r,ht(e));var S=(r,e,t)=>new Promise((o,i)=>{var l=a=>{try{n(t.next(a));}catch(s){i(s);}},m=a=>{try{n(t.throw(a));}catch(s){i(s);}},n=a=>a.done?o(a.value):Promise.resolve(a.value).then(l,m);n((t=t.apply(r,e)).next());}),Mo=function(r,e){this[0]=r,this[1]=e;},je=(r,e,t)=>{var o=(m,n,a,s)=>{try{var d=t[m](n),g=(n=d.value)instanceof Mo,C=d.done;Promise.resolve(g?n[0]:n).then(f=>g?o(m==="return"?m:"next",n[1]?{done:f.done,value:f.value}:f,a,s):a({value:f,done:C})).catch(f=>o("throw",f,a,s));}catch(f){s(f);}},i=m=>l[m]=n=>new Promise((a,s)=>o(m,n,a,s)),l={};return t=t.apply(r,e),l[W("asyncIterator")]=()=>l,i("next"),i("throw"),i("return"),l},bo=r=>{var e=r[W("asyncIterator")],t=!1,o,i={};return e==null?(e=r[W("iterator")](),o=l=>i[l]=m=>e[l](m)):(e=e.call(r),o=l=>i[l]=m=>{if(t){if(t=!1,l==="throw")throw m;return m}return t=!0,{done:!1,value:new Mo(new Promise(n=>{var a=e[l](m);a instanceof Object||yt("Object expected"),n(a);}),1)}}),i[W("iterator")]=()=>i,o("next"),"throw"in e?o("throw"):i.throw=l=>{throw l},"return"in e&&o("return"),i};var Be=(r,e)=>provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:0,max:r,step:.01,default:e}),qe=r=>provider.RangeConfigItem({param:"maxOutputTokens",title:provider.CHAT_CONFIG.MAX_TOKENS.title,description:provider.CHAT_CONFIG.MAX_TOKENS.description,min:0,max:r,step:1,default:0}),Ae=r=>provider.MultiStringConfigItem({param:"stopSequences",title:provider.CHAT_CONFIG.STOP(r).title,description:provider.CHAT_CONFIG.STOP(r).description,max:r}),ze=r=>provider.RangeConfigItem({param:"topP",title:provider.CHAT_CONFIG.TOP_P.title,description:provider.CHAT_CONFIG.TOP_P.description,min:0,max:1,step:.01,default:r}),qn=r=>provider.RangeConfigItem({param:"topK",title:provider.CHAT_CONFIG.TOP_K.title,description:provider.CHAT_CONFIG.TOP_K.description,min:1,max:40,step:1,default:r}),An=provider.RangeConfigItem({param:"frequencyPenalty",title:provider.CHAT_CONFIG.FREQUENCY_PENALTY.title,description:provider.CHAT_CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),zn=provider.RangeConfigItem({param:"presencePenalty",title:provider.CHAT_CONFIG.PRESENCE_PENALTY.title,description:provider.CHAT_CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),Hn=provider.RangeConfigItem({param:"seed",title:provider.CHAT_CONFIG.SEED.title,description:provider.CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),He=provider.SelectStringConfigItem({param:"toolChoice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'none' means the model will not call a function. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","any","none"]}),Ke=provider.ObjectSchemaConfigItem({param:"safetySettings",title:"Safety settings",description:"The safety rating contains the category of harm and the harm probability level in that category for a piece of content.",objectSchema:zod.z.array(zod.z.object({threshold:zod.z.enum(["HARM_BLOCK_THRESHOLD_UNSPECIFIED","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH","BLOCK_NONE","OFF"]),category:zod.z.enum(["HARM_CATEGORY_UNSPECIFIED","HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT","HARM_CATEGORY_CIVIC_INTEGRITY"])}))}),Ye=provider.SelectBooleanConfigItem({param:"reasoningEnabled",title:"Reasoning Enabled",description:"Controls whether the model is allowed to think for a longer period of time before generating a response. This can be useful for complex tasks that require more time to think.",default:!1});var Q=(r,e,t,o,i)=>zod.z.object({temperature:Be(r,e).schema,maxTokens:qe(t).schema,stop:Ae(o).schema,topP:ze(i).schema,toolChoice:He.schema,safetySettings:Ke.schema}),ee=(r,e,t,o,i)=>({temperature:Be(r,e).def,maxTokens:qe(t).def,stop:Ae(o).def,topP:ze(i).def,toolChoice:He.def,safetySettings:Ke.def});var Go=provider.ObjectSchemaConfigItem({param:"response_schema",title:provider.CHAT_CONFIG.RESPONSE_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_SCHEMA.description,objectSchema:types.ResponseSchema}),_o=provider.SelectStringConfigItem({param:"response_format",title:provider.CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_schema"]}),te=(r,e,t,o,i)=>N(P({},ee(r,e,t,o,i)),{responseFormat:_o.def,responseSchema:Go.def}),ne=(r,e,t,o,i)=>Q(r,e,t,o,i).extend({responseFormat:_o.schema,responseSchema:Go.schema});var Po=(r,e,t,o,i)=>ne(r,e,t,o,i).extend({reasoningEnabled:Ye.schema}),So=(r,e,t,o,i)=>N(P({},te(r,e,t,o,i)),{reasoningEnabled:Ye.def});var Ve=r=>provider.RangeConfigItem({param:"outputDimensionality",title:provider.EMBEDDING_CONFIG.DIMENSIONS.title,description:provider.EMBEDDING_CONFIG.DIMENSIONS.description,min:1,max:r,step:1,default:r});var Ro=r=>zod.z.object({dimensions:Ve(r).schema}),Oo=r=>({dimensions:Ve(r).def});var h={base:(r,e,t,o,i)=>({def:ee(r,e,t,o,i),schema:Q(r,e,t,o,i)}),responseSchema:(r,e,t,o,i)=>({def:te(r,e,t,o,i),schema:ne(r,e,t,o,i)}),reasoning:(r,e,t,o,i)=>({def:So(r,e,t,o,i),schema:Po(r,e,t,o,i)})},j={base:r=>({def:Oo(r),schema:Ro(r)})};var Ot="google",$=class{constructor(){this.version="v1";this.name=Ot;this.chatModelFactories={[ie]:{model:se,modelOptions:xo,modelSchema:Je},[ae]:{model:re,modelOptions:ko,modelSchema:Xe},[le]:{model:me,modelOptions:vo,modelSchema:We},[de]:{model:pe,modelOptions:Fo,modelSchema:Ze},[ce]:{model:ge,modelOptions:No,modelSchema:Qe},[he]:{model:fe,modelOptions:Io,modelSchema:eo},[ue]:{model:ye,modelOptions:Do,modelSchema:oo},[Ce]:{model:Te,modelOptions:Lo,modelSchema:to},[Me]:{model:be,modelOptions:Uo,modelSchema:no},[Ge]:{model:_e,modelOptions:$o,modelSchema:io},[Pe]:{model:Se,modelOptions:jo,modelSchema:so},[Ee]:{model:Re,modelOptions:Bo,modelSchema:ao},[Oe]:{model:we,modelOptions:qo,modelSchema:ro}};this.embeddingModelFactories={[lo]:{model:xe,modelOptions:Ao,modelSchema:mo},[po]:{model:ke,modelOptions:zo,modelSchema:co}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,t)=>(e[t]=this.chatModelFactories[t].modelSchema,e),{})}chatModel(e){let t=e.modelName;if(!(t in this.chatModelFactories))throw new provider.ProviderError({info:`Google chat model: ${t} not found`,cause:new Error(`Google chat model: ${t} not found, available chat models:
8
8
  [${this.chatModelLiterals().join(", ")}]`)});let o=this.chatModelFactories[t].model,i=this.chatModelFactories[t].modelOptions.parse(e);return new o(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,t)=>(e[t]=this.embeddingModelFactories[t].modelSchema,e),{})}embeddingModel(e){let t=e.modelName;if(!(t in this.embeddingModelFactories))throw new provider.ProviderError({info:`Google embedding model: ${t} not found`,cause:new Error(`Google embedding model: ${t} not found, available embedding models:
9
- [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[t].model,i=this.embeddingModelFactories[t].modelOptions.parse(e);return new o(i)}};$.baseUrl="https://generativelanguage.googleapis.com/v1beta";var u={"base-gemini-1-chat-model":{modelName:"base-gemini-1-chat-model",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:0,outputPricePerMillion:0}}}]},"gemini-1.0-pro-001":{modelName:"gemini-1.0-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-latest":{modelName:"gemini-1.0-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-vision":{modelName:"gemini-1.0-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro":{modelName:"gemini-1.0-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.5-flash-001":{modelName:"gemini-1.5-flash-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash-002":{modelName:"gemini-1.5-flash-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.0375,outputPricePerMillion:.15}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}}]},"gemini-1.5-flash-latest":{modelName:"gemini-1.5-flash-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash":{modelName:"gemini-1.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-pro-001":{modelName:"gemini-1.5-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-002":{modelName:"gemini-1.5-pro-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-latest":{modelName:"gemini-1.5-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro":{modelName:"gemini-1.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-2.0-flash-exp":{modelName:"gemini-2.0-flash-exp",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-2.5-flash-preview-04-17":{modelName:"gemini-2.5-flash-preview-04-17",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-2.5-pro-preview-03-25":{modelName:"gemini-2.5-pro-preview-03-25",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:15}}}]},"gemini-pro-vision":{modelName:"gemini-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-pro":{modelName:"gemini-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-2.5-pro":{modelName:"gemini-2.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}}]},"gemini-2.5-flash":{modelName:"gemini-2.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.3,outputPricePerMillion:2.5}}}]}};var M=zod.z.enum([types.SystemRoleLiteral,types.UserRoleLiteral,types.AssistantRoleLiteral,types.ToolRoleLiteral]),Ft="model",Nt="function",b={system:types.UserRoleLiteral,user:types.UserRoleLiteral,assistant:Ft,tool:Nt};var G=[types.TextModalityLiteral,types.ImageModalityLiteral,types.PdfModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],P=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral,types.PdfModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]),Si=[types.TextModalityLiteral],Ei=zod.z.enum([types.TextModalityLiteral]),Ri=[types.TextModalityLiteral,types.ImageModalityLiteral],Oi=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral]),wi=[types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],xi=zod.z.enum([types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]);var It=zod.z.object({text:zod.z.string()}),Dt=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Ko=zod.z.object({candidates:zod.z.array(zod.z.object({content:zod.z.object({role:zod.z.string(),parts:zod.z.array(zod.z.union([It,Dt]))}).optional(),finishReason:zod.z.string(),index:zod.z.number().optional(),safetyRatings:zod.z.optional(zod.z.array(zod.z.object({category:zod.z.string(),probability:zod.z.string(),blocked:zod.z.boolean().optional()})))})),promptFeedback:zod.z.optional(zod.z.object({safetyRatings:zod.z.optional(zod.z.array(zod.z.object({category:zod.z.string(),probability:zod.z.string()})))})),usageMetadata:zod.z.object({promptTokenCount:zod.z.number(),cachedContentTokenCount:zod.z.number().optional(),candidatesTokenCount:zod.z.number().optional(),totalTokenCount:zod.z.number()}).optional()}),Lt=zod.z.object({text:zod.z.string()}),Ut=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),ho=zod.z.object({candidates:zod.z.array(zod.z.object({content:zod.z.object({role:zod.z.string(),parts:zod.z.array(zod.z.union([Lt,Ut]))}).optional(),finishReason:zod.z.string().optional(),index:zod.z.number().optional(),safetyRatings:zod.z.optional(zod.z.array(zod.z.object({category:zod.z.string(),probability:zod.z.string(),blocked:zod.z.boolean().optional()})))})),promptFeedback:zod.z.optional(zod.z.object({safetyRatings:zod.z.optional(zod.z.array(zod.z.object({category:zod.z.string(),probability:zod.z.string()})))})),usageMetadata:zod.z.object({promptTokenCount:zod.z.number().optional(),cachedContentTokenCount:zod.z.number().optional(),candidatesTokenCount:zod.z.number().optional(),totalTokenCount:zod.z.number().optional()}).optional()});var Wo=zod.z.object({text:zod.z.string().min(1)}),$t=zod.z.object({inline_data:zod.z.object({mime_type:zod.z.string().min(1),data:zod.z.string().base64()})}),jt=zod.z.object({file_data:zod.z.object({mime_type:zod.z.string().min(1),file_uri:zod.z.string().min(1)})}),Bt=zod.z.object({function_call:zod.z.object({name:zod.z.string().min(1),args:zod.z.record(zod.z.string().min(1))})}),qt=zod.z.object({function_response:zod.z.object({name:zod.z.string().min(1),response:zod.z.record(zod.z.string().min(1))})}),zt=zod.z.object({role:zod.z.enum(["user","model","function"]),parts:zod.z.array(zod.z.union([Wo,$t,jt,Bt,qt]))}),Yo=zod.z.object({parts:zod.z.array(Wo)}),At=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),parameters:zod.z.any()}),Vo=zod.z.object({function_calling_config:zod.z.object({mode:zod.z.enum(["ANY","AUTO","NONE"]),allowed_function_names:zod.z.array(zod.z.string()).optional()})}),Jo=zod.z.object({stopSequences:zod.z.array(zod.z.string()).optional(),maxOutputTokens:zod.z.number().optional(),temperature:zod.z.number().optional(),topP:zod.z.number().optional(),topK:zod.z.number().optional(),presencePenalty:zod.z.number().optional(),frequencyPenalty:zod.z.number().optional(),seed:zod.z.number().optional()}),Xo=zod.z.object({category:zod.z.enum(["HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT","HARM_CATEGORY_CIVIC_INTEGRITY"]),threshold:zod.z.enum(["HARM_BLOCK_THRESHOLD_UNSPECIFIED","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH","BLOCK_NONE","OFF"])}),Zo=zod.z.object({model:zod.z.string().min(1).optional(),contents:zod.z.array(zt),systemInstruction:Yo.optional(),system_instruction:Yo.optional(),generationConfig:Jo.optional(),generation_config:Jo.optional(),safetySettings:zod.z.array(Xo).optional(),safety_settings:zod.z.array(Xo).optional(),tools:zod.z.object({function_declarations:zod.z.array(At)}).optional(),toolConfig:Vo.optional(),tool_config:Vo.optional()});var T=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),y=class{constructor(e,t){this.version="v1";var i;let o=T.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash((i=o.baseUrl)!=null?i:$.baseUrl),this.completeChatUrl=provider.urlWithoutTrailingSlash(o.completeChatUrl||`${this.baseUrl}/models/${this.modelName}:generateContent?key=${this.apiKey}`),this.streamChatUrl=provider.urlWithoutTrailingSlash(o.streamChatUrl||`${this.baseUrl}/models/${this.modelName}:streamGenerateContent?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.reduce((t,o)=>t+o.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformPdfMessages(e){return S(this,null,function*(){let t=n=>S(this,null,function*(){let a=yield fetch(n,{headers:{"User-Agent":"Mozilla/5.0 (compatible; GoogleFilesAPI/1.0)"}});if(!a.ok)throw new provider.InvalidMessagesError({info:`Failed to download PDF from URL: ${n}`,cause:new Error(`HTTP ${a.status}: ${a.statusText}`)});let s=yield a.arrayBuffer();return Buffer.from(s)}),o=n=>S(this,null,function*(){try{let a=yield fetch(`https://generativelanguage.googleapis.com/v1beta/files?key=${this.apiKey}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok)return null;let g=((yield a.json()).files||[]).find(C=>C.displayName===n);return g?g.uri:null}catch(a){return null}}),i=(n,a)=>S(this,null,function*(){let s=yield fetch(`https://generativelanguage.googleapis.com/upload/v1beta/files?key=${this.apiKey}`,{method:"POST",headers:{"X-Goog-Upload-Protocol":"resumable","X-Goog-Upload-Command":"start","X-Goog-Upload-Header-Content-Length":n.length.toString(),"X-Goog-Upload-Header-Content-Type":"application/pdf","Content-Type":"application/json"},body:JSON.stringify({file:{display_name:a}})});if(!s.ok)throw new provider.InvalidMessagesError({info:"Failed to start PDF upload to Google Files API",cause:new Error(`HTTP ${s.status}: ${s.statusText}`)});let d=s.headers.get("x-goog-upload-url");if(!d)throw new provider.InvalidMessagesError({info:"No upload URL received from Google Files API",cause:new Error("Missing x-goog-upload-url header")});let g=yield fetch(d,{method:"POST",headers:{"Content-Length":n.length.toString(),"X-Goog-Upload-Offset":"0","X-Goog-Upload-Command":"upload, finalize"},body:n});if(!g.ok)throw new provider.InvalidMessagesError({info:"Failed to upload PDF content to Google Files API",cause:new Error(`HTTP ${g.status}: ${g.statusText}`)});return (yield g.json()).file.uri}),l=n=>S(this,null,function*(){let a=yield o(n.providerCacheKey);if(a)return a;let s;if(n.value.type==="url")s=yield t(n.value.url);else {let d=n.value.base64,g="data:application/pdf;base64,";d=d.startsWith(g)?d.substring(g.length):d,s=Buffer.from(d,"base64");let C=s.toString("ascii",0,4);if(C!=="%PDF")throw new provider.InvalidMessagesError({info:`Base64 content is not a valid PDF. Header: ${C}`,cause:new Error(`Expected PDF header '%PDF', got '${C}'`)})}return yield i(s,n.providerCacheKey)}),m=[];for(let n of e){let a=[];for(let s of n.content)if(s.modality===types.PdfModalityLiteral){let d=yield l(s);a.push(N(_({},s),{value:{type:"url",url:d}}));}else a.push(s);m.push(N(_({},n),{content:a}));}return m})}transformModelRequest(e){let t=Zo.safeParse(e);if(!t.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,i=o.model;if(o.system_instruction&&o.systemInstruction)throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'system_instruction' and 'systemInstruction' are not allowed at the same time")});if(o.generation_config&&o.generationConfig)throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'generation_config' and 'generationConfig' are not allowed at the same time")});if(o.tool_config&&o.toolConfig)throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tool_config' and 'toolConfig' are not allowed at the same time")});let l=o.system_instruction||o.systemInstruction,m=o.generation_config||o.generationConfig,n=o.safety_settings||o.safetySettings,a=o.tool_config||o.toolConfig;if(a&&(!o.tools||o.tools.function_declarations.length===0))throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let s={};a&&(a.function_calling_config.mode==="ANY"&&a.function_calling_config.allowed_function_names&&a.function_calling_config.allowed_function_names.length===1?s.toolChoice=a.function_calling_config.allowed_function_names[0]:s.toolChoice=a.function_calling_config.mode.toLowerCase()),s.seed=m==null?void 0:m.seed,s.maxTokens=m==null?void 0:m.maxOutputTokens,s.temperature=m==null?void 0:m.temperature,s.topP=m==null?void 0:m.topP,s.presencePenalty=m==null?void 0:m.presencePenalty,s.frequencyPenalty=m==null?void 0:m.frequencyPenalty,s.stop=m==null?void 0:m.stopSequences,s.safetySettings=n;let d=types.Config().parse(provider.removeUndefinedEntries(s)),g=[];l&&l.parts.forEach(f=>{g.push({role:types.SystemRoleLiteral,content:[{modality:types.TextModalityLiteral,value:f.text}]});}),o.contents.forEach(f=>{let w=f.role;switch(w){case"user":{let k=f.parts.map(R=>"text"in R?{modality:types.TextModalityLiteral,value:R.text}:{modality:types.ImageModalityLiteral,detail:"auto",value:{type:types.Base64ImageContentTypeLiteral,base64:R.inline_data.data,mediaType:R.inline_data.mime_type.split("/")[1]}});g.push({role:w,content:k});}break;case"model":{let k=f.parts.map((R,F)=>"text"in R?{modality:types.TextModalityLiteral,value:R.text}:{modality:types.ToolCallModalityLiteral,id:F.toString(),index:F,name:R.function_call.name,arguments:JSON.stringify(R.function_call.args)});g.push({role:types.AssistantRoleLiteral,content:k});}break;case"function":{let k=f.parts.map((R,F)=>({modality:types.ToolResponseModalityLiteral,id:F.toString(),index:F,name:R.function_response.name,data:JSON.stringify(R.function_response.response)}));g.push({role:types.ToolRoleLiteral,content:k});}break;default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${f.role}' is not supported for model : ${this.modelName}`)})}});let C=[];return o.tools&&o.tools.function_declarations.forEach(f=>{C.push({type:"function",definition:{schema:{name:f.name,description:f.description,parameters:f.parameters}}});}),{modelName:i,config:d,messages:g,tools:C.length>0?C:void 0}}transformConfig(e,t,o){let i=e.toolChoice;delete e.toolChoice;let l=this.modelSchema.config.schema.safeParse(e);if(!l.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:l.error});let m=l.data;Object.keys(m).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
10
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let n=Object.keys(m).reduce((d,g)=>{let C=this.modelSchema.config.def[g],f=C.param,w=m[g];return g==="reasoningEnabled"?d.thinkingConfig={includeThoughts:w}:g==="maxReasoningTokens"?d.thinkingConfig=d.thinkingConfig&&typeof d.thinkingConfig=="object"?N(_({},d.thinkingConfig),{thinkingBudget:w}):{thinkingBudget:w}:f==="maxOutputTokens"&&C.type==="range"&&w===0?d[f]=C.max:d[f]=w,d},{}),a=n.safetySettings;delete n.safetySettings;let s;if(i!==void 0){let d=i;if(!o||o&&o.length===0)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let g=this.modelSchema.config.def.toolChoice;if(g.choices.includes(d))d==="any"?s={function_calling_config:{mode:"ANY",allowed_function_names:o.map(C=>C.definition.schema.name)}}:s={function_calling_config:{mode:d.toUpperCase()}};else if(o.map(C=>C.definition.schema.name).includes(d))s={function_calling_config:{mode:"ANY",allowed_function_names:[d]}};else throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
11
- one of [${g.choices.join(", ")}]`)})}}if("response_format"in n&&n.response_format!==void 0){let d=n.response_format;if(d==="json_schema"){let g=n.response_schema;if(!("response_schema"in n)||!n.response_schema||!(g!=null&&g.schema))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});n.responseSchema=g.schema,n.responseMimeType="application/json","additionalProperties"in g.schema&&delete n.responseSchema.additionalProperties,delete n.response_format,delete n.response_schema;}else d==="json_object"?(n.responseSchema={type:"object"},delete n.response_format):d==="text"&&delete n.response_format;}return _(_({generation_config:n},s?{tool_config:s}:{}),a?{safety_settings:a}:{})}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let t=n=>{let a=n.match(/^data:(image\/[a-zA-Z]+|application\/pdf);base64,/);return a?n.substring(a[0].length):n},o=e.map(n=>{let a=types.Message().safeParse(n);if(!a.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:a.error});return a.data});o.forEach(n=>{n.content.forEach(a=>{if(!this.modelSchema.modalities.includes(a.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${a.modality}',
9
+ [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[t].model,i=this.embeddingModelFactories[t].modelOptions.parse(e);return new o(i)}};$.baseUrl="https://generativelanguage.googleapis.com/v1beta";var u={"base-gemini-1-chat-model":{modelName:"base-gemini-1-chat-model",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:0,outputPricePerMillion:0}}}]},"gemini-1.0-pro-001":{modelName:"gemini-1.0-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-latest":{modelName:"gemini-1.0-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-vision":{modelName:"gemini-1.0-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro":{modelName:"gemini-1.0-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.5-flash-001":{modelName:"gemini-1.5-flash-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash-002":{modelName:"gemini-1.5-flash-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.0375,outputPricePerMillion:.15}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}}]},"gemini-1.5-flash-latest":{modelName:"gemini-1.5-flash-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash":{modelName:"gemini-1.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-pro-001":{modelName:"gemini-1.5-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-002":{modelName:"gemini-1.5-pro-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-latest":{modelName:"gemini-1.5-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro":{modelName:"gemini-1.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-2.0-flash-exp":{modelName:"gemini-2.0-flash-exp",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-2.5-flash-preview-04-17":{modelName:"gemini-2.5-flash-preview-04-17",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-2.5-pro-preview-03-25":{modelName:"gemini-2.5-pro-preview-03-25",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:15}}}]},"gemini-pro-vision":{modelName:"gemini-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-pro":{modelName:"gemini-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-2.5-pro":{modelName:"gemini-2.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}}]},"gemini-2.5-flash":{modelName:"gemini-2.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.3,outputPricePerMillion:2.5}}}]}};var M=zod.z.enum([types.SystemRoleLiteral,types.UserRoleLiteral,types.AssistantRoleLiteral,types.ToolRoleLiteral]),Nt="model",It="function",b={system:types.UserRoleLiteral,user:types.UserRoleLiteral,assistant:Nt,tool:It};var G=[types.TextModalityLiteral,types.ImageModalityLiteral,types.PdfModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],_=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral,types.PdfModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]),Ri=[types.TextModalityLiteral],Oi=zod.z.enum([types.TextModalityLiteral]),wi=[types.TextModalityLiteral,types.ImageModalityLiteral],xi=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral]),ki=[types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],vi=zod.z.enum([types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]);var Dt=zod.z.object({text:zod.z.string()}),Lt=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Ko=zod.z.object({candidates:zod.z.array(zod.z.object({content:zod.z.object({role:zod.z.string(),parts:zod.z.array(zod.z.union([Dt,Lt]))}).optional(),finishReason:zod.z.string(),index:zod.z.number().optional(),safetyRatings:zod.z.optional(zod.z.array(zod.z.object({category:zod.z.string(),probability:zod.z.string(),blocked:zod.z.boolean().optional()})))})),promptFeedback:zod.z.optional(zod.z.object({safetyRatings:zod.z.optional(zod.z.array(zod.z.object({category:zod.z.string(),probability:zod.z.string()})))})),usageMetadata:zod.z.object({promptTokenCount:zod.z.number(),cachedContentTokenCount:zod.z.number().optional(),candidatesTokenCount:zod.z.number().optional(),totalTokenCount:zod.z.number()}).optional()}),Ut=zod.z.object({text:zod.z.string()}),$t=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),ho=zod.z.object({candidates:zod.z.array(zod.z.object({content:zod.z.object({role:zod.z.string(),parts:zod.z.array(zod.z.union([Ut,$t]))}).optional(),finishReason:zod.z.string().optional(),index:zod.z.number().optional(),safetyRatings:zod.z.optional(zod.z.array(zod.z.object({category:zod.z.string(),probability:zod.z.string(),blocked:zod.z.boolean().optional()})))})),promptFeedback:zod.z.optional(zod.z.object({safetyRatings:zod.z.optional(zod.z.array(zod.z.object({category:zod.z.string(),probability:zod.z.string()})))})),usageMetadata:zod.z.object({promptTokenCount:zod.z.number().optional(),cachedContentTokenCount:zod.z.number().optional(),candidatesTokenCount:zod.z.number().optional(),totalTokenCount:zod.z.number().optional()}).optional()});var Wo=zod.z.object({text:zod.z.string().min(1)}),jt=zod.z.object({inline_data:zod.z.object({mime_type:zod.z.string().min(1),data:zod.z.string().base64()})}),Bt=zod.z.object({file_data:zod.z.object({mime_type:zod.z.string().min(1),file_uri:zod.z.string().min(1)})}),qt=zod.z.object({function_call:zod.z.object({name:zod.z.string().min(1),args:zod.z.record(zod.z.string().min(1))})}),At=zod.z.object({function_response:zod.z.object({name:zod.z.string().min(1),response:zod.z.record(zod.z.string().min(1))})}),zt=zod.z.object({role:zod.z.enum(["user","model","function"]),parts:zod.z.array(zod.z.union([Wo,jt,Bt,qt,At]))}),Yo=zod.z.object({parts:zod.z.array(Wo)}),Ht=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),parameters:zod.z.any()}),Vo=zod.z.object({function_calling_config:zod.z.object({mode:zod.z.enum(["ANY","AUTO","NONE"]),allowed_function_names:zod.z.array(zod.z.string()).optional()})}),Jo=zod.z.object({stopSequences:zod.z.array(zod.z.string()).optional(),maxOutputTokens:zod.z.number().optional(),temperature:zod.z.number().optional(),topP:zod.z.number().optional(),topK:zod.z.number().optional(),presencePenalty:zod.z.number().optional(),frequencyPenalty:zod.z.number().optional(),seed:zod.z.number().optional()}),Xo=zod.z.object({category:zod.z.enum(["HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT","HARM_CATEGORY_CIVIC_INTEGRITY"]),threshold:zod.z.enum(["HARM_BLOCK_THRESHOLD_UNSPECIFIED","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH","BLOCK_NONE","OFF"])}),Zo=zod.z.object({model:zod.z.string().min(1).optional(),contents:zod.z.array(zt),systemInstruction:Yo.optional(),system_instruction:Yo.optional(),generationConfig:Jo.optional(),generation_config:Jo.optional(),safetySettings:zod.z.array(Xo).optional(),safety_settings:zod.z.array(Xo).optional(),tools:zod.z.object({function_declarations:zod.z.array(Ht)}).optional(),toolConfig:Vo.optional(),tool_config:Vo.optional()});var T=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),y=class{constructor(e,t){this.version="v1";var i;let o=T.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash((i=o.baseUrl)!=null?i:$.baseUrl),this.completeChatUrl=provider.urlWithoutTrailingSlash(o.completeChatUrl||`${this.baseUrl}/models/${this.modelName}:generateContent?key=${this.apiKey}`),this.streamChatUrl=provider.urlWithoutTrailingSlash(o.streamChatUrl||`${this.baseUrl}/models/${this.modelName}:streamGenerateContent?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.reduce((t,o)=>t+o.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformPdfMessages(e){return S(this,null,function*(){let t=n=>S(this,null,function*(){let a={};provider.isRunningInBrowser()||(a["User-Agent"]="Mozilla/5.0 (compatible; GoogleFilesAPI/1.0)");let s=yield fetch(n,{headers:a});if(!s.ok)throw new provider.InvalidMessagesError({info:`Failed to download PDF from URL: ${n}`,cause:new Error(`HTTP ${s.status}: ${s.statusText}`)});let d=yield s.arrayBuffer();return new Uint8Array(d)}),o=n=>S(this,null,function*(){try{let a=yield fetch(`https://generativelanguage.googleapis.com/v1beta/files?key=${this.apiKey}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok)return null;let g=((yield a.json()).files||[]).find(C=>C.displayName===n);return g?g.uri:null}catch(a){return null}}),i=(n,a)=>S(this,null,function*(){let s=yield fetch(`https://generativelanguage.googleapis.com/upload/v1beta/files?key=${this.apiKey}`,{method:"POST",headers:{"X-Goog-Upload-Protocol":"resumable","X-Goog-Upload-Command":"start","X-Goog-Upload-Header-Content-Length":n.length.toString(),"X-Goog-Upload-Header-Content-Type":"application/pdf","Content-Type":"application/json"},body:JSON.stringify({file:{display_name:a}})});if(!s.ok)throw new provider.InvalidMessagesError({info:"Failed to start PDF upload to Google Files API",cause:new Error(`HTTP ${s.status}: ${s.statusText}`)});let d=s.headers.get("x-goog-upload-url");if(!d)throw new provider.InvalidMessagesError({info:"No upload URL received from Google Files API",cause:new Error("Missing x-goog-upload-url header")});let g={"X-Goog-Upload-Offset":"0","X-Goog-Upload-Command":"upload, finalize"};provider.isRunningInBrowser()||(g["Content-Length"]=n.length.toString());let C=yield fetch(d,{method:"POST",headers:g,body:n});if(!C.ok)throw new provider.InvalidMessagesError({info:"Failed to upload PDF content to Google Files API",cause:new Error(`HTTP ${C.status}: ${C.statusText}`)});return (yield C.json()).file.uri}),l=n=>S(this,null,function*(){let a=yield o(n.providerCacheKey);if(a)return a;let s;if(n.value.type==="url")s=yield t(n.value.url);else {let d=n.value.base64,g="data:application/pdf;base64,";d=d.startsWith(g)?d.substring(g.length):d,s=provider.convertBase64ToUint8Array(d);}return yield i(s,n.providerCacheKey)}),m=[];for(let n of e){let a=[];for(let s of n.content)if(s.modality===types.PdfModalityLiteral){let d=yield l(s);a.push(N(P({},s),{value:{type:"url",url:d}}));}else a.push(s);m.push(N(P({},n),{content:a}));}return m})}transformModelRequest(e){let t=Zo.safeParse(e);if(!t.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,i=o.model;if(o.system_instruction&&o.systemInstruction)throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'system_instruction' and 'systemInstruction' are not allowed at the same time")});if(o.generation_config&&o.generationConfig)throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'generation_config' and 'generationConfig' are not allowed at the same time")});if(o.tool_config&&o.toolConfig)throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tool_config' and 'toolConfig' are not allowed at the same time")});let l=o.system_instruction||o.systemInstruction,m=o.generation_config||o.generationConfig,n=o.safety_settings||o.safetySettings,a=o.tool_config||o.toolConfig;if(a&&(!o.tools||o.tools.function_declarations.length===0))throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let s={};a&&(a.function_calling_config.mode==="ANY"&&a.function_calling_config.allowed_function_names&&a.function_calling_config.allowed_function_names.length===1?s.toolChoice=a.function_calling_config.allowed_function_names[0]:s.toolChoice=a.function_calling_config.mode.toLowerCase()),s.seed=m==null?void 0:m.seed,s.maxTokens=m==null?void 0:m.maxOutputTokens,s.temperature=m==null?void 0:m.temperature,s.topP=m==null?void 0:m.topP,s.presencePenalty=m==null?void 0:m.presencePenalty,s.frequencyPenalty=m==null?void 0:m.frequencyPenalty,s.stop=m==null?void 0:m.stopSequences,s.safetySettings=n;let d=types.Config().parse(provider.removeUndefinedEntries(s)),g=[];l&&l.parts.forEach(f=>{g.push({role:types.SystemRoleLiteral,content:[{modality:types.TextModalityLiteral,value:f.text}]});}),o.contents.forEach(f=>{let w=f.role;switch(w){case"user":{let k=f.parts.map(E=>"text"in E?{modality:types.TextModalityLiteral,value:E.text}:{modality:types.ImageModalityLiteral,detail:"auto",value:{type:types.Base64ImageContentTypeLiteral,base64:E.inline_data.data,mediaType:E.inline_data.mime_type.split("/")[1]}});g.push({role:w,content:k});}break;case"model":{let k=f.parts.map((E,F)=>"text"in E?{modality:types.TextModalityLiteral,value:E.text}:{modality:types.ToolCallModalityLiteral,id:F.toString(),index:F,name:E.function_call.name,arguments:JSON.stringify(E.function_call.args)});g.push({role:types.AssistantRoleLiteral,content:k});}break;case"function":{let k=f.parts.map((E,F)=>({modality:types.ToolResponseModalityLiteral,id:F.toString(),index:F,name:E.function_response.name,data:JSON.stringify(E.function_response.response)}));g.push({role:types.ToolRoleLiteral,content:k});}break;default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${f.role}' is not supported for model : ${this.modelName}`)})}});let C=[];return o.tools&&o.tools.function_declarations.forEach(f=>{C.push({type:"function",definition:{schema:{name:f.name,description:f.description,parameters:f.parameters}}});}),{modelName:i,config:d,messages:g,tools:C.length>0?C:void 0}}transformConfig(e,t,o){let i=e.toolChoice;delete e.toolChoice;let l=this.modelSchema.config.schema.safeParse(e);if(!l.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:l.error});let m=l.data;Object.keys(m).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
10
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let n=Object.keys(m).reduce((d,g)=>{let C=this.modelSchema.config.def[g],f=C.param,w=m[g];return g==="reasoningEnabled"?d.thinkingConfig={includeThoughts:w}:g==="maxReasoningTokens"?d.thinkingConfig=d.thinkingConfig&&typeof d.thinkingConfig=="object"?N(P({},d.thinkingConfig),{thinkingBudget:w}):{thinkingBudget:w}:f==="maxOutputTokens"&&C.type==="range"&&w===0?d[f]=C.max:d[f]=w,d},{}),a=n.safetySettings;delete n.safetySettings;let s;if(i!==void 0){let d=i;if(!o||o&&o.length===0)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let g=this.modelSchema.config.def.toolChoice;if(g.choices.includes(d))d==="any"?s={function_calling_config:{mode:"ANY",allowed_function_names:o.map(C=>C.definition.schema.name)}}:s={function_calling_config:{mode:d.toUpperCase()}};else if(o.map(C=>C.definition.schema.name).includes(d))s={function_calling_config:{mode:"ANY",allowed_function_names:[d]}};else throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
11
+ one of [${g.choices.join(", ")}]`)})}}if("response_format"in n&&n.response_format!==void 0){let d=n.response_format;if(d==="json_schema"){let g=n.response_schema;if(!("response_schema"in n)||!n.response_schema||!(g!=null&&g.schema))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});n.responseSchema=g.schema,n.responseMimeType="application/json","additionalProperties"in g.schema&&delete n.responseSchema.additionalProperties,delete n.response_format,delete n.response_schema;}else d==="json_object"?(n.responseSchema={type:"object"},delete n.response_format):d==="text"&&delete n.response_format;}return P(P({generation_config:n},s?{tool_config:s}:{}),a?{safety_settings:a}:{})}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let t=n=>{let a=n.match(/^data:(image\/[a-zA-Z]+|application\/pdf);base64,/);return a?n.substring(a[0].length):n},o=e.map(n=>{let a=types.Message().safeParse(n);if(!a.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:a.error});return a.data});o.forEach(n=>{n.content.forEach(a=>{if(!this.modelSchema.modalities.includes(a.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${a.modality}',
12
12
  available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(n=>{if(!Object.keys(this.modelSchema.roles).includes(n.role))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${n.role}',
13
13
  available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let i={parts:[]},l=[];if(o.forEach(n=>{switch(n.role){case types.SystemRoleLiteral:n.content.forEach(a=>{if(a.modality===types.TextModalityLiteral)i.parts.push({text:a.value});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})});break;case types.AssistantRoleLiteral:{let a=[];n.content.forEach(s=>{if(s.modality===types.TextModalityLiteral)a.push({text:s.value});else if(s.modality===types.ToolCallModalityLiteral)a.push({function_call:{name:s.name,args:JSON.parse(s.arguments)}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${s.modality}'`)})}),l.push({role:this.modelSchema.roles[n.role],parts:a});}break;case types.UserRoleLiteral:{let a=[];n.content.forEach(s=>{if(s.modality===types.TextModalityLiteral)a.push({text:s.value});else if(s.modality===types.ImageModalityLiteral){if(s.value.type==="base64"){let d=s.value.base64;d=t(d),a.push({inline_data:{mime_type:`image/${s.value.mediaType}`,data:d}});}else if(s.value.type==="url")throw new provider.InvalidMessagesError({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${s.value.type}'`)})}else if(s.modality===types.PdfModalityLiteral)if(s.value.type==="base64"){let d=s.value.base64;d=t(d),a.push({inline_data:{mime_type:"application/pdf",data:d}});}else s.value.type==="url"&&a.push({file_data:{mime_type:"application/pdf",file_uri:s.value.url}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${s.modality}'`)})}),l.push({role:this.modelSchema.roles[n.role],parts:a});}break;case types.ToolRoleLiteral:{let a=[];n.content.forEach(s=>{if(s.modality===types.ToolResponseModalityLiteral)a.push({function_response:{name:s.name,response:JSON.parse(s.data)}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${s.modality}'`)})}),l.push({role:this.modelSchema.roles[n.role],parts:a});}break;default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' is not supported,
14
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),l[0].role!==this.modelSchema.roles[types.UserRoleLiteral])throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=n=>n===this.modelSchema.roles[types.UserRoleLiteral]||n===this.modelSchema.roles[types.ToolRoleLiteral]?[this.modelSchema.roles[types.AssistantRoleLiteral]]:[this.modelSchema.roles[types.UserRoleLiteral],this.modelSchema.roles[types.ToolRoleLiteral]];for(let n=1;n<l.length;n++)if(!m(l[n-1].role).includes(l[n].role))throw new provider.InvalidMessagesError({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${l[n].role}' after message with role : '${l[n-1].role}'`)});if(l[l.length-1].role!==this.modelSchema.roles[types.UserRoleLiteral]&&l[l.length-1].role!==this.modelSchema.roles[types.ToolRoleLiteral])throw new provider.InvalidMessagesError({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return _({contents:l},i.parts.length>0?{system_instruction:i}:{})}transformTools(e){if(!this.modelSchema.modalities.includes(types.ToolCallModalityLiteral))throw new provider.InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${types.ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:[{function_declarations:e.map(i=>{let l=types.Tool().safeParse(i);if(!l.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:l.error});return l.data}).map(i=>({name:i.definition.schema.name,description:i.definition.schema.description,parameters:i.definition.schema.parameters}))}]}}getCompleteChatUrl(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getCompleteChatData(e,t,o){return S(this,null,function*(){let i=this.transformConfig(e,t,o),l=yield this.transformPdfMessages(t),m=this.transformMessages(l);if(m.messages&&m.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let n=o?this.transformTools(o):{};return _(_(_(_({},this.getDefaultParams()),i),m),n)})}transformCompleteChatResponse(e){let t=Ko.safeParse(e);if(t.success){if(t.data.candidates.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(t.data)}`)});let o=t.data,i=[],l,m=o.candidates[0].content;if(m){let s=m.parts.map((d,g)=>{if("text"in d&&d.text!==void 0)return types.createTextContent(d.text);if("functionCall"in d&&d.functionCall!==void 0)return types.createToolCallContent(g,`${d.functionCall.name}_${g}`,d.functionCall.name,JSON.stringify(d.functionCall.args))});return i.push({role:types.AssistantRoleLiteral,content:s}),o.usageMetadata&&(l={promptTokens:o.usageMetadata.promptTokenCount,totalTokens:o.usageMetadata.totalTokenCount,completionTokens:o.usageMetadata.candidatesTokenCount||0}),{messages:i,usage:l,logProbs:void 0}}let n=o.candidates[0].safetyRatings;if(n&&n.length>0&&n.forEach(s=>{if(s.blocked)throw new provider.ModelResponseError({info:`Blocked content for category: ${s.category} with probability: ${s.probability}`,cause:new Error(`Blocked content for category: ${s.category} with probability: ${s.probability}`)})}),o.candidates[0].finishReason==="SAFETY")throw new provider.ModelResponseError({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new provider.ModelResponseError({info:"Invalid response from model",cause:t.error})}getStreamChatUrl(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getStreamChatData(e,t,o){return S(this,null,function*(){let i=this.transformConfig(e,t,o),l=yield this.transformPdfMessages(t),m=this.transformMessages(l);if(m.messages&&m.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let n=o?this.transformTools(o):{};return _(_(_(_({},this.getDefaultParams()),i),m),n)})}transformStreamChatResponseChunk(e,t){return je(this,null,function*(){let o=(t+e).split(",\r").filter(i=>i.trim()!=="");for(let i of o){let l=i;if(l=l.replace(/\n/g,""),l.startsWith("[")||l.startsWith(",{"))l=l.slice(1);else if(l.endsWith("]")){if(l==="]")return;l=l.slice(0,-1);}let m;try{m=JSON.parse(l);}catch(a){if(a instanceof SyntaxError){t=l;continue}else throw a}t="";let n=ho.safeParse(m);if(n.success){let a={partialMessages:[]},s=n.data;if(s.candidates.length>0){let d=s.candidates[0].content;d&&"parts"in d&&d.parts.length>0&&d.parts.forEach((g,C)=>{if("text"in g&&g.text!==void 0&&a.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,g.text)),"functionCall"in g&&g.functionCall!==void 0){let f=g.functionCall;a.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,C,`${f.name}_${C}`,f.name,JSON.stringify(f.args)));}});}s.usageMetadata&&(a.usage={promptTokens:s.usageMetadata.promptTokenCount,completionTokens:s.usageMetadata.candidatesTokenCount,totalTokens:s.usageMetadata.totalTokenCount}),yield {partialResponse:a,buffer:t};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:n.error})}yield {partialResponse:{partialMessages:[]},buffer:t};})}transformProxyStreamChatResponseChunk(e,t,o,i,l){return je(this,null,function*(){if((l==null?void 0:l.alt)!=="sse"){yield*bo(this.transformStreamChatResponseChunk(e,t));return}let m=t+e,n=[],a="",s=0;for(;s<m.length;){let d=m.indexOf(`
15
- `,s);if(d===-1){a=m.substring(s);break}else {let g=m.substring(s,d).trim();g&&n.push(g),s=d+1;}}for(let d of n){if(d==="data: [DONE]")return;if(d.startsWith("data: ")){let g=d.substring(6);try{let C=JSON.parse(g),f=ho.safeParse(C);if(f.success){let w={partialMessages:[]},x=f.data;if(x.candidates.length>0){let k=x.candidates[0].content;k&&"parts"in k&&k.parts.length>0&&k.parts.forEach((R,F)=>{if("text"in R&&R.text!==void 0&&w.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,R.text)),"functionCall"in R&&R.functionCall!==void 0){let $e=R.functionCall;w.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,F,`${$e.name}_${F}`,$e.name,JSON.stringify($e.args)));}});}x.usageMetadata&&x.usageMetadata.totalTokenCount&&x.usageMetadata.promptTokenCount&&x.usageMetadata.candidatesTokenCount&&(w.usage={promptTokens:x.usageMetadata.promptTokenCount,completionTokens:x.usageMetadata.candidatesTokenCount,totalTokens:x.usageMetadata.totalTokenCount}),yield {partialResponse:w,buffer:t};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:f.error})}catch(C){throw new provider.ModelResponseError({info:`Malformed JSON received in stream: ${g}`,cause:C})}}}yield {partialResponse:{partialMessages:[]},buffer:a};})}getProxyCompleteChatUrl(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyStreamChatUrl(e,t,o){return S(this,null,function*(){return new Promise(i=>{if(!o||Object.keys(o).length===0){i(this.streamChatUrl);return}let l=new URL(this.streamChatUrl);Object.entries(o).forEach(([m,n])=>{n!=null&&l.searchParams.set(m,n);}),i(l.toString());})})}getProxyCompleteChatHeaders(e,t,o){return S(this,null,function*(){if(!t)return {};let i=_({},t);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(e,t,o){return S(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,o)})}getModelPricing(){if(!(this.modelName in u))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return u[this.modelName]}};var ie="gemini-1.5-flash-001",Qt="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Je=provider.ChatModelSchema(M,P).parse({name:ie,description:Qt,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[ie]}),xo=T,se=class extends y{constructor(e){super(Je,e);}};var ae="gemini-1.5-flash-002",on="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Xe=provider.ChatModelSchema(M,P).parse({name:ae,description:on,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[ae]}),ko=T,re=class extends y{constructor(e){super(Xe,e);}};var le="gemini-1.5-flash-latest",nn="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",We=provider.ChatModelSchema(M,P).parse({name:le,description:nn,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[le]}),vo=T,me=class extends y{constructor(e){super(We,e);}};var de="gemini-1.5-flash",an="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Ze=provider.ChatModelSchema(M,P).parse({name:de,description:an,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[de]}),Fo=T,pe=class extends y{constructor(e){super(Ze,e);}};var ce="gemini-1.5-pro-001",ln="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Qe=provider.ChatModelSchema(M,P).parse({name:ce,description:ln,maxInputTokens:2e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[ce]}),No=T,ge=class extends y{constructor(e){super(Qe,e);}};var he="gemini-1.5-pro-002",dn="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",eo=provider.ChatModelSchema(M,P).parse({name:he,description:dn,maxInputTokens:2e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[he]}),Io=T,fe=class extends y{constructor(e){super(eo,e);}};var ue="gemini-1.5-pro-latest",cn="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",oo=provider.ChatModelSchema(M,P).parse({name:ue,description:cn,maxInputTokens:2e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[ue]}),Do=T,ye=class extends y{constructor(e){super(oo,e);}};var Ce="gemini-1.5-pro",hn="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",to=provider.ChatModelSchema(M,P).parse({name:Ce,description:hn,maxInputTokens:2e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[Ce]}),Lo=T,Te=class extends y{constructor(e){super(to,e);}};var Me="gemini-2.0-flash-exp",un="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",no=provider.ChatModelSchema(M,P).parse({name:Me,description:un,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[Me]}),Uo=T,be=class extends y{constructor(e){super(no,e);}};var Ge="gemini-2.5-flash-preview-04-17",Cn="Google's best model in Gemini 2.5 family in terms of price-performance, offering well-rounded capabilities.",io=provider.ChatModelSchema(M,P).parse({name:Ge,description:Cn,maxInputTokens:1048576,maxOutputTokens:65536,roles:b,modalities:G,config:{def:h.responseSchema(2,1,65536,4,.95).def,schema:h.responseSchema(2,1,65536,4,.95).schema},price:u[Ge]}),$o=T,Pe=class extends y{constructor(e){super(io,e);}};var _e="gemini-2.5-pro-preview-03-25",Mn="Google's preview model in Gemini 2.5 family for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",so=provider.ChatModelSchema(M,P).parse({name:_e,description:Mn,maxInputTokens:1048576,maxOutputTokens:65536,roles:b,modalities:G,config:{def:h.reasoning(2,1,65536,4,.95).def,schema:h.reasoning(2,1,65536,4,.95).schema},price:u[_e]}),jo=T,Se=class extends y{constructor(e){super(so,e);}};var Ee="gemini-2.5-flash",Gn="Google's Gemini 2.5 Flash model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",ao=provider.ChatModelSchema(M,P).parse({name:Ee,description:Gn,maxInputTokens:1048576,maxOutputTokens:65536,roles:b,modalities:G,config:{def:h.responseSchema(2,1,65536,4,.95).def,schema:h.responseSchema(2,1,65536,4,.95).schema},price:u[Ee]}),Bo=T,Re=class extends y{constructor(e){super(ao,e);}};var Oe="gemini-2.5-pro",_n="Google's Gemini 2.5 Pro model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",ro=provider.ChatModelSchema(M,P).parse({name:Oe,description:_n,maxInputTokens:1048576,maxOutputTokens:65536,roles:b,modalities:G,config:{def:h.reasoning(2,1,65536,4,.95).def,schema:h.reasoning(2,1,65536,4,.95).schema},price:u[Oe]}),qo=T,we=class extends y{constructor(e){super(ro,e);}};var Le=[types.EmbeddingTextModalityLiteral],Ue=zod.z.enum([types.EmbeddingTextModalityLiteral]);var rt=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))});var En=zod.z.object({model:zod.z.string().min(1),content:zod.z.object({parts:zod.z.array(zod.z.object({text:zod.z.string().min(1)})).min(1)})}),lt=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(En).min(1),outputDimensionality:zod.z.number().int().min(1).optional()});var X=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),z=class{constructor(e,t){this.version="v1";let o=X.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(o.baseUrl||$.baseUrl),this.getEmbeddingsUrl=provider.urlWithoutTrailingSlash(o.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((t,o)=>t+o.length,0)}transformModelRequest(e){let t=lt.safeParse(e);if(!t.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,i=o.model,l={outputDimensionality:o.outputDimensionality},m=types.Config().parse(provider.removeUndefinedEntries(l)),n={modality:types.EmbeddingTextModalityLiteral,requests:o.requests.reduce((a,s)=>(a.push(...s.content.parts.map(d=>d.text)),a),[])};return {modelName:i,config:m,embeddingRequests:n}}transformConfig(e,t){let o=this.modelSchema.config.schema.safeParse(e);if(!o.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let i=o.data;return Object.keys(i).forEach(m=>{if(!this.modelSchema.config.def[m])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${m}',
16
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((m,n)=>{let s=this.modelSchema.config.def[n].param,d=i[n];return m[s]=d,m},{})}transformEmbeddingRequests(e){let t=types.EmbeddingRequests().safeParse(e);if(!t.success)throw new provider.InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:t.error});if(e.modality!==types.EmbeddingTextModalityLiteral)throw new provider.InvalidEmbeddingRequestsError({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${types.EmbeddingTextModalityLiteral}' modality is supported for model : '${this.modelName}'`)});return {requests:t.data.requests.map(i=>({model:`models/${this.modelName}`,content:{parts:[{text:i}]}}))}}getGetEmbeddingsUrl(e,t){return S(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return S(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return S(this,null,function*(){return new Promise(o=>{let i=this.transformConfig(e),l=this.transformEmbeddingRequests(t);if(t.requests.length===0)throw new provider.InvalidEmbeddingRequestsError({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});i.outputDimensionality&&(l.requests.forEach(m=>{m.outputDimensionality=i.outputDimensionality;}),delete i.outputDimensionality),o(_(_(_({},this.getDefaultParams()),i),l));})})}transformGetEmbeddingsResponse(e){let t=rt.safeParse(e);if(t.success){let i=t.data.embeddings.map((l,m)=>({index:m,embedding:l.values}));return {encodingFormat:types.FloatEmbeddingLiteral,embeddings:i}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:t.error})}};var lo="text-embedding-001",Nn="text-embedding-001",mo=provider.EmbeddingModelSchema(Ue).parse({name:lo,description:Nn,modalities:Le,maxInputTokens:2048,maxOutputTokens:768,config:{def:j.base(768).def,schema:j.base(768).schema}}),zo=X,xe=class extends z{constructor(e){super(mo,e);}};var po="text-embedding-004",Dn="text-embedding-004",co=provider.EmbeddingModelSchema(Ue).parse({name:po,description:Dn,modalities:Le,maxInputTokens:2048,maxOutputTokens:768,config:{def:j.base(768).def,schema:j.base(768).schema}}),Ao=X,ke=class extends z{constructor(e){super(co,e);}};
14
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),l[0].role!==this.modelSchema.roles[types.UserRoleLiteral])throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=n=>n===this.modelSchema.roles[types.UserRoleLiteral]||n===this.modelSchema.roles[types.ToolRoleLiteral]?[this.modelSchema.roles[types.AssistantRoleLiteral]]:[this.modelSchema.roles[types.UserRoleLiteral],this.modelSchema.roles[types.ToolRoleLiteral]];for(let n=1;n<l.length;n++)if(!m(l[n-1].role).includes(l[n].role))throw new provider.InvalidMessagesError({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${l[n].role}' after message with role : '${l[n-1].role}'`)});if(l[l.length-1].role!==this.modelSchema.roles[types.UserRoleLiteral]&&l[l.length-1].role!==this.modelSchema.roles[types.ToolRoleLiteral])throw new provider.InvalidMessagesError({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return P({contents:l},i.parts.length>0?{system_instruction:i}:{})}transformTools(e){if(!this.modelSchema.modalities.includes(types.ToolCallModalityLiteral))throw new provider.InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${types.ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:[{function_declarations:e.map(i=>{let l=types.Tool().safeParse(i);if(!l.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:l.error});return l.data}).map(i=>({name:i.definition.schema.name,description:i.definition.schema.description,parameters:i.definition.schema.parameters}))}]}}getCompleteChatUrl(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getCompleteChatData(e,t,o){return S(this,null,function*(){let i=this.transformConfig(e,t,o),l=yield this.transformPdfMessages(t),m=this.transformMessages(l);if(m.messages&&m.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let n=o?this.transformTools(o):{};return P(P(P(P({},this.getDefaultParams()),i),m),n)})}transformCompleteChatResponse(e){let t=Ko.safeParse(e);if(t.success){if(t.data.candidates.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(t.data)}`)});let o=t.data,i=[],l,m=o.candidates[0].content;if(m){let s=m.parts.map((d,g)=>{if("text"in d&&d.text!==void 0)return types.createTextContent(d.text);if("functionCall"in d&&d.functionCall!==void 0)return types.createToolCallContent(g,`${d.functionCall.name}_${g}`,d.functionCall.name,JSON.stringify(d.functionCall.args))});return i.push({role:types.AssistantRoleLiteral,content:s}),o.usageMetadata&&(l={promptTokens:o.usageMetadata.promptTokenCount,totalTokens:o.usageMetadata.totalTokenCount,completionTokens:o.usageMetadata.candidatesTokenCount||0}),{messages:i,usage:l,logProbs:void 0}}let n=o.candidates[0].safetyRatings;if(n&&n.length>0&&n.forEach(s=>{if(s.blocked)throw new provider.ModelResponseError({info:`Blocked content for category: ${s.category} with probability: ${s.probability}`,cause:new Error(`Blocked content for category: ${s.category} with probability: ${s.probability}`)})}),o.candidates[0].finishReason==="SAFETY")throw new provider.ModelResponseError({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new provider.ModelResponseError({info:"Invalid response from model",cause:t.error})}getStreamChatUrl(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getStreamChatData(e,t,o){return S(this,null,function*(){let i=this.transformConfig(e,t,o),l=yield this.transformPdfMessages(t),m=this.transformMessages(l);if(m.messages&&m.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let n=o?this.transformTools(o):{};return P(P(P(P({},this.getDefaultParams()),i),m),n)})}transformStreamChatResponseChunk(e,t){return je(this,null,function*(){let o=(t+e).split(",\r").filter(i=>i.trim()!=="");for(let i of o){let l=i;if(l=l.replace(/\n/g,""),l.startsWith("[")||l.startsWith(",{"))l=l.slice(1);else if(l.endsWith("]")){if(l==="]")return;l=l.slice(0,-1);}let m;try{m=JSON.parse(l);}catch(a){if(a instanceof SyntaxError){t=l;continue}else throw a}t="";let n=ho.safeParse(m);if(n.success){let a={partialMessages:[]},s=n.data;if(s.candidates.length>0){let d=s.candidates[0].content;d&&"parts"in d&&d.parts.length>0&&d.parts.forEach((g,C)=>{if("text"in g&&g.text!==void 0&&a.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,g.text)),"functionCall"in g&&g.functionCall!==void 0){let f=g.functionCall;a.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,C,`${f.name}_${C}`,f.name,JSON.stringify(f.args)));}});}s.usageMetadata&&(a.usage={promptTokens:s.usageMetadata.promptTokenCount,completionTokens:s.usageMetadata.candidatesTokenCount,totalTokens:s.usageMetadata.totalTokenCount}),yield {partialResponse:a,buffer:t};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:n.error})}yield {partialResponse:{partialMessages:[]},buffer:t};})}transformProxyStreamChatResponseChunk(e,t,o,i,l){return je(this,null,function*(){if((l==null?void 0:l.alt)!=="sse"){yield*bo(this.transformStreamChatResponseChunk(e,t));return}let m=t+e,n=[],a="",s=0;for(;s<m.length;){let d=m.indexOf(`
15
+ `,s);if(d===-1){a=m.substring(s);break}else {let g=m.substring(s,d).trim();g&&n.push(g),s=d+1;}}for(let d of n){if(d==="data: [DONE]")return;if(d.startsWith("data: ")){let g=d.substring(6);try{let C=JSON.parse(g),f=ho.safeParse(C);if(f.success){let w={partialMessages:[]},x=f.data;if(x.candidates.length>0){let k=x.candidates[0].content;k&&"parts"in k&&k.parts.length>0&&k.parts.forEach((E,F)=>{if("text"in E&&E.text!==void 0&&w.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,E.text)),"functionCall"in E&&E.functionCall!==void 0){let $e=E.functionCall;w.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,F,`${$e.name}_${F}`,$e.name,JSON.stringify($e.args)));}});}x.usageMetadata&&x.usageMetadata.totalTokenCount&&x.usageMetadata.promptTokenCount&&x.usageMetadata.candidatesTokenCount&&(w.usage={promptTokens:x.usageMetadata.promptTokenCount,completionTokens:x.usageMetadata.candidatesTokenCount,totalTokens:x.usageMetadata.totalTokenCount}),yield {partialResponse:w,buffer:t};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:f.error})}catch(C){throw new provider.ModelResponseError({info:`Malformed JSON received in stream: ${g}`,cause:C})}}}yield {partialResponse:{partialMessages:[]},buffer:a};})}getProxyCompleteChatUrl(e,t,o){return S(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyStreamChatUrl(e,t,o){return S(this,null,function*(){return new Promise(i=>{if(!o||Object.keys(o).length===0){i(this.streamChatUrl);return}let l=new URL(this.streamChatUrl);Object.entries(o).forEach(([m,n])=>{n!=null&&l.searchParams.set(m,n);}),i(l.toString());})})}getProxyCompleteChatHeaders(e,t,o){return S(this,null,function*(){if(!t)return {};let i=P({},t);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(e,t,o){return S(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,o)})}getModelPricing(){if(!(this.modelName in u))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return u[this.modelName]}};var ie="gemini-1.5-flash-001",on="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Je=provider.ChatModelSchema(M,_).parse({name:ie,description:on,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[ie]}),xo=T,se=class extends y{constructor(e){super(Je,e);}};var ae="gemini-1.5-flash-002",nn="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Xe=provider.ChatModelSchema(M,_).parse({name:ae,description:nn,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[ae]}),ko=T,re=class extends y{constructor(e){super(Xe,e);}};var le="gemini-1.5-flash-latest",an="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",We=provider.ChatModelSchema(M,_).parse({name:le,description:an,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[le]}),vo=T,me=class extends y{constructor(e){super(We,e);}};var de="gemini-1.5-flash",ln="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Ze=provider.ChatModelSchema(M,_).parse({name:de,description:ln,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[de]}),Fo=T,pe=class extends y{constructor(e){super(Ze,e);}};var ce="gemini-1.5-pro-001",dn="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Qe=provider.ChatModelSchema(M,_).parse({name:ce,description:dn,maxInputTokens:2e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[ce]}),No=T,ge=class extends y{constructor(e){super(Qe,e);}};var he="gemini-1.5-pro-002",cn="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",eo=provider.ChatModelSchema(M,_).parse({name:he,description:cn,maxInputTokens:2e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[he]}),Io=T,fe=class extends y{constructor(e){super(eo,e);}};var ue="gemini-1.5-pro-latest",hn="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",oo=provider.ChatModelSchema(M,_).parse({name:ue,description:hn,maxInputTokens:2e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[ue]}),Do=T,ye=class extends y{constructor(e){super(oo,e);}};var Ce="gemini-1.5-pro",un="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",to=provider.ChatModelSchema(M,_).parse({name:Ce,description:un,maxInputTokens:2e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[Ce]}),Lo=T,Te=class extends y{constructor(e){super(to,e);}};var Me="gemini-2.0-flash-exp",Cn="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",no=provider.ChatModelSchema(M,_).parse({name:Me,description:Cn,maxInputTokens:1e6,maxOutputTokens:8192,roles:b,modalities:G,config:{def:h.responseSchema(2,1,8192,4,.95).def,schema:h.responseSchema(2,1,8192,4,.95).schema},price:u[Me]}),Uo=T,be=class extends y{constructor(e){super(no,e);}};var Ge="gemini-2.5-flash-preview-04-17",Mn="Google's best model in Gemini 2.5 family in terms of price-performance, offering well-rounded capabilities.",io=provider.ChatModelSchema(M,_).parse({name:Ge,description:Mn,maxInputTokens:1048576,maxOutputTokens:65536,roles:b,modalities:G,config:{def:h.responseSchema(2,1,65536,4,.95).def,schema:h.responseSchema(2,1,65536,4,.95).schema},price:u[Ge]}),$o=T,_e=class extends y{constructor(e){super(io,e);}};var Pe="gemini-2.5-pro-preview-03-25",Gn="Google's preview model in Gemini 2.5 family for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",so=provider.ChatModelSchema(M,_).parse({name:Pe,description:Gn,maxInputTokens:1048576,maxOutputTokens:65536,roles:b,modalities:G,config:{def:h.reasoning(2,1,65536,4,.95).def,schema:h.reasoning(2,1,65536,4,.95).schema},price:u[Pe]}),jo=T,Se=class extends y{constructor(e){super(so,e);}};var Ee="gemini-2.5-flash",Pn="Google's Gemini 2.5 Flash model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",ao=provider.ChatModelSchema(M,_).parse({name:Ee,description:Pn,maxInputTokens:1048576,maxOutputTokens:65536,roles:b,modalities:G,config:{def:h.responseSchema(2,1,65536,4,.95).def,schema:h.responseSchema(2,1,65536,4,.95).schema},price:u[Ee]}),Bo=T,Re=class extends y{constructor(e){super(ao,e);}};var Oe="gemini-2.5-pro",En="Google's Gemini 2.5 Pro model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",ro=provider.ChatModelSchema(M,_).parse({name:Oe,description:En,maxInputTokens:1048576,maxOutputTokens:65536,roles:b,modalities:G,config:{def:h.reasoning(2,1,65536,4,.95).def,schema:h.reasoning(2,1,65536,4,.95).schema},price:u[Oe]}),qo=T,we=class extends y{constructor(e){super(ro,e);}};var Le=[types.EmbeddingTextModalityLiteral],Ue=zod.z.enum([types.EmbeddingTextModalityLiteral]);var lt=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))});var On=zod.z.object({model:zod.z.string().min(1),content:zod.z.object({parts:zod.z.array(zod.z.object({text:zod.z.string().min(1)})).min(1)})}),mt=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(On).min(1),outputDimensionality:zod.z.number().int().min(1).optional()});var X=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),A=class{constructor(e,t){this.version="v1";let o=X.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(o.baseUrl||$.baseUrl),this.getEmbeddingsUrl=provider.urlWithoutTrailingSlash(o.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((t,o)=>t+o.length,0)}transformModelRequest(e){let t=mt.safeParse(e);if(!t.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,i=o.model,l={outputDimensionality:o.outputDimensionality},m=types.Config().parse(provider.removeUndefinedEntries(l)),n={modality:types.EmbeddingTextModalityLiteral,requests:o.requests.reduce((a,s)=>(a.push(...s.content.parts.map(d=>d.text)),a),[])};return {modelName:i,config:m,embeddingRequests:n}}transformConfig(e,t){let o=this.modelSchema.config.schema.safeParse(e);if(!o.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let i=o.data;return Object.keys(i).forEach(m=>{if(!this.modelSchema.config.def[m])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${m}',
16
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((m,n)=>{let s=this.modelSchema.config.def[n].param,d=i[n];return m[s]=d,m},{})}transformEmbeddingRequests(e){let t=types.EmbeddingRequests().safeParse(e);if(!t.success)throw new provider.InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:t.error});if(e.modality!==types.EmbeddingTextModalityLiteral)throw new provider.InvalidEmbeddingRequestsError({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${types.EmbeddingTextModalityLiteral}' modality is supported for model : '${this.modelName}'`)});return {requests:t.data.requests.map(i=>({model:`models/${this.modelName}`,content:{parts:[{text:i}]}}))}}getGetEmbeddingsUrl(e,t){return S(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return S(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return S(this,null,function*(){return new Promise(o=>{let i=this.transformConfig(e),l=this.transformEmbeddingRequests(t);if(t.requests.length===0)throw new provider.InvalidEmbeddingRequestsError({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});i.outputDimensionality&&(l.requests.forEach(m=>{m.outputDimensionality=i.outputDimensionality;}),delete i.outputDimensionality),o(P(P(P({},this.getDefaultParams()),i),l));})})}transformGetEmbeddingsResponse(e){let t=lt.safeParse(e);if(t.success){let i=t.data.embeddings.map((l,m)=>({index:m,embedding:l.values}));return {encodingFormat:types.FloatEmbeddingLiteral,embeddings:i}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:t.error})}};var lo="text-embedding-001",Dn="text-embedding-001",mo=provider.EmbeddingModelSchema(Ue).parse({name:lo,description:Dn,modalities:Le,maxInputTokens:2048,maxOutputTokens:768,config:{def:j.base(768).def,schema:j.base(768).schema}}),Ao=X,xe=class extends A{constructor(e){super(mo,e);}};var po="text-embedding-004",Un="text-embedding-004",co=provider.EmbeddingModelSchema(Ue).parse({name:po,description:Un,modalities:Le,maxInputTokens:2048,maxOutputTokens:768,config:{def:j.base(768).def,schema:j.base(768).schema}}),zo=X,ke=class extends A{constructor(e){super(co,e);}};
17
17
 
18
18
  exports.BaseChatModel = y;
19
19
  exports.BaseChatModelOptions = T;
20
- exports.BaseEmbeddingModel = z;
20
+ exports.BaseEmbeddingModel = A;
21
21
  exports.BaseEmbeddingModelOptions = X;
22
22
  exports.ChatModelBaseConfigDef = ee;
23
23
  exports.ChatModelBaseConfigSchema = Q;
24
24
  exports.ChatModelReasoningConfigDef = So;
25
- exports.ChatModelReasoningConfigSchema = _o;
25
+ exports.ChatModelReasoningConfigSchema = Po;
26
26
  exports.EmbeddingModelBaseConfigDef = Oo;
27
27
  exports.EmbeddingModelBaseConfigSchema = Ro;
28
28
  exports.Gemini1_5Flash = pe;
@@ -64,7 +64,7 @@ exports.Gemini2_0FlashExpSchema = no;
64
64
  exports.Gemini2_5Flash = Re;
65
65
  exports.Gemini2_5FlashLiteral = Ee;
66
66
  exports.Gemini2_5FlashOptions = Bo;
67
- exports.Gemini2_5FlashPreview0417 = Pe;
67
+ exports.Gemini2_5FlashPreview0417 = _e;
68
68
  exports.Gemini2_5FlashPreview0417Literal = Ge;
69
69
  exports.Gemini2_5FlashPreview0417Options = $o;
70
70
  exports.Gemini2_5FlashPreview0417Schema = io;
@@ -73,70 +73,70 @@ exports.Gemini2_5Pro = we;
73
73
  exports.Gemini2_5ProLiteral = Oe;
74
74
  exports.Gemini2_5ProOptions = qo;
75
75
  exports.Gemini2_5ProPreview0325 = Se;
76
- exports.Gemini2_5ProPreview0325Literal = _e;
76
+ exports.Gemini2_5ProPreview0325Literal = Pe;
77
77
  exports.Gemini2_5ProPreview0325Options = jo;
78
78
  exports.Gemini2_5ProPreview0325Schema = so;
79
79
  exports.Gemini2_5ProSchema = ro;
80
80
  exports.Google = $;
81
- exports.GoogleChatAssistantRoleLiteral = Ft;
81
+ exports.GoogleChatAssistantRoleLiteral = Nt;
82
82
  exports.GoogleChatContent = zt;
83
- exports.GoogleChatContentPartFileData = jt;
84
- exports.GoogleChatContentPartFunctionCall = Bt;
85
- exports.GoogleChatContentPartFunctionResponse = qt;
86
- exports.GoogleChatContentPartInlineData = $t;
83
+ exports.GoogleChatContentPartFileData = Bt;
84
+ exports.GoogleChatContentPartFunctionCall = qt;
85
+ exports.GoogleChatContentPartFunctionResponse = At;
86
+ exports.GoogleChatContentPartInlineData = jt;
87
87
  exports.GoogleChatContentPartText = Wo;
88
88
  exports.GoogleChatGenerationConfig = Jo;
89
89
  exports.GoogleChatModelConfigs = h;
90
90
  exports.GoogleChatModelModalities = G;
91
- exports.GoogleChatModelModalitiesEnum = P;
91
+ exports.GoogleChatModelModalitiesEnum = _;
92
92
  exports.GoogleChatModelResponseSchemaConfigDef = te;
93
93
  exports.GoogleChatModelResponseSchemaConfigSchema = ne;
94
94
  exports.GoogleChatModelRoles = M;
95
95
  exports.GoogleChatModelRolesMap = b;
96
- exports.GoogleChatModelTextModalities = Si;
97
- exports.GoogleChatModelTextModalitiesEnum = Ei;
98
- exports.GoogleChatModelTextToolModalities = wi;
99
- exports.GoogleChatModelTextToolModalitiesEnum = xi;
100
- exports.GoogleChatModelTextVisionModalities = Ri;
101
- exports.GoogleChatModelTextVisionModalitiesEnum = Oi;
96
+ exports.GoogleChatModelTextModalities = Ri;
97
+ exports.GoogleChatModelTextModalitiesEnum = Oi;
98
+ exports.GoogleChatModelTextToolModalities = ki;
99
+ exports.GoogleChatModelTextToolModalitiesEnum = vi;
100
+ exports.GoogleChatModelTextVisionModalities = wi;
101
+ exports.GoogleChatModelTextVisionModalitiesEnum = xi;
102
102
  exports.GoogleChatRequest = Zo;
103
103
  exports.GoogleChatSafetySettings = Xo;
104
104
  exports.GoogleChatSystemInstruction = Yo;
105
- exports.GoogleChatTool = At;
105
+ exports.GoogleChatTool = Ht;
106
106
  exports.GoogleChatToolConfig = Vo;
107
- exports.GoogleChatToolRoleLiteral = Nt;
107
+ exports.GoogleChatToolRoleLiteral = It;
108
108
  exports.GoogleCompleteChatResponse = Ko;
109
- exports.GoogleCompleteChatTextResponse = It;
110
- exports.GoogleCompleteChatToolResponse = Dt;
109
+ exports.GoogleCompleteChatTextResponse = Dt;
110
+ exports.GoogleCompleteChatToolResponse = Lt;
111
111
  exports.GoogleEmbeddingModelConfigs = j;
112
112
  exports.GoogleEmbeddingModelModalities = Le;
113
113
  exports.GoogleEmbeddingModelModalitiesEnum = Ue;
114
- exports.GoogleEmbeddingRequest = lt;
115
- exports.GoogleEmbeddingRequestInput = En;
116
- exports.GoogleGetEmbeddingsResponse = rt;
114
+ exports.GoogleEmbeddingRequest = mt;
115
+ exports.GoogleEmbeddingRequestInput = On;
116
+ exports.GoogleGetEmbeddingsResponse = lt;
117
117
  exports.GoogleStreamChatResponse = ho;
118
- exports.GoogleStreamChatTextResponse = Lt;
119
- exports.GoogleStreamChatToolResponse = Ut;
120
- exports.ProviderLiteral = Rt;
118
+ exports.GoogleStreamChatTextResponse = Ut;
119
+ exports.GoogleStreamChatToolResponse = $t;
120
+ exports.ProviderLiteral = Ot;
121
121
  exports.Text_Embedding_001 = xe;
122
122
  exports.Text_Embedding_001Literal = lo;
123
- exports.Text_Embedding_001Options = zo;
123
+ exports.Text_Embedding_001Options = Ao;
124
124
  exports.Text_Embedding_001Schema = mo;
125
125
  exports.Text_Embedding_004 = ke;
126
126
  exports.Text_Embedding_004Literal = po;
127
- exports.Text_Embedding_004Options = Ao;
127
+ exports.Text_Embedding_004Options = zo;
128
128
  exports.Text_Embedding_004Schema = co;
129
129
  exports.dimensions = Ve;
130
- exports.frequencyPenalty = Bn;
130
+ exports.frequencyPenalty = An;
131
131
  exports.maxTokens = qe;
132
- exports.presencePenalty = qn;
132
+ exports.presencePenalty = zn;
133
133
  exports.reasoningEnabled = Ye;
134
134
  exports.safetySettings = Ke;
135
- exports.seed = zn;
136
- exports.stop = ze;
135
+ exports.seed = Hn;
136
+ exports.stop = Ae;
137
137
  exports.temperature = Be;
138
138
  exports.toolChoice = He;
139
- exports.topK = jn;
140
- exports.topP = Ae;
139
+ exports.topK = qn;
140
+ exports.topP = ze;
141
141
  //# sourceMappingURL=index.js.map
142
142
  //# sourceMappingURL=index.js.map