36772-vm/ai/config.php
2025-12-08 22:34:54 +00:00

87 lines
2.8 KiB
PHP

<?php
// ai/config.php - OpenAI proxy configuration (workspace scope)
// Reads values from environment variables or executor/.env
// For Appwizzy platform compatibility
/**
* Load environment variables from .env file if not already set
* This ensures compatibility with both CLI and web environments
*/
function loadEnvIfNeeded() {
// Check if required environment variables are missing
$projectUuid = getenv('PROJECT_UUID');
$projectId = getenv('PROJECT_ID');
if (
($projectUuid === false || $projectUuid === null || $projectUuid === '') ||
($projectId === false || $projectId === null || $projectId === '')
) {
$envPath = realpath(__DIR__ . '/../../.env'); // executor/.env
if ($envPath && is_readable($envPath)) {
$lines = @file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
foreach ($lines as $line) {
$line = trim($line);
if ($line === '' || $line[0] === '#') {
continue;
}
if (!str_contains($line, '=')) {
continue;
}
[$key, $value] = array_map('trim', explode('=', $line, 2));
if ($key === '') {
continue;
}
$value = trim($value, "\"' ");
if (getenv($key) === false || getenv($key) === '') {
putenv("{$key}={$value}");
}
}
}
}
}
// Load environment variables if needed
loadEnvIfNeeded();
// Get configuration values
$projectUuid = getenv('PROJECT_UUID');
$projectId = getenv('PROJECT_ID');
// Set defaults if not found
$projectUuid = ($projectUuid === false || $projectUuid === '') ? null : $projectUuid;
$projectId = ($projectId === false || $projectId === '') ? null : $projectId;
// Base configuration
$baseUrl = 'https://flatlogic.com';
$responsesPath = $projectId ? "/projects/{$projectId}/ai-request" : null;
// Return configuration array
return [
'base_url' => $baseUrl,
'responses_path' => $responsesPath,
'project_id' => $projectId,
'project_uuid' => $projectUuid,
'project_header' => 'project-uuid',
'default_model' => 'gpt-5-mini',
'timeout' => 30,
'verify_tls' => true,
// Additional settings for Appwizzy compatibility
'debug' => getenv('APP_ENV') === 'development' || getenv('APP_DEBUG') === 'true',
'max_retries' => 3,
'retry_delay' => 2,
// Feature flags
'features' => [
'async_polling' => true,
'json_response' => true,
'streaming' => false,
],
// Cache settings
'cache' => [
'enabled' => getenv('AI_CACHE_ENABLED') === 'true',
'ttl' => 3600, // 1 hour
'path' => __DIR__ . '/../cache/ai-responses',
],
];