mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 10:10:56 -07:00
refactor(cli): switch useToolScheduler to event-driven engine (#18565)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user