genlayer 0.0.24 → 0.0.26
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 +9 -0
- package/dist/index.js +26 -18
- package/package.json +1 -1
- package/src/commands/general/index.ts +2 -1
- package/src/commands/general/init.ts +6 -5
- package/src/commands/general/start.ts +24 -11
- package/src/lib/config/simulator.ts +2 -2
- package/src/lib/services/simulator.ts +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.0.26 (2024-05-07)
|
|
4
|
+
|
|
5
|
+
## 0.0.25 (2024-05-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* OPEN AI .env key renamed in simulator ([#21](https://github.com/yeagerai/genlayer-cli/issues/21)) ([676d159](https://github.com/yeagerai/genlayer-cli/commit/676d1591871d6f81f1b8695bd4366997384579c6))
|
|
11
|
+
|
|
3
12
|
## 0.0.24 (2024-05-06)
|
|
4
13
|
|
|
5
14
|
## 0.0.23 (2024-05-01)
|
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.
|
|
39899
|
+
var version = "0.0.26";
|
|
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.";
|
|
@@ -42506,7 +42506,7 @@ var STARTING_TIMEOUT_WAIT_CYLCE = 2e3;
|
|
|
42506
42506
|
var STARTING_TIMEOUT_ATTEMPTS = 120;
|
|
42507
42507
|
var AI_PROVIDERS_CONFIG = {
|
|
42508
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: "
|
|
42509
|
+
openai: { name: "OpenAI (You will need to provide an OpenAI API key)", envVar: "OPENAIKEY", cliOptionValue: "openai" }
|
|
42510
42510
|
};
|
|
42511
42511
|
|
|
42512
42512
|
// src/lib/services/simulator.ts
|
|
@@ -44521,13 +44521,13 @@ function waitForSimulatorToBeReady() {
|
|
|
44521
44521
|
yield sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
|
|
44522
44522
|
return waitForSimulatorToBeReady(retries - 1);
|
|
44523
44523
|
}
|
|
44524
|
-
return { initialized: false,
|
|
44524
|
+
return { initialized: false, errorCode: "ERROR", errorMessage: error.message };
|
|
44525
44525
|
}
|
|
44526
|
-
return { initialized: false,
|
|
44526
|
+
return { initialized: false, errorCode: "TIMEOUT" };
|
|
44527
44527
|
});
|
|
44528
44528
|
}
|
|
44529
|
-
function
|
|
44530
|
-
return rpcClient.request({ method: "
|
|
44529
|
+
function clearAccountsAndTransactionsDatabase() {
|
|
44530
|
+
return rpcClient.request({ method: "clear_account_and_transactions_tables", params: [] });
|
|
44531
44531
|
}
|
|
44532
44532
|
function initializeDatabase() {
|
|
44533
44533
|
return __async(this, null, function* () {
|
|
@@ -44659,12 +44659,13 @@ function initAction(options) {
|
|
|
44659
44659
|
return;
|
|
44660
44660
|
}
|
|
44661
44661
|
try {
|
|
44662
|
-
const { initialized,
|
|
44663
|
-
if (!initialized &&
|
|
44662
|
+
const { initialized, errorCode, errorMessage } = yield waitForSimulatorToBeReady();
|
|
44663
|
+
if (!initialized && errorCode === "ERROR") {
|
|
44664
|
+
console.log(errorMessage);
|
|
44664
44665
|
console.error("Unable to initialize the GenLayer simulator. Please try again.");
|
|
44665
44666
|
return;
|
|
44666
44667
|
}
|
|
44667
|
-
if (!initialized &&
|
|
44668
|
+
if (!initialized && errorCode === "TIMEOUT") {
|
|
44668
44669
|
console.error(
|
|
44669
44670
|
"The simulator is taking too long to initialize. Please try again after the simulator is ready."
|
|
44670
44671
|
);
|
|
@@ -44681,7 +44682,7 @@ function initAction(options) {
|
|
|
44681
44682
|
}
|
|
44682
44683
|
console.log("Initializing the database...");
|
|
44683
44684
|
try {
|
|
44684
|
-
yield
|
|
44685
|
+
yield clearAccountsAndTransactionsDatabase();
|
|
44685
44686
|
const { createResponse, tablesResponse } = yield initializeDatabase();
|
|
44686
44687
|
if (!createResponse || !tablesResponse) {
|
|
44687
44688
|
console.error("Unable to initialize the database. Please try again.");
|
|
@@ -44714,8 +44715,10 @@ function initAction(options) {
|
|
|
44714
44715
|
// src/commands/general/start.ts
|
|
44715
44716
|
function startAction(options) {
|
|
44716
44717
|
return __async(this, null, function* () {
|
|
44717
|
-
const
|
|
44718
|
-
|
|
44718
|
+
const { resetAccounts, resetValidators } = options;
|
|
44719
|
+
const restartAccountsHintText = resetAccounts ? "restarting the accounts and transactions database" : "keeping the accounts and transactions records";
|
|
44720
|
+
const restartValidatorsHintText = resetValidators ? "and creating new random validators" : "and keeping the existing validators";
|
|
44721
|
+
console.log(`Starting GenLayer simulator ${restartAccountsHintText} ${restartValidatorsHintText}`);
|
|
44719
44722
|
console.log(`Updating GenLayer Simulator...`);
|
|
44720
44723
|
try {
|
|
44721
44724
|
yield updateSimulator();
|
|
@@ -44731,12 +44734,13 @@ function startAction(options) {
|
|
|
44731
44734
|
return;
|
|
44732
44735
|
}
|
|
44733
44736
|
try {
|
|
44734
|
-
const { initialized,
|
|
44735
|
-
if (!initialized &&
|
|
44737
|
+
const { initialized, errorCode, errorMessage } = yield waitForSimulatorToBeReady();
|
|
44738
|
+
if (!initialized && errorCode === "ERROR") {
|
|
44739
|
+
console.log(errorMessage);
|
|
44736
44740
|
console.error("Unable to initialize the GenLayer simulator. Please try again.");
|
|
44737
44741
|
return;
|
|
44738
44742
|
}
|
|
44739
|
-
if (!initialized &&
|
|
44743
|
+
if (!initialized && errorCode === "TIMEOUT") {
|
|
44740
44744
|
console.error(
|
|
44741
44745
|
"The simulator is taking too long to initialize. Please try again after the simulator is ready."
|
|
44742
44746
|
);
|
|
@@ -44747,10 +44751,10 @@ function startAction(options) {
|
|
|
44747
44751
|
console.error(error);
|
|
44748
44752
|
return;
|
|
44749
44753
|
}
|
|
44750
|
-
if (
|
|
44754
|
+
if (resetAccounts) {
|
|
44751
44755
|
console.log("Initializing the database...");
|
|
44752
44756
|
try {
|
|
44753
|
-
yield
|
|
44757
|
+
yield clearAccountsAndTransactionsDatabase();
|
|
44754
44758
|
const { createResponse, tablesResponse } = yield initializeDatabase();
|
|
44755
44759
|
if (!createResponse || !tablesResponse) {
|
|
44756
44760
|
console.error("Unable to initialize the database. Please try again.");
|
|
@@ -44760,6 +44764,9 @@ function startAction(options) {
|
|
|
44760
44764
|
console.error(error);
|
|
44761
44765
|
return;
|
|
44762
44766
|
}
|
|
44767
|
+
console.log("Database successfully reset...");
|
|
44768
|
+
}
|
|
44769
|
+
if (resetValidators) {
|
|
44763
44770
|
console.log("Initializing validators...");
|
|
44764
44771
|
try {
|
|
44765
44772
|
yield deleteAllValidators();
|
|
@@ -44769,6 +44776,7 @@ function startAction(options) {
|
|
|
44769
44776
|
console.error(error);
|
|
44770
44777
|
return;
|
|
44771
44778
|
}
|
|
44779
|
+
console.log("New random validators successfully created...");
|
|
44772
44780
|
}
|
|
44773
44781
|
console.log(
|
|
44774
44782
|
`GenLayer simulator initialized successfully! Go to ${getFrontendUrl()} in your browser to access it.`
|
|
@@ -44784,7 +44792,7 @@ function startAction(options) {
|
|
|
44784
44792
|
// src/commands/general/index.ts
|
|
44785
44793
|
function initializeGeneralCommands(program2) {
|
|
44786
44794
|
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("
|
|
44795
|
+
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
44796
|
return program2;
|
|
44789
44797
|
}
|
|
44790
44798
|
|
package/package.json
CHANGED
|
@@ -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("
|
|
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
|
-
|
|
12
|
+
clearAccountsAndTransactionsDatabase,
|
|
13
13
|
createRandomValidators,
|
|
14
14
|
deleteAllValidators,
|
|
15
15
|
pullOllamaModel,
|
|
@@ -140,12 +140,13 @@ export async function initAction(options: InitActionOptions) {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
try {
|
|
143
|
-
const {initialized,
|
|
144
|
-
if (!initialized &&
|
|
143
|
+
const {initialized, errorCode, errorMessage} = await waitForSimulatorToBeReady();
|
|
144
|
+
if (!initialized && errorCode === "ERROR") {
|
|
145
|
+
console.log(errorMessage);
|
|
145
146
|
console.error("Unable to initialize the GenLayer simulator. Please try again.");
|
|
146
147
|
return;
|
|
147
148
|
}
|
|
148
|
-
if (!initialized &&
|
|
149
|
+
if (!initialized && errorCode === "TIMEOUT") {
|
|
149
150
|
console.error(
|
|
150
151
|
"The simulator is taking too long to initialize. Please try again after the simulator is ready.",
|
|
151
152
|
);
|
|
@@ -167,7 +168,7 @@ export async function initAction(options: InitActionOptions) {
|
|
|
167
168
|
console.log("Initializing the database...");
|
|
168
169
|
try {
|
|
169
170
|
//remove everything from the database
|
|
170
|
-
await
|
|
171
|
+
await clearAccountsAndTransactionsDatabase();
|
|
171
172
|
|
|
172
173
|
const {createResponse, tablesResponse} = await initializeDatabase();
|
|
173
174
|
if (!createResponse || !tablesResponse) {
|
|
@@ -4,21 +4,29 @@ import {
|
|
|
4
4
|
waitForSimulatorToBeReady,
|
|
5
5
|
deleteAllValidators,
|
|
6
6
|
createRandomValidators,
|
|
7
|
-
|
|
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
|
-
|
|
14
|
+
resetAccounts: string;
|
|
15
|
+
resetValidators: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export async function startAction(options: StartActionOptions) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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,
|
|
43
|
-
if (!initialized &&
|
|
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 &&
|
|
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 (
|
|
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
|
|
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
|
|
@@ -16,12 +16,12 @@ export const STARTING_TIMEOUT_WAIT_CYLCE = 2000;
|
|
|
16
16
|
export const STARTING_TIMEOUT_ATTEMPTS = 120;
|
|
17
17
|
|
|
18
18
|
export type AiProviders = "ollama" | "openai";
|
|
19
|
-
export type AiProvidersEnvVars = "ollama" | "
|
|
19
|
+
export type AiProvidersEnvVars = "ollama" | "OPENAIKEY";
|
|
20
20
|
export type AiProvidersConfigType = {
|
|
21
21
|
[key in AiProviders]: {name: string; envVar: AiProvidersEnvVars; cliOptionValue: string};
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export const AI_PROVIDERS_CONFIG: AiProvidersConfigType = {
|
|
25
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: "
|
|
26
|
+
openai: {name: "OpenAI (You will need to provide an OpenAI API key)", envVar: "OPENAIKEY", cliOptionValue: "openai"},
|
|
27
27
|
};
|
|
@@ -141,7 +141,8 @@ export function runSimulator(): Promise<{stdout: string; stderr: string}> {
|
|
|
141
141
|
|
|
142
142
|
type WaitForSimulatorToBeReadyResultType = {
|
|
143
143
|
initialized: boolean;
|
|
144
|
-
|
|
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,
|
|
166
|
+
return {initialized: false, errorCode: "ERROR", errorMessage: error.message};
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
return {initialized: false,
|
|
169
|
+
return {initialized: false, errorCode: "TIMEOUT"};
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
export function
|
|
172
|
-
return rpcClient.request({method: "
|
|
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 = {
|