refactor(desktop): extract shared runtime/provider/model selection + env-var helpers (Phase 1B.1)#1624
Merged
Merged
Conversation
…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>
This was referenced Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 isfalse(Create/Edit), theisModelCustomparameter is unused.Behavior
Zero behavior change by design, with one disclosed exception: Create/Edit previously allocated fresh
envVarsobjects on no-op deletes; the shared helpers return the same reference, removing spurious re-renders. (Persona already had these guards.)Not adopted:
useRequiredCredentialStatein Persona/Create — the credential derivations are not equivalent (Persona'scomputeLocalModeGatefalls back to the runtime file-config provider; Create/Edit don't), so per the map's conservative default nothing moved there.Verification
src/), file-size check: clean-g "agent|persona": 56/56; full suite runs in CIPart 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).