2026-02-18 15:28:17 -05:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2026 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2026-04-10 16:04:59 -07:00
|
|
|
import {
|
|
|
|
|
CoreToolCallStatus,
|
|
|
|
|
belongsInConfirmationQueue,
|
|
|
|
|
} from '@google/gemini-cli-core';
|
2026-02-18 15:28:17 -05:00
|
|
|
import {
|
|
|
|
|
type HistoryItemWithoutId,
|
|
|
|
|
type IndividualToolCallDisplay,
|
|
|
|
|
} from '../types.js';
|
2026-04-10 16:04:59 -07:00
|
|
|
import {
|
|
|
|
|
getAllToolCalls,
|
|
|
|
|
buildToolVisibilityContextFromDisplay,
|
|
|
|
|
} from './historyUtils.js';
|
2026-02-18 15:28:17 -05:00
|
|
|
|
|
|
|
|
export interface ConfirmingToolState {
|
|
|
|
|
tool: IndividualToolCallDisplay;
|
|
|
|
|
index: number;
|
|
|
|
|
total: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selects the "head" of the confirmation queue.
|
|
|
|
|
*/
|
|
|
|
|
export function getConfirmingToolState(
|
|
|
|
|
pendingHistoryItems: HistoryItemWithoutId[],
|
|
|
|
|
): ConfirmingToolState | null {
|
2026-03-23 18:49:51 -07:00
|
|
|
const allPendingTools = getAllToolCalls(pendingHistoryItems);
|
2026-02-18 15:28:17 -05:00
|
|
|
|
|
|
|
|
const confirmingTools = allPendingTools.filter(
|
|
|
|
|
(tool) => tool.status === CoreToolCallStatus.AwaitingApproval,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (confirmingTools.length === 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-10 16:04:59 -07:00
|
|
|
const actionablePendingTools = allPendingTools.filter((tool) =>
|
|
|
|
|
belongsInConfirmationQueue(buildToolVisibilityContextFromDisplay(tool)),
|
|
|
|
|
);
|
|
|
|
|
|
2026-02-18 15:28:17 -05:00
|
|
|
const head = confirmingTools[0];
|
2026-04-10 16:04:59 -07:00
|
|
|
const headIndexInFullList = actionablePendingTools.findIndex(
|
2026-02-18 15:28:17 -05:00
|
|
|
(tool) => tool.callId === head.callId,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
tool: head,
|
|
|
|
|
index: headIndexInFullList + 1,
|
2026-04-10 16:04:59 -07:00
|
|
|
total: actionablePendingTools.length,
|
2026-02-18 15:28:17 -05:00
|
|
|
};
|
|
|
|
|
}
|