$args Field definition from settings fields. */ /** * Static Cloudflare Workers AI model definitions. * * These don't come from an API registry — Cloudflare has only two FLUX * models and pricing is stable. Costs are per-image at 1024×632 (default). * * @var array */ private const CLOUDFLARE_MODELS = [ 'flux-1-schnell' => [ 'name' => 'FLUX.1 [schnell]', 'provider' => 'Cloudflare', 'cost_per_image' => '$0.0007', 'description' => 'Fast + cheap, 4 inference steps', ], 'flux-1-dev' => [ 'name' => 'FLUX.1 [dev]', 'provider' => 'Cloudflare', 'cost_per_image' => '$0.0028', 'description' => 'Higher quality, ~4× cost, 20 steps', ], ]; public static function render( string $id, string $value, array $args ): void { $capability = $args['capability'] ?? 'text→text'; $display_name = $value ?: __( '— Select a model —', 'prautoblogger' ); $display_price = ''; if ( 'cloudflare_image' === $capability ) { // Resolve from static Cloudflare model list. $cf_model = self::CLOUDFLARE_MODELS[ $value ] ?? null; if ( null !== $cf_model ) { $display_name = $cf_model['name']; $display_price = $cf_model['cost_per_image'] . '/image'; } } else { // Resolve from the OpenRouter model registry cache. $registry = prautoblogger()->get_executor()->get_model_registry(); $model = $registry->find_model( $value ); if ( null !== $model ) { $display_name = $model['name'] ?? $value; $in = (float) ( $model['input_price_per_m'] ?? 0 ); $out = (float) ( $model['output_price_per_m'] ?? 0 ); $display_price = self::format_price( $in ) . ' / ' . self::format_price( $out ); } } // Hidden input carries the actual value for the form submission. printf( '', esc_attr( $id ), esc_attr( $id ), esc_attr( $value ) ); // Trigger button — opens the model picker popup via JS. printf( '', esc_attr( $id ), esc_attr( $capability ), esc_html( $display_name ), esc_html( $display_price ) ); } /** * Format a price-per-million-tokens value for display. * * @param float $price Price per 1M tokens. * @return string Formatted price string like "$0.25" or "Free". */ private static function format_price( float $price ): string { if ( $price <= 0 ) { return __( 'Free', 'prautoblogger' ); } if ( $price < 0.01 ) { return '$' . number_format( $price, 4 ); } return '$' . number_format( $price, 2 ); } }