@alexsun-top/opencode-chat-room 0.8.1 → 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 (125) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +18 -62
  3. package/README.zh-CN.md +25 -69
  4. package/dist/cli.js +1008 -274
  5. package/package.json +10 -7
  6. package/packages/chat-room-channeld/README.md +42 -15
  7. package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
  8. package/packages/chat-room-channeld/src/adapter.ts +150 -7
  9. package/packages/chat-room-channeld/src/cli.ts +72 -5
  10. package/packages/chat-room-channeld/src/host.ts +41 -11
  11. package/packages/chat-room-channeld/src/inbound.ts +13 -4
  12. package/packages/chat-room-channeld/src/pg/database.ts +187 -0
  13. package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
  14. package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
  15. package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
  16. package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
  17. package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
  18. package/packages/chat-room-channeld/src/protocol.ts +53 -1
  19. package/packages/chat-room-channeld/src/rules.ts +7 -2
  20. package/packages/chat-room-channeld/src/state.ts +73 -97
  21. package/packages/chat-room-channeld/src/stats.ts +140 -109
  22. package/plugin.ts +1 -1
  23. package/server/assets/base.css +11 -3
  24. package/server/assets/chat/admin-badge.js +32 -30
  25. package/server/assets/chat/admin.js +198 -163
  26. package/server/assets/chat/announcements.js +295 -210
  27. package/server/assets/chat/attachment-store.js +106 -75
  28. package/server/assets/chat/attachments.js +686 -441
  29. package/server/assets/chat/chat-background.js +206 -0
  30. package/server/assets/chat/clipboard.js +44 -25
  31. package/server/assets/chat/confirm-dialog.js +36 -34
  32. package/server/assets/chat/copy-action.js +40 -40
  33. package/server/assets/chat/create-room-dialog.js +50 -48
  34. package/server/assets/chat/diagram-viewer.js +293 -228
  35. package/server/assets/chat/doc-preview.js +510 -388
  36. package/server/assets/chat/editor.js +423 -335
  37. package/server/assets/chat/events.js +637 -502
  38. package/server/assets/chat/files.js +476 -426
  39. package/server/assets/chat/history-loader.js +79 -73
  40. package/server/assets/chat/icons.js +9 -11
  41. package/server/assets/chat/image-zoom.js +239 -169
  42. package/server/assets/chat/index.js +6 -5
  43. package/server/assets/chat/install-prompt.js +86 -66
  44. package/server/assets/chat/integration-account-schema.js +101 -0
  45. package/server/assets/chat/integration-editor.js +162 -153
  46. package/server/assets/chat/integration-values.js +109 -100
  47. package/server/assets/chat/integrations.js +696 -479
  48. package/server/assets/chat/join-requests.js +408 -358
  49. package/server/assets/chat/locales/de.js +193 -194
  50. package/server/assets/chat/locales/es.js +193 -194
  51. package/server/assets/chat/locales/fr.js +193 -194
  52. package/server/assets/chat/locales/index.js +1 -2
  53. package/server/assets/chat/locales/it.js +193 -194
  54. package/server/assets/chat/locales/ja.js +193 -193
  55. package/server/assets/chat/locales/ko.js +193 -193
  56. package/server/assets/chat/markdown-footnotes.js +134 -102
  57. package/server/assets/chat/markdown.js +553 -386
  58. package/server/assets/chat/members.js +236 -197
  59. package/server/assets/chat/mentions.js +157 -133
  60. package/server/assets/chat/message-cache.js +40 -33
  61. package/server/assets/chat/message-polling.js +280 -227
  62. package/server/assets/chat/message-window.js +74 -55
  63. package/server/assets/chat/messages.js +552 -479
  64. package/server/assets/chat/office-preview.js +46 -45
  65. package/server/assets/chat/palette.js +450 -412
  66. package/server/assets/chat/panels.js +94 -58
  67. package/server/assets/chat/pwa.js +144 -73
  68. package/server/assets/chat/questions.js +372 -302
  69. package/server/assets/chat/recall.js +320 -273
  70. package/server/assets/chat/receipts.js +149 -122
  71. package/server/assets/chat/reminders.js +331 -216
  72. package/server/assets/chat/replies.js +165 -136
  73. package/server/assets/chat/resource-format.js +59 -62
  74. package/server/assets/chat/room-list.js +58 -55
  75. package/server/assets/chat/room-watcher.js +72 -50
  76. package/server/assets/chat/rooms.js +623 -505
  77. package/server/assets/chat/search.js +136 -114
  78. package/server/assets/chat/settings.js +229 -140
  79. package/server/assets/chat/shiki.js +61 -62
  80. package/server/assets/chat/shortcuts.js +212 -190
  81. package/server/assets/chat/side-pane.js +166 -131
  82. package/server/assets/chat/state.js +851 -707
  83. package/server/assets/chat/system-events.js +55 -27
  84. package/server/assets/chat/system-messages.js +59 -49
  85. package/server/assets/chat/task-form.js +178 -182
  86. package/server/assets/chat/task-row.js +158 -155
  87. package/server/assets/chat/tasks.js +653 -593
  88. package/server/assets/chat/viewport.js +32 -29
  89. package/server/assets/chat/window-controls.js +37 -0
  90. package/server/assets/code-highlight.css +22 -6
  91. package/server/assets/conversation.css +65 -16
  92. package/server/assets/doc-preview.css +6 -1
  93. package/server/assets/files.css +3 -0
  94. package/server/assets/monaco/integration-rules.css +1 -1
  95. package/server/assets/monaco/integration-rules.js +841 -533
  96. package/server/assets/responsive.css +32 -2
  97. package/server/assets/settings.css +117 -13
  98. package/server/assets/window-controls.css +36 -0
  99. package/server/channel-attachments.ts +133 -0
  100. package/server/channel-integration.ts +79 -26
  101. package/server/channels.ts +15 -5
  102. package/server/chat-server.ts +9 -1
  103. package/server/chat.html +73 -38
  104. package/server/manifest.webmanifest +1 -0
  105. package/server/routes/pages.ts +7 -5
  106. package/server/sw.js +346 -267
  107. package/src/center/center-client.ts +1 -1
  108. package/src/state/pg-database.ts +5 -5
  109. package/src/state/pg-migrate.ts +7 -7
  110. package/src/state/pg-worker.mjs +2 -17
  111. package/src/state/sqlite-database.ts +14 -5
  112. package/src/state/sqlite-rooms.ts +130 -23
  113. package/src/state/sqlite-state-store.ts +6 -5
  114. package/src/state/sqlite.ts +3 -3
  115. package/src/web/integration-rules-editor.ts +141 -5
  116. package/src/web/integration-rules.ts +6 -2
  117. package/src/web/integration-schema.ts +7 -6
  118. package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
  119. package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
  120. package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
  121. package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
  122. package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
  123. package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
  124. package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
  125. package/server/assets/chat/forward.js +0 -69
@@ -1,124 +1,133 @@
1
1
  // Parsing and account-reference checks for integration rules and inbound routes.
2
2
  const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
3
-
4
3
  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;
4
+ const value = String(error?.message || error || "").trim()
5
+ .replace(/channeld/gi, "integrations")
6
+ .replace(/\bBearer\s+\S+/gi, "Bearer [redacted]")
7
+ .replace(/\b(secret|token|password|authorization|api[_-]?key)\b\s*[:=]\s*\S+/gi, "$1=[redacted]");
8
+ return value || fallback;
10
9
  }
11
-
12
10
  export function stateLabel(state, text) {
13
- return text({
14
- started: "integrationsStateStarted", starting: "integrationsStateStarting", stopped: "integrationsStateStopped",
15
- error: "integrationsStateError", failed: "integrationsStateError",
16
- }[state] || "integrationsStateUnknown");
11
+ return text({
12
+ started: "integrationsStateStarted", starting: "integrationsStateStarting", stopped: "integrationsStateStopped",
13
+ error: "integrationsStateError", failed: "integrationsStateError",
14
+ }[state] || "integrationsStateUnknown");
17
15
  }
18
-
19
16
  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;
17
+ const body = { id: account.id, platform: account.platform, pluginId: account.pluginId };
18
+ if (account.envClear) {
19
+ body.env = {};
20
+ return body;
21
+ }
22
+ const setKeys = Object.keys(account.envSet || {});
23
+ if (setKeys.length)
24
+ body.env = account.envSet;
25
+ const deleted = (account.envDelete || []).filter((key) => !setKeys.includes(key));
26
+ // Delete-only edits must omit env; {} means clear every stored key.
27
+ if (deleted.length)
28
+ body.envDelete = deleted;
29
+ return body;
28
30
  }
29
-
30
31
  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
- };
32
+ const envKeys = Array.isArray(account.envKeys) ? account.envKeys.filter((key) => typeof key === "string") : [];
33
+ return {
34
+ id: String(account.id || ""),
35
+ platform: String(account.platform || ""),
36
+ pluginId: String(account.pluginId || ""),
37
+ envKeys,
38
+ storedKeys: [...envKeys],
39
+ envSet: {},
40
+ envDelete: [],
41
+ envClear: false,
42
+ state: typeof account.state === "string" ? account.state : "unknown",
43
+ lastError: typeof account.lastError === "string" ? account.lastError : "",
44
+ };
44
45
  }
45
-
46
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 });
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
+ }
51
52
  }
52
- }
53
- return plugins;
53
+ return plugins;
54
54
  }
55
-
56
55
  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;
56
+ const position = /position (\d+)/.exec(message), row = /line (\d+)/i.exec(message);
57
+ return position ? value.slice(0, Number(position[1])).split("\n").length : row ? Number(row[1]) : 1;
59
58
  }
60
-
61
59
  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 }));
60
+ let rules;
61
+ try {
62
+ rules = JSON.parse(value || "[]");
79
63
  }
80
- if (!Array.isArray(rule.to) || !rule.to.length) {
81
- throw new Error(text("integrationsTargetRequired", { index: ruleNumber, target: 1, field: "to" }));
64
+ catch (error) {
65
+ throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, String(error.message)) }));
82
66
  }
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 }));
67
+ return checkRules(rules, accounts, text);
68
+ }
69
+ export function checkRules(rules, accounts, text) {
70
+ if (!Array.isArray(rules))
71
+ 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))
76
+ throw new Error(text("integrationsInvalidRules"));
77
+ const from = rule.from;
78
+ if (!isRecord(from) || from.platform !== "chatroom" || from.account !== "center") {
79
+ throw new Error(text("integrationsFromRequired", { index: ruleNumber }));
80
+ }
81
+ if (!Array.isArray(rule.to) || !rule.to.length) {
82
+ throw new Error(text("integrationsTargetRequired", { index: ruleNumber, target: 1, field: "to" }));
88
83
  }
89
- }
90
- if (!known.has(target.account)) {
91
- throw new Error(text("integrationsTargetMissing", { index: ruleNumber, target: targetIndex + 1, account: target.account }));
92
- }
84
+ rule.to.forEach((target, targetIndex) => {
85
+ if (!isRecord(target))
86
+ throw new Error(text("integrationsInvalidRules"));
87
+ for (const field of ["platform", "account", "room"]) {
88
+ if (typeof target[field] !== "string" || !target[field].trim()) {
89
+ throw new Error(text("integrationsTargetRequired", { index: ruleNumber, target: targetIndex + 1, field }));
90
+ }
91
+ }
92
+ if (!known.has(target.account)) {
93
+ throw new Error(text("integrationsTargetMissing", { index: ruleNumber, target: targetIndex + 1, account: target.account }));
94
+ }
95
+ });
93
96
  });
94
- });
95
- return rules;
97
+ return rules;
96
98
  }
97
-
98
99
  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);
100
+ let inbound;
101
+ try {
102
+ inbound = JSON.parse(value || "[]");
103
+ }
104
+ catch (error) {
105
+ throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, String(error.message)) }));
106
+ }
107
+ return checkInbound(inbound, accounts);
105
108
  }
106
-
107
109
  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
- }
110
+ if (!Array.isArray(inbound))
111
+ throw new Error("Inbound routes must be a JSON array.");
112
+ const known = new Map(accounts.map((account) => [account.id, account]));
113
+ inbound.forEach((route, index) => {
114
+ const label = `Inbound route ${index + 1}`;
115
+ if (!isRecord(route) || !isRecord(route.from))
116
+ throw new Error(`${label}: from is required.`);
117
+ const from = route.from;
118
+ for (const field of ["platform", "account", "room"]) {
119
+ if (typeof from[field] !== "string" || !from[field].trim())
120
+ throw new Error(`${label}: from.${field} is required.`);
121
+ }
122
+ if (from.event !== undefined && typeof from.event !== "string")
123
+ throw new Error(`${label}: from.event must be a string.`);
124
+ const account = known.get(from.account);
125
+ if (!account)
126
+ throw new Error(`${label}: account “${from.account}” does not exist.`);
127
+ if (account.platform !== from.platform)
128
+ throw new Error(`${label}: account “${from.account}” belongs to “${account.platform}”.`);
129
+ if (!isRecord(route.to) || typeof route.to.room !== "string" || !route.to.room.trim())
130
+ throw new Error(`${label}: to.room is required.`);
131
+ });
132
+ return inbound;
133
+ }