PluginProbe
AI / trunk
AI vtrunk
1.3.0 1.2.0 1.1.0 1.0.2 1.0.1 1.0.0 0.9.0 trunk 0.1.1 0.2.0 0.2.1 0.3.0 0.3.1 0.4.0 0.4.1 0.5.0 0.6.0 0.7.0 0.8.0
ai / includes / Experiments / AI_Request_Logging / AI_Request_Logging.php

AI_Request_Logging.php in AI trunk, at includes/Experiments/AI_Request_Logging/AI_Request_Logging.php

78 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AI Request Logging experiment implementation.
4 *
5 * @package WordPress\AI
6 */
7
8 declare( strict_types=1 );
9
10 namespace WordPress\AI\Experiments\AI_Request_Logging;
11
12 use WordPress\AI\Abstracts\Abstract_Feature;
13 use WordPress\AI\Experiments\Experiment_Category;
14 use WordPress\AI\Logging\AI_Request_Log_Manager;
15 use WordPress\AI\Logging\AI_Request_Log_Page;
16 use WordPress\AI\Logging\Logging_Integration;
17 use WordPress\AI\Logging\REST\AI_Request_Log_Controller;
18
19 defined( 'ABSPATH' ) || exit;
20
21 /**
22 * Provides AI request logging for observability and debugging.
23 *
24 * @since 1.0.0
25 */
26 class AI_Request_Logging extends Abstract_Feature {
27
28 /**
29 * Shared log manager instance.
30 */
31 private ?AI_Request_Log_Manager $manager = null;
32
33 /**
34 * {@inheritDoc}
35 */
36 public static function get_id(): string {
37 return 'ai-request-logging';
38 }
39
40 /**
41 * {@inheritDoc}
42 */
43 protected function load_metadata(): array {
44 return array(
45 'label' => __( 'AI Request Logging', 'ai' ),
46 'description' => __( 'Logs AI requests for observability and debugging. View detailed logs under Tools.', 'ai' ),
47 'category' => Experiment_Category::ADMIN,
48 'capability' => 'none',
49 );
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 public function register(): void {
56 $manager = $this->get_manager();
57 $manager->init();
58 Logging_Integration::init( $manager );
59
60 $controller = new AI_Request_Log_Controller( $manager );
61 $page = new AI_Request_Log_Page( $manager );
62
63 add_action( 'rest_api_init', array( $controller, 'register_routes' ) );
64 add_action( 'admin_menu', array( $page, 'register_menu' ) );
65 }
66
67 /**
68 * Lazily instantiate the log manager.
69 */
70 private function get_manager(): AI_Request_Log_Manager {
71 if ( null === $this->manager ) {
72 $this->manager = new AI_Request_Log_Manager();
73 }
74
75 return $this->manager;
76 }
77 }
78