mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-06 11:21:15 -07:00
feat(cli): refactor model command to support set and manage subcommands (#19221)
This commit is contained in:
@@ -4,14 +4,51 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {
|
||||
ModelSlashCommandEvent,
|
||||
logModelSlashCommand,
|
||||
} from '@google/gemini-cli-core';
|
||||
import {
|
||||
type CommandContext,
|
||||
CommandKind,
|
||||
type SlashCommand,
|
||||
} from './types.js';
|
||||
import { MessageType } from '../types.js';
|
||||
|
||||
export const modelCommand: SlashCommand = {
|
||||
name: 'model',
|
||||
const setModelCommand: SlashCommand = {
|
||||
name: 'set',
|
||||
description:
|
||||
'Set the model to use. Usage: /model set <model-name> [--persist]',
|
||||
kind: CommandKind.BUILT_IN,
|
||||
autoExecute: false,
|
||||
action: async (context: CommandContext, args: string) => {
|
||||
const parts = args.trim().split(/\s+/).filter(Boolean);
|
||||
if (parts.length === 0) {
|
||||
context.ui.addItem({
|
||||
type: MessageType.ERROR,
|
||||
text: 'Usage: /model set <model-name> [--persist]',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const modelName = parts[0];
|
||||
const persist = parts.includes('--persist');
|
||||
|
||||
if (context.services.config) {
|
||||
context.services.config.setModel(modelName, !persist);
|
||||
const event = new ModelSlashCommandEvent(modelName);
|
||||
logModelSlashCommand(context.services.config, event);
|
||||
|
||||
context.ui.addItem({
|
||||
type: MessageType.INFO,
|
||||
text: `Model set to ${modelName}${persist ? ' (persisted)' : ''}`,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const manageModelCommand: SlashCommand = {
|
||||
name: 'manage',
|
||||
description: 'Opens a dialog to configure the model',
|
||||
kind: CommandKind.BUILT_IN,
|
||||
autoExecute: true,
|
||||
@@ -25,3 +62,13 @@ export const modelCommand: SlashCommand = {
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const modelCommand: SlashCommand = {
|
||||
name: 'model',
|
||||
description: 'Manage model configuration',
|
||||
kind: CommandKind.BUILT_IN,
|
||||
autoExecute: false,
|
||||
subCommands: [manageModelCommand, setModelCommand],
|
||||
action: async (context: CommandContext, args: string) =>
|
||||
manageModelCommand.action!(context, args),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user