feat: add centralized mode validation for agent providers

Prevents server crashes when invalid modes are passed to agents by
validating mode IDs before attempting to set them on the SDK.

- Export VALID_CLAUDE_MODES and VALID_CODEX_MODES from provider files
- Add validateMode() function in agent-manager.ts
- Apply validation in createAgent(), resumeAgent(), and setAgentMode()
- Throws clear error listing valid modes when validation fails

This fixes the crash when 'read-only' (Codex mode) was passed to
a Claude agent.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2025-12-03 20:03:38 +07:00
co-authored by Claude
parent b7eed8409b
commit 7b649eb77f
3 changed files with 47 additions and 0 deletions
@@ -72,6 +72,10 @@ const DEFAULT_MODES: AgentMode[] = [
},
];
export const VALID_CLAUDE_MODES = new Set(
DEFAULT_MODES.map((mode) => mode.id)
);
type ClaudeAgentConfig = AgentSessionConfig & { provider: "claude" };
export type ClaudeContentChunk = { type: string; [key: string]: any };