Skip to content

feat(upstreams): request headers alongside the API key, as in the enterprise gateway - #38

Merged
fylorn merged 1 commit into
devfrom
feat/upstream-headers
Sep 17, 2026
Merged

fylorn merged 1 commit into
devfrom
feat/upstream-headers

Conversation

@fylorn

@fylorn fylorn commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Why

The upstream dialog could only store one credential (a key, an environment variable, or an OAuth refresh token). Relays that authenticate with their own header, or that need anthropic-version or an organization header pinned, could not be connected. The enterprise gateway already edits upstream credentials as a header table; core v0.3.0 (ThinkWatchProject/ThinkWatch-Core#34) adopts the same model, and this PR brings the UI in line.

What changes

Connection step

  • The credential-type select is replaced by an authentication mode: API key or OAuth.
  • API key says which header the key is sent in (x-api-key, Authorization: Bearer, x-goog-api-key) for the chosen or detected protocol. Core computes this, not the UI. The field accepts ${VAR}, and an environment reference is shown in plain text. The key is optional.
  • Request headers: a row editor (name, value, remove). When editing, secret values are not filled back in: a blank value keeps the saved one ("已保存,留空即保持不变"), and renaming such a row requires a new value. Validation beyond required fields (reserved names, duplicates, placeholders) comes from core on test and save.
  • A saved key can be removed explicitly. Saved OAuth credentials are still replaced as a whole, since the refresh token and client secret never leave core.
  • Refreshing the model list re-tests with the form's values whenever the address, protocol, key, headers, OAuth or proxy differ from what is saved.

Plumbing

  • types.ts follows tw-api 0.3.0: SecretView, HeaderView, OAuthView, SecretChange, HeaderInput, OAuthChange; CredentialInput is removed.
  • preview_provider takes the whole ProviderPreviewRequest, including the selected protocol.
  • The Ollama preset no longer fills a placeholder key.

Unrelated fix found while reviewing the diff

  • The "新建代理…" and "新建价目表…" option values were literal NUL bytes, so git treated ConnectionSection.tsx and BillingSection.tsx as binary and their diffs did not render. They are now names with a leading space, which core rejects as real names. src/source.test.ts keeps control characters out of the sources. (Both files still show as binary in this PR's diff because the base version is binary. They render normally from the next change.)

Tests

  • upstreamForm.test.ts: keep, set and remove for the key; saved header values kept by name, case-insensitively; OAuth kept or replaced when switching modes; what counts as a connection change; required-field messages for header rows.
  • Checked in the isolated preview harness: editing a relay with a masked header, adding a reserved header (core error shown), switching to OAuth, saving an env-referenced key and reopening, removing a saved key, the saved-OAuth summary, and the key header following preset and protocol changes.

pnpm typecheck, pnpm test, cargo fmt --check, cargo clippy -D warnings and cargo test pass locally.

🤖 Generated with Claude Code

…erprise gateway

Pins core v0.3.0, which models upstream credentials as an API key plus an
ordered header table plus optional OAuth.

The connection step replaces the credential-type select (key / env /
OAuth) with:

- an authentication mode (API key or OAuth)
- an API key field that says which header the key is sent in for the
  chosen or detected protocol, and accepts `${VAR}`. The key is optional:
  local services and relays that authenticate with their own header do
  not need one
- a header editor. Saved values that are secrets are not filled back in;
  leaving one blank keeps it, the same convention the enterprise gateway
  uses. A saved key can be removed explicitly

Saved OAuth credentials are still replaced as a whole, because the
refresh token and client secret never come back from core.

Also fixes two sentinel option values in the proxy and price sheet selects
that were literal NUL bytes. They worked, but git treated both files as
binary, so their diffs were invisible in review. The sentinels are now
names with a leading space, which core rejects as real names, and a test
keeps control characters out of the sources.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit a0ec380 into dev Sep 17, 2026
2 checks passed
@fylorn
fylorn deleted the feat/upstream-headers branch September 17, 2026 11:21
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