Skip to content

Commit a9544e5

Browse files
committed
Implement recently used voice input configurations tracking and quick pick sorting
1 parent 84d9107 commit a9544e5

3 files changed

Lines changed: 106 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ Code Web Chat operates exclusively on your machine. Your prompts are sent direct
118118
- `Code Web Chat: Check All with Keywords` - Search and add files containing specific keywords to the context.
119119
- `Code Web Chat: Copy Context` - Copy XML-formatted checked files from the Workspace view to the clipboard.
120120
- `Code Web Chat: Copy Context of Open Editors` - Copy XML-formatted checked files from the Open Editors view to the clipboard.
121-
- `Code Web Chat: Undo Context Selection` - Undo the last context change.
122-
- `Code Web Chat: Redo Context Selection` - Redo the last undone context change.
123121

124122
### Commit messages
125123

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export const RECENTLY_USED_COMMIT_MESSAGES_CONFIG_IDS_STATE_KEY =
6161
'recently-used-commit-messages-config-ids'
6262
export const RECENTLY_USED_INTELLIGENT_UPDATE_CONFIG_IDS_STATE_KEY =
6363
'recently-used-intelligent-update-config-ids'
64+
export const RECENTLY_USED_VOICE_INPUT_CONFIG_IDS_STATE_KEY =
65+
'recently-used-voice-input-config-ids'
6466

6567
export const get_presets_collapsed_state_key = (web_prompt_type: string) =>
6668
`presets-collapsed-${web_prompt_type}`

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

Lines changed: 104 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import { spawn } from 'child_process'
44
import { Logger } from '@shared/utils/logger'
55
import {
66
ModelProvidersManager,
7-
ToolConfig
7+
ToolConfig,
8+
get_tool_config_id
89
} from '@/services/model-providers-manager'
910
import { PROVIDERS } from '@shared/constants/providers'
1011
import * as vscode from 'vscode'
1112
import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1213
import axios from 'axios'
1314
import { make_api_request } from '@/utils/make-api-request'
1415
import { voice_input_instructions } from '@/constants/instructions'
16+
import { RECENTLY_USED_VOICE_INPUT_CONFIG_IDS_STATE_KEY } from '@/constants/state-keys'
1517

1618
const MIN_RECORDING_DURATION = 1000
1719

@@ -66,19 +68,110 @@ const stop_recording = async (panel_provider: PanelProvider) => {
6668
if (configs.length == 1) {
6769
config = configs[0]
6870
} else {
69-
const selected = await vscode.window.showQuickPick(
70-
configs.map((c) => ({
71-
label: c.model,
72-
description: c.provider_name,
73-
config: c
74-
})),
71+
const recent_ids =
72+
panel_provider.context.workspaceState.get<string[]>(
73+
RECENTLY_USED_VOICE_INPUT_CONFIG_IDS_STATE_KEY
74+
) || []
75+
76+
const matched_recent_configs: ToolConfig[] = []
77+
const remaining_configs: ToolConfig[] = []
78+
79+
configs.forEach((config) => {
80+
const id = get_tool_config_id(config)
81+
if (recent_ids.includes(id)) {
82+
matched_recent_configs.push(config)
83+
} else {
84+
remaining_configs.push(config)
85+
}
86+
})
87+
88+
matched_recent_configs.sort((a, b) => {
89+
const id_a = get_tool_config_id(a)
90+
const id_b = get_tool_config_id(b)
91+
return recent_ids.indexOf(id_a) - recent_ids.indexOf(id_b)
92+
})
93+
94+
const map_config_to_item = (config: ToolConfig) => ({
95+
label: config.model,
96+
description: config.provider_name,
97+
config,
98+
id: get_tool_config_id(config)
99+
})
100+
101+
const items: (vscode.QuickPickItem & {
102+
config?: ToolConfig
103+
id?: string
104+
})[] = []
105+
106+
if (matched_recent_configs.length > 0) {
107+
items.push({
108+
label: 'recently used',
109+
kind: vscode.QuickPickItemKind.Separator
110+
})
111+
items.push(...matched_recent_configs.map(map_config_to_item))
112+
}
113+
114+
if (remaining_configs.length > 0) {
115+
if (matched_recent_configs.length > 0) {
116+
items.push({
117+
label: 'other configurations',
118+
kind: vscode.QuickPickItemKind.Separator
119+
})
120+
}
121+
items.push(...remaining_configs.map(map_config_to_item))
122+
}
123+
124+
const quick_pick = vscode.window.createQuickPick()
125+
quick_pick.items = items
126+
quick_pick.title = 'Configurations'
127+
quick_pick.placeholder = 'Select a configuration'
128+
quick_pick.buttons = [
75129
{
76-
title: 'Configurations',
77-
placeHolder: 'Select a configuration'
130+
iconPath: new vscode.ThemeIcon('close'),
131+
tooltip: 'Close'
78132
}
79-
)
80-
if (selected) {
133+
]
134+
135+
const selected = await new Promise<
136+
| (vscode.QuickPickItem & {
137+
config?: ToolConfig
138+
id?: string
139+
})
140+
| undefined
141+
>((resolve) => {
142+
quick_pick.onDidTriggerButton((button) => {
143+
if (button.tooltip == 'Close') {
144+
resolve(undefined)
145+
quick_pick.hide()
146+
}
147+
})
148+
quick_pick.onDidAccept(() => {
149+
const selected = quick_pick.selectedItems[0] as any
150+
resolve(selected)
151+
quick_pick.hide()
152+
})
153+
quick_pick.onDidHide(() => {
154+
resolve(undefined)
155+
quick_pick.dispose()
156+
})
157+
quick_pick.show()
158+
})
159+
160+
if (selected && selected.config) {
81161
config = selected.config
162+
163+
let recents =
164+
panel_provider.context.workspaceState.get<string[]>(
165+
RECENTLY_USED_VOICE_INPUT_CONFIG_IDS_STATE_KEY
166+
) || []
167+
recents = [
168+
selected.id!,
169+
...recents.filter((id) => id != selected.id!)
170+
]
171+
panel_provider.context.workspaceState.update(
172+
RECENTLY_USED_VOICE_INPUT_CONFIG_IDS_STATE_KEY,
173+
recents
174+
)
82175
} else {
83176
return
84177
}

0 commit comments

Comments
 (0)