Skip to content

Commit 9089e10

Browse files
committed
Add voice input instructions and default option settings
- in 'General' section, add 'Features' group. In there we want multi-option configuration setting: 'Default option for Code At Cursor...' (desc: Decide whether any option should be preselected): 'Ask'/'Send request'/'Invoke agent'/'Autofill chatbot'/'Copy prompt' - [Changes] rename 'default option for code at cursor' to 'code at cursor', desc: 'Choose how to proceed.' - [Changes] move 'code at cursor' to `apps/editor/src/views/settings/frontend/i18n/translations/common.ts` - rename 'choices' to 'default actions' - default action should not be for 'code at cursor' but for 'voice input' - rename 'default actions' to 'Voice Input' - voice input's default action should have options: ask, send request, invoke agent - voice input's default action should be named 'Handle with...' - add translations to [Fragment] - use [Fragment] in `apps/editor/src/views/prompt/backend/message-handlers/handle-voice-input.ts` - '[Fragment]' should be in '# Task' section, how should respond in '# Output formatting' section - move [Pasted text] to package.json as 'VoiceInputInstructions' - should not read [Pasted text] twice - allow configuring voiceInputInstructions in settings - add translations [Pasted text] - fill missing handlers - move [Fragment] to common, and use for 'commit message instructions' as well (replacing) - change order [Image] └── apps └── editor ├── package.json └── src ├── constants │ └── instructions.ts └── views ├── prompt │ └── backend │ └── message-handlers │ └── handle-voice-input.ts └── settings ├── backend │ ├── message-handlers │ │ ├── add-provider │ │ │ ├── handle-add-provider.ts │ │ │ ├── pick-extended-provider.ts │ │ │ └── pick-provider-source.ts │ │ ├── handle-create-api-configuration.ts │ │ ├── handle-create-cli-configuration.ts │ │ ├── handle-create-template.ts │ │ ├── handle-create-web-configuration.ts │ │ ├── handle-delete-api-configuration.ts │ │ ├── handle-delete-cli-configuration.ts │ │ ├── handle-delete-provider.ts │ │ ├── handle-delete-template.ts │ │ ├── handle-delete-web-configuration.ts │ │ ├── handle-get-ai-studio-user-id.ts │ │ ├── handle-get-api-configurations.ts │ │ ├── handle-get-attach-ascii-tree-of-context.ts │ │ ├── handle-get-cli-configurations.ts │ │ ├── handle-get-commit-message-instructions.ts │ │ ├── handle-get-default-option-for-voice-input.ts │ │ ├── handle-get-edit-files-system-instructions.ts │ │ ├── handle-get-gemini-user-id.ts │ │ ├── handle-get-include-prompts-in-commit-messages.ts │ │ ├── handle-get-is-modern-ui.ts │ │ ├── handle-get-providers.ts │ │ ├── handle-get-send-with-shift-enter.ts │ │ ├── handle-get-templates.ts │ │ ├── handle-get-use-context-files-in-commit-message-prompt.ts │ │ ├── handle-get-voice-input-instructions.ts │ │ ├── handle-get-web-configurations.ts │ │ ├── handle-open-allow-patterns-settings.ts │ │ ├── handle-open-editor-settings.ts │ │ ├── handle-open-ignore-patterns-settings.ts │ │ ├── handle-open-keybindings.ts │ │ ├── handle-pick-agent.ts │ │ ├── handle-pick-api-model.ts │ │ ├── handle-pick-api-reasoning-effort.ts │ │ ├── handle-pick-chatbot.ts │ │ ├── handle-pick-model.ts │ │ ├── handle-pick-provider.ts │ │ ├── handle-pick-reasoning-effort.ts │ │ ├── handle-reorder-api-configurations.ts │ │ ├── handle-reorder-cli-configurations.ts │ │ ├── handle-reorder-providers.ts │ │ ├── handle-reorder-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 │ │ ├── handle-set-default-web-configuration.ts │ │ ├── handle-update-ai-studio-user-id.ts │ │ ├── handle-update-api-configuration.ts │ │ ├── handle-update-attach-ascii-tree-of-context.ts │ │ ├── handle-update-cli-configuration.ts │ │ ├── handle-update-commit-message-instructions.ts │ │ ├── handle-update-default-option-for-voice-input.ts │ │ ├── handle-update-edit-files-system-instructions.ts │ │ ├── handle-update-gemini-user-id.ts │ │ ├── handle-update-include-prompts-in-commit-messages.ts │ │ ├── handle-update-provider.ts │ │ ├── handle-update-send-with-shift-enter.ts │ │ ├── handle-update-templates.ts │ │ ├── handle-update-use-context-files-in-commit-message-prompt.ts │ │ ├── handle-update-voice-input-instructions.ts │ │ ├── handle-update-web-configuration.ts │ │ └── index.ts │ └── settings-view-provider.ts ├── frontend │ ├── Home │ │ ├── Home.tsx │ │ ├── hooks │ │ │ └── use-scroll-to.ts │ │ ├── index.ts │ │ └── sections │ │ ├── ApiSection.tsx │ │ ├── CliSection.tsx │ │ ├── GeneralSection.tsx │ │ └── WebSection.tsx │ ├── Settings.tsx │ ├── hooks │ │ └── use-settings.ts │ └── i18n │ └── translations │ ├── api.ts │ ├── common.ts │ └── general.ts └── types └── messages.ts
1 parent a6d7d82 commit 9089e10

17 files changed

Lines changed: 502 additions & 32 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,11 @@
949949
"scope": "resource",
950950
"default": "Write a brief and precise summary for the changes, limited to a single sentence. Because the summary will be used for a commit message, don't use any markdown formatting and don't include a trailing dot. Use an imperative tone to ensure clarity and focus on the primary change or purpose."
951951
},
952+
"codeWebChat.voiceInputInstructions": {
953+
"type": "string",
954+
"scope": "resource",
955+
"default": "Transcribe using clean verbatim. Remove filler words (such as 'um,' 'uh,' 'like'), false starts, and stutters. Preserve the speaker's exact words, slang, and sentence structure, but use natural punctuation and sentence breaks to ensure readability."
956+
},
952957
"codeWebChat.attachAsciiTreeOfContext": {
953958
"type": "string",
954959
"scope": "resource",
@@ -974,6 +979,16 @@
974979
"scope": "resource",
975980
"default": true
976981
},
982+
"codeWebChat.defaultOptionForVoiceInput": {
983+
"type": "string",
984+
"scope": "resource",
985+
"enum": [
986+
"ask",
987+
"send-request",
988+
"invoke-agent"
989+
],
990+
"default": "ask"
991+
},
977992
"codeWebChat.voiceInputPushToTalk": {
978993
"type": "boolean",
979994
"scope": "resource"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export const intelligent_file_search_format_for_prompt_view = (
6565
These files contain the core greeting logic and module exports.`
6666
}
6767

68-
export const voice_input_instructions =
69-
'Respond with a transcription of the following audio recording or the word INAUDIBLE, and nothing else.'
68+
export const voice_input_output_formatting =
69+
'Respond with the audio transcription or the word INAUDIBLE, without explanations or any other text.'
7070

7171
export const cli_edit_ask_requirements = {
7272
preloaded_context:

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1111
import axios from 'axios'
1212
import { send_llm_message } from '@/utils/send-llm-message'
1313
import {
14-
voice_input_instructions,
14+
voice_input_output_formatting,
1515
cli_edit_ask_requirements
1616
} from '@/constants/instructions'
1717
import {
@@ -126,12 +126,28 @@ const stop_recording = async (prompt_view_provider: PromptViewProvider) => {
126126

127127
prompt_view_provider.audio_chunks = []
128128

129+
const config = vscode.workspace.getConfiguration('codeWebChat')
130+
const default_option = config.get<'ask' | 'send-request' | 'invoke-agent'>(
131+
'defaultOptionForVoiceInput'
132+
)
133+
const voice_input_task_instructions = config.get<string>(
134+
'voiceInputInstructions'
135+
)
136+
129137
let current_action =
130138
prompt_view_provider.extension_context.workspaceState.get<string>(
131139
LAST_USED_VOICE_INPUT_ACTION_STATE_KEY
132140
)
133141
let show_action_quick_pick = true
134142

143+
if (default_option == 'send-request') {
144+
current_action = 'send-request'
145+
show_action_quick_pick = false
146+
} else if (default_option == 'invoke-agent') {
147+
current_action = 'invoke-agent'
148+
show_action_quick_pick = false
149+
}
150+
135151
while (true) {
136152
if (show_action_quick_pick) {
137153
current_action = await new Promise<string | undefined | 'back'>(
@@ -140,7 +156,7 @@ const stop_recording = async (prompt_view_provider: PromptViewProvider) => {
140156
vscode.QuickPickItem & { id: string }
141157
>()
142158
quick_pick.items = [
143-
{ label: t('common.action.send-request'), id: 'make-api' },
159+
{ label: t('common.action.send-request'), id: 'send-request' },
144160
{ label: t('common.action.invoke-agent'), id: 'invoke-agent' }
145161
]
146162
const active_item = current_action
@@ -196,9 +212,7 @@ const stop_recording = async (prompt_view_provider: PromptViewProvider) => {
196212
show_action_quick_pick = false
197213

198214
if (current_action == 'invoke-agent') {
199-
const config_codeWebChat =
200-
vscode.workspace.getConfiguration('codeWebChat')
201-
const agent_configs = config_codeWebChat.get<any[]>('agents', []) || []
215+
const agent_configs = config.get<any[]>('agents', []) || []
202216
const default_agent = agent_configs.find(
203217
(c: any) => c.isDefaultForVoiceInput
204218
)
@@ -213,7 +227,7 @@ const stop_recording = async (prompt_view_provider: PromptViewProvider) => {
213227
)
214228
await fs.promises.writeFile(temp_audio_path, audio_buffer)
215229

216-
const cli_prompt = `# Task\n\n${voice_input_instructions}\n\nAudio file: \`${temp_audio_path.replace(/\\/g, '/')}\`\n\n# Requirements\n\n- ${cli_edit_ask_requirements.disable_tool_calling}\n- ${cli_edit_ask_requirements.exception_read_audio}`
230+
const cli_prompt = `# Task\n\n${voice_input_task_instructions}\n\nAudio file: \`${temp_audio_path.replace(/\\/g, '/')}\`\n\n# Output formatting\n\n${voice_input_output_formatting}\n\n# Requirements\n\n- ${cli_edit_ask_requirements.disable_tool_calling}\n- ${cli_edit_ask_requirements.exception_read_audio}`
217231

218232
const invoke_cli_result = await invoke_agentic_cli({
219233
workspace_provider: prompt_view_provider.workspace_provider,
@@ -262,7 +276,7 @@ const stop_recording = async (prompt_view_provider: PromptViewProvider) => {
262276
prompt_view_provider.add_text_at_cursor_position(text)
263277
}
264278
break
265-
} else if (current_action == 'make-api') {
279+
} else if (current_action == 'send-request') {
266280
let show_quick_pick = false
267281

268282
while (true) {
@@ -306,7 +320,10 @@ const stop_recording = async (prompt_view_provider: PromptViewProvider) => {
306320
{
307321
role: 'user',
308322
content: [
309-
{ type: 'text', text: voice_input_instructions },
323+
{
324+
type: 'text',
325+
text: `# Task\n\n${voice_input_task_instructions}\n\n# Output formatting\n\n${voice_input_output_formatting}`
326+
},
310327
{
311328
type: 'input_audio',
312329
input_audio: { data: base64_audio, format: 'wav' }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsViewProvider } from '@/views/settings/backend/settings-view-provider'
3+
4+
export const handle_get_default_option_for_voice_input = async (
5+
provider: SettingsViewProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const value = config.get<'ask' | 'send-request' | 'invoke-agent'>(
9+
'defaultOptionForVoiceInput',
10+
'ask'
11+
)
12+
provider.postMessage({
13+
command: 'DEFAULT_OPTION_FOR_VOICE_INPUT',
14+
value
15+
})
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsViewProvider } from '../settings-view-provider'
3+
4+
export const handle_get_voice_input_instructions = async (
5+
provider: SettingsViewProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const default_instructions =
9+
config.inspect<string>('voiceInputInstructions')?.defaultValue || ''
10+
const instructions =
11+
config.get<string>('voiceInputInstructions') || default_instructions
12+
provider.postMessage({
13+
command: 'VOICE_INPUT_INSTRUCTIONS',
14+
instructions,
15+
default_instructions
16+
})
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as vscode from 'vscode'
2+
import { UpdateDefaultOptionForVoiceInputMessage } from '@/views/settings/types/messages'
3+
4+
export const handle_update_default_option_for_voice_input = async (
5+
message: UpdateDefaultOptionForVoiceInputMessage
6+
): Promise<void> => {
7+
await vscode.workspace
8+
.getConfiguration('codeWebChat')
9+
.update(
10+
'defaultOptionForVoiceInput',
11+
message.value,
12+
vscode.ConfigurationTarget.Global
13+
)
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as vscode from 'vscode'
2+
import { UpdateVoiceInputInstructionsMessage } from '../../types/messages'
3+
4+
export const handle_update_voice_input_instructions = async (
5+
message: UpdateVoiceInputInstructionsMessage
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const default_instructions =
9+
config.inspect<string>('voiceInputInstructions')?.defaultValue || ''
10+
await config.update(
11+
'voiceInputInstructions',
12+
message.instructions == '' || message.instructions == default_instructions
13+
? undefined
14+
: message.instructions,
15+
vscode.ConfigurationTarget.Global
16+
)
17+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export * from './handle-get-use-context-files-in-commit-message-prompt'
1919
export * from './handle-update-use-context-files-in-commit-message-prompt'
2020
export * from './handle-get-include-prompts-in-commit-messages'
2121
export * from './handle-update-include-prompts-in-commit-messages'
22+
export * from './handle-get-default-option-for-voice-input'
23+
export * from './handle-update-default-option-for-voice-input'
24+
export * from './handle-get-voice-input-instructions'
25+
export * from './handle-update-voice-input-instructions'
2226
export * from './handle-get-gemini-user-id'
2327
export * from './handle-update-gemini-user-id'
2428
export * from './handle-get-ai-studio-user-id'

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
handle_get_attach_ascii_tree_of_context,
1313
handle_get_use_context_files_in_commit_message_prompt,
1414
handle_get_include_prompts_in_commit_messages,
15+
handle_get_default_option_for_voice_input,
16+
handle_get_voice_input_instructions,
1517
handle_get_edit_files_system_instructions,
1618
handle_get_gemini_user_id,
1719
handle_get_ai_studio_user_id,
@@ -24,6 +26,8 @@ import {
2426
handle_update_attach_ascii_tree_of_context,
2527
handle_update_use_context_files_in_commit_message_prompt,
2628
handle_update_include_prompts_in_commit_messages,
29+
handle_update_default_option_for_voice_input,
30+
handle_update_voice_input_instructions,
2731
handle_update_edit_files_system_instructions,
2832
handle_update_gemini_user_id,
2933
handle_update_ai_studio_user_id,
@@ -185,6 +189,14 @@ export class SettingsViewProvider {
185189
'UPDATE_SELECT_ALL_PROMPTS_IN_COMMIT_MESSAGES_BY_DEFAULT'
186190
) {
187191
await handle_update_include_prompts_in_commit_messages(message)
192+
} else if (message.command == 'GET_DEFAULT_OPTION_FOR_VOICE_INPUT') {
193+
await handle_get_default_option_for_voice_input(this)
194+
} else if (message.command == 'UPDATE_DEFAULT_OPTION_FOR_VOICE_INPUT') {
195+
await handle_update_default_option_for_voice_input(message)
196+
} else if (message.command == 'GET_VOICE_INPUT_INSTRUCTIONS') {
197+
await handle_get_voice_input_instructions(this)
198+
} else if (message.command == 'UPDATE_VOICE_INPUT_INSTRUCTIONS') {
199+
await handle_update_voice_input_instructions(message)
188200
} else if (message.command == 'GET_GEMINI_USER_ID') {
189201
await handle_get_gemini_user_id(this)
190202
} else if (message.command == 'UPDATE_GEMINI_USER_ID') {
@@ -273,6 +285,8 @@ export class SettingsViewProvider {
273285
void handle_get_attach_ascii_tree_of_context(this)
274286
void handle_get_use_context_files_in_commit_message_prompt(this)
275287
void handle_get_include_prompts_in_commit_messages(this)
288+
void handle_get_default_option_for_voice_input(this)
289+
void handle_get_voice_input_instructions(this)
276290
void handle_get_gemini_user_id(this)
277291
void handle_get_ai_studio_user_id(this)
278292
void handle_get_send_with_shift_enter(this)

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type NavItem =
2222
| 'section:general:group:open-links'
2323
| 'section:general:group:prompt'
2424
| 'section:general:group:commits'
25+
| 'section:general:group:voice-input'
2526
| 'section:web'
2627
| 'section:web:group:chatbots'
2728
| 'section:web:group:web-defaults'
@@ -53,6 +54,10 @@ export const NAV_ITEMS_CONFIG: NavConfigItem[] = [
5354
id: 'section:general:group:commits',
5455
label: 'general.commits.title'
5556
},
57+
{
58+
id: 'section:general:group:voice-input',
59+
label: 'general.voice-input.title'
60+
},
5661
{
5762
id: 'section:web',
5863
label: 'web.title'
@@ -112,6 +117,13 @@ type Props = {
112117
attach_ascii_tree_of_context: 'ask' | 'always' | 'never'
113118
use_context_files_in_commit_message_prompt: 'ask' | 'always' | 'never'
114119
select_all_prompts_in_commit_messages_by_default: boolean
120+
default_option_for_voice_input: 'ask' | 'send-request' | 'invoke-agent'
121+
on_default_option_for_voice_input_change: (
122+
value: 'ask' | 'send-request' | 'invoke-agent'
123+
) => void
124+
voice_input_instructions: string
125+
default_voice_input_instructions: string
126+
on_voice_input_instructions_change: (instructions: string) => void
115127
gemini_user_id: number | null
116128
ai_studio_user_id: number | null
117129
send_with_shift_enter: boolean
@@ -212,6 +224,7 @@ export const Home: React.FC<Props> = (props) => {
212224

213225
const [commit_instructions, set_commit_instructions] = useState('')
214226
const [edit_files_instructions, set_edit_files_instructions] = useState('')
227+
const [voice_instructions, set_voice_instructions] = useState('')
215228

216229
const get_has_warning = (id: NavItem): boolean => {
217230
if (id == 'section:api:group:providers') {
@@ -231,6 +244,10 @@ export const Home: React.FC<Props> = (props) => {
231244
set_edit_files_instructions(props.edit_files_system_instructions || '')
232245
}, [props.edit_files_system_instructions])
233246

247+
useEffect(() => {
248+
set_voice_instructions(props.voice_input_instructions || '')
249+
}, [props.voice_input_instructions])
250+
234251
return (
235252
<div style={{ height: '100vh' }}>
236253
<UiLayout
@@ -326,6 +343,29 @@ export const Home: React.FC<Props> = (props) => {
326343
on_select_all_prompts_in_commit_messages_by_default_change={
327344
props.on_select_all_prompts_in_commit_messages_by_default_change
328345
}
346+
default_option_for_voice_input={props.default_option_for_voice_input}
347+
on_default_option_for_voice_input_change={
348+
props.on_default_option_for_voice_input_change
349+
}
350+
voice_instructions={voice_instructions}
351+
set_voice_instructions={set_voice_instructions}
352+
on_voice_instructions_blur={() => {
353+
props.on_voice_input_instructions_change(voice_instructions)
354+
if (
355+
voice_instructions == '' &&
356+
props.voice_input_instructions ==
357+
props.default_voice_input_instructions
358+
) {
359+
set_voice_instructions(props.default_voice_input_instructions)
360+
}
361+
}}
362+
default_voice_instructions={props.default_voice_input_instructions}
363+
on_restore_voice_instructions={() => {
364+
set_voice_instructions(props.default_voice_input_instructions)
365+
props.on_voice_input_instructions_change(
366+
props.default_voice_input_instructions
367+
)
368+
}}
329369
commit_instructions={commit_instructions}
330370
set_commit_instructions={set_commit_instructions}
331371
on_commit_instructions_blur={() => {

0 commit comments

Comments
 (0)