Skip to content

fix(models): use provider options apiKey for discovery and explain fallback (#152) - #161

Draft
justin-carper wants to merge 2 commits into
mainfrom
fix-152-discovery-key
Draft

justin-carper wants to merge 2 commits into
mainfrom
fix-152-discovery-key

Conversation

@justin-carper

Copy link
Copy Markdown
Collaborator

Fixes #152.

Cause

A key set only in provider.cursor.options.apiKey (README-documented) reached the provider for chat, but model discovery never saw it:

  • config hook called discoverModels({}) (env var or cache only)
  • provider.models route used only ctx.auth

So the picker showed the 4-model static fallback (src/fallback-models.ts), the exact list in the issue screenshot. Every discovery failure (no key, invalid key, network) also fell back silently: the warning was dropped.

Fix

  • config hook passes options.apiKey to discovery; provider.models route also reads provider.key / provider.options.apiKey.
  • One toast explaining a fallback. It waits for the auth loader's keyed refresh (or 10s) before deciding, so a stored opencode auth login key that works yields "restart to see all models" instead of a false "no key". If the config key fails but the stored key works, it names the config key. Timers unref'd; skipped under CI.

Not covered (tracked)

  • v2 path (src/plugin/v2.ts:345) has the equivalent gap and no notice.
  • Config hook and route use different key precedence when both a stored and an options key exist.

Verification

  • New test/issue-152-discovery-key.test.ts (12 cases) incl. loader-before-config and bad-config-key/good-stored-key.
  • npm run prepublishOnly: 668 tests pass, typecheck + build clean.
  • Bun ruled out as a cause: Cursor.models.list() behaves the same under Bun 1.4.1 and Node 26 (both reach Cursor's auth check).
  • Not run: a live opencode session with a real key.

…llback (#152)

The config hook and provider.models route ignored provider.cursor.options.apiKey, so users with the key only there got the 4-model static fallback while chat worked. Discovery now reads it (and provider.key), and a one-time toast explains any fallback, waiting for the auth loader's keyed refresh before deciding.
…s; skip under CI

Review follow-ups for #152: when options.apiKey/CURSOR_API_KEY fails but the stored login key works, warn about the config key instead of advising a restart that would not help. Notice timers are unref'd and skipped under CI. Tests cover loader-before-config and restore all touched env vars.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing models

1 participant