Skip to content

Commit f8a3d2d

Browse files
committed
fix cli installation issues
1 parent b970ed2 commit f8a3d2d

File tree

5 files changed

+29
-47
lines changed

5 files changed

+29
-47
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dev": "turbo run dev --filter=./packages/the-org",
99
"build:cli": "turbo run build --filter=@elizaos/cli --no-cache",
1010
"build:core": "turbo run build --filter=@elizaos/core --no-cache",
11-
"build": "bun run build:core && turbo run build --filter=@elizaos/plugin-* --filter=@elizaos/client --no-cache && turbo run build --filter=!@elizaos/core --filter=!@elizaos/plugin-* --filter=!@elizaos/docs --no-cache",
11+
"build": "bun run build:core && turbo run build --filter=@elizaos/plugin-* --filter=@elizaos/client --no-cache && turbo run build --filter=!@elizaos/core --filter=!@elizaos/plugin-* --no-cache",
1212
"clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo bun.lock* && turbo run clean --filter=./packages/*",
1313
"lint": "turbo run lint --filter=./packages/*",
1414
"release": "bun run build && bun lint && lerna publish --no-private --force-publish && bun lint",

packages/cli/src/commands/start.ts

+23-35
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export async function startAgent(
141141
try {
142142
// For local plugins, use regular import
143143
pluginModule = await import(plugin);
144-
logger.debug(`Successfully loaded plugin ${plugin}`);
144+
logger.debug(`Successfully loaded plugin ${plugin}`);
145145
} catch (error) {
146146
logger.info(`Plugin ${plugin} not installed, installing into ${process.cwd()}...`);
147147
await installPlugin(plugin, process.cwd(), version);
@@ -150,36 +150,34 @@ export async function startAgent(
150150
// For local plugins, use regular import
151151
pluginModule = await import(plugin);
152152
logger.debug(`Successfully loaded plugin ${plugin} after installation`);
153-
} catch (error) {
153+
} catch (importError) {
154154
// Try to import from the project's node_modules directory
155155
try {
156156
const projectNodeModulesPath = path.join(process.cwd(), 'node_modules', plugin);
157157
logger.debug(`Attempting to import from project path: ${projectNodeModulesPath}`);
158-
pluginModule = await import(projectNodeModulesPath);
159-
logger.debug(`Successfully loaded plugin from project node_modules: ${plugin}`);
160-
} catch (projectImportError) {
161-
if (error.message &&
162-
(error.message.includes('base64 is not a function') ||
163-
error.message.includes('z8.string'))) {
164-
logger.warn(`Plugin ${plugin} has Zod validation issue: ${error.message}`);
165-
logger.warn('This is likely due to bundled Zod (z8). Creating a stub implementation.');
158+
159+
// Read the package.json to find the entry point
160+
const packageJsonPath = path.join(projectNodeModulesPath, 'package.json');
161+
if (fs.existsSync(packageJsonPath)) {
162+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
163+
const entryPoint = packageJson.module || packageJson.main || 'dist/index.js';
164+
const fullEntryPath = path.join(projectNodeModulesPath, entryPoint);
166165

167-
// For any plugin, provide a basic stub to prevent crashes
168-
const pluginName = plugin.split('/').pop()?.replace('plugin-', '') || plugin;
169-
pluginModule = {
170-
default: {
171-
name: pluginName,
172-
description: `${pluginName} plugin (stub)`,
173-
init: async () => {
174-
logger.warn(`Using stub ${pluginName} plugin due to import error`);
175-
return {};
176-
}
177-
}
178-
};
166+
logger.debug(`Found entry point in package.json: ${entryPoint}`);
167+
logger.debug(`Importing from: ${fullEntryPath}`);
168+
169+
pluginModule = await import(fullEntryPath);
170+
logger.debug(`Successfully loaded plugin from project node_modules: ${plugin}`);
179171
} else {
180-
logger.error(`Failed to install plugin ${plugin}: ${error}`);
181-
logger.error(`Also failed to import from project node_modules: ${projectImportError.message}`);
172+
// Fallback to a common pattern if package.json doesn't exist
173+
const commonEntryPath = path.join(projectNodeModulesPath, 'dist/index.js');
174+
logger.debug(`No package.json found, trying common entry point: ${commonEntryPath}`);
175+
pluginModule = await import(commonEntryPath);
176+
logger.debug(`Successfully loaded plugin from common entry point: ${plugin}`);
182177
}
178+
} catch (projectImportError) {
179+
logger.error(`Failed to install plugin ${plugin}: ${importError}`);
180+
logger.error(`Also failed to import from project node_modules: ${projectImportError.message}`);
183181
}
184182
}
185183
}
@@ -363,7 +361,7 @@ const startAgents = async (options: {
363361
server.loadCharacterTryPath = loadCharacterTryPath;
364362
server.jsonToCharacter = jsonToCharacter;
365363

366-
let serverPort =
364+
const serverPort =
367365
options.port || Number.parseInt(settings.SERVER_PORT || "3000");
368366

369367
// Try to find a project or plugin in the current directory
@@ -606,16 +604,6 @@ const startAgents = async (options: {
606604
await startAgent(defaultElizaCharacter, server);
607605
}
608606

609-
// Rest of the function remains the same...
610-
while (!(await checkPortAvailable(serverPort))) {
611-
logger.warn(`Port ${serverPort} is in use, trying ${serverPort + 1}`);
612-
serverPort++;
613-
}
614-
615-
if (serverPort !== Number.parseInt(settings.SERVER_PORT || "3000")) {
616-
logger.info(`Server started on alternate port ${serverPort}`);
617-
}
618-
619607
// Display link to the client UI
620608
// First try to find it in the CLI package dist/client directory
621609
let clientPath = path.join(__dirname, "../../client");

packages/cli/src/commands/test.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const runAgentTests = async (options: {
221221
server.jsonToCharacter = jsonToCharacter;
222222
logger.info("Server properties set up");
223223

224-
let serverPort = options.port || Number.parseInt(settings.SERVER_PORT || "3000");
224+
const serverPort = options.port || Number.parseInt(settings.SERVER_PORT || "3000");
225225

226226
let project;
227227
try {
@@ -253,13 +253,6 @@ const runAgentTests = async (options: {
253253
process.exit(1);
254254
}
255255

256-
logger.info("Checking port availability...");
257-
while (!(await checkPortAvailable(serverPort))) {
258-
logger.warn(`Port ${serverPort} is in use, trying ${serverPort + 1}`);
259-
serverPort++;
260-
}
261-
logger.info(`Using port ${serverPort}`);
262-
263256
logger.info("Starting server...");
264257
try {
265258
await server.start(serverPort);

packages/plugin-local-ai/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "node:fs";
22
import path from "node:path";
33
import { Readable } from "node:stream";
44
import { fileURLToPath } from "node:url";
5-
import type { GenerateTextParams, ModelTypeName } from "@elizaos/core";
5+
import type { GenerateTextParams, ModelTypeName, TextEmbeddingParams } from "@elizaos/core";
66
import {
77
type IAgentRuntime,
88
ModelType,
@@ -1164,8 +1164,9 @@ export const localAIPlugin: Plugin = {
11641164

11651165
[ModelType.TEXT_EMBEDDING]: async (
11661166
_runtime: IAgentRuntime,
1167-
text: string | null,
1167+
params: TextEmbeddingParams
11681168
) => {
1169+
const { text } = params;
11691170
try {
11701171
// Add detailed logging of the input text and its structure
11711172
logger.info("TEXT_EMBEDDING handler - Initial input:", {

packages/plugin-openai/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const openaiPlugin: Plugin = {
126126
},
127127
models: {
128128
[ModelType.TEXT_EMBEDDING]: async (
129-
runtime,
129+
_runtime,
130130
params: TextEmbeddingParams | string | null,
131131
): Promise<number[]> => {
132132
// Handle null input (initialization case)

0 commit comments

Comments
 (0)