@@ -141,7 +141,7 @@ export async function startAgent(
141
141
try {
142
142
// For local plugins, use regular import
143
143
pluginModule = await import ( plugin ) ;
144
- logger . debug ( `Successfully loaded plugin ${ plugin } ` ) ;
144
+ logger . debug ( `Successfully loaded plugin ${ plugin } ` ) ;
145
145
} catch ( error ) {
146
146
logger . info ( `Plugin ${ plugin } not installed, installing into ${ process . cwd ( ) } ...` ) ;
147
147
await installPlugin ( plugin , process . cwd ( ) , version ) ;
@@ -150,36 +150,34 @@ export async function startAgent(
150
150
// For local plugins, use regular import
151
151
pluginModule = await import ( plugin ) ;
152
152
logger . debug ( `Successfully loaded plugin ${ plugin } after installation` ) ;
153
- } catch ( error ) {
153
+ } catch ( importError ) {
154
154
// Try to import from the project's node_modules directory
155
155
try {
156
156
const projectNodeModulesPath = path . join ( process . cwd ( ) , 'node_modules' , plugin ) ;
157
157
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 ) ;
166
165
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 } ` ) ;
179
171
} 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 } ` ) ;
182
177
}
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 } ` ) ;
183
181
}
184
182
}
185
183
}
@@ -363,7 +361,7 @@ const startAgents = async (options: {
363
361
server . loadCharacterTryPath = loadCharacterTryPath ;
364
362
server . jsonToCharacter = jsonToCharacter ;
365
363
366
- let serverPort =
364
+ const serverPort =
367
365
options . port || Number . parseInt ( settings . SERVER_PORT || "3000" ) ;
368
366
369
367
// Try to find a project or plugin in the current directory
@@ -606,16 +604,6 @@ const startAgents = async (options: {
606
604
await startAgent ( defaultElizaCharacter , server ) ;
607
605
}
608
606
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
-
619
607
// Display link to the client UI
620
608
// First try to find it in the CLI package dist/client directory
621
609
let clientPath = path . join ( __dirname , "../../client" ) ;
0 commit comments