|
| 1 | +import * as vscode from 'vscode' |
| 2 | +import { SelectDefaultAgentConfigurationMessage } from '@/views/settings/types/messages' |
| 3 | +import { t } from '@/i18n' |
| 4 | + |
| 5 | +export const handle_select_default_cli_configuration = async ( |
| 6 | + message: SelectDefaultAgentConfigurationMessage |
| 7 | +): Promise<void> => { |
| 8 | + const config = vscode.workspace.getConfiguration('codeWebChat') |
| 9 | + const agent_configs = config.get<any[]>('agents', []) || [] |
| 10 | + if (agent_configs.length === 0) return |
| 11 | + |
| 12 | + const items = agent_configs.map((c) => { |
| 13 | + const is_unnamed = /^\(\d+\)$/.test(c.name.trim()) |
| 14 | + const display_name = is_unnamed ? c.agent : c.name.replace(/ \(\d+\)$/, '') |
| 15 | + |
| 16 | + const description_parts = [] |
| 17 | + if (c.agent !== display_name) { |
| 18 | + description_parts.push(c.agent) |
| 19 | + } |
| 20 | + if (c.flags) { |
| 21 | + description_parts.push( |
| 22 | + Array.isArray(c.flags) ? c.flags.join(' ') : c.flags |
| 23 | + ) |
| 24 | + } |
| 25 | + |
| 26 | + return { |
| 27 | + label: display_name, |
| 28 | + description: |
| 29 | + description_parts.length > 0 ? description_parts.join(' ') : undefined, |
| 30 | + cli_configuration_name: c.name |
| 31 | + } |
| 32 | + }) |
| 33 | + |
| 34 | + const quick_pick = vscode.window.createQuickPick< |
| 35 | + vscode.QuickPickItem & { cli_configuration_name: string } |
| 36 | + >() |
| 37 | + quick_pick.items = items |
| 38 | + quick_pick.title = t('common.title.agents') |
| 39 | + quick_pick.placeholder = t('common.placeholder.select-agent') |
| 40 | + |
| 41 | + const close_button: vscode.QuickInputButton = { |
| 42 | + iconPath: new vscode.ThemeIcon('close'), |
| 43 | + tooltip: t('common.close') |
| 44 | + } |
| 45 | + quick_pick.buttons = [close_button] |
| 46 | + |
| 47 | + quick_pick.onDidTriggerButton((button) => { |
| 48 | + if (button === close_button) { |
| 49 | + quick_pick.hide() |
| 50 | + } |
| 51 | + }) |
| 52 | + |
| 53 | + quick_pick.onDidAccept(async () => { |
| 54 | + const selected = quick_pick.selectedItems[0] |
| 55 | + quick_pick.hide() |
| 56 | + |
| 57 | + if (selected) { |
| 58 | + const updated = agent_configs.map((c) => { |
| 59 | + const new_c = { ...c } |
| 60 | + if (message.cli_feature == 'agentic-search') { |
| 61 | + if (c.name == selected.cli_configuration_name) { |
| 62 | + new_c.isDefaultForAgenticSearch = true |
| 63 | + } else { |
| 64 | + delete new_c.isDefaultForAgenticSearch |
| 65 | + } |
| 66 | + } else if (message.cli_feature == 'code-at-cursor') { |
| 67 | + if (c.name == selected.cli_configuration_name) { |
| 68 | + new_c.isDefaultForCodeAtCursor = true |
| 69 | + } else { |
| 70 | + delete new_c.isDefaultForCodeAtCursor |
| 71 | + } |
| 72 | + } |
| 73 | + return new_c |
| 74 | + }) |
| 75 | + await config.update('agents', updated, vscode.ConfigurationTarget.Global) |
| 76 | + } |
| 77 | + }) |
| 78 | + |
| 79 | + quick_pick.onDidHide(() => quick_pick.dispose()) |
| 80 | + quick_pick.show() |
| 81 | +} |
0 commit comments