2026-01-21 00:18:42 -05:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2026 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type {
|
|
|
|
|
Config,
|
|
|
|
|
EditorType,
|
|
|
|
|
CompletedToolCall,
|
|
|
|
|
ToolCallRequestInfo,
|
|
|
|
|
} from '@google/gemini-cli-core';
|
|
|
|
|
import {
|
|
|
|
|
type TrackedScheduledToolCall,
|
|
|
|
|
type TrackedValidatingToolCall,
|
|
|
|
|
type TrackedWaitingToolCall,
|
|
|
|
|
type TrackedExecutingToolCall,
|
|
|
|
|
type TrackedCompletedToolCall,
|
|
|
|
|
type TrackedCancelledToolCall,
|
|
|
|
|
type MarkToolsAsSubmittedFn,
|
|
|
|
|
type CancelAllFn,
|
|
|
|
|
} from './useReactToolScheduler.js';
|
|
|
|
|
import {
|
|
|
|
|
useToolExecutionScheduler,
|
2026-02-08 15:28:37 -05:00
|
|
|
type TrackedToolCall,
|
2026-01-21 00:18:42 -05:00
|
|
|
} from './useToolExecutionScheduler.js';
|
|
|
|
|
|
|
|
|
|
// Re-export specific state types from Legacy, as the structures are compatible
|
|
|
|
|
// and useGeminiStream relies on them for narrowing.
|
|
|
|
|
export type {
|
2026-02-08 15:28:37 -05:00
|
|
|
TrackedToolCall,
|
2026-01-21 00:18:42 -05:00
|
|
|
TrackedScheduledToolCall,
|
|
|
|
|
TrackedValidatingToolCall,
|
|
|
|
|
TrackedWaitingToolCall,
|
|
|
|
|
TrackedExecutingToolCall,
|
|
|
|
|
TrackedCompletedToolCall,
|
|
|
|
|
TrackedCancelledToolCall,
|
2026-01-27 16:06:24 -08:00
|
|
|
MarkToolsAsSubmittedFn,
|
|
|
|
|
CancelAllFn,
|
2026-01-21 00:18:42 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Unified Schedule function (Promise<void> | Promise<CompletedToolCall[]>)
|
|
|
|
|
export type ScheduleFn = (
|
|
|
|
|
request: ToolCallRequestInfo | ToolCallRequestInfo[],
|
|
|
|
|
signal: AbortSignal,
|
|
|
|
|
) => Promise<void | CompletedToolCall[]>;
|
|
|
|
|
|
|
|
|
|
export type UseToolSchedulerReturn = [
|
|
|
|
|
TrackedToolCall[],
|
|
|
|
|
ScheduleFn,
|
|
|
|
|
MarkToolsAsSubmittedFn,
|
|
|
|
|
React.Dispatch<React.SetStateAction<TrackedToolCall[]>>,
|
|
|
|
|
CancelAllFn,
|
|
|
|
|
number,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
2026-02-08 15:28:37 -05:00
|
|
|
* Hook that uses the Event-Driven scheduler for tool execution.
|
2026-01-21 00:18:42 -05:00
|
|
|
*/
|
|
|
|
|
export function useToolScheduler(
|
|
|
|
|
onComplete: (tools: CompletedToolCall[]) => Promise<void>,
|
|
|
|
|
config: Config,
|
|
|
|
|
getPreferredEditor: () => EditorType | undefined,
|
|
|
|
|
): UseToolSchedulerReturn {
|
2026-02-08 15:28:37 -05:00
|
|
|
return useToolExecutionScheduler(
|
|
|
|
|
onComplete,
|
|
|
|
|
config,
|
|
|
|
|
getPreferredEditor,
|
|
|
|
|
) as UseToolSchedulerReturn;
|
2026-01-21 00:18:42 -05:00
|
|
|
}
|