fix: simplify settings parsing and reset widget state on session change

- Simplify _parse_settings to handle dict/str/None types only
- Reset ClarificationQuestionsWidget answers and isSubmitted when sessionId changes
This commit is contained in:
Zamil Majdy
2026-01-30 11:49:57 -06:00
parent d37edad901
commit a04c1fa978
2 changed files with 24 additions and 7 deletions

View File

@@ -52,6 +52,18 @@ class RecentExecution(pydantic.BaseModel):
activity_summary: str | None = None
def _parse_settings(settings: dict | str | None) -> GraphSettings:
"""Parse settings from database, handling both dict and string formats."""
if settings is None:
return GraphSettings()
try:
if isinstance(settings, str):
settings = json_loads(settings)
return GraphSettings.model_validate(settings)
except Exception:
return GraphSettings()
class LibraryAgent(pydantic.BaseModel):
"""
Represents an agent in the library, including metadata for display and
@@ -245,11 +257,7 @@ class LibraryAgent(pydantic.BaseModel):
is_latest_version=is_latest_version,
is_favorite=agent.isFavorite,
recommended_schedule_cron=agent.AgentGraph.recommendedScheduleCron,
settings=GraphSettings.model_validate(
json_loads(agent.settings)
if isinstance(agent.settings, str)
else agent.settings
),
settings=_parse_settings(agent.settings),
marketplace_listing=marketplace_listing_data,
)

View File

@@ -41,16 +41,25 @@ export function ClarificationQuestionsWidget({
useEffect(() => {
const storageKey = getStorageKey(sessionId);
if (!storageKey) return;
if (!storageKey) {
setAnswers({});
setIsSubmitted(false);
return;
}
try {
const saved = localStorage.getItem(storageKey);
if (saved) {
const parsed = JSON.parse(saved) as Record<string, string>;
setAnswers(parsed);
setIsSubmitted(false);
} else {
setAnswers({});
setIsSubmitted(false);
}
} catch {
// Ignore parse errors
setAnswers({});
setIsSubmitted(false);
}
}, [sessionId]);