Skip to content

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

Train S3 fixes: a webhook into a bot the caller cannot see answers as a missing bot; the live-status test expects #6043's quiet note

milind-soniaf6eb99087bd
diff --git a/server/routes/webhooks.test.ts b/server/routes/webhooks.test.ts
index fb971e7ade..1ee0f9e768 100644
--- a/server/routes/webhooks.test.ts
+++ b/server/routes/webhooks.test.ts
@@ -23,7 +23,7 @@ function folder(): string {
folders.push(made);
return made;
}
-const manager = (file: string) => new WebhookManager({ file, botState: () => "ready", enqueue: () => ({ id: "run-1" }), roomMember: () => ({ ok: true }),
+const manager = (file: string) => new WebhookManager({ file, botState: (botId) => botId.startsWith("bot-") ? "ready" : "missing", enqueue: () => ({ id: "run-1" }), roomMember: () => ({ ok: true }),
roomPost: async (trigger) => ({ posted: true, attachments: 0, threadId: `${trigger.groupId}-thread` }) });
async function serve(seen: (botId: string) => boolean = () => true, file = join(folder(), "webhooks.json"), seesRoom: (groupId: string) => boolean = () => true) {
@@ -31,7 +31,9 @@ async function serve(seen: (botId: string) => boolean = () => true, file = join(
const routes = [createWebhookRoutes({ webhooks, ingress: () => ({ available: true, baseUrl: "http://127.0.0.1:8800" }), visible: () => ({ everything: false, bot: seen, group: seesRoom }) })];
const server = createServer(async (req, res) => {
const url = new URL(req.url ?? "/", "http://localhost");
- const handled = await dispatchRoutes(routes, { req, res, url, path: url.pathname, method: req.method ?? "GET", auth: { kind: "loopback", scopes: ["admin", "client"] }, json, readBody });
+ // As the server answers a refusal the manager throws: its status and message.
+ const handled = await dispatchRoutes(routes, { req, res, url, path: url.pathname, method: req.method ?? "GET", auth: { kind: "loopback", scopes: ["admin", "client"] }, json, readBody })
+ .catch((error: { status?: number; message?: string }) => { json(res, error.status ?? 500, { error: error.message }); return true; });
if (!handled) json(res, 404, { from: "inline routes" });
});
servers.push(server);
@@ -69,7 +71,10 @@ describe("a webhook's address for the person", () => {
}
expect(hidden.webhooks.list()).toEqual([expect.objectContaining({ id: theirs.webhook.id, name: "Hidden" })]);
expect(hidden.webhooks.authorize(theirs.webhook.endpointId, theirs.secret)).toBe(true);
- expect((await hidden.call("POST", "/api/webhooks", { name: "Into theirs", prompt: "", botId: "bot-hidden" })).status).toBe(404);
+ // Into a bot this viewer cannot see: answered as for a bot that does not exist, and nothing is made.
+ expect(await hidden.call("POST", "/api/webhooks", { name: "Into theirs", prompt: "", botId: "bot-hidden" })).toEqual(await hidden.call("POST", "/api/webhooks", { name: "Into theirs", prompt: "", botId: "gone-1" }));
+ expect(await hidden.call("POST", "/api/webhooks", { name: "Into theirs", prompt: "", botId: "bot-hidden" })).toEqual({ status: 400, body: { error: "That MAUS no longer exists" } });
+ expect(hidden.webhooks.list().map((hook) => hook.botId)).toEqual(["bot-hidden"]);
expect((await hidden.call("POST", "/api/webhooks", { name: "Mine", prompt: "", botId: "bot-a" })).status).toBe(201);
const file = join(folder(), "webhooks.json");
diff --git a/server/routes/webhooks.ts b/server/routes/webhooks.ts
index b12fa58547..c8848a144c 100644
--- a/server/routes/webhooks.ts
+++ b/server/routes/webhooks.ts
@@ -1,5 +1,7 @@
// The person's side of webhook automations. Deliveries land on a separate webhook-only loopback listener, so a relay never
// exposes the rest of the control surface. Only the list is a client route; the rest, the address included, needs admin.
+import { randomUUID } from "node:crypto";
+
import { webhookVisible } from "../bot-visibility.ts";
import type { RequestAuth } from "../request-auth.ts";
import { webhookCredential } from "../webhook-ingress.ts";
@@ -26,8 +28,9 @@ export function createWebhookRoutes({ webhooks, ingress, visible }: WebhookRoute
}
if (path === "/api/webhooks" && method === "POST") {
const body = await readBody(req);
- // Security: on a Team Cloud an admin may not see another person's private bot; a webhook into it is refused alike.
- if (body && typeof body === "object" && !Array.isArray(body) && !webhookVisible(body, visible(auth))) return json(res, 404, { error: "no such bot" });
+ // Security: on a Team Cloud an admin may not see another person's own MausBot; a webhook into it is answered
+ // exactly as one into a bot that does not exist.
+ if (body && typeof body === "object" && !Array.isArray(body) && !webhookVisible(body, visible(auth))) body.botId = randomUUID();
const created = webhooks.create(body);
return json(res, 201, { webhook: created.webhook, ...withCredential(created.webhook, created.secret) });
}
diff --git a/src/components/ChatView.live-status.test.ts b/src/components/ChatView.live-status.test.ts
index d8a439b959..2c56b9ef6f 100644
--- a/src/components/ChatView.live-status.test.ts
+++ b/src/components/ChatView.live-status.test.ts
@@ -131,10 +131,10 @@ describe("the mascot and its status line through a long turn", () => {
engine({ type: "turn.progress", activity: "write", itemId: "toolu_write", file: "index.html", bytes: 14 * 1024 + 300 } as Partial<RuntimeEvent>);
expect(statusLine()).toBe("Working · 1m 12s · Writing index.html · 14 KB");
- // Ten silent minutes: no frame, no row. Nothing times the mascot out.
+ // Ten silent minutes: no frame, no row. Nothing times the mascot out; the line says how long it has been quiet.
act(() => void vi.advanceTimersByTime(10 * 60_000));
expect(mascot()).not.toBeNull();
- expect(statusLine()).toBe("Working · 11m 12s · Writing index.html · 14 KB");
+ expect(statusLine()).toBe("Working · 11m 12s · Writing index.html · 14 KB · nothing new for 10 min");
});
it("stays through a long silent tool, keeping the call's own words while it runs", () => {