Skip to content

feat(acp): add model dropdown and credential fields to agent settings page - #14733

Merged
simonrosenberg merged 23 commits into
mainfrom
feat/acp-agent-settings-credentials
Jun 11, 2026
Merged

simonrosenberg merged 23 commits into
mainfrom
feat/acp-agent-settings-credentials

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Port Agent Canvas ACP UX to OpenHands

  • A human has tested these changes. checkbox.

Summary

  • Ports the key UX blocks from agent-canvas's docker-acp branch to OpenHands so that ACP works in Docker and cloud deployments (where credentials can't silently inherit from the user's machine environment)
  • Adds per-provider model dropdown (sourced from the SDK registry, same data canvas gets via typescript-client) with a "Custom" free-text fallback
  • Adds a credentials section below the command textarea for built-in providers (Claude Code: ANTHROPIC_API_KEY + ANTHROPIC_BASE_URL; Codex: OPENAI_API_KEY + OPENAI_BASE_URL) — fields are saved as global secrets and injected by the agent-server at subprocess spawn time

Changes

Backend

  • ACPProviderConfig: new default_model and available_models fields (from SDK registry)
  • ACPModelOption: new model to carry {id, label} per provider
  • Config injector passes model data from ACP_PROVIDERS SDK registry

Frontend

  • agent-settings.tsx: model dropdown (per-provider suggestions + Custom), credential section, combined save flow (credentials first → agent spec, single toast)
  • acp-credentials-section.tsx + acp-secret-field.tsx: credential form UI
  • acp-provider-secrets.ts: per-provider secret field definitions (API key + base URL per provider, matching canvas's ACP_PROVIDER_SECRETS)
  • use-acp-credential-form.ts + use-save-acp-secrets.ts: credential state management and save flow

What this unblocks

Epic: #15746 — Phase 3 (Docker) and Phase 4 (Cloud). With API keys reachable via the Settings → Agent credentials section instead of requiring machine-local shell env, users can configure Claude Code and Codex ACP providers in Docker/cloud deployments.

How to Test

  1. Set ENABLE_ACP=true
  2. Go to Settings → Agent, switch to ACP
  3. Select "Claude Code" preset → verify model dropdown shows Claude Opus/Sonnet/Haiku options
  4. Select "Codex" preset → verify GPT-5.x models appear in dropdown
  5. Select "Gemini CLI" → verify credentials section shows Vertex SA fields (GOOGLE_APPLICATION_CREDENTIALS_JSON, GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION, GOOGLE_GENAI_USE_VERTEXAI) and GEMINI_API_KEY
  6. For Claude Code or Codex: paste an API key → Save → verify it appears in Settings → Secrets

🤖 Generated with Claude Code


To run this PR locally, use the following command:

GUI with Docker:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   --name openhands-app-00fe407   docker.openhands.dev/openhands/openhands:00fe407

simonrosenberg and others added 2 commits June 9, 2026 21:09
… page

Ports the two key blocks from agent-canvas docker-acp to OpenHands so that
ACP works in Docker and cloud deployments where credentials can't silently
inherit from the user's machine:

**Backend:**
- Extends `ACPProviderConfig` with `default_model` and `available_models`
  (sourced from the SDK registry, same data canvas reads via typescript-client)
- Adds `ACPModelOption` model to carry `{id, label}` per provider

**Frontend:**
- Model selector: per-provider dropdown (known models from config) with
  "Custom" fallback for free-text override; syncs model when preset/command
  changes provider
- Credentials section: API key + base URL fields for Claude Code and Codex,
  saved as global secrets that the agent-server injects into the subprocess
  at spawn time; Gemini CLI is intentionally absent (no static key auth)
- `useAcpCredentialForm` + `useSaveAcpSecrets` hooks matching canvas shape
- `AcpCredentialsSection` + `AcpSecretField` components
- Combined save: credentials persist first, then agent spec, single toast

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@simonrosenberg simonrosenberg self-assigned this Jun 9, 2026

all-hands-bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: feat(acp): add model dropdown and credential fields to agent settings page

🟡 Acceptable — Works well overall, a few improvements suggested.


[TESTING GAPS]

  • [frontend/tests/routes/agent-settings.test.tsx] Missing Coverage: The new model dropdown (agent-model-selector) and credential sections (acp-credentials-section.tsx, acp-secret-field.tsx) have no test coverage. The existing tests still use the old single agent-model-input test ID. Add tests for:
    • Model selection via dropdown updates acpModel state correctly
    • Switching between known models and custom model input
    • Credential form fields render for built-in providers (claude-code, codex)
    • Saving credentials persists secrets correctly
    • Credential form resets when provider changes

[IMPROVEMENT OPPORTUNITIES]

  • [frontend/src/routes/agent-settings.tsx, Line 189] State Complexity: The handleSave async function has sequential saves (credentials first, then settings) with complex control flow. Consider extracting a saveCredentialsIfDirty() helper to improve readability and make the flow more explicit.

  • [frontend/src/hooks/use-acp-credential-form.ts, Line 31] useMemo Dependency: providerKey changes trigger getAcpProviderSecrets() recalculation, but the memoization is correct. However, the fields derivation inside the hook could be consolidated with the hook's return shape for clarity.

  • [frontend/src/hooks/use-save-acp-secrets.ts, Line 39] Sequential Await: Using for...of with await inside is correct here (credentials should be sequential), but consider adding a comment explaining why sequential is required (e.g., API rate limits, order dependency).


[STYLE NOTES]

  • [frontend/src/i18n/translation.json, Line 26455] JSON Formatting: The file appears correctly formatted now. I initially flagged a potential issue but after checking the actual file, the structure is valid.

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟢 LOW

The changes are additive frontend UI improvements with no breaking changes to existing APIs. The credential storage uses the existing secrets infrastructure. Model selection is optional and degrades gracefully (text input fallback). The code follows existing patterns in the codebase.


VERDICT:
✅ Worth merging — Core functionality is solid. Tests should be added in a follow-up.

KEY INSIGHT:
The credential form pattern (useAcpCredentialForm + useSaveAcpSecrets) is well-designed — it cleanly separates form state management from persistence logic, making the components easy to reason about.


This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation

Comment thread frontend/src/routes/agent-settings.tsx Resolved
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

all-hands-bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: feat(acp): add model dropdown and credential fields to agent settings page

🟡 Acceptable — Feature is functional and well-structured, with a few areas worth considering.


[IMPROVEMENT OPPORTUNITIES]

  • [frontend/src/routes/agent-settings.tsx, Line ~190] Complexity: The handleSave function has sequential async operations (credentials → agent spec → secrets). Consider extracting a clear async waterfall or parallelizing independent operations. The existing review suggestion about extracting saveCredentialsIfNeeded is valid.

  • [frontend/src/hooks/use-save-acp-secrets.ts, Line ~39] Performance: Sequential for...await loop for saving credentials. If the list grows or network is slow, this adds latency linearly. Consider Promise.all if the API supports concurrent saves, or document why sequential is required (rate limits, ordering).


[TESTING GAPS]

  • No test files were added. For new state management hooks (use-acp-credential-form.ts, use-save-acp-secrets.ts), consider adding unit tests to verify:
    • Form state resets when provider changes
    • Save correctly filters empty values
    • Conflict detection works as expected

[RISK ASSESSMENT]

  • [Overall PR] Risk Assessment: LOW
    The changes add UI and config for a new feature area without modifying existing core behavior. Credentials are handled via the existing secrets infrastructure with proper masking. Backend changes are additive only.

VERDICT:
✅ Worth merging — Core functionality is solid. The complexity in handleSave is the main area to watch; consider addressing the sequential save pattern before this becomes entrenched.

KEY INSIGHT:
The credential flow (secret field → global secret → agent-server inject) is a clean pattern that cleanly separates concerns and should scale well to additional providers.


This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation

@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/app_conversation
  live_status_app_conversation_service.py 1626-1654, 1669-1688, 1711-1712
  openhands/app_server/event_callback
  webhook_router.py 477, 482-483, 494-504
  openhands/app_server/secrets
  secrets_router.py 262-272
  openhands/app_server/web_client
  default_web_client_config_injector.py
  web_client_models.py
Project Total  

This report was generated by python-coverage-comment-action

Also fixes missing trailing newline on translation.json (pre-commit end-of-file-fixer).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

all-hands-bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: feat(acp): add model dropdown and credential fields to agent settings page

🟢 Good taste — Clean, well-structured implementation.


Summary

This PR adds a model dropdown for ACP agents (with custom model fallback) and credential fields (API key, base URL) for built-in providers (Claude Code, Codex). The changes span frontend UI components, form hooks, and backend models.


Analysis

Data Structures ✅

  • ACPModelOption and ACPProviderConfig types are clean and minimal
  • Credential form hooks follow idiomatic React patterns
  • The AcpCredentialForm interface is well-designed with clear separation of concerns

Security ✅

  • Credentials are properly masked (type="password") for secret fields
  • Values are trimmed before saving, preventing accidental whitespace
  • Existing secrets are detected and placeholder text is shown instead of revealing values
  • Secrets are stored via a dedicated createSecret mutation (assumed to use proper secret management)

Complexity ✅

  • The handleSave function has sequential async operations, but the pattern is intentional (credentials must exist before agent spec is applied)
  • The isKnownModel helper is a clean abstraction
  • Form state management is appropriately split across hooks

Minor Observations

  • The credentialForm.reset() call after successful save is appropriate for UX (clears typed values, shows placeholder)
  • The sync logic when typing in the command textarea (detectPreset comparison) is a nice touch
  • i18n coverage across 15+ languages is thorough

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟢 LOW
    The changes are additive UI/UX improvements with proper state management and no breaking changes to existing APIs.

VERDICT:
✅ Worth merging: Solid implementation, no blocking issues.

KEY INSIGHT:
The sequential save pattern (credentials → agent spec) is correct by design — agent config references secrets by name, so they must persist first.


Improve this review? If any feedback above seems incorrect or irrelevant to this repository, you can teach the reviewer to do better:

  1. Add a .agents/skills/custom-codereview-guide.md file to your branch (or edit it if one already exists) with the /codereview trigger and the context the reviewer is missing (e.g., "Security concerns about X do not apply here because Y"). See the customization docs for the required frontmatter format.
  2. Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
  3. When your PR is merged, the guideline file goes through normal code review by repository maintainers.

Resolve with AI? Install the iterate skill in your agent and run /iterate to automatically drive this PR through CI, review, and QA until it's merge-ready.

Was this review helpful? React with 👍 or 👎 to give feedback.

This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation

simonrosenberg and others added 5 commits June 10, 2026 09:45
Add CLAUDE_CODE_OAUTH_TOKEN, CODEX_AUTH_JSON (multiline), and Gemini Vertex
credentials (SA JSON + project/location/Vertexai flag) so subscription users
can configure ACP agents without an API key.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pass autoComplete="new-password" for secret fields and "off" for plain
text fields. Without this Chrome detects type="password" inputs near text
fields and pops its credential-fill UI when the user clicks nearby.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…om secrets to LookupSecret

- Add GET /api/v1/webhooks/custom-secret endpoint: JWT scoped per secret
  (payload {user_id, secret_name}), returns plain-text value.  Mirrors
  the existing /api/v1/webhooks/secrets pattern for git-provider tokens.

- _setup_secrets_for_git_providers: when web_url is set, convert each
  custom secret from StaticSecret to LookupSecret pointing at the new
  endpoint.  Values are never materialised in the app-server process;
  the SDK resolves them lazily inside the conversation pod.

- _build_acp_start_conversation_request: drop AgentContext relay.
  Secrets are now passed directly as secrets= to create_request(),
  which is the preferred path per SDK _start_request_kwargs design
  (agent_context.secrets is only the fallback).  Aligns with how
  agent-canvas builds StartConversationRequest (agent-canvas#1039).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Backend:
- Add SwitchAcpModelRequest model to app_conversation_models.py
- Add POST /api/v1/app-conversations/{id}/switch_acp_model endpoint that
  proxies to the agent server's switch_acp_model endpoint (which issues
  a session/set_model ACP protocol call), mirrors error codes (400/409/504),
  and persists the new model on the conversation record so the chat header
  reflects the switch without a full reload.

Frontend:
- Add V1ConversationService.switchAcpModel() API method
- Add useSwitchAcpModel() mutation hook (invalidates conversation query on
  success so llm_model in the header updates)
- Add SwitchAcpModelButton component: reads available_models from the
  acp_providers config (same source as agent-settings), detects the
  current model from conversation.llm_model, renders a dropdown of
  available models matching canvas's ChatInputModel UX. Returns null for
  non-ACP conversations or providers with no model list.
- Wire SwitchAcpModelButton into ChatInputActions alongside SwitchProfileButton
  (SwitchProfileButton already returns null for ACP conversations, so only
  one of the two is ever visible)
- Add SETTINGS$AVAILABLE_MODELS i18n key (15 locales)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…istry

Expose api_key_env_var and base_url_env_var through ACPProviderConfig so the
frontend doesn't duplicate the SDK registry's knowledge of which env vars each
provider uses.  ACP_PROVIDER_SECRETS_EXTRA now holds only the truly
provider-specific extras (OAuth tokens, file-content blobs, Vertex config).
getAcpProviderSecrets() appends the SDK-sourced key and URL fields dynamically,
which also adds the previously missing GEMINI_API_KEY / GEMINI_BASE_URL fields
to the Gemini CLI credential section.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
simonrosenberg and others added 9 commits June 10, 2026 11:01
…request

create_agent() folds provider creds (e.g. ANTHROPIC_API_KEY) into
acp_agent.agent_context.secrets. _start_request_kwargs auto-lifts those
into request.secrets only when no explicit secrets= is passed. Since we
now pass secrets= to create_request(), the auto-lift was silently skipped
whenever the user had any custom secrets, leaving the ACP subprocess
without its authentication credentials → -32603 Internal error.

Fix: after create_agent(), extract provider_secrets from agent_context and
merge them with user/git secrets (user wins on collision) before the
create_request call.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
secrets=None fails StartConversationRequest Pydantic validation (field
requires dict); secrets={} is valid and semantically identical — the
auto-lift in _start_request_kwargs is skipped either way when secrets is
explicitly in kwargs, but provider_secrets are already merged into the
dict by the prior step so nothing is lost.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ACP provider credentials reach the subprocess exclusively via the
request.secrets → secret_registry pipeline (set up by the credential
form in this PR).  Reading llm.api_key through resolve_provider_env()
and re-merging the result was the wrong semantic: the SDK never does
LLM inference for ACP, so llm.api_key has no meaning here.

The workaround in bcd8abd existed because passing explicit secrets=
to create_request() suppressed _start_request_kwargs's auto-lift of
agent_context.secrets; now that we deliberately don't want that fold,
the workaround is simply removed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…crets

After removing the llm.api_key fold, user panel secrets flow through
request.secrets directly. Update all assertions and rename/rewrite tests
to match the new design: request.secrets is the sole credentials channel;
llm.api_key is explicitly verified not to bleed through.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…starts

switch_acp_model requires an active ACP session (post first run()).  When
execution_status is null the subprocess hasn't initialised yet, so route
the model change through PATCH /api/settings (acp_model) instead.  The
conversation picks up the saved model when it starts.  Live sessions
(execution_status non-null) continue to use the real-time switch path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ACP request now uses StaticSecrets from user_context.get_secrets()
  directly, bypassing LookupSecret wrapping whose X-Access-Token headers
  are redacted by the SDK serializer (TOKEN matches SECRET_KEY_PATTERNS)
- Hide code/plan toggle for ACP conversations (agent_kind==="acp")
- Model switch falls back to settings update on 409 (session not yet
  initialized) instead of requiring a live ACP session

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ow secret upsert

ACP credentials flow through agent_context.secrets (api_key_env_var), not llm.
Stripping api_key and base_url unconditionally mirrors Canvas (ACP_SETTINGS_KEYS
has no llm entry) and prevents proxy settings from leaking into the subprocess env
as OPENAI_BASE_URL etc. — which caused -32603 Internal error with subscription auth.

Also converts POST /secrets from strict-create to upsert so users can refresh
subscription credentials (e.g. CODEX_AUTH_JSON) without a 400 error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
app_conversation_models.py: ruff-format quote normalization.
test_live_status_app_conversation_service.py: _setup_secrets_for_git_providers
wraps StaticSecrets as LookupSecret when web_url is set; update three tests to
use StaticSecret inputs (not plain strings) and assert LookupSecret output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
simonrosenberg and others added 3 commits June 10, 2026 16:58
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Backend:
- Revert _setup_secrets_for_git_providers LookupSecret wrapping of custom
  secrets (non-ACP scope; ACP never calls this function)
- Remove get_custom_secret endpoint (paired with the revert above)
- Add _resolve_user_context helper to webhook_router; add null-guard to
  get_secret for missing access token
- _build_acp_start_conversation_request: add git provider tokens as
  StaticSecrets (ACP cannot use LookupSecrets — X-Access-Token header is
  redacted by the SDK serializer matching SECRET_KEY_PATTERNS)
- Restore _configure_llm to model_copy (pre-existing fix from #14451,
  incorrectly reverted in a prior commit)
- Merge double model_copy calls into one in _build_acp_start_conversation_request

Frontend:
- switch-acp-model-button: invalidate active-conversation query on 409
  fallback so the model chip label updates immediately
- agent-settings: remove isCustomModel boolean state; derive selectedModelKey
  purely from isKnownModel to eliminate dual-state divergence
- use-save-acp-secrets: parallel-save credentials with Promise.all instead
  of sequential awaits
- use-acp-credential-form: memoize getAcpCredentialConflicts result

Tests:
- Update _setup_secrets_for_git_providers assertions: custom secrets are now
  StaticSecret (no LookupSecret wrapping), provider tokens remain LookupSecret
  when web_url is set
- Add get_provider_tokens AsyncMock to _call_build helper in
  TestBuildAcpStartConversationRequestSecrets

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- secrets_router: preserve existing description when upserting a secret
  with no description supplied (prevents ACP credential save from wiping
  user-supplied descriptions)
- webhook_router: inline ternary to satisfy ruff-format
- test file: wrap long assert lines for ruff line-length
- agent-settings.tsx: split ternary for prettier

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the type: feat A new feature label Jun 10, 2026
…citly set

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@simonrosenberg
simonrosenberg merged commit d0230a2 into main Jun 11, 2026
21 checks passed
@simonrosenberg
simonrosenberg deleted the feat/acp-agent-settings-credentials branch June 11, 2026 13:39
@openhands-release-bot openhands-release-bot Bot added the released: cloud-1.39.0 Shipped in cloud-1.39.0 label Jun 24, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in cloud-1.39.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: cloud-1.39.0 Shipped in cloud-1.39.0 type: feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants