@wabot-dev/framework 0.5.15 → 0.7.0
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/addon/chat-bot/anthropic/AnthropicChatAdapter.js +63 -2
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +9 -2
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +53 -2
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +35 -4
- package/dist/src/addon/chat-bot/openrouter/OpenRouterChatAdapter.js +26 -6
- package/dist/src/addon/chat-bot/pg/PgChatRepository.js +9 -1
- package/dist/src/addon/chat-bot/ram/RamChatRepository.js +13 -0
- package/dist/src/feature/chat-bot/Chat.js +23 -3
- package/dist/src/feature/chat-bot/ChatOperator.js +54 -0
- package/dist/src/feature/chat-bot/ChatRepository.js +3 -0
- package/dist/src/feature/chat-bot/extractChatMessageText.js +18 -2
- package/dist/src/feature/chat-bot/isChatMessageEmpty.js +5 -0
- package/dist/src/feature/mindset/MindsetOperator.js +15 -2
- package/dist/src/feature/pg/PgCrudRepository.js +2 -2
- package/dist/src/index.d.ts +45 -6
- package/dist/src/index.js +2 -0
- package/package.json +6 -6
|
@@ -7,8 +7,16 @@ import 'uuid';
|
|
|
7
7
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
8
8
|
import { safeJsonParse } from '../../../feature/chat-bot/safeJsonParse.js';
|
|
9
9
|
import { extractChatMessageText } from '../../../feature/chat-bot/extractChatMessageText.js';
|
|
10
|
+
import { isChatMessageEmpty } from '../../../feature/chat-bot/isChatMessageEmpty.js';
|
|
10
11
|
import { Anthropic } from '@anthropic-ai/sdk';
|
|
11
12
|
|
|
13
|
+
const ANTHROPIC_SUPPORTED_IMAGE_MIME_TYPES = [
|
|
14
|
+
'image/png',
|
|
15
|
+
'image/jpeg',
|
|
16
|
+
'image/gif',
|
|
17
|
+
'image/webp',
|
|
18
|
+
];
|
|
19
|
+
const ANTHROPIC_SUPPORTED_DOCUMENT_MIME_TYPES = ['application/pdf', 'text/plain'];
|
|
12
20
|
let AnthropicChatAdapter = class AnthropicChatAdapter {
|
|
13
21
|
env;
|
|
14
22
|
anthropic;
|
|
@@ -50,10 +58,59 @@ let AnthropicChatAdapter = class AnthropicChatAdapter {
|
|
|
50
58
|
return messages;
|
|
51
59
|
}
|
|
52
60
|
mapHumanMessage(item) {
|
|
53
|
-
if (
|
|
61
|
+
if (isChatMessageEmpty(item)) {
|
|
54
62
|
throw new Error('User message content is empty');
|
|
55
63
|
}
|
|
56
|
-
|
|
64
|
+
const blocks = [];
|
|
65
|
+
blocks.push({
|
|
66
|
+
type: 'text',
|
|
67
|
+
text: extractChatMessageText(item, {
|
|
68
|
+
supportedImageMimeTypes: ANTHROPIC_SUPPORTED_IMAGE_MIME_TYPES,
|
|
69
|
+
supportedDocumentMimeTypes: ANTHROPIC_SUPPORTED_DOCUMENT_MIME_TYPES,
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
if (item.images) {
|
|
73
|
+
for (const image of item.images) {
|
|
74
|
+
if (!ANTHROPIC_SUPPORTED_IMAGE_MIME_TYPES.includes(image.mimeType))
|
|
75
|
+
continue;
|
|
76
|
+
blocks.push({ type: 'image', source: this.toAnthropicImageSource(image) });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (item.documents) {
|
|
80
|
+
for (const doc of item.documents) {
|
|
81
|
+
if (!ANTHROPIC_SUPPORTED_DOCUMENT_MIME_TYPES.includes(doc.mimeType))
|
|
82
|
+
continue;
|
|
83
|
+
blocks.push({ type: 'document', source: this.toAnthropicDocumentSource(doc) });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { role: 'user', content: blocks };
|
|
87
|
+
}
|
|
88
|
+
toAnthropicImageSource(image) {
|
|
89
|
+
if (image.publicUrl) {
|
|
90
|
+
return { type: 'url', url: image.publicUrl };
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
type: 'base64',
|
|
94
|
+
media_type: image.mimeType,
|
|
95
|
+
data: stripDataUrlPrefix(image.base64Url),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
toAnthropicDocumentSource(doc) {
|
|
99
|
+
if (doc.publicUrl) {
|
|
100
|
+
return { type: 'url', url: doc.publicUrl };
|
|
101
|
+
}
|
|
102
|
+
if (doc.mimeType === 'text/plain') {
|
|
103
|
+
return {
|
|
104
|
+
type: 'text',
|
|
105
|
+
media_type: 'text/plain',
|
|
106
|
+
data: Buffer.from(stripDataUrlPrefix(doc.base64Url), 'base64').toString('utf-8'),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
type: 'base64',
|
|
111
|
+
media_type: 'application/pdf',
|
|
112
|
+
data: stripDataUrlPrefix(doc.base64Url),
|
|
113
|
+
};
|
|
57
114
|
}
|
|
58
115
|
mapBotMessage(item) {
|
|
59
116
|
if (!item.text) {
|
|
@@ -134,5 +191,9 @@ AnthropicChatAdapter = __decorate([
|
|
|
134
191
|
singleton(),
|
|
135
192
|
__metadata("design:paramtypes", [Env])
|
|
136
193
|
], AnthropicChatAdapter);
|
|
194
|
+
function stripDataUrlPrefix(dataUrl) {
|
|
195
|
+
const commaIndex = dataUrl.indexOf(',');
|
|
196
|
+
return commaIndex >= 0 && dataUrl.startsWith('data:') ? dataUrl.slice(commaIndex + 1) : dataUrl;
|
|
197
|
+
}
|
|
137
198
|
|
|
138
199
|
export { AnthropicChatAdapter };
|
|
@@ -5,6 +5,7 @@ import 'uuid';
|
|
|
5
5
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
6
6
|
import '../../../core/error/setupErrorHandlers.js';
|
|
7
7
|
import { extractChatMessageText } from '../../../feature/chat-bot/extractChatMessageText.js';
|
|
8
|
+
import { isChatMessageEmpty } from '../../../feature/chat-bot/isChatMessageEmpty.js';
|
|
8
9
|
import { OpenAI } from 'openai';
|
|
9
10
|
|
|
10
11
|
class DeepSeekChatAdapter {
|
|
@@ -55,10 +56,16 @@ class DeepSeekChatAdapter {
|
|
|
55
56
|
return deepSeekInput;
|
|
56
57
|
}
|
|
57
58
|
mapHumanMessage(item) {
|
|
58
|
-
if (
|
|
59
|
+
if (isChatMessageEmpty(item)) {
|
|
59
60
|
throw new Error('User message content is empty');
|
|
60
61
|
}
|
|
61
|
-
return {
|
|
62
|
+
return {
|
|
63
|
+
role: 'user',
|
|
64
|
+
content: extractChatMessageText(item, {
|
|
65
|
+
supportedImageMimeTypes: [],
|
|
66
|
+
supportedDocumentMimeTypes: [],
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
62
69
|
}
|
|
63
70
|
mapBotMessage(item) {
|
|
64
71
|
if (!item.text) {
|
|
@@ -8,8 +8,26 @@ import 'uuid';
|
|
|
8
8
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
9
9
|
import { safeJsonParse } from '../../../feature/chat-bot/safeJsonParse.js';
|
|
10
10
|
import { extractChatMessageText } from '../../../feature/chat-bot/extractChatMessageText.js';
|
|
11
|
+
import { isChatMessageEmpty } from '../../../feature/chat-bot/isChatMessageEmpty.js';
|
|
11
12
|
import { GoogleGenAI } from '@google/genai';
|
|
12
13
|
|
|
14
|
+
const GOOGLE_SUPPORTED_IMAGE_MIME_TYPES = [
|
|
15
|
+
'image/png',
|
|
16
|
+
'image/jpeg',
|
|
17
|
+
'image/webp',
|
|
18
|
+
'image/heic',
|
|
19
|
+
'image/heif',
|
|
20
|
+
];
|
|
21
|
+
const GOOGLE_SUPPORTED_DOCUMENT_MIME_TYPES = [
|
|
22
|
+
'application/pdf',
|
|
23
|
+
'text/plain',
|
|
24
|
+
'text/csv',
|
|
25
|
+
'text/html',
|
|
26
|
+
'text/markdown',
|
|
27
|
+
'text/xml',
|
|
28
|
+
'text/rtf',
|
|
29
|
+
'application/json',
|
|
30
|
+
];
|
|
13
31
|
let GoogleChatAdapter = class GoogleChatAdapter {
|
|
14
32
|
ai;
|
|
15
33
|
logger = new Logger('wabot:google-chat-adapter-v2');
|
|
@@ -46,10 +64,39 @@ let GoogleChatAdapter = class GoogleChatAdapter {
|
|
|
46
64
|
return contents;
|
|
47
65
|
}
|
|
48
66
|
mapHumanMessage(item) {
|
|
49
|
-
if (
|
|
67
|
+
if (isChatMessageEmpty(item)) {
|
|
50
68
|
throw new Error('User message content is empty');
|
|
51
69
|
}
|
|
52
|
-
|
|
70
|
+
const parts = [];
|
|
71
|
+
parts.push({
|
|
72
|
+
text: extractChatMessageText(item, {
|
|
73
|
+
supportedImageMimeTypes: GOOGLE_SUPPORTED_IMAGE_MIME_TYPES,
|
|
74
|
+
supportedDocumentMimeTypes: GOOGLE_SUPPORTED_DOCUMENT_MIME_TYPES,
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
if (item.images) {
|
|
78
|
+
for (const image of item.images) {
|
|
79
|
+
if (!GOOGLE_SUPPORTED_IMAGE_MIME_TYPES.includes(image.mimeType))
|
|
80
|
+
continue;
|
|
81
|
+
parts.push(this.toGoogleFilePart(image));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (item.documents) {
|
|
85
|
+
for (const doc of item.documents) {
|
|
86
|
+
if (!GOOGLE_SUPPORTED_DOCUMENT_MIME_TYPES.includes(doc.mimeType))
|
|
87
|
+
continue;
|
|
88
|
+
parts.push(this.toGoogleFilePart(doc));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { role: 'user', parts };
|
|
92
|
+
}
|
|
93
|
+
toGoogleFilePart(file) {
|
|
94
|
+
if (file.publicUrl) {
|
|
95
|
+
return { fileData: { fileUri: file.publicUrl, mimeType: file.mimeType } };
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
inlineData: { data: stripDataUrlPrefix(file.base64Url), mimeType: file.mimeType },
|
|
99
|
+
};
|
|
53
100
|
}
|
|
54
101
|
mapBotMessage(item) {
|
|
55
102
|
if (!item.text) {
|
|
@@ -144,5 +191,9 @@ GoogleChatAdapter = __decorate([
|
|
|
144
191
|
singleton(),
|
|
145
192
|
__metadata("design:paramtypes", [Env])
|
|
146
193
|
], GoogleChatAdapter);
|
|
194
|
+
function stripDataUrlPrefix(dataUrl) {
|
|
195
|
+
const commaIndex = dataUrl.indexOf(',');
|
|
196
|
+
return commaIndex >= 0 && dataUrl.startsWith('data:') ? dataUrl.slice(commaIndex + 1) : dataUrl;
|
|
197
|
+
}
|
|
147
198
|
|
|
148
199
|
export { GoogleChatAdapter };
|
|
@@ -5,9 +5,17 @@ import 'uuid';
|
|
|
5
5
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
6
6
|
import '../../../core/error/setupErrorHandlers.js';
|
|
7
7
|
import { extractChatMessageText } from '../../../feature/chat-bot/extractChatMessageText.js';
|
|
8
|
+
import { isChatMessageEmpty } from '../../../feature/chat-bot/isChatMessageEmpty.js';
|
|
8
9
|
import { Logger } from '../../../core/logger/Logger.js';
|
|
9
10
|
import { OpenAI } from 'openai';
|
|
10
11
|
|
|
12
|
+
const OPENAI_SUPPORTED_IMAGE_MIME_TYPES = [
|
|
13
|
+
'image/png',
|
|
14
|
+
'image/jpeg',
|
|
15
|
+
'image/webp',
|
|
16
|
+
'image/gif',
|
|
17
|
+
];
|
|
18
|
+
const OPENAI_SUPPORTED_DOCUMENT_MIME_TYPES = ['application/pdf'];
|
|
11
19
|
let OpenaiChatAdapter = class OpenaiChatAdapter {
|
|
12
20
|
openai = new OpenAI();
|
|
13
21
|
logger = new Logger('wabot:openai-chat-adapter');
|
|
@@ -41,11 +49,21 @@ let OpenaiChatAdapter = class OpenaiChatAdapter {
|
|
|
41
49
|
return openIaInput;
|
|
42
50
|
}
|
|
43
51
|
mapConectionMessage(item) {
|
|
52
|
+
if (isChatMessageEmpty(item)) {
|
|
53
|
+
throw new Error('User message content is empty');
|
|
54
|
+
}
|
|
44
55
|
const content = [];
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
content.push({
|
|
57
|
+
type: 'input_text',
|
|
58
|
+
text: extractChatMessageText(item, {
|
|
59
|
+
supportedImageMimeTypes: OPENAI_SUPPORTED_IMAGE_MIME_TYPES,
|
|
60
|
+
supportedDocumentMimeTypes: OPENAI_SUPPORTED_DOCUMENT_MIME_TYPES,
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
47
63
|
if (item.images) {
|
|
48
64
|
for (const image of item.images) {
|
|
65
|
+
if (!OPENAI_SUPPORTED_IMAGE_MIME_TYPES.includes(image.mimeType))
|
|
66
|
+
continue;
|
|
49
67
|
content.push({
|
|
50
68
|
type: 'input_image',
|
|
51
69
|
image_url: image.publicUrl ?? image.base64Url,
|
|
@@ -53,8 +71,21 @@ let OpenaiChatAdapter = class OpenaiChatAdapter {
|
|
|
53
71
|
});
|
|
54
72
|
}
|
|
55
73
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
74
|
+
if (item.documents) {
|
|
75
|
+
for (const doc of item.documents) {
|
|
76
|
+
if (!OPENAI_SUPPORTED_DOCUMENT_MIME_TYPES.includes(doc.mimeType))
|
|
77
|
+
continue;
|
|
78
|
+
if (doc.publicUrl) {
|
|
79
|
+
content.push({ type: 'input_file', file_url: doc.publicUrl });
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
content.push({
|
|
83
|
+
type: 'input_file',
|
|
84
|
+
file_data: doc.base64Url,
|
|
85
|
+
filename: doc.name ?? `${doc.id}.pdf`,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
58
89
|
}
|
|
59
90
|
return { role: 'user', content };
|
|
60
91
|
}
|
|
@@ -7,8 +7,16 @@ import 'uuid';
|
|
|
7
7
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
8
8
|
import '../../../core/error/setupErrorHandlers.js';
|
|
9
9
|
import { extractChatMessageText } from '../../../feature/chat-bot/extractChatMessageText.js';
|
|
10
|
+
import { isChatMessageEmpty } from '../../../feature/chat-bot/isChatMessageEmpty.js';
|
|
10
11
|
import { OpenRouter } from '@openrouter/sdk';
|
|
11
12
|
|
|
13
|
+
const OPENROUTER_SUPPORTED_IMAGE_MIME_TYPES = [
|
|
14
|
+
'image/png',
|
|
15
|
+
'image/jpeg',
|
|
16
|
+
'image/webp',
|
|
17
|
+
'image/gif',
|
|
18
|
+
];
|
|
19
|
+
const OPENROUTER_SUPPORTED_DOCUMENT_MIME_TYPES = ['application/pdf'];
|
|
12
20
|
let OpenRouterChatAdapter = class OpenRouterChatAdapter {
|
|
13
21
|
env;
|
|
14
22
|
openRouter;
|
|
@@ -51,19 +59,31 @@ let OpenRouterChatAdapter = class OpenRouterChatAdapter {
|
|
|
51
59
|
return messages;
|
|
52
60
|
}
|
|
53
61
|
mapHumanMessage(item) {
|
|
62
|
+
if (isChatMessageEmpty(item)) {
|
|
63
|
+
throw new Error('User message content is empty');
|
|
64
|
+
}
|
|
54
65
|
const contentParts = [];
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
contentParts.push(extractChatMessageText(item, {
|
|
67
|
+
supportedImageMimeTypes: OPENROUTER_SUPPORTED_IMAGE_MIME_TYPES,
|
|
68
|
+
supportedDocumentMimeTypes: OPENROUTER_SUPPORTED_DOCUMENT_MIME_TYPES,
|
|
69
|
+
}));
|
|
57
70
|
if (item.images) {
|
|
58
71
|
for (const image of item.images) {
|
|
72
|
+
if (!OPENROUTER_SUPPORTED_IMAGE_MIME_TYPES.includes(image.mimeType))
|
|
73
|
+
continue;
|
|
59
74
|
const imageUrl = image.publicUrl ?? image.base64Url;
|
|
60
|
-
if (imageUrl)
|
|
75
|
+
if (imageUrl)
|
|
61
76
|
contentParts.push(imageUrl);
|
|
62
|
-
}
|
|
63
77
|
}
|
|
64
78
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
79
|
+
if (item.documents) {
|
|
80
|
+
for (const doc of item.documents) {
|
|
81
|
+
if (!OPENROUTER_SUPPORTED_DOCUMENT_MIME_TYPES.includes(doc.mimeType))
|
|
82
|
+
continue;
|
|
83
|
+
const docUrl = doc.publicUrl ?? doc.base64Url;
|
|
84
|
+
if (docUrl)
|
|
85
|
+
contentParts.push(docUrl);
|
|
86
|
+
}
|
|
67
87
|
}
|
|
68
88
|
return { role: 'user', content: contentParts.join('\n') };
|
|
69
89
|
}
|
|
@@ -10,6 +10,7 @@ import '../../../feature/pg/withPgClient.js';
|
|
|
10
10
|
import '../../../feature/pg/pgStorage.js';
|
|
11
11
|
import { Chat } from '../../../feature/chat-bot/Chat.js';
|
|
12
12
|
import '../../../feature/chat-bot/ChatBot.js';
|
|
13
|
+
import { ChatOperator } from '../../../feature/chat-bot/ChatOperator.js';
|
|
13
14
|
import 'uuid';
|
|
14
15
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
15
16
|
import '../../../core/error/setupErrorHandlers.js';
|
|
@@ -25,7 +26,7 @@ let PgChatRepository = class PgChatRepository extends PgCrudRepository {
|
|
|
25
26
|
async findByConnection(query) {
|
|
26
27
|
const sql = `
|
|
27
28
|
SELECT ${this.columns}
|
|
28
|
-
FROM ${this.table}
|
|
29
|
+
FROM ${this.table}
|
|
29
30
|
WHERE data->'connections' @> $1::jsonb
|
|
30
31
|
LIMIT 1
|
|
31
32
|
`;
|
|
@@ -35,6 +36,13 @@ let PgChatRepository = class PgChatRepository extends PgCrudRepository {
|
|
|
35
36
|
async findMemory(chatId) {
|
|
36
37
|
return new PgChatMemory(this.pool, chatId);
|
|
37
38
|
}
|
|
39
|
+
async findOperator(chatId) {
|
|
40
|
+
const chat = await this.find(chatId);
|
|
41
|
+
if (!chat)
|
|
42
|
+
return null;
|
|
43
|
+
const memory = new PgChatMemory(this.pool, chatId);
|
|
44
|
+
return new ChatOperator(chat, memory, this);
|
|
45
|
+
}
|
|
38
46
|
};
|
|
39
47
|
PgChatRepository = __decorate([
|
|
40
48
|
singleton(),
|
|
@@ -2,6 +2,10 @@ import { __decorate } from 'tslib';
|
|
|
2
2
|
import { v4 } from 'uuid';
|
|
3
3
|
import { RamChatMemory } from './RamChatMemory.js';
|
|
4
4
|
import { singleton } from '../../../core/injection/index.js';
|
|
5
|
+
import '../../../feature/chat-bot/ChatBot.js';
|
|
6
|
+
import { ChatOperator } from '../../../feature/chat-bot/ChatOperator.js';
|
|
7
|
+
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
8
|
+
import '../../../core/error/setupErrorHandlers.js';
|
|
5
9
|
|
|
6
10
|
let RamChatRepository = class RamChatRepository {
|
|
7
11
|
items = [];
|
|
@@ -36,6 +40,15 @@ let RamChatRepository = class RamChatRepository {
|
|
|
36
40
|
}
|
|
37
41
|
return Promise.resolve(memory.memory);
|
|
38
42
|
}
|
|
43
|
+
async findOperator(chatId) {
|
|
44
|
+
const chat = this.items.find((item) => item.id === chatId) ?? null;
|
|
45
|
+
if (!chat)
|
|
46
|
+
return null;
|
|
47
|
+
const memory = this.getMemory(chatId);
|
|
48
|
+
if (!memory)
|
|
49
|
+
return null;
|
|
50
|
+
return new ChatOperator(chat, memory.memory, this);
|
|
51
|
+
}
|
|
39
52
|
getMemory(chatId) {
|
|
40
53
|
return this.memories.find((r) => r.chatId === chatId) ?? null;
|
|
41
54
|
}
|
|
@@ -33,20 +33,40 @@ class Chat extends Entity {
|
|
|
33
33
|
}
|
|
34
34
|
this.data.connections.push(connection);
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
removeConnection(connection) {
|
|
37
|
+
const index = this.data.connections.findIndex((c) => c.channelName === connection.channelName && c.id === connection.id);
|
|
38
|
+
if (index === -1) {
|
|
39
|
+
throw new Error('Connection does not exist');
|
|
40
|
+
}
|
|
41
|
+
this.data.connections.splice(index, 1);
|
|
42
|
+
}
|
|
43
|
+
hasAssociation(association) {
|
|
44
|
+
return this.data.associations?.some((a) => a.type === association.type && a.id === association.id) ?? false;
|
|
45
|
+
}
|
|
46
|
+
hasAssociations(type) {
|
|
47
|
+
return this.data.associations?.some((a) => a.type === type) ?? false;
|
|
38
48
|
}
|
|
39
49
|
getAssociationsByType(type) {
|
|
40
50
|
return this.data.associations?.filter((a) => a.type === type) ?? [];
|
|
41
51
|
}
|
|
42
52
|
addAssociation(association) {
|
|
43
|
-
if (this.hasAssociation(association
|
|
53
|
+
if (this.hasAssociation(association)) {
|
|
44
54
|
throw new Error('Association already exists');
|
|
45
55
|
}
|
|
46
56
|
if (!this.data.associations)
|
|
47
57
|
this.data.associations = [];
|
|
48
58
|
this.data.associations.push(association);
|
|
49
59
|
}
|
|
60
|
+
removeAssociation(association) {
|
|
61
|
+
if (!this.data.associations) {
|
|
62
|
+
throw new Error('Association does not exist');
|
|
63
|
+
}
|
|
64
|
+
const index = this.data.associations.findIndex((a) => a.type === association.type && a.id === association.id);
|
|
65
|
+
if (index === -1) {
|
|
66
|
+
throw new Error('Association does not exist');
|
|
67
|
+
}
|
|
68
|
+
this.data.associations.splice(index, 1);
|
|
69
|
+
}
|
|
50
70
|
validatePrivateChat() {
|
|
51
71
|
if (this.data.connections.length < 1) {
|
|
52
72
|
throw new Error('PRIVATE chat should have one or more connections');
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ChatItem } from './ChatItem.js';
|
|
2
|
+
|
|
3
|
+
class ChatOperator {
|
|
4
|
+
chat;
|
|
5
|
+
memory;
|
|
6
|
+
repository;
|
|
7
|
+
constructor(chat, memory, repository) {
|
|
8
|
+
this.chat = chat;
|
|
9
|
+
this.memory = memory;
|
|
10
|
+
this.repository = repository;
|
|
11
|
+
}
|
|
12
|
+
async saveHumanMessage(message) {
|
|
13
|
+
const item = new ChatItem({ type: 'humanMessage', humanMessage: message });
|
|
14
|
+
await this.memory.create(item);
|
|
15
|
+
return item;
|
|
16
|
+
}
|
|
17
|
+
async saveBotMessage(message) {
|
|
18
|
+
const item = new ChatItem({ type: 'botMessage', botMessage: message });
|
|
19
|
+
await this.memory.create(item);
|
|
20
|
+
return item;
|
|
21
|
+
}
|
|
22
|
+
getConnections() {
|
|
23
|
+
return this.chat.connections;
|
|
24
|
+
}
|
|
25
|
+
async addConnection(connection) {
|
|
26
|
+
this.chat.addConnection(connection);
|
|
27
|
+
await this.repository.update(this.chat);
|
|
28
|
+
}
|
|
29
|
+
async removeConnection(connection) {
|
|
30
|
+
this.chat.removeConnection(connection);
|
|
31
|
+
await this.repository.update(this.chat);
|
|
32
|
+
}
|
|
33
|
+
hasAssociations(type) {
|
|
34
|
+
return this.chat.hasAssociations(type);
|
|
35
|
+
}
|
|
36
|
+
hasAssociation(association) {
|
|
37
|
+
return this.chat.hasAssociation(association);
|
|
38
|
+
}
|
|
39
|
+
findAssociations(type) {
|
|
40
|
+
if (type === undefined)
|
|
41
|
+
return this.chat.associations;
|
|
42
|
+
return this.chat.getAssociationsByType(type);
|
|
43
|
+
}
|
|
44
|
+
async addAssociation(association) {
|
|
45
|
+
this.chat.addAssociation(association);
|
|
46
|
+
await this.repository.update(this.chat);
|
|
47
|
+
}
|
|
48
|
+
async removeAssociation(association) {
|
|
49
|
+
this.chat.removeAssociation(association);
|
|
50
|
+
await this.repository.update(this.chat);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { ChatOperator };
|
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
function extractChatMessageText(message) {
|
|
1
|
+
function extractChatMessageText(message, options = {}) {
|
|
2
2
|
const messageData = {
|
|
3
3
|
senderId: message.senderId,
|
|
4
4
|
senderName: message.senderName,
|
|
5
5
|
text: message.text,
|
|
6
6
|
object: message.object,
|
|
7
7
|
metadata: message.metadata,
|
|
8
|
-
images: message.images?.map((x) => ({
|
|
8
|
+
images: message.images?.map((x) => ({
|
|
9
|
+
id: x.id,
|
|
10
|
+
name: x.name,
|
|
11
|
+
mimeType: x.mimeType,
|
|
12
|
+
notAnalyzed: isAnalyzed(x.mimeType, options.supportedImageMimeTypes) ? undefined : true,
|
|
13
|
+
})),
|
|
14
|
+
documents: message.documents?.map((x) => ({
|
|
15
|
+
id: x.id,
|
|
16
|
+
name: x.name,
|
|
17
|
+
mimeType: x.mimeType,
|
|
18
|
+
notAnalyzed: isAnalyzed(x.mimeType, options.supportedDocumentMimeTypes) ? undefined : true,
|
|
19
|
+
})),
|
|
9
20
|
};
|
|
10
21
|
return JSON.stringify(messageData);
|
|
11
22
|
}
|
|
23
|
+
function isAnalyzed(mimeType, supported) {
|
|
24
|
+
if (supported === undefined)
|
|
25
|
+
return true;
|
|
26
|
+
return supported.includes(mimeType);
|
|
27
|
+
}
|
|
12
28
|
|
|
13
29
|
export { extractChatMessageText };
|
|
@@ -4,13 +4,15 @@ import { Mindset } from './IMindset.js';
|
|
|
4
4
|
import { MindsetMetadataStore } from './metadata/MindsetMetadataStore.js';
|
|
5
5
|
import { validateModel } from '../../core/validation/core/validateModel.js';
|
|
6
6
|
import '../../core/validation/metadata/ValidationMetadataStore.js';
|
|
7
|
-
import { CustomError } from '../../core/error/CustomError.js';
|
|
7
|
+
import { CustomError, errorToPlainObject } from '../../core/error/CustomError.js';
|
|
8
8
|
import '../../core/error/setupErrorHandlers.js';
|
|
9
|
+
import { Logger } from '../../core/logger/Logger.js';
|
|
9
10
|
import { Container } from '../../core/injection/Container.js';
|
|
10
11
|
|
|
11
12
|
let MindsetOperator = class MindsetOperator {
|
|
12
13
|
mindset;
|
|
13
14
|
container;
|
|
15
|
+
logger = new Logger('wabot:mindset-operator');
|
|
14
16
|
metadata;
|
|
15
17
|
constructor(mindset, container, metadataStore) {
|
|
16
18
|
this.mindset = mindset;
|
|
@@ -139,7 +141,14 @@ let MindsetOperator = class MindsetOperator {
|
|
|
139
141
|
return await this.functionResponseToString(response);
|
|
140
142
|
}
|
|
141
143
|
catch (error) {
|
|
142
|
-
|
|
144
|
+
const aiResponse = await this.functionErrorToString(error);
|
|
145
|
+
if (error instanceof Error) {
|
|
146
|
+
this.logger.error(`Function '${name}' threw an exception`, error, { aiResponse });
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.logger.error(`Function '${name}' threw a non-Error value`, { error, aiResponse });
|
|
150
|
+
}
|
|
151
|
+
return aiResponse;
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
154
|
async functionResponseToString(response) {
|
|
@@ -181,6 +190,10 @@ let MindsetOperator = class MindsetOperator {
|
|
|
181
190
|
body: typeof data === 'object' ? data : { message: data?.toString?.() || 'Unknown error' },
|
|
182
191
|
});
|
|
183
192
|
}
|
|
193
|
+
if (error instanceof Error) {
|
|
194
|
+
const { stack: _stack, ...plain } = errorToPlainObject(error);
|
|
195
|
+
return JSON.stringify(plain);
|
|
196
|
+
}
|
|
184
197
|
if (error?.message) {
|
|
185
198
|
return error.message;
|
|
186
199
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { generate } from 'short-uuid';
|
|
2
2
|
import { PgRepositoryBase } from './PgRepositoryBase.js';
|
|
3
3
|
import { CustomError } from '../../core/error/CustomError.js';
|
|
4
4
|
import '../../core/error/setupErrorHandlers.js';
|
|
@@ -54,7 +54,7 @@ class PgCrudRepository extends PgRepositoryBase {
|
|
|
54
54
|
if (item.wasCreated()) {
|
|
55
55
|
throw new Error('Item already created');
|
|
56
56
|
}
|
|
57
|
-
item['data'].id =
|
|
57
|
+
item['data'].id = generate();
|
|
58
58
|
item['data'].createdAt = new Date().getTime();
|
|
59
59
|
item.validate();
|
|
60
60
|
const sql = `
|
package/dist/src/index.d.ts
CHANGED
|
@@ -678,12 +678,15 @@ declare class Chat extends Entity<IChatData> {
|
|
|
678
678
|
id: string;
|
|
679
679
|
} | null;
|
|
680
680
|
addConnection(connection: IChatConnection): void;
|
|
681
|
-
|
|
681
|
+
removeConnection(connection: IChatConnection): void;
|
|
682
|
+
hasAssociation(association: IChatAssociation): boolean;
|
|
683
|
+
hasAssociations(type: string): boolean;
|
|
682
684
|
getAssociationsByType(type: string): {
|
|
683
685
|
type: string;
|
|
684
686
|
id: string;
|
|
685
687
|
}[];
|
|
686
688
|
addAssociation(association: IChatAssociation): void;
|
|
689
|
+
removeAssociation(association: IChatAssociation): void;
|
|
687
690
|
private validatePrivateChat;
|
|
688
691
|
private validateGroupChat;
|
|
689
692
|
validate(): void;
|
|
@@ -805,6 +808,7 @@ interface IMindsetTool {
|
|
|
805
808
|
declare class MindsetOperator implements IMindset {
|
|
806
809
|
private mindset;
|
|
807
810
|
private container;
|
|
811
|
+
private logger;
|
|
808
812
|
private metadata;
|
|
809
813
|
constructor(mindset: Mindset, container: Container, metadataStore: MindsetMetadataStore);
|
|
810
814
|
context(): Promise<string>;
|
|
@@ -822,27 +826,32 @@ declare class MindsetOperator implements IMindset {
|
|
|
822
826
|
functionErrorToString(error: any): Promise<string>;
|
|
823
827
|
}
|
|
824
828
|
|
|
825
|
-
interface
|
|
829
|
+
interface IChatMessagesPublicFile {
|
|
826
830
|
name?: string;
|
|
827
831
|
publicUrl: string;
|
|
828
832
|
base64Url?: undefined;
|
|
829
833
|
mimeType: string;
|
|
830
834
|
id: string;
|
|
831
835
|
}
|
|
832
|
-
interface
|
|
836
|
+
interface IChatMessagesPrivateFile {
|
|
833
837
|
name?: string;
|
|
834
838
|
publicUrl?: undefined;
|
|
835
839
|
base64Url: string;
|
|
836
840
|
mimeType: string;
|
|
837
841
|
id: string;
|
|
838
842
|
}
|
|
839
|
-
type
|
|
843
|
+
type IChatMessageFile = IChatMessagesPrivateFile | IChatMessagesPublicFile;
|
|
844
|
+
|
|
845
|
+
type IChatMessageDocument = IChatMessageFile;
|
|
846
|
+
|
|
847
|
+
type IChatMessageImage = IChatMessageFile;
|
|
840
848
|
|
|
841
849
|
interface IChatMessage {
|
|
842
850
|
senderId?: string;
|
|
843
851
|
senderName?: string;
|
|
844
852
|
text?: string;
|
|
845
853
|
images?: IChatMessageImage[];
|
|
854
|
+
documents?: IChatMessageDocument[];
|
|
846
855
|
object?: object;
|
|
847
856
|
metadata?: Record<string, string>;
|
|
848
857
|
}
|
|
@@ -938,6 +947,24 @@ interface IChatRepository {
|
|
|
938
947
|
update(chat: Chat): Promise<void>;
|
|
939
948
|
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
940
949
|
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
950
|
+
findOperator(chatId: string): Promise<ChatOperator | null>;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
declare class ChatOperator {
|
|
954
|
+
private chat;
|
|
955
|
+
private memory;
|
|
956
|
+
private repository;
|
|
957
|
+
constructor(chat: Chat, memory: IChatMemory, repository: IChatRepository);
|
|
958
|
+
saveHumanMessage(message: IChatMessage): Promise<ChatItem>;
|
|
959
|
+
saveBotMessage(message: IChatMessage): Promise<ChatItem>;
|
|
960
|
+
getConnections(): IChatConnection[];
|
|
961
|
+
addConnection(connection: IChatConnection): Promise<void>;
|
|
962
|
+
removeConnection(connection: IChatConnection): Promise<void>;
|
|
963
|
+
hasAssociations(type: string): boolean;
|
|
964
|
+
hasAssociation(association: IChatAssociation): boolean;
|
|
965
|
+
findAssociations(type?: string): IChatAssociation[];
|
|
966
|
+
addAssociation(association: IChatAssociation): Promise<void>;
|
|
967
|
+
removeAssociation(association: IChatAssociation): Promise<void>;
|
|
941
968
|
}
|
|
942
969
|
|
|
943
970
|
declare class ChatRepository implements IChatRepository {
|
|
@@ -945,6 +972,7 @@ declare class ChatRepository implements IChatRepository {
|
|
|
945
972
|
update(chat: Chat): Promise<void>;
|
|
946
973
|
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
947
974
|
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
975
|
+
findOperator(chatId: string): Promise<ChatOperator | null>;
|
|
948
976
|
}
|
|
949
977
|
|
|
950
978
|
declare function chatBot(mindset: IConstructor<IMindset>): (target: object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -963,7 +991,13 @@ declare class ChatBotMetadataStore {
|
|
|
963
991
|
|
|
964
992
|
declare function safeJsonParse<T = unknown>(json: string | undefined | null, context?: string): T;
|
|
965
993
|
|
|
966
|
-
|
|
994
|
+
interface IExtractChatMessageTextOptions {
|
|
995
|
+
supportedImageMimeTypes?: readonly string[];
|
|
996
|
+
supportedDocumentMimeTypes?: readonly string[];
|
|
997
|
+
}
|
|
998
|
+
declare function extractChatMessageText(message: IChatMessage, options?: IExtractChatMessageTextOptions): string;
|
|
999
|
+
|
|
1000
|
+
declare function isChatMessageEmpty(message: IChatMessage): boolean;
|
|
967
1001
|
|
|
968
1002
|
interface IchatControllerConfig {
|
|
969
1003
|
}
|
|
@@ -1513,6 +1547,8 @@ declare class AnthropicChatAdapter implements IChatAdapter {
|
|
|
1513
1547
|
nextItems(req: IChatAdapterNextItemsReq): Promise<IChatAdapterNextItemsRes>;
|
|
1514
1548
|
private mapChatItems;
|
|
1515
1549
|
private mapHumanMessage;
|
|
1550
|
+
private toAnthropicImageSource;
|
|
1551
|
+
private toAnthropicDocumentSource;
|
|
1516
1552
|
private mapBotMessage;
|
|
1517
1553
|
private mapFunctionCall;
|
|
1518
1554
|
private mapTool;
|
|
@@ -1542,6 +1578,7 @@ declare class GoogleChatAdapter implements IChatAdapter {
|
|
|
1542
1578
|
nextItems(req: IChatAdapterNextItemsReq): Promise<IChatAdapterNextItemsRes>;
|
|
1543
1579
|
private mapChatItems;
|
|
1544
1580
|
private mapHumanMessage;
|
|
1581
|
+
private toGoogleFilePart;
|
|
1545
1582
|
private mapBotMessage;
|
|
1546
1583
|
private mapFunctionCall;
|
|
1547
1584
|
private mapTool;
|
|
@@ -1578,6 +1615,7 @@ declare class PgChatRepository extends PgCrudRepository<Chat> implements IChatRe
|
|
|
1578
1615
|
constructor(pool: Pool);
|
|
1579
1616
|
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
1580
1617
|
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
1618
|
+
findOperator(chatId: string): Promise<ChatOperator | null>;
|
|
1581
1619
|
}
|
|
1582
1620
|
|
|
1583
1621
|
declare class PgChatMemory extends PgCrudRepository<ChatItem> implements IChatMemory {
|
|
@@ -1600,6 +1638,7 @@ declare class RamChatRepository implements IChatRepository {
|
|
|
1600
1638
|
create(chat: Chat): Promise<void>;
|
|
1601
1639
|
findByConnection(query: IChatConnection): Promise<Chat | null>;
|
|
1602
1640
|
findMemory(chatId: string): Promise<IChatMemory | null>;
|
|
1641
|
+
findOperator(chatId: string): Promise<ChatOperator | null>;
|
|
1603
1642
|
private getMemory;
|
|
1604
1643
|
}
|
|
1605
1644
|
|
|
@@ -2178,4 +2217,4 @@ declare function HtmlModule(options: IHtmlModuleOptions): {
|
|
|
2178
2217
|
new (): {};
|
|
2179
2218
|
};
|
|
2180
2219
|
|
|
2181
|
-
export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, Async, AsyncMetadataStore, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, type ClientMap, CmdChannel, Container, ControllerMetadataStore, CronJob, CronJobRepository, CustomError, DeepSeekChatAdapter, DescriptionMetadataStore, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, type ErrorSeverity, ExpressProvider, GoogleChatAdapter, type GoogleChatAdapterV2Options, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemsReq, type IChatAdapterNextItemsRes, type IChatAssociation, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICmdChannelMessage, type ICmdReceivedMessage, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICronConfig, type ICronJobData, type ICrudRepository, type ICustomErrorData, type IDescriptionMetadata, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IErrorHandlersConfig, type IErrorMonitor, type IErrorMonitorContext, type IFunctionCall, type IFunctionCallItem, type IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHandshakeMiddleware, type IHandshakeMiddlewareMetadata, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobRepository, type IJwtRefreshTokenData, type IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type ILockKey, type ILocker, type ILockerKey, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetConfig, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IPersistentData, type IPgRepositoryConfig, type IPropertyValidatorInfo, type IReceivedMessage, type IRemoteApiKeyFetcher, type IRestControllerConfig, type IRestControllerMetadata, type IScheduleAt, type IScheduleDelay, type ISendByWasenderRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelMessage, type ISocketChannelReceivedMessage, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, type ISocketReceivedMessage, type IStorableData, type ITelegramChannelConfig, type ITelegramChannelMessage, type ITelegramReceivedMessage, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateInputShape, type IValidateIsInOptions, type IValidateIsRecordOptions, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWasenderChannelMessageListener, type IWasenderDeviceListMetadata, type IWasenderEvent, type IWasenderMessageContent, type IWasenderMessageContextInfo, type IWasenderMessageKey, type IWasenderMessageReceivedData, type IWasenderMessageReceivedEvent, type IWasenderQrUpdatedEvent, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppByWasenderChannelConfig, type IWhatsAppByWasenderReceivedMessage, type IWhatsAppChannelMessage, type IWhatsAppCloudContact, type IWhatsAppCloudMessage, type IWhatsAppCloudMessageMetadata, type IWhatsAppCloudTemplate, type IWhatsAppCloudTemplateComponent, type IWhatsAppCloudTemplateMessage, type IWhatsAppCloudTemplateParameter, type IWhatsAppCloudTemplateResponse, type IWhatsAppCloudWebhookPayload, type IWhatsAppData, type IWhatsAppMessageListener, type IWhatsAppProxyListenMessageEventData, type IWhatsAppProxyListenMessageEventReq, type IWhatsAppProxyMessage, type IWhatsAppProxyMessageContent, type IWhatsAppProxyMessageEventReq, type IWhatsAppProxySendMessageEventReq, type IWhatsAppReceivedMessage, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtHandshakeGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Locker, Logger, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenRouterChatAdapter, OpenaiChatAdapter, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCronJobRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgLockKey, PgLocker, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RemoteApiKeyRepository, RestControllerMetadataStore, RestRequest, SocketChannel, SocketChannelConfig, SocketChannelReceivedMessage, SocketControllerMetadataStore, SocketServerConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT, WabotChatAdapter, WasenderWebhookController, WhatsApp, WhatsAppByWasenderChannel, WhatsAppByWasenderChannelConfig, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByCloudApi, WhatsAppReceiverByWabotProxy, WhatsAppReceiverByWasender, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByWabotProxy, WhatsAppSenderByWasender, WhatsAppWabotProxyConnection, WhatsappChannelConfig, apiKeyGuard, apiKeyHandshakeGuard, chatBot, chatController, chatItemTypeOptions, cmd, cmdChannelName, command, commandHandler, container, cron, description, errorToPlainObject, extractChatMessageText, extractNumberFromWasenderMessageKey, getClientMap, getPgClient, handshakeMiddlewares, inject, injectable, isArray, isBoolean, isDate, isIn, isModel, isNotEmpty, isNumber, isOptional, isPresent, isRecord, isString, jwtGuard, jwtHandshakeGuard, max, middleware, min, mindset, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, onSocketEvent, pgStorage, readJsonFromFile, restController, runChatControllers, runCommandHandlers, runCronHandlers, runRestControllers, runSocketControllers, safeJsonParse, scoped, setupErrorHandlers, singleton, socket, socketChannelName, socketController, stopCommandHandlers, stopCronHandlers, telegram, telegramChannelName, validateAndTransform, validateArray, validateIsBoolean, validateIsDate, validateIsIn, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsRecord, validateIsString, validateMax, validateMin, validateModel, whatsApp, whatsAppByWasender, whatsAppByWasenderChannelName, whatsAppChannelName, withPgClient, withPgTransaction, writeJsonToFile };
|
|
2220
|
+
export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, Async, AsyncMetadataStore, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatOperator, ChatRepository, ChatResolver, type ClientMap, CmdChannel, Container, ControllerMetadataStore, CronJob, CronJobRepository, CustomError, DeepSeekChatAdapter, DescriptionMetadataStore, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, type ErrorSeverity, ExpressProvider, GoogleChatAdapter, type GoogleChatAdapterV2Options, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemsReq, type IChatAdapterNextItemsRes, type IChatAssociation, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatMessageDocument, type IChatMessageFile, type IChatMessageImage, type IChatMessagesPrivateFile, type IChatMessagesPublicFile, type IChatRepository, type IChatType, type ICmdChannelMessage, type ICmdReceivedMessage, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICronConfig, type ICronJobData, type ICrudRepository, type ICustomErrorData, type IDescriptionMetadata, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IErrorHandlersConfig, type IErrorMonitor, type IErrorMonitorContext, type IExtractChatMessageTextOptions, type IFunctionCall, type IFunctionCallItem, type IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHandshakeMiddleware, type IHandshakeMiddlewareMetadata, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobRepository, type IJwtRefreshTokenData, type IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type ILockKey, type ILocker, type ILockerKey, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetConfig, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IPersistentData, type IPgRepositoryConfig, type IPropertyValidatorInfo, type IReceivedMessage, type IRemoteApiKeyFetcher, type IRestControllerConfig, type IRestControllerMetadata, type IScheduleAt, type IScheduleDelay, type ISendByWasenderRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelMessage, type ISocketChannelReceivedMessage, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, type ISocketReceivedMessage, type IStorableData, type ITelegramChannelConfig, type ITelegramChannelMessage, type ITelegramReceivedMessage, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateInputShape, type IValidateIsInOptions, type IValidateIsRecordOptions, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWasenderChannelMessageListener, type IWasenderDeviceListMetadata, type IWasenderEvent, type IWasenderMessageContent, type IWasenderMessageContextInfo, type IWasenderMessageKey, type IWasenderMessageReceivedData, type IWasenderMessageReceivedEvent, type IWasenderQrUpdatedEvent, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppByWasenderChannelConfig, type IWhatsAppByWasenderReceivedMessage, type IWhatsAppChannelMessage, type IWhatsAppCloudContact, type IWhatsAppCloudMessage, type IWhatsAppCloudMessageMetadata, type IWhatsAppCloudTemplate, type IWhatsAppCloudTemplateComponent, type IWhatsAppCloudTemplateMessage, type IWhatsAppCloudTemplateParameter, type IWhatsAppCloudTemplateResponse, type IWhatsAppCloudWebhookPayload, type IWhatsAppData, type IWhatsAppMessageListener, type IWhatsAppProxyListenMessageEventData, type IWhatsAppProxyListenMessageEventReq, type IWhatsAppProxyMessage, type IWhatsAppProxyMessageContent, type IWhatsAppProxyMessageEventReq, type IWhatsAppProxySendMessageEventReq, type IWhatsAppReceivedMessage, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtHandshakeGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Locker, Logger, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenRouterChatAdapter, OpenaiChatAdapter, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCronJobRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgLockKey, PgLocker, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RemoteApiKeyRepository, RestControllerMetadataStore, RestRequest, SocketChannel, SocketChannelConfig, SocketChannelReceivedMessage, SocketControllerMetadataStore, SocketServerConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT, WabotChatAdapter, WasenderWebhookController, WhatsApp, WhatsAppByWasenderChannel, WhatsAppByWasenderChannelConfig, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByCloudApi, WhatsAppReceiverByWabotProxy, WhatsAppReceiverByWasender, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByWabotProxy, WhatsAppSenderByWasender, WhatsAppWabotProxyConnection, WhatsappChannelConfig, apiKeyGuard, apiKeyHandshakeGuard, chatBot, chatController, chatItemTypeOptions, cmd, cmdChannelName, command, commandHandler, container, cron, description, errorToPlainObject, extractChatMessageText, extractNumberFromWasenderMessageKey, getClientMap, getPgClient, handshakeMiddlewares, inject, injectable, isArray, isBoolean, isChatMessageEmpty, isDate, isIn, isModel, isNotEmpty, isNumber, isOptional, isPresent, isRecord, isString, jwtGuard, jwtHandshakeGuard, max, middleware, min, mindset, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, onSocketEvent, pgStorage, readJsonFromFile, restController, runChatControllers, runCommandHandlers, runCronHandlers, runRestControllers, runSocketControllers, safeJsonParse, scoped, setupErrorHandlers, singleton, socket, socketChannelName, socketController, stopCommandHandlers, stopCronHandlers, telegram, telegramChannelName, validateAndTransform, validateArray, validateIsBoolean, validateIsDate, validateIsIn, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsRecord, validateIsString, validateMax, validateMin, validateModel, whatsApp, whatsAppByWasender, whatsAppByWasenderChannelName, whatsAppChannelName, withPgClient, withPgTransaction, writeJsonToFile };
|
package/dist/src/index.js
CHANGED
|
@@ -57,12 +57,14 @@ export { ChatAdapter } from './feature/chat-bot/ChatAdapter.js';
|
|
|
57
57
|
export { ChatBot } from './feature/chat-bot/ChatBot.js';
|
|
58
58
|
export { ChatItem } from './feature/chat-bot/ChatItem.js';
|
|
59
59
|
export { ChatMemory } from './feature/chat-bot/ChatMemory.js';
|
|
60
|
+
export { ChatOperator } from './feature/chat-bot/ChatOperator.js';
|
|
60
61
|
export { ChatRepository } from './feature/chat-bot/ChatRepository.js';
|
|
61
62
|
export { chatItemTypeOptions } from './feature/chat-bot/IChatItem.js';
|
|
62
63
|
export { chatBot } from './feature/chat-bot/metadata/@chatBot.js';
|
|
63
64
|
export { ChatBotMetadataStore } from './feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
64
65
|
export { safeJsonParse } from './feature/chat-bot/safeJsonParse.js';
|
|
65
66
|
export { extractChatMessageText } from './feature/chat-bot/extractChatMessageText.js';
|
|
67
|
+
export { isChatMessageEmpty } from './feature/chat-bot/isChatMessageEmpty.js';
|
|
66
68
|
export { chatController } from './feature/chat-controller/metadata/controller/@chatController.js';
|
|
67
69
|
export { ControllerMetadataStore } from './feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
68
70
|
export { ChatResolver } from './feature/chat-controller/ChatResolver.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wabot-dev/framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Framework for IA Chat Bots",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -35,11 +35,12 @@
|
|
|
35
35
|
"prettier": "^3.5.3",
|
|
36
36
|
"rollup": "^4.60.0",
|
|
37
37
|
"tsup": "^8.4.0",
|
|
38
|
-
"typescript": "
|
|
38
|
+
"typescript": "^6.0.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@anthropic-ai/sdk": "^0.60.0",
|
|
42
42
|
"@google/genai": "^1.16.0",
|
|
43
|
+
"@openrouter/sdk": "^0.12.2",
|
|
43
44
|
"@types/big.js": "^6.2.2",
|
|
44
45
|
"@types/debug": "^4.1.12",
|
|
45
46
|
"@types/express": "^5.0.1",
|
|
@@ -60,13 +61,12 @@
|
|
|
60
61
|
"openai": "^6.10.0",
|
|
61
62
|
"pg": "^8.15.6",
|
|
62
63
|
"reflect-metadata": "^0.2.2",
|
|
63
|
-
"short-uuid": "^
|
|
64
|
+
"short-uuid": "^6.0.3",
|
|
64
65
|
"socket.io": "^4.8.1",
|
|
65
66
|
"socket.io-client": "^4.8.1",
|
|
66
67
|
"tslib": "^2.8.1",
|
|
67
68
|
"tsyringe": "^4.9.1",
|
|
68
|
-
"uuid": "^
|
|
69
|
-
"wasenderapi": "^0.1.5"
|
|
70
|
-
"@openrouter/sdk": "^0.12.2"
|
|
69
|
+
"uuid": "^14.0.0",
|
|
70
|
+
"wasenderapi": "^0.1.5"
|
|
71
71
|
}
|
|
72
72
|
}
|