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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
小众软件
小众软件
美团技术团队
Martin Fowler
Martin Fowler
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
J
Java Code Geeks
B
Blog
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
博客园 - Franky

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(providers): harden malformed success responses · open...
vincentkoc · 2026-05-16 · via Recent Commits to openclaw:main

@@ -27,27 +27,74 @@ const POLL_INTERVAL_MS = 5_000;

2727

const MAX_POLL_ATTEMPTS = 120;

28282929

type BytePlusTaskCreateResponse = {

30-

id?: string;

30+

id?: unknown;

3131

};

32323333

type BytePlusTaskResponse = {

34-

id?: string;

35-

model?: string;

36-

status?: "running" | "failed" | "queued" | "succeeded" | "cancelled";

37-

error?: {

38-

code?: string;

39-

message?: string;

40-

};

41-

content?: {

42-

video_url?: string;

43-

last_frame_url?: string;

44-

file_url?: string;

45-

};

46-

duration?: number;

47-

ratio?: string;

48-

resolution?: string;

34+

id?: unknown;

35+

model?: unknown;

36+

status?: unknown;

37+

error?: unknown;

38+

content?: unknown;

39+

duration?: unknown;

40+

ratio?: unknown;

41+

resolution?: unknown;

4942

};

504344+

type BytePlusTaskStatus = "running" | "failed" | "queued" | "succeeded" | "cancelled";

45+46+

function isRecord(value: unknown): value is Record<string, unknown> {

47+

return typeof value === "object" && value !== null && !Array.isArray(value);

48+

}

49+50+

async function readBytePlusJsonResponse<T>(

51+

response: Pick<Response, "json">,

52+

label: string,

53+

): Promise<T> {

54+

let payload: unknown;

55+

try {

56+

payload = await response.json();

57+

} catch (cause) {

58+

throw new Error(`${label}: malformed JSON response`, { cause });

59+

}

60+

if (!isRecord(payload)) {

61+

throw new Error(`${label}: malformed JSON response`);

62+

}

63+

return payload as T;

64+

}

65+66+

function readBytePlusTaskStatus(payload: BytePlusTaskResponse): BytePlusTaskStatus {

67+

const status = normalizeOptionalString(payload.status);

68+

switch (status) {

69+

case "running":

70+

case "failed":

71+

case "queued":

72+

case "succeeded":

73+

case "cancelled":

74+

return status;

75+

case undefined:

76+

throw new Error("BytePlus video status response missing task status");

77+

default:

78+

throw new Error(`BytePlus video status response returned unknown task status: ${status}`);

79+

}

80+

}

81+82+

function readBytePlusErrorMessage(error: unknown): string | undefined {

83+

return isRecord(error) ? normalizeOptionalString(error.message) : undefined;

84+

}

85+86+

function readBytePlusVideoUrl(payload: BytePlusTaskResponse): string {

87+

const content = payload.content;

88+

if (content !== undefined && !isRecord(content)) {

89+

throw new Error("BytePlus video generation completed with malformed content");

90+

}

91+

const videoUrl = normalizeOptionalString(content?.video_url);

92+

if (!videoUrl) {

93+

throw new Error("BytePlus video generation completed without a video URL");

94+

}

95+

return videoUrl;

96+

}

97+5198

function resolveBytePlusVideoBaseUrl(req: VideoGenerationRequest): string {

5299

return (

53100

normalizeOptionalString(req.cfg?.models?.providers?.byteplus?.baseUrl) ?? BYTEPLUS_BASE_URL

@@ -100,14 +147,17 @@ async function pollBytePlusTask(params: {

100147

provider: "byteplus",

101148

requestFailedMessage: "BytePlus video status request failed",

102149

});

103-

const payload = (await response.json()) as BytePlusTaskResponse;

104-

switch (normalizeOptionalString(payload.status)) {

150+

const payload = await readBytePlusJsonResponse<BytePlusTaskResponse>(

151+

response,

152+

"BytePlus video status request failed",

153+

);

154+

switch (readBytePlusTaskStatus(payload)) {

105155

case "succeeded":

106156

return payload;

107157

case "failed":

108158

case "cancelled":

109159

throw new Error(

110-

normalizeOptionalString(payload.error?.message) || "BytePlus video generation failed",

160+

readBytePlusErrorMessage(payload.error) || "BytePlus video generation failed",

111161

);

112162

case "queued":

113163

case "running":

@@ -292,7 +342,10 @@ export function buildBytePlusVideoGenerationProvider(): VideoGenerationProvider

292342

});

293343

try {

294344

await assertOkOrThrowHttpError(response, "BytePlus video generation failed");

295-

const submitted = (await response.json()) as BytePlusTaskCreateResponse;

345+

const submitted = await readBytePlusJsonResponse<BytePlusTaskCreateResponse>(

346+

response,

347+

"BytePlus video generation failed",

348+

);

296349

const taskId = normalizeOptionalString(submitted.id);

297350

if (!taskId) {

298351

throw new Error("BytePlus video generation response missing task id");

@@ -307,10 +360,7 @@ export function buildBytePlusVideoGenerationProvider(): VideoGenerationProvider

307360

baseUrl,

308361

fetchFn,

309362

});

310-

const videoUrl = normalizeOptionalString(completed.content?.video_url);

311-

if (!videoUrl) {

312-

throw new Error("BytePlus video generation completed without a video URL");

313-

}

363+

const videoUrl = readBytePlusVideoUrl(completed);

314364

const video = await downloadBytePlusVideo({

315365

url: videoUrl,

316366

timeoutMs: createProviderOperationTimeoutResolver({

@@ -321,14 +371,14 @@ export function buildBytePlusVideoGenerationProvider(): VideoGenerationProvider

321371

});

322372

return {

323373

videos: [video],

324-

model: completed.model ?? resolvedModel,

374+

model: normalizeOptionalString(completed.model) ?? resolvedModel,

325375

metadata: {

326376

taskId,

327-

status: completed.status,

377+

status: normalizeOptionalString(completed.status),

328378

videoUrl,

329-

ratio: completed.ratio,

330-

resolution: completed.resolution,

331-

duration: completed.duration,

379+

ratio: normalizeOptionalString(completed.ratio),

380+

resolution: normalizeOptionalString(completed.resolution),

381+

duration: typeof completed.duration === "number" ? completed.duration : undefined,

332382

},

333383

};

334384

} finally {