$v) { $lines[] = '- ' . $k . ': ' . (is_bool($v) ? ($v ? 'yes' : 'no') : (string) $v); } }; $lines[] = '# AIPCF diagnostics'; $lines[] = 'Made ' . gmdate('Y-m-d H:i') . ' UTC. Secrets, addresses and content are left out.'; $ai = ai_plugin_status(); $add('Versions', [ 'AIPCF' => \AIPCF_VERSION, 'WordPress' => get_bloginfo('version'), 'PHP' => PHP_VERSION, 'AI plugin' => $ai['status'] . (self::aiPluginVersion() !== '' ? ' ' . self::aiPluginVersion() : ''), 'Multisite' => is_multisite(), ]); $add('Environment', [ 'Object cache' => wp_using_ext_object_cache() ? 'external' : 'database', 'WP-Cron disabled' => defined('DISABLE_WP_CRON') && \DISABLE_WP_CRON, 'WP_DEBUG' => defined('WP_DEBUG') && \WP_DEBUG, 'Memory limit' => (string) ini_get('memory_limit'), 'Max execution' => (string) ini_get('max_execution_time') . ' s', 'pdo_pgsql' => extension_loaded('pdo_pgsql'), ]); $add('Connection', [ 'Account ID set' => get_account_id() !== '', 'API token set' => get_api_key() !== '', 'Token kept in' => (string) ($s['api_key'] ?? '') !== '' ? 'AIPCF' : (core_connector_is_available() ? 'Connectors' : 'wp-config or environment'), 'Connector approval' => class_exists('\\WordPress\\AI\\Connector_Approval\\Approvals_Store') ? (is_connector_approved() ? 'allowed' : 'NOT allowed') : 'not used', 'AI Gateway' => Gateway::id() !== '' ? 'on (' . Gateway::mode() . ')' : 'off', 'Gateway bypassed now' => (bool) get_transient(Gateway::DOWN_TRANSIENT), ]); $add('Models', [ 'Writing' => get_default_model_id(), 'Short tasks' => (string) ($s['light_model'] ?? '') !== '' ? (string) $s['light_model'] : 'off', 'Reading images' => vision_model_id(), 'Making images' => (string) ($s['image_model'] ?? ''), ]); $today = UsageTracker::todayTotals(); $usage = [ 'Daily budget' => !empty($s['budget_enabled']) ? number_format((float) ($s['budget_neurons'] ?? 0)) . ' (' . (string) ($s['budget_action'] ?? '') . ')' : 'off', 'Whole account' => self::account(), 'Used today' => number_format((float) ($today['neurons'] ?? 0), 1) . ' neurons, ' . (int) ($today['requests'] ?? 0) . ' requests', ]; foreach ((array) ($today['tasks'] ?? []) as $task => $n) { $usage[' ' . $task] = number_format((float) $n, 1); } $add('Today', $usage); $f = static fn(string $k): string => !empty(FeatureSettings::get($k)) ? 'on' : 'off'; $add('Features', [ 'Site assistant' => $f('chat_enabled') . ' (' . (string) FeatureSettings::get('chat_capability') . ', limit ' . (int) FeatureSettings::get('chat_daily_neurons') . ')', 'Related posts' => $f('related_enabled') . ($f('related_auto') === 'on' ? ', added automatically' : ''), 'Search' => $f('search_enabled') . ($f('search_takeover') === 'on' ? ', best matches above the site search' : ''), 'Link assistant' => $f('links_enabled'), 'Search insights' => $f('insights_enabled'), 'AI agents' => $f('agents_enabled') . ' (' . (string) FeatureSettings::get('agents_capability') . ', limit ' . (int) FeatureSettings::get('agents_daily_neurons') . ')', 'Backfill' => Backfill::enabled() ? 'on (' . implode(', ', (array) ($s['backfill_tasks'] ?? [])) . ')' : 'off', ]); if (EmbeddingSettings::enabled() || IndexTable::exists()) { $c = IndexTable::counts(EmbeddingSettings::signature()); $state = State::get(); $add('Content index', [ 'On' => EmbeddingSettings::enabled(), 'Kept in' => StoreFactory::currentId(), 'Model' => Models::current(), 'Indexed' => $c['indexed'] . ' (' . $c['chunks'] . ' parts)', 'Waiting' => $c['pending'] + $c['stale'], 'Failed' => $c['failed'], 'Paused' => (string) ($state['paused'] ?? '') !== '' ? (string) $state['paused'] : 'no', 'Moving' => !empty($state['move']) ? 'yes' : 'no', 'Last run' => !empty($state['last_run']) ? human_time_diff((int) $state['last_run']) . ' ago' : 'never', 'Last error' => (string) ($state['last_error'] ?? '') !== '' ? (string) $state['last_error'] : 'none', ]); } $b = Backfill::state(); if (Backfill::enabled() || !empty($b['last_run'])) { $left = Backfill::remaining(); $add('Backfill', [ 'Left' => $left['meta_description'] . ' meta descriptions, ' . $left['alt_text'] . ' alt texts', 'SEO plugin' => Backfill::metaDescriptionKey() !== '' ? 'yes' : 'none found', 'Last run' => !empty($b['last_run']) ? human_time_diff((int) $b['last_run']) . ' ago' : 'never', 'Last error' => (string) ($b['last_error'] ?? '') !== '' ? (string) $b['last_error'] : 'none', ]); } $checks = Checks::last(); if ($checks !== null) { $rows = []; foreach ($checks['results'] as $r) { $rows[$r['label']] = strtoupper($r['state']) . ($r['detail'] !== '' ? ' - ' . $r['detail'] : ''); } $add('Checks (' . human_time_diff((int) $checks['at']) . ' ago)', $rows); } $lines[] = ''; $lines[] = '## Recent errors'; $errors = array_slice(ErrorLog::all(), 0, 20); if ($errors === []) { $lines[] = '- none'; } foreach ($errors as $e) { $lines[] = sprintf( '- %s UTC | %s | %s %s | HTTP %s %s | %s | ray %s | %d ms', gmdate('Y-m-d H:i', (int) $e['time']), $e['feature'] !== '' ? $e['feature'] : '-', $e['service'], $e['path'] . ($e['model'] !== '' ? ' (' . $e['model'] . ')' : ''), $e['status'] > 0 ? (string) $e['status'] : '-', $e['code'], $e['message'], $e['ray'] !== '' ? $e['ray'] : '-', (int) $e['ms'] ); } $lines[] = ''; $lines[] = '## Failed activity'; $failed = ActivityLog::entries(['failed' => 1], 10); if ($failed === []) { $lines[] = '- none'; } foreach ($failed as $a) { // Not the message: it can name posts. $lines[] = sprintf('- %s UTC | %s %s | %s | %d failed', (string) ($a['ts'] ?? ''), (string) ($a['tool'] ?? ''), (string) ($a['action'] ?? ''), (string) ($a['status'] ?? ''), (int) ($a['items_failed'] ?? 0)); } return Redact::text(implode("\n", $lines)) . "\n"; } private static function aiPluginVersion(): string { $file = WP_PLUGIN_DIR . '/ai/ai.php'; if (!file_exists($file)) { return ''; } $data = get_file_data($file, ['Version' => 'Version']); return (string) ($data['Version'] ?? ''); } /** * The whole account's use today, as last read from Cloudflare's analytics. */ private static function account(): string { $s = \WordPress\CloudflareWorkersAiProvider\Usage\AccountUsage::state(); if (!\WordPress\CloudflareWorkersAiProvider\Usage\AccountUsage::enabled()) { return 'not counted'; } if ($s['at'] === 0) { return 'not read yet'; } $when = gmdate('H:i', $s['at']) . ' UTC'; return $s['error'] !== '' ? 'error at ' . $when . ': ' . Redact::text($s['error']) : number_format($s['neurons'], 1) . ' neurons (' . $s['day'] . ', read ' . $when . ')'; } }