@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
@@ -0,0 +1,25 @@
1
+ class JwtRefreshTokenRepository {
2
+ find(id) {
3
+ throw new Error('Method not implemented.');
4
+ }
5
+ findOrThrow(id) {
6
+ throw new Error('Method not implemented.');
7
+ }
8
+ findByIds(ids) {
9
+ throw new Error('Method not implemented.');
10
+ }
11
+ findAll(id) {
12
+ throw new Error('Method not implemented.');
13
+ }
14
+ create(item) {
15
+ throw new Error('Method not implemented.');
16
+ }
17
+ update(item) {
18
+ throw new Error('Method not implemented.');
19
+ }
20
+ delete(item) {
21
+ throw new Error('Method not implemented.');
22
+ }
23
+ }
24
+
25
+ export { JwtRefreshTokenRepository };
@@ -0,0 +1,36 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import jwt from 'jsonwebtoken';
3
+ import { JwtConfig } from './JwtConfig.js';
4
+ import { JwtTokenDto } from './JwtTokenDto.js';
5
+ import { injectable } from '../../../core/injection/index.js';
6
+ import { Mapper } from '../../../core/mapper/Mapper.js';
7
+ import { JwtRefreshToken } from './JwtRefreshToken.js';
8
+
9
+ let JwtSigner = class JwtSigner {
10
+ config;
11
+ mapper;
12
+ constructor(config, mapper) {
13
+ this.config = config;
14
+ this.mapper = mapper;
15
+ }
16
+ async signAccessToken(info) {
17
+ const _authInfo = info instanceof JwtRefreshToken
18
+ ? {
19
+ ...info.authInfo,
20
+ refreshTokenId: info.id,
21
+ }
22
+ : info;
23
+ const token = jwt.sign(_authInfo, this.config.secretOrPrivateKey, {
24
+ expiresIn: this.config.accessExpirationSeconds,
25
+ });
26
+ const expiration = new Date().getTime() + this.config.accessExpirationSeconds * 1000;
27
+ return this.mapper.map({ token, expiration }, JwtTokenDto);
28
+ }
29
+ };
30
+ JwtSigner = __decorate([
31
+ injectable(),
32
+ __metadata("design:paramtypes", [JwtConfig,
33
+ Mapper])
34
+ ], JwtSigner);
35
+
36
+ export { JwtSigner };
@@ -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 { isDate } from '../../../core/validation/validators/is-date/@isDate.js';
5
+ import { isNotEmpty } from '../../../core/validation/validators/is-not-empty/@isNotEmpty.js';
6
+ import { isString } from '../../../core/validation/validators/is-string/@isString.js';
7
+
8
+ class JwtTokenDto {
9
+ token;
10
+ expiration;
11
+ }
12
+ __decorate([
13
+ isString(),
14
+ isNotEmpty(),
15
+ __metadata("design:type", String)
16
+ ], JwtTokenDto.prototype, "token", void 0);
17
+ __decorate([
18
+ isDate(),
19
+ __metadata("design:type", Date)
20
+ ], JwtTokenDto.prototype, "expiration", void 0);
21
+
22
+ export { JwtTokenDto };
@@ -0,0 +1,21 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { singleton } from '../../../core/injection/index.js';
3
+ import { Pool } from 'pg';
4
+ import { PgCrudRepository } from '../../../feature/pg/PgCrudRepository.js';
5
+ import { JwtRefreshToken } from './JwtRefreshToken.js';
6
+
7
+ let PgJwtRefreshTokenRepository = class PgJwtRefreshTokenRepository extends PgCrudRepository {
8
+ constructor(pool) {
9
+ super(pool, {
10
+ schema: 'wabot',
11
+ table: 'jwt_refresh_token',
12
+ constructor: JwtRefreshToken,
13
+ });
14
+ }
15
+ };
16
+ PgJwtRefreshTokenRepository = __decorate([
17
+ singleton(),
18
+ __metadata("design:paramtypes", [Pool])
19
+ ], PgJwtRefreshTokenRepository);
20
+
21
+ export { PgJwtRefreshTokenRepository };
@@ -0,0 +1,135 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Env } from '../../../core/env/Env.js';
3
+ import { singleton } from '../../../core/injection/index.js';
4
+ import { Logger } from '../../../core/logger/Logger.js';
5
+ import { Anthropic } from '@anthropic-ai/sdk';
6
+
7
+ let AnthropicChatAdapter = class AnthropicChatAdapter {
8
+ env;
9
+ anthropic;
10
+ logger = new Logger('wabot:anthropic-chat-adapter');
11
+ constructor(env) {
12
+ this.env = env;
13
+ const apiKey = this.env.requireString('ANTHROPIC_API_KEY');
14
+ this.anthropic = new Anthropic({ apiKey });
15
+ }
16
+ async nextItem(req) {
17
+ const tools = req.tools.map((x) => this.mapTool(x));
18
+ const messages = this.mapChatItems(req.prevItems);
19
+ const request = {
20
+ model: req.model,
21
+ max_tokens: 4096,
22
+ system: req.systemPrompt,
23
+ messages,
24
+ tools: tools.length > 0 ? tools : undefined,
25
+ };
26
+ this.logger.debug(`Call Claude API with Request: ${JSON.stringify(request)}`);
27
+ const response = await this.anthropic.messages.create(request);
28
+ return this.mapResponse(response);
29
+ }
30
+ mapChatItems(chatItems) {
31
+ const messages = [];
32
+ for (const chatItem of chatItems) {
33
+ switch (chatItem.type) {
34
+ case 'humanMessage':
35
+ messages.push(this.mapHumanMessage(chatItem.humanMessage));
36
+ break;
37
+ case 'botMessage':
38
+ messages.push(this.mapBotMessage(chatItem.botMessage));
39
+ break;
40
+ case 'functionCall':
41
+ messages.push(...this.mapFunctionCall(chatItem.functionCall));
42
+ break;
43
+ }
44
+ }
45
+ return messages;
46
+ }
47
+ mapHumanMessage(item) {
48
+ if (!item.text) {
49
+ throw new Error('User message content is empty');
50
+ }
51
+ return { role: 'user', content: item.text };
52
+ }
53
+ mapBotMessage(item) {
54
+ if (!item.text) {
55
+ throw new Error('Assistant message content is empty');
56
+ }
57
+ return { role: 'assistant', content: item.text };
58
+ }
59
+ mapFunctionCall(item) {
60
+ return [
61
+ {
62
+ role: 'assistant',
63
+ content: [
64
+ {
65
+ type: 'tool_use',
66
+ id: item.id,
67
+ name: item.name,
68
+ input: JSON.parse(item.arguments || '{}'),
69
+ },
70
+ ],
71
+ },
72
+ {
73
+ role: 'user',
74
+ content: [
75
+ {
76
+ type: 'tool_result',
77
+ tool_use_id: item.id,
78
+ content: item.result || 'No result',
79
+ },
80
+ ],
81
+ },
82
+ ];
83
+ }
84
+ mapTool(tool) {
85
+ return {
86
+ name: tool.name,
87
+ description: tool.description,
88
+ input_schema: {
89
+ type: 'object',
90
+ properties: tool.parameters.reduce((prev, param) => ({
91
+ ...prev,
92
+ [param.name]: { type: param.type, description: param.description },
93
+ }), {}),
94
+ required: tool.parameters.map((param) => param.name),
95
+ },
96
+ };
97
+ }
98
+ mapResponse(response) {
99
+ let chatItem;
100
+ const content = response.content[0];
101
+ if (content.type === 'text') {
102
+ chatItem = { type: 'botMessage', botMessage: { text: content.text } };
103
+ }
104
+ else if (content.type === 'tool_use') {
105
+ chatItem = {
106
+ type: 'functionCall',
107
+ functionCall: {
108
+ id: content.id,
109
+ name: content.name,
110
+ arguments: JSON.stringify(content.input),
111
+ },
112
+ };
113
+ }
114
+ else {
115
+ throw new Error('Not supported Claude Response');
116
+ }
117
+ let usage;
118
+ if (response.usage) {
119
+ usage = {
120
+ inputTokens: response.usage.input_tokens,
121
+ outputTokens: response.usage.output_tokens,
122
+ };
123
+ }
124
+ else {
125
+ throw new Error('Unable to found usage info');
126
+ }
127
+ return { chatItem, usage };
128
+ }
129
+ };
130
+ AnthropicChatAdapter = __decorate([
131
+ singleton(),
132
+ __metadata("design:paramtypes", [Env])
133
+ ], AnthropicChatAdapter);
134
+
135
+ export { AnthropicChatAdapter };
@@ -0,0 +1,137 @@
1
+ import { Logger } from '../../../core/logger/Logger.js';
2
+ import { OpenAI } from 'openai';
3
+
4
+ class DeepSeekChatAdapter {
5
+ deepSeek;
6
+ logger = new Logger('wabot:deepseek-chat-adapter');
7
+ constructor() {
8
+ const apiKey = process.env.DEEPSEEK_API_KEY;
9
+ const baseURL = process.env.DEEPSEEK_BASE_URL;
10
+ if (!apiKey) {
11
+ throw new Error('DEEPSEEK_API_KEY env variable is required');
12
+ }
13
+ if (!baseURL) {
14
+ throw new Error('DEEPSEEK_BASE_URL env variable is required');
15
+ }
16
+ this.deepSeek = new OpenAI({
17
+ apiKey,
18
+ baseURL,
19
+ });
20
+ }
21
+ async nextItem(req) {
22
+ const deepSeekInput = [];
23
+ deepSeekInput.push({ role: 'system', content: req.systemPrompt });
24
+ deepSeekInput.push(...this.mapChatItems(req.prevItems));
25
+ const tools = req.tools.map((x) => this.mapTool(x));
26
+ const response = await this.deepSeek.chat.completions.create({
27
+ model: req.model,
28
+ messages: deepSeekInput,
29
+ tools,
30
+ tool_choice: 'auto',
31
+ });
32
+ return this.mapResponse(response);
33
+ }
34
+ mapChatItems(chatItems) {
35
+ const deepSeekInput = [];
36
+ for (const chatItem of chatItems) {
37
+ switch (chatItem.type) {
38
+ case 'humanMessage':
39
+ deepSeekInput.push(this.mapHumanMessage(chatItem.humanMessage));
40
+ break;
41
+ case 'botMessage':
42
+ deepSeekInput.push(this.mapBotMessage(chatItem.botMessage));
43
+ break;
44
+ case 'functionCall':
45
+ deepSeekInput.push(...this.mapFunctionCall(chatItem.functionCall));
46
+ break;
47
+ }
48
+ }
49
+ return deepSeekInput;
50
+ }
51
+ mapHumanMessage(item) {
52
+ if (!item.text) {
53
+ throw new Error('User message content is empty');
54
+ }
55
+ return { role: 'user', content: item.text };
56
+ }
57
+ mapBotMessage(item) {
58
+ if (!item.text) {
59
+ throw new Error('Assistant message content is empty');
60
+ }
61
+ return { role: 'assistant', content: item.text };
62
+ }
63
+ mapFunctionCall(item) {
64
+ return [
65
+ {
66
+ role: 'assistant',
67
+ tool_calls: [
68
+ {
69
+ id: item.id,
70
+ type: 'function',
71
+ function: {
72
+ name: item.name,
73
+ arguments: item.arguments || '{}',
74
+ },
75
+ },
76
+ ],
77
+ },
78
+ {
79
+ role: 'tool',
80
+ tool_call_id: item.id,
81
+ content: item.result ?? 'No result',
82
+ },
83
+ ];
84
+ }
85
+ mapTool(tool) {
86
+ return {
87
+ type: 'function',
88
+ function: {
89
+ name: tool.name,
90
+ description: tool.description,
91
+ parameters: {
92
+ type: 'object',
93
+ properties: tool.parameters.reduce((prev, param) => ({
94
+ ...prev,
95
+ [param.name]: { type: param.type, description: param.description },
96
+ }), {}),
97
+ required: tool.parameters.map((param) => param.name),
98
+ additionalProperties: false,
99
+ },
100
+ strict: true,
101
+ },
102
+ };
103
+ }
104
+ mapResponse(response) {
105
+ let chatItem;
106
+ const { tool_calls: responseFunctionCall, content: responseText } = response.choices?.[0]?.message ?? {};
107
+ if (responseText) {
108
+ chatItem = { type: 'botMessage', botMessage: { text: responseText } };
109
+ }
110
+ else if (responseFunctionCall && responseFunctionCall[0]?.type === 'function') {
111
+ chatItem = {
112
+ type: 'functionCall',
113
+ functionCall: {
114
+ id: responseFunctionCall[0].id,
115
+ name: responseFunctionCall[0].function.name,
116
+ arguments: responseFunctionCall[0].function.arguments,
117
+ },
118
+ };
119
+ }
120
+ else {
121
+ throw new Error('Not supported DeepSeek Response');
122
+ }
123
+ let usage;
124
+ if (response.usage) {
125
+ usage = {
126
+ inputTokens: response.usage.prompt_tokens,
127
+ outputTokens: response.usage.completion_tokens,
128
+ };
129
+ }
130
+ else {
131
+ throw new Error('Unable to found usage info');
132
+ }
133
+ return { chatItem, usage };
134
+ }
135
+ }
136
+
137
+ export { DeepSeekChatAdapter };
@@ -0,0 +1,128 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Env } from '../../../core/env/Env.js';
3
+ import { singleton } from '../../../core/injection/index.js';
4
+ import { Logger } from '../../../core/logger/Logger.js';
5
+ import OpenAI from 'openai';
6
+
7
+ let GoogleChatAdapter = class GoogleChatAdapter {
8
+ env;
9
+ openai;
10
+ logger = new Logger('wabot:google-chat-adapter');
11
+ constructor(env) {
12
+ this.env = env;
13
+ const apiKey = this.env.requireString('GOOGLE_API_KEY');
14
+ this.openai = new OpenAI({
15
+ apiKey,
16
+ baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
17
+ });
18
+ }
19
+ async nextItem(req) {
20
+ const messages = [];
21
+ messages.push({ role: 'system', content: req.systemPrompt });
22
+ messages.push(...this.mapChatItems(req.prevItems));
23
+ const tools = req.tools.map((x) => this.mapTool(x));
24
+ const request = {
25
+ model: req.model,
26
+ messages,
27
+ tools,
28
+ };
29
+ const response = await this.openai.chat.completions.create(request);
30
+ return this.mapResponse(response);
31
+ }
32
+ mapChatItems(chatItems) {
33
+ const messages = [];
34
+ for (const chatItem of chatItems) {
35
+ switch (chatItem.type) {
36
+ case 'humanMessage':
37
+ messages.push(this.mapHumanMessage(chatItem.humanMessage));
38
+ break;
39
+ case 'botMessage':
40
+ messages.push(this.mapBotMessage(chatItem.botMessage));
41
+ break;
42
+ case 'functionCall':
43
+ messages.push(...this.mapFunctionCall(chatItem.functionCall));
44
+ break;
45
+ }
46
+ }
47
+ return messages;
48
+ }
49
+ mapHumanMessage(item) {
50
+ if (!item.text) {
51
+ throw new Error('User message content is empty');
52
+ }
53
+ return { role: 'user', content: item.text };
54
+ }
55
+ mapBotMessage(item) {
56
+ if (!item.text) {
57
+ throw new Error('Bot message content is empty');
58
+ }
59
+ return { role: 'assistant', content: item.text };
60
+ }
61
+ mapFunctionCall(item) {
62
+ return [
63
+ {
64
+ role: 'function',
65
+ name: item.id,
66
+ content: item.result ?? 'No result',
67
+ },
68
+ ];
69
+ }
70
+ mapTool(tool) {
71
+ return {
72
+ type: 'function',
73
+ function: {
74
+ name: tool.name,
75
+ description: tool.description,
76
+ parameters: {
77
+ type: 'object',
78
+ properties: tool.parameters.reduce((prev, param) => ({
79
+ ...prev,
80
+ [param.name]: {
81
+ type: param.type,
82
+ description: param.description,
83
+ },
84
+ }), {}),
85
+ required: tool.parameters.map((param) => param.name),
86
+ additionalProperties: false,
87
+ }
88
+ },
89
+ };
90
+ }
91
+ mapResponse(response) {
92
+ let chatItem;
93
+ const { tool_calls: responseFunctionCall, content: responseText } = response.choices?.[0]?.message ?? {};
94
+ if (responseText) {
95
+ chatItem = { type: 'botMessage', botMessage: { text: responseText } };
96
+ }
97
+ else if (responseFunctionCall && responseFunctionCall[0]?.type === 'function') {
98
+ chatItem = {
99
+ type: 'functionCall',
100
+ functionCall: {
101
+ id: responseFunctionCall[0].id,
102
+ name: responseFunctionCall[0].function.name,
103
+ arguments: responseFunctionCall[0].function.arguments,
104
+ },
105
+ };
106
+ }
107
+ else {
108
+ throw new Error('Not supported Gemini Response');
109
+ }
110
+ let usage;
111
+ if (response.usage) {
112
+ usage = {
113
+ inputTokens: response.usage.prompt_tokens,
114
+ outputTokens: response.usage.completion_tokens,
115
+ };
116
+ }
117
+ else {
118
+ throw new Error('Unable to found usage info');
119
+ }
120
+ return { chatItem, usage };
121
+ }
122
+ };
123
+ GoogleChatAdapter = __decorate([
124
+ singleton(),
125
+ __metadata("design:paramtypes", [Env])
126
+ ], GoogleChatAdapter);
127
+
128
+ export { GoogleChatAdapter };
@@ -0,0 +1,117 @@
1
+ import { __decorate } from 'tslib';
2
+ import { Logger } from '../../../core/logger/Logger.js';
3
+ import { OpenAI } from 'openai';
4
+ import { singleton } from '../../../core/injection/index.js';
5
+
6
+ let OpenaiChatAdapter = class OpenaiChatAdapter {
7
+ openai = new OpenAI();
8
+ logger = new Logger('wabot:openai-chat-adapter');
9
+ async nextItem(req) {
10
+ const openIaInput = [];
11
+ openIaInput.push({ role: 'system', content: req.systemPrompt });
12
+ openIaInput.push(...this.mapChatItems(req.prevItems));
13
+ const tools = req.tools.map((x) => this.mapTool(x));
14
+ const response = await this.openai.responses.create({
15
+ model: req.model,
16
+ input: openIaInput,
17
+ tools,
18
+ });
19
+ return this.mapResponse(response);
20
+ }
21
+ mapChatItems(chatItems) {
22
+ const openIaInput = [];
23
+ for (const chatItem of chatItems) {
24
+ switch (chatItem.type) {
25
+ case 'humanMessage':
26
+ openIaInput.push(this.mapConectionMessage(chatItem.humanMessage));
27
+ break;
28
+ case 'botMessage':
29
+ openIaInput.push(this.mapBotMessage(chatItem.botMessage));
30
+ break;
31
+ case 'functionCall':
32
+ openIaInput.push(...this.mapFunctionCall(chatItem.functionCall));
33
+ break;
34
+ }
35
+ }
36
+ return openIaInput;
37
+ }
38
+ mapConectionMessage(item) {
39
+ if (!item.text) {
40
+ throw new Error('System message content is empty');
41
+ }
42
+ return { role: 'user', content: item.text };
43
+ }
44
+ mapBotMessage(item) {
45
+ if (!item.text) {
46
+ throw new Error('System message content is empty');
47
+ }
48
+ return { role: 'assistant', content: item.text };
49
+ }
50
+ mapFunctionCall(item) {
51
+ return [
52
+ {
53
+ type: 'function_call',
54
+ call_id: item.id,
55
+ name: item.name,
56
+ arguments: JSON.stringify(item.arguments),
57
+ },
58
+ {
59
+ type: 'function_call_output',
60
+ call_id: item.id,
61
+ output: item.result ?? 'Not result',
62
+ },
63
+ ];
64
+ }
65
+ mapTool(tool) {
66
+ return {
67
+ type: 'function',
68
+ name: tool.name,
69
+ description: tool.description,
70
+ parameters: {
71
+ type: 'object',
72
+ properties: tool.parameters.reduce((prev, param) => ({
73
+ ...prev,
74
+ [param.name]: { type: param.type, description: param.description },
75
+ }), {}),
76
+ required: tool.parameters.map((param) => param.name),
77
+ additionalProperties: false,
78
+ },
79
+ strict: true,
80
+ };
81
+ }
82
+ mapResponse(response) {
83
+ let chatItem;
84
+ if (response.output_text) {
85
+ chatItem = { type: 'botMessage', botMessage: { text: response.output_text } };
86
+ }
87
+ else if (response.output && response.output[0]?.type == 'function_call') {
88
+ chatItem = {
89
+ type: 'functionCall',
90
+ functionCall: {
91
+ id: response.output[0].call_id,
92
+ name: response.output[0].name,
93
+ arguments: response.output[0].arguments,
94
+ },
95
+ };
96
+ }
97
+ else {
98
+ throw new Error('Not supported OpenIA Response');
99
+ }
100
+ let usage;
101
+ if (response.usage) {
102
+ usage = {
103
+ inputTokens: response.usage.input_tokens,
104
+ outputTokens: response.usage.output_tokens,
105
+ };
106
+ }
107
+ else {
108
+ throw new Error('Unable to found usage info');
109
+ }
110
+ return { chatItem, usage };
111
+ }
112
+ };
113
+ OpenaiChatAdapter = __decorate([
114
+ singleton()
115
+ ], OpenaiChatAdapter);
116
+
117
+ export { OpenaiChatAdapter };
@@ -1,7 +1,9 @@
1
- import '../../../../core/chat/repository/IChatRepository.js';
2
- import { ChatItem } from '../../../../core/chat/ChatItem.js';
3
- import '../../../../core/user/IUserRepository.js';
4
- import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
1
+ import { PgCrudRepository } from '../../../feature/pg/PgCrudRepository.js';
2
+ import '../../../feature/chat-bot/ChatBot.js';
3
+ import { ChatItem } from '../../../feature/chat-bot/ChatItem.js';
4
+ import '../../../core/injection/index.js';
5
+ import 'uuid';
6
+ import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
5
7
 
6
8
  class PgChatMemory extends PgCrudRepository {
7
9
  chatId;
@@ -1,11 +1,12 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
- import '../../../../core/chat/repository/IChatRepository.js';
3
- import { Chat } from '../../../../core/chat/Chat.js';
4
- import '../../../../core/user/IUserRepository.js';
5
- import { singleton } from '../../../../injection/index.js';
6
2
  import { Pool } from 'pg';
7
3
  import { PgChatMemory } from './PgChatMemory.js';
8
- import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
4
+ import { singleton } from '../../../core/injection/index.js';
5
+ import { PgCrudRepository } from '../../../feature/pg/PgCrudRepository.js';
6
+ import { Chat } from '../../../feature/chat-bot/Chat.js';
7
+ import '../../../feature/chat-bot/ChatBot.js';
8
+ import 'uuid';
9
+ import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
9
10
 
10
11
  let PgChatRepository = class PgChatRepository extends PgCrudRepository {
11
12
  constructor(pool) {
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { v4 } from 'uuid';
3
3
  import { RamChatMemory } from './RamChatMemory.js';
4
- import { singleton } from '../../../../injection/index.js';
4
+ import { singleton } from '../../../core/injection/index.js';
5
5
 
6
6
  let RamChatRepository = class RamChatRepository {
7
7
  items = [];
@@ -16,7 +16,7 @@ let RamChatRepository = class RamChatRepository {
16
16
  this.items.push(chat);
17
17
  const memory = {
18
18
  memory: new RamChatMemory(),
19
- chatId: chat.getId(),
19
+ chatId: chat.id,
20
20
  };
21
21
  this.memories.push(memory);
22
22
  }