Skip to content

feat(ai): self-host settings UI for Anthropic provider (5/5)#1987

Draft
gariasf wants to merge 2 commits into
feature/anthropic-rag-pgvectorfrom
feature/anthropic-settings-ui
Draft

feat(ai): self-host settings UI for Anthropic provider (5/5)#1987
gariasf wants to merge 2 commits into
feature/anthropic-rag-pgvectorfrom
feature/anthropic-settings-ui

Conversation

@gariasf
Copy link
Copy Markdown
Collaborator

@gariasf gariasf commented May 25, 2026

Summary

Closes the 5-PR Anthropic series. PR 5 of 5, stacked on #1986.

Adds the Anthropic panel and the install-wide LLM provider selector to the self-hosting settings page, plus a shared data-handling disclosure that covers both OpenAI and Anthropic with parity.

What changed

Views

  • _llm_provider_selector.html.erb — install-level select for Setting.llm_provider (`openai | anthropic`). Respects the `LLM_PROVIDER` env var (disables the control + shows the "configured through environment variables" hint, mirroring the OpenAI panel). Renders a compact "Data handling" block with one-sentence retention statements for each provider — surfaced once for both providers since the wording is the same.
  • _anthropic_settings.html.erb — mirrors _openai_settings.html.erb field-for-field:
    • anthropic_access_token password field, ******** redaction when stored, disabled when `ANTHROPIC_ACCESS_TOKEN` / `ANTHROPIC_API_KEY` env is set.
    • anthropic_base_url text field (optional — for AWS Bedrock / GCP Vertex proxies).
    • anthropic_model text field (optional — defaults to `claude-sonnet-4-6`).
    • All three fields disable when their env var is set, so env-driven installs see the value is locked.
  • show.html.erb — renders provider selector → OpenAI panel → Anthropic panel under the existing "General" section. No section restructure.

Controller (Settings::HostingsController)

  • Permits anthropic_access_token, anthropic_base_url, anthropic_model, llm_provider in hosting_params.
  • Persists each one, applying the same "********" placeholder protection that OpenAI uses so an unchanged form re-submit doesn't overwrite a stored key with the redacted display string.
  • Validates llm_provider against %w[openai anthropic] — unknown values are dropped without raising.
  • On Setting::ValidationError the rescue branch now also stashes @anthropic_base_url_input / @anthropic_model_input so the form re-renders with the user's typed values intact (parity with the OpenAI fix from issue Bug: OpenAI Custom URL field clears itself if Model is not filled first #1824).

Locales

  • Adds settings.hostings.llm_provider_selector.* and settings.hostings.anthropic_settings.* keys to config/locales/views/settings/hostings/en.yml.

Visual layout (General section)

General
├── AI Provider
│   ├── Active LLM provider:  [ OpenAI ▾ ]
│   ├── (provider help text)
│   └── Data handling
│       ├── OpenAI: API inputs are not used to train models by default. Standard retention is 30 days...
│       └── Anthropic: API inputs are not used to train models by default. Standard retention is 30 days...
├── OpenAI
│   └── (existing fields — unchanged)
├── Anthropic (Claude)
│   ├── API Key
│   ├── Base URL (Optional)
│   └── Default Model (Optional)
└── BrandFetch

Test plan

  • test/controllers/settings/hostings_controller_test.rb — 5 new tests:
    • update anthropic access token
    • "********" placeholder ignored (no overwrite of a stored key)
    • update anthropic base_url + model together
    • switch llm_provider to anthropic
    • reject unknown llm_provider values
  • Existing 26 hostings controller tests still pass (incl. the GET render exercising the three new partials).
  • bundle exec erb_lint ./app/views/settings/hostings/_anthropic_settings.html.erb ./app/views/settings/hostings/_llm_provider_selector.html.erb ./app/views/settings/hostings/show.html.erb — no errors.
  • Locale keys resolve via bin/rails runner I18n.t(...).
  • Full suite: 4385 runs, 18092 assertions, 0 failures, 26 pre-existing skips, 1 pre-existing libvips env error.
  • bin/rubocop clean on touched Ruby files.
  • bin/brakeman --no-pager clean.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1bfbdd37-eab5-44a0-9fdf-190f421907ca

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/anthropic-settings-ui

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gariasf gariasf force-pushed the feature/anthropic-rag-pgvector branch from 58c88d9 to 6d92ea2 Compare May 25, 2026 17:50
@gariasf gariasf force-pushed the feature/anthropic-settings-ui branch from a2866b2 to 21f475b Compare May 25, 2026 17:50
@gariasf gariasf force-pushed the feature/anthropic-rag-pgvector branch from 6d92ea2 to bb4fee3 Compare May 25, 2026 17:58
@gariasf gariasf force-pushed the feature/anthropic-settings-ui branch from 21f475b to 6b7a5c5 Compare May 25, 2026 17:58
@gariasf gariasf force-pushed the feature/anthropic-rag-pgvector branch from bb4fee3 to 06762d0 Compare May 25, 2026 18:34
@gariasf gariasf force-pushed the feature/anthropic-settings-ui branch from 6b7a5c5 to 603a2fd Compare May 25, 2026 18:39
@gariasf gariasf force-pushed the feature/anthropic-rag-pgvector branch from 06762d0 to d962f61 Compare May 26, 2026 08:39
@gariasf gariasf force-pushed the feature/anthropic-settings-ui branch from 603a2fd to 6903400 Compare May 26, 2026 08:39
@gariasf gariasf force-pushed the feature/anthropic-rag-pgvector branch from d962f61 to 509a2d2 Compare May 27, 2026 08:10
@gariasf gariasf force-pushed the feature/anthropic-settings-ui branch from 6903400 to fb9fd93 Compare May 27, 2026 08:10
gariasf added 2 commits May 27, 2026 10:42
Adds the Anthropic panel and the install-wide LLM provider selector to
the self-hosting settings page, plus a shared data-retention
disclosure that covers both OpenAI and Anthropic.

- New _llm_provider_selector partial: select for Setting.llm_provider
  (openai | anthropic), respects the LLM_PROVIDER env var (disables the
  control + shows the "configured through environment variables" hint
  when set, mirroring the existing OpenAI panel behaviour), and renders
  a compact data-handling block with one-line retention statements for
  each provider.
- New _anthropic_settings partial mirrors _openai_settings exactly:
  password-field for the API key with **** redaction, optional
  base_url (for AWS Bedrock / GCP Vertex), optional default model. All
  three fields disable when their ENV var is set.
- show.html.erb renders provider selector + OpenAI panel + Anthropic
  panel under the same "General" section so users can configure either
  (or both) without switching pages.
- Settings::HostingsController#update now permits and persists
  anthropic_access_token (ignoring the **** placeholder, same pattern
  as OpenAI), anthropic_base_url, anthropic_model, and llm_provider
  (validated against %w[openai anthropic]). On Setting::ValidationError
  the rescue branch preserves anthropic_base_url / anthropic_model
  input so the form re-renders with the user's typed values intact —
  parity with the issue #1824 fix for OpenAI.
- Locale keys added under settings.hostings.{llm_provider_selector,
  anthropic_settings}.

Tests cover token update + placeholder redaction, base_url + model
update, llm_provider switch to anthropic, and rejection of unknown
provider values. The existing GET render test still passes, exercising
all three new partials.

Closes the 5/5 Anthropic series stacked on #1986.
- Data-handling block in _llm_provider_selector swaps the invalid
  bg-surface-secondary token for bg-container-inset, matching the
  inset-card pattern used elsewhere in sure-design-system/components.css.
  bg-surface-secondary is not defined anywhere in the design system —
  Tailwind treated it as a no-op, so the block rendered with no
  background contrast.
- Settings::HostingsController validates anthropic_base_url as a
  URI::HTTP (catches https too) and raises Setting::ValidationError
  with a localized message when the input is not parseable.
  Previously any string was persisted, surfacing as an opaque
  connection error at request time instead of an immediate UX failure.
- Blank base_url now clears the setting (was already the case but
  exercised explicitly in tests now).
@gariasf gariasf force-pushed the feature/anthropic-rag-pgvector branch from 509a2d2 to b6e4b11 Compare May 27, 2026 08:42
@gariasf gariasf force-pushed the feature/anthropic-settings-ui branch from fb9fd93 to 6d977c3 Compare May 27, 2026 08:42
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