@wabot-dev/framework 0.1.0-beta.26 → 0.1.0-beta.28
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/claude/ClaudeChatBotAdapter.js +39 -40
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +37 -37
- package/dist/src/ai/openia/OpenaiChatAdapter.js +11 -11
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +30 -30
- package/dist/src/channels/cmd/CmdChannel.js +2 -2
- package/dist/src/channels/socket/SocketChannel.js +1 -1
- package/dist/src/channels/telegram/TelegramChannel.js +1 -1
- package/dist/src/channels/whatsapp/WhatsAppReceiver.js +10 -16
- package/dist/src/channels/whatsapp/WhatsAppSender.js +7 -11
- package/dist/src/chatbot/ChatBot.js +23 -24
- package/dist/src/chatbot/ChatBotAdapter.js +22 -24
- package/dist/src/core/chat/IChatAdapter.js +3 -0
- package/dist/src/index.d.ts +110 -88
- package/dist/src/index.js +4 -0
- package/dist/src/validation/metadata/@isArray.js +18 -0
- package/dist/src/validation/metadata/ValidationMetadataStore.js +28 -0
- package/dist/src/validation/modelInfo.js +9 -0
- package/dist/src/validation/validators/validateArray.js +41 -0
- package/package.json +1 -1
|
@@ -63,46 +63,45 @@ let ClaudeChatBotAdapter = class ClaudeChatBotAdapter extends ChatBotAdapter {
|
|
|
63
63
|
return newChatItem;
|
|
64
64
|
}
|
|
65
65
|
mapChatItems(chatItems) {
|
|
66
|
-
const messages = []
|
|
67
|
-
for (const item of chatItems) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return messages;
|
|
66
|
+
// const messages: Anthropic.Messages.MessageParam[] = []
|
|
67
|
+
// for (const item of chatItems) {
|
|
68
|
+
// const itemData = item.getData()
|
|
69
|
+
// if (itemData.type === 'CONNECTION_MESSAGE') {
|
|
70
|
+
// if (!itemData.content.text) {
|
|
71
|
+
// throw new Error('User message content is empty')
|
|
72
|
+
// }
|
|
73
|
+
// messages.push({ role: 'user', content: itemData.content.text })
|
|
74
|
+
// } else if (itemData.type === 'BOT_MESSAGE') {
|
|
75
|
+
// if (!itemData.content.text) {
|
|
76
|
+
// throw new Error('Assistant message content is empty')
|
|
77
|
+
// }
|
|
78
|
+
// messages.push({ role: 'assistant', content: itemData.content.text })
|
|
79
|
+
// } else if (itemData.type === 'FUNCTION_CALL') {
|
|
80
|
+
// messages.push({
|
|
81
|
+
// role: 'assistant',
|
|
82
|
+
// content: [
|
|
83
|
+
// {
|
|
84
|
+
// type: 'tool_use',
|
|
85
|
+
// id: itemData.content.id,
|
|
86
|
+
// name: itemData.content.name,
|
|
87
|
+
// input: JSON.parse(itemData.content.arguments || '{}')
|
|
88
|
+
// }
|
|
89
|
+
// ]
|
|
90
|
+
// })
|
|
91
|
+
// messages.push({
|
|
92
|
+
// role: 'user',
|
|
93
|
+
// content: [
|
|
94
|
+
// {
|
|
95
|
+
// type: 'tool_result',
|
|
96
|
+
// tool_use_id: itemData.content.id,
|
|
97
|
+
// content: itemData.content.result || 'No result'
|
|
98
|
+
// }
|
|
99
|
+
// ]
|
|
100
|
+
// })
|
|
101
|
+
// }
|
|
102
|
+
// }
|
|
103
|
+
// return messages
|
|
104
|
+
return [];
|
|
106
105
|
}
|
|
107
106
|
};
|
|
108
107
|
ClaudeChatBotAdapter = __decorate([
|
|
@@ -60,43 +60,43 @@ let DeepSeekChatBotAdapter = class DeepSeekChatBotAdapter extends ChatBotAdapter
|
|
|
60
60
|
return newChatItem;
|
|
61
61
|
}
|
|
62
62
|
mapChatItems(chatItems) {
|
|
63
|
-
const deepSeekInput = []
|
|
64
|
-
for (const item of chatItems) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return
|
|
63
|
+
// const deepSeekInput: OpenAI.Chat.ChatCompletionMessageParam[] = []
|
|
64
|
+
// for (const item of chatItems) {
|
|
65
|
+
// const itemData = item.getData()
|
|
66
|
+
// if (itemData.type === 'CONNECTION_MESSAGE') {
|
|
67
|
+
// if (!itemData.content.text) {
|
|
68
|
+
// throw new Error('System message content is empty')
|
|
69
|
+
// }
|
|
70
|
+
// deepSeekInput.push({ role: 'user', content: itemData.content.text })
|
|
71
|
+
// } else if (itemData.type === 'BOT_MESSAGE') {
|
|
72
|
+
// if (!itemData.content.text) {
|
|
73
|
+
// throw new Error('System message content is empty')
|
|
74
|
+
// }
|
|
75
|
+
// deepSeekInput.push({ role: 'assistant', content: itemData.content.text })
|
|
76
|
+
// }
|
|
77
|
+
// if (itemData.type === 'FUNCTION_CALL') {
|
|
78
|
+
// deepSeekInput.push({
|
|
79
|
+
// role: 'assistant',
|
|
80
|
+
// tool_calls: [
|
|
81
|
+
// {
|
|
82
|
+
// id: itemData.content.id,
|
|
83
|
+
// type: 'function',
|
|
84
|
+
// function: {
|
|
85
|
+
// name: itemData.content.name,
|
|
86
|
+
// arguments: JSON.stringify(itemData.content.arguments),
|
|
87
|
+
// },
|
|
88
|
+
// },
|
|
89
|
+
// ],
|
|
90
|
+
// })
|
|
91
|
+
// deepSeekInput.push({
|
|
92
|
+
// role: 'tool',
|
|
93
|
+
// tool_call_id: itemData.content.id,
|
|
94
|
+
// content: itemData.content.result ?? 'No result',
|
|
95
|
+
// })
|
|
96
|
+
// }
|
|
97
|
+
// }
|
|
98
|
+
// return deepSeekInput
|
|
99
|
+
return [];
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
DeepSeekChatBotAdapter = __decorate([
|
|
@@ -18,16 +18,16 @@ class OpenaiChatAdapter {
|
|
|
18
18
|
}
|
|
19
19
|
mapChatItems(chatItems) {
|
|
20
20
|
const openIaInput = [];
|
|
21
|
-
for (const
|
|
22
|
-
switch (type) {
|
|
23
|
-
case '
|
|
24
|
-
openIaInput.push(this.mapConectionMessage(
|
|
21
|
+
for (const chatItem of chatItems) {
|
|
22
|
+
switch (chatItem.type) {
|
|
23
|
+
case 'connectionMessage':
|
|
24
|
+
openIaInput.push(this.mapConectionMessage(chatItem.connectionMessage));
|
|
25
25
|
break;
|
|
26
|
-
case '
|
|
27
|
-
openIaInput.push(this.mapBotMessage(
|
|
26
|
+
case 'botMessage':
|
|
27
|
+
openIaInput.push(this.mapBotMessage(chatItem.botMessage));
|
|
28
28
|
break;
|
|
29
|
-
case '
|
|
30
|
-
openIaInput.push(...this.mapFunctionCall(
|
|
29
|
+
case 'functionCall':
|
|
30
|
+
openIaInput.push(...this.mapFunctionCall(chatItem.functionCall));
|
|
31
31
|
break;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -79,12 +79,12 @@ class OpenaiChatAdapter {
|
|
|
79
79
|
mapResponse(response) {
|
|
80
80
|
let newItem;
|
|
81
81
|
if (response.output_text) {
|
|
82
|
-
newItem = { type: '
|
|
82
|
+
newItem = { type: 'botMessage', botMessage: { text: response.output_text } };
|
|
83
83
|
}
|
|
84
84
|
else if (response.output && response.output[0]?.type == 'function_call') {
|
|
85
85
|
newItem = {
|
|
86
|
-
type: '
|
|
87
|
-
|
|
86
|
+
type: 'functionCall',
|
|
87
|
+
functionCall: {
|
|
88
88
|
id: response.output[0].call_id,
|
|
89
89
|
name: response.output[0].name,
|
|
90
90
|
arguments: response.output[0].arguments,
|
|
@@ -48,36 +48,36 @@ let OpenaiChatBotAdapter = class OpenaiChatBotAdapter extends ChatBotAdapter {
|
|
|
48
48
|
return newChatItem;
|
|
49
49
|
}
|
|
50
50
|
mapChatItems(chatItems) {
|
|
51
|
-
const openIaInput = []
|
|
52
|
-
for (const item of chatItems) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
51
|
+
// const openIaInput: OpenAI.Responses.ResponseInput = []
|
|
52
|
+
// for (const item of chatItems) {
|
|
53
|
+
// const itemData = item.getData()
|
|
54
|
+
// if (itemData.type === 'CONNECTION_MESSAGE') {
|
|
55
|
+
// if (!itemData.content.text) {
|
|
56
|
+
// throw new Error('System message content is empty')
|
|
57
|
+
// }
|
|
58
|
+
// openIaInput.push({ role: 'user', content: itemData.content.text })
|
|
59
|
+
// } else if (itemData.type === 'BOT_MESSAGE') {
|
|
60
|
+
// if (!itemData.content.text) {
|
|
61
|
+
// throw new Error('System message content is empty')
|
|
62
|
+
// }
|
|
63
|
+
// openIaInput.push({ role: 'assistant', content: itemData.content.text })
|
|
64
|
+
// }
|
|
65
|
+
// if (itemData.type === 'FUNCTION_CALL') {
|
|
66
|
+
// openIaInput.push({
|
|
67
|
+
// type: 'function_call',
|
|
68
|
+
// call_id: itemData.content.id,
|
|
69
|
+
// name: itemData.content.name,
|
|
70
|
+
// arguments: JSON.stringify(itemData.content.arguments),
|
|
71
|
+
// })
|
|
72
|
+
// openIaInput.push({
|
|
73
|
+
// type: 'function_call_output',
|
|
74
|
+
// call_id: itemData.content.id,
|
|
75
|
+
// output: itemData.content.result ?? 'Not result',
|
|
76
|
+
// })
|
|
77
|
+
// }
|
|
78
|
+
// }
|
|
79
|
+
// return openIaInput
|
|
80
|
+
return [];
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
OpenaiChatBotAdapter = __decorate([
|
|
@@ -54,10 +54,10 @@ let CmdChannel = CmdChannel_1 = class CmdChannel {
|
|
|
54
54
|
chatConnection,
|
|
55
55
|
userConnection,
|
|
56
56
|
text: trimmedInput,
|
|
57
|
-
senderName: 'cmd',
|
|
57
|
+
// senderName: 'cmd',
|
|
58
58
|
},
|
|
59
59
|
reply: (message) => {
|
|
60
|
-
console.log(`\n[${message.senderName}]: ${message.text}\n`)
|
|
60
|
+
// console.log(`\n[${message.senderName}]: ${message.text}\n`)
|
|
61
61
|
this.rl.prompt();
|
|
62
62
|
},
|
|
63
63
|
});
|
|
@@ -57,7 +57,7 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
|
|
|
57
57
|
chatConnection,
|
|
58
58
|
userConnection,
|
|
59
59
|
text: trimmedInput,
|
|
60
|
-
senderName: message.senderName,
|
|
60
|
+
// senderName: message.senderName,
|
|
61
61
|
},
|
|
62
62
|
reply: (message) => {
|
|
63
63
|
socket.emit(this.config.channel, message);
|
|
@@ -37,22 +37,16 @@ class WhatsAppReceiver {
|
|
|
37
37
|
this.logger.error(`message type ${message.type} is not supported yet`);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
await listener({
|
|
51
|
-
chatConnection,
|
|
52
|
-
userConnection,
|
|
53
|
-
senderName: contact.profile.name,
|
|
54
|
-
text: message.text.body,
|
|
55
|
-
});
|
|
40
|
+
({
|
|
41
|
+
id: contact.wa_id});
|
|
42
|
+
({
|
|
43
|
+
id: contact.wa_id});
|
|
44
|
+
// await listener({
|
|
45
|
+
// chatConnection,
|
|
46
|
+
// userConnection,
|
|
47
|
+
// senderName: contact.profile.name,
|
|
48
|
+
// text: message.text.body,
|
|
49
|
+
// })
|
|
56
50
|
}
|
|
57
51
|
}
|
|
58
52
|
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import '../../core/chat/repository/IChatRepository.js';
|
|
2
|
-
import { ChatItem } from '../../core/chat/ChatItem.js';
|
|
3
|
-
import '../../core/user/IUserRepository.js';
|
|
4
|
-
|
|
5
1
|
class WhatsAppSender {
|
|
6
2
|
logger;
|
|
7
3
|
chatRepository;
|
|
@@ -72,7 +68,7 @@ class WhatsAppSender {
|
|
|
72
68
|
.join('\n');
|
|
73
69
|
return {
|
|
74
70
|
text: this.replaceTemplateParameters(components, request.templateMessage.parameters),
|
|
75
|
-
senderName: request.senderName,
|
|
71
|
+
// senderName: request.senderName,
|
|
76
72
|
};
|
|
77
73
|
}
|
|
78
74
|
async writePrivateChatMemory(message, to) {
|
|
@@ -82,12 +78,12 @@ class WhatsAppSender {
|
|
|
82
78
|
channelName: 'WhatsAppChannel',
|
|
83
79
|
};
|
|
84
80
|
const chat = await this.chatResolver.resolve(chatConnection);
|
|
85
|
-
|
|
86
|
-
const chatItem = new ChatItem({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
})
|
|
90
|
-
await chatMemory
|
|
81
|
+
await this.chatRepository.findMemory(chat.id);
|
|
82
|
+
// const chatItem = new ChatItem({
|
|
83
|
+
// type: 'BOT_MESSAGE',
|
|
84
|
+
// content: message,
|
|
85
|
+
// })
|
|
86
|
+
// await chatMemory!.create(chatItem)
|
|
91
87
|
}
|
|
92
88
|
replaceTemplateParameters(template, data) {
|
|
93
89
|
let result = template;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
|
|
3
3
|
import '../core/chat/repository/IChatRepository.js';
|
|
4
|
-
import { ChatItem } from '../core/chat/ChatItem.js';
|
|
5
4
|
import '../core/user/IUserRepository.js';
|
|
6
5
|
import { injectable } from '../injection/index.js';
|
|
7
6
|
import { ChatBotAdapter } from './ChatBotAdapter.js';
|
|
@@ -15,31 +14,31 @@ let ChatBot = class ChatBot {
|
|
|
15
14
|
this.memory = memory;
|
|
16
15
|
}
|
|
17
16
|
async sendMessage(message, callback) {
|
|
18
|
-
const newChatItem = new ChatItem({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
await this.memory.create(newChatItem)
|
|
23
|
-
this.processLoop(callback)
|
|
17
|
+
// const newChatItem = new ChatItem({
|
|
18
|
+
// type: 'CONNECTION_MESSAGE',
|
|
19
|
+
// content: message,
|
|
20
|
+
// })
|
|
21
|
+
// await this.memory.create(newChatItem)
|
|
22
|
+
// this.processLoop(callback)
|
|
24
23
|
}
|
|
25
24
|
async processLoop(callback) {
|
|
26
|
-
const prevChatItems = await this.memory.findLastItems(10)
|
|
27
|
-
if (prevChatItems.length === 0) {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
const lastChatItem = prevChatItems[prevChatItems.length - 1]
|
|
31
|
-
const lastItemType = lastChatItem.getType()
|
|
32
|
-
if (lastItemType === 'BOT_MESSAGE') {
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
const newChatItem = await this.adapter.generateNextChatItem(prevChatItems)
|
|
36
|
-
await this.memory.create(newChatItem)
|
|
37
|
-
const newChatItemData = newChatItem.getData()
|
|
38
|
-
if (newChatItemData.type === 'BOT_MESSAGE') {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
this.processLoop(callback)
|
|
25
|
+
// const prevChatItems = await this.memory.findLastItems(10)
|
|
26
|
+
// if (prevChatItems.length === 0) {
|
|
27
|
+
// return
|
|
28
|
+
// }
|
|
29
|
+
// const lastChatItem = prevChatItems[prevChatItems.length - 1]
|
|
30
|
+
// const lastItemType = lastChatItem.getType()
|
|
31
|
+
// if (lastItemType === 'BOT_MESSAGE') {
|
|
32
|
+
// return
|
|
33
|
+
// }
|
|
34
|
+
// const newChatItem = await this.adapter.generateNextChatItem(prevChatItems)
|
|
35
|
+
// await this.memory.create(newChatItem)
|
|
36
|
+
// const newChatItemData = newChatItem.getData()
|
|
37
|
+
// if (newChatItemData.type === 'BOT_MESSAGE') {
|
|
38
|
+
// callback(newChatItemData.content)
|
|
39
|
+
// return
|
|
40
|
+
// }
|
|
41
|
+
// this.processLoop(callback)
|
|
43
42
|
}
|
|
44
43
|
};
|
|
45
44
|
ChatBot = __decorate([
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import '../core/chat/repository/IChatRepository.js';
|
|
2
|
-
import { ChatItem } from '../core/chat/ChatItem.js';
|
|
3
|
-
import '../core/user/IUserRepository.js';
|
|
4
|
-
|
|
5
1
|
class ChatBotAdapter {
|
|
6
2
|
mindset;
|
|
7
3
|
constructor(mindset) {
|
|
@@ -44,28 +40,30 @@ class ChatBotAdapter {
|
|
|
44
40
|
return systemPrompt;
|
|
45
41
|
}
|
|
46
42
|
async buildBotMessageItem(text) {
|
|
47
|
-
const senderName = (await this.mindset.identity()).name
|
|
48
|
-
const newBotMessage = new ChatItem({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})
|
|
55
|
-
return newBotMessage
|
|
43
|
+
// const senderName = (await this.mindset.identity()).name
|
|
44
|
+
// const newBotMessage = new ChatItem({
|
|
45
|
+
// type: 'BOT_MESSAGE',
|
|
46
|
+
// content: {
|
|
47
|
+
// senderName,
|
|
48
|
+
// text,
|
|
49
|
+
// },
|
|
50
|
+
// })
|
|
51
|
+
// return newBotMessage
|
|
52
|
+
return 0;
|
|
56
53
|
}
|
|
57
54
|
async buildFunctionCallItem(id, functionName, functionArguments) {
|
|
58
|
-
const functionResult = await this.mindset.callFunction(functionName, functionArguments)
|
|
59
|
-
const newFunctionCall = new ChatItem({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
})
|
|
68
|
-
return newFunctionCall
|
|
55
|
+
// const functionResult = await this.mindset.callFunction(functionName, functionArguments)
|
|
56
|
+
// const newFunctionCall = new ChatItem({
|
|
57
|
+
// type: 'FUNCTION_CALL',
|
|
58
|
+
// content: {
|
|
59
|
+
// id,
|
|
60
|
+
// name: functionName,
|
|
61
|
+
// arguments: functionArguments,
|
|
62
|
+
// result: functionResult,
|
|
63
|
+
// },
|
|
64
|
+
// })
|
|
65
|
+
// return newFunctionCall
|
|
66
|
+
return 0;
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
|
package/dist/src/index.d.ts
CHANGED
|
@@ -68,6 +68,67 @@ interface IPersistentData extends IEntityData {
|
|
|
68
68
|
declare class Persistent<D extends IPersistentData> extends Entity<D> {
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
interface IChatMessage {
|
|
72
|
+
text?: string;
|
|
73
|
+
}
|
|
74
|
+
interface IFunctionCall {
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
arguments?: string;
|
|
78
|
+
result?: string;
|
|
79
|
+
}
|
|
80
|
+
declare const chatItemTypeOptions: readonly ["botMessage", "connectionMessage", "functionCall"];
|
|
81
|
+
type IBotMessageItem = {
|
|
82
|
+
type: 'botMessage';
|
|
83
|
+
botMessage: IChatMessage;
|
|
84
|
+
};
|
|
85
|
+
type IConnectionMessageItem = {
|
|
86
|
+
type: 'connectionMessage';
|
|
87
|
+
connectionMessage: IChatMessage;
|
|
88
|
+
};
|
|
89
|
+
type IFunctionCallItem = {
|
|
90
|
+
type: 'functionCall';
|
|
91
|
+
functionCall: IFunctionCall;
|
|
92
|
+
};
|
|
93
|
+
type IChatItem = IBotMessageItem | IConnectionMessageItem | IFunctionCallItem;
|
|
94
|
+
type IChatItemType = IChatItem['type'] & (typeof chatItemTypeOptions)[number];
|
|
95
|
+
interface IChatToolParameter {
|
|
96
|
+
type: string;
|
|
97
|
+
name: string;
|
|
98
|
+
description: string;
|
|
99
|
+
}
|
|
100
|
+
interface IChatTool {
|
|
101
|
+
language: string;
|
|
102
|
+
name: string;
|
|
103
|
+
description: string;
|
|
104
|
+
parameters: IChatToolParameter[];
|
|
105
|
+
}
|
|
106
|
+
interface IChatAdapterNextItemReq {
|
|
107
|
+
model: string;
|
|
108
|
+
systemPrompt: string;
|
|
109
|
+
tools: IChatTool[];
|
|
110
|
+
prevItems: IChatItem[];
|
|
111
|
+
}
|
|
112
|
+
interface IChatAdapter {
|
|
113
|
+
nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type IChatItemData = IEntityData & IChatItem;
|
|
117
|
+
declare class ChatItem extends Entity<IChatItemData> {
|
|
118
|
+
getType(): "botMessage" | "connectionMessage" | "functionCall";
|
|
119
|
+
getContent(): IPrimitive | IStorableData | IPrimitive[] | IStorableData[];
|
|
120
|
+
getData(): IChatItemData;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface IChatMemory {
|
|
124
|
+
findLastItems(count: number): Promise<ChatItem[]>;
|
|
125
|
+
create(item: ChatItem): Promise<void>;
|
|
126
|
+
}
|
|
127
|
+
declare class ChatMemory implements IChatMemory {
|
|
128
|
+
findLastItems(count: number): Promise<ChatItem[]>;
|
|
129
|
+
create(item: ChatItem): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
|
|
71
132
|
type IChatType = 'PRIVATE' | 'GROUP';
|
|
72
133
|
interface IChatConnection extends IStorableData {
|
|
73
134
|
chatType: IChatType;
|
|
@@ -88,10 +149,22 @@ declare class Chat extends Entity<IChatData> {
|
|
|
88
149
|
validate(): void;
|
|
89
150
|
}
|
|
90
151
|
|
|
91
|
-
interface
|
|
152
|
+
interface IChatRepository {
|
|
153
|
+
create(chat: Chat): Promise<void>;
|
|
154
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
155
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
156
|
+
}
|
|
157
|
+
declare class ChatRepository implements IChatRepository {
|
|
158
|
+
create(chat: Chat): Promise<void>;
|
|
159
|
+
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
160
|
+
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
92
161
|
}
|
|
93
162
|
|
|
94
|
-
interface
|
|
163
|
+
interface IChatFunctionCall {
|
|
164
|
+
id: string;
|
|
165
|
+
name: string;
|
|
166
|
+
arguments?: string;
|
|
167
|
+
result?: string;
|
|
95
168
|
}
|
|
96
169
|
|
|
97
170
|
interface IUserConnection extends IStorableData {
|
|
@@ -113,66 +186,6 @@ declare class User extends Entity<IUserData> {
|
|
|
113
186
|
addConnection(connection: IUserConnection): void;
|
|
114
187
|
}
|
|
115
188
|
|
|
116
|
-
interface IChatMessage extends IStorableData {
|
|
117
|
-
text?: string;
|
|
118
|
-
documents?: IChatDocument[];
|
|
119
|
-
images?: IChatImage[];
|
|
120
|
-
senderName?: string;
|
|
121
|
-
}
|
|
122
|
-
interface IConnectionChatMessage extends IChatMessage {
|
|
123
|
-
chatConnection: IChatConnection;
|
|
124
|
-
userConnection: IUserConnection;
|
|
125
|
-
userId?: string;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
interface IChatFunctionCall {
|
|
129
|
-
id: string;
|
|
130
|
-
name: string;
|
|
131
|
-
arguments?: string;
|
|
132
|
-
result?: string;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
type ISystemMessageItem = {
|
|
136
|
-
type: 'BOT_MESSAGE';
|
|
137
|
-
content: IChatMessage;
|
|
138
|
-
};
|
|
139
|
-
type IReceivedMessageItem = {
|
|
140
|
-
type: 'CONNECTION_MESSAGE';
|
|
141
|
-
content: IConnectionChatMessage;
|
|
142
|
-
};
|
|
143
|
-
type ISystemFunctionCallItem = {
|
|
144
|
-
type: 'FUNCTION_CALL';
|
|
145
|
-
content: IChatFunctionCall;
|
|
146
|
-
};
|
|
147
|
-
type IChatItemRawData = ISystemMessageItem | IReceivedMessageItem | ISystemFunctionCallItem;
|
|
148
|
-
type IChatItemData = IEntityData & IChatItemRawData;
|
|
149
|
-
type IChatItemType = IChatItemData['type'];
|
|
150
|
-
declare class ChatItem extends Entity<IChatItemData> {
|
|
151
|
-
getType(): "BOT_MESSAGE" | "CONNECTION_MESSAGE" | "FUNCTION_CALL";
|
|
152
|
-
getContent(): IChatMessage | IConnectionChatMessage | IChatFunctionCall;
|
|
153
|
-
getData(): IChatItemData;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
interface IChatMemory {
|
|
157
|
-
findLastItems(count: number): Promise<ChatItem[]>;
|
|
158
|
-
create(item: ChatItem): Promise<void>;
|
|
159
|
-
}
|
|
160
|
-
declare class ChatMemory implements IChatMemory {
|
|
161
|
-
findLastItems(count: number): Promise<ChatItem[]>;
|
|
162
|
-
create(item: ChatItem): Promise<void>;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
interface IChatRepository {
|
|
166
|
-
create(chat: Chat): Promise<void>;
|
|
167
|
-
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
168
|
-
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
169
|
-
}
|
|
170
|
-
declare class ChatRepository implements IChatRepository {
|
|
171
|
-
create(chat: Chat): Promise<void>;
|
|
172
|
-
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
173
|
-
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
189
|
interface IUserRepository {
|
|
177
190
|
create(chat: User): Promise<void>;
|
|
178
191
|
update(chat: User): Promise<void>;
|
|
@@ -184,6 +197,12 @@ declare class UserRepository implements IUserRepository {
|
|
|
184
197
|
findByConnection(query: IUserConnection): Promise<User | null>;
|
|
185
198
|
}
|
|
186
199
|
|
|
200
|
+
interface IConnectionChatMessage extends IChatMessage {
|
|
201
|
+
chatConnection: IChatConnection;
|
|
202
|
+
userConnection: IUserConnection;
|
|
203
|
+
userId?: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
187
206
|
interface IMessageContext {
|
|
188
207
|
message: IConnectionChatMessage;
|
|
189
208
|
chat: Chat;
|
|
@@ -386,8 +405,8 @@ declare class ChatBotAdapter implements IChatBotAdapter {
|
|
|
386
405
|
constructor(mindset: MindsetOperator);
|
|
387
406
|
generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem>;
|
|
388
407
|
protected systemPrompt(): Promise<string>;
|
|
389
|
-
protected buildBotMessageItem(text: string): Promise<
|
|
390
|
-
protected buildFunctionCallItem(id: string, functionName: string, functionArguments: string): Promise<
|
|
408
|
+
protected buildBotMessageItem(text: string): Promise<any>;
|
|
409
|
+
protected buildFunctionCallItem(id: string, functionName: string, functionArguments: string): Promise<any>;
|
|
391
410
|
}
|
|
392
411
|
|
|
393
412
|
interface IChatBot {
|
|
@@ -402,27 +421,6 @@ declare class ChatBot implements IChatBot {
|
|
|
402
421
|
protected processLoop(callback: (message: IChatMessage) => void): Promise<void>;
|
|
403
422
|
}
|
|
404
423
|
|
|
405
|
-
interface IChatToolParameter {
|
|
406
|
-
type: string;
|
|
407
|
-
name: string;
|
|
408
|
-
description: string;
|
|
409
|
-
}
|
|
410
|
-
interface IChatTool {
|
|
411
|
-
language: string;
|
|
412
|
-
name: string;
|
|
413
|
-
description: string;
|
|
414
|
-
parameters: IChatToolParameter[];
|
|
415
|
-
}
|
|
416
|
-
interface IChatAdapterNextItemReq {
|
|
417
|
-
model: string;
|
|
418
|
-
systemPrompt: string;
|
|
419
|
-
tools: IChatTool[];
|
|
420
|
-
prevItems: IChatItemRawData[];
|
|
421
|
-
}
|
|
422
|
-
interface IChatAdapter {
|
|
423
|
-
nextItem(req: IChatAdapterNextItemReq): Promise<IChatItemRawData>;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
424
|
declare class DeepSeekChatBotAdapter extends ChatBotAdapter {
|
|
427
425
|
private deepSeek;
|
|
428
426
|
private model;
|
|
@@ -444,7 +442,7 @@ declare class OpenaiChatBotAdapter extends ChatBotAdapter {
|
|
|
444
442
|
declare class OpenaiChatAdapter implements IChatAdapter {
|
|
445
443
|
private openai;
|
|
446
444
|
private logger;
|
|
447
|
-
nextItem(req: IChatAdapterNextItemReq): Promise<
|
|
445
|
+
nextItem(req: IChatAdapterNextItemReq): Promise<IChatItem>;
|
|
448
446
|
private mapChatItems;
|
|
449
447
|
private mapConectionMessage;
|
|
450
448
|
private mapBotMessage;
|
|
@@ -1341,6 +1339,9 @@ interface IModelValidationError extends IValidationError {
|
|
|
1341
1339
|
[key: string]: string[];
|
|
1342
1340
|
};
|
|
1343
1341
|
}
|
|
1342
|
+
interface IArrayValidationError extends IValidationError {
|
|
1343
|
+
items: (IValidationError[] | null)[];
|
|
1344
|
+
}
|
|
1344
1345
|
type IValidationResult<V> = {
|
|
1345
1346
|
value: V;
|
|
1346
1347
|
error?: undefined;
|
|
@@ -1355,7 +1356,14 @@ type IModelValidationResult<V> = {
|
|
|
1355
1356
|
value?: undefined;
|
|
1356
1357
|
error: IModelValidationError;
|
|
1357
1358
|
};
|
|
1358
|
-
type
|
|
1359
|
+
type IArrayValidationResult<V> = {
|
|
1360
|
+
value: V[];
|
|
1361
|
+
error?: undefined;
|
|
1362
|
+
} | {
|
|
1363
|
+
value?: undefined;
|
|
1364
|
+
error: IArrayValidationError;
|
|
1365
|
+
};
|
|
1366
|
+
type IValidator<V = any, O = any> = (value: V, options: O) => IValidationResult<V>;
|
|
1359
1367
|
interface IPropertyValidatorInfo {
|
|
1360
1368
|
propertyName: string;
|
|
1361
1369
|
validator: IValidator;
|
|
@@ -1385,6 +1393,18 @@ declare class ValidationMetadataStore {
|
|
|
1385
1393
|
private getConstructorPropertiesValidatorsInfo;
|
|
1386
1394
|
}
|
|
1387
1395
|
|
|
1396
|
+
interface IValidateArrayOptions {
|
|
1397
|
+
}
|
|
1398
|
+
interface IValidateArrayOptionsWithItemsValidators extends IValidateArrayOptions {
|
|
1399
|
+
itemsValidator?: {
|
|
1400
|
+
validator: IValidator;
|
|
1401
|
+
options: any;
|
|
1402
|
+
}[];
|
|
1403
|
+
}
|
|
1404
|
+
declare function validateArray(value: any, options?: IValidateArrayOptionsWithItemsValidators): IArrayValidationResult<any>;
|
|
1405
|
+
|
|
1406
|
+
declare function isArray(options?: IValidateArrayOptions): (target: object, propertyKey: string | symbol) => void;
|
|
1407
|
+
|
|
1388
1408
|
declare function validateIsBoolean(value: any): IValidationResult<boolean>;
|
|
1389
1409
|
|
|
1390
1410
|
declare function validateIsDate(value: any): IValidationResult<Date>;
|
|
@@ -1411,4 +1431,6 @@ declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IM
|
|
|
1411
1431
|
|
|
1412
1432
|
declare function validate<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
|
|
1413
1433
|
|
|
1414
|
-
|
|
1434
|
+
declare function modelInfo<V>(modelConstructor: IConstructor<V>): IModelValidatorsInfo<V>;
|
|
1435
|
+
|
|
1436
|
+
export { Async, Auth, AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatBotAdapter, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatBotAdapter, EmailService, Entity, Env, EnvWhatsAppRepository, ExpressProvider, HtmlModule, HttpServerProvider, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatTool, type IChatToolParameter, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConnectionChatMessage, type IConnectionMessageItem, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEmailService, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IJobData, type IJobEvent, type IJobEventListener, type IJwtRefreshTokenData, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPostConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRestControllerConfig, type IRestControllerMetadata, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatAdapter, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, Random, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, get, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, param, post, prepareChatContainer, restController, runAsyncCommandHandlers, runChannel, runRestControllers, runServer, scoped, singleton, socket, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
|
package/dist/src/index.js
CHANGED
|
@@ -49,6 +49,7 @@ export { ChatMemory } from './core/chat/repository/IChatMemory.js';
|
|
|
49
49
|
export { ChatRepository } from './core/chat/repository/IChatRepository.js';
|
|
50
50
|
export { Chat } from './core/chat/Chat.js';
|
|
51
51
|
export { ChatItem } from './core/chat/ChatItem.js';
|
|
52
|
+
export { chatItemTypeOptions } from './core/chat/IChatAdapter.js';
|
|
52
53
|
export { User } from './core/user/User.js';
|
|
53
54
|
export { UserRepository } from './core/user/IUserRepository.js';
|
|
54
55
|
export { MessageContext } from './core/IMessageContext.js';
|
|
@@ -116,6 +117,7 @@ export { isString } from './validation/metadata/@isString.js';
|
|
|
116
117
|
export { max } from './validation/metadata/@max.js';
|
|
117
118
|
export { min } from './validation/metadata/@min.js';
|
|
118
119
|
export { ValidationMetadataStore } from './validation/metadata/ValidationMetadataStore.js';
|
|
120
|
+
export { isArray } from './validation/metadata/@isArray.js';
|
|
119
121
|
export { validateIsBoolean } from './validation/validators/validateIsBoolean.js';
|
|
120
122
|
export { validateIsDate } from './validation/validators/validateIsDate.js';
|
|
121
123
|
export { validateIsNotEmpty } from './validation/validators/validateIsNotEmpty.js';
|
|
@@ -125,5 +127,7 @@ export { validateMax } from './validation/validators/validateMax.js';
|
|
|
125
127
|
export { validateMin } from './validation/validators/validateMin.js';
|
|
126
128
|
export { validateIsPresent } from './validation/validators/validateIsPresent.js';
|
|
127
129
|
export { validateModel } from './validation/validators/validateModel.js';
|
|
130
|
+
export { validateArray } from './validation/validators/validateArray.js';
|
|
128
131
|
export { validate } from './validation/validate.js';
|
|
132
|
+
export { modelInfo } from './validation/modelInfo.js';
|
|
129
133
|
export { Container } from './injection/Container.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { validateArray } from '../validators/validateArray.js';
|
|
3
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
4
|
+
|
|
5
|
+
function isArray(options) {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
const propertyName = propertyKey.toString();
|
|
8
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
9
|
+
store.saveValidatorMetadata({
|
|
10
|
+
modelConstructor: target.constructor,
|
|
11
|
+
propertyName,
|
|
12
|
+
validator: validateArray,
|
|
13
|
+
validatorOptions: options,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { isArray };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { singleton } from '../../injection/index.js';
|
|
3
3
|
import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from '../validators/validateIsOptional.js';
|
|
4
|
+
import { validateArray } from '../validators/validateArray.js';
|
|
4
5
|
|
|
5
6
|
function getClassHierarchy(cls) {
|
|
6
7
|
const classes = [];
|
|
@@ -24,6 +25,33 @@ let ValidationMetadataStore = class ValidationMetadataStore {
|
|
|
24
25
|
modelValidators.set(validatorMetadata.propertyName, propertyValidators);
|
|
25
26
|
}
|
|
26
27
|
propertyValidators.unshift(validatorMetadata);
|
|
28
|
+
const arrayValidatorMetadata = propertyValidators.find((x) => x.validator === validateArray);
|
|
29
|
+
if (!arrayValidatorMetadata) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!arrayValidatorMetadata.validatorOptions) {
|
|
33
|
+
arrayValidatorMetadata.validatorOptions = {};
|
|
34
|
+
}
|
|
35
|
+
const arrayValidatorOptions = arrayValidatorMetadata.validatorOptions;
|
|
36
|
+
if (!arrayValidatorOptions.itemsValidator) {
|
|
37
|
+
arrayValidatorOptions.itemsValidator = [];
|
|
38
|
+
}
|
|
39
|
+
const removeValidatorsMetadata = [];
|
|
40
|
+
for (const validatorMetadata of propertyValidators) {
|
|
41
|
+
if (validatorMetadata.validator === validateArray ||
|
|
42
|
+
validatorMetadata.validator === _IS_OPTIONAL_DUMMY_VALIDATOR_) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
arrayValidatorOptions.itemsValidator.push({
|
|
46
|
+
options: validatorMetadata.validatorOptions,
|
|
47
|
+
validator: validatorMetadata.validator,
|
|
48
|
+
});
|
|
49
|
+
removeValidatorsMetadata.push(validatorMetadata);
|
|
50
|
+
}
|
|
51
|
+
for (const toRemove of removeValidatorsMetadata) {
|
|
52
|
+
const indexToRemove = propertyValidators.indexOf(toRemove);
|
|
53
|
+
propertyValidators.splice(indexToRemove, 1);
|
|
54
|
+
}
|
|
27
55
|
}
|
|
28
56
|
getModelValidatorsInfo(modelConstructor) {
|
|
29
57
|
const constructors = getClassHierarchy(modelConstructor);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { container } from '../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './metadata/ValidationMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function modelInfo(modelConstructor) {
|
|
5
|
+
const metadataStore = container.resolve(ValidationMetadataStore);
|
|
6
|
+
return metadataStore.getModelValidatorsInfo(modelConstructor);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { modelInfo };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function validateArray(value, options) {
|
|
2
|
+
if (!Array.isArray(value)) {
|
|
3
|
+
return {
|
|
4
|
+
error: { description: 'Should be an array', items: [] },
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
const { itemsValidator } = options ?? {};
|
|
8
|
+
const valueOut = [];
|
|
9
|
+
const errorItems = [];
|
|
10
|
+
for (const item of value) {
|
|
11
|
+
let itemOut = item;
|
|
12
|
+
const itemErrors = [];
|
|
13
|
+
for (const itemValidator of itemsValidator ?? []) {
|
|
14
|
+
const { error, value } = itemValidator.validator(itemOut, itemValidator.options);
|
|
15
|
+
if (error) {
|
|
16
|
+
itemErrors.push(error);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
itemOut = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (itemErrors.length == 0) {
|
|
23
|
+
valueOut.push(itemOut);
|
|
24
|
+
errorItems.push(null);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
valueOut.push(null);
|
|
28
|
+
errorItems.push(itemErrors);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (errorItems.some((x) => x != null)) {
|
|
32
|
+
return {
|
|
33
|
+
error: { description: 'Error on some items', items: errorItems },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
value: valueOut,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { validateArray };
|