type ) { case 'kb.crawl_all': $only = (string) ( $task->payload['source'] ?? '' ); $this->index_manager->start_full_crawl( '' !== $only ? $only : null ); return AgentResult::ok( array( 'started' => true, 'source' => '' !== $only ? $only : null, ) ); case 'kb.index_item': $source = (string) ( $task->payload['source'] ?? '' ); $external_id = (string) ( $task->payload['external_id'] ?? '' ); if ( '' === $source || '' === $external_id ) { return AgentResult::failed( 'missing source/external_id' ); } $outcome = $this->index_manager->index_item( $source, $external_id ); return ! empty( $outcome['ok'] ) ? AgentResult::ok( $outcome ) : AgentResult::failed( (string) ( $outcome['reason'] ?? 'index_failed' ), $outcome ); default: return AgentResult::refused( 'unsupported task type' ); } } /** * {@inheritDoc} */ public function self_check( AgentContext $context ): HealthReport { global $wpdb; $report = new HealthReport(); foreach ( array( 'agyl_kb_documents', 'agyl_kb_chunks', 'agyl_kb_terms', 'agyl_kb_links' ) as $table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $found = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . $table ) ); $report->add( $table . '_exists', ! empty( $found ), '', true ); } $adapters = $this->adapters->all(); $report->add( 'adapters_available', array() !== $adapters, $adapters ? implode( ', ', array_keys( $adapters ) ) : 'no source adapters registered' ); return $report; } }