Skip to content

fix(cli): keys add treats a provider name as a provider, not a URL (#142) - #155

Merged
Aayam Bansal (aayambansal) merged 1 commit into
mainfrom
fix/keys-add-provider-arg
Jul 8, 2026
Merged

Aayam Bansal (aayambansal) merged 1 commit into
mainfrom
fix/keys-add-provider-arg

Conversation

@aayambansal

Copy link
Copy Markdown
Member

Addresses the CLI crash in #142.

Problem

openscience keys add deepseek crashes:

Error: Unexpected error … fetch() URL is invalid

The add [url] positional was passed straight to fetch(\${url}/.well-known/openscience`), so a bare provider name became fetch("deepseek/.well-known/openscience")` — an invalid URL.

Fix

A new pure helper classifyKeyTarget(arg) classifies the positional:

  • an http(s) URL → a custom endpoint that advertises auth via /.well-known/openscience (the existing flow, unchanged)
  • a bare provider id (a-z0-9-, optional @ai-sdk/ prefix stripped) → preselects that provider and skips the picker, so keys add deepseek goes straight to the API-key prompt and stores a BYOK credential
  • anything else (a full model ref like deepseek/deepseek-v4-pro, spaces, other schemes) → falls through to the interactive picker with a clear note, instead of crashing

An unknown-but-valid provider id still stores the key, with a hint to finish wiring the provider in openscience.json.

Tests

Unit tests for the classifier, including the exact deepseek/deepseek-v4-pro shape from the report. Typecheck clean.

Scope note

This covers the CLI crash (path 2 in #142). The "manual config reverted on sync" part (path 1) is a separate concern in the sync/precedence layer — I'm tracking it separately and did not fold it in here. Supersedes #143, which stopped the crash but then ignored the provider name.

)

`openscience keys add deepseek` crashed with "fetch() URL is invalid":
the `add [url]` positional was passed straight to
`fetch(`${url}/.well-known/openscience`)`, so a bare provider name became
`fetch("deepseek/.well-known/openscience")`.

Classify the positional (new pure `classifyKeyTarget` helper):
- an http(s) URL is a custom endpoint → the well-known auth flow (unchanged)
- a bare provider id (a-z0-9-, optional `@ai-sdk/` prefix) preselects that
  provider and skips the picker, so `keys add deepseek` goes straight to the
  key prompt and stores a BYOK credential
- anything else falls through to the interactive picker with a clear note,
  instead of crashing

Unknown-but-valid ids still store the key with a hint to finish wiring the
provider in openscience.json. Adds unit tests for the classifier, including
the exact `deepseek/deepseek-v4-pro` shape from the report.
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openscience Ready Ready Preview, Comment Jul 8, 2026 8:22am

Request Review

@aayambansal
Aayam Bansal (aayambansal) merged commit 3a14065 into main Jul 8, 2026
12 checks passed
@aayambansal
Aayam Bansal (aayambansal) deleted the fix/keys-add-provider-arg branch July 8, 2026 08:26
pull Bot pushed a commit to vincentke1117/openscience that referenced this pull request Jul 11, 2026
…etic-sciences#159, synthetic-sciences#142)

The dashboard-synced config (default model, OpenRouter managed catalog)
was merged ON TOP of the user's own config, so a user's chosen default
model and custom OpenRouter models were reverted on every sync — the
'changes reverted on every sync' in synthetic-sciences#159/synthetic-sciences#142. Synced config is a
server recommendation, not a lockdown (enterprise lockdown is the /etc
managed layer, which still merges last and wins).

Flip the merge so the user's config overrides synced while model records
still union (server-whitelisted models the user didn't declare stay
available). Combined with the existing enabled_providers scoping, custom
BYOK providers and models added to openscience.json now persist.

Note: openscience-synced.json is sync-owned and rewritten each sync —
user edits belong in openscience.json. The 'keys add' crash was fixed
separately in synthetic-sciences#155.

This branch was successfully deployed

1 active deployment
Preview — d7ce9af7 Deployed Jul 8, 2026 by vercel[bot]
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.

1 participant