Skip to content

Commit 90bed46

Browse files
committed
Check if msg.content is array before accessing first element to avoid runtime errors
1 parent a70862c commit 90bed46

File tree

1 file changed

+12
-3
lines changed
  • packages/server/api/src/app/ai/chat

1 file changed

+12
-3
lines changed

packages/server/api/src/app/ai/chat/utils.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ export function mergeToolResultsIntoMessages(
2323
const msg = messages[i];
2424

2525
if (isToolMessage(msg)) {
26-
const toolResult = (msg.content as any[])[0];
27-
if (toolResult?.toolCallId) {
28-
toolResultsToMerge.push({ toolResult, messageIndex: i });
26+
if (Array.isArray(msg.content) && msg.content.length > 0) {
27+
const toolResult = msg.content[0];
28+
if (
29+
toolResult &&
30+
typeof toolResult === 'object' &&
31+
'toolCallId' in toolResult
32+
) {
33+
toolResultsToMerge.push({
34+
toolResult: toolResult as ToolResultPart,
35+
messageIndex: i,
36+
});
37+
}
2938
}
3039
continue;
3140
}

0 commit comments

Comments
 (0)