@@ -40,6 +40,7 @@ import {
40
40
import { zgPlugin } from "@elizaos/plugin-0g" ;
41
41
42
42
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap" ;
43
+ import { normalizeCharacter } from "@elizaos/plugin-di" ;
43
44
import createGoatPlugin from "@elizaos/plugin-goat" ;
44
45
// import { intifacePlugin } from "@elizaos/plugin-intiface";
45
46
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation" ;
@@ -248,6 +249,7 @@ export async function loadCharacterFromOnchain(): Promise<Character[]> {
248
249
}
249
250
}
250
251
252
+
251
253
async function loadCharactersFromUrl ( url : string ) : Promise < Character [ ] > {
252
254
try {
253
255
const response = await fetch ( url ) ;
@@ -319,6 +321,61 @@ async function loadCharacter(filePath: string): Promise<Character> {
319
321
return jsonToCharacter ( filePath , character ) ;
320
322
}
321
323
324
+ async function loadCharacterTryPath ( characterPath : string ) : Promise < Character > {
325
+ let content : string | null = null ;
326
+ let resolvedPath = "" ;
327
+
328
+ // Try different path resolutions in order
329
+ const pathsToTry = [
330
+ characterPath , // exact path as specified
331
+ path . resolve ( process . cwd ( ) , characterPath ) , // relative to cwd
332
+ path . resolve ( process . cwd ( ) , "agent" , characterPath ) , // Add this
333
+ path . resolve ( __dirname , characterPath ) , // relative to current script
334
+ path . resolve ( __dirname , "characters" , path . basename ( characterPath ) ) , // relative to agent/characters
335
+ path . resolve ( __dirname , "../characters" , path . basename ( characterPath ) ) , // relative to characters dir from agent
336
+ path . resolve (
337
+ __dirname ,
338
+ "../../characters" ,
339
+ path . basename ( characterPath )
340
+ ) , // relative to project root characters dir
341
+ ] ;
342
+
343
+ elizaLogger . info (
344
+ "Trying paths:" ,
345
+ pathsToTry . map ( ( p ) => ( {
346
+ path : p ,
347
+ exists : fs . existsSync ( p ) ,
348
+ } ) )
349
+ ) ;
350
+
351
+ for ( const tryPath of pathsToTry ) {
352
+ content = tryLoadFile ( tryPath ) ;
353
+ if ( content !== null ) {
354
+ resolvedPath = tryPath ;
355
+ break ;
356
+ }
357
+ }
358
+
359
+ if ( content === null ) {
360
+ elizaLogger . error (
361
+ `Error loading character from ${ characterPath } : File not found in any of the expected locations`
362
+ ) ;
363
+ elizaLogger . error ( "Tried the following paths:" ) ;
364
+ pathsToTry . forEach ( ( p ) => elizaLogger . error ( ` - ${ p } ` ) ) ;
365
+ throw new Error (
366
+ `Error loading character from ${ characterPath } : File not found in any of the expected locations`
367
+ ) ;
368
+ }
369
+ try {
370
+ const character : Character = await loadCharacter ( resolvedPath ) ;
371
+ elizaLogger . info ( `Successfully loaded character from: ${ resolvedPath } ` ) ;
372
+ return character ;
373
+ } catch ( e ) {
374
+ elizaLogger . error ( `Error parsing character from ${ resolvedPath } : ${ e } ` ) ;
375
+ throw new Error ( `Error parsing character from ${ resolvedPath } : ${ e } ` ) ;
376
+ }
377
+ }
378
+
322
379
function commaSeparatedStringToArray ( commaSeparated : string ) : string [ ] {
323
380
return commaSeparated ?. split ( "," ) . map ( ( value ) => value . trim ( ) ) ;
324
381
}
@@ -331,68 +388,11 @@ export async function loadCharacters(
331
388
332
389
if ( characterPaths ?. length > 0 ) {
333
390
for ( const characterPath of characterPaths ) {
334
- let content : string | null = null ;
335
- let resolvedPath = "" ;
336
-
337
- // Try different path resolutions in order
338
- const pathsToTry = [
339
- characterPath , // exact path as specified
340
- path . resolve ( process . cwd ( ) , characterPath ) , // relative to cwd
341
- path . resolve ( process . cwd ( ) , "agent" , characterPath ) , // Add this
342
- path . resolve ( __dirname , characterPath ) , // relative to current script
343
- path . resolve (
344
- __dirname ,
345
- "characters" ,
346
- path . basename ( characterPath )
347
- ) , // relative to agent/characters
348
- path . resolve (
349
- __dirname ,
350
- "../characters" ,
351
- path . basename ( characterPath )
352
- ) , // relative to characters dir from agent
353
- path . resolve (
354
- __dirname ,
355
- "../../characters" ,
356
- path . basename ( characterPath )
357
- ) , // relative to project root characters dir
358
- ] ;
359
-
360
- elizaLogger . info (
361
- "Trying paths:" ,
362
- pathsToTry . map ( ( p ) => ( {
363
- path : p ,
364
- exists : fs . existsSync ( p ) ,
365
- } ) )
366
- ) ;
367
-
368
- for ( const tryPath of pathsToTry ) {
369
- content = tryLoadFile ( tryPath ) ;
370
- if ( content !== null ) {
371
- resolvedPath = tryPath ;
372
- break ;
373
- }
374
- }
375
-
376
- if ( content === null ) {
377
- elizaLogger . error (
378
- `Error loading character from ${ characterPath } : File not found in any of the expected locations`
379
- ) ;
380
- elizaLogger . error ( "Tried the following paths:" ) ;
381
- pathsToTry . forEach ( ( p ) => elizaLogger . error ( ` - ${ p } ` ) ) ;
382
- process . exit ( 1 ) ;
383
- }
384
-
385
391
try {
386
- const character : Character = await loadCharacter ( resolvedPath ) ;
387
-
392
+ const character : Character =
393
+ await loadCharacterTryPath ( characterPath ) ;
388
394
loadedCharacters . push ( character ) ;
389
- elizaLogger . info (
390
- `Successfully loaded character from: ${ resolvedPath } `
391
- ) ;
392
395
} catch ( e ) {
393
- elizaLogger . error (
394
- `Error parsing character from ${ resolvedPath } : ${ e } `
395
- ) ;
396
396
process . exit ( 1 ) ;
397
397
}
398
398
}
@@ -1219,6 +1219,9 @@ const startAgents = async () => {
1219
1219
characters = await loadCharacters ( charactersArg ) ;
1220
1220
}
1221
1221
1222
+ // Normalize characters for injectable plugins
1223
+ characters = await Promise . all ( characters . map ( normalizeCharacter ) ) ;
1224
+
1222
1225
try {
1223
1226
for ( const character of characters ) {
1224
1227
await startAgent ( character , directClient ) ;
@@ -1244,6 +1247,9 @@ const startAgents = async () => {
1244
1247
return startAgent ( character , directClient ) ;
1245
1248
} ;
1246
1249
1250
+ directClient . loadCharacterTryPath = loadCharacterTryPath ;
1251
+ directClient . jsonToCharacter = jsonToCharacter ;
1252
+
1247
1253
directClient . start ( serverPort ) ;
1248
1254
1249
1255
if ( serverPort !== Number . parseInt ( settings . SERVER_PORT || "3000" ) ) {
0 commit comments