1
1
import fs from "node:fs" ;
2
2
import net from "node:net" ;
3
3
import os from "node:os" ;
4
- import path from "node:path" ;
4
+ import path , { dirname } from "node:path" ;
5
5
import { fileURLToPath } from "node:url" ;
6
6
import { buildProject } from "@/src/utils/build-project" ;
7
7
import {
@@ -115,8 +115,20 @@ async function startAgent(
115
115
) : Promise < IAgentRuntime > {
116
116
character . id ??= stringToUuid ( character . name ) ;
117
117
118
- // get the cli version
119
- const cliVersion = require ( "@elizaos/cli/package.json" ) . version ;
118
+ // For ESM modules we need to use import.meta.url instead of __dirname
119
+ const __filename = fileURLToPath ( import . meta. url ) ;
120
+ const __dirname = dirname ( __filename ) ;
121
+
122
+ // Find package.json relative to the current file
123
+ const packageJsonPath = path . resolve ( __dirname , "../package.json" ) ;
124
+
125
+ // Add a simple check in case the path is incorrect
126
+ let version = "0.0.0" ; // Fallback version
127
+ if ( ! fs . existsSync ( packageJsonPath ) ) {
128
+ } else {
129
+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , "utf-8" ) ) ;
130
+ version = packageJson . version ;
131
+ }
120
132
121
133
// for each plugin, check if it installed, and install if it is not
122
134
for ( const plugin of character . plugins ) {
@@ -125,8 +137,8 @@ async function startAgent(
125
137
try {
126
138
await import ( plugin ) ;
127
139
} catch ( error ) {
128
- logger . info ( `Plugin ${ plugin } not installed, installing...` ) ;
129
- await installPlugin ( plugin , process . cwd ( ) , cliVersion ) ;
140
+ logger . info ( `Plugin ${ plugin } not installed, installing into ${ process . cwd ( ) } ...` ) ;
141
+ await installPlugin ( plugin , process . cwd ( ) , version ) ;
130
142
}
131
143
}
132
144
0 commit comments