Let bots take in messages sent while they reply
A reply read the session once at the start, so a message sent while it ran was never seen, and the follow-up reply queued for it then finished silently: the message was saved before the reply, so the thread ended with the bot. Those messages went unanswered. The text loop now reads new user messages after every round of tools and before an answer goes out, and the bot decides from what each one means whether it changes the work (folded in, or the unsent answer redrafted) or is a separate request, which it acknowledges at once with the new send_message tool and does after the current work. Messages sent that way are marked interim, so the thinking row stays up while the bot works. A reply job records the newest user message it read, and a queued reply only stays silent when a finished reply already read everything. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import type { BUN_SQLITE_COBBLE_BOT_MESSAGES } from "@/db/types/db";
|
||||
|
||||
type Params = {
|
||||
/**
|
||||
* The session's latest messages, oldest first.
|
||||
*/
|
||||
history: Pick<BUN_SQLITE_COBBLE_BOT_MESSAGES, "id" | "author">[];
|
||||
/**
|
||||
* The newest user message a finished reply answered
|
||||
* (`grabAnsweredMessageId`), null when none is on record.
|
||||
*/
|
||||
answered_id: number | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether a reply has anything left to answer. A user message that came in
|
||||
* while the last reply ran is saved before that reply, so the thread ends
|
||||
* with the bot's message even though the bot never read it: what the last
|
||||
* reply read decides, not who wrote last. Without a record (no reply has
|
||||
* finished in the session), the user having the last word does.
|
||||
*/
|
||||
export default function hasUnansweredMessage({ history, answered_id }: Params) {
|
||||
const user_ids = history
|
||||
.filter((message) => message.author == "user")
|
||||
.map((message) => Number(message.id));
|
||||
|
||||
if (!user_ids.length) return false;
|
||||
|
||||
if (answered_id) {
|
||||
return Math.max(...user_ids) > answered_id;
|
||||
}
|
||||
|
||||
return history[history.length - 1]?.author == "user";
|
||||
}
|
||||
Reference in New Issue
Block a user