@alexsun-top/opencode-chat-room 0.8.0 → 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.
- package/CHANGELOG.md +29 -0
- package/LICENSE +2 -2
- package/README.md +38 -6
- package/README.zh-CN.md +38 -6
- package/cli.ts +27 -1
- package/dist/cli.js +5074 -3212
- package/package.json +23 -3
- package/packages/chat-room-channeld/README.md +98 -25
- package/packages/chat-room-channeld/dist/feishu-adapter.js +912 -149
- package/packages/chat-room-channeld/src/adapter.ts +36 -2
- package/packages/chat-room-channeld/src/config.ts +63 -1
- package/packages/chat-room-channeld/src/delivery.ts +6 -1
- package/packages/chat-room-channeld/src/feishu-adapter.ts +122 -292
- package/packages/chat-room-channeld/src/feishu-card.ts +27 -0
- package/packages/chat-room-channeld/src/feishu-inbound.ts +158 -0
- package/packages/chat-room-channeld/src/feishu-live.ts +355 -0
- package/packages/chat-room-channeld/src/feishu-send.ts +342 -0
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +173 -0
- package/packages/chat-room-channeld/src/host-helpers.ts +11 -0
- package/packages/chat-room-channeld/src/host.ts +120 -2
- package/packages/chat-room-channeld/src/inbound.ts +26 -0
- package/packages/chat-room-channeld/src/state.ts +17 -0
- package/packages/chat-room-channeld/src/stats.ts +43 -1
- package/server/admin-state.ts +13 -13
- package/server/app.ts +95 -0
- package/server/assets/NOTICE.txt +2 -1
- package/server/assets/base.css +15 -9
- package/server/assets/chat/announcements.js +70 -7
- package/server/assets/chat/doc-preview.js +184 -35
- package/server/assets/chat/events.js +3 -0
- package/server/assets/chat/files.js +46 -4
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/integration-editor.js +163 -0
- package/server/assets/chat/integration-values.js +124 -0
- package/server/assets/chat/integrations.js +498 -0
- package/server/assets/chat/locales/de.js +40 -4
- package/server/assets/chat/locales/es.js +40 -4
- package/server/assets/chat/locales/fr.js +40 -4
- package/server/assets/chat/locales/it.js +40 -4
- package/server/assets/chat/locales/ja.js +40 -4
- package/server/assets/chat/locales/ko.js +40 -4
- package/server/assets/chat/markdown.js +22 -8
- package/server/assets/chat/messages.js +5 -5
- package/server/assets/chat/office-preview.js +69 -0
- package/server/assets/chat/panels.js +36 -0
- package/server/assets/chat/recall.js +58 -7
- package/server/assets/chat/receipts.js +15 -3
- package/server/assets/chat/reminders.js +69 -8
- package/server/assets/chat/resource-format.js +11 -0
- package/server/assets/chat/settings.js +30 -2
- package/server/assets/chat/side-pane.js +1 -2
- package/server/assets/chat/state.js +93 -10
- package/server/assets/chat/system-events.js +32 -0
- package/server/assets/chat/system-messages.js +23 -14
- package/server/assets/chat/task-row.js +0 -6
- package/server/assets/chat/tasks.js +121 -33
- package/server/assets/code-highlight.css +55 -32
- package/server/assets/conversation.css +123 -23
- package/server/assets/doc-preview.css +35 -3
- package/server/assets/files.css +5 -0
- package/server/assets/fluent-icons.svg +2 -0
- package/server/assets/monaco/LICENSE +21 -0
- package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
- package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
- package/server/assets/monaco/editor.worker.js +45 -0
- package/server/assets/monaco/integration-rules.css +1 -0
- package/server/assets/monaco/integration-rules.js +1297 -0
- package/server/assets/monaco/json.worker.js +77 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
- package/server/assets/office/docx.bundle.js +33 -0
- package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
- package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
- package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
- package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
- package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
- package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
- package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
- package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
- package/server/assets/office/licenses/zrender-LICENSE.txt +29 -0
- package/server/assets/office/pptx.bundle.js +104 -0
- package/server/assets/office/xlsx.bundle.js +141 -0
- package/server/assets/recall.css +5 -4
- package/server/assets/responsive.css +50 -11
- package/server/assets/settings.css +73 -1
- package/server/assets/tasks.css +57 -7
- package/server/channel-integration.ts +519 -0
- package/server/channel-settings.ts +77 -0
- package/server/channels.ts +261 -18
- package/server/chat-server.ts +32 -580
- package/server/chat.html +187 -21
- package/server/http-server.ts +3 -182
- package/server/resource-routes.ts +16 -16
- package/server/routes/inbox.ts +100 -0
- package/server/routes/pages.ts +83 -0
- package/server/routes/questions.ts +39 -0
- package/server/routes/room-actions.ts +162 -0
- package/server/routes/rooms.ts +160 -0
- package/server/startup.ts +84 -0
- package/server/sw.js +4 -0
- package/server/task-routes.ts +1 -1
- package/src/center/center-client.ts +2 -10
- package/src/config/file-config.ts +7 -54
- package/src/platform/http-server.ts +182 -0
- package/src/protocol/addressing.ts +21 -0
- package/src/protocol/config.ts +58 -0
- package/src/protocol/room.ts +51 -0
- package/src/rooms/resources.ts +26 -16
- package/src/rooms/room-service.ts +2 -48
- package/src/rooms/storage.ts +329 -0
- package/src/rooms/tasks.ts +21 -5
- package/src/runtime/watch.ts +1 -1
- package/src/state/pg-database.ts +183 -0
- package/src/state/pg-migrate.ts +175 -0
- package/src/state/pg-sql.mjs +175 -0
- package/src/state/pg-worker.mjs +148 -0
- package/src/state/sqlite-announcements.ts +25 -0
- package/src/state/sqlite-database.ts +121 -0
- package/src/state/sqlite-legacy.ts +90 -0
- package/src/state/sqlite-members.ts +155 -0
- package/src/state/sqlite-messages.ts +288 -0
- package/src/state/sqlite-resources.ts +39 -0
- package/src/state/sqlite-rooms.ts +87 -0
- package/src/state/sqlite-schema.ts +80 -0
- package/src/state/sqlite-state-store.ts +33 -0
- package/src/state/sqlite-state.ts +15 -897
- package/src/state/sqlite-tasks.ts +65 -0
- package/src/state/sqlite-transaction.ts +13 -0
- package/src/state/sqlite.ts +21 -1
- package/src/state/store.ts +5 -1
- package/src/tui/app.mjs +32 -19
- package/src/tui/config.mjs +12 -4
- package/src/tui/i18n.mjs +38 -0
- package/src/tui/info-app.mjs +50 -51
- package/src/tui/info-content.mjs +79 -44
- package/src/tui/join-app.mjs +9 -9
- package/src/tui/locales/en.mjs +349 -0
- package/src/tui/locales/zh-CN.mjs +349 -0
- package/src/tui/main.mjs +85 -37
- package/src/tui/markdown.mjs +3 -2
- package/src/tui/mentions.mjs +3 -1
- package/src/tui/message-app.mjs +22 -21
- package/src/tui/message-view.mjs +2 -1
- package/src/tui/palette-app.mjs +9 -8
- package/src/tui/palette.mjs +30 -24
- package/src/tui/prefs.mjs +92 -0
- package/src/tui/reminder-app.mjs +18 -17
- package/src/tui/room-settings-app.mjs +30 -28
- package/src/tui/settings-app.mjs +153 -0
- package/src/tui/ui-content.mjs +65 -86
- package/src/tui/ui-help.mjs +73 -0
- package/src/tui/ui-overlay-view.mjs +23 -7
- package/src/tui/ui-suggest.mjs +6 -5
- package/src/tui/ui-theme.mjs +37 -33
- package/src/tui/ui-view.mjs +22 -7
- package/src/tui/ui.mjs +15 -3
- package/src/web/editor.worker.ts +1 -0
- package/src/web/integration-rules-editor.ts +439 -0
- package/src/web/integration-rules.ts +22 -0
- package/src/web/integration-schema.ts +228 -0
- package/src/web/json.worker.ts +1 -0
- package/src/web/office-viewer.ts +221 -0
package/src/tui/message-app.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// confirmation, and a prompt-based reply flow that uses api.send's replyTo.
|
|
3
3
|
import { mergeMessages } from "./messages.mjs";
|
|
4
4
|
import { canonicalizeMentions } from "./mentions.mjs";
|
|
5
|
+
import { t } from "./i18n.mjs";
|
|
5
6
|
|
|
6
7
|
const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
|
|
7
8
|
|
|
@@ -11,7 +12,7 @@ export function attachMessageActions(Class) {
|
|
|
11
12
|
const palette = this.state.palette;
|
|
12
13
|
if (!palette || !this.state.current || !this.state.joined) {
|
|
13
14
|
this.state.palette = null;
|
|
14
|
-
this.setStatus("
|
|
15
|
+
this.setStatus(t("info.joinFirst"), "error");
|
|
15
16
|
return null;
|
|
16
17
|
}
|
|
17
18
|
palette.mode = "prompt";
|
|
@@ -21,25 +22,25 @@ export function attachMessageActions(Class) {
|
|
|
21
22
|
palette.subtitle = `#${this.state.current.name}`;
|
|
22
23
|
palette.error = "";
|
|
23
24
|
palette.prompt = { label, value: "", action, data };
|
|
24
|
-
palette.hint = "
|
|
25
|
+
palette.hint = t("palette.enterNextHint");
|
|
25
26
|
this.touch();
|
|
26
27
|
return palette;
|
|
27
28
|
},
|
|
28
29
|
|
|
29
30
|
startMessageRecall() {
|
|
30
|
-
return this.messageActionPalette("
|
|
31
|
+
return this.messageActionPalette(t("message.recallTitle"), t("message.recallPrompt"), "message-recall-id");
|
|
31
32
|
},
|
|
32
33
|
|
|
33
34
|
startMessageReveal() {
|
|
34
|
-
return this.messageActionPalette("
|
|
35
|
+
return this.messageActionPalette(t("message.revealTitle"), t("message.revealPrompt"), "message-reveal-id");
|
|
35
36
|
},
|
|
36
37
|
|
|
37
38
|
startMessageReply() {
|
|
38
|
-
return this.messageActionPalette("
|
|
39
|
+
return this.messageActionPalette(t("message.replyTitle"), t("message.replyPrompt"), "message-reply-id");
|
|
39
40
|
},
|
|
40
41
|
|
|
41
42
|
startAskQuestion() {
|
|
42
|
-
return this.messageActionPalette("
|
|
43
|
+
return this.messageActionPalette(t("message.askTitle"), t("message.askPrompt"), "message-ask");
|
|
43
44
|
},
|
|
44
45
|
|
|
45
46
|
async submitMessagePrompt(prompt, value) {
|
|
@@ -48,14 +49,14 @@ export function attachMessageActions(Class) {
|
|
|
48
49
|
const participants = palette?.roomParticipants || this.state.current?.participants;
|
|
49
50
|
if (!palette || palette.mode !== "prompt") return;
|
|
50
51
|
if (!roomId) {
|
|
51
|
-
palette.error = "
|
|
52
|
+
palette.error = t("info.joinFirst");
|
|
52
53
|
this.touch();
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
if (prompt.action === "message-ask") {
|
|
56
57
|
const question = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
57
58
|
if (!question) {
|
|
58
|
-
palette.error = "
|
|
59
|
+
palette.error = t("message.questionRequired");
|
|
59
60
|
this.touch();
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
@@ -68,7 +69,7 @@ export function attachMessageActions(Class) {
|
|
|
68
69
|
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
69
70
|
this.state.connection = "online";
|
|
70
71
|
this.closePalette();
|
|
71
|
-
this.setStatus("
|
|
72
|
+
this.setStatus(t("message.questionSent"), "success");
|
|
72
73
|
this.markRead();
|
|
73
74
|
} catch (error) {
|
|
74
75
|
if (this.state.palette === palette) {
|
|
@@ -81,7 +82,7 @@ export function attachMessageActions(Class) {
|
|
|
81
82
|
}
|
|
82
83
|
const id = String(value ?? "").trim();
|
|
83
84
|
if (!id) {
|
|
84
|
-
palette.error = "message
|
|
85
|
+
palette.error = t("message.idRequired");
|
|
85
86
|
this.touch();
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
@@ -90,23 +91,23 @@ export function attachMessageActions(Class) {
|
|
|
90
91
|
palette.mode = "confirm";
|
|
91
92
|
palette.previous = { mode: "prompt", hint: palette.hint };
|
|
92
93
|
palette.confirm = {
|
|
93
|
-
text: recall ?
|
|
94
|
+
text: recall ? t("message.recallConfirm", { id }) : t("message.revealConfirm", { id }),
|
|
94
95
|
action: recall ? "message-recall" : "message-reveal",
|
|
95
96
|
data: { id },
|
|
96
97
|
};
|
|
97
|
-
palette.hint = "
|
|
98
|
+
palette.hint = t("palette.confirmHint");
|
|
98
99
|
palette.error = "";
|
|
99
100
|
this.touch();
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
103
|
if (prompt.action === "message-reply-id") {
|
|
103
104
|
palette.prompt = {
|
|
104
|
-
label:
|
|
105
|
+
label: t("message.replyLabel", { id }),
|
|
105
106
|
value: "",
|
|
106
107
|
action: "message-reply-text",
|
|
107
108
|
data: { id },
|
|
108
109
|
};
|
|
109
|
-
palette.hint = "
|
|
110
|
+
palette.hint = t("message.replyHint");
|
|
110
111
|
palette.error = "";
|
|
111
112
|
this.touch();
|
|
112
113
|
return;
|
|
@@ -114,7 +115,7 @@ export function attachMessageActions(Class) {
|
|
|
114
115
|
if (prompt.action === "message-reply-text") {
|
|
115
116
|
const text = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
116
117
|
if (!text) {
|
|
117
|
-
palette.error = "
|
|
118
|
+
palette.error = t("message.replyRequired");
|
|
118
119
|
this.touch();
|
|
119
120
|
return;
|
|
120
121
|
}
|
|
@@ -128,7 +129,7 @@ export function attachMessageActions(Class) {
|
|
|
128
129
|
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
129
130
|
this.state.connection = "online";
|
|
130
131
|
this.closePalette();
|
|
131
|
-
this.setStatus("
|
|
132
|
+
this.setStatus(t("message.replySent"), "success");
|
|
132
133
|
this.markRead();
|
|
133
134
|
} catch (error) {
|
|
134
135
|
if (this.state.palette === palette) {
|
|
@@ -154,19 +155,19 @@ export function attachMessageActions(Class) {
|
|
|
154
155
|
const target = this.state.messages.find((message) => message.id === id);
|
|
155
156
|
if (target) target.recalledAt = Date.now();
|
|
156
157
|
this.closePalette();
|
|
157
|
-
this.setStatus(
|
|
158
|
+
this.setStatus(t("message.recalledStatus", { id }), "success");
|
|
158
159
|
return;
|
|
159
160
|
}
|
|
160
161
|
const revealed = await this.api.reveal(roomId, id, this.sessionID);
|
|
161
162
|
palette.mode = "detail";
|
|
162
|
-
palette.title = "
|
|
163
|
+
palette.title = t("message.revealed");
|
|
163
164
|
palette.confirm = null;
|
|
164
165
|
palette.detail = {
|
|
165
|
-
title: "
|
|
166
|
-
markdown: String(revealed?.text ?? "
|
|
166
|
+
title: t("message.revealed"),
|
|
167
|
+
markdown: String(revealed?.text ?? t("message.empty")),
|
|
167
168
|
kind: "revealed-message",
|
|
168
169
|
};
|
|
169
|
-
palette.hint = "
|
|
170
|
+
palette.hint = t("palette.closeHint");
|
|
170
171
|
palette.searching = false;
|
|
171
172
|
this.touch();
|
|
172
173
|
} catch (error) {
|
package/src/tui/message-view.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
formatAttachments,
|
|
19
19
|
prepareMarkdown,
|
|
20
20
|
} from "./markdown.mjs";
|
|
21
|
+
import { t } from "./i18n.mjs";
|
|
21
22
|
|
|
22
23
|
let treeSitter;
|
|
23
24
|
const treeClient = () => (treeSitter ??= getTreeSitterClient());
|
|
@@ -67,7 +68,7 @@ function messageBody(ui, message, info, highlighted) {
|
|
|
67
68
|
id: `message-recalled-${message.id}`,
|
|
68
69
|
width: "100%",
|
|
69
70
|
wrapMode: "word",
|
|
70
|
-
content: new StyledText([dim(italic("
|
|
71
|
+
content: new StyledText([dim(italic(t("chat.recalled")))]),
|
|
71
72
|
}));
|
|
72
73
|
return body;
|
|
73
74
|
}
|
package/src/tui/palette-app.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// terminal core stays under the project line budget.
|
|
3
3
|
import { buildCommands, filterCommands, nextScope, scopeSources, searchMessages } from "./palette.mjs";
|
|
4
4
|
import { mergeMessages, oldestSeq } from "./messages.mjs";
|
|
5
|
+
import { t } from "./i18n.mjs";
|
|
5
6
|
|
|
6
7
|
const SEARCH_PAGES = 2;
|
|
7
8
|
|
|
@@ -93,7 +94,7 @@ export function attachPalette(Class) {
|
|
|
93
94
|
// A failed page must not consume the room's search budget.
|
|
94
95
|
this.historyPages.set(room.id, (this.historyPages.get(room.id) ?? 0) + 1);
|
|
95
96
|
} catch (error) {
|
|
96
|
-
if (this.state.palette === palette) palette.error =
|
|
97
|
+
if (this.state.palette === palette) palette.error = t("palette.historyError", { error: error.message ?? error });
|
|
97
98
|
} finally {
|
|
98
99
|
this.historyInflight.delete(room.id);
|
|
99
100
|
}
|
|
@@ -168,7 +169,7 @@ export function attachPalette(Class) {
|
|
|
168
169
|
return;
|
|
169
170
|
case "new-room":
|
|
170
171
|
palette.mode = "prompt";
|
|
171
|
-
palette.prompt = { label: "
|
|
172
|
+
palette.prompt = { label: t("palette.newRoomPrompt"), value: "", action: "new-room", data: {} };
|
|
172
173
|
palette.selected = 0;
|
|
173
174
|
palette.error = "";
|
|
174
175
|
this.touch();
|
|
@@ -213,7 +214,7 @@ export function attachPalette(Class) {
|
|
|
213
214
|
await this.openReminders();
|
|
214
215
|
return;
|
|
215
216
|
case "settings":
|
|
216
|
-
this.
|
|
217
|
+
this.openSettingsEditor();
|
|
217
218
|
return;
|
|
218
219
|
case "room-settings":
|
|
219
220
|
await this.openRoomSettings();
|
|
@@ -260,7 +261,7 @@ export function attachPalette(Class) {
|
|
|
260
261
|
const palette = this.state.palette;
|
|
261
262
|
const name = String(palette?.prompt?.value ?? "").trim();
|
|
262
263
|
if (!name) {
|
|
263
|
-
palette.error = "
|
|
264
|
+
palette.error = t("palette.enterRoomName");
|
|
264
265
|
this.touch();
|
|
265
266
|
return;
|
|
266
267
|
}
|
|
@@ -274,7 +275,7 @@ export function attachPalette(Class) {
|
|
|
274
275
|
const index = this.state.rooms.findIndex((room) => room.id === roomID);
|
|
275
276
|
this.closePalette();
|
|
276
277
|
if (index >= 0) await this.openRoom(index);
|
|
277
|
-
else this.setStatus(
|
|
278
|
+
else this.setStatus(t("palette.created", { name }), "success");
|
|
278
279
|
} catch (error) {
|
|
279
280
|
if (this.state.palette) {
|
|
280
281
|
this.state.palette.searching = false;
|
|
@@ -287,7 +288,7 @@ export function attachPalette(Class) {
|
|
|
287
288
|
async leaveCurrent() {
|
|
288
289
|
const room = this.state.current;
|
|
289
290
|
if (!room || !this.state.joined) {
|
|
290
|
-
this.setStatus("
|
|
291
|
+
this.setStatus(t("palette.notJoined"), "error");
|
|
291
292
|
return;
|
|
292
293
|
}
|
|
293
294
|
try {
|
|
@@ -297,9 +298,9 @@ export function attachPalette(Class) {
|
|
|
297
298
|
const summary = this.state.rooms.find((item) => item.id === room.id);
|
|
298
299
|
if (summary) summary.joined = false;
|
|
299
300
|
await this.refreshRooms(true);
|
|
300
|
-
this.setStatus(
|
|
301
|
+
this.setStatus(t("palette.left", { name: room.name }), "success");
|
|
301
302
|
} catch (error) {
|
|
302
|
-
this.setStatus(
|
|
303
|
+
this.setStatus(t("palette.leaveFailed", { error: error.message ?? error }), "error");
|
|
303
304
|
}
|
|
304
305
|
},
|
|
305
306
|
|
package/src/tui/palette.mjs
CHANGED
|
@@ -1,45 +1,51 @@
|
|
|
1
1
|
// Pure command palette logic: command lists, scoped client-side search,
|
|
2
2
|
// ranking and snippets. No I/O lives here so it is easy to test.
|
|
3
|
+
import { t } from "./i18n.mjs";
|
|
3
4
|
|
|
4
5
|
const SEARCH_LIMIT = 50;
|
|
5
6
|
|
|
7
|
+
/** Match the visible label plus optional search aliases such as exit/quit. */
|
|
6
8
|
export function filterCommands(commands, query) {
|
|
7
|
-
const normalize = (value) => String(value ?? "").trim().toLowerCase()
|
|
9
|
+
const normalize = (value) => String(value ?? "").trim().toLowerCase()
|
|
10
|
+
.replace(/^[/\\]+/, "").replace(/[-_]+/g, " ");
|
|
8
11
|
const needle = normalize(query);
|
|
9
12
|
if (!needle) return commands.slice();
|
|
10
|
-
return commands.filter((command) =>
|
|
13
|
+
return commands.filter((command) => {
|
|
14
|
+
const haystack = normalize([command.label, ...(command.keywords ?? [])].join(" "));
|
|
15
|
+
return haystack.includes(needle);
|
|
16
|
+
});
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
/** Commands shown when the palette query is empty. */
|
|
14
20
|
export function buildCommands({ rooms = [], current = null, joined = false, help = false } = {}) {
|
|
15
21
|
const commands = [
|
|
16
|
-
{ id: "refresh", label: "
|
|
17
|
-
{ id: "new-room", label: "
|
|
22
|
+
{ id: "refresh", label: t("command.refresh") },
|
|
23
|
+
{ id: "new-room", label: t("command.newRoom") },
|
|
18
24
|
];
|
|
19
25
|
for (const room of rooms) {
|
|
20
|
-
if (!room.joined) commands.push({ id: `join:${room.id}`, label:
|
|
26
|
+
if (!room.joined) commands.push({ id: `join:${room.id}`, label: t("command.join", { name: room.name }), roomId: room.id });
|
|
21
27
|
}
|
|
22
|
-
if (current && joined) commands.push({ id: "leave-room", label:
|
|
23
|
-
commands.push({ id: "toggle-help", label: help ? "
|
|
28
|
+
if (current && joined) commands.push({ id: "leave-room", label: t("command.leave", { name: current.name }) });
|
|
29
|
+
commands.push({ id: "toggle-help", label: help ? t("command.hideHelp") : t("command.showHelp") });
|
|
24
30
|
for (const room of rooms) {
|
|
25
|
-
if (room.joined) commands.push({ id: `switch:${room.id}`, label:
|
|
31
|
+
if (room.joined) commands.push({ id: `switch:${room.id}`, label: t("command.switch", { name: room.name }), roomId: room.id });
|
|
26
32
|
}
|
|
27
|
-
commands.push({ id: "search-room", label: "
|
|
28
|
-
commands.push({ id: "search-all", label: "
|
|
29
|
-
commands.push({ id: "members", label: "
|
|
30
|
-
commands.push({ id: "join-requests", label: "
|
|
31
|
-
commands.push({ id: "announcements", label: "
|
|
32
|
-
commands.push({ id: "questions", label: "
|
|
33
|
-
commands.push({ id: "files", label: "
|
|
34
|
-
commands.push({ id: "reminders", label: "
|
|
35
|
-
commands.push({ id: "settings", label: "
|
|
36
|
-
commands.push({ id: "room-settings", label: "
|
|
37
|
-
commands.push({ id: "delete-room", label: "
|
|
38
|
-
commands.push({ id: "recall-message", label: "
|
|
39
|
-
commands.push({ id: "reveal-message", label: "
|
|
40
|
-
commands.push({ id: "reply-message", label: "
|
|
41
|
-
commands.push({ id: "ask-question", label: "
|
|
42
|
-
commands.push({ id: "quit", label: "
|
|
33
|
+
commands.push({ id: "search-room", label: t("command.searchRoom") });
|
|
34
|
+
commands.push({ id: "search-all", label: t("command.searchAll") });
|
|
35
|
+
commands.push({ id: "members", label: t("command.members") });
|
|
36
|
+
commands.push({ id: "join-requests", label: t("command.joinRequests") });
|
|
37
|
+
commands.push({ id: "announcements", label: t("command.announcements") });
|
|
38
|
+
commands.push({ id: "questions", label: t("command.questions") });
|
|
39
|
+
commands.push({ id: "files", label: t("command.files") });
|
|
40
|
+
commands.push({ id: "reminders", label: t("command.reminders") });
|
|
41
|
+
commands.push({ id: "settings", label: t("command.settings") });
|
|
42
|
+
commands.push({ id: "room-settings", label: t("command.roomSettings") });
|
|
43
|
+
commands.push({ id: "delete-room", label: t("command.deleteRoom") });
|
|
44
|
+
commands.push({ id: "recall-message", label: t("command.recall") });
|
|
45
|
+
commands.push({ id: "reveal-message", label: t("command.reveal") });
|
|
46
|
+
commands.push({ id: "reply-message", label: t("command.reply") });
|
|
47
|
+
commands.push({ id: "ask-question", label: t("command.ask") });
|
|
48
|
+
commands.push({ id: "quit", label: t("command.quit"), keywords: ["exit", "quit", "q"] });
|
|
43
49
|
return commands;
|
|
44
50
|
}
|
|
45
51
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Persistent TUI preferences in $XDG_CONFIG_HOME/chatroom/tui.json. The file
|
|
2
|
+
// only stores language, theme, participant and url; a server token is never
|
|
3
|
+
// written or accepted from this layer.
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { loadTuiConfig } from "./config.mjs";
|
|
9
|
+
import { DEFAULT_LANGUAGE, normalizeLanguage } from "./i18n.mjs";
|
|
10
|
+
|
|
11
|
+
export const PREFS_FILE_NAME = "tui.json";
|
|
12
|
+
export const DEFAULT_THEME = "dark";
|
|
13
|
+
export const THEMES = ["dark", "light"];
|
|
14
|
+
const LANGUAGE_VALUES = ["en", "zh", "zh-cn", "zh_cn"];
|
|
15
|
+
|
|
16
|
+
export function normalizeTheme(value) {
|
|
17
|
+
return String(value ?? "").trim().toLowerCase() === "light" ? "light" : "dark";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function tuiPrefsFile(env = process.env) {
|
|
21
|
+
const home = env.HOME || os.homedir();
|
|
22
|
+
const configHome = env.XDG_CONFIG_HOME || path.join(home, ".config");
|
|
23
|
+
return path.join(configHome, "chatroom", PREFS_FILE_NAME);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Keep only known, valid fields; unknown or malformed values are dropped. */
|
|
27
|
+
function cleanPrefs(value) {
|
|
28
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
29
|
+
const prefs = {};
|
|
30
|
+
const language = typeof value.language === "string" ? value.language.trim().toLowerCase() : "";
|
|
31
|
+
if (LANGUAGE_VALUES.includes(language)) prefs.language = normalizeLanguage(language);
|
|
32
|
+
const theme = typeof value.theme === "string" ? value.theme.trim().toLowerCase() : "";
|
|
33
|
+
if (THEMES.includes(theme)) prefs.theme = theme;
|
|
34
|
+
if (typeof value.participant === "string" && value.participant.trim()) {
|
|
35
|
+
prefs.participant = value.participant.trim().slice(0, 64);
|
|
36
|
+
}
|
|
37
|
+
if (typeof value.url === "string" && /^https?:\/\/[^/]+/i.test(value.url.trim())) {
|
|
38
|
+
prefs.url = value.url.trim().replace(/\/+$/, "");
|
|
39
|
+
}
|
|
40
|
+
return prefs;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A missing or malformed file is not an error: it means "no preferences". */
|
|
44
|
+
export function loadTuiPrefs(env = process.env) {
|
|
45
|
+
try {
|
|
46
|
+
const data = JSON.parse(readFileSync(tuiPrefsFile(env), "utf8"));
|
|
47
|
+
return cleanPrefs(data);
|
|
48
|
+
} catch {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function saveTuiPrefs(env = process.env, patch = {}) {
|
|
54
|
+
const prefs = cleanPrefs({ ...loadTuiPrefs(env), ...cleanPrefs(patch) });
|
|
55
|
+
const file = tuiPrefsFile(env);
|
|
56
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
57
|
+
const temp = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
58
|
+
writeFileSync(temp, `${JSON.stringify(prefs, null, 2)}\n`, { mode: 0o600 });
|
|
59
|
+
renameSync(temp, file);
|
|
60
|
+
return prefs;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function envValue(env, key) {
|
|
64
|
+
const value = env[key];
|
|
65
|
+
return value === undefined || value === "" ? undefined : value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Resolve language and theme: flags > env > tui.json > project config > defaults. */
|
|
69
|
+
export function resolveTuiPreferences(env = process.env, cwd = process.cwd(), flags = {}, sources = {}) {
|
|
70
|
+
const prefs = sources.prefs ?? loadTuiPrefs(env);
|
|
71
|
+
const project = sources.project === undefined ? loadTuiConfig(env, cwd) : sources.project;
|
|
72
|
+
return {
|
|
73
|
+
language: normalizeLanguage(
|
|
74
|
+
flags.language
|
|
75
|
+
?? envValue(env, "CHAT_ROOM_TUI_LANGUAGE")
|
|
76
|
+
?? prefs.language
|
|
77
|
+
?? project?.client?.language
|
|
78
|
+
?? project?.language
|
|
79
|
+
?? DEFAULT_LANGUAGE,
|
|
80
|
+
),
|
|
81
|
+
theme: normalizeTheme(
|
|
82
|
+
flags.theme
|
|
83
|
+
?? envValue(env, "CHAT_ROOM_TUI_THEME")
|
|
84
|
+
?? prefs.theme
|
|
85
|
+
?? project?.client?.theme
|
|
86
|
+
?? project?.theme
|
|
87
|
+
?? DEFAULT_THEME,
|
|
88
|
+
),
|
|
89
|
+
prefs,
|
|
90
|
+
prefsFile: tuiPrefsFile(env),
|
|
91
|
+
};
|
|
92
|
+
}
|
package/src/tui/reminder-app.mjs
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
// info-content.mjs so errors can be tested without a renderer.
|
|
4
4
|
import { parseReminderSchedule, reminderRows } from "./info-content.mjs";
|
|
5
5
|
import { sanitizeText } from "./messages.mjs";
|
|
6
|
+
import { t } from "./i18n.mjs";
|
|
6
7
|
|
|
7
8
|
const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
|
|
8
|
-
|
|
9
|
+
const reminderHint = () => t("reminder.hint");
|
|
9
10
|
|
|
10
11
|
function promptScheduleLabel() {
|
|
11
|
-
return
|
|
12
|
+
return t("reminder.schedulePrompt");
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export function attachReminders(Class) {
|
|
15
16
|
Object.assign(Class.prototype, {
|
|
16
17
|
openReminders() {
|
|
17
|
-
return this.openInfo("reminders", "
|
|
18
|
+
return this.openInfo("reminders", t("reminder.title"), reminderHint(), async (room) =>
|
|
18
19
|
reminderRows(await this.api.reminders(room.id, this.sessionID)));
|
|
19
20
|
},
|
|
20
21
|
|
|
@@ -37,8 +38,8 @@ export function attachReminders(Class) {
|
|
|
37
38
|
if (!palette) return;
|
|
38
39
|
palette.mode = "prompt";
|
|
39
40
|
palette.error = "";
|
|
40
|
-
palette.prompt = { label: "
|
|
41
|
-
palette.hint = "
|
|
41
|
+
palette.prompt = { label: t("reminder.textPrompt"), value: "", action: "reminder-text", data: {} };
|
|
42
|
+
palette.hint = t("palette.enterNextHint");
|
|
42
43
|
this.touch();
|
|
43
44
|
},
|
|
44
45
|
|
|
@@ -49,12 +50,12 @@ export function attachReminders(Class) {
|
|
|
49
50
|
palette.mode = "prompt";
|
|
50
51
|
palette.error = "";
|
|
51
52
|
palette.prompt = {
|
|
52
|
-
label: "
|
|
53
|
+
label: t("reminder.textPrompt"),
|
|
53
54
|
value: reminder.text,
|
|
54
55
|
action: "reminder-edit-text",
|
|
55
56
|
data: { id: reminder.value },
|
|
56
57
|
};
|
|
57
|
-
palette.hint = "
|
|
58
|
+
palette.hint = t("palette.enterSaveHint");
|
|
58
59
|
this.touch();
|
|
59
60
|
},
|
|
60
61
|
|
|
@@ -68,7 +69,7 @@ export function attachReminders(Class) {
|
|
|
68
69
|
this.touch();
|
|
69
70
|
try {
|
|
70
71
|
await this.api.updateReminder(roomId, reminder.value, this.sessionID, { paused: !reminder.paused });
|
|
71
|
-
this.setStatus(
|
|
72
|
+
this.setStatus(t(reminder.paused ? "reminder.resumed" : "reminder.paused"), "success");
|
|
72
73
|
await this.openReminders();
|
|
73
74
|
} catch (error) {
|
|
74
75
|
if (this.state.palette === palette) {
|
|
@@ -87,11 +88,11 @@ export function attachReminders(Class) {
|
|
|
87
88
|
palette.error = "";
|
|
88
89
|
palette.previous = { mode: "info", hint: palette.hint };
|
|
89
90
|
palette.confirm = {
|
|
90
|
-
text:
|
|
91
|
+
text: t("reminder.deleteConfirm", { text: sanitizeText(reminder.text).slice(0, 50) }),
|
|
91
92
|
action: "reminder-delete",
|
|
92
93
|
data: { id: reminder.value },
|
|
93
94
|
};
|
|
94
|
-
palette.hint = "
|
|
95
|
+
palette.hint = t("palette.deleteHint");
|
|
95
96
|
this.touch();
|
|
96
97
|
},
|
|
97
98
|
|
|
@@ -100,14 +101,14 @@ export function attachReminders(Class) {
|
|
|
100
101
|
const roomId = this.reminderRoomId(palette);
|
|
101
102
|
if (!palette || palette.mode !== "prompt") return;
|
|
102
103
|
if (!roomId) {
|
|
103
|
-
palette.error = "
|
|
104
|
+
palette.error = t("info.joinFirst");
|
|
104
105
|
this.touch();
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
107
108
|
if (prompt.action === "reminder-text") {
|
|
108
109
|
const text = String(value ?? "").trim();
|
|
109
110
|
if (!text) {
|
|
110
|
-
palette.error = "reminder
|
|
111
|
+
palette.error = t("reminder.textRequired");
|
|
111
112
|
this.touch();
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
@@ -117,7 +118,7 @@ export function attachReminders(Class) {
|
|
|
117
118
|
action: "reminder-schedule",
|
|
118
119
|
data: { text },
|
|
119
120
|
};
|
|
120
|
-
palette.hint = "
|
|
121
|
+
palette.hint = t("reminder.scheduleHint");
|
|
121
122
|
palette.error = "";
|
|
122
123
|
this.touch();
|
|
123
124
|
return;
|
|
@@ -136,7 +137,7 @@ export function attachReminders(Class) {
|
|
|
136
137
|
this.touch();
|
|
137
138
|
try {
|
|
138
139
|
await this.api.createReminder(roomId, this.sessionID, prompt.data.text, schedule);
|
|
139
|
-
this.setStatus("reminder
|
|
140
|
+
this.setStatus(t("reminder.created"), "success");
|
|
140
141
|
await this.openReminders();
|
|
141
142
|
} catch (error) {
|
|
142
143
|
if (this.state.palette === palette) {
|
|
@@ -150,7 +151,7 @@ export function attachReminders(Class) {
|
|
|
150
151
|
if (prompt.action === "reminder-edit-text") {
|
|
151
152
|
const text = String(value ?? "").trim();
|
|
152
153
|
if (!text) {
|
|
153
|
-
palette.error = "reminder
|
|
154
|
+
palette.error = t("reminder.textRequired");
|
|
154
155
|
this.touch();
|
|
155
156
|
return;
|
|
156
157
|
}
|
|
@@ -159,7 +160,7 @@ export function attachReminders(Class) {
|
|
|
159
160
|
this.touch();
|
|
160
161
|
try {
|
|
161
162
|
await this.api.updateReminder(roomId, prompt.data.id, this.sessionID, { text });
|
|
162
|
-
this.setStatus("reminder
|
|
163
|
+
this.setStatus(t("reminder.updated"), "success");
|
|
163
164
|
await this.openReminders();
|
|
164
165
|
} catch (error) {
|
|
165
166
|
if (this.state.palette === palette) {
|
|
@@ -179,7 +180,7 @@ export function attachReminders(Class) {
|
|
|
179
180
|
this.touch();
|
|
180
181
|
try {
|
|
181
182
|
await this.api.deleteReminder(roomId, confirm.data.id, this.sessionID);
|
|
182
|
-
this.setStatus("reminder
|
|
183
|
+
this.setStatus(t("reminder.deleted"), "success");
|
|
183
184
|
await this.openReminders();
|
|
184
185
|
} catch (error) {
|
|
185
186
|
if (this.state.palette === palette) {
|