Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Chat: say when a running turn has sent nothing for a while

Krishna Dobhalc62fd79b5f8b
diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx
index 2b4a032f18..9c5ecd07a5 100644
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@ -1216,6 +1216,7 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
className={cn(!advanced && presenceUnderBubble && SIMPLE_STACKED)}
label={teammatesWorking ? t("chat.teammatesWorking") : sharedRun.label}
visible={presenceVisible}
+ threadId={bot.threadId}
{...now}
phrases={teammatesWorking ? undefined : now.phrases}
seed={`${bot.id}:${bot.threadId ?? ""}:${busySince ?? ""}`}
diff --git a/src/components/GroupView.tsx b/src/components/GroupView.tsx
index b17747b302..383ebbb1c6 100644
--- a/src/components/GroupView.tsx
+++ b/src/components/GroupView.tsx
@@ -1159,6 +1159,7 @@ export function GroupView({ group, inForkPanel = false }: { group: Group; inFork
/>
}
visible={presenceVisible}
+ threadId={group.threadId}
phrases={activity?.phrases}
phase={activity?.phase}
size={activity?.size} hover={activity?.hover} quiet={live.status && "quiet" in live.status ? live.status.quiet : undefined}
diff --git a/src/components/TurnPresence.tsx b/src/components/TurnPresence.tsx
index bc70cbcb1d..c8d2f2046b 100644
--- a/src/components/TurnPresence.tsx
+++ b/src/components/TurnPresence.tsx
@@ -3,7 +3,8 @@ import { ChevronDown } from "lucide-react";
import { cn } from "@/lib/cn";
import { WorkingTimer } from "@/components/WorkingIndicator";
import { phraseAt, phraseHoldMs } from "@/lib/live-activity";
-import { quietText } from "@/lib/now-steps";
+import { quietText, silenceText } from "@/lib/now-steps";
+import { lastFrameAt } from "@/state/turn-status";
import { t } from "@/lib/i18n";
import { formatElapsed } from "@/lib/working-time";
import type { StepQuiet } from "../../shared/turn-progress";
@@ -69,6 +70,18 @@ function QuietPart({ quiet }: { quiet: StepQuiet }) {
return <><Dot /><span data-turn-quiet="" className="text-[12px] text-ink-tertiary">{quietText(quiet, now)}</span></>;
}
+/** "nothing new for 5 min" when the whole turn has gone silent, counted from the last frame this window saw. */
+function SilencePart({ threadId }: { threadId: string }) {
+ const [watchedFrom] = useState(() => Date.now());
+ const [now, setNow] = useState(() => Date.now());
+ useEffect(() => {
+ const timer = setInterval(() => setNow(Date.now()), 15_000);
+ return () => clearInterval(timer);
+ }, []);
+ const text = silenceText(lastFrameAt(threadId) ?? watchedFrom, now);
+ return text ? <><Dot /><span data-turn-silent="" className="text-[12px] text-ink-tertiary">{text}</span></> : null;
+}
+
/** The turn's live status line: "Working · 1m 12s · Running scrape.py · busy, no output yet". The lead word and the
* timer stay for the whole turn; `phrases` say what is happening now and rotate through their alternates; `size` is how
* much of the file is written; `quiet` is how a long step is doing. With nothing to say the line is the lead and the timer
@@ -88,6 +101,7 @@ export function TurnPresence({
detail,
hover,
quiet,
+ threadId,
card,
cardLabel,
className,
@@ -107,6 +121,8 @@ export function TurnPresence({
/** The whole command, query or address behind the phrase. */
hover?: string;
quiet?: StepQuiet;
+ /** The thread whose live frames tell whether the turn has gone silent. */
+ threadId?: string;
card?: ReactNode;
cardLabel?: string;
className?: string;
@@ -201,6 +217,7 @@ export function TurnPresence({
{quiet && <QuietPart quiet={quiet} />}
</>
)}
+ {threadId && !quiet && <SilencePart threadId={threadId} />}
</span>
) : null;
return (
diff --git a/src/lib/now-steps.test.ts b/src/lib/now-steps.test.ts
index c4365b0d26..9dc78547ad 100644
--- a/src/lib/now-steps.test.ts
+++ b/src/lib/now-steps.test.ts
@@ -1,7 +1,15 @@
import { describe, expect, it } from "vitest";
import type { Message } from "@/state/store";
-import { nowSteps, quietText, stepLabel } from "./now-steps";
+import { nowSteps, quietText, silenceText, stepLabel } from "./now-steps";
+
+describe("a turn that has gone silent", () => {
+ it("says nothing for the first two minutes, then counts minutes and hours", () => {
+ expect(silenceText(0, 119_000)).toBeUndefined();
+ expect(silenceText(0, 5 * 60_000)).toBe("nothing new for 5 min");
+ expect(silenceText(0, 125 * 60_000)).toBe("nothing new for 2 h");
+ });
+});
let id = 0;
const ask = (text: string, extra: Partial<Message> = {}): Message => ({ id: `u${++id}`, role: "user", kind: "text", at: id, text, ...extra });
diff --git a/src/lib/now-steps.ts b/src/lib/now-steps.ts
index 2616d773e3..5bd46c8bef 100644
--- a/src/lib/now-steps.ts
+++ b/src/lib/now-steps.ts
@@ -79,3 +79,14 @@ export function quietText(quiet: StepQuiet | undefined, now: number): string | u
if (minutes < 60) return t("chat.liveness.outputMinutes", { count: minutes });
return t("chat.liveness.outputHours", { count: Math.floor(minutes / 60) });
}
+
+export const SILENCE_SHOWN_MS = 2 * 60_000;
+
+/** "nothing new for 5 min" once the whole turn has sent no frame for a while; nothing before that. */
+export function silenceText(lastFrame: number, now: number): string | undefined {
+ const quietMs = now - lastFrame;
+ if (quietMs < SILENCE_SHOWN_MS) return undefined;
+ const minutes = Math.floor(quietMs / 60_000);
+ if (minutes < 60) return t("chat.liveness.silentMinutes", { count: minutes });
+ return t("chat.liveness.silentHours", { count: Math.floor(minutes / 60) });
+}
diff --git a/src/locales/de.json b/src/locales/de.json
index 2ee96f2002..b74bacd7bd 100644
--- a/src/locales/de.json
+++ b/src/locales/de.json
@@ -1093,6 +1093,8 @@
"chat.liveness.outputJustNow": "letzte Ausgabe gerade eben",
"chat.liveness.outputMinutes": "letzte Ausgabe vor {count} Min.",
"chat.liveness.outputHours": "letzte Ausgabe vor {count} Std.",
+ "chat.liveness.silentMinutes": "seit {count} Min. nichts Neues",
+ "chat.liveness.silentHours": "seit {count} Std. nichts Neues",
"chat.liveness.network": "wartet auf das Netzwerk",
"chat.liveness.busy": "beschäftigt, noch keine Ausgabe",
"chat.liveness.idle": "im Leerlauf, noch keine Ausgabe",
diff --git a/src/locales/en.json b/src/locales/en.json
index b039eb520f..635d4ab947 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2900,6 +2900,8 @@
"chat.liveness.outputJustNow": "last output just now",
"chat.liveness.outputMinutes": "last output {count} min ago",
"chat.liveness.outputHours": "last output {count} h ago",
+ "chat.liveness.silentMinutes": "nothing new for {count} min",
+ "chat.liveness.silentHours": "nothing new for {count} h",
"chat.liveness.network": "waiting on the network",
"chat.liveness.busy": "busy, no output yet",
"chat.liveness.idle": "idle, no output yet",
diff --git a/src/locales/es.json b/src/locales/es.json
index ad50a259a0..7ab2a4ad2a 100644
--- a/src/locales/es.json
+++ b/src/locales/es.json
@@ -2118,6 +2118,8 @@
"chat.liveness.outputJustNow": "última salida hace un momento",
"chat.liveness.outputMinutes": "última salida hace {count} min",
"chat.liveness.outputHours": "última salida hace {count} h",
+ "chat.liveness.silentMinutes": "nada nuevo desde hace {count} min",
+ "chat.liveness.silentHours": "nada nuevo desde hace {count} h",
"chat.liveness.network": "esperando a la red",
"chat.liveness.busy": "ocupado, aún sin salida",
"chat.liveness.idle": "inactivo, aún sin salida",
diff --git a/src/locales/fr.json b/src/locales/fr.json
index 7a87e9bcf6..5120373b4b 100644
--- a/src/locales/fr.json
+++ b/src/locales/fr.json
@@ -916,6 +916,8 @@
"chat.liveness.outputJustNow": "dernière sortie à l’instant",
"chat.liveness.outputMinutes": "dernière sortie il y a {count} min",
"chat.liveness.outputHours": "dernière sortie il y a {count} h",
+ "chat.liveness.silentMinutes": "rien de nouveau depuis {count} min",
+ "chat.liveness.silentHours": "rien de nouveau depuis {count} h",
"chat.liveness.network": "attend le réseau",
"chat.liveness.busy": "occupé, pas encore de sortie",
"chat.liveness.idle": "inactif, pas encore de sortie",
diff --git a/src/locales/hi.json b/src/locales/hi.json
index 587f6505c8..008011d3b8 100644
--- a/src/locales/hi.json
+++ b/src/locales/hi.json
@@ -916,6 +916,8 @@
"chat.liveness.outputJustNow": "आखिरी आउटपुट अभी-अभी",
"chat.liveness.outputMinutes": "आखिरी आउटपुट {count} मिनट पहले",
"chat.liveness.outputHours": "आखिरी आउटपुट {count} घंटे पहले",
+ "chat.liveness.silentMinutes": "{count} मिनट से कुछ नया नहीं",
+ "chat.liveness.silentHours": "{count} घंटे से कुछ नया नहीं",
"chat.liveness.network": "नेटवर्क का इंतज़ार कर रहा है",
"chat.liveness.busy": "व्यस्त, अभी तक कोई आउटपुट नहीं",
"chat.liveness.idle": "निष्क्रिय, अभी तक कोई आउटपुट नहीं",
diff --git a/src/locales/it.json b/src/locales/it.json
index 87053dc525..0e4d6161cd 100644
--- a/src/locales/it.json
+++ b/src/locales/it.json
@@ -2205,6 +2205,8 @@
"chat.liveness.outputJustNow": "ultimo output poco fa",
"chat.liveness.outputMinutes": "ultimo output {count} min fa",
"chat.liveness.outputHours": "ultimo output {count} h fa",
+ "chat.liveness.silentMinutes": "niente di nuovo da {count} min",
+ "chat.liveness.silentHours": "niente di nuovo da {count} h",
"chat.liveness.network": "in attesa della rete",
"chat.liveness.busy": "occupato, ancora nessun output",
"chat.liveness.idle": "inattivo, ancora nessun output",
diff --git a/src/locales/ja.json b/src/locales/ja.json
index 48db1728b1..a983c62244 100644
--- a/src/locales/ja.json
+++ b/src/locales/ja.json
@@ -2533,6 +2533,8 @@
"chat.liveness.outputJustNow": "最後の出力:たった今",
"chat.liveness.outputMinutes": "最後の出力:{count} 分前",
"chat.liveness.outputHours": "最後の出力:{count} 時間前",
+ "chat.liveness.silentMinutes": "{count} 分間、新しい動きなし",
+ "chat.liveness.silentHours": "{count} 時間、新しい動きなし",
"chat.liveness.network": "ネットワーク待ち",
"chat.liveness.busy": "処理中、まだ出力なし",
"chat.liveness.idle": "待機中、まだ出力なし",
diff --git a/src/locales/ko.json b/src/locales/ko.json
index d6694bd7bf..99b15d9743 100644
--- a/src/locales/ko.json
+++ b/src/locales/ko.json
@@ -2422,6 +2422,8 @@
"chat.liveness.outputJustNow": "방금 마지막 출력",
"chat.liveness.outputMinutes": "{count}분 전 마지막 출력",
"chat.liveness.outputHours": "{count}시간 전 마지막 출력",
+ "chat.liveness.silentMinutes": "{count}분째 새 소식 없음",
+ "chat.liveness.silentHours": "{count}시간째 새 소식 없음",
"chat.liveness.network": "네트워크 대기 중",
"chat.liveness.busy": "바쁨, 아직 출력 없음",
"chat.liveness.idle": "대기 중, 아직 출력 없음",
diff --git a/src/locales/pl.json b/src/locales/pl.json
index 0a7c21e14f..61d12cf275 100644
--- a/src/locales/pl.json
+++ b/src/locales/pl.json
@@ -2248,6 +2248,8 @@
"chat.liveness.outputJustNow": "ostatnie wyjście przed chwilą",
"chat.liveness.outputMinutes": "ostatnie wyjście {count} min temu",
"chat.liveness.outputHours": "ostatnie wyjście {count} godz. temu",
+ "chat.liveness.silentMinutes": "nic nowego od {count} min",
+ "chat.liveness.silentHours": "nic nowego od {count} godz.",
"chat.liveness.network": "czeka na sieć",
"chat.liveness.busy": "zajęty, jeszcze bez wyjścia",
"chat.liveness.idle": "bezczynny, jeszcze bez wyjścia",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index b23cf93af5..d1decd8909 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -2727,6 +2727,8 @@
"chat.liveness.outputJustNow": "última saída agora mesmo",
"chat.liveness.outputMinutes": "última saída há {count} min",
"chat.liveness.outputHours": "última saída há {count} h",
+ "chat.liveness.silentMinutes": "nada de novo há {count} min",
+ "chat.liveness.silentHours": "nada de novo há {count} h",
"chat.liveness.network": "aguardando a rede",
"chat.liveness.busy": "em atividade, sem saída ainda",
"chat.liveness.idle": "sem atividade, sem saída ainda",
diff --git a/src/locales/ru.json b/src/locales/ru.json
index c2fec6004b..06e3d5e582 100644
--- a/src/locales/ru.json
+++ b/src/locales/ru.json
@@ -2282,6 +2282,8 @@
"chat.liveness.outputJustNow": "последний вывод только что",
"chat.liveness.outputMinutes": "последний вывод {count} мин назад",
"chat.liveness.outputHours": "последний вывод {count} ч назад",
+ "chat.liveness.silentMinutes": "ничего нового уже {count} мин",
+ "chat.liveness.silentHours": "ничего нового уже {count} ч",
"chat.liveness.network": "ждёт сеть",
"chat.liveness.busy": "занят, вывода пока нет",
"chat.liveness.idle": "простаивает, вывода пока нет",
diff --git a/src/locales/tr.json b/src/locales/tr.json
index 5ba8e01832..aba964a986 100644
--- a/src/locales/tr.json
+++ b/src/locales/tr.json
@@ -1821,6 +1821,8 @@
"chat.liveness.outputJustNow": "son çıktı az önce",
"chat.liveness.outputMinutes": "son çıktı {count} dk önce",
"chat.liveness.outputHours": "son çıktı {count} sa önce",
+ "chat.liveness.silentMinutes": "{count} dakikadır yeni bir şey yok",
+ "chat.liveness.silentHours": "{count} saattir yeni bir şey yok",
"chat.liveness.network": "ağı bekliyor",
"chat.liveness.busy": "meşgul, henüz çıktı yok",
"chat.liveness.idle": "boşta, henüz çıktı yok",
diff --git a/src/locales/uk.json b/src/locales/uk.json
index f0a63ce406..b2ae81ccde 100644
--- a/src/locales/uk.json
+++ b/src/locales/uk.json
@@ -1077,6 +1077,8 @@
"chat.liveness.outputJustNow": "останній вивід щойно",
"chat.liveness.outputMinutes": "останній вивід {count} хв тому",
"chat.liveness.outputHours": "останній вивід {count} год тому",
+ "chat.liveness.silentMinutes": "нічого нового вже {count} хв",
+ "chat.liveness.silentHours": "нічого нового вже {count} год",
"chat.liveness.network": "чекає на мережу",
"chat.liveness.busy": "зайнятий, виводу ще немає",
"chat.liveness.idle": "простоює, виводу ще немає",
diff --git a/src/locales/vi.json b/src/locales/vi.json
index 580b5f0854..801aea0e80 100644
--- a/src/locales/vi.json
+++ b/src/locales/vi.json
@@ -1821,6 +1821,8 @@
"chat.liveness.outputJustNow": "đầu ra gần nhất: vừa xong",
"chat.liveness.outputMinutes": "đầu ra gần nhất: {count} phút trước",
"chat.liveness.outputHours": "đầu ra gần nhất: {count} giờ trước",
+ "chat.liveness.silentMinutes": "không có gì mới trong {count} phút",
+ "chat.liveness.silentHours": "không có gì mới trong {count} giờ",
"chat.liveness.network": "đang chờ mạng",
"chat.liveness.busy": "đang bận, chưa có đầu ra",
"chat.liveness.idle": "đang rảnh, chưa có đầu ra",
diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.json
index e6fc38f881..4e6fa21d29 100644
--- a/src/locales/zh-tw.json
+++ b/src/locales/zh-tw.json
@@ -2710,6 +2710,8 @@
"chat.liveness.outputJustNow": "最近輸出:剛剛",
"chat.liveness.outputMinutes": "最近輸出:{count} 分鐘前",
"chat.liveness.outputHours": "最近輸出:{count} 小時前",
+ "chat.liveness.silentMinutes": "已 {count} 分鐘沒有新動靜",
+ "chat.liveness.silentHours": "已 {count} 小時沒有新動靜",
"chat.liveness.network": "正在等待網路",
"chat.liveness.busy": "忙碌中,尚無輸出",
"chat.liveness.idle": "閒置中,尚無輸出",
diff --git a/src/locales/zh.json b/src/locales/zh.json
index 02583b3f9e..42effb4d3a 100644
--- a/src/locales/zh.json
+++ b/src/locales/zh.json
@@ -2771,6 +2771,8 @@
"chat.liveness.outputJustNow": "最近输出:刚刚",
"chat.liveness.outputMinutes": "最近输出:{count} 分钟前",
"chat.liveness.outputHours": "最近输出:{count} 小时前",
+ "chat.liveness.silentMinutes": "已 {count} 分钟没有新动静",
+ "chat.liveness.silentHours": "已 {count} 小时没有新动静",
"chat.liveness.network": "正在等待网络",
"chat.liveness.busy": "忙碌中,尚无输出",
"chat.liveness.idle": "空闲,尚无输出",
diff --git a/src/state/turn-status.test.ts b/src/state/turn-status.test.ts
index 676935eed8..d65960ba34 100644
--- a/src/state/turn-status.test.ts
+++ b/src/state/turn-status.test.ts
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it } from "vitest";
import type { RuntimeEvent } from "../../shared/runtime-events";
-import { noteTurnEvent, resetTurnLive, turnLive } from "./turn-status";
+import { lastFrameAt, noteTurnEvent, resetTurnLive, turnLive } from "./turn-status";
let seq = 0;
const note = (event: Partial<RuntimeEvent>, threadId = "t") =>
@@ -9,6 +9,19 @@ const note = (event: Partial<RuntimeEvent>, threadId = "t") =>
afterEach(() => resetTurnLive());
+describe("a thread's last frame", () => {
+ it("stamps every frame, even one that changes nothing on the line", () => {
+ expect(lastFrameAt("t")).toBeUndefined();
+ note({ type: "content.delta", streamKind: "assistant_text", delta: "a" } as Partial<RuntimeEvent>);
+ const first = lastFrameAt("t")!;
+ expect(first).toBeGreaterThan(0);
+ const status = turnLive("t");
+ note({ type: "content.delta", streamKind: "assistant_text", delta: "b" } as Partial<RuntimeEvent>);
+ expect(lastFrameAt("t")).toBeGreaterThanOrEqual(first);
+ expect(turnLive("t"), "the line's state is untouched, so nothing re-renders").toBe(status);
+ });
+});
+
describe("a thread's live turn", () => {
it("knows nothing before any frame", () => {
expect(turnLive("t")).toEqual({ ended: false, status: null });
diff --git a/src/state/turn-status.ts b/src/state/turn-status.ts
index 151986285b..7960c70891 100644
--- a/src/state/turn-status.ts
+++ b/src/state/turn-status.ts
@@ -20,6 +20,7 @@ export interface TurnLive {
const UNKNOWN: TurnLive = { ended: false, status: null };
const MAX_THREADS = 500;
const threads = new Map<string, TurnLive>();
+const lastFrames = new Map<string, number>();
const listeners = new Map<string, Set<() => void>>();
function sameStatus(a: LiveStatus | null, b: LiveStatus | null): boolean {
@@ -41,6 +42,9 @@ function put(threadId: string, next: TurnLive): void {
* the status describes: "Writing index.html · 14 KB" outlasts the call's own chip until the call finishes. */
export function noteTurnEvent(event: RuntimeEvent): void {
const { threadId } = event;
+ lastFrames.delete(threadId);
+ lastFrames.set(threadId, Date.now());
+ if (lastFrames.size > MAX_THREADS) lastFrames.delete(lastFrames.keys().next().value!);
const current = threads.get(threadId);
const sameTurn = current && (!event.turnId || event.turnId === current.turnId);
const turnId = event.turnId ?? current?.turnId;
@@ -75,6 +79,11 @@ export function turnLive(threadId: string | null | undefined): TurnLive {
return (threadId && threads.get(threadId)) || UNKNOWN;
}
+/** When this thread last sent any live frame. Read on a clock rather than subscribed, so streamed text never re-renders. */
+export function lastFrameAt(threadId: string | null | undefined): number | undefined {
+ return threadId ? lastFrames.get(threadId) : undefined;
+}
+
function subscribe(threadId: string | null | undefined, listener: () => void): () => void {
if (!threadId) return () => {};
let set = listeners.get(threadId);
@@ -97,4 +106,5 @@ export function useTurnLive(threadId: string | null | undefined): TurnLive {
/** Tests only. */
export function resetTurnLive(): void {
threads.clear();
+ lastFrames.clear();
}