'1.0.0', 'name' => $settings['company_name'], 'description' => $settings['company_desc'], 'url' => home_url(), 'provider' => [ 'organization' => $settings['company_name'], 'url' => home_url(), 'contact' => $settings['company_email'], ], 'capabilities' => [ 'data_formats' => [ 'application/json', 'text/plain', 'text/html' ], 'protocols' => [ 'https' ], 'a2a' => ! empty( $settings['enable_agent_card'] ), 'languages' => $settings['languages'] ?? [ get_locale() ], ], 'tools' => $tools, 'authentication' => [ 'type' => 'none', ], 'metadata' => [ 'generated_by' => 'AI-Ready WP ' . AIREWP_VERSION, 'generated_at' => gmdate( 'c' ), 'language' => get_locale(), ], ]; return apply_filters( 'airewp_agents_json', $agents_json, $settings ); } /** * Build tools array based on site capabilities. */ private static function build_tools( array $settings ): array { $tools = []; // Always available: business info $tools[] = [ 'name' => 'get_business_info', 'description' => sprintf( 'Get information about %s — services, contact details, and company overview.', $settings['company_name'] ), 'endpoint' => home_url( '/wp-json/airewp/v1/info' ), 'method' => 'GET', 'parameters' => [], ]; // Pages/content tool $tools[] = [ 'name' => 'get_pages', 'description' => 'Get a list of all public pages with titles, URLs, and descriptions.', 'endpoint' => home_url( '/wp-json/wp/v2/pages?per_page=100&_fields=id,title,link,excerpt' ), 'method' => 'GET', 'parameters' => [], ]; // Posts/blog tool $post_count = wp_count_posts(); if ( $post_count->publish > 0 ) { $tools[] = [ 'name' => 'get_posts', 'description' => 'Get blog posts and articles. Supports search and category filtering.', 'endpoint' => home_url( '/wp-json/wp/v2/posts' ), 'method' => 'GET', 'parameters' => [ [ 'name' => 'search', 'type' => 'string', 'description' => 'Search term to filter posts.', 'required' => false, ], [ 'name' => 'per_page', 'type' => 'integer', 'description' => 'Number of results (max 100).', 'required' => false, ], ], ]; } // Services tool (if services defined) if ( ! empty( $settings['services'] ) ) { $tools[] = [ 'name' => 'get_services', 'description' => sprintf( 'Get the services offered by %s.', $settings['company_name'] ), 'endpoint' => home_url( '/wp-json/airewp/v1/services' ), 'method' => 'GET', 'parameters' => [], ]; } // Contact form tool if ( self::has_contact_form() ) { $tools[] = [ 'name' => 'submit_contact', 'description' => 'Submit a contact inquiry.', 'endpoint' => home_url( '/wp-json/airewp/v1/contact' ), 'method' => 'POST', 'parameters' => [ [ 'name' => 'name', 'type' => 'string', 'description' => 'Name of the person making the inquiry.', 'required' => true, ], [ 'name' => 'email', 'type' => 'string', 'description' => 'Email address.', 'required' => true, ], [ 'name' => 'message', 'type' => 'string', 'description' => 'The inquiry message.', 'required' => true, ], ], ]; } // WooCommerce tools if ( class_exists( 'WooCommerce' ) ) { $tools[] = [ 'name' => 'get_products', 'description' => 'Browse products in the shop. Supports search and category filtering.', 'endpoint' => home_url( '/wp-json/wc/store/v1/products' ), 'method' => 'GET', 'parameters' => [ [ 'name' => 'search', 'type' => 'string', 'description' => 'Search term.', 'required' => false, ], [ 'name' => 'category', 'type' => 'string', 'description' => 'Category slug to filter by.', 'required' => false, ], ], ]; } return $tools; } /** * Check if a contact form plugin is active. */ private static function has_contact_form(): bool { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } return is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) || is_plugin_active( 'wpforms-lite/wpforms.php' ) || is_plugin_active( 'wpforms/wpforms.php' ) || is_plugin_active( 'forminator/forminator.php' ); } }