@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.
Files changed (92) hide show
  1. package/CHANGELOG.md +12 -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 +11 -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 +201 -161
  23. package/server/assets/chat/announcements.js +302 -208
  24. package/server/assets/chat/attachment-store.js +116 -76
  25. package/server/assets/chat/attachments.js +701 -441
  26. package/server/assets/chat/chat-background.js +179 -156
  27. package/server/assets/chat/clipboard.js +45 -25
  28. package/server/assets/chat/confirm-dialog.js +38 -35
  29. package/server/assets/chat/copy-action.js +40 -41
  30. package/server/assets/chat/create-room-dialog.js +50 -47
  31. package/server/assets/chat/diagram-viewer.js +293 -236
  32. package/server/assets/chat/doc-preview.js +516 -443
  33. package/server/assets/chat/editor.js +446 -336
  34. package/server/assets/chat/events.js +650 -510
  35. package/server/assets/chat/files.js +505 -431
  36. package/server/assets/chat/history-loader.js +81 -73
  37. package/server/assets/chat/icons.js +9 -11
  38. package/server/assets/chat/image-zoom.js +246 -179
  39. package/server/assets/chat/index.js +2 -3
  40. package/server/assets/chat/install-prompt.js +90 -69
  41. package/server/assets/chat/integration-account-schema.js +91 -87
  42. package/server/assets/chat/integration-editor.js +162 -155
  43. package/server/assets/chat/integration-values.js +116 -101
  44. package/server/assets/chat/integrations.js +750 -626
  45. package/server/assets/chat/join-requests.js +415 -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 -103
  54. package/server/assets/chat/markdown.js +557 -404
  55. package/server/assets/chat/members.js +259 -197
  56. package/server/assets/chat/mentions.js +181 -133
  57. package/server/assets/chat/message-cache.js +40 -33
  58. package/server/assets/chat/message-polling.js +299 -227
  59. package/server/assets/chat/message-window.js +78 -55
  60. package/server/assets/chat/messages.js +562 -480
  61. package/server/assets/chat/office-preview.js +46 -45
  62. package/server/assets/chat/palette.js +464 -417
  63. package/server/assets/chat/panels.js +94 -79
  64. package/server/assets/chat/pwa.js +147 -75
  65. package/server/assets/chat/questions.js +374 -302
  66. package/server/assets/chat/recall.js +338 -273
  67. package/server/assets/chat/receipts.js +151 -121
  68. package/server/assets/chat/reminders.js +345 -214
  69. package/server/assets/chat/replies.js +181 -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 +76 -50
  73. package/server/assets/chat/rooms.js +631 -500
  74. package/server/assets/chat/search.js +138 -114
  75. package/server/assets/chat/settings.js +225 -201
  76. package/server/assets/chat/shiki.js +62 -63
  77. package/server/assets/chat/shortcuts.js +212 -189
  78. package/server/assets/chat/side-pane.js +161 -150
  79. package/server/assets/chat/state.js +860 -737
  80. package/server/assets/chat/system-events.js +46 -44
  81. package/server/assets/chat/system-messages.js +57 -56
  82. package/server/assets/chat/task-form.js +179 -183
  83. package/server/assets/chat/task-row.js +158 -155
  84. package/server/assets/chat/tasks.js +665 -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 +3 -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
@@ -32,9 +32,8 @@ import { initSettings } from "./settings.js";
32
32
  import { initChatBackground } from "./chat-background.js";
33
33
  import { initIntegrations } from "./integrations.js";
34
34
  import { initWindowControls } from "./window-controls.js";
35
-
36
- if (isMobileDevice()) document.documentElement.dataset.mobile = "true";
37
-
35
+ if (isMobileDevice())
36
+ document.documentElement.dataset.mobile = "true";
38
37
  initWindowControls();
39
38
  initSettings(app);
40
39
  initChatBackground(app);
@@ -1,82 +1,103 @@
1
- // A one-time install recommendation for phones. The browser prompt itself is deferred
2
- // until the Install button gesture; desktop, standalone, installed, and recent dissent
3
- // all stay silent. Local storage is optional: blocked storage falls back to this tab.
4
1
  const DISMISS_MS = 30 * 24 * 60 * 60 * 1000;
5
2
  const DISMISS_KEY = "chat.installDismissedAt";
6
3
  const INSTALLED_KEY = "chat.installedApp";
7
4
  const memory = new Map();
8
-
5
+ function installPromptEvent(event) {
6
+ return "prompt" in event && typeof event.prompt === "function";
7
+ }
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
37
+ || navigator.standalone === true;
26
38
  }
27
-
28
39
  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
- }
40
+ const card = app.$("#installPrompt"), installButton = app.$("#btnInstallApp"), guideButton = app.$("#btnInstallGuide"), guide = app.$("#installGuide"), dismissButton = app.$("#btnDismissInstall");
41
+ const rail = app.$("#railInstall"), railInstall = app.$("#btnRailInstall"), railGuide = app.$("#railInstallGuide");
42
+ if (!card || !installButton || !guideButton || !guide || !dismissButton || !rail || !railInstall || !railGuide)
43
+ return;
44
+ const eligible = () => matchMedia("(max-width: 760px)").matches && window.isSecureContext;
45
+ const suppressed = () => read(INSTALLED_KEY) === "1" || Number(read(DISMISS_KEY) || 0) > Date.now() - DISMISS_MS;
46
+ let deferred = null;
47
+ const hide = () => {
48
+ const fromCard = card.contains(document.activeElement), fromRail = rail.contains(document.activeElement);
49
+ card.hidden = true;
50
+ rail.hidden = true;
51
+ if (fromCard)
52
+ app.$("#inName")?.focus({ preventScroll: true });
53
+ else if (fromRail)
54
+ app.$("#btnSettings")?.focus({ preventScroll: true });
55
+ };
56
+ // The join card explains itself; the room drawer carries the same offer for people
57
+ // who restore straight into a room and never see the join page.
58
+ const render = (mode) => {
59
+ const visible = Boolean(mode) && eligible() && !isStandalone() && !suppressed();
60
+ card.hidden = rail.hidden = !visible;
61
+ if (!visible)
62
+ return;
63
+ installButton.hidden = mode !== "prompt";
64
+ guideButton.hidden = mode !== "ios";
65
+ railInstall.hidden = mode !== "prompt";
66
+ railGuide.hidden = mode !== "ios";
67
+ if (mode !== "ios") {
68
+ guide.hidden = true;
69
+ guideButton.setAttribute("aria-expanded", "false");
70
+ }
71
+ };
72
+ window.addEventListener("beforeinstallprompt", (event) => {
73
+ if (!installPromptEvent(event) || !eligible() || isStandalone() || suppressed())
74
+ return;
75
+ event.preventDefault();
76
+ deferred = event;
77
+ render("prompt");
78
+ });
79
+ window.addEventListener("appinstalled", () => { write(INSTALLED_KEY, "1"); hide(); });
80
+ const promptInstall = async () => {
81
+ const prompt = deferred;
82
+ if (!prompt)
83
+ return;
84
+ deferred = null;
85
+ let accepted = false;
86
+ try {
87
+ accepted = (await prompt.prompt())?.outcome === "accepted";
88
+ }
89
+ catch { /* Count it as declined. */ }
90
+ write(accepted ? INSTALLED_KEY : DISMISS_KEY, accepted ? "1" : String(Date.now()));
91
+ hide();
92
+ };
93
+ installButton.addEventListener("click", promptInstall);
94
+ railInstall.addEventListener("click", promptInstall);
95
+ guideButton.addEventListener("click", () => {
96
+ const open = guide.hidden;
97
+ guide.hidden = !open;
98
+ guideButton.setAttribute("aria-expanded", String(open));
99
+ });
100
+ dismissButton.addEventListener("click", () => { write(DISMISS_KEY, String(Date.now())); hide(); });
101
+ if (isIos())
102
+ render("ios");
103
+ }
@@ -1,99 +1,103 @@
1
- // Account form generated from the JSON Schema a plugin declares in initialize.
2
1
  const CONTROL = { string: "text", secret: "password", number: "number" };
3
-
4
2
  function textFor(field, fallback) {
5
- return typeof field.label === "string" && field.label.trim() ? field.label : fallback;
3
+ return typeof field.label === "string" && field.label.trim() ? field.label : fallback;
6
4
  }
7
-
8
5
  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);
6
+ const label = document.createElement("label");
7
+ label.className = "field integration-schema-field";
8
+ const caption = document.createElement("span");
9
+ caption.className = "field-label";
10
+ caption.textContent = textFor(field, field.key);
11
+ if (field.required) {
12
+ const required = document.createElement("span");
13
+ required.className = "integration-required";
14
+ required.textContent = " *";
15
+ caption.append(required);
38
16
  }
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;
17
+ let control;
18
+ if (field.type === "boolean" || field.type === "select") {
19
+ control = document.createElement("select");
20
+ control.className = "input";
21
+ const blank = document.createElement("option");
22
+ blank.value = "";
23
+ blank.textContent = existing
24
+ ? (stored ? text("integrationsKeepStored") : text("integrationsNotSet"))
25
+ : "";
26
+ control.append(blank);
27
+ const options = field.type === "boolean"
28
+ ? [{ value: "1", label: "True" }, { value: "0", label: "False" }]
29
+ : Array.isArray(field.options) ? field.options : [];
30
+ for (const option of options) {
31
+ const node = document.createElement("option");
32
+ node.value = String(option.value);
33
+ node.textContent = typeof option.label === "string" && option.label ? option.label : String(option.value);
34
+ control.append(node);
35
+ }
36
+ if (!existing && typeof field.default === "string" && field.default !== "") {
37
+ control.value = field.type === "boolean"
38
+ ? (["1", "true", "on", "yes"].includes(field.default.toLowerCase()) ? "1" : "0")
39
+ : field.default;
40
+ }
43
41
  }
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);
42
+ else {
43
+ control = document.createElement("input");
44
+ control.className = "input";
45
+ control.type = (field.type && CONTROL[field.type]) || "text";
46
+ control.autocomplete = field.type === "secret" ? "new-password" : "off";
47
+ if (existing)
48
+ control.placeholder = stored ? text("integrationsLeaveBlank") : text("integrationsNotSet");
49
+ else if (typeof field.default === "string")
50
+ 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);
64
64
  }
65
-
66
65
  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
- }
66
+ container.textContent = "";
67
+ const schema = plugin?.account?.schema;
68
+ const fields = Array.isArray(schema) ? 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
+ if (key === undefined)
88
+ continue;
89
+ keys.add(key);
90
+ const value = String(control.value ?? "").trim();
91
+ if (value !== "") {
92
+ values[key] = value;
93
+ continue;
94
+ }
95
+ if (control.dataset.accountRequired === "1" && control.dataset.accountStored !== "1") {
96
+ const label = control.closest(".integration-schema-field")?.querySelector(".field-label")?.textContent || key;
97
+ missing.push(label.replace(/\s*\*$/, ""));
98
+ }
91
99
  }
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
- }
100
+ if (missing.length)
101
+ throw new Error(text("integrationsAccountRequired", { fields: missing.join(", ") }));
102
+ return { values, keys };
103
+ }