Skip to content

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

fix(cli): include screen frames in conversation event filters

Afloatf72f938a9c50
diff --git a/server/headless/events.test.ts b/server/headless/events.test.ts
index 9ab8c7487d..cc70209636 100644
--- a/server/headless/events.test.ts
+++ b/server/headless/events.test.ts
@@ -73,6 +73,34 @@ describe("events against a server", () => {
if (end) res.end();
};
+ it.each([
+ { flags: ["--thread", "t1", "--screens"], expected: ["t1"] },
+ { flags: ["--job", "t1", "--screens"], expected: ["t1", "child"] },
+ { flags: ["--thread", "t1"], expected: [] },
+ ])("keeps requested screen frames within the selected conversations: $flags", async ({ flags, expected }) => {
+ asked.length = 0;
+ answer = (req, res) => {
+ if (req.url?.startsWith("/api/threads/t1/job")) {
+ res.writeHead(200, { "content-type": "application/json" });
+ return res.end(JSON.stringify({ threadId: "t1", since: 1_000, state: "running", nodes: [{ threadId: "child" }] }));
+ }
+ stream(res, [
+ 'data: {"kind":"hello","resumed":false}\n\n',
+ ...["t1", "child", "other"].map((threadId) => `data: ${JSON.stringify({ kind: "screen", botId: "lead", threadId, surface: "computer", png: "AAAA" })}\n\n`),
+ 'data: {"kind":"message","threadId":"t1","text":"finished fixture"}\n\n',
+ ], false);
+ };
+ const { io, out } = capture();
+ const controller = new AbortController();
+ const code = await runHeadless(["events", ...flags], {
+ env: { OPENMAUSBOT_URL: origin }, signal: controller.signal,
+ io: { ...io, out: (line) => { io.out(line); if (JSON.parse(line).kind === "message") controller.abort(); } },
+ });
+ expect(code).toBe(130);
+ expect(out.map((line) => JSON.parse(line)).filter((frame) => frame.kind === "screen").map((frame) => frame.threadId)).toEqual(expected);
+ expect(asked).toContain(`/api/events?screens=${flags.includes("--screens") ? "on" : "off"}`);
+ });
+
it("ends with the refusal when the stream is refused (an expired token), instead of asking again forever", async () => {
asked.length = 0;
answer = (_req, res) => { res.writeHead(401, { "content-type": "application/json" }); res.end(JSON.stringify({ error: "unauthorized: this session has expired or was revoked" })); };
diff --git a/server/headless/events.ts b/server/headless/events.ts
index 033ad17d01..2b74898e70 100644
--- a/server/headless/events.ts
+++ b/server/headless/events.ts
@@ -13,7 +13,7 @@ const FINAL = new Set(["needs-input", "completed", "failed", "stalled", "idle"])
export function frameThreads(frame: Frame): string[] {
const own = (record: Frame | undefined) => [record?.threadId, ...(Array.isArray(record?.tasks) ? record.tasks.map((task: Frame) => task.threadId) : [])];
switch (frame.kind) {
- case "message": case "message.patch": case "thread": return [frame.threadId];
+ case "message": case "message.patch": case "thread": case "screen": return [frame.threadId];
case "runtime": return [frame.event?.threadId];
case "bot": return own(frame.bot);
case "group": return own(frame.group);