__( 'Block Container Label Generation', 'ai' ), 'description' => __( 'Generate concise labels for content blocks. Requires an AI connector that includes support for text generation models.', 'ai' ), 'category' => Experiment_Category::EDITOR, 'usage' => array( 'trigger' => 'on_demand', 'runs' => __( 'When you click Generate Block Labels in List View or Generate label in the Rename modal', 'ai' ), 'sends' => __( 'The text of each container block and its inner blocks, the post title, and a short outline of the other container blocks and their labels', 'ai' ), 'requests' => __( 'One request per unlabeled container block, or one per click in the Rename modal', 'ai' ), ), ); } /** * {@inheritDoc} * * @since 1.5.0 */ public function register(): void { add_action( 'wp_abilities_api_init', array( $this, 'register_ability' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } /** * Registers the ability. * * @since 1.5.0 */ public function register_ability(): void { wp_register_ability( sprintf( 'ai/%s', $this->get_id() ), array( 'label' => $this->get_label(), 'description' => $this->get_description(), 'ability_class' => Block_Container_Label_Generation_Ability::class, ) ); } /** * Enqueues and localizes the admin script. * * @since 1.5.0 * * @param string $hook_suffix The current admin page hook suffix. */ public function enqueue_assets( string $hook_suffix ): void { // Enqueue assets only on the post editor screen. if ( 'post.php' !== $hook_suffix && 'post-new.php' !== $hook_suffix ) { return; } Asset_Loader::enqueue_script( 'block-container-label-generation', 'experiments/block-container-label-generation', array( 'include_core_abilities' => true, ) ); Asset_Loader::enqueue_style( 'block-container-label-generation', 'experiments/block-container-label-generation', ); Asset_Loader::localize_script( 'block-container-label-generation', 'BlockContainerLabelGenerationData', array( 'enabled' => $this->is_enabled(), 'minContentLength' => get_min_content_length( 'block-container-label-generation', Block_Container_Label_Generation_Ability::DEFAULT_MIN_CONTENT_LENGTH ), ) ); } }