initialize(); try { $connection = (string) config('database.default'); $cfg = (array) config('database.connections.' . $connection); $safe = [ 'local_database' => in_array((string) ($cfg['hostname'] ?? ''), ['127.0.0.1', 'localhost', '::1'], true), 'table_prefix_valid' => preg_match('/^[a-zA-Z0-9_]*$/D', (string) ($cfg['prefix'] ?? '')) === 1, 'progress_column_present' => isset(\think\facade\Db::name('prescription_ai_task')->getFields()['progress_json']), 'running_models' => \think\facade\Db::name('prescription_ai_task')->where('status', 'running')->field('model_key,COUNT(*) AS count')->group('model_key')->select()->toArray(), 'active_preparation_count' => \think\facade\Db::name('prescription_ai_batch')->where('lock_until', '>', time())->count(), 'active_batch_count' => \think\facade\Db::name('prescription_ai_batch')->where('validity', 'current')->whereIn('status', ['preparing', 'waiting_sources', 'queued', 'running', 'retry_wait'])->count(), 'active_task_count' => \think\facade\Db::name('prescription_ai_task')->whereIn('status', ['queued', 'running', 'retry_wait'])->count(), ]; echo json_encode($safe, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), PHP_EOL; } catch (\Throwable $e) { echo json_encode(['error' => get_class($e)]), PHP_EOL; exit(1); }