@conto_finance/create-conto-agent 0.1.2 → 0.3.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.
@@ -1,78 +0,0 @@
1
- // src/lib/config.ts
2
- import fs from "fs";
3
- import path from "path";
4
- import os from "os";
5
- var CONTO_DIR = path.join(os.homedir(), ".conto");
6
- var CONFIG_FILE = path.join(CONTO_DIR, "config.json");
7
- function ensureContoDir() {
8
- if (!fs.existsSync(CONTO_DIR)) {
9
- fs.mkdirSync(CONTO_DIR, { recursive: true });
10
- }
11
- }
12
- function loadGlobalConfig() {
13
- try {
14
- if (fs.existsSync(CONFIG_FILE)) {
15
- const raw = fs.readFileSync(CONFIG_FILE, "utf-8");
16
- return JSON.parse(raw);
17
- }
18
- } catch {
19
- }
20
- return {};
21
- }
22
- function saveGlobalConfig(config) {
23
- ensureContoDir();
24
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n");
25
- }
26
- function loadProjectEnv(dir) {
27
- const envPath = path.join(dir || process.cwd(), ".env.local");
28
- if (fs.existsSync(envPath)) {
29
- const content = fs.readFileSync(envPath, "utf-8");
30
- const result = {};
31
- for (const line of content.split("\n")) {
32
- const match = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
33
- if (match) result[match[1]] = match[2];
34
- }
35
- return result;
36
- }
37
- return {};
38
- }
39
- function loadConfig() {
40
- const global = loadGlobalConfig();
41
- const env = loadProjectEnv();
42
- return {
43
- apiKey: env.CONTO_API_KEY || global.server?.apiKey,
44
- baseUrl: env.CONTO_BASE_URL || global.server?.baseUrl || "https://conto.finance",
45
- agentId: env.CONTO_AGENT_ID || global.agent?.id,
46
- chainId: env.CONTO_CHAIN_ID || global.network?.chainId,
47
- chainName: env.CONTO_CHAIN_NAME || global.network?.chain,
48
- currency: env.CONTO_CURRENCY || global.network?.currency,
49
- explorerUrl: env.CONTO_EXPLORER_URL || global.network?.explorerUrl,
50
- walletId: env.CONTO_WALLET_ID || global.wallet?.id,
51
- walletAddress: env.CONTO_WALLET_ADDRESS || global.wallet?.address,
52
- orgApiKey: global.server?.orgApiKey,
53
- testnet: global.network?.testnet || env.CONTO_CHAIN_ID === "42431"
54
- };
55
- }
56
- function writeEnvLocal(dir, vars) {
57
- const lines = Object.entries(vars).map(([key, value]) => `${key}=${value}`);
58
- const content = lines.join("\n") + "\n";
59
- fs.writeFileSync(path.join(dir, ".env.local"), content);
60
- }
61
- function writeContoConfig(dir, config) {
62
- fs.writeFileSync(path.join(dir, "conto.config.json"), JSON.stringify(config, null, 2) + "\n");
63
- }
64
- function clearGlobalConfig() {
65
- if (fs.existsSync(CONFIG_FILE)) {
66
- fs.unlinkSync(CONFIG_FILE);
67
- }
68
- }
69
-
70
- export {
71
- loadGlobalConfig,
72
- saveGlobalConfig,
73
- loadProjectEnv,
74
- loadConfig,
75
- writeEnvLocal,
76
- writeContoConfig,
77
- clearGlobalConfig
78
- };