@ducci/jarvis 1.0.70 → 1.0.71
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/package.json
CHANGED
|
@@ -20,10 +20,28 @@ async function appendTelegramChatLog(chatId, sessionId, direction, text, ts = nu
|
|
|
20
20
|
await fs.promises.appendFile(logFile, line, 'utf8').catch(() => {});
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function escapeHtml(str) {
|
|
24
|
+
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function markdownToHtml(text) {
|
|
28
|
+
// 1. Block fences: ```[lang]\ncontent\n``` → <pre>content</pre>
|
|
29
|
+
text = text.replace(/```[\w]*\n([\s\S]*?)\n?```/g, (_, content) => {
|
|
30
|
+
return `<pre>${escapeHtml(content)}</pre>`;
|
|
31
|
+
});
|
|
32
|
+
// 2. Inline code: `content` → <code>content</code> (no newlines inside)
|
|
33
|
+
text = text.replace(/`([^`\n]+)`/g, (_, content) => {
|
|
34
|
+
return `<code>${escapeHtml(content)}</code>`;
|
|
35
|
+
});
|
|
36
|
+
return text;
|
|
37
|
+
}
|
|
38
|
+
|
|
23
39
|
async function sendMessage(api, chatId, text, sessionId) {
|
|
24
40
|
const MAX_TG = 4096;
|
|
25
41
|
// Telegram HTML mode does not support <br> — replace with newlines before sending
|
|
26
42
|
text = text.replace(/<br\s*\/?>/gi, '\n');
|
|
43
|
+
// Convert leftover Markdown code fences to HTML (model sometimes mixes both formats)
|
|
44
|
+
text = markdownToHtml(text);
|
|
27
45
|
const chunks = [];
|
|
28
46
|
for (let i = 0; i < text.length; i += MAX_TG) {
|
|
29
47
|
chunks.push(text.slice(i, i + MAX_TG));
|