@adaline/azure 1.8.4 → 1.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,9 +9,9 @@ Message: ${xs(n)}`),this.name=at,this.info=o,this.cause=n,this.name=s!=null?s:at
9
9
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(l).reduce((d,u)=>{let c=this.modelSchema.config.def[u],x=c.param,f=l[u];return x==="max_completion_tokens"&&c.type==="range"&&f===0?d[x]=c.max:d[x]=f,d},{});if(r.top_logprobs&&!r.logprobs)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in r&&r.tool_choice!==void 0){let d=r.tool_choice;if(!n||n&&n.length===0)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(n&&n.length>0){let u=this.modelSchema.config.def.toolChoice;if(!u.choices.includes(d))if(n.map(c=>c.definition.schema.name).includes(d))r.tool_choice={type:"function",function:{name:d}};else throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
10
10
  one of [${u.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let d=r.response_format;if(d==="json_schema")if("response_schema"in r)r.response_format={type:"json_schema",json_schema:r.response_schema},delete r.response_schema;else throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else r.response_format={type:d};}return r}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let o=e.map(n=>{let s=Ce().safeParse(n);if(!s.success)throw new N({info:"Invalid messages",cause:s.error});return s.data});return o.forEach(n=>{n.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new N({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${s.modality}',
11
11
  available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(n=>{if(!Object.keys(this.modelSchema.roles).includes(n.role))throw new N({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${n.role}',
12
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:o.map(n=>{switch(n.role){case me:{let s=[];return n.content.forEach(a=>{if(a.modality===U)s.push({type:"text",text:a.value});else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case A:{let s=[],a=[];return n.content.forEach(l=>{if(l.modality===U)s.push({type:"text",text:l.value});else if(l.modality===D)a.push({id:l.id,type:"function",function:{name:l.name,arguments:l.arguments}});else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${l.modality}'`)})}),k({role:this.modelSchema.roles[n.role],content:s},a.length>0?{tool_calls:a}:{})}case de:{let s=[],a=[];n.content.forEach(r=>{if(r.modality===U)s.push({type:"text",text:r.value});else if(r.modality===J)a.push({type:"image_url",image_url:{url:r.value.type==="url"?r.value.url:r.value.base64,detail:r.detail}});else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${r.modality}'`)})});let l=[...s,...a];return {role:this.modelSchema.roles[n.role],content:l}}case pe:{if(n.content.length!==1)throw new N({info:`Invalid message for role : '${n.role}'`,cause:new Error(`role : '${n.role}' must have exactly one content item`)});if(n.content[0].modality!==H)throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' must have content with modality : '${H}'`)});let s=n.content[0];return {role:this.modelSchema.roles[n.role],tool_call_id:s.id,content:s.data}}default:throw new N({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' is not supported,
12
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),o.forEach(n=>{n.content=n.content.filter(s=>s.modality!=="error"&&s.modality!=="search-result");}),{messages:o.map(n=>{switch(n.role){case me:{let s=[];return n.content.forEach(a=>{if(a.modality===U)s.push({type:"text",text:a.value});else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case A:{let s=[],a=[];return n.content.forEach(l=>{if(l.modality===U)s.push({type:"text",text:l.value});else if(l.modality===D)a.push({id:l.id,type:"function",function:{name:l.name,arguments:l.arguments}});else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${l.modality}'`)})}),k({role:this.modelSchema.roles[n.role],content:s},a.length>0?{tool_calls:a}:{})}case de:{let s=[],a=[];n.content.forEach(r=>{if(r.modality===U)s.push({type:"text",text:r.value});else if(r.modality===J)a.push({type:"image_url",image_url:{url:r.value.type==="url"?r.value.url:r.value.base64,detail:r.detail}});else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${r.modality}'`)})});let l=[...s,...a];return {role:this.modelSchema.roles[n.role],content:l}}case pe:{if(n.content.length!==1)throw new N({info:`Invalid message for role : '${n.role}'`,cause:new Error(`role : '${n.role}' must have exactly one content item`)});if(n.content[0].modality!==H)throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' must have content with modality : '${H}'`)});let s=n.content[0];return {role:this.modelSchema.roles[n.role],tool_call_id:s.id,content:s.data}}default:throw new N({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' is not supported,
13
13
  available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(e){if(!this.modelSchema.modalities.includes(D))throw new ve({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${D}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(o=>{let n=gt().safeParse(o);if(!n.success)throw new ve({info:"Invalid tools",cause:n.error});return n.data}).map(o=>({type:"function",function:o.definition.schema}))}}getCompleteChatUrl(e,o,n){return $(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,n){return $(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(e,o,n){return $(this,null,function*(){let s=this.transformConfig(e,o,n),a=this.transformMessages(o);if(a.messages&&a.messages.length===0)throw new N({info:"Messages are required",cause:new Error("Messages are required")});let l=n?this.transformTools(n):{};return new Promise(r=>{r(k(k(k(k({},this.getDefaultParams()),s),a),l));})})}transformCompleteChatResponse(e){let o=wi.safeParse(e);if(o.success){if(o.data.choices.length===0)throw new z({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(o.data)}`)});let n=o.data,s=[{role:A,content:[]}],a=n.choices[0].message;a.content&&s[0].content.push(ue(a.content)),a.refusal&&s[0].content.push(ue(a.refusal)),a.tool_calls&&a.tool_calls.forEach((u,c)=>{s[0].content.push(Ee(c,u.id,u.function.name,u.function.arguments));});let l={promptTokens:n.usage.prompt_tokens,completionTokens:n.usage.completion_tokens,totalTokens:n.usage.total_tokens},r=[],d=n.choices[0].logprobs;return d&&(d.content&&r.push(...d.content.map(u=>({token:u.token,logProb:u.logprob,bytes:u.bytes,topLogProbs:u.top_logprobs.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes}))}))),d.refusal&&r.push(...d.refusal.map(u=>({token:u.token,logProb:u.logprob,bytes:u.bytes,topLogProbs:u.top_logprobs.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes}))})))),{messages:s,usage:l,logProbs:r}}throw new z({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,n){return $(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,o,n){return $(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(e,o,n){return $(this,null,function*(){let s=this.transformConfig(e,o,n),a=this.transformMessages(o);if(a.messages&&a.messages.length===0)throw new N({info:"Messages are required",cause:new Error("Messages are required")});let l=n?this.transformTools(n):{};return new Promise(r=>{r(k(k(k(k({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),a),l));})})}transformStreamChatResponseChunk(e,o){return je(this,null,function*(){var n,s;let a=o+e,l=[],r="",d=0;for(;d<a.length;){let u=a.indexOf(`
14
- `,d);if(u===-1){r=a.substring(d);break}else {let c=a.substring(d,u).trim();c&&l.push(c),d=u+1;}}for(let u of l){if(u==="data: [DONE]")return;if(u.startsWith("data: ")){let c=u.substring(6);try{let x=JSON.parse(c),f=Ii.safeParse(x);if(f.success){let y={partialMessages:[]},g=f.data;if(g.choices.length>0){let I=g.choices[0].delta;if(I!==void 0&&Object.keys(I).length!==0){if("content"in I&&I.content!==null)y.partialMessages.push(Y(A,I.content));else if("refusal"in I&&I.refusal!==null)y.partialMessages.push(Y(A,I.refusal));else if("tool_calls"in I&&I.tool_calls!==void 0){let M=I.tool_calls.at(0);y.partialMessages.push(ge(A,M.index,M.id,(n=M.function)==null?void 0:n.name,(s=M.function)==null?void 0:s.arguments));}}}g.usage&&(y.usage={promptTokens:g.usage.prompt_tokens,completionTokens:g.usage.completion_tokens,totalTokens:g.usage.total_tokens}),yield {partialResponse:y,buffer:r};}else throw new z({info:"Invalid response from model",cause:f.error})}catch(x){throw new z({info:`Malformed JSON received in stream: ${c}`,cause:x})}}}yield {partialResponse:{partialMessages:[]},buffer:r};})}transformProxyStreamChatResponseChunk(e,o,n,s,a){return je(this,null,function*(){yield*nt(mn(this.transformStreamChatResponseChunk(e,o)));})}getProxyStreamChatUrl(e,o,n){return $(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,o,n){return $(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,o,n){return $(this,null,function*(){if(!o)return {};let s=k({},o);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(e,o,n){return $(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,o,n)})}getModelPricing(){if(!(this.modelName in S))throw new z({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return S[this.modelName]}},Rn=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),Fi=class{constructor(e,o){this.version="v1";let n=Rn.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=re(n.baseUrl||$e.baseUrl),this.responsesUrl=`${this.baseUrl}/responses`,this.organization=n.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return k({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){let o=r=>{let d=/(\d+)(h|m|s|ms)/g,u={h:36e5,m:6e4,s:1e3,ms:1},c,x=0;for(;(c=d.exec(r))!==null;){let f=parseInt(c[1]),y=c[2];x+=f*u[y];}return x},n=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(n=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(n,s);return {shouldRetry:a,delayMs:l}}getTokenCount(e){return e.reduce((o,n)=>o+n.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(e){throw new z({info:"transformModelRequest not supported for Responses API models",cause:new Error("Use the standard gateway interface with config, messages, and tools parameters")})}transformConfig(e,o,n){let s=we().parse(e),a={};for(let d of Object.keys(this.modelSchema.config.def)){let u=this.modelSchema.config.def[d],c=u==null?void 0:u.param;c&&s[d]!==void 0&&(a[c]=s[d]);}let l=s.toolChoice;if(l!==void 0)if(n&&n.length>0){let d=l,u=n.map(c=>c.definition.schema.name);if(["none","auto","required"].includes(d))a.tool_choice=d;else if(u.includes(d))a.tool_choice={type:"function",function:{name:d}};else throw new K({info:`Invalid tool choice for model : '${this.modelName}'`,cause:new Error(`Tool with name '${d}' not found in tools`)})}else throw new K({info:`Invalid tool choice for model : '${this.modelName}'`,cause:new Error("Tools are required when tool_choice is specified")});let r=s.responseFormat;if(r!==void 0)if(r==="json_schema"){if(!s.responseSchema)throw new K({info:`Invalid response schema for model : '${this.modelName}'`,cause:new Error("Response schema is required when response format is 'json_schema'")});a.response_format={type:r,json_schema:a.response_schema},delete a.response_schema;}else a.response_format={type:r};return "reasoning_effort"in a&&a.reasoning_effort!==void 0&&(a.reasoning={effort:a.reasoning_effort},delete a.reasoning_effort),"verbosity"in a&&a.verbosity!==void 0&&(a.text={verbosity:a.verbosity},delete a.verbosity),a}transformMessages(e){if(!e||e.length===0)return {messages:[]};let o=e.map(n=>{let s=Ce().safeParse(n);if(!s.success)throw new N({info:"Invalid messages",cause:s.error});return s.data});return o.forEach(n=>{n.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new N({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${s.modality}'`)})});}),o.forEach(n=>{if(!Object.keys(this.modelSchema.roles).includes(n.role))throw new N({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${n.role}'`)})}),{messages:o.map(n=>{switch(n.role){case me:{let s=[];return n.content.forEach(a=>{if(a.modality===U)s.push({type:"input_text",text:a.value});else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case A:{let s=[];return n.content.forEach(a=>{if(a.modality===U)s.push({type:"output_text",text:a.value});else throw a.modality===D?new N({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 N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case de:{let s=[];return n.content.forEach(a=>{if(a.modality===U)s.push({type:"input_text",text:a.value});else if(a.modality===J){let l=a.value,r=l.type==="url"?l.url:l.base64;s.push({type:"image_url",image_url:{url:r,detail:a.detail}});}else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case pe:{if(n.content.length!==1)throw new N({info:`Invalid message for role : '${n.role}'`,cause:new Error(`role : '${n.role}' must have exactly one content item`)});if(n.content[0].modality!==H)throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' must have content with modality : '${H}'`)});let s=n.content[0];return {role:this.modelSchema.roles[n.role],tool_call_id:s.id,content:s.data}}default:throw new N({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' is not supported`)})}})}}transformTools(e){if(!e||e.length===0)return {tools:[]};if(!this.modelSchema.modalities.includes(D))throw new ve({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality`)});return {tools:e.map(o=>{let n=gt().safeParse(o);if(!n.success)throw new ve({info:"Invalid tools",cause:n.error});return n.data}).map(o=>({type:"function",function:o.definition.schema}))}}getCompleteChatUrl(e,o,n){return $(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getCompleteChatHeaders(e,o,n){return $(this,null,function*(){return Promise.resolve(this.getDefaultHeaders())})}getCompleteChatData(e,o,n){return $(this,null,function*(){let s=this.transformConfig(e,o,n),a=this.transformMessages(o);if(a.messages&&a.messages.length===0)throw new N({info:"Messages are required",cause:new Error("Messages are required")});let l=n?this.transformTools(n):{};return Promise.resolve(ne(k(k(k({},this.getDefaultParams()),s),l),{input:a.messages}))})}transformCompleteChatResponse(e){var o,n,s,a,l,r,d,u,c,x,f;let y=(e==null?void 0:e.output)||(e==null?void 0:e.outputs);if(!y||!Array.isArray(y)||y.length===0)throw new z({info:"Invalid response from model",cause:new Error(`No output in response : ${JSON.stringify(e)}`)});let g=[{role:A,content:[]}];for(let M of y)if((M==null?void 0:M.type)==="message"&&Array.isArray(M.content))M.content.forEach(G=>{var F,h,q,V,R,O;if((G==null?void 0:G.type)==="text"||(G==null?void 0:G.type)==="output_text")G.text&&g[0].content.push(ue(G.text));else if((G==null?void 0:G.type)==="tool_call"&&G.tool_call){let W=G.tool_call;g[0].content.push(Ee((F=W.index)!=null?F:0,(h=W.id)!=null?h:"",(V=(q=W.function)==null?void 0:q.name)!=null?V:"",(O=(R=W.function)==null?void 0:R.arguments)!=null?O:""));}});else if(((M==null?void 0:M.type)==="text"||(M==null?void 0:M.type)==="output_text")&&M!=null&&M.text)g[0].content.push(ue(M.text));else if((M==null?void 0:M.type)==="tool_call"&&M.tool_call){let G=M.tool_call;g[0].content.push(Ee((o=G.index)!=null?o:0,(n=G.id)!=null?n:"",(a=(s=G.function)==null?void 0:s.name)!=null?a:"",(r=(l=G.function)==null?void 0:l.arguments)!=null?r:""));}if(g[0].content.length===0){let M=y[0],G=(M==null?void 0:M.content)||[],F=[];if(G.forEach(h=>{((h==null?void 0:h.type)==="text"||(h==null?void 0:h.type)==="output_text")&&h!=null&&h.text&&F.push(h.text);}),F.length>0)g[0].content.push(ue(F.join(`
14
+ `,d);if(u===-1){r=a.substring(d);break}else {let c=a.substring(d,u).trim();c&&l.push(c),d=u+1;}}for(let u of l){if(u==="data: [DONE]")return;if(u.startsWith("data: ")){let c=u.substring(6);try{let x=JSON.parse(c),f=Ii.safeParse(x);if(f.success){let y={partialMessages:[]},g=f.data;if(g.choices.length>0){let I=g.choices[0].delta;if(I!==void 0&&Object.keys(I).length!==0){if("content"in I&&I.content!==null)y.partialMessages.push(Y(A,I.content));else if("refusal"in I&&I.refusal!==null)y.partialMessages.push(Y(A,I.refusal));else if("tool_calls"in I&&I.tool_calls!==void 0){let M=I.tool_calls.at(0);y.partialMessages.push(ge(A,M.index,M.id,(n=M.function)==null?void 0:n.name,(s=M.function)==null?void 0:s.arguments));}}}g.usage&&(y.usage={promptTokens:g.usage.prompt_tokens,completionTokens:g.usage.completion_tokens,totalTokens:g.usage.total_tokens}),yield {partialResponse:y,buffer:r};}else throw new z({info:"Invalid response from model",cause:f.error})}catch(x){throw new z({info:`Malformed JSON received in stream: ${c}`,cause:x})}}}yield {partialResponse:{partialMessages:[]},buffer:r};})}transformProxyStreamChatResponseChunk(e,o,n,s,a){return je(this,null,function*(){yield*nt(mn(this.transformStreamChatResponseChunk(e,o)));})}getProxyStreamChatUrl(e,o,n){return $(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,o,n){return $(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,o,n){return $(this,null,function*(){if(!o)return {};let s=k({},o);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(e,o,n){return $(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,o,n)})}getModelPricing(){if(!(this.modelName in S))throw new z({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return S[this.modelName]}},Rn=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),Fi=class{constructor(e,o){this.version="v1";let n=Rn.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=re(n.baseUrl||$e.baseUrl),this.responsesUrl=`${this.baseUrl}/responses`,this.organization=n.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return k({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){let o=r=>{let d=/(\d+)(h|m|s|ms)/g,u={h:36e5,m:6e4,s:1e3,ms:1},c,x=0;for(;(c=d.exec(r))!==null;){let f=parseInt(c[1]),y=c[2];x+=f*u[y];}return x},n=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(n=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(n,s);return {shouldRetry:a,delayMs:l}}getTokenCount(e){return e.reduce((o,n)=>o+n.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(e){throw new z({info:"transformModelRequest not supported for Responses API models",cause:new Error("Use the standard gateway interface with config, messages, and tools parameters")})}transformConfig(e,o,n){let s=we().parse(e),a={};for(let d of Object.keys(this.modelSchema.config.def)){let u=this.modelSchema.config.def[d],c=u==null?void 0:u.param;c&&s[d]!==void 0&&(a[c]=s[d]);}let l=s.toolChoice;if(l!==void 0)if(n&&n.length>0){let d=l,u=n.map(c=>c.definition.schema.name);if(["none","auto","required"].includes(d))a.tool_choice=d;else if(u.includes(d))a.tool_choice={type:"function",function:{name:d}};else throw new K({info:`Invalid tool choice for model : '${this.modelName}'`,cause:new Error(`Tool with name '${d}' not found in tools`)})}else throw new K({info:`Invalid tool choice for model : '${this.modelName}'`,cause:new Error("Tools are required when tool_choice is specified")});let r=s.responseFormat;if(r!==void 0)if(r==="json_schema"){if(!s.responseSchema)throw new K({info:`Invalid response schema for model : '${this.modelName}'`,cause:new Error("Response schema is required when response format is 'json_schema'")});a.response_format={type:r,json_schema:a.response_schema},delete a.response_schema;}else a.response_format={type:r};return "reasoning_effort"in a&&a.reasoning_effort!==void 0&&(a.reasoning={effort:a.reasoning_effort},delete a.reasoning_effort),"verbosity"in a&&a.verbosity!==void 0&&(a.text={verbosity:a.verbosity},delete a.verbosity),a}transformMessages(e){if(!e||e.length===0)return {messages:[]};let o=e.map(n=>{let s=Ce().safeParse(n);if(!s.success)throw new N({info:"Invalid messages",cause:s.error});return s.data});return o.forEach(n=>{n.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new N({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${s.modality}'`)})});}),o.forEach(n=>{if(!Object.keys(this.modelSchema.roles).includes(n.role))throw new N({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${n.role}'`)})}),o.forEach(n=>{n.content=n.content.filter(s=>s.modality!=="error"&&s.modality!=="search-result");}),{messages:o.map(n=>{switch(n.role){case me:{let s=[];return n.content.forEach(a=>{if(a.modality===U)s.push({type:"input_text",text:a.value});else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case A:{let s=[];return n.content.forEach(a=>{if(a.modality===U)s.push({type:"output_text",text:a.value});else throw a.modality===D?new N({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 N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case de:{let s=[];return n.content.forEach(a=>{if(a.modality===U)s.push({type:"input_text",text:a.value});else if(a.modality===J){let l=a.value,r=l.type==="url"?l.url:l.base64;s.push({type:"image_url",image_url:{url:r,detail:a.detail}});}else throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${a.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case pe:{if(n.content.length!==1)throw new N({info:`Invalid message for role : '${n.role}'`,cause:new Error(`role : '${n.role}' must have exactly one content item`)});if(n.content[0].modality!==H)throw new N({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' must have content with modality : '${H}'`)});let s=n.content[0];return {role:this.modelSchema.roles[n.role],tool_call_id:s.id,content:s.data}}default:throw new N({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' is not supported`)})}})}}transformTools(e){if(!e||e.length===0)return {tools:[]};if(!this.modelSchema.modalities.includes(D))throw new ve({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality`)});return {tools:e.map(o=>{let n=gt().safeParse(o);if(!n.success)throw new ve({info:"Invalid tools",cause:n.error});return n.data}).map(o=>({type:"function",function:o.definition.schema}))}}getCompleteChatUrl(e,o,n){return $(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getCompleteChatHeaders(e,o,n){return $(this,null,function*(){return Promise.resolve(this.getDefaultHeaders())})}getCompleteChatData(e,o,n){return $(this,null,function*(){let s=this.transformConfig(e,o,n),a=this.transformMessages(o);if(a.messages&&a.messages.length===0)throw new N({info:"Messages are required",cause:new Error("Messages are required")});let l=n?this.transformTools(n):{};return Promise.resolve(ne(k(k(k({},this.getDefaultParams()),s),l),{input:a.messages}))})}transformCompleteChatResponse(e){var o,n,s,a,l,r,d,u,c,x,f;let y=(e==null?void 0:e.output)||(e==null?void 0:e.outputs);if(!y||!Array.isArray(y)||y.length===0)throw new z({info:"Invalid response from model",cause:new Error(`No output in response : ${JSON.stringify(e)}`)});let g=[{role:A,content:[]}];for(let M of y)if((M==null?void 0:M.type)==="message"&&Array.isArray(M.content))M.content.forEach(G=>{var F,h,q,V,R,O;if((G==null?void 0:G.type)==="text"||(G==null?void 0:G.type)==="output_text")G.text&&g[0].content.push(ue(G.text));else if((G==null?void 0:G.type)==="tool_call"&&G.tool_call){let W=G.tool_call;g[0].content.push(Ee((F=W.index)!=null?F:0,(h=W.id)!=null?h:"",(V=(q=W.function)==null?void 0:q.name)!=null?V:"",(O=(R=W.function)==null?void 0:R.arguments)!=null?O:""));}});else if(((M==null?void 0:M.type)==="text"||(M==null?void 0:M.type)==="output_text")&&M!=null&&M.text)g[0].content.push(ue(M.text));else if((M==null?void 0:M.type)==="tool_call"&&M.tool_call){let G=M.tool_call;g[0].content.push(Ee((o=G.index)!=null?o:0,(n=G.id)!=null?n:"",(a=(s=G.function)==null?void 0:s.name)!=null?a:"",(r=(l=G.function)==null?void 0:l.arguments)!=null?r:""));}if(g[0].content.length===0){let M=y[0],G=(M==null?void 0:M.content)||[],F=[];if(G.forEach(h=>{((h==null?void 0:h.type)==="text"||(h==null?void 0:h.type)==="output_text")&&h!=null&&h.text&&F.push(h.text);}),F.length>0)g[0].content.push(ue(F.join(`
15
15
  `)));else throw new z({info:"Invalid response from model",cause:new Error(`No text content found in response : ${JSON.stringify(e)}`)})}let I=e.usage||{};return {messages:g,usage:{promptTokens:(u=(d=I.input_tokens)!=null?d:I.prompt_tokens)!=null?u:0,completionTokens:(x=(c=I.output_tokens)!=null?c:I.completion_tokens)!=null?x:0,totalTokens:(f=I.total_tokens)!=null?f:(I.input_tokens||0)+(I.output_tokens||0)}}}getStreamChatUrl(e,o,n){return $(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getStreamChatHeaders(e,o,n){return $(this,null,function*(){return Promise.resolve(ne(k({},this.getDefaultHeaders()),{Accept:"text/event-stream"}))})}getStreamChatData(e,o,n){return $(this,null,function*(){let s=this.transformConfig(e,o,n),a=this.transformMessages(o);if(a.messages&&a.messages.length===0)throw new N({info:"Messages are required",cause:new Error("Messages are required")});let l=n?this.transformTools(n):{};return Promise.resolve(ne(k(k(k({},this.getDefaultParams()),s),l),{input:a.messages,stream:!0}))})}transformStreamChatResponseChunk(e,o){return je(this,null,function*(){var n,s,a,l,r,d,u,c,x,f;let y=o+e,g=[],I="",M=0;for(;M<y.length;){let G=y.indexOf(`
16
16
  `,M);if(G===-1){I=y.substring(M);break}else {let F=y.substring(M,G).trim();F&&g.push(F),M=G+1;}}for(let G of g){if(G==="data: [DONE]")return;if(G.startsWith("data: ")){let F=G.substring(6);try{let h=JSON.parse(F),q={partialMessages:[]},V=!1;if((h.type==="response.output_text.delta"||h.type==="output_text.delta")&&typeof h.delta=="string"&&h.delta.length>0&&(q.partialMessages.push(Y(A,h.delta)),V=!0),h.type==="response.content_part.added"&&h.part){let R=h.part;R.type==="output_text"&&typeof R.text=="string"&&R.text.length>0&&(q.partialMessages.push(Y(A,R.text)),V=!0);}if(!V&&h.delta){let R=h.delta;typeof R=="string"&&R.length>0?(q.partialMessages.push(Y(A,R)),V=!0):R&&typeof R=="object"&&R.text!==void 0&&R.text!==null?(q.partialMessages.push(Y(A,R.text)),V=!0):Array.isArray(R.content)&&R.content.forEach(O=>{var W,fe,_e,ye;if((O==null?void 0:O.type)==="output_text"&&O!=null&&O.text)q.partialMessages.push(Y(A,O.text)),V=!0;else if((O==null?void 0:O.type)==="tool_call"&&O!=null&&O.tool_call){let B=O.tool_call;q.partialMessages.push(ge(A,(W=B.index)!=null?W:0,(fe=B.id)!=null?fe:"",(_e=B.function)==null?void 0:_e.name,(ye=B.function)==null?void 0:ye.arguments)),V=!0;}});}if((h.type==="tool_call"||h.type==="tool_call.delta"||h.type==="response.tool_call.delta")&&(n=h.delta)!=null&&n.tool_call){let R=h.delta.tool_call;q.partialMessages.push(ge(A,(s=R.index)!=null?s:0,(a=R.id)!=null?a:"",(l=R.function)==null?void 0:l.name,(r=R.function)==null?void 0:r.arguments));}if(!h.delta&&(h.output||h.outputs)){let R=h.output||h.outputs;Array.isArray(R)&&R.forEach(O=>{var W,fe,_e,ye;if((O==null?void 0:O.type)==="message"&&Array.isArray(O.content))O.content.forEach(B=>{var Xt,eo,to,oo;if(((B==null?void 0:B.type)==="text"||(B==null?void 0:B.type)==="output_text")&&B!=null&&B.text)q.partialMessages.push(Y(A,B.text));else if((B==null?void 0:B.type)==="tool_call"&&B!=null&&B.tool_call){let ke=B.tool_call;q.partialMessages.push(ge(A,(Xt=ke.index)!=null?Xt:0,(eo=ke.id)!=null?eo:"",(to=ke.function)==null?void 0:to.name,(oo=ke.function)==null?void 0:oo.arguments));}});else if(((O==null?void 0:O.type)==="text"||(O==null?void 0:O.type)==="output_text")&&O!=null&&O.text)q.partialMessages.push(Y(A,O.text));else if((O==null?void 0:O.type)==="tool_call"&&O!=null&&O.tool_call){let B=O.tool_call;q.partialMessages.push(ge(A,(W=B.index)!=null?W:0,(fe=B.id)!=null?fe:"",(_e=B.function)==null?void 0:_e.name,(ye=B.function)==null?void 0:ye.arguments));}});}h.usage&&(q.usage={promptTokens:(u=(d=h.usage.input_tokens)!=null?d:h.usage.prompt_tokens)!=null?u:0,completionTokens:(x=(c=h.usage.output_tokens)!=null?c:h.usage.completion_tokens)!=null?x:0,totalTokens:(f=h.usage.total_tokens)!=null?f:(h.usage.input_tokens||0)+(h.usage.output_tokens||0)}),(q.partialMessages.length>0||q.usage)&&(yield {partialResponse:q,buffer:I});}catch(h){throw new z({info:`Malformed JSON received in stream: ${F}`,cause:h})}}}})}transformProxyStreamChatResponseChunk(e,o,n,s,a){return je(this,null,function*(){yield*nt(mn(this.transformStreamChatResponseChunk(e,o)));})}getProxyStreamChatUrl(e,o,n){return $(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getProxyCompleteChatUrl(e,o,n){return $(this,null,function*(){return Promise.resolve(this.responsesUrl)})}getProxyCompleteChatHeaders(e,o,n){return $(this,null,function*(){if(!o)return {};let s=k({},o);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(e,o,n){return $(this,null,function*(){let s=yield this.getProxyCompleteChatHeaders(e,o,n);return ne(k({},s),{Accept:"text/event-stream"})})}getModelPricing(){if(!(this.modelName in S))throw new z({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return S[this.modelName]}},vt="gpt-3.5-turbo-0125",Hi="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.",Be=_(b,X).parse({name:vt,description:Hi,maxInputTokens:4092,maxOutputTokens:4092,roles:T,modalities:Q,config:{def:p.responseFormat(4092,4).def,schema:p.responseFormat(4092,4).schema},price:S[vt]}),Ki=v,Ji=class extends P{constructor(e){super(Be,e);}},xt="gpt-3.5-turbo-1106",Vi="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.",qe=_(b,X).parse({name:xt,description:Vi,maxInputTokens:4092,maxOutputTokens:16385,roles:T,modalities:Q,config:{def:p.responseFormat(16385,4).def,schema:p.responseFormat(16385,4).schema},price:S[xt]}),Wi=v,Yi=class extends P{constructor(e){super(qe,e);}},St="gpt-3.5-turbo",Zi="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",De=_(b,X).parse({name:St,description:Zi,maxInputTokens:4092,maxOutputTokens:4092,roles:T,modalities:Q,config:{def:p.responseFormat(4092,4).def,schema:p.responseFormat(4092,4).schema},price:S[St]}),Qi=v,Xi=class extends P{constructor(e){super(De,e);}},Ot="gpt-4-0125-preview",er="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.",Gn=_(b,X).parse({name:Ot,description:er,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:Q,config:{def:p.base(4092,4).def,schema:p.base(4092,4).schema},price:S[Ot]}),tr=v,or=class extends P{constructor(e){super(Gn,e);}},Mt="gpt-4-0613",nr="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",ze=_(b,X).parse({name:Mt,description:nr,maxInputTokens:8192,maxOutputTokens:4092,roles:T,modalities:Q,config:{def:p.base(4092,4).def,schema:p.base(4092,4).schema},price:S[Mt]}),ar=v,sr=class extends P{constructor(e){super(ze,e);}},kt="gpt-4-1106-preview",ir="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.",Fe=_(b,X).parse({name:kt,description:ir,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:Q,config:{def:p.base(4092,4).def,schema:p.base(4092,4).schema},price:S[kt]}),rr=v,lr=class extends P{constructor(e){super(Fe,e);}},Ct="gpt-4.1",mr="Flagship model for complex tasks. It is well suited for problem solving across domains. Training data up to May 2024.",jn=_(b,L).parse({name:Ct,description:mr,maxInputTokens:1047576,maxOutputTokens:32768,roles:T,modalities:j,config:{def:p.responseSchema(32768,4).def,schema:p.responseSchema(32768,4).schema},price:S[Ct]}),dr=v,pr=class extends P{constructor(e){super(jn,e);}},wt="gpt-4.1-mini",cr="Provides a balance between intelligence, speed, and cost that makes it an attractive model for many use cases. Training data up to May 2024.",Ln=_(b,L).parse({name:wt,description:cr,maxInputTokens:1047576,maxOutputTokens:32768,roles:T,modalities:j,config:{def:p.responseSchema(32768,4).def,schema:p.responseSchema(32768,4).schema},price:S[wt]}),ur=v,gr=class extends P{constructor(e){super(Ln,e);}},Et="gpt-4.1-nano",hr="Fastest, most cost-effective GPT-4.1 model. Training data up to May 2024.",Nn=_(b,L).parse({name:Et,description:hr,maxInputTokens:1047576,maxOutputTokens:32768,roles:T,modalities:j,config:{def:p.responseSchema(32768,4).def,schema:p.responseSchema(32768,4).schema},price:S[Et]}),fr=v,_r=class extends P{constructor(e){super(Nn,e);}},It="gpt-5.1",yr="Flagship GPT-5.1 model for coding and agentic tasks with configurable reasoning effort. Training data up to September 2024.",An=_(b,L).parse({name:It,description:yr,maxInputTokens:4e5,maxOutputTokens:128e3,roles:T,modalities:j,config:{def:p.gpt5(128e3,4).def,schema:p.gpt5(128e3,4).schema},price:S[It]}),br=v,Tr=class extends P{constructor(e){super(An,e);}},Rt="gpt-5.2",Pr="Flagship GPT-5.2 model with enhanced reasoning controls and extended knowledge coverage. Training data up to January 2025.",Un=_(b,L).parse({name:Rt,description:Pr,maxInputTokens:4e5,maxOutputTokens:131072,roles:T,modalities:j,config:{def:p.gpt5(131072,4).def,schema:p.gpt5(131072,4).schema},price:S[Rt]}),vr=v,xr=class extends P{constructor(e){super(Un,e);}},Gt="gpt-5.2-chat-latest",Sr="Latest GPT-5.2 chat-optimized model for conversational workloads with tool/function calling support. Training data up to January 2025.",Or=j,Mr=L,$n=_(b,Mr).parse({name:Gt,description:Sr,maxInputTokens:4e5,maxOutputTokens:131072,roles:T,modalities:Or,config:{def:p.gpt5(131072,4).def,schema:p.gpt5(131072,4).schema},price:S[Gt]}),kr=v,Cr=class extends P{constructor(e){super($n,e);}},jt="gpt-5.2-pro",wr="GPT-5.2 Pro available via the OpenAI Responses API for advanced reasoning and agentic workflows. Training data up to January 2025.",Bn=_(b,L).parse({name:jt,description:wr,maxInputTokens:4e5,maxOutputTokens:131072,roles:T,modalities:j,config:{def:p.gpt5(131072,4).def,schema:p.gpt5(131072,4).schema},price:S[jt]}),Er=Rn,Ir=class extends Fi{constructor(e){super(Bn,e);}},Lt="gpt-5",Rr="Most advanced GPT-5 model for complex reasoning and problem-solving tasks. Training data up to October 2024.",qn=_(b,L).parse({name:Lt,description:Rr,maxInputTokens:4e5,maxOutputTokens:131072,roles:T,modalities:j,config:{def:p.gpt5(131072,4).def,schema:p.gpt5(131072,4).schema},price:S[Lt]}),Gr=v,jr=class extends P{constructor(e){super(qn,e);}},Nt="gpt-5-mini",Lr="Faster, more cost-effective GPT-5 model that balances intelligence and efficiency. Training data up to October 2024.",Dn=_(b,L).parse({name:Nt,description:Lr,maxInputTokens:4e5,maxOutputTokens:131072,roles:T,modalities:j,config:{def:p.gpt5(131072,4).def,schema:p.gpt5(131072,4).schema},price:S[Nt]}),Nr=v,Ar=class extends P{constructor(e){super(Dn,e);}},At="gpt-5-nano",Ur="Most cost-effective GPT-5 model optimized for speed and efficiency. Training data up to October 2024.",zn=_(b,L).parse({name:At,description:Ur,maxInputTokens:4e5,maxOutputTokens:131072,roles:T,modalities:j,config:{def:p.gpt5(131072,4).def,schema:p.gpt5(131072,4).schema},price:S[At]}),$r=v,Br=class extends P{constructor(e){super(zn,e);}},Ut="gpt-5-chat-latest",qr="Latest GPT-5 model optimized for conversational use. Does not support function calling or structured outputs. Training data up to October 2024.",Dr=[U,J],zr=zod.z.enum([U,J]),Fn=_(b,zr).parse({name:Ut,description:qr,maxInputTokens:4e5,maxOutputTokens:131072,roles:T,modalities:Dr,config:{def:p.gpt5(131072,4).def,schema:p.gpt5(131072,4).schema},price:S[Ut]}),Fr=v,Hr=class extends P{constructor(e){super(Fn,e);}},$t="gpt-4-turbo-2024-04-09",Kr="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.",He=_(b,L).parse({name:$t,description:Kr,maxInputTokens:128e3,maxOutputTokens:4096,roles:T,modalities:j,config:{def:p.responseFormat(4096,4).def,schema:p.responseFormat(4096,4).schema},price:S[$t]}),Jr=v,Vr=class extends P{constructor(e){super(He,e);}},Bt="gpt-4-turbo-preview",Wr="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",Hn=_(b,X).parse({name:Bt,description:Wr,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:Q,config:{def:p.responseFormat(4092,4).def,schema:p.responseFormat(4092,4).schema},price:S[Bt]}),Yr=v,Zr=class extends P{constructor(e){super(Hn,e);}},qt="gpt-4-turbo",Qr="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.",Kn=_(b,L).parse({name:qt,description:Qr,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:j,config:{def:p.responseFormat(4092,4).def,schema:p.responseFormat(4092,4).schema},price:S[qt]}),Xr=v,el=class extends P{constructor(e){super(Kn,e);}},Dt="gpt-4",tl="Currently points to gpt-4-0613. Training data up to Sept 2021.",Ke=_(b,X).parse({name:Dt,description:tl,maxInputTokens:8192,maxOutputTokens:4092,roles:T,modalities:Q,config:{def:p.base(4092,4).def,schema:p.base(4092,4).schema},price:S[Dt]}),ol=v,nl=class extends P{constructor(e){super(Ke,e);}},zt="gpt-4o-2024-05-13",al="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Je=_(b,L).parse({name:zt,description:al,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:j,config:{def:p.responseSchema(4092,4).def,schema:p.responseSchema(4092,4).schema},price:S[zt]}),sl=v,il=class extends P{constructor(e){super(Je,e);}},Ft="gpt-4o-2024-08-06",rl="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Ve=_(b,L).parse({name:Ft,description:rl,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:j,config:{def:p.responseSchema(4092,4).def,schema:p.responseSchema(4092,4).schema},price:S[Ft]}),ll=v,ml=class extends P{constructor(e){super(Ve,e);}},Ht="gpt-4o-mini-2024-07-18",dl="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.",We=_(b,L).parse({name:Ht,description:dl,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:j,config:{def:p.responseSchema(4092,4).def,schema:p.responseSchema(4092,4).schema},price:S[Ht]}),pl=v,cl=class extends P{constructor(e){super(We,e);}},Kt="gpt-4o-mini",ul="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.",Ye=_(b,L).parse({name:Kt,description:ul,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:j,config:{def:p.responseSchema(4092,4).def,schema:p.responseSchema(4092,4).schema},price:S[Kt]}),gl=v,hl=class extends P{constructor(e){super(Ye,e);}},Jt="gpt-4o",fl="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.",Ze=_(b,L).parse({name:Jt,description:fl,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:j,config:{def:p.responseSchema(4092,4).def,schema:p.responseSchema(4092,4).schema},price:S[Jt]}),_l=v,yl=class extends P{constructor(e){super(Ze,e);}},Vt="o1-2024-12-17",bl="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",Jn=_(b,L).parse({name:Vt,description:bl,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:j,config:{def:p.oSeries(1e5,4).def,schema:p.oSeries(1e5,4).schema},price:S[Vt]}),Tl=v,Pl=class extends P{constructor(e){super(Jn,e);}},Wt="o1",vl="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",Vn=_(b,L).parse({name:Wt,description:vl,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:j,config:{def:p.oSeries(1e5,4).def,schema:p.oSeries(1e5,4).schema},price:S[Wt]}),xl=v,Sl=class extends P{constructor(e){super(Vn,e);}},Wn="o3-2025-04-16",Ol="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",Yn=_(b,L).parse({name:Wn,description:Ol,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:j,config:{def:p.oSeries(1e5,4).def,schema:p.oSeries(1e5,4).schema}}),Ml=v,kl=class extends P{constructor(e){super(Yn,e);}},Zn="o3",Cl="A new standard for math, science, coding, and visual reasoning tasks. Training data up to Jun 2024.",Qn=_(b,L).parse({name:Zn,description:Cl,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:j,config:{def:p.oSeries(1e5,4).def,schema:p.oSeries(1e5,4).schema}}),wl=v,El=class extends P{constructor(e){super(Qn,e);}},Xn="o3-mini",Il="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.",ea=_(b,X).parse({name:Xn,description:Il,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:Q,config:{def:p.oSeries(1e5,4).def,schema:p.oSeries(1e5,4).schema}}),Rl=v,Gl=class extends P{constructor(e){super(ea,e);}},ta="o3-mini-2025-01-31",jl="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.",oa=_(b,X).parse({name:ta,description:jl,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:Q,config:{def:p.oSeries(1e5,4).def,schema:p.oSeries(1e5,4).schema}}),Ll=v,Nl=class extends P{constructor(e){super(oa,e);}},na="o4-mini-2025-04-16",Al="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",aa=_(b,L).parse({name:na,description:Al,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:j,config:{def:p.oSeries(1e5,4).def,schema:p.oSeries(1e5,4).schema}}),Ul=v,$l=class extends P{constructor(e){super(aa,e);}},sa="o4-mini",Bl="Optimized for fast, effective reasoning with exceptionally efficient performance in coding and visual tasks. Training data up to Jun 2024.",ia=_(b,L).parse({name:sa,description:Bl,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:j,config:{def:p.oSeries(1e5,4).def,schema:p.oSeries(1e5,4).schema}}),ql=v,Dl=class extends P{constructor(e){super(ia,e);}},xe=[se,ce],Se=zod.z.enum([se,ce]),zl=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()})}),Fl=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)),Hl=zod.z.object({model:zod.z.string().min(1).optional(),input:Fl,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()}),Qe=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),Oe=class{constructor(e,o){this.version="v1";let n=Qe.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=re(n.baseUrl||$e.baseUrl),this.getEmbeddingsUrl=re(n.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let o=r=>{let d=/(\d+)(h|m|s|ms)/g,u={h:36e5,m:6e4,s:1e3,ms:1},c,x=0;for(;(c=d.exec(r))!==null;){let f=parseInt(c[1]),y=c[2];x+=f*u[y];}return x},n=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(n=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(n,s);return {shouldRetry:a,delayMs:l}}getTokenCount(e){return e.requests.reduce((o,n)=>o+n.length,0)}transformModelRequest(e){let o=Hl.safeParse(e);if(!o.success)throw new Pe({info:"Invalid model request",cause:o.error});let n=o.data,s=n.model,a={encodingFormat:n.encoding_format,dimensions:n.dimensions},l=we().parse(Pt(a)),r,d;return typeof n.input=="string"?d=se:typeof n.input[0]=="string"?d=se:d=ce,d===se?typeof n.input=="string"?r={modality:d,requests:[n.input]}:r={modality:d,requests:n.input}:typeof n.input[0]=="number"?r={modality:d,requests:[n.input]}:r={modality:d,requests:n.input},{modelName:s,config:l,embeddingRequests:r}}transformConfig(e,o){let n=this.modelSchema.config.schema.safeParse(e);if(!n.success)throw new K({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:n.error});let s=n.data;return Object.keys(s).forEach(a=>{if(!this.modelSchema.config.def[a])throw new K({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${a}',
17
17
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((a,l)=>{let r=this.modelSchema.config.def[l].param,d=s[l];return a[r]=d,a},{})}transformEmbeddingRequests(e){let o=Mo().safeParse(e);if(!o.success)throw new Ko({info:"Invalid embedding requests",cause:o.error});return {input:o.data.requests}}getGetEmbeddingsUrl(e,o){return $(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return $(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return $(this,null,function*(){return new Promise(n=>{n(k(k(k({},this.getDefaultParams()),this.transformConfig(e,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o,n=zl.safeParse(e);if(n.success){let s=n.data;o=typeof s.data[0].embedding=="string"?ut:ct;let a=s.data.map(l=>typeof l.embedding=="string"?{index:l.index,embedding:l.embedding}:{index:l.index,embedding:l.embedding});return {encodingFormat:o,embeddings:a,usage:{totalTokens:s.usage.total_tokens}}}throw new z({info:"Invalid response from model",cause:n.error})}},ra="text-embedding-ada-002",Kl="Most capable 2nd generation embedding model, replacing 16 first generation models",Xe=he(Se).parse({name:ra,description:Kl,modalities:xe,maxInputTokens:8192,maxOutputTokens:1536,config:{def:ae.base().def,schema:ae.base().schema}}),Jl=Qe,Vl=class extends Oe{constructor(e){super(Xe,e);}},la="text-embedding-3-small",Wl="Increased performance over 2nd generation ada embedding model",et=he(Se).parse({name:la,description:Wl,modalities:xe,maxInputTokens:8192,maxOutputTokens:1536,config:{def:ae.dimensions(1536).def,schema:ae.dimensions(1536).schema}}),Yl=Qe,Zl=class extends Oe{constructor(e){super(et,e);}},ma="text-embedding-3-large",Ql="Most capable embedding model for both english and non-english tasks",tt=he(Se).parse({name:ma,description:Ql,modalities:xe,maxInputTokens:8192,maxOutputTokens:3072,config:{def:ae.dimensions(3072).def,schema:ae.dimensions(3072).schema}}),Xl=Qe,em=class extends Oe{constructor(e){super(tt,e);}};var Zt=_(b,L).parse({name:"__base__",description:"Base chat model for Azure OpenAI",maxInputTokens:128e3,maxOutputTokens:128e3,roles:T,modalities:j,config:{def:p.base(128e3,4).def,schema:p.base(128e3,4).schema}});var w=class extends P{constructor(n,s){let a=C.parse(s),l;if(a.baseUrl)l=a.baseUrl;else if(a.resourceName)l=le.azureUrl(a.resourceName,"openai");else throw new Ie({info:"Either 'baseUrl' or 'resourceName' must be provided",cause:new Error("Either 'baseUrl' or 'resourceName' must be provided")});let r="2024-06-01",d=`${l}/openai/deployments/${a.deploymentId}`;super(n,{modelName:a.deploymentId,apiKey:a.apiKey,baseUrl:d,completeChatUrl:`${d}/chat/completions?api-version=${r}`,streamChatUrl:`${d}/chat/completions?api-version=${r}`});this.version="v1";this.modelSchema=n,this.deploymentId=a.deploymentId,this.azureApiKey=a.apiKey,this.azureApiVersion=r;}getDefaultHeaders(){return {"Content-Type":"application/json","api-key":this.azureApiKey,source:"adaline"}}getModelPricing(){throw new z({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error("Pricing configuration not supported azure provider.")})}};var Fd="gpt-4o",tm=Ze,Hd=C,da=class extends w{constructor(o){super(tm,o);}};var Yd="gpt-4o-mini",om=Ye,Zd=C,pa=class extends w{constructor(o){super(om,o);}};var op="gpt-4o-mini-2024-07-18",nm=We,np=C,ca=class extends w{constructor(o){super(nm,o);}};var lp="gpt-4o-2024-08-06",am=Ve,mp=C,ua=class extends w{constructor(o){super(am,o);}};var gp="gpt-4o-2024-05-13",sm=Je,hp=C,ga=class extends w{constructor(o){super(sm,o);}};var Tp="gpt-4",im=Ke,Pp=C,ha=class extends w{constructor(o){super(im,o);}};var Mp="gpt-4-turbo-2024-04-09",rm=He,kp=C,fa=class extends w{constructor(o){super(rm,o);}};var Rp="gpt-4-1106-preview",lm=Fe,Gp=C,_a=class extends w{constructor(o){super(lm,o);}};var Up="gpt-4-0613",mm=ze,$p=C,ya=class extends w{constructor(o){super(mm,o);}};var Fp="gpt-3-5-turbo",dm=De,Hp=C,ba=class extends w{constructor(o){super(dm,o);}};var Yp="gpt-3-5-turbo-1106",pm=qe,Zp=C,Ta=class extends w{constructor(o){super(pm,o);}};var oc="gpt-3-5-turbo-0125",cm=Be,nc=C,Pa=class extends w{constructor(o){super(cm,o);}};var ee=zod.z.object({apiKey:zod.z.string().min(1),deploymentId:zod.z.string().min(1),resourceName:zod.z.string().min(1).optional(),baseUrl:zod.z.string().optional()});var Qt=he(Se).parse({name:"__base__",description:"Base embedding model for Azure OpenAI",maxInputTokens:8192,maxOutputTokens:3072,modalities:xe,config:{def:ae.dimensions(3072).def,schema:ae.dimensions(3072).schema}});var te=class extends Oe{constructor(n,s){let a=ee.parse(s),l;if(a.baseUrl)l=a.baseUrl;else if(a.resourceName)l=le.azureUrl(a.resourceName,"openai");else throw new Ie({info:"Either 'baseUrl' or 'resourceName' must be provided",cause:new Error("Either 'baseUrl' or 'resourceName' must be provided")});let r="2024-06-01",d=`${l}/openai/deployments/${a.deploymentId}`;super(n,{modelName:a.deploymentId,apiKey:a.apiKey,baseUrl:d,getEmbeddingsUrl:`${d}/embeddings?api-version=${r}`});this.version="v1";this.modelSchema=n,this.deploymentId=a.deploymentId,this.azureApiKey=a.apiKey,this.azureApiVersion=r;}getDefaultHeaders(){return {"Content-Type":"application/json","api-key":this.azureApiKey,source:"adaline"}}};var Pc="text-embedding-3-large",um=tt,vc=ee,va=class extends te{constructor(o){super(um,o);}};var kc="text-embedding-ada-002",gm=Xe,Cc=ee,xa=class extends te{constructor(o){super(gm,o);}};var Gc="text-embedding-3-small",hm=et,jc=ee,Sa=class extends te{constructor(o){super(hm,o);}};var fm="azure",le=class{constructor(){this.version="v1";this.name=fm;}chatModelLiterals(){return ["__base__"]}chatModelSchemas(){return {__base__:Zt}}chatModel(o){let n=w,s=C.parse(o);return new n(Zt,s)}embeddingModelLiterals(){return ["__base__"]}embeddingModelSchemas(){return {__base__:Qt}}embeddingModel(o){let n=te,s=ee.parse(o);return new n(Qt,s)}};le.azureUrl=(o,n)=>`https://${o}.${n}.azure.com`;