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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
B
Blog
腾讯CDC
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
L
LangChain Blog
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS 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
improve: speed up provider tool-call streaming (#95957) ·...
vincentkoc · 2026-06-23 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -547,6 +547,62 @@ describe("google transport stream", () => {

547547

]);

548548

});

549549
550+

it("keeps duplicate tool-call ids distinct while retaining the first signature", async () => {

551+

guardedFetchMock.mockResolvedValueOnce(

552+

buildSseResponse([

553+

{

554+

candidates: [

555+

{

556+

content: {

557+

parts: [

558+

{

559+

functionCall: {

560+

id: "call_1",

561+

name: "first",

562+

args: { value: 1 },

563+

},

564+

thoughtSignature: "first_signature",

565+

},

566+

{

567+

functionCall: {

568+

id: "call_1",

569+

name: "second",

570+

args: { value: 2 },

571+

},

572+

},

573+

],

574+

},

575+

finishReason: "STOP",

576+

},

577+

],

578+

},

579+

]),

580+

);

581+
582+

const streamFn = createGoogleGenerativeAiTransportStreamFn();

583+

const stream = await Promise.resolve(

584+

streamFn(buildGeminiModel(), {

585+

messages: [{ role: "user", content: "hello", timestamp: 0 }],

586+

} as never),

587+

);

588+

const result = await stream.result();

589+

const toolCalls = result.content.filter((block) => block.type === "toolCall");

590+
591+

expect(toolCalls).toHaveLength(2);

592+

expect(toolCalls[0]).toMatchObject({

593+

id: "call_1",

594+

name: "first",

595+

arguments: { value: 1 },

596+

thoughtSignature: "first_signature",

597+

});

598+

expect(toolCalls[1]).toMatchObject({

599+

name: "second",

600+

arguments: { value: 2 },

601+

thoughtSignature: "first_signature",

602+

});

603+

expect(toolCalls[1]?.id).not.toBe("call_1");

604+

});

605+
550606

it("keeps explicit thinking signatures after tool-call SSE parts", async () => {

551607

guardedFetchMock.mockResolvedValueOnce(

552608

buildSseResponse([

Original file line numberDiff line numberDiff line change

@@ -1266,6 +1266,10 @@ function createGoogleTransportStreamFn(kind: CanonicalGoogleTransportApi): Strea

12661266

});

12671267

stream.push({ type: "start", partial: output as never });

12681268

let currentBlockIndex = -1;

1269+

const toolCallBlocksById = new Map<

1270+

string,

1271+

Extract<GoogleTransportContentBlock, { type: "toolCall" }>

1272+

>();

12691273

const chunks =

12701274

sse.firstChunk === undefined

12711275

? sse.chunks

@@ -1356,18 +1360,9 @@ function createGoogleTransportStreamFn(kind: CanonicalGoogleTransportApi): Strea

13561360

currentBlockIndex = -1;

13571361

}

13581362

const providedId = part.functionCall.id;

1359-

const isDuplicate = output.content.some(

1360-

(block) => block.type === "toolCall" && block.id === providedId,

1361-

);

13621363

const existingToolCall =

1363-

typeof providedId === "string"

1364-

? output.content.find(

1365-

(

1366-

block,

1367-

): block is Extract<GoogleTransportContentBlock, { type: "toolCall" }> =>

1368-

block.type === "toolCall" && block.id === providedId,

1369-

)

1370-

: undefined;

1364+

typeof providedId === "string" ? toolCallBlocksById.get(providedId) : undefined;

1365+

const isDuplicate = existingToolCall !== undefined;

13711366

const toolCallId =

13721367

providedId && !isDuplicate

13731368

? providedId

@@ -1383,6 +1378,9 @@ function createGoogleTransportStreamFn(kind: CanonicalGoogleTransportApi): Strea

13831378

),

13841379

};

13851380

output.content.push(toolCall);

1381+

if (!toolCallBlocksById.has(toolCall.id)) {

1382+

toolCallBlocksById.set(toolCall.id, toolCall);

1383+

}

13861384

const blockIndex = output.content.length - 1;

13871385

stream.push({

13881386

type: "toolcall_start",

Original file line numberDiff line numberDiff line change

@@ -135,6 +135,62 @@ describe("consumeGoogleGenerateContentStream", () => {

135135

});

136136

expect(output.usage.cost.total).toBeGreaterThan(0);

137137

});

138+
139+

it("generates a new id when Google repeats a streamed tool-call id", async () => {

140+

const output = createOutput();

141+

const stream = new AssistantMessageEventStream();

142+

const events: string[] = [];

143+

const collect = (async () => {

144+

for await (const event of stream) {

145+

events.push(event.type);

146+

}

147+

})();

148+
149+

await consumeGoogleGenerateContentStream({

150+

chunks: chunks([

151+

{

152+

candidates: [

153+

{

154+

content: {

155+

parts: [{ functionCall: { id: "call_1", name: "lookup", args: {} } }],

156+

},

157+

},

158+

],

159+

} as GenerateContentResponse,

160+

{

161+

candidates: [

162+

{

163+

content: {

164+

parts: [{ functionCall: { id: "call_1", name: "lookup", args: {} } }],

165+

},

166+

finishReason: FinishReason.STOP,

167+

},

168+

],

169+

} as GenerateContentResponse,

170+

]),

171+

model,

172+

output,

173+

stream,

174+

nextToolCallId: (name) => `generated-${name}`,

175+

});

176+

await collect;

177+
178+

expect(events.at(-1)).toBe("done");

179+

expect(output.content).toEqual([

180+

{

181+

type: "toolCall",

182+

id: "call_1",

183+

name: "lookup",

184+

arguments: {},

185+

},

186+

{

187+

type: "toolCall",

188+

id: "generated-lookup",

189+

name: "lookup",

190+

arguments: {},

191+

},

192+

]);

193+

});

138194

});

139195
140196

describe("buildGoogleGenerateContentParams", () => {

Original file line numberDiff line numberDiff line change

@@ -750,6 +750,12 @@ export async function consumeGoogleGenerateContentStream<T extends GoogleApiType

750750

params.stream.push({ type: "start", partial: params.output });

751751

let currentBlock: TextContent | ThinkingContent | null = null;

752752

const blocks = params.output.content;

753+

const toolCallIds = new Set<string>();

754+

for (const block of blocks) {

755+

if (block.type === "toolCall") {

756+

toolCallIds.add(block.id);

757+

}

758+

}

753759

const blockIndex = () => blocks.length - 1;

754760
755761

const endCurrentBlock = () => {

@@ -835,11 +841,7 @@ export async function consumeGoogleGenerateContentStream<T extends GoogleApiType

835841

if (part.functionCall) {

836842

endCurrentBlock();

837843

const providedId = part.functionCall.id;

838-

const needsNewId =

839-

!providedId ||

840-

params.output.content.some(

841-

(block) => block.type === "toolCall" && block.id === providedId,

842-

);

844+

const needsNewId = !providedId || toolCallIds.has(providedId);

843845

const toolCall: ToolCall = {

844846

type: "toolCall",

845847

id: needsNewId ? params.nextToolCallId(part.functionCall.name) : providedId,

@@ -849,6 +851,7 @@ export async function consumeGoogleGenerateContentStream<T extends GoogleApiType

849851

};

850852
851853

params.output.content.push(toolCall);

854+

toolCallIds.add(toolCall.id);

852855

params.stream.push({

853856

type: "toolcall_start",

854857

contentIndex: blockIndex(),

Original file line numberDiff line numberDiff line change

@@ -874,6 +874,57 @@ describe("openai-completions stop-reason tool-call guard", () => {

874874

expect(eventTypes.filter((type) => type === "thinking_end")).toHaveLength(1);

875875

});

876876
877+

it("attaches encrypted reasoning details to the matching streamed tool call", async () => {

878+

mockChunksRef.chunks = [

879+

makeToolCallChunk("call_1", "first", '{"value":1}'),

880+

{

881+

id: "chatcmpl-test",

882+

choices: [

883+

{

884+

index: 0,

885+

delta: {

886+

tool_calls: [

887+

{

888+

index: 1,

889+

id: "call_2",

890+

function: { name: "second", arguments: '{"value":2}' },

891+

type: "function",

892+

},

893+

],

894+

reasoning_details: [

895+

{

896+

type: "reasoning.encrypted",

897+

id: "call_1",

898+

data: "encrypted",

899+

},

900+

],

901+

} as OpenAICompatibleDelta & {

902+

reasoning_details: Array<Record<string, string>>;

903+

},

904+

},

905+

],

906+

},

907+

makeFinishChunk("tool_calls"),

908+

];

909+
910+

const stream = streamOpenAICompletions(model, context, {

911+

apiKey: "sk-test",

912+

});

913+

const result = await stream.result();

914+

const toolCalls = result.content.filter((block) => block.type === "toolCall");

915+
916+

expect(toolCalls).toHaveLength(2);

917+

expect(toolCalls[0]).toMatchObject({

918+

id: "call_1",

919+

thoughtSignature: JSON.stringify({

920+

type: "reasoning.encrypted",

921+

id: "call_1",

922+

data: "encrypted",

923+

}),

924+

});

925+

expect(toolCalls[1]).not.toHaveProperty("thoughtSignature");

926+

});

927+
877928

it("keeps one native reasoning block when content and reasoning co-occur", async () => {

878929

mockChunksRef.chunks = [

879930

{

Original file line numberDiff line numberDiff line change

@@ -186,6 +186,7 @@ export const streamOpenAICompletions: StreamFunction<

186186

let hasFinishReason = false;

187187

const toolCallBlocksByIndex = new Map<number, StreamingToolCallBlock>();

188188

const toolCallBlocksById = new Map<string, StreamingToolCallBlock>();

189+

const toolCallBlocksByFirstId = new Map<string, StreamingToolCallBlock>();

189190

const blocks = output.content as StreamingBlock[];

190191

// A block can be finished mid-stream (native reasoning sealed at the

191192

// text-lane transition) and again by the end-of-stream loop; guard so its

@@ -197,6 +198,11 @@ export const streamOpenAICompletions: StreamFunction<

197198

blocks.push(block);

198199

};

199200

const getContentIndex = (block: StreamingBlock) => contentIndices.get(block) ?? -1;

201+

const rememberFirstToolCallById = (id: string, block: StreamingToolCallBlock) => {

202+

if (!toolCallBlocksByFirstId.has(id)) {

203+

toolCallBlocksByFirstId.set(id, block);

204+

}

205+

};

200206

const finishBlock = (block: StreamingBlock) => {

201207

const contentIndex = getContentIndex(block);

202208

if (contentIndex === -1 || finishedBlocks.has(block)) {

@@ -311,6 +317,7 @@ export const streamOpenAICompletions: StreamFunction<

311317

}

312318

if (toolCall.id) {

313319

toolCallBlocksById.set(toolCall.id, block);

320+

rememberFirstToolCallById(toolCall.id, block);

314321

}

315322

appendBlock(block);

316323

stream.push({

@@ -432,6 +439,7 @@ export const streamOpenAICompletions: StreamFunction<

432439

if (!block.id && toolCall.id) {

433440

block.id = toolCall.id;

434441

toolCallBlocksById.set(toolCall.id, block);

442+

rememberFirstToolCallById(toolCall.id, block);

435443

}

436444

if (!block.name && toolCall.function?.name) {

437445

block.name = toolCall.function.name;

@@ -457,9 +465,7 @@ export const streamOpenAICompletions: StreamFunction<

457465

if (reasoningDetails && Array.isArray(reasoningDetails)) {

458466

for (const detail of reasoningDetails) {

459467

if (detail.type === "reasoning.encrypted" && detail.id && detail.data) {

460-

const matchingToolCall = output.content.find(

461-

(b) => b.type === "toolCall" && b.id === detail.id,

462-

) as ToolCall | undefined;

468+

const matchingToolCall = toolCallBlocksByFirstId.get(detail.id);

463469

if (matchingToolCall) {

464470

matchingToolCall.thoughtSignature = JSON.stringify(detail);

465471

}