genlayer 0.0.28 → 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 +2 -0
- package/dist/index.js +41 -17
- package/package.json +1 -1
- package/src/commands/general/index.ts +1 -0
- package/src/commands/general/init.ts +2 -2
- package/src/commands/general/start.ts +25 -3
- package/src/lib/config/simulator.ts +10 -7
- package/src/lib/services/simulator.ts +13 -5
package/CHANGELOG.md
CHANGED
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.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.";
|
|
@@ -42506,18 +42506,21 @@ 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
|
|
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
|
|
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
|
-
|
|
42518
|
-
name:
|
|
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: "
|
|
42523
|
+
cliOptionValue: "heuristai"
|
|
42521
42524
|
}
|
|
42522
42525
|
};
|
|
42523
42526
|
|
|
@@ -44528,7 +44531,7 @@ function waitForSimulatorToBeReady() {
|
|
|
44528
44531
|
return waitForSimulatorToBeReady(retries - 1);
|
|
44529
44532
|
}
|
|
44530
44533
|
} catch (error) {
|
|
44531
|
-
if ((error.message.includes("ECONNRESET") || 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) {
|
|
44532
44535
|
yield sleep(STARTING_TIMEOUT_WAIT_CYLCE * 2);
|
|
44533
44536
|
return waitForSimulatorToBeReady(retries - 1);
|
|
44534
44537
|
}
|
|
@@ -44547,15 +44550,21 @@ function initializeDatabase() {
|
|
|
44547
44550
|
return { createResponse, tablesResponse };
|
|
44548
44551
|
});
|
|
44549
44552
|
}
|
|
44550
|
-
function createRandomValidators(numValidators) {
|
|
44551
|
-
return rpcClient.request({
|
|
44553
|
+
function createRandomValidators(numValidators, llmProviders) {
|
|
44554
|
+
return rpcClient.request({
|
|
44555
|
+
method: "create_random_validators",
|
|
44556
|
+
params: [numValidators, 1, 10, llmProviders]
|
|
44557
|
+
});
|
|
44552
44558
|
}
|
|
44553
44559
|
function deleteAllValidators() {
|
|
44554
44560
|
return rpcClient.request({ method: "delete_all_validators", params: [] });
|
|
44555
44561
|
}
|
|
44556
|
-
function getAiProvidersOptions() {
|
|
44562
|
+
function getAiProvidersOptions(withHint = true) {
|
|
44557
44563
|
return Object.values(AI_PROVIDERS_CONFIG).map((providerConfig) => {
|
|
44558
|
-
return {
|
|
44564
|
+
return {
|
|
44565
|
+
name: `${providerConfig.name}${withHint ? ` ${providerConfig.hint}` : ""}`,
|
|
44566
|
+
value: providerConfig.cliOptionValue
|
|
44567
|
+
};
|
|
44559
44568
|
});
|
|
44560
44569
|
}
|
|
44561
44570
|
function getFrontendUrl() {
|
|
@@ -44623,7 +44632,7 @@ function initAction(options) {
|
|
|
44623
44632
|
type: "checkbox",
|
|
44624
44633
|
name: "selectedLlmProviders",
|
|
44625
44634
|
message: "Select which LLM providers do you want to use:",
|
|
44626
|
-
choices: getAiProvidersOptions(),
|
|
44635
|
+
choices: getAiProvidersOptions(true),
|
|
44627
44636
|
validate: function(answer) {
|
|
44628
44637
|
if (answer.length < 1) {
|
|
44629
44638
|
return "You must choose at least one option.";
|
|
@@ -44708,7 +44717,7 @@ function initAction(options) {
|
|
|
44708
44717
|
console.log("Initializing validators...");
|
|
44709
44718
|
try {
|
|
44710
44719
|
yield deleteAllValidators();
|
|
44711
|
-
yield createRandomValidators(Number(options.numValidators));
|
|
44720
|
+
yield createRandomValidators(Number(options.numValidators), selectedLlmProviders);
|
|
44712
44721
|
} catch (error) {
|
|
44713
44722
|
console.error("Unable to initialize the validators.");
|
|
44714
44723
|
console.error(error);
|
|
@@ -44728,9 +44737,9 @@ function initAction(options) {
|
|
|
44728
44737
|
// src/commands/general/start.ts
|
|
44729
44738
|
function startAction(options) {
|
|
44730
44739
|
return __async(this, null, function* () {
|
|
44731
|
-
const { resetAccounts, resetValidators } = options;
|
|
44740
|
+
const { resetAccounts, resetValidators, numValidators } = options;
|
|
44732
44741
|
const restartAccountsHintText = resetAccounts ? "restarting the accounts and transactions database" : "keeping the accounts and transactions records";
|
|
44733
|
-
const restartValidatorsHintText = resetValidators ?
|
|
44742
|
+
const restartValidatorsHintText = resetValidators ? `and creating new ${numValidators} random validators` : "and keeping the existing validators";
|
|
44734
44743
|
console.log(`Starting GenLayer simulator ${restartAccountsHintText} ${restartValidatorsHintText}`);
|
|
44735
44744
|
console.log(`Updating GenLayer Simulator...`);
|
|
44736
44745
|
try {
|
|
@@ -44783,7 +44792,22 @@ function startAction(options) {
|
|
|
44783
44792
|
console.log("Initializing validators...");
|
|
44784
44793
|
try {
|
|
44785
44794
|
yield deleteAllValidators();
|
|
44786
|
-
|
|
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);
|
|
44787
44811
|
} catch (error) {
|
|
44788
44812
|
console.error("Unable to initialize the validators.");
|
|
44789
44813
|
console.error(error);
|
|
@@ -44805,7 +44829,7 @@ function startAction(options) {
|
|
|
44805
44829
|
// src/commands/general/index.ts
|
|
44806
44830
|
function initializeGeneralCommands(program2) {
|
|
44807
44831
|
program2.command("init").description("Initialize the GenLayer Environment").option("-n, --numValidators <numValidators>", "Number of validators", "5").action(initAction);
|
|
44808
|
-
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);
|
|
44809
44833
|
return program2;
|
|
44810
44834
|
}
|
|
44811
44835
|
|
package/package.json
CHANGED
|
@@ -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.";
|
|
@@ -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(Number(options.numValidators));
|
|
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
|
-
?
|
|
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);
|
|
@@ -15,25 +15,28 @@ 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" | "
|
|
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
|
|
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
|
|
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
|
-
|
|
35
|
-
name:
|
|
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: "
|
|
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,
|
|
@@ -160,7 +161,8 @@ export async function waitForSimulatorToBeReady(
|
|
|
160
161
|
}
|
|
161
162
|
} catch (error: any) {
|
|
162
163
|
if (
|
|
163
|
-
(error.
|
|
164
|
+
(error.name === "FetchError" ||
|
|
165
|
+
error.message.includes("ECONNRESET") ||
|
|
164
166
|
error.message.includes("ECONNREFUSED") ||
|
|
165
167
|
error.message.includes("socket hang up")) &&
|
|
166
168
|
retries > 0
|
|
@@ -189,17 +191,23 @@ export async function initializeDatabase(): Promise<InitializeDatabaseResultType
|
|
|
189
191
|
return {createResponse, tablesResponse};
|
|
190
192
|
}
|
|
191
193
|
|
|
192
|
-
export function createRandomValidators(numValidators: number): Promise<any> {
|
|
193
|
-
return rpcClient.request({
|
|
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
|
+
});
|
|
194
199
|
}
|
|
195
200
|
|
|
196
201
|
export function deleteAllValidators(): Promise<any> {
|
|
197
202
|
return rpcClient.request({method: "delete_all_validators", params: []});
|
|
198
203
|
}
|
|
199
204
|
|
|
200
|
-
export function getAiProvidersOptions(): Array<{name: string; value: string}> {
|
|
205
|
+
export function getAiProvidersOptions(withHint: boolean = true): Array<{name: string; value: string}> {
|
|
201
206
|
return Object.values(AI_PROVIDERS_CONFIG).map(providerConfig => {
|
|
202
|
-
return {
|
|
207
|
+
return {
|
|
208
|
+
name: `${providerConfig.name}${withHint ? ` ${providerConfig.hint}` : ""}`,
|
|
209
|
+
value: providerConfig.cliOptionValue,
|
|
210
|
+
};
|
|
203
211
|
});
|
|
204
212
|
}
|
|
205
213
|
|