| 1 |
<?php |
| 2 |
/** |
| 3 |
* Generate llms.txt preview ability. |
| 4 |
* |
| 5 |
* @package ThinkRank\Abilities\Analysis |
| 6 |
*/ |
| 7 |
|
| 8 |
declare(strict_types=1); |
| 9 |
|
| 10 |
namespace ThinkRank\Abilities\Analysis; |
| 11 |
|
| 12 |
use ThinkRank\Abilities\Ability_Base; |
| 13 |
use ThinkRank\SEO\LLMs_Txt_Manager; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Generates a preview of the llms.txt content without publishing it. |
| 21 |
* |
| 22 |
* This is a pure preview: it never writes the file to disk. Pass an empty |
| 23 |
* user_input object to preview using the currently saved settings. |
| 24 |
*/ |
| 25 |
class Generate_Llms_Txt extends Ability_Base { |
| 26 |
/** |
| 27 |
* Constructor. |
| 28 |
*/ |
| 29 |
public function __construct() { |
| 30 |
$this->id = 'thinkrank/generate-llms-txt'; |
| 31 |
$this->label = __( 'Generate ThinkRank llms.txt Preview', 'thinkrank' ); |
| 32 |
$this->description = __( 'Generate a preview of the llms.txt content without publishing it to disk. Pass an empty user_input object to preview using the currently saved settings. Use publish-llms-txt to actually write it.', 'thinkrank' ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* {@inheritDoc} |
| 37 |
* |
| 38 |
* @return array<string, mixed> |
| 39 |
*/ |
| 40 |
public function get_input_schema() { |
| 41 |
return [ |
| 42 |
'type' => 'object', |
| 43 |
'additionalProperties' => false, |
| 44 |
'properties' => [ |
| 45 |
'user_input' => [ |
| 46 |
'type' => 'object', |
| 47 |
'description' => __( 'Optional override values for the preview. When empty, saved settings are used.', 'thinkrank' ), |
| 48 |
], |
| 49 |
], |
| 50 |
]; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* {@inheritDoc} |
| 55 |
* |
| 56 |
* @return array<string, mixed> |
| 57 |
*/ |
| 58 |
public function get_output_schema() { |
| 59 |
return [ |
| 60 |
'type' => 'object', |
| 61 |
'properties' => [ |
| 62 |
'content' => [ 'type' => 'string' ], |
| 63 |
'sections' => [ 'type' => [ 'array', 'object' ] ], |
| 64 |
'metadata' => [ 'type' => 'object' ], |
| 65 |
'validation' => [ 'type' => [ 'array', 'object' ] ], |
| 66 |
], |
| 67 |
]; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Execute ability. |
| 72 |
* |
| 73 |
* @param array<string, mixed> $input Ability input payload. |
| 74 |
* @return array<string, mixed> |
| 75 |
*/ |
| 76 |
public function execute( $input ) { |
| 77 |
$user_input = isset( $input['user_input'] ) && is_array( $input['user_input'] ) ? $input['user_input'] : []; |
| 78 |
|
| 79 |
$manager = new LLMs_Txt_Manager(); |
| 80 |
|
| 81 |
return $manager->generate_llms_txt( $user_input, [] ); |
| 82 |
} |
| 83 |
} |
| 84 |
|