@@ -101,16 +101,53 @@ export class ModelPickerWidget extends Disposable {
101
101
* Shows the picker at the specified anchor
102
102
*/
103
103
showAt ( anchor : HTMLElement | StandardMouseEvent | IAnchor , container ?: HTMLElement ) : void {
104
- const items : IActionListItem < ILanguageModelChatMetadataAndIdentifier > [ ] = this . getActionItems ( ) . map ( item => ( {
105
- item : item . model ,
106
- description : item . model . metadata . description ,
107
- kind : ActionListItemKind . Action ,
108
- canPreview : false ,
109
- group : { title : '' , icon : ThemeIcon . fromId ( item . isCurrent ? Codicon . check . id : Codicon . blank . id ) } ,
110
- disabled : false ,
111
- hideIcon : false ,
112
- label : item . model . metadata . name ,
113
- } satisfies IActionListItem < ILanguageModelChatMetadataAndIdentifier > ) ) ;
104
+ const actionItems = this . getActionItems ( ) ;
105
+ const items : IActionListItem < ILanguageModelChatMetadataAndIdentifier > [ ] = [ ] ;
106
+
107
+ // Group models by categories
108
+ const modelsByCategory = new Map < string , IModelPickerActionItem [ ] > ( ) ;
109
+
110
+ // First, group models by their categories
111
+ for ( const item of actionItems ) {
112
+ const category = item . model . metadata . modelPickerCategory ;
113
+ if ( ! modelsByCategory . has ( category . label ) ) {
114
+ modelsByCategory . set ( category . label , [ ] ) ;
115
+ }
116
+ modelsByCategory . get ( category . label ) ! . push ( item ) ;
117
+ }
118
+
119
+ for ( const [ categoryLabel , modelsInCategory ] of modelsByCategory . entries ( ) ) {
120
+ // Skip empty categories
121
+ if ( modelsInCategory . length === 0 ) {
122
+ continue ;
123
+ }
124
+
125
+ // Add category header
126
+ items . push ( {
127
+ label : categoryLabel ,
128
+ kind : ActionListItemKind . Header ,
129
+ canPreview : false ,
130
+ disabled : false ,
131
+ hideIcon : true ,
132
+ } satisfies IActionListItem < ILanguageModelChatMetadataAndIdentifier > ) ;
133
+
134
+ // Add models in this category
135
+ for ( const item of modelsInCategory ) {
136
+ items . push ( {
137
+ item : item . model ,
138
+ description : item . model . metadata . description ,
139
+ kind : ActionListItemKind . Action ,
140
+ canPreview : false ,
141
+ group : { title : '' , icon : ThemeIcon . fromId ( item . isCurrent ? Codicon . check . id : Codicon . blank . id ) } ,
142
+ disabled : false ,
143
+ hideIcon : false ,
144
+ label : item . model . metadata . name ,
145
+ } satisfies IActionListItem < ILanguageModelChatMetadataAndIdentifier > ) ;
146
+ }
147
+
148
+ // Remove this category from the map so we don't process it again
149
+ modelsByCategory . delete ( categoryLabel ) ;
150
+ }
114
151
115
152
const delegate = {
116
153
onSelect : ( item : ILanguageModelChatMetadataAndIdentifier ) => {
0 commit comments