27 lines
913 B
TypeScript
27 lines
913 B
TypeScript
/** The bot marks a steering message with this reaction once it has picked it up. */
|
|
const SEEN_REACTION = "👀";
|
|
|
|
/**
|
|
* User messages sent after the active run started that the bot has not picked
|
|
* up yet. The run's own trigger message predates the run, so it never counts.
|
|
*/
|
|
export function queuedFollowUps<
|
|
T extends { id: string; role: string; createdAt?: string | undefined },
|
|
>(
|
|
messages: readonly T[],
|
|
runCreatedAt: string | undefined,
|
|
reactions: ReadonlyMap<string, ReadonlyMap<string, number>>,
|
|
): T[] {
|
|
if (!runCreatedAt) return [];
|
|
const runStart = Date.parse(runCreatedAt);
|
|
if (Number.isNaN(runStart)) return [];
|
|
return messages.filter(
|
|
(message) =>
|
|
message.role === "user" &&
|
|
!message.id.includes(":") &&
|
|
typeof message.createdAt === "string" &&
|
|
Date.parse(message.createdAt) > runStart &&
|
|
!reactions.get(message.id)?.has(SEEN_REACTION),
|
|
);
|
|
}
|