@alexsun-top/opencode-chat-room 0.8.4 → 0.8.6
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 +17 -3
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +20 -1
- package/dist/cli.js +3785 -1462
- package/package.json +19 -11
- package/packages/chat-room-channeld/README.md +16 -10
- package/packages/chat-room-channeld/src/delivery.ts +0 -4
- package/packages/chat-room-channeld/src/host.ts +48 -37
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/database.ts +141 -49
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +148 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +201 -0
- package/packages/chat-room-channeld/src/state-rows.ts +132 -0
- package/packages/chat-room-channeld/src/state.ts +129 -157
- package/plugin.ts +21 -5
- package/server/app.ts +9 -0
- package/server/assets/base.css +22 -2
- package/server/assets/chat/admin.js +17 -1
- package/server/assets/chat/announcements.js +79 -34
- package/server/assets/chat/attachments.js +3 -3
- package/server/assets/chat/clipboard.js +1 -1
- package/server/assets/chat/confirm-dialog.js +3 -0
- package/server/assets/chat/copy-action.js +1 -1
- package/server/assets/chat/create-room-dialog.js +7 -0
- package/server/assets/chat/diagram-viewer.js +4 -8
- package/server/assets/chat/doc-preview.js +71 -31
- package/server/assets/chat/editor.js +49 -10
- package/server/assets/chat/events.js +13 -6
- package/server/assets/chat/files.js +33 -27
- package/server/assets/chat/history-loader.js +31 -15
- package/server/assets/chat/integration-editor.js +27 -1
- package/server/assets/chat/integrations.js +108 -16
- package/server/assets/chat/join-requests.js +40 -2
- package/server/assets/chat/locales/de.js +5 -3
- package/server/assets/chat/locales/es.js +5 -3
- package/server/assets/chat/locales/fr.js +5 -3
- package/server/assets/chat/locales/it.js +5 -3
- package/server/assets/chat/locales/ja.js +5 -3
- package/server/assets/chat/locales/ko.js +5 -3
- package/server/assets/chat/markdown-footnotes.js +27 -15
- package/server/assets/chat/markdown.js +6 -12
- package/server/assets/chat/members.js +34 -22
- package/server/assets/chat/mentions.js +8 -5
- package/server/assets/chat/message-cache.js +9 -3
- package/server/assets/chat/message-polling.js +10 -4
- package/server/assets/chat/message-window.js +58 -1
- package/server/assets/chat/messages.js +90 -37
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/operator.js +624 -0
- package/server/assets/chat/palette.js +7 -10
- package/server/assets/chat/panels.js +42 -0
- package/server/assets/chat/questions.js +75 -58
- package/server/assets/chat/recall.js +14 -5
- package/server/assets/chat/receipts.js +63 -7
- package/server/assets/chat/refresh-timing.js +6 -0
- package/server/assets/chat/reminders.js +47 -13
- package/server/assets/chat/replies.js +39 -25
- package/server/assets/chat/resource-format.js +6 -3
- package/server/assets/chat/room-list.js +202 -3
- package/server/assets/chat/room-watcher.js +3 -1
- package/server/assets/chat/rooms.js +29 -7
- package/server/assets/chat/settings.js +37 -6
- package/server/assets/chat/shortcuts.js +3 -1
- package/server/assets/chat/side-pane.js +1 -1
- package/server/assets/chat/state.js +51 -18
- package/server/assets/chat/system-events.js +3 -2
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/tasks.js +37 -14
- package/server/assets/chat/window-controls.js +25 -15
- package/server/assets/code-highlight.css +0 -13
- package/server/assets/conversation.css +45 -5
- package/server/assets/doc-preview.css +9 -0
- package/server/assets/files.css +4 -0
- package/server/assets/monaco/integration-rules.js +1 -1
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/assets/responsive.css +12 -2
- package/server/assets/settings.css +3 -1
- package/server/assets/tasks.css +6 -1
- package/server/assets/window-controls.css +3 -1
- package/server/channels.ts +3 -2
- package/server/chat.html +7 -2
- package/server/inbox.ts +3 -1
- package/server/join-requests.ts +8 -1
- package/server/member-routes.ts +16 -2
- package/server/newrooms.ts +2 -13
- package/server/operator-auth.ts +21 -0
- package/server/operator-routes.ts +150 -0
- package/server/operator-state.ts +64 -0
- package/server/operator.css +139 -0
- package/server/room-owner.ts +17 -0
- package/server/routes/inbox.ts +15 -5
- package/server/routes/pages.ts +12 -2
- package/server/routes/room-actions.ts +4 -3
- package/server/sw.js +3 -1
- package/server/system.html +109 -0
- package/server/wake.ts +1 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/acp/client.ts +254 -0
- package/src/acp/protocol.ts +300 -0
- package/src/acp/watch.ts +498 -0
- package/src/agent/agent-receipts.ts +98 -8
- package/src/center/center-client.ts +6 -1
- package/src/center/center-inbox.ts +54 -7
- package/src/center/center-wake.ts +57 -3
- package/src/center/forward-client.ts +48 -0
- package/src/center/mentions.ts +16 -3
- package/src/center/notification-delay.ts +139 -0
- package/src/center/queue.ts +3 -0
- package/src/config/file-config.ts +25 -0
- package/src/mcp/server.ts +389 -0
- package/src/protocol/config.ts +7 -0
- package/src/runtime/plugin-notifications.ts +43 -9
- package/src/runtime/v2-plugin.ts +14 -3
- package/src/runtime/v2-receiver.ts +10 -2
- package/src/runtime/watch.ts +5 -1
- package/src/state/pg-database.ts +133 -49
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +148 -99
- package/src/state/pg-worker.mts +201 -0
- package/src/state/receiver-state.ts +47 -0
- package/src/state/sqlite-database.ts +6 -2
- package/src/state/sqlite-members.ts +48 -4
- package/src/state/sqlite-messages.ts +25 -12
- package/src/state/sqlite-schema.ts +4 -1
- package/src/state/sqlite-state.ts +1 -1
- package/src/state/store.ts +31 -11
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +473 -423
- package/src/tui/app.mts +543 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +275 -242
- package/src/tui/room-settings-app.mts +318 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
- package/src/web/integration-rules-editor.ts +25 -2
package/src/tui/main.mjs
CHANGED
|
@@ -4,240 +4,246 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { createApp } from "./app.mjs";
|
|
6
6
|
import { DEFAULT_LANGUAGE, getLanguage, normalizeLanguage, setLanguage, t } from "./i18n.mjs";
|
|
7
|
-
|
|
8
7
|
const NAME = "opencode-chat-room cli";
|
|
9
8
|
const FALLBACK_VERSION = "0.8.1";
|
|
10
9
|
const LANGUAGE_VALUES = ["en", "zh", "zh-cn", "zh_cn"];
|
|
11
|
-
|
|
12
10
|
export const HELP = t("cli.help");
|
|
13
|
-
|
|
14
11
|
export function helpText(language) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const previous = getLanguage();
|
|
13
|
+
setLanguage(language);
|
|
14
|
+
const text = t("cli.help");
|
|
15
|
+
setLanguage(previous);
|
|
16
|
+
return text;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
export function parseArgs(argv = []) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
19
|
+
const options = {
|
|
20
|
+
help: false,
|
|
21
|
+
version: false,
|
|
22
|
+
setup: false,
|
|
23
|
+
name: undefined,
|
|
24
|
+
language: undefined,
|
|
25
|
+
theme: undefined,
|
|
26
|
+
server: undefined,
|
|
27
|
+
};
|
|
28
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
29
|
+
const arg = argv[index];
|
|
30
|
+
if (arg === "--help" || arg === "-h")
|
|
31
|
+
options.help = true;
|
|
32
|
+
else if (arg === "--version" || arg === "-v")
|
|
33
|
+
options.version = true;
|
|
34
|
+
else if (arg === "--setup")
|
|
35
|
+
options.setup = true;
|
|
36
|
+
else if (arg.startsWith("--")) {
|
|
37
|
+
const split = arg.indexOf("=");
|
|
38
|
+
const key = split === -1 ? arg : arg.slice(0, split);
|
|
39
|
+
if (!["--name", "--language", "--theme", "--server"].includes(key)) {
|
|
40
|
+
return { error: `unknown option: ${arg}` };
|
|
41
|
+
}
|
|
42
|
+
let value = split === -1 ? argv[index + 1] : arg.slice(split + 1);
|
|
43
|
+
if (split === -1) {
|
|
44
|
+
if (!value || value.startsWith("-"))
|
|
45
|
+
return { error: `${key} requires a value` };
|
|
46
|
+
index += 1;
|
|
47
|
+
}
|
|
48
|
+
if (!value)
|
|
49
|
+
return { error: `${key} requires a value` };
|
|
50
|
+
if (key === "--language") {
|
|
51
|
+
if (!LANGUAGE_VALUES.includes(value.trim().toLowerCase())) {
|
|
52
|
+
return { error: "--language must be en or zh-CN" };
|
|
53
|
+
}
|
|
54
|
+
options.language = normalizeLanguage(value);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (key === "--theme") {
|
|
58
|
+
value = value.trim().toLowerCase();
|
|
59
|
+
if (value !== "dark" && value !== "light")
|
|
60
|
+
return { error: "--theme must be dark or light" };
|
|
61
|
+
options.theme = value;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (key === "--name")
|
|
65
|
+
options.name = value;
|
|
66
|
+
else
|
|
67
|
+
options.server = value;
|
|
52
68
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (value !== "dark" && value !== "light") return { error: "--theme must be dark or light" };
|
|
59
|
-
options.theme = value;
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
options[key.slice(2)] = value;
|
|
63
|
-
} else {
|
|
64
|
-
return { error: `unknown option: ${arg}` };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return options;
|
|
69
|
+
else {
|
|
70
|
+
return { error: `unknown option: ${arg}` };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return options;
|
|
68
74
|
}
|
|
69
|
-
|
|
70
75
|
function runtimeProblem() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (typeof globalThis.Deno !== "undefined" || (!bunSupported && !nodeSupported)) {
|
|
77
|
-
return "the terminal client requires Bun 1.3.14+ or Node.js 26.4+ with --experimental-ffi. Install Bun 1.3.14+ and retry, or use a supported Node.js version.";
|
|
78
|
-
}
|
|
79
|
-
return "";
|
|
76
|
+
const [bunMajor = 0, bunMinor = 0, bunPatch = 0] = (process.versions.bun ?? "").split(".").map(Number);
|
|
77
|
+
if (bunMajor > 1 || (bunMajor === 1 && (bunMinor > 3 || (bunMinor === 3 && bunPatch >= 14)))) {
|
|
78
|
+
return "";
|
|
79
|
+
}
|
|
80
|
+
return "the terminal client requires Bun 1.3.14+. Install Bun and run bunx --bun @alexsun-top/opencode-chat-room cli.";
|
|
80
81
|
}
|
|
81
|
-
|
|
82
82
|
function version() {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
try {
|
|
84
|
+
for (const candidate of ["../../package.json", "../package.json"]) {
|
|
85
|
+
try {
|
|
86
|
+
const data = JSON.parse(readFileSync(new URL(candidate, import.meta.url), "utf8"));
|
|
87
|
+
if (typeof data.version === "string")
|
|
88
|
+
return data.version;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Source runs from src/tui, bundled CLI runs from dist.
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return FALLBACK_VERSION;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return FALLBACK_VERSION;
|
|
98
|
+
}
|
|
96
99
|
}
|
|
97
|
-
|
|
98
100
|
function redact(text, token) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
if (!token)
|
|
102
|
+
return text;
|
|
103
|
+
return String(text).split(token).join("***");
|
|
101
104
|
}
|
|
102
|
-
|
|
103
105
|
function errorText(error) {
|
|
104
|
-
|
|
106
|
+
return error instanceof Error ? error.message : String(error ?? "unknown error");
|
|
105
107
|
}
|
|
106
|
-
|
|
107
108
|
async function helpLanguage(options) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
const explicit = options.language ?? process.env.CHAT_ROOM_TUI_LANGUAGE;
|
|
110
|
+
if (explicit)
|
|
111
|
+
return normalizeLanguage(explicit);
|
|
112
|
+
try {
|
|
113
|
+
const { loadTuiPrefs } = await import("./prefs.mjs");
|
|
114
|
+
return normalizeLanguage(loadTuiPrefs(process.env).language ?? DEFAULT_LANGUAGE);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return DEFAULT_LANGUAGE;
|
|
118
|
+
}
|
|
116
119
|
}
|
|
117
|
-
|
|
118
120
|
/** --setup always opens settings; a missing tui.json means first run. */
|
|
119
121
|
export function shouldOpenSetup(options = {}, prefsExists = true) {
|
|
120
|
-
|
|
122
|
+
return Boolean(options.setup) || !prefsExists;
|
|
121
123
|
}
|
|
122
|
-
|
|
123
124
|
export async function main(argv = process.argv.slice(2)) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
] = await Promise.all([
|
|
157
|
-
import("./config.mjs"),
|
|
158
|
-
import("./session.mjs"),
|
|
159
|
-
import("./http.mjs"),
|
|
160
|
-
import("./prefs.mjs"),
|
|
161
|
-
]);
|
|
162
|
-
const prefs = loadTuiPrefs(process.env);
|
|
163
|
-
const project = loadTuiConfig(process.env, process.cwd());
|
|
164
|
-
config = resolveTuiConfig(process.env, process.cwd(), { flags: options, prefs, project });
|
|
165
|
-
const preferences = resolveTuiPreferences(process.env, process.cwd(), options, { prefs, project });
|
|
166
|
-
setLanguage(preferences.language);
|
|
167
|
-
const requested = options.name?.trim();
|
|
168
|
-
const session = loadSession(config.stateFile, requested || config.participant);
|
|
169
|
-
const participant = requested || session.name || config.participant;
|
|
170
|
-
if (session.name !== participant) {
|
|
171
|
-
try {
|
|
172
|
-
saveSession(config.stateFile, { ...session, name: participant });
|
|
173
|
-
} catch {
|
|
174
|
-
// A read-only state file only costs a new identity next time.
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
const api = createApi({ url: config.url, token: config.token, requestTimeoutMs: config.requestTimeoutMs });
|
|
178
|
-
let host = config.url;
|
|
125
|
+
const options = parseArgs(argv);
|
|
126
|
+
if ("error" in options) {
|
|
127
|
+
process.stderr.write(`${NAME}: ${options.error}\n`);
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
if (options.help) {
|
|
131
|
+
process.stdout.write(helpText(await helpLanguage(options)));
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
if (options.version) {
|
|
135
|
+
process.stdout.write(`${NAME} ${version()}\n`);
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
const unsupported = runtimeProblem();
|
|
139
|
+
if (unsupported) {
|
|
140
|
+
process.stderr.write(`${NAME}: ${unsupported}\n`);
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
144
|
+
process.stderr.write(`${NAME}: requires an interactive terminal. Use --help for usage.\n`);
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
import.meta.resolve("@opentui/core");
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
process.stderr.write(`${NAME}: OpenTUI is not installed. Run bunx --bun @alexsun-top/opencode-chat-room cli.\n`);
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
let config;
|
|
155
|
+
let renderer;
|
|
156
|
+
let ui;
|
|
179
157
|
try {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
158
|
+
const [{ resolveTuiConfig, findTuiConfigFile, loadTuiConfig }, { loadSession, saveSession }, { createApi }, { loadTuiPrefs, saveTuiPrefs, resolveTuiPreferences, tuiPrefsFile },] = await Promise.all([
|
|
159
|
+
import("./config.mjs"),
|
|
160
|
+
import("./session.mjs"),
|
|
161
|
+
import("./http.mjs"),
|
|
162
|
+
import("./prefs.mjs"),
|
|
163
|
+
]);
|
|
164
|
+
const prefs = loadTuiPrefs(process.env);
|
|
165
|
+
const project = loadTuiConfig(process.env, process.cwd());
|
|
166
|
+
config = resolveTuiConfig(process.env, process.cwd(), { flags: options, prefs, project });
|
|
167
|
+
const preferences = resolveTuiPreferences(process.env, process.cwd(), options, { prefs, project });
|
|
168
|
+
setLanguage(preferences.language);
|
|
169
|
+
const requested = options.name?.trim();
|
|
170
|
+
const session = loadSession(config.stateFile, requested || config.participant);
|
|
171
|
+
const participant = requested || session.name || config.participant;
|
|
172
|
+
if (session.name !== participant) {
|
|
173
|
+
try {
|
|
174
|
+
saveSession(config.stateFile, { ...session, name: participant });
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
// A read-only state file only costs a new identity next time.
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const api = createApi({ url: config.url, token: config.token, requestTimeoutMs: config.requestTimeoutMs });
|
|
181
|
+
let host = config.url;
|
|
182
|
+
try {
|
|
183
|
+
host = new URL(config.url).host;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// Keep the raw URL when it is not parseable.
|
|
187
|
+
}
|
|
188
|
+
const [{ createCliRenderer }, { createTui }] = await Promise.all([
|
|
189
|
+
import("@opentui/core"),
|
|
190
|
+
import("./ui.mjs"),
|
|
191
|
+
]);
|
|
192
|
+
renderer = await createCliRenderer({
|
|
193
|
+
screenMode: "alternate-screen",
|
|
194
|
+
exitOnCtrlC: false,
|
|
195
|
+
useMouse: true,
|
|
196
|
+
targetFps: 30,
|
|
197
|
+
clearOnShutdown: true,
|
|
198
|
+
});
|
|
199
|
+
const app = createApp({
|
|
200
|
+
api,
|
|
201
|
+
sessionID: session.sessionID,
|
|
202
|
+
participant,
|
|
203
|
+
host,
|
|
204
|
+
settings: {
|
|
205
|
+
server: config.url,
|
|
206
|
+
participant,
|
|
207
|
+
sessionFile: config.stateFile,
|
|
208
|
+
configFile: findTuiConfigFile(process.env, process.cwd()) ?? "",
|
|
209
|
+
prefsFile: tuiPrefsFile(process.env),
|
|
210
|
+
language: preferences.language,
|
|
211
|
+
theme: preferences.theme,
|
|
212
|
+
requestTimeoutMs: config.requestTimeoutMs,
|
|
213
|
+
pollTimeoutMs: 20000,
|
|
214
|
+
token: config.token,
|
|
215
|
+
},
|
|
216
|
+
savePrefs: (next) => saveTuiPrefs(process.env, next),
|
|
217
|
+
downloadDir: path.join(process.cwd(), "downloads"),
|
|
218
|
+
});
|
|
219
|
+
ui = createTui(renderer, app);
|
|
220
|
+
await app.init();
|
|
221
|
+
ui.sync();
|
|
222
|
+
// Settings need a working server to boot, so first run and --setup open
|
|
223
|
+
// here, right after the room list loads. Without a configured server the
|
|
224
|
+
// config error above still exits before the terminal is touched.
|
|
225
|
+
if (shouldOpenSetup(options, existsSync(preferences.prefsFile)))
|
|
226
|
+
app.openSettingsEditor();
|
|
227
|
+
return await new Promise((resolve) => {
|
|
228
|
+
const finish = () => resolve(0);
|
|
229
|
+
if (app.state.quit) {
|
|
230
|
+
finish();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const unsubscribe = app.subscribe(() => {
|
|
234
|
+
if (!app.state.quit)
|
|
235
|
+
return;
|
|
236
|
+
unsubscribe();
|
|
237
|
+
finish();
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
process.stderr.write(`${NAME}: ${redact(errorText(error), config?.token)}\n`);
|
|
243
|
+
return 1;
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
ui?.destroy();
|
|
247
|
+
renderer?.destroy();
|
|
248
|
+
}
|
|
249
|
+
}
|