Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep getting reoccuring issue: #1970

Open
DanielleMichelle opened this issue Jan 7, 2025 · 0 comments
Open

Keep getting reoccuring issue: #1970

DanielleMichelle opened this issue Jan 7, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@DanielleMichelle
Copy link

[{
"resource": "/Users/danielle_fabric/eliza/agent/src/index.ts",
"owner": "typescript",
"code": "2305",
"severity": 8,
"message": "Module '"@elizaos/core"' has no exported member 'createAgent'.",
"source": "ts",
"startLineNumber": 11,
"startColumn": 10,
"endLineNumber": 11,
"endColumn": 21
},{
"resource": "/Users/danielle_fabric/eliza/agent/src/index.ts",
"owner": "typescript",
"code": "2305",
"severity": 8,
"message": "Module '"@elizaos/core"' has no exported member 'initializeClients'.",
"source": "ts",
"startLineNumber": 11,
"startColumn": 23,
"endLineNumber": 11,
"endColumn": 40
}]

Despite trying to update more than 20 times keeps saying same 2 errors:

My current index.ts code:
// Import necessary packages
import { fileURLToPath } from "url"; // Ensure the url module is imported for fileURLToPath
import * as path from "path";
import * as fs from "fs";
import yargs from "yargs";
import { DirectClient } from "@elizaos/client-direct";
import { TwitterClientInterface } from "@elizaos/client-twitter";
import { mainCharacter } from "../mainCharacter.ts";
import Twitter from 'twitter'; // Import Twitter package

import { createAgent, initializeClients, elizaLogger, settings, validateCharacterConfig, Character } from "@elizaos/core"; // Make sure these are exported

// Define the interface for characters with onStart property
interface CharacterWithOnStart extends Character {
onStart?: string[];
}

const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory

// Helper functions
function tryLoadFile(filePath: string): string | null {
try {
return fs.readFileSync(filePath, "utf8");
} catch (e) {
return null;
}
}

export const wait = (minTime: number = 1000, maxTime: number = 3000) => {
const waitTime =
Math.floor(Math.random() * (maxTime - minTime + 1)) + minTime;
return new Promise((resolve) => setTimeout(resolve, waitTime));
};

// Parse Arguments with yargs
export function parseArguments(): { character?: string; characters?: string } {
try {
return yargs(process.argv.slice(2)) // start from the third argument to ignore node and script path
.option("character", {
type: "string",
description: "Path to the character JSON file",
})
.option("characters", {
type: "string",
description: "Comma separated list of paths to character JSON files",
})
.parseSync();
} catch (error) {
elizaLogger.error("Error parsing arguments:", error);
return {};
}
}

// Twitter Login Function
async function loginToTwitter() {
const twitterClient = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});

try {
    const account = await twitterClient.get('account/verify_credentials');
    elizaLogger.info('Successfully logged in to Twitter:', account);
} catch (error) {
    elizaLogger.error('Error logging in to Twitter:', error);
}

}

// Add Twitter login to onStart
async function runOnStartActions(character: CharacterWithOnStart) {
if (character.onStart && character.onStart.includes("Run Twitter Login")) {
await loginToTwitter(); // Trigger the Twitter login
}
}

// Load Characters and Run OnStart Actions
export async function loadCharacters(charactersArg: string): Promise<Character[]> {
let characterPaths = charactersArg?.split(",").map((filePath) => filePath.trim());
const loadedCharacters = [];

if (characterPaths?.length > 0) {
    for (const characterPath of characterPaths) {
        let content = null;
        let resolvedPath = "";

        const pathsToTry = [
            characterPath,
            path.resolve(process.cwd(), characterPath),
            path.resolve(process.cwd(), "agent", characterPath),
            path.resolve(__dirname, characterPath),
            path.resolve(__dirname, "characters", path.basename(characterPath)),
            path.resolve(__dirname, "../characters", path.basename(characterPath)),
            path.resolve(__dirname, "../../characters", path.basename(characterPath)),
        ];

        for (const tryPath of pathsToTry) {
            content = tryLoadFile(tryPath);
            if (content !== null) {
                resolvedPath = tryPath;
                break;
            }
        }

        if (content === null) {
            elizaLogger.error(`Error loading character from ${characterPath}: File not found`);
            process.exit(1);
        }

        try {
            const character = JSON.parse(content);
            validateCharacterConfig(character);

            loadedCharacters.push(character);
            elizaLogger.info(`Successfully loaded character from: ${resolvedPath}`);

            // Run the onStart actions
            await runOnStartActions(character);

        } catch (e) {
            elizaLogger.error(`Error parsing character from ${resolvedPath}: ${e}`);
            process.exit(1);
        }
    }
}

if (loadedCharacters.length === 0) {
    elizaLogger.info("No characters found, using default character");
    loadedCharacters.push(mainCharacter);
}

return loadedCharacters;

}

// Define startAgents function
async function startAgents() {
const directClient = new DirectClient();
const { character } = parseArguments(); // Explicitly get the character argument

if (!character) {
    elizaLogger.error("Character path not provided.");
    process.exit(1);
}

const characters = await loadCharacters(character); // Pass the correct character argument
for (const character of characters) {
    const opts = {};  // Provide the necessary opts argument
    const runtime = await createAgent(character, opts);
    await runtime.initialize();
    runtime.clients = await initializeClients(character, runtime);
    directClient.registerAgent(runtime);
}

// Starting the client server
const serverPort = parseInt(settings.SERVER_PORT || "3000");
directClient.start(serverPort);

}

startAgents().catch((error) => {
elizaLogger.error("Unhandled error in startAgents:", error);
process.exit(1);
});

@DanielleMichelle DanielleMichelle added the bug Something isn't working label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant