'object' ], [ 'annotations' => [ 'readonly' => true, 'idempotent' => true, 'destructive' => false, ], ], function () { return current_user_can( 'edit_posts' ); }, [ 'type' => 'object', 'properties' => [ 'summary' => [ 'type' => 'boolean', 'default' => false, 'description' => 'When true, returns an array of { type, description } for discovery instead of full schemas.', ], ], ] ); } public function execute( $input = [] ) { $input = is_array( $input ) ? $input : []; $summary = ! empty( $input['summary'] ); $widgets = array_filter( Widget_Context_Helper::get_llm_eligible_widgets(), static function ( $config, $type ) { if ( Widget_Context_Helper::VERSION_V4 === Widget_Context_Helper::get_widget_version( $config ) ) { return true; } return Widget_Context_Helper::is_v3_allowlisted( (string) $type ); }, ARRAY_FILTER_USE_BOTH ); if ( $summary ) { return $this->build_summaries( $widgets ); } return $this->build_schemas( $widgets ); } private function build_summaries( array $widgets ): array { $summaries = []; foreach ( $widgets as $widget_type => $config ) { $full_summary = Widget_Context_Helper::build_widget_summary( $widget_type, $config ); $summaries[] = [ 'type' => $full_summary['type'], 'description' => $full_summary['description'] ?? null, ]; } return [ 'widgets' => $summaries ]; } private function build_schemas( array $widgets ): array { $parents_index = Widget_Context_Helper::build_parents_index( $widgets ); $schemas = []; foreach ( $widgets as $widget_type => $config ) { $schemas[ $widget_type ] = Widget_Context_Helper::build_widget_schema( $widget_type, $config, $parents_index ); } return $schemas; } }