raw('schedules', ['type' => 'array', 'description' => 'Array of schedule objects. Each must have taskId, editFrom (ISO8601), and editTo (ISO8601).'])->required(); } /** * Handle the tool request. */ public function handle(array $arguments): ToolResult { $schedules = ($arguments['schedules'] ?? []); $results = []; $successCount = 0; $failureCount = 0; $validationErrors = []; foreach ($schedules as $index => $schedule) { if (! isset($schedule['taskId']) || ! isset($schedule['editFrom']) || ! isset($schedule['editTo'])) { $validationErrors[] = "Schedule #{$index} is missing required fields (taskId, editFrom, editTo)"; continue; } try { $editFrom = new \DateTime($schedule['editFrom']); $editTo = new \DateTime($schedule['editTo']); } catch (\Exception $e) { $validationErrors[] = "Schedule #{$index} has invalid date format. Use ISO8601 (e.g. 2024-04-30T15:00:00-04:00)"; continue; } $duration = $editTo->getTimestamp() - $editFrom->getTimestamp(); if ($duration < 900) { $validationErrors[] = "Schedule #{$index} is shorter than the minimum 15 minute duration"; } } if (! empty($validationErrors)) { return ToolResult::error("Validation failed:\n- ".implode("\n- ", $validationErrors)); } foreach ($schedules as $schedule) { $taskId = $schedule['taskId']; $params = [ 'editFrom' => $schedule['editFrom'], 'editTo' => $schedule['editTo'], ]; if ($this->ticketsService->patch($taskId, $params)) { $successCount++; $results[] = ['taskId' => $taskId, 'status' => 'success']; } else { $failureCount++; $results[] = ['taskId' => $taskId, 'status' => 'error', 'message' => 'Failed to schedule task']; } } return ToolResult::text( "Bulk task scheduling completed. Success: {$successCount}, Failed: {$failureCount}\n\n". Str::toMarkdown($results) ); } }