diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 34e0aee1ae..2f77d1d0c7 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -11,6 +11,7 @@ $httpsPort = $this->getParam('httpsPort', ''); $version = $this->getParam('version', ''); $organization = $this->getParam('organization', ''); $image = $this->getParam('image', ''); +$enableAssistant = $this->getParam('enableAssistant', false); ?>services: traefik: image: traefik:2.11 @@ -848,6 +849,7 @@ $image = $this->getParam('image', ''); - _APP_DB_USER - _APP_DB_PASS + appwrite-assistant: image: appwrite/assistant:0.8.4 container_name: appwrite-assistant @@ -857,6 +859,7 @@ $image = $this->getParam('image', ''); - appwrite environment: - _APP_ASSISTANT_OPENAI_API_KEY + appwrite-browser: image: appwrite/browser:0.3.2 diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index b210a020b9..e51ea3188a 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -148,11 +148,63 @@ class Install extends Action $httpsPort = ($httpsPort) ? $httpsPort : $defaultHTTPSPort; } + $enableAssistant = false; + $assistantExistsInOldCompose = false; + + if ($data !== false && isset($compose)) { + try { + $assistantService = $compose->getService('appwrite-assistant'); + $assistantExistsInOldCompose = $assistantService !== null; + } catch (\Throwable) { + // assistant service doesn't exist, keep default false + } + } + + if ($interactive == 'Y' && Console::isInteractive()) { + $prompt = 'Add Appwrite Assistant? (Y/n)' . ($assistantExistsInOldCompose ? ' [Currently enabled]' : ''); + $answer = Console::confirm($prompt); + + if (empty($answer)) { + $enableAssistant = $assistantExistsInOldCompose; + } else { + $enableAssistant = \strtolower($answer) === 'y'; + } + } elseif ($assistantExistsInOldCompose) { + $enableAssistant = true; + } + $input = []; $password = new Password(); $token = new Token(); foreach ($vars as $var) { + if ($var['name'] === '_APP_ASSISTANT_OPENAI_API_KEY') { + if (!$enableAssistant) { + $input[$var['name']] = ''; + continue; + } + + // key already exists + if (!empty($var['default'])) { + $input[$var['name']] = $var['default']; + continue; + } + + // if assistant enabled and no key, ask for it + if (Console::isInteractive() && $interactive === 'Y') { + $input[$var['name']] = Console::confirm('Enter your OpenAI API key for Appwrite Assistant:'); + if (empty($input[$var['name']])) { + Console::warning('No API key provided. Assistant will be disabled.'); + $enableAssistant = false; + $input[$var['name']] = ''; + } + continue; + } + + $input[$var['name']] = ''; + continue; + } + if (!empty($var['filter']) && ($interactive !== 'Y' || !Console::isInteractive())) { if ($data && $var['default'] !== null) { $input[$var['name']] = $var['default']; @@ -199,7 +251,8 @@ class Install extends Action ->setParam('httpsPort', $httpsPort) ->setParam('version', APP_VERSION_STABLE) ->setParam('organization', $organization) - ->setParam('image', $image); + ->setParam('image', $image) + ->setParam('enableAssistant', $enableAssistant); $templateForEnv->setParam('vars', $input);