Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
normand1 committed Nov 16, 2024
1 parent c93510c commit 4d7e0aa
Show file tree
Hide file tree
Showing 12 changed files with 457 additions and 507 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v23.1.0
20 changes: 19 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@
"runtimeExecutable": "pnpm",
"runtimeArgs": ["run", "dev"],
"skipFiles": ["<node_internals>/**"]
}
},
{
"type": "node",
"request": "launch",
"name": "Debug Vitest",
"program": "${workspaceFolder}/node_modules/vitest/vitest.mjs",
"args": [
"run",
"--",
"${relativeFile}" // Ensures the currently open test file is passed
],
"cwd": "${workspaceFolder}",
"env": {
"NODE_ENV": "test" // Ensure test environment is set
},
"autoAttachChildProcesses": true,
"smartStep": true,
"skipFiles": ["<node_internals>/**"]
}
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"docker:run": "bash ./scripts/docker.sh run",
"docker:bash": "bash ./scripts/docker.sh bash",
"docker:start": "bash ./scripts/docker.sh start",
"docker": "pnpm docker:build && pnpm docker:run && pnpm docker:bash"
"docker": "pnpm docker:build && pnpm docker:run && pnpm docker:bash",
"tests": "pnpm --dir packages/core test"
},
"devDependencies": {
"concurrently": "^9.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
elizaConfig.yaml
custom_actions/
custom_actions/
cache/

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { models } from "./models.ts";
import { IAgentRuntime, ModelProviderName, ModelClass } from "./types.ts";
import fs from "fs";
import { trimTokens } from "./generation.ts";
import { settings } from "./settings.ts";
import settings from "./settings.ts";

function getRootPath() {
const __filename = fileURLToPath(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
parseJSONObjectFromText,
parseShouldRespondFromText,
} from "./parsing.ts";
import { settings } from "./settings.ts";
import settings from "./settings.ts";
import {
Content,
IAgentRuntime,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { settings } from "./settings.ts";
import settings from "./settings.ts";
import { Models, ModelProviderName, ModelClass } from "./types.ts";

export const models: Models = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { formatActors, formatMessages, getActorDetails } from "./messages.ts";
import { parseJsonArrayFromText } from "./parsing.ts";
import { formatPosts } from "./posts.ts";
import { getProviders } from "./providers.ts";
import { settings } from "./settings.ts";
import settings from "./settings.ts";
import {
Character,
Goal,
Expand Down
76 changes: 18 additions & 58 deletions packages/core/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,54 @@ import { config } from "dotenv";
import fs from "fs";
import path from "path";

export interface Settings {
MAIN_WALLET_ADDRESS: string;
OPENAI_API_KEY: string;
USE_OPENAI_EMBEDDING: string;
SYSTEM_PROMPT: string;
OPENROUTER_MODEL: string;
SMALL_OPENROUTER_MODEL: string;
MEDIUM_OPENROUTER_MODEL: string;
LARGE_OPENROUTER_MODEL: string;
OLLAMA_MODEL: string;
LARGE_OLLAMA_MODEL: string;
MEDIUM_OLLAMA_MODEL: string;
SMALL_OLLAMA_MODEL: string;
OLLAMA_SERVER_URL: string;
OLLAMA_EMBEDDING_MODEL: string;
RPC_URL: string;
BASE_MINT: string;
BACKEND_URL: string;
BACKEND_TOKEN: string;
BIRDEYE_API_KEY: string;
HELIUS_API_KEY: string;
SERVER_PORT: string;
CAPSOLVER_API_KEY: string;
CUDA_PATH: string;
}

/**
* Recursively searches for a .env file starting from the current directory
* and moving up through parent directories
* @param {string} [startDir=process.cwd()] - Starting directory for the search
* @returns {string|null} Path to the nearest .env file or null if not found
*/
export function findNearestEnvFile(startDir = process.cwd()) {
console.error('DEBUG - Starting env file search');
console.error('DEBUG - Current working directory:', process.cwd());

// In test environment, use the known working path
if (process.env.NODE_ENV === 'test' || process.env.VITEST) {
const testPath = path.join(process.cwd(), '.env.test');
console.error('DEBUG - Checking test path:', testPath);
if (fs.existsSync(testPath)) {
console.error('DEBUG - Found test env file at:', testPath);
return testPath;
}
}

// Look for regular .env
let currentDir = startDir;
const envFile = process.env.NODE_ENV === 'test' ? '.env.test' : '.env';

// Continue searching until we reach the root directory
while (currentDir !== path.parse(currentDir).root) {
const envPath = path.join(currentDir, envFile);
console.error('DEBUG - Checking path:', envPath);
const envPath = path.join(currentDir, ".env");

if (fs.existsSync(envPath)) {
console.error('DEBUG - Found env file at:', envPath);
return envPath;
}

// Move up to parent directory
currentDir = path.dirname(currentDir);
}

console.error('DEBUG - No env file found after checking all paths');
console.error('DEBUG - Final cwd:', process.cwd());
console.error('DEBUG - Final NODE_ENV:', process.env.NODE_ENV);
return null;
// Check root directory as well
const rootEnvPath = path.join(path.parse(currentDir).root, ".env");
return fs.existsSync(rootEnvPath) ? rootEnvPath : null;
}

/**
* Loads environment variables from the nearest .env file
* @returns {Object} Environment variables object
* @throws {Error} If no .env file is found
*/
export function loadEnvConfig() {
console.error('DEBUG - loadEnvConfig called');
console.error('DEBUG - Current working directory:', process.cwd());
console.error('DEBUG - NODE_ENV:', process.env.NODE_ENV);

const envPath = findNearestEnvFile();

if (!envPath) {
throw new Error("No .env file found in current or parent directories.");
}

console.error('DEBUG - Loading env file from:', envPath);
// Load the .env file
const result = config({ path: envPath });

if (result.error) {
throw new Error(`Error loading .env file: ${result.error}`);
}

console.error('DEBUG - Successfully loaded env file');

// Populate the settings object with the environment variables
Object.assign(settings, process.env);
console.log(`Loaded .env file from: ${envPath}`);
return process.env;
}

export const settings: Settings = {} as Settings;
export const settings = loadEnvConfig();
export default settings;
Loading

0 comments on commit 4d7e0aa

Please sign in to comment.