@alexsun-top/opencode-chat-room 0.7.6 → 0.7.8
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 +32 -0
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/dist/cli.js +815 -192
- package/package.json +3 -2
- package/plugin.ts +15 -3
- package/server/assets/base.css +0 -2
- package/server/assets/chat/announcements.js +5 -2
- package/server/assets/chat/clipboard.js +30 -0
- package/server/assets/chat/copy-action.js +48 -0
- package/server/assets/chat/diagram-viewer.js +253 -0
- package/server/assets/chat/doc-preview.js +160 -13
- package/server/assets/chat/editor.js +10 -7
- package/server/assets/chat/events.js +26 -5
- package/server/assets/chat/files.js +26 -5
- package/server/assets/chat/history-loader.js +3 -1
- package/server/assets/chat/index.js +11 -1
- package/server/assets/chat/join-requests.js +6 -3
- package/server/assets/chat/locales/de.js +20 -2
- package/server/assets/chat/locales/es.js +20 -2
- package/server/assets/chat/locales/fr.js +20 -2
- package/server/assets/chat/locales/it.js +20 -2
- package/server/assets/chat/locales/ja.js +20 -2
- package/server/assets/chat/locales/ko.js +20 -2
- package/server/assets/chat/markdown.js +75 -86
- package/server/assets/chat/messages.js +7 -3
- package/server/assets/chat/palette.js +40 -18
- package/server/assets/chat/pwa.js +2 -0
- package/server/assets/chat/questions.js +6 -0
- package/server/assets/chat/resource-format.js +74 -0
- package/server/assets/chat/rooms.js +9 -1
- package/server/assets/chat/shortcuts.js +14 -3
- package/server/assets/chat/side-pane.js +136 -0
- package/server/assets/chat/state.js +85 -8
- package/server/assets/chat/system-messages.js +3 -1
- package/server/assets/chat/task-form.js +197 -0
- package/server/assets/chat/task-row.js +170 -0
- package/server/assets/chat/tasks.js +521 -0
- package/server/assets/chat/viewport.js +5 -0
- package/server/assets/conversation.css +25 -1
- package/server/assets/diagram-viewer.css +141 -0
- package/server/assets/doc-preview.css +24 -5
- package/server/assets/responsive.css +108 -14
- package/server/assets/tasks.css +419 -0
- package/server/chat-server.ts +9 -4
- package/server/chat.html +120 -21
- package/server/member-routes.ts +3 -0
- package/server/resource-routes.ts +3 -1
- package/server/sw.js +247 -4
- package/server/task-routes.ts +53 -0
- package/skills/chatroom/SKILL.md +3 -1
- package/src/README.md +3 -3
- package/src/agent/chatroom-skill.ts +8 -2
- package/src/agent/task-tool.ts +155 -0
- package/src/center/center-client.ts +44 -0
- package/src/rooms/resources.ts +2 -2
- package/src/rooms/tasks.ts +246 -0
- package/src/runtime/v2-plugin.ts +11 -2
- package/src/runtime/watch.ts +38 -5
- package/src/state/sqlite-state.ts +93 -8
- package/src/state/store.ts +2 -2
- package/src/tui/app.mjs +14 -4
- package/src/tui/http.mjs +2 -2
- package/src/tui/info-app.mjs +24 -15
- package/src/tui/join-app.mjs +3 -3
- package/src/tui/main.mjs +4 -4
- package/src/tui/markdown.mjs +31 -5
- package/src/tui/mentions.mjs +218 -0
- package/src/tui/message-app.mjs +15 -11
- package/src/tui/palette-app.mjs +19 -9
- package/src/tui/reminder-app.mjs +14 -10
- package/src/tui/ui-content.mjs +12 -3
- package/src/tui/ui-mentions.mjs +44 -0
- package/src/tui/ui-suggest-view.mjs +63 -0
- package/src/tui/ui-suggest.mjs +197 -0
- package/src/tui/ui-theme.mjs +2 -1
- package/src/tui/ui-view.mjs +2 -0
- package/src/tui/ui.mjs +17 -9
|
@@ -109,6 +109,7 @@ export function initQuestions(app) {
|
|
|
109
109
|
input.setAttribute("aria-label", app.t("answerPlaceholder"));
|
|
110
110
|
installEditor(input);
|
|
111
111
|
input.isKnownMention = (name) => app.mentionExists(name);
|
|
112
|
+
input.mentionLabel = (name) => name === "all" ? app.t("allMembers") : name;
|
|
112
113
|
const key = `${roomId}\0${question.id}`;
|
|
113
114
|
input.draftValue = drafts.has(key) ? drafts.get(key) : questionAuthorMention(question, roomId, app);
|
|
114
115
|
input.dataset.empty = input.value ? "false" : "true";
|
|
@@ -300,6 +301,11 @@ export function initQuestions(app) {
|
|
|
300
301
|
const activateRoom = app.activateRoom;
|
|
301
302
|
app.activateRoom = (roomId, preserveRoomListGeneration = false) => {
|
|
302
303
|
activateRoom(roomId, preserveRoomListGeneration);
|
|
304
|
+
// Error and too-long banners belong to the room that produced them.
|
|
305
|
+
delete status.dataset.error;
|
|
306
|
+
delete status.dataset.tooLong;
|
|
307
|
+
status.hidden = true;
|
|
308
|
+
status.textContent = "";
|
|
303
309
|
void load(roomId);
|
|
304
310
|
};
|
|
305
311
|
const applyLocale = app.applyLocale;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Shared classification for resources that open in the reading pane. The server
|
|
2
|
+
// sniffs text and PDF uploads as application/octet-stream, so the filename
|
|
3
|
+
// extension is a first-class signal alongside the MIME type.
|
|
4
|
+
export const TEXT_PREVIEW_LIMIT = 2 * 1024 * 1024;
|
|
5
|
+
|
|
6
|
+
const MIME_LANGUAGES = {
|
|
7
|
+
"application/json": "json", "application/ld+json": "json",
|
|
8
|
+
"application/xml": "xml", "text/xml": "xml",
|
|
9
|
+
"application/javascript": "javascript", "application/x-javascript": "javascript",
|
|
10
|
+
"application/typescript": "typescript",
|
|
11
|
+
"application/x-yaml": "yaml", "application/yaml": "yaml",
|
|
12
|
+
"application/toml": "ini",
|
|
13
|
+
"text/html": "xml", "text/css": "css",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const EXTENSION_LANGUAGES = {
|
|
17
|
+
txt: "", log: "", csv: "", tsv: "",
|
|
18
|
+
json: "json", jsonc: "json", yaml: "yaml", yml: "yaml",
|
|
19
|
+
toml: "ini", ini: "ini", conf: "ini", env: "ini", properties: "properties",
|
|
20
|
+
sh: "bash", bash: "bash", zsh: "bash", fish: "bash",
|
|
21
|
+
ps1: "powershell", bat: "dos", cmd: "dos",
|
|
22
|
+
js: "javascript", mjs: "javascript", cjs: "javascript", jsx: "javascript",
|
|
23
|
+
ts: "typescript", tsx: "typescript",
|
|
24
|
+
py: "python", rb: "ruby", go: "go", rs: "rust", java: "java",
|
|
25
|
+
kt: "kotlin", kts: "kotlin", c: "c", h: "c", cpp: "cpp", hpp: "cpp", cc: "cpp",
|
|
26
|
+
cs: "csharp", php: "php", swift: "swift", sql: "sql",
|
|
27
|
+
html: "xml", htm: "xml", css: "css", scss: "scss", less: "less",
|
|
28
|
+
xml: "xml", svg: "xml", vue: "xml", svelte: "xml",
|
|
29
|
+
lua: "lua", r: "r", pl: "perl", pm: "perl", dart: "dart",
|
|
30
|
+
gradle: "groovy", dockerfile: "dockerfile", makefile: "makefile", mk: "makefile",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const LANGUAGE_NAMES = {
|
|
34
|
+
typescript: "TypeScript", javascript: "JavaScript", python: "Python", ruby: "Ruby",
|
|
35
|
+
bash: "Shell", yaml: "YAML", json: "JSON", xml: "XML", c: "C", cpp: "C++",
|
|
36
|
+
csharp: "C#", kotlin: "Kotlin", rust: "Rust", go: "Go", java: "Java",
|
|
37
|
+
php: "PHP", swift: "Swift", sql: "SQL", css: "CSS", scss: "SCSS", less: "Less",
|
|
38
|
+
ini: "Config", properties: "Properties", powershell: "PowerShell", dos: "Batch",
|
|
39
|
+
dockerfile: "Dockerfile", makefile: "Makefile", lua: "Lua", r: "R", perl: "Perl",
|
|
40
|
+
dart: "Dart", groovy: "Gradle",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const TEXT_MIMES = new Set([
|
|
44
|
+
"application/json", "application/ld+json", "application/xml", "application/x-yaml",
|
|
45
|
+
"application/yaml", "application/toml", "application/javascript",
|
|
46
|
+
"application/x-javascript", "application/typescript",
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
function fileExtension(name) {
|
|
50
|
+
const base = String(name || "").toLowerCase().split(/[\\/]/).pop() || "";
|
|
51
|
+
if (base === "dockerfile" || base === "makefile") return base;
|
|
52
|
+
return /\.([a-z0-9]+)$/.exec(base)?.[1] || "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isTextMime(mime) {
|
|
56
|
+
if (mime === "text/markdown" || mime === "text/x-markdown") return false;
|
|
57
|
+
return mime.startsWith("text/") || TEXT_MIMES.has(mime);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function docPreviewFormat(resource) {
|
|
61
|
+
const mime = String(resource?.mimeType || "").split(";")[0].trim().toLowerCase();
|
|
62
|
+
const name = String(resource?.name || "");
|
|
63
|
+
const ext = fileExtension(name);
|
|
64
|
+
if (mime === "application/pdf" || ext === "pdf") return { kind: "pdf", language: "", label: "PDF" };
|
|
65
|
+
if (mime === "text/markdown" || mime === "text/x-markdown" || ext === "md" || ext === "markdown") {
|
|
66
|
+
return { kind: "markdown", language: "", label: "" };
|
|
67
|
+
}
|
|
68
|
+
const knownExtension = Object.hasOwn(EXTENSION_LANGUAGES, ext);
|
|
69
|
+
if (!knownExtension && !isTextMime(mime)) return null;
|
|
70
|
+
const language = knownExtension ? EXTENSION_LANGUAGES[ext] : MIME_LANGUAGES[mime] || "";
|
|
71
|
+
return { kind: "text", language, label: LANGUAGE_NAMES[language] || (ext ? ext.toUpperCase() : "Text") };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const isDocPreviewResource = (resource) => docPreviewFormat(resource) !== null;
|
|
@@ -133,6 +133,7 @@ export function initRooms(app) {
|
|
|
133
133
|
app.captureReadingPosition?.();
|
|
134
134
|
}
|
|
135
135
|
app.stopPolling();
|
|
136
|
+
app.state.previousRoomId = app.state.room?.id;
|
|
136
137
|
app.state.room = entry.room;
|
|
137
138
|
app.state.myName = entry.name;
|
|
138
139
|
app.state.unread = entry.unreadIds.size + (entry.unreadOverflow ? 100 : 0);
|
|
@@ -212,6 +213,7 @@ export function initRooms(app) {
|
|
|
212
213
|
};
|
|
213
214
|
|
|
214
215
|
app.createRoom = async (pending) => {
|
|
216
|
+
if (app.state.joinBusy) return;
|
|
215
217
|
const fromChat = pending?.fromChat ?? Boolean(app.state.room);
|
|
216
218
|
const name = pending?.name || (fromChat ? app.state.myName : $("#inName").value.trim()) || LS.name || app.t("guest");
|
|
217
219
|
const roomName = pending?.roomName || $(fromChat ? "#inRoomNameChat" : "#inRoomName").value.trim();
|
|
@@ -253,6 +255,7 @@ export function initRooms(app) {
|
|
|
253
255
|
};
|
|
254
256
|
|
|
255
257
|
app.setJoinBusy = (busy) => {
|
|
258
|
+
app.state.joinBusy = busy;
|
|
256
259
|
$("#btnJoin").disabled = busy;
|
|
257
260
|
$("#btnCreate").disabled = busy;
|
|
258
261
|
};
|
|
@@ -304,7 +307,9 @@ export function initRooms(app) {
|
|
|
304
307
|
if (next) app.activateRoom(next, true);
|
|
305
308
|
else {
|
|
306
309
|
LS.roomId = "";
|
|
307
|
-
|
|
310
|
+
// Leaving the last room returns to the start screen; reload the list so
|
|
311
|
+
// the room the user just left is available to rejoin without a manual refresh.
|
|
312
|
+
app.showJoin(true, true);
|
|
308
313
|
if (reason) app.showJoinError("roomNotFound");
|
|
309
314
|
}
|
|
310
315
|
}
|
|
@@ -317,6 +322,9 @@ export function initRooms(app) {
|
|
|
317
322
|
clearTimeout(app.state.watcherTimer);
|
|
318
323
|
if (!app.state.rooms.size && !app.state.restorePending?.size && !app.state.restoreRetry) return;
|
|
319
324
|
app.state.watcherTimer = setTimeout(async () => {
|
|
325
|
+
// A hidden tab has no reader; skip background room polling until it is
|
|
326
|
+
// visible again (the next timer tick after visibility resumes).
|
|
327
|
+
if (typeof document !== "undefined" && document.hidden) { app.startRoomWatcher(); return; }
|
|
320
328
|
const inactive = [...app.state.rooms.keys()].filter((id) => id !== app.state.room?.id);
|
|
321
329
|
await bounded(inactive, 3, (roomId) => watchRoom(roomId, app));
|
|
322
330
|
if (app.state.restorePending?.size || app.state.restoreRetry) void app.refreshRoomList(true);
|
|
@@ -124,12 +124,23 @@ export function initShortcuts(app) {
|
|
|
124
124
|
animateScroll(bottom ? thread.scrollHeight : 0);
|
|
125
125
|
};
|
|
126
126
|
app.animateRoomSwitch = (direction) => {
|
|
127
|
-
//
|
|
128
|
-
|
|
127
|
+
// Fluent motion lives in the selected indicator: the old bar collapses toward
|
|
128
|
+
// the direction of travel while the new bar expands from the opposite edge.
|
|
129
|
+
const oldId = app.state.previousRoomId;
|
|
130
|
+
const oldRows = oldId ? document.querySelectorAll(`#roomListChat .room-row[data-room-id="${CSS.escape(oldId)}"]`) : [];
|
|
131
|
+
for (const row of oldRows) {
|
|
132
|
+
row.classList.remove("room-switch-leave");
|
|
133
|
+
row.style.setProperty("--room-switch-origin", direction > 0 ? "bottom" : "top");
|
|
134
|
+
void row.offsetWidth;
|
|
135
|
+
row.classList.add("room-switch-leave");
|
|
136
|
+
setTimeout(() => row.classList.remove("room-switch-leave"), 220);
|
|
137
|
+
}
|
|
138
|
+
for (const row of document.querySelectorAll("#roomListChat .room-row.selected")) {
|
|
129
139
|
row.classList.remove("room-switch-enter");
|
|
130
|
-
row.style.setProperty("--room-switch-
|
|
140
|
+
row.style.setProperty("--room-switch-origin", direction > 0 ? "top" : "bottom");
|
|
131
141
|
void row.offsetWidth;
|
|
132
142
|
row.classList.add("room-switch-enter");
|
|
143
|
+
setTimeout(() => row.classList.remove("room-switch-enter"), 220);
|
|
133
144
|
row.scrollIntoView({ block: "nearest" });
|
|
134
145
|
}
|
|
135
146
|
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Resizes the right-hand pane (Markdown preview or task board) on wide windows.
|
|
2
|
+
// --side-pane-width holds the only width; the rail keeps its 252px column and the
|
|
3
|
+
// chat column never shrinks below MIN_CHAT.
|
|
4
|
+
const STORAGE_KEY = "chat.sidePaneWidth";
|
|
5
|
+
const MIN_WIDTH = 360;
|
|
6
|
+
const MIN_CHAT = 420;
|
|
7
|
+
const RAIL_WIDTH = 252;
|
|
8
|
+
const GUTTER = 8;
|
|
9
|
+
const MAX_WIDTH = 960;
|
|
10
|
+
|
|
11
|
+
export function initSidePaneSplitter(app) {
|
|
12
|
+
const view = app.$("#chatView");
|
|
13
|
+
const handle = app.$("#sidePaneHandle");
|
|
14
|
+
const preview = app.$("#docPreview");
|
|
15
|
+
const tasks = app.$("#tasksDialog");
|
|
16
|
+
if (!view || !handle) return;
|
|
17
|
+
|
|
18
|
+
let stored = readStored();
|
|
19
|
+
let applied = 0;
|
|
20
|
+
let frame = 0;
|
|
21
|
+
let pending = 0;
|
|
22
|
+
let drag = null;
|
|
23
|
+
|
|
24
|
+
const activePane = () => view.classList.contains("has-doc") ? preview
|
|
25
|
+
: view.classList.contains("has-tasks") ? tasks : null;
|
|
26
|
+
|
|
27
|
+
const maxWidth = () => {
|
|
28
|
+
const available = view.clientWidth - RAIL_WIDTH - GUTTER - MIN_CHAT;
|
|
29
|
+
return Math.max(MIN_WIDTH, Math.min(window.innerWidth * 0.7, MAX_WIDTH, available));
|
|
30
|
+
};
|
|
31
|
+
const clamp = (width) => Math.max(MIN_WIDTH, Math.min(width, maxWidth()));
|
|
32
|
+
|
|
33
|
+
const syncAria = () => {
|
|
34
|
+
handle.setAttribute("aria-valuemin", String(MIN_WIDTH));
|
|
35
|
+
handle.setAttribute("aria-valuemax", String(Math.round(maxWidth())));
|
|
36
|
+
const pane = activePane();
|
|
37
|
+
if (pane?.open) {
|
|
38
|
+
handle.setAttribute("aria-valuenow", String(Math.round(pane.getBoundingClientRect().width)));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const apply = (width) => {
|
|
43
|
+
applied = Math.round(width);
|
|
44
|
+
view.style.setProperty("--side-pane-width", `${applied}px`);
|
|
45
|
+
syncAria();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Pane classes change on open, close, and breakpoint switches; the hidden
|
|
49
|
+
// attribute changes when the workspace first appears.
|
|
50
|
+
const reflow = () => {
|
|
51
|
+
if (!view.clientWidth) return;
|
|
52
|
+
if (stored == null) syncAria();
|
|
53
|
+
else apply(clamp(stored));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const setWidth = (width) => {
|
|
57
|
+
const next = clamp(width);
|
|
58
|
+
apply(next);
|
|
59
|
+
return next;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const persist = (width) => {
|
|
63
|
+
stored = Math.round(width);
|
|
64
|
+
try { localStorage.setItem(STORAGE_KEY, String(stored)); } catch { /* The width still applies for this page. */ }
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
handle.addEventListener("pointerdown", (event) => {
|
|
68
|
+
const pane = activePane();
|
|
69
|
+
if (event.button !== 0 || !pane?.open) return;
|
|
70
|
+
drag = { pointerId: event.pointerId, x: event.clientX, width: pane.getBoundingClientRect().width };
|
|
71
|
+
applied = Math.round(drag.width);
|
|
72
|
+
pending = drag.width;
|
|
73
|
+
handle.setPointerCapture(event.pointerId);
|
|
74
|
+
handle.classList.add("is-dragging");
|
|
75
|
+
document.body.classList.add("is-resizing-pane");
|
|
76
|
+
handle.focus({ preventScroll: true });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
handle.addEventListener("pointermove", (event) => {
|
|
80
|
+
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
81
|
+
// Dragging left widens the right-hand pane; the divider follows the pointer.
|
|
82
|
+
pending = clamp(drag.width - (event.clientX - drag.x));
|
|
83
|
+
if (frame) return;
|
|
84
|
+
frame = requestAnimationFrame(() => {
|
|
85
|
+
frame = 0;
|
|
86
|
+
apply(pending);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const endDrag = (event) => {
|
|
91
|
+
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
92
|
+
if (frame) { cancelAnimationFrame(frame); frame = 0; }
|
|
93
|
+
apply(pending);
|
|
94
|
+
persist(applied);
|
|
95
|
+
drag = null;
|
|
96
|
+
handle.classList.remove("is-dragging");
|
|
97
|
+
document.body.classList.remove("is-resizing-pane");
|
|
98
|
+
if (handle.hasPointerCapture(event.pointerId)) handle.releasePointerCapture(event.pointerId);
|
|
99
|
+
};
|
|
100
|
+
handle.addEventListener("pointerup", endDrag);
|
|
101
|
+
handle.addEventListener("pointercancel", endDrag);
|
|
102
|
+
|
|
103
|
+
handle.addEventListener("keydown", (event) => {
|
|
104
|
+
if (!activePane()?.open) return;
|
|
105
|
+
const current = activePane().getBoundingClientRect().width;
|
|
106
|
+
const step = event.shiftKey ? 64 : 16;
|
|
107
|
+
let next;
|
|
108
|
+
if (event.key === "ArrowRight") next = current - step;
|
|
109
|
+
else if (event.key === "ArrowLeft") next = current + step;
|
|
110
|
+
else if (event.key === "Home") next = MIN_WIDTH;
|
|
111
|
+
else if (event.key === "End") next = maxWidth();
|
|
112
|
+
else return;
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
persist(setWidth(next));
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
handle.addEventListener("dblclick", () => {
|
|
118
|
+
stored = null;
|
|
119
|
+
try { localStorage.removeItem(STORAGE_KEY); } catch { /* Ignore unavailable storage. */ }
|
|
120
|
+
view.style.removeProperty("--side-pane-width");
|
|
121
|
+
syncAria();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
window.addEventListener("resize", reflow);
|
|
125
|
+
new MutationObserver(reflow).observe(view, { attributes: true, attributeFilter: ["class", "hidden"] });
|
|
126
|
+
reflow();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function readStored() {
|
|
130
|
+
try {
|
|
131
|
+
const width = Number(localStorage.getItem(STORAGE_KEY));
|
|
132
|
+
return Number.isFinite(width) && width > 0 ? width : null;
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -23,6 +23,13 @@ export const app = {
|
|
|
23
23
|
failedRenderIds: new Set(),
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
// Phones and tablets lack the hardware keyboard the shortcut hint assumes.
|
|
27
|
+
// iPadOS reports a desktop Macintosh UA, so touch points identify it there.
|
|
28
|
+
export function isMobileDevice() {
|
|
29
|
+
const ua = navigator.userAgent || "";
|
|
30
|
+
return /Android|iPhone|iPad|iPod/i.test(ua) || (/Macintosh/.test(ua) && (navigator.maxTouchPoints || 0) > 1);
|
|
31
|
+
}
|
|
32
|
+
|
|
26
33
|
export function createRandomId() {
|
|
27
34
|
const crypto = globalThis.crypto;
|
|
28
35
|
if (crypto?.randomUUID) return crypto.randomUUID();
|
|
@@ -34,6 +41,12 @@ export function createRandomId() {
|
|
|
34
41
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
35
42
|
}
|
|
36
43
|
|
|
44
|
+
// Media cached by the service worker belongs to a browser identity; drop it whenever
|
|
45
|
+
// that identity changes and keep only the current identity record.
|
|
46
|
+
const clearMediaCache = () => {
|
|
47
|
+
try { globalThis.navigator?.serviceWorker?.controller?.postMessage({ type: "CLEAR_MEDIA_CACHE" }); } catch { /* Cache cleanup is best effort. */ }
|
|
48
|
+
};
|
|
49
|
+
|
|
37
50
|
export function createAuth(storage, fetcher, translate = (key) => key, sessionStore) {
|
|
38
51
|
const memory = Object.create(null);
|
|
39
52
|
let browserIdentity, identityPersistent = false, identityConflict = false;
|
|
@@ -75,14 +88,21 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
75
88
|
};
|
|
76
89
|
const ensureIdentity = () => {
|
|
77
90
|
if (browserIdentity) return browserIdentity;
|
|
91
|
+
const priorID = readSession("chat.sessionID");
|
|
78
92
|
let store;
|
|
79
93
|
try {
|
|
80
94
|
store = storage ?? globalThis.localStorage;
|
|
81
95
|
const canonical = parseIdentity(store.getItem(identityKey));
|
|
82
|
-
if (canonical) {
|
|
96
|
+
if (canonical) {
|
|
97
|
+
browserIdentity = canonical;
|
|
98
|
+
identityPersistent = true;
|
|
99
|
+
if (priorID && priorID !== canonical.sessionID) { clearMediaCache(); void postMediaIdentity(); }
|
|
100
|
+
syncTabIdentity();
|
|
101
|
+
return canonical;
|
|
102
|
+
}
|
|
83
103
|
} catch { /* Keep this tab's identity in memory when storage is blocked. */ }
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
browserIdentity = { sessionID: validSessionID(priorID) ? priorID : createRandomId(), name: validSessionID(priorID) ? (readSession("chat.name") || "").slice(0, 64) : "" };
|
|
105
|
+
if (priorID && priorID !== browserIdentity.sessionID) { clearMediaCache(); void postMediaIdentity(); }
|
|
86
106
|
syncTabIdentity();
|
|
87
107
|
try {
|
|
88
108
|
store ||= storage ?? globalThis.localStorage;
|
|
@@ -168,7 +188,15 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
168
188
|
},
|
|
169
189
|
set failedMessages(value) { writeSession("chat.failedMessages", JSON.stringify(value)); },
|
|
170
190
|
};
|
|
171
|
-
const saveToken = (value) => {
|
|
191
|
+
const saveToken = (value) => {
|
|
192
|
+
const next = String(value ?? "").trim();
|
|
193
|
+
const changed = next !== auth.token;
|
|
194
|
+
auth.token = next;
|
|
195
|
+
// A token change can change what the person may see, so cached images must not
|
|
196
|
+
// survive into the new identity. An empty value is the sign-out path.
|
|
197
|
+
if (changed) { clearMediaCache(); void postMediaIdentity(); }
|
|
198
|
+
return auth.token;
|
|
199
|
+
};
|
|
172
200
|
const apiResponse = async (url, options = {}) => {
|
|
173
201
|
assertIdentity();
|
|
174
202
|
const headers = { ...options.headers };
|
|
@@ -248,7 +276,7 @@ export const messages = {
|
|
|
248
276
|
reminderEdit: "Edit", reminderEditHeading: "Edit reminder", reminderSave: "Save changes",
|
|
249
277
|
reminderCreated: "Reminder created.", reminderUpdated: "Reminder updated.", reminderDeleted: "Reminder deleted.",
|
|
250
278
|
reminderInvalid: "Check the date, 5-field CRON expression, IANA timezone, and reminder text.", reminderLoadFailed: "Could not load reminders. Your draft is still here.",
|
|
251
|
-
diagramLoading: "Rendering diagram…", diagramRenderFailed: "Diagram unavailable; showing its source.", resourceLoading: "Loading file…", resourceFailed: "This file could not be loaded.", resourceDownload: "Download", resourceMoreActions: "More actions for {name}", resourcePreview: "Preview", resourceHide: "Hide preview", docPreviewEyebrow: "Markdown preview", docPreviewFailed: "This document could not be loaded.", docPreviewEmpty: "This document is empty.", zoomImage: "Open image", imagePreviewTitle: "Image preview", imageZoomControls: "Image zoom", zoomIn: "Zoom in", zoomOut: "Zoom out", zoomReset: "Reset zoom", installTitle: "Install OC Chat", installBody: "Add it to your home screen for a full-screen chat.", installAction: "Install", installHow: "How to install", installNotNow: "Not now", installIosGuide: "Tap Share, then Add to Home Screen.",
|
|
279
|
+
diagramLoading: "Rendering diagram…", diagramRenderFailed: "Diagram unavailable; showing its source.", resourceLoading: "Loading file…", resourceFailed: "This file could not be loaded.", resourceDownload: "Download", resourceMoreActions: "More actions for {name}", resourcePreview: "Preview", resourceHide: "Hide preview", docPreviewEyebrow: "Markdown preview", docPreviewFileEyebrow: "File preview", docPreviewFailed: "This document could not be loaded.", docPreviewEmpty: "This document is empty.", docPreviewTooLarge: "This file is too large to preview (over 2 MB). Download it instead.", sidePaneResize: "Resize side pane", zoomImage: "Open image", imagePreviewTitle: "Image preview", imageZoomControls: "Image zoom", zoomIn: "Zoom in", zoomOut: "Zoom out", zoomReset: "Reset zoom", openDiagram: "Open diagram", diagramViewerTitle: "Diagram", diagramZoomControls: "Diagram zoom", diagramFit: "Fit", installTitle: "Install OC Chat", installBody: "Add it to your home screen for a full-screen chat.", installAction: "Install", installHow: "How to install", installNotNow: "Not now", installIosGuide: "Tap Share, then Add to Home Screen.",
|
|
252
280
|
pwaUpdateTitle: "Update available", pwaUpdateBody: "A new version is ready. Reload now, or update the next time you open the app.", pwaUpdateNow: "Update now", pwaUpdateLater: "Later",
|
|
253
281
|
announcementDelete: "Delete announcement",
|
|
254
282
|
announcementNew: "New announcement", announcementEmpty: "No announcements yet.", announcementLoading: "Loading announcements…",
|
|
@@ -299,10 +327,28 @@ export const messages = {
|
|
|
299
327
|
filesUnknownUploader: "Unknown uploader", filesSummary: ({ count, size }) => `${count} file${count === 1 ? "" : "s"} · ${size}`,
|
|
300
328
|
filesLoading: "Loading files…", filesLoadFailed: "Could not load files. Try again.", filesEmpty: "No files in this room yet.",
|
|
301
329
|
filesEmptyFiltered: "No files from this uploader.", filesLoadMore: "Load more",
|
|
302
|
-
filesHint: "Preview images, audio, video, and
|
|
330
|
+
filesHint: "Preview images, audio, video, Markdown, text, code, and PDF. Download any file.",
|
|
303
331
|
filesPreviewFailed: "Could not load this preview.", filesDownloadFailed: "Could not download this file.",
|
|
304
332
|
filesPreviewLabel: ({ name }) => `Preview ${name}`, filesDownloadLabel: ({ name }) => `Download ${name}`,
|
|
305
333
|
filesDeleteLabel: ({ name }) => `Delete ${name}`, filesRefresh: "Refresh files",
|
|
334
|
+
tasksTitle: "Tasks", tasksEyebrow: "Room tasks", tasksRefresh: "Refresh tasks", tasksMenuLabel: "Task actions",
|
|
335
|
+
tasksClearCompleted: "Clear completed", tasksClearConfirm: ({ count }) => `Clear ${count} completed task${count === 1 ? "" : "s"}? This cannot be undone.`,
|
|
336
|
+
tasksClearFailed: "Could not clear completed tasks. Try again.",
|
|
337
|
+
tasksLoading: "Loading tasks…", tasksLoadFailed: "Could not load tasks. Try again.", tasksEmpty: "No tasks yet. Add the first one.",
|
|
338
|
+
tasksEmptyFiltered: "No tasks with this status.", tasksCreate: "Add task", tasksTitleLabel: "Title",
|
|
339
|
+
tasksTitlePlaceholder: "What needs doing?", tasksDescriptionLabel: "Description", tasksDescriptionPlaceholder: "Add details, links, or acceptance notes",
|
|
340
|
+
tasksAssigneeLabel: "Assignee", tasksUnassigned: "Unassigned", tasksFilterLabel: "Show", tasksFilterAll: "All statuses",
|
|
341
|
+
tasksDueDateLabel: "Due date", tasksDueOn: ({ date }) => `Due ${date}`, tasksOverdue: "Overdue",
|
|
342
|
+
tasksParticipantsLabel: "Participants", tasksParticipantsMeta: ({ names }) => `Participants: ${names}`,
|
|
343
|
+
tasksConclusionLabel: "Conclusion", tasksConclusionPlaceholder: "What was the outcome?",
|
|
344
|
+
tasksStepsLabel: "Steps", tasksAddStep: "Add step", tasksRemoveStep: "Remove step", tasksStepPlaceholder: "Describe a step",
|
|
345
|
+
tasksStepDoneLabel: "Step done", tasksStepsHint: "Up to 30 steps. Check the ones that are done.",
|
|
346
|
+
tasksStepsProgress: ({ done, total }) => `${done} of ${total} step${total === 1 ? "" : "s"} done`,
|
|
347
|
+
tasksStatusTodo: "To do", tasksStatusDoing: "Doing", tasksStatusDone: "Done",
|
|
348
|
+
tasksSummary: ({ count }) => `${count} task${count === 1 ? "" : "s"}`, tasksCreator: ({ name }) => `Created by ${name}`, tasksUpdated: ({ time }) => `Updated ${time}`,
|
|
349
|
+
tasksEditLabel: ({ title }) => `Edit ${title}`, tasksDeleteLabel: ({ title }) => `Delete ${title}`, tasksStatusFor: ({ title }) => `Status for ${title}`,
|
|
350
|
+
tasksInvalid: "Add a title of 1–200 characters.", tasksCreateFailed: "Could not add this task. Try again.", tasksUpdateFailed: "Could not update this task. Try again.",
|
|
351
|
+
tasksDeleteFailed: "Could not delete this task. Try again.", tasksDeleteConfirm: ({ title }) => `Delete “${title}”? This cannot be undone.`,
|
|
306
352
|
earlierMessages: "Earlier messages omitted", messagesBetweenOmitted: "Messages between this reading point and latest are omitted.", you: "You", saved: "Saved",
|
|
307
353
|
savedMemory: "Saved for this tab only", copyFailed: ({ id }) => `Copy failed. Copy manually: ${id}`,
|
|
308
354
|
copyMessage: "Copy", copiedMessage: "Copied", copyMessageFailed: "Could not copy. Select and copy the message manually.", wrapCode: "Wrap code",
|
|
@@ -382,7 +428,7 @@ export const messages = {
|
|
|
382
428
|
reminderEdit: "编辑", reminderEditHeading: "编辑提醒", reminderSave: "保存修改",
|
|
383
429
|
reminderCreated: "提醒已创建。", reminderUpdated: "提醒已更新。", reminderDeleted: "提醒已删除。",
|
|
384
430
|
reminderInvalid: "请检查日期、5 字段 CRON 表达式、IANA 时区和提醒内容。", reminderLoadFailed: "无法加载提醒,草稿仍已保留。",
|
|
385
|
-
diagramLoading: "正在渲染图表…", diagramRenderFailed: "图表无法显示,以下为源代码。", resourceLoading: "正在加载文件…", resourceFailed: "无法加载此文件。", resourceDownload: "下载", resourceMoreActions: "{name} 的更多操作", resourcePreview: "预览", resourceHide: "收起预览", docPreviewEyebrow: "Markdown 预览", docPreviewFailed: "无法加载此文档。", docPreviewEmpty: "此文档为空。", zoomImage: "查看大图", imagePreviewTitle: "图片预览", imageZoomControls: "图片缩放", zoomIn: "放大", zoomOut: "缩小", zoomReset: "重置缩放", installTitle: "安装 OC Chat", installBody: "添加到主屏幕,获得全屏聊天体验。", installAction: "安装", installHow: "如何安装", installNotNow: "暂不", installIosGuide: "点击共享按钮,然后选择“添加到主屏幕”。",
|
|
431
|
+
diagramLoading: "正在渲染图表…", diagramRenderFailed: "图表无法显示,以下为源代码。", resourceLoading: "正在加载文件…", resourceFailed: "无法加载此文件。", resourceDownload: "下载", resourceMoreActions: "{name} 的更多操作", resourcePreview: "预览", resourceHide: "收起预览", docPreviewEyebrow: "Markdown 预览", docPreviewFileEyebrow: "文件预览", docPreviewFailed: "无法加载此文档。", docPreviewEmpty: "此文档为空。", docPreviewTooLarge: "文件太大,无法预览(超过 2 MB),请下载查看。", sidePaneResize: "调整侧边栏宽度", zoomImage: "查看大图", imagePreviewTitle: "图片预览", imageZoomControls: "图片缩放", zoomIn: "放大", zoomOut: "缩小", zoomReset: "重置缩放", openDiagram: "查看图表", diagramViewerTitle: "图表", diagramZoomControls: "图表缩放", diagramFit: "适应窗口", installTitle: "安装 OC Chat", installBody: "添加到主屏幕,获得全屏聊天体验。", installAction: "安装", installHow: "如何安装", installNotNow: "暂不", installIosGuide: "点击共享按钮,然后选择“添加到主屏幕”。",
|
|
386
432
|
pwaUpdateTitle: "有可用更新", pwaUpdateBody: "新版本已准备好。可以立即刷新,或下次打开时再升级。", pwaUpdateNow: "立即升级", pwaUpdateLater: "稍后",
|
|
387
433
|
announcementDelete: "删除公告",
|
|
388
434
|
announcementNew: "新建公告", announcementEmpty: "暂无公告。", announcementLoading: "正在加载公告…",
|
|
@@ -429,10 +475,28 @@ export const messages = {
|
|
|
429
475
|
filesUnknownUploader: "未知上传者", filesSummary: ({ count, size }) => `${count} 个文件 · ${size}`,
|
|
430
476
|
filesLoading: "正在加载文件…", filesLoadFailed: "无法加载文件,请重试。", filesEmpty: "这个房间还没有文件。",
|
|
431
477
|
filesEmptyFiltered: "此上传者没有文件。", filesLoadMore: "加载更多",
|
|
432
|
-
filesHint: "
|
|
478
|
+
filesHint: "可预览图片、音频、视频、Markdown、文本、代码和 PDF,所有文件都可下载。",
|
|
433
479
|
filesPreviewFailed: "无法加载预览。", filesDownloadFailed: "无法下载此文件。",
|
|
434
480
|
filesPreviewLabel: ({ name }) => `预览 ${name}`, filesDownloadLabel: ({ name }) => `下载 ${name}`,
|
|
435
481
|
filesDeleteLabel: ({ name }) => `删除 ${name}`, filesRefresh: "刷新文件",
|
|
482
|
+
tasksTitle: "任务", tasksEyebrow: "房间任务", tasksRefresh: "刷新任务", tasksMenuLabel: "任务操作",
|
|
483
|
+
tasksClearCompleted: "清除已完成任务", tasksClearConfirm: ({ count }) => `清除 ${count} 个已完成任务?此操作无法撤销。`,
|
|
484
|
+
tasksClearFailed: "无法清除已完成任务,请重试。",
|
|
485
|
+
tasksLoading: "正在加载任务…", tasksLoadFailed: "无法加载任务,请重试。", tasksEmpty: "还没有任务,添加第一个吧。",
|
|
486
|
+
tasksEmptyFiltered: "此状态下没有任务。", tasksCreate: "添加任务", tasksTitleLabel: "标题",
|
|
487
|
+
tasksTitlePlaceholder: "需要做什么?", tasksDescriptionLabel: "描述", tasksDescriptionPlaceholder: "补充细节、链接或完成标准",
|
|
488
|
+
tasksAssigneeLabel: "负责人", tasksUnassigned: "未指派", tasksFilterLabel: "显示", tasksFilterAll: "全部状态",
|
|
489
|
+
tasksDueDateLabel: "截止日期", tasksDueOn: ({ date }) => `截止 ${date}`, tasksOverdue: "已逾期",
|
|
490
|
+
tasksParticipantsLabel: "参与人员", tasksParticipantsMeta: ({ names }) => `参与人员:${names}`,
|
|
491
|
+
tasksConclusionLabel: "结论", tasksConclusionPlaceholder: "最终结果如何?",
|
|
492
|
+
tasksStepsLabel: "完成步骤", tasksAddStep: "添加步骤", tasksRemoveStep: "删除步骤", tasksStepPlaceholder: "描述一个步骤",
|
|
493
|
+
tasksStepDoneLabel: "步骤已完成", tasksStepsHint: "最多 30 个步骤,勾选已完成的步骤。",
|
|
494
|
+
tasksStepsProgress: ({ done, total }) => `已完成 ${done}/${total} 步`,
|
|
495
|
+
tasksStatusTodo: "待办", tasksStatusDoing: "进行中", tasksStatusDone: "已完成",
|
|
496
|
+
tasksSummary: ({ count }) => `${count} 个任务`, tasksCreator: ({ name }) => `由 ${name} 创建`, tasksUpdated: ({ time }) => `更新于 ${time}`,
|
|
497
|
+
tasksEditLabel: ({ title }) => `编辑 ${title}`, tasksDeleteLabel: ({ title }) => `删除 ${title}`, tasksStatusFor: ({ title }) => `${title} 的状态`,
|
|
498
|
+
tasksInvalid: "标题需为 1–200 个字符。", tasksCreateFailed: "无法添加任务,请重试。", tasksUpdateFailed: "无法更新任务,请重试。",
|
|
499
|
+
tasksDeleteFailed: "无法删除任务,请重试。", tasksDeleteConfirm: ({ title }) => `删除“${title}”?此操作无法撤销。`,
|
|
436
500
|
joined: "已加入", joinAction: "加入房间", unreadMessages: ({ count }) => `${count} 条未读`,
|
|
437
501
|
today: "今天", yesterday: "昨天", earlierMessages: "更早的消息已省略", messagesBetweenOmitted: "此阅读位置与最新消息之间的部分消息已省略。", you: "我", saved: "已保存",
|
|
438
502
|
savedMemory: "仅保存于当前标签页", copyFailed: ({ id }) => `复制失败,请手动复制:${id}`,
|
|
@@ -478,6 +542,19 @@ app.LS = LS;
|
|
|
478
542
|
app.api = api;
|
|
479
543
|
app.apiBlob = apiBlob;
|
|
480
544
|
app.setToken = saveToken;
|
|
545
|
+
// The service worker partitions its image cache by this hash; raw credentials never
|
|
546
|
+
// leave the page. A missing controller is fine: the identity is posted on controllerchange.
|
|
547
|
+
async function postMediaIdentity() {
|
|
548
|
+
try {
|
|
549
|
+
const controller = globalThis.navigator?.serviceWorker?.controller;
|
|
550
|
+
const subtle = globalThis.crypto?.subtle;
|
|
551
|
+
if (!controller || !subtle) return;
|
|
552
|
+
const digest = await subtle.digest("SHA-256", new TextEncoder().encode(`${LS.token}\n${LS.sessionID}`));
|
|
553
|
+
const identity = [...new Uint8Array(digest).slice(0, 8)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
554
|
+
controller.postMessage({ type: "SET_MEDIA_IDENTITY", identity });
|
|
555
|
+
} catch { /* Image caching stays disabled until an identity can be posted. */ }
|
|
556
|
+
}
|
|
557
|
+
app.postMediaIdentity = postMediaIdentity;
|
|
481
558
|
export const SUPPORTED_LOCALES = ["en", "zh-CN", "ja", "ko", "fr", "de", "es", "it"];
|
|
482
559
|
const intlLocales = { en: "en-US", "zh-CN": "zh-CN", ja: "ja-JP", ko: "ko-KR", fr: "fr-FR", de: "de-DE", es: "es-ES", it: "it-IT" };
|
|
483
560
|
app.locale = messages[LS.locale] ? LS.locale : "en";
|
|
@@ -23,7 +23,9 @@ function formatLine(line, app) {
|
|
|
23
23
|
|
|
24
24
|
export function formatSystemMessage(message, app) {
|
|
25
25
|
// `<at>@name</at>` is an editor token; system rows and previews show the plain mention.
|
|
26
|
-
let text = String(message?.text ?? "")
|
|
26
|
+
let text = String(message?.text ?? "")
|
|
27
|
+
.replace(/<at>@all<\/at>/g, `@${app.t("allMembers")}`)
|
|
28
|
+
.replace(/<at>([\s\S]*?)<\/at>/g, "$1");
|
|
27
29
|
// Resource markers are internal IDs. A rail preview must not expose them.
|
|
28
30
|
const resources = /\[\[resource:[0-9a-f-]{36}\]\]/gi;
|
|
29
31
|
if (resources.test(text)) {
|