Skip to content

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

Rooms: a tag a same-named teammate takes names no bot in "Sender → Addressee"

AdityaUmaleb9e4f8e2e8f5
diff --git a/src/components/GroupView.tsx b/src/components/GroupView.tsx
index 58e01a33d2..95d00c643d 100644
--- a/src/components/GroupView.tsx
+++ b/src/components/GroupView.tsx
@@ -327,7 +327,7 @@ export const Transcript = memo(function Transcript({
const { state, dispatch } = useStore();
const showThreads = useShowThreads();
const showToolCalls = showToolCallsEnabled(state.config);
- const canReact = useCanReact(group.threadId);
+ const canReact = useCanReact(group.threadId); const teammatePeers = useTeammates().peers;
const memberOf = (id?: string) => members.find((b) => b.id === id); const messages = useLiveTranscript(group.threadId, saved, transcript, members, roomThreadSpeakerId(group, group.threadId));
const folds = useMemo(() => roomTurnFolds(messages), [messages, locale]);
const items = useMemo(() => groupActivityRuns(messages.filter(message =>
@@ -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} to={m.kind === "text" ? roomAddressees(m, members, transcript) : undefined} />
+ <ClusterLabel bot={memberOf(m.from.botId)} name={m.from.name} color={m.from.color} to={m.kind === "text" ? roomAddressees(m, members, transcript, teammatePeers) : undefined} />
)}
{fold && (
<TurnNarrationRun
diff --git a/src/lib/room-addressees.test.ts b/src/lib/room-addressees.test.ts
index 3cb46f6ddb..3f495c6d72 100644
--- a/src/lib/room-addressees.test.ts
+++ b/src/lib/room-addressees.test.ts
@@ -27,6 +27,13 @@ describe("roomAddressees", () => {
expect(roomAddressees(reply, members, [asked, reply])).toEqual([{ key: "user:You", name: "You" }]);
});
+ it("leaves a tag a same-named teammate takes to the teammate", () => {
+ const message = msg({ from: from(mylo), text: "@Athena can you check? @Athena Bot too" });
+ const bots = [...members, { id: "b-athena-bot", name: "Athena Bot", color: "blue" as const }];
+ expect(roomAddressees(message, bots, [], [{ name: "Athena", person: true }]))
+ .toEqual([{ key: "b-athena-bot", name: "Athena Bot", color: "blue" }]);
+ });
+
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
index 61f4a8c319..04f616dcb2 100644
--- a/src/lib/room-addressees.ts
+++ b/src/lib/room-addressees.ts
@@ -1,17 +1,19 @@
import { blankCode } from "../../shared/skill-command";
import type { MausColor } from "./mascot";
-import { mentionRanges } from "./mentions";
+import { mentionRanges, type MentionPeer } 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. */
+ * The sender itself is never listed. A tag a teammate takes (a tie with a bot's name is the teammate's, as the server
+ * reads it) names no bot. */
export function roomAddressees(
message: Pick<Message, "text" | "replyToId" | "from">,
members: readonly Pick<Bot, "id" | "name" | "color">[],
transcript: readonly Message[],
+ teammates: readonly MentionPeer[] = [],
): RoomAddressee[] {
const sender = message.from?.botId;
const out: RoomAddressee[] = [];
@@ -23,7 +25,8 @@ export function roomAddressees(
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)) {
+ for (const range of mentionRanges(blankCode(text), [...members, ...teammates])) {
+ if (range.person) continue;
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 });