Skip to content

Commit 295b391

Browse files
committed
Refactor default config resolution logic to centralize fallback behavior and update equality checks to use loose comparison
1 parent ce3c2f4 commit 295b391

6 files changed

Lines changed: 66 additions & 56 deletions

File tree

‎apps/editor/src/services/model-providers-manager.ts‎

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class ModelProvidersManager {
248248

249249
if (default_config_from_settings) {
250250
const provider = this._providers.find(
251-
(p) => p.name === default_config_from_settings.providerName
251+
(p) => p.name == default_config_from_settings.providerName
252252
)
253253
const tool_config: ToolConfig = {
254254
provider_name: default_config_from_settings.providerName,
@@ -294,15 +294,9 @@ export class ModelProvidersManager {
294294
ToolConfig | undefined
295295
> {
296296
await this._load_promise
297-
const default_config = this._get_default_tool_config_from_settings(
297+
return this._get_default_tool_config_from_settings(
298298
'configurationsForCodeAtCursor'
299299
)
300-
if (default_config) return default_config
301-
302-
const configs = await this.get_code_completions_tool_configs()
303-
if (configs.length == 1) return configs[0]
304-
305-
return undefined
306300
}
307301

308302
public async set_default_code_completions_config(config: ToolConfig | null) {
@@ -344,15 +338,9 @@ export class ModelProvidersManager {
344338
ToolConfig | undefined
345339
> {
346340
await this._load_promise
347-
const default_config = this._get_default_tool_config_from_settings(
341+
return this._get_default_tool_config_from_settings(
348342
'configurationsForCommitMessages'
349343
)
350-
if (default_config) return default_config
351-
352-
const configs = await this.get_commit_messages_tool_configs()
353-
if (configs.length == 1) return configs[0]
354-
355-
return undefined
356344
}
357345

358346
public async set_default_commit_messages_config(config: ToolConfig | null) {
@@ -382,15 +370,9 @@ export class ModelProvidersManager {
382370
ToolConfig | undefined
383371
> {
384372
await this._load_promise
385-
const default_config = this._get_default_tool_config_from_settings(
373+
return this._get_default_tool_config_from_settings(
386374
'configurationsForIntelligentUpdate'
387375
)
388-
if (default_config) return default_config
389-
390-
const configs = await this.get_intelligent_update_tool_configs()
391-
if (configs.length == 1) return configs[0]
392-
393-
return undefined
394376
}
395377

396378
public async set_default_intelligent_update_config(
@@ -420,15 +402,9 @@ export class ModelProvidersManager {
420402
ToolConfig | undefined
421403
> {
422404
await this._load_promise
423-
const default_config = this._get_default_tool_config_from_settings(
405+
return this._get_default_tool_config_from_settings(
424406
'configurationsForPruneContext'
425407
)
426-
if (default_config) return default_config
427-
428-
const configs = await this.get_prune_context_tool_configs()
429-
if (configs.length == 1) return configs[0]
430-
431-
return undefined
432408
}
433409

434410
public async set_default_prune_context_config(config: ToolConfig | null) {
@@ -454,15 +430,9 @@ export class ModelProvidersManager {
454430
ToolConfig | undefined
455431
> {
456432
await this._load_promise
457-
const default_config = this._get_default_tool_config_from_settings(
433+
return this._get_default_tool_config_from_settings(
458434
'configurationsForVoiceInput'
459435
)
460-
if (default_config) return default_config
461-
462-
const configs = await this.get_voice_input_tool_configs()
463-
if (configs.length == 1) return configs[0]
464-
465-
return undefined
466436
}
467437

468438
public async set_default_voice_input_config(config: ToolConfig | null) {

‎apps/editor/src/utils/intelligent-update-utils.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export const get_intelligent_update_config = async (
3535
if (!show_quick_pick) {
3636
selected_config =
3737
await api_providers_manager.get_default_intelligent_update_config()
38+
39+
if (!selected_config && intelligent_update_configs.length == 1) {
40+
selected_config = intelligent_update_configs[0]
41+
}
3842
}
3943

4044
if (!selected_config || show_quick_pick) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ const create_description = (config: ToolConfig): string => {
1717
return description_parts.join(' · ')
1818
}
1919

20-
export const handle_get_configurations = async (
21-
provider: SettingsProvider,
20+
export const handle_get_configurations = async (params: {
21+
provider: SettingsProvider
2222
type:
2323
| 'code-at-cursor'
2424
| 'edit-context'
2525
| 'intelligent-update'
2626
| 'commit-messages'
2727
| 'prune-context'
2828
| 'voice-input'
29-
): Promise<void> => {
30-
const providers_manager = new ModelProvidersManager(provider.context)
29+
}): Promise<void> => {
30+
const providers_manager = new ModelProvidersManager(params.provider.context)
3131

3232
let saved_configs: ToolConfig[] = []
3333
let default_config: ToolConfig | undefined
3434
let command: string
3535

36-
switch (type) {
36+
switch (params.type) {
3737
case 'code-at-cursor':
3838
saved_configs =
3939
await providers_manager.get_code_completions_tool_configs()
@@ -84,7 +84,7 @@ export const handle_get_configurations = async (
8484
}
8585
)
8686

87-
provider.postMessage({
87+
params.provider.postMessage({
8888
command,
8989
configurations: configs_for_client
9090
} as any)

‎apps/editor/src/views/settings/backend/message-handlers/handle-set-default-configuration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const handle_set_default_configuration = async (
5656

5757
const configs = await get_configs()
5858
const config_to_set_as_default = configs.find(
59-
(c) => get_tool_config_id(c) === configuration_id
59+
(c) => get_tool_config_id(c) == configuration_id
6060
)
6161

6262
if (config_to_set_as_default) {

‎apps/editor/src/views/settings/backend/settings-provider.ts‎

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ export class SettingsProvider {
123123
} else if (message.command == 'CHANGE_MODEL_PROVIDER_KEY') {
124124
await handle_change_model_provider_key(this, message)
125125
} else if (message.command == 'GET_CODE_AT_CURSOR_CONFIGURATIONS') {
126-
await handle_get_configurations(this, 'code-at-cursor')
126+
await handle_get_configurations({
127+
provider: this,
128+
type: 'code-at-cursor'
129+
})
127130
} else if (message.command == 'REORDER_CODE_AT_CURSOR_CONFIGURATIONS') {
128131
await handle_reorder_configuration(
129132
this,
@@ -145,7 +148,10 @@ export class SettingsProvider {
145148
'code-at-cursor'
146149
)
147150
} else if (message.command == 'GET_EDIT_CONTEXT_CONFIGURATIONS') {
148-
await handle_get_configurations(this, 'edit-context')
151+
await handle_get_configurations({
152+
provider: this,
153+
type: 'edit-context'
154+
})
149155
} else if (message.command == 'REORDER_EDIT_CONTEXT_CONFIGURATIONS') {
150156
await handle_reorder_configuration(
151157
this,
@@ -169,7 +175,10 @@ export class SettingsProvider {
169175
} else if (message.command == 'UPDATE_EDIT_FORMAT_INSTRUCTIONS') {
170176
await handle_update_edit_format_instructions(message)
171177
} else if (message.command == 'GET_INTELLIGENT_UPDATE_CONFIGURATIONS') {
172-
await handle_get_configurations(this, 'intelligent-update')
178+
await handle_get_configurations({
179+
provider: this,
180+
type: 'intelligent-update'
181+
})
173182
} else if (
174183
message.command == 'REORDER_INTELLIGENT_UPDATE_CONFIGURATIONS'
175184
) {
@@ -195,7 +204,10 @@ export class SettingsProvider {
195204
'intelligent-update'
196205
)
197206
} else if (message.command == 'GET_PRUNE_CONTEXT_CONFIGURATIONS') {
198-
await handle_get_configurations(this, 'prune-context')
207+
await handle_get_configurations({
208+
provider: this,
209+
type: 'prune-context'
210+
})
199211
} else if (message.command == 'REORDER_PRUNE_CONTEXT_CONFIGURATIONS') {
200212
await handle_reorder_configuration(
201213
this,
@@ -209,7 +221,10 @@ export class SettingsProvider {
209221
'prune-context'
210222
)
211223
} else if (message.command == 'GET_VOICE_INPUT_CONFIGURATIONS') {
212-
await handle_get_configurations(this, 'voice-input')
224+
await handle_get_configurations({
225+
provider: this,
226+
type: 'voice-input'
227+
})
213228
} else if (message.command == 'REORDER_VOICE_INPUT_CONFIGURATIONS') {
214229
await handle_reorder_configuration(
215230
this,
@@ -229,7 +244,10 @@ export class SettingsProvider {
229244
'voice-input'
230245
)
231246
} else if (message.command == 'GET_COMMIT_MESSAGES_CONFIGURATIONS') {
232-
await handle_get_configurations(this, 'commit-messages')
247+
await handle_get_configurations({
248+
provider: this,
249+
type: 'commit-messages'
250+
})
233251
} else if (
234252
message.command == 'REORDER_COMMIT_MESSAGES_CONFIGURATIONS'
235253
) {
@@ -326,14 +344,32 @@ export class SettingsProvider {
326344
vscode.workspace.onDidChangeConfiguration((e) => {
327345
if (e.affectsConfiguration('codeWebChat')) {
328346
void handle_get_model_providers(this)
329-
void handle_get_configurations(this, 'code-at-cursor')
330-
void handle_get_configurations(this, 'commit-messages')
331-
void handle_get_configurations(this, 'edit-context')
347+
void handle_get_configurations({
348+
provider: this,
349+
type: 'code-at-cursor'
350+
})
351+
void handle_get_configurations({
352+
provider: this,
353+
type: 'commit-messages'
354+
})
355+
void handle_get_configurations({
356+
provider: this,
357+
type: 'edit-context'
358+
})
332359
void handle_get_edit_context_system_instructions(this)
333360
void handle_get_edit_format_instructions(this)
334-
void handle_get_configurations(this, 'voice-input')
335-
void handle_get_configurations(this, 'intelligent-update')
336-
void handle_get_configurations(this, 'prune-context')
361+
void handle_get_configurations({
362+
provider: this,
363+
type: 'voice-input'
364+
})
365+
void handle_get_configurations({
366+
provider: this,
367+
type: 'intelligent-update'
368+
})
369+
void handle_get_configurations({
370+
provider: this,
371+
type: 'prune-context'
372+
})
337373
void handle_get_context_size_warning_threshold(this)
338374
void handle_get_commit_message_instructions(this)
339375
void handle_get_commit_message_auto_accept_after(this)

‎packages/shared/src/constants/chatbots.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const CHATBOTS = {
196196
models: {
197197
'deepseek-v3.1': { label: 'DeepSeek V3.1' },
198198
'glm-4.7': { label: 'GLM-4.7' },
199-
'kimi-k2-thinking': { label: 'Kimi K2 Thinking' },
199+
'kimi-k2': { label: 'Kimi K2' },
200200
'gpt-oss-120b': { label: 'GPT OSS 120B' }
201201
}
202202
} as Chatbot,

0 commit comments

Comments
 (0)