@adaline/openai 1.16.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +19 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -3648,7 +3648,7 @@ declare class BaseChatModel implements ChatModelV1<ChatModelSchemaType> {
|
|
|
3648
3648
|
getDefaultBaseUrl(): UrlType;
|
|
3649
3649
|
getDefaultHeaders(): HeadersType;
|
|
3650
3650
|
getDefaultParams(): ParamsType;
|
|
3651
|
-
getRetryDelay(responseHeaders: HeadersType): {
|
|
3651
|
+
getRetryDelay(responseHeaders: HeadersType, _responseData: unknown): {
|
|
3652
3652
|
shouldRetry: boolean;
|
|
3653
3653
|
delayMs: number;
|
|
3654
3654
|
};
|
|
@@ -3713,7 +3713,7 @@ declare class BaseChatModelResponsesApi implements ChatModelV1<ChatModelSchemaTy
|
|
|
3713
3713
|
getDefaultBaseUrl(): UrlType;
|
|
3714
3714
|
getDefaultHeaders(): HeadersType;
|
|
3715
3715
|
getDefaultParams(): ParamsType;
|
|
3716
|
-
getRetryDelay(responseHeaders: HeadersType): {
|
|
3716
|
+
getRetryDelay(responseHeaders: HeadersType, _responseData: unknown): {
|
|
3717
3717
|
shouldRetry: boolean;
|
|
3718
3718
|
delayMs: number;
|
|
3719
3719
|
};
|
|
@@ -7659,7 +7659,7 @@ declare class BaseEmbeddingModel implements EmbeddingModelV1<EmbeddingModelSchem
|
|
|
7659
7659
|
getDefaultBaseUrl(): UrlType;
|
|
7660
7660
|
getDefaultHeaders(): HeadersType;
|
|
7661
7661
|
getDefaultParams(): ParamsType;
|
|
7662
|
-
getRetryDelay(responseHeaders: HeadersType): {
|
|
7662
|
+
getRetryDelay(responseHeaders: HeadersType, _responseData: unknown): {
|
|
7663
7663
|
shouldRetry: boolean;
|
|
7664
7664
|
delayMs: number;
|
|
7665
7665
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3648,7 +3648,7 @@ declare class BaseChatModel implements ChatModelV1<ChatModelSchemaType> {
|
|
|
3648
3648
|
getDefaultBaseUrl(): UrlType;
|
|
3649
3649
|
getDefaultHeaders(): HeadersType;
|
|
3650
3650
|
getDefaultParams(): ParamsType;
|
|
3651
|
-
getRetryDelay(responseHeaders: HeadersType): {
|
|
3651
|
+
getRetryDelay(responseHeaders: HeadersType, _responseData: unknown): {
|
|
3652
3652
|
shouldRetry: boolean;
|
|
3653
3653
|
delayMs: number;
|
|
3654
3654
|
};
|
|
@@ -3713,7 +3713,7 @@ declare class BaseChatModelResponsesApi implements ChatModelV1<ChatModelSchemaTy
|
|
|
3713
3713
|
getDefaultBaseUrl(): UrlType;
|
|
3714
3714
|
getDefaultHeaders(): HeadersType;
|
|
3715
3715
|
getDefaultParams(): ParamsType;
|
|
3716
|
-
getRetryDelay(responseHeaders: HeadersType): {
|
|
3716
|
+
getRetryDelay(responseHeaders: HeadersType, _responseData: unknown): {
|
|
3717
3717
|
shouldRetry: boolean;
|
|
3718
3718
|
delayMs: number;
|
|
3719
3719
|
};
|
|
@@ -7659,7 +7659,7 @@ declare class BaseEmbeddingModel implements EmbeddingModelV1<EmbeddingModelSchem
|
|
|
7659
7659
|
getDefaultBaseUrl(): UrlType;
|
|
7660
7660
|
getDefaultHeaders(): HeadersType;
|
|
7661
7661
|
getDefaultParams(): ParamsType;
|
|
7662
|
-
getRetryDelay(responseHeaders: HeadersType): {
|
|
7662
|
+
getRetryDelay(responseHeaders: HeadersType, _responseData: unknown): {
|
|
7663
7663
|
shouldRetry: boolean;
|
|
7664
7664
|
delayMs: number;
|
|
7665
7665
|
};
|
package/dist/index.js
CHANGED
|
@@ -4,18 +4,18 @@ var zod = require('zod');
|
|
|
4
4
|
var provider = require('@adaline/provider');
|
|
5
5
|
var types = require('@adaline/types');
|
|
6
6
|
|
|
7
|
-
var Ns=Object.defineProperty,qs=Object.defineProperties;var zs=Object.getOwnPropertyDescriptors;var dn=Object.getOwnPropertySymbols;var Us=Object.prototype.hasOwnProperty,Bs=Object.prototype.propertyIsEnumerable;var ye=(i,e)=>(e=Symbol[i])?e:Symbol.for("Symbol."+i),js=i=>{throw TypeError(i)};var cn=(i,e,n)=>e in i?Ns(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,b=(i,e)=>{for(var n in e||(e={}))Us.call(e,n)&&cn(i,n,e[n]);if(dn)for(var n of dn(e))Bs.call(e,n)&&cn(i,n,e[n]);return i},q=(i,e)=>qs(i,zs(e));var k=(i,e,n)=>new Promise((o,t)=>{var s=p=>{try{l(n.next(p));}catch(_){t(_);}},r=p=>{try{l(n.throw(p));}catch(_){t(_);}},l=p=>p.done?o(p.value):Promise.resolve(p.value).then(s,r);l((n=n.apply(i,e)).next());}),un=function(i,e){this[0]=i,this[1]=e;},ie=(i,e,n)=>{var o=(r,l,p,_)=>{try{var f=n[r](l),I=(l=f.value)instanceof un,P=f.done;Promise.resolve(I?l[0]:l).then(S=>I?o(r==="return"?r:"next",l[1]?{done:S.done,value:S.value}:S,p,_):p({value:S,done:P})).catch(S=>o("throw",S,p,_));}catch(S){_(S);}},t=r=>s[r]=l=>new Promise((p,_)=>o(r,l,p,_)),s={};return n=n.apply(i,e),s[ye("asyncIterator")]=()=>s,t("next"),t("throw"),t("return"),s},Me=i=>{var e=i[ye("asyncIterator")],n=!1,o,t={};return e==null?(e=i[ye("iterator")](),o=s=>t[s]=r=>e[s](r)):(e=e.call(i),o=s=>t[s]=r=>{if(n){if(n=!1,s==="throw")throw r;return r}return n=!0,{done:!1,value:new un(new Promise(l=>{var p=e[s](r);p instanceof Object||js("Object expected"),l(p);}),1)}}),t[ye("iterator")]=()=>t,o("next"),"throw"in e?o("throw"):t.throw=s=>{throw s},"return"in e&&o("return"),t};var $o=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=i=>provider.RangeConfigItem({param:"max_completion_tokens",title:provider.CHAT_CONFIG.MAX_TOKENS.title,description:provider.CHAT_CONFIG.MAX_TOKENS.description,min:0,max:i,step:1,default:0}),Ho=i=>provider.MultiStringConfigItem({param:"stop",title:provider.CHAT_CONFIG.STOP(i).title,description:provider.CHAT_CONFIG.STOP(i).description,max:i}),Vo=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}),Ko=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}),Jo=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}),Wo=provider.RangeConfigItem({param:"seed",title:provider.CHAT_CONFIG.SEED.title,description:provider.CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),Yo=provider.SelectBooleanConfigItem({param:"logprobs",title:provider.CHAT_CONFIG.LOG_PROBS.title,description:provider.CHAT_CONFIG.LOG_PROBS.description,default:!1}),Qo=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}),Xo=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"]}),Zo=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"]}),et=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 Y=(i,e)=>zod.z.object({temperature:$o.schema,maxTokens:Fo(i).schema,stop:Ho(e).schema,topP:Vo.schema,frequencyPenalty:Ko.schema,presencePenalty:Jo.schema,seed:Wo.schema.transform(n=>n===0?void 0:n),logProbs:Yo.schema,topLogProbs:Qo.schema,toolChoice:Xo.schema}),Q=(i,e)=>({temperature:$o.def,maxTokens:Fo(i).def,stop:Ho(e).def,topP:Vo.def,frequencyPenalty:Ko.def,presencePenalty:Jo.def,seed:Wo.def,logProbs:Yo.def,topLogProbs:Qo.def,toolChoice:Xo.def});var hn=provider.ObjectSchemaConfigItem({param:"response_schema",title:provider.CHAT_CONFIG.RESPONSE_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_SCHEMA.description,objectSchema:types.ResponseSchema}),fn=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=(i,e)=>q(b({},Q(i,e)),{responseFormat:fn.def,responseSchema:hn.def}),oe=(i,e)=>Y(i,e).extend({responseFormat:fn.schema,responseSchema:hn.schema});var gn=(i,e)=>q(b({},Q(i,e)),{reasoningEffort:Zo.def,verbosity:et.def,responseFormat:ee(i,e).responseFormat,responseSchema:ee(i,e).responseSchema}),_n=(i,e)=>Y(i,e).extend({reasoningEffort:Zo.schema,verbosity:et.schema,responseFormat:oe(i,e).shape.responseFormat,responseSchema:oe(i,e).shape.responseSchema});var yn=provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),Mn=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"]}),Cn=(i,e)=>q(b({},ee(i,e)),{temperature:yn.def,reasoningEffort:Mn.def}),On=(i,e)=>oe(i,e).extend({temperature:yn.schema,reasoningEffort:Mn.schema});var bn=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"]}),xn=(i,e)=>q(b({},Q(i,e)),{responseFormat:bn.def}),Sn=(i,e)=>Y(i,e).extend({responseFormat:bn.schema});var ot=provider.SelectStringConfigItem({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),tt=i=>provider.RangeConfigItem({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:i,step:1,default:i});var Oe=()=>zod.z.object({encodingFormat:ot.schema}),Pe=()=>({encodingFormat:ot.def});var In=i=>Oe().extend({dimensions:tt(i).schema}),Rn=i=>q(b({},Pe()),{dimensions:tt(i).def});var a={base:(i,e)=>({def:Q(i,e),schema:Y(i,e)}),responseFormat:(i,e)=>({def:xn(i,e),schema:Sn(i,e)}),responseSchema:(i,e)=>({def:ee(i,e),schema:oe(i,e)}),oSeries:(i,e)=>({def:Cn(i,e),schema:On(i,e)}),gpt5:(i,e)=>({def:gn(i,e),schema:_n(i,e)})},K={base:()=>({def:Pe(),schema:Oe()}),dimensions:i=>({def:Rn(i),schema:In(i)})};var g={"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}}}]},"gpt-5.1":{modelName:"gpt-5.1",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.5,outputPricePerMillion:12}}}]},"gpt-5.2":{modelName:"gpt-5.2",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.75,outputPricePerMillion:14}}}]},"gpt-5.2-chat-latest":{modelName:"gpt-5.2-chat-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.75,outputPricePerMillion:14}}}]},"gpt-5.2-pro":{modelName:"gpt-5.2-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:21,outputPricePerMillion:168}}}]}};var ti="openai",J=class{constructor(){this.version="v1";this.name=ti;this.chatModelFactories={[Re]:{model:Ae,modelOptions:kn,modelSchema:it},[be]:{model:xe,modelOptions:En,modelSchema:nt},[Se]:{model:Ie,modelOptions:Gn,modelSchema:st},[Ee]:{model:Ge,modelOptions:wn,modelSchema:at},[ke]:{model:we,modelOptions:vn,modelSchema:rt},[ve]:{model:Le,modelOptions:Ln,modelSchema:lt},[De]:{model:Ne,modelOptions:Dn,modelSchema:pt},[qe]:{model:ze,modelOptions:Nn,modelSchema:mt},[Ue]:{model:Be,modelOptions:qn,modelSchema:dt},[Ye]:{model:Qe,modelOptions:$n,modelSchema:gt},[je]:{model:$e,modelOptions:zn,modelSchema:ct},[Fe]:{model:He,modelOptions:Un,modelSchema:ut},[Je]:{model:We,modelOptions:jn,modelSchema:ft},[Ve]:{model:Ke,modelOptions:Bn,modelSchema:ht},[Xe]:{model:Ze,modelOptions:Fn,modelSchema:_t},[eo]:{model:oo,modelOptions:Hn,modelSchema:Tt},[to]:{model:no,modelOptions:Vn,modelSchema:yt},[so]:{model:io,modelOptions:Kn,modelSchema:Mt},[ao]:{model:ro,modelOptions:Jn,modelSchema:Ct},[lo]:{model:po,modelOptions:Wn,modelSchema:Ot},[mo]:{model:co,modelOptions:Yn,modelSchema:Pt},[fo]:{model:go,modelOptions:Xn,modelSchema:xt},[yo]:{model:Mo,modelOptions:es,modelSchema:It},[Co]:{model:Oo,modelOptions:os,modelSchema:Rt},[_o]:{model:To,modelOptions:Zn,modelSchema:St},[uo]:{model:ho,modelOptions:Qn,modelSchema:bt},[xo]:{model:So,modelOptions:ns,modelSchema:Et},[Po]:{model:bo,modelOptions:ts,modelSchema:At},[Nt]:{model:Eo,modelOptions:rs,modelSchema:qt},[Lt]:{model:Ao,modelOptions:as,modelSchema:Dt},[Gt]:{model:Io,modelOptions:ss,modelSchema:kt},[wt]:{model:Ro,modelOptions:is,modelSchema:vt},[zt]:{model:Go,modelOptions:ls,modelSchema:Ut},[Bt]:{model:ko,modelOptions:ps,modelSchema:jt}};this.embeddingModelFactories={[$t]:{model:wo,modelOptions:ms,modelSchema:Ft},[Ht]:{model:vo,modelOptions:ds,modelSchema:Vt},[Kt]:{model:Lo,modelOptions:cs,modelSchema:Jt}};}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[
|
|
9
|
-
[${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[n].model,t=this.embeddingModelFactories[n].modelOptions.parse(e);return new o(t)}};J.baseUrl="https://api.openai.com/v1";var d=zod.z.enum([types.SystemRoleLiteral,types.UserRoleLiteral,types.AssistantRoleLiteral,types.ToolRoleLiteral]),c={system:types.SystemRoleLiteral,user:types.UserRoleLiteral,assistant:types.AssistantRoleLiteral,tool:types.ToolRoleLiteral};var y=[types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],M=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]),fl=[types.TextModalityLiteral],gl=zod.z.enum([types.TextModalityLiteral]),w=[types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],v=zod.z.enum([types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]);var qo=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Ts=zod.z.object({content:zod.z.array(qo.extend({top_logprobs:zod.z.array(qo)})).nullable().optional(),refusal:zod.z.array(qo.extend({top_logprobs:zod.z.array(qo)})).nullable().optional()}).nullable(),si=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()})})),ys=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:si.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Ts.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()})}),ii=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()})),Ms=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:ii.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Ts.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 ai=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()})}),ri=zod.z.enum(["none","auto","required"]),li=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),pi=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()})})),Yt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),mi=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()})}),di=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)})}),ci=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(Yt).min(1))}),ui=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Yt,mi])).min(1))}),hi=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(Yt).min(1)).optional(),tool_calls:zod.z.array(di).min(1).optional()}),fi=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),gi=zod.z.union([ci,ui,hi,fi]),Cs=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(gi).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:pi.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(ai).optional(),tool_choice:ri.or(li).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()}),u=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||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 n=l=>{let p=/(\d+)(h|m|s|ms)/g,_={h:36e5,m:6e4,s:1e3,ms:1},f,I=0;for(;(f=p.exec(l))!==null;){let P=parseInt(f[1]),S=f[2];I+=P*_[S];}return I},o=0,t=0,s=!0;e["x-ratelimit-reset-requests"]&&(o=n(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(t=n(e["x-ratelimit-reset-tokens"]));let r=Math.max(o,t);return {shouldRetry:s,delayMs:r}}getTokenCount(e){return e.reduce((n,o)=>n+o.content.map(t=>t.modality==="text"?t.value:"").join(" ").length,0)}transformModelRequest(e){let n=Cs.safeParse(e);if(!n.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:n.error});let o=n.data,t=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 s={};o.response_format&&(s.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(s.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"?s.toolChoice=o.tool_choice:s.toolChoice=o.tool_choice.function.name),s.seed=o.seed,s.maxTokens=o.max_completion_tokens,s.temperature=o.temperature,s.topP=o.top_p,s.presencePenalty=o.presence_penalty,s.frequencyPenalty=o.frequency_penalty,s.stop=o.stop,s.logProbs=o.logprobs,s.topLogProbs=o.top_logprobs,s.reasoningEffort=o.reasoning_effort,s.verbosity=o.verbosity;let r=types.Config().parse(provider.removeUndefinedEntries(s)),l=[],p={};o.messages.forEach(f=>{let I=f.role;switch(I){case"system":{let P=f.content;if(typeof P=="string")l.push({role:I,content:[{modality:types.TextModalityLiteral,value:P}]});else {let S=P.map(R=>({modality:types.TextModalityLiteral,value:R.text}));l.push({role:I,content:S});}}break;case"user":{let P=f.content;if(typeof P=="string")l.push({role:I,content:[{modality:types.TextModalityLiteral,value:P}]});else {let S=P.map(R=>R.type==="text"?{modality:types.TextModalityLiteral,value:R.text}:R.image_url.url.startsWith("data:")?{modality:types.ImageModalityLiteral,detail:R.image_url.detail||"auto",value:{type:types.Base64ImageContentTypeLiteral,base64:R.image_url.url,mediaType:provider.getMimeTypeFromBase64(R.image_url.url)}}:{modality:types.ImageModalityLiteral,detail:R.image_url.detail||"auto",value:{type:types.UrlImageContentTypeLiteral,url:R.image_url.url}});l.push({role:I,content:S});}}break;case"assistant":{let P=[];if(!f.content&&!f.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(f.content){let S=f.content;typeof S=="string"?P.push({modality:types.TextModalityLiteral,value:S}):S.forEach(R=>{P.push({modality:types.TextModalityLiteral,value:R.text});});}f.tool_calls&&f.tool_calls.forEach((R,L)=>{let x={modality:types.ToolCallModalityLiteral,id:R.id,index:L,name:R.function.name,arguments:R.function.arguments};P.push(x),p[x.id]=x;}),l.push({role:I,content:P});}break;case"tool":{let P=f;l.push({role:I,content:[{modality:types.ToolResponseModalityLiteral,id:P.tool_call_id,index:p[P.tool_call_id].index,name:p[P.tool_call_id].name,data:P.content}]});}break}});let _=[];return o.tools&&o.tools.forEach(f=>{_.push({type:"function",definition:{schema:{name:f.function.name,description:f.function.description||"",strict:f.function.strict,parameters:f.function.parameters}}});}),{modelName:t,config:r,messages:l,tools:_.length>0?_:void 0}}transformConfig(e,n,o){let t=e.toolChoice;delete e.toolChoice;let s=this.modelSchema.config.schema.safeParse(e);if(!s.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:s.error});let r=s.data;t!==void 0&&(r.toolChoice=t),Object.keys(r).forEach(p=>{if(!(p in this.modelSchema.config.def))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${p}',
|
|
10
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let l=Object.keys(r).reduce((p,
|
|
11
|
-
one of [${
|
|
12
|
-
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),
|
|
13
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),
|
|
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(t=>{let
|
|
15
|
-
`,r);if(_===-1){s=o.substring(r);break}else {let f=o.substring(r,_).trim();f&&t.push(f),r=_+1;}}for(let _ of t){if(_==="data: [DONE]")return;if(_.startsWith("data: ")){let f=_.substring(6);try{let I=JSON.parse(f),P=Ms.safeParse(I);if(P.success){let S={partialMessages:[]},R=P.data;if(R.choices.length>0){let L=R.choices[0].delta;if(L!==void 0&&Object.keys(L).length!==0){if("content"in L&&L.content!==null)S.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,L.content));else if("refusal"in L&&L.refusal!==null)S.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,L.refusal));else if("tool_calls"in L&&L.tool_calls!==void 0){let x=L.tool_calls.at(0);S.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,x.index,x.id,(l=x.function)==null?void 0:l.name,(p=x.function)==null?void 0:p.arguments));}}}R.usage&&(S.usage={promptTokens:R.usage.prompt_tokens,completionTokens:R.usage.completion_tokens,totalTokens:R.usage.total_tokens}),yield {partialResponse:S,buffer:s};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:P.error})}catch(I){throw new provider.ModelResponseError({info:`Malformed JSON received in stream: ${f}`,cause:I})}}}yield {partialResponse:{partialMessages:[]},buffer:s};})}transformProxyStreamChatResponseChunk(e,n,o,t,s){return ie(this,null,function*(){yield*Me(this.transformStreamChatResponseChunk(e,n));})}getProxyStreamChatUrl(e,n,o){return k(this,null,function*(){return new Promise(t=>{t(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,n,o){return k(this,null,function*(){return new Promise(t=>{t(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,n,o){return k(this,null,function*(){if(!n)return {};let t=b({},n);return delete t.host,delete t["content-length"],t})}getProxyStreamChatHeaders(e,n,o){return k(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,n,o)})}getModelPricing(){if(!(this.modelName in g))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return g[this.modelName]}};var sn=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),Bo=class{constructor(e,n){this.version="v1";let o=sn.parse(n);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(o.baseUrl||J.baseUrl),this.responsesUrl=`${this.baseUrl}/responses`,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=l=>{let p=/(\d+)(h|m|s|ms)/g,_={h:36e5,m:6e4,s:1e3,ms:1},f,I=0;for(;(f=p.exec(l))!==null;){let P=parseInt(f[1]),S=f[2];I+=P*_[S];}return I},o=0,t=0,s=!0;e["x-ratelimit-reset-requests"]&&(o=n(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(t=n(e["x-ratelimit-reset-tokens"]));let r=Math.max(o,t);return {shouldRetry:s,delayMs:r}}getTokenCount(e){return e.reduce((n,o)=>n+o.content.map(t=>t.modality==="text"?t.value:"").join(" ").length,0)}transformModelRequest(e){throw new provider.ModelResponseError({info:"transformModelRequest not supported for Responses API models",cause:new Error("Use the standard gateway interface with config, messages, and tools parameters")})}transformConfig(e,n,o){let t=types.Config().parse(e),s={};for(let p of Object.keys(this.modelSchema.config.def)){let _=this.modelSchema.config.def[p],f=_==null?void 0:_.param;f&&t[p]!==void 0&&(s[f]=t[p]);}let r=t.toolChoice;if(r!==void 0)if(o&&o.length>0){let p=r,_=o.map(f=>f.definition.schema.name);if(["none","auto","required"].includes(p))s.tool_choice=p;else if(_.includes(p))s.tool_choice={type:"function",function:{name:p}};else throw new provider.InvalidConfigError({info:`Invalid tool choice for model : '${this.modelName}'`,cause:new Error(`Tool with name '${p}' not found in tools`)})}else throw new provider.InvalidConfigError({info:`Invalid tool choice for model : '${this.modelName}'`,cause:new Error("Tools are required when tool_choice is specified")});let l=t.responseFormat;if(l!==void 0)if(l==="json_schema"){if(!t.responseSchema)throw new provider.InvalidConfigError({info:`Invalid response schema for model : '${this.modelName}'`,cause:new Error("Response schema is required when response format is 'json_schema'")});s.response_format={type:l,json_schema:s.response_schema},delete s.response_schema;}else s.response_format={type:l};return "reasoning_effort"in s&&s.reasoning_effort!==void 0&&(s.reasoning={effort:s.reasoning_effort},delete s.reasoning_effort),"verbosity"in s&&s.verbosity!==void 0&&(s.text={verbosity:s.verbosity},delete s.verbosity),s}transformMessages(e){if(!e||e.length===0)return {messages:[]};let n=e.map(t=>{let s=types.Message().safeParse(t);if(!s.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:s.error});return s.data});return n.forEach(t=>{t.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${s.modality}'`)})});}),n.forEach(t=>{if(!Object.keys(this.modelSchema.roles).includes(t.role))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${t.role}'`)})}),n.forEach(t=>{t.content=t.content.filter(s=>s.modality!=="error"&&s.modality!=="search-result");}),{messages:n.map(t=>{switch(t.role){case types.SystemRoleLiteral:{let s=[];return t.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)s.push({type:"input_text",text:r.value});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${r.modality}'`)})}),{role:this.modelSchema.roles[t.role],content:s}}case types.AssistantRoleLiteral:{let s=[];return t.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)s.push({type:"output_text",text:r.value});else throw r.modality===types.ToolCallModalityLiteral?new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error("tool calls in message history are not supported for Responses API")}):new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${r.modality}'`)})}),{role:this.modelSchema.roles[t.role],content:s}}case types.UserRoleLiteral:{let s=[];return t.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)s.push({type:"input_text",text:r.value});else if(r.modality===types.ImageModalityLiteral){let l=r.value,p=l.type==="url"?l.url:l.base64;s.push({type:"image_url",image_url:{url:p,detail:r.detail}});}else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${r.modality}'`)})}),{role:this.modelSchema.roles[t.role],content:s}}case types.ToolRoleLiteral:{if(t.content.length!==1)throw new provider.InvalidMessagesError({info:`Invalid message for role : '${t.role}'`,cause:new Error(`role : '${t.role}' must have exactly one content item`)});if(t.content[0].modality!==types.ToolResponseModalityLiteral)throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' must have content with modality : '${types.ToolResponseModalityLiteral}'`)});let s=t.content[0];return {role:this.modelSchema.roles[t.role],tool_call_id:s.id,content:s.data}}default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' is not supported`)})}})}}transformTools(e){if(!e||e.length===0)return {tools:[]};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`)});return {tools:e.map(t=>{let s=types.Tool().safeParse(t);if(!s.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:s.error});return s.data}).map(t=>({type:"function",function:t.definition.schema}))}}getCompleteChatUrl(e,n,o){return k(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getCompleteChatHeaders(e,n,o){return k(this,null,function*(){return Promise.resolve(this.getDefaultHeaders())})}getCompleteChatData(e,n,o){return k(this,null,function*(){let t=this.transformConfig(e,n,o),s=this.transformMessages(n);if(s.messages&&s.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return Promise.resolve(q(b(b(b({},this.getDefaultParams()),t),r),{input:s.messages}))})}transformCompleteChatResponse(e){var s,r,l,p,_,f,I,P,S,R,L;let n=(e==null?void 0:e.output)||(e==null?void 0:e.outputs);if(!n||!Array.isArray(n)||n.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No output in response : ${JSON.stringify(e)}`)});let o=[{role:types.AssistantRoleLiteral,content:[]}];for(let x of n)if((x==null?void 0:x.type)==="message"&&Array.isArray(x.content))x.content.forEach(A=>{var B,C,D,H,G,O;if((A==null?void 0:A.type)==="text"||(A==null?void 0:A.type)==="output_text")A.text&&o[0].content.push(types.createTextContent(A.text));else if((A==null?void 0:A.type)==="tool_call"&&A.tool_call){let V=A.tool_call;o[0].content.push(types.createToolCallContent((B=V.index)!=null?B:0,(C=V.id)!=null?C:"",(H=(D=V.function)==null?void 0:D.name)!=null?H:"",(O=(G=V.function)==null?void 0:G.arguments)!=null?O:""));}});else if(((x==null?void 0:x.type)==="text"||(x==null?void 0:x.type)==="output_text")&&(x!=null&&x.text))o[0].content.push(types.createTextContent(x.text));else if((x==null?void 0:x.type)==="tool_call"&&x.tool_call){let A=x.tool_call;o[0].content.push(types.createToolCallContent((s=A.index)!=null?s:0,(r=A.id)!=null?r:"",(p=(l=A.function)==null?void 0:l.name)!=null?p:"",(f=(_=A.function)==null?void 0:_.arguments)!=null?f:""));}if(o[0].content.length===0){let x=n[0],A=(x==null?void 0:x.content)||[],B=[];if(A.forEach(C=>{((C==null?void 0:C.type)==="text"||(C==null?void 0:C.type)==="output_text")&&(C!=null&&C.text)&&B.push(C.text);}),B.length>0)o[0].content.push(types.createTextContent(B.join(`
|
|
16
|
-
`)));else throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No text content found in response : ${JSON.stringify(e)}`)})}let t=e.usage||{};return {messages:o,usage:{promptTokens:(
|
|
17
|
-
`,r);if(A===-1){s=o.substring(r);break}else {let B=o.substring(r,A).trim();B&&t.push(B),r=A+1;}}for(let A of t){if(A==="data: [DONE]")return;if(A.startsWith("data: ")){let B=A.substring(6);try{let C=JSON.parse(B),D={partialMessages:[]},H=!1;if((C.type==="response.output_text.delta"||C.type==="output_text.delta")&&typeof C.delta=="string"&&C.delta.length>0&&(D.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,C.delta)),H=!0),C.type==="response.content_part.added"&&C.part){let G=C.part;G.type==="output_text"&&typeof G.text=="string"&&G.text.length>0&&(D.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,G.text)),H=!0);}if(!H&&C.delta){let G=C.delta;typeof G=="string"&&G.length>0?(D.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,G)),H=!0):G&&typeof G=="object"&&G.text!==void 0&&G.text!==null?(D.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,G.text)),H=!0):Array.isArray(G.content)&&G.content.forEach(O=>{var V,me,de,ce;if((O==null?void 0:O.type)==="output_text"&&(O!=null&&O.text))D.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,O.text)),H=!0;else if((O==null?void 0:O.type)==="tool_call"&&(O!=null&&O.tool_call)){let E=O.tool_call;D.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,(V=E.index)!=null?V:0,(me=E.id)!=null?me:"",(de=E.function)==null?void 0:de.name,(ce=E.function)==null?void 0:ce.arguments)),H=!0;}});}if((C.type==="tool_call"||C.type==="tool_call.delta"||C.type==="response.tool_call.delta")&&(l=C.delta)!=null&&l.tool_call){let G=C.delta.tool_call;D.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,(p=G.index)!=null?p:0,(_=G.id)!=null?_:"",(f=G.function)==null?void 0:f.name,(I=G.function)==null?void 0:I.arguments));}if(!C.delta&&(C.output||C.outputs)){let G=C.output||C.outputs;Array.isArray(G)&&G.forEach(O=>{var V,me,de,ce;if((O==null?void 0:O.type)==="message"&&Array.isArray(O.content))O.content.forEach(E=>{var rn,ln,pn,mn;if(((E==null?void 0:E.type)==="text"||(E==null?void 0:E.type)==="output_text")&&(E!=null&&E.text))D.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,E.text));else if((E==null?void 0:E.type)==="tool_call"&&(E!=null&&E.tool_call)){let Te=E.tool_call;D.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,(rn=Te.index)!=null?rn:0,(ln=Te.id)!=null?ln:"",(pn=Te.function)==null?void 0:pn.name,(mn=Te.function)==null?void 0:mn.arguments));}});else if(((O==null?void 0:O.type)==="text"||(O==null?void 0:O.type)==="output_text")&&(O!=null&&O.text))D.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,O.text));else if((O==null?void 0:O.type)==="tool_call"&&(O!=null&&O.tool_call)){let E=O.tool_call;D.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,(V=E.index)!=null?V:0,(me=E.id)!=null?me:"",(de=E.function)==null?void 0:de.name,(ce=E.function)==null?void 0:ce.arguments));}});}C.usage&&(D.usage={promptTokens:(S=(P=C.usage.input_tokens)!=null?P:C.usage.prompt_tokens)!=null?S:0,completionTokens:(L=(R=C.usage.output_tokens)!=null?R:C.usage.completion_tokens)!=null?L:0,totalTokens:(x=C.usage.total_tokens)!=null?x:(C.usage.input_tokens||0)+(C.usage.output_tokens||0)}),(D.partialMessages.length>0||D.usage)&&(yield {partialResponse:D,buffer:s});}catch(C){throw new provider.ModelResponseError({info:`Malformed JSON received in stream: ${B}`,cause:C})}}}})}transformProxyStreamChatResponseChunk(e,n,o,t,s){return ie(this,null,function*(){yield*Me(this.transformStreamChatResponseChunk(e,n));})}getProxyStreamChatUrl(e,n,o){return k(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getProxyCompleteChatUrl(e,n,o){return k(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getProxyCompleteChatHeaders(e,n,o){return k(this,null,function*(){if(!n)return {};let t=b({},n);return delete t.host,delete t["content-length"],t})}getProxyStreamChatHeaders(e,n,o){return k(this,null,function*(){let t=yield this.getProxyCompleteChatHeaders(e,n,o);return q(b({},t),{Accept:"text/event-stream"})})}getModelPricing(){if(!(this.modelName in g))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return g[this.modelName]}};var be="gpt-3.5-turbo-0125",qi="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.",nt=provider.ChatModelSchema(d,v).parse({name:be,description:qi,maxInputTokens:4092,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.responseFormat(4092,4).def,schema:a.responseFormat(4092,4).schema},price:g[be]}),En=h,xe=class extends u{constructor(e){super(nt,e);}};var Se="gpt-3.5-turbo-1106",Ui="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.",st=provider.ChatModelSchema(d,v).parse({name:Se,description:Ui,maxInputTokens:4092,maxOutputTokens:16385,roles:c,modalities:w,config:{def:a.responseFormat(16385,4).def,schema:a.responseFormat(16385,4).schema},price:g[Se]}),Gn=h,Ie=class extends u{constructor(e){super(st,e);}};var Re="gpt-3.5-turbo",ji="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",it=provider.ChatModelSchema(d,v).parse({name:Re,description:ji,maxInputTokens:4092,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.responseFormat(4092,4).def,schema:a.responseFormat(4092,4).schema},price:g[Re]}),kn=h,Ae=class extends u{constructor(e){super(it,e);}};var Ee="gpt-4-0125-preview",Fi="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.",at=provider.ChatModelSchema(d,v).parse({name:Ee,description:Fi,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.base(4092,4).def,schema:a.base(4092,4).schema},price:g[Ee]}),wn=h,Ge=class extends u{constructor(e){super(at,e);}};var ke="gpt-4-0613",Vi="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",rt=provider.ChatModelSchema(d,v).parse({name:ke,description:Vi,maxInputTokens:8192,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.base(4092,4).def,schema:a.base(4092,4).schema},price:g[ke]}),vn=h,we=class extends u{constructor(e){super(rt,e);}};var ve="gpt-4-1106-preview",Ji="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.",lt=provider.ChatModelSchema(d,v).parse({name:ve,description:Ji,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.base(4092,4).def,schema:a.base(4092,4).schema},price:g[ve]}),Ln=h,Le=class extends u{constructor(e){super(lt,e);}};var De="gpt-4.1",Yi="Flagship model for complex tasks. It is well suited for problem solving across domains. Training data up to May 2024.",pt=provider.ChatModelSchema(d,M).parse({name:De,description:Yi,maxInputTokens:1047576,maxOutputTokens:32768,roles:c,modalities:y,config:{def:a.responseSchema(32768,4).def,schema:a.responseSchema(32768,4).schema},price:g[De]}),Dn=h,Ne=class extends u{constructor(e){super(pt,e);}};var qe="gpt-4.1-mini",Xi="Provides a balance between intelligence, speed, and cost that makes it an attractive model for many use cases. Training data up to May 2024.",mt=provider.ChatModelSchema(d,M).parse({name:qe,description:Xi,maxInputTokens:1047576,maxOutputTokens:32768,roles:c,modalities:y,config:{def:a.responseSchema(32768,4).def,schema:a.responseSchema(32768,4).schema},price:g[qe]}),Nn=h,ze=class extends u{constructor(e){super(mt,e);}};var Ue="gpt-4.1-nano",ea="Fastest, most cost-effective GPT-4.1 model. Training data up to May 2024.",dt=provider.ChatModelSchema(d,M).parse({name:Ue,description:ea,maxInputTokens:1047576,maxOutputTokens:32768,roles:c,modalities:y,config:{def:a.responseSchema(32768,4).def,schema:a.responseSchema(32768,4).schema},price:g[Ue]}),qn=h,Be=class extends u{constructor(e){super(dt,e);}};var je="gpt-5.1",ta="Flagship GPT-5.1 model for coding and agentic tasks with configurable reasoning effort. Training data up to September 2024.",ct=provider.ChatModelSchema(d,M).parse({name:je,description:ta,maxInputTokens:4e5,maxOutputTokens:128e3,roles:c,modalities:y,config:{def:a.gpt5(128e3,4).def,schema:a.gpt5(128e3,4).schema},price:g[je]}),zn=h,$e=class extends u{constructor(e){super(ct,e);}};var Fe="gpt-5.2",sa="Flagship GPT-5.2 model with enhanced reasoning controls and extended knowledge coverage. Training data up to January 2025.",ut=provider.ChatModelSchema(d,M).parse({name:Fe,description:sa,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:g[Fe]}),Un=h,He=class extends u{constructor(e){super(ut,e);}};var Ve="gpt-5.2-chat-latest",aa="Latest GPT-5.2 chat-optimized model for conversational workloads with tool/function calling support. Training data up to January 2025.",ra=y,la=M,ht=provider.ChatModelSchema(d,la).parse({name:Ve,description:aa,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:ra,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:g[Ve]}),Bn=h,Ke=class extends u{constructor(e){super(ht,e);}};var Je="gpt-5.2-pro",ma="GPT-5.2 Pro available via the OpenAI Responses API for advanced reasoning and agentic workflows. Training data up to January 2025.",ft=provider.ChatModelSchema(d,M).parse({name:Je,description:ma,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:g[Je]}),jn=sn,We=class extends Bo{constructor(e){super(ft,e);}};var Ye="gpt-5",ca="Most advanced GPT-5 model for complex reasoning and problem-solving tasks. Training data up to October 2024.",gt=provider.ChatModelSchema(d,M).parse({name:Ye,description:ca,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:g[Ye]}),$n=h,Qe=class extends u{constructor(e){super(gt,e);}};var Xe="gpt-5-mini",ha="Faster, more cost-effective GPT-5 model that balances intelligence and efficiency. Training data up to October 2024.",_t=provider.ChatModelSchema(d,M).parse({name:Xe,description:ha,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:g[Xe]}),Fn=h,Ze=class extends u{constructor(e){super(_t,e);}};var eo="gpt-5-nano",ga="Most cost-effective GPT-5 model optimized for speed and efficiency. Training data up to October 2024.",Tt=provider.ChatModelSchema(d,M).parse({name:eo,description:ga,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:g[eo]}),Hn=h,oo=class extends u{constructor(e){super(Tt,e);}};var to="gpt-5-chat-latest",ya="Latest GPT-5 model optimized for conversational use. Does not support function calling or structured outputs. Training data up to October 2024.",Ma=[types.TextModalityLiteral,types.ImageModalityLiteral],Ca=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral]),yt=provider.ChatModelSchema(d,Ca).parse({name:to,description:ya,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:Ma,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:g[to]}),Vn=h,no=class extends u{constructor(e){super(yt,e);}};var so="gpt-4-turbo-2024-04-09",Pa="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.",Mt=provider.ChatModelSchema(d,M).parse({name:so,description:Pa,maxInputTokens:128e3,maxOutputTokens:4096,roles:c,modalities:y,config:{def:a.responseFormat(4096,4).def,schema:a.responseFormat(4096,4).schema},price:g[so]}),Kn=h,io=class extends u{constructor(e){super(Mt,e);}};var ao="gpt-4-turbo-preview",xa="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",Ct=provider.ChatModelSchema(d,v).parse({name:ao,description:xa,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.responseFormat(4092,4).def,schema:a.responseFormat(4092,4).schema},price:g[ao]}),Jn=h,ro=class extends u{constructor(e){super(Ct,e);}};var lo="gpt-4-turbo",Ia="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.",Ot=provider.ChatModelSchema(d,M).parse({name:lo,description:Ia,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseFormat(4092,4).def,schema:a.responseFormat(4092,4).schema},price:g[lo]}),Wn=h,po=class extends u{constructor(e){super(Ot,e);}};var mo="gpt-4",Aa="Currently points to gpt-4-0613. Training data up to Sept 2021.",Pt=provider.ChatModelSchema(d,v).parse({name:mo,description:Aa,maxInputTokens:8192,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.base(4092,4).def,schema:a.base(4092,4).schema},price:g[mo]}),Yn=h,co=class extends u{constructor(e){super(Pt,e);}};var uo="gpt-4o-2024-05-13",Ga="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",bt=provider.ChatModelSchema(d,M).parse({name:uo,description:Ga,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:g[uo]}),Qn=h,ho=class extends u{constructor(e){super(bt,e);}};var fo="gpt-4o-2024-08-06",wa="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",xt=provider.ChatModelSchema(d,M).parse({name:fo,description:wa,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:g[fo]}),Xn=h,go=class extends u{constructor(e){super(xt,e);}};var _o="gpt-4o-mini-2024-07-18",La="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.",St=provider.ChatModelSchema(d,M).parse({name:_o,description:La,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:g[_o]}),Zn=h,To=class extends u{constructor(e){super(St,e);}};var yo="gpt-4o-mini",Na="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.",It=provider.ChatModelSchema(d,M).parse({name:yo,description:Na,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:g[yo]}),es=h,Mo=class extends u{constructor(e){super(It,e);}};var Co="gpt-4o",za="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.",Rt=provider.ChatModelSchema(d,M).parse({name:Co,description:za,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:g[Co]}),os=h,Oo=class extends u{constructor(e){super(Rt,e);}};var Po="o1-2024-12-17",Ba="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",At=provider.ChatModelSchema(d,M).parse({name:Po,description:Ba,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema},price:g[Po]}),ts=h,bo=class extends u{constructor(e){super(At,e);}};var xo="o1",$a="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",Et=provider.ChatModelSchema(d,M).parse({name:xo,description:$a,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema},price:g[xo]}),ns=h,So=class extends u{constructor(e){super(Et,e);}};var Gt="o3-2025-04-16",Ha="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",kt=provider.ChatModelSchema(d,M).parse({name:Gt,description:Ha,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),ss=h,Io=class extends u{constructor(e){super(kt,e);}};var wt="o3",Ka="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",vt=provider.ChatModelSchema(d,M).parse({name:wt,description:Ka,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),is=h,Ro=class extends u{constructor(e){super(vt,e);}};var Lt="o3-mini",Wa="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.",Dt=provider.ChatModelSchema(d,v).parse({name:Lt,description:Wa,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:w,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),as=h,Ao=class extends u{constructor(e){super(Dt,e);}};var Nt="o3-mini-2025-01-31",Qa="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.",qt=provider.ChatModelSchema(d,v).parse({name:Nt,description:Qa,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:w,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),rs=h,Eo=class extends u{constructor(e){super(qt,e);}};var zt="o4-mini-2025-04-16",Za="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",Ut=provider.ChatModelSchema(d,M).parse({name:zt,description:Za,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),ls=h,Go=class extends u{constructor(e){super(Ut,e);}};var Bt="o4-mini",or="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",jt=provider.ChatModelSchema(d,M).parse({name:Bt,description:or,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),ps=h,ko=class extends u{constructor(e){super(jt,e);}};var le=[types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral],pe=zod.z.enum([types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral]);var ws=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 nr=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)),vs=zod.z.object({model:zod.z.string().min(1).optional(),input:nr,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()});var se=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),X=class{constructor(e,n){this.version="v1";let o=se.parse(n);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 n=l=>{let p=/(\d+)(h|m|s|ms)/g,_={h:36e5,m:6e4,s:1e3,ms:1},f,I=0;for(;(f=p.exec(l))!==null;){let P=parseInt(f[1]),S=f[2];I+=P*_[S];}return I},o=0,t=0,s=!0;e["x-ratelimit-reset-requests"]&&(o=n(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(t=n(e["x-ratelimit-reset-tokens"]));let r=Math.max(o,t);return {shouldRetry:s,delayMs:r}}getTokenCount(e){return e.requests.reduce((n,o)=>n+o.length,0)}transformModelRequest(e){let n=vs.safeParse(e);if(!n.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:n.error});let o=n.data,t=o.model,s={encodingFormat:o.encoding_format,dimensions:o.dimensions},r=types.Config().parse(provider.removeUndefinedEntries(s)),l,p;return typeof o.input=="string"?p=types.EmbeddingTextModalityLiteral:typeof o.input[0]=="string"?p=types.EmbeddingTextModalityLiteral:p=types.EmbeddingTokenModalityLiteral,p===types.EmbeddingTextModalityLiteral?typeof o.input=="string"?l={modality:p,requests:[o.input]}:l={modality:p,requests:o.input}:typeof o.input[0]=="number"?l={modality:p,requests:[o.input]}:l={modality:p,requests:o.input},{modelName:t,config:r,embeddingRequests:l}}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 t=o.data;return Object.keys(t).forEach(r=>{if(!this.modelSchema.config.def[r])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${r}',
|
|
18
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(t).reduce((r,l)=>{let
|
|
7
|
+
var Ns=Object.defineProperty,qs=Object.defineProperties;var zs=Object.getOwnPropertyDescriptors;var dn=Object.getOwnPropertySymbols;var Us=Object.prototype.hasOwnProperty,Bs=Object.prototype.propertyIsEnumerable;var ye=(i,e)=>(e=Symbol[i])?e:Symbol.for("Symbol."+i),js=i=>{throw TypeError(i)};var cn=(i,e,s)=>e in i?Ns(i,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[e]=s,b=(i,e)=>{for(var s in e||(e={}))Us.call(e,s)&&cn(i,s,e[s]);if(dn)for(var s of dn(e))Bs.call(e,s)&&cn(i,s,e[s]);return i},q=(i,e)=>qs(i,zs(e));var k=(i,e,s)=>new Promise((o,t)=>{var n=p=>{try{l(s.next(p));}catch(g){t(g);}},r=p=>{try{l(s.throw(p));}catch(g){t(g);}},l=p=>p.done?o(p.value):Promise.resolve(p.value).then(n,r);l((s=s.apply(i,e)).next());}),un=function(i,e){this[0]=i,this[1]=e;},ie=(i,e,s)=>{var o=(r,l,p,g)=>{try{var T=s[r](l),x=(l=T.value)instanceof un,O=T.done;Promise.resolve(x?l[0]:l).then(I=>x?o(r==="return"?r:"next",l[1]?{done:I.done,value:I.value}:I,p,g):p({value:I,done:O})).catch(I=>o("throw",I,p,g));}catch(I){g(I);}},t=r=>n[r]=l=>new Promise((p,g)=>o(r,l,p,g)),n={};return s=s.apply(i,e),n[ye("asyncIterator")]=()=>n,t("next"),t("throw"),t("return"),n},Me=i=>{var e=i[ye("asyncIterator")],s=!1,o,t={};return e==null?(e=i[ye("iterator")](),o=n=>t[n]=r=>e[n](r)):(e=e.call(i),o=n=>t[n]=r=>{if(s){if(s=!1,n==="throw")throw r;return r}return s=!0,{done:!1,value:new un(new Promise(l=>{var p=e[n](r);p instanceof Object||js("Object expected"),l(p);}),1)}}),t[ye("iterator")]=()=>t,o("next"),"throw"in e?o("throw"):t.throw=n=>{throw n},"return"in e&&o("return"),t};var $o=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=i=>provider.RangeConfigItem({param:"max_completion_tokens",title:provider.CHAT_CONFIG.MAX_TOKENS.title,description:provider.CHAT_CONFIG.MAX_TOKENS.description,min:0,max:i,step:1,default:0}),Ho=i=>provider.MultiStringConfigItem({param:"stop",title:provider.CHAT_CONFIG.STOP(i).title,description:provider.CHAT_CONFIG.STOP(i).description,max:i}),Vo=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}),Ko=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}),Jo=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}),Wo=provider.RangeConfigItem({param:"seed",title:provider.CHAT_CONFIG.SEED.title,description:provider.CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),Yo=provider.SelectBooleanConfigItem({param:"logprobs",title:provider.CHAT_CONFIG.LOG_PROBS.title,description:provider.CHAT_CONFIG.LOG_PROBS.description,default:!1}),Qo=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}),Xo=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"]}),Zo=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"]}),et=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 Y=(i,e)=>zod.z.object({temperature:$o.schema,maxTokens:Fo(i).schema,stop:Ho(e).schema,topP:Vo.schema,frequencyPenalty:Ko.schema,presencePenalty:Jo.schema,seed:Wo.schema.transform(s=>s===0?void 0:s),logProbs:Yo.schema,topLogProbs:Qo.schema,toolChoice:Xo.schema}),Q=(i,e)=>({temperature:$o.def,maxTokens:Fo(i).def,stop:Ho(e).def,topP:Vo.def,frequencyPenalty:Ko.def,presencePenalty:Jo.def,seed:Wo.def,logProbs:Yo.def,topLogProbs:Qo.def,toolChoice:Xo.def});var hn=provider.ObjectSchemaConfigItem({param:"response_schema",title:provider.CHAT_CONFIG.RESPONSE_SCHEMA.title,description:provider.CHAT_CONFIG.RESPONSE_SCHEMA.description,objectSchema:types.ResponseSchema}),fn=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=(i,e)=>q(b({},Q(i,e)),{responseFormat:fn.def,responseSchema:hn.def}),oe=(i,e)=>Y(i,e).extend({responseFormat:fn.schema,responseSchema:hn.schema});var gn=(i,e)=>q(b({},Q(i,e)),{reasoningEffort:Zo.def,verbosity:et.def,responseFormat:ee(i,e).responseFormat,responseSchema:ee(i,e).responseSchema}),_n=(i,e)=>Y(i,e).extend({reasoningEffort:Zo.schema,verbosity:et.schema,responseFormat:oe(i,e).shape.responseFormat,responseSchema:oe(i,e).shape.responseSchema});var yn=provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),Mn=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"]}),Cn=(i,e)=>q(b({},ee(i,e)),{temperature:yn.def,reasoningEffort:Mn.def}),On=(i,e)=>oe(i,e).extend({temperature:yn.schema,reasoningEffort:Mn.schema});var bn=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"]}),xn=(i,e)=>q(b({},Q(i,e)),{responseFormat:bn.def}),Sn=(i,e)=>Y(i,e).extend({responseFormat:bn.schema});var ot=provider.SelectStringConfigItem({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),tt=i=>provider.RangeConfigItem({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:i,step:1,default:i});var Oe=()=>zod.z.object({encodingFormat:ot.schema}),Pe=()=>({encodingFormat:ot.def});var In=i=>Oe().extend({dimensions:tt(i).schema}),Rn=i=>q(b({},Pe()),{dimensions:tt(i).def});var a={base:(i,e)=>({def:Q(i,e),schema:Y(i,e)}),responseFormat:(i,e)=>({def:xn(i,e),schema:Sn(i,e)}),responseSchema:(i,e)=>({def:ee(i,e),schema:oe(i,e)}),oSeries:(i,e)=>({def:Cn(i,e),schema:On(i,e)}),gpt5:(i,e)=>({def:gn(i,e),schema:_n(i,e)})},K={base:()=>({def:Pe(),schema:Oe()}),dimensions:i=>({def:Rn(i),schema:In(i)})};var f={"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}}}]},"gpt-5.1":{modelName:"gpt-5.1",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.5,outputPricePerMillion:12}}}]},"gpt-5.2":{modelName:"gpt-5.2",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.75,outputPricePerMillion:14}}}]},"gpt-5.2-chat-latest":{modelName:"gpt-5.2-chat-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1.75,outputPricePerMillion:14}}}]},"gpt-5.2-pro":{modelName:"gpt-5.2-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:21,outputPricePerMillion:168}}}]}};var ti="openai",J=class{constructor(){this.version="v1";this.name=ti;this.chatModelFactories={[Re]:{model:Ae,modelOptions:kn,modelSchema:it},[be]:{model:xe,modelOptions:En,modelSchema:nt},[Se]:{model:Ie,modelOptions:Gn,modelSchema:st},[Ee]:{model:Ge,modelOptions:wn,modelSchema:at},[ke]:{model:we,modelOptions:vn,modelSchema:rt},[ve]:{model:De,modelOptions:Dn,modelSchema:lt},[Le]:{model:Ne,modelOptions:Ln,modelSchema:pt},[qe]:{model:ze,modelOptions:Nn,modelSchema:mt},[Ue]:{model:Be,modelOptions:qn,modelSchema:dt},[Ye]:{model:Qe,modelOptions:$n,modelSchema:gt},[je]:{model:$e,modelOptions:zn,modelSchema:ct},[Fe]:{model:He,modelOptions:Un,modelSchema:ut},[Je]:{model:We,modelOptions:jn,modelSchema:ft},[Ve]:{model:Ke,modelOptions:Bn,modelSchema:ht},[Xe]:{model:Ze,modelOptions:Fn,modelSchema:_t},[eo]:{model:oo,modelOptions:Hn,modelSchema:Tt},[to]:{model:no,modelOptions:Vn,modelSchema:yt},[so]:{model:io,modelOptions:Kn,modelSchema:Mt},[ao]:{model:ro,modelOptions:Jn,modelSchema:Ct},[lo]:{model:po,modelOptions:Wn,modelSchema:Ot},[mo]:{model:co,modelOptions:Yn,modelSchema:Pt},[fo]:{model:go,modelOptions:Xn,modelSchema:xt},[yo]:{model:Mo,modelOptions:es,modelSchema:It},[Co]:{model:Oo,modelOptions:os,modelSchema:Rt},[_o]:{model:To,modelOptions:Zn,modelSchema:St},[uo]:{model:ho,modelOptions:Qn,modelSchema:bt},[xo]:{model:So,modelOptions:ns,modelSchema:Et},[Po]:{model:bo,modelOptions:ts,modelSchema:At},[Nt]:{model:Eo,modelOptions:rs,modelSchema:qt},[Dt]:{model:Ao,modelOptions:as,modelSchema:Lt},[Gt]:{model:Io,modelOptions:ss,modelSchema:kt},[wt]:{model:Ro,modelOptions:is,modelSchema:vt},[zt]:{model:Go,modelOptions:ls,modelSchema:Ut},[Bt]:{model:ko,modelOptions:ps,modelSchema:jt}};this.embeddingModelFactories={[$t]:{model:wo,modelOptions:ms,modelSchema:Ft},[Ht]:{model:vo,modelOptions:ds,modelSchema:Vt},[Kt]:{model:Do,modelOptions:cs,modelSchema:Jt}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,s)=>(e[s]=this.chatModelFactories[s].modelSchema,e),{})}chatModel(e){let s=e.modelName;if(!(s in this.chatModelFactories))throw new provider.ProviderError({info:`OpenAI chat model: ${s} not found`,cause:new Error(`OpenAI chat model: ${s} not found, available chat models:
|
|
8
|
+
[${this.chatModelLiterals().join(", ")}]`)});let o=this.chatModelFactories[s].model,t=this.chatModelFactories[s].modelOptions.parse(e);return new o(t)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,s)=>(e[s]=this.embeddingModelFactories[s].modelSchema,e),{})}embeddingModel(e){let s=e.modelName;if(!(s in this.embeddingModelFactories))throw new provider.ProviderError({info:`OpenAI embedding model: ${s} not found`,cause:new Error(`OpenAI embedding model: ${s} not found, available embedding models:
|
|
9
|
+
[${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[s].model,t=this.embeddingModelFactories[s].modelOptions.parse(e);return new o(t)}};J.baseUrl="https://api.openai.com/v1";var d=zod.z.enum([types.SystemRoleLiteral,types.UserRoleLiteral,types.AssistantRoleLiteral,types.ToolRoleLiteral]),c={system:types.SystemRoleLiteral,user:types.UserRoleLiteral,assistant:types.AssistantRoleLiteral,tool:types.ToolRoleLiteral};var y=[types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],M=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]),fl=[types.TextModalityLiteral],gl=zod.z.enum([types.TextModalityLiteral]),w=[types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],v=zod.z.enum([types.TextModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]);var qo=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Ts=zod.z.object({content:zod.z.array(qo.extend({top_logprobs:zod.z.array(qo)})).nullable().optional(),refusal:zod.z.array(qo.extend({top_logprobs:zod.z.array(qo)})).nullable().optional()}).nullable(),si=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()})})),ys=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:si.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Ts.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()})}),ii=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()})),Ms=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:ii.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Ts.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 ai=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()})}),ri=zod.z.enum(["none","auto","required"]),li=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),pi=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()})})),Yt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),mi=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()})}),di=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)})}),ci=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(Yt).min(1))}),ui=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Yt,mi])).min(1))}),hi=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(Yt).min(1)).optional(),tool_calls:zod.z.array(di).min(1).optional()}),fi=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),gi=zod.z.union([ci,ui,hi,fi]),Cs=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(gi).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:pi.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(ai).optional(),tool_choice:ri.or(li).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()}),u=class{constructor(e,s){this.version="v1";let o=h.parse(s);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,s){let o=p=>{let g=/(\d+)(h|m|s|ms)/g,T={h:36e5,m:6e4,s:1e3,ms:1},x,O=0;for(;(x=g.exec(p))!==null;){let I=parseInt(x[1]),R=x[2];O+=I*T[R];}return O},t=0,n=0,r=!0;e["x-ratelimit-reset-requests"]&&(t=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(n=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(t,n);return {shouldRetry:r,delayMs:l}}getTokenCount(e){return e.reduce((s,o)=>s+o.content.map(t=>t.modality==="text"?t.value:"").join(" ").length,0)}transformModelRequest(e){let s=Cs.safeParse(e);if(!s.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:s.error});let o=s.data,t=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 n={};o.response_format&&(n.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(n.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"?n.toolChoice=o.tool_choice:n.toolChoice=o.tool_choice.function.name),n.seed=o.seed,n.maxTokens=o.max_completion_tokens,n.temperature=o.temperature,n.topP=o.top_p,n.presencePenalty=o.presence_penalty,n.frequencyPenalty=o.frequency_penalty,n.stop=o.stop,n.logProbs=o.logprobs,n.topLogProbs=o.top_logprobs,n.reasoningEffort=o.reasoning_effort,n.verbosity=o.verbosity;let r=types.Config().parse(provider.removeUndefinedEntries(n)),l=[],p={};o.messages.forEach(T=>{let x=T.role;switch(x){case"system":{let O=T.content;if(typeof O=="string")l.push({role:x,content:[{modality:types.TextModalityLiteral,value:O}]});else {let I=O.map(R=>({modality:types.TextModalityLiteral,value:R.text}));l.push({role:x,content:I});}}break;case"user":{let O=T.content;if(typeof O=="string")l.push({role:x,content:[{modality:types.TextModalityLiteral,value:O}]});else {let I=O.map(R=>R.type==="text"?{modality:types.TextModalityLiteral,value:R.text}:R.image_url.url.startsWith("data:")?{modality:types.ImageModalityLiteral,detail:R.image_url.detail||"auto",value:{type:types.Base64ImageContentTypeLiteral,base64:R.image_url.url,mediaType:provider.getMimeTypeFromBase64(R.image_url.url)}}:{modality:types.ImageModalityLiteral,detail:R.image_url.detail||"auto",value:{type:types.UrlImageContentTypeLiteral,url:R.image_url.url}});l.push({role:x,content:I});}}break;case"assistant":{let O=[];if(!T.content&&!T.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(T.content){let I=T.content;typeof I=="string"?O.push({modality:types.TextModalityLiteral,value:I}):I.forEach(R=>{O.push({modality:types.TextModalityLiteral,value:R.text});});}T.tool_calls&&T.tool_calls.forEach((R,D)=>{let S={modality:types.ToolCallModalityLiteral,id:R.id,index:D,name:R.function.name,arguments:R.function.arguments};O.push(S),p[S.id]=S;}),l.push({role:x,content:O});}break;case"tool":{let O=T;l.push({role:x,content:[{modality:types.ToolResponseModalityLiteral,id:O.tool_call_id,index:p[O.tool_call_id].index,name:p[O.tool_call_id].name,data:O.content}]});}break}});let g=[];return o.tools&&o.tools.forEach(T=>{g.push({type:"function",definition:{schema:{name:T.function.name,description:T.function.description||"",strict:T.function.strict,parameters:T.function.parameters}}});}),{modelName:t,config:r,messages:l,tools:g.length>0?g:void 0}}transformConfig(e,s,o){let t=e.toolChoice;delete e.toolChoice;let n=this.modelSchema.config.schema.safeParse(e);if(!n.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let r=n.data;t!==void 0&&(r.toolChoice=t),Object.keys(r).forEach(p=>{if(!(p in this.modelSchema.config.def))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${p}',
|
|
10
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let l=Object.keys(r).reduce((p,g)=>{let T=this.modelSchema.config.def[g],x=T.param,O=r[g];return x==="max_completion_tokens"&&T.type==="range"&&O===0?p[x]=T.max:p[x]=O,p},{});if(l.top_logprobs&&!l.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 l&&l.tool_choice!==void 0){let p=l.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 g=this.modelSchema.config.def.toolChoice;if(!g.choices.includes(p))if(o.map(T=>T.definition.schema.name).includes(p))l.tool_choice={type:"function",function:{name:p}};else throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${p}' is not part of provided 'tools' names or
|
|
11
|
+
one of [${g.choices.join(", ")}]`)})}}if("response_format"in l&&l.response_format!==void 0){let p=l.response_format;if(p==="json_schema")if("response_schema"in l)l.response_format={type:"json_schema",json_schema:l.response_schema},delete l.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 l.response_format={type:p};}return l}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let s=e.map(t=>{let n=types.Message().safeParse(t);if(!n.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:n.error});return n.data});return s.forEach(t=>{t.content.forEach(n=>{if(!this.modelSchema.modalities.includes(n.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${n.modality}',
|
|
12
|
+
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),s.forEach(t=>{if(!Object.keys(this.modelSchema.roles).includes(t.role))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${t.role}',
|
|
13
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),s.forEach(t=>{t.content=t.content.filter(n=>n.modality!=="error"&&n.modality!=="search-result");}),{messages:s.map(t=>{switch(t.role){case types.SystemRoleLiteral:{let n=[];return t.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)n.push({type:"text",text:r.value});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${r.modality}'`)})}),{role:this.modelSchema.roles[t.role],content:n}}case types.AssistantRoleLiteral:{let n=[],r=[];return t.content.forEach(l=>{if(l.modality===types.TextModalityLiteral)n.push({type:"text",text:l.value});else if(l.modality===types.ToolCallModalityLiteral)r.push({id:l.id,type:"function",function:{name:l.name,arguments:l.arguments}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${l.modality}'`)})}),b({role:this.modelSchema.roles[t.role],content:n},r.length>0?{tool_calls:r}:{})}case types.UserRoleLiteral:{let n=[],r=[];t.content.forEach(p=>{if(p.modality===types.TextModalityLiteral)n.push({type:"text",text:p.value});else if(p.modality===types.ImageModalityLiteral)r.push({type:"image_url",image_url:{url:p.value.type==="url"?p.value.url:p.value.base64,detail:p.detail}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${p.modality}'`)})});let l=[...n,...r];return {role:this.modelSchema.roles[t.role],content:l}}case types.ToolRoleLiteral:{if(t.content.length!==1)throw new provider.InvalidMessagesError({info:`Invalid message for role : '${t.role}'`,cause:new Error(`role : '${t.role}' must have exactly one content item`)});if(t.content[0].modality!==types.ToolResponseModalityLiteral)throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' must have content with modality : '${types.ToolResponseModalityLiteral}'`)});let n=t.content[0];return {role:this.modelSchema.roles[t.role],tool_call_id:n.id,content:n.data}}default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${t.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(t=>{let n=types.Tool().safeParse(t);if(!n.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:n.error});return n.data}).map(t=>({type:"function",function:t.definition.schema}))}}getCompleteChatUrl(e,s,o){return k(this,null,function*(){return new Promise(t=>{t(this.completeChatUrl);})})}getCompleteChatHeaders(e,s,o){return k(this,null,function*(){return new Promise(t=>{t(this.getDefaultHeaders());})})}getCompleteChatData(e,s,o){return k(this,null,function*(){let t=this.transformConfig(e,s,o),n=this.transformMessages(s);if(n.messages&&n.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return new Promise(l=>{l(b(b(b(b({},this.getDefaultParams()),t),n),r));})})}transformCompleteChatResponse(e){let s=ys.safeParse(e);if(s.success){if(s.data.choices.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(s.data)}`)});let o=s.data,t=[{role:types.AssistantRoleLiteral,content:[]}],n=o.choices[0].message;n.content&&t[0].content.push(types.createTextContent(n.content)),n.refusal&&t[0].content.push(types.createTextContent(n.refusal)),n.tool_calls&&n.tool_calls.forEach((g,T)=>{t[0].content.push(types.createToolCallContent(T,g.id,g.function.name,g.function.arguments));});let r={promptTokens:o.usage.prompt_tokens,completionTokens:o.usage.completion_tokens,totalTokens:o.usage.total_tokens},l=[],p=o.choices[0].logprobs;return p&&(p.content&&l.push(...p.content.map(g=>({token:g.token,logProb:g.logprob,bytes:g.bytes,topLogProbs:g.top_logprobs.map(T=>({token:T.token,logProb:T.logprob,bytes:T.bytes}))}))),p.refusal&&l.push(...p.refusal.map(g=>({token:g.token,logProb:g.logprob,bytes:g.bytes,topLogProbs:g.top_logprobs.map(T=>({token:T.token,logProb:T.logprob,bytes:T.bytes}))})))),{messages:t,usage:r,logProbs:l}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:s.error})}getStreamChatUrl(e,s,o){return k(this,null,function*(){return new Promise(t=>{t(this.streamChatUrl);})})}getStreamChatHeaders(e,s,o){return k(this,null,function*(){return new Promise(t=>{t(this.getDefaultHeaders());})})}getStreamChatData(e,s,o){return k(this,null,function*(){let t=this.transformConfig(e,s,o),n=this.transformMessages(s);if(n.messages&&n.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return new Promise(l=>{l(b(b(b(b({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),t),n),r));})})}transformStreamChatResponseChunk(e,s){return ie(this,null,function*(){var l,p;let o=s+e,t=[],n="",r=0;for(;r<o.length;){let g=o.indexOf(`
|
|
15
|
+
`,r);if(g===-1){n=o.substring(r);break}else {let T=o.substring(r,g).trim();T&&t.push(T),r=g+1;}}for(let g of t){if(g==="data: [DONE]")return;if(g.startsWith("data: ")){let T=g.substring(6);try{let x=JSON.parse(T),O=Ms.safeParse(x);if(O.success){let I={partialMessages:[]},R=O.data;if(R.choices.length>0){let D=R.choices[0].delta;if(D!==void 0&&Object.keys(D).length!==0){if("content"in D&&D.content!==null)I.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,D.content));else if("refusal"in D&&D.refusal!==null)I.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,D.refusal));else if("tool_calls"in D&&D.tool_calls!==void 0){let S=D.tool_calls.at(0);I.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,S.index,S.id,(l=S.function)==null?void 0:l.name,(p=S.function)==null?void 0:p.arguments));}}}R.usage&&(I.usage={promptTokens:R.usage.prompt_tokens,completionTokens:R.usage.completion_tokens,totalTokens:R.usage.total_tokens}),yield {partialResponse:I,buffer:n};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:O.error})}catch(x){throw new provider.ModelResponseError({info:`Malformed JSON received in stream: ${T}`,cause:x})}}}yield {partialResponse:{partialMessages:[]},buffer:n};})}transformProxyStreamChatResponseChunk(e,s,o,t,n){return ie(this,null,function*(){yield*Me(this.transformStreamChatResponseChunk(e,s));})}getProxyStreamChatUrl(e,s,o){return k(this,null,function*(){return new Promise(t=>{t(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,s,o){return k(this,null,function*(){return new Promise(t=>{t(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,s,o){return k(this,null,function*(){if(!s)return {};let t=b({},s);return delete t.host,delete t["content-length"],t})}getProxyStreamChatHeaders(e,s,o){return k(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,s,o)})}getModelPricing(){if(!(this.modelName in f))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return f[this.modelName]}};var sn=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),Bo=class{constructor(e,s){this.version="v1";let o=sn.parse(s);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(o.baseUrl||J.baseUrl),this.responsesUrl=`${this.baseUrl}/responses`,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,s){let o=p=>{let g=/(\d+)(h|m|s|ms)/g,T={h:36e5,m:6e4,s:1e3,ms:1},x,O=0;for(;(x=g.exec(p))!==null;){let I=parseInt(x[1]),R=x[2];O+=I*T[R];}return O},t=0,n=0,r=!0;e["x-ratelimit-reset-requests"]&&(t=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(n=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(t,n);return {shouldRetry:r,delayMs:l}}getTokenCount(e){return e.reduce((s,o)=>s+o.content.map(t=>t.modality==="text"?t.value:"").join(" ").length,0)}transformModelRequest(e){throw new provider.ModelResponseError({info:"transformModelRequest not supported for Responses API models",cause:new Error("Use the standard gateway interface with config, messages, and tools parameters")})}transformConfig(e,s,o){let t=types.Config().parse(e),n={};for(let p of Object.keys(this.modelSchema.config.def)){let g=this.modelSchema.config.def[p],T=g==null?void 0:g.param;T&&t[p]!==void 0&&(n[T]=t[p]);}let r=t.toolChoice;if(r!==void 0)if(o&&o.length>0){let p=r,g=o.map(T=>T.definition.schema.name);if(["none","auto","required"].includes(p))n.tool_choice=p;else if(g.includes(p))n.tool_choice={type:"function",function:{name:p}};else throw new provider.InvalidConfigError({info:`Invalid tool choice for model : '${this.modelName}'`,cause:new Error(`Tool with name '${p}' not found in tools`)})}else throw new provider.InvalidConfigError({info:`Invalid tool choice for model : '${this.modelName}'`,cause:new Error("Tools are required when tool_choice is specified")});let l=t.responseFormat;if(l!==void 0)if(l==="json_schema"){if(!t.responseSchema)throw new provider.InvalidConfigError({info:`Invalid response schema for model : '${this.modelName}'`,cause:new Error("Response schema is required when response format is 'json_schema'")});n.response_format={type:l,json_schema:n.response_schema},delete n.response_schema;}else n.response_format={type:l};return "reasoning_effort"in n&&n.reasoning_effort!==void 0&&(n.reasoning={effort:n.reasoning_effort},delete n.reasoning_effort),"verbosity"in n&&n.verbosity!==void 0&&(n.text={verbosity:n.verbosity},delete n.verbosity),n}transformMessages(e){if(!e||e.length===0)return {messages:[]};let s=e.map(t=>{let n=types.Message().safeParse(t);if(!n.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:n.error});return n.data});return s.forEach(t=>{t.content.forEach(n=>{if(!this.modelSchema.modalities.includes(n.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${n.modality}'`)})});}),s.forEach(t=>{if(!Object.keys(this.modelSchema.roles).includes(t.role))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${t.role}'`)})}),s.forEach(t=>{t.content=t.content.filter(n=>n.modality!=="error"&&n.modality!=="search-result");}),{messages:s.map(t=>{switch(t.role){case types.SystemRoleLiteral:{let n=[];return t.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)n.push({type:"input_text",text:r.value});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${r.modality}'`)})}),{role:this.modelSchema.roles[t.role],content:n}}case types.AssistantRoleLiteral:{let n=[];return t.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)n.push({type:"output_text",text:r.value});else throw r.modality===types.ToolCallModalityLiteral?new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error("tool calls in message history are not supported for Responses API")}):new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${r.modality}'`)})}),{role:this.modelSchema.roles[t.role],content:n}}case types.UserRoleLiteral:{let n=[];return t.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)n.push({type:"input_text",text:r.value});else if(r.modality===types.ImageModalityLiteral){let l=r.value,p=l.type==="url"?l.url:l.base64;n.push({type:"image_url",image_url:{url:p,detail:r.detail}});}else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${r.modality}'`)})}),{role:this.modelSchema.roles[t.role],content:n}}case types.ToolRoleLiteral:{if(t.content.length!==1)throw new provider.InvalidMessagesError({info:`Invalid message for role : '${t.role}'`,cause:new Error(`role : '${t.role}' must have exactly one content item`)});if(t.content[0].modality!==types.ToolResponseModalityLiteral)throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' must have content with modality : '${types.ToolResponseModalityLiteral}'`)});let n=t.content[0];return {role:this.modelSchema.roles[t.role],tool_call_id:n.id,content:n.data}}default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${t.role}' is not supported`)})}})}}transformTools(e){if(!e||e.length===0)return {tools:[]};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`)});return {tools:e.map(t=>{let n=types.Tool().safeParse(t);if(!n.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:n.error});return n.data}).map(t=>({type:"function",function:t.definition.schema}))}}getCompleteChatUrl(e,s,o){return k(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getCompleteChatHeaders(e,s,o){return k(this,null,function*(){return Promise.resolve(this.getDefaultHeaders())})}getCompleteChatData(e,s,o){return k(this,null,function*(){let t=this.transformConfig(e,s,o),n=this.transformMessages(s);if(n.messages&&n.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return Promise.resolve(q(b(b(b({},this.getDefaultParams()),t),r),{input:n.messages}))})}transformCompleteChatResponse(e){var n,r,l,p,g,T,x,O,I,R,D;let s=(e==null?void 0:e.output)||(e==null?void 0:e.outputs);if(!s||!Array.isArray(s)||s.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No output in response : ${JSON.stringify(e)}`)});let o=[{role:types.AssistantRoleLiteral,content:[]}];for(let S of s)if((S==null?void 0:S.type)==="message"&&Array.isArray(S.content))S.content.forEach(A=>{var B,C,L,H,G,P;if((A==null?void 0:A.type)==="text"||(A==null?void 0:A.type)==="output_text")A.text&&o[0].content.push(types.createTextContent(A.text));else if((A==null?void 0:A.type)==="tool_call"&&A.tool_call){let V=A.tool_call;o[0].content.push(types.createToolCallContent((B=V.index)!=null?B:0,(C=V.id)!=null?C:"",(H=(L=V.function)==null?void 0:L.name)!=null?H:"",(P=(G=V.function)==null?void 0:G.arguments)!=null?P:""));}});else if(((S==null?void 0:S.type)==="text"||(S==null?void 0:S.type)==="output_text")&&(S!=null&&S.text))o[0].content.push(types.createTextContent(S.text));else if((S==null?void 0:S.type)==="tool_call"&&S.tool_call){let A=S.tool_call;o[0].content.push(types.createToolCallContent((n=A.index)!=null?n:0,(r=A.id)!=null?r:"",(p=(l=A.function)==null?void 0:l.name)!=null?p:"",(T=(g=A.function)==null?void 0:g.arguments)!=null?T:""));}if(o[0].content.length===0){let S=s[0],A=(S==null?void 0:S.content)||[],B=[];if(A.forEach(C=>{((C==null?void 0:C.type)==="text"||(C==null?void 0:C.type)==="output_text")&&(C!=null&&C.text)&&B.push(C.text);}),B.length>0)o[0].content.push(types.createTextContent(B.join(`
|
|
16
|
+
`)));else throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No text content found in response : ${JSON.stringify(e)}`)})}let t=e.usage||{};return {messages:o,usage:{promptTokens:(O=(x=t.input_tokens)!=null?x:t.prompt_tokens)!=null?O:0,completionTokens:(R=(I=t.output_tokens)!=null?I:t.completion_tokens)!=null?R:0,totalTokens:(D=t.total_tokens)!=null?D:(t.input_tokens||0)+(t.output_tokens||0)}}}getStreamChatUrl(e,s,o){return k(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getStreamChatHeaders(e,s,o){return k(this,null,function*(){return Promise.resolve(q(b({},this.getDefaultHeaders()),{Accept:"text/event-stream"}))})}getStreamChatData(e,s,o){return k(this,null,function*(){let t=this.transformConfig(e,s,o),n=this.transformMessages(s);if(n.messages&&n.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return Promise.resolve(q(b(b(b({},this.getDefaultParams()),t),r),{input:n.messages,stream:!0}))})}transformStreamChatResponseChunk(e,s){return ie(this,null,function*(){var l,p,g,T,x,O,I,R,D,S;let o=s+e,t=[],n="",r=0;for(;r<o.length;){let A=o.indexOf(`
|
|
17
|
+
`,r);if(A===-1){n=o.substring(r);break}else {let B=o.substring(r,A).trim();B&&t.push(B),r=A+1;}}for(let A of t){if(A==="data: [DONE]")return;if(A.startsWith("data: ")){let B=A.substring(6);try{let C=JSON.parse(B),L={partialMessages:[]},H=!1;if((C.type==="response.output_text.delta"||C.type==="output_text.delta")&&typeof C.delta=="string"&&C.delta.length>0&&(L.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,C.delta)),H=!0),C.type==="response.content_part.added"&&C.part){let G=C.part;G.type==="output_text"&&typeof G.text=="string"&&G.text.length>0&&(L.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,G.text)),H=!0);}if(!H&&C.delta){let G=C.delta;typeof G=="string"&&G.length>0?(L.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,G)),H=!0):G&&typeof G=="object"&&G.text!==void 0&&G.text!==null?(L.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,G.text)),H=!0):Array.isArray(G.content)&&G.content.forEach(P=>{var V,me,de,ce;if((P==null?void 0:P.type)==="output_text"&&(P!=null&&P.text))L.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,P.text)),H=!0;else if((P==null?void 0:P.type)==="tool_call"&&(P!=null&&P.tool_call)){let E=P.tool_call;L.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,(V=E.index)!=null?V:0,(me=E.id)!=null?me:"",(de=E.function)==null?void 0:de.name,(ce=E.function)==null?void 0:ce.arguments)),H=!0;}});}if((C.type==="tool_call"||C.type==="tool_call.delta"||C.type==="response.tool_call.delta")&&(l=C.delta)!=null&&l.tool_call){let G=C.delta.tool_call;L.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,(p=G.index)!=null?p:0,(g=G.id)!=null?g:"",(T=G.function)==null?void 0:T.name,(x=G.function)==null?void 0:x.arguments));}if(!C.delta&&(C.output||C.outputs)){let G=C.output||C.outputs;Array.isArray(G)&&G.forEach(P=>{var V,me,de,ce;if((P==null?void 0:P.type)==="message"&&Array.isArray(P.content))P.content.forEach(E=>{var rn,ln,pn,mn;if(((E==null?void 0:E.type)==="text"||(E==null?void 0:E.type)==="output_text")&&(E!=null&&E.text))L.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,E.text));else if((E==null?void 0:E.type)==="tool_call"&&(E!=null&&E.tool_call)){let Te=E.tool_call;L.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,(rn=Te.index)!=null?rn:0,(ln=Te.id)!=null?ln:"",(pn=Te.function)==null?void 0:pn.name,(mn=Te.function)==null?void 0:mn.arguments));}});else if(((P==null?void 0:P.type)==="text"||(P==null?void 0:P.type)==="output_text")&&(P!=null&&P.text))L.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,P.text));else if((P==null?void 0:P.type)==="tool_call"&&(P!=null&&P.tool_call)){let E=P.tool_call;L.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,(V=E.index)!=null?V:0,(me=E.id)!=null?me:"",(de=E.function)==null?void 0:de.name,(ce=E.function)==null?void 0:ce.arguments));}});}C.usage&&(L.usage={promptTokens:(I=(O=C.usage.input_tokens)!=null?O:C.usage.prompt_tokens)!=null?I:0,completionTokens:(D=(R=C.usage.output_tokens)!=null?R:C.usage.completion_tokens)!=null?D:0,totalTokens:(S=C.usage.total_tokens)!=null?S:(C.usage.input_tokens||0)+(C.usage.output_tokens||0)}),(L.partialMessages.length>0||L.usage)&&(yield {partialResponse:L,buffer:n});}catch(C){throw new provider.ModelResponseError({info:`Malformed JSON received in stream: ${B}`,cause:C})}}}})}transformProxyStreamChatResponseChunk(e,s,o,t,n){return ie(this,null,function*(){yield*Me(this.transformStreamChatResponseChunk(e,s));})}getProxyStreamChatUrl(e,s,o){return k(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getProxyCompleteChatUrl(e,s,o){return k(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getProxyCompleteChatHeaders(e,s,o){return k(this,null,function*(){if(!s)return {};let t=b({},s);return delete t.host,delete t["content-length"],t})}getProxyStreamChatHeaders(e,s,o){return k(this,null,function*(){let t=yield this.getProxyCompleteChatHeaders(e,s,o);return q(b({},t),{Accept:"text/event-stream"})})}getModelPricing(){if(!(this.modelName in f))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return f[this.modelName]}};var be="gpt-3.5-turbo-0125",qi="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.",nt=provider.ChatModelSchema(d,v).parse({name:be,description:qi,maxInputTokens:4092,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.responseFormat(4092,4).def,schema:a.responseFormat(4092,4).schema},price:f[be]}),En=h,xe=class extends u{constructor(e){super(nt,e);}};var Se="gpt-3.5-turbo-1106",Ui="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.",st=provider.ChatModelSchema(d,v).parse({name:Se,description:Ui,maxInputTokens:4092,maxOutputTokens:16385,roles:c,modalities:w,config:{def:a.responseFormat(16385,4).def,schema:a.responseFormat(16385,4).schema},price:f[Se]}),Gn=h,Ie=class extends u{constructor(e){super(st,e);}};var Re="gpt-3.5-turbo",ji="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",it=provider.ChatModelSchema(d,v).parse({name:Re,description:ji,maxInputTokens:4092,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.responseFormat(4092,4).def,schema:a.responseFormat(4092,4).schema},price:f[Re]}),kn=h,Ae=class extends u{constructor(e){super(it,e);}};var Ee="gpt-4-0125-preview",Fi="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.",at=provider.ChatModelSchema(d,v).parse({name:Ee,description:Fi,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.base(4092,4).def,schema:a.base(4092,4).schema},price:f[Ee]}),wn=h,Ge=class extends u{constructor(e){super(at,e);}};var ke="gpt-4-0613",Vi="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",rt=provider.ChatModelSchema(d,v).parse({name:ke,description:Vi,maxInputTokens:8192,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.base(4092,4).def,schema:a.base(4092,4).schema},price:f[ke]}),vn=h,we=class extends u{constructor(e){super(rt,e);}};var ve="gpt-4-1106-preview",Ji="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.",lt=provider.ChatModelSchema(d,v).parse({name:ve,description:Ji,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.base(4092,4).def,schema:a.base(4092,4).schema},price:f[ve]}),Dn=h,De=class extends u{constructor(e){super(lt,e);}};var Le="gpt-4.1",Yi="Flagship model for complex tasks. It is well suited for problem solving across domains. Training data up to May 2024.",pt=provider.ChatModelSchema(d,M).parse({name:Le,description:Yi,maxInputTokens:1047576,maxOutputTokens:32768,roles:c,modalities:y,config:{def:a.responseSchema(32768,4).def,schema:a.responseSchema(32768,4).schema},price:f[Le]}),Ln=h,Ne=class extends u{constructor(e){super(pt,e);}};var qe="gpt-4.1-mini",Xi="Provides a balance between intelligence, speed, and cost that makes it an attractive model for many use cases. Training data up to May 2024.",mt=provider.ChatModelSchema(d,M).parse({name:qe,description:Xi,maxInputTokens:1047576,maxOutputTokens:32768,roles:c,modalities:y,config:{def:a.responseSchema(32768,4).def,schema:a.responseSchema(32768,4).schema},price:f[qe]}),Nn=h,ze=class extends u{constructor(e){super(mt,e);}};var Ue="gpt-4.1-nano",ea="Fastest, most cost-effective GPT-4.1 model. Training data up to May 2024.",dt=provider.ChatModelSchema(d,M).parse({name:Ue,description:ea,maxInputTokens:1047576,maxOutputTokens:32768,roles:c,modalities:y,config:{def:a.responseSchema(32768,4).def,schema:a.responseSchema(32768,4).schema},price:f[Ue]}),qn=h,Be=class extends u{constructor(e){super(dt,e);}};var je="gpt-5.1",ta="Flagship GPT-5.1 model for coding and agentic tasks with configurable reasoning effort. Training data up to September 2024.",ct=provider.ChatModelSchema(d,M).parse({name:je,description:ta,maxInputTokens:4e5,maxOutputTokens:128e3,roles:c,modalities:y,config:{def:a.gpt5(128e3,4).def,schema:a.gpt5(128e3,4).schema},price:f[je]}),zn=h,$e=class extends u{constructor(e){super(ct,e);}};var Fe="gpt-5.2",sa="Flagship GPT-5.2 model with enhanced reasoning controls and extended knowledge coverage. Training data up to January 2025.",ut=provider.ChatModelSchema(d,M).parse({name:Fe,description:sa,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:f[Fe]}),Un=h,He=class extends u{constructor(e){super(ut,e);}};var Ve="gpt-5.2-chat-latest",aa="Latest GPT-5.2 chat-optimized model for conversational workloads with tool/function calling support. Training data up to January 2025.",ra=y,la=M,ht=provider.ChatModelSchema(d,la).parse({name:Ve,description:aa,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:ra,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:f[Ve]}),Bn=h,Ke=class extends u{constructor(e){super(ht,e);}};var Je="gpt-5.2-pro",ma="GPT-5.2 Pro available via the OpenAI Responses API for advanced reasoning and agentic workflows. Training data up to January 2025.",ft=provider.ChatModelSchema(d,M).parse({name:Je,description:ma,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:f[Je]}),jn=sn,We=class extends Bo{constructor(e){super(ft,e);}};var Ye="gpt-5",ca="Most advanced GPT-5 model for complex reasoning and problem-solving tasks. Training data up to October 2024.",gt=provider.ChatModelSchema(d,M).parse({name:Ye,description:ca,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:f[Ye]}),$n=h,Qe=class extends u{constructor(e){super(gt,e);}};var Xe="gpt-5-mini",ha="Faster, more cost-effective GPT-5 model that balances intelligence and efficiency. Training data up to October 2024.",_t=provider.ChatModelSchema(d,M).parse({name:Xe,description:ha,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:f[Xe]}),Fn=h,Ze=class extends u{constructor(e){super(_t,e);}};var eo="gpt-5-nano",ga="Most cost-effective GPT-5 model optimized for speed and efficiency. Training data up to October 2024.",Tt=provider.ChatModelSchema(d,M).parse({name:eo,description:ga,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:y,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:f[eo]}),Hn=h,oo=class extends u{constructor(e){super(Tt,e);}};var to="gpt-5-chat-latest",ya="Latest GPT-5 model optimized for conversational use. Does not support function calling or structured outputs. Training data up to October 2024.",Ma=[types.TextModalityLiteral,types.ImageModalityLiteral],Ca=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral]),yt=provider.ChatModelSchema(d,Ca).parse({name:to,description:ya,maxInputTokens:4e5,maxOutputTokens:131072,roles:c,modalities:Ma,config:{def:a.gpt5(131072,4).def,schema:a.gpt5(131072,4).schema},price:f[to]}),Vn=h,no=class extends u{constructor(e){super(yt,e);}};var so="gpt-4-turbo-2024-04-09",Pa="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.",Mt=provider.ChatModelSchema(d,M).parse({name:so,description:Pa,maxInputTokens:128e3,maxOutputTokens:4096,roles:c,modalities:y,config:{def:a.responseFormat(4096,4).def,schema:a.responseFormat(4096,4).schema},price:f[so]}),Kn=h,io=class extends u{constructor(e){super(Mt,e);}};var ao="gpt-4-turbo-preview",xa="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",Ct=provider.ChatModelSchema(d,v).parse({name:ao,description:xa,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.responseFormat(4092,4).def,schema:a.responseFormat(4092,4).schema},price:f[ao]}),Jn=h,ro=class extends u{constructor(e){super(Ct,e);}};var lo="gpt-4-turbo",Ia="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.",Ot=provider.ChatModelSchema(d,M).parse({name:lo,description:Ia,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseFormat(4092,4).def,schema:a.responseFormat(4092,4).schema},price:f[lo]}),Wn=h,po=class extends u{constructor(e){super(Ot,e);}};var mo="gpt-4",Aa="Currently points to gpt-4-0613. Training data up to Sept 2021.",Pt=provider.ChatModelSchema(d,v).parse({name:mo,description:Aa,maxInputTokens:8192,maxOutputTokens:4092,roles:c,modalities:w,config:{def:a.base(4092,4).def,schema:a.base(4092,4).schema},price:f[mo]}),Yn=h,co=class extends u{constructor(e){super(Pt,e);}};var uo="gpt-4o-2024-05-13",Ga="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",bt=provider.ChatModelSchema(d,M).parse({name:uo,description:Ga,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:f[uo]}),Qn=h,ho=class extends u{constructor(e){super(bt,e);}};var fo="gpt-4o-2024-08-06",wa="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",xt=provider.ChatModelSchema(d,M).parse({name:fo,description:wa,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:f[fo]}),Xn=h,go=class extends u{constructor(e){super(xt,e);}};var _o="gpt-4o-mini-2024-07-18",Da="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.",St=provider.ChatModelSchema(d,M).parse({name:_o,description:Da,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:f[_o]}),Zn=h,To=class extends u{constructor(e){super(St,e);}};var yo="gpt-4o-mini",Na="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.",It=provider.ChatModelSchema(d,M).parse({name:yo,description:Na,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:f[yo]}),es=h,Mo=class extends u{constructor(e){super(It,e);}};var Co="gpt-4o",za="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.",Rt=provider.ChatModelSchema(d,M).parse({name:Co,description:za,maxInputTokens:128e3,maxOutputTokens:4092,roles:c,modalities:y,config:{def:a.responseSchema(4092,4).def,schema:a.responseSchema(4092,4).schema},price:f[Co]}),os=h,Oo=class extends u{constructor(e){super(Rt,e);}};var Po="o1-2024-12-17",Ba="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",At=provider.ChatModelSchema(d,M).parse({name:Po,description:Ba,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema},price:f[Po]}),ts=h,bo=class extends u{constructor(e){super(At,e);}};var xo="o1",$a="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",Et=provider.ChatModelSchema(d,M).parse({name:xo,description:$a,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema},price:f[xo]}),ns=h,So=class extends u{constructor(e){super(Et,e);}};var Gt="o3-2025-04-16",Ha="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",kt=provider.ChatModelSchema(d,M).parse({name:Gt,description:Ha,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),ss=h,Io=class extends u{constructor(e){super(kt,e);}};var wt="o3",Ka="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",vt=provider.ChatModelSchema(d,M).parse({name:wt,description:Ka,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),is=h,Ro=class extends u{constructor(e){super(vt,e);}};var Dt="o3-mini",Wa="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.",Lt=provider.ChatModelSchema(d,v).parse({name:Dt,description:Wa,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:w,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),as=h,Ao=class extends u{constructor(e){super(Lt,e);}};var Nt="o3-mini-2025-01-31",Qa="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.",qt=provider.ChatModelSchema(d,v).parse({name:Nt,description:Qa,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:w,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),rs=h,Eo=class extends u{constructor(e){super(qt,e);}};var zt="o4-mini-2025-04-16",Za="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",Ut=provider.ChatModelSchema(d,M).parse({name:zt,description:Za,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),ls=h,Go=class extends u{constructor(e){super(Ut,e);}};var Bt="o4-mini",or="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",jt=provider.ChatModelSchema(d,M).parse({name:Bt,description:or,maxInputTokens:2e5,maxOutputTokens:1e5,roles:c,modalities:y,config:{def:a.oSeries(1e5,4).def,schema:a.oSeries(1e5,4).schema}}),ps=h,ko=class extends u{constructor(e){super(jt,e);}};var le=[types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral],pe=zod.z.enum([types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral]);var ws=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 nr=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)),vs=zod.z.object({model:zod.z.string().min(1).optional(),input:nr,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()});var se=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),X=class{constructor(e,s){this.version="v1";let o=se.parse(s);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,s){let o=p=>{let g=/(\d+)(h|m|s|ms)/g,T={h:36e5,m:6e4,s:1e3,ms:1},x,O=0;for(;(x=g.exec(p))!==null;){let I=parseInt(x[1]),R=x[2];O+=I*T[R];}return O},t=0,n=0,r=!0;e["x-ratelimit-reset-requests"]&&(t=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(n=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(t,n);return {shouldRetry:r,delayMs:l}}getTokenCount(e){return e.requests.reduce((s,o)=>s+o.length,0)}transformModelRequest(e){let s=vs.safeParse(e);if(!s.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:s.error});let o=s.data,t=o.model,n={encodingFormat:o.encoding_format,dimensions:o.dimensions},r=types.Config().parse(provider.removeUndefinedEntries(n)),l,p;return typeof o.input=="string"?p=types.EmbeddingTextModalityLiteral:typeof o.input[0]=="string"?p=types.EmbeddingTextModalityLiteral:p=types.EmbeddingTokenModalityLiteral,p===types.EmbeddingTextModalityLiteral?typeof o.input=="string"?l={modality:p,requests:[o.input]}:l={modality:p,requests:o.input}:typeof o.input[0]=="number"?l={modality:p,requests:[o.input]}:l={modality:p,requests:o.input},{modelName:t,config:r,embeddingRequests:l}}transformConfig(e,s){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 t=o.data;return Object.keys(t).forEach(r=>{if(!this.modelSchema.config.def[r])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${r}',
|
|
18
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(t).reduce((r,l)=>{let g=this.modelSchema.config.def[l].param,T=t[l];return r[g]=T,r},{})}transformEmbeddingRequests(e){let s=types.EmbeddingRequests().safeParse(e);if(!s.success)throw new provider.InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:s.error});return {input:s.data.requests}}getGetEmbeddingsUrl(e,s){return k(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,s){return k(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,s){return k(this,null,function*(){return new Promise(o=>{o(b(b(b({},this.getDefaultParams()),this.transformConfig(e,s)),this.transformEmbeddingRequests(s)));})})}transformGetEmbeddingsResponse(e){let s,o=ws.safeParse(e);if(o.success){let t=o.data;s=typeof t.data[0].embedding=="string"?types.Base64EmbeddingLiteral:types.FloatEmbeddingLiteral;let n=t.data.map(r=>typeof r.embedding=="string"?{index:r.index,embedding:r.embedding}:{index:r.index,embedding:r.embedding});return {encodingFormat:s,embeddings:n,usage:{totalTokens:t.usage.total_tokens}}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:o.error})}};var $t="text-embedding-ada-002",hr="Most capable 2nd generation embedding model, replacing 16 first generation models",Ft=provider.EmbeddingModelSchema(pe).parse({name:$t,description:hr,modalities:le,maxInputTokens:8192,maxOutputTokens:1536,config:{def:K.base().def,schema:K.base().schema}}),ms=se,wo=class extends X{constructor(e){super(Ft,e);}};var Ht="text-embedding-3-small",gr="Increased performance over 2nd generation ada embedding model",Vt=provider.EmbeddingModelSchema(pe).parse({name:Ht,description:gr,modalities:le,maxInputTokens:8192,maxOutputTokens:1536,config:{def:K.dimensions(1536).def,schema:K.dimensions(1536).schema}}),ds=se,vo=class extends X{constructor(e){super(Vt,e);}};var Kt="text-embedding-3-large",Tr="Most capable embedding model for both english and non-english tasks",Jt=provider.EmbeddingModelSchema(pe).parse({name:Kt,description:Tr,modalities:le,maxInputTokens:8192,maxOutputTokens:3072,config:{def:K.dimensions(3072).def,schema:K.dimensions(3072).schema}}),cs=se,Do=class extends X{constructor(e){super(Jt,e);}};
|
|
19
19
|
|
|
20
20
|
exports.BaseChatModel = u;
|
|
21
21
|
exports.BaseChatModelOptions = h;
|
|
@@ -62,12 +62,12 @@ exports.GPT_4_0613Literal = ke;
|
|
|
62
62
|
exports.GPT_4_0613Options = vn;
|
|
63
63
|
exports.GPT_4_0613Schema = rt;
|
|
64
64
|
exports.GPT_4_1 = Ne;
|
|
65
|
-
exports.GPT_4_1106_Preview =
|
|
65
|
+
exports.GPT_4_1106_Preview = De;
|
|
66
66
|
exports.GPT_4_1106_PreviewLiteral = ve;
|
|
67
|
-
exports.GPT_4_1106_PreviewOptions =
|
|
67
|
+
exports.GPT_4_1106_PreviewOptions = Dn;
|
|
68
68
|
exports.GPT_4_1106_PreviewSchema = lt;
|
|
69
|
-
exports.GPT_4_1Literal =
|
|
70
|
-
exports.GPT_4_1Options =
|
|
69
|
+
exports.GPT_4_1Literal = Le;
|
|
70
|
+
exports.GPT_4_1Options = Ln;
|
|
71
71
|
exports.GPT_4_1Schema = pt;
|
|
72
72
|
exports.GPT_4_1_Mini = ze;
|
|
73
73
|
exports.GPT_4_1_MiniLiteral = qe;
|
|
@@ -156,9 +156,9 @@ exports.O3Mini2025_01_31 = Eo;
|
|
|
156
156
|
exports.O3Mini2025_01_31Literal = Nt;
|
|
157
157
|
exports.O3Mini2025_01_31Options = rs;
|
|
158
158
|
exports.O3Mini2025_01_31Schema = qt;
|
|
159
|
-
exports.O3MiniLiteral =
|
|
159
|
+
exports.O3MiniLiteral = Dt;
|
|
160
160
|
exports.O3MiniOptions = as;
|
|
161
|
-
exports.O3MiniSchema =
|
|
161
|
+
exports.O3MiniSchema = Lt;
|
|
162
162
|
exports.O3Options = is;
|
|
163
163
|
exports.O3Schema = vt;
|
|
164
164
|
exports.O3_2025_04_16 = Io;
|
|
@@ -207,7 +207,7 @@ exports.OpenAIStreamChatResponse = Ms;
|
|
|
207
207
|
exports.OpenAIToolCallsCompleteChatResponse = si;
|
|
208
208
|
exports.OpenAIToolCallsStreamChatResponse = ii;
|
|
209
209
|
exports.ProviderLiteral = ti;
|
|
210
|
-
exports.Text_Embedding_3_Large =
|
|
210
|
+
exports.Text_Embedding_3_Large = Do;
|
|
211
211
|
exports.Text_Embedding_3_LargeLiteral = Kt;
|
|
212
212
|
exports.Text_Embedding_3_LargeSchema = Jt;
|
|
213
213
|
exports.Text_Embedding_3_Large_Options = cs;
|