File size: 2,042 Bytes
52efc7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | /**
* @license
* Copyright 2025 Google LLC
* 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';
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.agentContext?.config) {
context.services.agentContext.config.setModel(modelName, !persist);
const event = new ModelSlashCommandEvent(modelName);
logModelSlashCommand(context.services.agentContext.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,
action: async (context: CommandContext) => {
if (context.services.agentContext?.config) {
await context.services.agentContext.config.refreshUserQuota();
}
return {
type: 'dialog',
dialog: 'model',
};
},
};
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),
};
|