@alexsun-top/opencode-chat-room 0.8.2 → 0.8.3

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +18 -62
  3. package/README.zh-CN.md +25 -69
  4. package/dist/cli.js +466 -188
  5. package/package.json +8 -5
  6. package/packages/chat-room-channeld/README.md +25 -3
  7. package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
  8. package/packages/chat-room-channeld/src/adapter.ts +5 -0
  9. package/packages/chat-room-channeld/src/cli.ts +72 -5
  10. package/packages/chat-room-channeld/src/host.ts +17 -2
  11. package/packages/chat-room-channeld/src/pg/database.ts +187 -0
  12. package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
  13. package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
  14. package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
  15. package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
  16. package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
  17. package/packages/chat-room-channeld/src/protocol.ts +1 -0
  18. package/packages/chat-room-channeld/src/state.ts +73 -97
  19. package/packages/chat-room-channeld/src/stats.ts +140 -109
  20. package/server/assets/base.css +3 -1
  21. package/server/assets/chat/admin-badge.js +32 -30
  22. package/server/assets/chat/admin.js +198 -161
  23. package/server/assets/chat/announcements.js +295 -208
  24. package/server/assets/chat/attachment-store.js +106 -75
  25. package/server/assets/chat/attachments.js +686 -441
  26. package/server/assets/chat/chat-background.js +185 -156
  27. package/server/assets/chat/clipboard.js +44 -25
  28. package/server/assets/chat/confirm-dialog.js +36 -33
  29. package/server/assets/chat/copy-action.js +40 -40
  30. package/server/assets/chat/create-room-dialog.js +50 -47
  31. package/server/assets/chat/diagram-viewer.js +293 -234
  32. package/server/assets/chat/doc-preview.js +507 -441
  33. package/server/assets/chat/editor.js +423 -335
  34. package/server/assets/chat/events.js +637 -510
  35. package/server/assets/chat/files.js +476 -430
  36. package/server/assets/chat/history-loader.js +79 -73
  37. package/server/assets/chat/icons.js +9 -11
  38. package/server/assets/chat/image-zoom.js +239 -176
  39. package/server/assets/chat/index.js +2 -3
  40. package/server/assets/chat/install-prompt.js +86 -66
  41. package/server/assets/chat/integration-account-schema.js +88 -86
  42. package/server/assets/chat/integration-editor.js +162 -153
  43. package/server/assets/chat/integration-values.js +109 -100
  44. package/server/assets/chat/integrations.js +689 -622
  45. package/server/assets/chat/join-requests.js +408 -358
  46. package/server/assets/chat/locales/de.js +193 -194
  47. package/server/assets/chat/locales/es.js +193 -194
  48. package/server/assets/chat/locales/fr.js +193 -194
  49. package/server/assets/chat/locales/index.js +1 -2
  50. package/server/assets/chat/locales/it.js +193 -194
  51. package/server/assets/chat/locales/ja.js +193 -193
  52. package/server/assets/chat/locales/ko.js +193 -193
  53. package/server/assets/chat/markdown-footnotes.js +134 -102
  54. package/server/assets/chat/markdown.js +547 -403
  55. package/server/assets/chat/members.js +236 -197
  56. package/server/assets/chat/mentions.js +157 -133
  57. package/server/assets/chat/message-cache.js +40 -33
  58. package/server/assets/chat/message-polling.js +280 -227
  59. package/server/assets/chat/message-window.js +74 -55
  60. package/server/assets/chat/messages.js +552 -480
  61. package/server/assets/chat/office-preview.js +46 -45
  62. package/server/assets/chat/palette.js +450 -417
  63. package/server/assets/chat/panels.js +94 -78
  64. package/server/assets/chat/pwa.js +144 -73
  65. package/server/assets/chat/questions.js +372 -302
  66. package/server/assets/chat/recall.js +320 -273
  67. package/server/assets/chat/receipts.js +149 -121
  68. package/server/assets/chat/reminders.js +331 -214
  69. package/server/assets/chat/replies.js +165 -130
  70. package/server/assets/chat/resource-format.js +59 -62
  71. package/server/assets/chat/room-list.js +58 -55
  72. package/server/assets/chat/room-watcher.js +72 -50
  73. package/server/assets/chat/rooms.js +623 -500
  74. package/server/assets/chat/search.js +136 -114
  75. package/server/assets/chat/settings.js +223 -200
  76. package/server/assets/chat/shiki.js +61 -62
  77. package/server/assets/chat/shortcuts.js +212 -187
  78. package/server/assets/chat/side-pane.js +160 -150
  79. package/server/assets/chat/state.js +849 -735
  80. package/server/assets/chat/system-events.js +45 -43
  81. package/server/assets/chat/system-messages.js +57 -56
  82. package/server/assets/chat/task-form.js +178 -182
  83. package/server/assets/chat/task-row.js +158 -155
  84. package/server/assets/chat/tasks.js +653 -587
  85. package/server/assets/chat/viewport.js +32 -29
  86. package/server/assets/chat/window-controls.js +32 -32
  87. package/server/assets/conversation.css +10 -4
  88. package/server/chat-server.ts +9 -1
  89. package/server/chat.html +2 -1
  90. package/server/routes/pages.ts +7 -5
  91. package/server/sw.js +346 -268
  92. package/src/web/integration-rules-editor.ts +2 -0
@@ -5,78 +5,98 @@ const DISMISS_MS = 30 * 24 * 60 * 60 * 1000;
5
5
  const DISMISS_KEY = "chat.installDismissedAt";
6
6
  const INSTALLED_KEY = "chat.installedApp";
7
7
  const memory = new Map();
8
-
9
8
  function read(key) {
10
- try { return localStorage.getItem(key); } catch { /* Try the tab next. */ }
11
- try { return sessionStorage.getItem(key); } catch { /* Use memory. */ }
12
- return memory.get(key) ?? null;
9
+ try {
10
+ return localStorage.getItem(key);
11
+ }
12
+ catch { /* Try the tab next. */ }
13
+ try {
14
+ return sessionStorage.getItem(key);
15
+ }
16
+ catch { /* Use memory. */ }
17
+ return memory.get(key) ?? null;
13
18
  }
14
-
15
19
  function write(key, value) {
16
- try { localStorage.setItem(key, value); return; } catch { /* Try the tab next. */ }
17
- try { sessionStorage.setItem(key, value); } catch { memory.set(key, value); }
20
+ try {
21
+ localStorage.setItem(key, value);
22
+ return;
23
+ }
24
+ catch { /* Try the tab next. */ }
25
+ try {
26
+ sessionStorage.setItem(key, value);
27
+ }
28
+ catch {
29
+ memory.set(key, value);
30
+ }
18
31
  }
19
-
20
32
  function isIos() {
21
- return /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
33
+ return /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
22
34
  }
23
-
24
35
  function isStandalone() {
25
- return matchMedia("(display-mode: standalone)").matches || navigator.standalone === true;
36
+ return matchMedia("(display-mode: standalone)").matches || navigator.standalone === true;
26
37
  }
27
-
28
38
  export function initInstallPrompt(app) {
29
- const card = app.$("#installPrompt"), installButton = app.$("#btnInstallApp"), guideButton = app.$("#btnInstallGuide"), guide = app.$("#installGuide"), dismissButton = app.$("#btnDismissInstall");
30
- const rail = app.$("#railInstall"), railInstall = app.$("#btnRailInstall"), railGuide = app.$("#railInstallGuide");
31
- if (!card || !installButton || !guideButton || !guide || !dismissButton || !rail || !railInstall || !railGuide) return;
32
- const eligible = () => matchMedia("(max-width: 760px)").matches && window.isSecureContext;
33
- const suppressed = () => read(INSTALLED_KEY) === "1" || Number(read(DISMISS_KEY) || 0) > Date.now() - DISMISS_MS;
34
- let deferred = null;
35
-
36
- function hide() {
37
- const fromCard = card.contains(document.activeElement), fromRail = rail.contains(document.activeElement);
38
- card.hidden = true;
39
- rail.hidden = true;
40
- if (fromCard) app.$("#inName")?.focus({ preventScroll: true });
41
- else if (fromRail) app.$("#btnSettings")?.focus({ preventScroll: true });
42
- }
43
-
44
- // The join card explains itself; the room drawer carries the same offer for people
45
- // who restore straight into a room and never see the join page.
46
- function render(mode) {
47
- const visible = Boolean(mode) && eligible() && !isStandalone() && !suppressed();
48
- card.hidden = rail.hidden = !visible;
49
- if (!visible) return;
50
- installButton.hidden = mode !== "prompt";
51
- guideButton.hidden = mode !== "ios";
52
- railInstall.hidden = mode !== "prompt";
53
- railGuide.hidden = mode !== "ios";
54
- if (mode !== "ios") { guide.hidden = true; guideButton.setAttribute("aria-expanded", "false"); }
55
- }
56
-
57
- window.addEventListener("beforeinstallprompt", (event) => {
58
- if (!eligible() || isStandalone() || suppressed()) return;
59
- event.preventDefault();
60
- deferred = event;
61
- render("prompt");
62
- });
63
- window.addEventListener("appinstalled", () => { write(INSTALLED_KEY, "1"); hide(); });
64
- const promptInstall = async () => {
65
- const prompt = deferred;
66
- if (!prompt) return;
67
- deferred = null;
68
- let accepted = false;
69
- try { accepted = (await prompt.prompt())?.outcome === "accepted"; } catch { /* Count it as declined. */ }
70
- write(accepted ? INSTALLED_KEY : DISMISS_KEY, accepted ? "1" : String(Date.now()));
71
- hide();
72
- };
73
- installButton.addEventListener("click", promptInstall);
74
- railInstall.addEventListener("click", promptInstall);
75
- guideButton.addEventListener("click", () => {
76
- const open = guide.hidden;
77
- guide.hidden = !open;
78
- guideButton.setAttribute("aria-expanded", String(open));
79
- });
80
- dismissButton.addEventListener("click", () => { write(DISMISS_KEY, String(Date.now())); hide(); });
81
- if (isIos()) render("ios");
82
- }
39
+ const card = app.$("#installPrompt"), installButton = app.$("#btnInstallApp"), guideButton = app.$("#btnInstallGuide"), guide = app.$("#installGuide"), dismissButton = app.$("#btnDismissInstall");
40
+ const rail = app.$("#railInstall"), railInstall = app.$("#btnRailInstall"), railGuide = app.$("#railInstallGuide");
41
+ if (!card || !installButton || !guideButton || !guide || !dismissButton || !rail || !railInstall || !railGuide)
42
+ return;
43
+ const eligible = () => matchMedia("(max-width: 760px)").matches && window.isSecureContext;
44
+ const suppressed = () => read(INSTALLED_KEY) === "1" || Number(read(DISMISS_KEY) || 0) > Date.now() - DISMISS_MS;
45
+ let deferred = null;
46
+ function hide() {
47
+ const fromCard = card.contains(document.activeElement), fromRail = rail.contains(document.activeElement);
48
+ card.hidden = true;
49
+ rail.hidden = true;
50
+ if (fromCard)
51
+ app.$("#inName")?.focus({ preventScroll: true });
52
+ else if (fromRail)
53
+ app.$("#btnSettings")?.focus({ preventScroll: true });
54
+ }
55
+ // The join card explains itself; the room drawer carries the same offer for people
56
+ // who restore straight into a room and never see the join page.
57
+ function render(mode) {
58
+ const visible = Boolean(mode) && eligible() && !isStandalone() && !suppressed();
59
+ card.hidden = rail.hidden = !visible;
60
+ if (!visible)
61
+ return;
62
+ installButton.hidden = mode !== "prompt";
63
+ guideButton.hidden = mode !== "ios";
64
+ railInstall.hidden = mode !== "prompt";
65
+ railGuide.hidden = mode !== "ios";
66
+ if (mode !== "ios") {
67
+ guide.hidden = true;
68
+ guideButton.setAttribute("aria-expanded", "false");
69
+ }
70
+ }
71
+ window.addEventListener("beforeinstallprompt", (event) => {
72
+ if (!eligible() || isStandalone() || suppressed())
73
+ return;
74
+ event.preventDefault();
75
+ deferred = event;
76
+ render("prompt");
77
+ });
78
+ window.addEventListener("appinstalled", () => { write(INSTALLED_KEY, "1"); hide(); });
79
+ const promptInstall = async () => {
80
+ const prompt = deferred;
81
+ if (!prompt)
82
+ return;
83
+ deferred = null;
84
+ let accepted = false;
85
+ try {
86
+ accepted = (await prompt.prompt())?.outcome === "accepted";
87
+ }
88
+ catch { /* Count it as declined. */ }
89
+ write(accepted ? INSTALLED_KEY : DISMISS_KEY, accepted ? "1" : String(Date.now()));
90
+ hide();
91
+ };
92
+ installButton.addEventListener("click", promptInstall);
93
+ railInstall.addEventListener("click", promptInstall);
94
+ guideButton.addEventListener("click", () => {
95
+ const open = guide.hidden;
96
+ guide.hidden = !open;
97
+ guideButton.setAttribute("aria-expanded", String(open));
98
+ });
99
+ dismissButton.addEventListener("click", () => { write(DISMISS_KEY, String(Date.now())); hide(); });
100
+ if (isIos())
101
+ render("ios");
102
+ }
@@ -1,99 +1,101 @@
1
1
  // Account form generated from the JSON Schema a plugin declares in initialize.
2
2
  const CONTROL = { string: "text", secret: "password", number: "number" };
3
-
4
3
  function textFor(field, fallback) {
5
- return typeof field.label === "string" && field.label.trim() ? field.label : fallback;
4
+ return typeof field.label === "string" && field.label.trim() ? field.label : fallback;
6
5
  }
7
-
8
6
  function addField(container, field, existing, stored, text) {
9
- const label = document.createElement("label");
10
- label.className = "field integration-schema-field";
11
- const caption = document.createElement("span");
12
- caption.className = "field-label";
13
- caption.textContent = textFor(field, field.key);
14
- if (field.required) {
15
- const required = document.createElement("span");
16
- required.className = "integration-required";
17
- required.textContent = " *";
18
- caption.append(required);
19
- }
20
- let control;
21
- if (field.type === "boolean" || field.type === "select") {
22
- control = document.createElement("select");
23
- control.className = "input";
24
- const blank = document.createElement("option");
25
- blank.value = "";
26
- blank.textContent = existing
27
- ? (stored ? text("integrationsKeepStored") : text("integrationsNotSet"))
28
- : "";
29
- control.append(blank);
30
- const options = field.type === "boolean"
31
- ? [{ value: "1", label: "True" }, { value: "0", label: "False" }]
32
- : Array.isArray(field.options) ? field.options : [];
33
- for (const option of options) {
34
- const node = document.createElement("option");
35
- node.value = String(option.value);
36
- node.textContent = typeof option.label === "string" && option.label ? option.label : String(option.value);
37
- control.append(node);
7
+ const label = document.createElement("label");
8
+ label.className = "field integration-schema-field";
9
+ const caption = document.createElement("span");
10
+ caption.className = "field-label";
11
+ caption.textContent = textFor(field, field.key);
12
+ if (field.required) {
13
+ const required = document.createElement("span");
14
+ required.className = "integration-required";
15
+ required.textContent = " *";
16
+ caption.append(required);
38
17
  }
39
- if (!existing && typeof field.default === "string" && field.default !== "") {
40
- control.value = field.type === "boolean"
41
- ? (["1", "true", "on", "yes"].includes(field.default.toLowerCase()) ? "1" : "0")
42
- : field.default;
18
+ let control;
19
+ if (field.type === "boolean" || field.type === "select") {
20
+ control = document.createElement("select");
21
+ control.className = "input";
22
+ const blank = document.createElement("option");
23
+ blank.value = "";
24
+ blank.textContent = existing
25
+ ? (stored ? text("integrationsKeepStored") : text("integrationsNotSet"))
26
+ : "";
27
+ control.append(blank);
28
+ const options = field.type === "boolean"
29
+ ? [{ value: "1", label: "True" }, { value: "0", label: "False" }]
30
+ : Array.isArray(field.options) ? field.options : [];
31
+ for (const option of options) {
32
+ const node = document.createElement("option");
33
+ node.value = String(option.value);
34
+ node.textContent = typeof option.label === "string" && option.label ? option.label : String(option.value);
35
+ control.append(node);
36
+ }
37
+ if (!existing && typeof field.default === "string" && field.default !== "") {
38
+ control.value = field.type === "boolean"
39
+ ? (["1", "true", "on", "yes"].includes(field.default.toLowerCase()) ? "1" : "0")
40
+ : field.default;
41
+ }
43
42
  }
44
- } else {
45
- control = document.createElement("input");
46
- control.className = "input";
47
- control.type = CONTROL[field.type] || "text";
48
- control.autocomplete = field.type === "secret" ? "new-password" : "off";
49
- if (existing) control.placeholder = stored ? text("integrationsLeaveBlank") : text("integrationsNotSet");
50
- else if (typeof field.default === "string") control.value = field.default;
51
- }
52
- control.dataset.accountKey = field.key;
53
- control.dataset.accountType = field.type || "string";
54
- control.dataset.accountRequired = field.required ? "1" : "0";
55
- control.dataset.accountStored = stored ? "1" : "0";
56
- label.append(caption, control);
57
- if (typeof field.description === "string" && field.description.trim()) {
58
- const hint = document.createElement("span");
59
- hint.className = "hint";
60
- hint.textContent = field.description;
61
- label.append(hint);
62
- }
63
- container.append(label);
43
+ else {
44
+ control = document.createElement("input");
45
+ control.className = "input";
46
+ control.type = CONTROL[field.type] || "text";
47
+ control.autocomplete = field.type === "secret" ? "new-password" : "off";
48
+ if (existing)
49
+ control.placeholder = stored ? text("integrationsLeaveBlank") : text("integrationsNotSet");
50
+ else if (typeof field.default === "string")
51
+ control.value = field.default;
52
+ }
53
+ control.dataset.accountKey = field.key;
54
+ control.dataset.accountType = field.type || "string";
55
+ control.dataset.accountRequired = field.required ? "1" : "0";
56
+ control.dataset.accountStored = stored ? "1" : "0";
57
+ label.append(caption, control);
58
+ if (typeof field.description === "string" && field.description.trim()) {
59
+ const hint = document.createElement("span");
60
+ hint.className = "hint";
61
+ hint.textContent = field.description;
62
+ label.append(hint);
63
+ }
64
+ container.append(label);
64
65
  }
65
-
66
66
  export function renderAccountSchema(container, plugin, account, text) {
67
- container.textContent = "";
68
- const fields = Array.isArray(plugin?.account?.schema) ? plugin.account.schema : [];
69
- container.hidden = fields.length === 0;
70
- if (!fields.length) return;
71
- const existing = Boolean(account);
72
- const stored = new Set(account?.envKeys || []);
73
- for (const field of fields) {
74
- if (!field || typeof field.key !== "string") continue;
75
- addField(container, field, existing, stored.has(field.key), text);
76
- }
67
+ container.textContent = "";
68
+ const fields = Array.isArray(plugin?.account?.schema) ? plugin.account.schema : [];
69
+ container.hidden = fields.length === 0;
70
+ if (!fields.length)
71
+ return;
72
+ const existing = Boolean(account);
73
+ const stored = new Set(account?.envKeys || []);
74
+ for (const field of fields) {
75
+ if (!field || typeof field.key !== "string")
76
+ continue;
77
+ addField(container, field, existing, stored.has(field.key), text);
78
+ }
77
79
  }
78
-
79
80
  /** Values still land in the account env map; blank means "keep stored". */
80
81
  export function readAccountSchema(container, text) {
81
- const values = {};
82
- const keys = new Set();
83
- const missing = [];
84
- for (const control of container.querySelectorAll("[data-account-key]")) {
85
- const key = control.dataset.accountKey;
86
- keys.add(key);
87
- const value = String(control.value ?? "").trim();
88
- if (value !== "") {
89
- values[key] = value;
90
- continue;
82
+ const values = {};
83
+ const keys = new Set();
84
+ const missing = [];
85
+ for (const control of container.querySelectorAll("[data-account-key]")) {
86
+ const key = control.dataset.accountKey;
87
+ keys.add(key);
88
+ const value = String(control.value ?? "").trim();
89
+ if (value !== "") {
90
+ values[key] = value;
91
+ continue;
92
+ }
93
+ if (control.dataset.accountRequired === "1" && control.dataset.accountStored !== "1") {
94
+ const label = control.closest(".integration-schema-field")?.querySelector(".field-label")?.textContent || key;
95
+ missing.push(label.replace(/\s*\*$/, ""));
96
+ }
91
97
  }
92
- if (control.dataset.accountRequired === "1" && control.dataset.accountStored !== "1") {
93
- const label = control.closest(".integration-schema-field")?.querySelector(".field-label")?.textContent || key;
94
- missing.push(label.replace(/\s*\*$/, ""));
95
- }
96
- }
97
- if (missing.length) throw new Error(text("integrationsAccountRequired", { fields: missing.join(", ") }));
98
- return { values, keys };
99
- }
98
+ if (missing.length)
99
+ throw new Error(text("integrationsAccountRequired", { fields: missing.join(", ") }));
100
+ return { values, keys };
101
+ }