@adaline/bedrock 1.7.2 → 1.8.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 +22 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -5,60 +5,60 @@ var sha256Js = require('@aws-crypto/sha256-js');
|
|
|
5
5
|
var protocolHttp = require('@smithy/protocol-http');
|
|
6
6
|
var signatureV4 = require('@smithy/signature-v4');
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
Message: ${ei(o)}`),this.name=Fe,this.info=n,this.cause=o,this.name=s!=null?s:Fe,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(n){return n instanceof bn}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},ti=zod.z.object({inputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M input tokens"),outputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M output tokens")}).describe("Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier."),ni=zod.z.object({base:ti.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),oi=zod.z.object({minTokens:zod.z.number().int().nonnegative().describe("Inclusive lower token bound for this tier."),maxTokens:zod.z.number().int().nullable().optional().describe("Exclusive upper token bound; `null` means \u221E."),prices:ni.describe("Price categories and rates for this specific token range.")}).refine(t=>t.maxTokens===null||typeof t.maxTokens=="number"&&t.maxTokens>t.minTokens,{message:"maxTokens must be > minTokens (or null for infinite).",path:["maxTokens"]}).describe("A single pricing tier defined by a token range and associated prices.");zod.z.object({modelName:zod.z.string().describe("Model name this schedule applies to."),currency:zod.z.string().default("USD").describe("Currency code (e.g., USD)."),tokenRanges:zod.z.array(oi).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((t,n)=>{let{tokenRanges:o}=t;o[0].minTokens!==0&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let i=1;i<o.length;i++){let l=o[i-1],r=o[i];if(l.maxTokens===null){n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i-1,"maxTokens"],message:"Cannot define any tokenRanges after an infinite tier (maxTokens = null)."});break}r.minTokens!==l.maxTokens&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i,"minTokens"],message:`Tier ${i} minTokens (${r.minTokens}) must equal previous tier's maxTokens (${l.maxTokens}) for contiguity.`}),r.minTokens<l.minTokens&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i,"minTokens"],message:`tokenRanges must be sorted by ascending minTokens. Tier ${i} (${r.minTokens}) starts before Tier ${i-1} (${l.minTokens}).`});}let s=o[o.length-1];o.every(i=>i.maxTokens!==null||i===s)&&s.maxTokens!==null&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",o.length-1,"maxTokens"],message:"The final tier must have maxTokens = null (representing infinity)."});}).describe("Complete pricing schedule for a single chat model, including all its token-based tiers.");var ai="function",ii=zod.z.enum(["object","array","number","string","boolean","null"]),si=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ii.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(si).optional(),required:zod.z.array(zod.z.string()).optional()});var ri=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()}),li=zod.z.enum(["function"]),di=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),ci=zod.z.object({type:zod.z.literal("http"),method:zod.z.enum(["get","post"]),url:zod.z.string().url(),headers:zod.z.record(zod.z.string()).optional(),query:zod.z.record(zod.z.string()).optional(),body:zod.z.record(zod.z.any()).optional(),proxyUrl:zod.z.string().url().optional(),proxyHeaders:zod.z.record(zod.z.string()).optional(),retry:di.optional()}),mi=zod.z.discriminatedUnion("type",[ci]),pi=zod.z.object({type:li,definition:zod.z.object({schema:ri}),apiSettings:mi.optional()}),ui=[ai];zod.z.enum(ui);var hi=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[pi.extend({metadata:t})]),gi=t=>ln().parse({modality:P,value:t}),fi=(t,n,o,s)=>cn().parse({modality:L,index:t,id:n,name:o,arguments:s}),Ht=(t,n)=>le().parse({role:t,partialContent:dn().parse({modality:ot,value:n})}),Ft=(t,n,o,s,i)=>le().parse({role:t,partialContent:mn().parse({modality:at,index:n,id:o,name:s,arguments:i})}),yi=(t,n)=>tt().parse({modality:J,value:{type:be,thinking:t,signature:n}}),bi=t=>tt().parse({modality:J,value:{type:et,data:t}}),ze=(t,n,o)=>le().parse({role:t,partialContent:nt().parse({modality:ye,value:{type:be,thinking:n,signature:o}})}),ki=(t,n)=>le().parse({role:t,partialContent:nt().parse({modality:ye,value:{type:et,data:n}})}),Ci=Object.defineProperty,zt=Object.getOwnPropertySymbols,vi=Object.prototype.hasOwnProperty,Ti=Object.prototype.propertyIsEnumerable,Kt=(t,n,o)=>n in t?Ci(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o,ke=(t,n)=>{for(var o in n||(n={}))vi.call(n,o)&&Kt(t,o,n[o]);if(zt)for(var o of zt(n))Ti.call(n,o)&&Kt(t,o,n[o]);return t},Vt="ProviderError",Jt=class kn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Vt),this.name=Vt,this.info=n,this.cause=o;}static isProviderError(n){return n instanceof kn}},Gt="ModelResponseError",H=class Cn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Gt),this.name=Gt,this.cause=o,this.info=n;}static isModelResponseError(n){return n instanceof Cn}},Zt="InvalidModelRequestError",Ve=class vn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Zt),this.name=Zt,this.cause=o,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(n){return n instanceof vn}},Wt="InvalidConfigError",K=class Tn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Wt),this.name=Wt,this.cause=o,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(n){return n instanceof Tn}},Xt="InvalidMessagesError",I=class Mn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Xt),this.name=Xt,this.cause=o,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(n){return n instanceof Mn}},Yt="InvalidToolsError",Qt=class xn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Yt),this.name=Yt,this.cause=o,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(n){return n instanceof xn}},en="InvalidEmbeddingRequestsError",tn=class Sn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},en),this.name=en,this.info=n,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(n){return n instanceof Sn}},it="multi-string",wn=zod.z.object({type:zod.z.literal(it),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()}),Mi=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),xi=t=>({def:wn.parse(ke({type:it},t)),schema:Mi(t.max)}),On="object-schema",Si=zod.z.object({type:zod.z.literal(On),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),st="range",Pn=zod.z.object({type:zod.z.literal(st),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()}),wi=(t,n,o,s)=>zod.z.number().min(t).max(n).step(o).default(s).optional(),de=t=>({def:Pn.parse(ke({type:st},t)),schema:wi(t.min,t.max,t.step,t.default)}),rt="select-boolean",Rn=zod.z.object({type:zod.z.literal(rt),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()}),Oi=t=>zod.z.boolean().nullable().default(t).optional(),jn=t=>({def:Rn.parse(ke({type:rt},t)),schema:Oi(t.default)}),lt="select-string",En=zod.z.object({type:zod.z.literal(lt),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())}),Pi=(t,n)=>zod.z.enum(n).nullable().default(t).optional(),dt=t=>({def:En.parse(ke({type:lt},t)),schema:Pi(t.default,t.choices)}),Ri=[st,it,lt,On,rt];zod.z.enum(Ri);var _n=zod.z.discriminatedUnion("type",[Pn,wn,En,Rn,Si]),F=(t=an,n=Na)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(n).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),maxReasoningTokens:zod.z.number().int().positive().min(1).optional(),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),_n),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var s,i;let l=Object.keys(o.def),r=Object.keys((i=(s=o.schema)==null?void 0:s.shape)!=null?i:{});return l.every(d=>r.includes(d))&&r.every(d=>l.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"}),price:zod.z.custom()}),ee=(t=Ja)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).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),_n),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(n=>{var o,s;let i=Object.keys(n.def),l=Object.keys((s=(o=n.schema)==null?void 0:o.shape)!=null?s:{});return i.every(r=>l.includes(r))&&l.every(r=>i.includes(r))},{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 ji={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."},Ei={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."},_i={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},Ii=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Bi={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."},Ai={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."},Ni={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."},Ui={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."},Li={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."},$i={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."},Di={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."},qi={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."},Hi={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."},Fi={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."},zi={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Ki={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."},Vi={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."},Ji={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."},A={TEMPERATURE:ji,MAX_TOKENS:Ei,STOP:Ii,TOP_A:Bi,TOP_P:Ai,TOP_K:Ni,MIN_P:Ui,FREQUENCY_PENALTY:Li,PRESENCE_PENALTY:$i,REPETITION_PENALTY:qi,SEED:Di,LOG_PROBS:Hi,TOP_LOG_PROBS:Fi,ECHO:zi,RESPONSE_FORMAT:Ki,RESPONSE_FORMAT_WITH_SCHEMA:Vi,RESPONSE_SCHEMA:Ji,MAX_REASONING_TOKENS:_i},In=t=>Object.fromEntries(Object.entries(t).filter(([n,o])=>o!=null)),se=t=>t==null?void 0:t.replace(/\/$/,""),Bn=de({param:"temperature",title:A.TEMPERATURE.title,description:A.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),An=t=>de({param:"max_tokens",title:A.MAX_TOKENS.title,description:A.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Nn=t=>xi({param:"stop_sequences",title:A.STOP(t).title,description:A.STOP(t).description,max:t}),Un=de({param:"top_p",title:A.TOP_P.title,description:A.TOP_P.description,min:0,max:1,step:.01,default:1}),Ln=de({param:"top_k",title:A.TOP_K.title,description:A.TOP_K.description,min:0,max:1,step:.01,default:1}),$n=dt({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"]}),Ce=(t,n)=>zod.z.object({temperature:Bn.schema,maxTokens:An(t).schema,stop:Nn(n).schema,topP:Un.schema,topK:Ln.schema,toolChoice:$n.schema}),ve=(t,n)=>({temperature:Bn.def,maxTokens:An(t).def,stop:Nn(n).def,topP:Un.def,topK:Ln.def,toolChoice:$n.def}),Dn=(t,n)=>de({param:"max_reasoning_tokens",title:A.MAX_REASONING_TOKENS.title,description:A.MAX_REASONING_TOKENS.description,min:t,max:n,step:1,default:0}),qn=jn({param:"reasoning_enabled",title:"Reasoning Enabled",description:`Controls whether the model is allowed to think for a longer period of time before generating a response.
|
|
10
|
-
This can be useful for complex tasks that require more time to think.`,default:!1}),
|
|
8
|
+
var ra=Object.defineProperty,la=Object.defineProperties;var da=Object.getOwnPropertyDescriptors;var Bt=Object.getOwnPropertySymbols,ca=Object.getPrototypeOf,ma=Object.prototype.hasOwnProperty,pa=Object.prototype.propertyIsEnumerable,ua=Reflect.get;var me=(t,n)=>(n=Symbol[t])?n:Symbol.for("Symbol."+t),ha=t=>{throw TypeError(t)};var At=(t,n,o)=>n in t?ra(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o,j=(t,n)=>{for(var o in n||(n={}))ma.call(n,o)&&At(t,o,n[o]);if(Bt)for(var o of Bt(n))pa.call(n,o)&&At(t,o,n[o]);return t},z=(t,n)=>la(t,da(n));var pe=(t,n,o)=>ua(ca(t),o,n);var U=(t,n,o)=>new Promise((s,i)=>{var l=m=>{try{d(o.next(m));}catch(p){i(p);}},r=m=>{try{d(o.throw(m));}catch(p){i(p);}},d=m=>m.done?s(m.value):Promise.resolve(m.value).then(l,r);d((o=o.apply(t,n)).next());}),ue=function(t,n){this[0]=t,this[1]=n;},He=(t,n,o)=>{var s=(r,d,m,p)=>{try{var b=o[r](d),v=(d=b.value)instanceof ue,h=b.done;Promise.resolve(v?d[0]:d).then(u=>v?s(r==="return"?r:"next",d[1]?{done:u.done,value:u.value}:u,m,p):m({value:u,done:h})).catch(u=>s("throw",u,m,p));}catch(u){p(u);}},i=r=>l[r]=d=>new Promise((m,p)=>s(r,d,m,p)),l={};return o=o.apply(t,n),l[me("asyncIterator")]=()=>l,i("next"),i("throw"),i("return"),l},he=t=>{var n=t[me("asyncIterator")],o=!1,s,i={};return n==null?(n=t[me("iterator")](),s=l=>i[l]=r=>n[l](r)):(n=n.call(t),s=l=>i[l]=r=>{if(o){if(o=!1,l==="throw")throw r;return r}return o=!0,{done:!1,value:new ue(new Promise(d=>{var m=n[l](r);m instanceof Object||ha("Object expected"),d(m);}),1)}}),i[me("iterator")]=()=>i,s("next"),"throw"in n?s("throw"):i.throw=l=>{throw l},"return"in n&&s("return"),i};var ga=Object.defineProperty,fa=Object.defineProperties,ya=Object.getOwnPropertyDescriptors,Nt=Object.getOwnPropertySymbols,ba=Object.prototype.hasOwnProperty,ka=Object.prototype.propertyIsEnumerable,ge=(t,n)=>(n=Symbol[t])?n:Symbol.for("Symbol."+t),Ca=t=>{throw TypeError(t)},Ut=(t,n,o)=>n in t?ga(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o,O=(t,n)=>{for(var o in n||(n={}))ba.call(n,o)&&Ut(t,o,n[o]);if(Nt)for(var o of Nt(n))ka.call(n,o)&&Ut(t,o,n[o]);return t},nn=(t,n)=>fa(t,ya(n)),B=(t,n,o)=>new Promise((s,i)=>{var l=m=>{try{d(o.next(m));}catch(p){i(p);}},r=m=>{try{d(o.throw(m));}catch(p){i(p);}},d=m=>m.done?s(m.value):Promise.resolve(m.value).then(l,r);d((o=o.apply(t,n)).next());}),on=function(t,n){this[0]=t,this[1]=n;},Lt=(t,n,o)=>{var s=(r,d,m,p)=>{try{var b=o[r](d),v=(d=b.value)instanceof on,h=b.done;Promise.resolve(v?d[0]:d).then(u=>v?s(r==="return"?r:"next",d[1]?{done:u.done,value:u.value}:u,m,p):m({value:u,done:h})).catch(u=>s("throw",u,m,p));}catch(u){p(u);}},i=r=>l[r]=d=>new Promise((m,p)=>s(r,d,m,p)),l={};return o=o.apply(t,n),l[ge("asyncIterator")]=()=>l,i("next"),i("throw"),i("return"),l},va=t=>{var n=t[ge("asyncIterator")],o=!1,s,i={};return n==null?(n=t[ge("iterator")](),s=l=>i[l]=r=>n[l](r)):(n=n.call(t),s=l=>i[l]=r=>{if(o){if(o=!1,l==="throw")throw r;return r}return o=!0,{done:!1,value:new on(new Promise(d=>{var m=n[l](r);m instanceof Object||Ca("Object expected"),d(m);}),1)}}),i[ge("iterator")]=()=>i,s("next"),"throw"in n?s("throw"):i.throw=l=>{throw l},"return"in n&&s("return"),i},re="system",X="user",R="assistant",Qe="tool",Ta=[re,X,R,Qe],an=zod.z.enum(Ta),Ma=[R],xa=zod.z.enum(Ma),V="image",sn="base64",Sa=["png","jpeg","webp","gif"],wa=zod.z.object({type:zod.z.literal(sn),base64:zod.z.string(),mediaType:zod.z.enum(Sa)}),Oa="url",Pa=zod.z.object({type:zod.z.literal(Oa),url:zod.z.string()}),Ra=zod.z.discriminatedUnion("type",[wa,Pa]),ja=["low","medium","high","auto"],Ea=zod.z.enum(ja),_a=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(V),detail:Ea,value:Ra,metadata:t}),rn="pdf",Ia="base64",Ba=zod.z.object({type:zod.z.literal(Ia),base64:zod.z.string()}),Aa="url",Na=zod.z.object({type:zod.z.literal(Aa),url:zod.z.string()}),Ua=zod.z.discriminatedUnion("type",[Ba,Na]),La=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(rn),value:Ua,providerCacheKey:zod.z.string(),metadata:t}),J="reasoning",ye="partial-reasoning",be="thinking",et="redacted",Ke=zod.z.object({type:zod.z.literal(be),thinking:zod.z.string(),signature:zod.z.string()}),ln=zod.z.object({type:zod.z.literal(et),data:zod.z.string()}),$a=zod.z.discriminatedUnion("type",[Ke,ln]),tt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(J),value:$a,metadata:t}),qa=zod.z.object({type:zod.z.literal(be),thinking:Ke.shape.thinking.optional(),signature:Ke.shape.signature.optional()}),Da=zod.z.discriminatedUnion("type",[qa,ln]),nt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ye),value:Da,metadata:t}),P="text",dn=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(P),value:zod.z.string(),metadata:t}),ot="partial-text",cn=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ot),value:zod.z.string(),metadata:t}),L="tool-call",mn=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(L),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),at="partial-tool-call",pn=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(at),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),G="tool-response",Ha=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(G),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:t}),Fa=[P,V,rn,L,G,J],za=zod.z.enum(Fa),Ka=(t=zod.z.undefined(),n=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[dn(t),_a(n),La(o),mn(s),Ha(i),tt(l)]),Va=[ot,at,ye];zod.z.enum(Va);var Ja=(t=zod.z.undefined(),n=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[cn(t),pn(n),nt(o)]),un=(t=an,n=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(Ka(n,o,s,i,r)),metadata:l}),le=(t=xa,n=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:t,partialContent:Ja(n,o,s),metadata:i}),Ga=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),$t=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Za=$t.extend({topLogProbs:zod.z.array($t)}),hn=zod.z.array(Za);zod.z.object({messages:zod.z.array(un()),usage:Ga.optional(),logProbs:hn.optional()});var Wa=zod.z.object({promptTokens:zod.z.number().nonnegative().optional(),completionTokens:zod.z.number().nonnegative().optional(),totalTokens:zod.z.number().nonnegative().optional()});zod.z.object({partialMessages:zod.z.array(le()),usage:Wa.optional(),logProbs:hn.optional()});var gn=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,Ya=["object","array","number","string","boolean","enum"],qt=zod.z.enum(Ya),Xa=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()}),Qa=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(Xa),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:Qa}).optional();var Q="text",fn="token",ei=[Q,fn],ti=zod.z.enum(ei),ni=zod.z.array(zod.z.string().min(1)),oi=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),ai=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(Q),metadata:t,requests:ni}),zod.z.object({modality:zod.z.literal(fn),metadata:t,requests:oi})]),yn="float",ii=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),bn="base64",si=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Dt=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(yn),embeddings:zod.z.array(ii),usage:Dt.optional()}),zod.z.object({encodingFormat:zod.z.literal(bn),embeddings:zod.z.array(si),usage:Dt.optional()})]);var ri=t=>{let n=new WeakSet;return JSON.stringify(t,(o,s)=>{if(typeof s=="object"&&s!==null){if(n.has(s))return;n.add(s);}return s})},li=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:ri(t),Fe="GatewayBaseError",W=class kn extends Error{constructor({info:n,cause:o},s){super(`[${s!=null?s:Fe}]: ${n}
|
|
9
|
+
Message: ${li(o)}`),this.name=Fe,this.info=n,this.cause=o,this.name=s!=null?s:Fe,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(n){return n instanceof kn}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},di=zod.z.object({inputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M input tokens"),outputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M output tokens")}).describe("Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier."),ci=zod.z.object({base:di.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),mi=zod.z.object({minTokens:zod.z.number().int().nonnegative().describe("Inclusive lower token bound for this tier."),maxTokens:zod.z.number().int().nullable().optional().describe("Exclusive upper token bound; `null` means \u221E."),prices:ci.describe("Price categories and rates for this specific token range.")}).refine(t=>t.maxTokens===null||typeof t.maxTokens=="number"&&t.maxTokens>t.minTokens,{message:"maxTokens must be > minTokens (or null for infinite).",path:["maxTokens"]}).describe("A single pricing tier defined by a token range and associated prices.");zod.z.object({modelName:zod.z.string().describe("Model name this schedule applies to."),currency:zod.z.string().default("USD").describe("Currency code (e.g., USD)."),tokenRanges:zod.z.array(mi).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((t,n)=>{let{tokenRanges:o}=t;o[0].minTokens!==0&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let i=1;i<o.length;i++){let l=o[i-1],r=o[i];if(l.maxTokens===null){n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i-1,"maxTokens"],message:"Cannot define any tokenRanges after an infinite tier (maxTokens = null)."});break}r.minTokens!==l.maxTokens&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i,"minTokens"],message:`Tier ${i} minTokens (${r.minTokens}) must equal previous tier's maxTokens (${l.maxTokens}) for contiguity.`}),r.minTokens<l.minTokens&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i,"minTokens"],message:`tokenRanges must be sorted by ascending minTokens. Tier ${i} (${r.minTokens}) starts before Tier ${i-1} (${l.minTokens}).`});}let s=o[o.length-1];o.every(i=>i.maxTokens!==null||i===s)&&s.maxTokens!==null&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",o.length-1,"maxTokens"],message:"The final tier must have maxTokens = null (representing infinity)."});}).describe("Complete pricing schedule for a single chat model, including all its token-based tiers.");var pi="function",ui=zod.z.enum(["object","array","number","string","boolean","null"]),hi=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ui.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(hi).optional(),required:zod.z.array(zod.z.string()).optional()});var gi=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()}),fi=zod.z.enum(["function"]),yi=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),bi=zod.z.object({type:zod.z.literal("http"),method:zod.z.enum(["get","post"]),url:zod.z.string().url(),headers:zod.z.record(zod.z.string()).optional(),query:zod.z.record(zod.z.string()).optional(),body:zod.z.record(zod.z.any()).optional(),proxyUrl:zod.z.string().url().optional(),proxyHeaders:zod.z.record(zod.z.string()).optional(),retry:yi.optional()}),ki=zod.z.discriminatedUnion("type",[bi]),Ci=zod.z.object({type:fi,definition:zod.z.object({schema:gi}),request:ki.optional()}),vi=[pi];zod.z.enum(vi);var Ti=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Ci.extend({metadata:t})]),Mi=t=>dn().parse({modality:P,value:t}),xi=(t,n,o,s)=>mn().parse({modality:L,index:t,id:n,name:o,arguments:s}),Ht=(t,n)=>le().parse({role:t,partialContent:cn().parse({modality:ot,value:n})}),Ft=(t,n,o,s,i)=>le().parse({role:t,partialContent:pn().parse({modality:at,index:n,id:o,name:s,arguments:i})}),Si=(t,n)=>tt().parse({modality:J,value:{type:be,thinking:t,signature:n}}),wi=t=>tt().parse({modality:J,value:{type:et,data:t}}),ze=(t,n,o)=>le().parse({role:t,partialContent:nt().parse({modality:ye,value:{type:be,thinking:n,signature:o}})}),Oi=(t,n)=>le().parse({role:t,partialContent:nt().parse({modality:ye,value:{type:et,data:n}})}),Pi=Object.defineProperty,zt=Object.getOwnPropertySymbols,Ri=Object.prototype.hasOwnProperty,ji=Object.prototype.propertyIsEnumerable,Kt=(t,n,o)=>n in t?Pi(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o,ke=(t,n)=>{for(var o in n||(n={}))Ri.call(n,o)&&Kt(t,o,n[o]);if(zt)for(var o of zt(n))ji.call(n,o)&&Kt(t,o,n[o]);return t},Vt="ProviderError",Jt=class Cn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Vt),this.name=Vt,this.info=n,this.cause=o;}static isProviderError(n){return n instanceof Cn}},Gt="ModelResponseError",H=class vn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Gt),this.name=Gt,this.cause=o,this.info=n;}static isModelResponseError(n){return n instanceof vn}},Zt="InvalidModelRequestError",Ve=class Tn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Zt),this.name=Zt,this.cause=o,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(n){return n instanceof Tn}},Wt="InvalidConfigError",K=class Mn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Wt),this.name=Wt,this.cause=o,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(n){return n instanceof Mn}},Yt="InvalidMessagesError",I=class xn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Yt),this.name=Yt,this.cause=o,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(n){return n instanceof xn}},Xt="InvalidToolsError",Qt=class Sn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},Xt),this.name=Xt,this.cause=o,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(n){return n instanceof Sn}},en="InvalidEmbeddingRequestsError",tn=class wn extends W{constructor({info:n,cause:o}){super({info:n,cause:o},en),this.name=en,this.info=n,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(n){return n instanceof wn}},it="multi-string",On=zod.z.object({type:zod.z.literal(it),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()}),Ei=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),_i=t=>({def:On.parse(ke({type:it},t)),schema:Ei(t.max)}),Pn="object-schema",Ii=zod.z.object({type:zod.z.literal(Pn),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),st="range",Rn=zod.z.object({type:zod.z.literal(st),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()}),Bi=(t,n,o,s)=>zod.z.number().min(t).max(n).step(o).default(s).optional(),de=t=>({def:Rn.parse(ke({type:st},t)),schema:Bi(t.min,t.max,t.step,t.default)}),rt="select-boolean",jn=zod.z.object({type:zod.z.literal(rt),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()}),Ai=t=>zod.z.boolean().nullable().default(t).optional(),En=t=>({def:jn.parse(ke({type:rt},t)),schema:Ai(t.default)}),lt="select-string",_n=zod.z.object({type:zod.z.literal(lt),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())}),Ni=(t,n)=>zod.z.enum(n).nullable().default(t).optional(),dt=t=>({def:_n.parse(ke({type:lt},t)),schema:Ni(t.default,t.choices)}),Ui=[st,it,lt,Pn,rt];zod.z.enum(Ui);var In=zod.z.discriminatedUnion("type",[Rn,On,_n,jn,Ii]),F=(t=an,n=za)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(n).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),maxReasoningTokens:zod.z.number().int().positive().min(1).optional(),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),In),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var s,i;let l=Object.keys(o.def),r=Object.keys((i=(s=o.schema)==null?void 0:s.shape)!=null?i:{});return l.every(d=>r.includes(d))&&r.every(d=>l.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"}),price:zod.z.custom()}),ee=(t=ti)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).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),In),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(n=>{var o,s;let i=Object.keys(n.def),l=Object.keys((s=(o=n.schema)==null?void 0:o.shape)!=null?s:{});return i.every(r=>l.includes(r))&&l.every(r=>i.includes(r))},{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 Li={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."},$i={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."},qi={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},Di=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Hi={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."},Fi={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."},zi={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."},Ki={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."},Vi={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."},Ji={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."},Gi={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."},Zi={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."},Wi={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."},Yi={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."},Xi={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Qi={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."},es={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."},ts={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."},A={TEMPERATURE:Li,MAX_TOKENS:$i,STOP:Di,TOP_A:Hi,TOP_P:Fi,TOP_K:zi,MIN_P:Ki,FREQUENCY_PENALTY:Vi,PRESENCE_PENALTY:Ji,REPETITION_PENALTY:Zi,SEED:Gi,LOG_PROBS:Wi,TOP_LOG_PROBS:Yi,ECHO:Xi,RESPONSE_FORMAT:Qi,RESPONSE_FORMAT_WITH_SCHEMA:es,RESPONSE_SCHEMA:ts,MAX_REASONING_TOKENS:qi},Bn=t=>Object.fromEntries(Object.entries(t).filter(([n,o])=>o!=null)),se=t=>t==null?void 0:t.replace(/\/$/,""),An=de({param:"temperature",title:A.TEMPERATURE.title,description:A.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),Nn=t=>de({param:"max_tokens",title:A.MAX_TOKENS.title,description:A.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Un=t=>_i({param:"stop_sequences",title:A.STOP(t).title,description:A.STOP(t).description,max:t}),Ln=de({param:"top_p",title:A.TOP_P.title,description:A.TOP_P.description,min:0,max:1,step:.01,default:1}),$n=de({param:"top_k",title:A.TOP_K.title,description:A.TOP_K.description,min:0,max:1,step:.01,default:1}),qn=dt({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"]}),Ce=(t,n)=>zod.z.object({temperature:An.schema,maxTokens:Nn(t).schema,stop:Un(n).schema,topP:Ln.schema,topK:$n.schema,toolChoice:qn.schema}),ve=(t,n)=>({temperature:An.def,maxTokens:Nn(t).def,stop:Un(n).def,topP:Ln.def,topK:$n.def,toolChoice:qn.def}),Dn=(t,n)=>de({param:"max_reasoning_tokens",title:A.MAX_REASONING_TOKENS.title,description:A.MAX_REASONING_TOKENS.description,min:t,max:n,step:1,default:0}),Hn=En({param:"reasoning_enabled",title:"Reasoning Enabled",description:`Controls whether the model is allowed to think for a longer period of time before generating a response.
|
|
10
|
+
This can be useful for complex tasks that require more time to think.`,default:!1}),ns=(t,n,o,s)=>nn(O({},ve(t,n)),{reasoningEnabled:Hn.def,maxReasoningTokens:Dn(o,s).def}),os=(t,n,o,s)=>Ce(t,n).extend({reasoningEnabled:Hn.schema,maxReasoningTokens:Dn(o,s).schema}),Fn=dt({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"",choices:["base64",""]}),zn=dt({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:"",choices:["query","document",""]}),Kn=En({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0}),as=()=>zod.z.object({encodingFormat:Fn.schema,inputType:zn.schema,truncation:Kn.schema}),is=()=>({encodingFormat:Fn.def,inputType:zn.def,truncation:Kn.def}),S={base:(t,n)=>({def:ve(t,n),schema:Ce(t,n)}),extendedThinking:(t,n,o,s)=>({def:ns(t,n,o,s),schema:os(t,n,o,s)})},N={base:()=>({def:is(),schema:as()})},ss="anthropic",fe=class{constructor(){this.version="v1",this.name=ss,this.chatModelFactories={[Qn]:{model:Ws,modelOptions:Zs,modelSchema:eo},[ao]:{model:ir,modelOptions:ar,modelSchema:io},[no]:{model:nr,modelOptions:tr,modelSchema:oo},[Ze]:{model:Ds,modelOptions:qs,modelSchema:Wn},[We]:{model:zs,modelOptions:Fs,modelSchema:Yn},[Xe]:{model:Qs,modelOptions:Xs,modelSchema:to},[Ye]:{model:Js,modelOptions:Vs,modelSchema:Xn},[Ge]:{model:Ls,modelOptions:Us,modelSchema:Zn},[Je]:{model:As,modelOptions:Bs,modelSchema:Gn}},this.embeddingModelFactories={[yo]:{model:wr,modelOptions:Sr,modelSchema:bo},[go]:{model:Mr,modelOptions:Tr,modelSchema:fo},[so]:{model:mr,modelOptions:cr,modelSchema:ro},[lo]:{model:hr,modelOptions:ur,modelSchema:co},[mo]:{model:yr,modelOptions:fr,modelSchema:po},[uo]:{model:Cr,modelOptions:kr,modelSchema:ho}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,n)=>(t[n]=this.chatModelFactories[n].modelSchema,t),{})}chatModel(t){let n=t.modelName;if(!(n in this.chatModelFactories))throw new Jt({info:`Anthropic chat model: ${n} not found`,cause:new Error(`Anthropic chat model: ${n} not found, available chat models:
|
|
11
11
|
${this.chatModelLiterals().join(", ")}`)});let o=this.chatModelFactories[n].model,s=this.chatModelFactories[n].modelOptions.parse(t);return new o(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,n)=>(t[n]=this.embeddingModelFactories[n].modelSchema,t),{})}embeddingModel(t){let n=t.modelName;if(!(n in this.embeddingModelFactories))throw new Jt({info:`Anthropic embedding model: ${n} not found`,cause:new Error(`Anthropic embedding model: ${n} not found, available embedding models:
|
|
12
|
-
${this.embeddingModelLiterals().join(", ")}`)});let o=this.embeddingModelFactories[n].model,s=this.embeddingModelFactories[n].modelOptions.parse(t);return new o(s)}};fe.chatBaseUrl="https://api.anthropic.com/v1",fe.embeddingBaseUrl="https://api.voyageai.com/v1";var Z={"claude-3-opus-20240229":{modelName:"claude-3-opus-20240229",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]},"claude-3-sonnet-20240229":{modelName:"claude-3-sonnet-20240229",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-5-sonnet-20240620":{modelName:"claude-3-5-sonnet-20240620",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-5-sonnet-20241022":{modelName:"claude-3-5-sonnet-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-7-sonnet-20250219":{modelName:"claude-3-7-sonnet-20250219",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-haiku-20240307":{modelName:"claude-3-haiku-20240307",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:1.25}}}]},"claude-3-haiku-20241022":{modelName:"claude-3-haiku-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:1.25}}}]},"claude-3-5-haiku-20241022":{modelName:"claude-3-5-haiku-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.8,outputPricePerMillion:4}}}]},"claude-4-sonnet-20250514":{modelName:"claude-4-sonnet-20250514",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-4-opus-20250514":{modelName:"claude-4-opus-20250514",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]}},g=zod.z.enum([re,
|
|
13
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let p=Object.keys(m).reduce((h,u)=>{let
|
|
14
|
-
one of [${u.choices.join(", ")}]`)})}}let b=i!==void 0,v=l!==void 0;if(b!==v)throw new K({info:`Invalid extended thinking config for model: '${this.modelName}'`,cause:new Error("Both 'reasoningEnabled' and 'maxReasoningTokens' must be defined together.")});if(b&&v){let h=p.max_tokens;if(i)if(l<h)p.thinking={type:"enabled",budget_tokens:l};else throw new K({info:`Invalid extended thinking token budget for model: '${this.modelName}'`,cause:new Error(`maxReasoningTokens (${l}) must be less than max_tokens (${h})`)})}return p}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let n=l=>{let r=l.match(/^data:image\/[a-zA-Z]+;base64,/);return r?l.substring(r[0].length):l},o=t.map(l=>{let r=
|
|
15
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[
|
|
16
|
-
`).filter(s=>s.trim()!=="");for(let s of o)if(s.startsWith("data: {")&&s.endsWith("}")){let i;try{i=JSON.parse(s.substring(6));}catch(l){throw new H({info:`Malformed JSON received in stream : ${i}`,cause:l})}if("type"in i){if(i.type==="message_stop")return;if(i.type==="message_start"){let l=
|
|
17
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,l)=>{let r=this.modelSchema.config.def[l].param,d=s[l];return i[r]=d,i},{})}transformEmbeddingRequests(t){let n=
|
|
18
|
-
Message: ${
|
|
19
|
-
${this.chatModelLiterals().join(", ")}`)});let s=this.chatModelFactories[o].model,i=this.chatModelFactories[o].modelOptions.parse(n);return new s(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((n,o)=>(n[o]=this.embeddingModelFactories[o].modelSchema,n),{})}embeddingModel(n){throw new yt({info:"Adaline Bedrock provider does not support embedding models yet",cause:new Error("Adaline Bedrock provider does not support embedding models yet")})}};ae.awsService="bedrock",ae.awsDefaultRegion="us-east-1",ae.awsUrl=n=>`https://bedrock-runtime.${n!=null?n:ae.awsDefaultRegion}.amazonaws.com`;var E=ae;var M=zod.z.object({modelName:zod.z.string(),awsAccessKeyId:zod.z.string(),awsSecretAccessKey:zod.z.string()});var T={"anthropic.claude-3-5-haiku-20241022-v1:0":{modelName:"anthropic.claude-3-5-haiku-20241022-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1,outputPricePerMillion:5}}}]},"anthropic.claude-3-5-sonnet-20240620-v1:0":{modelName:"anthropic.claude-3-5-sonnet-20240620-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"anthropic.claude-3-5-sonnet-20241022-v2:0":{modelName:"anthropic.claude-3-5-sonnet-20241022-v2:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"anthropic.claude-3-haiku-20240307-v1:0":{modelName:"anthropic.claude-3-haiku-20240307-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:1.25}}}]},"anthropic.claude-3-opus-20240229-v1:0":{modelName:"anthropic.claude-3-opus-20240229-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]},"anthropic.claude-3-sonnet-20240229-v1:0":{modelName:"anthropic.claude-3-sonnet-20240229-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"anthropic.claude-opus-4-20250514-v1:0":{modelName:"anthropic.claude-opus-4-20250514-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]},"anthropic.claude-sonnet-4-20250514-v1:0":{modelName:"anthropic.claude-sonnet-4-20250514-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"anthropic.claude-3-7-sonnet-20250219-v1:0":{modelName:"anthropic.claude-3-7-sonnet-20250219-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]}};var x=class t extends ${constructor(o,s){let i=M.parse(s);super(o,{apiKey:"random-api-key",modelName:i.modelName});this.version="v1";this.modelSchema=o,this.modelName=i.modelName,this.awsService=E.awsService,this.awsAccessKeyId=i.awsAccessKeyId,this.awsSecretAccessKey=i.awsSecretAccessKey;}getDefaultBaseUrl(){return E.awsUrl()}getDefaultHeaders(){return {Accept:"application/json","Content-Type":"application/json"}}getDefaultParams(){return {anthropic_version:"bedrock-2023-05-31"}}getCompleteChatUrl(o,s,i){let l=E.awsUrl(o==null?void 0:o.awsRegion);return new Promise(r=>{r(`${l}/model/${this.modelName}/invoke`);})}transformConfig(o,s,i){let l=j({},o);return delete l.awsRegion,super.transformConfig(l,s,i)}getCompleteChatHeaders(o,s,i){return U(this,null,function*(){let l=new URL(yield this.getCompleteChatUrl(o,s,i)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},d=(o==null?void 0:o.awsRegion)||E.awsDefaultRegion,m=this.getDefaultHeaders();m=z(j({},m),{host:E.awsUrl(d).split("://")[1]});let p=yield this.getCompleteChatData(o||{},s||[],i),b=new protocolHttp.HttpRequest({hostname:l.hostname,path:l.pathname,protocol:l.protocol,method:"POST",body:JSON.stringify(p),headers:m});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:d,sha256:sha256Js.Sha256}).sign(b)).headers})}getCompleteChatData(o,s,i){return U(this,null,function*(){let l=j(j({},this.getDefaultParams()),yield pe(t.prototype,this,"getCompleteChatData").call(this,o,s,i));return new Promise(r=>{r(l);})})}getStreamChatUrl(o,s,i){return U(this,null,function*(){let l=E.awsUrl(o==null?void 0:o.awsRegion);return new Promise(r=>{r(`${l}/model/${this.modelName}/invoke-with-response-stream`);})})}getStreamChatHeaders(o,s,i){return U(this,null,function*(){let l=new URL(yield this.getStreamChatUrl(o,s,i)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},d=(o==null?void 0:o.awsRegion)||E.awsDefaultRegion,m=this.getDefaultHeaders();m=z(j({},m),{host:E.awsUrl(d).split("://")[1]});let p=yield this.getCompleteChatData(o||{},s||[],i),b=new protocolHttp.HttpRequest({hostname:l.hostname,path:l.pathname,protocol:l.protocol,method:"POST",body:JSON.stringify(p),headers:m});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:d,sha256:sha256Js.Sha256}).sign(b)).headers})}getStreamChatData(o,s,i){return U(this,null,function*(){let l=j(j({},this.getDefaultParams()),yield pe(t.prototype,this,"getStreamChatData").call(this,o,s,i));return "stream"in l&&delete l.stream,l})}transformStreamChatResponseChunk(o,s){return He(this,null,function*(){let i=o.toString(),l=/{\s*"bytes"\s*:\s*"[\w=+/]+".*?}/g,r=i.match(l)||[];for(let d of r){let m=d.indexOf("{"),p=d.indexOf("}");if(m!==-1&&p!==-1&&m<p){let b;try{b=JSON.parse(d.slice(m,p+1));}catch(u){throw new bt({info:`Malformed JSON received in stream : ${b}`,cause:u})}let v=Jo(b.bytes),h=(yield new ue(pe(t.prototype,this,"transformStreamChatResponseChunk").call(this,`data: ${v}`,s).next())).value;h&&(yield h);}}})}transformProxyStreamChatResponseChunk(o,s,i,l,r){return He(this,null,function*(){yield*he(this.transformStreamChatResponseChunk(o,s));})}getRegionHelper(o){var i;let s=o["aws-region"];if(!s){let l=(i=o.authorization)==null?void 0:i.match(/Credential=[^/]+\/\d+\/([^/]+)\/bedrock/);l&&(s=l[1]);}return s}getProxyStreamChatUrl(o,s,i){return U(this,null,function*(){let l=this.getRegionHelper(s||{}),r=E.awsUrl(l);return new Promise(d=>{d(`${r}/model/${this.modelName}/invoke-with-response-stream`);})})}getProxyChatHeaders(o,s,i,l){return U(this,null,function*(){let r=new URL(yield o());if(!i)return {};let d=i["aws-access-key-id"],m=i["aws-secret-access-key"],p=this.getRegionHelper(i);if(!d||!m)return {};let b={accessKeyId:d,secretAccessKey:m};i=z(j({},i),{host:r.host,"content-type":"application/json",accept:"application/json"}),delete i["content-length"];let v=i.authorization||i.Authorization;if(v){let _=v.match(/SignedHeaders=([^,]+)/);if(_&&_[1]){let ie=_[1].split(";").map(ce=>ce.trim().toLowerCase());ie.push("authorization"),i=Object.keys(i).reduce((ce,qe)=>{var It;return ie.includes(qe.toLowerCase())&&(ce[qe]=(It=i==null?void 0:i[qe])!=null?It:""),ce},{});}}let h=new protocolHttp.HttpRequest({hostname:r.hostname,path:r.pathname,protocol:r.protocol,method:"POST",body:JSON.stringify(s),headers:i});return (yield new signatureV4.SignatureV4({credentials:b,service:this.awsService,region:p,sha256:sha256Js.Sha256}).sign(h)).headers})}getProxyCompleteChatUrl(o,s,i){return U(this,null,function*(){let l=this.getRegionHelper(s||{}),r=E.awsUrl(l);return new Promise(d=>{d(`${r}/model/${this.modelName}/invoke`);})})}getProxyCompleteChatHeaders(o,s,i){return U(this,null,function*(){return this.getProxyChatHeaders(()=>this.getProxyCompleteChatUrl(o,s,i),o,s,i)})}getProxyStreamChatHeaders(o,s,i){return U(this,null,function*(){return this.getProxyChatHeaders(()=>this.getProxyStreamChatUrl(o,s,i),o,s,i)})}getModelPricing(){if(!(this.modelName in T))throw new bt({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return T[this.modelName]}};var Te="anthropic.claude-3-5-haiku-20241022-v1:0",$l="Our fastest model with intelligence at blazing speeds.",vt=w(g,C).parse({name:Te,description:$l,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:y.base(8192,4).def,schema:y.base(8192,4).schema},price:T[Te]}),Wo=M,Me=class extends x{constructor(n){super(vt,n);}};var xe="anthropic.claude-3-5-sonnet-20240620-v1:0",Dl="Most intelligent model. Highest level of intelligence and capability.",Tt=w(g,C).parse({name:xe,description:Dl,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:y.base(8192,4).def,schema:y.base(8192,4).schema},price:T[xe]}),Xo=M,Se=class extends x{constructor(n){super(Tt,n);}};var we="anthropic.claude-3-5-sonnet-20241022-v2:0",ql="Most intelligent model. Highest level of intelligence and capability.",Mt=w(g,C).parse({name:we,description:ql,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:y.base(8192,4).def,schema:y.base(8192,4).schema},price:T[we]}),Yo=M,Oe=class extends x{constructor(n){super(Mt,n);}};var Pe="anthropic.claude-3-7-sonnet-20250219-v1:0",Hl="Most intelligent model. Highest level of intelligence and capability.",xt=w(g,C).parse({name:Pe,description:Hl,maxInputTokens:2e5,maxOutputTokens:128e3,roles:f,modalities:k,config:{def:y.base(128e3,4).def,schema:y.base(128e3,4).schema},price:T[Pe]}),Qo=M,Re=class extends x{constructor(n){super(xt,n);}getDefaultHeaders(){let n=super.getDefaultHeaders();return n=z(j({},n),{"anthropic-beta":"output-128k-2025-02-19"}),n}};var je="anthropic.claude-3-haiku-20240307-v1:0",Fl="Claude 3 Haiku is a large-scale multimodal model trained by Anthropic. It is the successor to Claude 3 and is designed to be more powerful and capable than its predecessor.",St=w(g,C).parse({name:je,description:Fl,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:y.base(4096,4).def,schema:y.base(4096,4).schema},price:T[je]}),ea=M,Ee=class extends x{constructor(n){super(St,n);}};var _e="anthropic.claude-3-opus-20240229-v1:0",zl="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",wt=w(g,C).parse({name:_e,description:zl,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:y.base(4096,4).def,schema:y.base(4096,4).schema},price:T[_e]}),ta=M,Ie=class extends x{constructor(n){super(wt,n);}};var Be="anthropic.claude-3-sonnet-20240229-v1:0",Kl="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Ot=w(g,C).parse({name:Be,description:Kl,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:y.base(4096,4).def,schema:y.base(4096,4).schema},price:T[Be]}),na=M,Ae=class extends x{constructor(n){super(Ot,n);}};var Ne="anthropic.claude-opus-4-20250514-v1:0",Vl="Our high-performance model with exceptional reasoning and efficiency. Training cutoff: March 2025.",Pt=w(g,C).parse({name:Ne,description:Vl,maxInputTokens:2e5,maxOutputTokens:32e3,roles:f,modalities:k,config:{def:y.base(32e3,4).def,schema:y.base(32e3,4).schema},price:T[Ne]}),oa=M,Ue=class extends x{constructor(n){super(Pt,n);}};var Le="anthropic.claude-sonnet-4-20250514-v1:0",Jl="Our most capable and intelligent model yet. Training cutoff: March 2025.",Rt=w(g,C).parse({name:Le,description:Jl,maxInputTokens:2e5,maxOutputTokens:64e3,roles:f,modalities:k,config:{def:y.base(64e3,4).def,schema:y.base(64e3,4).schema},price:T[Le]}),aa=M,$e=class extends x{constructor(n){super(Rt,n);}};
|
|
12
|
+
${this.embeddingModelLiterals().join(", ")}`)});let o=this.embeddingModelFactories[n].model,s=this.embeddingModelFactories[n].modelOptions.parse(t);return new o(s)}};fe.chatBaseUrl="https://api.anthropic.com/v1",fe.embeddingBaseUrl="https://api.voyageai.com/v1";var Z={"claude-3-opus-20240229":{modelName:"claude-3-opus-20240229",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]},"claude-3-sonnet-20240229":{modelName:"claude-3-sonnet-20240229",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-5-sonnet-20240620":{modelName:"claude-3-5-sonnet-20240620",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-5-sonnet-20241022":{modelName:"claude-3-5-sonnet-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-7-sonnet-20250219":{modelName:"claude-3-7-sonnet-20250219",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-3-haiku-20240307":{modelName:"claude-3-haiku-20240307",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:1.25}}}]},"claude-3-haiku-20241022":{modelName:"claude-3-haiku-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:1.25}}}]},"claude-3-5-haiku-20241022":{modelName:"claude-3-5-haiku-20241022",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.8,outputPricePerMillion:4}}}]},"claude-4-sonnet-20250514":{modelName:"claude-4-sonnet-20250514",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"claude-4-opus-20250514":{modelName:"claude-4-opus-20250514",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]}},g=zod.z.enum([re,X,R,Qe]),f={system:re,user:X,assistant:R,tool:X},k=[P,V,L,G],C=zod.z.enum([P,V,L,G]),ct=[P,V,L,G,J],mt=zod.z.enum([P,V,L,G,J]),rs=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ls=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),ds=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string(),signature:zod.z.string()}),cs=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),ms=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[rs,ls,ds,cs])),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()})}),ps=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()})})}),us=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()})}),hs=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),gs=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),fs=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string()}),ys=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),bs=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[hs,gs,fs,ys])}),ks=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),Cs=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),vs=zod.z.object({type:zod.z.literal("thinking_delta"),thinking:zod.z.string()}),Ts=zod.z.object({type:zod.z.literal("signature_delta"),signature:zod.z.string()}),Ms=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[ks,Cs,vs,Ts])}),xs=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string().optional(),signature:zod.z.string().optional()}),Ss=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),ws=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),Os=zod.z.object({type:zod.z.enum(["auto","any"])}),Ps=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),pt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),Vn=zod.z.object({type:zod.z.literal("image"),source:zod.z.object({type:zod.z.literal("base64"),media_type:zod.z.enum(["image/jpeg","image/png","image/gif","image/webp"]),data:zod.z.string().base64()})});zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("tool_use"),name:zod.z.string().min(1),input:zod.z.record(zod.z.any())});var Jn=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([pt,Vn])).min(1))}),Rs=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([pt,Vn,Jn])).min(1))}),js=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([pt,Jn,xs,Ss])).min(1))}),Es=zod.z.union([Rs,js]),_s=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Es).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([Os,Ps]).optional(),tools:zod.z.array(ws).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()}),D=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),$=class{constructor(t,n){this.version="v1";let o=D.parse(n);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=se(fe.chatBaseUrl),this.completeChatUrl=se(o.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=se(o.streamChatUrl||`${this.baseUrl}/messages`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"x-api-key":`${this.apiKey}`,"anthropic-version":"2023-06-01","content-type":"application/json","anthropic-dangerous-direct-browser-access":"true"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){let n=0,o=!0;return t["x-should-retry"]&&(o=t["x-should-retry"].toLowerCase()!=="false"),t["retry-after"]&&(n=parseInt(t["retry-after"])*1e3),{shouldRetry:o,delayMs:n}}getTokenCount(t){return t.reduce((n,o)=>n+o.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(t){let n=_s.safeParse(t);if(!n.success)throw new Ve({info:"Invalid model request",cause:n.error});let o=n.data,s=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new Ve({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let i={};o.tool_choice&&(o.tool_choice.type==="tool"?i.toolChoice=o.tool_choice.name:i.toolChoice=o.tool_choice.type),i.maxTokens=o.max_tokens,i.temperature=o.temperature,i.topP=o.top_p,i.topK=o.top_k,i.stop=o.stop_sequences;let l=gn().parse(Bn(i)),r=[],d={};o.system&&r.push({role:re,content:[{modality:P,value:o.system}]}),o.messages.forEach(p=>{let b=p.role;switch(b){case"user":{let v=p.content;if(typeof v=="string")r.push({role:b,content:[{modality:P,value:v}]});else {let h=v.map(u=>{if(u.type==="text")return {modality:P,value:u.text};if(u.type==="image"){let q="auto",_=u.source.media_type.split("/")[1];return {modality:V,detail:q,value:{type:sn,mediaType:_,base64:u.source.data}}}else return {modality:G,id:u.tool_use_id,index:d[u.tool_use_id].index,name:d[u.tool_use_id].name,data:typeof u.content=="string"?u.content:JSON.stringify(u.content)}});r.push({role:b,content:h});}}break;case"assistant":{let v=p.content;if(typeof v=="string")r.push({role:b,content:[{modality:P,value:v}]});else {let h=v.map((u,q)=>{if(u.type==="text")return {modality:P,value:u.text};{let _={modality:L,id:u.id,index:q,name:u.name,arguments:JSON.stringify(u.input)};return d[u.id]=_,_}});r.push({role:b,content:h});}}break}});let m=[];return o.tools&&o.tools.forEach(p=>{m.push({type:"function",definition:{schema:{name:p.name,description:p.description||"",parameters:p.input_schema}}});}),{modelName:s,config:l,messages:r,tools:m.length>0?m:void 0}}transformConfig(t,n,o){let s=t.toolChoice,i=t.reasoningEnabled,l=t.maxReasoningTokens,r=O({},t);delete r.toolChoice,delete r.reasoningEnabled,delete r.maxReasoningTokens;let d=this.modelSchema.config.schema.safeParse(r);if(!d.success)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:d.error});let m=d.data;s!==void 0&&(m.toolChoice=s),Object.keys(m).forEach(h=>{if(!(h in this.modelSchema.config.def))throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${h}',
|
|
13
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let p=Object.keys(m).reduce((h,u)=>{let q=this.modelSchema.config.def[u],_=q.param,ie=m[u];return _==="max_tokens"&&q.type==="range"&&ie===0?h[_]=q.max:h[_]=ie,h},{});if(!p.max_tokens){let h=this.modelSchema.config.def.maxTokens;p.max_tokens=h.max;}if("tool_choice"in p&&p.tool_choice!==void 0){let h=p.tool_choice;if(!o||o&&o.length===0)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let u=this.modelSchema.config.def.toolChoice;if(u.choices.includes(h))p.tool_choice={type:h};else if(o.map(q=>q.definition.schema.name).includes(h))p.tool_choice={type:"tool",name:h};else throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${h}' is not part of provided 'tools' names or
|
|
14
|
+
one of [${u.choices.join(", ")}]`)})}}let b=i!==void 0,v=l!==void 0;if(b!==v)throw new K({info:`Invalid extended thinking config for model: '${this.modelName}'`,cause:new Error("Both 'reasoningEnabled' and 'maxReasoningTokens' must be defined together.")});if(b&&v){let h=p.max_tokens;if(i)if(l<h)p.thinking={type:"enabled",budget_tokens:l};else throw new K({info:`Invalid extended thinking token budget for model: '${this.modelName}'`,cause:new Error(`maxReasoningTokens (${l}) must be less than max_tokens (${h})`)})}return p}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let n=l=>{let r=l.match(/^data:image\/[a-zA-Z]+;base64,/);return r?l.substring(r[0].length):l},o=t.map(l=>{let r=un().safeParse(l);if(!r.success)throw new I({info:"Invalid messages",cause:r.error});return r.data});o.forEach(l=>{l.content.forEach(r=>{if(!this.modelSchema.modalities.includes(r.modality))throw new I({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${r.modality}', available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(l=>{if(!Object.keys(this.modelSchema.roles).includes(l.role))throw new I({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${l.role}', available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let s="",i=[];if(o.forEach(l=>{switch(l.role){case re:{l.content.forEach(r=>{if(r.modality===P)s+=r.value;else throw new I({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${l.role}' cannot have content with modality : '${r.modality}'`)})});break}case R:{let r=[];l.content.forEach(d=>{if(d.modality===P)r.push({type:"text",text:d.value});else if(d.modality===L)r.push({type:"tool_use",id:d.id,name:d.name,input:JSON.parse(d.arguments)});else if(d.modality===J&&d.value.type==="thinking")r.push({type:"thinking",thinking:d.value.thinking,signature:d.value.signature});else if(d.modality===J&&d.value.type==="redacted")r.push({type:"redacted_thinking",data:d.value.data});else throw new I({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${l.role}' cannot have content with modality : '${d.modality}'`)})}),i.push({role:this.modelSchema.roles[l.role],content:r});break}case X:{let r=[];l.content.forEach(d=>{if(d.modality===P)r.push({type:"text",text:d.value});else if(d.modality===V){if(d.value.type==="base64"){let m=d.value.base64;m=n(m),r.push({type:"image",source:{type:"base64",media_type:`image/${d.value.mediaType}`,data:m}});}else if(d.value.type==="url")throw new I({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${d.value.type}'`)})}else throw new I({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${l.role}' cannot have content with modality : '${d.modality}'`)})}),i.push({role:this.modelSchema.roles[l.role],content:r});break}case Qe:{let r=[];l.content.forEach(d=>{if(d.modality===G)r.push({type:"tool_result",tool_use_id:d.id,content:d.data});else throw new I({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${l.role}' cannot have content with modality : '${d.modality}'`)})}),i.push({role:this.modelSchema.roles[l.role],content:r});break}default:throw new I({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${l.role}' is not supported,
|
|
15
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[X])throw new I({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});return {system:s,messages:i}}transformTools(t){if(!this.modelSchema.modalities.includes(L))throw new Qt({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${L}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(n=>{let o=Ti().safeParse(n);if(!o.success)throw new Qt({info:"Invalid tools",cause:o.error});return o.data}).map(n=>({name:n.definition.schema.name,description:n.definition.schema.description,input_schema:n.definition.schema.parameters}))}}getCompleteChatUrl(t,n,o){return B(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(t,n,o){return B(this,null,function*(){let s=this.getDefaultHeaders();return new Promise(i=>{i(s);})})}getCompleteChatData(t,n,o){return B(this,null,function*(){let s=this.transformConfig(t,n,o),i=this.transformMessages(n);if(i.messages&&i.messages.length===0)throw new I({info:"Messages are required",cause:new Error("Messages are required")});let l=o?this.transformTools(o):{};return new Promise(r=>{r(O(O(O(O({},this.getDefaultParams()),s),i),l));})})}transformCompleteChatResponse(t){let n=ms.safeParse(t);if(n.success){let o=n.data,s=o.content.map((r,d)=>{if(r.type==="text")return Mi(r.text);if(r.type==="tool_use")return xi(d,r.id,r.name,JSON.stringify(r.input));if(r.type==="thinking")return Si(r.thinking,r.signature);if(r.type==="redacted_thinking")return wi(r.data)}),i=[{role:R,content:s}],l={promptTokens:o.usage.input_tokens,completionTokens:o.usage.output_tokens,totalTokens:o.usage.input_tokens+o.usage.output_tokens};return {messages:i,usage:l,logProbs:[]}}throw new H({info:"Invalid response from model",cause:n.error})}getStreamChatUrl(t,n,o){return B(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(t,n,o){let s=this.getDefaultHeaders();return new Promise(i=>{i(s);})}getStreamChatData(t,n,o){return B(this,null,function*(){let s=this.transformConfig(t,n,o),i=this.transformMessages(n);if(i.messages&&i.messages.length===0)throw new I({info:"Messages are required",cause:new Error("Messages are required")});let l=o?this.transformTools(o):{};return new Promise(r=>{r(O(O(O(O({stream:!0},this.getDefaultParams()),s),i),l));})})}transformStreamChatResponseChunk(t,n){return Lt(this,null,function*(){let o=(n+t).split(`
|
|
16
|
+
`).filter(s=>s.trim()!=="");for(let s of o)if(s.startsWith("data: {")&&s.endsWith("}")){let i;try{i=JSON.parse(s.substring(6));}catch(l){throw new H({info:`Malformed JSON received in stream : ${i}`,cause:l})}if("type"in i){if(i.type==="message_stop")return;if(i.type==="message_start"){let l=ps.safeParse(i);if(l.success){let r=l.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:n};}else throw new H({info:"Invalid response from model",cause:l.error})}else if(i.type==="message_delta"){let l=us.safeParse(i);if(l.success){let r=l.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:void 0,completionTokens:r.usage.output_tokens,totalTokens:r.usage.output_tokens}},buffer:n};}else throw new H({info:"Invalid response from model",cause:l.error})}else if(i.type==="content_block_start"){let l=bs.safeParse(i);if(l.success){let r=l.data,d=[];r.content_block.type==="text"?d.push(Ht(R,r.content_block.text)):r.content_block.type==="tool_use"?d.push(Ft(R,r.index,r.content_block.id,r.content_block.name,"")):r.content_block.type==="thinking"?d.push(ze(R,r.content_block.thinking)):r.content_block.type==="redacted_thinking"&&d.push(Oi(R,r.content_block.data)),yield {partialResponse:{partialMessages:d},buffer:n};}else throw new H({info:"Invalid response from model",cause:l.error})}else if(i.type==="content_block_delta"){let l=Ms.safeParse(i);if(l.success){let r=l.data,d=[];r.delta.type==="text_delta"?d.push(Ht(R,r.delta.text)):r.delta.type==="input_json_delta"?d.push(Ft(R,r.index,"","",r.delta.partial_json)):r.delta.type==="thinking_delta"?d.push(ze(R,r.delta.thinking)):r.delta.type==="signature_delta"&&d.push(ze(R,void 0,r.delta.signature)),yield {partialResponse:{partialMessages:d},buffer:n};}else throw new H({info:"Invalid response from model",cause:l.error})}}else throw new H({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property, received: ${JSON.stringify(i)}`)})}})}transformProxyStreamChatResponseChunk(t,n,o,s,i){return Lt(this,null,function*(){yield*he(va(this.transformStreamChatResponseChunk(t,n)));})}getProxyStreamChatUrl(t,n,o){return B(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(t,n,o){return B(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(t,n,o){return B(this,null,function*(){if(!n)return {};let s=O({},n);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(t,n,o){return B(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,n,o)})}getModelPricing(){if(!(this.modelName in Z))throw new H({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return Z[this.modelName]}},Je="claude-4-opus-20250514",Is="Our high-performance model with exceptional reasoning and efficiency. Training cutoff: March 2025.",Gn=F(g,mt).parse({name:Je,description:Is,maxInputTokens:2e5,maxOutputTokens:32e3,maxReasoningTokens:32e3,roles:f,modalities:ct,config:{def:S.extendedThinking(32e3,4,1024,32e3).def,schema:S.extendedThinking(32e3,4,1024,32e3).schema},price:Z[Je]}),Bs=D,As=class extends ${constructor(t){super(Gn,t);}},Ge="claude-4-sonnet-20250514",Ns="Our most capable and intelligent model yet. Training cutoff: March 2025.",Zn=F(g,mt).parse({name:Ge,description:Ns,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:f,modalities:ct,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:Z[Ge]}),Us=D,Ls=class extends ${constructor(t){super(Zn,t);}},Ze="claude-3-5-sonnet-20240620",$s="Most intelligent model. Highest level of intelligence and capability.",Wn=F(g,C).parse({name:Ze,description:$s,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:Z[Ze]}),qs=D,Ds=class extends ${constructor(t){super(Wn,t);}},We="claude-3-5-sonnet-20241022",Hs="Most intelligent model. Highest level of intelligence and capability.",Yn=F(g,C).parse({name:We,description:Hs,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:Z[We]}),Fs=D,zs=class extends ${constructor(t){super(Yn,t);}},Ye="claude-3-7-sonnet-20250219",Ks="Most intelligent model. Highest level of intelligence and capability.",Xn=F(g,mt).parse({name:Ye,description:Ks,maxInputTokens:2e5,maxOutputTokens:128e3,maxReasoningTokens:64e3,roles:f,modalities:ct,config:{def:S.extendedThinking(128e3,4,1024,64e3).def,schema:S.extendedThinking(128e3,4,1024,64e3).schema},price:Z[Ye]}),Vs=D,Js=class extends ${constructor(t){super(Xn,t);}getDefaultHeaders(){let t=super.getDefaultHeaders();return t=nn(O({},t),{"anthropic-beta":"output-128k-2025-02-19"}),t}},Qn="claude-3-haiku-20240307",Gs="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",eo=F(g,C).parse({name:Qn,description:Gs,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),Zs=D,Ws=class extends ${constructor(t){super(eo,t);}},Xe="claude-3-5-haiku-20241022",Ys="Our fastest model with intelligence at blazing speeds.",to=F(g,C).parse({name:Xe,description:Ys,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:Z[Xe]}),Xs=D,Qs=class extends ${constructor(t){super(to,t);}},no="claude-3-opus-20240229",er="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",oo=F(g,C).parse({name:no,description:er,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),tr=D,nr=class extends ${constructor(t){super(oo,t);}},ao="claude-3-sonnet-20240229",or="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",io=F(g,C).parse({name:ao,description:or,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),ar=D,ir=class extends ${constructor(t){super(io,t);}},te=[Q],ne=zod.z.enum([Q]),sr=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()})}),rr=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),lr=zod.z.object({model:zod.z.string().min(1).optional(),input:rr,encoding_format:zod.z.enum(["base64"]).nullable().optional(),input_type:zod.z.enum(["query","document"]).nullable().optional(),truncation:zod.z.boolean().optional()}),Y=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),oe=class{constructor(t,n){this.version="v1";let o=Y.parse(n);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=se(fe.embeddingBaseUrl),this.getEmbeddingsUrl=se(o.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getTokenCount(t){return t.requests.reduce((n,o)=>n+o.length,0)}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}transformModelRequest(t){let n=lr.safeParse(t);if(!n.success)throw new Ve({info:"Invalid model request",cause:n.error});let o=n.data,s=o.model,i={encodingFormat:o.encoding_format,inputType:o.input_type,truncation:o.truncation},l=gn().parse(Bn(i)),r;return typeof o.input=="string"?r={modality:Q,requests:[o.input]}:r={modality:Q,requests:o.input},{modelName:s,config:l,embeddingRequests:r}}transformConfig(t,n){"inputType"in t&&t.inputType===""&&delete t.inputType,"encodingFormat"in t&&t.encodingFormat===""&&delete t.encodingFormat;let o=this.modelSchema.config.schema.safeParse(t);if(!o.success)throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let s=o.data;return Object.keys(s).forEach(i=>{if(!this.modelSchema.config.def[i])throw new K({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${i}',
|
|
17
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,l)=>{let r=this.modelSchema.config.def[l].param,d=s[l];return i[r]=d,i},{})}transformEmbeddingRequests(t){let n=ai().safeParse(t);if(!n.success)throw new tn({info:"Invalid embedding requests",cause:n.error});if(n.data.requests.length>128)throw new tn({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:n.data.requests}}getGetEmbeddingsUrl(t,n){return B(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,n){return B(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,n){return B(this,null,function*(){return new Promise(o=>{o(O(O(O({},this.getDefaultParams()),this.transformConfig(t,n)),this.transformEmbeddingRequests(n)));})})}transformGetEmbeddingsResponse(t){let n,o=sr.safeParse(t);if(o.success){let s=o.data;n=typeof s.data[0].embedding=="string"?bn:yn;let i=s.data.map(l=>typeof l.embedding=="string"?{index:l.index,embedding:l.embedding}:{index:l.index,embedding:l.embedding});return {encodingFormat:n,embeddings:i,usage:{totalTokens:s.usage.total_tokens}}}throw new H({info:"Invalid response from model",cause:o.error})}},so="voyage-code-2",dr="Optimized for code retrieval.",ro=ee(ne).parse({name:so,description:dr,modalities:te,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:N.base().def,schema:N.base().schema}}),cr=Y,mr=class extends oe{constructor(t){super(ro,t);}},lo="voyage-law-2",pr="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",co=ee(ne).parse({name:lo,description:pr,modalities:te,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:N.base().def,schema:N.base().schema}}),ur=Y,hr=class extends oe{constructor(t){super(co,t);}},mo="voyage-multilingual-2",gr="Optimized for multilingual retrieval and RAG.",po=ee(ne).parse({name:mo,description:gr,modalities:te,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:N.base().def,schema:N.base().schema}}),fr=Y,yr=class extends oe{constructor(t){super(po,t);}},uo="voyage-finance-2",br="Optimized for finance retrieval and RAG.",ho=ee(ne).parse({name:uo,description:br,modalities:te,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:N.base().def,schema:N.base().schema}}),kr=Y,Cr=class extends oe{constructor(t){super(ho,t);}},go="voyage-3-lite",vr="Optimized for latency and cost.",fo=ee(ne).parse({name:go,description:vr,modalities:te,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:N.base().def,schema:N.base().schema}}),Tr=Y,Mr=class extends oe{constructor(t){super(fo,t);}},yo="voyage-3",xr="Optimized for quality.",bo=ee(ne).parse({name:yo,description:xr,modalities:te,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:N.base().def,schema:N.base().schema}}),Sr=Y,wr=class extends oe{constructor(t){super(bo,t);}};var Or="system",Pr="user",To="assistant",Rr="tool",jr=[Or,Pr,To,Rr],gt=zod.z.enum(jr),Er=[To],_r=zod.z.enum(Er),Mo="image",Ir="base64",Br=["png","jpeg","webp","gif"],Ar=zod.z.object({type:zod.z.literal(Ir),base64:zod.z.string(),mediaType:zod.z.enum(Br)}),Nr="url",Ur=zod.z.object({type:zod.z.literal(Nr),url:zod.z.string()}),Lr=zod.z.discriminatedUnion("type",[Ar,Ur]),$r=["low","medium","high","auto"],qr=zod.z.enum($r),Dr=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Mo),detail:qr,value:Lr,metadata:t}),xo="pdf",Hr="base64",Fr=zod.z.object({type:zod.z.literal(Hr),base64:zod.z.string()}),zr="url",Kr=zod.z.object({type:zod.z.literal(zr),url:zod.z.string()}),Vr=zod.z.discriminatedUnion("type",[Fr,Kr]),Jr=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(xo),value:Vr,providerCacheKey:zod.z.string(),metadata:t}),So="reasoning",wo="partial-reasoning",Oo="thinking",Gr="redacted",ht=zod.z.object({type:zod.z.literal(Oo),thinking:zod.z.string(),signature:zod.z.string()}),Po=zod.z.object({type:zod.z.literal(Gr),data:zod.z.string()}),Zr=zod.z.discriminatedUnion("type",[ht,Po]),Wr=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(So),value:Zr,metadata:t}),Yr=zod.z.object({type:zod.z.literal(Oo),thinking:ht.shape.thinking.optional(),signature:ht.shape.signature.optional()}),Xr=zod.z.discriminatedUnion("type",[Yr,Po]),Qr=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(wo),value:Xr,metadata:t}),Ro="text",el=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ro),value:zod.z.string(),metadata:t}),jo="partial-text",tl=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(jo),value:zod.z.string(),metadata:t}),Eo="tool-call",nl=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Eo),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),_o="partial-tool-call",ol=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_o),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),Io="tool-response",al=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Io),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),apiResponse:zod.z.object({statusCode:zod.z.number().int().nonnegative()}).optional(),metadata:t}),il=[Ro,Mo,xo,Eo,Io,So],Bo=zod.z.enum(il),sl=(t=zod.z.undefined(),n=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[el(t),Dr(n),Jr(o),nl(s),al(i),Wr(l)]),rl=[jo,_o,wo];zod.z.enum(rl);var ll=(t=zod.z.undefined(),n=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[tl(t),ol(n),Qr(o)]);var dl=(t=gt,n=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(sl(n,o,s,i,r)),metadata:l}),cl=(t=_r,n=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:t,partialContent:ll(n,o,s),metadata:i}),ml=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),ko=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),pl=ko.extend({topLogProbs:zod.z.array(ko)}),Ao=zod.z.array(pl);zod.z.object({messages:zod.z.array(dl()),usage:ml.optional(),logProbs:Ao.optional()});var ul=zod.z.object({promptTokens:zod.z.number().nonnegative().optional(),completionTokens:zod.z.number().nonnegative().optional(),totalTokens:zod.z.number().nonnegative().optional()});zod.z.object({partialMessages:zod.z.array(cl()),usage:ul.optional(),logProbs:Ao.optional()});var hl=["object","array","number","string","boolean","enum"],Co=zod.z.enum(hl),gl=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Co,zod.z.array(zod.z.union([Co,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()}),fl=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(gl),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:fl}).optional();var yl="text",bl="token",kl=[yl,bl];zod.z.enum(kl);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var vl="float",Tl=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Ml="base64",xl=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),vo=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(vl),embeddings:zod.z.array(Tl),usage:vo.optional()}),zod.z.object({encodingFormat:zod.z.literal(Ml),embeddings:zod.z.array(xl),usage:vo.optional()})]);var Sl=t=>{let n=new WeakSet;return JSON.stringify(t,(o,s)=>{if(typeof s=="object"&&s!==null){if(n.has(s))return;n.add(s);}return s})},wl=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:Sl(t),ut="GatewayBaseError",ft=class No extends Error{constructor({info:n,cause:o},s){super(`[${s!=null?s:ut}]: ${n}
|
|
18
|
+
Message: ${wl(o)}`),this.name=ut,this.info=n,this.cause=o,this.name=s!=null?s:ut,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(n){return n instanceof No}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Ol=zod.z.object({inputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M input tokens"),outputPricePerMillion:zod.z.number().nonnegative().describe("Price per 1M output tokens")}).describe("Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier."),Pl=zod.z.object({base:Ol.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),Rl=zod.z.object({minTokens:zod.z.number().int().nonnegative().describe("Inclusive lower token bound for this tier."),maxTokens:zod.z.number().int().nullable().optional().describe("Exclusive upper token bound; `null` means \u221E."),prices:Pl.describe("Price categories and rates for this specific token range.")}).refine(t=>t.maxTokens===null||typeof t.maxTokens=="number"&&t.maxTokens>t.minTokens,{message:"maxTokens must be > minTokens (or null for infinite).",path:["maxTokens"]}).describe("A single pricing tier defined by a token range and associated prices.");zod.z.object({modelName:zod.z.string().describe("Model name this schedule applies to."),currency:zod.z.string().default("USD").describe("Currency code (e.g., USD)."),tokenRanges:zod.z.array(Rl).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((t,n)=>{let{tokenRanges:o}=t;o[0].minTokens!==0&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let i=1;i<o.length;i++){let l=o[i-1],r=o[i];if(l.maxTokens===null){n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i-1,"maxTokens"],message:"Cannot define any tokenRanges after an infinite tier (maxTokens = null)."});break}r.minTokens!==l.maxTokens&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i,"minTokens"],message:`Tier ${i} minTokens (${r.minTokens}) must equal previous tier's maxTokens (${l.maxTokens}) for contiguity.`}),r.minTokens<l.minTokens&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",i,"minTokens"],message:`tokenRanges must be sorted by ascending minTokens. Tier ${i} (${r.minTokens}) starts before Tier ${i-1} (${l.minTokens}).`});}let s=o[o.length-1];o.every(i=>i.maxTokens!==null||i===s)&&s.maxTokens!==null&&n.addIssue({code:zod.z.ZodIssueCode.custom,path:["tokenRanges",o.length-1,"maxTokens"],message:"The final tier must have maxTokens = null (representing infinity)."});}).describe("Complete pricing schedule for a single chat model, including all its token-based tiers.");var jl="function";var El=zod.z.enum(["object","array","number","string","boolean","null"]),_l=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:El.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(_l).optional(),required:zod.z.array(zod.z.string()).optional()});var Il=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 Bl=zod.z.enum(["function"]),Al=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),Nl=zod.z.object({type:zod.z.literal("http"),method:zod.z.enum(["get","post"]),url:zod.z.string().url(),headers:zod.z.record(zod.z.string()).optional(),query:zod.z.record(zod.z.string()).optional(),body:zod.z.record(zod.z.any()).optional(),proxyUrl:zod.z.string().url().optional(),proxyHeaders:zod.z.record(zod.z.string()).optional(),retry:Al.optional()}),Ul=zod.z.discriminatedUnion("type",[Nl]);zod.z.object({type:Bl,definition:zod.z.object({schema:Il}),request:Ul.optional()});var Ll=[jl];zod.z.enum(Ll);var $l=Object.defineProperty,Uo=Object.getOwnPropertySymbols,ql=Object.prototype.hasOwnProperty,Dl=Object.prototype.propertyIsEnumerable,Lo=(t,n,o)=>n in t?$l(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o,Hl=(t,n)=>{for(var o in n||(n={}))ql.call(n,o)&&Lo(t,o,n[o]);if(Uo)for(var o of Uo(n))Dl.call(n,o)&&Lo(t,o,n[o]);return t},$o="ProviderError",yt=class Do extends ft{constructor({info:n,cause:o}){super({info:n,cause:o},$o),this.name=$o,this.info=n,this.cause=o;}static isProviderError(n){return n instanceof Do}};var qo="ModelResponseError",bt=class Ho extends ft{constructor({info:n,cause:o}){super({info:n,cause:o},qo),this.name=qo,this.cause=o,this.info=n;}static isModelResponseError(n){return n instanceof Ho}};var Fo="multi-string",Fl=zod.z.object({type:zod.z.literal(Fo),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()});var zo="object-schema",zl=zod.z.object({type:zod.z.literal(zo),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 Ko="range",Kl=zod.z.object({type:zod.z.literal(Ko),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()});var Vo="select-boolean",Vl=zod.z.object({type:zod.z.literal(Vo),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()});var kt="select-string",Jo=zod.z.object({type:zod.z.literal(kt),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())}),Jl=(t,n)=>zod.z.enum(n).nullable().default(t).optional(),Go=t=>({def:Jo.parse(Hl({type:kt},t)),schema:Jl(t.default,t.choices)}),Gl=[Ko,Fo,kt,zo,Vo];zod.z.enum(Gl);var Zl=zod.z.discriminatedUnion("type",[Kl,Fl,Jo,Vl,zl]),w=(t=gt,n=Bo)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(n).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),maxReasoningTokens:zod.z.number().int().positive().min(1).optional(),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Zl),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var s,i;let l=Object.keys(o.def),r=Object.keys((i=(s=o.schema)==null?void 0:s.shape)!=null?i:{});return l.every(d=>r.includes(d))&&r.every(d=>l.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"}),price:zod.z.custom()});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 Wl=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var Zo=t=>{if(Wl()){let n=atob(t),o=new Uint8Array(n.length);for(let s=0;s<n.length;s++)o[s]=n.charCodeAt(s);return new TextDecoder("utf-8").decode(o)}else return Buffer.from(t,"base64").toString("utf-8")};var Ct=Go({param:"awsRegion",title:"AWS Region",description:"Controls which region the model will use to call AWS services.",default:"us-east-1",choices:["us-east-1","us-west-2","eu-west-1","eu-west-3","eu-central-1","ap-south-3","ap-southeast-1","ap-southeast-2","ap-northeast-1"]});var Wo=(t,n)=>Ce(t,n).extend({awsRegion:Ct.schema}),Yo=(t,n)=>z(j({},ve(t,n)),{awsRegion:Ct.def});var y={base:(t,n)=>({def:Yo(t,n),schema:Wo(t,n)})};var Yl="bedrock",ae=class ae{constructor(){this.version="v1";this.name=Yl;this.chatModelFactories={[je]:{model:Ee,modelOptions:na,modelSchema:St},[Be]:{model:Ae,modelOptions:aa,modelSchema:Ot},[_e]:{model:Ie,modelOptions:oa,modelSchema:wt},[xe]:{model:Se,modelOptions:Qo,modelSchema:Tt},[we]:{model:Oe,modelOptions:ea,modelSchema:Mt},[Te]:{model:Me,modelOptions:Xo,modelSchema:vt},[Pe]:{model:Re,modelOptions:ta,modelSchema:xt},[Le]:{model:$e,modelOptions:sa,modelSchema:Rt},[Ne]:{model:Ue,modelOptions:ia,modelSchema:Pt}};this.embeddingModelFactories={};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((n,o)=>(n[o]=this.chatModelFactories[o].modelSchema,n),{})}chatModel(n){let o=n.modelName;if(!(o in this.chatModelFactories))throw new yt({info:`Bedrock chat model: ${o} not found`,cause:new Error(`Bedrock chat model: ${o} not found, available chat models:
|
|
19
|
+
${this.chatModelLiterals().join(", ")}`)});let s=this.chatModelFactories[o].model,i=this.chatModelFactories[o].modelOptions.parse(n);return new s(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((n,o)=>(n[o]=this.embeddingModelFactories[o].modelSchema,n),{})}embeddingModel(n){throw new yt({info:"Adaline Bedrock provider does not support embedding models yet",cause:new Error("Adaline Bedrock provider does not support embedding models yet")})}};ae.awsService="bedrock",ae.awsDefaultRegion="us-east-1",ae.awsUrl=n=>`https://bedrock-runtime.${n!=null?n:ae.awsDefaultRegion}.amazonaws.com`;var E=ae;var M=zod.z.object({modelName:zod.z.string(),awsAccessKeyId:zod.z.string(),awsSecretAccessKey:zod.z.string()});var T={"anthropic.claude-3-5-haiku-20241022-v1:0":{modelName:"anthropic.claude-3-5-haiku-20241022-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1,outputPricePerMillion:5}}}]},"anthropic.claude-3-5-sonnet-20240620-v1:0":{modelName:"anthropic.claude-3-5-sonnet-20240620-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"anthropic.claude-3-5-sonnet-20241022-v2:0":{modelName:"anthropic.claude-3-5-sonnet-20241022-v2:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"anthropic.claude-3-haiku-20240307-v1:0":{modelName:"anthropic.claude-3-haiku-20240307-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.25,outputPricePerMillion:1.25}}}]},"anthropic.claude-3-opus-20240229-v1:0":{modelName:"anthropic.claude-3-opus-20240229-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]},"anthropic.claude-3-sonnet-20240229-v1:0":{modelName:"anthropic.claude-3-sonnet-20240229-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"anthropic.claude-opus-4-20250514-v1:0":{modelName:"anthropic.claude-opus-4-20250514-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:15,outputPricePerMillion:75}}}]},"anthropic.claude-sonnet-4-20250514-v1:0":{modelName:"anthropic.claude-sonnet-4-20250514-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]},"anthropic.claude-3-7-sonnet-20250219-v1:0":{modelName:"anthropic.claude-3-7-sonnet-20250219-v1:0",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:3,outputPricePerMillion:15}}}]}};var x=class t extends ${constructor(o,s){let i=M.parse(s);super(o,{apiKey:"random-api-key",modelName:i.modelName});this.version="v1";this.modelSchema=o,this.modelName=i.modelName,this.awsService=E.awsService,this.awsAccessKeyId=i.awsAccessKeyId,this.awsSecretAccessKey=i.awsSecretAccessKey;}getDefaultBaseUrl(){return E.awsUrl()}getDefaultHeaders(){return {Accept:"application/json","Content-Type":"application/json"}}getDefaultParams(){return {anthropic_version:"bedrock-2023-05-31"}}getCompleteChatUrl(o,s,i){let l=E.awsUrl(o==null?void 0:o.awsRegion);return new Promise(r=>{r(`${l}/model/${this.modelName}/invoke`);})}transformConfig(o,s,i){let l=j({},o);return delete l.awsRegion,super.transformConfig(l,s,i)}getCompleteChatHeaders(o,s,i){return U(this,null,function*(){let l=new URL(yield this.getCompleteChatUrl(o,s,i)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},d=(o==null?void 0:o.awsRegion)||E.awsDefaultRegion,m=this.getDefaultHeaders();m=z(j({},m),{host:E.awsUrl(d).split("://")[1]});let p=yield this.getCompleteChatData(o||{},s||[],i),b=new protocolHttp.HttpRequest({hostname:l.hostname,path:l.pathname,protocol:l.protocol,method:"POST",body:JSON.stringify(p),headers:m});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:d,sha256:sha256Js.Sha256}).sign(b)).headers})}getCompleteChatData(o,s,i){return U(this,null,function*(){let l=j(j({},this.getDefaultParams()),yield pe(t.prototype,this,"getCompleteChatData").call(this,o,s,i));return new Promise(r=>{r(l);})})}getStreamChatUrl(o,s,i){return U(this,null,function*(){let l=E.awsUrl(o==null?void 0:o.awsRegion);return new Promise(r=>{r(`${l}/model/${this.modelName}/invoke-with-response-stream`);})})}getStreamChatHeaders(o,s,i){return U(this,null,function*(){let l=new URL(yield this.getStreamChatUrl(o,s,i)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},d=(o==null?void 0:o.awsRegion)||E.awsDefaultRegion,m=this.getDefaultHeaders();m=z(j({},m),{host:E.awsUrl(d).split("://")[1]});let p=yield this.getCompleteChatData(o||{},s||[],i),b=new protocolHttp.HttpRequest({hostname:l.hostname,path:l.pathname,protocol:l.protocol,method:"POST",body:JSON.stringify(p),headers:m});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:d,sha256:sha256Js.Sha256}).sign(b)).headers})}getStreamChatData(o,s,i){return U(this,null,function*(){let l=j(j({},this.getDefaultParams()),yield pe(t.prototype,this,"getStreamChatData").call(this,o,s,i));return "stream"in l&&delete l.stream,l})}transformStreamChatResponseChunk(o,s){return He(this,null,function*(){let i=o.toString(),l=/{\s*"bytes"\s*:\s*"[\w=+/]+".*?}/g,r=i.match(l)||[];for(let d of r){let m=d.indexOf("{"),p=d.indexOf("}");if(m!==-1&&p!==-1&&m<p){let b;try{b=JSON.parse(d.slice(m,p+1));}catch(u){throw new bt({info:`Malformed JSON received in stream : ${b}`,cause:u})}let v=Zo(b.bytes),h=(yield new ue(pe(t.prototype,this,"transformStreamChatResponseChunk").call(this,`data: ${v}`,s).next())).value;h&&(yield h);}}})}transformProxyStreamChatResponseChunk(o,s,i,l,r){return He(this,null,function*(){yield*he(this.transformStreamChatResponseChunk(o,s));})}getRegionHelper(o){var i;let s=o["aws-region"];if(!s){let l=(i=o.authorization)==null?void 0:i.match(/Credential=[^/]+\/\d+\/([^/]+)\/bedrock/);l&&(s=l[1]);}return s}getProxyStreamChatUrl(o,s,i){return U(this,null,function*(){let l=this.getRegionHelper(s||{}),r=E.awsUrl(l);return new Promise(d=>{d(`${r}/model/${this.modelName}/invoke-with-response-stream`);})})}getProxyChatHeaders(o,s,i,l){return U(this,null,function*(){let r=new URL(yield o());if(!i)return {};let d=i["aws-access-key-id"],m=i["aws-secret-access-key"],p=this.getRegionHelper(i);if(!d||!m)return {};let b={accessKeyId:d,secretAccessKey:m};i=z(j({},i),{host:r.host,"content-type":"application/json",accept:"application/json"}),delete i["content-length"];let v=i.authorization||i.Authorization;if(v){let _=v.match(/SignedHeaders=([^,]+)/);if(_&&_[1]){let ie=_[1].split(";").map(ce=>ce.trim().toLowerCase());ie.push("authorization"),i=Object.keys(i).reduce((ce,De)=>{var It;return ie.includes(De.toLowerCase())&&(ce[De]=(It=i==null?void 0:i[De])!=null?It:""),ce},{});}}let h=new protocolHttp.HttpRequest({hostname:r.hostname,path:r.pathname,protocol:r.protocol,method:"POST",body:JSON.stringify(s),headers:i});return (yield new signatureV4.SignatureV4({credentials:b,service:this.awsService,region:p,sha256:sha256Js.Sha256}).sign(h)).headers})}getProxyCompleteChatUrl(o,s,i){return U(this,null,function*(){let l=this.getRegionHelper(s||{}),r=E.awsUrl(l);return new Promise(d=>{d(`${r}/model/${this.modelName}/invoke`);})})}getProxyCompleteChatHeaders(o,s,i){return U(this,null,function*(){return this.getProxyChatHeaders(()=>this.getProxyCompleteChatUrl(o,s,i),o,s,i)})}getProxyStreamChatHeaders(o,s,i){return U(this,null,function*(){return this.getProxyChatHeaders(()=>this.getProxyStreamChatUrl(o,s,i),o,s,i)})}getModelPricing(){if(!(this.modelName in T))throw new bt({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return T[this.modelName]}};var Te="anthropic.claude-3-5-haiku-20241022-v1:0",Ql="Our fastest model with intelligence at blazing speeds.",vt=w(g,C).parse({name:Te,description:Ql,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:y.base(8192,4).def,schema:y.base(8192,4).schema},price:T[Te]}),Xo=M,Me=class extends x{constructor(n){super(vt,n);}};var xe="anthropic.claude-3-5-sonnet-20240620-v1:0",ed="Most intelligent model. Highest level of intelligence and capability.",Tt=w(g,C).parse({name:xe,description:ed,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:y.base(8192,4).def,schema:y.base(8192,4).schema},price:T[xe]}),Qo=M,Se=class extends x{constructor(n){super(Tt,n);}};var we="anthropic.claude-3-5-sonnet-20241022-v2:0",td="Most intelligent model. Highest level of intelligence and capability.",Mt=w(g,C).parse({name:we,description:td,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:k,config:{def:y.base(8192,4).def,schema:y.base(8192,4).schema},price:T[we]}),ea=M,Oe=class extends x{constructor(n){super(Mt,n);}};var Pe="anthropic.claude-3-7-sonnet-20250219-v1:0",nd="Most intelligent model. Highest level of intelligence and capability.",xt=w(g,C).parse({name:Pe,description:nd,maxInputTokens:2e5,maxOutputTokens:128e3,roles:f,modalities:k,config:{def:y.base(128e3,4).def,schema:y.base(128e3,4).schema},price:T[Pe]}),ta=M,Re=class extends x{constructor(n){super(xt,n);}getDefaultHeaders(){let n=super.getDefaultHeaders();return n=z(j({},n),{"anthropic-beta":"output-128k-2025-02-19"}),n}};var je="anthropic.claude-3-haiku-20240307-v1:0",od="Claude 3 Haiku is a large-scale multimodal model trained by Anthropic. It is the successor to Claude 3 and is designed to be more powerful and capable than its predecessor.",St=w(g,C).parse({name:je,description:od,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:y.base(4096,4).def,schema:y.base(4096,4).schema},price:T[je]}),na=M,Ee=class extends x{constructor(n){super(St,n);}};var _e="anthropic.claude-3-opus-20240229-v1:0",ad="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",wt=w(g,C).parse({name:_e,description:ad,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:y.base(4096,4).def,schema:y.base(4096,4).schema},price:T[_e]}),oa=M,Ie=class extends x{constructor(n){super(wt,n);}};var Be="anthropic.claude-3-sonnet-20240229-v1:0",id="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Ot=w(g,C).parse({name:Be,description:id,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:k,config:{def:y.base(4096,4).def,schema:y.base(4096,4).schema},price:T[Be]}),aa=M,Ae=class extends x{constructor(n){super(Ot,n);}};var Ne="anthropic.claude-opus-4-20250514-v1:0",sd="Our high-performance model with exceptional reasoning and efficiency. Training cutoff: March 2025.",Pt=w(g,C).parse({name:Ne,description:sd,maxInputTokens:2e5,maxOutputTokens:32e3,roles:f,modalities:k,config:{def:y.base(32e3,4).def,schema:y.base(32e3,4).schema},price:T[Ne]}),ia=M,Ue=class extends x{constructor(n){super(Pt,n);}};var Le="anthropic.claude-sonnet-4-20250514-v1:0",rd="Our most capable and intelligent model yet. Training cutoff: March 2025.",Rt=w(g,C).parse({name:Le,description:rd,maxInputTokens:2e5,maxOutputTokens:64e3,roles:f,modalities:k,config:{def:y.base(64e3,4).def,schema:y.base(64e3,4).schema},price:T[Le]}),sa=M,$e=class extends x{constructor(n){super(Rt,n);}};
|
|
20
20
|
|
|
21
21
|
exports.BaseChatModelAnthropic = x;
|
|
22
22
|
exports.BaseChatModelOptions = M;
|
|
23
23
|
exports.Bedrock = E;
|
|
24
|
-
exports.BedrockAnthropicChatModelBaseConfigDef =
|
|
25
|
-
exports.BedrockAnthropicChatModelBaseConfigSchema =
|
|
24
|
+
exports.BedrockAnthropicChatModelBaseConfigDef = Yo;
|
|
25
|
+
exports.BedrockAnthropicChatModelBaseConfigSchema = Wo;
|
|
26
26
|
exports.BedrockAnthropicChatModelConfigs = y;
|
|
27
27
|
exports.BedrockClaude3Haiku20240307 = Ee;
|
|
28
28
|
exports.BedrockClaude3Haiku20240307Literal = je;
|
|
29
|
-
exports.BedrockClaude3Haiku20240307Options =
|
|
29
|
+
exports.BedrockClaude3Haiku20240307Options = na;
|
|
30
30
|
exports.BedrockClaude3Haiku20240307Schema = St;
|
|
31
31
|
exports.BedrockClaude3Opus20240229 = Ie;
|
|
32
32
|
exports.BedrockClaude3Opus20240229Literal = _e;
|
|
33
|
-
exports.BedrockClaude3Opus20240229Options =
|
|
33
|
+
exports.BedrockClaude3Opus20240229Options = oa;
|
|
34
34
|
exports.BedrockClaude3Opus20240229Schema = wt;
|
|
35
35
|
exports.BedrockClaude3Sonnet20240229 = Ae;
|
|
36
36
|
exports.BedrockClaude3Sonnet20240229Literal = Be;
|
|
37
|
-
exports.BedrockClaude3Sonnet20240229Options =
|
|
37
|
+
exports.BedrockClaude3Sonnet20240229Options = aa;
|
|
38
38
|
exports.BedrockClaude3Sonnet20240229Schema = Ot;
|
|
39
39
|
exports.BedrockClaude3_5Haiku20241022 = Me;
|
|
40
40
|
exports.BedrockClaude3_5Haiku20241022Literal = Te;
|
|
41
|
-
exports.BedrockClaude3_5Haiku20241022Options =
|
|
41
|
+
exports.BedrockClaude3_5Haiku20241022Options = Xo;
|
|
42
42
|
exports.BedrockClaude3_5Haiku20241022Schema = vt;
|
|
43
43
|
exports.BedrockClaude3_5Sonnet20240620 = Se;
|
|
44
44
|
exports.BedrockClaude3_5Sonnet20240620Literal = xe;
|
|
45
|
-
exports.BedrockClaude3_5Sonnet20240620Options =
|
|
45
|
+
exports.BedrockClaude3_5Sonnet20240620Options = Qo;
|
|
46
46
|
exports.BedrockClaude3_5Sonnet20240620Schema = Tt;
|
|
47
47
|
exports.BedrockClaude3_5Sonnet20241022 = Oe;
|
|
48
48
|
exports.BedrockClaude3_5Sonnet20241022Literal = we;
|
|
49
|
-
exports.BedrockClaude3_5Sonnet20241022Options =
|
|
49
|
+
exports.BedrockClaude3_5Sonnet20241022Options = ea;
|
|
50
50
|
exports.BedrockClaude3_5Sonnet20241022Schema = Mt;
|
|
51
51
|
exports.BedrockClaude3_7Sonnet20250219 = Re;
|
|
52
52
|
exports.BedrockClaude3_7Sonnet20250219Literal = Pe;
|
|
53
|
-
exports.BedrockClaude3_7Sonnet20250219Options =
|
|
53
|
+
exports.BedrockClaude3_7Sonnet20250219Options = ta;
|
|
54
54
|
exports.BedrockClaude3_7Sonnet20250219Schema = xt;
|
|
55
55
|
exports.BedrockClaude4Opus20250514 = Ue;
|
|
56
56
|
exports.BedrockClaude4Opus20250514Literal = Ne;
|
|
57
|
-
exports.BedrockClaude4Opus20250514Options =
|
|
57
|
+
exports.BedrockClaude4Opus20250514Options = ia;
|
|
58
58
|
exports.BedrockClaude4Opus20250514Schema = Pt;
|
|
59
59
|
exports.BedrockClaude4Sonnet20250514 = $e;
|
|
60
60
|
exports.BedrockClaude4Sonnet20250514Literal = Le;
|
|
61
|
-
exports.BedrockClaude4Sonnet20250514Options =
|
|
61
|
+
exports.BedrockClaude4Sonnet20250514Options = sa;
|
|
62
62
|
exports.BedrockClaude4Sonnet20250514Schema = Rt;
|
|
63
63
|
exports.awsRegionChoice = Ct;
|
|
64
64
|
//# sourceMappingURL=index.js.map
|