@adaline/bedrock 0.12.0 → 0.13.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 +22 -20
- package/dist/index.d.ts +22 -20
- package/dist/index.js +20 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChatModelSchemaType, UrlType, HeadersType, ParamsType, ProviderV1, ChatModelV1, EmbeddingModelSchemaType, EmbeddingModelV1 } from '@adaline/provider';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { BaseChatModel } from '@adaline/anthropic';
|
|
4
4
|
import { ConfigType, MessageType, ToolType, PartialChatResponseType } from '@adaline/types';
|
|
5
5
|
|
|
6
|
-
declare
|
|
7
|
-
readonly version: "v1";
|
|
8
|
-
readonly name = "bedrock";
|
|
9
|
-
static readonly awsService = "bedrock";
|
|
10
|
-
static readonly awsUrl: (awsRegion: string) => string;
|
|
11
|
-
private readonly chatModelFactories;
|
|
12
|
-
private readonly embeddingModelFactories;
|
|
13
|
-
chatModelLiterals(): string[];
|
|
14
|
-
chatModelSchemas(): Record<string, ChatModelSchemaType>;
|
|
15
|
-
chatModel(options: O): ChatModelV1;
|
|
16
|
-
embeddingModelLiterals(): string[];
|
|
17
|
-
embeddingModelSchemas(): Record<string, EmbeddingModelSchemaType>;
|
|
18
|
-
embeddingModel(options: O): EmbeddingModelV1;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare const BaseChatModelAnthropicOptions: z.ZodObject<{
|
|
6
|
+
declare const BaseChatModelOptions: z.ZodObject<{
|
|
22
7
|
modelName: z.ZodString;
|
|
23
8
|
awsRegion: z.ZodString;
|
|
24
9
|
awsAccessKeyId: z.ZodString;
|
|
@@ -34,7 +19,8 @@ declare const BaseChatModelAnthropicOptions: z.ZodObject<{
|
|
|
34
19
|
awsAccessKeyId: string;
|
|
35
20
|
awsSecretAccessKey: string;
|
|
36
21
|
}>;
|
|
37
|
-
type
|
|
22
|
+
type BaseChatModelOptionsType = z.infer<typeof BaseChatModelOptions>;
|
|
23
|
+
|
|
38
24
|
declare class BaseChatModelAnthropic extends BaseChatModel {
|
|
39
25
|
readonly version: "v1";
|
|
40
26
|
modelSchema: ChatModelSchemaType;
|
|
@@ -44,7 +30,7 @@ declare class BaseChatModelAnthropic extends BaseChatModel {
|
|
|
44
30
|
private readonly awsRegion;
|
|
45
31
|
private readonly awsAccessKeyId;
|
|
46
32
|
private readonly awsSecretAccessKey;
|
|
47
|
-
constructor(modelSchema: ChatModelSchemaType, options:
|
|
33
|
+
constructor(modelSchema: ChatModelSchemaType, options: BaseChatModelOptionsType);
|
|
48
34
|
getDefaultBaseUrl(): UrlType;
|
|
49
35
|
getDefaultHeaders(): HeadersType;
|
|
50
36
|
getDefaultParams(): ParamsType;
|
|
@@ -60,6 +46,7 @@ declare class BaseChatModelAnthropic extends BaseChatModel {
|
|
|
60
46
|
}>;
|
|
61
47
|
}
|
|
62
48
|
|
|
49
|
+
declare const BedrockClaude3Haiku20240307Literal = "anthropic.claude-3-haiku-20240307-v1:0";
|
|
63
50
|
declare const BedrockClaude3Haiku20240307Schema: {
|
|
64
51
|
name: string;
|
|
65
52
|
description: string;
|
|
@@ -127,4 +114,19 @@ declare class BedrockClaude3Haiku20240307 extends BaseChatModelAnthropic {
|
|
|
127
114
|
constructor(options: BedrockClaude3Haiku20240307OptionsType);
|
|
128
115
|
}
|
|
129
116
|
|
|
130
|
-
|
|
117
|
+
declare class Bedrock<C extends BaseChatModelOptionsType, E extends Record<string, any> = Record<string, any>> implements ProviderV1<C, E> {
|
|
118
|
+
readonly version: "v1";
|
|
119
|
+
readonly name = "bedrock";
|
|
120
|
+
static readonly awsService = "bedrock";
|
|
121
|
+
static readonly awsUrl: (awsRegion: string) => string;
|
|
122
|
+
private readonly chatModelFactories;
|
|
123
|
+
private readonly embeddingModelFactories;
|
|
124
|
+
chatModelLiterals(): string[];
|
|
125
|
+
chatModelSchemas(): Record<string, ChatModelSchemaType>;
|
|
126
|
+
chatModel(options: C): ChatModelV1;
|
|
127
|
+
embeddingModelLiterals(): string[];
|
|
128
|
+
embeddingModelSchemas(): Record<string, EmbeddingModelSchemaType>;
|
|
129
|
+
embeddingModel(options: E): EmbeddingModelV1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export { BaseChatModelAnthropic, BaseChatModelOptions, type BaseChatModelOptionsType, Bedrock, BedrockClaude3Haiku20240307, BedrockClaude3Haiku20240307Literal, BedrockClaude3Haiku20240307Options, type BedrockClaude3Haiku20240307OptionsType, BedrockClaude3Haiku20240307Schema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChatModelSchemaType, UrlType, HeadersType, ParamsType, ProviderV1, ChatModelV1, EmbeddingModelSchemaType, EmbeddingModelV1 } from '@adaline/provider';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { BaseChatModel } from '@adaline/anthropic';
|
|
4
4
|
import { ConfigType, MessageType, ToolType, PartialChatResponseType } from '@adaline/types';
|
|
5
5
|
|
|
6
|
-
declare
|
|
7
|
-
readonly version: "v1";
|
|
8
|
-
readonly name = "bedrock";
|
|
9
|
-
static readonly awsService = "bedrock";
|
|
10
|
-
static readonly awsUrl: (awsRegion: string) => string;
|
|
11
|
-
private readonly chatModelFactories;
|
|
12
|
-
private readonly embeddingModelFactories;
|
|
13
|
-
chatModelLiterals(): string[];
|
|
14
|
-
chatModelSchemas(): Record<string, ChatModelSchemaType>;
|
|
15
|
-
chatModel(options: O): ChatModelV1;
|
|
16
|
-
embeddingModelLiterals(): string[];
|
|
17
|
-
embeddingModelSchemas(): Record<string, EmbeddingModelSchemaType>;
|
|
18
|
-
embeddingModel(options: O): EmbeddingModelV1;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare const BaseChatModelAnthropicOptions: z.ZodObject<{
|
|
6
|
+
declare const BaseChatModelOptions: z.ZodObject<{
|
|
22
7
|
modelName: z.ZodString;
|
|
23
8
|
awsRegion: z.ZodString;
|
|
24
9
|
awsAccessKeyId: z.ZodString;
|
|
@@ -34,7 +19,8 @@ declare const BaseChatModelAnthropicOptions: z.ZodObject<{
|
|
|
34
19
|
awsAccessKeyId: string;
|
|
35
20
|
awsSecretAccessKey: string;
|
|
36
21
|
}>;
|
|
37
|
-
type
|
|
22
|
+
type BaseChatModelOptionsType = z.infer<typeof BaseChatModelOptions>;
|
|
23
|
+
|
|
38
24
|
declare class BaseChatModelAnthropic extends BaseChatModel {
|
|
39
25
|
readonly version: "v1";
|
|
40
26
|
modelSchema: ChatModelSchemaType;
|
|
@@ -44,7 +30,7 @@ declare class BaseChatModelAnthropic extends BaseChatModel {
|
|
|
44
30
|
private readonly awsRegion;
|
|
45
31
|
private readonly awsAccessKeyId;
|
|
46
32
|
private readonly awsSecretAccessKey;
|
|
47
|
-
constructor(modelSchema: ChatModelSchemaType, options:
|
|
33
|
+
constructor(modelSchema: ChatModelSchemaType, options: BaseChatModelOptionsType);
|
|
48
34
|
getDefaultBaseUrl(): UrlType;
|
|
49
35
|
getDefaultHeaders(): HeadersType;
|
|
50
36
|
getDefaultParams(): ParamsType;
|
|
@@ -60,6 +46,7 @@ declare class BaseChatModelAnthropic extends BaseChatModel {
|
|
|
60
46
|
}>;
|
|
61
47
|
}
|
|
62
48
|
|
|
49
|
+
declare const BedrockClaude3Haiku20240307Literal = "anthropic.claude-3-haiku-20240307-v1:0";
|
|
63
50
|
declare const BedrockClaude3Haiku20240307Schema: {
|
|
64
51
|
name: string;
|
|
65
52
|
description: string;
|
|
@@ -127,4 +114,19 @@ declare class BedrockClaude3Haiku20240307 extends BaseChatModelAnthropic {
|
|
|
127
114
|
constructor(options: BedrockClaude3Haiku20240307OptionsType);
|
|
128
115
|
}
|
|
129
116
|
|
|
130
|
-
|
|
117
|
+
declare class Bedrock<C extends BaseChatModelOptionsType, E extends Record<string, any> = Record<string, any>> implements ProviderV1<C, E> {
|
|
118
|
+
readonly version: "v1";
|
|
119
|
+
readonly name = "bedrock";
|
|
120
|
+
static readonly awsService = "bedrock";
|
|
121
|
+
static readonly awsUrl: (awsRegion: string) => string;
|
|
122
|
+
private readonly chatModelFactories;
|
|
123
|
+
private readonly embeddingModelFactories;
|
|
124
|
+
chatModelLiterals(): string[];
|
|
125
|
+
chatModelSchemas(): Record<string, ChatModelSchemaType>;
|
|
126
|
+
chatModel(options: C): ChatModelV1;
|
|
127
|
+
embeddingModelLiterals(): string[];
|
|
128
|
+
embeddingModelSchemas(): Record<string, EmbeddingModelSchemaType>;
|
|
129
|
+
embeddingModel(options: E): EmbeddingModelV1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export { BaseChatModelAnthropic, BaseChatModelOptions, type BaseChatModelOptionsType, Bedrock, BedrockClaude3Haiku20240307, BedrockClaude3Haiku20240307Literal, BedrockClaude3Haiku20240307Options, type BedrockClaude3Haiku20240307OptionsType, BedrockClaude3Haiku20240307Schema };
|
package/dist/index.js
CHANGED
|
@@ -5,27 +5,27 @@ var sha256Js = require('@aws-crypto/sha256-js');
|
|
|
5
5
|
var protocolHttp = require('@smithy/protocol-http');
|
|
6
6
|
var signatureV4 = require('@smithy/signature-v4');
|
|
7
7
|
|
|
8
|
-
var Mo=Object.defineProperty
|
|
9
|
-
Message: ${Lo(a)}`),this.name=me,this.info=t,this.cause=a,this.name=i!=null?i:me,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof _e}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Uo="system",Bo="user",Re="assistant",Fo="tool",Do=[Uo,Bo,Re,Fo],ue=zod.z.enum(Do),Ko=[Re],Ho=zod.z.enum(Ko),Ne="image",Vo="base64",zo=["png","jpeg","webp","gif"],Jo=zod.z.object({type:zod.z.literal(Vo),base64:zod.z.string(),media_type:zod.z.enum(zo)}),Go="url",Wo=zod.z.object({type:zod.z.literal(Go),url:zod.z.string()}),Zo=zod.z.discriminatedUnion("type",[Jo,Wo]),Yo=["low","medium","high","auto"],Qo=zod.z.enum(Yo),Xo=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ne),detail:Qo,value:Zo,metadata:o}),Ae="text",ea=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ae),value:zod.z.string(),metadata:o}),qe="partial-text",ta=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(qe),value:zod.z.string(),metadata:o}),$e="tool-call",oa=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal($e),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:o}),Le="partial-tool-call",aa=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Le),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:o}),Ue="tool-response",na=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ue),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:o}),ia=[Ae,Ne,$e,Ue],Be=zod.z.enum(ia),sa=(o=zod.z.undefined(),t=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[ea(o),Xo(t),oa(a),na(i)]),ra=[qe,Le];zod.z.enum(ra);var la=(o=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[ta(o),aa(t)]);var da=(o=ue,t=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),r=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:o,content:zod.z.array(sa(t,a,i,r)),metadata:s}),ma=(o=Ho,t=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:o,partialContent:la(t,a),metadata:i});var ca=["object","array","number","string","boolean","enum"],Me=zod.z.enum(ca),ua=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Me,zod.z.array(zod.z.union([Me,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),pa=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(ua),additionalProperties:zod.z.literal(!1)});zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:pa}).optional();var ha="function";var ga=zod.z.enum(["object","array","number","string","boolean","null"]),fa=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ga.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(fa).optional(),required:zod.z.array(zod.z.string()).optional()});var ya=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 ba=zod.z.enum(["function"]);zod.z.object({type:ba,definition:zod.z.object({schema:ya})});var va=[ha];zod.z.enum(va);var wa="text",Ca="token",Ta=[wa,Ca];zod.z.enum(Ta);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var ka="float",Sa=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Oa="base64",ja=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Pe=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(ka),embeddings:zod.z.array(Sa),usage:Pe.optional()}),zod.z.object({encodingFormat:zod.z.literal(Oa),embeddings:zod.z.array(ja),usage:Pe.optional()})]);var Fe=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Ie=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Ea=Ie.extend({topLogProbs:zod.z.array(Ie)}),De=zod.z.array(Ea);zod.z.object({messages:zod.z.array(da()),usage:Fe.optional(),logProbs:De.optional()});zod.z.object({partialMessages:zod.z.array(ma()),usage:Fe.optional(),logProbs:De.optional()});var Ke="ProviderError",z=class Ve extends ce{constructor({info:t,cause:a}){super({info:t,cause:a},Ke),this.name=Ke,this.info=t,this.cause=a;}static isProviderError(t){return t instanceof Ve}};var He="ModelResponseError",ze=class Je extends ce{constructor({info:t,cause:a}){super({info:t,cause:a},He),this.name=He,this.cause=a,this.info=t;}static isModelResponseError(t){return t instanceof Je}};var Ge="multi-string",Ma=zod.z.object({type:zod.z.literal(Ge),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()});var We="object-schema",Pa=zod.z.object({type:zod.z.literal(We),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var Ze="range",Ia=zod.z.object({type:zod.z.literal(Ze),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()});var Ye="select-boolean",_a=zod.z.object({type:zod.z.literal(Ye),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()});var Qe="select-string",Ra=zod.z.object({type:zod.z.literal(Qe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))});var Na=[Ze,Ge,Qe,We,Ye];zod.z.enum(Na);var Aa=zod.z.discriminatedUnion("type",[Ia,Ma,Ra,_a,Pa]),Xe=(o=ue,t=Be)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(o,zod.z.string().min(1).optional()),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Aa),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var i,r;let s=Object.keys(a.def),l=Object.keys((r=(i=a.schema)==null?void 0:i.shape)!=null?r:{});return s.every(d=>l.includes(d))&&l.every(d=>s.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var qa=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var et=o=>{if(qa()){let t=atob(o),a=new Uint8Array(t.length);for(let i=0;i<t.length;i++)a[i]=t.charCodeAt(i);return new TextDecoder("utf-8").decode(a)}else return Buffer.from(o,"base64").toString("utf-8")};var $a=Object.defineProperty,La=Object.defineProperties,Ua=Object.getOwnPropertyDescriptors,tt=Object.getOwnPropertySymbols,Ba=Object.prototype.hasOwnProperty,Fa=Object.prototype.propertyIsEnumerable,Da=(o,t)=>(t=Symbol[o])?t:Symbol.for("Symbol."+o),ot=(o,t,a)=>t in o?$a(o,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[t]=a,f=(o,t)=>{for(var a in t||(t={}))Ba.call(t,a)&&ot(o,a,t[a]);if(tt)for(var a of tt(t))Fa.call(t,a)&&ot(o,a,t[a]);return o},ee=(o,t)=>La(o,Ua(t)),j=(o,t,a)=>new Promise((i,r)=>{var s=c=>{try{d(a.next(c));}catch(u){r(u);}},l=c=>{try{d(a.throw(c));}catch(u){r(u);}},d=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,l);d((a=a.apply(o,t)).next());}),Ka=function(o,t){this[0]=o,this[1]=t;},Ha=(o,t,a)=>{var i=(l,d,c,u)=>{try{var h=a[l](d),g=(d=h.value)instanceof Ka,T=h.done;Promise.resolve(g?d[0]:d).then(p=>g?i(l==="return"?l:"next",d[1]?{done:p.done,value:p.value}:p,c,u):c({value:p,done:T})).catch(p=>i("throw",p,c,u));}catch(p){u(p);}},r=l=>s[l]=d=>new Promise((c,u)=>i(l,d,c,u)),s={};return a=a.apply(o,t),s[Da("asyncIterator")]=()=>s,r("next"),r("throw"),r("return"),s},Va=o=>{let t=new WeakSet;return JSON.stringify(o,(a,i)=>{if(typeof i=="object"&&i!==null){if(t.has(i))return;t.add(i);}return i})},za=o=>o==null?"unknown error":typeof o=="string"?o:o instanceof Error?o.message:Va(o),pe="GatewayBaseError",P=class vt extends Error{constructor({info:t,cause:a},i){super(`[${i!=null?i:pe}]: ${t}
|
|
10
|
-
Message: ${za(a)}`),this.name=pe,this.info=t,this.cause=a,this.name=i!=null?i:pe,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof vt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},G="system",M="user",w="assistant",Ja="tool",Ga=[G,M,w,Ja],wt=zod.z.enum(Ga),Wa=[w],Za=zod.z.enum(Wa),N="image",Ct="base64",Ya=["png","jpeg","webp","gif"],Qa=zod.z.object({type:zod.z.literal(Ct),base64:zod.z.string(),media_type:zod.z.enum(Ya)}),Xa="url",en=zod.z.object({type:zod.z.literal(Xa),url:zod.z.string()}),tn=zod.z.discriminatedUnion("type",[Qa,en]),on=["low","medium","high","auto"],an=zod.z.enum(on),nn=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(N),detail:an,value:tn,metadata:o}),y="text",Tt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(y),value:zod.z.string(),metadata:o}),ge="partial-text",xt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ge),value:zod.z.string(),metadata:o}),k="tool-call",kt=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(k),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:o}),fe="partial-tool-call",St=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(fe),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:o}),A="tool-response",sn=(o=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(A),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:o}),rn=[y,N,k,A],ln=zod.z.enum(rn),dn=(o=zod.z.undefined(),t=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Tt(o),nn(t),kt(a),sn(i)]),mn=[ge,fe];zod.z.enum(mn);var cn=(o=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[xt(o),St(t)]),Ot=(o=wt,t=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),r=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:o,content:zod.z.array(dn(t,a,i,r)),metadata:s}),ye=(o=Za,t=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:o,partialContent:cn(t,a),metadata:i}),un=o=>Tt().parse({modality:y,value:o}),pn=(o,t,a,i)=>kt().parse({modality:k,index:o,id:t,name:a,arguments:i}),at=(o,t)=>ye().parse({role:o,partialContent:xt().parse({modality:ge,value:t})}),nt=(o,t,a,i,r)=>ye().parse({role:o,partialContent:St().parse({modality:fe,index:t,id:a,name:i,arguments:r})}),jt=(o=zod.z.record(zod.z.string(),zod.z.any()).optional())=>o,hn=["object","array","number","string","boolean","enum"],it=zod.z.enum(hn),gn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([it,zod.z.array(zod.z.union([it,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),fn=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(gn),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:fn}).optional();var yn="function",bn=zod.z.enum(["object","array","number","string","boolean","null"]),vn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:bn.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(vn).optional(),required:zod.z.array(zod.z.string()).optional()});var wn=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),parameters:zod.z.any(),strict:zod.z.boolean().optional()}),Cn=zod.z.enum(["function"]),Tn=zod.z.object({type:Cn,definition:zod.z.object({schema:wn})}),xn=[yn];zod.z.enum(xn);var kn=(o=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Tn.extend({metadata:o})]),q="text",Et="token",Sn=[q,Et],On=zod.z.enum(Sn),jn=zod.z.array(zod.z.string().min(1)),En=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Mn=(o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(q),metadata:o,requests:jn}),zod.z.object({modality:zod.z.literal(Et),metadata:o,requests:En})]),Mt="float",Pn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Pt="base64",In=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),st=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Mt),embeddings:zod.z.array(Pn),usage:st.optional()}),zod.z.object({encodingFormat:zod.z.literal(Pt),embeddings:zod.z.array(In),usage:st.optional()})]);var It=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),rt=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),_n=rt.extend({topLogProbs:zod.z.array(rt)}),_t=zod.z.array(_n);zod.z.object({messages:zod.z.array(Ot()),usage:It.optional(),logProbs:_t.optional()});zod.z.object({partialMessages:zod.z.array(ye()),usage:It.optional(),logProbs:_t.optional()});var Rn=Object.defineProperty,lt=Object.getOwnPropertySymbols,Nn=Object.prototype.hasOwnProperty,An=Object.prototype.propertyIsEnumerable,dt=(o,t,a)=>t in o?Rn(o,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[t]=a,oe=(o,t)=>{for(var a in t||(t={}))Nn.call(t,a)&&dt(o,a,t[a]);if(lt)for(var a of lt(t))An.call(t,a)&&dt(o,a,t[a]);return o},mt="ProviderError",X=class Rt extends P{constructor({info:t,cause:a}){super({info:t,cause:a},mt),this.name=mt,this.info=t,this.cause=a;}static isProviderError(t){return t instanceof Rt}},ct="ModelResponseError",O=class Nt extends P{constructor({info:t,cause:a}){super({info:t,cause:a},ct),this.name=ct,this.cause=a,this.info=t;}static isModelResponseError(t){return t instanceof Nt}},ut="InvalidModelRequestError",he=class At extends P{constructor({info:t,cause:a}){super({info:t,cause:a},ut),this.name=ut,this.cause=a,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof At}},pt="InvalidConfigError",E=class qt extends P{constructor({info:t,cause:a}){super({info:t,cause:a},pt),this.name=pt,this.cause=a,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof qt}},ht="InvalidMessagesError",b=class $t extends P{constructor({info:t,cause:a}){super({info:t,cause:a},ht),this.name=ht,this.cause=a,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof $t}},gt="InvalidToolsError",ft=class Lt extends P{constructor({info:t,cause:a}){super({info:t,cause:a},gt),this.name=gt,this.cause=a,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof Lt}},yt="InvalidEmbeddingRequestsError",bt=class Ut extends P{constructor({info:t,cause:a}){super({info:t,cause:a},yt),this.name=yt,this.info=t,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Ut}},be="multi-string",Bt=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),max:zod.z.number().int().positive()}),qn=o=>zod.z.array(zod.z.string()).max(o).default([]).optional(),$n=o=>({def:Bt.parse(oe({type:be},o)),schema:qn(o.max)}),Ft="object-schema",Ln=zod.z.object({type:zod.z.literal(Ft),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),ve="range",Dt=zod.z.object({type:zod.z.literal(ve),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),Un=(o,t,a,i)=>zod.z.number().min(o).max(t).step(a).default(i).optional(),ae=o=>({def:Dt.parse(oe({type:ve},o)),schema:Un(o.min,o.max,o.step,o.default)}),we="select-boolean",Kt=zod.z.object({type:zod.z.literal(we),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),Bn=o=>zod.z.boolean().nullable().default(o).optional(),Fn=o=>({def:Kt.parse(oe({type:we},o)),schema:Bn(o.default)}),Ce="select-string",Ht=zod.z.object({type:zod.z.literal(Ce),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))}),Dn=(o,t)=>zod.z.enum(t).nullable().default(o).optional(),Te=o=>({def:Ht.parse(oe({type:Ce},o)),schema:Dn(o.default,o.choices)}),Kn=[ve,be,Ce,Ft,we];zod.z.enum(Kn);var Vt=zod.z.discriminatedUnion("type",[Dt,Bt,Ht,Kt,Ln]),ne=(o=wt,t=ln)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(o,zod.z.string().min(1).optional()),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Vt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var i,r;let s=Object.keys(a.def),l=Object.keys((r=(i=a.schema)==null?void 0:i.shape)!=null?r:{});return s.every(d=>l.includes(d))&&l.every(d=>s.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),$=(o=On)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(o).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Vt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var a,i;let r=Object.keys(t.def),s=Object.keys((i=(a=t.schema)==null?void 0:a.shape)!=null?i:{});return r.every(l=>s.includes(l))&&s.every(l=>r.includes(l))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var Hn={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."},Vn={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."},zn=o=>({type:"multi",title:"Stop sequence",description:`Enter up to ${o} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Jn={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."},Gn={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."},Wn={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},Zn={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},Yn={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."},Qn={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."},Xn={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."},ei={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."},ti={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."},oi={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."},ai={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},ni={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."},ii={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."},si={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},x={TEMPERATURE:Hn,MAX_TOKENS:Vn,STOP:zn,TOP_A:Jn,TOP_P:Gn,TOP_K:Wn,MIN_P:Zn,FREQUENCY_PENALTY:Yn,PRESENCE_PENALTY:Qn,REPETITION_PENALTY:ei,SEED:Xn,LOG_PROBS:ti,TOP_LOG_PROBS:oi,ECHO:ai,RESPONSE_FORMAT:ni,RESPONSE_FORMAT_WITH_SCHEMA:ii,RESPONSE_SCHEMA:si},zt=o=>Object.fromEntries(Object.entries(o).filter(([t,a])=>a!=null)),J=o=>o==null?void 0:o.replace(/\/$/,""),Jt=ae({param:"temperature",title:x.TEMPERATURE.title,description:x.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),Gt=o=>ae({param:"max_tokens",title:x.MAX_TOKENS.title,description:x.MAX_TOKENS.description,min:0,max:o,step:1,default:0}),Wt=o=>$n({param:"stop_sequences",title:x.STOP(o).title,description:x.STOP(o).description,max:o}),Zt=ae({param:"top_p",title:x.TOP_P.title,description:x.TOP_P.description,min:0,max:1,step:.01,default:1}),Yt=ae({param:"top_k",title:x.TOP_K.title,description:x.TOP_K.description,min:0,max:1,step:.01,default:1}),Qt=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"]}),ri=(o,t)=>zod.z.object({temperature:Jt.schema,maxTokens:Gt(o).schema,stop:Wt(t).schema,topP:Zt.schema,topK:Yt.schema,toolChoice:Qt.schema}),li=(o,t)=>({temperature:Jt.def,maxTokens:Gt(o).def,stop:Wt(t).def,topP:Zt.def,topK:Yt.def,toolChoice:Qt.def}),Xt=Te({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:null,choices:["base64"]}),eo=Te({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:null,choices:["query","document"]}),to=Fn({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0}),di=()=>zod.z.object({encodingFormat:Xt.schema,inputType:eo.schema,truncation:to.schema}),mi=()=>({encodingFormat:Xt.def,inputType:eo.def,truncation:to.def}),C={base:(o,t)=>({def:li(o,t),schema:ri(o,t)})},v={base:()=>({def:mi(),schema:di()})},L=zod.z.enum([G,M,w]),U={system:G,user:M,assistant:w},B=[y,N,k,A],F=zod.z.enum([y,N,k,A]),ci=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),ui=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),pi=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[ci,ui])),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()})}),hi=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()})})}),gi=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()})}),fi=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),yi=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),bi=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[fi,yi])}),vi=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),wi=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),Ci=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[vi,wi])}),Ti=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),xi=zod.z.object({type:zod.z.enum(["auto","any"])}),ki=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),xe=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),oo=zod.z.object({type:zod.z.literal("image"),source:zod.z.object({type:zod.z.literal("base64"),media_type:zod.z.enum(["image/jpeg","image/png","image/gif","image/webp"]),data:zod.z.string().base64()})});zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("tool_use"),name:zod.z.string().min(1),input:zod.z.record(zod.z.any())});var ao=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([xe,oo])).min(1))}),Si=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xe,oo,ao])).min(1))}),Oi=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([xe,ao])).min(1))}),ji=zod.z.union([Si,Oi]),Ei=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(ji).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([xi,ki]).optional(),tools:zod.z.array(Ti).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()}),Mi="anthropic",te=class{constructor(){this.version="v1",this.name=Mi,this.chatModelFactories={[no]:{model:_i,modelOptions:Ii,modelSchema:io},[so]:{model:Ai,modelOptions:Ni,modelSchema:ro},[lo]:{model:Li,modelOptions:$i,modelSchema:mo},[co]:{model:Fi,modelOptions:Bi,modelSchema:uo}},this.embeddingModelFactories={[xo]:{model:ls,modelOptions:rs,modelSchema:ko},[Co]:{model:is,modelOptions:ns,modelSchema:To},[po]:{model:Ji,modelOptions:zi,modelSchema:ho},[go]:{model:Zi,modelOptions:Wi,modelSchema:fo},[yo]:{model:Xi,modelOptions:Qi,modelSchema:bo},[vo]:{model:os,modelOptions:ts,modelSchema:wo}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((o,t)=>(o[t]=this.chatModelFactories[t].modelSchema,o),{})}chatModel(o){let t=o.modelName;if(!t)throw new X({info:"options.modelName is required",cause:new Error("options.modelName is required")});if(!(t in this.chatModelFactories))throw new X({info:`Anthropic chat model: ${t} not found`,cause:new Error(`Anthropic chat model: ${t} not found, available chat models:
|
|
11
|
-
${this.chatModelLiterals().join(", ")}`)});let a=this.chatModelFactories[
|
|
12
|
-
${this.embeddingModelLiterals().join(", ")}`)});let a=this.embeddingModelFactories[
|
|
13
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let
|
|
14
|
-
one of [${c.choices.join(", ")}]`)})}}return
|
|
15
|
-
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),
|
|
16
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let a="",i=[];if(
|
|
17
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[
|
|
18
|
-
`).filter(i=>i.trim()!=="");for(let i of a)if(i.startsWith("data: {")&&i.endsWith("}")){let
|
|
19
|
-
received : ${JSON.stringify(
|
|
20
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((
|
|
21
|
-
${this.chatModelLiterals().join(", ")}`)});let i=this.chatModelFactories[a].model,
|
|
22
|
-
${this.embeddingModelLiterals().join(", ")}`)});let i=this.embeddingModelFactories[a].model,r=le(S({},t),{modelName:a}),s=this.embeddingModelFactories[a].modelOptions.parse(r);return new i(s)}};_.awsService="bedrock",_.awsUrl=t=>`https://bedrock.${t}.amazonaws.com`;
|
|
8
|
+
var Mo=Object.defineProperty;var ke=Object.getOwnPropertySymbols,Po=Object.getPrototypeOf,Io=Object.prototype.hasOwnProperty,_o=Object.prototype.propertyIsEnumerable,Ro=Reflect.get;var Ao=(t,o)=>(o=Symbol[t])?o:Symbol.for("Symbol."+t);var Se=(t,o,a)=>o in t?Mo(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,V=(t,o)=>{for(var a in o||(o={}))Io.call(o,a)&&Se(t,a,o[a]);if(ke)for(var a of ke(o))_o.call(o,a)&&Se(t,a,o[a]);return t};var Y=(t,o,a)=>Ro(Po(t),a,o);var _=(t,o,a)=>new Promise((i,l)=>{var s=c=>{try{m(a.next(c));}catch(p){l(p);}},r=c=>{try{m(a.throw(c));}catch(p){l(p);}},m=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,r);m((a=a.apply(t,o)).next());}),se=function(t,o){this[0]=t,this[1]=o;},je=(t,o,a)=>{var i=(r,m,c,p)=>{try{var h=a[r](m),g=(m=h.value)instanceof se,T=h.done;Promise.resolve(g?m[0]:m).then(u=>g?i(r==="return"?r:"next",m[1]?{done:u.done,value:u.value}:u,c,p):c({value:u,done:T})).catch(u=>i("throw",u,c,p));}catch(u){p(u);}},l=r=>s[r]=m=>new Promise((c,p)=>i(r,m,c,p)),s={};return a=a.apply(t,o),s[Ao("asyncIterator")]=()=>s,l("next"),l("throw"),l("return"),s};var No=t=>{let o=new WeakSet;return JSON.stringify(t,(a,i)=>{if(typeof i=="object"&&i!==null){if(o.has(i))return;o.add(i);}return i})},qo=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:No(t),re="GatewayBaseError",le=class Pe extends Error{constructor({info:o,cause:a},i){super(`[${i!=null?i:re}]: ${o}
|
|
9
|
+
Message: ${qo(a)}`),this.name=re,this.info=o,this.cause=a,this.name=i!=null?i:re,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(o){return o instanceof Pe}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Lo="system",$o="user",Ie="assistant",Uo="tool",Bo=[Lo,$o,Ie,Uo],me=zod.z.enum(Bo),Fo=[Ie],Do=zod.z.enum(Fo),_e="image",Ko="base64",Ho=["png","jpeg","webp","gif"],Vo=zod.z.object({type:zod.z.literal(Ko),base64:zod.z.string(),media_type:zod.z.enum(Ho)}),zo="url",Jo=zod.z.object({type:zod.z.literal(zo),url:zod.z.string()}),Go=zod.z.discriminatedUnion("type",[Vo,Jo]),Wo=["low","medium","high","auto"],Zo=zod.z.enum(Wo),Yo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(_e),detail:Zo,value:Go,metadata:t}),Re="text",Qo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Re),value:zod.z.string(),metadata:t}),Ae="partial-text",Xo=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ae),value:zod.z.string(),metadata:t}),Ne="tool-call",ea=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ne),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),qe="partial-tool-call",ta=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(qe),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),Le="tool-response",oa=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Le),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),aa=[Re,_e,Ne,Le],$e=zod.z.enum(aa),na=(t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Qo(t),Yo(o),ea(a),oa(i)]),ia=[Ae,qe];zod.z.enum(ia);var sa=(t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Xo(t),ta(o)]);var ra=(t=me,o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(na(o,a,i,l)),metadata:s}),la=(t=Do,o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:t,partialContent:sa(o,a),metadata:i});var ma=["object","array","number","string","boolean","enum"],Oe=zod.z.enum(ma),da=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([Oe,zod.z.array(zod.z.union([Oe,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()}),ca=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(da),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:ca}).optional();var pa="function";var ua=zod.z.enum(["object","array","number","string","boolean","null"]),ha=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ua.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(ha).optional(),required:zod.z.array(zod.z.string()).optional()});var ga=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 fa=zod.z.enum(["function"]);zod.z.object({type:fa,definition:zod.z.object({schema:ga})});var ya=[pa];zod.z.enum(ya);var ba="text",va="token",wa=[ba,va];zod.z.enum(wa);zod.z.array(zod.z.string().min(1));zod.z.array(zod.z.array(zod.z.number().int().nonnegative()));var Ta="float",xa=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),ka="base64",Sa=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Ee=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Ta),embeddings:zod.z.array(xa),usage:Ee.optional()}),zod.z.object({encodingFormat:zod.z.literal(ka),embeddings:zod.z.array(Sa),usage:Ee.optional()})]);var Ue=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Me=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),ja=Me.extend({topLogProbs:zod.z.array(Me)}),Be=zod.z.array(ja);zod.z.object({messages:zod.z.array(ra()),usage:Ue.optional(),logProbs:Be.optional()});zod.z.object({partialMessages:zod.z.array(la()),usage:Ue.optional(),logProbs:Be.optional()});var Fe="ProviderError",de=class Ke extends le{constructor({info:o,cause:a}){super({info:o,cause:a},Fe),this.name=Fe,this.info=o,this.cause=a;}static isProviderError(o){return o instanceof Ke}};var De="ModelResponseError",He=class Ve extends le{constructor({info:o,cause:a}){super({info:o,cause:a},De),this.name=De,this.cause=a,this.info=o;}static isModelResponseError(o){return o instanceof Ve}};var ze="multi-string",Oa=zod.z.object({type:zod.z.literal(ze),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()});var Je="object-schema",Ea=zod.z.object({type:zod.z.literal(Je),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()});var Ge="range",Ma=zod.z.object({type:zod.z.literal(Ge),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()});var We="select-boolean",Pa=zod.z.object({type:zod.z.literal(We),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()});var Ze="select-string",Ia=zod.z.object({type:zod.z.literal(Ze),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))});var _a=[Ge,ze,Ze,Je,We];zod.z.enum(_a);var Ra=zod.z.discriminatedUnion("type",[Ma,Oa,Ia,Pa,Ea]),Ye=(t=me,o=$e)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(o).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Ra),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var i,l;let s=Object.keys(a.def),r=Object.keys((l=(i=a.schema)==null?void 0:i.shape)!=null?l:{});return s.every(m=>r.includes(m))&&r.every(m=>s.includes(m))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var Aa=()=>typeof window!="undefined"&&typeof window.document!="undefined"&&typeof navigator!="undefined";var Qe=t=>{if(Aa()){let o=atob(t),a=new Uint8Array(o.length);for(let i=0;i<o.length;i++)a[i]=o.charCodeAt(i);return new TextDecoder("utf-8").decode(a)}else return Buffer.from(t,"base64").toString("utf-8")};var Na=Object.defineProperty,qa=Object.defineProperties,La=Object.getOwnPropertyDescriptors,Xe=Object.getOwnPropertySymbols,$a=Object.prototype.hasOwnProperty,Ua=Object.prototype.propertyIsEnumerable,Ba=(t,o)=>(o=Symbol[t])?o:Symbol.for("Symbol."+t),et=(t,o,a)=>o in t?Na(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,f=(t,o)=>{for(var a in o||(o={}))$a.call(o,a)&&et(t,a,o[a]);if(Xe)for(var a of Xe(o))Ua.call(o,a)&&et(t,a,o[a]);return t},tt=(t,o)=>qa(t,La(o)),j=(t,o,a)=>new Promise((i,l)=>{var s=c=>{try{m(a.next(c));}catch(p){l(p);}},r=c=>{try{m(a.throw(c));}catch(p){l(p);}},m=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,r);m((a=a.apply(t,o)).next());}),Fa=function(t,o){this[0]=t,this[1]=o;},Da=(t,o,a)=>{var i=(r,m,c,p)=>{try{var h=a[r](m),g=(m=h.value)instanceof Fa,T=h.done;Promise.resolve(g?m[0]:m).then(u=>g?i(r==="return"?r:"next",m[1]?{done:u.done,value:u.value}:u,c,p):c({value:u,done:T})).catch(u=>i("throw",u,c,p));}catch(u){p(u);}},l=r=>s[r]=m=>new Promise((c,p)=>i(r,m,c,p)),s={};return a=a.apply(t,o),s[Ba("asyncIterator")]=()=>s,l("next"),l("throw"),l("return"),s},Ka=t=>{let o=new WeakSet;return JSON.stringify(t,(a,i)=>{if(typeof i=="object"&&i!==null){if(o.has(i))return;o.add(i);}return i})},Ha=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:Ka(t),ce="GatewayBaseError",M=class vt extends Error{constructor({info:o,cause:a},i){super(`[${i!=null?i:ce}]: ${o}
|
|
10
|
+
Message: ${Ha(a)}`),this.name=ce,this.info=o,this.cause=a,this.name=i!=null?i:ce,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(o){return o instanceof vt}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},J="system",E="user",w="assistant",Va="tool",za=[J,E,w,Va],wt=zod.z.enum(za),Ja=[w],Ga=zod.z.enum(Ja),R="image",Ct="base64",Wa=["png","jpeg","webp","gif"],Za=zod.z.object({type:zod.z.literal(Ct),base64:zod.z.string(),media_type:zod.z.enum(Wa)}),Ya="url",Qa=zod.z.object({type:zod.z.literal(Ya),url:zod.z.string()}),Xa=zod.z.discriminatedUnion("type",[Za,Qa]),en=["low","medium","high","auto"],tn=zod.z.enum(en),on=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(R),detail:tn,value:Xa,metadata:t}),y="text",Tt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(y),value:zod.z.string(),metadata:t}),ue="partial-text",xt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(ue),value:zod.z.string(),metadata:t}),k="tool-call",kt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(k),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),he="partial-tool-call",St=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(he),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),A="tool-response",an=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(A),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),nn=[y,R,k,A],sn=zod.z.enum(nn),rn=(t=zod.z.undefined(),o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Tt(t),on(o),kt(a),an(i)]),ln=[ue,he];zod.z.enum(ln);var mn=(t=zod.z.undefined(),o=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[xt(t),St(o)]),jt=(t=wt,o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined(),l=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(rn(o,a,i,l)),metadata:s}),ge=(t=Ga,o=zod.z.undefined(),a=zod.z.undefined(),i=zod.z.undefined())=>zod.z.object({role:t,partialContent:mn(o,a),metadata:i}),dn=t=>Tt().parse({modality:y,value:t}),cn=(t,o,a,i)=>kt().parse({modality:k,index:t,id:o,name:a,arguments:i}),ot=(t,o)=>ge().parse({role:t,partialContent:xt().parse({modality:ue,value:o})}),at=(t,o,a,i,l)=>ge().parse({role:t,partialContent:St().parse({modality:he,index:o,id:a,name:i,arguments:l})}),Ot=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,pn=["object","array","number","string","boolean","enum"],nt=zod.z.enum(pn),un=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([nt,zod.z.array(zod.z.union([nt,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),hn=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(un),additionalProperties:zod.z.literal(!1)});zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:hn}).optional();var gn="function",fn=zod.z.enum(["object","array","number","string","boolean","null"]),yn=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:fn.optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional()});zod.z.object({type:zod.z.enum(["object"]),title:zod.z.string().optional(),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(yn).optional(),required:zod.z.array(zod.z.string()).optional()});var bn=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),parameters:zod.z.any(),strict:zod.z.boolean().optional()}),vn=zod.z.enum(["function"]),wn=zod.z.object({type:vn,definition:zod.z.object({schema:bn})}),Cn=[gn];zod.z.enum(Cn);var Tn=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[wn.extend({metadata:t})]),N="text",Et="token",xn=[N,Et],kn=zod.z.enum(xn),Sn=zod.z.array(zod.z.string().min(1)),jn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),On=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(N),metadata:t,requests:Sn}),zod.z.object({modality:zod.z.literal(Et),metadata:t,requests:jn})]),Mt="float",En=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Pt="base64",Mn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),it=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Mt),embeddings:zod.z.array(En),usage:it.optional()}),zod.z.object({encodingFormat:zod.z.literal(Pt),embeddings:zod.z.array(Mn),usage:it.optional()})]);var It=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),st=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Pn=st.extend({topLogProbs:zod.z.array(st)}),_t=zod.z.array(Pn);zod.z.object({messages:zod.z.array(jt()),usage:It.optional(),logProbs:_t.optional()});zod.z.object({partialMessages:zod.z.array(ge()),usage:It.optional(),logProbs:_t.optional()});var In=Object.defineProperty,rt=Object.getOwnPropertySymbols,_n=Object.prototype.hasOwnProperty,Rn=Object.prototype.propertyIsEnumerable,lt=(t,o,a)=>o in t?In(t,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[o]=a,X=(t,o)=>{for(var a in o||(o={}))_n.call(o,a)&<(t,a,o[a]);if(rt)for(var a of rt(o))Rn.call(o,a)&<(t,a,o[a]);return t},mt="ProviderError",dt=class Rt extends M{constructor({info:o,cause:a}){super({info:o,cause:a},mt),this.name=mt,this.info=o,this.cause=a;}static isProviderError(o){return o instanceof Rt}},ct="ModelResponseError",S=class At extends M{constructor({info:o,cause:a}){super({info:o,cause:a},ct),this.name=ct,this.cause=a,this.info=o;}static isModelResponseError(o){return o instanceof At}},pt="InvalidModelRequestError",pe=class Nt extends M{constructor({info:o,cause:a}){super({info:o,cause:a},pt),this.name=pt,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(o){return o instanceof Nt}},ut="InvalidConfigError",O=class qt extends M{constructor({info:o,cause:a}){super({info:o,cause:a},ut),this.name=ut,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(o){return o instanceof qt}},ht="InvalidMessagesError",b=class Lt extends M{constructor({info:o,cause:a}){super({info:o,cause:a},ht),this.name=ht,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(o){return o instanceof Lt}},gt="InvalidToolsError",ft=class $t extends M{constructor({info:o,cause:a}){super({info:o,cause:a},gt),this.name=gt,this.cause=a,this.info=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(o){return o instanceof $t}},yt="InvalidEmbeddingRequestsError",bt=class Ut extends M{constructor({info:o,cause:a}){super({info:o,cause:a},yt),this.name=yt,this.info=o,this.cause=a,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(o){return o instanceof Ut}},fe="multi-string",Bt=zod.z.object({type:zod.z.literal(fe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),An=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),Nn=t=>({def:Bt.parse(X({type:fe},t)),schema:An(t.max)}),Ft="object-schema",qn=zod.z.object({type:zod.z.literal(Ft),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),ye="range",Dt=zod.z.object({type:zod.z.literal(ye),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),Ln=(t,o,a,i)=>zod.z.number().min(t).max(o).step(a).default(i).optional(),ee=t=>({def:Dt.parse(X({type:ye},t)),schema:Ln(t.min,t.max,t.step,t.default)}),be="select-boolean",Kt=zod.z.object({type:zod.z.literal(be),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),$n=t=>zod.z.boolean().nullable().default(t).optional(),Un=t=>({def:Kt.parse(X({type:be},t)),schema:$n(t.default)}),ve="select-string",Ht=zod.z.object({type:zod.z.literal(ve),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))}),Bn=(t,o)=>zod.z.enum(o).nullable().default(t).optional(),we=t=>({def:Ht.parse(X({type:ve},t)),schema:Bn(t.default,t.choices)}),Fn=[ye,fe,ve,Ft,be];zod.z.enum(Fn);var Vt=zod.z.discriminatedUnion("type",[Dt,Bt,Ht,Kt,qn]),te=(t=wt,o=sn)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(o).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Vt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(a=>{var i,l;let s=Object.keys(a.def),r=Object.keys((l=(i=a.schema)==null?void 0:i.shape)!=null?l:{});return s.every(m=>r.includes(m))&&r.every(m=>s.includes(m))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),q=(t=kn)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),Vt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var a,i;let l=Object.keys(o.def),s=Object.keys((i=(a=o.schema)==null?void 0:a.shape)!=null?i:{});return l.every(r=>s.includes(r))&&s.every(r=>l.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var Dn={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},Kn={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},Hn=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Vn={type:"range",title:"Top A",description:"Considers only the top tokens that have 'sufficiently high' probabilities relative to the most likely token, functioning like a dynamic Top-P. A lower Top-A value narrows down the token choices based on the highest probability token, while a higher Top-A value refines the filtering without necessarily impacting the creativity of the output."},zn={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},Jn={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},Gn={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},Wn={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},Zn={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},Yn={type:"range",title:"Seed",description:"When seed is fixed to a specific value, the model makes a best effort to provide the same response for repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such as the temperature, can cause variations in the response even when you use the same seed value. By default, a random seed value is used."},Qn={type:"range",title:"Repetition penalty",description:"Reduces the likelihood of repeating tokens from the input. Increasing this value makes the model less prone to repetition, but setting it too high may lead to less coherent output, often resulting in run-on sentences missing smaller words. The token penalty is scaled according to the original token's probability."},Xn={type:"boolean",title:"Log probs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned."},ei={type:"range",title:"Top log probs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used."},ti={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},oi={type:"select",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt."},ai={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},ni={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},x={TEMPERATURE:Dn,MAX_TOKENS:Kn,STOP:Hn,TOP_A:Vn,TOP_P:zn,TOP_K:Jn,MIN_P:Gn,FREQUENCY_PENALTY:Wn,PRESENCE_PENALTY:Zn,REPETITION_PENALTY:Qn,SEED:Yn,LOG_PROBS:Xn,TOP_LOG_PROBS:ei,ECHO:ti,RESPONSE_FORMAT:oi,RESPONSE_FORMAT_WITH_SCHEMA:ai,RESPONSE_SCHEMA:ni},zt=t=>Object.fromEntries(Object.entries(t).filter(([o,a])=>a!=null)),z=t=>t==null?void 0:t.replace(/\/$/,""),Jt=ee({param:"temperature",title:x.TEMPERATURE.title,description:x.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),Gt=t=>ee({param:"max_tokens",title:x.MAX_TOKENS.title,description:x.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Wt=t=>Nn({param:"stop_sequences",title:x.STOP(t).title,description:x.STOP(t).description,max:t}),Zt=ee({param:"top_p",title:x.TOP_P.title,description:x.TOP_P.description,min:0,max:1,step:.01,default:1}),Yt=ee({param:"top_k",title:x.TOP_K.title,description:x.TOP_K.description,min:0,max:1,step:.01,default:1}),Qt=we({param:"tool_choice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'any' means the model will call any of the provided tools. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","any"]}),ii=(t,o)=>zod.z.object({temperature:Jt.schema,maxTokens:Gt(t).schema,stop:Wt(o).schema,topP:Zt.schema,topK:Yt.schema,toolChoice:Qt.schema}),si=(t,o)=>({temperature:Jt.def,maxTokens:Gt(t).def,stop:Wt(o).def,topP:Zt.def,topK:Yt.def,toolChoice:Qt.def}),Xt=we({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:null,choices:["base64"]}),eo=we({param:"input_type",title:"Input type",description:"Select the input type for the word embedding.",default:null,choices:["query","document"]}),to=Un({param:"truncation",title:"Truncation",description:"Select the truncation for the word embedding.",default:!0}),ri=()=>zod.z.object({encodingFormat:Xt.schema,inputType:eo.schema,truncation:to.schema}),li=()=>({encodingFormat:Xt.def,inputType:eo.def,truncation:to.def}),C={base:(t,o)=>({def:si(t,o),schema:ii(t,o)})},v={base:()=>({def:li(),schema:ri()})},L=zod.z.enum([J,E,w]),$={system:J,user:E,assistant:w},U=[y,R,k,A],B=zod.z.enum([y,R,k,A]),mi=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),di=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.record(zod.z.any())}),ci=zod.z.object({content:zod.z.array(zod.z.discriminatedUnion("type",[mi,di])),id:zod.z.string(),model:zod.z.string(),role:zod.z.string(),stop_reason:zod.z.string(),stop_sequence:zod.z.null(),type:zod.z.literal("message"),usage:zod.z.object({input_tokens:zod.z.number(),output_tokens:zod.z.number(),cache_creation_input_tokens:zod.z.number().nullish(),cache_read_input_tokens:zod.z.number().nullish()})}),pi=zod.z.object({type:zod.z.literal("message_start"),message:zod.z.object({id:zod.z.string(),type:zod.z.literal("message"),role:zod.z.string(),model:zod.z.string(),stop_reason:zod.z.string().nullable(),stop_sequence:zod.z.string().nullable(),content:zod.z.array(zod.z.any()),usage:zod.z.object({input_tokens:zod.z.number(),output_tokens:zod.z.number()})})}),ui=zod.z.object({type:zod.z.literal("message_delta"),delta:zod.z.object({stop_reason:zod.z.string().nullable(),stop_sequence:zod.z.string().nullable()}),usage:zod.z.object({output_tokens:zod.z.number()})}),hi=zod.z.object({type:zod.z.literal("text"),text:zod.z.string()}),gi=zod.z.object({type:zod.z.literal("tool_use"),id:zod.z.string(),name:zod.z.string(),input:zod.z.object({})}),fi=zod.z.object({type:zod.z.literal("content_block_start"),index:zod.z.number(),content_block:zod.z.discriminatedUnion("type",[hi,gi])}),yi=zod.z.object({type:zod.z.literal("text_delta"),text:zod.z.string()}),bi=zod.z.object({type:zod.z.literal("input_json_delta"),partial_json:zod.z.string()}),vi=zod.z.object({type:zod.z.literal("content_block_delta"),index:zod.z.number(),delta:zod.z.discriminatedUnion("type",[yi,bi])}),wi=zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),input_schema:zod.z.any()}),Ci=zod.z.object({type:zod.z.enum(["auto","any"])}),Ti=zod.z.object({type:zod.z.literal("tool"),name:zod.z.string().min(1)}),Ce=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),oo=zod.z.object({type:zod.z.literal("image"),source:zod.z.object({type:zod.z.literal("base64"),media_type:zod.z.enum(["image/jpeg","image/png","image/gif","image/webp"]),data:zod.z.string().base64()})});zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("tool_use"),name:zod.z.string().min(1),input:zod.z.record(zod.z.any())});var ao=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([Ce,oo])).min(1))}),xi=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ce,oo,ao])).min(1))}),ki=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ce,ao])).min(1))}),Si=zod.z.union([xi,ki]),ji=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Si).min(1),system:zod.z.string().min(1).optional(),max_tokens:zod.z.number().min(0).optional(),stop_sequences:zod.z.array(zod.z.string().min(1)).optional(),temperature:zod.z.number().min(0).max(1).optional(),tool_choice:zod.z.union([Ci,Ti]).optional(),tools:zod.z.array(wi).min(1).optional(),top_p:zod.z.number().min(0).max(1).optional(),top_k:zod.z.number().min(0).optional()}),Oi="anthropic",Q=class{constructor(){this.version="v1",this.name=Oi,this.chatModelFactories={[no]:{model:Pi,modelOptions:Mi,modelSchema:io},[so]:{model:Ri,modelOptions:_i,modelSchema:ro},[lo]:{model:qi,modelOptions:Ni,modelSchema:mo},[co]:{model:Ui,modelOptions:$i,modelSchema:po}},this.embeddingModelFactories={[xo]:{model:ss,modelOptions:is,modelSchema:ko},[Co]:{model:as,modelOptions:os,modelSchema:To},[uo]:{model:Vi,modelOptions:Hi,modelSchema:ho},[go]:{model:Gi,modelOptions:Ji,modelSchema:fo},[yo]:{model:Yi,modelOptions:Zi,modelSchema:bo},[vo]:{model:es,modelOptions:Xi,modelSchema:wo}};}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 dt({info:`Anthropic chat model: ${o} not found`,cause:new Error(`Anthropic chat model: ${o} not found, available chat models:
|
|
11
|
+
${this.chatModelLiterals().join(", ")}`)});let a=this.chatModelFactories[o].model,i=this.chatModelFactories[o].modelOptions.parse(t);return new a(i)}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 dt({info:`Anthropic embedding model: ${o} not found`,cause:new Error(`Anthropic embedding model: ${o} not found, available embedding models:
|
|
12
|
+
${this.embeddingModelLiterals().join(", ")}`)});let a=this.embeddingModelFactories[o].model,i=this.embeddingModelFactories[o].modelOptions.parse(t);return new a(i)}};Q.chatBaseUrl="https://api.anthropic.com/v1",Q.embeddingBaseUrl="https://api.anthropic.com/v1";var G=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional()}),F=class{constructor(t,o){this.version="v1";let a=G.parse(o);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=z(Q.chatBaseUrl),this.completeChatUrl=z(a.completeChatUrl||`${this.baseUrl}/messages`),this.streamChatUrl=z(a.streamChatUrl||`${this.baseUrl}/messages`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"x-api-key":`${this.apiKey}`,"anthropic-version":"2023-06-01","content-type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){let o=0,a=!0;return t["x-should-retry"]&&(a=t["x-should-retry"].toLowerCase()!=="false"),t["retry-after"]&&(o=parseInt(t["retry-after"])*1e3),{shouldRetry:a,delayMs:o}}getTokenCount(t){return t.reduce((o,a)=>o+a.content.map(i=>i.modality==="text"?i.value:"").join(" ").length,0)}transformModelRequest(t){let o=ji.safeParse(t);if(!o.success)throw new pe({info:"Invalid model request",cause:o.error});let a=o.data,i=a.model;if(a.tool_choice&&(!a.tools||a.tools.length===0))throw new pe({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let l={};a.tool_choice&&(a.tool_choice.type==="tool"?l.toolChoice=a.tool_choice.name:l.toolChoice=a.tool_choice.type),l.maxTokens=a.max_tokens,l.temperature=a.temperature,l.topP=a.top_p,l.topK=a.top_k,l.stop=a.stop_sequences;let s=Ot().parse(zt(l)),r=[],m={};a.system&&r.push({role:J,content:[{modality:y,value:a.system}]}),a.messages.forEach(p=>{let h=p.role;switch(h){case"user":{let g=p.content;if(typeof g=="string")r.push({role:h,content:[{modality:y,value:g}]});else {let T=g.map(u=>{if(u.type==="text")return {modality:y,value:u.text};if(u.type==="image"){let ie="auto",Z=u.source.media_type.split("/")[1];return {modality:R,detail:ie,value:{type:Ct,media_type:Z,base64:u.source.data}}}else return {modality:A,id:u.tool_use_id,index:m[u.tool_use_id].index,name:m[u.tool_use_id].name,data:typeof u.content=="string"?u.content:JSON.stringify(u.content)}});r.push({role:h,content:T});}}break;case"assistant":{let g=p.content;if(typeof g=="string")r.push({role:h,content:[{modality:y,value:g}]});else {let T=g.map((u,ie)=>{if(u.type==="text")return {modality:y,value:u.text};{let Z={modality:k,id:u.id,index:ie,name:u.name,arguments:JSON.stringify(u.input)};return m[u.id]=Z,Z}});r.push({role:h,content:T});}}break}});let c=[];return a.tools&&a.tools.forEach(p=>{c.push({type:"function",definition:{schema:{name:p.name,description:p.description||"",parameters:p.input_schema}}});}),{modelName:i,config:s,messages:r,tools:c.length>0?c:void 0}}transformConfig(t,o,a){let i=t.toolChoice;delete t.toolChoice;let l=this.modelSchema.config.schema.safeParse(t);if(!l.success)throw new O({info:`Invalid config for model : '${this.modelName}'`,cause:l.error});let s=l.data;i!==void 0&&(s.toolChoice=i),Object.keys(s).forEach(m=>{if(!(m in this.modelSchema.config.def))throw new O({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${m}',
|
|
13
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(s).reduce((m,c)=>{let p=this.modelSchema.config.def[c],h=p.param,g=s[c];return h==="max_tokens"&&p.type==="range"&&g===0?m[h]=p.max:m[h]=g,m},{});if(!r.max_tokens)throw new O({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`'max_tokens' is required for model : '${this.modelName}'`)});if("tool_choice"in r&&r.tool_choice!==void 0){let m=r.tool_choice;if(!a||a&&a.length===0)throw new O({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(a&&a.length>0){let c=this.modelSchema.config.def.toolChoice;if(c.choices.includes(m))r.tool_choice={type:m};else if(a.map(p=>p.definition.schema.name).includes(m))r.tool_choice={type:"tool",name:m};else throw new O({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${m}' is not part of provided 'tools' names or
|
|
14
|
+
one of [${c.choices.join(", ")}]`)})}}return r}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let o=t.map(s=>{let r=jt().safeParse(s);if(!r.success)throw new b({info:"Invalid messages",cause:r.error});return r.data});o.forEach(s=>{s.content.forEach(r=>{if(!this.modelSchema.modalities.includes(r.modality))throw new b({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${r.modality}',
|
|
15
|
+
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new b({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
|
|
16
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let a="",i=[];if(o.forEach(s=>{switch(s.role){case J:s.content.forEach(r=>{if(r.modality===y)a+=r.value;else throw new b({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${r.modality}'`)})});break;case w:{let r=[];s.content.forEach(m=>{if(m.modality===y)r.push({type:"text",text:m.value});else if(m.modality===k)r.push({type:"tool_use",id:m.id,name:m.name,input:JSON.parse(m.arguments)});else throw new b({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${m.modality}'`)})}),i.push({role:this.modelSchema.roles[s.role],content:r});}break;case E:{let r=[];s.content.forEach(m=>{if(m.modality===y)r.push({type:"text",text:m.value});else if(m.modality===R){if(m.value.type==="base64")r.push({type:"image",source:{type:"base64",media_type:`image/${m.value.media_type}`,data:m.value.base64}});else if(m.value.type==="url")throw new b({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${m.value.type}'`)})}else if(m.modality===A)r.push({type:"tool_result",tool_use_id:m.id,content:m.data});else throw new b({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${m.modality}'`)})}),i.push({role:this.modelSchema.roles[s.role],content:r});}break;default:throw new b({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
|
|
17
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[E])throw new b({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let l=s=>s===this.modelSchema.roles[E]?this.modelSchema.roles[w]:this.modelSchema.roles[E];for(let s=1;s<i.length;s++)if(i[s].role!==l(i[s-1].role))throw new b({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires messages to alternate between user and assistant`)});return {system:a,messages:i}}transformTools(t){if(!this.modelSchema.modalities.includes(k))throw new ft({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${k}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(o=>{let a=Tn().safeParse(o);if(!a.success)throw new ft({info:"Invalid tools",cause:a.error});return a.data}).map(o=>({name:o.definition.schema.name,description:o.definition.schema.description,input_schema:o.definition.schema.parameters}))}}getCompleteChatUrl(t,o,a){return j(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(t,o,a){return j(this,null,function*(){let i=this.getDefaultHeaders();return a&&a.length>0&&(i=tt(f({},i),{"anthropic-beta":"tools-2024-05-16"})),new Promise(l=>{l(i);})})}getCompleteChatData(t,o,a){return j(this,null,function*(){let i=this.transformConfig(t,o,a),l=this.transformMessages(o);if(l.messages&&l.messages.length===0)throw new b({info:"Messages are required",cause:new Error("Messages are required")});let s=a?this.transformTools(a):{};return new Promise(r=>{r(f(f(f(f({},this.getDefaultParams()),i),l),s));})})}transformCompleteChatResponse(t){let o=ci.safeParse(t);if(o.success){let a=o.data,i=a.content.map((r,m)=>{if(r.type==="text")return dn(r.text);if(r.type==="tool_use")return cn(m,r.id,r.name,JSON.stringify(r.input))}),l=[{role:w,content:i}],s={promptTokens:a.usage.input_tokens,completionTokens:a.usage.output_tokens,totalTokens:a.usage.input_tokens+a.usage.output_tokens};return {messages:l,usage:s,logProbs:[]}}throw new S({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(t,o,a){return j(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(t,o,a){let i=this.getDefaultHeaders();return a&&a.length>0&&(i=tt(f({},i),{"anthropic-beta":"tools-2024-05-16"})),new Promise(l=>{l(i);})}getStreamChatData(t,o,a){return j(this,null,function*(){let i=this.transformConfig(t,o,a),l=this.transformMessages(o);if(l.messages&&l.messages.length===0)throw new b({info:"Messages are required",cause:new Error("Messages are required")});let s=a?this.transformTools(a):{};return new Promise(r=>{r(f(f(f(f({stream:!0},this.getDefaultParams()),i),l),s));})})}transformStreamChatResponseChunk(t,o){return Da(this,null,function*(){let a=(o+t).split(`
|
|
18
|
+
`).filter(i=>i.trim()!=="");for(let i of a)if(i.startsWith("data: {")&&i.endsWith("}")){let l;try{l=JSON.parse(i.substring(6));}catch(s){throw new S({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${l}`)})}if("type"in l){if(l.type==="message_stop")return;if(l.type==="message_start"){let s=pi.safeParse(l);if(s.success){let r=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:r.message.usage.input_tokens,completionTokens:r.message.usage.output_tokens,totalTokens:r.message.usage.input_tokens+r.message.usage.output_tokens}},buffer:o};}else throw new S({info:"Invalid response from model",cause:s.error})}else if(l.type==="message_delta"){let s=ui.safeParse(l);if(s.success){let r=s.data;yield {partialResponse:{partialMessages:[],usage:{promptTokens:0,completionTokens:r.usage.output_tokens,totalTokens:r.usage.output_tokens}},buffer:o};}else throw new S({info:"Invalid response from model",cause:s.error})}else if(l.type==="content_block_start"){let s=fi.safeParse(l);if(s.success){let r=s.data,m=[];r.content_block.type==="text"?m.push(ot(w,r.content_block.text)):r.content_block.type==="tool_use"&&m.push(at(w,r.index,r.content_block.id,r.content_block.name,"")),yield {partialResponse:{partialMessages:m},buffer:o};}else throw new S({info:"Invalid response from model",cause:s.error})}else if(l.type==="content_block_delta"){let s=vi.safeParse(l);if(s.success){let r=s.data,m=[];r.delta.type==="text_delta"?m.push(ot(w,r.delta.text)):r.delta.type==="input_json_delta"&&m.push(at(w,r.index,"","",r.delta.partial_json)),yield {partialResponse:{partialMessages:m},buffer:o};}else throw new S({info:"Invalid response from model",cause:s.error})}}else throw new S({info:"Invalid JSON received in stream",cause:new Error(`Invalid JSON received in stream, expected 'type' property,
|
|
19
|
+
received : ${JSON.stringify(l)}`)})}})}},no="claude-3-haiku-20240307",Ei="Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance.",io=te(L,B).parse({name:no,description:Ei,maxInputTokens:2e5,maxOutputTokens:4096,roles:$,modalities:U,config:{def:C.base(4096,4).def,schema:C.base(4096,4).schema}}),Mi=G,Pi=class extends F{constructor(t){super(io,t);}},so="claude-3-sonnet-20240229",Ii="Balance of intelligence and speed. Strong utility, balanced for scaled deployments.",ro=te(L,B).parse({name:so,description:Ii,maxInputTokens:2e5,maxOutputTokens:4096,roles:$,modalities:U,config:{def:C.base(4096,4).def,schema:C.base(4096,4).schema}}),_i=G,Ri=class extends F{constructor(t){super(ro,t);}},lo="claude-3-opus-20240229",Ai="Powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding.",mo=te(L,B).parse({name:lo,description:Ai,maxInputTokens:2e5,maxOutputTokens:4096,roles:$,modalities:U,config:{def:C.base(4096,4).def,schema:C.base(4096,4).schema}}),Ni=G,qi=class extends F{constructor(t){super(mo,t);}},co="claude-3-5-sonnet-20240620",Li="Most intelligent model. Highest level of intelligence and capability.",po=te(L,B).parse({name:co,description:Li,maxInputTokens:2e5,maxOutputTokens:8192,roles:$,modalities:U,config:{def:C.base(8192,4).def,schema:C.base(8192,4).schema}}),$i=G,Ui=class extends F{constructor(t){super(po,t);}},D=[N],K=zod.z.enum([N]),Bi=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()})}),Fi=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),Di=zod.z.object({model:zod.z.string().min(1).optional(),input:Fi,encoding_format:zod.z.enum(["base64"]).nullable().optional(),input_type:zod.z.enum(["query","document"]).nullable().optional(),truncation:zod.z.boolean().optional()}),P=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),getEmbeddingsUrl:zod.z.string().url().optional()}),H=class{constructor(t,o){this.version="v1";let a=P.parse(o);this.modelSchema=t,this.modelName=a.modelName,this.apiKey=a.apiKey,this.baseUrl=z(Q.embeddingBaseUrl),this.getEmbeddingsUrl=z(a.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getTokenCount(t){return t.requests.reduce((o,a)=>o+a.length,0)}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}transformModelRequest(t){let o=Di.safeParse(t);if(!o.success)throw new pe({info:"Invalid model request",cause:o.error});let a=o.data,i=a.model,l={encodingFormat:a.encoding_format,inputType:a.input_type,truncation:a.truncation},s=Ot().parse(zt(l)),r;return typeof a.input=="string"?r={modality:N,requests:[a.input]}:r={modality:N,requests:a.input},{modelName:i,config:s,embeddingRequests:r}}transformConfig(t,o){let a=this.modelSchema.config.schema.safeParse(t);if(!a.success)throw new O({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let i=a.data;return Object.keys(i).forEach(l=>{if(!this.modelSchema.config.def[l])throw new O({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${l}',
|
|
20
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((l,s)=>{let r=this.modelSchema.config.def[s].param,m=i[s];return l[r]=m,l},{})}transformEmbeddingRequests(t){let o=On().safeParse(t);if(!o.success)throw new bt({info:"Invalid embedding requests",cause:o.error});if(o.data.requests.length>128)throw new bt({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Max requests for model : '${this.modelName}' is 128`)});return {input:o.data.requests}}getGetEmbeddingsUrl(t,o){return j(this,null,function*(){return new Promise(a=>{a(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,o){return j(this,null,function*(){return new Promise(a=>{a(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,o){return j(this,null,function*(){return new Promise(a=>{a(f(f(f({},this.getDefaultParams()),this.transformConfig(t,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(t){let o,a=Bi.safeParse(t);if(a.success){let i=a.data;o=typeof i.data[0].embedding=="string"?Pt:Mt;let l=i.data.map(s=>typeof s.embedding=="string"?{index:s.index,embedding:s.embedding}:{index:s.index,embedding:s.embedding});return {encodingFormat:o,embeddings:l,usage:{totalTokens:i.usage.total_tokens}}}throw new S({info:"Invalid response from model",cause:a.error})}},uo="voyage-code-2",Ki="Optimized for code retrieval.",ho=q(K).parse({name:uo,description:Ki,modalities:D,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:v.base().def,schema:v.base().schema}}),Hi=P,Vi=class extends H{constructor(t){super(ho,t);}},go="voyage-law-2",zi="Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains.",fo=q(K).parse({name:go,description:zi,modalities:D,maxInputTokens:16e3,maxOutputTokens:16e3,config:{def:v.base().def,schema:v.base().schema}}),Ji=P,Gi=class extends H{constructor(t){super(fo,t);}},yo="voyage-multilingual-2",Wi="Optimized for multilingual retrieval and RAG.",bo=q(K).parse({name:yo,description:Wi,modalities:D,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:v.base().def,schema:v.base().schema}}),Zi=P,Yi=class extends H{constructor(t){super(bo,t);}},vo="voyage-finance-2",Qi="Optimized for finance retrieval and RAG.",wo=q(K).parse({name:vo,description:Qi,modalities:D,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:v.base().def,schema:v.base().schema}}),Xi=P,es=class extends H{constructor(t){super(wo,t);}},Co="voyage-3-lite",ts="Optimized for latency and cost.",To=q(K).parse({name:Co,description:ts,modalities:D,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:v.base().def,schema:v.base().schema}}),os=P,as=class extends H{constructor(t){super(To,t);}},xo="voyage-3",ns="Optimized for quality.",ko=q(K).parse({name:xo,description:ns,modalities:D,maxInputTokens:32e3,maxOutputTokens:32e3,config:{def:v.base().def,schema:v.base().schema}}),is=P,ss=class extends H{constructor(t){super(ko,t);}};var oe=zod.z.object({modelName:zod.z.string(),awsRegion:zod.z.string(),awsAccessKeyId:zod.z.string(),awsSecretAccessKey:zod.z.string()});var ae=class t extends F{constructor(a,i){let l=oe.parse(i);super(a,{apiKey:"random-api-key",modelName:l.modelName});this.version="v1";this.modelSchema=a,this.modelName=l.modelName,this.awsRegion=l.awsRegion,this.awsUrl=I.awsUrl(this.awsRegion),this.awsService=I.awsService,this.awsAccessKeyId=l.awsAccessKeyId,this.awsSecretAccessKey=l.awsSecretAccessKey;}getDefaultBaseUrl(){return this.awsUrl}getDefaultHeaders(){return {Accept:"application/json","Content-Type":"application/json",host:this.awsUrl.split("://")[1]}}getDefaultParams(){return {anthropic_version:"bedrock-2023-05-31"}}getCompleteChatUrl(a,i,l){return new Promise(s=>{s(`${this.awsUrl}/model/${this.modelName}/invoke`);})}getCompleteChatHeaders(a,i,l){return _(this,null,function*(){let s=new URL(yield this.getCompleteChatUrl(a,i,l)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},m=this.getDefaultHeaders(),c=this.getCompleteChatData(a||{},i||[],l),p=new protocolHttp.HttpRequest({hostname:s.hostname,path:s.pathname,protocol:s.protocol,method:"POST",body:JSON.stringify(c),headers:m});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:this.awsRegion,sha256:sha256Js.Sha256}).sign(p)).headers})}getCompleteChatData(a,i,l){return _(this,null,function*(){let s=V(V({},this.getDefaultParams()),Y(t.prototype,this,"getCompleteChatData").call(this,a,i,l));return new Promise(r=>{r(s);})})}getStreamChatUrl(a,i,l){return _(this,null,function*(){return new Promise(s=>{s(`${this.awsUrl}/model/${this.modelName}/invoke-with-response-stream`);})})}getStreamChatHeaders(a,i,l){return _(this,null,function*(){let s=new URL(yield this.getStreamChatUrl(a,i,l)),r={accessKeyId:this.awsAccessKeyId,secretAccessKey:this.awsSecretAccessKey},m=this.getDefaultHeaders(),c=this.getCompleteChatData(a||{},i||[],l),p=new protocolHttp.HttpRequest({hostname:s.hostname,path:s.pathname,protocol:s.protocol,method:"POST",body:JSON.stringify(c),headers:m});return (yield new signatureV4.SignatureV4({credentials:r,service:this.awsService,region:this.awsRegion,sha256:sha256Js.Sha256}).sign(p)).headers})}getStreamChatData(a,i,l){return _(this,null,function*(){let s=V(V({},this.getDefaultParams()),Y(t.prototype,this,"getStreamChatData").call(this,a,i,l));return "stream"in s&&delete s.stream,s})}transformStreamChatResponseChunk(a,i){return je(this,null,function*(){let l=a.toString(),s=/{\s*"bytes"\s*:\s*"[\w=+/]+".*?}/g,r=l.match(s)||[];for(let m of r){let c=m.indexOf("{"),p=m.indexOf("}");if(c!==-1&&p!==-1&&c<p){let h;try{h=JSON.parse(m.slice(c,p+1));}catch(u){throw new He({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${h}`)})}let g=Qe(h.bytes),T=(yield new se(Y(t.prototype,this,"transformStreamChatResponseChunk").call(this,`data: ${g}`,i).next())).value;T&&(yield T);}}})}};var Te="anthropic.claude-3-haiku-20240307-v1:0",rs="Claude 3 Haiku is a large-scale multimodal model trained by Anthropic. It is the successor to Claude 3 and is designed to be more powerful and capable than its predecessor.",xe=Ye(L,B).parse({name:Te,description:rs,maxInputTokens:128e3,maxOutputTokens:128e3,roles:$,modalities:U,config:{def:C.base(128e3,4).def,schema:C.base(128e3,4).schema}}),Eo=oe,ne=class extends ae{constructor(o){super(xe,o);}};var ls="bedrock",I=class{constructor(){this.version="v1";this.name=ls;this.chatModelFactories={[Te]:{model:ne,modelOptions:Eo,modelSchema:xe}};this.embeddingModelFactories={};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((o,a)=>(o[a]=this.chatModelFactories[a].modelSchema,o),{})}chatModel(o){let a=o.modelName;if(!(a in this.chatModelFactories))throw new de({info:`Bedrock chat model: ${a} not found`,cause:new Error(`Bedrock chat model: ${a} not found, available chat models:
|
|
21
|
+
${this.chatModelLiterals().join(", ")}`)});let i=this.chatModelFactories[a].model,l=this.chatModelFactories[a].modelOptions.parse(o);return new i(l)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((o,a)=>(o[a]=this.embeddingModelFactories[a].modelSchema,o),{})}embeddingModel(o){throw new de({info:"Adaline Bedrock provider does not support embedding models yet",cause:new Error("Adaline Bedrock provider does not support embedding models yet")})}};I.awsService="bedrock",I.awsUrl=o=>`https://bedrock.${o}.amazonaws.com`;
|
|
23
22
|
|
|
24
|
-
exports.BaseChatModelAnthropic =
|
|
25
|
-
exports.
|
|
26
|
-
exports.Bedrock =
|
|
27
|
-
exports.BedrockClaude3Haiku20240307 =
|
|
23
|
+
exports.BaseChatModelAnthropic = ae;
|
|
24
|
+
exports.BaseChatModelOptions = oe;
|
|
25
|
+
exports.Bedrock = I;
|
|
26
|
+
exports.BedrockClaude3Haiku20240307 = ne;
|
|
27
|
+
exports.BedrockClaude3Haiku20240307Literal = Te;
|
|
28
28
|
exports.BedrockClaude3Haiku20240307Options = Eo;
|
|
29
|
-
exports.BedrockClaude3Haiku20240307Schema =
|
|
29
|
+
exports.BedrockClaude3Haiku20240307Schema = xe;
|
|
30
30
|
//# sourceMappingURL=index.js.map
|
|
31
31
|
//# sourceMappingURL=index.js.map
|