@adaline/bedrock 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +19 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,27 +5,27 @@ 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: ${qo(a)}`),this.name=re,this.info=o,this.cause=a,this.name=i!=null?i:re,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(o){return o instanceof Ie}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Lo="system",Uo="user",_e="assistant",Bo="tool",Fo=[Lo,Uo,_e,Bo],me=zod.z.enum(Fo),Do=[_e],Ko=zod.z.enum(Do),Re="image",Ho="base64",Vo=["png","jpeg","webp","gif"],zo=zod.z.object({type:zod.z.literal(Ho),base64:zod.z.string(),media_type:zod.z.enum(Vo)}),Jo="url",Go=zod.z.object({type:zod.z.literal(Jo),url:zod.z.string()}),Wo=zod.z.discriminatedUnion("type",[zo,Go]),Zo=["low","medium","high","auto"],Yo=zod.z.enum(Zo),Qo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Re),detail:Yo,value:Wo,metadata:t}),Ae="text",Xo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ae),value:zod.z.string(),metadata:t}),Ne="partial-text",ea=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ne),value:zod.z.string(),metadata:t}),$e="tool-call",ta=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal($e),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),qe="partial-tool-call",oa=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(qe),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),Le="tool-response",aa=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Le),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),na=[Ae,Re,$e,Le],Ue=zod.z.enum(na),ia=(t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Xo(t),Qo(o),ta(a),aa(i)]),sa=[Ne,qe];zod.z.enum(sa);var ra=(t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[ea(t),oa(o)]);var la=(t=me,o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(ia(o,a,i,l)),metadata:s}),ma=(t=Ko,o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:t,partialContent:ra(o,a),metadata:i});var da=["object","array","number","string","boolean","enum"],Ee=zod.z.enum(da),ca=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Ee,zod.z.array(zod.z.union([Ee,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()}),pa=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(ca),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:pa}).optional();var ua="function";var ha=zod.z.enum(["object","array","number","string","boolean","null"]),ga=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ha.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(ga).optional(),required:zod.z.array(zod.z.string()).optional()});var fa=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 ya=zod.z.enum(["function"]);zod.z.object({type:ya,definition:zod.z.object({schema:fa})});var ba=[ua];zod.z.enum(ba);var va="text",wa="token",Ca=[va,wa];zod.z.enum(Ca);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var xa="float",ka=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Sa="base64",ja=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Me=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(xa),embeddings:zod.z.array(ka),usage:Me.optional()}),zod.z.object({encodingFormat:zod.z.literal(Sa),embeddings:zod.z.array(ja),usage:Me.optional()})]);var Be=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Pe=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Oa=Pe.extend({topLogProbs:zod.z.array(Pe)}),Fe=zod.z.array(Oa);zod.z.object({messages:zod.z.array(la()),usage:Be.optional(),logProbs:Fe.optional()});zod.z.object({partialMessages:zod.z.array(ma()),usage:Be.optional(),logProbs:Fe.optional()});var De="ProviderError",de=class He extends le{constructor({info:o,cause:a}){super({info:o,cause:a},De),this.name=De,this.info=o,this.cause=a;}static isProviderError(o){return o instanceof He}};var Ke="ModelResponseError",Ve=class ze extends le{constructor({info:o,cause:a}){super({info:o,cause:a},Ke),this.name=Ke,this.cause=a,this.info=o;}static isModelResponseError(o){return o instanceof ze}};var Je="multi-string",Ea=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()});var Ge="object-schema",Ma=zod.z.object({type:zod.z.literal(Ge),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 We="range",Pa=zod.z.object({type:zod.z.literal(We),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 Ze="select-boolean",Ia=zod.z.object({type:zod.z.literal(Ze),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()});var Ye="select-string",_a=zod.z.object({type:zod.z.literal(Ye),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))});var Ra=[We,Je,Ye,Ge,Ze];zod.z.enum(Ra);var Aa=zod.z.discriminatedUnion("type",[Pa,Ea,_a,Ia,Ma]),Qe=(t=me,o=Ue)=>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),Aa),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var i,l;let s=Object.keys(a.def),r=Object.keys((l=(i=a.schema)==null?void 0:i.shape)!=null?l:{});return s.every(m=>r.includes(m))&&r.every(m=>s.includes(m))},{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 Na=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var Xe=t=>{if(Na()){let o=atob(t),a=new Uint8Array(o.length);for(let i=0;i<o.length;i++)a[i]=o.charCodeAt(i);return new TextDecoder("utf-8").decode(a)}else return Buffer.from(t,"base64").toString("utf-8")};var $a=Object.defineProperty,qa=Object.defineProperties,La=Object.getOwnPropertyDescriptors,et=Object.getOwnPropertySymbols,Ua=Object.prototype.hasOwnProperty,Ba=Object.prototype.propertyIsEnumerable,Fa=(t,o)=>(o=Symbol[t])?o:Symbol.for("Symbol."+t),tt=(t,o,a)=>o in t?$a(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,y=(t,o)=>{for(var a in o||(o={}))Ua.call(o,a)&&tt(t,a,o[a]);if(et)for(var a of et(o))Ba.call(o,a)&&tt(t,a,o[a]);return t},ot=(t,o)=>qa(t,La(o)),j=(t,o,a)=>new Promise((i,l)=>{var s=c=>{try{m(a.next(c));}catch(p){l(p);}},r=c=>{try{m(a.throw(c));}catch(p){l(p);}},m=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,r);m((a=a.apply(t,o)).next());}),Da=function(t,o){this[0]=t,this[1]=o;},Ka=(t,o,a)=>{var i=(r,m,c,p)=>{try{var h=a[r](m),g=(m=h.value)instanceof Da,T=h.done;Promise.resolve(g?m[0]:m).then(u=>g?i(r==="return"?r:"next",m[1]?{done:u.done,value:u.value}:u,c,p):c({value:u,done:T})).catch(u=>i("throw",u,c,p));}catch(u){p(u);}},l=r=>s[r]=m=>new Promise((c,p)=>i(r,m,c,p)),s={};return a=a.apply(t,o),s[Fa("asyncIterator")]=()=>s,l("next"),l("throw"),l("return"),s},Ha=t=>{let o=new WeakSet;return JSON.stringify(t,(a,i)=>{if(typeof i=="object"&&i!==null){if(o.has(i))return;o.add(i);}return i})},Va=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:Ha(t),ce="GatewayBaseError",M=class wt extends Error{constructor({info:o,cause:a},i){super(`[${i!=null?i:ce}]: ${o}
|
|
10
|
-
Message: ${Va(a)}`),this.name=ce,this.info=o,this.cause=a,this.name=i!=null?i:ce,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(o){return o instanceof wt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},J="system",O="user",w="assistant",ue="tool",za=[J,O,w,ue],Ct=zod.z.enum(za),Ja=[w],Ga=zod.z.enum(Ja),R="image",Tt="base64",Wa=["png","jpeg","webp","gif"],Za=zod.z.object({type:zod.z.literal(Tt),base64:zod.z.string(),media_type:zod.z.enum(Wa)}),Ya="url",Qa=zod.z.object({type:zod.z.literal(Ya),url:zod.z.string()}),Xa=zod.z.discriminatedUnion("type",[Za,Qa]),en=["low","medium","high","auto"],tn=zod.z.enum(en),on=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(R),detail:tn,value:Xa,metadata:t}),b="text",xt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(b),value:zod.z.string(),metadata:t}),he="partial-text",kt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(he),value:zod.z.string(),metadata:t}),k="tool-call",St=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(k),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),ge="partial-tool-call",jt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ge),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),A="tool-response",an=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(A),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),nn=[b,R,k,A],sn=zod.z.enum(nn),rn=(t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[xt(t),on(o),St(a),an(i)]),ln=[he,ge];zod.z.enum(ln);var mn=(t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[kt(t),jt(o)]),Ot=(t=Ct,o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(rn(o,a,i,l)),metadata:s}),fe=(t=Ga,o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:t,partialContent:mn(o,a),metadata:i}),dn=t=>xt().parse({modality:b,value:t}),cn=(t,o,a,i)=>St().parse({modality:k,index:t,id:o,name:a,arguments:i}),at=(t,o)=>fe().parse({role:t,partialContent:kt().parse({modality:he,value:o})}),nt=(t,o,a,i,l)=>fe().parse({role:t,partialContent:jt().parse({modality:ge,index:o,id:a,name:i,arguments:l})}),Et=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,pn=["object","array","number","string","boolean","enum"],it=zod.z.enum(pn),un=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([it,zod.z.array(zod.z.union([it,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()}),hn=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(un),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:hn}).optional();var gn="function",fn=zod.z.enum(["object","array","number","string","boolean","null"]),yn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:fn.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(yn).optional(),required:zod.z.array(zod.z.string()).optional()});var bn=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()}),vn=zod.z.enum(["function"]),wn=zod.z.object({type:vn,definition:zod.z.object({schema:bn})}),Cn=[gn];zod.z.enum(Cn);var Tn=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[wn.extend({metadata:t})]),N="text",Mt="token",xn=[N,Mt],kn=zod.z.enum(xn),Sn=zod.z.array(zod.z.string().min(1)),jn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),On=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(N),metadata:t,requests:Sn}),zod.z.object({modality:zod.z.literal(Mt),metadata:t,requests:jn})]),Pt="float",En=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),It="base64",Mn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),st=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Pt),embeddings:zod.z.array(En),usage:st.optional()}),zod.z.object({encodingFormat:zod.z.literal(It),embeddings:zod.z.array(Mn),usage:st.optional()})]);var _t=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),rt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Pn=rt.extend({topLogProbs:zod.z.array(rt)}),Rt=zod.z.array(Pn);zod.z.object({messages:zod.z.array(Ot()),usage:_t.optional(),logProbs:Rt.optional()});zod.z.object({partialMessages:zod.z.array(fe()),usage:_t.optional(),logProbs:Rt.optional()});var In=Object.defineProperty,lt=Object.getOwnPropertySymbols,_n=Object.prototype.hasOwnProperty,Rn=Object.prototype.propertyIsEnumerable,mt=(t,o,a)=>o in t?In(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,X=(t,o)=>{for(var a in o||(o={}))_n.call(o,a)&&mt(t,a,o[a]);if(lt)for(var a of lt(o))Rn.call(o,a)&&mt(t,a,o[a]);return t},dt="ProviderError",ct=class At extends M{constructor({info:o,cause:a}){super({info:o,cause:a},dt),this.name=dt,this.info=o,this.cause=a;}static isProviderError(o){return o instanceof At}},pt="ModelResponseError",S=class Nt extends M{constructor({info:o,cause:a}){super({info:o,cause:a},pt),this.name=pt,this.cause=a,this.info=o;}static isModelResponseError(o){return o instanceof Nt}},ut="InvalidModelRequestError",pe=class $t extends M{constructor({info:o,cause:a}){super({info:o,cause:a},ut),this.name=ut,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(o){return o instanceof $t}},ht="InvalidConfigError",E=class qt extends M{constructor({info:o,cause:a}){super({info:o,cause:a},ht),this.name=ht,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(o){return o instanceof qt}},gt="InvalidMessagesError",f=class Lt extends M{constructor({info:o,cause:a}){super({info:o,cause:a},gt),this.name=gt,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(o){return o instanceof Lt}},ft="InvalidToolsError",yt=class Ut extends M{constructor({info:o,cause:a}){super({info:o,cause:a},ft),this.name=ft,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(o){return o instanceof Ut}},bt="InvalidEmbeddingRequestsError",vt=class Bt extends M{constructor({info:o,cause:a}){super({info:o,cause:a},bt),this.name=bt,this.info=o,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(o){return o instanceof Bt}},ye="multi-string",Ft=zod.z.object({type:zod.z.literal(ye),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()}),An=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),Nn=t=>({def:Ft.parse(X({type:ye},t)),schema:An(t.max)}),Dt="object-schema",$n=zod.z.object({type:zod.z.literal(Dt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),be="range",Kt=zod.z.object({type:zod.z.literal(be),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()}),qn=(t,o,a,i)=>zod.z.number().min(t).max(o).step(a).default(i).optional(),ee=t=>({def:Kt.parse(X({type:be},t)),schema:qn(t.min,t.max,t.step,t.default)}),ve="select-boolean",Ht=zod.z.object({type:zod.z.literal(ve),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()}),Ln=t=>zod.z.boolean().nullable().default(t).optional(),Un=t=>({def:Ht.parse(X({type:ve},t)),schema:Ln(t.default)}),we="select-string",Vt=zod.z.object({type:zod.z.literal(we),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))}),Bn=(t,o)=>zod.z.enum(o).nullable().default(t).optional(),Ce=t=>({def:Vt.parse(X({type:we},t)),schema:Bn(t.default,t.choices)}),Fn=[be,ye,we,Dt,ve];zod.z.enum(Fn);var zt=zod.z.discriminatedUnion("type",[Kt,Ft,Vt,Ht,$n]),te=(t=Ct,o=sn)=>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),zt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var i,l;let s=Object.keys(a.def),r=Object.keys((l=(i=a.schema)==null?void 0:i.shape)!=null?l:{});return s.every(m=>r.includes(m))&&r.every(m=>s.includes(m))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),$=(t=kn)=>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),zt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var a,i;let l=Object.keys(o.def),s=Object.keys((i=(a=o.schema)==null?void 0:a.shape)!=null?i:{});return l.every(r=>s.includes(r))&&s.every(r=>l.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 Dn={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},Kn={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."},Hn=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.`}),Vn={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."},zn={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."},Jn={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."},Gn={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."},Wn={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."},Zn={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."},Yn={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."},Qn={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."},Xn={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."},ei={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."},ti={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},oi={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."},ai={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."},ni={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."},x={TEMPERATURE:Dn,MAX_TOKENS:Kn,STOP:Hn,TOP_A:Vn,TOP_P:zn,TOP_K:Jn,MIN_P:Gn,FREQUENCY_PENALTY:Wn,PRESENCE_PENALTY:Zn,REPETITION_PENALTY:Qn,SEED:Yn,LOG_PROBS:Xn,TOP_LOG_PROBS:ei,ECHO:ti,RESPONSE_FORMAT:oi,RESPONSE_FORMAT_WITH_SCHEMA:ai,RESPONSE_SCHEMA:ni},Jt=t=>Object.fromEntries(Object.entries(t).filter(([o,a])=>a!=null)),z=t=>t==null?void 0:t.replace(/\/$/,""),Gt=ee({param:"temperature",title:x.TEMPERATURE.title,description:x.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),Wt=t=>ee({param:"max_tokens",title:x.MAX_TOKENS.title,description:x.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Zt=t=>Nn({param:"stop_sequences",title:x.STOP(t).title,description:x.STOP(t).description,max:t}),Yt=ee({param:"top_p",title:x.TOP_P.title,description:x.TOP_P.description,min:0,max:1,step:.01,default:1}),Qt=ee({param:"top_k",title:x.TOP_K.title,description:x.TOP_K.description,min:0,max:1,step:.01,default:1}),Xt=Ce({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"]}),ii=(t,o)=>zod.z.object({temperature:Gt.schema,maxTokens:Wt(t).schema,stop:Zt(o).schema,topP:Yt.schema,topK:Qt.schema,toolChoice:Xt.schema}),si=(t,o)=>({temperature:Gt.def,maxTokens:Wt(t).def,stop:Zt(o).def,topP:Yt.def,topK:Qt.def,toolChoice:Xt.def}),eo=Ce({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:null,choices:["base64"]}),to=Ce({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:null,choices:["query","document"]}),oo=Un({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0}),ri=()=>zod.z.object({encodingFormat:eo.schema,inputType:to.schema,truncation:oo.schema}),li=()=>({encodingFormat:eo.def,inputType:to.def,truncation:oo.def}),C={base:(t,o)=>({def:si(t,o),schema:ii(t,o)})},v={base:()=>({def:li(),schema:ri()})},q=zod.z.enum([J,O,w,ue]),L={system:J,user:O,assistant:w,tool:O},U=[b,R,k,A],B=zod.z.enum([b,R,k,A]),mi=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),di=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),ci=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[mi,di])),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()})}),pi=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()})})}),ui=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()})}),hi=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),gi=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),fi=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[hi,gi])}),yi=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),bi=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),vi=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[yi,bi])}),wi=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),Ci=zod.z.object({type:zod.z.enum(["auto","any"])}),Ti=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),Te=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),ao=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 no=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([Te,ao])).min(1))}),xi=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Te,ao,no])).min(1))}),ki=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Te,no])).min(1))}),Si=zod.z.union([xi,ki]),ji=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Si).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([Ci,Ti]).optional(),tools:zod.z.array(wi).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()}),Oi="anthropic",Q=class{constructor(){this.version="v1",this.name=Oi,this.chatModelFactories={[io]:{model:Pi,modelOptions:Mi,modelSchema:so},[ro]:{model:Ri,modelOptions:_i,modelSchema:lo},[mo]:{model:$i,modelOptions:Ni,modelSchema:co},[po]:{model:Ui,modelOptions:Li,modelSchema:uo}},this.embeddingModelFactories={[ko]:{model:ss,modelOptions:is,modelSchema:So},[To]:{model:as,modelOptions:os,modelSchema:xo},[ho]:{model:Vi,modelOptions:Hi,modelSchema:go},[fo]:{model:Gi,modelOptions:Ji,modelSchema:yo},[bo]:{model:Yi,modelOptions:Zi,modelSchema:vo},[wo]:{model:es,modelOptions:Xi,modelSchema:Co}};}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:
|
|
11
|
-
${this.chatModelLiterals().join(", ")}`)});let
|
|
12
|
-
${this.embeddingModelLiterals().join(", ")}`)});let
|
|
13
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(s).reduce((
|
|
14
|
-
one of [${c.choices.join(", ")}]`)})}}return r}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let
|
|
15
|
-
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),
|
|
16
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let
|
|
17
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[
|
|
18
|
-
`).filter(i=>i.trim()!=="");for(let i of
|
|
19
|
-
received : ${JSON.stringify(l)}`)})}})}},
|
|
20
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((l,s)=>{let r=this.modelSchema.config.def[s].param,
|
|
21
|
-
${this.chatModelLiterals().join(", ")}`)});let i=this.chatModelFactories[
|
|
8
|
+
var qa=Object.defineProperty;var Se=Object.getOwnPropertySymbols,$a=Object.getPrototypeOf,Ua=Object.prototype.hasOwnProperty,Ba=Object.prototype.propertyIsEnumerable,Fa=Reflect.get;var Da=(t,a)=>(a=Symbol[t])?a:Symbol.for("Symbol."+t);var Oe=(t,a,o)=>a in t?qa(t,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[a]=o,J=(t,a)=>{for(var o in a||(a={}))Ua.call(a,o)&&Oe(t,o,a[o]);if(Se)for(var o of Se(a))Ba.call(a,o)&&Oe(t,o,a[o]);return t};var Q=(t,a,o)=>Fa($a(t),o,a);var U=(t,a,o)=>new Promise((i,l)=>{var s=c=>{try{d(o.next(c));}catch(u){l(u);}},r=c=>{try{d(o.throw(c));}catch(u){l(u);}},d=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,r);d((o=o.apply(t,a)).next());}),se=function(t,a){this[0]=t,this[1]=a;},je=(t,a,o)=>{var i=(r,d,c,u)=>{try{var h=o[r](d),g=(d=h.value)instanceof se,k=h.done;Promise.resolve(g?d[0]:d).then(p=>g?i(r==="return"?r:"next",d[1]?{done:p.done,value:p.value}:p,c,u):c({value:p,done:k})).catch(p=>i("throw",p,c,u));}catch(p){u(p);}},l=r=>s[r]=d=>new Promise((c,u)=>i(r,d,c,u)),s={};return o=o.apply(t,a),s[Da("asyncIterator")]=()=>s,l("next"),l("throw"),l("return"),s};var Ha=t=>{let a=new WeakSet;return JSON.stringify(t,(o,i)=>{if(typeof i=="object"&&i!==null){if(a.has(i))return;a.add(i);}return i})},Ka=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:Ha(t),re="GatewayBaseError",le=class _e extends Error{constructor({info:a,cause:o},i){super(`[${i!=null?i:re}]: ${a}
|
|
9
|
+
Message: ${Ka(o)}`),this.name=re,this.info=a,this.cause=o,this.name=i!=null?i:re,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(a){return a instanceof _e}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},za="system",Va="user",Ie="assistant",Ja="tool",Ga=[za,Va,Ie,Ja],de=zod.z.enum(Ga),Wa=[Ie],Za=zod.z.enum(Wa),Re="image",Ya="base64",Qa=["png","jpeg","webp","gif"],Xa=zod.z.object({type:zod.z.literal(Ya),base64:zod.z.string(),media_type:zod.z.enum(Qa)}),eo="url",to=zod.z.object({type:zod.z.literal(eo),url:zod.z.string()}),ao=zod.z.discriminatedUnion("type",[Xa,to]),oo=["low","medium","high","auto"],no=zod.z.enum(oo),io=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Re),detail:no,value:ao,metadata:t}),Ae="text",so=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ae),value:zod.z.string(),metadata:t}),Ne="partial-text",ro=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ne),value:zod.z.string(),metadata:t}),Le="tool-call",lo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Le),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),qe="partial-tool-call",mo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(qe),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),$e="tool-response",co=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal($e),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),uo=[Ae,Re,Le,$e],Ue=zod.z.enum(uo),po=(t=zod.z.undefined(),a=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[so(t),io(a),lo(o),co(i)]),ho=[Ne,qe];zod.z.enum(ho);var go=(t=zod.z.undefined(),a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[ro(t),mo(a)]);var fo=(t=de,a=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(po(a,o,i,l)),metadata:s}),yo=(t=Za,a=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:t,partialContent:go(a,o),metadata:i});var bo=["object","array","number","string","boolean","enum"],Ee=zod.z.enum(bo),vo=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Ee,zod.z.array(zod.z.union([Ee,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()}),wo=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(vo),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:wo}).optional();var Co="function";var ko=zod.z.enum(["object","array","number","string","boolean","null"]),xo=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ko.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(xo).optional(),required:zod.z.array(zod.z.string()).optional()});var To=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 So=zod.z.enum(["function"]);zod.z.object({type:So,definition:zod.z.object({schema:To})});var Oo=[Co];zod.z.enum(Oo);var jo="text",Eo="token",Mo=[jo,Eo];zod.z.enum(Mo);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var _o="float",Io=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Ro="base64",Ao=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Me=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(_o),embeddings:zod.z.array(Io),usage:Me.optional()}),zod.z.object({encodingFormat:zod.z.literal(Ro),embeddings:zod.z.array(Ao),usage:Me.optional()})]);var Be=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Pe=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),No=Pe.extend({topLogProbs:zod.z.array(Pe)}),Fe=zod.z.array(No);zod.z.object({messages:zod.z.array(fo()),usage:Be.optional(),logProbs:Fe.optional()});zod.z.object({partialMessages:zod.z.array(yo()),usage:Be.optional(),logProbs:Fe.optional()});var De="ProviderError",me=class Ke extends le{constructor({info:a,cause:o}){super({info:a,cause:o},De),this.name=De,this.info=a,this.cause=o;}static isProviderError(a){return a instanceof Ke}};var He="ModelResponseError",ze=class Ve extends le{constructor({info:a,cause:o}){super({info:a,cause:o},He),this.name=He,this.cause=o,this.info=a;}static isModelResponseError(a){return a instanceof Ve}};var Je="multi-string",Lo=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()});var Ge="object-schema",qo=zod.z.object({type:zod.z.literal(Ge),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 We="range",$o=zod.z.object({type:zod.z.literal(We),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 Ze="select-boolean",Uo=zod.z.object({type:zod.z.literal(Ze),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()});var Ye="select-string",Bo=zod.z.object({type:zod.z.literal(Ye),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))});var Fo=[We,Je,Ye,Ge,Ze];zod.z.enum(Fo);var Do=zod.z.discriminatedUnion("type",[$o,Lo,Bo,Uo,qo]),Qe=(t=de,a=Ue)=>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(a).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Do),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var i,l;let s=Object.keys(o.def),r=Object.keys((l=(i=o.schema)==null?void 0:i.shape)!=null?l:{});return s.every(d=>r.includes(d))&&r.every(d=>s.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 Ho=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var Xe=t=>{if(Ho()){let a=atob(t),o=new Uint8Array(a.length);for(let i=0;i<a.length;i++)o[i]=a.charCodeAt(i);return new TextDecoder("utf-8").decode(o)}else return Buffer.from(t,"base64").toString("utf-8")};var Ko=Object.defineProperty,zo=Object.defineProperties,Vo=Object.getOwnPropertyDescriptors,et=Object.getOwnPropertySymbols,Jo=Object.prototype.hasOwnProperty,Go=Object.prototype.propertyIsEnumerable,Wo=(t,a)=>(a=Symbol[t])?a:Symbol.for("Symbol."+t),tt=(t,a,o)=>a in t?Ko(t,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[a]=o,b=(t,a)=>{for(var o in a||(a={}))Jo.call(a,o)&&tt(t,o,a[o]);if(et)for(var o of et(a))Go.call(a,o)&&tt(t,o,a[o]);return t},at=(t,a)=>zo(t,Vo(a)),I=(t,a,o)=>new Promise((i,l)=>{var s=c=>{try{d(o.next(c));}catch(u){l(u);}},r=c=>{try{d(o.throw(c));}catch(u){l(u);}},d=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,r);d((o=o.apply(t,a)).next());}),Zo=function(t,a){this[0]=t,this[1]=a;},Yo=(t,a,o)=>{var i=(r,d,c,u)=>{try{var h=o[r](d),g=(d=h.value)instanceof Zo,k=h.done;Promise.resolve(g?d[0]:d).then(p=>g?i(r==="return"?r:"next",d[1]?{done:p.done,value:p.value}:p,c,u):c({value:p,done:k})).catch(p=>i("throw",p,c,u));}catch(p){u(p);}},l=r=>s[r]=d=>new Promise((c,u)=>i(r,d,c,u)),s={};return o=o.apply(t,a),s[Wo("asyncIterator")]=()=>s,l("next"),l("throw"),l("return"),s},Qo=t=>{let a=new WeakSet;return JSON.stringify(t,(o,i)=>{if(typeof i=="object"&&i!==null){if(a.has(i))return;a.add(i);}return i})},Xo=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:Qo(t),ce="GatewayBaseError",L=class wt extends Error{constructor({info:a,cause:o},i){super(`[${i!=null?i:ce}]: ${a}
|
|
10
|
+
Message: ${Xo(o)}`),this.name=ce,this.info=a,this.cause=o,this.name=i!=null?i:ce,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(a){return a instanceof wt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},W="system",R="user",C="assistant",pe="tool",en=[W,R,C,pe],Ct=zod.z.enum(en),tn=[C],an=zod.z.enum(tn),B="image",kt="base64",on=["png","jpeg","webp","gif"],nn=zod.z.object({type:zod.z.literal(kt),base64:zod.z.string(),media_type:zod.z.enum(on)}),sn="url",rn=zod.z.object({type:zod.z.literal(sn),url:zod.z.string()}),ln=zod.z.discriminatedUnion("type",[nn,rn]),dn=["low","medium","high","auto"],mn=zod.z.enum(dn),cn=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(B),detail:mn,value:ln,metadata:t}),v="text",xt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(v),value:zod.z.string(),metadata:t}),he="partial-text",Tt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(he),value:zod.z.string(),metadata:t}),M="tool-call",St=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(M),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),ge="partial-tool-call",Ot=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ge),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),F="tool-response",un=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(F),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),pn=[v,B,M,F],hn=zod.z.enum(pn),gn=(t=zod.z.undefined(),a=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[xt(t),cn(a),St(o),un(i)]),fn=[he,ge];zod.z.enum(fn);var yn=(t=zod.z.undefined(),a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Tt(t),Ot(a)]),jt=(t=Ct,a=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(gn(a,o,i,l)),metadata:s}),fe=(t=an,a=zod.z.undefined(),o=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:t,partialContent:yn(a,o),metadata:i}),bn=t=>xt().parse({modality:v,value:t}),vn=(t,a,o,i)=>St().parse({modality:M,index:t,id:a,name:o,arguments:i}),ot=(t,a)=>fe().parse({role:t,partialContent:Tt().parse({modality:he,value:a})}),nt=(t,a,o,i,l)=>fe().parse({role:t,partialContent:Ot().parse({modality:ge,index:a,id:o,name:i,arguments:l})}),Et=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,wn=["object","array","number","string","boolean","enum"],it=zod.z.enum(wn),Cn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([it,zod.z.array(zod.z.union([it,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()}),kn=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(Cn),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:kn}).optional();var xn="function",Tn=zod.z.enum(["object","array","number","string","boolean","null"]),Sn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Tn.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(Sn).optional(),required:zod.z.array(zod.z.string()).optional()});var On=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()}),jn=zod.z.enum(["function"]),En=zod.z.object({type:jn,definition:zod.z.object({schema:On})}),Mn=[xn];zod.z.enum(Mn);var Pn=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[En.extend({metadata:t})]),D="text",Mt="token",_n=[D,Mt],In=zod.z.enum(_n),Rn=zod.z.array(zod.z.string().min(1)),An=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Nn=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(D),metadata:t,requests:Rn}),zod.z.object({modality:zod.z.literal(Mt),metadata:t,requests:An})]),Pt="float",Ln=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),_t="base64",qn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),st=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Pt),embeddings:zod.z.array(Ln),usage:st.optional()}),zod.z.object({encodingFormat:zod.z.literal(_t),embeddings:zod.z.array(qn),usage:st.optional()})]);var It=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),rt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),$n=rt.extend({topLogProbs:zod.z.array(rt)}),Rt=zod.z.array($n);zod.z.object({messages:zod.z.array(jt()),usage:It.optional(),logProbs:Rt.optional()});zod.z.object({partialMessages:zod.z.array(fe()),usage:It.optional(),logProbs:Rt.optional()});var Un=Object.defineProperty,lt=Object.getOwnPropertySymbols,Bn=Object.prototype.hasOwnProperty,Fn=Object.prototype.propertyIsEnumerable,dt=(t,a,o)=>a in t?Un(t,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[a]=o,ee=(t,a)=>{for(var o in a||(a={}))Bn.call(a,o)&&dt(t,o,a[o]);if(lt)for(var o of lt(a))Fn.call(a,o)&&dt(t,o,a[o]);return t},mt="ProviderError",ct=class At extends L{constructor({info:a,cause:o}){super({info:a,cause:o},mt),this.name=mt,this.info=a,this.cause=o;}static isProviderError(a){return a instanceof At}},ut="ModelResponseError",_=class Nt extends L{constructor({info:a,cause:o}){super({info:a,cause:o},ut),this.name=ut,this.cause=o,this.info=a;}static isModelResponseError(a){return a instanceof Nt}},pt="InvalidModelRequestError",ue=class Lt extends L{constructor({info:a,cause:o}){super({info:a,cause:o},pt),this.name=pt,this.cause=o,this.info=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(a){return a instanceof Lt}},ht="InvalidConfigError",N=class qt extends L{constructor({info:a,cause:o}){super({info:a,cause:o},ht),this.name=ht,this.cause=o,this.info=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(a){return a instanceof qt}},gt="InvalidMessagesError",y=class $t extends L{constructor({info:a,cause:o}){super({info:a,cause:o},gt),this.name=gt,this.cause=o,this.info=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(a){return a instanceof $t}},ft="InvalidToolsError",yt=class Ut extends L{constructor({info:a,cause:o}){super({info:a,cause:o},ft),this.name=ft,this.cause=o,this.info=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(a){return a instanceof Ut}},bt="InvalidEmbeddingRequestsError",vt=class Bt extends L{constructor({info:a,cause:o}){super({info:a,cause:o},bt),this.name=bt,this.info=a,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(a){return a instanceof Bt}},ye="multi-string",Ft=zod.z.object({type:zod.z.literal(ye),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()}),Dn=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),Hn=t=>({def:Ft.parse(ee({type:ye},t)),schema:Dn(t.max)}),Dt="object-schema",Kn=zod.z.object({type:zod.z.literal(Dt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),be="range",Ht=zod.z.object({type:zod.z.literal(be),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()}),zn=(t,a,o,i)=>zod.z.number().min(t).max(a).step(o).default(i).optional(),te=t=>({def:Ht.parse(ee({type:be},t)),schema:zn(t.min,t.max,t.step,t.default)}),ve="select-boolean",Kt=zod.z.object({type:zod.z.literal(ve),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()}),Vn=t=>zod.z.boolean().nullable().default(t).optional(),Jn=t=>({def:Kt.parse(ee({type:ve},t)),schema:Vn(t.default)}),we="select-string",zt=zod.z.object({type:zod.z.literal(we),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))}),Gn=(t,a)=>zod.z.enum(a).nullable().default(t).optional(),Ce=t=>({def:zt.parse(ee({type:we},t)),schema:Gn(t.default,t.choices)}),Wn=[be,ye,we,Dt,ve];zod.z.enum(Wn);var Vt=zod.z.discriminatedUnion("type",[Ht,Ft,zt,Kt,Kn]),A=(t=Ct,a=hn)=>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(a).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Vt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var i,l;let s=Object.keys(o.def),r=Object.keys((l=(i=o.schema)==null?void 0:i.shape)!=null?l:{});return s.every(d=>r.includes(d))&&r.every(d=>s.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),H=(t=In)=>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),Vt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var o,i;let l=Object.keys(a.def),s=Object.keys((i=(o=a.schema)==null?void 0:o.shape)!=null?i:{});return l.every(r=>s.includes(r))&&s.every(r=>l.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 Zn={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."},Yn={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."},Qn=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.`}),Xn={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."},ei={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."},ti={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."},ai={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."},oi={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."},ni={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."},ii={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."},si={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."},ri={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."},li={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."},di={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},mi={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."},ci={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."},ui={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."},x={TEMPERATURE:Zn,MAX_TOKENS:Yn,STOP:Qn,TOP_A:Xn,TOP_P:ei,TOP_K:ti,MIN_P:ai,FREQUENCY_PENALTY:oi,PRESENCE_PENALTY:ni,REPETITION_PENALTY:si,SEED:ii,LOG_PROBS:ri,TOP_LOG_PROBS:li,ECHO:di,RESPONSE_FORMAT:mi,RESPONSE_FORMAT_WITH_SCHEMA:ci,RESPONSE_SCHEMA:ui},Jt=t=>Object.fromEntries(Object.entries(t).filter(([a,o])=>o!=null)),G=t=>t==null?void 0:t.replace(/\/$/,""),Gt=te({param:"temperature",title:x.TEMPERATURE.title,description:x.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),Wt=t=>te({param:"max_tokens",title:x.MAX_TOKENS.title,description:x.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Zt=t=>Hn({param:"stop_sequences",title:x.STOP(t).title,description:x.STOP(t).description,max:t}),Yt=te({param:"top_p",title:x.TOP_P.title,description:x.TOP_P.description,min:0,max:1,step:.01,default:1}),Qt=te({param:"top_k",title:x.TOP_K.title,description:x.TOP_K.description,min:0,max:1,step:.01,default:1}),Xt=Ce({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"]}),pi=(t,a)=>zod.z.object({temperature:Gt.schema,maxTokens:Wt(t).schema,stop:Zt(a).schema,topP:Yt.schema,topK:Qt.schema,toolChoice:Xt.schema}),hi=(t,a)=>({temperature:Gt.def,maxTokens:Wt(t).def,stop:Zt(a).def,topP:Yt.def,topK:Qt.def,toolChoice:Xt.def}),ea=Ce({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:null,choices:["base64"]}),ta=Ce({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:null,choices:["query","document"]}),aa=Jn({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0}),gi=()=>zod.z.object({encodingFormat:ea.schema,inputType:ta.schema,truncation:aa.schema}),fi=()=>({encodingFormat:ea.def,inputType:ta.def,truncation:aa.def}),f={base:(t,a)=>({def:hi(t,a),schema:pi(t,a)})},w={base:()=>({def:fi(),schema:gi()})},yi="anthropic",X=class{constructor(){this.version="v1",this.name=yi,this.chatModelFactories={[ca]:{model:Ji,modelOptions:Vi,modelSchema:ua},[va]:{model:is,modelOptions:ns,modelSchema:wa},[ya]:{model:as,modelOptions:ts,modelSchema:ba},[ia]:{model:$i,modelOptions:qi,modelSchema:sa},[ra]:{model:Fi,modelOptions:Bi,modelSchema:la},[pa]:{model:Zi,modelOptions:Wi,modelSchema:ha},[da]:{model:Ki,modelOptions:Hi,modelSchema:ma},[ga]:{model:Xi,modelOptions:Qi,modelSchema:fa}},this.embeddingModelFactories={[_a]:{model:Os,modelOptions:Ss,modelSchema:Ia},[Ma]:{model:xs,modelOptions:ks,modelSchema:Pa},[Ca]:{model:cs,modelOptions:ms,modelSchema:ka},[xa]:{model:hs,modelOptions:ps,modelSchema:Ta},[Sa]:{model:ys,modelOptions:fs,modelSchema:Oa},[ja]:{model:ws,modelOptions:vs,modelSchema:Ea}};}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 ct({info:`Anthropic chat model: ${a} not found`,cause:new Error(`Anthropic chat model: ${a} not found, available chat models:
|
|
11
|
+
${this.chatModelLiterals().join(", ")}`)});let o=this.chatModelFactories[a].model,i=this.chatModelFactories[a].modelOptions.parse(t);return new o(i)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,a)=>(t[a]=this.embeddingModelFactories[a].modelSchema,t),{})}embeddingModel(t){let a=t.modelName;if(!(a in this.embeddingModelFactories))throw new ct({info:`Anthropic embedding model: ${a} not found`,cause:new Error(`Anthropic embedding model: ${a} not found, available embedding models:
|
|
12
|
+
${this.embeddingModelLiterals().join(", ")}`)});let o=this.embeddingModelFactories[a].model,i=this.embeddingModelFactories[a].modelOptions.parse(t);return new o(i)}};X.chatBaseUrl="https://api.anthropic.com/v1",X.embeddingBaseUrl="https://api.voyageai.com/v1";var T=zod.z.enum([W,R,C,pe]),S={system:W,user:R,assistant:C,tool:R},O=[v,B,M,F],j=zod.z.enum([v,B,M,F]),bi=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),vi=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),wi=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[bi,vi])),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()})}),Ci=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()})})}),ki=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()})}),xi=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),Ti=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),Si=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[xi,Ti])}),Oi=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),ji=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),Ei=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[Oi,ji])}),Mi=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),Pi=zod.z.object({type:zod.z.enum(["auto","any"])}),_i=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),ke=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),oa=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 na=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([ke,oa])).min(1))}),Ii=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([ke,oa,na])).min(1))}),Ri=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([ke,na])).min(1))}),Ai=zod.z.union([Ii,Ri]),Ni=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Ai).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([Pi,_i]).optional(),tools:zod.z.array(Mi).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()}),P=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),E=class{constructor(t,a){this.version="v1";let o=P.parse(a);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=G(X.chatBaseUrl),this.completeChatUrl=G(o.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=G(o.streamChatUrl||`${this.baseUrl}/messages`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"x-api-key":`${this.apiKey}`,"anthropic-version":"2023-06-01","content-type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){let a=0,o=!0;return t["x-should-retry"]&&(o=t["x-should-retry"].toLowerCase()!=="false"),t["retry-after"]&&(a=parseInt(t["retry-after"])*1e3),{shouldRetry:o,delayMs:a}}getTokenCount(t){return t.reduce((a,o)=>a+o.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformModelRequest(t){let a=Ni.safeParse(t);if(!a.success)throw new ue({info:"Invalid model request",cause:a.error});let o=a.data,i=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new ue({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let l={};o.tool_choice&&(o.tool_choice.type==="tool"?l.toolChoice=o.tool_choice.name:l.toolChoice=o.tool_choice.type),l.maxTokens=o.max_tokens,l.temperature=o.temperature,l.topP=o.top_p,l.topK=o.top_k,l.stop=o.stop_sequences;let s=Et().parse(Jt(l)),r=[],d={};o.system&&r.push({role:W,content:[{modality:v,value:o.system}]}),o.messages.forEach(u=>{let h=u.role;switch(h){case"user":{let g=u.content;if(typeof g=="string")r.push({role:h,content:[{modality:v,value:g}]});else {let k=g.map(p=>{if(p.type==="text")return {modality:v,value:p.text};if(p.type==="image"){let ie="auto",Y=p.source.media_type.split("/")[1];return {modality:B,detail:ie,value:{type:kt,media_type:Y,base64:p.source.data}}}else return {modality:F,id:p.tool_use_id,index:d[p.tool_use_id].index,name:d[p.tool_use_id].name,data:typeof p.content=="string"?p.content:JSON.stringify(p.content)}});r.push({role:h,content:k});}}break;case"assistant":{let g=u.content;if(typeof g=="string")r.push({role:h,content:[{modality:v,value:g}]});else {let k=g.map((p,ie)=>{if(p.type==="text")return {modality:v,value:p.text};{let Y={modality:M,id:p.id,index:ie,name:p.name,arguments:JSON.stringify(p.input)};return d[p.id]=Y,Y}});r.push({role:h,content:k});}}break}});let c=[];return o.tools&&o.tools.forEach(u=>{c.push({type:"function",definition:{schema:{name:u.name,description:u.description||"",parameters:u.input_schema}}});}),{modelName:i,config:s,messages:r,tools:c.length>0?c:void 0}}transformConfig(t,a,o){let i=t.toolChoice;delete t.toolChoice;let l=this.modelSchema.config.schema.safeParse(t);if(!l.success)throw new N({info:`Invalid config for model : '${this.modelName}'`,cause:l.error});let s=l.data;i!==void 0&&(s.toolChoice=i),Object.keys(s).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new N({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
|
|
13
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(s).reduce((d,c)=>{let u=this.modelSchema.config.def[c],h=u.param,g=s[c];return h==="max_tokens"&&u.type==="range"&&g===0?d[h]=u.max:d[h]=g,d},{});if(!r.max_tokens)throw new N({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`'max_tokens' is required for model : '${this.modelName}'`)});if("tool_choice"in r&&r.tool_choice!==void 0){let d=r.tool_choice;if(!o||o&&o.length===0)throw new N({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let c=this.modelSchema.config.def.toolChoice;if(c.choices.includes(d))r.tool_choice={type:d};else if(o.map(u=>u.definition.schema.name).includes(d))r.tool_choice={type:"tool",name:d};else throw new N({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
|
|
14
|
+
one of [${c.choices.join(", ")}]`)})}}return r}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let a=t.map(s=>{let r=jt().safeParse(s);if(!r.success)throw new y({info:"Invalid messages",cause:r.error});return r.data});a.forEach(s=>{s.content.forEach(r=>{if(!this.modelSchema.modalities.includes(r.modality))throw new y({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${r.modality}',
|
|
15
|
+
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),a.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new y({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
|
|
16
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let o="",i=[];if(a.forEach(s=>{switch(s.role){case W:s.content.forEach(r=>{if(r.modality===v)o+=r.value;else throw new y({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${r.modality}'`)})});break;case C:{let r=[];s.content.forEach(d=>{if(d.modality===v)r.push({type:"text",text:d.value});else if(d.modality===M)r.push({type:"tool_use",id:d.id,name:d.name,input:JSON.parse(d.arguments)});else throw new y({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),i.push({role:this.modelSchema.roles[s.role],content:r});}break;case R:{let r=[];s.content.forEach(d=>{if(d.modality===v)r.push({type:"text",text:d.value});else if(d.modality===B){if(d.value.type==="base64")r.push({type:"image",source:{type:"base64",media_type:`image/${d.value.media_type}`,data:d.value.base64}});else if(d.value.type==="url")throw new y({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${d.value.type}'`)})}else throw new y({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),i.push({role:this.modelSchema.roles[s.role],content:r});}break;case pe:{let r=[];s.content.forEach(d=>{if(d.modality===F)r.push({type:"tool_result",tool_use_id:d.id,content:d.data});else throw new y({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),i.push({role:this.modelSchema.roles[s.role],content:r});}break;default:throw new y({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
|
|
17
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[R])throw new y({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let l=s=>s===this.modelSchema.roles[R]?this.modelSchema.roles[C]:this.modelSchema.roles[R];for(let s=1;s<i.length;s++)if(i[s].role!==l(i[s-1].role))throw new y({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires messages to alternate between user and assistant`)});return {system:o,messages:i}}transformTools(t){if(!this.modelSchema.modalities.includes(M))throw new yt({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${M}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(a=>{let o=Pn().safeParse(a);if(!o.success)throw new yt({info:"Invalid tools",cause:o.error});return o.data}).map(a=>({name:a.definition.schema.name,description:a.definition.schema.description,input_schema:a.definition.schema.parameters}))}}getCompleteChatUrl(t,a,o){return I(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(t,a,o){return I(this,null,function*(){let i=this.getDefaultHeaders();return o&&o.length>0&&(i=at(b({},i),{"anthropic-beta":"tools-2024-05-16"})),new Promise(l=>{l(i);})})}getCompleteChatData(t,a,o){return I(this,null,function*(){let i=this.transformConfig(t,a,o),l=this.transformMessages(a);if(l.messages&&l.messages.length===0)throw new y({info:"Messages are required",cause:new Error("Messages are required")});let s=o?this.transformTools(o):{};return new Promise(r=>{r(b(b(b(b({},this.getDefaultParams()),i),l),s));})})}transformCompleteChatResponse(t){let a=wi.safeParse(t);if(a.success){let o=a.data,i=o.content.map((r,d)=>{if(r.type==="text")return bn(r.text);if(r.type==="tool_use")return vn(d,r.id,r.name,JSON.stringify(r.input))}),l=[{role:C,content:i}],s={promptTokens:o.usage.input_tokens,completionTokens:o.usage.output_tokens,totalTokens:o.usage.input_tokens+o.usage.output_tokens};return {messages:l,usage:s,logProbs:[]}}throw new _({info:"Invalid response from model",cause:a.error})}getStreamChatUrl(t,a,o){return I(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(t,a,o){let i=this.getDefaultHeaders();return o&&o.length>0&&(i=at(b({},i),{"anthropic-beta":"tools-2024-05-16"})),new Promise(l=>{l(i);})}getStreamChatData(t,a,o){return I(this,null,function*(){let i=this.transformConfig(t,a,o),l=this.transformMessages(a);if(l.messages&&l.messages.length===0)throw new y({info:"Messages are required",cause:new Error("Messages are required")});let s=o?this.transformTools(o):{};return new Promise(r=>{r(b(b(b(b({stream:!0},this.getDefaultParams()),i),l),s));})})}transformStreamChatResponseChunk(t,a){return Yo(this,null,function*(){let o=(a+t).split(`
|
|
18
|
+
`).filter(i=>i.trim()!=="");for(let i of o)if(i.startsWith("data: {")&&i.endsWith("}")){let l;try{l=JSON.parse(i.substring(6));}catch(s){throw new _({info:`Malformed JSON received in stream : ${l}`,cause:s})}if("type"in l){if(l.type==="message_stop")return;if(l.type==="message_start"){let s=Ci.safeParse(l);if(s.success){let r=s.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:a};}else throw new _({info:"Invalid response from model",cause:s.error})}else if(l.type==="message_delta"){let s=ki.safeParse(l);if(s.success){let r=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:0,completionTokens:r.usage.output_tokens,totalTokens:r.usage.output_tokens}},buffer:a};}else throw new _({info:"Invalid response from model",cause:s.error})}else if(l.type==="content_block_start"){let s=Si.safeParse(l);if(s.success){let r=s.data,d=[];r.content_block.type==="text"?d.push(ot(C,r.content_block.text)):r.content_block.type==="tool_use"&&d.push(nt(C,r.index,r.content_block.id,r.content_block.name,"")),yield {partialResponse:{partialMessages:d},buffer:a};}else throw new _({info:"Invalid response from model",cause:s.error})}else if(l.type==="content_block_delta"){let s=Ei.safeParse(l);if(s.success){let r=s.data,d=[];r.delta.type==="text_delta"?d.push(ot(C,r.delta.text)):r.delta.type==="input_json_delta"&&d.push(nt(C,r.index,"","",r.delta.partial_json)),yield {partialResponse:{partialMessages:d},buffer:a};}else throw new _({info:"Invalid response from model",cause:s.error})}}else throw new _({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property,
|
|
19
|
+
received : ${JSON.stringify(l)}`)})}})}},ia="claude-3-5-sonnet-20240620",Li="Most intelligent model. Highest level of intelligence and capability.",sa=A(T,j).parse({name:ia,description:Li,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:O,config:{def:f.base(8192,4).def,schema:f.base(8192,4).schema}}),qi=P,$i=class extends E{constructor(t){super(sa,t);}},ra="claude-3-5-sonnet-20241022",Ui="Most intelligent model. Highest level of intelligence and capability.",la=A(T,j).parse({name:ra,description:Ui,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:O,config:{def:f.base(8192,4).def,schema:f.base(8192,4).schema}}),Bi=P,Fi=class extends E{constructor(t){super(la,t);}},da="claude-3-5-sonnet-latest",Di="Most intelligent model. Highest level of intelligence and capability.",ma=A(T,j).parse({name:da,description:Di,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:O,config:{def:f.base(8192,4).def,schema:f.base(8192,4).schema}}),Hi=P,Ki=class extends E{constructor(t){super(ma,t);}},ca="claude-3-haiku-20240307",zi="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",ua=A(T,j).parse({name:ca,description:zi,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:O,config:{def:f.base(4096,4).def,schema:f.base(4096,4).schema}}),Vi=P,Ji=class extends E{constructor(t){super(ua,t);}},pa="claude-3-5-haiku-20241022",Gi="Our fastest model with intelligence at blazing speeds.",ha=A(T,j).parse({name:pa,description:Gi,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:O,config:{def:f.base(8192,4).def,schema:f.base(8192,4).schema}}),Wi=P,Zi=class extends E{constructor(t){super(ha,t);}},ga="claude-3-5-haiku-latest",Yi="Our fastest model with intelligence at blazing speeds.",fa=A(T,j).parse({name:ga,description:Yi,maxInputTokens:2e5,maxOutputTokens:8192,roles:S,modalities:O,config:{def:f.base(8192,4).def,schema:f.base(8192,4).schema}}),Qi=P,Xi=class extends E{constructor(t){super(fa,t);}},ya="claude-3-opus-20240229",es="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",ba=A(T,j).parse({name:ya,description:es,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:O,config:{def:f.base(4096,4).def,schema:f.base(4096,4).schema}}),ts=P,as=class extends E{constructor(t){super(ba,t);}},va="claude-3-sonnet-20240229",os="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",wa=A(T,j).parse({name:va,description:os,maxInputTokens:2e5,maxOutputTokens:4096,roles:S,modalities:O,config:{def:f.base(4096,4).def,schema:f.base(4096,4).schema}}),ns=P,is=class extends E{constructor(t){super(wa,t);}},K=[D],z=zod.z.enum([D]),ss=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()})}),rs=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),ls=zod.z.object({model:zod.z.string().min(1).optional(),input:rs,encoding_format:zod.z.enum(["base64"]).nullable().optional(),input_type:zod.z.enum(["query","document"]).nullable().optional(),truncation:zod.z.boolean().optional()}),q=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),V=class{constructor(t,a){this.version="v1";let o=q.parse(a);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=G(X.embeddingBaseUrl),this.getEmbeddingsUrl=G(o.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getTokenCount(t){return t.requests.reduce((a,o)=>a+o.length,0)}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}transformModelRequest(t){let a=ls.safeParse(t);if(!a.success)throw new ue({info:"Invalid model request",cause:a.error});let o=a.data,i=o.model,l={encodingFormat:o.encoding_format,inputType:o.input_type,truncation:o.truncation},s=Et().parse(Jt(l)),r;return typeof o.input=="string"?r={modality:D,requests:[o.input]}:r={modality:D,requests:o.input},{modelName:i,config:s,embeddingRequests:r}}transformConfig(t,a){let o=this.modelSchema.config.schema.safeParse(t);if(!o.success)throw new N({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let i=o.data;return Object.keys(i).forEach(l=>{if(!this.modelSchema.config.def[l])throw new N({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${l}',
|
|
20
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((l,s)=>{let r=this.modelSchema.config.def[s].param,d=i[s];return l[r]=d,l},{})}transformEmbeddingRequests(t){let a=Nn().safeParse(t);if(!a.success)throw new vt({info:"Invalid embedding requests",cause:a.error});if(a.data.requests.length>128)throw new vt({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:a.data.requests}}getGetEmbeddingsUrl(t,a){return I(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,a){return I(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,a){return I(this,null,function*(){return new Promise(o=>{o(b(b(b({},this.getDefaultParams()),this.transformConfig(t,a)),this.transformEmbeddingRequests(a)));})})}transformGetEmbeddingsResponse(t){let a,o=ss.safeParse(t);if(o.success){let i=o.data;a=typeof i.data[0].embedding=="string"?_t:Pt;let l=i.data.map(s=>typeof s.embedding=="string"?{index:s.index,embedding:s.embedding}:{index:s.index,embedding:s.embedding});return {encodingFormat:a,embeddings:l,usage:{totalTokens:i.usage.total_tokens}}}throw new _({info:"Invalid response from model",cause:o.error})}},Ca="voyage-code-2",ds="Optimized for code retrieval.",ka=H(z).parse({name:Ca,description:ds,modalities:K,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:w.base().def,schema:w.base().schema}}),ms=q,cs=class extends V{constructor(t){super(ka,t);}},xa="voyage-law-2",us="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",Ta=H(z).parse({name:xa,description:us,modalities:K,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:w.base().def,schema:w.base().schema}}),ps=q,hs=class extends V{constructor(t){super(Ta,t);}},Sa="voyage-multilingual-2",gs="Optimized for multilingual retrieval and RAG.",Oa=H(z).parse({name:Sa,description:gs,modalities:K,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:w.base().def,schema:w.base().schema}}),fs=q,ys=class extends V{constructor(t){super(Oa,t);}},ja="voyage-finance-2",bs="Optimized for finance retrieval and RAG.",Ea=H(z).parse({name:ja,description:bs,modalities:K,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:w.base().def,schema:w.base().schema}}),vs=q,ws=class extends V{constructor(t){super(Ea,t);}},Ma="voyage-3-lite",Cs="Optimized for latency and cost.",Pa=H(z).parse({name:Ma,description:Cs,modalities:K,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:w.base().def,schema:w.base().schema}}),ks=q,xs=class extends V{constructor(t){super(Pa,t);}},_a="voyage-3",Ts="Optimized for quality.",Ia=H(z).parse({name:_a,description:Ts,modalities:K,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:w.base().def,schema:w.base().schema}}),Ss=q,Os=class extends V{constructor(t){super(Ia,t);}};var ae=zod.z.object({modelName:zod.z.string(),awsRegion:zod.z.string(),awsAccessKeyId:zod.z.string(),awsSecretAccessKey:zod.z.string()});var oe=class t extends E{constructor(o,i){let l=ae.parse(i);super(o,{apiKey:"random-api-key",modelName:l.modelName});this.version="v1";this.modelSchema=o,this.modelName=l.modelName,this.awsRegion=l.awsRegion,this.awsUrl=$.awsUrl(this.awsRegion),this.awsService=$.awsService,this.awsAccessKeyId=l.awsAccessKeyId,this.awsSecretAccessKey=l.awsSecretAccessKey;}getDefaultBaseUrl(){return this.awsUrl}getDefaultHeaders(){return {Accept:"application/json","Content-Type":"application/json",host:this.awsUrl.split("://")[1]}}getDefaultParams(){return {anthropic_version:"bedrock-2023-05-31"}}getCompleteChatUrl(o,i,l){return new Promise(s=>{s(`${this.awsUrl}/model/${this.modelName}/invoke`);})}getCompleteChatHeaders(o,i,l){return U(this,null,function*(){let s=new URL(yield this.getCompleteChatUrl(o,i,l)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},d=this.getDefaultHeaders(),c=this.getCompleteChatData(o||{},i||[],l),u=new protocolHttp.HttpRequest({hostname:s.hostname,path:s.pathname,protocol:s.protocol,method:"POST",body:JSON.stringify(c),headers:d});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:this.awsRegion,sha256:sha256Js.Sha256}).sign(u)).headers})}getCompleteChatData(o,i,l){return U(this,null,function*(){let s=J(J({},this.getDefaultParams()),Q(t.prototype,this,"getCompleteChatData").call(this,o,i,l));return new Promise(r=>{r(s);})})}getStreamChatUrl(o,i,l){return U(this,null,function*(){return new Promise(s=>{s(`${this.awsUrl}/model/${this.modelName}/invoke-with-response-stream`);})})}getStreamChatHeaders(o,i,l){return U(this,null,function*(){let s=new URL(yield this.getStreamChatUrl(o,i,l)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},d=this.getDefaultHeaders(),c=this.getCompleteChatData(o||{},i||[],l),u=new protocolHttp.HttpRequest({hostname:s.hostname,path:s.pathname,protocol:s.protocol,method:"POST",body:JSON.stringify(c),headers:d});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:this.awsRegion,sha256:sha256Js.Sha256}).sign(u)).headers})}getStreamChatData(o,i,l){return U(this,null,function*(){let s=J(J({},this.getDefaultParams()),Q(t.prototype,this,"getStreamChatData").call(this,o,i,l));return "stream"in s&&delete s.stream,s})}transformStreamChatResponseChunk(o,i){return je(this,null,function*(){let l=o.toString(),s=/{\s*"bytes"\s*:\s*"[\w=+/]+".*?}/g,r=l.match(s)||[];for(let d of r){let c=d.indexOf("{"),u=d.indexOf("}");if(c!==-1&&u!==-1&&c<u){let h;try{h=JSON.parse(d.slice(c,u+1));}catch(p){throw new ze({info:`Malformed JSON received in stream : ${h}`,cause:p})}let g=Xe(h.bytes),k=(yield new se(Q(t.prototype,this,"transformStreamChatResponseChunk").call(this,`data: ${g}`,i).next())).value;k&&(yield k);}}})}};var xe="anthropic.claude-3-haiku-20240307-v1:0",js="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.",Te=Qe(T,j).parse({name:xe,description:js,maxInputTokens:128e3,maxOutputTokens:128e3,roles:S,modalities:O,config:{def:f.base(128e3,4).def,schema:f.base(128e3,4).schema}}),La=ae,ne=class extends oe{constructor(a){super(Te,a);}};var Es="bedrock",$=class{constructor(){this.version="v1";this.name=Es;this.chatModelFactories={[xe]:{model:ne,modelOptions:La,modelSchema:Te}};this.embeddingModelFactories={};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((a,o)=>(a[o]=this.chatModelFactories[o].modelSchema,a),{})}chatModel(a){let o=a.modelName;if(!(o in this.chatModelFactories))throw new me({info:`Bedrock chat model: ${o} not found`,cause:new Error(`Bedrock chat model: ${o} not found, available chat models:
|
|
21
|
+
${this.chatModelLiterals().join(", ")}`)});let i=this.chatModelFactories[o].model,l=this.chatModelFactories[o].modelOptions.parse(a);return new i(l)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((a,o)=>(a[o]=this.embeddingModelFactories[o].modelSchema,a),{})}embeddingModel(a){throw new me({info:"Adaline Bedrock provider does not support embedding models yet",cause:new Error("Adaline Bedrock provider does not support embedding models yet")})}};$.awsService="bedrock",$.awsUrl=a=>`https://bedrock.${a}.amazonaws.com`;
|
|
22
22
|
|
|
23
|
-
exports.BaseChatModelAnthropic =
|
|
24
|
-
exports.BaseChatModelOptions =
|
|
25
|
-
exports.Bedrock =
|
|
23
|
+
exports.BaseChatModelAnthropic = oe;
|
|
24
|
+
exports.BaseChatModelOptions = ae;
|
|
25
|
+
exports.Bedrock = $;
|
|
26
26
|
exports.BedrockClaude3Haiku20240307 = ne;
|
|
27
27
|
exports.BedrockClaude3Haiku20240307Literal = xe;
|
|
28
|
-
exports.BedrockClaude3Haiku20240307Options =
|
|
29
|
-
exports.BedrockClaude3Haiku20240307Schema =
|
|
28
|
+
exports.BedrockClaude3Haiku20240307Options = La;
|
|
29
|
+
exports.BedrockClaude3Haiku20240307Schema = Te;
|
|
30
30
|
//# sourceMappingURL=index.js.map
|
|
31
31
|
//# sourceMappingURL=index.js.map
|