Skip to content

Commit 1008df4

Browse files
committed
Refactor API configuration management handlers and standardize UI labels and discard confirmation messages throughout the application
- current behavior regarding api configurations: user can view the list of api configurations and set defaults. expected bahavior: user can only set defaults, replace the list with [list of configurations] placeholder. Remove now obsolete logic. - current behavior: in the api configuration editing UI, when changing model provider, user is not asked to select model. expected behavior: user should be asked to select model whenever they change model provider. - in settings, allow managing api configurations. We allow code duplications in handlers and messages. Re-use `apps/editor/src/views/actions`. - in settings: finish listing api configurations and editing them via `apps/editor/src/views/components/EditApiConfigurationForm/EditApiConfigurationForm.tsx` - Type '{ providers: Provider[]; api_configurations: ApiConfiguration[]; defaults: Record<ToolType, string | null>; edit_context_system_instructions: string; ... 52 more ...; scroll_to_section_on_load: NavItem | undefined; }' is missing the following properties from type 'Props': on_reorder_api_configurations, on_add_api_configuration, on_edit_api_configuration, on_delete_api_configuration - fix `apps/editor/src/views/settings/backend/message-handlers/handle-get-api-configurations.ts` - on <DefaultConfigurationSelector, we can't just pass props.api_configurations to 'configurations' prop beacuse api configuration is of type [Fragment] - we noticed updating api configuration in panel is more advanced, e.g. it validates reasoning effort or requires model selection when changing 'model provider' - when cancelling, the primary action should be 'Discard' instead of 'Save', secondary action (the always shown Cancel) should let user continue editing. Update texts accordingly. - when api configuration was modified but user clicks 'cancel', the modal appears correctly but form gets closed - should not.
1 parent f735e0f commit 1008df4

25 files changed

Lines changed: 657 additions & 209 deletions

‎apps/editor/src/views/actions/update-api-configuration/interactions/edit-reasoning-effort-for-api-config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const edit_reasoning_effort_for_api_config = async (
1414
return await new Promise<string | undefined>((resolve) => {
1515
const quick_pick = vscode.window.createQuickPick()
1616
quick_pick.items = effort_options
17-
quick_pick.title = 'Edit API Configuration'
17+
quick_pick.title = 'Edit Configuration'
1818
quick_pick.placeholder = 'Select reasoning effort'
1919
const close_button: vscode.QuickInputButton = {
2020
iconPath: new vscode.ThemeIcon('close'),

‎apps/editor/src/views/actions/update-api-configuration/update-api-configuration.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ export const update_api_configuration = async (params: {
5454
}
5555

5656
if (params.origin == 'cancel') {
57-
const save_changes_button = 'Save'
57+
const discard_button = 'Discard'
5858
const result = await vscode.window.showWarningMessage(
59-
dictionary.information_message.CONFIRM_SAVE_CHANGES_TO_ITEM(
59+
dictionary.information_message.CONFIRM_DISCARD_UNSAVED_CHANGES(
6060
'API configuration'
6161
),
6262
{
@@ -66,12 +66,14 @@ export const update_api_configuration = async (params: {
6666
'API configuration'
6767
)
6868
},
69-
save_changes_button
69+
discard_button
7070
)
7171

72-
if (result != save_changes_button) {
73-
return { success: true, has_changes: false }
72+
if (result != discard_button) {
73+
return { success: false, has_changes: true }
7474
}
75+
76+
return { success: true, has_changes: false }
7577
}
7678

7779
const new_config = {

‎apps/editor/src/views/actions/update-web-configuration.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export const update_web_configuration = async (params: {
5757
}
5858

5959
if (params.origin == 'cancel') {
60-
const save_changes_button = 'Save'
60+
const discard_button = 'Discard'
6161
const result = await vscode.window.showWarningMessage(
62-
dictionary.information_message.CONFIRM_SAVE_CHANGES_TO_ITEM(
62+
dictionary.information_message.CONFIRM_DISCARD_UNSAVED_CHANGES(
6363
'web configuration'
6464
),
6565
{
@@ -69,12 +69,14 @@ export const update_web_configuration = async (params: {
6969
'web configuration'
7070
)
7171
},
72-
save_changes_button
72+
discard_button
7373
)
7474

75-
if (result != save_changes_button) {
76-
return { success: true, has_changes: false }
75+
if (result != discard_button) {
76+
return { success: false, has_changes: true }
7777
}
78+
79+
return { success: true, has_changes: false }
7880
}
7981

8082
const updated_ui_web_configuration = { ...final_updated_web_configuration }
Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { PanelProvider } from '@/views/panel/backend/panel-provider'
22
import { PickModelProviderMessage } from '@/views/panel/types/messages'
3-
import { edit_model_provider_for_api_configuration } from '@/views/actions/update-api-configuration/interactions'
3+
import {
4+
edit_model_provider_for_api_configuration,
5+
edit_model_for_api_configuration
6+
} from '@/views/actions/update-api-configuration/interactions'
47
import { ModelProvidersManager } from '@/services/model-providers-manager'
8+
import { ModelFetcher } from '@/services/model-fetcher'
59

610
export const handle_pick_model_provider = async (
711
panel_provider: PanelProvider,
@@ -13,9 +17,29 @@ export const handle_pick_model_provider = async (
1317
message.current_model_provider_name
1418
)
1519
if (result) {
16-
panel_provider.send_message({
17-
command: 'NEWLY_PICKED_MODEL_PROVIDER',
18-
model_provider_name: result.model_provider_name
20+
const model_fetcher = new ModelFetcher()
21+
const temp_api_configuration = {
22+
id: '',
23+
model_provider_name: result.model_provider_name,
24+
model: ''
25+
}
26+
27+
const new_model = await edit_model_for_api_configuration({
28+
api_configuration: temp_api_configuration,
29+
providers_manager,
30+
model_fetcher,
31+
tool_type: message.tool_type
1932
})
33+
34+
if (new_model !== undefined) {
35+
panel_provider.send_message({
36+
command: 'NEWLY_PICKED_MODEL_PROVIDER',
37+
model_provider_name: result.model_provider_name
38+
})
39+
panel_provider.send_message({
40+
command: 'NEWLY_PICKED_API_MODEL',
41+
model_id: new_model
42+
})
43+
}
2044
}
2145
}

‎apps/editor/src/views/panel/frontend/Panel.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,16 @@ export const Panel = () => {
571571
</UiButton>
572572
</div>
573573
}
574-
title="Edit API Configuration"
574+
title="Edit Configuration"
575575
>
576576
<EditApiConfigurationForm
577577
api_configuration={updating_api_configuration}
578578
on_update={set_updated_api_configuration}
579579
pick_model_provider={(current) => {
580580
post_message(vscode, {
581581
command: 'PICK_MODEL_PROVIDER',
582-
current_model_provider_name: current
582+
current_model_provider_name: current,
583+
tool_type: api_prompt_type
583584
})
584585
}}
585586
pick_model={(provider, current) => {

‎apps/editor/src/views/panel/types/messages.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ export interface UpdateApiConfigurationMessage extends BaseMessage {
588588
export interface PickModelProviderMessage extends BaseMessage {
589589
command: 'PICK_MODEL_PROVIDER'
590590
current_model_provider_name?: string
591+
tool_type: ToolType
591592
}
592593

593594
export interface PickApiModelMessage extends BaseMessage {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { SettingsProvider } from '../settings-provider'
2+
import { create_api_configuration } from '@/views/actions/create-api-configuration/create-api-configuration'
3+
import { get_api_configuration_id } from '@/services/model-providers-manager'
4+
import { CreateApiConfigurationMessage } from '../../types/messages'
5+
6+
export const handle_create_api_configuration = async (
7+
provider: SettingsProvider,
8+
message: CreateApiConfigurationMessage
9+
): Promise<void> => {
10+
const result = await create_api_configuration({
11+
context: provider.context,
12+
tool_type: message.tool_type || 'intelligent-update',
13+
create_on_top: message.create_on_top,
14+
insertion_index: message.insertion_index
15+
})
16+
17+
if (result) {
18+
provider.postMessage({
19+
command: 'START_API_CONFIGURATION_CREATION',
20+
api_configuration: {
21+
...result.config,
22+
id: get_api_configuration_id(result.config)
23+
},
24+
insertion_index: result.insertion_index,
25+
tool_type: message.tool_type
26+
})
27+
}
28+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
2-
import { delete_api_configuration } from '../../../actions/delete-api-configuration'
1+
import { SettingsProvider } from '../settings-provider'
2+
import { delete_api_configuration } from '@/views/actions/delete-api-configuration'
33

44
export const handle_delete_api_configuration = async (
55
provider: SettingsProvider,
6-
api_configuration_id: string
6+
message: any
77
): Promise<void> => {
88
await delete_api_configuration({
99
context: provider.context,
10-
api_configuration_id
10+
api_configuration_id: message.api_configuration_id
1111
})
1212
}

‎apps/editor/src/views/settings/backend/message-handlers/handle-get-api-configurations.ts‎

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,39 @@
11
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
22
import {
33
ModelProvidersManager,
4-
ApiConfiguration,
54
get_api_configuration_id
65
} from '@/services/model-providers-manager'
7-
import { ApiConfigurationForClient } from '@/views/settings/types/messages'
8-
9-
const create_description = (api_configuration: ApiConfiguration): string => {
10-
const description_parts = [api_configuration.model_provider_name]
11-
if (api_configuration.temperature != null) {
12-
description_parts.push(`${api_configuration.temperature}`)
13-
}
14-
if (api_configuration.reasoning_effort) {
15-
description_parts.push(`${api_configuration.reasoning_effort}`)
16-
}
17-
return description_parts.join(' · ')
18-
}
6+
import { ApiConfiguration } from '@/views/settings/types/messages'
197

208
export const handle_get_api_configurations = async (
219
provider: SettingsProvider
2210
): Promise<void> => {
2311
const providers_manager = new ModelProvidersManager(provider.context)
2412

25-
const saved_api_configurations = await providers_manager.get_api_configurations()
13+
const saved_api_configurations =
14+
await providers_manager.get_api_configurations()
15+
16+
const api_configurations: ApiConfiguration[] = saved_api_configurations.map(
17+
(api_configuration) => ({
18+
...api_configuration,
19+
id: get_api_configuration_id(api_configuration)
20+
})
21+
)
2622

27-
const def_cac = await providers_manager.get_default_code_completions_api_configuration()
28-
const def_iu = await providers_manager.get_default_intelligent_update_api_configuration()
29-
const def_cm = await providers_manager.get_default_commit_messages_api_configuration()
23+
const def_cac =
24+
await providers_manager.get_default_code_completions_api_configuration()
25+
const def_iu =
26+
await providers_manager.get_default_intelligent_update_api_configuration()
27+
const def_cm =
28+
await providers_manager.get_default_commit_messages_api_configuration()
3029
const def_frf =
3130
await providers_manager.get_default_find_relevant_files_api_configuration()
32-
const def_vi = await providers_manager.get_default_voice_input_api_configuration()
33-
34-
const api_configurations_for_client: ApiConfigurationForClient[] = saved_api_configurations.map(
35-
(api_configuration) => {
36-
return {
37-
id: get_api_configuration_id(api_configuration),
38-
model: api_configuration.model,
39-
description: create_description(api_configuration)
40-
}
41-
}
42-
)
31+
const def_vi =
32+
await providers_manager.get_default_voice_input_api_configuration()
4333

4434
provider.postMessage({
4535
command: 'API_CONFIGURATIONS',
46-
api_configurations: api_configurations_for_client,
36+
api_configurations,
4737
defaults: {
4838
'code-at-cursor': def_cac ? get_api_configuration_id(def_cac) : null,
4939
'intelligent-update': def_iu ? get_api_configuration_id(def_iu) : null,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { SettingsProvider } from '../settings-provider'
2+
import { ModelProvidersManager } from '@/services/model-providers-manager'
3+
import { ModelFetcher } from '@/services/model-fetcher'
4+
import { edit_model_for_api_configuration } from '@/views/actions/update-api-configuration/interactions'
5+
6+
export const handle_pick_api_model = async (
7+
provider: SettingsProvider,
8+
message: any
9+
): Promise<void> => {
10+
const providers_manager = new ModelProvidersManager(provider.context)
11+
const model_fetcher = new ModelFetcher()
12+
13+
const model = await edit_model_for_api_configuration({
14+
api_configuration: {
15+
model_provider_name: message.model_provider_name,
16+
model: message.current_model
17+
} as any,
18+
providers_manager,
19+
model_fetcher,
20+
tool_type: message.tool_type
21+
})
22+
23+
if (model) {
24+
provider.postMessage({
25+
command: 'NEWLY_PICKED_API_MODEL',
26+
model_id: model
27+
})
28+
}
29+
}

0 commit comments

Comments
 (0)