Skip to content

Commit accf57c

Browse files
committed
Add customizable voice input instructions with progress feedback and UI settings integration
1 parent 82c1a7e commit accf57c

15 files changed

Lines changed: 250 additions & 35 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@
685685
"type": "string",
686686
"scope": "resource"
687687
},
688+
"codeWebChat.voiceInputInstructions": {
689+
"type": "string",
690+
"scope": "resource"
691+
},
688692
"codeWebChat.commitMessageAutoAcceptAfter": {
689693
"type": "number",
690694
"scope": "resource",

‎apps/editor/src/constants/instructions.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ Your response must begin with "**Relevant files:**", then list paths one under a
4040
- \`src/hello.ts\`
4141
- \`src/welcome.ts\`
4242
</system>`
43+
44+
export const voice_input_instructions =
45+
'Respond with a transcription of the following audio recording or text "(inaudible)", and nothing else.'

‎apps/editor/src/views/panel/backend/message-handlers/handle-voice-input.ts‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as vscode from 'vscode'
1111
import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1212
import axios from 'axios'
1313
import { make_api_request } from '@/utils/make-api-request'
14+
import { voice_input_instructions } from '@/constants/instructions'
1415

1516
const start_recording = (panel_provider: PanelProvider) => {
1617
panel_provider.audio_chunks = []
@@ -79,6 +80,12 @@ const stop_recording = async (panel_provider: PanelProvider) => {
7980
}
8081
}
8182

83+
panel_provider.send_message({
84+
command: 'SHOW_PROGRESS',
85+
title: 'Transcribing...',
86+
cancellable: true
87+
})
88+
8289
const provider = await model_providers_manager.get_provider(
8390
config!.provider_name
8491
)
@@ -100,6 +107,10 @@ const stop_recording = async (panel_provider: PanelProvider) => {
100107
endpoint_url = provider.base_url
101108
}
102109

110+
const instructions = vscode.workspace
111+
.getConfiguration('codeWebChat')
112+
.get<string>('voiceInputInstructions')
113+
103114
const body: { [key: string]: any } = {
104115
model: config.model,
105116
messages: [
@@ -108,7 +119,7 @@ const stop_recording = async (panel_provider: PanelProvider) => {
108119
content: [
109120
{
110121
type: 'text',
111-
text: 'Transcribe this audio.'
122+
text: instructions || voice_input_instructions
112123
},
113124
{
114125
type: 'input_audio',
@@ -124,19 +135,23 @@ const stop_recording = async (panel_provider: PanelProvider) => {
124135

125136
apply_reasoning_effort(body, provider, config.reasoning_effort)
126137

127-
const cancel_token_source = axios.CancelToken.source()
138+
panel_provider.api_call_cancel_token_source = axios.CancelToken.source()
128139

129140
const result = await make_api_request({
130141
endpoint_url,
131142
api_key: provider.api_key,
132143
body,
133-
cancellation_token: cancel_token_source.token
144+
cancellation_token: panel_provider.api_call_cancel_token_source.token
134145
})
135146

136147
if (result?.response) {
137148
panel_provider.add_text_at_cursor_position(result.response)
138149
}
139150
} catch (error: any) {
151+
if (axios.isCancel(error)) {
152+
return
153+
}
154+
140155
Logger.error({
141156
function_name: 'stop_recording',
142157
message: 'Failed to process audio',
@@ -145,6 +160,11 @@ const stop_recording = async (panel_provider: PanelProvider) => {
145160
vscode.window.showErrorMessage(
146161
'Failed to process audio: ' + error.message
147162
)
163+
} finally {
164+
panel_provider.api_call_cancel_token_source = null
165+
panel_provider.send_message({
166+
command: 'HIDE_PROGRESS'
167+
})
148168
}
149169
}
150170
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
import { voice_input_instructions } from '@/constants/instructions'
4+
5+
export const handle_get_voice_input_instructions = async (
6+
provider: SettingsProvider
7+
): Promise<void> => {
8+
const config = vscode.workspace.getConfiguration('codeWebChat')
9+
const instructions =
10+
config.get<string>('voiceInputInstructions') || voice_input_instructions
11+
provider.postMessage({
12+
command: 'VOICE_INPUT_INSTRUCTIONS',
13+
instructions
14+
})
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as vscode from 'vscode'
2+
import { UpdateVoiceInputInstructionsMessage } from '@/views/settings/types/messages'
3+
import { voice_input_instructions } from '@/constants/instructions'
4+
5+
export const handle_update_voice_input_instructions = async (
6+
message: UpdateVoiceInputInstructionsMessage
7+
): Promise<void> => {
8+
await vscode.workspace
9+
.getConfiguration('codeWebChat')
10+
.update(
11+
'voiceInputInstructions',
12+
message.instructions == '' ||
13+
message.instructions == voice_input_instructions
14+
? undefined
15+
: message.instructions,
16+
vscode.ConfigurationTarget.Global
17+
)
18+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export * from './handle-get-commit-message-instructions'
1313
export * from './handle-update-commit-message-instructions'
1414
export * from './handle-get-commit-message-auto-accept-after'
1515
export * from './handle-update-commit-message-auto-accept-after'
16+
export * from './handle-get-voice-input-instructions'
17+
export * from './handle-update-voice-input-instructions'
1618
export * from './handle-get-clear-checks-in-workspace-behavior'
1719
export * from './handle-update-clear-checks-in-workspace-behavior'
1820
export * from './handle-get-gemini-user-id'

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
handle_get_are_automatic_checkpoints_disabled,
1414
handle_get_configurations,
1515
handle_get_commit_message_instructions,
16+
handle_get_voice_input_instructions,
1617
handle_get_commit_message_auto_accept_after,
1718
handle_get_context_size_warning_threshold,
1819
handle_get_edit_context_system_instructions,
@@ -30,6 +31,7 @@ import {
3031
handle_update_clear_checks_in_workspace_behavior,
3132
handle_update_are_automatic_checkpoints_disabled,
3233
handle_update_commit_message_instructions,
34+
handle_update_voice_input_instructions,
3335
handle_update_commit_message_auto_accept_after,
3436
handle_update_context_size_warning_threshold,
3537
handle_update_edit_context_system_instructions,
@@ -275,6 +277,10 @@ export class SettingsProvider {
275277
await handle_get_commit_message_instructions(this)
276278
} else if (message.command == 'UPDATE_COMMIT_MESSAGE_INSTRUCTIONS') {
277279
await handle_update_commit_message_instructions(message)
280+
} else if (message.command == 'GET_VOICE_INPUT_INSTRUCTIONS') {
281+
await handle_get_voice_input_instructions(this)
282+
} else if (message.command == 'UPDATE_VOICE_INPUT_INSTRUCTIONS') {
283+
await handle_update_voice_input_instructions(message)
278284
} else if (message.command == 'GET_COMMIT_MESSAGE_AUTO_ACCEPT_AFTER') {
279285
await handle_get_commit_message_auto_accept_after(this)
280286
} else if (
@@ -375,6 +381,7 @@ export class SettingsProvider {
375381
})
376382
void handle_get_context_size_warning_threshold(this)
377383
void handle_get_commit_message_instructions(this)
384+
void handle_get_voice_input_instructions(this)
378385
void handle_get_commit_message_auto_accept_after(this)
379386
void handle_get_clear_checks_in_workspace_behavior(this)
380387
void handle_get_are_automatic_checkpoints_disabled(this)

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

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import {
2020
} from '@/views/settings/types/messages'
2121
import { GeneralSection } from './sections/GeneralSection'
2222
import { use_translation, TranslationKey } from '@/views/i18n/use-translation'
23+
import {
24+
commit_message_instructions as default_commit_message_instructions,
25+
voice_input_instructions as default_voice_input_instructions
26+
} from '@/constants/instructions'
27+
import { default_system_instructions } from '@shared/constants/default-system-instructions'
2328

2429
type NavItem =
2530
| 'general'
@@ -84,6 +89,7 @@ type Props = {
8489
edit_context_system_instructions: string
8590
intelligent_update_configs: ConfigurationForClient[]
8691
prune_context_configs: ConfigurationForClient[]
92+
voice_input_instructions: string
8793
commit_message_instructions: string
8894
commit_message_auto_accept_after: number | null
8995
context_size_warning_threshold: number
@@ -113,6 +119,7 @@ type Props = {
113119
instructions: EditFormatInstructions
114120
) => void
115121
on_edit_context_system_instructions_change: (instructions: string) => void
122+
on_voice_input_instructions_change: (instructions: string) => void
116123
on_automatic_checkpoints_toggle: (disabled: boolean) => void
117124
on_checkpoint_lifespan_change: (hours: number | undefined) => void
118125
on_gemini_user_id_change: (id: number | null) => void
@@ -166,6 +173,7 @@ export const Home: React.FC<Props> = (props) => {
166173
'commit-messages': null
167174
})
168175
const [commit_instructions, set_commit_instructions] = useState('')
176+
const [voice_input_instructions, set_voice_input_instructions] = useState('')
169177
const [
170178
commit_message_auto_accept_after_str,
171179
set_commit_message_auto_accept_after_str
@@ -254,6 +262,10 @@ export const Home: React.FC<Props> = (props) => {
254262
set_commit_instructions(props.commit_message_instructions || '')
255263
}, [props.commit_message_instructions])
256264

265+
useEffect(() => {
266+
set_voice_input_instructions(props.voice_input_instructions || '')
267+
}, [props.voice_input_instructions])
268+
257269
useEffect(() => {
258270
set_commit_message_auto_accept_after_str(
259271
props.commit_message_auto_accept_after === null ||
@@ -465,11 +477,18 @@ export const Home: React.FC<Props> = (props) => {
465477
<Textarea
466478
value={edit_context_instructions}
467479
on_change={set_edit_context_instructions}
468-
on_blur={() =>
480+
on_blur={() => {
469481
props.on_edit_context_system_instructions_change(
470482
edit_context_instructions
471483
)
472-
}
484+
if (
485+
edit_context_instructions == '' &&
486+
props.edit_context_system_instructions ==
487+
default_system_instructions
488+
) {
489+
set_edit_context_instructions(default_system_instructions)
490+
}
491+
}}
473492
/>
474493
}
475494
/>
@@ -593,7 +612,9 @@ export const Home: React.FC<Props> = (props) => {
593612
</Button>
594613
}
595614
>
596-
<Notice type="info">A request includes the selected files.</Notice>
615+
<Notice type="info">
616+
A request includes the editor with cursor and the selected files.
617+
</Notice>
597618
{props.code_at_cursor_configs.length == 0 && (
598619
<Notice type="warning">
599620
Add a configuration to use this feature.
@@ -690,6 +711,30 @@ export const Home: React.FC<Props> = (props) => {
690711
props.on_unset_default_config('VOICE_INPUT')
691712
}
692713
/>
714+
<Item
715+
title="Instructions"
716+
description="Instructions for the model to process voice input."
717+
slot_below={
718+
<Textarea
719+
value={voice_input_instructions}
720+
on_change={set_voice_input_instructions}
721+
on_blur={() => {
722+
props.on_voice_input_instructions_change(
723+
voice_input_instructions
724+
)
725+
if (
726+
voice_input_instructions == '' &&
727+
props.voice_input_instructions ==
728+
default_voice_input_instructions
729+
) {
730+
set_voice_input_instructions(
731+
default_voice_input_instructions
732+
)
733+
}
734+
}}
735+
/>
736+
}
737+
/>
693738
</Group>
694739
</Section>
695740

@@ -745,9 +790,18 @@ export const Home: React.FC<Props> = (props) => {
745790
<Textarea
746791
value={commit_instructions}
747792
on_change={set_commit_instructions}
748-
on_blur={() =>
793+
on_blur={() => {
749794
props.on_commit_instructions_change(commit_instructions)
750-
}
795+
if (
796+
commit_instructions == '' &&
797+
props.commit_message_instructions ==
798+
default_commit_message_instructions
799+
) {
800+
set_commit_instructions(
801+
default_commit_message_instructions
802+
)
803+
}
804+
}}
751805
/>
752806
}
753807
/>

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import {
1212
CHECKPOINT_DEFAULT_LIFESPAN,
1313
DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD
1414
} from '@/constants/values'
15+
import {
16+
EDIT_FORMAT_INSTRUCTIONS_BEFORE_AFTER,
17+
EDIT_FORMAT_INSTRUCTIONS_DIFF,
18+
EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
19+
EDIT_FORMAT_INSTRUCTIONS_WHOLE
20+
} from '@/constants/edit-format-instructions'
1521

1622
type ClearChecksBehavior = 'ignore-open-editors' | 'uncheck-all'
1723

@@ -151,6 +157,31 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
151157

152158
const handle_instructions_blur = () => {
153159
props.on_edit_format_instructions_change(instructions)
160+
161+
set_instructions((prev) => ({
162+
whole:
163+
prev.whole == '' &&
164+
props.edit_format_instructions.whole == EDIT_FORMAT_INSTRUCTIONS_WHOLE
165+
? EDIT_FORMAT_INSTRUCTIONS_WHOLE
166+
: prev.whole,
167+
truncated:
168+
prev.truncated == '' &&
169+
props.edit_format_instructions.truncated ==
170+
EDIT_FORMAT_INSTRUCTIONS_TRUNCATED
171+
? EDIT_FORMAT_INSTRUCTIONS_TRUNCATED
172+
: prev.truncated,
173+
before_after:
174+
prev.before_after == '' &&
175+
props.edit_format_instructions.before_after ==
176+
EDIT_FORMAT_INSTRUCTIONS_BEFORE_AFTER
177+
? EDIT_FORMAT_INSTRUCTIONS_BEFORE_AFTER
178+
: prev.before_after,
179+
diff:
180+
prev.diff == '' &&
181+
props.edit_format_instructions.diff == EDIT_FORMAT_INSTRUCTIONS_DIFF
182+
? EDIT_FORMAT_INSTRUCTIONS_DIFF
183+
: prev.diff
184+
}))
154185
}
155186

156187
return (

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const Settings = () => {
3030
settings_hook.voice_input_configs !== undefined &&
3131
settings_hook.intelligent_update_configs !== undefined &&
3232
settings_hook.prune_context_configs !== undefined &&
33+
settings_hook.voice_input_instructions !== undefined &&
3334
settings_hook.commit_message_instructions !== undefined &&
3435
settings_hook.commit_message_auto_accept_after !== undefined &&
3536
settings_hook.context_size_warning_threshold !== undefined &&
@@ -74,6 +75,7 @@ export const Settings = () => {
7475
context_size_warning_threshold={
7576
settings_hook.context_size_warning_threshold!
7677
}
78+
voice_input_instructions={settings_hook.voice_input_instructions!}
7779
commit_message_instructions={settings_hook.commit_message_instructions!}
7880
commit_message_auto_accept_after={
7981
settings_hook.commit_message_auto_accept_after!
@@ -103,6 +105,9 @@ export const Settings = () => {
103105
on_context_size_warning_threshold_change={
104106
settings_hook.handle_context_size_warning_threshold_change
105107
}
108+
on_voice_input_instructions_change={
109+
settings_hook.handle_voice_input_instructions_change
110+
}
106111
on_commit_instructions_change={
107112
settings_hook.handle_commit_instructions_change
108113
}

0 commit comments

Comments
 (0)