@exagent/agent 0.1.13 → 0.1.14

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/dist/index.js CHANGED
@@ -878,6 +878,187 @@ function getAllStrategyTemplates() {
878
878
  return STRATEGY_TEMPLATES;
879
879
  }
880
880
 
881
+ // src/config.ts
882
+ var import_fs2 = require("fs");
883
+ var import_path2 = require("path");
884
+ var import_dotenv = require("dotenv");
885
+
886
+ // src/types.ts
887
+ var import_zod = require("zod");
888
+ var WalletSetupSchema = import_zod.z.enum(["generate", "provide"]);
889
+ var LLMProviderSchema = import_zod.z.enum(["openai", "anthropic", "google", "deepseek", "mistral", "groq", "together", "ollama", "custom"]);
890
+ var LLMConfigSchema = import_zod.z.object({
891
+ provider: LLMProviderSchema,
892
+ model: import_zod.z.string().optional(),
893
+ apiKey: import_zod.z.string().optional(),
894
+ endpoint: import_zod.z.string().url().optional(),
895
+ temperature: import_zod.z.number().min(0).max(2).default(0.7),
896
+ maxTokens: import_zod.z.number().positive().default(4096)
897
+ });
898
+ var RiskUniverseSchema = import_zod.z.enum(["core", "established", "derivatives", "emerging", "frontier"]);
899
+ var TradingConfigSchema = import_zod.z.object({
900
+ timeHorizon: import_zod.z.enum(["intraday", "swing", "position"]).default("swing"),
901
+ maxPositionSizeBps: import_zod.z.number().min(100).max(1e4).default(1e3),
902
+ // 1-100%
903
+ maxDailyLossBps: import_zod.z.number().min(0).max(1e4).default(500),
904
+ // 0-100%
905
+ maxConcurrentPositions: import_zod.z.number().min(1).max(100).default(5),
906
+ tradingIntervalMs: import_zod.z.number().min(1e3).default(6e4),
907
+ // minimum 1 second
908
+ maxSlippageBps: import_zod.z.number().min(10).max(1e3).default(100),
909
+ // 0.1-10%, default 1%
910
+ minTradeValueUSD: import_zod.z.number().min(0).default(1)
911
+ // minimum trade value in USD
912
+ });
913
+ var VaultPolicySchema = import_zod.z.enum([
914
+ "disabled",
915
+ // Never create a vault - trade with agent's own capital only
916
+ "manual"
917
+ // Only create vault when explicitly directed by owner
918
+ ]);
919
+ var VaultConfigSchema = import_zod.z.object({
920
+ // Policy for vault creation (asked during deployment)
921
+ policy: VaultPolicySchema.default("manual"),
922
+ // Default vault name (auto-generated from agent name if not set)
923
+ defaultName: import_zod.z.string().optional(),
924
+ // Default vault symbol (auto-generated if not set)
925
+ defaultSymbol: import_zod.z.string().optional(),
926
+ // Fee recipient for vault fees (default: agent wallet)
927
+ feeRecipient: import_zod.z.string().optional(),
928
+ // When vault exists, trade through vault instead of direct trading
929
+ // This pools depositors' capital with the agent's trades
930
+ preferVaultTrading: import_zod.z.boolean().default(true)
931
+ });
932
+ var WalletConfigSchema = import_zod.z.object({
933
+ setup: WalletSetupSchema.default("provide")
934
+ }).optional();
935
+ var RelayConfigSchema = import_zod.z.object({
936
+ enabled: import_zod.z.boolean().default(false),
937
+ apiUrl: import_zod.z.string().url(),
938
+ heartbeatIntervalMs: import_zod.z.number().min(5e3).default(3e4)
939
+ }).optional();
940
+ var AgentConfigSchema = import_zod.z.object({
941
+ // Identity (from on-chain registration)
942
+ agentId: import_zod.z.union([import_zod.z.number().positive(), import_zod.z.string()]),
943
+ name: import_zod.z.string().min(3).max(32),
944
+ // Network
945
+ network: import_zod.z.literal("mainnet").default("mainnet"),
946
+ // Wallet setup preference
947
+ wallet: WalletConfigSchema,
948
+ // LLM
949
+ llm: LLMConfigSchema,
950
+ // Trading parameters
951
+ riskUniverse: RiskUniverseSchema.default("established"),
952
+ trading: TradingConfigSchema.default({}),
953
+ // Vault configuration (copy trading)
954
+ vault: VaultConfigSchema.default({}),
955
+ // Relay configuration (command center)
956
+ relay: RelayConfigSchema,
957
+ // Allowed tokens (addresses)
958
+ allowedTokens: import_zod.z.array(import_zod.z.string()).optional()
959
+ });
960
+
961
+ // src/config.ts
962
+ function loadConfig(configPath) {
963
+ (0, import_dotenv.config)();
964
+ const configFile = configPath || process.env.EXAGENT_CONFIG || "agent-config.json";
965
+ const fullPath = configFile.startsWith("/") ? configFile : (0, import_path2.join)(process.cwd(), configFile);
966
+ if (!(0, import_fs2.existsSync)(fullPath)) {
967
+ throw new Error(`Config file not found: ${fullPath}`);
968
+ }
969
+ const rawConfig = JSON.parse((0, import_fs2.readFileSync)(fullPath, "utf-8"));
970
+ const config = AgentConfigSchema.parse(rawConfig);
971
+ const privateKey = process.env.EXAGENT_PRIVATE_KEY;
972
+ if (privateKey && (!privateKey.startsWith("0x") || privateKey.length !== 66)) {
973
+ throw new Error("EXAGENT_PRIVATE_KEY must be a valid 32-byte hex string starting with 0x");
974
+ }
975
+ const llmConfig = { ...config.llm };
976
+ if (process.env.OPENAI_API_KEY && config.llm.provider === "openai") {
977
+ llmConfig.apiKey = process.env.OPENAI_API_KEY;
978
+ }
979
+ if (process.env.ANTHROPIC_API_KEY && config.llm.provider === "anthropic") {
980
+ llmConfig.apiKey = process.env.ANTHROPIC_API_KEY;
981
+ }
982
+ if (process.env.GOOGLE_AI_API_KEY && config.llm.provider === "google") {
983
+ llmConfig.apiKey = process.env.GOOGLE_AI_API_KEY;
984
+ }
985
+ if (process.env.DEEPSEEK_API_KEY && config.llm.provider === "deepseek") {
986
+ llmConfig.apiKey = process.env.DEEPSEEK_API_KEY;
987
+ }
988
+ if (process.env.MISTRAL_API_KEY && config.llm.provider === "mistral") {
989
+ llmConfig.apiKey = process.env.MISTRAL_API_KEY;
990
+ }
991
+ if (process.env.GROQ_API_KEY && config.llm.provider === "groq") {
992
+ llmConfig.apiKey = process.env.GROQ_API_KEY;
993
+ }
994
+ if (process.env.TOGETHER_API_KEY && config.llm.provider === "together") {
995
+ llmConfig.apiKey = process.env.TOGETHER_API_KEY;
996
+ }
997
+ if (process.env.EXAGENT_LLM_URL) {
998
+ llmConfig.endpoint = process.env.EXAGENT_LLM_URL;
999
+ }
1000
+ if (process.env.EXAGENT_LLM_MODEL) {
1001
+ llmConfig.model = process.env.EXAGENT_LLM_MODEL;
1002
+ }
1003
+ const network = process.env.EXAGENT_NETWORK || config.network;
1004
+ return {
1005
+ ...config,
1006
+ llm: llmConfig,
1007
+ network,
1008
+ privateKey: privateKey || ""
1009
+ };
1010
+ }
1011
+ function validateConfig(config) {
1012
+ if (!config.privateKey) {
1013
+ throw new Error("Private key is required");
1014
+ }
1015
+ if (config.llm.provider !== "ollama" && !config.llm.apiKey) {
1016
+ throw new Error(`API key required for ${config.llm.provider} provider`);
1017
+ }
1018
+ if (config.llm.provider === "ollama" && !config.llm.endpoint) {
1019
+ config.llm.endpoint = "http://localhost:11434";
1020
+ }
1021
+ if (config.llm.provider === "custom" && !config.llm.endpoint) {
1022
+ throw new Error("Endpoint required for custom LLM provider");
1023
+ }
1024
+ if (!config.agentId || Number(config.agentId) <= 0) {
1025
+ throw new Error("Valid agent ID required");
1026
+ }
1027
+ }
1028
+ var DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
1029
+ function getRpcUrl() {
1030
+ return process.env.BASE_RPC_URL || process.env.EXAGENT_RPC_URL || DEFAULT_RPC_URL;
1031
+ }
1032
+ function createSampleConfig(agentId, name) {
1033
+ return {
1034
+ agentId,
1035
+ name,
1036
+ network: "mainnet",
1037
+ llm: {
1038
+ provider: "openai",
1039
+ model: "gpt-4.1",
1040
+ temperature: 0.7,
1041
+ maxTokens: 4096
1042
+ },
1043
+ riskUniverse: "established",
1044
+ trading: {
1045
+ timeHorizon: "swing",
1046
+ maxPositionSizeBps: 1e3,
1047
+ maxDailyLossBps: 500,
1048
+ maxConcurrentPositions: 5,
1049
+ tradingIntervalMs: 6e4,
1050
+ maxSlippageBps: 100,
1051
+ minTradeValueUSD: 1
1052
+ },
1053
+ vault: {
1054
+ // Default to manual - user must explicitly enable auto-creation
1055
+ policy: "manual",
1056
+ // Will use agent name for vault name if not set
1057
+ preferVaultTrading: true
1058
+ }
1059
+ };
1060
+ }
1061
+
881
1062
  // src/trading/executor.ts
882
1063
  var TradeExecutor = class {
883
1064
  client;
@@ -1446,7 +1627,7 @@ var VaultManager = class {
1446
1627
  this.addresses = ADDRESSES[config.network];
1447
1628
  this.account = (0, import_accounts.privateKeyToAccount)(config.walletKey);
1448
1629
  this.chain = import_chains.base;
1449
- const rpcUrl = "https://mainnet.base.org";
1630
+ const rpcUrl = getRpcUrl();
1450
1631
  this.publicClient = (0, import_viem2.createPublicClient)({
1451
1632
  chain: this.chain,
1452
1633
  transport: (0, import_viem2.http)(rpcUrl)
@@ -2574,10 +2755,10 @@ var AgentRuntime = class {
2574
2755
  }
2575
2756
  }
2576
2757
  /**
2577
- * Get RPC URL based on network
2758
+ * Get RPC URL from environment or default
2578
2759
  */
2579
2760
  getRpcUrl() {
2580
- return "https://mainnet.base.org";
2761
+ return getRpcUrl();
2581
2762
  }
2582
2763
  /**
2583
2764
  * Default tokens to track.
@@ -2672,183 +2853,6 @@ var AgentRuntime = class {
2672
2853
  }
2673
2854
  };
2674
2855
 
2675
- // src/config.ts
2676
- var import_fs2 = require("fs");
2677
- var import_path2 = require("path");
2678
- var import_dotenv = require("dotenv");
2679
-
2680
- // src/types.ts
2681
- var import_zod = require("zod");
2682
- var WalletSetupSchema = import_zod.z.enum(["generate", "provide"]);
2683
- var LLMProviderSchema = import_zod.z.enum(["openai", "anthropic", "google", "deepseek", "mistral", "groq", "together", "ollama", "custom"]);
2684
- var LLMConfigSchema = import_zod.z.object({
2685
- provider: LLMProviderSchema,
2686
- model: import_zod.z.string().optional(),
2687
- apiKey: import_zod.z.string().optional(),
2688
- endpoint: import_zod.z.string().url().optional(),
2689
- temperature: import_zod.z.number().min(0).max(2).default(0.7),
2690
- maxTokens: import_zod.z.number().positive().default(4096)
2691
- });
2692
- var RiskUniverseSchema = import_zod.z.enum(["core", "established", "derivatives", "emerging", "frontier"]);
2693
- var TradingConfigSchema = import_zod.z.object({
2694
- timeHorizon: import_zod.z.enum(["intraday", "swing", "position"]).default("swing"),
2695
- maxPositionSizeBps: import_zod.z.number().min(100).max(1e4).default(1e3),
2696
- // 1-100%
2697
- maxDailyLossBps: import_zod.z.number().min(0).max(1e4).default(500),
2698
- // 0-100%
2699
- maxConcurrentPositions: import_zod.z.number().min(1).max(100).default(5),
2700
- tradingIntervalMs: import_zod.z.number().min(1e3).default(6e4),
2701
- // minimum 1 second
2702
- maxSlippageBps: import_zod.z.number().min(10).max(1e3).default(100),
2703
- // 0.1-10%, default 1%
2704
- minTradeValueUSD: import_zod.z.number().min(0).default(1)
2705
- // minimum trade value in USD
2706
- });
2707
- var VaultPolicySchema = import_zod.z.enum([
2708
- "disabled",
2709
- // Never create a vault - trade with agent's own capital only
2710
- "manual"
2711
- // Only create vault when explicitly directed by owner
2712
- ]);
2713
- var VaultConfigSchema = import_zod.z.object({
2714
- // Policy for vault creation (asked during deployment)
2715
- policy: VaultPolicySchema.default("manual"),
2716
- // Default vault name (auto-generated from agent name if not set)
2717
- defaultName: import_zod.z.string().optional(),
2718
- // Default vault symbol (auto-generated if not set)
2719
- defaultSymbol: import_zod.z.string().optional(),
2720
- // Fee recipient for vault fees (default: agent wallet)
2721
- feeRecipient: import_zod.z.string().optional(),
2722
- // When vault exists, trade through vault instead of direct trading
2723
- // This pools depositors' capital with the agent's trades
2724
- preferVaultTrading: import_zod.z.boolean().default(true)
2725
- });
2726
- var WalletConfigSchema = import_zod.z.object({
2727
- setup: WalletSetupSchema.default("provide")
2728
- }).optional();
2729
- var RelayConfigSchema = import_zod.z.object({
2730
- enabled: import_zod.z.boolean().default(false),
2731
- apiUrl: import_zod.z.string().url(),
2732
- heartbeatIntervalMs: import_zod.z.number().min(5e3).default(3e4)
2733
- }).optional();
2734
- var AgentConfigSchema = import_zod.z.object({
2735
- // Identity (from on-chain registration)
2736
- agentId: import_zod.z.union([import_zod.z.number().positive(), import_zod.z.string()]),
2737
- name: import_zod.z.string().min(3).max(32),
2738
- // Network
2739
- network: import_zod.z.literal("mainnet").default("mainnet"),
2740
- // Wallet setup preference
2741
- wallet: WalletConfigSchema,
2742
- // LLM
2743
- llm: LLMConfigSchema,
2744
- // Trading parameters
2745
- riskUniverse: RiskUniverseSchema.default("established"),
2746
- trading: TradingConfigSchema.default({}),
2747
- // Vault configuration (copy trading)
2748
- vault: VaultConfigSchema.default({}),
2749
- // Relay configuration (command center)
2750
- relay: RelayConfigSchema,
2751
- // Allowed tokens (addresses)
2752
- allowedTokens: import_zod.z.array(import_zod.z.string()).optional()
2753
- });
2754
-
2755
- // src/config.ts
2756
- function loadConfig(configPath) {
2757
- (0, import_dotenv.config)();
2758
- const configFile = configPath || process.env.EXAGENT_CONFIG || "agent-config.json";
2759
- const fullPath = configFile.startsWith("/") ? configFile : (0, import_path2.join)(process.cwd(), configFile);
2760
- if (!(0, import_fs2.existsSync)(fullPath)) {
2761
- throw new Error(`Config file not found: ${fullPath}`);
2762
- }
2763
- const rawConfig = JSON.parse((0, import_fs2.readFileSync)(fullPath, "utf-8"));
2764
- const config = AgentConfigSchema.parse(rawConfig);
2765
- const privateKey = process.env.EXAGENT_PRIVATE_KEY;
2766
- if (privateKey && (!privateKey.startsWith("0x") || privateKey.length !== 66)) {
2767
- throw new Error("EXAGENT_PRIVATE_KEY must be a valid 32-byte hex string starting with 0x");
2768
- }
2769
- const llmConfig = { ...config.llm };
2770
- if (process.env.OPENAI_API_KEY && config.llm.provider === "openai") {
2771
- llmConfig.apiKey = process.env.OPENAI_API_KEY;
2772
- }
2773
- if (process.env.ANTHROPIC_API_KEY && config.llm.provider === "anthropic") {
2774
- llmConfig.apiKey = process.env.ANTHROPIC_API_KEY;
2775
- }
2776
- if (process.env.GOOGLE_AI_API_KEY && config.llm.provider === "google") {
2777
- llmConfig.apiKey = process.env.GOOGLE_AI_API_KEY;
2778
- }
2779
- if (process.env.DEEPSEEK_API_KEY && config.llm.provider === "deepseek") {
2780
- llmConfig.apiKey = process.env.DEEPSEEK_API_KEY;
2781
- }
2782
- if (process.env.MISTRAL_API_KEY && config.llm.provider === "mistral") {
2783
- llmConfig.apiKey = process.env.MISTRAL_API_KEY;
2784
- }
2785
- if (process.env.GROQ_API_KEY && config.llm.provider === "groq") {
2786
- llmConfig.apiKey = process.env.GROQ_API_KEY;
2787
- }
2788
- if (process.env.TOGETHER_API_KEY && config.llm.provider === "together") {
2789
- llmConfig.apiKey = process.env.TOGETHER_API_KEY;
2790
- }
2791
- if (process.env.EXAGENT_LLM_URL) {
2792
- llmConfig.endpoint = process.env.EXAGENT_LLM_URL;
2793
- }
2794
- if (process.env.EXAGENT_LLM_MODEL) {
2795
- llmConfig.model = process.env.EXAGENT_LLM_MODEL;
2796
- }
2797
- const network = process.env.EXAGENT_NETWORK || config.network;
2798
- return {
2799
- ...config,
2800
- llm: llmConfig,
2801
- network,
2802
- privateKey: privateKey || ""
2803
- };
2804
- }
2805
- function validateConfig(config) {
2806
- if (!config.privateKey) {
2807
- throw new Error("Private key is required");
2808
- }
2809
- if (config.llm.provider !== "ollama" && !config.llm.apiKey) {
2810
- throw new Error(`API key required for ${config.llm.provider} provider`);
2811
- }
2812
- if (config.llm.provider === "ollama" && !config.llm.endpoint) {
2813
- config.llm.endpoint = "http://localhost:11434";
2814
- }
2815
- if (config.llm.provider === "custom" && !config.llm.endpoint) {
2816
- throw new Error("Endpoint required for custom LLM provider");
2817
- }
2818
- if (!config.agentId || Number(config.agentId) <= 0) {
2819
- throw new Error("Valid agent ID required");
2820
- }
2821
- }
2822
- function createSampleConfig(agentId, name) {
2823
- return {
2824
- agentId,
2825
- name,
2826
- network: "mainnet",
2827
- llm: {
2828
- provider: "openai",
2829
- model: "gpt-4.1",
2830
- temperature: 0.7,
2831
- maxTokens: 4096
2832
- },
2833
- riskUniverse: "established",
2834
- trading: {
2835
- timeHorizon: "swing",
2836
- maxPositionSizeBps: 1e3,
2837
- maxDailyLossBps: 500,
2838
- maxConcurrentPositions: 5,
2839
- tradingIntervalMs: 6e4,
2840
- maxSlippageBps: 100,
2841
- minTradeValueUSD: 1
2842
- },
2843
- vault: {
2844
- // Default to manual - user must explicitly enable auto-creation
2845
- policy: "manual",
2846
- // Will use agent name for vault name if not set
2847
- preferVaultTrading: true
2848
- }
2849
- };
2850
- }
2851
-
2852
2856
  // src/secure-env.ts
2853
2857
  var crypto = __toESM(require("crypto"));
2854
2858
  var fs = __toESM(require("fs"));
package/dist/index.mjs CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  loadStrategy,
35
35
  validateConfig,
36
36
  validateStrategy
37
- } from "./chunk-BSNYL2DK.mjs";
37
+ } from "./chunk-YWPRVCRB.mjs";
38
38
  export {
39
39
  AgentConfigSchema,
40
40
  AgentRuntime,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exagent/agent",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Autonomous trading agent runtime for Exagent",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,7 +29,7 @@
29
29
  "clean": "rm -rf dist"
30
30
  },
31
31
  "dependencies": {
32
- "@exagent/sdk": "^0.1.5",
32
+ "@exagent/sdk": "^0.1.6",
33
33
  "chalk": "^5.3.0",
34
34
  "commander": "^12.0.0",
35
35
  "dotenv": "^16.4.0",