diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ModelPickerGroupsBuilder.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ModelPickerGroupsBuilder.java index fb838528..705ec253 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ModelPickerGroupsBuilder.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ModelPickerGroupsBuilder.java @@ -130,7 +130,7 @@ private static List buildModelDropdownItems(List 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; diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ModelService.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ModelService.java index c76cd6b1..0cb4708b 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ModelService.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ModelService.java @@ -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); + } } }; } @@ -328,25 +331,31 @@ private void onDidCopilotStatusChange(CopilotStatusResult copilotStatusResult) { } } + private String findModelKeyByName(String modelName) { + Map currentModels = modelObservable.getValue(); + for (Map.Entry 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 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 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) { @@ -396,7 +405,7 @@ public CopilotModel getFallbackModel() { */ public void setFallBackModelAsActiveModel() { if (fallbackModel != null) { - setActiveModel(fallbackModel.getModelName()); + setActiveModel(fallbackModel.getModelKey()); } } @@ -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)); diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/swt/ModelHoverContentProvider.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/swt/ModelHoverContentProvider.java index a1698ffe..e0690211 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/swt/ModelHoverContentProvider.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/swt/ModelHoverContentProvider.java @@ -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.