@wabot-dev/framework 0.1.0-beta.39 → 0.1.0-beta.40
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/src/addon/chat-bot/{claude/ClaudeChatAdapter.js → anthropic/AnthropicChatAdapter.js}
RENAMED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Logger } from '../../../core/logger/Logger.js';
|
|
2
2
|
import { Anthropic } from '@anthropic-ai/sdk';
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class AnthropicChatAdapter {
|
|
5
|
+
env;
|
|
5
6
|
anthropic;
|
|
6
|
-
logger = new Logger('wabot:
|
|
7
|
-
constructor() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
throw new Error('CLAUDE_API_KEY env variable is required');
|
|
11
|
-
}
|
|
7
|
+
logger = new Logger('wabot:anthropic-chat-adapter');
|
|
8
|
+
constructor(env) {
|
|
9
|
+
this.env = env;
|
|
10
|
+
const apiKey = this.env.requireString('ANTHROPIC_API_KEY');
|
|
12
11
|
this.anthropic = new Anthropic({ apiKey });
|
|
13
12
|
}
|
|
14
13
|
async nextItem(req) {
|
|
@@ -126,4 +125,4 @@ class ClaudeChatAdapter {
|
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
|
|
129
|
-
export {
|
|
128
|
+
export { AnthropicChatAdapter };
|
|
@@ -1,35 +1,19 @@
|
|
|
1
1
|
import { Logger } from '../../../core/logger/Logger.js';
|
|
2
2
|
import { GoogleGenAI } from '@google/genai';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
'gemini-1.5-flash',
|
|
7
|
-
'gemini-1.5-pro',
|
|
8
|
-
'gemini-pro',
|
|
9
|
-
];
|
|
10
|
-
const DEFAULT_MODEL = 'gemini-1.5-flash';
|
|
11
|
-
class GeminiChatAdapter {
|
|
4
|
+
class GoogleChatAdapter {
|
|
5
|
+
env;
|
|
12
6
|
genai;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const apiKey =
|
|
17
|
-
if (!apiKey) {
|
|
18
|
-
throw new Error('GEMINI_API_KEY env variable is required');
|
|
19
|
-
}
|
|
20
|
-
this.model = process.env.GEMINI_MODEL || DEFAULT_MODEL;
|
|
21
|
-
this.validateModel(this.model);
|
|
7
|
+
logger = new Logger('wabot:google-chat-adapter');
|
|
8
|
+
constructor(env) {
|
|
9
|
+
this.env = env;
|
|
10
|
+
const apiKey = this.env.requireString('GOOGLE_API_KEY');
|
|
22
11
|
this.genai = new GoogleGenAI({ apiKey });
|
|
23
12
|
}
|
|
24
|
-
validateModel(model) {
|
|
25
|
-
if (!SUPPORTED_MODELS.includes(model)) {
|
|
26
|
-
throw new Error(`Unsupported Gemini model: ${model}. Supported models: ${SUPPORTED_MODELS.join(', ')}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
13
|
async nextItem(req) {
|
|
30
14
|
const contents = this.buildContents(req.prevItems, req.systemPrompt);
|
|
31
15
|
const tools = req.tools.length > 0 ? req.tools.map(this.mapTool) : undefined;
|
|
32
|
-
const request = { model:
|
|
16
|
+
const request = { model: req.model, contents, tools };
|
|
33
17
|
this.logger.debug(`Call Gemini API with Request: ${JSON.stringify(request)}`);
|
|
34
18
|
const response = await this.genai.models.generateContent(request);
|
|
35
19
|
return this.mapResponse(response);
|
|
@@ -39,7 +23,7 @@ class GeminiChatAdapter {
|
|
|
39
23
|
if (systemPrompt) {
|
|
40
24
|
contents.push({ role: 'user', parts: [{ text: systemPrompt }] }, { role: 'model', parts: [{ text: 'I understand. I will follow these instructions.' }] });
|
|
41
25
|
}
|
|
42
|
-
chatItems.forEach(chatItem => {
|
|
26
|
+
chatItems.forEach((chatItem) => {
|
|
43
27
|
switch (chatItem.type) {
|
|
44
28
|
case 'humanMessage':
|
|
45
29
|
this.validateMessageContent(chatItem.humanMessage.text, 'User');
|
|
@@ -70,20 +54,29 @@ class GeminiChatAdapter {
|
|
|
70
54
|
},
|
|
71
55
|
{
|
|
72
56
|
role: 'user',
|
|
73
|
-
parts: [
|
|
57
|
+
parts: [
|
|
58
|
+
{
|
|
59
|
+
functionResponse: { name: item.name, response: { result: item.result || 'No result' } },
|
|
60
|
+
},
|
|
61
|
+
],
|
|
74
62
|
},
|
|
75
63
|
];
|
|
76
64
|
}
|
|
77
65
|
mapTool = (tool) => ({
|
|
78
|
-
functionDeclarations: [
|
|
66
|
+
functionDeclarations: [
|
|
67
|
+
{
|
|
79
68
|
name: tool.name,
|
|
80
69
|
description: tool.description,
|
|
81
70
|
parameters: {
|
|
82
71
|
type: 'object',
|
|
83
|
-
properties: tool.parameters.reduce((acc, param) => ({
|
|
84
|
-
|
|
72
|
+
properties: tool.parameters.reduce((acc, param) => ({
|
|
73
|
+
...acc,
|
|
74
|
+
[param.name]: { type: param.type, description: param.description },
|
|
75
|
+
}), {}),
|
|
76
|
+
required: tool.parameters.map((param) => param.name),
|
|
85
77
|
},
|
|
86
|
-
}
|
|
78
|
+
},
|
|
79
|
+
],
|
|
87
80
|
});
|
|
88
81
|
mapResponse(response) {
|
|
89
82
|
this.validateResponse(response);
|
|
@@ -99,7 +92,9 @@ class GeminiChatAdapter {
|
|
|
99
92
|
arguments: JSON.stringify(part.functionCall.args || {}),
|
|
100
93
|
},
|
|
101
94
|
}
|
|
102
|
-
: (() => {
|
|
95
|
+
: (() => {
|
|
96
|
+
throw new Error('Not supported Gemini Response');
|
|
97
|
+
})();
|
|
103
98
|
const usage = {
|
|
104
99
|
inputTokens: response.response.usageMetadata?.promptTokenCount || 0,
|
|
105
100
|
outputTokens: response.response.usageMetadata?.candidatesTokenCount || 0,
|
|
@@ -122,4 +117,4 @@ class GeminiChatAdapter {
|
|
|
122
117
|
}
|
|
123
118
|
}
|
|
124
119
|
|
|
125
|
-
export {
|
|
120
|
+
export { GoogleChatAdapter };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -829,10 +829,11 @@ declare class PgJobRepository extends PgCrudRepository<Job> implements IJobRepos
|
|
|
829
829
|
constructor(pool: Pool);
|
|
830
830
|
}
|
|
831
831
|
|
|
832
|
-
declare class
|
|
832
|
+
declare class AnthropicChatAdapter implements IChatAdapter {
|
|
833
|
+
private env;
|
|
833
834
|
private anthropic;
|
|
834
835
|
private logger;
|
|
835
|
-
constructor();
|
|
836
|
+
constructor(env: Env);
|
|
836
837
|
nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
|
|
837
838
|
private mapChatItems;
|
|
838
839
|
private mapHumanMessage;
|
|
@@ -855,12 +856,11 @@ declare class DeepSeekChatAdapter implements IChatAdapter {
|
|
|
855
856
|
private mapResponse;
|
|
856
857
|
}
|
|
857
858
|
|
|
858
|
-
declare class
|
|
859
|
+
declare class GoogleChatAdapter implements IChatAdapter {
|
|
860
|
+
private env;
|
|
859
861
|
private genai;
|
|
860
|
-
private model;
|
|
861
862
|
private logger;
|
|
862
|
-
constructor();
|
|
863
|
-
private validateModel;
|
|
863
|
+
constructor(env: Env);
|
|
864
864
|
nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
|
|
865
865
|
private buildContents;
|
|
866
866
|
private validateMessageContent;
|
|
@@ -1334,4 +1334,4 @@ declare class MoneyDto {
|
|
|
1334
1334
|
currency: string;
|
|
1335
1335
|
}
|
|
1336
1336
|
|
|
1337
|
-
export { Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver,
|
|
1337
|
+
export { AnthropicChatAdapter, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, HtmlModule, HttpServerProvider, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatAdapterNextItemRes, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenaiChatAdapter, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, get, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, param, post, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, scoped, singleton, socket, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
|
package/dist/src/index.js
CHANGED
|
@@ -61,9 +61,9 @@ export { EXPRESS_REQ, EXPRESS_RES } from './feature/rest-controller/injection-to
|
|
|
61
61
|
export { SocketServerProvider } from './feature/socket/SocketServerProvider.js';
|
|
62
62
|
export { Money } from './feature/money/Money.js';
|
|
63
63
|
export { PgJobRepository } from './addon/async/pg/PgJobRepository.js';
|
|
64
|
-
export {
|
|
64
|
+
export { AnthropicChatAdapter } from './addon/chat-bot/anthropic/AnthropicChatAdapter.js';
|
|
65
65
|
export { DeepSeekChatAdapter } from './addon/chat-bot/deepseek/DeepSeekChatAdapter.js';
|
|
66
|
-
export {
|
|
66
|
+
export { GoogleChatAdapter } from './addon/chat-bot/google/GoogleChatAdapter.js';
|
|
67
67
|
export { OpenaiChatAdapter } from './addon/chat-bot/openia/OpenaiChatAdapter.js';
|
|
68
68
|
export { PgChatRepository } from './addon/chat-bot/pg/PgChatRepository.js';
|
|
69
69
|
export { PgChatMemory } from './addon/chat-bot/pg/PgChatMemory.js';
|