Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(threads): save a file attached to a hand-off result card
ARAYN70110379ca0603a1
diff --git a/server/index.test.ts b/server/index.test.tsindex eb21134836..48fb6eeabf 100644--- a/server/index.test.ts+++ b/server/index.test.ts@@ -748,6 +748,16 @@ beforeAll(async () => {text: `[Clip](<${pathToFileURL(linkedVideo).href}>) and [notes](<${pathToFileURL(linkedFile).href}>)`,from: { botId: "test-bot-a", name: "Test bot A", color: "purple" },},+ {+ id: "handoff-result-card", at: 14, parentId: "linked-video-message", role: "bot", kind: "activity",+ roomRequest: { id: "handoff-request", phase: "result" },+ attachments: [{ kind: "file", path: deliveredImage, mime: "image/png", name: "returned.png" }],+ from: { botId: "test-bot-a", name: "Test bot A", color: "purple" },+ },+ {+ id: "plain-activity-card", at: 15, parentId: "handoff-result-card", role: "bot", kind: "activity",+ tool: { name: "Did something", ok: true },+ },],}),);@@ -14644,6 +14654,20 @@ describe("message pages", () => {expect(await saved.text()).toBe("delivered photo bytes");});+ it("saves a file attached to a hand-off result card, and only that file", async () => {+ const threadId = "test-linked-file-room-thread";+ const save = (id: string, path: string) => api("POST", `/api/threads/${threadId}/messages/${id}/file`, { path });+ const attached = await fetch(`${BASE}/api/threads/${threadId}/messages/handoff-result-card/file`, {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ path: join(home, ".openmausbot", "attachments", "5e1dbd0a-7c3a-4f1e-9b2d-6a0c4f8e2b71.png") }),+ });+ expect(attached.status).toBe(200);+ expect(await attached.text()).toBe("delivered photo bytes");+ expect((await save("handoff-result-card", join(home, "Downloads", "sideboard.png"))).status).toBe(403);+ expect((await save("plain-activity-card", join(home, ".openmausbot", "attachments", "5e1dbd0a-7c3a-4f1e-9b2d-6a0c4f8e2b71.png"))).status).toBe(403);+ });+it("downloads an exact user attachment only from the private attachment store", async () => {const threadId = "test-linked-file-room-thread";const shared = join(home, ".openmausbot", "attachments", "shared-notes.pdf");diff --git a/server/routes/threads.ts b/server/routes/threads.tsindex 00da8225a3..e5229e8857 100644--- a/server/routes/threads.ts+++ b/server/routes/threads.ts@@ -204,7 +204,9 @@ export function createThreadRoutes(deps: ThreadRouteDeps): RouteHandler {const message = store.messagesFor(threadId).find((candidate) => candidate.id === m![2]);if (!message) return json(res, 404, { error: "no such message" });- if (message.kind !== "text" || (!message.text && !message.attachments?.length)) {+ // A non-text card (a hand-off result is an activity message) shares only what it explicitly attaches.+ const attachmentsOnly = message.kind !== "text";+ if ((attachmentsOnly && !message.attachments?.length) || (!message.text && !message.attachments?.length)) {return json(res, 403, { error: "that message does not share this file" });}const messageText = message.text ?? "";@@ -229,6 +231,9 @@ export function createThreadRoutes(deps: ThreadRouteDeps): RouteHandler {const botAttachment = message.role === "bot"? message.attachments?.find((attachment) => attachment.path === href): undefined;+ if (attachmentsOnly && !botAttachment) {+ return json(res, 403, { error: "that message does not share this file" });+ }if (message.role === "user") {downloadName = messageAttachmentName(messageText, href) ?? undefined;if (!downloadName) {