php-agentic/Mcp/Tools/Agent/Template/TemplatePreview.php
Snider ad83825f93 refactor: rename namespace Core\Agentic to Core\Mod\Agentic
Updates all classes to use the new modular namespace convention.
Adds Service/ layer with Core\Service\Agentic for service definition.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 16:12:58 +00:00

69 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Agentic\Mcp\Tools\Agent\Template;
use Core\Mod\Agentic\Services\PlanTemplateService;
use Core\Mod\Agentic\Mcp\Tools\Agent\AgentTool;
/**
* Preview a template with variables.
*/
class TemplatePreview extends AgentTool
{
protected string $category = 'template';
protected array $scopes = ['read'];
public function name(): string
{
return 'template_preview';
}
public function description(): string
{
return 'Preview a template with variables';
}
public function inputSchema(): array
{
return [
'type' => 'object',
'properties' => [
'template' => [
'type' => 'string',
'description' => 'Template name/slug',
],
'variables' => [
'type' => 'object',
'description' => 'Variable values for the template',
],
],
'required' => ['template'],
];
}
public function handle(array $args, array $context = []): array
{
try {
$templateSlug = $this->require($args, 'template');
} catch (\InvalidArgumentException $e) {
return $this->error($e->getMessage());
}
$templateService = app(PlanTemplateService::class);
$variables = $this->optional($args, 'variables', []);
$preview = $templateService->previewTemplate($templateSlug, $variables);
if (! $preview) {
return $this->error("Template not found: {$templateSlug}");
}
return [
'template' => $templateSlug,
'preview' => $preview,
];
}
}