@wabot-dev/framework 0.1.0-beta.6 → 0.1.0-beta.60

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 (183) 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 +53 -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 +35 -0
  8. package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +28 -0
  9. package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +42 -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 +23 -0
  31. package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
  32. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +9 -4
  33. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -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 +9 -4
  36. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  37. package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +25 -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 +20 -41
  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 +26 -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 +60 -0
  49. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
  50. package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
  51. package/dist/src/core/auth/Auth.js +24 -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/validateIsOptional.js +5 -0
  62. package/dist/src/core/validation/core/validateModel.js +36 -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/is-boolean/@isBoolean.js +17 -0
  70. package/dist/src/core/validation/validators/is-boolean/validateIsBoolean.js +12 -0
  71. package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
  72. package/dist/src/core/validation/validators/is-date/validateIsDate.js +16 -0
  73. package/dist/src/core/validation/validators/is-not-empty/@isNotEmpty.js +17 -0
  74. package/dist/src/core/validation/validators/is-not-empty/validateIsNotEmpty.js +12 -0
  75. package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
  76. package/dist/src/core/validation/validators/is-number/validateIsNumber.js +12 -0
  77. package/dist/src/core/validation/validators/is-present/@isPresent.js +17 -0
  78. package/dist/src/core/validation/validators/is-present/validateIsPresent.js +12 -0
  79. package/dist/src/core/validation/validators/is-string/@isString.js +17 -0
  80. package/dist/src/core/validation/validators/is-string/validateIsString.js +12 -0
  81. package/dist/src/core/validation/validators/max/@max.js +18 -0
  82. package/dist/src/core/validation/validators/max/validateMax.js +17 -0
  83. package/dist/src/core/validation/validators/min/@min.js +18 -0
  84. package/dist/src/core/validation/validators/min/validateMin.js +17 -0
  85. package/dist/src/feature/async/@command.js +11 -0
  86. package/dist/src/feature/async/@commandHandler.js +12 -0
  87. package/dist/src/feature/async/Async.js +38 -0
  88. package/dist/src/feature/async/Command.js +9 -0
  89. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  90. package/dist/src/feature/async/Job.js +27 -0
  91. package/dist/src/feature/async/JobRepository.js +31 -0
  92. package/dist/src/feature/async/JobRunner.js +48 -0
  93. package/dist/src/feature/async/JobsEventsHub.js +36 -0
  94. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  95. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  96. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  97. package/dist/src/feature/chat-bot/ChatBot.js +73 -0
  98. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  99. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  100. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  101. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  102. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  103. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  104. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
  105. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  106. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  107. package/dist/src/feature/chat-controller/runChatControllers.js +69 -0
  108. package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
  109. package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
  110. package/dist/src/{mindset → feature/mindset}/IMindset.js +3 -0
  111. package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +69 -42
  112. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  113. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  114. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  115. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  116. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  117. package/dist/src/feature/money/Money.js +61 -0
  118. package/dist/src/feature/money/MoneyDto.js +22 -0
  119. package/dist/src/{repository → feature}/pg/PgCrudRepository.js +30 -9
  120. package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
  121. package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
  122. package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
  123. package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
  124. package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
  125. package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
  126. package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
  127. package/dist/src/feature/rest-controller/metadata/@restController.js +15 -0
  128. package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
  129. package/dist/src/feature/rest-controller/metadata/methodDecorator.js +19 -0
  130. package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
  131. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
  132. package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
  133. package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
  134. package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
  135. package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
  136. package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
  137. package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
  138. package/dist/src/index.d.ts +1202 -575
  139. package/dist/src/index.js +145 -76
  140. package/package.json +10 -4
  141. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
  142. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
  143. package/dist/src/channels/cmd/@cmd.js +0 -18
  144. package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
  145. package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
  146. package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
  147. package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
  148. package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
  149. package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
  150. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
  151. package/dist/src/chatbot/ChatBot.js +0 -51
  152. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  153. package/dist/src/controller/channel/UserResolver.js +0 -21
  154. package/dist/src/core/IMessageContext.js +0 -12
  155. package/dist/src/core/chat/ChatItem.js +0 -15
  156. package/dist/src/core/chat/repository/IChatMemory.js +0 -10
  157. package/dist/src/core/user/IUserRepository.js +0 -19
  158. package/dist/src/core/user/User.js +0 -26
  159. package/dist/src/env/WabotEnv.js +0 -27
  160. package/dist/src/injection/index.js +0 -4
  161. package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
  162. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  163. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  164. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  165. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  166. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  167. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  168. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  169. package/dist/src/pre-made/service/EmailService.js +0 -13
  170. package/dist/src/pre-made/service/OtpService.js +0 -14
  171. package/dist/src/server/prepareChatContainer.js +0 -43
  172. package/dist/src/server/runChannel.js +0 -27
  173. package/dist/src/server/runServer.js +0 -40
  174. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  175. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  176. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  177. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
  178. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  179. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  180. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  181. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  182. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  183. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -1,183 +1,427 @@
1
+ import * as tsyringe from 'tsyringe';
2
+ import { DependencyContainer as DependencyContainer$1 } from 'tsyringe';
3
+ export { DependencyContainer } from 'tsyringe';
1
4
  import InjectionToken from 'tsyringe/dist/typings/providers/injection-token';
2
5
  import DependencyContainer, { PreResolutionInterceptorCallback, PostResolutionInterceptorCallback } from 'tsyringe/dist/typings/types/dependency-container';
3
6
  import InterceptionOptions from 'tsyringe/dist/typings/types/interceptor-options';
4
7
  import { Server } from 'http';
5
- import { Express } from 'express';
6
- import { Server as Server$1 } from 'socket.io';
7
- import { Socket } from 'socket.io-client';
8
+ import { Express, Request, Response } from 'express';
9
+ import * as big_js from 'big.js';
8
10
  import { Pool } from 'pg';
9
- import * as tsyringe from 'tsyringe';
10
- import { DependencyContainer as DependencyContainer$1 } from 'tsyringe';
11
- export { DependencyContainer } from 'tsyringe';
11
+ import { Server as Server$1, Socket } from 'socket.io';
12
+ import { Algorithm } from 'jsonwebtoken';
13
+ import { Socket as Socket$1 } from 'socket.io-client';
12
14
 
13
- interface IMindsetFunctionConfig {
14
- description: string;
15
+ type IPrimitive = null | number | string | boolean | undefined;
16
+ type IStorableData = {
17
+ [key: string]: IPrimitive | IPrimitive[] | IStorableData | IStorableData[];
18
+ };
19
+ declare class Storable<D extends IStorableData> {
20
+ protected data: D;
21
+ constructor(data: D);
15
22
  }
16
23
 
17
- declare function mindsetFunction(config: IMindsetFunctionConfig): (target: object, propertyKey: string | symbol) => void;
18
-
19
- declare const MINDSET_FUNCTION_DECORATION_FUNCTION = "mindsetFunction";
20
-
21
- interface IMindsetFunctionDecoration {
22
- decorationName: string;
23
- functionName: string;
24
- constructor: Function;
25
- paramsTypes: Function[];
26
- decorationConfig: any;
24
+ declare class Auth<D extends IStorableData> {
25
+ private authInfo;
26
+ require(): D;
27
+ assign(authInfo: D): void;
27
28
  }
28
29
 
29
- interface IPersistentData {
30
+ interface IEntityData extends IStorableData {
30
31
  id?: string;
31
32
  createdAt?: number | null;
32
33
  discardedAt?: number | null;
33
34
  }
34
- declare class Persistent<D extends IPersistentData = IPersistentData> {
35
- protected data: D;
36
- constructor(data: D);
35
+ declare class Entity<D extends IEntityData> extends Storable<D> {
36
+ get id(): string;
37
+ /**
38
+ * @deprecated use id
39
+ */
37
40
  getId(): string;
41
+ get createdAt(): Date;
42
+ /**
43
+ * @deprecated use createdAt
44
+ */
38
45
  getCreatedAt(): Date;
39
- update(newData: D): void;
46
+ update(newData: Omit<D, 'id' | 'createdAt' | 'discardedAt'>): void;
40
47
  wasCreated(): boolean;
41
48
  validate(): void;
42
- discard(): void;
43
49
  }
44
-
45
- type IChatType = 'PRIVATE' | 'GROUP';
46
- interface IChatConnection {
47
- chatType: IChatType;
48
- channelName: string;
49
- id: string;
50
+ /**
51
+ * @deprecated Should use IEntityData
52
+ */
53
+ interface IPersistentData extends IEntityData {
50
54
  }
51
- interface IChatData extends IPersistentData {
52
- type: IChatType;
53
- connections: IChatConnection[];
55
+ /**
56
+ * @deprecated Should use Entity
57
+ */
58
+ declare class Persistent<D extends IPersistentData> extends Entity<D> {
54
59
  }
55
- declare class Chat extends Persistent<IChatData> {
56
- constructor(data: IChatData);
57
- isPrivate(): boolean;
58
- isGroup(): boolean;
59
- hasConnection(connection: IChatConnection): boolean;
60
- private validatePrivateChat;
61
- private validateGroupChat;
62
- validate(): void;
60
+
61
+ type IEnvType = 'development' | 'staging' | 'testing' | 'production';
62
+ declare class Env {
63
+ private envType;
64
+ constructor();
65
+ isDevelopment(): boolean;
66
+ isProduction(): boolean;
67
+ isTesting(): boolean;
68
+ requireString(varName: string, options?: {
69
+ default?: string;
70
+ }): string;
71
+ requireNumber(varName: string, options?: {
72
+ default?: number;
73
+ }): number;
74
+ }
75
+
76
+ interface ICustomErrorData {
77
+ message: string;
78
+ humanMessage?: string;
79
+ code?: string;
80
+ httpCode?: number;
81
+ cause?: Error;
82
+ info?: any;
83
+ }
84
+ declare class CustomError extends Error {
85
+ humanMessage?: string;
86
+ code?: string;
87
+ httpCode?: number;
88
+ info?: any;
89
+ constructor(data: ICustomErrorData);
63
90
  }
64
91
 
65
- interface IChatDocument {
92
+ type IConstructor<T> = new (...args: any[]) => T;
93
+
94
+ declare class Container implements DependencyContainer {
95
+ register(token: unknown, provider: unknown, options?: unknown): DependencyContainer;
96
+ registerSingleton(from: unknown, to?: unknown): DependencyContainer;
97
+ registerType<T>(from: InjectionToken<T>, to: InjectionToken<T>): DependencyContainer;
98
+ registerInstance<T>(token: InjectionToken<T>, instance: T): DependencyContainer;
99
+ resolve<T>(token: InjectionToken<T>): T;
100
+ resolveAll<T>(token: InjectionToken<T>): T[];
101
+ isRegistered<T>(token: InjectionToken<T>, recursive?: boolean): boolean;
102
+ reset(): void;
103
+ clearInstances(): void;
104
+ createChildContainer(): DependencyContainer;
105
+ beforeResolution<T>(token: InjectionToken<T>, callback: PreResolutionInterceptorCallback<T>, options?: InterceptionOptions): void;
106
+ afterResolution<T>(token: InjectionToken<T>, callback: PostResolutionInterceptorCallback<T>, options?: InterceptionOptions): void;
107
+ dispose(): Promise<void> | void;
66
108
  }
67
109
 
68
- interface IChatImage {
110
+ declare const injectable: typeof tsyringe.injectable;
111
+ declare const container: tsyringe.DependencyContainer;
112
+ declare const singleton: typeof tsyringe.singleton;
113
+ declare const inject: typeof tsyringe.inject;
114
+ declare const scoped: typeof tsyringe.scoped;
115
+ declare const Lifecycle: typeof tsyringe.Lifecycle;
116
+
117
+ declare class Logger {
118
+ private debuggers;
119
+ constructor(name: string);
120
+ trace(...args: any[]): void;
121
+ debug(...args: any[]): void;
122
+ info(...args: any[]): void;
123
+ warn(...args: any[]): void;
124
+ error(...args: any[]): void;
125
+ fatal(...args: any[]): void;
126
+ private log;
69
127
  }
70
128
 
71
- interface IUserConnection {
72
- channelName: string;
73
- id: string;
129
+ declare class Mapper {
130
+ map<T>(data: any, ctor: IConstructor<T>): T;
74
131
  }
75
- interface IUserData extends IPersistentData {
76
- shortName: string;
77
- connections: IUserConnection[];
78
- keyValueData: {
79
- [key: string]: string;
80
- };
132
+
133
+ interface PasswordHashOptions {
134
+ password: string;
135
+ saltLength?: number;
136
+ keyLength?: number;
81
137
  }
82
- declare class User extends Persistent<IUserData> {
83
- constructor(data: IUserData);
84
- hasConnection(connection: IUserConnection): boolean;
85
- getValue(key: string): string;
86
- setValue(key: string, value: string): void;
87
- addConnection(connection: IUserConnection): void;
138
+ declare class Password {
139
+ static hash(options: PasswordHashOptions): string;
140
+ static isValid(req: {
141
+ password: string;
142
+ hash: string;
143
+ }): boolean;
144
+ static generate(length: number): string;
88
145
  }
89
146
 
90
- interface IChatMessage {
91
- text?: string;
92
- documents?: IChatDocument[];
93
- images?: IChatImage[];
94
- senderName: string;
95
- }
96
- interface IConnectionChatMessage extends IChatMessage {
97
- chatConnection: IChatConnection;
98
- userConnection: IUserConnection;
99
- userId?: string;
147
+ declare class Random {
148
+ static integer(options: {
149
+ min: number;
150
+ max: number;
151
+ }): number;
152
+ static slug(name: string, options: {
153
+ randomLength: number;
154
+ }): string;
155
+ static alphaNumeric(length: number): string;
156
+ static alphaNumericLowerCase(length: number): string;
157
+ static numberCode(length: number): string;
100
158
  }
101
159
 
102
- interface IChatFunctionCall {
103
- id: string;
104
- name: string;
105
- arguments?: string;
106
- result: string;
160
+ interface ICrudRepository<T> {
161
+ find(id: string): Promise<T | null>;
162
+ findOrThrow(id: string): Promise<T>;
163
+ findByIds(ids: string[]): Promise<T[]>;
164
+ findAll(id: string): Promise<T[]>;
165
+ create(item: T): Promise<void>;
166
+ update(item: T): Promise<void>;
167
+ delete(item: T): Promise<void>;
107
168
  }
108
169
 
109
- type ISystemMessageItem = {
110
- type: 'BOT_MESSAGE';
111
- content: IChatMessage;
170
+ declare function isModel(model: IConstructor<any>): (target: object, propertyKey: string | symbol) => void;
171
+
172
+ declare function isOptional(): (target: object, propertyKey: string | symbol) => void;
173
+
174
+ interface IValidationError {
175
+ description: string;
176
+ }
177
+ interface IModelValidationError extends IValidationError {
178
+ properties: {
179
+ [key: string]: string[];
180
+ };
181
+ }
182
+ interface IArrayValidationError extends IValidationError {
183
+ items: (IValidationError[] | null)[];
184
+ }
185
+ type IValidationResult<V> = {
186
+ value: V;
187
+ error?: undefined;
188
+ } | {
189
+ value?: undefined;
190
+ error: IValidationError;
112
191
  };
113
- type IReceivedMessageItem = {
114
- type: 'CONNECTION_MESSAGE';
115
- content: IConnectionChatMessage;
192
+ type IModelValidationResult<V> = {
193
+ value: V;
194
+ error?: undefined;
195
+ } | {
196
+ value?: undefined;
197
+ error: IModelValidationError;
116
198
  };
117
- type ISystemFunctionCallItem = {
118
- type: 'FUNCTION_CALL';
119
- content: IChatFunctionCall;
199
+ type IArrayValidationResult<V> = {
200
+ value: V[];
201
+ error?: undefined;
202
+ } | {
203
+ value?: undefined;
204
+ error: IArrayValidationError;
120
205
  };
121
- type IChatItemData = {
122
- id?: string;
123
- createdAt?: number;
124
- } & (ISystemMessageItem | IReceivedMessageItem | ISystemFunctionCallItem);
125
- type IChatItemType = IChatItemData['type'];
126
- declare class ChatItem extends Persistent<IChatItemData> {
127
- getType(): "BOT_MESSAGE" | "CONNECTION_MESSAGE" | "FUNCTION_CALL";
128
- getContent(): IChatMessage | IConnectionChatMessage | IChatFunctionCall;
129
- getData(): IChatItemData;
206
+ type IValidator<V = any, O = any> = (value: V, options: O) => IValidationResult<V>;
207
+ interface IPropertyValidatorInfo {
208
+ propertyName: string;
209
+ validator: IValidator;
210
+ validatorOptions?: any;
211
+ }
212
+ type IModelValidatorsInfo<V> = {
213
+ modelConstructor: IConstructor<V>;
214
+ properties: {
215
+ [prop: string]: {
216
+ isOptional?: boolean;
217
+ validators?: IPropertyValidatorInfo[];
218
+ } | undefined;
219
+ };
220
+ };
221
+
222
+ interface IValidateArrayOptions {
223
+ minLength?: number;
224
+ maxLength?: number;
225
+ }
226
+ interface IValidateArrayOptionsWithItemsValidators extends IValidateArrayOptions {
227
+ itemsValidator?: {
228
+ validator: IValidator;
229
+ options: any;
230
+ }[];
130
231
  }
232
+ declare function validateArray(value: any, options?: IValidateArrayOptionsWithItemsValidators): IArrayValidationResult<any>;
131
233
 
132
- interface IChatMemory {
133
- findLastItems(count: number): Promise<ChatItem[]>;
134
- create(item: ChatItem): Promise<void>;
234
+ declare function isArray(options?: IValidateArrayOptions): (target: object, propertyKey: string | symbol) => void;
235
+
236
+ interface IValidatorMetadata {
237
+ modelConstructor: IConstructor<any>;
238
+ propertyName: string;
239
+ validator: IValidator;
240
+ validatorOptions?: any;
135
241
  }
136
- declare class ChatMemory implements IChatMemory {
137
- findLastItems(count: number): Promise<ChatItem[]>;
138
- create(item: ChatItem): Promise<void>;
242
+
243
+ declare class ValidationMetadataStore {
244
+ private validators;
245
+ saveValidatorMetadata(validatorMetadata: IValidatorMetadata): void;
246
+ getModelValidatorsInfo<V>(modelConstructor: IConstructor<V>): IModelValidatorsInfo<V>;
247
+ private getConstructorPropertiesValidatorsInfo;
139
248
  }
140
249
 
141
- interface IChatRepository {
142
- create(chat: Chat): Promise<void>;
143
- findByConnection(query: IChatConnection): Promise<Chat | null>;
144
- findMemory(chatId: string): Promise<IChatMemory | null>;
250
+ declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IModelValidationResult<V>;
251
+
252
+ declare function validate<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
253
+
254
+ declare function modelInfo<V>(modelConstructor: IConstructor<V>): IModelValidatorsInfo<V>;
255
+
256
+ declare function isBoolean(): (target: object, propertyKey: string | symbol) => void;
257
+
258
+ declare function validateIsBoolean(value: any): IValidationResult<boolean>;
259
+
260
+ declare function isDate(): (target: object, propertyKey: string | symbol) => void;
261
+
262
+ declare function validateIsDate(value: any): IValidationResult<Date>;
263
+
264
+ declare function isNotEmpty(): (target: object, propertyKey: string | symbol) => void;
265
+
266
+ declare function validateIsNotEmpty(value: any): IValidationResult<any>;
267
+
268
+ declare function isNumber(): (target: object, propertyKey: string | symbol) => void;
269
+
270
+ declare function validateIsNumber(value: any): IValidationResult<number>;
271
+
272
+ declare function isPresent(): (target: object, propertyKey: string | symbol) => void;
273
+
274
+ declare function validateIsPresent(value: any): IValidationResult<any>;
275
+
276
+ declare function isString(): (target: object, propertyKey: string | symbol) => void;
277
+
278
+ declare function validateIsString(value: any): IValidationResult<string>;
279
+
280
+ declare function min(limit: any): (target: object, propertyKey: string | symbol) => void;
281
+
282
+ interface IValidateMinOptions {
283
+ limit: any;
145
284
  }
146
- declare class ChatRepository implements IChatRepository {
147
- create(chat: Chat): Promise<void>;
148
- findByConnection(query: IChatConnection): Promise<Chat | null>;
149
- findMemory(chatId: string): Promise<IChatMemory | null>;
285
+ declare function validateMin(value: any, options: IValidateMinOptions): IValidationResult<any>;
286
+
287
+ declare function max(limit: any): (target: object, propertyKey: string | symbol) => void;
288
+
289
+ interface IValidateMaxOptions {
290
+ limit: any;
150
291
  }
292
+ declare function validateMax(value: any, options: IValidateMaxOptions): IValidationResult<any>;
151
293
 
152
- interface IUserRepository {
153
- create(chat: User): Promise<void>;
154
- update(chat: User): Promise<void>;
155
- findByConnection(query: IUserConnection): Promise<User | null>;
294
+ interface ICommandConfig {
295
+ name?: string;
156
296
  }
157
- declare class UserRepository implements IUserRepository {
158
- create(chat: User): Promise<void>;
159
- update(chat: User): Promise<void>;
160
- findByConnection(query: IUserConnection): Promise<User | null>;
297
+ declare function command(config?: ICommandConfig): (target: IConstructor<any>) => void;
298
+
299
+ declare class Command<T extends IStorableData> extends Storable<T> {
300
+ getData(): T;
161
301
  }
162
302
 
163
- interface IMessageContext {
164
- message: IConnectionChatMessage;
165
- chat: Chat;
166
- user: User | null;
303
+ interface ICommandHandler<C extends Command<any>> {
304
+ handle(command: C): void | Promise<void>;
167
305
  }
168
- declare class MessageContext implements IMessageContext {
169
- message: IConnectionChatMessage;
170
- chat: Chat;
171
- user: User | null;
172
- constructor(message: IConnectionChatMessage, chat: Chat, user: User | null);
306
+
307
+ interface ICommandHandlerConfig<C extends Command<any>> {
308
+ command: IConstructor<C>;
173
309
  }
310
+ declare function commandHandler<C extends Command<any>>(config: ICommandHandlerConfig<C>): (target: IConstructor<ICommandHandler<C>>) => void;
174
311
 
175
- interface IReversibleMapper<T1, T2> {
176
- map(input: T1): T2;
177
- rev(input: T2): T1;
312
+ declare class CommandMetadataStore {
313
+ private handlersMap;
314
+ private handlersInverseMap;
315
+ private commandsMap;
316
+ private commandsInverseMap;
317
+ registerCommand(command: IConstructor<Command<any>>, commandName: string): void;
318
+ registerHandler(command: IConstructor<Command<any>>, handlerConstructor: IConstructor<ICommandHandler<any>>): void;
319
+ getHandlerForCommandName(commandName: string): IConstructor<ICommandHandler<any>> | null;
320
+ getCommandNameForHandler(handlerConstructor: IConstructor<ICommandHandler<any>>): string | null;
321
+ getCommandName(command: IConstructor<Command<any>>): string | null;
322
+ getCommandForCommandName(commandName: string): IConstructor<Command<any>> | null;
178
323
  }
179
324
 
180
- type IConstructor<T> = new (...args: any[]) => T;
325
+ interface IJobData extends IEntityData {
326
+ commandName: string;
327
+ commandData: any;
328
+ startedAt?: number;
329
+ successAt?: number;
330
+ failedAt?: number;
331
+ retryAt?: number;
332
+ error?: {
333
+ message: string;
334
+ stack?: string;
335
+ info?: any;
336
+ };
337
+ }
338
+ declare class Job extends Entity<IJobData> {
339
+ get commandName(): string;
340
+ hasFinished(): boolean;
341
+ setAsStarted(): void;
342
+ setAsSuccess(): void;
343
+ setAsFailed(error: Error): void;
344
+ }
345
+
346
+ interface IJobRepository extends ICrudRepository<Job> {
347
+ }
348
+
349
+ declare class JobRepository implements IJobRepository {
350
+ find(id: string): Promise<Job | null>;
351
+ findOrThrow(id: string): Promise<Job>;
352
+ findByIds(ids: string[]): Promise<Job[]>;
353
+ findAll(id: string): Promise<Job[]>;
354
+ create(item: Job): Promise<void>;
355
+ update(item: Job): Promise<void>;
356
+ delete(item: Job): Promise<void>;
357
+ }
358
+
359
+ interface IJobEvent extends IStorableData {
360
+ jobId: string;
361
+ type: 'created';
362
+ }
363
+ type IJobEventListener = (event: IJobEvent) => void | Promise<void>;
364
+ declare class JobsEventsHub {
365
+ private logger;
366
+ private jobsEventsListener;
367
+ notifyJobCreated(job: Job): void;
368
+ listenJobsEvents(listener: IJobEventListener): void;
369
+ }
370
+
371
+ declare class Async {
372
+ private jobRepository;
373
+ private handlerContainer;
374
+ private jobsEventsHub;
375
+ constructor(jobRepository: JobRepository, handlerContainer: CommandMetadataStore, jobsEventsHub: JobsEventsHub);
376
+ run<T extends IStorableData>(command: Command<T>): Promise<Job>;
377
+ }
378
+
379
+ declare class JobRunner {
380
+ private jobRepository;
381
+ private handlerContainer;
382
+ private logger;
383
+ constructor(jobRepository: JobRepository, handlerContainer: CommandMetadataStore);
384
+ run(job: Job): Promise<void>;
385
+ }
386
+
387
+ declare function runAsyncCommandHandlers(handlers: IConstructor<ICommandHandler<any>>[]): void;
388
+
389
+ interface IChatConnection extends IStorableData {
390
+ channelName: string;
391
+ id: string;
392
+ }
393
+
394
+ type IChatType = 'PRIVATE' | 'GROUP';
395
+
396
+ interface IChatData extends IEntityData {
397
+ type: IChatType;
398
+ connections: IChatConnection[];
399
+ }
400
+ declare class Chat extends Entity<IChatData> {
401
+ constructor(data: IChatData);
402
+ isPrivate(): boolean;
403
+ isGroup(): boolean;
404
+ hasConnection(connection: IChatConnection): boolean;
405
+ private validatePrivateChat;
406
+ private validateGroupChat;
407
+ validate(): void;
408
+ }
409
+
410
+ interface IMindsetFunctionConfig {
411
+ description: string;
412
+ }
413
+
414
+ declare function mindsetFunction(config: IMindsetFunctionConfig): (target: object, propertyKey: string | symbol) => void;
415
+
416
+ declare const MINDSET_FUNCTION_DECORATION_FUNCTION = "mindsetFunction";
417
+
418
+ interface IMindsetFunctionDecoration {
419
+ decorationName: string;
420
+ functionName: string;
421
+ constructor: Function;
422
+ paramsTypes: Function[];
423
+ decorationConfig: any;
424
+ }
181
425
 
182
426
  interface IMindsetIdentity {
183
427
  name: string;
@@ -186,15 +430,21 @@ interface IMindsetIdentity {
186
430
  personality?: string;
187
431
  emotions?: string;
188
432
  }
433
+ interface IMindsetLlm {
434
+ provider?: string;
435
+ model: string;
436
+ }
189
437
  interface IMindset {
190
438
  identity(): Promise<IMindsetIdentity>;
191
439
  skills(): Promise<string>;
192
440
  limits(): Promise<string>;
441
+ llms(): Promise<IMindsetLlm[]>;
193
442
  }
194
443
  declare class Mindset implements IMindset {
195
444
  identity(): Promise<IMindsetIdentity>;
196
445
  skills(): Promise<string>;
197
446
  limits(): Promise<string>;
447
+ llms(): Promise<IMindsetLlm[]>;
198
448
  }
199
449
 
200
450
  interface IMindsetConfig {
@@ -226,8 +476,6 @@ interface IMindsetModuleDecoration {
226
476
  decorationConfig: any;
227
477
  }
228
478
 
229
- declare function isOptional(): PropertyDecorator;
230
-
231
479
  interface IParamConfig {
232
480
  name?: string;
233
481
  optional?: boolean;
@@ -285,26 +533,17 @@ declare class MindsetMetadataStore {
285
533
  getMindsetMetadata(ctor: Function): IMindsetMetadata;
286
534
  }
287
535
 
288
- declare class Container implements DependencyContainer {
289
- register(token: unknown, provider: unknown, options?: unknown): DependencyContainer;
290
- registerSingleton(from: unknown, to?: unknown): DependencyContainer;
291
- registerType<T>(from: InjectionToken<T>, to: InjectionToken<T>): DependencyContainer;
292
- registerInstance<T>(token: InjectionToken<T>, instance: T): DependencyContainer;
293
- resolve<T>(token: InjectionToken<T>): T;
294
- resolveAll<T>(token: InjectionToken<T>): T[];
295
- isRegistered<T>(token: InjectionToken<T>, recursive?: boolean): boolean;
296
- reset(): void;
297
- clearInstances(): void;
298
- createChildContainer(): DependencyContainer;
299
- beforeResolution<T>(token: InjectionToken<T>, callback: PreResolutionInterceptorCallback<T>, options?: InterceptionOptions): void;
300
- afterResolution<T>(token: InjectionToken<T>, callback: PostResolutionInterceptorCallback<T>, options?: InterceptionOptions): void;
301
- dispose(): Promise<void> | void;
536
+ interface IMindsetToolParameter {
537
+ type: string;
538
+ name: string;
539
+ description: string;
540
+ }
541
+ interface IMindsetTool {
542
+ language: string;
543
+ name: string;
544
+ description: string;
545
+ parameters: IMindsetToolParameter[];
302
546
  }
303
-
304
- declare const injectable: typeof tsyringe.injectable;
305
- declare const container: tsyringe.DependencyContainer;
306
- declare const singleton: typeof tsyringe.singleton;
307
- declare const inject: typeof tsyringe.inject;
308
547
 
309
548
  declare class MindsetOperator implements IMindset {
310
549
  private mindset;
@@ -314,99 +553,124 @@ declare class MindsetOperator implements IMindset {
314
553
  identity(): Promise<IMindsetIdentity>;
315
554
  skills(): Promise<string>;
316
555
  limits(): Promise<string>;
556
+ llms(): Promise<IMindsetLlm[]>;
557
+ systemPrompt(): Promise<string>;
558
+ tools(): IMindsetTool[];
559
+ protected tool(fn: IMindsetFunctionMetadata, module: IMindsetModuleMetadata): IMindsetTool;
560
+ protected toolParameter(param: IMindsetFunctionParamMetadata): IMindsetToolParameter;
317
561
  callFunction(name: string, params: string): Promise<string>;
318
- allFunctionsDescriptors(): Promise<{
319
- readonly type: "function";
320
- readonly name: string;
321
- readonly description: string;
322
- readonly parameters: {
323
- readonly type: "object";
324
- readonly properties: {};
325
- readonly required: string[];
326
- };
327
- }[]>;
328
- private functionDescriptor;
329
- private toolParam;
330
562
  }
331
563
 
332
- declare function chatBot(mindset: IConstructor<IMindset>): (target: object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
564
+ interface IChatMessage extends IStorableData {
565
+ senderId?: string;
566
+ senderName?: string;
567
+ text?: string;
568
+ }
333
569
 
334
- interface IChatBotMetadata {
335
- constructor: IConstructor<any>;
336
- mindsetConstructor: IConstructor<IMindset>;
337
- injectionToken: string;
570
+ interface IFunctionCall extends IStorableData {
571
+ id: string;
572
+ name: string;
573
+ arguments?: string;
574
+ result?: string;
338
575
  }
339
576
 
340
- declare class ChatBotMetadataStore {
341
- private chatBots;
342
- saveChatBotMetadata(chatBot: IChatBotMetadata): void;
343
- getChatBotsMetadata(): IChatBotMetadata[];
577
+ declare const chatItemTypeOptions: readonly ["botMessage", "humanMessage", "functionCall"];
578
+ type IBotMessageItem = {
579
+ type: 'botMessage';
580
+ botMessage: IChatMessage;
581
+ };
582
+ type IHumanMessageItem = {
583
+ type: 'humanMessage';
584
+ humanMessage: IChatMessage;
585
+ };
586
+ type IFunctionCallItem = {
587
+ type: 'functionCall';
588
+ functionCall: IFunctionCall;
589
+ };
590
+ type IChatItem = IBotMessageItem | IHumanMessageItem | IFunctionCallItem;
591
+ type IChatItemType = (typeof chatItemTypeOptions)[number];
592
+
593
+ interface ILanguageModelUsage {
594
+ inputTokens: number;
595
+ outputTokens: number;
344
596
  }
345
597
 
346
- interface IChatBotAdapter {
347
- generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem>;
598
+ interface IChatAdapterNextItemReq {
599
+ model: string;
600
+ systemPrompt: string;
601
+ tools: IMindsetTool[];
602
+ prevItems: IChatItem[];
348
603
  }
349
- declare class ChatBotAdapter implements IChatBotAdapter {
350
- protected mindset: MindsetOperator;
351
- constructor(mindset: MindsetOperator);
352
- generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem>;
353
- protected systemPrompt(): Promise<string>;
354
- protected buildBotMessageItem(text: string): Promise<ChatItem>;
355
- protected buildFunctionCallItem(id: string, functionName: string, functionArguments: string): Promise<ChatItem>;
604
+ interface IChatAdapterNextItemRes {
605
+ chatItem: IChatItem;
606
+ usage: ILanguageModelUsage;
607
+ }
608
+ interface IChatAdapter {
609
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
356
610
  }
357
611
 
358
- interface IChatBot {
359
- sendMessage(message: IChatMessage, callback: (message: IChatMessage) => void): void | Promise<void>;
612
+ declare class ChatAdapter implements IChatAdapter {
613
+ nextItem(req: IChatAdapterNextItemReq & {
614
+ provider?: string;
615
+ }): Promise<IChatAdapterNextItemRes>;
360
616
  }
361
617
 
362
- declare class ChatBot implements IChatBot {
363
- private memory;
364
- private adapter;
365
- constructor(memory: ChatMemory, adapter: ChatBotAdapter);
366
- sendMessage(message: IConnectionChatMessage, callback: (message: IChatMessage) => void): Promise<void>;
367
- protected processLoop(callback: (message: IChatMessage) => void): Promise<void>;
618
+ type IChatItemData = IEntityData & IChatItem;
619
+ declare class ChatItem extends Entity<IChatItemData> {
620
+ get type(): "botMessage" | "humanMessage" | "functionCall";
621
+ get botMessage(): IChatMessage;
622
+ get functionCall(): IFunctionCall;
623
+ setFunctionResult(result: string): void;
624
+ getData(): IChatItemData;
368
625
  }
369
626
 
370
- declare class DeepSeekChatBotAdapter extends ChatBotAdapter {
371
- private deepSeek;
372
- private model;
373
- constructor(mindset: MindsetOperator);
374
- validateEnvVariables(envVariables: (string | undefined)[]): void;
375
- generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem>;
376
- private mapChatItems;
627
+ interface IChatMemory {
628
+ findLastItems(count: number): Promise<ChatItem[]>;
629
+ create(item: ChatItem): Promise<void>;
377
630
  }
378
631
 
379
- declare class OpenaiChatBotAdapter extends ChatBotAdapter {
380
- private openai;
381
- private model;
382
- private logger;
383
- constructor(mindset: MindsetOperator);
384
- generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem>;
385
- private mapChatItems;
632
+ declare class ChatMemory implements IChatMemory {
633
+ findLastItems(count: number): Promise<ChatItem[]>;
634
+ create(item: ChatItem): Promise<void>;
386
635
  }
387
636
 
388
- declare function cmd(): (target: object, propertyKey: string | symbol) => void;
637
+ interface IChatBot {
638
+ sendMessage(message: IChatMessage, callback: (message: IChatMessage) => void): void | Promise<void>;
639
+ }
389
640
 
390
- declare class ChatResolver {
391
- private chatRepository;
392
- constructor(chatRepository: ChatRepository);
393
- resolve(connection: IChatConnection): Promise<Chat>;
394
- private resolveGroupChat;
395
- private resolvePrivateChat;
641
+ declare class ChatBot implements IChatBot {
642
+ private memory;
643
+ private adapter;
644
+ private mindset;
645
+ constructor(memory: ChatMemory, adapter: ChatAdapter, mindset: MindsetOperator);
646
+ sendMessage(message: IChatMessage, callback: (message: IChatMessage) => void): Promise<void>;
647
+ protected processLoop(callback: (message: IChatMessage) => void): Promise<void>;
396
648
  }
397
649
 
398
- interface IReceivedMessage extends IMessageContext {
399
- reply: (message: IChatMessage) => void;
650
+ interface IChatRepository {
651
+ create(chat: Chat): Promise<void>;
652
+ findByConnection(query: IChatConnection): Promise<Chat | null>;
653
+ findMemory(chatId: string): Promise<IChatMemory | null>;
400
654
  }
401
- interface IChatChannel {
402
- listen(callback: (message: IReceivedMessage) => void): void;
403
- connect(): void;
655
+
656
+ declare class ChatRepository implements IChatRepository {
657
+ create(chat: Chat): Promise<void>;
658
+ findByConnection(query: IChatConnection): Promise<Chat | null>;
659
+ findMemory(chatId: string): Promise<IChatMemory | null>;
404
660
  }
405
661
 
406
- declare class UserResolver {
407
- private userRepository;
408
- constructor(userRepository: UserRepository);
409
- resolve(connection: IUserConnection): Promise<User | null>;
662
+ declare function chatBot(mindset: IConstructor<IMindset>): (target: object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
663
+
664
+ interface IChatBotMetadata {
665
+ constructor: IConstructor<any>;
666
+ mindsetConstructor: IConstructor<IMindset>;
667
+ injectionToken: string;
668
+ }
669
+
670
+ declare class ChatBotMetadataStore {
671
+ private chatBots;
672
+ saveChatBotMetadata(chatBot: IChatBotMetadata): void;
673
+ getChatBotsMetadata(): IChatBotMetadata[];
410
674
  }
411
675
 
412
676
  interface IchatControllerConfig {
@@ -418,6 +682,20 @@ interface IChatControllerMetadata {
418
682
  controllerConstructor: Function;
419
683
  }
420
684
 
685
+ interface IReceivedMessage {
686
+ message: IChatMessage;
687
+ reply: (message: IChatMessage) => void;
688
+ }
689
+
690
+ interface IChannelMessage extends IReceivedMessage {
691
+ chatConnection: IChatConnection;
692
+ }
693
+
694
+ interface IChatChannel {
695
+ listen(callback: (received: IChannelMessage) => void): void;
696
+ connect(): void;
697
+ }
698
+
421
699
  interface IChannelMetadata {
422
700
  controllerConstructor: IConstructor<any>;
423
701
  functionName: string;
@@ -436,16 +714,20 @@ declare class ControllerMetadataStore {
436
714
  } | null;
437
715
  }
438
716
 
439
- declare class CmdChannel implements IChatChannel {
440
- private chatResolver;
441
- private userResolver;
442
- private rl;
443
- private callBack;
444
- constructor(chatResolver: ChatResolver, userResolver: UserResolver);
445
- listen(callback: (message: IReceivedMessage) => void): void;
446
- connect(): void;
717
+ declare class ChatResolver {
718
+ private chatRepository;
719
+ constructor(chatRepository: ChatRepository);
720
+ resolve(connection: IChatConnection): Promise<Chat>;
721
+ private resolveGroupChat;
722
+ private resolvePrivateChat;
723
+ }
724
+
725
+ interface IMessageContext extends IReceivedMessage {
726
+ chat: Chat;
447
727
  }
448
728
 
729
+ declare function runChatControllers(controllers: IConstructor<any>[]): void;
730
+
449
731
  declare class HttpServerProvider {
450
732
  server: Server | null;
451
733
  private listening;
@@ -464,16 +746,152 @@ declare class ExpressProvider {
464
746
  private createExpress;
465
747
  }
466
748
 
467
- interface ISocketChannelConfig {
468
- channel: string;
749
+ interface IMoneyData extends IStorableData {
750
+ amount: string;
751
+ currency: string;
752
+ }
753
+ declare class Money extends Storable<IMoneyData> {
754
+ getData(): {
755
+ [key: string]: IPrimitive | IStorableData | IPrimitive[] | IStorableData[];
756
+ amount: string;
757
+ currency: string;
758
+ };
759
+ get amount(): big_js.Big;
760
+ get currency(): string;
761
+ plus(money: Money): Money;
762
+ minus(money: Money): Money;
763
+ times(value: bigint | string): Money;
764
+ div(value: bigint | string): Money;
765
+ negative(): Money;
766
+ isGretterThan(money: Money): boolean;
767
+ protected validateEqualCurrencies(left: string, right: string): void;
768
+ static zero(currency: string): Money;
469
769
  }
470
770
 
471
- declare class SocketChannelConfig implements ISocketChannelConfig {
472
- channel: string;
473
- constructor(channel: string);
771
+ declare class MoneyDto {
772
+ amount: string;
773
+ currency: string;
474
774
  }
475
775
 
476
- declare function socket(config: SocketChannelConfig): (target: object, propertyKey: string | symbol) => void;
776
+ type IPgRepositoryConfig<P extends Entity<IEntityData>> = {
777
+ schema?: string;
778
+ table: string;
779
+ constructor: IConstructor<P>;
780
+ add?: {
781
+ columns: {
782
+ [column: string]: {
783
+ type: string;
784
+ value: (item: P) => boolean | number | string | null | Date;
785
+ };
786
+ };
787
+ };
788
+ };
789
+
790
+ declare class PgRepositoryBase<P extends Entity<IEntityData>> {
791
+ protected pool: Pool;
792
+ protected config: IPgRepositoryConfig<any>;
793
+ private tableIsCreated;
794
+ protected schema: string;
795
+ protected table: string;
796
+ protected columnsList: string[];
797
+ protected columnsAndTypes: string;
798
+ protected columns: string;
799
+ protected vars: string;
800
+ protected updates: string;
801
+ addColumns: {
802
+ [columns: string]: {
803
+ type: string;
804
+ value: (item: P) => number | boolean | string | null | Date;
805
+ };
806
+ };
807
+ constructor(pool: Pool, config: IPgRepositoryConfig<any>);
808
+ protected values(item: P): (string | number | boolean | Date | null)[];
809
+ protected exec(sql: string, values: any[]): Promise<void>;
810
+ protected query(sql: string, values: any[]): Promise<P[]>;
811
+ protected connect(): Promise<Pool>;
812
+ protected ensureTable(): Promise<void>;
813
+ protected ensureColumns(): Promise<void>;
814
+ }
815
+
816
+ declare class PgCrudRepository<P extends Entity<IEntityData>> extends PgRepositoryBase<P> implements ICrudRepository<P> {
817
+ protected readonly config: IPgRepositoryConfig<P>;
818
+ constructor(pool: Pool, config: IPgRepositoryConfig<P>);
819
+ find(id: string): Promise<P | null>;
820
+ findByIds(ids: string[]): Promise<P[]>;
821
+ findOrThrow(id: string): Promise<P>;
822
+ findAll(): Promise<P[]>;
823
+ create(item: P): Promise<void>;
824
+ update(item: P): Promise<void>;
825
+ delete(item: P): Promise<void>;
826
+ }
827
+
828
+ interface IEndPointConfig {
829
+ path?: string;
830
+ disableJsonParser?: boolean;
831
+ disableUrlEncodedParser?: boolean;
832
+ }
833
+
834
+ declare function onGet(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
835
+
836
+ interface IMiddleware {
837
+ handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
838
+ }
839
+
840
+ declare function middleware(middlewareConstructor: IConstructor<IMiddleware>): (target: object, propertyKey: string | symbol) => void;
841
+
842
+ declare function onPost(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
843
+
844
+ declare function onPut(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
845
+
846
+ declare function onDelete(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
847
+
848
+ interface IRestControllerConfig {
849
+ path: string;
850
+ }
851
+
852
+ declare function restController(config: string | IRestControllerConfig): (target: IConstructor<any>) => void;
853
+
854
+ interface IEndPointMetadata {
855
+ method: 'get' | 'post' | 'put' | 'delete';
856
+ config?: IEndPointConfig;
857
+ controllerConstructor: IConstructor<any>;
858
+ functionName: string;
859
+ paramsTypes: any[];
860
+ }
861
+
862
+ interface IMiddlewareMetadata {
863
+ controllerConstructor: IConstructor<any>;
864
+ functionName: string;
865
+ middlewareConstructor: IConstructor<IMiddleware>;
866
+ }
867
+
868
+ interface IRestControllerMetadata {
869
+ controllerConstructor: IConstructor<any>;
870
+ path: string;
871
+ }
872
+
873
+ declare class RestControllerMetadataStore {
874
+ private endPoints;
875
+ private middlewares;
876
+ private restControllers;
877
+ saveControllerMetadata(controllerMetadata: IRestControllerMetadata): void;
878
+ saveEndPointMetadata(endPointMetadata: IEndPointMetadata): void;
879
+ saveMiddlewareMetadata(middlewareMetadata: IMiddlewareMetadata): void;
880
+ getControllerEndPointsInfo(controllerConstructor: IConstructor<any>): {
881
+ middlewares: IMiddlewareMetadata[];
882
+ controller: IRestControllerMetadata;
883
+ method: "get" | "post" | "put" | "delete";
884
+ config?: IEndPointConfig;
885
+ controllerConstructor: IConstructor<any>;
886
+ functionName: string;
887
+ paramsTypes: any[];
888
+ }[];
889
+ }
890
+
891
+ declare function runRestControllers(controllers: IConstructor<any>[]): void;
892
+
893
+ declare const EXPRESS_REQ = "EXPRESS_REQ";
894
+ declare const EXPRESS_RES = "EXPRESS_RES";
477
895
 
478
896
  declare class SocketServerProvider {
479
897
  private httpServerProvider;
@@ -485,138 +903,422 @@ declare class SocketServerProvider {
485
903
  private createSocketServer;
486
904
  }
487
905
 
488
- interface ISocketChannelReceivedMessage {
489
- chatId: string;
490
- userId: string;
491
- senderName: string;
492
- text: string;
906
+ interface IConnectionMiddleware {
907
+ handle(socket: Socket, container: DependencyContainer$1): Promise<void>;
493
908
  }
494
- declare class SocketChannel implements IChatChannel {
495
- private config;
496
- private socketServerProvider;
497
- private chatResolver;
498
- private userResolver;
499
- private callBack;
500
- private server;
501
- constructor(config: SocketChannelConfig, socketServerProvider: SocketServerProvider, chatResolver: ChatResolver, userResolver: UserResolver);
502
- listen(callback: (message: IReceivedMessage) => void): void;
503
- connect(): void;
909
+
910
+ declare function connectionMiddleware(middlewareConstructor: IConstructor<IConnectionMiddleware>): (target: object, propertyKey: string | symbol) => void;
911
+
912
+ interface ISocketConnectionConfig {
913
+ namespace: string;
504
914
  }
505
915
 
506
- interface ITelegramChannelConfig {
507
- botToken: string;
916
+ declare function socketConnection(config?: string | ISocketConnectionConfig): (target: object, propertyKey: string | symbol) => void;
917
+
918
+ interface ISocketControllerConfig {
919
+ namespace: string;
508
920
  }
509
- declare class TelegramChannelConfig implements ITelegramChannelConfig {
510
- botToken: string;
511
- constructor(botToken: string);
921
+
922
+ declare function socketController(config?: string | ISocketControllerConfig): (target: IConstructor<any>) => void;
923
+
924
+ interface ISocketEventConfig {
925
+ namespace?: string;
926
+ event: string;
512
927
  }
513
928
 
514
- declare function telegram(config: ITelegramChannelConfig): (target: object, propertyKey: string | symbol) => void;
929
+ declare function socketEvent(config: string | ISocketEventConfig): (target: object, propertyKey: string | symbol) => void;
515
930
 
516
- declare class TelegramChannel implements IChatChannel {
517
- private config;
518
- private chatResolver;
519
- private userResolver;
520
- private bot;
521
- constructor(config: TelegramChannelConfig, chatResolver: ChatResolver, userResolver: UserResolver);
522
- listen(callback: (message: IReceivedMessage) => void): void;
523
- connect(): void;
931
+ interface IConnectionMiddlewareMetadata {
932
+ controllerConstructor: IConstructor<any>;
933
+ functionName: string;
934
+ middlewareConstructor: IConstructor<IConnectionMiddleware>;
524
935
  }
525
936
 
526
- interface IWhatsappChannelConfig {
527
- number: string;
528
- proxy?: string;
937
+ interface ISocketConnectionMetadata {
938
+ config?: ISocketConnectionConfig;
939
+ controllerConstructor: IConstructor<any>;
940
+ functionName: string;
941
+ paramsTypes: any[];
529
942
  }
530
- declare class WhatsappChannelConfig implements IWhatsappChannelConfig {
531
- number: string;
532
- constructor(number: string);
943
+
944
+ interface ISocketControllerMetadata {
945
+ controllerConstructor: IConstructor<any>;
946
+ config?: ISocketControllerConfig;
533
947
  }
534
948
 
535
- declare function whatsapp(config: IWhatsappChannelConfig): (target: object, propertyKey: string | symbol) => void;
949
+ interface ISocketEventMetadata {
950
+ config: ISocketEventConfig;
951
+ controllerConstructor: IConstructor<any>;
952
+ functionName: string;
953
+ paramsTypes: any[];
954
+ }
955
+
956
+ declare class SocketControllerMetadataStore {
957
+ private socketControllers;
958
+ private socketConnections;
959
+ private socketEvents;
960
+ private connectionMiddlewares;
961
+ saveControllerMetadata(controllerMetadata: ISocketControllerMetadata): void;
962
+ saveSocketConnectionMetadata(socketConnectionMetadata: ISocketConnectionMetadata): void;
963
+ saveSocketEventMetadata(socketEventMetadata: ISocketEventMetadata): void;
964
+ saveConnectionMiddlewareMetadata(middlewareMetadata: IConnectionMiddlewareMetadata): void;
965
+ getControllerSockerConnectionsInfo(controllerConstructor: IConstructor<any>): {
966
+ events: ISocketEventMetadata[];
967
+ connectionMiddlewares: IConnectionMiddlewareMetadata[];
968
+ controller: ISocketControllerMetadata;
969
+ config?: ISocketConnectionConfig;
970
+ controllerConstructor: IConstructor<any>;
971
+ functionName: string;
972
+ paramsTypes: any[];
973
+ }[];
974
+ }
975
+
976
+ declare function runSocketControllers(controllers: IConstructor<any>[]): void;
977
+
978
+ declare class PgJobRepository extends PgCrudRepository<Job> implements IJobRepository {
979
+ constructor(pool: Pool);
980
+ }
536
981
 
537
- type IWhatsAppTemplateParameter = {
538
- type: 'text';
539
- text: string;
540
- parameter_name?: string;
541
- } | {
542
- type: 'currency';
543
- currency: {
544
- fallback_value: string;
545
- code: string;
546
- amount_1000: number;
547
- };
548
- } | {
549
- type: 'date_time';
550
- date_time: {
551
- fallback_value: string;
982
+ declare function apiKeyConnectionGuard(): (target: object, propertyKey: string | symbol) => void;
983
+
984
+ declare function apiKeyGuard(): (target: object, propertyKey: string | symbol) => void;
985
+
986
+ interface IApiKeyData<A extends IStorableData> extends IEntityData {
987
+ passwordHash?: string;
988
+ authInfo: A;
989
+ name: string;
990
+ }
991
+ declare class ApiKey<A extends IStorableData> extends Entity<IApiKeyData<A>> {
992
+ get authInfo(): A;
993
+ setAuthInfo(authInfo: A): void;
994
+ generatePassword(): string;
995
+ isValidPassword(password: string): boolean;
996
+ validatePassword(password: string): void;
997
+ static inflate(secret: string): {
998
+ id: string;
999
+ pass: string;
552
1000
  };
553
- };
554
- interface IWhatsAppTemplateMessage {
555
- templateName: string;
556
- languageCode: string;
557
- parameters: IWhatsAppTemplateParameter[];
1001
+ static deflate(data: {
1002
+ id: string;
1003
+ pass: string;
1004
+ }): string;
558
1005
  }
559
1006
 
560
- interface IWhatsAppWebhookPayload {
561
- object: 'whatsapp_business_account';
562
- entry: IEntry[];
1007
+ interface IApiKeyRepository<A extends IStorableData> {
1008
+ find(id: string): Promise<ApiKey<A> | null>;
1009
+ findOrThrow(id: string): Promise<ApiKey<A>>;
1010
+ create(item: ApiKey<A>): Promise<void>;
1011
+ generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes>;
1012
+ findAuthInfo(secret: string): Promise<A>;
1013
+ }
1014
+ interface IGenerateApiKeyReq<A extends IStorableData> extends IStorableData {
1015
+ name: string;
1016
+ authInfo: A;
563
1017
  }
564
- interface IEntry {
1018
+ interface IGenerateApiKeyRes {
565
1019
  id: string;
566
- changes: IChange[];
1020
+ secret: string;
567
1021
  }
568
- type IChange = IMessagesChange;
569
- interface IMessagesChange {
570
- value: IMessagesChangeValue;
571
- field: 'messages';
1022
+
1023
+ declare class ApiKeyRepository<A extends IStorableData> implements IApiKeyRepository<A> {
1024
+ findAuthInfo(secret: string): Promise<A>;
1025
+ find(id: string): Promise<ApiKey<A> | null>;
1026
+ findOrThrow(id: string): Promise<ApiKey<A>>;
1027
+ create(item: ApiKey<A>): Promise<void>;
1028
+ generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes>;
1029
+ static generate(repository: ApiKeyRepository<any>, req: IGenerateApiKeyReq<any>): Promise<{
1030
+ id: string;
1031
+ secret: string;
1032
+ }>;
1033
+ static findAuthInfo<A extends IStorableData>(repository: ApiKeyRepository<A>, secret: string): Promise<A>;
572
1034
  }
573
- interface IMessagesChangeValue {
574
- messaging_product: 'whatsapp';
575
- metadata: IMessageMetadata;
576
- contacts?: IWhatsAppContact[];
577
- messages?: IWhatsAppMessage[];
1035
+
1036
+ declare class ApiKeyConnectionGuardMiddleware implements IConnectionMiddleware {
1037
+ private apiKeyRepository;
1038
+ private auth;
1039
+ constructor(apiKeyRepository: ApiKeyRepository<any>, auth: Auth<any>);
1040
+ handle(socket: Socket, container: DependencyContainer$1): Promise<void>;
578
1041
  }
579
- interface IMessageMetadata {
580
- display_phone_number: string;
581
- phone_number_id: string;
1042
+
1043
+ declare class ApiKeyGuardMiddleware implements IMiddleware {
1044
+ private apiKeyRepository;
1045
+ private auth;
1046
+ constructor(apiKeyRepository: ApiKeyRepository<any>, auth: Auth<any>);
1047
+ handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
582
1048
  }
583
- interface IWhatsAppContact {
584
- profile: {
585
- name: string;
1049
+
1050
+ declare class PgApiKeyRepository<A extends IStorableData> extends PgCrudRepository<ApiKey<A>> implements IApiKeyRepository<A> {
1051
+ constructor(pool: Pool);
1052
+ findAuthInfo(secret: string): Promise<A>;
1053
+ generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes>;
1054
+ }
1055
+
1056
+ declare class RemoteApiKeyRepository<A extends IStorableData> implements IApiKeyRepository<A> {
1057
+ private fetcher;
1058
+ private cacheSeconds;
1059
+ private cache;
1060
+ constructor(fetcher: (id: string) => Promise<ApiKey<A> | null>, cacheSeconds: number);
1061
+ find(id: string): Promise<ApiKey<A> | null>;
1062
+ findOrThrow(id: string): Promise<ApiKey<A>>;
1063
+ findAuthInfo(secret: string): Promise<A>;
1064
+ create(item: ApiKey<A>): Promise<void>;
1065
+ generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes>;
1066
+ }
1067
+
1068
+ declare function jwtConnectionGuard(): (target: object, propertyKey: string | symbol) => void;
1069
+
1070
+ declare function jwtGuard(): (target: object, propertyKey: string | symbol) => void;
1071
+
1072
+ interface IJwtRefreshTokenData<A extends IStorableData> extends IEntityData {
1073
+ authInfo: A;
1074
+ passwordHash?: string;
1075
+ expirationTime: number;
1076
+ }
1077
+ declare class JwtRefreshToken<A extends IStorableData> extends Entity<IJwtRefreshTokenData<A>> {
1078
+ get authInfo(): A;
1079
+ get expirationTime(): Date;
1080
+ generatePassword(): string;
1081
+ isValidPassword(password: string): boolean;
1082
+ validatePassword(password: string): void;
1083
+ static inflate(secret: string): {
1084
+ id: string;
1085
+ pass: string;
586
1086
  };
587
- wa_id: string;
1087
+ static deflate(data: {
1088
+ id: string;
1089
+ pass: string;
1090
+ }): string;
1091
+ }
1092
+
1093
+ interface IJwtRefreshTokenRepository<D extends IStorableData> extends ICrudRepository<JwtRefreshToken<D>> {
1094
+ }
1095
+
1096
+ declare class JwtTokenDto {
1097
+ token?: string;
1098
+ expiration?: Date;
1099
+ }
1100
+
1101
+ declare class JwtAccessAndRefreshTokenDto {
1102
+ access?: JwtTokenDto;
1103
+ refresh?: JwtTokenDto;
1104
+ }
1105
+
1106
+ declare class JwtConfig {
1107
+ secretOrPublicKey: string;
1108
+ secretOrPrivateKey: string;
1109
+ algorithm: Algorithm;
1110
+ accessExpirationSeconds: number;
1111
+ refreshExpirationSeconds: number;
1112
+ constructor(env: Env);
1113
+ }
1114
+
1115
+ declare class JwtSigner {
1116
+ private config;
1117
+ private mapper;
1118
+ constructor(config: JwtConfig, mapper: Mapper);
1119
+ signAccessToken<D extends IStorableData>(info: D | JwtRefreshToken<any>): Promise<JwtTokenDto>;
1120
+ }
1121
+
1122
+ declare class JwtRefreshTokenRepository<D extends IStorableData> implements IJwtRefreshTokenRepository<D> {
1123
+ find(id: string): Promise<JwtRefreshToken<D> | null>;
1124
+ findOrThrow(id: string): Promise<JwtRefreshToken<D>>;
1125
+ findByIds(ids: string[]): Promise<JwtRefreshToken<D>[]>;
1126
+ findAll(id: string): Promise<JwtRefreshToken<D>[]>;
1127
+ create(item: JwtRefreshToken<D>): Promise<void>;
1128
+ update(item: JwtRefreshToken<D>): Promise<void>;
1129
+ delete(item: JwtRefreshToken<D>): Promise<void>;
1130
+ }
1131
+
1132
+ declare class Jwt {
1133
+ private auth;
1134
+ private jwtSigner;
1135
+ private jwtRefreshTokenRepository;
1136
+ private config;
1137
+ constructor(auth: Auth<any>, jwtSigner: JwtSigner, jwtRefreshTokenRepository: JwtRefreshTokenRepository<any>, config: JwtConfig);
1138
+ createToken(): Promise<JwtAccessAndRefreshTokenDto>;
1139
+ refreshToken(refreshSecret: string): Promise<JwtTokenDto>;
1140
+ }
1141
+
1142
+ declare class JwtConnectionGuardMiddleware implements IConnectionMiddleware {
1143
+ private config;
1144
+ private auth;
1145
+ constructor(config: JwtConfig, auth: Auth<any>);
1146
+ handle(socket: Socket, container: DependencyContainer$1): Promise<void>;
1147
+ }
1148
+
1149
+ declare class JwtGuardMiddleware implements IMiddleware {
1150
+ private config;
1151
+ private auth;
1152
+ constructor(config: JwtConfig, auth: Auth<any>);
1153
+ handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
1154
+ }
1155
+
1156
+ declare class PgJwtRefreshTokenRepository<D extends IStorableData> extends PgCrudRepository<JwtRefreshToken<D>> implements IJwtRefreshTokenRepository<D> {
1157
+ constructor(pool: Pool);
1158
+ }
1159
+
1160
+ declare class AnthropicChatAdapter implements IChatAdapter {
1161
+ private env;
1162
+ private anthropic;
1163
+ private logger;
1164
+ constructor(env: Env);
1165
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
1166
+ private mapChatItems;
1167
+ private mapHumanMessage;
1168
+ private mapBotMessage;
1169
+ private mapFunctionCall;
1170
+ private mapTool;
1171
+ private mapResponse;
1172
+ }
1173
+
1174
+ declare class DeepSeekChatAdapter implements IChatAdapter {
1175
+ private deepSeek;
1176
+ private logger;
1177
+ constructor();
1178
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
1179
+ private mapChatItems;
1180
+ private mapHumanMessage;
1181
+ private mapBotMessage;
1182
+ private mapFunctionCall;
1183
+ private mapTool;
1184
+ private mapResponse;
1185
+ }
1186
+
1187
+ declare class GoogleChatAdapter implements IChatAdapter {
1188
+ private env;
1189
+ private openai;
1190
+ private logger;
1191
+ constructor(env: Env);
1192
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
1193
+ private mapChatItems;
1194
+ private mapHumanMessage;
1195
+ private mapBotMessage;
1196
+ private mapFunctionCall;
1197
+ private mapTool;
1198
+ private mapResponse;
1199
+ }
1200
+
1201
+ declare class OpenaiChatAdapter implements IChatAdapter {
1202
+ private openai;
1203
+ private logger;
1204
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
1205
+ private mapChatItems;
1206
+ private mapConectionMessage;
1207
+ private mapBotMessage;
1208
+ private mapFunctionCall;
1209
+ private mapTool;
1210
+ private mapResponse;
1211
+ }
1212
+
1213
+ declare class PgChatRepository extends PgCrudRepository<Chat> implements IChatRepository {
1214
+ constructor(pool: Pool);
1215
+ findByConnection(query: IChatConnection): Promise<Chat | null>;
1216
+ findMemory(chatId: string): Promise<IChatMemory | null>;
1217
+ }
1218
+
1219
+ declare class PgChatMemory extends PgCrudRepository<ChatItem> implements IChatMemory {
1220
+ private chatId;
1221
+ constructor(pool: Pool, chatId: string);
1222
+ findLastItems(count: number): Promise<ChatItem[]>;
1223
+ }
1224
+
1225
+ declare class RamChatMemory implements IChatMemory {
1226
+ private memory;
1227
+ findLastItems(count: number): Promise<ChatItem[]>;
1228
+ create(item: ChatItem): Promise<void>;
1229
+ clearMemory(): Promise<void>;
1230
+ }
1231
+
1232
+ declare class RamChatRepository implements IChatRepository {
1233
+ private items;
1234
+ private memories;
1235
+ create(chat: Chat): Promise<void>;
1236
+ findByConnection(query: IChatConnection): Promise<Chat | null>;
1237
+ findMemory(chatId: string): Promise<IChatMemory | null>;
1238
+ private getMemory;
1239
+ }
1240
+
1241
+ declare class WabotChatAdapter implements IChatAdapter {
1242
+ private apiKey;
1243
+ private baseUrl;
1244
+ private logger;
1245
+ constructor(env: Env);
1246
+ nextItem(req: IChatAdapterNextItemReq): Promise<IChatAdapterNextItemRes>;
1247
+ }
1248
+
1249
+ declare function cmd(): (target: object, propertyKey: string | symbol) => void;
1250
+
1251
+ declare class CmdChannel implements IChatChannel {
1252
+ private rl;
1253
+ private callBack;
1254
+ listen(callback: (message: IChannelMessage) => void): void;
1255
+ connect(): void;
1256
+ }
1257
+
1258
+ interface ISocketChannelConfig {
1259
+ channel: string;
1260
+ }
1261
+
1262
+ declare class SocketChannelConfig implements ISocketChannelConfig {
1263
+ channel: string;
1264
+ constructor(channel: string);
1265
+ }
1266
+
1267
+ declare function socket(config: SocketChannelConfig): (target: object, propertyKey: string | symbol) => void;
1268
+
1269
+ interface ISocketChannelReceivedMessage {
1270
+ chatId: string;
1271
+ userId: string;
1272
+ senderName: string;
1273
+ text: string;
1274
+ }
1275
+ declare class SocketChannel implements IChatChannel {
1276
+ private config;
1277
+ private socketServerProvider;
1278
+ private callBack;
1279
+ private server;
1280
+ constructor(config: SocketChannelConfig, socketServerProvider: SocketServerProvider);
1281
+ listen(callback: (message: IChannelMessage) => void): void;
1282
+ connect(): void;
1283
+ }
1284
+
1285
+ interface ITelegramChannelConfig {
1286
+ botToken: string;
588
1287
  }
589
- type IWhatsAppMessage = ITextMessage | IAudioMessage;
590
- interface IBaseMessage {
591
- from: string;
592
- id: string;
593
- timestamp: string;
594
- type: string;
1288
+ declare class TelegramChannelConfig implements ITelegramChannelConfig {
1289
+ botToken: string;
1290
+ constructor(botToken: string);
595
1291
  }
596
- interface ITextMessage extends IBaseMessage {
597
- type: 'text';
598
- text: {
599
- body: string;
600
- };
1292
+
1293
+ declare function telegram(config: ITelegramChannelConfig): (target: object, propertyKey: string | symbol) => void;
1294
+
1295
+ declare class TelegramChannel implements IChatChannel {
1296
+ private config;
1297
+ private bot;
1298
+ constructor(config: TelegramChannelConfig);
1299
+ listen(callback: (message: IChannelMessage) => void): void;
1300
+ connect(): void;
601
1301
  }
602
- interface IAudioMessage extends IBaseMessage {
603
- type: 'audio';
604
- audio: {
605
- mime_type: string;
606
- sha256: string;
607
- id: string;
608
- voice: boolean;
609
- };
1302
+
1303
+ interface IWhatsappChannelConfig {
1304
+ number: string;
1305
+ proxy?: string;
1306
+ }
1307
+ declare class WhatsappChannelConfig implements IWhatsappChannelConfig {
1308
+ number: string;
1309
+ constructor(number: string);
610
1310
  }
611
1311
 
612
- interface IWhatsAppBusinessNumber {
1312
+ declare function whatsApp(config: string | IWhatsappChannelConfig): (target: object, propertyKey: string | symbol) => void;
1313
+
1314
+ interface IWhatsAppBusinessNumber extends IStorableData {
613
1315
  id: string;
614
1316
  number: string;
615
1317
  }
616
- interface IWhatsAppBusinessAccount {
1318
+ interface IWhatsAppBusinessAccount extends IStorableData {
617
1319
  id: string;
618
1320
  }
619
- interface IWhatsAppData extends IPersistentData {
1321
+ interface IWhatsAppData extends IEntityData {
620
1322
  slug: string;
621
1323
  verifyToken: string;
622
1324
  appSecret: string;
@@ -624,7 +1326,7 @@ interface IWhatsAppData extends IPersistentData {
624
1326
  businessAccount: IWhatsAppBusinessAccount;
625
1327
  businessNumbers: IWhatsAppBusinessNumber[];
626
1328
  }
627
- declare class WhatsApp extends Persistent<IWhatsAppData> {
1329
+ declare class WhatsApp extends Entity<IWhatsAppData> {
628
1330
  getVerifyToken(): string;
629
1331
  getSlug(): string;
630
1332
  getBusinessAccount(): IWhatsAppBusinessAccount;
@@ -635,57 +1337,88 @@ declare class WhatsApp extends Persistent<IWhatsAppData> {
635
1337
  getBussinessNumber(number: string): IWhatsAppBusinessNumber | null;
636
1338
  }
637
1339
 
638
- declare class Logger {
639
- private debuggers;
640
- constructor(name: string);
641
- trace(...args: any[]): void;
642
- debug(...args: any[]): void;
643
- info(...args: any[]): void;
644
- warn(...args: any[]): void;
645
- error(...args: any[]): void;
646
- fatal(...args: any[]): void;
647
- private log;
1340
+ interface IWhatsAppRepository {
1341
+ findBySlug(slug: string): Promise<WhatsApp | null>;
1342
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
1343
+ }
1344
+
1345
+ declare class EnvWhatsAppRepository implements IWhatsAppRepository {
1346
+ private env;
1347
+ constructor(env: Env);
1348
+ findBySlug(slug: string): Promise<WhatsApp | null>;
1349
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
1350
+ private getFromEnvVars;
1351
+ }
1352
+
1353
+ declare class PgWhatsAppRepository extends PgCrudRepository<WhatsApp> implements IWhatsAppRepository {
1354
+ constructor(pool: Pool);
1355
+ findBySlug(slug: string): Promise<WhatsApp | null>;
1356
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
648
1357
  }
649
1358
 
650
- type IWhatsAppMessageListener = (message: IConnectionChatMessage) => Promise<void>;
1359
+ type IWhatsAppMessageListener = (message: Omit<IChannelMessage, 'reply'>) => Promise<void>;
651
1360
  interface IListenWhatsAppMessageRequest {
652
1361
  to: string;
653
1362
  listener: IWhatsAppMessageListener;
654
1363
  }
655
- declare abstract class WhatsAppReceiver {
656
- protected logger: Logger;
657
- private listeners;
658
- constructor(logger: Logger);
659
- abstract connect(): Promise<void>;
1364
+ declare class WhatsAppReceiver {
1365
+ connect(): Promise<void>;
660
1366
  listenMessage(request: IListenWhatsAppMessageRequest): void;
661
- protected handlePayload(payload: IWhatsAppWebhookPayload): Promise<void>;
662
- private emmitMessage;
663
1367
  }
664
1368
 
665
- interface IWhatsAppRepository {
666
- findBySlug(slug: string): Promise<WhatsApp | null>;
667
- findByBusinessNumber(number: string): Promise<WhatsApp | null>;
1369
+ type IWhatsAppCloudTemplateParameter = {
1370
+ type: 'text';
1371
+ text: string;
1372
+ parameter_name?: string;
1373
+ } | {
1374
+ type: 'currency';
1375
+ currency: {
1376
+ fallback_value: string;
1377
+ code: string;
1378
+ amount_1000: number;
1379
+ };
1380
+ } | {
1381
+ type: 'date_time';
1382
+ date_time: {
1383
+ fallback_value: string;
1384
+ };
1385
+ };
1386
+ interface IWhatsAppCloudTemplateMessage {
1387
+ templateName: string;
1388
+ languageCode: string;
1389
+ parameters: IWhatsAppCloudTemplateParameter[];
668
1390
  }
669
1391
 
670
- declare class WhatsAppRepository implements IWhatsAppRepository {
671
- findBySlug(slug: string): Promise<WhatsApp | null>;
672
- findByBusinessNumber(number: string): Promise<WhatsApp | null>;
1392
+ interface IWhatsAppCloudTemplateResponse {
1393
+ data: IWhatsAppCloudTemplate[];
1394
+ paging: IWhatsAppCloudApiPaging;
673
1395
  }
674
-
675
- interface IWhatsAppTemplate {
1396
+ interface IWhatsAppCloudTemplate {
676
1397
  name: string;
677
1398
  parameter_format: 'POSITIONAL' | 'OTHER';
678
- components: IWhatsAppTemplateComponent[];
1399
+ components: IWhatsAppCloudTemplateComponent[];
679
1400
  language: string;
680
1401
  status: string;
681
1402
  category: string;
682
1403
  id: string;
683
1404
  }
684
- interface IWhatsAppTemplateComponent {
1405
+ interface IWhatsAppCloudTemplateComponent {
685
1406
  type: 'HEADER' | 'BODY' | 'FOOTER';
686
1407
  format?: 'TEXT';
687
1408
  text?: string;
688
1409
  }
1410
+ interface IWhatsAppCloudApiPaging {
1411
+ cursors: IWhatsAppCloudApiCursors;
1412
+ }
1413
+ interface IWhatsAppCloudApiCursors {
1414
+ before: string;
1415
+ after: string;
1416
+ }
1417
+
1418
+ declare class WhatsAppRepository implements IWhatsAppRepository {
1419
+ findBySlug(slug: string): Promise<WhatsApp | null>;
1420
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
1421
+ }
689
1422
 
690
1423
  interface ISendWhatsAppRequest {
691
1424
  from: string;
@@ -695,7 +1428,7 @@ interface ISendWhatsAppRequest {
695
1428
  interface ISendWhatsAppTemplateRequest {
696
1429
  from: string;
697
1430
  to: string;
698
- templateMessage: IWhatsAppTemplateMessage;
1431
+ templateMessage: IWhatsAppCloudTemplateMessage;
699
1432
  senderName: string;
700
1433
  }
701
1434
  interface IGetWhatsAppTemplateRequest {
@@ -706,270 +1439,164 @@ interface IGetWhatsAppTemplateRequest {
706
1439
  interface IWhatsAppSenderOptions {
707
1440
  writeChatMemory?: boolean;
708
1441
  }
709
- declare abstract class WhatsAppSender {
710
- protected logger: Logger;
1442
+ declare class WhatsAppSender {
711
1443
  protected chatRepository: ChatRepository;
712
1444
  protected chatResolver: ChatResolver;
713
1445
  protected whatsAppRepository: WhatsAppRepository;
714
- constructor(logger: Logger, chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
715
- protected abstract handleSendRequest(request: ISendWhatsAppRequest): Promise<void>;
716
- protected abstract handleSendTemplateRequest(request: ISendWhatsAppTemplateRequest): Promise<void>;
717
- protected abstract handleGetWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
1446
+ constructor(chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
718
1447
  sendWhatsApp(request: ISendWhatsAppRequest, options?: IWhatsAppSenderOptions): Promise<void>;
719
1448
  sendWhatsAppTemplate(request: ISendWhatsAppTemplateRequest, options?: IWhatsAppSenderOptions): Promise<void>;
720
- getWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
721
- protected resolveTemplateToChatMessage(request: ISendWhatsAppTemplateRequest): Promise<IChatMessage>;
1449
+ protected getWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppCloudTemplate | null>;
1450
+ protected mapTemplateToChatMessage(request: ISendWhatsAppTemplateRequest): Promise<IChatMessage>;
722
1451
  protected writePrivateChatMemory(message: IChatMessage, to: string): Promise<void>;
723
- private replaceTemplateParameters;
1452
+ protected replaceTemplateParameters(template: string, data: IWhatsAppCloudTemplateParameter[]): string;
724
1453
  }
725
1454
 
726
1455
  declare class WhatsAppChannel implements IChatChannel {
727
1456
  private config;
728
- private chatResolver;
729
- private userResolver;
730
1457
  private sender;
731
1458
  private receiver;
732
1459
  private logger;
733
- constructor(config: WhatsappChannelConfig, chatResolver: ChatResolver, userResolver: UserResolver, sender: WhatsAppSender, receiver: WhatsAppReceiver);
734
- listen(callback: (message: IReceivedMessage) => void): void;
1460
+ constructor(config: WhatsappChannelConfig, sender: WhatsAppSender, receiver: WhatsAppReceiver);
1461
+ listen(callback: (message: IChannelMessage) => void): void;
735
1462
  connect(): void;
736
1463
  }
737
1464
 
738
- declare class WabotDevConnection {
739
- private devProxy;
740
- private devProxySocket;
741
- private devToken;
742
- private logger;
743
- static isTokenAvailable(): boolean;
744
- constructor();
745
- getSocket(): Promise<Socket>;
746
- }
747
-
748
- declare class WhatsAppReceiverByDevConnection extends WhatsAppReceiver {
749
- private wabotDevConnection;
750
- constructor(wabotDevConnection: WabotDevConnection);
751
- connect(): Promise<void>;
1465
+ interface IWhatsAppCloudWebhookPayload {
1466
+ object: 'whatsapp_business_account';
1467
+ entry: IWhatsAppCloudEntry[];
752
1468
  }
753
-
754
- declare class WhatsAppReceiverByWebHook extends WhatsAppReceiver {
755
- private expressProvider;
756
- private whatsAppRepository;
757
- private expressApp;
758
- private webhookPath;
759
- constructor(expressProvider: ExpressProvider, whatsAppRepository: WhatsAppRepository);
760
- connect(): Promise<void>;
1469
+ interface IWhatsAppCloudEntry {
1470
+ id: string;
1471
+ changes: IWhatsAppCloudChange[];
761
1472
  }
762
-
763
- declare class WhatsAppSenderByDevConnection extends WhatsAppSender {
764
- private wabotDevConnection;
765
- constructor(wabotDevConnection: WabotDevConnection, chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
766
- handleSendRequest(request: ISendWhatsAppRequest): Promise<void>;
767
- handleSendTemplateRequest(request: ISendWhatsAppTemplateRequest): Promise<void>;
768
- handleGetWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
1473
+ type IWhatsAppCloudChange = IWhatsAppCloudMessagesChange;
1474
+ interface IWhatsAppCloudMessagesChange {
1475
+ value: IWhatsAppCloudMessagesChangeValue;
1476
+ field: 'messages';
769
1477
  }
770
-
771
- declare class WhatsAppSenderByCloudApi extends WhatsAppSender {
772
- constructor(chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
773
- handleSendRequest(request: ISendWhatsAppRequest): Promise<void>;
774
- handleSendTemplateRequest(request: ISendWhatsAppTemplateRequest): Promise<void>;
775
- handleGetWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
1478
+ interface IWhatsAppCloudMessagesChangeValue {
1479
+ messaging_product: 'whatsapp';
1480
+ metadata: IWhatsAppCloudMessageMetadata;
1481
+ contacts?: IWhatsAppCloudContact[];
1482
+ messages?: IWhatsAppCloudMessage[];
776
1483
  }
777
-
778
- interface ICrudRepository<T> {
779
- find(id: string): Promise<T | null>;
780
- findAll(id: string): Promise<T[]>;
781
- create(item: T): Promise<void>;
782
- update(item: T): Promise<void>;
783
- discard(item: T): Promise<void>;
1484
+ interface IWhatsAppCloudMessageMetadata {
1485
+ display_phone_number: string;
1486
+ phone_number_id: string;
784
1487
  }
785
-
786
- type IPgRepositoryConfig<P extends Persistent> = {
787
- schema?: string;
788
- table: string;
789
- constructor: IConstructor<P>;
790
- add?: {
791
- columns: {
792
- [column: string]: {
793
- type: string;
794
- value: (item: P) => boolean | number | string | null | Date;
795
- };
796
- };
797
- };
798
- };
799
-
800
- declare class PgRepositoryBase<P extends Persistent> {
801
- protected pool: Pool;
802
- protected config: IPgRepositoryConfig<any>;
803
- private tableIsCreated;
804
- schema: string;
805
- table: string;
806
- columnsList: string[];
807
- columnsAndTypes: string;
808
- columns: string;
809
- vars: string;
810
- updates: string;
811
- addColumns: {
812
- [columns: string]: {
813
- type: string;
814
- value: (item: P) => number | boolean | string | null | Date;
815
- };
1488
+ interface IWhatsAppCloudContact {
1489
+ profile: {
1490
+ name: string;
816
1491
  };
817
- constructor(pool: Pool, config: IPgRepositoryConfig<any>);
818
- values(item: P): (string | number | boolean | Date | null)[];
819
- protected exec(sql: string, values: any[]): Promise<void>;
820
- protected query(sql: string, values: any[]): Promise<any[]>;
821
- protected connect(): Promise<Pool>;
822
- protected ensureTable(): Promise<void>;
823
- protected ensureColumns(): Promise<void>;
824
- }
825
-
826
- declare class PgCrudRepository<P extends Persistent> extends PgRepositoryBase<P> implements ICrudRepository<P> {
827
- protected readonly config: IPgRepositoryConfig<P>;
828
- constructor(pool: Pool, config: IPgRepositoryConfig<P>);
829
- find(id: string): Promise<P | null>;
830
- findAll(): Promise<P[]>;
831
- create(item: P): Promise<void>;
832
- update(item: P): Promise<void>;
833
- discard(item: P): Promise<void>;
834
- }
835
-
836
- declare class PgWhatsAppRepository extends PgCrudRepository<WhatsApp> implements IWhatsAppRepository {
837
- constructor(pool: Pool);
838
- findBySlug(slug: string): Promise<WhatsApp | null>;
839
- findByBusinessNumber(number: string): Promise<WhatsApp | null>;
1492
+ wa_id: string;
840
1493
  }
841
-
842
- type IWabotEnvType = 'development' | 'staging' | 'testing' | 'production';
843
- declare class WabotEnv {
844
- private envType;
845
- constructor();
846
- isDevelopment(): boolean;
847
- isProduction(): boolean;
848
- requireString(varName: string): string;
1494
+ type IWhatsAppCloudMessage = IWhatsAppCloudTextMessage | IWhatsAppCloudAudioMessage;
1495
+ interface IWhatsAppCloudBaseMessage {
1496
+ from: string;
1497
+ id: string;
1498
+ timestamp: string;
1499
+ type: string;
849
1500
  }
850
-
851
- declare class EnvWhatsAppRepository implements IWhatsAppRepository {
852
- private env;
853
- constructor(env: WabotEnv);
854
- findBySlug(slug: string): Promise<WhatsApp | null>;
855
- findByBusinessNumber(number: string): Promise<WhatsApp | null>;
856
- private getFromEnvVars;
1501
+ interface IWhatsAppCloudTextMessage extends IWhatsAppCloudBaseMessage {
1502
+ type: 'text';
1503
+ text: {
1504
+ body: string;
1505
+ };
857
1506
  }
858
-
859
- declare function prepareChatContainer(container: DependencyContainer$1, context: IMessageContext, mindsetCtor?: IConstructor<IMindset>): Promise<DependencyContainer$1>;
860
-
861
- interface IrunChannelProps {
862
- channel: IConstructor<IChatChannel>;
863
- channelConfig?: object;
864
- mindset: IConstructor<IMindset>;
865
- chatRepository: IConstructor<IChatRepository>;
866
- chatBotAdapter: IConstructor<IChatBotAdapter>;
1507
+ interface IWhatsAppCloudAudioMessage extends IWhatsAppCloudBaseMessage {
1508
+ type: 'audio';
1509
+ audio: {
1510
+ mime_type: string;
1511
+ sha256: string;
1512
+ id: string;
1513
+ voice: boolean;
1514
+ };
867
1515
  }
868
- declare function runChannel(props: IrunChannelProps): void;
869
1516
 
870
- interface IServerProvider<T, ST extends T> {
871
- replace: IConstructor<T>;
872
- with: IConstructor<ST>;
873
- singleton?: true;
874
- }
875
- interface IServerConfig {
876
- controllers: IConstructor<any>[];
877
- providers?: IServerProvider<unknown, unknown>[];
1517
+ declare class WhatsAppReceiverByCloudApi extends WhatsAppReceiver {
1518
+ private expressProvider;
1519
+ private whatsAppRepository;
1520
+ private listeners;
1521
+ private expressApp;
1522
+ private logger;
1523
+ private webhookPath;
1524
+ constructor(expressProvider: ExpressProvider, whatsAppRepository: WhatsAppRepository);
1525
+ connect(): Promise<void>;
1526
+ listenMessage(request: IListenWhatsAppMessageRequest): void;
1527
+ protected handlePayload(payload: IWhatsAppCloudWebhookPayload): Promise<void>;
1528
+ private emmitMessage;
878
1529
  }
879
- declare function runServer(config: IServerConfig): void;
880
1530
 
881
- declare class SendOneTimePasswordRequest {
882
- fromEmail: string;
883
- toEmail: string;
1531
+ declare class WhatsAppSenderByCloudApi extends WhatsAppSender {
1532
+ private logger;
1533
+ constructor(chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
1534
+ sendWhatsApp(request: ISendWhatsAppRequest, options?: IWhatsAppSenderOptions): Promise<void>;
1535
+ sendWhatsAppTemplate(request: ISendWhatsAppTemplateRequest, options?: IWhatsAppSenderOptions): Promise<void>;
1536
+ protected getWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppCloudTemplate | null>;
884
1537
  }
885
1538
 
886
- declare class ValidateOneTimePasswordRequest {
887
- userEmail: string;
888
- otp: string;
1539
+ interface IWhatsAppProxyMessageContent {
1540
+ text: string;
889
1541
  }
890
1542
 
891
- interface ISendEmailRequest {
1543
+ interface IWhatsAppProxyMessage {
892
1544
  from: string;
893
1545
  to: string;
894
- subject: string;
895
- html: string;
896
- }
897
- interface IEmailService {
898
- sendEmail(request: ISendEmailRequest): Promise<void>;
899
- }
900
- declare class EmailService implements IEmailService {
901
- sendEmail(request: ISendEmailRequest): Promise<void>;
902
- }
903
-
904
- interface IOtpService {
905
- generate(): Promise<string>;
906
- }
907
- declare class OtpService implements IOtpService {
908
- generate(): Promise<string>;
909
- }
910
-
911
- declare class AuthenticationModule {
912
- private userRepository;
913
- private emailService;
914
- private otpService;
915
- private context;
916
- constructor(userRepository: UserRepository, emailService: EmailService, otpService: OtpService, context: MessageContext);
917
- sendOneTimePassword(request: SendOneTimePasswordRequest): Promise<string>;
918
- validateOneTimePassword(request: ValidateOneTimePasswordRequest): Promise<string>;
919
- protected generateOtpEmailHtml(otp: string, user: User): Promise<string>;
920
- protected generateOtpEmailSubject(): Promise<string>;
1546
+ senderName?: string;
1547
+ content: IWhatsAppProxyMessageContent;
921
1548
  }
922
1549
 
923
- declare class RegisterUserWithEmailRequest {
924
- email: string;
925
- shortName: string;
1550
+ declare const WHATSAPP_PROXY_SEND_MESSAGE_EVENT: "sendMessage";
1551
+ interface IWhatsAppProxySendMessageEventReq {
1552
+ event: typeof WHATSAPP_PROXY_SEND_MESSAGE_EVENT;
1553
+ data: IWhatsAppProxyMessage;
926
1554
  }
927
-
928
- declare class RegisterUserModule {
929
- private userRepository;
930
- private context;
931
- constructor(userRepository: UserRepository, context: MessageContext);
932
- registerUserWithEmail(request: RegisterUserWithEmailRequest): Promise<string>;
1555
+ declare const WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT: "listenMessage";
1556
+ interface IWhatsAppProxyListenMessageEventReq {
1557
+ event: typeof WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT;
1558
+ data: IWhatsAppProxyListenMessageEventData;
933
1559
  }
934
-
935
- declare class PgUserRepository extends PgCrudRepository<User> implements IUserRepository {
936
- constructor(pool: Pool);
937
- findByConnection(query: IUserConnection): Promise<User | null>;
1560
+ interface IWhatsAppProxyListenMessageEventData {
1561
+ from?: string[];
1562
+ to: string[];
938
1563
  }
939
-
940
- declare class RamUserRepository implements IUserRepository {
941
- private items;
942
- create(chat: User): Promise<void>;
943
- findByConnection(query: IUserConnection): Promise<User | null>;
944
- update(chat: User): Promise<void>;
1564
+ declare const WHATSAPP_MESSAGE_EVENT: "message";
1565
+ interface IWhatsAppProxyMessageEventReq {
1566
+ event: typeof WHATSAPP_MESSAGE_EVENT;
1567
+ data: IWhatsAppProxyMessage;
945
1568
  }
946
1569
 
947
- declare class PgChatRepository extends PgCrudRepository<Chat> implements IChatRepository {
948
- constructor(pool: Pool);
949
- findByConnection(query: IChatConnection): Promise<Chat | null>;
950
- findMemory(chatId: string): Promise<IChatMemory | null>;
1570
+ declare class WhatsAppWabotProxyConnection {
1571
+ private baseUrl;
1572
+ private socket;
1573
+ private apiKey;
1574
+ private logger;
1575
+ constructor(env: Env);
1576
+ getSocket(): Promise<Socket$1>;
951
1577
  }
952
1578
 
953
- declare class PgChatMemory extends PgCrudRepository<ChatItem> implements IChatMemory {
954
- private chatId;
955
- constructor(pool: Pool, chatId: string);
956
- findLastItems(count: number): Promise<ChatItem[]>;
1579
+ declare class WhatsAppReceiverByWabotProxy extends WhatsAppReceiver {
1580
+ private connection;
1581
+ private loger;
1582
+ constructor(connection: WhatsAppWabotProxyConnection);
1583
+ connect(): Promise<void>;
1584
+ listenMessage(request: IListenWhatsAppMessageRequest): void;
957
1585
  }
958
1586
 
959
- declare class RamChatMemory implements IChatMemory {
960
- private memory;
961
- findLastItems(count: number): Promise<ChatItem[]>;
962
- create(item: ChatItem): Promise<void>;
963
- clearMemory(): Promise<void>;
1587
+ declare class WhatsAppSenderByWabotProxy extends WhatsAppSender {
1588
+ private wabotDevConnection;
1589
+ private logger;
1590
+ constructor(wabotDevConnection: WhatsAppWabotProxyConnection, chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
1591
+ sendWhatsApp(request: ISendWhatsAppRequest, options?: IWhatsAppSenderOptions): Promise<void>;
964
1592
  }
965
1593
 
966
- declare class RamChatRepository implements IChatRepository {
967
- private items;
968
- private memories;
969
- create(chat: Chat): Promise<void>;
970
- findByConnection(query: IChatConnection): Promise<Chat | null>;
971
- findMemory(chatId: string): Promise<IChatMemory | null>;
972
- private getMemory;
1594
+ interface IHtmlModuleOptions {
1595
+ url: string;
1596
+ title: string;
973
1597
  }
1598
+ declare function HtmlModule(options: IHtmlModuleOptions): {
1599
+ new (): {};
1600
+ };
974
1601
 
975
- export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, DeepSeekChatBotAdapter, EmailService, EnvWhatsAppRepository, ExpressProvider, HttpServerProvider, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type IEmailService, type IGetWhatsAppTemplateRequest, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IReceivedMessage, type IReceivedMessageItem, type IReversibleMapper, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IWabotEnvType, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, container, inject, injectable, isOptional, mindset, mindsetFunction, mindsetModule, param, prepareChatContainer, runChannel, runServer, singleton, socket, telegram, whatsapp };
1602
+ export { AnthropicChatAdapter, ApiKey, ApiKeyConnectionGuardMiddleware, ApiKeyGuardMiddleware, ApiKeyRepository, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatAdapterNextItemRes, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConnectionMiddleware, type IConnectionMiddlewareMetadata, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISocketConnectionConfig, type ISocketConnectionMetadata, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppCloudContact, type IWhatsAppCloudMessage, type IWhatsAppCloudMessageMetadata, type IWhatsAppCloudTemplate, type IWhatsAppCloudTemplateComponent, type IWhatsAppCloudTemplateMessage, type IWhatsAppCloudTemplateParameter, type IWhatsAppCloudTemplateResponse, type IWhatsAppCloudWebhookPayload, type IWhatsAppData, type IWhatsAppMessageListener, type IWhatsAppProxyListenMessageEventData, type IWhatsAppProxyListenMessageEventReq, type IWhatsAppProxyMessage, type IWhatsAppProxyMessageContent, type IWhatsAppProxyMessageEventReq, type IWhatsAppProxySendMessageEventReq, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtConnectionGuardMiddleware, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenaiChatAdapter, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RemoteApiKeyRepository, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketControllerMetadataStore, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT, WabotChatAdapter, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByCloudApi, WhatsAppReceiverByWabotProxy, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByWabotProxy, WhatsAppWabotProxyConnection, WhatsappChannelConfig, apiKeyConnectionGuard, apiKeyGuard, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, connectionMiddleware, container, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtConnectionGuard, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, param, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, runSocketControllers, scoped, singleton, socket, socketConnection, socketController, socketEvent, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsApp };