惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
Y
Y Combinator Blog
IT之家
IT之家
博客园 - 聂微东
L
LangChain Blog
爱范儿
爱范儿
H
Help Net Security
GbyAI
GbyAI
F
Fortinet All Blogs
B
Blog
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
D
DataBreaches.Net
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(scripts): cap firecrawl compare HTML reads · openclaw...
vincentkoc · 2026-05-30 · via Recent Commits to openclaw:main
1+

import { pathToFileURL } from "node:url";

12

import { fetchFirecrawlContent } from "../extensions/firecrawl/api.ts";

23

import { extractReadableContent } from "../src/agents/tools/web-tools.js";

34

import { formatErrorMessage } from "../src/infra/errors.ts";

@@ -18,6 +19,12 @@ const baseUrl = process.env.FIRECRAWL_BASE_URL ?? "https://api.firecrawl.dev";

1819

const userAgent =

1920

"Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36";

2021

const timeoutMs = 30_000;

22+

const FETCH_HTML_MAX_BYTES = 5 * 1024 * 1024;

23+24+

type FetchHtmlOptions = {

25+

fetchImpl?: typeof fetch;

26+

maxBytes?: number;

27+

};

21282229

function truncate(value: string, max = 180): string {

2330

if (!value) {

@@ -26,7 +33,97 @@ function truncate(value: string, max = 180): string {

2633

return value.length > max ? `${value.slice(0, max)}…` : value;

2734

}

283529-

async function fetchHtml(url: string): Promise<{

36+

function responseBodyTooLargeError(label: string, maxBytes: number): Error {

37+

return new Error(`${label} response body exceeded ${maxBytes} bytes`);

38+

}

39+40+

async function readBoundedResponseText(

41+

response: Response,

42+

label: string,

43+

signal: AbortSignal,

44+

maxBytes = FETCH_HTML_MAX_BYTES,

45+

): Promise<string> {

46+

const contentLength = Number(response.headers.get("content-length") ?? "");

47+

if (Number.isSafeInteger(contentLength) && contentLength > maxBytes) {

48+

await response.body?.cancel().catch(() => undefined);

49+

throw responseBodyTooLargeError(label, maxBytes);

50+

}

51+

if (!response.body) {

52+

return "";

53+

}

54+55+

const reader = response.body.getReader();

56+

const decoder = new TextDecoder();

57+

const chunks: string[] = [];

58+

let totalBytes = 0;

59+

let canceled = false;

60+61+

try {

62+

for (;;) {

63+

const { done, value } = await readResponseChunk(reader, label, signal, () => {

64+

canceled = true;

65+

});

66+

if (done) {

67+

const tail = decoder.decode();

68+

if (tail) {

69+

chunks.push(tail);

70+

}

71+

break;

72+

}

73+74+

totalBytes += value.byteLength;

75+

if (totalBytes > maxBytes) {

76+

canceled = true;

77+

await reader.cancel().catch(() => undefined);

78+

throw responseBodyTooLargeError(label, maxBytes);

79+

}

80+

chunks.push(decoder.decode(value, { stream: true }));

81+

}

82+

} finally {

83+

if (!canceled) {

84+

reader.releaseLock();

85+

}

86+

}

87+88+

return chunks.join("");

89+

}

90+91+

async function readResponseChunk(

92+

reader: ReadableStreamDefaultReader<Uint8Array>,

93+

label: string,

94+

signal: AbortSignal,

95+

markCanceled: () => void,

96+

): Promise<ReadableStreamReadResult<Uint8Array>> {

97+

if (signal.aborted) {

98+

markCanceled();

99+

await reader.cancel().catch(() => undefined);

100+

throw signal.reason instanceof Error ? signal.reason : new Error(`${label} request aborted`);

101+

}

102+103+

let removeAbortListener: (() => void) | undefined;

104+

const abortPromise = new Promise<ReadableStreamReadResult<Uint8Array>>((_resolve, reject) => {

105+

const onAbort = () => {

106+

markCanceled();

107+

void reader.cancel().catch(() => undefined);

108+

reject(

109+

signal.reason instanceof Error ? signal.reason : new Error(`${label} request aborted`),

110+

);

111+

};

112+

signal.addEventListener("abort", onAbort, { once: true });

113+

removeAbortListener = () => signal.removeEventListener("abort", onAbort);

114+

});

115+116+

try {

117+

return await Promise.race([reader.read(), abortPromise]);

118+

} finally {

119+

removeAbortListener?.();

120+

}

121+

}

122+123+

async function fetchHtml(

124+

url: string,

125+

options: FetchHtmlOptions = {},

126+

): Promise<{

30127

ok: boolean;

31128

status: number;

32129

contentType: string;

@@ -35,14 +132,20 @@ async function fetchHtml(url: string): Promise<{

35132

}> {

36133

const controller = new AbortController();

37134

const timer = setTimeout(() => controller.abort(), timeoutMs);

135+

const fetchImpl = options.fetchImpl ?? fetch;

38136

try {

39-

const res = await fetch(url, {

137+

const res = await fetchImpl(url, {

40138

method: "GET",

41139

headers: { Accept: "*/*", "User-Agent": userAgent },

42140

signal: controller.signal,

43141

});

44142

const contentType = res.headers.get("content-type") ?? "application/octet-stream";

45-

const body = await res.text();

143+

const body = await readBoundedResponseText(

144+

res,

145+

"local HTML fetch",

146+

controller.signal,

147+

options.maxBytes ?? FETCH_HTML_MAX_BYTES,

148+

);

46149

return {

47150

ok: res.ok,

48151

status: res.status,

@@ -135,7 +238,15 @@ async function run() {

135238

process.exit(0);

136239

}

137240138-

run().catch((error) => {

139-

console.error(error);

140-

process.exit(1);

141-

});

241+

if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {

242+

run().catch((error) => {

243+

console.error(error);

244+

process.exit(1);

245+

});

246+

}

247+248+

export const testing = {

249+

FETCH_HTML_MAX_BYTES,

250+

fetchHtml,

251+

readBoundedResponseText,

252+

};