@elizaos/core 1.6.5-alpha.8 → 1.6.5-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46146,20 +46146,23 @@ class AgentRuntime {
46146
46146
  }
46147
46147
  if (plugin.services) {
46148
46148
  for (const service of plugin.services) {
46149
- if (!this.servicePromises.has(service.serviceType)) {
46150
- this._createServiceResolver(service.serviceType);
46149
+ const serviceType = service.serviceType;
46150
+ const serviceName = service.name || "Unknown";
46151
+ this.logger.debug(`Plugin ${plugin.name} registering service: ${serviceType}`);
46152
+ if (!this.servicePromises.has(serviceType)) {
46153
+ this._createServiceResolver(serviceType);
46151
46154
  }
46152
- this.serviceRegistrationStatus.set(service.serviceType, "pending");
46155
+ this.serviceRegistrationStatus.set(serviceType, "pending");
46153
46156
  this.registerService(service).catch((error) => {
46154
- this.logger.error(`Service registration failed for ${service.serviceType}: ${error instanceof Error ? error.message : String(error)}`);
46155
- const handler = this.servicePromiseHandlers.get(service.serviceType);
46157
+ this.logger.error(`Plugin ${plugin.name} failed to register service ${serviceType}: ${error instanceof Error ? error.message : String(error)}`);
46158
+ const handler = this.servicePromiseHandlers.get(serviceType);
46156
46159
  if (handler) {
46157
- const serviceError = new Error(`Service ${service.serviceType} failed to register: ${error instanceof Error ? error.message : String(error)}`);
46160
+ const serviceError = new Error(`Service ${serviceType} from plugin ${plugin.name} failed to register: ${error instanceof Error ? error.message : String(error)}`);
46158
46161
  handler.reject(serviceError);
46159
- this.servicePromiseHandlers.delete(service.serviceType);
46160
- this.servicePromises.delete(service.serviceType);
46162
+ this.servicePromiseHandlers.delete(serviceType);
46163
+ this.servicePromises.delete(serviceType);
46161
46164
  }
46162
- this.serviceRegistrationStatus.set(service.serviceType, "failed");
46165
+ this.serviceRegistrationStatus.set(serviceType, "failed");
46163
46166
  });
46164
46167
  }
46165
46168
  }
@@ -47209,11 +47212,12 @@ class AgentRuntime {
47209
47212
  }
47210
47213
  async registerService(serviceDef) {
47211
47214
  const serviceType = serviceDef.serviceType;
47215
+ const serviceName = serviceDef.name || "Unknown";
47212
47216
  if (!serviceType) {
47213
- this.logger.warn(`Service ${serviceDef.name} is missing serviceType. Please define a static serviceType property.`);
47217
+ this.logger.warn(`Service ${serviceName} is missing serviceType. Please define a static serviceType property.`);
47214
47218
  return;
47215
47219
  }
47216
- this.logger.debug(`${this.character.name}(${this.agentId}) - Registering service:`, serviceType);
47220
+ this.logger.info(`Registering service: ${serviceType}`);
47217
47221
  this.serviceRegistrationStatus.set(serviceType, "registering");
47218
47222
  try {
47219
47223
  this.logger.debug(`Service ${serviceType} waiting for initialization...`);
@@ -47223,8 +47227,13 @@ class AgentRuntime {
47223
47227
  }, 30000);
47224
47228
  });
47225
47229
  await Promise.race([this.initPromise, initTimeout]);
47226
- this.logger.debug(`Service ${serviceType} proceeding - initialization complete`);
47230
+ if (typeof serviceDef.start !== "function") {
47231
+ throw new Error(`Service ${serviceType} does not have a static start method. All services must implement static async start(runtime: IAgentRuntime): Promise<Service>.`);
47232
+ }
47227
47233
  const serviceInstance = await serviceDef.start(this);
47234
+ if (!serviceInstance) {
47235
+ throw new Error(`Service ${serviceType} start() method returned null or undefined. It must return a Service instance.`);
47236
+ }
47228
47237
  if (!this.services.has(serviceType)) {
47229
47238
  this.services.set(serviceType, []);
47230
47239
  }
@@ -47244,14 +47253,26 @@ class AgentRuntime {
47244
47253
  serviceDef.registerSendHandlers(this, serviceInstance);
47245
47254
  }
47246
47255
  this.serviceRegistrationStatus.set(serviceType, "registered");
47247
- this.logger.debug(`${this.character.name}(${this.agentId}) - Service ${serviceType} registered successfully`);
47256
+ this.logger.info(`Service ${serviceType} registered successfully`);
47248
47257
  } catch (error) {
47249
47258
  const errorMessage = error instanceof Error ? error.message : String(error);
47250
- this.logger.error(`${this.character.name}(${this.agentId}) - Failed to register service ${serviceType}: ${errorMessage}`);
47259
+ const errorStack = error instanceof Error ? error.stack : undefined;
47260
+ this.logger.error(`Failed to register service ${serviceType}: ${errorMessage}`);
47251
47261
  if (error?.message?.includes("timed out waiting for runtime initialization")) {
47252
47262
  this.logger.error(`Service ${serviceType} failed due to runtime initialization timeout. Check if runtime.initialize() is being called and completing successfully.`);
47263
+ } else if (error?.message?.includes("Not implemented")) {
47264
+ this.logger.error(`Service ${serviceType} failed because it does not implement the static start() method. ` + `All services must override the base Service.start() method. ` + `Add: static async start(runtime: IAgentRuntime): Promise<${serviceName}> { return new ${serviceName}(runtime); }`);
47265
+ if (errorStack) {
47266
+ this.logger.debug(`Stack trace: ${errorStack}`);
47267
+ }
47253
47268
  } else if (error?.message?.includes("Service") && error?.message?.includes("failed to start")) {
47254
- this.logger.error(`Service ${serviceType} failed to start. Check service implementation and dependencies.`);
47269
+ this.logger.error(`Service ${serviceType} (${serviceName}) failed to start. Check service implementation and dependencies.`);
47270
+ } else if (error?.message?.includes("does not have a static start method")) {
47271
+ this.logger.error(`Service ${serviceType} (${serviceName}) is missing required static start() method implementation.`);
47272
+ } else {
47273
+ if (errorStack) {
47274
+ this.logger.debug(`Service ${serviceType} (${serviceName}) error stack: ${errorStack}`);
47275
+ }
47255
47276
  }
47256
47277
  this.serviceRegistrationStatus.set(serviceType, "failed");
47257
47278
  const handler = this.servicePromiseHandlers.get(serviceType);
@@ -47375,8 +47396,25 @@ class AgentRuntime {
47375
47396
  const errorMsg = `No handler found for delegate type: ${modelKey}`;
47376
47397
  throw new Error(errorMsg);
47377
47398
  }
47378
- this.logger.debug(`[useModel] ${modelKey} input: ` + JSON.stringify(params, safeReplacer(), 2).replace(/\\n/g, `
47399
+ const binaryModels = [ModelType.TRANSCRIPTION, ModelType.IMAGE, ModelType.AUDIO, ModelType.VIDEO];
47400
+ if (!binaryModels.includes(modelKey)) {
47401
+ this.logger.debug(`[useModel] ${modelKey} input: ` + JSON.stringify(params, safeReplacer(), 2).replace(/\\n/g, `
47379
47402
  `));
47403
+ } else {
47404
+ let sizeInfo = "unknown size";
47405
+ if (Buffer.isBuffer(params)) {
47406
+ sizeInfo = `${params.length} bytes`;
47407
+ } else if (typeof Blob !== "undefined" && params instanceof Blob) {
47408
+ sizeInfo = `${params.size} bytes`;
47409
+ } else if (typeof params === "object" && params !== null) {
47410
+ if ("audio" in params && Buffer.isBuffer(params.audio)) {
47411
+ sizeInfo = `${params.audio.length} bytes`;
47412
+ } else if ("audio" in params && typeof Blob !== "undefined" && params.audio instanceof Blob) {
47413
+ sizeInfo = `${params.audio.size} bytes`;
47414
+ }
47415
+ }
47416
+ this.logger.debug(`[useModel] ${modelKey} input: <binary data: ${sizeInfo}>`);
47417
+ }
47380
47418
  let modelParams;
47381
47419
  if (params === null || params === undefined || typeof params !== "object" || Array.isArray(params) || BufferUtils.isBuffer(params)) {
47382
47420
  modelParams = params;
@@ -48491,42 +48529,74 @@ async function loadAndPreparePlugin(pluginName) {
48491
48529
  return null;
48492
48530
  }
48493
48531
  }
48532
+ function normalizePluginName(pluginName) {
48533
+ const scopedMatch = pluginName.match(/^@[^/]+\/plugin-(.+)$/);
48534
+ if (scopedMatch) {
48535
+ return scopedMatch[1];
48536
+ }
48537
+ return pluginName;
48538
+ }
48494
48539
  function resolvePluginDependencies(availablePlugins, isTestMode = false) {
48495
48540
  const resolutionOrder = [];
48496
48541
  const visited = new Set;
48497
48542
  const visiting = new Set;
48543
+ const lookupMap = new Map;
48544
+ for (const [key, plugin] of availablePlugins.entries()) {
48545
+ lookupMap.set(key, plugin);
48546
+ if (plugin.name !== key) {
48547
+ lookupMap.set(plugin.name, plugin);
48548
+ }
48549
+ if (!plugin.name.startsWith("@")) {
48550
+ lookupMap.set(`@elizaos/plugin-${plugin.name}`, plugin);
48551
+ }
48552
+ const normalizedKey = normalizePluginName(key);
48553
+ if (normalizedKey !== key) {
48554
+ lookupMap.set(normalizedKey, plugin);
48555
+ }
48556
+ }
48498
48557
  function visit(pluginName) {
48499
- if (!availablePlugins.has(pluginName)) {
48500
- logger.warn(`Plugin dependency "${pluginName}" not found and will be skipped.`);
48501
- return;
48558
+ const plugin = lookupMap.get(pluginName);
48559
+ if (!plugin) {
48560
+ const normalizedName = normalizePluginName(pluginName);
48561
+ const pluginByNormalized = lookupMap.get(normalizedName);
48562
+ if (!pluginByNormalized) {
48563
+ logger.warn(`Plugin dependency "${pluginName}" not found and will be skipped.`);
48564
+ return;
48565
+ }
48566
+ return visit(pluginByNormalized.name);
48502
48567
  }
48503
- if (visited.has(pluginName))
48568
+ const canonicalName = plugin.name;
48569
+ if (visited.has(canonicalName))
48504
48570
  return;
48505
- if (visiting.has(pluginName)) {
48506
- logger.error(`Circular dependency detected involving plugin: ${pluginName}`);
48571
+ if (visiting.has(canonicalName)) {
48572
+ logger.error(`Circular dependency detected involving plugin: ${canonicalName}`);
48507
48573
  return;
48508
48574
  }
48509
- visiting.add(pluginName);
48510
- const plugin = availablePlugins.get(pluginName);
48511
- if (plugin) {
48512
- const deps = [...plugin.dependencies || []];
48513
- if (isTestMode) {
48514
- deps.push(...plugin.testDependencies || []);
48515
- }
48516
- for (const dep of deps) {
48517
- visit(dep);
48518
- }
48575
+ visiting.add(canonicalName);
48576
+ const deps = [...plugin.dependencies || []];
48577
+ if (isTestMode) {
48578
+ deps.push(...plugin.testDependencies || []);
48579
+ }
48580
+ for (const dep of deps) {
48581
+ visit(dep);
48519
48582
  }
48520
- visiting.delete(pluginName);
48521
- visited.add(pluginName);
48522
- resolutionOrder.push(pluginName);
48583
+ visiting.delete(canonicalName);
48584
+ visited.add(canonicalName);
48585
+ resolutionOrder.push(canonicalName);
48523
48586
  }
48524
- for (const name of availablePlugins.keys()) {
48525
- if (!visited.has(name)) {
48526
- visit(name);
48587
+ for (const plugin of availablePlugins.values()) {
48588
+ if (!visited.has(plugin.name)) {
48589
+ visit(plugin.name);
48527
48590
  }
48528
48591
  }
48529
- const finalPlugins = resolutionOrder.map((name) => availablePlugins.get(name)).filter((p) => Boolean(p));
48592
+ const finalPlugins = resolutionOrder.map((name) => {
48593
+ for (const plugin of availablePlugins.values()) {
48594
+ if (plugin.name === name) {
48595
+ return plugin;
48596
+ }
48597
+ }
48598
+ return null;
48599
+ }).filter((p) => Boolean(p));
48530
48600
  logger.info({ plugins: finalPlugins.map((p) => p.name) }, `Final plugins being loaded:`);
48531
48601
  return finalPlugins;
48532
48602
  }
@@ -48541,26 +48611,33 @@ async function loadPlugin(nameOrPlugin) {
48541
48611
  }
48542
48612
  return nameOrPlugin;
48543
48613
  }
48614
+ function queueDependency(depName, seenDependencies, pluginMap, queue2) {
48615
+ const normalizedDepName = normalizePluginName(depName);
48616
+ const alreadyQueued = seenDependencies.has(depName) || seenDependencies.has(normalizedDepName) || Array.from(pluginMap.keys()).some((key) => normalizePluginName(key) === normalizedDepName) || Array.from(pluginMap.values()).some((p) => normalizePluginName(p.name) === normalizedDepName || p.name === depName || p.name === normalizedDepName);
48617
+ if (!alreadyQueued) {
48618
+ seenDependencies.add(depName);
48619
+ seenDependencies.add(normalizedDepName);
48620
+ queue2.push(depName);
48621
+ }
48622
+ }
48544
48623
  async function resolvePluginsImpl(plugins, isTestMode = false) {
48545
48624
  const pluginMap = new Map;
48546
48625
  const queue2 = [...plugins];
48626
+ const seenDependencies = new Set;
48547
48627
  while (queue2.length > 0) {
48548
48628
  const next = queue2.shift();
48549
48629
  const loaded = await loadPlugin(next);
48550
48630
  if (!loaded)
48551
48631
  continue;
48552
- if (!pluginMap.has(loaded.name)) {
48553
- pluginMap.set(loaded.name, loaded);
48632
+ const canonicalName = loaded.name;
48633
+ if (!pluginMap.has(canonicalName)) {
48634
+ pluginMap.set(canonicalName, loaded);
48554
48635
  for (const depName of loaded.dependencies ?? []) {
48555
- if (!pluginMap.has(depName)) {
48556
- queue2.push(depName);
48557
- }
48636
+ queueDependency(depName, seenDependencies, pluginMap, queue2);
48558
48637
  }
48559
48638
  if (isTestMode) {
48560
48639
  for (const depName of loaded.testDependencies ?? []) {
48561
- if (!pluginMap.has(depName)) {
48562
- queue2.push(depName);
48563
- }
48640
+ queueDependency(depName, seenDependencies, pluginMap, queue2);
48564
48641
  }
48565
48642
  }
48566
48643
  }
@@ -49125,6 +49202,7 @@ export {
49125
49202
  parseCharacter,
49126
49203
  parseBooleanFromText2 as parseBooleanFromText,
49127
49204
  parseAndValidateCharacter,
49205
+ normalizePluginName,
49128
49206
  normalizeJsonString,
49129
49207
  multiStepSummaryTemplate,
49130
49208
  multiStepDecisionTemplate,
@@ -49246,5 +49324,5 @@ export {
49246
49324
  AgentRuntime
49247
49325
  };
49248
49326
 
49249
- //# debugId=E31A2F74693DFF0064756E2164756E21
49327
+ //# debugId=14B681AD83723C0164756E2164756E21
49250
49328
  //# sourceMappingURL=index.node.js.map