genlayer 0.12.1 → 0.12.2-beta.1
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/.github/workflows/publish-beta.yml +2 -2
- package/.github/workflows/publish.yml +2 -2
- package/.github/workflows/validate-code.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/index.js +24679 -108276
- package/docker-compose.yml +1 -1
- package/esbuild.config.dev.js +18 -0
- package/esbuild.config.js +10 -5
- package/esbuild.config.prod.js +17 -0
- package/eslint.config.js +59 -0
- package/package.json +12 -9
- package/scripts/postinstall.js +10 -6
- package/src/commands/config/getSetReset.ts +25 -18
- package/src/commands/contracts/deploy.ts +105 -25
- package/src/commands/contracts/index.ts +5 -1
- package/src/commands/general/index.ts +10 -4
- package/src/commands/general/init.ts +136 -189
- package/src/commands/general/start.ts +76 -77
- package/src/commands/general/stop.ts +6 -5
- package/src/commands/keygen/create.ts +9 -11
- package/src/commands/update/index.ts +3 -8
- package/src/commands/update/ollama.ts +56 -56
- package/src/commands/validators/validators.ts +48 -55
- package/src/lib/actions/BaseAction.ts +75 -4
- package/src/lib/config/simulator.ts +1 -1
- package/src/lib/services/simulator.ts +3 -2
- package/tests/actions/create.test.ts +18 -30
- package/tests/actions/deploy.test.ts +200 -30
- package/tests/actions/getSetReset.test.ts +29 -42
- package/tests/actions/init.test.ts +240 -475
- package/tests/actions/ollama.test.ts +40 -55
- package/tests/actions/start.test.ts +107 -108
- package/tests/actions/stop.test.ts +23 -4
- package/tests/actions/validators.test.ts +273 -142
- package/tests/commands/call.test.ts +4 -1
- package/tests/commands/deploy.test.ts +11 -0
- package/tests/commands/init.test.ts +11 -12
- package/tests/commands/up.test.ts +31 -23
- package/tests/commands/update.test.ts +2 -5
- package/tests/libs/baseAction.test.ts +175 -0
- package/tests/services/simulator.test.ts +15 -0
- package/.eslintrc.js +0 -58
- package/esbuild.config.dev +0 -16
- package/esbuild.config.prod +0 -16
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import inquirer from "inquirer";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { DistinctQuestion } from "inquirer";
|
|
3
|
+
import { ISimulatorService } from "../../lib/interfaces/ISimulatorService";
|
|
4
|
+
import { AI_PROVIDERS_CONFIG, AiProviders } from "../../lib/config/simulator";
|
|
4
5
|
import { OllamaAction } from "../update/ollama";
|
|
5
|
-
import {
|
|
6
|
+
import { BaseAction } from "../../lib/actions/BaseAction";
|
|
7
|
+
import { SimulatorService } from "../../lib/services/simulator";
|
|
6
8
|
|
|
7
9
|
export interface InitActionOptions {
|
|
8
10
|
numValidators: number;
|
|
@@ -11,217 +13,162 @@ export interface InitActionOptions {
|
|
|
11
13
|
localnetVersion: string;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
function getRequirementsErrorMessage({docker}: Record<string, boolean>): string {
|
|
15
|
-
|
|
16
|
+
function getRequirementsErrorMessage({ docker }: Record<string, boolean>): string {
|
|
16
17
|
if (!docker) {
|
|
17
18
|
return "Docker is not installed. Please install Docker and try again.\n";
|
|
18
19
|
}
|
|
19
|
-
|
|
20
20
|
return "";
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function getVersionErrorMessage({docker, node}: Record<string, string>): string {
|
|
23
|
+
function getVersionErrorMessage({ docker, node }: Record<string, string>): string {
|
|
24
24
|
let message = "";
|
|
25
25
|
|
|
26
26
|
if (docker) {
|
|
27
27
|
message += `Docker version ${docker} or higher is required. Please update Docker and try again.\n`;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
29
|
if (node) {
|
|
31
30
|
message += `Node version ${node} or higher is required. Please update Node and try again.\n`;
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
return message;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
export
|
|
38
|
-
simulatorService
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if(localnetVersion !== 'latest'){
|
|
43
|
-
localnetVersion = simulatorService.normalizeLocalnetVersion(localnetVersion);
|
|
35
|
+
export class InitAction extends BaseAction {
|
|
36
|
+
private simulatorService: ISimulatorService;
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
this.simulatorService = new SimulatorService();
|
|
44
40
|
}
|
|
45
|
-
await simulatorService.checkCliVersion();
|
|
46
|
-
|
|
47
|
-
// Check if requirements are installed
|
|
48
|
-
try {
|
|
49
|
-
const requirementsInstalled = await simulatorService.checkInstallRequirements();
|
|
50
|
-
const requirementErrorMessage = getRequirementsErrorMessage(requirementsInstalled);
|
|
51
|
-
|
|
52
|
-
if (requirementErrorMessage) {
|
|
53
|
-
console.error(requirementErrorMessage);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error(error);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Check if the versions are correct
|
|
62
|
-
try {
|
|
63
|
-
const missingVersions = await simulatorService.checkVersionRequirements();
|
|
64
|
-
const versionErrorMessage = getVersionErrorMessage(missingVersions);
|
|
65
41
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
console.error(error);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
42
|
+
public async execute(options: InitActionOptions): Promise<void> {
|
|
43
|
+
try {
|
|
44
|
+
this.simulatorService.setComposeOptions(options.headless);
|
|
45
|
+
let localnetVersion = options.localnetVersion;
|
|
46
|
+
if (localnetVersion !== "latest") {
|
|
47
|
+
localnetVersion = this.simulatorService.normalizeLocalnetVersion(localnetVersion);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.startSpinner("Checking CLI version...");
|
|
51
|
+
await this.simulatorService.checkCliVersion();
|
|
52
|
+
|
|
53
|
+
this.setSpinnerText("Checking installation requirements...");
|
|
54
|
+
const requirementsInstalled = await this.simulatorService.checkInstallRequirements();
|
|
55
|
+
const requirementErrorMessage = getRequirementsErrorMessage(requirementsInstalled);
|
|
56
|
+
if (requirementErrorMessage) {
|
|
57
|
+
this.failSpinner(requirementErrorMessage);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.setSpinnerText("Checking version requirements...");
|
|
62
|
+
const missingVersions = await this.simulatorService.checkVersionRequirements();
|
|
63
|
+
const versionErrorMessage = getVersionErrorMessage(missingVersions);
|
|
64
|
+
if (versionErrorMessage) {
|
|
65
|
+
this.failSpinner(versionErrorMessage);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.stopSpinner();
|
|
69
|
+
|
|
70
|
+
// Confirm reset action with the user using BaseAction's confirm prompt
|
|
71
|
+
await this.confirmPrompt(
|
|
72
|
+
`This command is going to reset GenLayer docker images and containers, providers API Keys, and GenLayer database (accounts, transactions, validators and logs). Contract code (gpy files) will be kept. Do you want to continue?`
|
|
73
|
+
);
|
|
101
74
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// Since ollama runs locally we can run it here and then look for the other providers
|
|
119
|
-
const llmProvidersAnswer = await inquirer.prompt(questions);
|
|
120
|
-
const selectedLlmProviders = llmProvidersAnswer.selectedLlmProviders as AiProviders[];
|
|
121
|
-
|
|
122
|
-
// Gather the API Keys
|
|
123
|
-
const aiProvidersEnvVars: Record<string, string> = {};
|
|
124
|
-
const configurableAiProviders = selectedLlmProviders.filter(
|
|
125
|
-
(provider: AiProviders) => AI_PROVIDERS_CONFIG[provider].envVar,
|
|
126
|
-
);
|
|
127
|
-
for (let i = 0; i < configurableAiProviders.length; i++) {
|
|
128
|
-
const provider = configurableAiProviders[i];
|
|
129
|
-
const providerConfig = AI_PROVIDERS_CONFIG[provider];
|
|
130
|
-
const questions = [
|
|
131
|
-
{
|
|
132
|
-
type: "input",
|
|
133
|
-
name: providerConfig.cliOptionValue,
|
|
134
|
-
message: `Please enter your ${providerConfig.name} API Key:`,
|
|
135
|
-
validate: function (value: string) {
|
|
136
|
-
if (value.length) {
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
return `Please enter a valid API Key for ${providerConfig.name}.`;
|
|
75
|
+
this.logInfo(`Initializing GenLayer CLI with ${options.numValidators} validators`);
|
|
76
|
+
|
|
77
|
+
// Reset Docker containers and images
|
|
78
|
+
this.startSpinner("Resetting Docker containers and images...");
|
|
79
|
+
await this.simulatorService.resetDockerContainers();
|
|
80
|
+
await this.simulatorService.resetDockerImages();
|
|
81
|
+
this.stopSpinner();
|
|
82
|
+
|
|
83
|
+
const llmQuestions: DistinctQuestion[] = [
|
|
84
|
+
{
|
|
85
|
+
type: "checkbox",
|
|
86
|
+
name: "selectedLlmProviders",
|
|
87
|
+
message: "Select which LLM providers do you want to use:",
|
|
88
|
+
choices: this.simulatorService.getAiProvidersOptions(true),
|
|
89
|
+
validate: (answer) =>
|
|
90
|
+
answer.length < 1 ? "You must choose at least one option." : true,
|
|
140
91
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
simulatorService.addConfigToEnvFile(aiProvidersEnvVars);
|
|
150
|
-
simulatorService.addConfigToEnvFile({LOCALNETVERSION: localnetVersion});
|
|
151
|
-
|
|
152
|
-
// Run the GenLayer Simulator
|
|
153
|
-
console.log("Running the GenLayer Simulator...");
|
|
154
|
-
try {
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
156
|
-
await simulatorService.runSimulator();
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.error(error);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
const {initialized, errorCode, errorMessage} = await simulatorService.waitForSimulatorToBeReady();
|
|
164
|
-
if (!initialized && errorCode === "ERROR") {
|
|
165
|
-
console.log(errorMessage);
|
|
166
|
-
console.error("Unable to initialize the GenLayer simulator. Please try again.");
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (!initialized && errorCode === "TIMEOUT") {
|
|
170
|
-
console.error(
|
|
171
|
-
"The simulator is taking too long to initialize. Please try again after the simulator is ready.",
|
|
92
|
+
];
|
|
93
|
+
const llmProvidersAnswer = await inquirer.prompt(llmQuestions);
|
|
94
|
+
const selectedLlmProviders = llmProvidersAnswer.selectedLlmProviders as AiProviders[];
|
|
95
|
+
|
|
96
|
+
let defaultOllamaModel = this.getConfig().defaultOllamaModel;
|
|
97
|
+
const aiProvidersEnvVars: Record<string, string> = {};
|
|
98
|
+
const configurableAiProviders = selectedLlmProviders.filter(
|
|
99
|
+
(provider: AiProviders) => AI_PROVIDERS_CONFIG[provider].envVar
|
|
172
100
|
);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
101
|
+
for (const provider of configurableAiProviders) {
|
|
102
|
+
const providerConfig = AI_PROVIDERS_CONFIG[provider];
|
|
103
|
+
const keyQuestion: DistinctQuestion[] = [
|
|
104
|
+
{
|
|
105
|
+
type: "input",
|
|
106
|
+
name: providerConfig.cliOptionValue,
|
|
107
|
+
message: `Please enter your ${providerConfig.name} API Key:`,
|
|
108
|
+
validate: (value: string) =>
|
|
109
|
+
value.length ? true : `Please enter a valid API Key for ${providerConfig.name}.`,
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
const apiKeyAnswer = await inquirer.prompt(keyQuestion);
|
|
113
|
+
aiProvidersEnvVars[providerConfig.envVar!] = apiKeyAnswer[providerConfig.cliOptionValue];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.startSpinner("Configuring GenLayer Localnet environment...");
|
|
117
|
+
this.simulatorService.addConfigToEnvFile(aiProvidersEnvVars);
|
|
118
|
+
this.simulatorService.addConfigToEnvFile({ LOCALNETVERSION: localnetVersion });
|
|
119
|
+
|
|
120
|
+
this.setSpinnerText("Running GenLayer Localnet...");
|
|
121
|
+
await this.simulatorService.runSimulator();
|
|
122
|
+
|
|
123
|
+
this.setSpinnerText("Waiting for localnet to be ready...");
|
|
124
|
+
const { initialized, errorCode, errorMessage } =
|
|
125
|
+
await this.simulatorService.waitForSimulatorToBeReady();
|
|
126
|
+
if (!initialized) {
|
|
127
|
+
if (errorCode === "ERROR") {
|
|
128
|
+
this.failSpinner(`Unable to initialize the GenLayer Localnet: ${errorMessage}`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (errorCode === "TIMEOUT") {
|
|
132
|
+
this.failSpinner(
|
|
133
|
+
"The localnet is taking too long to initialize. Please try again after the localnet is ready."
|
|
134
|
+
);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
198
138
|
|
|
199
|
-
|
|
200
|
-
console.log("Initializing validators...");
|
|
201
|
-
try {
|
|
202
|
-
//remove all validators
|
|
203
|
-
await simulatorService.deleteAllValidators();
|
|
204
|
-
// create random validators
|
|
205
|
-
await simulatorService.createRandomValidators(Number(options.numValidators), selectedLlmProviders);
|
|
206
|
-
} catch (error) {
|
|
207
|
-
console.error("Unable to initialize the validators.");
|
|
208
|
-
console.error(error);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
139
|
+
this.stopSpinner();
|
|
211
140
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
141
|
+
if (selectedLlmProviders.includes("ollama")) {
|
|
142
|
+
const ollamaAction = new OllamaAction();
|
|
143
|
+
if (!defaultOllamaModel) {
|
|
144
|
+
this.writeConfig("defaultOllamaModel", "llama3");
|
|
145
|
+
defaultOllamaModel = "llama3";
|
|
146
|
+
}
|
|
147
|
+
await ollamaAction.updateModel(defaultOllamaModel);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
this.startSpinner("Initializing validators...");
|
|
151
|
+
await this.simulatorService.deleteAllValidators();
|
|
152
|
+
await this.simulatorService.createRandomValidators(
|
|
153
|
+
Number(options.numValidators),
|
|
154
|
+
selectedLlmProviders
|
|
155
|
+
);
|
|
215
156
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
157
|
+
if (options.resetDb) {
|
|
158
|
+
this.setSpinnerText("Cleaning database...");
|
|
159
|
+
await this.simulatorService.cleanDatabase();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let successMessage = "GenLayer Localnet initialized successfully! ";
|
|
163
|
+
if (!options.headless) {
|
|
164
|
+
successMessage += `Go to ${this.simulatorService.getFrontendUrl()} in your browser to access it.`;
|
|
165
|
+
}
|
|
166
|
+
if (!options.headless) {
|
|
167
|
+
await this.simulatorService.openFrontend();
|
|
168
|
+
}
|
|
169
|
+
this.succeedSpinner(successMessage);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
this.failSpinner("An error occurred during initialization.", error);
|
|
223
172
|
}
|
|
224
|
-
} catch (error) {
|
|
225
|
-
console.error(error);
|
|
226
173
|
}
|
|
227
174
|
}
|
|
@@ -1,104 +1,103 @@
|
|
|
1
1
|
import inquirer from "inquirer";
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
import { ISimulatorService } from "../../lib/interfaces/ISimulatorService";
|
|
3
|
+
import { DistinctQuestion } from "inquirer";
|
|
4
|
+
import { BaseAction } from "../../lib/actions/BaseAction";
|
|
5
|
+
import { SimulatorService } from "../../lib/services/simulator";
|
|
4
6
|
|
|
5
7
|
export interface StartActionOptions {
|
|
6
8
|
resetValidators: boolean;
|
|
7
9
|
numValidators: number;
|
|
8
10
|
headless: boolean;
|
|
9
|
-
resetDb: boolean
|
|
11
|
+
resetDb: boolean;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
+
export class StartAction extends BaseAction {
|
|
15
|
+
private simulatorService: ISimulatorService;
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.simulatorService = new SimulatorService();
|
|
20
|
+
}
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
async execute(options: StartActionOptions) {
|
|
23
|
+
const { resetValidators, numValidators, headless, resetDb } = options;
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
this.simulatorService.setComposeOptions(headless);
|
|
26
|
+
this.startSpinner("Checking CLI version...");
|
|
27
|
+
await this.simulatorService.checkCliVersion();
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
const restartValidatorsHintText = resetValidators
|
|
30
|
+
? `creating new ${numValidators} random validators`
|
|
31
|
+
: "keeping the existing validators";
|
|
32
|
+
this.setSpinnerText(`Starting GenLayer Localnet (${restartValidatorsHintText})...`);
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const {initialized, errorCode, errorMessage} = await simulatorService.waitForSimulatorToBeReady();
|
|
34
|
-
if (!initialized && errorCode === "ERROR") {
|
|
35
|
-
console.log(errorMessage);
|
|
36
|
-
console.error("Unable to initialize the GenLayer simulator. Please try again.");
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (!initialized && errorCode === "TIMEOUT") {
|
|
40
|
-
console.error(
|
|
41
|
-
"The simulator is taking too long to initialize. Please try again after the simulator is ready.",
|
|
42
|
-
);
|
|
34
|
+
try {
|
|
35
|
+
await this.simulatorService.runSimulator();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
this.failSpinner("Error starting the simulator", error);
|
|
43
38
|
return;
|
|
44
39
|
}
|
|
45
|
-
console.log("Simulator is running!");
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.error(error);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if(resetDb){
|
|
52
|
-
await simulatorService.cleanDatabase()
|
|
53
|
-
}
|
|
54
40
|
|
|
55
|
-
if (resetValidators) {
|
|
56
|
-
// Initializing validators
|
|
57
|
-
console.log("Initializing validators...");
|
|
58
41
|
try {
|
|
59
|
-
|
|
60
|
-
await simulatorService.
|
|
61
|
-
const questions = [
|
|
62
|
-
{
|
|
63
|
-
type: "checkbox",
|
|
64
|
-
name: "selectedLlmProviders",
|
|
65
|
-
message: "Select which LLM providers do you want to use:",
|
|
66
|
-
choices: simulatorService.getAiProvidersOptions(false),
|
|
67
|
-
validate: function (answer: string[]) {
|
|
68
|
-
if (answer.length < 1) {
|
|
69
|
-
return "You must choose at least one option.";
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
];
|
|
42
|
+
this.setSpinnerText("Waiting for the simulator to be ready...");
|
|
43
|
+
const { initialized, errorCode, errorMessage } = await this.simulatorService.waitForSimulatorToBeReady();
|
|
75
44
|
|
|
76
|
-
|
|
77
|
-
|
|
45
|
+
if (!initialized) {
|
|
46
|
+
if (errorCode === "ERROR") {
|
|
47
|
+
this.failSpinner("Unable to initialize the GenLayer simulator.", errorMessage);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (errorCode === "TIMEOUT") {
|
|
51
|
+
this.failSpinner("The simulator is taking too long to initialize. Please try again later.");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
78
55
|
|
|
79
|
-
// create random validators
|
|
80
|
-
await simulatorService.createRandomValidators(
|
|
81
|
-
Number(options.numValidators),
|
|
82
|
-
llmProvidersAnswer.selectedLlmProviders,
|
|
83
|
-
);
|
|
84
56
|
} catch (error) {
|
|
85
|
-
|
|
86
|
-
console.error(error);
|
|
57
|
+
this.failSpinner("Error waiting for the simulator to be ready", error);
|
|
87
58
|
return;
|
|
88
59
|
}
|
|
89
|
-
console.log("New random validators successfully created...");
|
|
90
|
-
}
|
|
91
60
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if(
|
|
98
|
-
|
|
61
|
+
if (resetDb) {
|
|
62
|
+
this.setSpinnerText("Resetting database...");
|
|
63
|
+
await this.simulatorService.cleanDatabase();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (resetValidators) {
|
|
67
|
+
this.setSpinnerText("Initializing validators...");
|
|
68
|
+
try {
|
|
69
|
+
await this.simulatorService.deleteAllValidators();
|
|
70
|
+
|
|
71
|
+
const questions: DistinctQuestion[] = [
|
|
72
|
+
{
|
|
73
|
+
type: "checkbox",
|
|
74
|
+
name: "selectedLlmProviders",
|
|
75
|
+
message: "Select which LLM providers do you want to use:",
|
|
76
|
+
choices: this.simulatorService.getAiProvidersOptions(false),
|
|
77
|
+
validate: (answer) => (answer.length < 1 ? "You must choose at least one option." : true),
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const llmProvidersAnswer = await inquirer.prompt(questions);
|
|
82
|
+
await this.simulatorService.createRandomValidators(numValidators, llmProvidersAnswer.selectedLlmProviders);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
this.failSpinner("Unable to initialize the validators", error);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
99
87
|
}
|
|
100
88
|
|
|
101
|
-
|
|
102
|
-
|
|
89
|
+
let successMessage = "GenLayer simulator initialized successfully! ";
|
|
90
|
+
successMessage += headless ? "" : `Go to ${this.simulatorService.getFrontendUrl()} in your browser to access it.`;
|
|
91
|
+
this.succeedSpinner(successMessage);
|
|
92
|
+
|
|
93
|
+
if (!headless) {
|
|
94
|
+
try {
|
|
95
|
+
this.startSpinner("Opening frontend...");
|
|
96
|
+
await this.simulatorService.openFrontend();
|
|
97
|
+
this.succeedSpinner("Frontend opened successfully");
|
|
98
|
+
} catch (error) {
|
|
99
|
+
this.failSpinner("Error opening the frontend", error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
103
102
|
}
|
|
104
103
|
}
|
|
@@ -11,15 +11,16 @@ export class StopAction extends BaseAction {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
public async stop(): Promise<void> {
|
|
14
|
-
try{
|
|
14
|
+
try {
|
|
15
15
|
await this.confirmPrompt(
|
|
16
16
|
"Are you sure you want to stop all running GenLayer containers? This will halt all active processes."
|
|
17
17
|
);
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
this.startSpinner("Stopping Docker containers...");
|
|
19
20
|
await this.simulatorService.stopDockerContainers();
|
|
20
|
-
|
|
21
|
-
}catch (error) {
|
|
22
|
-
|
|
21
|
+
this.succeedSpinner("All running GenLayer containers have been successfully stopped.");
|
|
22
|
+
} catch (error) {
|
|
23
|
+
this.failSpinner("An error occurred while stopping the containers.", error);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { writeFileSync, existsSync } from "fs";
|
|
2
2
|
import { ethers } from "ethers";
|
|
3
|
-
import {
|
|
3
|
+
import { BaseAction } from "../../lib/actions/BaseAction";
|
|
4
4
|
|
|
5
5
|
export interface CreateKeypairOptions {
|
|
6
6
|
output: string;
|
|
7
7
|
overwrite: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export class KeypairCreator {
|
|
11
|
-
private filePathManager: ConfigFileManager;
|
|
10
|
+
export class KeypairCreator extends BaseAction{
|
|
12
11
|
|
|
13
12
|
constructor() {
|
|
14
|
-
|
|
13
|
+
super()
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
createKeypairAction(options: CreateKeypairOptions) {
|
|
18
17
|
try {
|
|
19
|
-
|
|
20
|
-
const outputPath = this.
|
|
18
|
+
this.startSpinner(`Creating keypair...`);
|
|
19
|
+
const outputPath = this.getFilePath(options.output);
|
|
21
20
|
|
|
22
21
|
if(existsSync(outputPath) && !options.overwrite) {
|
|
23
|
-
|
|
22
|
+
this.failSpinner(
|
|
24
23
|
`The file at ${outputPath} already exists. Use the '--overwrite' option to replace it.`
|
|
25
24
|
);
|
|
26
25
|
return;
|
|
@@ -34,11 +33,10 @@ export class KeypairCreator {
|
|
|
34
33
|
|
|
35
34
|
writeFileSync(outputPath, JSON.stringify(keypairData, null, 2));
|
|
36
35
|
|
|
37
|
-
this.
|
|
38
|
-
|
|
36
|
+
this.writeConfig('keyPairPath', outputPath);
|
|
37
|
+
this.succeedSpinner(`Keypair successfully created and saved to: ${outputPath}`);
|
|
39
38
|
} catch (error) {
|
|
40
|
-
|
|
41
|
-
process.exit(1);
|
|
39
|
+
this.failSpinner("Failed to generate keypair:", error);
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { OllamaAction } from "./ollama";
|
|
3
|
-
import { ConfigFileManager } from "../../lib/config/ConfigFileManager";
|
|
4
3
|
|
|
5
4
|
export function initializeUpdateCommands(program: Command) {
|
|
6
5
|
const updateCommand = program
|
|
@@ -10,19 +9,15 @@ export function initializeUpdateCommands(program: Command) {
|
|
|
10
9
|
updateCommand
|
|
11
10
|
.command("ollama")
|
|
12
11
|
.description("Manage Ollama models (update or remove)")
|
|
13
|
-
.option("--model [model-name]", "Specify the model to update or remove")
|
|
12
|
+
.option("--model [model-name]", "Specify the model to update or remove", '')
|
|
14
13
|
.option("--remove", "Remove the specified model instead of updating")
|
|
15
14
|
.action(async (options) => {
|
|
16
|
-
const configManager = new ConfigFileManager();
|
|
17
|
-
const config = configManager.getConfig()
|
|
18
|
-
|
|
19
|
-
const modelName = options.model || config.defaultOllamaModel;
|
|
20
15
|
const ollamaAction = new OllamaAction();
|
|
21
16
|
|
|
22
17
|
if (options.remove) {
|
|
23
|
-
await ollamaAction.removeModel(
|
|
18
|
+
await ollamaAction.removeModel(options.model);
|
|
24
19
|
} else {
|
|
25
|
-
await ollamaAction.updateModel(
|
|
20
|
+
await ollamaAction.updateModel(options.model);
|
|
26
21
|
}
|
|
27
22
|
});
|
|
28
23
|
|