@adaline/openai 1.9.1 → 1.10.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
@@ -4,31 +4,31 @@ var zod = require('zod');
4
4
  var provider = require('@adaline/provider');
5
5
  var types = require('@adaline/types');
6
6
 
7
- var Fn=Object.defineProperty,$n=Object.defineProperties;var Hn=Object.getOwnPropertyDescriptors;var bt=Object.getOwnPropertySymbols;var Vn=Object.prototype.hasOwnProperty,Kn=Object.prototype.propertyIsEnumerable;var X=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Jn=n=>{throw TypeError(n)};var Pt=(n,e,t)=>e in n?Fn(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,b=(n,e)=>{for(var t in e||(e={}))Vn.call(e,t)&&Pt(n,t,e[t]);if(bt)for(var t of bt(e))Kn.call(e,t)&&Pt(n,t,e[t]);return n},v=(n,e)=>$n(n,Hn(e));var A=(n,e,t)=>new Promise((o,s)=>{var a=l=>{try{r(t.next(l));}catch(T){s(T);}},m=l=>{try{r(t.throw(l));}catch(T){s(T);}},r=l=>l.done?o(l.value):Promise.resolve(l.value).then(a,m);r((t=t.apply(n,e)).next());}),It=function(n,e){this[0]=n,this[1]=e;},co=(n,e,t)=>{var o=(m,r,l,T)=>{try{var g=t[m](r),P=(r=g.value)instanceof It,O=g.done;Promise.resolve(P?r[0]:r).then(C=>P?o(m==="return"?m:"next",r[1]?{done:C.done,value:C.value}:C,l,T):l({value:C,done:O})).catch(C=>o("throw",C,l,T));}catch(C){T(C);}},s=m=>a[m]=r=>new Promise((l,T)=>o(m,r,l,T)),a={};return t=t.apply(n,e),a[X("asyncIterator")]=()=>a,s("next"),s("throw"),s("return"),a},St=n=>{var e=n[X("asyncIterator")],t=!1,o,s={};return e==null?(e=n[X("iterator")](),o=a=>s[a]=m=>e[a](m)):(e=e.call(n),o=a=>s[a]=m=>{if(t){if(t=!1,a==="throw")throw m;return m}return t=!0,{done:!1,value:new It(new Promise(r=>{var l=e[a](m);l instanceof Object||Jn("Object expected"),r(l);}),1)}}),s[X("iterator")]=()=>s,o("next"),"throw"in e?o("throw"):s.throw=a=>{throw a},"return"in e&&o("return"),s};var ho=provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),fo=n=>provider.RangeConfigItem({param:"max_completion_tokens",title:provider.CHAT_CONFIG.MAX_TOKENS.title,description:provider.CHAT_CONFIG.MAX_TOKENS.description,min:0,max:n,step:1,default:0}),_o=n=>provider.MultiStringConfigItem({param:"stop",title:provider.CHAT_CONFIG.STOP(n).title,description:provider.CHAT_CONFIG.STOP(n).description,max:n}),go=provider.RangeConfigItem({param:"top_p",title:provider.CHAT_CONFIG.TOP_P.title,description:provider.CHAT_CONFIG.TOP_P.description,min:0,max:1,step:.01,default:1}),To=provider.RangeConfigItem({param:"frequency_penalty",title:provider.CHAT_CONFIG.FREQUENCY_PENALTY.title,description:provider.CHAT_CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Mo=provider.RangeConfigItem({param:"presence_penalty",title:provider.CHAT_CONFIG.PRESENCE_PENALTY.title,description:provider.CHAT_CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),yo=provider.RangeConfigItem({param:"seed",title:provider.CHAT_CONFIG.SEED.title,description:provider.CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),Oo=provider.SelectBooleanConfigItem({param:"logprobs",title:provider.CHAT_CONFIG.LOG_PROBS.title,description:provider.CHAT_CONFIG.LOG_PROBS.description,default:!1}),Co=provider.RangeConfigItem({param:"top_logprobs",title:provider.CHAT_CONFIG.TOP_LOG_PROBS.title,description:provider.CHAT_CONFIG.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),bo=provider.SelectStringConfigItem({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"]}),Po=provider.SelectStringConfigItem({param:"reasoning_effort",title:"Reasoning Effort",description:"Controls the depth of the model's reasoning before delivering an answer. 'minimal' prioritizes speed, 'high' engages in deep reasoning.",default:"medium",choices:["minimal","low","medium","high"]}),Io=provider.SelectStringConfigItem({param:"verbosity",title:"Verbosity",description:"Controls the length and detail of the model's responses, independent of reasoning depth. 'low' generates concise answers, 'high' provides comprehensive responses.",default:"medium",choices:["low","medium","high"]});var N=(n,e)=>zod.z.object({temperature:ho.schema,maxTokens:fo(n).schema,stop:_o(e).schema,topP:go.schema,frequencyPenalty:To.schema,presencePenalty:Mo.schema,seed:yo.schema.transform(t=>t===0?void 0:t),logProbs:Oo.schema,topLogProbs:Co.schema,toolChoice:bo.schema}),z=(n,e)=>({temperature:ho.def,maxTokens:fo(n).def,stop:_o(e).def,topP:go.def,frequencyPenalty:To.def,presencePenalty:Mo.def,seed:yo.def,logProbs:Oo.def,topLogProbs:Co.def,toolChoice:bo.def});var xt=(n,e)=>v(b({},z(n,e)),{reasoningEffort:Po.def,verbosity:Io.def}),Rt=(n,e)=>N(n,e).extend({reasoningEffort:Po.schema,verbosity:Io.schema});var At=provider.ObjectSchemaConfigItem({param:"response_schema",title:provider.CHAT_CONFIG.RESPONSE_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_SCHEMA.description,objectSchema:types.ResponseSchema}),Et=provider.SelectStringConfigItem({param:"response_format",title:provider.CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),ee=(n,e)=>v(b({},z(n,e)),{responseFormat:Et.def,responseSchema:At.def}),oe=(n,e)=>N(n,e).extend({responseFormat:Et.schema,responseSchema:At.schema});var kt=provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),wt=provider.SelectStringConfigItem({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"]}),vt=(n,e)=>v(b({},ee(n,e)),{temperature:kt.def,reasoningEffort:wt.def}),Lt=(n,e)=>oe(n,e).extend({temperature:kt.schema,reasoningEffort:wt.schema});var qt=provider.SelectStringConfigItem({param:"response_format",title:provider.CHAT_CONFIG.RESPONSE_FORMAT.title,description:provider.CHAT_CONFIG.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),Nt=(n,e)=>v(b({},z(n,e)),{responseFormat:qt.def}),zt=(n,e)=>N(n,e).extend({responseFormat:qt.schema});var So=provider.SelectStringConfigItem({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),xo=n=>provider.RangeConfigItem({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:n,step:1,default:n});var te=()=>zod.z.object({encodingFormat:So.schema}),ne=()=>({encodingFormat:So.def});var Bt=n=>te().extend({dimensions:xo(n).schema}),Ut=n=>v(b({},ne()),{dimensions:xo(n).def});var i={base:(n,e)=>({def:z(n,e),schema:N(n,e)}),responseFormat:(n,e)=>({def:Nt(n,e),schema:zt(n,e)}),responseSchema:(n,e)=>({def:ee(n,e),schema:oe(n,e)}),oSeries:(n,e)=>({def:vt(n,e),schema:Lt(n,e)}),gpt5:(n,e)=>({def:xt(n,e),schema:Rt(n,e)})},L={base:()=>({def:ne(),schema:te()}),dimensions:n=>({def:Ut(n),schema:Bt(n)})};var _={"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}}}]},"gpt-5":{modelName:"gpt-5",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}}]},"gpt-5-mini":{modelName:"gpt-5-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:2}}}]},"gpt-5-nano":{modelName:"gpt-5-nano",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.05,outputPricePerMillion:.4}}}]},"gpt-5-chat-latest":{modelName:"gpt-5-chat-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}}]}};var ps="openai",j=class{constructor(){this.version="v1";this.name=ps;this.chatModelFactories={[pe]:{model:le,modelOptions:Ht,modelSchema:Eo},[se]:{model:ie,modelOptions:Ft,modelSchema:Ro},[ae]:{model:re,modelOptions:$t,modelSchema:Ao},[me]:{model:de,modelOptions:Vt,modelSchema:Go},[ce]:{model:ue,modelOptions:Kt,modelSchema:ko},[he]:{model:fe,modelOptions:Jt,modelSchema:wo},[_e]:{model:ge,modelOptions:Wt,modelSchema:vo},[Te]:{model:Me,modelOptions:Yt,modelSchema:Lo},[ye]:{model:Oe,modelOptions:Qt,modelSchema:Do},[Ce]:{model:be,modelOptions:Xt,modelSchema:qo},[Pe]:{model:Ie,modelOptions:Zt,modelSchema:No},[Se]:{model:xe,modelOptions:en,modelSchema:zo},[Re]:{model:Ae,modelOptions:on,modelSchema:Bo},[Ee]:{model:Ge,modelOptions:tn,modelSchema:Uo},[ke]:{model:we,modelOptions:nn,modelSchema:jo},[ve]:{model:Le,modelOptions:sn,modelSchema:Fo},[De]:{model:qe,modelOptions:an,modelSchema:$o},[Be]:{model:Ue,modelOptions:pn,modelSchema:Vo},[$e]:{model:He,modelOptions:mn,modelSchema:Jo},[Ve]:{model:Ke,modelOptions:dn,modelSchema:Wo},[je]:{model:Fe,modelOptions:ln,modelSchema:Ko},[Ne]:{model:ze,modelOptions:rn,modelSchema:Ho},[Ye]:{model:Qe,modelOptions:un,modelSchema:Qo},[Je]:{model:We,modelOptions:cn,modelSchema:Yo},[st]:{model:oo,modelOptions:gn,modelSchema:it},[tt]:{model:eo,modelOptions:_n,modelSchema:nt},[Xo]:{model:Xe,modelOptions:hn,modelSchema:Zo},[et]:{model:Ze,modelOptions:fn,modelSchema:ot},[at]:{model:to,modelOptions:Tn,modelSchema:rt},[pt]:{model:no,modelOptions:Mn,modelSchema:lt}};this.embeddingModelFactories={[mt]:{model:so,modelOptions:yn,modelSchema:dt},[ct]:{model:io,modelOptions:On,modelSchema:ut},[ht]:{model:ao,modelOptions:Cn,modelSchema:ft}};}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 provider.ProviderError({info:`OpenAI chat model: ${t} not found`,cause:new Error(`OpenAI chat model: ${t} not found, available chat models:
8
- [${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 provider.ProviderError({info:`OpenAI embedding model: ${t} not found`,cause:new Error(`OpenAI embedding model: ${t} not found, available embedding models:
9
- [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[t].model,s=this.embeddingModelFactories[t].modelOptions.parse(e);return new o(s)}};j.baseUrl="https://api.openai.com/v1";var h=zod.z.enum([types.SystemRoleLiteral,types.UserRoleLiteral,types.AssistantRoleLiteral,types.ToolRoleLiteral]),f={system:types.SystemRoleLiteral,user:types.UserRoleLiteral,assistant:types.AssistantRoleLiteral,tool:types.ToolRoleLiteral};var M=[types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],y=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]),tr=[types.TextModalityLiteral],nr=zod.z.enum([types.TextModalityLiteral]),S=[types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],x=zod.z.enum([types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]);var lo=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Rn=zod.z.object({content:zod.z.array(lo.extend({top_logprobs:zod.z.array(lo)})).nullable().optional(),refusal:zod.z.array(lo.extend({top_logprobs:zod.z.array(lo)})).nullable().optional()}).nullable(),ms=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()})})),An=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:ms.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Rn.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()})}),ds=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()})),En=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:ds.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Rn.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()});var cs=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()})}),us=zod.z.enum(["none","auto","required"]),hs=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),fs=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()})})),gt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),_s=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()})}),gs=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)})}),Ts=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(gt).min(1))}),Ms=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([gt,_s])).min(1))}),ys=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(gt).min(1)).optional(),tool_calls:zod.z.array(gs).min(1).optional()}),Os=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),Cs=zod.z.union([Ts,Ms,ys,Os]),Gn=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Cs).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:fs.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(cs).optional(),tool_choice:us.or(hs).optional(),reasoning_effort:zod.z.enum(["minimal","low","medium","high"]).optional(),verbosity:zod.z.enum(["low","medium","high"]).optional()});var u=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()}),d=class{constructor(e,t){this.version="v1";let o=u.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(o.baseUrl||j.baseUrl),this.streamChatUrl=provider.urlWithoutTrailingSlash(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=provider.urlWithoutTrailingSlash(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return b({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 l=/(\d+)(h|m|s|ms)/g,T={h:36e5,m:6e4,s:1e3,ms:1},g,P=0;for(;(g=l.exec(r))!==null;){let O=parseInt(g[1]),C=g[2];P+=O*T[C];}return P},o=0,s=0,a=!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:a,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=Gn.safeParse(e);if(!t.success)throw new provider.InvalidModelRequestError({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 provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let a={};o.response_format&&(a.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(a.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"?a.toolChoice=o.tool_choice:a.toolChoice=o.tool_choice.function.name),a.seed=o.seed,a.maxTokens=o.max_completion_tokens,a.temperature=o.temperature,a.topP=o.top_p,a.presencePenalty=o.presence_penalty,a.frequencyPenalty=o.frequency_penalty,a.stop=o.stop,a.logProbs=o.logprobs,a.topLogProbs=o.top_logprobs,a.reasoningEffort=o.reasoning_effort,a.verbosity=o.verbosity;let m=types.Config().parse(provider.removeUndefinedEntries(a)),r=[],l={};o.messages.forEach(g=>{let P=g.role;switch(P){case"system":{let O=g.content;if(typeof O=="string")r.push({role:P,content:[{modality:types.TextModalityLiteral,value:O}]});else {let C=O.map(I=>({modality:types.TextModalityLiteral,value:I.text}));r.push({role:P,content:C});}}break;case"user":{let O=g.content;if(typeof O=="string")r.push({role:P,content:[{modality:types.TextModalityLiteral,value:O}]});else {let C=O.map(I=>I.type==="text"?{modality:types.TextModalityLiteral,value:I.text}:I.image_url.url.startsWith("data:")?{modality:types.ImageModalityLiteral,detail:I.image_url.detail||"auto",value:{type:types.Base64ImageContentTypeLiteral,base64:I.image_url.url,mediaType:provider.getMimeTypeFromBase64(I.image_url.url)}}:{modality:types.ImageModalityLiteral,detail:I.image_url.detail||"auto",value:{type:types.UrlImageContentTypeLiteral,url:I.image_url.url}});r.push({role:P,content:C});}}break;case"assistant":{let O=[];if(!g.content&&!g.tool_calls)throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(g.content){let C=g.content;typeof C=="string"?O.push({modality:types.TextModalityLiteral,value:C}):C.forEach(I=>{O.push({modality:types.TextModalityLiteral,value:I.text});});}g.tool_calls&&g.tool_calls.forEach((I,E)=>{let q={modality:types.ToolCallModalityLiteral,id:I.id,index:E,name:I.function.name,arguments:I.function.arguments};O.push(q),l[q.id]=q;}),r.push({role:P,content:O});}break;case"tool":{let O=g;r.push({role:P,content:[{modality:types.ToolResponseModalityLiteral,id:O.tool_call_id,index:l[O.tool_call_id].index,name:l[O.tool_call_id].name,data:O.content}]});}break}});let T=[];return o.tools&&o.tools.forEach(g=>{T.push({type:"function",definition:{schema:{name:g.function.name,description:g.function.description||"",strict:g.function.strict,parameters:g.function.parameters}}});}),{modelName:s,config:m,messages:r,tools:T.length>0?T:void 0}}transformConfig(e,t,o){let s=e.toolChoice;delete e.toolChoice;let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let m=a.data;s!==void 0&&(m.toolChoice=s),Object.keys(m).forEach(l=>{if(!(l in this.modelSchema.config.def))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${l}',
7
+ var Fn=Object.defineProperty,$n=Object.defineProperties;var Hn=Object.getOwnPropertyDescriptors;var bt=Object.getOwnPropertySymbols;var Vn=Object.prototype.hasOwnProperty,Kn=Object.prototype.propertyIsEnumerable;var ee=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Jn=t=>{throw TypeError(t)};var Pt=(t,e,n)=>e in t?Fn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,b=(t,e)=>{for(var n in e||(e={}))Vn.call(e,n)&&Pt(t,n,e[n]);if(bt)for(var n of bt(e))Kn.call(e,n)&&Pt(t,n,e[n]);return t},v=(t,e)=>$n(t,Hn(e));var A=(t,e,n)=>new Promise((o,s)=>{var a=l=>{try{r(n.next(l));}catch(T){s(T);}},m=l=>{try{r(n.throw(l));}catch(T){s(T);}},r=l=>l.done?o(l.value):Promise.resolve(l.value).then(a,m);r((n=n.apply(t,e)).next());}),St=function(t,e){this[0]=t,this[1]=e;},co=(t,e,n)=>{var o=(m,r,l,T)=>{try{var g=n[m](r),P=(r=g.value)instanceof St,O=g.done;Promise.resolve(P?r[0]:r).then(C=>P?o(m==="return"?m:"next",r[1]?{done:C.done,value:C.value}:C,l,T):l({value:C,done:O})).catch(C=>o("throw",C,l,T));}catch(C){T(C);}},s=m=>a[m]=r=>new Promise((l,T)=>o(m,r,l,T)),a={};return n=n.apply(t,e),a[ee("asyncIterator")]=()=>a,s("next"),s("throw"),s("return"),a},It=t=>{var e=t[ee("asyncIterator")],n=!1,o,s={};return e==null?(e=t[ee("iterator")](),o=a=>s[a]=m=>e[a](m)):(e=e.call(t),o=a=>s[a]=m=>{if(n){if(n=!1,a==="throw")throw m;return m}return n=!0,{done:!1,value:new St(new Promise(r=>{var l=e[a](m);l instanceof Object||Jn("Object expected"),r(l);}),1)}}),s[ee("iterator")]=()=>s,o("next"),"throw"in e?o("throw"):s.throw=a=>{throw a},"return"in e&&o("return"),s};var uo=provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),fo=t=>provider.RangeConfigItem({param:"max_completion_tokens",title:provider.CHAT_CONFIG.MAX_TOKENS.title,description:provider.CHAT_CONFIG.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),_o=t=>provider.MultiStringConfigItem({param:"stop",title:provider.CHAT_CONFIG.STOP(t).title,description:provider.CHAT_CONFIG.STOP(t).description,max:t}),go=provider.RangeConfigItem({param:"top_p",title:provider.CHAT_CONFIG.TOP_P.title,description:provider.CHAT_CONFIG.TOP_P.description,min:0,max:1,step:.01,default:1}),To=provider.RangeConfigItem({param:"frequency_penalty",title:provider.CHAT_CONFIG.FREQUENCY_PENALTY.title,description:provider.CHAT_CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Mo=provider.RangeConfigItem({param:"presence_penalty",title:provider.CHAT_CONFIG.PRESENCE_PENALTY.title,description:provider.CHAT_CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),yo=provider.RangeConfigItem({param:"seed",title:provider.CHAT_CONFIG.SEED.title,description:provider.CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),Oo=provider.SelectBooleanConfigItem({param:"logprobs",title:provider.CHAT_CONFIG.LOG_PROBS.title,description:provider.CHAT_CONFIG.LOG_PROBS.description,default:!1}),Co=provider.RangeConfigItem({param:"top_logprobs",title:provider.CHAT_CONFIG.TOP_LOG_PROBS.title,description:provider.CHAT_CONFIG.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),bo=provider.SelectStringConfigItem({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"]}),Po=provider.SelectStringConfigItem({param:"reasoning_effort",title:"Reasoning Effort",description:"Controls the depth of the model's reasoning before delivering an answer. 'minimal' prioritizes speed, 'high' engages in deep reasoning.",default:"medium",choices:["minimal","low","medium","high"]}),So=provider.SelectStringConfigItem({param:"verbosity",title:"Verbosity",description:"Controls the length and detail of the model's responses, independent of reasoning depth. 'low' generates concise answers, 'high' provides comprehensive responses.",default:"medium",choices:["low","medium","high"]});var N=(t,e)=>zod.z.object({temperature:uo.schema,maxTokens:fo(t).schema,stop:_o(e).schema,topP:go.schema,frequencyPenalty:To.schema,presencePenalty:Mo.schema,seed:yo.schema.transform(n=>n===0?void 0:n),logProbs:Oo.schema,topLogProbs:Co.schema,toolChoice:bo.schema}),z=(t,e)=>({temperature:uo.def,maxTokens:fo(t).def,stop:_o(e).def,topP:go.def,frequencyPenalty:To.def,presencePenalty:Mo.def,seed:yo.def,logProbs:Oo.def,topLogProbs:Co.def,toolChoice:bo.def});var xt=provider.ObjectSchemaConfigItem({param:"response_schema",title:provider.CHAT_CONFIG.RESPONSE_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_SCHEMA.description,objectSchema:types.ResponseSchema}),Rt=provider.SelectStringConfigItem({param:"response_format",title:provider.CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),j=(t,e)=>v(b({},z(t,e)),{responseFormat:Rt.def,responseSchema:xt.def}),F=(t,e)=>N(t,e).extend({responseFormat:Rt.schema,responseSchema:xt.schema});var At=(t,e)=>v(b({},z(t,e)),{reasoningEffort:Po.def,verbosity:So.def,responseFormat:j(t,e).responseFormat,responseSchema:j(t,e).responseSchema}),Et=(t,e)=>N(t,e).extend({reasoningEffort:Po.schema,verbosity:So.schema,responseFormat:F(t,e).shape.responseFormat,responseSchema:F(t,e).shape.responseSchema});var kt=provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),wt=provider.SelectStringConfigItem({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"]}),vt=(t,e)=>v(b({},j(t,e)),{temperature:kt.def,reasoningEffort:wt.def}),Dt=(t,e)=>F(t,e).extend({temperature:kt.schema,reasoningEffort:wt.schema});var qt=provider.SelectStringConfigItem({param:"response_format",title:provider.CHAT_CONFIG.RESPONSE_FORMAT.title,description:provider.CHAT_CONFIG.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),Nt=(t,e)=>v(b({},z(t,e)),{responseFormat:qt.def}),zt=(t,e)=>N(t,e).extend({responseFormat:qt.schema});var Io=provider.SelectStringConfigItem({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),xo=t=>provider.RangeConfigItem({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:t,step:1,default:t});var te=()=>zod.z.object({encodingFormat:Io.schema}),ne=()=>({encodingFormat:Io.def});var Bt=t=>te().extend({dimensions:xo(t).schema}),Ut=t=>v(b({},ne()),{dimensions:xo(t).def});var i={base:(t,e)=>({def:z(t,e),schema:N(t,e)}),responseFormat:(t,e)=>({def:Nt(t,e),schema:zt(t,e)}),responseSchema:(t,e)=>({def:j(t,e),schema:F(t,e)}),oSeries:(t,e)=>({def:vt(t,e),schema:Dt(t,e)}),gpt5:(t,e)=>({def:At(t,e),schema:Et(t,e)})},D={base:()=>({def:ne(),schema:te()}),dimensions:t=>({def:Ut(t),schema:Bt(t)})};var _={"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}}}]},"gpt-5":{modelName:"gpt-5",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}}]},"gpt-5-mini":{modelName:"gpt-5-mini",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:2}}}]},"gpt-5-nano":{modelName:"gpt-5-nano",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.05,outputPricePerMillion:.4}}}]},"gpt-5-chat-latest":{modelName:"gpt-5-chat-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}}]}};var ps="openai",$=class{constructor(){this.version="v1";this.name=ps;this.chatModelFactories={[pe]:{model:le,modelOptions:Ht,modelSchema:Eo},[se]:{model:ie,modelOptions:Ft,modelSchema:Ro},[ae]:{model:re,modelOptions:$t,modelSchema:Ao},[me]:{model:de,modelOptions:Vt,modelSchema:Go},[ce]:{model:he,modelOptions:Kt,modelSchema:ko},[ue]:{model:fe,modelOptions:Jt,modelSchema:wo},[_e]:{model:ge,modelOptions:Wt,modelSchema:vo},[Te]:{model:Me,modelOptions:Yt,modelSchema:Do},[ye]:{model:Oe,modelOptions:Qt,modelSchema:Lo},[Ce]:{model:be,modelOptions:Xt,modelSchema:qo},[Pe]:{model:Se,modelOptions:Zt,modelSchema:No},[Ie]:{model:xe,modelOptions:en,modelSchema:zo},[Re]:{model:Ae,modelOptions:on,modelSchema:Bo},[Ee]:{model:Ge,modelOptions:tn,modelSchema:Uo},[ke]:{model:we,modelOptions:nn,modelSchema:jo},[ve]:{model:De,modelOptions:sn,modelSchema:Fo},[Le]:{model:qe,modelOptions:an,modelSchema:$o},[Be]:{model:Ue,modelOptions:pn,modelSchema:Vo},[$e]:{model:He,modelOptions:mn,modelSchema:Jo},[Ve]:{model:Ke,modelOptions:dn,modelSchema:Wo},[je]:{model:Fe,modelOptions:ln,modelSchema:Ko},[Ne]:{model:ze,modelOptions:rn,modelSchema:Ho},[Ye]:{model:Qe,modelOptions:hn,modelSchema:Qo},[Je]:{model:We,modelOptions:cn,modelSchema:Yo},[st]:{model:oo,modelOptions:gn,modelSchema:it},[tt]:{model:eo,modelOptions:_n,modelSchema:nt},[Xo]:{model:Xe,modelOptions:un,modelSchema:Zo},[et]:{model:Ze,modelOptions:fn,modelSchema:ot},[at]:{model:to,modelOptions:Tn,modelSchema:rt},[pt]:{model:no,modelOptions:Mn,modelSchema:lt}};this.embeddingModelFactories={[mt]:{model:so,modelOptions:yn,modelSchema:dt},[ct]:{model:io,modelOptions:On,modelSchema:ht},[ut]:{model:ao,modelOptions:Cn,modelSchema:ft}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,n)=>(e[n]=this.chatModelFactories[n].modelSchema,e),{})}chatModel(e){let n=e.modelName;if(!(n in this.chatModelFactories))throw new provider.ProviderError({info:`OpenAI chat model: ${n} not found`,cause:new Error(`OpenAI chat model: ${n} not found, available chat models:
8
+ [${this.chatModelLiterals().join(", ")}]`)});let o=this.chatModelFactories[n].model,s=this.chatModelFactories[n].modelOptions.parse(e);return new o(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,n)=>(e[n]=this.embeddingModelFactories[n].modelSchema,e),{})}embeddingModel(e){let n=e.modelName;if(!(n in this.embeddingModelFactories))throw new provider.ProviderError({info:`OpenAI embedding model: ${n} not found`,cause:new Error(`OpenAI embedding model: ${n} not found, available embedding models:
9
+ [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[n].model,s=this.embeddingModelFactories[n].modelOptions.parse(e);return new o(s)}};$.baseUrl="https://api.openai.com/v1";var u=zod.z.enum([types.SystemRoleLiteral,types.UserRoleLiteral,types.AssistantRoleLiteral,types.ToolRoleLiteral]),f={system:types.SystemRoleLiteral,user:types.UserRoleLiteral,assistant:types.AssistantRoleLiteral,tool:types.ToolRoleLiteral};var M=[types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],y=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]),nr=[types.TextModalityLiteral],sr=zod.z.enum([types.TextModalityLiteral]),I=[types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],x=zod.z.enum([types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]);var lo=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Rn=zod.z.object({content:zod.z.array(lo.extend({top_logprobs:zod.z.array(lo)})).nullable().optional(),refusal:zod.z.array(lo.extend({top_logprobs:zod.z.array(lo)})).nullable().optional()}).nullable(),ms=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()})})),An=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:ms.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Rn.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()})}),ds=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()})),En=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:ds.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Rn.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()});var cs=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()})}),hs=zod.z.enum(["none","auto","required"]),us=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),fs=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()})})),gt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),_s=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()})}),gs=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)})}),Ts=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(gt).min(1))}),Ms=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([gt,_s])).min(1))}),ys=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(gt).min(1)).optional(),tool_calls:zod.z.array(gs).min(1).optional()}),Os=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),Cs=zod.z.union([Ts,Ms,ys,Os]),Gn=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Cs).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:fs.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(cs).optional(),tool_choice:hs.or(us).optional(),reasoning_effort:zod.z.enum(["minimal","low","medium","high"]).optional(),verbosity:zod.z.enum(["low","medium","high"]).optional()});var h=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()}),d=class{constructor(e,n){this.version="v1";let o=h.parse(n);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(o.baseUrl||$.baseUrl),this.streamChatUrl=provider.urlWithoutTrailingSlash(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=provider.urlWithoutTrailingSlash(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return b({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){let n=r=>{let l=/(\d+)(h|m|s|ms)/g,T={h:36e5,m:6e4,s:1e3,ms:1},g,P=0;for(;(g=l.exec(r))!==null;){let O=parseInt(g[1]),C=g[2];P+=O*T[C];}return P},o=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(o=n(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=n(e["x-ratelimit-reset-tokens"]));let m=Math.max(o,s);return {shouldRetry:a,delayMs:m}}getTokenCount(e){return e.reduce((n,o)=>n+o.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(e){let n=Gn.safeParse(e);if(!n.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:n.error});let o=n.data,s=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let a={};o.response_format&&(a.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(a.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"?a.toolChoice=o.tool_choice:a.toolChoice=o.tool_choice.function.name),a.seed=o.seed,a.maxTokens=o.max_completion_tokens,a.temperature=o.temperature,a.topP=o.top_p,a.presencePenalty=o.presence_penalty,a.frequencyPenalty=o.frequency_penalty,a.stop=o.stop,a.logProbs=o.logprobs,a.topLogProbs=o.top_logprobs,a.reasoningEffort=o.reasoning_effort,a.verbosity=o.verbosity;let m=types.Config().parse(provider.removeUndefinedEntries(a)),r=[],l={};o.messages.forEach(g=>{let P=g.role;switch(P){case"system":{let O=g.content;if(typeof O=="string")r.push({role:P,content:[{modality:types.TextModalityLiteral,value:O}]});else {let C=O.map(S=>({modality:types.TextModalityLiteral,value:S.text}));r.push({role:P,content:C});}}break;case"user":{let O=g.content;if(typeof O=="string")r.push({role:P,content:[{modality:types.TextModalityLiteral,value:O}]});else {let C=O.map(S=>S.type==="text"?{modality:types.TextModalityLiteral,value:S.text}:S.image_url.url.startsWith("data:")?{modality:types.ImageModalityLiteral,detail:S.image_url.detail||"auto",value:{type:types.Base64ImageContentTypeLiteral,base64:S.image_url.url,mediaType:provider.getMimeTypeFromBase64(S.image_url.url)}}:{modality:types.ImageModalityLiteral,detail:S.image_url.detail||"auto",value:{type:types.UrlImageContentTypeLiteral,url:S.image_url.url}});r.push({role:P,content:C});}}break;case"assistant":{let O=[];if(!g.content&&!g.tool_calls)throw new provider.InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(g.content){let C=g.content;typeof C=="string"?O.push({modality:types.TextModalityLiteral,value:C}):C.forEach(S=>{O.push({modality:types.TextModalityLiteral,value:S.text});});}g.tool_calls&&g.tool_calls.forEach((S,E)=>{let q={modality:types.ToolCallModalityLiteral,id:S.id,index:E,name:S.function.name,arguments:S.function.arguments};O.push(q),l[q.id]=q;}),r.push({role:P,content:O});}break;case"tool":{let O=g;r.push({role:P,content:[{modality:types.ToolResponseModalityLiteral,id:O.tool_call_id,index:l[O.tool_call_id].index,name:l[O.tool_call_id].name,data:O.content}]});}break}});let T=[];return o.tools&&o.tools.forEach(g=>{T.push({type:"function",definition:{schema:{name:g.function.name,description:g.function.description||"",strict:g.function.strict,parameters:g.function.parameters}}});}),{modelName:s,config:m,messages:r,tools:T.length>0?T:void 0}}transformConfig(e,n,o){let s=e.toolChoice;delete e.toolChoice;let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let m=a.data;s!==void 0&&(m.toolChoice=s),Object.keys(m).forEach(l=>{if(!(l in this.modelSchema.config.def))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${l}',
10
10
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((l,T)=>{let g=this.modelSchema.config.def[T],P=g.param,O=m[T];return P==="max_completion_tokens"&&g.type==="range"&&O===0?l[P]=g.max:l[P]=O,l},{});if(r.top_logprobs&&!r.logprobs)throw new provider.InvalidConfigError({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 l=r.tool_choice;if(!o||o&&o.length===0)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let T=this.modelSchema.config.def.toolChoice;if(!T.choices.includes(l))if(o.map(g=>g.definition.schema.name).includes(l))r.tool_choice={type:"function",function:{name:l}};else throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${l}' is not part of provided 'tools' names or
11
- one of [${T.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let l=r.response_format;if(l==="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 provider.InvalidConfigError({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:l};}return r}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let t=e.map(s=>{let a=types.Message().safeParse(s);if(!a.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:a.error});return a.data});return t.forEach(s=>{s.content.forEach(a=>{if(!this.modelSchema.modalities.includes(a.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${a.modality}',
12
- available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),t.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
13
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:t.map(s=>{switch(s.role){case types.SystemRoleLiteral:{let a=[];return s.content.forEach(m=>{if(m.modality===types.TextModalityLiteral)a.push({type:"text",text:m.value});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${m.modality}'`)})}),{role:this.modelSchema.roles[s.role],content:a}}case types.AssistantRoleLiteral:{let a=[],m=[];return s.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)a.push({type:"text",text:r.value});else if(r.modality===types.ToolCallModalityLiteral)m.push({id:r.id,type:"function",function:{name:r.name,arguments:r.arguments}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${r.modality}'`)})}),b({role:this.modelSchema.roles[s.role],content:a},m.length>0?{tool_calls:m}:{})}case types.UserRoleLiteral:{let a=[],m=[];s.content.forEach(l=>{if(l.modality===types.TextModalityLiteral)a.push({type:"text",text:l.value});else if(l.modality===types.ImageModalityLiteral)m.push({type:"image_url",image_url:{url:l.value.type==="url"?l.value.url:l.value.base64,detail:l.detail}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${l.modality}'`)})});let r=[...a,...m];return {role:this.modelSchema.roles[s.role],content:r}}case types.ToolRoleLiteral:{if(s.content.length!==1)throw new provider.InvalidMessagesError({info:`Invalid message for role : '${s.role}'`,cause:new Error(`role : '${s.role}' must have exactly one content item`)});if(s.content[0].modality!==types.ToolResponseModalityLiteral)throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' must have content with modality : '${types.ToolResponseModalityLiteral}'`)});let a=s.content[0];return {role:this.modelSchema.roles[s.role],tool_call_id:a.id,content:a.data}}default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
14
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(e){if(!this.modelSchema.modalities.includes(types.ToolCallModalityLiteral))throw new provider.InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${types.ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(s=>{let a=types.Tool().safeParse(s);if(!a.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:a.error});return a.data}).map(s=>({type:"function",function:s.definition.schema}))}}getCompleteChatUrl(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(e,t,o){return A(this,null,function*(){let s=this.transformConfig(e,t,o),a=this.transformMessages(t);if(a.messages&&a.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(b(b(b(b({},this.getDefaultParams()),s),a),m));})})}transformCompleteChatResponse(e){let t=An.safeParse(e);if(t.success){if(t.data.choices.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(t.data)}`)});let o=t.data,s=[{role:types.AssistantRoleLiteral,content:[]}],a=o.choices[0].message;a.content&&s[0].content.push(types.createTextContent(a.content)),a.refusal&&s[0].content.push(types.createTextContent(a.refusal)),a.tool_calls&&a.tool_calls.forEach((T,g)=>{s[0].content.push(types.createToolCallContent(g,T.id,T.function.name,T.function.arguments));});let m={promptTokens:o.usage.prompt_tokens,completionTokens:o.usage.completion_tokens,totalTokens:o.usage.total_tokens},r=[],l=o.choices[0].logprobs;return l&&(l.content&&r.push(...l.content.map(T=>({token:T.token,logProb:T.logprob,bytes:T.bytes,topLogProbs:T.top_logprobs.map(g=>({token:g.token,logProb:g.logprob,bytes:g.bytes}))}))),l.refusal&&r.push(...l.refusal.map(T=>({token:T.token,logProb:T.logprob,bytes:T.bytes,topLogProbs:T.top_logprobs.map(g=>({token:g.token,logProb:g.logprob,bytes:g.bytes}))})))),{messages:s,usage:m,logProbs:r}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:t.error})}getStreamChatUrl(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(e,t,o){return A(this,null,function*(){let s=this.transformConfig(e,t,o),a=this.transformMessages(t);if(a.messages&&a.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(b(b(b(b({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),a),m));})})}transformStreamChatResponseChunk(e,t){return co(this,null,function*(){var r,l;let o=t+e,s=[],a="",m=0;for(;m<o.length;){let T=o.indexOf(`
15
- `,m);if(T===-1){a=o.substring(m);break}else {let g=o.substring(m,T).trim();g&&s.push(g),m=T+1;}}for(let T of s){if(T==="data: [DONE]")return;if(T.startsWith("data: ")){let g=T.substring(6);try{let P=JSON.parse(g),O=En.safeParse(P);if(O.success){let C={partialMessages:[]},I=O.data;if(I.choices.length>0){let E=I.choices[0].delta;if(E!==void 0&&Object.keys(E).length!==0){if("content"in E&&E.content!==null)C.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,E.content));else if("refusal"in E&&E.refusal!==null)C.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,E.refusal));else if("tool_calls"in E&&E.tool_calls!==void 0){let q=E.tool_calls.at(0);C.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,q.index,q.id,(r=q.function)==null?void 0:r.name,(l=q.function)==null?void 0:l.arguments));}}}I.usage&&(C.usage={promptTokens:I.usage.prompt_tokens,completionTokens:I.usage.completion_tokens,totalTokens:I.usage.total_tokens}),yield {partialResponse:C,buffer:a};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:O.error})}catch(P){throw new provider.ModelResponseError({info:`Malformed JSON received in stream: ${g}`,cause:P})}}}yield {partialResponse:{partialMessages:[]},buffer:a};})}transformProxyStreamChatResponseChunk(e,t,o,s,a){return co(this,null,function*(){yield*St(this.transformStreamChatResponseChunk(e,t));})}getProxyStreamChatUrl(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,t,o){return A(this,null,function*(){if(!t)return {};let s=b({},t);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(e,t,o){return A(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,o)})}getModelPricing(){if(!(this.modelName in _))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return _[this.modelName]}};var se="gpt-3.5-turbo-0125",Ds="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.",Ro=provider.ChatModelSchema(h,x).parse({name:se,description:Ds,maxInputTokens:4092,maxOutputTokens:4092,roles:f,modalities:S,config:{def:i.responseFormat(4092,4).def,schema:i.responseFormat(4092,4).schema},price:_[se]}),Ft=u,ie=class extends d{constructor(e){super(Ro,e);}};var ae="gpt-3.5-turbo-1106",Ns="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.",Ao=provider.ChatModelSchema(h,x).parse({name:ae,description:Ns,maxInputTokens:4092,maxOutputTokens:16385,roles:f,modalities:S,config:{def:i.responseFormat(16385,4).def,schema:i.responseFormat(16385,4).schema},price:_[ae]}),$t=u,re=class extends d{constructor(e){super(Ao,e);}};var pe="gpt-3.5-turbo",Bs="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",Eo=provider.ChatModelSchema(h,x).parse({name:pe,description:Bs,maxInputTokens:4092,maxOutputTokens:4092,roles:f,modalities:S,config:{def:i.responseFormat(4092,4).def,schema:i.responseFormat(4092,4).schema},price:_[pe]}),Ht=u,le=class extends d{constructor(e){super(Eo,e);}};var me="gpt-4-0125-preview",js="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.",Go=provider.ChatModelSchema(h,x).parse({name:me,description:js,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:S,config:{def:i.base(4092,4).def,schema:i.base(4092,4).schema},price:_[me]}),Vt=u,de=class extends d{constructor(e){super(Go,e);}};var ce="gpt-4-0613",$s="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",ko=provider.ChatModelSchema(h,x).parse({name:ce,description:$s,maxInputTokens:8192,maxOutputTokens:4092,roles:f,modalities:S,config:{def:i.base(4092,4).def,schema:i.base(4092,4).schema},price:_[ce]}),Kt=u,ue=class extends d{constructor(e){super(ko,e);}};var he="gpt-4-1106-preview",Vs="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.",wo=provider.ChatModelSchema(h,x).parse({name:he,description:Vs,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:S,config:{def:i.base(4092,4).def,schema:i.base(4092,4).schema},price:_[he]}),Jt=u,fe=class extends d{constructor(e){super(wo,e);}};var _e="gpt-4.1",Js="Flagship model for complex tasks. It is well suited for problem solving across domains. Training data up to May 2024.",vo=provider.ChatModelSchema(h,y).parse({name:_e,description:Js,maxInputTokens:1047576,maxOutputTokens:32768,roles:f,modalities:M,config:{def:i.responseSchema(32768,4).def,schema:i.responseSchema(32768,4).schema},price:_[_e]}),Wt=u,ge=class extends d{constructor(e){super(vo,e);}};var Te="gpt-4.1-mini",Ys="Provides a balance between intelligence, speed, and cost that makes it an attractive model for many use cases. Training data up to May 2024.",Lo=provider.ChatModelSchema(h,y).parse({name:Te,description:Ys,maxInputTokens:1047576,maxOutputTokens:32768,roles:f,modalities:M,config:{def:i.responseSchema(32768,4).def,schema:i.responseSchema(32768,4).schema},price:_[Te]}),Yt=u,Me=class extends d{constructor(e){super(Lo,e);}};var ye="gpt-4.1-nano",Xs="Fastest, most cost-effective GPT-4.1 model. Training data up to May 2024.",Do=provider.ChatModelSchema(h,y).parse({name:ye,description:Xs,maxInputTokens:1047576,maxOutputTokens:32768,roles:f,modalities:M,config:{def:i.responseSchema(32768,4).def,schema:i.responseSchema(32768,4).schema},price:_[ye]}),Qt=u,Oe=class extends d{constructor(e){super(Do,e);}};var Ce="gpt-5",ei="Most advanced GPT-5 model for complex reasoning and problem-solving tasks. Training data up to October 2024.",qo=provider.ChatModelSchema(h,y).parse({name:Ce,description:ei,maxInputTokens:4e5,maxOutputTokens:131072,roles:f,modalities:M,config:{def:i.gpt5(131072,4).def,schema:i.gpt5(131072,4).schema},price:_[Ce]}),Xt=u,be=class extends d{constructor(e){super(qo,e);}};var Pe="gpt-5-mini",ti="Faster, more cost-effective GPT-5 model that balances intelligence and efficiency. Training data up to October 2024.",No=provider.ChatModelSchema(h,y).parse({name:Pe,description:ti,maxInputTokens:4e5,maxOutputTokens:131072,roles:f,modalities:M,config:{def:i.gpt5(131072,4).def,schema:i.gpt5(131072,4).schema},price:_[Pe]}),Zt=u,Ie=class extends d{constructor(e){super(No,e);}};var Se="gpt-5-nano",si="Most cost-effective GPT-5 model optimized for speed and efficiency. Training data up to October 2024.",zo=provider.ChatModelSchema(h,y).parse({name:Se,description:si,maxInputTokens:4e5,maxOutputTokens:131072,roles:f,modalities:M,config:{def:i.gpt5(131072,4).def,schema:i.gpt5(131072,4).schema},price:_[Se]}),en=u,xe=class extends d{constructor(e){super(zo,e);}};var Re="gpt-5-chat-latest",ri="Latest GPT-5 model optimized for conversational use. Does not support function calling or structured outputs. Training data up to October 2024.",pi=[types.TextModalityLiteral,types.ImageModalityLiteral],li=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral]),Bo=provider.ChatModelSchema(h,li).parse({name:Re,description:ri,maxInputTokens:4e5,maxOutputTokens:131072,roles:f,modalities:pi,config:{def:i.gpt5(131072,4).def,schema:i.gpt5(131072,4).schema},price:_[Re]}),on=u,Ae=class extends d{constructor(e){super(Bo,e);}};var Ee="gpt-4-turbo-2024-04-09",di="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.",Uo=provider.ChatModelSchema(h,y).parse({name:Ee,description:di,maxInputTokens:128e3,maxOutputTokens:4096,roles:f,modalities:M,config:{def:i.responseFormat(4096,4).def,schema:i.responseFormat(4096,4).schema},price:_[Ee]}),tn=u,Ge=class extends d{constructor(e){super(Uo,e);}};var ke="gpt-4-turbo-preview",ui="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",jo=provider.ChatModelSchema(h,x).parse({name:ke,description:ui,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:S,config:{def:i.responseFormat(4092,4).def,schema:i.responseFormat(4092,4).schema},price:_[ke]}),nn=u,we=class extends d{constructor(e){super(jo,e);}};var ve="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.",Fo=provider.ChatModelSchema(h,y).parse({name:ve,description:fi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseFormat(4092,4).def,schema:i.responseFormat(4092,4).schema},price:_[ve]}),sn=u,Le=class extends d{constructor(e){super(Fo,e);}};var De="gpt-4",gi="Currently points to gpt-4-0613. Training data up to Sept 2021.",$o=provider.ChatModelSchema(h,x).parse({name:De,description:gi,maxInputTokens:8192,maxOutputTokens:4092,roles:f,modalities:S,config:{def:i.base(4092,4).def,schema:i.base(4092,4).schema},price:_[De]}),an=u,qe=class extends d{constructor(e){super($o,e);}};var Ne="gpt-4o-2024-05-13",Mi="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Ho=provider.ChatModelSchema(h,y).parse({name:Ne,description:Mi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[Ne]}),rn=u,ze=class extends d{constructor(e){super(Ho,e);}};var Be="gpt-4o-2024-08-06",Oi="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Vo=provider.ChatModelSchema(h,y).parse({name:Be,description:Oi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[Be]}),pn=u,Ue=class extends d{constructor(e){super(Vo,e);}};var je="gpt-4o-mini-2024-07-18",bi="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.",Ko=provider.ChatModelSchema(h,y).parse({name:je,description:bi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[je]}),ln=u,Fe=class extends d{constructor(e){super(Ko,e);}};var $e="gpt-4o-mini",Ii="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.",Jo=provider.ChatModelSchema(h,y).parse({name:$e,description:Ii,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[$e]}),mn=u,He=class extends d{constructor(e){super(Jo,e);}};var Ve="gpt-4o",xi="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.",Wo=provider.ChatModelSchema(h,y).parse({name:Ve,description:xi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[Ve]}),dn=u,Ke=class extends d{constructor(e){super(Wo,e);}};var Je="o1-2024-12-17",Ai="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",Yo=provider.ChatModelSchema(h,y).parse({name:Je,description:Ai,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema},price:_[Je]}),cn=u,We=class extends d{constructor(e){super(Yo,e);}};var Ye="o1",Gi="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",Qo=provider.ChatModelSchema(h,y).parse({name:Ye,description:Gi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema},price:_[Ye]}),un=u,Qe=class extends d{constructor(e){super(Qo,e);}};var Xo="o3-2025-04-16",wi="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",Zo=provider.ChatModelSchema(h,y).parse({name:Xo,description:wi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),hn=u,Xe=class extends d{constructor(e){super(Zo,e);}};var et="o3",Li="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",ot=provider.ChatModelSchema(h,y).parse({name:et,description:Li,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),fn=u,Ze=class extends d{constructor(e){super(ot,e);}};var tt="o3-mini",qi="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.",nt=provider.ChatModelSchema(h,x).parse({name:tt,description:qi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:S,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),_n=u,eo=class extends d{constructor(e){super(nt,e);}};var st="o3-mini-2025-01-31",zi="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.",it=provider.ChatModelSchema(h,x).parse({name:st,description:zi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:S,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),gn=u,oo=class extends d{constructor(e){super(it,e);}};var at="o4-mini-2025-04-16",Ui="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",rt=provider.ChatModelSchema(h,y).parse({name:at,description:Ui,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),Tn=u,to=class extends d{constructor(e){super(rt,e);}};var pt="o4-mini",Fi="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",lt=provider.ChatModelSchema(h,y).parse({name:pt,description:Fi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),Mn=u,no=class extends d{constructor(e){super(lt,e);}};var K=[types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral],J=zod.z.enum([types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral]);var zn=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()})});var Hi=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)),Bn=zod.z.object({model:zod.z.string().min(1).optional(),input:Hi,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()});var $=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),B=class{constructor(e,t){this.version="v1";let o=$.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(o.baseUrl||j.baseUrl),this.getEmbeddingsUrl=provider.urlWithoutTrailingSlash(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 l=/(\d+)(h|m|s|ms)/g,T={h:36e5,m:6e4,s:1e3,ms:1},g,P=0;for(;(g=l.exec(r))!==null;){let O=parseInt(g[1]),C=g[2];P+=O*T[C];}return P},o=0,s=0,a=!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:a,delayMs:m}}getTokenCount(e){return e.requests.reduce((t,o)=>t+o.length,0)}transformModelRequest(e){let t=Bn.safeParse(e);if(!t.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,s=o.model,a={encodingFormat:o.encoding_format,dimensions:o.dimensions},m=types.Config().parse(provider.removeUndefinedEntries(a)),r,l;return typeof o.input=="string"?l=types.EmbeddingTextModalityLiteral:typeof o.input[0]=="string"?l=types.EmbeddingTextModalityLiteral:l=types.EmbeddingTokenModalityLiteral,l===types.EmbeddingTextModalityLiteral?typeof o.input=="string"?r={modality:l,requests:[o.input]}:r={modality:l,requests:o.input}:typeof o.input[0]=="number"?r={modality:l,requests:[o.input]}:r={modality:l,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 provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:o.error});let s=o.data;return Object.keys(s).forEach(m=>{if(!this.modelSchema.config.def[m])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${m}',
16
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((m,r)=>{let T=this.modelSchema.config.def[r].param,g=s[r];return m[T]=g,m},{})}transformEmbeddingRequests(e){let t=types.EmbeddingRequests().safeParse(e);if(!t.success)throw new provider.InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:t.error});return {input:t.data.requests}}getGetEmbeddingsUrl(e,t){return A(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return A(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return A(this,null,function*(){return new Promise(o=>{o(b(b(b({},this.getDefaultParams()),this.transformConfig(e,t)),this.transformEmbeddingRequests(t)));})})}transformGetEmbeddingsResponse(e){let t,o=zn.safeParse(e);if(o.success){let s=o.data;t=typeof s.data[0].embedding=="string"?types.Base64EmbeddingLiteral:types.FloatEmbeddingLiteral;let a=s.data.map(m=>typeof m.embedding=="string"?{index:m.index,embedding:m.embedding}:{index:m.index,embedding:m.embedding});return {encodingFormat:t,embeddings:a,usage:{totalTokens:s.usage.total_tokens}}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:o.error})}};var mt="text-embedding-ada-002",ta="Most capable 2nd generation embedding model, replacing 16 first generation models",dt=provider.EmbeddingModelSchema(J).parse({name:mt,description:ta,modalities:K,maxInputTokens:8192,maxOutputTokens:1536,config:{def:L.base().def,schema:L.base().schema}}),yn=$,so=class extends B{constructor(e){super(dt,e);}};var ct="text-embedding-3-small",sa="Increased performance over 2nd generation ada embedding model",ut=provider.EmbeddingModelSchema(J).parse({name:ct,description:sa,modalities:K,maxInputTokens:8192,maxOutputTokens:1536,config:{def:L.dimensions(1536).def,schema:L.dimensions(1536).schema}}),On=$,io=class extends B{constructor(e){super(ut,e);}};var ht="text-embedding-3-large",aa="Most capable embedding model for both english and non-english tasks",ft=provider.EmbeddingModelSchema(J).parse({name:ht,description:aa,modalities:K,maxInputTokens:8192,maxOutputTokens:3072,config:{def:L.dimensions(3072).def,schema:L.dimensions(3072).schema}}),Cn=$,ao=class extends B{constructor(e){super(ft,e);}};
11
+ one of [${T.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let l=r.response_format;if(l==="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 provider.InvalidConfigError({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:l};}return r}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let n=e.map(s=>{let a=types.Message().safeParse(s);if(!a.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:a.error});return a.data});return n.forEach(s=>{s.content.forEach(a=>{if(!this.modelSchema.modalities.includes(a.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${a.modality}',
12
+ available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),n.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
13
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:n.map(s=>{switch(s.role){case types.SystemRoleLiteral:{let a=[];return s.content.forEach(m=>{if(m.modality===types.TextModalityLiteral)a.push({type:"text",text:m.value});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${m.modality}'`)})}),{role:this.modelSchema.roles[s.role],content:a}}case types.AssistantRoleLiteral:{let a=[],m=[];return s.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)a.push({type:"text",text:r.value});else if(r.modality===types.ToolCallModalityLiteral)m.push({id:r.id,type:"function",function:{name:r.name,arguments:r.arguments}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${r.modality}'`)})}),b({role:this.modelSchema.roles[s.role],content:a},m.length>0?{tool_calls:m}:{})}case types.UserRoleLiteral:{let a=[],m=[];s.content.forEach(l=>{if(l.modality===types.TextModalityLiteral)a.push({type:"text",text:l.value});else if(l.modality===types.ImageModalityLiteral)m.push({type:"image_url",image_url:{url:l.value.type==="url"?l.value.url:l.value.base64,detail:l.detail}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${l.modality}'`)})});let r=[...a,...m];return {role:this.modelSchema.roles[s.role],content:r}}case types.ToolRoleLiteral:{if(s.content.length!==1)throw new provider.InvalidMessagesError({info:`Invalid message for role : '${s.role}'`,cause:new Error(`role : '${s.role}' must have exactly one content item`)});if(s.content[0].modality!==types.ToolResponseModalityLiteral)throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' must have content with modality : '${types.ToolResponseModalityLiteral}'`)});let a=s.content[0];return {role:this.modelSchema.roles[s.role],tool_call_id:a.id,content:a.data}}default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
14
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(e){if(!this.modelSchema.modalities.includes(types.ToolCallModalityLiteral))throw new provider.InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${types.ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(s=>{let a=types.Tool().safeParse(s);if(!a.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:a.error});return a.data}).map(s=>({type:"function",function:s.definition.schema}))}}getCompleteChatUrl(e,n,o){return A(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,n,o){return A(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(e,n,o){return A(this,null,function*(){let s=this.transformConfig(e,n,o),a=this.transformMessages(n);if(a.messages&&a.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(b(b(b(b({},this.getDefaultParams()),s),a),m));})})}transformCompleteChatResponse(e){let n=An.safeParse(e);if(n.success){if(n.data.choices.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(n.data)}`)});let o=n.data,s=[{role:types.AssistantRoleLiteral,content:[]}],a=o.choices[0].message;a.content&&s[0].content.push(types.createTextContent(a.content)),a.refusal&&s[0].content.push(types.createTextContent(a.refusal)),a.tool_calls&&a.tool_calls.forEach((T,g)=>{s[0].content.push(types.createToolCallContent(g,T.id,T.function.name,T.function.arguments));});let m={promptTokens:o.usage.prompt_tokens,completionTokens:o.usage.completion_tokens,totalTokens:o.usage.total_tokens},r=[],l=o.choices[0].logprobs;return l&&(l.content&&r.push(...l.content.map(T=>({token:T.token,logProb:T.logprob,bytes:T.bytes,topLogProbs:T.top_logprobs.map(g=>({token:g.token,logProb:g.logprob,bytes:g.bytes}))}))),l.refusal&&r.push(...l.refusal.map(T=>({token:T.token,logProb:T.logprob,bytes:T.bytes,topLogProbs:T.top_logprobs.map(g=>({token:g.token,logProb:g.logprob,bytes:g.bytes}))})))),{messages:s,usage:m,logProbs:r}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:n.error})}getStreamChatUrl(e,n,o){return A(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,n,o){return A(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(e,n,o){return A(this,null,function*(){let s=this.transformConfig(e,n,o),a=this.transformMessages(n);if(a.messages&&a.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(b(b(b(b({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),a),m));})})}transformStreamChatResponseChunk(e,n){return co(this,null,function*(){var r,l;let o=n+e,s=[],a="",m=0;for(;m<o.length;){let T=o.indexOf(`
15
+ `,m);if(T===-1){a=o.substring(m);break}else {let g=o.substring(m,T).trim();g&&s.push(g),m=T+1;}}for(let T of s){if(T==="data: [DONE]")return;if(T.startsWith("data: ")){let g=T.substring(6);try{let P=JSON.parse(g),O=En.safeParse(P);if(O.success){let C={partialMessages:[]},S=O.data;if(S.choices.length>0){let E=S.choices[0].delta;if(E!==void 0&&Object.keys(E).length!==0){if("content"in E&&E.content!==null)C.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,E.content));else if("refusal"in E&&E.refusal!==null)C.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,E.refusal));else if("tool_calls"in E&&E.tool_calls!==void 0){let q=E.tool_calls.at(0);C.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,q.index,q.id,(r=q.function)==null?void 0:r.name,(l=q.function)==null?void 0:l.arguments));}}}S.usage&&(C.usage={promptTokens:S.usage.prompt_tokens,completionTokens:S.usage.completion_tokens,totalTokens:S.usage.total_tokens}),yield {partialResponse:C,buffer:a};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:O.error})}catch(P){throw new provider.ModelResponseError({info:`Malformed JSON received in stream: ${g}`,cause:P})}}}yield {partialResponse:{partialMessages:[]},buffer:a};})}transformProxyStreamChatResponseChunk(e,n,o,s,a){return co(this,null,function*(){yield*It(this.transformStreamChatResponseChunk(e,n));})}getProxyStreamChatUrl(e,n,o){return A(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,n,o){return A(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,n,o){return A(this,null,function*(){if(!n)return {};let s=b({},n);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(e,n,o){return A(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,n,o)})}getModelPricing(){if(!(this.modelName in _))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return _[this.modelName]}};var se="gpt-3.5-turbo-0125",Ls="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.",Ro=provider.ChatModelSchema(u,x).parse({name:se,description:Ls,maxInputTokens:4092,maxOutputTokens:4092,roles:f,modalities:I,config:{def:i.responseFormat(4092,4).def,schema:i.responseFormat(4092,4).schema},price:_[se]}),Ft=h,ie=class extends d{constructor(e){super(Ro,e);}};var ae="gpt-3.5-turbo-1106",Ns="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.",Ao=provider.ChatModelSchema(u,x).parse({name:ae,description:Ns,maxInputTokens:4092,maxOutputTokens:16385,roles:f,modalities:I,config:{def:i.responseFormat(16385,4).def,schema:i.responseFormat(16385,4).schema},price:_[ae]}),$t=h,re=class extends d{constructor(e){super(Ao,e);}};var pe="gpt-3.5-turbo",Bs="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",Eo=provider.ChatModelSchema(u,x).parse({name:pe,description:Bs,maxInputTokens:4092,maxOutputTokens:4092,roles:f,modalities:I,config:{def:i.responseFormat(4092,4).def,schema:i.responseFormat(4092,4).schema},price:_[pe]}),Ht=h,le=class extends d{constructor(e){super(Eo,e);}};var me="gpt-4-0125-preview",js="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.",Go=provider.ChatModelSchema(u,x).parse({name:me,description:js,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:I,config:{def:i.base(4092,4).def,schema:i.base(4092,4).schema},price:_[me]}),Vt=h,de=class extends d{constructor(e){super(Go,e);}};var ce="gpt-4-0613",$s="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",ko=provider.ChatModelSchema(u,x).parse({name:ce,description:$s,maxInputTokens:8192,maxOutputTokens:4092,roles:f,modalities:I,config:{def:i.base(4092,4).def,schema:i.base(4092,4).schema},price:_[ce]}),Kt=h,he=class extends d{constructor(e){super(ko,e);}};var ue="gpt-4-1106-preview",Vs="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.",wo=provider.ChatModelSchema(u,x).parse({name:ue,description:Vs,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:I,config:{def:i.base(4092,4).def,schema:i.base(4092,4).schema},price:_[ue]}),Jt=h,fe=class extends d{constructor(e){super(wo,e);}};var _e="gpt-4.1",Js="Flagship model for complex tasks. It is well suited for problem solving across domains. Training data up to May 2024.",vo=provider.ChatModelSchema(u,y).parse({name:_e,description:Js,maxInputTokens:1047576,maxOutputTokens:32768,roles:f,modalities:M,config:{def:i.responseSchema(32768,4).def,schema:i.responseSchema(32768,4).schema},price:_[_e]}),Wt=h,ge=class extends d{constructor(e){super(vo,e);}};var Te="gpt-4.1-mini",Ys="Provides a balance between intelligence, speed, and cost that makes it an attractive model for many use cases. Training data up to May 2024.",Do=provider.ChatModelSchema(u,y).parse({name:Te,description:Ys,maxInputTokens:1047576,maxOutputTokens:32768,roles:f,modalities:M,config:{def:i.responseSchema(32768,4).def,schema:i.responseSchema(32768,4).schema},price:_[Te]}),Yt=h,Me=class extends d{constructor(e){super(Do,e);}};var ye="gpt-4.1-nano",Xs="Fastest, most cost-effective GPT-4.1 model. Training data up to May 2024.",Lo=provider.ChatModelSchema(u,y).parse({name:ye,description:Xs,maxInputTokens:1047576,maxOutputTokens:32768,roles:f,modalities:M,config:{def:i.responseSchema(32768,4).def,schema:i.responseSchema(32768,4).schema},price:_[ye]}),Qt=h,Oe=class extends d{constructor(e){super(Lo,e);}};var Ce="gpt-5",ei="Most advanced GPT-5 model for complex reasoning and problem-solving tasks. Training data up to October 2024.",qo=provider.ChatModelSchema(u,y).parse({name:Ce,description:ei,maxInputTokens:4e5,maxOutputTokens:131072,roles:f,modalities:M,config:{def:i.gpt5(131072,4).def,schema:i.gpt5(131072,4).schema},price:_[Ce]}),Xt=h,be=class extends d{constructor(e){super(qo,e);}};var Pe="gpt-5-mini",ti="Faster, more cost-effective GPT-5 model that balances intelligence and efficiency. Training data up to October 2024.",No=provider.ChatModelSchema(u,y).parse({name:Pe,description:ti,maxInputTokens:4e5,maxOutputTokens:131072,roles:f,modalities:M,config:{def:i.gpt5(131072,4).def,schema:i.gpt5(131072,4).schema},price:_[Pe]}),Zt=h,Se=class extends d{constructor(e){super(No,e);}};var Ie="gpt-5-nano",si="Most cost-effective GPT-5 model optimized for speed and efficiency. Training data up to October 2024.",zo=provider.ChatModelSchema(u,y).parse({name:Ie,description:si,maxInputTokens:4e5,maxOutputTokens:131072,roles:f,modalities:M,config:{def:i.gpt5(131072,4).def,schema:i.gpt5(131072,4).schema},price:_[Ie]}),en=h,xe=class extends d{constructor(e){super(zo,e);}};var Re="gpt-5-chat-latest",ri="Latest GPT-5 model optimized for conversational use. Does not support function calling or structured outputs. Training data up to October 2024.",pi=[types.TextModalityLiteral,types.ImageModalityLiteral],li=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral]),Bo=provider.ChatModelSchema(u,li).parse({name:Re,description:ri,maxInputTokens:4e5,maxOutputTokens:131072,roles:f,modalities:pi,config:{def:i.gpt5(131072,4).def,schema:i.gpt5(131072,4).schema},price:_[Re]}),on=h,Ae=class extends d{constructor(e){super(Bo,e);}};var Ee="gpt-4-turbo-2024-04-09",di="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.",Uo=provider.ChatModelSchema(u,y).parse({name:Ee,description:di,maxInputTokens:128e3,maxOutputTokens:4096,roles:f,modalities:M,config:{def:i.responseFormat(4096,4).def,schema:i.responseFormat(4096,4).schema},price:_[Ee]}),tn=h,Ge=class extends d{constructor(e){super(Uo,e);}};var ke="gpt-4-turbo-preview",hi="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",jo=provider.ChatModelSchema(u,x).parse({name:ke,description:hi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:I,config:{def:i.responseFormat(4092,4).def,schema:i.responseFormat(4092,4).schema},price:_[ke]}),nn=h,we=class extends d{constructor(e){super(jo,e);}};var ve="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.",Fo=provider.ChatModelSchema(u,y).parse({name:ve,description:fi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseFormat(4092,4).def,schema:i.responseFormat(4092,4).schema},price:_[ve]}),sn=h,De=class extends d{constructor(e){super(Fo,e);}};var Le="gpt-4",gi="Currently points to gpt-4-0613. Training data up to Sept 2021.",$o=provider.ChatModelSchema(u,x).parse({name:Le,description:gi,maxInputTokens:8192,maxOutputTokens:4092,roles:f,modalities:I,config:{def:i.base(4092,4).def,schema:i.base(4092,4).schema},price:_[Le]}),an=h,qe=class extends d{constructor(e){super($o,e);}};var Ne="gpt-4o-2024-05-13",Mi="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Ho=provider.ChatModelSchema(u,y).parse({name:Ne,description:Mi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[Ne]}),rn=h,ze=class extends d{constructor(e){super(Ho,e);}};var Be="gpt-4o-2024-08-06",Oi="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Vo=provider.ChatModelSchema(u,y).parse({name:Be,description:Oi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[Be]}),pn=h,Ue=class extends d{constructor(e){super(Vo,e);}};var je="gpt-4o-mini-2024-07-18",bi="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.",Ko=provider.ChatModelSchema(u,y).parse({name:je,description:bi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[je]}),ln=h,Fe=class extends d{constructor(e){super(Ko,e);}};var $e="gpt-4o-mini",Si="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.",Jo=provider.ChatModelSchema(u,y).parse({name:$e,description:Si,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[$e]}),mn=h,He=class extends d{constructor(e){super(Jo,e);}};var Ve="gpt-4o",xi="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.",Wo=provider.ChatModelSchema(u,y).parse({name:Ve,description:xi,maxInputTokens:128e3,maxOutputTokens:4092,roles:f,modalities:M,config:{def:i.responseSchema(4092,4).def,schema:i.responseSchema(4092,4).schema},price:_[Ve]}),dn=h,Ke=class extends d{constructor(e){super(Wo,e);}};var Je="o1-2024-12-17",Ai="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",Yo=provider.ChatModelSchema(u,y).parse({name:Je,description:Ai,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema},price:_[Je]}),cn=h,We=class extends d{constructor(e){super(Yo,e);}};var Ye="o1",Gi="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",Qo=provider.ChatModelSchema(u,y).parse({name:Ye,description:Gi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema},price:_[Ye]}),hn=h,Qe=class extends d{constructor(e){super(Qo,e);}};var Xo="o3-2025-04-16",wi="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",Zo=provider.ChatModelSchema(u,y).parse({name:Xo,description:wi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),un=h,Xe=class extends d{constructor(e){super(Zo,e);}};var et="o3",Di="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",ot=provider.ChatModelSchema(u,y).parse({name:et,description:Di,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),fn=h,Ze=class extends d{constructor(e){super(ot,e);}};var tt="o3-mini",qi="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.",nt=provider.ChatModelSchema(u,x).parse({name:tt,description:qi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:I,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),_n=h,eo=class extends d{constructor(e){super(nt,e);}};var st="o3-mini-2025-01-31",zi="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.",it=provider.ChatModelSchema(u,x).parse({name:st,description:zi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:I,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),gn=h,oo=class extends d{constructor(e){super(it,e);}};var at="o4-mini-2025-04-16",Ui="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",rt=provider.ChatModelSchema(u,y).parse({name:at,description:Ui,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),Tn=h,to=class extends d{constructor(e){super(rt,e);}};var pt="o4-mini",Fi="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",lt=provider.ChatModelSchema(u,y).parse({name:pt,description:Fi,maxInputTokens:2e5,maxOutputTokens:1e5,roles:f,modalities:M,config:{def:i.oSeries(1e5,4).def,schema:i.oSeries(1e5,4).schema}}),Mn=h,no=class extends d{constructor(e){super(lt,e);}};var W=[types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral],Y=zod.z.enum([types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral]);var zn=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()})});var Hi=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)),Bn=zod.z.object({model:zod.z.string().min(1).optional(),input:Hi,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()});var V=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),B=class{constructor(e,n){this.version="v1";let o=V.parse(n);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(o.baseUrl||$.baseUrl),this.getEmbeddingsUrl=provider.urlWithoutTrailingSlash(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 n=r=>{let l=/(\d+)(h|m|s|ms)/g,T={h:36e5,m:6e4,s:1e3,ms:1},g,P=0;for(;(g=l.exec(r))!==null;){let O=parseInt(g[1]),C=g[2];P+=O*T[C];}return P},o=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(o=n(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=n(e["x-ratelimit-reset-tokens"]));let m=Math.max(o,s);return {shouldRetry:a,delayMs:m}}getTokenCount(e){return e.requests.reduce((n,o)=>n+o.length,0)}transformModelRequest(e){let n=Bn.safeParse(e);if(!n.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:n.error});let o=n.data,s=o.model,a={encodingFormat:o.encoding_format,dimensions:o.dimensions},m=types.Config().parse(provider.removeUndefinedEntries(a)),r,l;return typeof o.input=="string"?l=types.EmbeddingTextModalityLiteral:typeof o.input[0]=="string"?l=types.EmbeddingTextModalityLiteral:l=types.EmbeddingTokenModalityLiteral,l===types.EmbeddingTextModalityLiteral?typeof o.input=="string"?r={modality:l,requests:[o.input]}:r={modality:l,requests:o.input}:typeof o.input[0]=="number"?r={modality:l,requests:[o.input]}:r={modality:l,requests:o.input},{modelName:s,config:m,embeddingRequests:r}}transformConfig(e,n){let o=this.modelSchema.config.schema.safeParse(e);if(!o.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:o.error});let s=o.data;return Object.keys(s).forEach(m=>{if(!this.modelSchema.config.def[m])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${m}',
16
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((m,r)=>{let T=this.modelSchema.config.def[r].param,g=s[r];return m[T]=g,m},{})}transformEmbeddingRequests(e){let n=types.EmbeddingRequests().safeParse(e);if(!n.success)throw new provider.InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:n.error});return {input:n.data.requests}}getGetEmbeddingsUrl(e,n){return A(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,n){return A(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,n){return A(this,null,function*(){return new Promise(o=>{o(b(b(b({},this.getDefaultParams()),this.transformConfig(e,n)),this.transformEmbeddingRequests(n)));})})}transformGetEmbeddingsResponse(e){let n,o=zn.safeParse(e);if(o.success){let s=o.data;n=typeof s.data[0].embedding=="string"?types.Base64EmbeddingLiteral:types.FloatEmbeddingLiteral;let a=s.data.map(m=>typeof m.embedding=="string"?{index:m.index,embedding:m.embedding}:{index:m.index,embedding:m.embedding});return {encodingFormat:n,embeddings:a,usage:{totalTokens:s.usage.total_tokens}}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:o.error})}};var mt="text-embedding-ada-002",ta="Most capable 2nd generation embedding model, replacing 16 first generation models",dt=provider.EmbeddingModelSchema(Y).parse({name:mt,description:ta,modalities:W,maxInputTokens:8192,maxOutputTokens:1536,config:{def:D.base().def,schema:D.base().schema}}),yn=V,so=class extends B{constructor(e){super(dt,e);}};var ct="text-embedding-3-small",sa="Increased performance over 2nd generation ada embedding model",ht=provider.EmbeddingModelSchema(Y).parse({name:ct,description:sa,modalities:W,maxInputTokens:8192,maxOutputTokens:1536,config:{def:D.dimensions(1536).def,schema:D.dimensions(1536).schema}}),On=V,io=class extends B{constructor(e){super(ht,e);}};var ut="text-embedding-3-large",aa="Most capable embedding model for both english and non-english tasks",ft=provider.EmbeddingModelSchema(Y).parse({name:ut,description:aa,modalities:W,maxInputTokens:8192,maxOutputTokens:3072,config:{def:D.dimensions(3072).def,schema:D.dimensions(3072).schema}}),Cn=V,ao=class extends B{constructor(e){super(ft,e);}};
17
17
 
18
18
  exports.BaseChatModel = d;
19
- exports.BaseChatModelOptions = u;
19
+ exports.BaseChatModelOptions = h;
20
20
  exports.BaseEmbeddingModel = B;
21
- exports.BaseEmbeddingModelOptions = $;
21
+ exports.BaseEmbeddingModelOptions = V;
22
22
  exports.ChatModelBaseConfigDef = z;
23
23
  exports.ChatModelBaseConfigSchema = N;
24
- exports.ChatModelGPT5ConfigDef = xt;
25
- exports.ChatModelGPT5ConfigSchema = Rt;
24
+ exports.ChatModelGPT5ConfigDef = At;
25
+ exports.ChatModelGPT5ConfigSchema = Et;
26
26
  exports.ChatModelOSeriesConfigDef = vt;
27
- exports.ChatModelOSeriesConfigSchema = Lt;
27
+ exports.ChatModelOSeriesConfigSchema = Dt;
28
28
  exports.ChatModelResponseFormatConfigDef = Nt;
29
29
  exports.ChatModelResponseFormatConfigSchema = zt;
30
- exports.ChatModelResponseSchemaConfigDef = ee;
31
- exports.ChatModelResponseSchemaConfigSchema = oe;
30
+ exports.ChatModelResponseSchemaConfigDef = j;
31
+ exports.ChatModelResponseSchemaConfigSchema = F;
32
32
  exports.EmbeddingModelBaseConfigDef = ne;
33
33
  exports.EmbeddingModelBaseConfigSchema = te;
34
34
  exports.EmbeddingModelDimensionsConfigDef = Ut;
@@ -46,20 +46,20 @@ exports.GPT_3_5_Turbo_1106Literal = ae;
46
46
  exports.GPT_3_5_Turbo_1106Options = $t;
47
47
  exports.GPT_3_5_Turbo_1106Schema = Ao;
48
48
  exports.GPT_4 = qe;
49
- exports.GPT_4Literal = De;
49
+ exports.GPT_4Literal = Le;
50
50
  exports.GPT_4Options = an;
51
51
  exports.GPT_4Schema = $o;
52
52
  exports.GPT_4_0125_Preview = de;
53
53
  exports.GPT_4_0125_PreviewLiteral = me;
54
54
  exports.GPT_4_0125_PreviewOptions = Vt;
55
55
  exports.GPT_4_0125_PreviewSchema = Go;
56
- exports.GPT_4_0613 = ue;
56
+ exports.GPT_4_0613 = he;
57
57
  exports.GPT_4_0613Literal = ce;
58
58
  exports.GPT_4_0613Options = Kt;
59
59
  exports.GPT_4_0613Schema = ko;
60
60
  exports.GPT_4_1 = ge;
61
61
  exports.GPT_4_1106_Preview = fe;
62
- exports.GPT_4_1106_PreviewLiteral = he;
62
+ exports.GPT_4_1106_PreviewLiteral = ue;
63
63
  exports.GPT_4_1106_PreviewOptions = Jt;
64
64
  exports.GPT_4_1106_PreviewSchema = wo;
65
65
  exports.GPT_4_1Literal = _e;
@@ -68,12 +68,12 @@ exports.GPT_4_1Schema = vo;
68
68
  exports.GPT_4_1_Mini = Me;
69
69
  exports.GPT_4_1_MiniLiteral = Te;
70
70
  exports.GPT_4_1_MiniOptions = Yt;
71
- exports.GPT_4_1_MiniSchema = Lo;
71
+ exports.GPT_4_1_MiniSchema = Do;
72
72
  exports.GPT_4_1_Nano = Oe;
73
73
  exports.GPT_4_1_NanoLiteral = ye;
74
74
  exports.GPT_4_1_NanoOptions = Qt;
75
- exports.GPT_4_1_NanoSchema = Do;
76
- exports.GPT_4_Turbo = Le;
75
+ exports.GPT_4_1_NanoSchema = Lo;
76
+ exports.GPT_4_Turbo = De;
77
77
  exports.GPT_4_TurboLiteral = ve;
78
78
  exports.GPT_4_TurboOptions = sn;
79
79
  exports.GPT_4_TurboSchema = Fo;
@@ -113,17 +113,17 @@ exports.GPT_5_ChatLatest = Ae;
113
113
  exports.GPT_5_ChatLatestLiteral = Re;
114
114
  exports.GPT_5_ChatLatestOptions = on;
115
115
  exports.GPT_5_ChatLatestSchema = Bo;
116
- exports.GPT_5_Mini = Ie;
116
+ exports.GPT_5_Mini = Se;
117
117
  exports.GPT_5_MiniLiteral = Pe;
118
118
  exports.GPT_5_MiniOptions = Zt;
119
119
  exports.GPT_5_MiniSchema = No;
120
120
  exports.GPT_5_Nano = xe;
121
- exports.GPT_5_NanoLiteral = Se;
121
+ exports.GPT_5_NanoLiteral = Ie;
122
122
  exports.GPT_5_NanoOptions = en;
123
123
  exports.GPT_5_NanoSchema = zo;
124
124
  exports.O1 = Qe;
125
125
  exports.O1Literal = Ye;
126
- exports.O1Options = un;
126
+ exports.O1Options = hn;
127
127
  exports.O1Schema = Qo;
128
128
  exports.O1_2024_12_17 = We;
129
129
  exports.O1_2024_12_17Literal = Je;
@@ -143,7 +143,7 @@ exports.O3Options = fn;
143
143
  exports.O3Schema = ot;
144
144
  exports.O3_2025_04_16 = Xe;
145
145
  exports.O3_2025_04_16Literal = Xo;
146
- exports.O3_2025_04_16Options = hn;
146
+ exports.O3_2025_04_16Options = un;
147
147
  exports.O3_2025_04_16Schema = Zo;
148
148
  exports.O4_Mini = no;
149
149
  exports.O4_MiniLiteral = pt;
@@ -153,15 +153,15 @@ exports.O4_Mini_2025_04_16 = to;
153
153
  exports.O4_Mini_2025_04_16Literal = at;
154
154
  exports.O4_Mini_2025_04_16Options = Tn;
155
155
  exports.O4_Mini_2025_04_16Schema = rt;
156
- exports.OpenAI = j;
156
+ exports.OpenAI = $;
157
157
  exports.OpenAIChatModelConfigs = i;
158
158
  exports.OpenAIChatModelModalities = M;
159
159
  exports.OpenAIChatModelModalitiesEnum = y;
160
- exports.OpenAIChatModelRoles = h;
160
+ exports.OpenAIChatModelRoles = u;
161
161
  exports.OpenAIChatModelRolesMap = f;
162
- exports.OpenAIChatModelTextModalities = tr;
163
- exports.OpenAIChatModelTextModalitiesEnum = nr;
164
- exports.OpenAIChatModelTextToolModalities = S;
162
+ exports.OpenAIChatModelTextModalities = nr;
163
+ exports.OpenAIChatModelTextModalitiesEnum = sr;
164
+ exports.OpenAIChatModelTextToolModalities = I;
165
165
  exports.OpenAIChatModelTextToolModalitiesEnum = x;
166
166
  exports.OpenAIChatRequest = Gn;
167
167
  exports.OpenAIChatRequestAssistantMessage = ys;
@@ -172,14 +172,14 @@ exports.OpenAIChatRequestSystemMessage = Ts;
172
172
  exports.OpenAIChatRequestTextContent = gt;
173
173
  exports.OpenAIChatRequestTool = cs;
174
174
  exports.OpenAIChatRequestToolCallContent = gs;
175
- exports.OpenAIChatRequestToolChoiceEnum = us;
176
- exports.OpenAIChatRequestToolChoiceFunction = hs;
175
+ exports.OpenAIChatRequestToolChoiceEnum = hs;
176
+ exports.OpenAIChatRequestToolChoiceFunction = us;
177
177
  exports.OpenAIChatRequestToolMessage = Os;
178
178
  exports.OpenAIChatRequestUserMessage = Ms;
179
179
  exports.OpenAICompleteChatResponse = An;
180
- exports.OpenAIEmbeddingModelConfigs = L;
181
- exports.OpenAIEmbeddingModelModalities = K;
182
- exports.OpenAIEmbeddingModelModalitiesEnum = J;
180
+ exports.OpenAIEmbeddingModelConfigs = D;
181
+ exports.OpenAIEmbeddingModelModalities = W;
182
+ exports.OpenAIEmbeddingModelModalitiesEnum = Y;
183
183
  exports.OpenAIEmbeddingRequest = Bn;
184
184
  exports.OpenAIEmbeddingRequestInput = Hi;
185
185
  exports.OpenAIGetEmbeddingsResponse = zn;
@@ -188,19 +188,19 @@ exports.OpenAIToolCallsCompleteChatResponse = ms;
188
188
  exports.OpenAIToolCallsStreamChatResponse = ds;
189
189
  exports.ProviderLiteral = ps;
190
190
  exports.Text_Embedding_3_Large = ao;
191
- exports.Text_Embedding_3_LargeLiteral = ht;
191
+ exports.Text_Embedding_3_LargeLiteral = ut;
192
192
  exports.Text_Embedding_3_LargeSchema = ft;
193
193
  exports.Text_Embedding_3_Large_Options = Cn;
194
194
  exports.Text_Embedding_3_Small = io;
195
195
  exports.Text_Embedding_3_SmallLiteral = ct;
196
- exports.Text_Embedding_3_SmallSchema = ut;
196
+ exports.Text_Embedding_3_SmallSchema = ht;
197
197
  exports.Text_Embedding_3_Small_Options = On;
198
198
  exports.Text_Embedding_Ada002 = so;
199
199
  exports.Text_Embedding_Ada002Literal = mt;
200
200
  exports.Text_Embedding_Ada002Schema = dt;
201
201
  exports.Text_Embedding_Ada002_Options = yn;
202
202
  exports.dimensions = xo;
203
- exports.encodingFormat = So;
203
+ exports.encodingFormat = Io;
204
204
  exports.frequencyPenalty = To;
205
205
  exports.logProbs = Oo;
206
206
  exports.maxTokens = fo;
@@ -208,10 +208,10 @@ exports.presencePenalty = Mo;
208
208
  exports.reasoningEffort = Po;
209
209
  exports.seed = yo;
210
210
  exports.stop = _o;
211
- exports.temperature = ho;
211
+ exports.temperature = uo;
212
212
  exports.toolChoice = bo;
213
213
  exports.topLogProbs = Co;
214
214
  exports.topP = go;
215
- exports.verbosity = Io;
215
+ exports.verbosity = So;
216
216
  //# sourceMappingURL=index.js.map
217
217
  //# sourceMappingURL=index.js.map