Files
hado/core/app/Mcp/Tools/UpdateEvent.php

33 lines
1.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Mcp\Tools;
use App\Ingest\ManualEvents;
use App\Models\Event;
use App\Presenters\EventPresenter;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\ResponseFactory;
class UpdateEvent extends AgentTool
{
protected string $name = 'update_event';
protected string $description = 'Поправить своё событие (editable: true) — любое подмножество полей create_event, остальное не меняется. Новый `due_at` — это перенос: состояние пересчитывается от новой даты даже у закрытого события, «Помню» сбрасывается, `fire_at` без явного значения считается заново (за 30 дней до нового срока). События других источников не правятся — их закрывают через mark_done.';
public function __construct(private readonly ManualEvents $manual) {}
public function schema(JsonSchema $schema): array
{
return ['id' => $schema->integer()->required()] + CreateEvent::fields($schema, required: false);
}
public function handle(Request $request): Response|ResponseFactory
{
$fields = $request->validate(CreateEvent::shape(required: false));
return $this->withOwnEvent($request, fn (Event $event) => $this->respond(EventPresenter::forUser($this->manual->update($event, $fields))));
}
}