@adaline/open-router 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -95,7 +95,7 @@ declare const OpenRouterChatModelConfigs: {
|
|
|
95
95
|
param: string;
|
|
96
96
|
title: string;
|
|
97
97
|
description: string;
|
|
98
|
-
default: string
|
|
98
|
+
default: string;
|
|
99
99
|
choices: string[];
|
|
100
100
|
};
|
|
101
101
|
};
|
|
@@ -260,7 +260,7 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
|
|
|
260
260
|
param: string;
|
|
261
261
|
title: string;
|
|
262
262
|
description: string;
|
|
263
|
-
default: string
|
|
263
|
+
default: string;
|
|
264
264
|
choices: string[];
|
|
265
265
|
};
|
|
266
266
|
};
|
|
@@ -434,7 +434,7 @@ declare const toolChoice: {
|
|
|
434
434
|
param: string;
|
|
435
435
|
title: string;
|
|
436
436
|
description: string;
|
|
437
|
-
default: string
|
|
437
|
+
default: string;
|
|
438
438
|
choices: string[];
|
|
439
439
|
};
|
|
440
440
|
schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNullable<zod.ZodEnum<[string, ...string[]]>>>>;
|
|
@@ -445,7 +445,7 @@ declare const responseFormat: {
|
|
|
445
445
|
param: string;
|
|
446
446
|
title: string;
|
|
447
447
|
description: string;
|
|
448
|
-
default: string
|
|
448
|
+
default: string;
|
|
449
449
|
choices: string[];
|
|
450
450
|
};
|
|
451
451
|
schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNullable<zod.ZodEnum<[string, ...string[]]>>>>;
|
|
@@ -992,11 +992,12 @@ declare const BaseChatModelSchema: {
|
|
|
992
992
|
param: string;
|
|
993
993
|
title: string;
|
|
994
994
|
description: string;
|
|
995
|
-
default: string
|
|
995
|
+
default: string;
|
|
996
996
|
choices: string[];
|
|
997
997
|
}>;
|
|
998
998
|
schema: zod.ZodObject<zod.ZodRawShape, zod.UnknownKeysParam, zod.ZodTypeAny, unknown, unknown>;
|
|
999
999
|
};
|
|
1000
|
+
maxReasoningTokens?: number | undefined;
|
|
1000
1001
|
};
|
|
1001
1002
|
|
|
1002
1003
|
declare class OpenRouter<C extends BaseChatModelOptionsType, E extends Record<string, any> = Record<string, any>> implements ProviderV1<C, E> {
|
package/dist/index.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ declare const OpenRouterChatModelConfigs: {
|
|
|
95
95
|
param: string;
|
|
96
96
|
title: string;
|
|
97
97
|
description: string;
|
|
98
|
-
default: string
|
|
98
|
+
default: string;
|
|
99
99
|
choices: string[];
|
|
100
100
|
};
|
|
101
101
|
};
|
|
@@ -260,7 +260,7 @@ declare const ChatModelBaseConfigDef: (maxOutputTokens: number, maxSequences: nu
|
|
|
260
260
|
param: string;
|
|
261
261
|
title: string;
|
|
262
262
|
description: string;
|
|
263
|
-
default: string
|
|
263
|
+
default: string;
|
|
264
264
|
choices: string[];
|
|
265
265
|
};
|
|
266
266
|
};
|
|
@@ -434,7 +434,7 @@ declare const toolChoice: {
|
|
|
434
434
|
param: string;
|
|
435
435
|
title: string;
|
|
436
436
|
description: string;
|
|
437
|
-
default: string
|
|
437
|
+
default: string;
|
|
438
438
|
choices: string[];
|
|
439
439
|
};
|
|
440
440
|
schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNullable<zod.ZodEnum<[string, ...string[]]>>>>;
|
|
@@ -445,7 +445,7 @@ declare const responseFormat: {
|
|
|
445
445
|
param: string;
|
|
446
446
|
title: string;
|
|
447
447
|
description: string;
|
|
448
|
-
default: string
|
|
448
|
+
default: string;
|
|
449
449
|
choices: string[];
|
|
450
450
|
};
|
|
451
451
|
schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNullable<zod.ZodEnum<[string, ...string[]]>>>>;
|
|
@@ -992,11 +992,12 @@ declare const BaseChatModelSchema: {
|
|
|
992
992
|
param: string;
|
|
993
993
|
title: string;
|
|
994
994
|
description: string;
|
|
995
|
-
default: string
|
|
995
|
+
default: string;
|
|
996
996
|
choices: string[];
|
|
997
997
|
}>;
|
|
998
998
|
schema: zod.ZodObject<zod.ZodRawShape, zod.UnknownKeysParam, zod.ZodTypeAny, unknown, unknown>;
|
|
999
999
|
};
|
|
1000
|
+
maxReasoningTokens?: number | undefined;
|
|
1000
1001
|
};
|
|
1001
1002
|
|
|
1002
1003
|
declare class OpenRouter<C extends BaseChatModelOptionsType, E extends Record<string, any> = Record<string, any>> implements ProviderV1<C, E> {
|
package/dist/index.js
CHANGED
|
@@ -2,35 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
Message: ${Et(o)}`),this.name=G,this.info=t,this.cause=o,this.name=a!=null?a:G,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof Se}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},k="system",q="user",_="assistant",L="tool",Pt=[k,q,_,L],V=zod.z.enum(Pt),St=[_],wt=zod.z.enum(St),P="image",Y="base64",jt=["png","jpeg","webp","gif"],It=zod.z.object({type:zod.z.literal(Y),base64:zod.z.string(),media_type:zod.z.enum(jt)}),J="url",kt=zod.z.object({type:zod.z.literal(J),url:zod.z.string()}),qt=zod.z.discriminatedUnion("type",[It,kt]),Lt=["low","medium","high","auto"],Nt=zod.z.enum(Lt),Ut=(n=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(P),detail:Nt,value:qt,metadata:n}),T="text",we=(n=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(T),value:zod.z.string(),metadata:n}),W="partial-text",je=(n=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(W),value:zod.z.string(),metadata:n}),E="tool-call",Ie=(n=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:n}),Z="partial-tool-call",ke=(n=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Z),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:n}),S="tool-response",$t=(n=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(S),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:n}),Bt=[T,P,E,S],qe=zod.z.enum(Bt),At=(n=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[we(n),Ut(t),Ie(o),$t(a)]),Ft=[W,Z];zod.z.enum(Ft);var zt=(n=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[je(n),ke(t)]);var Q=(n=V,t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:n,content:zod.z.array(At(t,o,a,s)),metadata:r}),X=(n=wt,t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined())=>zod.z.object({role:n,partialContent:zt(t,o),metadata:a}),ee=n=>we().parse({modality:T,value:n}),Le=(n,t,o,a)=>Ie().parse({modality:E,index:n,id:t,name:o,arguments:a});var te=(n,t)=>X().parse({role:n,partialContent:je().parse({modality:W,value:t})}),Ne=(n,t,o,a,s)=>X().parse({role:n,partialContent:ke().parse({modality:Z,index:t,id:o,name:a,arguments:s})});var Ue=(n=zod.z.record(zod.z.string(),zod.z.any()).optional())=>n,Dt=["object","array","number","string","boolean","enum"],_e=zod.z.enum(Dt),Ht=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([_e,zod.z.array(zod.z.union([_e,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()}),Kt=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(Ht),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:Kt}).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 $e=(n=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Zt.extend({metadata:n})]),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()}),Ee=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:Ee.optional()}),zod.z.object({encodingFormat:zod.z.literal(so),embeddings:zod.z.array(ro),usage:Ee.optional()})]);var Be=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Pe=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),io=Pe.extend({topLogProbs:zod.z.array(Pe)}),Ae=zod.z.array(io);zod.z.object({messages:zod.z.array(Q()),usage:Be.optional(),logProbs:Ae.optional()});zod.z.object({partialMessages:zod.z.array(X()),usage:Be.optional(),logProbs:Ae.optional()});var lo=Object.defineProperty,Fe=Object.getOwnPropertySymbols,po=Object.prototype.hasOwnProperty,mo=Object.prototype.propertyIsEnumerable,ze=(n,t,o)=>t in n?lo(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,A=(n,t)=>{for(var o in t||(t={}))po.call(t,o)&&ze(n,o,t[o]);if(Fe)for(var o of Fe(t))mo.call(t,o)&&ze(n,o,t[o]);return n},De="ProviderError",Je=class We extends j{constructor({info:t,cause:o}){super({info:t,cause:o},De),this.name=De,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof We}};var He="ModelResponseError",N=class Ze extends j{constructor({info:t,cause:o}){super({info:t,cause:o},He),this.name=He,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof Ze}},Ke="InvalidModelRequestError",F=class Qe extends j{constructor({info:t,cause:o}){super({info:t,cause:o},Ke),this.name=Ke,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Qe}},Ge="InvalidConfigError",I=class Xe extends j{constructor({info:t,cause:o}){super({info:t,cause:o},Ge),this.name=Ge,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Xe}},Ve="InvalidMessagesError",O=class et extends j{constructor({info:t,cause:o}){super({info:t,cause:o},Ve),this.name=Ve,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof et}},Ye="InvalidToolsError",oe=class tt extends j{constructor({info:t,cause:o}){super({info:t,cause:o},Ye),this.name=Ye,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof tt}};var ne="multi-string",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),max:zod.z.number().int().positive()}),co=n=>zod.z.array(zod.z.string()).max(n).default([]).optional(),nt=n=>({def:ot.parse(A({type:ne},n)),schema:co(n.max)}),at="object-schema",uo=zod.z.object({type:zod.z.literal(at),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 ae="range",st=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),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),ho=(n,t,o,a)=>zod.z.number().min(n).max(t).step(o).default(a).optional(),M=n=>({def:st.parse(A({type:ae},n)),schema:ho(n.min,n.max,n.step,n.default)}),se="select-boolean",rt=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()}),go=n=>zod.z.boolean().nullable().default(n).optional(),it=n=>({def:rt.parse(A({type:se},n)),schema:go(n.default)}),re="select-string",lt=zod.z.object({type:zod.z.literal(re),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))}),fo=(n,t)=>zod.z.enum(t).nullable().default(n).optional(),ie=n=>({def:lt.parse(A({type:re},n)),schema:fo(n.default,n.choices)}),yo=[ae,ne,re,at,se];zod.z.enum(yo);var bo=zod.z.discriminatedUnion("type",[st,ot,lt,rt,uo]),pt=(n=V,t=qe)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(n,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(o=>{var a,s;let r=Object.keys(o.def),d=Object.keys((s=(a=o.schema)==null?void 0:a.shape)!=null?s:{});return r.every(p=>d.includes(p))&&d.every(p=>r.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 Co={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."},To={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=n=>({type:"multi",title:"Stop sequence",description:`Enter up to ${n} 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."},xo={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."},_o={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."},Eo={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."},g={TEMPERATURE:Co,MAX_TOKENS:To,STOP:Ro,TOP_A:vo,TOP_P:Oo,TOP_K:Mo,MIN_P:xo,FREQUENCY_PENALTY:_o,PRESENCE_PENALTY:Eo,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 mt=n=>Object.fromEntries(Object.entries(n).filter(([t,o])=>o!=null));var ct=n=>n.split(";")[0].split("/")[1],z=n=>n==null?void 0:n.replace(/\/$/,"");var le=M({param:"temperature",title:g.TEMPERATURE.title,description:g.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),pe=n=>M({param:"max_tokens",title:g.MAX_TOKENS.title,description:g.MAX_TOKENS.description,min:0,max:n,step:1,default:0}),me=n=>nt({param:"stop",title:g.STOP(n).title,description:g.STOP(n).description,max:n}),Tn=M({param:"top_a",title:g.TOP_A.title,description:g.TOP_A.description,min:0,max:1,step:.01,default:0}),Rn=M({param:"top_k",title:g.TOP_K.title,description:g.TOP_K.description,min:0,max:100,step:1,default:0}),ce=M({param:"top_p",title:g.TOP_P.title,description:g.TOP_P.description,min:0,max:1,step:.01,default:1}),vn=M({param:"min_p",title:g.MIN_P.title,description:g.MIN_P.description,min:0,max:1,step:.01,default:0}),de=M({param:"frequency_penalty",title:g.FREQUENCY_PENALTY.title,description:g.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),ue=M({param:"presence_penalty",title:g.PRESENCE_PENALTY.title,description:g.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),On=M({param:"repetition_penalty",title:g.REPETITION_PENALTY.title,description:g.REPETITION_PENALTY.description,min:0,max:2,step:.01,default:0}),he=M({param:"seed",title:g.SEED.title,description:g.SEED.description,min:0,max:1e6,step:1,default:0}),ge=it({param:"logprobs",title:g.LOG_PROBS.title,description:g.LOG_PROBS.description,default:!1}),fe=M({param:"top_logprobs",title:g.TOP_LOG_PROBS.title,description:g.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),ye=ie({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"]}),Mn=ie({param:"response_format",title:g.RESPONSE_FORMAT.title,description:g.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]});var dt=(n,t)=>zod.z.object({temperature:le.schema,maxTokens:pe(n).schema,stop:me(t).schema,topP:ce.schema,frequencyPenalty:de.schema,presencePenalty:ue.schema,seed:he.schema.transform(o=>o===0?void 0:o),logProbs:ge.schema,topLogProbs:fe.schema,toolChoice:ye.schema}),ut=(n,t)=>({temperature:le.def,maxTokens:pe(n).def,stop:me(t).def,topP:ce.def,frequencyPenalty:de.def,presencePenalty:ue.def,seed:he.def,logProbs:ge.def,topLogProbs:fe.def,toolChoice:ye.def});var be={base:(n,t)=>({def:ut(n,t),schema:dt(n,t)})};var Uo="open-router",U=class{constructor(){this.version="v1";this.name=Uo;this.embeddingModelFactories={};}chatModelLiterals(){return ["__base__"]}chatModelSchemas(){return {__base__:Ce}}chatModel(t){let o=D,a=Te.parse(t);return new o(Ce,a)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,o)=>(t[o]=this.embeddingModelFactories[o].modelSchema,t),{})}embeddingModel(t){throw new Je({info:"Open Router does not support embedding models yet",cause:new Error("Open Router does not support embedding models yet")})}};U.baseUrl="https://openrouter.ai/api/v1";var ht=zod.z.enum([k,q,_,L]),gt={system:k,user:q,assistant:_,tool:L};var ft=[T,P,E,S],yt=zod.z.enum([T,P,E,S]);var H=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),bt=zod.z.object({content:zod.z.array(H.extend({top_logprobs:zod.z.array(H)})).nullable(),refusal:zod.z.array(H.extend({top_logprobs:zod.z.array(H)})).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()})})),Ct=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(),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:bt.optional(),finish_reason:zod.z.string().nullable().optional()})),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()})),Tt=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:bt,finish_reason:zod.z.string().nullable().optional()})),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"]),Ho=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),Ko=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()})})),Re=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(Re).min(1))}),Jo=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Re,Go])).min(1))}),Wo=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(Re).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]),Rt=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:Ko.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(Ho).optional()});var Te=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),openRouterReferer:zod.z.string().optional(),openRouterTitle:zod.z.string().optional()}),D=class{constructor(t,o){this.version="v1";let a=Te.parse(o);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=z(U.baseUrl),this.streamChatUrl=z(`${this.baseUrl}/chat/completions`),this.completeChatUrl=z(`${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"},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((o,a)=>o+a.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(t){let o=Rt.safeParse(t);if(!o.success)throw new F({info:"Invalid model request",cause:o.error});let a=o.data,s=a.model;if(a.tool_choice&&(!a.tools||a.tools.length===0))throw new F({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let r={};a.response_format&&(r.responseFormat=a.response_format.type,a.response_format.type==="json_schema"&&(r.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"?r.toolChoice=a.tool_choice:r.toolChoice=a.tool_choice.function.name),r.seed=a.seed,r.maxTokens=a.max_tokens,r.temperature=a.temperature,r.topA=a.top_a,r.topP=a.top_p,r.minP=a.min_p,r.topK=a.top_k,r.repetitionPenalty=a.repetition_penalty,r.presencePenalty=a.presence_penalty,r.frequencyPenalty=a.frequency_penalty,r.stop=a.stop,r.logProbs=a.logprobs,r.topLogProbs=a.top_logprobs;let d=Ue().parse(mt(r)),p=[],c={};a.messages.forEach(h=>{let C=h.role;switch(C){case"system":{let f=h.content;if(typeof f=="string")p.push({role:C,content:[{modality:T,value:f}]});else {let y=f.map(b=>({modality:T,value:b.text}));p.push({role:C,content:y});}}break;case"user":{let f=h.content;if(typeof f=="string")p.push({role:C,content:[{modality:T,value:f}]});else {let y=f.map(b=>b.type==="text"?{modality:T,value:b.text}:b.image_url.url.startsWith("data:")?{modality:P,detail:b.image_url.detail||"auto",value:{type:Y,base64:b.image_url.url,media_type:ct(b.image_url.url)}}:{modality:P,detail:b.image_url.detail||"auto",value:{type:J,url:b.image_url.url}});p.push({role:C,content:y});}}break;case"assistant":{let f=[];if(!h.content&&!h.tool_calls)throw new F({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(h.content){let y=h.content;typeof y=="string"?f.push({modality:T,value:y}):y.forEach(b=>{f.push({modality:T,value:b.text});});}h.tool_calls&&h.tool_calls.forEach((b,v)=>{let w={modality:E,id:b.id,index:v,name:b.function.name,arguments:b.function.arguments};f.push(w),c[w.id]=w;}),p.push({role:C,content:f});}break;case"tool":{let f=h;p.push({role:C,content:[{modality:S,id:f.tool_call_id,index:c[f.tool_call_id].index,name:c[f.tool_call_id].name,data:f.content}]});}break}});let u=[];return a.tools&&a.tools.forEach(h=>{u.push({type:"function",definition:{schema:{name:h.function.name,description:h.function.description||"",strict:h.function.strict,parameters:h.function.parameters}}});}),{modelName:s,config:d,messages:p,tools:u.length>0?u:void 0}}transformConfig(t,o,a){let s=t.toolChoice;delete t.toolChoice;let r=this.modelSchema.config.schema.safeParse(t);if(!r.success)throw new I({info:`Invalid config for model : '${this.modelName}'`,cause:r.error});let d=r.data;s!==void 0&&(d.toolChoice=s),Object.keys(d).forEach(c=>{if(!(c in this.modelSchema.config.def))throw new I({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(
|
|
8
|
-
one of [${u.choices.join(", ")}]`)})}}if("response_format"in p&&p.response_format!==void 0){let
|
|
9
|
-
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),
|
|
10
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:
|
|
11
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(t){if(!this.modelSchema.modalities.includes(
|
|
12
|
-
`,
|
|
5
|
+
var Pt=Object.defineProperty;var Me=Object.getOwnPropertySymbols;var _t=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable;var $=(o,t)=>(t=Symbol[o])?t:Symbol.for("Symbol."+o),wt=o=>{throw TypeError(o)};var Oe=(o,t,n)=>t in o?Pt(o,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[t]=n,R=(o,t)=>{for(var n in t||(t={}))_t.call(t,n)&&Oe(o,n,t[n]);if(Me)for(var n of Me(t))St.call(t,n)&&Oe(o,n,t[n]);return o};var x=(o,t,n)=>new Promise((a,s)=>{var r=d=>{try{p(n.next(d));}catch(u){s(u);}},c=d=>{try{p(n.throw(d));}catch(u){s(u);}},p=d=>d.done?a(d.value):Promise.resolve(d.value).then(r,c);p((n=n.apply(o,t)).next());}),xe=function(o,t){this[0]=o,this[1]=t;},K=(o,t,n)=>{var a=(c,p,d,u)=>{try{var g=n[c](p),C=(p=g.value)instanceof xe,y=g.done;Promise.resolve(C?p[0]:p).then(f=>C?a(c==="return"?c:"next",p[1]?{done:f.done,value:f.value}:f,d,u):d({value:f,done:y})).catch(f=>a("throw",f,d,u));}catch(f){u(f);}},s=c=>r[c]=p=>new Promise((d,u)=>a(c,p,d,u)),r={};return n=n.apply(o,t),r[$("asyncIterator")]=()=>r,s("next"),s("throw"),s("return"),r},Ee=o=>{var t=o[$("asyncIterator")],n=!1,a,s={};return t==null?(t=o[$("iterator")](),a=r=>s[r]=c=>t[r](c)):(t=t.call(o),a=r=>s[r]=c=>{if(n){if(n=!1,r==="throw")throw c;return c}return n=!0,{done:!1,value:new xe(new Promise(p=>{var d=t[r](c);d instanceof Object||wt("Object expected"),p(d);}),1)}}),s[$("iterator")]=()=>s,a("next"),"throw"in t?a("throw"):s.throw=r=>{throw r},"return"in t&&a("return"),s};var jt=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})},kt=o=>o==null?"unknown error":typeof o=="string"?o:o instanceof Error?o.message:jt(o),V="GatewayBaseError",j=class we extends Error{constructor({info:t,cause:n},a){super(`[${a!=null?a:V}]: ${t}
|
|
6
|
+
Message: ${kt(n)}`),this.name=V,this.info=t,this.cause=n,this.name=a!=null?a:V,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof we}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},I="system",q="user",E="assistant",L="tool",It=[I,q,E,L],Y=zod.z.enum(It),qt=[E],Lt=zod.z.enum(qt),_="image",W="base64",Nt=["png","jpeg","webp","gif"],Ut=zod.z.object({type:zod.z.literal(W),base64:zod.z.string(),media_type:zod.z.enum(Nt)}),J="url",Bt=zod.z.object({type:zod.z.literal(J),url:zod.z.string()}),$t=zod.z.discriminatedUnion("type",[Ut,Bt]),At=["low","medium","high","auto"],Ft=zod.z.enum(At),zt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_),detail:Ft,value:$t,metadata:o}),je="reasoning",ke="partial-reasoning",Ie="thinking",Dt="redacted",G=zod.z.object({type:zod.z.literal(Ie),thinking:zod.z.string(),signature:zod.z.string()}),qe=zod.z.object({type:zod.z.literal(Dt),data:zod.z.string()}),Ht=zod.z.discriminatedUnion("type",[G,qe]),Kt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(je),value:Ht,metadata:o}),Vt=zod.z.object({type:zod.z.literal(Ie),thinking:G.shape.thinking.optional(),signature:G.shape.signature.optional()}),Gt=zod.z.discriminatedUnion("type",[Vt,qe]),Yt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ke),value:Gt,metadata:o}),T="text",Le=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(T),value:zod.z.string(),metadata:o}),X="partial-text",Ne=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(X),value:zod.z.string(),metadata:o}),P="tool-call",Ue=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(P),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:o}),Z="partial-tool-call",Be=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Z),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:o}),S="tool-response",Wt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(S),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:o}),Jt=[T,_,P,S,je],$e=zod.z.enum(Jt),Xt=(o=zod.z.undefined(),t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Le(o),zt(t),Ue(n),Wt(a),Kt(s)]),Zt=[X,Z,ke];zod.z.enum(Zt);var Qt=(o=zod.z.undefined(),t=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ne(o),Be(t),Yt(n)]);var Q=(o=Y,t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined(),c=zod.z.undefined())=>zod.z.object({role:o,content:zod.z.array(Xt(t,n,a,s,c)),metadata:r}),ee=(o=Lt,t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:o,partialContent:Qt(t,n,a),metadata:s}),te=o=>Le().parse({modality:T,value:o}),Ae=(o,t,n,a)=>Ue().parse({modality:P,index:o,id:t,name:n,arguments:a});var oe=(o,t)=>ee().parse({role:o,partialContent:Ne().parse({modality:X,value:t})}),Fe=(o,t,n,a,s)=>ee().parse({role:o,partialContent:Be().parse({modality:Z,index:t,id:n,name:a,arguments:s})});var ze=(o=zod.z.record(zod.z.string(),zod.z.any()).optional())=>o,eo=["object","array","number","string","boolean","enum"],Pe=zod.z.enum(eo),to=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Pe,zod.z.array(zod.z.union([Pe,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()}),oo=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(to),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:oo}).optional();var no="function";var ao=zod.z.enum(["object","array","number","string","boolean","null"]),so=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ao.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(so).optional(),required:zod.z.array(zod.z.string()).optional()});var ro=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 io=zod.z.enum(["function"]),lo=zod.z.object({type:io,definition:zod.z.object({schema:ro})}),po=[no];zod.z.enum(po);var De=(o=zod.z.undefined())=>zod.z.discriminatedUnion("type",[lo.extend({metadata:o})]),mo="text",co="token",uo=[mo,co];zod.z.enum(uo);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var ho="float",yo=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),fo="base64",bo=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),_e=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(ho),embeddings:zod.z.array(yo),usage:_e.optional()}),zod.z.object({encodingFormat:zod.z.literal(fo),embeddings:zod.z.array(bo),usage:_e.optional()})]);var He=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Se=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Co=Se.extend({topLogProbs:zod.z.array(Se)}),Ke=zod.z.array(Co);zod.z.object({messages:zod.z.array(Q()),usage:He.optional(),logProbs:Ke.optional()});zod.z.object({partialMessages:zod.z.array(ee()),usage:He.optional(),logProbs:Ke.optional()});var To=Object.defineProperty,Ve=Object.getOwnPropertySymbols,Ro=Object.prototype.hasOwnProperty,vo=Object.prototype.propertyIsEnumerable,Ge=(o,t,n)=>t in o?To(o,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[t]=n,A=(o,t)=>{for(var n in t||(t={}))Ro.call(t,n)&&Ge(o,n,t[n]);if(Ve)for(var n of Ve(t))vo.call(t,n)&&Ge(o,n,t[n]);return o},Ye="ProviderError",et=class tt extends j{constructor({info:t,cause:n}){super({info:t,cause:n},Ye),this.name=Ye,this.info=t,this.cause=n;}static isProviderError(t){return t instanceof tt}};var We="ModelResponseError",N=class ot extends j{constructor({info:t,cause:n}){super({info:t,cause:n},We),this.name=We,this.cause=n,this.info=t;}static isModelResponseError(t){return t instanceof ot}},Je="InvalidModelRequestError",F=class nt extends j{constructor({info:t,cause:n}){super({info:t,cause:n},Je),this.name=Je,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof nt}},Xe="InvalidConfigError",k=class at extends j{constructor({info:t,cause:n}){super({info:t,cause:n},Xe),this.name=Xe,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof at}},Ze="InvalidMessagesError",M=class st extends j{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 isInvalidMessagesError(t){return t instanceof st}},Qe="InvalidToolsError",ne=class rt extends j{constructor({info:t,cause:n}){super({info:t,cause:n},Qe),this.name=Qe,this.cause=n,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof rt}};var ae="multi-string",it=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),max:zod.z.number().int().positive()}),Mo=o=>zod.z.array(zod.z.string()).max(o).default([]).optional(),lt=o=>({def:it.parse(A({type:ae},o)),schema:Mo(o.max)}),pt="object-schema",Oo=zod.z.object({type:zod.z.literal(pt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var se="range",mt=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),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),xo=(o,t,n,a)=>zod.z.number().min(o).max(t).step(n).default(a).optional(),O=o=>({def:mt.parse(A({type:se},o)),schema:xo(o.min,o.max,o.step,o.default)}),re="select-boolean",dt=zod.z.object({type:zod.z.literal(re),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()}),Eo=o=>zod.z.boolean().nullable().default(o).optional(),ct=o=>({def:dt.parse(A({type:re},o)),schema:Eo(o.default)}),ie="select-string",ut=zod.z.object({type:zod.z.literal(ie),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())}),Po=(o,t)=>zod.z.enum(t).nullable().default(o).optional(),le=o=>({def:ut.parse(A({type:ie},o)),schema:Po(o.default,o.choices)}),_o=[se,ae,ie,pt,re];zod.z.enum(_o);var So=zod.z.discriminatedUnion("type",[mt,it,ut,dt,Oo]),gt=(o=Y,t=$e)=>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),maxReasoningTokens:zod.z.number().int().positive().min(1).optional(),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),So),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(n=>{var a,s;let r=Object.keys(n.def),c=Object.keys((s=(a=n.schema)==null?void 0:a.shape)!=null?s:{});return r.every(p=>c.includes(p))&&c.every(p=>r.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 wo={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."},jo={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."},ko={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},Io=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.`}),qo={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."},Lo={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."},No={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."},Uo={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."},Bo={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."},Ao={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."},Fo={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."},zo={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."},Do={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."},Ho={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."},Vo={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."},Go={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."},h={TEMPERATURE:wo,MAX_TOKENS:jo,STOP:Io,TOP_A:qo,TOP_P:Lo,TOP_K:No,MIN_P:Uo,FREQUENCY_PENALTY:Bo,PRESENCE_PENALTY:$o,REPETITION_PENALTY:Fo,SEED:Ao,LOG_PROBS:zo,TOP_LOG_PROBS:Do,ECHO:Ho,RESPONSE_FORMAT:Ko,RESPONSE_FORMAT_WITH_SCHEMA:Vo,RESPONSE_SCHEMA:Go,MAX_REASONING_TOKENS:ko};var ht=o=>Object.fromEntries(Object.entries(o).filter(([t,n])=>n!=null));var yt=o=>o.split(";")[0].split("/")[1],z=o=>o==null?void 0:o.replace(/\/$/,"");var pe=O({param:"temperature",title:h.TEMPERATURE.title,description:h.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),me=o=>O({param:"max_tokens",title:h.MAX_TOKENS.title,description:h.MAX_TOKENS.description,min:0,max:o,step:1,default:0}),de=o=>lt({param:"stop",title:h.STOP(o).title,description:h.STOP(o).description,max:o}),kn=O({param:"top_a",title:h.TOP_A.title,description:h.TOP_A.description,min:0,max:1,step:.01,default:0}),In=O({param:"top_k",title:h.TOP_K.title,description:h.TOP_K.description,min:0,max:100,step:1,default:0}),ce=O({param:"top_p",title:h.TOP_P.title,description:h.TOP_P.description,min:0,max:1,step:.01,default:1}),qn=O({param:"min_p",title:h.MIN_P.title,description:h.MIN_P.description,min:0,max:1,step:.01,default:0}),ue=O({param:"frequency_penalty",title:h.FREQUENCY_PENALTY.title,description:h.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),ge=O({param:"presence_penalty",title:h.PRESENCE_PENALTY.title,description:h.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),Ln=O({param:"repetition_penalty",title:h.REPETITION_PENALTY.title,description:h.REPETITION_PENALTY.description,min:0,max:2,step:.01,default:0}),he=O({param:"seed",title:h.SEED.title,description:h.SEED.description,min:0,max:1e6,step:1,default:0}),ye=ct({param:"logprobs",title:h.LOG_PROBS.title,description:h.LOG_PROBS.description,default:!1}),fe=O({param:"top_logprobs",title:h.TOP_LOG_PROBS.title,description:h.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),be=le({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"]}),Nn=le({param:"response_format",title:h.RESPONSE_FORMAT.title,description:h.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]});var ft=(o,t)=>zod.z.object({temperature:pe.schema,maxTokens:me(o).schema,stop:de(t).schema,topP:ce.schema,frequencyPenalty:ue.schema,presencePenalty:ge.schema,seed:he.schema.transform(n=>n===0?void 0:n),logProbs:ye.schema,topLogProbs:fe.schema,toolChoice:be.schema}),bt=(o,t)=>({temperature:pe.def,maxTokens:me(o).def,stop:de(t).def,topP:ce.def,frequencyPenalty:ue.def,presencePenalty:ge.def,seed:he.def,logProbs:ye.def,topLogProbs:fe.def,toolChoice:be.def});var Ce={base:(o,t)=>({def:bt(o,t),schema:ft(o,t)})};var Wo="open-router",U=class{constructor(){this.version="v1";this.name=Wo;this.embeddingModelFactories={};}chatModelLiterals(){return ["__base__"]}chatModelSchemas(){return {__base__:Te}}chatModel(t){let n=D,a=Re.parse(t);return new n(Te,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 et({info:"Open Router does not support embedding models yet",cause:new Error("Open Router does not support embedding models yet")})}};U.baseUrl="https://openrouter.ai/api/v1";var Ct=zod.z.enum([I,q,E,L]),Tt={system:I,user:q,assistant:E,tool:L};var Rt=[T,_,P,S],vt=zod.z.enum([T,_,P,S]);var H=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Mt=zod.z.object({content:zod.z.array(H.extend({top_logprobs:zod.z.array(H)})).nullable(),refusal:zod.z.array(H.extend({top_logprobs:zod.z.array(H)})).nullable()}).nullable(),Zo=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()})})),Ot=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(),message:zod.z.object({role:zod.z.string(),content:zod.z.string().nullable().optional(),tool_calls:Zo.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Mt.optional(),finish_reason:zod.z.string().nullable().optional()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()}),Qo=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()})),xt=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:Qo.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Mt,finish_reason:zod.z.string().nullable().optional()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()});var en=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()})}),tn=zod.z.enum(["none","auto","required"]),on=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),nn=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()})})),ve=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),an=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()})}),sn=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)})}),rn=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(ve).min(1))}),ln=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([ve,an])).min(1))}),pn=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(ve).min(1)).optional(),tool_calls:zod.z.array(sn).min(1).optional()}),mn=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),dn=zod.z.union([rn,ln,pn,mn]),Et=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(dn).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:nn.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(en).optional(),tool_choice:tn.or(on).optional()});var Re=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),openRouterReferer:zod.z.string().optional(),openRouterTitle:zod.z.string().optional()}),D=class{constructor(t,n){this.version="v1";let a=Re.parse(n);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=z(U.baseUrl),this.streamChatUrl=z(`${this.baseUrl}/chat/completions`),this.completeChatUrl=z(`${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"},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(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(t){let n=Et.safeParse(t);if(!n.success)throw new F({info:"Invalid model request",cause:n.error});let a=n.data,s=a.model;if(a.tool_choice&&(!a.tools||a.tools.length===0))throw new F({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let r={};a.response_format&&(r.responseFormat=a.response_format.type,a.response_format.type==="json_schema"&&(r.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"?r.toolChoice=a.tool_choice:r.toolChoice=a.tool_choice.function.name),r.seed=a.seed,r.maxTokens=a.max_tokens,r.temperature=a.temperature,r.topA=a.top_a,r.topP=a.top_p,r.minP=a.min_p,r.topK=a.top_k,r.repetitionPenalty=a.repetition_penalty,r.presencePenalty=a.presence_penalty,r.frequencyPenalty=a.frequency_penalty,r.stop=a.stop,r.logProbs=a.logprobs,r.topLogProbs=a.top_logprobs;let c=ze().parse(ht(r)),p=[],d={};a.messages.forEach(g=>{let C=g.role;switch(C){case"system":{let y=g.content;if(typeof y=="string")p.push({role:C,content:[{modality:T,value:y}]});else {let f=y.map(b=>({modality:T,value:b.text}));p.push({role:C,content:f});}}break;case"user":{let y=g.content;if(typeof y=="string")p.push({role:C,content:[{modality:T,value:y}]});else {let f=y.map(b=>b.type==="text"?{modality:T,value:b.text}:b.image_url.url.startsWith("data:")?{modality:_,detail:b.image_url.detail||"auto",value:{type:W,base64:b.image_url.url,media_type:yt(b.image_url.url)}}:{modality:_,detail:b.image_url.detail||"auto",value:{type:J,url:b.image_url.url}});p.push({role:C,content:f});}}break;case"assistant":{let y=[];if(!g.content&&!g.tool_calls)throw new F({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(g.content){let f=g.content;typeof f=="string"?y.push({modality:T,value:f}):f.forEach(b=>{y.push({modality:T,value:b.text});});}g.tool_calls&&g.tool_calls.forEach((b,v)=>{let w={modality:P,id:b.id,index:v,name:b.function.name,arguments:b.function.arguments};y.push(w),d[w.id]=w;}),p.push({role:C,content:y});}break;case"tool":{let y=g;p.push({role:C,content:[{modality:S,id:y.tool_call_id,index:d[y.tool_call_id].index,name:d[y.tool_call_id].name,data:y.content}]});}break}});let u=[];return a.tools&&a.tools.forEach(g=>{u.push({type:"function",definition:{schema:{name:g.function.name,description:g.function.description||"",strict:g.function.strict,parameters:g.function.parameters}}});}),{modelName:s,config:c,messages:p,tools:u.length>0?u:void 0}}transformConfig(t,n,a){let s=t.toolChoice;delete t.toolChoice;let r=this.modelSchema.config.schema.safeParse(t);if(!r.success)throw new k({info:`Invalid config for model : '${this.modelName}'`,cause:r.error});let c=r.data;s!==void 0&&(c.toolChoice=s),Object.keys(c).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new k({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
|
|
7
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let p=Object.keys(c).reduce((d,u)=>{let g=this.modelSchema.config.def[u],C=g.param,y=c[u];return C==="max_tokens"&&g.type==="range"&&y===0?d[C]=g.max:d[C]=y,d},{});if(p.top_logprobs&&!p.logprobs)throw new k({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 d=p.tool_choice;if(!a||a&&a.length===0)throw new k({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(a&&a.length>0){let u=this.modelSchema.config.def.toolChoice;if(!u.choices.includes(d))if(a.map(g=>g.definition.schema.name).includes(d))p.tool_choice={type:"function",function:{name:d}};else throw new k({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
|
|
8
|
+
one of [${u.choices.join(", ")}]`)})}}if("response_format"in p&&p.response_format!==void 0){let d=p.response_format;if(d==="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 k({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:d};}return p}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let n=t.map(s=>{let r=Q().safeParse(s);if(!r.success)throw new M({info:"Invalid messages",cause:r.error});return r.data});return n.forEach(s=>{s.content.forEach(r=>{if(!this.modelSchema.modalities.includes(r.modality))throw new M({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${r.modality}',
|
|
9
|
+
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),n.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new M({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
|
|
10
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:n.map(s=>{switch(s.role){case I:{let r=[];return s.content.forEach(c=>{if(c.modality===T)r.push({type:"text",text:c.value});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${c.modality}'`)})}),{role:this.modelSchema.roles[s.role],content:r}}case E:{let r=[],c=[];return s.content.forEach(p=>{if(p.modality===T)r.push({type:"text",text:p.value});else if(p.modality===P)c.push({id:p.id,type:"function",function:{name:p.name,arguments:p.arguments}});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${p.modality}'`)})}),R(R({role:this.modelSchema.roles[s.role]},r.length>0?{content:r}:{}),c.length>0?{tool_calls:c}:{})}case q:{let r=[],c=[];s.content.forEach(d=>{if(d.modality===T)r.push({type:"text",text:d.value});else if(d.modality===_)c.push({type:"image_url",image_url:{url:d.value.type==="url"?d.value.url:d.value.base64,detail:d.detail}});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})});let p=[...r,...c];return {role:this.modelSchema.roles[s.role],content:p}}case L:{if(s.content.length!==1)throw new M({info:`Invalid message for role : '${s.role}'`,cause:new Error(`role : '${s.role}' must have exactly one content item`)});if(s.content[0].modality!==S)throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' must have content with modality : '${S}'`)});let r=s.content[0];return {role:this.modelSchema.roles[s.role],tool_call_id:r.id,content:r.data}}default:throw new M({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
|
|
11
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(t){if(!this.modelSchema.modalities.includes(P))throw new ne({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${P}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(s=>{let r=De().safeParse(s);if(!r.success)throw new ne({info:"Invalid tools",cause:r.error});return r.data}).map(s=>({type:"function",function:s.definition.schema}))}}getCompleteChatUrl(t,n,a){return x(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(t,n,a){return x(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(t,n,a){return x(this,null,function*(){let s=this.transformConfig(t,n,a),r=this.transformMessages(n);if(r.messages&&r.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let c=a?this.transformTools(a):{};return new Promise(p=>{p(R(R(R(R({},this.getDefaultParams()),s),r),c));})})}transformCompleteChatResponse(t){let n=Ot.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,s=[{role:E,content:[]}],r=a.choices[0].message;r.content&&s[0].content.push(te(r.content)),r.refusal&&s[0].content.push(te(r.refusal)),r.tool_calls&&r.tool_calls.forEach((u,g)=>{s[0].content.push(Ae(g,u.id,u.function.name,u.function.arguments));});let c;a.usage&&(c={promptTokens:a.usage.prompt_tokens,completionTokens:a.usage.completion_tokens,totalTokens:a.usage.total_tokens});let p=[],d=a.choices[0].logprobs;return d&&(d.content&&p.push(...d.content.map(u=>({token:u.token,logProb:u.logprob,bytes:u.bytes,topLogProbs:u.top_logprobs.map(g=>({token:g.token,logProb:g.logprob,bytes:g.bytes}))}))),d.refusal&&p.push(...d.refusal.map(u=>({token:u.token,logProb:u.logprob,bytes:u.bytes,topLogProbs:u.top_logprobs.map(g=>({token:g.token,logProb:g.logprob,bytes:g.bytes}))})))),{messages:s,usage:c,logProbs:p}}throw new N({info:"Invalid response from model",cause:n.error})}getStreamChatUrl(t,n,a){return x(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(t,n,a){return x(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(t,n,a){return x(this,null,function*(){let s=this.transformConfig(t,n,a),r=this.transformMessages(n);if(r.messages&&r.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let c=a?this.transformTools(a):{};return new Promise(p=>{p(R(R(R(R({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),r),c));})})}transformStreamChatResponseChunk(t,n){return K(this,null,function*(){var p,d;let a=n+t,s=[],r="",c=0;for(;c<a.length;){let u=a.indexOf(`
|
|
12
|
+
`,c);if(u===-1){r=a.substring(c);break}else {let g=a.substring(c,u).trim();g&&s.push(g),c=u+1;}}for(let u of s){if(u==="data: [DONE]")return;if(u.startsWith("data: ")){let g=u.substring(6);try{let C=JSON.parse(g),y=xt.safeParse(C);if(y.success){let f={partialMessages:[]},b=y.data;if(b.choices.length>0){let v=b.choices[0].delta;if(v!==void 0&&Object.keys(v).length!==0){if("content"in v&&v.content!==null)f.partialMessages.push(oe(E,v.content));else if("refusal"in v&&v.refusal!==null)f.partialMessages.push(oe(E,v.refusal));else if("tool_calls"in v&&v.tool_calls!==void 0){let w=v.tool_calls.at(0);f.partialMessages.push(Fe(E,w.index,w.id,(p=w.function)==null?void 0:p.name,(d=w.function)==null?void 0:d.arguments));}}}b.usage&&(f.usage={promptTokens:b.usage.prompt_tokens,completionTokens:b.usage.completion_tokens,totalTokens:b.usage.total_tokens}),yield {partialResponse:f,buffer:r};}else throw new N({info:"Invalid response from model",cause:y.error})}catch(C){throw new N({info:`Malformed JSON received in stream: ${g}`,cause:C})}}}yield {partialResponse:{partialMessages:[]},buffer:r};})}transformProxyStreamChatResponseChunk(t,n,a,s,r){return K(this,null,function*(){yield*Ee(this.transformStreamChatResponseChunk(t,n));})}getProxyStreamChatUrl(t,n,a){return x(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(t,n,a){return x(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(t,n,a){return x(this,null,function*(){if(!n)return {};let s=R({},n);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(t,n,a){return x(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,n,a)})}};var Te=gt(Ct,vt).parse({name:"__base__",description:"Base chat model for Open Router",maxInputTokens:128e3,maxOutputTokens:128e3,roles:Tt,modalities:Rt,config:{def:Ce.base(128e3,4).def,schema:Ce.base(128e3,4).schema}});
|
|
13
13
|
|
|
14
14
|
exports.BaseChatModel = D;
|
|
15
|
-
exports.BaseChatModelOptions =
|
|
16
|
-
exports.BaseChatModelSchema =
|
|
17
|
-
exports.ChatModelBaseConfigDef =
|
|
18
|
-
exports.ChatModelBaseConfigSchema =
|
|
15
|
+
exports.BaseChatModelOptions = Re;
|
|
16
|
+
exports.BaseChatModelSchema = Te;
|
|
17
|
+
exports.ChatModelBaseConfigDef = bt;
|
|
18
|
+
exports.ChatModelBaseConfigSchema = ft;
|
|
19
19
|
exports.OpenRouter = U;
|
|
20
|
-
exports.OpenRouterChatModelConfigs =
|
|
21
|
-
exports.frequencyPenalty =
|
|
22
|
-
exports.logProbs =
|
|
23
|
-
exports.maxTokens =
|
|
24
|
-
exports.minP =
|
|
25
|
-
exports.presencePenalty =
|
|
26
|
-
exports.repetitionPenalty =
|
|
27
|
-
exports.responseFormat =
|
|
20
|
+
exports.OpenRouterChatModelConfigs = Ce;
|
|
21
|
+
exports.frequencyPenalty = ue;
|
|
22
|
+
exports.logProbs = ye;
|
|
23
|
+
exports.maxTokens = me;
|
|
24
|
+
exports.minP = qn;
|
|
25
|
+
exports.presencePenalty = ge;
|
|
26
|
+
exports.repetitionPenalty = Ln;
|
|
27
|
+
exports.responseFormat = Nn;
|
|
28
28
|
exports.seed = he;
|
|
29
|
-
exports.stop =
|
|
30
|
-
exports.temperature =
|
|
31
|
-
exports.toolChoice =
|
|
32
|
-
exports.topA =
|
|
33
|
-
exports.topK =
|
|
29
|
+
exports.stop = de;
|
|
30
|
+
exports.temperature = pe;
|
|
31
|
+
exports.toolChoice = be;
|
|
32
|
+
exports.topA = kn;
|
|
33
|
+
exports.topK = In;
|
|
34
34
|
exports.topLogProbs = fe;
|
|
35
35
|
exports.topP = ce;
|
|
36
36
|
//# sourceMappingURL=index.js.map
|