> */ public static function get_all_versions(): array { $versions = get_option( self::VERSIONS_KEY, array() ); if ( ! is_array( $versions ) ) { return array(); } $sorted = $versions; usort( $sorted, static fn( $a, $b ) => (int) ( $b['version'] ?? 0 ) - (int) ( $a['version'] ?? 0 ) ); return $sorted; } /** * Check if the given hash differs from the current active config. * * Used by the Settings page to warn before saving a scoring-relevant change. * * @param string $proposed_hash Hash to check. * * @return bool True when the config would change. */ public static function would_change( string $proposed_hash ): bool { $versions = get_option( self::VERSIONS_KEY, array() ); $active = (int) get_option( self::ACTIVE_KEY, 0 ); foreach ( $versions as $v ) { if ( isset( $v['version'] ) && (int) $v['version'] === $active ) { return isset( $v['hash'] ) && $v['hash'] !== $proposed_hash; } } return false; } /** * Create a new version record and activate it. * * Side effects: Updates prv_config_versions and prv_active_config_version. * * @return int The new version number. */ private static function create_version_record(): int { $versions = get_option( self::VERSIONS_KEY, array() ); if ( ! is_array( $versions ) ) { $versions = array(); } $new_version = count( $versions ) + 1; $models = PRV_Model_Registry::get_enabled_slugs(); $peptides = array_column( PRV_Config::get_peptides(), 'slug' ); $intents = PRV_Config::get_prompt_intents(); $versions[] = array( 'version' => $new_version, 'hash' => self::compute_hash(), 'timestamp' => time(), 'models' => $models, 'peptides' => $peptides, 'intents' => $intents, ); update_option( self::VERSIONS_KEY, $versions ); update_option( self::ACTIVE_KEY, $new_version ); return $new_version; } }