Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): convert headerless HTML in web_fetch (#4799)

Ben Pankow5243d1d0816c
diff --git a/.changeset/web-fetch-headerless-html.md b/.changeset/web-fetch-headerless-html.md
new file mode 100644
index 000000000..650a3a690
--- /dev/null
+++ b/.changeset/web-fetch-headerless-html.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+`web_fetch` now converts HTML pages served without a `Content-Type` header instead of returning truncated raw source.
diff --git a/packages/eve/src/execution/web-fetch/execute.test.ts b/packages/eve/src/execution/web-fetch/execute.test.ts
index 33b36f0bb..e8fd80454 100644
--- a/packages/eve/src/execution/web-fetch/execute.test.ts
+++ b/packages/eve/src/execution/web-fetch/execute.test.ts
@@ -173,6 +173,28 @@ describe("executeWebFetchTool", () => {
expect(result.content).not.toContain("evil");
});
+ it("converts HTML served without a Content-Type", async () => {
+ const script = "const ignored = 1;\n".repeat(MAX_OUTPUT_LINES + 500);
+ const html = `\n<!DOCTYPE html><html><head><script>${script}</script></head><body><h1>Visible title</h1></body></html>`;
+ // Bytes, because a string body would get an implicit text/plain header.
+ requestPublicUrlMock.mockResolvedValueOnce(new Response(new TextEncoder().encode(html)));
+
+ const result = await executeWebFetchTool({ url: "https://example.com" });
+
+ expect(result).toMatchObject({ contentType: "", truncated: false });
+ expect(result.content).toContain("# Visible title");
+ expect(result.content).not.toContain("const ignored");
+ });
+
+ it("leaves headerless non-HTML content as-is", async () => {
+ const body = '<?xml version="1.0"?><feed><title>Feed</title></feed>';
+ requestPublicUrlMock.mockResolvedValueOnce(new Response(new TextEncoder().encode(body)));
+
+ const result = await executeWebFetchTool({ url: "https://example.com" });
+
+ expect(result.content).toBe(body);
+ });
+
it("returns non-HTML content as-is regardless of format", async () => {
const json = '{"key": "value"}';
diff --git a/packages/eve/src/execution/web-fetch/execute.ts b/packages/eve/src/execution/web-fetch/execute.ts
index 5d57610a4..646c87efb 100644
--- a/packages/eve/src/execution/web-fetch/execute.ts
+++ b/packages/eve/src/execution/web-fetch/execute.ts
@@ -94,8 +94,10 @@ export async function executeWebFetchTool(
const buffer = await response.arrayBuffer();
const contentType = response.headers.get("content-type") ?? "";
- const isHtml = contentType.includes("text/html");
const body = new TextDecoder().decode(buffer);
+ const isHtml =
+ contentType.includes("text/html") ||
+ (contentType.trim() === "" && /^\s*<(?:!doctype\s+html|html)[\s>]/i.test(body));
let rawContent: string;