@adaline/vertex 1.4.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,24 +2,24 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
- var zn=Object.defineProperty,Vn=Object.defineProperties;var Kn=Object.getOwnPropertyDescriptors;var Wt=Object.getOwnPropertySymbols;var Yn=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable;var He=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Wn=t=>{throw TypeError(t)};var Xt=(t,e,o)=>e in t?zn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,b=(t,e)=>{for(var o in e||(e={}))Yn.call(e,o)&&Xt(t,o,e[o]);if(Wt)for(var o of Wt(e))Jn.call(e,o)&&Xt(t,o,e[o]);return t},E=(t,e)=>Vn(t,Kn(e));var Te=(t,e,o)=>new Promise((i,a)=>{var d=l=>{try{m(o.next(l));}catch(c){a(c);}},r=l=>{try{m(o.throw(l));}catch(c){a(c);}},m=l=>l.done?i(l.value):Promise.resolve(l.value).then(d,r);m((o=o.apply(t,e)).next());}),Xn=function(t,e){this[0]=t,this[1]=e;};var Zt=t=>{var e=t[He("asyncIterator")],o=!1,i,a={};return e==null?(e=t[He("iterator")](),i=d=>a[d]=r=>e[d](r)):(e=e.call(t),i=d=>a[d]=r=>{if(o){if(o=!1,d==="throw")throw r;return r}return o=!0,{done:!1,value:new Xn(new Promise(m=>{var l=e[d](r);l instanceof Object||Wn("Object expected"),m(l);}),1)}}),a[He("iterator")]=()=>a,i("next"),"throw"in e?i("throw"):a.throw=d=>{throw d},"return"in e&&i("return"),a};var ue="system",V="user",q="assistant",ee="tool",Zn=[ue,V,q,ee],Ke=zod.z.enum(Zn),Qn=[q],ei=zod.z.enum(Qn),te="image",Ye="base64",ti=["png","jpeg","webp","gif"],oi=zod.z.object({type:zod.z.literal(Ye),base64:zod.z.string(),mediaType:zod.z.enum(ti)}),ni="url",ii=zod.z.object({type:zod.z.literal(ni),url:zod.z.string()}),ai=zod.z.discriminatedUnion("type",[oi,ii]),si=["low","medium","high","auto"],ri=zod.z.enum(si),li=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(te),detail:ri,value:ai,metadata:t}),se="pdf",mi="base64",di=zod.z.object({type:zod.z.literal(mi),base64:zod.z.string()}),ci="url",pi=zod.z.object({type:zod.z.literal(ci),url:zod.z.string()}),ui=zod.z.discriminatedUnion("type",[di,pi]),gi=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(se),value:ui,providerCacheKey:zod.z.string(),metadata:t}),oo="reasoning",no="partial-reasoning",io="thinking",hi="redacted",Ve=zod.z.object({type:zod.z.literal(io),thinking:zod.z.string(),signature:zod.z.string()}),ao=zod.z.object({type:zod.z.literal(hi),data:zod.z.string()}),fi=zod.z.discriminatedUnion("type",[Ve,ao]),yi=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(oo),value:fi,metadata:t}),bi=zod.z.object({type:zod.z.literal(io),thinking:Ve.shape.thinking.optional(),signature:Ve.shape.signature.optional()}),Ti=zod.z.discriminatedUnion("type",[bi,ao]),Mi=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(no),value:Ti,metadata:t}),S="text",so=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(S),value:zod.z.string(),metadata:t}),Je="partial-text",ro=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Je),value:zod.z.string(),metadata:t}),B="tool-call",lo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(B),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),We="partial-tool-call",mo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(We),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),oe="tool-response",_i=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(oe),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:t}),Pi=[S,te,se,B,oe,oo],co=zod.z.enum(Pi),ki=(t=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined(),a=zod.z.undefined(),d=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[so(t),li(e),gi(o),lo(i),_i(a),yi(d)]),xi=[Je,We,no];zod.z.enum(xi);var Ei=(t=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[ro(t),mo(e),Mi(o)]);var Xe=(t=Ke,e=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined(),a=zod.z.undefined(),d=zod.z.undefined(),r=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(ki(e,o,i,a,r,d)),metadata:m}),Ze=(t=ei,e=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined(),a=zod.z.undefined())=>zod.z.object({role:t,partialContent:Ei(e,o,i),metadata:a}),vi=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Qt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Ci=Qt.extend({topLogProbs:zod.z.array(Qt)}),po=zod.z.array(Ci);zod.z.object({messages:zod.z.array(Xe()),usage:vi.optional(),logProbs:po.optional()});var Si=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(Ze()),usage:Si.optional(),logProbs:po.optional()});var ge=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,Oi=["object","array","number","string","boolean","enum"],eo=zod.z.enum(Oi),wi=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([eo,zod.z.array(zod.z.union([eo,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()}),Ri=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(wi),additionalProperties:zod.z.literal(!1)}),uo=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:Ri}).optional(),O="text",go="token",Gi=[O,go],ho=zod.z.enum(Gi),Ii=zod.z.array(zod.z.string().min(1)),ji=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Me=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(O),metadata:t,requests:Ii}),zod.z.object({modality:zod.z.literal(go),metadata:t,requests:ji})]),he="float",Ni=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Fi="base64",Li=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),to=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(he),embeddings:zod.z.array(Ni),usage:to.optional()}),zod.z.object({encodingFormat:zod.z.literal(Fi),embeddings:zod.z.array(Li),usage:to.optional()})]);var Ui=t=>{let e=new WeakSet;return JSON.stringify(t,(o,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return;e.add(i);}return i})},$i=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:Ui(t),ze="GatewayBaseError",W=class fo extends Error{constructor({info:e,cause:o},i){super(`[${i!=null?i:ze}]: ${e}
6
- Message: ${$i(o)}`),this.name=ze,this.info=e,this.cause=o,this.name=i!=null?i:ze,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(e){return e instanceof fo}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Di=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."),qi=zod.z.object({base:Di.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),Ai=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:qi.describe("Price categories and rates for this specific token range.")}).refine(t=>t.maxTokens===null||typeof t.maxTokens=="number"&&t.maxTokens>t.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(Ai).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((t,e)=>{let{tokenRanges:o}=t;o[0].minTokens!==0&&e.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let a=1;a<o.length;a++){let d=o[a-1],r=o[a];if(d.maxTokens===null){e.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!==d.maxTokens&&e.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",a,"minTokens"],message:`Tier ${a} minTokens (${r.minTokens}) must equal previous tier's maxTokens (${d.maxTokens}) for contiguity.`}),r.minTokens<d.minTokens&&e.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} (${d.minTokens}).`});}let i=o[o.length-1];o.every(a=>a.maxTokens!==null||a===i)&&i.maxTokens!==null&&e.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",o.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 Bi="function";var Hi=zod.z.enum(["object","array","number","string","boolean","null"]),zi=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Hi.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(zi).optional(),required:zod.z.array(zod.z.string()).optional()});var Vi=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 Ki=zod.z.enum(["function"]),Yi=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),Ji=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:Yi.optional()}),Wi=zod.z.discriminatedUnion("type",[Ji]),Xi=zod.z.object({type:Ki,definition:zod.z.object({schema:Vi}),request:Wi.optional()}),Zi=[Bi];zod.z.enum(Zi);var yo=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Xi.extend({metadata:t})]),bo=t=>so().parse({modality:S,value:t}),To=(t,e,o,i)=>lo().parse({modality:B,index:t,id:e,name:o,arguments:i});var Qe=(t,e)=>Ze().parse({role:t,partialContent:ro().parse({modality:Je,value:e})}),et=(t,e,o,i,a)=>Ze().parse({role:t,partialContent:mo().parse({modality:We,index:e,id:o,name:i,arguments:a})});var Qi=Object.defineProperty,Mo=Object.getOwnPropertySymbols,ea=Object.prototype.hasOwnProperty,ta=Object.prototype.propertyIsEnumerable,_o=(t,e,o)=>e in t?Qi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,fe=(t,e)=>{for(var o in e||(e={}))ea.call(e,o)&&_o(t,o,e[o]);if(Mo)for(var o of Mo(e))ta.call(e,o)&&_o(t,o,e[o]);return t},Po="ProviderError",de=class wo extends W{constructor({info:e,cause:o}){super({info:e,cause:o},Po),this.name=Po,this.info=e,this.cause=o;}static isProviderError(e){return e instanceof wo}},ko="ModelError",_e=class Ro extends W{constructor({info:e,cause:o}){super({info:e,cause:o},ko),this.name=ko,this.info=e,this.cause=o;}static isModelError(e){return e instanceof Ro}},xo="ModelResponseError",I=class Go extends W{constructor({info:e,cause:o}){super({info:e,cause:o},xo),this.name=xo,this.cause=o,this.info=e;}static isModelResponseError(e){return e instanceof Go}},Eo="InvalidModelRequestError",X=class Io extends W{constructor({info:e,cause:o}){super({info:e,cause:o},Eo),this.name=Eo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(e){return e instanceof Io}},vo="InvalidConfigError",H=class jo extends W{constructor({info:e,cause:o}){super({info:e,cause:o},vo),this.name=vo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(e){return e instanceof jo}},Co="InvalidMessagesError",T=class No extends W{constructor({info:e,cause:o}){super({info:e,cause:o},Co),this.name=Co,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(e){return e instanceof No}},So="InvalidToolsError",tt=class Fo extends W{constructor({info:e,cause:o}){super({info:e,cause:o},So),this.name=So,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(e){return e instanceof Fo}},Oo="InvalidEmbeddingRequestsError",ne=class Lo extends W{constructor({info:e,cause:o}){super({info:e,cause:o},Oo),this.name=Oo,this.info=e,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(e){return e instanceof Lo}},ot="multi-string",Uo=zod.z.object({type:zod.z.literal(ot),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()}),oa=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),$o=t=>({def:Uo.parse(fe({type:ot},t)),schema:oa(t.max)}),nt="object-schema",Do=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),objectSchema:zod.z.any()}),na=t=>t.optional(),it=t=>({def:Do.parse(fe({type:nt},t)),schema:na(t.objectSchema)}),at="range",qo=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),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),ia=(t,e,o,i)=>zod.z.number().min(t).max(e).step(o).default(i).optional(),K=t=>({def:qo.parse(fe({type:at},t)),schema:ia(t.min,t.max,t.step,t.default)}),st="select-boolean",Ao=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.boolean().nullable()}),aa=t=>zod.z.boolean().nullable().default(t).optional(),Pe=t=>({def:Ao.parse(fe({type:st},t)),schema:aa(t.default)}),rt="select-string",Bo=zod.z.object({type:zod.z.literal(rt),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())}),sa=(t,e)=>zod.z.enum(e).nullable().default(t).optional(),lt=t=>({def:Bo.parse(fe({type:rt},t)),schema:sa(t.default,t.choices)}),ra=[at,ot,rt,nt,st];zod.z.enum(ra);var Ho=zod.z.discriminatedUnion("type",[qo,Uo,Bo,Ao,Do]),j=(t=Ke,e=co)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(e).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),Ho),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var i,a;let d=Object.keys(o.def),r=Object.keys((a=(i=o.schema)==null?void 0:i.shape)!=null?a:{});return d.every(m=>r.includes(m))&&r.every(m=>d.includes(m))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"}),price:zod.z.custom()}),z=(t=ho)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).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),Ho),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(e=>{var o,i;let a=Object.keys(e.def),d=Object.keys((i=(o=e.schema)==null?void 0:o.shape)!=null?i:{});return a.every(r=>d.includes(r))&&d.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 la={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."},ma={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."},da={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},ca=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),pa={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."},ua={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."},ga={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."},ha={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."},fa={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."},ya={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."},ba={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."},Ta={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."},Ma={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."},_a={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."},Pa={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},ka={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."},xa={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."},Ea={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."},_={TEMPERATURE:la,MAX_TOKENS:ma,STOP:ca,TOP_A:pa,TOP_P:ua,TOP_K:ga,MIN_P:ha,FREQUENCY_PENALTY:fa,PRESENCE_PENALTY:ya,REPETITION_PENALTY:Ta,SEED:ba,LOG_PROBS:Ma,TOP_LOG_PROBS:_a,ECHO:Pa,RESPONSE_FORMAT:ka,RESPONSE_FORMAT_WITH_SCHEMA:xa,RESPONSE_SCHEMA:Ea,MAX_REASONING_TOKENS:da},va={type:"range",title:"Dimensions",description:"Select the number of dimensions for the word embedding."},Ca={type:"select",title:"Encoding format",description:"Select the encoding format for the word embedding."},ce={DIMENSIONS:va,ENCODING_FORMAT:Ca};var ye=t=>Object.fromEntries(Object.entries(t).filter(([e,o])=>o!=null)),mt=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined",zo=t=>{let e=t.replace(/-/g,"+").replace(/_/g,"/"),o=globalThis.atob(e);return Uint8Array.from(o,i=>i.codePointAt(0))};var pe=t=>t==null?void 0:t.replace(/\/$/,"");var Sa=Object.defineProperty,Oa=Object.defineProperties,wa=Object.getOwnPropertyDescriptors,Vo=Object.getOwnPropertySymbols,Ra=Object.prototype.hasOwnProperty,Ga=Object.prototype.propertyIsEnumerable,ke=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Ia=t=>{throw TypeError(t)},Ko=(t,e,o)=>e in t?Sa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,M=(t,e)=>{for(var o in e||(e={}))Ra.call(e,o)&&Ko(t,o,e[o]);if(Vo)for(var o of Vo(e))Ga.call(e,o)&&Ko(t,o,e[o]);return t},be=(t,e)=>Oa(t,wa(e)),P=(t,e,o)=>new Promise((i,a)=>{var d=l=>{try{m(o.next(l));}catch(c){a(c);}},r=l=>{try{m(o.throw(l));}catch(c){a(c);}},m=l=>l.done?i(l.value):Promise.resolve(l.value).then(d,r);m((o=o.apply(t,e)).next());}),en=function(t,e){this[0]=t,this[1]=e;},Yo=(t,e,o)=>{var i=(r,m,l,c)=>{try{var u=o[r](m),g=(m=u.value)instanceof en,h=u.done;Promise.resolve(g?m[0]:m).then(y=>g?i(r==="return"?r:"next",m[1]?{done:y.done,value:y.value}:y,l,c):l({value:y,done:h})).catch(y=>i("throw",y,l,c));}catch(y){c(y);}},a=r=>d[r]=m=>new Promise((l,c)=>i(r,m,l,c)),d={};return o=o.apply(t,e),d[ke("asyncIterator")]=()=>d,a("next"),a("throw"),a("return"),d},ja=t=>{var e=t[ke("asyncIterator")],o=!1,i,a={};return e==null?(e=t[ke("iterator")](),i=d=>a[d]=r=>e[d](r)):(e=e.call(t),i=d=>a[d]=r=>{if(o){if(o=!1,d==="throw")throw r;return r}return o=!0,{done:!1,value:new en(new Promise(m=>{var l=e[d](r);l instanceof Object||Ia("Object expected"),m(l);}),1)}}),a[ke("iterator")]=()=>a,i("next"),"throw"in e?i("throw"):a.throw=d=>{throw d},"return"in e&&i("return"),a},tn=(t,e)=>K({param:"temperature",title:_.TEMPERATURE.title,description:_.TEMPERATURE.description,min:0,max:t,step:.01,default:e}),on=t=>K({param:"maxOutputTokens",title:_.MAX_TOKENS.title,description:_.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),nn=t=>$o({param:"stopSequences",title:_.STOP(t).title,description:_.STOP(t).description,max:t}),an=t=>K({param:"topP",title:_.TOP_P.title,description:_.TOP_P.description,min:0,max:1,step:.01,default:t});K({param:"frequencyPenalty",title:_.FREQUENCY_PENALTY.title,description:_.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0});K({param:"presencePenalty",title:_.PRESENCE_PENALTY.title,description:_.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0});K({param:"seed",title:_.SEED.title,description:_.SEED.description,min:0,max:1e6,step:1,default:0});var sn=lt({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"]}),rn=it({param:"safetySettings",title:"Safety settings",description:"The safety rating contains the category of harm and the harm probability level in that category for a piece of content.",objectSchema:zod.z.array(zod.z.object({threshold:zod.z.enum(["HARM_BLOCK_THRESHOLD_UNSPECIFIED","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH","BLOCK_NONE","OFF"]),category:zod.z.enum(["HARM_CATEGORY_UNSPECIFIED","HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT","HARM_CATEGORY_CIVIC_INTEGRITY"])}))}),ln=Pe({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}),mn=(t,e,o,i,a)=>zod.z.object({temperature:tn(t,e).schema,maxTokens:on(o).schema,stop:nn(i).schema,topP:an(a).schema,toolChoice:sn.schema,safetySettings:rn.schema}),dn=(t,e,o,i,a)=>({temperature:tn(t,e).def,maxTokens:on(o).def,stop:nn(i).def,topP:an(a).def,toolChoice:sn.def,safetySettings:rn.def}),cn=it({param:"response_schema",title:_.RESPONSE_SCHEMA.title,description:_.RESPONSE_SCHEMA.description,objectSchema:uo}),pn=lt({param:"response_format",title:_.RESPONSE_FORMAT_WITH_SCHEMA.title,description:_.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_schema"]}),un=(t,e,o,i,a)=>be(M({},dn(t,e,o,i,a)),{responseFormat:pn.def,responseSchema:cn.def}),gn=(t,e,o,i,a)=>mn(t,e,o,i,a).extend({responseFormat:pn.schema,responseSchema:cn.schema}),Na=(t,e,o,i,a)=>gn(t,e,o,i,a).extend({reasoningEnabled:ln.schema}),Fa=(t,e,o,i,a)=>be(M({},un(t,e,o,i,a)),{reasoningEnabled:ln.def}),hn=t=>K({param:"outputDimensionality",title:ce.DIMENSIONS.title,description:ce.DIMENSIONS.description,min:1,max:t,step:1,default:t}),La=t=>zod.z.object({dimensions:hn(t).schema}),Ua=t=>({dimensions:hn(t).def}),f={base:(t,e,o,i,a)=>({def:dn(t,e,o,i,a),schema:mn(t,e,o,i,a)}),responseSchema:(t,e,o,i,a)=>({def:un(t,e,o,i,a),schema:gn(t,e,o,i,a)}),reasoning:(t,e,o,i,a)=>({def:Fa(t,e,o,i,a),schema:Na(t,e,o,i,a)})},xe={base:t=>({def:Ua(t),schema:La(t)})},$a="google",kt=class{constructor(){this.version="v1",this.name=$a,this.chatModelFactories={[dt]:{model:os,modelOptions:ts,modelSchema:Ee},[ct]:{model:as,modelOptions:is,modelSchema:ve},[pt]:{model:ls,modelOptions:rs,modelSchema:yn},[ut]:{model:cs,modelOptions:ds,modelSchema:Ce},[gt]:{model:gs,modelOptions:us,modelSchema:Se},[ht]:{model:ys,modelOptions:fs,modelSchema:Oe},[ft]:{model:Ms,modelOptions:Ts,modelSchema:bn},[yt]:{model:ks,modelOptions:Ps,modelSchema:we},[bt]:{model:vs,modelOptions:Es,modelSchema:Re},[Tt]:{model:Os,modelOptions:Ss,modelSchema:Tn},[Mt]:{model:Gs,modelOptions:Rs,modelSchema:Mn},[_t]:{model:Ns,modelOptions:js,modelSchema:_n},[Pt]:{model:Us,modelOptions:Ls,modelSchema:Pn}},this.embeddingModelFactories={[vn]:{model:Hs,modelOptions:Bs,modelSchema:Cn},[Sn]:{model:Ks,modelOptions:Vs,modelSchema:On}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,e)=>(t[e]=this.chatModelFactories[e].modelSchema,t),{})}chatModel(t){let e=t.modelName;if(!(e in this.chatModelFactories))throw new de({info:`Google chat model: ${e} not found`,cause:new Error(`Google chat model: ${e} not found, available chat models:
7
- [${this.chatModelLiterals().join(", ")}]`)});let o=this.chatModelFactories[e].model,i=this.chatModelFactories[e].modelOptions.parse(t);return new o(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,e)=>(t[e]=this.embeddingModelFactories[e].modelSchema,t),{})}embeddingModel(t){let e=t.modelName;if(!(e in this.embeddingModelFactories))throw new de({info:`Google embedding model: ${e} not found`,cause:new Error(`Google embedding model: ${e} not found, available embedding models:
8
- [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[e].model,i=this.embeddingModelFactories[e].modelOptions.parse(t);return new o(i)}};kt.baseUrl="https://generativelanguage.googleapis.com/v1beta";var w={"base-gemini-1-chat-model":{modelName:"base-gemini-1-chat-model",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:0,outputPricePerMillion:0}}}]},"gemini-1.0-pro-001":{modelName:"gemini-1.0-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-latest":{modelName:"gemini-1.0-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-vision":{modelName:"gemini-1.0-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro":{modelName:"gemini-1.0-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.5-flash-001":{modelName:"gemini-1.5-flash-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash-002":{modelName:"gemini-1.5-flash-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.0375,outputPricePerMillion:.15}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}}]},"gemini-1.5-flash-latest":{modelName:"gemini-1.5-flash-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash":{modelName:"gemini-1.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-pro-001":{modelName:"gemini-1.5-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-002":{modelName:"gemini-1.5-pro-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-latest":{modelName:"gemini-1.5-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro":{modelName:"gemini-1.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-2.0-flash-exp":{modelName:"gemini-2.0-flash-exp",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-2.5-flash-preview-04-17":{modelName:"gemini-2.5-flash-preview-04-17",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-2.5-pro-preview-03-25":{modelName:"gemini-2.5-pro-preview-03-25",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:15}}}]},"gemini-pro-vision":{modelName:"gemini-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-pro":{modelName:"gemini-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-2.5-pro":{modelName:"gemini-2.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}}]},"gemini-2.5-flash":{modelName:"gemini-2.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.3,outputPricePerMillion:2.5}}}]}},F=zod.z.enum([ue,V,q,ee]),Da="model",qa="function",L={system:V,user:V,assistant:Da,tool:qa},U=[S,te,se,B,oe],$=zod.z.enum([S,te,se,B,oe]);zod.z.enum([S]);zod.z.enum([S,te]);zod.z.enum([S,B,oe]);var Aa=zod.z.object({text:zod.z.string()}),Ba=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Ha=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([Aa,Ba]))}).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()}),za=zod.z.object({text:zod.z.string()}),Va=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Jo=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([za,Va]))}).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()}),fn=zod.z.object({text:zod.z.string().min(1)}),Ka=zod.z.object({inline_data:zod.z.object({mime_type:zod.z.string().min(1),data:zod.z.string().base64()})}),Ya=zod.z.object({file_data:zod.z.object({mime_type:zod.z.string().min(1),file_uri:zod.z.string().min(1)})}),Ja=zod.z.object({function_call:zod.z.object({name:zod.z.string().min(1),args:zod.z.record(zod.z.string().min(1))})}),Wa=zod.z.object({function_response:zod.z.object({name:zod.z.string().min(1),response:zod.z.record(zod.z.string().min(1))})}),Xa=zod.z.object({role:zod.z.enum(["user","model","function"]),parts:zod.z.array(zod.z.union([fn,Ka,Ya,Ja,Wa]))}),Wo=zod.z.object({parts:zod.z.array(fn)}),Za=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),parameters:zod.z.any()}),Xo=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()}),Qo=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"])}),Qa=zod.z.object({model:zod.z.string().min(1).optional(),contents:zod.z.array(Xa),systemInstruction:Wo.optional(),system_instruction:Wo.optional(),generationConfig:Zo.optional(),generation_config:Zo.optional(),safetySettings:zod.z.array(Qo).optional(),safety_settings:zod.z.array(Qo).optional(),tools:zod.z.object({function_declarations:zod.z.array(Za)}).optional(),toolConfig:Xo.optional(),tool_config:Xo.optional()}),N=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()}),R=class{constructor(t,e){this.version="v1";var o;let i=N.parse(e);this.modelSchema=t,this.modelName=i.modelName,this.apiKey=i.apiKey,this.baseUrl=pe((o=i.baseUrl)!=null?o:kt.baseUrl),this.completeChatUrl=pe(i.completeChatUrl||`${this.baseUrl}/models/${this.modelName}:generateContent?key=${this.apiKey}`),this.streamChatUrl=pe(i.streamChatUrl||`${this.baseUrl}/models/${this.modelName}:streamGenerateContent?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.reduce((e,o)=>e+o.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformPdfMessages(t){return P(this,null,function*(){let e=r=>P(this,null,function*(){let m={};mt()||(m["User-Agent"]="Mozilla/5.0 (compatible; GoogleFilesAPI/1.0)");let l=yield fetch(r,{headers:m});if(!l.ok)throw new T({info:`Failed to download PDF from URL: ${r}`,cause:new Error(`HTTP ${l.status}: ${l.statusText}`)});let c=yield l.arrayBuffer();return new Uint8Array(c)}),o=r=>P(this,null,function*(){try{let m=yield fetch(`https://generativelanguage.googleapis.com/v1beta/files?key=${this.apiKey}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!m.ok)return null;let l=((yield m.json()).files||[]).find(c=>c.displayName===r);return l?l.uri:null}catch(m){return null}}),i=(r,m)=>P(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:m}})});if(!l.ok)throw new T({info:"Failed to start PDF upload to Google Files API",cause:new Error(`HTTP ${l.status}: ${l.statusText}`)});let c=l.headers.get("x-goog-upload-url");if(!c)throw new T({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"};mt()||(u["Content-Length"]=r.length.toString());let g=yield fetch(c,{method:"POST",headers:u,body:r});if(!g.ok)throw new T({info:"Failed to upload PDF content to Google Files API",cause:new Error(`HTTP ${g.status}: ${g.statusText}`)});return (yield g.json()).file.uri}),a=r=>P(this,null,function*(){let m=yield o(r.providerCacheKey);if(m)return m;let l;if(r.value.type==="url")l=yield e(r.value.url);else {let c=r.value.base64,u="data:application/pdf;base64,";c=c.startsWith(u)?c.substring(u.length):c,l=zo(c);}return yield i(l,r.providerCacheKey)}),d=[];for(let r of t){let m=[];for(let l of r.content)if(l.modality===se){let c=yield a(l);m.push(be(M({},l),{value:{type:"url",url:c}}));}else m.push(l);d.push(be(M({},r),{content:m}));}return d})}transformModelRequest(t){let e=Qa.safeParse(t);if(!e.success)throw new X({info:"Invalid model request",cause:e.error});let o=e.data,i=o.model;if(o.system_instruction&&o.systemInstruction)throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'system_instruction' and 'systemInstruction' are not allowed at the same time")});if(o.generation_config&&o.generationConfig)throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'generation_config' and 'generationConfig' are not allowed at the same time")});if(o.tool_config&&o.toolConfig)throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tool_config' and 'toolConfig' are not allowed at the same time")});let a=o.system_instruction||o.systemInstruction,d=o.generation_config||o.generationConfig,r=o.safety_settings||o.safetySettings,m=o.tool_config||o.toolConfig;if(m&&(!o.tools||o.tools.function_declarations.length===0))throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let l={};m&&(m.function_calling_config.mode==="ANY"&&m.function_calling_config.allowed_function_names&&m.function_calling_config.allowed_function_names.length===1?l.toolChoice=m.function_calling_config.allowed_function_names[0]:l.toolChoice=m.function_calling_config.mode.toLowerCase()),l.seed=d==null?void 0:d.seed,l.maxTokens=d==null?void 0:d.maxOutputTokens,l.temperature=d==null?void 0:d.temperature,l.topP=d==null?void 0:d.topP,l.presencePenalty=d==null?void 0:d.presencePenalty,l.frequencyPenalty=d==null?void 0:d.frequencyPenalty,l.stop=d==null?void 0:d.stopSequences,l.safetySettings=r;let c=ge().parse(ye(l)),u=[];a&&a.parts.forEach(h=>{u.push({role:ue,content:[{modality:S,value:h.text}]});}),o.contents.forEach(h=>{let y=h.role;switch(y){case"user":{let C=h.parts.map(k=>"text"in k?{modality:S,value:k.text}:{modality:te,detail:"auto",value:{type:Ye,base64:k.inline_data.data,mediaType:k.inline_data.mime_type.split("/")[1]}});u.push({role:y,content:C});}break;case"model":{let C=h.parts.map((k,D)=>"text"in k?{modality:S,value:k.text}:{modality:B,id:D.toString(),index:D,name:k.function_call.name,arguments:JSON.stringify(k.function_call.args)});u.push({role:q,content:C});}break;case"function":{let C=h.parts.map((k,D)=>({modality:oe,id:D.toString(),index:D,name:k.function_response.name,data:JSON.stringify(k.function_response.response)}));u.push({role:ee,content:C});}break;default:throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${h.role}' is not supported for model : ${this.modelName}`)})}});let g=[];return o.tools&&o.tools.function_declarations.forEach(h=>{g.push({type:"function",definition:{schema:{name:h.name,description:h.description,parameters:h.parameters}}});}),{modelName:i,config:c,messages:u,tools:g.length>0?g:void 0}}transformConfig(t,e,o){let i=t.toolChoice;delete t.toolChoice;let a=this.modelSchema.config.schema.safeParse(t);if(!a.success)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let d=a.data;Object.keys(d).forEach(c=>{if(!(c in this.modelSchema.config.def))throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${c}',
9
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(d).reduce((c,u)=>{let g=this.modelSchema.config.def[u],h=g.param,y=d[u];return u==="reasoningEnabled"?c.thinkingConfig={includeThoughts:y}:u==="maxReasoningTokens"?c.thinkingConfig=c.thinkingConfig&&typeof c.thinkingConfig=="object"?be(M({},c.thinkingConfig),{thinkingBudget:y}):{thinkingBudget:y}:h==="maxOutputTokens"&&g.type==="range"&&y===0?c[h]=g.max:c[h]=y,c},{}),m=r.safetySettings;delete r.safetySettings;let l;if(i!==void 0){let c=i;if(!o||o&&o.length===0)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let u=this.modelSchema.config.def.toolChoice;if(u.choices.includes(c))c==="any"?l={function_calling_config:{mode:"ANY",allowed_function_names:o.map(g=>g.definition.schema.name)}}:l={function_calling_config:{mode:c.toUpperCase()}};else if(o.map(g=>g.definition.schema.name).includes(c))l={function_calling_config:{mode:"ANY",allowed_function_names:[c]}};else throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${c}' is not part of provided 'tools' names or
10
- one of [${u.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let c=r.response_format;if(c==="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 c==="json_object"?(r.responseSchema={type:"object"},delete r.response_format):c==="text"&&delete r.response_format;}return M(M({generation_config:r},l?{tool_config:l}:{}),m?{safety_settings:m}:{})}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let e=r=>{let m=r.match(/^data:(image\/[a-zA-Z]+|application\/pdf);base64,/);return m?r.substring(m[0].length):r},o=t.map(r=>{let m=Xe().safeParse(r);if(!m.success)throw new T({info:"Invalid messages",cause:m.error});return m.data});o.forEach(r=>{r.content.forEach(m=>{if(!this.modelSchema.modalities.includes(m.modality))throw new T({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${m.modality}',
11
- available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new T({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}',
12
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let i={parts:[]},a=[];if(o.forEach(r=>{switch(r.role){case ue:r.content.forEach(m=>{if(m.modality===S)i.parts.push({text:m.value});else throw new T({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${m.modality}'`)})});break;case q:{let m=[];r.content.forEach(l=>{if(l.modality===S)m.push({text:l.value});else if(l.modality===B)m.push({function_call:{name:l.name,args:JSON.parse(l.arguments)}});else throw new T({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:m});}break;case V:{let m=[];r.content.forEach(l=>{if(l.modality===S)m.push({text:l.value});else if(l.modality===te){if(l.value.type==="base64"){let c=l.value.base64;c=e(c),m.push({inline_data:{mime_type:`image/${l.value.mediaType}`,data:c}});}else if(l.value.type==="url")throw new T({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===se)if(l.value.type==="base64"){let c=l.value.base64;c=e(c),m.push({inline_data:{mime_type:"application/pdf",data:c}});}else l.value.type==="url"&&m.push({file_data:{mime_type:"application/pdf",file_uri:l.value.url}});else throw new T({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:m});}break;case ee:{let m=[];r.content.forEach(l=>{if(l.modality===oe)m.push({function_response:{name:l.name,response:JSON.parse(l.data)}});else throw new T({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:m});}break;default:throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
13
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),a[0].role!==this.modelSchema.roles[V])throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let d=r=>r===this.modelSchema.roles[V]||r===this.modelSchema.roles[ee]?[this.modelSchema.roles[q]]:[this.modelSchema.roles[V],this.modelSchema.roles[ee]];for(let r=1;r<a.length;r++)if(!d(a[r-1].role).includes(a[r].role))throw new T({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[V]&&a[a.length-1].role!==this.modelSchema.roles[ee])throw new T({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return M({contents:a},i.parts.length>0?{system_instruction:i}:{})}transformTools(t){if(!this.modelSchema.modalities.includes(B))throw new tt({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${B}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:[{function_declarations:t.map(e=>{let o=yo().safeParse(e);if(!o.success)throw new tt({info:"Invalid tools",cause:o.error});return o.data}).map(e=>({name:e.definition.schema.name,description:e.definition.schema.description,parameters:e.definition.schema.parameters}))}]}}getCompleteChatUrl(t,e,o){return P(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(t,e,o){return P(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getCompleteChatData(t,e,o){return P(this,null,function*(){let i=this.transformConfig(t,e,o),a=yield this.transformPdfMessages(e),d=this.transformMessages(a);if(d.messages&&d.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return M(M(M(M({},this.getDefaultParams()),i),d),r)})}transformCompleteChatResponse(t){let e=Ha.safeParse(t);if(e.success){if(e.data.candidates.length===0)throw new I({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(e.data)}`)});let o=e.data,i=[],a,d=o.candidates[0].content;if(d){let m=d.parts.map((l,c)=>{if("text"in l&&l.text!==void 0)return bo(l.text);if("functionCall"in l&&l.functionCall!==void 0)return To(c,`${l.functionCall.name}_${c}`,l.functionCall.name,JSON.stringify(l.functionCall.args))});return i.push({role:q,content:m}),o.usageMetadata&&(a={promptTokens:o.usageMetadata.promptTokenCount,totalTokens:o.usageMetadata.totalTokenCount,completionTokens:o.usageMetadata.candidatesTokenCount||0}),{messages:i,usage:a,logProbs:void 0}}let r=o.candidates[0].safetyRatings;if(r&&r.length>0&&r.forEach(m=>{if(m.blocked)throw new I({info:`Blocked content for category: ${m.category} with probability: ${m.probability}`,cause:new Error(`Blocked content for category: ${m.category} with probability: ${m.probability}`)})}),o.candidates[0].finishReason==="SAFETY")throw new I({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new I({info:"Invalid response from model",cause:e.error})}getStreamChatUrl(t,e,o){return P(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(t,e,o){return P(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getStreamChatData(t,e,o){return P(this,null,function*(){let i=this.transformConfig(t,e,o),a=yield this.transformPdfMessages(e),d=this.transformMessages(a);if(d.messages&&d.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return M(M(M(M({},this.getDefaultParams()),i),d),r)})}transformStreamChatResponseChunk(t,e){return Yo(this,null,function*(){let o=(e+t).split(",\r").filter(i=>i.trim()!=="");for(let i of o){let a=i;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 d;try{d=JSON.parse(a);}catch(m){if(m instanceof SyntaxError){e=a;continue}else throw m}e="";let r=Jo.safeParse(d);if(r.success){let m={partialMessages:[]},l=r.data;if(l.candidates.length>0){let c=l.candidates[0].content;c&&"parts"in c&&c.parts.length>0&&c.parts.forEach((u,g)=>{if("text"in u&&u.text!==void 0&&m.partialMessages.push(Qe(q,u.text)),"functionCall"in u&&u.functionCall!==void 0){let h=u.functionCall;m.partialMessages.push(et(q,g,`${h.name}_${g}`,h.name,JSON.stringify(h.args)));}});}l.usageMetadata&&(m.usage={promptTokens:l.usageMetadata.promptTokenCount,completionTokens:l.usageMetadata.candidatesTokenCount,totalTokens:l.usageMetadata.totalTokenCount}),yield {partialResponse:m,buffer:e};}else throw new I({info:"Invalid response from model",cause:r.error})}yield {partialResponse:{partialMessages:[]},buffer:e};})}transformProxyStreamChatResponseChunk(t,e,o,i,a){return Yo(this,null,function*(){if((a==null?void 0:a.alt)!=="sse"){yield*Zt(ja(this.transformStreamChatResponseChunk(t,e)));return}let d=e+t,r=[],m="",l=0;for(;l<d.length;){let c=d.indexOf(`
14
- `,l);if(c===-1){m=d.substring(l);break}else {let u=d.substring(l,c).trim();u&&r.push(u),l=c+1;}}for(let c of r){if(c==="data: [DONE]")return;if(c.startsWith("data: ")){let u=c.substring(6);try{let g=JSON.parse(u),h=Jo.safeParse(g);if(h.success){let y={partialMessages:[]},C=h.data;if(C.candidates.length>0){let k=C.candidates[0].content;k&&"parts"in k&&k.parts.length>0&&k.parts.forEach((D,Jt)=>{if("text"in D&&D.text!==void 0&&y.partialMessages.push(Qe(q,D.text)),"functionCall"in D&&D.functionCall!==void 0){let Be=D.functionCall;y.partialMessages.push(et(q,Jt,`${Be.name}_${Jt}`,Be.name,JSON.stringify(Be.args)));}});}C.usageMetadata&&C.usageMetadata.totalTokenCount&&C.usageMetadata.promptTokenCount&&C.usageMetadata.candidatesTokenCount&&(y.usage={promptTokens:C.usageMetadata.promptTokenCount,completionTokens:C.usageMetadata.candidatesTokenCount,totalTokens:C.usageMetadata.totalTokenCount}),yield {partialResponse:y,buffer:e};}else throw new I({info:"Invalid response from model",cause:h.error})}catch(g){throw new I({info:`Malformed JSON received in stream: ${u}`,cause:g})}}}yield {partialResponse:{partialMessages:[]},buffer:m};})}getProxyCompleteChatUrl(t,e,o){return P(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyStreamChatUrl(t,e,o){return P(this,null,function*(){return new Promise(i=>{if(!o||Object.keys(o).length===0){i(this.streamChatUrl);return}let a=new URL(this.streamChatUrl);Object.entries(o).forEach(([d,r])=>{r!=null&&a.searchParams.set(d,r);}),i(a.toString());})})}getProxyCompleteChatHeaders(t,e,o){return P(this,null,function*(){if(!e)return {};let i=M({},e);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(t,e,o){return P(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,e,o)})}getModelPricing(){if(!(this.modelName in w))throw new I({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return w[this.modelName]}},dt="gemini-1.5-flash-001",es="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",Ee=j(F,$).parse({name:dt,description:es,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[dt]}),ts=N,os=class extends R{constructor(t){super(Ee,t);}},ct="gemini-1.5-flash-002",ns="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",ve=j(F,$).parse({name:ct,description:ns,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[ct]}),is=N,as=class extends R{constructor(t){super(ve,t);}},pt="gemini-1.5-flash-latest",ss="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",yn=j(F,$).parse({name:pt,description:ss,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[pt]}),rs=N,ls=class extends R{constructor(t){super(yn,t);}},ut="gemini-1.5-flash",ms="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=j(F,$).parse({name:ut,description:ms,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[ut]}),ds=N,cs=class extends R{constructor(t){super(Ce,t);}},gt="gemini-1.5-pro-001",ps="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Se=j(F,$).parse({name:gt,description:ps,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[gt]}),us=N,gs=class extends R{constructor(t){super(Se,t);}},ht="gemini-1.5-pro-002",hs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Oe=j(F,$).parse({name:ht,description:hs,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[ht]}),fs=N,ys=class extends R{constructor(t){super(Oe,t);}},ft="gemini-1.5-pro-latest",bs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",bn=j(F,$).parse({name:ft,description:bs,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[ft]}),Ts=N,Ms=class extends R{constructor(t){super(bn,t);}},yt="gemini-1.5-pro",_s="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",we=j(F,$).parse({name:yt,description:_s,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[yt]}),Ps=N,ks=class extends R{constructor(t){super(we,t);}},bt="gemini-2.0-flash-exp",xs="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",Re=j(F,$).parse({name:bt,description:xs,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[bt]}),Es=N,vs=class extends R{constructor(t){super(Re,t);}},Tt="gemini-2.5-flash-preview-04-17",Cs="Google's best model in Gemini 2.5 family in terms of price-performance, offering well-rounded capabilities.",Tn=j(F,$).parse({name:Tt,description:Cs,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:f.responseSchema(2,1,65536,4,.95).def,schema:f.responseSchema(2,1,65536,4,.95).schema},price:w[Tt]}),Ss=N,Os=class extends R{constructor(t){super(Tn,t);}},Mt="gemini-2.5-pro-preview-03-25",ws="Google's preview model in Gemini 2.5 family for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Mn=j(F,$).parse({name:Mt,description:ws,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:f.reasoning(2,1,65536,4,.95).def,schema:f.reasoning(2,1,65536,4,.95).schema},price:w[Mt]}),Rs=N,Gs=class extends R{constructor(t){super(Mn,t);}},_t="gemini-2.5-flash",Is="Google's Gemini 2.5 Flash model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",_n=j(F,$).parse({name:_t,description:Is,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:f.responseSchema(2,1,65536,4,.95).def,schema:f.responseSchema(2,1,65536,4,.95).schema},price:w[_t]}),js=N,Ns=class extends R{constructor(t){super(_n,t);}},Pt="gemini-2.5-pro",Fs="Google's Gemini 2.5 Pro model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Pn=j(F,$).parse({name:Pt,description:Fs,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:f.reasoning(2,1,65536,4,.95).def,schema:f.reasoning(2,1,65536,4,.95).schema},price:w[Pt]}),Ls=N,Us=class extends R{constructor(t){super(Pn,t);}},kn=[O],xn=zod.z.enum([O]),$s=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),Ds=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)})}),qs=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(Ds).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),xt=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),En=class{constructor(t,e){this.version="v1";let o=xt.parse(e);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=pe(o.baseUrl||kt.baseUrl),this.getEmbeddingsUrl=pe(o.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.requests.reduce((e,o)=>e+o.length,0)}transformModelRequest(t){let e=qs.safeParse(t);if(!e.success)throw new X({info:"Invalid model request",cause:e.error});let o=e.data,i=o.model,a={outputDimensionality:o.outputDimensionality},d=ge().parse(ye(a)),r={modality:O,requests:o.requests.reduce((m,l)=>(m.push(...l.content.parts.map(c=>c.text)),m),[])};return {modelName:i,config:d,embeddingRequests:r}}transformConfig(t,e){let o=this.modelSchema.config.schema.safeParse(t);if(!o.success)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let i=o.data;return Object.keys(i).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}',
15
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((a,d)=>{let r=this.modelSchema.config.def[d].param,m=i[d];return a[r]=m,a},{})}transformEmbeddingRequests(t){let e=Me().safeParse(t);if(!e.success)throw new ne({info:"Invalid embedding requests",cause:e.error});if(t.modality!==O)throw new ne({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${O}' modality is supported for model : '${this.modelName}'`)});return {requests:e.data.requests.map(o=>({model:`models/${this.modelName}`,content:{parts:[{text:o}]}}))}}getGetEmbeddingsUrl(t,e){return P(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,e){return P(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,e){return P(this,null,function*(){return new Promise(o=>{let i=this.transformConfig(t),a=this.transformEmbeddingRequests(e);if(e.requests.length===0)throw new ne({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});i.outputDimensionality&&(a.requests.forEach(d=>{d.outputDimensionality=i.outputDimensionality;}),delete i.outputDimensionality),o(M(M(M({},this.getDefaultParams()),i),a));})})}transformGetEmbeddingsResponse(t){let e=$s.safeParse(t);if(e.success){let o=e.data.embeddings.map((i,a)=>({index:a,embedding:i.values}));return {encodingFormat:he,embeddings:o}}throw new I({info:"Invalid response from model",cause:e.error})}},vn="text-embedding-001",As="text-embedding-001",Cn=z(xn).parse({name:vn,description:As,modalities:kn,maxInputTokens:2048,maxOutputTokens:768,config:{def:xe.base(768).def,schema:xe.base(768).schema}}),Bs=xt,Hs=class extends En{constructor(t){super(Cn,t);}},Sn="text-embedding-004",zs="text-embedding-004",On=z(xn).parse({name:Sn,description:zs,modalities:kn,maxInputTokens:2048,maxOutputTokens:768,config:{def:xe.base(768).def,schema:xe.base(768).schema}}),Vs=xt,Ks=class extends En{constructor(t){super(On,t);}};var Ys="vertex",re=class{constructor(){this.version="v1";this.name=Ys;this.chatModelFactories={[Et]:{model:Ge,modelOptions:wn,modelSchema:vt},[Ct]:{model:Ie,modelOptions:Rn,modelSchema:St},[Ot]:{model:je,modelOptions:Gn,modelSchema:wt},[Rt]:{model:Ne,modelOptions:In,modelSchema:Gt},[It]:{model:Fe,modelOptions:jn,modelSchema:jt},[Nt]:{model:Le,modelOptions:Nn,modelSchema:Ft},[Lt]:{model:Ue,modelOptions:Fn,modelSchema:Ut}};this.embeddingModelFactories={[$t]:{model:$e,modelOptions:Ln,modelSchema:Dt},[qt]:{model:De,modelOptions:Un,modelSchema:At},[zt]:{model:Ae,modelOptions:Dn,modelSchema:Vt},[Bt]:{model:qe,modelOptions:$n,modelSchema:Ht}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}chatModel(e){let o=e.modelName;if(!(o in this.chatModelFactories))throw new de({info:`Vertex chat model: ${o} not found`,cause:new Error(`Vertex chat model: ${o} not found, available chat models:
16
- ${this.chatModelLiterals().join(", ")}`)});let i=this.chatModelFactories[o].model,a=this.chatModelFactories[o].modelOptions.parse(e);return new i(a)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,o)=>(e[o]=this.embeddingModelFactories[o].modelSchema,e),{})}embeddingModel(e){let o=e.modelName;if(!(o in this.embeddingModelFactories))throw new de({info:`Vertex embedding model: ${o} not found`,cause:new Error(`Vertex embedding model: ${o} not found, available embedding models:
17
- ${this.embeddingModelLiterals().join(", ")}`)});let i=this.embeddingModelFactories[o].model,a=this.embeddingModelFactories[o].modelOptions.parse(e);return new i(a)}};re.baseUrl=(e,o,i="google")=>`https://${e}-aiplatform.googleapis.com/v1/projects/${o}/locations/${e}/publishers/${i}`;var x={"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}}}]}};var G=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()}),v=class extends R{constructor(o,i){let a=G.parse(i),d;if(a.baseUrl)d=a.baseUrl;else if(a.location&&a.projectId)d=re.baseUrl(a.location,a.projectId,a.publisher);else throw new _e({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(o,{modelName:a.modelName,apiKey:"random-api-key",completeChatUrl:`${d}/models/${a.modelName}:generateContent`,streamChatUrl:`${d}/models/${a.modelName}:streamGenerateContent`});this.version="v1";this.modelSchema=o,this.modelName=a.modelName,this.accessToken=a.accessToken,this.location=a.location,this.projectId=a.projectId,this.publisher=a.publisher;}getDefaultHeaders(){return E(b({},super.getDefaultHeaders()),{Authorization:`Bearer ${this.accessToken}`})}getModelPricing(){if(!(this.modelName in x))throw new I({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return x[this.modelName]}};var Et="gemini-1.5-flash-001",vt=E(b({},Ee),{price:x[Et]}),wn=G,Ge=class extends v{constructor(e){super(vt,e);}};var Ct="gemini-1.5-flash-002",St=E(b({},ve),{price:x[Ct]}),Rn=G,Ie=class extends v{constructor(e){super(St,e);}};var Ot="gemini-1.5-flash",wt=E(b({},Ce),{price:x[Ot]}),Gn=G,je=class extends v{constructor(e){super(wt,e);}};var Rt="gemini-1.5-pro-001",Gt=E(b({},Se),{price:x[Rt]}),In=G,Ne=class extends v{constructor(e){super(Gt,e);}};var It="gemini-1.5-pro-002",jt=E(b({},Oe),{price:x[It]}),jn=G,Fe=class extends v{constructor(e){super(jt,e);}};var Nt="gemini-1.5-pro",Ft=E(b({},we),{price:x[Nt]}),Nn=G,Le=class extends v{constructor(e){super(Ft,e);}};var Lt="gemini-2.0-flash-exp",Ut=E(b({},Re),{price:x[Lt]}),Fn=G,Ue=class extends v{constructor(e){super(Ut,e);}};var ie=[O],ae=zod.z.enum([O]);var qn=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 Q=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()}),J=class{constructor(e,o){this.version="v1";let i=Q.parse(o);this.modelSchema=e,this.modelName=i.modelName,this.accessToken=i.accessToken;let a;if(i.baseUrl)a=i.baseUrl;else if(i.location&&i.projectId)a=re.baseUrl(i.location,i.projectId,i.publisher);else throw new _e({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/${i.modelName}:predict`,this.location=i.location,this.projectId=i.projectId;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`}}getDefaultParams(){return {}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((o,i)=>o+i.length,0)}transformModelRequest(e){var l,c,u,g;let o=An.safeParse(e);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let i=o.data,a=i.model,d={autoTruncate:((l=i.parameters)==null?void 0:l.auto_truncate)||((c=i.parameters)==null?void 0:c.autoTruncate),dimensions:((u=i.parameters)==null?void 0:u.output_dimensionality)||((g=i.parameters)==null?void 0:g.outputDimensionality)},r=ge().parse(ye(d)),m={modality:O,requests:i.instances.map(h=>h.content)};return {modelName:a,config:r,embeddingRequests:m}}transformConfig(e,o){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 a=i.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}',
18
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),{parameters:Object.keys(a).reduce((r,m)=>{let c=this.modelSchema.config.def[m].param,u=a[m];return r[c]=u,r},{})}}transformEmbeddingRequests(e){let o=Me().safeParse(e);if(!o.success)throw new ne({info:"Invalid embedding requests",cause:o.error});if(e.modality!==O)throw new ne({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${O}' modality is supported for model : '${this.modelName}'`)});return {instances:o.data.requests.map(a=>({content:a}))}}getGetEmbeddingsUrl(e,o){return Te(this,null,function*(){return new Promise(i=>{i(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return Te(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return Te(this,null,function*(){return new Promise(i=>{if(o.requests.length===0)throw new ne({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});i(b(b(b({},this.getDefaultParams()),this.transformConfig(e)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o=qn.safeParse(e);if(o.success){let a=o.data.predictions.map((d,r)=>({index:r,embedding:d.embeddings.values}));return {encodingFormat:he,embeddings:a}}throw new I({info:"Invalid response from model",cause:o.error})}};var Kt=t=>K({param:"output_dimensionality",title:ce.DIMENSIONS.title,description:ce.DIMENSIONS.description,min:1,max:t,step:1,default:t}),Yt=Pe({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=t=>zod.z.object({dimensions:Kt(t).schema,autoTruncate:Yt.schema}),Hn=t=>({dimensions:Kt(t).def,autoTruncate:Yt.def});var A={base:t=>({def:Hn(t),schema:Bn(t)})};var $t="text-embedding-004",Zs="text-embedding-004",Dt=z(ae).parse({name:$t,description:Zs,modalities:ie,maxInputTokens:2048,maxOutputTokens:768,config:{def:A.base(768).def,schema:A.base(768).schema}}),Ln=Q,$e=class extends J{constructor(e){super(Dt,e);}};var qt="text-multilingual-embedding-002",Qs="text-multilingual-embedding-002",At=z(ae).parse({name:qt,description:Qs,modalities:ie,maxInputTokens:2048,maxOutputTokens:768,config:{def:A.base(768).def,schema:A.base(768).schema}}),Un=Q,De=class extends J{constructor(e){super(At,e);}};var Bt="textembedding-gecko-multilingual@001",er="textembedding-gecko-multilingual@001",Ht=z(ae).parse({name:Bt,description:er,modalities:ie,maxInputTokens:2048,maxOutputTokens:768,config:{def:A.base(768).def,schema:A.base(768).schema}}),$n=Q,qe=class extends J{constructor(e){super(Ht,e);}};var zt="textembedding-gecko@003",tr="textembedding-gecko@003",Vt=z(ae).parse({name:zt,description:tr,modalities:ie,maxInputTokens:2048,maxOutputTokens:768,config:{def:A.base(768).def,schema:A.base(768).schema}}),Dn=Q,Ae=class extends J{constructor(e){super(Vt,e);}};
5
+ var zn=Object.defineProperty,Vn=Object.defineProperties;var Kn=Object.getOwnPropertyDescriptors;var Jt=Object.getOwnPropertySymbols;var Yn=Object.prototype.hasOwnProperty,Wn=Object.prototype.propertyIsEnumerable;var He=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Jn=e=>{throw TypeError(e)};var Xt=(e,t,n)=>t in e?zn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,b=(e,t)=>{for(var n in t||(t={}))Yn.call(t,n)&&Xt(e,n,t[n]);if(Jt)for(var n of Jt(t))Wn.call(t,n)&&Xt(e,n,t[n]);return e},E=(e,t)=>Vn(e,Kn(t));var Te=(e,t,n)=>new Promise((i,a)=>{var m=l=>{try{d(n.next(l));}catch(c){a(c);}},r=l=>{try{d(n.throw(l));}catch(c){a(c);}},d=l=>l.done?i(l.value):Promise.resolve(l.value).then(m,r);d((n=n.apply(e,t)).next());}),Xn=function(e,t){this[0]=e,this[1]=t;};var Zt=e=>{var t=e[He("asyncIterator")],n=!1,i,a={};return t==null?(t=e[He("iterator")](),i=m=>a[m]=r=>t[m](r)):(t=t.call(e),i=m=>a[m]=r=>{if(n){if(n=!1,m==="throw")throw r;return r}return n=!0,{done:!1,value:new Xn(new Promise(d=>{var l=t[m](r);l instanceof Object||Jn("Object expected"),d(l);}),1)}}),a[He("iterator")]=()=>a,i("next"),"throw"in t?i("throw"):a.throw=m=>{throw m},"return"in t&&i("return"),a};var ue="system",V="user",q="assistant",ee="tool",Zn=[ue,V,q,ee],Ke=zod.z.enum(Zn),Qn=[q],ei=zod.z.enum(Qn),te="image",Ye="base64",ti=["png","jpeg","webp","gif"],oi=zod.z.object({type:zod.z.literal(Ye),base64:zod.z.string(),mediaType:zod.z.enum(ti)}),ni="url",ii=zod.z.object({type:zod.z.literal(ni),url:zod.z.string()}),ai=zod.z.discriminatedUnion("type",[oi,ii]),si=["low","medium","high","auto"],ri=zod.z.enum(si),li=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(te),detail:ri,value:ai,metadata:e}),se="pdf",mi="base64",di=zod.z.object({type:zod.z.literal(mi),base64:zod.z.string()}),ci="url",pi=zod.z.object({type:zod.z.literal(ci),url:zod.z.string()}),ui=zod.z.discriminatedUnion("type",[di,pi]),gi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(se),value:ui,file:zod.z.object({name:zod.z.string(),id:zod.z.string(),size:zod.z.number().optional()}),metadata:e}),oo="reasoning",no="partial-reasoning",io="thinking",hi="redacted",Ve=zod.z.object({type:zod.z.literal(io),thinking:zod.z.string(),signature:zod.z.string()}),ao=zod.z.object({type:zod.z.literal(hi),data:zod.z.string()}),fi=zod.z.discriminatedUnion("type",[Ve,ao]),yi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(oo),value:fi,metadata:e}),bi=zod.z.object({type:zod.z.literal(io),thinking:Ve.shape.thinking.optional(),signature:Ve.shape.signature.optional()}),Ti=zod.z.discriminatedUnion("type",[bi,ao]),Mi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(no),value:Ti,metadata:e}),S="text",so=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(S),value:zod.z.string(),metadata:e}),We="partial-text",ro=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(We),value:zod.z.string(),metadata:e}),B="tool-call",lo=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(B),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}),Je="partial-tool-call",mo=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Je),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}),oe="tool-response",Pi=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(oe),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}),_i="partial-tool-response",ki=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_i),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}),xi=[S,te,se,B,oe,oo],co=zod.z.enum(xi),Ei=(e=zod.z.undefined(),t=zod.z.undefined(),n=zod.z.undefined(),i=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[so(e),li(t),gi(n),lo(i),Pi(a),yi(m)]),vi=[We,Je,no];zod.z.enum(vi);var Ci=(e=zod.z.undefined(),t=zod.z.undefined(),n=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[ro(e),mo(t),Mi(n),ki(i)]);var Xe=(e=Ke,t=zod.z.undefined(),n=zod.z.undefined(),i=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(Ei(t,n,i,a,r,m)),metadata:d}),Ze=(e=ei,t=zod.z.undefined(),n=zod.z.undefined(),i=zod.z.undefined(),a=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:e,partialContent:Ci(t,n,i,m),metadata:a}),Si=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Qt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Oi=Qt.extend({topLogProbs:zod.z.array(Qt)}),po=zod.z.array(Oi);zod.z.object({messages:zod.z.array(Xe()),usage:Si.optional(),logProbs:po.optional()});var wi=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(Ze()),usage:wi.optional(),logProbs:po.optional()});var ge=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,Ri=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:Ri.optional(),authorizationToken:zod.z.string().min(1).optional()});var Gi=["object","array","number","string","boolean","enum"],eo=zod.z.enum(Gi),Ii=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([eo,zod.z.array(zod.z.union([eo,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()}),ji=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(Ii),additionalProperties:zod.z.literal(!1)}),uo=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:ji}).optional(),O="text",go="token",Ni=[O,go],ho=zod.z.enum(Ni),Fi=zod.z.array(zod.z.string().min(1)),Li=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(O),metadata:e,requests:Fi}),zod.z.object({modality:zod.z.literal(go),metadata:e,requests:Li})]),he="float",Ui=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),$i="base64",Di=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),to=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(he),embeddings:zod.z.array(Ui),usage:to.optional()}),zod.z.object({encodingFormat:zod.z.literal($i),embeddings:zod.z.array(Di),usage:to.optional()})]);var qi=e=>{let t=new WeakSet;return JSON.stringify(e,(n,i)=>{if(typeof i=="object"&&i!==null){if(t.has(i))return;t.add(i);}return i})},Ai=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:qi(e),ze="GatewayBaseError",J=class fo extends Error{constructor({info:t,cause:n},i){super(`[${i!=null?i:ze}]: ${t}
6
+ Message: ${Ai(n)}`),this.name=ze,this.info=t,this.cause=n,this.name=i!=null?i:ze,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof fo}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Bi=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."),Hi=zod.z.object({base:Bi.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),zi=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:Hi.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(zi).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((e,t)=>{let{tokenRanges:n}=e;n[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<n.length;a++){let m=n[a-1],r=n[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 i=n[n.length-1];n.every(a=>a.maxTokens!==null||a===i)&&i.maxTokens!==null&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",n.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 Vi="function";var Ki=zod.z.enum(["object","array","number","string","boolean","null"]),Yi=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Ki.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(Yi).optional(),required:zod.z.array(zod.z.string()).optional()});var Wi=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 Ji=zod.z.enum(["function"]),Xi=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),Zi=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:Xi.optional()}),Qi=zod.z.discriminatedUnion("type",[Zi]),ea=zod.z.object({type:Ji,definition:zod.z.object({schema:Wi}),request:Qi.optional()}),ta=[Vi];zod.z.enum(ta);var yo=(e=zod.z.undefined())=>zod.z.discriminatedUnion("type",[ea.extend({metadata:e})]),bo=e=>so().parse({modality:S,value:e}),To=(e,t,n,i,a)=>lo().parse({modality:B,index:e,id:t,name:n,arguments:i,serverName:a});var Qe=(e,t)=>Ze().parse({role:e,partialContent:ro().parse({modality:We,value:t})}),et=(e,t,n,i,a,m)=>Ze().parse({role:e,partialContent:mo().parse({modality:Je,index:t,id:n,name:i,arguments:a,serverName:m})});var oa=Object.defineProperty,Mo=Object.getOwnPropertySymbols,na=Object.prototype.hasOwnProperty,ia=Object.prototype.propertyIsEnumerable,Po=(e,t,n)=>t in e?oa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fe=(e,t)=>{for(var n in t||(t={}))na.call(t,n)&&Po(e,n,t[n]);if(Mo)for(var n of Mo(t))ia.call(t,n)&&Po(e,n,t[n]);return e},_o="ProviderError",de=class wo extends J{constructor({info:t,cause:n}){super({info:t,cause:n},_o),this.name=_o,this.info=t,this.cause=n;}static isProviderError(t){return t instanceof wo}},ko="ModelError",Pe=class Ro extends J{constructor({info:t,cause:n}){super({info:t,cause:n},ko),this.name=ko,this.info=t,this.cause=n;}static isModelError(t){return t instanceof Ro}},xo="ModelResponseError",I=class Go extends J{constructor({info:t,cause:n}){super({info:t,cause:n},xo),this.name=xo,this.cause=n,this.info=t;}static isModelResponseError(t){return t instanceof Go}},Eo="InvalidModelRequestError",X=class Io extends J{constructor({info:t,cause:n}){super({info:t,cause:n},Eo),this.name=Eo,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Io}},vo="InvalidConfigError",H=class jo extends J{constructor({info:t,cause:n}){super({info:t,cause:n},vo),this.name=vo,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof jo}},Co="InvalidMessagesError",T=class No extends J{constructor({info:t,cause:n}){super({info:t,cause:n},Co),this.name=Co,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof No}},So="InvalidToolsError",tt=class Fo extends J{constructor({info:t,cause:n}){super({info:t,cause:n},So),this.name=So,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof Fo}},Oo="InvalidEmbeddingRequestsError",ne=class Lo extends J{constructor({info:t,cause:n}){super({info:t,cause:n},Oo),this.name=Oo,this.info=t,this.cause=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Lo}},ot="multi-string",Uo=zod.z.object({type:zod.z.literal(ot),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()}),aa=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),$o=e=>({def:Uo.parse(fe({type:ot},e)),schema:aa(e.max)}),nt="object-schema",Do=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),objectSchema:zod.z.any()}),sa=e=>e.optional(),it=e=>({def:Do.parse(fe({type:nt},e)),schema:sa(e.objectSchema)}),at="range",qo=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),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),ra=(e,t,n,i)=>zod.z.number().min(e).max(t).step(n).default(i).optional(),K=e=>({def:qo.parse(fe({type:at},e)),schema:ra(e.min,e.max,e.step,e.default)}),st="select-boolean",Ao=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.boolean().nullable()}),la=e=>zod.z.boolean().nullable().default(e).optional(),_e=e=>({def:Ao.parse(fe({type:st},e)),schema:la(e.default)}),rt="select-string",Bo=zod.z.object({type:zod.z.literal(rt),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())}),ma=(e,t)=>zod.z.enum(t).nullable().default(e).optional(),lt=e=>({def:Bo.parse(fe({type:rt},e)),schema:ma(e.default,e.choices)}),da=[at,ot,rt,nt,st];zod.z.enum(da);var Ho=zod.z.discriminatedUnion("type",[qo,Uo,Bo,Ao,Do]),j=(e=Ke,t=co)=>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),Ho),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(n=>{var i,a;let m=Object.keys(n.def),r=Object.keys((a=(i=n.schema)==null?void 0:i.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()}),z=(e=ho)=>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),Ho),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var n,i;let a=Object.keys(t.def),m=Object.keys((i=(n=t.schema)==null?void 0:n.shape)!=null?i:{});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 ca={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."},pa={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."},ua={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},ga=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.`}),ha={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."},fa={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."},ya={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."},ba={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."},Ta={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."},Ma={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."},Pa={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."},_a={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."},ka={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."},xa={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."},Ea={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},va={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."},Ca={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."},Sa={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."},Oa={type:"object",title:"MCP servers",description:"MCP servers to use for the model."},P={TEMPERATURE:ca,MAX_TOKENS:pa,STOP:ga,TOP_A:ha,TOP_P:fa,TOP_K:ya,MIN_P:ba,FREQUENCY_PENALTY:Ta,PRESENCE_PENALTY:Ma,REPETITION_PENALTY:_a,SEED:Pa,LOG_PROBS:ka,TOP_LOG_PROBS:xa,ECHO:Ea,RESPONSE_FORMAT:va,RESPONSE_FORMAT_WITH_SCHEMA:Ca,RESPONSE_SCHEMA:Sa,MAX_REASONING_TOKENS:ua,MCP_SERVERS:Oa},wa={type:"range",title:"Dimensions",description:"Select the number of dimensions for the word embedding."},Ra={type:"select",title:"Encoding format",description:"Select the encoding format for the word embedding."},ce={DIMENSIONS:wa,ENCODING_FORMAT:Ra};var ye=e=>Object.fromEntries(Object.entries(e).filter(([t,n])=>n!=null)),mt=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined",zo=e=>{let t=e.replace(/-/g,"+").replace(/_/g,"/"),n=globalThis.atob(t);return Uint8Array.from(n,i=>i.codePointAt(0))};var pe=e=>e==null?void 0:e.replace(/\/$/,"");var Ga=Object.defineProperty,Ia=Object.defineProperties,ja=Object.getOwnPropertyDescriptors,Vo=Object.getOwnPropertySymbols,Na=Object.prototype.hasOwnProperty,Fa=Object.prototype.propertyIsEnumerable,ke=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),La=e=>{throw TypeError(e)},Ko=(e,t,n)=>t in e?Ga(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,M=(e,t)=>{for(var n in t||(t={}))Na.call(t,n)&&Ko(e,n,t[n]);if(Vo)for(var n of Vo(t))Fa.call(t,n)&&Ko(e,n,t[n]);return e},be=(e,t)=>Ia(e,ja(t)),_=(e,t,n)=>new Promise((i,a)=>{var m=l=>{try{d(n.next(l));}catch(c){a(c);}},r=l=>{try{d(n.throw(l));}catch(c){a(c);}},d=l=>l.done?i(l.value):Promise.resolve(l.value).then(m,r);d((n=n.apply(e,t)).next());}),en=function(e,t){this[0]=e,this[1]=t;},Yo=(e,t,n)=>{var i=(r,d,l,c)=>{try{var u=n[r](d),g=(d=u.value)instanceof en,h=u.done;Promise.resolve(g?d[0]:d).then(y=>g?i(r==="return"?r:"next",d[1]?{done:y.done,value:y.value}:y,l,c):l({value:y,done:h})).catch(y=>i("throw",y,l,c));}catch(y){c(y);}},a=r=>m[r]=d=>new Promise((l,c)=>i(r,d,l,c)),m={};return n=n.apply(e,t),m[ke("asyncIterator")]=()=>m,a("next"),a("throw"),a("return"),m},Ua=e=>{var t=e[ke("asyncIterator")],n=!1,i,a={};return t==null?(t=e[ke("iterator")](),i=m=>a[m]=r=>t[m](r)):(t=t.call(e),i=m=>a[m]=r=>{if(n){if(n=!1,m==="throw")throw r;return r}return n=!0,{done:!1,value:new en(new Promise(d=>{var l=t[m](r);l instanceof Object||La("Object expected"),d(l);}),1)}}),a[ke("iterator")]=()=>a,i("next"),"throw"in t?i("throw"):a.throw=m=>{throw m},"return"in t&&i("return"),a},tn=(e,t)=>K({param:"temperature",title:P.TEMPERATURE.title,description:P.TEMPERATURE.description,min:0,max:e,step:.01,default:t}),on=e=>K({param:"maxOutputTokens",title:P.MAX_TOKENS.title,description:P.MAX_TOKENS.description,min:0,max:e,step:1,default:0}),nn=e=>$o({param:"stopSequences",title:P.STOP(e).title,description:P.STOP(e).description,max:e}),an=e=>K({param:"topP",title:P.TOP_P.title,description:P.TOP_P.description,min:0,max:1,step:.01,default:e});K({param:"frequencyPenalty",title:P.FREQUENCY_PENALTY.title,description:P.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0});K({param:"presencePenalty",title:P.PRESENCE_PENALTY.title,description:P.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0});K({param:"seed",title:P.SEED.title,description:P.SEED.description,min:0,max:1e6,step:1,default:0});var sn=lt({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"]}),rn=it({param:"safetySettings",title:"Safety settings",description:"The safety rating contains the category of harm and the harm probability level in that category for a piece of content.",objectSchema:zod.z.array(zod.z.object({threshold:zod.z.enum(["HARM_BLOCK_THRESHOLD_UNSPECIFIED","BLOCK_LOW_AND_ABOVE","BLOCK_MEDIUM_AND_ABOVE","BLOCK_ONLY_HIGH","BLOCK_NONE","OFF"]),category:zod.z.enum(["HARM_CATEGORY_UNSPECIFIED","HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT","HARM_CATEGORY_CIVIC_INTEGRITY"])}))}),ln=_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}),mn=(e,t,n,i,a)=>zod.z.object({temperature:tn(e,t).schema,maxTokens:on(n).schema,stop:nn(i).schema,topP:an(a).schema,toolChoice:sn.schema,safetySettings:rn.schema}),dn=(e,t,n,i,a)=>({temperature:tn(e,t).def,maxTokens:on(n).def,stop:nn(i).def,topP:an(a).def,toolChoice:sn.def,safetySettings:rn.def}),cn=it({param:"response_schema",title:P.RESPONSE_SCHEMA.title,description:P.RESPONSE_SCHEMA.description,objectSchema:uo}),pn=lt({param:"response_format",title:P.RESPONSE_FORMAT_WITH_SCHEMA.title,description:P.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_schema"]}),un=(e,t,n,i,a)=>be(M({},dn(e,t,n,i,a)),{responseFormat:pn.def,responseSchema:cn.def}),gn=(e,t,n,i,a)=>mn(e,t,n,i,a).extend({responseFormat:pn.schema,responseSchema:cn.schema}),$a=(e,t,n,i,a)=>gn(e,t,n,i,a).extend({reasoningEnabled:ln.schema}),Da=(e,t,n,i,a)=>be(M({},un(e,t,n,i,a)),{reasoningEnabled:ln.def}),hn=e=>K({param:"outputDimensionality",title:ce.DIMENSIONS.title,description:ce.DIMENSIONS.description,min:1,max:e,step:1,default:e}),qa=e=>zod.z.object({dimensions:hn(e).schema}),Aa=e=>({dimensions:hn(e).def}),f={base:(e,t,n,i,a)=>({def:dn(e,t,n,i,a),schema:mn(e,t,n,i,a)}),responseSchema:(e,t,n,i,a)=>({def:un(e,t,n,i,a),schema:gn(e,t,n,i,a)}),reasoning:(e,t,n,i,a)=>({def:Da(e,t,n,i,a),schema:$a(e,t,n,i,a)})},xe={base:e=>({def:Aa(e),schema:qa(e)})},Ba="google",kt=class{constructor(){this.version="v1",this.name=Ba,this.chatModelFactories={[dt]:{model:ss,modelOptions:as,modelSchema:Ee},[ct]:{model:ms,modelOptions:ls,modelSchema:ve},[pt]:{model:ps,modelOptions:cs,modelSchema:yn},[ut]:{model:hs,modelOptions:gs,modelSchema:Ce},[gt]:{model:bs,modelOptions:ys,modelSchema:Se},[ht]:{model:Ps,modelOptions:Ms,modelSchema:Oe},[ft]:{model:xs,modelOptions:ks,modelSchema:bn},[yt]:{model:Cs,modelOptions:vs,modelSchema:we},[bt]:{model:ws,modelOptions:Os,modelSchema:Re},[Tt]:{model:Is,modelOptions:Gs,modelSchema:Tn},[Mt]:{model:Fs,modelOptions:Ns,modelSchema:Mn},[Pt]:{model:$s,modelOptions:Us,modelSchema:Pn},[_t]:{model:As,modelOptions:qs,modelSchema:_n}},this.embeddingModelFactories={[vn]:{model:Ys,modelOptions:Ks,modelSchema:Cn},[Sn]:{model:Xs,modelOptions:Js,modelSchema:On}};}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 de({info:`Google chat model: ${t} not found`,cause:new Error(`Google chat model: ${t} not found, available chat models:
7
+ [${this.chatModelLiterals().join(", ")}]`)});let n=this.chatModelFactories[t].model,i=this.chatModelFactories[t].modelOptions.parse(e);return new n(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,t)=>(e[t]=this.embeddingModelFactories[t].modelSchema,e),{})}embeddingModel(e){let t=e.modelName;if(!(t in this.embeddingModelFactories))throw new de({info:`Google embedding model: ${t} not found`,cause:new Error(`Google embedding model: ${t} not found, available embedding models:
8
+ [${this.embeddingModelLiterals().join(", ")}]`)});let n=this.embeddingModelFactories[t].model,i=this.embeddingModelFactories[t].modelOptions.parse(e);return new n(i)}};kt.baseUrl="https://generativelanguage.googleapis.com/v1beta";var w={"base-gemini-1-chat-model":{modelName:"base-gemini-1-chat-model",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:0,outputPricePerMillion:0}}}]},"gemini-1.0-pro-001":{modelName:"gemini-1.0-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-latest":{modelName:"gemini-1.0-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-vision":{modelName:"gemini-1.0-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro":{modelName:"gemini-1.0-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.5-flash-001":{modelName:"gemini-1.5-flash-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash-002":{modelName:"gemini-1.5-flash-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.0375,outputPricePerMillion:.15}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}}]},"gemini-1.5-flash-latest":{modelName:"gemini-1.5-flash-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash":{modelName:"gemini-1.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-pro-001":{modelName:"gemini-1.5-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-002":{modelName:"gemini-1.5-pro-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-latest":{modelName:"gemini-1.5-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro":{modelName:"gemini-1.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-2.0-flash-exp":{modelName:"gemini-2.0-flash-exp",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-2.5-flash-preview-04-17":{modelName:"gemini-2.5-flash-preview-04-17",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-2.5-pro-preview-03-25":{modelName:"gemini-2.5-pro-preview-03-25",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:15}}}]},"gemini-pro-vision":{modelName:"gemini-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-pro":{modelName:"gemini-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-2.5-pro":{modelName:"gemini-2.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}}]},"gemini-2.5-flash":{modelName:"gemini-2.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.3,outputPricePerMillion:2.5}}}]}},F=zod.z.enum([ue,V,q,ee]),Ha="model",za="function",L={system:V,user:V,assistant:Ha,tool:za},U=[S,te,se,B,oe],$=zod.z.enum([S,te,se,B,oe]);zod.z.enum([S]);zod.z.enum([S,te]);zod.z.enum([S,B,oe]);var Va=zod.z.object({text:zod.z.string()}),Ka=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Ya=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([Va,Ka]))}).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()}),Wa=zod.z.object({text:zod.z.string()}),Ja=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Wo=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([Wa,Ja]))}).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()}),fn=zod.z.object({text:zod.z.string().min(1)}),Xa=zod.z.object({inline_data:zod.z.object({mime_type:zod.z.string().min(1),data:zod.z.string().base64()})}),Za=zod.z.object({file_data:zod.z.object({mime_type:zod.z.string().min(1),file_uri:zod.z.string().min(1)})}),Qa=zod.z.object({function_call:zod.z.object({name:zod.z.string().min(1),args:zod.z.record(zod.z.string().min(1))})}),es=zod.z.object({function_response:zod.z.object({name:zod.z.string().min(1),response:zod.z.record(zod.z.string().min(1))})}),ts=zod.z.object({role:zod.z.enum(["user","model","function"]),parts:zod.z.array(zod.z.union([fn,Xa,Za,Qa,es]))}),Jo=zod.z.object({parts:zod.z.array(fn)}),os=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),parameters:zod.z.any()}),Xo=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()}),Qo=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"])}),ns=zod.z.object({model:zod.z.string().min(1).optional(),contents:zod.z.array(ts),systemInstruction:Jo.optional(),system_instruction:Jo.optional(),generationConfig:Zo.optional(),generation_config:Zo.optional(),safetySettings:zod.z.array(Qo).optional(),safety_settings:zod.z.array(Qo).optional(),tools:zod.z.object({function_declarations:zod.z.array(os)}).optional(),toolConfig:Xo.optional(),tool_config:Xo.optional()}),N=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()}),R=class{constructor(e,t){this.version="v1";var n;let i=N.parse(t);this.modelSchema=e,this.modelName=i.modelName,this.apiKey=i.apiKey,this.baseUrl=pe((n=i.baseUrl)!=null?n:kt.baseUrl),this.completeChatUrl=pe(i.completeChatUrl||`${this.baseUrl}/models/${this.modelName}:generateContent?key=${this.apiKey}`),this.streamChatUrl=pe(i.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,n)=>t+n.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformPdfMessages(e){return _(this,null,function*(){let t=r=>_(this,null,function*(){let d={};mt()||(d["User-Agent"]="Mozilla/5.0 (compatible; GoogleFilesAPI/1.0)");let l=yield fetch(r,{headers:d});if(!l.ok)throw new T({info:`Failed to download PDF from URL: ${r}`,cause:new Error(`HTTP ${l.status}: ${l.statusText}`)});let c=yield l.arrayBuffer();return new Uint8Array(c)}),n=r=>_(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(c=>c.displayName===r);return l?l.uri:null}catch(d){return null}}),i=(r,d)=>_(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 T({info:"Failed to start PDF upload to Google Files API",cause:new Error(`HTTP ${l.status}: ${l.statusText}`)});let c=l.headers.get("x-goog-upload-url");if(!c)throw new T({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"};mt()||(u["Content-Length"]=r.length.toString());let g=yield fetch(c,{method:"POST",headers:u,body:r});if(!g.ok)throw new T({info:"Failed to upload PDF content to Google Files API",cause:new Error(`HTTP ${g.status}: ${g.statusText}`)});return (yield g.json()).file.uri}),a=r=>_(this,null,function*(){let d=yield n(r.file.id);if(d)return d;let l;if(r.value.type==="url")l=yield t(r.value.url);else {let c=r.value.base64,u="data:application/pdf;base64,";c=c.startsWith(u)?c.substring(u.length):c,l=zo(c);}return yield i(l,r.file.id)}),m=[];for(let r of e){let d=[];for(let l of r.content)if(l.modality===se){let c=yield a(l);d.push(be(M({},l),{value:{type:"url",url:c}}));}else d.push(l);m.push(be(M({},r),{content:d}));}return m})}transformModelRequest(e){let t=ns.safeParse(e);if(!t.success)throw new X({info:"Invalid model request",cause:t.error});let n=t.data,i=n.model;if(n.system_instruction&&n.systemInstruction)throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'system_instruction' and 'systemInstruction' are not allowed at the same time")});if(n.generation_config&&n.generationConfig)throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'generation_config' and 'generationConfig' are not allowed at the same time")});if(n.tool_config&&n.toolConfig)throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tool_config' and 'toolConfig' are not allowed at the same time")});let a=n.system_instruction||n.systemInstruction,m=n.generation_config||n.generationConfig,r=n.safety_settings||n.safetySettings,d=n.tool_config||n.toolConfig;if(d&&(!n.tools||n.tools.function_declarations.length===0))throw new X({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 c=ge().parse(ye(l)),u=[];a&&a.parts.forEach(h=>{u.push({role:ue,content:[{modality:S,value:h.text}]});}),n.contents.forEach(h=>{let y=h.role;switch(y){case"user":{let C=h.parts.map(k=>"text"in k?{modality:S,value:k.text}:{modality:te,detail:"auto",value:{type:Ye,base64:k.inline_data.data,mediaType:k.inline_data.mime_type.split("/")[1]}});u.push({role:y,content:C});}break;case"model":{let C=h.parts.map((k,D)=>"text"in k?{modality:S,value:k.text}:{modality:B,id:D.toString(),index:D,name:k.function_call.name,arguments:JSON.stringify(k.function_call.args)});u.push({role:q,content:C});}break;case"function":{let C=h.parts.map((k,D)=>({modality:oe,id:D.toString(),index:D,name:k.function_response.name,data:JSON.stringify(k.function_response.response)}));u.push({role:ee,content:C});}break;default:throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${h.role}' is not supported for model : ${this.modelName}`)})}});let g=[];return n.tools&&n.tools.function_declarations.forEach(h=>{g.push({type:"function",definition:{schema:{name:h.name,description:h.description,parameters:h.parameters}}});}),{modelName:i,config:c,messages:u,tools:g.length>0?g:void 0}}transformConfig(e,t,n){let i=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(c=>{if(!(c in this.modelSchema.config.def))throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${c}',
9
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((c,u)=>{let g=this.modelSchema.config.def[u],h=g.param,y=m[u];return u==="reasoningEnabled"?c.thinkingConfig={includeThoughts:y}:u==="maxReasoningTokens"?c.thinkingConfig=c.thinkingConfig&&typeof c.thinkingConfig=="object"?be(M({},c.thinkingConfig),{thinkingBudget:y}):{thinkingBudget:y}:h==="maxOutputTokens"&&g.type==="range"&&y===0?c[h]=g.max:c[h]=y,c},{}),d=r.safetySettings;delete r.safetySettings;let l;if(i!==void 0){let c=i;if(!n||n&&n.length===0)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(n&&n.length>0){let u=this.modelSchema.config.def.toolChoice;if(u.choices.includes(c))c==="any"?l={function_calling_config:{mode:"ANY",allowed_function_names:n.map(g=>g.definition.schema.name)}}:l={function_calling_config:{mode:c.toUpperCase()}};else if(n.map(g=>g.definition.schema.name).includes(c))l={function_calling_config:{mode:"ANY",allowed_function_names:[c]}};else throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${c}' is not part of provided 'tools' names or
10
+ one of [${u.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let c=r.response_format;if(c==="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 c==="json_object"?(r.responseSchema={type:"object"},delete r.response_format):c==="text"&&delete r.response_format;}return M(M({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},n=e.map(r=>{let d=Xe().safeParse(r);if(!d.success)throw new T({info:"Invalid messages",cause:d.error});return d.data});n.forEach(r=>{r.content.forEach(d=>{if(!this.modelSchema.modalities.includes(d.modality))throw new T({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${d.modality}',
11
+ available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),n.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new T({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}',
12
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let i={parts:[]},a=[];if(n.forEach(r=>{switch(r.role){case ue:r.content.forEach(d=>{if(d.modality===S)i.parts.push({text:d.value});else throw new T({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 q:{let d=[];r.content.forEach(l=>{if(l.modality===S)d.push({text:l.value});else if(l.modality===B)d.push({function_call:{name:l.name,args:JSON.parse(l.arguments)}});else throw new T({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 V:{let d=[];r.content.forEach(l=>{if(l.modality===S)d.push({text:l.value});else if(l.modality===te){if(l.value.type==="base64"){let c=l.value.base64;c=t(c),d.push({inline_data:{mime_type:`image/${l.value.mediaType}`,data:c}});}else if(l.value.type==="url")throw new T({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===se)if(l.value.type==="base64"){let c=l.value.base64;c=t(c),d.push({inline_data:{mime_type:"application/pdf",data:c}});}else l.value.type==="url"&&d.push({file_data:{mime_type:"application/pdf",file_uri:l.value.url}});else throw new T({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 ee:{let d=[];r.content.forEach(l=>{if(l.modality===oe)d.push({function_response:{name:l.name,response:JSON.parse(l.data)}});else throw new T({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 T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
13
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),a[0].role!==this.modelSchema.roles[V])throw new T({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[V]||r===this.modelSchema.roles[ee]?[this.modelSchema.roles[q]]:[this.modelSchema.roles[V],this.modelSchema.roles[ee]];for(let r=1;r<a.length;r++)if(!m(a[r-1].role).includes(a[r].role))throw new T({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[V]&&a[a.length-1].role!==this.modelSchema.roles[ee])throw new T({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return M({contents:a},i.parts.length>0?{system_instruction:i}:{})}transformTools(e){if(!this.modelSchema.modalities.includes(B))throw new tt({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${B}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:[{function_declarations:e.map(t=>{let n=yo().safeParse(t);if(!n.success)throw new tt({info:"Invalid tools",cause:n.error});return n.data}).map(t=>({name:t.definition.schema.name,description:t.definition.schema.description,parameters:t.definition.schema.parameters}))}]}}getCompleteChatUrl(e,t,n){return _(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,n){return _(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getCompleteChatData(e,t,n){return _(this,null,function*(){let i=this.transformConfig(e,t,n),a=yield this.transformPdfMessages(t),m=this.transformMessages(a);if(m.messages&&m.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let r=n?this.transformTools(n):{};return M(M(M(M({},this.getDefaultParams()),i),m),r)})}transformCompleteChatResponse(e){let t=Ya.safeParse(e);if(t.success){if(t.data.candidates.length===0)throw new I({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(t.data)}`)});let n=t.data,i=[],a,m=n.candidates[0].content;if(m){let d=m.parts.map((l,c)=>{if("text"in l&&l.text!==void 0)return bo(l.text);if("functionCall"in l&&l.functionCall!==void 0)return To(c,`${l.functionCall.name}_${c}`,l.functionCall.name,JSON.stringify(l.functionCall.args))});return i.push({role:q,content:d}),n.usageMetadata&&(a={promptTokens:n.usageMetadata.promptTokenCount,totalTokens:n.usageMetadata.totalTokenCount,completionTokens:n.usageMetadata.candidatesTokenCount||0}),{messages:i,usage:a,logProbs:void 0}}let r=n.candidates[0].safetyRatings;if(r&&r.length>0&&r.forEach(d=>{if(d.blocked)throw new I({info:`Blocked content for category: ${d.category} with probability: ${d.probability}`,cause:new Error(`Blocked content for category: ${d.category} with probability: ${d.probability}`)})}),n.candidates[0].finishReason==="SAFETY")throw new I({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new I({info:"Invalid response from model",cause:t.error})}getStreamChatUrl(e,t,n){return _(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(e,t,n){return _(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getStreamChatData(e,t,n){return _(this,null,function*(){let i=this.transformConfig(e,t,n),a=yield this.transformPdfMessages(t),m=this.transformMessages(a);if(m.messages&&m.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let r=n?this.transformTools(n):{};return M(M(M(M({},this.getDefaultParams()),i),m),r)})}transformStreamChatResponseChunk(e,t){return Yo(this,null,function*(){let n=(t+e).split(",\r").filter(i=>i.trim()!=="");for(let i of n){let a=i;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=Wo.safeParse(m);if(r.success){let d={partialMessages:[]},l=r.data;if(l.candidates.length>0){let c=l.candidates[0].content;c&&"parts"in c&&c.parts.length>0&&c.parts.forEach((u,g)=>{if("text"in u&&u.text!==void 0&&d.partialMessages.push(Qe(q,u.text)),"functionCall"in u&&u.functionCall!==void 0){let h=u.functionCall;d.partialMessages.push(et(q,g,`${h.name}_${g}`,h.name,JSON.stringify(h.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 I({info:"Invalid response from model",cause:r.error})}yield {partialResponse:{partialMessages:[]},buffer:t};})}transformProxyStreamChatResponseChunk(e,t,n,i,a){return Yo(this,null,function*(){if((a==null?void 0:a.alt)!=="sse"){yield*Zt(Ua(this.transformStreamChatResponseChunk(e,t)));return}let m=t+e,r=[],d="",l=0;for(;l<m.length;){let c=m.indexOf(`
14
+ `,l);if(c===-1){d=m.substring(l);break}else {let u=m.substring(l,c).trim();u&&r.push(u),l=c+1;}}for(let c of r){if(c==="data: [DONE]")return;if(c.startsWith("data: ")){let u=c.substring(6);try{let g=JSON.parse(u),h=Wo.safeParse(g);if(h.success){let y={partialMessages:[]},C=h.data;if(C.candidates.length>0){let k=C.candidates[0].content;k&&"parts"in k&&k.parts.length>0&&k.parts.forEach((D,Wt)=>{if("text"in D&&D.text!==void 0&&y.partialMessages.push(Qe(q,D.text)),"functionCall"in D&&D.functionCall!==void 0){let Be=D.functionCall;y.partialMessages.push(et(q,Wt,`${Be.name}_${Wt}`,Be.name,JSON.stringify(Be.args)));}});}C.usageMetadata&&C.usageMetadata.totalTokenCount&&C.usageMetadata.promptTokenCount&&C.usageMetadata.candidatesTokenCount&&(y.usage={promptTokens:C.usageMetadata.promptTokenCount,completionTokens:C.usageMetadata.candidatesTokenCount,totalTokens:C.usageMetadata.totalTokenCount}),yield {partialResponse:y,buffer:t};}else throw new I({info:"Invalid response from model",cause:h.error})}catch(g){throw new I({info:`Malformed JSON received in stream: ${u}`,cause:g})}}}yield {partialResponse:{partialMessages:[]},buffer:d};})}getProxyCompleteChatUrl(e,t,n){return _(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyStreamChatUrl(e,t,n){return _(this,null,function*(){return new Promise(i=>{if(!n||Object.keys(n).length===0){i(this.streamChatUrl);return}let a=new URL(this.streamChatUrl);Object.entries(n).forEach(([m,r])=>{r!=null&&a.searchParams.set(m,r);}),i(a.toString());})})}getProxyCompleteChatHeaders(e,t,n){return _(this,null,function*(){if(!t)return {};let i=M({},t);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(e,t,n){return _(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,n)})}getModelPricing(){if(!(this.modelName in w))throw new I({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return w[this.modelName]}},dt="gemini-1.5-flash-001",is="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",Ee=j(F,$).parse({name:dt,description:is,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[dt]}),as=N,ss=class extends R{constructor(e){super(Ee,e);}},ct="gemini-1.5-flash-002",rs="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",ve=j(F,$).parse({name:ct,description:rs,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[ct]}),ls=N,ms=class extends R{constructor(e){super(ve,e);}},pt="gemini-1.5-flash-latest",ds="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",yn=j(F,$).parse({name:pt,description:ds,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[pt]}),cs=N,ps=class extends R{constructor(e){super(yn,e);}},ut="gemini-1.5-flash",us="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=j(F,$).parse({name:ut,description:us,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[ut]}),gs=N,hs=class extends R{constructor(e){super(Ce,e);}},gt="gemini-1.5-pro-001",fs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Se=j(F,$).parse({name:gt,description:fs,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[gt]}),ys=N,bs=class extends R{constructor(e){super(Se,e);}},ht="gemini-1.5-pro-002",Ts="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Oe=j(F,$).parse({name:ht,description:Ts,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[ht]}),Ms=N,Ps=class extends R{constructor(e){super(Oe,e);}},ft="gemini-1.5-pro-latest",_s="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",bn=j(F,$).parse({name:ft,description:_s,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[ft]}),ks=N,xs=class extends R{constructor(e){super(bn,e);}},yt="gemini-1.5-pro",Es="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",we=j(F,$).parse({name:yt,description:Es,maxInputTokens:2e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[yt]}),vs=N,Cs=class extends R{constructor(e){super(we,e);}},bt="gemini-2.0-flash-exp",Ss="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",Re=j(F,$).parse({name:bt,description:Ss,maxInputTokens:1e6,maxOutputTokens:8192,roles:L,modalities:U,config:{def:f.responseSchema(2,1,8192,4,.95).def,schema:f.responseSchema(2,1,8192,4,.95).schema},price:w[bt]}),Os=N,ws=class extends R{constructor(e){super(Re,e);}},Tt="gemini-2.5-flash-preview-04-17",Rs="Google's best model in Gemini 2.5 family in terms of price-performance, offering well-rounded capabilities.",Tn=j(F,$).parse({name:Tt,description:Rs,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:f.responseSchema(2,1,65536,4,.95).def,schema:f.responseSchema(2,1,65536,4,.95).schema},price:w[Tt]}),Gs=N,Is=class extends R{constructor(e){super(Tn,e);}},Mt="gemini-2.5-pro-preview-03-25",js="Google's preview model in Gemini 2.5 family for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Mn=j(F,$).parse({name:Mt,description:js,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:f.reasoning(2,1,65536,4,.95).def,schema:f.reasoning(2,1,65536,4,.95).schema},price:w[Mt]}),Ns=N,Fs=class extends R{constructor(e){super(Mn,e);}},Pt="gemini-2.5-flash",Ls="Google's Gemini 2.5 Flash model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Pn=j(F,$).parse({name:Pt,description:Ls,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:f.responseSchema(2,1,65536,4,.95).def,schema:f.responseSchema(2,1,65536,4,.95).schema},price:w[Pt]}),Us=N,$s=class extends R{constructor(e){super(Pn,e);}},_t="gemini-2.5-pro",Ds="Google's Gemini 2.5 Pro model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",_n=j(F,$).parse({name:_t,description:Ds,maxInputTokens:1048576,maxOutputTokens:65536,roles:L,modalities:U,config:{def:f.reasoning(2,1,65536,4,.95).def,schema:f.reasoning(2,1,65536,4,.95).schema},price:w[_t]}),qs=N,As=class extends R{constructor(e){super(_n,e);}},kn=[O],xn=zod.z.enum([O]),Bs=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),Hs=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)})}),zs=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(Hs).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),xt=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),En=class{constructor(e,t){this.version="v1";let n=xt.parse(t);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=pe(n.baseUrl||kt.baseUrl),this.getEmbeddingsUrl=pe(n.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,n)=>t+n.length,0)}transformModelRequest(e){let t=zs.safeParse(e);if(!t.success)throw new X({info:"Invalid model request",cause:t.error});let n=t.data,i=n.model,a={outputDimensionality:n.outputDimensionality},m=ge().parse(ye(a)),r={modality:O,requests:n.requests.reduce((d,l)=>(d.push(...l.content.parts.map(c=>c.text)),d),[])};return {modelName:i,config:m,embeddingRequests:r}}transformConfig(e,t){let n=this.modelSchema.config.schema.safeParse(e);if(!n.success)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let i=n.data;return Object.keys(i).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}',
15
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((a,m)=>{let r=this.modelSchema.config.def[m].param,d=i[m];return a[r]=d,a},{})}transformEmbeddingRequests(e){let t=Me().safeParse(e);if(!t.success)throw new ne({info:"Invalid embedding requests",cause:t.error});if(e.modality!==O)throw new ne({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${O}' modality is supported for model : '${this.modelName}'`)});return {requests:t.data.requests.map(n=>({model:`models/${this.modelName}`,content:{parts:[{text:n}]}}))}}getGetEmbeddingsUrl(e,t){return _(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return _(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return _(this,null,function*(){return new Promise(n=>{let i=this.transformConfig(e),a=this.transformEmbeddingRequests(t);if(t.requests.length===0)throw new ne({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});i.outputDimensionality&&(a.requests.forEach(m=>{m.outputDimensionality=i.outputDimensionality;}),delete i.outputDimensionality),n(M(M(M({},this.getDefaultParams()),i),a));})})}transformGetEmbeddingsResponse(e){let t=Bs.safeParse(e);if(t.success){let n=t.data.embeddings.map((i,a)=>({index:a,embedding:i.values}));return {encodingFormat:he,embeddings:n}}throw new I({info:"Invalid response from model",cause:t.error})}},vn="text-embedding-001",Vs="text-embedding-001",Cn=z(xn).parse({name:vn,description:Vs,modalities:kn,maxInputTokens:2048,maxOutputTokens:768,config:{def:xe.base(768).def,schema:xe.base(768).schema}}),Ks=xt,Ys=class extends En{constructor(e){super(Cn,e);}},Sn="text-embedding-004",Ws="text-embedding-004",On=z(xn).parse({name:Sn,description:Ws,modalities:kn,maxInputTokens:2048,maxOutputTokens:768,config:{def:xe.base(768).def,schema:xe.base(768).schema}}),Js=xt,Xs=class extends En{constructor(e){super(On,e);}};var Zs="vertex",re=class{constructor(){this.version="v1";this.name=Zs;this.chatModelFactories={[Et]:{model:Ge,modelOptions:wn,modelSchema:vt},[Ct]:{model:Ie,modelOptions:Rn,modelSchema:St},[Ot]:{model:je,modelOptions:Gn,modelSchema:wt},[Rt]:{model:Ne,modelOptions:In,modelSchema:Gt},[It]:{model:Fe,modelOptions:jn,modelSchema:jt},[Nt]:{model:Le,modelOptions:Nn,modelSchema:Ft},[Lt]:{model:Ue,modelOptions:Fn,modelSchema:Ut}};this.embeddingModelFactories={[$t]:{model:$e,modelOptions:Ln,modelSchema:Dt},[qt]:{model:De,modelOptions:Un,modelSchema:At},[zt]:{model:Ae,modelOptions:Dn,modelSchema:Vt},[Bt]:{model:qe,modelOptions:$n,modelSchema:Ht}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,n)=>(t[n]=this.chatModelFactories[n].modelSchema,t),{})}chatModel(t){let n=t.modelName;if(!(n in this.chatModelFactories))throw new de({info:`Vertex chat model: ${n} not found`,cause:new Error(`Vertex chat model: ${n} not found, available chat models:
16
+ ${this.chatModelLiterals().join(", ")}`)});let i=this.chatModelFactories[n].model,a=this.chatModelFactories[n].modelOptions.parse(t);return new i(a)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,n)=>(t[n]=this.embeddingModelFactories[n].modelSchema,t),{})}embeddingModel(t){let n=t.modelName;if(!(n in this.embeddingModelFactories))throw new de({info:`Vertex embedding model: ${n} not found`,cause:new Error(`Vertex embedding model: ${n} not found, available embedding models:
17
+ ${this.embeddingModelLiterals().join(", ")}`)});let i=this.embeddingModelFactories[n].model,a=this.embeddingModelFactories[n].modelOptions.parse(t);return new i(a)}};re.baseUrl=(t,n,i="google")=>`https://${t}-aiplatform.googleapis.com/v1/projects/${n}/locations/${t}/publishers/${i}`;var x={"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}}}]}};var G=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()}),v=class extends R{constructor(n,i){let a=G.parse(i),m;if(a.baseUrl)m=a.baseUrl;else if(a.location&&a.projectId)m=re.baseUrl(a.location,a.projectId,a.publisher);else throw new Pe({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(n,{modelName:a.modelName,apiKey:"random-api-key",completeChatUrl:`${m}/models/${a.modelName}:generateContent`,streamChatUrl:`${m}/models/${a.modelName}:streamGenerateContent`});this.version="v1";this.modelSchema=n,this.modelName=a.modelName,this.accessToken=a.accessToken,this.location=a.location,this.projectId=a.projectId,this.publisher=a.publisher;}getDefaultHeaders(){return E(b({},super.getDefaultHeaders()),{Authorization:`Bearer ${this.accessToken}`})}getModelPricing(){if(!(this.modelName in x))throw new I({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return x[this.modelName]}};var Et="gemini-1.5-flash-001",vt=E(b({},Ee),{price:x[Et]}),wn=G,Ge=class extends v{constructor(t){super(vt,t);}};var Ct="gemini-1.5-flash-002",St=E(b({},ve),{price:x[Ct]}),Rn=G,Ie=class extends v{constructor(t){super(St,t);}};var Ot="gemini-1.5-flash",wt=E(b({},Ce),{price:x[Ot]}),Gn=G,je=class extends v{constructor(t){super(wt,t);}};var Rt="gemini-1.5-pro-001",Gt=E(b({},Se),{price:x[Rt]}),In=G,Ne=class extends v{constructor(t){super(Gt,t);}};var It="gemini-1.5-pro-002",jt=E(b({},Oe),{price:x[It]}),jn=G,Fe=class extends v{constructor(t){super(jt,t);}};var Nt="gemini-1.5-pro",Ft=E(b({},we),{price:x[Nt]}),Nn=G,Le=class extends v{constructor(t){super(Ft,t);}};var Lt="gemini-2.0-flash-exp",Ut=E(b({},Re),{price:x[Lt]}),Fn=G,Ue=class extends v{constructor(t){super(Ut,t);}};var ie=[O],ae=zod.z.enum([O]);var qn=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 Q=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()}),W=class{constructor(t,n){this.version="v1";let i=Q.parse(n);this.modelSchema=t,this.modelName=i.modelName,this.accessToken=i.accessToken;let a;if(i.baseUrl)a=i.baseUrl;else if(i.location&&i.projectId)a=re.baseUrl(i.location,i.projectId,i.publisher);else throw new Pe({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/${i.modelName}:predict`,this.location=i.location,this.projectId=i.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((n,i)=>n+i.length,0)}transformModelRequest(t){var l,c,u,g;let n=An.safeParse(t);if(!n.success)throw new X({info:"Invalid model request",cause:n.error});let i=n.data,a=i.model,m={autoTruncate:((l=i.parameters)==null?void 0:l.auto_truncate)||((c=i.parameters)==null?void 0:c.autoTruncate),dimensions:((u=i.parameters)==null?void 0:u.output_dimensionality)||((g=i.parameters)==null?void 0:g.outputDimensionality)},r=ge().parse(ye(m)),d={modality:O,requests:i.instances.map(h=>h.content)};return {modelName:a,config:r,embeddingRequests:d}}transformConfig(t,n){let i=this.modelSchema.config.schema.safeParse(t);if(!i.success)throw new H({info:`Invalid config for model : '${this.modelName}'`,cause:i.error});let a=i.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}',
18
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),{parameters:Object.keys(a).reduce((r,d)=>{let c=this.modelSchema.config.def[d].param,u=a[d];return r[c]=u,r},{})}}transformEmbeddingRequests(t){let n=Me().safeParse(t);if(!n.success)throw new ne({info:"Invalid embedding requests",cause:n.error});if(t.modality!==O)throw new ne({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${O}' modality is supported for model : '${this.modelName}'`)});return {instances:n.data.requests.map(a=>({content:a}))}}getGetEmbeddingsUrl(t,n){return Te(this,null,function*(){return new Promise(i=>{i(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,n){return Te(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,n){return Te(this,null,function*(){return new Promise(i=>{if(n.requests.length===0)throw new ne({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});i(b(b(b({},this.getDefaultParams()),this.transformConfig(t)),this.transformEmbeddingRequests(n)));})})}transformGetEmbeddingsResponse(t){let n=qn.safeParse(t);if(n.success){let a=n.data.predictions.map((m,r)=>({index:r,embedding:m.embeddings.values}));return {encodingFormat:he,embeddings:a}}throw new I({info:"Invalid response from model",cause:n.error})}};var Kt=e=>K({param:"output_dimensionality",title:ce.DIMENSIONS.title,description:ce.DIMENSIONS.description,min:1,max:e,step:1,default:e}),Yt=_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:Kt(e).schema,autoTruncate:Yt.schema}),Hn=e=>({dimensions:Kt(e).def,autoTruncate:Yt.def});var A={base:e=>({def:Hn(e),schema:Bn(e)})};var $t="text-embedding-004",or="text-embedding-004",Dt=z(ae).parse({name:$t,description:or,modalities:ie,maxInputTokens:2048,maxOutputTokens:768,config:{def:A.base(768).def,schema:A.base(768).schema}}),Ln=Q,$e=class extends W{constructor(t){super(Dt,t);}};var qt="text-multilingual-embedding-002",nr="text-multilingual-embedding-002",At=z(ae).parse({name:qt,description:nr,modalities:ie,maxInputTokens:2048,maxOutputTokens:768,config:{def:A.base(768).def,schema:A.base(768).schema}}),Un=Q,De=class extends W{constructor(t){super(At,t);}};var Bt="textembedding-gecko-multilingual@001",ir="textembedding-gecko-multilingual@001",Ht=z(ae).parse({name:Bt,description:ir,modalities:ie,maxInputTokens:2048,maxOutputTokens:768,config:{def:A.base(768).def,schema:A.base(768).schema}}),$n=Q,qe=class extends W{constructor(t){super(Ht,t);}};var zt="textembedding-gecko@003",ar="textembedding-gecko@003",Vt=z(ae).parse({name:zt,description:ar,modalities:ie,maxInputTokens:2048,maxOutputTokens:768,config:{def:A.base(768).def,schema:A.base(768).schema}}),Dn=Q,Ae=class extends W{constructor(t){super(Vt,t);}};
19
19
 
20
20
  exports.BaseChatModelOptions = G;
21
21
  exports.BaseChatModelVertex = v;
22
- exports.BaseEmbeddingModel = J;
22
+ exports.BaseEmbeddingModel = W;
23
23
  exports.BaseEmbeddingModelOptions = Q;
24
24
  exports.Gemini1_5Flash = je;
25
25
  exports.Gemini1_5Flash001 = Ge;