Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Say the connected-apps service is out of date when its upload route is missing
AdityaUmalee0eab4bd3776
diff --git a/server/composio-files.test.ts b/server/composio-files.test.tsindex 8428db4d6a..2c64d715ac 100644--- a/server/composio-files.test.ts+++ b/server/composio-files.test.ts@@ -1,7 +1,7 @@import { afterEach, describe, expect, it, vi } from "vitest";import type { AppConfig } from "./config.ts";-import { requestFileUpload } from "./composio-files.ts";+import { requestFileUpload, UploadServiceOutdatedError } from "./composio-files.ts";const request = { toolkit_slug: "googledrive", tool_slug: "GOOGLEDRIVE_UPLOAD_FILE", filename: "report.pdf", mimetype: "application/pdf", md5: "0".repeat(32) };const withKey = { composio: { apiKey: "ak_test" } } as unknown as AppConfig;@@ -41,4 +41,19 @@ describe("upload links for connected-app files", () => {vi.stubGlobal("fetch", answering({ key: "k", url: "http://127.0.0.1:9000/upload/1" }));await expect(requestFileUpload(withKey, request, { url: "http://127.0.0.1:9000", token: service.token })).resolves.toMatchObject({ url: "http://127.0.0.1:9000/upload/1" });});+ it("says the connected-apps service is out of date when it has no upload route", async () => {+ vi.stubGlobal("fetch", async () => Response.json({ error: "not found" }, { status: 404 }));+ const outdated = requestFileUpload(withKey, request, service);+ await expect(outdated).rejects.toBeInstanceOf(UploadServiceOutdatedError);+ await expect(outdated).rejects.toThrow("out of date");+ });++ it("keeps the answer's own error for other failures and for Composio's 404", async () => {+ vi.stubGlobal("fetch", async () => Response.json({ error: "googledrive is not connected" }, { status: 409 }));+ await expect(requestFileUpload(withKey, request, service)).rejects.toThrow("googledrive is not connected");+ vi.stubGlobal("fetch", async () => Response.json({ error: "not found" }, { status: 404 }));+ const fromComposio = requestFileUpload(withKey, request);+ await expect(fromComposio).rejects.toThrow("not found");+ await expect(fromComposio).rejects.not.toBeInstanceOf(UploadServiceOutdatedError);+ });});diff --git a/server/composio-files.ts b/server/composio-files.tsindex 5d89777287..79ef2af6b4 100644--- a/server/composio-files.ts+++ b/server/composio-files.ts@@ -36,6 +36,13 @@ export interface FileUploadRequest {md5: string;}+/** The connected-apps service answered its unknown-route 404: it runs a version from before it took file uploads. */+export class UploadServiceOutdatedError extends Error {+ constructor() {+ super("the connected-apps service is out of date and does not take file uploads yet");+ }+}+const projectAnswerSchema = z.object({ key: z.string().min(1), new_presigned_url: z.string().optional(), newPresignedUrl: z.string().optional() });const serviceAnswerSchema = z.object({ key: z.string().min(1), url: z.string().min(1) });@@ -49,6 +56,7 @@ export async function requestFileUpload(cfg: AppConfig, request: FileUploadRequebody: JSON.stringify(request),signal: AbortSignal.timeout(30_000),});+ if (broker && response.status === 404) throw new UploadServiceOutdatedError();if (!response.ok) throw new Error(await responseError(response, `the upload service answered HTTP ${response.status}`));const body: unknown = await response.json();const answer = apiKey ? projectAnswerSchema.parse(body) : serviceAnswerSchema.parse(body);diff --git a/server/connector-files.test.ts b/server/connector-files.test.tsindex 1f016de5d0..5b5089caf0 100644--- a/server/connector-files.test.ts+++ b/server/connector-files.test.ts@@ -9,6 +9,7 @@ import {connectorFileScope, localFileReferences, openBotFile, prepareConnectorFiles, stageConnectorFiles, withMissingFileHint,type BotFileScope, type FileStagingDeps,} from "./connector-files.ts";+import { UploadServiceOutdatedError } from "./composio-files.ts";import { outboundCard } from "./outbound-requests.ts";const call = <A,>(name: string, args: A, id = 1) => ({ jsonrpc: "2.0", id, method: "tools/call", params: { name, arguments: args } });@@ -142,6 +143,16 @@ describe("connected-app file arguments", () => {expect("refusal" in staged && staged.refusal).toContain("do not keep retrying");});+ it("tells the bot not to retry when the connected-apps service is too old to take uploads", async () => {+ const { value } = deps({ requestUpload: async () => { throw new UploadServiceOutdatedError(); } });+ const staged = await stageConnectorFiles(multi({ tool_slug: "GOOGLEDRIVE_UPLOAD_FILE", arguments: { file_to_upload: "/tmp/report.pdf" } }), value);+ const refusal = "refusal" in staged ? staged.refusal : "";+ expect(refusal).toContain("uploading report.pdf for Google Drive failed: the connected-apps service is out of date");+ expect(refusal).toContain("Nothing was written to Google Drive");+ expect(refusal).toContain("Trying again will not help");+ expect(refusal).not.toContain("try the call once more");+ });+it("puts the bytes without following a redirect", async () => {const seen: RequestInit[] = [];vi.stubGlobal("fetch", async (_url: string, init: RequestInit) => { seen.push(init); return new Response("{}"); });diff --git a/server/connector-files.ts b/server/connector-files.tsindex 1797f41ed2..09b890fa37 100644--- a/server/connector-files.ts+++ b/server/connector-files.ts@@ -14,7 +14,7 @@ import { connectorCallsIn } from "../shared/outbound.ts";import { FILE_MAX_BYTES, limitMegabytes } from "../shared/upload-limits.ts";import { guestWorkspaceToHost } from "./bot-attachment.ts";import type { BrokerAccess } from "./composio-broker-access.ts";-import { requestFileUpload } from "./composio-files.ts";+import { requestFileUpload, UploadServiceOutdatedError } from "./composio-files.ts";import type { AppConfig } from "./config.ts";import { withFailedCallHint } from "./connector-scope-hint.ts";import { serviceSlugFor, serviceSlugForCandidates } from "./connector-verdict.ts";@@ -252,6 +252,13 @@ export function uploadFailedText(reference: Pick<FileReference, "tool">, name: s+ `${app} failed and why, and do not keep retrying.`;}+/** What the bot is told when the connected-apps service is too old to take the file: retrying cannot help. */+function uploadServiceOutdatedText(reference: Pick<FileReference, "tool">, name: string, app: string): string {+ return `OpenMausBot did not run ${reference.tool}: uploading ${name} for ${app} failed: the connected-apps service is out of date `+ + `and does not take file uploads yet. Nothing was written to ${app}. Trying again will not help: tell the person that sending `+ + `files to ${app} works once the OpenMausBot team updates that service. A ${app} tool that takes text instead of a file still works.`;+}+export interface PreparedFiles {/** The files the call will upload, for its approval card. */files: Array<CardFile & { tool: string; source: unknown }>;@@ -299,7 +306,9 @@ export async function prepareConnectorFiles(frame: unknown, deps: FileStagingDepawait put(link.url, file.bytes, mimetype);reference.replace({ name, mimetype, s3key: link.key });} catch (error) {- throw new Error(uploadFailedText(reference, name, app, reasonOf(error)));+ throw new Error(error instanceof UploadServiceOutdatedError+ ? uploadServiceOutdatedText(reference, name, app)+ : uploadFailedText(reference, name, app, reasonOf(error)));}}return found.frame;