@adaline/bedrock 2.4.0 → 2.4.2

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