feat: MCP tools for events (list/get/create/update/delete/done/ack); EventRules shared by /api and manual

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
nikita.hohlov
2026-09-05 06:10:41 -03:00
parent 450c165fce
commit ed45a1d516
18 changed files with 711 additions and 56 deletions

View File

@@ -2,10 +2,9 @@
namespace App\Http\Requests;
use App\Ingest\DueAtParser;
use App\Ingest\EventRules;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;
use InvalidArgumentException;
class UpsertEventsRequest extends FormRequest
{
@@ -21,42 +20,25 @@ class UpsertEventsRequest extends FormRequest
'events.*.user' => ['required', 'string', 'max:255'],
'events.*.source_ref' => ['required', 'string', 'max:255'],
'events.*.topic' => ['sometimes', 'nullable', 'string', 'max:255'],
'events.*.due_at' => ['required', 'string'],
'events.*.fire_at' => ['required', 'date_format:Y-m-d'],
'events.*.after_due' => ['required', 'in:keep,expire'],
'events.*.payload' => ['required', 'array'],
'events.*.payload.title' => ['required', 'string'],
'events.*.payload.subtitle' => ['sometimes', 'nullable', 'string'],
'events.*.payload.deep_link' => ['sometimes', 'nullable', 'string', 'max:2048', 'regex:#^(/(?![/\\\\])|https?://)#i'],
'events.*.payload.done_label' => ['sometimes', 'nullable', 'string', 'max:64'],
];
] + EventRules::itemPrefixed('events.*.');
}
public function messages(): array
{
return [
'events.*.payload.deep_link.regex' => 'deep_link должен быть относительным путём или http(s)-ссылкой',
];
return EventRules::messages('events.*.');
}
public function after(): array
{
return [function (Validator $v) {
foreach ((array) $this->input('events', []) as $i => $item) {
if (! is_array($item) || ! isset($item['due_at'], $item['fire_at']) || ! is_string($item['due_at'])) {
if (! is_array($item)) {
continue;
}
try {
$due = DueAtParser::parse($item['due_at']);
} catch (InvalidArgumentException $e) {
$v->errors()->add("events.$i.due_at", $e->getMessage());
continue;
}
// Проверка fire_at <= день срока — по поясу по умолчанию; для fixed это
// приближение, точный день пользователя известен только при upsert.
if ($v->errors()->missing("events.$i.fire_at") && $item['fire_at'] > $due->dayFor(config('hado.default_tz'))) {
$v->errors()->add("events.$i.fire_at", 'fire_at не может быть позже дня срока');
foreach (EventRules::check($item) as $field => $error) {
if ($v->errors()->missing("events.$i.$field")) {
$v->errors()->add("events.$i.$field", $error);
}
}
}
}];