'Ready for review']); */ class EndSession { use Action; public function __construct( private AgentSessionService $sessionService, ) {} /** * @throws \InvalidArgumentException */ public function handle( string $sessionId, string $status, ?string $summary = null, ?array $handoffNotes = null, ): AgentSession { if ($sessionId === '') { throw new \InvalidArgumentException('session_id is required'); } $valid = ['completed', 'handed_off', 'paused', 'failed']; if (! in_array($status, $valid, true)) { throw new \InvalidArgumentException( sprintf('status must be one of: %s', implode(', ', $valid)) ); } $session = $this->sessionService->end($sessionId, $status, $summary, $handoffNotes); if (! $session) { throw new \InvalidArgumentException("Session not found: {$sessionId}"); } return $session; } }