@alexsun-top/opencode-chat-room 0.8.3 → 0.8.5
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 +7 -1
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +1 -1
- package/dist/cli.js +35 -16
- package/package.json +15 -9
- package/packages/chat-room-channeld/README.md +3 -2
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +107 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
- package/plugin.ts +1 -1
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +16 -10
- package/server/assets/chat/announcements.js +12 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +48 -33
- 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 +1 -2
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +19 -12
- package/server/assets/chat/editor.js +87 -61
- package/server/assets/chat/events.js +49 -34
- package/server/assets/chat/files.js +45 -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 +2 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +138 -81
- package/server/assets/chat/join-requests.js +20 -13
- package/server/assets/chat/markdown-footnotes.js +8 -8
- package/server/assets/chat/markdown.js +48 -38
- package/server/assets/chat/members.js +48 -25
- package/server/assets/chat/mentions.js +39 -12
- package/server/assets/chat/message-cache.js +2 -2
- package/server/assets/chat/message-polling.js +40 -21
- package/server/assets/chat/message-window.js +10 -6
- package/server/assets/chat/messages.js +70 -46
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/palette.js +45 -29
- package/server/assets/chat/panels.js +19 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +25 -22
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +25 -8
- package/server/assets/chat/replies.js +34 -15
- package/server/assets/chat/resource-format.js +2 -2
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +51 -40
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +16 -14
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +3 -3
- package/server/assets/chat/side-pane.js +4 -3
- package/server/assets/chat/state.js +65 -37
- package/server/assets/chat/system-events.js +6 -5
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +41 -28
- package/server/assets/chat/window-controls.js +3 -2
- package/server/assets/conversation.css +14 -2
- package/server/assets/doc-preview.css +6 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/chat.html +1 -0
- package/server/sw.js +3 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/agent/agent-receipts.ts +12 -4
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +107 -99
- package/src/state/pg-worker.mts +166 -0
- package/src/state/store.ts +21 -7
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +426 -423
- package/src/tui/app.mts +500 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +257 -242
- package/src/tui/room-settings-app.mts +301 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Settings > Integrations: runtime switch, accounts, plugin uploads, and rules.
|
|
2
1
|
import { initIntegrationEditor } from "./integration-editor.js";
|
|
3
2
|
import { iconNode } from "./icons.js";
|
|
4
3
|
import { readAccountSchema, renderAccountSchema } from "./integration-account-schema.js";
|
|
@@ -9,6 +8,45 @@ const IDENTIFIER = /^[A-Za-z0-9._-]{1,128}$/;
|
|
|
9
8
|
const PLUGIN_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*\.(?:js|mjs|cjs|ts)$/;
|
|
10
9
|
const ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
11
10
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
11
|
+
function readPlugin(value) {
|
|
12
|
+
const account = isRecord(value.account) ? value.account : null;
|
|
13
|
+
return {
|
|
14
|
+
...value,
|
|
15
|
+
pluginId: String(value.pluginId ?? ""),
|
|
16
|
+
name: String(value.name ?? ""),
|
|
17
|
+
platform: String(value.platform ?? ""),
|
|
18
|
+
account: account ? { env: account.env, schema: account.schema } : undefined,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function normalizeAccountRow(account) {
|
|
22
|
+
return {
|
|
23
|
+
id: account.id,
|
|
24
|
+
platform: account.platform,
|
|
25
|
+
pluginId: account.pluginId,
|
|
26
|
+
envKeys: account.envKeys ?? [],
|
|
27
|
+
storedKeys: account.storedKeys ?? [],
|
|
28
|
+
envSet: account.envSet ?? {},
|
|
29
|
+
envDelete: account.envDelete ?? [],
|
|
30
|
+
envClear: account.envClear ?? false,
|
|
31
|
+
state: account.state ?? "unknown",
|
|
32
|
+
lastError: account.lastError ?? "",
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function pluginsOf(data) {
|
|
36
|
+
return knownPlugins(data).map((plugin) => readPlugin(isRecord(plugin) ? plugin : {}));
|
|
37
|
+
}
|
|
38
|
+
function envFieldsOf(plugin) {
|
|
39
|
+
const account = plugin && isRecord(plugin.account) ? plugin.account : {};
|
|
40
|
+
const env = Array.isArray(account.env) ? account.env : [];
|
|
41
|
+
return env.filter(isRecord).map((field) => ({
|
|
42
|
+
key: String(field.key ?? ""),
|
|
43
|
+
label: typeof field.label === "string" ? field.label : undefined,
|
|
44
|
+
description: typeof field.description === "string" ? field.description : undefined,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
function errorText(error) {
|
|
48
|
+
return error instanceof Error ? error.message : String(error);
|
|
49
|
+
}
|
|
12
50
|
export function initIntegrations(app) {
|
|
13
51
|
const $ = app.$;
|
|
14
52
|
const panel = $("#settingsPanelIntegrations");
|
|
@@ -30,12 +68,20 @@ export function initIntegrations(app) {
|
|
|
30
68
|
const accountClear = $("#btnClearAccountEnv"), accountAddEnv = $("#btnAddAccountEnv");
|
|
31
69
|
const pluginDialog = $("#integrationPluginDialog"), pluginForm = $("#integrationPluginForm");
|
|
32
70
|
const pluginError = $("#integrationPluginError"), pluginFile = $("#integrationPluginFile");
|
|
71
|
+
if (!enabledInput || !statusText || !integrationBody || !disabledHint || !panelError || !accountsList
|
|
72
|
+
|| !accountsEmpty || !pluginsList || !pluginsEmpty || !rulesError || !saveButton
|
|
73
|
+
|| !accountDialog || !accountForm || !accountError || !accountId || !accountPlugin || !accountSchema
|
|
74
|
+
|| !accountSchemaField || !accountAdvanced || !accountEnv || !accountEnvNote || !accountClear || !accountAddEnv
|
|
75
|
+
|| !pluginDialog || !pluginForm || !pluginError || !pluginFile)
|
|
76
|
+
return;
|
|
77
|
+
const api = (url, options) => app.api(url, options);
|
|
33
78
|
let data = { enabled: false, source: "managed", editable: true, accounts: [], rules: [], inbound: [], plugins: [] };
|
|
34
79
|
let initialInbound = "[]";
|
|
35
|
-
let loaded = false, loading = false, saving = false,
|
|
80
|
+
let loaded = false, loading = false, saving = false, clearEnv = false;
|
|
81
|
+
let accountDraft = null;
|
|
36
82
|
let pluginUploadSource = "", pluginUploadName = "";
|
|
37
83
|
const text = (key, values) => app.t(key, values);
|
|
38
|
-
const clean = (error) => cleanError(error, text("integrationsLoadFailed"));
|
|
84
|
+
const clean = (error) => String(cleanError(error, text("integrationsLoadFailed")));
|
|
39
85
|
const showPanelError = (error) => { panelError.textContent = clean(error); panelError.hidden = false; };
|
|
40
86
|
const hidePanelError = () => { panelError.hidden = true; };
|
|
41
87
|
const showStatus = (value) => { statusText.textContent = value; };
|
|
@@ -67,7 +113,7 @@ export function initIntegrations(app) {
|
|
|
67
113
|
getValue: () => data.inbound,
|
|
68
114
|
getAccounts: () => data.accounts,
|
|
69
115
|
});
|
|
70
|
-
|
|
116
|
+
const applyEditableState = () => {
|
|
71
117
|
const editable = data.editable !== false;
|
|
72
118
|
if (externalNotice)
|
|
73
119
|
externalNotice.hidden = editable;
|
|
@@ -78,30 +124,30 @@ export function initIntegrations(app) {
|
|
|
78
124
|
uploadPluginButton.disabled = !editable;
|
|
79
125
|
rulesSection.setEditable(editable);
|
|
80
126
|
inboundSection.setEditable(editable);
|
|
81
|
-
}
|
|
82
|
-
|
|
127
|
+
};
|
|
128
|
+
const applyEnabledState = () => {
|
|
83
129
|
const enabled = enabledInput.checked;
|
|
84
130
|
integrationBody.hidden = !enabled;
|
|
85
131
|
disabledHint.hidden = enabled;
|
|
86
|
-
}
|
|
87
|
-
const pluginNameOf = (pluginId) =>
|
|
132
|
+
};
|
|
133
|
+
const pluginNameOf = (pluginId) => String(pluginsOf(data).find((plugin) => plugin.pluginId === pluginId)?.name || pluginId);
|
|
88
134
|
function adopt(snapshot) {
|
|
89
135
|
const raw = isRecord(snapshot) ? snapshot : {};
|
|
90
136
|
data = {
|
|
91
137
|
enabled: raw.enabled === true,
|
|
92
138
|
source: typeof raw.source === "string" ? raw.source : "managed",
|
|
93
139
|
editable: raw.editable !== false,
|
|
94
|
-
accounts: Array.isArray(raw.accounts) ? raw.accounts.filter(isRecord).map(normalizeAccount) : [],
|
|
140
|
+
accounts: Array.isArray(raw.accounts) ? raw.accounts.filter(isRecord).map((account) => normalizeAccountRow(normalizeAccount(account))) : [],
|
|
95
141
|
rules: Array.isArray(raw.rules) ? raw.rules : [],
|
|
96
142
|
inbound: Array.isArray(raw.inbound) ? raw.inbound : data.inbound,
|
|
97
143
|
plugins: Array.isArray(raw.plugins)
|
|
98
|
-
? raw.plugins.filter((plugin) =>
|
|
144
|
+
? raw.plugins.filter(isRecord).filter((plugin) => typeof plugin.pluginId === "string" && typeof plugin.name === "string" && typeof plugin.platform === "string").map(readPlugin)
|
|
99
145
|
: data.plugins,
|
|
100
146
|
};
|
|
101
147
|
initialInbound = JSON.stringify(data.inbound);
|
|
102
148
|
loaded = true;
|
|
103
149
|
}
|
|
104
|
-
|
|
150
|
+
const renderAccounts = () => {
|
|
105
151
|
accountsList.textContent = "";
|
|
106
152
|
for (const account of data.accounts) {
|
|
107
153
|
const row = document.createElement("li");
|
|
@@ -163,9 +209,9 @@ export function initIntegrations(app) {
|
|
|
163
209
|
accountsEmpty.hidden = data.accounts.length > 0;
|
|
164
210
|
rulesSection.setAccounts(data.accounts);
|
|
165
211
|
inboundSection.setAccounts(data.accounts);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const plugins =
|
|
212
|
+
};
|
|
213
|
+
const renderPlugins = () => {
|
|
214
|
+
const plugins = pluginsOf(data);
|
|
169
215
|
pluginsList.textContent = "";
|
|
170
216
|
for (const plugin of plugins) {
|
|
171
217
|
const row = document.createElement("li");
|
|
@@ -187,7 +233,7 @@ export function initIntegrations(app) {
|
|
|
187
233
|
pluginsList.append(row);
|
|
188
234
|
}
|
|
189
235
|
pluginsEmpty.hidden = plugins.length > 0;
|
|
190
|
-
}
|
|
236
|
+
};
|
|
191
237
|
async function downloadPlugin(plugin, button) {
|
|
192
238
|
if (button.disabled)
|
|
193
239
|
return;
|
|
@@ -217,14 +263,14 @@ export function initIntegrations(app) {
|
|
|
217
263
|
inboundSection.setAccounts(data.accounts);
|
|
218
264
|
hideRulesError();
|
|
219
265
|
}
|
|
220
|
-
|
|
266
|
+
const renderAll = () => {
|
|
221
267
|
enabledInput.checked = data.enabled;
|
|
222
268
|
renderAccounts();
|
|
223
269
|
renderPlugins();
|
|
224
270
|
renderRules();
|
|
225
271
|
applyEnabledState();
|
|
226
272
|
applyEditableState();
|
|
227
|
-
}
|
|
273
|
+
};
|
|
228
274
|
async function load(force = false) {
|
|
229
275
|
if (loading || loaded && !force)
|
|
230
276
|
return;
|
|
@@ -234,7 +280,7 @@ export function initIntegrations(app) {
|
|
|
234
280
|
hidePanelError();
|
|
235
281
|
showStatus(text("integrationsLoading"));
|
|
236
282
|
try {
|
|
237
|
-
adopt(await
|
|
283
|
+
adopt(await api("/channeld/integration", { cache: "no-store" }));
|
|
238
284
|
renderAll();
|
|
239
285
|
showStatus("");
|
|
240
286
|
}
|
|
@@ -247,24 +293,24 @@ export function initIntegrations(app) {
|
|
|
247
293
|
}
|
|
248
294
|
}
|
|
249
295
|
app.loadIntegrations = () => { void load(true); };
|
|
250
|
-
|
|
296
|
+
const setSaving = (busy) => {
|
|
251
297
|
saving = busy;
|
|
252
298
|
saveButton.disabled = busy || data.editable === false;
|
|
253
299
|
enabledInput.disabled = busy;
|
|
254
|
-
}
|
|
300
|
+
};
|
|
255
301
|
let envMenuSerial = 0;
|
|
256
|
-
|
|
257
|
-
const plugin =
|
|
258
|
-
return (plugin
|
|
259
|
-
}
|
|
260
|
-
|
|
302
|
+
const envFields = () => {
|
|
303
|
+
const plugin = pluginsOf(data).find((item) => item.pluginId === accountPlugin.value);
|
|
304
|
+
return envFieldsOf(plugin).filter((field) => ENV_KEY.test(field.key));
|
|
305
|
+
};
|
|
306
|
+
const closeEnvMenus = (except) => {
|
|
261
307
|
for (const menu of accountEnv.querySelectorAll(".integration-env-menu")) {
|
|
262
308
|
if (menu === except)
|
|
263
309
|
continue;
|
|
264
310
|
menu.hidden = true;
|
|
265
311
|
menu.parentElement?.querySelector(".integration-env-key")?.setAttribute("aria-expanded", "false");
|
|
266
312
|
}
|
|
267
|
-
}
|
|
313
|
+
};
|
|
268
314
|
function addEnvRow(container, entry = {}, existing = false, onRemove = null) {
|
|
269
315
|
const row = document.createElement("div");
|
|
270
316
|
row.className = `integration-env-row${existing ? " is-stored" : ""}`;
|
|
@@ -300,7 +346,7 @@ export function initIntegrations(app) {
|
|
|
300
346
|
key.setAttribute("aria-expanded", "false");
|
|
301
347
|
};
|
|
302
348
|
const choose = (option) => {
|
|
303
|
-
key.value = option.dataset.key;
|
|
349
|
+
key.value = option.dataset.key ?? "";
|
|
304
350
|
hide();
|
|
305
351
|
value.focus();
|
|
306
352
|
};
|
|
@@ -401,8 +447,12 @@ export function initIntegrations(app) {
|
|
|
401
447
|
function readEnv(container) {
|
|
402
448
|
const values = {};
|
|
403
449
|
for (const row of container.querySelectorAll(".integration-env-row")) {
|
|
404
|
-
const
|
|
405
|
-
const
|
|
450
|
+
const keyNode = row.querySelector(".integration-env-key");
|
|
451
|
+
const valueNode = row.querySelector(".integration-env-value");
|
|
452
|
+
if (!keyNode || !valueNode)
|
|
453
|
+
continue;
|
|
454
|
+
const key = keyNode.value.trim();
|
|
455
|
+
const value = valueNode.value;
|
|
406
456
|
if (!key && !value)
|
|
407
457
|
continue;
|
|
408
458
|
if (!ENV_KEY.test(key) || Object.hasOwn(values, key))
|
|
@@ -412,9 +462,9 @@ export function initIntegrations(app) {
|
|
|
412
462
|
}
|
|
413
463
|
return values;
|
|
414
464
|
}
|
|
415
|
-
|
|
465
|
+
const fillPlugins = (selected) => {
|
|
416
466
|
accountPlugin.textContent = "";
|
|
417
|
-
const plugins =
|
|
467
|
+
const plugins = pluginsOf(data);
|
|
418
468
|
if (!plugins.length) {
|
|
419
469
|
const option = document.createElement("option");
|
|
420
470
|
option.value = "";
|
|
@@ -428,14 +478,14 @@ export function initIntegrations(app) {
|
|
|
428
478
|
accountPlugin.append(option);
|
|
429
479
|
}
|
|
430
480
|
accountPlugin.value = plugins.some((plugin) => plugin.pluginId === selected) ? selected : plugins[0]?.pluginId || "";
|
|
431
|
-
}
|
|
481
|
+
};
|
|
432
482
|
/** Stable once saved; a blank ID is only a convenience for new accounts. */
|
|
433
483
|
function newAccountId(plugin) {
|
|
434
484
|
const prefix = String(plugin?.platform || "account").replace(/[^A-Za-z0-9._-]/g, "") || "account";
|
|
435
485
|
const bytes = crypto.getRandomValues(new Uint8Array(4));
|
|
436
486
|
return `${prefix}-${[...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
437
487
|
}
|
|
438
|
-
|
|
488
|
+
const setClearEnv = (next) => {
|
|
439
489
|
clearEnv = next;
|
|
440
490
|
accountClear.textContent = text(next ? "integrationsKeepEnv" : "integrationsClearEnv");
|
|
441
491
|
accountEnvNote.hidden = !next;
|
|
@@ -445,7 +495,7 @@ export function initIntegrations(app) {
|
|
|
445
495
|
control.disabled = next;
|
|
446
496
|
for (const control of accountSchema.querySelectorAll("input, select, button"))
|
|
447
497
|
control.disabled = next;
|
|
448
|
-
}
|
|
498
|
+
};
|
|
449
499
|
function removeStoredKey(key) {
|
|
450
500
|
if (!key || !accountDraft)
|
|
451
501
|
return;
|
|
@@ -456,19 +506,19 @@ export function initIntegrations(app) {
|
|
|
456
506
|
if (accountDraft.envSet)
|
|
457
507
|
delete accountDraft.envSet[key];
|
|
458
508
|
}
|
|
459
|
-
|
|
460
|
-
const plugin =
|
|
509
|
+
const syncAccountSchema = () => {
|
|
510
|
+
const plugin = pluginsOf(data).find((item) => item.pluginId === accountPlugin.value);
|
|
461
511
|
closeEnvMenus();
|
|
462
512
|
renderAccountSchema(accountSchema, plugin, accountDraft?.id ? accountDraft : null, text);
|
|
463
513
|
accountSchemaField.hidden = accountSchema.hidden;
|
|
464
514
|
// Without a declared schema the raw env rows are the only way to configure
|
|
465
515
|
// the account, so keep them open; schema-backed plugins can collapse them.
|
|
466
|
-
accountAdvanced.open = accountSchema.hidden;
|
|
467
|
-
}
|
|
468
|
-
|
|
516
|
+
accountAdvanced.open = Boolean(accountSchema.hidden);
|
|
517
|
+
};
|
|
518
|
+
const openAccount = (account = null, presetPlugin = "") => {
|
|
469
519
|
if (data.editable === false)
|
|
470
520
|
return;
|
|
471
|
-
if (!
|
|
521
|
+
if (!pluginsOf(data).length) {
|
|
472
522
|
showPanelError(text("integrationsPluginFirst"));
|
|
473
523
|
return;
|
|
474
524
|
}
|
|
@@ -492,25 +542,26 @@ export function initIntegrations(app) {
|
|
|
492
542
|
setClearEnv(Boolean(account?.envClear));
|
|
493
543
|
accountDialog.showModal();
|
|
494
544
|
accountPlugin.focus();
|
|
495
|
-
}
|
|
496
|
-
|
|
545
|
+
};
|
|
546
|
+
const closeAccount = () => {
|
|
497
547
|
if (accountDialog.open)
|
|
498
548
|
accountDialog.close();
|
|
499
549
|
accountDraft = null;
|
|
500
|
-
}
|
|
550
|
+
};
|
|
501
551
|
accountForm.addEventListener("submit", (event) => {
|
|
502
552
|
event.preventDefault();
|
|
503
|
-
|
|
553
|
+
const draft = accountDraft;
|
|
554
|
+
if (!draft)
|
|
504
555
|
return;
|
|
505
556
|
hideAccountError();
|
|
506
557
|
const pluginId = accountPlugin.value;
|
|
507
|
-
const plugin =
|
|
558
|
+
const plugin = pluginsOf(data).find((item) => item.pluginId === pluginId);
|
|
508
559
|
if (!plugin)
|
|
509
560
|
return showAccountError(text("integrationsAccountInvalid"));
|
|
510
|
-
const id =
|
|
561
|
+
const id = draft.id || accountId.value.trim() || newAccountId(plugin);
|
|
511
562
|
if (!IDENTIFIER.test(id))
|
|
512
563
|
return showAccountError(text("integrationsAccountInvalid"));
|
|
513
|
-
if (data.accounts.some((item) => item.id === id && item.id !==
|
|
564
|
+
if (data.accounts.some((item) => item.id === id && item.id !== draft.id)) {
|
|
514
565
|
return showAccountError(text("integrationsDuplicateAccount"));
|
|
515
566
|
}
|
|
516
567
|
let values;
|
|
@@ -528,37 +579,38 @@ export function initIntegrations(app) {
|
|
|
528
579
|
return showAccountError(error);
|
|
529
580
|
}
|
|
530
581
|
// A schema field and a free-form env row can name the same key: the schema wins.
|
|
531
|
-
|
|
582
|
+
const schemaKeys = [...schema.keys].filter((key) => typeof key === "string");
|
|
583
|
+
for (const key of schemaKeys)
|
|
532
584
|
delete values[key];
|
|
533
585
|
const schemaValues = clearEnv ? {} : schema.values;
|
|
534
|
-
const envSet = clearEnv ? {} : { ...(
|
|
535
|
-
const deleted = new Set(clearEnv ? [] :
|
|
586
|
+
const envSet = clearEnv ? {} : { ...(draft.envSet || {}), ...values, ...schemaValues };
|
|
587
|
+
const deleted = new Set(clearEnv ? [] : draft.envDelete || []);
|
|
536
588
|
for (const key of Object.keys(values))
|
|
537
589
|
deleted.delete(key);
|
|
538
590
|
for (const key of Object.keys(schemaValues))
|
|
539
591
|
deleted.delete(key);
|
|
540
|
-
const remaining = (
|
|
592
|
+
const remaining = (draft.envKeys || []).filter((key) => !deleted.has(key));
|
|
541
593
|
const next = {
|
|
542
594
|
id,
|
|
543
595
|
platform: plugin.platform,
|
|
544
596
|
pluginId: plugin.pluginId,
|
|
545
|
-
state:
|
|
546
|
-
lastError:
|
|
597
|
+
state: draft.state,
|
|
598
|
+
lastError: draft.lastError,
|
|
547
599
|
envKeys: clearEnv ? [] : [...new Set([...remaining, ...Object.keys(envSet)])],
|
|
548
|
-
storedKeys:
|
|
600
|
+
storedKeys: draft.storedKeys || [],
|
|
549
601
|
envSet,
|
|
550
602
|
envDelete: clearEnv ? [] : [...deleted].filter((key) => !Object.hasOwn(envSet, key)),
|
|
551
603
|
envClear: clearEnv,
|
|
552
604
|
};
|
|
553
|
-
data.accounts =
|
|
554
|
-
? data.accounts.map((item) => item.id ===
|
|
605
|
+
data.accounts = draft.id
|
|
606
|
+
? data.accounts.map((item) => item.id === draft.id ? next : item)
|
|
555
607
|
: [...data.accounts, next];
|
|
556
608
|
renderAccounts();
|
|
557
609
|
renderPlugins();
|
|
558
610
|
closeAccount();
|
|
559
611
|
showStatus(text("integrationsAccountSaved"));
|
|
560
612
|
});
|
|
561
|
-
async
|
|
613
|
+
const save = async () => {
|
|
562
614
|
if (saving || data.editable === false)
|
|
563
615
|
return;
|
|
564
616
|
if (data.enabled && !enabledInput.checked && !(await app.confirmAction(text("integrationsDisableConfirm")))) {
|
|
@@ -575,11 +627,12 @@ export function initIntegrations(app) {
|
|
|
575
627
|
if (rulesState.editor) {
|
|
576
628
|
if (rulesState.errors.length)
|
|
577
629
|
return;
|
|
630
|
+
const editorValue = Reflect.get(rulesState, "value");
|
|
578
631
|
try {
|
|
579
|
-
rules = checkRules(
|
|
632
|
+
rules = checkRules(editorValue, data.accounts, text);
|
|
580
633
|
}
|
|
581
634
|
catch (error) {
|
|
582
|
-
return rulesSection.showMessage(error
|
|
635
|
+
return rulesSection.showMessage(errorText(error));
|
|
583
636
|
}
|
|
584
637
|
}
|
|
585
638
|
else {
|
|
@@ -587,7 +640,7 @@ export function initIntegrations(app) {
|
|
|
587
640
|
rules = parseRules(rulesState.text, data.accounts, text);
|
|
588
641
|
}
|
|
589
642
|
catch (error) {
|
|
590
|
-
return showRulesError(error
|
|
643
|
+
return showRulesError(errorText(error));
|
|
591
644
|
}
|
|
592
645
|
}
|
|
593
646
|
const inboundState = inboundSection.current();
|
|
@@ -595,11 +648,12 @@ export function initIntegrations(app) {
|
|
|
595
648
|
if (inboundState.editor) {
|
|
596
649
|
if (inboundState.errors.length)
|
|
597
650
|
return;
|
|
651
|
+
const editorValue = Reflect.get(inboundState, "value");
|
|
598
652
|
try {
|
|
599
|
-
inbound = checkInbound(
|
|
653
|
+
inbound = checkInbound(editorValue, data.accounts);
|
|
600
654
|
}
|
|
601
655
|
catch (error) {
|
|
602
|
-
return inboundSection.showMessage(error
|
|
656
|
+
return inboundSection.showMessage(errorText(error));
|
|
603
657
|
}
|
|
604
658
|
}
|
|
605
659
|
else {
|
|
@@ -607,13 +661,13 @@ export function initIntegrations(app) {
|
|
|
607
661
|
inbound = parseInbound(inboundState.text, data.accounts, text);
|
|
608
662
|
}
|
|
609
663
|
catch (error) {
|
|
610
|
-
return inboundSection.showMessage(error
|
|
664
|
+
return inboundSection.showMessage(errorText(error));
|
|
611
665
|
}
|
|
612
666
|
}
|
|
613
667
|
const inboundChanged = JSON.stringify(inbound) !== initialInbound;
|
|
614
668
|
setSaving(true);
|
|
615
669
|
try {
|
|
616
|
-
adopt(await
|
|
670
|
+
adopt(await api("/channeld/integration", {
|
|
617
671
|
method: "PUT",
|
|
618
672
|
body: JSON.stringify({
|
|
619
673
|
enabled: enabledInput.checked,
|
|
@@ -633,8 +687,8 @@ export function initIntegrations(app) {
|
|
|
633
687
|
finally {
|
|
634
688
|
setSaving(false);
|
|
635
689
|
}
|
|
636
|
-
}
|
|
637
|
-
|
|
690
|
+
};
|
|
691
|
+
const openUpload = () => {
|
|
638
692
|
if (data.editable === false)
|
|
639
693
|
return;
|
|
640
694
|
pluginForm.reset();
|
|
@@ -643,7 +697,7 @@ export function initIntegrations(app) {
|
|
|
643
697
|
hidePluginError();
|
|
644
698
|
pluginDialog.showModal();
|
|
645
699
|
pluginFile.focus();
|
|
646
|
-
}
|
|
700
|
+
};
|
|
647
701
|
pluginFile.addEventListener("change", async () => {
|
|
648
702
|
const file = pluginFile.files?.[0];
|
|
649
703
|
pluginUploadSource = "";
|
|
@@ -672,18 +726,21 @@ export function initIntegrations(app) {
|
|
|
672
726
|
if (new TextEncoder().encode(source).length > MAX_SOURCE)
|
|
673
727
|
return showPluginError(text("integrationsSourceTooLarge"));
|
|
674
728
|
const submit = $("#btnSaveIntegrationPlugin");
|
|
729
|
+
if (!submit)
|
|
730
|
+
return;
|
|
675
731
|
submit.disabled = true;
|
|
676
732
|
try {
|
|
677
|
-
const result = await
|
|
733
|
+
const result = await api("/channeld/plugins", {
|
|
678
734
|
method: "POST",
|
|
679
735
|
body: JSON.stringify({ name, source }),
|
|
680
736
|
});
|
|
737
|
+
if (!isRecord(result))
|
|
738
|
+
return;
|
|
681
739
|
const plugin = {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
...(result.account ? { account: result.account } : {}),
|
|
740
|
+
...result,
|
|
741
|
+
pluginId: String(result.pluginId ?? ""),
|
|
742
|
+
name: String(result.name ?? ""),
|
|
743
|
+
platform: String(result.platform ?? ""),
|
|
687
744
|
};
|
|
688
745
|
data.plugins = [...data.plugins.filter((item) => item.pluginId !== plugin.pluginId), plugin];
|
|
689
746
|
renderPlugins();
|
|
@@ -698,18 +755,18 @@ export function initIntegrations(app) {
|
|
|
698
755
|
submit.disabled = false;
|
|
699
756
|
}
|
|
700
757
|
});
|
|
701
|
-
|
|
758
|
+
accountAddEnv.addEventListener("click", () => addEnvRow(accountEnv).querySelector(".integration-env-key")?.focus());
|
|
702
759
|
accountPlugin.addEventListener("change", syncAccountSchema);
|
|
703
760
|
accountClear.addEventListener("click", () => setClearEnv(!clearEnv));
|
|
704
761
|
enabledInput.addEventListener("change", applyEnabledState);
|
|
705
|
-
addAccountButton
|
|
706
|
-
uploadPluginButton
|
|
707
|
-
$("#btnRefreshIntegrations")
|
|
762
|
+
addAccountButton?.addEventListener("click", () => openAccount(null));
|
|
763
|
+
uploadPluginButton?.addEventListener("click", openUpload);
|
|
764
|
+
$("#btnRefreshIntegrations")?.addEventListener("click", () => void load(true));
|
|
708
765
|
saveButton.addEventListener("click", () => void save());
|
|
709
|
-
$("#btnCloseIntegrationAccount")
|
|
710
|
-
$("#btnCancelIntegrationAccount")
|
|
766
|
+
$("#btnCloseIntegrationAccount")?.addEventListener("click", closeAccount);
|
|
767
|
+
$("#btnCancelIntegrationAccount")?.addEventListener("click", closeAccount);
|
|
711
768
|
accountDialog.addEventListener("cancel", (event) => { event.preventDefault(); closeAccount(); });
|
|
712
|
-
$("#btnCloseIntegrationPlugin")
|
|
713
|
-
$("#btnCancelIntegrationPlugin")
|
|
769
|
+
$("#btnCloseIntegrationPlugin")?.addEventListener("click", () => pluginDialog.close());
|
|
770
|
+
$("#btnCancelIntegrationPlugin")?.addEventListener("click", () => pluginDialog.close());
|
|
714
771
|
pluginDialog.addEventListener("cancel", (event) => { event.preventDefault(); pluginDialog.close(); });
|
|
715
772
|
}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { LS } from "./state.js";
|
|
2
2
|
import { isRoomAdmin } from "./admin-badge.js";
|
|
3
|
+
const isJoinRequest = (value) => typeof value === "object" && value !== null
|
|
4
|
+
&& "sessionID" in value && typeof value.sessionID === "string" && value.sessionID.length > 0
|
|
5
|
+
&& "name" in value && typeof value.name === "string";
|
|
6
|
+
const statusOf = (error) => error instanceof Error && "status" in error && typeof error.status === "number" ? error.status : 0;
|
|
3
7
|
// Pending join state is browser-local; the server remains authoritative.
|
|
4
8
|
export function initJoinRequests(app) {
|
|
5
|
-
const $ =
|
|
9
|
+
const $ = (selector) => {
|
|
10
|
+
const element = app.$(selector);
|
|
11
|
+
if (!element)
|
|
12
|
+
throw new Error(`Missing element: ${selector}`);
|
|
13
|
+
return element;
|
|
14
|
+
};
|
|
6
15
|
const pendingIds = (app.state.pendingJoinIds ??= new Set());
|
|
7
16
|
let pending = { roomId: "", name: "", status: "", timer: 0, generation: 0, checking: false, cancelling: false };
|
|
8
17
|
let requests = [], requestsRoomId = "", requestsGeneration = 0, requestsLoading = false, loadingRoomId = "", deniedRoomId = "";
|
|
@@ -63,7 +72,7 @@ export function initJoinRequests(app) {
|
|
|
63
72
|
clearTimeout(pending.timer);
|
|
64
73
|
if (!pending.roomId || pending.status !== "pending")
|
|
65
74
|
return;
|
|
66
|
-
pending.timer = setTimeout(() => void checkPending(), delay);
|
|
75
|
+
pending.timer = window.setTimeout(() => void checkPending(), delay);
|
|
67
76
|
}
|
|
68
77
|
async function checkPending() {
|
|
69
78
|
if (pending.checking || !pending.roomId || pending.status !== "pending")
|
|
@@ -105,7 +114,7 @@ export function initJoinRequests(app) {
|
|
|
105
114
|
catch (error) {
|
|
106
115
|
if (generation !== pending.generation)
|
|
107
116
|
return;
|
|
108
|
-
if (error
|
|
117
|
+
if (statusOf(error) === 404) {
|
|
109
118
|
pendingIds.delete(roomId);
|
|
110
119
|
pending.status = "gone";
|
|
111
120
|
app.setText(title, "joinPendingGoneTitle");
|
|
@@ -192,15 +201,13 @@ export function initJoinRequests(app) {
|
|
|
192
201
|
if (generation !== requestsGeneration || app.state.room?.id !== roomId)
|
|
193
202
|
return;
|
|
194
203
|
requestsRoomId = roomId;
|
|
195
|
-
requests = Array.isArray(data.requests)
|
|
196
|
-
? data.requests.filter((request) => request && typeof request.sessionID === "string" && request.sessionID && typeof request.name === "string")
|
|
197
|
-
: [];
|
|
204
|
+
requests = Array.isArray(data.requests) ? data.requests.filter(isJoinRequest) : [];
|
|
198
205
|
renderRequests();
|
|
199
206
|
}
|
|
200
207
|
catch (error) {
|
|
201
208
|
if (generation !== requestsGeneration || app.state.room?.id !== roomId)
|
|
202
209
|
return;
|
|
203
|
-
if (error
|
|
210
|
+
if (statusOf(error) === 403) {
|
|
204
211
|
deniedRoomId = roomId;
|
|
205
212
|
requests = [];
|
|
206
213
|
renderRequests();
|
|
@@ -219,7 +226,7 @@ export function initJoinRequests(app) {
|
|
|
219
226
|
const room = app.state.room;
|
|
220
227
|
const visible = Boolean(room && room.kind !== "direct" && room.joinPolicy === "approval" && isRoomAdmin(app) && deniedRoomId !== room.id);
|
|
221
228
|
section.hidden = !visible;
|
|
222
|
-
if (!visible) {
|
|
229
|
+
if (!room || !visible) {
|
|
223
230
|
list.textContent = "";
|
|
224
231
|
requestSignature = "";
|
|
225
232
|
updateBadge(0);
|
|
@@ -309,14 +316,14 @@ export function initJoinRequests(app) {
|
|
|
309
316
|
void app.refreshRoomMeta?.();
|
|
310
317
|
}
|
|
311
318
|
catch (error) {
|
|
312
|
-
if (error
|
|
319
|
+
if (statusOf(error) === 404) {
|
|
313
320
|
requests = requests.filter((entry) => entry.sessionID !== request.sessionID);
|
|
314
321
|
requestSignature = "";
|
|
315
322
|
app.setText($("#joinRequestsStatus"), "joinRequestAlreadyHandled");
|
|
316
323
|
renderRequests();
|
|
317
324
|
focusAfterRequest(index);
|
|
318
325
|
}
|
|
319
|
-
else if (error
|
|
326
|
+
else if (statusOf(error) === 403) {
|
|
320
327
|
deniedRoomId = room.id;
|
|
321
328
|
requests = [];
|
|
322
329
|
renderRequests();
|
|
@@ -325,8 +332,8 @@ export function initJoinRequests(app) {
|
|
|
325
332
|
item.removeAttribute("aria-busy");
|
|
326
333
|
approve.disabled = false;
|
|
327
334
|
deny.disabled = false;
|
|
328
|
-
app.setText($("#joinRequestsStatus"), "joinRequestActionFailed", { message: error.message });
|
|
329
|
-
if (error
|
|
335
|
+
app.setText($("#joinRequestsStatus"), "joinRequestActionFailed", { message: error instanceof Error ? error.message : String(error) });
|
|
336
|
+
if (statusOf(error) === 409)
|
|
330
337
|
void refreshRequests();
|
|
331
338
|
}
|
|
332
339
|
}
|
|
@@ -365,7 +372,7 @@ export function initJoinRequests(app) {
|
|
|
365
372
|
catch (error) {
|
|
366
373
|
if (generation !== pending.generation)
|
|
367
374
|
return;
|
|
368
|
-
if (error
|
|
375
|
+
if (statusOf(error) === 404) {
|
|
369
376
|
pendingIds.delete(roomId);
|
|
370
377
|
closePending();
|
|
371
378
|
($("#joinView").hidden ? $("#msgInput") : $("#inRoomId"))?.focus({ preventScroll: true });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Code masking keeps footnote syntax literal inside fences and inline spans.
|
|
2
1
|
function maskCode(value, nonce) {
|
|
3
2
|
const blocks = [];
|
|
4
3
|
const token = () => `CHATCODETOKEN${nonce}${blocks.length}END`;
|
|
@@ -19,24 +18,25 @@ function maskCode(value, nonce) {
|
|
|
19
18
|
blocks.push(line);
|
|
20
19
|
return key;
|
|
21
20
|
}),
|
|
22
|
-
restore: (text) => text.replace(new RegExp(`CHATCODETOKEN${nonce}(\\d+)END`, "g"), (_, index) => blocks[Number(index)]),
|
|
21
|
+
restore: (text) => text.replace(new RegExp(`CHATCODETOKEN${nonce}(\\d+)END`, "g"), (_, index) => blocks[Number(index)] ?? ""),
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
24
|
export function prepareFootnotes(value, nonce) {
|
|
26
25
|
const code = maskCode(value, nonce);
|
|
27
26
|
const lines = code.masked.split("\n"), definitions = new Map(), kept = [];
|
|
28
27
|
for (let index = 0; index < lines.length; index++) {
|
|
29
|
-
const
|
|
28
|
+
const line = lines[index] ?? "";
|
|
29
|
+
const match = /^ {0,3}\[\^([^\]\s]+)\]:[ \t]*(.*)$/.exec(line);
|
|
30
30
|
if (!match) {
|
|
31
|
-
kept.push(
|
|
31
|
+
kept.push(line);
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
|
-
let body = match[2].trim();
|
|
35
|
-
while (index + 1 < lines.length && /^(?: {2,}|\t)/.test(lines[index + 1])) {
|
|
34
|
+
let body = (match[2] ?? "").trim();
|
|
35
|
+
while (index + 1 < lines.length && /^(?: {2,}|\t)/.test(lines[index + 1] ?? "")) {
|
|
36
36
|
index++;
|
|
37
|
-
body += `\n${lines[index].replace(/^(?: {2,4}|\t)/, "")}`;
|
|
37
|
+
body += `\n${(lines[index] ?? "").replace(/^(?: {2,4}|\t)/, "")}`;
|
|
38
38
|
}
|
|
39
|
-
definitions.set(match[1], code.restore(body));
|
|
39
|
+
definitions.set(match[1] ?? "", code.restore(body));
|
|
40
40
|
kept.push("");
|
|
41
41
|
}
|
|
42
42
|
const references = new Map(), tokens = [], tokenLabels = [];
|