php-agentic/Boot.php

113 lines
3.9 KiB
PHP
Raw Normal View History

2026-01-27 00:28:29 +00:00
<?php
declare(strict_types=1);
namespace Core\Mod\Agentic;
2026-01-27 00:28:29 +00:00
use Core\Events\AdminPanelBooting;
use Core\Events\ConsoleBooting;
use Core\Events\McpToolsRegistering;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
class Boot extends ServiceProvider
{
protected string $moduleName = 'agentic';
/**
* Events this module listens to for lazy loading.
*
* @var array<class-string, string>
*/
public static array $listens = [
AdminPanelBooting::class => 'onAdminPanel',
ConsoleBooting::class => 'onConsole',
McpToolsRegistering::class => 'onMcpTools',
];
public function boot(): void
{
$this->loadMigrationsFrom(__DIR__.'/Migrations');
$this->loadTranslationsFrom(__DIR__.'/Lang', 'agentic');
$this->configureRateLimiting();
}
/**
* Configure rate limiting for agentic endpoints.
*/
protected function configureRateLimiting(): void
{
// Rate limit for the for-agents.json endpoint
// Allow 60 requests per minute per IP
RateLimiter::for('agentic-api', function (Request $request) {
return Limit::perMinute(60)->by($request->ip());
});
}
public function register(): void
{
$this->mergeConfigFrom(
__DIR__.'/config.php',
'mcp'
);
$this->app->singleton(\Core\Mod\Agentic\Services\AgenticManager::class);
2026-01-27 00:28:29 +00:00
}
// -------------------------------------------------------------------------
// Event-driven handlers (for lazy loading once event system is integrated)
// -------------------------------------------------------------------------
/**
* Handle admin panel booting event.
*/
public function onAdminPanel(AdminPanelBooting $event): void
{
$event->views($this->moduleName, __DIR__.'/View/Blade');
// Register admin routes
if (file_exists(__DIR__.'/Routes/admin.php')) {
$event->routes(fn () => require __DIR__.'/Routes/admin.php');
}
// Register Livewire components
$event->livewire('agentic.admin.dashboard', View\Modal\Admin\Dashboard::class);
$event->livewire('agentic.admin.plans', View\Modal\Admin\Plans::class);
$event->livewire('agentic.admin.plan-detail', View\Modal\Admin\PlanDetail::class);
$event->livewire('agentic.admin.sessions', View\Modal\Admin\Sessions::class);
$event->livewire('agentic.admin.session-detail', View\Modal\Admin\SessionDetail::class);
$event->livewire('agentic.admin.tool-analytics', View\Modal\Admin\ToolAnalytics::class);
$event->livewire('agentic.admin.tool-calls', View\Modal\Admin\ToolCalls::class);
$event->livewire('agentic.admin.api-keys', View\Modal\Admin\ApiKeys::class);
$event->livewire('agentic.admin.templates', View\Modal\Admin\Templates::class);
// Note: Navigation is registered via AdminMenuProvider interface
// in the existing boot() method until we migrate to pure event-driven nav.
}
/**
* Handle console booting event.
*/
public function onConsole(ConsoleBooting $event): void
{
$event->command(Console\Commands\TaskCommand::class);
$event->command(Console\Commands\PlanCommand::class);
$event->command(Console\Commands\GenerateCommand::class);
}
/**
* Handle MCP tools registration event.
*
* Note: Agent tools (plan_create, session_start, etc.) are implemented in
* the Mcp module at Mod\Mcp\Tools\Agent\* and registered via AgentToolRegistry.
* This method is available for Agentic-specific MCP tools if needed in future.
*/
public function onMcpTools(McpToolsRegistering $event): void
{
// Agent tools are registered in Mcp module via AgentToolRegistry
// No additional MCP tools needed from Agentic module at this time
}
}