@elizaos/core 1.6.5-alpha.7 → 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.
@@ -27300,9 +27300,45 @@ var _getFetchImplementation = (debug) => {
27300
27300
  var getDefaultProjectName = () => {
27301
27301
  return getLangSmithEnvironmentVariable("PROJECT") ?? getEnvironmentVariable2("LANGCHAIN_SESSION") ?? "default";
27302
27302
  };
27303
+ // ../../node_modules/langsmith/dist/utils/warn.js
27304
+ var warnedMessages = {};
27305
+ function warnOnce(message) {
27306
+ if (!warnedMessages[message]) {
27307
+ console.warn(message);
27308
+ warnedMessages[message] = true;
27309
+ }
27310
+ }
27303
27311
 
27312
+ // ../../node_modules/langsmith/dist/utils/_uuid.js
27313
+ var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
27314
+ var UUID7_WARNING_EMITTED = false;
27315
+ function assertUuid(str, which) {
27316
+ if (!UUID_REGEX.test(str)) {
27317
+ const msg = which !== undefined ? `Invalid UUID for ${which}: ${str}` : `Invalid UUID: ${str}`;
27318
+ throw new Error(msg);
27319
+ }
27320
+ return str;
27321
+ }
27322
+ function uuid7FromTime(timestamp) {
27323
+ const msecs = typeof timestamp === "string" ? Date.parse(timestamp) : timestamp;
27324
+ return v72({ msecs, seq: 0 });
27325
+ }
27326
+ function getUuidVersion(uuidStr) {
27327
+ if (!UUID_REGEX.test(uuidStr)) {
27328
+ return null;
27329
+ }
27330
+ const versionChar = uuidStr[14];
27331
+ return parseInt(versionChar, 16);
27332
+ }
27333
+ function warnIfNotUuidV7(uuidStr, _idType) {
27334
+ const version3 = getUuidVersion(uuidStr);
27335
+ if (version3 !== null && version3 !== 7 && !UUID7_WARNING_EMITTED) {
27336
+ UUID7_WARNING_EMITTED = true;
27337
+ warnOnce(`LangSmith now uses UUID v7 for run and trace identifiers. ` + `This warning appears when passing custom IDs. ` + `Please use: import { uuidv7 } from 'langsmith'; const id = uuidv7(); ` + `Future versions will require UUID v7.`);
27338
+ }
27339
+ }
27304
27340
  // ../../node_modules/langsmith/dist/index.js
27305
- var __version__ = "0.3.79";
27341
+ var __version__ = "0.3.80";
27306
27342
 
27307
27343
  // ../../node_modules/langsmith/dist/utils/env.js
27308
27344
  var globalEnv;
@@ -27914,6 +27950,12 @@ class AsyncCaller {
27914
27950
  writable: true,
27915
27951
  value: undefined
27916
27952
  });
27953
+ Object.defineProperty(this, "maxQueueSizeBytes", {
27954
+ enumerable: true,
27955
+ configurable: true,
27956
+ writable: true,
27957
+ value: undefined
27958
+ });
27917
27959
  Object.defineProperty(this, "queue", {
27918
27960
  enumerable: true,
27919
27961
  configurable: true,
@@ -27926,8 +27968,15 @@ class AsyncCaller {
27926
27968
  writable: true,
27927
27969
  value: undefined
27928
27970
  });
27971
+ Object.defineProperty(this, "queueSizeBytes", {
27972
+ enumerable: true,
27973
+ configurable: true,
27974
+ writable: true,
27975
+ value: 0
27976
+ });
27929
27977
  this.maxConcurrency = params.maxConcurrency ?? Infinity;
27930
27978
  this.maxRetries = params.maxRetries ?? 6;
27979
+ this.maxQueueSizeBytes = params.maxQueueSizeBytes;
27931
27980
  if ("default" in import_p_queue.default) {
27932
27981
  this.queue = new import_p_queue.default.default({
27933
27982
  concurrency: this.maxConcurrency
@@ -27938,8 +27987,18 @@ class AsyncCaller {
27938
27987
  this.onFailedResponseHook = params?.onFailedResponseHook;
27939
27988
  }
27940
27989
  call(callable, ...args) {
27990
+ return this.callWithOptions({}, callable, ...args);
27991
+ }
27992
+ callWithOptions(options, callable, ...args) {
27993
+ const sizeBytes = options.sizeBytes ?? 0;
27994
+ if (this.maxQueueSizeBytes !== undefined && sizeBytes > 0 && this.queueSizeBytes + sizeBytes > this.maxQueueSizeBytes) {
27995
+ return Promise.reject(new Error(`Queue size limit (${this.maxQueueSizeBytes} bytes) exceeded. ` + `Current queue size: ${this.queueSizeBytes} bytes, attempted addition: ${sizeBytes} bytes.`));
27996
+ }
27997
+ if (sizeBytes > 0) {
27998
+ this.queueSizeBytes += sizeBytes;
27999
+ }
27941
28000
  const onFailedResponseHook = this.onFailedResponseHook;
27942
- return this.queue.add(() => import_p_retry.default(() => callable(...args).catch((error) => {
28001
+ let promise = this.queue.add(() => import_p_retry.default(() => callable(...args).catch((error) => {
27943
28002
  if (error instanceof Error) {
27944
28003
  throw error;
27945
28004
  } else {
@@ -27970,11 +28029,14 @@ class AsyncCaller {
27970
28029
  retries: this.maxRetries,
27971
28030
  randomize: true
27972
28031
  }), { throwOnTimeout: true });
27973
- }
27974
- callWithOptions(options, callable, ...args) {
28032
+ if (sizeBytes > 0) {
28033
+ promise = promise.finally(() => {
28034
+ this.queueSizeBytes -= sizeBytes;
28035
+ });
28036
+ }
27975
28037
  if (options.signal) {
27976
28038
  return Promise.race([
27977
- this.call(callable, ...args),
28039
+ promise,
27978
28040
  new Promise((_, reject) => {
27979
28041
  options.signal?.addEventListener("abort", () => {
27980
28042
  reject(new Error("AbortError"));
@@ -27982,7 +28044,7 @@ class AsyncCaller {
27982
28044
  })
27983
28045
  ]);
27984
28046
  }
27985
- return this.call(callable, ...args);
28047
+ return promise;
27986
28048
  }
27987
28049
  }
27988
28050
 
@@ -28001,25 +28063,6 @@ function convertLangChainMessageToExample(message) {
28001
28063
  return converted;
28002
28064
  }
28003
28065
 
28004
- // ../../node_modules/langsmith/dist/utils/_uuid.js
28005
- var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
28006
- function assertUuid(str, which) {
28007
- if (!UUID_REGEX.test(str)) {
28008
- const msg = which !== undefined ? `Invalid UUID for ${which}: ${str}` : `Invalid UUID: ${str}`;
28009
- throw new Error(msg);
28010
- }
28011
- return str;
28012
- }
28013
-
28014
- // ../../node_modules/langsmith/dist/utils/warn.js
28015
- var warnedMessages = {};
28016
- function warnOnce(message) {
28017
- if (!warnedMessages[message]) {
28018
- console.warn(message);
28019
- warnedMessages[message] = true;
28020
- }
28021
- }
28022
-
28023
28066
  // ../../node_modules/langsmith/dist/utils/prompts.js
28024
28067
  var import_semver = __toESM(require_semver2(), 1);
28025
28068
  function parsePromptIdentifier(identifier) {
@@ -28329,9 +28372,14 @@ function _formatFeedbackScore(score) {
28329
28372
  }
28330
28373
  return score;
28331
28374
  }
28375
+ var DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
28376
+ var DEFAULT_MAX_SIZE_BYTES = 1024 * 1024 * 1024;
28377
+ var SERVER_INFO_REQUEST_TIMEOUT_MS = 1e4;
28378
+ var DEFAULT_BATCH_SIZE_LIMIT = 100;
28379
+ var DEFAULT_API_URL = "https://api.smith.langchain.com";
28332
28380
 
28333
28381
  class AutoBatchQueue {
28334
- constructor() {
28382
+ constructor(maxSizeBytes) {
28335
28383
  Object.defineProperty(this, "items", {
28336
28384
  enumerable: true,
28337
28385
  configurable: true,
@@ -28344,6 +28392,13 @@ class AutoBatchQueue {
28344
28392
  writable: true,
28345
28393
  value: 0
28346
28394
  });
28395
+ Object.defineProperty(this, "maxSizeBytes", {
28396
+ enumerable: true,
28397
+ configurable: true,
28398
+ writable: true,
28399
+ value: undefined
28400
+ });
28401
+ this.maxSizeBytes = maxSizeBytes ?? DEFAULT_MAX_SIZE_BYTES;
28347
28402
  }
28348
28403
  peek() {
28349
28404
  return this.items[0];
@@ -28354,6 +28409,11 @@ class AutoBatchQueue {
28354
28409
  itemPromiseResolve = resolve;
28355
28410
  });
28356
28411
  const size = serialize(item.item, `Serializing run with id: ${item.item.id}`).length;
28412
+ if (this.sizeBytes + size > this.maxSizeBytes && this.items.length > 0) {
28413
+ console.warn(`AutoBatchQueue size limit (${this.maxSizeBytes} bytes) exceeded. Dropping run with id: ${item.item.id}. ` + `Current queue size: ${this.sizeBytes} bytes, attempted addition: ${size} bytes.`);
28414
+ itemPromiseResolve();
28415
+ return itemPromise;
28416
+ }
28357
28417
  this.items.push({
28358
28418
  action: item.action,
28359
28419
  payload: item.item,
@@ -28393,16 +28453,13 @@ class AutoBatchQueue {
28393
28453
  item: it.payload,
28394
28454
  otelContext: it.otelContext,
28395
28455
  apiKey: it.apiKey,
28396
- apiUrl: it.apiUrl
28456
+ apiUrl: it.apiUrl,
28457
+ size: it.size
28397
28458
  })),
28398
28459
  () => popped.forEach((it) => it.itemPromiseResolve())
28399
28460
  ];
28400
28461
  }
28401
28462
  }
28402
- var DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
28403
- var SERVER_INFO_REQUEST_TIMEOUT_MS = 1e4;
28404
- var DEFAULT_BATCH_SIZE_LIMIT = 100;
28405
- var DEFAULT_API_URL = "https://api.smith.langchain.com";
28406
28463
 
28407
28464
  class Client {
28408
28465
  get _fetch() {
@@ -28491,7 +28548,7 @@ class Client {
28491
28548
  enumerable: true,
28492
28549
  configurable: true,
28493
28550
  writable: true,
28494
- value: new AutoBatchQueue
28551
+ value: undefined
28495
28552
  });
28496
28553
  Object.defineProperty(this, "autoBatchTimeout", {
28497
28554
  enumerable: true,
@@ -28613,9 +28670,11 @@ class Client {
28613
28670
  }
28614
28671
  this.debug = config.debug ?? this.debug;
28615
28672
  this.fetchImplementation = config.fetchImplementation;
28673
+ const maxMemory = config.maxIngestMemoryBytes ?? DEFAULT_MAX_SIZE_BYTES;
28616
28674
  this.batchIngestCaller = new AsyncCaller({
28617
- maxRetries: 2,
28675
+ maxRetries: 4,
28618
28676
  maxConcurrency: this.traceBatchConcurrency,
28677
+ maxQueueSizeBytes: maxMemory,
28619
28678
  ...config.callerOptions ?? {},
28620
28679
  onFailedResponseHook: handle429,
28621
28680
  debug: config.debug ?? this.debug
@@ -28623,6 +28682,7 @@ class Client {
28623
28682
  this.hideInputs = config.hideInputs ?? config.anonymizer ?? defaultConfig.hideInputs;
28624
28683
  this.hideOutputs = config.hideOutputs ?? config.anonymizer ?? defaultConfig.hideOutputs;
28625
28684
  this.autoBatchTracing = config.autoBatchTracing ?? this.autoBatchTracing;
28685
+ this.autoBatchQueue = new AutoBatchQueue(maxMemory);
28626
28686
  this.blockOnRootRunFinalization = config.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization;
28627
28687
  this.batchSizeBytesLimit = config.batchSizeBytesLimit;
28628
28688
  this.batchSizeLimit = config.batchSizeLimit;
@@ -28893,6 +28953,7 @@ class Client {
28893
28953
  if (!batch.length) {
28894
28954
  return;
28895
28955
  }
28956
+ const batchSizeBytes = batch.reduce((sum, item) => sum + (item.size ?? 0), 0);
28896
28957
  try {
28897
28958
  if (this.langSmithToOTELTranslator !== undefined) {
28898
28959
  this._sendBatchToOTELTranslator(batch);
@@ -28904,9 +28965,16 @@ class Client {
28904
28965
  const serverInfo = await this._ensureServerInfo();
28905
28966
  if (serverInfo?.batch_ingest_config?.use_multipart_endpoint) {
28906
28967
  const useGzip = serverInfo?.instance_flags?.gzip_body_enabled;
28907
- await this.multipartIngestRuns(ingestParams, { ...options, useGzip });
28968
+ await this.multipartIngestRuns(ingestParams, {
28969
+ ...options,
28970
+ useGzip,
28971
+ sizeBytes: batchSizeBytes
28972
+ });
28908
28973
  } else {
28909
- await this.batchIngestRuns(ingestParams, options);
28974
+ await this.batchIngestRuns(ingestParams, {
28975
+ ...options,
28976
+ sizeBytes: batchSizeBytes
28977
+ });
28910
28978
  }
28911
28979
  }
28912
28980
  } catch (e) {
@@ -29140,7 +29208,7 @@ class Client {
29140
29208
  if (options?.apiKey !== undefined) {
29141
29209
  headers["x-api-key"] = options.apiKey;
29142
29210
  }
29143
- await this.batchIngestCaller.call(async () => {
29211
+ await this.batchIngestCaller.callWithOptions({ sizeBytes: options?.sizeBytes }, async () => {
29144
29212
  const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/batch`, {
29145
29213
  method: "POST",
29146
29214
  headers,
@@ -29333,7 +29401,7 @@ class Client {
29333
29401
  const buildBuffered = () => this._createNodeFetchBody(parts, boundary);
29334
29402
  const buildStream = () => this._createMultipartStream(parts, boundary);
29335
29403
  const sendWithRetry = async (bodyFactory) => {
29336
- return this.batchIngestCaller.call(async () => {
29404
+ return this.batchIngestCaller.callWithOptions({ sizeBytes: options?.sizeBytes }, async () => {
29337
29405
  const body = await bodyFactory();
29338
29406
  const headers = {
29339
29407
  ...this.headers,
@@ -31570,9 +31638,12 @@ var _LC_CONTEXT_VARIABLES_KEY = Symbol.for("lc:context_variables");
31570
31638
  function stripNonAlphanumeric(input) {
31571
31639
  return input.replace(/[-:.]/g, "");
31572
31640
  }
31573
- function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
31641
+ function getMicrosecondPrecisionDatestring(epoch, executionOrder = 1) {
31574
31642
  const paddedOrder = executionOrder.toFixed(0).slice(0, 3).padStart(3, "0");
31575
- const microsecondPrecisionDatestring = `${new Date(epoch).toISOString().slice(0, -1)}${paddedOrder}Z`;
31643
+ return `${new Date(epoch).toISOString().slice(0, -1)}${paddedOrder}Z`;
31644
+ }
31645
+ function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
31646
+ const microsecondPrecisionDatestring = getMicrosecondPrecisionDatestring(epoch, executionOrder);
31576
31647
  return {
31577
31648
  dottedOrder: stripNonAlphanumeric(microsecondPrecisionDatestring) + runId,
31578
31649
  microsecondPrecisionDatestring
@@ -31820,24 +31891,37 @@ class RunTree {
31820
31891
  delete config.id;
31821
31892
  }
31822
31893
  Object.assign(this, { ...defaultConfig, ...config, client });
31894
+ this.execution_order ??= 1;
31895
+ this.child_execution_order ??= 1;
31896
+ if (!this.dotted_order) {
31897
+ this._serialized_start_time = getMicrosecondPrecisionDatestring(this.start_time, this.execution_order);
31898
+ }
31899
+ if (!this.id) {
31900
+ this.id = uuid7FromTime(this._serialized_start_time ?? this.start_time);
31901
+ }
31902
+ if (config.id) {
31903
+ warnIfNotUuidV7(config.id, "run_id");
31904
+ }
31823
31905
  if (!this.trace_id) {
31824
31906
  if (this.parent_run) {
31825
31907
  this.trace_id = this.parent_run.trace_id ?? this.id;
31826
31908
  } else {
31827
31909
  this.trace_id = this.id;
31828
31910
  }
31911
+ } else if (config.trace_id) {
31912
+ warnIfNotUuidV7(config.trace_id, "trace_id");
31913
+ }
31914
+ if (config.parent_run_id) {
31915
+ warnIfNotUuidV7(config.parent_run_id, "parent_run_id");
31829
31916
  }
31830
31917
  this.replicas = _ensureWriteReplicas(this.replicas);
31831
- this.execution_order ??= 1;
31832
- this.child_execution_order ??= 1;
31833
31918
  if (!this.dotted_order) {
31834
- const { dottedOrder, microsecondPrecisionDatestring } = convertToDottedOrderFormat(this.start_time, this.id, this.execution_order);
31919
+ const { dottedOrder } = convertToDottedOrderFormat(this.start_time, this.id, this.execution_order);
31835
31920
  if (this.parent_run) {
31836
31921
  this.dotted_order = this.parent_run.dotted_order + "." + dottedOrder;
31837
31922
  } else {
31838
31923
  this.dotted_order = dottedOrder;
31839
31924
  }
31840
- this._serialized_start_time = microsecondPrecisionDatestring;
31841
31925
  }
31842
31926
  }
31843
31927
  set metadata(metadata) {
@@ -31853,15 +31937,15 @@ class RunTree {
31853
31937
  return this.extra?.metadata;
31854
31938
  }
31855
31939
  static getDefaultConfig() {
31940
+ const start_time = Date.now();
31856
31941
  return {
31857
- id: v42(),
31858
31942
  run_type: "chain",
31859
31943
  project_name: getDefaultProjectName(),
31860
31944
  child_runs: [],
31861
31945
  api_url: getEnvironmentVariable2("LANGCHAIN_ENDPOINT") ?? "http://localhost:1984",
31862
31946
  api_key: getEnvironmentVariable2("LANGCHAIN_API_KEY"),
31863
31947
  caller_options: {},
31864
- start_time: Date.now(),
31948
+ start_time,
31865
31949
  serialized: {},
31866
31950
  inputs: {},
31867
31951
  extra: {}
@@ -31965,39 +32049,10 @@ class RunTree {
31965
32049
  }
31966
32050
  _remapForProject(projectName, runtimeEnv, excludeChildRuns = true) {
31967
32051
  const baseRun = this._convertToCreate(this, runtimeEnv, excludeChildRuns);
31968
- if (projectName === this.project_name) {
31969
- return baseRun;
31970
- }
31971
- const createRemappedId = (originalId) => {
31972
- return v52(`${originalId}:${projectName}`, v52.DNS);
31973
- };
31974
- const newId = createRemappedId(baseRun.id);
31975
- const newTraceId = baseRun.trace_id ? createRemappedId(baseRun.trace_id) : undefined;
31976
- const newParentRunId = baseRun.parent_run_id ? createRemappedId(baseRun.parent_run_id) : undefined;
31977
- let newDottedOrder;
31978
- if (baseRun.dotted_order) {
31979
- const segments = _parseDottedOrder(baseRun.dotted_order);
31980
- const rebuilt = [];
31981
- for (let i = 0;i < segments.length - 1; i++) {
31982
- const [timestamp, segmentId] = segments[i];
31983
- const remappedId = createRemappedId(segmentId);
31984
- rebuilt.push(timestamp.toISOString().replace(/[-:]/g, "").replace(".", "") + remappedId);
31985
- }
31986
- const [lastTimestamp] = segments[segments.length - 1];
31987
- rebuilt.push(lastTimestamp.toISOString().replace(/[-:]/g, "").replace(".", "") + newId);
31988
- newDottedOrder = rebuilt.join(".");
31989
- } else {
31990
- newDottedOrder = undefined;
31991
- }
31992
- const remappedRun = {
32052
+ return {
31993
32053
  ...baseRun,
31994
- id: newId,
31995
- trace_id: newTraceId,
31996
- parent_run_id: newParentRunId,
31997
- dotted_order: newDottedOrder,
31998
32054
  session_name: projectName
31999
32055
  };
32000
- return remappedRun;
32001
32056
  }
32002
32057
  async postRun(excludeChildRuns = true) {
32003
32058
  try {
@@ -32031,6 +32086,9 @@ class RunTree {
32031
32086
  const runData = this._remapForProject(projectName ?? this.project_name);
32032
32087
  const updatePayload = {
32033
32088
  id: runData.id,
32089
+ name: runData.name,
32090
+ run_type: runData.run_type,
32091
+ start_time: runData.start_time,
32034
32092
  outputs: runData.outputs,
32035
32093
  error: runData.error,
32036
32094
  parent_run_id: runData.parent_run_id,
@@ -32057,6 +32115,9 @@ class RunTree {
32057
32115
  } else {
32058
32116
  try {
32059
32117
  const runUpdate = {
32118
+ name: this.name,
32119
+ run_type: this.run_type,
32120
+ start_time: this._serialized_start_time ?? this.start_time,
32060
32121
  end_time: this.end_time,
32061
32122
  error: this.error,
32062
32123
  outputs: this.outputs,
@@ -32210,22 +32271,6 @@ function isCallbackManagerLike(x) {
32210
32271
  function isRunnableConfigLike(x) {
32211
32272
  return x != null && typeof x.callbacks === "object" && (containsLangChainTracerLike(x.callbacks?.handlers) || containsLangChainTracerLike(x.callbacks));
32212
32273
  }
32213
- function _parseDottedOrder(dottedOrder) {
32214
- const parts = dottedOrder.split(".");
32215
- return parts.map((part) => {
32216
- const timestampStr = part.slice(0, -36);
32217
- const uuidStr = part.slice(-36);
32218
- const year = parseInt(timestampStr.slice(0, 4));
32219
- const month = parseInt(timestampStr.slice(4, 6)) - 1;
32220
- const day = parseInt(timestampStr.slice(6, 8));
32221
- const hour = parseInt(timestampStr.slice(9, 11));
32222
- const minute = parseInt(timestampStr.slice(11, 13));
32223
- const second = parseInt(timestampStr.slice(13, 15));
32224
- const microsecond = parseInt(timestampStr.slice(15, 21));
32225
- const timestamp = new Date(year, month, day, hour, minute, second, microsecond / 1000);
32226
- return [timestamp, uuidStr];
32227
- });
32228
- }
32229
32274
  function _getWriteReplicasFromEnv() {
32230
32275
  const envVar = getEnvironmentVariable2("LANGSMITH_RUNS_ENDPOINTS");
32231
32276
  if (!envVar)
@@ -33790,7 +33835,9 @@ function patchConfig(config = {}, { callbacks, maxConcurrency, recursionLimit, r
33790
33835
  return newConfig;
33791
33836
  }
33792
33837
  function pickRunnableConfigKeys(config) {
33793
- return config ? {
33838
+ if (!config)
33839
+ return;
33840
+ return {
33794
33841
  configurable: config.configurable,
33795
33842
  recursionLimit: config.recursionLimit,
33796
33843
  callbacks: config.callbacks,
@@ -33798,8 +33845,9 @@ function pickRunnableConfigKeys(config) {
33798
33845
  metadata: config.metadata,
33799
33846
  maxConcurrency: config.maxConcurrency,
33800
33847
  timeout: config.timeout,
33801
- signal: config.signal
33802
- } : undefined;
33848
+ signal: config.signal,
33849
+ store: config.store
33850
+ };
33803
33851
  }
33804
33852
 
33805
33853
  // ../../node_modules/@langchain/core/dist/utils/signal.js
@@ -46098,20 +46146,23 @@ class AgentRuntime {
46098
46146
  }
46099
46147
  if (plugin.services) {
46100
46148
  for (const service of plugin.services) {
46101
- if (!this.servicePromises.has(service.serviceType)) {
46102
- 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);
46103
46154
  }
46104
- this.serviceRegistrationStatus.set(service.serviceType, "pending");
46155
+ this.serviceRegistrationStatus.set(serviceType, "pending");
46105
46156
  this.registerService(service).catch((error) => {
46106
- this.logger.error(`Service registration failed for ${service.serviceType}: ${error instanceof Error ? error.message : String(error)}`);
46107
- 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);
46108
46159
  if (handler) {
46109
- 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)}`);
46110
46161
  handler.reject(serviceError);
46111
- this.servicePromiseHandlers.delete(service.serviceType);
46112
- this.servicePromises.delete(service.serviceType);
46162
+ this.servicePromiseHandlers.delete(serviceType);
46163
+ this.servicePromises.delete(serviceType);
46113
46164
  }
46114
- this.serviceRegistrationStatus.set(service.serviceType, "failed");
46165
+ this.serviceRegistrationStatus.set(serviceType, "failed");
46115
46166
  });
46116
46167
  }
46117
46168
  }
@@ -47161,11 +47212,12 @@ class AgentRuntime {
47161
47212
  }
47162
47213
  async registerService(serviceDef) {
47163
47214
  const serviceType = serviceDef.serviceType;
47215
+ const serviceName = serviceDef.name || "Unknown";
47164
47216
  if (!serviceType) {
47165
- 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.`);
47166
47218
  return;
47167
47219
  }
47168
- this.logger.debug(`${this.character.name}(${this.agentId}) - Registering service:`, serviceType);
47220
+ this.logger.info(`Registering service: ${serviceType}`);
47169
47221
  this.serviceRegistrationStatus.set(serviceType, "registering");
47170
47222
  try {
47171
47223
  this.logger.debug(`Service ${serviceType} waiting for initialization...`);
@@ -47175,8 +47227,13 @@ class AgentRuntime {
47175
47227
  }, 30000);
47176
47228
  });
47177
47229
  await Promise.race([this.initPromise, initTimeout]);
47178
- 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
+ }
47179
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
+ }
47180
47237
  if (!this.services.has(serviceType)) {
47181
47238
  this.services.set(serviceType, []);
47182
47239
  }
@@ -47196,14 +47253,26 @@ class AgentRuntime {
47196
47253
  serviceDef.registerSendHandlers(this, serviceInstance);
47197
47254
  }
47198
47255
  this.serviceRegistrationStatus.set(serviceType, "registered");
47199
- this.logger.debug(`${this.character.name}(${this.agentId}) - Service ${serviceType} registered successfully`);
47256
+ this.logger.info(`Service ${serviceType} registered successfully`);
47200
47257
  } catch (error) {
47201
47258
  const errorMessage = error instanceof Error ? error.message : String(error);
47202
- 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}`);
47203
47261
  if (error?.message?.includes("timed out waiting for runtime initialization")) {
47204
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
+ }
47205
47268
  } else if (error?.message?.includes("Service") && error?.message?.includes("failed to start")) {
47206
- 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
+ }
47207
47276
  }
47208
47277
  this.serviceRegistrationStatus.set(serviceType, "failed");
47209
47278
  const handler = this.servicePromiseHandlers.get(serviceType);
@@ -47327,8 +47396,25 @@ class AgentRuntime {
47327
47396
  const errorMsg = `No handler found for delegate type: ${modelKey}`;
47328
47397
  throw new Error(errorMsg);
47329
47398
  }
47330
- 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, `
47331
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
+ }
47332
47418
  let modelParams;
47333
47419
  if (params === null || params === undefined || typeof params !== "object" || Array.isArray(params) || BufferUtils.isBuffer(params)) {
47334
47420
  modelParams = params;
@@ -47943,23 +48029,21 @@ async function loadSecretsNodeImpl(character) {
47943
48029
  if (!character.settings) {
47944
48030
  character.settings = {};
47945
48031
  }
47946
- const existingSettings = { ...character.settings };
47947
48032
  const existingSecrets = character.settings.secrets && typeof character.settings.secrets === "object" ? { ...character.settings.secrets } : {};
47948
- character.settings = {
47949
- ...envVars,
47950
- ...existingSettings
47951
- };
47952
48033
  character.settings.secrets = {
47953
48034
  ...envVars,
47954
48035
  ...existingSecrets
47955
48036
  };
47956
48037
  return true;
47957
48038
  }
47958
- async function setDefaultSecretsFromEnv(character) {
48039
+ async function setDefaultSecretsFromEnv(character, options) {
47959
48040
  const env2 = detectEnvironment();
47960
48041
  if (env2 !== "node") {
47961
48042
  return false;
47962
48043
  }
48044
+ if (options?.skipEnvMerge) {
48045
+ return false;
48046
+ }
47963
48047
  return loadSecretsNodeImpl(character);
47964
48048
  }
47965
48049
 
@@ -48445,42 +48529,74 @@ async function loadAndPreparePlugin(pluginName) {
48445
48529
  return null;
48446
48530
  }
48447
48531
  }
48532
+ function normalizePluginName(pluginName) {
48533
+ const scopedMatch = pluginName.match(/^@[^/]+\/plugin-(.+)$/);
48534
+ if (scopedMatch) {
48535
+ return scopedMatch[1];
48536
+ }
48537
+ return pluginName;
48538
+ }
48448
48539
  function resolvePluginDependencies(availablePlugins, isTestMode = false) {
48449
48540
  const resolutionOrder = [];
48450
48541
  const visited = new Set;
48451
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
+ }
48452
48557
  function visit(pluginName) {
48453
- if (!availablePlugins.has(pluginName)) {
48454
- logger.warn(`Plugin dependency "${pluginName}" not found and will be skipped.`);
48455
- 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);
48456
48567
  }
48457
- if (visited.has(pluginName))
48568
+ const canonicalName = plugin.name;
48569
+ if (visited.has(canonicalName))
48458
48570
  return;
48459
- if (visiting.has(pluginName)) {
48460
- logger.error(`Circular dependency detected involving plugin: ${pluginName}`);
48571
+ if (visiting.has(canonicalName)) {
48572
+ logger.error(`Circular dependency detected involving plugin: ${canonicalName}`);
48461
48573
  return;
48462
48574
  }
48463
- visiting.add(pluginName);
48464
- const plugin = availablePlugins.get(pluginName);
48465
- if (plugin) {
48466
- const deps = [...plugin.dependencies || []];
48467
- if (isTestMode) {
48468
- deps.push(...plugin.testDependencies || []);
48469
- }
48470
- for (const dep of deps) {
48471
- visit(dep);
48472
- }
48575
+ visiting.add(canonicalName);
48576
+ const deps = [...plugin.dependencies || []];
48577
+ if (isTestMode) {
48578
+ deps.push(...plugin.testDependencies || []);
48473
48579
  }
48474
- visiting.delete(pluginName);
48475
- visited.add(pluginName);
48476
- resolutionOrder.push(pluginName);
48580
+ for (const dep of deps) {
48581
+ visit(dep);
48582
+ }
48583
+ visiting.delete(canonicalName);
48584
+ visited.add(canonicalName);
48585
+ resolutionOrder.push(canonicalName);
48477
48586
  }
48478
- for (const name of availablePlugins.keys()) {
48479
- if (!visited.has(name)) {
48480
- visit(name);
48587
+ for (const plugin of availablePlugins.values()) {
48588
+ if (!visited.has(plugin.name)) {
48589
+ visit(plugin.name);
48481
48590
  }
48482
48591
  }
48483
- 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));
48484
48600
  logger.info({ plugins: finalPlugins.map((p) => p.name) }, `Final plugins being loaded:`);
48485
48601
  return finalPlugins;
48486
48602
  }
@@ -48495,26 +48611,33 @@ async function loadPlugin(nameOrPlugin) {
48495
48611
  }
48496
48612
  return nameOrPlugin;
48497
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
+ }
48498
48623
  async function resolvePluginsImpl(plugins, isTestMode = false) {
48499
48624
  const pluginMap = new Map;
48500
48625
  const queue2 = [...plugins];
48626
+ const seenDependencies = new Set;
48501
48627
  while (queue2.length > 0) {
48502
48628
  const next = queue2.shift();
48503
48629
  const loaded = await loadPlugin(next);
48504
48630
  if (!loaded)
48505
48631
  continue;
48506
- if (!pluginMap.has(loaded.name)) {
48507
- pluginMap.set(loaded.name, loaded);
48632
+ const canonicalName = loaded.name;
48633
+ if (!pluginMap.has(canonicalName)) {
48634
+ pluginMap.set(canonicalName, loaded);
48508
48635
  for (const depName of loaded.dependencies ?? []) {
48509
- if (!pluginMap.has(depName)) {
48510
- queue2.push(depName);
48511
- }
48636
+ queueDependency(depName, seenDependencies, pluginMap, queue2);
48512
48637
  }
48513
48638
  if (isTestMode) {
48514
48639
  for (const depName of loaded.testDependencies ?? []) {
48515
- if (!pluginMap.has(depName)) {
48516
- queue2.push(depName);
48517
- }
48640
+ queueDependency(depName, seenDependencies, pluginMap, queue2);
48518
48641
  }
48519
48642
  }
48520
48643
  }
@@ -48545,7 +48668,7 @@ class ElizaOS extends EventTarget {
48545
48668
  async addAgents(agents, options) {
48546
48669
  const promises = agents.map(async (agent) => {
48547
48670
  const character = agent.character;
48548
- await setDefaultSecretsFromEnv(character);
48671
+ await setDefaultSecretsFromEnv(character, { skipEnvMerge: options?.isTestMode });
48549
48672
  const resolvedPlugins = agent.plugins ? await resolvePlugins(agent.plugins, options?.isTestMode || false) : [];
48550
48673
  const runtime = new AgentRuntime({
48551
48674
  character,
@@ -49079,6 +49202,7 @@ export {
49079
49202
  parseCharacter,
49080
49203
  parseBooleanFromText2 as parseBooleanFromText,
49081
49204
  parseAndValidateCharacter,
49205
+ normalizePluginName,
49082
49206
  normalizeJsonString,
49083
49207
  multiStepSummaryTemplate,
49084
49208
  multiStepDecisionTemplate,
@@ -49200,5 +49324,5 @@ export {
49200
49324
  AgentRuntime
49201
49325
  };
49202
49326
 
49203
- //# debugId=8BDA0F1B9BD79A0864756E2164756E21
49327
+ //# debugId=14B681AD83723C0164756E2164756E21
49204
49328
  //# sourceMappingURL=index.node.js.map