mom: Single accumulated message per run, exclude data dir from biome

This commit is contained in:
Mario Zechner 2025-11-26 01:21:45 +01:00
parent 9e0255b10b
commit 6117127b02
2 changed files with 42 additions and 33 deletions

View file

@ -36,6 +36,7 @@
"!**/node_modules/**/*", "!**/node_modules/**/*",
"!**/test-sessions.ts", "!**/test-sessions.ts",
"!packages/web-ui/src/app.css", "!packages/web-ui/src/app.css",
"!packages/mom/data/**/*",
"!!**/node_modules" "!!**/node_modules"
] ]
} }

View file

@ -177,7 +177,11 @@ export class MomBot {
// Process attachments (for context, already logged by message handler) // Process attachments (for context, already logged by message handler)
const attachments = event.files ? this.store.processAttachments(event.channel, event.files, event.ts) : []; const attachments = event.files ? this.store.processAttachments(event.channel, event.files, event.ts) : [];
let typingMessageTs: string | null = null; // Track the single message for this run
let messageTs: string | null = null;
let accumulatedText = "";
let isThinking = true; // Track if we're still in "thinking" state
let updatePromise: Promise<void> = Promise.resolve();
return { return {
message: { message: {
@ -190,46 +194,50 @@ export class MomBot {
}, },
store: this.store, store: this.store,
respond: async (responseText: string) => { respond: async (responseText: string) => {
let responseTs: string; // Queue updates to avoid race conditions
updatePromise = updatePromise.then(async () => {
if (isThinking) {
// First real response replaces "Thinking..."
accumulatedText = responseText;
isThinking = false;
} else {
// Subsequent responses get appended
accumulatedText += "\n" + responseText;
}
if (typingMessageTs) { if (messageTs) {
// Update the typing message with the response // Update existing message
await this.webClient.chat.update({ await this.webClient.chat.update({
channel: event.channel, channel: event.channel,
ts: typingMessageTs, ts: messageTs,
text: responseText, text: accumulatedText,
}); });
responseTs = typingMessageTs; } else {
typingMessageTs = null; // Post initial message
} else { const result = await this.webClient.chat.postMessage({
// Post a new message channel: event.channel,
const result = await this.webClient.chat.postMessage({ text: accumulatedText,
channel: event.channel, });
text: responseText, messageTs = result.ts as string;
}); }
responseTs = result.ts as string;
}
// Log the bot response // Log the response
await this.store.logBotResponse(event.channel, responseText, responseTs); await this.store.logBotResponse(event.channel, responseText, messageTs!);
});
await updatePromise;
}, },
setTyping: async (isTyping: boolean) => { setTyping: async (isTyping: boolean) => {
if (isTyping && !typingMessageTs) { if (isTyping && !messageTs) {
// Post a "thinking" message (italic) // Post initial "thinking" message
accumulatedText = "_Thinking..._";
const result = await this.webClient.chat.postMessage({ const result = await this.webClient.chat.postMessage({
channel: event.channel, channel: event.channel,
text: "_Thinking..._", text: accumulatedText,
}); });
typingMessageTs = result.ts as string; messageTs = result.ts as string;
} else if (!isTyping && typingMessageTs) {
// Clear typing state (message will be updated by respond())
// If respond() wasn't called, delete the typing message
await this.webClient.chat.delete({
channel: event.channel,
ts: typingMessageTs,
});
typingMessageTs = null;
} }
// We don't delete/clear anymore - message persists and gets updated
}, },
uploadFile: async (filePath: string, title?: string) => { uploadFile: async (filePath: string, title?: string) => {
const fileName = title || basename(filePath); const fileName = title || basename(filePath);