@wabot-dev/framework 0.0.3 → 0.0.5

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 (94) hide show
  1. package/dist/src/channels/cmd/@cmd.js +0 -0
  2. package/dist/src/index.d.ts +445 -10
  3. package/dist/src/mindset/metadata/mindsets/@mindset.js +1 -1
  4. package/dist/src/server/runChannel.js +1 -1
  5. package/dist/src/server/runServer.js +1 -1
  6. package/package.json +5 -4
  7. package/dist/src/_virtual/_commonjsHelpers.js +0 -5
  8. package/dist/src/_virtual/main.js +0 -7
  9. package/dist/src/_virtual/main2.js +0 -3
  10. package/dist/src/ai/index.d.ts +0 -1
  11. package/dist/src/ai/openia/OpenaiChatBotAdapter.d.ts +0 -9
  12. package/dist/src/ai/openia/index.d.ts +0 -1
  13. package/dist/src/channels/cmd/CmdChannel.d.ts +0 -9
  14. package/dist/src/channels/cmd/index.d.ts +0 -1
  15. package/dist/src/channels/index.d.ts +0 -2
  16. package/dist/src/channels/telegram/@telegram.d.ts +0 -2
  17. package/dist/src/channels/telegram/TelegramChannel.d.ts +0 -12
  18. package/dist/src/channels/telegram/TelegramChannelConfig.d.ts +0 -7
  19. package/dist/src/channels/telegram/index.d.ts +0 -3
  20. package/dist/src/chatbot/ChatBot.d.ts +0 -11
  21. package/dist/src/chatbot/ChatBotAdapter.d.ts +0 -26
  22. package/dist/src/chatbot/IChatBot.d.ts +0 -4
  23. package/dist/src/chatbot/chat/Chat.d.ts +0 -23
  24. package/dist/src/chatbot/chat/IChatFunctionCall.d.ts +0 -6
  25. package/dist/src/chatbot/chat/IChatItem.d.ts +0 -19
  26. package/dist/src/chatbot/chat/index.d.ts +0 -4
  27. package/dist/src/chatbot/chat/repository/IChatMemory.d.ts +0 -9
  28. package/dist/src/chatbot/chat/repository/IChatRepository.d.ts +0 -12
  29. package/dist/src/chatbot/chat/repository/index.d.ts +0 -3
  30. package/dist/src/chatbot/chat/repository/ram/RamChatMemory.d.ts +0 -8
  31. package/dist/src/chatbot/chat/repository/ram/RamChatRepository.d.ts +0 -11
  32. package/dist/src/chatbot/chat/repository/ram/index.d.ts +0 -2
  33. package/dist/src/chatbot/index.d.ts +0 -5
  34. package/dist/src/chatbot/metadata/@chatBot.d.ts +0 -3
  35. package/dist/src/chatbot/metadata/ChatBotMetadataStore.d.ts +0 -6
  36. package/dist/src/chatbot/metadata/IChatBotMetadata.d.ts +0 -7
  37. package/dist/src/chatbot/metadata/index.d.ts +0 -3
  38. package/dist/src/context/IContext.d.ts +0 -18
  39. package/dist/src/context/index.d.ts +0 -1
  40. package/dist/src/controller/channel/ChatResolver.d.ts +0 -9
  41. package/dist/src/controller/channel/IChatChannel.d.ts +0 -5
  42. package/dist/src/controller/channel/IMessageContext.d.ts +0 -10
  43. package/dist/src/controller/channel/index.d.ts +0 -3
  44. package/dist/src/controller/index.d.ts +0 -2
  45. package/dist/src/controller/metadata/ControllerMetadataStore.d.ts +0 -12
  46. package/dist/src/controller/metadata/channel/IChannelMetadata.d.ts +0 -8
  47. package/dist/src/controller/metadata/channel/index.d.ts +0 -1
  48. package/dist/src/controller/metadata/controller/@chatController.d.ts +0 -3
  49. package/dist/src/controller/metadata/controller/IChatControllerConfig.d.ts +0 -2
  50. package/dist/src/controller/metadata/controller/IChatControllerMetadata.d.ts +0 -3
  51. package/dist/src/controller/metadata/controller/index.d.ts +0 -3
  52. package/dist/src/controller/metadata/index.d.ts +0 -3
  53. package/dist/src/injection/Container.d.ts +0 -18
  54. package/dist/src/injection/index.d.ts +0 -3
  55. package/dist/src/message/IChatDocument.d.ts +0 -2
  56. package/dist/src/message/IChatImage.d.ts +0 -2
  57. package/dist/src/message/IChatMessage.d.ts +0 -9
  58. package/dist/src/message/IChatSender.d.ts +0 -4
  59. package/dist/src/message/index.d.ts +0 -4
  60. package/dist/src/mindset/IMindset.d.ts +0 -17
  61. package/dist/src/mindset/MindsetOperator.d.ts +0 -25
  62. package/dist/src/mindset/index.d.ts +0 -3
  63. package/dist/src/mindset/metadata/IMindsetMetadata.d.ts +0 -28
  64. package/dist/src/mindset/metadata/MindsetMetadataStore.d.ts +0 -19
  65. package/dist/src/mindset/metadata/functions/@mindsetFunction.d.ts +0 -3
  66. package/dist/src/mindset/metadata/functions/IMindsetFunctionConfig.d.ts +0 -3
  67. package/dist/src/mindset/metadata/functions/IMindsetFunctionDecoration.d.ts +0 -7
  68. package/dist/src/mindset/metadata/functions/decoratorNames.d.ts +0 -1
  69. package/dist/src/mindset/metadata/functions/index.d.ts +0 -4
  70. package/dist/src/mindset/metadata/index.d.ts +0 -6
  71. package/dist/src/mindset/metadata/mindsets/@mindset.d.ts +0 -5
  72. package/dist/src/mindset/metadata/mindsets/IMindsetConfig.d.ts +0 -4
  73. package/dist/src/mindset/metadata/mindsets/IMindsetDecoration.d.ts +0 -6
  74. package/dist/src/mindset/metadata/mindsets/decoratorNames.d.ts +0 -1
  75. package/dist/src/mindset/metadata/mindsets/index.d.ts +0 -3
  76. package/dist/src/mindset/metadata/modules/@mindsetModule.d.ts +0 -4
  77. package/dist/src/mindset/metadata/modules/IMindsetModuleConfig.d.ts +0 -3
  78. package/dist/src/mindset/metadata/modules/IMindsetModuleDecoration.d.ts +0 -5
  79. package/dist/src/mindset/metadata/modules/decoratorNames.d.ts +0 -1
  80. package/dist/src/mindset/metadata/modules/index.d.ts +0 -4
  81. package/dist/src/mindset/metadata/params/@isOptional.d.ts +0 -2
  82. package/dist/src/mindset/metadata/params/@param.d.ts +0 -3
  83. package/dist/src/mindset/metadata/params/IParamConfig.d.ts +0 -4
  84. package/dist/src/mindset/metadata/params/IParamDecoration.d.ts +0 -7
  85. package/dist/src/mindset/metadata/params/decoratorNames.d.ts +0 -2
  86. package/dist/src/mindset/metadata/params/index.d.ts +0 -3
  87. package/dist/src/node_modules/dotenv/lib/main.js +0 -376
  88. package/dist/src/node_modules/dotenv/package.json.js +0 -5
  89. package/dist/src/server/index.d.ts +0 -3
  90. package/dist/src/server/prepareChatContainer.d.ts +0 -5
  91. package/dist/src/server/runChannel.d.ts +0 -12
  92. package/dist/src/server/runServer.d.ts +0 -8
  93. package/dist/src/shared/IConstructor.d.ts +0 -1
  94. package/dist/src/shared/index.d.ts +0 -1
@@ -1,376 +0,0 @@
1
- import { __module as main } from '../../../_virtual/main2.js';
2
- import require$$0 from 'fs';
3
- import require$$1 from 'path';
4
- import require$$2 from 'os';
5
- import require$$3 from 'crypto';
6
- import require$$4 from '../package.json.js';
7
-
8
- var hasRequiredMain;
9
-
10
- function requireMain () {
11
- if (hasRequiredMain) return main.exports;
12
- hasRequiredMain = 1;
13
- const fs = require$$0;
14
- const path = require$$1;
15
- const os = require$$2;
16
- const crypto = require$$3;
17
- const packageJson = require$$4;
18
-
19
- const version = packageJson.version;
20
-
21
- const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
22
-
23
- // Parse src into an Object
24
- function parse (src) {
25
- const obj = {};
26
-
27
- // Convert buffer to string
28
- let lines = src.toString();
29
-
30
- // Convert line breaks to same format
31
- lines = lines.replace(/\r\n?/mg, '\n');
32
-
33
- let match;
34
- while ((match = LINE.exec(lines)) != null) {
35
- const key = match[1];
36
-
37
- // Default undefined or null to empty string
38
- let value = (match[2] || '');
39
-
40
- // Remove whitespace
41
- value = value.trim();
42
-
43
- // Check if double quoted
44
- const maybeQuote = value[0];
45
-
46
- // Remove surrounding quotes
47
- value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2');
48
-
49
- // Expand newlines if double quoted
50
- if (maybeQuote === '"') {
51
- value = value.replace(/\\n/g, '\n');
52
- value = value.replace(/\\r/g, '\r');
53
- }
54
-
55
- // Add to object
56
- obj[key] = value;
57
- }
58
-
59
- return obj
60
- }
61
-
62
- function _parseVault (options) {
63
- const vaultPath = _vaultPath(options);
64
-
65
- // Parse .env.vault
66
- const result = DotenvModule.configDotenv({ path: vaultPath });
67
- if (!result.parsed) {
68
- const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
69
- err.code = 'MISSING_DATA';
70
- throw err
71
- }
72
-
73
- // handle scenario for comma separated keys - for use with key rotation
74
- // example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
75
- const keys = _dotenvKey(options).split(',');
76
- const length = keys.length;
77
-
78
- let decrypted;
79
- for (let i = 0; i < length; i++) {
80
- try {
81
- // Get full key
82
- const key = keys[i].trim();
83
-
84
- // Get instructions for decrypt
85
- const attrs = _instructions(result, key);
86
-
87
- // Decrypt
88
- decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
89
-
90
- break
91
- } catch (error) {
92
- // last key
93
- if (i + 1 >= length) {
94
- throw error
95
- }
96
- // try next key
97
- }
98
- }
99
-
100
- // Parse decrypted .env string
101
- return DotenvModule.parse(decrypted)
102
- }
103
-
104
- function _warn (message) {
105
- console.log(`[dotenv@${version}][WARN] ${message}`);
106
- }
107
-
108
- function _debug (message) {
109
- console.log(`[dotenv@${version}][DEBUG] ${message}`);
110
- }
111
-
112
- function _dotenvKey (options) {
113
- // prioritize developer directly setting options.DOTENV_KEY
114
- if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
115
- return options.DOTENV_KEY
116
- }
117
-
118
- // secondary infra already contains a DOTENV_KEY environment variable
119
- if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
120
- return process.env.DOTENV_KEY
121
- }
122
-
123
- // fallback to empty string
124
- return ''
125
- }
126
-
127
- function _instructions (result, dotenvKey) {
128
- // Parse DOTENV_KEY. Format is a URI
129
- let uri;
130
- try {
131
- uri = new URL(dotenvKey);
132
- } catch (error) {
133
- if (error.code === 'ERR_INVALID_URL') {
134
- const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development');
135
- err.code = 'INVALID_DOTENV_KEY';
136
- throw err
137
- }
138
-
139
- throw error
140
- }
141
-
142
- // Get decrypt key
143
- const key = uri.password;
144
- if (!key) {
145
- const err = new Error('INVALID_DOTENV_KEY: Missing key part');
146
- err.code = 'INVALID_DOTENV_KEY';
147
- throw err
148
- }
149
-
150
- // Get environment
151
- const environment = uri.searchParams.get('environment');
152
- if (!environment) {
153
- const err = new Error('INVALID_DOTENV_KEY: Missing environment part');
154
- err.code = 'INVALID_DOTENV_KEY';
155
- throw err
156
- }
157
-
158
- // Get ciphertext payload
159
- const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
160
- const ciphertext = result.parsed[environmentKey]; // DOTENV_VAULT_PRODUCTION
161
- if (!ciphertext) {
162
- const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
163
- err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT';
164
- throw err
165
- }
166
-
167
- return { ciphertext, key }
168
- }
169
-
170
- function _vaultPath (options) {
171
- let possibleVaultPath = null;
172
-
173
- if (options && options.path && options.path.length > 0) {
174
- if (Array.isArray(options.path)) {
175
- for (const filepath of options.path) {
176
- if (fs.existsSync(filepath)) {
177
- possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`;
178
- }
179
- }
180
- } else {
181
- possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`;
182
- }
183
- } else {
184
- possibleVaultPath = path.resolve(process.cwd(), '.env.vault');
185
- }
186
-
187
- if (fs.existsSync(possibleVaultPath)) {
188
- return possibleVaultPath
189
- }
190
-
191
- return null
192
- }
193
-
194
- function _resolveHome (envPath) {
195
- return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
196
- }
197
-
198
- function _configVault (options) {
199
- const debug = Boolean(options && options.debug);
200
- if (debug) {
201
- _debug('Loading env from encrypted .env.vault');
202
- }
203
-
204
- const parsed = DotenvModule._parseVault(options);
205
-
206
- let processEnv = process.env;
207
- if (options && options.processEnv != null) {
208
- processEnv = options.processEnv;
209
- }
210
-
211
- DotenvModule.populate(processEnv, parsed, options);
212
-
213
- return { parsed }
214
- }
215
-
216
- function configDotenv (options) {
217
- const dotenvPath = path.resolve(process.cwd(), '.env');
218
- let encoding = 'utf8';
219
- const debug = Boolean(options && options.debug);
220
-
221
- if (options && options.encoding) {
222
- encoding = options.encoding;
223
- } else {
224
- if (debug) {
225
- _debug('No encoding is specified. UTF-8 is used by default');
226
- }
227
- }
228
-
229
- let optionPaths = [dotenvPath]; // default, look for .env
230
- if (options && options.path) {
231
- if (!Array.isArray(options.path)) {
232
- optionPaths = [_resolveHome(options.path)];
233
- } else {
234
- optionPaths = []; // reset default
235
- for (const filepath of options.path) {
236
- optionPaths.push(_resolveHome(filepath));
237
- }
238
- }
239
- }
240
-
241
- // Build the parsed data in a temporary object (because we need to return it). Once we have the final
242
- // parsed data, we will combine it with process.env (or options.processEnv if provided).
243
- let lastError;
244
- const parsedAll = {};
245
- for (const path of optionPaths) {
246
- try {
247
- // Specifying an encoding returns a string instead of a buffer
248
- const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }));
249
-
250
- DotenvModule.populate(parsedAll, parsed, options);
251
- } catch (e) {
252
- if (debug) {
253
- _debug(`Failed to load ${path} ${e.message}`);
254
- }
255
- lastError = e;
256
- }
257
- }
258
-
259
- let processEnv = process.env;
260
- if (options && options.processEnv != null) {
261
- processEnv = options.processEnv;
262
- }
263
-
264
- DotenvModule.populate(processEnv, parsedAll, options);
265
-
266
- if (lastError) {
267
- return { parsed: parsedAll, error: lastError }
268
- } else {
269
- return { parsed: parsedAll }
270
- }
271
- }
272
-
273
- // Populates process.env from .env file
274
- function config (options) {
275
- // fallback to original dotenv if DOTENV_KEY is not set
276
- if (_dotenvKey(options).length === 0) {
277
- return DotenvModule.configDotenv(options)
278
- }
279
-
280
- const vaultPath = _vaultPath(options);
281
-
282
- // dotenvKey exists but .env.vault file does not exist
283
- if (!vaultPath) {
284
- _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
285
-
286
- return DotenvModule.configDotenv(options)
287
- }
288
-
289
- return DotenvModule._configVault(options)
290
- }
291
-
292
- function decrypt (encrypted, keyStr) {
293
- const key = Buffer.from(keyStr.slice(-64), 'hex');
294
- let ciphertext = Buffer.from(encrypted, 'base64');
295
-
296
- const nonce = ciphertext.subarray(0, 12);
297
- const authTag = ciphertext.subarray(-16);
298
- ciphertext = ciphertext.subarray(12, -16);
299
-
300
- try {
301
- const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce);
302
- aesgcm.setAuthTag(authTag);
303
- return `${aesgcm.update(ciphertext)}${aesgcm.final()}`
304
- } catch (error) {
305
- const isRange = error instanceof RangeError;
306
- const invalidKeyLength = error.message === 'Invalid key length';
307
- const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data';
308
-
309
- if (isRange || invalidKeyLength) {
310
- const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)');
311
- err.code = 'INVALID_DOTENV_KEY';
312
- throw err
313
- } else if (decryptionFailed) {
314
- const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY');
315
- err.code = 'DECRYPTION_FAILED';
316
- throw err
317
- } else {
318
- throw error
319
- }
320
- }
321
- }
322
-
323
- // Populate process.env with parsed values
324
- function populate (processEnv, parsed, options = {}) {
325
- const debug = Boolean(options && options.debug);
326
- const override = Boolean(options && options.override);
327
-
328
- if (typeof parsed !== 'object') {
329
- const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate');
330
- err.code = 'OBJECT_REQUIRED';
331
- throw err
332
- }
333
-
334
- // Set process.env
335
- for (const key of Object.keys(parsed)) {
336
- if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
337
- if (override === true) {
338
- processEnv[key] = parsed[key];
339
- }
340
-
341
- if (debug) {
342
- if (override === true) {
343
- _debug(`"${key}" is already defined and WAS overwritten`);
344
- } else {
345
- _debug(`"${key}" is already defined and was NOT overwritten`);
346
- }
347
- }
348
- } else {
349
- processEnv[key] = parsed[key];
350
- }
351
- }
352
- }
353
-
354
- const DotenvModule = {
355
- configDotenv,
356
- _configVault,
357
- _parseVault,
358
- config,
359
- decrypt,
360
- parse,
361
- populate
362
- };
363
-
364
- main.exports.configDotenv = DotenvModule.configDotenv;
365
- main.exports._configVault = DotenvModule._configVault;
366
- main.exports._parseVault = DotenvModule._parseVault;
367
- main.exports.config = DotenvModule.config;
368
- main.exports.decrypt = DotenvModule.decrypt;
369
- main.exports.parse = DotenvModule.parse;
370
- main.exports.populate = DotenvModule.populate;
371
-
372
- main.exports = DotenvModule;
373
- return main.exports;
374
- }
375
-
376
- export { requireMain as __require };
@@ -1,5 +0,0 @@
1
- var version = "16.5.0";
2
- var require$$4 = {
3
- version: version};
4
-
5
- export { require$$4 as default, version };
@@ -1,3 +0,0 @@
1
- export * from './prepareChatContainer';
2
- export * from './runChannel';
3
- export * from './runServer';
@@ -1,5 +0,0 @@
1
- import { IContext } from '@/context';
2
- import { IConstructor } from '@/shared';
3
- import { DependencyContainer } from '@/injection';
4
- import { IMindset } from '@/mindset';
5
- export declare function prepareChatContainer(container: DependencyContainer, context: IContext, mindsetCtor?: IConstructor<IMindset>): Promise<DependencyContainer>;
@@ -1,12 +0,0 @@
1
- import { IChatBotAdapter, IChatRepository } from '@/chatbot';
2
- import { IChatChannel } from '@/controller';
3
- import { IMindset } from '@/mindset';
4
- import { IConstructor } from '@/shared';
5
- export interface IrunChannelProps {
6
- channel: IConstructor<IChatChannel>;
7
- channelConfig?: object;
8
- mindset: IConstructor<IMindset>;
9
- chatRepository: IConstructor<IChatRepository>;
10
- chatBotAdapter: IConstructor<IChatBotAdapter>;
11
- }
12
- export declare function runChannel(props: IrunChannelProps): void;
@@ -1,8 +0,0 @@
1
- import { IChatBotAdapter, IChatRepository } from '@/chatbot';
2
- import { IConstructor } from '@/shared';
3
- export interface IServerConfig {
4
- controllers: IConstructor<any>[];
5
- chatRepository?: IConstructor<IChatRepository>;
6
- chatBotAdapter?: IConstructor<IChatBotAdapter>;
7
- }
8
- export declare function runServer(config: IServerConfig): void;
@@ -1 +0,0 @@
1
- export type IConstructor<T> = new (...args: any[]) => T;
@@ -1 +0,0 @@
1
- export * from './IConstructor';