@alexsun-top/opencode-chat-room 0.7.8 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/LICENSE +21 -0
  3. package/README.md +77 -36
  4. package/README.zh-CN.md +82 -41
  5. package/cli.ts +27 -1
  6. package/dist/cli.js +6905 -2764
  7. package/package.json +33 -3
  8. package/packages/chat-room-channeld/README.md +315 -0
  9. package/packages/chat-room-channeld/dist/feishu-adapter.js +1262 -0
  10. package/packages/chat-room-channeld/dist/mock-adapter.js +295 -0
  11. package/packages/chat-room-channeld/src/adapter.ts +509 -0
  12. package/packages/chat-room-channeld/src/cli.ts +124 -0
  13. package/packages/chat-room-channeld/src/config.ts +269 -0
  14. package/packages/chat-room-channeld/src/delivery.ts +163 -0
  15. package/packages/chat-room-channeld/src/feishu-adapter.ts +303 -0
  16. package/packages/chat-room-channeld/src/feishu-card.ts +27 -0
  17. package/packages/chat-room-channeld/src/feishu-inbound.ts +158 -0
  18. package/packages/chat-room-channeld/src/feishu-live.ts +355 -0
  19. package/packages/chat-room-channeld/src/feishu-send.ts +342 -0
  20. package/packages/chat-room-channeld/src/feishu-ws-frames.ts +173 -0
  21. package/packages/chat-room-channeld/src/framing.ts +128 -0
  22. package/packages/chat-room-channeld/src/host-helpers.ts +52 -0
  23. package/packages/chat-room-channeld/src/host.ts +627 -0
  24. package/packages/chat-room-channeld/src/inbound.ts +26 -0
  25. package/packages/chat-room-channeld/src/ingest-gate.ts +108 -0
  26. package/packages/chat-room-channeld/src/log.ts +26 -0
  27. package/packages/chat-room-channeld/src/mock-adapter.ts +206 -0
  28. package/packages/chat-room-channeld/src/protocol.ts +75 -0
  29. package/packages/chat-room-channeld/src/published.ts +37 -0
  30. package/packages/chat-room-channeld/src/rules.ts +127 -0
  31. package/packages/chat-room-channeld/src/state.ts +502 -0
  32. package/packages/chat-room-channeld/src/stats.ts +209 -0
  33. package/plugin.ts +22 -5
  34. package/server/addressing-routes.ts +130 -0
  35. package/server/admin-state.ts +13 -13
  36. package/server/app.ts +95 -0
  37. package/server/assets/NOTICE.txt +3 -2
  38. package/server/assets/SHIKI-LICENSE +22 -0
  39. package/server/assets/base.css +24 -10
  40. package/server/assets/chat/announcements.js +70 -7
  41. package/server/assets/chat/doc-preview.js +187 -39
  42. package/server/assets/chat/events.js +3 -0
  43. package/server/assets/chat/files.js +46 -4
  44. package/server/assets/chat/forward.js +69 -0
  45. package/server/assets/chat/index.js +4 -0
  46. package/server/assets/chat/integration-editor.js +163 -0
  47. package/server/assets/chat/integration-values.js +124 -0
  48. package/server/assets/chat/integrations.js +498 -0
  49. package/server/assets/chat/locales/de.js +45 -4
  50. package/server/assets/chat/locales/es.js +45 -4
  51. package/server/assets/chat/locales/fr.js +45 -4
  52. package/server/assets/chat/locales/it.js +45 -4
  53. package/server/assets/chat/locales/ja.js +45 -4
  54. package/server/assets/chat/locales/ko.js +45 -4
  55. package/server/assets/chat/markdown-footnotes.js +115 -0
  56. package/server/assets/chat/markdown.js +46 -43
  57. package/server/assets/chat/messages.js +5 -5
  58. package/server/assets/chat/office-preview.js +69 -0
  59. package/server/assets/chat/palette.js +1 -1
  60. package/server/assets/chat/panels.js +36 -0
  61. package/server/assets/chat/recall.js +58 -7
  62. package/server/assets/chat/receipts.js +15 -3
  63. package/server/assets/chat/reminders.js +69 -8
  64. package/server/assets/chat/replies.js +7 -1
  65. package/server/assets/chat/resource-format.js +11 -0
  66. package/server/assets/chat/settings.js +30 -2
  67. package/server/assets/chat/shiki.js +87 -0
  68. package/server/assets/chat/side-pane.js +9 -3
  69. package/server/assets/chat/state.js +107 -11
  70. package/server/assets/chat/system-events.js +32 -0
  71. package/server/assets/chat/system-messages.js +23 -12
  72. package/server/assets/chat/task-row.js +0 -6
  73. package/server/assets/chat/tasks.js +121 -33
  74. package/server/assets/code-highlight.css +74 -62
  75. package/server/assets/conversation.css +126 -25
  76. package/server/assets/doc-preview.css +36 -3
  77. package/server/assets/files.css +5 -0
  78. package/server/assets/fluent-icons.svg +2 -0
  79. package/server/assets/monaco/LICENSE +21 -0
  80. package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
  81. package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
  82. package/server/assets/monaco/editor.worker.js +45 -0
  83. package/server/assets/monaco/integration-rules.css +1 -0
  84. package/server/assets/monaco/integration-rules.js +1297 -0
  85. package/server/assets/monaco/json.worker.js +77 -0
  86. package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
  87. package/server/assets/office/docx.bundle.js +33 -0
  88. package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
  89. package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
  90. package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
  91. package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
  92. package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
  93. package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
  94. package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
  95. package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
  96. package/server/assets/{HIGHLIGHT-LICENSE → office/licenses/zrender-LICENSE.txt} +2 -2
  97. package/server/assets/office/pptx.bundle.js +104 -0
  98. package/server/assets/office/xlsx.bundle.js +141 -0
  99. package/server/assets/recall.css +5 -4
  100. package/server/assets/responsive.css +52 -8
  101. package/server/assets/settings.css +73 -1
  102. package/server/assets/shiki.bundle.js +152 -0
  103. package/server/assets/tasks.css +57 -7
  104. package/server/channel-integration.ts +519 -0
  105. package/server/channel-settings.ts +77 -0
  106. package/server/channels.ts +557 -0
  107. package/server/chat-server.ts +33 -558
  108. package/server/chat.html +195 -22
  109. package/server/http-server.ts +3 -182
  110. package/server/resource-routes.ts +16 -16
  111. package/server/routes/inbox.ts +100 -0
  112. package/server/routes/pages.ts +83 -0
  113. package/server/routes/questions.ts +39 -0
  114. package/server/routes/room-actions.ts +162 -0
  115. package/server/routes/rooms.ts +160 -0
  116. package/server/startup.ts +84 -0
  117. package/server/sw.js +5 -2
  118. package/server/task-routes.ts +1 -1
  119. package/skills/chatroom/SKILL.md +1 -1
  120. package/src/center/center-client.ts +71 -1
  121. package/src/config/file-config.ts +29 -42
  122. package/src/platform/http-server.ts +182 -0
  123. package/src/protocol/addressing.ts +21 -0
  124. package/src/protocol/config.ts +58 -0
  125. package/src/protocol/room.ts +51 -0
  126. package/src/rooms/resources.ts +26 -16
  127. package/src/rooms/room-service.ts +2 -48
  128. package/src/rooms/storage.ts +329 -0
  129. package/src/rooms/tasks.ts +21 -5
  130. package/src/runtime/v2-plugin.ts +8 -2
  131. package/src/runtime/watch.ts +4 -3
  132. package/src/state/pg-database.ts +183 -0
  133. package/src/state/pg-migrate.ts +175 -0
  134. package/src/state/pg-sql.mjs +175 -0
  135. package/src/state/pg-worker.mjs +148 -0
  136. package/src/state/sqlite-announcements.ts +25 -0
  137. package/src/state/sqlite-database.ts +121 -0
  138. package/src/state/sqlite-legacy.ts +90 -0
  139. package/src/state/sqlite-members.ts +155 -0
  140. package/src/state/sqlite-messages.ts +288 -0
  141. package/src/state/sqlite-resources.ts +39 -0
  142. package/src/state/sqlite-rooms.ts +87 -0
  143. package/src/state/sqlite-schema.ts +80 -0
  144. package/src/state/sqlite-state-store.ts +33 -0
  145. package/src/state/sqlite-state.ts +15 -866
  146. package/src/state/sqlite-tasks.ts +65 -0
  147. package/src/state/sqlite-transaction.ts +13 -0
  148. package/src/state/sqlite.ts +21 -1
  149. package/src/state/store.ts +13 -3
  150. package/src/tui/app.mjs +32 -19
  151. package/src/tui/config.mjs +12 -4
  152. package/src/tui/http.mjs +16 -2
  153. package/src/tui/i18n.mjs +38 -0
  154. package/src/tui/info-app.mjs +50 -51
  155. package/src/tui/info-content.mjs +79 -44
  156. package/src/tui/join-app.mjs +9 -9
  157. package/src/tui/locales/en.mjs +349 -0
  158. package/src/tui/locales/zh-CN.mjs +349 -0
  159. package/src/tui/main.mjs +85 -37
  160. package/src/tui/markdown.mjs +3 -2
  161. package/src/tui/mentions.mjs +3 -1
  162. package/src/tui/message-app.mjs +22 -21
  163. package/src/tui/message-view.mjs +2 -1
  164. package/src/tui/palette-app.mjs +9 -8
  165. package/src/tui/palette.mjs +30 -24
  166. package/src/tui/prefs.mjs +92 -0
  167. package/src/tui/reminder-app.mjs +18 -17
  168. package/src/tui/room-settings-app.mjs +30 -28
  169. package/src/tui/settings-app.mjs +153 -0
  170. package/src/tui/ui-content.mjs +65 -86
  171. package/src/tui/ui-help.mjs +73 -0
  172. package/src/tui/ui-overlay-view.mjs +23 -7
  173. package/src/tui/ui-suggest.mjs +6 -5
  174. package/src/tui/ui-theme.mjs +37 -33
  175. package/src/tui/ui-view.mjs +22 -7
  176. package/src/tui/ui.mjs +15 -3
  177. package/src/web/editor.worker.ts +1 -0
  178. package/src/web/integration-rules-editor.ts +439 -0
  179. package/src/web/integration-rules.ts +22 -0
  180. package/src/web/integration-schema.ts +228 -0
  181. package/src/web/json.worker.ts +1 -0
  182. package/src/web/office-viewer.ts +221 -0
  183. package/server/assets/highlight-10.7.3.min.js +0 -1358
@@ -0,0 +1,163 @@
1
+ // Lazy Monaco wrapper for one integration rules section. The textarea stays in the
2
+ // page as the no-JS and failed-download fallback, so this module never imports Monaco.
3
+ const BUNDLE_URL = "/assets/monaco/integration-rules.js";
4
+ const STYLES_URL = "/assets/monaco/integration-rules.css";
5
+ let bundlePromise = null;
6
+
7
+ function loadBundle() {
8
+ if (!bundlePromise) {
9
+ bundlePromise = import(BUNDLE_URL)
10
+ .then((module) => {
11
+ if (!document.querySelector("link[data-integration-rules-editor]")) {
12
+ const link = document.createElement("link");
13
+ link.rel = "stylesheet";
14
+ link.href = STYLES_URL;
15
+ link.dataset.integrationRulesEditor = "true";
16
+ document.head.append(link);
17
+ }
18
+ return module;
19
+ })
20
+ .catch((error) => {
21
+ // Keep this a warning: a blocked asset must not surface as an uncaught page error.
22
+ console.warn("Integration code editor unavailable; keeping the plain text editor.", error);
23
+ throw error;
24
+ });
25
+ }
26
+ return bundlePromise;
27
+ }
28
+
29
+ export function initIntegrationEditor(app, options) {
30
+ const host = app.$(options.editor);
31
+ const textarea = app.$(options.textarea);
32
+ const fallback = app.$(options.fallback);
33
+ const error = app.$(options.error);
34
+ const errorList = app.$(options.errors);
35
+ const formatGroup = app.$(options.formats);
36
+ let controller = null, loading = null, failed = false, editable = true;
37
+
38
+ if (formatGroup) formatGroup.hidden = true;
39
+
40
+ const applyEditable = () => {
41
+ host?.setAttribute("data-read-only", String(!editable));
42
+ if (textarea) textarea.readOnly = !editable;
43
+ for (const button of formatGroup?.querySelectorAll("[data-format]") || []) button.disabled = !editable;
44
+ controller?.setReadOnly(!editable);
45
+ };
46
+
47
+ const updateFormatButtons = () => {
48
+ const active = controller?.getFormat() || "json";
49
+ for (const button of formatGroup?.querySelectorAll("[data-format]") || []) {
50
+ button.setAttribute("aria-pressed", String(button.dataset.format === active));
51
+ }
52
+ };
53
+
54
+ const render = (result) => {
55
+ if (textarea) textarea.value = result.text;
56
+ host?.setAttribute("data-error-count", String(result.errors.length));
57
+ host?.setAttribute("aria-invalid", String(result.errors.length > 0));
58
+ updateFormatButtons();
59
+ if (!error || !errorList) return;
60
+ errorList.textContent = "";
61
+ if (!result.errors.length) {
62
+ error.hidden = true;
63
+ errorList.hidden = true;
64
+ return;
65
+ }
66
+ const first = result.errors[0];
67
+ error.textContent = app.t("integrationsRulesErrors", {
68
+ count: result.errors.length,
69
+ first: `Line ${first.line}: ${first.message}`,
70
+ });
71
+ error.hidden = false;
72
+ errorList.hidden = false;
73
+ for (const issue of result.errors) {
74
+ const item = document.createElement("li");
75
+ const button = document.createElement("button");
76
+ button.type = "button";
77
+ button.className = "integration-rule-error";
78
+ button.textContent = `Line ${issue.line}${issue.path ? ` · ${issue.path}` : ""}: ${issue.message}`;
79
+ button.addEventListener("click", () => controller?.reveal(issue.line, issue.column));
80
+ item.append(button);
81
+ errorList.append(item);
82
+ }
83
+ };
84
+
85
+ const clearErrors = () => {
86
+ if (error) error.hidden = true;
87
+ if (errorList) { errorList.hidden = true; errorList.textContent = ""; }
88
+ host?.setAttribute("data-error-count", "0");
89
+ host?.removeAttribute("aria-invalid");
90
+ };
91
+
92
+ const ensure = () => {
93
+ if (controller || failed || !host) return loading;
94
+ if (loading) return loading;
95
+ loading = loadBundle().then((module) => {
96
+ controller = module.createIntegrationRulesEditor({
97
+ kind: options.kind,
98
+ container: host,
99
+ value: options.getValue(),
100
+ accounts: options.getAccounts(),
101
+ onChange: render,
102
+ });
103
+ host.hidden = false;
104
+ if (textarea) textarea.hidden = true;
105
+ if (fallback) fallback.hidden = true;
106
+ if (formatGroup) formatGroup.hidden = false;
107
+ applyEditable();
108
+ render(controller.validate());
109
+ }).catch(() => {
110
+ failed = true;
111
+ if (fallback) {
112
+ fallback.textContent = app.t("integrationsEditorUnavailable");
113
+ fallback.hidden = false;
114
+ }
115
+ }).finally(() => { loading = null; });
116
+ return loading;
117
+ };
118
+
119
+ const refresh = () => {
120
+ const value = options.getValue() ?? [];
121
+ clearErrors();
122
+ if (controller) controller.setValue(value);
123
+ else if (textarea) textarea.value = JSON.stringify(value, null, 2);
124
+ };
125
+
126
+ const current = () => {
127
+ if (controller) {
128
+ const result = controller.validate();
129
+ render(result);
130
+ return { editor: true, ...result };
131
+ }
132
+ return { editor: false, text: textarea?.value || "", errors: [] };
133
+ };
134
+
135
+ for (const button of formatGroup?.querySelectorAll("[data-format]") || []) {
136
+ button.addEventListener("click", () => {
137
+ if (!controller || !editable) return;
138
+ controller.setFormat(button.dataset.format === "yaml" ? "yaml" : "json");
139
+ updateFormatButtons();
140
+ });
141
+ }
142
+ textarea?.addEventListener("input", clearErrors);
143
+
144
+ return {
145
+ ensure,
146
+ refresh,
147
+ current,
148
+ showMessage: (message) => {
149
+ if (!error) return;
150
+ error.textContent = message;
151
+ error.hidden = false;
152
+ if (errorList) { errorList.hidden = true; errorList.textContent = ""; }
153
+ },
154
+ setAccounts: (accounts) => controller?.setAccounts(accounts),
155
+ setEditable: (next) => {
156
+ editable = next !== false;
157
+ applyEditable();
158
+ },
159
+ getText: () => textarea?.value || "",
160
+ hasEditor: () => Boolean(controller),
161
+ dispose: () => controller?.dispose(),
162
+ };
163
+ }
@@ -0,0 +1,124 @@
1
+ // Parsing and account-reference checks for integration rules and inbound routes.
2
+ const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
3
+
4
+ export function cleanError(error, fallback) {
5
+ const value = String(error?.message || error || "").trim()
6
+ .replace(/channeld/gi, "integrations")
7
+ .replace(/\bBearer\s+\S+/gi, "Bearer [redacted]")
8
+ .replace(/\b(secret|token|password|authorization|api[_-]?key)\b\s*[:=]\s*\S+/gi, "$1=[redacted]");
9
+ return value || fallback;
10
+ }
11
+
12
+ export function stateLabel(state, text) {
13
+ return text({
14
+ started: "integrationsStateStarted", starting: "integrationsStateStarting", stopped: "integrationsStateStopped",
15
+ error: "integrationsStateError", failed: "integrationsStateError",
16
+ }[state] || "integrationsStateUnknown");
17
+ }
18
+
19
+ export function accountBody(account) {
20
+ const body = { id: account.id, platform: account.platform, pluginId: account.pluginId };
21
+ if (account.envClear) { body.env = {}; return body; }
22
+ const setKeys = Object.keys(account.envSet || {});
23
+ if (setKeys.length) body.env = account.envSet;
24
+ const deleted = (account.envDelete || []).filter((key) => !setKeys.includes(key));
25
+ // Delete-only edits must omit env; {} means clear every stored key.
26
+ if (deleted.length) body.envDelete = deleted;
27
+ return body;
28
+ }
29
+
30
+ export function normalizeAccount(account) {
31
+ const envKeys = Array.isArray(account.envKeys) ? account.envKeys.filter((key) => typeof key === "string") : [];
32
+ return {
33
+ id: String(account.id || ""),
34
+ platform: String(account.platform || ""),
35
+ pluginId: String(account.pluginId || ""),
36
+ envKeys,
37
+ storedKeys: [...envKeys],
38
+ envSet: {},
39
+ envDelete: [],
40
+ envClear: false,
41
+ state: typeof account.state === "string" ? account.state : "unknown",
42
+ lastError: typeof account.lastError === "string" ? account.lastError : "",
43
+ };
44
+ }
45
+
46
+ export function knownPlugins(data) {
47
+ const plugins = [...data.plugins];
48
+ for (const account of data.accounts) {
49
+ if (account.pluginId && !plugins.some((plugin) => plugin.pluginId === account.pluginId)) {
50
+ plugins.push({ pluginId: account.pluginId, name: account.pluginId, platform: account.platform });
51
+ }
52
+ }
53
+ return plugins;
54
+ }
55
+
56
+ function jsonLine(value, message) {
57
+ const position = /position (\d+)/.exec(message), row = /line (\d+)/i.exec(message);
58
+ return position ? value.slice(0, Number(position[1])).split("\n").length : row ? Number(row[1]) : 1;
59
+ }
60
+
61
+ export function parseRules(value, accounts, text) {
62
+ let rules;
63
+ try { rules = JSON.parse(value || "[]"); }
64
+ catch (error) {
65
+ throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, String(error.message)) }));
66
+ }
67
+ return checkRules(rules, accounts, text);
68
+ }
69
+
70
+ export function checkRules(rules, accounts, text) {
71
+ if (!Array.isArray(rules)) throw new Error(text("integrationsInvalidRules"));
72
+ const known = new Set(accounts.map((account) => account.id));
73
+ rules.forEach((rule, index) => {
74
+ const ruleNumber = index + 1;
75
+ if (!isRecord(rule)) throw new Error(text("integrationsInvalidRules"));
76
+ const from = rule.from;
77
+ if (!isRecord(from) || from.platform !== "chatroom" || from.account !== "center") {
78
+ throw new Error(text("integrationsFromRequired", { index: ruleNumber }));
79
+ }
80
+ if (!Array.isArray(rule.to) || !rule.to.length) {
81
+ throw new Error(text("integrationsTargetRequired", { index: ruleNumber, target: 1, field: "to" }));
82
+ }
83
+ rule.to.forEach((target, targetIndex) => {
84
+ if (!isRecord(target)) throw new Error(text("integrationsInvalidRules"));
85
+ for (const field of ["platform", "account", "room"]) {
86
+ if (typeof target[field] !== "string" || !target[field].trim()) {
87
+ throw new Error(text("integrationsTargetRequired", { index: ruleNumber, target: targetIndex + 1, field }));
88
+ }
89
+ }
90
+ if (!known.has(target.account)) {
91
+ throw new Error(text("integrationsTargetMissing", { index: ruleNumber, target: targetIndex + 1, account: target.account }));
92
+ }
93
+ });
94
+ });
95
+ return rules;
96
+ }
97
+
98
+ export function parseInbound(value, accounts, text) {
99
+ let inbound;
100
+ try { inbound = JSON.parse(value || "[]"); }
101
+ catch (error) {
102
+ throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, String(error.message)) }));
103
+ }
104
+ return checkInbound(inbound, accounts);
105
+ }
106
+
107
+ export function checkInbound(inbound, accounts) {
108
+ if (!Array.isArray(inbound)) throw new Error("Inbound routes must be a JSON array.");
109
+ const known = new Map(accounts.map((account) => [account.id, account]));
110
+ inbound.forEach((route, index) => {
111
+ const label = `Inbound route ${index + 1}`;
112
+ if (!isRecord(route) || !isRecord(route.from)) throw new Error(`${label}: from is required.`);
113
+ const from = route.from;
114
+ for (const field of ["platform", "account", "room"]) {
115
+ if (typeof from[field] !== "string" || !from[field].trim()) throw new Error(`${label}: from.${field} is required.`);
116
+ }
117
+ if (from.event !== undefined && typeof from.event !== "string") throw new Error(`${label}: from.event must be a string.`);
118
+ const account = known.get(from.account);
119
+ if (!account) throw new Error(`${label}: account “${from.account}” does not exist.`);
120
+ if (account.platform !== from.platform) throw new Error(`${label}: account “${from.account}” belongs to “${account.platform}”.`);
121
+ if (!isRecord(route.to) || typeof route.to.room !== "string" || !route.to.room.trim()) throw new Error(`${label}: to.room is required.`);
122
+ });
123
+ return inbound;
124
+ }