Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): advise only when the result is agent-browser's own launch failure, advice first
AdityaUmale1f073515077e
diff --git a/server/browser-tool-shape.test.ts b/server/browser-tool-shape.test.tsindex 3d440afc28..73cff11881 100644--- a/server/browser-tool-shape.test.ts+++ b/server/browser-tool-shape.test.ts@@ -83,12 +83,18 @@ describe("browser tool shaping", () => {const shaped = shape({ content: [{ type: "text", text: launch }], isError: true });expect(shaped.isError).toBe(true);expect(shaped.content).toHaveLength(1);- expect(shaped.content[0].text.startsWith(launch)).toBe(true);+ // the advice comes first, so a client that cuts a long stderr short still shows it+ expect(shaped.content[0].text.startsWith("This host is missing libraries the browser needs (libatk-1.0.so.0)")).toBe(true);+ expect(shaped.content[0].text.endsWith(launch)).toBe(true);expect(shaped.content[0].text).toContain("missing libraries the browser needs (libatk-1.0.so.0)");+ // agent-browser's longer-stderr form of the marker counts too+ expect(shape({ content: [{ type: "text", text: launch.replace("Chrome stderr:", "Chrome stderr (last 20 lines):") }], isError: true }).content[0].text).toContain("--with-deps");expect(shaped.content[0].text).toContain("`sudo openmausbot browser install --with-deps`");// a page that merely mentions the loader's words, or another failure, gets no install adviceconst echoed = "Error: page script failed: /usr/bin/app: error while loading shared libraries: libfoo.so.1: cannot open shared object file";- for (const result of [{ content: [{ type: "text", text: launch }] }, { content: [{ type: "text", text: "Chrome exited early (exit code: 1)" }], isError: true }, { content: [{ type: "text", text: echoed }], isError: true }]) {+ // a page error that quotes a whole launch error, marker included, did not come from our launch+ const quotedLaunch = `Error: page script failed: ${launch}`;+ for (const result of [{ content: [{ type: "text", text: launch }] }, { content: [{ type: "text", text: "Chrome exited early (exit code: 1)" }], isError: true }, { content: [{ type: "text", text: echoed }], isError: true }, { content: [{ type: "text", text: quotedLaunch }], isError: true }]) {expect(shape(result).content).toEqual(result.content);}// an absurdly long library name is cut shortdiff --git a/server/browser-tool-shape.ts b/server/browser-tool-shape.tsindex 2f802a34e0..8163136ac6 100644--- a/server/browser-tool-shape.ts+++ b/server/browser-tool-shape.ts@@ -146,14 +146,17 @@ export function describePageChange(before: PageState, after: PageState): string].filter(Boolean).join(" ") + title;}-/** agent-browser prints a failed Chrome launch's stderr after this line. */-const CHROME_STDERR = "Chrome stderr:";+/** agent-browser's own error when the Chrome it launched dies before DevTools is up. */+const LAUNCH_FAILURE = "Chrome exited early (exit code:";+/** agent-browser prints that launch's stderr after this line ("Chrome stderr:" or "Chrome stderr (last N lines):"). */+const CHROME_STDERR = /^Chrome stderr(?: \(last \d+ lines\))?:$/m;const MAX_LIBRARY_NAME = 120;/** The library a failed Chrome launch's own stderr names, not one a page's text merely quotes. */function launchMissingLibrary(text: string): string | undefined {- const stderr = text.indexOf(CHROME_STDERR);- const library = stderr < 0 ? undefined : loaderMissingLibrary(text.slice(stderr));+ if (!text.trimStart().startsWith(LAUNCH_FAILURE)) return undefined;+ const stderr = CHROME_STDERR.exec(text);+ const library = stderr ? loaderMissingLibrary(text.slice(stderr.index)) : undefined;return library && library.length > MAX_LIBRARY_NAME ? `${library.slice(0, MAX_LIBRARY_NAME)}…` : library;}@@ -172,10 +175,11 @@ export function shapeBrowserToolResult(result: unknown, options: { toolName?: stif (!textParts) return { ...result, content };// agent-browser launches Chrome itself, so a host missing system libraries// only shows the loader's words; say how to install them, as our own launch does.- // The advice joins the first text part: some MCP clients show only that one.+ // The advice leads the first text part: some MCP clients show only that one,+ // and a long stderr can be cut off at the end.if (library) {const first = content.find((part): part is { text: string } => isRecord(part) && part.type === "text" && typeof part.text === "string");- if (first) first.text += `\n\n${new BrowserHostError("libraries", [library]).message}`;+ if (first) first.text = `${new BrowserHostError("libraries", [library]).message}\n\n${first.text}`;}return { ...Object.fromEntries(Object.entries(result).filter(([key]) => key !== "structuredContent")), content };}