CSAI internel server error with optimize image enabled

The following error appears in the console when the Optimize option is enabled for images in the CSAI settings and the mentioned PHP extensions aren’t enabled.

 Error fetching URL 
    Object { code: "internal_server_error", message: `E_ERROR: Uncaught Error: Class "Spatie\\ImageOptimizer\\OptimizerChainFactory" not found in /var/web/site/public_html/wp-content/plugins/cornerstone-ai/REST/REST.php:190\nStack trace:\n#0 [internal function]: {closure:{closure:/var/web/site/public_html/wp-content/plugins/cornerstone-ai/REST/REST.php:7}:134}(Array)\n#1 /var/web/site/public_html/wp-content/themes/pro/cornerstone/includes/classes/Services/Routes.php(149): call_user_func_array(Object(Closure), Array)\n#2 /var/web/site/public_html/wp-includes/class-wp-hook.php(324): Themeco\\Cornerstone\\Services\\Routes->{closure:Themeco\\Cornerstone\\Services\\Routes::add_route():148}(NULL, Array)\n#3 /var/web/site/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(NULL, Array)\n#4 /var/web/site/public_html/wp-content/themes/pro/cornerstone/includes/classes/Services/Routes.php(101): apply_filters('tco_routing_pos...', NULL, Array)\n#5 /var/web/site/public_html/wp-includes/rest-api/class-wp-rest-server.php(1292): Themeco\\Cornerstone\\Services\\Routes->rest_endpoint(Object(WP_REST_Request))\n#6 /var/web/site/public_html/wp-includes/rest-api/class-wp-rest-server.php(1125): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/themeco/data/(...', Array, NULL)\n#7 /var/web/site/public_html/wp-includes/rest-api/class-wp-rest-server.php(439): WP_REST_Server->dispatch(Object(WP_REST_Request))\n#8 /var/web/site/public_html/wp-includes/rest-api.php(459): WP_REST_Server->serve_request('/themeco/data/a...')\n#9 /var/web/site/public_html/wp-includes/class-wp-hook.php(324): rest_api_loaded(Object(WP))\n#10 /var/web/site/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)\n#11 /var/web/site/public_html/wp-includes/plugin.php(565): WP_Hook->do_action(Array)\n#12 /var/web/site/public_html/wp-includes/class-wp.php(418): do_action_ref_array('parse_request', Array)\n#13 /var/web/site/public_html/wp-includes/class-wp.php(818): WP->parse_request('')\n#14 /var/web/site/public_html/wp-includes/functions.php(1342): WP->main('')\n#15 /var/web/site/public_html/wp-blog-header.php(16): wp()\n#16 /var/web/site/public_html/index.php(17): require('/var/web/site/p...')\n#17 {main}\n  thrown in /var/web/site/public_html/wp-content/plugins/cornerstone-ai/REST/REST.php on line 190. <p>There has been a critical error on this website.</p><p><a href="https://wordpress.org/documentation/article/faq-troubleshooting/">Learn more about troubleshooting WordPress.</a></p>`, data: {…}, additional_errors: [] }
    ai.js:293:9007

I triggered this by going into an older thread in which an image was generated and I tried downloading the image.

There was no user facing error message or any clue that the action failed, so perhaps it’s a good idea to add some message in the UI as well?

I’ll prevent the issue from happening. I think it happens when the image optimization plugins aren’t installed on the server. Thanks for the feedback.

That may indeed be the case since I don’t have those installed.