load-env.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import fs from 'fs';
  2. import os from 'os';
  3. import path from 'path';
  4. import { fileURLToPath } from 'url';
  5. import {
  6. applyConfigToProcessEnv,
  7. getPilotDeckConfigPath,
  8. readPilotDeckConfigFile,
  9. } from './services/pilotdeckConfig.js';
  10. const __filename = fileURLToPath(import.meta.url);
  11. const __dirname = path.dirname(__filename);
  12. const REPO_ROOT = path.resolve(__dirname, '../..');
  13. // EDGECLAW_API_BASE_URL / EDGECLAW_API_KEY / EDGECLAW_MODEL used to be
  14. // required here, but no code in ui/ actually consumes those variables —
  15. // chat execution goes through pilotdeck-bridge.js → src/gateway, which
  16. // reads ~/.pilotdeck/pilotdeck.yaml directly. The sanity check has been
  17. // retired; ui/server boots even when the config file is missing.
  18. function applyDerivedRuntimeEnv() {
  19. const { config } = readPilotDeckConfigFile();
  20. applyConfigToProcessEnv(config);
  21. }
  22. export function getRepoRootDir() {
  23. return REPO_ROOT;
  24. }
  25. export function getPilotDeckConfigFilePath() {
  26. return getPilotDeckConfigPath();
  27. }
  28. export function hasPilotDeckConfigFile() {
  29. return fs.existsSync(getPilotDeckConfigPath());
  30. }
  31. // Stub for the deprecated boot-time sanity check. Kept as a named export
  32. // so existing callers (e.g. ui/server/index.js) don't need a coordinated
  33. // removal; the function is now a no-op that returns the empty list of
  34. // missing keys.
  35. export function assertRequiredPilotDeckEnv() {
  36. return [];
  37. }
  38. export function loadRootPilotDeckEnv() {
  39. applyDerivedRuntimeEnv();
  40. if (!process.env.DATABASE_PATH) {
  41. process.env.DATABASE_PATH = path.join(process.env.PILOT_HOME || path.join(os.homedir(), '.pilotdeck'), 'auth.db');
  42. }
  43. return hasPilotDeckConfigFile();
  44. }
  45. loadRootPilotDeckEnv();