@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.
- package/CHANGELOG.md +33 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +1008 -274
- package/package.json +10 -7
- package/packages/chat-room-channeld/README.md +42 -15
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +150 -7
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +41 -11
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- 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 +53 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/plugin.ts +1 -1
- package/server/assets/base.css +11 -3
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -163
- package/server/assets/chat/announcements.js +295 -210
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +206 -0
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -34
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -48
- package/server/assets/chat/diagram-viewer.js +293 -228
- package/server/assets/chat/doc-preview.js +510 -388
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -502
- package/server/assets/chat/files.js +476 -426
- package/server/assets/chat/history-loader.js +79 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +239 -169
- package/server/assets/chat/index.js +6 -5
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +101 -0
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +696 -479
- package/server/assets/chat/join-requests.js +408 -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 -102
- package/server/assets/chat/markdown.js +553 -386
- package/server/assets/chat/members.js +236 -197
- package/server/assets/chat/mentions.js +157 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +280 -227
- package/server/assets/chat/message-window.js +74 -55
- package/server/assets/chat/messages.js +552 -479
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -412
- package/server/assets/chat/panels.js +94 -58
- package/server/assets/chat/pwa.js +144 -73
- package/server/assets/chat/questions.js +372 -302
- package/server/assets/chat/recall.js +320 -273
- package/server/assets/chat/receipts.js +149 -122
- package/server/assets/chat/reminders.js +331 -216
- package/server/assets/chat/replies.js +165 -136
- 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 +72 -50
- package/server/assets/chat/rooms.js +623 -505
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +229 -140
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -190
- package/server/assets/chat/side-pane.js +166 -131
- package/server/assets/chat/state.js +851 -707
- package/server/assets/chat/system-events.js +55 -27
- package/server/assets/chat/system-messages.js +59 -49
- package/server/assets/chat/task-form.js +178 -182
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +653 -593
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +65 -16
- package/server/assets/doc-preview.css +6 -1
- package/server/assets/files.css +3 -0
- package/server/assets/monaco/integration-rules.css +1 -1
- package/server/assets/monaco/integration-rules.js +841 -533
- package/server/assets/responsive.css +32 -2
- package/server/assets/settings.css +117 -13
- package/server/assets/window-controls.css +36 -0
- package/server/channel-attachments.ts +133 -0
- package/server/channel-integration.ts +79 -26
- package/server/channels.ts +15 -5
- package/server/chat-server.ts +9 -1
- package/server/chat.html +73 -38
- package/server/manifest.webmanifest +1 -0
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -267
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-database.ts +5 -5
- package/src/state/pg-migrate.ts +7 -7
- package/src/state/pg-worker.mjs +2 -17
- package/src/state/sqlite-database.ts +14 -5
- package/src/state/sqlite-rooms.ts +130 -23
- package/src/state/sqlite-state-store.ts +6 -5
- package/src/state/sqlite.ts +3 -3
- package/src/web/integration-rules-editor.ts +141 -5
- package/src/web/integration-rules.ts +6 -2
- package/src/web/integration-schema.ts +7 -6
- package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
- package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
- package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
- package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
- package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
- package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
58
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
81
|
-
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, String(error.message)) }));
|
|
82
66
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
91
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
+
}
|