genlayer 0.10.1 → 0.10.2

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,12 @@
1
1
 
2
2
 
3
+ ## 0.10.2 (2025-01-30)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * updated studio version ([#174](https://github.com/yeagerai/genlayer-cli/issues/174)) ([e70e7f2](https://github.com/yeagerai/genlayer-cli/commit/e70e7f2e549abc9c9633ae066820fb272c9334ee))
9
+
3
10
  ## 0.10.1 (2025-01-29)
4
11
 
5
12
 
package/dist/index.js CHANGED
@@ -54537,7 +54537,7 @@ var {
54537
54537
  } = import_index.default;
54538
54538
 
54539
54539
  // package.json
54540
- var version = "0.10.1";
54540
+ var version = "0.10.2";
54541
54541
  var package_default = {
54542
54542
  name: "genlayer",
54543
54543
  version,
@@ -54678,7 +54678,7 @@ function v4(options, buf, offset) {
54678
54678
  var v4_default = v4;
54679
54679
 
54680
54680
  // src/lib/config/simulator.ts
54681
- var localnetCompatibleVersion = "v0.34.3";
54681
+ var localnetCompatibleVersion = "v0.35.2";
54682
54682
  var DEFAULT_JSON_RPC_URL = "http://localhost:4000/api";
54683
54683
  var CONTAINERS_NAME_PREFIX = "/genlayer-";
54684
54684
  var IMAGES_NAME_PREFIX = "yeagerai";
@@ -54726,26 +54726,23 @@ var JsonRpcClient = class {
54726
54726
  this.serverUrl = serverUrl;
54727
54727
  }
54728
54728
  async request({ method, params }) {
54729
- try {
54730
- const response = await (0, import_node_fetch.default)(this.serverUrl, {
54731
- method: "POST",
54732
- headers: {
54733
- "Content-Type": "application/json"
54734
- },
54735
- body: JSON.stringify({
54736
- jsonrpc: "2.0",
54737
- id: v4_default(),
54738
- method,
54739
- params
54740
- })
54741
- });
54742
- if (response.ok) {
54743
- return response.json();
54744
- }
54745
- } catch (error) {
54746
- throw new Error(`Fetch Error: ${error.message}`);
54729
+ const response = await (0, import_node_fetch.default)(this.serverUrl, {
54730
+ method: "POST",
54731
+ headers: {
54732
+ "Content-Type": "application/json"
54733
+ },
54734
+ body: JSON.stringify({
54735
+ jsonrpc: "2.0",
54736
+ id: v4_default(),
54737
+ method,
54738
+ params
54739
+ })
54740
+ });
54741
+ if (response.ok) {
54742
+ return response.json();
54747
54743
  }
54748
- return null;
54744
+ const result = await response.json();
54745
+ throw new Error(result?.error?.message || response.statusText);
54749
54746
  }
54750
54747
  };
54751
54748
  var rpcClient = new JsonRpcClient(DEFAULT_JSON_RPC_URL);
@@ -55382,12 +55379,12 @@ Run npm install -g genlayer to update
55382
55379
  }
55383
55380
  createRandomValidators(numValidators, llmProviders) {
55384
55381
  return rpcClient.request({
55385
- method: "create_random_validators",
55382
+ method: "sim_createRandomValidators",
55386
55383
  params: [numValidators, 1, 10, llmProviders]
55387
55384
  });
55388
55385
  }
55389
55386
  deleteAllValidators() {
55390
- return rpcClient.request({ method: "delete_all_validators", params: [] });
55387
+ return rpcClient.request({ method: "sim_deleteAllValidators", params: [] });
55391
55388
  }
55392
55389
  getAiProvidersOptions(withHint = true) {
55393
55390
  return Object.values(AI_PROVIDERS_CONFIG).map((providerConfig) => {
@@ -86776,6 +86773,273 @@ function initializeConfigCommands(program2) {
86776
86773
  return program2;
86777
86774
  }
86778
86775
 
86776
+ // src/lib/actions/BaseAction.ts
86777
+ var BaseAction = class {
86778
+ async confirmPrompt(message) {
86779
+ const answer = await lib_default.prompt([
86780
+ {
86781
+ type: "confirm",
86782
+ name: "confirmAction",
86783
+ message,
86784
+ default: true
86785
+ }
86786
+ ]);
86787
+ if (!answer.confirmAction) {
86788
+ console.log("Operation aborted!");
86789
+ process.exit(0);
86790
+ }
86791
+ }
86792
+ };
86793
+
86794
+ // src/commands/validators/validators.ts
86795
+ var ValidatorsAction = class extends BaseAction {
86796
+ async getValidator(options) {
86797
+ try {
86798
+ if (options.address) {
86799
+ console.log(`Fetching validator with address: ${options.address}`);
86800
+ const result = await rpcClient.request({
86801
+ method: "sim_getValidator",
86802
+ params: [options.address]
86803
+ });
86804
+ console.log("Validator Details:", result.result);
86805
+ } else {
86806
+ console.log("Fetching all validators...");
86807
+ const result = await rpcClient.request({
86808
+ method: "sim_getAllValidators",
86809
+ params: []
86810
+ });
86811
+ console.log("All Validators:", result.result);
86812
+ }
86813
+ } catch (error) {
86814
+ console.error("Error fetching validators:", error);
86815
+ }
86816
+ }
86817
+ async deleteValidator(options) {
86818
+ try {
86819
+ if (options.address) {
86820
+ await this.confirmPrompt(`This command will delete the validator with the address: ${options.address}. Do you want to continue?`);
86821
+ console.log(`Deleting validator with address: ${options.address}`);
86822
+ const result = await rpcClient.request({
86823
+ method: "sim_deleteValidator",
86824
+ params: [options.address]
86825
+ });
86826
+ console.log("Deleted Address:", result.result);
86827
+ } else {
86828
+ await this.confirmPrompt(`This command will delete all validators. Do you want to continue?`);
86829
+ console.log("Deleting all validators...");
86830
+ await rpcClient.request({
86831
+ method: "sim_deleteAllValidators",
86832
+ params: []
86833
+ });
86834
+ console.log("Successfully deleted all validators");
86835
+ }
86836
+ } catch (error) {
86837
+ console.error("Error deleting validators:", error);
86838
+ }
86839
+ }
86840
+ async countValidators() {
86841
+ try {
86842
+ console.log("Counting all validators...");
86843
+ const result = await rpcClient.request({
86844
+ method: "sim_countValidators",
86845
+ params: []
86846
+ });
86847
+ console.log("Total Validators:", result.result);
86848
+ } catch (error) {
86849
+ console.error("Error counting validators:", error);
86850
+ }
86851
+ }
86852
+ async updateValidator(options) {
86853
+ try {
86854
+ console.log(`Fetching validator with address: ${options.address}...`);
86855
+ const currentValidator = await rpcClient.request({
86856
+ method: "sim_getValidator",
86857
+ params: [options.address]
86858
+ });
86859
+ if (!currentValidator.result) {
86860
+ throw new Error(`Validator with address ${options.address} not found.`);
86861
+ }
86862
+ console.log("Current Validator Details:", currentValidator.result);
86863
+ const parsedStake = options.stake ? parseInt(options.stake, 10) : currentValidator.result.stake;
86864
+ if (isNaN(parsedStake) || parsedStake < 0) {
86865
+ return console.error("Invalid stake value. Stake must be a positive integer.");
86866
+ }
86867
+ const updatedValidator = {
86868
+ address: options.address,
86869
+ stake: options.stake || currentValidator.result.stake,
86870
+ provider: options.provider || currentValidator.result.provider,
86871
+ model: options.model || currentValidator.result.model,
86872
+ config: options.config ? JSON.parse(options.config) : currentValidator.result.config
86873
+ };
86874
+ console.log("Updated Validator Details:", updatedValidator);
86875
+ const result = await rpcClient.request({
86876
+ method: "sim_updateValidator",
86877
+ params: [
86878
+ updatedValidator.address,
86879
+ updatedValidator.stake,
86880
+ updatedValidator.provider,
86881
+ updatedValidator.model,
86882
+ updatedValidator.config
86883
+ ]
86884
+ });
86885
+ console.log("Validator successfully updated:", result.result);
86886
+ } catch (error) {
86887
+ console.error("Error updating validator:", error);
86888
+ }
86889
+ }
86890
+ async createRandomValidators(options) {
86891
+ try {
86892
+ const count = parseInt(options.count, 10);
86893
+ if (isNaN(count) || count < 1) {
86894
+ return console.error("Invalid count. Please provide a positive integer.");
86895
+ }
86896
+ console.log(`Creating ${count} random validator(s)...`);
86897
+ console.log(`Providers: ${options.providers.length > 0 ? options.providers.join(", ") : "None"}`);
86898
+ console.log(`Models: ${options.models.length > 0 ? options.models.join(", ") : "None"}`);
86899
+ const result = await rpcClient.request({
86900
+ method: "sim_createRandomValidators",
86901
+ params: [count, 1, 10, options.providers, options.models]
86902
+ });
86903
+ console.log("Random validators successfully created:", result.result);
86904
+ } catch (error) {
86905
+ console.error("Error creating random validators:", error);
86906
+ }
86907
+ }
86908
+ async createValidator(options) {
86909
+ try {
86910
+ const stake = parseInt(options.stake, 10);
86911
+ if (isNaN(stake) || stake < 1) {
86912
+ return console.error("Invalid stake. Please provide a positive integer.");
86913
+ }
86914
+ if (options.model && !options.provider) {
86915
+ return console.error("You must specify a provider if using a model.");
86916
+ }
86917
+ console.log("Fetching available providers and models...");
86918
+ const providersAndModels = await rpcClient.request({
86919
+ method: "sim_getProvidersAndModels",
86920
+ params: []
86921
+ });
86922
+ if (!providersAndModels.result || providersAndModels.result.length === 0) {
86923
+ return console.error("No providers or models available.");
86924
+ }
86925
+ const availableProviders = [
86926
+ ...new Map(
86927
+ providersAndModels.result.filter((entry) => entry.is_available).map((entry) => [entry.provider, entry])
86928
+ ).values()
86929
+ ];
86930
+ let provider = options.provider;
86931
+ if (!provider) {
86932
+ const { selectedProvider } = await lib_default.prompt([
86933
+ {
86934
+ type: "list",
86935
+ name: "selectedProvider",
86936
+ message: "Select a provider:",
86937
+ choices: availableProviders.map((entry) => entry.provider)
86938
+ }
86939
+ ]);
86940
+ provider = selectedProvider;
86941
+ }
86942
+ const availableModels = providersAndModels.result.filter(
86943
+ (entry) => entry.provider === provider && entry.is_model_available
86944
+ );
86945
+ if (availableModels.length === 0) {
86946
+ return console.error("No models available for the selected provider.");
86947
+ }
86948
+ let model = options.model;
86949
+ if (!model) {
86950
+ const { selectedModel } = await lib_default.prompt([
86951
+ {
86952
+ type: "list",
86953
+ name: "selectedModel",
86954
+ message: "Select a model:",
86955
+ choices: availableModels.map((entry) => entry.model)
86956
+ }
86957
+ ]);
86958
+ model = selectedModel;
86959
+ }
86960
+ const modelDetails = availableModels.find(
86961
+ (entry) => entry.model === model
86962
+ );
86963
+ if (!modelDetails) {
86964
+ return console.error("Selected model details not found.");
86965
+ }
86966
+ const config = options.config ? JSON.parse(options.config) : modelDetails.config;
86967
+ console.log("Creating validator with the following details:");
86968
+ console.log(`Stake: ${stake}`);
86969
+ console.log(`Provider: ${modelDetails.provider}`);
86970
+ console.log(`Model: ${modelDetails.model}`);
86971
+ console.log(`Config:`, config);
86972
+ console.log(`Plugin:`, modelDetails.plugin);
86973
+ console.log(`Plugin Config:`, modelDetails.plugin_config);
86974
+ const result = await rpcClient.request({
86975
+ method: "sim_createValidator",
86976
+ params: [
86977
+ stake,
86978
+ modelDetails.provider,
86979
+ modelDetails.model,
86980
+ config,
86981
+ modelDetails.plugin,
86982
+ modelDetails.plugin_config
86983
+ ]
86984
+ });
86985
+ console.log("Validator successfully created:", result.result);
86986
+ } catch (error) {
86987
+ console.error("Error creating validator:", error);
86988
+ }
86989
+ }
86990
+ };
86991
+
86992
+ // src/commands/validators/index.ts
86993
+ function initializeValidatorCommands(program2) {
86994
+ const validatorsAction = new ValidatorsAction();
86995
+ const validatorsCommand = program2.command("validators").description("Manage validator operations");
86996
+ validatorsCommand.command("get").description("Retrieve details of a specific validator or all validators").option("--address <validatorAddress>", "The address of the validator to retrieve (omit to retrieve all validators)").action(async (options) => {
86997
+ await validatorsAction.getValidator({ address: options.address });
86998
+ });
86999
+ validatorsCommand.command("delete").description("Delete a specific validator or all validators").option("--address <validatorAddress>", "The address of the validator to delete (omit to delete all validators)").action(async (options) => {
87000
+ await validatorsAction.deleteValidator({ address: options.address });
87001
+ });
87002
+ validatorsCommand.command("count").description("Count all validators").action(async () => {
87003
+ await validatorsAction.countValidators();
87004
+ });
87005
+ validatorsCommand.command("update <validatorAddress>").description("Update a validator's details").option("--stake <stake>", "New stake for the validator").option("--provider <provider>", "New provider for the validator").option("--model <model>", "New model for the validator").option("--config <config>", "New JSON config for the validator").action(async (validatorAddress, options) => {
87006
+ await validatorsAction.updateValidator({
87007
+ address: validatorAddress,
87008
+ stake: options.stake,
87009
+ provider: options.provider,
87010
+ model: options.model,
87011
+ config: options.config
87012
+ });
87013
+ });
87014
+ validatorsCommand.command("create-random").description("Create random validators").option("--count <count>", "Number of validators to create", "1").option(
87015
+ "--providers <providers...>",
87016
+ "Space-separated list of provider names (e.g., openai ollama)",
87017
+ []
87018
+ ).option(
87019
+ "--models <models...>",
87020
+ "Space-separated list of model names (e.g., gpt-4 gpt-4o)",
87021
+ []
87022
+ ).action(async (options) => {
87023
+ await validatorsAction.createRandomValidators({
87024
+ count: options.count,
87025
+ providers: options.providers,
87026
+ models: options.models
87027
+ });
87028
+ });
87029
+ validatorsCommand.command("create").description("Create a new validator").option("--stake <stake>", "Stake amount for the validator (default: 1)", "1").option(
87030
+ "--config <config>",
87031
+ `Optional JSON configuration for the validator (e.g., '{"max_tokens": 500, "temperature": 0.75}')`
87032
+ ).option("--provider <provider>", "Specify the provider for the validator").option("--model <model>", "Specify the model for the validator").action(async (options) => {
87033
+ await validatorsAction.createValidator({
87034
+ stake: options.stake,
87035
+ config: options.config,
87036
+ provider: options.provider,
87037
+ model: options.model
87038
+ });
87039
+ });
87040
+ return program2;
87041
+ }
87042
+
86779
87043
  // src/commands/update/index.ts
86780
87044
  function initializeUpdateCommands(program2) {
86781
87045
  const updateCommand = program2.command("update").description("Update resources like models or configurations");
@@ -86799,6 +87063,7 @@ function initializeCLI() {
86799
87063
  initializeContractsCommands(program);
86800
87064
  initializeConfigCommands(program);
86801
87065
  initializeUpdateCommands(program);
87066
+ initializeValidatorCommands(program);
86802
87067
  program.parse(process.argv);
86803
87068
  }
86804
87069
  initializeCLI();
@@ -61,6 +61,9 @@ services:
61
61
  max-file: "3"
62
62
  deploy:
63
63
  replicas: ${JSONRPC_REPLICAS:-1}
64
+ volumes:
65
+ - hardhat_artifacts:/app/hardhat/artifacts
66
+ - hardhat_deployments:/app/hardhat/deployments
64
67
 
65
68
  webrequest:
66
69
  image: yeagerai/simulator-webrequest:${LOCALNETVERSION:-latest}
@@ -144,8 +147,15 @@ services:
144
147
  condition: service_healthy
145
148
 
146
149
  hardhat:
147
- image: yeagerai/simulator-hardhat
150
+ image: yeagerai/simulator-hardhat:${LOCALNETVERSION:-latest}
148
151
  ports:
149
152
  - "${HARDHAT_PORT:-8545}:8545"
150
153
  environment:
151
- - HARDHAT_NETWORK=hardhat
154
+ - HARDHAT_NETWORK=hardhat
155
+ volumes:
156
+ - hardhat_artifacts:/app/artifacts
157
+ - hardhat_deployments:/app/deployments
158
+
159
+ volumes:
160
+ hardhat_artifacts:
161
+ hardhat_deployments:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -0,0 +1,94 @@
1
+ import { Command } from "commander";
2
+ import { ValidatorsAction } from "./validators";
3
+
4
+ export function initializeValidatorCommands(program: Command) {
5
+ const validatorsAction = new ValidatorsAction();
6
+
7
+ const validatorsCommand = program
8
+ .command("validators")
9
+ .description("Manage validator operations");
10
+
11
+ validatorsCommand
12
+ .command("get")
13
+
14
+ .description("Retrieve details of a specific validator or all validators")
15
+ .option("--address <validatorAddress>", "The address of the validator to retrieve (omit to retrieve all validators)")
16
+ .action(async (options) => {
17
+ await validatorsAction.getValidator({ address: options.address });
18
+ });
19
+
20
+ validatorsCommand
21
+ .command("delete")
22
+ .description("Delete a specific validator or all validators")
23
+ .option("--address <validatorAddress>", "The address of the validator to delete (omit to delete all validators)")
24
+ .action(async (options) => {
25
+ await validatorsAction.deleteValidator({ address: options.address });
26
+ });
27
+
28
+ validatorsCommand
29
+ .command("count")
30
+ .description("Count all validators")
31
+ .action(async () => {
32
+ await validatorsAction.countValidators();
33
+ });
34
+
35
+ validatorsCommand
36
+ .command("update <validatorAddress>")
37
+ .description("Update a validator's details")
38
+ .option("--stake <stake>", "New stake for the validator")
39
+ .option("--provider <provider>", "New provider for the validator")
40
+ .option("--model <model>", "New model for the validator")
41
+ .option("--config <config>", "New JSON config for the validator")
42
+ .action(async (validatorAddress, options) => {
43
+ await validatorsAction.updateValidator({
44
+ address: validatorAddress,
45
+ stake: options.stake,
46
+ provider: options.provider,
47
+ model: options.model,
48
+ config: options.config,
49
+ });
50
+ });
51
+
52
+ validatorsCommand
53
+ .command("create-random")
54
+ .description("Create random validators")
55
+ .option("--count <count>", "Number of validators to create", "1") // Default to "1"
56
+ .option(
57
+ "--providers <providers...>",
58
+ "Space-separated list of provider names (e.g., openai ollama)",
59
+ []
60
+ )
61
+ .option(
62
+ "--models <models...>",
63
+ "Space-separated list of model names (e.g., gpt-4 gpt-4o)",
64
+ []
65
+ )
66
+ .action(async (options) => {
67
+ await validatorsAction.createRandomValidators({
68
+ count: options.count,
69
+ providers: options.providers,
70
+ models: options.models,
71
+ });
72
+ });
73
+
74
+ validatorsCommand
75
+ .command("create")
76
+ .description("Create a new validator")
77
+ .option("--stake <stake>", "Stake amount for the validator (default: 1)", "1")
78
+ .option(
79
+ "--config <config>",
80
+ 'Optional JSON configuration for the validator (e.g., \'{"max_tokens": 500, "temperature": 0.75}\')'
81
+ )
82
+ .option("--provider <provider>", "Specify the provider for the validator")
83
+ .option("--model <model>", "Specify the model for the validator")
84
+ .action(async (options) => {
85
+ await validatorsAction.createValidator({
86
+ stake: options.stake,
87
+ config: options.config,
88
+ provider: options.provider,
89
+ model: options.model,
90
+ });
91
+ });
92
+
93
+ return program;
94
+ }