@adaline/anthropic 0.24.0 → 0.26.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
@@ -2,18 +2,18 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
- var Jo=Object.defineProperty,Wo=Object.defineProperties;var Zo=Object.getOwnPropertyDescriptors;var At=Object.getOwnPropertySymbols;var Yo=Object.prototype.hasOwnProperty,Qo=Object.prototype.propertyIsEnumerable;var ae=(a,e)=>(e=Symbol[a])?e:Symbol.for("Symbol."+a),Xo=a=>{throw TypeError(a)};var kt=(a,e,o)=>e in a?Jo(a,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[e]=o,C=(a,e)=>{for(var o in e||(e={}))Yo.call(e,o)&&kt(a,o,e[o]);if(At)for(var o of At(e))Qo.call(e,o)&&kt(a,o,e[o]);return a},Re=(a,e)=>Wo(a,Zo(e));var k=(a,e,o)=>new Promise((n,s)=>{var d=p=>{try{r(o.next(p));}catch(u){s(u);}},i=p=>{try{r(o.throw(p));}catch(u){s(u);}},r=p=>p.done?n(p.value):Promise.resolve(p.value).then(d,i);r((o=o.apply(a,e)).next());}),_t=function(a,e){this[0]=a,this[1]=e;},ve=(a,e,o)=>{var n=(i,r,p,u)=>{try{var g=o[i](r),A=(r=g.value)instanceof _t,q=g.done;Promise.resolve(A?r[0]:r).then(O=>A?n(i==="return"?i:"next",r[1]?{done:O.done,value:O.value}:O,p,u):p({value:O,done:q})).catch(O=>n("throw",O,p,u));}catch(O){u(O);}},s=i=>d[i]=r=>new Promise((p,u)=>n(i,r,p,u)),d={};return o=o.apply(a,e),d[ae("asyncIterator")]=()=>d,s("next"),s("throw"),s("return"),d},wt=a=>{var e=a[ae("asyncIterator")],o=!1,n,s={};return e==null?(e=a[ae("iterator")](),n=d=>s[d]=i=>e[d](i)):(e=e.call(a),n=d=>s[d]=i=>{if(o){if(o=!1,d==="throw")throw i;return i}return o=!0,{done:!1,value:new _t(new Promise(r=>{var p=e[d](i);p instanceof Object||Xo("Object expected"),r(p);}),1)}}),s[ae("iterator")]=()=>s,n("next"),"throw"in e?n("throw"):s.throw=d=>{throw d},"return"in e&&n("return"),s};var en=a=>{let e=new WeakSet;return JSON.stringify(a,(o,n)=>{if(typeof n=="object"&&n!==null){if(e.has(n))return;e.add(n);}return n})},tn=a=>a==null?"unknown error":typeof a=="string"?a:a instanceof Error?a.message:en(a),Oe="GatewayBaseError",H=class Lt extends Error{constructor({info:e,cause:o},n){super(`[${n!=null?n:Oe}]: ${e}
6
- Message: ${tn(o)}`),this.name=Oe,this.info=e,this.cause=o,this.name=n!=null?n:Oe,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(e){return e instanceof Lt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Z="system",z="user",P="assistant",Q="tool",on=[Z,z,P,Q],xe=zod.z.enum(on),nn=[P],an=zod.z.enum(nn),D="image",Ae="base64",sn=["png","jpeg","webp","gif"],rn=zod.z.object({type:zod.z.literal(Ae),base64:zod.z.string(),media_type:zod.z.enum(sn)}),ln="url",dn=zod.z.object({type:zod.z.literal(ln),url:zod.z.string()}),pn=zod.z.discriminatedUnion("type",[rn,dn]),mn=["low","medium","high","auto"],cn=zod.z.enum(mn),un=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(D),detail:cn,value:pn,metadata:a}),x="text",jt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(x),value:zod.z.string(),metadata:a}),ke="partial-text",Bt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ke),value:zod.z.string(),metadata:a}),V="tool-call",Ut=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(V),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:a}),_e="partial-tool-call",Vt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_e),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:a}),F="tool-response",hn=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(F),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:a}),gn=[x,D,V,F],Nt=zod.z.enum(gn),yn=(a=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[jt(a),un(e),Ut(o),hn(n)]),fn=[ke,_e];zod.z.enum(fn);var bn=(a=zod.z.undefined(),e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Bt(a),Vt(e)]);var we=(a=xe,e=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined(),s=zod.z.undefined(),d=zod.z.undefined())=>zod.z.object({role:a,content:zod.z.array(yn(e,o,n,s)),metadata:d}),qe=(a=an,e=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.object({role:a,partialContent:bn(e,o),metadata:n}),zt=a=>jt().parse({modality:x,value:a}),$t=(a,e,o,n)=>Ut().parse({modality:V,index:a,id:e,name:o,arguments:n});var Pe=(a,e)=>qe().parse({role:a,partialContent:Bt().parse({modality:ke,value:e})}),Ie=(a,e,o,n,s)=>qe().parse({role:a,partialContent:Vt().parse({modality:_e,index:e,id:o,name:n,arguments:s})});var se=(a=zod.z.record(zod.z.string(),zod.z.any()).optional())=>a,Cn=["object","array","number","string","boolean","enum"],qt=zod.z.enum(Cn),Tn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([qt,zod.z.array(zod.z.union([qt,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()}),Mn=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(Tn),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:Mn}).optional();var En="function";var Sn=zod.z.enum(["object","array","number","string","boolean","null"]),Rn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Sn.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()});zod.z.object({type:zod.z.enum(["object"]),title:zod.z.string().optional(),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Rn).optional(),required:zod.z.array(zod.z.string()).optional()});var vn=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),parameters:zod.z.any(),strict:zod.z.boolean().optional()});var On=zod.z.enum(["function"]),xn=zod.z.object({type:On,definition:zod.z.object({schema:vn})}),An=[En];zod.z.enum(An);var Ht=(a=zod.z.undefined())=>zod.z.discriminatedUnion("type",[xn.extend({metadata:a})]),K="text",Dt="token",kn=[K,Dt],Ft=zod.z.enum(kn),_n=zod.z.array(zod.z.string().min(1)),wn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Kt=(a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(K),metadata:a,requests:_n}),zod.z.object({modality:zod.z.literal(Dt),metadata:a,requests:wn})]),Le="float",qn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),je="base64",Pn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Pt=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Le),embeddings:zod.z.array(qn),usage:Pt.optional()}),zod.z.object({encodingFormat:zod.z.literal(je),embeddings:zod.z.array(Pn),usage:Pt.optional()})]);var Gt=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),It=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),In=It.extend({topLogProbs:zod.z.array(It)}),Jt=zod.z.array(In);zod.z.object({messages:zod.z.array(we()),usage:Gt.optional(),logProbs:Jt.optional()});zod.z.object({partialMessages:zod.z.array(qe()),usage:Gt.optional(),logProbs:Jt.optional()});var Ln=Object.defineProperty,Wt=Object.getOwnPropertySymbols,jn=Object.prototype.hasOwnProperty,Bn=Object.prototype.propertyIsEnumerable,Zt=(a,e,o)=>e in a?Ln(a,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[e]=o,ie=(a,e)=>{for(var o in e||(e={}))jn.call(e,o)&&Zt(a,o,e[o]);if(Wt)for(var o of Wt(e))Bn.call(e,o)&&Zt(a,o,e[o]);return a},Yt="ProviderError",Be=class ao extends H{constructor({info:e,cause:o}){super({info:e,cause:o},Yt),this.name=Yt,this.info=e,this.cause=o;}static isProviderError(e){return e instanceof ao}};var Qt="ModelResponseError",$=class so extends H{constructor({info:e,cause:o}){super({info:e,cause:o},Qt),this.name=Qt,this.cause=o,this.info=e;}static isModelResponseError(e){return e instanceof so}},Xt="InvalidModelRequestError",X=class io extends H{constructor({info:e,cause:o}){super({info:e,cause:o},Xt),this.name=Xt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(e){return e instanceof io}},eo="InvalidConfigError",G=class ro extends H{constructor({info:e,cause:o}){super({info:e,cause:o},eo),this.name=eo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(e){return e instanceof ro}},to="InvalidMessagesError",_=class lo extends H{constructor({info:e,cause:o}){super({info:e,cause:o},to),this.name=to,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(e){return e instanceof lo}},oo="InvalidToolsError",Ue=class po extends H{constructor({info:e,cause:o}){super({info:e,cause:o},oo),this.name=oo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(e){return e instanceof po}},no="InvalidEmbeddingRequestsError",Ve=class mo extends H{constructor({info:e,cause:o}){super({info:e,cause:o},no),this.name=no,this.info=e,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(e){return e instanceof mo}},Ne="multi-string",co=zod.z.object({type:zod.z.literal(Ne),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),Un=a=>zod.z.array(zod.z.string()).max(a).default([]).optional(),uo=a=>({def:co.parse(ie({type:Ne},a)),schema:Un(a.max)}),ho="object-schema",Vn=zod.z.object({type:zod.z.literal(ho),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var ze="range",go=zod.z.object({type:zod.z.literal(ze),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),Nn=(a,e,o,n)=>zod.z.number().min(a).max(e).step(o).default(n).optional(),ee=a=>({def:go.parse(ie({type:ze},a)),schema:Nn(a.min,a.max,a.step,a.default)}),$e="select-boolean",yo=zod.z.object({type:zod.z.literal($e),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),zn=a=>zod.z.boolean().nullable().default(a).optional(),fo=a=>({def:yo.parse(ie({type:$e},a)),schema:zn(a.default)}),He="select-string",bo=zod.z.object({type:zod.z.literal(He),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))}),$n=(a,e)=>zod.z.enum(e).nullable().default(a).optional(),te=a=>({def:bo.parse(ie({type:He},a)),schema:$n(a.default,a.choices)}),Hn=[ze,Ne,He,ho,$e];zod.z.enum(Hn);var Co=zod.z.discriminatedUnion("type",[go,co,bo,yo,Vn]),M=(a=xe,e=Nt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(a,zod.z.string().min(1).optional()),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Co),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var n,s;let d=Object.keys(o.def),i=Object.keys((s=(n=o.schema)==null?void 0:n.shape)!=null?s:{});return d.every(r=>i.includes(r))&&i.every(r=>d.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),L=(a=Ft)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(a).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Co),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(e=>{var o,n;let s=Object.keys(e.def),d=Object.keys((n=(o=e.schema)==null?void 0:o.shape)!=null?n:{});return s.every(i=>d.includes(i))&&d.every(i=>s.includes(i))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var Dn={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},Fn={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},Kn=a=>({type:"multi",title:"Stop sequence",description:`Enter up to ${a} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Gn={type:"range",title:"Top A",description:"Considers only the top tokens that have 'sufficiently high' probabilities relative to the most likely token, functioning like a dynamic Top-P. A lower Top-A value narrows down the token choices based on the highest probability token, while a higher Top-A value refines the filtering without necessarily impacting the creativity of the output."},Jn={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},Wn={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},Zn={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},Yn={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},Qn={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},Xn={type:"range",title:"Seed",description:"When seed is fixed to a specific value, the model makes a best effort to provide the same response for repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such as the temperature, can cause variations in the response even when you use the same seed value. By default, a random seed value is used."},ea={type:"range",title:"Repetition penalty",description:"Reduces the likelihood of repeating tokens from the input. Increasing this value makes the model less prone to repetition, but setting it too high may lead to less coherent output, often resulting in run-on sentences missing smaller words. The token penalty is scaled according to the original token's probability."},ta={type:"boolean",title:"Log probs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned."},oa={type:"range",title:"Top log probs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used."},na={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},aa={type:"select",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt."},sa={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},ia={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},N={TEMPERATURE:Dn,MAX_TOKENS:Fn,STOP:Kn,TOP_A:Gn,TOP_P:Jn,TOP_K:Wn,MIN_P:Zn,FREQUENCY_PENALTY:Yn,PRESENCE_PENALTY:Qn,REPETITION_PENALTY:ea,SEED:Xn,LOG_PROBS:ta,TOP_LOG_PROBS:oa,ECHO:na,RESPONSE_FORMAT:aa,RESPONSE_FORMAT_WITH_SCHEMA:sa,RESPONSE_SCHEMA:ia};var re=a=>Object.fromEntries(Object.entries(a).filter(([e,o])=>o!=null));var Y=a=>a==null?void 0:a.replace(/\/$/,"");var De=ee({param:"temperature",title:N.TEMPERATURE.title,description:N.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),Fe=a=>ee({param:"max_tokens",title:N.MAX_TOKENS.title,description:N.MAX_TOKENS.description,min:0,max:a,step:1,default:0}),Ke=a=>uo({param:"stop_sequences",title:N.STOP(a).title,description:N.STOP(a).description,max:a}),Ge=ee({param:"top_p",title:N.TOP_P.title,description:N.TOP_P.description,min:0,max:1,step:.01,default:1}),Je=ee({param:"top_k",title:N.TOP_K.title,description:N.TOP_K.description,min:0,max:1,step:.01,default:1}),We=te({param:"tool_choice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'any' means the model will call any of the provided tools. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","any"]});var To=(a,e)=>zod.z.object({temperature:De.schema,maxTokens:Fe(a).schema,stop:Ke(e).schema,topP:Ge.schema,topK:Je.schema,toolChoice:We.schema}),Mo=(a,e)=>({temperature:De.def,maxTokens:Fe(a).def,stop:Ke(e).def,topP:Ge.def,topK:Je.def,toolChoice:We.def});var Ze=te({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:null,choices:["base64"]}),Ye=te({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:null,choices:["query","document"]}),Qe=fo({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0});var Eo=()=>zod.z.object({encodingFormat:Ze.schema,inputType:Ye.schema,truncation:Qe.schema}),So=()=>({encodingFormat:Ze.def,inputType:Ye.def,truncation:Qe.def});var h={base:(a,e)=>({def:Mo(a,e),schema:To(a,e)})},f={base:()=>({def:So(),schema:Eo()})};var da="anthropic",J=class{constructor(){this.version="v1";this.name=da;this.chatModelFactories={[st]:{model:me,modelOptions:xo,modelSchema:it},[ut]:{model:ge,modelOptions:wo,modelSchema:ht},[mt]:{model:he,modelOptions:_o,modelSchema:ct},[Xe]:{model:le,modelOptions:Ro,modelSchema:et},[tt]:{model:de,modelOptions:vo,modelSchema:ot},[rt]:{model:ce,modelOptions:Ao,modelSchema:lt},[nt]:{model:pe,modelOptions:Oo,modelSchema:at},[dt]:{model:ue,modelOptions:ko,modelSchema:pt}};this.embeddingModelFactories={[vt]:{model:Me,modelOptions:Bo,modelSchema:Ot},[St]:{model:Te,modelOptions:jo,modelSchema:Rt},[gt]:{model:ye,modelOptions:qo,modelSchema:yt},[ft]:{model:fe,modelOptions:Po,modelSchema:bt},[Ct]:{model:be,modelOptions:Io,modelSchema:Tt},[Mt]:{model:Ce,modelOptions:Lo,modelSchema:Et}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}chatModel(e){let o=e.modelName;if(!(o in this.chatModelFactories))throw new Be({info:`Anthropic chat model: ${o} not found`,cause:new Error(`Anthropic chat model: ${o} not found, available chat models:
7
- ${this.chatModelLiterals().join(", ")}`)});let n=this.chatModelFactories[o].model,s=this.chatModelFactories[o].modelOptions.parse(e);return new n(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,o)=>(e[o]=this.embeddingModelFactories[o].modelSchema,e),{})}embeddingModel(e){let o=e.modelName;if(!(o in this.embeddingModelFactories))throw new Be({info:`Anthropic embedding model: ${o} not found`,cause:new Error(`Anthropic embedding model: ${o} not found, available embedding models:
8
- ${this.embeddingModelLiterals().join(", ")}`)});let n=this.embeddingModelFactories[o].model,s=this.embeddingModelFactories[o].modelOptions.parse(e);return new n(s)}};J.chatBaseUrl="https://api.anthropic.com/v1",J.embeddingBaseUrl="https://api.voyageai.com/v1";var E=zod.z.enum([Z,z,P,Q]),S={system:Z,user:z,assistant:P,tool:z};var R=[x,D,V,F],v=zod.z.enum([x,D,V,F]);var ca=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ua=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),Uo=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[ca,ua])),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()})}),Vo=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()})})}),No=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()})}),ha=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ga=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),zo=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[ha,ga])}),ya=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),fa=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),$o=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[ya,fa])});var ba=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),Ca=zod.z.object({type:zod.z.enum(["auto","any"])}),Ta=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")}),Ho=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()})}),Ps=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())}),Do=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,Ho])).min(1))}),Ma=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xt,Ho,Do])).min(1))}),Ea=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xt,Do])).min(1))}),Sa=zod.z.union([Ma,Ea]),Fo=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Sa).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([Ca,Ta]).optional(),tools:zod.z.array(ba).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()});var T=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),b=class{constructor(e,o){this.version="v1";let n=T.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Y(J.chatBaseUrl),this.completeChatUrl=Y(n.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=Y(n.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(e){let o=0,n=!0;return e["x-should-retry"]&&(n=e["x-should-retry"].toLowerCase()!=="false"),e["retry-after"]&&(o=parseInt(e["retry-after"])*1e3),{shouldRetry:n,delayMs:o}}getTokenCount(e){return e.reduce((o,n)=>o+n.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(e){let o=Fo.safeParse(e);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let n=o.data,s=n.model;if(n.tool_choice&&(!n.tools||n.tools.length===0))throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let d={};n.tool_choice&&(n.tool_choice.type==="tool"?d.toolChoice=n.tool_choice.name:d.toolChoice=n.tool_choice.type),d.maxTokens=n.max_tokens,d.temperature=n.temperature,d.topP=n.top_p,d.topK=n.top_k,d.stop=n.stop_sequences;let i=se().parse(re(d)),r=[],p={};n.system&&r.push({role:Z,content:[{modality:x,value:n.system}]}),n.messages.forEach(g=>{let A=g.role;switch(A){case"user":{let q=g.content;if(typeof q=="string")r.push({role:A,content:[{modality:x,value:q}]});else {let O=q.map(y=>{if(y.type==="text")return {modality:x,value:y.text};if(y.type==="image"){let Se="auto",ne=y.source.media_type.split("/")[1];return {modality:D,detail:Se,value:{type:Ae,media_type:ne,base64:y.source.data}}}else return {modality:F,id:y.tool_use_id,index:p[y.tool_use_id].index,name:p[y.tool_use_id].name,data:typeof y.content=="string"?y.content:JSON.stringify(y.content)}});r.push({role:A,content:O});}}break;case"assistant":{let q=g.content;if(typeof q=="string")r.push({role:A,content:[{modality:x,value:q}]});else {let O=q.map((y,Se)=>{if(y.type==="text")return {modality:x,value:y.text};{let ne={modality:V,id:y.id,index:Se,name:y.name,arguments:JSON.stringify(y.input)};return p[y.id]=ne,ne}});r.push({role:A,content:O});}}break}});let u=[];return n.tools&&n.tools.forEach(g=>{u.push({type:"function",definition:{schema:{name:g.name,description:g.description||"",parameters:g.input_schema}}});}),{modelName:s,config:i,messages:r,tools:u.length>0?u:void 0}}transformConfig(e,o,n){let s=e.toolChoice,d=C({},e);delete d.toolChoice;let i=this.modelSchema.config.schema.safeParse(d);if(!i.success)throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:i.error});let r=i.data;s!==void 0&&(r.toolChoice=s),Object.keys(r).forEach(u=>{if(!(u in this.modelSchema.config.def))throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${u}',
9
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let p=Object.keys(r).reduce((u,g)=>{let A=this.modelSchema.config.def[g],q=A.param,O=r[g];return q==="max_tokens"&&A.type==="range"&&O===0?u[q]=A.max:u[q]=O,u},{});if(!p.max_tokens){let u=this.modelSchema.config.def.maxTokens;p.max_tokens=u.max;}if("tool_choice"in p&&p.tool_choice!==void 0){let u=p.tool_choice;if(!n||n&&n.length===0)throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(n&&n.length>0){let g=this.modelSchema.config.def.toolChoice;if(g.choices.includes(u))p.tool_choice={type:u};else if(n.map(A=>A.definition.schema.name).includes(u))p.tool_choice={type:"tool",name:u};else throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${u}' is not part of provided 'tools' names or
10
- one of [${g.choices.join(", ")}]`)})}}return p}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let o=e.map(i=>{let r=we().safeParse(i);if(!r.success)throw new _({info:"Invalid messages",cause:r.error});return r.data});o.forEach(i=>{i.content.forEach(r=>{if(!this.modelSchema.modalities.includes(r.modality))throw new _({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${r.modality}',
11
- available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(i=>{if(!Object.keys(this.modelSchema.roles).includes(i.role))throw new _({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${i.role}',
12
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let n="",s=[];if(o.forEach(i=>{switch(i.role){case Z:i.content.forEach(r=>{if(r.modality===x)n+=r.value;else throw new _({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${i.role}' cannot have content with modality : '${r.modality}'`)})});break;case P:{let r=[];i.content.forEach(p=>{if(p.modality===x)r.push({type:"text",text:p.value});else if(p.modality===V)r.push({type:"tool_use",id:p.id,name:p.name,input:JSON.parse(p.arguments)});else throw new _({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${i.role}' cannot have content with modality : '${p.modality}'`)})}),s.push({role:this.modelSchema.roles[i.role],content:r});}break;case z:{let r=[];i.content.forEach(p=>{if(p.modality===x)r.push({type:"text",text:p.value});else if(p.modality===D){if(p.value.type==="base64")r.push({type:"image",source:{type:"base64",media_type:`image/${p.value.media_type}`,data:p.value.base64}});else if(p.value.type==="url")throw new _({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${p.value.type}'`)})}else throw new _({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${i.role}' cannot have content with modality : '${p.modality}'`)})}),s.push({role:this.modelSchema.roles[i.role],content:r});}break;case Q:{let r=[];i.content.forEach(p=>{if(p.modality===F)r.push({type:"tool_result",tool_use_id:p.id,content:p.data});else throw new _({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${i.role}' cannot have content with modality : '${p.modality}'`)})}),s.push({role:this.modelSchema.roles[i.role],content:r});}break;default:throw new _({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${i.role}' is not supported,
13
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),s[0].role!==this.modelSchema.roles[z])throw new _({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let d=i=>i===this.modelSchema.roles[z]?this.modelSchema.roles[P]:this.modelSchema.roles[z];for(let i=1;i<s.length;i++)if(s[i].role!==d(s[i-1].role))throw new _({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires messages to alternate between user and assistant`)});return {system:n,messages:s}}transformTools(e){if(!this.modelSchema.modalities.includes(V))throw new Ue({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${V}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(s=>{let d=Ht().safeParse(s);if(!d.success)throw new Ue({info:"Invalid tools",cause:d.error});return d.data}).map(s=>({name:s.definition.schema.name,description:s.definition.schema.description,input_schema:s.definition.schema.parameters}))}}getCompleteChatUrl(e,o,n){return k(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,n){return k(this,null,function*(){let s=this.getDefaultHeaders();return n&&n.length>0&&(s=Re(C({},s),{"anthropic-beta":"tools-2024-05-16"})),new Promise(d=>{d(s);})})}getCompleteChatData(e,o,n){return k(this,null,function*(){let s=this.transformConfig(e,o,n),d=this.transformMessages(o);if(d.messages&&d.messages.length===0)throw new _({info:"Messages are required",cause:new Error("Messages are required")});let i=n?this.transformTools(n):{};return new Promise(r=>{r(C(C(C(C({},this.getDefaultParams()),s),d),i));})})}transformCompleteChatResponse(e){let o=Uo.safeParse(e);if(o.success){let n=o.data,d=n.content.map((p,u)=>{if(p.type==="text")return zt(p.text);if(p.type==="tool_use")return $t(u,p.id,p.name,JSON.stringify(p.input))}),i=[{role:P,content:d}],r={promptTokens:n.usage.input_tokens,completionTokens:n.usage.output_tokens,totalTokens:n.usage.input_tokens+n.usage.output_tokens};return {messages:i,usage:r,logProbs:[]}}throw new $({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,n){return k(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,o,n){let s=this.getDefaultHeaders();return n&&n.length>0&&(s=Re(C({},s),{"anthropic-beta":"tools-2024-05-16"})),new Promise(d=>{d(s);})}getStreamChatData(e,o,n){return k(this,null,function*(){let s=this.transformConfig(e,o,n),d=this.transformMessages(o);if(d.messages&&d.messages.length===0)throw new _({info:"Messages are required",cause:new Error("Messages are required")});let i=n?this.transformTools(n):{};return new Promise(r=>{r(C(C(C(C({stream:!0},this.getDefaultParams()),s),d),i));})})}transformStreamChatResponseChunk(e,o){return ve(this,null,function*(){let n=(o+e).split(`
14
- `).filter(s=>s.trim()!=="");for(let s of n)if(s.startsWith("data: {")&&s.endsWith("}")){let d;try{d=JSON.parse(s.substring(6));}catch(i){throw new $({info:`Malformed JSON received in stream : ${d}`,cause:i})}if("type"in d){if(d.type==="message_stop")return;if(d.type==="message_start"){let i=Vo.safeParse(d);if(i.success){let r=i.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:r.message.usage.input_tokens,completionTokens:r.message.usage.output_tokens,totalTokens:r.message.usage.input_tokens+r.message.usage.output_tokens}},buffer:o};}else throw new $({info:"Invalid response from model",cause:i.error})}else if(d.type==="message_delta"){let i=No.safeParse(d);if(i.success){let r=i.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:0,completionTokens:r.usage.output_tokens,totalTokens:r.usage.output_tokens}},buffer:o};}else throw new $({info:"Invalid response from model",cause:i.error})}else if(d.type==="content_block_start"){let i=zo.safeParse(d);if(i.success){let r=i.data,p=[];r.content_block.type==="text"?p.push(Pe(P,r.content_block.text)):r.content_block.type==="tool_use"&&p.push(Ie(P,r.index,r.content_block.id,r.content_block.name,"")),yield {partialResponse:{partialMessages:p},buffer:o};}else throw new $({info:"Invalid response from model",cause:i.error})}else if(d.type==="content_block_delta"){let i=$o.safeParse(d);if(i.success){let r=i.data,p=[];r.delta.type==="text_delta"?p.push(Pe(P,r.delta.text)):r.delta.type==="input_json_delta"&&p.push(Ie(P,r.index,"","",r.delta.partial_json)),yield {partialResponse:{partialMessages:p},buffer:o};}else throw new $({info:"Invalid response from model",cause:i.error})}}else throw new $({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property,
15
- received : ${JSON.stringify(d)}`)})}})}transformProxyStreamChatResponseChunk(e,o,n,s,d){return ve(this,null,function*(){yield*wt(this.transformStreamChatResponseChunk(e,o));})}getProxyStreamChatUrl(e,o,n){return k(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,o,n){return k(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,o,n){return k(this,null,function*(){if(!o)return {};let s=C({},o);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(e,o,n){return k(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,o,n)})}};var Xe="claude-3-5-sonnet-20240620",Ra="Most intelligent model. Highest level of intelligence and capability.",et=M(E,v).parse({name:Xe,description:Ra,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),Ro=T,le=class extends b{constructor(e){super(et,e);}};var tt="claude-3-5-sonnet-20241022",va="Most intelligent model. Highest level of intelligence and capability.",ot=M(E,v).parse({name:tt,description:va,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),vo=T,de=class extends b{constructor(e){super(ot,e);}};var nt="claude-3-5-sonnet-latest",Oa="Most intelligent model. Highest level of intelligence and capability.",at=M(E,v).parse({name:nt,description:Oa,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),Oo=T,pe=class extends b{constructor(e){super(at,e);}};var st="claude-3-haiku-20240307",xa="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",it=M(E,v).parse({name:st,description:xa,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:R,config:{def:h.base(4096,4).def,schema:h.base(4096,4).schema}}),xo=T,me=class extends b{constructor(e){super(it,e);}};var rt="claude-3-5-haiku-20241022",Aa="Our fastest model with intelligence at blazing speeds.",lt=M(E,v).parse({name:rt,description:Aa,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),Ao=T,ce=class extends b{constructor(e){super(lt,e);}};var dt="claude-3-5-haiku-latest",ka="Our fastest model with intelligence at blazing speeds.",pt=M(E,v).parse({name:dt,description:ka,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),ko=T,ue=class extends b{constructor(e){super(pt,e);}};var mt="claude-3-opus-20240229",_a="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",ct=M(E,v).parse({name:mt,description:_a,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:R,config:{def:h.base(4096,4).def,schema:h.base(4096,4).schema}}),_o=T,he=class extends b{constructor(e){super(ct,e);}};var ut="claude-3-sonnet-20240229",wa="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",ht=M(E,v).parse({name:ut,description:wa,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:R,config:{def:h.base(4096,4).def,schema:h.base(4096,4).schema}}),wo=T,ge=class extends b{constructor(e){super(ht,e);}};var j=[K],B=zod.z.enum([K]);var Ko=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)),Go=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 I=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),w=class{constructor(e,o){this.version="v1";let n=I.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Y(J.embeddingBaseUrl),this.getEmbeddingsUrl=Y(n.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getTokenCount(e){return e.requests.reduce((o,n)=>o+n.length,0)}getRetryDelay(e){return {shouldRetry:!0,delayMs:0}}transformModelRequest(e){let o=Go.safeParse(e);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let n=o.data,s=n.model,d={encodingFormat:n.encoding_format,inputType:n.input_type,truncation:n.truncation},i=se().parse(re(d)),r;return typeof n.input=="string"?r={modality:K,requests:[n.input]}:r={modality:K,requests:n.input},{modelName:s,config:i,embeddingRequests:r}}transformConfig(e,o){let n=this.modelSchema.config.schema.safeParse(e);if(!n.success)throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let s=n.data;return Object.keys(s).forEach(i=>{if(!this.modelSchema.config.def[i])throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${i}',
16
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,r)=>{let u=this.modelSchema.config.def[r].param,g=s[r];return i[u]=g,i},{})}transformEmbeddingRequests(e){let o=Kt().safeParse(e);if(!o.success)throw new Ve({info:"Invalid embedding requests",cause:o.error});if(o.data.requests.length>128)throw new Ve({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:o.data.requests}}getGetEmbeddingsUrl(e,o){return k(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return k(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return k(this,null,function*(){return new Promise(n=>{n(C(C(C({},this.getDefaultParams()),this.transformConfig(e,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o,n=Ko.safeParse(e);if(n.success){let s=n.data;o=typeof s.data[0].embedding=="string"?je:Le;let d=s.data.map(i=>typeof i.embedding=="string"?{index:i.index,embedding:i.embedding}:{index:i.index,embedding:i.embedding});return {encodingFormat:o,embeddings:d,usage:{totalTokens:s.usage.total_tokens}}}throw new $({info:"Invalid response from model",cause:n.error})}};var gt="voyage-code-2",Ia="Optimized for code retrieval.",yt=L(B).parse({name:gt,description:Ia,modalities:j,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:f.base().def,schema:f.base().schema}}),qo=I,ye=class extends w{constructor(e){super(yt,e);}};var ft="voyage-law-2",La="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",bt=L(B).parse({name:ft,description:La,modalities:j,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:f.base().def,schema:f.base().schema}}),Po=I,fe=class extends w{constructor(e){super(bt,e);}};var Ct="voyage-multilingual-2",ja="Optimized for multilingual retrieval and RAG.",Tt=L(B).parse({name:Ct,description:ja,modalities:j,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),Io=I,be=class extends w{constructor(e){super(Tt,e);}};var Mt="voyage-finance-2",Ba="Optimized for finance retrieval and RAG.",Et=L(B).parse({name:Mt,description:Ba,modalities:j,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),Lo=I,Ce=class extends w{constructor(e){super(Et,e);}};var St="voyage-3-lite",Ua="Optimized for latency and cost.",Rt=L(B).parse({name:St,description:Ua,modalities:j,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),jo=I,Te=class extends w{constructor(e){super(Rt,e);}};var vt="voyage-3",Va="Optimized for quality.",Ot=L(B).parse({name:vt,description:Va,modalities:j,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),Bo=I,Me=class extends w{constructor(e){super(Ot,e);}};
5
+ var Jo=Object.defineProperty,Wo=Object.defineProperties;var Zo=Object.getOwnPropertyDescriptors;var At=Object.getOwnPropertySymbols;var Yo=Object.prototype.hasOwnProperty,Qo=Object.prototype.propertyIsEnumerable;var ae=(a,e)=>(e=Symbol[a])?e:Symbol.for("Symbol."+a),Xo=a=>{throw TypeError(a)};var kt=(a,e,o)=>e in a?Jo(a,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[e]=o,C=(a,e)=>{for(var o in e||(e={}))Yo.call(e,o)&&kt(a,o,e[o]);if(At)for(var o of At(e))Qo.call(e,o)&&kt(a,o,e[o]);return a},Re=(a,e)=>Wo(a,Zo(e));var k=(a,e,o)=>new Promise((n,i)=>{var r=d=>{try{s(o.next(d));}catch(c){i(c);}},p=d=>{try{s(o.throw(d));}catch(c){i(c);}},s=d=>d.done?n(d.value):Promise.resolve(d.value).then(r,p);s((o=o.apply(a,e)).next());}),_t=function(a,e){this[0]=a,this[1]=e;},ve=(a,e,o)=>{var n=(p,s,d,c)=>{try{var g=o[p](s),A=(s=g.value)instanceof _t,q=g.done;Promise.resolve(A?s[0]:s).then(O=>A?n(p==="return"?p:"next",s[1]?{done:O.done,value:O.value}:O,d,c):d({value:O,done:q})).catch(O=>n("throw",O,d,c));}catch(O){c(O);}},i=p=>r[p]=s=>new Promise((d,c)=>n(p,s,d,c)),r={};return o=o.apply(a,e),r[ae("asyncIterator")]=()=>r,i("next"),i("throw"),i("return"),r},wt=a=>{var e=a[ae("asyncIterator")],o=!1,n,i={};return e==null?(e=a[ae("iterator")](),n=r=>i[r]=p=>e[r](p)):(e=e.call(a),n=r=>i[r]=p=>{if(o){if(o=!1,r==="throw")throw p;return p}return o=!0,{done:!1,value:new _t(new Promise(s=>{var d=e[r](p);d instanceof Object||Xo("Object expected"),s(d);}),1)}}),i[ae("iterator")]=()=>i,n("next"),"throw"in e?n("throw"):i.throw=r=>{throw r},"return"in e&&n("return"),i};var en=a=>{let e=new WeakSet;return JSON.stringify(a,(o,n)=>{if(typeof n=="object"&&n!==null){if(e.has(n))return;e.add(n);}return n})},tn=a=>a==null?"unknown error":typeof a=="string"?a:a instanceof Error?a.message:en(a),Oe="GatewayBaseError",F=class Lt extends Error{constructor({info:e,cause:o},n){super(`[${n!=null?n:Oe}]: ${e}
6
+ Message: ${tn(o)}`),this.name=Oe,this.info=e,this.cause=o,this.name=n!=null?n:Oe,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(e){return e instanceof Lt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Z="system",z="user",P="assistant",Q="tool",on=[Z,z,P,Q],xe=zod.z.enum(on),nn=[P],an=zod.z.enum(nn),H="image",Ae="base64",sn=["png","jpeg","webp","gif"],rn=zod.z.object({type:zod.z.literal(Ae),base64:zod.z.string(),media_type:zod.z.enum(sn)}),ln="url",dn=zod.z.object({type:zod.z.literal(ln),url:zod.z.string()}),pn=zod.z.discriminatedUnion("type",[rn,dn]),mn=["low","medium","high","auto"],cn=zod.z.enum(mn),un=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(H),detail:cn,value:pn,metadata:a}),x="text",jt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(x),value:zod.z.string(),metadata:a}),ke="partial-text",Bt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ke),value:zod.z.string(),metadata:a}),V="tool-call",Ut=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(V),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:a}),_e="partial-tool-call",Vt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_e),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:a}),D="tool-response",hn=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(D),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:a}),gn=[x,H,V,D],Nt=zod.z.enum(gn),yn=(a=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[jt(a),un(e),Ut(o),hn(n)]),fn=[ke,_e];zod.z.enum(fn);var bn=(a=zod.z.undefined(),e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Bt(a),Vt(e)]);var we=(a=xe,e=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined(),i=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:a,content:zod.z.array(yn(e,o,n,i)),metadata:r}),qe=(a=an,e=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.object({role:a,partialContent:bn(e,o),metadata:n}),zt=a=>jt().parse({modality:x,value:a}),$t=(a,e,o,n)=>Ut().parse({modality:V,index:a,id:e,name:o,arguments:n});var Pe=(a,e)=>qe().parse({role:a,partialContent:Bt().parse({modality:ke,value:e})}),Ie=(a,e,o,n,i)=>qe().parse({role:a,partialContent:Vt().parse({modality:_e,index:e,id:o,name:n,arguments:i})});var se=(a=zod.z.record(zod.z.string(),zod.z.any()).optional())=>a,Cn=["object","array","number","string","boolean","enum"],qt=zod.z.enum(Cn),Tn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([qt,zod.z.array(zod.z.union([qt,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()}),Mn=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(Tn),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:Mn}).optional();var En="function";var Sn=zod.z.enum(["object","array","number","string","boolean","null"]),Rn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Sn.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()});zod.z.object({type:zod.z.enum(["object"]),title:zod.z.string().optional(),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Rn).optional(),required:zod.z.array(zod.z.string()).optional()});var vn=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),parameters:zod.z.any(),strict:zod.z.boolean().optional()});var On=zod.z.enum(["function"]),xn=zod.z.object({type:On,definition:zod.z.object({schema:vn})}),An=[En];zod.z.enum(An);var Ft=(a=zod.z.undefined())=>zod.z.discriminatedUnion("type",[xn.extend({metadata:a})]),K="text",Ht="token",kn=[K,Ht],Dt=zod.z.enum(kn),_n=zod.z.array(zod.z.string().min(1)),wn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Kt=(a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(K),metadata:a,requests:_n}),zod.z.object({modality:zod.z.literal(Ht),metadata:a,requests:wn})]),Le="float",qn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),je="base64",Pn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Pt=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Le),embeddings:zod.z.array(qn),usage:Pt.optional()}),zod.z.object({encodingFormat:zod.z.literal(je),embeddings:zod.z.array(Pn),usage:Pt.optional()})]);var Gt=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),It=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),In=It.extend({topLogProbs:zod.z.array(It)}),Jt=zod.z.array(In);zod.z.object({messages:zod.z.array(we()),usage:Gt.optional(),logProbs:Jt.optional()});zod.z.object({partialMessages:zod.z.array(qe()),usage:Gt.optional(),logProbs:Jt.optional()});var Ln=Object.defineProperty,Wt=Object.getOwnPropertySymbols,jn=Object.prototype.hasOwnProperty,Bn=Object.prototype.propertyIsEnumerable,Zt=(a,e,o)=>e in a?Ln(a,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[e]=o,ie=(a,e)=>{for(var o in e||(e={}))jn.call(e,o)&&Zt(a,o,e[o]);if(Wt)for(var o of Wt(e))Bn.call(e,o)&&Zt(a,o,e[o]);return a},Yt="ProviderError",Be=class ao extends F{constructor({info:e,cause:o}){super({info:e,cause:o},Yt),this.name=Yt,this.info=e,this.cause=o;}static isProviderError(e){return e instanceof ao}};var Qt="ModelResponseError",$=class so extends F{constructor({info:e,cause:o}){super({info:e,cause:o},Qt),this.name=Qt,this.cause=o,this.info=e;}static isModelResponseError(e){return e instanceof so}},Xt="InvalidModelRequestError",X=class io extends F{constructor({info:e,cause:o}){super({info:e,cause:o},Xt),this.name=Xt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(e){return e instanceof io}},eo="InvalidConfigError",G=class ro extends F{constructor({info:e,cause:o}){super({info:e,cause:o},eo),this.name=eo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(e){return e instanceof ro}},to="InvalidMessagesError",_=class lo extends F{constructor({info:e,cause:o}){super({info:e,cause:o},to),this.name=to,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(e){return e instanceof lo}},oo="InvalidToolsError",Ue=class po extends F{constructor({info:e,cause:o}){super({info:e,cause:o},oo),this.name=oo,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(e){return e instanceof po}},no="InvalidEmbeddingRequestsError",Ve=class mo extends F{constructor({info:e,cause:o}){super({info:e,cause:o},no),this.name=no,this.info=e,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(e){return e instanceof mo}},Ne="multi-string",co=zod.z.object({type:zod.z.literal(Ne),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),Un=a=>zod.z.array(zod.z.string()).max(a).default([]).optional(),uo=a=>({def:co.parse(ie({type:Ne},a)),schema:Un(a.max)}),ho="object-schema",Vn=zod.z.object({type:zod.z.literal(ho),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var ze="range",go=zod.z.object({type:zod.z.literal(ze),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),Nn=(a,e,o,n)=>zod.z.number().min(a).max(e).step(o).default(n).optional(),ee=a=>({def:go.parse(ie({type:ze},a)),schema:Nn(a.min,a.max,a.step,a.default)}),$e="select-boolean",yo=zod.z.object({type:zod.z.literal($e),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),zn=a=>zod.z.boolean().nullable().default(a).optional(),fo=a=>({def:yo.parse(ie({type:$e},a)),schema:zn(a.default)}),Fe="select-string",bo=zod.z.object({type:zod.z.literal(Fe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string(),choices:zod.z.array(zod.z.string())}),$n=(a,e)=>zod.z.enum(e).nullable().default(a).optional(),te=a=>({def:bo.parse(ie({type:Fe},a)),schema:$n(a.default,a.choices)}),Fn=[ze,Ne,Fe,ho,$e];zod.z.enum(Fn);var Co=zod.z.discriminatedUnion("type",[go,co,bo,yo,Vn]),M=(a=xe,e=Nt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(a,zod.z.string().min(1).optional()),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Co),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var n,i;let r=Object.keys(o.def),p=Object.keys((i=(n=o.schema)==null?void 0:n.shape)!=null?i:{});return r.every(s=>p.includes(s))&&p.every(s=>r.includes(s))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),L=(a=Dt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(a).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Co),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(e=>{var o,n;let i=Object.keys(e.def),r=Object.keys((n=(o=e.schema)==null?void 0:o.shape)!=null?n:{});return i.every(p=>r.includes(p))&&r.every(p=>i.includes(p))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var Hn={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},Dn={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},Kn=a=>({type:"multi",title:"Stop sequence",description:`Enter up to ${a} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Gn={type:"range",title:"Top A",description:"Considers only the top tokens that have 'sufficiently high' probabilities relative to the most likely token, functioning like a dynamic Top-P. A lower Top-A value narrows down the token choices based on the highest probability token, while a higher Top-A value refines the filtering without necessarily impacting the creativity of the output."},Jn={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},Wn={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},Zn={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},Yn={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},Qn={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},Xn={type:"range",title:"Seed",description:"When seed is fixed to a specific value, the model makes a best effort to provide the same response for repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such as the temperature, can cause variations in the response even when you use the same seed value. By default, a random seed value is used."},ea={type:"range",title:"Repetition penalty",description:"Reduces the likelihood of repeating tokens from the input. Increasing this value makes the model less prone to repetition, but setting it too high may lead to less coherent output, often resulting in run-on sentences missing smaller words. The token penalty is scaled according to the original token's probability."},ta={type:"boolean",title:"Log probs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned."},oa={type:"range",title:"Top log probs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used."},na={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},aa={type:"select",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt."},sa={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},ia={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},N={TEMPERATURE:Hn,MAX_TOKENS:Dn,STOP:Kn,TOP_A:Gn,TOP_P:Jn,TOP_K:Wn,MIN_P:Zn,FREQUENCY_PENALTY:Yn,PRESENCE_PENALTY:Qn,REPETITION_PENALTY:ea,SEED:Xn,LOG_PROBS:ta,TOP_LOG_PROBS:oa,ECHO:na,RESPONSE_FORMAT:aa,RESPONSE_FORMAT_WITH_SCHEMA:sa,RESPONSE_SCHEMA:ia};var re=a=>Object.fromEntries(Object.entries(a).filter(([e,o])=>o!=null));var Y=a=>a==null?void 0:a.replace(/\/$/,"");var He=ee({param:"temperature",title:N.TEMPERATURE.title,description:N.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),De=a=>ee({param:"max_tokens",title:N.MAX_TOKENS.title,description:N.MAX_TOKENS.description,min:0,max:a,step:1,default:0}),Ke=a=>uo({param:"stop_sequences",title:N.STOP(a).title,description:N.STOP(a).description,max:a}),Ge=ee({param:"top_p",title:N.TOP_P.title,description:N.TOP_P.description,min:0,max:1,step:.01,default:1}),Je=ee({param:"top_k",title:N.TOP_K.title,description:N.TOP_K.description,min:0,max:1,step:.01,default:1}),We=te({param:"tool_choice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'any' means the model will call any of the provided tools. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","any"]});var To=(a,e)=>zod.z.object({temperature:He.schema,maxTokens:De(a).schema,stop:Ke(e).schema,topP:Ge.schema,topK:Je.schema,toolChoice:We.schema}),Mo=(a,e)=>({temperature:He.def,maxTokens:De(a).def,stop:Ke(e).def,topP:Ge.def,topK:Je.def,toolChoice:We.def});var Ze=te({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"",choices:["base64",""]}),Ye=te({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:"",choices:["query","document",""]}),Qe=fo({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0});var Eo=()=>zod.z.object({encodingFormat:Ze.schema,inputType:Ye.schema,truncation:Qe.schema}),So=()=>({encodingFormat:Ze.def,inputType:Ye.def,truncation:Qe.def});var h={base:(a,e)=>({def:Mo(a,e),schema:To(a,e)})},f={base:()=>({def:So(),schema:Eo()})};var da="anthropic",J=class{constructor(){this.version="v1";this.name=da;this.chatModelFactories={[st]:{model:me,modelOptions:xo,modelSchema:it},[ut]:{model:ge,modelOptions:wo,modelSchema:ht},[mt]:{model:he,modelOptions:_o,modelSchema:ct},[Xe]:{model:le,modelOptions:Ro,modelSchema:et},[tt]:{model:de,modelOptions:vo,modelSchema:ot},[rt]:{model:ce,modelOptions:Ao,modelSchema:lt},[nt]:{model:pe,modelOptions:Oo,modelSchema:at},[dt]:{model:ue,modelOptions:ko,modelSchema:pt}};this.embeddingModelFactories={[vt]:{model:Me,modelOptions:Bo,modelSchema:Ot},[St]:{model:Te,modelOptions:jo,modelSchema:Rt},[gt]:{model:ye,modelOptions:qo,modelSchema:yt},[ft]:{model:fe,modelOptions:Po,modelSchema:bt},[Ct]:{model:be,modelOptions:Io,modelSchema:Tt},[Mt]:{model:Ce,modelOptions:Lo,modelSchema:Et}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}chatModel(e){let o=e.modelName;if(!(o in this.chatModelFactories))throw new Be({info:`Anthropic chat model: ${o} not found`,cause:new Error(`Anthropic chat model: ${o} not found, available chat models:
7
+ ${this.chatModelLiterals().join(", ")}`)});let n=this.chatModelFactories[o].model,i=this.chatModelFactories[o].modelOptions.parse(e);return new n(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,o)=>(e[o]=this.embeddingModelFactories[o].modelSchema,e),{})}embeddingModel(e){let o=e.modelName;if(!(o in this.embeddingModelFactories))throw new Be({info:`Anthropic embedding model: ${o} not found`,cause:new Error(`Anthropic embedding model: ${o} not found, available embedding models:
8
+ ${this.embeddingModelLiterals().join(", ")}`)});let n=this.embeddingModelFactories[o].model,i=this.embeddingModelFactories[o].modelOptions.parse(e);return new n(i)}};J.chatBaseUrl="https://api.anthropic.com/v1",J.embeddingBaseUrl="https://api.voyageai.com/v1";var E=zod.z.enum([Z,z,P,Q]),S={system:Z,user:z,assistant:P,tool:z};var R=[x,H,V,D],v=zod.z.enum([x,H,V,D]);var ca=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ua=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),Uo=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[ca,ua])),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()})}),Vo=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()})})}),No=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()})}),ha=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ga=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),zo=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[ha,ga])}),ya=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),fa=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),$o=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[ya,fa])});var ba=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),Ca=zod.z.object({type:zod.z.enum(["auto","any"])}),Ta=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")}),Fo=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()})}),Ps=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())}),Ho=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,Fo])).min(1))}),Ma=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xt,Fo,Ho])).min(1))}),Ea=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xt,Ho])).min(1))}),Sa=zod.z.union([Ma,Ea]),Do=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Sa).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([Ca,Ta]).optional(),tools:zod.z.array(ba).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()});var T=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),b=class{constructor(e,o){this.version="v1";let n=T.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Y(J.chatBaseUrl),this.completeChatUrl=Y(n.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=Y(n.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(e){let o=0,n=!0;return e["x-should-retry"]&&(n=e["x-should-retry"].toLowerCase()!=="false"),e["retry-after"]&&(o=parseInt(e["retry-after"])*1e3),{shouldRetry:n,delayMs:o}}getTokenCount(e){return e.reduce((o,n)=>o+n.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformModelRequest(e){let o=Do.safeParse(e);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let n=o.data,i=n.model;if(n.tool_choice&&(!n.tools||n.tools.length===0))throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let r={};n.tool_choice&&(n.tool_choice.type==="tool"?r.toolChoice=n.tool_choice.name:r.toolChoice=n.tool_choice.type),r.maxTokens=n.max_tokens,r.temperature=n.temperature,r.topP=n.top_p,r.topK=n.top_k,r.stop=n.stop_sequences;let p=se().parse(re(r)),s=[],d={};n.system&&s.push({role:Z,content:[{modality:x,value:n.system}]}),n.messages.forEach(g=>{let A=g.role;switch(A){case"user":{let q=g.content;if(typeof q=="string")s.push({role:A,content:[{modality:x,value:q}]});else {let O=q.map(y=>{if(y.type==="text")return {modality:x,value:y.text};if(y.type==="image"){let Se="auto",ne=y.source.media_type.split("/")[1];return {modality:H,detail:Se,value:{type:Ae,media_type:ne,base64:y.source.data}}}else return {modality:D,id:y.tool_use_id,index:d[y.tool_use_id].index,name:d[y.tool_use_id].name,data:typeof y.content=="string"?y.content:JSON.stringify(y.content)}});s.push({role:A,content:O});}}break;case"assistant":{let q=g.content;if(typeof q=="string")s.push({role:A,content:[{modality:x,value:q}]});else {let O=q.map((y,Se)=>{if(y.type==="text")return {modality:x,value:y.text};{let ne={modality:V,id:y.id,index:Se,name:y.name,arguments:JSON.stringify(y.input)};return d[y.id]=ne,ne}});s.push({role:A,content:O});}}break}});let c=[];return n.tools&&n.tools.forEach(g=>{c.push({type:"function",definition:{schema:{name:g.name,description:g.description||"",parameters:g.input_schema}}});}),{modelName:i,config:p,messages:s,tools:c.length>0?c:void 0}}transformConfig(e,o,n){let i=e.toolChoice,r=C({},e);delete r.toolChoice;let p=this.modelSchema.config.schema.safeParse(r);if(!p.success)throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:p.error});let s=p.data;i!==void 0&&(s.toolChoice=i),Object.keys(s).forEach(c=>{if(!(c in this.modelSchema.config.def))throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${c}',
9
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let d=Object.keys(s).reduce((c,g)=>{let A=this.modelSchema.config.def[g],q=A.param,O=s[g];return q==="max_tokens"&&A.type==="range"&&O===0?c[q]=A.max:c[q]=O,c},{});if(!d.max_tokens){let c=this.modelSchema.config.def.maxTokens;d.max_tokens=c.max;}if("tool_choice"in d&&d.tool_choice!==void 0){let c=d.tool_choice;if(!n||n&&n.length===0)throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(n&&n.length>0){let g=this.modelSchema.config.def.toolChoice;if(g.choices.includes(c))d.tool_choice={type:c};else if(n.map(A=>A.definition.schema.name).includes(c))d.tool_choice={type:"tool",name:c};else throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${c}' is not part of provided 'tools' names or
10
+ one of [${g.choices.join(", ")}]`)})}}return d}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let o=s=>{let d=s.match(/^data:image\/[a-zA-Z]+;base64,/);return d?s.substring(d[0].length):s},n=e.map(s=>{let d=we().safeParse(s);if(!d.success)throw new _({info:"Invalid messages",cause:d.error});return d.data});n.forEach(s=>{s.content.forEach(d=>{if(!this.modelSchema.modalities.includes(d.modality))throw new _({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${d.modality}',
11
+ available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),n.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new _({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
12
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let i="",r=[];if(n.forEach(s=>{switch(s.role){case Z:{s.content.forEach(d=>{if(d.modality===x)i+=d.value;else throw new _({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})});break}case P:{let d=[];s.content.forEach(c=>{if(c.modality===x)d.push({type:"text",text:c.value});else if(c.modality===V)d.push({type:"tool_use",id:c.id,name:c.name,input:JSON.parse(c.arguments)});else throw new _({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${c.modality}'`)})}),r.push({role:this.modelSchema.roles[s.role],content:d});break}case z:{let d=[];s.content.forEach(c=>{if(c.modality===x)d.push({type:"text",text:c.value});else if(c.modality===H){if(c.value.type==="base64"){let g=c.value.base64;g=o(g),d.push({type:"image",source:{type:"base64",media_type:`image/${c.value.media_type}`,data:g}});}else if(c.value.type==="url")throw new _({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${c.value.type}'`)})}else throw new _({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${c.modality}'`)})}),r.push({role:this.modelSchema.roles[s.role],content:d});break}case Q:{let d=[];s.content.forEach(c=>{if(c.modality===D)d.push({type:"tool_result",tool_use_id:c.id,content:c.data});else throw new _({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${c.modality}'`)})}),r.push({role:this.modelSchema.roles[s.role],content:d});break}default:throw new _({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
13
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),r[0].role!==this.modelSchema.roles[z])throw new _({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let p=s=>s===this.modelSchema.roles[z]?this.modelSchema.roles[P]:this.modelSchema.roles[z];for(let s=1;s<r.length;s++)if(r[s].role!==p(r[s-1].role))throw new _({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires messages to alternate between user and assistant`)});return {system:i,messages:r}}transformTools(e){if(!this.modelSchema.modalities.includes(V))throw new Ue({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${V}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(i=>{let r=Ft().safeParse(i);if(!r.success)throw new Ue({info:"Invalid tools",cause:r.error});return r.data}).map(i=>({name:i.definition.schema.name,description:i.definition.schema.description,input_schema:i.definition.schema.parameters}))}}getCompleteChatUrl(e,o,n){return k(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,n){return k(this,null,function*(){let i=this.getDefaultHeaders();return n&&n.length>0&&(i=Re(C({},i),{"anthropic-beta":"tools-2024-05-16"})),new Promise(r=>{r(i);})})}getCompleteChatData(e,o,n){return k(this,null,function*(){let i=this.transformConfig(e,o,n),r=this.transformMessages(o);if(r.messages&&r.messages.length===0)throw new _({info:"Messages are required",cause:new Error("Messages are required")});let p=n?this.transformTools(n):{};return new Promise(s=>{s(C(C(C(C({},this.getDefaultParams()),i),r),p));})})}transformCompleteChatResponse(e){let o=Uo.safeParse(e);if(o.success){let n=o.data,r=n.content.map((d,c)=>{if(d.type==="text")return zt(d.text);if(d.type==="tool_use")return $t(c,d.id,d.name,JSON.stringify(d.input))}),p=[{role:P,content:r}],s={promptTokens:n.usage.input_tokens,completionTokens:n.usage.output_tokens,totalTokens:n.usage.input_tokens+n.usage.output_tokens};return {messages:p,usage:s,logProbs:[]}}throw new $({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,n){return k(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(e,o,n){let i=this.getDefaultHeaders();return n&&n.length>0&&(i=Re(C({},i),{"anthropic-beta":"tools-2024-05-16"})),new Promise(r=>{r(i);})}getStreamChatData(e,o,n){return k(this,null,function*(){let i=this.transformConfig(e,o,n),r=this.transformMessages(o);if(r.messages&&r.messages.length===0)throw new _({info:"Messages are required",cause:new Error("Messages are required")});let p=n?this.transformTools(n):{};return new Promise(s=>{s(C(C(C(C({stream:!0},this.getDefaultParams()),i),r),p));})})}transformStreamChatResponseChunk(e,o){return ve(this,null,function*(){let n=(o+e).split(`
14
+ `).filter(i=>i.trim()!=="");for(let i of n)if(i.startsWith("data: {")&&i.endsWith("}")){let r;try{r=JSON.parse(i.substring(6));}catch(p){throw new $({info:`Malformed JSON received in stream : ${r}`,cause:p})}if("type"in r){if(r.type==="message_stop")return;if(r.type==="message_start"){let p=Vo.safeParse(r);if(p.success){let s=p.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:s.message.usage.input_tokens,completionTokens:s.message.usage.output_tokens,totalTokens:s.message.usage.input_tokens+s.message.usage.output_tokens}},buffer:o};}else throw new $({info:"Invalid response from model",cause:p.error})}else if(r.type==="message_delta"){let p=No.safeParse(r);if(p.success){let s=p.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:0,completionTokens:s.usage.output_tokens,totalTokens:s.usage.output_tokens}},buffer:o};}else throw new $({info:"Invalid response from model",cause:p.error})}else if(r.type==="content_block_start"){let p=zo.safeParse(r);if(p.success){let s=p.data,d=[];s.content_block.type==="text"?d.push(Pe(P,s.content_block.text)):s.content_block.type==="tool_use"&&d.push(Ie(P,s.index,s.content_block.id,s.content_block.name,"")),yield {partialResponse:{partialMessages:d},buffer:o};}else throw new $({info:"Invalid response from model",cause:p.error})}else if(r.type==="content_block_delta"){let p=$o.safeParse(r);if(p.success){let s=p.data,d=[];s.delta.type==="text_delta"?d.push(Pe(P,s.delta.text)):s.delta.type==="input_json_delta"&&d.push(Ie(P,s.index,"","",s.delta.partial_json)),yield {partialResponse:{partialMessages:d},buffer:o};}else throw new $({info:"Invalid response from model",cause:p.error})}}else throw new $({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property,
15
+ received : ${JSON.stringify(r)}`)})}})}transformProxyStreamChatResponseChunk(e,o,n,i,r){return ve(this,null,function*(){yield*wt(this.transformStreamChatResponseChunk(e,o));})}getProxyStreamChatUrl(e,o,n){return k(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getProxyCompleteChatUrl(e,o,n){return k(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyCompleteChatHeaders(e,o,n){return k(this,null,function*(){if(!o)return {};let i=C({},o);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(e,o,n){return k(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,o,n)})}};var Xe="claude-3-5-sonnet-20240620",Ra="Most intelligent model. Highest level of intelligence and capability.",et=M(E,v).parse({name:Xe,description:Ra,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),Ro=T,le=class extends b{constructor(e){super(et,e);}};var tt="claude-3-5-sonnet-20241022",va="Most intelligent model. Highest level of intelligence and capability.",ot=M(E,v).parse({name:tt,description:va,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),vo=T,de=class extends b{constructor(e){super(ot,e);}};var nt="claude-3-5-sonnet-latest",Oa="Most intelligent model. Highest level of intelligence and capability.",at=M(E,v).parse({name:nt,description:Oa,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),Oo=T,pe=class extends b{constructor(e){super(at,e);}};var st="claude-3-haiku-20240307",xa="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",it=M(E,v).parse({name:st,description:xa,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:R,config:{def:h.base(4096,4).def,schema:h.base(4096,4).schema}}),xo=T,me=class extends b{constructor(e){super(it,e);}};var rt="claude-3-5-haiku-20241022",Aa="Our fastest model with intelligence at blazing speeds.",lt=M(E,v).parse({name:rt,description:Aa,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),Ao=T,ce=class extends b{constructor(e){super(lt,e);}};var dt="claude-3-5-haiku-latest",ka="Our fastest model with intelligence at blazing speeds.",pt=M(E,v).parse({name:dt,description:ka,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:R,config:{def:h.base(8192,4).def,schema:h.base(8192,4).schema}}),ko=T,ue=class extends b{constructor(e){super(pt,e);}};var mt="claude-3-opus-20240229",_a="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",ct=M(E,v).parse({name:mt,description:_a,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:R,config:{def:h.base(4096,4).def,schema:h.base(4096,4).schema}}),_o=T,he=class extends b{constructor(e){super(ct,e);}};var ut="claude-3-sonnet-20240229",wa="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",ht=M(E,v).parse({name:ut,description:wa,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:R,config:{def:h.base(4096,4).def,schema:h.base(4096,4).schema}}),wo=T,ge=class extends b{constructor(e){super(ht,e);}};var j=[K],B=zod.z.enum([K]);var Ko=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)),Go=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 I=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),w=class{constructor(e,o){this.version="v1";let n=I.parse(o);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Y(J.embeddingBaseUrl),this.getEmbeddingsUrl=Y(n.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getTokenCount(e){return e.requests.reduce((o,n)=>o+n.length,0)}getRetryDelay(e){return {shouldRetry:!0,delayMs:0}}transformModelRequest(e){let o=Go.safeParse(e);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let n=o.data,i=n.model,r={encodingFormat:n.encoding_format,inputType:n.input_type,truncation:n.truncation},p=se().parse(re(r)),s;return typeof n.input=="string"?s={modality:K,requests:[n.input]}:s={modality:K,requests:n.input},{modelName:i,config:p,embeddingRequests:s}}transformConfig(e,o){"inputType"in e&&e.inputType===""&&delete e.inputType,"encodingFormat"in e&&e.encodingFormat===""&&delete e.encodingFormat;let n=this.modelSchema.config.schema.safeParse(e);if(!n.success)throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let i=n.data;return Object.keys(i).forEach(p=>{if(!this.modelSchema.config.def[p])throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${p}',
16
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((p,s)=>{let c=this.modelSchema.config.def[s].param,g=i[s];return p[c]=g,p},{})}transformEmbeddingRequests(e){let o=Kt().safeParse(e);if(!o.success)throw new Ve({info:"Invalid embedding requests",cause:o.error});if(o.data.requests.length>128)throw new Ve({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:o.data.requests}}getGetEmbeddingsUrl(e,o){return k(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return k(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return k(this,null,function*(){return new Promise(n=>{n(C(C(C({},this.getDefaultParams()),this.transformConfig(e,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o,n=Ko.safeParse(e);if(n.success){let i=n.data;o=typeof i.data[0].embedding=="string"?je:Le;let r=i.data.map(p=>typeof p.embedding=="string"?{index:p.index,embedding:p.embedding}:{index:p.index,embedding:p.embedding});return {encodingFormat:o,embeddings:r,usage:{totalTokens:i.usage.total_tokens}}}throw new $({info:"Invalid response from model",cause:n.error})}};var gt="voyage-code-2",Ia="Optimized for code retrieval.",yt=L(B).parse({name:gt,description:Ia,modalities:j,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:f.base().def,schema:f.base().schema}}),qo=I,ye=class extends w{constructor(e){super(yt,e);}};var ft="voyage-law-2",La="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",bt=L(B).parse({name:ft,description:La,modalities:j,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:f.base().def,schema:f.base().schema}}),Po=I,fe=class extends w{constructor(e){super(bt,e);}};var Ct="voyage-multilingual-2",ja="Optimized for multilingual retrieval and RAG.",Tt=L(B).parse({name:Ct,description:ja,modalities:j,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),Io=I,be=class extends w{constructor(e){super(Tt,e);}};var Mt="voyage-finance-2",Ba="Optimized for finance retrieval and RAG.",Et=L(B).parse({name:Mt,description:Ba,modalities:j,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),Lo=I,Ce=class extends w{constructor(e){super(Et,e);}};var St="voyage-3-lite",Ua="Optimized for latency and cost.",Rt=L(B).parse({name:St,description:Ua,modalities:j,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),jo=I,Te=class extends w{constructor(e){super(Rt,e);}};var vt="voyage-3",Va="Optimized for quality.",Ot=L(B).parse({name:vt,description:Va,modalities:j,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:f.base().def,schema:f.base().schema}}),Bo=I,Me=class extends w{constructor(e){super(Ot,e);}};
17
17
 
18
18
  exports.Anthropic = J;
19
19
  exports.AnthropicChatModelConfigs = h;
@@ -28,16 +28,16 @@ exports.AnthropicEmbeddingModelModalitiesEnum = B;
28
28
  exports.AnthropicEmbeddingRequest = Go;
29
29
  exports.AnthropicEmbeddingRequestInput = Pa;
30
30
  exports.AnthropicGetEmbeddingsResponse = Ko;
31
- exports.AnthropicRequest = Fo;
31
+ exports.AnthropicRequest = Do;
32
32
  exports.AnthropicRequestAssistantMessage = Ea;
33
- exports.AnthropicRequestImageContent = Ho;
33
+ exports.AnthropicRequestImageContent = Fo;
34
34
  exports.AnthropicRequestMessage = Sa;
35
35
  exports.AnthropicRequestTextContent = xt;
36
36
  exports.AnthropicRequestTool = ba;
37
37
  exports.AnthropicRequestToolCallContent = Ps;
38
38
  exports.AnthropicRequestToolChoiceEnum = Ca;
39
39
  exports.AnthropicRequestToolChoiceTool = Ta;
40
- exports.AnthropicRequestToolResponseContent = Do;
40
+ exports.AnthropicRequestToolResponseContent = Ho;
41
41
  exports.AnthropicRequestUserMessage = Ma;
42
42
  exports.AnthropicStreamChatContentBlockDeltaResponse = $o;
43
43
  exports.AnthropicStreamChatContentBlockStartResponse = zo;
@@ -110,9 +110,9 @@ exports.VoyageMultilingual2Options = Io;
110
110
  exports.VoyageMultilingual2Schema = Tt;
111
111
  exports.encodingFormat = Ze;
112
112
  exports.inputType = Ye;
113
- exports.maxTokens = Fe;
113
+ exports.maxTokens = De;
114
114
  exports.stop = Ke;
115
- exports.temperature = De;
115
+ exports.temperature = He;
116
116
  exports.toolChoice = We;
117
117
  exports.topK = Je;
118
118
  exports.topP = Ge;