@@ -4,14 +4,16 @@ import { spawn } from 'child_process'
44import { Logger } from '@shared/utils/logger'
55import {
66 ModelProvidersManager ,
7- ToolConfig
7+ ToolConfig ,
8+ get_tool_config_id
89} from '@/services/model-providers-manager'
910import { PROVIDERS } from '@shared/constants/providers'
1011import * as vscode from 'vscode'
1112import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1213import axios from 'axios'
1314import { make_api_request } from '@/utils/make-api-request'
1415import { voice_input_instructions } from '@/constants/instructions'
16+ import { RECENTLY_USED_VOICE_INPUT_CONFIG_IDS_STATE_KEY } from '@/constants/state-keys'
1517
1618const 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