From 7b9afdbb2fc97496519b3523e3ea55e8ce47910e Mon Sep 17 00:00:00 2001 From: dal Date: Sun, 24 Aug 2025 21:51:13 -0600 Subject: [PATCH] Enhance tool result conversion by validating toolCallId - Added checks to ensure toolCallId exists and is a valid string before processing tool results. - Preserves the original part if toolCallId is missing or invalid, improving robustness in message conversion. --- packages/ai/src/utils/message-conversion.ts | 6 ++++++ .../src/queries/messages/chatConversationHistory.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/ai/src/utils/message-conversion.ts b/packages/ai/src/utils/message-conversion.ts index 7d15e8490..1508718f5 100644 --- a/packages/ai/src/utils/message-conversion.ts +++ b/packages/ai/src/utils/message-conversion.ts @@ -167,6 +167,12 @@ function convertToolResultPart(part: unknown): unknown { } } + // Ensure toolCallId exists and is valid + // If it's missing or invalid, preserve the original part + if (!rest.toolCallId || typeof rest.toolCallId !== 'string') { + return part; + } + return { ...rest, output, diff --git a/packages/database/src/queries/messages/chatConversationHistory.ts b/packages/database/src/queries/messages/chatConversationHistory.ts index 5717e862c..7612e1935 100644 --- a/packages/database/src/queries/messages/chatConversationHistory.ts +++ b/packages/database/src/queries/messages/chatConversationHistory.ts @@ -166,6 +166,12 @@ function convertToolResultPart(part: unknown): unknown { } } + // Ensure toolCallId exists and is valid + // If it's missing or invalid, preserve the original part + if (!rest.toolCallId || typeof rest.toolCallId !== 'string') { + return part; + } + return { ...rest, output,