@adaline/anthropic 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -355,11 +355,12 @@ declare const truncation: {
355
355
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNullable<zod.ZodBoolean>>>;
356
356
  };
357
357
 
358
- declare const AnthropicChatModelRoles: z.ZodEnum<["system", "user", "assistant"]>;
358
+ declare const AnthropicChatModelRoles: z.ZodEnum<["system", "user", "assistant", "tool"]>;
359
359
  declare const AnthropicChatModelRolesMap: {
360
360
  readonly system: "system";
361
361
  readonly user: "user";
362
362
  readonly assistant: "assistant";
363
+ readonly tool: "user";
363
364
  };
364
365
 
365
366
  declare const AnthropicChatModelModalities: ChatModelSchemaType["modalities"];
@@ -1936,7 +1937,7 @@ declare const Claude3Haiku20240307Literal = "claude-3-haiku-20240307";
1936
1937
  declare const Claude3Haiku20240307Schema: {
1937
1938
  description: string;
1938
1939
  name: string;
1939
- roles: Partial<Record<"system" | "user" | "assistant", string | undefined>>;
1940
+ roles: Partial<Record<"system" | "user" | "assistant" | "tool", string | undefined>>;
1940
1941
  modalities: ["text" | "image" | "tool-call" | "tool-response", ...("text" | "image" | "tool-call" | "tool-response")[]];
1941
1942
  maxInputTokens: number;
1942
1943
  maxOutputTokens: number;
@@ -2004,7 +2005,7 @@ declare const Claude3Sonnet20240229Literal = "claude-3-sonnet-20240229";
2004
2005
  declare const Claude3Sonnet20240229Schema: {
2005
2006
  description: string;
2006
2007
  name: string;
2007
- roles: Partial<Record<"system" | "user" | "assistant", string | undefined>>;
2008
+ roles: Partial<Record<"system" | "user" | "assistant" | "tool", string | undefined>>;
2008
2009
  modalities: ["text" | "image" | "tool-call" | "tool-response", ...("text" | "image" | "tool-call" | "tool-response")[]];
2009
2010
  maxInputTokens: number;
2010
2011
  maxOutputTokens: number;
@@ -2072,7 +2073,7 @@ declare const Claude3Opus20240229Literal = "claude-3-opus-20240229";
2072
2073
  declare const Claude3Opus20240229Schema: {
2073
2074
  description: string;
2074
2075
  name: string;
2075
- roles: Partial<Record<"system" | "user" | "assistant", string | undefined>>;
2076
+ roles: Partial<Record<"system" | "user" | "assistant" | "tool", string | undefined>>;
2076
2077
  modalities: ["text" | "image" | "tool-call" | "tool-response", ...("text" | "image" | "tool-call" | "tool-response")[]];
2077
2078
  maxInputTokens: number;
2078
2079
  maxOutputTokens: number;
@@ -2140,7 +2141,7 @@ declare const Claude3_5Sonnet20240620Literal = "claude-3-5-sonnet-20240620";
2140
2141
  declare const Claude3_5Sonnet20240620Schema: {
2141
2142
  description: string;
2142
2143
  name: string;
2143
- roles: Partial<Record<"system" | "user" | "assistant", string | undefined>>;
2144
+ roles: Partial<Record<"system" | "user" | "assistant" | "tool", string | undefined>>;
2144
2145
  modalities: ["text" | "image" | "tool-call" | "tool-response", ...("text" | "image" | "tool-call" | "tool-response")[]];
2145
2146
  maxInputTokens: number;
2146
2147
  maxOutputTokens: number;
package/dist/index.d.ts CHANGED
@@ -355,11 +355,12 @@ declare const truncation: {
355
355
  schema: zod.ZodOptional<zod.ZodDefault<zod.ZodNullable<zod.ZodBoolean>>>;
356
356
  };
357
357
 
358
- declare const AnthropicChatModelRoles: z.ZodEnum<["system", "user", "assistant"]>;
358
+ declare const AnthropicChatModelRoles: z.ZodEnum<["system", "user", "assistant", "tool"]>;
359
359
  declare const AnthropicChatModelRolesMap: {
360
360
  readonly system: "system";
361
361
  readonly user: "user";
362
362
  readonly assistant: "assistant";
363
+ readonly tool: "user";
363
364
  };
364
365
 
365
366
  declare const AnthropicChatModelModalities: ChatModelSchemaType["modalities"];
@@ -1936,7 +1937,7 @@ declare const Claude3Haiku20240307Literal = "claude-3-haiku-20240307";
1936
1937
  declare const Claude3Haiku20240307Schema: {
1937
1938
  description: string;
1938
1939
  name: string;
1939
- roles: Partial<Record<"system" | "user" | "assistant", string | undefined>>;
1940
+ roles: Partial<Record<"system" | "user" | "assistant" | "tool", string | undefined>>;
1940
1941
  modalities: ["text" | "image" | "tool-call" | "tool-response", ...("text" | "image" | "tool-call" | "tool-response")[]];
1941
1942
  maxInputTokens: number;
1942
1943
  maxOutputTokens: number;
@@ -2004,7 +2005,7 @@ declare const Claude3Sonnet20240229Literal = "claude-3-sonnet-20240229";
2004
2005
  declare const Claude3Sonnet20240229Schema: {
2005
2006
  description: string;
2006
2007
  name: string;
2007
- roles: Partial<Record<"system" | "user" | "assistant", string | undefined>>;
2008
+ roles: Partial<Record<"system" | "user" | "assistant" | "tool", string | undefined>>;
2008
2009
  modalities: ["text" | "image" | "tool-call" | "tool-response", ...("text" | "image" | "tool-call" | "tool-response")[]];
2009
2010
  maxInputTokens: number;
2010
2011
  maxOutputTokens: number;
@@ -2072,7 +2073,7 @@ declare const Claude3Opus20240229Literal = "claude-3-opus-20240229";
2072
2073
  declare const Claude3Opus20240229Schema: {
2073
2074
  description: string;
2074
2075
  name: string;
2075
- roles: Partial<Record<"system" | "user" | "assistant", string | undefined>>;
2076
+ roles: Partial<Record<"system" | "user" | "assistant" | "tool", string | undefined>>;
2076
2077
  modalities: ["text" | "image" | "tool-call" | "tool-response", ...("text" | "image" | "tool-call" | "tool-response")[]];
2077
2078
  maxInputTokens: number;
2078
2079
  maxOutputTokens: number;
@@ -2140,7 +2141,7 @@ declare const Claude3_5Sonnet20240620Literal = "claude-3-5-sonnet-20240620";
2140
2141
  declare const Claude3_5Sonnet20240620Schema: {
2141
2142
  description: string;
2142
2143
  name: string;
2143
- roles: Partial<Record<"system" | "user" | "assistant", string | undefined>>;
2144
+ roles: Partial<Record<"system" | "user" | "assistant" | "tool", string | undefined>>;
2144
2145
  modalities: ["text" | "image" | "tool-call" | "tool-response", ...("text" | "image" | "tool-call" | "tool-response")[]];
2145
2146
  maxInputTokens: number;
2146
2147
  maxOutputTokens: number;
package/dist/index.js CHANGED
@@ -2,18 +2,18 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
- var Ao=Object.defineProperty,wo=Object.defineProperties;var ko=Object.getOwnPropertyDescriptors;var ut=Object.getOwnPropertySymbols;var _o=Object.prototype.hasOwnProperty,qo=Object.prototype.propertyIsEnumerable;var jo=(a,t)=>(t=Symbol[a])?t:Symbol.for("Symbol."+a);var gt=(a,t,o)=>t in a?Ao(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o,f=(a,t)=>{for(var o in t||(t={}))_o.call(t,o)&&gt(a,o,t[o]);if(ut)for(var o of ut(t))qo.call(t,o)&&gt(a,o,t[o]);return a},be=(a,t)=>wo(a,ko(t));var j=(a,t,o)=>new Promise((n,l)=>{var m=d=>{try{i(o.next(d));}catch(u){l(u);}},s=d=>{try{i(o.throw(d));}catch(u){l(u);}},i=d=>d.done?n(d.value):Promise.resolve(d.value).then(m,s);i((o=o.apply(a,t)).next());}),Io=function(a,t){this[0]=a,this[1]=t;},ht=(a,t,o)=>{var n=(s,i,d,u)=>{try{var g=o[s](i),R=(i=g.value)instanceof Io,v=g.done;Promise.resolve(R?i[0]:i).then(S=>R?n(s==="return"?s:"next",i[1]?{done:S.done,value:S.value}:S,d,u):d({value:S,done:v})).catch(S=>n("throw",S,d,u));}catch(S){u(S);}},l=s=>m[s]=i=>new Promise((d,u)=>n(s,i,d,u)),m={};return o=o.apply(a,t),m[jo("asyncIterator")]=()=>m,l("next"),l("throw"),l("return"),m};var Po=a=>{let t=new WeakSet;return JSON.stringify(a,(o,n)=>{if(typeof n=="object"&&n!==null){if(t.has(n))return;t.add(n);}return n})},Lo=a=>a==null?"unknown error":typeof a=="string"?a:a instanceof Error?a.message:Po(a),Te="GatewayBaseError",V=class Tt extends Error{constructor({info:t,cause:o},n){super(`[${n!=null?n:Te}]: ${t}
6
- Message: ${Lo(o)}`),this.name=Te,this.info=t,this.cause=o,this.name=n!=null?n:Te,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof Tt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Z="system",L="user",C="assistant",Bo="tool",No=[Z,L,C,Bo],Ce=zod.z.enum(No),Vo=[C],Uo=zod.z.enum(Vo),U="image",Me="base64",$o=["png","jpeg","webp","gif"],zo=zod.z.object({type:zod.z.literal(Me),base64:zod.z.string(),media_type:zod.z.enum($o)}),Fo="url",Do=zod.z.object({type:zod.z.literal(Fo),url:zod.z.string()}),Ho=zod.z.discriminatedUnion("type",[zo,Do]),Ko=["low","medium","high","auto"],Go=zod.z.enum(Ko),Jo=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(U),detail:Go,value:Ho,metadata:a}),b="text",Ct=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(b),value:zod.z.string(),metadata:a}),Ee="partial-text",Mt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ee),value:zod.z.string(),metadata:a}),_="tool-call",Et=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:a}),Re="partial-tool-call",Rt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Re),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:a}),$="tool-response",Wo=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal($),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:a}),Zo=[b,U,_,$],vt=zod.z.enum(Zo),Yo=(a=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ct(a),Jo(t),Et(o),Wo(n)]),Qo=[Ee,Re];zod.z.enum(Qo);var Xo=(a=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Mt(a),Rt(t)]);var ve=(a=Ce,t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined(),l=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:a,content:zod.z.array(Yo(t,o,n,l)),metadata:m}),Se=(a=Uo,t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.object({role:a,partialContent:Xo(t,o),metadata:n}),St=a=>Ct().parse({modality:b,value:a}),xt=(a,t,o,n)=>Et().parse({modality:_,index:a,id:t,name:o,arguments:n});var xe=(a,t)=>Se().parse({role:a,partialContent:Mt().parse({modality:Ee,value:t})}),Oe=(a,t,o,n,l)=>Se().parse({role:a,partialContent:Rt().parse({modality:Re,index:t,id:o,name:n,arguments:l})});var ne=(a=zod.z.record(zod.z.string(),zod.z.any()).optional())=>a,en=["object","array","number","string","boolean","enum"],yt=zod.z.enum(en),tn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([yt,zod.z.array(zod.z.union([yt,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()}),on=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(tn),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:on}).optional();var nn="function";var an=zod.z.enum(["object","array","number","string","boolean","null"]),sn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:an.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 rn=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 ln=zod.z.enum(["function"]),dn=zod.z.object({type:ln,definition:zod.z.object({schema:rn})}),mn=[nn];zod.z.enum(mn);var Ot=(a=zod.z.undefined())=>zod.z.discriminatedUnion("type",[dn.extend({metadata:a})]),z="text",At="token",pn=[z,At],wt=zod.z.enum(pn),cn=zod.z.array(zod.z.string().min(1)),un=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),kt=(a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(z),metadata:a,requests:cn}),zod.z.object({modality:zod.z.literal(At),metadata:a,requests:un})]),Ae="float",gn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),we="base64",hn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),ft=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Ae),embeddings:zod.z.array(gn),usage:ft.optional()}),zod.z.object({encodingFormat:zod.z.literal(we),embeddings:zod.z.array(hn),usage:ft.optional()})]);var _t=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),bt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),yn=bt.extend({topLogProbs:zod.z.array(bt)}),qt=zod.z.array(yn);zod.z.object({messages:zod.z.array(ve()),usage:_t.optional(),logProbs:qt.optional()});zod.z.object({partialMessages:zod.z.array(Se()),usage:_t.optional(),logProbs:qt.optional()});var fn=Object.defineProperty,jt=Object.getOwnPropertySymbols,bn=Object.prototype.hasOwnProperty,Tn=Object.prototype.propertyIsEnumerable,It=(a,t,o)=>t in a?fn(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o,ae=(a,t)=>{for(var o in t||(t={}))bn.call(t,o)&&It(a,o,t[o]);if(jt)for(var o of jt(t))Tn.call(t,o)&&It(a,o,t[o]);return a},Pt="ProviderError",ke=class zt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Pt),this.name=Pt,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof zt}};var Lt="ModelResponseError",I=class Ft extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Lt),this.name=Lt,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof Ft}},Bt="InvalidModelRequestError",Q=class Dt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Bt),this.name=Bt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Dt}},Nt="InvalidConfigError",B=class Ht extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Nt),this.name=Nt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Ht}},Vt="InvalidMessagesError",M=class Kt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Vt),this.name=Vt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof Kt}},Ut="InvalidToolsError",_e=class Gt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Ut),this.name=Ut,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof Gt}},$t="InvalidEmbeddingRequestsError",qe=class Jt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},$t),this.name=$t,this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Jt}},je="multi-string",Wt=zod.z.object({type:zod.z.literal(je),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),Cn=a=>zod.z.array(zod.z.string()).max(a).default([]).optional(),Zt=a=>({def:Wt.parse(ae({type:je},a)),schema:Cn(a.max)}),Yt="object-schema",Mn=zod.z.object({type:zod.z.literal(Yt),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var Ie="range",Qt=zod.z.object({type:zod.z.literal(Ie),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),En=(a,t,o,n)=>zod.z.number().min(a).max(t).step(o).default(n).optional(),X=a=>({def:Qt.parse(ae({type:Ie},a)),schema:En(a.min,a.max,a.step,a.default)}),Pe="select-boolean",Xt=zod.z.object({type:zod.z.literal(Pe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),Rn=a=>zod.z.boolean().nullable().default(a).optional(),eo=a=>({def:Xt.parse(ae({type:Pe},a)),schema:Rn(a.default)}),Le="select-string",to=zod.z.object({type:zod.z.literal(Le),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))}),vn=(a,t)=>zod.z.enum(t).nullable().default(a).optional(),ee=a=>({def:to.parse(ae({type:Le},a)),schema:vn(a.default,a.choices)}),Sn=[Ie,je,Le,Yt,Pe];zod.z.enum(Sn);var oo=zod.z.discriminatedUnion("type",[Qt,Wt,to,Xt,Mn]),F=(a=Ce,t=vt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(a,zod.z.string().min(1).optional()),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),oo),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var n,l;let m=Object.keys(o.def),s=Object.keys((l=(n=o.schema)==null?void 0:n.shape)!=null?l:{});return m.every(i=>s.includes(i))&&s.every(i=>m.includes(i))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),x=(a=wt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),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),oo),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var o,n;let l=Object.keys(t.def),m=Object.keys((n=(o=t.schema)==null?void 0:o.shape)!=null?n:{});return l.every(s=>m.includes(s))&&m.every(s=>l.includes(s))},{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 xn={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."},On={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."},An=a=>({type:"multi",title:"Stop sequence",description:`Enter up to ${a} sequences that will halt additional text output. The generated text will exclude these sequences.`}),wn={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."},kn={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."},_n={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."},qn={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."},jn={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."},In={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."},Pn={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."},Ln={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."},Bn={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."},Nn={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."},Vn={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Un={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."},$n={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},zn={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},q={TEMPERATURE:xn,MAX_TOKENS:On,STOP:An,TOP_A:wn,TOP_P:kn,TOP_K:_n,MIN_P:qn,FREQUENCY_PENALTY:jn,PRESENCE_PENALTY:In,REPETITION_PENALTY:Ln,SEED:Pn,LOG_PROBS:Bn,TOP_LOG_PROBS:Nn,ECHO:Vn,RESPONSE_FORMAT:Un,RESPONSE_FORMAT_WITH_SCHEMA:$n,RESPONSE_SCHEMA:zn};var se=a=>Object.fromEntries(Object.entries(a).filter(([t,o])=>o!=null));var Y=a=>a==null?void 0:a.replace(/\/$/,"");var Be=X({param:"temperature",title:q.TEMPERATURE.title,description:q.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),Ne=a=>X({param:"max_tokens",title:q.MAX_TOKENS.title,description:q.MAX_TOKENS.description,min:0,max:a,step:1,default:0}),Ve=a=>Zt({param:"stop_sequences",title:q.STOP(a).title,description:q.STOP(a).description,max:a}),Ue=X({param:"top_p",title:q.TOP_P.title,description:q.TOP_P.description,min:0,max:1,step:.01,default:1}),$e=X({param:"top_k",title:q.TOP_K.title,description:q.TOP_K.description,min:0,max:1,step:.01,default:1}),ze=ee({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"]});var no=(a,t)=>zod.z.object({temperature:Be.schema,maxTokens:Ne(a).schema,stop:Ve(t).schema,topP:Ue.schema,topK:$e.schema,toolChoice:ze.schema}),ao=(a,t)=>({temperature:Be.def,maxTokens:Ne(a).def,stop:Ve(t).def,topP:Ue.def,topK:$e.def,toolChoice:ze.def});var Fe=ee({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:null,choices:["base64"]}),De=ee({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:null,choices:["query","document"]}),He=eo({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0});var so=()=>zod.z.object({encodingFormat:Fe.schema,inputType:De.schema,truncation:He.schema}),io=()=>({encodingFormat:Fe.def,inputType:De.def,truncation:He.def});var O={base:(a,t)=>({def:ao(a,t),schema:no(a,t)})},y={base:()=>({def:io(),schema:so()})};var D=zod.z.enum([Z,L,C]),H={system:Z,user:L,assistant:C};var K=[b,U,_,$],G=zod.z.enum([b,U,_,$]);var Gn=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),Jn=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),ro=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[Gn,Jn])),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()})}),lo=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()})})}),mo=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()})}),Wn=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),Zn=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),po=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[Wn,Zn])}),Yn=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),Qn=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),co=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[Yn,Qn])});var Xn=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),ea=zod.z.object({type:zod.z.enum(["auto","any"])}),ta=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")}),uo=zod.z.object({type:zod.z.literal("image"),source:zod.z.object({type:zod.z.literal("base64"),media_type:zod.z.enum(["image/jpeg","image/png","image/gif","image/webp"]),data:zod.z.string().base64()})}),ns=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())}),go=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,uo])).min(1))}),oa=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ke,uo,go])).min(1))}),na=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ke,go])).min(1))}),aa=zod.z.union([oa,na]),ho=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(aa).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([ea,ta]).optional(),tools:zod.z.array(Xn).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()});var sa="anthropic",J=class{constructor(){this.version="v1";this.name=sa;this.chatModelFactories={[Ge]:{model:ie,modelOptions:yo,modelSchema:Je},[We]:{model:re,modelOptions:fo,modelSchema:Ze},[Ye]:{model:le,modelOptions:bo,modelSchema:Qe},[Xe]:{model:de,modelOptions:To,modelSchema:et}};this.embeddingModelFactories={[pt]:{model:he,modelOptions:So,modelSchema:ct},[dt]:{model:ge,modelOptions:vo,modelSchema:mt},[tt]:{model:me,modelOptions:Co,modelSchema:ot},[nt]:{model:pe,modelOptions:Mo,modelSchema:at},[st]:{model:ce,modelOptions:Eo,modelSchema:it},[rt]:{model:ue,modelOptions:Ro,modelSchema:lt}};}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 ke({info:`Anthropic chat model: ${o} not found`,cause:new Error(`Anthropic chat model: ${o} not found, available chat models:
7
- ${this.chatModelLiterals().join(", ")}`)});let n=this.chatModelFactories[o].model,l=this.chatModelFactories[o].modelOptions.parse(t);return new n(l)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,o)=>(t[o]=this.embeddingModelFactories[o].modelSchema,t),{})}embeddingModel(t){let o=t.modelName;if(!(o in this.embeddingModelFactories))throw new ke({info:`Anthropic embedding model: ${o} not found`,cause:new Error(`Anthropic embedding model: ${o} not found, available embedding models:
8
- ${this.embeddingModelLiterals().join(", ")}`)});let n=this.embeddingModelFactories[o].model,l=this.embeddingModelFactories[o].modelOptions.parse(t);return new n(l)}};J.chatBaseUrl="https://api.anthropic.com/v1",J.embeddingBaseUrl="https://api.anthropic.com/v1";var N=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),P=class{constructor(t,o){this.version="v1";let n=N.parse(o);this.modelSchema=t,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Y(J.chatBaseUrl),this.completeChatUrl=Y(n.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=Y(n.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 o=0,n=!0;return t["x-should-retry"]&&(n=t["x-should-retry"].toLowerCase()!=="false"),t["retry-after"]&&(o=parseInt(t["retry-after"])*1e3),{shouldRetry:n,delayMs:o}}getTokenCount(t){return t.reduce((o,n)=>o+n.content.map(l=>l.modality==="text"?l.value:"").join(" ").length,0)}transformModelRequest(t){let o=ho.safeParse(t);if(!o.success)throw new Q({info:"Invalid model request",cause:o.error});let n=o.data,l=n.model;if(n.tool_choice&&(!n.tools||n.tools.length===0))throw new Q({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let m={};n.tool_choice&&(n.tool_choice.type==="tool"?m.toolChoice=n.tool_choice.name:m.toolChoice=n.tool_choice.type),m.maxTokens=n.max_tokens,m.temperature=n.temperature,m.topP=n.top_p,m.topK=n.top_k,m.stop=n.stop_sequences;let s=ne().parse(se(m)),i=[],d={};n.system&&i.push({role:Z,content:[{modality:b,value:n.system}]}),n.messages.forEach(g=>{let R=g.role;switch(R){case"user":{let v=g.content;if(typeof v=="string")i.push({role:R,content:[{modality:b,value:v}]});else {let S=v.map(h=>{if(h.type==="text")return {modality:b,value:h.text};if(h.type==="image"){let fe="auto",oe=h.source.media_type.split("/")[1];return {modality:U,detail:fe,value:{type:Me,media_type:oe,base64:h.source.data}}}else return {modality:$,id:h.tool_use_id,index:d[h.tool_use_id].index,name:d[h.tool_use_id].name,data:typeof h.content=="string"?h.content:JSON.stringify(h.content)}});i.push({role:R,content:S});}}break;case"assistant":{let v=g.content;if(typeof v=="string")i.push({role:R,content:[{modality:b,value:v}]});else {let S=v.map((h,fe)=>{if(h.type==="text")return {modality:b,value:h.text};{let oe={modality:_,id:h.id,index:fe,name:h.name,arguments:JSON.stringify(h.input)};return d[h.id]=oe,oe}});i.push({role:R,content:S});}}break}});let u=[];return n.tools&&n.tools.forEach(g=>{u.push({type:"function",definition:{schema:{name:g.name,description:g.description||"",parameters:g.input_schema}}});}),{modelName:l,config:s,messages:i,tools:u.length>0?u:void 0}}transformConfig(t,o,n){let l=t.toolChoice;delete t.toolChoice;let m=this.modelSchema.config.schema.safeParse(t);if(!m.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:m.error});let s=m.data;l!==void 0&&(s.toolChoice=l),Object.keys(s).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
5
+ var wo=Object.defineProperty,ko=Object.defineProperties;var _o=Object.getOwnPropertyDescriptors;var gt=Object.getOwnPropertySymbols;var qo=Object.prototype.hasOwnProperty,jo=Object.prototype.propertyIsEnumerable;var Io=(a,t)=>(t=Symbol[a])?t:Symbol.for("Symbol."+a);var ht=(a,t,o)=>t in a?wo(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o,f=(a,t)=>{for(var o in t||(t={}))qo.call(t,o)&&ht(a,o,t[o]);if(gt)for(var o of gt(t))jo.call(t,o)&&ht(a,o,t[o]);return a},Te=(a,t)=>ko(a,_o(t));var j=(a,t,o)=>new Promise((n,l)=>{var m=d=>{try{i(o.next(d));}catch(u){l(u);}},s=d=>{try{i(o.throw(d));}catch(u){l(u);}},i=d=>d.done?n(d.value):Promise.resolve(d.value).then(m,s);i((o=o.apply(a,t)).next());}),Po=function(a,t){this[0]=a,this[1]=t;},yt=(a,t,o)=>{var n=(s,i,d,u)=>{try{var g=o[s](i),R=(i=g.value)instanceof Po,v=g.done;Promise.resolve(R?i[0]:i).then(S=>R?n(s==="return"?s:"next",i[1]?{done:S.done,value:S.value}:S,d,u):d({value:S,done:v})).catch(S=>n("throw",S,d,u));}catch(S){u(S);}},l=s=>m[s]=i=>new Promise((d,u)=>n(s,i,d,u)),m={};return o=o.apply(a,t),m[Io("asyncIterator")]=()=>m,l("next"),l("throw"),l("return"),m};var Lo=a=>{let t=new WeakSet;return JSON.stringify(a,(o,n)=>{if(typeof n=="object"&&n!==null){if(t.has(n))return;t.add(n);}return n})},Bo=a=>a==null?"unknown error":typeof a=="string"?a:a instanceof Error?a.message:Lo(a),Ce="GatewayBaseError",V=class Ct extends Error{constructor({info:t,cause:o},n){super(`[${n!=null?n:Ce}]: ${t}
6
+ Message: ${Bo(o)}`),this.name=Ce,this.info=t,this.cause=o,this.name=n!=null?n:Ce,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof Ct}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Z="system",I="user",M="assistant",Q="tool",No=[Z,I,M,Q],Me=zod.z.enum(No),Vo=[M],Uo=zod.z.enum(Vo),U="image",Ee="base64",$o=["png","jpeg","webp","gif"],zo=zod.z.object({type:zod.z.literal(Ee),base64:zod.z.string(),media_type:zod.z.enum($o)}),Fo="url",Do=zod.z.object({type:zod.z.literal(Fo),url:zod.z.string()}),Ho=zod.z.discriminatedUnion("type",[zo,Do]),Ko=["low","medium","high","auto"],Go=zod.z.enum(Ko),Jo=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(U),detail:Go,value:Ho,metadata:a}),b="text",Mt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(b),value:zod.z.string(),metadata:a}),Re="partial-text",Et=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Re),value:zod.z.string(),metadata:a}),_="tool-call",Rt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:a}),ve="partial-tool-call",vt=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ve),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:a}),$="tool-response",Wo=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal($),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:a}),Zo=[b,U,_,$],St=zod.z.enum(Zo),Yo=(a=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Mt(a),Jo(t),Rt(o),Wo(n)]),Qo=[Re,ve];zod.z.enum(Qo);var Xo=(a=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Et(a),vt(t)]);var Se=(a=Me,t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined(),l=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:a,content:zod.z.array(Yo(t,o,n,l)),metadata:m}),xe=(a=Uo,t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.object({role:a,partialContent:Xo(t,o),metadata:n}),xt=a=>Mt().parse({modality:b,value:a}),Ot=(a,t,o,n)=>Rt().parse({modality:_,index:a,id:t,name:o,arguments:n});var Oe=(a,t)=>xe().parse({role:a,partialContent:Et().parse({modality:Re,value:t})}),Ae=(a,t,o,n,l)=>xe().parse({role:a,partialContent:vt().parse({modality:ve,index:t,id:o,name:n,arguments:l})});var ae=(a=zod.z.record(zod.z.string(),zod.z.any()).optional())=>a,en=["object","array","number","string","boolean","enum"],ft=zod.z.enum(en),tn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([ft,zod.z.array(zod.z.union([ft,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()}),on=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(tn),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:on}).optional();var nn="function";var an=zod.z.enum(["object","array","number","string","boolean","null"]),sn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:an.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 rn=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 ln=zod.z.enum(["function"]),dn=zod.z.object({type:ln,definition:zod.z.object({schema:rn})}),mn=[nn];zod.z.enum(mn);var At=(a=zod.z.undefined())=>zod.z.discriminatedUnion("type",[dn.extend({metadata:a})]),z="text",wt="token",pn=[z,wt],kt=zod.z.enum(pn),cn=zod.z.array(zod.z.string().min(1)),un=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),_t=(a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(z),metadata:a,requests:cn}),zod.z.object({modality:zod.z.literal(wt),metadata:a,requests:un})]),we="float",gn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),ke="base64",hn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),bt=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(we),embeddings:zod.z.array(gn),usage:bt.optional()}),zod.z.object({encodingFormat:zod.z.literal(ke),embeddings:zod.z.array(hn),usage:bt.optional()})]);var qt=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Tt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),yn=Tt.extend({topLogProbs:zod.z.array(Tt)}),jt=zod.z.array(yn);zod.z.object({messages:zod.z.array(Se()),usage:qt.optional(),logProbs:jt.optional()});zod.z.object({partialMessages:zod.z.array(xe()),usage:qt.optional(),logProbs:jt.optional()});var fn=Object.defineProperty,It=Object.getOwnPropertySymbols,bn=Object.prototype.hasOwnProperty,Tn=Object.prototype.propertyIsEnumerable,Pt=(a,t,o)=>t in a?fn(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o,se=(a,t)=>{for(var o in t||(t={}))bn.call(t,o)&&Pt(a,o,t[o]);if(It)for(var o of It(t))Tn.call(t,o)&&Pt(a,o,t[o]);return a},Lt="ProviderError",_e=class Ft extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Lt),this.name=Lt,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof Ft}};var Bt="ModelResponseError",P=class Dt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Bt),this.name=Bt,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof Dt}},Nt="InvalidModelRequestError",X=class Ht extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Nt),this.name=Nt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof Ht}},Vt="InvalidConfigError",B=class Kt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Vt),this.name=Vt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Kt}},Ut="InvalidMessagesError",T=class Gt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},Ut),this.name=Ut,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof Gt}},$t="InvalidToolsError",qe=class Jt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},$t),this.name=$t,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof Jt}},zt="InvalidEmbeddingRequestsError",je=class Wt extends V{constructor({info:t,cause:o}){super({info:t,cause:o},zt),this.name=zt,this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Wt}},Ie="multi-string",Zt=zod.z.object({type:zod.z.literal(Ie),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()}),Cn=a=>zod.z.array(zod.z.string()).max(a).default([]).optional(),Yt=a=>({def:Zt.parse(se({type:Ie},a)),schema:Cn(a.max)}),Qt="object-schema",Mn=zod.z.object({type:zod.z.literal(Qt),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 Pe="range",Xt=zod.z.object({type:zod.z.literal(Pe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),En=(a,t,o,n)=>zod.z.number().min(a).max(t).step(o).default(n).optional(),ee=a=>({def:Xt.parse(se({type:Pe},a)),schema:En(a.min,a.max,a.step,a.default)}),Le="select-boolean",eo=zod.z.object({type:zod.z.literal(Le),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()}),Rn=a=>zod.z.boolean().nullable().default(a).optional(),to=a=>({def:eo.parse(se({type:Le},a)),schema:Rn(a.default)}),Be="select-string",oo=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),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))}),vn=(a,t)=>zod.z.enum(t).nullable().default(a).optional(),te=a=>({def:oo.parse(se({type:Be},a)),schema:vn(a.default,a.choices)}),Sn=[Pe,Ie,Be,Qt,Le];zod.z.enum(Sn);var no=zod.z.discriminatedUnion("type",[Xt,Zt,oo,eo,Mn]),F=(a=Me,t=St)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(a,zod.z.string().min(1).optional()),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),no),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var n,l;let m=Object.keys(o.def),s=Object.keys((l=(n=o.schema)==null?void 0:n.shape)!=null?l:{});return m.every(i=>s.includes(i))&&s.every(i=>m.includes(i))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),x=(a=kt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),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),no),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var o,n;let l=Object.keys(t.def),m=Object.keys((n=(o=t.schema)==null?void 0:o.shape)!=null?n:{});return l.every(s=>m.includes(s))&&m.every(s=>l.includes(s))},{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 xn={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."},On={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."},An=a=>({type:"multi",title:"Stop sequence",description:`Enter up to ${a} sequences that will halt additional text output. The generated text will exclude these sequences.`}),wn={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."},kn={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."},_n={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."},qn={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."},jn={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."},In={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."},Pn={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."},Ln={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."},Bn={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."},Nn={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."},Vn={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Un={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."},$n={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},zn={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},q={TEMPERATURE:xn,MAX_TOKENS:On,STOP:An,TOP_A:wn,TOP_P:kn,TOP_K:_n,MIN_P:qn,FREQUENCY_PENALTY:jn,PRESENCE_PENALTY:In,REPETITION_PENALTY:Ln,SEED:Pn,LOG_PROBS:Bn,TOP_LOG_PROBS:Nn,ECHO:Vn,RESPONSE_FORMAT:Un,RESPONSE_FORMAT_WITH_SCHEMA:$n,RESPONSE_SCHEMA:zn};var ie=a=>Object.fromEntries(Object.entries(a).filter(([t,o])=>o!=null));var Y=a=>a==null?void 0:a.replace(/\/$/,"");var Ne=ee({param:"temperature",title:q.TEMPERATURE.title,description:q.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),Ve=a=>ee({param:"max_tokens",title:q.MAX_TOKENS.title,description:q.MAX_TOKENS.description,min:0,max:a,step:1,default:0}),Ue=a=>Yt({param:"stop_sequences",title:q.STOP(a).title,description:q.STOP(a).description,max:a}),$e=ee({param:"top_p",title:q.TOP_P.title,description:q.TOP_P.description,min:0,max:1,step:.01,default:1}),ze=ee({param:"top_k",title:q.TOP_K.title,description:q.TOP_K.description,min:0,max:1,step:.01,default:1}),Fe=te({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"]});var ao=(a,t)=>zod.z.object({temperature:Ne.schema,maxTokens:Ve(a).schema,stop:Ue(t).schema,topP:$e.schema,topK:ze.schema,toolChoice:Fe.schema}),so=(a,t)=>({temperature:Ne.def,maxTokens:Ve(a).def,stop:Ue(t).def,topP:$e.def,topK:ze.def,toolChoice:Fe.def});var De=te({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:null,choices:["base64"]}),He=te({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:null,choices:["query","document"]}),Ke=to({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0});var io=()=>zod.z.object({encodingFormat:De.schema,inputType:He.schema,truncation:Ke.schema}),ro=()=>({encodingFormat:De.def,inputType:He.def,truncation:Ke.def});var O={base:(a,t)=>({def:so(a,t),schema:ao(a,t)})},y={base:()=>({def:ro(),schema:io()})};var D=zod.z.enum([Z,I,M,Q]),H={system:Z,user:I,assistant:M,tool:I};var K=[b,U,_,$],G=zod.z.enum([b,U,_,$]);var Gn=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),Jn=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),lo=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[Gn,Jn])),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()})}),mo=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()})})}),po=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()})}),Wn=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),Zn=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),co=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[Wn,Zn])}),Yn=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),Qn=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),uo=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[Yn,Qn])});var Xn=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),ea=zod.z.object({type:zod.z.enum(["auto","any"])}),ta=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),Ge=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),go=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()})}),ns=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())}),ho=zod.z.object({type:zod.z.literal("tool_result"),tool_use_id:zod.z.string().min(1),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ge,go])).min(1))}),oa=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ge,go,ho])).min(1))}),na=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ge,ho])).min(1))}),aa=zod.z.union([oa,na]),yo=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(aa).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([ea,ta]).optional(),tools:zod.z.array(Xn).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()});var sa="anthropic",J=class{constructor(){this.version="v1";this.name=sa;this.chatModelFactories={[Je]:{model:re,modelOptions:fo,modelSchema:We},[Ze]:{model:le,modelOptions:bo,modelSchema:Ye},[Qe]:{model:de,modelOptions:To,modelSchema:Xe},[et]:{model:me,modelOptions:Co,modelSchema:tt}};this.embeddingModelFactories={[ct]:{model:ye,modelOptions:xo,modelSchema:ut},[mt]:{model:he,modelOptions:So,modelSchema:pt},[ot]:{model:pe,modelOptions:Mo,modelSchema:nt},[at]:{model:ce,modelOptions:Eo,modelSchema:st},[it]:{model:ue,modelOptions:Ro,modelSchema:rt},[lt]:{model:ge,modelOptions:vo,modelSchema:dt}};}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 _e({info:`Anthropic chat model: ${o} not found`,cause:new Error(`Anthropic chat model: ${o} not found, available chat models:
7
+ ${this.chatModelLiterals().join(", ")}`)});let n=this.chatModelFactories[o].model,l=this.chatModelFactories[o].modelOptions.parse(t);return new n(l)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,o)=>(t[o]=this.embeddingModelFactories[o].modelSchema,t),{})}embeddingModel(t){let o=t.modelName;if(!(o in this.embeddingModelFactories))throw new _e({info:`Anthropic embedding model: ${o} not found`,cause:new Error(`Anthropic embedding model: ${o} not found, available embedding models:
8
+ ${this.embeddingModelLiterals().join(", ")}`)});let n=this.embeddingModelFactories[o].model,l=this.embeddingModelFactories[o].modelOptions.parse(t);return new n(l)}};J.chatBaseUrl="https://api.anthropic.com/v1",J.embeddingBaseUrl="https://api.anthropic.com/v1";var N=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),L=class{constructor(t,o){this.version="v1";let n=N.parse(o);this.modelSchema=t,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Y(J.chatBaseUrl),this.completeChatUrl=Y(n.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=Y(n.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 o=0,n=!0;return t["x-should-retry"]&&(n=t["x-should-retry"].toLowerCase()!=="false"),t["retry-after"]&&(o=parseInt(t["retry-after"])*1e3),{shouldRetry:n,delayMs:o}}getTokenCount(t){return t.reduce((o,n)=>o+n.content.map(l=>l.modality==="text"?l.value:"").join(" ").length,0)}transformModelRequest(t){let o=yo.safeParse(t);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let n=o.data,l=n.model;if(n.tool_choice&&(!n.tools||n.tools.length===0))throw new X({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let m={};n.tool_choice&&(n.tool_choice.type==="tool"?m.toolChoice=n.tool_choice.name:m.toolChoice=n.tool_choice.type),m.maxTokens=n.max_tokens,m.temperature=n.temperature,m.topP=n.top_p,m.topK=n.top_k,m.stop=n.stop_sequences;let s=ae().parse(ie(m)),i=[],d={};n.system&&i.push({role:Z,content:[{modality:b,value:n.system}]}),n.messages.forEach(g=>{let R=g.role;switch(R){case"user":{let v=g.content;if(typeof v=="string")i.push({role:R,content:[{modality:b,value:v}]});else {let S=v.map(h=>{if(h.type==="text")return {modality:b,value:h.text};if(h.type==="image"){let be="auto",ne=h.source.media_type.split("/")[1];return {modality:U,detail:be,value:{type:Ee,media_type:ne,base64:h.source.data}}}else return {modality:$,id:h.tool_use_id,index:d[h.tool_use_id].index,name:d[h.tool_use_id].name,data:typeof h.content=="string"?h.content:JSON.stringify(h.content)}});i.push({role:R,content:S});}}break;case"assistant":{let v=g.content;if(typeof v=="string")i.push({role:R,content:[{modality:b,value:v}]});else {let S=v.map((h,be)=>{if(h.type==="text")return {modality:b,value:h.text};{let ne={modality:_,id:h.id,index:be,name:h.name,arguments:JSON.stringify(h.input)};return d[h.id]=ne,ne}});i.push({role:R,content:S});}}break}});let u=[];return n.tools&&n.tools.forEach(g=>{u.push({type:"function",definition:{schema:{name:g.name,description:g.description||"",parameters:g.input_schema}}});}),{modelName:l,config:s,messages:i,tools:u.length>0?u:void 0}}transformConfig(t,o,n){let l=t.toolChoice;delete t.toolChoice;let m=this.modelSchema.config.schema.safeParse(t);if(!m.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:m.error});let s=m.data;l!==void 0&&(s.toolChoice=l),Object.keys(s).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
9
9
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let i=Object.keys(s).reduce((d,u)=>{let g=this.modelSchema.config.def[u],R=g.param,v=s[u];return R==="max_tokens"&&g.type==="range"&&v===0?d[R]=g.max:d[R]=v,d},{});if(!i.max_tokens)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`'max_tokens' is required for model : '${this.modelName}'`)});if("tool_choice"in i&&i.tool_choice!==void 0){let d=i.tool_choice;if(!n||n&&n.length===0)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(n&&n.length>0){let u=this.modelSchema.config.def.toolChoice;if(u.choices.includes(d))i.tool_choice={type:d};else if(n.map(g=>g.definition.schema.name).includes(d))i.tool_choice={type:"tool",name:d};else throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
10
- one of [${u.choices.join(", ")}]`)})}}return i}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let o=t.map(s=>{let i=ve().safeParse(s);if(!i.success)throw new M({info:"Invalid messages",cause:i.error});return i.data});o.forEach(s=>{s.content.forEach(i=>{if(!this.modelSchema.modalities.includes(i.modality))throw new M({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${i.modality}',
11
- available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new M({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
12
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let n="",l=[];if(o.forEach(s=>{switch(s.role){case Z:s.content.forEach(i=>{if(i.modality===b)n+=i.value;else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${i.modality}'`)})});break;case C:{let i=[];s.content.forEach(d=>{if(d.modality===b)i.push({type:"text",text:d.value});else if(d.modality===_)i.push({type:"tool_use",id:d.id,name:d.name,input:JSON.parse(d.arguments)});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),l.push({role:this.modelSchema.roles[s.role],content:i});}break;case L:{let i=[];s.content.forEach(d=>{if(d.modality===b)i.push({type:"text",text:d.value});else if(d.modality===U){if(d.value.type==="base64")i.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 M({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${d.value.type}'`)})}else if(d.modality===$)i.push({type:"tool_result",tool_use_id:d.id,content:d.data});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),l.push({role:this.modelSchema.roles[s.role],content:i});}break;default:throw new M({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
13
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),l[0].role!==this.modelSchema.roles[L])throw new M({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=s=>s===this.modelSchema.roles[L]?this.modelSchema.roles[C]:this.modelSchema.roles[L];for(let s=1;s<l.length;s++)if(l[s].role!==m(l[s-1].role))throw new M({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires messages to alternate between user and assistant`)});return {system:n,messages:l}}transformTools(t){if(!this.modelSchema.modalities.includes(_))throw new _e({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${_}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(l=>{let m=Ot().safeParse(l);if(!m.success)throw new _e({info:"Invalid tools",cause:m.error});return m.data}).map(l=>({name:l.definition.schema.name,description:l.definition.schema.description,input_schema:l.definition.schema.parameters}))}}getCompleteChatUrl(t,o,n){return j(this,null,function*(){return new Promise(l=>{l(this.completeChatUrl);})})}getCompleteChatHeaders(t,o,n){return j(this,null,function*(){let l=this.getDefaultHeaders();return n&&n.length>0&&(l=be(f({},l),{"anthropic-beta":"tools-2024-05-16"})),new Promise(m=>{m(l);})})}getCompleteChatData(t,o,n){return j(this,null,function*(){let l=this.transformConfig(t,o,n),m=this.transformMessages(o);if(m.messages&&m.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let s=n?this.transformTools(n):{};return new Promise(i=>{i(f(f(f(f({},this.getDefaultParams()),l),m),s));})})}transformCompleteChatResponse(t){let o=ro.safeParse(t);if(o.success){let n=o.data,m=n.content.map((d,u)=>{if(d.type==="text")return St(d.text);if(d.type==="tool_use")return xt(u,d.id,d.name,JSON.stringify(d.input))}),s=[{role:C,content:m}],i={promptTokens:n.usage.input_tokens,completionTokens:n.usage.output_tokens,totalTokens:n.usage.input_tokens+n.usage.output_tokens};return {messages:s,usage:i,logProbs:[]}}throw new I({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(t,o,n){return j(this,null,function*(){return new Promise(l=>{l(this.streamChatUrl);})})}getStreamChatHeaders(t,o,n){let l=this.getDefaultHeaders();return n&&n.length>0&&(l=be(f({},l),{"anthropic-beta":"tools-2024-05-16"})),new Promise(m=>{m(l);})}getStreamChatData(t,o,n){return j(this,null,function*(){let l=this.transformConfig(t,o,n),m=this.transformMessages(o);if(m.messages&&m.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let s=n?this.transformTools(n):{};return new Promise(i=>{i(f(f(f(f({stream:!0},this.getDefaultParams()),l),m),s));})})}transformStreamChatResponseChunk(t,o){return ht(this,null,function*(){let n=(o+t).split(`
14
- `).filter(l=>l.trim()!=="");for(let l of n)if(l.startsWith("data: {")&&l.endsWith("}")){let m;try{m=JSON.parse(l.substring(6));}catch(s){throw new I({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${m}`)})}if("type"in m){if(m.type==="message_stop")return;if(m.type==="message_start"){let s=lo.safeParse(m);if(s.success){let i=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:i.message.usage.input_tokens,completionTokens:i.message.usage.output_tokens,totalTokens:i.message.usage.input_tokens+i.message.usage.output_tokens}},buffer:o};}else throw new I({info:"Invalid response from model",cause:s.error})}else if(m.type==="message_delta"){let s=mo.safeParse(m);if(s.success){let i=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:0,completionTokens:i.usage.output_tokens,totalTokens:i.usage.output_tokens}},buffer:o};}else throw new I({info:"Invalid response from model",cause:s.error})}else if(m.type==="content_block_start"){let s=po.safeParse(m);if(s.success){let i=s.data,d=[];i.content_block.type==="text"?d.push(xe(C,i.content_block.text)):i.content_block.type==="tool_use"&&d.push(Oe(C,i.index,i.content_block.id,i.content_block.name,"")),yield {partialResponse:{partialMessages:d},buffer:o};}else throw new I({info:"Invalid response from model",cause:s.error})}else if(m.type==="content_block_delta"){let s=co.safeParse(m);if(s.success){let i=s.data,d=[];i.delta.type==="text_delta"?d.push(xe(C,i.delta.text)):i.delta.type==="input_json_delta"&&d.push(Oe(C,i.index,"","",i.delta.partial_json)),yield {partialResponse:{partialMessages:d},buffer:o};}else throw new I({info:"Invalid response from model",cause:s.error})}}else throw new I({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property,
15
- received : ${JSON.stringify(m)}`)})}})}};var Ge="claude-3-haiku-20240307",ia="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",Je=F(D,G).parse({name:Ge,description:ia,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),yo=N,ie=class extends P{constructor(t){super(Je,t);}};var We="claude-3-sonnet-20240229",ra="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Ze=F(D,G).parse({name:We,description:ra,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),fo=N,re=class extends P{constructor(t){super(Ze,t);}};var Ye="claude-3-opus-20240229",la="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",Qe=F(D,G).parse({name:Ye,description:la,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),bo=N,le=class extends P{constructor(t){super(Qe,t);}};var Xe="claude-3-5-sonnet-20240620",da="Most intelligent model. Highest level of intelligence and capability.",et=F(D,G).parse({name:Xe,description:da,maxInputTokens:2e5,maxOutputTokens:8192,roles:H,modalities:K,config:{def:O.base(8192,4).def,schema:O.base(8192,4).schema}}),To=N,de=class extends P{constructor(t){super(et,t);}};var A=[z],w=zod.z.enum([z]);var xo=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()})});var pa=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),Oo=zod.z.object({model:zod.z.string().min(1).optional(),input:pa,encoding_format:zod.z.enum(["base64"]).nullable().optional(),input_type:zod.z.enum(["query","document"]).nullable().optional(),truncation:zod.z.boolean().optional()});var E=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),T=class{constructor(t,o){this.version="v1";let n=E.parse(o);this.modelSchema=t,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Y(J.embeddingBaseUrl),this.getEmbeddingsUrl=Y(n.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getTokenCount(t){return t.requests.reduce((o,n)=>o+n.length,0)}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}transformModelRequest(t){let o=Oo.safeParse(t);if(!o.success)throw new Q({info:"Invalid model request",cause:o.error});let n=o.data,l=n.model,m={encodingFormat:n.encoding_format,inputType:n.input_type,truncation:n.truncation},s=ne().parse(se(m)),i;return typeof n.input=="string"?i={modality:z,requests:[n.input]}:i={modality:z,requests:n.input},{modelName:l,config:s,embeddingRequests:i}}transformConfig(t,o){let n=this.modelSchema.config.schema.safeParse(t);if(!n.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let l=n.data;return Object.keys(l).forEach(s=>{if(!this.modelSchema.config.def[s])throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
16
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(l).reduce((s,i)=>{let u=this.modelSchema.config.def[i].param,g=l[i];return s[u]=g,s},{})}transformEmbeddingRequests(t){let o=kt().safeParse(t);if(!o.success)throw new qe({info:"Invalid embedding requests",cause:o.error});if(o.data.requests.length>128)throw new qe({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:o.data.requests}}getGetEmbeddingsUrl(t,o){return j(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,o){return j(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,o){return j(this,null,function*(){return new Promise(n=>{n(f(f(f({},this.getDefaultParams()),this.transformConfig(t,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(t){let o,n=xo.safeParse(t);if(n.success){let l=n.data;o=typeof l.data[0].embedding=="string"?we:Ae;let m=l.data.map(s=>typeof s.embedding=="string"?{index:s.index,embedding:s.embedding}:{index:s.index,embedding:s.embedding});return {encodingFormat:o,embeddings:m,usage:{totalTokens:l.usage.total_tokens}}}throw new I({info:"Invalid response from model",cause:n.error})}};var tt="voyage-code-2",ca="Optimized for code retrieval.",ot=x(w).parse({name:tt,description:ca,modalities:A,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:y.base().def,schema:y.base().schema}}),Co=E,me=class extends T{constructor(t){super(ot,t);}};var nt="voyage-law-2",ua="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",at=x(w).parse({name:nt,description:ua,modalities:A,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:y.base().def,schema:y.base().schema}}),Mo=E,pe=class extends T{constructor(t){super(at,t);}};var st="voyage-multilingual-2",ga="Optimized for multilingual retrieval and RAG.",it=x(w).parse({name:st,description:ga,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:y.base().def,schema:y.base().schema}}),Eo=E,ce=class extends T{constructor(t){super(it,t);}};var rt="voyage-finance-2",ha="Optimized for finance retrieval and RAG.",lt=x(w).parse({name:rt,description:ha,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:y.base().def,schema:y.base().schema}}),Ro=E,ue=class extends T{constructor(t){super(lt,t);}};var dt="voyage-3-lite",ya="Optimized for latency and cost.",mt=x(w).parse({name:dt,description:ya,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:y.base().def,schema:y.base().schema}}),vo=E,ge=class extends T{constructor(t){super(mt,t);}};var pt="voyage-3",fa="Optimized for quality.",ct=x(w).parse({name:pt,description:fa,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:y.base().def,schema:y.base().schema}}),So=E,he=class extends T{constructor(t){super(ct,t);}};
10
+ one of [${u.choices.join(", ")}]`)})}}return i}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let o=t.map(s=>{let i=Se().safeParse(s);if(!i.success)throw new T({info:"Invalid messages",cause:i.error});return i.data});o.forEach(s=>{s.content.forEach(i=>{if(!this.modelSchema.modalities.includes(i.modality))throw new T({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${i.modality}',
11
+ available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new T({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
12
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let n="",l=[];if(o.forEach(s=>{switch(s.role){case Z:s.content.forEach(i=>{if(i.modality===b)n+=i.value;else throw new T({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${i.modality}'`)})});break;case M:{let i=[];s.content.forEach(d=>{if(d.modality===b)i.push({type:"text",text:d.value});else if(d.modality===_)i.push({type:"tool_use",id:d.id,name:d.name,input:JSON.parse(d.arguments)});else throw new T({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),l.push({role:this.modelSchema.roles[s.role],content:i});}break;case I:{let i=[];s.content.forEach(d=>{if(d.modality===b)i.push({type:"text",text:d.value});else if(d.modality===U){if(d.value.type==="base64")i.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 T({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 T({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),l.push({role:this.modelSchema.roles[s.role],content:i});}break;case Q:{let i=[];s.content.forEach(d=>{if(d.modality===$)i.push({type:"tool_result",tool_use_id:d.id,content:d.data});else throw new T({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),l.push({role:this.modelSchema.roles[s.role],content:i});}break;default:throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
13
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),l[0].role!==this.modelSchema.roles[I])throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=s=>s===this.modelSchema.roles[I]?this.modelSchema.roles[M]:this.modelSchema.roles[I];for(let s=1;s<l.length;s++)if(l[s].role!==m(l[s-1].role))throw new T({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires messages to alternate between user and assistant`)});return {system:n,messages:l}}transformTools(t){if(!this.modelSchema.modalities.includes(_))throw new qe({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${_}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(l=>{let m=At().safeParse(l);if(!m.success)throw new qe({info:"Invalid tools",cause:m.error});return m.data}).map(l=>({name:l.definition.schema.name,description:l.definition.schema.description,input_schema:l.definition.schema.parameters}))}}getCompleteChatUrl(t,o,n){return j(this,null,function*(){return new Promise(l=>{l(this.completeChatUrl);})})}getCompleteChatHeaders(t,o,n){return j(this,null,function*(){let l=this.getDefaultHeaders();return n&&n.length>0&&(l=Te(f({},l),{"anthropic-beta":"tools-2024-05-16"})),new Promise(m=>{m(l);})})}getCompleteChatData(t,o,n){return j(this,null,function*(){let l=this.transformConfig(t,o,n),m=this.transformMessages(o);if(m.messages&&m.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let s=n?this.transformTools(n):{};return new Promise(i=>{i(f(f(f(f({},this.getDefaultParams()),l),m),s));})})}transformCompleteChatResponse(t){let o=lo.safeParse(t);if(o.success){let n=o.data,m=n.content.map((d,u)=>{if(d.type==="text")return xt(d.text);if(d.type==="tool_use")return Ot(u,d.id,d.name,JSON.stringify(d.input))}),s=[{role:M,content:m}],i={promptTokens:n.usage.input_tokens,completionTokens:n.usage.output_tokens,totalTokens:n.usage.input_tokens+n.usage.output_tokens};return {messages:s,usage:i,logProbs:[]}}throw new P({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(t,o,n){return j(this,null,function*(){return new Promise(l=>{l(this.streamChatUrl);})})}getStreamChatHeaders(t,o,n){let l=this.getDefaultHeaders();return n&&n.length>0&&(l=Te(f({},l),{"anthropic-beta":"tools-2024-05-16"})),new Promise(m=>{m(l);})}getStreamChatData(t,o,n){return j(this,null,function*(){let l=this.transformConfig(t,o,n),m=this.transformMessages(o);if(m.messages&&m.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let s=n?this.transformTools(n):{};return new Promise(i=>{i(f(f(f(f({stream:!0},this.getDefaultParams()),l),m),s));})})}transformStreamChatResponseChunk(t,o){return yt(this,null,function*(){let n=(o+t).split(`
14
+ `).filter(l=>l.trim()!=="");for(let l of n)if(l.startsWith("data: {")&&l.endsWith("}")){let m;try{m=JSON.parse(l.substring(6));}catch(s){throw new P({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${m}`)})}if("type"in m){if(m.type==="message_stop")return;if(m.type==="message_start"){let s=mo.safeParse(m);if(s.success){let i=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:i.message.usage.input_tokens,completionTokens:i.message.usage.output_tokens,totalTokens:i.message.usage.input_tokens+i.message.usage.output_tokens}},buffer:o};}else throw new P({info:"Invalid response from model",cause:s.error})}else if(m.type==="message_delta"){let s=po.safeParse(m);if(s.success){let i=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:0,completionTokens:i.usage.output_tokens,totalTokens:i.usage.output_tokens}},buffer:o};}else throw new P({info:"Invalid response from model",cause:s.error})}else if(m.type==="content_block_start"){let s=co.safeParse(m);if(s.success){let i=s.data,d=[];i.content_block.type==="text"?d.push(Oe(M,i.content_block.text)):i.content_block.type==="tool_use"&&d.push(Ae(M,i.index,i.content_block.id,i.content_block.name,"")),yield {partialResponse:{partialMessages:d},buffer:o};}else throw new P({info:"Invalid response from model",cause:s.error})}else if(m.type==="content_block_delta"){let s=uo.safeParse(m);if(s.success){let i=s.data,d=[];i.delta.type==="text_delta"?d.push(Oe(M,i.delta.text)):i.delta.type==="input_json_delta"&&d.push(Ae(M,i.index,"","",i.delta.partial_json)),yield {partialResponse:{partialMessages:d},buffer:o};}else throw new P({info:"Invalid response from model",cause:s.error})}}else throw new P({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property,
15
+ received : ${JSON.stringify(m)}`)})}})}};var Je="claude-3-haiku-20240307",ia="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",We=F(D,G).parse({name:Je,description:ia,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),fo=N,re=class extends L{constructor(t){super(We,t);}};var Ze="claude-3-sonnet-20240229",ra="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",Ye=F(D,G).parse({name:Ze,description:ra,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),bo=N,le=class extends L{constructor(t){super(Ye,t);}};var Qe="claude-3-opus-20240229",la="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",Xe=F(D,G).parse({name:Qe,description:la,maxInputTokens:2e5,maxOutputTokens:4096,roles:H,modalities:K,config:{def:O.base(4096,4).def,schema:O.base(4096,4).schema}}),To=N,de=class extends L{constructor(t){super(Xe,t);}};var et="claude-3-5-sonnet-20240620",da="Most intelligent model. Highest level of intelligence and capability.",tt=F(D,G).parse({name:et,description:da,maxInputTokens:2e5,maxOutputTokens:8192,roles:H,modalities:K,config:{def:O.base(8192,4).def,schema:O.base(8192,4).schema}}),Co=N,me=class extends L{constructor(t){super(tt,t);}};var A=[z],w=zod.z.enum([z]);var Oo=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()})});var pa=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),Ao=zod.z.object({model:zod.z.string().min(1).optional(),input:pa,encoding_format:zod.z.enum(["base64"]).nullable().optional(),input_type:zod.z.enum(["query","document"]).nullable().optional(),truncation:zod.z.boolean().optional()});var E=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),C=class{constructor(t,o){this.version="v1";let n=E.parse(o);this.modelSchema=t,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=Y(J.embeddingBaseUrl),this.getEmbeddingsUrl=Y(n.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getTokenCount(t){return t.requests.reduce((o,n)=>o+n.length,0)}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}transformModelRequest(t){let o=Ao.safeParse(t);if(!o.success)throw new X({info:"Invalid model request",cause:o.error});let n=o.data,l=n.model,m={encodingFormat:n.encoding_format,inputType:n.input_type,truncation:n.truncation},s=ae().parse(ie(m)),i;return typeof n.input=="string"?i={modality:z,requests:[n.input]}:i={modality:z,requests:n.input},{modelName:l,config:s,embeddingRequests:i}}transformConfig(t,o){let n=this.modelSchema.config.schema.safeParse(t);if(!n.success)throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let l=n.data;return Object.keys(l).forEach(s=>{if(!this.modelSchema.config.def[s])throw new B({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
16
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(l).reduce((s,i)=>{let u=this.modelSchema.config.def[i].param,g=l[i];return s[u]=g,s},{})}transformEmbeddingRequests(t){let o=_t().safeParse(t);if(!o.success)throw new je({info:"Invalid embedding requests",cause:o.error});if(o.data.requests.length>128)throw new je({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:o.data.requests}}getGetEmbeddingsUrl(t,o){return j(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,o){return j(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,o){return j(this,null,function*(){return new Promise(n=>{n(f(f(f({},this.getDefaultParams()),this.transformConfig(t,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(t){let o,n=Oo.safeParse(t);if(n.success){let l=n.data;o=typeof l.data[0].embedding=="string"?ke:we;let m=l.data.map(s=>typeof s.embedding=="string"?{index:s.index,embedding:s.embedding}:{index:s.index,embedding:s.embedding});return {encodingFormat:o,embeddings:m,usage:{totalTokens:l.usage.total_tokens}}}throw new P({info:"Invalid response from model",cause:n.error})}};var ot="voyage-code-2",ca="Optimized for code retrieval.",nt=x(w).parse({name:ot,description:ca,modalities:A,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:y.base().def,schema:y.base().schema}}),Mo=E,pe=class extends C{constructor(t){super(nt,t);}};var at="voyage-law-2",ua="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",st=x(w).parse({name:at,description:ua,modalities:A,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:y.base().def,schema:y.base().schema}}),Eo=E,ce=class extends C{constructor(t){super(st,t);}};var it="voyage-multilingual-2",ga="Optimized for multilingual retrieval and RAG.",rt=x(w).parse({name:it,description:ga,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:y.base().def,schema:y.base().schema}}),Ro=E,ue=class extends C{constructor(t){super(rt,t);}};var lt="voyage-finance-2",ha="Optimized for finance retrieval and RAG.",dt=x(w).parse({name:lt,description:ha,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:y.base().def,schema:y.base().schema}}),vo=E,ge=class extends C{constructor(t){super(dt,t);}};var mt="voyage-3-lite",ya="Optimized for latency and cost.",pt=x(w).parse({name:mt,description:ya,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:y.base().def,schema:y.base().schema}}),So=E,he=class extends C{constructor(t){super(pt,t);}};var ct="voyage-3",fa="Optimized for quality.",ut=x(w).parse({name:ct,description:fa,modalities:A,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:y.base().def,schema:y.base().schema}}),xo=E,ye=class extends C{constructor(t){super(ut,t);}};
17
17
 
18
18
  exports.Anthropic = J;
19
19
  exports.AnthropicChatModelConfigs = O;
@@ -21,85 +21,85 @@ exports.AnthropicChatModelModalities = K;
21
21
  exports.AnthropicChatModelModalitiesEnum = G;
22
22
  exports.AnthropicChatModelRoles = D;
23
23
  exports.AnthropicChatModelRolesMap = H;
24
- exports.AnthropicCompleteChatResponse = ro;
24
+ exports.AnthropicCompleteChatResponse = lo;
25
25
  exports.AnthropicEmbeddingModelConfigs = y;
26
26
  exports.AnthropicEmbeddingModelModalities = A;
27
27
  exports.AnthropicEmbeddingModelModalitiesEnum = w;
28
- exports.AnthropicEmbeddingRequest = Oo;
28
+ exports.AnthropicEmbeddingRequest = Ao;
29
29
  exports.AnthropicEmbeddingRequestInput = pa;
30
- exports.AnthropicGetEmbeddingsResponse = xo;
31
- exports.AnthropicRequest = ho;
30
+ exports.AnthropicGetEmbeddingsResponse = Oo;
31
+ exports.AnthropicRequest = yo;
32
32
  exports.AnthropicRequestAssistantMessage = na;
33
- exports.AnthropicRequestImageContent = uo;
33
+ exports.AnthropicRequestImageContent = go;
34
34
  exports.AnthropicRequestMessage = aa;
35
- exports.AnthropicRequestTextContent = Ke;
35
+ exports.AnthropicRequestTextContent = Ge;
36
36
  exports.AnthropicRequestTool = Xn;
37
37
  exports.AnthropicRequestToolCallContent = ns;
38
38
  exports.AnthropicRequestToolChoiceEnum = ea;
39
39
  exports.AnthropicRequestToolChoiceTool = ta;
40
- exports.AnthropicRequestToolResponseContent = go;
40
+ exports.AnthropicRequestToolResponseContent = ho;
41
41
  exports.AnthropicRequestUserMessage = oa;
42
- exports.AnthropicStreamChatContentBlockDeltaResponse = co;
43
- exports.AnthropicStreamChatContentBlockStartResponse = po;
44
- exports.AnthropicStreamChatMessageDeltaResponse = mo;
45
- exports.AnthropicStreamChatMessageStartResponse = lo;
46
- exports.BaseChatModel = P;
42
+ exports.AnthropicStreamChatContentBlockDeltaResponse = uo;
43
+ exports.AnthropicStreamChatContentBlockStartResponse = co;
44
+ exports.AnthropicStreamChatMessageDeltaResponse = po;
45
+ exports.AnthropicStreamChatMessageStartResponse = mo;
46
+ exports.BaseChatModel = L;
47
47
  exports.BaseChatModelOptions = N;
48
- exports.BaseEmbeddingModel = T;
48
+ exports.BaseEmbeddingModel = C;
49
49
  exports.BaseEmbeddingModelOptions = E;
50
- exports.ChatModelBaseConfigDef = ao;
51
- exports.ChatModelBaseConfigSchema = no;
52
- exports.Claude3Haiku20240307 = ie;
53
- exports.Claude3Haiku20240307Literal = Ge;
54
- exports.Claude3Haiku20240307Options = yo;
55
- exports.Claude3Haiku20240307Schema = Je;
56
- exports.Claude3Opus20240229 = le;
57
- exports.Claude3Opus20240229Literal = Ye;
58
- exports.Claude3Opus20240229Options = bo;
59
- exports.Claude3Opus20240229Schema = Qe;
60
- exports.Claude3Sonnet20240229 = re;
61
- exports.Claude3Sonnet20240229Literal = We;
62
- exports.Claude3Sonnet20240229Options = fo;
63
- exports.Claude3Sonnet20240229Schema = Ze;
64
- exports.Claude3_5Sonnet20240620 = de;
65
- exports.Claude3_5Sonnet20240620Literal = Xe;
66
- exports.Claude3_5Sonnet20240620Options = To;
67
- exports.Claude3_5Sonnet20240620Schema = et;
68
- exports.EmbeddingModelBaseConfigDef = io;
69
- exports.EmbeddingModelBaseConfigSchema = so;
50
+ exports.ChatModelBaseConfigDef = so;
51
+ exports.ChatModelBaseConfigSchema = ao;
52
+ exports.Claude3Haiku20240307 = re;
53
+ exports.Claude3Haiku20240307Literal = Je;
54
+ exports.Claude3Haiku20240307Options = fo;
55
+ exports.Claude3Haiku20240307Schema = We;
56
+ exports.Claude3Opus20240229 = de;
57
+ exports.Claude3Opus20240229Literal = Qe;
58
+ exports.Claude3Opus20240229Options = To;
59
+ exports.Claude3Opus20240229Schema = Xe;
60
+ exports.Claude3Sonnet20240229 = le;
61
+ exports.Claude3Sonnet20240229Literal = Ze;
62
+ exports.Claude3Sonnet20240229Options = bo;
63
+ exports.Claude3Sonnet20240229Schema = Ye;
64
+ exports.Claude3_5Sonnet20240620 = me;
65
+ exports.Claude3_5Sonnet20240620Literal = et;
66
+ exports.Claude3_5Sonnet20240620Options = Co;
67
+ exports.Claude3_5Sonnet20240620Schema = tt;
68
+ exports.EmbeddingModelBaseConfigDef = ro;
69
+ exports.EmbeddingModelBaseConfigSchema = io;
70
70
  exports.ProviderLiteral = sa;
71
- exports.Voyage3 = he;
72
- exports.Voyage3Lite = ge;
73
- exports.Voyage3LiteLiteral = dt;
74
- exports.Voyage3LiteOptions = vo;
75
- exports.Voyage3LiteSchema = mt;
76
- exports.Voyage3Literal = pt;
77
- exports.Voyage3Options = So;
78
- exports.Voyage3Schema = ct;
79
- exports.VoyageCode2 = me;
80
- exports.VoyageCode2Literal = tt;
81
- exports.VoyageCode2Options = Co;
82
- exports.VoyageCode2Schema = ot;
83
- exports.VoyageFinance2 = ue;
84
- exports.VoyageFinance2Literal = rt;
85
- exports.VoyageFinance2Options = Ro;
86
- exports.VoyageFinance2Schema = lt;
87
- exports.VoyageLaw2 = pe;
88
- exports.VoyageLaw2Literal = nt;
89
- exports.VoyageLaw2Options = Mo;
90
- exports.VoyageLaw2Schema = at;
91
- exports.VoyageMultilingual2 = ce;
92
- exports.VoyageMultilingual2Literal = st;
93
- exports.VoyageMultilingual2Options = Eo;
94
- exports.VoyageMultilingual2Schema = it;
95
- exports.encodingFormat = Fe;
96
- exports.inputType = De;
97
- exports.maxTokens = Ne;
98
- exports.stop = Ve;
99
- exports.temperature = Be;
100
- exports.toolChoice = ze;
101
- exports.topK = $e;
102
- exports.topP = Ue;
103
- exports.truncation = He;
71
+ exports.Voyage3 = ye;
72
+ exports.Voyage3Lite = he;
73
+ exports.Voyage3LiteLiteral = mt;
74
+ exports.Voyage3LiteOptions = So;
75
+ exports.Voyage3LiteSchema = pt;
76
+ exports.Voyage3Literal = ct;
77
+ exports.Voyage3Options = xo;
78
+ exports.Voyage3Schema = ut;
79
+ exports.VoyageCode2 = pe;
80
+ exports.VoyageCode2Literal = ot;
81
+ exports.VoyageCode2Options = Mo;
82
+ exports.VoyageCode2Schema = nt;
83
+ exports.VoyageFinance2 = ge;
84
+ exports.VoyageFinance2Literal = lt;
85
+ exports.VoyageFinance2Options = vo;
86
+ exports.VoyageFinance2Schema = dt;
87
+ exports.VoyageLaw2 = ce;
88
+ exports.VoyageLaw2Literal = at;
89
+ exports.VoyageLaw2Options = Eo;
90
+ exports.VoyageLaw2Schema = st;
91
+ exports.VoyageMultilingual2 = ue;
92
+ exports.VoyageMultilingual2Literal = it;
93
+ exports.VoyageMultilingual2Options = Ro;
94
+ exports.VoyageMultilingual2Schema = rt;
95
+ exports.encodingFormat = De;
96
+ exports.inputType = He;
97
+ exports.maxTokens = Ve;
98
+ exports.stop = Ue;
99
+ exports.temperature = Ne;
100
+ exports.toolChoice = Fe;
101
+ exports.topK = ze;
102
+ exports.topP = $e;
103
+ exports.truncation = Ke;
104
104
  //# sourceMappingURL=index.js.map
105
105
  //# sourceMappingURL=index.js.map