@adaline/vertex 0.13.0 → 0.15.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
@@ -79,7 +79,7 @@ declare const Gemini1_0Pro001Schema: {
79
79
  param: string;
80
80
  title: string;
81
81
  description: string;
82
- default: string | null;
82
+ default: string;
83
83
  choices: string[];
84
84
  }>;
85
85
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -153,7 +153,7 @@ declare const Gemini1_0ProVisionSchema: {
153
153
  param: string;
154
154
  title: string;
155
155
  description: string;
156
- default: string | null;
156
+ default: string;
157
157
  choices: string[];
158
158
  }>;
159
159
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -227,7 +227,7 @@ declare const Gemini1_0ProSchema: {
227
227
  param: string;
228
228
  title: string;
229
229
  description: string;
230
- default: string | null;
230
+ default: string;
231
231
  choices: string[];
232
232
  }>;
233
233
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -301,7 +301,7 @@ declare const Gemini1_5Flash001Schema: {
301
301
  param: string;
302
302
  title: string;
303
303
  description: string;
304
- default: string | null;
304
+ default: string;
305
305
  choices: string[];
306
306
  }>;
307
307
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -375,7 +375,7 @@ declare const Gemini1_5Flash002Schema: {
375
375
  param: string;
376
376
  title: string;
377
377
  description: string;
378
- default: string | null;
378
+ default: string;
379
379
  choices: string[];
380
380
  }>;
381
381
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -449,7 +449,7 @@ declare const Gemini1_5FlashSchema: {
449
449
  param: string;
450
450
  title: string;
451
451
  description: string;
452
- default: string | null;
452
+ default: string;
453
453
  choices: string[];
454
454
  }>;
455
455
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -523,7 +523,7 @@ declare const Gemini1_5Pro001Schema: {
523
523
  param: string;
524
524
  title: string;
525
525
  description: string;
526
- default: string | null;
526
+ default: string;
527
527
  choices: string[];
528
528
  }>;
529
529
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -597,7 +597,7 @@ declare const Gemini1_5Pro002Schema: {
597
597
  param: string;
598
598
  title: string;
599
599
  description: string;
600
- default: string | null;
600
+ default: string;
601
601
  choices: string[];
602
602
  }>;
603
603
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -671,7 +671,7 @@ declare const Gemini1_5ProSchema: {
671
671
  param: string;
672
672
  title: string;
673
673
  description: string;
674
- default: string | null;
674
+ default: string;
675
675
  choices: string[];
676
676
  }>;
677
677
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -745,7 +745,7 @@ declare const Gemini2_0FlashExpSchema: {
745
745
  param: string;
746
746
  title: string;
747
747
  description: string;
748
- default: string | null;
748
+ default: string;
749
749
  choices: string[];
750
750
  }>;
751
751
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -873,7 +873,7 @@ declare const Text_Embedding_004Schema: {
873
873
  param: string;
874
874
  title: string;
875
875
  description: string;
876
- default: string | null;
876
+ default: string;
877
877
  choices: string[];
878
878
  }>;
879
879
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -946,7 +946,7 @@ declare const Text_Multilingual_Embedding_002Schema: {
946
946
  param: string;
947
947
  title: string;
948
948
  description: string;
949
- default: string | null;
949
+ default: string;
950
950
  choices: string[];
951
951
  }>;
952
952
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -1019,7 +1019,7 @@ declare const Text_Embedding_Gecko_Multilingual_001Schema: {
1019
1019
  param: string;
1020
1020
  title: string;
1021
1021
  description: string;
1022
- default: string | null;
1022
+ default: string;
1023
1023
  choices: string[];
1024
1024
  }>;
1025
1025
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -1092,7 +1092,7 @@ declare const Text_Embedding_Gecko_003Schema: {
1092
1092
  param: string;
1093
1093
  title: string;
1094
1094
  description: string;
1095
- default: string | null;
1095
+ default: string;
1096
1096
  choices: string[];
1097
1097
  }>;
1098
1098
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
package/dist/index.d.ts CHANGED
@@ -79,7 +79,7 @@ declare const Gemini1_0Pro001Schema: {
79
79
  param: string;
80
80
  title: string;
81
81
  description: string;
82
- default: string | null;
82
+ default: string;
83
83
  choices: string[];
84
84
  }>;
85
85
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -153,7 +153,7 @@ declare const Gemini1_0ProVisionSchema: {
153
153
  param: string;
154
154
  title: string;
155
155
  description: string;
156
- default: string | null;
156
+ default: string;
157
157
  choices: string[];
158
158
  }>;
159
159
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -227,7 +227,7 @@ declare const Gemini1_0ProSchema: {
227
227
  param: string;
228
228
  title: string;
229
229
  description: string;
230
- default: string | null;
230
+ default: string;
231
231
  choices: string[];
232
232
  }>;
233
233
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -301,7 +301,7 @@ declare const Gemini1_5Flash001Schema: {
301
301
  param: string;
302
302
  title: string;
303
303
  description: string;
304
- default: string | null;
304
+ default: string;
305
305
  choices: string[];
306
306
  }>;
307
307
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -375,7 +375,7 @@ declare const Gemini1_5Flash002Schema: {
375
375
  param: string;
376
376
  title: string;
377
377
  description: string;
378
- default: string | null;
378
+ default: string;
379
379
  choices: string[];
380
380
  }>;
381
381
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -449,7 +449,7 @@ declare const Gemini1_5FlashSchema: {
449
449
  param: string;
450
450
  title: string;
451
451
  description: string;
452
- default: string | null;
452
+ default: string;
453
453
  choices: string[];
454
454
  }>;
455
455
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -523,7 +523,7 @@ declare const Gemini1_5Pro001Schema: {
523
523
  param: string;
524
524
  title: string;
525
525
  description: string;
526
- default: string | null;
526
+ default: string;
527
527
  choices: string[];
528
528
  }>;
529
529
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -597,7 +597,7 @@ declare const Gemini1_5Pro002Schema: {
597
597
  param: string;
598
598
  title: string;
599
599
  description: string;
600
- default: string | null;
600
+ default: string;
601
601
  choices: string[];
602
602
  }>;
603
603
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -671,7 +671,7 @@ declare const Gemini1_5ProSchema: {
671
671
  param: string;
672
672
  title: string;
673
673
  description: string;
674
- default: string | null;
674
+ default: string;
675
675
  choices: string[];
676
676
  }>;
677
677
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -745,7 +745,7 @@ declare const Gemini2_0FlashExpSchema: {
745
745
  param: string;
746
746
  title: string;
747
747
  description: string;
748
- default: string | null;
748
+ default: string;
749
749
  choices: string[];
750
750
  }>;
751
751
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -873,7 +873,7 @@ declare const Text_Embedding_004Schema: {
873
873
  param: string;
874
874
  title: string;
875
875
  description: string;
876
- default: string | null;
876
+ default: string;
877
877
  choices: string[];
878
878
  }>;
879
879
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -946,7 +946,7 @@ declare const Text_Multilingual_Embedding_002Schema: {
946
946
  param: string;
947
947
  title: string;
948
948
  description: string;
949
- default: string | null;
949
+ default: string;
950
950
  choices: string[];
951
951
  }>;
952
952
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -1019,7 +1019,7 @@ declare const Text_Embedding_Gecko_Multilingual_001Schema: {
1019
1019
  param: string;
1020
1020
  title: string;
1021
1021
  description: string;
1022
- default: string | null;
1022
+ default: string;
1023
1023
  choices: string[];
1024
1024
  }>;
1025
1025
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
@@ -1092,7 +1092,7 @@ declare const Text_Embedding_Gecko_003Schema: {
1092
1092
  param: string;
1093
1093
  title: string;
1094
1094
  description: string;
1095
- default: string | null;
1095
+ default: string;
1096
1096
  choices: string[];
1097
1097
  }>;
1098
1098
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
package/dist/index.js CHANGED
@@ -2,20 +2,20 @@
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 r=c=>{try{m(o.next(c));}catch(p){s(p);}},l=c=>{try{m(o.throw(c));}catch(p){s(p);}},m=c=>c.done?a(c.value):Promise.resolve(c.value).then(r,l);m((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=r=>s[r]=l=>e[r](l)):(e=e.call(t),a=r=>s[r]=l=>{if(o){if(o=!1,r==="throw")throw l;return l}return o=!0,{done:!1,value:new aa(new Promise(m=>{var c=e[r](l);c instanceof Object||na("Object expected"),m(c);}),1)}}),s[Qe("iterator")]=()=>s,a("next"),"throw"in e?a("throw"):s.throw=r=>{throw r},"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(),r=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(Ea(e,o,a,s)),metadata:r}),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().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))}),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 r=Object.keys(o.def),l=Object.keys((s=(a=o.schema)==null?void 0:a.shape)!=null?s:{});return r.every(m=>l.includes(m))&&l.every(m=>r.includes(m))},{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),r=Object.keys((a=(o=e.schema)==null?void 0:o.shape)!=null?a:{});return s.every(l=>r.includes(l))&&r.every(l=>s.includes(l))},{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 r=c=>{try{m(o.next(c));}catch(p){s(p);}},l=c=>{try{m(o.throw(c));}catch(p){s(p);}},m=c=>c.done?a(c.value):Promise.resolve(c.value).then(r,l);m((o=o.apply(t,e)).next());}),Bo=function(t,e){this[0]=t,this[1]=e;},No=(t,e,o)=>{var a=(l,m,c,p)=>{try{var u=o[l](m),f=(m=u.value)instanceof Bo,h=u.done;Promise.resolve(f?m[0]:m).then(_=>f?a(l==="return"?l:"next",m[1]?{done:_.done,value:_.value}:_,c,p):c({value:_,done:h})).catch(_=>a("throw",_,c,p));}catch(_){p(_);}},s=l=>r[l]=m=>new Promise((c,p)=>a(l,m,c,p)),r={};return o=o.apply(t,e),r[be("asyncIterator")]=()=>r,s("next"),s("throw"),s("return"),r},bi=t=>{var e=t[be("asyncIterator")],o=!1,a,s={};return e==null?(e=t[be("iterator")](),a=r=>s[r]=l=>e[r](l)):(e=e.call(t),a=r=>s[r]=l=>{if(o){if(o=!1,r==="throw")throw l;return l}return o=!0,{done:!1,value:new Bo(new Promise(m=>{var c=e[r](l);c instanceof Object||yi("Object expected"),m(c);}),1)}}),s[be("iterator")]=()=>s,a("next"),"throw"in e?a("throw"):s.throw=r=>{throw r},"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,r)=>zod.z.object({temperature:Ee(t,e).schema,maxTokens:Te(o).schema,stop:Me(a).schema,topP:xe(s).schema,topK:Ao(r).schema,frequencyPenalty:Do.schema,presencePenalty:Vo.schema,seed:zo.schema.transform(l=>l===0?void 0:l),toolChoice:Ce.schema,safetySettings:ve.schema}),Mi=(t,e,o,a,s,r)=>({temperature:Ee(t,e).def,maxTokens:Te(o).def,stop:Me(a).def,topP:xe(s).def,topK:Ao(r).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,r)=>({def:Mi(t,e,o,a,s,r),schema:Ti(t,e,o,a,s,r)})},_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 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:
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,r=o.generation_config||o.generationConfig,l=o.safety_settings||o.safetySettings,m=o.tool_config||o.toolConfig;if(m&&(!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 c={};m&&(m.function_calling_config.mode==="ANY"&&m.function_calling_config.allowed_function_names&&m.function_calling_config.allowed_function_names.length===1?c.toolChoice=m.function_calling_config.allowed_function_names[0]:c.toolChoice=m.function_calling_config.mode.toLowerCase()),c.seed=r==null?void 0:r.seed,c.maxTokens=r==null?void 0:r.maxOutputTokens,c.temperature=r==null?void 0:r.temperature,c.topP=r==null?void 0:r.topP,c.presencePenalty=r==null?void 0:r.presencePenalty,c.frequencyPenalty=r==null?void 0:r.frequencyPenalty,c.stop=r==null?void 0:r.stopSequences,c.safetySettings=l;let p=ce().parse(ge(c)),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 r=s.data;Object.keys(r).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
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let l=Object.keys(r).reduce((p,u)=>{let f=this.modelSchema.config.def[u],h=f.param,_=r[u];return h==="maxOutputTokens"&&f.type==="range"&&_===0?p[h]=f.max:p[h]=_,p},{}),m=l.safetySettings;delete l.safetySettings;let c;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"?c={function_calling_config:{mode:"ANY",allowed_function_names:o.map(f=>f.definition.schema.name)}}:c={function_calling_config:{mode:p.toUpperCase()}};else if(o.map(f=>f.definition.schema.name).includes(p))c={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:l},c?{tool_config:c}:{}),m?{safety_settings:m}:{})}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let e=t.map(r=>{let l=it().safeParse(r);if(!l.success)throw new x({info:"Invalid messages",cause:l.error});return l.data});e.forEach(r=>{r.content.forEach(l=>{if(!this.modelSchema.modalities.includes(l.modality))throw new x({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${l.modality}',
11
- available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),e.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 o={parts:[]},a=[];if(e.forEach(r=>{switch(r.role){case de:r.content.forEach(l=>{if(l.modality===T)o.parts.push({text:l.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 : '${l.modality}'`)})});break;case j:{let l=[];r.content.forEach(m=>{if(m.modality===T)l.push({text:m.value});else if(m.modality===R)l.push({function_call:{name:m.name,args:JSON.parse(m.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 : '${m.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:l});}break;case F:{let l=[];r.content.forEach(m=>{if(m.modality===T)l.push({text:m.value});else if(m.modality===z){if(m.value.type==="base64")l.push({inline_data:{mime_type:m.value.media_type,data:m.value.base64}});else if(m.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: '${m.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 : '${m.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:l});}break;case X:{let l=[];r.content.forEach(m=>{if(m.modality===H)l.push({function_response:{name:m.name,response:JSON.parse(m.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 : '${m.modality}'`)})}),a.push({role:this.modelSchema.roles[r.role],parts:l});}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(", ")}]`)})}}),a[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 s=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<a.length;r++)if(!s(a[r-1].role).includes(a[r].role))throw new x({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${a[r].role}' after message with role : '${a[r-1].role}'`)});if(a[a.length-1].role!==this.modelSchema.roles[F]&&a[a.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:a},o.parts.length>0?{system_instruction:o}:{})}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 r=o?this.transformTools(o):{};return new Promise(l=>{l(G(G(G(G({},this.getDefaultParams()),a),s),r));})})}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,r=o.candidates[0].content;if(r){let m=r.parts.map((c,p)=>{if("text"in c&&c.text!==void 0)return Zt(c.text);if("functionCall"in c&&c.functionCall!==void 0)return Xt(p,`${c.functionCall.name}_${p}`,c.functionCall.name,JSON.stringify(c.functionCall.args))});return a.push({role:j,content:m}),o.usageMetadata&&(s={promptTokens:o.usageMetadata.promptTokenCount,totalTokens:o.usageMetadata.totalTokenCount,completionTokens:o.usageMetadata.candidatesTokenCount||0}),{messages:a,usage:s,logProbs:void 0}}let l=o.candidates[0].safetyRatings;if(l&&l.length>0&&l.forEach(m=>{if(m.blocked)throw new $({info:`Blocked content for category: ${m.category} with probability: ${m.probability}`,cause:new Error(`Blocked content for category: ${m.category} with probability: ${m.probability}`)})}),o.candidates[0].finishReason==="SAFETY")throw new $({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 r=o?this.transformTools(o):{};return new Promise(l=>{l(G(G(G(G({},this.getDefaultParams()),a),s),r));})})}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 r;try{r=JSON.parse(s);}catch(m){if(m instanceof SyntaxError){e=s;continue}else throw m}e="";let l=Lo.safeParse(r);if(l.success){let m={partialMessages:[]},c=l.data;if(c.candidates.length>0){let p=c.candidates[0].content;p&&"parts"in p&&p.parts.length>0&&p.parts.forEach((u,f)=>{if("text"in u&&u.text!==void 0&&m.partialMessages.push(rt(j,u.text)),"functionCall"in u&&u.functionCall!==void 0){let h=u.functionCall;m.partialMessages.push(lt(j,f,`${h.name}_${f}`,h.name,JSON.stringify(h.args)));}});}c.usageMetadata&&c.usageMetadata.totalTokenCount&&c.usageMetadata.promptTokenCount&&c.usageMetadata.candidatesTokenCount&&(m.usage={promptTokens:c.usageMetadata.promptTokenCount,completionTokens:c.usageMetadata.candidatesTokenCount,totalTokens:c.usageMetadata.totalTokenCount}),yield {partialResponse:m,buffer:e};}else throw new $({info:"Invalid response from model",cause:l.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 r=e+t,l=[],m="",c=0;for(;c<r.length;){let p=r.indexOf(`
14
- `,c);if(p===-1){m=r.substring(c);break}else {let u=r.substring(c,p).trim();u&&l.push(u),c=p+1;}}for(let p of l){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:m};})}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(([r,l])=>{l!=null&&s.searchParams.set(r,l);}),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},r=ce().parse(ge(s)),l={modality:S,requests:o.requests.reduce((m,c)=>(m.push(...c.content.parts.map(p=>p.text)),m),[])};return {modelName:a,config:r,embeddingRequests:l}}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,r)=>{let l=this.modelSchema.config.def[r].param,m=a[r];return s[l]=m,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(r=>{r.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:
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}',
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}',
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:
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),r;if(s.baseUrl)r=s.baseUrl;else if(s.location&&s.projectId)r=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:`${r}/models/${s.modelName}:generateContent`,streamChatUrl:`${r}/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 c,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,r={autoTruncate:((c=a.parameters)==null?void 0:c.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)},l=ce().parse(ge(r)),m={modality:S,requests:a.instances.map(h=>h.content)};return {modelName:s,config:l,embeddingRequests:m}}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(l=>{if(!this.modelSchema.config.def[l])throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${l}',
18
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),{parameters:Object.keys(s).reduce((l,m)=>{let p=this.modelSchema.config.def[m].param,u=s[m];return l[p]=u,l},{})}}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((r,l)=>({index:l,embedding:r.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 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);}};
19
19
 
20
20
  exports.BaseChatModelOptions = b;
21
21
  exports.BaseChatModelVertex = y;