genlayer 0.0.19 → 0.0.21

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
 
2
2
 
3
+ ## 0.0.21 (2024-04-30)
4
+
5
+ ## 0.0.20 (2024-04-26)
6
+
3
7
  ## 0.0.19 (2024-04-26)
4
8
 
5
9
  ## 0.0.17 (2024-04-23)
package/dist/index.js CHANGED
@@ -1052,7 +1052,7 @@ var require_command = __commonJS({
1052
1052
  var EventEmitter = require("events").EventEmitter;
1053
1053
  var childProcess = require("child_process");
1054
1054
  var path = require("path");
1055
- var fs2 = require("fs");
1055
+ var fs3 = require("fs");
1056
1056
  var process4 = require("process");
1057
1057
  var { Argument: Argument2, humanReadableArgName } = require_argument();
1058
1058
  var { CommanderError: CommanderError2 } = require_error();
@@ -1951,11 +1951,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
1951
1951
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1952
1952
  function findFile(baseDir, baseName) {
1953
1953
  const localBin = path.resolve(baseDir, baseName);
1954
- if (fs2.existsSync(localBin))
1954
+ if (fs3.existsSync(localBin))
1955
1955
  return localBin;
1956
1956
  if (sourceExt.includes(path.extname(baseName)))
1957
1957
  return void 0;
1958
- const foundExt = sourceExt.find((ext) => fs2.existsSync(`${localBin}${ext}`));
1958
+ const foundExt = sourceExt.find((ext) => fs3.existsSync(`${localBin}${ext}`));
1959
1959
  if (foundExt)
1960
1960
  return `${localBin}${foundExt}`;
1961
1961
  return void 0;
@@ -1967,7 +1967,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1967
1967
  if (this._scriptPath) {
1968
1968
  let resolvedScriptPath;
1969
1969
  try {
1970
- resolvedScriptPath = fs2.realpathSync(this._scriptPath);
1970
+ resolvedScriptPath = fs3.realpathSync(this._scriptPath);
1971
1971
  } catch (err) {
1972
1972
  resolvedScriptPath = this._scriptPath;
1973
1973
  }
@@ -17601,10 +17601,10 @@ var require_supports_color = __commonJS({
17601
17601
  return 3;
17602
17602
  }
17603
17603
  if ("TERM_PROGRAM" in env2) {
17604
- const version = parseInt((env2.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
17604
+ const version2 = parseInt((env2.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
17605
17605
  switch (env2.TERM_PROGRAM) {
17606
17606
  case "iTerm.app":
17607
- return version >= 3 ? 3 : 2;
17607
+ return version2 >= 3 ? 3 : 2;
17608
17608
  case "Apple_Terminal":
17609
17609
  return 2;
17610
17610
  }
@@ -29099,7 +29099,7 @@ var require_iso2022 = __commonJS({
29099
29099
  var require_chardet = __commonJS({
29100
29100
  "node_modules/chardet/index.js"(exports2, module2) {
29101
29101
  "use strict";
29102
- var fs2 = require("fs");
29102
+ var fs3 = require("fs");
29103
29103
  var utf8 = require_utf8();
29104
29104
  var unicode = require_unicode();
29105
29105
  var mbcs = require_mbcs();
@@ -29173,29 +29173,29 @@ var require_chardet = __commonJS({
29173
29173
  var fd;
29174
29174
  var handler = function(err, buffer) {
29175
29175
  if (fd) {
29176
- fs2.closeSync(fd);
29176
+ fs3.closeSync(fd);
29177
29177
  }
29178
29178
  if (err)
29179
29179
  return cb(err, null);
29180
29180
  cb(null, self2.detect(buffer, opts));
29181
29181
  };
29182
29182
  if (opts && opts.sampleSize) {
29183
- fd = fs2.openSync(filepath, "r"), sample = Buffer.allocUnsafe(opts.sampleSize);
29184
- fs2.read(fd, sample, 0, opts.sampleSize, null, function(err) {
29183
+ fd = fs3.openSync(filepath, "r"), sample = Buffer.allocUnsafe(opts.sampleSize);
29184
+ fs3.read(fd, sample, 0, opts.sampleSize, null, function(err) {
29185
29185
  handler(err, sample);
29186
29186
  });
29187
29187
  return;
29188
29188
  }
29189
- fs2.readFile(filepath, handler);
29189
+ fs3.readFile(filepath, handler);
29190
29190
  };
29191
29191
  module2.exports.detectFileSync = function(filepath, opts) {
29192
29192
  if (opts && opts.sampleSize) {
29193
- var fd = fs2.openSync(filepath, "r"), sample2 = Buffer.allocUnsafe(opts.sampleSize);
29194
- fs2.readSync(fd, sample2, 0, opts.sampleSize);
29195
- fs2.closeSync(fd);
29193
+ var fd = fs3.openSync(filepath, "r"), sample2 = Buffer.allocUnsafe(opts.sampleSize);
29194
+ fs3.readSync(fd, sample2, 0, opts.sampleSize);
29195
+ fs3.closeSync(fd);
29196
29196
  return self2.detect(sample2, opts);
29197
29197
  }
29198
- return self2.detect(fs2.readFileSync(filepath), opts);
29198
+ return self2.detect(fs3.readFileSync(filepath), opts);
29199
29199
  };
29200
29200
  module2.exports.detectAll = function(buffer, opts) {
29201
29201
  if (typeof opts !== "object") {
@@ -32699,7 +32699,7 @@ var require_os_tmpdir = __commonJS({
32699
32699
  var require_tmp = __commonJS({
32700
32700
  "node_modules/tmp/lib/tmp.js"(exports2, module2) {
32701
32701
  "use strict";
32702
- var fs2 = require("fs");
32702
+ var fs3 = require("fs");
32703
32703
  var path = require("path");
32704
32704
  var crypto3 = require("crypto");
32705
32705
  var osTmpDir = require_os_tmpdir();
@@ -32763,7 +32763,7 @@ var require_tmp = __commonJS({
32763
32763
  return cb(new Error("Invalid template provided"));
32764
32764
  (function _getUniqueName() {
32765
32765
  const name = _generateTmpName(opts);
32766
- fs2.stat(name, function(err) {
32766
+ fs3.stat(name, function(err) {
32767
32767
  if (!err) {
32768
32768
  if (tries-- > 0)
32769
32769
  return _getUniqueName();
@@ -32782,7 +32782,7 @@ var require_tmp = __commonJS({
32782
32782
  do {
32783
32783
  const name = _generateTmpName(opts);
32784
32784
  try {
32785
- fs2.statSync(name);
32785
+ fs3.statSync(name);
32786
32786
  } catch (e2) {
32787
32787
  return name;
32788
32788
  }
@@ -32795,14 +32795,14 @@ var require_tmp = __commonJS({
32795
32795
  tmpName(opts, function _tmpNameCreated(err, name) {
32796
32796
  if (err)
32797
32797
  return cb(err);
32798
- fs2.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err2, fd) {
32798
+ fs3.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err2, fd) {
32799
32799
  if (err2)
32800
32800
  return cb(err2);
32801
32801
  if (opts.discardDescriptor) {
32802
- return fs2.close(fd, function _discardCallback(err3) {
32802
+ return fs3.close(fd, function _discardCallback(err3) {
32803
32803
  if (err3) {
32804
32804
  try {
32805
- fs2.unlinkSync(name);
32805
+ fs3.unlinkSync(name);
32806
32806
  } catch (e2) {
32807
32807
  if (!isENOENT(e2)) {
32808
32808
  err3 = e2;
@@ -32825,9 +32825,9 @@ var require_tmp = __commonJS({
32825
32825
  opts.postfix = opts.postfix || ".tmp";
32826
32826
  const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
32827
32827
  const name = tmpNameSync(opts);
32828
- var fd = fs2.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
32828
+ var fd = fs3.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
32829
32829
  if (opts.discardDescriptor) {
32830
- fs2.closeSync(fd);
32830
+ fs3.closeSync(fd);
32831
32831
  fd = void 0;
32832
32832
  }
32833
32833
  return {
@@ -32839,9 +32839,9 @@ var require_tmp = __commonJS({
32839
32839
  function _rmdirRecursiveSync(root) {
32840
32840
  const dirs = [root];
32841
32841
  do {
32842
- var dir2 = dirs.pop(), deferred = false, files = fs2.readdirSync(dir2);
32842
+ var dir2 = dirs.pop(), deferred = false, files = fs3.readdirSync(dir2);
32843
32843
  for (var i2 = 0, length = files.length; i2 < length; i2++) {
32844
- var file2 = path.join(dir2, files[i2]), stat2 = fs2.lstatSync(file2);
32844
+ var file2 = path.join(dir2, files[i2]), stat2 = fs3.lstatSync(file2);
32845
32845
  if (stat2.isDirectory()) {
32846
32846
  if (!deferred) {
32847
32847
  deferred = true;
@@ -32849,11 +32849,11 @@ var require_tmp = __commonJS({
32849
32849
  }
32850
32850
  dirs.push(file2);
32851
32851
  } else {
32852
- fs2.unlinkSync(file2);
32852
+ fs3.unlinkSync(file2);
32853
32853
  }
32854
32854
  }
32855
32855
  if (!deferred) {
32856
- fs2.rmdirSync(dir2);
32856
+ fs3.rmdirSync(dir2);
32857
32857
  }
32858
32858
  } while (dirs.length !== 0);
32859
32859
  }
@@ -32862,7 +32862,7 @@ var require_tmp = __commonJS({
32862
32862
  tmpName(opts, function _tmpNameCreated(err, name) {
32863
32863
  if (err)
32864
32864
  return cb(err);
32865
- fs2.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err2) {
32865
+ fs3.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err2) {
32866
32866
  if (err2)
32867
32867
  return cb(err2);
32868
32868
  cb(null, name, _prepareTmpDirRemoveCallback(name, opts));
@@ -32872,7 +32872,7 @@ var require_tmp = __commonJS({
32872
32872
  function dirSync(options) {
32873
32873
  var args = _parseArguments(options), opts = args[0];
32874
32874
  const name = tmpNameSync(opts);
32875
- fs2.mkdirSync(name, opts.mode || DIR_MODE);
32875
+ fs3.mkdirSync(name, opts.mode || DIR_MODE);
32876
32876
  return {
32877
32877
  name,
32878
32878
  removeCallback: _prepareTmpDirRemoveCallback(name, opts)
@@ -32882,7 +32882,7 @@ var require_tmp = __commonJS({
32882
32882
  const removeCallback = _prepareRemoveCallback(function _removeCallback(fdPath) {
32883
32883
  try {
32884
32884
  if (0 <= fdPath[0]) {
32885
- fs2.closeSync(fdPath[0]);
32885
+ fs3.closeSync(fdPath[0]);
32886
32886
  }
32887
32887
  } catch (e2) {
32888
32888
  if (!isEBADF(e2) && !isENOENT(e2)) {
@@ -32890,7 +32890,7 @@ var require_tmp = __commonJS({
32890
32890
  }
32891
32891
  }
32892
32892
  try {
32893
- fs2.unlinkSync(fdPath[1]);
32893
+ fs3.unlinkSync(fdPath[1]);
32894
32894
  } catch (e2) {
32895
32895
  if (!isENOENT(e2)) {
32896
32896
  throw e2;
@@ -32903,7 +32903,7 @@ var require_tmp = __commonJS({
32903
32903
  return removeCallback;
32904
32904
  }
32905
32905
  function _prepareTmpDirRemoveCallback(name, opts) {
32906
- const removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs2.rmdirSync.bind(fs2);
32906
+ const removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs3.rmdirSync.bind(fs3);
32907
32907
  const removeCallback = _prepareRemoveCallback(removeFunction, name);
32908
32908
  if (!opts.keep) {
32909
32909
  _removeObjects.unshift(removeCallback);
@@ -32948,10 +32948,10 @@ var require_tmp = __commonJS({
32948
32948
  function setGracefulCleanup() {
32949
32949
  _gracefulCleanup = true;
32950
32950
  }
32951
- var version = process.versions.node.split(".").map(function(value) {
32951
+ var version2 = process.versions.node.split(".").map(function(value) {
32952
32952
  return parseInt(value, 10);
32953
32953
  });
32954
- if (version[0] === 0 && (version[1] < 9 || version[1] === 9 && version[2] < 5)) {
32954
+ if (version2[0] === 0 && (version2[1] < 9 || version2[1] === 9 && version2[2] < 5)) {
32955
32955
  process.addListener("uncaughtException", function _uncaughtExceptionThrown(err) {
32956
32956
  _uncaughtException = true;
32957
32957
  _garbageCollector();
@@ -34416,6 +34416,345 @@ var require_set = __commonJS({
34416
34416
  }
34417
34417
  });
34418
34418
 
34419
+ // node_modules/dotenv/package.json
34420
+ var require_package = __commonJS({
34421
+ "node_modules/dotenv/package.json"(exports2, module2) {
34422
+ module2.exports = {
34423
+ name: "dotenv",
34424
+ version: "16.4.5",
34425
+ description: "Loads environment variables from .env file",
34426
+ main: "lib/main.js",
34427
+ types: "lib/main.d.ts",
34428
+ exports: {
34429
+ ".": {
34430
+ types: "./lib/main.d.ts",
34431
+ require: "./lib/main.js",
34432
+ default: "./lib/main.js"
34433
+ },
34434
+ "./config": "./config.js",
34435
+ "./config.js": "./config.js",
34436
+ "./lib/env-options": "./lib/env-options.js",
34437
+ "./lib/env-options.js": "./lib/env-options.js",
34438
+ "./lib/cli-options": "./lib/cli-options.js",
34439
+ "./lib/cli-options.js": "./lib/cli-options.js",
34440
+ "./package.json": "./package.json"
34441
+ },
34442
+ scripts: {
34443
+ "dts-check": "tsc --project tests/types/tsconfig.json",
34444
+ lint: "standard",
34445
+ "lint-readme": "standard-markdown",
34446
+ pretest: "npm run lint && npm run dts-check",
34447
+ test: "tap tests/*.js --100 -Rspec",
34448
+ "test:coverage": "tap --coverage-report=lcov",
34449
+ prerelease: "npm test",
34450
+ release: "standard-version"
34451
+ },
34452
+ repository: {
34453
+ type: "git",
34454
+ url: "git://github.com/motdotla/dotenv.git"
34455
+ },
34456
+ funding: "https://dotenvx.com",
34457
+ keywords: [
34458
+ "dotenv",
34459
+ "env",
34460
+ ".env",
34461
+ "environment",
34462
+ "variables",
34463
+ "config",
34464
+ "settings"
34465
+ ],
34466
+ readmeFilename: "README.md",
34467
+ license: "BSD-2-Clause",
34468
+ devDependencies: {
34469
+ "@definitelytyped/dtslint": "^0.0.133",
34470
+ "@types/node": "^18.11.3",
34471
+ decache: "^4.6.1",
34472
+ sinon: "^14.0.1",
34473
+ standard: "^17.0.0",
34474
+ "standard-markdown": "^7.1.0",
34475
+ "standard-version": "^9.5.0",
34476
+ tap: "^16.3.0",
34477
+ tar: "^6.1.11",
34478
+ typescript: "^4.8.4"
34479
+ },
34480
+ engines: {
34481
+ node: ">=12"
34482
+ },
34483
+ browser: {
34484
+ fs: false
34485
+ }
34486
+ };
34487
+ }
34488
+ });
34489
+
34490
+ // node_modules/dotenv/lib/main.js
34491
+ var require_main2 = __commonJS({
34492
+ "node_modules/dotenv/lib/main.js"(exports2, module2) {
34493
+ "use strict";
34494
+ var fs3 = require("fs");
34495
+ var path = require("path");
34496
+ var os3 = require("os");
34497
+ var crypto3 = require("crypto");
34498
+ var packageJson = require_package();
34499
+ var version2 = packageJson.version;
34500
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
34501
+ function parse2(src) {
34502
+ const obj = {};
34503
+ let lines = src.toString();
34504
+ lines = lines.replace(/\r\n?/mg, "\n");
34505
+ let match;
34506
+ while ((match = LINE.exec(lines)) != null) {
34507
+ const key = match[1];
34508
+ let value = match[2] || "";
34509
+ value = value.trim();
34510
+ const maybeQuote = value[0];
34511
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
34512
+ if (maybeQuote === '"') {
34513
+ value = value.replace(/\\n/g, "\n");
34514
+ value = value.replace(/\\r/g, "\r");
34515
+ }
34516
+ obj[key] = value;
34517
+ }
34518
+ return obj;
34519
+ }
34520
+ function _parseVault(options) {
34521
+ const vaultPath = _vaultPath(options);
34522
+ const result = DotenvModule.configDotenv({ path: vaultPath });
34523
+ if (!result.parsed) {
34524
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
34525
+ err.code = "MISSING_DATA";
34526
+ throw err;
34527
+ }
34528
+ const keys = _dotenvKey(options).split(",");
34529
+ const length = keys.length;
34530
+ let decrypted;
34531
+ for (let i2 = 0; i2 < length; i2++) {
34532
+ try {
34533
+ const key = keys[i2].trim();
34534
+ const attrs = _instructions(result, key);
34535
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
34536
+ break;
34537
+ } catch (error) {
34538
+ if (i2 + 1 >= length) {
34539
+ throw error;
34540
+ }
34541
+ }
34542
+ }
34543
+ return DotenvModule.parse(decrypted);
34544
+ }
34545
+ function _log(message) {
34546
+ console.log(`[dotenv@${version2}][INFO] ${message}`);
34547
+ }
34548
+ function _warn(message) {
34549
+ console.log(`[dotenv@${version2}][WARN] ${message}`);
34550
+ }
34551
+ function _debug(message) {
34552
+ console.log(`[dotenv@${version2}][DEBUG] ${message}`);
34553
+ }
34554
+ function _dotenvKey(options) {
34555
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
34556
+ return options.DOTENV_KEY;
34557
+ }
34558
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
34559
+ return process.env.DOTENV_KEY;
34560
+ }
34561
+ return "";
34562
+ }
34563
+ function _instructions(result, dotenvKey) {
34564
+ let uri;
34565
+ try {
34566
+ uri = new URL(dotenvKey);
34567
+ } catch (error) {
34568
+ if (error.code === "ERR_INVALID_URL") {
34569
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
34570
+ err.code = "INVALID_DOTENV_KEY";
34571
+ throw err;
34572
+ }
34573
+ throw error;
34574
+ }
34575
+ const key = uri.password;
34576
+ if (!key) {
34577
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
34578
+ err.code = "INVALID_DOTENV_KEY";
34579
+ throw err;
34580
+ }
34581
+ const environment = uri.searchParams.get("environment");
34582
+ if (!environment) {
34583
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
34584
+ err.code = "INVALID_DOTENV_KEY";
34585
+ throw err;
34586
+ }
34587
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
34588
+ const ciphertext = result.parsed[environmentKey];
34589
+ if (!ciphertext) {
34590
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
34591
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
34592
+ throw err;
34593
+ }
34594
+ return { ciphertext, key };
34595
+ }
34596
+ function _vaultPath(options) {
34597
+ let possibleVaultPath = null;
34598
+ if (options && options.path && options.path.length > 0) {
34599
+ if (Array.isArray(options.path)) {
34600
+ for (const filepath of options.path) {
34601
+ if (fs3.existsSync(filepath)) {
34602
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
34603
+ }
34604
+ }
34605
+ } else {
34606
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
34607
+ }
34608
+ } else {
34609
+ possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
34610
+ }
34611
+ if (fs3.existsSync(possibleVaultPath)) {
34612
+ return possibleVaultPath;
34613
+ }
34614
+ return null;
34615
+ }
34616
+ function _resolveHome(envPath) {
34617
+ return envPath[0] === "~" ? path.join(os3.homedir(), envPath.slice(1)) : envPath;
34618
+ }
34619
+ function _configVault(options) {
34620
+ _log("Loading env from encrypted .env.vault");
34621
+ const parsed = DotenvModule._parseVault(options);
34622
+ let processEnv = process.env;
34623
+ if (options && options.processEnv != null) {
34624
+ processEnv = options.processEnv;
34625
+ }
34626
+ DotenvModule.populate(processEnv, parsed, options);
34627
+ return { parsed };
34628
+ }
34629
+ function configDotenv(options) {
34630
+ const dotenvPath = path.resolve(process.cwd(), ".env");
34631
+ let encoding = "utf8";
34632
+ const debug = Boolean(options && options.debug);
34633
+ if (options && options.encoding) {
34634
+ encoding = options.encoding;
34635
+ } else {
34636
+ if (debug) {
34637
+ _debug("No encoding is specified. UTF-8 is used by default");
34638
+ }
34639
+ }
34640
+ let optionPaths = [dotenvPath];
34641
+ if (options && options.path) {
34642
+ if (!Array.isArray(options.path)) {
34643
+ optionPaths = [_resolveHome(options.path)];
34644
+ } else {
34645
+ optionPaths = [];
34646
+ for (const filepath of options.path) {
34647
+ optionPaths.push(_resolveHome(filepath));
34648
+ }
34649
+ }
34650
+ }
34651
+ let lastError;
34652
+ const parsedAll = {};
34653
+ for (const path2 of optionPaths) {
34654
+ try {
34655
+ const parsed = DotenvModule.parse(fs3.readFileSync(path2, { encoding }));
34656
+ DotenvModule.populate(parsedAll, parsed, options);
34657
+ } catch (e2) {
34658
+ if (debug) {
34659
+ _debug(`Failed to load ${path2} ${e2.message}`);
34660
+ }
34661
+ lastError = e2;
34662
+ }
34663
+ }
34664
+ let processEnv = process.env;
34665
+ if (options && options.processEnv != null) {
34666
+ processEnv = options.processEnv;
34667
+ }
34668
+ DotenvModule.populate(processEnv, parsedAll, options);
34669
+ if (lastError) {
34670
+ return { parsed: parsedAll, error: lastError };
34671
+ } else {
34672
+ return { parsed: parsedAll };
34673
+ }
34674
+ }
34675
+ function config(options) {
34676
+ if (_dotenvKey(options).length === 0) {
34677
+ return DotenvModule.configDotenv(options);
34678
+ }
34679
+ const vaultPath = _vaultPath(options);
34680
+ if (!vaultPath) {
34681
+ _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
34682
+ return DotenvModule.configDotenv(options);
34683
+ }
34684
+ return DotenvModule._configVault(options);
34685
+ }
34686
+ function decrypt(encrypted, keyStr) {
34687
+ const key = Buffer.from(keyStr.slice(-64), "hex");
34688
+ let ciphertext = Buffer.from(encrypted, "base64");
34689
+ const nonce = ciphertext.subarray(0, 12);
34690
+ const authTag = ciphertext.subarray(-16);
34691
+ ciphertext = ciphertext.subarray(12, -16);
34692
+ try {
34693
+ const aesgcm = crypto3.createDecipheriv("aes-256-gcm", key, nonce);
34694
+ aesgcm.setAuthTag(authTag);
34695
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
34696
+ } catch (error) {
34697
+ const isRange = error instanceof RangeError;
34698
+ const invalidKeyLength = error.message === "Invalid key length";
34699
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
34700
+ if (isRange || invalidKeyLength) {
34701
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
34702
+ err.code = "INVALID_DOTENV_KEY";
34703
+ throw err;
34704
+ } else if (decryptionFailed) {
34705
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
34706
+ err.code = "DECRYPTION_FAILED";
34707
+ throw err;
34708
+ } else {
34709
+ throw error;
34710
+ }
34711
+ }
34712
+ }
34713
+ function populate(processEnv, parsed, options = {}) {
34714
+ const debug = Boolean(options && options.debug);
34715
+ const override = Boolean(options && options.override);
34716
+ if (typeof parsed !== "object") {
34717
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
34718
+ err.code = "OBJECT_REQUIRED";
34719
+ throw err;
34720
+ }
34721
+ for (const key of Object.keys(parsed)) {
34722
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
34723
+ if (override === true) {
34724
+ processEnv[key] = parsed[key];
34725
+ }
34726
+ if (debug) {
34727
+ if (override === true) {
34728
+ _debug(`"${key}" is already defined and WAS overwritten`);
34729
+ } else {
34730
+ _debug(`"${key}" is already defined and was NOT overwritten`);
34731
+ }
34732
+ }
34733
+ } else {
34734
+ processEnv[key] = parsed[key];
34735
+ }
34736
+ }
34737
+ }
34738
+ var DotenvModule = {
34739
+ configDotenv,
34740
+ _configVault,
34741
+ _parseVault,
34742
+ config,
34743
+ decrypt,
34744
+ parse: parse2,
34745
+ populate
34746
+ };
34747
+ module2.exports.configDotenv = DotenvModule.configDotenv;
34748
+ module2.exports._configVault = DotenvModule._configVault;
34749
+ module2.exports._parseVault = DotenvModule._parseVault;
34750
+ module2.exports.config = DotenvModule.config;
34751
+ module2.exports.decrypt = DotenvModule.decrypt;
34752
+ module2.exports.parse = DotenvModule.parse;
34753
+ module2.exports.populate = DotenvModule.populate;
34754
+ module2.exports = DotenvModule;
34755
+ }
34756
+ });
34757
+
34419
34758
  // node_modules/web-streams-polyfill/dist/ponyfill.es2018.js
34420
34759
  var require_ponyfill_es2018 = __commonJS({
34421
34760
  "node_modules/web-streams-polyfill/dist/ponyfill.es2018.js"(exports2, module2) {
@@ -39555,6 +39894,9 @@ var {
39555
39894
  Help
39556
39895
  } = import_index.default;
39557
39896
 
39897
+ // package.json
39898
+ var version = "0.0.21";
39899
+
39558
39900
  // src/lib/config/text.ts
39559
39901
  var CLI_DESCRIPTION = "GenLayer CLI is a development environment for the GenLayer ecosystem. It allows developers to interact with the protocol by creating accounts, sending transactions, and working with Intelligent Contracts by testing, debugging, and deploying them.";
39560
39902
 
@@ -39836,10 +40178,10 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
39836
40178
  return 3;
39837
40179
  }
39838
40180
  if ("TERM_PROGRAM" in env) {
39839
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
40181
+ const version2 = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
39840
40182
  switch (env.TERM_PROGRAM) {
39841
40183
  case "iTerm.app": {
39842
- return version >= 3 ? 3 : 2;
40184
+ return version2 >= 3 ? 3 : 2;
39843
40185
  }
39844
40186
  case "Apple_Terminal": {
39845
40187
  return 2;
@@ -42145,6 +42487,36 @@ var inquirer = {
42145
42487
  };
42146
42488
  var inquirer_default = inquirer;
42147
42489
 
42490
+ // src/lib/config/simulator.ts
42491
+ var DEFAULT_JSON_RPC_URL = "http://localhost:4000/api";
42492
+ var DEFAULT_REPO_GH_URL = "git@github.com:yeagerai/genlayer-simulator.git";
42493
+ var DEFAULT_CONFIG_SIMULATOR_COMMAND = (simulatorLocation) => ({
42494
+ darwin: `cd ${simulatorLocation} && cp .env.example .env`,
42495
+ win32: `cd ${simulatorLocation} && xcopy .env.example .env`,
42496
+ linux: `cd ${simulatorLocation} && cp .env.example .env`
42497
+ });
42498
+ var DEFAULT_RUN_SIMULATOR_COMMAND = (simulatorLocation) => ({
42499
+ darwin: `osascript -e 'tell application "Terminal" to do script "cd ${simulatorLocation} && docker compose build && docker compose up"'`,
42500
+ win32: `start cmd.exe /k "cd ${simulatorLocation} && docker compose build && docker compose up"`,
42501
+ linux: `x-terminal-emulator -e bash -c 'cd ${simulatorLocation} && docker compose build && docker compose up; echo "Press enter to exit"; read'`
42502
+ });
42503
+ var DEFAULT_RUN_OLLAMA_COMMAND = (simulatorLocation) => ({
42504
+ darwin: `osascript -e 'tell application "Terminal" to do script "cd ${simulatorLocation} && docker exec -it ollama ollama run llama2"'`,
42505
+ win32: `start cmd.exe /k "cd ${simulatorLocation} && docker exec -it ollama ollama run llama2"`,
42506
+ linux: `x-terminal-emulator -e bash -c 'cd ${simulatorLocation} && docker exec -it ollama ollama run llama2; echo "Press enter to exit"; read'`
42507
+ });
42508
+ var AVAILABLE_PLATFORMS = ["darwin", "win32", "linux"];
42509
+ var STARTING_TIMEOUT_WAIT_CYLCE = 2e3;
42510
+ var STARTING_TIMEOUT_ATTEMPTS = 120;
42511
+ var AI_PROVIDERS_CONFIG = {
42512
+ ollama: { name: "Ollama", envVar: "ollama", cliOptionValue: "ollama" },
42513
+ openai: { name: "OpenAI", envVar: "GENVMOPENAIKEY", cliOptionValue: "openai" }
42514
+ };
42515
+
42516
+ // src/lib/services/simulator.ts
42517
+ var fs2 = __toESM(require("fs"));
42518
+ var dotenv = __toESM(require_main2());
42519
+
42148
42520
  // node_modules/node-fetch/src/index.js
42149
42521
  var import_node_http2 = __toESM(require("http"), 1);
42150
42522
  var import_node_https = __toESM(require("https"), 1);
@@ -43498,18 +43870,6 @@ function v4(options, buf, offset) {
43498
43870
  }
43499
43871
  var v4_default = v4;
43500
43872
 
43501
- // src/lib/config/simulator.ts
43502
- var DEFAULT_JSON_RPC_URL = "http://localhost:4000/api";
43503
- var DEFAULT_REPO_GH_URL = "git@github.com:yeagerai/genlayer-simulator.git";
43504
- var DEFAULT_RUN_SIMULATOR_COMMAND = (simulatorLocation) => ({
43505
- darwin: `osascript -e 'tell application "Terminal" to do script "cd ${simulatorLocation} && cp .env.example .env && docker compose build && docker compose up"'`,
43506
- win32: `start cmd.exe /k "cd ${simulatorLocation} && xcopy .env.example .env && docker compose build && docker compose up"`,
43507
- linux: `x-terminal-emulator -e 'bash -c "cd ${simulatorLocation} && cp .env.example .env && docker compose build && docker compose up"'`
43508
- });
43509
- var AVAILABLE_PLATFORMS = ["darwin", "win32", "linux"];
43510
- var STARTING_TIMEOUT_WAIT_CYLCE = 2e3;
43511
- var STARTING_TIMEOUT_ATTEMPTS = 60;
43512
-
43513
43873
  // src/lib/clients/jsonRpcClient.ts
43514
43874
  var JsonRpcClient = class {
43515
43875
  constructor(serverUrl) {
@@ -43567,8 +43927,10 @@ function checkCommand(command, toolName) {
43567
43927
  console.log(`${toolName} is installed.`);
43568
43928
  });
43569
43929
  }
43570
- function executeCommand(command, toolName) {
43930
+ function executeCommand(cmdsByPlatform, toolName) {
43571
43931
  try {
43932
+ const runningPlatform = getPlatform();
43933
+ const command = cmdsByPlatform[runningPlatform];
43572
43934
  return asyncExec(command);
43573
43935
  } catch (error) {
43574
43936
  throw new Error(`Error executing ${toolName}: ${error.message}`);
@@ -43601,6 +43963,19 @@ function getSimulatorLocation() {
43601
43963
  function sleep(millliseconds) {
43602
43964
  return new Promise((resolve) => setTimeout(resolve, millliseconds));
43603
43965
  }
43966
+ function addConfigToEnvFile(newConfig) {
43967
+ const simulatorLocation = getSimulatorLocation();
43968
+ const envFilePath = `${simulatorLocation}/.env`;
43969
+ fs2.writeFileSync(`${envFilePath}.bak`, fs2.readFileSync(envFilePath));
43970
+ const envConfig = dotenv.parse(fs2.readFileSync(envFilePath, "utf8"));
43971
+ Object.keys(newConfig).forEach((key) => {
43972
+ envConfig[key] = newConfig[key];
43973
+ });
43974
+ const updatedConfig = Object.keys(envConfig).map((key) => {
43975
+ return `${key}=${envConfig[key]}`;
43976
+ }).join("\n");
43977
+ fs2.writeFileSync(envFilePath, updatedConfig);
43978
+ }
43604
43979
  function checkRequirements() {
43605
43980
  return __async(this, null, function* () {
43606
43981
  const requirementsInstalled = {
@@ -43630,9 +44005,12 @@ function downloadSimulator() {
43630
44005
  return __async(this, null, function* () {
43631
44006
  const simulatorLocation = getSimulatorLocation();
43632
44007
  try {
43633
- yield executeCommand(`git clone ${DEFAULT_REPO_GH_URL} ${simulatorLocation}`, "git");
44008
+ const gitCommand = `git clone ${DEFAULT_REPO_GH_URL} ${simulatorLocation}`;
44009
+ const cmdsByPlatform = { darwin: gitCommand, win32: gitCommand, linux: gitCommand };
44010
+ yield executeCommand(cmdsByPlatform, "git");
43634
44011
  } catch (error) {
43635
- if (error.toString().includes("already exists and is not an empty directory")) {
44012
+ const simulatorLocationExists = fs2.existsSync(simulatorLocation);
44013
+ if (simulatorLocationExists) {
43636
44014
  return { wasInstalled: true };
43637
44015
  }
43638
44016
  throw error;
@@ -43643,17 +44021,29 @@ function downloadSimulator() {
43643
44021
  function updateSimulator() {
43644
44022
  return __async(this, null, function* () {
43645
44023
  const simulatorLocation = getSimulatorLocation();
43646
- try {
43647
- yield executeCommand(`cd ${simulatorLocation} && git pull`, "git");
43648
- } catch (error) {
43649
- if (error.toString().includes("already exists and is not an empty directory")) {
43650
- return { wasInstalled: true };
43651
- }
43652
- throw error;
43653
- }
44024
+ const gitCommand = `cd ${simulatorLocation} && git pull`;
44025
+ const cmdsByPlatform = { darwin: gitCommand, win32: gitCommand, linux: gitCommand };
44026
+ yield executeCommand(cmdsByPlatform, "git");
43654
44027
  return { wasInstalled: false };
43655
44028
  });
43656
44029
  }
44030
+ function runOllamaModel() {
44031
+ return __async(this, null, function* () {
44032
+ const simulatorLocation = getSimulatorLocation();
44033
+ const cmdsByPlatform = DEFAULT_RUN_OLLAMA_COMMAND(simulatorLocation);
44034
+ yield executeCommandInNewTerminal(cmdsByPlatform);
44035
+ return true;
44036
+ });
44037
+ }
44038
+ function configSimulator(newConfig) {
44039
+ return __async(this, null, function* () {
44040
+ const simulatorLocation = getSimulatorLocation();
44041
+ const commandsByPlatform = DEFAULT_CONFIG_SIMULATOR_COMMAND(simulatorLocation);
44042
+ yield executeCommand(commandsByPlatform, "copy (cp)");
44043
+ addConfigToEnvFile(newConfig);
44044
+ return true;
44045
+ });
44046
+ }
43657
44047
  function runSimulator() {
43658
44048
  const simulatorLocation = getSimulatorLocation();
43659
44049
  const commandsByPlatform = DEFAULT_RUN_SIMULATOR_COMMAND(simulatorLocation);
@@ -43661,24 +44051,29 @@ function runSimulator() {
43661
44051
  }
43662
44052
  function waitForSimulatorToBeReady() {
43663
44053
  return __async(this, arguments, function* (retries = STARTING_TIMEOUT_ATTEMPTS) {
44054
+ console.log("Waiting for Simulator to be ready...:");
43664
44055
  try {
43665
44056
  const response = yield rpcClient.request({ method: "ping", params: [] });
43666
44057
  if (response && response.result.status === "OK") {
43667
- return true;
44058
+ return { initialized: true };
43668
44059
  }
43669
44060
  if (retries > 0) {
43670
44061
  yield sleep(STARTING_TIMEOUT_WAIT_CYLCE);
43671
44062
  return waitForSimulatorToBeReady(retries - 1);
43672
44063
  }
43673
44064
  } catch (error) {
43674
- if (error.message.includes("ECONNREFUSED") && retries > 0) {
44065
+ if ((error.message.includes("ECONNREFUSED") || error.message.includes("socket hang up")) && retries > 0) {
43675
44066
  yield sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
43676
44067
  return waitForSimulatorToBeReady(retries - 1);
43677
44068
  }
44069
+ return { initialized: false, error: "ERROR" };
43678
44070
  }
43679
- return false;
44071
+ return { initialized: false, error: "TIMEOUT" };
43680
44072
  });
43681
44073
  }
44074
+ function clearDatabaseTables() {
44075
+ return rpcClient.request({ method: "clear_tables", params: [] });
44076
+ }
43682
44077
  function initializeDatabase() {
43683
44078
  return __async(this, null, function* () {
43684
44079
  const createResponse = yield rpcClient.request({ method: "create_db", params: [] });
@@ -43686,6 +44081,17 @@ function initializeDatabase() {
43686
44081
  return { createResponse, tablesResponse };
43687
44082
  });
43688
44083
  }
44084
+ function createRandomValidators() {
44085
+ return rpcClient.request({ method: "create_random_validators", params: [10, 1, 10] });
44086
+ }
44087
+ function deleteAllValidators() {
44088
+ return rpcClient.request({ method: "delete_all_validators", params: [] });
44089
+ }
44090
+ function getAiProvidersOptions() {
44091
+ return Object.values(AI_PROVIDERS_CONFIG).map((providerConfig) => {
44092
+ return { name: providerConfig.name, value: providerConfig.cliOptionValue };
44093
+ });
44094
+ }
43689
44095
 
43690
44096
  // src/commands/general/init.ts
43691
44097
  function getRequirementsErrorMessage({ git, docker }) {
@@ -43736,6 +44142,50 @@ function initAction(options) {
43736
44142
  console.error(error);
43737
44143
  return;
43738
44144
  }
44145
+ const questions = [
44146
+ {
44147
+ type: "checkbox",
44148
+ name: "selectedLlmProviders",
44149
+ message: "Select which LLM providers do you want to use:",
44150
+ choices: getAiProvidersOptions(),
44151
+ validate: function(answer) {
44152
+ if (answer.length < 1) {
44153
+ return "You must choose at least one option.";
44154
+ }
44155
+ return true;
44156
+ }
44157
+ }
44158
+ ];
44159
+ const llmProvidersAnswer = yield inquirer_default.prompt(questions);
44160
+ const selectedLlmProviders = llmProvidersAnswer.selectedLlmProviders;
44161
+ const aiProvidersEnvVars = {};
44162
+ const configurableAiProviders = selectedLlmProviders.filter((provider) => provider !== "ollama");
44163
+ for (let i2 = 0; i2 < configurableAiProviders.length; i2++) {
44164
+ const provider = configurableAiProviders[i2];
44165
+ const providerConfig = AI_PROVIDERS_CONFIG[provider];
44166
+ const questions2 = [
44167
+ {
44168
+ type: "password",
44169
+ name: providerConfig.cliOptionValue,
44170
+ message: `Please enter your ${providerConfig.name} API Key:`,
44171
+ validate: function(value) {
44172
+ if (value.length) {
44173
+ return true;
44174
+ }
44175
+ return `Please enter a valid API Key for ${providerConfig.name}.`;
44176
+ }
44177
+ }
44178
+ ];
44179
+ const apiKeyAnswer = yield inquirer_default.prompt(questions2);
44180
+ aiProvidersEnvVars[providerConfig.envVar] = apiKeyAnswer[providerConfig.cliOptionValue];
44181
+ }
44182
+ console.log("Configuring GenLayer Simulator environment...");
44183
+ try {
44184
+ yield configSimulator(aiProvidersEnvVars);
44185
+ } catch (error) {
44186
+ console.error(error);
44187
+ return;
44188
+ }
43739
44189
  console.log("Running the GenLayer Simulator...");
43740
44190
  try {
43741
44191
  yield runSimulator();
@@ -43744,18 +44194,28 @@ function initAction(options) {
43744
44194
  return;
43745
44195
  }
43746
44196
  try {
43747
- const initialized = yield waitForSimulatorToBeReady();
43748
- if (!initialized) {
44197
+ const { initialized, error } = yield waitForSimulatorToBeReady();
44198
+ if (!initialized && error === "ERROR") {
43749
44199
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
43750
44200
  return;
43751
44201
  }
44202
+ if (!initialized && error === "TIMEOUT") {
44203
+ console.error(
44204
+ "The simulator is taking too lonk to initialize. Please try again after the simulator is ready."
44205
+ );
44206
+ return;
44207
+ }
43752
44208
  console.log("Simulator is running!");
43753
44209
  } catch (error) {
43754
44210
  console.error(error);
43755
44211
  return;
43756
44212
  }
44213
+ if (selectedLlmProviders.includes("ollama")) {
44214
+ yield runOllamaModel();
44215
+ }
43757
44216
  console.log("Initializing the database...");
43758
44217
  try {
44218
+ yield clearDatabaseTables();
43759
44219
  const { createResponse, tablesResponse } = yield initializeDatabase();
43760
44220
  if (!createResponse || !tablesResponse) {
43761
44221
  console.error("Unable to initialize the database. Please try again.");
@@ -43765,6 +44225,15 @@ function initAction(options) {
43765
44225
  console.error(error);
43766
44226
  return;
43767
44227
  }
44228
+ console.log("Initializing validators...");
44229
+ try {
44230
+ yield deleteAllValidators();
44231
+ yield createRandomValidators();
44232
+ } catch (error) {
44233
+ console.error("Unable to initialize the validators.");
44234
+ console.error(error);
44235
+ return;
44236
+ }
43768
44237
  console.log("GenLayer simulator initialized successfully!");
43769
44238
  });
43770
44239
  }
@@ -43776,7 +44245,7 @@ function initializeGeneralCommands(program2) {
43776
44245
  }
43777
44246
 
43778
44247
  // src/index.ts
43779
- program.version("0.0.1").description(CLI_DESCRIPTION);
44248
+ program.version(version).description(CLI_DESCRIPTION);
43780
44249
  initializeGeneralCommands(program);
43781
44250
  program.parse(process.argv);
43782
44251
  /*! Bundled license information:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -53,6 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "commander": "^12.0.0",
56
+ "dotenv": "^16.4.5",
56
57
  "inquirer": "^9.2.19",
57
58
  "node-fetch": "^3.3.2",
58
59
  "uuid": "^9.0.1"
@@ -1,12 +1,19 @@
1
1
  import inquirer from "inquirer";
2
2
 
3
+ import {AI_PROVIDERS_CONFIG, AiProviders} from "@/lib/config/simulator";
3
4
  import {
4
5
  initializeDatabase,
5
6
  checkRequirements,
6
7
  downloadSimulator,
8
+ configSimulator,
7
9
  runSimulator,
8
10
  waitForSimulatorToBeReady,
9
11
  updateSimulator,
12
+ clearDatabaseTables,
13
+ createRandomValidators,
14
+ deleteAllValidators,
15
+ runOllamaModel,
16
+ getAiProvidersOptions,
10
17
  } from "@/lib/services/simulator";
11
18
  export interface InitActionOptions {
12
19
  numValidators: number;
@@ -68,6 +75,58 @@ export async function initAction(options: InitActionOptions) {
68
75
  return;
69
76
  }
70
77
 
78
+ // Check LLM configuration
79
+ const questions = [
80
+ {
81
+ type: "checkbox",
82
+ name: "selectedLlmProviders",
83
+ message: "Select which LLM providers do you want to use:",
84
+ choices: getAiProvidersOptions(),
85
+ validate: function (answer: string[]) {
86
+ if (answer.length < 1) {
87
+ return "You must choose at least one option.";
88
+ }
89
+ return true;
90
+ },
91
+ },
92
+ ];
93
+
94
+ // Since ollama runs locally we can run it here and then look for the other providers
95
+ const llmProvidersAnswer = await inquirer.prompt(questions);
96
+ const selectedLlmProviders = llmProvidersAnswer.selectedLlmProviders as AiProviders[];
97
+
98
+ // Gather the API Keys
99
+ const aiProvidersEnvVars: Record<string, string> = {};
100
+ const configurableAiProviders = selectedLlmProviders.filter((provider: string) => provider !== "ollama");
101
+ for (let i = 0; i < configurableAiProviders.length; i++) {
102
+ const provider = configurableAiProviders[i];
103
+ const providerConfig = AI_PROVIDERS_CONFIG[provider];
104
+ const questions = [
105
+ {
106
+ type: "password",
107
+ name: providerConfig.cliOptionValue,
108
+ message: `Please enter your ${providerConfig.name} API Key:`,
109
+ validate: function (value: string) {
110
+ if (value.length) {
111
+ return true;
112
+ }
113
+ return `Please enter a valid API Key for ${providerConfig.name}.`;
114
+ },
115
+ },
116
+ ];
117
+
118
+ const apiKeyAnswer = await inquirer.prompt(questions);
119
+ aiProvidersEnvVars[providerConfig.envVar] = apiKeyAnswer[providerConfig.cliOptionValue];
120
+ }
121
+
122
+ console.log("Configuring GenLayer Simulator environment...");
123
+ try {
124
+ await configSimulator(aiProvidersEnvVars);
125
+ } catch (error) {
126
+ console.error(error);
127
+ return;
128
+ }
129
+
71
130
  // Run the GenLayer Simulator
72
131
  console.log("Running the GenLayer Simulator...");
73
132
  try {
@@ -78,20 +137,34 @@ export async function initAction(options: InitActionOptions) {
78
137
  }
79
138
 
80
139
  try {
81
- const initialized = await waitForSimulatorToBeReady();
82
- if (!initialized) {
140
+ const {initialized, error} = await waitForSimulatorToBeReady();
141
+ if (!initialized && error === "ERROR") {
83
142
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
84
143
  return;
85
144
  }
145
+ if (!initialized && error === "TIMEOUT") {
146
+ console.error(
147
+ "The simulator is taking too lonk to initialize. Please try again after the simulator is ready.",
148
+ );
149
+ return;
150
+ }
86
151
  console.log("Simulator is running!");
87
152
  } catch (error) {
88
153
  console.error(error);
89
154
  return;
90
155
  }
91
156
 
157
+ // Ollama doesn't need changes in configuration, we just run it
158
+ if (selectedLlmProviders.includes("ollama")) {
159
+ await runOllamaModel();
160
+ }
161
+
92
162
  // Initialize the database
93
163
  console.log("Initializing the database...");
94
164
  try {
165
+ //remove everything from the database
166
+ await clearDatabaseTables();
167
+
95
168
  const {createResponse, tablesResponse} = await initializeDatabase();
96
169
  if (!createResponse || !tablesResponse) {
97
170
  console.error("Unable to initialize the database. Please try again.");
@@ -101,5 +174,19 @@ export async function initAction(options: InitActionOptions) {
101
174
  console.error(error);
102
175
  return;
103
176
  }
177
+
178
+ // Initializing validators
179
+ console.log("Initializing validators...");
180
+ try {
181
+ //remove all validators
182
+ await deleteAllValidators();
183
+ // create random validators
184
+ await createRandomValidators();
185
+ } catch (error) {
186
+ console.error("Unable to initialize the validators.");
187
+ console.error(error);
188
+ return;
189
+ }
190
+
104
191
  console.log("GenLayer simulator initialized successfully!");
105
192
  }
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import {program} from "commander";
3
-
3
+ import {version} from "../package.json";
4
4
  import {CLI_DESCRIPTION} from "@/lib/config/text";
5
5
  import {initializeGeneralCommands} from "@/commands/general";
6
6
 
7
- program.version("0.0.1").description(CLI_DESCRIPTION);
7
+ program.version(version).description(CLI_DESCRIPTION);
8
8
 
9
9
  initializeGeneralCommands(program);
10
10
 
@@ -20,18 +20,23 @@ type ExecuteCommandResult = {
20
20
  stderr: string;
21
21
  };
22
22
 
23
- export function executeCommand(command: string, toolName: string): Promise<ExecuteCommandResult> {
23
+ type ExecuteCommandInNewTerminalInput = {
24
+ [key in RunningPlatform]: string;
25
+ };
26
+
27
+ export function executeCommand(
28
+ cmdsByPlatform: ExecuteCommandInNewTerminalInput,
29
+ toolName: string,
30
+ ): Promise<ExecuteCommandResult> {
24
31
  try {
32
+ const runningPlatform = getPlatform();
33
+ const command = cmdsByPlatform[runningPlatform];
25
34
  return asyncExec(command);
26
35
  } catch (error: any) {
27
36
  throw new Error(`Error executing ${toolName}: ${error.message}`);
28
37
  }
29
38
  }
30
39
 
31
- type ExecuteCommandInNewTerminalInput = {
32
- [key in RunningPlatform]: string;
33
- };
34
-
35
40
  export function executeCommandInNewTerminal(
36
41
  cmdsByPlatform: ExecuteCommandInNewTerminalInput,
37
42
  ): PromiseWithChild<{stdout: string; stderr: string}> {
@@ -1,11 +1,32 @@
1
1
  export const DEFAULT_JSON_RPC_URL = "http://localhost:4000/api";
2
2
  export const DEFAULT_REPO_GH_URL = "git@github.com:yeagerai/genlayer-simulator.git";
3
+ export const DEFAULT_CONFIG_SIMULATOR_COMMAND = (simulatorLocation: string) => ({
4
+ darwin: `cd ${simulatorLocation} && cp .env.example .env`,
5
+ win32: `cd ${simulatorLocation} && xcopy .env.example .env`,
6
+ linux: `cd ${simulatorLocation} && cp .env.example .env`,
7
+ });
3
8
  export const DEFAULT_RUN_SIMULATOR_COMMAND = (simulatorLocation: string) => ({
4
- darwin: `osascript -e 'tell application "Terminal" to do script "cd ${simulatorLocation} && cp .env.example .env && docker compose build && docker compose up"'`,
5
- win32: `start cmd.exe /k "cd ${simulatorLocation} && xcopy .env.example .env && docker compose build && docker compose up"`,
6
- linux: `x-terminal-emulator -e 'bash -c "cd ${simulatorLocation} && cp .env.example .env && docker compose build && docker compose up"'`,
9
+ darwin: `osascript -e 'tell application "Terminal" to do script "cd ${simulatorLocation} && docker compose build && docker compose up"'`,
10
+ win32: `start cmd.exe /k "cd ${simulatorLocation} && docker compose build && docker compose up"`,
11
+ linux: `x-terminal-emulator -e bash -c 'cd ${simulatorLocation} && docker compose build && docker compose up; echo "Press enter to exit"; read'`,
12
+ });
13
+ export const DEFAULT_RUN_OLLAMA_COMMAND = (simulatorLocation: string) => ({
14
+ darwin: `osascript -e 'tell application "Terminal" to do script "cd ${simulatorLocation} && docker exec -it ollama ollama run llama2"'`,
15
+ win32: `start cmd.exe /k "cd ${simulatorLocation} && docker exec -it ollama ollama run llama2"`,
16
+ linux: `x-terminal-emulator -e bash -c 'cd ${simulatorLocation} && docker exec -it ollama ollama run llama2; echo "Press enter to exit"; read'`,
7
17
  });
8
18
  export const AVAILABLE_PLATFORMS = ["darwin", "win32", "linux"] as const;
9
19
  export type RunningPlatform = (typeof AVAILABLE_PLATFORMS)[number];
10
20
  export const STARTING_TIMEOUT_WAIT_CYLCE = 2000;
11
- export const STARTING_TIMEOUT_ATTEMPTS = 60;
21
+ export const STARTING_TIMEOUT_ATTEMPTS = 120;
22
+
23
+ export type AiProviders = "ollama" | "openai";
24
+ export type AiProvidersEnvVars = "ollama" | "GENVMOPENAIKEY";
25
+ export type AiProvidersConfigType = {
26
+ [key in AiProviders]: {name: string; envVar: AiProvidersEnvVars; cliOptionValue: string};
27
+ };
28
+
29
+ export const AI_PROVIDERS_CONFIG: AiProvidersConfigType = {
30
+ ollama: {name: "Ollama", envVar: "ollama", cliOptionValue: "ollama"},
31
+ openai: {name: "OpenAI", envVar: "GENVMOPENAIKEY", cliOptionValue: "openai"},
32
+ };
@@ -1,9 +1,15 @@
1
+ import * as fs from "fs";
2
+ import * as dotenv from "dotenv";
3
+
1
4
  import {rpcClient} from "@/lib/clients/jsonRpcClient";
2
5
  import {
3
6
  DEFAULT_REPO_GH_URL,
4
7
  DEFAULT_RUN_SIMULATOR_COMMAND,
8
+ DEFAULT_CONFIG_SIMULATOR_COMMAND,
9
+ DEFAULT_RUN_OLLAMA_COMMAND,
5
10
  STARTING_TIMEOUT_WAIT_CYLCE,
6
11
  STARTING_TIMEOUT_ATTEMPTS,
12
+ AI_PROVIDERS_CONFIG,
7
13
  } from "@/lib/config/simulator";
8
14
  import {
9
15
  checkCommand,
@@ -22,6 +28,30 @@ function sleep(millliseconds: number): Promise<void> {
22
28
  return new Promise(resolve => setTimeout(resolve, millliseconds));
23
29
  }
24
30
 
31
+ function addConfigToEnvFile(newConfig: Record<string, string>): void {
32
+ const simulatorLocation = getSimulatorLocation();
33
+ const envFilePath = `${simulatorLocation}/.env`;
34
+
35
+ // Create a backup of the original .env file
36
+ fs.writeFileSync(`${envFilePath}.bak`, fs.readFileSync(envFilePath));
37
+
38
+ // Transform the config string to object
39
+ const envConfig = dotenv.parse(fs.readFileSync(envFilePath, "utf8"));
40
+ Object.keys(newConfig).forEach(key => {
41
+ envConfig[key] = newConfig[key];
42
+ });
43
+
44
+ // Transform the updated config object back into a string
45
+ const updatedConfig = Object.keys(envConfig)
46
+ .map(key => {
47
+ return `${key}=${envConfig[key]}`;
48
+ })
49
+ .join("\n");
50
+
51
+ // Write the new .env file
52
+ fs.writeFileSync(envFilePath, updatedConfig);
53
+ }
54
+
25
55
  // Public functions
26
56
  export async function checkRequirements(): Promise<Record<string, boolean>> {
27
57
  const requirementsInstalled = {
@@ -57,9 +87,12 @@ export async function downloadSimulator(): Promise<DownloadSimulatorResultType>
57
87
  const simulatorLocation = getSimulatorLocation();
58
88
 
59
89
  try {
60
- await executeCommand(`git clone ${DEFAULT_REPO_GH_URL} ${simulatorLocation}`, "git");
90
+ const gitCommand = `git clone ${DEFAULT_REPO_GH_URL} ${simulatorLocation}`;
91
+ const cmdsByPlatform = {darwin: gitCommand, win32: gitCommand, linux: gitCommand};
92
+ await executeCommand(cmdsByPlatform, "git");
61
93
  } catch (error: any) {
62
- if (error.toString().includes("already exists and is not an empty directory")) {
94
+ const simulatorLocationExists = fs.existsSync(simulatorLocation);
95
+ if (simulatorLocationExists) {
63
96
  return {wasInstalled: true};
64
97
  }
65
98
  throw error;
@@ -69,44 +102,64 @@ export async function downloadSimulator(): Promise<DownloadSimulatorResultType>
69
102
 
70
103
  export async function updateSimulator(): Promise<DownloadSimulatorResultType> {
71
104
  const simulatorLocation = getSimulatorLocation();
72
-
73
- try {
74
- await executeCommand(`cd ${simulatorLocation} && git pull`, "git");
75
- } catch (error: any) {
76
- if (error.toString().includes("already exists and is not an empty directory")) {
77
- return {wasInstalled: true};
78
- }
79
- throw error;
80
- }
105
+ const gitCommand = `cd ${simulatorLocation} && git pull`;
106
+ const cmdsByPlatform = {darwin: gitCommand, win32: gitCommand, linux: gitCommand};
107
+ await executeCommand(cmdsByPlatform, "git");
81
108
  return {wasInstalled: false};
82
109
  }
83
110
 
111
+ export async function runOllamaModel(): Promise<boolean> {
112
+ const simulatorLocation = getSimulatorLocation();
113
+ const cmdsByPlatform = DEFAULT_RUN_OLLAMA_COMMAND(simulatorLocation);
114
+ await executeCommandInNewTerminal(cmdsByPlatform);
115
+ return true;
116
+ }
117
+
118
+ export async function configSimulator(newConfig: Record<string, string>): Promise<boolean> {
119
+ const simulatorLocation = getSimulatorLocation();
120
+ const commandsByPlatform = DEFAULT_CONFIG_SIMULATOR_COMMAND(simulatorLocation);
121
+ await executeCommand(commandsByPlatform, "copy (cp)");
122
+ addConfigToEnvFile(newConfig);
123
+ return true;
124
+ }
125
+
84
126
  export function runSimulator(): Promise<{stdout: string; stderr: string}> {
85
127
  const simulatorLocation = getSimulatorLocation();
86
128
  const commandsByPlatform = DEFAULT_RUN_SIMULATOR_COMMAND(simulatorLocation);
87
129
  return executeCommandInNewTerminal(commandsByPlatform);
88
130
  }
89
131
 
132
+ type WaitForSimulatorToBeReadyResultType = {
133
+ initialized: boolean;
134
+ error?: "TIMEOUT" | "ERROR";
135
+ };
136
+
90
137
  export async function waitForSimulatorToBeReady(
91
138
  retries: number = STARTING_TIMEOUT_ATTEMPTS,
92
- ): Promise<boolean> {
139
+ ): Promise<WaitForSimulatorToBeReadyResultType> {
140
+ console.log("Waiting for Simulator to be ready...:");
93
141
  try {
94
142
  const response = await rpcClient.request({method: "ping", params: []});
95
143
  if (response && response.result.status === "OK") {
96
- return true;
144
+ return {initialized: true};
97
145
  }
98
146
  if (retries > 0) {
99
147
  await sleep(STARTING_TIMEOUT_WAIT_CYLCE);
100
148
  return waitForSimulatorToBeReady(retries - 1);
101
149
  }
102
150
  } catch (error: any) {
103
- if (error.message.includes("ECONNREFUSED") && retries > 0) {
151
+ if ((error.message.includes("ECONNREFUSED") || error.message.includes("socket hang up")) && retries > 0) {
104
152
  await sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
105
153
  return waitForSimulatorToBeReady(retries - 1);
106
154
  }
155
+ return {initialized: false, error: "ERROR"};
107
156
  }
108
157
 
109
- return false;
158
+ return {initialized: false, error: "TIMEOUT"};
159
+ }
160
+
161
+ export function clearDatabaseTables(): Promise<any> {
162
+ return rpcClient.request({method: "clear_tables", params: []});
110
163
  }
111
164
 
112
165
  type InitializeDatabaseResultType = {
@@ -119,3 +172,17 @@ export async function initializeDatabase(): Promise<InitializeDatabaseResultType
119
172
  const tablesResponse = await rpcClient.request({method: "create_tables", params: []});
120
173
  return {createResponse, tablesResponse};
121
174
  }
175
+
176
+ export function createRandomValidators(): Promise<any> {
177
+ return rpcClient.request({method: "create_random_validators", params: [10, 1, 10]});
178
+ }
179
+
180
+ export function deleteAllValidators(): Promise<any> {
181
+ return rpcClient.request({method: "delete_all_validators", params: []});
182
+ }
183
+
184
+ export function getAiProvidersOptions(): Array<{name: string; value: string}> {
185
+ return Object.values(AI_PROVIDERS_CONFIG).map(providerConfig => {
186
+ return {name: providerConfig.name, value: providerConfig.cliOptionValue};
187
+ });
188
+ }
package/tsconfig.json CHANGED
@@ -45,7 +45,7 @@
45
45
  // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
46
46
  // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
47
47
  // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
48
- // "resolveJsonModule": true, /* Enable importing .json files. */
48
+ "resolveJsonModule": true /* Enable importing .json files. */,
49
49
  // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
50
50
  // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
51
51