Skip to content

Commit 76983aa

Browse files
committed
Add support for default API and web configurations for commit message generation
- user should be able to select default chatbot/model for commit message (like they do for other api tools like 'code at cursor' - change order move system instructions above 'defaults' └── apps └── editor └── src ├── commands │ ├── code-at-cursor-command │ │ └── utils │ │ ├── get-code-at-cursor-config.ts │ │ └── perform-code-at-cursor.ts │ └── generate-commit-message-commands │ ├── actions │ │ └── run-generate-action.ts │ └── utils │ ├── generate-commit-message-with-api.ts │ └── get-commit-message-config.ts ├── services │ └── providers-manager.ts ├── utils │ ├── cli-configuration-format-converters.ts │ └── get-api-configuration.ts └── views ├── settings │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-get-api-configurations.ts │ │ │ ├── handle-get-cli-configurations.ts │ │ │ ├── handle-select-default-api-configuration.ts │ │ │ ├── handle-select-default-cli-configuration.ts │ │ │ ├── handle-set-default-api-configuration.ts │ │ │ ├── handle-set-default-cli-configuration.ts │ │ │ └── index.ts │ │ └── settings-view-provider.ts │ ├── frontend │ │ ├── App.tsx │ │ ├── Home │ │ │ ├── Home.tsx │ │ │ ├── hooks │ │ │ │ └── use-scroll-to.ts │ │ │ ├── index.ts │ │ │ └── sections │ │ │ ├── ApiSection.tsx │ │ │ ├── CliSection.tsx │ │ │ ├── GeneralSection.tsx │ │ │ └── WebSection.tsx │ │ ├── Settings.tsx │ │ ├── forms │ │ │ ├── EditProviderForm │ │ │ │ ├── EditProviderForm.module.scss │ │ │ │ ├── EditProviderForm.tsx │ │ │ │ └── index.ts │ │ │ └── EditTemplateForm │ │ │ ├── EditTemplateForm.module.scss │ │ │ ├── EditTemplateForm.tsx │ │ │ └── index.ts │ │ ├── hooks │ │ │ ├── use-api-configuration-editing.ts │ │ │ ├── use-cli-configuration-editing.ts │ │ │ ├── use-provider-editing.ts │ │ │ ├── use-settings.ts │ │ │ └── use-web-configuration-editing.ts │ │ ├── i18n │ │ │ ├── translations │ │ │ │ ├── actions.ts │ │ │ │ ├── api.ts │ │ │ │ ├── cli.ts │ │ │ │ ├── common.ts │ │ │ │ ├── edit-provider-form.ts │ │ │ │ ├── edit-template-form.ts │ │ │ │ ├── general.ts │ │ │ │ ├── index.ts │ │ │ │ ├── sections.ts │ │ │ │ └── web.ts │ │ │ └── use-translation.tsx │ │ └── utils │ │ └── post-message.ts │ └── types │ └── messages.ts └── shared ├── actions │ └── api │ └── update │ └── update.ts └── types └── api-features.ts
1 parent fac57d1 commit 76983aa

10 files changed

Lines changed: 115 additions & 41 deletions

File tree

‎apps/editor/src/commands/generate-commit-message-commands/actions/run-generate-action.ts‎

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

407407
let selected_web_configuration_name: string | undefined
408408

409-
if (valid_web_configurations.length == 1) {
409+
const default_web_config = valid_web_configurations.find(
410+
(c: any) => c.isDefaultForCommitMessage
411+
)
412+
413+
if (default_web_config) {
414+
selected_web_configuration_name = default_web_config.name
415+
} else if (valid_web_configurations.length == 1) {
410416
selected_web_configuration_name = valid_web_configurations[0].name
411417
} else {
412418
const recents_key =

‎apps/editor/src/commands/generate-commit-message-commands/utils/get-commit-message-config.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export const get_commit_message_api_configuration = async (params: {
3434
show_back_button,
3535
ignore_focus_out: true,
3636
caller_name: 'get_commit_message_api_configuration',
37-
auto_select_last_used: false
37+
auto_select_last_used: false,
38+
default_api_configuration:
39+
await providers_manager.get_default_commit_message_api_configuration()
3840
})
3941

4042
if (result === 'back') {

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type ConfigApiConfigurationFormat = {
2424
isDefaultForPatchRepair?: boolean
2525
isDefaultForVoiceInput?: boolean
2626
isDefaultForIntelligentSearch?: boolean
27+
isDefaultForCommitMessage?: boolean
2728
}
2829

2930
export const get_api_configuration_id = (
@@ -191,6 +192,8 @@ export class ProvidersManager {
191192
new_config.isDefaultForVoiceInput = true
192193
if (old_config?.isDefaultForIntelligentSearch)
193194
new_config.isDefaultForIntelligentSearch = true
195+
if (old_config?.isDefaultForCommitMessage)
196+
new_config.isDefaultForCommitMessage = true
194197
if (c.reasoning_effort !== undefined)
195198
new_config.reasoningEffort = c.reasoning_effort
196199
if (c.is_pinned !== undefined) new_config.isPinned = c.is_pinned
@@ -345,6 +348,24 @@ export class ProvidersManager {
345348
)
346349
}
347350

351+
public async get_default_commit_message_api_configuration(): Promise<
352+
ApiConfiguration | undefined
353+
> {
354+
await this._load_promise
355+
return this._get_default_api_configuration_from_settings(
356+
'isDefaultForCommitMessage'
357+
)
358+
}
359+
360+
public async set_default_commit_message_api_configuration(
361+
api_configuration: ApiConfiguration | null
362+
) {
363+
await this._set_default_api_configuration_in_settings(
364+
'isDefaultForCommitMessage',
365+
api_configuration
366+
)
367+
}
368+
348369
public async update_provider_name_in_api_configurations(params: {
349370
old_name: string
350371
new_name: string

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export const handle_get_api_configurations = async (
2828
await providers_manager.get_default_voice_input_api_configuration()
2929
const def_is =
3030
await providers_manager.get_default_intelligent_search_api_configuration()
31+
const def_cm =
32+
await providers_manager.get_default_commit_message_api_configuration()
3133

3234
provider.postMessage({
3335
command: 'API_CONFIGURATIONS',
@@ -36,7 +38,8 @@ export const handle_get_api_configurations = async (
3638
'code-at-cursor': def_cac ? get_api_configuration_id(def_cac) : null,
3739
'patch-repair': def_pr ? get_api_configuration_id(def_pr) : null,
3840
'voice-input': def_vi ? get_api_configuration_id(def_vi) : null,
39-
'intelligent-search': def_is ? get_api_configuration_id(def_is) : null
41+
'intelligent-search': def_is ? get_api_configuration_id(def_is) : null,
42+
'commit-message': def_cm ? get_api_configuration_id(def_cm) : null
4043
}
4144
})
4245
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@ export const handle_set_default_api_configuration = async (
3535
await providers_manager.set_default_intelligent_search_api_configuration(
3636
api_configuration_to_set
3737
)
38+
} else if (type == 'commit-message') {
39+
await providers_manager.set_default_commit_message_api_configuration(
40+
api_configuration_to_set
41+
)
3842
}
3943
}

‎apps/editor/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ export const NAV_ITEMS_CONFIG: NavConfigItem[] = [
8282
id: 'section:api:group:models',
8383
label: 'api.configurations.title'
8484
},
85-
{
86-
id: 'section:api:group:api-defaults',
87-
label: 'api.default-configurations.title'
88-
},
8985
{
9086
id: 'section:api:group:system-instructions',
9187
label: 'api.system-instructions.title'
9288
},
89+
{
90+
id: 'section:api:group:api-defaults',
91+
label: 'api.default-configurations.title'
92+
},
9393
{
9494
id: 'section:cli',
9595
label: 'cli.title'

‎apps/editor/src/views/settings/frontend/Home/sections/ApiSection.tsx‎

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,42 @@ export const ApiSection = forwardRef<HTMLDivElement, Props>((props, ref) => {
300300
</UiGroup>
301301
</div>
302302

303+
<div
304+
ref={(el) =>
305+
props.set_section_ref('section:api:group:system-instructions', el)
306+
}
307+
>
308+
<UiGroup
309+
title={t('api.system-instructions.title')}
310+
is_disabled={props.api_configurations.length === 0}
311+
>
312+
<UiItem
313+
title={t('api.system-instructions.edit-files.title')}
314+
description={t('api.system-instructions.edit-files.description')}
315+
is_toggleable
316+
translations={{
317+
expand: t('common.expand'),
318+
collapse: t('common.collapse')
319+
}}
320+
>
321+
<UiTextarea
322+
value={props.edit_files_instructions}
323+
min_rows={3}
324+
on_change={props.set_edit_files_instructions}
325+
on_blur={props.on_edit_files_instructions_blur}
326+
action_icon={
327+
props.edit_files_instructions !==
328+
props.default_edit_files_instructions
329+
? 'discard'
330+
: undefined
331+
}
332+
action_title={t('general.action.restore-default')}
333+
on_action_click={props.on_restore_edit_files_instructions}
334+
/>
335+
</UiItem>
336+
</UiGroup>
337+
</div>
338+
303339
<div
304340
ref={(el) =>
305341
props.set_section_ref('section:api:group:api-defaults', el)
@@ -369,42 +405,21 @@ export const ApiSection = forwardRef<HTMLDivElement, Props>((props, ref) => {
369405
unset: t('api.configurations.action.unset-default')
370406
}}
371407
/>
372-
</UiGroup>
373-
</div>
374-
375-
<div
376-
ref={(el) =>
377-
props.set_section_ref('section:api:group:system-instructions', el)
378-
}
379-
>
380-
<UiGroup
381-
title={t('api.system-instructions.title')}
382-
is_disabled={props.api_configurations.length === 0}
383-
>
384-
<UiItem
385-
title={t('api.system-instructions.edit-files.title')}
386-
description={t('api.system-instructions.edit-files.description')}
387-
is_toggleable
408+
<DefaultConfigurationSelector
409+
title={t('api.default-configurations.tool.commit-message')}
410+
value={props.defaults['commit-message'] || null}
411+
configurations={selector_configurations}
412+
on_unset={() =>
413+
props.on_set_default_api_configuration('commit-message', null)
414+
}
415+
on_select={() =>
416+
props.on_select_default_api_configuration('commit-message')
417+
}
388418
translations={{
389-
expand: t('common.expand'),
390-
collapse: t('common.collapse')
419+
select: t('api.configurations.action.select-default'),
420+
unset: t('api.configurations.action.unset-default')
391421
}}
392-
>
393-
<UiTextarea
394-
value={props.edit_files_instructions}
395-
min_rows={3}
396-
on_change={props.set_edit_files_instructions}
397-
on_blur={props.on_edit_files_instructions_blur}
398-
action_icon={
399-
props.edit_files_instructions !==
400-
props.default_edit_files_instructions
401-
? 'discard'
402-
: undefined
403-
}
404-
action_title={t('general.action.restore-default')}
405-
on_action_click={props.on_restore_edit_files_instructions}
406-
/>
407-
</UiItem>
422+
/>
408423
</UiGroup>
409424
</div>
410425
</UiSection>

‎apps/editor/src/views/settings/frontend/i18n/translations/api.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,24 @@ export const translations = {
454454
hu: 'Intelligens keresés',
455455
bg: 'Интелигентно търсене'
456456
},
457+
'api.default-configurations.tool.commit-message': {
458+
en: 'Commit Message',
459+
pl: 'Wiadomość commita',
460+
'zh-cn': '提交信息',
461+
ja: 'コミットメッセージ',
462+
'zh-tw': '提交訊息',
463+
de: 'Commit-Nachricht',
464+
es: 'Mensaje de commit',
465+
fr: 'Message de commit',
466+
'pt-br': 'Mensagem de commit',
467+
ru: 'Сообщение коммита',
468+
ko: '커밋 메시지',
469+
it: 'Messaggio di commit',
470+
tr: 'Commit Mesajı',
471+
cs: 'Zpráva commitu',
472+
hu: 'Commit üzenet',
473+
bg: 'Съобщение на къмит'
474+
},
457475
'api.system-instructions.title': {
458476
en: 'System Instructions',
459477
pl: 'Instrukcje systemowe',

‎apps/editor/src/views/shared/actions/api/update/update.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ export const update = async (params: {
126126
await providers_manager.set_default_voice_input_api_configuration(
127127
new_config as any
128128
)
129+
} else if (params.api_feature == 'commit-message') {
130+
await providers_manager.set_default_commit_message_api_configuration(
131+
new_config as any
132+
)
129133
}
130134
}
131135

‎apps/editor/src/views/shared/types/api-features.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export type ApiFeature =
33
| 'patch-repair'
44
| 'voice-input'
55
| 'intelligent-search'
6+
| 'commit-message'

0 commit comments

Comments
 (0)