Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): give install advice only for a real Chrome launch failure
AdityaUmale1ae748a934a4
diff --git a/server/browser-tool-shape.test.ts b/server/browser-tool-shape.test.tsindex 556c0d190f..3d440afc28 100644--- a/server/browser-tool-shape.test.ts+++ b/server/browser-tool-shape.test.ts@@ -87,9 +87,14 @@ describe("browser tool shaping", () => {expect(shaped.content[0].text).toContain("missing libraries the browser needs (libatk-1.0.so.0)");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 advice- for (const result of [{ content: [{ type: "text", text: launch }] }, { content: [{ type: "text", text: "Chrome exited early (exit code: 1)" }], isError: true }]) {+ const 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 }]) {expect(shape(result).content).toEqual(result.content);}+ // an absurdly long library name is cut short+ const long = shape({ content: [{ type: "text", text: launch.replace("libatk-1.0.so.0", "x".repeat(5000)) }], isError: true }).content[0].text;+ expect(long).toContain(`(${"x".repeat(120)}…)`);+ expect(long).not.toContain(`${"x".repeat(121)})`);// the install command is for Linux hosts onlyObject.defineProperty(process, "platform", { value: "darwin" });expect(shape({ content: [{ type: "text", text: launch }], isError: true }).content[0].text).toBe(launch);diff --git a/server/browser-tool-shape.ts b/server/browser-tool-shape.tsindex e5828c975d..2f802a34e0 100644--- a/server/browser-tool-shape.ts+++ b/server/browser-tool-shape.ts@@ -146,6 +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:";+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));+ return library && library.length > MAX_LIBRARY_NAME ? `${library.slice(0, MAX_LIBRARY_NAME)}…` : library;+}+export function shapeBrowserToolResult(result: unknown, options: { toolName?: string; budget?: number } = {}): unknown {if (!isRecord(result) || !Array.isArray(result.content)) return result;const budget = options.budget ?? DEFAULT_BROWSER_RESULT_BUDGET;@@ -154,14 +165,14 @@ export function shapeBrowserToolResult(result: unknown, options: { toolName?: stconst content = (result.content as unknown[]).map((part) => {if (!isRecord(part) || part.type !== "text" || typeof part.text !== "string") return part;textParts++;- if (result.isError === true && process.platform === "linux") library ??= loaderMissingLibrary(part.text);+ if (result.isError === true && process.platform === "linux") library ??= launchMissingLibrary(part.text);const outcome = trimResultText({ text: withoutLifecycle(part.text), budget, toolName: options.toolName });return { ...part, text: outcome.trimmed ? outcome.text + BROWSER_NARROWING_HINT : outcome.text };});if (!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: older Claude Code shows a bot only that one.+ // The advice joins the first text part: some MCP clients show only that one.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}`;