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