-
Notifications
You must be signed in to change notification settings - Fork 5
feat(settings): /settings page skeleton + agent config (#554) #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| """V2 Settings router — agent settings managed via the web UI. | ||
|
|
||
| Reads/writes a flat AgentSettings shape persisted in | ||
| .codeframe/config.yaml via load_environment_config / save_environment_config. | ||
|
|
||
| Routes: | ||
| GET /api/v2/settings - Load agent settings (returns defaults if missing) | ||
| PUT /api/v2/settings - Save agent settings (merges into existing config) | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| from fastapi import APIRouter, Depends, HTTPException, Request | ||
|
|
||
| from codeframe.core.config import ( | ||
| AgentBudgetConfig, | ||
| EnvironmentConfig, | ||
| load_environment_config, | ||
| save_environment_config, | ||
| ) | ||
| from codeframe.core.workspace import Workspace | ||
| from codeframe.lib.rate_limiter import rate_limit_standard | ||
| from codeframe.ui.dependencies import get_v2_workspace | ||
| from codeframe.ui.models import ( | ||
| AGENT_TYPES, | ||
| AgentSettingsResponse, | ||
| AgentTypeModelConfig, | ||
| UpdateAgentSettingsRequest, | ||
| ) | ||
| from codeframe.ui.response_models import ErrorCodes, api_error | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| router = APIRouter(prefix="/api/v2/settings", tags=["settings"]) | ||
|
|
||
|
|
||
| def _config_to_response(config: EnvironmentConfig) -> AgentSettingsResponse: | ||
| """Map an EnvironmentConfig to the flat AgentSettings response shape.""" | ||
| saved_models = config.agent_type_models or {} | ||
| agent_models = [ | ||
| AgentTypeModelConfig( | ||
| agent_type=agent_type, | ||
| default_model=saved_models.get(agent_type, ""), | ||
| ) | ||
| for agent_type in AGENT_TYPES | ||
| ] | ||
| # Guard against legacy YAML where agent_budget may have been removed/nulled. | ||
| budget = config.agent_budget or AgentBudgetConfig() | ||
| return AgentSettingsResponse( | ||
| agent_models=agent_models, | ||
| max_turns=budget.max_iterations, | ||
| max_cost_usd=config.max_cost_usd, | ||
| ) | ||
|
|
||
|
|
||
| @router.get("", response_model=AgentSettingsResponse) | ||
| @rate_limit_standard() | ||
| async def get_settings( | ||
| request: Request, | ||
| workspace: Workspace = Depends(get_v2_workspace), | ||
| ) -> AgentSettingsResponse: | ||
| """Load agent settings for the workspace. | ||
|
|
||
| Returns defaults if no .codeframe/config.yaml exists. | ||
| """ | ||
| try: | ||
| config = load_environment_config(workspace.repo_path) or EnvironmentConfig() | ||
| return _config_to_response(config) | ||
| except Exception as e: | ||
| logger.error(f"Failed to load settings: {e}", exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, | ||
| detail=api_error( | ||
| "Failed to load settings", ErrorCodes.EXECUTION_FAILED, str(e) | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| @router.put("", response_model=AgentSettingsResponse) | ||
| @rate_limit_standard() | ||
| async def update_settings( | ||
| request: Request, | ||
| body: UpdateAgentSettingsRequest, | ||
| workspace: Workspace = Depends(get_v2_workspace), | ||
| ) -> AgentSettingsResponse: | ||
| """Save agent settings. | ||
|
|
||
| Merges into existing EnvironmentConfig so unrelated fields | ||
| (package_manager, test_framework, etc.) are preserved. | ||
| """ | ||
| try: | ||
| config = load_environment_config(workspace.repo_path) or EnvironmentConfig() | ||
| if config.agent_budget is None: | ||
| config.agent_budget = AgentBudgetConfig() | ||
|
|
||
| config.agent_budget.max_iterations = body.max_turns | ||
| config.max_cost_usd = body.max_cost_usd | ||
| # Skip empty model strings — they're equivalent to "key not present" | ||
| # in _config_to_response, so persisting them just adds yaml noise. | ||
| # AgentType Literal in the model already rejects unknown agent_type values. | ||
| config.agent_type_models = { | ||
| entry.agent_type: entry.default_model | ||
| for entry in body.agent_models | ||
| if entry.default_model | ||
| } | ||
|
|
||
| save_environment_config(workspace.repo_path, config) | ||
| return _config_to_response(config) | ||
| except Exception as e: | ||
| logger.error(f"Failed to save settings: {e}", exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, | ||
| detail=api_error( | ||
| "Failed to save settings", ErrorCodes.EXECUTION_FAILED, str(e) | ||
| ), | ||
| ) |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.