Gemini: Fix parsing multiple tool calls in one response Fixes #4537

3246d2960c26a18985000b6ae88ece0f78650aa9

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +3 -2Ignore whitespace
public/scripts/tool-calling.js+3 -2
@@ -526,12 +526,13 @@ export class ToolManager {
526 for (let choiceIndex = 0; choiceIndex < parsed.candidates.length; choiceIndex++) {526 for (let choiceIndex = 0; choiceIndex < parsed.candidates.length; choiceIndex++) {
527 const candidate = parsed.candidates[choiceIndex];527 const candidate = parsed.candidates[choiceIndex];
528 if (Array.isArray(candidate?.content?.parts)) {528 if (Array.isArray(candidate?.content?.parts)) {
529 for (let toolCallIndex = 0; toolCallIndex < candidate.content.parts.length; toolCallIndex++) {529 for (let partIndex = 0; partIndex < candidate.content.parts.length; partIndex++) {
530 const part = candidate.content.parts[toolCallIndex];530 const part = candidate.content.parts[partIndex];
531 if (part.functionCall) {531 if (part.functionCall) {
532 if (!Array.isArray(toolCalls[choiceIndex])) {532 if (!Array.isArray(toolCalls[choiceIndex])) {
533 toolCalls[choiceIndex] = [];533 toolCalls[choiceIndex] = [];
534 }534 }
535 const toolCallIndex = toolCalls[choiceIndex].length;
535 if (toolCalls[choiceIndex][toolCallIndex] === undefined) {536 if (toolCalls[choiceIndex][toolCallIndex] === undefined) {
536 toolCalls[choiceIndex][toolCallIndex] = {};537 toolCalls[choiceIndex][toolCallIndex] = {};
537 }538 }