@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
package/src/tui/messages.mjs
CHANGED
|
@@ -1,67 +1,73 @@
|
|
|
1
1
|
// Shared message helpers: ordering, sequence cursors, merging and display text.
|
|
2
2
|
export function messageStamp(message) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const value = message?.createdAt;
|
|
4
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
5
|
+
return value;
|
|
6
|
+
const parsed = Date.parse(String(value ?? ""));
|
|
7
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
9
|
export function oldestSeq(messages) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
let oldest;
|
|
11
|
+
for (const message of messages) {
|
|
12
|
+
if (typeof message?.seq === "number" && (oldest === undefined || message.seq < oldest))
|
|
13
|
+
oldest = message.seq;
|
|
14
|
+
}
|
|
15
|
+
return oldest;
|
|
16
|
+
}
|
|
17
|
+
function isChatMessage(value) {
|
|
18
|
+
if (!value || typeof value !== "object")
|
|
19
|
+
return false;
|
|
20
|
+
const id = value.id;
|
|
21
|
+
return typeof id === "string" && id !== "";
|
|
15
22
|
}
|
|
16
|
-
|
|
17
23
|
/** Merge by message id, keep the first copy, and pick up recall updates. */
|
|
18
24
|
export function mergeMessages(target, items) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (!Array.isArray(items) || !items.length)
|
|
26
|
+
return target;
|
|
27
|
+
const known = new Map(target.map((message) => [message.id, message]));
|
|
28
|
+
for (const itemsEntry of items) {
|
|
29
|
+
if (!isChatMessage(itemsEntry))
|
|
30
|
+
continue;
|
|
31
|
+
const found = known.get(itemsEntry.id);
|
|
32
|
+
if (found) {
|
|
33
|
+
if (itemsEntry.recalledAt && !found.recalledAt)
|
|
34
|
+
found.recalledAt = itemsEntry.recalledAt;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const copy = { ...itemsEntry };
|
|
38
|
+
known.set(itemsEntry.id, copy);
|
|
39
|
+
target.push(copy);
|
|
27
40
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
target.push(copy);
|
|
31
|
-
}
|
|
32
|
-
target.sort((a, b) => messageStamp(a) - messageStamp(b));
|
|
33
|
-
return target;
|
|
41
|
+
target.sort((a, b) => messageStamp(a) - messageStamp(b));
|
|
42
|
+
return target;
|
|
34
43
|
}
|
|
35
|
-
|
|
36
44
|
/** Strip terminal control characters from server-provided text. */
|
|
37
45
|
export function sanitizeText(value) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
return String(value ?? "")
|
|
47
|
+
.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, " ")
|
|
48
|
+
.replace(/\t/g, " ");
|
|
41
49
|
}
|
|
42
|
-
|
|
43
50
|
function formatTime(value) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
const date = new Date(typeof value === "number" ? value : String(value ?? ""));
|
|
52
|
+
if (Number.isNaN(date.getTime()))
|
|
53
|
+
return "--:--";
|
|
54
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
55
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
56
|
+
return `${hours}:${minutes}`;
|
|
49
57
|
}
|
|
50
|
-
|
|
51
58
|
function senderName(room, message) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
const id = message?.senderId ?? message?.senderSessionID ?? "?";
|
|
60
|
+
const person = (room?.participants ?? []).find((entry) => entry?.id === id);
|
|
61
|
+
return sanitizeText(person?.name ?? id);
|
|
55
62
|
}
|
|
56
|
-
|
|
57
63
|
/** Display fields for one message; recalled bodies are never shown. */
|
|
58
64
|
export function formatMessage(message, room) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
65
|
+
const recalled = Boolean(message?.recalledAt);
|
|
66
|
+
return {
|
|
67
|
+
time: formatTime(message?.createdAt),
|
|
68
|
+
sender: senderName(room, message),
|
|
69
|
+
body: recalled ? "[recalled]" : sanitizeText(message?.text),
|
|
70
|
+
recalled,
|
|
71
|
+
question: Boolean(message?.isQuestion),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Shared message helpers: ordering, sequence cursors, merging and display text.
|
|
2
|
+
|
|
3
|
+
export interface Participant {
|
|
4
|
+
id?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ChatMessage {
|
|
9
|
+
id: string;
|
|
10
|
+
createdAt?: number | string;
|
|
11
|
+
text?: string;
|
|
12
|
+
seq?: number;
|
|
13
|
+
senderId?: string;
|
|
14
|
+
senderSessionID?: string;
|
|
15
|
+
recalledAt?: number;
|
|
16
|
+
isQuestion?: boolean;
|
|
17
|
+
[extra: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ChatRoom {
|
|
21
|
+
participants?: readonly Participant[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface FormattedMessage {
|
|
25
|
+
time: string;
|
|
26
|
+
sender: string;
|
|
27
|
+
body: string;
|
|
28
|
+
recalled: boolean;
|
|
29
|
+
question: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function messageStamp(message: ChatMessage | null | undefined): number {
|
|
33
|
+
const value = message?.createdAt;
|
|
34
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
35
|
+
const parsed = Date.parse(String(value ?? ""));
|
|
36
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function oldestSeq(messages: Iterable<ChatMessage | null | undefined>): number | undefined {
|
|
40
|
+
let oldest: number | undefined;
|
|
41
|
+
for (const message of messages) {
|
|
42
|
+
if (typeof message?.seq === "number" && (oldest === undefined || message.seq < oldest)) oldest = message.seq;
|
|
43
|
+
}
|
|
44
|
+
return oldest;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isChatMessage(value: unknown): value is ChatMessage {
|
|
48
|
+
if (!value || typeof value !== "object") return false;
|
|
49
|
+
const id = (value as { id?: unknown }).id;
|
|
50
|
+
return typeof id === "string" && id !== "";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Merge by message id, keep the first copy, and pick up recall updates. */
|
|
54
|
+
export function mergeMessages(target: ChatMessage[], items: unknown): ChatMessage[] {
|
|
55
|
+
if (!Array.isArray(items) || !items.length) return target;
|
|
56
|
+
const known = new Map(target.map((message) => [message.id, message]));
|
|
57
|
+
for (const itemsEntry of items) {
|
|
58
|
+
if (!isChatMessage(itemsEntry)) continue;
|
|
59
|
+
const found = known.get(itemsEntry.id);
|
|
60
|
+
if (found) {
|
|
61
|
+
if (itemsEntry.recalledAt && !found.recalledAt) found.recalledAt = itemsEntry.recalledAt;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const copy: ChatMessage = { ...itemsEntry };
|
|
65
|
+
known.set(itemsEntry.id, copy);
|
|
66
|
+
target.push(copy);
|
|
67
|
+
}
|
|
68
|
+
target.sort((a, b) => messageStamp(a) - messageStamp(b));
|
|
69
|
+
return target;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Strip terminal control characters from server-provided text. */
|
|
73
|
+
export function sanitizeText(value: unknown): string {
|
|
74
|
+
return String(value ?? "")
|
|
75
|
+
.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, " ")
|
|
76
|
+
.replace(/\t/g, " ");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function formatTime(value: unknown): string {
|
|
80
|
+
const date = new Date(typeof value === "number" ? value : String(value ?? ""));
|
|
81
|
+
if (Number.isNaN(date.getTime())) return "--:--";
|
|
82
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
83
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
84
|
+
return `${hours}:${minutes}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function senderName(room: ChatRoom | null | undefined, message: ChatMessage | null | undefined): string {
|
|
88
|
+
const id = message?.senderId ?? message?.senderSessionID ?? "?";
|
|
89
|
+
const person = (room?.participants ?? []).find((entry) => entry?.id === id);
|
|
90
|
+
return sanitizeText(person?.name ?? id);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Display fields for one message; recalled bodies are never shown. */
|
|
94
|
+
export function formatMessage(
|
|
95
|
+
message: ChatMessage | null | undefined,
|
|
96
|
+
room: ChatRoom | null | undefined,
|
|
97
|
+
): FormattedMessage {
|
|
98
|
+
const recalled = Boolean(message?.recalledAt);
|
|
99
|
+
return {
|
|
100
|
+
time: formatTime(message?.createdAt),
|
|
101
|
+
sender: senderName(room, message),
|
|
102
|
+
body: recalled ? "[recalled]" : sanitizeText(message?.text),
|
|
103
|
+
recalled,
|
|
104
|
+
question: Boolean(message?.isQuestion),
|
|
105
|
+
};
|
|
106
|
+
}
|