aiFormGenerationService = $aiFormGenerationService; } /** * @param WP_REST_Request> $data * * @return WP_REST_Response * * @throws InvalidArgumentException * @throws QueryExecutionException * @throws ServiceUnavailableException * @throws ValidationException */ public function handle(WP_REST_Request $data): WP_REST_Response { Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); $prompt = sanitize_textarea_field((string) ($data->get_param('prompt') ?? '')); if ($prompt === '') { throw new InvalidArgumentException( BackendStrings::getAiStrings()['ai_prompt_required'] ); } $form = $this->aiFormGenerationService->generateAndCreateForm($prompt); return new WP_REST_Response($form, 200); } }