@elizaos/core 1.6.2-alpha.10 → 1.6.2-alpha.12

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.
@@ -25,6 +25,7 @@ var __export = (target, all) => {
25
25
  set: (newValue) => all[name] = () => newValue
26
26
  });
27
27
  };
28
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
28
29
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
29
30
 
30
31
  // ../../node_modules/retry/lib/retry_operation.js
@@ -2291,6 +2292,9 @@ var require_parse_options = __commonJS((exports, module) => {
2291
2292
  var require_identifiers = __commonJS((exports, module) => {
2292
2293
  var numeric = /^[0-9]+$/;
2293
2294
  var compareIdentifiers = (a, b) => {
2295
+ if (typeof a === "number" && typeof b === "number") {
2296
+ return a === b ? 0 : a < b ? -1 : 1;
2297
+ }
2294
2298
  const anum = numeric.test(a);
2295
2299
  const bnum = numeric.test(b);
2296
2300
  if (anum && bnum) {
@@ -2393,7 +2397,25 @@ var require_semver = __commonJS((exports, module) => {
2393
2397
  if (!(other instanceof SemVer)) {
2394
2398
  other = new SemVer(other, this.options);
2395
2399
  }
2396
- return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
2400
+ if (this.major < other.major) {
2401
+ return -1;
2402
+ }
2403
+ if (this.major > other.major) {
2404
+ return 1;
2405
+ }
2406
+ if (this.minor < other.minor) {
2407
+ return -1;
2408
+ }
2409
+ if (this.minor > other.minor) {
2410
+ return 1;
2411
+ }
2412
+ if (this.patch < other.patch) {
2413
+ return -1;
2414
+ }
2415
+ if (this.patch > other.patch) {
2416
+ return 1;
2417
+ }
2418
+ return 0;
2397
2419
  }
2398
2420
  comparePre(other) {
2399
2421
  if (!(other instanceof SemVer)) {
@@ -3070,6 +3092,7 @@ var require_range = __commonJS((exports, module) => {
3070
3092
  return result;
3071
3093
  };
3072
3094
  var parseComparator = (comp, options) => {
3095
+ comp = comp.replace(re[t.BUILD], "");
3073
3096
  debug("comp", comp, options);
3074
3097
  comp = replaceCarets(comp, options);
3075
3098
  debug("caret", comp);
@@ -9811,6 +9834,220 @@ Length provided: ${this.length}. Number of dictionaries provided: ${this.diction
9811
9834
  };
9812
9835
  });
9813
9836
 
9837
+ // src/utils/environment.ts
9838
+ var exports_environment = {};
9839
+ __export(exports_environment, {
9840
+ setEnv: () => setEnv,
9841
+ loadEnvConfig: () => loadEnvConfig,
9842
+ initBrowserEnvironment: () => initBrowserEnvironment,
9843
+ hasEnv: () => hasEnv,
9844
+ getNumberEnv: () => getNumberEnv,
9845
+ getEnvironment: () => getEnvironment,
9846
+ getEnv: () => getEnv3,
9847
+ getBooleanEnv: () => getBooleanEnv,
9848
+ findEnvFile: () => findEnvFile,
9849
+ detectEnvironment: () => detectEnvironment,
9850
+ currentRuntime: () => currentRuntime,
9851
+ Environment: () => Environment
9852
+ });
9853
+ function detectEnvironment() {
9854
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
9855
+ return "node";
9856
+ }
9857
+ if (typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined" && typeof globalThis.window.document !== "undefined") {
9858
+ return "browser";
9859
+ }
9860
+ return "unknown";
9861
+ }
9862
+
9863
+ class BrowserEnvironmentStore {
9864
+ store = {};
9865
+ constructor() {
9866
+ if (typeof globalThis !== "undefined" && globalThis.window && globalThis.window.ENV) {
9867
+ this.store = { ...globalThis.window.ENV };
9868
+ }
9869
+ if (typeof globalThis !== "undefined" && globalThis.__ENV__) {
9870
+ this.store = { ...this.store, ...globalThis.__ENV__ };
9871
+ }
9872
+ }
9873
+ get(key) {
9874
+ const value = this.store[key];
9875
+ return value !== undefined ? String(value) : undefined;
9876
+ }
9877
+ set(key, value) {
9878
+ this.store[key] = value;
9879
+ }
9880
+ has(key) {
9881
+ return key in this.store;
9882
+ }
9883
+ getAll() {
9884
+ return { ...this.store };
9885
+ }
9886
+ }
9887
+
9888
+ class Environment {
9889
+ runtime;
9890
+ browserStore;
9891
+ cache = new Map;
9892
+ constructor() {
9893
+ this.runtime = detectEnvironment();
9894
+ if (this.runtime === "browser") {
9895
+ this.browserStore = new BrowserEnvironmentStore;
9896
+ }
9897
+ }
9898
+ getRuntime() {
9899
+ return this.runtime;
9900
+ }
9901
+ isNode() {
9902
+ return this.runtime === "node";
9903
+ }
9904
+ isBrowser() {
9905
+ return this.runtime === "browser";
9906
+ }
9907
+ get(key, defaultValue) {
9908
+ if (this.cache.has(key)) {
9909
+ const cached = this.cache.get(key);
9910
+ return cached === undefined && defaultValue !== undefined ? defaultValue : cached;
9911
+ }
9912
+ let value;
9913
+ switch (this.runtime) {
9914
+ case "node":
9915
+ if (typeof process !== "undefined" && process.env) {
9916
+ value = process.env[key];
9917
+ }
9918
+ break;
9919
+ case "browser":
9920
+ if (this.browserStore) {
9921
+ value = this.browserStore.get(key);
9922
+ }
9923
+ break;
9924
+ default:
9925
+ value = undefined;
9926
+ }
9927
+ this.cache.set(key, value);
9928
+ return value === undefined && defaultValue !== undefined ? defaultValue : value;
9929
+ }
9930
+ set(key, value) {
9931
+ const stringValue = String(value);
9932
+ this.cache.delete(key);
9933
+ switch (this.runtime) {
9934
+ case "node":
9935
+ if (typeof process !== "undefined" && process.env) {
9936
+ process.env[key] = stringValue;
9937
+ }
9938
+ break;
9939
+ case "browser":
9940
+ if (this.browserStore) {
9941
+ this.browserStore.set(key, value);
9942
+ }
9943
+ break;
9944
+ }
9945
+ }
9946
+ has(key) {
9947
+ const value = this.get(key);
9948
+ return value !== undefined;
9949
+ }
9950
+ getAll() {
9951
+ switch (this.runtime) {
9952
+ case "node":
9953
+ if (typeof process !== "undefined" && process.env) {
9954
+ return { ...process.env };
9955
+ }
9956
+ break;
9957
+ case "browser":
9958
+ if (this.browserStore) {
9959
+ return this.browserStore.getAll();
9960
+ }
9961
+ break;
9962
+ }
9963
+ return {};
9964
+ }
9965
+ getBoolean(key, defaultValue = false) {
9966
+ const value = this.get(key);
9967
+ if (value === undefined) {
9968
+ return defaultValue;
9969
+ }
9970
+ return ["true", "1", "yes", "on"].includes(value.toLowerCase());
9971
+ }
9972
+ getNumber(key, defaultValue) {
9973
+ const value = this.get(key);
9974
+ if (value === undefined) {
9975
+ return defaultValue;
9976
+ }
9977
+ const parsed = Number(value);
9978
+ return isNaN(parsed) ? defaultValue : parsed;
9979
+ }
9980
+ clearCache() {
9981
+ this.cache.clear();
9982
+ }
9983
+ }
9984
+ function getEnvironment() {
9985
+ if (!environmentInstance) {
9986
+ environmentInstance = new Environment;
9987
+ }
9988
+ return environmentInstance;
9989
+ }
9990
+ function getEnv3(key, defaultValue) {
9991
+ return getEnvironment().get(key, defaultValue);
9992
+ }
9993
+ function setEnv(key, value) {
9994
+ getEnvironment().set(key, value);
9995
+ }
9996
+ function hasEnv(key) {
9997
+ return getEnvironment().has(key);
9998
+ }
9999
+ function getBooleanEnv(key, defaultValue = false) {
10000
+ return getEnvironment().getBoolean(key, defaultValue);
10001
+ }
10002
+ function getNumberEnv(key, defaultValue) {
10003
+ return getEnvironment().getNumber(key, defaultValue);
10004
+ }
10005
+ function initBrowserEnvironment(config) {
10006
+ const env = getEnvironment();
10007
+ if (env.isBrowser()) {
10008
+ Object.entries(config).forEach(([key, value]) => {
10009
+ if (value !== undefined) {
10010
+ env.set(key, value);
10011
+ }
10012
+ });
10013
+ }
10014
+ }
10015
+ function findEnvFile() {
10016
+ if (typeof process === "undefined" || !process.cwd) {
10017
+ return null;
10018
+ }
10019
+ const fs = __require("node:fs");
10020
+ const path = __require("node:path");
10021
+ const possiblePaths = [
10022
+ path.join(process.cwd(), ".env"),
10023
+ path.join(process.cwd(), ".env.local")
10024
+ ];
10025
+ for (const envPath of possiblePaths) {
10026
+ if (fs.existsSync(envPath)) {
10027
+ return envPath;
10028
+ }
10029
+ }
10030
+ return null;
10031
+ }
10032
+ async function loadEnvConfig(envPath) {
10033
+ if (typeof process === "undefined" || !process.cwd) {
10034
+ return {};
10035
+ }
10036
+ const dotenv = __require("dotenv");
10037
+ const resolvedPath = envPath || findEnvFile();
10038
+ if (resolvedPath) {
10039
+ const result = dotenv.config({ path: resolvedPath });
10040
+ if (result.error) {
10041
+ throw result.error;
10042
+ }
10043
+ }
10044
+ return process.env;
10045
+ }
10046
+ var environmentInstance = null, currentRuntime;
10047
+ var init_environment = __esm(() => {
10048
+ currentRuntime = detectEnvironment();
10049
+ });
10050
+
9814
10051
  // ../../node_modules/picocolors/picocolors.js
9815
10052
  var require_picocolors = __commonJS((exports, module) => {
9816
10053
  var p = process || {};
@@ -10499,24 +10736,6 @@ var require_get_proto = __commonJS((exports, module) => {
10499
10736
  } : null;
10500
10737
  });
10501
10738
 
10502
- // ../../node_modules/async-function/index.js
10503
- var require_async_function = __commonJS((exports, module) => {
10504
- var cached = async function() {}.constructor;
10505
- module.exports = () => cached;
10506
- });
10507
-
10508
- // ../../node_modules/generator-function/index.js
10509
- var require_generator_function = __commonJS((exports, module) => {
10510
- var cached = function* () {}.constructor;
10511
- module.exports = () => cached;
10512
- });
10513
-
10514
- // ../../node_modules/async-generator-function/index.js
10515
- var require_async_generator_function = __commonJS((exports, module) => {
10516
- var cached = async function* () {}.constructor;
10517
- module.exports = () => cached;
10518
- });
10519
-
10520
10739
  // ../../node_modules/hasown/index.js
10521
10740
  var require_hasown = __commonJS((exports, module) => {
10522
10741
  var call = Function.prototype.call;
@@ -10543,6 +10762,12 @@ var require_get_intrinsic = __commonJS((exports, module) => {
10543
10762
  var pow = require_pow();
10544
10763
  var round = require_round();
10545
10764
  var sign = require_sign();
10765
+ var $Function = Function;
10766
+ var getEvalledConstructor = function(expressionSyntax) {
10767
+ try {
10768
+ return $Function('"use strict"; return (' + expressionSyntax + ").constructor;")();
10769
+ } catch (e) {}
10770
+ };
10546
10771
  var $gOPD = require_gopd();
10547
10772
  var $defineProperty = require_es_define_property();
10548
10773
  var throwTypeError = function() {
@@ -10597,7 +10822,7 @@ var require_get_intrinsic = __commonJS((exports, module) => {
10597
10822
  "%Float32Array%": typeof Float32Array === "undefined" ? undefined3 : Float32Array,
10598
10823
  "%Float64Array%": typeof Float64Array === "undefined" ? undefined3 : Float64Array,
10599
10824
  "%FinalizationRegistry%": typeof FinalizationRegistry === "undefined" ? undefined3 : FinalizationRegistry,
10600
- "%Function%": Function,
10825
+ "%Function%": $Function,
10601
10826
  "%GeneratorFunction%": needsEval,
10602
10827
  "%Int8Array%": typeof Int8Array === "undefined" ? undefined3 : Int8Array,
10603
10828
  "%Int16Array%": typeof Int16Array === "undefined" ? undefined3 : Int16Array,
@@ -10660,17 +10885,14 @@ var require_get_intrinsic = __commonJS((exports, module) => {
10660
10885
  }
10661
10886
  }
10662
10887
  var errorProto;
10663
- var getAsyncFunction = require_async_function();
10664
- var getGeneratorFunction = require_generator_function();
10665
- var getAsyncGeneratorFunction = require_async_generator_function();
10666
10888
  var doEval = function doEval(name) {
10667
10889
  var value;
10668
10890
  if (name === "%AsyncFunction%") {
10669
- value = getAsyncFunction() || undefined;
10891
+ value = getEvalledConstructor("async function () {}");
10670
10892
  } else if (name === "%GeneratorFunction%") {
10671
- value = getGeneratorFunction() || undefined;
10893
+ value = getEvalledConstructor("function* () {}");
10672
10894
  } else if (name === "%AsyncGeneratorFunction%") {
10673
- value = getAsyncGeneratorFunction() || undefined;
10895
+ value = getEvalledConstructor("async function* () {}");
10674
10896
  } else if (name === "%AsyncGenerator%") {
10675
10897
  var fn = doEval("%AsyncGeneratorFunction%");
10676
10898
  if (fn) {
@@ -25770,7 +25992,7 @@ var getDefaultProjectName = () => {
25770
25992
  };
25771
25993
 
25772
25994
  // ../../node_modules/langsmith/dist/index.js
25773
- var __version__ = "0.3.71";
25995
+ var __version__ = "0.3.72";
25774
25996
 
25775
25997
  // ../../node_modules/langsmith/dist/utils/env.js
25776
25998
  var globalEnv;
@@ -39079,171 +39301,8 @@ var import_handlebars = __toESM(require_lib(), 1);
39079
39301
  var import_unique_names_generator = __toESM(require_dist4(), 1);
39080
39302
  import { z as z2 } from "zod";
39081
39303
 
39082
- // src/utils/environment.ts
39083
- function detectEnvironment() {
39084
- if (typeof process !== "undefined" && process.versions && process.versions.node) {
39085
- return "node";
39086
- }
39087
- if (typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined" && typeof globalThis.window.document !== "undefined") {
39088
- return "browser";
39089
- }
39090
- return "unknown";
39091
- }
39092
-
39093
- class BrowserEnvironmentStore {
39094
- store = {};
39095
- constructor() {
39096
- if (typeof globalThis !== "undefined" && globalThis.window && globalThis.window.ENV) {
39097
- this.store = { ...globalThis.window.ENV };
39098
- }
39099
- if (typeof globalThis !== "undefined" && globalThis.__ENV__) {
39100
- this.store = { ...this.store, ...globalThis.__ENV__ };
39101
- }
39102
- }
39103
- get(key) {
39104
- const value = this.store[key];
39105
- return value !== undefined ? String(value) : undefined;
39106
- }
39107
- set(key, value) {
39108
- this.store[key] = value;
39109
- }
39110
- has(key) {
39111
- return key in this.store;
39112
- }
39113
- getAll() {
39114
- return { ...this.store };
39115
- }
39116
- }
39117
-
39118
- class Environment {
39119
- runtime;
39120
- browserStore;
39121
- cache = new Map;
39122
- constructor() {
39123
- this.runtime = detectEnvironment();
39124
- if (this.runtime === "browser") {
39125
- this.browserStore = new BrowserEnvironmentStore;
39126
- }
39127
- }
39128
- getRuntime() {
39129
- return this.runtime;
39130
- }
39131
- isNode() {
39132
- return this.runtime === "node";
39133
- }
39134
- isBrowser() {
39135
- return this.runtime === "browser";
39136
- }
39137
- get(key, defaultValue) {
39138
- if (this.cache.has(key)) {
39139
- const cached = this.cache.get(key);
39140
- return cached === undefined && defaultValue !== undefined ? defaultValue : cached;
39141
- }
39142
- let value;
39143
- switch (this.runtime) {
39144
- case "node":
39145
- if (typeof process !== "undefined" && process.env) {
39146
- value = process.env[key];
39147
- }
39148
- break;
39149
- case "browser":
39150
- if (this.browserStore) {
39151
- value = this.browserStore.get(key);
39152
- }
39153
- break;
39154
- default:
39155
- value = undefined;
39156
- }
39157
- this.cache.set(key, value);
39158
- return value === undefined && defaultValue !== undefined ? defaultValue : value;
39159
- }
39160
- set(key, value) {
39161
- const stringValue = String(value);
39162
- this.cache.delete(key);
39163
- switch (this.runtime) {
39164
- case "node":
39165
- if (typeof process !== "undefined" && process.env) {
39166
- process.env[key] = stringValue;
39167
- }
39168
- break;
39169
- case "browser":
39170
- if (this.browserStore) {
39171
- this.browserStore.set(key, value);
39172
- }
39173
- break;
39174
- }
39175
- }
39176
- has(key) {
39177
- const value = this.get(key);
39178
- return value !== undefined;
39179
- }
39180
- getAll() {
39181
- switch (this.runtime) {
39182
- case "node":
39183
- if (typeof process !== "undefined" && process.env) {
39184
- return { ...process.env };
39185
- }
39186
- break;
39187
- case "browser":
39188
- if (this.browserStore) {
39189
- return this.browserStore.getAll();
39190
- }
39191
- break;
39192
- }
39193
- return {};
39194
- }
39195
- getBoolean(key, defaultValue = false) {
39196
- const value = this.get(key);
39197
- if (value === undefined) {
39198
- return defaultValue;
39199
- }
39200
- return ["true", "1", "yes", "on"].includes(value.toLowerCase());
39201
- }
39202
- getNumber(key, defaultValue) {
39203
- const value = this.get(key);
39204
- if (value === undefined) {
39205
- return defaultValue;
39206
- }
39207
- const parsed = Number(value);
39208
- return isNaN(parsed) ? defaultValue : parsed;
39209
- }
39210
- clearCache() {
39211
- this.cache.clear();
39212
- }
39213
- }
39214
- var environmentInstance = null;
39215
- function getEnvironment() {
39216
- if (!environmentInstance) {
39217
- environmentInstance = new Environment;
39218
- }
39219
- return environmentInstance;
39220
- }
39221
- function getEnv3(key, defaultValue) {
39222
- return getEnvironment().get(key, defaultValue);
39223
- }
39224
- function setEnv(key, value) {
39225
- getEnvironment().set(key, value);
39226
- }
39227
- function hasEnv(key) {
39228
- return getEnvironment().has(key);
39229
- }
39230
- function getBooleanEnv(key, defaultValue = false) {
39231
- return getEnvironment().getBoolean(key, defaultValue);
39232
- }
39233
- function getNumberEnv(key, defaultValue) {
39234
- return getEnvironment().getNumber(key, defaultValue);
39235
- }
39236
- function initBrowserEnvironment(config) {
39237
- const env = getEnvironment();
39238
- if (env.isBrowser()) {
39239
- Object.entries(config).forEach(([key, value]) => {
39240
- if (value !== undefined) {
39241
- env.set(key, value);
39242
- }
39243
- });
39244
- }
39245
- }
39246
- var currentRuntime = detectEnvironment();
39304
+ // src/logger.ts
39305
+ init_environment();
39247
39306
  // ../../node_modules/adze/dist/tools.js
39248
39307
  class Tools {
39249
39308
  globalStore;
@@ -41379,6 +41438,7 @@ var recentLogs = () => globalInMemoryDestination.recentLogs();
41379
41438
  var logger_default = logger;
41380
41439
 
41381
41440
  // src/utils.ts
41441
+ init_environment();
41382
41442
  function upgradeDoubleToTriple(tpl) {
41383
41443
  return tpl.replace(/(?<!{){{(?![{#\/!>])([\s\S]*?)}}/g, (_match, inner) => {
41384
41444
  if (inner.trim() === "else")
@@ -42090,6 +42150,10 @@ function parseAndValidateCharacter(jsonString) {
42090
42150
  function isValidCharacter(data2) {
42091
42151
  return validateCharacter(data2).success;
42092
42152
  }
42153
+
42154
+ // src/index.node.ts
42155
+ init_environment();
42156
+
42093
42157
  // src/utils/buffer.ts
42094
42158
  function hasNativeBuffer() {
42095
42159
  return typeof Buffer !== "undefined" && typeof Buffer.from === "function";
@@ -42862,6 +42926,9 @@ function v43(options, buf, offset) {
42862
42926
  return _v4(options, buf, offset);
42863
42927
  }
42864
42928
  var v4_default = v43;
42929
+ // src/runtime.ts
42930
+ init_environment();
42931
+
42865
42932
  // src/search.ts
42866
42933
  var isV = (char) => {
42867
42934
  switch (char) {
@@ -45580,6 +45647,7 @@ class AgentRuntime {
45580
45647
 
45581
45648
  // src/settings.ts
45582
45649
  var import_crypto_browserify = __toESM(require_crypto_browserify(), 1);
45650
+ init_environment();
45583
45651
  function createSettingFromConfig(configSetting) {
45584
45652
  return {
45585
45653
  name: configSetting.name,
@@ -45856,20 +45924,324 @@ function defineService(definition) {
45856
45924
  return createService(definition.serviceType).withDescription(definition.description).withStart(definition.start).withStop(definition.stop || (() => Promise.resolve())).build();
45857
45925
  }
45858
45926
 
45927
+ // src/secrets.ts
45928
+ init_environment();
45929
+ function hasCharacterSecrets(character) {
45930
+ return Boolean(character?.settings?.secrets && Object.keys(character.settings.secrets).length > 0);
45931
+ }
45932
+ async function loadSecretsNodeImpl(character) {
45933
+ const fs = await import("node:fs");
45934
+ const dotenv = await import("dotenv");
45935
+ const { findEnvFile: findEnvFile2 } = await Promise.resolve().then(() => (init_environment(), exports_environment));
45936
+ if (hasCharacterSecrets(character)) {
45937
+ return false;
45938
+ }
45939
+ const envPath = findEnvFile2();
45940
+ if (!envPath)
45941
+ return false;
45942
+ try {
45943
+ const buf = fs.readFileSync(envPath);
45944
+ const envSecrets = dotenv.parse(buf);
45945
+ if (!character.settings) {
45946
+ character.settings = {};
45947
+ }
45948
+ character.settings.secrets = envSecrets;
45949
+ return true;
45950
+ } catch {
45951
+ return false;
45952
+ }
45953
+ }
45954
+ async function setDefaultSecretsFromEnv(character) {
45955
+ const env2 = detectEnvironment();
45956
+ if (env2 !== "node") {
45957
+ return false;
45958
+ }
45959
+ return loadSecretsNodeImpl(character);
45960
+ }
45961
+
45962
+ // src/plugin.ts
45963
+ init_environment();
45964
+ var attemptedInstalls = new Set;
45965
+ function isAutoInstallAllowed() {
45966
+ if (process.env.ELIZA_NO_AUTO_INSTALL === "true")
45967
+ return false;
45968
+ if (process.env.ELIZA_NO_PLUGIN_AUTO_INSTALL === "true")
45969
+ return false;
45970
+ if (process.env.CI === "true")
45971
+ return false;
45972
+ if (process.env.ELIZA_TEST_MODE === "true")
45973
+ return false;
45974
+ if (false)
45975
+ ;
45976
+ return true;
45977
+ }
45978
+ async function tryInstallPlugin(pluginName) {
45979
+ try {
45980
+ if (!isAutoInstallAllowed()) {
45981
+ logger.debug(`Auto-install disabled or not allowed in this environment. Skipping install for ${pluginName}.`);
45982
+ return false;
45983
+ }
45984
+ if (attemptedInstalls.has(pluginName)) {
45985
+ logger.debug(`Auto-install already attempted for ${pluginName}. Skipping.`);
45986
+ return false;
45987
+ }
45988
+ attemptedInstalls.add(pluginName);
45989
+ if (typeof Bun === "undefined" || typeof Bun.spawn !== "function") {
45990
+ logger.warn(`Bun runtime not available. Cannot auto-install ${pluginName}. Please run: bun add ${pluginName}`);
45991
+ return false;
45992
+ }
45993
+ try {
45994
+ const check = Bun.spawn(["bun", "--version"], { stdout: "pipe", stderr: "pipe" });
45995
+ const code = await check.exited;
45996
+ if (code !== 0) {
45997
+ logger.warn(`Bun not available on PATH. Cannot auto-install ${pluginName}. Please run: bun add ${pluginName}`);
45998
+ return false;
45999
+ }
46000
+ } catch {
46001
+ logger.warn(`Bun not available on PATH. Cannot auto-install ${pluginName}. Please run: bun add ${pluginName}`);
46002
+ return false;
46003
+ }
46004
+ logger.info(`Attempting to auto-install missing plugin: ${pluginName}`);
46005
+ const install = Bun.spawn(["bun", "add", pluginName], {
46006
+ cwd: process.cwd(),
46007
+ env: process.env,
46008
+ stdout: "inherit",
46009
+ stderr: "inherit"
46010
+ });
46011
+ const exit = await install.exited;
46012
+ if (exit === 0) {
46013
+ logger.info(`Successfully installed ${pluginName}. Retrying import...`);
46014
+ return true;
46015
+ }
46016
+ logger.error(`bun add ${pluginName} failed with exit code ${exit}. Please install manually.`);
46017
+ return false;
46018
+ } catch (e) {
46019
+ const message = e instanceof Error ? e.message : String(e);
46020
+ logger.error(`Unexpected error during auto-install of ${pluginName}: ${message}`);
46021
+ return false;
46022
+ }
46023
+ }
46024
+ function isValidPluginShape(obj) {
46025
+ if (!obj || typeof obj !== "object") {
46026
+ return false;
46027
+ }
46028
+ const plugin = obj;
46029
+ if (!plugin.name) {
46030
+ return false;
46031
+ }
46032
+ return !!(plugin.init || plugin.services || plugin.providers || plugin.actions || plugin.evaluators || plugin.description);
46033
+ }
46034
+ function validatePlugin(plugin) {
46035
+ const errors = [];
46036
+ if (!plugin) {
46037
+ errors.push("Plugin is null or undefined");
46038
+ return { isValid: false, errors };
46039
+ }
46040
+ const pluginObj = plugin;
46041
+ if (!pluginObj.name) {
46042
+ errors.push("Plugin must have a name");
46043
+ }
46044
+ if (pluginObj.actions) {
46045
+ if (!Array.isArray(pluginObj.actions)) {
46046
+ errors.push("Plugin actions must be an array");
46047
+ } else {
46048
+ const invalidActions = pluginObj.actions.filter((a) => typeof a !== "object" || !a);
46049
+ if (invalidActions.length > 0) {
46050
+ errors.push("Plugin actions must be an array of action objects");
46051
+ }
46052
+ }
46053
+ }
46054
+ if (pluginObj.services) {
46055
+ if (!Array.isArray(pluginObj.services)) {
46056
+ errors.push("Plugin services must be an array");
46057
+ } else {
46058
+ const invalidServices = pluginObj.services.filter((s) => typeof s !== "function" && (typeof s !== "object" || !s));
46059
+ if (invalidServices.length > 0) {
46060
+ errors.push("Plugin services must be an array of service classes or objects");
46061
+ }
46062
+ }
46063
+ }
46064
+ if (pluginObj.providers && !Array.isArray(pluginObj.providers)) {
46065
+ errors.push("Plugin providers must be an array");
46066
+ }
46067
+ if (pluginObj.evaluators && !Array.isArray(pluginObj.evaluators)) {
46068
+ errors.push("Plugin evaluators must be an array");
46069
+ }
46070
+ return {
46071
+ isValid: errors.length === 0,
46072
+ errors
46073
+ };
46074
+ }
46075
+ async function loadAndPreparePlugin(pluginName) {
46076
+ try {
46077
+ let pluginModule;
46078
+ try {
46079
+ pluginModule = await import(pluginName);
46080
+ } catch (error) {
46081
+ logger.warn(`Failed to load plugin ${pluginName}: ${error}`);
46082
+ const attempted = await tryInstallPlugin(pluginName);
46083
+ if (!attempted) {
46084
+ return null;
46085
+ }
46086
+ try {
46087
+ pluginModule = await import(pluginName);
46088
+ } catch (secondError) {
46089
+ logger.error(`Auto-install attempted for ${pluginName} but import still failed: ${secondError}`);
46090
+ return null;
46091
+ }
46092
+ }
46093
+ if (!pluginModule) {
46094
+ logger.error(`Failed to load module for plugin ${pluginName}.`);
46095
+ return null;
46096
+ }
46097
+ const expectedFunctionName = `${pluginName.replace(/^@elizaos\/plugin-/, "").replace(/^@elizaos\//, "").replace(/-./g, (match) => match[1].toUpperCase())}Plugin`;
46098
+ const moduleObj = pluginModule;
46099
+ const exportsToCheck = [
46100
+ moduleObj[expectedFunctionName],
46101
+ moduleObj.default,
46102
+ ...Object.values(moduleObj)
46103
+ ];
46104
+ for (const potentialPlugin of exportsToCheck) {
46105
+ if (isValidPluginShape(potentialPlugin)) {
46106
+ return potentialPlugin;
46107
+ }
46108
+ if (typeof potentialPlugin === "function" && potentialPlugin.length === 0) {
46109
+ try {
46110
+ const produced = potentialPlugin();
46111
+ if (isValidPluginShape(produced)) {
46112
+ return produced;
46113
+ }
46114
+ } catch (err) {
46115
+ logger.debug(`Factory export threw for ${pluginName}: ${err}`);
46116
+ }
46117
+ }
46118
+ }
46119
+ logger.warn(`Could not find a valid plugin export in ${pluginName}.`);
46120
+ return null;
46121
+ } catch (error) {
46122
+ logger.error(`Error loading plugin ${pluginName}: ${error}`);
46123
+ return null;
46124
+ }
46125
+ }
46126
+ function resolvePluginDependencies(availablePlugins, isTestMode = false) {
46127
+ const resolutionOrder = [];
46128
+ const visited = new Set;
46129
+ const visiting = new Set;
46130
+ function visit(pluginName) {
46131
+ if (!availablePlugins.has(pluginName)) {
46132
+ logger.warn(`Plugin dependency "${pluginName}" not found and will be skipped.`);
46133
+ return;
46134
+ }
46135
+ if (visited.has(pluginName))
46136
+ return;
46137
+ if (visiting.has(pluginName)) {
46138
+ logger.error(`Circular dependency detected involving plugin: ${pluginName}`);
46139
+ return;
46140
+ }
46141
+ visiting.add(pluginName);
46142
+ const plugin = availablePlugins.get(pluginName);
46143
+ if (plugin) {
46144
+ const deps = [...plugin.dependencies || []];
46145
+ if (isTestMode) {
46146
+ deps.push(...plugin.testDependencies || []);
46147
+ }
46148
+ for (const dep of deps) {
46149
+ visit(dep);
46150
+ }
46151
+ }
46152
+ visiting.delete(pluginName);
46153
+ visited.add(pluginName);
46154
+ resolutionOrder.push(pluginName);
46155
+ }
46156
+ for (const name of availablePlugins.keys()) {
46157
+ if (!visited.has(name)) {
46158
+ visit(name);
46159
+ }
46160
+ }
46161
+ const finalPlugins = resolutionOrder.map((name) => availablePlugins.get(name)).filter((p) => Boolean(p));
46162
+ logger.info({ plugins: finalPlugins.map((p) => p.name) }, `Final plugins being loaded:`);
46163
+ return finalPlugins;
46164
+ }
46165
+ async function loadPlugin(nameOrPlugin) {
46166
+ if (typeof nameOrPlugin === "string") {
46167
+ return loadAndPreparePlugin(nameOrPlugin);
46168
+ }
46169
+ const validation = validatePlugin(nameOrPlugin);
46170
+ if (!validation.isValid) {
46171
+ logger.error(`Invalid plugin provided: ${validation.errors.join(", ")}`);
46172
+ return null;
46173
+ }
46174
+ return nameOrPlugin;
46175
+ }
46176
+ async function resolvePluginsImpl(plugins, isTestMode = false) {
46177
+ const pluginMap = new Map;
46178
+ const queue2 = [...plugins];
46179
+ while (queue2.length > 0) {
46180
+ const next = queue2.shift();
46181
+ const loaded = await loadPlugin(next);
46182
+ if (!loaded)
46183
+ continue;
46184
+ if (!pluginMap.has(loaded.name)) {
46185
+ pluginMap.set(loaded.name, loaded);
46186
+ for (const depName of loaded.dependencies ?? []) {
46187
+ if (!pluginMap.has(depName)) {
46188
+ queue2.push(depName);
46189
+ }
46190
+ }
46191
+ if (isTestMode) {
46192
+ for (const depName of loaded.testDependencies ?? []) {
46193
+ if (!pluginMap.has(depName)) {
46194
+ queue2.push(depName);
46195
+ }
46196
+ }
46197
+ }
46198
+ }
46199
+ }
46200
+ return resolvePluginDependencies(pluginMap, isTestMode);
46201
+ }
46202
+ async function resolvePlugins(plugins, isTestMode = false) {
46203
+ const env2 = detectEnvironment();
46204
+ if (env2 === "node") {
46205
+ return resolvePluginsImpl(plugins, isTestMode);
46206
+ }
46207
+ const pluginObjects = plugins.filter((p) => typeof p !== "string");
46208
+ if (plugins.some((p) => typeof p === "string")) {
46209
+ logger.warn("Browser environment: String plugin references are not supported. Only Plugin objects will be used. Skipped plugins: " + plugins.filter((p) => typeof p === "string").join(", "));
46210
+ }
46211
+ const pluginMap = new Map;
46212
+ for (const plugin of pluginObjects) {
46213
+ pluginMap.set(plugin.name, plugin);
46214
+ }
46215
+ return resolvePluginDependencies(pluginMap, isTestMode);
46216
+ }
46217
+
45859
46218
  // src/elizaos.ts
45860
46219
  class ElizaOS extends EventTarget {
45861
46220
  runtimes = new Map;
45862
46221
  editableMode = false;
45863
46222
  async addAgents(agents) {
45864
46223
  const promises = agents.map(async (agent) => {
46224
+ const character = agent.character;
46225
+ if (!hasCharacterSecrets(character)) {
46226
+ await setDefaultSecretsFromEnv(character);
46227
+ }
46228
+ const resolvedPlugins = agent.plugins ? await resolvePlugins(agent.plugins) : [];
45865
46229
  const runtime = new AgentRuntime({
45866
- character: agent.character,
45867
- plugins: agent.plugins || [],
46230
+ character,
46231
+ plugins: resolvedPlugins,
45868
46232
  settings: agent.settings || {}
45869
46233
  });
45870
46234
  this.runtimes.set(runtime.agentId, runtime);
46235
+ const { settings, ...characterWithoutSecrets } = character;
46236
+ const { secrets, ...settingsWithoutSecrets } = settings || {};
45871
46237
  this.dispatchEvent(new CustomEvent("agent:added", {
45872
- detail: { agentId: runtime.agentId, character: agent.character }
46238
+ detail: {
46239
+ agentId: runtime.agentId,
46240
+ character: {
46241
+ ...characterWithoutSecrets,
46242
+ settings: settingsWithoutSecrets
46243
+ }
46244
+ }
45873
46245
  }));
45874
46246
  return runtime.agentId;
45875
46247
  });
@@ -46277,6 +46649,47 @@ Data: ${JSON.stringify(entity.metadata)}
46277
46649
  return entityStrings.join(`
46278
46650
  `);
46279
46651
  }
46652
+ // src/character.ts
46653
+ function parseCharacter(input) {
46654
+ if (typeof input === "string") {
46655
+ throw new Error(`Character path provided but must be loaded first: ${input}`);
46656
+ }
46657
+ if (typeof input === "object") {
46658
+ const validationResult = validateCharacter(input);
46659
+ if (!validationResult.success) {
46660
+ const errorDetails = validationResult.error?.issues ? validationResult.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; ") : validationResult.error?.message || "Unknown validation error";
46661
+ throw new Error(`Character validation failed: ${errorDetails}`);
46662
+ }
46663
+ return validationResult.data;
46664
+ }
46665
+ throw new Error("Invalid character input format");
46666
+ }
46667
+ function validateCharacterConfig(character) {
46668
+ const validationResult = validateCharacter(character);
46669
+ if (validationResult.success) {
46670
+ return {
46671
+ isValid: true,
46672
+ errors: []
46673
+ };
46674
+ }
46675
+ const errors = validationResult.error?.issues ? validationResult.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`) : [validationResult.error?.message || "Unknown validation error"];
46676
+ return {
46677
+ isValid: false,
46678
+ errors
46679
+ };
46680
+ }
46681
+ function mergeCharacterDefaults(char) {
46682
+ const defaults = {
46683
+ settings: {},
46684
+ plugins: [],
46685
+ bio: []
46686
+ };
46687
+ return {
46688
+ ...defaults,
46689
+ ...char,
46690
+ name: char.name || "Unnamed Character"
46691
+ };
46692
+ }
46280
46693
 
46281
46694
  // src/index.node.ts
46282
46695
  var isBrowser4 = false;
@@ -46284,11 +46697,14 @@ var isNode3 = true;
46284
46697
  export {
46285
46698
  waitForServerReady,
46286
46699
  validateUuid,
46700
+ validatePlugin,
46701
+ validateCharacterConfig,
46287
46702
  validateCharacter,
46288
46703
  uuidSchema2 as uuidSchema,
46289
46704
  updateWorldSettings,
46290
46705
  unsaltWorldSettings,
46291
46706
  unsaltSettingValue,
46707
+ tryInstallPlugin,
46292
46708
  truncateToCompleteSentence,
46293
46709
  trimTokens,
46294
46710
  toString2 as toString,
@@ -46301,10 +46717,13 @@ export {
46301
46717
  shouldRespondTemplate,
46302
46718
  settingsSchema,
46303
46719
  setEnv,
46720
+ setDefaultSecretsFromEnv,
46304
46721
  secretsSchema,
46305
46722
  saltWorldSettings,
46306
46723
  saltSettingValue,
46307
46724
  safeReplacer,
46725
+ resolvePlugins,
46726
+ resolvePluginDependencies,
46308
46727
  resetPaths,
46309
46728
  recentLogs,
46310
46729
  randomBytes,
@@ -46313,6 +46732,7 @@ export {
46313
46732
  pingServer,
46314
46733
  parseKeyValueXml,
46315
46734
  parseJSONObjectFromText,
46735
+ parseCharacter,
46316
46736
  parseBooleanFromText2 as parseBooleanFromText,
46317
46737
  parseAndValidateCharacter,
46318
46738
  normalizeJsonString,
@@ -46320,9 +46740,14 @@ export {
46320
46740
  multiStepDecisionTemplate,
46321
46741
  messageHandlerTemplate,
46322
46742
  messageExampleSchema,
46743
+ mergeCharacterDefaults,
46323
46744
  mediaSchema,
46324
46745
  logger,
46746
+ loadPlugin,
46747
+ loadEnvConfig,
46748
+ loadAndPreparePlugin,
46325
46749
  knowledgeItemSchema,
46750
+ isValidPluginShape,
46326
46751
  isValidCharacter,
46327
46752
  isNode3 as isNode,
46328
46753
  isMessageMetadata,
@@ -46338,6 +46763,7 @@ export {
46338
46763
  initBrowserEnvironment,
46339
46764
  imageDescriptionTemplate,
46340
46765
  hasEnv,
46766
+ hasCharacterSecrets,
46341
46767
  getWorldSettings,
46342
46768
  getUserServerRole,
46343
46769
  getUploadsChannelsDir,
@@ -46368,6 +46794,7 @@ export {
46368
46794
  formatActions,
46369
46795
  formatActionNames,
46370
46796
  findWorldsForOwner,
46797
+ findEnvFile,
46371
46798
  findEntityByName,
46372
46799
  equals,
46373
46800
  encryptedCharacter,
@@ -46427,5 +46854,5 @@ export {
46427
46854
  AgentRuntime
46428
46855
  };
46429
46856
 
46430
- //# debugId=EC34687CD2FBE32664756E2164756E21
46857
+ //# debugId=E2D0C494EAA6822164756E2164756E21
46431
46858
  //# sourceMappingURL=index.node.js.map