@alexsun-top/opencode-chat-room 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +466 -188
- package/package.json +11 -5
- package/packages/chat-room-channeld/README.md +25 -3
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +5 -0
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +17 -2
- package/packages/chat-room-channeld/src/pg/database.ts +187 -0
- package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
- package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
- package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
- package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
- package/packages/chat-room-channeld/src/protocol.ts +1 -0
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/server/assets/base.css +3 -1
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +201 -161
- package/server/assets/chat/announcements.js +302 -208
- package/server/assets/chat/attachment-store.js +116 -76
- package/server/assets/chat/attachments.js +701 -441
- package/server/assets/chat/chat-background.js +179 -156
- package/server/assets/chat/clipboard.js +45 -25
- package/server/assets/chat/confirm-dialog.js +38 -35
- package/server/assets/chat/copy-action.js +40 -41
- package/server/assets/chat/create-room-dialog.js +50 -47
- package/server/assets/chat/diagram-viewer.js +293 -236
- package/server/assets/chat/doc-preview.js +516 -443
- package/server/assets/chat/editor.js +446 -336
- package/server/assets/chat/events.js +650 -510
- package/server/assets/chat/files.js +505 -431
- package/server/assets/chat/history-loader.js +81 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +246 -179
- package/server/assets/chat/index.js +2 -3
- package/server/assets/chat/install-prompt.js +90 -69
- package/server/assets/chat/integration-account-schema.js +91 -87
- package/server/assets/chat/integration-editor.js +162 -155
- package/server/assets/chat/integration-values.js +116 -101
- package/server/assets/chat/integrations.js +750 -626
- package/server/assets/chat/join-requests.js +415 -358
- package/server/assets/chat/locales/de.js +193 -194
- package/server/assets/chat/locales/es.js +193 -194
- package/server/assets/chat/locales/fr.js +193 -194
- package/server/assets/chat/locales/index.js +1 -2
- package/server/assets/chat/locales/it.js +193 -194
- package/server/assets/chat/locales/ja.js +193 -193
- package/server/assets/chat/locales/ko.js +193 -193
- package/server/assets/chat/markdown-footnotes.js +134 -103
- package/server/assets/chat/markdown.js +557 -404
- package/server/assets/chat/members.js +259 -197
- package/server/assets/chat/mentions.js +181 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +299 -227
- package/server/assets/chat/message-window.js +78 -55
- package/server/assets/chat/messages.js +562 -480
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +464 -417
- package/server/assets/chat/panels.js +94 -79
- package/server/assets/chat/pwa.js +147 -75
- package/server/assets/chat/questions.js +374 -302
- package/server/assets/chat/recall.js +338 -273
- package/server/assets/chat/receipts.js +151 -121
- package/server/assets/chat/reminders.js +345 -214
- package/server/assets/chat/replies.js +181 -130
- package/server/assets/chat/resource-format.js +59 -62
- package/server/assets/chat/room-list.js +58 -55
- package/server/assets/chat/room-watcher.js +76 -50
- package/server/assets/chat/rooms.js +631 -500
- package/server/assets/chat/search.js +138 -114
- package/server/assets/chat/settings.js +225 -201
- package/server/assets/chat/shiki.js +62 -63
- package/server/assets/chat/shortcuts.js +212 -189
- package/server/assets/chat/side-pane.js +161 -150
- package/server/assets/chat/state.js +860 -737
- package/server/assets/chat/system-events.js +46 -44
- package/server/assets/chat/system-messages.js +57 -56
- package/server/assets/chat/task-form.js +179 -183
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +665 -587
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +32 -32
- package/server/assets/conversation.css +10 -4
- package/server/chat-server.ts +9 -1
- package/server/chat.html +3 -1
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -268
- package/src/web/integration-rules-editor.ts +2 -0
|
@@ -1,144 +1,192 @@
|
|
|
1
1
|
import { editorSelectionOffsets, replaceEditorRange } from "./editor.js";
|
|
2
|
-
|
|
2
|
+
// The composer keeps its text in a non-standard "value" property patched onto
|
|
3
|
+
// each contenteditable editor, so read it through a guard instead of HTMLElement.
|
|
4
|
+
function editorValue(editor) {
|
|
5
|
+
const value = Reflect.get(editor, "value");
|
|
6
|
+
return typeof value === "string" ? value : "";
|
|
7
|
+
}
|
|
3
8
|
export function initMentions(app) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
9
|
+
const $ = app.$;
|
|
10
|
+
const mention = { active: false, start: 0, query: "", items: [], index: 0, editor: null };
|
|
11
|
+
app.mention = mention;
|
|
12
|
+
app.mentionActive = false;
|
|
13
|
+
app.updateMentionList = (query = mention.query) => {
|
|
14
|
+
mention.query = query;
|
|
15
|
+
mention.items = filterNames(query, app.mentionNames());
|
|
16
|
+
mention.index = mention.items.length ? 0 : -1;
|
|
17
|
+
const picker = $("#mentionPicker");
|
|
18
|
+
if (!picker)
|
|
19
|
+
return;
|
|
20
|
+
picker.textContent = "";
|
|
21
|
+
const list = document.createElement("ul");
|
|
22
|
+
mention.items.forEach((name, index) => list.append(createOption(name, index, query, app)));
|
|
23
|
+
picker.append(list);
|
|
24
|
+
if (!mention.items.length) {
|
|
25
|
+
const empty = document.createElement("p");
|
|
26
|
+
empty.className = "mention-empty";
|
|
27
|
+
empty.textContent = app.t("mentionEmpty");
|
|
28
|
+
picker.append(empty);
|
|
29
|
+
}
|
|
30
|
+
const hint = document.createElement("p");
|
|
31
|
+
hint.className = "mention-hint";
|
|
32
|
+
hint.textContent = app.t("mentionHint");
|
|
33
|
+
picker.append(hint);
|
|
34
|
+
highlightMention(app, mention);
|
|
35
|
+
};
|
|
36
|
+
app.openMention = (start, query, input = $("#msgInput")) => {
|
|
37
|
+
if (!input)
|
|
38
|
+
return;
|
|
39
|
+
mention.active = app.mentionActive = true;
|
|
40
|
+
mention.editor = input;
|
|
41
|
+
mention.start = start;
|
|
42
|
+
app.updateMentionList?.(query);
|
|
43
|
+
const picker = $("#mentionPicker");
|
|
44
|
+
if (!picker)
|
|
45
|
+
return;
|
|
46
|
+
picker.hidden = false;
|
|
47
|
+
if (input.id !== "msgInput") {
|
|
48
|
+
const rect = input.getBoundingClientRect();
|
|
49
|
+
Object.assign(picker.style, { position: "fixed", left: `${rect.left}px`, right: `${innerWidth - rect.right}px`, bottom: `${innerHeight - rect.top + 8}px` });
|
|
50
|
+
}
|
|
51
|
+
input.setAttribute("aria-expanded", "true");
|
|
52
|
+
};
|
|
53
|
+
app.closeMention = () => {
|
|
54
|
+
mention.active = app.mentionActive = false;
|
|
55
|
+
mention.items = [];
|
|
56
|
+
mention.editor?.setAttribute("aria-expanded", "false");
|
|
57
|
+
mention.editor?.removeAttribute("aria-activedescendant");
|
|
58
|
+
mention.editor = null;
|
|
59
|
+
const picker = $("#mentionPicker");
|
|
60
|
+
if (!picker)
|
|
61
|
+
return;
|
|
62
|
+
picker.hidden = true;
|
|
63
|
+
picker.removeAttribute("style");
|
|
64
|
+
};
|
|
65
|
+
app.recomputeMention = (input = $("#msgInput")) => {
|
|
66
|
+
if (!(input instanceof HTMLElement))
|
|
67
|
+
input = $("#msgInput");
|
|
68
|
+
if (!input)
|
|
69
|
+
return;
|
|
70
|
+
if (mention.active && mention.editor !== input)
|
|
71
|
+
app.closeMention();
|
|
72
|
+
const match = currentMention(input);
|
|
73
|
+
if (match) {
|
|
74
|
+
mention.active ? app.updateMentionList?.(match.query) : app.openMention(match.start, match.query, input);
|
|
75
|
+
}
|
|
76
|
+
else if (mention.active)
|
|
77
|
+
app.closeMention();
|
|
78
|
+
};
|
|
79
|
+
app.moveMention = (direction) => {
|
|
80
|
+
if (!mention.items.length)
|
|
81
|
+
return;
|
|
82
|
+
mention.index = (mention.index + direction + mention.items.length) % mention.items.length;
|
|
83
|
+
highlightMention(app, mention);
|
|
84
|
+
};
|
|
85
|
+
app.handleMentionKey = (event, input) => {
|
|
86
|
+
if (!mention.active || mention.editor !== input || event.isComposing || event.keyCode === 229)
|
|
87
|
+
return false;
|
|
88
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
app.moveMention(event.key === "ArrowDown" ? 1 : -1);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
if (event.key === "Escape") {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
app.closeMention();
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
99
|
+
if (mention.items.length) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
app.insertMention(mention.items[mention.index]);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
app.closeMention();
|
|
105
|
+
return event.key === "Tab";
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
};
|
|
109
|
+
app.insertMention = (name) => {
|
|
110
|
+
const input = mention.editor || $("#msgInput");
|
|
111
|
+
if (!input)
|
|
112
|
+
return;
|
|
113
|
+
const end = mention.start + 1 + mention.query.length;
|
|
114
|
+
if (editorValue(input).slice(mention.start, end) !== `@${mention.query}`)
|
|
115
|
+
return app.closeMention();
|
|
116
|
+
replaceEditorRange(input, mention.start, end, `<at>@${name}</at>`);
|
|
117
|
+
app.closeMention();
|
|
118
|
+
// Chrome can reset the selection while focus() lands; restore the caret last.
|
|
119
|
+
input.focus({ preventScroll: true });
|
|
120
|
+
const setCaret = Reflect.get(input, "setCaret");
|
|
121
|
+
if (typeof setCaret === "function")
|
|
122
|
+
setCaret.call(input, mention.start + `<at>@${name}</at>`.length);
|
|
123
|
+
input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText" }));
|
|
124
|
+
};
|
|
85
125
|
}
|
|
86
|
-
|
|
87
126
|
function filterNames(query, names) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
127
|
+
const normalized = query.toLocaleLowerCase();
|
|
128
|
+
const starts = [], contains = [];
|
|
129
|
+
for (const name of names) {
|
|
130
|
+
if (!name)
|
|
131
|
+
continue;
|
|
132
|
+
if (name.toLocaleLowerCase().startsWith(normalized))
|
|
133
|
+
starts.push(name);
|
|
134
|
+
else if (name.toLocaleLowerCase().includes(normalized))
|
|
135
|
+
contains.push(name);
|
|
136
|
+
}
|
|
137
|
+
const allMatches = !normalized || "all".includes(normalized) || "所有人".includes(normalized);
|
|
138
|
+
return (allMatches ? ["all"] : []).concat(starts, contains);
|
|
97
139
|
}
|
|
98
|
-
|
|
99
140
|
function createOption(name, index, query, app) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
141
|
+
const option = document.createElement("li");
|
|
142
|
+
option.className = "mention-opt";
|
|
143
|
+
option.id = `mention-opt-${index}`;
|
|
144
|
+
option.dataset.name = name;
|
|
145
|
+
option.setAttribute("role", "option");
|
|
146
|
+
const at = document.createElement("span");
|
|
147
|
+
at.className = "mention-at";
|
|
148
|
+
at.textContent = "@";
|
|
149
|
+
option.append(at);
|
|
150
|
+
const label = name === "all" ? app.t("allMembers") : name;
|
|
151
|
+
const offset = label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase());
|
|
152
|
+
if (!query || offset < 0)
|
|
153
|
+
option.append(document.createTextNode(label));
|
|
154
|
+
else {
|
|
155
|
+
option.append(document.createTextNode(label.slice(0, offset)));
|
|
156
|
+
const hit = document.createElement("span");
|
|
157
|
+
hit.className = "mention-hit";
|
|
158
|
+
hit.textContent = label.slice(offset, offset + query.length);
|
|
159
|
+
option.append(hit, document.createTextNode(label.slice(offset + query.length)));
|
|
160
|
+
}
|
|
161
|
+
return option;
|
|
120
162
|
}
|
|
121
|
-
|
|
122
163
|
function currentMention(input) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
164
|
+
const [position, end] = editorSelectionOffsets(input), value = editorValue(input);
|
|
165
|
+
if (position !== end)
|
|
166
|
+
return null;
|
|
167
|
+
let start = position;
|
|
168
|
+
while (start > 0 && /[\p{L}\p{N}_]/u.test(value[start - 1]))
|
|
169
|
+
start--;
|
|
170
|
+
const at = start - 1;
|
|
171
|
+
if (at >= 0 && value[at] === "@" && (at === 0 || !/[A-Za-z0-9_]/.test(value[at - 1]))) {
|
|
172
|
+
return { start: at, query: value.slice(start, position) };
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
132
175
|
}
|
|
133
|
-
|
|
134
176
|
function highlightMention(app, mention) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
177
|
+
const input = mention.editor || app.$("#msgInput"), picker = app.$("#mentionPicker");
|
|
178
|
+
if (!input || !picker)
|
|
179
|
+
return;
|
|
180
|
+
const options = picker.querySelectorAll(".mention-opt");
|
|
181
|
+
options.forEach((option, index) => {
|
|
182
|
+
option.classList.toggle("active", index === mention.index);
|
|
183
|
+
option.setAttribute("aria-selected", String(index === mention.index));
|
|
184
|
+
});
|
|
185
|
+
const active = options[mention.index];
|
|
186
|
+
if (!active) {
|
|
187
|
+
input.removeAttribute("aria-activedescendant");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
active.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
191
|
+
input.setAttribute("aria-activedescendant", active.id);
|
|
144
192
|
}
|
|
@@ -4,48 +4,55 @@
|
|
|
4
4
|
const DB_NAME = "chat-room-history";
|
|
5
5
|
const STORE = "rooms";
|
|
6
6
|
const CACHE_LIMIT = 2000;
|
|
7
|
-
|
|
8
7
|
let opening;
|
|
9
8
|
function open() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
opening ??= new Promise((resolve, reject) => {
|
|
10
|
+
if (!globalThis.indexedDB) {
|
|
11
|
+
reject(new Error("IndexedDB unavailable"));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const request = indexedDB.open(DB_NAME, 1);
|
|
15
|
+
request.onupgradeneeded = () => request.result.createObjectStore(STORE, { keyPath: "roomId" });
|
|
16
|
+
request.onsuccess = () => resolve(request.result);
|
|
17
|
+
request.onerror = () => reject(request.error);
|
|
18
|
+
request.onblocked = () => reject(new Error("IndexedDB blocked"));
|
|
19
|
+
});
|
|
20
|
+
return opening;
|
|
19
21
|
}
|
|
20
|
-
|
|
21
22
|
async function withStore(mode, run) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const db = await open();
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const transaction = db.transaction(STORE, mode);
|
|
26
|
+
const request = run(transaction.objectStore(STORE));
|
|
27
|
+
transaction.oncomplete = () => resolve(request === undefined ? undefined : request.result);
|
|
28
|
+
transaction.onerror = () => reject(transaction.error);
|
|
29
|
+
transaction.onabort = () => reject(transaction.error);
|
|
30
|
+
});
|
|
30
31
|
}
|
|
31
|
-
|
|
32
32
|
export async function loadCachedRooms() {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
try {
|
|
34
|
+
return (await withStore("readonly", (store) => store.getAll())) || [];
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
|
-
|
|
37
40
|
export async function deleteCachedRoom(roomId) {
|
|
38
|
-
|
|
41
|
+
try {
|
|
42
|
+
await withStore("readwrite", (store) => store.delete(roomId));
|
|
43
|
+
}
|
|
44
|
+
catch { /* optional cache */ }
|
|
39
45
|
}
|
|
40
|
-
|
|
41
46
|
const pending = new Map();
|
|
42
47
|
export function cacheRoomSoon(app, roomId) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
pending.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (pending.has(roomId))
|
|
49
|
+
return;
|
|
50
|
+
pending.set(roomId, setTimeout(() => {
|
|
51
|
+
pending.delete(roomId);
|
|
52
|
+
const entry = app.state.rooms.get(roomId);
|
|
53
|
+
if (!entry?.room)
|
|
54
|
+
return;
|
|
55
|
+
const snapshot = { ...entry.room, messages: entry.room.messages.slice(-CACHE_LIMIT) };
|
|
56
|
+
void withStore("readwrite", (store) => store.put({ roomId, name: entry.name, savedAt: Date.now(), room: snapshot })).catch(() => { });
|
|
57
|
+
}, 800));
|
|
51
58
|
}
|