@wabot-dev/framework 0.2.0-beta.14 → 0.2.0-beta.15
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/anthropic/AnthropicChatAdapter.js +2 -2
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +2 -2
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +2 -2
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +43 -19
- package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +1 -1
- package/dist/src/feature/chat-bot/ChatAdapter.js +1 -1
- package/dist/src/feature/chat-bot/ChatBot.js +14 -10
- package/dist/src/index.d.ts +12 -12
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ let AnthropicChatAdapter = class AnthropicChatAdapter {
|
|
|
13
13
|
const apiKey = this.env.requireString('ANTHROPIC_API_KEY');
|
|
14
14
|
this.anthropic = new Anthropic({ apiKey });
|
|
15
15
|
}
|
|
16
|
-
async
|
|
16
|
+
async nextItems(req) {
|
|
17
17
|
const tools = req.tools.map((x) => this.mapTool(x));
|
|
18
18
|
const messages = this.mapChatItems(req.prevItems);
|
|
19
19
|
const request = {
|
|
@@ -124,7 +124,7 @@ let AnthropicChatAdapter = class AnthropicChatAdapter {
|
|
|
124
124
|
else {
|
|
125
125
|
throw new Error('Unable to found usage info');
|
|
126
126
|
}
|
|
127
|
-
return { chatItem, usage };
|
|
127
|
+
return { nextItems: [chatItem], usage };
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
AnthropicChatAdapter = __decorate([
|
|
@@ -18,7 +18,7 @@ class DeepSeekChatAdapter {
|
|
|
18
18
|
baseURL,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
async
|
|
21
|
+
async nextItems(req) {
|
|
22
22
|
const deepSeekInput = [];
|
|
23
23
|
deepSeekInput.push({ role: 'system', content: req.systemPrompt });
|
|
24
24
|
deepSeekInput.push(...this.mapChatItems(req.prevItems));
|
|
@@ -130,7 +130,7 @@ class DeepSeekChatAdapter {
|
|
|
130
130
|
else {
|
|
131
131
|
throw new Error('Unable to found usage info');
|
|
132
132
|
}
|
|
133
|
-
return { chatItem, usage };
|
|
133
|
+
return { nextItems: [chatItem], usage };
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -16,7 +16,7 @@ let GoogleChatAdapter = class GoogleChatAdapter {
|
|
|
16
16
|
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
async
|
|
19
|
+
async nextItems(req) {
|
|
20
20
|
const messages = [];
|
|
21
21
|
messages.push({ role: 'system', content: req.systemPrompt });
|
|
22
22
|
messages.push(...this.mapChatItems(req.prevItems));
|
|
@@ -117,7 +117,7 @@ let GoogleChatAdapter = class GoogleChatAdapter {
|
|
|
117
117
|
else {
|
|
118
118
|
throw new Error('Unable to found usage info');
|
|
119
119
|
}
|
|
120
|
-
return { chatItem, usage };
|
|
120
|
+
return { nextItems: [chatItem], usage };
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
123
|
GoogleChatAdapter = __decorate([
|
|
@@ -6,7 +6,7 @@ import { singleton } from '../../../core/injection/index.js';
|
|
|
6
6
|
let OpenaiChatAdapter = class OpenaiChatAdapter {
|
|
7
7
|
openai = new OpenAI();
|
|
8
8
|
logger = new Logger('wabot:openai-chat-adapter');
|
|
9
|
-
async
|
|
9
|
+
async nextItems(req) {
|
|
10
10
|
const openIaInput = [];
|
|
11
11
|
openIaInput.push({ role: 'system', content: req.systemPrompt });
|
|
12
12
|
openIaInput.push(...this.mapChatItems(req.prevItems));
|
|
@@ -80,23 +80,6 @@ let OpenaiChatAdapter = class OpenaiChatAdapter {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
mapResponse(response) {
|
|
83
|
-
let chatItem;
|
|
84
|
-
if (response.output_text) {
|
|
85
|
-
chatItem = { type: 'botMessage', botMessage: { text: response.output_text } };
|
|
86
|
-
}
|
|
87
|
-
else if (response.output && response.output[0]?.type == 'function_call') {
|
|
88
|
-
chatItem = {
|
|
89
|
-
type: 'functionCall',
|
|
90
|
-
functionCall: {
|
|
91
|
-
id: response.output[0].call_id,
|
|
92
|
-
name: response.output[0].name,
|
|
93
|
-
arguments: response.output[0].arguments,
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
throw new Error('Not supported OpenIA Response');
|
|
99
|
-
}
|
|
100
83
|
let usage;
|
|
101
84
|
if (response.usage) {
|
|
102
85
|
usage = {
|
|
@@ -107,7 +90,48 @@ let OpenaiChatAdapter = class OpenaiChatAdapter {
|
|
|
107
90
|
else {
|
|
108
91
|
throw new Error('Unable to found usage info');
|
|
109
92
|
}
|
|
110
|
-
|
|
93
|
+
const nextItems = [];
|
|
94
|
+
for (const output of response.output) {
|
|
95
|
+
if (output.type === 'message') {
|
|
96
|
+
for (const content of output.content) {
|
|
97
|
+
if (content.type === 'output_text' && content.text) {
|
|
98
|
+
nextItems.push({ type: 'botMessage', botMessage: { text: content.text } });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (output.type === 'function_call') {
|
|
103
|
+
nextItems.push({
|
|
104
|
+
type: 'functionCall',
|
|
105
|
+
functionCall: { id: output.call_id, name: output.name, arguments: output.arguments },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return { usage, nextItems };
|
|
110
|
+
// let chatItem: IChatItem
|
|
111
|
+
// if (response.output_text) {
|
|
112
|
+
// chatItem = { type: 'botMessage', botMessage: { text: response.output_text } }
|
|
113
|
+
// } else if (response.output && response.output[0]?.type == 'function_call') {
|
|
114
|
+
// chatItem = {
|
|
115
|
+
// type: 'functionCall',
|
|
116
|
+
// functionCall: {
|
|
117
|
+
// id: response.output[0].call_id,
|
|
118
|
+
// name: response.output[0].name,
|
|
119
|
+
// arguments: response.output[0].arguments,
|
|
120
|
+
// },
|
|
121
|
+
// }
|
|
122
|
+
// } else {
|
|
123
|
+
// throw new Error('Not supported OpenIA Response')
|
|
124
|
+
// }
|
|
125
|
+
// let usage: ILanguageModelUsage
|
|
126
|
+
// if (response.usage) {
|
|
127
|
+
// usage = {
|
|
128
|
+
// inputTokens: response.usage.input_tokens,
|
|
129
|
+
// outputTokens: response.usage.output_tokens,
|
|
130
|
+
// }
|
|
131
|
+
// } else {
|
|
132
|
+
// throw new Error('Unable to found usage info')
|
|
133
|
+
// }
|
|
134
|
+
// return { chatItem, usage }
|
|
111
135
|
}
|
|
112
136
|
};
|
|
113
137
|
OpenaiChatAdapter = __decorate([
|
|
@@ -15,7 +15,7 @@ let WabotChatAdapter = class WabotChatAdapter {
|
|
|
15
15
|
this.baseUrl = this.baseUrl.substring(0, this.baseUrl.length - 1);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
async
|
|
18
|
+
async nextItems(req) {
|
|
19
19
|
const response = await fetch(this.baseUrl + '/chat-bot/next-item', {
|
|
20
20
|
method: 'post',
|
|
21
21
|
headers: {
|
|
@@ -41,23 +41,27 @@ let ChatBot = class ChatBot {
|
|
|
41
41
|
throw new Error(`Invalid ${this.mindset.constructor.name} - llms not found`);
|
|
42
42
|
}
|
|
43
43
|
const llm = llms[0];
|
|
44
|
-
const {
|
|
44
|
+
const { nextItems: newItemsData } = await this.adapter.nextItems({
|
|
45
45
|
model: llm.model,
|
|
46
46
|
provider: llm.provider,
|
|
47
47
|
systemPrompt,
|
|
48
48
|
tools,
|
|
49
49
|
prevItems: prevItems.map((x) => x.getData()),
|
|
50
50
|
});
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
for (const newItemData of newItemsData) {
|
|
52
|
+
if (newItemData.type === 'functionCall') {
|
|
53
|
+
newItemData.functionCall.result = await this.mindset.callFunction(newItemData.functionCall.name, newItemData.functionCall.arguments ?? '{}');
|
|
54
|
+
}
|
|
55
|
+
else if (newItemData.type === 'botMessage') {
|
|
56
|
+
newItemData.botMessage.senderName = identity.name;
|
|
57
|
+
}
|
|
58
|
+
const newChatItem = new ChatItem(newItemData);
|
|
59
|
+
await this.memory.create(newChatItem);
|
|
60
|
+
if (newItemData.type === 'botMessage') {
|
|
61
|
+
callback(newChatItem.botMessage);
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
|
-
|
|
55
|
-
newItemData.botMessage.senderName = identity.name;
|
|
56
|
-
}
|
|
57
|
-
const newChatItem = new ChatItem(newItemData);
|
|
58
|
-
await this.memory.create(newChatItem);
|
|
59
|
-
if (newChatItem.type === 'botMessage') {
|
|
60
|
-
callback(newChatItem.botMessage);
|
|
64
|
+
if (newItemsData.length == 0 || newItemsData[newItemsData.length - 1].type === 'botMessage') {
|
|
61
65
|
return;
|
|
62
66
|
}
|
|
63
67
|
this.processLoop(callback);
|
package/dist/src/index.d.ts
CHANGED
|
@@ -615,24 +615,24 @@ interface ILanguageModelUsage {
|
|
|
615
615
|
outputTokens: number;
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
-
interface
|
|
618
|
+
interface IChatAdapterNextItemsReq {
|
|
619
619
|
model: string;
|
|
620
620
|
systemPrompt: string;
|
|
621
621
|
tools: IMindsetTool[];
|
|
622
622
|
prevItems: IChatItem[];
|
|
623
623
|
}
|
|
624
|
-
interface
|
|
625
|
-
|
|
624
|
+
interface IChatAdapterNextItemsRes {
|
|
625
|
+
nextItems: IChatItem[];
|
|
626
626
|
usage: ILanguageModelUsage;
|
|
627
627
|
}
|
|
628
628
|
interface IChatAdapter {
|
|
629
|
-
|
|
629
|
+
nextItems(req: IChatAdapterNextItemsReq): Promise<IChatAdapterNextItemsRes>;
|
|
630
630
|
}
|
|
631
631
|
|
|
632
632
|
declare class ChatAdapter implements IChatAdapter {
|
|
633
|
-
|
|
633
|
+
nextItems(req: IChatAdapterNextItemsReq & {
|
|
634
634
|
provider?: string;
|
|
635
|
-
}): Promise<
|
|
635
|
+
}): Promise<IChatAdapterNextItemsRes>;
|
|
636
636
|
}
|
|
637
637
|
|
|
638
638
|
type IChatItemData = IEntityData & IChatItem;
|
|
@@ -1175,7 +1175,7 @@ declare class AnthropicChatAdapter implements IChatAdapter {
|
|
|
1175
1175
|
private anthropic;
|
|
1176
1176
|
private logger;
|
|
1177
1177
|
constructor(env: Env);
|
|
1178
|
-
|
|
1178
|
+
nextItems(req: IChatAdapterNextItemsReq): Promise<IChatAdapterNextItemsRes>;
|
|
1179
1179
|
private mapChatItems;
|
|
1180
1180
|
private mapHumanMessage;
|
|
1181
1181
|
private mapBotMessage;
|
|
@@ -1188,7 +1188,7 @@ declare class DeepSeekChatAdapter implements IChatAdapter {
|
|
|
1188
1188
|
private deepSeek;
|
|
1189
1189
|
private logger;
|
|
1190
1190
|
constructor();
|
|
1191
|
-
|
|
1191
|
+
nextItems(req: IChatAdapterNextItemsReq): Promise<IChatAdapterNextItemsRes>;
|
|
1192
1192
|
private mapChatItems;
|
|
1193
1193
|
private mapHumanMessage;
|
|
1194
1194
|
private mapBotMessage;
|
|
@@ -1202,7 +1202,7 @@ declare class GoogleChatAdapter implements IChatAdapter {
|
|
|
1202
1202
|
private openai;
|
|
1203
1203
|
private logger;
|
|
1204
1204
|
constructor(env: Env);
|
|
1205
|
-
|
|
1205
|
+
nextItems(req: IChatAdapterNextItemsReq): Promise<IChatAdapterNextItemsRes>;
|
|
1206
1206
|
private mapChatItems;
|
|
1207
1207
|
private mapHumanMessage;
|
|
1208
1208
|
private mapBotMessage;
|
|
@@ -1214,7 +1214,7 @@ declare class GoogleChatAdapter implements IChatAdapter {
|
|
|
1214
1214
|
declare class OpenaiChatAdapter implements IChatAdapter {
|
|
1215
1215
|
private openai;
|
|
1216
1216
|
private logger;
|
|
1217
|
-
|
|
1217
|
+
nextItems(req: IChatAdapterNextItemsReq): Promise<IChatAdapterNextItemsRes>;
|
|
1218
1218
|
private mapChatItems;
|
|
1219
1219
|
private mapConectionMessage;
|
|
1220
1220
|
private mapBotMessage;
|
|
@@ -1256,7 +1256,7 @@ declare class WabotChatAdapter implements IChatAdapter {
|
|
|
1256
1256
|
private baseUrl;
|
|
1257
1257
|
private logger;
|
|
1258
1258
|
constructor(env: Env);
|
|
1259
|
-
|
|
1259
|
+
nextItems(req: IChatAdapterNextItemsReq): Promise<IChatAdapterNextItemsRes>;
|
|
1260
1260
|
}
|
|
1261
1261
|
|
|
1262
1262
|
declare function cmd(): (target: object, propertyKey: string | symbol) => void;
|
|
@@ -1623,4 +1623,4 @@ declare function HtmlModule(options: IHtmlModuleOptions): {
|
|
|
1623
1623
|
new (): {};
|
|
1624
1624
|
};
|
|
1625
1625
|
|
|
1626
|
-
export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, 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 IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type
|
|
1626
|
+
export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, 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 IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemsReq, type IChatAdapterNextItemsRes, 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 IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHandshakeMiddleware, type IHandshakeMiddlewareMetadata, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetLlm, 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 IRemoteApiKeyFetcher, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateInputShape, type IValidateIsInOptions, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppCloudContact, type IWhatsAppCloudMessage, type IWhatsAppCloudMessageMetadata, type IWhatsAppCloudTemplate, type IWhatsAppCloudTemplateComponent, type IWhatsAppCloudTemplateMessage, type IWhatsAppCloudTemplateParameter, type IWhatsAppCloudTemplateResponse, type IWhatsAppCloudWebhookPayload, type IWhatsAppData, type IWhatsAppMessageListener, type IWhatsAppProxyListenMessageEventData, type IWhatsAppProxyListenMessageEventReq, type IWhatsAppProxyMessage, type IWhatsAppProxyMessageContent, type IWhatsAppProxyMessageEventReq, type IWhatsAppProxySendMessageEventReq, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtHandshakeGuardMiddleware, 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, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RemoteApiKeyRepository, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketChannelReceivedMessage, SocketControllerMetadataStore, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT, WabotChatAdapter, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByCloudApi, WhatsAppReceiverByWabotProxy, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByWabotProxy, WhatsAppWabotProxyConnection, WhatsappChannelConfig, apiKeyGuard, apiKeyHandshakeGuard, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, handshakeMiddlewares, inject, injectable, isArray, isBoolean, isDate, isIn, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, jwtHandshakeGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, onSocketEvent, param, readJsonFromFile, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, runSocketControllers, scoped, singleton, socket, socketController, telegram, validateAndTransform, validateArray, validateIsBoolean, validateIsDate, validateIsIn, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsApp, writeJsonToFile };
|