Skip to content

feat: Mistral Vibe sign-in provider (CLI + v8 management) - #13

Open
bntvllnt wants to merge 8 commits into
mainfrom
feat/mistral-login
Open

bntvllnt wants to merge 8 commits into
mainfrom
feat/mistral-login

Conversation

@bntvllnt

Copy link
Copy Markdown

What

Adds a built-in mistral provider so a Mistral Vibe / Le Chat Pro plan can be used through the proxy.

Sign-in uses the same browser flow as Mistral's Vibe CLI (PKCE create → server-side poll → exchange) and returns a normal Mistral API key. Plan usage is pooled across Studio, API and Vibe per Mistral's docs. The key does not expire, so there is no refresh.

UI / CLI ──► /v8/management/oauth/auth-url?provider=mistral
proxy ──► POST console.mistral.ai/api/vibe/sign-in  → sign_in_url (user approves)
proxy polls poll_url → exchange → api_key → auths/mistral-*.json (0600)
requests ──► OpenAI-compatible executor ──► api.mistral.ai/v1/chat/completions
  • --mistral-login CLI flag (honours --no-browser, --login-proxy)
  • v8 management: provider=mistral on oauth/auth-url; status and cancel use the existing generic endpoints. No /v0 changes.
  • Reuses the OpenAI-compatible executor. The only change there is a fallback that reads base_url/api_key from auth Metadata when Attributes lack them, so the raw key never lands in Attributes or usage records.
  • Static model list from Vibe's own config: mistral-large-4-0, mistral-vibe-cli-latest, mistral-vibe-cli-fast, mistral-small-latest
  • TUI entry and docs/management-api-v8.md

Security

  • sign_in_url / poll_url must be on the sign-in origin (poll_url under /api). Redirects are not followed.
  • The API key, exchange token, PKCE verifier and full sign-in URL are never logged. Known gap: a transport error while polling can log the poll URL, which carries a short-lived polling token. That token cannot exchange for the key without the verifier.
  • Each sign-in creates a new key in the Mistral workspace. Deleting the auth file does not revoke it (documented in the UI).

Tests

  • Unit tests for the sign-in client: PKCE S256, pending→completed, 410 expired, denied, provider error, unknown status, 403/9004 workspace message, missing key, foreign-origin URLs, cancel, lifetime.
  • Management handler: auth-url → status wait→ok → 0600 file, failure paths, cancel, targeted re-login.
  • E2E test/mistral_login_e2e_test.go against a fake Mistral: sign-in, then OpenAI /v1/chat/completions and Claude /v1/messages (stream and non-stream) through the proxy. Asserts the upstream bearer key, path and model. Covers the denied path and an upstream 401 surfacing to the client.
  • Regression test that user payload rules are applied last on the Mistral path (AGENTS.md).

Results:

  • go vet ./... and go build pass.
  • Targeted packages pass: 1457 tests in the Mistral-related packages plus 13 targeted Mistral tests, rerun by the lead.
  • Full go test ./... has one failure, internal/discovery TestAdvertiserAndBrowser_Integration (mDNS). It fails the same way on main.
  • gofmt lists two untouched test files that are already unformatted on main.

Manual check

A local proxy and the UI from the companion PR, opened in a browser:

  • The real console.mistral.ai sign-in URL is returned, the waiting state shows, cancel works.
  • Desktop 1440px and mobile 390px: no overflow, no console errors.

Not yet verified live: approving a sign-in and a real inference call. That needs the account owner to click approve.

Companion UI PR: vllnt/Cli-Proxy-API-Management-Center feat/mistral-login.

Adds internal/auth/mistral: PKCE S256 sign-in (start, poll, exchange) against the Mistral console API, origin and path validation of returned URLs, no-redirect HTTP client, and credential metadata/file naming that keeps the API key out of names and labels.
Auth files restored from disk carry api_key and base_url in Metadata only. Fall back to Metadata when Attributes lack them so file-based API-key providers such as Mistral work, while keeping the raw key out of Attributes and usage records. Adds mistral request-path tests, including the payload-config-last regression.
Hard-codes the Mistral Vibe model IDs instead of extending models.json, because the remote catalog refresh replaces models.json wholesale and has no Mistral section.
Registers the Mistral authenticator with the CLI auth manager and refresh registry (no scheduled refresh: the provisioned key does not expire), adds the --mistral-login flag, and builds auth records with the key in Metadata only.
Dispatch provider=mistral from /v8/management/oauth/auth-url to a sign-in flow that returns the sign-in url and state. Status and cancel reuse the generic v8 OAuth session routes. Mistral keys carry no email or account id, so targeted re-login is allowed like Kimi.
Bind the Mistral provider to the shared OpenAI-compatible executor and publish the static Mistral model list for each Mistral credential, honoring oauth-excluded-models.
Add Mistral to the TUI OAuth provider list and the v8 provider table, and document the mistral provider in the v8 management API docs.
Drive the v8 sign-in against a fake Mistral service, then serve OpenAI and Claude format requests (stream and non-stream) with the provisioned key. Add denied sign-in and upstream 401 cases, and a service-level test that a saved credential file is picked up by the watcher.
}

func keyFingerprint(apiKey string) string {
sum := sha256.Sum256([]byte(strings.TrimSpace(apiKey)))
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.

2 participants