@alexsun-top/opencode-chat-room 0.8.4 → 0.8.5
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 +5 -1
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/cli.ts +1 -1
- package/dist/cli.js +35 -16
- package/package.json +14 -11
- package/packages/chat-room-channeld/README.md +3 -2
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- 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 +107 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
- package/plugin.ts +1 -1
- package/server/assets/chat/admin.js +4 -1
- package/server/assets/chat/announcements.js +3 -0
- package/server/assets/chat/attachments.js +3 -3
- package/server/assets/chat/clipboard.js +1 -1
- package/server/assets/chat/copy-action.js +1 -1
- package/server/assets/chat/doc-preview.js +1 -1
- package/server/assets/chat/editor.js +11 -7
- package/server/assets/chat/events.js +7 -5
- package/server/assets/chat/files.js +5 -1
- package/server/assets/chat/integration-editor.js +2 -0
- package/server/assets/chat/integrations.js +1 -1
- package/server/assets/chat/join-requests.js +1 -1
- package/server/assets/chat/markdown-footnotes.js +8 -7
- package/server/assets/chat/markdown.js +6 -5
- package/server/assets/chat/members.js +3 -3
- package/server/assets/chat/mentions.js +8 -5
- package/server/assets/chat/message-cache.js +1 -1
- package/server/assets/chat/message-polling.js +2 -2
- package/server/assets/chat/message-window.js +1 -1
- package/server/assets/chat/messages.js +17 -3
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/palette.js +5 -3
- package/server/assets/chat/panels.js +19 -0
- package/server/assets/chat/questions.js +3 -2
- package/server/assets/chat/reminders.js +3 -0
- package/server/assets/chat/replies.js +6 -3
- package/server/assets/chat/resource-format.js +2 -2
- package/server/assets/chat/rooms.js +7 -4
- package/server/assets/chat/settings.js +4 -3
- package/server/assets/chat/shortcuts.js +3 -1
- package/server/assets/chat/side-pane.js +1 -1
- package/server/assets/chat/state.js +30 -11
- package/server/assets/chat/system-events.js +3 -2
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/tasks.js +4 -3
- package/server/assets/chat/window-controls.js +3 -2
- package/server/assets/conversation.css +14 -2
- package/server/assets/doc-preview.css +6 -0
- 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/sw.js +3 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/agent/agent-receipts.ts +12 -4
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +107 -99
- package/src/state/pg-worker.mts +166 -0
- package/src/state/store.ts +21 -7
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +426 -423
- package/src/tui/app.mts +500 -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 +257 -242
- package/src/tui/room-settings-app.mts +301 -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
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
// Pure formatting for the CLI parity commands. No terminal or network code, so
|
|
2
|
+
// the row text and the settings redaction can be checked directly in tests.
|
|
3
|
+
import { sanitizeText } from "./messages.mjs";
|
|
4
|
+
import type { ChatMessage } from "./messages.mjs";
|
|
5
|
+
import { t } from "./i18n.mjs";
|
|
6
|
+
import type {
|
|
7
|
+
Announcement,
|
|
8
|
+
JoinRequest,
|
|
9
|
+
Member,
|
|
10
|
+
Question,
|
|
11
|
+
Reminder,
|
|
12
|
+
ReminderScheduleInput,
|
|
13
|
+
Resource,
|
|
14
|
+
} from "./wire.mjs";
|
|
15
|
+
|
|
16
|
+
export type {
|
|
17
|
+
Announcement,
|
|
18
|
+
JoinRequest,
|
|
19
|
+
Member,
|
|
20
|
+
Question,
|
|
21
|
+
Reminder,
|
|
22
|
+
ReminderScheduleInput,
|
|
23
|
+
Resource,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface MemberRow {
|
|
27
|
+
name: string;
|
|
28
|
+
value: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AnnouncementRow {
|
|
32
|
+
name: string;
|
|
33
|
+
value: string;
|
|
34
|
+
content: string;
|
|
35
|
+
updatedAt?: unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface QuestionRow {
|
|
39
|
+
name: string;
|
|
40
|
+
value: string;
|
|
41
|
+
text?: string;
|
|
42
|
+
open: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface FileRow {
|
|
46
|
+
name: string;
|
|
47
|
+
value: string;
|
|
48
|
+
resource: Resource;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface JoinRequestRow {
|
|
52
|
+
name: string;
|
|
53
|
+
value: string;
|
|
54
|
+
request: JoinRequest;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ReminderRow {
|
|
58
|
+
name: string;
|
|
59
|
+
value: string;
|
|
60
|
+
paused: boolean;
|
|
61
|
+
text: string;
|
|
62
|
+
schedule?: ReminderScheduleInput;
|
|
63
|
+
nextRunAt?: unknown;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface SettingsInput {
|
|
67
|
+
token?: unknown;
|
|
68
|
+
server?: unknown;
|
|
69
|
+
participant?: unknown;
|
|
70
|
+
language?: unknown;
|
|
71
|
+
sessionFile?: unknown;
|
|
72
|
+
configFile?: unknown;
|
|
73
|
+
theme?: unknown;
|
|
74
|
+
pollTimeoutMs?: number;
|
|
75
|
+
requestTimeoutMs?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const oneLine = (value: unknown, max = 100): string => {
|
|
79
|
+
const text = sanitizeText(value).replace(/\s+/g, " ").trim();
|
|
80
|
+
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
function timeLabel(value: unknown): string {
|
|
84
|
+
const ms = typeof value === "number" ? value : Date.parse(String(value ?? ""));
|
|
85
|
+
if (!Number.isFinite(ms)) return t("time.unknown");
|
|
86
|
+
const date = new Date(ms);
|
|
87
|
+
const pad = (part: number) => String(part).padStart(2, "0");
|
|
88
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function formatBytes(size: unknown): string {
|
|
92
|
+
const bytes = Number(size);
|
|
93
|
+
if (!Number.isFinite(bytes) || bytes < 0) return "?";
|
|
94
|
+
if (bytes < 1024) return `${Math.round(bytes)} B`;
|
|
95
|
+
const units = ["KB", "MB", "GB", "TB"];
|
|
96
|
+
let value = bytes / 1024;
|
|
97
|
+
let unit = 0;
|
|
98
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
99
|
+
value /= 1024;
|
|
100
|
+
unit += 1;
|
|
101
|
+
}
|
|
102
|
+
return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function memberRows(members: readonly Member[], selfID?: string | null): MemberRow[] {
|
|
106
|
+
const list: readonly Member[] = Array.isArray(members) ? members : [];
|
|
107
|
+
return list.map((member) => {
|
|
108
|
+
const self = Boolean(selfID) && member.sessionID === selfID;
|
|
109
|
+
const name = sanitizeText(member.name || member.sessionID || "?");
|
|
110
|
+
const type = member.type === "agent" ? t("member.typeAgent") : t("member.typeHuman");
|
|
111
|
+
const activity = sanitizeText(member.activity?.state || t("member.activityUnknown"));
|
|
112
|
+
return {
|
|
113
|
+
name: t("member.row", {
|
|
114
|
+
marker: self ? "●" : "○",
|
|
115
|
+
name: self ? t("member.self", { name }) : name,
|
|
116
|
+
type,
|
|
117
|
+
activity,
|
|
118
|
+
}),
|
|
119
|
+
value: String(member.sessionID ?? name),
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function announcementRows(announcements: readonly Announcement[]): AnnouncementRow[] {
|
|
125
|
+
const list: readonly Announcement[] = Array.isArray(announcements) ? announcements : [];
|
|
126
|
+
return list.map((item) => ({
|
|
127
|
+
name: t("announcement.row", { name: sanitizeText(item.name), time: timeLabel(item.updatedAt) }),
|
|
128
|
+
value: String(item.name),
|
|
129
|
+
content: String(item.content ?? ""),
|
|
130
|
+
updatedAt: item.updatedAt,
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function questionRows(open: readonly Question[], messages: readonly ChatMessage[] = []): QuestionRow[] {
|
|
135
|
+
const rows: QuestionRow[] = [];
|
|
136
|
+
const seen = new Set<unknown>();
|
|
137
|
+
const rowOf = (marker: string, sender: unknown, text: unknown, answered: boolean) => t("question.row", {
|
|
138
|
+
marker,
|
|
139
|
+
sender: sanitizeText(sender || "?"),
|
|
140
|
+
text: oneLine(text),
|
|
141
|
+
answered: answered ? t("question.answered") : "",
|
|
142
|
+
});
|
|
143
|
+
const openList: readonly Question[] = Array.isArray(open) ? open : [];
|
|
144
|
+
for (const question of openList) {
|
|
145
|
+
seen.add(question.id);
|
|
146
|
+
const answered = Boolean(question.answeredByMessageID);
|
|
147
|
+
rows.push({
|
|
148
|
+
name: rowOf(answered ? "✓" : "?", question.senderId, question.text, answered),
|
|
149
|
+
value: String(question.id),
|
|
150
|
+
text: String(question.text ?? ""),
|
|
151
|
+
open: !answered,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
const messageList: readonly ChatMessage[] = Array.isArray(messages) ? messages : [];
|
|
155
|
+
for (const message of messageList) {
|
|
156
|
+
if (!message?.isQuestion || !message.answeredByMessageID || seen.has(message.id)) continue;
|
|
157
|
+
seen.add(message.id);
|
|
158
|
+
rows.push({
|
|
159
|
+
name: rowOf("✓", message.senderId, message.text, true),
|
|
160
|
+
value: String(message.id),
|
|
161
|
+
open: false,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return rows;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function fileRows(resources: readonly Resource[]): FileRow[] {
|
|
168
|
+
const list: readonly Resource[] = Array.isArray(resources) ? resources : [];
|
|
169
|
+
return list.map((item) => ({
|
|
170
|
+
name: t("file.row", {
|
|
171
|
+
name: sanitizeText(item.name),
|
|
172
|
+
size: formatBytes(item.size),
|
|
173
|
+
uploader: sanitizeText(item.uploaderName || item.uploaderSessionID || t("file.uploaderUnknown")),
|
|
174
|
+
time: timeLabel(item.createdAt),
|
|
175
|
+
}),
|
|
176
|
+
value: String(item.id),
|
|
177
|
+
resource: item,
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function joinRequestRows(requests: readonly JoinRequest[]): JoinRequestRow[] {
|
|
182
|
+
const list: readonly JoinRequest[] = Array.isArray(requests) ? requests : [];
|
|
183
|
+
return list.map((item) => ({
|
|
184
|
+
name: t("join.row", {
|
|
185
|
+
name: sanitizeText(item.name || item.participantId || "?"),
|
|
186
|
+
type: item.isAgent ? t("common.agent") : t("common.human"),
|
|
187
|
+
time: timeLabel(item.createdAt),
|
|
188
|
+
}),
|
|
189
|
+
value: String(item.sessionID),
|
|
190
|
+
request: item,
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function reminderRows(reminders: readonly Reminder[]): ReminderRow[] {
|
|
195
|
+
const list: readonly Reminder[] = Array.isArray(reminders) ? reminders : [];
|
|
196
|
+
return list.map((item) => {
|
|
197
|
+
const schedule = item.schedule?.type === "cron"
|
|
198
|
+
? t("reminder.cron", {
|
|
199
|
+
expression: sanitizeText(item.schedule.expression),
|
|
200
|
+
timezone: sanitizeText(item.schedule.timezone || t("common.server")),
|
|
201
|
+
})
|
|
202
|
+
: t("reminder.once", { time: timeLabel(Date.parse(item.schedule?.at ?? "")) });
|
|
203
|
+
const next = typeof item.nextRunAt === "string" ? timeLabel(Date.parse(item.nextRunAt)) : timeLabel(item.nextRunAt);
|
|
204
|
+
return {
|
|
205
|
+
name: t("reminder.row", {
|
|
206
|
+
marker: item.paused ? "⏸" : "●",
|
|
207
|
+
text: oneLine(item.text),
|
|
208
|
+
schedule,
|
|
209
|
+
time: next,
|
|
210
|
+
}),
|
|
211
|
+
value: String(item.id),
|
|
212
|
+
paused: Boolean(item.paused),
|
|
213
|
+
text: String(item.text ?? ""),
|
|
214
|
+
schedule: item.schedule,
|
|
215
|
+
nextRunAt: item.nextRunAt,
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export type ParsedReminderSchedule =
|
|
221
|
+
| { type: "cron"; expression: string; timezone?: string }
|
|
222
|
+
| { type: "once"; at: string; timezone?: string };
|
|
223
|
+
|
|
224
|
+
function timezoneOrThrow(value: string): string {
|
|
225
|
+
try {
|
|
226
|
+
new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
227
|
+
return value;
|
|
228
|
+
} catch {
|
|
229
|
+
throw new Error(t("schedule.timezone", { value }));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Parse "once <ISO datetime> [timezone]" or "cron <5 fields> [timezone]". */
|
|
234
|
+
export function parseReminderSchedule(input: unknown): ParsedReminderSchedule {
|
|
235
|
+
const parts = String(input ?? "").trim().split(/\s+/);
|
|
236
|
+
const kind = parts.shift()?.toLowerCase();
|
|
237
|
+
if (kind === "cron") {
|
|
238
|
+
if (parts.length < 5) throw new Error(t("schedule.cronFields"));
|
|
239
|
+
if (parts.length > 6) throw new Error(t("schedule.cronAccept"));
|
|
240
|
+
const expression = parts.slice(0, 5).join(" ");
|
|
241
|
+
const tzField = parts[5];
|
|
242
|
+
const timezone = tzField ? timezoneOrThrow(tzField) : undefined;
|
|
243
|
+
return timezone ? { type: "cron", expression, timezone } : { type: "cron", expression };
|
|
244
|
+
}
|
|
245
|
+
if (kind === "once") {
|
|
246
|
+
if (!parts.length) throw new Error(t("schedule.onceNeeds"));
|
|
247
|
+
if (parts.length > 2) throw new Error(t("schedule.onceAccept"));
|
|
248
|
+
const at = parts[0] ?? "";
|
|
249
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(at) || !Number.isFinite(Date.parse(at))) {
|
|
250
|
+
throw new Error(t("schedule.onceInvalid"));
|
|
251
|
+
}
|
|
252
|
+
const tzField = parts[1];
|
|
253
|
+
const timezone = tzField ? timezoneOrThrow(tzField) : undefined;
|
|
254
|
+
if (Date.parse(at) <= Date.now()) throw new Error(t("schedule.onceFuture"));
|
|
255
|
+
return timezone ? { type: "once", at, timezone } : { type: "once", at };
|
|
256
|
+
}
|
|
257
|
+
throw new Error(t("schedule.start"));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function safeValue(value: unknown, token: string): string {
|
|
261
|
+
let text = String(value ?? "");
|
|
262
|
+
try {
|
|
263
|
+
const parsed = new URL(text);
|
|
264
|
+
if (parsed.username || parsed.password) {
|
|
265
|
+
parsed.username = "";
|
|
266
|
+
parsed.password = "";
|
|
267
|
+
text = parsed.toString().replace(/\/$/, "");
|
|
268
|
+
}
|
|
269
|
+
} catch {
|
|
270
|
+
// Not a URL: keep the string.
|
|
271
|
+
}
|
|
272
|
+
return token ? text.split(token).join("***") : text;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function settingsMarkdown(settings: SettingsInput = {}): string {
|
|
276
|
+
const token = settings.token ? String(settings.token) : "";
|
|
277
|
+
const lines = [
|
|
278
|
+
`- **${t("settings.labelServer")}**: ${safeValue(settings.server || t("common.notSet"), token)}`,
|
|
279
|
+
`- **${t("settings.labelParticipant")}**: ${safeValue(settings.participant || "?", token)}`,
|
|
280
|
+
`- **${t("settings.labelLanguage")}**: ${safeValue(settings.language || "en", token)}`,
|
|
281
|
+
`- **${t("settings.labelSessionFile")}**: ${safeValue(settings.sessionFile || t("common.unknown"), token)}`,
|
|
282
|
+
`- **${t("settings.labelConfigFile")}**: ${safeValue(settings.configFile || t("settings.environmentOnly"), token)}`,
|
|
283
|
+
`- **${t("settings.labelTheme")}**: ${safeValue(settings.theme || "dark", token)}`,
|
|
284
|
+
`- **${t("settings.labelDelivery")}**: ${t("settings.deliveryValue", { seconds: Math.round((settings.pollTimeoutMs ?? 20000) / 1000) })}`,
|
|
285
|
+
`- **${t("settings.labelRequestTimeout")}**: ${t("settings.requestTimeoutValue", { seconds: Math.round((settings.requestTimeoutMs ?? 10000) / 1000) })}`,
|
|
286
|
+
`- **${t("settings.labelToken")}**: ${token ? t("settings.tokenSet") : t("common.notSet")}`,
|
|
287
|
+
`- **${t("room.labelEditing")}**: ${t("settings.editAvailable")}`,
|
|
288
|
+
];
|
|
289
|
+
return lines.join("\n");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export interface RoomSettings {
|
|
293
|
+
name?: string;
|
|
294
|
+
description?: string;
|
|
295
|
+
ownerId?: string;
|
|
296
|
+
adminIds?: readonly string[];
|
|
297
|
+
adminSessionID?: string;
|
|
298
|
+
successorId?: string;
|
|
299
|
+
joinPolicy?: string;
|
|
300
|
+
kind?: string;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface RoomSettingsOptions {
|
|
304
|
+
participant?: string;
|
|
305
|
+
sessionID?: string;
|
|
306
|
+
canEdit?: boolean;
|
|
307
|
+
agentName?: string;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function roomSettingsMarkdown(room: RoomSettings = {}, {
|
|
311
|
+
participant,
|
|
312
|
+
sessionID,
|
|
313
|
+
canEdit = false,
|
|
314
|
+
agentName = "",
|
|
315
|
+
}: RoomSettingsOptions = {}): string {
|
|
316
|
+
const owner = Boolean(participant) && room.ownerId === participant;
|
|
317
|
+
const admin = owner || (participant !== undefined && (room.adminIds ?? []).includes(participant));
|
|
318
|
+
const agentAdmin = Boolean(room.adminSessionID) && room.adminSessionID === sessionID;
|
|
319
|
+
const role = owner ? t("room.roleOwner")
|
|
320
|
+
: admin ? t("room.roleAdmin")
|
|
321
|
+
: agentAdmin ? t("room.roleManagement")
|
|
322
|
+
: t("room.roleMember");
|
|
323
|
+
const policy = room.joinPolicy === "approval" ? t("room.policyApproval") : t("room.policyOpen");
|
|
324
|
+
const description = room.description ? oneLine(room.description, 300) : t("common.notSet");
|
|
325
|
+
const admins = (room.adminIds ?? []).filter(Boolean).join(", ") || t("common.none");
|
|
326
|
+
const successor = room.successorId || t("common.none");
|
|
327
|
+
const management = room.adminSessionID ? (agentName || room.adminSessionID) : t("common.none");
|
|
328
|
+
const label = (key: string) => `- **${t(key)}**`;
|
|
329
|
+
return [
|
|
330
|
+
`${label("room.labelName")}: ${oneLine(room.name || "?", 80)}`,
|
|
331
|
+
`${label("room.labelDescription")}: ${description}`,
|
|
332
|
+
`${label("room.labelJoinPolicy")}: ${policy}`,
|
|
333
|
+
`${label("room.labelKind")}: ${room.kind === "direct" ? t("room.kindDirect") : t("room.kindGroup")}`,
|
|
334
|
+
`${label("room.labelOwner")}: ${oneLine(room.ownerId || "?", 80)}`,
|
|
335
|
+
`${label("room.labelAdmins")}: ${admins}`,
|
|
336
|
+
`${label("room.labelSuccessor")}: ${successor}`,
|
|
337
|
+
`${label("room.labelManagement")}: ${management}`,
|
|
338
|
+
`${label("room.labelRole")}: ${role}`,
|
|
339
|
+
`${label("room.labelEditing")}: ${canEdit ? t("room.editingAvailable") : t("room.editingReadOnly")}`,
|
|
340
|
+
].join("\n");
|
|
341
|
+
}
|
package/src/tui/join-app.mjs
CHANGED
|
@@ -2,70 +2,81 @@
|
|
|
2
2
|
// overlay and maps 403s to the server's reviewer rule in plain language.
|
|
3
3
|
import { joinRequestRows } from "./info-content.mjs";
|
|
4
4
|
import { t } from "./i18n.mjs";
|
|
5
|
-
|
|
6
5
|
const reviewHint = () => t("join.reviewHint");
|
|
7
6
|
const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
|
|
8
|
-
|
|
7
|
+
// Attached APIs and errors may carry a status property on a plain object too.
|
|
8
|
+
const statusOf = (error) => {
|
|
9
|
+
if (typeof error === "object" && error !== null && "status" in error && typeof error.status === "number") {
|
|
10
|
+
return error.status;
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
};
|
|
9
14
|
export function attachJoinRequests(Class) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
15
|
+
Object.assign(Class.prototype, {
|
|
16
|
+
openJoinRequests() {
|
|
17
|
+
return this.openInfo("join-requests", t("join.title"), reviewHint(), async (room) => {
|
|
18
|
+
try {
|
|
19
|
+
const result = await this.api.joinRequests(room.id, this.sessionID);
|
|
20
|
+
return joinRequestRows(result.requests);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (statusOf(error) === 403)
|
|
24
|
+
throw new Error(t("join.adminError"));
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
selectedJoinRequest() {
|
|
30
|
+
const palette = this.state.palette;
|
|
31
|
+
if (!palette || palette.mode !== "info" || palette.kind !== "join-requests")
|
|
32
|
+
return null;
|
|
33
|
+
return this.paletteItems()[palette.selected] ?? null;
|
|
34
|
+
},
|
|
35
|
+
askJoinDecision(decision) {
|
|
36
|
+
const palette = this.state.palette;
|
|
37
|
+
const request = this.selectedJoinRequest();
|
|
38
|
+
if (!palette || !request)
|
|
39
|
+
return;
|
|
40
|
+
const name = request.request?.name || request.request?.participantId || request.value;
|
|
41
|
+
palette.mode = "confirm";
|
|
42
|
+
palette.previous = { mode: "info", hint: palette.hint };
|
|
43
|
+
palette.confirm = {
|
|
44
|
+
text: decision === "approve" ? t("join.approve", { name }) : t("join.deny", { name }),
|
|
45
|
+
action: `join-${decision}`,
|
|
46
|
+
data: { sessionID: request.value, name },
|
|
47
|
+
};
|
|
48
|
+
palette.error = "";
|
|
49
|
+
palette.hint = t("palette.confirmHint");
|
|
50
|
+
this.touch();
|
|
51
|
+
},
|
|
52
|
+
async runJoinConfirm(confirm) {
|
|
53
|
+
const palette = this.state.palette;
|
|
54
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
55
|
+
if (!palette || !roomId)
|
|
56
|
+
return;
|
|
57
|
+
const requestSessionID = confirm.data.sessionID;
|
|
58
|
+
if (!requestSessionID)
|
|
59
|
+
return;
|
|
60
|
+
const decision = confirm.action === "join-approve" ? "approve" : "deny";
|
|
61
|
+
palette.searching = true;
|
|
62
|
+
palette.error = "";
|
|
63
|
+
this.touch();
|
|
64
|
+
try {
|
|
65
|
+
await this.api.decideJoin(roomId, requestSessionID, this.sessionID, decision);
|
|
66
|
+
this.setStatus(t(decision === "approve" ? "join.approved" : "join.denied", { name: confirm.data.name }), "success");
|
|
67
|
+
await this.openJoinRequests();
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (this.state.palette === palette) {
|
|
71
|
+
palette.mode = "info";
|
|
72
|
+
palette.confirm = null;
|
|
73
|
+
palette.previous = null;
|
|
74
|
+
palette.searching = false;
|
|
75
|
+
palette.hint = reviewHint();
|
|
76
|
+
palette.error = statusOf(error) === 403 ? t("join.adminError") : errorText(error);
|
|
77
|
+
this.touch();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Pending join-request review for the current room. Reuses the info/confirm
|
|
2
|
+
// overlay and maps 403s to the server's reviewer rule in plain language.
|
|
3
|
+
import { joinRequestRows } from "./info-content.mjs";
|
|
4
|
+
import { t } from "./i18n.mjs";
|
|
5
|
+
import type { ChatApp } from "./app.mjs";
|
|
6
|
+
import type { PaletteConfirm, PaletteItem } from "./app-types.mjs";
|
|
7
|
+
|
|
8
|
+
const reviewHint = (): string => t("join.reviewHint");
|
|
9
|
+
const errorText = (error: unknown): string => (error instanceof Error ? error.message : String(error ?? "unknown error"));
|
|
10
|
+
|
|
11
|
+
// Attached APIs and errors may carry a status property on a plain object too.
|
|
12
|
+
const statusOf = (error: unknown): number | undefined => {
|
|
13
|
+
if (typeof error === "object" && error !== null && "status" in error && typeof error.status === "number") {
|
|
14
|
+
return error.status;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Palette methods owned by the still-JS palette attach module.
|
|
20
|
+
interface JoinApp extends ChatApp {
|
|
21
|
+
paletteItems(): PaletteItem[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// The methods this module attaches become visible on ChatApp for app.mts and
|
|
25
|
+
// the later attach migrations.
|
|
26
|
+
declare module "./app.mjs" {
|
|
27
|
+
interface ChatApp {
|
|
28
|
+
openJoinRequests(): Promise<void>;
|
|
29
|
+
selectedJoinRequest(): PaletteItem | null;
|
|
30
|
+
askJoinDecision(decision: "approve" | "deny"): void;
|
|
31
|
+
runJoinConfirm(confirm: PaletteConfirm): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function attachJoinRequests(Class: { prototype: ChatApp }) {
|
|
36
|
+
Object.assign(Class.prototype, {
|
|
37
|
+
openJoinRequests(this: JoinApp): Promise<void> {
|
|
38
|
+
return this.openInfo("join-requests", t("join.title"), reviewHint(), async (room) => {
|
|
39
|
+
try {
|
|
40
|
+
const result = await this.api.joinRequests(room.id, this.sessionID);
|
|
41
|
+
return joinRequestRows(result.requests);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (statusOf(error) === 403) throw new Error(t("join.adminError"));
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
selectedJoinRequest(this: JoinApp): PaletteItem | null {
|
|
50
|
+
const palette = this.state.palette;
|
|
51
|
+
if (!palette || palette.mode !== "info" || palette.kind !== "join-requests") return null;
|
|
52
|
+
return this.paletteItems()[palette.selected] ?? null;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
askJoinDecision(this: JoinApp, decision: "approve" | "deny"): void {
|
|
56
|
+
const palette = this.state.palette;
|
|
57
|
+
const request = this.selectedJoinRequest();
|
|
58
|
+
if (!palette || !request) return;
|
|
59
|
+
const name = request.request?.name || request.request?.participantId || request.value;
|
|
60
|
+
palette.mode = "confirm";
|
|
61
|
+
palette.previous = { mode: "info", hint: palette.hint };
|
|
62
|
+
palette.confirm = {
|
|
63
|
+
text: decision === "approve" ? t("join.approve", { name }) : t("join.deny", { name }),
|
|
64
|
+
action: `join-${decision}`,
|
|
65
|
+
data: { sessionID: request.value, name },
|
|
66
|
+
};
|
|
67
|
+
palette.error = "";
|
|
68
|
+
palette.hint = t("palette.confirmHint");
|
|
69
|
+
this.touch();
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
async runJoinConfirm(this: JoinApp, confirm: PaletteConfirm): Promise<void> {
|
|
73
|
+
const palette = this.state.palette;
|
|
74
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
75
|
+
if (!palette || !roomId) return;
|
|
76
|
+
const requestSessionID = confirm.data.sessionID;
|
|
77
|
+
if (!requestSessionID) return;
|
|
78
|
+
const decision = confirm.action === "join-approve" ? "approve" : "deny";
|
|
79
|
+
palette.searching = true;
|
|
80
|
+
palette.error = "";
|
|
81
|
+
this.touch();
|
|
82
|
+
try {
|
|
83
|
+
await this.api.decideJoin(roomId, requestSessionID, this.sessionID, decision);
|
|
84
|
+
this.setStatus(t(decision === "approve" ? "join.approved" : "join.denied", { name: confirm.data.name }), "success");
|
|
85
|
+
await this.openJoinRequests();
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (this.state.palette === palette) {
|
|
88
|
+
palette.mode = "info";
|
|
89
|
+
palette.confirm = null;
|
|
90
|
+
palette.previous = null;
|
|
91
|
+
palette.searching = false;
|
|
92
|
+
palette.hint = reviewHint();
|
|
93
|
+
palette.error = statusOf(error) === 403 ? t("join.adminError") : errorText(error);
|
|
94
|
+
this.touch();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|