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

推荐订阅源

Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
J
Java Code Geeks
L
LangChain Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
博客园 - 司徒正美
B
Blog
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Engineering at Meta
Engineering at Meta
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog

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
refactor(providers): share bounded error body reader · op...
vincentkoc · 2026-06-23 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -1,3 +1,4 @@

1+

import { readResponseBodySnippet } from "../infra/http-error-body.js";

12

/**

23

* Adapts MiniMax VLM image-understanding requests for agent image inputs.

34

*/

@@ -15,58 +16,6 @@ const MINIMAX_VLM_ERROR_BODY_MAX_BYTES = 8 * 1024;

1516

const MINIMAX_VLM_ERROR_BODY_MAX_CHARS = 400;

1617

const DEFAULT_MINIMAX_VLM_TIMEOUT_MS = 60_000;

1718
18-

async function readErrorBodySnippet(res: Response): Promise<string> {

19-

try {

20-

const body = res.body;

21-

if (!body || typeof body.getReader !== "function") {

22-

return (await res.text()).slice(0, MINIMAX_VLM_ERROR_BODY_MAX_CHARS);

23-

}

24-
25-

const reader = body.getReader();

26-

const chunks: Uint8Array[] = [];

27-

let total = 0;

28-

let truncated = false;

29-

try {

30-

while (true) {

31-

const { done, value } = await reader.read();

32-

if (done || !value?.byteLength) {

33-

break;

34-

}

35-

const remaining = MINIMAX_VLM_ERROR_BODY_MAX_BYTES - total;

36-

if (remaining <= 0) {

37-

truncated = true;

38-

break;

39-

}

40-

if (value.byteLength > remaining) {

41-

chunks.push(value.subarray(0, remaining));

42-

total += remaining;

43-

truncated = true;

44-

break;

45-

}

46-

chunks.push(value);

47-

total += value.byteLength;

48-

if (total >= MINIMAX_VLM_ERROR_BODY_MAX_BYTES) {

49-

truncated = true;

50-

break;

51-

}

52-

}

53-

} finally {

54-

if (truncated) {

55-

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

56-

}

57-

try {

58-

reader.releaseLock();

59-

} catch {}

60-

}

61-
62-

return new TextDecoder()

63-

.decode(Buffer.concat(chunks, total))

64-

.slice(0, MINIMAX_VLM_ERROR_BODY_MAX_CHARS);

65-

} catch {

66-

return "";

67-

}

68-

}

69-
7019

export function isMinimaxVlmProvider(provider: string): boolean {

7120

const normalized = provider.trim().toLowerCase();

7221

return (

@@ -160,10 +109,7 @@ export async function minimaxUnderstandImage(params: {

160109

// Without this, HTTP_PROXY/HTTPS_PROXY env vars are silently ignored (#51619).

161110

ensureGlobalUndiciEnvProxyDispatcher();

162111
163-

const timeoutMs = resolvePositiveTimerTimeoutMs(

164-

params.timeoutMs,

165-

DEFAULT_MINIMAX_VLM_TIMEOUT_MS,

166-

);

112+

const timeoutMs = resolvePositiveTimerTimeoutMs(params.timeoutMs, DEFAULT_MINIMAX_VLM_TIMEOUT_MS);

167113
168114

const res = await fetch(url, {

169115

method: "POST",

@@ -181,7 +127,10 @@ export async function minimaxUnderstandImage(params: {

181127
182128

const traceId = res.headers.get("Trace-Id") ?? "";

183129

if (!res.ok) {

184-

const body = await readErrorBodySnippet(res);

130+

const body = await readResponseBodySnippet(res, {

131+

maxBytes: MINIMAX_VLM_ERROR_BODY_MAX_BYTES,

132+

maxChars: MINIMAX_VLM_ERROR_BODY_MAX_CHARS,

133+

});

185134

const trace = traceId ? ` Trace-Id: ${traceId}` : "";

186135

throw new Error(

187136

`MiniMax VLM request failed (${res.status} ${res.statusText}).${trace}${

Original file line numberDiff line numberDiff line change

@@ -3,6 +3,7 @@

33

* This bypasses shared model runtime's content type system which does not have a "document" type.

44

*/

55
6+

import { readResponseBodySnippet } from "../../infra/http-error-body.js";

67

import { normalizeProviderTransportWithPlugin } from "../../plugins/provider-runtime.js";

78

import { isRecord } from "../../utils.js";

89

import { normalizeSecretInput } from "../../utils/normalize-secret-input.js";

@@ -17,57 +18,6 @@ const NATIVE_PDF_PROVIDER_FETCH_TIMEOUT_MS = 120_000;

1718

const NATIVE_PDF_ERROR_BODY_MAX_BYTES = 8 * 1024;

1819

const NATIVE_PDF_ERROR_BODY_MAX_CHARS = 400;

1920
20-

async function readErrorBodySnippet(res: Response): Promise<string> {

21-

try {

22-

const body = res.body;

23-

if (!body || typeof body.getReader !== "function") {

24-

return (await res.text()).slice(0, NATIVE_PDF_ERROR_BODY_MAX_CHARS);

25-

}

26-
27-

const reader = body.getReader();

28-

const chunks: Uint8Array[] = [];

29-

let total = 0;

30-

let truncated = false;

31-

try {

32-

while (true) {

33-

const { done, value } = await reader.read();

34-

if (done || !value?.byteLength) {

35-

break;

36-

}

37-

const remaining = NATIVE_PDF_ERROR_BODY_MAX_BYTES - total;

38-

if (remaining <= 0) {

39-

truncated = true;

40-

break;

41-

}

42-

if (value.byteLength > remaining) {

43-

chunks.push(value.subarray(0, remaining));

44-

total += remaining;

45-

truncated = true;

46-

break;

47-

}

48-

chunks.push(value);

49-

total += value.byteLength;

50-

if (total >= NATIVE_PDF_ERROR_BODY_MAX_BYTES) {

51-

truncated = true;

52-

break;

53-

}

54-

}

55-

} finally {

56-

if (truncated) {

57-

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

58-

}

59-

try {

60-

reader.releaseLock();

61-

} catch {}

62-

}

63-

return new TextDecoder()

64-

.decode(Buffer.concat(chunks, total))

65-

.slice(0, NATIVE_PDF_ERROR_BODY_MAX_CHARS);

66-

} catch {

67-

return "";

68-

}

69-

}

70-
7121

// ---------------------------------------------------------------------------

7222

// Anthropic – native PDF via Messages API

7323

// ---------------------------------------------------------------------------

@@ -133,7 +83,10 @@ export async function anthropicAnalyzePdf(params: {

13383

});

13484
13585

if (!res.ok) {

136-

const body = await readErrorBodySnippet(res);

86+

const body = await readResponseBodySnippet(res, {

87+

maxBytes: NATIVE_PDF_ERROR_BODY_MAX_BYTES,

88+

maxChars: NATIVE_PDF_ERROR_BODY_MAX_CHARS,

89+

});

13790

throw new Error(

13891

`Anthropic PDF request failed (${res.status} ${res.statusText})${body ? `: ${body}` : ""}`,

13992

);

@@ -218,7 +171,10 @@ export async function geminiAnalyzePdf(params: {

218171

});

219172
220173

if (!res.ok) {

221-

const body = await readErrorBodySnippet(res);

174+

const body = await readResponseBodySnippet(res, {

175+

maxBytes: NATIVE_PDF_ERROR_BODY_MAX_BYTES,

176+

maxChars: NATIVE_PDF_ERROR_BODY_MAX_CHARS,

177+

});

222178

throw new Error(

223179

`Gemini PDF request failed (${res.status} ${res.statusText})${body ? `: ${body}` : ""}`,

224180

);

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,52 @@

1+

export async function readResponseBodySnippet(

2+

response: Response,

3+

limits: { maxBytes: number; maxChars: number },

4+

): Promise<string> {

5+

try {

6+

const body = response.body;

7+

if (!body || typeof body.getReader !== "function") {

8+

return (await response.text()).slice(0, limits.maxChars);

9+

}

10+
11+

const reader = body.getReader();

12+

const chunks: Uint8Array[] = [];

13+

let total = 0;

14+

let truncated = false;

15+

try {

16+

while (true) {

17+

const { done, value } = await reader.read();

18+

if (done || !value?.byteLength) {

19+

break;

20+

}

21+

const remaining = limits.maxBytes - total;

22+

if (remaining <= 0) {

23+

truncated = true;

24+

break;

25+

}

26+

if (value.byteLength > remaining) {

27+

chunks.push(value.subarray(0, remaining));

28+

total += remaining;

29+

truncated = true;

30+

break;

31+

}

32+

chunks.push(value);

33+

total += value.byteLength;

34+

if (total >= limits.maxBytes) {

35+

truncated = true;

36+

break;

37+

}

38+

}

39+

} finally {

40+

if (truncated) {

41+

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

42+

}

43+

try {

44+

reader.releaseLock();

45+

} catch {}

46+

}

47+
48+

return new TextDecoder().decode(Buffer.concat(chunks, total)).slice(0, limits.maxChars);

49+

} catch {

50+

return "";

51+

}

52+

}