@wabot-dev/framework 0.1.0-beta.4 → 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/async/pg/PgJobRepository.js +26 -0
- package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +128 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +120 -0
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +111 -0
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +5 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +5 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
- package/dist/src/addon/chat-controller/cmd/@cmd.js +22 -0
- package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +8 -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 +8 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/{channels → addon/chat-controller}/whatsapp/@whatsapp.js +8 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
- package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +1 -1
- package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevConnection.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/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiver.js +4 -7
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByDevConnection.js +4 -10
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByWebHook.js +6 -12
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +39 -10
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByCloudApi.js +10 -13
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByDevConnection.js +13 -15
- package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
- package/dist/src/addon/money/MoneyDto.js +22 -0
- package/dist/src/{repository → addon/repository}/pg/PgCrudRepository.js +23 -2
- package/dist/src/{repository → addon/repository}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/addon/rest-controller/jwt/@jwtGuard.js +17 -0
- package/dist/src/addon/rest-controller/jwt/Jwt.js +31 -0
- package/dist/src/addon/rest-controller/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/addon/rest-controller/jwt/JwtConfig.js +28 -0
- package/dist/src/addon/rest-controller/jwt/JwtGuardMiddleware.js +45 -0
- package/dist/src/addon/rest-controller/jwt/JwtRefreshToken.js +9 -0
- package/dist/src/addon/rest-controller/jwt/JwtRefreshTokenRepository.js +21 -0
- package/dist/src/addon/rest-controller/jwt/JwtSigner.js +48 -0
- package/dist/src/addon/rest-controller/jwt/JwtTokenDto.js +22 -0
- package/dist/src/addon/validation/is-boolean/@isBoolean.js +17 -0
- package/dist/src/addon/validation/is-boolean/validateIsBoolean.js +12 -0
- package/dist/src/addon/validation/is-date/@isDate.js +17 -0
- package/dist/src/addon/validation/is-date/validateIsDate.js +16 -0
- package/dist/src/addon/validation/is-not-empty/@isNotEmpty.js +17 -0
- package/dist/src/addon/validation/is-not-empty/validateIsNotEmpty.js +12 -0
- package/dist/src/addon/validation/is-number/@isNumber.js +17 -0
- package/dist/src/addon/validation/is-number/validateIsNumber.js +12 -0
- package/dist/src/addon/validation/is-present/@isPresent.js +17 -0
- package/dist/src/addon/validation/is-present/validateIsPresent.js +12 -0
- package/dist/src/addon/validation/is-string/@isString.js +17 -0
- package/dist/src/addon/validation/is-string/validateIsString.js +12 -0
- package/dist/src/addon/validation/max/@max.js +18 -0
- package/dist/src/addon/validation/max/validateMax.js +17 -0
- package/dist/src/addon/validation/min/@min.js +18 -0
- package/dist/src/addon/validation/min/validateMin.js +17 -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/random/Random.js +37 -0
- package/dist/src/core/storable/Storable.js +8 -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/validateArray.js +51 -0
- package/dist/src/core/validation/validators/validateIsOptional.js +5 -0
- package/dist/src/core/validation/validators/validateModel.js +36 -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 +50 -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 +5 -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}/MindsetOperator.js +66 -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/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 +88 -0
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
- package/dist/src/index.d.ts +848 -483
- package/dist/src/index.js +122 -76
- package/package.json +9 -3
- 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/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/wabot → addon/chat-controller/whatsapp}/WabotDevSocketContracts.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}/IMindset.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,29 @@
|
|
|
1
|
+
import { JobsEventsHub } from './JobsEventsHub.js';
|
|
2
|
+
import { JobRunner } from './JobRunner.js';
|
|
3
|
+
import { CommandMetadataStore } from './CommandMetadataStore.js';
|
|
4
|
+
import { JobRepository } from './JobRepository.js';
|
|
5
|
+
import { container } from '../../core/injection/index.js';
|
|
6
|
+
|
|
7
|
+
function runAsyncCommandHandlers(handlers) {
|
|
8
|
+
const eventsHub = container.resolve(JobsEventsHub);
|
|
9
|
+
const jobRunner = container.resolve(JobRunner);
|
|
10
|
+
const jobRepository = container.resolve(JobRepository);
|
|
11
|
+
const commandsHandlersContainer = container.resolve(CommandMetadataStore);
|
|
12
|
+
const handledCommands = handlers
|
|
13
|
+
.map((x) => commandsHandlersContainer.getCommandNameForHandler(x))
|
|
14
|
+
.filter((x) => x)
|
|
15
|
+
.map((x) => x);
|
|
16
|
+
eventsHub.listenJobsEvents(async (event) => {
|
|
17
|
+
try {
|
|
18
|
+
const job = await jobRepository.findOrThrow(event.jobId);
|
|
19
|
+
if (handledCommands.includes(job.commandName)) {
|
|
20
|
+
jobRunner.run(job);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { runAsyncCommandHandlers };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ChatItem } from './ChatItem.js';
|
|
2
|
+
|
|
3
|
+
class ChatBot {
|
|
4
|
+
memory;
|
|
5
|
+
adapter;
|
|
6
|
+
mindset;
|
|
7
|
+
constructor(memory, adapter, mindset) {
|
|
8
|
+
this.memory = memory;
|
|
9
|
+
this.adapter = adapter;
|
|
10
|
+
this.mindset = mindset;
|
|
11
|
+
}
|
|
12
|
+
async sendMessage(message, callback) {
|
|
13
|
+
const newChatItem = new ChatItem({
|
|
14
|
+
type: 'humanMessage',
|
|
15
|
+
humanMessage: message,
|
|
16
|
+
});
|
|
17
|
+
await this.memory.create(newChatItem);
|
|
18
|
+
this.processLoop(callback);
|
|
19
|
+
}
|
|
20
|
+
async processLoop(callback) {
|
|
21
|
+
const prevItems = await this.memory.findLastItems(10);
|
|
22
|
+
if (prevItems.length === 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const lastChatItem = prevItems[prevItems.length - 1];
|
|
26
|
+
if (lastChatItem.type === 'botMessage') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const systemPrompt = await this.mindset.systemPrompt();
|
|
30
|
+
const tools = this.mindset.tools();
|
|
31
|
+
const { chatItem: newItemData } = await this.adapter.nextItem({
|
|
32
|
+
model: 'gpt',
|
|
33
|
+
systemPrompt,
|
|
34
|
+
tools,
|
|
35
|
+
prevItems: prevItems.map((x) => x.getData()),
|
|
36
|
+
});
|
|
37
|
+
if (newItemData.type === 'functionCall') {
|
|
38
|
+
newItemData.functionCall.result = await this.mindset.callFunction(newItemData.functionCall.name, newItemData.functionCall.arguments ?? '{}');
|
|
39
|
+
}
|
|
40
|
+
const newChatItem = new ChatItem(newItemData);
|
|
41
|
+
await this.memory.create(newChatItem);
|
|
42
|
+
if (newChatItem.type === 'botMessage') {
|
|
43
|
+
callback(newChatItem.botMessage);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.processLoop(callback);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
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,9 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import '../../core/
|
|
5
|
-
import
|
|
2
|
+
import { Chat } from '../chat-bot/Chat.js';
|
|
3
|
+
import { ChatRepository } from '../chat-bot/ChatRepository.js';
|
|
4
|
+
import { injectable } from '../../core/injection/index.js';
|
|
5
|
+
import 'uuid';
|
|
6
|
+
import '../chat-bot/metadata/ChatBotMetadataStore.js';
|
|
6
7
|
|
|
7
8
|
let ChatResolver = class ChatResolver {
|
|
8
9
|
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,66 @@ let MindsetOperator = class MindsetOperator {
|
|
|
22
22
|
limits() {
|
|
23
23
|
return this.mindset.limits();
|
|
24
24
|
}
|
|
25
|
-
async
|
|
26
|
-
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
async systemPrompt() {
|
|
26
|
+
let [identity, skills, limits] = await Promise.all([
|
|
27
|
+
this.identity(),
|
|
28
|
+
this.skills(),
|
|
29
|
+
this.limits(),
|
|
30
|
+
]);
|
|
31
|
+
const language = identity.language.replaceAll('#', ' ');
|
|
32
|
+
const name = identity.name.replaceAll('#', ' ');
|
|
33
|
+
const age = identity.age ? identity.age.toString().replaceAll('#', ' ') : null;
|
|
34
|
+
const personality = identity.personality ? identity.personality.replaceAll('#', ' ') : null;
|
|
35
|
+
skills = skills.replaceAll('#', ' ');
|
|
36
|
+
limits = limits.replaceAll('#', ' ');
|
|
37
|
+
const systemPrompt = `
|
|
38
|
+
# System Instructions
|
|
39
|
+
you should act as a assistant.
|
|
40
|
+
your main language is ${language}.
|
|
41
|
+
your name is ${name}.
|
|
42
|
+
${age ? 'you are ' + age + ' years old.' : ''}
|
|
43
|
+
|
|
44
|
+
${personality ? '## Personality (in your main language) \n' + personality : ''}
|
|
45
|
+
|
|
46
|
+
## Skills (in your main language)
|
|
47
|
+
${skills}
|
|
48
|
+
|
|
49
|
+
## System limitations (in your main language)
|
|
50
|
+
${limits}
|
|
51
|
+
|
|
52
|
+
## Chat memory
|
|
53
|
+
Next you will receive a chat history,
|
|
54
|
+
you should use this information to answer the user.
|
|
55
|
+
`;
|
|
56
|
+
return systemPrompt;
|
|
45
57
|
}
|
|
46
|
-
|
|
58
|
+
tools() {
|
|
47
59
|
return this.metadata.modules
|
|
48
|
-
.map((module) => module.functions.map((fn) => this.
|
|
60
|
+
.map((module) => module.functions.map((fn) => this.tool(fn, module)))
|
|
49
61
|
.flat();
|
|
50
62
|
}
|
|
51
|
-
|
|
63
|
+
tool(fn, module) {
|
|
52
64
|
const description = fn.config.description.replaceAll('#', ' ');
|
|
53
65
|
return {
|
|
54
|
-
|
|
66
|
+
language: module.config.language ?? 'english',
|
|
55
67
|
name: fn.name,
|
|
56
68
|
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
|
-
},
|
|
69
|
+
parameters: fn.params.map((param) => this.toolParameter(param)),
|
|
65
70
|
};
|
|
66
71
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
description: `
|
|
72
|
+
toolParameter(param) {
|
|
73
|
+
let description = `
|
|
70
74
|
### description (in your main language)
|
|
71
75
|
${param.config.description.replaceAll('#', ' ')}
|
|
72
|
-
|
|
73
|
-
};
|
|
76
|
+
`;
|
|
74
77
|
const type = (() => {
|
|
75
78
|
if (param.type === Number)
|
|
76
79
|
return 'number';
|
|
77
80
|
if (param.type === String)
|
|
78
81
|
return 'string';
|
|
79
82
|
if (param.type === Date) {
|
|
80
|
-
|
|
83
|
+
description = `${description}
|
|
81
84
|
### format: ISO 8681 - YYYY-MM-DDTHH:mm:ssZ
|
|
82
|
-
${addons.description}
|
|
83
85
|
`;
|
|
84
86
|
return 'string';
|
|
85
87
|
}
|
|
@@ -87,9 +89,31 @@ let MindsetOperator = class MindsetOperator {
|
|
|
87
89
|
})();
|
|
88
90
|
return {
|
|
89
91
|
type,
|
|
90
|
-
|
|
92
|
+
name: param.name,
|
|
93
|
+
description,
|
|
91
94
|
};
|
|
92
95
|
}
|
|
96
|
+
async callFunction(name, params) {
|
|
97
|
+
const fnMetadata = this.metadata.modules
|
|
98
|
+
.map((module) => module.functions)
|
|
99
|
+
.flat()
|
|
100
|
+
.find((fn) => fn.name === name);
|
|
101
|
+
if (!fnMetadata) {
|
|
102
|
+
throw new Error(`Function ${name} not found`);
|
|
103
|
+
}
|
|
104
|
+
const paramsObj = JSON.parse(params);
|
|
105
|
+
const module = this.container.resolve(fnMetadata.moduleConstructor);
|
|
106
|
+
try {
|
|
107
|
+
const response = await module[name](paramsObj);
|
|
108
|
+
if (!response) {
|
|
109
|
+
return 'success';
|
|
110
|
+
}
|
|
111
|
+
return response.toString();
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return `Error: ${error}`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
93
117
|
};
|
|
94
118
|
MindsetOperator = __decorate([
|
|
95
119
|
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,19 @@
|
|
|
1
|
+
import { container } from '../../../core/injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function get(config) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const functionName = propertyKey.toString();
|
|
7
|
+
const paramsTypes = Reflect.getMetadata('design:paramtypes', target, functionName);
|
|
8
|
+
const store = container.resolve(RestControllerMetadataStore);
|
|
9
|
+
store.saveEndPointMetadata({
|
|
10
|
+
controllerConstructor: target.constructor,
|
|
11
|
+
method: 'get',
|
|
12
|
+
config: typeof config === 'string' ? { path: config } : config,
|
|
13
|
+
functionName,
|
|
14
|
+
paramsTypes,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { get };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { container } from '../../../core/injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function middleware(middlewareConstructor) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const functionName = propertyKey.toString();
|
|
7
|
+
const store = container.resolve(RestControllerMetadataStore);
|
|
8
|
+
store.saveMiddlewareMetadata({
|
|
9
|
+
controllerConstructor: target.constructor,
|
|
10
|
+
functionName,
|
|
11
|
+
middlewareConstructor: middlewareConstructor,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { middleware };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { container } from '../../../core/injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function post(config) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const functionName = propertyKey.toString();
|
|
7
|
+
const paramsTypes = Reflect.getMetadata('design:paramtypes', target, functionName);
|
|
8
|
+
const store = container.resolve(RestControllerMetadataStore);
|
|
9
|
+
store.saveEndPointMetadata({
|
|
10
|
+
controllerConstructor: target.constructor,
|
|
11
|
+
method: 'post',
|
|
12
|
+
config: typeof config === 'string' ? { path: config } : config,
|
|
13
|
+
functionName,
|
|
14
|
+
paramsTypes,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { post };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { container, injectable } from '../../../core/injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function restController(config) {
|
|
5
|
+
return function (target) {
|
|
6
|
+
const metaDataStore = container.resolve(RestControllerMetadataStore);
|
|
7
|
+
metaDataStore.saveControllerMetadata({
|
|
8
|
+
controllerConstructor: target,
|
|
9
|
+
path: typeof config === 'string' ? config : config.path,
|
|
10
|
+
});
|
|
11
|
+
injectable()(target);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { restController };
|