Skip to content

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

Rooms: bigger sender name in the bot's colour, with "Sender → Addressee"

AdityaUmaleae4a1c4663ac
diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx
index 8d8712cc09..1c1b60506b 100644
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@ -606,13 +606,13 @@ function PeerLabel({ peer }: { peer: PeerLine }) {
<BotAvatar
bot={author ?? { name: peer.name, color: "blue" }}
state={normalizeState(author?.mascotExpression) ?? "happy"}
- size={16}
+ size={20}
motion="none"
motionKey={0}
animated={false}
/>
- <span className="text-[11px] font-medium text-ink-secondary">{peer.name}</span>
- <span className="text-[11px] text-ink-tertiary">· {how}</span>
+ <span className={cn("text-[13px] font-semibold", author ? "bot-identity" : "text-ink-secondary")} data-bot-color={author?.color}>{peer.name}</span>
+ <span className="text-[12px] text-ink-tertiary">· {how}</span>
</div>
);
}
diff --git a/src/components/GroupView.speaker.test.ts b/src/components/GroupView.speaker.test.ts
index f1eaa0bccc..851ab6a89b 100644
--- a/src/components/GroupView.speaker.test.ts
+++ b/src/components/GroupView.speaker.test.ts
@@ -57,7 +57,7 @@ describe("room speaker names", () => {
]);
expect(html.match(/data-bot-color="blue"/g)).toHaveLength(1);
expect(html.match(/data-bot-color="orange"/g)).toHaveLength(1);
- expect(html).toContain('class="text-[11px] font-medium bot-identity" data-bot-color="blue"');
+ expect(html).toContain('class="text-[13px] font-semibold bot-identity" data-bot-color="blue"');
expect(html).toContain(">Ada<");
expect(html).toContain(">Kai<");
expect(html).toContain("var(--identity-blue)");
@@ -80,4 +80,14 @@ describe("room speaker names", () => {
expect(html).toContain('data-bot-color="blue"');
expect(html).toContain("the notes are in");
});
+
+ it("shows who a bot speaks to, in that bot's colour", () => {
+ const html = markup([
+ line("u", "user", "@Ada check it"),
+ line("a", "bot", "Sure. @Kai, can you draw it?", { botId: "ada", name: "Ada", color: "blue" }),
+ line("k", "bot", "here", { botId: "kai", name: "Kai", color: "orange" }),
+ ]);
+ expect(html).toMatch(/>Ada<\/span><span[^>]*>→<\/span><span class="text-\[13px\] font-semibold bot-identity" data-bot-color="orange">Kai</);
+ expect(html.match(/→/g)).toHaveLength(1);
+ });
});
diff --git a/src/components/GroupView.tsx b/src/components/GroupView.tsx
index 3f3a797a02..58e01a33d2 100644
--- a/src/components/GroupView.tsx
+++ b/src/components/GroupView.tsx
@@ -28,7 +28,7 @@ import { CompactionChip, DigestChip } from "./DigestChip";
import { roomActivityVisible } from "@/lib/room-activity";
import { StatusActivityRow } from "@/components/StatusActivityRow"; import { BugReportNote } from "@/components/BugReportNote";
import { normalizeState } from "@/lib/mascot";
-import { botTextShowsSpeaker, laterTextOwns, runShowsSpeaker } from "@/lib/room-speaker";
+import { botTextShowsSpeaker, laterTextOwns, runShowsSpeaker } from "@/lib/room-speaker"; import { roomAddressees } from "@/lib/room-addressees";
import { defaultResponderName, groupResponseHint, jevRoomRoutingOn } from "@/lib/group-routing";
import { ChatMarkdown } from "./ChatMarkdown";
import { FailedTurnRow, MessageBoundary } from "./ChatView";
@@ -490,7 +490,7 @@ export const Transcript = memo(function Transcript({
(m.kind === "text" && botTextShowsSpeaker(items, i))
|| (!user && m.kind !== "text" && newCluster && !(m.kind === "activity" && m.comm) && !laterTextOwns(items, i, m.from.botId, m.at))
) && (
- <ClusterLabel bot={memberOf(m.from.botId)} name={m.from.name} color={m.from.color} />
+ <ClusterLabel bot={memberOf(m.from.botId)} name={m.from.name} color={m.from.color} to={m.kind === "text" ? roomAddressees(m, members, transcript) : undefined} />
)}
{fold && (
<TurnNarrationRun
diff --git a/src/components/RoomClusterLabel.tsx b/src/components/RoomClusterLabel.tsx
index cddfdc4ba5..42654582bd 100644
--- a/src/components/RoomClusterLabel.tsx
+++ b/src/components/RoomClusterLabel.tsx
@@ -1,29 +1,49 @@
+import { Fragment } from "react";
+
import { BotAvatar } from "./Avatar";
import { cn } from "@/lib/cn";
import { MAUS_COLOR_NAMES, normalizeState, type MausColor } from "@/lib/mascot";
+import type { RoomAddressee } from "@/lib/room-addressees";
import type { Bot } from "@/state/store";
-function isPaletteColor(color: string): color is MausColor {
- return (MAUS_COLOR_NAMES as readonly string[]).includes(color);
+function isPaletteColor(color: string | undefined): color is MausColor {
+ return (MAUS_COLOR_NAMES as readonly string[]).includes(color ?? "");
}
-export function ClusterLabel({ bot, name, color }: { bot?: Bot; name: string; color: string }) {
+function Name({ name, color }: { name: string; color?: string }) {
const known = isPaletteColor(color);
return (
- <div className="mt-1 flex items-center gap-1.5 pl-0.5">
+ <span
+ className={cn("text-[13px] font-semibold", known ? "bot-identity" : "text-ink-secondary")}
+ data-bot-color={known ? color : undefined}
+ >{name}</span>
+ );
+}
+
+export function ClusterLabel({ bot, name, color, to = [] }: { bot?: Bot; name: string; color: string; to?: readonly RoomAddressee[] }) {
+ return (
+ <div className="mt-1.5 flex flex-wrap items-center gap-x-1.5 gap-y-0.5 pl-0.5">
<BotAvatar
bot={bot ?? { name, color: color as Bot["color"] }}
state={normalizeState(bot?.mascotExpression) ?? "happy"}
- size={16}
+ size={20}
motion="none"
motionKey={0}
animated={false}
- readable={known}
+ readable={isPaletteColor(color)}
/>
- <span
- className={cn("text-[11px] font-medium", known ? "bot-identity" : "text-ink-secondary")}
- data-bot-color={known ? color : undefined}
- >{name}</span>
+ <Name name={name} color={color} />
+ {to.length > 0 && (
+ <>
+ <span className="inline-block text-[13px] text-ink-tertiary rtl:-scale-x-100">→</span>
+ {to.map((addressee, index) => (
+ <Fragment key={addressee.key}>
+ <Name name={addressee.name} color={addressee.color} />
+ {index < to.length - 1 && <span className="-ms-1 text-[13px] text-ink-tertiary">,</span>}
+ </Fragment>
+ ))}
+ </>
+ )}
</div>
);
}
diff --git a/src/lib/room-addressees.test.ts b/src/lib/room-addressees.test.ts
new file mode 100644
index 0000000000..3cb46f6ddb
--- /dev/null
+++ b/src/lib/room-addressees.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, it } from "vitest";
+
+import { roomAddressees } from "./room-addressees";
+import type { Message } from "@/state/store";
+
+const mylo = { id: "b-mylo", name: "Mylo", color: "purple" as const };
+const athena = { id: "b-athena", name: "Athena", color: "green" as const };
+const members = [mylo, athena];
+const from = (bot: typeof mylo | typeof athena) => ({ botId: bot.id, name: bot.name, color: bot.color });
+const msg = (over: Partial<Message>): Message => ({ id: "m", role: "bot", kind: "text", text: "", at: 1, ...over } as Message);
+
+describe("roomAddressees", () => {
+ it("names the room bots a message @mentions, not the sender", () => {
+ const message = msg({ from: from(mylo), text: "Sure. @Athena, can you draw it? cc @Mylo" });
+ expect(roomAddressees(message, members, [])).toEqual([{ key: athena.id, name: "Athena", color: "green" }]);
+ });
+
+ it("names the author of the replied-to message first", () => {
+ const asked = msg({ id: "q", from: from(mylo), text: "@Athena chart please" });
+ const reply = msg({ id: "r", from: from(athena), replyToId: "q", text: "On it. @Mylo" });
+ expect(roomAddressees(reply, members, [asked, reply])).toEqual([{ key: mylo.id, name: "Mylo", color: "purple" }]);
+ });
+
+ it("calls the person You when a bot replies to them", () => {
+ const asked = msg({ id: "q", role: "user", text: "@Mylo check sales" });
+ const reply = msg({ id: "r", from: from(mylo), replyToId: "q", text: "Done." });
+ expect(roomAddressees(reply, members, [asked, reply])).toEqual([{ key: "user:You", name: "You" }]);
+ });
+
+ it("ignores mentions inside code and plain text without mentions", () => {
+ expect(roomAddressees(msg({ from: from(mylo), text: "run `@Athena` later" }), members, [])).toEqual([]);
+ expect(roomAddressees(msg({ from: from(mylo), text: "Sales were up 12%." }), members, [])).toEqual([]);
+ });
+});
diff --git a/src/lib/room-addressees.ts b/src/lib/room-addressees.ts
new file mode 100644
index 0000000000..61f4a8c319
--- /dev/null
+++ b/src/lib/room-addressees.ts
@@ -0,0 +1,32 @@
+import { blankCode } from "../../shared/skill-command";
+import type { MausColor } from "./mascot";
+import { mentionRanges } from "./mentions";
+import { replyAuthor } from "./replies";
+import type { Bot, Message } from "@/state/store";
+
+export type RoomAddressee = { key: string; name: string; color?: MausColor };
+
+/** Who a bot's room message speaks to: the author of the message it replies to, then the room bots it @mentions.
+ * The sender itself is never listed. */
+export function roomAddressees(
+ message: Pick<Message, "text" | "replyToId" | "from">,
+ members: readonly Pick<Bot, "id" | "name" | "color">[],
+ transcript: readonly Message[],
+): RoomAddressee[] {
+ const sender = message.from?.botId;
+ const out: RoomAddressee[] = [];
+ const add = (entry: RoomAddressee) => {
+ if (entry.key !== sender && !out.some((seen) => seen.key === entry.key)) out.push(entry);
+ };
+ const target = message.replyToId ? transcript.find((candidate) => candidate.id === message.replyToId) : undefined;
+ if (target?.role === "user") add({ key: `user:${replyAuthor(target)}`, name: replyAuthor(target) });
+ else if (target?.from) add({ key: target.from.botId, name: target.from.name, color: target.from.color });
+ const text = message.text ?? "";
+ if (!text.includes("@")) return out;
+ for (const range of mentionRanges(blankCode(text), members)) {
+ const name = text.slice(range.start + 1, range.end).toLowerCase();
+ const bot = members.find((member) => member.name.toLowerCase() === name);
+ if (bot) add({ key: bot.id, name: bot.name, color: bot.color });
+ }
+ return out;
+}