Extract business logic from MCP tool handlers into 15 Action classes (Plan 5, Session 5, Phase 3, Task 2) following the Brain pattern. MCP tools become thin wrappers calling Action::run(). Add framework-level REST controllers and routes as sensible defaults for consumers. Co-Authored-By: Virgil <virgil@lethean.io>
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Core PHP Framework
|
|
*
|
|
* Licensed under the European Union Public Licence (EUPL) v1.2.
|
|
* See LICENSE file for details.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Mod\Agentic\Actions\Session;
|
|
|
|
use Core\Actions\Action;
|
|
use Core\Mod\Agentic\Models\AgentSession;
|
|
use Core\Mod\Agentic\Services\AgentSessionService;
|
|
|
|
/**
|
|
* End an agent session with a final status and optional summary.
|
|
*
|
|
* Usage:
|
|
* $session = EndSession::run('ses_abc123', 'completed', 'All phases done');
|
|
*/
|
|
class EndSession
|
|
{
|
|
use Action;
|
|
|
|
public function __construct(
|
|
private AgentSessionService $sessionService,
|
|
) {}
|
|
|
|
/**
|
|
* @throws \InvalidArgumentException
|
|
*/
|
|
public function handle(string $sessionId, string $status, ?string $summary = 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);
|
|
|
|
if (! $session) {
|
|
throw new \InvalidArgumentException("Session not found: {$sessionId}");
|
|
}
|
|
|
|
return $session;
|
|
}
|
|
}
|