Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static List<DropdownItem> buildModelDropdownItems(List<CopilotModel> mod
String selectedLabel = StringUtils.isNotBlank(effortLevel) && StringUtils.isNotBlank(name)
? name + " - " + effortLevel : null;

items.add(new DropdownItem.Builder().id(rawName).label(name).selectedLabel(selectedLabel).suffix(suffix)
items.add(new DropdownItem.Builder().id(model.getModelKey()).label(name).selectedLabel(selectedLabel).suffix(suffix)
.icon(resolveModelIcon(model)).hoverProvider(new ModelHoverContentProvider(model)).build());
}
return items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ private void initializeEventHandlers() {
currentChatMode = ChatMode.Agent;
updateModelsForChatMode(ChatMode.Agent);

// Then switch to the specified model (setActiveModel will be called after models are loaded)
setActiveModel(modelName);
// Resolve name to key, then activate
String modelKey = findModelKeyByName(modelName);
if (modelKey != null) {
setActiveModel(modelKey);
}
}
};
}
Expand Down Expand Up @@ -328,25 +331,31 @@ private void onDidCopilotStatusChange(CopilotStatusResult copilotStatusResult) {
}
}

private String findModelKeyByName(String modelName) {
Map<String, CopilotModel> currentModels = modelObservable.getValue();
for (Map.Entry<String, CopilotModel> entry : currentModels.entrySet()) {
if (entry.getValue().getModelName().equals(modelName)) {
return entry.getKey();
}
}
return null;
}

/**
* Set the active model by name.
* Set the active model by its composite key.
*
* @param modelName the name of the model
* @param modelKey the composite key of the model
*/
public void setActiveModel(String modelName) {
public void setActiveModel(String modelKey) {
Map<String, CopilotModel> currentModels = modelObservable.getValue();

// Find model by model name and get its composite key
String compositeKey = null;
final CopilotModel model;
CopilotModel foundModel = null;

for (Map.Entry<String, CopilotModel> entry : currentModels.entrySet()) {
if (entry.getValue().getModelName().equals(modelName)) {
compositeKey = entry.getKey();
foundModel = entry.getValue();
break;
}
if (currentModels.containsKey(modelKey)) {
compositeKey = modelKey;
foundModel = currentModels.get(modelKey);
}
model = foundModel;
if (model != null && compositeKey != null) {
Expand Down Expand Up @@ -396,7 +405,7 @@ public CopilotModel getFallbackModel() {
*/
public void setFallBackModelAsActiveModel() {
if (fallbackModel != null) {
setActiveModel(fallbackModel.getModelName());
setActiveModel(fallbackModel.getModelKey());
}
}

Expand Down Expand Up @@ -551,7 +560,7 @@ public void bindModelPicker(final DropdownButton picker) {
if (activeModel == null || picker.isDisposed()) {
return;
}
picker.setSelectedItemId(activeModel.getModelName());
picker.setSelectedItemId(activeModel.getModelKey());
String suffix = StringUtils.isNotBlank(activeModel.getDegradationReason())
? " - " + activeModel.getDegradationReason() : "";
picker.setToolTipText(NLS.bind(Messages.chat_actionBar_modelPicker_Tooltip, suffix));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void mouseDown(MouseEvent e) {
// to update its label/suffix so the dropdown control reflects the (model, effort) pair the user just
// chose -- even when they clicked an effort on a non-active model.
modelService.setSelectedReasoningEffort(model, effort);
modelService.setActiveModel(model.getModelName());
modelService.setActiveModel(model.getModelKey());
// Close the entire dropdown (hover + main popup) via the host-provided callback so the user sees an
// immediate dismiss. Next time the dropdown opens, refreshBoundModelPickers (invoked from
// setSelectedReasoningEffort) has updated the model row's suffix to reflect the newly selected effort.
Expand Down