@alexsun-top/opencode-chat-room 0.7.8 → 0.8.1
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 +43 -1
- package/LICENSE +21 -0
- package/README.md +77 -36
- package/README.zh-CN.md +82 -41
- package/cli.ts +27 -1
- package/dist/cli.js +6905 -2764
- package/package.json +33 -3
- package/packages/chat-room-channeld/README.md +315 -0
- package/packages/chat-room-channeld/dist/feishu-adapter.js +1262 -0
- package/packages/chat-room-channeld/dist/mock-adapter.js +295 -0
- package/packages/chat-room-channeld/src/adapter.ts +509 -0
- package/packages/chat-room-channeld/src/cli.ts +124 -0
- package/packages/chat-room-channeld/src/config.ts +269 -0
- package/packages/chat-room-channeld/src/delivery.ts +163 -0
- package/packages/chat-room-channeld/src/feishu-adapter.ts +303 -0
- package/packages/chat-room-channeld/src/feishu-card.ts +27 -0
- package/packages/chat-room-channeld/src/feishu-inbound.ts +158 -0
- package/packages/chat-room-channeld/src/feishu-live.ts +355 -0
- package/packages/chat-room-channeld/src/feishu-send.ts +342 -0
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +173 -0
- package/packages/chat-room-channeld/src/framing.ts +128 -0
- package/packages/chat-room-channeld/src/host-helpers.ts +52 -0
- package/packages/chat-room-channeld/src/host.ts +627 -0
- package/packages/chat-room-channeld/src/inbound.ts +26 -0
- package/packages/chat-room-channeld/src/ingest-gate.ts +108 -0
- package/packages/chat-room-channeld/src/log.ts +26 -0
- package/packages/chat-room-channeld/src/mock-adapter.ts +206 -0
- package/packages/chat-room-channeld/src/protocol.ts +75 -0
- package/packages/chat-room-channeld/src/published.ts +37 -0
- package/packages/chat-room-channeld/src/rules.ts +127 -0
- package/packages/chat-room-channeld/src/state.ts +502 -0
- package/packages/chat-room-channeld/src/stats.ts +209 -0
- package/plugin.ts +22 -5
- package/server/addressing-routes.ts +130 -0
- package/server/admin-state.ts +13 -13
- package/server/app.ts +95 -0
- package/server/assets/NOTICE.txt +3 -2
- package/server/assets/SHIKI-LICENSE +22 -0
- package/server/assets/base.css +24 -10
- package/server/assets/chat/announcements.js +70 -7
- package/server/assets/chat/doc-preview.js +187 -39
- package/server/assets/chat/events.js +3 -0
- package/server/assets/chat/files.js +46 -4
- package/server/assets/chat/forward.js +69 -0
- package/server/assets/chat/index.js +4 -0
- package/server/assets/chat/integration-editor.js +163 -0
- package/server/assets/chat/integration-values.js +124 -0
- package/server/assets/chat/integrations.js +498 -0
- package/server/assets/chat/locales/de.js +45 -4
- package/server/assets/chat/locales/es.js +45 -4
- package/server/assets/chat/locales/fr.js +45 -4
- package/server/assets/chat/locales/it.js +45 -4
- package/server/assets/chat/locales/ja.js +45 -4
- package/server/assets/chat/locales/ko.js +45 -4
- package/server/assets/chat/markdown-footnotes.js +115 -0
- package/server/assets/chat/markdown.js +46 -43
- package/server/assets/chat/messages.js +5 -5
- package/server/assets/chat/office-preview.js +69 -0
- package/server/assets/chat/palette.js +1 -1
- package/server/assets/chat/panels.js +36 -0
- package/server/assets/chat/recall.js +58 -7
- package/server/assets/chat/receipts.js +15 -3
- package/server/assets/chat/reminders.js +69 -8
- package/server/assets/chat/replies.js +7 -1
- package/server/assets/chat/resource-format.js +11 -0
- package/server/assets/chat/settings.js +30 -2
- package/server/assets/chat/shiki.js +87 -0
- package/server/assets/chat/side-pane.js +9 -3
- package/server/assets/chat/state.js +107 -11
- package/server/assets/chat/system-events.js +32 -0
- package/server/assets/chat/system-messages.js +23 -12
- package/server/assets/chat/task-row.js +0 -6
- package/server/assets/chat/tasks.js +121 -33
- package/server/assets/code-highlight.css +74 -62
- package/server/assets/conversation.css +126 -25
- package/server/assets/doc-preview.css +36 -3
- package/server/assets/files.css +5 -0
- package/server/assets/fluent-icons.svg +2 -0
- package/server/assets/monaco/LICENSE +21 -0
- package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
- package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
- package/server/assets/monaco/editor.worker.js +45 -0
- package/server/assets/monaco/integration-rules.css +1 -0
- package/server/assets/monaco/integration-rules.js +1297 -0
- package/server/assets/monaco/json.worker.js +77 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
- package/server/assets/office/docx.bundle.js +33 -0
- package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
- package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
- package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
- package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
- package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
- package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
- package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
- package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
- package/server/assets/{HIGHLIGHT-LICENSE → office/licenses/zrender-LICENSE.txt} +2 -2
- package/server/assets/office/pptx.bundle.js +104 -0
- package/server/assets/office/xlsx.bundle.js +141 -0
- package/server/assets/recall.css +5 -4
- package/server/assets/responsive.css +52 -8
- package/server/assets/settings.css +73 -1
- package/server/assets/shiki.bundle.js +152 -0
- package/server/assets/tasks.css +57 -7
- package/server/channel-integration.ts +519 -0
- package/server/channel-settings.ts +77 -0
- package/server/channels.ts +557 -0
- package/server/chat-server.ts +33 -558
- package/server/chat.html +195 -22
- package/server/http-server.ts +3 -182
- package/server/resource-routes.ts +16 -16
- package/server/routes/inbox.ts +100 -0
- package/server/routes/pages.ts +83 -0
- package/server/routes/questions.ts +39 -0
- package/server/routes/room-actions.ts +162 -0
- package/server/routes/rooms.ts +160 -0
- package/server/startup.ts +84 -0
- package/server/sw.js +5 -2
- package/server/task-routes.ts +1 -1
- package/skills/chatroom/SKILL.md +1 -1
- package/src/center/center-client.ts +71 -1
- package/src/config/file-config.ts +29 -42
- package/src/platform/http-server.ts +182 -0
- package/src/protocol/addressing.ts +21 -0
- package/src/protocol/config.ts +58 -0
- package/src/protocol/room.ts +51 -0
- package/src/rooms/resources.ts +26 -16
- package/src/rooms/room-service.ts +2 -48
- package/src/rooms/storage.ts +329 -0
- package/src/rooms/tasks.ts +21 -5
- package/src/runtime/v2-plugin.ts +8 -2
- package/src/runtime/watch.ts +4 -3
- package/src/state/pg-database.ts +183 -0
- package/src/state/pg-migrate.ts +175 -0
- package/src/state/pg-sql.mjs +175 -0
- package/src/state/pg-worker.mjs +148 -0
- package/src/state/sqlite-announcements.ts +25 -0
- package/src/state/sqlite-database.ts +121 -0
- package/src/state/sqlite-legacy.ts +90 -0
- package/src/state/sqlite-members.ts +155 -0
- package/src/state/sqlite-messages.ts +288 -0
- package/src/state/sqlite-resources.ts +39 -0
- package/src/state/sqlite-rooms.ts +87 -0
- package/src/state/sqlite-schema.ts +80 -0
- package/src/state/sqlite-state-store.ts +33 -0
- package/src/state/sqlite-state.ts +15 -866
- package/src/state/sqlite-tasks.ts +65 -0
- package/src/state/sqlite-transaction.ts +13 -0
- package/src/state/sqlite.ts +21 -1
- package/src/state/store.ts +13 -3
- package/src/tui/app.mjs +32 -19
- package/src/tui/config.mjs +12 -4
- package/src/tui/http.mjs +16 -2
- package/src/tui/i18n.mjs +38 -0
- package/src/tui/info-app.mjs +50 -51
- package/src/tui/info-content.mjs +79 -44
- package/src/tui/join-app.mjs +9 -9
- package/src/tui/locales/en.mjs +349 -0
- package/src/tui/locales/zh-CN.mjs +349 -0
- package/src/tui/main.mjs +85 -37
- package/src/tui/markdown.mjs +3 -2
- package/src/tui/mentions.mjs +3 -1
- package/src/tui/message-app.mjs +22 -21
- package/src/tui/message-view.mjs +2 -1
- package/src/tui/palette-app.mjs +9 -8
- package/src/tui/palette.mjs +30 -24
- package/src/tui/prefs.mjs +92 -0
- package/src/tui/reminder-app.mjs +18 -17
- package/src/tui/room-settings-app.mjs +30 -28
- package/src/tui/settings-app.mjs +153 -0
- package/src/tui/ui-content.mjs +65 -86
- package/src/tui/ui-help.mjs +73 -0
- package/src/tui/ui-overlay-view.mjs +23 -7
- package/src/tui/ui-suggest.mjs +6 -5
- package/src/tui/ui-theme.mjs +37 -33
- package/src/tui/ui-view.mjs +22 -7
- package/src/tui/ui.mjs +15 -3
- package/src/web/editor.worker.ts +1 -0
- package/src/web/integration-rules-editor.ts +439 -0
- package/src/web/integration-rules.ts +22 -0
- package/src/web/integration-schema.ts +228 -0
- package/src/web/json.worker.ts +1 -0
- package/src/web/office-viewer.ts +221 -0
- package/server/assets/highlight-10.7.3.min.js +0 -1358
|
@@ -42,6 +42,12 @@ export function initRecall(app) {
|
|
|
42
42
|
if (revealTarget && app.state.room) {
|
|
43
43
|
const message = app.state.room.messages.find((item) => item.id === revealTarget.dataset.revealMessage);
|
|
44
44
|
if (message) void toggleOriginal(revealTarget, message, app);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const reeditTarget = event.target.closest?.("[data-reedit-message]");
|
|
48
|
+
if (reeditTarget && app.state.room) {
|
|
49
|
+
const message = app.state.room.messages.find((item) => item.id === reeditTarget.dataset.reeditMessage);
|
|
50
|
+
if (message) void reedit(message, reeditTarget, app);
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
53
|
|
|
@@ -195,7 +201,11 @@ function renderTombstone(row, message, app, live) {
|
|
|
195
201
|
const shown = Boolean(message._revealed) && message._revealedText !== undefined;
|
|
196
202
|
body.hidden = !shown;
|
|
197
203
|
setRevealButton(reveal, shown, app);
|
|
198
|
-
|
|
204
|
+
const actions = document.createElement("div");
|
|
205
|
+
actions.className = "recalled-actions";
|
|
206
|
+
actions.append(reveal);
|
|
207
|
+
if (isOwnMessage(message, app)) actions.append(reeditButton(message, app));
|
|
208
|
+
bubble.append(body, actions);
|
|
199
209
|
if (live) { row.classList.remove("recalled-in"); void row.offsetWidth; row.classList.add("recalled-in"); }
|
|
200
210
|
return row;
|
|
201
211
|
}
|
|
@@ -227,6 +237,15 @@ function renderSystemTombstone(row, message, app, live) {
|
|
|
227
237
|
return row;
|
|
228
238
|
}
|
|
229
239
|
|
|
240
|
+
function reeditButton(message, app) {
|
|
241
|
+
const button = document.createElement("button");
|
|
242
|
+
button.type = "button";
|
|
243
|
+
button.className = "recalled-reedit";
|
|
244
|
+
button.dataset.reeditMessage = message.id;
|
|
245
|
+
button.textContent = app.t("reeditMessage");
|
|
246
|
+
return button;
|
|
247
|
+
}
|
|
248
|
+
|
|
230
249
|
function fillRevealed(body, message, text, app) {
|
|
231
250
|
body.textContent = "";
|
|
232
251
|
if (message.senderId === "system") body.textContent = formatSystemMessage({ senderId: "system", text }, app);
|
|
@@ -240,7 +259,7 @@ function setRevealButton(button, shown, app) {
|
|
|
240
259
|
|
|
241
260
|
async function toggleOriginal(button, message, app) {
|
|
242
261
|
if (button.disabled) return;
|
|
243
|
-
const body = button.
|
|
262
|
+
const body = button.closest(".msg-text, .sys")?.querySelector(".recalled-body");
|
|
244
263
|
if (!body) return;
|
|
245
264
|
if (message._revealedText !== undefined) {
|
|
246
265
|
message._revealed = !message._revealed;
|
|
@@ -251,11 +270,7 @@ async function toggleOriginal(button, message, app) {
|
|
|
251
270
|
button.disabled = true;
|
|
252
271
|
setRevealButton(button, false, app);
|
|
253
272
|
try {
|
|
254
|
-
const
|
|
255
|
-
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/messages/${encodeURIComponent(message.id)}/content?sessionID=${encodeURIComponent(LS.sessionID)}`);
|
|
256
|
-
const text = typeof result?.message?.text === "string" ? result.message.text : typeof result?.text === "string" ? result.text : undefined;
|
|
257
|
-
if (text === undefined) throw new Error(app.t("revealFailed"));
|
|
258
|
-
message._revealedText = text;
|
|
273
|
+
const text = await loadOriginalText(message, app);
|
|
259
274
|
message._revealed = true;
|
|
260
275
|
fillRevealed(body, message, text, app);
|
|
261
276
|
body.hidden = false;
|
|
@@ -265,4 +280,40 @@ async function toggleOriginal(button, message, app) {
|
|
|
265
280
|
} finally {
|
|
266
281
|
button.disabled = false;
|
|
267
282
|
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function loadOriginalText(message, app) {
|
|
286
|
+
if (message._revealedText !== undefined) return message._revealedText;
|
|
287
|
+
const roomId = app.state.room?.id;
|
|
288
|
+
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/messages/${encodeURIComponent(message.id)}/content?sessionID=${encodeURIComponent(LS.sessionID)}`);
|
|
289
|
+
const text = typeof result?.message?.text === "string" ? result.message.text : typeof result?.text === "string" ? result.text : undefined;
|
|
290
|
+
if (text === undefined) throw new Error(app.t("revealFailed"));
|
|
291
|
+
message._revealedText = text;
|
|
292
|
+
return text;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function reedit(message, button, app) {
|
|
296
|
+
const roomId = app.state.room?.id, input = app.$("#msgInput");
|
|
297
|
+
if (!roomId || !input || button.disabled || !isOwnMessage(message, app)) return;
|
|
298
|
+
if (input.draftValue.trim() && !(await app.confirmAction(app.t("reeditReplaceDraft")))) return;
|
|
299
|
+
button.disabled = true;
|
|
300
|
+
try {
|
|
301
|
+
const text = await loadOriginalText(message, app);
|
|
302
|
+
if (app.state.room?.id !== roomId) return;
|
|
303
|
+
input.draftValue = text;
|
|
304
|
+
app.saveDraft(roomId, text);
|
|
305
|
+
app.autoGrow(input);
|
|
306
|
+
app.updateDraftCount();
|
|
307
|
+
app.updateSendState();
|
|
308
|
+
// A click is explicit intent, so focus the editor even on touch layouts.
|
|
309
|
+
if (!app.focusChatComposer({ force: true })) {
|
|
310
|
+
input.focus({ preventScroll: true });
|
|
311
|
+
input.setCaret?.(input.value.length);
|
|
312
|
+
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (error.status === 401) app.openChatSettings();
|
|
315
|
+
app.showSendError(error.status === 401 ? "sendAuth" : "revealFailed", { message: error.message });
|
|
316
|
+
} finally {
|
|
317
|
+
button.disabled = false;
|
|
318
|
+
}
|
|
268
319
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { pointerOrSelectionActive } from "./message-window.js";
|
|
2
|
+
import { icon } from "./icons.js";
|
|
3
|
+
|
|
4
|
+
const READ_ALL_ICON = icon("checkmark", "message-read-check");
|
|
2
5
|
|
|
3
6
|
export function initReceipts(app) {
|
|
4
7
|
const $ = app.$, panel = $("#readerPanel");
|
|
@@ -96,14 +99,23 @@ export function initReceipts(app) {
|
|
|
96
99
|
}
|
|
97
100
|
function updateButton(button, message, own = button.dataset.ownMessage === "true") {
|
|
98
101
|
const readers = readersFor(message), count = readers.length, known = hasReceiptData(message);
|
|
99
|
-
const
|
|
102
|
+
const allRead = own && known && readByEveryone(message, readers);
|
|
103
|
+
const label = allRead ? app.t("receiptAllRead") : readerStatus(message, readers);
|
|
100
104
|
button.hidden = !own && count === 0;
|
|
101
|
-
button.
|
|
102
|
-
button.
|
|
105
|
+
if (allRead) button.innerHTML = READ_ALL_ICON;
|
|
106
|
+
else button.textContent = String(count || (known ? 0 : "…"));
|
|
107
|
+
button.dataset.readerState = allRead ? "all" : count ? "read" : known ? "empty" : "unknown";
|
|
103
108
|
button.setAttribute("aria-label", label);
|
|
104
109
|
button.setAttribute("aria-expanded", String(selectedID === message.id));
|
|
105
110
|
button.title = label;
|
|
106
111
|
}
|
|
112
|
+
function readByEveryone(message, readers) {
|
|
113
|
+
const senderID = message.senderSessionID || (app.state.room?.kind === "direct" ? message.senderId : "");
|
|
114
|
+
const eligible = (app.state.memberSessions.get(app.state.room?.id) || []).filter((member) => member.sessionID && member.sessionID !== senderID);
|
|
115
|
+
if (!eligible.length) return false;
|
|
116
|
+
const seen = new Set(readers.map((reader) => reader.sessionID));
|
|
117
|
+
return eligible.every((member) => seen.has(member.sessionID));
|
|
118
|
+
}
|
|
107
119
|
function readersFor(message) {
|
|
108
120
|
const key = receiptKey(message);
|
|
109
121
|
const senderID = message.senderSessionID || (app.state.room?.kind === "direct" ? message.senderId : "");
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { LS } from "./state.js";
|
|
2
2
|
|
|
3
3
|
export function initReminders(app) {
|
|
4
|
-
const $ = app.$,
|
|
5
|
-
const
|
|
4
|
+
const $ = app.$, surface = $("#remindersDialog"), trigger = $("#btnReminders"), list = $("#reminderList");
|
|
5
|
+
const dialog = $("#reminderDialog"), newButton = $("#btnNewReminder");
|
|
6
|
+
const heading = $("#reminderDialogHeading"), panelHeading = $("#reminderHeading"), submit = $("#btnSubmitReminder");
|
|
7
|
+
const chatView = $("#chatView");
|
|
6
8
|
app.setText($("#reminderTemplateHint"), "reminderTemplateHint", { time: "{time}", initiator: "{initiator}", room: "{room}" });
|
|
7
9
|
let reminders = [], generation = 0, roomGeneration = 0, activeRoomId, editing = null, createDraft = null, saving = false, saveToken = 0;
|
|
10
|
+
let opener = null, pendingReopen = false, restoreSurfaceFocus = true;
|
|
8
11
|
const drafts = new Map();
|
|
9
12
|
const roomId = () => app.state.room?.id;
|
|
10
13
|
const status = (text) => { $("#reminderStatus").textContent = text; };
|
|
@@ -23,6 +26,47 @@ export function initReminders(app) {
|
|
|
23
26
|
if (!dialog.open) dialog.showModal();
|
|
24
27
|
$("#reminderText").focus();
|
|
25
28
|
}
|
|
29
|
+
const clearPane = () => {
|
|
30
|
+
surface.classList.remove("is-pane");
|
|
31
|
+
if (chatView.dataset.sidePane !== "reminders") return;
|
|
32
|
+
delete chatView.dataset.sidePane;
|
|
33
|
+
chatView.classList.remove("has-pane");
|
|
34
|
+
};
|
|
35
|
+
const showSurface = () => {
|
|
36
|
+
if (app.panelPlacement("reminders") === "pane") {
|
|
37
|
+
app.closeOtherPanelSurfaces?.("reminders");
|
|
38
|
+
surface.classList.add("is-pane");
|
|
39
|
+
chatView.classList.add("has-pane");
|
|
40
|
+
chatView.dataset.sidePane = "reminders";
|
|
41
|
+
if (!surface.open) surface.show();
|
|
42
|
+
} else {
|
|
43
|
+
clearPane();
|
|
44
|
+
if (!surface.open) surface.showModal();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const syncMode = () => {
|
|
48
|
+
if (!surface.open || (app.panelPlacement("reminders") === "pane") === surface.classList.contains("is-pane")) return;
|
|
49
|
+
pendingReopen = true;
|
|
50
|
+
surface.close();
|
|
51
|
+
showSurface();
|
|
52
|
+
panelHeading.focus({ preventScroll: true });
|
|
53
|
+
};
|
|
54
|
+
const closeSurface = (focus = true) => {
|
|
55
|
+
restoreSurfaceFocus = focus;
|
|
56
|
+
if (surface.open) surface.close();
|
|
57
|
+
};
|
|
58
|
+
function openSurface() {
|
|
59
|
+
if (!roomId()) return;
|
|
60
|
+
if (app.panelPlacement("reminders") === "pane") app.closeDocPreview?.(false);
|
|
61
|
+
if (surface.open) { panelHeading.focus(); return; }
|
|
62
|
+
app.closePanels?.();
|
|
63
|
+
const active = document.activeElement;
|
|
64
|
+
opener = active instanceof HTMLElement && active !== document.body && !active.closest("dialog") && !$("#roomOptions")?.contains(active)
|
|
65
|
+
? active : $("#btnRoomOptions");
|
|
66
|
+
showSurface();
|
|
67
|
+
panelHeading.focus();
|
|
68
|
+
void load();
|
|
69
|
+
}
|
|
26
70
|
const current = (id, context) => roomId() === id && roomGeneration === context;
|
|
27
71
|
const invalidateLoads = () => { generation++; };
|
|
28
72
|
const errorText = (error) => error?.message || app.t("requestFailed", { status: error?.status || "?" });
|
|
@@ -142,16 +186,33 @@ export function initReminders(app) {
|
|
|
142
186
|
$("#btnCancelReminder").addEventListener("click", () => dialog.close());
|
|
143
187
|
dialog.addEventListener("click", (event) => { if (event.target === dialog) dialog.close(); });
|
|
144
188
|
dialog.addEventListener("close", () => { editing = null; });
|
|
145
|
-
trigger.addEventListener("click", () => {
|
|
146
|
-
|
|
147
|
-
|
|
189
|
+
trigger.addEventListener("click", () => { app.closePanels(); openSurface(); });
|
|
190
|
+
$("#btnCloseReminders").addEventListener("click", () => closeSurface());
|
|
191
|
+
surface.addEventListener("click", (event) => { if (event.target === surface) closeSurface(); });
|
|
192
|
+
surface.addEventListener("cancel", (event) => { event.preventDefault(); closeSurface(); });
|
|
193
|
+
surface.addEventListener("close", () => {
|
|
194
|
+
if (pendingReopen) { pendingReopen = false; return; }
|
|
195
|
+
clearPane();
|
|
196
|
+
const focus = restoreSurfaceFocus;
|
|
197
|
+
restoreSurfaceFocus = true;
|
|
198
|
+
const target = opener;
|
|
199
|
+
opener = null;
|
|
200
|
+
if (focus && target?.isConnected) target.focus({ preventScroll: true });
|
|
201
|
+
});
|
|
202
|
+
document.addEventListener("keydown", (event) => {
|
|
203
|
+
if (event.key !== "Escape" || !surface.open || !surface.classList.contains("is-pane")) return;
|
|
204
|
+
if (!surface.contains(document.activeElement)) return;
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
closeSurface();
|
|
148
207
|
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
208
|
+
app.registerPanelSurface?.("reminders", { close: () => closeSurface(false) });
|
|
209
|
+
app.watchPanel?.("reminders", syncMode);
|
|
210
|
+
const closePanels = app.closePanels;
|
|
211
|
+
app.closePanels = () => { closePanels(); if (dialog.open) dialog.close(); };
|
|
152
212
|
document.addEventListener("chat-room-activated", (event) => {
|
|
153
213
|
if (activeRoomId) drafts.set(activeRoomId, createDraft ?? formDraft());
|
|
154
214
|
if (dialog.open) dialog.close();
|
|
215
|
+
if (surface.open && !surface.classList.contains("is-pane")) closeSurface(false);
|
|
155
216
|
formStatus("");
|
|
156
217
|
editing = null; createDraft = null; saving = false; saveToken++; submit.disabled = false;
|
|
157
218
|
activeRoomId = event.detail; restoreDraft(drafts.get(activeRoomId));
|
|
@@ -33,7 +33,7 @@ function bindMessageActions(app) {
|
|
|
33
33
|
const render = app.renderMessage;
|
|
34
34
|
app.renderMessage = (message, live) => {
|
|
35
35
|
const row = render(message, live);
|
|
36
|
-
if (message.senderId === "system" || message.pending) return row;
|
|
36
|
+
if (message.senderId === "system" || message.pending || message.recalledAt) return row;
|
|
37
37
|
if (message.answerToMessageID) row.querySelector(".msg-meta")?.after(quoteButton(message, app));
|
|
38
38
|
const copy = row.querySelector("[data-copy-message]");
|
|
39
39
|
if (copy) {
|
|
@@ -42,6 +42,12 @@ function bindMessageActions(app) {
|
|
|
42
42
|
reply.type = "button"; reply.className = "message-reply"; reply.innerHTML = icon("arrow_reply", "message-reply-icon");
|
|
43
43
|
reply.setAttribute("aria-label", app.t("replyMessage")); reply.dataset.i18nAriaLabel = "replyMessage"; reply.dataset.replyMessage = message.id;
|
|
44
44
|
copy.before(actions); actions.append(copy, reply);
|
|
45
|
+
if (document.body.dataset.channeld === "on") {
|
|
46
|
+
const forward = document.createElement("button");
|
|
47
|
+
forward.type = "button"; forward.className = "message-reply message-forward"; forward.innerHTML = icon("arrow_right", "message-reply-icon");
|
|
48
|
+
forward.setAttribute("aria-label", app.t("forwardMessage")); forward.dataset.i18nAriaLabel = "forwardMessage"; forward.dataset.forwardMessage = message.id;
|
|
49
|
+
actions.append(forward);
|
|
50
|
+
}
|
|
45
51
|
}
|
|
46
52
|
return row;
|
|
47
53
|
};
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
// sniffs text and PDF uploads as application/octet-stream, so the filename
|
|
3
3
|
// extension is a first-class signal alongside the MIME type.
|
|
4
4
|
export const TEXT_PREVIEW_LIMIT = 2 * 1024 * 1024;
|
|
5
|
+
// Office files are zipped XML packages; the viewer needs far more room than text.
|
|
6
|
+
export const OFFICE_PREVIEW_LIMIT = 20 * 1024 * 1024;
|
|
7
|
+
export const OFFICE_KINDS = new Set(["docx", "xlsx", "pptx"]);
|
|
8
|
+
const OFFICE_MIMES = {
|
|
9
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
10
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
11
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
|
|
12
|
+
};
|
|
5
13
|
|
|
6
14
|
const MIME_LANGUAGES = {
|
|
7
15
|
"application/json": "json", "application/ld+json": "json",
|
|
@@ -65,6 +73,9 @@ export function docPreviewFormat(resource) {
|
|
|
65
73
|
if (mime === "text/markdown" || mime === "text/x-markdown" || ext === "md" || ext === "markdown") {
|
|
66
74
|
return { kind: "markdown", language: "", label: "" };
|
|
67
75
|
}
|
|
76
|
+
// Server sniffing reports Office packages as octet-stream, so the extension counts.
|
|
77
|
+
const office = OFFICE_MIMES[mime] || (OFFICE_KINDS.has(ext) ? ext : "");
|
|
78
|
+
if (office) return { kind: office, language: "", label: office.toUpperCase() };
|
|
68
79
|
const knownExtension = Object.hasOwn(EXTENSION_LANGUAGES, ext);
|
|
69
80
|
if (!knownExtension && !isTextMime(mime)) return null;
|
|
70
81
|
const language = knownExtension ? EXTENSION_LANGUAGES[ext] : MIME_LANGUAGES[mime] || "";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Browser settings shared by the join page and the chat: language, theme, and the optional token.
|
|
1
|
+
// Browser settings shared by the join page and the chat: language, theme, window frame, and the optional token.
|
|
2
2
|
export const THEMES = ["system", "light", "dark", "forest", "sand"];
|
|
3
3
|
|
|
4
4
|
export function initSettings(app) {
|
|
@@ -8,19 +8,29 @@ export function initSettings(app) {
|
|
|
8
8
|
const tokenInput = $("#inTokenChat"), tokenHint = $("#tokenHint");
|
|
9
9
|
const contentInput = $("#inContentTransition");
|
|
10
10
|
const pageInput = $("#inPageStep"), pageValue = $("#pageStepValue");
|
|
11
|
+
const frameSelect = $("#inWindowFrame");
|
|
12
|
+
const panelInputs = [...dialog.querySelectorAll("[data-panel-mode]")];
|
|
13
|
+
if (document.body.dataset.integrationsAdmin !== "true") {
|
|
14
|
+
$("#settingsTabIntegrations")?.remove();
|
|
15
|
+
$("#settingsPanelIntegrations")?.remove();
|
|
16
|
+
}
|
|
11
17
|
const tabs = [...dialog.querySelectorAll('[role="tab"]')];
|
|
12
18
|
const scheme = matchMedia("(prefers-color-scheme: dark)");
|
|
13
19
|
let opener = null;
|
|
14
20
|
|
|
15
21
|
const syncThemeColor = () => {
|
|
16
22
|
const meta = document.querySelector('meta[name="theme-color"]');
|
|
17
|
-
const
|
|
23
|
+
const token = document.documentElement.dataset.windowFrame === "borderless" ? "--surface" : "--bg";
|
|
24
|
+
const background = getComputedStyle(document.documentElement).getPropertyValue(token).trim();
|
|
18
25
|
if (meta && background) meta.content = background;
|
|
19
26
|
};
|
|
20
27
|
const syncThemeInputs = () => {
|
|
21
28
|
const stored = THEMES.includes(app.LS.theme) ? app.LS.theme : "system";
|
|
22
29
|
for (const input of dialog.querySelectorAll('input[name="theme"]')) input.checked = input.value === stored;
|
|
23
30
|
};
|
|
31
|
+
const syncPanelInputs = () => {
|
|
32
|
+
for (const select of panelInputs) select.value = app.panelMode(select.dataset.panelMode);
|
|
33
|
+
};
|
|
24
34
|
const applyTheme = (value, persist) => {
|
|
25
35
|
const theme = THEMES.includes(value) ? value : "system";
|
|
26
36
|
document.documentElement.dataset.theme = theme;
|
|
@@ -31,6 +41,16 @@ export function initSettings(app) {
|
|
|
31
41
|
app.setTheme = (value) => applyTheme(value, true);
|
|
32
42
|
app.settingsOpen = () => dialog.open;
|
|
33
43
|
|
|
44
|
+
const framePreference = () => app.LS.windowFrame === "borderless" ? "borderless" : "framed";
|
|
45
|
+
const applyWindowFrame = (mode, persist) => {
|
|
46
|
+
const preference = mode === "borderless" ? "borderless" : "framed";
|
|
47
|
+
document.documentElement.dataset.windowFrame = preference;
|
|
48
|
+
if (frameSelect) frameSelect.value = preference;
|
|
49
|
+
if (persist) app.LS.windowFrame = preference;
|
|
50
|
+
syncThemeColor();
|
|
51
|
+
};
|
|
52
|
+
app.setWindowFrame = (value) => applyWindowFrame(value, true);
|
|
53
|
+
|
|
34
54
|
// One tab stop for the whole tablist; arrow keys move selection like a native tab widget.
|
|
35
55
|
const activateTab = (name, { focus = false } = {}) => {
|
|
36
56
|
for (const tab of tabs) {
|
|
@@ -41,6 +61,7 @@ export function initSettings(app) {
|
|
|
41
61
|
if (panel) panel.hidden = !selected;
|
|
42
62
|
if (selected && focus) tab.focus();
|
|
43
63
|
}
|
|
64
|
+
if (name === "integrations") app.loadIntegrations?.();
|
|
44
65
|
};
|
|
45
66
|
const onTabKey = (event) => {
|
|
46
67
|
const index = tabs.indexOf(event.target);
|
|
@@ -59,6 +80,8 @@ export function initSettings(app) {
|
|
|
59
80
|
const open = ({ token = false } = {}) => {
|
|
60
81
|
app.closePanels?.();
|
|
61
82
|
syncThemeInputs();
|
|
83
|
+
syncPanelInputs();
|
|
84
|
+
applyWindowFrame(framePreference(), false);
|
|
62
85
|
if (contentInput) contentInput.checked = app.LS.contentTransition;
|
|
63
86
|
if (pageInput) pageInput.value = String(app.LS.pageStep);
|
|
64
87
|
if (pageValue) pageValue.textContent = `${app.LS.pageStep}%`;
|
|
@@ -96,6 +119,10 @@ export function initSettings(app) {
|
|
|
96
119
|
});
|
|
97
120
|
dialog.addEventListener("change", (event) => {
|
|
98
121
|
if (event.target instanceof HTMLInputElement && event.target.name === "theme") app.setTheme(event.target.value);
|
|
122
|
+
if (event.target === frameSelect) app.setWindowFrame(frameSelect.value);
|
|
123
|
+
if (event.target instanceof HTMLSelectElement && event.target.dataset.panelMode) {
|
|
124
|
+
app.setPanelMode(event.target.dataset.panelMode, event.target.value);
|
|
125
|
+
}
|
|
99
126
|
if (event.target === contentInput) app.LS.contentTransition = contentInput.checked;
|
|
100
127
|
if (event.target === pageInput) {
|
|
101
128
|
app.LS.pageStep = pageInput.value;
|
|
@@ -114,4 +141,5 @@ export function initSettings(app) {
|
|
|
114
141
|
scheme.addEventListener("change", () => { if (app.LS.theme === "system") syncThemeColor(); });
|
|
115
142
|
|
|
116
143
|
applyTheme(app.LS.theme, false);
|
|
144
|
+
applyWindowFrame(framePreference(), false);
|
|
117
145
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Lazy Shiki highlighting. The bundle is fetched on the first fenced code block,
|
|
2
|
+
// so a conversation without code never downloads or parses it.
|
|
3
|
+
|
|
4
|
+
const LANGUAGE_ALIASES = new Map([
|
|
5
|
+
["ts", "typescript"], ["typescript", "typescript"],
|
|
6
|
+
["tsx", "tsx"],
|
|
7
|
+
["js", "javascript"], ["javascript", "javascript"], ["mjs", "javascript"], ["cjs", "javascript"], ["node", "javascript"],
|
|
8
|
+
["jsx", "jsx"],
|
|
9
|
+
["json", "json"], ["jsonc", "json"],
|
|
10
|
+
["bash", "shellscript"], ["sh", "shellscript"], ["zsh", "shellscript"],
|
|
11
|
+
["shell", "shellscript"], ["shellscript", "shellscript"], ["console", "shellscript"],
|
|
12
|
+
["yml", "yaml"], ["yaml", "yaml"],
|
|
13
|
+
["md", "markdown"], ["markdown", "markdown"],
|
|
14
|
+
["py", "python"], ["python", "python"],
|
|
15
|
+
["rs", "rust"], ["rust", "rust"],
|
|
16
|
+
["go", "go"], ["golang", "go"],
|
|
17
|
+
["java", "java"],
|
|
18
|
+
["sql", "sql"],
|
|
19
|
+
["html", "html"], ["htm", "html"],
|
|
20
|
+
["xml", "xml"], ["svg", "xml"], ["xsl", "xml"],
|
|
21
|
+
["css", "css"],
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const pending = new Set();
|
|
25
|
+
let highlighterPromise;
|
|
26
|
+
let failed = false;
|
|
27
|
+
let warned = false;
|
|
28
|
+
|
|
29
|
+
function warnOnce(error) {
|
|
30
|
+
if (warned) return;
|
|
31
|
+
warned = true;
|
|
32
|
+
console.warn("Syntax highlighting unavailable; showing plain code.", error);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getHighlighter() {
|
|
36
|
+
if (failed) return null;
|
|
37
|
+
highlighterPromise ??= import("/assets/shiki.bundle.js")
|
|
38
|
+
.then((module) => module.createHighlighter())
|
|
39
|
+
.catch((error) => {
|
|
40
|
+
failed = true;
|
|
41
|
+
warnOnce(error);
|
|
42
|
+
return null;
|
|
43
|
+
});
|
|
44
|
+
return highlighterPromise;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function languageOf(code) {
|
|
48
|
+
return (/language-(\S+)/.exec(code.className) || [])[1]?.toLowerCase() || "";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Returns Shiki's HTML (it escapes the code text) or null for an unknown or failed language.
|
|
52
|
+
export async function highlightToHtml(code, lang) {
|
|
53
|
+
const language = LANGUAGE_ALIASES.get(String(lang || "").toLowerCase());
|
|
54
|
+
if (!language) return null;
|
|
55
|
+
try {
|
|
56
|
+
const highlighter = await getHighlighter();
|
|
57
|
+
if (!highlighter) return null;
|
|
58
|
+
return highlighter.codeToHtml(code, { lang: language, theme: "chatroom" });
|
|
59
|
+
} catch (error) {
|
|
60
|
+
warnOnce(error);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function whenShikiIdle() {
|
|
66
|
+
return Promise.allSettled([...pending]);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Replaces the escaped text inside one code element, leaving the surrounding
|
|
70
|
+
// pre, toolbar, wrap state, and copy button alone.
|
|
71
|
+
export function enhanceCodeElement(code) {
|
|
72
|
+
const task = embed(code).catch(() => {}).finally(() => pending.delete(task));
|
|
73
|
+
pending.add(task);
|
|
74
|
+
return task;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function embed(code) {
|
|
78
|
+
if (!LANGUAGE_ALIASES.has(languageOf(code))) return;
|
|
79
|
+
const markup = await highlightToHtml(code.textContent || "", languageOf(code));
|
|
80
|
+
if (!markup || !code.isConnected) return;
|
|
81
|
+
const template = document.createElement("template");
|
|
82
|
+
template.innerHTML = markup;
|
|
83
|
+
const rendered = template.content.querySelector("code");
|
|
84
|
+
if (!rendered) return;
|
|
85
|
+
code.replaceChildren(...rendered.childNodes);
|
|
86
|
+
code.classList.add("shiki");
|
|
87
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
const STORAGE_KEY = "chat.sidePaneWidth";
|
|
5
5
|
const MIN_WIDTH = 360;
|
|
6
6
|
const MIN_CHAT = 420;
|
|
7
|
+
const WIDE_TASKS_MIN_CHAT = 700;
|
|
7
8
|
const RAIL_WIDTH = 252;
|
|
8
9
|
const GUTTER = 8;
|
|
9
10
|
const MAX_WIDTH = 960;
|
|
@@ -12,7 +13,6 @@ export function initSidePaneSplitter(app) {
|
|
|
12
13
|
const view = app.$("#chatView");
|
|
13
14
|
const handle = app.$("#sidePaneHandle");
|
|
14
15
|
const preview = app.$("#docPreview");
|
|
15
|
-
const tasks = app.$("#tasksDialog");
|
|
16
16
|
if (!view || !handle) return;
|
|
17
17
|
|
|
18
18
|
let stored = readStored();
|
|
@@ -22,10 +22,16 @@ export function initSidePaneSplitter(app) {
|
|
|
22
22
|
let drag = null;
|
|
23
23
|
|
|
24
24
|
const activePane = () => view.classList.contains("has-doc") ? preview
|
|
25
|
-
: view.classList.contains("has-
|
|
25
|
+
: view.classList.contains("has-pane") ? view.querySelector(":scope > dialog.is-pane[open]") : null;
|
|
26
|
+
|
|
27
|
+
// A wide task board must leave the conversation a full working column; the
|
|
28
|
+
// Markdown preview keeps the normal minimum.
|
|
29
|
+
const wideTasks = () => view.classList.contains("has-tasks") && !view.classList.contains("has-doc")
|
|
30
|
+
&& window.matchMedia("(min-width: 1500px) and (min-height: 900px)").matches;
|
|
31
|
+
const minChat = () => wideTasks() ? WIDE_TASKS_MIN_CHAT : MIN_CHAT;
|
|
26
32
|
|
|
27
33
|
const maxWidth = () => {
|
|
28
|
-
const available = view.clientWidth - RAIL_WIDTH - GUTTER -
|
|
34
|
+
const available = view.clientWidth - RAIL_WIDTH - GUTTER - minChat();
|
|
29
35
|
return Math.max(MIN_WIDTH, Math.min(window.innerWidth * 0.7, MAX_WIDTH, available));
|
|
30
36
|
};
|
|
31
37
|
const clamp = (width) => Math.max(MIN_WIDTH, Math.min(width, maxWidth()));
|