mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-09 21:00:56 -07:00
feat(cli): Add state management and plumbing for agent configuration dialog (#17259)
This commit is contained in:
@@ -188,6 +188,7 @@ describe('useSlashCommandProcessor', () => {
|
||||
openSettingsDialog: vi.fn(),
|
||||
openSessionBrowser: vi.fn(),
|
||||
openModelDialog: mockOpenModelDialog,
|
||||
openAgentConfigDialog: vi.fn(),
|
||||
openPermissionsDialog: vi.fn(),
|
||||
quit: mockSetQuittingMessages,
|
||||
setDebugMessage: vi.fn(),
|
||||
@@ -520,6 +521,82 @@ describe('useSlashCommandProcessor', () => {
|
||||
expect(mockFn).toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it('should handle "dialog: agentConfig" action with props', async () => {
|
||||
const mockOpenAgentConfigDialog = vi.fn();
|
||||
const agentDefinition = { name: 'test-agent' };
|
||||
const commandName = 'agentconfigcmd';
|
||||
const command = createTestCommand({
|
||||
name: commandName,
|
||||
action: vi.fn().mockResolvedValue({
|
||||
type: 'dialog',
|
||||
dialog: 'agentConfig',
|
||||
props: {
|
||||
name: 'test-agent',
|
||||
displayName: 'Test Agent',
|
||||
definition: agentDefinition,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
// Re-setup the hook with the mock action that we can inspect
|
||||
mockBuiltinLoadCommands.mockResolvedValue(Object.freeze([command]));
|
||||
mockFileLoadCommands.mockResolvedValue(Object.freeze([]));
|
||||
mockMcpLoadCommands.mockResolvedValue(Object.freeze([]));
|
||||
|
||||
let result!: { current: ReturnType<typeof useSlashCommandProcessor> };
|
||||
await act(async () => {
|
||||
const hook = renderHook(() =>
|
||||
useSlashCommandProcessor(
|
||||
mockConfig,
|
||||
mockSettings,
|
||||
mockAddItem,
|
||||
mockClearItems,
|
||||
mockLoadHistory,
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
{
|
||||
openAuthDialog: vi.fn(),
|
||||
openThemeDialog: vi.fn(),
|
||||
openEditorDialog: vi.fn(),
|
||||
openPrivacyNotice: vi.fn(),
|
||||
openSettingsDialog: vi.fn(),
|
||||
openSessionBrowser: vi.fn(),
|
||||
openModelDialog: vi.fn(),
|
||||
openAgentConfigDialog: mockOpenAgentConfigDialog,
|
||||
openPermissionsDialog: vi.fn(),
|
||||
quit: vi.fn(),
|
||||
setDebugMessage: vi.fn(),
|
||||
toggleCorgiMode: vi.fn(),
|
||||
toggleDebugProfiler: vi.fn(),
|
||||
dispatchExtensionStateUpdate: vi.fn(),
|
||||
addConfirmUpdateExtensionRequest: vi.fn(),
|
||||
setText: vi.fn(),
|
||||
},
|
||||
new Map(),
|
||||
true,
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
),
|
||||
);
|
||||
result = hook.result;
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(result.current.slashCommands).toHaveLength(1),
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await result.current.handleSlashCommand(`/${commandName}`);
|
||||
});
|
||||
|
||||
expect(mockOpenAgentConfigDialog).toHaveBeenCalledWith(
|
||||
'test-agent',
|
||||
'Test Agent',
|
||||
agentDefinition,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle "load_history" action', async () => {
|
||||
|
||||
@@ -19,6 +19,7 @@ import type {
|
||||
ExtensionsStartingEvent,
|
||||
ExtensionsStoppingEvent,
|
||||
ToolCallConfirmationDetails,
|
||||
AgentDefinition,
|
||||
} from '@google/gemini-cli-core';
|
||||
import {
|
||||
GitService,
|
||||
@@ -69,6 +70,11 @@ interface SlashCommandProcessorActions {
|
||||
openSettingsDialog: () => void;
|
||||
openSessionBrowser: () => void;
|
||||
openModelDialog: () => void;
|
||||
openAgentConfigDialog: (
|
||||
name: string,
|
||||
displayName: string,
|
||||
definition: AgentDefinition,
|
||||
) => void;
|
||||
openPermissionsDialog: (props?: { targetDirectory?: string }) => void;
|
||||
quit: (messages: HistoryItem[]) => void;
|
||||
setDebugMessage: (message: string) => void;
|
||||
@@ -224,6 +230,7 @@ export const useSlashCommandProcessor = (
|
||||
toggleDebugProfiler: actions.toggleDebugProfiler,
|
||||
toggleVimEnabled,
|
||||
reloadCommands,
|
||||
openAgentConfigDialog: actions.openAgentConfigDialog,
|
||||
extensionsUpdateState,
|
||||
dispatchExtensionStateUpdate: actions.dispatchExtensionStateUpdate,
|
||||
addConfirmUpdateExtensionRequest:
|
||||
@@ -452,6 +459,26 @@ export const useSlashCommandProcessor = (
|
||||
case 'model':
|
||||
actions.openModelDialog();
|
||||
return { type: 'handled' };
|
||||
case 'agentConfig': {
|
||||
const props = result.props as Record<string, unknown>;
|
||||
if (
|
||||
!props ||
|
||||
typeof props['name'] !== 'string' ||
|
||||
typeof props['displayName'] !== 'string' ||
|
||||
!props['definition']
|
||||
) {
|
||||
throw new Error(
|
||||
'Received invalid properties for agentConfig dialog action.',
|
||||
);
|
||||
}
|
||||
|
||||
actions.openAgentConfigDialog(
|
||||
props['name'],
|
||||
props['displayName'],
|
||||
props['definition'] as AgentDefinition,
|
||||
);
|
||||
return { type: 'handled' };
|
||||
}
|
||||
case 'permissions':
|
||||
actions.openPermissionsDialog(
|
||||
result.props as { targetDirectory?: string },
|
||||
|
||||
Reference in New Issue
Block a user