@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.
- package/dist/{chunk-6TRDZ4JG.js → chunk-K4LBO234.js} +1 -1
- package/dist/chunk-QN5FG53Q.js +1223 -0
- package/dist/chunk-WMVGNUSL.js +127 -0
- package/dist/cli.js +371 -110
- package/dist/{config-CFVDT6M4.js → config-RZBPNEBZ.js} +9 -1
- package/dist/index.js +75 -26
- package/dist/{output-VT23PY74.js → output-IN47X4NU.js} +1 -1
- package/package.json +10 -6
- package/dist/chunk-AWKUQSTP.js +0 -777
- package/dist/chunk-NK52PCTE.js +0 -78
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
var PRIVATE_DIR_MODE = 448;
|
|
8
|
+
var PRIVATE_FILE_MODE = 384;
|
|
9
|
+
var DEFAULT_VISIBLE_SECRET_CHARS = 10;
|
|
10
|
+
var SENSITIVE_CONFIG_KEY_PATTERN = /(^|\.)(apiKey|orgApiKey)$/i;
|
|
11
|
+
function ensureContoDir() {
|
|
12
|
+
if (!fs.existsSync(CONTO_DIR)) {
|
|
13
|
+
fs.mkdirSync(CONTO_DIR, { recursive: true, mode: PRIVATE_DIR_MODE });
|
|
14
|
+
}
|
|
15
|
+
fs.chmodSync(CONTO_DIR, PRIVATE_DIR_MODE);
|
|
16
|
+
}
|
|
17
|
+
function writePrivateFile(filePath, content) {
|
|
18
|
+
fs.writeFileSync(filePath, content, { mode: PRIVATE_FILE_MODE });
|
|
19
|
+
fs.chmodSync(filePath, PRIVATE_FILE_MODE);
|
|
20
|
+
}
|
|
21
|
+
function loadGlobalConfig() {
|
|
22
|
+
try {
|
|
23
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
24
|
+
const raw = fs.readFileSync(CONFIG_FILE, "utf-8");
|
|
25
|
+
return JSON.parse(raw);
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
function saveGlobalConfig(config) {
|
|
32
|
+
ensureContoDir();
|
|
33
|
+
writePrivateFile(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n");
|
|
34
|
+
}
|
|
35
|
+
function loadProjectEnv(dir) {
|
|
36
|
+
const envPath = path.join(dir || process.cwd(), ".env.local");
|
|
37
|
+
if (fs.existsSync(envPath)) {
|
|
38
|
+
const content = fs.readFileSync(envPath, "utf-8");
|
|
39
|
+
const result = {};
|
|
40
|
+
for (const line of content.split("\n")) {
|
|
41
|
+
const match = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
|
|
42
|
+
if (match) result[match[1]] = match[2];
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
function loadProjectConfig(dir) {
|
|
49
|
+
const configPath = path.join(dir || process.cwd(), "conto.config.json");
|
|
50
|
+
try {
|
|
51
|
+
if (fs.existsSync(configPath)) {
|
|
52
|
+
const raw = fs.readFileSync(configPath, "utf-8");
|
|
53
|
+
return JSON.parse(raw);
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
function loadConfig() {
|
|
60
|
+
const global = loadGlobalConfig();
|
|
61
|
+
const project = loadProjectConfig();
|
|
62
|
+
const env = loadProjectEnv();
|
|
63
|
+
return {
|
|
64
|
+
apiKey: env.CONTO_API_KEY || global.server?.apiKey,
|
|
65
|
+
baseUrl: env.CONTO_BASE_URL || global.server?.baseUrl || "https://conto.finance",
|
|
66
|
+
agentId: env.CONTO_AGENT_ID || global.agent?.id,
|
|
67
|
+
chainId: env.CONTO_CHAIN_ID || global.network?.chainId,
|
|
68
|
+
chainName: env.CONTO_CHAIN_NAME || global.network?.chain,
|
|
69
|
+
currency: env.CONTO_CURRENCY || global.network?.currency,
|
|
70
|
+
explorerUrl: env.CONTO_EXPLORER_URL || global.network?.explorerUrl,
|
|
71
|
+
walletId: env.CONTO_WALLET_ID || global.wallet?.id,
|
|
72
|
+
walletAddress: env.CONTO_WALLET_ADDRESS || global.wallet?.address,
|
|
73
|
+
orgApiKey: global.server?.orgApiKey,
|
|
74
|
+
// Sandbox metadata is project-scoped and ephemeral. Do not let a prior
|
|
75
|
+
// sandbox stored in ~/.conto/config.json bleed into unrelated agents.
|
|
76
|
+
sandboxExecution: env.CONTO_SANDBOX_EXECUTION || project.sandbox?.execution,
|
|
77
|
+
sandboxExpiresAt: env.CONTO_SANDBOX_EXPIRES_AT || project.sandbox?.expiresAt,
|
|
78
|
+
testnet: global.network?.testnet || project.network?.testnet || env.CONTO_CHAIN_ID === "42431"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function writeEnvLocal(dir, entries) {
|
|
82
|
+
const lines = entries.map(
|
|
83
|
+
(entry) => typeof entry === "string" ? entry : `${entry[0]}=${entry[1]}`
|
|
84
|
+
);
|
|
85
|
+
const content = lines.join("\n") + "\n";
|
|
86
|
+
writePrivateFile(path.join(dir, ".env.local"), content);
|
|
87
|
+
}
|
|
88
|
+
function writeContoConfig(dir, config) {
|
|
89
|
+
fs.writeFileSync(path.join(dir, "conto.config.json"), JSON.stringify(config, null, 2) + "\n");
|
|
90
|
+
}
|
|
91
|
+
function clearGlobalConfig() {
|
|
92
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
93
|
+
fs.unlinkSync(CONFIG_FILE);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function isSensitiveConfigKey(key) {
|
|
97
|
+
return SENSITIVE_CONFIG_KEY_PATTERN.test(key);
|
|
98
|
+
}
|
|
99
|
+
function maskSecret(value, visibleChars = DEFAULT_VISIBLE_SECRET_CHARS) {
|
|
100
|
+
if (!value) return "";
|
|
101
|
+
const prefixLength = Math.max(1, Math.min(visibleChars, value.length));
|
|
102
|
+
return `${value.slice(0, prefixLength)}...`;
|
|
103
|
+
}
|
|
104
|
+
function missingSdkKeyMessage(config) {
|
|
105
|
+
if (config.orgApiKey) {
|
|
106
|
+
return [
|
|
107
|
+
"Logged in with an organization key, but no agent SDK key is configured.",
|
|
108
|
+
'Run "npx create-conto-agent --api-key <org-api-key>" to create an agent,',
|
|
109
|
+
"or set CONTO_API_KEY to an existing conto_agent_ key."
|
|
110
|
+
].join(" ");
|
|
111
|
+
}
|
|
112
|
+
return 'Not configured. Run "npx create-conto-agent" first, or set CONTO_API_KEY.';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
loadGlobalConfig,
|
|
117
|
+
saveGlobalConfig,
|
|
118
|
+
loadProjectEnv,
|
|
119
|
+
loadProjectConfig,
|
|
120
|
+
loadConfig,
|
|
121
|
+
writeEnvLocal,
|
|
122
|
+
writeContoConfig,
|
|
123
|
+
clearGlobalConfig,
|
|
124
|
+
isSensitiveConfigKey,
|
|
125
|
+
maskSecret,
|
|
126
|
+
missingSdkKeyMessage
|
|
127
|
+
};
|