|
| 1 | +import { SettingsProvider } from '@/views/settings/backend/settings-provider' |
| 2 | +import { |
| 3 | + ModelProvidersManager, |
| 4 | + ToolConfig, |
| 5 | + get_tool_config_id |
| 6 | +} from '@/services/model-providers-manager' |
| 7 | +import { ConfigurationForClient } from '@/views/settings/types/messages' |
| 8 | + |
| 9 | +const create_description = (config: ToolConfig): string => { |
| 10 | + const description_parts = [config.provider_name] |
| 11 | + if (config.temperature != null) { |
| 12 | + description_parts.push(`${config.temperature}`) |
| 13 | + } |
| 14 | + if (config.reasoning_effort) { |
| 15 | + description_parts.push(`${config.reasoning_effort}`) |
| 16 | + } |
| 17 | + return description_parts.join(' · ') |
| 18 | +} |
| 19 | + |
| 20 | +export const handle_get_configurations = async ( |
| 21 | + provider: SettingsProvider, |
| 22 | + type: |
| 23 | + | 'code-completions' |
| 24 | + | 'edit-context' |
| 25 | + | 'intelligent-update' |
| 26 | + | 'commit-messages' |
| 27 | + | 'prune-context' |
| 28 | +): Promise<void> => { |
| 29 | + const providers_manager = new ModelProvidersManager(provider.context) |
| 30 | + |
| 31 | + let saved_configs: ToolConfig[] = [] |
| 32 | + let default_config: ToolConfig | undefined |
| 33 | + let command: string |
| 34 | + |
| 35 | + switch (type) { |
| 36 | + case 'code-completions': |
| 37 | + saved_configs = |
| 38 | + await providers_manager.get_code_completions_tool_configs() |
| 39 | + default_config = |
| 40 | + await providers_manager.get_default_code_completions_config() |
| 41 | + command = 'CODE_COMPLETIONS_CONFIGURATIONS' |
| 42 | + break |
| 43 | + case 'edit-context': |
| 44 | + saved_configs = await providers_manager.get_edit_context_tool_configs() |
| 45 | + command = 'EDIT_CONTEXT_CONFIGURATIONS' |
| 46 | + break |
| 47 | + case 'intelligent-update': |
| 48 | + saved_configs = |
| 49 | + await providers_manager.get_intelligent_update_tool_configs() |
| 50 | + default_config = |
| 51 | + await providers_manager.get_default_intelligent_update_config() |
| 52 | + command = 'INTELLIGENT_UPDATE_CONFIGURATIONS' |
| 53 | + break |
| 54 | + case 'commit-messages': |
| 55 | + saved_configs = await providers_manager.get_commit_messages_tool_configs() |
| 56 | + default_config = |
| 57 | + await providers_manager.get_default_commit_messages_config() |
| 58 | + command = 'COMMIT_MESSAGES_CONFIGURATIONS' |
| 59 | + break |
| 60 | + case 'prune-context': |
| 61 | + saved_configs = await providers_manager.get_prune_context_tool_configs() |
| 62 | + command = 'PRUNE_CONTEXT_CONFIGURATIONS' |
| 63 | + break |
| 64 | + } |
| 65 | + |
| 66 | + const default_config_id = default_config |
| 67 | + ? get_tool_config_id(default_config) |
| 68 | + : null |
| 69 | + |
| 70 | + const configs_for_client: ConfigurationForClient[] = saved_configs.map( |
| 71 | + (config) => { |
| 72 | + return { |
| 73 | + id: get_tool_config_id(config), |
| 74 | + model: config.model, |
| 75 | + description: create_description(config), |
| 76 | + is_default: get_tool_config_id(config) === default_config_id |
| 77 | + } |
| 78 | + } |
| 79 | + ) |
| 80 | + |
| 81 | + provider.postMessage({ |
| 82 | + command, |
| 83 | + configurations: configs_for_client |
| 84 | + } as any) |
| 85 | +} |
0 commit comments