appName = $appName; $this->request = $request; $this->config = $config; } /** * Load configuration */ public function load(): JSONResponse { $clientId = $this->config->getAppValue('analyticshub', 'google_client_id', ''); $apiKey = $this->config->getAppValue('analyticshub', 'anthropic_api_key', ''); $llmEndpoint = $this->config->getAppValue('analyticshub', 'llm_api_endpoint', ''); $llmModel = $this->config->getAppValue('analyticshub', 'llm_model', ''); $refreshToken = $this->config->getAppValue('analyticshub', 'google_refresh_token', ''); // Check if configured $isConfigured = !empty($clientId) && !empty($apiKey) && !empty($refreshToken); // Mask sensitive values for display $maskedApiKey = ''; if (!empty($apiKey)) { $maskedApiKey = substr($apiKey, 0, 8) . '...' . substr($apiKey, -4); } $maskedRefreshToken = ''; if (!empty($refreshToken)) { $maskedRefreshToken = substr($refreshToken, 0, 10) . '...'; } return new JSONResponse([ 'success' => true, 'data' => [ 'google_client_id' => $clientId, 'google_refresh_token' => $maskedRefreshToken, 'llm_api_endpoint' => $llmEndpoint, 'llm_model' => $llmModel, 'anthropic_api_key' => $maskedApiKey, 'is_configured' => $isConfigured, ], ]); } /** * Save configuration */ public function save(): JSONResponse { $data = json_decode($this->request->getRawBody(), true); if (!$data) { return new JSONResponse([ 'success' => false, 'error' => 'Invalid request body', ], 400); } $clientId = $data['google_client_id'] ?? ''; $clientSecret = $data['google_client_secret'] ?? ''; $refreshToken = $data['google_refresh_token'] ?? ''; $apiKey = $data['anthropic_api_key'] ?? ''; $llmEndpoint = $data['llm_api_endpoint'] ?? ''; $llmModel = $data['llm_model'] ?? ''; if (empty($clientId) || empty($clientSecret) || empty($apiKey)) { return new JSONResponse([ 'success' => false, 'error' => 'Missing required fields', ], 400); } // Save configuration $this->config->setAppValue('analyticshub', 'google_client_id', $clientId); $this->config->setAppValue('analyticshub', 'google_client_secret', $clientSecret); if (!empty($refreshToken)) { $this->config->setAppValue('analyticshub', 'google_refresh_token', $refreshToken); } if (!empty($llmEndpoint)) { $this->config->setAppValue('analyticshub', 'llm_api_endpoint', $llmEndpoint); } if (!empty($llmModel)) { $this->config->setAppValue('analyticshub', 'llm_model', $llmModel); } $this->config->setAppValue('analyticshub', 'anthropic_api_key', $apiKey); // Check if fully configured $isConfigured = !empty($clientId) && !empty($clientSecret) && !empty($apiKey) && !empty($refreshToken); return new JSONResponse([ 'success' => true, 'data' => [ 'is_configured' => $isConfigured, ], ]); } }