@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/chunk-YWPRVCRB.mjs +3009 -0
- package/dist/cli.js +155 -151
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +184 -180
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -834,6 +834,158 @@ function getAllStrategyTemplates() {
|
|
|
834
834
|
return STRATEGY_TEMPLATES;
|
|
835
835
|
}
|
|
836
836
|
|
|
837
|
+
// src/config.ts
|
|
838
|
+
var import_fs2 = require("fs");
|
|
839
|
+
var import_path2 = require("path");
|
|
840
|
+
var import_dotenv = require("dotenv");
|
|
841
|
+
|
|
842
|
+
// src/types.ts
|
|
843
|
+
var import_zod = require("zod");
|
|
844
|
+
var WalletSetupSchema = import_zod.z.enum(["generate", "provide"]);
|
|
845
|
+
var LLMProviderSchema = import_zod.z.enum(["openai", "anthropic", "google", "deepseek", "mistral", "groq", "together", "ollama", "custom"]);
|
|
846
|
+
var LLMConfigSchema = import_zod.z.object({
|
|
847
|
+
provider: LLMProviderSchema,
|
|
848
|
+
model: import_zod.z.string().optional(),
|
|
849
|
+
apiKey: import_zod.z.string().optional(),
|
|
850
|
+
endpoint: import_zod.z.string().url().optional(),
|
|
851
|
+
temperature: import_zod.z.number().min(0).max(2).default(0.7),
|
|
852
|
+
maxTokens: import_zod.z.number().positive().default(4096)
|
|
853
|
+
});
|
|
854
|
+
var RiskUniverseSchema = import_zod.z.enum(["core", "established", "derivatives", "emerging", "frontier"]);
|
|
855
|
+
var TradingConfigSchema = import_zod.z.object({
|
|
856
|
+
timeHorizon: import_zod.z.enum(["intraday", "swing", "position"]).default("swing"),
|
|
857
|
+
maxPositionSizeBps: import_zod.z.number().min(100).max(1e4).default(1e3),
|
|
858
|
+
// 1-100%
|
|
859
|
+
maxDailyLossBps: import_zod.z.number().min(0).max(1e4).default(500),
|
|
860
|
+
// 0-100%
|
|
861
|
+
maxConcurrentPositions: import_zod.z.number().min(1).max(100).default(5),
|
|
862
|
+
tradingIntervalMs: import_zod.z.number().min(1e3).default(6e4),
|
|
863
|
+
// minimum 1 second
|
|
864
|
+
maxSlippageBps: import_zod.z.number().min(10).max(1e3).default(100),
|
|
865
|
+
// 0.1-10%, default 1%
|
|
866
|
+
minTradeValueUSD: import_zod.z.number().min(0).default(1)
|
|
867
|
+
// minimum trade value in USD
|
|
868
|
+
});
|
|
869
|
+
var VaultPolicySchema = import_zod.z.enum([
|
|
870
|
+
"disabled",
|
|
871
|
+
// Never create a vault - trade with agent's own capital only
|
|
872
|
+
"manual"
|
|
873
|
+
// Only create vault when explicitly directed by owner
|
|
874
|
+
]);
|
|
875
|
+
var VaultConfigSchema = import_zod.z.object({
|
|
876
|
+
// Policy for vault creation (asked during deployment)
|
|
877
|
+
policy: VaultPolicySchema.default("manual"),
|
|
878
|
+
// Default vault name (auto-generated from agent name if not set)
|
|
879
|
+
defaultName: import_zod.z.string().optional(),
|
|
880
|
+
// Default vault symbol (auto-generated if not set)
|
|
881
|
+
defaultSymbol: import_zod.z.string().optional(),
|
|
882
|
+
// Fee recipient for vault fees (default: agent wallet)
|
|
883
|
+
feeRecipient: import_zod.z.string().optional(),
|
|
884
|
+
// When vault exists, trade through vault instead of direct trading
|
|
885
|
+
// This pools depositors' capital with the agent's trades
|
|
886
|
+
preferVaultTrading: import_zod.z.boolean().default(true)
|
|
887
|
+
});
|
|
888
|
+
var WalletConfigSchema = import_zod.z.object({
|
|
889
|
+
setup: WalletSetupSchema.default("provide")
|
|
890
|
+
}).optional();
|
|
891
|
+
var RelayConfigSchema = import_zod.z.object({
|
|
892
|
+
enabled: import_zod.z.boolean().default(false),
|
|
893
|
+
apiUrl: import_zod.z.string().url(),
|
|
894
|
+
heartbeatIntervalMs: import_zod.z.number().min(5e3).default(3e4)
|
|
895
|
+
}).optional();
|
|
896
|
+
var AgentConfigSchema = import_zod.z.object({
|
|
897
|
+
// Identity (from on-chain registration)
|
|
898
|
+
agentId: import_zod.z.union([import_zod.z.number().positive(), import_zod.z.string()]),
|
|
899
|
+
name: import_zod.z.string().min(3).max(32),
|
|
900
|
+
// Network
|
|
901
|
+
network: import_zod.z.literal("mainnet").default("mainnet"),
|
|
902
|
+
// Wallet setup preference
|
|
903
|
+
wallet: WalletConfigSchema,
|
|
904
|
+
// LLM
|
|
905
|
+
llm: LLMConfigSchema,
|
|
906
|
+
// Trading parameters
|
|
907
|
+
riskUniverse: RiskUniverseSchema.default("established"),
|
|
908
|
+
trading: TradingConfigSchema.default({}),
|
|
909
|
+
// Vault configuration (copy trading)
|
|
910
|
+
vault: VaultConfigSchema.default({}),
|
|
911
|
+
// Relay configuration (command center)
|
|
912
|
+
relay: RelayConfigSchema,
|
|
913
|
+
// Allowed tokens (addresses)
|
|
914
|
+
allowedTokens: import_zod.z.array(import_zod.z.string()).optional()
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
// src/config.ts
|
|
918
|
+
function loadConfig(configPath) {
|
|
919
|
+
(0, import_dotenv.config)();
|
|
920
|
+
const configFile = configPath || process.env.EXAGENT_CONFIG || "agent-config.json";
|
|
921
|
+
const fullPath = configFile.startsWith("/") ? configFile : (0, import_path2.join)(process.cwd(), configFile);
|
|
922
|
+
if (!(0, import_fs2.existsSync)(fullPath)) {
|
|
923
|
+
throw new Error(`Config file not found: ${fullPath}`);
|
|
924
|
+
}
|
|
925
|
+
const rawConfig = JSON.parse((0, import_fs2.readFileSync)(fullPath, "utf-8"));
|
|
926
|
+
const config = AgentConfigSchema.parse(rawConfig);
|
|
927
|
+
const privateKey = process.env.EXAGENT_PRIVATE_KEY;
|
|
928
|
+
if (privateKey && (!privateKey.startsWith("0x") || privateKey.length !== 66)) {
|
|
929
|
+
throw new Error("EXAGENT_PRIVATE_KEY must be a valid 32-byte hex string starting with 0x");
|
|
930
|
+
}
|
|
931
|
+
const llmConfig = { ...config.llm };
|
|
932
|
+
if (process.env.OPENAI_API_KEY && config.llm.provider === "openai") {
|
|
933
|
+
llmConfig.apiKey = process.env.OPENAI_API_KEY;
|
|
934
|
+
}
|
|
935
|
+
if (process.env.ANTHROPIC_API_KEY && config.llm.provider === "anthropic") {
|
|
936
|
+
llmConfig.apiKey = process.env.ANTHROPIC_API_KEY;
|
|
937
|
+
}
|
|
938
|
+
if (process.env.GOOGLE_AI_API_KEY && config.llm.provider === "google") {
|
|
939
|
+
llmConfig.apiKey = process.env.GOOGLE_AI_API_KEY;
|
|
940
|
+
}
|
|
941
|
+
if (process.env.DEEPSEEK_API_KEY && config.llm.provider === "deepseek") {
|
|
942
|
+
llmConfig.apiKey = process.env.DEEPSEEK_API_KEY;
|
|
943
|
+
}
|
|
944
|
+
if (process.env.MISTRAL_API_KEY && config.llm.provider === "mistral") {
|
|
945
|
+
llmConfig.apiKey = process.env.MISTRAL_API_KEY;
|
|
946
|
+
}
|
|
947
|
+
if (process.env.GROQ_API_KEY && config.llm.provider === "groq") {
|
|
948
|
+
llmConfig.apiKey = process.env.GROQ_API_KEY;
|
|
949
|
+
}
|
|
950
|
+
if (process.env.TOGETHER_API_KEY && config.llm.provider === "together") {
|
|
951
|
+
llmConfig.apiKey = process.env.TOGETHER_API_KEY;
|
|
952
|
+
}
|
|
953
|
+
if (process.env.EXAGENT_LLM_URL) {
|
|
954
|
+
llmConfig.endpoint = process.env.EXAGENT_LLM_URL;
|
|
955
|
+
}
|
|
956
|
+
if (process.env.EXAGENT_LLM_MODEL) {
|
|
957
|
+
llmConfig.model = process.env.EXAGENT_LLM_MODEL;
|
|
958
|
+
}
|
|
959
|
+
const network = process.env.EXAGENT_NETWORK || config.network;
|
|
960
|
+
return {
|
|
961
|
+
...config,
|
|
962
|
+
llm: llmConfig,
|
|
963
|
+
network,
|
|
964
|
+
privateKey: privateKey || ""
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
function validateConfig(config) {
|
|
968
|
+
if (!config.privateKey) {
|
|
969
|
+
throw new Error("Private key is required");
|
|
970
|
+
}
|
|
971
|
+
if (config.llm.provider !== "ollama" && !config.llm.apiKey) {
|
|
972
|
+
throw new Error(`API key required for ${config.llm.provider} provider`);
|
|
973
|
+
}
|
|
974
|
+
if (config.llm.provider === "ollama" && !config.llm.endpoint) {
|
|
975
|
+
config.llm.endpoint = "http://localhost:11434";
|
|
976
|
+
}
|
|
977
|
+
if (config.llm.provider === "custom" && !config.llm.endpoint) {
|
|
978
|
+
throw new Error("Endpoint required for custom LLM provider");
|
|
979
|
+
}
|
|
980
|
+
if (!config.agentId || Number(config.agentId) <= 0) {
|
|
981
|
+
throw new Error("Valid agent ID required");
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
var DEFAULT_RPC_URL = "https://base-rpc.publicnode.com";
|
|
985
|
+
function getRpcUrl() {
|
|
986
|
+
return process.env.BASE_RPC_URL || process.env.EXAGENT_RPC_URL || DEFAULT_RPC_URL;
|
|
987
|
+
}
|
|
988
|
+
|
|
837
989
|
// src/trading/executor.ts
|
|
838
990
|
var TradeExecutor = class {
|
|
839
991
|
client;
|
|
@@ -1402,7 +1554,7 @@ var VaultManager = class {
|
|
|
1402
1554
|
this.addresses = ADDRESSES[config.network];
|
|
1403
1555
|
this.account = (0, import_accounts.privateKeyToAccount)(config.walletKey);
|
|
1404
1556
|
this.chain = import_chains.base;
|
|
1405
|
-
const rpcUrl =
|
|
1557
|
+
const rpcUrl = getRpcUrl();
|
|
1406
1558
|
this.publicClient = (0, import_viem2.createPublicClient)({
|
|
1407
1559
|
chain: this.chain,
|
|
1408
1560
|
transport: (0, import_viem2.http)(rpcUrl)
|
|
@@ -2530,10 +2682,10 @@ var AgentRuntime = class {
|
|
|
2530
2682
|
}
|
|
2531
2683
|
}
|
|
2532
2684
|
/**
|
|
2533
|
-
* Get RPC URL
|
|
2685
|
+
* Get RPC URL from environment or default
|
|
2534
2686
|
*/
|
|
2535
2687
|
getRpcUrl() {
|
|
2536
|
-
return
|
|
2688
|
+
return getRpcUrl();
|
|
2537
2689
|
}
|
|
2538
2690
|
/**
|
|
2539
2691
|
* Default tokens to track.
|
|
@@ -2628,154 +2780,6 @@ var AgentRuntime = class {
|
|
|
2628
2780
|
}
|
|
2629
2781
|
};
|
|
2630
2782
|
|
|
2631
|
-
// src/config.ts
|
|
2632
|
-
var import_fs2 = require("fs");
|
|
2633
|
-
var import_path2 = require("path");
|
|
2634
|
-
var import_dotenv = require("dotenv");
|
|
2635
|
-
|
|
2636
|
-
// src/types.ts
|
|
2637
|
-
var import_zod = require("zod");
|
|
2638
|
-
var WalletSetupSchema = import_zod.z.enum(["generate", "provide"]);
|
|
2639
|
-
var LLMProviderSchema = import_zod.z.enum(["openai", "anthropic", "google", "deepseek", "mistral", "groq", "together", "ollama", "custom"]);
|
|
2640
|
-
var LLMConfigSchema = import_zod.z.object({
|
|
2641
|
-
provider: LLMProviderSchema,
|
|
2642
|
-
model: import_zod.z.string().optional(),
|
|
2643
|
-
apiKey: import_zod.z.string().optional(),
|
|
2644
|
-
endpoint: import_zod.z.string().url().optional(),
|
|
2645
|
-
temperature: import_zod.z.number().min(0).max(2).default(0.7),
|
|
2646
|
-
maxTokens: import_zod.z.number().positive().default(4096)
|
|
2647
|
-
});
|
|
2648
|
-
var RiskUniverseSchema = import_zod.z.enum(["core", "established", "derivatives", "emerging", "frontier"]);
|
|
2649
|
-
var TradingConfigSchema = import_zod.z.object({
|
|
2650
|
-
timeHorizon: import_zod.z.enum(["intraday", "swing", "position"]).default("swing"),
|
|
2651
|
-
maxPositionSizeBps: import_zod.z.number().min(100).max(1e4).default(1e3),
|
|
2652
|
-
// 1-100%
|
|
2653
|
-
maxDailyLossBps: import_zod.z.number().min(0).max(1e4).default(500),
|
|
2654
|
-
// 0-100%
|
|
2655
|
-
maxConcurrentPositions: import_zod.z.number().min(1).max(100).default(5),
|
|
2656
|
-
tradingIntervalMs: import_zod.z.number().min(1e3).default(6e4),
|
|
2657
|
-
// minimum 1 second
|
|
2658
|
-
maxSlippageBps: import_zod.z.number().min(10).max(1e3).default(100),
|
|
2659
|
-
// 0.1-10%, default 1%
|
|
2660
|
-
minTradeValueUSD: import_zod.z.number().min(0).default(1)
|
|
2661
|
-
// minimum trade value in USD
|
|
2662
|
-
});
|
|
2663
|
-
var VaultPolicySchema = import_zod.z.enum([
|
|
2664
|
-
"disabled",
|
|
2665
|
-
// Never create a vault - trade with agent's own capital only
|
|
2666
|
-
"manual"
|
|
2667
|
-
// Only create vault when explicitly directed by owner
|
|
2668
|
-
]);
|
|
2669
|
-
var VaultConfigSchema = import_zod.z.object({
|
|
2670
|
-
// Policy for vault creation (asked during deployment)
|
|
2671
|
-
policy: VaultPolicySchema.default("manual"),
|
|
2672
|
-
// Default vault name (auto-generated from agent name if not set)
|
|
2673
|
-
defaultName: import_zod.z.string().optional(),
|
|
2674
|
-
// Default vault symbol (auto-generated if not set)
|
|
2675
|
-
defaultSymbol: import_zod.z.string().optional(),
|
|
2676
|
-
// Fee recipient for vault fees (default: agent wallet)
|
|
2677
|
-
feeRecipient: import_zod.z.string().optional(),
|
|
2678
|
-
// When vault exists, trade through vault instead of direct trading
|
|
2679
|
-
// This pools depositors' capital with the agent's trades
|
|
2680
|
-
preferVaultTrading: import_zod.z.boolean().default(true)
|
|
2681
|
-
});
|
|
2682
|
-
var WalletConfigSchema = import_zod.z.object({
|
|
2683
|
-
setup: WalletSetupSchema.default("provide")
|
|
2684
|
-
}).optional();
|
|
2685
|
-
var RelayConfigSchema = import_zod.z.object({
|
|
2686
|
-
enabled: import_zod.z.boolean().default(false),
|
|
2687
|
-
apiUrl: import_zod.z.string().url(),
|
|
2688
|
-
heartbeatIntervalMs: import_zod.z.number().min(5e3).default(3e4)
|
|
2689
|
-
}).optional();
|
|
2690
|
-
var AgentConfigSchema = import_zod.z.object({
|
|
2691
|
-
// Identity (from on-chain registration)
|
|
2692
|
-
agentId: import_zod.z.union([import_zod.z.number().positive(), import_zod.z.string()]),
|
|
2693
|
-
name: import_zod.z.string().min(3).max(32),
|
|
2694
|
-
// Network
|
|
2695
|
-
network: import_zod.z.literal("mainnet").default("mainnet"),
|
|
2696
|
-
// Wallet setup preference
|
|
2697
|
-
wallet: WalletConfigSchema,
|
|
2698
|
-
// LLM
|
|
2699
|
-
llm: LLMConfigSchema,
|
|
2700
|
-
// Trading parameters
|
|
2701
|
-
riskUniverse: RiskUniverseSchema.default("established"),
|
|
2702
|
-
trading: TradingConfigSchema.default({}),
|
|
2703
|
-
// Vault configuration (copy trading)
|
|
2704
|
-
vault: VaultConfigSchema.default({}),
|
|
2705
|
-
// Relay configuration (command center)
|
|
2706
|
-
relay: RelayConfigSchema,
|
|
2707
|
-
// Allowed tokens (addresses)
|
|
2708
|
-
allowedTokens: import_zod.z.array(import_zod.z.string()).optional()
|
|
2709
|
-
});
|
|
2710
|
-
|
|
2711
|
-
// src/config.ts
|
|
2712
|
-
function loadConfig(configPath) {
|
|
2713
|
-
(0, import_dotenv.config)();
|
|
2714
|
-
const configFile = configPath || process.env.EXAGENT_CONFIG || "agent-config.json";
|
|
2715
|
-
const fullPath = configFile.startsWith("/") ? configFile : (0, import_path2.join)(process.cwd(), configFile);
|
|
2716
|
-
if (!(0, import_fs2.existsSync)(fullPath)) {
|
|
2717
|
-
throw new Error(`Config file not found: ${fullPath}`);
|
|
2718
|
-
}
|
|
2719
|
-
const rawConfig = JSON.parse((0, import_fs2.readFileSync)(fullPath, "utf-8"));
|
|
2720
|
-
const config = AgentConfigSchema.parse(rawConfig);
|
|
2721
|
-
const privateKey = process.env.EXAGENT_PRIVATE_KEY;
|
|
2722
|
-
if (privateKey && (!privateKey.startsWith("0x") || privateKey.length !== 66)) {
|
|
2723
|
-
throw new Error("EXAGENT_PRIVATE_KEY must be a valid 32-byte hex string starting with 0x");
|
|
2724
|
-
}
|
|
2725
|
-
const llmConfig = { ...config.llm };
|
|
2726
|
-
if (process.env.OPENAI_API_KEY && config.llm.provider === "openai") {
|
|
2727
|
-
llmConfig.apiKey = process.env.OPENAI_API_KEY;
|
|
2728
|
-
}
|
|
2729
|
-
if (process.env.ANTHROPIC_API_KEY && config.llm.provider === "anthropic") {
|
|
2730
|
-
llmConfig.apiKey = process.env.ANTHROPIC_API_KEY;
|
|
2731
|
-
}
|
|
2732
|
-
if (process.env.GOOGLE_AI_API_KEY && config.llm.provider === "google") {
|
|
2733
|
-
llmConfig.apiKey = process.env.GOOGLE_AI_API_KEY;
|
|
2734
|
-
}
|
|
2735
|
-
if (process.env.DEEPSEEK_API_KEY && config.llm.provider === "deepseek") {
|
|
2736
|
-
llmConfig.apiKey = process.env.DEEPSEEK_API_KEY;
|
|
2737
|
-
}
|
|
2738
|
-
if (process.env.MISTRAL_API_KEY && config.llm.provider === "mistral") {
|
|
2739
|
-
llmConfig.apiKey = process.env.MISTRAL_API_KEY;
|
|
2740
|
-
}
|
|
2741
|
-
if (process.env.GROQ_API_KEY && config.llm.provider === "groq") {
|
|
2742
|
-
llmConfig.apiKey = process.env.GROQ_API_KEY;
|
|
2743
|
-
}
|
|
2744
|
-
if (process.env.TOGETHER_API_KEY && config.llm.provider === "together") {
|
|
2745
|
-
llmConfig.apiKey = process.env.TOGETHER_API_KEY;
|
|
2746
|
-
}
|
|
2747
|
-
if (process.env.EXAGENT_LLM_URL) {
|
|
2748
|
-
llmConfig.endpoint = process.env.EXAGENT_LLM_URL;
|
|
2749
|
-
}
|
|
2750
|
-
if (process.env.EXAGENT_LLM_MODEL) {
|
|
2751
|
-
llmConfig.model = process.env.EXAGENT_LLM_MODEL;
|
|
2752
|
-
}
|
|
2753
|
-
const network = process.env.EXAGENT_NETWORK || config.network;
|
|
2754
|
-
return {
|
|
2755
|
-
...config,
|
|
2756
|
-
llm: llmConfig,
|
|
2757
|
-
network,
|
|
2758
|
-
privateKey: privateKey || ""
|
|
2759
|
-
};
|
|
2760
|
-
}
|
|
2761
|
-
function validateConfig(config) {
|
|
2762
|
-
if (!config.privateKey) {
|
|
2763
|
-
throw new Error("Private key is required");
|
|
2764
|
-
}
|
|
2765
|
-
if (config.llm.provider !== "ollama" && !config.llm.apiKey) {
|
|
2766
|
-
throw new Error(`API key required for ${config.llm.provider} provider`);
|
|
2767
|
-
}
|
|
2768
|
-
if (config.llm.provider === "ollama" && !config.llm.endpoint) {
|
|
2769
|
-
config.llm.endpoint = "http://localhost:11434";
|
|
2770
|
-
}
|
|
2771
|
-
if (config.llm.provider === "custom" && !config.llm.endpoint) {
|
|
2772
|
-
throw new Error("Endpoint required for custom LLM provider");
|
|
2773
|
-
}
|
|
2774
|
-
if (!config.agentId || Number(config.agentId) <= 0) {
|
|
2775
|
-
throw new Error("Valid agent ID required");
|
|
2776
|
-
}
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2779
2783
|
// src/cli.ts
|
|
2780
2784
|
var import_accounts3 = require("viem/accounts");
|
|
2781
2785
|
|
package/dist/cli.mjs
CHANGED
package/dist/index.d.mts
CHANGED