@wabot-dev/framework 0.1.0-beta.3 → 0.1.0-beta.30

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 (149) hide show
  1. package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
  2. package/dist/src/addon/chat-bot/claude/ClaudeChatBotAdapter.js +107 -0
  3. package/dist/src/addon/chat-bot/deepseek/DeepSeekChatBotAdapter.js +103 -0
  4. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +101 -0
  5. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +5 -4
  6. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +5 -5
  7. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
  8. package/dist/src/addon/chat-controller/cmd/@cmd.js +22 -0
  9. package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
  10. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +8 -4
  11. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -23
  12. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
  13. package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +8 -4
  14. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  15. package/dist/src/{channels → addon/chat-controller}/whatsapp/@whatsapp.js +8 -4
  16. package/dist/src/addon/chat-controller/whatsapp/EnvWhatsAppRepository.js +49 -0
  17. package/dist/src/{channels/whatsapp/WhatsAppRepository.js → addon/chat-controller/whatsapp/PgWhatsAppRepository.js} +5 -5
  18. package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevConnection.js +2 -2
  19. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +5 -4
  20. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
  21. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiver.js +4 -7
  22. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByDevConnection.js +3 -9
  23. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByWebHook.js +2 -9
  24. package/dist/src/{core/chat/repository/IChatMemory.js → addon/chat-controller/whatsapp/WhatsAppRepository.js} +4 -4
  25. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +39 -10
  26. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByCloudApi.js +10 -13
  27. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByDevConnection.js +13 -15
  28. package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
  29. package/dist/src/{repository → addon/repository}/pg/PgCrudRepository.js +23 -2
  30. package/dist/src/{repository → addon/repository}/pg/PgRepositoryBase.js +2 -2
  31. package/dist/src/addon/rest-controller/jwt/@jwtGuard.js +17 -0
  32. package/dist/src/addon/rest-controller/jwt/Jwt.js +36 -0
  33. package/dist/src/addon/rest-controller/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
  34. package/dist/src/addon/rest-controller/jwt/JwtConfig.js +28 -0
  35. package/dist/src/addon/rest-controller/jwt/JwtGuardMiddleware.js +50 -0
  36. package/dist/src/addon/rest-controller/jwt/JwtRefreshToken.js +9 -0
  37. package/dist/src/addon/rest-controller/jwt/JwtRefreshTokenRepository.js +21 -0
  38. package/dist/src/addon/rest-controller/jwt/JwtSigner.js +48 -0
  39. package/dist/src/addon/rest-controller/jwt/JwtTokenDto.js +22 -0
  40. package/dist/src/addon/validation/is-boolean/@isBoolean.js +17 -0
  41. package/dist/src/addon/validation/is-boolean/validateIsBoolean.js +12 -0
  42. package/dist/src/addon/validation/is-date/@isDate.js +17 -0
  43. package/dist/src/addon/validation/is-date/validateIsDate.js +16 -0
  44. package/dist/src/addon/validation/is-not-empty/@isNotEmpty.js +17 -0
  45. package/dist/src/addon/validation/is-not-empty/validateIsNotEmpty.js +12 -0
  46. package/dist/src/addon/validation/is-number/@isNumber.js +17 -0
  47. package/dist/src/addon/validation/is-number/validateIsNumber.js +12 -0
  48. package/dist/src/addon/validation/is-present/@isPresent.js +17 -0
  49. package/dist/src/addon/validation/is-present/validateIsPresent.js +12 -0
  50. package/dist/src/addon/validation/is-string/@isString.js +17 -0
  51. package/dist/src/addon/validation/is-string/validateIsString.js +12 -0
  52. package/dist/src/addon/validation/max/@max.js +18 -0
  53. package/dist/src/addon/validation/max/validateMax.js +17 -0
  54. package/dist/src/addon/validation/min/@min.js +18 -0
  55. package/dist/src/addon/validation/min/validateMin.js +17 -0
  56. package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -9
  57. package/dist/src/core/env/Env.js +39 -0
  58. package/dist/src/core/error/CustomError.js +15 -0
  59. package/dist/src/core/injection/index.js +4 -0
  60. package/dist/src/core/mapper/Mapper.js +42 -0
  61. package/dist/src/core/random/Random.js +37 -0
  62. package/dist/src/core/storable/Storable.js +8 -0
  63. package/dist/src/core/validation/metadata/@isArray.js +18 -0
  64. package/dist/src/core/validation/metadata/@isModel.js +18 -0
  65. package/dist/src/core/validation/metadata/@isOptional.js +17 -0
  66. package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
  67. package/dist/src/core/validation/modelInfo.js +9 -0
  68. package/dist/src/core/validation/validate.js +11 -0
  69. package/dist/src/core/validation/validators/validateArray.js +41 -0
  70. package/dist/src/core/validation/validators/validateIsOptional.js +5 -0
  71. package/dist/src/core/validation/validators/validateModel.js +34 -0
  72. package/dist/src/feature/async/@command.js +11 -0
  73. package/dist/src/feature/async/@commandHandler.js +12 -0
  74. package/dist/src/feature/async/Async.js +38 -0
  75. package/dist/src/feature/async/Command.js +9 -0
  76. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  77. package/dist/src/feature/async/Job.js +24 -0
  78. package/dist/src/feature/async/JobRepository.js +31 -0
  79. package/dist/src/feature/async/JobRunner.js +45 -0
  80. package/dist/src/feature/async/JobsEventsHub.js +24 -0
  81. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  82. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  83. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  84. package/dist/src/feature/chat-bot/ChatBot.js +50 -0
  85. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  86. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  87. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  88. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  89. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  90. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  91. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +5 -4
  92. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  93. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  94. package/dist/src/feature/chat-controller/runChatControllers.js +69 -0
  95. package/dist/src/{channels → feature}/express/ExpressProvider.js +1 -1
  96. package/dist/src/{channels → feature}/http/HttpServerProvider.js +1 -1
  97. package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +66 -42
  98. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  99. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  100. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  101. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  102. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  103. package/dist/src/feature/rest-controller/auth/Auth.js +24 -0
  104. package/dist/src/feature/rest-controller/metadata/@get.js +19 -0
  105. package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
  106. package/dist/src/feature/rest-controller/metadata/@post.js +19 -0
  107. package/dist/src/feature/rest-controller/metadata/@restController.js +15 -0
  108. package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
  109. package/dist/src/feature/rest-controller/runRestControllers.js +75 -0
  110. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +1 -1
  111. package/dist/src/index.d.ts +785 -475
  112. package/dist/src/index.js +118 -74
  113. package/package.json +6 -3
  114. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
  115. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -84
  116. package/dist/src/channels/cmd/@cmd.js +0 -18
  117. package/dist/src/chatbot/ChatBot.js +0 -51
  118. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  119. package/dist/src/controller/channel/UserResolver.js +0 -21
  120. package/dist/src/core/IMessageContext.js +0 -12
  121. package/dist/src/core/chat/ChatItem.js +0 -15
  122. package/dist/src/core/user/IUserRepository.js +0 -19
  123. package/dist/src/core/user/User.js +0 -26
  124. package/dist/src/env/WabotEnv.js +0 -21
  125. package/dist/src/injection/index.js +0 -4
  126. package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
  127. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  128. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  129. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  130. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  131. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  132. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  133. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  134. package/dist/src/pre-made/service/EmailService.js +0 -13
  135. package/dist/src/pre-made/service/OtpService.js +0 -14
  136. package/dist/src/server/prepareChatContainer.js +0 -43
  137. package/dist/src/server/runChannel.js +0 -27
  138. package/dist/src/server/runServer.js +0 -40
  139. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  140. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  141. /package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevSocketContracts.js +0 -0
  142. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  143. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  144. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  145. /package/dist/src/{mindset → feature/mindset}/IMindset.js +0 -0
  146. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  147. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  148. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  149. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -0,0 +1,26 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Pool } from 'pg';
3
+ import { singleton } from '../../../core/injection/index.js';
4
+ import { PgCrudRepository } from '../../repository/pg/PgCrudRepository.js';
5
+ import '../../../feature/async/CommandMetadataStore.js';
6
+ import '../../../feature/async/Async.js';
7
+ import { Job } from '../../../feature/async/Job.js';
8
+ import '../../../feature/async/JobRepository.js';
9
+ import '../../../feature/async/JobRunner.js';
10
+ import '../../../feature/async/JobsEventsHub.js';
11
+
12
+ let PgJobRepository = class PgJobRepository extends PgCrudRepository {
13
+ constructor(pool) {
14
+ super(pool, {
15
+ schema: 'wabot',
16
+ table: 'job',
17
+ constructor: Job,
18
+ });
19
+ }
20
+ };
21
+ PgJobRepository = __decorate([
22
+ singleton(),
23
+ __metadata("design:paramtypes", [Pool])
24
+ ], PgJobRepository);
25
+
26
+ export { PgJobRepository };
@@ -0,0 +1,107 @@
1
+ // import { injectable } from '@/injection'
2
+ // import { Anthropic } from '@anthropic-ai/sdk'
3
+ // import { ChatBotAdapter } from '@/chatbot'
4
+ // import type { ChatItem } from '@/core'
5
+ // import { MindsetOperator } from '@/mindset'
6
+ // import { Logger } from '@/logger'
7
+ class DummyClaudeChatBotAdapter {
8
+ }
9
+ // @injectable()
10
+ // export class ClaudeChatBotAdapter extends ChatBotAdapter {
11
+ // private anthropic: Anthropic
12
+ // private model: string
13
+ // private logger = new Logger('wabot:claude-chat-bot-adapter')
14
+ // constructor(mindset: MindsetOperator) {
15
+ // super(mindset)
16
+ // const apiKey = process.env.CLAUDE_API_KEY
17
+ // if (!apiKey) {
18
+ // throw new Error(`CLAUDE_API_KEY env variable is required`)
19
+ // }
20
+ // const model = process.env.CLAUDE_CHAT_MODEL
21
+ // if (!model) {
22
+ // throw new Error(`CLAUDE_CHAT_MODEL env variable is required`)
23
+ // }
24
+ // this.anthropic = new Anthropic({ apiKey })
25
+ // this.model = model
26
+ // }
27
+ // override async generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem> {
28
+ // const systemPrompt = await this.systemPrompt()
29
+ // const tools = (await this.mindset.allFunctionsDescriptors()).map((fn) => {
30
+ // return {
31
+ // name: fn.name,
32
+ // description: fn.description,
33
+ // input_schema: {
34
+ // ...fn.parameters,
35
+ // type: 'object' as const
36
+ // }
37
+ // }
38
+ // })
39
+ // const messages = this.mapChatItems(chatItems)
40
+ // const request = {
41
+ // model: this.model,
42
+ // max_tokens: 4096,
43
+ // system: systemPrompt,
44
+ // messages,
45
+ // tools: tools.length > 0 ? tools : undefined,
46
+ // }
47
+ // this.logger.debug(`Call Claude API with Request: ${JSON.stringify(request)}`)
48
+ // const response = await this.anthropic.messages.create(request)
49
+ // let newChatItem: ChatItem
50
+ // const content = response.content[0]
51
+ // if (content.type === 'text') {
52
+ // newChatItem = await this.buildBotMessageItem(content.text)
53
+ // } else if (content.type === 'tool_use') {
54
+ // newChatItem = await this.buildFunctionCallItem(
55
+ // content.id,
56
+ // content.name,
57
+ // JSON.stringify(content.input),
58
+ // )
59
+ // } else {
60
+ // throw new Error('Not supported Claude Response')
61
+ // }
62
+ // return newChatItem
63
+ // }
64
+ // private mapChatItems(chatItems: ChatItem[]): Anthropic.Messages.MessageParam[] {
65
+ // // const messages: Anthropic.Messages.MessageParam[] = []
66
+ // // for (const item of chatItems) {
67
+ // // const itemData = item.getData()
68
+ // // if (itemData.type === 'CONNECTION_MESSAGE') {
69
+ // // if (!itemData.content.text) {
70
+ // // throw new Error('User message content is empty')
71
+ // // }
72
+ // // messages.push({ role: 'user', content: itemData.content.text })
73
+ // // } else if (itemData.type === 'BOT_MESSAGE') {
74
+ // // if (!itemData.content.text) {
75
+ // // throw new Error('Assistant message content is empty')
76
+ // // }
77
+ // // messages.push({ role: 'assistant', content: itemData.content.text })
78
+ // // } else if (itemData.type === 'FUNCTION_CALL') {
79
+ // // messages.push({
80
+ // // role: 'assistant',
81
+ // // content: [
82
+ // // {
83
+ // // type: 'tool_use',
84
+ // // id: itemData.content.id,
85
+ // // name: itemData.content.name,
86
+ // // input: JSON.parse(itemData.content.arguments || '{}')
87
+ // // }
88
+ // // ]
89
+ // // })
90
+ // // messages.push({
91
+ // // role: 'user',
92
+ // // content: [
93
+ // // {
94
+ // // type: 'tool_result',
95
+ // // tool_use_id: itemData.content.id,
96
+ // // content: itemData.content.result || 'No result'
97
+ // // }
98
+ // // ]
99
+ // // })
100
+ // // }
101
+ // // }
102
+ // // return messages
103
+ // return []
104
+ // }
105
+ // }
106
+
107
+ export { DummyClaudeChatBotAdapter };
@@ -0,0 +1,103 @@
1
+ // import { injectable } from '@/injection'
2
+ // import { OpenAI } from 'openai'
3
+ // import { ChatBotAdapter } from '@/chatbot'
4
+ // import type { ChatItem } from '@/core'
5
+ // import { MindsetOperator } from '@/mindset'
6
+ class DummyDeepSeekChatBotAdapter {
7
+ }
8
+ // @injectable()
9
+ // export class DeepSeekChatBotAdapter extends ChatBotAdapter {
10
+ // private deepSeek: OpenAI
11
+ // private model: string
12
+ // constructor(mindset: MindsetOperator) {
13
+ // super(mindset)
14
+ // const model = process.env.DEEPSEEK_CHAT_MODEL
15
+ // const apiKey = process.env.DEEPSEEK_API_KEY
16
+ // const baseURL = process.env.DEEPSEEK_BASE_URL
17
+ // this.validateEnvVariables([model, apiKey, baseURL])
18
+ // this.model = model || 'deepseek-chat'
19
+ // this.deepSeek = new OpenAI({
20
+ // apiKey: apiKey,
21
+ // baseURL: baseURL,
22
+ // })
23
+ // }
24
+ // validateEnvVariables(envVariables: (string | undefined)[]): void {
25
+ // envVariables.forEach((envVariable) => {
26
+ // if (!envVariable) {
27
+ // throw new Error('Missing environment variable')
28
+ // }
29
+ // })
30
+ // }
31
+ // override async generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem> {
32
+ // const systemPrompt = await this.systemPrompt()
33
+ // const tools = (await this.mindset.allFunctionsDescriptors()).map((fn) => {
34
+ // const parameters = { ...fn.parameters, additionalProperties: false, type: 'object' }
35
+ // return {
36
+ // type: 'function',
37
+ // function: { name: fn.name, description: fn.description, parameters, strict: true },
38
+ // } as const
39
+ // })
40
+ // const response = await this.deepSeek.chat.completions.create({
41
+ // model: this.model,
42
+ // messages: [{ role: 'system', content: systemPrompt }, ...this.mapChatItems(chatItems)],
43
+ // tools: tools,
44
+ // tool_choice: 'auto',
45
+ // })
46
+ // let newChatItem: ChatItem
47
+ // const { tool_calls: responseFunctionCall, content: responseText } =
48
+ // response.choices?.[0]?.message ?? {}
49
+ // if (responseText) {
50
+ // newChatItem = await this.buildBotMessageItem(responseText)
51
+ // } else if (responseFunctionCall && responseFunctionCall[0]?.type == 'function') {
52
+ // newChatItem = await this.buildFunctionCallItem(
53
+ // responseFunctionCall[0].id,
54
+ // responseFunctionCall[0].function.name,
55
+ // responseFunctionCall[0].function.arguments,
56
+ // )
57
+ // } else {
58
+ // throw new Error('Not supported DeepSeek Response')
59
+ // }
60
+ // return newChatItem
61
+ // }
62
+ // private mapChatItems(chatItems: ChatItem[]): OpenAI.Chat.ChatCompletionMessageParam[] {
63
+ // // const deepSeekInput: OpenAI.Chat.ChatCompletionMessageParam[] = []
64
+ // // for (const item of chatItems) {
65
+ // // const itemData = item.getData()
66
+ // // if (itemData.type === 'CONNECTION_MESSAGE') {
67
+ // // if (!itemData.content.text) {
68
+ // // throw new Error('System message content is empty')
69
+ // // }
70
+ // // deepSeekInput.push({ role: 'user', content: itemData.content.text })
71
+ // // } else if (itemData.type === 'BOT_MESSAGE') {
72
+ // // if (!itemData.content.text) {
73
+ // // throw new Error('System message content is empty')
74
+ // // }
75
+ // // deepSeekInput.push({ role: 'assistant', content: itemData.content.text })
76
+ // // }
77
+ // // if (itemData.type === 'FUNCTION_CALL') {
78
+ // // deepSeekInput.push({
79
+ // // role: 'assistant',
80
+ // // tool_calls: [
81
+ // // {
82
+ // // id: itemData.content.id,
83
+ // // type: 'function',
84
+ // // function: {
85
+ // // name: itemData.content.name,
86
+ // // arguments: JSON.stringify(itemData.content.arguments),
87
+ // // },
88
+ // // },
89
+ // // ],
90
+ // // })
91
+ // // deepSeekInput.push({
92
+ // // role: 'tool',
93
+ // // tool_call_id: itemData.content.id,
94
+ // // content: itemData.content.result ?? 'No result',
95
+ // // })
96
+ // // }
97
+ // // }
98
+ // // return deepSeekInput
99
+ // return []
100
+ // }
101
+ // }
102
+
103
+ export { DummyDeepSeekChatBotAdapter };
@@ -0,0 +1,101 @@
1
+ import { Logger } from '../../../core/logger/Logger.js';
2
+ import { OpenAI } from 'openai';
3
+
4
+ class OpenaiChatAdapter {
5
+ openai = new OpenAI();
6
+ logger = new Logger('wabot:openai-chat-adapter');
7
+ async nextItem(req) {
8
+ const openIaInput = [];
9
+ openIaInput.push({ role: 'system', content: req.systemPrompt });
10
+ openIaInput.push(...this.mapChatItems(req.prevItems));
11
+ const tools = req.tools.map((x) => this.mapTool(x));
12
+ const response = await this.openai.responses.create({
13
+ model: req.model,
14
+ input: openIaInput,
15
+ tools,
16
+ });
17
+ return this.mapResponse(response);
18
+ }
19
+ mapChatItems(chatItems) {
20
+ const openIaInput = [];
21
+ for (const chatItem of chatItems) {
22
+ switch (chatItem.type) {
23
+ case 'humanMessage':
24
+ openIaInput.push(this.mapConectionMessage(chatItem.humanMessage));
25
+ break;
26
+ case 'botMessage':
27
+ openIaInput.push(this.mapBotMessage(chatItem.botMessage));
28
+ break;
29
+ case 'functionCall':
30
+ openIaInput.push(...this.mapFunctionCall(chatItem.functionCall));
31
+ break;
32
+ }
33
+ }
34
+ return openIaInput;
35
+ }
36
+ mapConectionMessage(item) {
37
+ if (!item.text) {
38
+ throw new Error('System message content is empty');
39
+ }
40
+ return { role: 'user', content: item.text };
41
+ }
42
+ mapBotMessage(item) {
43
+ if (!item.text) {
44
+ throw new Error('System message content is empty');
45
+ }
46
+ return { role: 'assistant', content: item.text };
47
+ }
48
+ mapFunctionCall(item) {
49
+ return [
50
+ {
51
+ type: 'function_call',
52
+ call_id: item.id,
53
+ name: item.name,
54
+ arguments: JSON.stringify(item.arguments),
55
+ },
56
+ {
57
+ type: 'function_call_output',
58
+ call_id: item.id,
59
+ output: item.result ?? 'Not result',
60
+ },
61
+ ];
62
+ }
63
+ mapTool(tool) {
64
+ return {
65
+ type: 'function',
66
+ name: tool.name,
67
+ description: tool.description,
68
+ parameters: {
69
+ type: 'object',
70
+ properties: tool.parameters.reduce((prev, param) => ({
71
+ ...prev,
72
+ [param.name]: { type: param.type, description: param.description },
73
+ }), {}),
74
+ required: tool.parameters.map((param) => param.name),
75
+ },
76
+ strict: true,
77
+ };
78
+ }
79
+ mapResponse(response) {
80
+ let newItem;
81
+ if (response.output_text) {
82
+ newItem = { type: 'botMessage', botMessage: { text: response.output_text } };
83
+ }
84
+ else if (response.output && response.output[0]?.type == 'function_call') {
85
+ newItem = {
86
+ type: 'functionCall',
87
+ functionCall: {
88
+ id: response.output[0].call_id,
89
+ name: response.output[0].name,
90
+ arguments: response.output[0].arguments,
91
+ },
92
+ };
93
+ }
94
+ else {
95
+ throw new Error('Not supported OpenIA Response');
96
+ }
97
+ return newItem;
98
+ }
99
+ }
100
+
101
+ export { OpenaiChatAdapter };
@@ -1,7 +1,8 @@
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 '../../repository/pg/PgCrudRepository.js';
2
+ import { ChatItem } from '../../../feature/chat-bot/ChatItem.js';
3
+ import '../../../core/injection/index.js';
4
+ import 'uuid';
5
+ import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
5
6
 
6
7
  class PgChatMemory extends PgCrudRepository {
7
8
  chatId;
@@ -1,11 +1,11 @@
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 '../../repository/pg/PgCrudRepository.js';
6
+ import { Chat } from '../../../feature/chat-bot/Chat.js';
7
+ import 'uuid';
8
+ import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
9
9
 
10
10
  let PgChatRepository = class PgChatRepository extends PgCrudRepository {
11
11
  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
  }
@@ -0,0 +1,22 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
3
+ import '../../../feature/chat-controller/ChatResolver.js';
4
+ import 'uuid';
5
+ import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
6
+ import 'reflect-metadata';
7
+ import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
8
+ import '../../../feature/mindset/MindsetOperator.js';
9
+ import { CmdChannel } from './CmdChannel.js';
10
+
11
+ function cmd() {
12
+ return function (target, propertyKey) {
13
+ const store = container.resolve(ControllerMetadataStore);
14
+ store.saveChannelMetadata({
15
+ channelConstructor: CmdChannel,
16
+ functionName: propertyKey.toString(),
17
+ controllerConstructor: target.constructor,
18
+ });
19
+ };
20
+ }
21
+
22
+ export { cmd };
@@ -1,25 +1,15 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { ChatResolver } from '../../controller/channel/ChatResolver.js';
3
- import { UserResolver } from '../../controller/channel/UserResolver.js';
4
- import { injectable } from '../../injection/index.js';
5
- import '../../controller/metadata/ControllerMetadataStore.js';
1
+ import { __decorate } from 'tslib';
2
+ import { injectable } from '../../../core/injection/index.js';
6
3
  import * as readline from 'readline';
7
4
 
8
5
  var CmdChannel_1;
9
6
  const chatId = 'cmd';
10
- const userId = 'cmd';
11
7
  let CmdChannel = CmdChannel_1 = class CmdChannel {
12
- chatResolver;
13
- userResolver;
14
8
  rl = readline.createInterface({
15
9
  input: process.stdin,
16
10
  output: process.stdout,
17
11
  });
18
12
  callBack = null;
19
- constructor(chatResolver, userResolver) {
20
- this.chatResolver = chatResolver;
21
- this.userResolver = userResolver;
22
- }
23
13
  listen(callback) {
24
14
  this.callBack = callback;
25
15
  }
@@ -39,22 +29,12 @@ let CmdChannel = CmdChannel_1 = class CmdChannel {
39
29
  chatType: 'PRIVATE',
40
30
  channelName: CmdChannel_1.name,
41
31
  };
42
- const chat = await this.chatResolver.resolve(chatConnection);
43
- const userConnection = {
44
- id: userId,
45
- channelName: CmdChannel_1.name,
46
- };
47
- const user = await this.userResolver.resolve(userConnection);
48
32
  if (!this.callBack)
49
33
  return;
50
34
  this.callBack({
51
- chat,
52
- user,
35
+ chatConnection,
53
36
  message: {
54
- chatConnection,
55
- userConnection,
56
37
  text: trimmedInput,
57
- senderName: 'cmd',
58
38
  },
59
39
  reply: (message) => {
60
40
  console.log(`\n[${message.senderName}]: ${message.text}\n`);
@@ -65,9 +45,7 @@ let CmdChannel = CmdChannel_1 = class CmdChannel {
65
45
  }
66
46
  };
67
47
  CmdChannel = CmdChannel_1 = __decorate([
68
- injectable(),
69
- __metadata("design:paramtypes", [ChatResolver,
70
- UserResolver])
48
+ injectable()
71
49
  ], CmdChannel);
72
50
 
73
51
  export { CmdChannel };
@@ -1,7 +1,11 @@
1
- import '../../controller/channel/ChatResolver.js';
2
- import '../../controller/channel/UserResolver.js';
3
- import { container } from '../../injection/index.js';
4
- import { ControllerMetadataStore } from '../../controller/metadata/ControllerMetadataStore.js';
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
3
+ import '../../../feature/chat-controller/ChatResolver.js';
4
+ import 'uuid';
5
+ import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
6
+ import 'reflect-metadata';
7
+ import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
8
+ import '../../../feature/mindset/MindsetOperator.js';
5
9
  import { SocketChannel } from './SocketChannel.js';
6
10
  import { SocketChannelConfig } from './SocketChannelConfig.js';
7
11
 
@@ -1,24 +1,17 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
+ import { injectable } from '../../../core/injection/index.js';
3
+ import { SocketServerProvider } from '../../../feature/socket/SocketServerProvider.js';
2
4
  import { SocketChannelConfig } from './SocketChannelConfig.js';
3
- import { injectable } from '../../injection/index.js';
4
- import { ChatResolver } from '../../controller/channel/ChatResolver.js';
5
- import { UserResolver } from '../../controller/channel/UserResolver.js';
6
- import '../../controller/metadata/ControllerMetadataStore.js';
7
- import { SocketServerProvider } from './SocketServerProvider.js';
8
5
 
9
6
  var SocketChannel_1;
10
7
  let SocketChannel = SocketChannel_1 = class SocketChannel {
11
8
  config;
12
9
  socketServerProvider;
13
- chatResolver;
14
- userResolver;
15
10
  callBack = null;
16
11
  server;
17
- constructor(config, socketServerProvider, chatResolver, userResolver) {
12
+ constructor(config, socketServerProvider) {
18
13
  this.config = config;
19
14
  this.socketServerProvider = socketServerProvider;
20
- this.chatResolver = chatResolver;
21
- this.userResolver = userResolver;
22
15
  this.server = this.socketServerProvider.getSocketServer();
23
16
  }
24
17
  listen(callback) {
@@ -42,20 +35,11 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
42
35
  chatType: 'PRIVATE',
43
36
  channelName: SocketChannel_1.name,
44
37
  };
45
- const chat = await this.chatResolver.resolve(chatConnection);
46
- const userConnection = {
47
- id: message.userId,
48
- channelName: SocketChannel_1.name,
49
- };
50
- const user = await this.userResolver.resolve(userConnection);
51
38
  if (!this.callBack)
52
39
  return;
53
40
  this.callBack({
54
- chat,
55
- user,
41
+ chatConnection,
56
42
  message: {
57
- chatConnection,
58
- userConnection,
59
43
  text: trimmedInput,
60
44
  senderName: message.senderName,
61
45
  },
@@ -71,9 +55,7 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
71
55
  SocketChannel = SocketChannel_1 = __decorate([
72
56
  injectable(),
73
57
  __metadata("design:paramtypes", [SocketChannelConfig,
74
- SocketServerProvider,
75
- ChatResolver,
76
- UserResolver])
58
+ SocketServerProvider])
77
59
  ], SocketChannel);
78
60
 
79
61
  export { SocketChannel };
@@ -1,5 +1,5 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
- import { injectable } from '../../injection/index.js';
2
+ import { injectable } from '../../../core/injection/index.js';
3
3
 
4
4
  let SocketChannelConfig = class SocketChannelConfig {
5
5
  channel;
@@ -1,7 +1,11 @@
1
- import { container } from '../../injection/index.js';
2
- import '../../controller/channel/ChatResolver.js';
3
- import '../../controller/channel/UserResolver.js';
4
- import { ControllerMetadataStore } from '../../controller/metadata/ControllerMetadataStore.js';
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
3
+ import '../../../feature/chat-controller/ChatResolver.js';
4
+ import 'uuid';
5
+ import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
6
+ import 'reflect-metadata';
7
+ import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
8
+ import '../../../feature/mindset/MindsetOperator.js';
5
9
  import { TelegramChannel } from './TelegramChannel.js';
6
10
  import { TelegramChannelConfig } from './TelegramChannelConfig.js';
7
11
 
@@ -1,21 +1,14 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
- import { ChatResolver } from '../../controller/channel/ChatResolver.js';
3
- import { UserResolver } from '../../controller/channel/UserResolver.js';
4
- import { injectable } from '../../injection/index.js';
5
- import '../../controller/metadata/ControllerMetadataStore.js';
6
2
  import { Bot } from 'grammy';
7
3
  import { TelegramChannelConfig } from './TelegramChannelConfig.js';
4
+ import { injectable } from '../../../core/injection/index.js';
8
5
 
9
6
  var TelegramChannel_1;
10
7
  let TelegramChannel = TelegramChannel_1 = class TelegramChannel {
11
8
  config;
12
- chatResolver;
13
- userResolver;
14
9
  bot;
15
- constructor(config, chatResolver, userResolver) {
10
+ constructor(config) {
16
11
  this.config = config;
17
- this.chatResolver = chatResolver;
18
- this.userResolver = userResolver;
19
12
  this.bot = new Bot(this.config.botToken);
20
13
  }
21
14
  listen(callback) {
@@ -28,18 +21,9 @@ let TelegramChannel = TelegramChannel_1 = class TelegramChannel {
28
21
  chatType: ctx.message.chat.type === 'private' ? 'PRIVATE' : 'GROUP',
29
22
  channelName: TelegramChannel_1.name,
30
23
  };
31
- const chat = await this.chatResolver.resolve(chatConnection);
32
- const userConnection = {
33
- id: ctx.from.id.toString(),
34
- channelName: TelegramChannel_1.name,
35
- };
36
- const user = await this.userResolver.resolve(userConnection);
37
24
  callback({
38
- chat,
39
- user,
25
+ chatConnection,
40
26
  message: {
41
- chatConnection,
42
- userConnection,
43
27
  senderName: ctx.from.first_name,
44
28
  text: ctx.message.text,
45
29
  },
@@ -55,9 +39,7 @@ let TelegramChannel = TelegramChannel_1 = class TelegramChannel {
55
39
  };
56
40
  TelegramChannel = TelegramChannel_1 = __decorate([
57
41
  injectable(),
58
- __metadata("design:paramtypes", [TelegramChannelConfig,
59
- ChatResolver,
60
- UserResolver])
42
+ __metadata("design:paramtypes", [TelegramChannelConfig])
61
43
  ], TelegramChannel);
62
44
 
63
45
  export { TelegramChannel };
@@ -1,8 +1,12 @@
1
- import { container } from '../../injection/index.js';
1
+ import { container } from '../../../core/injection/index.js';
2
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';
3
+ import { ControllerMetadataStore } from '../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
4
+ import '../../../feature/chat-controller/ChatResolver.js';
5
+ import 'uuid';
6
+ import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
7
+ import 'reflect-metadata';
8
+ import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
9
+ import '../../../feature/mindset/MindsetOperator.js';
6
10
  import { WhatsAppChannel } from './WhatsAppChannel.js';
7
11
 
8
12
  function whatsapp(config) {