/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { Content } from '@google/genai'; import { HistoryItemWithoutId } from '../types.js'; import { Config, GitService, Logger } from '@shenjianz/geminicli-balancer-core'; import { LoadedSettings } from '../../config/settings.js'; import { UseHistoryManagerReturn } from '../hooks/useHistoryManager.js'; import type { HistoryItem } from '../types.js'; import { SessionStatsState } from '../contexts/SessionContext.js'; export interface CommandContext { services: { config: Config | null; settings: LoadedSettings; git: GitService | undefined; logger: Logger; }; ui: { /** Adds a new item to the history display. */ addItem: UseHistoryManagerReturn['addItem']; /** Clears all history items and the console screen. */ clear: () => void; /** * Sets the transient debug message displayed in the application footer in debug mode. */ setDebugMessage: (message: string) => void; /** The currently pending history item, if any. */ pendingItem: HistoryItemWithoutId | null; /** * Sets a pending item in the history, which is useful for indicating * that a long-running operation is in progress. * * @param item The history item to display as pending, or `null` to clear. */ setPendingItem: (item: HistoryItemWithoutId | null) => void; /** * Loads a new set of history items, replacing the current history. * * @param history The array of history items to load. */ loadHistory: UseHistoryManagerReturn['loadHistory']; /** Toggles a special display mode. */ toggleCorgiMode: () => void; }; session: { stats: SessionStatsState; }; } /** * The return type for a command action that results in scheduling a tool call. */ export interface ToolActionReturn { type: 'tool'; toolName: string; toolArgs: Record; } /** The return type for a command action that results in the app quitting. */ export interface QuitActionReturn { type: 'quit'; messages: HistoryItem[]; } /** * The return type for a command action that results in a simple message * being displayed to the user. */ export interface MessageActionReturn { type: 'message'; messageType: 'info' | 'error'; content: string; } /** * The return type for a command action that needs to open a dialog. */ export interface OpenDialogActionReturn { type: 'dialog'; dialog: 'help' | 'auth' | 'theme' | 'editor' | 'privacy'; } /** * The return type for a command action that results in replacing * the entire conversation history. */ export interface LoadHistoryActionReturn { type: 'load_history'; history: HistoryItemWithoutId[]; clientHistory: Content[]; } export type SlashCommandActionReturn = ToolActionReturn | MessageActionReturn | QuitActionReturn | OpenDialogActionReturn | LoadHistoryActionReturn; export interface SlashCommand { name: string; altName?: string; description?: string; action?: (context: CommandContext, args: string) => void | SlashCommandActionReturn | Promise; completion?: (context: CommandContext, partialArg: string) => Promise; subCommands?: SlashCommand[]; }