| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Mcp\Abilities\Utils; |
| 4 |
|
| 5 |
use Elementor\Core\Base\Document; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
class Document_Mutation_Links { |
| 12 |
|
| 13 |
public static function preview_schema_property(): array { |
| 14 |
return Document_Preview_Url::output_schema_property(); |
| 15 |
} |
| 16 |
|
| 17 |
public static function llm_instructions_schema_property(): array { |
| 18 |
return [ |
| 19 |
'type' => 'string', |
| 20 |
'description' => 'Mandatory next step: include this text (with the preview link) in your reply to the user.', |
| 21 |
]; |
| 22 |
} |
| 23 |
|
| 24 |
public static function for_document( Document $document, ?string $success_message = null ): array { |
| 25 |
$preview_url = Document_Preview_Url::for_document( $document ); |
| 26 |
|
| 27 |
return [ |
| 28 |
'preview_url' => $preview_url, |
| 29 |
'llm_instructions' => self::build_llm_instructions( $preview_url, $success_message ), |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
private static function build_llm_instructions( string $preview_url, ?string $success_message = null ): string { |
| 34 |
$prefix = $success_message ?? __( 'Change saved.', 'elementor' ); |
| 35 |
|
| 36 |
return sprintf( |
| 37 |
/* translators: 1: Success message, 2: Preview URL the LLM must share with the user. */ |
| 38 |
__( '%1$s You MUST show the user this preview link in your reply (they must be logged into WordPress as an editor): %2$s', 'elementor' ), |
| 39 |
$prefix, |
| 40 |
$preview_url |
| 41 |
); |
| 42 |
} |
| 43 |
} |
| 44 |
|