jackwener/OpenCLI · error · ArgumentError

Model "${wanted}" is ambiguous in Trae CN model menu: ${cont

Error message

Model "${wanted}" is ambiguous in Trae CN model menu: ${containsMatches.map(item => item.Model).join(', ')}

What it means

selectTraeModel matches the requested model name against the model menu using normalized labels. When there is no exact match but multiple fuzzy (substring) matches exist, the choice is ambiguous and the library throws this ArgumentError listing all candidates so you can disambiguate.

Source

Thrown at clis/trae-cn/utils.js:724

    'The prompt was injected and submit was triggered, but no new user turn containing that prompt appeared.',
  );
}

export async function selectTraeModel(page, name) {
  const wanted = ensurePrompt(name);
  const wantedKey = normalizeModelLabel(wanted);
  let models = await page.evaluate(listOpenModelItemsScript());
  if (!models || models.length === 0) {
    await page.click(TRAE_CN_MODEL_TRIGGER_SELECTOR);
    await page.wait(0.8);
    models = await page.evaluate(listOpenModelItemsScript());
  }
  const exactMatch = models.find((item) => normalizeModelLabel(item.Model) === wantedKey);
  const containsMatches = exactMatch
    ? []
    : models.filter((item) => normalizeModelLabel(item.Model).includes(wantedKey));
  if (!exactMatch && containsMatches.length > 1) {
    throw new ArgumentError(
      `Model "${wanted}" is ambiguous in Trae CN model menu: ${containsMatches.map(item => item.Model).join(', ')}`,
    );
  }
  const match = exactMatch || containsMatches[0];
  if (!match) {
    throw new ArgumentError(`Model "${wanted}" not found in Trae CN model menu`);
  }
  await page.click(TRAE_CN_MODEL_ITEM_SELECTOR, { nth: match.Index });
  await page.wait(0.8);
  const info = await page.evaluate(inspectTraeShellScript());
  const selectedLabel = info.model || '';
  const selectedKey = normalizeModelLabel(selectedLabel);
  const matchKey = normalizeModelLabel(match.Model);
  if (!selectedKey || (selectedKey !== matchKey && selectedKey !== wantedKey)) {
    throw new CommandExecutionError(
      `Trae CN model switch did not verify the requested model: requested "${wanted}", current "${selectedLabel || 'unknown'}"`,
      'Open the Trae CN model menu and verify the requested model is selectable, then retry.',
    );

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the full exact model name as shown in the Trae CN menu
  2. Pick one of the listed ambiguous candidates verbatim
  3. Check the model menu contents first with a read/inspect command

Example fix

// before
selectTraeModel(page, 'deepseek')
// after
selectTraeModel(page, 'deepseek-r1')
Defensive patterns

Strategy: validation

Validate before calling

const models = await page.evaluate(listModelsScript());
const wantedKey = normalizeModelLabel(wanted);
const matches = models.filter(m => normalizeModelLabel(m.Model).includes(wantedKey));
if (!matches.some(m => normalizeModelLabel(m.Model) === wantedKey) && matches.length > 1)
  throw new Error(`Ambiguous model "${wanted}": ${matches.map(m=>m.Model).join(', ')}`);

Type guard

const isUnambiguousModel = (models, wanted) => {
  const key = normalizeModelLabel(wanted);
  return models.some(m => normalizeModelLabel(m.Model) === key) ||
    models.filter(m => normalizeModelLabel(m.Model).includes(key)).length === 1;
};

Try / catch

try { await selectTraeModel(page, name); } catch (e) { if (/is ambiguous/.test(e.message)) { console.error(e.message + '\nPass the full model name'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Passing a partial name that matches several menu entries, e.g. 'gpt' matching 'gpt-4o' and 'gpt-4o-mini', or a common prefix like 'deepseek'.

Common situations: Users typing shorthand model names, or menu containing multiple variants/families of the same model line.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/c79eb285cb0e7a91. Report an issue: GitHub.