refactor(cli): switch useToolScheduler to event-driven engine (#18565)

This commit is contained in:
Abhi
2026-02-08 15:28:37 -05:00
committed by GitHub
parent 4a48d7cf93
commit 802bcf4dee
4 changed files with 9 additions and 100 deletions

View File

@@ -11,8 +11,6 @@ import type {
ToolCallRequestInfo,
} from '@google/gemini-cli-core';
import {
useReactToolScheduler,
type TrackedToolCall as LegacyTrackedToolCall,
type TrackedScheduledToolCall,
type TrackedValidatingToolCall,
type TrackedWaitingToolCall,
@@ -24,12 +22,13 @@ import {
} from './useReactToolScheduler.js';
import {
useToolExecutionScheduler,
type TrackedToolCall as NewTrackedToolCall,
type TrackedToolCall,
} from './useToolExecutionScheduler.js';
// Re-export specific state types from Legacy, as the structures are compatible
// and useGeminiStream relies on them for narrowing.
export type {
TrackedToolCall,
TrackedScheduledToolCall,
TrackedValidatingToolCall,
TrackedWaitingToolCall,
@@ -40,9 +39,6 @@ export type {
CancelAllFn,
};
// Unified type that covers both implementations
export type TrackedToolCall = LegacyTrackedToolCall | NewTrackedToolCall;
// Unified Schedule function (Promise<void> | Promise<CompletedToolCall[]>)
export type ScheduleFn = (
request: ToolCallRequestInfo | ToolCallRequestInfo[],
@@ -59,30 +55,16 @@ export type UseToolSchedulerReturn = [
];
/**
* Facade hook that switches between the Legacy and Event-Driven schedulers
* based on configuration.
*
* Note: This conditionally calls hooks, which technically violates the standard
* Rules of Hooks linting. However, this is safe here because
* `config.isEventDrivenSchedulerEnabled()` is static for the lifetime of the
* application session (it essentially acts as a compile-time feature flag).
* Hook that uses the Event-Driven scheduler for tool execution.
*/
export function useToolScheduler(
onComplete: (tools: CompletedToolCall[]) => Promise<void>,
config: Config,
getPreferredEditor: () => EditorType | undefined,
): UseToolSchedulerReturn {
const isEventDriven = config.isEventDrivenSchedulerEnabled();
// Note: We return the hooks directly without casting. They return compatible
// tuple structures, but use explicit tuple signatures rather than the
// UseToolSchedulerReturn named type to avoid circular dependencies back to
// this facade.
if (isEventDriven) {
// eslint-disable-next-line react-hooks/rules-of-hooks
return useToolExecutionScheduler(onComplete, config, getPreferredEditor);
}
// eslint-disable-next-line react-hooks/rules-of-hooks
return useReactToolScheduler(onComplete, config, getPreferredEditor);
return useToolExecutionScheduler(
onComplete,
config,
getPreferredEditor,
) as UseToolSchedulerReturn;
}