okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0215-parked: chat: a parked message is sent only from the chat that is also the active one (#5806)7c11eb58b

main
1.6 KiB24 linesraw
1/** What Enter does when the person sends a message while the assistant is still answering (#4783). The web chat page has the same three. */
2export type WhileBusy = 'wait' | 'queue' | 'interject';
3export const WHILE_BUSY: readonly WhileBusy[] = ['wait', 'queue', 'interject'];
4export const validWhileBusy = (value: unknown): value is WhileBusy => WHILE_BUSY.includes(value as WhileBusy);
5
6/**
7 * What to do with the message, as one word:
8 *  - 'refuse'    Wait: nothing is sent until the answer is done (the message stays in the box, as always);
9 *  - 'goal'      Send after, while a goal runs: the host's own queue delivers it between steps (it asks the host first, so this is only a try);
10 *  - 'park'      Send after: the message waits here and goes when the answer is done;
11 *  - 'interrupt' Interrupt: the answer stops where it is (what is written stays) and the message goes as soon as it has stopped.
12 */
13export type BusyPlan = 'refuse' | 'goal' | 'park' | 'interrupt';
14export function busyPlan(mode: WhileBusy): BusyPlan {
15  return mode === 'queue' ? 'goal' : mode === 'interject' ? 'interrupt' : 'refuse';
16}
17
18/**
19 * #5806: may the chat on screen send its parked message now? Only when it is also the store's active chat, which is where sendMessage sends:
20 * a click in the side bar makes the other chat active before the page shows it, and in that moment the message went to the other chat.
21 */
22export function parkedReady(viewed: string | null | undefined, active: string | null | undefined, streaming: boolean, parked: number): boolean {
23  return !!viewed && viewed === active && !streaming && parked > 0;
24}