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

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
Jina AI
Jina AI
B
Blog
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
腾讯CDC
C
Check Point Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
罗磊的独立博客
B
Blog RSS Feed
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 叶小钗
M
MIT News - Artificial intelligence
GbyAI
GbyAI

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: share script bounded response reader · openclaw...
vincentkoc · 2026-05-30 · via Recent Commits to openclaw:main

@@ -6,6 +6,7 @@ import { GoogleGenAI, Modality } from "@google/genai";

66

import { chromium, type Browser } from "playwright";

77

import { createServer } from "vite";

88

import { buildOpenAIRealtimeVoiceProvider } from "../../extensions/openai/realtime-voice-provider.ts";

9+

import { readBoundedResponseText } from "../lib/bounded-response.ts";

910

import {

1011

parseStrictIntegerOption,

1112

previewForDevToolLog,

@@ -50,95 +51,16 @@ function shortError(error: unknown): string {

5051

return previewForDevToolLog(error instanceof Error ? error.message : String(error), 800);

5152

}

525353-

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

54-

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

55-

}

56-5754

async function readBoundedText(

5855

response: Response,

5956

label: string,

6057

maxBytes = OPENAI_HTTP_RESPONSE_MAX_BYTES,

6158

signal?: AbortSignal,

6259

): Promise<string> {

63-

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

64-

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

65-

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

66-

throw responseBodyTooLargeError(label, maxBytes);

67-

}

68-69-

if (!response.body) {

70-

return "";

71-

}

72-73-

const reader = response.body.getReader();

74-

const decoder = new TextDecoder();

75-

const chunks: string[] = [];

76-

let totalBytes = 0;

77-

let canceled = false;

78-79-

try {

80-

for (;;) {

81-

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

82-

canceled = true;

83-

});

84-

if (done) {

85-

const tail = decoder.decode();

86-

if (tail) {

87-

chunks.push(tail);

88-

}

89-

break;

90-

}

91-92-

totalBytes += value.byteLength;

93-

if (totalBytes > maxBytes) {

94-

canceled = true;

95-

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

96-

throw responseBodyTooLargeError(label, maxBytes);

97-

}

98-

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

99-

}

100-

} finally {

101-

if (!canceled) {

102-

reader.releaseLock();

103-

}

104-

}

105-106-

return chunks.join("");

107-

}

108-109-

async function readResponseChunk(

110-

reader: ReadableStreamDefaultReader<Uint8Array>,

111-

label: string,

112-

signal: AbortSignal | undefined,

113-

markCanceled: () => void,

114-

): Promise<ReadableStreamReadResult<Uint8Array>> {

115-

if (!signal) {

116-

return await reader.read();

117-

}

118-

if (signal.aborted) {

119-

markCanceled();

120-

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

121-

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

122-

}

123-124-

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

125-

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

126-

const onAbort = () => {

127-

markCanceled();

128-

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

129-

reject(

130-

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

131-

);

132-

};

133-

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

134-

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

60+

return await readBoundedResponseText(response, label, maxBytes, {

61+

createTooLargeError: (message) => new Error(message),

62+

signal,

13563

});

136-137-

try {

138-

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

139-

} finally {

140-

removeAbortListener?.();

141-

}

14264

}

1436514466

async function readBoundedJsonResponse(