@alexsun-top/opencode-chat-room 0.8.3 → 0.8.4
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/CHANGELOG.md +3 -1
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/package.json +6 -3
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +12 -9
- package/server/assets/chat/announcements.js +9 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +46 -31
- package/server/assets/chat/chat-background.js +8 -14
- package/server/assets/chat/clipboard.js +2 -1
- package/server/assets/chat/confirm-dialog.js +3 -3
- package/server/assets/chat/copy-action.js +0 -1
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +18 -11
- package/server/assets/chat/editor.js +80 -58
- package/server/assets/chat/events.js +43 -30
- package/server/assets/chat/files.js +41 -13
- package/server/assets/chat/history-loader.js +5 -3
- package/server/assets/chat/image-zoom.js +21 -17
- package/server/assets/chat/install-prompt.js +10 -9
- package/server/assets/chat/integration-account-schema.js +5 -3
- package/server/assets/chat/integration-editor.js +0 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +137 -80
- package/server/assets/chat/join-requests.js +19 -12
- package/server/assets/chat/markdown-footnotes.js +0 -1
- package/server/assets/chat/markdown.js +43 -34
- package/server/assets/chat/members.js +45 -22
- package/server/assets/chat/mentions.js +31 -7
- package/server/assets/chat/message-cache.js +1 -1
- package/server/assets/chat/message-polling.js +38 -19
- package/server/assets/chat/message-window.js +9 -5
- package/server/assets/chat/messages.js +53 -43
- package/server/assets/chat/palette.js +40 -26
- package/server/assets/chat/panels.js +0 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +22 -20
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +22 -8
- package/server/assets/chat/replies.js +28 -12
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +44 -36
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +12 -11
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +0 -2
- package/server/assets/chat/side-pane.js +3 -2
- package/server/assets/chat/state.js +35 -26
- package/server/assets/chat/system-events.js +4 -4
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +37 -25
- package/server/chat.html +1 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Room files: a file-browser dialog over the room's uploaded resources.
|
|
2
1
|
import { LS } from "./state.js";
|
|
3
2
|
import { isRoomAdmin } from "./admin-badge.js";
|
|
4
3
|
import { icon } from "./icons.js";
|
|
@@ -15,6 +14,23 @@ const ICONS = {
|
|
|
15
14
|
download: "arrow_download",
|
|
16
15
|
trash: "delete",
|
|
17
16
|
};
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function readResource(value) {
|
|
21
|
+
if (!isRecord(value) || typeof value.id !== "string")
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
id: value.id,
|
|
25
|
+
name: typeof value.name === "string" ? value.name : "",
|
|
26
|
+
roomID: typeof value.roomID === "string" ? value.roomID : "",
|
|
27
|
+
mimeType: typeof value.mimeType === "string" ? value.mimeType : undefined,
|
|
28
|
+
size: typeof value.size === "number" ? value.size : undefined,
|
|
29
|
+
createdAt: typeof value.createdAt === "number" ? value.createdAt : undefined,
|
|
30
|
+
uploaderName: typeof value.uploaderName === "string" ? value.uploaderName : undefined,
|
|
31
|
+
uploaderSessionID: typeof value.uploaderSessionID === "string" ? value.uploaderSessionID : undefined,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
18
34
|
export function initFiles(app) {
|
|
19
35
|
const dialog = app.$("#filesDialog");
|
|
20
36
|
if (!dialog)
|
|
@@ -23,7 +39,10 @@ export function initFiles(app) {
|
|
|
23
39
|
const list = $("#fileList"), select = $("#filesUploader"), summary = $("#filesSummary");
|
|
24
40
|
const empty = $("#filesEmpty"), error = $("#filesError"), more = $("#btnFilesMore");
|
|
25
41
|
const roomName = $("#filesRoomName"), heading = $("#filesHeading"), trigger = $("#btnFiles"), chatView = $("#chatView");
|
|
26
|
-
|
|
42
|
+
if (!list || !select || !summary || !empty || !error || !more || !roomName || !heading || !chatView)
|
|
43
|
+
return;
|
|
44
|
+
let items = [], total = 0, loading = false, generation = 0, opener = null;
|
|
45
|
+
let preview = null, previewToken = 0;
|
|
27
46
|
let pendingReopen = false, restoreFocus = true;
|
|
28
47
|
const mediaKind = (mime) => /^image\//.test(mime || "") ? "image"
|
|
29
48
|
: /^audio\//.test(mime || "") ? "audio"
|
|
@@ -42,7 +61,8 @@ export function initFiles(app) {
|
|
|
42
61
|
return `${size.toLocaleString(app.intlLocale(), { maximumFractionDigits: size >= 10 ? 0 : 1 })} ${units[unit]}`;
|
|
43
62
|
};
|
|
44
63
|
const selfIsHuman = () => {
|
|
45
|
-
const
|
|
64
|
+
const roomId = app.state.room?.id;
|
|
65
|
+
const self = roomId ? app.state.memberSessions.get(roomId)?.find((member) => member.sessionID === LS.sessionID) : undefined;
|
|
46
66
|
return !self || self.type === "human";
|
|
47
67
|
};
|
|
48
68
|
const canDelete = (resource) => {
|
|
@@ -78,6 +98,8 @@ export function initFiles(app) {
|
|
|
78
98
|
if (!kind)
|
|
79
99
|
return;
|
|
80
100
|
const box = row.querySelector(".file-preview");
|
|
101
|
+
if (!box)
|
|
102
|
+
return;
|
|
81
103
|
box.hidden = false;
|
|
82
104
|
box.classList.remove("is-error");
|
|
83
105
|
box.textContent = app.t("resourceLoading");
|
|
@@ -91,10 +113,11 @@ export function initFiles(app) {
|
|
|
91
113
|
const url = URL.createObjectURL(blob);
|
|
92
114
|
const media = kind === "image" ? new Image() : document.createElement(kind);
|
|
93
115
|
media.className = `file-preview-media file-preview-${kind}`;
|
|
94
|
-
media
|
|
95
|
-
|
|
116
|
+
if (media instanceof HTMLImageElement || media instanceof HTMLMediaElement)
|
|
117
|
+
media.src = url;
|
|
118
|
+
if (media instanceof HTMLImageElement)
|
|
96
119
|
media.alt = resource.name;
|
|
97
|
-
else {
|
|
120
|
+
else if (media instanceof HTMLMediaElement) {
|
|
98
121
|
media.controls = true;
|
|
99
122
|
media.setAttribute("aria-label", resource.name);
|
|
100
123
|
}
|
|
@@ -298,20 +321,22 @@ export function initFiles(app) {
|
|
|
298
321
|
summary.textContent = app.t("filesLoading");
|
|
299
322
|
try {
|
|
300
323
|
const offset = reset ? 0 : items.length;
|
|
301
|
-
const before = !reset && items.length ? `&before=${encodeURIComponent(items.
|
|
324
|
+
const before = !reset && items.length ? `&before=${encodeURIComponent(items[items.length - 1].id)}` : "";
|
|
302
325
|
const page = await app.api(`/rooms/${encodeURIComponent(room.id)}/resources?limit=${PAGE_SIZE}&offset=${offset}${before}`, {
|
|
303
326
|
headers: { "x-session-id": LS.sessionID },
|
|
304
327
|
});
|
|
305
328
|
if (request !== generation || app.state.room?.id !== room.id)
|
|
306
329
|
return;
|
|
330
|
+
const payload = isRecord(page) ? page : {};
|
|
307
331
|
const seen = new Set(items.map((item) => item.id));
|
|
308
|
-
for (const
|
|
309
|
-
|
|
332
|
+
for (const value of Array.isArray(payload.resources) ? payload.resources : []) {
|
|
333
|
+
const resource = readResource(value);
|
|
334
|
+
if (!resource || seen.has(resource.id))
|
|
310
335
|
continue;
|
|
311
336
|
seen.add(resource.id);
|
|
312
337
|
items.push(resource);
|
|
313
338
|
}
|
|
314
|
-
total = Number(
|
|
339
|
+
total = Number(payload.total) || items.length;
|
|
315
340
|
render();
|
|
316
341
|
}
|
|
317
342
|
catch {
|
|
@@ -397,7 +422,7 @@ export function initFiles(app) {
|
|
|
397
422
|
dialog.close();
|
|
398
423
|
};
|
|
399
424
|
trigger?.addEventListener("click", () => { app.closePanels(); open(); });
|
|
400
|
-
$("#btnCloseFiles")?.addEventListener("click", close);
|
|
425
|
+
$("#btnCloseFiles")?.addEventListener("click", () => close());
|
|
401
426
|
document.addEventListener("keydown", (event) => {
|
|
402
427
|
if (event.key !== "Escape" || event.altKey || !dialog.open || !dialog.classList.contains("is-pane"))
|
|
403
428
|
return;
|
|
@@ -442,11 +467,14 @@ export function initFiles(app) {
|
|
|
442
467
|
target.focus({ preventScroll: true });
|
|
443
468
|
});
|
|
444
469
|
list.addEventListener("click", (event) => {
|
|
445
|
-
const
|
|
470
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
471
|
+
const button = target?.closest("[data-file-action]");
|
|
446
472
|
if (!button || !list.contains(button))
|
|
447
473
|
return;
|
|
448
474
|
const row = button.closest(".file-row");
|
|
449
|
-
|
|
475
|
+
if (!row)
|
|
476
|
+
return;
|
|
477
|
+
const resource = items.find((item) => item.id === row.dataset.resourceId);
|
|
450
478
|
if (!resource)
|
|
451
479
|
return;
|
|
452
480
|
const action = button.dataset.fileAction;
|
|
@@ -17,7 +17,8 @@ export function initHistoryLoader(app) {
|
|
|
17
17
|
const prependOlder = (older, thread, list) => {
|
|
18
18
|
// The loading spinner can be the first child; only a day separator at the
|
|
19
19
|
// boundary is a duplicate to drop.
|
|
20
|
-
const
|
|
20
|
+
const first = list.firstElementChild;
|
|
21
|
+
const tailSep = first instanceof HTMLElement && first.classList.contains("day-sep") ? first : null;
|
|
21
22
|
const fragment = document.createDocumentFragment();
|
|
22
23
|
let day = null;
|
|
23
24
|
for (const message of older) {
|
|
@@ -36,7 +37,8 @@ export function initHistoryLoader(app) {
|
|
|
36
37
|
}
|
|
37
38
|
const beforeHeight = thread.scrollHeight, beforeTop = thread.scrollTop;
|
|
38
39
|
list.prepend(fragment);
|
|
39
|
-
|
|
40
|
+
const last = older.at(-1), tailDay = last && new Date(last.createdAt).toDateString();
|
|
41
|
+
if (tailSep?.classList.contains("day-sep") && tailDay === tailSep.dataset.day)
|
|
40
42
|
tailSep.remove();
|
|
41
43
|
app.cancelThreadScrollAnimation?.();
|
|
42
44
|
thread.scrollTop = beforeTop + (thread.scrollHeight - beforeHeight);
|
|
@@ -45,7 +47,7 @@ export function initHistoryLoader(app) {
|
|
|
45
47
|
app.loadOlderHistory = async () => {
|
|
46
48
|
const room = app.state.room, entry = room && app.state.rooms.get(room.id);
|
|
47
49
|
const thread = $("#thread"), list = $("#msgList");
|
|
48
|
-
if (!room || !entry || loading)
|
|
50
|
+
if (!room || !entry || !thread || !list || loading)
|
|
49
51
|
return;
|
|
50
52
|
loading = true;
|
|
51
53
|
const generation = app.state.pollGeneration;
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
// An image in a message opens full-screen in a native dialog. Nothing in the
|
|
2
|
-
// message list moves: the overlay is a top-layer dialog, not a row change.
|
|
3
1
|
export function initImageZoom(app) {
|
|
4
2
|
const dialog = app.$("#imageDialog"), preview = app.$("#imageDialogImage");
|
|
5
3
|
const zoomLevel = app.$("#zoomLevel"), zoomOut = app.$("#btnZoomOut"), zoomIn = app.$("#btnZoomIn"), zoomReset = app.$("#btnZoomReset");
|
|
4
|
+
if (!dialog || !preview)
|
|
5
|
+
return;
|
|
6
6
|
const MAX = 4, STEP = 1.25;
|
|
7
|
-
let trigger = null, scale = 1, fitScale = 1, pendingFit = false, panX = 0, panY = 0
|
|
7
|
+
let trigger = null, scale = 1, fitScale = 1, pendingFit = false, panX = 0, panY = 0;
|
|
8
|
+
let drag = null;
|
|
8
9
|
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
9
|
-
const imageOf = (node) =>
|
|
10
|
-
|
|
10
|
+
const imageOf = (node) => {
|
|
11
|
+
const image = node instanceof Element ? node.closest("#msgList img, #attachmentList img") : null;
|
|
12
|
+
return image instanceof HTMLImageElement ? image : null;
|
|
13
|
+
};
|
|
14
|
+
const fitLimit = () => {
|
|
11
15
|
const style = getComputedStyle(dialog);
|
|
12
16
|
const width = dialog.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
|
|
13
17
|
const height = dialog.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);
|
|
14
18
|
if (!preview.naturalWidth || !preview.naturalHeight)
|
|
15
19
|
return 1;
|
|
16
20
|
return Math.min(1, width / preview.naturalWidth, height / preview.naturalHeight);
|
|
17
|
-
}
|
|
18
|
-
|
|
21
|
+
};
|
|
22
|
+
const limits = () => {
|
|
19
23
|
const style = getComputedStyle(dialog);
|
|
20
24
|
const box = dialog.getBoundingClientRect();
|
|
21
25
|
const left = box.left + parseFloat(style.paddingLeft), right = box.right - parseFloat(style.paddingRight);
|
|
@@ -34,8 +38,8 @@ export function initImageZoom(app) {
|
|
|
34
38
|
const minY = fitsY ? 0 : bottom - baseTop - scaledHeight;
|
|
35
39
|
const maxY = fitsY ? 0 : top - baseTop;
|
|
36
40
|
return { minX, maxX, minY, maxY, x: maxX - minX, y: maxY - minY };
|
|
37
|
-
}
|
|
38
|
-
|
|
41
|
+
};
|
|
42
|
+
const apply = () => {
|
|
39
43
|
const limit = limits();
|
|
40
44
|
panX = clamp(panX, limit.minX, limit.maxX);
|
|
41
45
|
panY = clamp(panY, limit.minY, limit.maxY);
|
|
@@ -47,8 +51,8 @@ export function initImageZoom(app) {
|
|
|
47
51
|
zoomOut.disabled = scale <= fitScale + .001;
|
|
48
52
|
if (zoomIn)
|
|
49
53
|
zoomIn.disabled = scale >= MAX - .001;
|
|
50
|
-
}
|
|
51
|
-
|
|
54
|
+
};
|
|
55
|
+
const zoomTo = (next, x = innerWidth / 2, y = innerHeight / 2) => {
|
|
52
56
|
const target = clamp(next, fitScale, MAX);
|
|
53
57
|
if (Math.abs(target - scale) < .001)
|
|
54
58
|
return apply();
|
|
@@ -64,17 +68,17 @@ export function initImageZoom(app) {
|
|
|
64
68
|
}
|
|
65
69
|
preview.style.animation = "none";
|
|
66
70
|
apply();
|
|
67
|
-
}
|
|
71
|
+
};
|
|
68
72
|
const zoomBy = (factor) => zoomTo(scale * factor);
|
|
69
|
-
|
|
73
|
+
const resetZoom = () => {
|
|
70
74
|
fitScale = fitLimit();
|
|
71
75
|
scale = fitScale;
|
|
72
76
|
pendingFit = false;
|
|
73
77
|
panX = 0;
|
|
74
78
|
panY = 0;
|
|
75
79
|
apply();
|
|
76
|
-
}
|
|
77
|
-
|
|
80
|
+
};
|
|
81
|
+
const open = (image) => {
|
|
78
82
|
if (!image || !dialog)
|
|
79
83
|
return;
|
|
80
84
|
trigger = image;
|
|
@@ -92,7 +96,7 @@ export function initImageZoom(app) {
|
|
|
92
96
|
apply();
|
|
93
97
|
else
|
|
94
98
|
resetZoom();
|
|
95
|
-
}
|
|
99
|
+
};
|
|
96
100
|
const close = () => { if (dialog.open)
|
|
97
101
|
dialog.close(); };
|
|
98
102
|
// A click that focuses the image makes the browser scroll it into view; the
|
|
@@ -135,7 +139,7 @@ export function initImageZoom(app) {
|
|
|
135
139
|
if (!dialog.open)
|
|
136
140
|
return;
|
|
137
141
|
event.preventDefault();
|
|
138
|
-
if (event.target.closest
|
|
142
|
+
if (event.target instanceof Element && event.target.closest(".image-dialog-tools, .image-dialog-close"))
|
|
139
143
|
return;
|
|
140
144
|
const delta = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaY;
|
|
141
145
|
zoomTo(scale * Math.exp(-delta * .0015), event.clientX, event.clientY);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// A one-time install recommendation for phones. The browser prompt itself is deferred
|
|
2
|
-
// until the Install button gesture; desktop, standalone, installed, and recent dissent
|
|
3
|
-
// all stay silent. Local storage is optional: blocked storage falls back to this tab.
|
|
4
1
|
const DISMISS_MS = 30 * 24 * 60 * 60 * 1000;
|
|
5
2
|
const DISMISS_KEY = "chat.installDismissedAt";
|
|
6
3
|
const INSTALLED_KEY = "chat.installedApp";
|
|
7
4
|
const memory = new Map();
|
|
5
|
+
function installPromptEvent(event) {
|
|
6
|
+
return "prompt" in event && typeof event.prompt === "function";
|
|
7
|
+
}
|
|
8
8
|
function read(key) {
|
|
9
9
|
try {
|
|
10
10
|
return localStorage.getItem(key);
|
|
@@ -33,7 +33,8 @@ function isIos() {
|
|
|
33
33
|
return /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
|
|
34
34
|
}
|
|
35
35
|
function isStandalone() {
|
|
36
|
-
return matchMedia("(display-mode: standalone)").matches
|
|
36
|
+
return matchMedia("(display-mode: standalone)").matches
|
|
37
|
+
|| navigator.standalone === true;
|
|
37
38
|
}
|
|
38
39
|
export function initInstallPrompt(app) {
|
|
39
40
|
const card = app.$("#installPrompt"), installButton = app.$("#btnInstallApp"), guideButton = app.$("#btnInstallGuide"), guide = app.$("#installGuide"), dismissButton = app.$("#btnDismissInstall");
|
|
@@ -43,7 +44,7 @@ export function initInstallPrompt(app) {
|
|
|
43
44
|
const eligible = () => matchMedia("(max-width: 760px)").matches && window.isSecureContext;
|
|
44
45
|
const suppressed = () => read(INSTALLED_KEY) === "1" || Number(read(DISMISS_KEY) || 0) > Date.now() - DISMISS_MS;
|
|
45
46
|
let deferred = null;
|
|
46
|
-
|
|
47
|
+
const hide = () => {
|
|
47
48
|
const fromCard = card.contains(document.activeElement), fromRail = rail.contains(document.activeElement);
|
|
48
49
|
card.hidden = true;
|
|
49
50
|
rail.hidden = true;
|
|
@@ -51,10 +52,10 @@ export function initInstallPrompt(app) {
|
|
|
51
52
|
app.$("#inName")?.focus({ preventScroll: true });
|
|
52
53
|
else if (fromRail)
|
|
53
54
|
app.$("#btnSettings")?.focus({ preventScroll: true });
|
|
54
|
-
}
|
|
55
|
+
};
|
|
55
56
|
// The join card explains itself; the room drawer carries the same offer for people
|
|
56
57
|
// who restore straight into a room and never see the join page.
|
|
57
|
-
|
|
58
|
+
const render = (mode) => {
|
|
58
59
|
const visible = Boolean(mode) && eligible() && !isStandalone() && !suppressed();
|
|
59
60
|
card.hidden = rail.hidden = !visible;
|
|
60
61
|
if (!visible)
|
|
@@ -67,9 +68,9 @@ export function initInstallPrompt(app) {
|
|
|
67
68
|
guide.hidden = true;
|
|
68
69
|
guideButton.setAttribute("aria-expanded", "false");
|
|
69
70
|
}
|
|
70
|
-
}
|
|
71
|
+
};
|
|
71
72
|
window.addEventListener("beforeinstallprompt", (event) => {
|
|
72
|
-
if (!eligible() || isStandalone() || suppressed())
|
|
73
|
+
if (!installPromptEvent(event) || !eligible() || isStandalone() || suppressed())
|
|
73
74
|
return;
|
|
74
75
|
event.preventDefault();
|
|
75
76
|
deferred = event;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Account form generated from the JSON Schema a plugin declares in initialize.
|
|
2
1
|
const CONTROL = { string: "text", secret: "password", number: "number" };
|
|
3
2
|
function textFor(field, fallback) {
|
|
4
3
|
return typeof field.label === "string" && field.label.trim() ? field.label : fallback;
|
|
@@ -43,7 +42,7 @@ function addField(container, field, existing, stored, text) {
|
|
|
43
42
|
else {
|
|
44
43
|
control = document.createElement("input");
|
|
45
44
|
control.className = "input";
|
|
46
|
-
control.type = CONTROL[field.type] || "text";
|
|
45
|
+
control.type = (field.type && CONTROL[field.type]) || "text";
|
|
47
46
|
control.autocomplete = field.type === "secret" ? "new-password" : "off";
|
|
48
47
|
if (existing)
|
|
49
48
|
control.placeholder = stored ? text("integrationsLeaveBlank") : text("integrationsNotSet");
|
|
@@ -65,7 +64,8 @@ function addField(container, field, existing, stored, text) {
|
|
|
65
64
|
}
|
|
66
65
|
export function renderAccountSchema(container, plugin, account, text) {
|
|
67
66
|
container.textContent = "";
|
|
68
|
-
const
|
|
67
|
+
const schema = plugin?.account?.schema;
|
|
68
|
+
const fields = Array.isArray(schema) ? schema : [];
|
|
69
69
|
container.hidden = fields.length === 0;
|
|
70
70
|
if (!fields.length)
|
|
71
71
|
return;
|
|
@@ -84,6 +84,8 @@ export function readAccountSchema(container, text) {
|
|
|
84
84
|
const missing = [];
|
|
85
85
|
for (const control of container.querySelectorAll("[data-account-key]")) {
|
|
86
86
|
const key = control.dataset.accountKey;
|
|
87
|
+
if (key === undefined)
|
|
88
|
+
continue;
|
|
87
89
|
keys.add(key);
|
|
88
90
|
const value = String(control.value ?? "").trim();
|
|
89
91
|
if (value !== "") {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Lazy Monaco wrapper for one integration rules section. The textarea stays in the
|
|
2
|
-
// page as the no-JS and failed-download fallback, so this module never imports Monaco.
|
|
3
1
|
const BUNDLE_URL = "/assets/monaco/integration-rules.js";
|
|
4
2
|
const STYLES_URL = "/assets/monaco/integration-rules.css";
|
|
5
3
|
let bundlePromise = null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Parsing and account-reference checks for integration rules and inbound routes.
|
|
2
1
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3
2
|
export function cleanError(error, fallback) {
|
|
4
|
-
const
|
|
3
|
+
const detail = error instanceof Error ? error.message || error : error;
|
|
4
|
+
const value = String(detail || "").trim()
|
|
5
5
|
.replace(/channeld/gi, "integrations")
|
|
6
6
|
.replace(/\bBearer\s+\S+/gi, "Bearer [redacted]")
|
|
7
7
|
.replace(/\b(secret|token|password|authorization|api[_-]?key)\b\s*[:=]\s*\S+/gi, "$1=[redacted]");
|
|
@@ -62,7 +62,8 @@ export function parseRules(value, accounts, text) {
|
|
|
62
62
|
rules = JSON.parse(value || "[]");
|
|
63
63
|
}
|
|
64
64
|
catch (error) {
|
|
65
|
-
|
|
65
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
66
|
+
throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, message) }));
|
|
66
67
|
}
|
|
67
68
|
return checkRules(rules, accounts, text);
|
|
68
69
|
}
|
|
@@ -85,12 +86,14 @@ export function checkRules(rules, accounts, text) {
|
|
|
85
86
|
if (!isRecord(target))
|
|
86
87
|
throw new Error(text("integrationsInvalidRules"));
|
|
87
88
|
for (const field of ["platform", "account", "room"]) {
|
|
88
|
-
|
|
89
|
+
const value = target[field];
|
|
90
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
89
91
|
throw new Error(text("integrationsTargetRequired", { index: ruleNumber, target: targetIndex + 1, field }));
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
const targetAccount = typeof target.account === "string" ? target.account : "";
|
|
95
|
+
if (!known.has(targetAccount)) {
|
|
96
|
+
throw new Error(text("integrationsTargetMissing", { index: ruleNumber, target: targetIndex + 1, account: targetAccount }));
|
|
94
97
|
}
|
|
95
98
|
});
|
|
96
99
|
});
|
|
@@ -102,7 +105,8 @@ export function parseInbound(value, accounts, text) {
|
|
|
102
105
|
inbound = JSON.parse(value || "[]");
|
|
103
106
|
}
|
|
104
107
|
catch (error) {
|
|
105
|
-
|
|
108
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
109
|
+
throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, message) }));
|
|
106
110
|
}
|
|
107
111
|
return checkInbound(inbound, accounts);
|
|
108
112
|
}
|
|
@@ -116,16 +120,18 @@ export function checkInbound(inbound, accounts) {
|
|
|
116
120
|
throw new Error(`${label}: from is required.`);
|
|
117
121
|
const from = route.from;
|
|
118
122
|
for (const field of ["platform", "account", "room"]) {
|
|
119
|
-
|
|
123
|
+
const value = from[field];
|
|
124
|
+
if (typeof value !== "string" || !value.trim())
|
|
120
125
|
throw new Error(`${label}: from.${field} is required.`);
|
|
121
126
|
}
|
|
122
127
|
if (from.event !== undefined && typeof from.event !== "string")
|
|
123
128
|
throw new Error(`${label}: from.event must be a string.`);
|
|
124
|
-
const
|
|
129
|
+
const fromAccount = typeof from.account === "string" ? from.account : "";
|
|
130
|
+
const account = known.get(fromAccount);
|
|
125
131
|
if (!account)
|
|
126
|
-
throw new Error(`${label}: account “${
|
|
132
|
+
throw new Error(`${label}: account “${fromAccount}” does not exist.`);
|
|
127
133
|
if (account.platform !== from.platform)
|
|
128
|
-
throw new Error(`${label}: account “${
|
|
134
|
+
throw new Error(`${label}: account “${fromAccount}” belongs to “${account.platform}”.`);
|
|
129
135
|
if (!isRecord(route.to) || typeof route.to.room !== "string" || !route.to.room.trim())
|
|
130
136
|
throw new Error(`${label}: to.room is required.`);
|
|
131
137
|
});
|