Skip to content

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

Check the tag last and redact only a reply that will show (#8096)

Bugfixer 2b1dff201a949
diff --git a/server/index.ts b/server/index.ts
index bd0a9f1df9..abb675f840 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -3912,7 +3912,7 @@ const handedLines: HandedLineDeps | undefined = CLOUD_TEAM ? undefined : { store
const problem = roomHandoffProblem(child, parent);
const source = store.bot(parent.botId);
const answer = problem || !source ? null
- : taggedAnswerRow(child, parent, bot, taggedTeammates(parent.text, personalReach.peers(store.bots, source, parent.threadId)).map((one) => one.id));
+ : taggedAnswerRow(child, parent, bot, (botId) => taggedTeammates(parent.text, personalReach.peers(store.bots, source, parent.threadId)).some((one) => one.id === botId));
store.appendMessage(parent.threadId, answer ?? {
role: "bot", kind: "activity",
roomRequest: { id: child.id, phase: "result" }, ...handoffFiles.returnedWith(child, parent),
diff --git a/server/tagged-answer.test.ts b/server/tagged-answer.test.ts
index 410dad4808..b4a2e5986b 100644
--- a/server/tagged-answer.test.ts
+++ b/server/tagged-answer.test.ts
@@ -4,30 +4,31 @@ import { taggedAnswerRow } from "./tagged-answer.ts";
const chief = { id: "chief", name: "Chief", color: "red" as const };
const answered = { id: "h1", botId: "chief", mode: "consult" as const, status: "completed" as const, result: " $4.20 today. " };
const wesChat = { botId: "wes" };
+const is = (...ids: string[]) => (botId: string) => ids.includes(botId);
describe("a teammate tagged in another bot's one-to-one chat", () => {
it("answers there under its own name", () => {
- expect(taggedAnswerRow(answered, wesChat, chief, ["chief"])).toEqual({
+ expect(taggedAnswerRow(answered, wesChat, chief, is("chief"))).toEqual({
role: "bot", kind: "text", text: "$4.20 today.",
from: { botId: "chief", name: "Chief", color: "red" }, roomRequest: { id: "h1", phase: "result" },
});
});
it("keeps the teammate row for everything else", () => {
- expect(taggedAnswerRow(answered, wesChat, chief, [])).toBeNull();
- expect(taggedAnswerRow(answered, { ...wesChat, groupId: "room" }, chief, ["chief"])).toBeNull();
- expect(taggedAnswerRow(answered, { ...wesChat, parentId: "p" }, chief, ["chief"])).toBeNull();
- expect(taggedAnswerRow({ ...answered, mode: "work" }, wesChat, chief, ["chief"])).toBeNull();
- expect(taggedAnswerRow({ ...answered, status: "failed" }, wesChat, chief, ["chief"])).toBeNull();
- expect(taggedAnswerRow({ ...answered, result: " " }, wesChat, chief, ["chief"])).toBeNull();
- expect(taggedAnswerRow(answered, wesChat, undefined, ["chief"])).toBeNull();
- expect(taggedAnswerRow({ ...answered, botId: "wes" }, wesChat, chief, ["wes"])).toBeNull();
+ expect(taggedAnswerRow(answered, wesChat, chief, is())).toBeNull();
+ expect(taggedAnswerRow(answered, { ...wesChat, groupId: "room" }, chief, is("chief"))).toBeNull();
+ expect(taggedAnswerRow(answered, { ...wesChat, parentId: "p" }, chief, is("chief"))).toBeNull();
+ expect(taggedAnswerRow({ ...answered, mode: "work" }, wesChat, chief, is("chief"))).toBeNull();
+ expect(taggedAnswerRow({ ...answered, status: "failed" }, wesChat, chief, is("chief"))).toBeNull();
+ expect(taggedAnswerRow({ ...answered, result: " " }, wesChat, chief, is("chief"))).toBeNull();
+ expect(taggedAnswerRow(answered, wesChat, undefined, is("chief"))).toBeNull();
+ expect(taggedAnswerRow({ ...answered, botId: "wes" }, wesChat, chief, is("wes"))).toBeNull();
});
});
describe("the tagged teammate's reply", () => {
it("hides secrets like the teammate row does", () => {
const key = "sk-ant-api03-" + "x".repeat(40);
- expect(taggedAnswerRow({ ...answered, result: `key ${key}` }, wesChat, chief, ["chief"])?.text).not.toContain(key);
+ expect(taggedAnswerRow({ ...answered, result: `key ${key}` }, wesChat, chief, is("chief"))?.text).not.toContain(key);
});
});
diff --git a/server/tagged-answer.ts b/server/tagged-answer.ts
index 9f8175d728..282c468d71 100644
--- a/server/tagged-answer.ts
+++ b/server/tagged-answer.ts
@@ -12,12 +12,11 @@ export function taggedAnswerRow(
child: Pick<HandoffView, "id" | "botId" | "mode" | "status" | "result">,
parent: Pick<HandoffView, "botId" | "groupId" | "parentId">,
bot: Pick<WireBot, "id" | "name" | "color"> | undefined,
- tagged: readonly string[],
+ tagged: (botId: string) => boolean,
): Omit<Message, "id" | "at"> | null {
- const text = redactSecretsInText(child.result.trim());
- if (!bot || !text || parent.groupId || parent.parentId || child.botId === parent.botId) return null;
- if (child.mode !== "consult" || child.status !== "completed" || !tagged.includes(child.botId)) return null;
- return { role: "bot", kind: "text", text, from: { botId: bot.id, name: bot.name, color: bot.color }, roomRequest: { id: child.id, phase: "result" } };
+ if (!bot || parent.groupId || parent.parentId || child.botId === parent.botId || child.mode !== "consult" || child.status !== "completed") return null;
+ const text = tagged(child.botId) ? redactSecretsInText(child.result.trim()) : "";
+ return text ? { role: "bot", kind: "text", text, from: { botId: bot.id, name: bot.name, color: bot.color }, roomRequest: { id: child.id, phase: "result" } } : null;
}
/** The line the chat's own bot reads when it is told the people it tagged: their answer is already in the chat. */
diff --git a/shared/skill-burger/layers.ts b/shared/skill-burger/layers.ts
index accb34f853..c76f5aeaea 100644
--- a/shared/skill-burger/layers.ts
+++ b/shared/skill-burger/layers.ts
@@ -489,10 +489,10 @@ function repliesIn(run: readonly RunMessage[]): Map<string, Omit<DelegateReply,
for (const message of run) {
const request = message.roomRequest;
// A tagged teammate's answer is a text row in its own name (server/tagged-answer.ts); every other reply is an activity row.
- if ((message.kind !== "activity" && message.kind !== "text") || request?.phase !== "result" || !request.id) continue;
+ if (request?.phase !== "result" || !request.id) continue;
out.set(request.id, {
name: message.from?.name ?? "", ...(message.from?.botId ? { botId: message.from.botId } : {}), requestId: request.id,
- ok: message.tool?.ok !== false, text: message.tool?.output ?? (message.kind === "text" ? message.text : undefined) ?? message.tool?.name ?? "",
+ ok: message.tool?.ok !== false, text: message.tool?.output ?? message.tool?.name ?? message.text ?? "",
});
}
return out;