@wabot-dev/framework 0.1.0-beta.9 → 0.2.0-beta.1

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.
Files changed (212) hide show
  1. package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
  2. package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
  3. package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
  4. package/dist/src/addon/auth/api-key/ApiKey.js +45 -0
  5. package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
  6. package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
  7. package/dist/src/addon/auth/api-key/ApiKeyRepository.js +22 -0
  8. package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +53 -0
  9. package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +62 -0
  10. package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
  11. package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
  12. package/dist/src/addon/auth/jwt/Jwt.js +53 -0
  13. package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
  14. package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
  15. package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
  16. package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
  17. package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
  18. package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
  19. package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
  20. package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
  21. package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
  22. package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
  23. package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
  24. package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
  25. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
  26. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
  27. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
  28. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
  29. package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
  30. package/dist/src/addon/chat-controller/cmd/@cmd.js +24 -0
  31. package/dist/src/addon/chat-controller/cmd/CmdChannel.js +91 -0
  32. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +10 -4
  33. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +9 -23
  34. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
  35. package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +10 -4
  36. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  37. package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +26 -0
  38. package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
  39. package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
  40. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
  41. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
  42. package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
  43. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +15 -39
  44. package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
  45. package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +27 -20
  46. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
  47. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
  48. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +61 -0
  49. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
  50. package/dist/src/{pre-made/module → addon/mindset}/html/HtmlModule.js +7 -7
  51. package/dist/src/core/auth/Auth.js +33 -0
  52. package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
  53. package/dist/src/core/env/Env.js +39 -0
  54. package/dist/src/core/error/CustomError.js +15 -0
  55. package/dist/src/core/injection/index.js +4 -0
  56. package/dist/src/core/mapper/Mapper.js +42 -0
  57. package/dist/src/core/password/Password.js +30 -0
  58. package/dist/src/core/random/Random.js +65 -0
  59. package/dist/src/core/storable/Storable.js +8 -0
  60. package/dist/src/core/validation/core/validateArray.js +51 -0
  61. package/dist/src/core/validation/core/validateModel.js +36 -0
  62. package/dist/src/{validation/metadata/@isNumber.js → core/validation/metadata/@isArray.js} +5 -4
  63. package/dist/src/{validation/metadata/@isDate.js → core/validation/metadata/@isModel.js} +5 -4
  64. package/dist/src/{validation → core/validation}/metadata/@isOptional.js +1 -1
  65. package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
  66. package/dist/src/core/validation/modelInfo.js +9 -0
  67. package/dist/src/{validation/validateModel2.js → core/validation/validate.js} +3 -3
  68. package/dist/src/{validation/metadata → core/validation/validators/is-boolean}/@isBoolean.js +3 -3
  69. package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
  70. package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
  71. package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
  72. package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js +3 -3
  73. package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
  74. package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js +3 -3
  75. package/dist/src/{validation/metadata → core/validation/validators/is-string}/@isString.js +3 -3
  76. package/dist/src/{validation/metadata → core/validation/validators/max}/@max.js +3 -3
  77. package/dist/src/{validation/metadata → core/validation/validators/min}/@min.js +3 -3
  78. package/dist/src/feature/async/@command.js +11 -0
  79. package/dist/src/feature/async/@commandHandler.js +12 -0
  80. package/dist/src/feature/async/Async.js +38 -0
  81. package/dist/src/feature/async/Command.js +9 -0
  82. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  83. package/dist/src/feature/async/Job.js +27 -0
  84. package/dist/src/feature/async/JobRepository.js +31 -0
  85. package/dist/src/feature/async/JobRunner.js +48 -0
  86. package/dist/src/feature/async/JobsEventsHub.js +36 -0
  87. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  88. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  89. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  90. package/dist/src/feature/chat-bot/ChatBot.js +73 -0
  91. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  92. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  93. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  94. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  95. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  96. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  97. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
  98. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  99. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  100. package/dist/src/feature/chat-controller/runChatControllers.js +83 -0
  101. package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
  102. package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
  103. package/dist/src/{mindset → feature/mindset}/IMindset.js +6 -0
  104. package/dist/src/feature/mindset/MindsetOperator.js +180 -0
  105. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  106. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  107. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  108. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  109. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  110. package/dist/src/feature/money/Money.js +61 -0
  111. package/dist/src/feature/money/MoneyDto.js +22 -0
  112. package/dist/src/{repository → feature}/pg/PgCrudRepository.js +24 -10
  113. package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
  114. package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
  115. package/dist/src/{rest-controller/metadata/@post.js → feature/rest-controller/metadata/@middleware.js} +5 -8
  116. package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
  117. package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
  118. package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
  119. package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
  120. package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +2 -2
  121. package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +14 -1
  122. package/dist/src/{rest-controller/metadata/@get.js → feature/rest-controller/metadata/methodDecorator.js} +5 -5
  123. package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
  124. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
  125. package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
  126. package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
  127. package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
  128. package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
  129. package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
  130. package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
  131. package/dist/src/index.d.ts +1219 -718
  132. package/dist/src/index.js +147 -102
  133. package/package.json +8 -2
  134. package/dist/src/_virtual/_commonjsHelpers.js +0 -5
  135. package/dist/src/_virtual/cjs.js +0 -7
  136. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
  137. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
  138. package/dist/src/channels/cmd/@cmd.js +0 -18
  139. package/dist/src/channels/cmd/CmdChannel.js +0 -73
  140. package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
  141. package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
  142. package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
  143. package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
  144. package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
  145. package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
  146. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
  147. package/dist/src/chatbot/ChatBot.js +0 -51
  148. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  149. package/dist/src/controller/channel/UserResolver.js +0 -21
  150. package/dist/src/core/IMessageContext.js +0 -12
  151. package/dist/src/core/chat/ChatItem.js +0 -15
  152. package/dist/src/core/chat/repository/IChatMemory.js +0 -10
  153. package/dist/src/core/user/IUserRepository.js +0 -19
  154. package/dist/src/core/user/User.js +0 -26
  155. package/dist/src/env/WabotEnv.js +0 -27
  156. package/dist/src/injection/index.js +0 -4
  157. package/dist/src/mindset/MindsetOperator.js +0 -101
  158. package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +0 -90
  159. package/dist/src/node_modules/deepmerge/dist/cjs.js +0 -142
  160. package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +0 -102
  161. package/dist/src/node_modules/dom-serializer/lib/esm/index.js +0 -186
  162. package/dist/src/node_modules/domelementtype/lib/esm/index.js +0 -53
  163. package/dist/src/node_modules/domhandler/lib/esm/index.js +0 -148
  164. package/dist/src/node_modules/domhandler/lib/esm/node.js +0 -334
  165. package/dist/src/node_modules/entities/lib/esm/decode.js +0 -458
  166. package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +0 -62
  167. package/dist/src/node_modules/entities/lib/esm/escape.js +0 -99
  168. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +0 -8
  169. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +0 -8
  170. package/dist/src/node_modules/html-to-text/lib/html-to-text.js +0 -2147
  171. package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +0 -491
  172. package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +0 -928
  173. package/dist/src/node_modules/htmlparser2/lib/esm/index.js +0 -18
  174. package/dist/src/node_modules/leac/lib/leac.js +0 -3
  175. package/dist/src/node_modules/parseley/lib/parseley.js +0 -270
  176. package/dist/src/node_modules/peberminta/lib/core.js +0 -171
  177. package/dist/src/node_modules/selderee/lib/selderee.js +0 -380
  178. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  179. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  180. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  181. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  182. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  183. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  184. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  185. package/dist/src/pre-made/service/EmailService.js +0 -13
  186. package/dist/src/pre-made/service/OtpService.js +0 -14
  187. package/dist/src/rest-controller/runRestControllers.js +0 -74
  188. package/dist/src/server/prepareChatContainer.js +0 -43
  189. package/dist/src/server/runChannel.js +0 -27
  190. package/dist/src/server/runServer.js +0 -40
  191. package/dist/src/validation/metadata/@validable.js +0 -14
  192. package/dist/src/validation/metadata/ValidationMetadataStore.js +0 -55
  193. package/dist/src/validation/validators/validateModel.js +0 -47
  194. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  195. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  196. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  197. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
  198. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  199. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  200. /package/dist/src/{validation/validators → core/validation/core}/validateIsOptional.js +0 -0
  201. /package/dist/src/{validation/validators → core/validation/validators/is-boolean}/validateIsBoolean.js +0 -0
  202. /package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js +0 -0
  203. /package/dist/src/{validation/validators → core/validation/validators/is-not-empty}/validateIsNotEmpty.js +0 -0
  204. /package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js +0 -0
  205. /package/dist/src/{validation/validators → core/validation/validators/is-present}/validateIsPresent.js +0 -0
  206. /package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js +0 -0
  207. /package/dist/src/{validation/validators → core/validation/validators/max}/validateMax.js +0 -0
  208. /package/dist/src/{validation/validators → core/validation/validators/min}/validateMin.js +0 -0
  209. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  210. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  211. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  212. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -1,57 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { singleton } from '../../injection/index.js';
3
- import { Logger } from '../../logger/Logger.js';
4
- import { io } from 'socket.io-client';
5
- import { devEmitEvent } from './WabotDevSocketContracts.js';
6
-
7
- var WabotDevConnection_1;
8
- let WabotDevConnection = WabotDevConnection_1 = class WabotDevConnection {
9
- devProxy;
10
- devProxySocket = null;
11
- devToken;
12
- logger = new Logger('wabot:dev-connection');
13
- static isTokenAvailable() {
14
- return !!process.env.WABOT_DEV_TOKEN;
15
- }
16
- constructor() {
17
- if (!WabotDevConnection_1.isTokenAvailable()) {
18
- throw new Error('WABOT_DEV_TOKEN is not set in environment variables');
19
- }
20
- this.devToken = process.env.WABOT_DEV_TOKEN;
21
- this.devProxy = process.env.WABOT_DEV_PROXY ?? 'https://proxy.wabot.dev';
22
- }
23
- async getSocket() {
24
- if (this.devProxySocket) {
25
- return this.devProxySocket;
26
- }
27
- return new Promise((resolve, reject) => {
28
- const devProxySocket = io(this.devProxy, { autoConnect: false });
29
- devProxySocket.on('connect', async () => {
30
- try {
31
- const req = {
32
- token: this.devToken,
33
- };
34
- this.logger.debug('dev connection request');
35
- const ack = await devProxySocket.emitWithAck(devEmitEvent.DEV_CONNECTION, req);
36
- if (ack != 'OK') {
37
- return reject(new Error('Dev connection failed'));
38
- }
39
- this.logger.debug('success dev connection');
40
- this.devProxySocket = devProxySocket;
41
- resolve(devProxySocket);
42
- }
43
- catch (err) {
44
- this.logger.error(err);
45
- reject(err);
46
- }
47
- });
48
- devProxySocket.connect();
49
- });
50
- }
51
- };
52
- WabotDevConnection = WabotDevConnection_1 = __decorate([
53
- singleton(),
54
- __metadata("design:paramtypes", [])
55
- ], WabotDevConnection);
56
-
57
- export { WabotDevConnection };
@@ -1,10 +0,0 @@
1
- const devListentEvent = {
2
- DEV_WATSAPP_WEBHOOK: 'dev-whatsapp-webhook',
3
- };
4
- const devEmitEvent = {
5
- DEV_CONNECTION: 'dev-connection',
6
- DEV_SEND_WHATSAPP: 'dev-send-whatsapp',
7
- DEV_SEND_WHATSAPP_TEMPLATE: 'dev-send-whatsapp-template',
8
- };
9
-
10
- export { devEmitEvent, devListentEvent };
@@ -1,20 +0,0 @@
1
- import { container } from '../../injection/index.js';
2
- import { WhatsappChannelConfig } from './WhatsAppChannelConfig.js';
3
- import '../../controller/channel/ChatResolver.js';
4
- import '../../controller/channel/UserResolver.js';
5
- import { ControllerMetadataStore } from '../../controller/metadata/ControllerMetadataStore.js';
6
- import { WhatsAppChannel } from './WhatsAppChannel.js';
7
-
8
- function whatsapp(config) {
9
- return function (target, propertyKey) {
10
- const store = container.resolve(ControllerMetadataStore);
11
- store.saveChannelMetadata({
12
- channelConstructor: WhatsAppChannel,
13
- functionName: propertyKey.toString(),
14
- controllerConstructor: target.constructor,
15
- channelConfig: new WhatsappChannelConfig(config.number),
16
- });
17
- };
18
- }
19
-
20
- export { whatsapp };
@@ -1,59 +0,0 @@
1
- class WhatsAppReceiver {
2
- logger;
3
- listeners = new Map();
4
- constructor(logger) {
5
- this.logger = logger;
6
- }
7
- listenMessage(request) {
8
- this.listeners.set(request.to, request.listener);
9
- }
10
- async handlePayload(payload) {
11
- try {
12
- for (const entry of payload.entry) {
13
- for (const change of entry.changes) {
14
- if (change.field !== 'messages' || !change.value.messages || !change.value.contacts) {
15
- continue;
16
- }
17
- for (const message of change.value.messages) {
18
- const contact = change.value.contacts.find((x) => x.wa_id === message.from);
19
- if (!contact) {
20
- continue;
21
- }
22
- await this.emmitMessage(change.value.metadata, message, contact);
23
- }
24
- }
25
- }
26
- }
27
- catch (err) {
28
- this.logger.error(err);
29
- }
30
- }
31
- async emmitMessage(metadata, message, contact) {
32
- const listener = this.listeners.get(metadata.display_phone_number);
33
- if (!listener) {
34
- return;
35
- }
36
- if (message.type !== 'text') {
37
- this.logger.error(`message type ${message.type} is not supported yet`);
38
- return;
39
- }
40
- const channelName = 'WhatsAppChannel';
41
- const chatConnection = {
42
- id: contact.wa_id,
43
- chatType: 'PRIVATE',
44
- channelName,
45
- };
46
- const userConnection = {
47
- id: contact.wa_id,
48
- channelName,
49
- };
50
- await listener({
51
- chatConnection,
52
- userConnection,
53
- senderName: contact.profile.name,
54
- text: message.text.body,
55
- });
56
- }
57
- }
58
-
59
- export { WhatsAppReceiver };
@@ -1,32 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { Logger } from '../../logger/Logger.js';
3
- import { WhatsAppReceiver } from './WhatsAppReceiver.js';
4
- import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
5
- import { devListentEvent } from '../wabot/WabotDevSocketContracts.js';
6
- import { singleton } from 'tsyringe';
7
- import { container } from '../../injection/index.js';
8
-
9
- let WhatsAppReceiverByDevConnection = class WhatsAppReceiverByDevConnection extends WhatsAppReceiver {
10
- wabotDevConnection;
11
- constructor(wabotDevConnection) {
12
- super(new Logger('wabot:whatsapp-receiver-by-dev-connection'));
13
- this.wabotDevConnection = wabotDevConnection;
14
- }
15
- async connect() {
16
- const socket = await this.wabotDevConnection.getSocket();
17
- socket.on(devListentEvent.DEV_WATSAPP_WEBHOOK, (payload) => {
18
- this.handlePayload(payload);
19
- });
20
- }
21
- };
22
- WhatsAppReceiverByDevConnection = __decorate([
23
- singleton(),
24
- __metadata("design:paramtypes", [WabotDevConnection])
25
- ], WhatsAppReceiverByDevConnection);
26
- if (WabotDevConnection.isTokenAvailable()) {
27
- container.register(WhatsAppReceiver, {
28
- useClass: WhatsAppReceiverByDevConnection,
29
- });
30
- }
31
-
32
- export { WhatsAppReceiverByDevConnection };
@@ -1,63 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { Logger } from '../../logger/Logger.js';
3
- import { WhatsAppReceiver } from './WhatsAppReceiver.js';
4
- import { singleton } from 'tsyringe';
5
- import { ExpressProvider } from '../express/ExpressProvider.js';
6
- import { WhatsAppRepository } from './WhatsAppRepository.js';
7
- import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
8
- import { container } from '../../injection/index.js';
9
-
10
- let WhatsAppReceiverByWebHook = class WhatsAppReceiverByWebHook extends WhatsAppReceiver {
11
- expressProvider;
12
- whatsAppRepository;
13
- expressApp;
14
- webhookPath = '/whatsapp/web-hook/:slug';
15
- constructor(expressProvider, whatsAppRepository) {
16
- super(new Logger('wabot:whatsapp-receiver-by-webhook'));
17
- this.expressProvider = expressProvider;
18
- this.whatsAppRepository = whatsAppRepository;
19
- this.expressApp = this.expressProvider.getExpress();
20
- }
21
- async connect() {
22
- this.expressApp.get(this.webhookPath, async (req, res) => {
23
- try {
24
- let mode = req.query['hub.mode'];
25
- let token = req.query['hub.verify_token'];
26
- let challenge = req.query['hub.challenge'];
27
- if (!mode || !token || !challenge) {
28
- res.sendStatus(400);
29
- return;
30
- }
31
- const whatsApp = await this.whatsAppRepository.findBySlug(req.params.slug);
32
- if (!whatsApp || mode !== 'subscribe' || token !== whatsApp.getVerifyToken()) {
33
- res.sendStatus(403);
34
- return;
35
- }
36
- res.status(200).send(challenge);
37
- }
38
- catch (e) {
39
- this.logger.error(e);
40
- res.sendStatus(500);
41
- return;
42
- }
43
- });
44
- this.expressApp.post(this.webhookPath, (req, res) => {
45
- const payload = req.body;
46
- this.handlePayload(payload);
47
- res.sendStatus(200);
48
- });
49
- this.expressProvider.listen();
50
- }
51
- };
52
- WhatsAppReceiverByWebHook = __decorate([
53
- singleton(),
54
- __metadata("design:paramtypes", [ExpressProvider,
55
- WhatsAppRepository])
56
- ], WhatsAppReceiverByWebHook);
57
- if (!WabotDevConnection.isTokenAvailable()) {
58
- container.register(WhatsAppReceiver, {
59
- useClass: WhatsAppReceiverByWebHook,
60
- });
61
- }
62
-
63
- export { WhatsAppReceiverByWebHook };
@@ -1,61 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { WhatsAppSender } from './WhatsAppSender.js';
3
- import { WabotDevConnection } from '../wabot/WabotDevConnection.js';
4
- import { devEmitEvent } from '../wabot/WabotDevSocketContracts.js';
5
- import { Logger } from '../../logger/Logger.js';
6
- import { ChatRepository } from '../../core/chat/repository/IChatRepository.js';
7
- import '../../core/user/IUserRepository.js';
8
- import { singleton, container } from '../../injection/index.js';
9
- import { ChatResolver } from '../../controller/channel/ChatResolver.js';
10
- import '../../controller/channel/UserResolver.js';
11
- import '../../controller/metadata/ControllerMetadataStore.js';
12
- import { WhatsAppRepository } from './WhatsAppRepository.js';
13
-
14
- let WhatsAppSenderByDevConnection = class WhatsAppSenderByDevConnection extends WhatsAppSender {
15
- wabotDevConnection;
16
- constructor(wabotDevConnection, chatRepository, chatResolver, whatsAppRepository) {
17
- super(new Logger('wabot:whatsapp-sender-by-dev-connection'), chatRepository, chatResolver, whatsAppRepository);
18
- this.wabotDevConnection = wabotDevConnection;
19
- }
20
- async handleSendRequest(request) {
21
- const socket = await this.wabotDevConnection.getSocket();
22
- const req = {
23
- from: request.from,
24
- to: request.to,
25
- message: request.message,
26
- };
27
- const ack = await socket.emitWithAck(devEmitEvent.DEV_SEND_WHATSAPP, req);
28
- if (ack != 'OK') {
29
- throw new Error(`Error sending WhatsApp template: ${ack}`);
30
- }
31
- }
32
- async handleSendTemplateRequest(request) {
33
- const socket = await this.wabotDevConnection.getSocket();
34
- const req = {
35
- from: request.from,
36
- to: request.to,
37
- message: request.templateMessage,
38
- };
39
- const ack = await socket.emitWithAck(devEmitEvent.DEV_SEND_WHATSAPP_TEMPLATE, req);
40
- if (ack != 'OK') {
41
- throw new Error(`Error sending WhatsApp template: ${ack}`);
42
- }
43
- }
44
- async handleGetWhatsAppTemplate(request) {
45
- throw new Error('Not implemented');
46
- }
47
- };
48
- WhatsAppSenderByDevConnection = __decorate([
49
- singleton(),
50
- __metadata("design:paramtypes", [WabotDevConnection,
51
- ChatRepository,
52
- ChatResolver,
53
- WhatsAppRepository])
54
- ], WhatsAppSenderByDevConnection);
55
- if (WabotDevConnection.isTokenAvailable()) {
56
- container.register(WhatsAppSender, {
57
- useClass: WhatsAppSenderByDevConnection,
58
- });
59
- }
60
-
61
- export { WhatsAppSenderByDevConnection };
@@ -1,51 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
3
- import '../core/chat/repository/IChatRepository.js';
4
- import { ChatItem } from '../core/chat/ChatItem.js';
5
- import '../core/user/IUserRepository.js';
6
- import { injectable } from '../injection/index.js';
7
- import { ChatBotAdapter } from './ChatBotAdapter.js';
8
-
9
- let ChatBot = class ChatBot {
10
- memory;
11
- adapter;
12
- constructor(memory, adapter) {
13
- this.memory = memory;
14
- this.adapter = adapter;
15
- this.memory = memory;
16
- }
17
- async sendMessage(message, callback) {
18
- const newChatItem = new ChatItem({
19
- type: 'CONNECTION_MESSAGE',
20
- content: message,
21
- });
22
- await this.memory.create(newChatItem);
23
- this.processLoop(callback);
24
- }
25
- async processLoop(callback) {
26
- const prevChatItems = await this.memory.findLastItems(10);
27
- if (prevChatItems.length === 0) {
28
- return;
29
- }
30
- const lastChatItem = prevChatItems[prevChatItems.length - 1];
31
- const lastItemType = lastChatItem.getType();
32
- if (lastItemType === 'BOT_MESSAGE') {
33
- return;
34
- }
35
- const newChatItem = await this.adapter.generateNextChatItem(prevChatItems);
36
- await this.memory.create(newChatItem);
37
- const newChatItemData = newChatItem.getData();
38
- if (newChatItemData.type === 'BOT_MESSAGE') {
39
- callback(newChatItemData.content);
40
- return;
41
- }
42
- this.processLoop(callback);
43
- }
44
- };
45
- ChatBot = __decorate([
46
- injectable(),
47
- __metadata("design:paramtypes", [ChatMemory,
48
- ChatBotAdapter])
49
- ], ChatBot);
50
-
51
- export { ChatBot };
@@ -1,72 +0,0 @@
1
- import '../core/chat/repository/IChatRepository.js';
2
- import { ChatItem } from '../core/chat/ChatItem.js';
3
- import '../core/user/IUserRepository.js';
4
-
5
- class ChatBotAdapter {
6
- mindset;
7
- constructor(mindset) {
8
- this.mindset = mindset;
9
- }
10
- generateNextChatItem(chatItems) {
11
- throw new Error('Not implemented');
12
- }
13
- async systemPrompt() {
14
- let [identity, skills, limits] = await Promise.all([
15
- this.mindset.identity(),
16
- this.mindset.skills(),
17
- this.mindset.limits(),
18
- ]);
19
- const language = identity.language.replaceAll('#', ' ');
20
- const name = identity.name.replaceAll('#', ' ');
21
- const age = identity.age ? identity.age.toString().replaceAll('#', ' ') : null;
22
- const personality = identity.personality ? identity.personality.replaceAll('#', ' ') : null;
23
- skills = skills.replaceAll('#', ' ');
24
- limits = limits.replaceAll('#', ' ');
25
- const systemPrompt = `
26
- # System Instructions
27
- you should act as a assistant.
28
- your main language is ${language}.
29
- your name is ${name}.
30
- ${age ? 'you are ' + age + ' years old.' : ''}
31
-
32
- ${personality ? '## Personality (in your main language) \n' + personality : ''}
33
-
34
- ## Skills (in your main language)
35
- ${skills}
36
-
37
- ## System limitations (in your main language)
38
- ${limits}
39
-
40
- ## Chat memory
41
- Next you will receive a chat history,
42
- you should use this information to answer the user.
43
- `;
44
- return systemPrompt;
45
- }
46
- async buildBotMessageItem(text) {
47
- const senderName = (await this.mindset.identity()).name;
48
- const newBotMessage = new ChatItem({
49
- type: 'BOT_MESSAGE',
50
- content: {
51
- senderName,
52
- text,
53
- },
54
- });
55
- return newBotMessage;
56
- }
57
- async buildFunctionCallItem(id, functionName, functionArguments) {
58
- const functionResult = await this.mindset.callFunction(functionName, functionArguments);
59
- const newFunctionCall = new ChatItem({
60
- type: 'FUNCTION_CALL',
61
- content: {
62
- id,
63
- name: functionName,
64
- arguments: functionArguments,
65
- result: functionResult,
66
- },
67
- });
68
- return newFunctionCall;
69
- }
70
- }
71
-
72
- export { ChatBotAdapter };
@@ -1,21 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import '../../core/chat/repository/IChatRepository.js';
3
- import { UserRepository } from '../../core/user/IUserRepository.js';
4
- import { singleton } from '../../injection/index.js';
5
-
6
- let UserResolver = class UserResolver {
7
- userRepository;
8
- constructor(userRepository) {
9
- this.userRepository = userRepository;
10
- }
11
- async resolve(connection) {
12
- let user = await this.userRepository.findByConnection(connection);
13
- return user;
14
- }
15
- };
16
- UserResolver = __decorate([
17
- singleton(),
18
- __metadata("design:paramtypes", [UserRepository])
19
- ], UserResolver);
20
-
21
- export { UserResolver };
@@ -1,12 +0,0 @@
1
- class MessageContext {
2
- message;
3
- chat;
4
- user;
5
- constructor(message, chat, user) {
6
- this.message = message;
7
- this.chat = chat;
8
- this.user = user;
9
- }
10
- }
11
-
12
- export { MessageContext };
@@ -1,15 +0,0 @@
1
- import { Persistent } from '../Persistent.js';
2
-
3
- class ChatItem extends Persistent {
4
- getType() {
5
- return this.data.type;
6
- }
7
- getContent() {
8
- return this.data.content;
9
- }
10
- getData() {
11
- return this.data;
12
- }
13
- }
14
-
15
- export { ChatItem };
@@ -1,10 +0,0 @@
1
- class ChatMemory {
2
- findLastItems(count) {
3
- throw new Error('Method not implemented.');
4
- }
5
- create(item) {
6
- throw new Error('Method not implemented.');
7
- }
8
- }
9
-
10
- export { ChatMemory };
@@ -1,19 +0,0 @@
1
- import { __decorate } from 'tslib';
2
- import { singleton } from '../../injection/index.js';
3
-
4
- let UserRepository = class UserRepository {
5
- create(chat) {
6
- throw new Error('Method not implemented.');
7
- }
8
- update(chat) {
9
- throw new Error('Method not implemented.');
10
- }
11
- findByConnection(query) {
12
- throw new Error('Method not implemented.');
13
- }
14
- };
15
- UserRepository = __decorate([
16
- singleton()
17
- ], UserRepository);
18
-
19
- export { UserRepository };
@@ -1,26 +0,0 @@
1
- import { Persistent } from '../Persistent.js';
2
-
3
- class User extends Persistent {
4
- constructor(data) {
5
- super(data);
6
- }
7
- hasConnection(connection) {
8
- for (const con of this.data.connections) {
9
- if (con.channelName === connection.channelName && con.id === connection.id) {
10
- return true;
11
- }
12
- }
13
- return false;
14
- }
15
- getValue(key) {
16
- return this.data.keyValueData[key];
17
- }
18
- setValue(key, value) {
19
- this.data.keyValueData[key] = value;
20
- }
21
- addConnection(connection) {
22
- this.data.connections.push(connection);
23
- }
24
- }
25
-
26
- export { User };
@@ -1,27 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { singleton } from 'tsyringe';
3
-
4
- let WabotEnv = class WabotEnv {
5
- envType;
6
- constructor() {
7
- this.envType = process.env.WABOT_ENV ?? 'development';
8
- }
9
- isDevelopment() {
10
- return this.envType === 'development';
11
- }
12
- isProduction() {
13
- return this.envType === 'production';
14
- }
15
- requireString(varName) {
16
- const value = process.env[varName];
17
- if (!value)
18
- throw new Error(`Env Variable ${varName} is required`);
19
- return value;
20
- }
21
- };
22
- WabotEnv = __decorate([
23
- singleton(),
24
- __metadata("design:paramtypes", [])
25
- ], WabotEnv);
26
-
27
- export { WabotEnv };
@@ -1,4 +0,0 @@
1
- await import('reflect-metadata');
2
- const { injectable, container, singleton, inject } = await import('tsyringe');
3
-
4
- export { container, inject, injectable, singleton };
@@ -1,101 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { injectable } from '../injection/index.js';
3
- import { Mindset } from './IMindset.js';
4
- import { MindsetMetadataStore } from './metadata/MindsetMetadataStore.js';
5
- import { Container } from '../injection/Container.js';
6
-
7
- let MindsetOperator = class MindsetOperator {
8
- mindset;
9
- container;
10
- metadata;
11
- constructor(mindset, container, metadataStore) {
12
- this.mindset = mindset;
13
- this.container = container;
14
- this.metadata = metadataStore.getMindsetMetadata(this.mindset.constructor);
15
- }
16
- identity() {
17
- return this.mindset.identity();
18
- }
19
- skills() {
20
- return this.mindset.skills();
21
- }
22
- limits() {
23
- return this.mindset.limits();
24
- }
25
- async callFunction(name, params) {
26
- const fnMetadata = this.metadata.modules
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
- }
45
- }
46
- async allFunctionsDescriptors() {
47
- return this.metadata.modules
48
- .map((module) => module.functions.map((fn) => this.functionDescriptor(fn)))
49
- .flat();
50
- }
51
- functionDescriptor(fn) {
52
- const description = fn.config.description.replaceAll('#', ' ');
53
- return {
54
- type: 'function',
55
- name: fn.name,
56
- 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
- },
65
- };
66
- }
67
- toolParam(param) {
68
- const addons = {
69
- description: `
70
- ### description (in your main language)
71
- ${param.config.description.replaceAll('#', ' ')}
72
- `,
73
- };
74
- const type = (() => {
75
- if (param.type === Number)
76
- return 'number';
77
- if (param.type === String)
78
- return 'string';
79
- if (param.type === Date) {
80
- addons.description = `${addons.description}
81
- ### format: ISO 8681 - YYYY-MM-DDTHH:mm:ssZ
82
- ${addons.description}
83
- `;
84
- return 'string';
85
- }
86
- throw new Error(`Unsupported type`);
87
- })();
88
- return {
89
- type,
90
- ...addons,
91
- };
92
- }
93
- };
94
- MindsetOperator = __decorate([
95
- injectable(),
96
- __metadata("design:paramtypes", [Mindset,
97
- Container,
98
- MindsetMetadataStore])
99
- ], MindsetOperator);
100
-
101
- export { MindsetOperator };