/
home
/
altere25
/
.trash
/
wp-to-sanity-companion.1
/
/home/altere25/.trash/wp-to-sanity-companion.1
mkdir
upload
Name
Size
Mode
Actions
assets/
-
0755
rm
includes/
-
0755
rm
templates/
-
0755
rm
assets\css\admin.css
7611
0644
edit
dl
rm
assets\js\admin.js
8534
0644
edit
dl
rm
assets\js\claude-connect.js
6502
0644
edit
dl
rm
includes\class-ad-admin.php
26374
0644
edit
dl
rm
includes\class-ad-ai-client.php
8153
0644
edit
dl
rm
includes\class-ad-auth.php
9189
0644
edit
dl
rm
includes\class-ad-cli.php
8669
0644
edit
dl
rm
includes\class-ad-extractor.php
12210
0644
edit
dl
rm
includes\class-ad-mcp.php
6429
0644
edit
dl
rm
includes\class-ad-plugin-core.php
7947
0644
edit
dl
rm
includes\class-ad-progress.php
8022
0644
edit
dl
rm
includes\class-ad-rest.php
31008
0644
edit
dl
rm
includes\class-ad-uninstall.php
1924
0644
edit
dl
rm
includes\class-ad-webhook.php
14854
0644
edit
dl
rm
templates\admin\claude-connect.php
5152
0644
edit
dl
rm
templates\admin\dashboard.php
10457
0644
edit
dl
rm
templates\admin\export.php
16570
0644
edit
dl
rm
templates\admin\log.php
10849
0644
edit
dl
rm
templates\admin\onboarding-v2.php
3827
0644
edit
dl
rm
templates\admin\onboarding.php
10714
0644
edit
dl
rm
templates\admin\progress.php
2443
0644
edit
dl
rm
templates\admin\schema-preview.php
5213
0644
edit
dl
rm
uninstall.php
365
0644
edit
dl
rm
wp-to-sanity-companion.php
4467
0644
edit
dl
rm
Edit:
/home/altere25/.trash/wp-to-sanity-companion.1/includes\class-ad-ai-client.php
(8153B)
<?php /** * Altered Digital Migration — AI Service HTTP Client * * Thin wp_remote_* wrapper around the Altered Digital AI service * (apps/ai-service). The plugin authenticates with the Altered Digital * account JWT (AD_Auth) on user-facing routes, and with an internal token * on Worker-invoked routes. * * Phase B: stubbed — methods return empty/`not_configured` payloads. The * Phase C work wires these to the live AI service endpoints. * * @package AlteredDigitalMigration */ if (!defined('ABSPATH')) { exit; } class AD_AI_Client { /** @var AD_Plugin_Core */ private $core; public function __construct(AD_Plugin_Core $core) { $this->core = $core; } /** * Base AI service URL (set in AD settings once customer connects). */ private function service_url(): string { return $this->core->setting('ai_service_url', ''); } /** * Internal token used for Worker→AI-service calls (distinct from the * user's AD account JWT). */ private function internal_token(): string { return $this->core->setting('ai_service_internal_token', ''); } /** * Trigger a full-site analysis. POSTs the plugin's aggregated analysis * payload (builder distribution, post counts, ACF inventory, media count) * to the AI service, which classifies complexity + estimates effort. * * @param string $wp_site_url * @param string $account_jwt Altered Digital account JWT (AD_Auth). * @param array $plugin_analysis_payload From AD_Extractor::build_analysis_payload(). * @return array{success:bool,data:array<string,mixed>} */ public function analyze(string $wp_site_url, string $account_jwt, array $plugin_analysis_payload = []): array { $url = $this->service_url(); if (empty($url)) { return [ 'success' => false, 'data' => ['error' => 'not_configured', 'message' => 'AI service URL not set.'], ]; } $endpoint = rtrim($url, '/') . '/analyze'; $response = wp_remote_post($endpoint, [ 'timeout' => 60, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $account_jwt, ], 'body' => wp_json_encode([ 'wp_site_url' => $wp_site_url, 'plugin_analysis_payload' => $plugin_analysis_payload, ]), ]); return $this->parse_response($response); } /** * Fetch analysis status by id. * * @param string $analysis_id * @param string $account_jwt * @return array{success:bool,data:array<string,mixed>} */ public function analysis_status(string $analysis_id, string $account_jwt): array { $url = $this->service_url(); if (empty($url)) { return ['success' => false, 'data' => ['error' => 'not_configured']]; } $endpoint = rtrim($url, '/') . '/analyze/' . rawurlencode($analysis_id) . '/status'; $response = wp_remote_get($endpoint, [ 'timeout' => 15, 'headers' => ['Authorization' => 'Bearer ' . $account_jwt], ]); return $this->parse_response($response); } /** * Request a quote for an analysis. * * @param string $analysis_id * @param array<int,string> $add_ons * @param string $account_jwt * @return array{success:bool,data:array<string,mixed>} */ public function quote(string $analysis_id, array $add_ons, string $account_jwt): array { $url = $this->service_url(); if (empty($url)) { return ['success' => false, 'data' => ['error' => 'not_configured']]; } $endpoint = rtrim($url, '/') . '/quote'; $response = wp_remote_post($endpoint, [ 'timeout' => 30, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $account_jwt, ], 'body' => wp_json_encode([ 'analysis_id' => $analysis_id, 'add_ons' => $add_ons, ]), ]); return $this->parse_response($response); } /** * Begin Stripe Checkout for a quote (50% upfront). * * @param string $quote_id * @param string $account_jwt * @return array{success:bool,data:array<string,mixed>} */ public function start_checkout(string $quote_id, string $account_jwt): array { $url = $this->service_url(); if (empty($url)) { return ['success' => false, 'data' => ['error' => 'not_configured']]; } $endpoint = rtrim($url, '/') . '/stripe/checkout'; $response = wp_remote_post($endpoint, [ 'timeout' => 30, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $account_jwt, ], 'body' => wp_json_encode(['quote_id' => $quote_id]), ]); return $this->parse_response($response); } /** * Approve a migration (runs QA + captures final 50%). * * @param string $quote_id * @param string $account_jwt * @return array{success:bool,data:array<string,mixed>} */ public function approve(string $quote_id, string $account_jwt): array { $url = $this->service_url(); if (empty($url)) { return ['success' => false, 'data' => ['error' => 'not_configured']]; } $endpoint = rtrim($url, '/') . '/approve'; $response = wp_remote_post($endpoint, [ 'timeout' => 45, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $account_jwt, ], 'body' => wp_json_encode(['quote_id' => $quote_id]), ]); return $this->parse_response($response); } /** * Generate a Sanity Studio schema from the site analysis. * * @param array $analysis_payload From AD_Extractor::build_analysis_payload(). * @param string $account_jwt * @return array{success:bool,data:array<string,mixed>} */ public function schema_generate(array $analysis_payload, string $account_jwt): array { $url = $this->service_url(); if (empty($url)) { return ['success' => false, 'data' => ['error' => 'not_configured']]; } $endpoint = rtrim($url, '/') . '/schema-generate'; $response = wp_remote_post($endpoint, [ 'timeout' => 90, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $account_jwt, ], 'body' => wp_json_encode(['analysis_json' => $analysis_payload]), ]); return $this->parse_response($response); } // ----------------------------------------------------------------- // Internal helpers // ----------------------------------------------------------------- /** * Normalize a wp_remote_* response into the {success,data} envelope. */ private function parse_response($response): array { if (is_wp_error($response)) { return [ 'success' => false, 'data' => ['error' => $response->get_error_message()], ]; } $code = wp_remote_retrieve_response_code($response); $body = wp_remote_retrieve_body($response); $decoded = json_decode($body, true); if ($code < 200 || $code >= 300 || !is_array($decoded)) { return [ 'success' => false, 'data' => [ 'error' => is_array($decoded) && !empty($decoded['error']) ? $decoded['error'] : 'http_' . intval($code), 'status' => intval($code), 'body' => $body, ], ]; } return [ 'success' => true, 'data' => $decoded, ]; } }
Save
cmd:
run