Skip to content

refactor(desktop): extract shared runtime/provider/model selection + env-var helpers (Phase 1B.1)#1624

Merged
wesbillman merged 1 commit into
mainfrom
feat/agent-ui-shared-sections
Jul 8, 2026
Merged

refactor(desktop): extract shared runtime/provider/model selection + env-var helpers (Phase 1B.1)#1624
wesbillman merged 1 commit into
mainfrom
feat/agent-ui-shared-sections

Conversation

@wesbillman

Copy link
Copy Markdown
Collaborator

Phase 1B.1 — shared runtime/provider/model selection + env-var helpers

First slice of Phase 1B (UI unification) toward the unified Agent model (#1618 landed the record groundwork, #1623 folds the store). The persona, create-agent, and edit-agent dialogs each carried their own copy of the runtime → LLM provider → model dropdown state machine and the provider-API-key env-var bookkeeping. This PR extracts both into pure, tested modules and wires all three dialogs onto them — shrinking the three overlapping editors before B2 unifies them.

What moved

  • providerEnvVarUpdates.ts (+10 tests): set/remove the managed provider API key, clear it on provider switch, merge Advanced-section env edits preserving the managed key. All helpers return the same reference on no-op.
  • runtimeModelProviderSelection.ts (+12 tests): pure transition functions for the three dropdown handlers. Cross-dialog divergences are parameterized, never merged (per the reviewed extraction map):
    • lockedRuntimeReset: "full" (Persona/Edit clear the managed key + custom-model flag on switch to a provider-locked runtime) vs "provider-only" (Create keeps them).
    • clearModelWhenApiKeyMissing: Persona-only — provider switch clears the model when the new provider's API key isn't filled.
    • clearKnownModelOnCustomEntry: Persona-only — entering "Custom model..." drops a known model. When this flag is false (Create/Edit), the isModelCustom parameter is unused.
  • Dialog-specific side effects stay at the call sites: Edit's inherit-pin/command-sync/advanced-auto-expand block, Create's catalog memory + command sync.

Behavior

Zero behavior change by design, with one disclosed exception: Create/Edit previously allocated fresh envVars objects on no-op deletes; the shared helpers return the same reference, removing spurious re-renders. (Persona already had these guards.)

Not adopted: useRequiredCredentialState in Persona/Create — the credential derivations are not equivalent (Persona's computeLocalModeGate falls back to the runtime file-config provider; Create/Edit don't), so per the map's conservative default nothing moved there.

Verification

  • tsc, biome (full src/), file-size check: clean
  • Frontend unit tests: 2056 passed / 0 failed (22 new)
  • Smoke e2e -g "agent|persona": 56/56; full suite runs in CI
  • Cross-reviewed by Pinky (independent verification run: same results), map-first review — approved

Part of the Phase 1B slice plan: each PR leaves the app fully working with both old and new paths mounted. Next: B2 (unified AgentDialog, create paths).

…env-var helpers (Phase 1B.1)

The persona, create-agent, and edit-agent dialogs each carried their own
copy of the runtime -> LLM provider -> model dropdown state machine and the
provider-API-key env-var bookkeeping. Extract both into pure, tested
modules and wire all three dialogs onto them:

- providerEnvVarUpdates.ts: set/remove the managed provider API key, clear
  it on provider switch, merge Advanced-section env edits preserving the
  managed key. Same-reference no-op guards throughout.
- runtimeModelProviderSelection.ts: pure transition functions for the three
  dropdown handlers. Cross-dialog divergences are parameterized, never
  merged: lockedRuntimeReset (full for Persona/Edit, provider-only for
  Create), clearModelWhenApiKeyMissing (Persona only),
  clearKnownModelOnCustomEntry (Persona only). Dialog-specific side effects
  (Edit's inherit-pin/command-sync, Create's catalog memory) stay at the
  call sites.

Zero behavior change by design, with one disclosed exception: Create/Edit
previously allocated fresh envVars objects on no-op deletes; the shared
helpers return the same reference, removing spurious re-renders.

Verified: tsc, biome (full src/), 2056 frontend unit tests (22 new),
file-size check, smoke e2e -g "agent|persona" (56 passed).

Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co>
Signed-off-by: Wes <wesbillman@users.noreply.github.com>
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