Skip to content

Commit 58f184f

Browse files
committed
Add default chatbot selection for Code at Cursor and Intelligent Search web configurations
- add the ability to set default chatbot for 'code at cursor' and 'intelligent search' - respect default chatbot in 'code at cursor' and 'intelligent search' └── apps └── editor ├── package.json └── src ├── commands │ └── code-at-cursor-command │ ├── code-at-cursor-commands.ts │ ├── index.ts │ └── utils │ ├── get-code-at-cursor-config.ts │ ├── perform-code-at-cursor.ts │ └── show-ghost-text.ts ├── features │ └── search-files │ ├── index.ts │ ├── search-files.ts │ ├── search-modes │ │ ├── perform-intelligent-search-mode.ts │ │ ├── perform-keywords-search-mode.ts │ │ └── perform-phrase-search-mode.ts │ └── utils │ ├── analyze-files.ts │ ├── check-matches-condition.ts │ ├── create-search-regex.ts │ ├── prompt-for-config.ts │ ├── prompt-for-intelligent-search-results.ts │ ├── prompt-for-keywords-match-mode.ts │ ├── prompt-for-keywords-target.ts │ ├── prompt-for-search-mode.ts │ ├── prompt-for-search-results.ts │ ├── prompt-for-search-term.ts │ ├── prompt-for-shrink-mode.ts │ ├── search-files-by-intelligent.ts │ ├── search-files-by-keywords.ts │ ├── search-files-by-phrase.ts │ └── show-search-results-quick-pick.ts ├── i18n │ └── translations │ └── common.ts ├── utils │ ├── cli-configuration-format-converters.ts │ └── web-configuration-format-converters.ts └── views └── settings ├── backend │ ├── message-handlers │ │ ├── handle-get-api-configurations.ts │ │ ├── handle-get-cli-configurations.ts │ │ ├── handle-get-web-configurations.ts │ │ ├── handle-select-default-api-configuration.ts │ │ ├── handle-select-default-cli-configuration.ts │ │ ├── handle-select-default-web-configuration.ts │ │ ├── handle-set-default-api-configuration.ts │ │ ├── handle-set-default-cli-configuration.ts │ │ └── index.ts │ └── settings-view-provider.ts ├── frontend │ ├── Home │ │ ├── Home.tsx │ │ └── sections │ │ ├── ApiSection.tsx │ │ ├── CliSection.tsx │ │ └── WebSection.tsx │ ├── Settings.tsx │ ├── hooks │ │ ├── use-settings.ts │ │ └── use-web-configuration-editing.ts │ └── i18n │ └── translations │ ├── api.ts │ ├── cli.ts │ └── web.ts └── types └── messages.ts
1 parent 23a7baf commit 58f184f

16 files changed

Lines changed: 424 additions & 4 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,12 @@
11151115
},
11161116
"isPinned": {
11171117
"type": "boolean"
1118+
},
1119+
"isDefaultForCodeAtCursor": {
1120+
"type": "boolean"
1121+
},
1122+
"isDefaultForIntelligentSearch": {
1123+
"type": "boolean"
11181124
}
11191125
}
11201126
}

‎apps/editor/src/commands/code-at-cursor-command/utils/perform-code-at-cursor.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,13 @@ export const perform_code_at_cursor = async (params: {
293293

294294
let selected_web_configuration_name: string | undefined
295295

296-
if (valid_web_configurations.length == 1) {
296+
const default_web_config = valid_web_configurations.find(
297+
(c) => c.isDefaultForCodeAtCursor
298+
)
299+
300+
if (default_web_config) {
301+
selected_web_configuration_name = default_web_config.name
302+
} else if (valid_web_configurations.length == 1) {
297303
selected_web_configuration_name = valid_web_configurations[0].name
298304
} else {
299305
const recents_key =

‎apps/editor/src/features/search-files/search-modes/perform-intelligent-search-mode.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,13 @@ export const perform_intelligent_search_mode = async (params: {
324324

325325
let selected_web_configuration_name: string | undefined
326326

327-
if (valid_web_configurations.length == 1) {
327+
const default_web_config = valid_web_configurations.find(
328+
(c) => c.isDefaultForIntelligentSearch
329+
)
330+
331+
if (default_web_config) {
332+
selected_web_configuration_name = default_web_config.name
333+
} else if (valid_web_configurations.length == 1) {
328334
selected_web_configuration_name = valid_web_configurations[0].name
329335
} else {
330336
const recents_key = get_last_used_web_configuration_key(

‎apps/editor/src/i18n/translations/common.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,24 @@ export const translations = {
611611
hu: 'Chatbotok',
612612
bg: 'Чатботове'
613613
},
614+
'common.placeholder.select-chatbot': {
615+
en: 'Select chatbot',
616+
pl: 'Wybierz chatbota',
617+
'zh-cn': '选择聊天机器人',
618+
ja: 'チャットボットを選択',
619+
'zh-tw': '選擇聊天機器人',
620+
de: 'Chatbot auswählen',
621+
es: 'Seleccionar chatbot',
622+
fr: 'Sélectionner un chatbot',
623+
'pt-br': 'Selecionar chatbot',
624+
ru: 'Выберите чат-бота',
625+
ko: '챗봇 선택',
626+
it: 'Seleziona chatbot',
627+
tr: 'Sohbet botu seç',
628+
cs: 'Vybrat chatbota',
629+
hu: 'Chatbot kiválasztása',
630+
bg: 'Изберете чатбот'
631+
},
614632
'common.title.agents': {
615633
en: 'Agents',
616634
pl: 'Agenci',

‎apps/editor/src/utils/web-configuration-format-converters.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export type ConfigWebConfigurationFormat = {
1111
port?: number
1212
newUrl?: string
1313
isPinned?: boolean
14+
isDefaultForCodeAtCursor?: boolean
15+
isDefaultForIntelligentSearch?: boolean
1416
}
1517

1618
export const config_web_configuration_to_ui_format = (

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ export const handle_get_web_configurations = async (
3232
}
3333
}
3434
return config_web_configuration_to_ui_format({ ...config, model })
35-
})
35+
}),
36+
defaults: {
37+
'code-at-cursor':
38+
web_configurations_config.find((c: any) => c.isDefaultForCodeAtCursor)
39+
?.name || null,
40+
'intelligent-search':
41+
web_configurations_config.find(
42+
(c: any) => c.isDefaultForIntelligentSearch
43+
)?.name || null
44+
}
3645
})
3746
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import * as vscode from 'vscode'
2+
import { SelectDefaultWebConfigurationMessage } from '@/views/settings/types/messages'
3+
import { t } from '@/i18n'
4+
import { CHATBOTS } from '@shared/constants/chatbots'
5+
6+
export const handle_select_default_web_configuration = async (
7+
message: SelectDefaultWebConfigurationMessage
8+
): Promise<void> => {
9+
const config = vscode.workspace.getConfiguration('codeWebChat')
10+
const web_configs = config.get<any[]>('chatbots', []) || []
11+
if (web_configs.length === 0) return
12+
13+
const items = web_configs.map((c) => {
14+
const is_unnamed =
15+
!c.name ||
16+
c.name.startsWith('unnamed-') ||
17+
/^\(\d+\)$/.test(c.name.trim())
18+
const display_name = is_unnamed
19+
? c.chatbot!
20+
: c.name!.replace(/ \(\d+\)$/, '')
21+
22+
const get_details = (): string[] => {
23+
const { chatbot, model, reasoningEffort } = c
24+
const model_display_name =
25+
model && chatbot && CHATBOTS[chatbot as keyof typeof CHATBOTS]
26+
? CHATBOTS[chatbot as keyof typeof CHATBOTS].models?.[model]?.label ||
27+
model
28+
: null
29+
30+
const details: string[] = []
31+
if (is_unnamed) {
32+
if (model_display_name) details.push(model_display_name)
33+
} else if (model_display_name) {
34+
details.push(chatbot!, model_display_name)
35+
} else if (chatbot) {
36+
details.push(chatbot)
37+
}
38+
39+
if (reasoningEffort) {
40+
details.push(reasoningEffort)
41+
}
42+
43+
return details
44+
}
45+
46+
const description_parts = get_details()
47+
48+
return {
49+
label: display_name,
50+
description:
51+
description_parts.length > 0 ? description_parts.join(' ') : undefined,
52+
web_configuration_name: c.name
53+
}
54+
})
55+
56+
const quick_pick = vscode.window.createQuickPick<
57+
vscode.QuickPickItem & { web_configuration_name: string }
58+
>()
59+
quick_pick.items = items
60+
quick_pick.title = t('common.title.chatbots')
61+
quick_pick.placeholder = t('common.placeholder.select-chatbot')
62+
63+
const close_button: vscode.QuickInputButton = {
64+
iconPath: new vscode.ThemeIcon('close'),
65+
tooltip: t('common.close')
66+
}
67+
quick_pick.buttons = [close_button]
68+
69+
quick_pick.onDidTriggerButton((button) => {
70+
if (button === close_button) {
71+
quick_pick.hide()
72+
}
73+
})
74+
75+
quick_pick.onDidAccept(async () => {
76+
const selected = quick_pick.selectedItems[0]
77+
quick_pick.hide()
78+
79+
if (selected) {
80+
const updated = web_configs.map((c) => {
81+
const new_c = { ...c }
82+
if (message.web_feature == 'code-at-cursor') {
83+
if (c.name == selected.web_configuration_name) {
84+
new_c.isDefaultForCodeAtCursor = true
85+
} else {
86+
delete new_c.isDefaultForCodeAtCursor
87+
}
88+
} else if (message.web_feature == 'intelligent-search') {
89+
if (c.name == selected.web_configuration_name) {
90+
new_c.isDefaultForIntelligentSearch = true
91+
} else {
92+
delete new_c.isDefaultForIntelligentSearch
93+
}
94+
}
95+
return new_c
96+
})
97+
await config.update(
98+
'chatbots',
99+
updated,
100+
vscode.ConfigurationTarget.Global
101+
)
102+
}
103+
})
104+
105+
quick_pick.onDidHide(() => quick_pick.dispose())
106+
quick_pick.show()
107+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as vscode from 'vscode'
2+
import { SetDefaultWebConfigurationMessage } from '@/views/settings/types/messages'
3+
4+
export const handle_set_default_web_configuration = async (
5+
message: SetDefaultWebConfigurationMessage
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const web_configs = config.get<any[]>('chatbots', []) || []
9+
const updated = web_configs.map((c) => {
10+
const new_c = { ...c }
11+
if (message.web_feature == 'code-at-cursor') {
12+
if (c.name == message.web_configuration_name) {
13+
new_c.isDefaultForCodeAtCursor = true
14+
} else {
15+
delete new_c.isDefaultForCodeAtCursor
16+
}
17+
} else if (message.web_feature == 'intelligent-search') {
18+
if (c.name == message.web_configuration_name) {
19+
new_c.isDefaultForIntelligentSearch = true
20+
} else {
21+
delete new_c.isDefaultForIntelligentSearch
22+
}
23+
}
24+
return new_c
25+
})
26+
await config.update('chatbots', updated, vscode.ConfigurationTarget.Global)
27+
}

‎apps/editor/src/views/settings/backend/message-handlers/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export * from './handle-pick-chatbot'
3636
export * from './handle-pick-model'
3737
export * from './handle-pick-reasoning-effort'
3838
export * from './handle-update-web-configuration'
39+
export * from './handle-set-default-web-configuration'
40+
export * from './handle-select-default-web-configuration'
3941
export * from './handle-create-api-configuration'
4042
export * from './handle-update-api-configuration'
4143
export * from './handle-delete-api-configuration'

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import {
3838
handle_pick_model,
3939
handle_pick_reasoning_effort,
4040
handle_update_web_configuration,
41+
handle_set_default_web_configuration,
42+
handle_select_default_web_configuration,
4143
handle_create_api_configuration,
4244
handle_update_api_configuration,
4345
handle_delete_api_configuration,
@@ -231,6 +233,10 @@ export class SettingsViewProvider {
231233
await handle_pick_reasoning_effort(this, message)
232234
} else if (message.command == 'UPDATE_WEB_CONFIGURATION') {
233235
await handle_update_web_configuration(this, message)
236+
} else if (message.command == 'SET_DEFAULT_WEB_CONFIGURATION') {
237+
await handle_set_default_web_configuration(message)
238+
} else if (message.command == 'SELECT_DEFAULT_WEB_CONFIGURATION') {
239+
await handle_select_default_web_configuration(message)
234240
} else if (message.command == 'CREATE_API_CONFIGURATION') {
235241
await handle_create_api_configuration(this, message)
236242
} else if (message.command == 'UPDATE_API_CONFIGURATION') {

0 commit comments

Comments
 (0)