@adaline/custom 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
- var he=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),bn=e=>{throw TypeError(e)};var yn=function(e,t){this[0]=e,this[1]=t;};var fe=e=>{var t=e[he("asyncIterator")],o=!1,s,i={};return t==null?(t=e[he("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 yn(new Promise(d=>{var c=t[m](r);c instanceof Object||bn("Object expected"),d(c);}),1)}}),i[he("iterator")]=()=>i,s("next"),"throw"in t?s("throw"):i.throw=m=>{throw m},"return"in t&&s("return"),i};var X="system",z="user",R="assistant",Q="tool",Tn=[X,z,R,Q],Te=zod.z.enum(Tn),_n=[R],vn=zod.z.enum(_n),G="image",_e="base64",Pn=["png","jpeg","webp","gif"],kn=zod.z.object({type:zod.z.literal(_e),base64:zod.z.string(),media_type:zod.z.enum(Pn)}),ve="url",xn=zod.z.object({type:zod.z.literal(ve),url:zod.z.string()}),Mn=zod.z.discriminatedUnion("type",[kn,xn]),Sn=["low","medium","high","auto"],On=zod.z.enum(Sn),Cn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(G),detail:On,value:Mn,metadata:e}),ft="reasoning",bt="partial-reasoning",yt="thinking",wn="redacted",ye=zod.z.object({type:zod.z.literal(yt),thinking:zod.z.string(),signature:zod.z.string()}),Tt=zod.z.object({type:zod.z.literal(wn),data:zod.z.string()}),En=zod.z.discriminatedUnion("type",[ye,Tt]),Rn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ft),value:En,metadata:e}),In=zod.z.object({type:zod.z.literal(yt),thinking:ye.shape.thinking.optional(),signature:ye.shape.signature.optional()}),jn=zod.z.discriminatedUnion("type",[In,Tt]),Ln=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(bt),value:jn,metadata:e}),x="text",_t=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(x),value:zod.z.string(),metadata:e}),Pe="partial-text",vt=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Pe),value:zod.z.string(),metadata:e}),I="tool-call",Pt=(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}),ke="partial-tool-call",kt=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ke),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:e}),L="tool-response",Nn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(L),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:e}),Un=[x,G,I,L,ft],xt=zod.z.enum(Un),An=(e=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[_t(e),Cn(t),Pt(o),Nn(s),Rn(i)]),$n=[Pe,ke,bt];zod.z.enum($n);var Gn=(e=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[vt(e),kt(t),Ln(o)]);var xe=(e=Te,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(An(t,o,s,i,r)),metadata:m}),Me=(e=vn,t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:e,partialContent:Gn(t,o,s),metadata:i}),qn=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),pt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Dn=pt.extend({topLogProbs:zod.z.array(pt)}),Mt=zod.z.array(Dn);zod.z.object({messages:zod.z.array(xe()),usage:qn.optional(),logProbs:Mt.optional()});var Fn=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(Me()),usage:Fn.optional(),logProbs:Mt.optional()});var Se=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,Bn=["object","array","number","string","boolean","enum"],gt=zod.z.enum(Bn),zn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([gt,zod.z.array(zod.z.union([gt,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()}),Hn=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(zn),additionalProperties:zod.z.literal(!1)}),St=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:Hn}).optional(),q="text",J="token",Jn=[q,J],Ot=zod.z.enum(Jn),Kn=zod.z.array(zod.z.string().min(1)),Vn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Ct=(e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(q),metadata:e,requests:Kn}),zod.z.object({modality:zod.z.literal(J),metadata:e,requests:Vn})]),Oe="float",Wn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Ce="base64",Yn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),ht=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Oe),embeddings:zod.z.array(Wn),usage:ht.optional()}),zod.z.object({encodingFormat:zod.z.literal(Ce),embeddings:zod.z.array(Yn),usage:ht.optional()})]);var Zn=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})},Xn=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:Zn(e),be="GatewayBaseError",U=class wt extends Error{constructor({info:t,cause:o},s){super(`[${s!=null?s:be}]: ${t}
5
+ var he=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),bn=e=>{throw TypeError(e)};var yn=function(e,t){this[0]=e,this[1]=t;};var fe=e=>{var t=e[he("asyncIterator")],o=!1,s,i={};return t==null?(t=e[he("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 yn(new Promise(d=>{var c=t[m](r);c instanceof Object||bn("Object expected"),d(c);}),1)}}),i[he("iterator")]=()=>i,s("next"),"throw"in t?s("throw"):i.throw=m=>{throw m},"return"in t&&s("return"),i};var X="system",z="user",R="assistant",Q="tool",Tn=[X,z,R,Q],Te=zod.z.enum(Tn),_n=[R],vn=zod.z.enum(_n),G="image",_e="base64",Pn=["png","jpeg","webp","gif"],kn=zod.z.object({type:zod.z.literal(_e),base64:zod.z.string(),mediaType:zod.z.enum(Pn)}),ve="url",xn=zod.z.object({type:zod.z.literal(ve),url:zod.z.string()}),Mn=zod.z.discriminatedUnion("type",[kn,xn]),Sn=["low","medium","high","auto"],On=zod.z.enum(Sn),Cn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(G),detail:On,value:Mn,metadata:e}),ft="reasoning",bt="partial-reasoning",yt="thinking",wn="redacted",ye=zod.z.object({type:zod.z.literal(yt),thinking:zod.z.string(),signature:zod.z.string()}),Tt=zod.z.object({type:zod.z.literal(wn),data:zod.z.string()}),En=zod.z.discriminatedUnion("type",[ye,Tt]),Rn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ft),value:En,metadata:e}),In=zod.z.object({type:zod.z.literal(yt),thinking:ye.shape.thinking.optional(),signature:ye.shape.signature.optional()}),jn=zod.z.discriminatedUnion("type",[In,Tt]),Ln=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(bt),value:jn,metadata:e}),x="text",_t=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(x),value:zod.z.string(),metadata:e}),Pe="partial-text",vt=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Pe),value:zod.z.string(),metadata:e}),I="tool-call",Pt=(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}),ke="partial-tool-call",kt=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ke),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:e}),L="tool-response",Nn=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(L),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:e}),Un=[x,G,I,L,ft],xt=zod.z.enum(Un),An=(e=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[_t(e),Cn(t),Pt(o),Nn(s),Rn(i)]),$n=[Pe,ke,bt];zod.z.enum($n);var Gn=(e=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[vt(e),kt(t),Ln(o)]);var xe=(e=Te,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(An(t,o,s,i,r)),metadata:m}),Me=(e=vn,t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:e,partialContent:Gn(t,o,s),metadata:i}),qn=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),pt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Dn=pt.extend({topLogProbs:zod.z.array(pt)}),Mt=zod.z.array(Dn);zod.z.object({messages:zod.z.array(xe()),usage:qn.optional(),logProbs:Mt.optional()});var Fn=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(Me()),usage:Fn.optional(),logProbs:Mt.optional()});var Se=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,Bn=["object","array","number","string","boolean","enum"],gt=zod.z.enum(Bn),zn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([gt,zod.z.array(zod.z.union([gt,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()}),Hn=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(zn),additionalProperties:zod.z.literal(!1)}),St=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:Hn}).optional(),q="text",J="token",Jn=[q,J],Ot=zod.z.enum(Jn),Kn=zod.z.array(zod.z.string().min(1)),Vn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Ct=(e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(q),metadata:e,requests:Kn}),zod.z.object({modality:zod.z.literal(J),metadata:e,requests:Vn})]),Oe="float",Wn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Ce="base64",Yn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),ht=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Oe),embeddings:zod.z.array(Wn),usage:ht.optional()}),zod.z.object({encodingFormat:zod.z.literal(Ce),embeddings:zod.z.array(Yn),usage:ht.optional()})]);var Zn=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})},Xn=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:Zn(e),be="GatewayBaseError",U=class wt extends Error{constructor({info:t,cause:o},s){super(`[${s!=null?s:be}]: ${t}
6
6
  Message: ${Xn(o)}`),this.name=be,this.info=t,this.cause=o,this.name=s!=null?s:be,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof wt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Qn=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."),ea=zod.z.object({base:Qn.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),ta=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:ea.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(ta).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 oa="function";var na=zod.z.enum(["object","array","number","string","boolean","null"]),aa=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:na.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(aa).optional(),required:zod.z.array(zod.z.string()).optional()});var sa=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 ia=zod.z.enum(["function"]),ra=zod.z.object({type:ia,definition:zod.z.object({schema:sa})}),la=[oa];zod.z.enum(la);var Et=(e=zod.z.undefined())=>zod.z.discriminatedUnion("type",[ra.extend({metadata:e})]),we=e=>_t().parse({modality:x,value:e}),Rt=(e,t,o,s)=>Pt().parse({modality:I,index:e,id:t,name:o,arguments:s});var Ee=(e,t)=>Me().parse({role:e,partialContent:vt().parse({modality:Pe,value:t})}),It=(e,t,o,s,i)=>Me().parse({role:e,partialContent:kt().parse({modality:ke,index:t,id:o,name:s,arguments:i})});var ma=Object.defineProperty,jt=Object.getOwnPropertySymbols,da=Object.prototype.hasOwnProperty,ca=Object.prototype.propertyIsEnumerable,Lt=(e,t,o)=>t in e?ma(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,ee=(e,t)=>{for(var o in t||(t={}))da.call(t,o)&&Lt(e,o,t[o]);if(jt)for(var o of jt(t))ca.call(t,o)&&Lt(e,o,t[o]);return e},Nt="ProviderError",te=class Bt extends U{constructor({info:t,cause:o}){super({info:t,cause:o},Nt),this.name=Nt,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof Bt}},Ut="ModelError",H=class zt extends U{constructor({info:t,cause:o}){super({info:t,cause:o},Ut),this.name=Ut,this.info=t,this.cause=o;}static isModelError(t){return t instanceof zt}},At="ModelResponseError",A=class Ht extends U{constructor({info:t,cause:o}){super({info:t,cause:o},At),this.name=At,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof Ht}},$t="InvalidModelRequestError",K=class Jt extends U{constructor({info:t,cause:o}){super({info:t,cause:o},$t),this.name=$t,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Jt}},Gt="InvalidConfigError",$=class Kt extends U{constructor({info:t,cause:o}){super({info:t,cause:o},Gt),this.name=Gt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Kt}},qt="InvalidMessagesError",j=class Vt extends U{constructor({info:t,cause:o}){super({info:t,cause:o},qt),this.name=qt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof Vt}},Dt="InvalidToolsError",Re=class Wt extends U{constructor({info:t,cause:o}){super({info:t,cause:o},Dt),this.name=Dt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof Wt}},Ft="InvalidEmbeddingRequestsError",Yt=class Zt extends U{constructor({info:t,cause:o}){super({info:t,cause:o},Ft),this.name=Ft,this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Zt}},Ie="multi-string",Xt=zod.z.object({type:zod.z.literal(Ie),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),ua=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),Qt=e=>({def:Xt.parse(ee({type:Ie},e)),schema:ua(e.max)}),je="object-schema",eo=zod.z.object({type:zod.z.literal(je),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),pa=e=>e.optional(),to=e=>({def:eo.parse(ee({type:je},e)),schema:pa(e.objectSchema)}),Le="range",oo=zod.z.object({type:zod.z.literal(Le),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()}),ga=(e,t,o,s)=>zod.z.number().min(e).max(t).step(o).default(s).optional(),N=e=>({def:oo.parse(ee({type:Le},e)),schema:ga(e.min,e.max,e.step,e.default)}),Ne="select-boolean",no=zod.z.object({type:zod.z.literal(Ne),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),ha=e=>zod.z.boolean().nullable().default(e).optional(),ao=e=>({def:no.parse(ee({type:Ne},e)),schema:ha(e.default)}),Ue="select-string",so=zod.z.object({type:zod.z.literal(Ue),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())}),fa=(e,t)=>zod.z.enum(t).nullable().default(e).optional(),V=e=>({def:so.parse(ee({type:Ue},e)),schema:fa(e.default,e.choices)}),ba=[Le,Ie,Ue,je,Ne];zod.z.enum(ba);var io=zod.z.discriminatedUnion("type",[oo,Xt,so,no,eo]),f=(e=Te,t=xt)=>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),io),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()}),le=(e=Ot)=>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),io),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 ya={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."},Ta={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."},_a={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},va=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.`}),Pa={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."},ka={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."},xa={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."},Ma={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."},Sa={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."},Oa={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."},Ca={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."},wa={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."},Ea={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."},Ra={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."},Ia={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},ja={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."},La={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."},Na={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."},b={TEMPERATURE:ya,MAX_TOKENS:Ta,STOP:va,TOP_A:Pa,TOP_P:ka,TOP_K:xa,MIN_P:Ma,FREQUENCY_PENALTY:Sa,PRESENCE_PENALTY:Oa,REPETITION_PENALTY:wa,SEED:Ca,LOG_PROBS:Ea,TOP_LOG_PROBS:Ra,ECHO:Ia,RESPONSE_FORMAT:ja,RESPONSE_FORMAT_WITH_SCHEMA:La,RESPONSE_SCHEMA:Na,MAX_REASONING_TOKENS:_a};var Ae=e=>Object.fromEntries(Object.entries(e).filter(([t,o])=>o!=null));var ro=e=>e.split(";")[0].split("/")[1],W=e=>e==null?void 0:e.replace(/\/$/,"");var Ua=Object.defineProperty,Aa=Object.defineProperties,$a=Object.getOwnPropertyDescriptors,lo=Object.getOwnPropertySymbols,Ga=Object.prototype.hasOwnProperty,qa=Object.prototype.propertyIsEnumerable,de=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Da=e=>{throw TypeError(e)},mo=(e,t,o)=>t in e?Ua(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,M=(e,t)=>{for(var o in t||(t={}))Ga.call(t,o)&&mo(e,o,t[o]);if(lo)for(var o of lo(t))qa.call(t,o)&&mo(e,o,t[o]);return e},oe=(e,t)=>Aa(e,$a(t)),O=(e,t,o)=>new Promise((s,i)=>{var m=c=>{try{d(o.next(c));}catch(u){i(u);}},r=c=>{try{d(o.throw(c));}catch(u){i(u);}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(m,r);d((o=o.apply(e,t)).next());}),co=function(e,t){this[0]=e,this[1]=t;},ce=(e,t,o)=>{var s=(r,d,c,u)=>{try{var T=o[r](d),g=(d=T.value)instanceof co,_=T.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,u):c({value:h,done:_})).catch(h=>s("throw",h,c,u));}catch(h){u(h);}},i=r=>m[r]=d=>new Promise((c,u)=>s(r,d,c,u)),m={};return o=o.apply(e,t),m[de("asyncIterator")]=()=>m,i("next"),i("throw"),i("return"),m},uo=e=>{var t=e[de("asyncIterator")],o=!1,s,i={};return t==null?(t=e[de("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 co(new Promise(d=>{var c=t[m](r);c instanceof Object||Da("Object expected"),d(c);}),1)}}),i[de("iterator")]=()=>i,s("next"),"throw"in t?s("throw"):i.throw=m=>{throw m},"return"in t&&s("return"),i},po=N({param:"temperature",title:b.TEMPERATURE.title,description:b.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),go=e=>N({param:"max_completion_tokens",title:b.MAX_TOKENS.title,description:b.MAX_TOKENS.description,min:0,max:e,step:1,default:0}),ho=e=>Qt({param:"stop",title:b.STOP(e).title,description:b.STOP(e).description,max:e}),fo=N({param:"top_p",title:b.TOP_P.title,description:b.TOP_P.description,min:0,max:1,step:.01,default:1}),bo=N({param:"frequency_penalty",title:b.FREQUENCY_PENALTY.title,description:b.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),yo=N({param:"presence_penalty",title:b.PRESENCE_PENALTY.title,description:b.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),To=N({param:"seed",title:b.SEED.title,description:b.SEED.description,min:0,max:1e6,step:1,default:0}),_o=ao({param:"logprobs",title:b.LOG_PROBS.title,description:b.LOG_PROBS.description,default:!1}),vo=N({param:"top_logprobs",title:b.TOP_LOG_PROBS.title,description:b.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),Po=V({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"]}),at=(e,t)=>zod.z.object({temperature:po.schema,maxTokens:go(e).schema,stop:ho(t).schema,topP:fo.schema,frequencyPenalty:bo.schema,presencePenalty:yo.schema,seed:To.schema.transform(o=>o===0?void 0:o),logProbs:_o.schema,topLogProbs:vo.schema,toolChoice:Po.schema}),st=(e,t)=>({temperature:po.def,maxTokens:go(e).def,stop:ho(t).def,topP:fo.def,frequencyPenalty:bo.def,presencePenalty:yo.def,seed:To.def,logProbs:_o.def,topLogProbs:vo.def,toolChoice:Po.def}),ko=to({param:"response_schema",title:b.RESPONSE_SCHEMA.title,description:b.RESPONSE_SCHEMA.description,objectSchema:St}),xo=V({param:"response_format",title:b.RESPONSE_FORMAT_WITH_SCHEMA.title,description:b.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),Mo=(e,t)=>oe(M({},st(e,t)),{responseFormat:xo.def,responseSchema:ko.def}),So=(e,t)=>at(e,t).extend({responseFormat:xo.schema,responseSchema:ko.schema}),Oo=N({param:"temperature",title:b.TEMPERATURE.title,description:b.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),Co=V({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"]}),Fa=(e,t)=>oe(M({},Mo(e,t)),{temperature:Oo.def,reasoningEffort:Co.def}),Ba=(e,t)=>So(e,t).extend({temperature:Oo.schema,reasoningEffort:Co.schema}),wo=V({param:"response_format",title:b.RESPONSE_FORMAT.title,description:b.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),za=(e,t)=>oe(M({},st(e,t)),{responseFormat:wo.def}),Ha=(e,t)=>at(e,t).extend({responseFormat:wo.schema}),Eo=V({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),Ro=e=>N({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:e,step:1,default:e}),Io=()=>zod.z.object({encodingFormat:Eo.schema}),jo=()=>({encodingFormat:Eo.def}),Ja=e=>Io().extend({dimensions:Ro(e).schema}),Ka=e=>oe(M({},jo()),{dimensions:Ro(e).def}),p={base:(e,t)=>({def:st(e,t),schema:at(e,t)}),responseFormat:(e,t)=>({def:za(e,t),schema:Ha(e,t)}),responseSchema:(e,t)=>({def:Mo(e,t),schema:So(e,t)}),oSeries:(e,t)=>({def:Fa(e,t),schema:Ba(e,t)})},Y={base:()=>({def:jo(),schema:Io()}),dimensions:e=>({def:Ka(e),schema:Ja(e)})},v={"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-preview":{modelName:"o1-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:60}}}]},"o1-mini-2024-09-12":{modelName:"o1-mini-2024-09-12",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},"o1-mini":{modelName:"o1-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.1,outputPricePerMillion:4.4}}}]},o1:{modelName:"o1",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:60}}}]},"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}}}]}},Va="openai",it=class{constructor(){this.version="v1",this.name=Va,this.chatModelFactories={[qe]:{model:Ts,modelOptions:ys,modelSchema:$o},[$e]:{model:ps,modelOptions:us,modelSchema:Uo},[Ge]:{model:fs,modelOptions:hs,modelSchema:Ao},[De]:{model:Ps,modelOptions:vs,modelSchema:Go},[Fe]:{model:Ms,modelOptions:xs,modelSchema:qo},[Be]:{model:Cs,modelOptions:Os,modelSchema:Do},[ze]:{model:Rs,modelOptions:Es,modelSchema:Fo},[He]:{model:Ls,modelOptions:js,modelSchema:Bo},[Je]:{model:As,modelOptions:Us,modelSchema:zo},[Ke]:{model:qs,modelOptions:Gs,modelSchema:Ho},[We]:{model:Js,modelOptions:Hs,modelSchema:Ko},[Ze]:{model:Xs,modelOptions:Zs,modelSchema:Wo},[Xe]:{model:ti,modelOptions:ei,modelSchema:Yo},[Ye]:{model:Ws,modelOptions:Vs,modelSchema:Vo},[Ve]:{model:Bs,modelOptions:Fs,modelSchema:Jo},[tt]:{model:di,modelOptions:mi,modelSchema:Qo},[ot]:{model:pi,modelOptions:ui,modelSchema:en},[nt]:{model:fi,modelOptions:hi,modelSchema:tn},[Qe]:{model:ai,modelOptions:ni,modelSchema:Zo},[et]:{model:ri,modelOptions:ii,modelSchema:Xo},[on]:{model:Ti,modelOptions:yi,modelSchema:nn},[an]:{model:Pi,modelOptions:vi,modelSchema:sn},[rn]:{model:Mi,modelOptions:xi,modelSchema:ln},[mn]:{model:Ci,modelOptions:Oi,modelSchema:dn}},this.embeddingModelFactories={[cn]:{model:Li,modelOptions:ji,modelSchema:un},[pn]:{model:Ai,modelOptions:Ui,modelSchema:gn},[hn]:{model:qi,modelOptions:Gi,modelSchema:fn}};}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 te({info:`OpenAI chat model: ${t} not found`,cause:new Error(`OpenAI chat model: ${t} not found, available chat models:
7
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 te({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)}};it.baseUrl="https://api.openai.com/v1";var P=zod.z.enum([X,z,R,Q]),k={system:X,user:z,assistant:R,tool:Q},ne=zod.z.enum([z,R]),ae={user:z,assistant:R},w=[x,G,I,L],E=zod.z.enum([x,G,I,L]),se=[x],ie=zod.z.enum([x]),D=[x,I,L],F=zod.z.enum([x,I,L]),me=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Lo=zod.z.object({content:zod.z.array(me.extend({top_logprobs:zod.z.array(me)})).nullable().optional(),refusal:zod.z.array(me.extend({top_logprobs:zod.z.array(me)})).nullable().optional()}).nullable(),Wa=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()})})),Ya=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:Wa.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Lo.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()})}),Za=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()})),Xa=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:Za.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Lo,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()}),Qa=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()})}),es=zod.z.enum(["none","auto","required"]),ts=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),os=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()})})),rt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),ns=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()})}),as=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)})}),ss=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(rt).min(1))}),is=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([rt,ns])).min(1))}),rs=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(rt).min(1)).optional(),tool_calls:zod.z.array(as).min(1).optional()}),ls=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),ms=zod.z.union([ss,is,rs,ls]),No=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(ms).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:os.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(Qa).optional(),tool_choice:es.or(ts).optional()}),ds=No,y=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()}),S=class{constructor(e,t){this.version="v1";let o=y.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=W(o.baseUrl||it.baseUrl),this.streamChatUrl=W(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=W(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return M({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},u,T=0;for(;(u=d.exec(r))!==null;){let g=parseInt(u[1]),_=u[2];T+=g*c[_];}return T},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=No.safeParse(e);if(!t.success)throw new K({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 K({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=Se().parse(Ae(i)),r=[],d={};o.messages.forEach(u=>{let T=u.role;switch(T){case"system":{let g=u.content;if(typeof g=="string")r.push({role:T,content:[{modality:x,value:g}]});else {let _=g.map(h=>({modality:x,value:h.text}));r.push({role:T,content:_});}}break;case"user":{let g=u.content;if(typeof g=="string")r.push({role:T,content:[{modality:x,value:g}]});else {let _=g.map(h=>h.type==="text"?{modality:x,value:h.text}:h.image_url.url.startsWith("data:")?{modality:G,detail:h.image_url.detail||"auto",value:{type:_e,base64:h.image_url.url,media_type:ro(h.image_url.url)}}:{modality:G,detail:h.image_url.detail||"auto",value:{type:ve,url:h.image_url.url}});r.push({role:T,content:_});}}break;case"assistant":{let g=[];if(!u.content&&!u.tool_calls)throw new K({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(u.content){let _=u.content;typeof _=="string"?g.push({modality:x,value:_}):_.forEach(h=>{g.push({modality:x,value:h.text});});}u.tool_calls&&u.tool_calls.forEach((_,h)=>{let C={modality:I,id:_.id,index:h,name:_.function.name,arguments:_.function.arguments};g.push(C),d[C.id]=C;}),r.push({role:T,content:g});}break;case"tool":{let g=u;r.push({role:T,content:[{modality:L,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(u=>{c.push({type:"function",definition:{schema:{name:u.function.name,description:u.function.description||"",strict:u.function.strict,parameters:u.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}',
8
+ [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[t].model,s=this.embeddingModelFactories[t].modelOptions.parse(e);return new o(s)}};it.baseUrl="https://api.openai.com/v1";var P=zod.z.enum([X,z,R,Q]),k={system:X,user:z,assistant:R,tool:Q},ne=zod.z.enum([z,R]),ae={user:z,assistant:R},w=[x,G,I,L],E=zod.z.enum([x,G,I,L]),se=[x],ie=zod.z.enum([x]),D=[x,I,L],F=zod.z.enum([x,I,L]),me=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Lo=zod.z.object({content:zod.z.array(me.extend({top_logprobs:zod.z.array(me)})).nullable().optional(),refusal:zod.z.array(me.extend({top_logprobs:zod.z.array(me)})).nullable().optional()}).nullable(),Wa=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()})})),Ya=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:Wa.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Lo.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()})}),Za=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()})),Xa=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:Za.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Lo,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()}),Qa=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()})}),es=zod.z.enum(["none","auto","required"]),ts=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),os=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()})})),rt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),ns=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()})}),as=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)})}),ss=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(rt).min(1))}),is=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([rt,ns])).min(1))}),rs=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(rt).min(1)).optional(),tool_calls:zod.z.array(as).min(1).optional()}),ls=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),ms=zod.z.union([ss,is,rs,ls]),No=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(ms).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:os.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(Qa).optional(),tool_choice:es.or(ts).optional()}),ds=No,y=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()}),S=class{constructor(e,t){this.version="v1";let o=y.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=W(o.baseUrl||it.baseUrl),this.streamChatUrl=W(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=W(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return M({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},u,T=0;for(;(u=d.exec(r))!==null;){let g=parseInt(u[1]),_=u[2];T+=g*c[_];}return T},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=No.safeParse(e);if(!t.success)throw new K({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 K({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=Se().parse(Ae(i)),r=[],d={};o.messages.forEach(u=>{let T=u.role;switch(T){case"system":{let g=u.content;if(typeof g=="string")r.push({role:T,content:[{modality:x,value:g}]});else {let _=g.map(h=>({modality:x,value:h.text}));r.push({role:T,content:_});}}break;case"user":{let g=u.content;if(typeof g=="string")r.push({role:T,content:[{modality:x,value:g}]});else {let _=g.map(h=>h.type==="text"?{modality:x,value:h.text}:h.image_url.url.startsWith("data:")?{modality:G,detail:h.image_url.detail||"auto",value:{type:_e,base64:h.image_url.url,mediaType:ro(h.image_url.url)}}:{modality:G,detail:h.image_url.detail||"auto",value:{type:ve,url:h.image_url.url}});r.push({role:T,content:_});}}break;case"assistant":{let g=[];if(!u.content&&!u.tool_calls)throw new K({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(u.content){let _=u.content;typeof _=="string"?g.push({modality:x,value:_}):_.forEach(h=>{g.push({modality:x,value:h.text});});}u.tool_calls&&u.tool_calls.forEach((_,h)=>{let C={modality:I,id:_.id,index:h,name:_.function.name,arguments:_.function.arguments};g.push(C),d[C.id]=C;}),r.push({role:T,content:g});}break;case"tool":{let g=u;r.push({role:T,content:[{modality:L,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(u=>{c.push({type:"function",definition:{schema:{name:u.function.name,description:u.function.description||"",strict:u.function.strict,parameters:u.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
9
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((d,c)=>{let u=this.modelSchema.config.def[c],T=u.param,g=m[c];return T==="max_completion_tokens"&&u.type==="range"&&g===0?d[T]=u.max:d[T]=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(u=>u.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
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=xe().safeParse(o);if(!s.success)throw new j({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 j({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${s.modality}',
11
11
  available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),t.forEach(o=>{if(!Object.keys(this.modelSchema.roles).includes(o.role))throw new j({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${o.role}',