@adaline/anthropic 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,11 +8,11 @@ Message: ${Lo(o)}`),this.name=Te,this.info=e,this.cause=o,this.name=a!=null?a:Te
8
8
  ${this.chatModelLiterals().join(", ")}`)});return this.chatModelFactories[e].modelSchema}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModel(e,o){if(!(e in this.embeddingModelFactories))throw new Q({info:`Anthropic embedding model: ${e} not found`,cause:new Error(`Anthropic embedding model: ${e} not found, available embedding models:
9
9
  ${this.embeddingModelLiterals().join(", ")}`)});let a=this.embeddingModelFactories[e].model,l=y({},o),d=this.embeddingModelFactories[e].modelOptions.parse(l);return new a(d)}embeddingModelSchema(e){if(!(e in this.embeddingModelFactories))throw new Q({info:`Anthropic embedding model: ${e} not found`,cause:new Error(`Anthropic embedding model: ${e} not found, available embedding models:
10
10
  ${this.embeddingModelLiterals().join(", ")}`)});return this.embeddingModelFactories[e].modelSchema}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,o)=>(e[o]=this.embeddingModelFactories[o].modelSchema,e),{})}};J.chatBaseUrl="https://api.anthropic.com/v1",J.embeddingBaseUrl="https://api.anthropic.com/v1";var V=zod.z.object({apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),P=class{constructor(e,o){this.version="v1";let a=V.parse(o);this.modelSchema=e,this.apiKey=a.apiKey,this.baseUrl=Y(J.chatBaseUrl),this.completeChatUrl=Y(a.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=Y(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",source:"adaline.ai"}}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let o=0,a=!0;return e["x-should-retry"]&&(a=e["x-should-retry"].toLowerCase()!=="false"),e["retry-after"]&&(o=parseInt(e["retry-after"])*1e3),{shouldRetry:a,delayMs:o}}getTokenCount(e){return e.reduce((o,a)=>o+a.content.map(l=>l.modality==="text"?l.value:"").join(" ").length,0)}transformModelRequest(e){let o=go.safeParse(e);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let a=o.data,l=a.model;if(a.tool_choice&&(!a.tools||a.tools.length===0))throw new X({info:`Invalid model request for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let d={};a.tool_choice&&(a.tool_choice.type==="tool"?d.toolChoice=a.tool_choice.name:d.toolChoice=a.tool_choice.type),d.maxTokens=a.max_tokens,d.temperature=a.temperature,d.topP=a.top_p,d.topK=a.top_k,d.stop=a.stop_sequences;let s=ne().parse(se(d)),i=[],m={};a.system&&i.push({role:Z,content:[{modality:b,value:a.system}]}),a.messages.forEach(h=>{let S=h.role;switch(S){case"user":{let R=h.content;if(typeof R=="string")i.push({role:S,content:[{modality:b,value:R}]});else {let v=R.map(g=>{if(g.type==="text")return {modality:b,value:g.text};if(g.type==="image"){let fe="auto",oe=g.source.media_type.split("/")[1];return {modality:$,detail:fe,value:{type:Me,media_type:oe,base64:g.source.data}}}else return {modality:z,id:g.tool_use_id,index:m[g.tool_use_id].index,name:m[g.tool_use_id].name,data:typeof g.content=="string"?g.content:JSON.stringify(g.content)}});i.push({role:S,content:v});}}break;case"assistant":{let R=h.content;if(typeof R=="string")i.push({role:S,content:[{modality:b,value:R}]});else {let v=R.map((g,fe)=>{if(g.type==="text")return {modality:b,value:g.text};{let oe={modality:_,id:g.id,index:fe,name:g.name,arguments:JSON.stringify(g.input)};return m[g.id]=oe,oe}});i.push({role:S,content:v});}}break}});let u=[];return a.tools&&a.tools.forEach(h=>{u.push({type:"function",definition:{schema:{name:h.name,description:h.description||"",parameters:h.input_schema}}});}),{modelName:l,config:s,messages:i,tools:u.length>0?u:void 0}}transformConfig(e,o,a){let l=e.toolChoice;delete e.toolChoice;let d=this.modelSchema.config.schema.safeParse(e);if(!d.success)throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:d.error});let s=d.data;l!==void 0&&(s.toolChoice=l),Object.keys(s).forEach(m=>{if(!(m in this.modelSchema.config.def))throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${m}',
11
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let i=Object.keys(s).reduce((m,u)=>{let h=this.modelSchema.config.def[u],S=h.param,R=s[u];return S==="max_tokens"&&h.type==="range"&&R===0?m[S]=h.max:m[S]=R,m},{});if(!i.max_tokens)throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`'max_tokens' is required for model : '${this.modelSchema.name}'`)});if("tool_choice"in i&&i.tool_choice!==void 0){let m=i.tool_choice;if(!a||a&&a.length===0)throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(a&&a.length>0){let u=this.modelSchema.config.def.toolChoice;if(!u.choices.includes(m))if(a.map(h=>h.definition.schema.name).includes(m))i.tool_choice={type:"tool",name:m};else throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`toolChoice : '${m}' is not part of provided 'tools' names or
12
- one of [${u.choices.join(", ")}]`)})}}return i}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let o=e.map(s=>{let i=Re().safeParse(s);if(!i.success)throw new M({info:"Invalid messages",cause:i.error});return i.data});o.forEach(s=>{s.content.forEach(i=>{if(!this.modelSchema.modalities.includes(i.modality))throw new M({info:`Invalid message content for model : '${this.modelSchema.name}'`,cause:new Error(`model : '${this.modelSchema.name}' does not support modality : '${i.modality}',
11
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let i=Object.keys(s).reduce((m,u)=>{let h=this.modelSchema.config.def[u],S=h.param,R=s[u];return S==="max_tokens"&&h.type==="range"&&R===0?m[S]=h.max:m[S]=R,m},{});if(!i.max_tokens)throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`'max_tokens' is required for model : '${this.modelSchema.name}'`)});if("tool_choice"in i&&i.tool_choice!==void 0){let m=i.tool_choice;if(!a||a&&a.length===0)throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(a&&a.length>0){let u=this.modelSchema.config.def.toolChoice;if(u.choices.includes(m))i.tool_choice={type:m};else if(a.map(h=>h.definition.schema.name).includes(m))i.tool_choice={type:"tool",name:m};else throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`toolChoice : '${m}' is not part of provided 'tools' names or
12
+ one of [${u.choices.join(", ")}]`)})}}return i}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let o=e.map(s=>{let i=Re().safeParse(s);if(!i.success)throw new M({info:"Invalid messages",cause:i.error});return i.data});o.forEach(s=>{s.content.forEach(i=>{if(!this.modelSchema.modalities.includes(i.modality))throw new M({info:`Invalid message content for model : '${this.modelSchema.name}'`,cause:new Error(`model : '${this.modelSchema.name}' does not support modality : '${i.modality}',
13
13
  available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new M({info:`Invalid message content for model : '${this.modelSchema.name}'`,cause:new Error(`model : '${this.modelSchema.name}' does not support role : '${s.role}',
14
14
  available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let a="",l=[];if(o.forEach(s=>{switch(s.role){case Z:s.content.forEach(i=>{if(i.modality===b)a+=i.value;else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${i.modality}'`)})});break;case C:{let i=[];s.content.forEach(m=>{if(m.modality===b)i.push({type:"text",text:m.value});else if(m.modality===_)i.push({type:"tool_use",id:m.id,name:m.name,input:JSON.parse(m.arguments)});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${m.modality}'`)})}),l.push({role:this.modelSchema.roles[s.role],content:i});}break;case L:{let i=[];s.content.forEach(m=>{if(m.modality===b)i.push({type:"text",text:m.value});else if(m.modality===$){if(m.value.type==="base64")i.push({type:"image",source:{type:"base64",media_type:`image/${m.value.media_type}`,data:m.value.base64}});else if(m.value.type==="url")throw new M({info:`Invalid message 'modality' for model : ${this.modelSchema.name}`,cause:new Error(`model: '${this.modelSchema.name}' does not support image content type: '${m.value.type}'`)})}else if(m.modality===z)i.push({type:"tool_result",tool_use_id:m.id,content:m.data});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${m.modality}'`)})}),l.push({role:this.modelSchema.roles[s.role],content:i});}break;default:throw new M({info:`Invalid message 'role' for model : ${this.modelSchema.name}`,cause:new Error(`role : '${s.role}' is not supported,
15
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),l[0].role!==this.modelSchema.roles[L])throw new M({info:`Invalid message 'role' for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' requires first message to be from user`)});let d=s=>s===this.modelSchema.roles[L]?this.modelSchema.roles[C]:this.modelSchema.roles[L];for(let s=1;s<l.length;s++)if(l[s].role!==d(l[s-1].role))throw new M({info:`Invalid message format for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' requires messages to alternate between user and assistant`)});return {system:a,messages:l}}transformTools(e){if(!this.modelSchema.modalities.includes(_))throw new ke({info:`Invalid tool 'modality' for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' does not support tool modality : '${_}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(l=>{let d=Ot().safeParse(l);if(!d.success)throw new ke({info:"Invalid tools",cause:d.error});return d.data}).map(l=>({name:l.definition.schema.name,description:l.definition.schema.description,function:l.definition.schema}))}}getCompleteChatUrl(e,o,a){return j(this,null,function*(){return new Promise(l=>{l(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,a){return j(this,null,function*(){let l=this.getDefaultHeaders();return a&&a.length>0&&(l=be(y({},l),{"anthropic-beta":"tools-2024-05-16"})),new Promise(d=>{d(l);})})}getCompleteChatData(e,o,a){return j(this,null,function*(){let l=this.transformConfig(e,o,a),d=this.transformMessages(o);if(d.messages&&d.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let s=a?this.transformTools(a):{};return new Promise(i=>{i(y(y(y(y({},this.getDefaultParams()),l),d),s));})})}transformCompleteChatResponse(e){let o=ro.safeParse(e);if(o.success){let a=o.data,d=a.content.map((m,u)=>{if(m.type==="text")return vt(m.text);if(m.type==="tool_use")return xt(u,m.id,m.name,JSON.stringify(m.input))}),s=[{role:C,content:d}],i={promptTokens:a.usage.input_tokens,completionTokens:a.usage.output_tokens,totalTokens:a.usage.input_tokens+a.usage.output_tokens};return {messages:s,usage:i,logProbs:[]}}throw new I({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,a){return j(this,null,function*(){return new Promise(l=>{l(this.streamChatUrl);})})}getStreamChatHeaders(e,o,a){let l=this.getDefaultHeaders();return a&&a.length>0&&(l=be(y({},l),{"anthropic-beta":"tools-2024-05-16"})),new Promise(d=>{d(l);})}getStreamChatData(e,o,a){return j(this,null,function*(){let l=this.transformConfig(e,o,a),d=this.transformMessages(o);if(d.messages&&d.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let s=a?this.transformTools(a):{};return new Promise(i=>{i(y(y(y(y({stream:!0},this.getDefaultParams()),l),d),s));})})}transformStreamChatResponseChunk(e,o){return gt(this,null,function*(){let a=(o+e).split(`
15
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),l[0].role!==this.modelSchema.roles[L])throw new M({info:`Invalid message 'role' for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' requires first message to be from user`)});let d=s=>s===this.modelSchema.roles[L]?this.modelSchema.roles[C]:this.modelSchema.roles[L];for(let s=1;s<l.length;s++)if(l[s].role!==d(l[s-1].role))throw new M({info:`Invalid message format for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' requires messages to alternate between user and assistant`)});return {system:a,messages:l}}transformTools(e){if(!this.modelSchema.modalities.includes(_))throw new ke({info:`Invalid tool 'modality' for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' does not support tool modality : '${_}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(l=>{let d=Ot().safeParse(l);if(!d.success)throw new ke({info:"Invalid tools",cause:d.error});return d.data}).map(l=>({name:l.definition.schema.name,description:l.definition.schema.description,input_schema:l.definition.schema.parameters}))}}getCompleteChatUrl(e,o,a){return j(this,null,function*(){return new Promise(l=>{l(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,a){return j(this,null,function*(){let l=this.getDefaultHeaders();return a&&a.length>0&&(l=be(y({},l),{"anthropic-beta":"tools-2024-05-16"})),new Promise(d=>{d(l);})})}getCompleteChatData(e,o,a){return j(this,null,function*(){let l=this.transformConfig(e,o,a),d=this.transformMessages(o);if(d.messages&&d.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let s=a?this.transformTools(a):{};return new Promise(i=>{i(y(y(y(y({},this.getDefaultParams()),l),d),s));})})}transformCompleteChatResponse(e){let o=ro.safeParse(e);if(o.success){let a=o.data,d=a.content.map((m,u)=>{if(m.type==="text")return vt(m.text);if(m.type==="tool_use")return xt(u,m.id,m.name,JSON.stringify(m.input))}),s=[{role:C,content:d}],i={promptTokens:a.usage.input_tokens,completionTokens:a.usage.output_tokens,totalTokens:a.usage.input_tokens+a.usage.output_tokens};return {messages:s,usage:i,logProbs:[]}}throw new I({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,a){return j(this,null,function*(){return new Promise(l=>{l(this.streamChatUrl);})})}getStreamChatHeaders(e,o,a){let l=this.getDefaultHeaders();return a&&a.length>0&&(l=be(y({},l),{"anthropic-beta":"tools-2024-05-16"})),new Promise(d=>{d(l);})}getStreamChatData(e,o,a){return j(this,null,function*(){let l=this.transformConfig(e,o,a),d=this.transformMessages(o);if(d.messages&&d.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let s=a?this.transformTools(a):{};return new Promise(i=>{i(y(y(y(y({stream:!0},this.getDefaultParams()),l),d),s));})})}transformStreamChatResponseChunk(e,o){return gt(this,null,function*(){let a=(o+e).split(`
16
16
  `).filter(l=>l.trim()!=="");for(let l of a)if(l.startsWith("data: {")&&l.endsWith("}")){let d;try{d=JSON.parse(l.substring(6));}catch(s){throw new I({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${d}`)})}if("type"in d){if(d.type==="message_stop")return;if(d.type==="message_start"){let s=lo.safeParse(d);if(s.success){let i=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:i.message.usage.input_tokens,completionTokens:i.message.usage.output_tokens,totalTokens:i.message.usage.input_tokens+i.message.usage.output_tokens}},buffer:o};}else throw new I({info:"Invalid response from model",cause:s.error})}else if(d.type==="message_delta"){let s=mo.safeParse(d);if(s.success){let i=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:0,completionTokens:i.usage.output_tokens,totalTokens:i.usage.output_tokens}},buffer:o};}else throw new I({info:"Invalid response from model",cause:s.error})}else if(d.type==="content_block_start"){let s=po.safeParse(d);if(s.success){let i=s.data,m=[];i.content_block.type==="text"?m.push(xe(C,i.content_block.text)):i.content_block.type==="tool_use"&&m.push(Oe(C,i.index,i.content_block.id,i.content_block.name,"")),yield {partialResponse:{partialMessages:m},buffer:o};}else throw new I({info:"Invalid response from model",cause:s.error})}else if(d.type==="content_block_delta"){let s=co.safeParse(d);if(s.success){let i=s.data,m=[];i.delta.type==="text_delta"?m.push(xe(C,i.delta.text)):i.delta.type==="input_json_delta"&&m.push(Oe(C,i.index,"","",i.delta.partial_json)),yield {partialResponse:{partialMessages:m},buffer:o};}else throw new I({info:"Invalid response from model",cause:s.error})}}else throw new I({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property,
17
17
  received : ${JSON.stringify(d)}`)})}})}};var Ke="claude-3-haiku-20240307",ia="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",Ge=D(N,G).parse({name:Ke,description:ia,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),yo=V,ie=class extends P{constructor(e){super(Ge,e);}};var Je="claude-3-sonnet-20240229",ra="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",We=D(N,G).parse({name:Je,description:ra,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),fo=V,re=class extends P{constructor(e){super(We,e);}};var Ze="claude-3-opus-20240229",la="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",Ye=D(N,G).parse({name:Ze,description:la,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),bo=V,le=class extends P{constructor(e){super(Ye,e);}};var Qe="claude-3-5-sonnet-20240620",da="Most intelligent model. Highest level of intelligence and capability.",Xe=D(N,G).parse({name:Qe,description:da,maxInputTokens:2e5,maxOutputTokens:8192,roles:H,modalities:K,config:{def:O.base(8192,4).def,schema:O.base(8192,4).schema}}),To=V,de=class extends P{constructor(e){super(Xe,e);}};var A=[F],w=zod.z.enum([F]);var xo=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()})});var pa=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),Oo=zod.z.object({model:zod.z.string().min(1).optional(),input:pa,encoding_format:zod.z.enum(["base64"]).nullable().optional(),input_type:zod.z.enum(["query","document"]).nullable().optional(),truncation:zod.z.boolean().optional()});var E=zod.z.object({apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),T=class{constructor(e,o){this.version="v1";let a=E.parse(o);this.modelSchema=e,this.apiKey=a.apiKey,this.baseUrl=Y(J.embeddingBaseUrl),this.getEmbeddingsUrl=Y(a.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"}}getDefaultParams(){return {model:this.modelSchema.name}}getTokenCount(e){return e.requests.reduce((o,a)=>o+a.length,0)}getRetryDelay(e){return {shouldRetry:!0,delayMs:0}}transformModelRequest(e){let o=Oo.safeParse(e);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let a=o.data,l=a.model,d={encodingFormat:a.encoding_format,inputType:a.input_type,truncation:a.truncation},s=ne().parse(se(d)),i;return typeof a.input=="string"?i={modality:F,requests:[a.input]}:i={modality:F,requests:a.input},{modelName:l,config:s,embeddingRequests:i}}transformConfig(e,o){let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:a.error});let l=a.data;return Object.keys(l).forEach(s=>{if(!this.modelSchema.config.def[s])throw new B({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${s}',
18
18
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(l).reduce((s,i)=>{let u=this.modelSchema.config.def[i].param,h=l[i];return s[u]=h,s},{})}transformEmbeddingRequests(e){let o=kt().safeParse(e);if(!o.success)throw new _e({info:"Invalid embedding requests",cause:o.error});if(o.data.requests.length>128)throw new _e({info:`Invalid embedding requests for model : '${this.modelSchema.name}'`,cause:new Error(`Max requests for model : '${this.modelSchema.name}' is 128`)});return {input:o.data.requests}}getGetEmbeddingsUrl(e,o){return j(this,null,function*(){return new Promise(a=>{a(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return j(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return j(this,null,function*(){return new Promise(a=>{a(y(y(y({},this.getDefaultParams()),this.transformConfig(e,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o,a=xo.safeParse(e);if(a.success){let l=a.data;o=typeof l.data[0].embedding=="string"?we:Ae;let d=l.data.map(s=>typeof s.embedding=="string"?{index:s.index,embedding:s.embedding}:{index:s.index,embedding:s.embedding});return {encodingFormat:o,embeddings:d,usage:{totalTokens:l.usage.total_tokens}}}throw new I({info:"Invalid response from model",cause:a.error})}};var et="voyage-code-2",ca="Optimized for code retrieval.",tt=x(w).parse({name:et,description:ca,modalities:A,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:f.base().def,schema:f.base().schema}}),Co=E,me=class extends T{constructor(e){super(tt,e);}};var ot="voyage-law-2",ua="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",nt=x(w).parse({name:ot,description:ua,modalities:A,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:f.base().def,schema:f.base().schema}}),Mo=E,pe=class extends T{constructor(e){super(nt,e);}};var at="voyage-multilingual-2",ha="Optimized for multilingual retrieval and RAG.",st=x(w).parse({name:at,description:ha,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),Eo=E,ce=class extends T{constructor(e){super(st,e);}};var it="voyage-finance-2",ga="Optimized for finance retrieval and RAG.",rt=x(w).parse({name:it,description:ga,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),So=E,ue=class extends T{constructor(e){super(rt,e);}};var lt="voyage-3-lite",ya="Optimized for latency and cost.",dt=x(w).parse({name:lt,description:ya,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),Ro=E,he=class extends T{constructor(e){super(dt,e);}};var mt="voyage-3",fa="Optimized for quality.",pt=x(w).parse({name:mt,description:fa,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),vo=E,ge=class extends T{constructor(e){super(pt,e);}};