@wabot-dev/framework 0.0.10 → 0.0.12
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.
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +2 -4
- package/dist/src/channels/cmd/@cmd.js +2 -0
- package/dist/src/channels/cmd/CmdChannel.js +2 -5
- package/dist/src/channels/telegram/@telegram.js +2 -0
- package/dist/src/channels/telegram/TelegramChannel.js +2 -4
- package/dist/src/chatbot/ChatBot.js +2 -4
- package/dist/src/chatbot/ChatBotAdapter.js +1 -3
- package/dist/src/chatbot/metadata/@chatBot.js +2 -0
- package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +2 -0
- package/dist/src/controller/channel/ChatResolver.js +1 -3
- package/dist/src/controller/channel/UserResolver.js +1 -3
- package/dist/src/controller/metadata/ControllerMetadataStore.js +2 -0
- package/dist/src/controller/metadata/controller/@chatController.js +2 -0
- package/dist/src/core/IMessageContext.js +1 -2
- package/dist/src/{shared → core}/Persistent.js +2 -4
- package/dist/src/core/chat/Chat.js +1 -1
- package/dist/src/core/chat/ChatItem.js +1 -1
- package/dist/src/core/user/{repository/IUserRepository.js → IUserRepository.js} +1 -1
- package/dist/src/core/user/User.js +1 -1
- package/dist/src/index.d.ts +235 -174
- package/dist/src/index.js +17 -15
- package/dist/src/mindset/MindsetOperator.js +2 -0
- package/dist/src/mindset/metadata/MindsetMetadataStore.js +2 -0
- package/dist/src/mindset/metadata/mindsets/@mindset.js +2 -0
- package/dist/src/mindset/metadata/modules/@mindsetModule.js +2 -0
- package/dist/src/pre-made/module/authentication/AuthenticationModule.js +1 -3
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +2 -0
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +2 -0
- package/dist/src/pre-made/module/register-user/RegisterUserModule.js +1 -3
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +2 -0
- package/dist/src/pre-made/repository/chat/pg/PgChatMemory.js +43 -0
- package/dist/src/pre-made/repository/chat/pg/PgChatRepository.js +42 -0
- package/dist/src/{core/chat/repository → pre-made/repository/chat}/ram/RamChatRepository.js +1 -2
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatMemory.js +23 -0
- package/dist/src/pre-made/repository/{sqlite/chat → chat/sqlite}/SqliteChatRepository.js +6 -16
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +38 -0
- package/dist/src/{core/user/repository → pre-made/repository/user}/ram/RamUserRepository.js +1 -2
- package/dist/src/pre-made/repository/user/sqlite/SqliteUserRepository.js +23 -0
- package/dist/src/repository/pg/PgCrudRepository.js +63 -0
- package/dist/src/repository/pg/PgRepositoryBase.js +89 -0
- package/dist/src/{pre-made/repository → repository}/sqlite/SqliteCrudRepository.js +1 -1
- package/dist/src/repository/sqlite/SqlitePersistentMapper.js +17 -0
- package/dist/src/server/prepareChatContainer.js +4 -6
- package/dist/src/server/runChannel.js +2 -4
- package/dist/src/server/runServer.js +2 -4
- package/package.json +4 -1
- package/dist/src/pre-made/repository/sqlite/chat/SqliteChatMemory.js +0 -35
- package/dist/src/pre-made/repository/sqlite/user/SqliteUserRepository.js +0 -33
- /package/dist/src/{core/chat/repository → pre-made/repository/chat}/ram/RamChatMemory.js +0 -0
package/dist/src/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import InterceptionOptions from 'tsyringe/dist/typings/types/interceptor-options
|
|
|
4
4
|
import * as tsyringe from 'tsyringe';
|
|
5
5
|
import { DependencyContainer as DependencyContainer$1 } from 'tsyringe';
|
|
6
6
|
export { DependencyContainer } from 'tsyringe';
|
|
7
|
+
import { Pool } from 'pg';
|
|
7
8
|
import { Database } from 'sqlite';
|
|
8
9
|
import sqlite3 from 'sqlite3';
|
|
9
10
|
|
|
@@ -23,21 +24,13 @@ interface IMindsetFunctionDecoration {
|
|
|
23
24
|
decorationConfig: any;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
type IConstructor<T> = new (...args: any[]) => T;
|
|
27
|
-
|
|
28
|
-
interface IReversibleMapper<T1, T2> {
|
|
29
|
-
map(input: T1): T2;
|
|
30
|
-
rev(input: T2): T1;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
27
|
interface IPersistent {
|
|
34
28
|
id?: string;
|
|
35
|
-
createdAt?:
|
|
36
|
-
discardedAt?:
|
|
29
|
+
createdAt?: number | null;
|
|
30
|
+
discardedAt?: number | null;
|
|
37
31
|
}
|
|
38
|
-
declare class Persistent<D extends IPersistent> {
|
|
32
|
+
declare class Persistent<D extends IPersistent = IPersistent> {
|
|
39
33
|
protected data: D;
|
|
40
|
-
private originalData;
|
|
41
34
|
constructor(data: D);
|
|
42
35
|
getId(): string;
|
|
43
36
|
getCreatedAt(): Date;
|
|
@@ -47,6 +40,143 @@ declare class Persistent<D extends IPersistent> {
|
|
|
47
40
|
discard(): void;
|
|
48
41
|
}
|
|
49
42
|
|
|
43
|
+
type IChatType = 'PRIVATE' | 'GROUP';
|
|
44
|
+
interface IChatConnection {
|
|
45
|
+
chatType: IChatType;
|
|
46
|
+
channelName: string;
|
|
47
|
+
id: string;
|
|
48
|
+
}
|
|
49
|
+
interface IChatData extends IPersistent {
|
|
50
|
+
type: IChatType;
|
|
51
|
+
connections: IChatConnection[];
|
|
52
|
+
}
|
|
53
|
+
declare class Chat extends Persistent<IChatData> {
|
|
54
|
+
constructor(data: IChatData);
|
|
55
|
+
isPrivate(): boolean;
|
|
56
|
+
isGroup(): boolean;
|
|
57
|
+
hasConnection(connection: IChatConnection): boolean;
|
|
58
|
+
private validatePrivateChat;
|
|
59
|
+
private validateGroupChat;
|
|
60
|
+
validate(): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface IChatDocument {
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface IChatImage {
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface IUserConnection {
|
|
70
|
+
channelName: string;
|
|
71
|
+
id: string;
|
|
72
|
+
}
|
|
73
|
+
interface IUserData extends IPersistent {
|
|
74
|
+
shortName: string;
|
|
75
|
+
connections: IUserConnection[];
|
|
76
|
+
keyValueData: {
|
|
77
|
+
[key: string]: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
declare class User extends Persistent<IUserData> {
|
|
81
|
+
constructor(data: IUserData);
|
|
82
|
+
hasConnection(connection: IUserConnection): boolean;
|
|
83
|
+
getValue(key: string): string;
|
|
84
|
+
setValue(key: string, value: string): void;
|
|
85
|
+
addConnection(connection: IUserConnection): void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface IChatMessage {
|
|
89
|
+
text?: string;
|
|
90
|
+
documents?: IChatDocument[];
|
|
91
|
+
images?: IChatImage[];
|
|
92
|
+
senderName: string;
|
|
93
|
+
}
|
|
94
|
+
interface IConnectionChatMessage extends IChatMessage {
|
|
95
|
+
chatConnection: IChatConnection;
|
|
96
|
+
userConnection: IUserConnection;
|
|
97
|
+
userId?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface IChatFunctionCall {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
arguments?: string;
|
|
104
|
+
result: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type ISystemMessageItem = {
|
|
108
|
+
type: 'BOT_MESSAGE';
|
|
109
|
+
content: IChatMessage;
|
|
110
|
+
};
|
|
111
|
+
type IReceivedMessageItem = {
|
|
112
|
+
type: 'CONNECTION_MESSAGE';
|
|
113
|
+
content: IConnectionChatMessage;
|
|
114
|
+
};
|
|
115
|
+
type ISystemFunctionCallItem = {
|
|
116
|
+
type: 'FUNCTION_CALL';
|
|
117
|
+
content: IChatFunctionCall;
|
|
118
|
+
};
|
|
119
|
+
type IChatItemData = {
|
|
120
|
+
id?: string;
|
|
121
|
+
createdAt?: number;
|
|
122
|
+
} & (ISystemMessageItem | IReceivedMessageItem | ISystemFunctionCallItem);
|
|
123
|
+
type IChatItemType = IChatItemData['type'];
|
|
124
|
+
declare class ChatItem extends Persistent<IChatItemData> {
|
|
125
|
+
getType(): "BOT_MESSAGE" | "CONNECTION_MESSAGE" | "FUNCTION_CALL";
|
|
126
|
+
getContent(): IChatMessage | IConnectionChatMessage | IChatFunctionCall;
|
|
127
|
+
getData(): IChatItemData;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
interface IChatMemory {
|
|
131
|
+
findLastItems(count: number): Promise<ChatItem[]>;
|
|
132
|
+
create(item: ChatItem): Promise<void>;
|
|
133
|
+
}
|
|
134
|
+
declare class ChatMemory implements IChatMemory {
|
|
135
|
+
findLastItems(count: number): Promise<ChatItem[]>;
|
|
136
|
+
create(item: ChatItem): Promise<void>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface IChatRepository {
|
|
140
|
+
create(chat: Chat): Promise<void>;
|
|
141
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
142
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
143
|
+
}
|
|
144
|
+
declare class ChatRepository implements IChatRepository {
|
|
145
|
+
create(chat: Chat): Promise<void>;
|
|
146
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
147
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface IUserRepository {
|
|
151
|
+
create(chat: User): Promise<void>;
|
|
152
|
+
update(chat: User): Promise<void>;
|
|
153
|
+
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
154
|
+
}
|
|
155
|
+
declare class UserRepository implements IUserRepository {
|
|
156
|
+
create(chat: User): Promise<void>;
|
|
157
|
+
update(chat: User): Promise<void>;
|
|
158
|
+
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface IMessageContext {
|
|
162
|
+
message: IConnectionChatMessage;
|
|
163
|
+
chat: Chat;
|
|
164
|
+
user: User | null;
|
|
165
|
+
}
|
|
166
|
+
declare class MessageContext implements IMessageContext {
|
|
167
|
+
message: IConnectionChatMessage;
|
|
168
|
+
chat: Chat;
|
|
169
|
+
user: User | null;
|
|
170
|
+
constructor(message: IConnectionChatMessage, chat: Chat, user: User | null);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface IReversibleMapper<T1, T2> {
|
|
174
|
+
map(input: T1): T2;
|
|
175
|
+
rev(input: T2): T1;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
type IConstructor<T> = new (...args: any[]) => T;
|
|
179
|
+
|
|
50
180
|
interface IMindsetIdentity {
|
|
51
181
|
name: string;
|
|
52
182
|
language: string;
|
|
@@ -210,159 +340,6 @@ declare class ChatBotMetadataStore {
|
|
|
210
340
|
getChatBotsMetadata(): IChatBotMetadata[];
|
|
211
341
|
}
|
|
212
342
|
|
|
213
|
-
type IChatType = 'PRIVATE' | 'GROUP';
|
|
214
|
-
interface IChatConnection {
|
|
215
|
-
chatType: IChatType;
|
|
216
|
-
channelName: string;
|
|
217
|
-
id: string;
|
|
218
|
-
}
|
|
219
|
-
interface IChatData extends IPersistent {
|
|
220
|
-
type: IChatType;
|
|
221
|
-
connections: IChatConnection[];
|
|
222
|
-
}
|
|
223
|
-
declare class Chat extends Persistent<IChatData> {
|
|
224
|
-
constructor(data: IChatData);
|
|
225
|
-
isPrivate(): boolean;
|
|
226
|
-
isGroup(): boolean;
|
|
227
|
-
hasConnection(connection: IChatConnection): boolean;
|
|
228
|
-
private validatePrivateChat;
|
|
229
|
-
private validateGroupChat;
|
|
230
|
-
validate(): void;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
interface IChatDocument {
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
interface IChatImage {
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
interface IUserConnection {
|
|
240
|
-
channelName: string;
|
|
241
|
-
id: string;
|
|
242
|
-
}
|
|
243
|
-
interface IUserData extends IPersistent {
|
|
244
|
-
shortName: string;
|
|
245
|
-
connections: IUserConnection[];
|
|
246
|
-
keyValueData: {
|
|
247
|
-
[key: string]: string;
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
declare class User extends Persistent<IUserData> {
|
|
251
|
-
constructor(data: IUserData);
|
|
252
|
-
hasConnection(connection: IUserConnection): boolean;
|
|
253
|
-
getValue(key: string): string;
|
|
254
|
-
setValue(key: string, value: string): void;
|
|
255
|
-
addConnection(connection: IUserConnection): void;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
interface IChatMessage {
|
|
259
|
-
text?: string;
|
|
260
|
-
documents?: IChatDocument[];
|
|
261
|
-
images?: IChatImage[];
|
|
262
|
-
senderName: string;
|
|
263
|
-
}
|
|
264
|
-
interface IConnectionChatMessage extends IChatMessage {
|
|
265
|
-
chatConnection: IChatConnection;
|
|
266
|
-
userConnection: IUserConnection;
|
|
267
|
-
userId?: string;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
interface IChatFunctionCall {
|
|
271
|
-
id: string;
|
|
272
|
-
name: string;
|
|
273
|
-
arguments?: string;
|
|
274
|
-
result: string;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
type ISystemMessageItem = {
|
|
278
|
-
type: 'BOT_MESSAGE';
|
|
279
|
-
content: IChatMessage;
|
|
280
|
-
};
|
|
281
|
-
type IReceivedMessageItem = {
|
|
282
|
-
type: 'CONNECTION_MESSAGE';
|
|
283
|
-
content: IConnectionChatMessage;
|
|
284
|
-
};
|
|
285
|
-
type ISystemFunctionCallItem = {
|
|
286
|
-
type: 'FUNCTION_CALL';
|
|
287
|
-
content: IChatFunctionCall;
|
|
288
|
-
};
|
|
289
|
-
type IChatItemData = {
|
|
290
|
-
id?: string;
|
|
291
|
-
createdAt?: Date;
|
|
292
|
-
} & (ISystemMessageItem | IReceivedMessageItem | ISystemFunctionCallItem);
|
|
293
|
-
type IChatItemType = IChatItemData['type'];
|
|
294
|
-
declare class ChatItem extends Persistent<IChatItemData> {
|
|
295
|
-
getType(): "BOT_MESSAGE" | "CONNECTION_MESSAGE" | "FUNCTION_CALL";
|
|
296
|
-
getContent(): IChatMessage | IConnectionChatMessage | IChatFunctionCall;
|
|
297
|
-
getData(): IChatItemData;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
interface IChatMemory {
|
|
301
|
-
findLastItems(count: number): Promise<ChatItem[]>;
|
|
302
|
-
create(item: ChatItem): Promise<void>;
|
|
303
|
-
}
|
|
304
|
-
declare class ChatMemory implements IChatMemory {
|
|
305
|
-
findLastItems(count: number): Promise<ChatItem[]>;
|
|
306
|
-
create(item: ChatItem): Promise<void>;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
declare class RamChatMemory implements IChatMemory {
|
|
310
|
-
private memory;
|
|
311
|
-
findLastItems(count: number): Promise<ChatItem[]>;
|
|
312
|
-
create(item: ChatItem): Promise<void>;
|
|
313
|
-
clearMemory(): Promise<void>;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
interface IChatRepository {
|
|
317
|
-
create(chat: Chat): Promise<void>;
|
|
318
|
-
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
319
|
-
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
320
|
-
}
|
|
321
|
-
declare class ChatRepository implements IChatRepository {
|
|
322
|
-
create(chat: Chat): Promise<void>;
|
|
323
|
-
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
324
|
-
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
declare class RamChatRepository implements IChatRepository {
|
|
328
|
-
private items;
|
|
329
|
-
private memories;
|
|
330
|
-
create(chat: Chat): Promise<void>;
|
|
331
|
-
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
332
|
-
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
333
|
-
private getMemory;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
interface IUserRepository {
|
|
337
|
-
create(chat: User): Promise<void>;
|
|
338
|
-
update(chat: User): Promise<void>;
|
|
339
|
-
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
340
|
-
}
|
|
341
|
-
declare class UserRepository implements IUserRepository {
|
|
342
|
-
create(chat: User): Promise<void>;
|
|
343
|
-
update(chat: User): Promise<void>;
|
|
344
|
-
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
declare class RamUserRepository implements IUserRepository {
|
|
348
|
-
private items;
|
|
349
|
-
create(chat: User): Promise<void>;
|
|
350
|
-
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
351
|
-
update(chat: User): Promise<void>;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
interface IMessageContext {
|
|
355
|
-
message: IConnectionChatMessage;
|
|
356
|
-
chat: Chat;
|
|
357
|
-
user: User | null;
|
|
358
|
-
}
|
|
359
|
-
declare class MessageContext implements IMessageContext {
|
|
360
|
-
message: IConnectionChatMessage;
|
|
361
|
-
chat: Chat;
|
|
362
|
-
user: User | null;
|
|
363
|
-
constructor(message: IConnectionChatMessage, chat: Chat, user: User | null);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
343
|
interface IChatBotAdapter {
|
|
367
344
|
generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem>;
|
|
368
345
|
}
|
|
@@ -560,7 +537,57 @@ interface ICrudRepository<T> {
|
|
|
560
537
|
discard(item: T): Promise<void>;
|
|
561
538
|
}
|
|
562
539
|
|
|
563
|
-
|
|
540
|
+
type IPgRepositoryConfig<P extends Persistent> = {
|
|
541
|
+
schema?: string;
|
|
542
|
+
table: string;
|
|
543
|
+
constructor: IConstructor<P>;
|
|
544
|
+
add?: {
|
|
545
|
+
columns: {
|
|
546
|
+
[column: string]: {
|
|
547
|
+
type: string;
|
|
548
|
+
value: (item: P) => boolean | number | string | null | Date;
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
declare class PgRepositoryBase<P extends Persistent> {
|
|
555
|
+
protected pool: Pool;
|
|
556
|
+
protected config: IPgRepositoryConfig<any>;
|
|
557
|
+
private tableIsCreated;
|
|
558
|
+
schema: string;
|
|
559
|
+
table: string;
|
|
560
|
+
columnsList: string[];
|
|
561
|
+
columnsAndTypes: string;
|
|
562
|
+
columns: string;
|
|
563
|
+
vars: string;
|
|
564
|
+
updates: string;
|
|
565
|
+
addColumns: {
|
|
566
|
+
[columns: string]: {
|
|
567
|
+
type: string;
|
|
568
|
+
value: (item: P) => number | boolean | string | null | Date;
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
constructor(pool: Pool, config: IPgRepositoryConfig<any>);
|
|
572
|
+
values(item: P): (string | number | boolean | Date | null)[];
|
|
573
|
+
protected exec(sql: string, values: any[]): Promise<void>;
|
|
574
|
+
protected query(sql: string, values: any[]): Promise<any[]>;
|
|
575
|
+
protected connect(): Promise<Pool>;
|
|
576
|
+
protected ensureTable(): Promise<void>;
|
|
577
|
+
protected ensureColumns(): Promise<void>;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
declare class PgCrudRepository<P extends Persistent> extends PgRepositoryBase<P> implements ICrudRepository<P> {
|
|
581
|
+
protected readonly config: IPgRepositoryConfig<P>;
|
|
582
|
+
constructor(pool: Pool, config: IPgRepositoryConfig<P>);
|
|
583
|
+
find(id: string): Promise<P | null>;
|
|
584
|
+
findAll(): Promise<P[]>;
|
|
585
|
+
create(item: P): Promise<void>;
|
|
586
|
+
update(item: P): Promise<void>;
|
|
587
|
+
discard(item: P): Promise<void>;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
declare class SqliteCrudRepository<P extends Persistent> implements ICrudRepository<P> {
|
|
564
591
|
private table;
|
|
565
592
|
private dbPath;
|
|
566
593
|
private mapper;
|
|
@@ -575,8 +602,37 @@ declare class SqliteCrudRepository<P extends Persistent<IPersistent>> implements
|
|
|
575
602
|
protected createTable(db: Database<sqlite3.Database, sqlite3.Statement>): Promise<void>;
|
|
576
603
|
}
|
|
577
604
|
|
|
578
|
-
declare class
|
|
605
|
+
declare class PgUserRepository extends PgCrudRepository<User> implements IUserRepository {
|
|
606
|
+
constructor(pool: Pool);
|
|
607
|
+
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
declare class RamUserRepository implements IUserRepository {
|
|
611
|
+
private items;
|
|
612
|
+
create(chat: User): Promise<void>;
|
|
613
|
+
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
614
|
+
update(chat: User): Promise<void>;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
declare class SqliteUserRepository extends SqliteCrudRepository<User> implements IUserRepository {
|
|
618
|
+
constructor();
|
|
619
|
+
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
620
|
+
static getDbPath(): string;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
declare class PgChatRepository extends PgCrudRepository<Chat> implements IChatRepository {
|
|
624
|
+
constructor(pool: Pool);
|
|
625
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
626
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
declare class PgChatMemory extends PgCrudRepository<ChatItem> implements IChatMemory {
|
|
579
630
|
private chatId;
|
|
631
|
+
constructor(pool: Pool, chatId: string);
|
|
632
|
+
findLastItems(count: number): Promise<ChatItem[]>;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
declare class SqliteChatMemory extends SqliteCrudRepository<ChatItem> implements IChatMemory {
|
|
580
636
|
constructor(chatId: string);
|
|
581
637
|
findLastItems(count: number): Promise<ChatItem[]>;
|
|
582
638
|
static getDbPath(chatId: string): string;
|
|
@@ -589,15 +645,20 @@ declare class SqliteChatRepository extends SqliteCrudRepository<Chat> implements
|
|
|
589
645
|
static getDbPath(): string;
|
|
590
646
|
}
|
|
591
647
|
|
|
592
|
-
declare class
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
648
|
+
declare class RamChatMemory implements IChatMemory {
|
|
649
|
+
private memory;
|
|
650
|
+
findLastItems(count: number): Promise<ChatItem[]>;
|
|
651
|
+
create(item: ChatItem): Promise<void>;
|
|
652
|
+
clearMemory(): Promise<void>;
|
|
596
653
|
}
|
|
597
654
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
655
|
+
declare class RamChatRepository implements IChatRepository {
|
|
656
|
+
private items;
|
|
657
|
+
private memories;
|
|
658
|
+
create(chat: Chat): Promise<void>;
|
|
659
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
660
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
661
|
+
private getMemory;
|
|
601
662
|
}
|
|
602
663
|
|
|
603
|
-
export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, EmailService, 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
|
|
664
|
+
export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, EmailService, 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 IEmailService, type IMessageContext, 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 IPersistent, type IReceivedMessage, type IReceivedMessageItem, type IReversibleMapper, type ISendEmailRequest, type IServerConfig, type IServerProvider, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IchatControllerConfig, type IrunChannelProps, 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, PgUserRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, SendOneTimePasswordRequest, SqliteChatMemory, SqliteChatRepository, SqliteUserRepository, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, chatBot, chatController, cmd, container, inject, injectable, isOptional, mindset, mindsetFunction, mindsetModule, param, prepareChatContainer, runChannel, runServer, singleton, telegram };
|
package/dist/src/index.js
CHANGED
|
@@ -10,7 +10,14 @@ export { mindsetFunction } from './mindset/metadata/functions/@mindsetFunction.j
|
|
|
10
10
|
export { MINDSET_FUNCTION_DECORATION_FUNCTION } from './mindset/metadata/functions/decoratorNames.js';
|
|
11
11
|
export { mindset } from './mindset/metadata/mindsets/@mindset.js';
|
|
12
12
|
export { MINDSET_DECORATION_MINDSET } from './mindset/metadata/mindsets/decoratorNames.js';
|
|
13
|
-
export {
|
|
13
|
+
export { ChatMemory } from './core/chat/repository/IChatMemory.js';
|
|
14
|
+
export { ChatRepository } from './core/chat/repository/IChatRepository.js';
|
|
15
|
+
export { Chat } from './core/chat/Chat.js';
|
|
16
|
+
export { ChatItem } from './core/chat/ChatItem.js';
|
|
17
|
+
export { User } from './core/user/User.js';
|
|
18
|
+
export { UserRepository } from './core/user/IUserRepository.js';
|
|
19
|
+
export { MessageContext } from './core/IMessageContext.js';
|
|
20
|
+
export { Persistent } from './core/Persistent.js';
|
|
14
21
|
export { mindsetModule } from './mindset/metadata/modules/@mindsetModule.js';
|
|
15
22
|
export { MINDSET_MODULE_DECORATION_MODULE } from './mindset/metadata/modules/decoratorNames.js';
|
|
16
23
|
export { isOptional } from './mindset/metadata/params/@isOptional.js';
|
|
@@ -21,16 +28,6 @@ export { MindsetMetadataStore } from './mindset/metadata/MindsetMetadataStore.js
|
|
|
21
28
|
export { MindsetOperator } from './mindset/MindsetOperator.js';
|
|
22
29
|
export { ChatBot } from './chatbot/ChatBot.js';
|
|
23
30
|
export { ChatBotAdapter } from './chatbot/ChatBotAdapter.js';
|
|
24
|
-
export { RamChatMemory } from './core/chat/repository/ram/RamChatMemory.js';
|
|
25
|
-
export { RamChatRepository } from './core/chat/repository/ram/RamChatRepository.js';
|
|
26
|
-
export { ChatMemory } from './core/chat/repository/IChatMemory.js';
|
|
27
|
-
export { ChatRepository } from './core/chat/repository/IChatRepository.js';
|
|
28
|
-
export { Chat } from './core/chat/Chat.js';
|
|
29
|
-
export { ChatItem } from './core/chat/ChatItem.js';
|
|
30
|
-
export { User } from './core/user/User.js';
|
|
31
|
-
export { RamUserRepository } from './core/user/repository/ram/RamUserRepository.js';
|
|
32
|
-
export { UserRepository } from './core/user/repository/IUserRepository.js';
|
|
33
|
-
export { MessageContext } from './core/IMessageContext.js';
|
|
34
31
|
export { ChatResolver } from './controller/channel/ChatResolver.js';
|
|
35
32
|
export { UserResolver } from './controller/channel/UserResolver.js';
|
|
36
33
|
export { chatController } from './controller/metadata/controller/@chatController.js';
|
|
@@ -46,8 +43,13 @@ export { RegisterUserWithEmailRequest } from './pre-made/module/register-user/re
|
|
|
46
43
|
export { RegisterUserModule } from './pre-made/module/register-user/RegisterUserModule.js';
|
|
47
44
|
export { EmailService } from './pre-made/service/EmailService.js';
|
|
48
45
|
export { OtpService } from './pre-made/service/OtpService.js';
|
|
49
|
-
export {
|
|
50
|
-
export {
|
|
51
|
-
export { SqliteUserRepository } from './pre-made/repository/sqlite/
|
|
52
|
-
export {
|
|
46
|
+
export { PgUserRepository } from './pre-made/repository/user/pg/PgUserRepository.js';
|
|
47
|
+
export { RamUserRepository } from './pre-made/repository/user/ram/RamUserRepository.js';
|
|
48
|
+
export { SqliteUserRepository } from './pre-made/repository/user/sqlite/SqliteUserRepository.js';
|
|
49
|
+
export { PgChatRepository } from './pre-made/repository/chat/pg/PgChatRepository.js';
|
|
50
|
+
export { PgChatMemory } from './pre-made/repository/chat/pg/PgChatMemory.js';
|
|
51
|
+
export { SqliteChatMemory } from './pre-made/repository/chat/sqlite/SqliteChatMemory.js';
|
|
52
|
+
export { SqliteChatRepository } from './pre-made/repository/chat/sqlite/SqliteChatRepository.js';
|
|
53
|
+
export { RamChatMemory } from './pre-made/repository/chat/ram/RamChatMemory.js';
|
|
54
|
+
export { RamChatRepository } from './pre-made/repository/chat/ram/RamChatRepository.js';
|
|
53
55
|
export { Container } from './injection/Container.js';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { injectable } from '../injection/index.js';
|
|
3
3
|
import { Mindset } from './IMindset.js';
|
|
4
|
+
import '../core/chat/repository/IChatRepository.js';
|
|
5
|
+
import '../core/user/IUserRepository.js';
|
|
4
6
|
import { MindsetMetadataStore } from './metadata/MindsetMetadataStore.js';
|
|
5
7
|
import { Container } from '../injection/Container.js';
|
|
6
8
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { singleton } from '../../injection/index.js';
|
|
3
|
+
import '../../core/chat/repository/IChatRepository.js';
|
|
4
|
+
import '../../core/user/IUserRepository.js';
|
|
3
5
|
import { MINDSET_FUNCTION_DECORATION_FUNCTION } from './functions/decoratorNames.js';
|
|
4
6
|
import { MINDSET_DECORATION_MINDSET } from './mindsets/decoratorNames.js';
|
|
5
7
|
import { MINDSET_MODULE_DECORATION_MODULE } from './modules/decoratorNames.js';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
+
import '../../../core/chat/repository/IChatRepository.js';
|
|
3
|
+
import '../../../core/user/IUserRepository.js';
|
|
2
4
|
import { container, injectable } from '../../../injection/index.js';
|
|
3
5
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
4
6
|
import { MINDSET_DECORATION_MINDSET } from './decoratorNames.js';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { container, injectable } from '../../../injection/index.js';
|
|
3
|
+
import '../../../core/chat/repository/IChatRepository.js';
|
|
4
|
+
import '../../../core/user/IUserRepository.js';
|
|
3
5
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
4
6
|
import { MINDSET_MODULE_DECORATION_MODULE } from './decoratorNames.js';
|
|
5
7
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import '../../../core/chat/repository/ram/RamChatRepository.js';
|
|
3
2
|
import '../../../core/chat/repository/IChatRepository.js';
|
|
4
|
-
import '../../../core/user/
|
|
5
|
-
import { UserRepository } from '../../../core/user/repository/IUserRepository.js';
|
|
3
|
+
import { UserRepository } from '../../../core/user/IUserRepository.js';
|
|
6
4
|
import { MessageContext } from '../../../core/IMessageContext.js';
|
|
7
5
|
import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
|
|
8
6
|
import 'reflect-metadata';
|
|
@@ -2,6 +2,8 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
+
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
+
import '../../../../core/user/IUserRepository.js';
|
|
5
7
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
6
8
|
import '../../../../mindset/MindsetOperator.js';
|
|
7
9
|
|
|
@@ -2,6 +2,8 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
+
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
+
import '../../../../core/user/IUserRepository.js';
|
|
5
7
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
6
8
|
import '../../../../mindset/MindsetOperator.js';
|
|
7
9
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import '../../../core/chat/repository/ram/RamChatRepository.js';
|
|
3
2
|
import '../../../core/chat/repository/IChatRepository.js';
|
|
4
3
|
import { User } from '../../../core/user/User.js';
|
|
5
|
-
import '../../../core/user/
|
|
6
|
-
import { UserRepository } from '../../../core/user/repository/IUserRepository.js';
|
|
4
|
+
import { UserRepository } from '../../../core/user/IUserRepository.js';
|
|
7
5
|
import { MessageContext } from '../../../core/IMessageContext.js';
|
|
8
6
|
import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
|
|
9
7
|
import 'reflect-metadata';
|
|
@@ -2,6 +2,8 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
+
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
+
import '../../../../core/user/IUserRepository.js';
|
|
5
7
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
6
8
|
import '../../../../mindset/MindsetOperator.js';
|
|
7
9
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ChatItem } from '../../../../core/chat/ChatItem.js';
|
|
2
|
+
import '../../../../core/chat/repository/IChatRepository.js';
|
|
3
|
+
import '../../../../core/user/IUserRepository.js';
|
|
4
|
+
import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
|
|
5
|
+
import 'fs';
|
|
6
|
+
import 'path';
|
|
7
|
+
import 'sqlite';
|
|
8
|
+
import 'sqlite3';
|
|
9
|
+
import 'uuid';
|
|
10
|
+
import 'pg';
|
|
11
|
+
|
|
12
|
+
class PgChatMemory extends PgCrudRepository {
|
|
13
|
+
chatId;
|
|
14
|
+
constructor(pool, chatId) {
|
|
15
|
+
super(pool, {
|
|
16
|
+
table: 'chat_item',
|
|
17
|
+
schema: 'wabot',
|
|
18
|
+
constructor: ChatItem,
|
|
19
|
+
add: {
|
|
20
|
+
columns: {
|
|
21
|
+
chat_id: {
|
|
22
|
+
type: 'TEXT',
|
|
23
|
+
value: () => chatId,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
this.chatId = chatId;
|
|
29
|
+
}
|
|
30
|
+
async findLastItems(count) {
|
|
31
|
+
const sql = `
|
|
32
|
+
SELECT ${this.columns}
|
|
33
|
+
FROM ${this.table}
|
|
34
|
+
WHERE chat_id = $1
|
|
35
|
+
ORDER BY created_at DESC
|
|
36
|
+
LIMIT $2
|
|
37
|
+
`;
|
|
38
|
+
const items = await this.query(sql, [this.chatId, count]);
|
|
39
|
+
return items.reverse();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { PgChatMemory };
|