| @@ -4,10 +4,10 @@ | ||
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | use Exception; |
| 7 | 7 | use Templately\Core\Importer\Utils\AIContentHelper; |
| 8 | -use Templately\Core\Importer\Utils\AIContentResolver; | |
| 9 | 8 | use Templately\Core\Importer\Utils\Utils; |
| 9 | +use Templately\Core\Importer\Utils\AIUtils; | |
| 10 | 10 | use Templately\Utils\Helper; |
| 11 | 11 | |
| 12 | 12 | class Finalizer extends BaseRunner { |
| 13 | 13 | use AIContentHelper; |
| @@ -273,25 +273,22 @@ | ||
| 273 | 273 | $processed_pages = get_option("templately_ai_processed_pages", []); |
| 274 | 274 | $updated_ids = $processed_pages[$this->process_id] ?? []; |
| 275 | 275 | $ai_paths = $this->generateAiFilePaths($old_template_id); |
| 276 | 276 | if($this->is_ai_content($old_template_id) && !file_exists($ai_paths['ai_file_path'])){ |
| 277 | - // Source-agnostic seam: whichever AI-content source owns this | |
| 278 | - // process (classic per-page callback, chat-id pull, or a future | |
| 279 | - // source) stages the .ai.json; otherwise the shared SSE-wait runs. | |
| 280 | - AIContentResolver::ensure_page_ready([ | |
| 281 | - 'session_id' => $this->session_id, | |
| 282 | - 'process_id' => $this->process_id, | |
| 283 | - 'content_id' => $old_template_id, | |
| 284 | - 'ai_page_ids' => $this->ai_page_ids, | |
| 285 | - 'updated_ids' => $updated_ids, | |
| 286 | - 'sse_callback' => [$this, 'sse_message'], | |
| 287 | - 'progress_id' => 'ai_content_time', | |
| 288 | - 'additional_sse_data' => [ | |
| 289 | - 'name' => method_exists($this, 'get_name') ? $this->get_name() : '', | |
| 277 | + // Use the static timeout-aware wait handler from AIUtils | |
| 278 | + AIUtils::handle_sse_wait_with_timeout( | |
| 279 | + $this->session_id, | |
| 280 | + 'ai_content_time', | |
| 281 | + $updated_ids, | |
| 282 | + $this->ai_page_ids, | |
| 283 | + [$this, 'sse_message'], | |
| 284 | + [ | |
| 285 | + 'name' => method_exists($this, 'get_name') ? $this->get_name() : '', | |
| 290 | 286 | 'post_type' => $post_type, |
| 291 | - 'id' => $old_template_id, | |
| 287 | + 'id' => $old_template_id, | |
| 292 | 288 | ], |
| 293 | - ]); | |
| 289 | + $old_template_id // Pass template ID for local site polling | |
| 290 | + ); | |
| 294 | 291 | } |
| 295 | 292 | // Check if this is AI content before processing |
| 296 | 293 | if ($this->isAiContent($old_template_id)) { |
| 297 | 294 | // Process AI content using AIContentHelper trait |