@adaline/bedrock 2.4.1 → 2.4.2

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
@@ -11,7 +11,7 @@ Message: ${Qi(a)}`),this.name=Ye,this.info=n,this.cause=a,this.name=i!=null?i:Ye
11
11
  ${this.chatModelLiterals().join(", ")}`)});let a=this.chatModelFactories[n].model,i=this.chatModelFactories[n].modelOptions.parse(t);return new a(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,n)=>(t[n]=this.embeddingModelFactories[n].modelSchema,t),{})}embeddingModel(t){let n=t.modelName;if(!(n in this.embeddingModelFactories))throw new rn({info:`Anthropic embedding model: ${n} not found`,cause:new Error(`Anthropic embedding model: ${n} not found, available embedding models:
12
12
  ${this.embeddingModelLiterals().join(", ")}`)});let a=this.embeddingModelFactories[n].model,i=this.embeddingModelFactories[n].modelOptions.parse(t);return new a(i)}};Te.chatBaseUrl="https://api.anthropic.com/v1",Te.embeddingBaseUrl="https://api.voyageai.com/v1";var G={"claude-3-opus-20240229":{modelName:"claude-3-opus-20240229",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]},"claude-3-sonnet-20240229":{modelName:"claude-3-sonnet-20240229",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-5-sonnet-20240620":{modelName:"claude-3-5-sonnet-20240620",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-5-sonnet-20241022":{modelName:"claude-3-5-sonnet-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-7-sonnet-20250219":{modelName:"claude-3-7-sonnet-20250219",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-haiku-20240307":{modelName:"claude-3-haiku-20240307",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:1.25}}}]},"claude-3-haiku-20241022":{modelName:"claude-3-haiku-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:1.25}}}]},"claude-3-5-haiku-20241022":{modelName:"claude-3-5-haiku-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.8,outputPricePerMillion:4}}}]},"claude-4-sonnet-20250514":{modelName:"claude-4-sonnet-20250514",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-4-opus-20250514":{modelName:"claude-4-opus-20250514",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]},"claude-sonnet-4-5-20250929":{modelName:"claude-sonnet-4-5-20250929",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-opus-4-5-20251101":{modelName:"claude-opus-4-5-20251101",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:5,outputPricePerMillion:25}}}]}},f=zod.z.enum([fe,se,_,mt]),y={system:fe,user:se,assistant:_,tool:se},k=[E,Y,K,J],C=zod.z.enum([E,Y,K,J]),ne=[E,Y,K,J,Q],oe=zod.z.enum([E,Y,K,J,Q]),or=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ar=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),ir=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string(),signature:zod.z.string()}),sr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),rr=zod.z.object({type:zod.z.literal("mcp_tool_use"),id:zod.z.string(),name:zod.z.string(),server_name:zod.z.string(),input:zod.z.record(zod.z.any())}),lr=zod.z.object({type:zod.z.literal("mcp_tool_result"),tool_use_id:zod.z.string(),is_error:zod.z.boolean(),content:zod.z.array(zod.z.any())}),dr=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[or,ar,ir,sr,rr,lr])),id:zod.z.string(),model:zod.z.string(),role:zod.z.string(),stop_reason:zod.z.string(),stop_sequence:zod.z.null(),type:zod.z.literal("message"),usage:zod.z.object({input_tokens:zod.z.number(),output_tokens:zod.z.number(),cache_creation_input_tokens:zod.z.number().nullish(),cache_read_input_tokens:zod.z.number().nullish()})}),cr=zod.z.object({type:zod.z.literal("message_start"),message:zod.z.object({id:zod.z.string(),type:zod.z.literal("message"),role:zod.z.string(),model:zod.z.string(),stop_reason:zod.z.string().nullable(),stop_sequence:zod.z.string().nullable(),content:zod.z.array(zod.z.any()),usage:zod.z.object({input_tokens:zod.z.number(),output_tokens:zod.z.number()})})}),mr=zod.z.object({type:zod.z.literal("message_delta"),delta:zod.z.object({stop_reason:zod.z.string().nullable(),stop_sequence:zod.z.string().nullable()}),usage:zod.z.object({output_tokens:zod.z.number()})}),pr=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ur=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),hr=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string()}),gr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),fr=zod.z.object({type:zod.z.literal("mcp_tool_use"),id:zod.z.string(),name:zod.z.string(),server_name:zod.z.string(),input:zod.z.record(zod.z.any())}),yr=zod.z.object({type:zod.z.literal("mcp_tool_result"),tool_use_id:zod.z.string(),is_error:zod.z.boolean(),content:zod.z.array(zod.z.any())}),br=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[pr,ur,hr,gr,fr,yr])}),kr=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),Cr=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),vr=zod.z.object({type:zod.z.literal("thinking_delta"),thinking:zod.z.string()}),Tr=zod.z.object({type:zod.z.literal("signature_delta"),signature:zod.z.string()}),Mr=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[kr,Cr,vr,Tr])}),xr=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string().optional(),signature:zod.z.string().optional()}),Sr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),Or=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),wr=zod.z.object({type:zod.z.enum(["auto","any"])}),Pr=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),xt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),yo=zod.z.object({type:zod.z.literal("image"),source:zod.z.object({type:zod.z.literal("base64"),media_type:zod.z.enum(["image/jpeg","image/png","image/gif","image/webp"]),data:zod.z.string().base64()})});zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("tool_use"),name:zod.z.string().min(1),input:zod.z.record(zod.z.any())});var bo=zod.z.object({type:zod.z.literal("tool_result"),tool_use_id:zod.z.string().min(1),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xt,yo])).min(1))});zod.z.object({type:zod.z.literal("mcp_tool_use"),id:zod.z.string().min(1),name:zod.z.string().min(1),server_name:zod.z.string().min(1),input:zod.z.record(zod.z.any())});zod.z.object({type:zod.z.literal("mcp_tool_result"),tool_use_id:zod.z.string().min(1),is_error:zod.z.boolean().default(!1),content:zod.z.array(zod.z.any())});var Rr=zod.z.object({enabled:zod.z.boolean().default(!0),allowed_tools:zod.z.array(zod.z.string().min(1)).optional()}),jr=zod.z.object({type:zod.z.literal("url"),url:zod.z.string().url().refine(t=>t.startsWith("https://"),{message:"MCP server URL must start with https://"}),name:zod.z.string().min(1),tool_configuration:Rr.optional(),authorization_token:zod.z.string().min(1).optional()}),_r=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xt,yo,bo])).min(1))}),Er=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xt,bo,xr,Sr])).min(1))}),Ir=zod.z.union([_r,Er]),Br=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Ir).min(1),system:zod.z.string().min(1).optional(),max_tokens:zod.z.number().min(0).optional(),stop_sequences:zod.z.array(zod.z.string().min(1)).optional(),temperature:zod.z.number().min(0).max(1).optional(),tool_choice:zod.z.union([wr,Pr]).optional(),tools:zod.z.array(Or).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional(),mcp_servers:zod.z.array(jr).min(1).optional()}),D=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),A=class{constructor(t,n){this.version="v1";let a=D.parse(n);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=ge(Te.chatBaseUrl),this.completeChatUrl=ge(a.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=ge(a.streamChatUrl||`${this.baseUrl}/messages`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"x-api-key":`${this.apiKey}`,"anthropic-version":"2023-06-01","content-type":"application/json","anthropic-dangerous-direct-browser-access":"true"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){let n=0,a=!0;return t["x-should-retry"]&&(a=t["x-should-retry"].toLowerCase()!=="false"),t["retry-after"]&&(n=parseInt(t["retry-after"])*1e3),{shouldRetry:a,delayMs:n}}getTokenCount(t){return t.reduce((n,a)=>n+a.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformModelRequest(t){let n=Br.safeParse(t);if(!n.success)throw new nt({info:"Invalid model request",cause:n.error});let a=n.data,i=a.model;if(a.tool_choice&&(!a.tools||a.tools.length===0))throw new nt({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let s={};a.tool_choice&&(a.tool_choice.type==="tool"?s.toolChoice=a.tool_choice.name:s.toolChoice=a.tool_choice.type),s.maxTokens=a.max_tokens,s.temperature=a.temperature,s.topP=a.top_p,s.topK=a.top_k,s.stop=a.stop_sequences;let r=Un().parse(no(s)),l=[],d={};a.system&&l.push({role:fe,content:[{modality:E,value:a.system}]}),a.messages.forEach(p=>{let h=p.role;switch(h){case"user":{let g=p.content;if(typeof g=="string")l.push({role:h,content:[{modality:E,value:g}]});else {let P=g.map(u=>{if(u.type==="text")return {modality:E,value:u.text};if(u.type==="image"){let v="auto",R=u.source.media_type.split("/")[1];return {modality:Y,detail:v,value:{type:Tn,mediaType:R,base64:u.source.data}}}else return {modality:J,id:u.tool_use_id,index:d[u.tool_use_id].index,name:d[u.tool_use_id].name,data:typeof u.content=="string"?u.content:JSON.stringify(u.content)}});l.push({role:h,content:P});}}break;case"assistant":{let g=p.content;if(typeof g=="string")l.push({role:h,content:[{modality:E,value:g}]});else {let P=g.map((u,v)=>{if(u.type==="text")return {modality:E,value:u.text};{let R={modality:K,id:u.id,index:v,name:u.name,arguments:JSON.stringify(u.input)};return d[u.id]=R,R}});l.push({role:h,content:P});}}break}});let m=[];return a.tools&&a.tools.forEach(p=>{m.push({type:"function",definition:{schema:{name:p.name,description:p.description||"",parameters:p.input_schema}}});}),{modelName:i,config:r,messages:l,tools:m.length>0?m:void 0}}transformConfig(t,n,a){let i=t.toolChoice,s=t.reasoningEnabled,r=t.maxReasoningTokens,l=t.mcp,d=t.mcpServers,m=w({},t);delete m.toolChoice,delete m.reasoningEnabled,delete m.maxReasoningTokens,delete m.mcp,delete m.mcpServers;let p=this.modelSchema.config.schema.safeParse(m);if(!p.success)throw new X({info:`Invalid config for model : '${this.modelName}'`,cause:p.error});let h=p.data;i!==void 0&&(h.toolChoice=i),Object.keys(h).forEach(v=>{if(!(v in this.modelSchema.config.def))throw new X({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${v}',
13
13
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let g=Object.keys(h).reduce((v,R)=>{let U=this.modelSchema.config.def[R],H=U.param,Z=h[R];return H==="max_tokens"&&U.type==="range"&&Z===0?v[H]=U.max:v[H]=Z,v},{});if(!g.max_tokens){let v=this.modelSchema.config.def.maxTokens;g.max_tokens=v.max;}if("tool_choice"in g&&g.tool_choice!==void 0){let v=g.tool_choice;if(!a||a&&a.length===0)throw new X({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(a&&a.length>0){let R=this.modelSchema.config.def.toolChoice;if(R.choices.includes(v))g.tool_choice={type:v};else if(a.map(U=>U.definition.schema.name).includes(v))g.tool_choice={type:"tool",name:v};else throw new X({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${v}' is not part of provided 'tools' names or
14
- one of [${R.choices.join(", ")}]`)})}}let P=s!==void 0,u=r!==void 0;if(P!==u)throw new X({info:`Invalid extended thinking config for model: '${this.modelName}'`,cause:new Error("Both 'reasoningEnabled' and 'maxReasoningTokens' must be defined together.")});if(P&&u){let v=g.max_tokens;if(s)if(r<v)g.thinking={type:"enabled",budget_tokens:r};else throw new X({info:`Invalid extended thinking token budget for model: '${this.modelName}'`,cause:new Error(`maxReasoningTokens (${r}) must be less than max_tokens (${v})`)})}return l&&d&&(g.mcp_servers=d),g}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let n=r=>{let l=r.match(/^data:image\/[a-zA-Z]+;base64,/);return l?r.substring(l[0].length):r},a=t.map(r=>{let l=An().safeParse(r);if(!l.success)throw new q({info:"Invalid messages",cause:l.error});return l.data});a.forEach(r=>{r.content.forEach(l=>{if(!this.modelSchema.modalities.includes(l.modality))throw new q({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${l.modality}', available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),a.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new q({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}', available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let i="",s=[];if(a.forEach(r=>{switch(r.role){case fe:{r.content.forEach(l=>{if(l.modality===E)i+=l.value;else throw new q({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})});break}case _:{let l=[];r.content.forEach(d=>{if(d.modality===E)l.push({type:"text",text:d.value});else if(d.modality===K)d.serverName?l.push({type:"mcp_tool_use",id:d.id,name:d.name,server_name:d.serverName,input:JSON.parse(d.arguments)}):l.push({type:"tool_use",id:d.id,name:d.name,input:JSON.parse(d.arguments)});else if(d.modality===Q&&d.value.type==="thinking")l.push({type:"thinking",thinking:d.value.thinking,signature:d.value.signature});else if(d.modality===Q&&d.value.type==="redacted")l.push({type:"redacted_thinking",data:d.value.data});else if(d.modality===J)l.push({type:"mcp_tool_result",tool_use_id:d.id,content:JSON.parse(d.data),is_error:d.apiResponse&&d.apiResponse.statusCode!==200||!1});else throw new q({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],content:l});break}case se:{let l=[];r.content.forEach(d=>{if(d.modality===E)l.push({type:"text",text:d.value});else if(d.modality===Y){if(d.value.type==="base64"){let m=d.value.base64;m=n(m),l.push({type:"image",source:{type:"base64",media_type:`image/${d.value.mediaType}`,data:m}});}else if(d.value.type==="url")throw new q({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${d.value.type}'`)})}else throw new q({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],content:l});break}case mt:{let l=[];r.content.forEach(d=>{if(d.modality===J)l.push({type:"tool_result",tool_use_id:d.id,content:d.data});else throw new q({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],content:l});break}default:throw new q({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
14
+ one of [${R.choices.join(", ")}]`)})}}let P=s!==void 0,u=r!==void 0;if(P!==u)throw new X({info:`Invalid extended thinking config for model: '${this.modelName}'`,cause:new Error("Both 'reasoningEnabled' and 'maxReasoningTokens' must be defined together.")});if(P&&u){let v=g.max_tokens;if(s)if(r<v)g.thinking={type:"enabled",budget_tokens:r};else throw new X({info:`Invalid extended thinking token budget for model: '${this.modelName}'`,cause:new Error(`maxReasoningTokens (${r}) must be less than max_tokens (${v})`)})}return l&&d&&(g.mcp_servers=d),g}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let n=r=>{let l=r.match(/^data:image\/[a-zA-Z]+;base64,/);return l?r.substring(l[0].length):r},a=t.map(r=>{let l=An().safeParse(r);if(!l.success)throw new q({info:"Invalid messages",cause:l.error});return l.data});a.forEach(r=>{r.content.forEach(l=>{if(!this.modelSchema.modalities.includes(l.modality))throw new q({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${l.modality}', available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),a.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new q({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}', available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),a.forEach(r=>{r.content=r.content.filter(l=>l.modality!=="error"&&l.modality!=="search-result");});let i="",s=[];if(a.forEach(r=>{switch(r.role){case fe:{r.content.forEach(l=>{if(l.modality===E)i+=l.value;else throw new q({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})});break}case _:{let l=[];r.content.forEach(d=>{if(d.modality===E)l.push({type:"text",text:d.value});else if(d.modality===K)d.serverName?l.push({type:"mcp_tool_use",id:d.id,name:d.name,server_name:d.serverName,input:JSON.parse(d.arguments)}):l.push({type:"tool_use",id:d.id,name:d.name,input:JSON.parse(d.arguments)});else if(d.modality===Q&&d.value.type==="thinking")l.push({type:"thinking",thinking:d.value.thinking,signature:d.value.signature});else if(d.modality===Q&&d.value.type==="redacted")l.push({type:"redacted_thinking",data:d.value.data});else if(d.modality===J)l.push({type:"mcp_tool_result",tool_use_id:d.id,content:JSON.parse(d.data),is_error:d.apiResponse&&d.apiResponse.statusCode!==200||!1});else throw new q({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],content:l});break}case se:{let l=[];r.content.forEach(d=>{if(d.modality===E)l.push({type:"text",text:d.value});else if(d.modality===Y){if(d.value.type==="base64"){let m=d.value.base64;m=n(m),l.push({type:"image",source:{type:"base64",media_type:`image/${d.value.mediaType}`,data:m}});}else if(d.value.type==="url")throw new q({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${d.value.type}'`)})}else throw new q({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],content:l});break}case mt:{let l=[];r.content.forEach(d=>{if(d.modality===J)l.push({type:"tool_result",tool_use_id:d.id,content:d.data});else throw new q({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],content:l});break}default:throw new q({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
15
15
  available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),s[0].role!==this.modelSchema.roles[se])throw new q({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});return {system:i,messages:s}}transformTools(t){if(!this.modelSchema.modalities.includes(K))throw new un({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${K}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(n=>{let a=us().safeParse(n);if(!a.success)throw new un({info:"Invalid tools",cause:a.error});return a.data}).map(n=>({name:n.definition.schema.name,description:n.definition.schema.description,input_schema:n.definition.schema.parameters}))}}getCompleteChatUrl(t,n,a){return B(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(t,n,a){return B(this,null,function*(){let i=this.getDefaultHeaders();if(t&&t.mcp&&t.mcpServers){let s=i["anthropic-beta"],r="mcp-client-2025-04-04";s?i=ee(w({},i),{"anthropic-beta":`${s},${r}`}):i=ee(w({},i),{"anthropic-beta":r});}return new Promise(s=>{s(i);})})}getCompleteChatData(t,n,a){return B(this,null,function*(){let i=this.transformConfig(t,n,a),s=this.transformMessages(n);if(s.messages&&s.messages.length===0)throw new q({info:"Messages are required",cause:new Error("Messages are required")});let r=a?this.transformTools(a):{};return new Promise(l=>{l(w(w(w(w({},this.getDefaultParams()),i),s),r));})})}transformCompleteChatResponse(t){let n=dr.safeParse(t);if(n.success){let a=n.data,i=a.content.map((l,d)=>{if(l.type==="text")return hs(l.text);if(l.type==="tool_use")return tn(d,l.id,l.name,JSON.stringify(l.input));if(l.type==="thinking")return ys(l.thinking,l.signature);if(l.type==="redacted_thinking")return bs(l.data);if(l.type==="mcp_tool_use")return tn(d,l.id,l.name,JSON.stringify(l.input),l.server_name);if(l.type==="mcp_tool_result")return gs(d,l.tool_use_id,"mcp_tool_result",JSON.stringify(l.content),{statusCode:l.is_error?500:200})}),s=[{role:_,content:i}],r={promptTokens:a.usage.input_tokens,completionTokens:a.usage.output_tokens,totalTokens:a.usage.input_tokens+a.usage.output_tokens};return {messages:s,usage:r,logProbs:[]}}throw new W({info:"Invalid response from model",cause:n.error})}getStreamChatUrl(t,n,a){return B(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(t,n,a){return B(this,null,function*(){let i=this.getDefaultHeaders();if(t&&t.mcp&&t.mcpServers){let s=i["anthropic-beta"],r="mcp-client-2025-04-04";s?i=ee(w({},i),{"anthropic-beta":`${s},${r}`}):i=ee(w({},i),{"anthropic-beta":r});}return new Promise(s=>{s(i);})})}getStreamChatData(t,n,a){return B(this,null,function*(){let i=this.transformConfig(t,n,a),s=this.transformMessages(n);if(s.messages&&s.messages.length===0)throw new q({info:"Messages are required",cause:new Error("Messages are required")});let r=a?this.transformTools(a):{};return new Promise(l=>{l(w(w(w(w({stream:!0},this.getDefaultParams()),i),s),r));})})}transformStreamChatResponseChunk(t,n){return Xt(this,null,function*(){let a=n+t,i=[],s="",r=0;for(;r<a.length;){let l=a.indexOf(`
16
16
  `,r);if(l===-1){s=a.substring(r);break}else {let d=a.substring(r,l).trim();d&&i.push(d),r=l+1;}}for(let l of i)if(l.startsWith("data: {")&&l.endsWith("}")){let d;try{d=JSON.parse(l.substring(6));}catch(m){throw new W({info:`Malformed JSON received in stream : ${d}`,cause:m})}if("type"in d){if(d.type==="message_stop")return;if(d.type==="message_start"){let m=cr.safeParse(d);if(m.success){let p=m.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:p.message.usage.input_tokens,completionTokens:p.message.usage.output_tokens,totalTokens:p.message.usage.input_tokens+p.message.usage.output_tokens}},buffer:n};}else throw new W({info:"Invalid response from model",cause:m.error})}else if(d.type==="message_delta"){let m=mr.safeParse(d);if(m.success){let p=m.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:void 0,completionTokens:p.usage.output_tokens,totalTokens:p.usage.output_tokens}},buffer:n};}else throw new W({info:"Invalid response from model",cause:m.error})}else if(d.type==="content_block_start"){let m=br.safeParse(d);if(m.success){let p=m.data,h=[];p.content_block.type==="text"?h.push(nn(_,p.content_block.text)):p.content_block.type==="tool_use"?h.push(Qe(_,p.index,p.content_block.id,p.content_block.name,"")):p.content_block.type==="thinking"?h.push(et(_,p.content_block.thinking)):p.content_block.type==="redacted_thinking"?h.push(ks(_,p.content_block.data)):p.content_block.type==="mcp_tool_use"?h.push(Qe(_,p.index,p.content_block.id,p.content_block.name,JSON.stringify(p.content_block.input),p.content_block.server_name)):p.content_block.type==="mcp_tool_result"&&h.push(fs(_,p.index,p.content_block.tool_use_id,"mcp_tool_result",JSON.stringify(p.content_block.content))),yield {partialResponse:{partialMessages:h},buffer:n};}else throw new W({info:"Invalid response from model",cause:m.error})}else if(d.type==="content_block_delta"){let m=Mr.safeParse(d);if(m.success){let p=m.data,h=[];p.delta.type==="text_delta"?h.push(nn(_,p.delta.text)):p.delta.type==="input_json_delta"?h.push(Qe(_,p.index,"","",p.delta.partial_json)):p.delta.type==="thinking_delta"?h.push(et(_,p.delta.thinking)):p.delta.type==="signature_delta"&&h.push(et(_,void 0,p.delta.signature)),yield {partialResponse:{partialMessages:h},buffer:n};}else throw new W({info:"Invalid response from model",cause:m.error})}}else throw new W({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property, received: ${JSON.stringify(d)}`)})}yield {partialResponse:{partialMessages:[]},buffer:s};})}transformProxyStreamChatResponseChunk(t,n,a,i,s){return Xt(this,null,function*(){yield*Ce(oi(this.transformStreamChatResponseChunk(t,n)));})}getProxyStreamChatUrl(t,n,a){return B(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getProxyCompleteChatUrl(t,n,a){return B(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyCompleteChatHeaders(t,n,a){return B(this,null,function*(){if(!n)return {};let i=w({},n);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(t,n,a){return B(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,n,a)})}getModelPricing(){if(!(this.modelName in G))throw new W({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return G[this.modelName]}},ot="claude-4-opus-20250514",Ar="Our high-performance model with exceptional reasoning and efficiency. Training cutoff: March 2025.",ko=V(f,oe).parse({name:ot,description:Ar,maxInputTokens:2e5,maxOutputTokens:32e3,maxReasoningTokens:32e3,roles:y,modalities:ne,config:{def:S.extendedThinking(32e3,4,1024,32e3).def,schema:S.extendedThinking(32e3,4,1024,32e3).schema},price:G[ot]}),Nr=D,Ur=class extends A{constructor(t){super(ko,t);}},at="claude-4-sonnet-20250514",Lr="Our most capable and intelligent model yet. Training cutoff: March 2025.",Co=V(f,oe).parse({name:at,description:Lr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:y,modalities:ne,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:G[at]}),qr=D,$r=class extends A{constructor(t){super(Co,t);}},it="claude-opus-4-5-20251101",Dr="Premium model combining maximum intelligence with practical performance. Ideal for complex specialized tasks, professional software engineering, and advanced agents. Training cutoff: August 2025.",vo=V(f,oe).parse({name:it,description:Dr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:y,modalities:ne,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:G[it]}),Hr=D,Fr=class extends A{constructor(t){super(vo,t);}},st="claude-sonnet-4-5-20250929",zr="Our best model for complex agents and coding, with the highest intelligence across most tasks. Training cutoff: July 2025.",To=V(f,oe).parse({name:st,description:zr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:y,modalities:ne,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:G[st]}),Kr=D,Vr=class extends A{constructor(t){super(To,t);}},rt="claude-3-5-sonnet-20240620",Jr="Most intelligent model. Highest level of intelligence and capability.",Mo=V(f,C).parse({name:rt,description:Jr,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:k,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:G[rt]}),Gr=D,Wr=class extends A{constructor(t){super(Mo,t);}},lt="claude-3-5-sonnet-20241022",Zr="Most intelligent model. Highest level of intelligence and capability.",xo=V(f,C).parse({name:lt,description:Zr,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:k,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:G[lt]}),Xr=D,Yr=class extends A{constructor(t){super(xo,t);}},dt="claude-3-7-sonnet-20250219",Qr="Most intelligent model. Highest level of intelligence and capability.",So=V(f,oe).parse({name:dt,description:Qr,maxInputTokens:2e5,maxOutputTokens:128e3,maxReasoningTokens:64e3,roles:y,modalities:ne,config:{def:S.extendedThinking(128e3,4,1024,64e3).def,schema:S.extendedThinking(128e3,4,1024,64e3).schema},price:G[dt]}),el=D,tl=class extends A{constructor(t){super(So,t);}getDefaultHeaders(){let t=super.getDefaultHeaders(),n=t["anthropic-beta"],a="output-128k-2025-02-19";return n?t=ee(w({},t),{"anthropic-beta":`${n},${a}`}):t=ee(w({},t),{"anthropic-beta":a}),t}},Oo="claude-3-haiku-20240307",nl="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",wo=V(f,C).parse({name:Oo,description:nl,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:k,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),ol=D,al=class extends A{constructor(t){super(wo,t);}},ct="claude-3-5-haiku-20241022",il="Our fastest model with intelligence at blazing speeds.",Po=V(f,C).parse({name:ct,description:il,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:k,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:G[ct]}),sl=D,rl=class extends A{constructor(t){super(Po,t);}},Ro="claude-3-opus-20240229",ll="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",jo=V(f,C).parse({name:Ro,description:ll,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:k,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),dl=D,cl=class extends A{constructor(t){super(jo,t);}},_o="claude-3-sonnet-20240229",ml="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Eo=V(f,C).parse({name:_o,description:ml,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:k,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),pl=D,ul=class extends A{constructor(t){super(Eo,t);}},ce=[re],me=zod.z.enum([re]),hl=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({total_tokens:zod.z.number()})}),gl=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),fl=zod.z.object({model:zod.z.string().min(1).optional(),input:gl,encoding_format:zod.z.enum(["base64"]).nullable().optional(),input_type:zod.z.enum(["query","document"]).nullable().optional(),truncation:zod.z.boolean().optional()}),ae=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),pe=class{constructor(t,n){this.version="v1";let a=ae.parse(n);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=ge(Te.embeddingBaseUrl),this.getEmbeddingsUrl=ge(a.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getTokenCount(t){return t.requests.reduce((n,a)=>n+a.length,0)}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}transformModelRequest(t){let n=fl.safeParse(t);if(!n.success)throw new nt({info:"Invalid model request",cause:n.error});let a=n.data,i=a.model,s={encodingFormat:a.encoding_format,inputType:a.input_type,truncation:a.truncation},r=Un().parse(no(s)),l;return typeof a.input=="string"?l={modality:re,requests:[a.input]}:l={modality:re,requests:a.input},{modelName:i,config:r,embeddingRequests:l}}transformConfig(t,n){"inputType"in t&&t.inputType===""&&delete t.inputType,"encodingFormat"in t&&t.encodingFormat===""&&delete t.encodingFormat;let a=this.modelSchema.config.schema.safeParse(t);if(!a.success)throw new X({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let i=a.data;return Object.keys(i).forEach(s=>{if(!this.modelSchema.config.def[s])throw new X({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
17
17
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((s,r)=>{let l=this.modelSchema.config.def[r].param,d=i[r];return s[l]=d,s},{})}transformEmbeddingRequests(t){let n=Wi().safeParse(t);if(!n.success)throw new gn({info:"Invalid embedding requests",cause:n.error});if(n.data.requests.length>128)throw new gn({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:n.data.requests}}getGetEmbeddingsUrl(t,n){return B(this,null,function*(){return new Promise(a=>{a(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,n){return B(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,n){return B(this,null,function*(){return new Promise(a=>{a(w(w(w({},this.getDefaultParams()),this.transformConfig(t,n)),this.transformEmbeddingRequests(n)));})})}transformGetEmbeddingsResponse(t){let n,a=hl.safeParse(t);if(a.success){let i=a.data;n=typeof i.data[0].embedding=="string"?$n:qn;let s=i.data.map(r=>typeof r.embedding=="string"?{index:r.index,embedding:r.embedding}:{index:r.index,embedding:r.embedding});return {encodingFormat:n,embeddings:s,usage:{totalTokens:i.usage.total_tokens}}}throw new W({info:"Invalid response from model",cause:a.error})}},Io="voyage-code-2",yl="Optimized for code retrieval.",Bo=de(me).parse({name:Io,description:yl,modalities:ce,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:$.base().def,schema:$.base().schema}}),bl=ae,kl=class extends pe{constructor(t){super(Bo,t);}},Ao="voyage-law-2",Cl="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",No=de(me).parse({name:Ao,description:Cl,modalities:ce,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:$.base().def,schema:$.base().schema}}),vl=ae,Tl=class extends pe{constructor(t){super(No,t);}},Uo="voyage-multilingual-2",Ml="Optimized for multilingual retrieval and RAG.",Lo=de(me).parse({name:Uo,description:Ml,modalities:ce,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:$.base().def,schema:$.base().schema}}),xl=ae,Sl=class extends pe{constructor(t){super(Lo,t);}},qo="voyage-finance-2",Ol="Optimized for finance retrieval and RAG.",$o=de(me).parse({name:qo,description:Ol,modalities:ce,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:$.base().def,schema:$.base().schema}}),wl=ae,Pl=class extends pe{constructor(t){super($o,t);}},Do="voyage-3-lite",Rl="Optimized for latency and cost.",Ho=de(me).parse({name:Do,description:Rl,modalities:ce,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:$.base().def,schema:$.base().schema}}),jl=ae,_l=class extends pe{constructor(t){super(Ho,t);}},Fo="voyage-3",El="Optimized for quality.",zo=de(me).parse({name:Fo,description:El,modalities:ce,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:$.base().def,schema:$.base().schema}}),Il=ae,Bl=class extends pe{constructor(t){super(zo,t);}};var Al="system",Nl="user",Go="assistant",Ul="tool",Ll=[Al,Nl,Go,Ul],wt=zod.z.enum(Ll),ql=[Go],$l=zod.z.enum(ql),Wo="error",Zo="safety",Dl=zod.z.object({type:zod.z.literal(Zo),value:zod.z.object({category:zod.z.string(),probability:zod.z.string(),blocked:zod.z.boolean(),message:zod.z.string()})}),Hl=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Wo),value:zod.z.discriminatedUnion("type",[Dl]),metadata:t}),Xo="partial-error",Fl=zod.z.object({type:zod.z.literal(Zo),category:zod.z.string().optional(),probability:zod.z.string().optional(),blocked:zod.z.boolean().optional(),message:zod.z.string().optional()}),zl=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Xo),value:zod.z.discriminatedUnion("type",[Fl]),metadata:t}),Yo="image",Kl="base64",Vl=["png","jpeg","webp","gif"],Jl=zod.z.object({type:zod.z.literal(Kl),base64:zod.z.string(),mediaType:zod.z.enum(Vl)}),Gl="url",Wl=zod.z.object({type:zod.z.literal(Gl),url:zod.z.string()}),Zl=zod.z.discriminatedUnion("type",[Jl,Wl]),Xl=["low","medium","high","auto"],Yl=zod.z.enum(Xl),Ql=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Yo),detail:Yl,value:Zl,metadata:t}),Qo="pdf",ed="base64",td=zod.z.object({type:zod.z.literal(ed),base64:zod.z.string()}),nd="url",od=zod.z.object({type:zod.z.literal(nd),url:zod.z.string()}),ad=zod.z.discriminatedUnion("type",[td,od]),id=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Qo),value:ad,file:zod.z.object({name:zod.z.string(),id:zod.z.string(),size:zod.z.number().optional()}),metadata:t}),ea="reasoning",ta="partial-reasoning",na="thinking",sd="redacted",Ot=zod.z.object({type:zod.z.literal(na),thinking:zod.z.string(),signature:zod.z.string()}),oa=zod.z.object({type:zod.z.literal(sd),data:zod.z.string()}),rd=zod.z.discriminatedUnion("type",[Ot,oa]),ld=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ea),value:rd,metadata:t}),dd=zod.z.object({type:zod.z.literal(na),thinking:Ot.shape.thinking.optional(),signature:Ot.shape.signature.optional()}),cd=zod.z.discriminatedUnion("type",[dd,oa]),md=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ta),value:cd,metadata:t}),aa="search-result",ia="google",pd=zod.z.object({type:zod.z.literal(ia),query:zod.z.string(),responses:zod.z.array(zod.z.object({source:zod.z.string(),url:zod.z.string(),title:zod.z.string(),snippet:zod.z.string().optional()})),references:zod.z.array(zod.z.object({text:zod.z.string(),responseIndices:zod.z.array(zod.z.number()),startIndex:zod.z.number().optional(),endIndex:zod.z.number().optional(),confidenceScores:zod.z.array(zod.z.number()).optional()}))}),ud=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(aa),value:zod.z.discriminatedUnion("type",[pd]),metadata:t}),sa="partial-search-result",hd=zod.z.object({type:zod.z.literal(ia),query:zod.z.string().optional(),responses:zod.z.array(zod.z.object({source:zod.z.string().optional(),url:zod.z.string().optional(),title:zod.z.string().optional(),snippet:zod.z.string().optional()})).optional(),references:zod.z.array(zod.z.object({text:zod.z.string().optional(),responseIndices:zod.z.array(zod.z.number()).optional(),startIndex:zod.z.number().optional(),endIndex:zod.z.number().optional(),confidenceScores:zod.z.array(zod.z.number()).optional()})).optional()}),gd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(sa),value:zod.z.discriminatedUnion("type",[hd]),metadata:t}),ra="text",fd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ra),value:zod.z.string(),metadata:t}),la="partial-text",yd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(la),value:zod.z.string(),metadata:t}),da="tool-call",bd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(da),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),serverName:zod.z.string().optional(),metadata:t}),ca="partial-tool-call",kd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ca),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),serverName:zod.z.string().optional(),metadata:t}),ma="tool-response",Cd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ma),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:t}),vd="partial-tool-response",Td=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(vd),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),data:zod.z.string().optional(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:t}),Md=[ra,Yo,Qo,da,ma,ea,Wo,aa],pa=zod.z.enum(Md),xd=(t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined(),l=zod.z.undefined(),d=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[fd(t),Ql(n),id(a),bd(i),Cd(s),ld(r),Hl(l),ud(d)]),Sd=[la,ca,ta,Xo,sa];zod.z.enum(Sd);var Od=(t=zod.z.undefined(),n=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[yd(t),kd(n),md(i),Td(a),zl(s),gd(r)]);var wd=(t=wt,n=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined(),l=zod.z.undefined(),d=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(xd(n,a,i,s,l,r)),metadata:d}),Pd=(t=$l,n=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:t,partialContent:Od(n,a,i,r),metadata:s}),Rd=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Ko=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),jd=Ko.extend({topLogProbs:zod.z.array(Ko)}),ua=zod.z.array(jd);zod.z.object({messages:zod.z.array(wd()),usage:Rd.optional(),logProbs:ua.optional()});var _d=zod.z.object({promptTokens:zod.z.number().nonnegative().optional(),completionTokens:zod.z.number().nonnegative().optional(),totalTokens:zod.z.number().nonnegative().optional()});zod.z.object({partialMessages:zod.z.array(Pd()),usage:_d.optional(),logProbs:ua.optional()});var Ed=zod.z.object({enabled:zod.z.boolean().default(!0),allowedTools:zod.z.array(zod.z.string().min(1))});zod.z.object({type:zod.z.literal("url"),url:zod.z.string().url().refine(t=>t.startsWith("https://"),{message:"MCP server URL must start with https://"}),name:zod.z.string().min(1),toolConfiguration:Ed.optional(),authorizationToken:zod.z.string().min(1).optional()});var Id=["object","array","number","string","boolean","enum"],Vo=zod.z.enum(Id),Bd=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Vo,zod.z.array(zod.z.union([Vo,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),Ad=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Bd),additionalProperties:zod.z.literal(!1)});zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:Ad}).optional();var Nd="text",Ud="token",Ld=[Nd,Ud];zod.z.enum(Ld);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var $d="float",Dd=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Hd="base64",Fd=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Jo=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal($d),embeddings:zod.z.array(Dd),usage:Jo.optional()}),zod.z.object({encodingFormat:zod.z.literal(Hd),embeddings:zod.z.array(Fd),usage:Jo.optional()})]);var zd=t=>{let n=new WeakSet;return JSON.stringify(t,(a,i)=>{if(typeof i=="object"&&i!==null){if(n.has(i))return;n.add(i);}return i})},Kd=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:zd(t),St="GatewayBaseError",Pt=class ha extends Error{constructor({info:n,cause:a},i){super(`[${i!=null?i:St}]: ${n}