@adaline/vertex 1.10.2 → 1.10.3

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
@@ -3,109 +3,109 @@
3
3
  var jose = require('jose');
4
4
  var zod = require('zod');
5
5
 
6
- var zn=Object.defineProperty,Hn=Object.defineProperties;var Vn=Object.getOwnPropertyDescriptors;var Ui=Object.getOwnPropertySymbols;var Kn=Object.prototype.hasOwnProperty,Yn=Object.prototype.propertyIsEnumerable;var mt=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Jn=e=>{throw TypeError(e)};var Di=(e,t,i)=>t in e?zn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,g=(e,t)=>{for(var i in t||(t={}))Kn.call(t,i)&&Di(e,i,t[i]);if(Ui)for(var i of Ui(t))Yn.call(t,i)&&Di(e,i,t[i]);return e},f=(e,t)=>Hn(e,Vn(t));var K=(e,t,i)=>new Promise((n,a)=>{var m=l=>{try{d(i.next(l));}catch(p){a(p);}},r=l=>{try{d(i.throw(l));}catch(p){a(p);}},d=l=>l.done?n(l.value):Promise.resolve(l.value).then(m,r);d((i=i.apply(e,t)).next());}),Wn=function(e,t){this[0]=e,this[1]=t;};var $i=e=>{var t=e[mt("asyncIterator")],i=!1,n,a={};return t==null?(t=e[mt("iterator")](),n=m=>a[m]=r=>t[m](r)):(t=t.call(e),n=m=>a[m]=r=>{if(i){if(i=!1,m==="throw")throw r;return r}return i=!0,{done:!1,value:new Wn(new Promise(d=>{var l=t[m](r);l instanceof Object||Jn("Object expected"),d(l);}),1)}}),a[mt("iterator")]=()=>a,n("next"),"throw"in t?n("throw"):a.throw=m=>{throw m},"return"in t&&n("return"),a};var fe="system",Y="user",B="assistant",ie="tool",Zn=[fe,Y,B,ie],pt=zod.z.enum(Zn),Xn=[B],Qn=zod.z.enum(Xn),oe="image",ut="base64",ea=["png","jpeg","webp","gif"],ta=zod.z.object({type:zod.z.literal(ut),base64:zod.z.string(),mediaType:zod.z.enum(ea)}),ia="url",oa=zod.z.object({type:zod.z.literal(ia),url:zod.z.string()}),na=zod.z.discriminatedUnion("type",[ta,oa]),aa=["low","medium","high","auto"],sa=zod.z.enum(aa),ra=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(oe),detail:sa,value:na,metadata:e}),le="pdf",la="base64",ma=zod.z.object({type:zod.z.literal(la),base64:zod.z.string()}),da="url",ca=zod.z.object({type:zod.z.literal(da),url:zod.z.string()}),pa=zod.z.discriminatedUnion("type",[ma,ca]),ua=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(le),value:pa,file:zod.z.object({name:zod.z.string(),id:zod.z.string(),size:zod.z.number().optional()}),metadata:e}),zi="reasoning",Hi="partial-reasoning",Vi="thinking",ga="redacted",ct=zod.z.object({type:zod.z.literal(Vi),thinking:zod.z.string(),signature:zod.z.string()}),Ki=zod.z.object({type:zod.z.literal(ga),data:zod.z.string()}),ha=zod.z.discriminatedUnion("type",[ct,Ki]),fa=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(zi),value:ha,metadata:e}),ya=zod.z.object({type:zod.z.literal(Vi),thinking:ct.shape.thinking.optional(),signature:ct.shape.signature.optional()}),ba=zod.z.discriminatedUnion("type",[ya,Ki]),Ta=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Hi),value:ba,metadata:e}),U="text",Yi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(U),value:zod.z.string(),metadata:e}),gt="partial-text",Ji=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(gt),value:zod.z.string(),metadata:e}),z="tool-call",Wi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(z),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),serverName:zod.z.string().optional(),metadata:e}),ht="partial-tool-call",Zi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ht),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),serverName:zod.z.string().optional(),metadata:e}),ne="tool-response",Pa=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ne),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:e}),Ma="partial-tool-response",_a=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ma),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),data:zod.z.string().optional(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:e}),ka=[U,oe,le,z,ne,zi],Xi=zod.z.enum(ka),va=(e=zod.z.undefined(),t=zod.z.undefined(),i=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Yi(e),ra(t),ua(i),Wi(n),Pa(a),fa(m)]),xa=[gt,ht,Hi];zod.z.enum(xa);var Sa=(e=zod.z.undefined(),t=zod.z.undefined(),i=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ji(e),Zi(t),Ta(i),_a(n)]);var ft=(e=pt,t=zod.z.undefined(),i=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined(),r=zod.z.undefined(),d=zod.z.undefined())=>zod.z.object({role:e,content:zod.z.array(va(t,i,n,a,r,m)),metadata:d}),yt=(e=Qn,t=zod.z.undefined(),i=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:e,partialContent:Sa(t,i,n,m),metadata:a}),Ea=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Ai=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Ca=Ai.extend({topLogProbs:zod.z.array(Ai)}),Qi=zod.z.array(Ca);zod.z.object({messages:zod.z.array(ft()),usage:Ea.optional(),logProbs:Qi.optional()});var Oa=zod.z.object({promptTokens:zod.z.number().nonnegative().optional(),completionTokens:zod.z.number().nonnegative().optional(),totalTokens:zod.z.number().nonnegative().optional()});zod.z.object({partialMessages:zod.z.array(yt()),usage:Oa.optional(),logProbs:Qi.optional()});var ye=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,wa=zod.z.object({enabled:zod.z.boolean().default(!0),allowedTools:zod.z.array(zod.z.string().min(1))});zod.z.object({type:zod.z.literal("url"),url:zod.z.string().url().refine(e=>e.startsWith("https://"),{message:"MCP server URL must start with https://"}),name:zod.z.string().min(1),toolConfiguration:wa.optional(),authorizationToken:zod.z.string().min(1).optional()});var Ga=["object","array","number","string","boolean","enum"],Bi=zod.z.enum(Ga),Ra=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Bi,zod.z.array(zod.z.union([Bi,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),Fa=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Ra),additionalProperties:zod.z.literal(!1)}),eo=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:Fa}).optional(),D="text",to="token",Ia=[D,to],io=zod.z.enum(Ia),ja=zod.z.array(zod.z.string().min(1)),La=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Me=(e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(D),metadata:e,requests:ja}),zod.z.object({modality:zod.z.literal(to),metadata:e,requests:La})]),be="float",Na=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Ua="base64",Da=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),qi=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(be),embeddings:zod.z.array(Na),usage:qi.optional()}),zod.z.object({encodingFormat:zod.z.literal(Ua),embeddings:zod.z.array(Da),usage:qi.optional()})]);var $a=e=>{let t=new WeakSet;return JSON.stringify(e,(i,n)=>{if(typeof n=="object"&&n!==null){if(t.has(n))return;t.add(n);}return n})},Aa=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:$a(e),dt="GatewayBaseError",X=class oo extends Error{constructor({info:t,cause:i},n){super(`[${n!=null?n:dt}]: ${t}
7
- Message: ${Aa(i)}`),this.name=dt,this.info=t,this.cause=i,this.name=n!=null?n:dt,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof oo}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Ba=zod.z.object({inputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M input tokens"),outputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M output tokens")}).describe("Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier."),qa=zod.z.object({base:Ba.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),za=zod.z.object({minTokens:zod.z.number().int().nonnegative().describe("Inclusive lower token bound for this tier."),maxTokens:zod.z.number().int().nullable().optional().describe("Exclusive upper token bound; `null` means \u221E."),prices:qa.describe("Price categories and rates for this specific token range.")}).refine(e=>e.maxTokens===null||typeof e.maxTokens=="number"&&e.maxTokens>e.minTokens,{message:"maxTokens must be > minTokens (or null for infinite).",path:["maxTokens"]}).describe("A single pricing tier defined by a token range and associated prices.");zod.z.object({modelName:zod.z.string().describe("Model name this schedule applies to."),currency:zod.z.string().default("USD").describe("Currency code (e.g., USD)."),tokenRanges:zod.z.array(za).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((e,t)=>{let{tokenRanges:i}=e;i[0].minTokens!==0&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let a=1;a<i.length;a++){let m=i[a-1],r=i[a];if(m.maxTokens===null){t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",a-1,"maxTokens"],message:"Cannot define any tokenRanges after an infinite tier (maxTokens = null)."});break}r.minTokens!==m.maxTokens&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",a,"minTokens"],message:`Tier ${a} minTokens (${r.minTokens}) must equal previous tier's maxTokens (${m.maxTokens}) for contiguity.`}),r.minTokens<m.minTokens&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",a,"minTokens"],message:`tokenRanges must be sorted by ascending minTokens. Tier ${a} (${r.minTokens}) starts before Tier ${a-1} (${m.minTokens}).`});}let n=i[i.length-1];i.every(a=>a.maxTokens!==null||a===n)&&n.maxTokens!==null&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i.length-1,"maxTokens"],message:"The final tier must have maxTokens = null (representing infinity)."});}).describe("Complete pricing schedule for a single chat model, including all its token-based tiers.");var Ha="function";var Va=zod.z.enum(["object","array","number","string","boolean","null"]),Ka=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Va.optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional()});zod.z.object({type:zod.z.enum(["object"]),title:zod.z.string().optional(),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Ka).optional(),required:zod.z.array(zod.z.string()).optional()});var Ya=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),parameters:zod.z.any(),strict:zod.z.boolean().optional()});var Ja=zod.z.enum(["function"]),Wa=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),Za=zod.z.object({type:zod.z.literal("http"),method:zod.z.enum(["get","post"]),url:zod.z.string().url(),headers:zod.z.record(zod.z.string()).optional(),query:zod.z.record(zod.z.string()).optional(),body:zod.z.record(zod.z.any()).optional(),proxyUrl:zod.z.string().url().optional(),proxyHeaders:zod.z.record(zod.z.string()).optional(),retry:Wa.optional()}),Xa=zod.z.discriminatedUnion("type",[Za]),Qa=zod.z.object({type:Ja,definition:zod.z.object({schema:Ya}),request:Xa.optional()}),es=[Ha];zod.z.enum(es);var no=(e=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Qa.extend({metadata:e})]),ao=e=>Yi().parse({modality:U,value:e}),so=(e,t,i,n,a)=>Wi().parse({modality:z,index:e,id:t,name:i,arguments:n,serverName:a});var bt=(e,t)=>yt().parse({role:e,partialContent:Ji().parse({modality:gt,value:t})}),Tt=(e,t,i,n,a,m)=>yt().parse({role:e,partialContent:Zi().parse({modality:ht,index:t,id:i,name:n,arguments:a,serverName:m})});var ts=Object.defineProperty,ro=Object.getOwnPropertySymbols,is=Object.prototype.hasOwnProperty,os=Object.prototype.propertyIsEnumerable,lo=(e,t,i)=>t in e?ts(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,ce=(e,t)=>{for(var i in t||(t={}))is.call(t,i)&&lo(e,i,t[i]);if(ro)for(var i of ro(t))os.call(t,i)&&lo(e,i,t[i]);return e},mo="ProviderError",pe=class To extends X{constructor({info:t,cause:i}){super({info:t,cause:i},mo),this.name=mo,this.info=t,this.cause=i;}static isProviderError(t){return t instanceof To}},co="ModelError",ue=class Po extends X{constructor({info:t,cause:i}){super({info:t,cause:i},co),this.name=co,this.info=t,this.cause=i;}static isModelError(t){return t instanceof Po}},po="ModelResponseError",$=class Mo extends X{constructor({info:t,cause:i}){super({info:t,cause:i},po),this.name=po,this.cause=i,this.info=t;}static isModelResponseError(t){return t instanceof Mo}},uo="InvalidModelRequestError",Q=class _o extends X{constructor({info:t,cause:i}){super({info:t,cause:i},uo),this.name=uo,this.cause=i,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof _o}},go="InvalidConfigError",H=class ko extends X{constructor({info:t,cause:i}){super({info:t,cause:i},go),this.name=go,this.cause=i,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof ko}},ho="InvalidMessagesError",v=class vo extends X{constructor({info:t,cause:i}){super({info:t,cause:i},ho),this.name=ho,this.cause=i,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof vo}},fo="InvalidToolsError",Pt=class xo extends X{constructor({info:t,cause:i}){super({info:t,cause:i},fo),this.name=fo,this.cause=i,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof xo}},yo="InvalidEmbeddingRequestsError",ae=class So extends X{constructor({info:t,cause:i}){super({info:t,cause:i},yo),this.name=yo,this.info=t,this.cause=i,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof So}},Mt="multi-string",Eo=zod.z.object({type:zod.z.literal(Mt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),ns=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),Co=e=>({def:Eo.parse(ce({type:Mt},e)),schema:ns(e.max)}),_t="object-schema",Oo=zod.z.object({type:zod.z.literal(_t),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),as=e=>e.optional(),wo=e=>({def:Oo.parse(ce({type:_t},e)),schema:as(e.objectSchema)}),kt="paired-select",ss=zod.z.object({value:zod.z.string().min(1),label:zod.z.string().min(1)}),bo=zod.z.object({key:zod.z.string().min(1),label:zod.z.string().min(1),description:zod.z.string().min(1).max(500).optional(),choices:zod.z.array(ss).min(1)}),Go=zod.z.object({type:zod.z.literal(kt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),fields:zod.z.tuple([bo,bo]),uniqueByField:zod.z.string().min(1).optional()}),rs=e=>{let t=e.map(a=>a.value);if(t.length===0)throw new Error("PairedSelectConfigItem fields must define at least one choice");let[i,...n]=t;return zod.z.enum([i,...n])},ls=e=>{let t=e.reduce((i,n)=>(i[n.key]=rs(n.choices),i),{});return zod.z.array(zod.z.object(t)).optional()},Ro=e=>{let t=Go.parse(ce({type:kt},e)),i=new Set(t.fields.map(n=>n.key));if(i.size!==t.fields.length)throw new Error("PairedSelectConfigItem fields must have unique keys");if(t.uniqueByField&&!i.has(t.uniqueByField))throw new Error("uniqueByField must reference one of the defined field keys");return {def:t,schema:ls(t.fields)}},vt="range",Fo=zod.z.object({type:zod.z.literal(vt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),ms=(e,t,i,n)=>zod.z.number().min(e).max(t).step(i).default(n).optional(),J=e=>({def:Fo.parse(ce({type:vt},e)),schema:ms(e.min,e.max,e.step,e.default)}),xt="select-boolean",Io=zod.z.object({type:zod.z.literal(xt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),ds=e=>zod.z.boolean().nullable().default(e).optional(),_e=e=>({def:Io.parse(ce({type:xt},e)),schema:ds(e.default)}),St="select-string",jo=zod.z.object({type:zod.z.literal(St),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string(),choices:zod.z.array(zod.z.string())}),cs=(e,t)=>zod.z.enum(t).nullable().default(e).optional(),Et=e=>({def:jo.parse(ce({type:St},e)),schema:cs(e.default,e.choices)}),ps=[vt,Mt,St,_t,xt,kt];zod.z.enum(ps);var Lo=zod.z.discriminatedUnion("type",[Fo,Eo,jo,Io,Oo,Go]),C=(e=pt,t=Xi)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(e,zod.z.string().min(1).optional()),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),maxReasoningTokens:zod.z.number().int().positive().min(1).optional(),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Lo),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(i=>{var n,a;let m=Object.keys(i.def),r=Object.keys((a=(n=i.schema)==null?void 0:n.shape)!=null?a:{});return m.every(d=>r.includes(d))&&r.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"}),price:zod.z.custom()}),V=(e=io)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Lo),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var i,n;let a=Object.keys(t.def),m=Object.keys((n=(i=t.schema)==null?void 0:i.shape)!=null?n:{});return a.every(r=>m.includes(r))&&m.every(r=>a.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var us={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},gs={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},hs={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},fs=e=>({type:"multi",title:"Stop sequence",description:`Enter up to ${e} sequences that will halt additional text output. The generated text will exclude these sequences.`}),ys={type:"range",title:"Top A",description:"Considers only the top tokens that have 'sufficiently high' probabilities relative to the most likely token, functioning like a dynamic Top-P. A lower Top-A value narrows down the token choices based on the highest probability token, while a higher Top-A value refines the filtering without necessarily impacting the creativity of the output."},bs={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},Ts={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},Ps={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},Ms={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},_s={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},ks={type:"range",title:"Seed",description:"When seed is fixed to a specific value, the model makes a best effort to provide the same response for repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such as the temperature, can cause variations in the response even when you use the same seed value. By default, a random seed value is used."},vs={type:"range",title:"Repetition penalty",description:"Reduces the likelihood of repeating tokens from the input. Increasing this value makes the model less prone to repetition, but setting it too high may lead to less coherent output, often resulting in run-on sentences missing smaller words. The token penalty is scaled according to the original token's probability."},xs={type:"boolean",title:"Log probs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned."},Ss={type:"range",title:"Top log probs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used."},Es={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Cs={type:"select",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt."},Os={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},ws={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},Gs={type:"object",title:"MCP servers",description:"MCP servers to use for the model."},S={TEMPERATURE:us,MAX_TOKENS:gs,STOP:fs,TOP_A:ys,TOP_P:bs,TOP_K:Ts,MIN_P:Ps,FREQUENCY_PENALTY:Ms,PRESENCE_PENALTY:_s,REPETITION_PENALTY:vs,SEED:ks,LOG_PROBS:xs,TOP_LOG_PROBS:Ss,ECHO:Es,RESPONSE_FORMAT:Cs,RESPONSE_FORMAT_WITH_SCHEMA:Os,RESPONSE_SCHEMA:ws,MAX_REASONING_TOKENS:hs,MCP_SERVERS:Gs},Rs={type:"range",title:"Dimensions",description:"Select the number of dimensions for the word embedding."},Fs={type:"select",title:"Encoding format",description:"Select the encoding format for the word embedding."},ge={DIMENSIONS:Rs,ENCODING_FORMAT:Fs};var Te=e=>Object.fromEntries(Object.entries(e).filter(([t,i])=>i!=null)),Ct=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined",No=e=>{let t=e.replace(/-/g,"+").replace(/_/g,"/"),i=globalThis.atob(t);return Uint8Array.from(i,n=>n.codePointAt(0))};var he=e=>e==null?void 0:e.replace(/\/$/,"");var Is=Object.defineProperty,js=Object.defineProperties,Ls=Object.getOwnPropertyDescriptors,Uo=Object.getOwnPropertySymbols,Ns=Object.prototype.hasOwnProperty,Us=Object.prototype.propertyIsEnumerable,ke=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ds=e=>{throw TypeError(e)},Do=(e,t,i)=>t in e?Is(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,x=(e,t)=>{for(var i in t||(t={}))Ns.call(t,i)&&Do(e,i,t[i]);if(Uo)for(var i of Uo(t))Us.call(t,i)&&Do(e,i,t[i]);return e},Pe=(e,t)=>js(e,Ls(t)),O=(e,t,i)=>new Promise((n,a)=>{var m=l=>{try{d(i.next(l));}catch(p){a(p);}},r=l=>{try{d(i.throw(l));}catch(p){a(p);}},d=l=>l.done?n(l.value):Promise.resolve(l.value).then(m,r);d((i=i.apply(e,t)).next());}),Ko=function(e,t){this[0]=e,this[1]=t;},$o=(e,t,i)=>{var n=(r,d,l,p)=>{try{var u=i[r](d),P=(d=u.value)instanceof Ko,_=u.done;Promise.resolve(P?d[0]:d).then(k=>P?n(r==="return"?r:"next",d[1]?{done:k.done,value:k.value}:k,l,p):l({value:k,done:_})).catch(k=>n("throw",k,l,p));}catch(k){p(k);}},a=r=>m[r]=d=>new Promise((l,p)=>n(r,d,l,p)),m={};return i=i.apply(e,t),m[ke("asyncIterator")]=()=>m,a("next"),a("throw"),a("return"),m},$s=e=>{var t=e[ke("asyncIterator")],i=!1,n,a={};return t==null?(t=e[ke("iterator")](),n=m=>a[m]=r=>t[m](r)):(t=t.call(e),n=m=>a[m]=r=>{if(i){if(i=!1,m==="throw")throw r;return r}return i=!0,{done:!1,value:new Ko(new Promise(d=>{var l=t[m](r);l instanceof Object||Ds("Object expected"),d(l);}),1)}}),a[ke("iterator")]=()=>a,n("next"),"throw"in t?n("throw"):a.throw=m=>{throw m},"return"in t&&n("return"),a},As=["HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT","HARM_CATEGORY_CIVIC_INTEGRITY"],Bs=["HARM_BLOCK_THRESHOLD_UNSPECIFIED","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH","BLOCK_NONE","OFF"],Yo=(e,t)=>e.replace(t,"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,i=>i.toUpperCase()),qs=As.map(e=>({value:e,label:Yo(e,"HARM_CATEGORY_")})),zs=Bs.map(e=>({value:e,label:Yo(e,"HARM_BLOCK_THRESHOLD_")})),Jo=(e,t)=>J({param:"temperature",title:S.TEMPERATURE.title,description:S.TEMPERATURE.description,min:0,max:e,step:.01,default:t}),Wo=e=>J({param:"maxOutputTokens",title:S.MAX_TOKENS.title,description:S.MAX_TOKENS.description,min:0,max:e,step:1,default:0}),Zo=e=>Co({param:"stopSequences",title:S.STOP(e).title,description:S.STOP(e).description,max:e}),Xo=e=>J({param:"topP",title:S.TOP_P.title,description:S.TOP_P.description,min:0,max:1,step:.01,default:e});J({param:"frequencyPenalty",title:S.FREQUENCY_PENALTY.title,description:S.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0});J({param:"presencePenalty",title:S.PRESENCE_PENALTY.title,description:S.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0});J({param:"seed",title:S.SEED.title,description:S.SEED.description,min:0,max:1e6,step:1,default:0});var Qo=Et({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"]}),en=Ro({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.",fields:[{key:"category",label:"Category",choices:qs},{key:"threshold",label:"Threshold",choices:zs}],uniqueByField:"category"}),tn=_e({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}),on=(e,t,i,n,a)=>zod.z.object({temperature:Jo(e,t).schema,maxTokens:Wo(i).schema,stop:Zo(n).schema,topP:Xo(a).schema,toolChoice:Qo.schema,safetySettings:en.schema}),nn=(e,t,i,n,a)=>({temperature:Jo(e,t).def,maxTokens:Wo(i).def,stop:Zo(n).def,topP:Xo(a).def,toolChoice:Qo.def,safetySettings:en.def}),an=wo({param:"response_schema",title:S.RESPONSE_SCHEMA.title,description:S.RESPONSE_SCHEMA.description,objectSchema:eo}),sn=Et({param:"response_format",title:S.RESPONSE_FORMAT_WITH_SCHEMA.title,description:S.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_schema"]}),rn=(e,t,i,n,a)=>Pe(x({},nn(e,t,i,n,a)),{responseFormat:sn.def,responseSchema:an.def}),ln=(e,t,i,n,a)=>on(e,t,i,n,a).extend({responseFormat:sn.schema,responseSchema:an.schema}),Hs=(e,t,i,n,a)=>ln(e,t,i,n,a).extend({reasoningEnabled:tn.schema}),Vs=(e,t,i,n,a)=>Pe(x({},rn(e,t,i,n,a)),{reasoningEnabled:tn.def}),mn=e=>J({param:"outputDimensionality",title:ge.DIMENSIONS.title,description:ge.DIMENSIONS.description,min:1,max:e,step:1,default:e}),Ks=e=>zod.z.object({dimensions:mn(e).schema}),Ys=e=>({dimensions:mn(e).def}),T={base:(e,t,i,n,a)=>({def:nn(e,t,i,n,a),schema:on(e,t,i,n,a)}),responseSchema:(e,t,i,n,a)=>({def:rn(e,t,i,n,a),schema:ln(e,t,i,n,a)}),reasoning:(e,t,i,n,a)=>({def:Vs(e,t,i,n,a),schema:Hs(e,t,i,n,a)})},ve={base:e=>({def:Ys(e),schema:Ks(e)})},Js="google",Ht=class{constructor(){this.version="v1",this.name=Js,this.chatModelFactories={[Ot]:{model:pr,modelOptions:cr,modelSchema:xe},[wt]:{model:hr,modelOptions:gr,modelSchema:Se},[Gt]:{model:br,modelOptions:yr,modelSchema:Ee},[Rt]:{model:Mr,modelOptions:Pr,modelSchema:Ce},[Ft]:{model:vr,modelOptions:kr,modelSchema:Oe},[It]:{model:Er,modelOptions:Sr,modelSchema:we},[jt]:{model:wr,modelOptions:Or,modelSchema:Ge},[Lt]:{model:Fr,modelOptions:Rr,modelSchema:Re},[Nt]:{model:Nr,modelOptions:Lr,modelSchema:Fe},[Dt]:{model:qr,modelOptions:Br,modelSchema:je},[At]:{model:Jr,modelOptions:Yr,modelSchema:Ne},[$t]:{model:Vr,modelOptions:Hr,modelSchema:Le},[Bt]:{model:Xr,modelOptions:Zr,modelSchema:Ue},[qt]:{model:tl,modelOptions:el,modelSchema:De},[zt]:{model:nl,modelOptions:ol,modelSchema:$e},[Ut]:{model:$r,modelOptions:Dr,modelSchema:Ie}},this.embeddingModelFactories={[hn]:{model:dl,modelOptions:ml,modelSchema:fn},[yn]:{model:ul,modelOptions:pl,modelSchema:bn}};}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 pe({info:`Google chat model: ${t} not found`,cause:new Error(`Google chat model: ${t} not found, available chat models:
8
- [${this.chatModelLiterals().join(", ")}]`)});let i=this.chatModelFactories[t].model,n=this.chatModelFactories[t].modelOptions.parse(e);return new i(n)}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 pe({info:`Google embedding model: ${t} not found`,cause:new Error(`Google embedding model: ${t} not found, available embedding models:
9
- [${this.embeddingModelLiterals().join(", ")}]`)});let i=this.embeddingModelFactories[t].model,n=this.embeddingModelFactories[t].modelOptions.parse(e);return new i(n)}};Ht.baseUrl="https://generativelanguage.googleapis.com/v1beta";var E={"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-3-pro-preview":{modelName:"gemini-3-pro-preview",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}}}]},"gemini-2.0-flash":{modelName:"gemini-2.0-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-2.5-flash-lite":{modelName:"gemini-2.5-flash-lite",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-3-flash-preview":{modelName:"gemini-3-flash-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:3}}}]}},R=zod.z.enum([fe,Y,B,ie]),Ws="model",Zs="function",F={system:Y,user:Y,assistant:Ws,tool:Zs},I=[U,oe,le,z,ne],j=zod.z.enum([U,oe,le,z,ne]);zod.z.enum([U]);zod.z.enum([U,oe]);zod.z.enum([U,z,ne]);var Xs=zod.z.object({text:zod.z.string()}),Qs=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),er=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([Xs,Qs]))}).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()}),tr=zod.z.object({text:zod.z.string()}),ir=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Ao=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([tr,ir]))}).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()}),dn=zod.z.object({text:zod.z.string().min(1)}),or=zod.z.object({inline_data:zod.z.object({mime_type:zod.z.string().min(1),data:zod.z.string().base64()})}),nr=zod.z.object({file_data:zod.z.object({mime_type:zod.z.string().min(1),file_uri:zod.z.string().min(1)})}),ar=zod.z.object({function_call:zod.z.object({name:zod.z.string().min(1),args:zod.z.record(zod.z.string().min(1))})}),sr=zod.z.object({function_response:zod.z.object({name:zod.z.string().min(1),response:zod.z.record(zod.z.string().min(1))})}),rr=zod.z.object({role:zod.z.enum(["user","model","function"]),parts:zod.z.array(zod.z.union([dn,or,nr,ar,sr]))}),Bo=zod.z.object({parts:zod.z.array(dn)}),lr=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),parameters:zod.z.any()}),qo=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()})}),zo=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()}),Ho=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"])}),mr=zod.z.object({model:zod.z.string().min(1).optional(),contents:zod.z.array(rr),systemInstruction:Bo.optional(),system_instruction:Bo.optional(),generationConfig:zo.optional(),generation_config:zo.optional(),safetySettings:zod.z.array(Ho).optional(),safety_settings:zod.z.array(Ho).optional(),tools:zod.z.object({function_declarations:zod.z.array(lr)}).optional(),toolConfig:qo.optional(),tool_config:qo.optional()}),L=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()}),w=class{constructor(e,t){this.version="v1";var i;let n=L.parse(t);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=he((i=n.baseUrl)!=null?i:Ht.baseUrl),this.completeChatUrl=he(n.completeChatUrl||`${this.baseUrl}/models/${this.modelName}:generateContent?key=${this.apiKey}`),this.streamChatUrl=he(n.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,i)=>t+i.content.map(n=>n.modality==="text"?n.value:"").join(" ").length,0)}transformPdfMessages(e){return O(this,null,function*(){let t=r=>O(this,null,function*(){let d={};Ct()||(d["User-Agent"]="Mozilla/5.0 (compatible; GoogleFilesAPI/1.0)");let l=yield fetch(r,{headers:d});if(!l.ok)throw new v({info:`Failed to download PDF from URL: ${r}`,cause:new Error(`HTTP ${l.status}: ${l.statusText}`)});let p=yield l.arrayBuffer();return new Uint8Array(p)}),i=r=>O(this,null,function*(){try{let d=yield fetch(`https://generativelanguage.googleapis.com/v1beta/files?key=${this.apiKey}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!d.ok)return null;let l=((yield d.json()).files||[]).find(p=>p.displayName===r);return l?l.uri:null}catch(d){return null}}),n=(r,d)=>O(this,null,function*(){let l=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":r.length.toString(),"X-Goog-Upload-Header-Content-Type":"application/pdf","Content-Type":"application/json"},body:JSON.stringify({file:{display_name:d}})});if(!l.ok)throw new v({info:"Failed to start PDF upload to Google Files API",cause:new Error(`HTTP ${l.status}: ${l.statusText}`)});let p=l.headers.get("x-goog-upload-url");if(!p)throw new v({info:"No upload URL received from Google Files API",cause:new Error("Missing x-goog-upload-url header")});let u={"X-Goog-Upload-Offset":"0","X-Goog-Upload-Command":"upload, finalize"};Ct()||(u["Content-Length"]=r.length.toString());let P=yield fetch(p,{method:"POST",headers:u,body:r});if(!P.ok)throw new v({info:"Failed to upload PDF content to Google Files API",cause:new Error(`HTTP ${P.status}: ${P.statusText}`)});return (yield P.json()).file.uri}),a=r=>O(this,null,function*(){let d=yield i(r.file.id);if(d)return d;let l;if(r.value.type==="url")l=yield t(r.value.url);else {let p=r.value.base64,u="data:application/pdf;base64,";p=p.startsWith(u)?p.substring(u.length):p,l=No(p);}return yield n(l,r.file.id)}),m=[];for(let r of e){let d=[];for(let l of r.content)if(l.modality===le){let p=yield a(l);d.push(Pe(x({},l),{value:{type:"url",url:p}}));}else d.push(l);m.push(Pe(x({},r),{content:d}));}return m})}transformModelRequest(e){let t=mr.safeParse(e);if(!t.success)throw new Q({info:"Invalid model request",cause:t.error});let i=t.data,n=i.model;if(i.system_instruction&&i.systemInstruction)throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'system_instruction' and 'systemInstruction' are not allowed at the same time")});if(i.generation_config&&i.generationConfig)throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'generation_config' and 'generationConfig' are not allowed at the same time")});if(i.tool_config&&i.toolConfig)throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tool_config' and 'toolConfig' are not allowed at the same time")});let a=i.system_instruction||i.systemInstruction,m=i.generation_config||i.generationConfig,r=i.safety_settings||i.safetySettings,d=i.tool_config||i.toolConfig;if(d&&(!i.tools||i.tools.function_declarations.length===0))throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let l={};d&&(d.function_calling_config.mode==="ANY"&&d.function_calling_config.allowed_function_names&&d.function_calling_config.allowed_function_names.length===1?l.toolChoice=d.function_calling_config.allowed_function_names[0]:l.toolChoice=d.function_calling_config.mode.toLowerCase()),l.seed=m==null?void 0:m.seed,l.maxTokens=m==null?void 0:m.maxOutputTokens,l.temperature=m==null?void 0:m.temperature,l.topP=m==null?void 0:m.topP,l.presencePenalty=m==null?void 0:m.presencePenalty,l.frequencyPenalty=m==null?void 0:m.frequencyPenalty,l.stop=m==null?void 0:m.stopSequences,l.safetySettings=r;let p=ye().parse(Te(l)),u=[];a&&a.parts.forEach(_=>{u.push({role:fe,content:[{modality:U,value:_.text}]});}),i.contents.forEach(_=>{let k=_.role;switch(k){case"user":{let N=_.parts.map(G=>"text"in G?{modality:U,value:G.text}:{modality:oe,detail:"auto",value:{type:ut,base64:G.inline_data.data,mediaType:G.inline_data.mime_type.split("/")[1]}});u.push({role:k,content:N});}break;case"model":{let N=_.parts.map((G,A)=>"text"in G?{modality:U,value:G.text}:{modality:z,id:A.toString(),index:A,name:G.function_call.name,arguments:JSON.stringify(G.function_call.args)});u.push({role:B,content:N});}break;case"function":{let N=_.parts.map((G,A)=>({modality:ne,id:A.toString(),index:A,name:G.function_response.name,data:JSON.stringify(G.function_response.response)}));u.push({role:ie,content:N});}break;default:throw new v({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${_.role}' is not supported for model : ${this.modelName}`)})}});let P=[];return i.tools&&i.tools.function_declarations.forEach(_=>{P.push({type:"function",definition:{schema:{name:_.name,description:_.description,parameters:_.parameters}}});}),{modelName:n,config:p,messages:u,tools:P.length>0?P:void 0}}transformConfig(e,t,i){let n=e.toolChoice;delete e.toolChoice;let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let m=a.data;Object.keys(m).forEach(p=>{if(!(p in this.modelSchema.config.def))throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${p}',
10
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((p,u)=>{let P=this.modelSchema.config.def[u],_=P.param,k=m[u];return u==="reasoningEnabled"?p.thinkingConfig={includeThoughts:k}:u==="maxReasoningTokens"?p.thinkingConfig=p.thinkingConfig&&typeof p.thinkingConfig=="object"?Pe(x({},p.thinkingConfig),{thinkingBudget:k}):{thinkingBudget:k}:_==="maxOutputTokens"&&P.type==="range"&&k===0?p[_]=P.max:p[_]=k,p},{}),d=r.safetySettings;delete r.safetySettings;let l;if(n!==void 0){let p=n;if(!i||i&&i.length===0)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(i&&i.length>0){let u=this.modelSchema.config.def.toolChoice;if(u.choices.includes(p))p==="any"?l={function_calling_config:{mode:"ANY",allowed_function_names:i.map(P=>P.definition.schema.name)}}:l={function_calling_config:{mode:p.toUpperCase()}};else if(i.map(P=>P.definition.schema.name).includes(p))l={function_calling_config:{mode:"ANY",allowed_function_names:[p]}};else throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${p}' is not part of provided 'tools' names or
11
- one of [${u.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let p=r.response_format;if(p==="json_schema"){let u=r.response_schema;if(!("response_schema"in r)||!r.response_schema||!(u!=null&&u.schema))throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});r.responseSchema=u.schema,r.responseMimeType="application/json","additionalProperties"in u.schema&&delete r.responseSchema.additionalProperties,delete r.response_format,delete r.response_schema;}else p==="json_object"?(r.responseSchema={type:"object"},delete r.response_format):p==="text"&&delete r.response_format;}return x(x({generation_config:r},l?{tool_config:l}:{}),d?{safety_settings:d}:{})}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let t=r=>{let d=r.match(/^data:(image\/[a-zA-Z]+|application\/pdf);base64,/);return d?r.substring(d[0].length):r},i=e.map(r=>{let d=ft().safeParse(r);if(!d.success)throw new v({info:"Invalid messages",cause:d.error});return d.data});i.forEach(r=>{r.content.forEach(d=>{if(!this.modelSchema.modalities.includes(d.modality))throw new v({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${d.modality}',
12
- available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),i.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new v({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}',
13
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let n={parts:[]},a=[];if(i.forEach(r=>{switch(r.role){case fe:r.content.forEach(d=>{if(d.modality===U)n.parts.push({text:d.value});else throw new v({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})});break;case B:{let d=[];r.content.forEach(l=>{if(l.modality===U)d.push({text:l.value});else if(l.modality===z)d.push({function_call:{name:l.name,args:JSON.parse(l.arguments)}});else throw new v({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:d});}break;case Y:{let d=[];r.content.forEach(l=>{if(l.modality===U)d.push({text:l.value});else if(l.modality===oe){if(l.value.type==="base64"){let p=l.value.base64;p=t(p),d.push({inline_data:{mime_type:`image/${l.value.mediaType}`,data:p}});}else if(l.value.type==="url")throw new v({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${l.value.type}'`)})}else if(l.modality===le)if(l.value.type==="base64"){let p=l.value.base64;p=t(p),d.push({inline_data:{mime_type:"application/pdf",data:p}});}else l.value.type==="url"&&d.push({file_data:{mime_type:"application/pdf",file_uri:l.value.url}});else throw new v({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:d});}break;case ie:{let d=[];r.content.forEach(l=>{if(l.modality===ne)d.push({function_response:{name:l.name,response:JSON.parse(l.data)}});else throw new v({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:d});}break;default:throw new v({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
14
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),a[0].role!==this.modelSchema.roles[Y])throw new v({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=r=>r===this.modelSchema.roles[Y]||r===this.modelSchema.roles[ie]?[this.modelSchema.roles[B]]:[this.modelSchema.roles[Y],this.modelSchema.roles[ie]];for(let r=1;r<a.length;r++)if(!m(a[r-1].role).includes(a[r].role))throw new v({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${a[r].role}' after message with role : '${a[r-1].role}'`)});if(a[a.length-1].role!==this.modelSchema.roles[Y]&&a[a.length-1].role!==this.modelSchema.roles[ie])throw new v({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return x({contents:a},n.parts.length>0?{system_instruction:n}:{})}stripAdditionalProperties(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(i=>this.stripAdditionalProperties(i));let t={};for(let[i,n]of Object.entries(e))i!=="additionalProperties"&&(t[i]=this.stripAdditionalProperties(n));return t}transformTools(e){if(!this.modelSchema.modalities.includes(z))throw new Pt({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${z}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:[{function_declarations:e.map(t=>{let i=no().safeParse(t);if(!i.success)throw new Pt({info:"Invalid tools",cause:i.error});return i.data}).map(t=>({name:t.definition.schema.name,description:t.definition.schema.description,parameters:this.stripAdditionalProperties(t.definition.schema.parameters)}))}]}}getCompleteChatUrl(e,t,i){return O(this,null,function*(){return new Promise(n=>{n(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,i){return O(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getCompleteChatData(e,t,i){return O(this,null,function*(){let n=this.transformConfig(e,t,i),a=yield this.transformPdfMessages(t),m=this.transformMessages(a);if(m.messages&&m.messages.length===0)throw new v({info:"Messages are required",cause:new Error("Messages are required")});let r=i?this.transformTools(i):{};return x(x(x(x({},this.getDefaultParams()),n),m),r)})}transformCompleteChatResponse(e){let t=er.safeParse(e);if(t.success){if(t.data.candidates.length===0)throw new $({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(t.data)}`)});let i=t.data,n=[],a,m=i.candidates[0].content;if(m){let d=m.parts.map((l,p)=>{if("text"in l&&l.text!==void 0)return ao(l.text);if("functionCall"in l&&l.functionCall!==void 0)return so(p,`${l.functionCall.name}_${p}`,l.functionCall.name,JSON.stringify(l.functionCall.args))});return n.push({role:B,content:d}),i.usageMetadata&&(a={promptTokens:i.usageMetadata.promptTokenCount,totalTokens:i.usageMetadata.totalTokenCount,completionTokens:i.usageMetadata.candidatesTokenCount||0}),{messages:n,usage:a,logProbs:void 0}}let r=i.candidates[0].safetyRatings;if(r&&r.length>0&&r.forEach(d=>{if(d.blocked)throw new $({info:`Blocked content for category: ${d.category} with probability: ${d.probability}`,cause:new Error(`Blocked content for category: ${d.category} with probability: ${d.probability}`)})}),i.candidates[0].finishReason==="SAFETY")throw new $({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new $({info:"Invalid response from model",cause:t.error})}getStreamChatUrl(e,t,i){return O(this,null,function*(){return new Promise(n=>{n(this.streamChatUrl);})})}getStreamChatHeaders(e,t,i){return O(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getStreamChatData(e,t,i){return O(this,null,function*(){let n=this.transformConfig(e,t,i),a=yield this.transformPdfMessages(t),m=this.transformMessages(a);if(m.messages&&m.messages.length===0)throw new v({info:"Messages are required",cause:new Error("Messages are required")});let r=i?this.transformTools(i):{};return x(x(x(x({},this.getDefaultParams()),n),m),r)})}transformStreamChatResponseChunk(e,t){return $o(this,null,function*(){let i=(t+e).split(",\r").filter(n=>n.trim()!=="");for(let n of i){let a=n;if(a=a.replace(/\n/g,""),a.startsWith("[")||a.startsWith(",{"))a=a.slice(1);else if(a.endsWith("]")){if(a==="]")return;a=a.slice(0,-1);}let m;try{m=JSON.parse(a);}catch(d){if(d instanceof SyntaxError){t=a;continue}else throw d}t="";let r=Ao.safeParse(m);if(r.success){let d={partialMessages:[]},l=r.data;if(l.candidates.length>0){let p=l.candidates[0].content;p&&"parts"in p&&p.parts.length>0&&p.parts.forEach((u,P)=>{if("text"in u&&u.text!==void 0&&d.partialMessages.push(bt(B,u.text)),"functionCall"in u&&u.functionCall!==void 0){let _=u.functionCall;d.partialMessages.push(Tt(B,P,`${_.name}_${P}`,_.name,JSON.stringify(_.args)));}});}l.usageMetadata&&(d.usage={promptTokens:l.usageMetadata.promptTokenCount,completionTokens:l.usageMetadata.candidatesTokenCount,totalTokens:l.usageMetadata.totalTokenCount}),yield {partialResponse:d,buffer:t};}else throw new $({info:"Invalid response from model",cause:r.error})}yield {partialResponse:{partialMessages:[]},buffer:t};})}transformProxyStreamChatResponseChunk(e,t,i,n,a){return $o(this,null,function*(){if((a==null?void 0:a.alt)!=="sse"){yield*$i($s(this.transformStreamChatResponseChunk(e,t)));return}let m=t+e,r=[],d="",l=0;for(;l<m.length;){let p=m.indexOf(`
15
- `,l);if(p===-1){d=m.substring(l);break}else {let u=m.substring(l,p).trim();u&&r.push(u),l=p+1;}}for(let p of r){if(p==="data: [DONE]")return;if(p.startsWith("data: ")){let u=p.substring(6);try{let P=JSON.parse(u),_=Ao.safeParse(P);if(_.success){let k={partialMessages:[]},N=_.data;if(N.candidates.length>0){let G=N.candidates[0].content;G&&"parts"in G&&G.parts.length>0&&G.parts.forEach((A,Ni)=>{if("text"in A&&A.text!==void 0&&k.partialMessages.push(bt(B,A.text)),"functionCall"in A&&A.functionCall!==void 0){let lt=A.functionCall;k.partialMessages.push(Tt(B,Ni,`${lt.name}_${Ni}`,lt.name,JSON.stringify(lt.args)));}});}N.usageMetadata&&N.usageMetadata.totalTokenCount&&N.usageMetadata.promptTokenCount&&N.usageMetadata.candidatesTokenCount&&(k.usage={promptTokens:N.usageMetadata.promptTokenCount,completionTokens:N.usageMetadata.candidatesTokenCount,totalTokens:N.usageMetadata.totalTokenCount}),yield {partialResponse:k,buffer:t};}else throw new $({info:"Invalid response from model",cause:_.error})}catch(P){throw new $({info:`Malformed JSON received in stream: ${u}`,cause:P})}}}yield {partialResponse:{partialMessages:[]},buffer:d};})}getProxyCompleteChatUrl(e,t,i){return O(this,null,function*(){return new Promise(n=>{n(this.completeChatUrl);})})}getProxyStreamChatUrl(e,t,i){return O(this,null,function*(){return new Promise(n=>{if(!i||Object.keys(i).length===0){n(this.streamChatUrl);return}let a=new URL(this.streamChatUrl);Object.entries(i).forEach(([m,r])=>{r!=null&&a.searchParams.set(m,r);}),n(a.toString());})})}getProxyCompleteChatHeaders(e,t,i){return O(this,null,function*(){if(!t)return {};let n=x({},t);return delete n.host,delete n["content-length"],n})}getProxyStreamChatHeaders(e,t,i){return O(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,i)})}getModelPricing(){if(!(this.modelName in E))throw new $({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return E[this.modelName]}},Ot="gemini-1.5-flash-001",dr="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=C(R,j).parse({name:Ot,description:dr,maxInputTokens:1e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[Ot]}),cr=L,pr=class extends w{constructor(e){super(xe,e);}},wt="gemini-1.5-flash-002",ur="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",Se=C(R,j).parse({name:wt,description:ur,maxInputTokens:1e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[wt]}),gr=L,hr=class extends w{constructor(e){super(Se,e);}},Gt="gemini-1.5-flash-latest",fr="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Ee=C(R,j).parse({name:Gt,description:fr,maxInputTokens:1e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[Gt]}),yr=L,br=class extends w{constructor(e){super(Ee,e);}},Rt="gemini-1.5-flash",Tr="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",Ce=C(R,j).parse({name:Rt,description:Tr,maxInputTokens:1e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[Rt]}),Pr=L,Mr=class extends w{constructor(e){super(Ce,e);}},Ft="gemini-1.5-pro-001",_r="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Oe=C(R,j).parse({name:Ft,description:_r,maxInputTokens:2e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[Ft]}),kr=L,vr=class extends w{constructor(e){super(Oe,e);}},It="gemini-1.5-pro-002",xr="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",we=C(R,j).parse({name:It,description:xr,maxInputTokens:2e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[It]}),Sr=L,Er=class extends w{constructor(e){super(we,e);}},jt="gemini-1.5-pro-latest",Cr="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ge=C(R,j).parse({name:jt,description:Cr,maxInputTokens:2e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[jt]}),Or=L,wr=class extends w{constructor(e){super(Ge,e);}},Lt="gemini-1.5-pro",Gr="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Re=C(R,j).parse({name:Lt,description:Gr,maxInputTokens:2e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[Lt]}),Rr=L,Fr=class extends w{constructor(e){super(Re,e);}},Vo="gemini-2.0-flash-exp",Ir="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",cn=C(R,j).parse({name:Vo,description:Ir,maxInputTokens:1e6,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[Vo]});var Nt="gemini-2.0-flash",jr="Google's Gemini 2.0 Flash model optimized for low-latency, high-performance tasks. Supports multimodal inputs including text, images, video, and audio with enhanced speed and efficiency.",Fe=C(R,j).parse({name:Nt,description:jr,maxInputTokens:1048576,maxOutputTokens:8192,roles:F,modalities:I,config:{def:T.responseSchema(2,1,8192,4,.95).def,schema:T.responseSchema(2,1,8192,4,.95).schema},price:E[Nt]}),Lr=L,Nr=class extends w{constructor(e){super(Fe,e);}},Ut="gemini-2.5-flash-lite",Ur="Google's most cost-efficient and fastest model in the 2.5 series. Optimized for high-volume, latency-sensitive tasks like translation and classification with enhanced reasoning capabilities.",Ie=C(R,j).parse({name:Ut,description:Ur,maxInputTokens:1048576,maxOutputTokens:65536,roles:F,modalities:I,config:{def:T.responseSchema(2,1,65536,4,.95).def,schema:T.responseSchema(2,1,65536,4,.95).schema},price:E[Ut]}),Dr=L,$r=class extends w{constructor(e){super(Ie,e);}},Dt="gemini-2.5-flash-preview-04-17",Ar="Google's best model in Gemini 2.5 family in terms of price-performance, offering well-rounded capabilities.",je=C(R,j).parse({name:Dt,description:Ar,maxInputTokens:1048576,maxOutputTokens:65536,roles:F,modalities:I,config:{def:T.responseSchema(2,1,65536,4,.95).def,schema:T.responseSchema(2,1,65536,4,.95).schema},price:E[Dt]}),Br=L,qr=class extends w{constructor(e){super(je,e);}},$t="gemini-2.5-flash",zr="Google's Gemini 2.5 Flash model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Le=C(R,j).parse({name:$t,description:zr,maxInputTokens:1048576,maxOutputTokens:65536,roles:F,modalities:I,config:{def:T.responseSchema(2,1,65536,4,.95).def,schema:T.responseSchema(2,1,65536,4,.95).schema},price:E[$t]}),Hr=L,Vr=class extends w{constructor(e){super(Le,e);}},At="gemini-2.5-pro-preview-03-25",Kr="Google's preview model in Gemini 2.5 family for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Ne=C(R,j).parse({name:At,description:Kr,maxInputTokens:1048576,maxOutputTokens:65536,roles:F,modalities:I,config:{def:T.reasoning(2,1,65536,4,.95).def,schema:T.reasoning(2,1,65536,4,.95).schema},price:E[At]}),Yr=L,Jr=class extends w{constructor(e){super(Ne,e);}},Bt="gemini-2.5-pro",Wr="Google's Gemini 2.5 Pro model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Ue=C(R,j).parse({name:Bt,description:Wr,maxInputTokens:1048576,maxOutputTokens:65536,roles:F,modalities:I,config:{def:T.reasoning(2,1,65536,4,.95).def,schema:T.reasoning(2,1,65536,4,.95).schema},price:E[Bt]}),Zr=L,Xr=class extends w{constructor(e){super(Ue,e);}},qt="gemini-3-flash-preview",Qr="Google's Gemini 3 Flash Preview model - a lightweight and efficient AI model with enhanced multimodal understanding, reasoning, and advanced coding capabilities. Optimized for speed and cost-effectiveness. Supports Text, Image, Video, Audio, and PDF inputs. Knowledge cutoff: January 2025.",De=C(R,j).parse({name:qt,description:Qr,maxInputTokens:1048576,maxOutputTokens:65536,roles:F,modalities:I,config:{def:T.reasoning(2,1,65536,4,.95).def,schema:T.reasoning(2,1,65536,4,.95).schema},price:E[qt]}),el=L,tl=class extends w{constructor(e){super(De,e);}},zt="gemini-3-pro-preview",il="Google's latest Gemini 3 Pro Preview model with enhanced multimodal understanding, reasoning, and thinking capabilities. Supports Text, Image, Video, Audio, and PDF inputs. Knowledge cutoff: January 2025.",$e=C(R,j).parse({name:zt,description:il,maxInputTokens:1048576,maxOutputTokens:65536,roles:F,modalities:I,config:{def:T.reasoning(2,1,65536,4,.95).def,schema:T.reasoning(2,1,65536,4,.95).schema},price:E[zt]}),ol=L,nl=class extends w{constructor(e){super($e,e);}},pn=[D],un=zod.z.enum([D]),al=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),sl=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)})}),rl=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(sl).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),Vt=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),gn=class{constructor(e,t){this.version="v1";let i=Vt.parse(t);this.modelSchema=e,this.modelName=i.modelName,this.apiKey=i.apiKey,this.baseUrl=he(i.baseUrl||Ht.baseUrl),this.getEmbeddingsUrl=he(i.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,i)=>t+i.length,0)}transformModelRequest(e){let t=rl.safeParse(e);if(!t.success)throw new Q({info:"Invalid model request",cause:t.error});let i=t.data,n=i.model,a={outputDimensionality:i.outputDimensionality},m=ye().parse(Te(a)),r={modality:D,requests:i.requests.reduce((d,l)=>(d.push(...l.content.parts.map(p=>p.text)),d),[])};return {modelName:n,config:m,embeddingRequests:r}}transformConfig(e,t){let i=this.modelSchema.config.schema.safeParse(e);if(!i.success)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:i.error});let n=i.data;return Object.keys(n).forEach(a=>{if(!this.modelSchema.config.def[a])throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${a}',
16
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(n).reduce((a,m)=>{let r=this.modelSchema.config.def[m].param,d=n[m];return a[r]=d,a},{})}transformEmbeddingRequests(e){let t=Me().safeParse(e);if(!t.success)throw new ae({info:"Invalid embedding requests",cause:t.error});if(e.modality!==D)throw new ae({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${D}' 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 O(this,null,function*(){return new Promise(i=>{i(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return O(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return O(this,null,function*(){return new Promise(i=>{let n=this.transformConfig(e),a=this.transformEmbeddingRequests(t);if(t.requests.length===0)throw new ae({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});n.outputDimensionality&&(a.requests.forEach(m=>{m.outputDimensionality=n.outputDimensionality;}),delete n.outputDimensionality),i(x(x(x({},this.getDefaultParams()),n),a));})})}transformGetEmbeddingsResponse(e){let t=al.safeParse(e);if(t.success){let i=t.data.embeddings.map((n,a)=>({index:a,embedding:n.values}));return {encodingFormat:be,embeddings:i}}throw new $({info:"Invalid response from model",cause:t.error})}},hn="text-embedding-001",ll="text-embedding-001",fn=V(un).parse({name:hn,description:ll,modalities:pn,maxInputTokens:2048,maxOutputTokens:768,config:{def:ve.base(768).def,schema:ve.base(768).schema}}),ml=Vt,dl=class extends gn{constructor(e){super(fn,e);}},yn="text-embedding-004",cl="text-embedding-004",bn=V(un).parse({name:yn,description:cl,modalities:pn,maxInputTokens:2048,maxOutputTokens:768,config:{def:ve.base(768).def,schema:ve.base(768).schema}}),pl=Vt,ul=class extends gn{constructor(e){super(bn,e);}};var gl="vertex",me=class{constructor(){this.version="v1";this.name=gl;this.chatModelFactories={[Kt]:{model:Ae,modelOptions:Tn,modelSchema:Yt},[Jt]:{model:Be,modelOptions:Pn,modelSchema:Wt},[ai]:{model:Ke,modelOptions:xn,modelSchema:si},[Zt]:{model:qe,modelOptions:Mn,modelSchema:Xt},[Qt]:{model:ze,modelOptions:_n,modelSchema:ei},[ti]:{model:He,modelOptions:kn,modelSchema:ii},[ri]:{model:Ye,modelOptions:Sn,modelSchema:li},[oi]:{model:Ve,modelOptions:vn,modelSchema:ni},[mi]:{model:Je,modelOptions:En,modelSchema:di},[ci]:{model:We,modelOptions:Cn,modelSchema:pi},[ui]:{model:Ze,modelOptions:On,modelSchema:gi},[hi]:{model:Xe,modelOptions:wn,modelSchema:fi},[Ti]:{model:et,modelOptions:Rn,modelSchema:Pi},[yi]:{model:Qe,modelOptions:Gn,modelSchema:bi},[Mi]:{model:tt,modelOptions:Fn,modelSchema:_i},[ki]:{model:it,modelOptions:In,modelSchema:vi},[xi]:{model:ot,modelOptions:jn,modelSchema:Si}};this.embeddingModelFactories={[Ei]:{model:nt,modelOptions:Ln,modelSchema:Ci},[Oi]:{model:at,modelOptions:Nn,modelSchema:wi},[Fi]:{model:rt,modelOptions:Dn,modelSchema:Ii},[Gi]:{model:st,modelOptions:Un,modelSchema:Ri}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,i)=>(t[i]=this.chatModelFactories[i].modelSchema,t),{})}chatModel(t){let i=t.modelName;if(!(i in this.chatModelFactories))throw new pe({info:`Vertex chat model: ${i} not found`,cause:new Error(`Vertex chat model: ${i} not found, available chat models:
17
- ${this.chatModelLiterals().join(", ")}`)});let n=this.chatModelFactories[i].model,a=this.chatModelFactories[i].modelOptions.parse(t);return new n(a)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,i)=>(t[i]=this.embeddingModelFactories[i].modelSchema,t),{})}embeddingModel(t){let i=t.modelName;if(!(i in this.embeddingModelFactories))throw new pe({info:`Vertex embedding model: ${i} not found`,cause:new Error(`Vertex embedding model: ${i} not found, available embedding models:
18
- ${this.embeddingModelLiterals().join(", ")}`)});let n=this.embeddingModelFactories[i].model,a=this.embeddingModelFactories[i].modelOptions.parse(t);return new n(a)}};me.baseUrl=(t,i,n="google")=>`https://${t}-aiplatform.googleapis.com/v1/projects/${i}/locations/${t}/publishers/${n}`;var h={"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-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":{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":{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:.15,outputPricePerMillion:.6}}}]},"gemini-2.0-flash":{modelName:"gemini-2.0-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-2.5-flash-lite":{modelName:"gemini-2.5-flash-lite",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-1.5-flash-latest":{modelName:"gemini-1.5-flash-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.01875,outputPricePerMillion:.075}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.0375,outputPricePerMillion:.15}}}]},"gemini-1.5-pro-latest":{modelName:"gemini-1.5-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.3125,outputPricePerMillion:1.25}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.625,outputPricePerMillion:2.5}}}]},"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:.5,outputPricePerMillion:2}}}]},"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-2.5-flash":{modelName:"gemini-2.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.3,outputPricePerMillion:2.5}}}]},"gemini-2.5-pro":{modelName:"gemini-2.5-pro",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-3-pro-preview":{modelName:"gemini-3-pro-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:2,outputPricePerMillion:12}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:4,outputPricePerMillion:18}}}]},"gemini-3-flash-preview":{modelName:"gemini-3-flash-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:3}}}]}};var b=zod.z.discriminatedUnion("authType",[zod.z.object({authType:zod.z.literal("accessToken"),accessToken:zod.z.string(),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional()}),zod.z.object({authType:zod.z.literal("serviceAccount"),serviceAccount:zod.z.object({client_email:zod.z.string().email(),private_key:zod.z.string(),type:zod.z.string().optional(),project_id:zod.z.string().optional(),private_key_id:zod.z.string().optional(),client_id:zod.z.string().optional(),auth_uri:zod.z.string().url().optional(),token_uri:zod.z.string().url().optional(),auth_provider_x509_cert_url:zod.z.string().url().optional(),client_x509_cert_url:zod.z.string().url().optional(),universe_domain:zod.z.string().optional()}),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional(),tokenLifetimeHours:zod.z.number().min(.1).max(24).default(1)})]),y=class extends w{constructor(i,n){let a=b.parse(n),m;if(a.baseUrl)m=a.baseUrl;else if(a.location&&a.projectId)m=me.baseUrl(a.location,a.projectId,a.publisher);else throw new ue({info:"Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided",cause:new Error("Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided")});super(i,{modelName:a.modelName,apiKey:"random-api-key",completeChatUrl:`${m}/models/${a.modelName}:generateContent`,streamChatUrl:`${m}/models/${a.modelName}:streamGenerateContent`});this.version="v1";this.accessToken=null;this.tokenExpiry=null;this.modelSchema=i,this.modelName=a.modelName,this.authOptions=a,this.location=a.location,this.projectId=a.projectId,this.publisher=a.publisher,a.authType==="accessToken"&&(this.accessToken=a.accessToken);}getAccessToken(){return K(this,null,function*(){if(this.accessToken&&this.tokenExpiry&&Date.now()<this.tokenExpiry)return this.accessToken;if(this.authOptions.authType==="serviceAccount")try{let i=this.authOptions.serviceAccount,n=Math.floor(Date.now()/1e3),a=yield new jose.SignJWT({scope:"https://www.googleapis.com/auth/cloud-platform",aud:"https://oauth2.googleapis.com/token"}).setProtectedHeader({alg:"RS256",typ:"JWT"}).setIssuedAt(n).setExpirationTime(n+this.authOptions.tokenLifetimeHours*3600).setIssuer(i.client_email).setSubject(i.client_email).sign(yield this.importPrivateKey(i.private_key)),m=yield fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:a})});if(!m.ok){let d=yield m.text();throw new Error(`Token exchange failed: ${m.status} ${d}`)}let r=yield m.json();if(!r.access_token)throw new Error(`No access token received from Google OAuth: ${r.error||"Unknown error"}`);return this.tokenExpiry=Date.now()+this.authOptions.tokenLifetimeHours*3600*1e3-5*60*1e3,this.accessToken=r.access_token,this.accessToken}catch(i){throw new ue({info:`Failed to generate service account token: ${i instanceof Error?i.message:String(i)}`,cause:i instanceof Error?i:new Error(String(i))})}if(this.accessToken)return this.accessToken;throw new ue({info:"No valid access token available",cause:new Error("No valid access token available")})})}importPrivateKey(i){return K(this,null,function*(){let n=i.replace(/-----BEGIN PRIVATE KEY-----/,"").replace(/-----END PRIVATE KEY-----/,"").replace(/\s/g,""),a=atob(n),m=new Uint8Array(a.length);for(let r=0;r<a.length;r++)m[r]=a.charCodeAt(r);return yield crypto.subtle.importKey("pkcs8",m,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])})}ensureToken(){return K(this,null,function*(){this.authOptions.authType==="serviceAccount"&&(yield this.getAccessToken());})}getDefaultHeaders(){return f(g({},super.getDefaultHeaders()),{Authorization:`Bearer ${this.accessToken}`})}getCompleteChatHeaders(i,n,a){return K(this,null,function*(){return yield this.ensureToken(),this.getDefaultHeaders()})}getStreamChatHeaders(i,n,a){return K(this,null,function*(){return yield this.ensureToken(),this.getDefaultHeaders()})}getModelPricing(){if(!(this.modelName in h))throw new $({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return h[this.modelName]}};var Kt="gemini-1.5-flash-001",Yt=f(g({},xe),{price:h[Kt]}),Tn=b,Ae=class extends y{constructor(t){super(Yt,t);}};var Jt="gemini-1.5-flash-002",Wt=f(g({},Se),{price:h[Jt]}),Pn=b,Be=class extends y{constructor(t){super(Wt,t);}};var Zt="gemini-1.5-flash",Xt=f(g({},Ce),{price:h[Zt]}),Mn=b,qe=class extends y{constructor(t){super(Xt,t);}};var Qt="gemini-1.5-pro-001",ei=f(g({},Oe),{price:h[Qt]}),_n=b,ze=class extends y{constructor(t){super(ei,t);}};var ti="gemini-1.5-pro-002",ii=f(g({},we),{price:h[ti]}),kn=b,He=class extends y{constructor(t){super(ii,t);}};var oi="gemini-1.5-pro",ni=f(g({},Re),{price:h[oi]}),vn=b,Ve=class extends y{constructor(t){super(ni,t);}};var ai="gemini-1.5-flash-latest",si=f(g({},Ee),{price:h[ai]}),xn=b,Ke=class extends y{constructor(t){super(si,t);}};var ri="gemini-1.5-pro-latest",li=f(g({},Ge),{price:h[ri]}),Sn=b,Ye=class extends y{constructor(t){super(li,t);}};var mi="gemini-2.0-flash-exp",di=f(g({},cn),{price:h[mi]}),En=b,Je=class extends y{constructor(t){super(di,t);}};var ci="gemini-2.0-flash",pi=f(g({},Fe),{price:h[ci]}),Cn=b,We=class extends y{constructor(t){super(pi,t);}};var ui="gemini-2.5-flash-lite",gi=f(g({},Ie),{price:h[ui]}),On=b,Ze=class extends y{constructor(t){super(gi,t);}};var hi="gemini-2.5-flash-preview-04-17",fi=f(g({},je),{price:h[hi]}),wn=b,Xe=class extends y{constructor(t){super(fi,t);}};var yi="gemini-2.5-flash",bi=f(g({},Le),{price:h[yi]}),Gn=b,Qe=class extends y{constructor(t){super(bi,t);}};var Ti="gemini-2.5-pro-preview-03-25",Pi=f(g({},Ne),{price:h[Ti]}),Rn=b,et=class extends y{constructor(t){super(Pi,t);}};var Mi="gemini-2.5-pro",_i=f(g({},Ue),{price:h[Mi]}),Fn=b,tt=class extends y{constructor(t){super(_i,t);}};var ki="gemini-3-flash-preview",vi=f(g({},De),{price:h[ki]}),In=b,it=class extends y{constructor(t){super(vi,t);}};var xi="gemini-3-pro-preview",Si=f(g({},$e),{price:h[xi]}),jn=b,ot=class extends y{constructor(t){super(Si,t);}};var se=[D],re=zod.z.enum([D]);var $n=zod.z.object({predictions:zod.z.array(zod.z.object({embeddings:zod.z.object({values:zod.z.array(zod.z.number()),statistics:zod.z.object({token_count:zod.z.number(),truncated:zod.z.boolean()})})}))});var An=zod.z.object({model:zod.z.string().min(1).optional(),instances:zod.z.array(zod.z.object({content:zod.z.string().min(1)})).min(1),parameters:zod.z.object({auto_truncate:zod.z.boolean().optional(),output_dimensionality:zod.z.number().int().min(1).optional(),autoTruncate:zod.z.boolean().optional(),outputDimensionality:zod.z.number().int().min(1).optional()}).optional()});var te=zod.z.object({accessToken:zod.z.string(),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional()}),Z=class{constructor(t,i){this.version="v1";let n=te.parse(i);this.modelSchema=t,this.modelName=n.modelName,this.accessToken=n.accessToken;let a;if(n.baseUrl)a=n.baseUrl;else if(n.location&&n.projectId)a=me.baseUrl(n.location,n.projectId,n.publisher);else throw new ue({info:"Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided",cause:new Error("Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided")});this.baseUrl=a,this.getEmbeddingsUrl=`${this.baseUrl}/models/${n.modelName}:predict`,this.location=n.location,this.projectId=n.projectId;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`}}getDefaultParams(){return {}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.requests.reduce((i,n)=>i+n.length,0)}transformModelRequest(t){var l,p,u,P;let i=An.safeParse(t);if(!i.success)throw new Q({info:"Invalid model request",cause:i.error});let n=i.data,a=n.model,m={autoTruncate:((l=n.parameters)==null?void 0:l.auto_truncate)||((p=n.parameters)==null?void 0:p.autoTruncate),dimensions:((u=n.parameters)==null?void 0:u.output_dimensionality)||((P=n.parameters)==null?void 0:P.outputDimensionality)},r=ye().parse(Te(m)),d={modality:D,requests:n.instances.map(_=>_.content)};return {modelName:a,config:r,embeddingRequests:d}}transformConfig(t,i){let n=this.modelSchema.config.schema.safeParse(t);if(!n.success)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let a=n.data;return Object.keys(a).forEach(r=>{if(!this.modelSchema.config.def[r])throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${r}',
19
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),{parameters:Object.keys(a).reduce((r,d)=>{let p=this.modelSchema.config.def[d].param,u=a[d];return r[p]=u,r},{})}}transformEmbeddingRequests(t){let i=Me().safeParse(t);if(!i.success)throw new ae({info:"Invalid embedding requests",cause:i.error});if(t.modality!==D)throw new ae({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${D}' modality is supported for model : '${this.modelName}'`)});return {instances:i.data.requests.map(a=>({content:a}))}}getGetEmbeddingsUrl(t,i){return K(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,i){return K(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,i){return K(this,null,function*(){return new Promise(n=>{if(i.requests.length===0)throw new ae({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});n(g(g(g({},this.getDefaultParams()),this.transformConfig(t)),this.transformEmbeddingRequests(i)));})})}transformGetEmbeddingsResponse(t){let i=$n.safeParse(t);if(i.success){let a=i.data.predictions.map((m,r)=>({index:r,embedding:m.embeddings.values}));return {encodingFormat:be,embeddings:a}}throw new $({info:"Invalid response from model",cause:i.error})}};var ji=e=>J({param:"output_dimensionality",title:ge.DIMENSIONS.title,description:ge.DIMENSIONS.description,min:1,max:e,step:1,default:e}),Li=_e({param:"auto_truncate",title:"Auto truncate",description:"When set to true, input text will be truncated. When set to false, an error is returned if the input text is longer than the maximum length supported by the model.",default:!0});var Bn=e=>zod.z.object({dimensions:ji(e).schema,autoTruncate:Li.schema}),qn=e=>({dimensions:ji(e).def,autoTruncate:Li.def});var q={base:e=>({def:qn(e),schema:Bn(e)})};var Ei="text-embedding-004",Tl="text-embedding-004",Ci=V(re).parse({name:Ei,description:Tl,modalities:se,maxInputTokens:2048,maxOutputTokens:768,config:{def:q.base(768).def,schema:q.base(768).schema}}),Ln=te,nt=class extends Z{constructor(t){super(Ci,t);}};var Oi="text-multilingual-embedding-002",Pl="text-multilingual-embedding-002",wi=V(re).parse({name:Oi,description:Pl,modalities:se,maxInputTokens:2048,maxOutputTokens:768,config:{def:q.base(768).def,schema:q.base(768).schema}}),Nn=te,at=class extends Z{constructor(t){super(wi,t);}};var Gi="textembedding-gecko-multilingual@001",Ml="textembedding-gecko-multilingual@001",Ri=V(re).parse({name:Gi,description:Ml,modalities:se,maxInputTokens:2048,maxOutputTokens:768,config:{def:q.base(768).def,schema:q.base(768).schema}}),Un=te,st=class extends Z{constructor(t){super(Ri,t);}};var Fi="textembedding-gecko@003",_l="textembedding-gecko@003",Ii=V(re).parse({name:Fi,description:_l,modalities:se,maxInputTokens:2048,maxOutputTokens:768,config:{def:q.base(768).def,schema:q.base(768).schema}}),Dn=te,rt=class extends Z{constructor(t){super(Ii,t);}};
6
+ var ca=Object.defineProperty,pa=Object.defineProperties;var ua=Object.getOwnPropertyDescriptors;var ei=Object.getOwnPropertySymbols;var ga=Object.prototype.hasOwnProperty,ha=Object.prototype.propertyIsEnumerable;var yt=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),fa=e=>{throw TypeError(e)};var ti=(e,t,i)=>t in e?ca(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,b=(e,t)=>{for(var i in t||(t={}))ga.call(t,i)&&ti(e,i,t[i]);if(ei)for(var i of ei(t))ha.call(t,i)&&ti(e,i,t[i]);return e},P=(e,t)=>pa(e,ua(t));var X=(e,t,i)=>new Promise((n,a)=>{var m=l=>{try{d(i.next(l));}catch(p){a(p);}},r=l=>{try{d(i.throw(l));}catch(p){a(p);}},d=l=>l.done?n(l.value):Promise.resolve(l.value).then(m,r);d((i=i.apply(e,t)).next());}),ya=function(e,t){this[0]=e,this[1]=t;};var oi=e=>{var t=e[yt("asyncIterator")],i=!1,n,a={};return t==null?(t=e[yt("iterator")](),n=m=>a[m]=r=>t[m](r)):(t=t.call(e),n=m=>a[m]=r=>{if(i){if(i=!1,m==="throw")throw r;return r}return i=!0,{done:!1,value:new ya(new Promise(d=>{var l=t[m](r);l instanceof Object||fa("Object expected"),d(l);}),1)}}),a[yt("iterator")]=()=>a,n("next"),"throw"in t?n("throw"):a.throw=m=>{throw m},"return"in t&&n("return"),a};var ve="system",Z="user",R="assistant",re="tool",ba=[ve,Z,R,re],Pt=zod.z.enum(ba),Ta=[R],Pa=zod.z.enum(Ta),Mt="error",we="safety",Ma=zod.z.object({type:zod.z.literal(we),value:zod.z.object({category:zod.z.string(),probability:zod.z.string(),blocked:zod.z.boolean(),message:zod.z.string()})}),si=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Mt),value:zod.z.discriminatedUnion("type",[Ma]),metadata:e}),vt="partial-error",va=zod.z.object({type:zod.z.literal(we),category:zod.z.string().optional(),probability:zod.z.string().optional(),blocked:zod.z.boolean().optional(),message:zod.z.string().optional()}),ri=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(vt),value:zod.z.discriminatedUnion("type",[va]),metadata:e}),le="image",_t="base64",_a=["png","jpeg","webp","gif"],ka=zod.z.object({type:zod.z.literal(_t),base64:zod.z.string(),mediaType:zod.z.enum(_a)}),xa="url",Sa=zod.z.object({type:zod.z.literal(xa),url:zod.z.string()}),Ea=zod.z.discriminatedUnion("type",[ka,Sa]),Ca=["low","medium","high","auto"],wa=zod.z.enum(Ca),Oa=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(le),detail:wa,value:Ea,metadata:e}),ue="pdf",Ga="base64",Ra=zod.z.object({type:zod.z.literal(Ga),base64:zod.z.string()}),Ia="url",ja=zod.z.object({type:zod.z.literal(Ia),url:zod.z.string()}),Fa=zod.z.discriminatedUnion("type",[Ra,ja]),Na=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ue),value:Fa,file:zod.z.object({name:zod.z.string(),id:zod.z.string(),size:zod.z.number().optional()}),metadata:e}),li="reasoning",mi="partial-reasoning",di="thinking",La="redacted",Tt=zod.z.object({type:zod.z.literal(di),thinking:zod.z.string(),signature:zod.z.string()}),ci=zod.z.object({type:zod.z.literal(La),data:zod.z.string()}),Ua=zod.z.discriminatedUnion("type",[Tt,ci]),Da=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(li),value:Ua,metadata:e}),$a=zod.z.object({type:zod.z.literal(di),thinking:Tt.shape.thinking.optional(),signature:Tt.shape.signature.optional()}),Aa=zod.z.discriminatedUnion("type",[$a,ci]),Ba=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(mi),value:Aa,metadata:e}),kt="search-result",Oe="google",qa=zod.z.object({type:zod.z.literal(Oe),query:zod.z.string(),responses:zod.z.array(zod.z.object({source:zod.z.string(),url:zod.z.string(),title:zod.z.string(),snippet:zod.z.string().optional()})),references:zod.z.array(zod.z.object({text:zod.z.string(),responseIndices:zod.z.array(zod.z.number()),startIndex:zod.z.number().optional(),endIndex:zod.z.number().optional(),confidenceScores:zod.z.array(zod.z.number()).optional()}))}),pi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(kt),value:zod.z.discriminatedUnion("type",[qa]),metadata:e}),xt="partial-search-result",za=zod.z.object({type:zod.z.literal(Oe),query:zod.z.string().optional(),responses:zod.z.array(zod.z.object({source:zod.z.string().optional(),url:zod.z.string().optional(),title:zod.z.string().optional(),snippet:zod.z.string().optional()})).optional(),references:zod.z.array(zod.z.object({text:zod.z.string().optional(),responseIndices:zod.z.array(zod.z.number()).optional(),startIndex:zod.z.number().optional(),endIndex:zod.z.number().optional(),confidenceScores:zod.z.array(zod.z.number()).optional()})).optional()}),ui=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(xt),value:zod.z.discriminatedUnion("type",[za]),metadata:e}),A="text",gi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(A),value:zod.z.string(),metadata:e}),St="partial-text",hi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(St),value:zod.z.string(),metadata:e}),V="tool-call",fi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(V),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),serverName:zod.z.string().optional(),metadata:e}),Et="partial-tool-call",yi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Et),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),serverName:zod.z.string().optional(),metadata:e}),me="tool-response",Ha=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(me),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:e}),Va="partial-tool-response",Ka=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Va),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),data:zod.z.string().optional(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:e}),Ya=[A,le,ue,V,me,li,Mt,kt],bi=zod.z.enum(Ya),Ja=(e=zod.z.undefined(),t=zod.z.undefined(),i=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined(),r=zod.z.undefined(),d=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[gi(e),Oa(t),Na(i),fi(n),Ha(a),Da(m),si(r),pi(d)]),Wa=[St,Et,mi,vt,xt];zod.z.enum(Wa);var Xa=(e=zod.z.undefined(),t=zod.z.undefined(),i=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[hi(e),yi(t),Ba(n),Ka(i),ri(a),ui(m)]);var Ct=(e=Pt,t=zod.z.undefined(),i=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined(),r=zod.z.undefined(),d=zod.z.undefined())=>zod.z.object({role:e,content:zod.z.array(Ja(t,i,n,a,r,m)),metadata:d}),_e=(e=Pa,t=zod.z.undefined(),i=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:e,partialContent:Xa(t,i,n,m),metadata:a}),Za=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),ii=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Qa=ii.extend({topLogProbs:zod.z.array(ii)}),Ti=zod.z.array(Qa);zod.z.object({messages:zod.z.array(Ct()),usage:Za.optional(),logProbs:Ti.optional()});var es=zod.z.object({promptTokens:zod.z.number().nonnegative().optional(),completionTokens:zod.z.number().nonnegative().optional(),totalTokens:zod.z.number().nonnegative().optional()});zod.z.object({partialMessages:zod.z.array(_e()),usage:es.optional(),logProbs:Ti.optional()});var ke=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,ts=zod.z.object({enabled:zod.z.boolean().default(!0),allowedTools:zod.z.array(zod.z.string().min(1))});zod.z.object({type:zod.z.literal("url"),url:zod.z.string().url().refine(e=>e.startsWith("https://"),{message:"MCP server URL must start with https://"}),name:zod.z.string().min(1),toolConfiguration:ts.optional(),authorizationToken:zod.z.string().min(1).optional()});var os=["object","array","number","string","boolean","enum"],ni=zod.z.enum(os),is=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([ni,zod.z.array(zod.z.union([ni,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),ns=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(is),additionalProperties:zod.z.literal(!1)}),Pi=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:ns}).optional(),B="text",Mi="token",as=[B,Mi],vi=zod.z.enum(as),ss=zod.z.array(zod.z.string().min(1)),rs=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Ge=(e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(B),metadata:e,requests:ss}),zod.z.object({modality:zod.z.literal(Mi),metadata:e,requests:rs})]),xe="float",ls=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),ms="base64",ds=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),ai=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(xe),embeddings:zod.z.array(ls),usage:ai.optional()}),zod.z.object({encodingFormat:zod.z.literal(ms),embeddings:zod.z.array(ds),usage:ai.optional()})]);var cs=e=>{let t=new WeakSet;return JSON.stringify(e,(i,n)=>{if(typeof n=="object"&&n!==null){if(t.has(n))return;t.add(n);}return n})},ps=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:cs(e),bt="GatewayBaseError",ie=class _i extends Error{constructor({info:t,cause:i},n){super(`[${n!=null?n:bt}]: ${t}
7
+ Message: ${ps(i)}`),this.name=bt,this.info=t,this.cause=i,this.name=n!=null?n:bt,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof _i}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},us=zod.z.object({inputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M input tokens"),outputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M output tokens")}).describe("Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier."),gs=zod.z.object({base:us.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),hs=zod.z.object({minTokens:zod.z.number().int().nonnegative().describe("Inclusive lower token bound for this tier."),maxTokens:zod.z.number().int().nullable().optional().describe("Exclusive upper token bound; `null` means \u221E."),prices:gs.describe("Price categories and rates for this specific token range.")}).refine(e=>e.maxTokens===null||typeof e.maxTokens=="number"&&e.maxTokens>e.minTokens,{message:"maxTokens must be > minTokens (or null for infinite).",path:["maxTokens"]}).describe("A single pricing tier defined by a token range and associated prices.");zod.z.object({modelName:zod.z.string().describe("Model name this schedule applies to."),currency:zod.z.string().default("USD").describe("Currency code (e.g., USD)."),tokenRanges:zod.z.array(hs).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((e,t)=>{let{tokenRanges:i}=e;i[0].minTokens!==0&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let a=1;a<i.length;a++){let m=i[a-1],r=i[a];if(m.maxTokens===null){t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",a-1,"maxTokens"],message:"Cannot define any tokenRanges after an infinite tier (maxTokens = null)."});break}r.minTokens!==m.maxTokens&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",a,"minTokens"],message:`Tier ${a} minTokens (${r.minTokens}) must equal previous tier's maxTokens (${m.maxTokens}) for contiguity.`}),r.minTokens<m.minTokens&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",a,"minTokens"],message:`tokenRanges must be sorted by ascending minTokens. Tier ${a} (${r.minTokens}) starts before Tier ${a-1} (${m.minTokens}).`});}let n=i[i.length-1];i.every(a=>a.maxTokens!==null||a===n)&&n.maxTokens!==null&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i.length-1,"maxTokens"],message:"The final tier must have maxTokens = null (representing infinity)."});}).describe("Complete pricing schedule for a single chat model, including all its token-based tiers.");var fs="function";var ys=zod.z.enum(["object","array","number","string","boolean","null"]),bs=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ys.optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional()});zod.z.object({type:zod.z.enum(["object"]),title:zod.z.string().optional(),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(bs).optional(),required:zod.z.array(zod.z.string()).optional()});var Ts=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),parameters:zod.z.any(),strict:zod.z.boolean().optional()});var Ps=zod.z.enum(["function"]),Ms=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),vs=zod.z.object({type:zod.z.literal("http"),method:zod.z.enum(["get","post"]),url:zod.z.string().url(),headers:zod.z.record(zod.z.string()).optional(),query:zod.z.record(zod.z.string()).optional(),body:zod.z.record(zod.z.any()).optional(),proxyUrl:zod.z.string().url().optional(),proxyHeaders:zod.z.record(zod.z.string()).optional(),retry:Ms.optional()}),_s=zod.z.discriminatedUnion("type",[vs]),ks=zod.z.object({type:Ps,definition:zod.z.object({schema:Ts}),request:_s.optional()}),xs=[fs];zod.z.enum(xs);var ki=(e=zod.z.undefined())=>zod.z.discriminatedUnion("type",[ks.extend({metadata:e})]),xi=e=>gi().parse({modality:A,value:e}),Si=(e,t,i,n,a)=>fi().parse({modality:V,index:e,id:t,name:i,arguments:n,serverName:a});var wt=(e,t)=>_e().parse({role:e,partialContent:hi().parse({modality:St,value:t})}),Ot=(e,t,i,n,a,m)=>_e().parse({role:e,partialContent:yi().parse({modality:Et,index:t,id:i,name:n,arguments:a,serverName:m})});var Gt=(e,t,i,n)=>si().parse({modality:Mt,value:{type:we,value:{category:e,probability:t,blocked:i,message:n}}});var Rt=(e,t,i,n,a)=>_e().parse({role:e,partialContent:ri().parse({modality:vt,value:{type:we,category:t,probability:i,blocked:n,message:a}})}),It=(e,t,i)=>pi().parse({modality:kt,value:{type:Oe,query:e,responses:t,references:i}});var jt=(e,t,i,n)=>_e().parse({role:e,partialContent:ui().parse({modality:xt,value:{type:Oe,query:t,responses:i,references:n}})});var Ss=Object.defineProperty,Ei=Object.getOwnPropertySymbols,Es=Object.prototype.hasOwnProperty,Cs=Object.prototype.propertyIsEnumerable,Ci=(e,t,i)=>t in e?Ss(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,fe=(e,t)=>{for(var i in t||(t={}))Es.call(t,i)&&Ci(e,i,t[i]);if(Ei)for(var i of Ei(t))Cs.call(t,i)&&Ci(e,i,t[i]);return e},wi="ProviderError",ye=class Ui extends ie{constructor({info:t,cause:i}){super({info:t,cause:i},wi),this.name=wi,this.info=t,this.cause=i;}static isProviderError(t){return t instanceof Ui}},Oi="ModelError",be=class Di extends ie{constructor({info:t,cause:i}){super({info:t,cause:i},Oi),this.name=Oi,this.info=t,this.cause=i;}static isModelError(t){return t instanceof Di}},Gi="ModelResponseError",z=class $i extends ie{constructor({info:t,cause:i}){super({info:t,cause:i},Gi),this.name=Gi,this.cause=i,this.info=t;}static isModelResponseError(t){return t instanceof $i}},Ri="InvalidModelRequestError",ne=class Ai extends ie{constructor({info:t,cause:i}){super({info:t,cause:i},Ri),this.name=Ri,this.cause=i,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Ai}},Ii="InvalidConfigError",K=class Bi extends ie{constructor({info:t,cause:i}){super({info:t,cause:i},Ii),this.name=Ii,this.cause=i,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Bi}},ji="InvalidMessagesError",E=class qi extends ie{constructor({info:t,cause:i}){super({info:t,cause:i},ji),this.name=ji,this.cause=i,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof qi}},Fi="InvalidToolsError",Ft=class zi extends ie{constructor({info:t,cause:i}){super({info:t,cause:i},Fi),this.name=Fi,this.cause=i,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof zi}},Ni="InvalidEmbeddingRequestsError",de=class Hi extends ie{constructor({info:t,cause:i}){super({info:t,cause:i},Ni),this.name=Ni,this.info=t,this.cause=i,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Hi}},Nt="multi-string",Vi=zod.z.object({type:zod.z.literal(Nt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),ws=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),Ki=e=>({def:Vi.parse(fe({type:Nt},e)),schema:ws(e.max)}),Lt="object-schema",Yi=zod.z.object({type:zod.z.literal(Lt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),Os=e=>e.optional(),Ji=e=>({def:Yi.parse(fe({type:Lt},e)),schema:Os(e.objectSchema)}),Ut="paired-select",Gs=zod.z.object({value:zod.z.string().min(1),label:zod.z.string().min(1)}),Li=zod.z.object({key:zod.z.string().min(1),label:zod.z.string().min(1),description:zod.z.string().min(1).max(500).optional(),choices:zod.z.array(Gs).min(1)}),Wi=zod.z.object({type:zod.z.literal(Ut),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),fields:zod.z.tuple([Li,Li]),uniqueByField:zod.z.string().min(1).optional()}),Rs=e=>{let t=e.map(a=>a.value);if(t.length===0)throw new Error("PairedSelectConfigItem fields must define at least one choice");let[i,...n]=t;return zod.z.enum([i,...n])},Is=e=>{let t=e.reduce((i,n)=>(i[n.key]=Rs(n.choices),i),{});return zod.z.array(zod.z.object(t)).optional()},Xi=e=>{let t=Wi.parse(fe({type:Ut},e)),i=new Set(t.fields.map(n=>n.key));if(i.size!==t.fields.length)throw new Error("PairedSelectConfigItem fields must have unique keys");if(t.uniqueByField&&!i.has(t.uniqueByField))throw new Error("uniqueByField must reference one of the defined field keys");return {def:t,schema:Is(t.fields)}},Dt="range",Zi=zod.z.object({type:zod.z.literal(Dt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),js=(e,t,i,n)=>zod.z.number().min(e).max(t).step(i).default(n).optional(),Q=e=>({def:Zi.parse(fe({type:Dt},e)),schema:js(e.min,e.max,e.step,e.default)}),$t="select-boolean",Qi=zod.z.object({type:zod.z.literal($t),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),Fs=e=>zod.z.boolean().nullable().default(e).optional(),Se=e=>({def:Qi.parse(fe({type:$t},e)),schema:Fs(e.default)}),At="select-string",en=zod.z.object({type:zod.z.literal(At),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string(),choices:zod.z.array(zod.z.string())}),Ns=(e,t)=>zod.z.enum(t).nullable().default(e).optional(),Bt=e=>({def:en.parse(fe({type:At},e)),schema:Ns(e.default,e.choices)}),Ls=[Dt,Nt,At,Lt,$t,Ut];zod.z.enum(Ls);var tn=zod.z.discriminatedUnion("type",[Zi,Vi,en,Qi,Yi,Wi]),I=(e=Pt,t=bi)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(e,zod.z.string().min(1).optional()),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),maxReasoningTokens:zod.z.number().int().positive().min(1).optional(),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),tn),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(i=>{var n,a;let m=Object.keys(i.def),r=Object.keys((a=(n=i.schema)==null?void 0:n.shape)!=null?a:{});return m.every(d=>r.includes(d))&&r.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"}),price:zod.z.custom()}),Y=(e=vi)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),tn),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var i,n;let a=Object.keys(t.def),m=Object.keys((n=(i=t.schema)==null?void 0:i.shape)!=null?n:{});return a.every(r=>m.includes(r))&&m.every(r=>a.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var Us={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},Ds={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},$s={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},As=e=>({type:"multi",title:"Stop sequence",description:`Enter up to ${e} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Bs={type:"range",title:"Top A",description:"Considers only the top tokens that have 'sufficiently high' probabilities relative to the most likely token, functioning like a dynamic Top-P. A lower Top-A value narrows down the token choices based on the highest probability token, while a higher Top-A value refines the filtering without necessarily impacting the creativity of the output."},qs={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},zs={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},Hs={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},Vs={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},Ks={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},Ys={type:"range",title:"Seed",description:"When seed is fixed to a specific value, the model makes a best effort to provide the same response for repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such as the temperature, can cause variations in the response even when you use the same seed value. By default, a random seed value is used."},Js={type:"range",title:"Repetition penalty",description:"Reduces the likelihood of repeating tokens from the input. Increasing this value makes the model less prone to repetition, but setting it too high may lead to less coherent output, often resulting in run-on sentences missing smaller words. The token penalty is scaled according to the original token's probability."},Ws={type:"boolean",title:"Log probs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned."},Xs={type:"range",title:"Top log probs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used."},Zs={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Qs={type:"select",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt."},er={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},tr={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},or={type:"object",title:"MCP servers",description:"MCP servers to use for the model."},w={TEMPERATURE:Us,MAX_TOKENS:Ds,STOP:As,TOP_A:Bs,TOP_P:qs,TOP_K:zs,MIN_P:Hs,FREQUENCY_PENALTY:Vs,PRESENCE_PENALTY:Ks,REPETITION_PENALTY:Js,SEED:Ys,LOG_PROBS:Ws,TOP_LOG_PROBS:Xs,ECHO:Zs,RESPONSE_FORMAT:Qs,RESPONSE_FORMAT_WITH_SCHEMA:er,RESPONSE_SCHEMA:tr,MAX_REASONING_TOKENS:$s,MCP_SERVERS:or},ir={type:"range",title:"Dimensions",description:"Select the number of dimensions for the word embedding."},nr={type:"select",title:"Encoding format",description:"Select the encoding format for the word embedding."},Te={DIMENSIONS:ir,ENCODING_FORMAT:nr};var Ee=e=>Object.fromEntries(Object.entries(e).filter(([t,i])=>i!=null)),qt=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined",on=e=>{let t=e.replace(/-/g,"+").replace(/_/g,"/"),i=globalThis.atob(t);return Uint8Array.from(i,n=>n.codePointAt(0))};var Pe=e=>e==null?void 0:e.replace(/\/$/,"");var ar=Object.defineProperty,sr=Object.defineProperties,rr=Object.getOwnPropertyDescriptors,nn=Object.getOwnPropertySymbols,lr=Object.prototype.hasOwnProperty,mr=Object.prototype.propertyIsEnumerable,Re=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),dr=e=>{throw TypeError(e)},an=(e,t,i)=>t in e?ar(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,S=(e,t)=>{for(var i in t||(t={}))lr.call(t,i)&&an(e,i,t[i]);if(nn)for(var i of nn(t))mr.call(t,i)&&an(e,i,t[i]);return e},Ce=(e,t)=>sr(e,rr(t)),j=(e,t,i)=>new Promise((n,a)=>{var m=l=>{try{d(i.next(l));}catch(p){a(p);}},r=l=>{try{d(i.throw(l));}catch(p){a(p);}},d=l=>l.done?n(l.value):Promise.resolve(l.value).then(m,r);d((i=i.apply(e,t)).next());}),un=function(e,t){this[0]=e,this[1]=t;},sn=(e,t,i)=>{var n=(r,d,l,p)=>{try{var g=i[r](d),y=(d=g.value)instanceof un,u=g.done;Promise.resolve(y?d[0]:d).then(h=>y?n(r==="return"?r:"next",d[1]?{done:h.done,value:h.value}:h,l,p):l({value:h,done:u})).catch(h=>n("throw",h,l,p));}catch(h){p(h);}},a=r=>m[r]=d=>new Promise((l,p)=>n(r,d,l,p)),m={};return i=i.apply(e,t),m[Re("asyncIterator")]=()=>m,a("next"),a("throw"),a("return"),m},cr=e=>{var t=e[Re("asyncIterator")],i=!1,n,a={};return t==null?(t=e[Re("iterator")](),n=m=>a[m]=r=>t[m](r)):(t=t.call(e),n=m=>a[m]=r=>{if(i){if(i=!1,m==="throw")throw r;return r}return i=!0,{done:!1,value:new un(new Promise(d=>{var l=t[m](r);l instanceof Object||dr("Object expected"),d(l);}),1)}}),a[Re("iterator")]=()=>a,n("next"),"throw"in t?n("throw"):a.throw=m=>{throw m},"return"in t&&n("return"),a},pr=["HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT","HARM_CATEGORY_CIVIC_INTEGRITY"],ur=["HARM_BLOCK_THRESHOLD_UNSPECIFIED","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH","BLOCK_NONE","OFF"],gn=(e,t)=>e.replace(t,"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,i=>i.toUpperCase()),gr=pr.map(e=>({value:e,label:gn(e,"HARM_CATEGORY_")})),hr=ur.map(e=>({value:e,label:gn(e,"HARM_BLOCK_THRESHOLD_")})),hn=(e,t)=>Q({param:"temperature",title:w.TEMPERATURE.title,description:w.TEMPERATURE.description,min:0,max:e,step:.01,default:t}),fn=e=>Q({param:"maxOutputTokens",title:w.MAX_TOKENS.title,description:w.MAX_TOKENS.description,min:0,max:e,step:1,default:0}),yn=e=>Ki({param:"stopSequences",title:w.STOP(e).title,description:w.STOP(e).description,max:e}),bn=e=>Q({param:"topP",title:w.TOP_P.title,description:w.TOP_P.description,min:0,max:1,step:.01,default:e});Q({param:"frequencyPenalty",title:w.FREQUENCY_PENALTY.title,description:w.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0});Q({param:"presencePenalty",title:w.PRESENCE_PENALTY.title,description:w.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0});Q({param:"seed",title:w.SEED.title,description:w.SEED.description,min:0,max:1e6,step:1,default:0});var Tn=Bt({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"]}),Pn=Xi({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.",fields:[{key:"category",label:"Category",choices:gr},{key:"threshold",label:"Threshold",choices:hr}],uniqueByField:"category"}),Mn=Se({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}),vn=Se({param:"googleSearch",title:"Google Search Tool",description:"Controls whether the model is allowed to use the Google Search tool. Powered by Google.",default:!1}),_n=(e,t,i,n,a)=>zod.z.object({temperature:hn(e,t).schema,maxTokens:fn(i).schema,stop:yn(n).schema,topP:bn(a).schema,toolChoice:Tn.schema,safetySettings:Pn.schema,googleSearchTool:vn.schema}),kn=(e,t,i,n,a)=>({temperature:hn(e,t).def,maxTokens:fn(i).def,stop:yn(n).def,topP:bn(a).def,toolChoice:Tn.def,safetySettings:Pn.def,googleSearchTool:vn.def}),xn=Ji({param:"response_schema",title:w.RESPONSE_SCHEMA.title,description:w.RESPONSE_SCHEMA.description,objectSchema:Pi}),Sn=Bt({param:"response_format",title:w.RESPONSE_FORMAT_WITH_SCHEMA.title,description:w.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_schema"]}),En=(e,t,i,n,a)=>Ce(S({},kn(e,t,i,n,a)),{responseFormat:Sn.def,responseSchema:xn.def}),Cn=(e,t,i,n,a)=>_n(e,t,i,n,a).extend({responseFormat:Sn.schema,responseSchema:xn.schema}),fr=(e,t,i,n,a)=>Cn(e,t,i,n,a).extend({reasoningEnabled:Mn.schema}),yr=(e,t,i,n,a)=>Ce(S({},En(e,t,i,n,a)),{reasoningEnabled:Mn.def}),wn=e=>Q({param:"outputDimensionality",title:Te.DIMENSIONS.title,description:Te.DIMENSIONS.description,min:1,max:e,step:1,default:e}),br=e=>zod.z.object({dimensions:wn(e).schema}),Tr=e=>({dimensions:wn(e).def}),_={base:(e,t,i,n,a)=>({def:kn(e,t,i,n,a),schema:_n(e,t,i,n,a)}),responseSchema:(e,t,i,n,a)=>({def:En(e,t,i,n,a),schema:Cn(e,t,i,n,a)}),reasoning:(e,t,i,n,a)=>({def:yr(e,t,i,n,a),schema:fr(e,t,i,n,a)})},Ie={base:e=>({def:Tr(e),schema:br(e)})},Pr="google",so=class{constructor(){this.version="v1",this.name=Pr,this.chatModelFactories={[zt]:{model:qr,modelOptions:Br,modelSchema:je},[Ht]:{model:Vr,modelOptions:Hr,modelSchema:Fe},[Vt]:{model:Jr,modelOptions:Yr,modelSchema:Ne},[Kt]:{model:Zr,modelOptions:Xr,modelSchema:Le},[Yt]:{model:tl,modelOptions:el,modelSchema:Ue},[Jt]:{model:nl,modelOptions:il,modelSchema:De},[Wt]:{model:rl,modelOptions:sl,modelSchema:$e},[Xt]:{model:dl,modelOptions:ml,modelSchema:Ae},[Zt]:{model:gl,modelOptions:ul,modelSchema:Be},[eo]:{model:Pl,modelOptions:Tl,modelSchema:ze},[oo]:{model:Sl,modelOptions:xl,modelSchema:Ve},[to]:{model:_l,modelOptions:vl,modelSchema:He},[io]:{model:wl,modelOptions:Cl,modelSchema:Ke},[no]:{model:Rl,modelOptions:Gl,modelSchema:Ye},[ao]:{model:Fl,modelOptions:jl,modelSchema:Je},[Qt]:{model:yl,modelOptions:fl,modelSchema:qe}},this.embeddingModelFactories={[Nn]:{model:Al,modelOptions:$l,modelSchema:Ln},[Un]:{model:zl,modelOptions:ql,modelSchema:Dn}};}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 ye({info:`Google chat model: ${t} not found`,cause:new Error(`Google chat model: ${t} not found, available chat models:
8
+ [${this.chatModelLiterals().join(", ")}]`)});let i=this.chatModelFactories[t].model,n=this.chatModelFactories[t].modelOptions.parse(e);return new i(n)}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 ye({info:`Google embedding model: ${t} not found`,cause:new Error(`Google embedding model: ${t} not found, available embedding models:
9
+ [${this.embeddingModelLiterals().join(", ")}]`)});let i=this.embeddingModelFactories[t].model,n=this.embeddingModelFactories[t].modelOptions.parse(e);return new i(n)}};so.baseUrl="https://generativelanguage.googleapis.com/v1beta";var O={"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-3-pro-preview":{modelName:"gemini-3-pro-preview",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}}}]},"gemini-2.0-flash":{modelName:"gemini-2.0-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-2.5-flash-lite":{modelName:"gemini-2.5-flash-lite",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-3-flash-preview":{modelName:"gemini-3-flash-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:3}}}]}},N=zod.z.enum([ve,Z,R,re]),Mr="model",vr="function",L={system:Z,user:Z,assistant:Mr,tool:vr},U=[A,le,ue,V,me],D=zod.z.enum([A,le,ue,V,me]);zod.z.enum([A]);zod.z.enum([A,le]);zod.z.enum([A,V,me]);var _r=zod.z.object({renderedContent:zod.z.string().optional()}),kr=zod.z.object({uri:zod.z.string().optional(),title:zod.z.string().optional()}),xr=zod.z.object({web:kr.optional()}),Sr=zod.z.object({startIndex:zod.z.number().optional(),endIndex:zod.z.number().optional(),text:zod.z.string().optional()}),Er=zod.z.object({segment:Sr.optional(),groundingChunkIndices:zod.z.array(zod.z.number()).optional(),confidenceScores:zod.z.array(zod.z.number()).optional()}),On=zod.z.object({searchEntryPoint:_r.optional(),groundingChunks:zod.z.array(xr).optional(),groundingSupports:zod.z.array(Er).optional(),webSearchQueries:zod.z.array(zod.z.string()).optional()}),Cr=zod.z.object({text:zod.z.string()}),wr=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Or=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([Cr,wr]))}).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()}))),groundingMetadata:On.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()}),Gr=zod.z.object({text:zod.z.string()}),Rr=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),rn=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([Gr,Rr]))}).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()}))),groundingMetadata:On.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()}),Gn=zod.z.object({text:zod.z.string().min(1)}),Ir=zod.z.object({inline_data:zod.z.object({mime_type:zod.z.string().min(1),data:zod.z.string().base64()})}),jr=zod.z.object({file_data:zod.z.object({mime_type:zod.z.string().min(1),file_uri:zod.z.string().min(1)})}),Fr=zod.z.object({function_call:zod.z.object({name:zod.z.string().min(1),args:zod.z.record(zod.z.string().min(1))})}),Nr=zod.z.object({function_response:zod.z.object({name:zod.z.string().min(1),response:zod.z.record(zod.z.string().min(1))})}),Lr=zod.z.object({role:zod.z.enum(["user","model","function"]),parts:zod.z.array(zod.z.union([Gn,Ir,jr,Fr,Nr]))}),ln=zod.z.object({parts:zod.z.array(Gn)}),Ur=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),parameters:zod.z.any()}),Dr=zod.z.object({timeRangeFilter:zod.z.object({startTime:zod.z.string().datetime().optional(),endTime:zod.z.string().datetime().optional()}).optional()}),mn=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()})}),dn=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()}),cn=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"])}),$r=zod.z.object({model:zod.z.string().min(1).optional(),contents:zod.z.array(Lr),systemInstruction:ln.optional(),system_instruction:ln.optional(),generationConfig:dn.optional(),generation_config:dn.optional(),safetySettings:zod.z.array(cn).optional(),safety_settings:zod.z.array(cn).optional(),tools:zod.z.object({function_declarations:zod.z.array(Ur),google_search:Dr.optional()}).optional(),toolConfig:mn.optional(),tool_config:mn.optional()}),$=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()}),F=class{constructor(e,t){this.version="v1";var i;let n=$.parse(t);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Pe((i=n.baseUrl)!=null?i:so.baseUrl),this.completeChatUrl=Pe(n.completeChatUrl||`${this.baseUrl}/models/${this.modelName}:generateContent?key=${this.apiKey}`),this.streamChatUrl=Pe(n.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,i)=>t+i.content.map(n=>n.modality==="text"?n.value:"").join(" ").length,0)}transformPdfMessages(e){return j(this,null,function*(){let t=r=>j(this,null,function*(){let d={};qt()||(d["User-Agent"]="Mozilla/5.0 (compatible; GoogleFilesAPI/1.0)");let l=yield fetch(r,{headers:d});if(!l.ok)throw new E({info:`Failed to download PDF from URL: ${r}`,cause:new Error(`HTTP ${l.status}: ${l.statusText}`)});let p=yield l.arrayBuffer();return new Uint8Array(p)}),i=r=>j(this,null,function*(){try{let d=yield fetch(`https://generativelanguage.googleapis.com/v1beta/files?key=${this.apiKey}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!d.ok)return null;let l=((yield d.json()).files||[]).find(p=>p.displayName===r);return l?l.uri:null}catch(d){return null}}),n=(r,d)=>j(this,null,function*(){let l=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":r.length.toString(),"X-Goog-Upload-Header-Content-Type":"application/pdf","Content-Type":"application/json"},body:JSON.stringify({file:{display_name:d}})});if(!l.ok)throw new E({info:"Failed to start PDF upload to Google Files API",cause:new Error(`HTTP ${l.status}: ${l.statusText}`)});let p=l.headers.get("x-goog-upload-url");if(!p)throw new E({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"};qt()||(g["Content-Length"]=r.length.toString());let y=yield fetch(p,{method:"POST",headers:g,body:r});if(!y.ok)throw new E({info:"Failed to upload PDF content to Google Files API",cause:new Error(`HTTP ${y.status}: ${y.statusText}`)});return (yield y.json()).file.uri}),a=r=>j(this,null,function*(){let d=yield i(r.file.id);if(d)return d;let l;if(r.value.type==="url")l=yield t(r.value.url);else {let p=r.value.base64,g="data:application/pdf;base64,";p=p.startsWith(g)?p.substring(g.length):p,l=on(p);}return yield n(l,r.file.id)}),m=[];for(let r of e){let d=[];for(let l of r.content)if(l.modality===ue){let p=yield a(l);d.push(Ce(S({},l),{value:{type:"url",url:p}}));}else d.push(l);m.push(Ce(S({},r),{content:d}));}return m})}transformModelRequest(e){let t=$r.safeParse(e);if(!t.success)throw new ne({info:"Invalid model request",cause:t.error});let i=t.data,n=i.model;if(i.system_instruction&&i.systemInstruction)throw new ne({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'system_instruction' and 'systemInstruction' are not allowed at the same time")});if(i.generation_config&&i.generationConfig)throw new ne({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'generation_config' and 'generationConfig' are not allowed at the same time")});if(i.tool_config&&i.toolConfig)throw new ne({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tool_config' and 'toolConfig' are not allowed at the same time")});let a=i.system_instruction||i.systemInstruction,m=i.generation_config||i.generationConfig,r=i.safety_settings||i.safetySettings,d=i.tool_config||i.toolConfig;if(d&&(!i.tools||i.tools.function_declarations.length===0))throw new ne({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let l={};d&&(d.function_calling_config.mode==="ANY"&&d.function_calling_config.allowed_function_names&&d.function_calling_config.allowed_function_names.length===1?l.toolChoice=d.function_calling_config.allowed_function_names[0]:l.toolChoice=d.function_calling_config.mode.toLowerCase()),l.seed=m==null?void 0:m.seed,l.maxTokens=m==null?void 0:m.maxOutputTokens,l.temperature=m==null?void 0:m.temperature,l.topP=m==null?void 0:m.topP,l.presencePenalty=m==null?void 0:m.presencePenalty,l.frequencyPenalty=m==null?void 0:m.frequencyPenalty,l.stop=m==null?void 0:m.stopSequences,l.safetySettings=r;let p=ke().parse(Ee(l)),g=[];a&&a.parts.forEach(u=>{g.push({role:ve,content:[{modality:A,value:u.text}]});}),i.contents.forEach(u=>{let h=u.role;switch(h){case"user":{let f=u.parts.map(k=>"text"in k?{modality:A,value:k.text}:{modality:le,detail:"auto",value:{type:_t,base64:k.inline_data.data,mediaType:k.inline_data.mime_type.split("/")[1]}});g.push({role:h,content:f});}break;case"model":{let f=u.parts.map((k,G)=>"text"in k?{modality:A,value:k.text}:{modality:V,id:G.toString(),index:G,name:k.function_call.name,arguments:JSON.stringify(k.function_call.args)});g.push({role:R,content:f});}break;case"function":{let f=u.parts.map((k,G)=>({modality:me,id:G.toString(),index:G,name:k.function_response.name,data:JSON.stringify(k.function_response.response)}));g.push({role:re,content:f});}break;default:throw new E({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${u.role}' is not supported for model : ${this.modelName}`)})}});let y=[];return i.tools&&i.tools.function_declarations.forEach(u=>{y.push({type:"function",definition:{schema:{name:u.name,description:u.description,parameters:u.parameters}}});}),{modelName:n,config:p,messages:g,tools:y.length>0?y:void 0}}transformConfig(e,t,i){let n=e.toolChoice;delete e.toolChoice;let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let m=a.data;Object.keys(m).forEach(p=>{if(!(p in this.modelSchema.config.def))throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${p}',
10
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((p,g)=>{let y=this.modelSchema.config.def[g],u=y.param,h=m[g];return g==="reasoningEnabled"?p.thinkingConfig={includeThoughts:h}:g==="maxReasoningTokens"?p.thinkingConfig=p.thinkingConfig&&typeof p.thinkingConfig=="object"?Ce(S({},p.thinkingConfig),{thinkingBudget:h}):{thinkingBudget:h}:u==="maxOutputTokens"&&y.type==="range"&&h===0?p[u]=y.max:p[u]=h,p},{}),d=r.safetySettings;delete r.safetySettings,delete r.googleSearch;let l;if(n!==void 0){let p=n;if(!i||i&&i.length===0)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(i&&i.length>0){let g=this.modelSchema.config.def.toolChoice;if(g.choices.includes(p))p==="any"?l={function_calling_config:{mode:"ANY",allowed_function_names:i.map(y=>y.definition.schema.name)}}:l={function_calling_config:{mode:p.toUpperCase()}};else if(i.map(y=>y.definition.schema.name).includes(p))l={function_calling_config:{mode:"ANY",allowed_function_names:[p]}};else throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${p}' is not part of provided 'tools' names or
11
+ one of [${g.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let p=r.response_format;if(p==="json_schema"){let g=r.response_schema;if(!("response_schema"in r)||!r.response_schema||!(g!=null&&g.schema))throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});r.responseSchema=g.schema,r.responseMimeType="application/json","additionalProperties"in g.schema&&delete r.responseSchema.additionalProperties,delete r.response_format,delete r.response_schema;}else p==="json_object"?(r.responseSchema={type:"object"},delete r.response_format):p==="text"&&delete r.response_format;}return S(S({generation_config:r},l?{tool_config:l}:{}),d?{safety_settings:d}:{})}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let t=r=>{let d=r.match(/^data:(image\/[a-zA-Z]+|application\/pdf);base64,/);return d?r.substring(d[0].length):r},i=e.map(r=>{let d=Ct().safeParse(r);if(!d.success)throw new E({info:"Invalid messages",cause:d.error});return d.data});i.forEach(r=>{r.content.forEach(d=>{if(!this.modelSchema.modalities.includes(d.modality))throw new E({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${d.modality}',
12
+ available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),i.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new E({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}',
13
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let n={parts:[]},a=[];if(i.forEach(r=>{switch(r.role){case ve:r.content.forEach(d=>{if(d.modality===A)n.parts.push({text:d.value});else throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})});break;case R:{let d=[];r.content.forEach(l=>{if(l.modality===A)d.push({text:l.value});else if(l.modality===V)d.push({function_call:{name:l.name,args:JSON.parse(l.arguments)}});else throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:d});}break;case Z:{let d=[];r.content.forEach(l=>{if(l.modality===A)d.push({text:l.value});else if(l.modality===le){if(l.value.type==="base64"){let p=l.value.base64;p=t(p),d.push({inline_data:{mime_type:`image/${l.value.mediaType}`,data:p}});}else if(l.value.type==="url")throw new E({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${l.value.type}'`)})}else if(l.modality===ue)if(l.value.type==="base64"){let p=l.value.base64;p=t(p),d.push({inline_data:{mime_type:"application/pdf",data:p}});}else l.value.type==="url"&&d.push({file_data:{mime_type:"application/pdf",file_uri:l.value.url}});else throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:d});}break;case re:{let d=[];r.content.forEach(l=>{if(l.modality===me)d.push({function_response:{name:l.name,response:JSON.parse(l.data)}});else throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:d});}break;default:throw new E({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
14
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),a[0].role!==this.modelSchema.roles[Z])throw new E({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=r=>r===this.modelSchema.roles[Z]||r===this.modelSchema.roles[re]?[this.modelSchema.roles[R]]:[this.modelSchema.roles[Z],this.modelSchema.roles[re]];for(let r=1;r<a.length;r++)if(!m(a[r-1].role).includes(a[r].role))throw new E({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${a[r].role}' after message with role : '${a[r-1].role}'`)});if(a[a.length-1].role!==this.modelSchema.roles[Z]&&a[a.length-1].role!==this.modelSchema.roles[re])throw new E({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return S({contents:a},n.parts.length>0?{system_instruction:n}:{})}stripAdditionalProperties(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(i=>this.stripAdditionalProperties(i));let t={};for(let[i,n]of Object.entries(e))i!=="additionalProperties"&&(t[i]=this.stripAdditionalProperties(n));return t}transformTools(e,t){if(!this.modelSchema.modalities.includes(V))throw new Ft({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${V}'`)});if((!e||e.length===0)&&!(t!=null&&t.googleSearchTool))return {tools:[]};let i=(e!=null?e:[]).map(n=>{let a=ki().safeParse(n);if(!a.success)throw new Ft({info:"Invalid tools",cause:a.error});return a.data}).map(n=>({name:n.definition.schema.name,description:n.definition.schema.description,parameters:this.stripAdditionalProperties(n.definition.schema.parameters)}));return {tools:[S(S({},i.length>0?{function_declarations:i}:{}),t!=null&&t.googleSearchTool?{google_search:{}}:{})]}}getCompleteChatUrl(e,t,i){return j(this,null,function*(){return new Promise(n=>{n(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,i){return j(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getCompleteChatData(e,t,i){return j(this,null,function*(){let n=this.transformConfig(e,t,i),a=yield this.transformPdfMessages(t),m=this.transformMessages(a);if(m.messages&&m.messages.length===0)throw new E({info:"Messages are required",cause:new Error("Messages are required")});let r=this.transformTools(i||[],e);return S(S(S(S({},this.getDefaultParams()),n),m),r)})}transformCompleteChatResponse(e){var t,i,n,a,m,r;let d=Or.safeParse(e);if(d.success){if(d.data.candidates.length===0)throw new z({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(d.data)}`)});let l={messages:[],usage:void 0,logProbs:void 0},p=d.data;p.usageMetadata&&(l.usage={promptTokens:p.usageMetadata.promptTokenCount,totalTokens:p.usageMetadata.totalTokenCount,completionTokens:p.usageMetadata.candidatesTokenCount||0});let g=p.candidates[0];if(g.content){let u=g.content.parts.map((h,f)=>{if("text"in h&&h.text!==void 0)return xi(h.text);if("functionCall"in h&&h.functionCall!==void 0)return Si(f,`${h.functionCall.name}_${f}`,h.functionCall.name,JSON.stringify(h.functionCall.args))});l.messages.push({role:R,content:u});}g.groundingMetadata&&(l.messages.length===0?l.messages.push({role:R,content:[It(((t=g.groundingMetadata.webSearchQueries)==null?void 0:t[0])||"",((i=g.groundingMetadata.groundingChunks)==null?void 0:i.map(u=>{var h,f;return {source:u.web?"web":"",url:((h=u.web)==null?void 0:h.uri)||"",title:((f=u.web)==null?void 0:f.title)||""}}))||[],((n=g.groundingMetadata.groundingSupports)==null?void 0:n.map(u=>{var h,f,k;return {text:((h=u.segment)==null?void 0:h.text)||"",responseIndices:u.groundingChunkIndices||[],startIndex:((f=u.segment)==null?void 0:f.startIndex)||void 0,endIndex:((k=u.segment)==null?void 0:k.endIndex)||void 0,confidenceScores:u.confidenceScores||void 0}}))||[])]}):l.messages[0].content.push(It(((a=g.groundingMetadata.webSearchQueries)==null?void 0:a[0])||"",((m=g.groundingMetadata.groundingChunks)==null?void 0:m.map(u=>{var h,f;return {source:u.web?"web":"",url:((h=u.web)==null?void 0:h.uri)||"",title:((f=u.web)==null?void 0:f.title)||""}}))||[],((r=g.groundingMetadata.groundingSupports)==null?void 0:r.map(u=>{var h,f,k;return {text:((h=u.segment)==null?void 0:h.text)||"",responseIndices:u.groundingChunkIndices||[],startIndex:((f=u.segment)==null?void 0:f.startIndex)||void 0,endIndex:((k=u.segment)==null?void 0:k.endIndex)||void 0,confidenceScores:u.confidenceScores||void 0}}))||[])));let y=g.safetyRatings;if(y&&y.length>0&&y.forEach(u=>{u.blocked&&(l.messages.length===0?l.messages.push({role:R,content:[Gt(u.category,u.probability,u.blocked,`Blocked content for category: ${u.category} with probability: ${u.probability}`)]}):l.messages[0].content.push(Gt(u.category,u.probability,u.blocked,`Blocked content for category: ${u.category} with probability: ${u.probability}`)));}),l.messages.length>0)return l;if(l.messages.length===0&&g.finishReason==="SAFETY")throw new z({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new z({info:"Invalid response from model",cause:d.error})}getStreamChatUrl(e,t,i){return j(this,null,function*(){return new Promise(n=>{n(this.streamChatUrl);})})}getStreamChatHeaders(e,t,i){return j(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getStreamChatData(e,t,i){return j(this,null,function*(){let n=this.transformConfig(e,t,i),a=yield this.transformPdfMessages(t),m=this.transformMessages(a);if(m.messages&&m.messages.length===0)throw new E({info:"Messages are required",cause:new Error("Messages are required")});let r=this.transformTools(i||[],e);return S(S(S(S({},this.getDefaultParams()),n),m),r)})}transformStreamChatResponseChunk(e,t){return sn(this,null,function*(){var i,n,a;let m=(t+e).split(",\r").filter(r=>r.trim()!=="");for(let r of m){let d=r;if(d=d.replace(/\n/g,""),d.startsWith("[")||d.startsWith(",{"))d=d.slice(1);else if(d.endsWith("]")){if(d==="]")return;d=d.slice(0,-1);}let l;try{l=JSON.parse(d);}catch(g){if(g instanceof SyntaxError){t=d;continue}else throw g}t="";let p=rn.safeParse(l);if(p.success){let g={partialMessages:[]},y=p.data;if(y.candidates.length>0){let u=y.candidates[0].content;u&&"parts"in u&&u.parts.length>0&&u.parts.forEach((h,f)=>{if("text"in h&&h.text!==void 0&&g.partialMessages.push(wt(R,h.text)),"functionCall"in h&&h.functionCall!==void 0){let k=h.functionCall;g.partialMessages.push(Ot(R,f,`${k.name}_${f}`,k.name,JSON.stringify(k.args)));}});}if(y.usageMetadata&&(g.usage={promptTokens:y.usageMetadata.promptTokenCount,completionTokens:y.usageMetadata.candidatesTokenCount,totalTokens:y.usageMetadata.totalTokenCount}),y.candidates.length>0){let u=y.candidates[0];u.groundingMetadata&&g.partialMessages.push(jt(R,((i=u.groundingMetadata.webSearchQueries)==null?void 0:i[0])||"",((n=u.groundingMetadata.groundingChunks)==null?void 0:n.map(f=>{var k,G;return {source:f.web?"web":"",url:((k=f.web)==null?void 0:k.uri)||"",title:((G=f.web)==null?void 0:G.title)||""}}))||[],((a=u.groundingMetadata.groundingSupports)==null?void 0:a.map(f=>{var k,G,q;return {text:((k=f.segment)==null?void 0:k.text)||"",responseIndices:f.groundingChunkIndices||[],startIndex:((G=f.segment)==null?void 0:G.startIndex)||void 0,endIndex:((q=f.segment)==null?void 0:q.endIndex)||void 0,confidenceScores:f.confidenceScores||void 0}}))||[]));let h=u.safetyRatings;h&&h.length>0&&h.forEach(f=>{f.blocked&&g.partialMessages.push(Rt(R,f.category,f.probability,f.blocked,`Blocked content for category: ${f.category} with probability: ${f.probability}`));});}yield {partialResponse:g,buffer:t};}else throw new z({info:"Invalid response from model",cause:p.error})}yield {partialResponse:{partialMessages:[]},buffer:t};})}transformProxyStreamChatResponseChunk(e,t,i,n,a){return sn(this,null,function*(){var m,r,d;if((a==null?void 0:a.alt)!=="sse"){yield*oi(cr(this.transformStreamChatResponseChunk(e,t)));return}let l=t+e,p=[],g="",y=0;for(;y<l.length;){let u=l.indexOf(`
15
+ `,y);if(u===-1){g=l.substring(y);break}else {let h=l.substring(y,u).trim();h&&p.push(h),y=u+1;}}for(let u of p){if(u==="data: [DONE]")return;if(u.startsWith("data: ")){let h=u.substring(6);try{let f=JSON.parse(h),k=rn.safeParse(f);if(k.success){let G={partialMessages:[]},q=k.data;if(q.candidates.length>0){let J=q.candidates[0].content;J&&"parts"in J&&J.parts.length>0&&J.parts.forEach((W,C)=>{if("text"in W&&W.text!==void 0&&G.partialMessages.push(wt(R,W.text)),"functionCall"in W&&W.functionCall!==void 0){let oe=W.functionCall;G.partialMessages.push(Ot(R,C,`${oe.name}_${C}`,oe.name,JSON.stringify(oe.args)));}});}if(q.usageMetadata&&q.usageMetadata.totalTokenCount&&q.usageMetadata.promptTokenCount&&q.usageMetadata.candidatesTokenCount&&(G.usage={promptTokens:q.usageMetadata.promptTokenCount,completionTokens:q.usageMetadata.candidatesTokenCount,totalTokens:q.usageMetadata.totalTokenCount}),q.candidates.length>0){let J=q.candidates[0];J.groundingMetadata&&G.partialMessages.push(jt(R,((m=J.groundingMetadata.webSearchQueries)==null?void 0:m[0])||"",((r=J.groundingMetadata.groundingChunks)==null?void 0:r.map(C=>{var oe,Me;return {source:C.web?"web":"",url:((oe=C.web)==null?void 0:oe.uri)||"",title:((Me=C.web)==null?void 0:Me.title)||""}}))||[],((d=J.groundingMetadata.groundingSupports)==null?void 0:d.map(C=>{var oe,Me,Qo;return {text:((oe=C.segment)==null?void 0:oe.text)||"",responseIndices:C.groundingChunkIndices||[],startIndex:((Me=C.segment)==null?void 0:Me.startIndex)||void 0,endIndex:((Qo=C.segment)==null?void 0:Qo.endIndex)||void 0,confidenceScores:C.confidenceScores||void 0}}))||[]));let W=J.safetyRatings;W&&W.length>0&&W.forEach(C=>{C.blocked&&G.partialMessages.push(Rt(R,C.category,C.probability,C.blocked,`Blocked content for category: ${C.category} with probability: ${C.probability}`));});}yield {partialResponse:G,buffer:t};}else throw new z({info:"Invalid response from model",cause:k.error})}catch(f){throw new z({info:`Malformed JSON received in stream: ${h}`,cause:f})}}}yield {partialResponse:{partialMessages:[]},buffer:g};})}getProxyCompleteChatUrl(e,t,i){return j(this,null,function*(){return new Promise(n=>{n(this.completeChatUrl);})})}getProxyStreamChatUrl(e,t,i){return j(this,null,function*(){return new Promise(n=>{if(!i||Object.keys(i).length===0){n(this.streamChatUrl);return}let a=new URL(this.streamChatUrl);Object.entries(i).forEach(([m,r])=>{r!=null&&a.searchParams.set(m,r);}),n(a.toString());})})}getProxyCompleteChatHeaders(e,t,i){return j(this,null,function*(){if(!t)return {};let n=S({},t);return delete n.host,delete n["content-length"],n})}getProxyStreamChatHeaders(e,t,i){return j(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,i)})}getModelPricing(){if(!(this.modelName in O))throw new z({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return O[this.modelName]}},zt="gemini-1.5-flash-001",Ar="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=I(N,D).parse({name:zt,description:Ar,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[zt]}),Br=$,qr=class extends F{constructor(e){super(je,e);}},Ht="gemini-1.5-flash-002",zr="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",Fe=I(N,D).parse({name:Ht,description:zr,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[Ht]}),Hr=$,Vr=class extends F{constructor(e){super(Fe,e);}},Vt="gemini-1.5-flash-latest",Kr="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Ne=I(N,D).parse({name:Vt,description:Kr,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[Vt]}),Yr=$,Jr=class extends F{constructor(e){super(Ne,e);}},Kt="gemini-1.5-flash",Wr="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",Le=I(N,D).parse({name:Kt,description:Wr,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[Kt]}),Xr=$,Zr=class extends F{constructor(e){super(Le,e);}},Yt="gemini-1.5-pro-001",Qr="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ue=I(N,D).parse({name:Yt,description:Qr,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[Yt]}),el=$,tl=class extends F{constructor(e){super(Ue,e);}},Jt="gemini-1.5-pro-002",ol="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",De=I(N,D).parse({name:Jt,description:ol,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[Jt]}),il=$,nl=class extends F{constructor(e){super(De,e);}},Wt="gemini-1.5-pro-latest",al="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",$e=I(N,D).parse({name:Wt,description:al,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[Wt]}),sl=$,rl=class extends F{constructor(e){super($e,e);}},Xt="gemini-1.5-pro",ll="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ae=I(N,D).parse({name:Xt,description:ll,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[Xt]}),ml=$,dl=class extends F{constructor(e){super(Ae,e);}},pn="gemini-2.0-flash-exp",cl="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",Rn=I(N,D).parse({name:pn,description:cl,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[pn]});var Zt="gemini-2.0-flash",pl="Google's Gemini 2.0 Flash model optimized for low-latency, high-performance tasks. Supports multimodal inputs including text, images, video, and audio with enhanced speed and efficiency.",Be=I(N,D).parse({name:Zt,description:pl,maxInputTokens:1048576,maxOutputTokens:8192,roles:L,modalities:U,config:{def:_.responseSchema(2,1,8192,4,.95).def,schema:_.responseSchema(2,1,8192,4,.95).schema},price:O[Zt]}),ul=$,gl=class extends F{constructor(e){super(Be,e);}},Qt="gemini-2.5-flash-lite",hl="Google's most cost-efficient and fastest model in the 2.5 series. Optimized for high-volume, latency-sensitive tasks like translation and classification with enhanced reasoning capabilities.",qe=I(N,D).parse({name:Qt,description:hl,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:_.responseSchema(2,1,65536,4,.95).def,schema:_.responseSchema(2,1,65536,4,.95).schema},price:O[Qt]}),fl=$,yl=class extends F{constructor(e){super(qe,e);}},eo="gemini-2.5-flash-preview-04-17",bl="Google's best model in Gemini 2.5 family in terms of price-performance, offering well-rounded capabilities.",ze=I(N,D).parse({name:eo,description:bl,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:_.responseSchema(2,1,65536,4,.95).def,schema:_.responseSchema(2,1,65536,4,.95).schema},price:O[eo]}),Tl=$,Pl=class extends F{constructor(e){super(ze,e);}},to="gemini-2.5-flash",Ml="Google's Gemini 2.5 Flash model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",He=I(N,D).parse({name:to,description:Ml,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:_.responseSchema(2,1,65536,4,.95).def,schema:_.responseSchema(2,1,65536,4,.95).schema},price:O[to]}),vl=$,_l=class extends F{constructor(e){super(He,e);}},oo="gemini-2.5-pro-preview-03-25",kl="Google's preview model in Gemini 2.5 family for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Ve=I(N,D).parse({name:oo,description:kl,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:_.reasoning(2,1,65536,4,.95).def,schema:_.reasoning(2,1,65536,4,.95).schema},price:O[oo]}),xl=$,Sl=class extends F{constructor(e){super(Ve,e);}},io="gemini-2.5-pro",El="Google's Gemini 2.5 Pro model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Ke=I(N,D).parse({name:io,description:El,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:_.reasoning(2,1,65536,4,.95).def,schema:_.reasoning(2,1,65536,4,.95).schema},price:O[io]}),Cl=$,wl=class extends F{constructor(e){super(Ke,e);}},no="gemini-3-flash-preview",Ol="Google's Gemini 3 Flash Preview model - a lightweight and efficient AI model with enhanced multimodal understanding, reasoning, and advanced coding capabilities. Optimized for speed and cost-effectiveness. Supports Text, Image, Video, Audio, and PDF inputs. Knowledge cutoff: January 2025.",Ye=I(N,D).parse({name:no,description:Ol,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:_.reasoning(2,1,65536,4,.95).def,schema:_.reasoning(2,1,65536,4,.95).schema},price:O[no]}),Gl=$,Rl=class extends F{constructor(e){super(Ye,e);}},ao="gemini-3-pro-preview",Il="Google's latest Gemini 3 Pro Preview model with enhanced multimodal understanding, reasoning, and thinking capabilities. Supports Text, Image, Video, Audio, and PDF inputs. Knowledge cutoff: January 2025.",Je=I(N,D).parse({name:ao,description:Il,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:_.reasoning(2,1,65536,4,.95).def,schema:_.reasoning(2,1,65536,4,.95).schema},price:O[ao]}),jl=$,Fl=class extends F{constructor(e){super(Je,e);}},In=[B],jn=zod.z.enum([B]),Nl=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),Ll=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)})}),Ul=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(Ll).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),ro=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),Fn=class{constructor(e,t){this.version="v1";let i=ro.parse(t);this.modelSchema=e,this.modelName=i.modelName,this.apiKey=i.apiKey,this.baseUrl=Pe(i.baseUrl||so.baseUrl),this.getEmbeddingsUrl=Pe(i.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,i)=>t+i.length,0)}transformModelRequest(e){let t=Ul.safeParse(e);if(!t.success)throw new ne({info:"Invalid model request",cause:t.error});let i=t.data,n=i.model,a={outputDimensionality:i.outputDimensionality},m=ke().parse(Ee(a)),r={modality:B,requests:i.requests.reduce((d,l)=>(d.push(...l.content.parts.map(p=>p.text)),d),[])};return {modelName:n,config:m,embeddingRequests:r}}transformConfig(e,t){let i=this.modelSchema.config.schema.safeParse(e);if(!i.success)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:i.error});let n=i.data;return Object.keys(n).forEach(a=>{if(!this.modelSchema.config.def[a])throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${a}',
16
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(n).reduce((a,m)=>{let r=this.modelSchema.config.def[m].param,d=n[m];return a[r]=d,a},{})}transformEmbeddingRequests(e){let t=Ge().safeParse(e);if(!t.success)throw new de({info:"Invalid embedding requests",cause:t.error});if(e.modality!==B)throw new de({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${B}' 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 j(this,null,function*(){return new Promise(i=>{i(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return j(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return j(this,null,function*(){return new Promise(i=>{let n=this.transformConfig(e),a=this.transformEmbeddingRequests(t);if(t.requests.length===0)throw new de({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});n.outputDimensionality&&(a.requests.forEach(m=>{m.outputDimensionality=n.outputDimensionality;}),delete n.outputDimensionality),i(S(S(S({},this.getDefaultParams()),n),a));})})}transformGetEmbeddingsResponse(e){let t=Nl.safeParse(e);if(t.success){let i=t.data.embeddings.map((n,a)=>({index:a,embedding:n.values}));return {encodingFormat:xe,embeddings:i}}throw new z({info:"Invalid response from model",cause:t.error})}},Nn="text-embedding-001",Dl="text-embedding-001",Ln=Y(jn).parse({name:Nn,description:Dl,modalities:In,maxInputTokens:2048,maxOutputTokens:768,config:{def:Ie.base(768).def,schema:Ie.base(768).schema}}),$l=ro,Al=class extends Fn{constructor(e){super(Ln,e);}},Un="text-embedding-004",Bl="text-embedding-004",Dn=Y(jn).parse({name:Un,description:Bl,modalities:In,maxInputTokens:2048,maxOutputTokens:768,config:{def:Ie.base(768).def,schema:Ie.base(768).schema}}),ql=ro,zl=class extends Fn{constructor(e){super(Dn,e);}};var Hl="vertex",ge=class{constructor(){this.version="v1";this.name=Hl;this.chatModelFactories={[lo]:{model:We,modelOptions:$n,modelSchema:mo},[co]:{model:Xe,modelOptions:An,modelSchema:po},[Mo]:{model:ot,modelOptions:Vn,modelSchema:vo},[uo]:{model:Ze,modelOptions:Bn,modelSchema:go},[ho]:{model:Qe,modelOptions:qn,modelSchema:fo},[yo]:{model:et,modelOptions:zn,modelSchema:bo},[_o]:{model:it,modelOptions:Kn,modelSchema:ko},[To]:{model:tt,modelOptions:Hn,modelSchema:Po},[xo]:{model:nt,modelOptions:Yn,modelSchema:So},[Eo]:{model:at,modelOptions:Jn,modelSchema:Co},[wo]:{model:st,modelOptions:Wn,modelSchema:Oo},[Go]:{model:rt,modelOptions:Xn,modelSchema:Ro},[Fo]:{model:mt,modelOptions:Qn,modelSchema:No},[Io]:{model:lt,modelOptions:Zn,modelSchema:jo},[Lo]:{model:dt,modelOptions:ea,modelSchema:Uo},[Do]:{model:ct,modelOptions:ta,modelSchema:$o},[Ao]:{model:pt,modelOptions:oa,modelSchema:Bo}};this.embeddingModelFactories={[qo]:{model:ut,modelOptions:ia,modelSchema:zo},[Ho]:{model:gt,modelOptions:na,modelSchema:Vo},[Jo]:{model:ft,modelOptions:sa,modelSchema:Wo},[Ko]:{model:ht,modelOptions:aa,modelSchema:Yo}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,i)=>(t[i]=this.chatModelFactories[i].modelSchema,t),{})}chatModel(t){let i=t.modelName;if(!(i in this.chatModelFactories))throw new ye({info:`Vertex chat model: ${i} not found`,cause:new Error(`Vertex chat model: ${i} not found, available chat models:
17
+ ${this.chatModelLiterals().join(", ")}`)});let n=this.chatModelFactories[i].model,a=this.chatModelFactories[i].modelOptions.parse(t);return new n(a)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,i)=>(t[i]=this.embeddingModelFactories[i].modelSchema,t),{})}embeddingModel(t){let i=t.modelName;if(!(i in this.embeddingModelFactories))throw new ye({info:`Vertex embedding model: ${i} not found`,cause:new Error(`Vertex embedding model: ${i} not found, available embedding models:
18
+ ${this.embeddingModelLiterals().join(", ")}`)});let n=this.embeddingModelFactories[i].model,a=this.embeddingModelFactories[i].modelOptions.parse(t);return new n(a)}};ge.baseUrl=(t,i,n="google")=>`https://${t}-aiplatform.googleapis.com/v1/projects/${i}/locations/${t}/publishers/${n}`;var T={"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-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":{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":{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:.15,outputPricePerMillion:.6}}}]},"gemini-2.0-flash":{modelName:"gemini-2.0-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-2.5-flash-lite":{modelName:"gemini-2.5-flash-lite",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-1.5-flash-latest":{modelName:"gemini-1.5-flash-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.01875,outputPricePerMillion:.075}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.0375,outputPricePerMillion:.15}}}]},"gemini-1.5-pro-latest":{modelName:"gemini-1.5-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.3125,outputPricePerMillion:1.25}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.625,outputPricePerMillion:2.5}}}]},"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:.5,outputPricePerMillion:2}}}]},"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-2.5-flash":{modelName:"gemini-2.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.3,outputPricePerMillion:2.5}}}]},"gemini-2.5-pro":{modelName:"gemini-2.5-pro",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-3-pro-preview":{modelName:"gemini-3-pro-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:2,outputPricePerMillion:12}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:4,outputPricePerMillion:18}}}]},"gemini-3-flash-preview":{modelName:"gemini-3-flash-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:3}}}]}};var v=zod.z.discriminatedUnion("authType",[zod.z.object({authType:zod.z.literal("accessToken"),accessToken:zod.z.string(),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional()}),zod.z.object({authType:zod.z.literal("serviceAccount"),serviceAccount:zod.z.object({client_email:zod.z.string().email(),private_key:zod.z.string(),type:zod.z.string().optional(),project_id:zod.z.string().optional(),private_key_id:zod.z.string().optional(),client_id:zod.z.string().optional(),auth_uri:zod.z.string().url().optional(),token_uri:zod.z.string().url().optional(),auth_provider_x509_cert_url:zod.z.string().url().optional(),client_x509_cert_url:zod.z.string().url().optional(),universe_domain:zod.z.string().optional()}),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional(),tokenLifetimeHours:zod.z.number().min(.1).max(24).default(1)})]),M=class extends F{constructor(i,n){let a=v.parse(n),m;if(a.baseUrl)m=a.baseUrl;else if(a.location&&a.projectId)m=ge.baseUrl(a.location,a.projectId,a.publisher);else throw new be({info:"Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided",cause:new Error("Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided")});super(i,{modelName:a.modelName,apiKey:"random-api-key",completeChatUrl:`${m}/models/${a.modelName}:generateContent`,streamChatUrl:`${m}/models/${a.modelName}:streamGenerateContent`});this.version="v1";this.accessToken=null;this.tokenExpiry=null;this.modelSchema=i,this.modelName=a.modelName,this.authOptions=a,this.location=a.location,this.projectId=a.projectId,this.publisher=a.publisher,a.authType==="accessToken"&&(this.accessToken=a.accessToken);}getAccessToken(){return X(this,null,function*(){if(this.accessToken&&this.tokenExpiry&&Date.now()<this.tokenExpiry)return this.accessToken;if(this.authOptions.authType==="serviceAccount")try{let i=this.authOptions.serviceAccount,n=Math.floor(Date.now()/1e3),a=yield new jose.SignJWT({scope:"https://www.googleapis.com/auth/cloud-platform",aud:"https://oauth2.googleapis.com/token"}).setProtectedHeader({alg:"RS256",typ:"JWT"}).setIssuedAt(n).setExpirationTime(n+this.authOptions.tokenLifetimeHours*3600).setIssuer(i.client_email).setSubject(i.client_email).sign(yield this.importPrivateKey(i.private_key)),m=yield fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:a})});if(!m.ok){let d=yield m.text();throw new Error(`Token exchange failed: ${m.status} ${d}`)}let r=yield m.json();if(!r.access_token)throw new Error(`No access token received from Google OAuth: ${r.error||"Unknown error"}`);return this.tokenExpiry=Date.now()+this.authOptions.tokenLifetimeHours*3600*1e3-5*60*1e3,this.accessToken=r.access_token,this.accessToken}catch(i){throw new be({info:`Failed to generate service account token: ${i instanceof Error?i.message:String(i)}`,cause:i instanceof Error?i:new Error(String(i))})}if(this.accessToken)return this.accessToken;throw new be({info:"No valid access token available",cause:new Error("No valid access token available")})})}importPrivateKey(i){return X(this,null,function*(){let n=i.replace(/-----BEGIN PRIVATE KEY-----/,"").replace(/-----END PRIVATE KEY-----/,"").replace(/\s/g,""),a=atob(n),m=new Uint8Array(a.length);for(let r=0;r<a.length;r++)m[r]=a.charCodeAt(r);return yield crypto.subtle.importKey("pkcs8",m,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])})}ensureToken(){return X(this,null,function*(){this.authOptions.authType==="serviceAccount"&&(yield this.getAccessToken());})}getDefaultHeaders(){return P(b({},super.getDefaultHeaders()),{Authorization:`Bearer ${this.accessToken}`})}getCompleteChatHeaders(i,n,a){return X(this,null,function*(){return yield this.ensureToken(),this.getDefaultHeaders()})}getStreamChatHeaders(i,n,a){return X(this,null,function*(){return yield this.ensureToken(),this.getDefaultHeaders()})}getModelPricing(){if(!(this.modelName in T))throw new z({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return T[this.modelName]}};var lo="gemini-1.5-flash-001",mo=P(b({},je),{price:T[lo]}),$n=v,We=class extends M{constructor(t){super(mo,t);}};var co="gemini-1.5-flash-002",po=P(b({},Fe),{price:T[co]}),An=v,Xe=class extends M{constructor(t){super(po,t);}};var uo="gemini-1.5-flash",go=P(b({},Le),{price:T[uo]}),Bn=v,Ze=class extends M{constructor(t){super(go,t);}};var ho="gemini-1.5-pro-001",fo=P(b({},Ue),{price:T[ho]}),qn=v,Qe=class extends M{constructor(t){super(fo,t);}};var yo="gemini-1.5-pro-002",bo=P(b({},De),{price:T[yo]}),zn=v,et=class extends M{constructor(t){super(bo,t);}};var To="gemini-1.5-pro",Po=P(b({},Ae),{price:T[To]}),Hn=v,tt=class extends M{constructor(t){super(Po,t);}};var Mo="gemini-1.5-flash-latest",vo=P(b({},Ne),{price:T[Mo]}),Vn=v,ot=class extends M{constructor(t){super(vo,t);}};var _o="gemini-1.5-pro-latest",ko=P(b({},$e),{price:T[_o]}),Kn=v,it=class extends M{constructor(t){super(ko,t);}};var xo="gemini-2.0-flash-exp",So=P(b({},Rn),{price:T[xo]}),Yn=v,nt=class extends M{constructor(t){super(So,t);}};var Eo="gemini-2.0-flash",Co=P(b({},Be),{price:T[Eo]}),Jn=v,at=class extends M{constructor(t){super(Co,t);}};var wo="gemini-2.5-flash-lite",Oo=P(b({},qe),{price:T[wo]}),Wn=v,st=class extends M{constructor(t){super(Oo,t);}};var Go="gemini-2.5-flash-preview-04-17",Ro=P(b({},ze),{price:T[Go]}),Xn=v,rt=class extends M{constructor(t){super(Ro,t);}};var Io="gemini-2.5-flash",jo=P(b({},He),{price:T[Io]}),Zn=v,lt=class extends M{constructor(t){super(jo,t);}};var Fo="gemini-2.5-pro-preview-03-25",No=P(b({},Ve),{price:T[Fo]}),Qn=v,mt=class extends M{constructor(t){super(No,t);}};var Lo="gemini-2.5-pro",Uo=P(b({},Ke),{price:T[Lo]}),ea=v,dt=class extends M{constructor(t){super(Uo,t);}};var Do="gemini-3-flash-preview",$o=P(b({},Ye),{price:T[Do]}),ta=v,ct=class extends M{constructor(t){super($o,t);}};var Ao="gemini-3-pro-preview",Bo=P(b({},Je),{price:T[Ao]}),oa=v,pt=class extends M{constructor(t){super(Bo,t);}};var ce=[B],pe=zod.z.enum([B]);var ra=zod.z.object({predictions:zod.z.array(zod.z.object({embeddings:zod.z.object({values:zod.z.array(zod.z.number()),statistics:zod.z.object({token_count:zod.z.number(),truncated:zod.z.boolean()})})}))});var la=zod.z.object({model:zod.z.string().min(1).optional(),instances:zod.z.array(zod.z.object({content:zod.z.string().min(1)})).min(1),parameters:zod.z.object({auto_truncate:zod.z.boolean().optional(),output_dimensionality:zod.z.number().int().min(1).optional(),autoTruncate:zod.z.boolean().optional(),outputDimensionality:zod.z.number().int().min(1).optional()}).optional()});var se=zod.z.object({accessToken:zod.z.string(),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional()}),te=class{constructor(t,i){this.version="v1";let n=se.parse(i);this.modelSchema=t,this.modelName=n.modelName,this.accessToken=n.accessToken;let a;if(n.baseUrl)a=n.baseUrl;else if(n.location&&n.projectId)a=ge.baseUrl(n.location,n.projectId,n.publisher);else throw new be({info:"Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided",cause:new Error("Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided")});this.baseUrl=a,this.getEmbeddingsUrl=`${this.baseUrl}/models/${n.modelName}:predict`,this.location=n.location,this.projectId=n.projectId;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`}}getDefaultParams(){return {}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.requests.reduce((i,n)=>i+n.length,0)}transformModelRequest(t){var l,p,g,y;let i=la.safeParse(t);if(!i.success)throw new ne({info:"Invalid model request",cause:i.error});let n=i.data,a=n.model,m={autoTruncate:((l=n.parameters)==null?void 0:l.auto_truncate)||((p=n.parameters)==null?void 0:p.autoTruncate),dimensions:((g=n.parameters)==null?void 0:g.output_dimensionality)||((y=n.parameters)==null?void 0:y.outputDimensionality)},r=ke().parse(Ee(m)),d={modality:B,requests:n.instances.map(u=>u.content)};return {modelName:a,config:r,embeddingRequests:d}}transformConfig(t,i){let n=this.modelSchema.config.schema.safeParse(t);if(!n.success)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let a=n.data;return Object.keys(a).forEach(r=>{if(!this.modelSchema.config.def[r])throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${r}',
19
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),{parameters:Object.keys(a).reduce((r,d)=>{let p=this.modelSchema.config.def[d].param,g=a[d];return r[p]=g,r},{})}}transformEmbeddingRequests(t){let i=Ge().safeParse(t);if(!i.success)throw new de({info:"Invalid embedding requests",cause:i.error});if(t.modality!==B)throw new de({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${B}' modality is supported for model : '${this.modelName}'`)});return {instances:i.data.requests.map(a=>({content:a}))}}getGetEmbeddingsUrl(t,i){return X(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,i){return X(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,i){return X(this,null,function*(){return new Promise(n=>{if(i.requests.length===0)throw new de({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});n(b(b(b({},this.getDefaultParams()),this.transformConfig(t)),this.transformEmbeddingRequests(i)));})})}transformGetEmbeddingsResponse(t){let i=ra.safeParse(t);if(i.success){let a=i.data.predictions.map((m,r)=>({index:r,embedding:m.embeddings.values}));return {encodingFormat:xe,embeddings:a}}throw new z({info:"Invalid response from model",cause:i.error})}};var Xo=e=>Q({param:"output_dimensionality",title:Te.DIMENSIONS.title,description:Te.DIMENSIONS.description,min:1,max:e,step:1,default:e}),Zo=Se({param:"auto_truncate",title:"Auto truncate",description:"When set to true, input text will be truncated. When set to false, an error is returned if the input text is longer than the maximum length supported by the model.",default:!0});var ma=e=>zod.z.object({dimensions:Xo(e).schema,autoTruncate:Zo.schema}),da=e=>({dimensions:Xo(e).def,autoTruncate:Zo.def});var H={base:e=>({def:da(e),schema:ma(e)})};var qo="text-embedding-004",Wl="text-embedding-004",zo=Y(pe).parse({name:qo,description:Wl,modalities:ce,maxInputTokens:2048,maxOutputTokens:768,config:{def:H.base(768).def,schema:H.base(768).schema}}),ia=se,ut=class extends te{constructor(t){super(zo,t);}};var Ho="text-multilingual-embedding-002",Xl="text-multilingual-embedding-002",Vo=Y(pe).parse({name:Ho,description:Xl,modalities:ce,maxInputTokens:2048,maxOutputTokens:768,config:{def:H.base(768).def,schema:H.base(768).schema}}),na=se,gt=class extends te{constructor(t){super(Vo,t);}};var Ko="textembedding-gecko-multilingual@001",Zl="textembedding-gecko-multilingual@001",Yo=Y(pe).parse({name:Ko,description:Zl,modalities:ce,maxInputTokens:2048,maxOutputTokens:768,config:{def:H.base(768).def,schema:H.base(768).schema}}),aa=se,ht=class extends te{constructor(t){super(Yo,t);}};var Jo="textembedding-gecko@003",Ql="textembedding-gecko@003",Wo=Y(pe).parse({name:Jo,description:Ql,modalities:ce,maxInputTokens:2048,maxOutputTokens:768,config:{def:H.base(768).def,schema:H.base(768).schema}}),sa=se,ft=class extends te{constructor(t){super(Wo,t);}};
20
20
 
21
- exports.BaseChatModelOptions = b;
22
- exports.BaseChatModelVertex = y;
23
- exports.BaseEmbeddingModel = Z;
24
- exports.BaseEmbeddingModelOptions = te;
25
- exports.Gemini1_5Flash = qe;
26
- exports.Gemini1_5Flash001 = Ae;
27
- exports.Gemini1_5Flash001Literal = Kt;
28
- exports.Gemini1_5Flash001Options = Tn;
29
- exports.Gemini1_5Flash001Schema = Yt;
30
- exports.Gemini1_5Flash002 = Be;
31
- exports.Gemini1_5Flash002Literal = Jt;
32
- exports.Gemini1_5Flash002Options = Pn;
33
- exports.Gemini1_5Flash002Schema = Wt;
34
- exports.Gemini1_5FlashLatest = Ke;
35
- exports.Gemini1_5FlashLatestLiteral = ai;
36
- exports.Gemini1_5FlashLatestOptions = xn;
37
- exports.Gemini1_5FlashLatestSchema = si;
38
- exports.Gemini1_5FlashLiteral = Zt;
39
- exports.Gemini1_5FlashOptions = Mn;
40
- exports.Gemini1_5FlashSchema = Xt;
41
- exports.Gemini1_5Pro = Ve;
42
- exports.Gemini1_5Pro001 = ze;
43
- exports.Gemini1_5Pro001Literal = Qt;
44
- exports.Gemini1_5Pro001Options = _n;
45
- exports.Gemini1_5Pro001Schema = ei;
46
- exports.Gemini1_5Pro002 = He;
47
- exports.Gemini1_5Pro002Literal = ti;
48
- exports.Gemini1_5Pro002Options = kn;
49
- exports.Gemini1_5Pro002Schema = ii;
50
- exports.Gemini1_5ProLatest = Ye;
51
- exports.Gemini1_5ProLatestLiteral = ri;
52
- exports.Gemini1_5ProLatestOptions = Sn;
53
- exports.Gemini1_5ProLatestSchema = li;
54
- exports.Gemini1_5ProLiteral = oi;
55
- exports.Gemini1_5ProOptions = vn;
56
- exports.Gemini1_5ProSchema = ni;
57
- exports.Gemini2_0Flash = We;
58
- exports.Gemini2_0FlashExp = Je;
59
- exports.Gemini2_0FlashExpLiteral = mi;
60
- exports.Gemini2_0FlashExpOptions = En;
61
- exports.Gemini2_0FlashExpSchema = di;
62
- exports.Gemini2_0FlashLiteral = ci;
63
- exports.Gemini2_0FlashOptions = Cn;
64
- exports.Gemini2_0FlashSchema = pi;
65
- exports.Gemini2_5Flash = Qe;
66
- exports.Gemini2_5FlashLite = Ze;
67
- exports.Gemini2_5FlashLiteLiteral = ui;
68
- exports.Gemini2_5FlashLiteOptions = On;
69
- exports.Gemini2_5FlashLiteSchema = gi;
70
- exports.Gemini2_5FlashLiteral = yi;
71
- exports.Gemini2_5FlashOptions = Gn;
72
- exports.Gemini2_5FlashPreview0417 = Xe;
73
- exports.Gemini2_5FlashPreview0417Literal = hi;
74
- exports.Gemini2_5FlashPreview0417Options = wn;
75
- exports.Gemini2_5FlashPreview0417Schema = fi;
76
- exports.Gemini2_5FlashSchema = bi;
77
- exports.Gemini2_5Pro = tt;
78
- exports.Gemini2_5ProLiteral = Mi;
79
- exports.Gemini2_5ProOptions = Fn;
80
- exports.Gemini2_5ProPreview0325 = et;
81
- exports.Gemini2_5ProPreview0325Literal = Ti;
82
- exports.Gemini2_5ProPreview0325Options = Rn;
83
- exports.Gemini2_5ProPreview0325Schema = Pi;
84
- exports.Gemini2_5ProSchema = _i;
85
- exports.Gemini3FlashPreview = it;
86
- exports.Gemini3FlashPreviewLiteral = ki;
87
- exports.Gemini3FlashPreviewOptions = In;
88
- exports.Gemini3FlashPreviewSchema = vi;
89
- exports.Gemini3ProPreview = ot;
90
- exports.Gemini3ProPreviewLiteral = xi;
91
- exports.Gemini3ProPreviewOptions = jn;
92
- exports.Gemini3ProPreviewSchema = Si;
93
- exports.Text_Embedding_004 = nt;
94
- exports.Text_Embedding_004Literal = Ei;
95
- exports.Text_Embedding_004Options = Ln;
96
- exports.Text_Embedding_004Schema = Ci;
97
- exports.Text_Embedding_Gecko_003 = rt;
98
- exports.Text_Embedding_Gecko_003Literal = Fi;
99
- exports.Text_Embedding_Gecko_003Options = Dn;
100
- exports.Text_Embedding_Gecko_003Schema = Ii;
101
- exports.Text_Embedding_Gecko_Multilingual_001 = st;
102
- exports.Text_Embedding_Gecko_Multilingual_001Literal = Gi;
103
- exports.Text_Embedding_Gecko_Multilingual_001Options = Un;
104
- exports.Text_Embedding_Gecko_Multilingual_001Schema = Ri;
105
- exports.Text_Multilingual_Embedding_002 = at;
106
- exports.Text_Multilingual_Embedding_002Literal = Oi;
107
- exports.Text_Multilingual_Embedding_002Options = Nn;
108
- exports.Text_Multilingual_Embedding_002Schema = wi;
109
- exports.Vertex = me;
21
+ exports.BaseChatModelOptions = v;
22
+ exports.BaseChatModelVertex = M;
23
+ exports.BaseEmbeddingModel = te;
24
+ exports.BaseEmbeddingModelOptions = se;
25
+ exports.Gemini1_5Flash = Ze;
26
+ exports.Gemini1_5Flash001 = We;
27
+ exports.Gemini1_5Flash001Literal = lo;
28
+ exports.Gemini1_5Flash001Options = $n;
29
+ exports.Gemini1_5Flash001Schema = mo;
30
+ exports.Gemini1_5Flash002 = Xe;
31
+ exports.Gemini1_5Flash002Literal = co;
32
+ exports.Gemini1_5Flash002Options = An;
33
+ exports.Gemini1_5Flash002Schema = po;
34
+ exports.Gemini1_5FlashLatest = ot;
35
+ exports.Gemini1_5FlashLatestLiteral = Mo;
36
+ exports.Gemini1_5FlashLatestOptions = Vn;
37
+ exports.Gemini1_5FlashLatestSchema = vo;
38
+ exports.Gemini1_5FlashLiteral = uo;
39
+ exports.Gemini1_5FlashOptions = Bn;
40
+ exports.Gemini1_5FlashSchema = go;
41
+ exports.Gemini1_5Pro = tt;
42
+ exports.Gemini1_5Pro001 = Qe;
43
+ exports.Gemini1_5Pro001Literal = ho;
44
+ exports.Gemini1_5Pro001Options = qn;
45
+ exports.Gemini1_5Pro001Schema = fo;
46
+ exports.Gemini1_5Pro002 = et;
47
+ exports.Gemini1_5Pro002Literal = yo;
48
+ exports.Gemini1_5Pro002Options = zn;
49
+ exports.Gemini1_5Pro002Schema = bo;
50
+ exports.Gemini1_5ProLatest = it;
51
+ exports.Gemini1_5ProLatestLiteral = _o;
52
+ exports.Gemini1_5ProLatestOptions = Kn;
53
+ exports.Gemini1_5ProLatestSchema = ko;
54
+ exports.Gemini1_5ProLiteral = To;
55
+ exports.Gemini1_5ProOptions = Hn;
56
+ exports.Gemini1_5ProSchema = Po;
57
+ exports.Gemini2_0Flash = at;
58
+ exports.Gemini2_0FlashExp = nt;
59
+ exports.Gemini2_0FlashExpLiteral = xo;
60
+ exports.Gemini2_0FlashExpOptions = Yn;
61
+ exports.Gemini2_0FlashExpSchema = So;
62
+ exports.Gemini2_0FlashLiteral = Eo;
63
+ exports.Gemini2_0FlashOptions = Jn;
64
+ exports.Gemini2_0FlashSchema = Co;
65
+ exports.Gemini2_5Flash = lt;
66
+ exports.Gemini2_5FlashLite = st;
67
+ exports.Gemini2_5FlashLiteLiteral = wo;
68
+ exports.Gemini2_5FlashLiteOptions = Wn;
69
+ exports.Gemini2_5FlashLiteSchema = Oo;
70
+ exports.Gemini2_5FlashLiteral = Io;
71
+ exports.Gemini2_5FlashOptions = Zn;
72
+ exports.Gemini2_5FlashPreview0417 = rt;
73
+ exports.Gemini2_5FlashPreview0417Literal = Go;
74
+ exports.Gemini2_5FlashPreview0417Options = Xn;
75
+ exports.Gemini2_5FlashPreview0417Schema = Ro;
76
+ exports.Gemini2_5FlashSchema = jo;
77
+ exports.Gemini2_5Pro = dt;
78
+ exports.Gemini2_5ProLiteral = Lo;
79
+ exports.Gemini2_5ProOptions = ea;
80
+ exports.Gemini2_5ProPreview0325 = mt;
81
+ exports.Gemini2_5ProPreview0325Literal = Fo;
82
+ exports.Gemini2_5ProPreview0325Options = Qn;
83
+ exports.Gemini2_5ProPreview0325Schema = No;
84
+ exports.Gemini2_5ProSchema = Uo;
85
+ exports.Gemini3FlashPreview = ct;
86
+ exports.Gemini3FlashPreviewLiteral = Do;
87
+ exports.Gemini3FlashPreviewOptions = ta;
88
+ exports.Gemini3FlashPreviewSchema = $o;
89
+ exports.Gemini3ProPreview = pt;
90
+ exports.Gemini3ProPreviewLiteral = Ao;
91
+ exports.Gemini3ProPreviewOptions = oa;
92
+ exports.Gemini3ProPreviewSchema = Bo;
93
+ exports.Text_Embedding_004 = ut;
94
+ exports.Text_Embedding_004Literal = qo;
95
+ exports.Text_Embedding_004Options = ia;
96
+ exports.Text_Embedding_004Schema = zo;
97
+ exports.Text_Embedding_Gecko_003 = ft;
98
+ exports.Text_Embedding_Gecko_003Literal = Jo;
99
+ exports.Text_Embedding_Gecko_003Options = sa;
100
+ exports.Text_Embedding_Gecko_003Schema = Wo;
101
+ exports.Text_Embedding_Gecko_Multilingual_001 = ht;
102
+ exports.Text_Embedding_Gecko_Multilingual_001Literal = Ko;
103
+ exports.Text_Embedding_Gecko_Multilingual_001Options = aa;
104
+ exports.Text_Embedding_Gecko_Multilingual_001Schema = Yo;
105
+ exports.Text_Multilingual_Embedding_002 = gt;
106
+ exports.Text_Multilingual_Embedding_002Literal = Ho;
107
+ exports.Text_Multilingual_Embedding_002Options = na;
108
+ exports.Text_Multilingual_Embedding_002Schema = Vo;
109
+ exports.Vertex = ge;
110
110
  //# sourceMappingURL=index.js.map
111
111
  //# sourceMappingURL=index.js.map