@wabot-dev/framework 0.1.0-beta.5 → 0.1.0-beta.51
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/async/pg/PgJobRepository.js +26 -0
- package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
- package/dist/src/addon/auth/api-key/ApiKey.js +53 -0
- package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyRepository.js +13 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +21 -0
- package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
- package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
- package/dist/src/addon/auth/jwt/Jwt.js +53 -0
- package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
- package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
- package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
- package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
- package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
- package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +145 -0
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
- package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +23 -0
- package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +9 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -23
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +9 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +25 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
- package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +20 -41
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
- package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +26 -20
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +60 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
- package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
- package/dist/src/core/auth/Auth.js +24 -0
- package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -9
- package/dist/src/core/env/Env.js +39 -0
- package/dist/src/core/error/CustomError.js +15 -0
- package/dist/src/core/injection/index.js +4 -0
- package/dist/src/core/mapper/Mapper.js +42 -0
- package/dist/src/core/password/Password.js +30 -0
- package/dist/src/core/random/Random.js +47 -0
- package/dist/src/core/storable/Storable.js +8 -0
- package/dist/src/core/validation/core/validateArray.js +51 -0
- package/dist/src/core/validation/core/validateIsOptional.js +5 -0
- package/dist/src/core/validation/core/validateModel.js +36 -0
- package/dist/src/core/validation/metadata/@isArray.js +18 -0
- package/dist/src/core/validation/metadata/@isModel.js +18 -0
- package/dist/src/core/validation/metadata/@isOptional.js +17 -0
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
- package/dist/src/core/validation/modelInfo.js +9 -0
- package/dist/src/core/validation/validate.js +11 -0
- package/dist/src/core/validation/validators/is-boolean/@isBoolean.js +17 -0
- package/dist/src/core/validation/validators/is-boolean/validateIsBoolean.js +12 -0
- package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
- package/dist/src/core/validation/validators/is-date/validateIsDate.js +16 -0
- package/dist/src/core/validation/validators/is-not-empty/@isNotEmpty.js +17 -0
- package/dist/src/core/validation/validators/is-not-empty/validateIsNotEmpty.js +12 -0
- package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
- package/dist/src/core/validation/validators/is-number/validateIsNumber.js +12 -0
- package/dist/src/core/validation/validators/is-present/@isPresent.js +17 -0
- package/dist/src/core/validation/validators/is-present/validateIsPresent.js +12 -0
- package/dist/src/core/validation/validators/is-string/@isString.js +17 -0
- package/dist/src/core/validation/validators/is-string/validateIsString.js +12 -0
- package/dist/src/core/validation/validators/max/@max.js +18 -0
- package/dist/src/core/validation/validators/max/validateMax.js +17 -0
- package/dist/src/core/validation/validators/min/@min.js +18 -0
- package/dist/src/core/validation/validators/min/validateMin.js +17 -0
- package/dist/src/feature/async/@command.js +11 -0
- package/dist/src/feature/async/@commandHandler.js +12 -0
- package/dist/src/feature/async/Async.js +38 -0
- package/dist/src/feature/async/Command.js +9 -0
- package/dist/src/feature/async/CommandMetadataStore.js +38 -0
- package/dist/src/feature/async/Job.js +24 -0
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/feature/async/JobRunner.js +45 -0
- package/dist/src/feature/async/JobsEventsHub.js +24 -0
- package/dist/src/feature/async/runCommandHandlers.js +29 -0
- package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
- package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
- package/dist/src/feature/chat-bot/ChatBot.js +73 -0
- package/dist/src/feature/chat-bot/ChatItem.js +24 -0
- package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
- package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
- package/dist/src/feature/chat-bot/IChatItem.js +3 -0
- package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
- package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
- package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
- package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
- package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
- package/dist/src/feature/chat-controller/runChatControllers.js +69 -0
- package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
- package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
- package/dist/src/{mindset → feature/mindset}/IMindset.js +3 -0
- package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +69 -42
- package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
- package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
- package/dist/src/feature/money/Money.js +61 -0
- package/dist/src/feature/money/MoneyDto.js +22 -0
- package/dist/src/{repository → feature}/pg/PgCrudRepository.js +25 -2
- package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
- package/dist/src/feature/rest-controller/metadata/@get.js +19 -0
- package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
- package/dist/src/feature/rest-controller/metadata/@post.js +19 -0
- package/dist/src/feature/rest-controller/metadata/@restController.js +15 -0
- package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
- package/dist/src/feature/rest-controller/runRestControllers.js +102 -0
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
- package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
- package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
- package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
- package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
- package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
- package/dist/src/feature/socket-controller/runSocketControllers.js +98 -0
- package/dist/src/index.d.ts +1151 -575
- package/dist/src/index.js +140 -76
- package/package.json +10 -4
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -84
- package/dist/src/channels/cmd/@cmd.js +0 -18
- package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
- package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
- package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
- package/dist/src/chatbot/ChatBot.js +0 -51
- package/dist/src/chatbot/ChatBotAdapter.js +0 -72
- package/dist/src/controller/channel/UserResolver.js +0 -21
- package/dist/src/core/IMessageContext.js +0 -12
- package/dist/src/core/chat/ChatItem.js +0 -15
- package/dist/src/core/chat/repository/IChatMemory.js +0 -10
- package/dist/src/core/user/IUserRepository.js +0 -19
- package/dist/src/core/user/User.js +0 -26
- package/dist/src/env/WabotEnv.js +0 -27
- package/dist/src/injection/index.js +0 -4
- package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
- package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
- package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
- package/dist/src/pre-made/service/EmailService.js +0 -13
- package/dist/src/pre-made/service/OtpService.js +0 -14
- package/dist/src/server/prepareChatContainer.js +0 -43
- package/dist/src/server/runChannel.js +0 -27
- package/dist/src/server/runServer.js +0 -40
- /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
- /package/dist/src/{injection → core/injection}/Container.js +0 -0
- /package/dist/src/{logger → core/logger}/Logger.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
import { injectable } from '../../core/injection/index.js';
|
|
4
|
+
import '../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
+
import { MindsetOperator } from '../mindset/MindsetOperator.js';
|
|
6
|
+
import { ChatAdapter } from './ChatAdapter.js';
|
|
7
|
+
import { ChatItem } from './ChatItem.js';
|
|
8
|
+
import { ChatMemory } from './ChatMemory.js';
|
|
9
|
+
|
|
10
|
+
let ChatBot = class ChatBot {
|
|
11
|
+
memory;
|
|
12
|
+
adapter;
|
|
13
|
+
mindset;
|
|
14
|
+
constructor(memory, adapter, mindset) {
|
|
15
|
+
this.memory = memory;
|
|
16
|
+
this.adapter = adapter;
|
|
17
|
+
this.mindset = mindset;
|
|
18
|
+
}
|
|
19
|
+
async sendMessage(message, callback) {
|
|
20
|
+
const newChatItem = new ChatItem({
|
|
21
|
+
type: 'humanMessage',
|
|
22
|
+
humanMessage: message,
|
|
23
|
+
});
|
|
24
|
+
await this.memory.create(newChatItem);
|
|
25
|
+
this.processLoop(callback);
|
|
26
|
+
}
|
|
27
|
+
async processLoop(callback) {
|
|
28
|
+
const prevItems = await this.memory.findLastItems(10);
|
|
29
|
+
if (prevItems.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const lastChatItem = prevItems[prevItems.length - 1];
|
|
33
|
+
if (lastChatItem.type === 'botMessage') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const systemPrompt = await this.mindset.systemPrompt();
|
|
37
|
+
const tools = this.mindset.tools();
|
|
38
|
+
const identity = await this.mindset.identity();
|
|
39
|
+
const llms = await this.mindset.llms();
|
|
40
|
+
if (llms.length === 0) {
|
|
41
|
+
throw new Error(`Invalid ${this.mindset.constructor.name} - llms not found`);
|
|
42
|
+
}
|
|
43
|
+
const llm = llms[0];
|
|
44
|
+
const { chatItem: newItemData } = await this.adapter.nextItem({
|
|
45
|
+
model: llm.model,
|
|
46
|
+
provider: llm.provider,
|
|
47
|
+
systemPrompt,
|
|
48
|
+
tools,
|
|
49
|
+
prevItems: prevItems.map((x) => x.getData()),
|
|
50
|
+
});
|
|
51
|
+
if (newItemData.type === 'functionCall') {
|
|
52
|
+
newItemData.functionCall.result = await this.mindset.callFunction(newItemData.functionCall.name, newItemData.functionCall.arguments ?? '{}');
|
|
53
|
+
}
|
|
54
|
+
else if (newItemData.type === 'botMessage') {
|
|
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);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.processLoop(callback);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
ChatBot = __decorate([
|
|
67
|
+
injectable(),
|
|
68
|
+
__metadata("design:paramtypes", [ChatMemory,
|
|
69
|
+
ChatAdapter,
|
|
70
|
+
MindsetOperator])
|
|
71
|
+
], ChatBot);
|
|
72
|
+
|
|
73
|
+
export { ChatBot };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Entity } from '../../core/entity/Entity.js';
|
|
2
|
+
|
|
3
|
+
class ChatItem extends Entity {
|
|
4
|
+
get type() {
|
|
5
|
+
return this.data.type;
|
|
6
|
+
}
|
|
7
|
+
get botMessage() {
|
|
8
|
+
return this.data.botMessage;
|
|
9
|
+
}
|
|
10
|
+
get functionCall() {
|
|
11
|
+
return this.data.functionCall;
|
|
12
|
+
}
|
|
13
|
+
setFunctionResult(result) {
|
|
14
|
+
if (this.data.type !== 'functionCall') {
|
|
15
|
+
throw new Error('The chat item is not functionCall type');
|
|
16
|
+
}
|
|
17
|
+
this.data.functionCall.result = result;
|
|
18
|
+
}
|
|
19
|
+
getData() {
|
|
20
|
+
return this.data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { ChatItem };
|
package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js}
RENAMED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { singleton } from '../../../injection/index.js';
|
|
3
|
-
|
|
4
|
-
let ChatRepository = class ChatRepository {
|
|
1
|
+
class ChatRepository {
|
|
5
2
|
create(chat) {
|
|
6
3
|
throw new Error('Method not implemented.');
|
|
7
4
|
}
|
|
@@ -11,9 +8,6 @@ let ChatRepository = class ChatRepository {
|
|
|
11
8
|
findMemory(chatId) {
|
|
12
9
|
throw new Error('Method not implemented.');
|
|
13
10
|
}
|
|
14
|
-
}
|
|
15
|
-
ChatRepository = __decorate([
|
|
16
|
-
singleton()
|
|
17
|
-
], ChatRepository);
|
|
11
|
+
}
|
|
18
12
|
|
|
19
13
|
export { ChatRepository };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import '
|
|
5
|
-
import { injectable } from '../../injection/index.js';
|
|
2
|
+
import { Chat } from '../chat-bot/Chat.js';
|
|
3
|
+
import '../chat-bot/ChatBot.js';
|
|
4
|
+
import { ChatRepository } from '../chat-bot/ChatRepository.js';
|
|
5
|
+
import { injectable } from '../../core/injection/index.js';
|
|
6
|
+
import 'uuid';
|
|
7
|
+
import '../chat-bot/metadata/ChatBotMetadataStore.js';
|
|
6
8
|
|
|
7
9
|
let ChatResolver = class ChatResolver {
|
|
8
10
|
chatRepository;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { container } from '../../core/injection/index.js';
|
|
2
|
+
import { Chat } from '../chat-bot/Chat.js';
|
|
3
|
+
import { ChatBot } from '../chat-bot/ChatBot.js';
|
|
4
|
+
import { ChatMemory } from '../chat-bot/ChatMemory.js';
|
|
5
|
+
import { ChatRepository } from '../chat-bot/ChatRepository.js';
|
|
6
|
+
import 'uuid';
|
|
7
|
+
import { ChatBotMetadataStore } from '../chat-bot/metadata/ChatBotMetadataStore.js';
|
|
8
|
+
import 'reflect-metadata';
|
|
9
|
+
import '../mindset/metadata/MindsetMetadataStore.js';
|
|
10
|
+
import { Mindset } from '../mindset/IMindset.js';
|
|
11
|
+
import '../mindset/MindsetOperator.js';
|
|
12
|
+
import { ChatResolver } from './ChatResolver.js';
|
|
13
|
+
import { ControllerMetadataStore } from './metadata/ControllerMetadataStore.js';
|
|
14
|
+
import { Container } from '../../core/injection/Container.js';
|
|
15
|
+
|
|
16
|
+
async function prepareChatContainer(container, messageContext, mindsetCtor) {
|
|
17
|
+
const chatContainer = container.createChildContainer();
|
|
18
|
+
chatContainer.register(Container, { useValue: chatContainer });
|
|
19
|
+
chatContainer.registerInstance(Chat, messageContext.chat);
|
|
20
|
+
const chatRepository = container.resolve(ChatRepository);
|
|
21
|
+
const chatMemory = await chatRepository.findMemory(messageContext.chat.id);
|
|
22
|
+
if (!chatMemory) {
|
|
23
|
+
throw new Error('Not found Chat Memory for Chat with Id=' + messageContext.chat.id);
|
|
24
|
+
}
|
|
25
|
+
chatContainer.registerInstance(ChatMemory, chatMemory);
|
|
26
|
+
const chatBotMetadataStore = container.resolve(ChatBotMetadataStore);
|
|
27
|
+
const chatBots = chatBotMetadataStore.getChatBotsMetadata();
|
|
28
|
+
for (const chatBotMetadata of chatBots) {
|
|
29
|
+
chatContainer.beforeResolution(chatBotMetadata.constructor, (a, b) => {
|
|
30
|
+
const subContainer = chatContainer.createChildContainer();
|
|
31
|
+
subContainer.register(Mindset, { useClass: chatBotMetadata.mindsetConstructor });
|
|
32
|
+
const chatBot = subContainer.resolve(ChatBot);
|
|
33
|
+
chatContainer.register(chatBotMetadata.injectionToken, { useValue: chatBot });
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return chatContainer;
|
|
37
|
+
}
|
|
38
|
+
function runChatControllers(controllers) {
|
|
39
|
+
const metadataStore = container.resolve(ControllerMetadataStore);
|
|
40
|
+
const chatResolver = container.resolve(ChatResolver);
|
|
41
|
+
for (const controllerCtor of controllers) {
|
|
42
|
+
const chatControllerMetadata = metadataStore.getChatControllerMetadata(controllerCtor);
|
|
43
|
+
if (!chatControllerMetadata) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
for (const channelMetadata of chatControllerMetadata.channels) {
|
|
47
|
+
const channelContainer = container.createChildContainer();
|
|
48
|
+
if (channelMetadata.channelConfig) {
|
|
49
|
+
channelContainer.register(channelMetadata.channelConfig.constructor, {
|
|
50
|
+
useValue: channelMetadata.channelConfig,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const channel = channelContainer.resolve(channelMetadata.channelConstructor);
|
|
54
|
+
channel.listen(async (channelMessage) => {
|
|
55
|
+
const chat = await chatResolver.resolve(channelMessage.chatConnection);
|
|
56
|
+
const chatContainer = await prepareChatContainer(channelContainer, {
|
|
57
|
+
chat,
|
|
58
|
+
message: channelMessage.message,
|
|
59
|
+
reply: channelMessage.reply,
|
|
60
|
+
});
|
|
61
|
+
const chatController = chatContainer.resolve(channelMetadata.controllerConstructor);
|
|
62
|
+
chatController[channelMetadata.functionName](channelMessage);
|
|
63
|
+
});
|
|
64
|
+
channel.connect();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { runChatControllers };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { HttpServerProvider } from '../http/HttpServerProvider.js';
|
|
3
3
|
import express from 'express';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { Logger } from '../../logger/Logger.js';
|
|
4
|
+
import { Logger } from '../../core/logger/Logger.js';
|
|
5
|
+
import { singleton } from '../../core/injection/index.js';
|
|
7
6
|
|
|
8
7
|
let ExpressProvider = class ExpressProvider {
|
|
9
8
|
httpServerProvider;
|
|
@@ -23,7 +22,6 @@ let ExpressProvider = class ExpressProvider {
|
|
|
23
22
|
}
|
|
24
23
|
createExpress() {
|
|
25
24
|
const expressApp = express();
|
|
26
|
-
expressApp.use(bodyParser.json());
|
|
27
25
|
expressApp.use((req, res, next) => {
|
|
28
26
|
const start = process.hrtime();
|
|
29
27
|
res.on('finish', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
-
import {
|
|
2
|
+
import { singleton } from '../../core/injection/index.js';
|
|
3
|
+
import { Logger } from '../../core/logger/Logger.js';
|
|
3
4
|
import { Server } from 'http';
|
|
4
|
-
import { singleton } from 'tsyringe';
|
|
5
5
|
|
|
6
6
|
let HttpServerProvider = class HttpServerProvider {
|
|
7
7
|
server = null;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { injectable } from '
|
|
2
|
+
import { injectable } from '../../core/injection/index.js';
|
|
3
3
|
import { Mindset } from './IMindset.js';
|
|
4
4
|
import { MindsetMetadataStore } from './metadata/MindsetMetadataStore.js';
|
|
5
|
-
import { Container } from '
|
|
5
|
+
import { Container } from '../../core/injection/Container.js';
|
|
6
6
|
|
|
7
7
|
let MindsetOperator = class MindsetOperator {
|
|
8
8
|
mindset;
|
|
@@ -22,64 +22,69 @@ let MindsetOperator = class MindsetOperator {
|
|
|
22
22
|
limits() {
|
|
23
23
|
return this.mindset.limits();
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.map((module) => module.functions)
|
|
28
|
-
.flat()
|
|
29
|
-
.find((fn) => fn.name === name);
|
|
30
|
-
if (!fnMetadata) {
|
|
31
|
-
throw new Error(`Function ${name} not found`);
|
|
32
|
-
}
|
|
33
|
-
const paramsObj = JSON.parse(params);
|
|
34
|
-
const module = this.container.resolve(fnMetadata.moduleConstructor);
|
|
35
|
-
try {
|
|
36
|
-
const response = await module[name](paramsObj);
|
|
37
|
-
if (!response) {
|
|
38
|
-
return 'success';
|
|
39
|
-
}
|
|
40
|
-
return response.toString();
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
return `Error: ${error}`;
|
|
44
|
-
}
|
|
25
|
+
llms() {
|
|
26
|
+
return this.mindset.llms();
|
|
45
27
|
}
|
|
46
|
-
async
|
|
28
|
+
async systemPrompt() {
|
|
29
|
+
let [identity, skills, limits] = await Promise.all([
|
|
30
|
+
this.identity(),
|
|
31
|
+
this.skills(),
|
|
32
|
+
this.limits(),
|
|
33
|
+
]);
|
|
34
|
+
const language = identity.language.replaceAll('#', ' ');
|
|
35
|
+
const name = identity.name.replaceAll('#', ' ');
|
|
36
|
+
const age = identity.age ? identity.age.toString().replaceAll('#', ' ') : null;
|
|
37
|
+
const personality = identity.personality ? identity.personality.replaceAll('#', ' ') : null;
|
|
38
|
+
skills = skills.replaceAll('#', ' ');
|
|
39
|
+
limits = limits.replaceAll('#', ' ');
|
|
40
|
+
const systemPrompt = `
|
|
41
|
+
# System Instructions
|
|
42
|
+
you should act as a assistant.
|
|
43
|
+
your main language is ${language}.
|
|
44
|
+
your name is ${name}.
|
|
45
|
+
${age ? 'you are ' + age + ' years old.' : ''}
|
|
46
|
+
|
|
47
|
+
${personality ? '## Personality (in your main language) \n' + personality : ''}
|
|
48
|
+
|
|
49
|
+
## Skills (in your main language)
|
|
50
|
+
${skills}
|
|
51
|
+
|
|
52
|
+
## System limitations (in your main language)
|
|
53
|
+
${limits}
|
|
54
|
+
|
|
55
|
+
## Chat memory
|
|
56
|
+
Next you will receive a chat history,
|
|
57
|
+
you should use this information to answer the user.
|
|
58
|
+
`;
|
|
59
|
+
return systemPrompt;
|
|
60
|
+
}
|
|
61
|
+
tools() {
|
|
47
62
|
return this.metadata.modules
|
|
48
|
-
.map((module) => module.functions.map((fn) => this.
|
|
63
|
+
.map((module) => module.functions.map((fn) => this.tool(fn, module)))
|
|
49
64
|
.flat();
|
|
50
65
|
}
|
|
51
|
-
|
|
66
|
+
tool(fn, module) {
|
|
52
67
|
const description = fn.config.description.replaceAll('#', ' ');
|
|
53
68
|
return {
|
|
54
|
-
|
|
69
|
+
language: module.config.language ?? 'english',
|
|
55
70
|
name: fn.name,
|
|
56
71
|
description,
|
|
57
|
-
parameters:
|
|
58
|
-
type: 'object',
|
|
59
|
-
properties: fn.params.reduce((prev, param) => ({
|
|
60
|
-
...prev,
|
|
61
|
-
[param.name]: this.toolParam(param),
|
|
62
|
-
}), {}),
|
|
63
|
-
required: fn.params.filter((param) => !param.config.optional).map((param) => param.name)
|
|
64
|
-
},
|
|
72
|
+
parameters: fn.params.map((param) => this.toolParameter(param)),
|
|
65
73
|
};
|
|
66
74
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
description: `
|
|
75
|
+
toolParameter(param) {
|
|
76
|
+
let description = `
|
|
70
77
|
### description (in your main language)
|
|
71
78
|
${param.config.description.replaceAll('#', ' ')}
|
|
72
|
-
|
|
73
|
-
};
|
|
79
|
+
`;
|
|
74
80
|
const type = (() => {
|
|
75
81
|
if (param.type === Number)
|
|
76
82
|
return 'number';
|
|
77
83
|
if (param.type === String)
|
|
78
84
|
return 'string';
|
|
79
85
|
if (param.type === Date) {
|
|
80
|
-
|
|
86
|
+
description = `${description}
|
|
81
87
|
### format: ISO 8681 - YYYY-MM-DDTHH:mm:ssZ
|
|
82
|
-
${addons.description}
|
|
83
88
|
`;
|
|
84
89
|
return 'string';
|
|
85
90
|
}
|
|
@@ -87,9 +92,31 @@ let MindsetOperator = class MindsetOperator {
|
|
|
87
92
|
})();
|
|
88
93
|
return {
|
|
89
94
|
type,
|
|
90
|
-
|
|
95
|
+
name: param.name,
|
|
96
|
+
description,
|
|
91
97
|
};
|
|
92
98
|
}
|
|
99
|
+
async callFunction(name, params) {
|
|
100
|
+
const fnMetadata = this.metadata.modules
|
|
101
|
+
.map((module) => module.functions)
|
|
102
|
+
.flat()
|
|
103
|
+
.find((fn) => fn.name === name);
|
|
104
|
+
if (!fnMetadata) {
|
|
105
|
+
throw new Error(`Function ${name} not found`);
|
|
106
|
+
}
|
|
107
|
+
const paramsObj = JSON.parse(params);
|
|
108
|
+
const module = this.container.resolve(fnMetadata.moduleConstructor);
|
|
109
|
+
try {
|
|
110
|
+
const response = await module[name](paramsObj);
|
|
111
|
+
if (!response) {
|
|
112
|
+
return 'success';
|
|
113
|
+
}
|
|
114
|
+
return response.toString();
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
return `Error: ${error}`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
93
120
|
};
|
|
94
121
|
MindsetOperator = __decorate([
|
|
95
122
|
injectable(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
-
import { singleton } from '
|
|
2
|
+
import { singleton } from '../../../core/injection/index.js';
|
|
3
3
|
import { MINDSET_FUNCTION_DECORATION_FUNCTION } from './functions/decoratorNames.js';
|
|
4
4
|
import { MINDSET_DECORATION_MINDSET } from './mindsets/decoratorNames.js';
|
|
5
5
|
import { MINDSET_MODULE_DECORATION_MODULE } from './modules/decoratorNames.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { container } from '
|
|
2
|
+
import { container } from '../../../../core/injection/index.js';
|
|
3
3
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
4
4
|
import { MINDSET_FUNCTION_DECORATION_FUNCTION } from './decoratorNames.js';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { container, injectable } from '
|
|
2
|
+
import { container, injectable } from '../../../../core/injection/index.js';
|
|
3
3
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
4
4
|
import { MINDSET_DECORATION_MINDSET } from './decoratorNames.js';
|
|
5
5
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import { container, injectable } from '../../../injection/index.js';
|
|
1
|
+
import { container, injectable } from '../../../../core/injection/index.js';
|
|
3
2
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
4
3
|
import { MINDSET_MODULE_DECORATION_MODULE } from './decoratorNames.js';
|
|
5
4
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
3
|
-
import { container } from '
|
|
3
|
+
import { container } from '../../../../core/injection/index.js';
|
|
4
4
|
import { PARAM_DECORATION_PARAM } from './decoratorNames.js';
|
|
5
5
|
|
|
6
6
|
function param(config) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Storable } from '../../core/storable/Storable.js';
|
|
2
|
+
import { Big } from 'big.js';
|
|
3
|
+
|
|
4
|
+
Big.strict = true;
|
|
5
|
+
class Money extends Storable {
|
|
6
|
+
getData() {
|
|
7
|
+
return { ...this.data };
|
|
8
|
+
}
|
|
9
|
+
get amount() {
|
|
10
|
+
return Big(this.data.amount);
|
|
11
|
+
}
|
|
12
|
+
get currency() {
|
|
13
|
+
return this.data.currency;
|
|
14
|
+
}
|
|
15
|
+
plus(money) {
|
|
16
|
+
this.validateEqualCurrencies(this.data.currency, money.data.currency);
|
|
17
|
+
return new Money({
|
|
18
|
+
amount: this.amount.plus(money.amount).toFixed(6),
|
|
19
|
+
currency: this.currency,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
minus(money) {
|
|
23
|
+
this.validateEqualCurrencies(this.data.currency, money.data.currency);
|
|
24
|
+
return new Money({
|
|
25
|
+
amount: this.amount.minus(money.amount).toFixed(6),
|
|
26
|
+
currency: this.currency,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
times(value) {
|
|
30
|
+
return new Money({
|
|
31
|
+
amount: this.amount.times(new Big(String(value))).toFixed(6),
|
|
32
|
+
currency: this.currency,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
div(value) {
|
|
36
|
+
return new Money({
|
|
37
|
+
amount: this.amount.div(new Big(String(value))).toFixed(6),
|
|
38
|
+
currency: this.currency,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
negative() {
|
|
42
|
+
return new Money({
|
|
43
|
+
amount: new Big('0').minus(this.amount).toFixed(6),
|
|
44
|
+
currency: this.currency,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
isGretterThan(money) {
|
|
48
|
+
this.validateEqualCurrencies(this.data.currency, money.data.currency);
|
|
49
|
+
return this.amount.gt(money.amount);
|
|
50
|
+
}
|
|
51
|
+
validateEqualCurrencies(left, right) {
|
|
52
|
+
if (left !== right) {
|
|
53
|
+
throw new Error(`Is not posible operate with diferent currencies: '${left}' and '${right}'`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
static zero(currency) {
|
|
57
|
+
return new Money({ currency, amount: '0' });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { Money };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import '../../core/injection/index.js';
|
|
3
|
+
import '../../core/validation/metadata/ValidationMetadataStore.js';
|
|
4
|
+
import { isNotEmpty } from '../../core/validation/validators/is-not-empty/@isNotEmpty.js';
|
|
5
|
+
import { isString } from '../../core/validation/validators/is-string/@isString.js';
|
|
6
|
+
|
|
7
|
+
class MoneyDto {
|
|
8
|
+
amount = '';
|
|
9
|
+
currency = '';
|
|
10
|
+
}
|
|
11
|
+
__decorate([
|
|
12
|
+
isString(),
|
|
13
|
+
isNotEmpty(),
|
|
14
|
+
__metadata("design:type", String)
|
|
15
|
+
], MoneyDto.prototype, "amount", void 0);
|
|
16
|
+
__decorate([
|
|
17
|
+
isString(),
|
|
18
|
+
isNotEmpty(),
|
|
19
|
+
__metadata("design:type", String)
|
|
20
|
+
], MoneyDto.prototype, "currency", void 0);
|
|
21
|
+
|
|
22
|
+
export { MoneyDto };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as shortUUID from 'short-uuid';
|
|
2
2
|
import { PgRepositoryBase } from './PgRepositoryBase.js';
|
|
3
|
+
import { CustomError } from '../../core/error/CustomError.js';
|
|
3
4
|
|
|
4
5
|
class PgCrudRepository extends PgRepositoryBase {
|
|
5
6
|
config;
|
|
@@ -17,6 +18,28 @@ class PgCrudRepository extends PgRepositoryBase {
|
|
|
17
18
|
const items = await this.query(sql, [id]);
|
|
18
19
|
return items.at(0) ?? null;
|
|
19
20
|
}
|
|
21
|
+
async findByIds(ids) {
|
|
22
|
+
if (ids.length === 0) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const sql = `
|
|
26
|
+
SELECT ${this.columns}
|
|
27
|
+
FROM ${this.table}
|
|
28
|
+
WHERE id IN (${ids.map((_, i) => '$' + (i + 1)).join(',')})
|
|
29
|
+
`;
|
|
30
|
+
const items = await this.query(sql, ids);
|
|
31
|
+
return items;
|
|
32
|
+
}
|
|
33
|
+
async findOrThrow(id) {
|
|
34
|
+
const item = await this.find(id);
|
|
35
|
+
if (!item) {
|
|
36
|
+
throw new CustomError({
|
|
37
|
+
message: `Not found ${this.config.constructor.name} with id = '${id}'`,
|
|
38
|
+
httpCode: 404,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return item;
|
|
42
|
+
}
|
|
20
43
|
async findAll() {
|
|
21
44
|
const sql = `
|
|
22
45
|
SELECT ${this.columns}
|
|
@@ -46,10 +69,10 @@ class PgCrudRepository extends PgRepositoryBase {
|
|
|
46
69
|
SET ${this.updates}
|
|
47
70
|
WHERE id = $${this.columnsList.length + 1}
|
|
48
71
|
`;
|
|
49
|
-
await this.exec(sql, [...this.values(item), item.
|
|
72
|
+
await this.exec(sql, [...this.values(item), item.id]);
|
|
50
73
|
}
|
|
51
74
|
async discard(item) {
|
|
52
|
-
const _item = await this.find(item.
|
|
75
|
+
const _item = await this.find(item.id);
|
|
53
76
|
if (!_item) {
|
|
54
77
|
throw new Error('Not found');
|
|
55
78
|
}
|