@adaline/vertex 0.14.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
@@ -3,7 +3,7 @@
3
3
  var zod = require('zod');
4
4
 
5
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().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 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:
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
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
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