Skip to content

Commit dafc343

Browse files
committed
Ignore streaming AI SDK tool availability
1 parent 85bfd41 commit dafc343

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/api/transform/__tests__/ai-sdk.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,43 @@ describe("AI SDK conversion utilities", () => {
536536
expect(seenStreamingToolCallIds.has("call_1")).toBe(false)
537537
})
538538

539+
it("ignores tool-input-available for calls that are still streaming input", () => {
540+
const seenStreamingToolCallIds = new Set<string>()
541+
const chunks = [
542+
...processAiSdkStreamPart(
543+
{ type: "tool-input-start" as const, id: "call_1", toolName: "attempt_completion" },
544+
seenStreamingToolCallIds,
545+
),
546+
...processAiSdkStreamPart(
547+
{
548+
type: "tool-input-available" as const,
549+
toolCallId: "call_1",
550+
toolName: "attempt_completion",
551+
input: {},
552+
},
553+
seenStreamingToolCallIds,
554+
),
555+
...processAiSdkStreamPart(
556+
{
557+
type: "tool-call" as const,
558+
toolCallId: "call_1",
559+
toolName: "attempt_completion",
560+
input: { result: "done" },
561+
},
562+
seenStreamingToolCallIds,
563+
),
564+
]
565+
566+
expect(chunks).toEqual([
567+
{
568+
type: "tool_call",
569+
id: "call_1",
570+
name: "attempt_completion",
571+
arguments: '{"result":"done"}',
572+
},
573+
])
574+
})
575+
539576
it("processes source chunks with URL", () => {
540577
const part = {
541578
type: "source" as const,

src/api/transform/ai-sdk.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ export function* processAiSdkStreamPart(
249249
break
250250

251251
case "tool-input-available":
252+
if (seenStreamingToolCallIds?.has(getToolCallId(part))) {
253+
break
254+
}
255+
252256
yield {
253257
type: "tool_call",
254258
id: getToolCallId(part),

0 commit comments

Comments
 (0)