@@ -184,12 +184,17 @@ function mergeCharacters(base: Character, child: Character): Character {
184
184
} ;
185
185
return mergeObjects ( base , child ) ;
186
186
}
187
- async function loadCharacter ( filePath : string ) : Promise < Character > {
188
- const content = tryLoadFile ( filePath ) ;
189
- if ( ! content ) {
190
- throw new Error ( `Character file not found: ${ filePath } ` ) ;
191
- }
192
- let character = JSON . parse ( content ) ;
187
+
188
+ async function loadCharacterFromUrl ( url : string ) : Promise < Character > {
189
+ const response = await fetch ( url ) ;
190
+ const character = await response . json ( ) ;
191
+ return jsonToCharacter ( url , character ) ;
192
+ }
193
+
194
+ async function jsonToCharacter (
195
+ filePath : string ,
196
+ character : any
197
+ ) : Promise < Character > {
193
198
validateCharacterConfig ( character ) ;
194
199
195
200
// .id isn't really valid
@@ -227,6 +232,15 @@ async function loadCharacter(filePath: string): Promise<Character> {
227
232
return character ;
228
233
}
229
234
235
+ async function loadCharacter ( filePath : string ) : Promise < Character > {
236
+ const content = tryLoadFile ( filePath ) ;
237
+ if ( ! content ) {
238
+ throw new Error ( `Character file not found: ${ filePath } ` ) ;
239
+ }
240
+ let character = JSON . parse ( content ) ;
241
+ return jsonToCharacter ( filePath , character ) ;
242
+ }
243
+
230
244
export async function loadCharacters (
231
245
charactersArg : string
232
246
) : Promise < Character [ ] > {
@@ -305,6 +319,16 @@ export async function loadCharacters(
305
319
}
306
320
307
321
if ( loadedCharacters . length === 0 ) {
322
+ if (
323
+ process . env . REMOTE_CHARACTER_URL != "" &&
324
+ process . env . REMOTE_CHARACTER_URL . startsWith ( "http" )
325
+ ) {
326
+ const character = await loadCharacterFromUrl (
327
+ process . env . REMOTE_CHARACTER_URL
328
+ ) ;
329
+ loadedCharacters . push ( character ) ;
330
+ }
331
+
308
332
elizaLogger . info ( "No characters found, using default character" ) ;
309
333
loadedCharacters . push ( defaultCharacter ) ;
310
334
}
@@ -1116,14 +1140,17 @@ startAgents().catch((error) => {
1116
1140
} ) ;
1117
1141
1118
1142
// Prevent unhandled exceptions from crashing the process if desired
1119
- if ( process . env . PREVENT_UNHANDLED_EXIT && parseBooleanFromText ( process . env . PREVENT_UNHANDLED_EXIT ) ) {
1143
+ if (
1144
+ process . env . PREVENT_UNHANDLED_EXIT &&
1145
+ parseBooleanFromText ( process . env . PREVENT_UNHANDLED_EXIT )
1146
+ ) {
1120
1147
// Handle uncaught exceptions to prevent the process from crashing
1121
- process . on ( ' uncaughtException' , function ( err ) {
1148
+ process . on ( " uncaughtException" , function ( err ) {
1122
1149
console . error ( "uncaughtException" , err ) ;
1123
1150
} ) ;
1124
1151
1125
1152
// Handle unhandled rejections to prevent the process from crashing
1126
- process . on ( ' unhandledRejection' , function ( err ) {
1153
+ process . on ( " unhandledRejection" , function ( err ) {
1127
1154
console . error ( "unhandledRejection" , err ) ;
1128
1155
} ) ;
1129
1156
}
0 commit comments