genlayer 0.0.25 → 0.0.27

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.27 (2024-05-08)
4
+
5
+ ## 0.0.26 (2024-05-07)
6
+
3
7
  ## 0.0.25 (2024-05-06)
4
8
 
5
9
 
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.25";
39899
+ var version = "0.0.27";
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.";
@@ -42505,8 +42505,20 @@ 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
- ollama: { name: "Ollama (This will download and run a local instance of Llama 2)", envVar: "ollama", cliOptionValue: "ollama" },
42509
- openai: { name: "OpenAI (You will need to provide an OpenAI API key)", envVar: "OPENAIKEY", cliOptionValue: "openai" }
42508
+ ollama: {
42509
+ name: "Ollama (This will download and run a local instance of Llama 2)",
42510
+ cliOptionValue: "ollama"
42511
+ },
42512
+ openai: {
42513
+ name: "OpenAI (You will need to provide an OpenAI API key)",
42514
+ envVar: "OPENAIKEY",
42515
+ cliOptionValue: "openai"
42516
+ },
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
+ envVar: "HEURISTAIAPIKEY",
42520
+ cliOptionValue: "heurist"
42521
+ }
42510
42522
  };
42511
42523
 
42512
42524
  // src/lib/services/simulator.ts
@@ -44521,13 +44533,13 @@ function waitForSimulatorToBeReady() {
44521
44533
  yield sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
44522
44534
  return waitForSimulatorToBeReady(retries - 1);
44523
44535
  }
44524
- return { initialized: false, error: "ERROR" };
44536
+ return { initialized: false, errorCode: "ERROR", errorMessage: error.message };
44525
44537
  }
44526
- return { initialized: false, error: "TIMEOUT" };
44538
+ return { initialized: false, errorCode: "TIMEOUT" };
44527
44539
  });
44528
44540
  }
44529
- function clearDatabaseTables() {
44530
- return rpcClient.request({ method: "clear_tables", params: [] });
44541
+ function clearAccountsAndTransactionsDatabase() {
44542
+ return rpcClient.request({ method: "clear_account_and_transactions_tables", params: [] });
44531
44543
  }
44532
44544
  function initializeDatabase() {
44533
44545
  return __async(this, null, function* () {
@@ -44624,7 +44636,9 @@ function initAction(options) {
44624
44636
  const llmProvidersAnswer = yield inquirer_default.prompt(questions);
44625
44637
  const selectedLlmProviders = llmProvidersAnswer.selectedLlmProviders;
44626
44638
  const aiProvidersEnvVars = {};
44627
- const configurableAiProviders = selectedLlmProviders.filter((provider) => provider !== "ollama");
44639
+ const configurableAiProviders = selectedLlmProviders.filter(
44640
+ (provider) => AI_PROVIDERS_CONFIG[provider].envVar
44641
+ );
44628
44642
  for (let i2 = 0; i2 < configurableAiProviders.length; i2++) {
44629
44643
  const provider = configurableAiProviders[i2];
44630
44644
  const providerConfig = AI_PROVIDERS_CONFIG[provider];
@@ -44659,12 +44673,13 @@ function initAction(options) {
44659
44673
  return;
44660
44674
  }
44661
44675
  try {
44662
- const { initialized, error } = yield waitForSimulatorToBeReady();
44663
- if (!initialized && error === "ERROR") {
44676
+ const { initialized, errorCode, errorMessage } = yield waitForSimulatorToBeReady();
44677
+ if (!initialized && errorCode === "ERROR") {
44678
+ console.log(errorMessage);
44664
44679
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
44665
44680
  return;
44666
44681
  }
44667
- if (!initialized && error === "TIMEOUT") {
44682
+ if (!initialized && errorCode === "TIMEOUT") {
44668
44683
  console.error(
44669
44684
  "The simulator is taking too long to initialize. Please try again after the simulator is ready."
44670
44685
  );
@@ -44681,7 +44696,7 @@ function initAction(options) {
44681
44696
  }
44682
44697
  console.log("Initializing the database...");
44683
44698
  try {
44684
- yield clearDatabaseTables();
44699
+ yield clearAccountsAndTransactionsDatabase();
44685
44700
  const { createResponse, tablesResponse } = yield initializeDatabase();
44686
44701
  if (!createResponse || !tablesResponse) {
44687
44702
  console.error("Unable to initialize the database. Please try again.");
@@ -44714,8 +44729,10 @@ function initAction(options) {
44714
44729
  // src/commands/general/start.ts
44715
44730
  function startAction(options) {
44716
44731
  return __async(this, null, function* () {
44717
- const restartHintText = options.restart ? "restarting the database and validators" : "keeping the database and validators previous configuration";
44718
- console.log(`Starting GenLayer simulator ${restartHintText}`);
44732
+ const { resetAccounts, resetValidators } = options;
44733
+ 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";
44735
+ console.log(`Starting GenLayer simulator ${restartAccountsHintText} ${restartValidatorsHintText}`);
44719
44736
  console.log(`Updating GenLayer Simulator...`);
44720
44737
  try {
44721
44738
  yield updateSimulator();
@@ -44731,12 +44748,13 @@ function startAction(options) {
44731
44748
  return;
44732
44749
  }
44733
44750
  try {
44734
- const { initialized, error } = yield waitForSimulatorToBeReady();
44735
- if (!initialized && error === "ERROR") {
44751
+ const { initialized, errorCode, errorMessage } = yield waitForSimulatorToBeReady();
44752
+ if (!initialized && errorCode === "ERROR") {
44753
+ console.log(errorMessage);
44736
44754
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
44737
44755
  return;
44738
44756
  }
44739
- if (!initialized && error === "TIMEOUT") {
44757
+ if (!initialized && errorCode === "TIMEOUT") {
44740
44758
  console.error(
44741
44759
  "The simulator is taking too long to initialize. Please try again after the simulator is ready."
44742
44760
  );
@@ -44747,10 +44765,10 @@ function startAction(options) {
44747
44765
  console.error(error);
44748
44766
  return;
44749
44767
  }
44750
- if (options.restart) {
44768
+ if (resetAccounts) {
44751
44769
  console.log("Initializing the database...");
44752
44770
  try {
44753
- yield clearDatabaseTables();
44771
+ yield clearAccountsAndTransactionsDatabase();
44754
44772
  const { createResponse, tablesResponse } = yield initializeDatabase();
44755
44773
  if (!createResponse || !tablesResponse) {
44756
44774
  console.error("Unable to initialize the database. Please try again.");
@@ -44760,6 +44778,9 @@ function startAction(options) {
44760
44778
  console.error(error);
44761
44779
  return;
44762
44780
  }
44781
+ console.log("Database successfully reset...");
44782
+ }
44783
+ if (resetValidators) {
44763
44784
  console.log("Initializing validators...");
44764
44785
  try {
44765
44786
  yield deleteAllValidators();
@@ -44769,6 +44790,7 @@ function startAction(options) {
44769
44790
  console.error(error);
44770
44791
  return;
44771
44792
  }
44793
+ console.log("New random validators successfully created...");
44772
44794
  }
44773
44795
  console.log(
44774
44796
  `GenLayer simulator initialized successfully! Go to ${getFrontendUrl()} in your browser to access it.`
@@ -44784,7 +44806,7 @@ function startAction(options) {
44784
44806
  // src/commands/general/index.ts
44785
44807
  function initializeGeneralCommands(program2) {
44786
44808
  program2.command("init").description("Initialize the GenLayer Environment").option("-n, --numValidators <numValidators>", "Number of validators", "5").action(initAction);
44787
- program2.command("up").description("Starts GenLayer's simulator").option("-nr, --no-restart", "Don't restart the database and validators", true).action(startAction);
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);
44788
44810
  return program2;
44789
44811
  }
44790
44812
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -13,7 +13,8 @@ export function initializeGeneralCommands(program: Command) {
13
13
  program
14
14
  .command("up")
15
15
  .description("Starts GenLayer's simulator")
16
- .option("-nr, --no-restart", "Don't restart the database and validators", true)
16
+ .option("--no-reset-accounts", "Don't restart the database for accouts and transactions", true)
17
+ .option("--reset-validators", "Remove all current validators and create new random ones", false)
17
18
  .action(startAction);
18
19
 
19
20
  return program;
@@ -9,7 +9,7 @@ import {
9
9
  runSimulator,
10
10
  waitForSimulatorToBeReady,
11
11
  updateSimulator,
12
- clearDatabaseTables,
12
+ clearAccountsAndTransactionsDatabase,
13
13
  createRandomValidators,
14
14
  deleteAllValidators,
15
15
  pullOllamaModel,
@@ -100,7 +100,9 @@ export async function initAction(options: InitActionOptions) {
100
100
 
101
101
  // Gather the API Keys
102
102
  const aiProvidersEnvVars: Record<string, string> = {};
103
- const configurableAiProviders = selectedLlmProviders.filter((provider: string) => provider !== "ollama");
103
+ const configurableAiProviders = selectedLlmProviders.filter(
104
+ (provider: AiProviders) => AI_PROVIDERS_CONFIG[provider].envVar,
105
+ );
104
106
  for (let i = 0; i < configurableAiProviders.length; i++) {
105
107
  const provider = configurableAiProviders[i];
106
108
  const providerConfig = AI_PROVIDERS_CONFIG[provider];
@@ -119,7 +121,7 @@ export async function initAction(options: InitActionOptions) {
119
121
  ];
120
122
 
121
123
  const apiKeyAnswer = await inquirer.prompt(questions);
122
- aiProvidersEnvVars[providerConfig.envVar] = apiKeyAnswer[providerConfig.cliOptionValue];
124
+ aiProvidersEnvVars[providerConfig.envVar!] = apiKeyAnswer[providerConfig.cliOptionValue];
123
125
  }
124
126
 
125
127
  console.log("Configuring GenLayer Simulator environment...");
@@ -140,12 +142,13 @@ export async function initAction(options: InitActionOptions) {
140
142
  }
141
143
 
142
144
  try {
143
- const {initialized, error} = await waitForSimulatorToBeReady();
144
- if (!initialized && error === "ERROR") {
145
+ const {initialized, errorCode, errorMessage} = await waitForSimulatorToBeReady();
146
+ if (!initialized && errorCode === "ERROR") {
147
+ console.log(errorMessage);
145
148
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
146
149
  return;
147
150
  }
148
- if (!initialized && error === "TIMEOUT") {
151
+ if (!initialized && errorCode === "TIMEOUT") {
149
152
  console.error(
150
153
  "The simulator is taking too long to initialize. Please try again after the simulator is ready.",
151
154
  );
@@ -167,7 +170,7 @@ export async function initAction(options: InitActionOptions) {
167
170
  console.log("Initializing the database...");
168
171
  try {
169
172
  //remove everything from the database
170
- await clearDatabaseTables();
173
+ await clearAccountsAndTransactionsDatabase();
171
174
 
172
175
  const {createResponse, tablesResponse} = await initializeDatabase();
173
176
  if (!createResponse || !tablesResponse) {
@@ -4,21 +4,29 @@ import {
4
4
  waitForSimulatorToBeReady,
5
5
  deleteAllValidators,
6
6
  createRandomValidators,
7
- clearDatabaseTables,
7
+ clearAccountsAndTransactionsDatabase,
8
8
  initializeDatabase,
9
9
  getFrontendUrl,
10
10
  openFrontend,
11
11
  } from "@/lib/services/simulator";
12
12
 
13
13
  export interface StartActionOptions {
14
- restart: string;
14
+ resetAccounts: string;
15
+ resetValidators: string;
15
16
  }
16
17
 
17
18
  export async function startAction(options: StartActionOptions) {
18
- const restartHintText = options.restart
19
- ? "restarting the database and validators"
20
- : "keeping the database and validators previous configuration";
21
- console.log(`Starting GenLayer simulator ${restartHintText}`);
19
+ const {resetAccounts, resetValidators} = options;
20
+
21
+ const restartAccountsHintText = resetAccounts
22
+ ? "restarting the accounts and transactions database"
23
+ : "keeping the accounts and transactions records";
24
+
25
+ const restartValidatorsHintText = resetValidators
26
+ ? "and creating new random validators"
27
+ : "and keeping the existing validators";
28
+
29
+ console.log(`Starting GenLayer simulator ${restartAccountsHintText} ${restartValidatorsHintText}`);
22
30
 
23
31
  // Update the simulator to the latest version
24
32
  console.log(`Updating GenLayer Simulator...`);
@@ -39,12 +47,13 @@ export async function startAction(options: StartActionOptions) {
39
47
  }
40
48
 
41
49
  try {
42
- const {initialized, error} = await waitForSimulatorToBeReady();
43
- if (!initialized && error === "ERROR") {
50
+ const {initialized, errorCode, errorMessage} = await waitForSimulatorToBeReady();
51
+ if (!initialized && errorCode === "ERROR") {
52
+ console.log(errorMessage);
44
53
  console.error("Unable to initialize the GenLayer simulator. Please try again.");
45
54
  return;
46
55
  }
47
- if (!initialized && error === "TIMEOUT") {
56
+ if (!initialized && errorCode === "TIMEOUT") {
48
57
  console.error(
49
58
  "The simulator is taking too long to initialize. Please try again after the simulator is ready.",
50
59
  );
@@ -56,12 +65,12 @@ export async function startAction(options: StartActionOptions) {
56
65
  return;
57
66
  }
58
67
 
59
- if (options.restart) {
68
+ if (resetAccounts) {
60
69
  // Initialize the database
61
70
  console.log("Initializing the database...");
62
71
  try {
63
72
  //remove everything from the database
64
- await clearDatabaseTables();
73
+ await clearAccountsAndTransactionsDatabase();
65
74
 
66
75
  const {createResponse, tablesResponse} = await initializeDatabase();
67
76
  if (!createResponse || !tablesResponse) {
@@ -72,7 +81,10 @@ export async function startAction(options: StartActionOptions) {
72
81
  console.error(error);
73
82
  return;
74
83
  }
84
+ console.log("Database successfully reset...");
85
+ }
75
86
 
87
+ if (resetValidators) {
76
88
  // Initializing validators
77
89
  console.log("Initializing validators...");
78
90
  try {
@@ -85,6 +97,7 @@ export async function startAction(options: StartActionOptions) {
85
97
  console.error(error);
86
98
  return;
87
99
  }
100
+ console.log("New random validators successfully created...");
88
101
  }
89
102
 
90
103
  // Simulator ready
@@ -15,13 +15,25 @@ 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";
19
- export type AiProvidersEnvVars = "ollama" | "OPENAIKEY";
18
+ export type AiProviders = "ollama" | "openai" | "heurist";
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; envVar?: AiProvidersEnvVars; cliOptionValue: string};
22
22
  };
23
23
 
24
24
  export const AI_PROVIDERS_CONFIG: AiProvidersConfigType = {
25
- ollama: {name: "Ollama (This will download and run a local instance of Llama 2)", envVar: "ollama", cliOptionValue: "ollama"},
26
- openai: {name: "OpenAI (You will need to provide an OpenAI API key)", envVar: "OPENAIKEY", cliOptionValue: "openai"},
25
+ ollama: {
26
+ name: "Ollama (This will download and run a local instance of Llama 2)",
27
+ cliOptionValue: "ollama",
28
+ },
29
+ openai: {
30
+ name: "OpenAI (You will need to provide an OpenAI API key)",
31
+ envVar: "OPENAIKEY",
32
+ cliOptionValue: "openai",
33
+ },
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
+ envVar: "HEURISTAIAPIKEY",
37
+ cliOptionValue: "heurist",
38
+ },
27
39
  };
@@ -141,7 +141,8 @@ export function runSimulator(): Promise<{stdout: string; stderr: string}> {
141
141
 
142
142
  type WaitForSimulatorToBeReadyResultType = {
143
143
  initialized: boolean;
144
- error?: "TIMEOUT" | "ERROR";
144
+ errorCode?: "TIMEOUT" | "ERROR";
145
+ errorMessage?: string;
145
146
  };
146
147
 
147
148
  export async function waitForSimulatorToBeReady(
@@ -162,14 +163,14 @@ export async function waitForSimulatorToBeReady(
162
163
  await sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
163
164
  return waitForSimulatorToBeReady(retries - 1);
164
165
  }
165
- return {initialized: false, error: "ERROR"};
166
+ return {initialized: false, errorCode: "ERROR", errorMessage: error.message};
166
167
  }
167
168
 
168
- return {initialized: false, error: "TIMEOUT"};
169
+ return {initialized: false, errorCode: "TIMEOUT"};
169
170
  }
170
171
 
171
- export function clearDatabaseTables(): Promise<any> {
172
- return rpcClient.request({method: "clear_tables", params: []});
172
+ export function clearAccountsAndTransactionsDatabase(): Promise<any> {
173
+ return rpcClient.request({method: "clear_account_and_transactions_tables", params: []});
173
174
  }
174
175
 
175
176
  type InitializeDatabaseResultType = {