feat: add model state persistence and improve model selection sync#209
Merged
chriswritescode-dev merged 5 commits intomainfrom Apr 30, 2026
Merged
feat: add model state persistence and improve model selection sync#209chriswritescode-dev merged 5 commits intomainfrom
chriswritescode-dev merged 5 commits intomainfrom
Conversation
- Create opencode_model_state table for storing user model preferences - Implement database-backed model state management (recent, favorite, variant) - Add atomic JSON file utilities with file locking for concurrent safety - Migrate providers routes from file-based to database storage - Add backfill migration to preserve existing model.json data - Include comprehensive tests for model-state and atomic-json modules - Refactor useSessionAgent hook to simplify agent/model resolution logic - Update getFileApiUrl to use consistent query parameter approach
- Add setActiveModel to modelStore and useModelSelection for direct model updates - Sync session agent model/variant to store when messages load - Include model, agent, and variant in optimistic user messages - Fix useSessionAgent to check isFetching during message loading - Update env.ts to use getter for BASE_PATH for dynamic resolution - Fix test environment variable from OPENCODE_WORKSPACE_PATH to WORKSPACE_PATH
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.
Summary
Changes
frontend/src/stores/modelStore.ts- Add setActiveModel methodfrontend/src/hooks/useModelSelection.ts- Add setActiveModel with provider validationfrontend/src/hooks/useSessionAgent.ts- Add isFetching check, prevent stale model restorationfrontend/src/hooks/useOpenCode.ts- Include model/agent/variant in optimistic messagesfrontend/src/components/message/PromptInput.tsx- Sync session agent model to storebackend/src/db/model-state.ts- Ensure table exists on accessbackend/src/routes/providers.ts- Migrate to database storageshared/src/config/env.ts- Change BASE_PATH to getter functionType of Change
Checklist
pnpm lintpasses locallypnpm typecheckpasses locally