Skip to content

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

fix(chat): drop a finished exchange from the line over the message box

luishron123c7978b9738bc
diff --git a/src/components/BotExchangeLine.dom.test.ts b/src/components/BotExchangeLine.dom.test.ts
index 3766482469..b23d39e0bd 100644
--- a/src/components/BotExchangeLine.dom.test.ts
+++ b/src/components/BotExchangeLine.dom.test.ts
@@ -114,10 +114,7 @@ describe("the bot exchange line", () => {
it.each([
[{ status: "queued" }, "asking…"],
[{ status: "needs_input" }, "needs you"],
- [{ status: "completed", finishedAt: 52_000 }, "42s"],
- [{ status: "cancelled", outcome: "stopped", finishedAt: 22_000 }, "stopped · 12s"],
- [{ status: "failed", outcome: "expired", finishedAt: 70_000 }, "ran out of time · 1m"],
- [{ status: "failed", outcome: "error", finishedAt: 13_000 }, "didn't finish · 3s"],
+ [{ status: "waiting" }, "working…"],
] as const)("shows %o as %s", async (record, text) => {
current = job([root(), handoff(record)]);
render();
@@ -125,12 +122,34 @@ describe("the bot exchange line", () => {
expect(line()!.textContent).toBe(`PepperEngineer·${text}`);
});
- it("goes quiet once the bots are done: one read, nothing held, and a compact row for the finished exchange", async () => {
+ it("goes quiet once the bots are done: one read, nothing held, and no line left", async () => {
current = job([{ ...root(), status: "completed" }, handoff({ status: "completed", finishedAt: 52_000 })]);
render({ ...pepper, busy: false });
await settle();
expect(reads()).toHaveLength(1);
- expect(line()!.getAttribute("data-state")).toBe("answered");
+ expect(host.querySelector("[data-bot-exchange-line]")).toBeNull();
+ });
+
+ it.each([
+ [{ status: "completed", finishedAt: 52_000 }],
+ [{ status: "cancelled", outcome: "stopped", finishedAt: 22_000 }],
+ [{ status: "failed", outcome: "expired", finishedAt: 70_000 }],
+ [{ status: "failed", outcome: "error", finishedAt: 13_000 }],
+ ] as const)("drops an exchange from the line once it ends (%o), keeping the open ones", async (record) => {
+ current = job([root(), handoff({ id: "h0", createdAt: 9_000, ...record }), handoff()]);
+ render();
+ await settle();
+ expect(Array.from(host.querySelectorAll("[data-bot-exchange]")).map((chip) => chip.getAttribute("data-bot-exchange"))).toEqual(["h1"]);
+ });
+
+ it("takes a chip off the line when its exchange ends, and the line with it once none is open", async () => {
+ fixture.load.mockResolvedValue({ messages: [], activeLeafId: null });
+ await openExchange();
+ current = job([root(), handoff({ status: "cancelled", outcome: "stopped", finishedAt: 22_000 })], "v2");
+ flushSync(() => stopButton()!.click());
+ await settle();
+ flushSync(() => host.querySelector<HTMLButtonElement>("[data-exchange-back]")!.click());
+ expect(host.querySelector("[data-bot-exchange-line]")).toBeNull();
});
it("shows nothing when no bot handed anything on", async () => {
@@ -159,13 +178,10 @@ describe("an opened exchange", () => {
}
it("shows only that exchange's lines of the helper's thread", async () => {
- current = job([root(), handoff({ status: "completed", finishedAt: 30_000 })]);
fixture.load.mockResolvedValue({ messages: [line1, ask, reply, later], activeLeafId: "next" });
await openExchange();
expect(fixture.load).toHaveBeenCalledWith("work-1");
expect(shown()).toEqual(["PepperCount the rows", "EngineerThere are 12 rows"]);
- expect(status()!.textContent).toBe("Engineer answered in 20s");
- expect(stopButton()).toBeNull();
});
it("has Stop while the helper works, and shows the stop once the server has it", async () => {
@@ -227,7 +243,7 @@ describe("an opened exchange", () => {
it("gives each of two hand-offs that ran in turn in the same thread only its own lines", async () => {
const askB = request("ask-b", "Now the totals", 20_400, "reply", "h2");
const replyB: Message = { id: "reply-b", role: "bot", kind: "text", text: "The totals add up", at: 25_000, parentId: "ask-b" };
- current = job([root(), handoff({ status: "completed", finishedAt: 20_100 }), handoff({ id: "h2", createdAt: 20_300 })]);
+ current = job([root(), handoff(), handoff({ id: "h2", status: "queued", createdAt: 20_300 })]);
fixture.load.mockResolvedValue({ messages: [line1, ask, reply, askB, replyB], activeLeafId: "reply-b" });
await openOne("h2");
expect(shown()).toEqual(["PepperNow the totals", "EngineerThe totals add up"]);
@@ -238,7 +254,6 @@ describe("an opened exchange", () => {
});
it("says so, instead of guessing, when the hand-off's request line is not in the thread", async () => {
- current = job([root(), handoff({ status: "completed", finishedAt: 30_000 })]);
fixture.load.mockResolvedValue({ messages: [line1, reply], activeLeafId: "reply" });
await openExchange();
expect(shown()).toEqual([]);
diff --git a/src/components/BotExchangeLine.tsx b/src/components/BotExchangeLine.tsx
index e7837ad1d3..3c5ce5d823 100644
--- a/src/components/BotExchangeLine.tsx
+++ b/src/components/BotExchangeLine.tsx
@@ -1,4 +1,4 @@
-// The bots' exchanges for the person's request: a line over the message box while they work, a compact row once done.
+// The bots' exchanges for the person's request: a line over the message box while they work; an ended one leaves it.
import { use, useState } from "react";
import { ArrowLeftRight, Square } from "lucide-react";
import { BotAvatar, InitialsAvatar } from "./Avatar";
@@ -17,21 +17,15 @@ const took = (entry: BotExchangeEntry, now = Date.now()) =>
formatDuration(Math.max(1, Math.round(((entry.finishedAt ?? now) - entry.createdAt) / 1_000)) * 1_000);
function lineState(entry: BotExchangeEntry): string {
- switch (entry.state) {
- case "asking": return t("chat.botExchange.asking");
- case "working": return t("chat.botExchange.working");
- case "needs-you": return t("chat.botExchange.needsYou");
- case "answered": return took(entry);
- case "stopped": return `${t("chat.botExchange.stopped")} · ${took(entry)}`;
- case "expired": return `${t("chat.botExchange.expired")} · ${took(entry)}`;
- case "failed": return `${t("chat.botExchange.failed")} · ${took(entry)}`;
- }
+ if (entry.state === "asking") return t("chat.botExchange.asking");
+ return entry.state === "needs-you" ? t("chat.botExchange.needsYou") : t("chat.botExchange.working");
}
export function BotExchangeLine() {
- const { exchanges } = use(BotExchangesContext);
+ const { exchanges: all } = use(BotExchangesContext);
const open = use(OpenExchangeContext);
const bots = useStoreSelector((state) => state.bots);
+ const exchanges = all.filter((entry) => !exchangeEnded(entry.state));
if (!open || !exchanges.length) return null;
const botOf = (id: string | undefined) => id ? bots.find((candidate) => candidate.id === id) : undefined;
return (
@@ -53,8 +47,8 @@ export function BotExchangeLine() {
asker: { botId: entry.asker.botId ?? "", name: entry.asker.name, color: asker?.color },
helper: { botId: entry.helper.botId, name: entry.helper.name, color: helper?.color },
})}
- className={cn("pointer-events-auto flex h-8 min-w-0 max-w-full items-center gap-1.5 rounded-full ps-1.5 pe-3 text-[13px] leading-[18px]",
- ELEVATED_FLOAT, ELEVATED_TINT, exchangeEnded(entry.state) ? "text-ink-secondary" : "text-ink")}
+ className={cn("pointer-events-auto flex h-8 min-w-0 max-w-full items-center gap-1.5 rounded-full ps-1.5 pe-3 text-[13px] leading-[18px] text-ink",
+ ELEVATED_FLOAT, ELEVATED_TINT)}
>
<Face bot={asker} name={entry.asker.name} />
<span dir="auto" className="min-w-0 max-w-[160px] truncate font-medium">{entry.asker.name}</span>
diff --git a/src/locales/de.json b/src/locales/de.json
index dbf0716cba..4228688c74 100644
--- a/src/locales/de.json
+++ b/src/locales/de.json
@@ -4223,9 +4223,6 @@
"chat.botExchange.asking": "fragt…",
"chat.botExchange.working": "arbeitet…",
"chat.botExchange.needsYou": "braucht dich",
- "chat.botExchange.stopped": "gestoppt",
- "chat.botExchange.expired": "Zeit abgelaufen",
- "chat.botExchange.failed": "nicht fertig geworden",
"chat.botExchange.status.asking": "{asker} fragt {helper}…",
"chat.botExchange.status.working": "{helper} arbeitet daran…",
"chat.botExchange.status.needsYou": "{helper} wartet in seinem Gespräch auf deine Antwort",
diff --git a/src/locales/en.json b/src/locales/en.json
index 38d624003e..a72496cb96 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -11680,9 +11680,6 @@
"chat.botExchange.asking": "asking…",
"chat.botExchange.working": "working…",
"chat.botExchange.needsYou": "needs you",
- "chat.botExchange.stopped": "stopped",
- "chat.botExchange.expired": "ran out of time",
- "chat.botExchange.failed": "didn't finish",
"chat.botExchange.status.asking": "{asker} is asking {helper}…",
"chat.botExchange.status.working": "{helper} is working on it…",
"chat.botExchange.status.needsYou": "{helper} is waiting for your answer in its conversation",
diff --git a/src/locales/es.json b/src/locales/es.json
index d6c5c11fc8..799a9f1dc9 100644
--- a/src/locales/es.json
+++ b/src/locales/es.json
@@ -6573,9 +6573,6 @@
"chat.botExchange.asking": "preguntando…",
"chat.botExchange.working": "trabajando…",
"chat.botExchange.needsYou": "te necesita",
- "chat.botExchange.stopped": "detenido",
- "chat.botExchange.expired": "se acabó el tiempo",
- "chat.botExchange.failed": "no terminó",
"chat.botExchange.status.asking": "{asker} le está pidiendo a {helper}…",
"chat.botExchange.status.working": "{helper} está trabajando en ello…",
"chat.botExchange.status.needsYou": "{helper} espera tu respuesta en su conversación",
diff --git a/src/locales/fr.json b/src/locales/fr.json
index 6095914701..0abedc21c8 100644
--- a/src/locales/fr.json
+++ b/src/locales/fr.json
@@ -3978,9 +3978,6 @@
"chat.botExchange.asking": "demande…",
"chat.botExchange.working": "travaille…",
"chat.botExchange.needsYou": "a besoin de vous",
- "chat.botExchange.stopped": "arrêté",
- "chat.botExchange.expired": "temps écoulé",
- "chat.botExchange.failed": "n’a pas terminé",
"chat.botExchange.status.asking": "{asker} demande à {helper}…",
"chat.botExchange.status.working": "{helper} y travaille…",
"chat.botExchange.status.needsYou": "{helper} attend votre réponse dans sa conversation",
diff --git a/src/locales/hi.json b/src/locales/hi.json
index 0bddb29d28..65f4a04610 100644
--- a/src/locales/hi.json
+++ b/src/locales/hi.json
@@ -3830,9 +3830,6 @@
"chat.botExchange.asking": "पूछ रहा है…",
"chat.botExchange.working": "काम कर रहा है…",
"chat.botExchange.needsYou": "आपकी ज़रूरत है",
- "chat.botExchange.stopped": "रोका गया",
- "chat.botExchange.expired": "समय खत्म",
- "chat.botExchange.failed": "पूरा नहीं हुआ",
"chat.botExchange.status.asking": "{asker}, {helper} से पूछ रहा है…",
"chat.botExchange.status.working": "{helper} इस पर काम कर रहा है…",
"chat.botExchange.status.needsYou": "{helper} अपनी बातचीत में आपके जवाब का इंतज़ार कर रहा है",
diff --git a/src/locales/it.json b/src/locales/it.json
index 3dded0c699..2635a8b016 100644
--- a/src/locales/it.json
+++ b/src/locales/it.json
@@ -11462,9 +11462,6 @@
"chat.botExchange.asking": "sta chiedendo…",
"chat.botExchange.working": "al lavoro…",
"chat.botExchange.needsYou": "ha bisogno di te",
- "chat.botExchange.stopped": "fermato",
- "chat.botExchange.expired": "tempo scaduto",
- "chat.botExchange.failed": "non ha finito",
"chat.botExchange.status.asking": "{asker} sta chiedendo a {helper}…",
"chat.botExchange.status.working": "{helper} ci sta lavorando…",
"chat.botExchange.status.needsYou": "{helper} aspetta la tua risposta nella sua conversazione",
diff --git a/src/locales/ja.json b/src/locales/ja.json
index 02829f1a8f..3af5a7e16e 100644
--- a/src/locales/ja.json
+++ b/src/locales/ja.json
@@ -8108,9 +8108,6 @@
"chat.botExchange.asking": "依頼中…",
"chat.botExchange.working": "作業中…",
"chat.botExchange.needsYou": "対応が必要",
- "chat.botExchange.stopped": "停止しました",
- "chat.botExchange.expired": "時間切れ",
- "chat.botExchange.failed": "完了できませんでした",
"chat.botExchange.status.asking": "{asker} が {helper} に依頼しています…",
"chat.botExchange.status.working": "{helper} が作業しています…",
"chat.botExchange.status.needsYou": "{helper} が会話であなたの返答を待っています",
diff --git a/src/locales/ko.json b/src/locales/ko.json
index 462894f008..4c0ba4e7af 100644
--- a/src/locales/ko.json
+++ b/src/locales/ko.json
@@ -7798,9 +7798,6 @@
"chat.botExchange.asking": "요청 중…",
"chat.botExchange.working": "작업 중…",
"chat.botExchange.needsYou": "확인 필요",
- "chat.botExchange.stopped": "중지됨",
- "chat.botExchange.expired": "시간 초과",
- "chat.botExchange.failed": "완료하지 못함",
"chat.botExchange.status.asking": "{asker}가 {helper}에게 요청하는 중…",
"chat.botExchange.status.working": "{helper}가 작업하는 중…",
"chat.botExchange.status.needsYou": "{helper}가 대화에서 답변을 기다리고 있어요",
diff --git a/src/locales/pl.json b/src/locales/pl.json
index d592629f1e..a808d03dd0 100644
--- a/src/locales/pl.json
+++ b/src/locales/pl.json
@@ -7269,9 +7269,6 @@
"chat.botExchange.asking": "pyta…",
"chat.botExchange.working": "pracuje…",
"chat.botExchange.needsYou": "potrzebuje ciebie",
- "chat.botExchange.stopped": "zatrzymano",
- "chat.botExchange.expired": "czas minął",
- "chat.botExchange.failed": "nie skończył",
"chat.botExchange.status.asking": "{asker} prosi {helper}…",
"chat.botExchange.status.working": "{helper} nad tym pracuje…",
"chat.botExchange.status.needsYou": "{helper} czeka na twoją odpowiedź w swojej rozmowie",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 88a98b9c8c..65c7ff203a 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -11680,9 +11680,6 @@
"chat.botExchange.asking": "pedindo…",
"chat.botExchange.working": "trabalhando…",
"chat.botExchange.needsYou": "precisa de você",
- "chat.botExchange.stopped": "parado",
- "chat.botExchange.expired": "tempo esgotado",
- "chat.botExchange.failed": "não terminou",
"chat.botExchange.status.asking": "{asker} está pedindo a {helper}…",
"chat.botExchange.status.working": "{helper} está trabalhando nisso…",
"chat.botExchange.status.needsYou": "{helper} está esperando sua resposta na conversa dele",
diff --git a/src/locales/ru.json b/src/locales/ru.json
index 2033ee3d3f..8ca556d745 100644
--- a/src/locales/ru.json
+++ b/src/locales/ru.json
@@ -7323,9 +7323,6 @@
"chat.botExchange.asking": "спрашивает…",
"chat.botExchange.working": "работает…",
"chat.botExchange.needsYou": "нужны вы",
- "chat.botExchange.stopped": "остановлено",
- "chat.botExchange.expired": "время вышло",
- "chat.botExchange.failed": "не закончил",
"chat.botExchange.status.asking": "{asker} просит {helper}…",
"chat.botExchange.status.working": "{helper} работает над этим…",
"chat.botExchange.status.needsYou": "{helper} ждёт вашего ответа в своём разговоре",
diff --git a/src/locales/tr.json b/src/locales/tr.json
index 5d1bf6b128..6acd555d80 100644
--- a/src/locales/tr.json
+++ b/src/locales/tr.json
@@ -6068,9 +6068,6 @@
"chat.botExchange.asking": "soruyor…",
"chat.botExchange.working": "çalışıyor…",
"chat.botExchange.needsYou": "sana ihtiyacı var",
- "chat.botExchange.stopped": "durduruldu",
- "chat.botExchange.expired": "süre doldu",
- "chat.botExchange.failed": "bitiremedi",
"chat.botExchange.status.asking": "{asker}, {helper} ile konuşuyor…",
"chat.botExchange.status.working": "{helper} bunun üzerinde çalışıyor…",
"chat.botExchange.status.needsYou": "{helper} kendi konuşmasında yanıtını bekliyor",
diff --git a/src/locales/uk.json b/src/locales/uk.json
index 031783b0e8..f30a62566b 100644
--- a/src/locales/uk.json
+++ b/src/locales/uk.json
@@ -4250,9 +4250,6 @@
"chat.botExchange.asking": "запитує…",
"chat.botExchange.working": "працює…",
"chat.botExchange.needsYou": "потрібні ви",
- "chat.botExchange.stopped": "зупинено",
- "chat.botExchange.expired": "час вийшов",
- "chat.botExchange.failed": "не завершив",
"chat.botExchange.status.asking": "{asker} просить {helper}…",
"chat.botExchange.status.working": "{helper} працює над цим…",
"chat.botExchange.status.needsYou": "{helper} чекає на вашу відповідь у своїй розмові",
diff --git a/src/locales/vi.json b/src/locales/vi.json
index d2886ff915..3b41101d2f 100644
--- a/src/locales/vi.json
+++ b/src/locales/vi.json
@@ -6068,9 +6068,6 @@
"chat.botExchange.asking": "đang hỏi…",
"chat.botExchange.working": "đang làm…",
"chat.botExchange.needsYou": "cần bạn",
- "chat.botExchange.stopped": "đã dừng",
- "chat.botExchange.expired": "hết thời gian",
- "chat.botExchange.failed": "chưa xong",
"chat.botExchange.status.asking": "{asker} đang nhờ {helper}…",
"chat.botExchange.status.working": "{helper} đang làm việc này…",
"chat.botExchange.status.needsYou": "{helper} đang chờ bạn trả lời trong cuộc trò chuyện của nó",
diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.json
index 88c990a449..bf158e19eb 100644
--- a/src/locales/zh-tw.json
+++ b/src/locales/zh-tw.json
@@ -10384,9 +10384,6 @@
"chat.botExchange.asking": "正在詢問…",
"chat.botExchange.working": "正在處理…",
"chat.botExchange.needsYou": "需要你",
- "chat.botExchange.stopped": "已停止",
- "chat.botExchange.expired": "已逾時",
- "chat.botExchange.failed": "未完成",
"chat.botExchange.status.asking": "{asker} 正在請 {helper} 幫忙…",
"chat.botExchange.status.working": "{helper} 正在處理…",
"chat.botExchange.status.needsYou": "{helper} 正在它的對話中等你回覆",
diff --git a/src/locales/zh.json b/src/locales/zh.json
index d85e71f9c2..f9bf121252 100644
--- a/src/locales/zh.json
+++ b/src/locales/zh.json
@@ -10297,9 +10297,6 @@
"chat.botExchange.asking": "正在询问…",
"chat.botExchange.working": "正在处理…",
"chat.botExchange.needsYou": "需要你",
- "chat.botExchange.stopped": "已停止",
- "chat.botExchange.expired": "已超时",
- "chat.botExchange.failed": "未完成",
"chat.botExchange.status.asking": "{asker} 正在请 {helper} 帮忙…",
"chat.botExchange.status.working": "{helper} 正在处理…",
"chat.botExchange.status.needsYou": "{helper} 正在它的对话中等你回复",