@@ -139,31 +139,57 @@ function buildModelSelectionExpression(
139139 };
140140
141141 const getButtonLabel = () => (button.textContent ?? '').trim();
142- if (MODEL_STRATEGY === 'current') {
143- return { status: 'already-selected', label: getButtonLabel() };
144- }
145- const buttonMatchesTarget = () => {
146- const normalizedLabel = normalizeText(getButtonLabel());
142+ const getSelectedModelLabels = () => {
143+ const labels = new Set();
144+ const push = (value) => {
145+ const normalized = (value ?? '').trim();
146+ if (normalized) {
147+ labels.add(normalized);
148+ }
149+ };
150+ push(getButtonLabel());
151+ const chipSelectors = [
152+ '[aria-label*="click to remove"]',
153+ '[class*="composer-pill"]',
154+ '[data-testid*="composer-pill"]',
155+ ];
156+ for (const selector of chipSelectors) {
157+ const nodes = Array.from(document.querySelectorAll(selector));
158+ for (const node of nodes) {
159+ push(node.getAttribute?.('aria-label')?.replace(/,\\s*click to remove$/i, ''));
160+ push(node.textContent);
161+ }
162+ }
163+ return Array.from(labels);
164+ };
165+ const labelMatchesTarget = (label) => {
166+ const normalizedLabel = normalizeText(label);
147167 if (!normalizedLabel) return false;
148168 if (desiredVersion) {
149169 if (desiredVersion === '5-4' && !normalizedLabel.includes('5 4')) return false;
150170 if (desiredVersion === '5-2' && !normalizedLabel.includes('5 2')) return false;
151171 if (desiredVersion === '5-1' && !normalizedLabel.includes('5 1')) return false;
152172 if (desiredVersion === '5-0' && !normalizedLabel.includes('5 0')) return false;
153173 }
154- if (wantsPro && !normalizedLabel.includes(' pro')) return false;
174+ if (wantsPro && !normalizedLabel.includes('pro')) return false;
155175 if (wantsInstant && !normalizedLabel.includes('instant')) return false;
156176 if (wantsThinking && !normalizedLabel.includes('thinking')) return false;
157- // Also reject if button has variants we DON'T want
158177 if (!wantsPro && normalizedLabel.includes(' pro')) return false;
159178 if (!wantsInstant && normalizedLabel.includes('instant')) return false;
160179 if (!wantsThinking && normalizedLabel.includes('thinking')) return false;
161180 return true;
162181 };
163-
164- if (buttonMatchesTarget()) {
182+ if (MODEL_STRATEGY === 'current') {
165183 return { status: 'already-selected', label: getButtonLabel() };
166184 }
185+ const currentSelectionMatchesTarget = () => {
186+ const labels = getSelectedModelLabels();
187+ return labels.some((label) => labelMatchesTarget(label));
188+ };
189+
190+ if (currentSelectionMatchesTarget()) {
191+ return { status: 'already-selected', label: getSelectedModelLabels()[0] || getButtonLabel() };
192+ }
167193
168194 let lastPointerClick = 0;
169195 const pointerClick = () => {
@@ -389,9 +415,9 @@ function buildModelSelectionExpression(
389415 }
390416 // Wait for the top bar label to reflect the requested model; otherwise keep scanning.
391417 setTimeout(() => {
392- if (buttonMatchesTarget ()) {
418+ if (currentSelectionMatchesTarget ()) {
393419 closeMenu();
394- resolve({ status: 'switched', label: getButtonLabel() || match.label });
420+ resolve({ status: 'switched', label: getSelectedModelLabels()[0] || getButtonLabel() || match.label });
395421 return;
396422 }
397423 attempt();
0 commit comments