@adaline/open-router 0.1.0 → 0.3.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.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as zod from 'zod';
2
2
  import { z } from 'zod';
3
- import { ChatModelV1, ChatModelSchemaType, UrlType, HeadersType, ParamsType, ProviderV1, EmbeddingModelV1, EmbeddingModelSchemaType } from '@adaline/provider';
3
+ import { ChatModelV1, ChatModelSchemaType, UrlType, HeadersType, ParamsType, ProviderV1, EmbeddingModelSchemaType, EmbeddingModelV1 } from '@adaline/provider';
4
4
  import { MessageType, ConfigType, ToolType, ChatResponseType, PartialChatResponseType } from '@adaline/types';
5
5
 
6
6
  declare const OpenRouterChatModelConfigs: {
@@ -12,9 +12,9 @@ declare const OpenRouterChatModelConfigs: {
12
12
  title: string;
13
13
  description: string;
14
14
  max: number;
15
+ default: number;
15
16
  min: number;
16
17
  step: number;
17
- default: number;
18
18
  };
19
19
  readonly maxTokens: {
20
20
  type: "range";
@@ -22,9 +22,9 @@ declare const OpenRouterChatModelConfigs: {
22
22
  title: string;
23
23
  description: string;
24
24
  max: number;
25
+ default: number;
25
26
  min: number;
26
27
  step: number;
27
- default: number;
28
28
  };
29
29
  readonly stop: {
30
30
  type: "multi-string";
@@ -39,9 +39,9 @@ declare const OpenRouterChatModelConfigs: {
39
39
  title: string;
40
40
  description: string;
41
41
  max: number;
42
+ default: number;
42
43
  min: number;
43
44
  step: number;
44
- default: number;
45
45
  };
46
46
  readonly frequencyPenalty: {
47
47
  type: "range";
@@ -49,9 +49,9 @@ declare const OpenRouterChatModelConfigs: {
49
49
  title: string;
50
50
  description: string;
51
51
  max: number;
52
+ default: number;
52
53
  min: number;
53
54
  step: number;
54
- default: number;
55
55
  };
56
56
  readonly presencePenalty: {
57
57
  type: "range";
@@ -59,9 +59,9 @@ declare const OpenRouterChatModelConfigs: {
59
59
  title: string;
60
60
  description: string;
61
61
  max: number;
62
+ default: number;
62
63
  min: number;
63
64
  step: number;
64
- default: number;
65
65
  };
66
66
  readonly seed: {
67
67
  type: "range";
@@ -69,9 +69,9 @@ declare const OpenRouterChatModelConfigs: {
69
69
  title: string;
70
70
  description: string;
71
71
  max: number;
72
+ default: number;
72
73
  min: number;
73
74
  step: number;
74
- default: number;
75
75
  };
76
76
  readonly logProbs: {
77
77
  type: "select-boolean";
@@ -86,9 +86,9 @@ declare const OpenRouterChatModelConfigs: {
86
86
  title: string;
87
87
  description: string;
88
88
  max: number;
89
+ default: number;
89
90
  min: number;
90
91
  step: number;
91
- default: number;
92
92
  };
93
93
  readonly toolChoice: {
94
94
  type: "select-string";
@@ -177,9 +177,9 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
177
177
  title: string;
178
178
  description: string;
179
179
  max: number;
180
+ default: number;
180
181
  min: number;
181
182
  step: number;
182
- default: number;
183
183
  };
184
184
  readonly maxTokens: {
185
185
  type: "range";
@@ -187,9 +187,9 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
187
187
  title: string;
188
188
  description: string;
189
189
  max: number;
190
+ default: number;
190
191
  min: number;
191
192
  step: number;
192
- default: number;
193
193
  };
194
194
  readonly stop: {
195
195
  type: "multi-string";
@@ -204,9 +204,9 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
204
204
  title: string;
205
205
  description: string;
206
206
  max: number;
207
+ default: number;
207
208
  min: number;
208
209
  step: number;
209
- default: number;
210
210
  };
211
211
  readonly frequencyPenalty: {
212
212
  type: "range";
@@ -214,9 +214,9 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
214
214
  title: string;
215
215
  description: string;
216
216
  max: number;
217
+ default: number;
217
218
  min: number;
218
219
  step: number;
219
- default: number;
220
220
  };
221
221
  readonly presencePenalty: {
222
222
  type: "range";
@@ -224,9 +224,9 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
224
224
  title: string;
225
225
  description: string;
226
226
  max: number;
227
+ default: number;
227
228
  min: number;
228
229
  step: number;
229
- default: number;
230
230
  };
231
231
  readonly seed: {
232
232
  type: "range";
@@ -234,9 +234,9 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
234
234
  title: string;
235
235
  description: string;
236
236
  max: number;
237
+ default: number;
237
238
  min: number;
238
239
  step: number;
239
- default: number;
240
240
  };
241
241
  readonly logProbs: {
242
242
  type: "select-boolean";
@@ -251,9 +251,9 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
251
251
  title: string;
252
252
  description: string;
253
253
  max: number;
254
+ default: number;
254
255
  min: number;
255
256
  step: number;
256
- default: number;
257
257
  };
258
258
  readonly toolChoice: {
259
259
  type: "select-string";
@@ -272,9 +272,9 @@ declare const temperature: {
272
272
  title: string;
273
273
  description: string;
274
274
  max: number;
275
+ default: number;
275
276
  min: number;
276
277
  step: number;
277
- default: number;
278
278
  };
279
279
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
280
280
  };
@@ -285,9 +285,9 @@ declare const maxTokens: (maxOutputTokens: number) => {
285
285
  title: string;
286
286
  description: string;
287
287
  max: number;
288
+ default: number;
288
289
  min: number;
289
290
  step: number;
290
- default: number;
291
291
  };
292
292
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
293
293
  };
@@ -308,9 +308,9 @@ declare const topA: {
308
308
  title: string;
309
309
  description: string;
310
310
  max: number;
311
+ default: number;
311
312
  min: number;
312
313
  step: number;
313
- default: number;
314
314
  };
315
315
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
316
316
  };
@@ -321,9 +321,9 @@ declare const topK: {
321
321
  title: string;
322
322
  description: string;
323
323
  max: number;
324
+ default: number;
324
325
  min: number;
325
326
  step: number;
326
- default: number;
327
327
  };
328
328
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
329
329
  };
@@ -334,9 +334,9 @@ declare const topP: {
334
334
  title: string;
335
335
  description: string;
336
336
  max: number;
337
+ default: number;
337
338
  min: number;
338
339
  step: number;
339
- default: number;
340
340
  };
341
341
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
342
342
  };
@@ -347,9 +347,9 @@ declare const minP: {
347
347
  title: string;
348
348
  description: string;
349
349
  max: number;
350
+ default: number;
350
351
  min: number;
351
352
  step: number;
352
- default: number;
353
353
  };
354
354
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
355
355
  };
@@ -360,9 +360,9 @@ declare const frequencyPenalty: {
360
360
  title: string;
361
361
  description: string;
362
362
  max: number;
363
+ default: number;
363
364
  min: number;
364
365
  step: number;
365
- default: number;
366
366
  };
367
367
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
368
368
  };
@@ -373,9 +373,9 @@ declare const presencePenalty: {
373
373
  title: string;
374
374
  description: string;
375
375
  max: number;
376
+ default: number;
376
377
  min: number;
377
378
  step: number;
378
- default: number;
379
379
  };
380
380
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
381
381
  };
@@ -386,9 +386,9 @@ declare const repetitionPenalty: {
386
386
  title: string;
387
387
  description: string;
388
388
  max: number;
389
+ default: number;
389
390
  min: number;
390
391
  step: number;
391
- default: number;
392
392
  };
393
393
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
394
394
  };
@@ -399,9 +399,9 @@ declare const seed: {
399
399
  title: string;
400
400
  description: string;
401
401
  max: number;
402
+ default: number;
402
403
  min: number;
403
404
  step: number;
404
- default: number;
405
405
  };
406
406
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
407
407
  };
@@ -422,9 +422,9 @@ declare const topLogProbs: {
422
422
  title: string;
423
423
  description: string;
424
424
  max: number;
425
+ default: number;
425
426
  min: number;
426
427
  step: number;
427
- default: number;
428
428
  };
429
429
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNumber>>;
430
430
  };
@@ -887,18 +887,18 @@ declare const OpenRouterChatRequest: z.ZodObject<{
887
887
  type OpenRouterChatRequestType = z.infer<typeof OpenRouterChatRequest>;
888
888
 
889
889
  declare const BaseChatModelOptions: z.ZodObject<{
890
- apiKey: z.ZodString;
891
890
  modelName: z.ZodString;
891
+ apiKey: z.ZodString;
892
892
  openRouterReferer: z.ZodOptional<z.ZodString>;
893
893
  openRouterTitle: z.ZodOptional<z.ZodString>;
894
894
  }, "strip", z.ZodTypeAny, {
895
- apiKey: string;
896
895
  modelName: string;
896
+ apiKey: string;
897
897
  openRouterReferer?: string | undefined;
898
898
  openRouterTitle?: string | undefined;
899
899
  }, {
900
- apiKey: string;
901
900
  modelName: string;
901
+ apiKey: string;
902
902
  openRouterReferer?: string | undefined;
903
903
  openRouterTitle?: string | undefined;
904
904
  }>;
@@ -959,33 +959,33 @@ declare const BaseChatModelSchema: {
959
959
  description: string;
960
960
  max: number;
961
961
  } | {
962
- type: "range";
962
+ type: "object-schema";
963
963
  param: string;
964
964
  title: string;
965
965
  description: string;
966
- max: number;
967
- min: number;
968
- step: number;
969
- default: number;
966
+ objectSchema?: any;
970
967
  } | {
971
- type: "select-string";
968
+ type: "range";
972
969
  param: string;
973
970
  title: string;
974
971
  description: string;
975
- default: string | null;
976
- choices: string[];
972
+ max: number;
973
+ default: number;
974
+ min: number;
975
+ step: number;
977
976
  } | {
978
- type: "object-schema";
977
+ type: "select-boolean";
979
978
  param: string;
980
979
  title: string;
981
980
  description: string;
982
- objectSchema?: any;
981
+ default: boolean | null;
983
982
  } | {
984
- type: "select-boolean";
983
+ type: "select-string";
985
984
  param: string;
986
985
  title: string;
987
986
  description: string;
988
- default: boolean | null;
987
+ default: string | null;
988
+ choices: string[];
989
989
  }>;
990
990
  schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, unknown, unknown>;
991
991
  };
@@ -995,14 +995,13 @@ declare class OpenRouter<O extends Record<string, any> = Record<string, any>> im
995
995
  readonly version: "v1";
996
996
  readonly name = "open-router";
997
997
  static readonly baseUrl = "https://openrouter.ai/api/v1";
998
+ private readonly embeddingModelFactories;
998
999
  chatModelLiterals(): string[];
999
- chatModel(name: string, options: O): ChatModelV1;
1000
- chatModelSchema(name: string): ChatModelSchemaType;
1001
1000
  chatModelSchemas(): Record<string, ChatModelSchemaType>;
1001
+ chatModel(options: O): ChatModelV1;
1002
1002
  embeddingModelLiterals(): string[];
1003
- embeddingModel(name: string, options: O): EmbeddingModelV1;
1004
- embeddingModelSchema(name: string): EmbeddingModelSchemaType;
1005
1003
  embeddingModelSchemas(): Record<string, EmbeddingModelSchemaType>;
1004
+ embeddingModel(options: O): EmbeddingModelV1;
1006
1005
  }
1007
1006
 
1008
1007
  export { BaseChatModel, type BaseChatModelOptionsType, BaseChatModelSchema, ChatModelBaseConfigDef, ChatModelBaseConfigSchema, OpenRouter, OpenRouterChatModelConfigs, frequencyPenalty, logProbs, maxTokens, minP, presencePenalty, repetitionPenalty, responseFormat, seed, stop, temperature, toolChoice, topA, topK, topLogProbs, topP };
package/dist/index.js CHANGED
@@ -2,34 +2,34 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
- var bt=Object.defineProperty;var Ce=Object.getOwnPropertySymbols;var Ct=Object.prototype.hasOwnProperty,Tt=Object.prototype.propertyIsEnumerable;var Rt=(o,t)=>(t=Symbol[o])?t:Symbol.for("Symbol."+o);var Te=(o,t,n)=>t in o?bt(o,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[t]=n,R=(o,t)=>{for(var n in t||(t={}))Ct.call(t,n)&&Te(o,n,t[n]);if(Ce)for(var n of Ce(t))Tt.call(t,n)&&Te(o,n,t[n]);return o};var P=(o,t,n)=>new Promise((a,r)=>{var s=c=>{try{p(n.next(c));}catch(h){r(h);}},d=c=>{try{p(n.throw(c));}catch(h){r(h);}},p=c=>c.done?a(c.value):Promise.resolve(c.value).then(s,d);p((n=n.apply(o,t)).next());}),vt=function(o,t){this[0]=o,this[1]=t;},Re=(o,t,n)=>{var a=(d,p,c,h)=>{try{var u=n[d](p),y=(p=u.value)instanceof vt,g=u.done;Promise.resolve(y?p[0]:p).then(b=>y?a(d==="return"?d:"next",p[1]?{done:b.done,value:b.value}:b,c,h):c({value:b,done:g})).catch(b=>a("throw",b,c,h));}catch(b){h(b);}},r=d=>s[d]=p=>new Promise((c,h)=>a(d,p,c,h)),s={};return n=n.apply(o,t),s[Rt("asyncIterator")]=()=>s,r("next"),r("throw"),r("return"),s};var Ot=o=>{let t=new WeakSet;return JSON.stringify(o,(n,a)=>{if(typeof a=="object"&&a!==null){if(t.has(a))return;t.add(a);}return a})},Mt=o=>o==null?"unknown error":typeof o=="string"?o:o instanceof Error?o.message:Ot(o),H="GatewayBaseError",w=class Ee extends Error{constructor({info:t,cause:n},a){super(`[${a!=null?a:H}]: ${t}
6
- Message: ${Mt(n)}`),this.name=H,this.info=t,this.cause=n,this.name=a!=null?a:H,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof Ee}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},I="system",k="user",v="assistant",q="tool",Et=[I,k,v,q],G=zod.z.enum(Et),xt=[v],_t=zod.z.enum(xt),x="image",Y="base64",Pt=["png","jpeg","webp","gif"],wt=zod.z.object({type:zod.z.literal(Y),base64:zod.z.string(),media_type:zod.z.enum(Pt)}),V="url",St=zod.z.object({type:zod.z.literal(V),url:zod.z.string()}),jt=zod.z.discriminatedUnion("type",[wt,St]),It=["low","medium","high","auto"],kt=zod.z.enum(It),qt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(x),detail:kt,value:jt,metadata:o}),T="text",xe=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(T),value:zod.z.string(),metadata:o}),J="partial-text",_e=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(J),value:zod.z.string(),metadata:o}),E="tool-call",Pe=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(E),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:o}),W="partial-tool-call",we=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(W),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:o}),_="tool-response",Lt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:o}),Nt=[T,x,E,_],Se=zod.z.enum(Nt),Ut=(o=zod.z.undefined(),t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[xe(o),qt(t),Pe(n),Lt(a)]),$t=[J,W];zod.z.enum($t);var Bt=(o=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[_e(o),we(t)]);var L=(o=G,t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),r=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:o,content:zod.z.array(Ut(t,n,a,r)),metadata:s}),Z=(o=_t,t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined())=>zod.z.object({role:o,partialContent:Bt(t,n),metadata:a});var Q=(o,t)=>L().parse({role:o,content:[xe().parse({modality:T,value:t})]});var je=(o,t,n,a,r)=>L().parse({role:o,content:[Pe().parse({modality:E,index:t,id:n,name:a,arguments:r})]});var X=(o,t)=>Z().parse({role:o,partialContent:_e().parse({modality:J,value:t})}),Ie=(o,t,n,a,r)=>Z().parse({role:o,partialContent:we().parse({modality:W,index:t,id:n,name:a,arguments:r})});var ke=(o=zod.z.record(zod.z.string(),zod.z.any()).optional())=>o,At=["object","array","number","string","boolean","enum"],ve=zod.z.enum(At),Ft=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([ve,zod.z.array(zod.z.union([ve,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()}),zt=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(Ft),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:zt}).optional();var Dt="function";var Kt=zod.z.enum(["object","array","number","string","boolean","null"]),Ht=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Kt.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(Ht).optional(),required:zod.z.array(zod.z.string()).optional()});var Gt=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 Yt=zod.z.enum(["function"]),Vt=zod.z.object({type:Yt,definition:zod.z.object({schema:Gt})}),Jt=[Dt];zod.z.enum(Jt);var qe=(o=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Vt.extend({metadata:o})]),Wt="text",Zt="token",Qt=[Wt,Zt];zod.z.enum(Qt);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var eo="float",to=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),oo="base64",no=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Oe=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(eo),embeddings:zod.z.array(to),usage:Oe.optional()}),zod.z.object({encodingFormat:zod.z.literal(oo),embeddings:zod.z.array(no),usage:Oe.optional()})]);var Le=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Me=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),ao=Me.extend({topLogProbs:zod.z.array(Me)}),Ne=zod.z.array(ao);zod.z.object({messages:zod.z.array(L()),usage:Le.optional(),logProbs:Ne.optional()});zod.z.object({partialMessages:zod.z.array(Z()),usage:Le.optional(),logProbs:Ne.optional()});var so=Object.defineProperty,Ue=Object.getOwnPropertySymbols,ro=Object.prototype.hasOwnProperty,io=Object.prototype.propertyIsEnumerable,$e=(o,t,n)=>t in o?so(o,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[t]=n,B=(o,t)=>{for(var n in t||(t={}))ro.call(t,n)&&$e(o,n,t[n]);if(Ue)for(var n of Ue(t))io.call(t,n)&&$e(o,n,t[n]);return o},Be="ProviderError",S=class He extends w{constructor({info:t,cause:n}){super({info:t,cause:n},Be),this.name=Be,this.info=t,this.cause=n;}static isProviderError(t){return t instanceof He}};var Ae="ModelResponseError",N=class Ge extends w{constructor({info:t,cause:n}){super({info:t,cause:n},Ae),this.name=Ae,this.cause=n,this.info=t;}static isModelResponseError(t){return t instanceof Ge}},Fe="InvalidModelRequestError",A=class Ye extends w{constructor({info:t,cause:n}){super({info:t,cause:n},Fe),this.name=Fe,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Ye}},ze="InvalidConfigError",j=class Ve extends w{constructor({info:t,cause:n}){super({info:t,cause:n},ze),this.name=ze,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Ve}},De="InvalidMessagesError",O=class Je extends w{constructor({info:t,cause:n}){super({info:t,cause:n},De),this.name=De,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof Je}},Ke="InvalidToolsError",ee=class We extends w{constructor({info:t,cause:n}){super({info:t,cause:n},Ke),this.name=Ke,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof We}};var te="multi-string",Ze=zod.z.object({type:zod.z.literal(te),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()}),lo=o=>zod.z.array(zod.z.string()).max(o).default([]).optional(),Qe=o=>({def:Ze.parse(B({type:te},o)),schema:lo(o.max)}),oe="range",Xe=zod.z.object({type:zod.z.literal(oe),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()}),po=(o,t,n,a)=>zod.z.number().min(o).max(t).step(n).default(a).optional(),M=o=>({def:Xe.parse(B({type:oe},o)),schema:po(o.min,o.max,o.step,o.default)}),ne="select-string",et=zod.z.object({type:zod.z.literal(ne),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))}),mo=(o,t)=>zod.z.enum(t).nullable().default(o).optional(),ae=o=>({def:et.parse(B({type:ne},o)),schema:mo(o.default,o.choices)}),tt="object-schema",co=zod.z.object({type:zod.z.literal(tt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var se="select-boolean",ot=zod.z.object({type:zod.z.literal(se),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()}),uo=o=>zod.z.boolean().nullable().default(o).optional(),nt=o=>({def:ot.parse(B({type:se},o)),schema:uo(o.default)}),ho=[oe,te,ne,tt,se];zod.z.enum(ho);var fo=zod.z.discriminatedUnion("type",[Xe,Ze,et,ot,co]),at=(o=G,t=Se)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(o,zod.z.string().min(1).optional()),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),fo),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(n=>{var a,r;let s=Object.keys(n.def),d=Object.keys((r=(a=n.schema)==null?void 0:a.shape)!=null?r:{});return s.every(p=>d.includes(p))&&d.every(p=>s.includes(p))},{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 go={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."},yo={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."},bo=o=>({type:"multi",title:"Stop sequence",description:`Enter up to ${o} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Co={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."},To={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."},Ro={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."},vo={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."},Oo={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."},Mo={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."},Eo={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."},xo={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."},_o={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."},Po={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."},wo={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},So={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."},jo={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."},Io={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."},f={TEMPERATURE:go,MAX_TOKENS:yo,STOP:bo,TOP_A:Co,TOP_P:To,TOP_K:Ro,MIN_P:vo,FREQUENCY_PENALTY:Oo,PRESENCE_PENALTY:Mo,REPETITION_PENALTY:xo,SEED:Eo,LOG_PROBS:_o,TOP_LOG_PROBS:Po,ECHO:wo,RESPONSE_FORMAT:So,RESPONSE_FORMAT_WITH_SCHEMA:jo,RESPONSE_SCHEMA:Io};var st=o=>Object.fromEntries(Object.entries(o).filter(([t,n])=>n!=null));var rt=o=>o.split(";")[0].split("/")[1],F=o=>o==null?void 0:o.replace(/\/$/,"");var re=M({param:"temperature",title:f.TEMPERATURE.title,description:f.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),ie=o=>M({param:"max_tokens",title:f.MAX_TOKENS.title,description:f.MAX_TOKENS.description,min:0,max:o,step:1,default:0}),le=o=>Qe({param:"stop",title:f.STOP(o).title,description:f.STOP(o).description,max:o}),bn=M({param:"top_a",title:f.TOP_A.title,description:f.TOP_A.description,min:0,max:1,step:.01,default:0}),Cn=M({param:"top_k",title:f.TOP_K.title,description:f.TOP_K.description,min:0,max:100,step:1,default:0}),pe=M({param:"top_p",title:f.TOP_P.title,description:f.TOP_P.description,min:0,max:1,step:.01,default:1}),Tn=M({param:"min_p",title:f.MIN_P.title,description:f.MIN_P.description,min:0,max:1,step:.01,default:0}),me=M({param:"frequency_penalty",title:f.FREQUENCY_PENALTY.title,description:f.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),ce=M({param:"presence_penalty",title:f.PRESENCE_PENALTY.title,description:f.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),Rn=M({param:"repetition_penalty",title:f.REPETITION_PENALTY.title,description:f.REPETITION_PENALTY.description,min:0,max:2,step:.01,default:0}),de=M({param:"seed",title:f.SEED.title,description:f.SEED.description,min:0,max:1e6,step:1,default:0}),ue=nt({param:"logprobs",title:f.LOG_PROBS.title,description:f.LOG_PROBS.description,default:!1}),he=M({param:"top_logprobs",title:f.TOP_LOG_PROBS.title,description:f.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),fe=ae({param:"tool_choice",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","required","none"]}),vn=ae({param:"response_format",title:f.RESPONSE_FORMAT.title,description:f.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]});var it=(o,t)=>zod.z.object({temperature:re.schema,maxTokens:ie(o).schema,stop:le(t).schema,topP:pe.schema,frequencyPenalty:me.schema,presencePenalty:ce.schema,seed:de.schema.transform(n=>n===0?void 0:n),logProbs:ue.schema,topLogProbs:he.schema,toolChoice:fe.schema}),lt=(o,t)=>({temperature:re.def,maxTokens:ie(o).def,stop:le(t).def,topP:pe.def,frequencyPenalty:me.def,presencePenalty:ce.def,seed:de.def,logProbs:ue.def,topLogProbs:he.def,toolChoice:fe.def});var ge={base:(o,t)=>({def:lt(o,t),schema:it(o,t)})};var qo="open-router",U=class{constructor(){this.version="v1";this.name=qo;}chatModelLiterals(){throw new S({info:"Not implemented",cause:new Error("Not implemented")})}chatModel(t,n){let a=R({modelName:t},n);return new z(ye,a)}chatModelSchema(t){return ye}chatModelSchemas(){throw new S({info:"Not implemented",cause:new Error("Not implemented")})}embeddingModelLiterals(){throw new S({info:"Open Router does not support embedding models",cause:new Error("Open Router does not support embedding models")})}embeddingModel(t,n){throw new S({info:"Open Router does not support embedding models",cause:new Error("Open Router does not support embedding models")})}embeddingModelSchema(t){throw new S({info:"Open Router does not support embedding models",cause:new Error("Open Router does not support embedding models")})}embeddingModelSchemas(){throw new S({info:"Open Router does not support embedding models",cause:new Error("Open Router does not support embedding models")})}};U.baseUrl="https://openrouter.ai/api/v1";var pt=zod.z.enum([I,k,v,q]),mt={system:I,user:k,assistant:v,tool:q};var ct=[T,x,E,_],dt=zod.z.enum([T,x,E,_]);var D=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),ut=zod.z.object({content:zod.z.array(D.extend({top_logprobs:zod.z.array(D)})).nullable(),refusal:zod.z.array(D.extend({top_logprobs:zod.z.array(D)})).nullable()}).nullable(),Uo=zod.z.array(zod.z.object({id:zod.z.string().min(1),type:zod.z.enum(["function"]),function:zod.z.object({name:zod.z.string(),arguments:zod.z.string()})})),ht=zod.z.object({id:zod.z.string(),object:zod.z.literal("chat.completion"),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable().optional(),choices:zod.z.array(zod.z.object({index:zod.z.number(),message:zod.z.object({role:zod.z.string(),content:zod.z.string().nullable().optional(),tool_calls:Uo.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:ut.optional(),finish_reason:zod.z.string()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()}),$o=zod.z.array(zod.z.object({index:zod.z.number().int(),id:zod.z.string().min(1).optional(),type:zod.z.enum(["function"]).optional(),function:zod.z.object({name:zod.z.string().min(1).optional(),arguments:zod.z.string().optional()}).optional()})),ft=zod.z.object({id:zod.z.string(),object:zod.z.string(),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable().optional(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({content:zod.z.string().nullable().optional(),tool_calls:$o.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:ut,finish_reason:zod.z.string().nullable()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()});var Bo=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),parameters:zod.z.any()})}),Ao=zod.z.enum(["none","auto","required"]),Fo=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),zo=zod.z.object({type:zod.z.enum(["text","json_object"])}).or(zod.z.object({type:zod.z.literal("json_schema"),json_schema:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),schema:zod.z.any()})})),be=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),Do=zod.z.object({type:zod.z.literal("image_url"),image_url:zod.z.object({url:zod.z.string().url().min(1),detail:zod.z.enum(["low","high","auto"]).optional()})}),Ko=zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),arguments:zod.z.string().min(1)})}),Ho=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(be).min(1))}),Go=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([be,Do])).min(1))}),Yo=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(be).min(1)).optional(),tool_calls:zod.z.array(Ko).min(1).optional()}),Vo=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),Jo=zod.z.union([Ho,Go,Yo,Vo]),gt=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Jo).min(1),frequency_penalty:zod.z.number().min(-2).max(2).nullable().optional(),logprobs:zod.z.boolean().nullable().optional(),top_logprobs:zod.z.number().min(0).max(20).nullable().optional(),max_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),repetition_penalty:zod.z.number().min(0).max(2).nullable().optional(),response_format:zo.optional(),seed:zod.z.number().nullable().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),top_a:zod.z.number().min(0).max(1).nullable().optional(),temperature:zod.z.number().min(0).max(2).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),top_k:zod.z.number().min(0).max(100).nullable().optional(),min_p:zod.z.number().min(0).max(1).nullable().optional(),tools:zod.z.array(Bo).optional(),tool_choice:Ao.or(Fo).optional()});var Wo=zod.z.object({apiKey:zod.z.string(),modelName:zod.z.string(),openRouterReferer:zod.z.string().optional(),openRouterTitle:zod.z.string().optional()}),z=class{constructor(t,n){this.version="v1";let a=Wo.parse(n);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=F(U.baseUrl),this.streamChatUrl=F(`${this.baseUrl}/chat/completions`),this.completeChatUrl=F(`${this.baseUrl}/chat/completions`),this.openRouterReferer=a.openRouterReferer,this.openRouterTitle=a.openRouterTitle;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return R(R({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"},this.openRouterReferer?{"HTTP-Referer":this.openRouterReferer}:{}),this.openRouterTitle?{"X-Title":this.openRouterTitle}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}getTokenCount(t){return t.reduce((n,a)=>n+a.content.map(r=>r.modality==="text"?r.value:"").join(" ").length,0)}transformModelRequest(t){let n=gt.safeParse(t);if(!n.success)throw new A({info:"Invalid model request",cause:n.error});let a=n.data,r=a.model;if(a.tool_choice&&(!a.tools||a.tools.length===0))throw new A({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let s={};a.response_format&&(s.responseFormat=a.response_format.type,a.response_format.type==="json_schema"&&(s.responseSchema={name:a.response_format.json_schema.name,description:a.response_format.json_schema.description||"",strict:a.response_format.json_schema.strict,schema:a.response_format.json_schema.schema})),a.tool_choice&&(typeof a.tool_choice=="string"?s.toolChoice=a.tool_choice:s.toolChoice=a.tool_choice.function.name),s.seed=a.seed,s.maxTokens=a.max_tokens,s.temperature=a.temperature,s.topA=a.top_a,s.topP=a.top_p,s.minP=a.min_p,s.topK=a.top_k,s.repetitionPenalty=a.repetition_penalty,s.presencePenalty=a.presence_penalty,s.frequencyPenalty=a.frequency_penalty,s.stop=a.stop,s.logProbs=a.logprobs,s.topLogProbs=a.top_logprobs;let d=ke().parse(st(s)),p=[],c={};a.messages.forEach(u=>{let y=u.role;switch(y){case"system":{let g=u.content;if(typeof g=="string")p.push({role:y,content:[{modality:T,value:g}]});else {let b=g.map(C=>({modality:T,value:C.text}));p.push({role:y,content:b});}}break;case"user":{let g=u.content;if(typeof g=="string")p.push({role:y,content:[{modality:T,value:g}]});else {let b=g.map(C=>C.type==="text"?{modality:T,value:C.text}:C.image_url.url.startsWith("data:")?{modality:x,detail:C.image_url.detail||"auto",value:{type:Y,base64:C.image_url.url,media_type:rt(C.image_url.url)}}:{modality:x,detail:C.image_url.detail||"auto",value:{type:V,url:C.image_url.url}});p.push({role:y,content:b});}}break;case"assistant":{let g=[];if(!u.content&&!u.tool_calls)throw new A({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(u.content){let b=u.content;typeof b=="string"?g.push({modality:T,value:b}):b.forEach(C=>{g.push({modality:T,value:C.text});});}u.tool_calls&&u.tool_calls.forEach((C,yt)=>{let K={modality:E,id:C.id,index:yt,name:C.function.name,arguments:C.function.arguments};g.push(K),c[K.id]=K;}),p.push({role:y,content:g});}break;case"tool":{let g=u;p.push({role:y,content:[{modality:_,id:g.tool_call_id,index:c[g.tool_call_id].index,name:c[g.tool_call_id].name,data:g.content}]});}break}});let h=[];return a.tools&&a.tools.forEach(u=>{h.push({type:"function",definition:{schema:{name:u.function.name,description:u.function.description||"",strict:u.function.strict,parameters:u.function.parameters}}});}),{modelName:r,config:d,messages:p,tools:h.length>0?h:void 0}}transformConfig(t,n,a){let r=t.toolChoice;delete t.toolChoice;let s=this.modelSchema.config.schema.safeParse(t);if(!s.success)throw new j({info:`Invalid config for model : '${this.modelName}'`,cause:s.error});let d=s.data;r!==void 0&&(d.toolChoice=r),Object.keys(d).forEach(c=>{if(!(c in this.modelSchema.config.def))throw new j({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${c}',
7
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let p=Object.keys(d).reduce((c,h)=>{let u=this.modelSchema.config.def[h],y=u.param,g=d[h];return y==="max_tokens"&&u.type==="range"&&g===0?c[y]=u.max:c[y]=g,c},{});if(p.top_logprobs&&!p.logprobs)throw new j({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in p&&p.tool_choice!==void 0){let c=p.tool_choice;if(!a||a&&a.length===0)throw new j({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(a&&a.length>0){let h=this.modelSchema.config.def.toolChoice;if(!h.choices.includes(c))if(a.map(u=>u.definition.schema.name).includes(c))p.tool_choice={type:"function",function:{name:c}};else throw new j({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${c}' is not part of provided 'tools' names or
8
- one of [${h.choices.join(", ")}]`)})}}if("response_format"in p&&p.response_format!==void 0){let c=p.response_format;if(c==="json_schema")if("response_schema"in p)p.response_format={type:"json_schema",json_schema:p.response_schema},delete p.response_schema;else throw new j({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else p.response_format={type:c};}return p}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let n=t.map(r=>{let s=L().safeParse(r);if(!s.success)throw new O({info:"Invalid messages",cause:s.error});return s.data});return n.forEach(r=>{r.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new O({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${s.modality}',
5
+ var Tt=Object.defineProperty,Ct=Object.defineProperties;var Rt=Object.getOwnPropertyDescriptors;var Te=Object.getOwnPropertySymbols;var vt=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable;var Mt=(o,t)=>(t=Symbol[o])?t:Symbol.for("Symbol."+o);var Ce=(o,t,n)=>t in o?Tt(o,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[t]=n,R=(o,t)=>{for(var n in t||(t={}))vt.call(t,n)&&Ce(o,n,t[n]);if(Te)for(var n of Te(t))Ot.call(t,n)&&Ce(o,n,t[n]);return o},Re=(o,t)=>Ct(o,Rt(t));var P=(o,t,n)=>new Promise((a,r)=>{var s=c=>{try{p(n.next(c));}catch(h){r(h);}},d=c=>{try{p(n.throw(c));}catch(h){r(h);}},p=c=>c.done?a(c.value):Promise.resolve(c.value).then(s,d);p((n=n.apply(o,t)).next());}),Et=function(o,t){this[0]=o,this[1]=t;},ve=(o,t,n)=>{var a=(d,p,c,h)=>{try{var u=n[d](p),y=(p=u.value)instanceof Et,g=u.done;Promise.resolve(y?p[0]:p).then(b=>y?a(d==="return"?d:"next",p[1]?{done:b.done,value:b.value}:b,c,h):c({value:b,done:g})).catch(b=>a("throw",b,c,h));}catch(b){h(b);}},r=d=>s[d]=p=>new Promise((c,h)=>a(d,p,c,h)),s={};return n=n.apply(o,t),s[Mt("asyncIterator")]=()=>s,r("next"),r("throw"),r("return"),s};var xt=o=>{let t=new WeakSet;return JSON.stringify(o,(n,a)=>{if(typeof a=="object"&&a!==null){if(t.has(a))return;t.add(a);}return a})},_t=o=>o==null?"unknown error":typeof o=="string"?o:o instanceof Error?o.message:xt(o),K="GatewayBaseError",S=class xe extends Error{constructor({info:t,cause:n},a){super(`[${a!=null?a:K}]: ${t}
6
+ Message: ${_t(n)}`),this.name=K,this.info=t,this.cause=n,this.name=a!=null?a:K,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof xe}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},j="system",I="user",v="assistant",k="tool",Pt=[j,I,v,k],H=zod.z.enum(Pt),St=[v],wt=zod.z.enum(St),x="image",G="base64",jt=["png","jpeg","webp","gif"],It=zod.z.object({type:zod.z.literal(G),base64:zod.z.string(),media_type:zod.z.enum(jt)}),V="url",kt=zod.z.object({type:zod.z.literal(V),url:zod.z.string()}),qt=zod.z.discriminatedUnion("type",[It,kt]),Lt=["low","medium","high","auto"],Nt=zod.z.enum(Lt),Ut=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(x),detail:Nt,value:qt,metadata:o}),C="text",_e=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(C),value:zod.z.string(),metadata:o}),Y="partial-text",Pe=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Y),value:zod.z.string(),metadata:o}),E="tool-call",Se=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(E),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:o}),J="partial-tool-call",we=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(J),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:o}),_="tool-response",$t=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:o}),Bt=[C,x,E,_],je=zod.z.enum(Bt),At=(o=zod.z.undefined(),t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[_e(o),Ut(t),Se(n),$t(a)]),Ft=[Y,J];zod.z.enum(Ft);var zt=(o=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Pe(o),we(t)]);var q=(o=H,t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),r=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:o,content:zod.z.array(At(t,n,a,r)),metadata:s}),W=(o=wt,t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined())=>zod.z.object({role:o,partialContent:zt(t,n),metadata:a});var Z=(o,t)=>q().parse({role:o,content:[_e().parse({modality:C,value:t})]});var Ie=(o,t,n,a,r)=>q().parse({role:o,content:[Se().parse({modality:E,index:t,id:n,name:a,arguments:r})]});var Q=(o,t)=>W().parse({role:o,partialContent:Pe().parse({modality:Y,value:t})}),ke=(o,t,n,a,r)=>W().parse({role:o,partialContent:we().parse({modality:J,index:t,id:n,name:a,arguments:r})});var qe=(o=zod.z.record(zod.z.string(),zod.z.any()).optional())=>o,Dt=["object","array","number","string","boolean","enum"],Oe=zod.z.enum(Dt),Kt=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Oe,zod.z.array(zod.z.union([Oe,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()}),Ht=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(Kt),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:Ht}).optional();var Gt="function";var Vt=zod.z.enum(["object","array","number","string","boolean","null"]),Yt=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Vt.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(Yt).optional(),required:zod.z.array(zod.z.string()).optional()});var Jt=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 Wt=zod.z.enum(["function"]),Zt=zod.z.object({type:Wt,definition:zod.z.object({schema:Jt})}),Qt=[Gt];zod.z.enum(Qt);var Le=(o=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Zt.extend({metadata:o})]),Xt="text",eo="token",to=[Xt,eo];zod.z.enum(to);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var no="float",ao=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),so="base64",ro=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Me=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(no),embeddings:zod.z.array(ao),usage:Me.optional()}),zod.z.object({encodingFormat:zod.z.literal(so),embeddings:zod.z.array(ro),usage:Me.optional()})]);var Ne=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Ee=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),io=Ee.extend({topLogProbs:zod.z.array(Ee)}),Ue=zod.z.array(io);zod.z.object({messages:zod.z.array(q()),usage:Ne.optional(),logProbs:Ue.optional()});zod.z.object({partialMessages:zod.z.array(W()),usage:Ne.optional(),logProbs:Ue.optional()});var lo=Object.defineProperty,$e=Object.getOwnPropertySymbols,po=Object.prototype.hasOwnProperty,mo=Object.prototype.propertyIsEnumerable,Be=(o,t,n)=>t in o?lo(o,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[t]=n,$=(o,t)=>{for(var n in t||(t={}))po.call(t,n)&&Be(o,n,t[n]);if($e)for(var n of $e(t))mo.call(t,n)&&Be(o,n,t[n]);return o},Ae="ProviderError",X=class Ge extends S{constructor({info:t,cause:n}){super({info:t,cause:n},Ae),this.name=Ae,this.info=t,this.cause=n;}static isProviderError(t){return t instanceof Ge}};var Fe="ModelResponseError",L=class Ve extends S{constructor({info:t,cause:n}){super({info:t,cause:n},Fe),this.name=Fe,this.cause=n,this.info=t;}static isModelResponseError(t){return t instanceof Ve}},ze="InvalidModelRequestError",B=class Ye extends S{constructor({info:t,cause:n}){super({info:t,cause:n},ze),this.name=ze,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Ye}},De="InvalidConfigError",w=class Je extends S{constructor({info:t,cause:n}){super({info:t,cause:n},De),this.name=De,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Je}},Ke="InvalidMessagesError",O=class We extends S{constructor({info:t,cause:n}){super({info:t,cause:n},Ke),this.name=Ke,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof We}},He="InvalidToolsError",ee=class Ze extends S{constructor({info:t,cause:n}){super({info:t,cause:n},He),this.name=He,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof Ze}};var te="multi-string",Qe=zod.z.object({type:zod.z.literal(te),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()}),co=o=>zod.z.array(zod.z.string()).max(o).default([]).optional(),Xe=o=>({def:Qe.parse($({type:te},o)),schema:co(o.max)}),et="object-schema",uo=zod.z.object({type:zod.z.literal(et),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var oe="range",tt=zod.z.object({type:zod.z.literal(oe),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()}),ho=(o,t,n,a)=>zod.z.number().min(o).max(t).step(n).default(a).optional(),M=o=>({def:tt.parse($({type:oe},o)),schema:ho(o.min,o.max,o.step,o.default)}),ne="select-boolean",ot=zod.z.object({type:zod.z.literal(ne),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()}),fo=o=>zod.z.boolean().nullable().default(o).optional(),nt=o=>({def:ot.parse($({type:ne},o)),schema:fo(o.default)}),ae="select-string",at=zod.z.object({type:zod.z.literal(ae),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))}),go=(o,t)=>zod.z.enum(t).nullable().default(o).optional(),se=o=>({def:at.parse($({type:ae},o)),schema:go(o.default,o.choices)}),yo=[oe,te,ae,et,ne];zod.z.enum(yo);var bo=zod.z.discriminatedUnion("type",[tt,Qe,at,ot,uo]),st=(o=H,t=je)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(o,zod.z.string().min(1).optional()),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),bo),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(n=>{var a,r;let s=Object.keys(n.def),d=Object.keys((r=(a=n.schema)==null?void 0:a.shape)!=null?r:{});return s.every(p=>d.includes(p))&&d.every(p=>s.includes(p))},{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 To={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."},Co={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."},Ro=o=>({type:"multi",title:"Stop sequence",description:`Enter up to ${o} sequences that will halt additional text output. The generated text will exclude these sequences.`}),vo={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."},Oo={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."},Mo={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."},Eo={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."},xo={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."},_o={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."},Po={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."},So={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."},wo={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."},jo={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."},Io={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},ko={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."},qo={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."},Lo={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."},f={TEMPERATURE:To,MAX_TOKENS:Co,STOP:Ro,TOP_A:vo,TOP_P:Oo,TOP_K:Mo,MIN_P:Eo,FREQUENCY_PENALTY:xo,PRESENCE_PENALTY:_o,REPETITION_PENALTY:So,SEED:Po,LOG_PROBS:wo,TOP_LOG_PROBS:jo,ECHO:Io,RESPONSE_FORMAT:ko,RESPONSE_FORMAT_WITH_SCHEMA:qo,RESPONSE_SCHEMA:Lo};var rt=o=>Object.fromEntries(Object.entries(o).filter(([t,n])=>n!=null));var it=o=>o.split(";")[0].split("/")[1],A=o=>o==null?void 0:o.replace(/\/$/,"");var re=M({param:"temperature",title:f.TEMPERATURE.title,description:f.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),ie=o=>M({param:"max_tokens",title:f.MAX_TOKENS.title,description:f.MAX_TOKENS.description,min:0,max:o,step:1,default:0}),le=o=>Xe({param:"stop",title:f.STOP(o).title,description:f.STOP(o).description,max:o}),Rn=M({param:"top_a",title:f.TOP_A.title,description:f.TOP_A.description,min:0,max:1,step:.01,default:0}),vn=M({param:"top_k",title:f.TOP_K.title,description:f.TOP_K.description,min:0,max:100,step:1,default:0}),pe=M({param:"top_p",title:f.TOP_P.title,description:f.TOP_P.description,min:0,max:1,step:.01,default:1}),On=M({param:"min_p",title:f.MIN_P.title,description:f.MIN_P.description,min:0,max:1,step:.01,default:0}),me=M({param:"frequency_penalty",title:f.FREQUENCY_PENALTY.title,description:f.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),ce=M({param:"presence_penalty",title:f.PRESENCE_PENALTY.title,description:f.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),Mn=M({param:"repetition_penalty",title:f.REPETITION_PENALTY.title,description:f.REPETITION_PENALTY.description,min:0,max:2,step:.01,default:0}),de=M({param:"seed",title:f.SEED.title,description:f.SEED.description,min:0,max:1e6,step:1,default:0}),ue=nt({param:"logprobs",title:f.LOG_PROBS.title,description:f.LOG_PROBS.description,default:!1}),he=M({param:"top_logprobs",title:f.TOP_LOG_PROBS.title,description:f.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),fe=se({param:"tool_choice",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","required","none"]}),En=se({param:"response_format",title:f.RESPONSE_FORMAT.title,description:f.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]});var lt=(o,t)=>zod.z.object({temperature:re.schema,maxTokens:ie(o).schema,stop:le(t).schema,topP:pe.schema,frequencyPenalty:me.schema,presencePenalty:ce.schema,seed:de.schema.transform(n=>n===0?void 0:n),logProbs:ue.schema,topLogProbs:he.schema,toolChoice:fe.schema}),pt=(o,t)=>({temperature:re.def,maxTokens:ie(o).def,stop:le(t).def,topP:pe.def,frequencyPenalty:me.def,presencePenalty:ce.def,seed:de.def,logProbs:ue.def,topLogProbs:he.def,toolChoice:fe.def});var ge={base:(o,t)=>({def:pt(o,t),schema:lt(o,t)})};var Uo="open-router",N=class{constructor(){this.version="v1";this.name=Uo;this.embeddingModelFactories={};}chatModelLiterals(){return ["base"]}chatModelSchemas(){return {base:ye}}chatModel(t){let n=t.modelName;if(!n)throw new X({info:"options.modelName is required",cause:new Error("options.modelName is required")});let a=Re(R({},t),{modelName:n});return new F(ye,a)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,n)=>(t[n]=this.embeddingModelFactories[n].modelSchema,t),{})}embeddingModel(t){throw new X({info:"Open Router does not support embedding models",cause:new Error("Open Router does not support embedding models")})}};N.baseUrl="https://openrouter.ai/api/v1";var mt=zod.z.enum([j,I,v,k]),ct={system:j,user:I,assistant:v,tool:k};var dt=[C,x,E,_],ut=zod.z.enum([C,x,E,_]);var z=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),ht=zod.z.object({content:zod.z.array(z.extend({top_logprobs:zod.z.array(z)})).nullable(),refusal:zod.z.array(z.extend({top_logprobs:zod.z.array(z)})).nullable()}).nullable(),Ao=zod.z.array(zod.z.object({id:zod.z.string().min(1),type:zod.z.enum(["function"]),function:zod.z.object({name:zod.z.string(),arguments:zod.z.string()})})),ft=zod.z.object({id:zod.z.string(),object:zod.z.literal("chat.completion"),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable().optional(),choices:zod.z.array(zod.z.object({index:zod.z.number(),message:zod.z.object({role:zod.z.string(),content:zod.z.string().nullable().optional(),tool_calls:Ao.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:ht.optional(),finish_reason:zod.z.string()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()}),Fo=zod.z.array(zod.z.object({index:zod.z.number().int(),id:zod.z.string().min(1).optional(),type:zod.z.enum(["function"]).optional(),function:zod.z.object({name:zod.z.string().min(1).optional(),arguments:zod.z.string().optional()}).optional()})),gt=zod.z.object({id:zod.z.string(),object:zod.z.string(),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable().optional(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({content:zod.z.string().nullable().optional(),tool_calls:Fo.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:ht,finish_reason:zod.z.string().nullable()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()});var zo=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),parameters:zod.z.any()})}),Do=zod.z.enum(["none","auto","required"]),Ko=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),Ho=zod.z.object({type:zod.z.enum(["text","json_object"])}).or(zod.z.object({type:zod.z.literal("json_schema"),json_schema:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),schema:zod.z.any()})})),be=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),Go=zod.z.object({type:zod.z.literal("image_url"),image_url:zod.z.object({url:zod.z.string().url().min(1),detail:zod.z.enum(["low","high","auto"]).optional()})}),Vo=zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),arguments:zod.z.string().min(1)})}),Yo=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(be).min(1))}),Jo=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([be,Go])).min(1))}),Wo=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(be).min(1)).optional(),tool_calls:zod.z.array(Vo).min(1).optional()}),Zo=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),Qo=zod.z.union([Yo,Jo,Wo,Zo]),yt=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Qo).min(1),frequency_penalty:zod.z.number().min(-2).max(2).nullable().optional(),logprobs:zod.z.boolean().nullable().optional(),top_logprobs:zod.z.number().min(0).max(20).nullable().optional(),max_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),repetition_penalty:zod.z.number().min(0).max(2).nullable().optional(),response_format:Ho.optional(),seed:zod.z.number().nullable().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),top_a:zod.z.number().min(0).max(1).nullable().optional(),temperature:zod.z.number().min(0).max(2).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),top_k:zod.z.number().min(0).max(100).nullable().optional(),min_p:zod.z.number().min(0).max(1).nullable().optional(),tools:zod.z.array(zo).optional(),tool_choice:Do.or(Ko).optional()});var Xo=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),openRouterReferer:zod.z.string().optional(),openRouterTitle:zod.z.string().optional()}),F=class{constructor(t,n){this.version="v1";let a=Xo.parse(n);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=A(N.baseUrl),this.streamChatUrl=A(`${this.baseUrl}/chat/completions`),this.completeChatUrl=A(`${this.baseUrl}/chat/completions`),this.openRouterReferer=a.openRouterReferer,this.openRouterTitle=a.openRouterTitle;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return R(R({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"},this.openRouterReferer?{"HTTP-Referer":this.openRouterReferer}:{}),this.openRouterTitle?{"X-Title":this.openRouterTitle}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}getTokenCount(t){return t.reduce((n,a)=>n+a.content.map(r=>r.modality==="text"?r.value:"").join(" ").length,0)}transformModelRequest(t){let n=yt.safeParse(t);if(!n.success)throw new B({info:"Invalid model request",cause:n.error});let a=n.data,r=a.model;if(a.tool_choice&&(!a.tools||a.tools.length===0))throw new B({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let s={};a.response_format&&(s.responseFormat=a.response_format.type,a.response_format.type==="json_schema"&&(s.responseSchema={name:a.response_format.json_schema.name,description:a.response_format.json_schema.description||"",strict:a.response_format.json_schema.strict,schema:a.response_format.json_schema.schema})),a.tool_choice&&(typeof a.tool_choice=="string"?s.toolChoice=a.tool_choice:s.toolChoice=a.tool_choice.function.name),s.seed=a.seed,s.maxTokens=a.max_tokens,s.temperature=a.temperature,s.topA=a.top_a,s.topP=a.top_p,s.minP=a.min_p,s.topK=a.top_k,s.repetitionPenalty=a.repetition_penalty,s.presencePenalty=a.presence_penalty,s.frequencyPenalty=a.frequency_penalty,s.stop=a.stop,s.logProbs=a.logprobs,s.topLogProbs=a.top_logprobs;let d=qe().parse(rt(s)),p=[],c={};a.messages.forEach(u=>{let y=u.role;switch(y){case"system":{let g=u.content;if(typeof g=="string")p.push({role:y,content:[{modality:C,value:g}]});else {let b=g.map(T=>({modality:C,value:T.text}));p.push({role:y,content:b});}}break;case"user":{let g=u.content;if(typeof g=="string")p.push({role:y,content:[{modality:C,value:g}]});else {let b=g.map(T=>T.type==="text"?{modality:C,value:T.text}:T.image_url.url.startsWith("data:")?{modality:x,detail:T.image_url.detail||"auto",value:{type:G,base64:T.image_url.url,media_type:it(T.image_url.url)}}:{modality:x,detail:T.image_url.detail||"auto",value:{type:V,url:T.image_url.url}});p.push({role:y,content:b});}}break;case"assistant":{let g=[];if(!u.content&&!u.tool_calls)throw new B({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(u.content){let b=u.content;typeof b=="string"?g.push({modality:C,value:b}):b.forEach(T=>{g.push({modality:C,value:T.text});});}u.tool_calls&&u.tool_calls.forEach((T,bt)=>{let D={modality:E,id:T.id,index:bt,name:T.function.name,arguments:T.function.arguments};g.push(D),c[D.id]=D;}),p.push({role:y,content:g});}break;case"tool":{let g=u;p.push({role:y,content:[{modality:_,id:g.tool_call_id,index:c[g.tool_call_id].index,name:c[g.tool_call_id].name,data:g.content}]});}break}});let h=[];return a.tools&&a.tools.forEach(u=>{h.push({type:"function",definition:{schema:{name:u.function.name,description:u.function.description||"",strict:u.function.strict,parameters:u.function.parameters}}});}),{modelName:r,config:d,messages:p,tools:h.length>0?h:void 0}}transformConfig(t,n,a){let r=t.toolChoice;delete t.toolChoice;let s=this.modelSchema.config.schema.safeParse(t);if(!s.success)throw new w({info:`Invalid config for model : '${this.modelName}'`,cause:s.error});let d=s.data;r!==void 0&&(d.toolChoice=r),Object.keys(d).forEach(c=>{if(!(c in this.modelSchema.config.def))throw new w({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${c}',
7
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let p=Object.keys(d).reduce((c,h)=>{let u=this.modelSchema.config.def[h],y=u.param,g=d[h];return y==="max_tokens"&&u.type==="range"&&g===0?c[y]=u.max:c[y]=g,c},{});if(p.top_logprobs&&!p.logprobs)throw new w({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in p&&p.tool_choice!==void 0){let c=p.tool_choice;if(!a||a&&a.length===0)throw new w({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(a&&a.length>0){let h=this.modelSchema.config.def.toolChoice;if(!h.choices.includes(c))if(a.map(u=>u.definition.schema.name).includes(c))p.tool_choice={type:"function",function:{name:c}};else throw new w({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${c}' is not part of provided 'tools' names or
8
+ one of [${h.choices.join(", ")}]`)})}}if("response_format"in p&&p.response_format!==void 0){let c=p.response_format;if(c==="json_schema")if("response_schema"in p)p.response_format={type:"json_schema",json_schema:p.response_schema},delete p.response_schema;else throw new w({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else p.response_format={type:c};}return p}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let n=t.map(r=>{let s=q().safeParse(r);if(!s.success)throw new O({info:"Invalid messages",cause:s.error});return s.data});return n.forEach(r=>{r.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new O({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${s.modality}',
9
9
  available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),n.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new O({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}',
10
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:n.map(r=>{switch(r.role){case I:{let s=[];return r.content.forEach(d=>{if(d.modality===T)s.push({type:"text",text:d.value});else throw new O({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})}),{role:this.modelSchema.roles[r.role],content:s}}case v:{let s=[],d=[];return r.content.forEach(p=>{if(p.modality===T)s.push({type:"text",text:p.value});else if(p.modality===E)d.push({id:p.id,type:"function",function:{name:p.name,arguments:p.arguments}});else throw new O({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${p.modality}'`)})}),R({role:this.modelSchema.roles[r.role],content:s},d.length>0?{tool_calls:d}:{})}case k:{let s=[],d=[];r.content.forEach(c=>{if(c.modality===T)s.push({type:"text",text:c.value});else if(c.modality===x)d.push({type:"image_url",image_url:{url:c.value.type==="url"?c.value.url:c.value.base64,detail:c.detail}});else throw new O({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${c.modality}'`)})});let p=[...s,...d];return {role:this.modelSchema.roles[r.role],content:p}}case q:{if(r.content.length!==1)throw new O({info:`Invalid message for role : '${r.role}'`,cause:new Error(`role : '${r.role}' must have exactly one content item`)});if(r.content[0].modality!==_)throw new O({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' must have content with modality : '${_}'`)});let s=r.content[0];return {role:this.modelSchema.roles[r.role],tool_call_id:s.id,content:s.data}}default:throw new O({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
11
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(t){if(!this.modelSchema.modalities.includes(E))throw new ee({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${E}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(r=>{let s=qe().safeParse(r);if(!s.success)throw new ee({info:"Invalid tools",cause:s.error});return s.data}).map(r=>({type:"function",function:r.definition.schema}))}}getCompleteChatUrl(t,n,a){return P(this,null,function*(){return new Promise(r=>{r(this.completeChatUrl);})})}getCompleteChatHeaders(t,n,a){return P(this,null,function*(){return new Promise(r=>{r(this.getDefaultHeaders());})})}getCompleteChatData(t,n,a){return P(this,null,function*(){let r=this.transformConfig(t,n,a),s=this.transformMessages(n);if(s.messages&&s.messages.length===0)throw new O({info:"Messages are required",cause:new Error("Messages are required")});let d=a?this.transformTools(a):{};return new Promise(p=>{p(R(R(R(R({},this.getDefaultParams()),r),s),d));})})}transformCompleteChatResponse(t){let n=ht.safeParse(t);if(n.success){if(n.data.choices.length===0)throw new N({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(n.data)}`)});let a=n.data,r=[],s=a.choices[0].message;s.content&&r.push(Q(v,s.content)),s.refusal&&r.push(Q(v,s.refusal)),s.tool_calls&&s.tool_calls.forEach((h,u)=>{r.push(je(v,u,h.id,h.function.name,h.function.arguments));});let d;a.usage&&(d={promptTokens:a.usage.prompt_tokens,completionTokens:a.usage.completion_tokens,totalTokens:a.usage.total_tokens});let p=[],c=a.choices[0].logprobs;return c&&(c.content&&p.push(...c.content.map(h=>({token:h.token,logProb:h.logprob,bytes:h.bytes,topLogProbs:h.top_logprobs.map(u=>({token:u.token,logProb:u.logprob,bytes:u.bytes}))}))),c.refusal&&p.push(...c.refusal.map(h=>({token:h.token,logProb:h.logprob,bytes:h.bytes,topLogProbs:h.top_logprobs.map(u=>({token:u.token,logProb:u.logprob,bytes:u.bytes}))})))),{messages:r,usage:d,logProbs:p}}throw new N({info:"Invalid response from model",cause:n.error})}getStreamChatUrl(t,n,a){return P(this,null,function*(){return new Promise(r=>{r(this.streamChatUrl);})})}getStreamChatHeaders(t,n,a){return P(this,null,function*(){return new Promise(r=>{r(this.getDefaultHeaders());})})}getStreamChatData(t,n,a){return P(this,null,function*(){let r=this.transformConfig(t,n,a),s=this.transformMessages(n);if(s.messages&&s.messages.length===0)throw new O({info:"Messages are required",cause:new Error("Messages are required")});let d=a?this.transformTools(a):{};return new Promise(p=>{p(R(R(R(R({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),r),s),d));})})}transformStreamChatResponseChunk(t,n){return Re(this,null,function*(){var r,s;let a=(n+t).split(`
12
- `).filter(d=>d.trim()!=="");for(let d of a){if(d==="data: [DONE]")return;if(d.startsWith("data: {")&&d.endsWith("}")){let p;try{p=JSON.parse(d.substring(6));}catch(h){throw new N({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${p}`)})}let c=ft.safeParse(p);if(c.success){let h={partialMessages:[]},u=c.data;if(u.choices.length>0){let y=u.choices[0].delta;if(y!==void 0&&Object.keys(y).length!==0){if("content"in y&&y.content!==null)h.partialMessages.push(X(v,y.content));else if("refusal"in y&&y.refusal!==null)h.partialMessages.push(X(v,y.refusal));else if("tool_calls"in y&&y.tool_calls!==void 0){let g=y.tool_calls.at(0);h.partialMessages.push(Ie(v,g.index,g.id,(r=g.function)==null?void 0:r.name,(s=g.function)==null?void 0:s.arguments));}}}u.usage&&(h.usage={promptTokens:u.usage.prompt_tokens,completionTokens:u.usage.completion_tokens,totalTokens:u.usage.total_tokens}),yield {partialResponse:h,buffer:n};}else throw new N({info:"Invalid response from model",cause:c.error})}}})}};var ye=at(pt,dt).parse({name:"open-router-base-chat-model",description:"Base chat model for Open Router",maxInputTokens:128e3,maxOutputTokens:128e3,roles:mt,modalities:ct,config:{def:ge.base(128e3,4).def,schema:ge.base(128e3,4).schema}});
10
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:n.map(r=>{switch(r.role){case j:{let s=[];return r.content.forEach(d=>{if(d.modality===C)s.push({type:"text",text:d.value});else throw new O({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})}),{role:this.modelSchema.roles[r.role],content:s}}case v:{let s=[],d=[];return r.content.forEach(p=>{if(p.modality===C)s.push({type:"text",text:p.value});else if(p.modality===E)d.push({id:p.id,type:"function",function:{name:p.name,arguments:p.arguments}});else throw new O({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${p.modality}'`)})}),R({role:this.modelSchema.roles[r.role],content:s},d.length>0?{tool_calls:d}:{})}case I:{let s=[],d=[];r.content.forEach(c=>{if(c.modality===C)s.push({type:"text",text:c.value});else if(c.modality===x)d.push({type:"image_url",image_url:{url:c.value.type==="url"?c.value.url:c.value.base64,detail:c.detail}});else throw new O({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${c.modality}'`)})});let p=[...s,...d];return {role:this.modelSchema.roles[r.role],content:p}}case k:{if(r.content.length!==1)throw new O({info:`Invalid message for role : '${r.role}'`,cause:new Error(`role : '${r.role}' must have exactly one content item`)});if(r.content[0].modality!==_)throw new O({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' must have content with modality : '${_}'`)});let s=r.content[0];return {role:this.modelSchema.roles[r.role],tool_call_id:s.id,content:s.data}}default:throw new O({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
11
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(t){if(!this.modelSchema.modalities.includes(E))throw new ee({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${E}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(r=>{let s=Le().safeParse(r);if(!s.success)throw new ee({info:"Invalid tools",cause:s.error});return s.data}).map(r=>({type:"function",function:r.definition.schema}))}}getCompleteChatUrl(t,n,a){return P(this,null,function*(){return new Promise(r=>{r(this.completeChatUrl);})})}getCompleteChatHeaders(t,n,a){return P(this,null,function*(){return new Promise(r=>{r(this.getDefaultHeaders());})})}getCompleteChatData(t,n,a){return P(this,null,function*(){let r=this.transformConfig(t,n,a),s=this.transformMessages(n);if(s.messages&&s.messages.length===0)throw new O({info:"Messages are required",cause:new Error("Messages are required")});let d=a?this.transformTools(a):{};return new Promise(p=>{p(R(R(R(R({},this.getDefaultParams()),r),s),d));})})}transformCompleteChatResponse(t){let n=ft.safeParse(t);if(n.success){if(n.data.choices.length===0)throw new L({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(n.data)}`)});let a=n.data,r=[],s=a.choices[0].message;s.content&&r.push(Z(v,s.content)),s.refusal&&r.push(Z(v,s.refusal)),s.tool_calls&&s.tool_calls.forEach((h,u)=>{r.push(Ie(v,u,h.id,h.function.name,h.function.arguments));});let d;a.usage&&(d={promptTokens:a.usage.prompt_tokens,completionTokens:a.usage.completion_tokens,totalTokens:a.usage.total_tokens});let p=[],c=a.choices[0].logprobs;return c&&(c.content&&p.push(...c.content.map(h=>({token:h.token,logProb:h.logprob,bytes:h.bytes,topLogProbs:h.top_logprobs.map(u=>({token:u.token,logProb:u.logprob,bytes:u.bytes}))}))),c.refusal&&p.push(...c.refusal.map(h=>({token:h.token,logProb:h.logprob,bytes:h.bytes,topLogProbs:h.top_logprobs.map(u=>({token:u.token,logProb:u.logprob,bytes:u.bytes}))})))),{messages:r,usage:d,logProbs:p}}throw new L({info:"Invalid response from model",cause:n.error})}getStreamChatUrl(t,n,a){return P(this,null,function*(){return new Promise(r=>{r(this.streamChatUrl);})})}getStreamChatHeaders(t,n,a){return P(this,null,function*(){return new Promise(r=>{r(this.getDefaultHeaders());})})}getStreamChatData(t,n,a){return P(this,null,function*(){let r=this.transformConfig(t,n,a),s=this.transformMessages(n);if(s.messages&&s.messages.length===0)throw new O({info:"Messages are required",cause:new Error("Messages are required")});let d=a?this.transformTools(a):{};return new Promise(p=>{p(R(R(R(R({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),r),s),d));})})}transformStreamChatResponseChunk(t,n){return ve(this,null,function*(){var r,s;let a=(n+t).split(`
12
+ `).filter(d=>d.trim()!=="");for(let d of a){if(d==="data: [DONE]")return;if(d.startsWith("data: {")&&d.endsWith("}")){let p;try{p=JSON.parse(d.substring(6));}catch(h){throw new L({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${p}`)})}let c=gt.safeParse(p);if(c.success){let h={partialMessages:[]},u=c.data;if(u.choices.length>0){let y=u.choices[0].delta;if(y!==void 0&&Object.keys(y).length!==0){if("content"in y&&y.content!==null)h.partialMessages.push(Q(v,y.content));else if("refusal"in y&&y.refusal!==null)h.partialMessages.push(Q(v,y.refusal));else if("tool_calls"in y&&y.tool_calls!==void 0){let g=y.tool_calls.at(0);h.partialMessages.push(ke(v,g.index,g.id,(r=g.function)==null?void 0:r.name,(s=g.function)==null?void 0:s.arguments));}}}u.usage&&(h.usage={promptTokens:u.usage.prompt_tokens,completionTokens:u.usage.completion_tokens,totalTokens:u.usage.total_tokens}),yield {partialResponse:h,buffer:n};}else throw new L({info:"Invalid response from model",cause:c.error})}}})}};var ye=st(mt,ut).parse({name:"open-router-base-chat-model",description:"Base chat model for Open Router",maxInputTokens:128e3,maxOutputTokens:128e3,roles:ct,modalities:dt,config:{def:ge.base(128e3,4).def,schema:ge.base(128e3,4).schema}});
13
13
 
14
- exports.BaseChatModel = z;
14
+ exports.BaseChatModel = F;
15
15
  exports.BaseChatModelSchema = ye;
16
- exports.ChatModelBaseConfigDef = lt;
17
- exports.ChatModelBaseConfigSchema = it;
18
- exports.OpenRouter = U;
16
+ exports.ChatModelBaseConfigDef = pt;
17
+ exports.ChatModelBaseConfigSchema = lt;
18
+ exports.OpenRouter = N;
19
19
  exports.OpenRouterChatModelConfigs = ge;
20
20
  exports.frequencyPenalty = me;
21
21
  exports.logProbs = ue;
22
22
  exports.maxTokens = ie;
23
- exports.minP = Tn;
23
+ exports.minP = On;
24
24
  exports.presencePenalty = ce;
25
- exports.repetitionPenalty = Rn;
26
- exports.responseFormat = vn;
25
+ exports.repetitionPenalty = Mn;
26
+ exports.responseFormat = En;
27
27
  exports.seed = de;
28
28
  exports.stop = le;
29
29
  exports.temperature = re;
30
30
  exports.toolChoice = fe;
31
- exports.topA = bn;
32
- exports.topK = Cn;
31
+ exports.topA = Rn;
32
+ exports.topK = vn;
33
33
  exports.topLogProbs = he;
34
34
  exports.topP = pe;
35
35
  //# sourceMappingURL=index.js.map