levix-bot 4.6.0 → 4.8.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/README.md +12 -2
- package/app.cjs +32 -7
- package/package.json +2 -2
- package/public/dashboard/assets/index-B8E5IYlB.js +540 -0
- package/public/dashboard/assets/index-C5D4wzm4.css +2 -0
- package/public/dashboard/index.html +4 -3
- package/public/dashboard.css +152 -53
- package/public/gateway-i18n.js +295 -0
- package/public/gateway.js +30 -1
- package/public/ui-boot.js +71 -0
- package/src/bootstrap/core.js +9 -0
- package/src/commands/md.cjs +44 -0
- package/src/config/defaults.cjs +1 -0
- package/src/core/socket.js +23 -0
- package/src/db/store.cjs +8 -0
- package/src/diagnostics/crashReports.cjs +491 -0
- package/src/diagnostics/device.cjs +119 -0
- package/src/diagnostics/sanitize.cjs +90 -0
- package/src/handlers/command.handler.js +2 -1
- package/src/index.js +9 -1
- package/src/panel/feedback.cjs +13 -1
- package/src/routes/dashboard.api.esm.js +186 -15
- package/src/services/autoDelete.cjs +3 -1
- package/src/utils/logger.cjs +88 -34
- package/src/utils/markdownParser.cjs +208 -136
- package/src/utils/storage.cjs +1 -0
- package/src/utils/storage.esm.js +1 -0
- package/views/dashboard.ejs +2 -1
- package/views/login.ejs +102 -71
- package/views/qr.ejs +59 -30
- package/views/setup.ejs +34 -30
- package/public/dashboard/assets/index-Con1xdhN.js +0 -515
- package/public/dashboard/assets/index-De78KNvv.css +0 -2
|
@@ -1,161 +1,233 @@
|
|
|
1
|
+
// Markdown from any provider -> WhatsApp text. This is a display boundary:
|
|
2
|
+
// stored AI history, code contents, identifiers and URLs remain untouched.
|
|
1
3
|
const { tr } = require("./i18n.cjs");
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
if (tableLines.length < 2) return null;
|
|
28
|
-
|
|
29
|
-
const headers = cleanCells(tableLines[0]);
|
|
30
|
-
// Line 1 is usually the separator: |---|---|
|
|
31
|
-
const separatorLine = tableLines[1];
|
|
32
|
-
if (!/^[\s|:-]+$/.test(separatorLine)) return null;
|
|
33
|
-
|
|
34
|
-
const rows = [];
|
|
35
|
-
for (let i = 2; i < tableLines.length; i++) {
|
|
36
|
-
const line = tableLines[i].trim();
|
|
37
|
-
if (!line) continue;
|
|
38
|
-
rows.push(cleanCells(line));
|
|
5
|
+
/** Split table cells without splitting escaped pipes or pipes inside code. */
|
|
6
|
+
function tableCells(line) {
|
|
7
|
+
const cells = [];
|
|
8
|
+
let cell = "";
|
|
9
|
+
let ticks = 0;
|
|
10
|
+
const text = line.trim();
|
|
11
|
+
for (let i = 0; i < text.length; i++) {
|
|
12
|
+
if (text[i] === "\\" && text[i + 1] === "|") {
|
|
13
|
+
cell += "|";
|
|
14
|
+
i++;
|
|
15
|
+
} else if (text[i] === "`") {
|
|
16
|
+
let end = i + 1;
|
|
17
|
+
while (text[end] === "`") end++;
|
|
18
|
+
const run = end - i;
|
|
19
|
+
if (!ticks) ticks = run;
|
|
20
|
+
else if (ticks === run) ticks = 0;
|
|
21
|
+
cell += text.slice(i, end);
|
|
22
|
+
i = end - 1;
|
|
23
|
+
} else if (text[i] === "|" && !ticks) {
|
|
24
|
+
cells.push(cell.trim());
|
|
25
|
+
cell = "";
|
|
26
|
+
} else cell += text[i];
|
|
39
27
|
}
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
cells.push(cell.trim());
|
|
29
|
+
if (text.startsWith("|")) cells.shift();
|
|
30
|
+
if (text.endsWith("|") && !text.endsWith("\\|")) cells.pop();
|
|
31
|
+
return cells;
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
function parseMarkdownTable(lines) {
|
|
35
|
+
if (lines.length < 2 || !lines[0].includes("|")) return null;
|
|
36
|
+
const headers = tableCells(lines[0]);
|
|
37
|
+
const separators = tableCells(lines[1]);
|
|
38
|
+
if (
|
|
39
|
+
!headers.length ||
|
|
40
|
+
headers.length !== separators.length ||
|
|
41
|
+
!separators.every((cell) => /^:?-{3,}:?$/.test(cell))
|
|
42
|
+
)
|
|
43
|
+
return null;
|
|
44
|
+
return { headers, rows: lines.slice(2).map(tableCells) };
|
|
45
|
+
}
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
function bold(value) {
|
|
48
|
+
// The whole heading/label is bold; flatten inner bold spans before wrapping.
|
|
49
|
+
const text = value.trim().replace(/\*([^*\n]+)\*/g, "$1");
|
|
50
|
+
return `*${text}*`;
|
|
51
|
+
}
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
function tableText({ headers, rows }) {
|
|
54
|
+
if (!rows.length) return headers.map(bold).join(" · ");
|
|
55
|
+
if (headers.length === 1 && rows.every((row) => row.length <= 1)) {
|
|
56
|
+
return `${bold(headers[0])}\n${rows.map((row) => `• ${row[0] || "—"}`).join("\n")}`;
|
|
57
|
+
}
|
|
58
|
+
return rows
|
|
59
|
+
.map((row, index) => {
|
|
60
|
+
const title = row[0] || tr(`Item ${index + 1}`, `عنصر ${index + 1}`);
|
|
61
|
+
const fields = [];
|
|
62
|
+
for (let c = 1; c < Math.max(headers.length, row.length); c++) {
|
|
63
|
+
const header = headers[c] || tr(`Column ${c + 1}`, `عمود ${c + 1}`);
|
|
64
|
+
const label = header.replace(/^\*([^*]+)\*$/, "$1");
|
|
65
|
+
const value = (row[c] || "—").replace(/<br\s*\/?>/gi, "\n");
|
|
66
|
+
fields.push(` • ${bold(`${label}:`)} ${value.replace(/\n/g, "\n ")}`);
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
cards.push(`📋 *${primaryLabel}*\n${fields.join("\n")}`);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
return cards.join("\n\n");
|
|
68
|
+
return `📋 ${bold(title)}\n${fields.join("\n")}`;
|
|
69
|
+
})
|
|
70
|
+
.join("\n\n");
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
/**
|
|
74
|
-
* Replaces markdown table blocks with WhatsApp-friendly formatted cards.
|
|
75
|
-
*/
|
|
73
|
+
/** Only a header followed by a real delimiter row starts a table. */
|
|
76
74
|
function convertMarkdownTables(text) {
|
|
77
75
|
const lines = text.split("\n");
|
|
78
76
|
const output = [];
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
output.push(...currentTable);
|
|
77
|
+
for (let i = 0; i < lines.length; i++) {
|
|
78
|
+
const parsed = parseMarkdownTable(lines.slice(i, i + 2));
|
|
79
|
+
if (!parsed) {
|
|
80
|
+
output.push(lines[i]);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
i += 2;
|
|
84
|
+
while (i < lines.length && lines[i].trim() && lines[i].includes("|")) {
|
|
85
|
+
// A second header/delimiter pair belongs to a separate table.
|
|
86
|
+
if (parseMarkdownTable(lines.slice(i, i + 2))) break;
|
|
87
|
+
parsed.rows.push(tableCells(lines[i++]));
|
|
91
88
|
}
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
i--;
|
|
90
|
+
output.push(tableText(parsed));
|
|
91
|
+
}
|
|
92
|
+
return output.join("\n");
|
|
93
|
+
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
function shieldCode(text, store) {
|
|
96
|
+
const runs = /`+|~{3,}/g;
|
|
97
|
+
let output = "";
|
|
98
|
+
let cursor = 0;
|
|
99
|
+
for (let match = runs.exec(text); match; match = runs.exec(text)) {
|
|
100
|
+
const marker = match[0];
|
|
101
|
+
const start = match.index;
|
|
102
|
+
const lineStart = text.lastIndexOf("\n", start - 1) + 1;
|
|
103
|
+
const lineEnd = text.indexOf("\n", runs.lastIndex);
|
|
104
|
+
const info = lineEnd < 0 ? "" : text.slice(runs.lastIndex, lineEnd);
|
|
105
|
+
const fenced =
|
|
106
|
+
marker.length >= 3 &&
|
|
107
|
+
lineEnd >= 0 &&
|
|
108
|
+
/^ {0,3}$/.test(text.slice(lineStart, start)) &&
|
|
109
|
+
!info.includes(marker[0]);
|
|
110
|
+
let rendered;
|
|
111
|
+
let end;
|
|
112
|
+
if (fenced) {
|
|
113
|
+
const close = new RegExp(`^ {0,3}${marker[0]}{${marker.length},}[ \\t]*$`, "gm");
|
|
114
|
+
close.lastIndex = lineEnd + 1;
|
|
115
|
+
const ending = close.exec(text);
|
|
116
|
+
let body = text.slice(lineEnd + 1, ending ? ending.index : text.length);
|
|
117
|
+
if (ending && body.endsWith("\n")) body = body.slice(0, -1);
|
|
118
|
+
rendered = `\`\`\`\n${body}\n\`\`\``;
|
|
119
|
+
end = ending ? ending.index + ending[0].length : text.length;
|
|
98
120
|
} else {
|
|
99
|
-
|
|
100
|
-
|
|
121
|
+
if (marker[0] !== "`") continue;
|
|
122
|
+
const close = new RegExp(`(?<!\`)\`{${marker.length}}(?!\`)`, "g");
|
|
123
|
+
close.lastIndex = runs.lastIndex;
|
|
124
|
+
const ending = close.exec(text);
|
|
125
|
+
if (!ending) continue;
|
|
126
|
+
end = ending.index + marker.length;
|
|
127
|
+
rendered =
|
|
128
|
+
marker.length === 2
|
|
129
|
+
? `\`\`\`${text.slice(runs.lastIndex, ending.index)}\`\`\``
|
|
130
|
+
: text.slice(start, end);
|
|
101
131
|
}
|
|
132
|
+
output += text.slice(cursor, start) + store(rendered);
|
|
133
|
+
cursor = end;
|
|
134
|
+
runs.lastIndex = end;
|
|
102
135
|
}
|
|
103
|
-
|
|
136
|
+
return output + text.slice(cursor);
|
|
137
|
+
}
|
|
104
138
|
|
|
105
|
-
|
|
139
|
+
function links(text, store) {
|
|
140
|
+
let output = "";
|
|
141
|
+
let cursor = 0;
|
|
142
|
+
let skipUntil = 0;
|
|
143
|
+
for (const match of text.matchAll(/!?\[([^[\]\n]*)\]\(/g)) {
|
|
144
|
+
if (match.index < cursor || match.index < skipUntil) continue;
|
|
145
|
+
const start = match.index + match[0].length;
|
|
146
|
+
let depth = 1;
|
|
147
|
+
let end = start;
|
|
148
|
+
for (; end < text.length && text[end] !== "\n"; end++) {
|
|
149
|
+
if (text[end] === "\\") {
|
|
150
|
+
end++;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (text[end] === "(") depth++;
|
|
154
|
+
if (text[end] === ")" && --depth === 0) break;
|
|
155
|
+
}
|
|
156
|
+
if (depth) {
|
|
157
|
+
skipUntil = end;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const destination = text.slice(start, end).match(/^<?(\S+?)>?(?:[ \t]+["'][\s\S]*["'])?$/)?.[1];
|
|
161
|
+
if (!destination) continue;
|
|
162
|
+
const name = match[1].trim();
|
|
163
|
+
output +=
|
|
164
|
+
text.slice(cursor, match.index) +
|
|
165
|
+
(name && name !== destination ? `${name}: ` : "") +
|
|
166
|
+
store(destination);
|
|
167
|
+
cursor = end + 1;
|
|
168
|
+
}
|
|
169
|
+
return output + text.slice(cursor);
|
|
106
170
|
}
|
|
107
171
|
|
|
108
|
-
/**
|
|
109
|
-
* Main parser: converts standard Markdown to WhatsApp formatting.
|
|
110
|
-
*/
|
|
111
172
|
function formatMarkdownForWhatsApp(content) {
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// 2. Convert markdown tables into WhatsApp cards
|
|
130
|
-
masked = convertMarkdownTables(masked);
|
|
131
|
-
|
|
132
|
-
// 3. Convert Headings: # Heading -> *Heading*
|
|
133
|
-
masked = masked.replace(/(^|\n|\s)(#{1,6})\s+([^\n]+)/g, (match, lead, hashes, title) => {
|
|
134
|
-
return `${lead}*${title.trim()}*`;
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// 4. Convert Strikethrough: ~~text~~ -> ~text~
|
|
138
|
-
masked = masked.replace(/~~([^~\n]+)~~/g, "~$1~");
|
|
139
|
-
|
|
140
|
-
// 5. Convert Bold: **text** -> *text*
|
|
141
|
-
masked = masked.replace(/\*\*([^*\n]+)\*\*/g, "*$1*");
|
|
142
|
-
|
|
143
|
-
// 6. Convert Italic: __text__ -> _text_
|
|
144
|
-
masked = masked.replace(/__([^_\n]+)__/g, "_$1_");
|
|
145
|
-
|
|
146
|
-
// 7. Restore inline code and code blocks safely
|
|
147
|
-
inlineCodes.forEach((code, idx) => {
|
|
148
|
-
masked = masked.split(`\x00INLINECODE${idx}\x00`).join(code);
|
|
149
|
-
});
|
|
150
|
-
codeBlocks.forEach((block, idx) => {
|
|
151
|
-
masked = masked.split(`\x00CODEBLOCK${idx}\x00`).join(block);
|
|
173
|
+
if (typeof content !== "string" || !content) return content;
|
|
174
|
+
// Pick an unused namespace: user text resembling a placeholder is not lost.
|
|
175
|
+
let prefix = "\x00WA";
|
|
176
|
+
while (content.includes(prefix)) prefix += "X";
|
|
177
|
+
const saved = [];
|
|
178
|
+
const store = (text) => `${prefix}${saved.push(text) - 1}\x00`;
|
|
179
|
+
let text = shieldCode(content.replace(/\r\n?/g, "\n"), store);
|
|
180
|
+
text = links(text, store);
|
|
181
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: Stop URLs before internal shielding tokens.
|
|
182
|
+
text = text.replace(/(?:https?:\/\/|www\.)[^\s<>\x00]+/gi, (url, offset, source) => {
|
|
183
|
+
for (const marker of ["***", "**", "__", "~~", "*", "_"]) {
|
|
184
|
+
if (source.slice(0, offset).endsWith(marker) && url.endsWith(marker)) {
|
|
185
|
+
return store(url.slice(0, -marker.length)) + marker;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return store(url);
|
|
152
189
|
});
|
|
153
|
-
|
|
154
|
-
|
|
190
|
+
text = text.replace(/\\([\\`*{}[\]()#+.!_>~|-])/g, (_, literal) => store(literal));
|
|
191
|
+
text = text
|
|
192
|
+
.replace(/\*\*\*([^*\n]+)\*\*\*/g, "*_$1_*")
|
|
193
|
+
.replace(/(?<![\p{L}\p{N}_])___([^_\n]+)___(?![\p{L}\p{N}_])/gu, "*_$1_*")
|
|
194
|
+
.replace(/\*\*([^*\n]+)\*\*/g, "*$1*")
|
|
195
|
+
.replace(/(?<![\p{L}\p{N}_])__([^_\n]+)__(?![\p{L}\p{N}_])/gu, "_$1_")
|
|
196
|
+
.replace(/~~([^~\n]+)~~/g, "~$1~");
|
|
197
|
+
text = convertMarkdownTables(text);
|
|
198
|
+
const lines = text.split("\n");
|
|
199
|
+
const output = [];
|
|
200
|
+
for (let i = 0; i < lines.length; i++) {
|
|
201
|
+
let line = lines[i];
|
|
202
|
+
const heading = line.match(/^ {0,3}#{1,6}[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/);
|
|
203
|
+
if (heading) line = bold(heading[1]);
|
|
204
|
+
else if (
|
|
205
|
+
line.trim() &&
|
|
206
|
+
!line.includes(prefix) &&
|
|
207
|
+
/^ {0,3}(?:={3,}|-{3,})[ \t]*$/.test(lines[i + 1] || "")
|
|
208
|
+
) {
|
|
209
|
+
line = bold(line);
|
|
210
|
+
i++;
|
|
211
|
+
} else if (/^ {0,3}(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/.test(line)) {
|
|
212
|
+
line = "──────────";
|
|
213
|
+
} else {
|
|
214
|
+
line = line
|
|
215
|
+
.replace(
|
|
216
|
+
/^(\s*)[-+*][ \t]+\[([ xX])\][ \t]+/,
|
|
217
|
+
(_, indent, check) => `${indent}${check === " " ? "☐" : "☑"} `,
|
|
218
|
+
)
|
|
219
|
+
.replace(/^(\s*)[-+*][ \t]+/, "$1• ")
|
|
220
|
+
.replace(/^(\s*)(\d+)\)[ \t]+/, "$1$2. ")
|
|
221
|
+
.replace(/^ {0,3}(?:>[ \t]*)+/, "> ");
|
|
222
|
+
}
|
|
223
|
+
output.push(line.replace(/[ \t]+$/, ""));
|
|
224
|
+
}
|
|
225
|
+
text = output.join("\n");
|
|
226
|
+
// A link can contain an already-protected code label, so restore inside out.
|
|
227
|
+
const token = new RegExp(`${prefix}(\\d+)\x00`, "g");
|
|
228
|
+
const restore = (whole, id) => saved[id]?.replace(token, restore) ?? whole;
|
|
229
|
+
text = text.replace(token, restore);
|
|
230
|
+
return text;
|
|
155
231
|
}
|
|
156
232
|
|
|
157
|
-
module.exports = {
|
|
158
|
-
formatMarkdownForWhatsApp,
|
|
159
|
-
convertMarkdownTables,
|
|
160
|
-
parseMarkdownTable,
|
|
161
|
-
};
|
|
233
|
+
module.exports = { formatMarkdownForWhatsApp, convertMarkdownTables, parseMarkdownTable };
|
package/src/utils/storage.cjs
CHANGED
|
@@ -102,6 +102,7 @@ module.exports = {
|
|
|
102
102
|
resetAutoDeleteCounter: store.resetAutoDeleteCounter,
|
|
103
103
|
insertAutoDeleteLog: store.insertAutoDeleteLog,
|
|
104
104
|
listAutoDeleteLog: store.listAutoDeleteLog,
|
|
105
|
+
countAutoDeleteLog: store.countAutoDeleteLog,
|
|
105
106
|
clearAutoDeleteLog: store.clearAutoDeleteLog,
|
|
106
107
|
clearAutoDeleteOnUnlink: store.clearAutoDeleteOnUnlink,
|
|
107
108
|
};
|
package/src/utils/storage.esm.js
CHANGED
|
@@ -118,5 +118,6 @@ export const incrementAutoDeleteCounter = store.incrementAutoDeleteCounter;
|
|
|
118
118
|
export const resetAutoDeleteCounter = store.resetAutoDeleteCounter;
|
|
119
119
|
export const insertAutoDeleteLog = store.insertAutoDeleteLog;
|
|
120
120
|
export const listAutoDeleteLog = store.listAutoDeleteLog;
|
|
121
|
+
export const countAutoDeleteLog = store.countAutoDeleteLog;
|
|
121
122
|
export const clearAutoDeleteLog = store.clearAutoDeleteLog;
|
|
122
123
|
export const clearAutoDeleteOnUnlink = store.clearAutoDeleteOnUnlink;
|
package/views/dashboard.ejs
CHANGED