@adaline/bedrock 0.19.0 → 0.20.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.d.mts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.js +40 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -5,51 +5,51 @@ var sha256Js = require('@aws-crypto/sha256-js');
|
|
|
5
5
|
var protocolHttp = require('@smithy/protocol-http');
|
|
6
6
|
var signatureV4 = require('@smithy/signature-v4');
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
Message: ${Na(a)}`),this.name=ve,this.info=t,this.cause=a,this.name=s!=null?s:ve,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof Tt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},te="system",$="user",I="assistant",we="tool",Ua=[te,$,I,we],Mt=zod.z.enum(Ua),qa=[I],$a=zod.z.enum(qa),V="image",Ot="base64",Ha=["png","jpeg","webp","gif"],Fa=zod.z.object({type:zod.z.literal(Ot),base64:zod.z.string(),media_type:zod.z.enum(Ha)}),Da="url",Ka=zod.z.object({type:zod.z.literal(Da),url:zod.z.string()}),za=zod.z.discriminatedUnion("type",[Fa,Ka]),Va=["low","medium","high","auto"],Ja=zod.z.enum(Va),Ga=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(V),detail:Ja,value:za,metadata:o}),O="text",jt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(O),value:zod.z.string(),metadata:o}),Se="partial-text",Et=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Se),value:zod.z.string(),metadata:o}),N="tool-call",Pt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(N),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:o}),xe="partial-tool-call",_t=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(xe),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:o}),J="tool-response",Wa=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(J),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:o}),Za=[O,V,N,J],Ya=zod.z.enum(Za),Qa=(o=zod.z.undefined(),t=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[jt(o),Ga(t),Pt(a),Wa(s)]),Xa=[Se,xe];zod.z.enum(Xa);var en=(o=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Et(o),_t(t)]),Rt=(o=Mt,t=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined())=>zod.z.object({role:o,content:zod.z.array(Qa(t,a,s,i)),metadata:l}),Te=(o=$a,t=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:o,partialContent:en(t,a),metadata:s}),tn=o=>jt().parse({modality:O,value:o}),on=(o,t,a,s)=>Pt().parse({modality:N,index:o,id:t,name:a,arguments:s}),rt=(o,t)=>Te().parse({role:o,partialContent:Et().parse({modality:Se,value:t})}),lt=(o,t,a,s,i)=>Te().parse({role:o,partialContent:_t().parse({modality:xe,index:t,id:a,name:s,arguments:i})}),It=(o=zod.z.record(zod.z.string(),zod.z.any()).optional())=>o,an=["object","array","number","string","boolean","enum"],dt=zod.z.enum(an),nn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([dt,zod.z.array(zod.z.union([dt,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()}),sn=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(nn),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:sn}).optional();var rn="function",ln=zod.z.enum(["object","array","number","string","boolean","null"]),dn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ln.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(dn).optional(),required:zod.z.array(zod.z.string()).optional()});var mn=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()}),cn=zod.z.enum(["function"]),pn=zod.z.object({type:cn,definition:zod.z.object({schema:mn})}),un=[rn];zod.z.enum(un);var hn=(o=zod.z.undefined())=>zod.z.discriminatedUnion("type",[pn.extend({metadata:o})]),G="text",Bt="token",gn=[G,Bt],fn=zod.z.enum(gn),yn=zod.z.array(zod.z.string().min(1)),bn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Cn=(o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(G),metadata:o,requests:yn}),zod.z.object({modality:zod.z.literal(Bt),metadata:o,requests:bn})]),At="float",vn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Lt="base64",kn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),mt=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(At),embeddings:zod.z.array(vn),usage:mt.optional()}),zod.z.object({encodingFormat:zod.z.literal(Lt),embeddings:zod.z.array(kn),usage:mt.optional()})]);var Nt=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),ct=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),wn=ct.extend({topLogProbs:zod.z.array(ct)}),Ut=zod.z.array(wn);zod.z.object({messages:zod.z.array(Rt()),usage:Nt.optional(),logProbs:Ut.optional()});zod.z.object({partialMessages:zod.z.array(Te()),usage:Nt.optional(),logProbs:Ut.optional()});var Sn=Object.defineProperty,pt=Object.getOwnPropertySymbols,xn=Object.prototype.hasOwnProperty,Tn=Object.prototype.propertyIsEnumerable,ut=(o,t,a)=>t in o?Sn(o,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[t]=a,de=(o,t)=>{for(var a in t||(t={}))xn.call(t,a)&&ut(o,a,t[a]);if(pt)for(var a of pt(t))Tn.call(t,a)&&ut(o,a,t[a]);return o},ht="ProviderError",gt=class qt extends F{constructor({info:t,cause:a}){super({info:t,cause:a},ht),this.name=ht,this.info=t,this.cause=a;}static isProviderError(t){return t instanceof qt}},ft="ModelResponseError",q=class $t extends F{constructor({info:t,cause:a}){super({info:t,cause:a},ft),this.name=ft,this.cause=a,this.info=t;}static isModelResponseError(t){return t instanceof $t}},yt="InvalidModelRequestError",ke=class Ht extends F{constructor({info:t,cause:a}){super({info:t,cause:a},yt),this.name=yt,this.cause=a,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Ht}},bt="InvalidConfigError",z=class Ft extends F{constructor({info:t,cause:a}){super({info:t,cause:a},bt),this.name=bt,this.cause=a,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Ft}},Ct="InvalidMessagesError",M=class Dt extends F{constructor({info:t,cause:a}){super({info:t,cause:a},Ct),this.name=Ct,this.cause=a,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof Dt}},vt="InvalidToolsError",kt=class Kt extends F{constructor({info:t,cause:a}){super({info:t,cause:a},vt),this.name=vt,this.cause=a,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof Kt}},wt="InvalidEmbeddingRequestsError",St=class zt extends F{constructor({info:t,cause:a}){super({info:t,cause:a},wt),this.name=wt,this.info=t,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof zt}},Me="multi-string",Vt=zod.z.object({type:zod.z.literal(Me),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()}),Mn=o=>zod.z.array(zod.z.string()).max(o).default([]).optional(),On=o=>({def:Vt.parse(de({type:Me},o)),schema:Mn(o.max)}),Jt="object-schema",jn=zod.z.object({type:zod.z.literal(Jt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),Oe="range",Gt=zod.z.object({type:zod.z.literal(Oe),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()}),En=(o,t,a,s)=>zod.z.number().min(o).max(t).step(a).default(s).optional(),me=o=>({def:Gt.parse(de({type:Oe},o)),schema:En(o.min,o.max,o.step,o.default)}),je="select-boolean",Wt=zod.z.object({type:zod.z.literal(je),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()}),Pn=o=>zod.z.boolean().nullable().default(o).optional(),_n=o=>({def:Wt.parse(de({type:je},o)),schema:Pn(o.default)}),Ee="select-string",Zt=zod.z.object({type:zod.z.literal(Ee),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))}),Rn=(o,t)=>zod.z.enum(t).nullable().default(o).optional(),Pe=o=>({def:Zt.parse(de({type:Ee},o)),schema:Rn(o.default,o.choices)}),In=[Oe,Me,Ee,Jt,je];zod.z.enum(In);var Yt=zod.z.discriminatedUnion("type",[Gt,Vt,Zt,Wt,jn]),H=(o=Mt,t=Ya)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(o,zod.z.string().min(1).optional()),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),Yt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var s,i;let l=Object.keys(a.def),r=Object.keys((i=(s=a.schema)==null?void 0:s.shape)!=null?i:{});return l.every(d=>r.includes(d))&&r.every(d=>l.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),W=(o=fn)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(o).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),Yt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var a,s;let i=Object.keys(t.def),l=Object.keys((s=(a=t.schema)==null?void 0:a.shape)!=null?s:{});return i.every(r=>l.includes(r))&&l.every(r=>i.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var Bn={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."},An={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."},Ln=o=>({type:"multi",title:"Stop sequence",description:`Enter up to ${o} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Nn={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."},Un={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."},qn={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."},$n={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."},Hn={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."},Fn={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."},Dn={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."},Kn={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."},zn={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."},Vn={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."},Jn={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Gn={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."},Wn={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."},Zn={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},A={TEMPERATURE:Bn,MAX_TOKENS:An,STOP:Ln,TOP_A:Nn,TOP_P:Un,TOP_K:qn,MIN_P:$n,FREQUENCY_PENALTY:Hn,PRESENCE_PENALTY:Fn,REPETITION_PENALTY:Kn,SEED:Dn,LOG_PROBS:zn,TOP_LOG_PROBS:Vn,ECHO:Jn,RESPONSE_FORMAT:Gn,RESPONSE_FORMAT_WITH_SCHEMA:Wn,RESPONSE_SCHEMA:Zn},Qt=o=>Object.fromEntries(Object.entries(o).filter(([t,a])=>a!=null)),ee=o=>o==null?void 0:o.replace(/\/$/,""),Xt=me({param:"temperature",title:A.TEMPERATURE.title,description:A.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),eo=o=>me({param:"max_tokens",title:A.MAX_TOKENS.title,description:A.MAX_TOKENS.description,min:0,max:o,step:1,default:0}),to=o=>On({param:"stop_sequences",title:A.STOP(o).title,description:A.STOP(o).description,max:o}),oo=me({param:"top_p",title:A.TOP_P.title,description:A.TOP_P.description,min:0,max:1,step:.01,default:1}),ao=me({param:"top_k",title:A.TOP_K.title,description:A.TOP_K.description,min:0,max:1,step:.01,default:1}),no=Pe({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"]}),_e=(o,t)=>zod.z.object({temperature:Xt.schema,maxTokens:eo(o).schema,stop:to(t).schema,topP:oo.schema,topK:ao.schema,toolChoice:no.schema}),Re=(o,t)=>({temperature:Xt.def,maxTokens:eo(o).def,stop:to(t).def,topP:oo.def,topK:ao.def,toolChoice:no.def}),so=Pe({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:null,choices:["base64"]}),io=Pe({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:null,choices:["query","document"]}),ro=_n({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0}),Yn=()=>zod.z.object({encodingFormat:so.schema,inputType:io.schema,truncation:ro.schema}),Qn=()=>({encodingFormat:so.def,inputType:io.def,truncation:ro.def}),w={base:(o,t)=>({def:Re(o,t),schema:_e(o,t)})},E={base:()=>({def:Qn(),schema:Yn()})},Xn="anthropic",le=class{constructor(){this.version="v1",this.name=Xn,this.chatModelFactories={[yo]:{model:Es,modelOptions:js,modelSchema:bo},[To]:{model:Hs,modelOptions:$s,modelSchema:Mo},[So]:{model:Us,modelOptions:Ns,modelSchema:xo},[co]:{model:vs,modelOptions:Cs,modelSchema:po},[uo]:{model:Ss,modelOptions:ws,modelSchema:ho},[Co]:{model:Rs,modelOptions:_s,modelSchema:vo},[go]:{model:Ms,modelOptions:Ts,modelSchema:fo},[ko]:{model:As,modelOptions:Bs,modelSchema:wo}},this.embeddingModelFactories={[No]:{model:li,modelOptions:ri,modelSchema:Uo},[Ao]:{model:si,modelOptions:ni,modelSchema:Lo},[Oo]:{model:Js,modelOptions:Vs,modelSchema:jo},[Eo]:{model:Zs,modelOptions:Ws,modelSchema:Po},[_o]:{model:Xs,modelOptions:Qs,modelSchema:Ro},[Io]:{model:oi,modelOptions:ti,modelSchema:Bo}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((o,t)=>(o[t]=this.chatModelFactories[t].modelSchema,o),{})}chatModel(o){let t=o.modelName;if(!(t in this.chatModelFactories))throw new gt({info:`Anthropic chat model: ${t} not found`,cause:new Error(`Anthropic chat model: ${t} not found, available chat models:
|
|
10
|
-
${this.chatModelLiterals().join(", ")}`)});let a=this.chatModelFactories[
|
|
11
|
-
${this.embeddingModelLiterals().join(", ")}`)});let a=this.embeddingModelFactories[
|
|
12
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let d=Object.keys(r).reduce((m,p)=>{let h=this.modelSchema.config.def[p],g=h.param,k=r[p];return g==="max_tokens"&&h.type==="range"&&k===0?m[g]=h.max:m[g]=k,m},{});if(!d.max_tokens){let m=this.modelSchema.config.def.maxTokens;d.max_tokens=m.max;}if("tool_choice"in d&&d.tool_choice!==void 0){let m=d.tool_choice;if(!a||a&&a.length===0)throw new
|
|
13
|
-
one of [${p.choices.join(", ")}]`)})}}return d}transformMessages(
|
|
8
|
+
var Ta=Object.defineProperty,Ma=Object.defineProperties;var Oa=Object.getOwnPropertyDescriptors;var st=Object.getOwnPropertySymbols,ja=Object.getPrototypeOf,Ea=Object.prototype.hasOwnProperty,Pa=Object.prototype.propertyIsEnumerable,_a=Reflect.get;var se=(t,o)=>(o=Symbol[t])?o:Symbol.for("Symbol."+t),Ra=t=>{throw TypeError(t)};var it=(t,o,a)=>o in t?Ta(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,_=(t,o)=>{for(var a in o||(o={}))Ea.call(o,a)&&it(t,a,o[a]);if(st)for(var a of st(o))Pa.call(o,a)&&it(t,a,o[a]);return t},K=(t,o)=>Ma(t,Oa(o));var ie=(t,o,a)=>_a(ja(t),a,o);var R=(t,o,a)=>new Promise((s,i)=>{var l=m=>{try{d(a.next(m));}catch(p){i(p);}},r=m=>{try{d(a.throw(m));}catch(p){i(p);}},d=m=>m.done?s(m.value):Promise.resolve(m.value).then(l,r);d((a=a.apply(t,o)).next());}),re=function(t,o){this[0]=t,this[1]=o;},ke=(t,o,a)=>{var s=(r,d,m,p)=>{try{var h=a[r](d),g=(d=h.value)instanceof re,k=h.done;Promise.resolve(g?d[0]:d).then(u=>g?s(r==="return"?r:"next",d[1]?{done:u.done,value:u.value}:u,m,p):m({value:u,done:k})).catch(u=>s("throw",u,m,p));}catch(u){p(u);}},i=r=>l[r]=d=>new Promise((m,p)=>s(r,d,m,p)),l={};return a=a.apply(t,o),l[se("asyncIterator")]=()=>l,i("next"),i("throw"),i("return"),l},le=t=>{var o=t[se("asyncIterator")],a=!1,s,i={};return o==null?(o=t[se("iterator")](),s=l=>i[l]=r=>o[l](r)):(o=o.call(t),s=l=>i[l]=r=>{if(a){if(a=!1,l==="throw")throw r;return r}return a=!0,{done:!1,value:new re(new Promise(d=>{var m=o[l](r);m instanceof Object||Ra("Object expected"),d(m);}),1)}}),i[se("iterator")]=()=>i,s("next"),"throw"in o?s("throw"):i.throw=l=>{throw l},"return"in o&&s("return"),i};var Ia=Object.defineProperty,Ba=Object.defineProperties,Aa=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertySymbols,La=Object.prototype.hasOwnProperty,Na=Object.prototype.propertyIsEnumerable,de=(t,o)=>(o=Symbol[t])?o:Symbol.for("Symbol."+t),Ua=t=>{throw TypeError(t)},lt=(t,o,a)=>o in t?Ia(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,S=(t,o)=>{for(var a in o||(o={}))La.call(o,a)&<(t,a,o[a]);if(rt)for(var a of rt(o))Na.call(o,a)&<(t,a,o[a]);return t},dt=(t,o)=>Ba(t,Aa(o)),j=(t,o,a)=>new Promise((s,i)=>{var l=m=>{try{d(a.next(m));}catch(p){i(p);}},r=m=>{try{d(a.throw(m));}catch(p){i(p);}},d=m=>m.done?s(m.value):Promise.resolve(m.value).then(l,r);d((a=a.apply(t,o)).next());}),jt=function(t,o){this[0]=t,this[1]=o;},mt=(t,o,a)=>{var s=(r,d,m,p)=>{try{var h=a[r](d),g=(d=h.value)instanceof jt,k=h.done;Promise.resolve(g?d[0]:d).then(u=>g?s(r==="return"?r:"next",d[1]?{done:u.done,value:u.value}:u,m,p):m({value:u,done:k})).catch(u=>s("throw",u,m,p));}catch(u){p(u);}},i=r=>l[r]=d=>new Promise((m,p)=>s(r,d,m,p)),l={};return a=a.apply(t,o),l[de("asyncIterator")]=()=>l,i("next"),i("throw"),i("return"),l},qa=t=>{var o=t[de("asyncIterator")],a=!1,s,i={};return o==null?(o=t[de("iterator")](),s=l=>i[l]=r=>o[l](r)):(o=o.call(t),s=l=>i[l]=r=>{if(a){if(a=!1,l==="throw")throw r;return r}return a=!0,{done:!1,value:new jt(new Promise(d=>{var m=o[l](r);m instanceof Object||Ua("Object expected"),d(m);}),1)}}),i[de("iterator")]=()=>i,s("next"),"throw"in o?s("throw"):i.throw=l=>{throw l},"return"in o&&s("return"),i},$a=t=>{let o=new WeakSet;return JSON.stringify(t,(a,s)=>{if(typeof s=="object"&&s!==null){if(o.has(s))return;o.add(s);}return s})},Ha=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:$a(t),we="GatewayBaseError",D=class Et extends Error{constructor({info:o,cause:a},s){super(`[${s!=null?s:we}]: ${o}
|
|
9
|
+
Message: ${Ha(a)}`),this.name=we,this.info=o,this.cause=a,this.name=s!=null?s:we,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(o){return o instanceof Et}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},oe="system",H="user",I="assistant",xe="tool",Fa=[oe,H,I,xe],Pt=zod.z.enum(Fa),Da=[I],za=zod.z.enum(Da),J="image",_t="base64",Ka=["png","jpeg","webp","gif"],Va=zod.z.object({type:zod.z.literal(_t),base64:zod.z.string(),media_type:zod.z.enum(Ka)}),Ja="url",Ga=zod.z.object({type:zod.z.literal(Ja),url:zod.z.string()}),Wa=zod.z.discriminatedUnion("type",[Va,Ga]),Za=["low","medium","high","auto"],Ya=zod.z.enum(Za),Qa=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(J),detail:Ya,value:Wa,metadata:t}),O="text",Rt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(O),value:zod.z.string(),metadata:t}),Te="partial-text",It=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Te),value:zod.z.string(),metadata:t}),N="tool-call",Bt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(N),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),Me="partial-tool-call",At=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Me),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),G="tool-response",Xa=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(G),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),en=[O,J,N,G],tn=zod.z.enum(en),on=(t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Rt(t),Qa(o),Bt(a),Xa(s)]),an=[Te,Me];zod.z.enum(an);var nn=(t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[It(t),At(o)]),Lt=(t=Pt,o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(on(o,a,s,i)),metadata:l}),Oe=(t=za,o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,partialContent:nn(o,a),metadata:s}),sn=t=>Rt().parse({modality:O,value:t}),rn=(t,o,a,s)=>Bt().parse({modality:N,index:t,id:o,name:a,arguments:s}),ct=(t,o)=>Oe().parse({role:t,partialContent:It().parse({modality:Te,value:o})}),pt=(t,o,a,s,i)=>Oe().parse({role:t,partialContent:At().parse({modality:Me,index:o,id:a,name:s,arguments:i})}),Nt=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,ln=["object","array","number","string","boolean","enum"],ut=zod.z.enum(ln),dn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([ut,zod.z.array(zod.z.union([ut,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),mn=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(dn),additionalProperties:zod.z.literal(!1)});zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:mn}).optional();var cn="function",pn=zod.z.enum(["object","array","number","string","boolean","null"]),un=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:pn.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(un).optional(),required:zod.z.array(zod.z.string()).optional()});var hn=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()}),gn=zod.z.enum(["function"]),fn=zod.z.object({type:gn,definition:zod.z.object({schema:hn})}),yn=[cn];zod.z.enum(yn);var bn=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[fn.extend({metadata:t})]),W="text",Ut="token",Cn=[W,Ut],vn=zod.z.enum(Cn),kn=zod.z.array(zod.z.string().min(1)),wn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Sn=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(W),metadata:t,requests:kn}),zod.z.object({modality:zod.z.literal(Ut),metadata:t,requests:wn})]),qt="float",xn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),$t="base64",Tn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),ht=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(qt),embeddings:zod.z.array(xn),usage:ht.optional()}),zod.z.object({encodingFormat:zod.z.literal($t),embeddings:zod.z.array(Tn),usage:ht.optional()})]);var Ht=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),gt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Mn=gt.extend({topLogProbs:zod.z.array(gt)}),Ft=zod.z.array(Mn);zod.z.object({messages:zod.z.array(Lt()),usage:Ht.optional(),logProbs:Ft.optional()});zod.z.object({partialMessages:zod.z.array(Oe()),usage:Ht.optional(),logProbs:Ft.optional()});var On=Object.defineProperty,ft=Object.getOwnPropertySymbols,jn=Object.prototype.hasOwnProperty,En=Object.prototype.propertyIsEnumerable,yt=(t,o,a)=>o in t?On(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,ce=(t,o)=>{for(var a in o||(o={}))jn.call(o,a)&&yt(t,a,o[a]);if(ft)for(var a of ft(o))En.call(o,a)&&yt(t,a,o[a]);return t},bt="ProviderError",Ct=class Dt extends D{constructor({info:o,cause:a}){super({info:o,cause:a},bt),this.name=bt,this.info=o,this.cause=a;}static isProviderError(o){return o instanceof Dt}},vt="ModelResponseError",$=class zt extends D{constructor({info:o,cause:a}){super({info:o,cause:a},vt),this.name=vt,this.cause=a,this.info=o;}static isModelResponseError(o){return o instanceof zt}},kt="InvalidModelRequestError",Se=class Kt extends D{constructor({info:o,cause:a}){super({info:o,cause:a},kt),this.name=kt,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(o){return o instanceof Kt}},wt="InvalidConfigError",V=class Vt extends D{constructor({info:o,cause:a}){super({info:o,cause:a},wt),this.name=wt,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(o){return o instanceof Vt}},St="InvalidMessagesError",M=class Jt extends D{constructor({info:o,cause:a}){super({info:o,cause:a},St),this.name=St,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(o){return o instanceof Jt}},xt="InvalidToolsError",Tt=class Gt extends D{constructor({info:o,cause:a}){super({info:o,cause:a},xt),this.name=xt,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(o){return o instanceof Gt}},Mt="InvalidEmbeddingRequestsError",Ot=class Wt extends D{constructor({info:o,cause:a}){super({info:o,cause:a},Mt),this.name=Mt,this.info=o,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(o){return o instanceof Wt}},je="multi-string",Zt=zod.z.object({type:zod.z.literal(je),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()}),Pn=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),_n=t=>({def:Zt.parse(ce({type:je},t)),schema:Pn(t.max)}),Yt="object-schema",Rn=zod.z.object({type:zod.z.literal(Yt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),Ee="range",Qt=zod.z.object({type:zod.z.literal(Ee),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()}),In=(t,o,a,s)=>zod.z.number().min(t).max(o).step(a).default(s).optional(),pe=t=>({def:Qt.parse(ce({type:Ee},t)),schema:In(t.min,t.max,t.step,t.default)}),Pe="select-boolean",Xt=zod.z.object({type:zod.z.literal(Pe),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()}),Bn=t=>zod.z.boolean().nullable().default(t).optional(),An=t=>({def:Xt.parse(ce({type:Pe},t)),schema:Bn(t.default)}),_e="select-string",eo=zod.z.object({type:zod.z.literal(_e),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string(),choices:zod.z.array(zod.z.string())}),Ln=(t,o)=>zod.z.enum(o).nullable().default(t).optional(),Re=t=>({def:eo.parse(ce({type:_e},t)),schema:Ln(t.default,t.choices)}),Nn=[Ee,je,_e,Yt,Pe];zod.z.enum(Nn);var to=zod.z.discriminatedUnion("type",[Qt,Zt,eo,Xt,Rn]),F=(t=Pt,o=tn)=>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(o).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),to),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var s,i;let l=Object.keys(a.def),r=Object.keys((i=(s=a.schema)==null?void 0:s.shape)!=null?i:{});return l.every(d=>r.includes(d))&&r.every(d=>l.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),Z=(t=vn)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),to),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var a,s;let i=Object.keys(o.def),l=Object.keys((s=(a=o.schema)==null?void 0:a.shape)!=null?s:{});return i.every(r=>l.includes(r))&&l.every(r=>i.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var Un={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."},qn={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."},$n=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.`}),Hn={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."},Fn={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."},Dn={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},zn={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},Kn={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."},Vn={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."},Jn={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."},Gn={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."},Wn={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."},Zn={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."},Yn={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Qn={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."},Xn={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."},es={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},A={TEMPERATURE:Un,MAX_TOKENS:qn,STOP:$n,TOP_A:Hn,TOP_P:Fn,TOP_K:Dn,MIN_P:zn,FREQUENCY_PENALTY:Kn,PRESENCE_PENALTY:Vn,REPETITION_PENALTY:Gn,SEED:Jn,LOG_PROBS:Wn,TOP_LOG_PROBS:Zn,ECHO:Yn,RESPONSE_FORMAT:Qn,RESPONSE_FORMAT_WITH_SCHEMA:Xn,RESPONSE_SCHEMA:es},oo=t=>Object.fromEntries(Object.entries(t).filter(([o,a])=>a!=null)),te=t=>t==null?void 0:t.replace(/\/$/,""),ao=pe({param:"temperature",title:A.TEMPERATURE.title,description:A.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),no=t=>pe({param:"max_tokens",title:A.MAX_TOKENS.title,description:A.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),so=t=>_n({param:"stop_sequences",title:A.STOP(t).title,description:A.STOP(t).description,max:t}),io=pe({param:"top_p",title:A.TOP_P.title,description:A.TOP_P.description,min:0,max:1,step:.01,default:1}),ro=pe({param:"top_k",title:A.TOP_K.title,description:A.TOP_K.description,min:0,max:1,step:.01,default:1}),lo=Re({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"]}),Ie=(t,o)=>zod.z.object({temperature:ao.schema,maxTokens:no(t).schema,stop:so(o).schema,topP:io.schema,topK:ro.schema,toolChoice:lo.schema}),Be=(t,o)=>({temperature:ao.def,maxTokens:no(t).def,stop:so(o).def,topP:io.def,topK:ro.def,toolChoice:lo.def}),mo=Re({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"",choices:["base64",""]}),co=Re({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:"",choices:["query","document",""]}),po=An({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0}),ts=()=>zod.z.object({encodingFormat:mo.schema,inputType:co.schema,truncation:po.schema}),os=()=>({encodingFormat:mo.def,inputType:co.def,truncation:po.def}),w={base:(t,o)=>({def:Be(t,o),schema:Ie(t,o)})},E={base:()=>({def:os(),schema:ts()})},as="anthropic",me=class{constructor(){this.version="v1",this.name=as,this.chatModelFactories={[ko]:{model:Is,modelOptions:Rs,modelSchema:wo},[Eo]:{model:Ks,modelOptions:zs,modelSchema:Po},[Oo]:{model:Fs,modelOptions:Hs,modelSchema:jo},[go]:{model:xs,modelOptions:Ss,modelSchema:fo},[yo]:{model:Os,modelOptions:Ms,modelSchema:bo},[So]:{model:Ls,modelOptions:As,modelSchema:xo},[Co]:{model:Ps,modelOptions:Es,modelSchema:vo},[To]:{model:qs,modelOptions:Us,modelSchema:Mo}},this.embeddingModelFactories={[Ho]:{model:pi,modelOptions:ci,modelSchema:Fo},[qo]:{model:di,modelOptions:li,modelSchema:$o},[_o]:{model:Ys,modelOptions:Zs,modelSchema:Ro},[Io]:{model:ei,modelOptions:Xs,modelSchema:Bo},[Ao]:{model:ai,modelOptions:oi,modelSchema:Lo},[No]:{model:ii,modelOptions:si,modelSchema:Uo}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,o)=>(t[o]=this.chatModelFactories[o].modelSchema,t),{})}chatModel(t){let o=t.modelName;if(!(o in this.chatModelFactories))throw new Ct({info:`Anthropic chat model: ${o} not found`,cause:new Error(`Anthropic chat model: ${o} not found, available chat models:
|
|
10
|
+
${this.chatModelLiterals().join(", ")}`)});let a=this.chatModelFactories[o].model,s=this.chatModelFactories[o].modelOptions.parse(t);return new a(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,o)=>(t[o]=this.embeddingModelFactories[o].modelSchema,t),{})}embeddingModel(t){let o=t.modelName;if(!(o in this.embeddingModelFactories))throw new Ct({info:`Anthropic embedding model: ${o} not found`,cause:new Error(`Anthropic embedding model: ${o} not found, available embedding models:
|
|
11
|
+
${this.embeddingModelLiterals().join(", ")}`)});let a=this.embeddingModelFactories[o].model,s=this.embeddingModelFactories[o].modelOptions.parse(t);return new a(s)}};me.chatBaseUrl="https://api.anthropic.com/v1",me.embeddingBaseUrl="https://api.voyageai.com/v1";var f=zod.z.enum([oe,H,I,xe]),y={system:oe,user:H,assistant:I,tool:H},b=[O,J,N,G],C=zod.z.enum([O,J,N,G]),ns=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ss=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),is=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[ns,ss])),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()})}),rs=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()})})}),ls=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()})}),ds=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ms=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),cs=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[ds,ms])}),ps=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),us=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),hs=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[ps,us])}),gs=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),fs=zod.z.object({type:zod.z.enum(["auto","any"])}),ys=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),Ae=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),uo=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 ho=zod.z.object({type:zod.z.literal("tool_result"),tool_use_id:zod.z.string().min(1),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ae,uo])).min(1))}),bs=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ae,uo,ho])).min(1))}),Cs=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ae,ho])).min(1))}),vs=zod.z.union([bs,Cs]),ks=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(vs).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([fs,ys]).optional(),tools:zod.z.array(gs).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()}),U=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),L=class{constructor(t,o){this.version="v1";let a=U.parse(o);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=te(me.chatBaseUrl),this.completeChatUrl=te(a.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=te(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 o=0,a=!0;return t["x-should-retry"]&&(a=t["x-should-retry"].toLowerCase()!=="false"),t["retry-after"]&&(o=parseInt(t["retry-after"])*1e3),{shouldRetry:a,delayMs:o}}getTokenCount(t){return t.reduce((o,a)=>o+a.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(t){let o=ks.safeParse(t);if(!o.success)throw new Se({info:"Invalid model request",cause:o.error});let a=o.data,s=a.model;if(a.tool_choice&&(!a.tools||a.tools.length===0))throw new Se({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let i={};a.tool_choice&&(a.tool_choice.type==="tool"?i.toolChoice=a.tool_choice.name:i.toolChoice=a.tool_choice.type),i.maxTokens=a.max_tokens,i.temperature=a.temperature,i.topP=a.top_p,i.topK=a.top_k,i.stop=a.stop_sequences;let l=Nt().parse(oo(i)),r=[],d={};a.system&&r.push({role:oe,content:[{modality:O,value:a.system}]}),a.messages.forEach(p=>{let h=p.role;switch(h){case"user":{let g=p.content;if(typeof g=="string")r.push({role:h,content:[{modality:O,value:g}]});else {let k=g.map(u=>{if(u.type==="text")return {modality:O,value:u.text};if(u.type==="image"){let ae="auto",q=u.source.media_type.split("/")[1];return {modality:J,detail:ae,value:{type:_t,media_type:q,base64:u.source.data}}}else return {modality:G,id:u.tool_use_id,index:d[u.tool_use_id].index,name:d[u.tool_use_id].name,data:typeof u.content=="string"?u.content:JSON.stringify(u.content)}});r.push({role:h,content:k});}}break;case"assistant":{let g=p.content;if(typeof g=="string")r.push({role:h,content:[{modality:O,value:g}]});else {let k=g.map((u,ae)=>{if(u.type==="text")return {modality:O,value:u.text};{let q={modality:N,id:u.id,index:ae,name:u.name,arguments:JSON.stringify(u.input)};return d[u.id]=q,q}});r.push({role:h,content:k});}}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:s,config:l,messages:r,tools:m.length>0?m:void 0}}transformConfig(t,o,a){let s=t.toolChoice,i=S({},t);delete i.toolChoice;let l=this.modelSchema.config.schema.safeParse(i);if(!l.success)throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:l.error});let r=l.data;s!==void 0&&(r.toolChoice=s),Object.keys(r).forEach(m=>{if(!(m in this.modelSchema.config.def))throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${m}',
|
|
12
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let d=Object.keys(r).reduce((m,p)=>{let h=this.modelSchema.config.def[p],g=h.param,k=r[p];return g==="max_tokens"&&h.type==="range"&&k===0?m[g]=h.max:m[g]=k,m},{});if(!d.max_tokens){let m=this.modelSchema.config.def.maxTokens;d.max_tokens=m.max;}if("tool_choice"in d&&d.tool_choice!==void 0){let m=d.tool_choice;if(!a||a&&a.length===0)throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(a&&a.length>0){let p=this.modelSchema.config.def.toolChoice;if(p.choices.includes(m))d.tool_choice={type:m};else if(a.map(h=>h.definition.schema.name).includes(m))d.tool_choice={type:"tool",name:m};else throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${m}' is not part of provided 'tools' names or
|
|
13
|
+
one of [${p.choices.join(", ")}]`)})}}return d}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let o=r=>{let d=r.match(/^data:image\/[a-zA-Z]+;base64,/);return d?r.substring(d[0].length):r},a=t.map(r=>{let d=Lt().safeParse(r);if(!d.success)throw new M({info:"Invalid messages",cause:d.error});return d.data});a.forEach(r=>{r.content.forEach(d=>{if(!this.modelSchema.modalities.includes(d.modality))throw new M({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${d.modality}',
|
|
14
14
|
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),a.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new M({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}',
|
|
15
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let s="",i=[];if(a.forEach(r=>{switch(r.role){case
|
|
16
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[
|
|
17
|
-
`).filter(s=>s.trim()!=="");for(let s of a)if(s.startsWith("data: {")&&s.endsWith("}")){let i;try{i=JSON.parse(s.substring(6));}catch(l){throw new
|
|
18
|
-
received : ${JSON.stringify(i)}`)})}})}transformProxyStreamChatResponseChunk(o,
|
|
19
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,l)=>{let r=this.modelSchema.config.def[l].param,d=s[l];return i[r]=d,i},{})}transformEmbeddingRequests(
|
|
20
|
-
Message: ${mi(a)}`),this.name=Be,this.info=t,this.cause=a,this.name=s!=null?s:Be,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof Fo}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},ci="system",pi="user",Do="assistant",ui="tool",hi=[ci,pi,Do,ui],Le=zod.z.enum(hi),gi=[Do],fi=zod.z.enum(gi),Ko="image",yi="base64",bi=["png","jpeg","webp","gif"],Ci=zod.z.object({type:zod.z.literal(yi),base64:zod.z.string(),media_type:zod.z.enum(bi)}),vi="url",ki=zod.z.object({type:zod.z.literal(vi),url:zod.z.string()}),wi=zod.z.discriminatedUnion("type",[Ci,ki]),Si=["low","medium","high","auto"],xi=zod.z.enum(Si),Ti=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ko),detail:xi,value:wi,metadata:o}),zo="text",Mi=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(zo),value:zod.z.string(),metadata:o}),Vo="partial-text",Oi=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Vo),value:zod.z.string(),metadata:o}),Jo="tool-call",ji=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Jo),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:o}),Go="partial-tool-call",Ei=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Go),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:o}),Wo="tool-response",Pi=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Wo),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:o}),_i=[zo,Ko,Jo,Wo],Zo=zod.z.enum(_i),Ri=(o=zod.z.undefined(),t=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Mi(o),Ti(t),ji(a),Pi(s)]),Ii=[Vo,Go];zod.z.enum(Ii);var Bi=(o=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Oi(o),Ei(t)]);var Ai=(o=Le,t=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined())=>zod.z.object({role:o,content:zod.z.array(Ri(t,a,s,i)),metadata:l}),Li=(o=fi,t=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:o,partialContent:Bi(t,a),metadata:s});var Ni=["object","array","number","string","boolean","enum"],qo=zod.z.enum(Ni),Ui=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([qo,zod.z.array(zod.z.union([qo,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),qi=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(Ui),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:qi}).optional();var $i="function";var Hi=zod.z.enum(["object","array","number","string","boolean","null"]),Fi=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Hi.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(Fi).optional(),required:zod.z.array(zod.z.string()).optional()});var Di=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 Ki=zod.z.enum(["function"]);zod.z.object({type:Ki,definition:zod.z.object({schema:Di})});var zi=[$i];zod.z.enum(zi);var Vi="text",Ji="token",Gi=[Vi,Ji];zod.z.enum(Gi);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var Zi="float",Yi=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Qi="base64",Xi=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),$o=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Zi),embeddings:zod.z.array(Yi),usage:$o.optional()}),zod.z.object({encodingFormat:zod.z.literal(Qi),embeddings:zod.z.array(Xi),usage:$o.optional()})]);var Yo=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Ho=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),er=Ho.extend({topLogProbs:zod.z.array(Ho)}),Qo=zod.z.array(er);zod.z.object({messages:zod.z.array(Ai()),usage:Yo.optional(),logProbs:Qo.optional()});zod.z.object({partialMessages:zod.z.array(Li()),usage:Yo.optional(),logProbs:Qo.optional()});var tr=Object.defineProperty,Xo=Object.getOwnPropertySymbols,or=Object.prototype.hasOwnProperty,ar=Object.prototype.propertyIsEnumerable,ea=(o,t,a)=>t in o?tr(o,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[t]=a,nr=(o,t)=>{for(var a in t||(t={}))or.call(t,a)&&ea(o,a,t[a]);if(Xo)for(var a of Xo(t))ar.call(t,a)&&ea(o,a,t[a]);return o},ta="ProviderError",Ne=class aa extends Ae{constructor({info:t,cause:a}){super({info:t,cause:a},ta),this.name=ta,this.info=t,this.cause=a;}static isProviderError(t){return t instanceof aa}};var oa="ModelResponseError",na=class sa extends Ae{constructor({info:t,cause:a}){super({info:t,cause:a},oa),this.name=oa,this.cause=a,this.info=t;}static isModelResponseError(t){return t instanceof sa}};var ia="multi-string",sr=zod.z.object({type:zod.z.literal(ia),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 ra="object-schema",ir=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),objectSchema:zod.z.any()});var la="range",rr=zod.z.object({type:zod.z.literal(la),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 da="select-boolean",lr=zod.z.object({type:zod.z.literal(da),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 Ue="select-string",ma=zod.z.object({type:zod.z.literal(Ue),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))}),dr=(o,t)=>zod.z.enum(t).nullable().default(o).optional(),ca=o=>({def:ma.parse(nr({type:Ue},o)),schema:dr(o.default,o.choices)}),mr=[la,ia,Ue,ra,da];zod.z.enum(mr);var cr=zod.z.discriminatedUnion("type",[rr,sr,ma,lr,ir]),P=(o=Le,t=Zo)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(o,zod.z.string().min(1).optional()),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),cr),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var s,i;let l=Object.keys(a.def),r=Object.keys((i=(s=a.schema)==null?void 0:s.shape)!=null?i:{});return l.every(d=>r.includes(d))&&r.every(d=>l.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});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 pr=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var pa=o=>{if(pr()){let t=atob(o),a=new Uint8Array(t.length);for(let s=0;s<t.length;s++)a[s]=t.charCodeAt(s);return new TextDecoder("utf-8").decode(a)}else return Buffer.from(o,"base64").toString("utf-8")};var qe=ca({param:"awsRegion",title:"AWS Region",description:"Controls which region the model will use to call AWS services.",default:"us-east-1",choices:["us-east-1","us-west-2","eu-west-1","eu-west-3","eu-central-1","ap-south-3","ap-southeast-1","ap-southeast-2","ap-northeast-1"]});var ua=(o,t)=>_e(o,t).extend({awsRegion:qe.schema}),ha=(o,t)=>K(_({},Re(o,t)),{awsRegion:qe.def});var v={base:(o,t)=>({def:ha(o,t),schema:ua(o,t)})};var ur="bedrock",X=class X{constructor(){this.version="v1";this.name=ur;this.chatModelFactories={[Ve]:{model:he,modelOptions:ba,modelSchema:Je},[Ze]:{model:fe,modelOptions:va,modelSchema:Ye},[Ge]:{model:ge,modelOptions:Ca,modelSchema:We},[Fe]:{model:pe,modelOptions:fa,modelSchema:De},[Ke]:{model:ue,modelOptions:ya,modelSchema:ze},[$e]:{model:ce,modelOptions:ga,modelSchema:He}};this.embeddingModelFactories={};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,a)=>(t[a]=this.chatModelFactories[a].modelSchema,t),{})}chatModel(t){let a=t.modelName;if(!(a in this.chatModelFactories))throw new Ne({info:`Bedrock chat model: ${a} not found`,cause:new Error(`Bedrock chat model: ${a} not found, available chat models:
|
|
21
|
-
${this.chatModelLiterals().join(", ")}`)});let s=this.chatModelFactories[a].model,i=this.chatModelFactories[a].modelOptions.parse(
|
|
15
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let s="",i=[];if(a.forEach(r=>{switch(r.role){case oe:{r.content.forEach(d=>{if(d.modality===O)s+=d.value;else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})});break}case I:{let d=[];r.content.forEach(m=>{if(m.modality===O)d.push({type:"text",text:m.value});else if(m.modality===N)d.push({type:"tool_use",id:m.id,name:m.name,input:JSON.parse(m.arguments)});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${m.modality}'`)})}),i.push({role:this.modelSchema.roles[r.role],content:d});break}case H:{let d=[];r.content.forEach(m=>{if(m.modality===O)d.push({type:"text",text:m.value});else if(m.modality===J){if(m.value.type==="base64"){let p=m.value.base64;p=o(p),d.push({type:"image",source:{type:"base64",media_type:`image/${m.value.media_type}`,data:p}});}else if(m.value.type==="url")throw new M({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${m.value.type}'`)})}else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${m.modality}'`)})}),i.push({role:this.modelSchema.roles[r.role],content:d});break}case xe:{let d=[];r.content.forEach(m=>{if(m.modality===G)d.push({type:"tool_result",tool_use_id:m.id,content:m.data});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${m.modality}'`)})}),i.push({role:this.modelSchema.roles[r.role],content:d});break}default:throw new M({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
|
|
16
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[H])throw new M({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let l=r=>r===this.modelSchema.roles[H]?this.modelSchema.roles[I]:this.modelSchema.roles[H];for(let r=1;r<i.length;r++)if(i[r].role!==l(i[r-1].role))throw new M({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires messages to alternate between user and assistant`)});return {system:s,messages:i}}transformTools(t){if(!this.modelSchema.modalities.includes(N))throw new Tt({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${N}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(o=>{let a=bn().safeParse(o);if(!a.success)throw new Tt({info:"Invalid tools",cause:a.error});return a.data}).map(o=>({name:o.definition.schema.name,description:o.definition.schema.description,input_schema:o.definition.schema.parameters}))}}getCompleteChatUrl(t,o,a){return j(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(t,o,a){return j(this,null,function*(){let s=this.getDefaultHeaders();return a&&a.length>0&&(s=dt(S({},s),{"anthropic-beta":"tools-2024-05-16"})),new Promise(i=>{i(s);})})}getCompleteChatData(t,o,a){return j(this,null,function*(){let s=this.transformConfig(t,o,a),i=this.transformMessages(o);if(i.messages&&i.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let l=a?this.transformTools(a):{};return new Promise(r=>{r(S(S(S(S({},this.getDefaultParams()),s),i),l));})})}transformCompleteChatResponse(t){let o=is.safeParse(t);if(o.success){let a=o.data,s=a.content.map((r,d)=>{if(r.type==="text")return sn(r.text);if(r.type==="tool_use")return rn(d,r.id,r.name,JSON.stringify(r.input))}),i=[{role:I,content:s}],l={promptTokens:a.usage.input_tokens,completionTokens:a.usage.output_tokens,totalTokens:a.usage.input_tokens+a.usage.output_tokens};return {messages:i,usage:l,logProbs:[]}}throw new $({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(t,o,a){return j(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(t,o,a){let s=this.getDefaultHeaders();return a&&a.length>0&&(s=dt(S({},s),{"anthropic-beta":"tools-2024-05-16"})),new Promise(i=>{i(s);})}getStreamChatData(t,o,a){return j(this,null,function*(){let s=this.transformConfig(t,o,a),i=this.transformMessages(o);if(i.messages&&i.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let l=a?this.transformTools(a):{};return new Promise(r=>{r(S(S(S(S({stream:!0},this.getDefaultParams()),s),i),l));})})}transformStreamChatResponseChunk(t,o){return mt(this,null,function*(){let a=(o+t).split(`
|
|
17
|
+
`).filter(s=>s.trim()!=="");for(let s of a)if(s.startsWith("data: {")&&s.endsWith("}")){let i;try{i=JSON.parse(s.substring(6));}catch(l){throw new $({info:`Malformed JSON received in stream : ${i}`,cause:l})}if("type"in i){if(i.type==="message_stop")return;if(i.type==="message_start"){let l=rs.safeParse(i);if(l.success){let r=l.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:r.message.usage.input_tokens,completionTokens:r.message.usage.output_tokens,totalTokens:r.message.usage.input_tokens+r.message.usage.output_tokens}},buffer:o};}else throw new $({info:"Invalid response from model",cause:l.error})}else if(i.type==="message_delta"){let l=ls.safeParse(i);if(l.success){let r=l.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:0,completionTokens:r.usage.output_tokens,totalTokens:r.usage.output_tokens}},buffer:o};}else throw new $({info:"Invalid response from model",cause:l.error})}else if(i.type==="content_block_start"){let l=cs.safeParse(i);if(l.success){let r=l.data,d=[];r.content_block.type==="text"?d.push(ct(I,r.content_block.text)):r.content_block.type==="tool_use"&&d.push(pt(I,r.index,r.content_block.id,r.content_block.name,"")),yield {partialResponse:{partialMessages:d},buffer:o};}else throw new $({info:"Invalid response from model",cause:l.error})}else if(i.type==="content_block_delta"){let l=hs.safeParse(i);if(l.success){let r=l.data,d=[];r.delta.type==="text_delta"?d.push(ct(I,r.delta.text)):r.delta.type==="input_json_delta"&&d.push(pt(I,r.index,"","",r.delta.partial_json)),yield {partialResponse:{partialMessages:d},buffer:o};}else throw new $({info:"Invalid response from model",cause:l.error})}}else throw new $({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property,
|
|
18
|
+
received : ${JSON.stringify(i)}`)})}})}transformProxyStreamChatResponseChunk(t,o,a,s,i){return mt(this,null,function*(){yield*le(qa(this.transformStreamChatResponseChunk(t,o)));})}getProxyStreamChatUrl(t,o,a){return j(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getProxyCompleteChatUrl(t,o,a){return j(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getProxyCompleteChatHeaders(t,o,a){return j(this,null,function*(){if(!o)return {};let s=S({},o);return delete s.host,delete s["content-length"],s})}getProxyStreamChatHeaders(t,o,a){return j(this,null,function*(){return yield this.getProxyCompleteChatHeaders(t,o,a)})}},go="claude-3-5-sonnet-20240620",ws="Most intelligent model. Highest level of intelligence and capability.",fo=F(f,C).parse({name:go,description:ws,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:b,config:{def:w.base(8192,4).def,schema:w.base(8192,4).schema}}),Ss=U,xs=class extends L{constructor(t){super(fo,t);}},yo="claude-3-5-sonnet-20241022",Ts="Most intelligent model. Highest level of intelligence and capability.",bo=F(f,C).parse({name:yo,description:Ts,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:b,config:{def:w.base(8192,4).def,schema:w.base(8192,4).schema}}),Ms=U,Os=class extends L{constructor(t){super(bo,t);}},Co="claude-3-5-sonnet-latest",js="Most intelligent model. Highest level of intelligence and capability.",vo=F(f,C).parse({name:Co,description:js,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:b,config:{def:w.base(8192,4).def,schema:w.base(8192,4).schema}}),Es=U,Ps=class extends L{constructor(t){super(vo,t);}},ko="claude-3-haiku-20240307",_s="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",wo=F(f,C).parse({name:ko,description:_s,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:b,config:{def:w.base(4096,4).def,schema:w.base(4096,4).schema}}),Rs=U,Is=class extends L{constructor(t){super(wo,t);}},So="claude-3-5-haiku-20241022",Bs="Our fastest model with intelligence at blazing speeds.",xo=F(f,C).parse({name:So,description:Bs,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:b,config:{def:w.base(8192,4).def,schema:w.base(8192,4).schema}}),As=U,Ls=class extends L{constructor(t){super(xo,t);}},To="claude-3-5-haiku-latest",Ns="Our fastest model with intelligence at blazing speeds.",Mo=F(f,C).parse({name:To,description:Ns,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:b,config:{def:w.base(8192,4).def,schema:w.base(8192,4).schema}}),Us=U,qs=class extends L{constructor(t){super(Mo,t);}},Oo="claude-3-opus-20240229",$s="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",jo=F(f,C).parse({name:Oo,description:$s,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:b,config:{def:w.base(4096,4).def,schema:w.base(4096,4).schema}}),Hs=U,Fs=class extends L{constructor(t){super(jo,t);}},Eo="claude-3-sonnet-20240229",Ds="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Po=F(f,C).parse({name:Eo,description:Ds,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:b,config:{def:w.base(4096,4).def,schema:w.base(4096,4).schema}}),zs=U,Ks=class extends L{constructor(t){super(Po,t);}},Y=[W],Q=zod.z.enum([W]),Vs=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()})}),Js=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),Gs=zod.z.object({model:zod.z.string().min(1).optional(),input:Js,encoding_format:zod.z.enum(["base64"]).nullable().optional(),input_type:zod.z.enum(["query","document"]).nullable().optional(),truncation:zod.z.boolean().optional()}),z=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),X=class{constructor(t,o){this.version="v1";let a=z.parse(o);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=te(me.embeddingBaseUrl),this.getEmbeddingsUrl=te(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((o,a)=>o+a.length,0)}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}transformModelRequest(t){let o=Gs.safeParse(t);if(!o.success)throw new Se({info:"Invalid model request",cause:o.error});let a=o.data,s=a.model,i={encodingFormat:a.encoding_format,inputType:a.input_type,truncation:a.truncation},l=Nt().parse(oo(i)),r;return typeof a.input=="string"?r={modality:W,requests:[a.input]}:r={modality:W,requests:a.input},{modelName:s,config:l,embeddingRequests:r}}transformConfig(t,o){"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 V({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let s=a.data;return Object.keys(s).forEach(i=>{if(!this.modelSchema.config.def[i])throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${i}',
|
|
19
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,l)=>{let r=this.modelSchema.config.def[l].param,d=s[l];return i[r]=d,i},{})}transformEmbeddingRequests(t){let o=Sn().safeParse(t);if(!o.success)throw new Ot({info:"Invalid embedding requests",cause:o.error});if(o.data.requests.length>128)throw new Ot({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:o.data.requests}}getGetEmbeddingsUrl(t,o){return j(this,null,function*(){return new Promise(a=>{a(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,o){return j(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,o){return j(this,null,function*(){return new Promise(a=>{a(S(S(S({},this.getDefaultParams()),this.transformConfig(t,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(t){let o,a=Vs.safeParse(t);if(a.success){let s=a.data;o=typeof s.data[0].embedding=="string"?$t:qt;let i=s.data.map(l=>typeof l.embedding=="string"?{index:l.index,embedding:l.embedding}:{index:l.index,embedding:l.embedding});return {encodingFormat:o,embeddings:i,usage:{totalTokens:s.usage.total_tokens}}}throw new $({info:"Invalid response from model",cause:a.error})}},_o="voyage-code-2",Ws="Optimized for code retrieval.",Ro=Z(Q).parse({name:_o,description:Ws,modalities:Y,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:E.base().def,schema:E.base().schema}}),Zs=z,Ys=class extends X{constructor(t){super(Ro,t);}},Io="voyage-law-2",Qs="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",Bo=Z(Q).parse({name:Io,description:Qs,modalities:Y,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:E.base().def,schema:E.base().schema}}),Xs=z,ei=class extends X{constructor(t){super(Bo,t);}},Ao="voyage-multilingual-2",ti="Optimized for multilingual retrieval and RAG.",Lo=Z(Q).parse({name:Ao,description:ti,modalities:Y,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:E.base().def,schema:E.base().schema}}),oi=z,ai=class extends X{constructor(t){super(Lo,t);}},No="voyage-finance-2",ni="Optimized for finance retrieval and RAG.",Uo=Z(Q).parse({name:No,description:ni,modalities:Y,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:E.base().def,schema:E.base().schema}}),si=z,ii=class extends X{constructor(t){super(Uo,t);}},qo="voyage-3-lite",ri="Optimized for latency and cost.",$o=Z(Q).parse({name:qo,description:ri,modalities:Y,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:E.base().def,schema:E.base().schema}}),li=z,di=class extends X{constructor(t){super($o,t);}},Ho="voyage-3",mi="Optimized for quality.",Fo=Z(Q).parse({name:Ho,description:mi,modalities:Y,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:E.base().def,schema:E.base().schema}}),ci=z,pi=class extends X{constructor(t){super(Fo,t);}};var ui=t=>{let o=new WeakSet;return JSON.stringify(t,(a,s)=>{if(typeof s=="object"&&s!==null){if(o.has(s))return;o.add(s);}return s})},hi=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:ui(t),Le="GatewayBaseError",Ne=class Vo extends Error{constructor({info:o,cause:a},s){super(`[${s!=null?s:Le}]: ${o}
|
|
20
|
+
Message: ${hi(a)}`),this.name=Le,this.info=o,this.cause=a,this.name=s!=null?s:Le,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(o){return o instanceof Vo}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},gi="system",fi="user",Jo="assistant",yi="tool",bi=[gi,fi,Jo,yi],Ue=zod.z.enum(bi),Ci=[Jo],vi=zod.z.enum(Ci),Go="image",ki="base64",wi=["png","jpeg","webp","gif"],Si=zod.z.object({type:zod.z.literal(ki),base64:zod.z.string(),media_type:zod.z.enum(wi)}),xi="url",Ti=zod.z.object({type:zod.z.literal(xi),url:zod.z.string()}),Mi=zod.z.discriminatedUnion("type",[Si,Ti]),Oi=["low","medium","high","auto"],ji=zod.z.enum(Oi),Ei=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Go),detail:ji,value:Mi,metadata:t}),Wo="text",Pi=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Wo),value:zod.z.string(),metadata:t}),Zo="partial-text",_i=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Zo),value:zod.z.string(),metadata:t}),Yo="tool-call",Ri=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Yo),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),Qo="partial-tool-call",Ii=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Qo),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),Xo="tool-response",Bi=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Xo),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),Ai=[Wo,Go,Yo,Xo],ea=zod.z.enum(Ai),Li=(t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Pi(t),Ei(o),Ri(a),Bi(s)]),Ni=[Zo,Qo];zod.z.enum(Ni);var Ui=(t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[_i(t),Ii(o)]);var qi=(t=Ue,o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(Li(o,a,s,i)),metadata:l}),$i=(t=vi,o=zod.z.undefined(),a=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,partialContent:Ui(o,a),metadata:s});var Hi=["object","array","number","string","boolean","enum"],Do=zod.z.enum(Hi),Fi=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Do,zod.z.array(zod.z.union([Do,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()}),Di=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Fi),additionalProperties:zod.z.literal(!1)});zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:Di}).optional();var zi="function";var Ki=zod.z.enum(["object","array","number","string","boolean","null"]),Vi=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Ki.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(Vi).optional(),required:zod.z.array(zod.z.string()).optional()});var Ji=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 Gi=zod.z.enum(["function"]);zod.z.object({type:Gi,definition:zod.z.object({schema:Ji})});var Wi=[zi];zod.z.enum(Wi);var Zi="text",Yi="token",Qi=[Zi,Yi];zod.z.enum(Qi);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var er="float",tr=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),or="base64",ar=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),zo=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(er),embeddings:zod.z.array(tr),usage:zo.optional()}),zod.z.object({encodingFormat:zod.z.literal(or),embeddings:zod.z.array(ar),usage:zo.optional()})]);var ta=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Ko=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),nr=Ko.extend({topLogProbs:zod.z.array(Ko)}),oa=zod.z.array(nr);zod.z.object({messages:zod.z.array(qi()),usage:ta.optional(),logProbs:oa.optional()});zod.z.object({partialMessages:zod.z.array($i()),usage:ta.optional(),logProbs:oa.optional()});var sr=Object.defineProperty,aa=Object.getOwnPropertySymbols,ir=Object.prototype.hasOwnProperty,rr=Object.prototype.propertyIsEnumerable,na=(t,o,a)=>o in t?sr(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,lr=(t,o)=>{for(var a in o||(o={}))ir.call(o,a)&&na(t,a,o[a]);if(aa)for(var a of aa(o))rr.call(o,a)&&na(t,a,o[a]);return t},sa="ProviderError",qe=class ra extends Ne{constructor({info:o,cause:a}){super({info:o,cause:a},sa),this.name=sa,this.info=o,this.cause=a;}static isProviderError(o){return o instanceof ra}};var ia="ModelResponseError",la=class da extends Ne{constructor({info:o,cause:a}){super({info:o,cause:a},ia),this.name=ia,this.cause=a,this.info=o;}static isModelResponseError(o){return o instanceof da}};var ma="multi-string",dr=zod.z.object({type:zod.z.literal(ma),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()});var ca="object-schema",mr=zod.z.object({type:zod.z.literal(ca),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var pa="range",cr=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),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()});var ua="select-boolean",pr=zod.z.object({type:zod.z.literal(ua),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()});var $e="select-string",ha=zod.z.object({type:zod.z.literal($e),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string(),choices:zod.z.array(zod.z.string())}),ur=(t,o)=>zod.z.enum(o).nullable().default(t).optional(),ga=t=>({def:ha.parse(lr({type:$e},t)),schema:ur(t.default,t.choices)}),hr=[pa,ma,$e,ca,ua];zod.z.enum(hr);var gr=zod.z.discriminatedUnion("type",[cr,dr,ha,pr,mr]),P=(t=Ue,o=ea)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(o).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),gr),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var s,i;let l=Object.keys(a.def),r=Object.keys((i=(s=a.schema)==null?void 0:s.shape)!=null?i:{});return l.every(d=>r.includes(d))&&r.every(d=>l.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});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 fr=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var fa=t=>{if(fr()){let o=atob(t),a=new Uint8Array(o.length);for(let s=0;s<o.length;s++)a[s]=o.charCodeAt(s);return new TextDecoder("utf-8").decode(a)}else return Buffer.from(t,"base64").toString("utf-8")};var He=ga({param:"awsRegion",title:"AWS Region",description:"Controls which region the model will use to call AWS services.",default:"us-east-1",choices:["us-east-1","us-west-2","eu-west-1","eu-west-3","eu-central-1","ap-south-3","ap-southeast-1","ap-southeast-2","ap-northeast-1"]});var ya=(t,o)=>Ie(t,o).extend({awsRegion:He.schema}),ba=(t,o)=>K(_({},Be(t,o)),{awsRegion:He.def});var v={base:(t,o)=>({def:ba(t,o),schema:ya(t,o)})};var yr="bedrock",ee=class ee{constructor(){this.version="v1";this.name=yr;this.chatModelFactories={[Ge]:{model:fe,modelOptions:wa,modelSchema:We},[Qe]:{model:be,modelOptions:xa,modelSchema:Xe},[Ze]:{model:ye,modelOptions:Sa,modelSchema:Ye},[ze]:{model:he,modelOptions:va,modelSchema:Ke},[Ve]:{model:ge,modelOptions:ka,modelSchema:Je},[Fe]:{model:ue,modelOptions:Ca,modelSchema:De}};this.embeddingModelFactories={};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((o,a)=>(o[a]=this.chatModelFactories[a].modelSchema,o),{})}chatModel(o){let a=o.modelName;if(!(a in this.chatModelFactories))throw new qe({info:`Bedrock chat model: ${a} not found`,cause:new Error(`Bedrock chat model: ${a} not found, available chat models:
|
|
21
|
+
${this.chatModelLiterals().join(", ")}`)});let s=this.chatModelFactories[a].model,i=this.chatModelFactories[a].modelOptions.parse(o);return new s(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((o,a)=>(o[a]=this.embeddingModelFactories[a].modelSchema,o),{})}embeddingModel(o){throw new qe({info:"Adaline Bedrock provider does not support embedding models yet",cause:new Error("Adaline Bedrock provider does not support embedding models yet")})}};ee.awsService="bedrock",ee.awsDefaultRegion="us-east-1",ee.awsUrl=o=>`https://bedrock-runtime.${o!=null?o:ee.awsDefaultRegion}.amazonaws.com`;var B=ee;var x=zod.z.object({modelName:zod.z.string(),awsAccessKeyId:zod.z.string(),awsSecretAccessKey:zod.z.string()});var T=class t extends L{constructor(a,s){let i=x.parse(s);super(a,{apiKey:"random-api-key",modelName:i.modelName});this.version="v1";this.modelSchema=a,this.modelName=i.modelName,this.awsService=B.awsService,this.awsAccessKeyId=i.awsAccessKeyId,this.awsSecretAccessKey=i.awsSecretAccessKey;}getDefaultBaseUrl(){return B.awsUrl()}getDefaultHeaders(){return {Accept:"application/json","Content-Type":"application/json"}}getDefaultParams(){return {anthropic_version:"bedrock-2023-05-31"}}getCompleteChatUrl(a,s,i){let l=B.awsUrl(a==null?void 0:a.awsRegion);return new Promise(r=>{r(`${l}/model/${this.modelName}/invoke`);})}transformConfig(a,s,i){let l=_({},a);return delete l.awsRegion,super.transformConfig(l,s,i)}getCompleteChatHeaders(a,s,i){return R(this,null,function*(){let l=new URL(yield this.getCompleteChatUrl(a,s,i)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},d=a==null?void 0:a.awsRegion,m=this.getDefaultHeaders();m=K(_({},m),{host:B.awsUrl(d).split("://")[1]});let p=yield this.getCompleteChatData(a||{},s||[],i),h=new protocolHttp.HttpRequest({hostname:l.hostname,path:l.pathname,protocol:l.protocol,method:"POST",body:JSON.stringify(p),headers:m});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:d,sha256:sha256Js.Sha256}).sign(h)).headers})}getCompleteChatData(a,s,i){return R(this,null,function*(){let l=_(_({},this.getDefaultParams()),yield ie(t.prototype,this,"getCompleteChatData").call(this,a,s,i));return new Promise(r=>{r(l);})})}getStreamChatUrl(a,s,i){return R(this,null,function*(){let l=B.awsUrl(a==null?void 0:a.awsRegion);return new Promise(r=>{r(`${l}/model/${this.modelName}/invoke-with-response-stream`);})})}getStreamChatHeaders(a,s,i){return R(this,null,function*(){let l=new URL(yield this.getStreamChatUrl(a,s,i)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},d=a==null?void 0:a.awsRegion,m=this.getDefaultHeaders();m=K(_({},m),{host:B.awsUrl(d).split("://")[1]});let p=yield this.getCompleteChatData(a||{},s||[],i),h=new protocolHttp.HttpRequest({hostname:l.hostname,path:l.pathname,protocol:l.protocol,method:"POST",body:JSON.stringify(p),headers:m});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:d,sha256:sha256Js.Sha256}).sign(h)).headers})}getStreamChatData(a,s,i){return R(this,null,function*(){let l=_(_({},this.getDefaultParams()),yield ie(t.prototype,this,"getStreamChatData").call(this,a,s,i));return "stream"in l&&delete l.stream,l})}transformStreamChatResponseChunk(a,s){return ke(this,null,function*(){let i=a.toString(),l=/{\s*"bytes"\s*:\s*"[\w=+/]+".*?}/g,r=i.match(l)||[];for(let d of r){let m=d.indexOf("{"),p=d.indexOf("}");if(m!==-1&&p!==-1&&m<p){let h;try{h=JSON.parse(d.slice(m,p+1));}catch(u){throw new la({info:`Malformed JSON received in stream : ${h}`,cause:u})}let g=fa(h.bytes),k=(yield new re(ie(t.prototype,this,"transformStreamChatResponseChunk").call(this,`data: ${g}`,s).next())).value;k&&(yield k);}}})}transformProxyStreamChatResponseChunk(a,s,i,l,r){return ke(this,null,function*(){yield*le(this.transformStreamChatResponseChunk(a,s));})}getRegionHelper(a){var i;let s=a["aws-region"];if(!s){let l=(i=a.authorization)==null?void 0:i.match(/Credential=[^/]+\/\d+\/([^/]+)\/bedrock/);l&&(s=l[1]);}return s}getProxyStreamChatUrl(a,s,i){return R(this,null,function*(){let l=this.getRegionHelper(s||{}),r=B.awsUrl(l);return new Promise(d=>{d(`${r}/model/${this.modelName}/invoke-with-response-stream`);})})}getProxyChatHeaders(a,s,i,l){return R(this,null,function*(){let r=new URL(yield a());if(!i)return {};let d=i["aws-access-key-id"],m=i["aws-secret-access-key"],p=this.getRegionHelper(i);if(!d||!m)return {};let h={accessKeyId:d,secretAccessKey:m};i=K(_({},i),{host:r.host,"content-type":"application/json",accept:"application/json"}),delete i["content-length"];let g=i.authorization||i.Authorization;if(g){let q=g.match(/SignedHeaders=([^,]+)/);if(q&&q[1]){let at=q[1].split(";").map(ne=>ne.trim().toLowerCase());at.push("authorization"),i=Object.keys(i).reduce((ne,ve)=>{var nt;return at.includes(ve.toLowerCase())&&(ne[ve]=(nt=i==null?void 0:i[ve])!=null?nt:""),ne},{});}}let k=new protocolHttp.HttpRequest({hostname:r.hostname,path:r.pathname,protocol:r.protocol,method:"POST",body:JSON.stringify(s),headers:i});return (yield new signatureV4.SignatureV4({credentials:h,service:this.awsService,region:p,sha256:sha256Js.Sha256}).sign(k)).headers})}getProxyCompleteChatUrl(a,s,i){return R(this,null,function*(){let l=this.getRegionHelper(s||{}),r=B.awsUrl(l);return new Promise(d=>{d(`${r}/model/${this.modelName}/invoke`);})})}getProxyCompleteChatHeaders(a,s,i){return R(this,null,function*(){return this.getProxyChatHeaders(()=>this.getProxyCompleteChatUrl(a,s,i),a,s,i)})}getProxyStreamChatHeaders(a,s,i){return R(this,null,function*(){return this.getProxyChatHeaders(()=>this.getProxyStreamChatUrl(a,s,i),a,s,i)})}};var Fe="anthropic.claude-3-5-haiku-20241022-v1:0",br="Our fastest model with intelligence at blazing speeds.",De=P(f,C).parse({name:Fe,description:br,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:b,config:{def:v.base(8192,4).def,schema:v.base(8192,4).schema}}),Ca=x,ue=class extends T{constructor(o){super(De,o);}};var ze="anthropic.claude-3-5-sonnet-20240620-v1:0",Cr="Most intelligent model. Highest level of intelligence and capability.",Ke=P(f,C).parse({name:ze,description:Cr,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:b,config:{def:v.base(8192,4).def,schema:v.base(8192,4).schema}}),va=x,he=class extends T{constructor(o){super(Ke,o);}};var Ve="anthropic.claude-3-5-sonnet-20241022-v2:0",vr="Most intelligent model. Highest level of intelligence and capability.",Je=P(f,C).parse({name:Ve,description:vr,maxInputTokens:2e5,maxOutputTokens:8192,roles:y,modalities:b,config:{def:v.base(8192,4).def,schema:v.base(8192,4).schema}}),ka=x,ge=class extends T{constructor(o){super(Je,o);}};var Ge="anthropic.claude-3-haiku-20240307-v1:0",kr="Claude 3 Haiku is a large-scale multimodal model trained by Anthropic. It is the successor to Claude 3 and is designed to be more powerful and capable than its predecessor.",We=P(f,C).parse({name:Ge,description:kr,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:b,config:{def:v.base(4096,4).def,schema:v.base(4096,4).schema}}),wa=x,fe=class extends T{constructor(o){super(We,o);}};var Ze="anthropic.claude-3-opus-20240229-v1:0",wr="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",Ye=P(f,C).parse({name:Ze,description:wr,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:b,config:{def:v.base(4096,4).def,schema:v.base(4096,4).schema}}),Sa=x,ye=class extends T{constructor(o){super(Ye,o);}};var Qe="anthropic.claude-3-sonnet-20240229-v1:0",Sr="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Xe=P(f,C).parse({name:Qe,description:Sr,maxInputTokens:2e5,maxOutputTokens:4096,roles:y,modalities:b,config:{def:v.base(4096,4).def,schema:v.base(4096,4).schema}}),xa=x,be=class extends T{constructor(o){super(Xe,o);}};
|
|
22
22
|
|
|
23
23
|
exports.BaseChatModelAnthropic = T;
|
|
24
24
|
exports.BaseChatModelOptions = x;
|
|
25
25
|
exports.Bedrock = B;
|
|
26
|
-
exports.BedrockAnthropicChatModelBaseConfigDef =
|
|
27
|
-
exports.BedrockAnthropicChatModelBaseConfigSchema =
|
|
26
|
+
exports.BedrockAnthropicChatModelBaseConfigDef = ba;
|
|
27
|
+
exports.BedrockAnthropicChatModelBaseConfigSchema = ya;
|
|
28
28
|
exports.BedrockAnthropicChatModelConfigs = v;
|
|
29
|
-
exports.BedrockClaude3Haiku20240307 =
|
|
30
|
-
exports.BedrockClaude3Haiku20240307Literal =
|
|
31
|
-
exports.BedrockClaude3Haiku20240307Options =
|
|
32
|
-
exports.BedrockClaude3Haiku20240307Schema =
|
|
33
|
-
exports.BedrockClaude3Opus20240229 =
|
|
34
|
-
exports.BedrockClaude3Opus20240229Literal =
|
|
35
|
-
exports.BedrockClaude3Opus20240229Options =
|
|
36
|
-
exports.BedrockClaude3Opus20240229Schema =
|
|
37
|
-
exports.BedrockClaude3Sonnet20240229 =
|
|
38
|
-
exports.BedrockClaude3Sonnet20240229Literal =
|
|
39
|
-
exports.BedrockClaude3Sonnet20240229Options =
|
|
40
|
-
exports.BedrockClaude3Sonnet20240229Schema =
|
|
41
|
-
exports.BedrockClaude3_5Haiku20241022 =
|
|
42
|
-
exports.BedrockClaude3_5Haiku20241022Literal =
|
|
43
|
-
exports.BedrockClaude3_5Haiku20241022Options =
|
|
44
|
-
exports.BedrockClaude3_5Haiku20241022Schema =
|
|
45
|
-
exports.BedrockClaude3_5Sonnet20240620 =
|
|
46
|
-
exports.BedrockClaude3_5Sonnet20240620Literal =
|
|
47
|
-
exports.BedrockClaude3_5Sonnet20240620Options =
|
|
48
|
-
exports.BedrockClaude3_5Sonnet20240620Schema =
|
|
49
|
-
exports.BedrockClaude3_5Sonnet20241022 =
|
|
50
|
-
exports.BedrockClaude3_5Sonnet20241022Literal =
|
|
51
|
-
exports.BedrockClaude3_5Sonnet20241022Options =
|
|
52
|
-
exports.BedrockClaude3_5Sonnet20241022Schema =
|
|
53
|
-
exports.awsRegionChoice =
|
|
29
|
+
exports.BedrockClaude3Haiku20240307 = fe;
|
|
30
|
+
exports.BedrockClaude3Haiku20240307Literal = Ge;
|
|
31
|
+
exports.BedrockClaude3Haiku20240307Options = wa;
|
|
32
|
+
exports.BedrockClaude3Haiku20240307Schema = We;
|
|
33
|
+
exports.BedrockClaude3Opus20240229 = ye;
|
|
34
|
+
exports.BedrockClaude3Opus20240229Literal = Ze;
|
|
35
|
+
exports.BedrockClaude3Opus20240229Options = Sa;
|
|
36
|
+
exports.BedrockClaude3Opus20240229Schema = Ye;
|
|
37
|
+
exports.BedrockClaude3Sonnet20240229 = be;
|
|
38
|
+
exports.BedrockClaude3Sonnet20240229Literal = Qe;
|
|
39
|
+
exports.BedrockClaude3Sonnet20240229Options = xa;
|
|
40
|
+
exports.BedrockClaude3Sonnet20240229Schema = Xe;
|
|
41
|
+
exports.BedrockClaude3_5Haiku20241022 = ue;
|
|
42
|
+
exports.BedrockClaude3_5Haiku20241022Literal = Fe;
|
|
43
|
+
exports.BedrockClaude3_5Haiku20241022Options = Ca;
|
|
44
|
+
exports.BedrockClaude3_5Haiku20241022Schema = De;
|
|
45
|
+
exports.BedrockClaude3_5Sonnet20240620 = he;
|
|
46
|
+
exports.BedrockClaude3_5Sonnet20240620Literal = ze;
|
|
47
|
+
exports.BedrockClaude3_5Sonnet20240620Options = va;
|
|
48
|
+
exports.BedrockClaude3_5Sonnet20240620Schema = Ke;
|
|
49
|
+
exports.BedrockClaude3_5Sonnet20241022 = ge;
|
|
50
|
+
exports.BedrockClaude3_5Sonnet20241022Literal = Ve;
|
|
51
|
+
exports.BedrockClaude3_5Sonnet20241022Options = ka;
|
|
52
|
+
exports.BedrockClaude3_5Sonnet20241022Schema = Je;
|
|
53
|
+
exports.awsRegionChoice = He;
|
|
54
54
|
//# sourceMappingURL=index.js.map
|
|
55
55
|
//# sourceMappingURL=index.js.map
|