@@ -275,29 +275,6 @@ export function getReasoningDeltaFromStreamChunk(
275275 return "";
276276 }
277277
278-export function consumePendingToolInputStart(
279- pendingToolStartsById: Set<string>,
280- pendingToolStartsByName: Map<string, number>,
281- toolCallId: string,
282- toolName: string,
283-): boolean {
284- if (toolCallId.length > 0) {
285- if (!pendingToolStartsById.has(toolCallId)) return false;
286- pendingToolStartsById.delete(toolCallId);
287- return true;
288- }
289-
290- if (toolName.length === 0) return false;
291- const pending = pendingToolStartsByName.get(toolName) ?? 0;
292- if (pending <= 0) return false;
293- if (pending === 1) {
294- pendingToolStartsByName.delete(toolName);
295- } else {
296- pendingToolStartsByName.set(toolName, pending - 1);
297- }
298- return true;
299-}
300-
301278 type StreamTextResult = ReturnType<typeof streamText>;
302279 type StreamTextResultFull = StreamTextResult & {
303280 fullStream: AsyncIterable<StreamChunk>;
@@ -1116,9 +1093,6 @@ export async function* runTurn(options: {
11161093 // awaited, causing an unhandled rejection that crashes the app.
11171094 // We catch it here to mark it as handled (awaiting it later will still throw).
11181095 result.response.catch(() => {});
1119- const pendingToolStartsById = new Set<string>();
1120- const pendingToolStartsByName = new Map<string, number>();
1121-
11221096 // Stream events
11231097 for await (const chunk of result.fullStream) {
11241098 const c = chunk as StreamChunk;
@@ -1161,26 +1135,10 @@ export async function* runTurn(options: {
11611135 }
11621136
11631137 case "tool-input-start": {
1164- const toolName =
1165- typeof c.toolName === "string" && c.toolName.length > 0
1166- ? c.toolName
1167- : "";
1168- const toolCallId = String(c.toolCallId ?? "");
1169- if (toolCallId.length > 0) {
1170- pendingToolStartsById.add(toolCallId);
1171- } else if (toolName.length > 0) {
1172- pendingToolStartsByName.set(
1173- toolName,
1174- (pendingToolStartsByName.get(toolName) ?? 0) + 1,
1175- );
1176- } else {
1177- break;
1178- }
11791138 yield {
1180- type: "tool-call-start",
1181- toolCallId,
1182- toolName,
1183- // tool-input-start usually arrives before full args are available.
1139+ type: "tool-input-start",
1140+ toolCallId: String(c.toolCallId ?? ""),
1141+ toolName: String(c.toolName ?? ""),
11841142 args: c.input ?? c.args,
11851143 };
11861144 break;
@@ -1189,16 +1147,6 @@ export async function* runTurn(options: {
11891147 case "tool-call": {
11901148 const toolName = String(c.toolName ?? "");
11911149 const toolCallId = String(c.toolCallId ?? "");
1192- if (
1193- consumePendingToolInputStart(
1194- pendingToolStartsById,
1195- pendingToolStartsByName,
1196- toolCallId,
1197- toolName,
1198- )
1199- ) {
1200- break;
1201- }
12021150 yield {
12031151 type: "tool-call-start",
12041152 toolCallId,