@@ -2,54 +2,94 @@ import { config } from "dotenv";
2
2
import fs from "fs" ;
3
3
import path from "path" ;
4
4
5
+ export interface Settings {
6
+ MAIN_WALLET_ADDRESS : string ;
7
+ OPENAI_API_KEY : string ;
8
+ USE_OPENAI_EMBEDDING : string ;
9
+ SYSTEM_PROMPT : string ;
10
+ OPENROUTER_MODEL : string ;
11
+ SMALL_OPENROUTER_MODEL : string ;
12
+ MEDIUM_OPENROUTER_MODEL : string ;
13
+ LARGE_OPENROUTER_MODEL : string ;
14
+ OLLAMA_MODEL : string ;
15
+ LARGE_OLLAMA_MODEL : string ;
16
+ MEDIUM_OLLAMA_MODEL : string ;
17
+ SMALL_OLLAMA_MODEL : string ;
18
+ OLLAMA_SERVER_URL : string ;
19
+ OLLAMA_EMBEDDING_MODEL : string ;
20
+ RPC_URL : string ;
21
+ BASE_MINT : string ;
22
+ BACKEND_URL : string ;
23
+ BACKEND_TOKEN : string ;
24
+ BIRDEYE_API_KEY : string ;
25
+ HELIUS_API_KEY : string ;
26
+ SERVER_PORT : string ;
27
+ CAPSOLVER_API_KEY : string ;
28
+ CUDA_PATH : string ;
29
+ }
30
+
5
31
/**
6
32
* Recursively searches for a .env file starting from the current directory
7
33
* and moving up through parent directories
8
- * @param {string } [startDir=process.cwd()] - Starting directory for the search
9
- * @returns {string|null } Path to the nearest .env file or null if not found
10
34
*/
11
35
export function findNearestEnvFile ( startDir = process . cwd ( ) ) {
36
+ console . error ( 'DEBUG - Starting env file search' ) ;
37
+ console . error ( 'DEBUG - Current working directory:' , process . cwd ( ) ) ;
38
+
39
+ // In test environment, use the known working path
40
+ if ( process . env . NODE_ENV === 'test' || process . env . VITEST ) {
41
+ const testPath = path . join ( process . cwd ( ) , '.env.test' ) ;
42
+ console . error ( 'DEBUG - Checking test path:' , testPath ) ;
43
+ if ( fs . existsSync ( testPath ) ) {
44
+ console . error ( 'DEBUG - Found test env file at:' , testPath ) ;
45
+ return testPath ;
46
+ }
47
+ }
48
+
49
+ // Look for regular .env
12
50
let currentDir = startDir ;
51
+ const envFile = process . env . NODE_ENV === 'test' ? '.env.test' : '.env' ;
13
52
14
- // Continue searching until we reach the root directory
15
53
while ( currentDir !== path . parse ( currentDir ) . root ) {
16
- const envPath = path . join ( currentDir , ".env" ) ;
17
-
54
+ const envPath = path . join ( currentDir , envFile ) ;
55
+ console . error ( 'DEBUG - Checking path:' , envPath ) ;
18
56
if ( fs . existsSync ( envPath ) ) {
57
+ console . error ( 'DEBUG - Found env file at:' , envPath ) ;
19
58
return envPath ;
20
59
}
21
-
22
- // Move up to parent directory
23
60
currentDir = path . dirname ( currentDir ) ;
24
61
}
25
62
26
- // Check root directory as well
27
- const rootEnvPath = path . join ( path . parse ( currentDir ) . root , ".env" ) ;
28
- return fs . existsSync ( rootEnvPath ) ? rootEnvPath : null ;
63
+ console . error ( 'DEBUG - No env file found after checking all paths' ) ;
64
+ console . error ( 'DEBUG - Final cwd:' , process . cwd ( ) ) ;
65
+ console . error ( 'DEBUG - Final NODE_ENV:' , process . env . NODE_ENV ) ;
66
+ return null ;
29
67
}
30
68
31
69
/**
32
70
* Loads environment variables from the nearest .env file
33
- * @returns {Object } Environment variables object
34
- * @throws {Error } If no .env file is found
35
71
*/
36
72
export function loadEnvConfig ( ) {
73
+ console . error ( 'DEBUG - loadEnvConfig called' ) ;
74
+ console . error ( 'DEBUG - Current working directory:' , process . cwd ( ) ) ;
75
+ console . error ( 'DEBUG - NODE_ENV:' , process . env . NODE_ENV ) ;
76
+
37
77
const envPath = findNearestEnvFile ( ) ;
38
78
39
79
if ( ! envPath ) {
40
80
throw new Error ( "No .env file found in current or parent directories." ) ;
41
81
}
42
82
43
- // Load the . env file
83
+ console . error ( 'DEBUG - Loading env file from:' , envPath ) ;
44
84
const result = config ( { path : envPath } ) ;
45
-
46
85
if ( result . error ) {
47
86
throw new Error ( `Error loading .env file: ${ result . error } ` ) ;
48
87
}
49
88
50
- console . log ( `Loaded .env file from: ${ envPath } ` ) ;
51
- return process . env ;
89
+ console . error ( 'DEBUG - Successfully loaded env file' ) ;
90
+
91
+ // Populate the settings object with the environment variables
92
+ Object . assign ( settings , process . env ) ;
52
93
}
53
94
54
- export const settings = loadEnvConfig ( ) ;
55
- export default settings ;
95
+ export const settings : Settings = { } as Settings ;
0 commit comments