@adaline/vertex 0.15.0 → 0.16.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.d.mts CHANGED
@@ -84,6 +84,7 @@ declare const Gemini1_0Pro001Schema: {
84
84
  }>;
85
85
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
86
86
  };
87
+ maxReasoningTokens?: number | undefined;
87
88
  };
88
89
  declare const Gemini1_0Pro001Options: z.ZodObject<{
89
90
  accessToken: z.ZodString;
@@ -158,6 +159,7 @@ declare const Gemini1_0ProVisionSchema: {
158
159
  }>;
159
160
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
160
161
  };
162
+ maxReasoningTokens?: number | undefined;
161
163
  };
162
164
  declare const Gemini1_0ProVisionOptions: z.ZodObject<{
163
165
  accessToken: z.ZodString;
@@ -232,6 +234,7 @@ declare const Gemini1_0ProSchema: {
232
234
  }>;
233
235
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
234
236
  };
237
+ maxReasoningTokens?: number | undefined;
235
238
  };
236
239
  declare const Gemini1_0ProOptions: z.ZodObject<{
237
240
  accessToken: z.ZodString;
@@ -306,6 +309,7 @@ declare const Gemini1_5Flash001Schema: {
306
309
  }>;
307
310
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
308
311
  };
312
+ maxReasoningTokens?: number | undefined;
309
313
  };
310
314
  declare const Gemini1_5Flash001Options: z.ZodObject<{
311
315
  accessToken: z.ZodString;
@@ -380,6 +384,7 @@ declare const Gemini1_5Flash002Schema: {
380
384
  }>;
381
385
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
382
386
  };
387
+ maxReasoningTokens?: number | undefined;
383
388
  };
384
389
  declare const Gemini1_5Flash002Options: z.ZodObject<{
385
390
  accessToken: z.ZodString;
@@ -454,6 +459,7 @@ declare const Gemini1_5FlashSchema: {
454
459
  }>;
455
460
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
456
461
  };
462
+ maxReasoningTokens?: number | undefined;
457
463
  };
458
464
  declare const Gemini1_5FlashOptions: z.ZodObject<{
459
465
  accessToken: z.ZodString;
@@ -528,6 +534,7 @@ declare const Gemini1_5Pro001Schema: {
528
534
  }>;
529
535
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
530
536
  };
537
+ maxReasoningTokens?: number | undefined;
531
538
  };
532
539
  declare const Gemini1_5Pro001Options: z.ZodObject<{
533
540
  accessToken: z.ZodString;
@@ -602,6 +609,7 @@ declare const Gemini1_5Pro002Schema: {
602
609
  }>;
603
610
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
604
611
  };
612
+ maxReasoningTokens?: number | undefined;
605
613
  };
606
614
  declare const Gemini1_5Pro002Options: z.ZodObject<{
607
615
  accessToken: z.ZodString;
@@ -676,6 +684,7 @@ declare const Gemini1_5ProSchema: {
676
684
  }>;
677
685
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
678
686
  };
687
+ maxReasoningTokens?: number | undefined;
679
688
  };
680
689
  declare const Gemini1_5ProOptions: z.ZodObject<{
681
690
  accessToken: z.ZodString;
@@ -750,6 +759,7 @@ declare const Gemini2_0FlashExpSchema: {
750
759
  }>;
751
760
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
752
761
  };
762
+ maxReasoningTokens?: number | undefined;
753
763
  };
754
764
  declare const Gemini2_0FlashExpOptions: z.ZodObject<{
755
765
  accessToken: z.ZodString;
package/dist/index.d.ts CHANGED
@@ -84,6 +84,7 @@ declare const Gemini1_0Pro001Schema: {
84
84
  }>;
85
85
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
86
86
  };
87
+ maxReasoningTokens?: number | undefined;
87
88
  };
88
89
  declare const Gemini1_0Pro001Options: z.ZodObject<{
89
90
  accessToken: z.ZodString;
@@ -158,6 +159,7 @@ declare const Gemini1_0ProVisionSchema: {
158
159
  }>;
159
160
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
160
161
  };
162
+ maxReasoningTokens?: number | undefined;
161
163
  };
162
164
  declare const Gemini1_0ProVisionOptions: z.ZodObject<{
163
165
  accessToken: z.ZodString;
@@ -232,6 +234,7 @@ declare const Gemini1_0ProSchema: {
232
234
  }>;
233
235
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
234
236
  };
237
+ maxReasoningTokens?: number | undefined;
235
238
  };
236
239
  declare const Gemini1_0ProOptions: z.ZodObject<{
237
240
  accessToken: z.ZodString;
@@ -306,6 +309,7 @@ declare const Gemini1_5Flash001Schema: {
306
309
  }>;
307
310
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
308
311
  };
312
+ maxReasoningTokens?: number | undefined;
309
313
  };
310
314
  declare const Gemini1_5Flash001Options: z.ZodObject<{
311
315
  accessToken: z.ZodString;
@@ -380,6 +384,7 @@ declare const Gemini1_5Flash002Schema: {
380
384
  }>;
381
385
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
382
386
  };
387
+ maxReasoningTokens?: number | undefined;
383
388
  };
384
389
  declare const Gemini1_5Flash002Options: z.ZodObject<{
385
390
  accessToken: z.ZodString;
@@ -454,6 +459,7 @@ declare const Gemini1_5FlashSchema: {
454
459
  }>;
455
460
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
456
461
  };
462
+ maxReasoningTokens?: number | undefined;
457
463
  };
458
464
  declare const Gemini1_5FlashOptions: z.ZodObject<{
459
465
  accessToken: z.ZodString;
@@ -528,6 +534,7 @@ declare const Gemini1_5Pro001Schema: {
528
534
  }>;
529
535
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
530
536
  };
537
+ maxReasoningTokens?: number | undefined;
531
538
  };
532
539
  declare const Gemini1_5Pro001Options: z.ZodObject<{
533
540
  accessToken: z.ZodString;
@@ -602,6 +609,7 @@ declare const Gemini1_5Pro002Schema: {
602
609
  }>;
603
610
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
604
611
  };
612
+ maxReasoningTokens?: number | undefined;
605
613
  };
606
614
  declare const Gemini1_5Pro002Options: z.ZodObject<{
607
615
  accessToken: z.ZodString;
@@ -676,6 +684,7 @@ declare const Gemini1_5ProSchema: {
676
684
  }>;
677
685
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
678
686
  };
687
+ maxReasoningTokens?: number | undefined;
679
688
  };
680
689
  declare const Gemini1_5ProOptions: z.ZodObject<{
681
690
  accessToken: z.ZodString;
@@ -750,6 +759,7 @@ declare const Gemini2_0FlashExpSchema: {
750
759
  }>;
751
760
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
752
761
  };
762
+ maxReasoningTokens?: number | undefined;
753
763
  };
754
764
  declare const Gemini2_0FlashExpOptions: z.ZodObject<{
755
765
  accessToken: z.ZodString;
package/dist/index.js CHANGED
@@ -2,81 +2,81 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
- var Xn=Object.defineProperty,Qn=Object.defineProperties;var ea=Object.getOwnPropertyDescriptors;var $t=Object.getOwnPropertySymbols;var ta=Object.prototype.hasOwnProperty,oa=Object.prototype.propertyIsEnumerable;var Qe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),na=t=>{throw TypeError(t)};var qt=(t,e,o)=>e in t?Xn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,ie=(t,e)=>{for(var o in e||(e={}))ta.call(e,o)&&qt(t,o,e[o]);if($t)for(var o of $t(e))oa.call(e,o)&&qt(t,o,e[o]);return t},Ut=(t,e)=>Qn(t,ea(e));var he=(t,e,o)=>new Promise((a,s)=>{var m=l=>{try{d(o.next(l));}catch(p){s(p);}},r=l=>{try{d(o.throw(l));}catch(p){s(p);}},d=l=>l.done?a(l.value):Promise.resolve(l.value).then(m,r);d((o=o.apply(t,e)).next());}),aa=function(t,e){this[0]=t,this[1]=e;};var Bt=t=>{var e=t[Qe("asyncIterator")],o=!1,a,s={};return e==null?(e=t[Qe("iterator")](),a=m=>s[m]=r=>e[m](r)):(e=e.call(t),a=m=>s[m]=r=>{if(o){if(o=!1,m==="throw")throw r;return r}return o=!0,{done:!1,value:new aa(new Promise(d=>{var l=e[m](r);l instanceof Object||na("Object expected"),d(l);}),1)}}),s[Qe("iterator")]=()=>s,a("next"),"throw"in e?a("throw"):s.throw=m=>{throw m},"return"in e&&a("return"),s};var ia=t=>{let e=new WeakSet;return JSON.stringify(t,(o,a)=>{if(typeof a=="object"&&a!==null){if(e.has(a))return;e.add(a);}return a})},sa=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:ia(t),et="GatewayBaseError",V=class zt extends Error{constructor({info:e,cause:o},a){super(`[${a!=null?a:et}]: ${e}
6
- Message: ${sa(o)}`),this.name=et,this.info=e,this.cause=o,this.name=a!=null?a:et,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(e){return e instanceof zt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},de="system",F="user",j="assistant",X="tool",ra=[de,F,j,X],tt=zod.z.enum(ra),la=[j],ma=zod.z.enum(la),z="image",ot="base64",da=["png","jpeg","webp","gif"],ca=zod.z.object({type:zod.z.literal(ot),base64:zod.z.string(),media_type:zod.z.enum(da)}),pa="url",ua=zod.z.object({type:zod.z.literal(pa),url:zod.z.string()}),ga=zod.z.discriminatedUnion("type",[ca,ua]),ha=["low","medium","high","auto"],fa=zod.z.enum(ha),ya=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(z),detail:fa,value:ga,metadata:t}),T="text",Ht=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(T),value:zod.z.string(),metadata:t}),nt="partial-text",Kt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(nt),value:zod.z.string(),metadata:t}),R="tool-call",Yt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(R),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),at="partial-tool-call",Jt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(at),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),H="tool-response",ba=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(H),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),_a=[T,z,R,H],Wt=zod.z.enum(_a),Ea=(t=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ht(t),ya(e),Yt(o),ba(a)]),Ta=[nt,at];zod.z.enum(Ta);var Ma=(t=zod.z.undefined(),e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Kt(t),Jt(e)]);var it=(t=tt,e=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(Ea(e,o,a,s)),metadata:m}),st=(t=ma,e=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined())=>zod.z.object({role:t,partialContent:Ma(e,o),metadata:a}),Zt=t=>Ht().parse({modality:T,value:t}),Xt=(t,e,o,a)=>Yt().parse({modality:R,index:t,id:e,name:o,arguments:a});var rt=(t,e)=>st().parse({role:t,partialContent:Kt().parse({modality:nt,value:e})}),lt=(t,e,o,a,s)=>st().parse({role:t,partialContent:Jt().parse({modality:at,index:e,id:o,name:a,arguments:s})});var ce=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,xa=["object","array","number","string","boolean","enum"],At=zod.z.enum(xa),Ca=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([At,zod.z.array(zod.z.union([At,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()}),va=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(Ca),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:va}).optional();var Oa="function";var Sa=zod.z.enum(["object","array","number","string","boolean","null"]),Ga=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Sa.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(Ga).optional(),required:zod.z.array(zod.z.string()).optional()});var Pa=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 wa=zod.z.enum(["function"]),ka=zod.z.object({type:wa,definition:zod.z.object({schema:Pa})}),Ia=[Oa];zod.z.enum(Ia);var Qt=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[ka.extend({metadata:t})]),S="text",eo="token",ja=[S,eo],to=zod.z.enum(ja),Ra=zod.z.array(zod.z.string().min(1)),Na=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),fe=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(S),metadata:t,requests:Ra}),zod.z.object({modality:zod.z.literal(eo),metadata:t,requests:Na})]),pe="float",La=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Fa="base64",$a=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Dt=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(La),usage:Dt.optional()}),zod.z.object({encodingFormat:zod.z.literal(Fa),embeddings:zod.z.array($a),usage:Dt.optional()})]);var oo=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Vt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),qa=Vt.extend({topLogProbs:zod.z.array(Vt)}),no=zod.z.array(qa);zod.z.object({messages:zod.z.array(it()),usage:oo.optional(),logProbs:no.optional()});zod.z.object({partialMessages:zod.z.array(st()),usage:oo.optional(),logProbs:no.optional()});var Ua=Object.defineProperty,ao=Object.getOwnPropertySymbols,Ba=Object.prototype.hasOwnProperty,Aa=Object.prototype.propertyIsEnumerable,io=(t,e,o)=>e in t?Ua(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,ue=(t,e)=>{for(var o in e||(e={}))Ba.call(e,o)&&io(t,o,e[o]);if(ao)for(var o of ao(e))Aa.call(e,o)&&io(t,o,e[o]);return t},so="ProviderError",se=class ho extends V{constructor({info:e,cause:o}){super({info:e,cause:o},so),this.name=so,this.info=e,this.cause=o;}static isProviderError(e){return e instanceof ho}},ro="ModelError",ye=class fo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},ro),this.name=ro,this.info=e,this.cause=o;}static isModelError(e){return e instanceof fo}},lo="ModelResponseError",$=class yo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},lo),this.name=lo,this.cause=o,this.info=e;}static isModelResponseError(e){return e instanceof yo}},mo="InvalidModelRequestError",K=class bo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},mo),this.name=mo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(e){return e instanceof bo}},co="InvalidConfigError",B=class _o extends V{constructor({info:e,cause:o}){super({info:e,cause:o},co),this.name=co,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(e){return e instanceof _o}},po="InvalidMessagesError",x=class Eo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},po),this.name=po,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(e){return e instanceof Eo}},uo="InvalidToolsError",mt=class To extends V{constructor({info:e,cause:o}){super({info:e,cause:o},uo),this.name=uo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(e){return e instanceof To}},go="InvalidEmbeddingRequestsError",Q=class Mo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},go),this.name=go,this.info=e,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(e){return e instanceof Mo}},dt="multi-string",xo=zod.z.object({type:zod.z.literal(dt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),Da=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),Co=t=>({def:xo.parse(ue({type:dt},t)),schema:Da(t.max)}),ct="object-schema",vo=zod.z.object({type:zod.z.literal(ct),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),Va=t=>t.optional(),Oo=t=>({def:vo.parse(ue({type:ct},t)),schema:Va(t.objectSchema)}),pt="range",So=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()}),za=(t,e,o,a)=>zod.z.number().min(t).max(e).step(o).default(a).optional(),q=t=>({def:So.parse(ue({type:pt},t)),schema:za(t.min,t.max,t.step,t.default)}),ut="select-boolean",Go=zod.z.object({type:zod.z.literal(ut),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),Ha=t=>zod.z.boolean().nullable().default(t).optional(),Po=t=>({def:Go.parse(ue({type:ut},t)),schema:Ha(t.default)}),gt="select-string",wo=zod.z.object({type:zod.z.literal(gt),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())}),Ka=(t,e)=>zod.z.enum(e).nullable().default(t).optional(),ko=t=>({def:wo.parse(ue({type:gt},t)),schema:Ka(t.default,t.choices)}),Ya=[pt,dt,gt,ct,ut];zod.z.enum(Ya);var Io=zod.z.discriminatedUnion("type",[So,xo,wo,Go,vo]),C=(t=tt,e=Wt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Io),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var a,s;let m=Object.keys(o.def),r=Object.keys((s=(a=o.schema)==null?void 0:a.shape)!=null?s:{});return m.every(d=>r.includes(d))&&r.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),U=(t=to)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Io),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(e=>{var o,a;let s=Object.keys(e.def),m=Object.keys((a=(o=e.schema)==null?void 0:o.shape)!=null?a:{});return s.every(r=>m.includes(r))&&m.every(r=>s.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 Ja={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."},Wa={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."},Za=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Xa={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."},Qa={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."},ei={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."},ti={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."},oi={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."},ni={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."},ai={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."},ii={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."},si={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."},ri={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."},li={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},mi={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."},di={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."},ci={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."},M={TEMPERATURE:Ja,MAX_TOKENS:Wa,STOP:Za,TOP_A:Xa,TOP_P:Qa,TOP_K:ei,MIN_P:ti,FREQUENCY_PENALTY:oi,PRESENCE_PENALTY:ni,REPETITION_PENALTY:ii,SEED:ai,LOG_PROBS:si,TOP_LOG_PROBS:ri,ECHO:li,RESPONSE_FORMAT:mi,RESPONSE_FORMAT_WITH_SCHEMA:di,RESPONSE_SCHEMA:ci},pi={type:"range",title:"Dimensions",description:"Select the number of dimensions for the word embedding."},ui={type:"select",title:"Encoding format",description:"Select the encoding format for the word embedding."},re={DIMENSIONS:pi,ENCODING_FORMAT:ui};var ge=t=>Object.fromEntries(Object.entries(t).filter(([e,o])=>o!=null));var le=t=>t==null?void 0:t.replace(/\/$/,"");var gi=Object.defineProperty,jo=Object.getOwnPropertySymbols,hi=Object.prototype.hasOwnProperty,fi=Object.prototype.propertyIsEnumerable,be=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),yi=t=>{throw TypeError(t)},Ro=(t,e,o)=>e in t?gi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,G=(t,e)=>{for(var o in e||(e={}))hi.call(e,o)&&Ro(t,o,e[o]);if(jo)for(var o of jo(e))fi.call(e,o)&&Ro(t,o,e[o]);return t},k=(t,e,o)=>new Promise((a,s)=>{var m=l=>{try{d(o.next(l));}catch(p){s(p);}},r=l=>{try{d(o.throw(l));}catch(p){s(p);}},d=l=>l.done?a(l.value):Promise.resolve(l.value).then(m,r);d((o=o.apply(t,e)).next());}),Bo=function(t,e){this[0]=t,this[1]=e;},No=(t,e,o)=>{var a=(r,d,l,p)=>{try{var u=o[r](d),f=(d=u.value)instanceof Bo,h=u.done;Promise.resolve(f?d[0]:d).then(_=>f?a(r==="return"?r:"next",d[1]?{done:_.done,value:_.value}:_,l,p):l({value:_,done:h})).catch(_=>a("throw",_,l,p));}catch(_){p(_);}},s=r=>m[r]=d=>new Promise((l,p)=>a(r,d,l,p)),m={};return o=o.apply(t,e),m[be("asyncIterator")]=()=>m,s("next"),s("throw"),s("return"),m},bi=t=>{var e=t[be("asyncIterator")],o=!1,a,s={};return e==null?(e=t[be("iterator")](),a=m=>s[m]=r=>e[m](r)):(e=e.call(t),a=m=>s[m]=r=>{if(o){if(o=!1,m==="throw")throw r;return r}return o=!0,{done:!1,value:new Bo(new Promise(d=>{var l=e[m](r);l instanceof Object||yi("Object expected"),d(l);}),1)}}),s[be("iterator")]=()=>s,a("next"),"throw"in e?a("throw"):s.throw=m=>{throw m},"return"in e&&a("return"),s},Ee=(t,e)=>q({param:"temperature",title:M.TEMPERATURE.title,description:M.TEMPERATURE.description,min:0,max:t,step:.01,default:e}),Te=t=>q({param:"maxOutputTokens",title:M.MAX_TOKENS.title,description:M.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Me=t=>Co({param:"stopSequences",title:M.STOP(t).title,description:M.STOP(t).description,max:t}),xe=t=>q({param:"topP",title:M.TOP_P.title,description:M.TOP_P.description,min:0,max:1,step:.01,default:t}),Ao=t=>q({param:"topK",title:M.TOP_K.title,description:M.TOP_K.description,min:1,max:40,step:1,default:t}),Do=q({param:"frequencyPenalty",title:M.FREQUENCY_PENALTY.title,description:M.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Vo=q({param:"presencePenalty",title:M.PRESENCE_PENALTY.title,description:M.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),zo=q({param:"seed",title:M.SEED.title,description:M.SEED.description,min:0,max:1e6,step:1,default:0}),Ce=ko({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"]}),ve=Oo({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"])}))}),_i=(t,e,o,a,s)=>zod.z.object({temperature:Ee(t,e).schema,maxTokens:Te(o).schema,stop:Me(a).schema,topP:xe(s).schema,toolChoice:Ce.schema,safetySettings:ve.schema}),Ei=(t,e,o,a,s)=>({temperature:Ee(t,e).def,maxTokens:Te(o).def,stop:Me(a).def,topP:xe(s).def,toolChoice:Ce.def,safetySettings:ve.def}),Ti=(t,e,o,a,s,m)=>zod.z.object({temperature:Ee(t,e).schema,maxTokens:Te(o).schema,stop:Me(a).schema,topP:xe(s).schema,topK:Ao(m).schema,frequencyPenalty:Do.schema,presencePenalty:Vo.schema,seed:zo.schema.transform(r=>r===0?void 0:r),toolChoice:Ce.schema,safetySettings:ve.schema}),Mi=(t,e,o,a,s,m)=>({temperature:Ee(t,e).def,maxTokens:Te(o).def,stop:Me(a).def,topP:xe(s).def,topK:Ao(m).def,frequencyPenalty:Do.def,presencePenalty:Vo.def,seed:zo.def,toolChoice:Ce.def,safetySettings:ve.def}),Ho=t=>q({param:"outputDimensionality",title:re.DIMENSIONS.title,description:re.DIMENSIONS.description,min:1,max:t,step:1,default:t}),xi=t=>zod.z.object({dimensions:Ho(t).schema}),Ci=t=>({dimensions:Ho(t).def}),g={base:(t,e,o,a,s)=>({def:Ei(t,e,o,a,s),schema:_i(t,e,o,a,s)}),c1:(t,e,o,a,s,m)=>({def:Mi(t,e,o,a,s,m),schema:Ti(t,e,o,a,s,m)})},_e={base:t=>({def:Ci(t),schema:xi(t)})},vi="google",ht=class{constructor(){this.version="v1",this.name=vi,this.chatModelFactories={[hn]:{model:Ps,modelOptions:Gs,modelSchema:fn},[un]:{model:Os,modelOptions:vs,modelSchema:gn},[tn]:{model:Qi,modelOptions:Xi,modelSchema:ke},[on]:{model:os,modelOptions:ts,modelSchema:Ie},[nn]:{model:is,modelOptions:as,modelSchema:an},[sn]:{model:ls,modelOptions:rs,modelSchema:je},[rn]:{model:cs,modelOptions:ds,modelSchema:Re},[ln]:{model:gs,modelOptions:us,modelSchema:Ne},[mn]:{model:ys,modelOptions:fs,modelSchema:dn},[cn]:{model:Es,modelOptions:_s,modelSchema:Le},[en]:{model:Wi,modelOptions:Ji,modelSchema:we},[Qo]:{model:Ki,modelOptions:Hi,modelSchema:Pe},[Zo]:{model:Vi,modelOptions:Di,modelSchema:Xo},[Wo]:{model:Bi,modelOptions:Ui,modelSchema:Ge},[pn]:{model:xs,modelOptions:Ms,modelSchema:Fe}},this.embeddingModelFactories={[En]:{model:Ns,modelOptions:Rs,modelSchema:Tn},[Mn]:{model:$s,modelOptions:Fs,modelSchema:xn}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,e)=>(t[e]=this.chatModelFactories[e].modelSchema,t),{})}chatModel(t){let e=t.modelName;if(!(e in this.chatModelFactories))throw new se({info:`Google chat model: ${e} not found`,cause:new Error(`Google chat model: ${e} not found, available chat models:
5
+ var na=Object.defineProperty,aa=Object.defineProperties;var ia=Object.getOwnPropertyDescriptors;var qt=Object.getOwnPropertySymbols;var sa=Object.prototype.hasOwnProperty,ra=Object.prototype.propertyIsEnumerable;var Qe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),la=t=>{throw TypeError(t)};var Ut=(t,e,o)=>e in t?na(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,ie=(t,e)=>{for(var o in e||(e={}))sa.call(e,o)&&Ut(t,o,e[o]);if(qt)for(var o of qt(e))ra.call(e,o)&&Ut(t,o,e[o]);return t},Bt=(t,e)=>aa(t,ia(e));var he=(t,e,o)=>new Promise((a,s)=>{var m=l=>{try{d(o.next(l));}catch(p){s(p);}},r=l=>{try{d(o.throw(l));}catch(p){s(p);}},d=l=>l.done?a(l.value):Promise.resolve(l.value).then(m,r);d((o=o.apply(t,e)).next());}),ma=function(t,e){this[0]=t,this[1]=e;};var At=t=>{var e=t[Qe("asyncIterator")],o=!1,a,s={};return e==null?(e=t[Qe("iterator")](),a=m=>s[m]=r=>e[m](r)):(e=e.call(t),a=m=>s[m]=r=>{if(o){if(o=!1,m==="throw")throw r;return r}return o=!0,{done:!1,value:new ma(new Promise(d=>{var l=e[m](r);l instanceof Object||la("Object expected"),d(l);}),1)}}),s[Qe("iterator")]=()=>s,a("next"),"throw"in e?a("throw"):s.throw=m=>{throw m},"return"in e&&a("return"),s};var da=t=>{let e=new WeakSet;return JSON.stringify(t,(o,a)=>{if(typeof a=="object"&&a!==null){if(e.has(a))return;e.add(a);}return a})},ca=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:da(t),et="GatewayBaseError",V=class Ht extends Error{constructor({info:e,cause:o},a){super(`[${a!=null?a:et}]: ${e}
6
+ Message: ${ca(o)}`),this.name=et,this.info=e,this.cause=o,this.name=a!=null?a:et,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(e){return e instanceof Ht}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},de="system",F="user",R="assistant",Z="tool",pa=[de,F,R,Z],ot=zod.z.enum(pa),ua=[R],ga=zod.z.enum(ua),z="image",nt="base64",ha=["png","jpeg","webp","gif"],fa=zod.z.object({type:zod.z.literal(nt),base64:zod.z.string(),media_type:zod.z.enum(ha)}),ya="url",ba=zod.z.object({type:zod.z.literal(ya),url:zod.z.string()}),_a=zod.z.discriminatedUnion("type",[fa,ba]),Ea=["low","medium","high","auto"],Ta=zod.z.enum(Ea),Ma=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(z),detail:Ta,value:_a,metadata:t}),Kt="reasoning",Yt="partial-reasoning",Jt="thinking",xa="redacted",tt=zod.z.object({type:zod.z.literal(Jt),thinking:zod.z.string(),signature:zod.z.string()}),Wt=zod.z.object({type:zod.z.literal(xa),data:zod.z.string()}),Ca=zod.z.discriminatedUnion("type",[tt,Wt]),va=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Kt),value:Ca,metadata:t}),Oa=zod.z.object({type:zod.z.literal(Jt),thinking:tt.shape.thinking.optional(),signature:tt.shape.signature.optional()}),Sa=zod.z.discriminatedUnion("type",[Oa,Wt]),Pa=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Yt),value:Sa,metadata:t}),T="text",Xt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(T),value:zod.z.string(),metadata:t}),at="partial-text",Zt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(at),value:zod.z.string(),metadata:t}),j="tool-call",Qt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(j),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),it="partial-tool-call",eo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(it),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),H="tool-response",Ga=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(H),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),wa=[T,z,j,H,Kt],to=zod.z.enum(wa),ka=(t=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Xt(t),Ma(e),Qt(o),Ga(a),va(s)]),Ia=[at,it,Yt];zod.z.enum(Ia);var Ra=(t=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Zt(t),eo(e),Pa(o)]);var st=(t=ot,e=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined(),m=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(ka(e,o,a,s,r)),metadata:m}),rt=(t=ga,e=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,partialContent:Ra(e,o,a),metadata:s}),oo=t=>Xt().parse({modality:T,value:t}),no=(t,e,o,a)=>Qt().parse({modality:j,index:t,id:e,name:o,arguments:a});var lt=(t,e)=>rt().parse({role:t,partialContent:Zt().parse({modality:at,value:e})}),mt=(t,e,o,a,s)=>rt().parse({role:t,partialContent:eo().parse({modality:it,index:e,id:o,name:a,arguments:s})});var ce=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,ja=["object","array","number","string","boolean","enum"],Dt=zod.z.enum(ja),Na=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Dt,zod.z.array(zod.z.union([Dt,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()}),La=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(Na),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:La}).optional();var Fa="function";var $a=zod.z.enum(["object","array","number","string","boolean","null"]),qa=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:$a.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(qa).optional(),required:zod.z.array(zod.z.string()).optional()});var Ua=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 Ba=zod.z.enum(["function"]),Aa=zod.z.object({type:Ba,definition:zod.z.object({schema:Ua})}),Da=[Fa];zod.z.enum(Da);var ao=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Aa.extend({metadata:t})]),S="text",io="token",Va=[S,io],so=zod.z.enum(Va),za=zod.z.array(zod.z.string().min(1)),Ha=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),fe=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(S),metadata:t,requests:za}),zod.z.object({modality:zod.z.literal(io),metadata:t,requests:Ha})]),pe="float",Ka=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Ya="base64",Ja=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Vt=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(Ka),usage:Vt.optional()}),zod.z.object({encodingFormat:zod.z.literal(Ya),embeddings:zod.z.array(Ja),usage:Vt.optional()})]);var ro=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),zt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Wa=zt.extend({topLogProbs:zod.z.array(zt)}),lo=zod.z.array(Wa);zod.z.object({messages:zod.z.array(st()),usage:ro.optional(),logProbs:lo.optional()});zod.z.object({partialMessages:zod.z.array(rt()),usage:ro.optional(),logProbs:lo.optional()});var Xa=Object.defineProperty,mo=Object.getOwnPropertySymbols,Za=Object.prototype.hasOwnProperty,Qa=Object.prototype.propertyIsEnumerable,co=(t,e,o)=>e in t?Xa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,ue=(t,e)=>{for(var o in e||(e={}))Za.call(e,o)&&co(t,o,e[o]);if(mo)for(var o of mo(e))Qa.call(e,o)&&co(t,o,e[o]);return t},po="ProviderError",se=class Eo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},po),this.name=po,this.info=e,this.cause=o;}static isProviderError(e){return e instanceof Eo}},uo="ModelError",ye=class To extends V{constructor({info:e,cause:o}){super({info:e,cause:o},uo),this.name=uo,this.info=e,this.cause=o;}static isModelError(e){return e instanceof To}},go="ModelResponseError",$=class Mo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},go),this.name=go,this.cause=o,this.info=e;}static isModelResponseError(e){return e instanceof Mo}},ho="InvalidModelRequestError",K=class xo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},ho),this.name=ho,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(e){return e instanceof xo}},fo="InvalidConfigError",B=class Co extends V{constructor({info:e,cause:o}){super({info:e,cause:o},fo),this.name=fo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(e){return e instanceof Co}},yo="InvalidMessagesError",x=class vo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},yo),this.name=yo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(e){return e instanceof vo}},bo="InvalidToolsError",dt=class Oo extends V{constructor({info:e,cause:o}){super({info:e,cause:o},bo),this.name=bo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(e){return e instanceof Oo}},_o="InvalidEmbeddingRequestsError",Q=class So extends V{constructor({info:e,cause:o}){super({info:e,cause:o},_o),this.name=_o,this.info=e,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(e){return e instanceof So}},ct="multi-string",Po=zod.z.object({type:zod.z.literal(ct),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()}),ei=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),Go=t=>({def:Po.parse(ue({type:ct},t)),schema:ei(t.max)}),pt="object-schema",wo=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),objectSchema:zod.z.any()}),ti=t=>t.optional(),ko=t=>({def:wo.parse(ue({type:pt},t)),schema:ti(t.objectSchema)}),ut="range",Io=zod.z.object({type:zod.z.literal(ut),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),oi=(t,e,o,a)=>zod.z.number().min(t).max(e).step(o).default(a).optional(),q=t=>({def:Io.parse(ue({type:ut},t)),schema:oi(t.min,t.max,t.step,t.default)}),gt="select-boolean",Ro=zod.z.object({type:zod.z.literal(gt),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()}),ni=t=>zod.z.boolean().nullable().default(t).optional(),jo=t=>({def:Ro.parse(ue({type:gt},t)),schema:ni(t.default)}),ht="select-string",No=zod.z.object({type:zod.z.literal(ht),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())}),ai=(t,e)=>zod.z.enum(e).nullable().default(t).optional(),Lo=t=>({def:No.parse(ue({type:ht},t)),schema:ai(t.default,t.choices)}),ii=[ut,ct,ht,pt,gt];zod.z.enum(ii);var Fo=zod.z.discriminatedUnion("type",[Io,Po,No,Ro,wo]),C=(t=ot,e=to)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),maxReasoningTokens:zod.z.number().int().positive().min(1).optional(),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Fo),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var a,s;let m=Object.keys(o.def),r=Object.keys((s=(a=o.schema)==null?void 0:a.shape)!=null?s:{});return m.every(d=>r.includes(d))&&r.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),U=(t=so)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Fo),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(e=>{var o,a;let s=Object.keys(e.def),m=Object.keys((a=(o=e.schema)==null?void 0:o.shape)!=null?a:{});return s.every(r=>m.includes(r))&&m.every(r=>s.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 si={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."},ri={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."},li={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},mi=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),di={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."},ci={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."},pi={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."},ui={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."},gi={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."},hi={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."},fi={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."},yi={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."},bi={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."},_i={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."},Ei={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Ti={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."},Mi={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."},xi={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."},M={TEMPERATURE:si,MAX_TOKENS:ri,STOP:mi,TOP_A:di,TOP_P:ci,TOP_K:pi,MIN_P:ui,FREQUENCY_PENALTY:gi,PRESENCE_PENALTY:hi,REPETITION_PENALTY:yi,SEED:fi,LOG_PROBS:bi,TOP_LOG_PROBS:_i,ECHO:Ei,RESPONSE_FORMAT:Ti,RESPONSE_FORMAT_WITH_SCHEMA:Mi,RESPONSE_SCHEMA:xi,MAX_REASONING_TOKENS:li},Ci={type:"range",title:"Dimensions",description:"Select the number of dimensions for the word embedding."},vi={type:"select",title:"Encoding format",description:"Select the encoding format for the word embedding."},re={DIMENSIONS:Ci,ENCODING_FORMAT:vi};var ge=t=>Object.fromEntries(Object.entries(t).filter(([e,o])=>o!=null));var le=t=>t==null?void 0:t.replace(/\/$/,"");var Oi=Object.defineProperty,$o=Object.getOwnPropertySymbols,Si=Object.prototype.hasOwnProperty,Pi=Object.prototype.propertyIsEnumerable,be=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Gi=t=>{throw TypeError(t)},qo=(t,e,o)=>e in t?Oi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,P=(t,e)=>{for(var o in e||(e={}))Si.call(e,o)&&qo(t,o,e[o]);if($o)for(var o of $o(e))Pi.call(e,o)&&qo(t,o,e[o]);return t},k=(t,e,o)=>new Promise((a,s)=>{var m=l=>{try{d(o.next(l));}catch(p){s(p);}},r=l=>{try{d(o.throw(l));}catch(p){s(p);}},d=l=>l.done?a(l.value):Promise.resolve(l.value).then(m,r);d((o=o.apply(t,e)).next());}),Ho=function(t,e){this[0]=t,this[1]=e;},Uo=(t,e,o)=>{var a=(r,d,l,p)=>{try{var u=o[r](d),f=(d=u.value)instanceof Ho,h=u.done;Promise.resolve(f?d[0]:d).then(_=>f?a(r==="return"?r:"next",d[1]?{done:_.done,value:_.value}:_,l,p):l({value:_,done:h})).catch(_=>a("throw",_,l,p));}catch(_){p(_);}},s=r=>m[r]=d=>new Promise((l,p)=>a(r,d,l,p)),m={};return o=o.apply(t,e),m[be("asyncIterator")]=()=>m,s("next"),s("throw"),s("return"),m},wi=t=>{var e=t[be("asyncIterator")],o=!1,a,s={};return e==null?(e=t[be("iterator")](),a=m=>s[m]=r=>e[m](r)):(e=e.call(t),a=m=>s[m]=r=>{if(o){if(o=!1,m==="throw")throw r;return r}return o=!0,{done:!1,value:new Ho(new Promise(d=>{var l=e[m](r);l instanceof Object||Gi("Object expected"),d(l);}),1)}}),s[be("iterator")]=()=>s,a("next"),"throw"in e?a("throw"):s.throw=m=>{throw m},"return"in e&&a("return"),s},Ee=(t,e)=>q({param:"temperature",title:M.TEMPERATURE.title,description:M.TEMPERATURE.description,min:0,max:t,step:.01,default:e}),Te=t=>q({param:"maxOutputTokens",title:M.MAX_TOKENS.title,description:M.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Me=t=>Go({param:"stopSequences",title:M.STOP(t).title,description:M.STOP(t).description,max:t}),xe=t=>q({param:"topP",title:M.TOP_P.title,description:M.TOP_P.description,min:0,max:1,step:.01,default:t}),Ko=t=>q({param:"topK",title:M.TOP_K.title,description:M.TOP_K.description,min:1,max:40,step:1,default:t}),Yo=q({param:"frequencyPenalty",title:M.FREQUENCY_PENALTY.title,description:M.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Jo=q({param:"presencePenalty",title:M.PRESENCE_PENALTY.title,description:M.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),Wo=q({param:"seed",title:M.SEED.title,description:M.SEED.description,min:0,max:1e6,step:1,default:0}),Ce=Lo({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"]}),ve=ko({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"])}))}),ki=(t,e,o,a,s)=>zod.z.object({temperature:Ee(t,e).schema,maxTokens:Te(o).schema,stop:Me(a).schema,topP:xe(s).schema,toolChoice:Ce.schema,safetySettings:ve.schema}),Ii=(t,e,o,a,s)=>({temperature:Ee(t,e).def,maxTokens:Te(o).def,stop:Me(a).def,topP:xe(s).def,toolChoice:Ce.def,safetySettings:ve.def}),Ri=(t,e,o,a,s,m)=>zod.z.object({temperature:Ee(t,e).schema,maxTokens:Te(o).schema,stop:Me(a).schema,topP:xe(s).schema,topK:Ko(m).schema,frequencyPenalty:Yo.schema,presencePenalty:Jo.schema,seed:Wo.schema.transform(r=>r===0?void 0:r),toolChoice:Ce.schema,safetySettings:ve.schema}),ji=(t,e,o,a,s,m)=>({temperature:Ee(t,e).def,maxTokens:Te(o).def,stop:Me(a).def,topP:xe(s).def,topK:Ko(m).def,frequencyPenalty:Yo.def,presencePenalty:Jo.def,seed:Wo.def,toolChoice:Ce.def,safetySettings:ve.def}),Xo=t=>q({param:"outputDimensionality",title:re.DIMENSIONS.title,description:re.DIMENSIONS.description,min:1,max:t,step:1,default:t}),Ni=t=>zod.z.object({dimensions:Xo(t).schema}),Li=t=>({dimensions:Xo(t).def}),g={base:(t,e,o,a,s)=>({def:Ii(t,e,o,a,s),schema:ki(t,e,o,a,s)}),c1:(t,e,o,a,s,m)=>({def:ji(t,e,o,a,s,m),schema:Ri(t,e,o,a,s,m)})},_e={base:t=>({def:Li(t),schema:Ni(t)})},Fi="google",ft=class{constructor(){this.version="v1",this.name=Fi,this.chatModelFactories={[En]:{model:Bs,modelOptions:Us,modelSchema:Tn},[bn]:{model:$s,modelOptions:Fs,modelSchema:_n},[rn]:{model:cs,modelOptions:ds,modelSchema:ke},[ln]:{model:gs,modelOptions:us,modelSchema:Ie},[mn]:{model:ys,modelOptions:fs,modelSchema:dn},[cn]:{model:Es,modelOptions:_s,modelSchema:Re},[pn]:{model:xs,modelOptions:Ms,modelSchema:je},[un]:{model:Os,modelOptions:vs,modelSchema:Ne},[gn]:{model:Gs,modelOptions:Ps,modelSchema:hn},[fn]:{model:Is,modelOptions:ks,modelSchema:Le},[sn]:{model:ls,modelOptions:rs,modelSchema:we},[an]:{model:is,modelOptions:as,modelSchema:Ge},[on]:{model:os,modelOptions:ts,modelSchema:nn},[tn]:{model:Qi,modelOptions:Zi,modelSchema:Pe},[yn]:{model:Ns,modelOptions:js,modelSchema:Fe}},this.embeddingModelFactories={[vn]:{model:Ks,modelOptions:Hs,modelSchema:On},[Sn]:{model:Ws,modelOptions:Js,modelSchema:Pn}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,e)=>(t[e]=this.chatModelFactories[e].modelSchema,t),{})}chatModel(t){let e=t.modelName;if(!(e in this.chatModelFactories))throw new se({info:`Google chat model: ${e} not found`,cause:new Error(`Google chat model: ${e} not found, available chat models:
7
7
  [${this.chatModelLiterals().join(", ")}]`)});let o=this.chatModelFactories[e].model,a=this.chatModelFactories[e].modelOptions.parse(t);return new o(a)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,e)=>(t[e]=this.embeddingModelFactories[e].modelSchema,t),{})}embeddingModel(t){let e=t.modelName;if(!(e in this.embeddingModelFactories))throw new se({info:`Google embedding model: ${e} not found`,cause:new Error(`Google embedding model: ${e} not found, available embedding models:
8
- [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[e].model,a=this.embeddingModelFactories[e].modelOptions.parse(t);return new o(a)}};ht.baseUrl="https://generativelanguage.googleapis.com/v1beta";var P=zod.z.enum([de,F,j,X]),Oi="model",Si="function",w={system:F,user:F,assistant:Oi,tool:Si},Y=[T,z,R,H],J=zod.z.enum([T,z,R,H]);zod.z.enum([T]);var Ko=[T,z],Yo=zod.z.enum([T,z]),Oe=[T,R,H],Se=zod.z.enum([T,R,H]),Gi=zod.z.object({text:zod.z.string()}),Pi=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),wi=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([Gi,Pi]))}).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()}),ki=zod.z.object({text:zod.z.string()}),Ii=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Lo=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([ki,Ii]))}).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()}),Jo=zod.z.object({text:zod.z.string().min(1)}),ji=zod.z.object({inline_data:zod.z.object({mime_type:zod.z.string().min(1),data:zod.z.string().base64()})}),Ri=zod.z.object({function_call:zod.z.object({name:zod.z.string().min(1),args:zod.z.record(zod.z.string().min(1))})}),Ni=zod.z.object({function_response:zod.z.object({name:zod.z.string().min(1),response:zod.z.record(zod.z.string().min(1))})}),Li=zod.z.object({role:zod.z.enum(["user","model","function"]),parts:zod.z.array(zod.z.union([Jo,ji,Ri,Ni]))}),Fo=zod.z.object({parts:zod.z.array(Jo)}),Fi=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),parameters:zod.z.any()}),$o=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()})}),qo=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()}),Uo=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"])}),$i=zod.z.object({model:zod.z.string().min(1).optional(),contents:zod.z.array(Li),systemInstruction:Fo.optional(),system_instruction:Fo.optional(),generationConfig:qo.optional(),generation_config:qo.optional(),safetySettings:zod.z.array(Uo).optional(),safety_settings:zod.z.array(Uo).optional(),tools:zod.z.object({function_declarations:zod.z.array(Fi)}).optional(),toolConfig:$o.optional(),tool_config:$o.optional()}),v=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()}),N=class{constructor(t,e){this.version="v1";var o;let a=v.parse(e);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=le((o=a.baseUrl)!=null?o:ht.baseUrl),this.completeChatUrl=le(a.completeChatUrl||`${this.baseUrl}/models/${this.modelName}:generateContent?key=${this.apiKey}`),this.streamChatUrl=le(a.streamChatUrl||`${this.baseUrl}/models/${this.modelName}:streamGenerateContent?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.reduce((e,o)=>e+o.content.map(a=>a.modality==="text"?a.value:"").join(" ").length,0)}transformModelRequest(t){let e=$i.safeParse(t);if(!e.success)throw new K({info:"Invalid model request",cause:e.error});let o=e.data,a=o.model;if(o.system_instruction&&o.systemInstruction)throw new K({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 K({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 K({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tool_config' and 'toolConfig' are not allowed at the same time")});let s=o.system_instruction||o.systemInstruction,m=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 K({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let l={};d&&(d.function_calling_config.mode==="ANY"&&d.function_calling_config.allowed_function_names&&d.function_calling_config.allowed_function_names.length===1?l.toolChoice=d.function_calling_config.allowed_function_names[0]:l.toolChoice=d.function_calling_config.mode.toLowerCase()),l.seed=m==null?void 0:m.seed,l.maxTokens=m==null?void 0:m.maxOutputTokens,l.temperature=m==null?void 0:m.temperature,l.topP=m==null?void 0:m.topP,l.presencePenalty=m==null?void 0:m.presencePenalty,l.frequencyPenalty=m==null?void 0:m.frequencyPenalty,l.stop=m==null?void 0:m.stopSequences,l.safetySettings=r;let p=ce().parse(ge(l)),u=[];s&&s.parts.forEach(h=>{u.push({role:de,content:[{modality:T,value:h.text}]});}),o.contents.forEach(h=>{let _=h.role;switch(_){case"user":{let O=h.parts.map(E=>"text"in E?{modality:T,value:E.text}:{modality:z,detail:"auto",value:{type:ot,base64:E.inline_data.data,media_type:E.inline_data.mime_type.split("/")[1]}});u.push({role:_,content:O});}break;case"model":{let O=h.parts.map((E,I)=>"text"in E?{modality:T,value:E.text}:{modality:R,id:I.toString(),index:I,name:E.function_call.name,arguments:JSON.stringify(E.function_call.args)});u.push({role:j,content:O});}break;case"function":{let O=h.parts.map((E,I)=>({modality:H,id:I.toString(),index:I,name:E.function_response.name,data:JSON.stringify(E.function_response.response)}));u.push({role:X,content:O});}break;default:throw new x({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${h.role}' is not supported for model : ${this.modelName}`)})}});let f=[];return o.tools&&o.tools.function_declarations.forEach(h=>{f.push({type:"function",definition:{schema:{name:h.name,description:h.description,parameters:h.parameters}}});}),{modelName:a,config:p,messages:u,tools:f.length>0?f:void 0}}transformConfig(t,e,o){let a=t.toolChoice;delete t.toolChoice;let s=this.modelSchema.config.schema.safeParse(t);if(!s.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:s.error});let m=s.data;Object.keys(m).forEach(p=>{if(!(p in this.modelSchema.config.def))throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${p}',
8
+ [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[e].model,a=this.embeddingModelFactories[e].modelOptions.parse(t);return new o(a)}};ft.baseUrl="https://generativelanguage.googleapis.com/v1beta";var G=zod.z.enum([de,F,R,Z]),$i="model",qi="function",w={system:F,user:F,assistant:$i,tool:qi},Y=[T,z,j,H],J=zod.z.enum([T,z,j,H]);zod.z.enum([T]);var Zo=[T,z],Qo=zod.z.enum([T,z]),Oe=[T,j,H],Se=zod.z.enum([T,j,H]),Ui=zod.z.object({text:zod.z.string()}),Bi=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Ai=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([Ui,Bi]))}).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()}),Di=zod.z.object({text:zod.z.string()}),Vi=zod.z.object({functionCall:zod.z.object({name:zod.z.string(),args:zod.z.record(zod.z.any())})}),Bo=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([Di,Vi]))}).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()}),en=zod.z.object({text:zod.z.string().min(1)}),zi=zod.z.object({inline_data:zod.z.object({mime_type:zod.z.string().min(1),data:zod.z.string().base64()})}),Hi=zod.z.object({function_call:zod.z.object({name:zod.z.string().min(1),args:zod.z.record(zod.z.string().min(1))})}),Ki=zod.z.object({function_response:zod.z.object({name:zod.z.string().min(1),response:zod.z.record(zod.z.string().min(1))})}),Yi=zod.z.object({role:zod.z.enum(["user","model","function"]),parts:zod.z.array(zod.z.union([en,zi,Hi,Ki]))}),Ao=zod.z.object({parts:zod.z.array(en)}),Ji=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),parameters:zod.z.any()}),Do=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()})}),Vo=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()}),zo=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"])}),Wi=zod.z.object({model:zod.z.string().min(1).optional(),contents:zod.z.array(Yi),systemInstruction:Ao.optional(),system_instruction:Ao.optional(),generationConfig:Vo.optional(),generation_config:Vo.optional(),safetySettings:zod.z.array(zo).optional(),safety_settings:zod.z.array(zo).optional(),tools:zod.z.object({function_declarations:zod.z.array(Ji)}).optional(),toolConfig:Do.optional(),tool_config:Do.optional()}),v=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()}),N=class{constructor(t,e){this.version="v1";var o;let a=v.parse(e);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=le((o=a.baseUrl)!=null?o:ft.baseUrl),this.completeChatUrl=le(a.completeChatUrl||`${this.baseUrl}/models/${this.modelName}:generateContent?key=${this.apiKey}`),this.streamChatUrl=le(a.streamChatUrl||`${this.baseUrl}/models/${this.modelName}:streamGenerateContent?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.reduce((e,o)=>e+o.content.map(a=>a.modality==="text"?a.value:"").join(" ").length,0)}transformModelRequest(t){let e=Wi.safeParse(t);if(!e.success)throw new K({info:"Invalid model request",cause:e.error});let o=e.data,a=o.model;if(o.system_instruction&&o.systemInstruction)throw new K({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 K({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 K({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tool_config' and 'toolConfig' are not allowed at the same time")});let s=o.system_instruction||o.systemInstruction,m=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 K({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let l={};d&&(d.function_calling_config.mode==="ANY"&&d.function_calling_config.allowed_function_names&&d.function_calling_config.allowed_function_names.length===1?l.toolChoice=d.function_calling_config.allowed_function_names[0]:l.toolChoice=d.function_calling_config.mode.toLowerCase()),l.seed=m==null?void 0:m.seed,l.maxTokens=m==null?void 0:m.maxOutputTokens,l.temperature=m==null?void 0:m.temperature,l.topP=m==null?void 0:m.topP,l.presencePenalty=m==null?void 0:m.presencePenalty,l.frequencyPenalty=m==null?void 0:m.frequencyPenalty,l.stop=m==null?void 0:m.stopSequences,l.safetySettings=r;let p=ce().parse(ge(l)),u=[];s&&s.parts.forEach(h=>{u.push({role:de,content:[{modality:T,value:h.text}]});}),o.contents.forEach(h=>{let _=h.role;switch(_){case"user":{let O=h.parts.map(E=>"text"in E?{modality:T,value:E.text}:{modality:z,detail:"auto",value:{type:nt,base64:E.inline_data.data,media_type:E.inline_data.mime_type.split("/")[1]}});u.push({role:_,content:O});}break;case"model":{let O=h.parts.map((E,I)=>"text"in E?{modality:T,value:E.text}:{modality:j,id:I.toString(),index:I,name:E.function_call.name,arguments:JSON.stringify(E.function_call.args)});u.push({role:R,content:O});}break;case"function":{let O=h.parts.map((E,I)=>({modality:H,id:I.toString(),index:I,name:E.function_response.name,data:JSON.stringify(E.function_response.response)}));u.push({role:Z,content:O});}break;default:throw new x({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${h.role}' is not supported for model : ${this.modelName}`)})}});let f=[];return o.tools&&o.tools.function_declarations.forEach(h=>{f.push({type:"function",definition:{schema:{name:h.name,description:h.description,parameters:h.parameters}}});}),{modelName:a,config:p,messages:u,tools:f.length>0?f:void 0}}transformConfig(t,e,o){let a=t.toolChoice;delete t.toolChoice;let s=this.modelSchema.config.schema.safeParse(t);if(!s.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:s.error});let m=s.data;Object.keys(m).forEach(p=>{if(!(p in this.modelSchema.config.def))throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${p}',
9
9
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((p,u)=>{let f=this.modelSchema.config.def[u],h=f.param,_=m[u];return h==="maxOutputTokens"&&f.type==="range"&&_===0?p[h]=f.max:p[h]=_,p},{}),d=r.safetySettings;delete r.safetySettings;let l;if(a!==void 0){let p=a;if(!o||o&&o.length===0)throw new B({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"?l={function_calling_config:{mode:"ANY",allowed_function_names:o.map(f=>f.definition.schema.name)}}:l={function_calling_config:{mode:p.toUpperCase()}};else if(o.map(f=>f.definition.schema.name).includes(p))l={function_calling_config:{mode:"ANY",allowed_function_names:[p]}};else throw new B({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 G(G({generation_config:r},l?{tool_config:l}:{}),d?{safety_settings:d}:{})}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let e=r=>{let d=r.match(/^data:image\/[a-zA-Z]+;base64,/);return d?r.substring(d[0].length):r},o=t.map(r=>{let d=it().safeParse(r);if(!d.success)throw new x({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 x({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${d.modality}',
10
+ one of [${u.choices.join(", ")}]`)})}}return P(P({generation_config:r},l?{tool_config:l}:{}),d?{safety_settings:d}:{})}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let e=r=>{let d=r.match(/^data:image\/[a-zA-Z]+;base64,/);return d?r.substring(d[0].length):r},o=t.map(r=>{let d=st().safeParse(r);if(!d.success)throw new x({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 x({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 x({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 a={parts:[]},s=[];if(o.forEach(r=>{switch(r.role){case de:r.content.forEach(d=>{if(d.modality===T)a.parts.push({text:d.value});else throw new x({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 j:{let d=[];r.content.forEach(l=>{if(l.modality===T)d.push({text:l.value});else if(l.modality===R)d.push({function_call:{name:l.name,args:JSON.parse(l.arguments)}});else throw new x({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;case F:{let d=[];r.content.forEach(l=>{if(l.modality===T)d.push({text:l.value});else if(l.modality===z){if(l.value.type==="base64"){let p=l.value.base64;p=e(p),d.push({inline_data:{mime_type:`image/${l.value.media_type}`,data:p}});}else if(l.value.type==="url")throw new x({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${l.value.type}'`)})}else throw new x({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;case X:{let d=[];r.content.forEach(l=>{if(l.modality===H)d.push({function_response:{name:l.name,response:JSON.parse(l.data)}});else throw new x({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;default:throw new x({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(", ")}]`)})}}),s[0].role!==this.modelSchema.roles[F])throw new x({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=r=>r===this.modelSchema.roles[F]||r===this.modelSchema.roles[X]?[this.modelSchema.roles[j]]:[this.modelSchema.roles[F],this.modelSchema.roles[X]];for(let r=1;r<s.length;r++)if(!m(s[r-1].role).includes(s[r].role))throw new x({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${s[r].role}' after message with role : '${s[r-1].role}'`)});if(s[s.length-1].role!==this.modelSchema.roles[F]&&s[s.length-1].role!==this.modelSchema.roles[X])throw new x({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return G({contents:s},a.parts.length>0?{system_instruction:a}:{})}transformTools(t){if(!this.modelSchema.modalities.includes(R))throw new mt({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${R}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:[{function_declarations:t.map(e=>{let o=Qt().safeParse(e);if(!o.success)throw new mt({info:"Invalid tools",cause:o.error});return o.data}).map(e=>({name:e.definition.schema.name,description:e.definition.schema.description,parameters:e.definition.schema.parameters}))}]}}getCompleteChatUrl(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.completeChatUrl);})})}getCompleteChatHeaders(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getCompleteChatData(t,e,o){return k(this,null,function*(){let a=this.transformConfig(t,e,o),s=this.transformMessages(e);if(s.messages&&s.messages.length===0)throw new x({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(G(G(G(G({},this.getDefaultParams()),a),s),m));})})}transformCompleteChatResponse(t){let e=wi.safeParse(t);if(e.success){if(e.data.candidates.length===0)throw new $({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(e.data)}`)});let o=e.data,a=[],s,m=o.candidates[0].content;if(m){let d=m.parts.map((l,p)=>{if("text"in l&&l.text!==void 0)return Zt(l.text);if("functionCall"in l&&l.functionCall!==void 0)return Xt(p,`${l.functionCall.name}_${p}`,l.functionCall.name,JSON.stringify(l.functionCall.args))});return a.push({role:j,content:d}),o.usageMetadata&&(s={promptTokens:o.usageMetadata.promptTokenCount,totalTokens:o.usageMetadata.totalTokenCount,completionTokens:o.usageMetadata.candidatesTokenCount||0}),{messages:a,usage:s,logProbs:void 0}}let r=o.candidates[0].safetyRatings;if(r&&r.length>0&&r.forEach(d=>{if(d.blocked)throw new $({info:`Blocked content for category: ${d.category} with probability: ${d.probability}`,cause:new Error(`Blocked content for category: ${d.category} with probability: ${d.probability}`)})}),o.candidates[0].finishReason==="SAFETY")throw new $({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new $({info:"Invalid response from model",cause:e.error})}getStreamChatUrl(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.streamChatUrl);})})}getStreamChatHeaders(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getStreamChatData(t,e,o){return k(this,null,function*(){let a=this.transformConfig(t,e,o),s=this.transformMessages(e);if(s.messages&&s.messages.length===0)throw new x({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(G(G(G(G({},this.getDefaultParams()),a),s),m));})})}transformStreamChatResponseChunk(t,e){return No(this,null,function*(){let o=(e+t).split(",\r").filter(a=>a.trim()!=="");for(let a of o){let s=a;if(s=s.replace(/\n/g,""),s.startsWith("[")||s.startsWith(",{"))s=s.slice(1);else if(s.endsWith("]")){if(s==="]")return;s=s.slice(0,-1);}let m;try{m=JSON.parse(s);}catch(d){if(d instanceof SyntaxError){e=s;continue}else throw d}e="";let r=Lo.safeParse(m);if(r.success){let d={partialMessages:[]},l=r.data;if(l.candidates.length>0){let p=l.candidates[0].content;p&&"parts"in p&&p.parts.length>0&&p.parts.forEach((u,f)=>{if("text"in u&&u.text!==void 0&&d.partialMessages.push(rt(j,u.text)),"functionCall"in u&&u.functionCall!==void 0){let h=u.functionCall;d.partialMessages.push(lt(j,f,`${h.name}_${f}`,h.name,JSON.stringify(h.args)));}});}l.usageMetadata&&l.usageMetadata.totalTokenCount&&l.usageMetadata.promptTokenCount&&l.usageMetadata.candidatesTokenCount&&(d.usage={promptTokens:l.usageMetadata.promptTokenCount,completionTokens:l.usageMetadata.candidatesTokenCount,totalTokens:l.usageMetadata.totalTokenCount}),yield {partialResponse:d,buffer:e};}else throw new $({info:"Invalid response from model",cause:r.error})}yield {partialResponse:{partialMessages:[]},buffer:e};})}transformProxyStreamChatResponseChunk(t,e,o,a,s){return No(this,null,function*(){if((s==null?void 0:s.alt)!=="sse"){yield*Bt(bi(this.transformStreamChatResponseChunk(t,e)));return}let m=e+t,r=[],d="",l=0;for(;l<m.length;){let p=m.indexOf(`
14
- `,l);if(p===-1){d=m.substring(l);break}else {let u=m.substring(l,p).trim();u&&r.push(u),l=p+1;}}for(let p of r){if(p==="data: [DONE]")return;if(p.startsWith("data: ")){let u=p.substring(6);try{let f=JSON.parse(u),h=Lo.safeParse(f);if(h.success){let _={partialMessages:[]},O=h.data;if(O.candidates.length>0){let E=O.candidates[0].content;E&&"parts"in E&&E.parts.length>0&&E.parts.forEach((I,Ft)=>{if("text"in I&&I.text!==void 0&&_.partialMessages.push(rt(j,I.text)),"functionCall"in I&&I.functionCall!==void 0){let Xe=I.functionCall;_.partialMessages.push(lt(j,Ft,`${Xe.name}_${Ft}`,Xe.name,JSON.stringify(Xe.args)));}});}O.usageMetadata&&O.usageMetadata.totalTokenCount&&O.usageMetadata.promptTokenCount&&O.usageMetadata.candidatesTokenCount&&(_.usage={promptTokens:O.usageMetadata.promptTokenCount,completionTokens:O.usageMetadata.candidatesTokenCount,totalTokens:O.usageMetadata.totalTokenCount}),yield {partialResponse:_,buffer:e};}else throw new $({info:"Invalid response from model",cause:h.error})}catch(f){throw new $({info:`Malformed JSON received in stream: ${u}`,cause:f})}}}yield {partialResponse:{partialMessages:[]},buffer:d};})}getProxyCompleteChatUrl(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.completeChatUrl);})})}getProxyStreamChatUrl(t,e,o){return k(this,null,function*(){return new Promise(a=>{if(!o||Object.keys(o).length===0){a(this.streamChatUrl);return}let s=new URL(this.streamChatUrl);Object.entries(o).forEach(([m,r])=>{r!=null&&s.searchParams.set(m,r);}),a(s.toString());})})}getProxyCompleteChatHeaders(t,e,o){return k(this,null,function*(){if(!e)return {};let a=G({},e);return delete a.host,delete a["content-length"],a})}getProxyStreamChatHeaders(t,e,o){return k(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,e,o)})}},me=class extends N{transformMessages(t){let e=super.transformMessages(t);if(e.systemInstruction){let o={role:this.modelSchema.roles[F],parts:e.systemInstruction.parts};e.contents.unshift(o),delete e.systemInstruction;}return e}},Wo="gemini-1.0-pro-001",qi="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",Ge=C(P,Se).parse({name:Wo,description:qi,maxInputTokens:30720,maxOutputTokens:2048,roles:w,modalities:Oe,config:{def:g.base(1,.9,2048,4,1).def,schema:g.base(1,.9,2048,4,1).schema}}),Ui=v,Bi=class extends me{constructor(t){super(Ge,t);}},Zo="gemini-1.0-pro-latest",Ai="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",Xo=C(P,Se).parse({name:Zo,description:Ai,maxInputTokens:30720,maxOutputTokens:2048,roles:w,modalities:Oe,config:{def:g.base(1,.9,2048,4,1).def,schema:g.base(1,.9,2048,4,1).schema}}),Di=v,Vi=class extends me{constructor(t){super(Xo,t);}},Qo="gemini-1.0-pro-vision",zi="Google's predecessor to Gemini 1.5 Pro, an image understanding model to handle a broad range of applications",Pe=C(P,Yo).parse({name:Qo,description:zi,maxInputTokens:12288,maxOutputTokens:4096,roles:w,modalities:Ko,config:{def:g.c1(1,.4,4096,4,1,32).def,schema:g.c1(1,.4,4096,4,1,32).schema}}),Hi=v,Ki=class extends me{constructor(t){super(Pe,t);}},en="gemini-1.0-pro",Yi="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",we=C(P,Se).parse({name:en,description:Yi,maxInputTokens:30720,maxOutputTokens:2048,roles:w,modalities:Oe,config:{def:g.base(1,.9,2048,4,1).def,schema:g.base(1,.9,2048,4,1).schema}}),Ji=v,Wi=class extends me{constructor(t){super(we,t);}},tn="gemini-1.5-flash-001",Zi="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",ke=C(P,J).parse({name:tn,description:Zi,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),Xi=v,Qi=class extends N{constructor(t){super(ke,t);}},on="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",Ie=C(P,J).parse({name:on,description:es,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,40).def,schema:g.c1(2,1,8192,4,.95,40).schema}}),ts=v,os=class extends N{constructor(t){super(Ie,t);}},nn="gemini-1.5-flash-latest",ns="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",an=C(P,J).parse({name:nn,description:ns,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),as=v,is=class extends N{constructor(t){super(an,t);}},sn="gemini-1.5-flash",ss="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",je=C(P,J).parse({name:sn,description:ss,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),rs=v,ls=class extends N{constructor(t){super(je,t);}},rn="gemini-1.5-pro-001",ms="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Re=C(P,J).parse({name:rn,description:ms,maxInputTokens:2e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),ds=v,cs=class extends N{constructor(t){super(Re,t);}},ln="gemini-1.5-pro-002",ps="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ne=C(P,J).parse({name:ln,description:ps,maxInputTokens:2e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,40).def,schema:g.c1(2,1,8192,4,.95,40).schema}}),us=v,gs=class extends N{constructor(t){super(Ne,t);}},mn="gemini-1.5-pro-latest",hs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",dn=C(P,J).parse({name:mn,description:hs,maxInputTokens:2e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),fs=v,ys=class extends N{constructor(t){super(dn,t);}},cn="gemini-1.5-pro",bs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Le=C(P,J).parse({name:cn,description:bs,maxInputTokens:2e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),_s=v,Es=class extends N{constructor(t){super(Le,t);}},pn="gemini-2.0-flash-exp",Ts="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",Fe=C(P,J).parse({name:pn,description:Ts,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),Ms=v,xs=class extends N{constructor(t){super(Fe,t);}},un="gemini-pro-vision",Cs="An image understanding model to handle a broad range of applications",gn=C(P,Yo).parse({name:un,description:Cs,maxInputTokens:12288,maxOutputTokens:4096,roles:w,modalities:Ko,config:{def:g.c1(1,.4,4096,4,1,32).def,schema:g.c1(1,.4,4096,4,1,32).schema}}),vs=v,Os=class extends me{constructor(t){super(gn,t);}},hn="gemini-pro",Ss="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=C(P,Se).parse({name:hn,description:Ss,maxInputTokens:30720,maxOutputTokens:2048,roles:w,modalities:Oe,config:{def:g.base(1,.9,2048,4,1).def,schema:g.base(1,.9,2048,4,1).schema}}),Gs=v,Ps=class extends me{constructor(t){super(fn,t);}},yn=[S],bn=zod.z.enum([S]),ws=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),ks=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)})}),Is=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(ks).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),ft=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),_n=class{constructor(t,e){this.version="v1";let o=ft.parse(e);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=le(o.baseUrl||ht.baseUrl),this.getEmbeddingsUrl=le(o.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.requests.reduce((e,o)=>e+o.length,0)}transformModelRequest(t){let e=Is.safeParse(t);if(!e.success)throw new K({info:"Invalid model request",cause:e.error});let o=e.data,a=o.model,s={outputDimensionality:o.outputDimensionality},m=ce().parse(ge(s)),r={modality:S,requests:o.requests.reduce((d,l)=>(d.push(...l.content.parts.map(p=>p.text)),d),[])};return {modelName:a,config:m,embeddingRequests:r}}transformConfig(t,e){let o=this.modelSchema.config.schema.safeParse(t);if(!o.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let a=o.data;return Object.keys(a).forEach(s=>{if(!this.modelSchema.config.def[s])throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
15
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(a).reduce((s,m)=>{let r=this.modelSchema.config.def[m].param,d=a[m];return s[r]=d,s},{})}transformEmbeddingRequests(t){let e=fe().safeParse(t);if(!e.success)throw new Q({info:"Invalid embedding requests",cause:e.error});if(t.modality!==S)throw new Q({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${S}' modality is supported for model : '${this.modelName}'`)});return {requests:e.data.requests.map(o=>({model:`models/${this.modelName}`,content:{parts:[{text:o}]}}))}}getGetEmbeddingsUrl(t,e){return k(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,e){return k(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,e){return k(this,null,function*(){return new Promise(o=>{let a=this.transformConfig(t),s=this.transformEmbeddingRequests(e);if(e.requests.length===0)throw new Q({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});a.outputDimensionality&&(s.requests.forEach(m=>{m.outputDimensionality=a.outputDimensionality;}),delete a.outputDimensionality),o(G(G(G({},this.getDefaultParams()),a),s));})})}transformGetEmbeddingsResponse(t){let e=ws.safeParse(t);if(e.success){let o=e.data.embeddings.map((a,s)=>({index:s,embedding:a.values}));return {encodingFormat:pe,embeddings:o}}throw new $({info:"Invalid response from model",cause:e.error})}},En="text-embedding-001",js="text-embedding-001",Tn=U(bn).parse({name:En,description:js,modalities:yn,maxInputTokens:2048,maxOutputTokens:768,config:{def:_e.base(768).def,schema:_e.base(768).schema}}),Rs=ft,Ns=class extends _n{constructor(t){super(Tn,t);}},Mn="text-embedding-004",Ls="text-embedding-004",xn=U(bn).parse({name:Mn,description:Ls,modalities:yn,maxInputTokens:2048,maxOutputTokens:768,config:{def:_e.base(768).def,schema:_e.base(768).schema}}),Fs=ft,$s=class extends _n{constructor(t){super(xn,t);}};var qs="vertex",oe=class{constructor(){this.version="v1";this.name=qs;this.chatModelFactories={[wn]:{model:Be,modelOptions:kn,modelSchema:Et},[In]:{model:Ae,modelOptions:jn,modelSchema:Tt},[Rn]:{model:De,modelOptions:Nn,modelSchema:Mt},[Ln]:{model:Ve,modelOptions:Fn,modelSchema:xt},[$n]:{model:ze,modelOptions:qn,modelSchema:Ct},[Un]:{model:He,modelOptions:Bn,modelSchema:vt},[Gn]:{model:Ue,modelOptions:Pn,modelSchema:_t},[On]:{model:qe,modelOptions:Sn,modelSchema:bt},[Cn]:{model:$e,modelOptions:vn,modelSchema:yt},[An]:{model:Ke,modelOptions:Dn,modelSchema:Ot}};this.embeddingModelFactories={[St]:{model:Ye,modelOptions:Vn,modelSchema:Gt},[Pt]:{model:Je,modelOptions:zn,modelSchema:wt},[jt]:{model:Ze,modelOptions:Kn,modelSchema:Rt},[kt]:{model:We,modelOptions:Hn,modelSchema:It}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}chatModel(e){let o=e.modelName;if(!(o in this.chatModelFactories))throw new se({info:`Vertex chat model: ${o} not found`,cause:new Error(`Vertex chat model: ${o} not found, available chat models:
12
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let a={parts:[]},s=[];if(o.forEach(r=>{switch(r.role){case de:r.content.forEach(d=>{if(d.modality===T)a.parts.push({text:d.value});else throw new x({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})});break;case R:{let d=[];r.content.forEach(l=>{if(l.modality===T)d.push({text:l.value});else if(l.modality===j)d.push({function_call:{name:l.name,args:JSON.parse(l.arguments)}});else throw new x({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;case F:{let d=[];r.content.forEach(l=>{if(l.modality===T)d.push({text:l.value});else if(l.modality===z){if(l.value.type==="base64"){let p=l.value.base64;p=e(p),d.push({inline_data:{mime_type:`image/${l.value.media_type}`,data:p}});}else if(l.value.type==="url")throw new x({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${l.value.type}'`)})}else throw new x({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;case Z:{let d=[];r.content.forEach(l=>{if(l.modality===H)d.push({function_response:{name:l.name,response:JSON.parse(l.data)}});else throw new x({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;default:throw new x({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(", ")}]`)})}}),s[0].role!==this.modelSchema.roles[F])throw new x({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=r=>r===this.modelSchema.roles[F]||r===this.modelSchema.roles[Z]?[this.modelSchema.roles[R]]:[this.modelSchema.roles[F],this.modelSchema.roles[Z]];for(let r=1;r<s.length;r++)if(!m(s[r-1].role).includes(s[r].role))throw new x({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${s[r].role}' after message with role : '${s[r-1].role}'`)});if(s[s.length-1].role!==this.modelSchema.roles[F]&&s[s.length-1].role!==this.modelSchema.roles[Z])throw new x({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return P({contents:s},a.parts.length>0?{system_instruction:a}:{})}transformTools(t){if(!this.modelSchema.modalities.includes(j))throw new dt({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${j}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:[{function_declarations:t.map(e=>{let o=ao().safeParse(e);if(!o.success)throw new dt({info:"Invalid tools",cause:o.error});return o.data}).map(e=>({name:e.definition.schema.name,description:e.definition.schema.description,parameters:e.definition.schema.parameters}))}]}}getCompleteChatUrl(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.completeChatUrl);})})}getCompleteChatHeaders(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getCompleteChatData(t,e,o){return k(this,null,function*(){let a=this.transformConfig(t,e,o),s=this.transformMessages(e);if(s.messages&&s.messages.length===0)throw new x({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(P(P(P(P({},this.getDefaultParams()),a),s),m));})})}transformCompleteChatResponse(t){let e=Ai.safeParse(t);if(e.success){if(e.data.candidates.length===0)throw new $({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(e.data)}`)});let o=e.data,a=[],s,m=o.candidates[0].content;if(m){let d=m.parts.map((l,p)=>{if("text"in l&&l.text!==void 0)return oo(l.text);if("functionCall"in l&&l.functionCall!==void 0)return no(p,`${l.functionCall.name}_${p}`,l.functionCall.name,JSON.stringify(l.functionCall.args))});return a.push({role:R,content:d}),o.usageMetadata&&(s={promptTokens:o.usageMetadata.promptTokenCount,totalTokens:o.usageMetadata.totalTokenCount,completionTokens:o.usageMetadata.candidatesTokenCount||0}),{messages:a,usage:s,logProbs:void 0}}let r=o.candidates[0].safetyRatings;if(r&&r.length>0&&r.forEach(d=>{if(d.blocked)throw new $({info:`Blocked content for category: ${d.category} with probability: ${d.probability}`,cause:new Error(`Blocked content for category: ${d.category} with probability: ${d.probability}`)})}),o.candidates[0].finishReason==="SAFETY")throw new $({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new $({info:"Invalid response from model",cause:e.error})}getStreamChatUrl(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.streamChatUrl);})})}getStreamChatHeaders(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getStreamChatData(t,e,o){return k(this,null,function*(){let a=this.transformConfig(t,e,o),s=this.transformMessages(e);if(s.messages&&s.messages.length===0)throw new x({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(P(P(P(P({},this.getDefaultParams()),a),s),m));})})}transformStreamChatResponseChunk(t,e){return Uo(this,null,function*(){let o=(e+t).split(",\r").filter(a=>a.trim()!=="");for(let a of o){let s=a;if(s=s.replace(/\n/g,""),s.startsWith("[")||s.startsWith(",{"))s=s.slice(1);else if(s.endsWith("]")){if(s==="]")return;s=s.slice(0,-1);}let m;try{m=JSON.parse(s);}catch(d){if(d instanceof SyntaxError){e=s;continue}else throw d}e="";let r=Bo.safeParse(m);if(r.success){let d={partialMessages:[]},l=r.data;if(l.candidates.length>0){let p=l.candidates[0].content;p&&"parts"in p&&p.parts.length>0&&p.parts.forEach((u,f)=>{if("text"in u&&u.text!==void 0&&d.partialMessages.push(lt(R,u.text)),"functionCall"in u&&u.functionCall!==void 0){let h=u.functionCall;d.partialMessages.push(mt(R,f,`${h.name}_${f}`,h.name,JSON.stringify(h.args)));}});}l.usageMetadata&&l.usageMetadata.totalTokenCount&&l.usageMetadata.promptTokenCount&&l.usageMetadata.candidatesTokenCount&&(d.usage={promptTokens:l.usageMetadata.promptTokenCount,completionTokens:l.usageMetadata.candidatesTokenCount,totalTokens:l.usageMetadata.totalTokenCount}),yield {partialResponse:d,buffer:e};}else throw new $({info:"Invalid response from model",cause:r.error})}yield {partialResponse:{partialMessages:[]},buffer:e};})}transformProxyStreamChatResponseChunk(t,e,o,a,s){return Uo(this,null,function*(){if((s==null?void 0:s.alt)!=="sse"){yield*At(wi(this.transformStreamChatResponseChunk(t,e)));return}let m=e+t,r=[],d="",l=0;for(;l<m.length;){let p=m.indexOf(`
14
+ `,l);if(p===-1){d=m.substring(l);break}else {let u=m.substring(l,p).trim();u&&r.push(u),l=p+1;}}for(let p of r){if(p==="data: [DONE]")return;if(p.startsWith("data: ")){let u=p.substring(6);try{let f=JSON.parse(u),h=Bo.safeParse(f);if(h.success){let _={partialMessages:[]},O=h.data;if(O.candidates.length>0){let E=O.candidates[0].content;E&&"parts"in E&&E.parts.length>0&&E.parts.forEach((I,$t)=>{if("text"in I&&I.text!==void 0&&_.partialMessages.push(lt(R,I.text)),"functionCall"in I&&I.functionCall!==void 0){let Ze=I.functionCall;_.partialMessages.push(mt(R,$t,`${Ze.name}_${$t}`,Ze.name,JSON.stringify(Ze.args)));}});}O.usageMetadata&&O.usageMetadata.totalTokenCount&&O.usageMetadata.promptTokenCount&&O.usageMetadata.candidatesTokenCount&&(_.usage={promptTokens:O.usageMetadata.promptTokenCount,completionTokens:O.usageMetadata.candidatesTokenCount,totalTokens:O.usageMetadata.totalTokenCount}),yield {partialResponse:_,buffer:e};}else throw new $({info:"Invalid response from model",cause:h.error})}catch(f){throw new $({info:`Malformed JSON received in stream: ${u}`,cause:f})}}}yield {partialResponse:{partialMessages:[]},buffer:d};})}getProxyCompleteChatUrl(t,e,o){return k(this,null,function*(){return new Promise(a=>{a(this.completeChatUrl);})})}getProxyStreamChatUrl(t,e,o){return k(this,null,function*(){return new Promise(a=>{if(!o||Object.keys(o).length===0){a(this.streamChatUrl);return}let s=new URL(this.streamChatUrl);Object.entries(o).forEach(([m,r])=>{r!=null&&s.searchParams.set(m,r);}),a(s.toString());})})}getProxyCompleteChatHeaders(t,e,o){return k(this,null,function*(){if(!e)return {};let a=P({},e);return delete a.host,delete a["content-length"],a})}getProxyStreamChatHeaders(t,e,o){return k(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,e,o)})}},me=class extends N{transformMessages(t){let e=super.transformMessages(t);if(e.systemInstruction){let o={role:this.modelSchema.roles[F],parts:e.systemInstruction.parts};e.contents.unshift(o),delete e.systemInstruction;}return e}},tn="gemini-1.0-pro-001",Xi="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",Pe=C(G,Se).parse({name:tn,description:Xi,maxInputTokens:30720,maxOutputTokens:2048,roles:w,modalities:Oe,config:{def:g.base(1,.9,2048,4,1).def,schema:g.base(1,.9,2048,4,1).schema}}),Zi=v,Qi=class extends me{constructor(t){super(Pe,t);}},on="gemini-1.0-pro-latest",es="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",nn=C(G,Se).parse({name:on,description:es,maxInputTokens:30720,maxOutputTokens:2048,roles:w,modalities:Oe,config:{def:g.base(1,.9,2048,4,1).def,schema:g.base(1,.9,2048,4,1).schema}}),ts=v,os=class extends me{constructor(t){super(nn,t);}},an="gemini-1.0-pro-vision",ns="Google's predecessor to Gemini 1.5 Pro, an image understanding model to handle a broad range of applications",Ge=C(G,Qo).parse({name:an,description:ns,maxInputTokens:12288,maxOutputTokens:4096,roles:w,modalities:Zo,config:{def:g.c1(1,.4,4096,4,1,32).def,schema:g.c1(1,.4,4096,4,1,32).schema}}),as=v,is=class extends me{constructor(t){super(Ge,t);}},sn="gemini-1.0-pro",ss="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",we=C(G,Se).parse({name:sn,description:ss,maxInputTokens:30720,maxOutputTokens:2048,roles:w,modalities:Oe,config:{def:g.base(1,.9,2048,4,1).def,schema:g.base(1,.9,2048,4,1).schema}}),rs=v,ls=class extends me{constructor(t){super(we,t);}},rn="gemini-1.5-flash-001",ms="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",ke=C(G,J).parse({name:rn,description:ms,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),ds=v,cs=class extends N{constructor(t){super(ke,t);}},ln="gemini-1.5-flash-002",ps="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",Ie=C(G,J).parse({name:ln,description:ps,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,40).def,schema:g.c1(2,1,8192,4,.95,40).schema}}),us=v,gs=class extends N{constructor(t){super(Ie,t);}},mn="gemini-1.5-flash-latest",hs="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",dn=C(G,J).parse({name:mn,description:hs,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),fs=v,ys=class extends N{constructor(t){super(dn,t);}},cn="gemini-1.5-flash",bs="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",Re=C(G,J).parse({name:cn,description:bs,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),_s=v,Es=class extends N{constructor(t){super(Re,t);}},pn="gemini-1.5-pro-001",Ts="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",je=C(G,J).parse({name:pn,description:Ts,maxInputTokens:2e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),Ms=v,xs=class extends N{constructor(t){super(je,t);}},un="gemini-1.5-pro-002",Cs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ne=C(G,J).parse({name:un,description:Cs,maxInputTokens:2e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,40).def,schema:g.c1(2,1,8192,4,.95,40).schema}}),vs=v,Os=class extends N{constructor(t){super(Ne,t);}},gn="gemini-1.5-pro-latest",Ss="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",hn=C(G,J).parse({name:gn,description:Ss,maxInputTokens:2e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),Ps=v,Gs=class extends N{constructor(t){super(hn,t);}},fn="gemini-1.5-pro",ws="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Le=C(G,J).parse({name:fn,description:ws,maxInputTokens:2e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),ks=v,Is=class extends N{constructor(t){super(Le,t);}},yn="gemini-2.0-flash-exp",Rs="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",Fe=C(G,J).parse({name:yn,description:Rs,maxInputTokens:1e6,maxOutputTokens:8192,roles:w,modalities:Y,config:{def:g.c1(2,1,8192,4,.95,64).def,schema:g.c1(2,1,8192,4,.95,64).schema}}),js=v,Ns=class extends N{constructor(t){super(Fe,t);}},bn="gemini-pro-vision",Ls="An image understanding model to handle a broad range of applications",_n=C(G,Qo).parse({name:bn,description:Ls,maxInputTokens:12288,maxOutputTokens:4096,roles:w,modalities:Zo,config:{def:g.c1(1,.4,4096,4,1,32).def,schema:g.c1(1,.4,4096,4,1,32).schema}}),Fs=v,$s=class extends me{constructor(t){super(_n,t);}},En="gemini-pro",qs="A model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Tn=C(G,Se).parse({name:En,description:qs,maxInputTokens:30720,maxOutputTokens:2048,roles:w,modalities:Oe,config:{def:g.base(1,.9,2048,4,1).def,schema:g.base(1,.9,2048,4,1).schema}}),Us=v,Bs=class extends me{constructor(t){super(Tn,t);}},Mn=[S],xn=zod.z.enum([S]),As=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),Ds=zod.z.object({model:zod.z.string().min(1),content:zod.z.object({parts:zod.z.array(zod.z.object({text:zod.z.string().min(1)})).min(1)})}),Vs=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(Ds).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),yt=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),Cn=class{constructor(t,e){this.version="v1";let o=yt.parse(e);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=le(o.baseUrl||ft.baseUrl),this.getEmbeddingsUrl=le(o.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.requests.reduce((e,o)=>e+o.length,0)}transformModelRequest(t){let e=Vs.safeParse(t);if(!e.success)throw new K({info:"Invalid model request",cause:e.error});let o=e.data,a=o.model,s={outputDimensionality:o.outputDimensionality},m=ce().parse(ge(s)),r={modality:S,requests:o.requests.reduce((d,l)=>(d.push(...l.content.parts.map(p=>p.text)),d),[])};return {modelName:a,config:m,embeddingRequests:r}}transformConfig(t,e){let o=this.modelSchema.config.schema.safeParse(t);if(!o.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let a=o.data;return Object.keys(a).forEach(s=>{if(!this.modelSchema.config.def[s])throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
15
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(a).reduce((s,m)=>{let r=this.modelSchema.config.def[m].param,d=a[m];return s[r]=d,s},{})}transformEmbeddingRequests(t){let e=fe().safeParse(t);if(!e.success)throw new Q({info:"Invalid embedding requests",cause:e.error});if(t.modality!==S)throw new Q({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${S}' modality is supported for model : '${this.modelName}'`)});return {requests:e.data.requests.map(o=>({model:`models/${this.modelName}`,content:{parts:[{text:o}]}}))}}getGetEmbeddingsUrl(t,e){return k(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,e){return k(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,e){return k(this,null,function*(){return new Promise(o=>{let a=this.transformConfig(t),s=this.transformEmbeddingRequests(e);if(e.requests.length===0)throw new Q({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});a.outputDimensionality&&(s.requests.forEach(m=>{m.outputDimensionality=a.outputDimensionality;}),delete a.outputDimensionality),o(P(P(P({},this.getDefaultParams()),a),s));})})}transformGetEmbeddingsResponse(t){let e=As.safeParse(t);if(e.success){let o=e.data.embeddings.map((a,s)=>({index:s,embedding:a.values}));return {encodingFormat:pe,embeddings:o}}throw new $({info:"Invalid response from model",cause:e.error})}},vn="text-embedding-001",zs="text-embedding-001",On=U(xn).parse({name:vn,description:zs,modalities:Mn,maxInputTokens:2048,maxOutputTokens:768,config:{def:_e.base(768).def,schema:_e.base(768).schema}}),Hs=yt,Ks=class extends Cn{constructor(t){super(On,t);}},Sn="text-embedding-004",Ys="text-embedding-004",Pn=U(xn).parse({name:Sn,description:Ys,modalities:Mn,maxInputTokens:2048,maxOutputTokens:768,config:{def:_e.base(768).def,schema:_e.base(768).schema}}),Js=yt,Ws=class extends Cn{constructor(t){super(Pn,t);}};var Xs="vertex",oe=class{constructor(){this.version="v1";this.name=Xs;this.chatModelFactories={[Nn]:{model:Be,modelOptions:Ln,modelSchema:Tt},[Fn]:{model:Ae,modelOptions:$n,modelSchema:Mt},[qn]:{model:De,modelOptions:Un,modelSchema:xt},[Bn]:{model:Ve,modelOptions:An,modelSchema:Ct},[Dn]:{model:ze,modelOptions:Vn,modelSchema:vt},[zn]:{model:He,modelOptions:Hn,modelSchema:Ot},[Rn]:{model:Ue,modelOptions:jn,modelSchema:Et},[kn]:{model:qe,modelOptions:In,modelSchema:_t},[Gn]:{model:$e,modelOptions:wn,modelSchema:bt},[Kn]:{model:Ke,modelOptions:Yn,modelSchema:St}};this.embeddingModelFactories={[Pt]:{model:Ye,modelOptions:Jn,modelSchema:Gt},[wt]:{model:Je,modelOptions:Wn,modelSchema:kt},[jt]:{model:Xe,modelOptions:Zn,modelSchema:Nt},[It]:{model:We,modelOptions:Xn,modelSchema:Rt}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}chatModel(e){let o=e.modelName;if(!(o in this.chatModelFactories))throw new se({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 a=this.chatModelFactories[o].model,s=this.chatModelFactories[o].modelOptions.parse(e);return new a(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,o)=>(e[o]=this.embeddingModelFactories[o].modelSchema,e),{})}embeddingModel(e){let o=e.modelName;if(!(o in this.embeddingModelFactories))throw new se({info:`Vertex embedding model: ${o} not found`,cause:new Error(`Vertex embedding model: ${o} not found, available embedding models:
17
- ${this.embeddingModelLiterals().join(", ")}`)});let a=this.embeddingModelFactories[o].model,s=this.embeddingModelFactories[o].modelOptions.parse(e);return new a(s)}};oe.baseUrl=(e,o,a="google")=>`https://${e}-aiplatform.googleapis.com/v1/projects/${o}/locations/${e}/publishers/${a}`;var b=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()}),y=class extends N{constructor(o,a){let s=b.parse(a),m;if(s.baseUrl)m=s.baseUrl;else if(s.location&&s.projectId)m=oe.baseUrl(s.location,s.projectId,s.publisher);else throw new ye({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:s.modelName,apiKey:"random-api-key",completeChatUrl:`${m}/models/${s.modelName}:generateContent`,streamChatUrl:`${m}/models/${s.modelName}:streamGenerateContent`});this.version="v1";this.modelSchema=o,this.modelName=s.modelName,this.accessToken=s.accessToken,this.location=s.location,this.projectId=s.projectId,this.publisher=s.publisher;}getDefaultHeaders(){return Ut(ie({},super.getDefaultHeaders()),{Authorization:`Bearer ${this.accessToken}`})}};var Cn="gemini-1.0-pro-001",yt=Ge,vn=b,$e=class extends y{constructor(e){super(yt,e);}};var On="gemini-1.0-pro-vision",bt=Pe,Sn=b,qe=class extends y{constructor(e){super(bt,e);}};var Gn="gemini-1.0-pro",_t=we,Pn=b,Ue=class extends y{constructor(e){super(_t,e);}};var wn="gemini-1.5-flash-001",Et=ke,kn=b,Be=class extends y{constructor(e){super(Et,e);}};var In="gemini-1.5-flash-002",Tt=Ie,jn=b,Ae=class extends y{constructor(e){super(Tt,e);}};var Rn="gemini-1.5-flash",Mt=je,Nn=b,De=class extends y{constructor(e){super(Mt,e);}};var Ln="gemini-1.5-pro-001",xt=Re,Fn=b,Ve=class extends y{constructor(e){super(xt,e);}};var $n="gemini-1.5-pro-002",Ct=Ne,qn=b,ze=class extends y{constructor(e){super(Ct,e);}};var Un="gemini-1.5-pro",vt=Le,Bn=b,He=class extends y{constructor(e){super(vt,e);}};var An="gemini-2.0-flash-exp",Ot=Fe,Dn=b,Ke=class extends y{constructor(e){super(Ot,e);}};var ee=[S],te=zod.z.enum([S]);var Yn=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 Jn=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 Z=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()}),D=class{constructor(e,o){this.version="v1";let a=Z.parse(o);this.modelSchema=e,this.modelName=a.modelName,this.accessToken=a.accessToken;let s;if(a.baseUrl)s=a.baseUrl;else if(a.location&&a.projectId)s=oe.baseUrl(a.location,a.projectId,a.publisher);else throw new ye({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=s,this.getEmbeddingsUrl=`${this.baseUrl}/models/${a.modelName}:predict`,this.location=a.location,this.projectId=a.projectId;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`}}getDefaultParams(){return {}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((o,a)=>o+a.length,0)}transformModelRequest(e){var l,p,u,f;let o=Jn.safeParse(e);if(!o.success)throw new K({info:"Invalid model request",cause:o.error});let a=o.data,s=a.model,m={autoTruncate:((l=a.parameters)==null?void 0:l.auto_truncate)||((p=a.parameters)==null?void 0:p.autoTruncate),dimensions:((u=a.parameters)==null?void 0:u.output_dimensionality)||((f=a.parameters)==null?void 0:f.outputDimensionality)},r=ce().parse(ge(m)),d={modality:S,requests:a.instances.map(h=>h.content)};return {modelName:s,config:r,embeddingRequests:d}}transformConfig(e,o){let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let s=a.data;return Object.keys(s).forEach(r=>{if(!this.modelSchema.config.def[r])throw new B({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(s).reduce((r,d)=>{let p=this.modelSchema.config.def[d].param,u=s[d];return r[p]=u,r},{})}}transformEmbeddingRequests(e){let o=fe().safeParse(e);if(!o.success)throw new Q({info:"Invalid embedding requests",cause:o.error});if(e.modality!==S)throw new Q({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${S}' modality is supported for model : '${this.modelName}'`)});return {instances:o.data.requests.map(s=>({content:s}))}}getGetEmbeddingsUrl(e,o){return he(this,null,function*(){return new Promise(a=>{a(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return he(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return he(this,null,function*(){return new Promise(a=>{if(o.requests.length===0)throw new Q({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});a(ie(ie(ie({},this.getDefaultParams()),this.transformConfig(e)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o=Yn.safeParse(e);if(o.success){let s=o.data.predictions.map((m,r)=>({index:r,embedding:m.embeddings.values}));return {encodingFormat:pe,embeddings:s}}throw new $({info:"Invalid response from model",cause:o.error})}};var Nt=t=>q({param:"output_dimensionality",title:re.DIMENSIONS.title,description:re.DIMENSIONS.description,min:1,max:t,step:1,default:t}),Lt=Po({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 Wn=t=>zod.z.object({dimensions:Nt(t).schema,autoTruncate:Lt.schema}),Zn=t=>({dimensions:Nt(t).def,autoTruncate:Lt.def});var L={base:t=>({def:Zn(t),schema:Wn(t)})};var St="text-embedding-004",As="text-embedding-004",Gt=U(te).parse({name:St,description:As,modalities:ee,maxInputTokens:2048,maxOutputTokens:768,config:{def:L.base(768).def,schema:L.base(768).schema}}),Vn=Z,Ye=class extends D{constructor(e){super(Gt,e);}};var Pt="text-multilingual-embedding-002",Ds="text-multilingual-embedding-002",wt=U(te).parse({name:Pt,description:Ds,modalities:ee,maxInputTokens:2048,maxOutputTokens:768,config:{def:L.base(768).def,schema:L.base(768).schema}}),zn=Z,Je=class extends D{constructor(e){super(wt,e);}};var kt="textembedding-gecko-multilingual@001",Vs="textembedding-gecko-multilingual@001",It=U(te).parse({name:kt,description:Vs,modalities:ee,maxInputTokens:2048,maxOutputTokens:768,config:{def:L.base(768).def,schema:L.base(768).schema}}),Hn=Z,We=class extends D{constructor(e){super(It,e);}};var jt="textembedding-gecko@003",zs="textembedding-gecko@003",Rt=U(te).parse({name:jt,description:zs,modalities:ee,maxInputTokens:2048,maxOutputTokens:768,config:{def:L.base(768).def,schema:L.base(768).schema}}),Kn=Z,Ze=class extends D{constructor(e){super(Rt,e);}};
17
+ ${this.embeddingModelLiterals().join(", ")}`)});let a=this.embeddingModelFactories[o].model,s=this.embeddingModelFactories[o].modelOptions.parse(e);return new a(s)}};oe.baseUrl=(e,o,a="google")=>`https://${e}-aiplatform.googleapis.com/v1/projects/${o}/locations/${e}/publishers/${a}`;var b=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()}),y=class extends N{constructor(o,a){let s=b.parse(a),m;if(s.baseUrl)m=s.baseUrl;else if(s.location&&s.projectId)m=oe.baseUrl(s.location,s.projectId,s.publisher);else throw new ye({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:s.modelName,apiKey:"random-api-key",completeChatUrl:`${m}/models/${s.modelName}:generateContent`,streamChatUrl:`${m}/models/${s.modelName}:streamGenerateContent`});this.version="v1";this.modelSchema=o,this.modelName=s.modelName,this.accessToken=s.accessToken,this.location=s.location,this.projectId=s.projectId,this.publisher=s.publisher;}getDefaultHeaders(){return Bt(ie({},super.getDefaultHeaders()),{Authorization:`Bearer ${this.accessToken}`})}};var Gn="gemini-1.0-pro-001",bt=Pe,wn=b,$e=class extends y{constructor(e){super(bt,e);}};var kn="gemini-1.0-pro-vision",_t=Ge,In=b,qe=class extends y{constructor(e){super(_t,e);}};var Rn="gemini-1.0-pro",Et=we,jn=b,Ue=class extends y{constructor(e){super(Et,e);}};var Nn="gemini-1.5-flash-001",Tt=ke,Ln=b,Be=class extends y{constructor(e){super(Tt,e);}};var Fn="gemini-1.5-flash-002",Mt=Ie,$n=b,Ae=class extends y{constructor(e){super(Mt,e);}};var qn="gemini-1.5-flash",xt=Re,Un=b,De=class extends y{constructor(e){super(xt,e);}};var Bn="gemini-1.5-pro-001",Ct=je,An=b,Ve=class extends y{constructor(e){super(Ct,e);}};var Dn="gemini-1.5-pro-002",vt=Ne,Vn=b,ze=class extends y{constructor(e){super(vt,e);}};var zn="gemini-1.5-pro",Ot=Le,Hn=b,He=class extends y{constructor(e){super(Ot,e);}};var Kn="gemini-2.0-flash-exp",St=Fe,Yn=b,Ke=class extends y{constructor(e){super(St,e);}};var ee=[S],te=zod.z.enum([S]);var Qn=zod.z.object({predictions:zod.z.array(zod.z.object({embeddings:zod.z.object({values:zod.z.array(zod.z.number()),statistics:zod.z.object({token_count:zod.z.number(),truncated:zod.z.boolean()})})}))});var ea=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 X=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()}),D=class{constructor(e,o){this.version="v1";let a=X.parse(o);this.modelSchema=e,this.modelName=a.modelName,this.accessToken=a.accessToken;let s;if(a.baseUrl)s=a.baseUrl;else if(a.location&&a.projectId)s=oe.baseUrl(a.location,a.projectId,a.publisher);else throw new ye({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=s,this.getEmbeddingsUrl=`${this.baseUrl}/models/${a.modelName}:predict`,this.location=a.location,this.projectId=a.projectId;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`}}getDefaultParams(){return {}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((o,a)=>o+a.length,0)}transformModelRequest(e){var l,p,u,f;let o=ea.safeParse(e);if(!o.success)throw new K({info:"Invalid model request",cause:o.error});let a=o.data,s=a.model,m={autoTruncate:((l=a.parameters)==null?void 0:l.auto_truncate)||((p=a.parameters)==null?void 0:p.autoTruncate),dimensions:((u=a.parameters)==null?void 0:u.output_dimensionality)||((f=a.parameters)==null?void 0:f.outputDimensionality)},r=ce().parse(ge(m)),d={modality:S,requests:a.instances.map(h=>h.content)};return {modelName:s,config:r,embeddingRequests:d}}transformConfig(e,o){let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let s=a.data;return Object.keys(s).forEach(r=>{if(!this.modelSchema.config.def[r])throw new B({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(s).reduce((r,d)=>{let p=this.modelSchema.config.def[d].param,u=s[d];return r[p]=u,r},{})}}transformEmbeddingRequests(e){let o=fe().safeParse(e);if(!o.success)throw new Q({info:"Invalid embedding requests",cause:o.error});if(e.modality!==S)throw new Q({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${S}' modality is supported for model : '${this.modelName}'`)});return {instances:o.data.requests.map(s=>({content:s}))}}getGetEmbeddingsUrl(e,o){return he(this,null,function*(){return new Promise(a=>{a(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return he(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return he(this,null,function*(){return new Promise(a=>{if(o.requests.length===0)throw new Q({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});a(ie(ie(ie({},this.getDefaultParams()),this.transformConfig(e)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o=Qn.safeParse(e);if(o.success){let s=o.data.predictions.map((m,r)=>({index:r,embedding:m.embeddings.values}));return {encodingFormat:pe,embeddings:s}}throw new $({info:"Invalid response from model",cause:o.error})}};var Lt=t=>q({param:"output_dimensionality",title:re.DIMENSIONS.title,description:re.DIMENSIONS.description,min:1,max:t,step:1,default:t}),Ft=jo({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 ta=t=>zod.z.object({dimensions:Lt(t).schema,autoTruncate:Ft.schema}),oa=t=>({dimensions:Lt(t).def,autoTruncate:Ft.def});var L={base:t=>({def:oa(t),schema:ta(t)})};var Pt="text-embedding-004",er="text-embedding-004",Gt=U(te).parse({name:Pt,description:er,modalities:ee,maxInputTokens:2048,maxOutputTokens:768,config:{def:L.base(768).def,schema:L.base(768).schema}}),Jn=X,Ye=class extends D{constructor(e){super(Gt,e);}};var wt="text-multilingual-embedding-002",tr="text-multilingual-embedding-002",kt=U(te).parse({name:wt,description:tr,modalities:ee,maxInputTokens:2048,maxOutputTokens:768,config:{def:L.base(768).def,schema:L.base(768).schema}}),Wn=X,Je=class extends D{constructor(e){super(kt,e);}};var It="textembedding-gecko-multilingual@001",or="textembedding-gecko-multilingual@001",Rt=U(te).parse({name:It,description:or,modalities:ee,maxInputTokens:2048,maxOutputTokens:768,config:{def:L.base(768).def,schema:L.base(768).schema}}),Xn=X,We=class extends D{constructor(e){super(Rt,e);}};var jt="textembedding-gecko@003",nr="textembedding-gecko@003",Nt=U(te).parse({name:jt,description:nr,modalities:ee,maxInputTokens:2048,maxOutputTokens:768,config:{def:L.base(768).def,schema:L.base(768).schema}}),Zn=X,Xe=class extends D{constructor(e){super(Nt,e);}};
19
19
 
20
20
  exports.BaseChatModelOptions = b;
21
21
  exports.BaseChatModelVertex = y;
22
22
  exports.BaseEmbeddingModel = D;
23
- exports.BaseEmbeddingModelOptions = Z;
23
+ exports.BaseEmbeddingModelOptions = X;
24
24
  exports.Gemini1_0Pro = Ue;
25
25
  exports.Gemini1_0Pro001 = $e;
26
- exports.Gemini1_0Pro001Literal = Cn;
27
- exports.Gemini1_0Pro001Options = vn;
28
- exports.Gemini1_0Pro001Schema = yt;
29
- exports.Gemini1_0ProLiteral = Gn;
30
- exports.Gemini1_0ProOptions = Pn;
31
- exports.Gemini1_0ProSchema = _t;
26
+ exports.Gemini1_0Pro001Literal = Gn;
27
+ exports.Gemini1_0Pro001Options = wn;
28
+ exports.Gemini1_0Pro001Schema = bt;
29
+ exports.Gemini1_0ProLiteral = Rn;
30
+ exports.Gemini1_0ProOptions = jn;
31
+ exports.Gemini1_0ProSchema = Et;
32
32
  exports.Gemini1_0ProVision = qe;
33
- exports.Gemini1_0ProVisionLiteral = On;
34
- exports.Gemini1_0ProVisionOptions = Sn;
35
- exports.Gemini1_0ProVisionSchema = bt;
33
+ exports.Gemini1_0ProVisionLiteral = kn;
34
+ exports.Gemini1_0ProVisionOptions = In;
35
+ exports.Gemini1_0ProVisionSchema = _t;
36
36
  exports.Gemini1_5Flash = De;
37
37
  exports.Gemini1_5Flash001 = Be;
38
- exports.Gemini1_5Flash001Literal = wn;
39
- exports.Gemini1_5Flash001Options = kn;
40
- exports.Gemini1_5Flash001Schema = Et;
38
+ exports.Gemini1_5Flash001Literal = Nn;
39
+ exports.Gemini1_5Flash001Options = Ln;
40
+ exports.Gemini1_5Flash001Schema = Tt;
41
41
  exports.Gemini1_5Flash002 = Ae;
42
- exports.Gemini1_5Flash002Literal = In;
43
- exports.Gemini1_5Flash002Options = jn;
44
- exports.Gemini1_5Flash002Schema = Tt;
45
- exports.Gemini1_5FlashLiteral = Rn;
46
- exports.Gemini1_5FlashOptions = Nn;
47
- exports.Gemini1_5FlashSchema = Mt;
42
+ exports.Gemini1_5Flash002Literal = Fn;
43
+ exports.Gemini1_5Flash002Options = $n;
44
+ exports.Gemini1_5Flash002Schema = Mt;
45
+ exports.Gemini1_5FlashLiteral = qn;
46
+ exports.Gemini1_5FlashOptions = Un;
47
+ exports.Gemini1_5FlashSchema = xt;
48
48
  exports.Gemini1_5Pro = He;
49
49
  exports.Gemini1_5Pro001 = Ve;
50
- exports.Gemini1_5Pro001Literal = Ln;
51
- exports.Gemini1_5Pro001Options = Fn;
52
- exports.Gemini1_5Pro001Schema = xt;
50
+ exports.Gemini1_5Pro001Literal = Bn;
51
+ exports.Gemini1_5Pro001Options = An;
52
+ exports.Gemini1_5Pro001Schema = Ct;
53
53
  exports.Gemini1_5Pro002 = ze;
54
- exports.Gemini1_5Pro002Literal = $n;
55
- exports.Gemini1_5Pro002Options = qn;
56
- exports.Gemini1_5Pro002Schema = Ct;
57
- exports.Gemini1_5ProLiteral = Un;
58
- exports.Gemini1_5ProOptions = Bn;
59
- exports.Gemini1_5ProSchema = vt;
54
+ exports.Gemini1_5Pro002Literal = Dn;
55
+ exports.Gemini1_5Pro002Options = Vn;
56
+ exports.Gemini1_5Pro002Schema = vt;
57
+ exports.Gemini1_5ProLiteral = zn;
58
+ exports.Gemini1_5ProOptions = Hn;
59
+ exports.Gemini1_5ProSchema = Ot;
60
60
  exports.Gemini2_0FlashExp = Ke;
61
- exports.Gemini2_0FlashExpLiteral = An;
62
- exports.Gemini2_0FlashExpOptions = Dn;
63
- exports.Gemini2_0FlashExpSchema = Ot;
61
+ exports.Gemini2_0FlashExpLiteral = Kn;
62
+ exports.Gemini2_0FlashExpOptions = Yn;
63
+ exports.Gemini2_0FlashExpSchema = St;
64
64
  exports.Text_Embedding_004 = Ye;
65
- exports.Text_Embedding_004Literal = St;
66
- exports.Text_Embedding_004Options = Vn;
65
+ exports.Text_Embedding_004Literal = Pt;
66
+ exports.Text_Embedding_004Options = Jn;
67
67
  exports.Text_Embedding_004Schema = Gt;
68
- exports.Text_Embedding_Gecko_003 = Ze;
68
+ exports.Text_Embedding_Gecko_003 = Xe;
69
69
  exports.Text_Embedding_Gecko_003Literal = jt;
70
- exports.Text_Embedding_Gecko_003Options = Kn;
71
- exports.Text_Embedding_Gecko_003Schema = Rt;
70
+ exports.Text_Embedding_Gecko_003Options = Zn;
71
+ exports.Text_Embedding_Gecko_003Schema = Nt;
72
72
  exports.Text_Embedding_Gecko_Multilingual_001 = We;
73
- exports.Text_Embedding_Gecko_Multilingual_001Literal = kt;
74
- exports.Text_Embedding_Gecko_Multilingual_001Options = Hn;
75
- exports.Text_Embedding_Gecko_Multilingual_001Schema = It;
73
+ exports.Text_Embedding_Gecko_Multilingual_001Literal = It;
74
+ exports.Text_Embedding_Gecko_Multilingual_001Options = Xn;
75
+ exports.Text_Embedding_Gecko_Multilingual_001Schema = Rt;
76
76
  exports.Text_Multilingual_Embedding_002 = Je;
77
- exports.Text_Multilingual_Embedding_002Literal = Pt;
78
- exports.Text_Multilingual_Embedding_002Options = zn;
79
- exports.Text_Multilingual_Embedding_002Schema = wt;
77
+ exports.Text_Multilingual_Embedding_002Literal = wt;
78
+ exports.Text_Multilingual_Embedding_002Options = Wn;
79
+ exports.Text_Multilingual_Embedding_002Schema = kt;
80
80
  exports.Vertex = oe;
81
81
  //# sourceMappingURL=index.js.map
82
82
  //# sourceMappingURL=index.js.map