@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
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Message actions on top of the palette prompts: recall and reveal by id with
|
|
2
|
+
// confirmation, and a prompt-based reply flow that uses api.send's replyTo.
|
|
3
|
+
import { mergeMessages } from "./messages.mjs";
|
|
4
|
+
import { canonicalizeMentions } from "./mentions.mjs";
|
|
5
|
+
import { t } from "./i18n.mjs";
|
|
6
|
+
import type { ChatApp } from "./app.mjs";
|
|
7
|
+
import type { PaletteConfirm, PaletteData, PalettePrompt, PaletteState } from "./app-types.mjs";
|
|
8
|
+
|
|
9
|
+
const errorText = (error: unknown): string => (error instanceof Error ? error.message : String(error ?? "unknown error"));
|
|
10
|
+
|
|
11
|
+
// Palette methods owned by the still-JS palette attach module.
|
|
12
|
+
interface MessageApp extends ChatApp {
|
|
13
|
+
closePalette(): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// The methods this module attaches become visible on ChatApp for app.mts and
|
|
17
|
+
// the later attach migrations.
|
|
18
|
+
declare module "./app.mjs" {
|
|
19
|
+
interface ChatApp {
|
|
20
|
+
messageActionPalette(title: string, label: string, action: string, data?: PaletteData): PaletteState | null;
|
|
21
|
+
startMessageRecall(): PaletteState | null;
|
|
22
|
+
startMessageReveal(): PaletteState | null;
|
|
23
|
+
startMessageReply(): PaletteState | null;
|
|
24
|
+
startAskQuestion(): PaletteState | null;
|
|
25
|
+
submitMessagePrompt(prompt: PalettePrompt, value: string): Promise<void>;
|
|
26
|
+
runMessageConfirm(confirm: PaletteConfirm): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function attachMessageActions(Class: { prototype: ChatApp }) {
|
|
31
|
+
Object.assign(Class.prototype, {
|
|
32
|
+
messageActionPalette(
|
|
33
|
+
this: MessageApp,
|
|
34
|
+
title: string,
|
|
35
|
+
label: string,
|
|
36
|
+
action: string,
|
|
37
|
+
data: PaletteData = {},
|
|
38
|
+
): PaletteState | null {
|
|
39
|
+
const palette = this.state.palette;
|
|
40
|
+
const current = this.state.current;
|
|
41
|
+
if (!palette || !current || !this.state.joined) {
|
|
42
|
+
this.state.palette = null;
|
|
43
|
+
this.setStatus(t("info.joinFirst"), "error");
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
palette.mode = "prompt";
|
|
47
|
+
palette.roomId = current.id;
|
|
48
|
+
palette.roomParticipants = [...(current.participants || [])];
|
|
49
|
+
palette.title = title;
|
|
50
|
+
palette.subtitle = `#${current.name}`;
|
|
51
|
+
palette.error = "";
|
|
52
|
+
palette.prompt = { label, value: "", action, data };
|
|
53
|
+
palette.hint = t("palette.enterNextHint");
|
|
54
|
+
this.touch();
|
|
55
|
+
return palette;
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
startMessageRecall(this: MessageApp): PaletteState | null {
|
|
59
|
+
return this.messageActionPalette(t("message.recallTitle"), t("message.recallPrompt"), "message-recall-id");
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
startMessageReveal(this: MessageApp): PaletteState | null {
|
|
63
|
+
return this.messageActionPalette(t("message.revealTitle"), t("message.revealPrompt"), "message-reveal-id");
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
startMessageReply(this: MessageApp): PaletteState | null {
|
|
67
|
+
return this.messageActionPalette(t("message.replyTitle"), t("message.replyPrompt"), "message-reply-id");
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
startAskQuestion(this: MessageApp): PaletteState | null {
|
|
71
|
+
return this.messageActionPalette(t("message.askTitle"), t("message.askPrompt"), "message-ask");
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
async submitMessagePrompt(this: MessageApp, prompt: PalettePrompt, value: string): Promise<void> {
|
|
75
|
+
const palette = this.state.palette;
|
|
76
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
77
|
+
const participants = palette?.roomParticipants || this.state.current?.participants;
|
|
78
|
+
if (!palette || palette.mode !== "prompt") return;
|
|
79
|
+
if (!roomId) {
|
|
80
|
+
palette.error = t("info.joinFirst");
|
|
81
|
+
this.touch();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (prompt.action === "message-ask") {
|
|
85
|
+
const question = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
86
|
+
if (!question) {
|
|
87
|
+
palette.error = t("message.questionRequired");
|
|
88
|
+
this.touch();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
palette.searching = true;
|
|
92
|
+
palette.error = "";
|
|
93
|
+
this.touch();
|
|
94
|
+
try {
|
|
95
|
+
const result = await this.api.send(roomId, this.sessionID, question, { isQuestion: true });
|
|
96
|
+
const messages = result?.messages;
|
|
97
|
+
if (Array.isArray(messages)) mergeMessages(this.state.messages, messages);
|
|
98
|
+
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
99
|
+
this.state.connection = "online";
|
|
100
|
+
this.closePalette();
|
|
101
|
+
this.setStatus(t("message.questionSent"), "success");
|
|
102
|
+
this.markRead();
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (this.state.palette === palette) {
|
|
105
|
+
palette.searching = false;
|
|
106
|
+
palette.error = errorText(error);
|
|
107
|
+
this.touch();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const id = String(value ?? "").trim();
|
|
113
|
+
if (!id) {
|
|
114
|
+
palette.error = t("message.idRequired");
|
|
115
|
+
this.touch();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (prompt.action === "message-recall-id" || prompt.action === "message-reveal-id") {
|
|
119
|
+
const recall = prompt.action === "message-recall-id";
|
|
120
|
+
palette.mode = "confirm";
|
|
121
|
+
palette.previous = { mode: "prompt", hint: palette.hint };
|
|
122
|
+
palette.confirm = {
|
|
123
|
+
text: recall ? t("message.recallConfirm", { id }) : t("message.revealConfirm", { id }),
|
|
124
|
+
action: recall ? "message-recall" : "message-reveal",
|
|
125
|
+
data: { id },
|
|
126
|
+
};
|
|
127
|
+
palette.hint = t("palette.confirmHint");
|
|
128
|
+
palette.error = "";
|
|
129
|
+
this.touch();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (prompt.action === "message-reply-id") {
|
|
133
|
+
palette.prompt = {
|
|
134
|
+
label: t("message.replyLabel", { id }),
|
|
135
|
+
value: "",
|
|
136
|
+
action: "message-reply-text",
|
|
137
|
+
data: { id },
|
|
138
|
+
};
|
|
139
|
+
palette.hint = t("message.replyHint");
|
|
140
|
+
palette.error = "";
|
|
141
|
+
this.touch();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (prompt.action === "message-reply-text") {
|
|
145
|
+
const text = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
146
|
+
if (!text) {
|
|
147
|
+
palette.error = t("message.replyRequired");
|
|
148
|
+
this.touch();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
palette.searching = true;
|
|
152
|
+
palette.error = "";
|
|
153
|
+
this.touch();
|
|
154
|
+
try {
|
|
155
|
+
const result = await this.api.send(roomId, this.sessionID, text, { replyToMessageID: prompt.data.id });
|
|
156
|
+
if (!this.isCurrent(roomId)) return;
|
|
157
|
+
const messages = result?.messages;
|
|
158
|
+
if (Array.isArray(messages)) mergeMessages(this.state.messages, messages);
|
|
159
|
+
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
160
|
+
this.state.connection = "online";
|
|
161
|
+
this.closePalette();
|
|
162
|
+
this.setStatus(t("message.replySent"), "success");
|
|
163
|
+
this.markRead();
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (this.state.palette === palette) {
|
|
166
|
+
palette.searching = false;
|
|
167
|
+
palette.error = errorText(error);
|
|
168
|
+
this.touch();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
async runMessageConfirm(this: MessageApp, confirm: PaletteConfirm): Promise<void> {
|
|
175
|
+
const palette = this.state.palette;
|
|
176
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
177
|
+
if (!palette || !roomId) return;
|
|
178
|
+
const id = confirm.data.id;
|
|
179
|
+
if (!id) return;
|
|
180
|
+
palette.searching = true;
|
|
181
|
+
palette.error = "";
|
|
182
|
+
this.touch();
|
|
183
|
+
try {
|
|
184
|
+
if (confirm.action === "message-recall") {
|
|
185
|
+
await this.api.recall(roomId, id, this.sessionID);
|
|
186
|
+
const target = this.state.messages.find((message) => message.id === id);
|
|
187
|
+
if (target) target.recalledAt = Date.now();
|
|
188
|
+
this.closePalette();
|
|
189
|
+
this.setStatus(t("message.recalledStatus", { id }), "success");
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const revealed = await this.api.reveal(roomId, id, this.sessionID);
|
|
193
|
+
palette.mode = "detail";
|
|
194
|
+
palette.title = t("message.revealed");
|
|
195
|
+
palette.confirm = null;
|
|
196
|
+
palette.detail = {
|
|
197
|
+
title: t("message.revealed"),
|
|
198
|
+
markdown: String(revealed?.text ?? t("message.empty")),
|
|
199
|
+
kind: "revealed-message",
|
|
200
|
+
};
|
|
201
|
+
palette.hint = t("palette.closeHint");
|
|
202
|
+
palette.searching = false;
|
|
203
|
+
this.touch();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (this.state.palette === palette) {
|
|
206
|
+
palette.searching = false;
|
|
207
|
+
palette.error = errorText(error);
|
|
208
|
+
this.touch();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
}
|
package/src/tui/message-view.mjs
CHANGED
|
@@ -1,129 +1,108 @@
|
|
|
1
1
|
// Message row renderables: grouped metadata plus a Markdown body with mention
|
|
2
2
|
// highlighting. Split from ui-content.mjs to keep the state sync readable.
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
MarkdownRenderable,
|
|
6
|
-
StyledText,
|
|
7
|
-
TextRenderable,
|
|
8
|
-
bold,
|
|
9
|
-
dim,
|
|
10
|
-
fg,
|
|
11
|
-
getTreeSitterClient,
|
|
12
|
-
italic,
|
|
13
|
-
} from "@opentui/core";
|
|
14
|
-
import {
|
|
15
|
-
MENTION_SENTINEL,
|
|
16
|
-
createMarkdownSyntax,
|
|
17
|
-
createMentionRenderNode,
|
|
18
|
-
formatAttachments,
|
|
19
|
-
prepareMarkdown,
|
|
20
|
-
} from "./markdown.mjs";
|
|
3
|
+
import { BoxRenderable, MarkdownRenderable, StyledText, TextRenderable, bold, dim, fg, getTreeSitterClient, italic, } from "@opentui/core";
|
|
4
|
+
import { MENTION_SENTINEL, createMarkdownSyntax, createMentionInlineHook, formatAttachments, prepareMarkdown, } from "./markdown.mjs";
|
|
21
5
|
import { t } from "./i18n.mjs";
|
|
22
|
-
|
|
23
6
|
let treeSitter;
|
|
24
7
|
const treeClient = () => (treeSitter ??= getTreeSitterClient());
|
|
25
|
-
|
|
26
8
|
export function hashText(text) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
9
|
+
let hash = 2166136261;
|
|
10
|
+
for (const char of String(text)) {
|
|
11
|
+
hash ^= char.codePointAt(0) ?? 0;
|
|
12
|
+
hash = Math.imul(hash, 16777619);
|
|
13
|
+
}
|
|
14
|
+
return (hash >>> 0).toString(36);
|
|
33
15
|
}
|
|
34
|
-
|
|
35
16
|
export function markdownStyle(ui) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
17
|
+
let style = ui.syntaxStyles.get(ui.theme.mode);
|
|
18
|
+
if (!style) {
|
|
19
|
+
style = createMarkdownSyntax(ui.renderer, ui.theme);
|
|
20
|
+
ui.syntaxStyles.set(ui.theme.mode, style);
|
|
21
|
+
}
|
|
22
|
+
return style;
|
|
42
23
|
}
|
|
43
|
-
|
|
44
24
|
function messageChunks(ui, message, info) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
const { theme } = ui;
|
|
26
|
+
const chunks = [];
|
|
27
|
+
const highlighted = message.id === ui.app.state.highlight;
|
|
28
|
+
if (highlighted)
|
|
29
|
+
chunks.push(bold(fg(theme.accent)("▸ ")));
|
|
30
|
+
if (info.question)
|
|
31
|
+
chunks.push(bold(fg(theme.warning)("? ")));
|
|
32
|
+
chunks.push(dim(`${info.time} `));
|
|
33
|
+
const own = message.senderId === ui.app.state.participant;
|
|
34
|
+
chunks.push(bold(fg(own ? theme.accent : theme.text)(info.sender)));
|
|
35
|
+
return chunks;
|
|
54
36
|
}
|
|
55
|
-
|
|
56
37
|
function messageBody(ui, message, info, highlighted) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
const body = new BoxRenderable(ui.renderer, {
|
|
39
|
+
id: `message-body-${message.id}`,
|
|
40
|
+
width: "100%",
|
|
41
|
+
flexDirection: "column",
|
|
42
|
+
flexShrink: 0,
|
|
43
|
+
paddingLeft: 2,
|
|
44
|
+
paddingRight: 1,
|
|
45
|
+
backgroundColor: highlighted ? ui.theme.raised : undefined,
|
|
46
|
+
});
|
|
47
|
+
if (info.recalled) {
|
|
48
|
+
body.add(new TextRenderable(ui.renderer, {
|
|
49
|
+
id: `message-recalled-${message.id}`,
|
|
50
|
+
width: "100%",
|
|
51
|
+
wrapMode: "word",
|
|
52
|
+
content: new StyledText([dim(italic(t("chat.recalled")))]),
|
|
53
|
+
}));
|
|
54
|
+
return body;
|
|
55
|
+
}
|
|
56
|
+
const markdown = prepareMarkdown(formatAttachments(info.body));
|
|
57
|
+
body.add(new MarkdownRenderable(ui.renderer, {
|
|
58
|
+
id: `message-markdown-${message.id}`,
|
|
59
|
+
width: "100%",
|
|
60
|
+
content: markdown,
|
|
61
|
+
syntaxStyle: markdownStyle(ui),
|
|
62
|
+
treeSitterClient: treeClient(),
|
|
63
|
+
fg: ui.theme.text,
|
|
64
|
+
conceal: true,
|
|
65
|
+
concealCode: false,
|
|
66
|
+
streaming: false,
|
|
67
|
+
tableOptions: {
|
|
68
|
+
style: "columns",
|
|
69
|
+
widthMode: "full",
|
|
70
|
+
wrapMode: "word",
|
|
71
|
+
cellPaddingX: 1,
|
|
72
|
+
cellPaddingY: 0,
|
|
73
|
+
borderColor: ui.theme.border,
|
|
74
|
+
},
|
|
75
|
+
...(markdown.includes(MENTION_SENTINEL)
|
|
76
|
+
? { inlineHook: createMentionInlineHook(ui.theme), inlineHookFilter: [MENTION_SENTINEL] }
|
|
77
|
+
: {}),
|
|
72
78
|
}));
|
|
73
79
|
return body;
|
|
74
|
-
}
|
|
75
|
-
const markdown = prepareMarkdown(formatAttachments(info.body));
|
|
76
|
-
body.add(new MarkdownRenderable(ui.renderer, {
|
|
77
|
-
id: `message-markdown-${message.id}`,
|
|
78
|
-
width: "100%",
|
|
79
|
-
content: markdown,
|
|
80
|
-
syntaxStyle: markdownStyle(ui),
|
|
81
|
-
treeSitterClient: treeClient(),
|
|
82
|
-
fg: ui.theme.text,
|
|
83
|
-
conceal: true,
|
|
84
|
-
concealCode: false,
|
|
85
|
-
streaming: false,
|
|
86
|
-
tableOptions: {
|
|
87
|
-
style: "columns",
|
|
88
|
-
widthMode: "full",
|
|
89
|
-
wrapMode: "word",
|
|
90
|
-
cellPaddingX: 1,
|
|
91
|
-
cellPaddingY: 0,
|
|
92
|
-
borderColor: ui.theme.border,
|
|
93
|
-
},
|
|
94
|
-
...(markdown.includes(MENTION_SENTINEL)
|
|
95
|
-
? { renderNode: createMentionRenderNode(ui.renderer, ui.theme, `message-${message.id}`) }
|
|
96
|
-
: {}),
|
|
97
|
-
}));
|
|
98
|
-
return body;
|
|
99
80
|
}
|
|
100
|
-
|
|
101
81
|
export function buildMessageBlock(ui, message, info, highlighted, marginTop) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
82
|
+
const block = new BoxRenderable(ui.renderer, {
|
|
83
|
+
id: `message-${message.id}`,
|
|
84
|
+
width: "100%",
|
|
85
|
+
flexDirection: "column",
|
|
86
|
+
flexShrink: 0,
|
|
87
|
+
marginTop,
|
|
88
|
+
});
|
|
89
|
+
block.add(new TextRenderable(ui.renderer, {
|
|
90
|
+
id: `message-head-${message.id}`,
|
|
91
|
+
width: "100%",
|
|
92
|
+
height: 1,
|
|
93
|
+
wrapMode: "none",
|
|
94
|
+
truncate: true,
|
|
95
|
+
content: new StyledText(messageChunks(ui, message, info)),
|
|
96
|
+
}));
|
|
97
|
+
block.add(messageBody(ui, message, info, highlighted));
|
|
98
|
+
return block;
|
|
119
99
|
}
|
|
120
|
-
|
|
121
100
|
export function addNotice(ui, id, text, color) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
101
|
+
ui.messageContent.add(new TextRenderable(ui.renderer, {
|
|
102
|
+
id: `message-${id}`,
|
|
103
|
+
width: "100%",
|
|
104
|
+
flexShrink: 0,
|
|
105
|
+
wrapMode: "char",
|
|
106
|
+
content: new StyledText([fg(color)(text)]),
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Message row renderables: grouped metadata plus a Markdown body with mention
|
|
2
|
+
// highlighting. Split from ui-content.mjs to keep the state sync readable.
|
|
3
|
+
import {
|
|
4
|
+
BoxRenderable,
|
|
5
|
+
MarkdownRenderable,
|
|
6
|
+
StyledText,
|
|
7
|
+
TextRenderable,
|
|
8
|
+
bold,
|
|
9
|
+
dim,
|
|
10
|
+
fg,
|
|
11
|
+
getTreeSitterClient,
|
|
12
|
+
italic,
|
|
13
|
+
} from "@opentui/core";
|
|
14
|
+
import type { CliRenderer, SyntaxStyle, TextChunk, ThemeMode } from "@opentui/core";
|
|
15
|
+
import {
|
|
16
|
+
MENTION_SENTINEL,
|
|
17
|
+
createMarkdownSyntax,
|
|
18
|
+
createMentionInlineHook,
|
|
19
|
+
formatAttachments,
|
|
20
|
+
prepareMarkdown,
|
|
21
|
+
} from "./markdown.mjs";
|
|
22
|
+
import { t } from "./i18n.mjs";
|
|
23
|
+
import type { ChatMessage, FormattedMessage } from "./messages.mjs";
|
|
24
|
+
import type { TuiTheme } from "./ui-theme.mjs";
|
|
25
|
+
|
|
26
|
+
export interface MessageAppState {
|
|
27
|
+
highlight?: string | null;
|
|
28
|
+
participant?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface MessageUi {
|
|
32
|
+
renderer: CliRenderer;
|
|
33
|
+
theme: TuiTheme;
|
|
34
|
+
syntaxStyles: Map<ThemeMode, SyntaxStyle>;
|
|
35
|
+
app: { state: MessageAppState };
|
|
36
|
+
messageContent: BoxRenderable;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let treeSitter: ReturnType<typeof getTreeSitterClient> | undefined;
|
|
40
|
+
const treeClient = () => (treeSitter ??= getTreeSitterClient());
|
|
41
|
+
|
|
42
|
+
export function hashText(text: unknown): string {
|
|
43
|
+
let hash = 2166136261;
|
|
44
|
+
for (const char of String(text)) {
|
|
45
|
+
hash ^= char.codePointAt(0) ?? 0;
|
|
46
|
+
hash = Math.imul(hash, 16777619);
|
|
47
|
+
}
|
|
48
|
+
return (hash >>> 0).toString(36);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function markdownStyle(ui: MessageUi): SyntaxStyle {
|
|
52
|
+
let style = ui.syntaxStyles.get(ui.theme.mode);
|
|
53
|
+
if (!style) {
|
|
54
|
+
style = createMarkdownSyntax(ui.renderer, ui.theme);
|
|
55
|
+
ui.syntaxStyles.set(ui.theme.mode, style);
|
|
56
|
+
}
|
|
57
|
+
return style;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function messageChunks(ui: MessageUi, message: ChatMessage, info: FormattedMessage): TextChunk[] {
|
|
61
|
+
const { theme } = ui;
|
|
62
|
+
const chunks: TextChunk[] = [];
|
|
63
|
+
const highlighted = message.id === ui.app.state.highlight;
|
|
64
|
+
if (highlighted) chunks.push(bold(fg(theme.accent)("▸ ")));
|
|
65
|
+
if (info.question) chunks.push(bold(fg(theme.warning)("? ")));
|
|
66
|
+
chunks.push(dim(`${info.time} `));
|
|
67
|
+
const own = message.senderId === ui.app.state.participant;
|
|
68
|
+
chunks.push(bold(fg(own ? theme.accent : theme.text)(info.sender)));
|
|
69
|
+
return chunks;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function messageBody(ui: MessageUi, message: ChatMessage, info: FormattedMessage, highlighted: boolean): BoxRenderable {
|
|
73
|
+
const body = new BoxRenderable(ui.renderer, {
|
|
74
|
+
id: `message-body-${message.id}`,
|
|
75
|
+
width: "100%",
|
|
76
|
+
flexDirection: "column",
|
|
77
|
+
flexShrink: 0,
|
|
78
|
+
paddingLeft: 2,
|
|
79
|
+
paddingRight: 1,
|
|
80
|
+
backgroundColor: highlighted ? ui.theme.raised : undefined,
|
|
81
|
+
});
|
|
82
|
+
if (info.recalled) {
|
|
83
|
+
body.add(new TextRenderable(ui.renderer, {
|
|
84
|
+
id: `message-recalled-${message.id}`,
|
|
85
|
+
width: "100%",
|
|
86
|
+
wrapMode: "word",
|
|
87
|
+
content: new StyledText([dim(italic(t("chat.recalled")))]),
|
|
88
|
+
}));
|
|
89
|
+
return body;
|
|
90
|
+
}
|
|
91
|
+
const markdown = prepareMarkdown(formatAttachments(info.body));
|
|
92
|
+
body.add(new MarkdownRenderable(ui.renderer, {
|
|
93
|
+
id: `message-markdown-${message.id}`,
|
|
94
|
+
width: "100%",
|
|
95
|
+
content: markdown,
|
|
96
|
+
syntaxStyle: markdownStyle(ui),
|
|
97
|
+
treeSitterClient: treeClient(),
|
|
98
|
+
fg: ui.theme.text,
|
|
99
|
+
conceal: true,
|
|
100
|
+
concealCode: false,
|
|
101
|
+
streaming: false,
|
|
102
|
+
tableOptions: {
|
|
103
|
+
style: "columns",
|
|
104
|
+
widthMode: "full",
|
|
105
|
+
wrapMode: "word",
|
|
106
|
+
cellPaddingX: 1,
|
|
107
|
+
cellPaddingY: 0,
|
|
108
|
+
borderColor: ui.theme.border,
|
|
109
|
+
},
|
|
110
|
+
...(markdown.includes(MENTION_SENTINEL)
|
|
111
|
+
? { inlineHook: createMentionInlineHook(ui.theme), inlineHookFilter: [MENTION_SENTINEL] }
|
|
112
|
+
: {}),
|
|
113
|
+
}));
|
|
114
|
+
return body;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function buildMessageBlock(
|
|
118
|
+
ui: MessageUi,
|
|
119
|
+
message: ChatMessage,
|
|
120
|
+
info: FormattedMessage,
|
|
121
|
+
highlighted: boolean,
|
|
122
|
+
marginTop: number,
|
|
123
|
+
): BoxRenderable {
|
|
124
|
+
const block = new BoxRenderable(ui.renderer, {
|
|
125
|
+
id: `message-${message.id}`,
|
|
126
|
+
width: "100%",
|
|
127
|
+
flexDirection: "column",
|
|
128
|
+
flexShrink: 0,
|
|
129
|
+
marginTop,
|
|
130
|
+
});
|
|
131
|
+
block.add(new TextRenderable(ui.renderer, {
|
|
132
|
+
id: `message-head-${message.id}`,
|
|
133
|
+
width: "100%",
|
|
134
|
+
height: 1,
|
|
135
|
+
wrapMode: "none",
|
|
136
|
+
truncate: true,
|
|
137
|
+
content: new StyledText(messageChunks(ui, message, info)),
|
|
138
|
+
}));
|
|
139
|
+
block.add(messageBody(ui, message, info, highlighted));
|
|
140
|
+
return block;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function addNotice(ui: MessageUi, id: string, text: string, color: string): void {
|
|
144
|
+
ui.messageContent.add(new TextRenderable(ui.renderer, {
|
|
145
|
+
id: `message-${id}`,
|
|
146
|
+
width: "100%",
|
|
147
|
+
flexShrink: 0,
|
|
148
|
+
wrapMode: "char",
|
|
149
|
+
content: new StyledText([fg(color)(text)]),
|
|
150
|
+
}));
|
|
151
|
+
}
|