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

推荐订阅源

云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
月光博客
月光博客
T
Tailwind CSS Blog
小众软件
小众软件
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
B
Blog RSS Feed
博客园 - 司徒正美
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
博客园 - Franky
U
Unit 42
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research

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(agents): repair smart-quoted tool args · openclaw/ope...
ferminquant · 2026-05-29 · via Recent Commits to openclaw:main

@@ -47,6 +47,86 @@ async function invokeProviderStream(params: {

4747

return await Promise.resolve(streamFn({} as never, {} as never, {} as never));

4848

}

494950+

type ToolCallRepairCaseResult = {

51+

partialArgs: unknown;

52+

streamedArgs: unknown;

53+

endMessageArgs: unknown;

54+

finalArgs: unknown;

55+

result: unknown;

56+

finalMessage: unknown;

57+

};

58+59+

async function runToolCallRepairCase(params: {

60+

toolName?: string;

61+

delta: string;

62+

provider?: string;

63+

modelApi?: string;

64+

}): Promise<ToolCallRepairCaseResult> {

65+

const toolName = params.toolName ?? "write";

66+

const partialToolCall = { type: "functionCall", name: toolName, arguments: {} };

67+

const streamedToolCall = { type: "functionCall", name: toolName, arguments: {} };

68+

const endMessageToolCall = { type: "functionCall", name: toolName, arguments: {} };

69+

const finalToolCall = { type: "functionCall", name: toolName, arguments: {} };

70+

const partialMessage = { role: "assistant", content: [partialToolCall] };

71+

const endMessage = { role: "assistant", content: [endMessageToolCall] };

72+

const finalMessage = { role: "assistant", content: [finalToolCall] };

73+74+

const stream = await invokeProviderStream({

75+

provider: params.provider ?? "openai-compatible",

76+

modelApi: params.modelApi ?? "openai-completions",

77+

baseFn: () =>

78+

createFakeStream({

79+

events: [

80+

{

81+

type: "toolcall_delta",

82+

contentIndex: 0,

83+

delta: `.functions.${toolName}:0 `,

84+

partial: partialMessage,

85+

},

86+

{

87+

type: "toolcall_delta",

88+

contentIndex: 0,

89+

delta: params.delta,

90+

partial: partialMessage,

91+

},

92+

{

93+

type: "toolcall_end",

94+

contentIndex: 0,

95+

toolCall: streamedToolCall,

96+

partial: partialMessage,

97+

message: endMessage,

98+

},

99+

],

100+

resultMessage: finalMessage,

101+

}),

102+

});

103+104+

for await (const item of stream) {

105+

// drain

106+

}

107+

const result = await stream.result();

108+109+

return {

110+

partialArgs: partialToolCall.arguments,

111+

streamedArgs: streamedToolCall.arguments,

112+

endMessageArgs: endMessageToolCall.arguments,

113+

finalArgs: finalToolCall.arguments,

114+

result,

115+

finalMessage,

116+

};

117+

}

118+119+

function expectAllToolCallArgs(

120+

result: ToolCallRepairCaseResult,

121+

expectedArgs: Record<string, unknown>,

122+

): void {

123+

expect(result.partialArgs).toEqual(expectedArgs);

124+

expect(result.streamedArgs).toEqual(expectedArgs);

125+

expect(result.endMessageArgs).toEqual(expectedArgs);

126+

expect(result.finalArgs).toEqual(expectedArgs);

127+

expect(result.result).toBe(result.finalMessage);

128+

}

129+50130

describe("shouldRepairMalformedToolCallArguments", () => {

51131

it("keeps the repair enabled for kimi providers on anthropic-messages", () => {

52132

expect(

@@ -182,4 +262,79 @@ describe("openai-completions malformed tool-call argument repair", () => {

182262

expect(result).toBe(finalMessage);

183263

},

184264

);

265+266+

it("repairs smart-quoted edit args with CJK, markdown, and inner smart quotes", async () => {

267+

const expectedContent =

268+

'更新 **草稿** with “smart”, “sure” and code "x"\nJSON-ish “alpha”, “path”: “ignored” snippet\nSee [“quoted”](https://example.test)\nconst re = /\\d+/;\n内部内容';

269+

const result = await runToolCallRepairCase({

270+

toolName: "edit",

271+

delta: String.raw` {“path”:“notes/报告.md”,“oldText”:“旧的 **草稿**”,“newText”:“更新 **草稿** with “smart”, “sure” and code "x"

272+

JSON-ish “alpha”, “path”: “ignored” snippet

273+

See [“quoted”](https://example.test)

274+

const re = /\d+/;

275+

内部内容”}`,

276+

});

277+278+

expectAllToolCallArgs(result, {

279+

path: "notes/报告.md",

280+

oldText: "旧的 **草稿**",

281+

newText: expectedContent,

282+

});

283+

});

284+285+

it("preserves smart quotes inside ASCII-delimited JSON content with trailing junk", async () => {

286+

const result = await runToolCallRepairCase({

287+

toolName: "read",

288+

delta: '{"path":"notes/日志.md","content":"包含“内部”与 **重点** 字样"}x',

289+

});

290+291+

expectAllToolCallArgs(result, {

292+

path: "notes/日志.md",

293+

content: "包含“内部”与 **重点** 字样",

294+

});

295+

});

296+297+

it("repairs smart-quoted command args that use workdir", async () => {

298+

const result = await runToolCallRepairCase({

299+

toolName: "exec",

300+

delta: "{“command“:“pwd“,“workdir“:“/tmp“}",

301+

});

302+303+

expectAllToolCallArgs(result, { command: "pwd", workdir: "/tmp" });

304+

});

305+306+

it("keeps duplicate-looking smart-quoted args inside content", async () => {

307+

const result = await runToolCallRepairCase({

308+

delta: String.raw` {“path”:“safe.txt”,“content”:“text ”, “path”: “other.txt””}`,

309+

});

310+311+

expectAllToolCallArgs(result, {

312+

path: "safe.txt",

313+

content: "text ”, “path”: “other.txt”",

314+

});

315+

});

316+317+

it("keeps unknown member-looking prose inside smart-quoted content", async () => {

318+

const result = await runToolCallRepairCase({

319+

delta: String.raw` {“path”:“safe.txt”,“content”:“Use ”, “foo”: “bar” in prose”}`,

320+

});

321+322+

expectAllToolCallArgs(result, {

323+

path: "safe.txt",

324+

content: "Use ”, “foo”: “bar” in prose",

325+

});

326+

expect(result.finalArgs).not.toHaveProperty("foo");

327+

});

328+329+

it("keeps member-looking prose inside mixed ASCII-key smart-quoted content", async () => {

330+

const result = await runToolCallRepairCase({

331+

delta: String.raw` {"path":"safe.txt","content":“Use ”, “foo”: “bar” in prose”}`,

332+

});

333+334+

expectAllToolCallArgs(result, {

335+

path: "safe.txt",

336+

content: "Use ”, “foo”: “bar” in prose",

337+

});

338+

expect(result.finalArgs).not.toHaveProperty("foo");

339+

});

185340

});