@alexsun-top/opencode-chat-room 0.7.5 → 0.7.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 +14 -0
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +20 -0
- package/dist/cli.js +18 -0
- package/package.json +1 -1
- package/server/assets/chat/doc-preview.js +113 -0
- package/server/assets/chat/events.js +6 -0
- package/server/assets/chat/files.js +14 -6
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/locales/de.js +3 -3
- package/server/assets/chat/locales/es.js +3 -3
- package/server/assets/chat/locales/fr.js +3 -3
- package/server/assets/chat/locales/it.js +3 -3
- package/server/assets/chat/locales/ja.js +3 -3
- package/server/assets/chat/locales/ko.js +3 -3
- package/server/assets/chat/markdown.js +12 -4
- package/server/assets/chat/palette.js +9 -5
- package/server/assets/chat/state.js +6 -6
- package/server/assets/chat/system-messages.js +7 -1
- package/server/assets/doc-preview.css +158 -0
- package/server/assets/edit-room.css +8 -0
- package/server/assets/settings.css +9 -2
- package/server/chat.html +33 -15
- package/server/sw.js +1 -0
- package/src/tui/app.mjs +16 -1
- package/src/tui/http.mjs +109 -10
- package/src/tui/info-app.mjs +435 -0
- package/src/tui/info-content.mjs +198 -0
- package/src/tui/join-app.mjs +71 -0
- package/src/tui/main.mjs +23 -4
- package/src/tui/markdown.mjs +269 -0
- package/src/tui/message-app.mjs +177 -0
- package/src/tui/message-view.mjs +128 -0
- package/src/tui/palette-app.mjs +85 -9
- package/src/tui/palette.mjs +17 -2
- package/src/tui/reminder-app.mjs +189 -0
- package/src/tui/room-settings-app.mjs +249 -0
- package/src/tui/ui-content.mjs +136 -93
- package/src/tui/ui-overlay-view.mjs +255 -0
- package/src/tui/ui-view.mjs +2 -190
- package/src/tui/ui.mjs +103 -1
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
|
|
5
|
+
const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
|
|
6
|
+
|
|
7
|
+
export function attachMessageActions(Class) {
|
|
8
|
+
Object.assign(Class.prototype, {
|
|
9
|
+
messageActionPalette(title, label, action, data = {}) {
|
|
10
|
+
const palette = this.state.palette;
|
|
11
|
+
if (!palette || !this.state.current || !this.state.joined) {
|
|
12
|
+
this.state.palette = null;
|
|
13
|
+
this.setStatus("open a joined room first", "error");
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
palette.mode = "prompt";
|
|
17
|
+
palette.title = title;
|
|
18
|
+
palette.subtitle = `#${this.state.current.name}`;
|
|
19
|
+
palette.error = "";
|
|
20
|
+
palette.prompt = { label, value: "", action, data };
|
|
21
|
+
palette.hint = "Enter next · Esc cancel";
|
|
22
|
+
this.touch();
|
|
23
|
+
return palette;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
startMessageRecall() {
|
|
27
|
+
return this.messageActionPalette("Recall message", "Message ID to recall", "message-recall-id");
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
startMessageReveal() {
|
|
31
|
+
return this.messageActionPalette("Reveal message", "Message ID to reveal", "message-reveal-id");
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
startMessageReply() {
|
|
35
|
+
return this.messageActionPalette("Reply", "Message ID to reply to", "message-reply-id");
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
startAskQuestion() {
|
|
39
|
+
return this.messageActionPalette("Ask question", "Question text", "message-ask");
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
async submitMessagePrompt(prompt, value) {
|
|
43
|
+
const palette = this.state.palette;
|
|
44
|
+
const room = this.state.current;
|
|
45
|
+
if (!palette || palette.mode !== "prompt") return;
|
|
46
|
+
if (!room) {
|
|
47
|
+
palette.error = "open a joined room first";
|
|
48
|
+
this.touch();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (prompt.action === "message-ask") {
|
|
52
|
+
const question = String(value ?? "").trim();
|
|
53
|
+
if (!question) {
|
|
54
|
+
palette.error = "question text is required";
|
|
55
|
+
this.touch();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
palette.searching = true;
|
|
59
|
+
palette.error = "";
|
|
60
|
+
this.touch();
|
|
61
|
+
try {
|
|
62
|
+
const result = await this.api.send(room.id, this.sessionID, question, { isQuestion: true });
|
|
63
|
+
if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
|
|
64
|
+
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
65
|
+
this.state.connection = "online";
|
|
66
|
+
this.closePalette();
|
|
67
|
+
this.setStatus("question sent", "success");
|
|
68
|
+
this.markRead();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (this.state.palette === palette) {
|
|
71
|
+
palette.searching = false;
|
|
72
|
+
palette.error = errorText(error);
|
|
73
|
+
this.touch();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const id = String(value ?? "").trim();
|
|
79
|
+
if (!id) {
|
|
80
|
+
palette.error = "message ID is required";
|
|
81
|
+
this.touch();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (prompt.action === "message-recall-id" || prompt.action === "message-reveal-id") {
|
|
85
|
+
const recall = prompt.action === "message-recall-id";
|
|
86
|
+
palette.mode = "confirm";
|
|
87
|
+
palette.previous = { mode: "prompt", hint: palette.hint };
|
|
88
|
+
palette.confirm = {
|
|
89
|
+
text: recall ? `Recall message "${id}"?` : `Reveal the original text of "${id}"?`,
|
|
90
|
+
action: recall ? "message-recall" : "message-reveal",
|
|
91
|
+
data: { id },
|
|
92
|
+
};
|
|
93
|
+
palette.hint = "Enter or y confirms · n or Esc cancels";
|
|
94
|
+
palette.error = "";
|
|
95
|
+
this.touch();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (prompt.action === "message-reply-id") {
|
|
99
|
+
palette.prompt = {
|
|
100
|
+
label: `Reply to ${id}`,
|
|
101
|
+
value: "",
|
|
102
|
+
action: "message-reply-text",
|
|
103
|
+
data: { id },
|
|
104
|
+
};
|
|
105
|
+
palette.hint = "Enter send · Esc cancel";
|
|
106
|
+
palette.error = "";
|
|
107
|
+
this.touch();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (prompt.action === "message-reply-text") {
|
|
111
|
+
const text = String(value ?? "").trim();
|
|
112
|
+
if (!text) {
|
|
113
|
+
palette.error = "reply text is required";
|
|
114
|
+
this.touch();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
palette.searching = true;
|
|
118
|
+
palette.error = "";
|
|
119
|
+
this.touch();
|
|
120
|
+
try {
|
|
121
|
+
const result = await this.api.send(room.id, this.sessionID, text, { replyToMessageID: prompt.data.id });
|
|
122
|
+
if (!this.isCurrent(room.id)) return;
|
|
123
|
+
if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
|
|
124
|
+
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
125
|
+
this.state.connection = "online";
|
|
126
|
+
this.closePalette();
|
|
127
|
+
this.setStatus("reply sent", "success");
|
|
128
|
+
this.markRead();
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (this.state.palette === palette) {
|
|
131
|
+
palette.searching = false;
|
|
132
|
+
palette.error = errorText(error);
|
|
133
|
+
this.touch();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
async runMessageConfirm(confirm) {
|
|
140
|
+
const palette = this.state.palette;
|
|
141
|
+
const room = this.state.current;
|
|
142
|
+
if (!palette || !room) return;
|
|
143
|
+
const id = confirm.data.id;
|
|
144
|
+
palette.searching = true;
|
|
145
|
+
palette.error = "";
|
|
146
|
+
this.touch();
|
|
147
|
+
try {
|
|
148
|
+
if (confirm.action === "message-recall") {
|
|
149
|
+
await this.api.recall(room.id, id, this.sessionID);
|
|
150
|
+
const target = this.state.messages.find((message) => message.id === id);
|
|
151
|
+
if (target) target.recalledAt = Date.now();
|
|
152
|
+
this.closePalette();
|
|
153
|
+
this.setStatus(`recalled ${id}`, "success");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const revealed = await this.api.reveal(room.id, id, this.sessionID);
|
|
157
|
+
palette.mode = "detail";
|
|
158
|
+
palette.title = "Revealed message";
|
|
159
|
+
palette.confirm = null;
|
|
160
|
+
palette.detail = {
|
|
161
|
+
title: "Revealed message",
|
|
162
|
+
markdown: String(revealed?.text ?? "(empty)"),
|
|
163
|
+
kind: "revealed-message",
|
|
164
|
+
};
|
|
165
|
+
palette.hint = "Esc close";
|
|
166
|
+
palette.searching = false;
|
|
167
|
+
this.touch();
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (this.state.palette === palette) {
|
|
170
|
+
palette.searching = false;
|
|
171
|
+
palette.error = errorText(error);
|
|
172
|
+
this.touch();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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 {
|
|
15
|
+
MENTION_SENTINEL,
|
|
16
|
+
createMarkdownSyntax,
|
|
17
|
+
createMentionRenderNode,
|
|
18
|
+
formatAttachments,
|
|
19
|
+
prepareMarkdown,
|
|
20
|
+
} from "./markdown.mjs";
|
|
21
|
+
|
|
22
|
+
let treeSitter;
|
|
23
|
+
const treeClient = () => (treeSitter ??= getTreeSitterClient());
|
|
24
|
+
|
|
25
|
+
export function hashText(text) {
|
|
26
|
+
let hash = 2166136261;
|
|
27
|
+
for (const char of String(text)) {
|
|
28
|
+
hash ^= char.codePointAt(0);
|
|
29
|
+
hash = Math.imul(hash, 16777619);
|
|
30
|
+
}
|
|
31
|
+
return (hash >>> 0).toString(36);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function markdownStyle(ui) {
|
|
35
|
+
let style = ui.syntaxStyles.get(ui.theme.mode);
|
|
36
|
+
if (!style) {
|
|
37
|
+
style = createMarkdownSyntax(ui.theme);
|
|
38
|
+
ui.syntaxStyles.set(ui.theme.mode, style);
|
|
39
|
+
}
|
|
40
|
+
return style;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function messageChunks(ui, message, info) {
|
|
44
|
+
const { theme } = ui;
|
|
45
|
+
const chunks = [];
|
|
46
|
+
const highlighted = message.id === ui.app.state.highlight;
|
|
47
|
+
if (highlighted) chunks.push(bold(fg(theme.accent)("▸ ")));
|
|
48
|
+
if (info.question) chunks.push(bold(fg(theme.warning)("? ")));
|
|
49
|
+
chunks.push(dim(`${info.time} `));
|
|
50
|
+
const own = message.senderId === ui.app.state.participant;
|
|
51
|
+
chunks.push(bold(fg(own ? theme.accent : theme.text)(info.sender)));
|
|
52
|
+
return chunks;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function messageBody(ui, message, info, highlighted) {
|
|
56
|
+
const body = new BoxRenderable(ui.renderer, {
|
|
57
|
+
id: `message-body-${message.id}`,
|
|
58
|
+
width: "100%",
|
|
59
|
+
flexDirection: "column",
|
|
60
|
+
flexShrink: 0,
|
|
61
|
+
paddingLeft: 2,
|
|
62
|
+
paddingRight: 1,
|
|
63
|
+
backgroundColor: highlighted ? ui.theme.raised : undefined,
|
|
64
|
+
});
|
|
65
|
+
if (info.recalled) {
|
|
66
|
+
body.add(new TextRenderable(ui.renderer, {
|
|
67
|
+
id: `message-recalled-${message.id}`,
|
|
68
|
+
width: "100%",
|
|
69
|
+
wrapMode: "word",
|
|
70
|
+
content: new StyledText([dim(italic("[recalled]"))]),
|
|
71
|
+
}));
|
|
72
|
+
return body;
|
|
73
|
+
}
|
|
74
|
+
const markdown = prepareMarkdown(formatAttachments(info.body));
|
|
75
|
+
body.add(new MarkdownRenderable(ui.renderer, {
|
|
76
|
+
id: `message-markdown-${message.id}`,
|
|
77
|
+
width: "100%",
|
|
78
|
+
content: markdown,
|
|
79
|
+
syntaxStyle: markdownStyle(ui),
|
|
80
|
+
treeSitterClient: treeClient(),
|
|
81
|
+
fg: ui.theme.text,
|
|
82
|
+
conceal: true,
|
|
83
|
+
concealCode: false,
|
|
84
|
+
streaming: false,
|
|
85
|
+
tableOptions: {
|
|
86
|
+
style: "columns",
|
|
87
|
+
widthMode: "full",
|
|
88
|
+
wrapMode: "word",
|
|
89
|
+
cellPaddingX: 1,
|
|
90
|
+
cellPaddingY: 0,
|
|
91
|
+
borderColor: ui.theme.border,
|
|
92
|
+
},
|
|
93
|
+
...(markdown.includes(MENTION_SENTINEL)
|
|
94
|
+
? { renderNode: createMentionRenderNode(ui.renderer, ui.theme, `message-${message.id}`) }
|
|
95
|
+
: {}),
|
|
96
|
+
}));
|
|
97
|
+
return body;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function buildMessageBlock(ui, message, info, highlighted, marginTop) {
|
|
101
|
+
const block = new BoxRenderable(ui.renderer, {
|
|
102
|
+
id: `message-${message.id}`,
|
|
103
|
+
width: "100%",
|
|
104
|
+
flexDirection: "column",
|
|
105
|
+
flexShrink: 0,
|
|
106
|
+
marginTop,
|
|
107
|
+
});
|
|
108
|
+
block.add(new TextRenderable(ui.renderer, {
|
|
109
|
+
id: `message-head-${message.id}`,
|
|
110
|
+
width: "100%",
|
|
111
|
+
height: 1,
|
|
112
|
+
wrapMode: "none",
|
|
113
|
+
truncate: true,
|
|
114
|
+
content: new StyledText(messageChunks(ui, message, info)),
|
|
115
|
+
}));
|
|
116
|
+
block.add(messageBody(ui, message, info, highlighted));
|
|
117
|
+
return block;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function addNotice(ui, id, text, color) {
|
|
121
|
+
ui.messageContent.add(new TextRenderable(ui.renderer, {
|
|
122
|
+
id: `message-${id}`,
|
|
123
|
+
width: "100%",
|
|
124
|
+
flexShrink: 0,
|
|
125
|
+
wrapMode: "char",
|
|
126
|
+
content: new StyledText([fg(color)(text)]),
|
|
127
|
+
}));
|
|
128
|
+
}
|
package/src/tui/palette-app.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// Command palette controller attached to ChatApp. Kept in its own file so the
|
|
2
2
|
// terminal core stays under the project line budget.
|
|
3
|
-
import { buildCommands, nextScope, scopeSources, searchMessages } from "./palette.mjs";
|
|
3
|
+
import { buildCommands, filterCommands, nextScope, scopeSources, searchMessages } from "./palette.mjs";
|
|
4
4
|
import { mergeMessages, oldestSeq } from "./messages.mjs";
|
|
5
5
|
|
|
6
6
|
const SEARCH_PAGES = 2;
|
|
7
7
|
|
|
8
8
|
export function attachPalette(Class) {
|
|
9
9
|
Object.assign(Class.prototype, {
|
|
10
|
-
openPalette() {
|
|
10
|
+
openPalette({ slash = false } = {}) {
|
|
11
11
|
this.historyPages.clear();
|
|
12
12
|
this.state.help = false;
|
|
13
13
|
this.state.palette = {
|
|
14
14
|
mode: "commands",
|
|
15
|
-
query: "",
|
|
15
|
+
query: slash ? "/" : "",
|
|
16
16
|
scope: "room",
|
|
17
17
|
selected: 0,
|
|
18
18
|
results: [],
|
|
@@ -30,12 +30,14 @@ export function attachPalette(Class) {
|
|
|
30
30
|
},
|
|
31
31
|
|
|
32
32
|
paletteCommands() {
|
|
33
|
-
|
|
33
|
+
const palette = this.state.palette;
|
|
34
|
+
const query = palette?.mode === "commands" ? String(palette.query ?? "").replace(/^\s*\//, "") : "";
|
|
35
|
+
return filterCommands(buildCommands({
|
|
34
36
|
rooms: this.state.rooms,
|
|
35
37
|
current: this.state.current,
|
|
36
38
|
joined: this.state.joined,
|
|
37
39
|
help: this.state.help,
|
|
38
|
-
});
|
|
40
|
+
}), query);
|
|
39
41
|
},
|
|
40
42
|
|
|
41
43
|
paletteItems() {
|
|
@@ -43,6 +45,7 @@ export function attachPalette(Class) {
|
|
|
43
45
|
if (!palette) return [];
|
|
44
46
|
if (palette.mode === "search") return palette.results;
|
|
45
47
|
if (palette.mode === "commands") return this.paletteCommands();
|
|
48
|
+
if (palette.mode === "info") return palette.items ?? [];
|
|
46
49
|
return [];
|
|
47
50
|
},
|
|
48
51
|
|
|
@@ -114,9 +117,18 @@ export function attachPalette(Class) {
|
|
|
114
117
|
const palette = this.state.palette;
|
|
115
118
|
if (!palette) return;
|
|
116
119
|
if (palette.mode === "prompt") {
|
|
117
|
-
await this.
|
|
120
|
+
await this.submitPalettePrompt();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (palette.mode === "info") {
|
|
124
|
+
await this.runInfoSelection();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (palette.mode === "confirm") {
|
|
128
|
+
await this.runConfirm();
|
|
118
129
|
return;
|
|
119
130
|
}
|
|
131
|
+
if (palette.mode === "detail") return;
|
|
120
132
|
if (palette.mode === "commands") {
|
|
121
133
|
const command = this.paletteCommands()[palette.selected];
|
|
122
134
|
if (command) await this.runPaletteCommand(command);
|
|
@@ -126,6 +138,17 @@ export function attachPalette(Class) {
|
|
|
126
138
|
if (result) await this.activateResult(result);
|
|
127
139
|
},
|
|
128
140
|
|
|
141
|
+
async submitPalettePrompt() {
|
|
142
|
+
const palette = this.state.palette;
|
|
143
|
+
const value = palette?.prompt?.value ?? "";
|
|
144
|
+
if (!palette?.prompt) return;
|
|
145
|
+
if (palette.prompt.action && palette.prompt.action !== "new-room") {
|
|
146
|
+
await this.submitCommandPrompt(palette.prompt, value);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
await this.createRoomFromPrompt();
|
|
150
|
+
},
|
|
151
|
+
|
|
129
152
|
async runPaletteCommand(command) {
|
|
130
153
|
const palette = this.state.palette;
|
|
131
154
|
switch (command.id) {
|
|
@@ -135,7 +158,7 @@ export function attachPalette(Class) {
|
|
|
135
158
|
return;
|
|
136
159
|
case "new-room":
|
|
137
160
|
palette.mode = "prompt";
|
|
138
|
-
palette.prompt = { label: "New room name", value: "" };
|
|
161
|
+
palette.prompt = { label: "New room name", value: "", action: "new-room", data: {} };
|
|
139
162
|
palette.selected = 0;
|
|
140
163
|
palette.error = "";
|
|
141
164
|
this.touch();
|
|
@@ -161,6 +184,50 @@ export function attachPalette(Class) {
|
|
|
161
184
|
this.touch();
|
|
162
185
|
void this.ensureSearchHistory();
|
|
163
186
|
return;
|
|
187
|
+
case "members":
|
|
188
|
+
await this.openMembers();
|
|
189
|
+
return;
|
|
190
|
+
case "join-requests":
|
|
191
|
+
await this.openJoinRequests();
|
|
192
|
+
return;
|
|
193
|
+
case "announcements":
|
|
194
|
+
await this.openAnnouncements();
|
|
195
|
+
return;
|
|
196
|
+
case "questions":
|
|
197
|
+
await this.openQuestions();
|
|
198
|
+
return;
|
|
199
|
+
case "files":
|
|
200
|
+
await this.openFiles();
|
|
201
|
+
return;
|
|
202
|
+
case "reminders":
|
|
203
|
+
await this.openReminders();
|
|
204
|
+
return;
|
|
205
|
+
case "settings":
|
|
206
|
+
this.openSettings();
|
|
207
|
+
return;
|
|
208
|
+
case "room-settings":
|
|
209
|
+
await this.openRoomSettings();
|
|
210
|
+
return;
|
|
211
|
+
case "delete-room":
|
|
212
|
+
await this.openRoomSettings();
|
|
213
|
+
this.askDeleteRoom();
|
|
214
|
+
return;
|
|
215
|
+
case "recall-message":
|
|
216
|
+
this.startMessageRecall();
|
|
217
|
+
return;
|
|
218
|
+
case "reveal-message":
|
|
219
|
+
this.startMessageReveal();
|
|
220
|
+
return;
|
|
221
|
+
case "reply-message":
|
|
222
|
+
this.startMessageReply();
|
|
223
|
+
return;
|
|
224
|
+
case "ask-question":
|
|
225
|
+
this.startAskQuestion();
|
|
226
|
+
return;
|
|
227
|
+
case "quit":
|
|
228
|
+
this.closePalette();
|
|
229
|
+
this.quit();
|
|
230
|
+
return;
|
|
164
231
|
default:
|
|
165
232
|
if (command.roomId) {
|
|
166
233
|
const index = this.state.rooms.findIndex((room) => room.id === command.roomId);
|
|
@@ -228,10 +295,10 @@ export function attachPalette(Class) {
|
|
|
228
295
|
|
|
229
296
|
setPaletteQuery(value) {
|
|
230
297
|
const palette = this.state.palette;
|
|
231
|
-
if (!palette || palette.mode
|
|
298
|
+
if (!palette || (palette.mode !== "commands" && palette.mode !== "search")) return;
|
|
232
299
|
const query = String(value ?? "");
|
|
233
300
|
palette.error = "";
|
|
234
|
-
if (!query) {
|
|
301
|
+
if (!query.trim()) {
|
|
235
302
|
palette.mode = "commands";
|
|
236
303
|
palette.query = "";
|
|
237
304
|
palette.results = [];
|
|
@@ -240,6 +307,15 @@ export function attachPalette(Class) {
|
|
|
240
307
|
this.touch();
|
|
241
308
|
return;
|
|
242
309
|
}
|
|
310
|
+
if (query.trimStart().startsWith("/")) {
|
|
311
|
+
palette.mode = "commands";
|
|
312
|
+
palette.query = query;
|
|
313
|
+
palette.results = [];
|
|
314
|
+
palette.searching = false;
|
|
315
|
+
palette.selected = 0;
|
|
316
|
+
this.touch();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
243
319
|
palette.mode = "search";
|
|
244
320
|
palette.query = query;
|
|
245
321
|
palette.selected = 0;
|
package/src/tui/palette.mjs
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
const SEARCH_LIMIT = 50;
|
|
5
5
|
|
|
6
6
|
export function filterCommands(commands, query) {
|
|
7
|
-
const
|
|
7
|
+
const normalize = (value) => String(value ?? "").trim().toLowerCase().replace(/[-_]+/g, " ");
|
|
8
|
+
const needle = normalize(query);
|
|
8
9
|
if (!needle) return commands.slice();
|
|
9
|
-
return commands.filter((command) => command.label
|
|
10
|
+
return commands.filter((command) => normalize(command.label).includes(needle));
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/** Commands shown when the palette query is empty. */
|
|
@@ -25,6 +26,20 @@ export function buildCommands({ rooms = [], current = null, joined = false, help
|
|
|
25
26
|
}
|
|
26
27
|
commands.push({ id: "search-room", label: "Search this room" });
|
|
27
28
|
commands.push({ id: "search-all", label: "Search all joined rooms" });
|
|
29
|
+
commands.push({ id: "members", label: "Members" });
|
|
30
|
+
commands.push({ id: "join-requests", label: "Join requests" });
|
|
31
|
+
commands.push({ id: "announcements", label: "Announcements" });
|
|
32
|
+
commands.push({ id: "questions", label: "Questions" });
|
|
33
|
+
commands.push({ id: "files", label: "Files" });
|
|
34
|
+
commands.push({ id: "reminders", label: "Reminders" });
|
|
35
|
+
commands.push({ id: "settings", label: "Settings" });
|
|
36
|
+
commands.push({ id: "room-settings", label: "Room settings" });
|
|
37
|
+
commands.push({ id: "delete-room", label: "Delete room..." });
|
|
38
|
+
commands.push({ id: "recall-message", label: "Recall message..." });
|
|
39
|
+
commands.push({ id: "reveal-message", label: "Reveal message..." });
|
|
40
|
+
commands.push({ id: "reply-message", label: "Reply to message..." });
|
|
41
|
+
commands.push({ id: "ask-question", label: "Ask question..." });
|
|
42
|
+
commands.push({ id: "quit", label: "Quit" });
|
|
28
43
|
return commands;
|
|
29
44
|
}
|
|
30
45
|
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Reminder management on top of the shared palette overlay: list, create,
|
|
2
|
+
// pause/resume, edit text and delete. Schedule parsing stays pure in
|
|
3
|
+
// info-content.mjs so errors can be tested without a renderer.
|
|
4
|
+
import { parseReminderSchedule, reminderRows } from "./info-content.mjs";
|
|
5
|
+
import { sanitizeText } from "./messages.mjs";
|
|
6
|
+
|
|
7
|
+
const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
|
|
8
|
+
export const REMINDER_HINT = "n new · p pause/resume · e edit · d delete · Esc close";
|
|
9
|
+
|
|
10
|
+
function promptScheduleLabel() {
|
|
11
|
+
return 'Schedule: once 2026-11-23T09:00 or cron 0 9 * * *';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function attachReminders(Class) {
|
|
15
|
+
Object.assign(Class.prototype, {
|
|
16
|
+
openReminders() {
|
|
17
|
+
return this.openInfo("reminders", "Reminders", REMINDER_HINT, async (room) =>
|
|
18
|
+
reminderRows(await this.api.reminders(room.id, this.sessionID)));
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
reminderPalette() {
|
|
22
|
+
const palette = this.state.palette;
|
|
23
|
+
return palette?.mode === "info" && palette.kind === "reminders" ? palette : null;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
selectedReminder() {
|
|
27
|
+
const palette = this.reminderPalette();
|
|
28
|
+
return palette ? this.paletteItems()[palette.selected] : null;
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
startReminderCreate() {
|
|
32
|
+
const palette = this.reminderPalette();
|
|
33
|
+
if (!palette) return;
|
|
34
|
+
palette.mode = "prompt";
|
|
35
|
+
palette.error = "";
|
|
36
|
+
palette.prompt = { label: "Reminder text", value: "", action: "reminder-text", data: {} };
|
|
37
|
+
palette.hint = "Enter next · Esc cancel";
|
|
38
|
+
this.touch();
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
startReminderEdit() {
|
|
42
|
+
const palette = this.reminderPalette();
|
|
43
|
+
const reminder = this.selectedReminder();
|
|
44
|
+
if (!palette || !reminder) return;
|
|
45
|
+
palette.mode = "prompt";
|
|
46
|
+
palette.error = "";
|
|
47
|
+
palette.prompt = {
|
|
48
|
+
label: "Reminder text",
|
|
49
|
+
value: reminder.text,
|
|
50
|
+
action: "reminder-edit-text",
|
|
51
|
+
data: { id: reminder.value },
|
|
52
|
+
};
|
|
53
|
+
palette.hint = "Enter save · Esc cancel";
|
|
54
|
+
this.touch();
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
async toggleReminder() {
|
|
58
|
+
const palette = this.reminderPalette();
|
|
59
|
+
const reminder = this.selectedReminder();
|
|
60
|
+
const room = this.state.current;
|
|
61
|
+
if (!palette || !reminder || !room) return;
|
|
62
|
+
palette.searching = true;
|
|
63
|
+
palette.error = "";
|
|
64
|
+
this.touch();
|
|
65
|
+
try {
|
|
66
|
+
await this.api.updateReminder(room.id, reminder.value, this.sessionID, { paused: !reminder.paused });
|
|
67
|
+
this.setStatus(`${reminder.paused ? "resumed" : "paused"} reminder`, "success");
|
|
68
|
+
await this.openReminders();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (this.state.palette === palette) {
|
|
71
|
+
palette.searching = false;
|
|
72
|
+
palette.error = errorText(error);
|
|
73
|
+
this.touch();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
askDeleteReminder() {
|
|
79
|
+
const palette = this.reminderPalette();
|
|
80
|
+
const reminder = this.selectedReminder();
|
|
81
|
+
if (!palette || !reminder) return;
|
|
82
|
+
palette.mode = "confirm";
|
|
83
|
+
palette.error = "";
|
|
84
|
+
palette.previous = { mode: "info", hint: palette.hint };
|
|
85
|
+
palette.confirm = {
|
|
86
|
+
text: `Delete reminder "${sanitizeText(reminder.text).slice(0, 50)}"?`,
|
|
87
|
+
action: "reminder-delete",
|
|
88
|
+
data: { id: reminder.value },
|
|
89
|
+
};
|
|
90
|
+
palette.hint = "Enter or y deletes · n or Esc cancels";
|
|
91
|
+
this.touch();
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
async submitReminderPrompt(prompt, value) {
|
|
95
|
+
const palette = this.state.palette;
|
|
96
|
+
const room = this.state.current;
|
|
97
|
+
if (!palette || palette.mode !== "prompt") return;
|
|
98
|
+
if (!room) {
|
|
99
|
+
palette.error = "open a joined room first";
|
|
100
|
+
this.touch();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (prompt.action === "reminder-text") {
|
|
104
|
+
const text = String(value ?? "").trim();
|
|
105
|
+
if (!text) {
|
|
106
|
+
palette.error = "reminder text is required";
|
|
107
|
+
this.touch();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
palette.prompt = {
|
|
111
|
+
label: promptScheduleLabel(),
|
|
112
|
+
value: "",
|
|
113
|
+
action: "reminder-schedule",
|
|
114
|
+
data: { text },
|
|
115
|
+
};
|
|
116
|
+
palette.hint = "once ISO datetime or cron 5 fields · Enter create";
|
|
117
|
+
palette.error = "";
|
|
118
|
+
this.touch();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (prompt.action === "reminder-schedule") {
|
|
122
|
+
let schedule;
|
|
123
|
+
try {
|
|
124
|
+
schedule = parseReminderSchedule(value);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
palette.error = errorText(error);
|
|
127
|
+
this.touch();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
palette.searching = true;
|
|
131
|
+
palette.error = "";
|
|
132
|
+
this.touch();
|
|
133
|
+
try {
|
|
134
|
+
await this.api.createReminder(room.id, this.sessionID, prompt.data.text, schedule);
|
|
135
|
+
this.setStatus("reminder created", "success");
|
|
136
|
+
await this.openReminders();
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (this.state.palette === palette) {
|
|
139
|
+
palette.searching = false;
|
|
140
|
+
palette.error = errorText(error);
|
|
141
|
+
this.touch();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (prompt.action === "reminder-edit-text") {
|
|
147
|
+
const text = String(value ?? "").trim();
|
|
148
|
+
if (!text) {
|
|
149
|
+
palette.error = "reminder text is required";
|
|
150
|
+
this.touch();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
palette.searching = true;
|
|
154
|
+
palette.error = "";
|
|
155
|
+
this.touch();
|
|
156
|
+
try {
|
|
157
|
+
await this.api.updateReminder(room.id, prompt.data.id, this.sessionID, { text });
|
|
158
|
+
this.setStatus("reminder updated", "success");
|
|
159
|
+
await this.openReminders();
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (this.state.palette === palette) {
|
|
162
|
+
palette.searching = false;
|
|
163
|
+
palette.error = errorText(error);
|
|
164
|
+
this.touch();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
async runReminderConfirm(confirm) {
|
|
171
|
+
const palette = this.state.palette;
|
|
172
|
+
const room = this.state.current;
|
|
173
|
+
if (!palette || !room) return;
|
|
174
|
+
palette.searching = true;
|
|
175
|
+
this.touch();
|
|
176
|
+
try {
|
|
177
|
+
await this.api.deleteReminder(room.id, confirm.data.id, this.sessionID);
|
|
178
|
+
this.setStatus("reminder deleted", "success");
|
|
179
|
+
await this.openReminders();
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (this.state.palette === palette) {
|
|
182
|
+
palette.searching = false;
|
|
183
|
+
palette.error = errorText(error);
|
|
184
|
+
this.touch();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
}
|