mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 08:03:46 +00:00
fix: prevent panic on empty modes/thoughtLevels in parse_agent_config
Use `.first()` with safe fallback instead of direct `[0]` index access, which would panic if the Vec is empty and no default is set. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4f7f9ce26d
commit
5c7a0ac761
1 changed files with 2 additions and 2 deletions
|
|
@ -221,7 +221,7 @@ fn parse_agent_config(json_str: &str) -> Vec<Value> {
|
|||
"name": "Mode",
|
||||
"category": "mode",
|
||||
"type": "select",
|
||||
"currentValue": config.default_mode.unwrap_or_else(|| modes[0].id.clone()),
|
||||
"currentValue": config.default_mode.or_else(|| modes.first().map(|m| m.id.clone())).unwrap_or_default(),
|
||||
"options": modes.iter().map(|m| json!({
|
||||
"value": m.id,
|
||||
"name": m.name,
|
||||
|
|
@ -235,7 +235,7 @@ fn parse_agent_config(json_str: &str) -> Vec<Value> {
|
|||
"name": "Thought Level",
|
||||
"category": "thought_level",
|
||||
"type": "select",
|
||||
"currentValue": config.default_thought_level.unwrap_or_else(|| thought_levels[0].id.clone()),
|
||||
"currentValue": config.default_thought_level.or_else(|| thought_levels.first().map(|t| t.id.clone())).unwrap_or_default(),
|
||||
"options": thought_levels.iter().map(|t| json!({
|
||||
"value": t.id,
|
||||
"name": t.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue