@adaline/bedrock 2.5.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,11 +9,11 @@ var Za=Object.defineProperty,Wa=Object.defineProperties;var Xa=Object.getOwnProp
9
9
  Message: ${is(a)}`),this.name=et,this.info=n,this.cause=a,this.name=i!=null?i:et,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(n){return n instanceof Kn}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},ss=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."),rs=zod.z.object({base:ss.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),ls=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:rs.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(ls).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 ds="function",cs=zod.z.enum(["object","array","number","string","boolean","null"]),ms=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:cs.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(ms).optional(),required:zod.z.array(zod.z.string()).optional()});var ps=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()}),us=zod.z.enum(["function"]),hs=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),gs=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:hs.optional()}),fs=zod.z.discriminatedUnion("type",[gs]),ys=zod.z.object({type:us,definition:zod.z.object({schema:ps}),request:fs.optional()}),bs=[ds];zod.z.enum(bs);var ks=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[ys.extend({metadata:t})]),Cs=t=>En().parse({modality:E,value:t}),sn=(t,n,a,i,s,r)=>In().parse({modality:V,index:t,id:n,name:a,arguments:i,serverName:s,thoughtSignature:r}),vs=(t,n,a,i,s,r)=>Nn().parse({modality:G,index:t,id:n,name:a,data:i,apiResponse:s,metadata:r}),rn=(t,n)=>le().parse({role:t,partialContent:Bn().parse({modality:bt,value:n})}),tt=(t,n,a,i,s,r,l)=>le().parse({role:t,partialContent:An().parse({modality:kt,index:n,id:a,name:i,arguments:s,serverName:r,thoughtSignature:l})}),Ts=(t,n,a,i,s)=>le().parse({role:t,partialContent:Ln().parse({modality:Un,index:n,id:a,name:i,data:s})}),Ms=(t,n)=>ft().parse({modality:te,value:{type:xe,thinking:t,signature:n}}),xs=t=>ft().parse({modality:te,value:{type:gt,data:t}}),nt=(t,n,a)=>le().parse({role:t,partialContent:yt().parse({modality:Me,value:{type:xe,thinking:n,signature:a}})}),Ss=(t,n)=>le().parse({role:t,partialContent:yt().parse({modality:Me,value:{type:gt,data:n}})}),Os=Object.defineProperty,ln=Object.getOwnPropertySymbols,ws=Object.prototype.hasOwnProperty,Ps=Object.prototype.propertyIsEnumerable,dn=(t,n,a)=>n in t?Os(t,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[n]=a,ye=(t,n)=>{for(var a in n||(n={}))ws.call(n,a)&&dn(t,a,n[a]);if(ln)for(var a of ln(n))Ps.call(n,a)&&dn(t,a,n[a]);return t},cn="ProviderError",mn=class Vn extends oe{constructor({info:n,cause:a}){super({info:n,cause:a},cn),this.name=cn,this.info=n,this.cause=a;}static isProviderError(n){return n instanceof Vn}},pn="ModelResponseError",X=class Jn extends oe{constructor({info:n,cause:a}){super({info:n,cause:a},pn),this.name=pn,this.cause=a,this.info=n;}static isModelResponseError(n){return n instanceof Jn}},un="InvalidModelRequestError",at=class Gn extends oe{constructor({info:n,cause:a}){super({info:n,cause:a},un),this.name=un,this.cause=a,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(n){return n instanceof Gn}},hn="InvalidConfigError",Q=class Zn extends oe{constructor({info:n,cause:a}){super({info:n,cause:a},hn),this.name=hn,this.cause=a,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(n){return n instanceof Zn}},gn="InvalidMessagesError",$=class Wn extends oe{constructor({info:n,cause:a}){super({info:n,cause:a},gn),this.name=gn,this.cause=a,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(n){return n instanceof Wn}},fn="InvalidToolsError",yn=class Xn extends oe{constructor({info:n,cause:a}){super({info:n,cause:a},fn),this.name=fn,this.cause=a,this.info=n,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(n){return n instanceof Xn}},bn="InvalidEmbeddingRequestsError",kn=class Yn extends oe{constructor({info:n,cause:a}){super({info:n,cause:a},bn),this.name=bn,this.info=n,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(n){return n instanceof Yn}},Ct="multi-string",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),max:zod.z.number().int().positive()}),Rs=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),_s=t=>({def:Qn.parse(ye({type:Ct},t)),schema:Rs(t.max)}),vt="object-schema",eo=zod.z.object({type:zod.z.literal(vt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),js=t=>t.optional(),Es=t=>({def:eo.parse(ye({type:vt},t)),schema:js(t.objectSchema)}),to="paired-select",Bs=zod.z.object({value:zod.z.string().min(1),label:zod.z.string().min(1)}),Cn=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(Bs).min(1)}),Is=zod.z.object({type:zod.z.literal(to),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),fields:zod.z.tuple([Cn,Cn]),uniqueByField:zod.z.string().min(1).optional()}),Tt="range",no=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),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),As=(t,n,a,i)=>zod.z.number().min(t).max(n).step(a).default(i).optional(),be=t=>({def:no.parse(ye({type:Tt},t)),schema:As(t.min,t.max,t.step,t.default)}),Mt="select-boolean",oo=zod.z.object({type:zod.z.literal(Mt),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()}),Ns=t=>zod.z.boolean().nullable().default(t).optional(),xt=t=>({def:oo.parse(ye({type:Mt},t)),schema:Ns(t.default)}),St="select-string",ao=zod.z.object({type:zod.z.literal(St),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string(),choices:zod.z.array(zod.z.string())}),Us=(t,n)=>zod.z.enum(n).nullable().default(t).optional(),Ot=t=>({def:ao.parse(ye({type:St},t)),schema:Us(t.default,t.choices)}),Ls=[Tt,Ct,St,vt,Mt,to];zod.z.enum(Ls);var io=zod.z.discriminatedUnion("type",[no,Qn,ao,oo,eo,Is]),H=(t=Tn,n=qi)=>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),io),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=Yi)=>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),io),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 qs={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."},$s={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."},Ds={type:"range",title:"Max reasoning tokens",description:"Specify the total tokens for reasoning, where one token approximates four English characters."},Hs=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.`}),Fs={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."},zs={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."},Vs={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."},Js={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."},Gs={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."},Zs={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."},Ws={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."},Xs={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."},Ys={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."},Qs={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},er={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."},tr={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."},nr={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."},or={type:"object",title:"MCP servers",description:"MCP servers to use for the model."},B={TEMPERATURE:qs,MAX_TOKENS:$s,STOP:Hs,TOP_A:Fs,TOP_P:zs,TOP_K:Ks,MIN_P:Vs,FREQUENCY_PENALTY:Js,PRESENCE_PENALTY:Gs,REPETITION_PENALTY:Ws,SEED:Zs,LOG_PROBS:Xs,TOP_LOG_PROBS:Ys,ECHO:Qs,RESPONSE_FORMAT:er,RESPONSE_FORMAT_WITH_SCHEMA:tr,RESPONSE_SCHEMA:nr,MAX_REASONING_TOKENS:Ds,MCP_SERVERS:or},so=t=>Object.fromEntries(Object.entries(t).filter(([n,a])=>a!=null)),ge=t=>t==null?void 0:t.replace(/\/$/,""),ro=be({param:"temperature",title:B.TEMPERATURE.title,description:B.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),lo=t=>be({param:"max_tokens",title:B.MAX_TOKENS.title,description:B.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),co=t=>_s({param:"stop_sequences",title:B.STOP(t).title,description:B.STOP(t).description,max:t}),mo=be({param:"top_p",title:B.TOP_P.title,description:B.TOP_P.description,min:0,max:1,step:.01,default:1}),po=be({param:"top_k",title:B.TOP_K.title,description:B.TOP_K.description,min:0,max:1,step:.01,default:1}),uo=Ot({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"]}),ho=xt({param:"mcp",title:"MCP",description:"Enable or disable Model Context Protocol (MCP) functionality for this model.",default:!1}),go=Es({param:"mcp_servers",title:B.MCP_SERVERS.title,description:B.MCP_SERVERS.description,objectSchema:zod.z.array(Ji)}),Se=(t,n)=>zod.z.object({temperature:ro.schema,maxTokens:lo(t).schema,stop:co(n).schema,topP:mo.schema,topK:po.schema,toolChoice:uo.schema,mcp:ho.schema,mcpServers:go.schema}),Oe=(t,n)=>({temperature:ro.def,maxTokens:lo(t).def,stop:co(n).def,topP:mo.def,topK:po.def,toolChoice:uo.def,mcp:ho.def,mcpServers:go.def}),fo=(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}),yo=xt({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
10
  This can be useful for complex tasks that require more time to think.`,default:!1}),ar=(t,n,a,i)=>ne(w({},Oe(t,n)),{reasoningEnabled:yo.def,maxReasoningTokens:fo(a,i).def}),ir=(t,n,a,i)=>Se(t,n).extend({reasoningEnabled:yo.schema,maxReasoningTokens:fo(a,i).schema}),bo=Ot({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"",choices:["base64",""]}),ko=Ot({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:"",choices:["query","document",""]}),Co=xt({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0}),sr=()=>zod.z.object({encodingFormat:bo.schema,inputType:ko.schema,truncation:Co.schema}),rr=()=>({encodingFormat:bo.def,inputType:ko.def,truncation:Co.def}),S={base:(t,n)=>({def:Oe(t,n),schema:Se(t,n)}),extendedThinking:(t,n,a,i)=>({def:ar(t,n,a,i),schema:ir(t,n,a,i)})},D={base:()=>({def:rr(),schema:sr()})},lr="anthropic",Te=class{constructor(){this.version="v1",this.name=lr,this.chatModelFactories={[jo]:{model:ul,modelOptions:pl,modelSchema:Eo},[No]:{model:Tl,modelOptions:vl,modelSchema:Uo},[Io]:{model:kl,modelOptions:bl,modelSchema:Ao},[ct]:{model:al,modelOptions:ol,modelSchema:Po},[mt]:{model:rl,modelOptions:sl,modelSchema:Ro},[ut]:{model:fl,modelOptions:gl,modelSchema:Bo},[pt]:{model:cl,modelOptions:dl,modelSchema:_o},[st]:{model:Vr,modelOptions:Kr,modelSchema:xo},[dt]:{model:tl,modelOptions:el,modelSchema:wo},[it]:{model:Fr,modelOptions:Hr,modelSchema:Mo},[rt]:{model:Zr,modelOptions:Gr,modelSchema:So},[lt]:{model:Yr,modelOptions:Xr,modelSchema:Oo}},this.embeddingModelFactories={[Go]:{model:Fl,modelOptions:Hl,modelSchema:Zo},[Vo]:{model:$l,modelOptions:ql,modelSchema:Jo},[Lo]:{model:Pl,modelOptions:wl,modelSchema:qo},[$o]:{model:jl,modelOptions:_l,modelSchema:Do},[Ho]:{model:Il,modelOptions:Bl,modelSchema:Fo},[zo]:{model:Ul,modelOptions:Nl,modelSchema:Ko}};}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 mn({info:`Anthropic chat model: ${n} not found`,cause:new Error(`Anthropic chat model: ${n} not found, available chat models:
11
11
  ${this.chatModelLiterals().join(", ")}`)});let 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 mn({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 J={"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}}}]},"claude-opus-4-6":{modelName:"claude-opus-4-6",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:5,outputPricePerMillion:25}}}]}},g=zod.z.enum([fe,se,j,ht]),f={system:fe,user:se,assistant:j,tool:se},C=[E,ee,V,G],v=zod.z.enum([E,ee,V,G]),Z=[E,ee,V,G,te],W=zod.z.enum([E,ee,V,G,te]),dr=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),cr=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),mr=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string(),signature:zod.z.string()}),pr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),ur=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())}),hr=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())}),gr=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[dr,cr,mr,pr,ur,hr])),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()})}),fr=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()})})}),yr=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()})}),br=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),kr=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),Cr=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string()}),vr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),Tr=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())}),Mr=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())}),xr=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[br,kr,Cr,vr,Tr,Mr])}),Sr=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),Or=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),wr=zod.z.object({type:zod.z.literal("thinking_delta"),thinking:zod.z.string()}),Pr=zod.z.object({type:zod.z.literal("signature_delta"),signature:zod.z.string()}),Rr=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[Sr,Or,wr,Pr])}),_r=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string().optional(),signature:zod.z.string().optional()}),jr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),Er=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),Br=zod.z.object({type:zod.z.enum(["auto","any"])}),Ir=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),wt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),vo=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 To=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([wt,vo])).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 Ar=zod.z.object({enabled:zod.z.boolean().default(!0),allowed_tools:zod.z.array(zod.z.string().min(1)).optional()}),Nr=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:Ar.optional(),authorization_token:zod.z.string().min(1).optional()}),Ur=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([wt,vo,To])).min(1))}),Lr=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([wt,To,_r,jr])).min(1))}),qr=zod.z.union([Ur,Lr]),$r=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(qr).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([Br,Ir]).optional(),tools:zod.z.array(Er).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(Nr).min(1).optional()}),N=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),I=class{constructor(t,n){this.version="v1";let a=N.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=$r.safeParse(t);if(!n.success)throw new at({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 at({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=Dn().parse(so(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 b=p.content;if(typeof b=="string")l.push({role:h,content:[{modality:E,value:b}]});else {let P=b.map(u=>{if(u.type==="text")return {modality:E,value:u.text};if(u.type==="image"){let x="auto",R=u.source.media_type.split("/")[1];return {modality:ee,detail:x,value:{type:On,mediaType:R,base64:u.source.data}}}else return {modality:G,id:u.tool_use_id,index:d[u.tool_use_id].index,name:d[u.tool_use_id].name,data:typeof u.content=="string"?u.content:JSON.stringify(u.content)}});l.push({role:h,content:P});}}break;case"assistant":{let b=p.content;if(typeof b=="string")l.push({role:h,content:[{modality:E,value:b}]});else {let P=b.map((u,x)=>{if(u.type==="text")return {modality:E,value:u.text};{let R={modality:V,id:u.id,index:x,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 Q({info:`Invalid config for model : '${this.modelName}'`,cause:p.error});let h=p.data;i!==void 0&&(h.toolChoice=i),Object.keys(h).forEach(x=>{if(!(x in this.modelSchema.config.def))throw new Q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${x}',
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 J={"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}}}]},"claude-opus-4-6":{modelName:"claude-opus-4-6",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:5,outputPricePerMillion:25}}}]}},g=zod.z.enum([fe,se,j,ht]),f={system:fe,user:se,assistant:j,tool:se},C=[E,ee,V,G],v=zod.z.enum([E,ee,V,G]),Z=[E,ee,V,G,te],W=zod.z.enum([E,ee,V,G,te]),dr=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),cr=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),mr=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string(),signature:zod.z.string()}),pr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),ur=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())}),hr=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())}),gr=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[dr,cr,mr,pr,ur,hr])),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()})}),fr=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()})})}),yr=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()})}),br=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),kr=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),Cr=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string()}),vr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),Tr=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())}),Mr=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())}),xr=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[br,kr,Cr,vr,Tr,Mr])}),Sr=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),Or=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),wr=zod.z.object({type:zod.z.literal("thinking_delta"),thinking:zod.z.string()}),Pr=zod.z.object({type:zod.z.literal("signature_delta"),signature:zod.z.string()}),Rr=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[Sr,Or,wr,Pr])}),_r=zod.z.object({type:zod.z.literal("thinking"),thinking:zod.z.string().optional(),signature:zod.z.string().optional()}),jr=zod.z.object({type:zod.z.literal("redacted_thinking"),data:zod.z.string()}),Er=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),Br=zod.z.object({type:zod.z.enum(["auto","any"])}),Ir=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),wt=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),vo=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 To=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([wt,vo])).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 Ar=zod.z.object({enabled:zod.z.boolean().default(!0),allowed_tools:zod.z.array(zod.z.string().min(1)).optional()}),Nr=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:Ar.optional(),authorization_token:zod.z.string().min(1).optional()}),Ur=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([wt,vo,To])).min(1))}),Lr=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([wt,To,_r,jr])).min(1))}),qr=zod.z.union([Ur,Lr]),$r=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(qr).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([Br,Ir]).optional(),tools:zod.z.array(Er).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(Nr).min(1).optional()}),N=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),I=class{constructor(t,n){this.version="v1";let a=N.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,n){let a=0,i=!0;return t["x-should-retry"]&&(i=t["x-should-retry"].toLowerCase()!=="false"),t["retry-after"]&&(a=parseInt(t["retry-after"])*1e3),{shouldRetry:i,delayMs:a}}getTokenCount(t){return t.reduce((n,a)=>n+a.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformModelRequest(t){let n=$r.safeParse(t);if(!n.success)throw new at({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 at({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=Dn().parse(so(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 b=p.content;if(typeof b=="string")l.push({role:h,content:[{modality:E,value:b}]});else {let P=b.map(u=>{if(u.type==="text")return {modality:E,value:u.text};if(u.type==="image"){let x="auto",R=u.source.media_type.split("/")[1];return {modality:ee,detail:x,value:{type:On,mediaType:R,base64:u.source.data}}}else return {modality:G,id:u.tool_use_id,index:d[u.tool_use_id].index,name:d[u.tool_use_id].name,data:typeof u.content=="string"?u.content:JSON.stringify(u.content)}});l.push({role:h,content:P});}}break;case"assistant":{let b=p.content;if(typeof b=="string")l.push({role:h,content:[{modality:E,value:b}]});else {let P=b.map((u,x)=>{if(u.type==="text")return {modality:E,value:u.text};{let R={modality:V,id:u.id,index:x,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 Q({info:`Invalid config for model : '${this.modelName}'`,cause:p.error});let h=p.data;i!==void 0&&(h.toolChoice=i),Object.keys(h).forEach(x=>{if(!(x in this.modelSchema.config.def))throw new Q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${x}',
13
13
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let b=Object.keys(h).reduce((x,R)=>{let L=this.modelSchema.config.def[R],F=L.param,Y=h[R];return F==="max_tokens"&&L.type==="range"&&Y===0?x[F]=L.max:x[F]=Y,x},{});if(!b.max_tokens){let x=this.modelSchema.config.def.maxTokens;b.max_tokens=x.max;}if("tool_choice"in b&&b.tool_choice!==void 0){let x=b.tool_choice;if(!a||a&&a.length===0)throw new Q({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(x))b.tool_choice={type:x};else if(a.map(L=>L.definition.schema.name).includes(x))b.tool_choice={type:"tool",name:x};else throw new Q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${x}' is not part of provided 'tools' names or
14
14
  one of [${R.choices.join(", ")}]`)})}}let P=s!==void 0,u=r!==void 0;if(P!==u)throw new Q({info:`Invalid extended thinking config for model: '${this.modelName}'`,cause:new Error("Both 'reasoningEnabled' and 'maxReasoningTokens' must be defined together.")});if(P&&u){let x=b.max_tokens;if(s)if(r<x)b.thinking={type:"enabled",budget_tokens:r};else throw new Q({info:`Invalid extended thinking token budget for model: '${this.modelName}'`,cause:new Error(`maxReasoningTokens (${r}) must be less than max_tokens (${x})`)})}return l&&d&&(b.mcp_servers=d),b}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=qn().safeParse(r);if(!l.success)throw new $({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 $({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 $({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 $({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===V)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===te&&d.value.type==="thinking")l.push({type:"thinking",thinking:d.value.thinking,signature:d.value.signature});else if(d.modality===te&&d.value.type==="redacted")l.push({type:"redacted_thinking",data:d.value.data});else if(d.modality===G)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===ee){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 ht:{let l=[];r.content.forEach(d=>{if(d.modality===G)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
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(V))throw new yn({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${V}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(n=>{let a=ks().safeParse(n);if(!a.success)throw new yn({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 A(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(t,n,a){return A(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=ne(w({},i),{"anthropic-beta":`${s},${r}`}):i=ne(w({},i),{"anthropic-beta":r});}return new Promise(s=>{s(i);})})}getCompleteChatData(t,n,a){return A(this,null,function*(){let i=this.transformConfig(t,n,a),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=a?this.transformTools(a):{};return new Promise(l=>{l(w(w(w(w({},this.getDefaultParams()),i),s),r));})})}transformCompleteChatResponse(t){let n=gr.safeParse(t);if(n.success){let a=n.data,i=a.content.map((l,d)=>{if(l.type==="text")return Cs(l.text);if(l.type==="tool_use")return sn(d,l.id,l.name,JSON.stringify(l.input));if(l.type==="thinking")return Ms(l.thinking,l.signature);if(l.type==="redacted_thinking")return xs(l.data);if(l.type==="mcp_tool_use")return sn(d,l.id,l.name,JSON.stringify(l.input),l.server_name);if(l.type==="mcp_tool_result")return vs(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: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 X({info:"Invalid response from model",cause:n.error})}getStreamChatUrl(t,n,a){return A(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(t,n,a){return A(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=ne(w({},i),{"anthropic-beta":`${s},${r}`}):i=ne(w({},i),{"anthropic-beta":r});}return new Promise(s=>{s(i);})})}getStreamChatData(t,n,a){return A(this,null,function*(){let i=this.transformConfig(t,n,a),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=a?this.transformTools(a):{};return new Promise(l=>{l(w(w(w(w({stream:!0},this.getDefaultParams()),i),s),r));})})}transformStreamChatResponseChunk(t,n){return tn(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 X({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=fr.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 X({info:"Invalid response from model",cause:m.error})}else if(d.type==="message_delta"){let m=yr.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 X({info:"Invalid response from model",cause:m.error})}else if(d.type==="content_block_start"){let m=xr.safeParse(d);if(m.success){let p=m.data,h=[];p.content_block.type==="text"?h.push(rn(j,p.content_block.text)):p.content_block.type==="tool_use"?h.push(tt(j,p.index,p.content_block.id,p.content_block.name,"")):p.content_block.type==="thinking"?h.push(nt(j,p.content_block.thinking)):p.content_block.type==="redacted_thinking"?h.push(Ss(j,p.content_block.data)):p.content_block.type==="mcp_tool_use"?h.push(tt(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(Ts(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 X({info:"Invalid response from model",cause:m.error})}else if(d.type==="content_block_delta"){let m=Rr.safeParse(d);if(m.success){let p=m.data,h=[];p.delta.type==="text_delta"?h.push(rn(j,p.delta.text)):p.delta.type==="input_json_delta"?h.push(tt(j,p.index,"","",p.delta.partial_json)):p.delta.type==="thinking_delta"?h.push(nt(j,p.delta.thinking)):p.delta.type==="signature_delta"&&h.push(nt(j,void 0,p.delta.signature)),yield {partialResponse:{partialMessages:h},buffer:n};}else throw new X({info:"Invalid response from model",cause:m.error})}}else throw new X({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 tn(this,null,function*(){yield*Ce(di(this.transformStreamChatResponseChunk(t,n)));})}getProxyStreamChatUrl(t,n,a){return A(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getProxyCompleteChatUrl(t,n,a){return A(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyCompleteChatHeaders(t,n,a){return A(this,null,function*(){if(!n)return {};let i=w({},n);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(t,n,a){return A(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,n,a)})}getModelPricing(){if(!(this.modelName in J))throw new X({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return J[this.modelName]}},it="claude-4-opus-20250514",Dr="Our high-performance model with exceptional reasoning and efficiency. Training cutoff: March 2025.",Mo=H(g,W).parse({name:it,description:Dr,maxInputTokens:2e5,maxOutputTokens:32e3,maxReasoningTokens:32e3,roles:f,modalities:Z,config:{def:S.extendedThinking(32e3,4,1024,32e3).def,schema:S.extendedThinking(32e3,4,1024,32e3).schema},price:J[it]}),Hr=N,Fr=class extends I{constructor(t){super(Mo,t);}},st="claude-4-sonnet-20250514",zr="Our most capable and intelligent model yet. Training cutoff: March 2025.",xo=H(g,W).parse({name:st,description:zr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:f,modalities:Z,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:J[st]}),Kr=N,Vr=class extends I{constructor(t){super(xo,t);}},rt="claude-opus-4-5-20251101",Jr="Premium model combining maximum intelligence with practical performance. Ideal for complex specialized tasks, professional software engineering, and advanced agents. Training cutoff: August 2025.",So=H(g,W).parse({name:rt,description:Jr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:f,modalities:Z,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:J[rt]}),Gr=N,Zr=class extends I{constructor(t){super(So,t);}},lt="claude-opus-4-6",Wr="Most intelligent model for building agents and coding. Features 128K max output tokens and 1M context window in beta. Training cutoff: August 2025.",Oo=H(g,W).parse({name:lt,description:Wr,maxInputTokens:2e5,maxOutputTokens:128e3,maxReasoningTokens:128e3,roles:f,modalities:Z,config:{def:S.extendedThinking(128e3,4,1024,128e3).def,schema:S.extendedThinking(128e3,4,1024,128e3).schema},price:J[lt]}),Xr=N,Yr=class extends I{constructor(t){super(Oo,t);}},dt="claude-sonnet-4-5-20250929",Qr="Our best model for complex agents and coding, with the highest intelligence across most tasks. Training cutoff: July 2025.",wo=H(g,W).parse({name:dt,description:Qr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:f,modalities:Z,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:J[dt]}),el=N,tl=class extends I{constructor(t){super(wo,t);}},ct="claude-3-5-sonnet-20240620",nl="Most intelligent model. Highest level of intelligence and capability.",Po=H(g,v).parse({name:ct,description:nl,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:C,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:J[ct]}),ol=N,al=class extends I{constructor(t){super(Po,t);}},mt="claude-3-5-sonnet-20241022",il="Most intelligent model. Highest level of intelligence and capability.",Ro=H(g,v).parse({name:mt,description:il,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:C,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:J[mt]}),sl=N,rl=class extends I{constructor(t){super(Ro,t);}},pt="claude-3-7-sonnet-20250219",ll="Most intelligent model. Highest level of intelligence and capability.",_o=H(g,W).parse({name:pt,description:ll,maxInputTokens:2e5,maxOutputTokens:128e3,maxReasoningTokens:64e3,roles:f,modalities:Z,config:{def:S.extendedThinking(128e3,4,1024,64e3).def,schema:S.extendedThinking(128e3,4,1024,64e3).schema},price:J[pt]}),dl=N,cl=class extends I{constructor(t){super(_o,t);}getDefaultHeaders(){let t=super.getDefaultHeaders(),n=t["anthropic-beta"],a="output-128k-2025-02-19";return n?t=ne(w({},t),{"anthropic-beta":`${n},${a}`}):t=ne(w({},t),{"anthropic-beta":a}),t}},jo="claude-3-haiku-20240307",ml="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",Eo=H(g,v).parse({name:jo,description:ml,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:C,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),pl=N,ul=class extends I{constructor(t){super(Eo,t);}},ut="claude-3-5-haiku-20241022",hl="Our fastest model with intelligence at blazing speeds.",Bo=H(g,v).parse({name:ut,description:hl,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:C,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:J[ut]}),gl=N,fl=class extends I{constructor(t){super(Bo,t);}},Io="claude-3-opus-20240229",yl="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",Ao=H(g,v).parse({name:Io,description:yl,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:C,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),bl=N,kl=class extends I{constructor(t){super(Ao,t);}},No="claude-3-sonnet-20240229",Cl="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Uo=H(g,v).parse({name:No,description:Cl,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:C,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),vl=N,Tl=class extends I{constructor(t){super(Uo,t);}},ce=[re],me=zod.z.enum([re]),Ml=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()})}),xl=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),Sl=zod.z.object({model:zod.z.string().min(1).optional(),input:xl,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=Sl.safeParse(t);if(!n.success)throw new at({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=Dn().parse(so(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 Q({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 Q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
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 X({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=fr.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 X({info:"Invalid response from model",cause:m.error})}else if(d.type==="message_delta"){let m=yr.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 X({info:"Invalid response from model",cause:m.error})}else if(d.type==="content_block_start"){let m=xr.safeParse(d);if(m.success){let p=m.data,h=[];p.content_block.type==="text"?h.push(rn(j,p.content_block.text)):p.content_block.type==="tool_use"?h.push(tt(j,p.index,p.content_block.id,p.content_block.name,"")):p.content_block.type==="thinking"?h.push(nt(j,p.content_block.thinking)):p.content_block.type==="redacted_thinking"?h.push(Ss(j,p.content_block.data)):p.content_block.type==="mcp_tool_use"?h.push(tt(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(Ts(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 X({info:"Invalid response from model",cause:m.error})}else if(d.type==="content_block_delta"){let m=Rr.safeParse(d);if(m.success){let p=m.data,h=[];p.delta.type==="text_delta"?h.push(rn(j,p.delta.text)):p.delta.type==="input_json_delta"?h.push(tt(j,p.index,"","",p.delta.partial_json)):p.delta.type==="thinking_delta"?h.push(nt(j,p.delta.thinking)):p.delta.type==="signature_delta"&&h.push(nt(j,void 0,p.delta.signature)),yield {partialResponse:{partialMessages:h},buffer:n};}else throw new X({info:"Invalid response from model",cause:m.error})}}else throw new X({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 tn(this,null,function*(){yield*Ce(di(this.transformStreamChatResponseChunk(t,n)));})}getProxyStreamChatUrl(t,n,a){return A(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getProxyCompleteChatUrl(t,n,a){return A(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyCompleteChatHeaders(t,n,a){return A(this,null,function*(){if(!n)return {};let i=w({},n);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(t,n,a){return A(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,n,a)})}getModelPricing(){if(!(this.modelName in J))throw new X({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return J[this.modelName]}},it="claude-4-opus-20250514",Dr="Our high-performance model with exceptional reasoning and efficiency. Training cutoff: March 2025.",Mo=H(g,W).parse({name:it,description:Dr,maxInputTokens:2e5,maxOutputTokens:32e3,maxReasoningTokens:32e3,roles:f,modalities:Z,config:{def:S.extendedThinking(32e3,4,1024,32e3).def,schema:S.extendedThinking(32e3,4,1024,32e3).schema},price:J[it]}),Hr=N,Fr=class extends I{constructor(t){super(Mo,t);}},st="claude-4-sonnet-20250514",zr="Our most capable and intelligent model yet. Training cutoff: March 2025.",xo=H(g,W).parse({name:st,description:zr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:f,modalities:Z,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:J[st]}),Kr=N,Vr=class extends I{constructor(t){super(xo,t);}},rt="claude-opus-4-5-20251101",Jr="Premium model combining maximum intelligence with practical performance. Ideal for complex specialized tasks, professional software engineering, and advanced agents. Training cutoff: August 2025.",So=H(g,W).parse({name:rt,description:Jr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:f,modalities:Z,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:J[rt]}),Gr=N,Zr=class extends I{constructor(t){super(So,t);}},lt="claude-opus-4-6",Wr="Most intelligent model for building agents and coding. Features 128K max output tokens and 1M context window in beta. Training cutoff: August 2025.",Oo=H(g,W).parse({name:lt,description:Wr,maxInputTokens:2e5,maxOutputTokens:128e3,maxReasoningTokens:128e3,roles:f,modalities:Z,config:{def:S.extendedThinking(128e3,4,1024,128e3).def,schema:S.extendedThinking(128e3,4,1024,128e3).schema},price:J[lt]}),Xr=N,Yr=class extends I{constructor(t){super(Oo,t);}},dt="claude-sonnet-4-5-20250929",Qr="Our best model for complex agents and coding, with the highest intelligence across most tasks. Training cutoff: July 2025.",wo=H(g,W).parse({name:dt,description:Qr,maxInputTokens:2e5,maxOutputTokens:64e3,maxReasoningTokens:64e3,roles:f,modalities:Z,config:{def:S.extendedThinking(64e3,4,1024,64e3).def,schema:S.extendedThinking(64e3,4,1024,64e3).schema},price:J[dt]}),el=N,tl=class extends I{constructor(t){super(wo,t);}},ct="claude-3-5-sonnet-20240620",nl="Most intelligent model. Highest level of intelligence and capability.",Po=H(g,v).parse({name:ct,description:nl,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:C,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:J[ct]}),ol=N,al=class extends I{constructor(t){super(Po,t);}},mt="claude-3-5-sonnet-20241022",il="Most intelligent model. Highest level of intelligence and capability.",Ro=H(g,v).parse({name:mt,description:il,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:C,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:J[mt]}),sl=N,rl=class extends I{constructor(t){super(Ro,t);}},pt="claude-3-7-sonnet-20250219",ll="Most intelligent model. Highest level of intelligence and capability.",_o=H(g,W).parse({name:pt,description:ll,maxInputTokens:2e5,maxOutputTokens:128e3,maxReasoningTokens:64e3,roles:f,modalities:Z,config:{def:S.extendedThinking(128e3,4,1024,64e3).def,schema:S.extendedThinking(128e3,4,1024,64e3).schema},price:J[pt]}),dl=N,cl=class extends I{constructor(t){super(_o,t);}getDefaultHeaders(){let t=super.getDefaultHeaders(),n=t["anthropic-beta"],a="output-128k-2025-02-19";return n?t=ne(w({},t),{"anthropic-beta":`${n},${a}`}):t=ne(w({},t),{"anthropic-beta":a}),t}},jo="claude-3-haiku-20240307",ml="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",Eo=H(g,v).parse({name:jo,description:ml,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:C,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),pl=N,ul=class extends I{constructor(t){super(Eo,t);}},ut="claude-3-5-haiku-20241022",hl="Our fastest model with intelligence at blazing speeds.",Bo=H(g,v).parse({name:ut,description:hl,maxInputTokens:2e5,maxOutputTokens:8192,roles:f,modalities:C,config:{def:S.base(8192,4).def,schema:S.base(8192,4).schema},price:J[ut]}),gl=N,fl=class extends I{constructor(t){super(Bo,t);}},Io="claude-3-opus-20240229",yl="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",Ao=H(g,v).parse({name:Io,description:yl,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:C,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),bl=N,kl=class extends I{constructor(t){super(Ao,t);}},No="claude-3-sonnet-20240229",Cl="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Uo=H(g,v).parse({name:No,description:Cl,maxInputTokens:2e5,maxOutputTokens:4096,roles:f,modalities:C,config:{def:S.base(4096,4).def,schema:S.base(4096,4).schema}}),vl=N,Tl=class extends I{constructor(t){super(Uo,t);}},ce=[re],me=zod.z.enum([re]),Ml=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()})}),xl=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),Sl=zod.z.object({model:zod.z.string().min(1).optional(),input:xl,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,n){return {shouldRetry:!0,delayMs:0}}transformModelRequest(t){let n=Sl.safeParse(t);if(!n.success)throw new at({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=Dn().parse(so(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 Q({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 Q({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
17
17
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((s,r)=>{let l=this.modelSchema.config.def[r].param,d=i[r];return s[l]=d,s},{})}transformEmbeddingRequests(t){let n=ts().safeParse(t);if(!n.success)throw new kn({info:"Invalid embedding requests",cause:n.error});if(n.data.requests.length>128)throw new kn({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 A(this,null,function*(){return new Promise(a=>{a(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,n){return A(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,n){return A(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=Ml.safeParse(t);if(a.success){let i=a.data;n=typeof i.data[0].embedding=="string"?zn:Fn;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 X({info:"Invalid response from model",cause:a.error})}},Lo="voyage-code-2",Ol="Optimized for code retrieval.",qo=de(me).parse({name:Lo,description:Ol,modalities:ce,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:D.base().def,schema:D.base().schema}}),wl=ae,Pl=class extends pe{constructor(t){super(qo,t);}},$o="voyage-law-2",Rl="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",Do=de(me).parse({name:$o,description:Rl,modalities:ce,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:D.base().def,schema:D.base().schema}}),_l=ae,jl=class extends pe{constructor(t){super(Do,t);}},Ho="voyage-multilingual-2",El="Optimized for multilingual retrieval and RAG.",Fo=de(me).parse({name:Ho,description:El,modalities:ce,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:D.base().def,schema:D.base().schema}}),Bl=ae,Il=class extends pe{constructor(t){super(Fo,t);}},zo="voyage-finance-2",Al="Optimized for finance retrieval and RAG.",Ko=de(me).parse({name:zo,description:Al,modalities:ce,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:D.base().def,schema:D.base().schema}}),Nl=ae,Ul=class extends pe{constructor(t){super(Ko,t);}},Vo="voyage-3-lite",Ll="Optimized for latency and cost.",Jo=de(me).parse({name:Vo,description:Ll,modalities:ce,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:D.base().def,schema:D.base().schema}}),ql=ae,$l=class extends pe{constructor(t){super(Jo,t);}},Go="voyage-3",Dl="Optimized for quality.",Zo=de(me).parse({name:Go,description:Dl,modalities:ce,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:D.base().def,schema:D.base().schema}}),Hl=ae,Fl=class extends pe{constructor(t){super(Zo,t);}};var zl="system",Kl="user",Qo="assistant",Vl="tool",Jl=[zl,Kl,Qo,Vl],_t=zod.z.enum(Jl),Gl=[Qo],Zl=zod.z.enum(Gl),ea="error",ta="safety",Wl=zod.z.object({type:zod.z.literal(ta),value:zod.z.object({category:zod.z.string(),probability:zod.z.string(),blocked:zod.z.boolean(),message:zod.z.string()})}),Xl=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ea),value:zod.z.discriminatedUnion("type",[Wl]),metadata:t}),na="partial-error",Yl=zod.z.object({type:zod.z.literal(ta),category:zod.z.string().optional(),probability:zod.z.string().optional(),blocked:zod.z.boolean().optional(),message:zod.z.string().optional()}),Ql=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(na),value:zod.z.discriminatedUnion("type",[Yl]),metadata:t}),oa="image",ed="base64",td=["png","jpeg","webp","gif"],nd=zod.z.object({type:zod.z.literal(ed),base64:zod.z.string(),mediaType:zod.z.enum(td)}),od="url",ad=zod.z.object({type:zod.z.literal(od),url:zod.z.string()}),id=zod.z.discriminatedUnion("type",[nd,ad]),sd=["low","medium","high","auto"],rd=zod.z.enum(sd),ld=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(oa),detail:rd,value:id,metadata:t}),aa="pdf",dd="base64",cd=zod.z.object({type:zod.z.literal(dd),base64:zod.z.string()}),md="url",pd=zod.z.object({type:zod.z.literal(md),url:zod.z.string()}),ud=zod.z.discriminatedUnion("type",[cd,pd]),hd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(aa),value:ud,file:zod.z.object({name:zod.z.string(),id:zod.z.string(),size:zod.z.number().optional()}),metadata:t}),ia="reasoning",sa="partial-reasoning",ra="thinking",gd="redacted",Rt=zod.z.object({type:zod.z.literal(ra),thinking:zod.z.string(),signature:zod.z.string()}),la=zod.z.object({type:zod.z.literal(gd),data:zod.z.string()}),fd=zod.z.discriminatedUnion("type",[Rt,la]),yd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ia),value:fd,metadata:t}),bd=zod.z.object({type:zod.z.literal(ra),thinking:Rt.shape.thinking.optional(),signature:Rt.shape.signature.optional()}),kd=zod.z.discriminatedUnion("type",[bd,la]),Cd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(sa),value:kd,metadata:t}),da="search-result",ca="google",vd=zod.z.object({type:zod.z.literal(ca),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()}))}),Td=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(da),value:zod.z.discriminatedUnion("type",[vd]),metadata:t}),ma="partial-search-result",Md=zod.z.object({type:zod.z.literal(ca),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()}),xd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ma),value:zod.z.discriminatedUnion("type",[Md]),metadata:t}),pa="text",Sd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(pa),value:zod.z.string(),metadata:t}),ua="partial-text",Od=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ua),value:zod.z.string(),metadata:t}),ha="tool-call",wd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ha),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(),thoughtSignature:zod.z.string().optional(),metadata:t}),ga="partial-tool-call",Pd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ga),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(),thoughtSignature:zod.z.string().optional(),metadata:t}),fa="tool-response",Rd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(fa),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}),_d="partial-tool-response",jd=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_d),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}),Ed=[pa,oa,aa,ha,fa,ia,ea,da],ya=zod.z.enum(Ed),Bd=(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",[Sd(t),ld(n),hd(a),wd(i),Rd(s),yd(r),Xl(l),Td(d)]),Id=[ua,ga,sa,na,ma];zod.z.enum(Id);var Ad=(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",[Od(t),Pd(n),Cd(i),jd(a),Ql(s),xd(r)]);var Nd=(t=_t,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(Bd(n,a,i,s,l,r)),metadata:d}),Ud=(t=Zl,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:Ad(n,a,i,r),metadata:s}),Ld=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Wo=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),qd=Wo.extend({topLogProbs:zod.z.array(Wo)}),ba=zod.z.array(qd);zod.z.object({messages:zod.z.array(Nd()),usage:Ld.optional(),logProbs:ba.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(Ud()),usage:$d.optional(),logProbs:ba.optional()});var Dd=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:Dd.optional(),authorizationToken:zod.z.string().min(1).optional()});var Hd=["object","array","number","string","boolean","enum"],Xo=zod.z.enum(Hd),Fd=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Xo,zod.z.array(zod.z.union([Xo,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()}),zd=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(Fd),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:zd}).optional();var Kd="text",Vd="token",Jd=[Kd,Vd];zod.z.enum(Jd);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var Zd="float",Wd=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Xd="base64",Yd=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Yo=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Zd),embeddings:zod.z.array(Wd),usage:Yo.optional()}),zod.z.object({encodingFormat:zod.z.literal(Xd),embeddings:zod.z.array(Yd),usage:Yo.optional()})]);var Qd=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})},ec=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:Qd(t),Pt="GatewayBaseError",jt=class ka extends Error{constructor({info:n,cause:a},i){super(`[${i!=null?i:Pt}]: ${n}
18
18
  Message: ${ec(a)}`),this.name=Pt,this.info=n,this.cause=a,this.name=i!=null?i:Pt,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(n){return n instanceof ka}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},tc=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."),nc=zod.z.object({base:tc.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),oc=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:nc.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(oc).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 ac="function";var ic=zod.z.enum(["object","array","number","string","boolean","null"]),sc=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ic.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(sc).optional(),required:zod.z.array(zod.z.string()).optional()});var rc=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 lc=zod.z.enum(["function"]),dc=zod.z.object({maxAttempts:zod.z.number().int().positive(),initialDelay:zod.z.number().int().positive(),exponentialFactor:zod.z.number().int().positive()}),cc=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:dc.optional()}),mc=zod.z.discriminatedUnion("type",[cc]);zod.z.object({type:lc,definition:zod.z.object({schema:rc}),request:mc.optional()});var pc=[ac];zod.z.enum(pc);var uc=Object.defineProperty,Ca=Object.getOwnPropertySymbols,hc=Object.prototype.hasOwnProperty,gc=Object.prototype.propertyIsEnumerable,va=(t,n,a)=>n in t?uc(t,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[n]=a,fc=(t,n)=>{for(var a in n||(n={}))hc.call(n,a)&&va(t,a,n[a]);if(Ca)for(var a of Ca(n))gc.call(n,a)&&va(t,a,n[a]);return t},Ta="ProviderError",Et=class Sa extends jt{constructor({info:n,cause:a}){super({info:n,cause:a},Ta),this.name=Ta,this.info=n,this.cause=a;}static isProviderError(n){return n instanceof Sa}};var Ma="ModelResponseError",we=class Oa extends jt{constructor({info:n,cause:a}){super({info:n,cause:a},Ma),this.name=Ma,this.cause=a,this.info=n;}static isModelResponseError(n){return n instanceof Oa}};var wa="multi-string",yc=zod.z.object({type:zod.z.literal(wa),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 Pa="object-schema",bc=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),objectSchema:zod.z.any()});var Ra="paired-select",kc=zod.z.object({value:zod.z.string().min(1),label:zod.z.string().min(1)}),xa=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(kc).min(1)}),Cc=zod.z.object({type:zod.z.literal(Ra),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),fields:zod.z.tuple([xa,xa]),uniqueByField:zod.z.string().min(1).optional()});var _a="range",vc=zod.z.object({type:zod.z.literal(_a),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 ja="select-boolean",Tc=zod.z.object({type:zod.z.literal(ja),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 Bt="select-string",Ea=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),default:zod.z.string(),choices:zod.z.array(zod.z.string())}),Mc=(t,n)=>zod.z.enum(n).nullable().default(t).optional(),Ba=t=>({def:Ea.parse(fc({type:Bt},t)),schema:Mc(t.default,t.choices)}),xc=[_a,wa,Bt,Pa,ja,Ra];zod.z.enum(xc);var Sc=zod.z.discriminatedUnion("type",[vc,yc,Ea,Tc,bc,Cc]),O=(t=_t,n=ya)=>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),Sc),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 Oc=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var Ia=t=>{if(Oc()){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 It=Ba({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 Aa=(t,n)=>Se(t,n).extend({awsRegion:It.schema}),Na=(t,n)=>z(_({},Oe(t,n)),{awsRegion:It.def});var y={base:(t,n)=>({def:Na(t,n),schema:Aa(t,n)})};var wc="bedrock",ue=class ue{constructor(){this.version="v1";this.name=wc;this.chatModelFactories={[Ne]:{model:Ue,modelOptions:Da,modelSchema:qt},[$e]:{model:De,modelOptions:Fa,modelSchema:Dt},[Le]:{model:qe,modelOptions:Ha,modelSchema:$t},[_e]:{model:je,modelOptions:La,modelSchema:Nt},[Ee]:{model:Be,modelOptions:qa,modelSchema:Ut},[Pe]:{model:Re,modelOptions:Ua,modelSchema:At},[Ie]:{model:Ae,modelOptions:$a,modelSchema:Lt},[ze]:{model:Ke,modelOptions:Ka,modelSchema:Ft},[We]:{model:Xe,modelOptions:Ga,modelSchema:Vt},[He]:{model:Fe,modelOptions:za,modelSchema:Ht},[Ve]:{model:Je,modelOptions:Va,modelSchema:zt},[Ge]:{model:Ze,modelOptions:Ja,modelSchema:Kt}};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 Et({info:`Bedrock chat model: ${s} not found`,cause:new Error(`Bedrock chat model: ${s} not found, available chat models:
19
19
  ${this.chatModelLiterals().join(", ")}`)});let r=this.chatModelFactories[s].model,l=this.chatModelFactories[s].modelOptions.parse(n);return new r(z(_({},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 Et({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 U=ue;var T=zod.z.object({modelName:zod.z.string(),awsAccessKeyId:zod.z.string(),awsSecretAccessKey:zod.z.string()});var k={"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}}}]},"anthropic.claude-opus-4-6-v1":{modelName:"anthropic.claude-opus-4-6-v1",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:5,outputPricePerMillion:25}}}]}};var M=class t extends I{constructor(a,i){let s=T.parse(i);super(a,{apiKey:"random-api-key",modelName:s.modelName});this.version="v1";this.modelSchema=a,this.modelName=s.modelName,this.awsService=U.awsService,this.awsAccessKeyId=s.awsAccessKeyId,this.awsSecretAccessKey=s.awsSecretAccessKey;}getDefaultBaseUrl(){return U.awsUrl()}getDefaultHeaders(){return {Accept:"application/json","Content-Type":"application/json"}}getDefaultParams(){return {anthropic_version:"bedrock-2023-05-31"}}getCompleteChatUrl(a,i,s){let r=U.awsUrl(a==null?void 0:a.awsRegion);return new Promise(l=>{l(`${r}/model/${this.modelName}/invoke`);})}transformConfig(a,i,s){let r=_({},a);return delete r.awsRegion,super.transformConfig(r,i,s)}getCompleteChatHeaders(a,i,s){return K(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)||U.awsDefaultRegion,m=this.getDefaultHeaders();m=z(_({},m),{host:U.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 K(this,null,function*(){let r=_(_({},this.getDefaultParams()),yield ke(t.prototype,this,"getCompleteChatData").call(this,a,i,s));return new Promise(l=>{l(r);})})}getStreamChatUrl(a,i,s){return K(this,null,function*(){let r=U.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 K(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)||U.awsDefaultRegion,m=this.getDefaultHeaders();m=z(_({},m),{host:U.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 K(this,null,function*(){let r=_(_({},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 Qe(this,null,function*(){let s=a.toString(),r=/{\s*"bytes"\s*:\s*"[\w=+/]+".*?}/g,l=s.match(r)||[];if(l.length!==0)for(let b of l){let P=b.indexOf("{"),u=b.indexOf("}");if(P===-1||u===-1||P>=u)continue;let x,R=b.slice(P,u+1);try{x=JSON.parse(R);}catch(q){throw new we({info:`Malformed JSON received in stream : ${R}`,cause:q})}let L=Ia(x.bytes),F="message_delta";try{let q=JSON.parse(L);q.type&&(F=q.type);}catch(q){throw new we({info:`Malformed JSON received in stream : ${L}`,cause:q})}let Y=`event: ${F}