@@ -11,9 +11,9 @@ import {
11
11
type Plugin ,
12
12
logger ,
13
13
settings ,
14
- stringToUuid
14
+ stringToUuid ,
15
+ ModelTypes
15
16
} from "@elizaos/core" ;
16
- import chalk from "chalk" ;
17
17
import { Command } from "commander" ;
18
18
import * as dotenv from "dotenv" ;
19
19
import { AgentServer } from "../server/index" ;
@@ -114,6 +114,7 @@ async function startAgent(
114
114
options : {
115
115
dataDir ?: string ;
116
116
postgresUrl ?: string ;
117
+ isPluginTestMode ?: boolean ;
117
118
} = { } ,
118
119
) : Promise < IAgentRuntime > {
119
120
character . id ??= stringToUuid ( character . name ) ;
@@ -129,6 +130,71 @@ async function startAgent(
129
130
// start services/plugins/process knowledge
130
131
await runtime . initialize ( ) ;
131
132
133
+ // Check if TEXT_EMBEDDING model is registered, if not, try to load one
134
+ // Skip auto-loading embedding models if we're in plugin test mode
135
+ const embeddingModel = runtime . getModel ( ModelTypes . TEXT_EMBEDDING ) ;
136
+ if ( ! embeddingModel && ! options . isPluginTestMode ) {
137
+ logger . info ( "No TEXT_EMBEDDING model registered. Attempting to load one automatically..." ) ;
138
+
139
+ // First check if OpenAI API key exists
140
+ if ( process . env . OPENAI_API_KEY ) {
141
+ logger . info ( "Found OpenAI API key. Loading OpenAI plugin for embeddings..." ) ;
142
+
143
+ try {
144
+ // Use Node's require mechanism to dynamically load the plugin
145
+ const pluginName = "@elizaos/plugin-openai" ;
146
+
147
+ try {
148
+ // Using require for dynamic imports in Node.js is safer than eval
149
+ // This is a CommonJS approach that works in Node.js
150
+ // @ts -ignore - Ignoring TypeScript's static checking for dynamic requires
151
+ const pluginModule = require ( pluginName ) ;
152
+ const plugin = pluginModule . default || pluginModule . openaiPlugin ;
153
+
154
+ if ( plugin ) {
155
+ await runtime . registerPlugin ( plugin ) ;
156
+ logger . success ( "Successfully loaded OpenAI plugin for embeddings" ) ;
157
+ } else {
158
+ logger . warn ( `Could not find a valid plugin export in ${ pluginName } ` ) ;
159
+ }
160
+ } catch ( error ) {
161
+ logger . warn ( `Failed to import OpenAI plugin: ${ error } ` ) ;
162
+ logger . warn ( `You may need to install it with: npm install ${ pluginName } ` ) ;
163
+ }
164
+ } catch ( error ) {
165
+ logger . warn ( `Error loading OpenAI plugin: ${ error } ` ) ;
166
+ }
167
+ } else {
168
+ logger . info ( "No OpenAI API key found. Loading local-ai plugin for embeddings..." ) ;
169
+
170
+ try {
171
+ // Use Node's require mechanism to dynamically load the plugin
172
+ const pluginName = "@elizaos/plugin-local-ai" ;
173
+
174
+ try {
175
+ // Using require for dynamic imports in Node.js is safer than eval
176
+ // @ts -ignore - Ignoring TypeScript's static checking for dynamic requires
177
+ const pluginModule = require ( pluginName ) ;
178
+ const plugin = pluginModule . default || pluginModule . localAIPlugin ;
179
+
180
+ if ( plugin ) {
181
+ await runtime . registerPlugin ( plugin ) ;
182
+ logger . success ( "Successfully loaded local-ai plugin for embeddings" ) ;
183
+ } else {
184
+ logger . warn ( `Could not find a valid plugin export in ${ pluginName } ` ) ;
185
+ }
186
+ } catch ( error ) {
187
+ logger . warn ( `Failed to import local-ai plugin: ${ error } ` ) ;
188
+ logger . warn ( `You may need to install it with: npm install ${ pluginName } ` ) ;
189
+ }
190
+ } catch ( error ) {
191
+ logger . warn ( `Error loading local-ai plugin: ${ error } ` ) ;
192
+ }
193
+ }
194
+ } else if ( ! embeddingModel && options . isPluginTestMode ) {
195
+ logger . info ( "No TEXT_EMBEDDING model registered, but running in plugin test mode - skipping auto-loading" ) ;
196
+ }
197
+
132
198
// add to container
133
199
server . registerAgent ( runtime ) ;
134
200
@@ -330,9 +396,12 @@ const startAgents = async (options: {
330
396
try {
331
397
// Check if we're in a project with a package.json
332
398
const packageJsonPath = path . join ( process . cwd ( ) , "package.json" ) ;
399
+ logger . debug ( `Checking for package.json at: ${ packageJsonPath } ` ) ;
400
+
333
401
if ( fs . existsSync ( packageJsonPath ) ) {
334
402
// Read and parse package.json to check if it's a project or plugin
335
403
const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , "utf-8" ) ) ;
404
+ logger . debug ( `Found package.json with name: ${ packageJson . name || 'unnamed' } ` ) ;
336
405
337
406
// Check if this is a plugin (package.json contains 'eliza' section with type='plugin')
338
407
if ( packageJson . eliza ?. type && packageJson . eliza . type === "plugin" ) {
@@ -423,6 +492,8 @@ const startAgents = async (options: {
423
492
}
424
493
425
494
// Log what was found
495
+ logger . debug ( `Classification results - isProject: ${ isProject } , isPlugin: ${ isPlugin } ` ) ;
496
+
426
497
if ( isProject ) {
427
498
logger . info ( "Found project configuration" ) ;
428
499
if ( projectModule ?. default ) {
@@ -446,7 +517,9 @@ const startAgents = async (options: {
446
517
} else if ( isPlugin ) {
447
518
logger . info ( `Found plugin: ${ pluginModule ?. name || "unnamed" } ` ) ;
448
519
} else {
449
- logger . info ( "No project or plugin found, will use custom character" ) ;
520
+ // Change the log message to be clearer about what we're doing
521
+ logger . info ( "Running in standalone mode - using default Eliza character" ) ;
522
+ logger . debug ( "Will load the default Eliza character from ../characters/eliza" ) ;
450
523
}
451
524
452
525
// Start agents based on project, plugin, or custom configuration
@@ -521,20 +594,32 @@ const startAgents = async (options: {
521
594
}
522
595
}
523
596
524
- // Load the custom character and add the plugin to it
597
+ // Load the default character with all its default plugins, then add the test plugin
525
598
logger . info (
526
- `Starting custom character with plugin: ${ pluginModule . name || "unnamed plugin" } ` ,
599
+ `Starting default Eliza character with plugin: ${ pluginModule . name || "unnamed plugin" } ` ,
527
600
) ;
528
601
529
- // Create a proper array of plugins, including the explicitly loaded one
602
+ // Import the default character with all its plugins
603
+ const { character : defaultElizaCharacter } = await import ( "../characters/eliza" ) ;
604
+
605
+ // Create an array of plugins, including the explicitly loaded one
606
+ // We're using our test plugin plus all the plugins from the default character
530
607
const pluginsToLoad = [ pluginModule ] ;
531
-
532
- // Start the agent with our custom character and plugins
533
- await startAgent ( customCharacter , server , undefined , pluginsToLoad ) ;
608
+
609
+ logger . debug ( `Using default character with plugins: ${ defaultElizaCharacter . plugins . join ( ", " ) } ` ) ;
610
+ logger . info ( "Plugin test mode: Using default character's plugins plus the plugin being tested" ) ;
611
+
612
+ // Start the agent with the default character and our test plugin
613
+ // We're in plugin test mode, so we should skip auto-loading embedding models
614
+ await startAgent ( defaultElizaCharacter , server , undefined , pluginsToLoad , {
615
+ isPluginTestMode : true
616
+ } ) ;
534
617
logger . info ( "Character started with plugin successfully" ) ;
535
618
} else {
536
- logger . info ( "Starting with custom character" ) ;
537
- await startAgent ( customCharacter , server ) ;
619
+ // When not in a project or plugin, load the default character with all plugins
620
+ const { character : defaultElizaCharacter } = await import ( "../characters/eliza" ) ;
621
+ logger . info ( "Using default Eliza character with all plugins" ) ;
622
+ await startAgent ( defaultElizaCharacter , server ) ;
538
623
}
539
624
540
625
// Rest of the function remains the same...
@@ -555,7 +640,7 @@ const startAgents = async (options: {
555
640
556
641
// If not found, fall back to the old relative path for development
557
642
if ( ! fs . existsSync ( clientPath ) ) {
558
- clientPath = path . join ( __dirname , "../../../../.. " , "packages/ client/dist" ) ;
643
+ clientPath = path . join ( __dirname , "../../../.." , "client/dist" ) ;
559
644
}
560
645
561
646
if ( fs . existsSync ( clientPath ) ) {
@@ -565,8 +650,8 @@ const startAgents = async (options: {
565
650
} else {
566
651
const clientSrcPath = path . join (
567
652
__dirname ,
568
- "../../../.. " ,
569
- "packages/ client" ,
653
+ "../../.." ,
654
+ "client" ,
570
655
) ;
571
656
if ( fs . existsSync ( clientSrcPath ) ) {
572
657
logger . info (
0 commit comments