genlayer 0.0.27 → 0.0.29

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.29 (2024-05-15)
4
+
5
+ ## 0.0.28 (2024-05-13)
6
+
3
7
  ## 0.0.27 (2024-05-08)
4
8
 
5
9
  ## 0.0.26 (2024-05-07)
package/dist/index.js CHANGED
@@ -39896,7 +39896,7 @@ var {
39896
39896
  } = import_index.default;
39897
39897
 
39898
39898
  // package.json
39899
- var version = "0.0.27";
39899
+ var version = "0.0.29";
39900
39900
 
39901
39901
  // src/lib/config/text.ts
39902
39902
  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.";
@@ -42497,27 +42497,30 @@ var DEFAULT_RUN_SIMULATOR_COMMAND = (simulatorLocation) => ({
42497
42497
  linux: `x-terminal-emulator -e bash -c 'cd ${simulatorLocation} && docker compose build && docker compose up; echo "Press enter to exit"; read'`
42498
42498
  });
42499
42499
  var DEFAULT_PULL_OLLAMA_COMMAND = (simulatorLocation) => ({
42500
- darwin: `osascript -e 'tell application "Terminal" to do script "cd ${simulatorLocation} && docker exec ollama ollama pull llama2"'`,
42501
- win32: `start cmd.exe /c "cd /d ${simulatorLocation} && docker exec ollama ollama pull llama2"`,
42502
- linux: `x-terminal-emulator -e bash -c 'cd ${simulatorLocation} && docker exec ollama ollama pull llama2'`
42500
+ darwin: `cd ${simulatorLocation} && docker exec ollama ollama pull llama3`,
42501
+ win32: `cd /d ${simulatorLocation} && docker exec ollama ollama pull llama3`,
42502
+ linux: `cd ${simulatorLocation} && docker exec ollama ollama pull llama3`
42503
42503
  });
42504
42504
  var AVAILABLE_PLATFORMS = ["darwin", "win32", "linux"];
42505
42505
  var STARTING_TIMEOUT_WAIT_CYLCE = 2e3;
42506
42506
  var STARTING_TIMEOUT_ATTEMPTS = 120;
42507
42507
  var AI_PROVIDERS_CONFIG = {
42508
42508
  ollama: {
42509
- name: "Ollama (This will download and run a local instance of Llama 2)",
42509
+ name: "Ollama",
42510
+ hint: "(This will download and run a local instance of Llama 3)",
42510
42511
  cliOptionValue: "ollama"
42511
42512
  },
42512
42513
  openai: {
42513
- name: "OpenAI (You will need to provide an OpenAI API key)",
42514
+ name: "OpenAI",
42515
+ hint: "(You will need to provide an OpenAI API key)",
42514
42516
  envVar: "OPENAIKEY",
42515
42517
  cliOptionValue: "openai"
42516
42518
  },
42517
- heurist: {
42518
- name: 'Heurist (You will need to provide an API key. Get free API credits at https://dev-api-form.heurist.ai/ with referral code: "genlayer"):',
42519
+ heuristai: {
42520
+ name: "Heurist",
42521
+ hint: '(You will need to provide an API key. Get free API credits at https://dev-api-form.heurist.ai/ with referral code: "genlayer")',
42519
42522
  envVar: "HEURISTAIAPIKEY",
42520
- cliOptionValue: "heurist"
42523
+ cliOptionValue: "heuristai"
42521
42524
  }
42522
42525
  };
42523
42526
 
@@ -44381,7 +44384,6 @@ function checkCommand(command, toolName) {
44381
44384
  if (stderr) {
44382
44385
  throw new MissingRequirementError(toolName);
44383
44386
  }
44384
- console.log(`${toolName} is installed.`);
44385
44387
  });
44386
44388
  }
44387
44389
  function executeCommand(cmdsByPlatform, toolName) {
@@ -44529,7 +44531,7 @@ function waitForSimulatorToBeReady() {
44529
44531
  return waitForSimulatorToBeReady(retries - 1);
44530
44532
  }
44531
44533
  } catch (error) {
44532
- if ((error.message.includes("ECONNREFUSED") || error.message.includes("socket hang up")) && retries > 0) {
44534
+ if ((error.name === "FetchError" || error.message.includes("ECONNRESET") || error.message.includes("ECONNREFUSED") || error.message.includes("socket hang up")) && retries > 0) {
44533
44535
  yield sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
44534
44536
  return waitForSimulatorToBeReady(retries - 1);
44535
44537
  }
@@ -44548,15 +44550,21 @@ function initializeDatabase() {
44548
44550
  return { createResponse, tablesResponse };
44549
44551
  });
44550
44552
  }
44551
- function createRandomValidators() {
44552
- return rpcClient.request({ method: "create_random_validators", params: [10, 1, 10] });
44553
+ function createRandomValidators(numValidators, llmProviders) {
44554
+ return rpcClient.request({
44555
+ method: "create_random_validators",
44556
+ params: [numValidators, 1, 10, llmProviders]
44557
+ });
44553
44558
  }
44554
44559
  function deleteAllValidators() {
44555
44560
  return rpcClient.request({ method: "delete_all_validators", params: [] });
44556
44561
  }
44557
- function getAiProvidersOptions() {
44562
+ function getAiProvidersOptions(withHint = true) {
44558
44563
  return Object.values(AI_PROVIDERS_CONFIG).map((providerConfig) => {
44559
- return { name: providerConfig.name, value: providerConfig.cliOptionValue };
44564
+ return {
44565
+ name: `${providerConfig.name}${withHint ? ` ${providerConfig.hint}` : ""}`,
44566
+ value: providerConfig.cliOptionValue
44567
+ };
44560
44568
  });
44561
44569
  }
44562
44570
  function getFrontendUrl() {
@@ -44624,7 +44632,7 @@ function initAction(options) {
44624
44632
  type: "checkbox",
44625
44633
  name: "selectedLlmProviders",
44626
44634
  message: "Select which LLM providers do you want to use:",
44627
- choices: getAiProvidersOptions(),
44635
+ choices: getAiProvidersOptions(true),
44628
44636
  validate: function(answer) {
44629
44637
  if (answer.length < 1) {
44630
44638
  return "You must choose at least one option.";
@@ -44691,7 +44699,7 @@ function initAction(options) {
44691
44699
  return;
44692
44700
  }
44693
44701
  if (selectedLlmProviders.includes("ollama")) {
44694
- console.log("Pulling llama2 from Ollama...");
44702
+ console.log("Pulling llama3 from Ollama...");
44695
44703
  yield pullOllamaModel();
44696
44704
  }
44697
44705
  console.log("Initializing the database...");
@@ -44709,7 +44717,7 @@ function initAction(options) {
44709
44717
  console.log("Initializing validators...");
44710
44718
  try {
44711
44719
  yield deleteAllValidators();
44712
- yield createRandomValidators();
44720
+ yield createRandomValidators(Number(options.numValidators), selectedLlmProviders);
44713
44721
  } catch (error) {
44714
44722
  console.error("Unable to initialize the validators.");
44715
44723
  console.error(error);
@@ -44729,9 +44737,9 @@ function initAction(options) {
44729
44737
  // src/commands/general/start.ts
44730
44738
  function startAction(options) {
44731
44739
  return __async(this, null, function* () {
44732
- const { resetAccounts, resetValidators } = options;
44740
+ const { resetAccounts, resetValidators, numValidators } = options;
44733
44741
  const restartAccountsHintText = resetAccounts ? "restarting the accounts and transactions database" : "keeping the accounts and transactions records";
44734
- const restartValidatorsHintText = resetValidators ? "and creating new random validators" : "and keeping the existing validators";
44742
+ const restartValidatorsHintText = resetValidators ? `and creating new ${numValidators} random validators` : "and keeping the existing validators";
44735
44743
  console.log(`Starting GenLayer simulator ${restartAccountsHintText} ${restartValidatorsHintText}`);
44736
44744
  console.log(`Updating GenLayer Simulator...`);
44737
44745
  try {
@@ -44784,7 +44792,22 @@ function startAction(options) {
44784
44792
  console.log("Initializing validators...");
44785
44793
  try {
44786
44794
  yield deleteAllValidators();
44787
- yield createRandomValidators();
44795
+ const questions = [
44796
+ {
44797
+ type: "checkbox",
44798
+ name: "selectedLlmProviders",
44799
+ message: "Select which LLM providers do you want to use:",
44800
+ choices: getAiProvidersOptions(false),
44801
+ validate: function(answer) {
44802
+ if (answer.length < 1) {
44803
+ return "You must choose at least one option.";
44804
+ }
44805
+ return true;
44806
+ }
44807
+ }
44808
+ ];
44809
+ const llmProvidersAnswer = yield inquirer_default.prompt(questions);
44810
+ yield createRandomValidators(Number(options.numValidators), llmProvidersAnswer.selectedLlmProviders);
44788
44811
  } catch (error) {
44789
44812
  console.error("Unable to initialize the validators.");
44790
44813
  console.error(error);
@@ -44806,7 +44829,7 @@ function startAction(options) {
44806
44829
  // src/commands/general/index.ts
44807
44830
  function initializeGeneralCommands(program2) {
44808
44831
  program2.command("init").description("Initialize the GenLayer Environment").option("-n, --numValidators <numValidators>", "Number of validators", "5").action(initAction);
44809
- program2.command("up").description("Starts GenLayer's simulator").option("--no-reset-accounts", "Don't restart the database for accouts and transactions", true).option("--reset-validators", "Remove all current validators and create new random ones", false).action(startAction);
44832
+ program2.command("up").description("Starts GenLayer's simulator").option("--no-reset-accounts", "Don't restart the database for accouts and transactions", true).option("--reset-validators", "Remove all current validators and create new random ones", false).option("--numValidators <numValidators>", "Number of validators", "5").action(startAction);
44810
44833
  return program2;
44811
44834
  }
44812
44835
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -15,6 +15,7 @@ export function initializeGeneralCommands(program: Command) {
15
15
  .description("Starts GenLayer's simulator")
16
16
  .option("--no-reset-accounts", "Don't restart the database for accouts and transactions", true)
17
17
  .option("--reset-validators", "Remove all current validators and create new random ones", false)
18
+ .option("--numValidators <numValidators>", "Number of validators", "5")
18
19
  .action(startAction);
19
20
 
20
21
  return program;
@@ -84,7 +84,7 @@ export async function initAction(options: InitActionOptions) {
84
84
  type: "checkbox",
85
85
  name: "selectedLlmProviders",
86
86
  message: "Select which LLM providers do you want to use:",
87
- choices: getAiProvidersOptions(),
87
+ choices: getAiProvidersOptions(true),
88
88
  validate: function (answer: string[]) {
89
89
  if (answer.length < 1) {
90
90
  return "You must choose at least one option.";
@@ -162,7 +162,7 @@ export async function initAction(options: InitActionOptions) {
162
162
 
163
163
  // Ollama doesn't need changes in configuration, we just run it
164
164
  if (selectedLlmProviders.includes("ollama")) {
165
- console.log("Pulling llama2 from Ollama...");
165
+ console.log("Pulling llama3 from Ollama...");
166
166
  await pullOllamaModel();
167
167
  }
168
168
 
@@ -188,7 +188,7 @@ export async function initAction(options: InitActionOptions) {
188
188
  //remove all validators
189
189
  await deleteAllValidators();
190
190
  // create random validators
191
- await createRandomValidators();
191
+ await createRandomValidators(Number(options.numValidators), selectedLlmProviders);
192
192
  } catch (error) {
193
193
  console.error("Unable to initialize the validators.");
194
194
  console.error(error);
@@ -1,3 +1,5 @@
1
+ import inquirer from "inquirer";
2
+
1
3
  import {
2
4
  updateSimulator,
3
5
  runSimulator,
@@ -8,22 +10,24 @@ import {
8
10
  initializeDatabase,
9
11
  getFrontendUrl,
10
12
  openFrontend,
13
+ getAiProvidersOptions,
11
14
  } from "@/lib/services/simulator";
12
15
 
13
16
  export interface StartActionOptions {
14
17
  resetAccounts: string;
15
18
  resetValidators: string;
19
+ numValidators: number;
16
20
  }
17
21
 
18
22
  export async function startAction(options: StartActionOptions) {
19
- const {resetAccounts, resetValidators} = options;
23
+ const {resetAccounts, resetValidators, numValidators} = options;
20
24
 
21
25
  const restartAccountsHintText = resetAccounts
22
26
  ? "restarting the accounts and transactions database"
23
27
  : "keeping the accounts and transactions records";
24
28
 
25
29
  const restartValidatorsHintText = resetValidators
26
- ? "and creating new random validators"
30
+ ? `and creating new ${numValidators} random validators`
27
31
  : "and keeping the existing validators";
28
32
 
29
33
  console.log(`Starting GenLayer simulator ${restartAccountsHintText} ${restartValidatorsHintText}`);
@@ -90,8 +94,26 @@ export async function startAction(options: StartActionOptions) {
90
94
  try {
91
95
  //remove all validators
92
96
  await deleteAllValidators();
97
+ const questions = [
98
+ {
99
+ type: "checkbox",
100
+ name: "selectedLlmProviders",
101
+ message: "Select which LLM providers do you want to use:",
102
+ choices: getAiProvidersOptions(false),
103
+ validate: function (answer: string[]) {
104
+ if (answer.length < 1) {
105
+ return "You must choose at least one option.";
106
+ }
107
+ return true;
108
+ },
109
+ },
110
+ ];
111
+
112
+ // Since ollama runs locally we can run it here and then look for the other providers
113
+ const llmProvidersAnswer = await inquirer.prompt(questions);
114
+
93
115
  // create random validators
94
- await createRandomValidators();
116
+ await createRandomValidators(Number(options.numValidators), llmProvidersAnswer.selectedLlmProviders);
95
117
  } catch (error) {
96
118
  console.error("Unable to initialize the validators.");
97
119
  console.error(error);
@@ -13,7 +13,6 @@ export async function checkCommand(command: string, toolName: string): Promise<v
13
13
  if (stderr) {
14
14
  throw new MissingRequirementError(toolName);
15
15
  }
16
- console.log(`${toolName} is installed.`);
17
16
  }
18
17
 
19
18
  type ExecuteCommandResult = {
@@ -6,34 +6,37 @@ export const DEFAULT_RUN_SIMULATOR_COMMAND = (simulatorLocation: string) => ({
6
6
  linux: `x-terminal-emulator -e bash -c 'cd ${simulatorLocation} && docker compose build && docker compose up; echo "Press enter to exit"; read'`,
7
7
  });
8
8
  export const DEFAULT_PULL_OLLAMA_COMMAND = (simulatorLocation: string) => ({
9
- darwin: `osascript -e 'tell application "Terminal" to do script "cd ${simulatorLocation} && docker exec ollama ollama pull llama2"'`,
10
- win32: `start cmd.exe /c "cd /d ${simulatorLocation} && docker exec ollama ollama pull llama2"`,
11
- linux: `x-terminal-emulator -e bash -c 'cd ${simulatorLocation} && docker exec ollama ollama pull llama2'`,
9
+ darwin: `cd ${simulatorLocation} && docker exec ollama ollama pull llama3`,
10
+ win32: `cd /d ${simulatorLocation} && docker exec ollama ollama pull llama3`,
11
+ linux: `cd ${simulatorLocation} && docker exec ollama ollama pull llama3`,
12
12
  });
13
13
  export const AVAILABLE_PLATFORMS = ["darwin", "win32", "linux"] as const;
14
14
  export type RunningPlatform = (typeof AVAILABLE_PLATFORMS)[number];
15
15
  export const STARTING_TIMEOUT_WAIT_CYLCE = 2000;
16
16
  export const STARTING_TIMEOUT_ATTEMPTS = 120;
17
17
 
18
- export type AiProviders = "ollama" | "openai" | "heurist";
18
+ export type AiProviders = "ollama" | "openai" | "heuristai";
19
19
  export type AiProvidersEnvVars = "ollama" | "OPENAIKEY" | "HEURISTAIAPIKEY";
20
20
  export type AiProvidersConfigType = {
21
- [key in AiProviders]: {name: string; envVar?: AiProvidersEnvVars; cliOptionValue: string};
21
+ [key in AiProviders]: {name: string; hint: string; envVar?: AiProvidersEnvVars; cliOptionValue: string};
22
22
  };
23
23
 
24
24
  export const AI_PROVIDERS_CONFIG: AiProvidersConfigType = {
25
25
  ollama: {
26
- name: "Ollama (This will download and run a local instance of Llama 2)",
26
+ name: "Ollama",
27
+ hint: "(This will download and run a local instance of Llama 3)",
27
28
  cliOptionValue: "ollama",
28
29
  },
29
30
  openai: {
30
- name: "OpenAI (You will need to provide an OpenAI API key)",
31
+ name: "OpenAI",
32
+ hint: "(You will need to provide an OpenAI API key)",
31
33
  envVar: "OPENAIKEY",
32
34
  cliOptionValue: "openai",
33
35
  },
34
- heurist: {
35
- name: 'Heurist (You will need to provide an API key. Get free API credits at https://dev-api-form.heurist.ai/ with referral code: "genlayer"):',
36
+ heuristai: {
37
+ name: "Heurist",
38
+ hint: '(You will need to provide an API key. Get free API credits at https://dev-api-form.heurist.ai/ with referral code: "genlayer")',
36
39
  envVar: "HEURISTAIAPIKEY",
37
- cliOptionValue: "heurist",
40
+ cliOptionValue: "heuristai",
38
41
  },
39
42
  };
@@ -10,6 +10,7 @@ import {
10
10
  STARTING_TIMEOUT_WAIT_CYLCE,
11
11
  STARTING_TIMEOUT_ATTEMPTS,
12
12
  AI_PROVIDERS_CONFIG,
13
+ AiProviders,
13
14
  } from "@/lib/config/simulator";
14
15
  import {
15
16
  checkCommand,
@@ -159,7 +160,13 @@ export async function waitForSimulatorToBeReady(
159
160
  return waitForSimulatorToBeReady(retries - 1);
160
161
  }
161
162
  } catch (error: any) {
162
- if ((error.message.includes("ECONNREFUSED") || error.message.includes("socket hang up")) && retries > 0) {
163
+ if (
164
+ (error.name === "FetchError" ||
165
+ error.message.includes("ECONNRESET") ||
166
+ error.message.includes("ECONNREFUSED") ||
167
+ error.message.includes("socket hang up")) &&
168
+ retries > 0
169
+ ) {
163
170
  await sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
164
171
  return waitForSimulatorToBeReady(retries - 1);
165
172
  }
@@ -184,17 +191,23 @@ export async function initializeDatabase(): Promise<InitializeDatabaseResultType
184
191
  return {createResponse, tablesResponse};
185
192
  }
186
193
 
187
- export function createRandomValidators(): Promise<any> {
188
- return rpcClient.request({method: "create_random_validators", params: [10, 1, 10]});
194
+ export function createRandomValidators(numValidators: number, llmProviders: AiProviders[]): Promise<any> {
195
+ return rpcClient.request({
196
+ method: "create_random_validators",
197
+ params: [numValidators, 1, 10, llmProviders],
198
+ });
189
199
  }
190
200
 
191
201
  export function deleteAllValidators(): Promise<any> {
192
202
  return rpcClient.request({method: "delete_all_validators", params: []});
193
203
  }
194
204
 
195
- export function getAiProvidersOptions(): Array<{name: string; value: string}> {
205
+ export function getAiProvidersOptions(withHint: boolean = true): Array<{name: string; value: string}> {
196
206
  return Object.values(AI_PROVIDERS_CONFIG).map(providerConfig => {
197
- return {name: providerConfig.name, value: providerConfig.cliOptionValue};
207
+ return {
208
+ name: `${providerConfig.name}${withHint ? ` ${providerConfig.hint}` : ""}`,
209
+ value: providerConfig.cliOptionValue,
210
+ };
198
211
  });
199
212
  }
200
213