@adaline/custom 1.2.1 → 1.2.3

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.js CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
- var le=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),cn=e=>{throw TypeError(e)};var pn=function(e,t){this[0]=e,this[1]=t;};var st=e=>{var t=e[le("asyncIterator")],o=!1,s,i={};return t==null?(t=e[le("iterator")](),s=m=>i[m]=r=>t[m](r)):(t=t.call(e),s=m=>i[m]=r=>{if(o){if(o=!1,m==="throw")throw r;return r}return o=!0,{done:!1,value:new pn(new Promise(d=>{var c=t[m](r);c instanceof Object||cn("Object expected"),d(c);}),1)}}),i[le("iterator")]=()=>i,s("next"),"throw"in t?s("throw"):i.throw=m=>{throw m},"return"in t&&s("return"),i};var V="system",W="user",j="assistant",Y="tool",un=[V,W,j,Y],ce=zod.z.enum(un),gn=[j],hn=zod.z.enum(gn),q="image",pe="base64",fn=["png","jpeg","webp","gif"],bn=zod.z.object({type:zod.z.literal(pe),base64:zod.z.string(),mediaType:zod.z.enum(fn)}),ue="url",yn=zod.z.object({type:zod.z.literal(ue),url:zod.z.string()}),Tn=zod.z.discriminatedUnion("type",[bn,yn]),_n=["low","medium","high","auto"],Pn=zod.z.enum(_n),vn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(q),detail:Pn,value:Tn,metadata:e}),mt="reasoning",dt="partial-reasoning",ct="thinking",kn="redacted",de=zod.z.object({type:zod.z.literal(ct),thinking:zod.z.string(),signature:zod.z.string()}),pt=zod.z.object({type:zod.z.literal(kn),data:zod.z.string()}),xn=zod.z.discriminatedUnion("type",[de,pt]),Mn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(mt),value:xn,metadata:e}),On=zod.z.object({type:zod.z.literal(ct),thinking:de.shape.thinking.optional(),signature:de.shape.signature.optional()}),Sn=zod.z.discriminatedUnion("type",[On,pt]),Cn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(dt),value:Sn,metadata:e}),M="text",ut=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(M),value:zod.z.string(),metadata:e}),ge="partial-text",gt=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ge),value:zod.z.string(),metadata:e}),I="tool-call",ht=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(I),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:e}),he="partial-tool-call",ft=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(he),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:e}),N="tool-response",En=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(N),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:e}),wn=[M,q,I,N,mt],bt=zod.z.enum(wn),In=(e=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[ut(e),vn(t),ht(o),En(s),Mn(i)]),Rn=[ge,he,dt];zod.z.enum(Rn);var jn=(e=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[gt(e),ft(t),Cn(o)]);var fe=(e=ce,t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),m=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:e,content:zod.z.array(In(t,o,s,i,r)),metadata:m}),be=(e=hn,t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:e,partialContent:jn(t,o,s),metadata:i}),Nn=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),it=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Ln=it.extend({topLogProbs:zod.z.array(it)}),yt=zod.z.array(Ln);zod.z.object({messages:zod.z.array(fe()),usage:Nn.optional(),logProbs:yt.optional()});var Un=zod.z.object({promptTokens:zod.z.number().nonnegative().optional(),completionTokens:zod.z.number().nonnegative().optional(),totalTokens:zod.z.number().nonnegative().optional()});zod.z.object({partialMessages:zod.z.array(be()),usage:Un.optional(),logProbs:yt.optional()});var ye=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,An=["object","array","number","string","boolean","enum"],rt=zod.z.enum(An),Gn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([rt,zod.z.array(zod.z.union([rt,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()}),$n=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(Gn),additionalProperties:zod.z.literal(!1)}),Tt=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:$n}).optional(),D="text",B="token",qn=[D,B],_t=zod.z.enum(qn),Dn=zod.z.array(zod.z.string().min(1)),Fn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Pt=(e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(D),metadata:e,requests:Dn}),zod.z.object({modality:zod.z.literal(B),metadata:e,requests:Fn})]),Te="float",Bn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),_e="base64",zn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),lt=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Te),embeddings:zod.z.array(Bn),usage:lt.optional()}),zod.z.object({encodingFormat:zod.z.literal(_e),embeddings:zod.z.array(zn),usage:lt.optional()})]);var Hn=e=>{let t=new WeakSet;return JSON.stringify(e,(o,s)=>{if(typeof s=="object"&&s!==null){if(t.has(s))return;t.add(s);}return s})},Jn=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:Hn(e),me="GatewayBaseError",F=class vt extends Error{constructor({info:t,cause:o},s){super(`[${s!=null?s:me}]: ${t}
6
- Message: ${Jn(o)}`),this.name=me,this.info=t,this.cause=o,this.name=s!=null?s:me,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof vt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Kn=zod.z.object({inputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M input tokens"),outputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M output tokens")}).describe("Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier."),Vn=zod.z.object({base:Kn.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),Wn=zod.z.object({minTokens:zod.z.number().int().nonnegative().describe("Inclusive lower token bound for this tier."),maxTokens:zod.z.number().int().nullable().optional().describe("Exclusive upper token bound; `null` means \u221E."),prices:Vn.describe("Price categories and rates for this specific token range.")}).refine(e=>e.maxTokens===null||typeof e.maxTokens=="number"&&e.maxTokens>e.minTokens,{message:"maxTokens must be > minTokens (or null for infinite).",path:["maxTokens"]}).describe("A single pricing tier defined by a token range and associated prices.");zod.z.object({modelName:zod.z.string().describe("Model name this schedule applies to."),currency:zod.z.string().default("USD").describe("Currency code (e.g., USD)."),tokenRanges:zod.z.array(Wn).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((e,t)=>{let{tokenRanges:o}=e;o[0].minTokens!==0&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let i=1;i<o.length;i++){let m=o[i-1],r=o[i];if(m.maxTokens===null){t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i-1,"maxTokens"],message:"Cannot define any tokenRanges after an infinite tier (maxTokens = null)."});break}r.minTokens!==m.maxTokens&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i,"minTokens"],message:`Tier ${i} minTokens (${r.minTokens}) must equal previous tier's maxTokens (${m.maxTokens}) for contiguity.`}),r.minTokens<m.minTokens&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i,"minTokens"],message:`tokenRanges must be sorted by ascending minTokens. Tier ${i} (${r.minTokens}) starts before Tier ${i-1} (${m.minTokens}).`});}let s=o[o.length-1];o.every(i=>i.maxTokens!==null||i===s)&&s.maxTokens!==null&&t.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",o.length-1,"maxTokens"],message:"The final tier must have maxTokens = null (representing infinity)."});}).describe("Complete pricing schedule for a single chat model, including all its token-based tiers.");var Yn="function";var Zn=zod.z.enum(["object","array","number","string","boolean","null"]),Xn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Zn.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(Xn).optional(),required:zod.z.array(zod.z.string()).optional()});var Qn=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 ea=zod.z.enum(["function"]),ta=zod.z.object({type:ea,definition:zod.z.object({schema:Qn})}),oa=[Yn];zod.z.enum(oa);var kt=(e=zod.z.undefined())=>zod.z.discriminatedUnion("type",[ta.extend({metadata:e})]),Pe=e=>ut().parse({modality:M,value:e}),xt=(e,t,o,s)=>ht().parse({modality:I,index:e,id:t,name:o,arguments:s});var ve=(e,t)=>be().parse({role:e,partialContent:gt().parse({modality:ge,value:t})}),Mt=(e,t,o,s,i)=>be().parse({role:e,partialContent:ft().parse({modality:he,index:t,id:o,name:s,arguments:i})});var na=Object.defineProperty,Ot=Object.getOwnPropertySymbols,aa=Object.prototype.hasOwnProperty,sa=Object.prototype.propertyIsEnumerable,St=(e,t,o)=>t in e?na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,Z=(e,t)=>{for(var o in t||(t={}))aa.call(t,o)&&St(e,o,t[o]);if(Ot)for(var o of Ot(t))sa.call(t,o)&&St(e,o,t[o]);return e},Ct="ProviderError",X=class Lt extends F{constructor({info:t,cause:o}){super({info:t,cause:o},Ct),this.name=Ct,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof Lt}};var Et="ModelResponseError",G=class Ut extends F{constructor({info:t,cause:o}){super({info:t,cause:o},Et),this.name=Et,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof Ut}},wt="InvalidModelRequestError",Q=class At extends F{constructor({info:t,cause:o}){super({info:t,cause:o},wt),this.name=wt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof At}},It="InvalidConfigError",$=class Gt extends F{constructor({info:t,cause:o}){super({info:t,cause:o},It),this.name=It,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Gt}},Rt="InvalidMessagesError",R=class $t extends F{constructor({info:t,cause:o}){super({info:t,cause:o},Rt),this.name=Rt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof $t}},jt="InvalidToolsError",ke=class qt extends F{constructor({info:t,cause:o}){super({info:t,cause:o},jt),this.name=jt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof qt}},Nt="InvalidEmbeddingRequestsError",Dt=class Ft extends F{constructor({info:t,cause:o}){super({info:t,cause:o},Nt),this.name=Nt,this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Ft}},xe="multi-string",Bt=zod.z.object({type:zod.z.literal(xe),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()}),ia=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),zt=e=>({def:Bt.parse(Z({type:xe},e)),schema:ia(e.max)}),Me="object-schema",Ht=zod.z.object({type:zod.z.literal(Me),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),ra=e=>e.optional(),Jt=e=>({def:Ht.parse(Z({type:Me},e)),schema:ra(e.objectSchema)}),Oe="range",Kt=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()}),la=(e,t,o,s)=>zod.z.number().min(e).max(t).step(o).default(s).optional(),L=e=>({def:Kt.parse(Z({type:Oe},e)),schema:la(e.min,e.max,e.step,e.default)}),Se="select-boolean",Vt=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()}),ma=e=>zod.z.boolean().nullable().default(e).optional(),Wt=e=>({def:Vt.parse(Z({type:Se},e)),schema:ma(e.default)}),Ce="select-string",Yt=zod.z.object({type:zod.z.literal(Ce),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())}),da=(e,t)=>zod.z.enum(t).nullable().default(e).optional(),z=e=>({def:Yt.parse(Z({type:Ce},e)),schema:da(e.default,e.choices)}),ca=[Oe,xe,Ce,Me,Se];zod.z.enum(ca);var Zt=zod.z.discriminatedUnion("type",[Kt,Bt,Yt,Vt,Ht]),f=(e=ce,t=bt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(e,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),Zt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var s,i;let m=Object.keys(o.def),r=Object.keys((i=(s=o.schema)==null?void 0:s.shape)!=null?i:{});return m.every(d=>r.includes(d))&&r.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"}),price:zod.z.custom()}),te=(e=_t)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Zt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var o,s;let i=Object.keys(t.def),m=Object.keys((s=(o=t.schema)==null?void 0:o.shape)!=null?s:{});return i.every(r=>m.includes(r))&&m.every(r=>i.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var pa={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."},ua={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."},ga={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},ha=e=>({type:"multi",title:"Stop sequence",description:`Enter up to ${e} sequences that will halt additional text output. The generated text will exclude these sequences.`}),fa={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."},ba={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."},ya={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."},Ta={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."},_a={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."},Pa={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."},va={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."},ka={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."},xa={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."},Ma={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."},Oa={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Sa={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."},Ca={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."},Ea={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."},_={TEMPERATURE:pa,MAX_TOKENS:ua,STOP:ha,TOP_A:fa,TOP_P:ba,TOP_K:ya,MIN_P:Ta,FREQUENCY_PENALTY:_a,PRESENCE_PENALTY:Pa,REPETITION_PENALTY:ka,SEED:va,LOG_PROBS:xa,TOP_LOG_PROBS:Ma,ECHO:Oa,RESPONSE_FORMAT:Sa,RESPONSE_FORMAT_WITH_SCHEMA:Ca,RESPONSE_SCHEMA:Ea,MAX_REASONING_TOKENS:ga};var Ee=e=>Object.fromEntries(Object.entries(e).filter(([t,o])=>o!=null));var Xt=e=>e.split(";")[0].split("/")[1],H=e=>e==null?void 0:e.replace(/\/$/,"");var wa=Object.defineProperty,Ia=Object.defineProperties,Ra=Object.getOwnPropertyDescriptors,Qt=Object.getOwnPropertySymbols,ja=Object.prototype.hasOwnProperty,Na=Object.prototype.propertyIsEnumerable,ne=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),La=e=>{throw TypeError(e)},eo=(e,t,o)=>t in e?wa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,O=(e,t)=>{for(var o in t||(t={}))ja.call(t,o)&&eo(e,o,t[o]);if(Qt)for(var o of Qt(t))Na.call(t,o)&&eo(e,o,t[o]);return e},ae=(e,t)=>Ia(e,Ra(t)),w=(e,t,o)=>new Promise((s,i)=>{var m=c=>{try{d(o.next(c));}catch(p){i(p);}},r=c=>{try{d(o.throw(c));}catch(p){i(p);}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(m,r);d((o=o.apply(e,t)).next());}),oo=function(e,t){this[0]=e,this[1]=t;},to=(e,t,o)=>{var s=(r,d,c,p)=>{try{var v=o[r](d),g=(d=v.value)instanceof oo,k=v.done;Promise.resolve(g?d[0]:d).then(h=>g?s(r==="return"?r:"next",d[1]?{done:h.done,value:h.value}:h,c,p):c({value:h,done:k})).catch(h=>s("throw",h,c,p));}catch(h){p(h);}},i=r=>m[r]=d=>new Promise((c,p)=>s(r,d,c,p)),m={};return o=o.apply(e,t),m[ne("asyncIterator")]=()=>m,i("next"),i("throw"),i("return"),m},Ua=e=>{var t=e[ne("asyncIterator")],o=!1,s,i={};return t==null?(t=e[ne("iterator")](),s=m=>i[m]=r=>t[m](r)):(t=t.call(e),s=m=>i[m]=r=>{if(o){if(o=!1,m==="throw")throw r;return r}return o=!0,{done:!1,value:new oo(new Promise(d=>{var c=t[m](r);c instanceof Object||La("Object expected"),d(c);}),1)}}),i[ne("iterator")]=()=>i,s("next"),"throw"in t?s("throw"):i.throw=m=>{throw m},"return"in t&&s("return"),i},no=L({param:"temperature",title:_.TEMPERATURE.title,description:_.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),ao=e=>L({param:"max_completion_tokens",title:_.MAX_TOKENS.title,description:_.MAX_TOKENS.description,min:0,max:e,step:1,default:0}),so=e=>zt({param:"stop",title:_.STOP(e).title,description:_.STOP(e).description,max:e}),io=L({param:"top_p",title:_.TOP_P.title,description:_.TOP_P.description,min:0,max:1,step:.01,default:1}),ro=L({param:"frequency_penalty",title:_.FREQUENCY_PENALTY.title,description:_.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),lo=L({param:"presence_penalty",title:_.PRESENCE_PENALTY.title,description:_.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),mo=L({param:"seed",title:_.SEED.title,description:_.SEED.description,min:0,max:1e6,step:1,default:0}),co=Wt({param:"logprobs",title:_.LOG_PROBS.title,description:_.LOG_PROBS.description,default:!1}),po=L({param:"top_logprobs",title:_.TOP_LOG_PROBS.title,description:_.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),uo=z({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"]}),Ye=(e,t)=>zod.z.object({temperature:no.schema,maxTokens:ao(e).schema,stop:so(t).schema,topP:io.schema,frequencyPenalty:ro.schema,presencePenalty:lo.schema,seed:mo.schema.transform(o=>o===0?void 0:o),logProbs:co.schema,topLogProbs:po.schema,toolChoice:uo.schema}),Ze=(e,t)=>({temperature:no.def,maxTokens:ao(e).def,stop:so(t).def,topP:io.def,frequencyPenalty:ro.def,presencePenalty:lo.def,seed:mo.def,logProbs:co.def,topLogProbs:po.def,toolChoice:uo.def}),go=Jt({param:"response_schema",title:_.RESPONSE_SCHEMA.title,description:_.RESPONSE_SCHEMA.description,objectSchema:Tt}),ho=z({param:"response_format",title:_.RESPONSE_FORMAT_WITH_SCHEMA.title,description:_.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),fo=(e,t)=>ae(O({},Ze(e,t)),{responseFormat:ho.def,responseSchema:go.def}),bo=(e,t)=>Ye(e,t).extend({responseFormat:ho.schema,responseSchema:go.schema}),yo=L({param:"temperature",title:_.TEMPERATURE.title,description:_.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),To=z({param:"reasoning_effort",title:"Reasoning Effort",description:"Constrains effort on reasoning for reasoning models. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.",default:"medium",choices:["low","medium","high"]}),Aa=(e,t)=>ae(O({},fo(e,t)),{temperature:yo.def,reasoningEffort:To.def}),Ga=(e,t)=>bo(e,t).extend({temperature:yo.schema,reasoningEffort:To.schema}),_o=z({param:"response_format",title:_.RESPONSE_FORMAT.title,description:_.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),$a=(e,t)=>ae(O({},Ze(e,t)),{responseFormat:_o.def}),qa=(e,t)=>Ye(e,t).extend({responseFormat:_o.schema}),Po=z({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),vo=e=>L({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:e,step:1,default:e}),ko=()=>zod.z.object({encodingFormat:Po.schema}),xo=()=>({encodingFormat:Po.def}),Da=e=>ko().extend({dimensions:vo(e).schema}),Fa=e=>ae(O({},xo()),{dimensions:vo(e).def}),u={base:(e,t)=>({def:Ze(e,t),schema:Ye(e,t)}),responseFormat:(e,t)=>({def:$a(e,t),schema:qa(e,t)}),responseSchema:(e,t)=>({def:fo(e,t),schema:bo(e,t)}),oSeries:(e,t)=>({def:Aa(e,t),schema:Ga(e,t)})},J={base:()=>({def:xo(),schema:ko()}),dimensions:e=>({def:Fa(e),schema:Da(e)})},x={"gpt-3.5-turbo-0125":{modelName:"gpt-3.5-turbo-0125",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gpt-3.5-turbo-1106":{modelName:"gpt-3.5-turbo-1106",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gpt-3.5-turbo":{modelName:"gpt-3.5-turbo",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gpt-4-0125-preview":{modelName:"gpt-4-0125-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:30,outputPricePerMillion:60}}}]},"gpt-4-0613":{modelName:"gpt-4-0613",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:30,outputPricePerMillion:60}}}]},"gpt-4-1106-preview":{modelName:"gpt-4-1106-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:30,outputPricePerMillion:60}}}]},"gpt-4-turbo-2024-04-09":{modelName:"gpt-4-turbo-2024-04-09",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:30}}}]},"gpt-4-turbo-preview":{modelName:"gpt-4-turbo-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:30}}}]},"gpt-4-turbo":{modelName:"gpt-4-turbo",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:30}}}]},"gpt-4":{modelName:"gpt-4",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:30,outputPricePerMillion:60}}}]},"gpt-4o-2024-05-13":{modelName:"gpt-4o-2024-05-13",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:5,outputPricePerMillion:20}}}]},"gpt-4o-2024-08-06":{modelName:"gpt-4o-2024-08-06",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gpt-4o-mini-2024-07-18":{modelName:"gpt-4o-mini-2024-07-18",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.6,outputPricePerMillion:2.4}}}]},"gpt-4o-mini":{modelName:"gpt-4o-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.6,outputPricePerMillion:2.4}}}]},"gpt-4o":{modelName:"gpt-4o",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:5,outputPricePerMillion:20}}}]},"o1-2024-12-17":{modelName:"o1-2024-12-17",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:60}}}]},o1:{modelName:"o1",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:60}}}]},"o3-mini-2025-01-31":{modelName:"o3-mini-2025-01-31",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"o3-mini":{modelName:"o3-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"o3-2025-04-16":{modelName:"o3-2025-04-16",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:40}}}]},o3:{modelName:"o3",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:40}}}]},"o4-mini-2025-04-16":{modelName:"o4-mini-2025-04-16",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"o4-mini":{modelName:"o4-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"gpt-4.1":{modelName:"gpt-4.1",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:2,outputPricePerMillion:8}}}]},"gpt-4.1-mini":{modelName:"gpt-4.1-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.4,outputPricePerMillion:1.6}}}]},"gpt-4.1-nano":{modelName:"gpt-4.1-nano",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]}},Ba="openai",Xe=class{constructor(){this.version="v1",this.name=Ba,this.chatModelFactories={[Re]:{model:gs,modelOptions:us,modelSchema:Co},[we]:{model:ls,modelOptions:rs,modelSchema:Oo},[Ie]:{model:cs,modelOptions:ds,modelSchema:So},[je]:{model:bs,modelOptions:fs,modelSchema:Eo},[Ne]:{model:_s,modelOptions:Ts,modelSchema:wo},[Le]:{model:ks,modelOptions:vs,modelSchema:Io},[Ue]:{model:Os,modelOptions:Ms,modelSchema:Ro},[Ae]:{model:Es,modelOptions:Cs,modelSchema:jo},[Ge]:{model:Rs,modelOptions:Is,modelSchema:No},[$e]:{model:Ls,modelOptions:Ns,modelSchema:Lo},[qe]:{model:Gs,modelOptions:As,modelSchema:Uo},[De]:{model:Ds,modelOptions:qs,modelSchema:Ao},[Fe]:{model:zs,modelOptions:Bs,modelSchema:Go},[ze]:{model:Ys,modelOptions:Ws,modelSchema:qo},[Je]:{model:oi,modelOptions:ti,modelSchema:Fo},[Ke]:{model:si,modelOptions:ai,modelSchema:Bo},[He]:{model:Qs,modelOptions:Xs,modelSchema:Do},[Be]:{model:Ks,modelOptions:Js,modelSchema:$o},[We]:{model:ci,modelOptions:di,modelSchema:Ho},[Ve]:{model:li,modelOptions:ri,modelSchema:zo},[Xo]:{model:ki,modelOptions:vi,modelSchema:Qo},[Yo]:{model:_i,modelOptions:Ti,modelSchema:Zo},[Jo]:{model:gi,modelOptions:ui,modelSchema:Ko},[Vo]:{model:bi,modelOptions:fi,modelSchema:Wo},[en]:{model:Oi,modelOptions:Mi,modelSchema:tn},[on]:{model:Ei,modelOptions:Ci,modelSchema:nn}},this.embeddingModelFactories={[an]:{model:Li,modelOptions:Ni,modelSchema:sn},[rn]:{model:Gi,modelOptions:Ai,modelSchema:ln},[mn]:{model:Di,modelOptions:qi,modelSchema:dn}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,t)=>(e[t]=this.chatModelFactories[t].modelSchema,e),{})}chatModel(e){let t=e.modelName;if(!(t in this.chatModelFactories))throw new X({info:`OpenAI chat model: ${t} not found`,cause:new Error(`OpenAI chat model: ${t} not found, available chat models:
7
- [${this.chatModelLiterals().join(", ")}]`)});let o=this.chatModelFactories[t].model,s=this.chatModelFactories[t].modelOptions.parse(e);return new o(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,t)=>(e[t]=this.embeddingModelFactories[t].modelSchema,e),{})}embeddingModel(e){let t=e.modelName;if(!(t in this.embeddingModelFactories))throw new X({info:`OpenAI embedding model: ${t} not found`,cause:new Error(`OpenAI embedding model: ${t} not found, available embedding models:
8
- [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[t].model,s=this.embeddingModelFactories[t].modelOptions.parse(e);return new o(s)}};Xe.baseUrl="https://api.openai.com/v1";var b=zod.z.enum([V,W,j,Y]),y={system:V,user:W,assistant:j,tool:Y},S=[M,q,I,N],C=zod.z.enum([M,q,I,N]);zod.z.enum([M]);var U=[M,I,N],A=zod.z.enum([M,I,N]),oe=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Mo=zod.z.object({content:zod.z.array(oe.extend({top_logprobs:zod.z.array(oe)})).nullable().optional(),refusal:zod.z.array(oe.extend({top_logprobs:zod.z.array(oe)})).nullable().optional()}).nullable(),za=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()})})),Ha=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(),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:za.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Mo.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()})}),Ja=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()})),Ka=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:Ja.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Mo.optional(),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()}),Va=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()})}),Wa=zod.z.enum(["none","auto","required"]),Ya=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),Za=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()})})),Qe=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),Xa=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()})}),Qa=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)})}),es=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(Qe).min(1))}),ts=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Qe,Xa])).min(1))}),os=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(Qe).min(1)).optional(),tool_calls:zod.z.array(Qa).min(1).optional()}),ns=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),as=zod.z.union([es,ts,os,ns]),ss=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(as).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_completion_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),response_format:Za.optional(),seed:zod.z.number().nullable().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),temperature:zod.z.number().min(0).max(2).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),tools:zod.z.array(Va).optional(),tool_choice:Wa.or(Ya).optional()}),P=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),T=class{constructor(e,t){this.version="v1";let o=P.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=H(o.baseUrl||Xe.baseUrl),this.streamChatUrl=H(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=H(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return O({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){let t=r=>{let d=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},p,v=0;for(;(p=d.exec(r))!==null;){let g=parseInt(p[1]),k=p[2];v+=g*c[k];}return v},o=0,s=0,i=!0;e["x-ratelimit-reset-requests"]&&(o=t(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=t(e["x-ratelimit-reset-tokens"]));let m=Math.max(o,s);return {shouldRetry:i,delayMs:m}}getTokenCount(e){return e.reduce((t,o)=>t+o.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(e){let t=ss.safeParse(e);if(!t.success)throw new Q({info:"Invalid model request",cause:t.error});let o=t.data,s=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let i={};o.response_format&&(i.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(i.responseSchema={name:o.response_format.json_schema.name,description:o.response_format.json_schema.description||"",strict:o.response_format.json_schema.strict,schema:o.response_format.json_schema.schema})),o.tool_choice&&(typeof o.tool_choice=="string"?i.toolChoice=o.tool_choice:i.toolChoice=o.tool_choice.function.name),i.seed=o.seed,i.maxTokens=o.max_completion_tokens,i.temperature=o.temperature,i.topP=o.top_p,i.presencePenalty=o.presence_penalty,i.frequencyPenalty=o.frequency_penalty,i.stop=o.stop,i.logProbs=o.logprobs,i.topLogProbs=o.top_logprobs;let m=ye().parse(Ee(i)),r=[],d={};o.messages.forEach(p=>{let v=p.role;switch(v){case"system":{let g=p.content;if(typeof g=="string")r.push({role:v,content:[{modality:M,value:g}]});else {let k=g.map(h=>({modality:M,value:h.text}));r.push({role:v,content:k});}}break;case"user":{let g=p.content;if(typeof g=="string")r.push({role:v,content:[{modality:M,value:g}]});else {let k=g.map(h=>h.type==="text"?{modality:M,value:h.text}:h.image_url.url.startsWith("data:")?{modality:q,detail:h.image_url.detail||"auto",value:{type:pe,base64:h.image_url.url,mediaType:Xt(h.image_url.url)}}:{modality:q,detail:h.image_url.detail||"auto",value:{type:ue,url:h.image_url.url}});r.push({role:v,content:k});}}break;case"assistant":{let g=[];if(!p.content&&!p.tool_calls)throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(p.content){let k=p.content;typeof k=="string"?g.push({modality:M,value:k}):k.forEach(h=>{g.push({modality:M,value:h.text});});}p.tool_calls&&p.tool_calls.forEach((k,h)=>{let E={modality:I,id:k.id,index:h,name:k.function.name,arguments:k.function.arguments};g.push(E),d[E.id]=E;}),r.push({role:v,content:g});}break;case"tool":{let g=p;r.push({role:v,content:[{modality:N,id:g.tool_call_id,index:d[g.tool_call_id].index,name:d[g.tool_call_id].name,data:g.content}]});}break}});let c=[];return o.tools&&o.tools.forEach(p=>{c.push({type:"function",definition:{schema:{name:p.function.name,description:p.function.description||"",strict:p.function.strict,parameters:p.function.parameters}}});}),{modelName:s,config:m,messages:r,tools:c.length>0?c:void 0}}transformConfig(e,t,o){let s=e.toolChoice;delete e.toolChoice;let i=this.modelSchema.config.schema.safeParse(e);if(!i.success)throw new $({info:`Invalid config for model : '${this.modelName}'`,cause:i.error});let m=i.data;s!==void 0&&(m.toolChoice=s),Object.keys(m).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new $({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
9
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((d,c)=>{let p=this.modelSchema.config.def[c],v=p.param,g=m[c];return v==="max_completion_tokens"&&p.type==="range"&&g===0?d[v]=p.max:d[v]=g,d},{});if(r.top_logprobs&&!r.logprobs)throw new $({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in r&&r.tool_choice!==void 0){let d=r.tool_choice;if(!o||o&&o.length===0)throw new $({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let c=this.modelSchema.config.def.toolChoice;if(!c.choices.includes(d))if(o.map(p=>p.definition.schema.name).includes(d))r.tool_choice={type:"function",function:{name:d}};else throw new $({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
10
- one of [${c.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let d=r.response_format;if(d==="json_schema")if("response_schema"in r)r.response_format={type:"json_schema",json_schema:r.response_schema},delete r.response_schema;else throw new $({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else r.response_format={type:d};}return r}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let t=e.map(o=>{let s=fe().safeParse(o);if(!s.success)throw new R({info:"Invalid messages",cause:s.error});return s.data});return t.forEach(o=>{o.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new R({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${s.modality}',
11
- available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),t.forEach(o=>{if(!Object.keys(this.modelSchema.roles).includes(o.role))throw new R({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${o.role}',
12
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:t.map(o=>{switch(o.role){case V:{let s=[];return o.content.forEach(i=>{if(i.modality===M)s.push({type:"text",text:i.value});else throw new R({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${o.role}' cannot have content with modality : '${i.modality}'`)})}),{role:this.modelSchema.roles[o.role],content:s}}case j:{let s=[],i=[];return o.content.forEach(m=>{if(m.modality===M)s.push({type:"text",text:m.value});else if(m.modality===I)i.push({id:m.id,type:"function",function:{name:m.name,arguments:m.arguments}});else throw new R({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${o.role}' cannot have content with modality : '${m.modality}'`)})}),O({role:this.modelSchema.roles[o.role],content:s},i.length>0?{tool_calls:i}:{})}case W:{let s=[],i=[];o.content.forEach(r=>{if(r.modality===M)s.push({type:"text",text:r.value});else if(r.modality===q)i.push({type:"image_url",image_url:{url:r.value.type==="url"?r.value.url:r.value.base64,detail:r.detail}});else throw new R({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${o.role}' cannot have content with modality : '${r.modality}'`)})});let m=[...s,...i];return {role:this.modelSchema.roles[o.role],content:m}}case Y:{if(o.content.length!==1)throw new R({info:`Invalid message for role : '${o.role}'`,cause:new Error(`role : '${o.role}' must have exactly one content item`)});if(o.content[0].modality!==N)throw new R({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${o.role}' must have content with modality : '${N}'`)});let s=o.content[0];return {role:this.modelSchema.roles[o.role],tool_call_id:s.id,content:s.data}}default:throw new R({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${o.role}' is not supported,
13
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(e){if(!this.modelSchema.modalities.includes(I))throw new ke({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${I}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(t=>{let o=kt().safeParse(t);if(!o.success)throw new ke({info:"Invalid tools",cause:o.error});return o.data}).map(t=>({type:"function",function:t.definition.schema}))}}getCompleteChatUrl(e,t,o){return w(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,o){return w(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(e,t,o){return w(this,null,function*(){let s=this.transformConfig(e,t,o),i=this.transformMessages(t);if(i.messages&&i.messages.length===0)throw new R({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(O(O(O(O({},this.getDefaultParams()),s),i),m));})})}transformCompleteChatResponse(e){let t=Ha.safeParse(e);if(t.success){if(t.data.choices.length===0)throw new G({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(t.data)}`)});let o=t.data,s=[{role:j,content:[]}],i=o.choices[0].message;i.content&&s[0].content.push(Pe(i.content)),i.refusal&&s[0].content.push(Pe(i.refusal)),i.tool_calls&&i.tool_calls.forEach((c,p)=>{s[0].content.push(xt(p,c.id,c.function.name,c.function.arguments));});let m={promptTokens:o.usage.prompt_tokens,completionTokens:o.usage.completion_tokens,totalTokens:o.usage.total_tokens},r=[],d=o.choices[0].logprobs;return d&&(d.content&&r.push(...d.content.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes,topLogProbs:c.top_logprobs.map(p=>({token:p.token,logProb:p.logprob,bytes:p.bytes}))}))),d.refusal&&r.push(...d.refusal.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes,topLogProbs:c.top_logprobs.map(p=>({token:p.token,logProb:p.logprob,bytes:p.bytes}))})))),{messages:s,usage:m,logProbs:r}}throw new G({info:"Invalid response from model",cause:t.error})}getStreamChatUrl(e,t,o){return w(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,t,o){return w(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(e,t,o){return w(this,null,function*(){let s=this.transformConfig(e,t,o),i=this.transformMessages(t);if(i.messages&&i.messages.length===0)throw new R({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(O(O(O(O({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),i),m));})})}transformStreamChatResponseChunk(e,t){return to(this,null,function*(){var o,s;let i=t+e,m=[],r="",d=0;for(;d<i.length;){let c=i.indexOf(`
14
- `,d);if(c===-1){r=i.substring(d);break}else {let p=i.substring(d,c).trim();p&&m.push(p),d=c+1;}}for(let c of m){if(c==="data: [DONE]")return;if(c.startsWith("data: ")){let p=c.substring(6);try{let v=JSON.parse(p),g=Ka.safeParse(v);if(g.success){let k={partialMessages:[]},h=g.data;if(h.choices.length>0){let E=h.choices[0].delta;if(E!==void 0&&Object.keys(E).length!==0){if("content"in E&&E.content!==null)k.partialMessages.push(ve(j,E.content));else if("refusal"in E&&E.refusal!==null)k.partialMessages.push(ve(j,E.refusal));else if("tool_calls"in E&&E.tool_calls!==void 0){let ee=E.tool_calls.at(0);k.partialMessages.push(Mt(j,ee.index,ee.id,(o=ee.function)==null?void 0:o.name,(s=ee.function)==null?void 0:s.arguments));}}}h.usage&&(k.usage={promptTokens:h.usage.prompt_tokens,completionTokens:h.usage.completion_tokens,totalTokens:h.usage.total_tokens}),yield {partialResponse:k,buffer:r};}else throw new G({info:"Invalid response from model",cause:g.error})}catch(v){throw new G({info:`Malformed JSON received in stream: ${p}`,cause:v})}}}yield {partialResponse:{partialMessages:[]},buffer:r};})}transformProxyStreamChatResponseChunk(e,t,o,s,i){return to(this,null,function*(){yield*st(Ua(this.transformStreamChatResponseChunk(e,t)));})}getProxyStreamChatUrl(e,t,o){return w(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,t,o){return w(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,t,o){return w(this,null,function*(){if(!t)return {};let s=O({},t);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(e,t,o){return w(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,o)})}getModelPricing(){if(!(this.modelName in x))throw new G({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return x[this.modelName]}},we="gpt-3.5-turbo-0125",is="The latest GPT-3.5 Turbo model with higher accuracy at responding in requested formats and a fix for a bug which caused a text encoding issue for non-English language function calls. Training data up to Sept 2021.",Oo=f(b,A).parse({name:we,description:is,maxInputTokens:4092,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema},price:x[we]}),rs=P,ls=class extends T{constructor(e){super(Oo,e);}},Ie="gpt-3.5-turbo-1106",ms="The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens. Training data up to Sept 2021.",So=f(b,A).parse({name:Ie,description:ms,maxInputTokens:4092,maxOutputTokens:16385,roles:y,modalities:U,config:{def:u.responseFormat(16385,4).def,schema:u.responseFormat(16385,4).schema},price:x[Ie]}),ds=P,cs=class extends T{constructor(e){super(So,e);}},Re="gpt-3.5-turbo",ps="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",Co=f(b,A).parse({name:Re,description:ps,maxInputTokens:4092,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema},price:x[Re]}),us=P,gs=class extends T{constructor(e){super(Co,e);}},je="gpt-4-0125-preview",hs="The latest GPT-4 model intended to reduce cases of \u201Claziness\u201D where the model doesn\u2019t complete a task. Training data up to Apr 2023.",Eo=f(b,A).parse({name:je,description:hs,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema},price:x[je]}),fs=P,bs=class extends T{constructor(e){super(Eo,e);}},Ne="gpt-4-0613",ys="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",wo=f(b,A).parse({name:Ne,description:ys,maxInputTokens:8192,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema},price:x[Ne]}),Ts=P,_s=class extends T{constructor(e){super(wo,e);}},Le="gpt-4-1106-preview",Ps="GPT-4 Turbo model featuring improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens. This preview model is not yet suited for production traffic. Training data up to Apr 2023.",Io=f(b,A).parse({name:Le,description:Ps,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema},price:x[Le]}),vs=P,ks=class extends T{constructor(e){super(Io,e);}},Ue="gpt-4.1",xs="Flagship model for complex tasks. It is well suited for problem solving across domains. Training data up to May 2024.",Ro=f(b,C).parse({name:Ue,description:xs,maxInputTokens:1047576,maxOutputTokens:32768,roles:y,modalities:S,config:{def:u.responseSchema(32768,4).def,schema:u.responseSchema(32768,4).schema},price:x[Ue]}),Ms=P,Os=class extends T{constructor(e){super(Ro,e);}},Ae="gpt-4.1-mini",Ss="Provides a balance between intelligence, speed, and cost that makes it an attractive model for many use cases. Training data up to May 2024.",jo=f(b,C).parse({name:Ae,description:Ss,maxInputTokens:1047576,maxOutputTokens:32768,roles:y,modalities:S,config:{def:u.responseSchema(32768,4).def,schema:u.responseSchema(32768,4).schema},price:x[Ae]}),Cs=P,Es=class extends T{constructor(e){super(jo,e);}},Ge="gpt-4.1-nano",ws="Fastest, most cost-effective GPT-4.1 model. Training data up to May 2024.",No=f(b,C).parse({name:Ge,description:ws,maxInputTokens:1047576,maxOutputTokens:32768,roles:y,modalities:S,config:{def:u.responseSchema(32768,4).def,schema:u.responseSchema(32768,4).schema},price:x[Ge]}),Is=P,Rs=class extends T{constructor(e){super(No,e);}},$e="gpt-4-turbo-2024-04-09",js="GPT-4 Turbo with Vision model. Vision requests can now use JSON mode and function calling. gpt-4-turbo currently points to this version. Training data up to Dec 2023.",Lo=f(b,C).parse({name:$e,description:js,maxInputTokens:128e3,maxOutputTokens:4096,roles:y,modalities:S,config:{def:u.responseFormat(4096,4).def,schema:u.responseFormat(4096,4).schema},price:x[$e]}),Ns=P,Ls=class extends T{constructor(e){super(Lo,e);}},qe="gpt-4-turbo-preview",Us="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",Uo=f(b,A).parse({name:qe,description:Us,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema},price:x[qe]}),As=P,Gs=class extends T{constructor(e){super(Uo,e);}},De="gpt-4-turbo",$s="The latest GPT-4 Turbo model with vision capabilities. Vision requests can now use JSON mode and function calling. Currently points to gpt-4-turbo-2024-04-09. Training data up to Dec 2023.",Ao=f(b,C).parse({name:De,description:$s,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema},price:x[De]}),qs=P,Ds=class extends T{constructor(e){super(Ao,e);}},Fe="gpt-4",Fs="Currently points to gpt-4-0613. Training data up to Sept 2021.",Go=f(b,A).parse({name:Fe,description:Fs,maxInputTokens:8192,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema},price:x[Fe]}),Bs=P,zs=class extends T{constructor(e){super(Go,e);}},Be="gpt-4o-2024-05-13",Hs="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",$o=f(b,C).parse({name:Be,description:Hs,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[Be]}),Js=P,Ks=class extends T{constructor(e){super($o,e);}},ze="gpt-4o-2024-08-06",Vs="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",qo=f(b,C).parse({name:ze,description:Vs,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[ze]}),Ws=P,Ys=class extends T{constructor(e){super(qo,e);}},He="gpt-4o-mini-2024-07-18",Zs="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",Do=f(b,C).parse({name:He,description:Zs,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[He]}),Xs=P,Qs=class extends T{constructor(e){super(Do,e);}},Je="gpt-4o-mini",ei="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",Fo=f(b,C).parse({name:Je,description:ei,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[Je]}),ti=P,oi=class extends T{constructor(e){super(Fo,e);}},Ke="gpt-4o",ni="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",Bo=f(b,C).parse({name:Ke,description:ni,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[Ke]}),ai=P,si=class extends T{constructor(e){super(Bo,e);}},Ve="o1-2024-12-17",ii="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",zo=f(b,C).parse({name:Ve,description:ii,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema},price:x[Ve]}),ri=P,li=class extends T{constructor(e){super(zo,e);}},We="o1",mi="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",Ho=f(b,C).parse({name:We,description:mi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema},price:x[We]}),di=P,ci=class extends T{constructor(e){super(Ho,e);}},Jo="o3-2025-04-16",pi="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",Ko=f(b,C).parse({name:Jo,description:pi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),ui=P,gi=class extends T{constructor(e){super(Ko,e);}},Vo="o3",hi="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",Wo=f(b,C).parse({name:Vo,description:hi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),fi=P,bi=class extends T{constructor(e){super(Wo,e);}},Yo="o3-mini",yi="o3-mini is the newest small reasoning model, providing high intelligence at the same cost and latency targets of o1-mini. Training data up to Sep 2023.",Zo=f(b,A).parse({name:Yo,description:yi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:U,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),Ti=P,_i=class extends T{constructor(e){super(Zo,e);}},Xo="o3-mini-2025-01-31",Pi="o3-mini is the newest small reasoning model, providing high intelligence at the same cost and latency targets of o1-mini. Training data up to Sep 2023.",Qo=f(b,A).parse({name:Xo,description:Pi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:U,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),vi=P,ki=class extends T{constructor(e){super(Qo,e);}},en="o4-mini-2025-04-16",xi="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",tn=f(b,C).parse({name:en,description:xi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),Mi=P,Oi=class extends T{constructor(e){super(tn,e);}},on="o4-mini",Si="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",nn=f(b,C).parse({name:on,description:Si,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),Ci=P,Ei=class extends T{constructor(e){super(nn,e);}},et=[D,B],tt=zod.z.enum([D,B]),wi=zod.z.object({object:zod.z.literal("list"),model:zod.z.string(),data:zod.z.array(zod.z.object({index:zod.z.number(),object:zod.z.literal("embedding"),embedding:zod.z.array(zod.z.number()).or(zod.z.string().base64())})),usage:zod.z.object({prompt_tokens:zod.z.number().nonnegative(),total_tokens:zod.z.number().nonnegative()})}),Ii=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)).or(zod.z.array(zod.z.number().int().nonnegative()).min(1)).or(zod.z.array(zod.z.array(zod.z.number().int().nonnegative()).min(1)).min(1)),Ri=zod.z.object({model:zod.z.string().min(1).optional(),input:Ii,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()}),se=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),ot=class{constructor(e,t){this.version="v1";let o=se.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=H(o.baseUrl||Xe.baseUrl),this.getEmbeddingsUrl=H(o.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let t=r=>{let d=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},p,v=0;for(;(p=d.exec(r))!==null;){let g=parseInt(p[1]),k=p[2];v+=g*c[k];}return v},o=0,s=0,i=!0;e["x-ratelimit-reset-requests"]&&(o=t(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=t(e["x-ratelimit-reset-tokens"]));let m=Math.max(o,s);return {shouldRetry:i,delayMs:m}}getTokenCount(e){return e.requests.reduce((t,o)=>t+o.length,0)}transformModelRequest(e){let t=Ri.safeParse(e);if(!t.success)throw new Q({info:"Invalid model request",cause:t.error});let o=t.data,s=o.model,i={encodingFormat:o.encoding_format,dimensions:o.dimensions},m=ye().parse(Ee(i)),r,d;return typeof o.input=="string"?d=D:typeof o.input[0]=="string"?d=D:d=B,d===D?typeof o.input=="string"?r={modality:d,requests:[o.input]}:r={modality:d,requests:o.input}:typeof o.input[0]=="number"?r={modality:d,requests:[o.input]}:r={modality:d,requests:o.input},{modelName:s,config:m,embeddingRequests:r}}transformConfig(e,t){let o=this.modelSchema.config.schema.safeParse(e);if(!o.success)throw new $({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:o.error});let s=o.data;return Object.keys(s).forEach(i=>{if(!this.modelSchema.config.def[i])throw new $({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${i}',
15
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,m)=>{let r=this.modelSchema.config.def[m].param,d=s[m];return i[r]=d,i},{})}transformEmbeddingRequests(e){let t=Pt().safeParse(e);if(!t.success)throw new Dt({info:"Invalid embedding requests",cause:t.error});return {input:t.data.requests}}getGetEmbeddingsUrl(e,t){return w(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return w(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return w(this,null,function*(){return new Promise(o=>{o(O(O(O({},this.getDefaultParams()),this.transformConfig(e,t)),this.transformEmbeddingRequests(t)));})})}transformGetEmbeddingsResponse(e){let t,o=wi.safeParse(e);if(o.success){let s=o.data;t=typeof s.data[0].embedding=="string"?_e:Te;let i=s.data.map(m=>typeof m.embedding=="string"?{index:m.index,embedding:m.embedding}:{index:m.index,embedding:m.embedding});return {encodingFormat:t,embeddings:i,usage:{totalTokens:s.usage.total_tokens}}}throw new G({info:"Invalid response from model",cause:o.error})}},an="text-embedding-ada-002",ji="Most capable 2nd generation embedding model, replacing 16 first generation models",sn=te(tt).parse({name:an,description:ji,modalities:et,maxInputTokens:8192,maxOutputTokens:1536,config:{def:J.base().def,schema:J.base().schema}}),Ni=se,Li=class extends ot{constructor(e){super(sn,e);}},rn="text-embedding-3-small",Ui="Increased performance over 2nd generation ada embedding model",ln=te(tt).parse({name:rn,description:Ui,modalities:et,maxInputTokens:8192,maxOutputTokens:1536,config:{def:J.dimensions(1536).def,schema:J.dimensions(1536).schema}}),Ai=se,Gi=class extends ot{constructor(e){super(ln,e);}},mn="text-embedding-3-large",$i="Most capable embedding model for both english and non-english tasks",dn=te(tt).parse({name:mn,description:$i,modalities:et,maxInputTokens:8192,maxOutputTokens:3072,config:{def:J.dimensions(3072).def,schema:J.dimensions(3072).schema}}),qi=se,Di=class extends ot{constructor(e){super(dn,e);}};var nt=f(b,C).parse({name:"__base__",description:"Base chat model for Custom",maxInputTokens:128e3,maxOutputTokens:128e3,roles:y,modalities:S,config:{def:u.base(128e3,4).def,schema:u.base(128e3,4).schema}});var ie=zod.z.object({apiKey:zod.z.string().min(1),modelName:zod.z.string(),baseUrl:zod.z.string().optional(),completeChatUrl:zod.z.string().optional(),streamChatUrl:zod.z.string().optional()});var re=class extends T{constructor(o,s){let i=ie.parse(s);super(o,{modelName:i.modelName,apiKey:i.apiKey,baseUrl:i.baseUrl,completeChatUrl:i.completeChatUrl,streamChatUrl:i.streamChatUrl});this.version="v1";}getModelPricing(){throw new G({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error("No pricing configuration for custom provider")})}};var Fi="custom",at=class{constructor(){this.version="v1";this.name=Fi;this.embeddingModelFactories={};}chatModelLiterals(){return ["__base__"]}chatModelSchemas(){return {__base__:nt}}chatModel(t){let o=re,s=ie.parse(t);return new o(nt,s)}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 X({info:"Custom embedding models not supported yet",cause:new Error("Custom embedding models not supported yet")})}};at.customUrl=t=>`${t}`;
5
+ var le=(e,o)=>(o=Symbol[e])?o:Symbol.for("Symbol."+e),cn=e=>{throw TypeError(e)};var pn=function(e,o){this[0]=e,this[1]=o;};var it=e=>{var o=e[le("asyncIterator")],n=!1,i,s={};return o==null?(o=e[le("iterator")](),i=m=>s[m]=r=>o[m](r)):(o=o.call(e),i=m=>s[m]=r=>{if(n){if(n=!1,m==="throw")throw r;return r}return n=!0,{done:!1,value:new pn(new Promise(d=>{var c=o[m](r);c instanceof Object||cn("Object expected"),d(c);}),1)}}),s[le("iterator")]=()=>s,i("next"),"throw"in o?i("throw"):s.throw=m=>{throw m},"return"in o&&i("return"),s};var V="system",Y="user",j="assistant",W="tool",un=[V,Y,j,W],ce=zod.z.enum(un),gn=[j],hn=zod.z.enum(gn),$="image",pe="base64",fn=["png","jpeg","webp","gif"],bn=zod.z.object({type:zod.z.literal(pe),base64:zod.z.string(),mediaType:zod.z.enum(fn)}),ue="url",yn=zod.z.object({type:zod.z.literal(ue),url:zod.z.string()}),Tn=zod.z.discriminatedUnion("type",[bn,yn]),_n=["low","medium","high","auto"],vn=zod.z.enum(_n),Pn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal($),detail:vn,value:Tn,metadata:e}),mt="reasoning",dt="partial-reasoning",ct="thinking",kn="redacted",de=zod.z.object({type:zod.z.literal(ct),thinking:zod.z.string(),signature:zod.z.string()}),pt=zod.z.object({type:zod.z.literal(kn),data:zod.z.string()}),xn=zod.z.discriminatedUnion("type",[de,pt]),Mn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(mt),value:xn,metadata:e}),On=zod.z.object({type:zod.z.literal(ct),thinking:de.shape.thinking.optional(),signature:de.shape.signature.optional()}),Sn=zod.z.discriminatedUnion("type",[On,pt]),Cn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(dt),value:Sn,metadata:e}),M="text",ut=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(M),value:zod.z.string(),metadata:e}),ge="partial-text",gt=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ge),value:zod.z.string(),metadata:e}),I="tool-call",ht=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(I),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:e}),he="partial-tool-call",ft=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(he),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:e}),N="tool-response",En=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(N),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:e}),wn=[M,$,I,N,mt],bt=zod.z.enum(wn),In=(e=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined(),i=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[ut(e),Pn(o),ht(n),En(i),Mn(s)]),Rn=[ge,he,dt];zod.z.enum(Rn);var jn=(e=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[gt(e),ft(o),Cn(n)]);var fe=(e=ce,o=zod.z.undefined(),n=zod.z.undefined(),i=zod.z.undefined(),s=zod.z.undefined(),m=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:e,content:zod.z.array(In(o,n,i,s,r)),metadata:m}),be=(e=hn,o=zod.z.undefined(),n=zod.z.undefined(),i=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:e,partialContent:jn(o,n,i),metadata:s}),Nn=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),st=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Ln=st.extend({topLogProbs:zod.z.array(st)}),yt=zod.z.array(Ln);zod.z.object({messages:zod.z.array(fe()),usage:Nn.optional(),logProbs:yt.optional()});var Un=zod.z.object({promptTokens:zod.z.number().nonnegative().optional(),completionTokens:zod.z.number().nonnegative().optional(),totalTokens:zod.z.number().nonnegative().optional()});zod.z.object({partialMessages:zod.z.array(be()),usage:Un.optional(),logProbs:yt.optional()});var ye=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,An=["object","array","number","string","boolean","enum"],rt=zod.z.enum(An),Gn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([rt,zod.z.array(zod.z.union([rt,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()}),qn=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(Gn),additionalProperties:zod.z.literal(!1)}),Tt=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:qn}).optional(),D="text",B="token",$n=[D,B],_t=zod.z.enum($n),Dn=zod.z.array(zod.z.string().min(1)),Fn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),vt=(e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(D),metadata:e,requests:Dn}),zod.z.object({modality:zod.z.literal(B),metadata:e,requests:Fn})]),Te="float",Bn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),_e="base64",zn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),lt=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Te),embeddings:zod.z.array(Bn),usage:lt.optional()}),zod.z.object({encodingFormat:zod.z.literal(_e),embeddings:zod.z.array(zn),usage:lt.optional()})]);var Hn=e=>{let o=new WeakSet;return JSON.stringify(e,(n,i)=>{if(typeof i=="object"&&i!==null){if(o.has(i))return;o.add(i);}return i})},Jn=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:Hn(e),me="GatewayBaseError",F=class Pt extends Error{constructor({info:o,cause:n},i){super(`[${i!=null?i:me}]: ${o}
6
+ Message: ${Jn(n)}`),this.name=me,this.info=o,this.cause=n,this.name=i!=null?i:me,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(o){return o instanceof Pt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Kn=zod.z.object({inputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M input tokens"),outputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M output tokens")}).describe("Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier."),Vn=zod.z.object({base:Kn.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),Yn=zod.z.object({minTokens:zod.z.number().int().nonnegative().describe("Inclusive lower token bound for this tier."),maxTokens:zod.z.number().int().nullable().optional().describe("Exclusive upper token bound; `null` means \u221E."),prices:Vn.describe("Price categories and rates for this specific token range.")}).refine(e=>e.maxTokens===null||typeof e.maxTokens=="number"&&e.maxTokens>e.minTokens,{message:"maxTokens must be > minTokens (or null for infinite).",path:["maxTokens"]}).describe("A single pricing tier defined by a token range and associated prices.");zod.z.object({modelName:zod.z.string().describe("Model name this schedule applies to."),currency:zod.z.string().default("USD").describe("Currency code (e.g., USD)."),tokenRanges:zod.z.array(Yn).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((e,o)=>{let{tokenRanges:n}=e;n[0].minTokens!==0&&o.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let s=1;s<n.length;s++){let m=n[s-1],r=n[s];if(m.maxTokens===null){o.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",s-1,"maxTokens"],message:"Cannot define any tokenRanges after an infinite tier (maxTokens = null)."});break}r.minTokens!==m.maxTokens&&o.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",s,"minTokens"],message:`Tier ${s} minTokens (${r.minTokens}) must equal previous tier's maxTokens (${m.maxTokens}) for contiguity.`}),r.minTokens<m.minTokens&&o.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",s,"minTokens"],message:`tokenRanges must be sorted by ascending minTokens. Tier ${s} (${r.minTokens}) starts before Tier ${s-1} (${m.minTokens}).`});}let i=n[n.length-1];n.every(s=>s.maxTokens!==null||s===i)&&i.maxTokens!==null&&o.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",n.length-1,"maxTokens"],message:"The final tier must have maxTokens = null (representing infinity)."});}).describe("Complete pricing schedule for a single chat model, including all its token-based tiers.");var Wn="function";var Zn=zod.z.enum(["object","array","number","string","boolean","null"]),Xn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Zn.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(Xn).optional(),required:zod.z.array(zod.z.string()).optional()});var Qn=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 ea=zod.z.enum(["function"]),ta=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),oa=zod.z.object({type:zod.z.literal("http"),method:zod.z.enum(["get","post"]),url:zod.z.string().url(),headers:zod.z.record(zod.z.string()).optional(),query:zod.z.record(zod.z.string()).optional(),body:zod.z.record(zod.z.any()).optional(),proxyUrl:zod.z.string().url().optional(),proxyHeaders:zod.z.record(zod.z.string()).optional(),retry:ta.optional()}),na=zod.z.discriminatedUnion("type",[oa]),aa=zod.z.object({type:ea,definition:zod.z.object({schema:Qn}),apiSettings:na.optional()}),ia=[Wn];zod.z.enum(ia);var kt=(e=zod.z.undefined())=>zod.z.discriminatedUnion("type",[aa.extend({metadata:e})]),ve=e=>ut().parse({modality:M,value:e}),xt=(e,o,n,i)=>ht().parse({modality:I,index:e,id:o,name:n,arguments:i});var Pe=(e,o)=>be().parse({role:e,partialContent:gt().parse({modality:ge,value:o})}),Mt=(e,o,n,i,s)=>be().parse({role:e,partialContent:ft().parse({modality:he,index:o,id:n,name:i,arguments:s})});var sa=Object.defineProperty,Ot=Object.getOwnPropertySymbols,ra=Object.prototype.hasOwnProperty,la=Object.prototype.propertyIsEnumerable,St=(e,o,n)=>o in e?sa(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,Z=(e,o)=>{for(var n in o||(o={}))ra.call(o,n)&&St(e,n,o[n]);if(Ot)for(var n of Ot(o))la.call(o,n)&&St(e,n,o[n]);return e},Ct="ProviderError",X=class Lt extends F{constructor({info:o,cause:n}){super({info:o,cause:n},Ct),this.name=Ct,this.info=o,this.cause=n;}static isProviderError(o){return o instanceof Lt}};var Et="ModelResponseError",G=class Ut extends F{constructor({info:o,cause:n}){super({info:o,cause:n},Et),this.name=Et,this.cause=n,this.info=o;}static isModelResponseError(o){return o instanceof Ut}},wt="InvalidModelRequestError",Q=class At extends F{constructor({info:o,cause:n}){super({info:o,cause:n},wt),this.name=wt,this.cause=n,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(o){return o instanceof At}},It="InvalidConfigError",q=class Gt extends F{constructor({info:o,cause:n}){super({info:o,cause:n},It),this.name=It,this.cause=n,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(o){return o instanceof Gt}},Rt="InvalidMessagesError",R=class qt extends F{constructor({info:o,cause:n}){super({info:o,cause:n},Rt),this.name=Rt,this.cause=n,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(o){return o instanceof qt}},jt="InvalidToolsError",ke=class $t extends F{constructor({info:o,cause:n}){super({info:o,cause:n},jt),this.name=jt,this.cause=n,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(o){return o instanceof $t}},Nt="InvalidEmbeddingRequestsError",Dt=class Ft extends F{constructor({info:o,cause:n}){super({info:o,cause:n},Nt),this.name=Nt,this.info=o,this.cause=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(o){return o instanceof Ft}},xe="multi-string",Bt=zod.z.object({type:zod.z.literal(xe),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()}),ma=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),zt=e=>({def:Bt.parse(Z({type:xe},e)),schema:ma(e.max)}),Me="object-schema",Ht=zod.z.object({type:zod.z.literal(Me),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),da=e=>e.optional(),Jt=e=>({def:Ht.parse(Z({type:Me},e)),schema:da(e.objectSchema)}),Oe="range",Kt=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()}),ca=(e,o,n,i)=>zod.z.number().min(e).max(o).step(n).default(i).optional(),L=e=>({def:Kt.parse(Z({type:Oe},e)),schema:ca(e.min,e.max,e.step,e.default)}),Se="select-boolean",Vt=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()}),pa=e=>zod.z.boolean().nullable().default(e).optional(),Yt=e=>({def:Vt.parse(Z({type:Se},e)),schema:pa(e.default)}),Ce="select-string",Wt=zod.z.object({type:zod.z.literal(Ce),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())}),ua=(e,o)=>zod.z.enum(o).nullable().default(e).optional(),z=e=>({def:Wt.parse(Z({type:Ce},e)),schema:ua(e.default,e.choices)}),ga=[Oe,xe,Ce,Me,Se];zod.z.enum(ga);var Zt=zod.z.discriminatedUnion("type",[Kt,Bt,Wt,Vt,Ht]),f=(e=ce,o=bt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(e,zod.z.string().min(1).optional()),modalities:zod.z.array(o).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),Zt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(n=>{var i,s;let m=Object.keys(n.def),r=Object.keys((s=(i=n.schema)==null?void 0:i.shape)!=null?s:{});return m.every(d=>r.includes(d))&&r.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"}),price:zod.z.custom()}),te=(e=_t)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Zt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var n,i;let s=Object.keys(o.def),m=Object.keys((i=(n=o.schema)==null?void 0:n.shape)!=null?i:{});return s.every(r=>m.includes(r))&&m.every(r=>s.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var ha={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."},fa={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."},ba={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},ya=e=>({type:"multi",title:"Stop sequence",description:`Enter up to ${e} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Ta={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."},_a={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."},va={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."},Pa={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."},ka={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."},xa={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."},Ma={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."},Oa={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."},Sa={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."},Ca={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."},Ea={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},wa={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."},Ia={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."},Ra={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."},_={TEMPERATURE:ha,MAX_TOKENS:fa,STOP:ya,TOP_A:Ta,TOP_P:_a,TOP_K:va,MIN_P:Pa,FREQUENCY_PENALTY:ka,PRESENCE_PENALTY:xa,REPETITION_PENALTY:Oa,SEED:Ma,LOG_PROBS:Sa,TOP_LOG_PROBS:Ca,ECHO:Ea,RESPONSE_FORMAT:wa,RESPONSE_FORMAT_WITH_SCHEMA:Ia,RESPONSE_SCHEMA:Ra,MAX_REASONING_TOKENS:ba};var Ee=e=>Object.fromEntries(Object.entries(e).filter(([o,n])=>n!=null));var Xt=e=>e.split(";")[0].split("/")[1],H=e=>e==null?void 0:e.replace(/\/$/,"");var ja=Object.defineProperty,Na=Object.defineProperties,La=Object.getOwnPropertyDescriptors,Qt=Object.getOwnPropertySymbols,Ua=Object.prototype.hasOwnProperty,Aa=Object.prototype.propertyIsEnumerable,ne=(e,o)=>(o=Symbol[e])?o:Symbol.for("Symbol."+e),Ga=e=>{throw TypeError(e)},eo=(e,o,n)=>o in e?ja(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,O=(e,o)=>{for(var n in o||(o={}))Ua.call(o,n)&&eo(e,n,o[n]);if(Qt)for(var n of Qt(o))Aa.call(o,n)&&eo(e,n,o[n]);return e},ae=(e,o)=>Na(e,La(o)),w=(e,o,n)=>new Promise((i,s)=>{var m=c=>{try{d(n.next(c));}catch(p){s(p);}},r=c=>{try{d(n.throw(c));}catch(p){s(p);}},d=c=>c.done?i(c.value):Promise.resolve(c.value).then(m,r);d((n=n.apply(e,o)).next());}),oo=function(e,o){this[0]=e,this[1]=o;},to=(e,o,n)=>{var i=(r,d,c,p)=>{try{var P=n[r](d),g=(d=P.value)instanceof oo,k=P.done;Promise.resolve(g?d[0]:d).then(h=>g?i(r==="return"?r:"next",d[1]?{done:h.done,value:h.value}:h,c,p):c({value:h,done:k})).catch(h=>i("throw",h,c,p));}catch(h){p(h);}},s=r=>m[r]=d=>new Promise((c,p)=>i(r,d,c,p)),m={};return n=n.apply(e,o),m[ne("asyncIterator")]=()=>m,s("next"),s("throw"),s("return"),m},qa=e=>{var o=e[ne("asyncIterator")],n=!1,i,s={};return o==null?(o=e[ne("iterator")](),i=m=>s[m]=r=>o[m](r)):(o=o.call(e),i=m=>s[m]=r=>{if(n){if(n=!1,m==="throw")throw r;return r}return n=!0,{done:!1,value:new oo(new Promise(d=>{var c=o[m](r);c instanceof Object||Ga("Object expected"),d(c);}),1)}}),s[ne("iterator")]=()=>s,i("next"),"throw"in o?i("throw"):s.throw=m=>{throw m},"return"in o&&i("return"),s},no=L({param:"temperature",title:_.TEMPERATURE.title,description:_.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),ao=e=>L({param:"max_completion_tokens",title:_.MAX_TOKENS.title,description:_.MAX_TOKENS.description,min:0,max:e,step:1,default:0}),io=e=>zt({param:"stop",title:_.STOP(e).title,description:_.STOP(e).description,max:e}),so=L({param:"top_p",title:_.TOP_P.title,description:_.TOP_P.description,min:0,max:1,step:.01,default:1}),ro=L({param:"frequency_penalty",title:_.FREQUENCY_PENALTY.title,description:_.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),lo=L({param:"presence_penalty",title:_.PRESENCE_PENALTY.title,description:_.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),mo=L({param:"seed",title:_.SEED.title,description:_.SEED.description,min:0,max:1e6,step:1,default:0}),co=Yt({param:"logprobs",title:_.LOG_PROBS.title,description:_.LOG_PROBS.description,default:!1}),po=L({param:"top_logprobs",title:_.TOP_LOG_PROBS.title,description:_.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),uo=z({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"]}),We=(e,o)=>zod.z.object({temperature:no.schema,maxTokens:ao(e).schema,stop:io(o).schema,topP:so.schema,frequencyPenalty:ro.schema,presencePenalty:lo.schema,seed:mo.schema.transform(n=>n===0?void 0:n),logProbs:co.schema,topLogProbs:po.schema,toolChoice:uo.schema}),Ze=(e,o)=>({temperature:no.def,maxTokens:ao(e).def,stop:io(o).def,topP:so.def,frequencyPenalty:ro.def,presencePenalty:lo.def,seed:mo.def,logProbs:co.def,topLogProbs:po.def,toolChoice:uo.def}),go=Jt({param:"response_schema",title:_.RESPONSE_SCHEMA.title,description:_.RESPONSE_SCHEMA.description,objectSchema:Tt}),ho=z({param:"response_format",title:_.RESPONSE_FORMAT_WITH_SCHEMA.title,description:_.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),fo=(e,o)=>ae(O({},Ze(e,o)),{responseFormat:ho.def,responseSchema:go.def}),bo=(e,o)=>We(e,o).extend({responseFormat:ho.schema,responseSchema:go.schema}),yo=L({param:"temperature",title:_.TEMPERATURE.title,description:_.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),To=z({param:"reasoning_effort",title:"Reasoning Effort",description:"Constrains effort on reasoning for reasoning models. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.",default:"medium",choices:["low","medium","high"]}),$a=(e,o)=>ae(O({},fo(e,o)),{temperature:yo.def,reasoningEffort:To.def}),Da=(e,o)=>bo(e,o).extend({temperature:yo.schema,reasoningEffort:To.schema}),_o=z({param:"response_format",title:_.RESPONSE_FORMAT.title,description:_.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),Fa=(e,o)=>ae(O({},Ze(e,o)),{responseFormat:_o.def}),Ba=(e,o)=>We(e,o).extend({responseFormat:_o.schema}),vo=z({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),Po=e=>L({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:e,step:1,default:e}),ko=()=>zod.z.object({encodingFormat:vo.schema}),xo=()=>({encodingFormat:vo.def}),za=e=>ko().extend({dimensions:Po(e).schema}),Ha=e=>ae(O({},xo()),{dimensions:Po(e).def}),u={base:(e,o)=>({def:Ze(e,o),schema:We(e,o)}),responseFormat:(e,o)=>({def:Fa(e,o),schema:Ba(e,o)}),responseSchema:(e,o)=>({def:fo(e,o),schema:bo(e,o)}),oSeries:(e,o)=>({def:$a(e,o),schema:Da(e,o)})},J={base:()=>({def:xo(),schema:ko()}),dimensions:e=>({def:Ha(e),schema:za(e)})},x={"gpt-3.5-turbo-0125":{modelName:"gpt-3.5-turbo-0125",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gpt-3.5-turbo-1106":{modelName:"gpt-3.5-turbo-1106",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gpt-3.5-turbo":{modelName:"gpt-3.5-turbo",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gpt-4-0125-preview":{modelName:"gpt-4-0125-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:30,outputPricePerMillion:60}}}]},"gpt-4-0613":{modelName:"gpt-4-0613",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:30,outputPricePerMillion:60}}}]},"gpt-4-1106-preview":{modelName:"gpt-4-1106-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:30,outputPricePerMillion:60}}}]},"gpt-4-turbo-2024-04-09":{modelName:"gpt-4-turbo-2024-04-09",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:30}}}]},"gpt-4-turbo-preview":{modelName:"gpt-4-turbo-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:30}}}]},"gpt-4-turbo":{modelName:"gpt-4-turbo",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:30}}}]},"gpt-4":{modelName:"gpt-4",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:30,outputPricePerMillion:60}}}]},"gpt-4o-2024-05-13":{modelName:"gpt-4o-2024-05-13",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:5,outputPricePerMillion:20}}}]},"gpt-4o-2024-08-06":{modelName:"gpt-4o-2024-08-06",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gpt-4o-mini-2024-07-18":{modelName:"gpt-4o-mini-2024-07-18",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.6,outputPricePerMillion:2.4}}}]},"gpt-4o-mini":{modelName:"gpt-4o-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.6,outputPricePerMillion:2.4}}}]},"gpt-4o":{modelName:"gpt-4o",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:5,outputPricePerMillion:20}}}]},"o1-2024-12-17":{modelName:"o1-2024-12-17",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:60}}}]},o1:{modelName:"o1",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:60}}}]},"o3-mini-2025-01-31":{modelName:"o3-mini-2025-01-31",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"o3-mini":{modelName:"o3-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"o3-2025-04-16":{modelName:"o3-2025-04-16",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:40}}}]},o3:{modelName:"o3",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:10,outputPricePerMillion:40}}}]},"o4-mini-2025-04-16":{modelName:"o4-mini-2025-04-16",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"o4-mini":{modelName:"o4-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"gpt-4.1":{modelName:"gpt-4.1",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:2,outputPricePerMillion:8}}}]},"gpt-4.1-mini":{modelName:"gpt-4.1-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.4,outputPricePerMillion:1.6}}}]},"gpt-4.1-nano":{modelName:"gpt-4.1-nano",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]}},Ja="openai",Xe=class{constructor(){this.version="v1",this.name=Ja,this.chatModelFactories={[Re]:{model:bi,modelOptions:fi,modelSchema:Co},[we]:{model:ci,modelOptions:di,modelSchema:Oo},[Ie]:{model:gi,modelOptions:ui,modelSchema:So},[je]:{model:_i,modelOptions:Ti,modelSchema:Eo},[Ne]:{model:ki,modelOptions:Pi,modelSchema:wo},[Le]:{model:Oi,modelOptions:Mi,modelSchema:Io},[Ue]:{model:Ei,modelOptions:Ci,modelSchema:Ro},[Ae]:{model:Ri,modelOptions:Ii,modelSchema:jo},[Ge]:{model:Li,modelOptions:Ni,modelSchema:No},[qe]:{model:Gi,modelOptions:Ai,modelSchema:Lo},[$e]:{model:Di,modelOptions:$i,modelSchema:Uo},[De]:{model:zi,modelOptions:Bi,modelSchema:Ao},[Fe]:{model:Ki,modelOptions:Ji,modelSchema:Go},[ze]:{model:Qi,modelOptions:Xi,modelSchema:$o},[Je]:{model:is,modelOptions:as,modelSchema:Fo},[Ke]:{model:ls,modelOptions:rs,modelSchema:Bo},[He]:{model:os,modelOptions:ts,modelSchema:Do},[Be]:{model:Wi,modelOptions:Yi,modelSchema:qo},[Ye]:{model:gs,modelOptions:us,modelSchema:Ho},[Ve]:{model:cs,modelOptions:ds,modelSchema:zo},[Xo]:{model:Os,modelOptions:Ms,modelSchema:Qo},[Wo]:{model:ks,modelOptions:Ps,modelSchema:Zo},[Jo]:{model:bs,modelOptions:fs,modelSchema:Ko},[Vo]:{model:_s,modelOptions:Ts,modelSchema:Yo},[en]:{model:Es,modelOptions:Cs,modelSchema:tn},[on]:{model:Rs,modelOptions:Is,modelSchema:nn}},this.embeddingModelFactories={[an]:{model:Gs,modelOptions:As,modelSchema:sn},[rn]:{model:Ds,modelOptions:$s,modelSchema:ln},[mn]:{model:zs,modelOptions:Bs,modelSchema:dn}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}chatModel(e){let o=e.modelName;if(!(o in this.chatModelFactories))throw new X({info:`OpenAI chat model: ${o} not found`,cause:new Error(`OpenAI chat model: ${o} not found, available chat models:
7
+ [${this.chatModelLiterals().join(", ")}]`)});let n=this.chatModelFactories[o].model,i=this.chatModelFactories[o].modelOptions.parse(e);return new n(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,o)=>(e[o]=this.embeddingModelFactories[o].modelSchema,e),{})}embeddingModel(e){let o=e.modelName;if(!(o in this.embeddingModelFactories))throw new X({info:`OpenAI embedding model: ${o} not found`,cause:new Error(`OpenAI embedding model: ${o} not found, available embedding models:
8
+ [${this.embeddingModelLiterals().join(", ")}]`)});let n=this.embeddingModelFactories[o].model,i=this.embeddingModelFactories[o].modelOptions.parse(e);return new n(i)}};Xe.baseUrl="https://api.openai.com/v1";var b=zod.z.enum([V,Y,j,W]),y={system:V,user:Y,assistant:j,tool:W},S=[M,$,I,N],C=zod.z.enum([M,$,I,N]);zod.z.enum([M]);var U=[M,I,N],A=zod.z.enum([M,I,N]),oe=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Mo=zod.z.object({content:zod.z.array(oe.extend({top_logprobs:zod.z.array(oe)})).nullable().optional(),refusal:zod.z.array(oe.extend({top_logprobs:zod.z.array(oe)})).nullable().optional()}).nullable(),Ka=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()})})),Va=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(),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:Ka.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Mo.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()})}),Ya=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()})),Wa=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:Ya.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Mo.optional(),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()}),Za=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()})}),Xa=zod.z.enum(["none","auto","required"]),Qa=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),ei=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()})})),Qe=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),ti=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()})}),oi=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)})}),ni=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(Qe).min(1))}),ai=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Qe,ti])).min(1))}),ii=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(Qe).min(1)).optional(),tool_calls:zod.z.array(oi).min(1).optional()}),si=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),ri=zod.z.union([ni,ai,ii,si]),li=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(ri).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_completion_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),response_format:ei.optional(),seed:zod.z.number().nullable().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),temperature:zod.z.number().min(0).max(2).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),tools:zod.z.array(Za).optional(),tool_choice:Xa.or(Qa).optional()}),v=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),T=class{constructor(e,o){this.version="v1";let n=v.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=H(n.baseUrl||Xe.baseUrl),this.streamChatUrl=H(n.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=H(n.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=n.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return O({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){let o=r=>{let d=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},p,P=0;for(;(p=d.exec(r))!==null;){let g=parseInt(p[1]),k=p[2];P+=g*c[k];}return P},n=0,i=0,s=!0;e["x-ratelimit-reset-requests"]&&(n=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(i=o(e["x-ratelimit-reset-tokens"]));let m=Math.max(n,i);return {shouldRetry:s,delayMs:m}}getTokenCount(e){return e.reduce((o,n)=>o+n.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformModelRequest(e){let o=li.safeParse(e);if(!o.success)throw new Q({info:"Invalid model request",cause:o.error});let n=o.data,i=n.model;if(n.tool_choice&&(!n.tools||n.tools.length===0))throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let s={};n.response_format&&(s.responseFormat=n.response_format.type,n.response_format.type==="json_schema"&&(s.responseSchema={name:n.response_format.json_schema.name,description:n.response_format.json_schema.description||"",strict:n.response_format.json_schema.strict,schema:n.response_format.json_schema.schema})),n.tool_choice&&(typeof n.tool_choice=="string"?s.toolChoice=n.tool_choice:s.toolChoice=n.tool_choice.function.name),s.seed=n.seed,s.maxTokens=n.max_completion_tokens,s.temperature=n.temperature,s.topP=n.top_p,s.presencePenalty=n.presence_penalty,s.frequencyPenalty=n.frequency_penalty,s.stop=n.stop,s.logProbs=n.logprobs,s.topLogProbs=n.top_logprobs;let m=ye().parse(Ee(s)),r=[],d={};n.messages.forEach(p=>{let P=p.role;switch(P){case"system":{let g=p.content;if(typeof g=="string")r.push({role:P,content:[{modality:M,value:g}]});else {let k=g.map(h=>({modality:M,value:h.text}));r.push({role:P,content:k});}}break;case"user":{let g=p.content;if(typeof g=="string")r.push({role:P,content:[{modality:M,value:g}]});else {let k=g.map(h=>h.type==="text"?{modality:M,value:h.text}:h.image_url.url.startsWith("data:")?{modality:$,detail:h.image_url.detail||"auto",value:{type:pe,base64:h.image_url.url,mediaType:Xt(h.image_url.url)}}:{modality:$,detail:h.image_url.detail||"auto",value:{type:ue,url:h.image_url.url}});r.push({role:P,content:k});}}break;case"assistant":{let g=[];if(!p.content&&!p.tool_calls)throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(p.content){let k=p.content;typeof k=="string"?g.push({modality:M,value:k}):k.forEach(h=>{g.push({modality:M,value:h.text});});}p.tool_calls&&p.tool_calls.forEach((k,h)=>{let E={modality:I,id:k.id,index:h,name:k.function.name,arguments:k.function.arguments};g.push(E),d[E.id]=E;}),r.push({role:P,content:g});}break;case"tool":{let g=p;r.push({role:P,content:[{modality:N,id:g.tool_call_id,index:d[g.tool_call_id].index,name:d[g.tool_call_id].name,data:g.content}]});}break}});let c=[];return n.tools&&n.tools.forEach(p=>{c.push({type:"function",definition:{schema:{name:p.function.name,description:p.function.description||"",strict:p.function.strict,parameters:p.function.parameters}}});}),{modelName:i,config:m,messages:r,tools:c.length>0?c:void 0}}transformConfig(e,o,n){let i=e.toolChoice;delete e.toolChoice;let s=this.modelSchema.config.schema.safeParse(e);if(!s.success)throw new q({info:`Invalid config for model : '${this.modelName}'`,cause:s.error});let m=s.data;i!==void 0&&(m.toolChoice=i),Object.keys(m).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
9
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((d,c)=>{let p=this.modelSchema.config.def[c],P=p.param,g=m[c];return P==="max_completion_tokens"&&p.type==="range"&&g===0?d[P]=p.max:d[P]=g,d},{});if(r.top_logprobs&&!r.logprobs)throw new q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in r&&r.tool_choice!==void 0){let d=r.tool_choice;if(!n||n&&n.length===0)throw new q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(n&&n.length>0){let c=this.modelSchema.config.def.toolChoice;if(!c.choices.includes(d))if(n.map(p=>p.definition.schema.name).includes(d))r.tool_choice={type:"function",function:{name:d}};else throw new q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
10
+ one of [${c.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let d=r.response_format;if(d==="json_schema")if("response_schema"in r)r.response_format={type:"json_schema",json_schema:r.response_schema},delete r.response_schema;else throw new q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else r.response_format={type:d};}return r}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let o=e.map(n=>{let i=fe().safeParse(n);if(!i.success)throw new R({info:"Invalid messages",cause:i.error});return i.data});return o.forEach(n=>{n.content.forEach(i=>{if(!this.modelSchema.modalities.includes(i.modality))throw new R({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${i.modality}',
11
+ available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(n=>{if(!Object.keys(this.modelSchema.roles).includes(n.role))throw new R({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${n.role}',
12
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:o.map(n=>{switch(n.role){case V:{let i=[];return n.content.forEach(s=>{if(s.modality===M)i.push({type:"text",text:s.value});else throw new R({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${s.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:i}}case j:{let i=[],s=[];return n.content.forEach(m=>{if(m.modality===M)i.push({type:"text",text:m.value});else if(m.modality===I)s.push({id:m.id,type:"function",function:{name:m.name,arguments:m.arguments}});else throw new R({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${m.modality}'`)})}),O({role:this.modelSchema.roles[n.role],content:i},s.length>0?{tool_calls:s}:{})}case Y:{let i=[],s=[];n.content.forEach(r=>{if(r.modality===M)i.push({type:"text",text:r.value});else if(r.modality===$)s.push({type:"image_url",image_url:{url:r.value.type==="url"?r.value.url:r.value.base64,detail:r.detail}});else throw new R({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${r.modality}'`)})});let m=[...i,...s];return {role:this.modelSchema.roles[n.role],content:m}}case W:{if(n.content.length!==1)throw new R({info:`Invalid message for role : '${n.role}'`,cause:new Error(`role : '${n.role}' must have exactly one content item`)});if(n.content[0].modality!==N)throw new R({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' must have content with modality : '${N}'`)});let i=n.content[0];return {role:this.modelSchema.roles[n.role],tool_call_id:i.id,content:i.data}}default:throw new R({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' is not supported,
13
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(e){if(!this.modelSchema.modalities.includes(I))throw new ke({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${I}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(o=>{let n=kt().safeParse(o);if(!n.success)throw new ke({info:"Invalid tools",cause:n.error});return n.data}).map(o=>({type:"function",function:o.definition.schema}))}}getCompleteChatUrl(e,o,n){return w(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,n){return w(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getCompleteChatData(e,o,n){return w(this,null,function*(){let i=this.transformConfig(e,o,n),s=this.transformMessages(o);if(s.messages&&s.messages.length===0)throw new R({info:"Messages are required",cause:new Error("Messages are required")});let m=n?this.transformTools(n):{};return new Promise(r=>{r(O(O(O(O({},this.getDefaultParams()),i),s),m));})})}transformCompleteChatResponse(e){let o=Va.safeParse(e);if(o.success){if(o.data.choices.length===0)throw new G({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(o.data)}`)});let n=o.data,i=[{role:j,content:[]}],s=n.choices[0].message;s.content&&i[0].content.push(ve(s.content)),s.refusal&&i[0].content.push(ve(s.refusal)),s.tool_calls&&s.tool_calls.forEach((c,p)=>{i[0].content.push(xt(p,c.id,c.function.name,c.function.arguments));});let m={promptTokens:n.usage.prompt_tokens,completionTokens:n.usage.completion_tokens,totalTokens:n.usage.total_tokens},r=[],d=n.choices[0].logprobs;return d&&(d.content&&r.push(...d.content.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes,topLogProbs:c.top_logprobs.map(p=>({token:p.token,logProb:p.logprob,bytes:p.bytes}))}))),d.refusal&&r.push(...d.refusal.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes,topLogProbs:c.top_logprobs.map(p=>({token:p.token,logProb:p.logprob,bytes:p.bytes}))})))),{messages:i,usage:m,logProbs:r}}throw new G({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,n){return w(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(e,o,n){return w(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getStreamChatData(e,o,n){return w(this,null,function*(){let i=this.transformConfig(e,o,n),s=this.transformMessages(o);if(s.messages&&s.messages.length===0)throw new R({info:"Messages are required",cause:new Error("Messages are required")});let m=n?this.transformTools(n):{};return new Promise(r=>{r(O(O(O(O({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),i),s),m));})})}transformStreamChatResponseChunk(e,o){return to(this,null,function*(){var n,i;let s=o+e,m=[],r="",d=0;for(;d<s.length;){let c=s.indexOf(`
14
+ `,d);if(c===-1){r=s.substring(d);break}else {let p=s.substring(d,c).trim();p&&m.push(p),d=c+1;}}for(let c of m){if(c==="data: [DONE]")return;if(c.startsWith("data: ")){let p=c.substring(6);try{let P=JSON.parse(p),g=Wa.safeParse(P);if(g.success){let k={partialMessages:[]},h=g.data;if(h.choices.length>0){let E=h.choices[0].delta;if(E!==void 0&&Object.keys(E).length!==0){if("content"in E&&E.content!==null)k.partialMessages.push(Pe(j,E.content));else if("refusal"in E&&E.refusal!==null)k.partialMessages.push(Pe(j,E.refusal));else if("tool_calls"in E&&E.tool_calls!==void 0){let ee=E.tool_calls.at(0);k.partialMessages.push(Mt(j,ee.index,ee.id,(n=ee.function)==null?void 0:n.name,(i=ee.function)==null?void 0:i.arguments));}}}h.usage&&(k.usage={promptTokens:h.usage.prompt_tokens,completionTokens:h.usage.completion_tokens,totalTokens:h.usage.total_tokens}),yield {partialResponse:k,buffer:r};}else throw new G({info:"Invalid response from model",cause:g.error})}catch(P){throw new G({info:`Malformed JSON received in stream: ${p}`,cause:P})}}}yield {partialResponse:{partialMessages:[]},buffer:r};})}transformProxyStreamChatResponseChunk(e,o,n,i,s){return to(this,null,function*(){yield*it(qa(this.transformStreamChatResponseChunk(e,o)));})}getProxyStreamChatUrl(e,o,n){return w(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,o,n){return w(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,o,n){return w(this,null,function*(){if(!o)return {};let i=O({},o);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(e,o,n){return w(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,o,n)})}getModelPricing(){if(!(this.modelName in x))throw new G({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return x[this.modelName]}},we="gpt-3.5-turbo-0125",mi="The latest GPT-3.5 Turbo model with higher accuracy at responding in requested formats and a fix for a bug which caused a text encoding issue for non-English language function calls. Training data up to Sept 2021.",Oo=f(b,A).parse({name:we,description:mi,maxInputTokens:4092,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema},price:x[we]}),di=v,ci=class extends T{constructor(e){super(Oo,e);}},Ie="gpt-3.5-turbo-1106",pi="The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens. Training data up to Sept 2021.",So=f(b,A).parse({name:Ie,description:pi,maxInputTokens:4092,maxOutputTokens:16385,roles:y,modalities:U,config:{def:u.responseFormat(16385,4).def,schema:u.responseFormat(16385,4).schema},price:x[Ie]}),ui=v,gi=class extends T{constructor(e){super(So,e);}},Re="gpt-3.5-turbo",hi="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",Co=f(b,A).parse({name:Re,description:hi,maxInputTokens:4092,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema},price:x[Re]}),fi=v,bi=class extends T{constructor(e){super(Co,e);}},je="gpt-4-0125-preview",yi="The latest GPT-4 model intended to reduce cases of \u201Claziness\u201D where the model doesn\u2019t complete a task. Training data up to Apr 2023.",Eo=f(b,A).parse({name:je,description:yi,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema},price:x[je]}),Ti=v,_i=class extends T{constructor(e){super(Eo,e);}},Ne="gpt-4-0613",vi="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",wo=f(b,A).parse({name:Ne,description:vi,maxInputTokens:8192,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema},price:x[Ne]}),Pi=v,ki=class extends T{constructor(e){super(wo,e);}},Le="gpt-4-1106-preview",xi="GPT-4 Turbo model featuring improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens. This preview model is not yet suited for production traffic. Training data up to Apr 2023.",Io=f(b,A).parse({name:Le,description:xi,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema},price:x[Le]}),Mi=v,Oi=class extends T{constructor(e){super(Io,e);}},Ue="gpt-4.1",Si="Flagship model for complex tasks. It is well suited for problem solving across domains. Training data up to May 2024.",Ro=f(b,C).parse({name:Ue,description:Si,maxInputTokens:1047576,maxOutputTokens:32768,roles:y,modalities:S,config:{def:u.responseSchema(32768,4).def,schema:u.responseSchema(32768,4).schema},price:x[Ue]}),Ci=v,Ei=class extends T{constructor(e){super(Ro,e);}},Ae="gpt-4.1-mini",wi="Provides a balance between intelligence, speed, and cost that makes it an attractive model for many use cases. Training data up to May 2024.",jo=f(b,C).parse({name:Ae,description:wi,maxInputTokens:1047576,maxOutputTokens:32768,roles:y,modalities:S,config:{def:u.responseSchema(32768,4).def,schema:u.responseSchema(32768,4).schema},price:x[Ae]}),Ii=v,Ri=class extends T{constructor(e){super(jo,e);}},Ge="gpt-4.1-nano",ji="Fastest, most cost-effective GPT-4.1 model. Training data up to May 2024.",No=f(b,C).parse({name:Ge,description:ji,maxInputTokens:1047576,maxOutputTokens:32768,roles:y,modalities:S,config:{def:u.responseSchema(32768,4).def,schema:u.responseSchema(32768,4).schema},price:x[Ge]}),Ni=v,Li=class extends T{constructor(e){super(No,e);}},qe="gpt-4-turbo-2024-04-09",Ui="GPT-4 Turbo with Vision model. Vision requests can now use JSON mode and function calling. gpt-4-turbo currently points to this version. Training data up to Dec 2023.",Lo=f(b,C).parse({name:qe,description:Ui,maxInputTokens:128e3,maxOutputTokens:4096,roles:y,modalities:S,config:{def:u.responseFormat(4096,4).def,schema:u.responseFormat(4096,4).schema},price:x[qe]}),Ai=v,Gi=class extends T{constructor(e){super(Lo,e);}},$e="gpt-4-turbo-preview",qi="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",Uo=f(b,A).parse({name:$e,description:qi,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema},price:x[$e]}),$i=v,Di=class extends T{constructor(e){super(Uo,e);}},De="gpt-4-turbo",Fi="The latest GPT-4 Turbo model with vision capabilities. Vision requests can now use JSON mode and function calling. Currently points to gpt-4-turbo-2024-04-09. Training data up to Dec 2023.",Ao=f(b,C).parse({name:De,description:Fi,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema},price:x[De]}),Bi=v,zi=class extends T{constructor(e){super(Ao,e);}},Fe="gpt-4",Hi="Currently points to gpt-4-0613. Training data up to Sept 2021.",Go=f(b,A).parse({name:Fe,description:Hi,maxInputTokens:8192,maxOutputTokens:4092,roles:y,modalities:U,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema},price:x[Fe]}),Ji=v,Ki=class extends T{constructor(e){super(Go,e);}},Be="gpt-4o-2024-05-13",Vi="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",qo=f(b,C).parse({name:Be,description:Vi,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[Be]}),Yi=v,Wi=class extends T{constructor(e){super(qo,e);}},ze="gpt-4o-2024-08-06",Zi="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",$o=f(b,C).parse({name:ze,description:Zi,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[ze]}),Xi=v,Qi=class extends T{constructor(e){super($o,e);}},He="gpt-4o-mini-2024-07-18",es="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",Do=f(b,C).parse({name:He,description:es,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[He]}),ts=v,os=class extends T{constructor(e){super(Do,e);}},Je="gpt-4o-mini",ns="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",Fo=f(b,C).parse({name:Je,description:ns,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[Je]}),as=v,is=class extends T{constructor(e){super(Fo,e);}},Ke="gpt-4o",ss="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",Bo=f(b,C).parse({name:Ke,description:ss,maxInputTokens:128e3,maxOutputTokens:4092,roles:y,modalities:S,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema},price:x[Ke]}),rs=v,ls=class extends T{constructor(e){super(Bo,e);}},Ve="o1-2024-12-17",ms="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",zo=f(b,C).parse({name:Ve,description:ms,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema},price:x[Ve]}),ds=v,cs=class extends T{constructor(e){super(zo,e);}},Ye="o1",ps="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",Ho=f(b,C).parse({name:Ye,description:ps,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema},price:x[Ye]}),us=v,gs=class extends T{constructor(e){super(Ho,e);}},Jo="o3-2025-04-16",hs="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",Ko=f(b,C).parse({name:Jo,description:hs,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),fs=v,bs=class extends T{constructor(e){super(Ko,e);}},Vo="o3",ys="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",Yo=f(b,C).parse({name:Vo,description:ys,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),Ts=v,_s=class extends T{constructor(e){super(Yo,e);}},Wo="o3-mini",vs="o3-mini is the newest small reasoning model, providing high intelligence at the same cost and latency targets of o1-mini. Training data up to Sep 2023.",Zo=f(b,A).parse({name:Wo,description:vs,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:U,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),Ps=v,ks=class extends T{constructor(e){super(Zo,e);}},Xo="o3-mini-2025-01-31",xs="o3-mini is the newest small reasoning model, providing high intelligence at the same cost and latency targets of o1-mini. Training data up to Sep 2023.",Qo=f(b,A).parse({name:Xo,description:xs,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:U,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),Ms=v,Os=class extends T{constructor(e){super(Qo,e);}},en="o4-mini-2025-04-16",Ss="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",tn=f(b,C).parse({name:en,description:Ss,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),Cs=v,Es=class extends T{constructor(e){super(tn,e);}},on="o4-mini",ws="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",nn=f(b,C).parse({name:on,description:ws,maxInputTokens:2e5,maxOutputTokens:1e5,roles:y,modalities:S,config:{def:u.oSeries(1e5,4).def,schema:u.oSeries(1e5,4).schema}}),Is=v,Rs=class extends T{constructor(e){super(nn,e);}},et=[D,B],tt=zod.z.enum([D,B]),js=zod.z.object({object:zod.z.literal("list"),model:zod.z.string(),data:zod.z.array(zod.z.object({index:zod.z.number(),object:zod.z.literal("embedding"),embedding:zod.z.array(zod.z.number()).or(zod.z.string().base64())})),usage:zod.z.object({prompt_tokens:zod.z.number().nonnegative(),total_tokens:zod.z.number().nonnegative()})}),Ns=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)).or(zod.z.array(zod.z.number().int().nonnegative()).min(1)).or(zod.z.array(zod.z.array(zod.z.number().int().nonnegative()).min(1)).min(1)),Ls=zod.z.object({model:zod.z.string().min(1).optional(),input:Ns,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()}),ie=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),ot=class{constructor(e,o){this.version="v1";let n=ie.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=H(n.baseUrl||Xe.baseUrl),this.getEmbeddingsUrl=H(n.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let o=r=>{let d=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},p,P=0;for(;(p=d.exec(r))!==null;){let g=parseInt(p[1]),k=p[2];P+=g*c[k];}return P},n=0,i=0,s=!0;e["x-ratelimit-reset-requests"]&&(n=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(i=o(e["x-ratelimit-reset-tokens"]));let m=Math.max(n,i);return {shouldRetry:s,delayMs:m}}getTokenCount(e){return e.requests.reduce((o,n)=>o+n.length,0)}transformModelRequest(e){let o=Ls.safeParse(e);if(!o.success)throw new Q({info:"Invalid model request",cause:o.error});let n=o.data,i=n.model,s={encodingFormat:n.encoding_format,dimensions:n.dimensions},m=ye().parse(Ee(s)),r,d;return typeof n.input=="string"?d=D:typeof n.input[0]=="string"?d=D:d=B,d===D?typeof n.input=="string"?r={modality:d,requests:[n.input]}:r={modality:d,requests:n.input}:typeof n.input[0]=="number"?r={modality:d,requests:[n.input]}:r={modality:d,requests:n.input},{modelName:i,config:m,embeddingRequests:r}}transformConfig(e,o){let n=this.modelSchema.config.schema.safeParse(e);if(!n.success)throw new q({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:n.error});let i=n.data;return Object.keys(i).forEach(s=>{if(!this.modelSchema.config.def[s])throw new q({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${s}',
15
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((s,m)=>{let r=this.modelSchema.config.def[m].param,d=i[m];return s[r]=d,s},{})}transformEmbeddingRequests(e){let o=vt().safeParse(e);if(!o.success)throw new Dt({info:"Invalid embedding requests",cause:o.error});return {input:o.data.requests}}getGetEmbeddingsUrl(e,o){return w(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return w(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return w(this,null,function*(){return new Promise(n=>{n(O(O(O({},this.getDefaultParams()),this.transformConfig(e,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o,n=js.safeParse(e);if(n.success){let i=n.data;o=typeof i.data[0].embedding=="string"?_e:Te;let s=i.data.map(m=>typeof m.embedding=="string"?{index:m.index,embedding:m.embedding}:{index:m.index,embedding:m.embedding});return {encodingFormat:o,embeddings:s,usage:{totalTokens:i.usage.total_tokens}}}throw new G({info:"Invalid response from model",cause:n.error})}},an="text-embedding-ada-002",Us="Most capable 2nd generation embedding model, replacing 16 first generation models",sn=te(tt).parse({name:an,description:Us,modalities:et,maxInputTokens:8192,maxOutputTokens:1536,config:{def:J.base().def,schema:J.base().schema}}),As=ie,Gs=class extends ot{constructor(e){super(sn,e);}},rn="text-embedding-3-small",qs="Increased performance over 2nd generation ada embedding model",ln=te(tt).parse({name:rn,description:qs,modalities:et,maxInputTokens:8192,maxOutputTokens:1536,config:{def:J.dimensions(1536).def,schema:J.dimensions(1536).schema}}),$s=ie,Ds=class extends ot{constructor(e){super(ln,e);}},mn="text-embedding-3-large",Fs="Most capable embedding model for both english and non-english tasks",dn=te(tt).parse({name:mn,description:Fs,modalities:et,maxInputTokens:8192,maxOutputTokens:3072,config:{def:J.dimensions(3072).def,schema:J.dimensions(3072).schema}}),Bs=ie,zs=class extends ot{constructor(e){super(dn,e);}};var nt=f(b,C).parse({name:"__base__",description:"Base chat model for Custom",maxInputTokens:128e3,maxOutputTokens:128e3,roles:y,modalities:S,config:{def:u.base(128e3,4).def,schema:u.base(128e3,4).schema}});var se=zod.z.object({apiKey:zod.z.string().min(1),modelName:zod.z.string(),baseUrl:zod.z.string().optional(),completeChatUrl:zod.z.string().optional(),streamChatUrl:zod.z.string().optional()});var re=class extends T{constructor(n,i){let s=se.parse(i);super(n,{modelName:s.modelName,apiKey:s.apiKey,baseUrl:s.baseUrl,completeChatUrl:s.completeChatUrl,streamChatUrl:s.streamChatUrl});this.version="v1";}getModelPricing(){throw new G({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error("No pricing configuration for custom provider")})}};var Hs="custom",at=class{constructor(){this.version="v1";this.name=Hs;this.embeddingModelFactories={};}chatModelLiterals(){return ["__base__"]}chatModelSchemas(){return {__base__:nt}}chatModel(o){let n=re,i=se.parse(o);return new n(nt,i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((o,n)=>(o[n]=this.embeddingModelFactories[n].modelSchema,o),{})}embeddingModel(o){throw new X({info:"Custom embedding models not supported yet",cause:new Error("Custom embedding models not supported yet")})}};at.customUrl=o=>`${o}`;
16
16
 
17
17
  exports.BaseChatModelOpenAI = re;
18
- exports.BaseChatModelOptions = ie;
18
+ exports.BaseChatModelOptions = se;
19
19
  exports.BaseChatModelSchema = nt;
20
20
  exports.Custom = at;
21
21
  //# sourceMappingURL=index.js.map