@0gfoundation/0g-agentdna 0.0.0-stage → 0.2.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/GUIDE.md +975 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +84 -0
- package/MIGRATION.zh.md +70 -0
- package/PROVIDERS.md +273 -0
- package/PROVIDERS.zh.md +234 -0
- package/README.md +334 -2
- package/dist/AgentClient.d.ts +312 -0
- package/dist/AgentClient.d.ts.map +1 -0
- package/dist/AgentClient.js +715 -0
- package/dist/AgentClient.js.map +1 -0
- package/dist/AgenticID.d.ts +823 -0
- package/dist/AgenticID.d.ts.map +1 -0
- package/dist/AgenticID.js +1188 -0
- package/dist/AgenticID.js.map +1 -0
- package/dist/AgenticIDClient.d.ts +68 -0
- package/dist/AgenticIDClient.d.ts.map +1 -0
- package/dist/AgenticIDClient.js +198 -0
- package/dist/AgenticIDClient.js.map +1 -0
- package/dist/AttestorClient.d.ts +465 -0
- package/dist/AttestorClient.d.ts.map +1 -0
- package/dist/AttestorClient.js +1030 -0
- package/dist/AttestorClient.js.map +1 -0
- package/dist/Providers.d.ts +72 -0
- package/dist/Providers.d.ts.map +1 -0
- package/dist/Providers.js +182 -0
- package/dist/Providers.js.map +1 -0
- package/dist/ReputationClient.d.ts +213 -0
- package/dist/ReputationClient.d.ts.map +1 -0
- package/dist/ReputationClient.js +708 -0
- package/dist/ReputationClient.js.map +1 -0
- package/dist/SandboxClient.d.ts +107 -0
- package/dist/SandboxClient.d.ts.map +1 -0
- package/dist/SandboxClient.js +200 -0
- package/dist/SandboxClient.js.map +1 -0
- package/dist/ServeProof.d.ts +161 -0
- package/dist/ServeProof.d.ts.map +1 -0
- package/dist/ServeProof.js +230 -0
- package/dist/ServeProof.js.map +1 -0
- package/dist/ServeSession.d.ts +180 -0
- package/dist/ServeSession.d.ts.map +1 -0
- package/dist/ServeSession.js +336 -0
- package/dist/ServeSession.js.map +1 -0
- package/dist/Settings.d.ts +179 -0
- package/dist/Settings.d.ts.map +1 -0
- package/dist/Settings.js +247 -0
- package/dist/Settings.js.map +1 -0
- package/dist/abi.d.ts +2216 -0
- package/dist/abi.d.ts.map +1 -0
- package/dist/abi.js +1248 -0
- package/dist/abi.js.map +1 -0
- package/dist/cli/commands/cells.d.ts +62 -0
- package/dist/cli/commands/cells.d.ts.map +1 -0
- package/dist/cli/commands/cells.js +113 -0
- package/dist/cli/commands/cells.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +15 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +236 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/interactive.d.ts +115 -0
- package/dist/cli/commands/interactive.d.ts.map +1 -0
- package/dist/cli/commands/interactive.js +3052 -0
- package/dist/cli/commands/interactive.js.map +1 -0
- package/dist/cli/commands/list.d.ts +31 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +91 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/providers.d.ts +3 -0
- package/dist/cli/commands/providers.d.ts.map +1 -0
- package/dist/cli/commands/providers.js +21 -0
- package/dist/cli/commands/providers.js.map +1 -0
- package/dist/cli/commands/settings.d.ts +22 -0
- package/dist/cli/commands/settings.d.ts.map +1 -0
- package/dist/cli/commands/settings.js +188 -0
- package/dist/cli/commands/settings.js.map +1 -0
- package/dist/cli/commands/status.d.ts +16 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +148 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/update.d.ts +21 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +95 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/config.d.ts +73 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +239 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/env.d.ts +36 -0
- package/dist/cli/env.d.ts.map +1 -0
- package/dist/cli/env.js +74 -0
- package/dist/cli/env.js.map +1 -0
- package/dist/cli/envelope.d.ts +33 -0
- package/dist/cli/envelope.d.ts.map +1 -0
- package/dist/cli/envelope.js +62 -0
- package/dist/cli/envelope.js.map +1 -0
- package/dist/cli/errors.d.ts +48 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/errors.js +81 -0
- package/dist/cli/errors.js.map +1 -0
- package/dist/cli/inference.d.ts +21 -0
- package/dist/cli/inference.d.ts.map +1 -0
- package/dist/cli/inference.js +60 -0
- package/dist/cli/inference.js.map +1 -0
- package/dist/cli/logo.d.ts +21 -0
- package/dist/cli/logo.d.ts.map +1 -0
- package/dist/cli/logo.js +131 -0
- package/dist/cli/logo.js.map +1 -0
- package/dist/cli/main.d.ts +14 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +223 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/proofs.d.ts +67 -0
- package/dist/cli/proofs.d.ts.map +1 -0
- package/dist/cli/proofs.js +133 -0
- package/dist/cli/proofs.js.map +1 -0
- package/dist/cli/ref.d.ts +39 -0
- package/dist/cli/ref.d.ts.map +1 -0
- package/dist/cli/ref.js +48 -0
- package/dist/cli/ref.js.map +1 -0
- package/dist/cli/sdk.d.ts +24 -0
- package/dist/cli/sdk.d.ts.map +1 -0
- package/dist/cli/sdk.js +65 -0
- package/dist/cli/sdk.js.map +1 -0
- package/dist/cli/settings.d.ts +66 -0
- package/dist/cli/settings.d.ts.map +1 -0
- package/dist/cli/settings.js +137 -0
- package/dist/cli/settings.js.map +1 -0
- package/dist/cli/tokenize.d.ts +61 -0
- package/dist/cli/tokenize.d.ts.map +1 -0
- package/dist/cli/tokenize.js +157 -0
- package/dist/cli/tokenize.js.map +1 -0
- package/dist/cli/types.d.ts +25 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +8 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/constants.d.ts +107 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +74 -0
- package/dist/constants.js.map +1 -0
- package/dist/context.d.ts +108 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +64 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-catalog.json +23 -0
- package/dist/seal.d.ts +47 -0
- package/dist/seal.d.ts.map +1 -0
- package/dist/seal.js +145 -0
- package/dist/seal.js.map +1 -0
- package/dist/secretEnv.d.ts +119 -0
- package/dist/secretEnv.d.ts.map +1 -0
- package/dist/secretEnv.js +199 -0
- package/dist/secretEnv.js.map +1 -0
- package/dist/taskHash.d.ts +39 -0
- package/dist/taskHash.d.ts.map +1 -0
- package/dist/taskHash.js +119 -0
- package/dist/taskHash.js.map +1 -0
- package/dist/types.d.ts +336 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -4
- package/scripts/sync-providers.cjs +8 -0
- package/src/AgentClient.ts +897 -0
- package/src/AgenticID.ts +1382 -0
- package/src/AgenticIDClient.ts +238 -0
- package/src/AttestorClient.ts +1306 -0
- package/src/Providers.ts +176 -0
- package/src/ReputationClient.ts +821 -0
- package/src/SandboxClient.ts +227 -0
- package/src/ServeProof.ts +290 -0
- package/src/ServeSession.ts +421 -0
- package/src/Settings.ts +296 -0
- package/src/abi.ts +1282 -0
- package/src/cli/commands/cells.ts +107 -0
- package/src/cli/commands/doctor.ts +235 -0
- package/src/cli/commands/interactive.ts +2738 -0
- package/src/cli/commands/list.ts +95 -0
- package/src/cli/commands/providers.ts +16 -0
- package/src/cli/commands/settings.ts +197 -0
- package/src/cli/commands/status.ts +170 -0
- package/src/cli/commands/update.ts +86 -0
- package/src/cli/config.ts +225 -0
- package/src/cli/env.ts +90 -0
- package/src/cli/envelope.ts +57 -0
- package/src/cli/errors.ts +114 -0
- package/src/cli/inference.ts +57 -0
- package/src/cli/logo.ts +125 -0
- package/src/cli/main.ts +235 -0
- package/src/cli/proofs.ts +160 -0
- package/src/cli/ref.ts +58 -0
- package/src/cli/sdk.ts +65 -0
- package/src/cli/settings.ts +153 -0
- package/src/cli/tokenize.ts +131 -0
- package/src/cli/types.ts +27 -0
- package/src/constants.ts +106 -0
- package/src/context.ts +161 -0
- package/src/index.ts +129 -0
- package/src/provider-catalog.json +23 -0
- package/src/seal.ts +163 -0
- package/src/secretEnv.ts +250 -0
- package/src/taskHash.ts +100 -0
- package/src/types.ts +357 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file config.ts
|
|
4
|
+
* @description Persisted CLI config so you don't re-export env vars every
|
|
5
|
+
* session. Two files under the XDG config dir
|
|
6
|
+
* (`$XDG_CONFIG_HOME/0g-agentdna`, default `~/.config/0g-agentdna`):
|
|
7
|
+
*
|
|
8
|
+
* config.json { attestorUrl, rpcUrl? } — non-secret, selects the env
|
|
9
|
+
* credentials { privateKey?, inferenceKeys? } — provider keys, chmod 0600
|
|
10
|
+
*
|
|
11
|
+
* The owner key is kept in its OWN file at 0600, not in config.json — the
|
|
12
|
+
* standard split (gh / aws / docker do the same) so a shared or
|
|
13
|
+
* world-readable config never carries the key.
|
|
14
|
+
*
|
|
15
|
+
* Environment variables always WIN over the files (AGENTIC_ATTESTOR_URL /
|
|
16
|
+
* AGENTIC_PRIVATE_KEY / AGENTIC_RPC_URL) so CI and one-off overrides work
|
|
17
|
+
* without touching disk. `readEnv` (env.ts) folds these files in as the
|
|
18
|
+
* fallback layer.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.configPaths = configPaths;
|
|
22
|
+
exports.loadConfig = loadConfig;
|
|
23
|
+
exports.loadSecretEnvPins = loadSecretEnvPins;
|
|
24
|
+
exports.recordSecretEnvPin = recordSecretEnvPin;
|
|
25
|
+
exports.saveConfig = saveConfig;
|
|
26
|
+
exports.loadCredentials = loadCredentials;
|
|
27
|
+
exports.saveCredentials = saveCredentials;
|
|
28
|
+
exports.loadKey = loadKey;
|
|
29
|
+
exports.normalizeKey = normalizeKey;
|
|
30
|
+
exports.saveKey = saveKey;
|
|
31
|
+
exports.loadApiKey = loadApiKey;
|
|
32
|
+
exports.saveApiKey = saveApiKey;
|
|
33
|
+
exports.inferenceKeyFromEnv = inferenceKeyFromEnv;
|
|
34
|
+
const node_fs_1 = require("node:fs");
|
|
35
|
+
const node_crypto_1 = require("node:crypto");
|
|
36
|
+
const node_os_1 = require("node:os");
|
|
37
|
+
const node_path_1 = require("node:path");
|
|
38
|
+
/** Resolve on-disk locations and move an existing legacy directory once.
|
|
39
|
+
* Renaming preserves credentials, proof tickets, downgrade pins, and modes.
|
|
40
|
+
* An existing AgentDNA directory always wins; the two stores are never merged. */
|
|
41
|
+
function configPaths(env = process.env) {
|
|
42
|
+
const base = env.XDG_CONFIG_HOME?.trim() || (0, node_path_1.join)((0, node_os_1.homedir)(), '.config');
|
|
43
|
+
const dir = (0, node_path_1.join)(base, '0g-agentdna');
|
|
44
|
+
const legacy = (0, node_path_1.join)(base, '0g-agenticid');
|
|
45
|
+
if (!(0, node_fs_1.existsSync)(dir) && (0, node_fs_1.existsSync)(legacy)) {
|
|
46
|
+
try {
|
|
47
|
+
(0, node_fs_1.renameSync)(legacy, dir);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
// Another CLI process may have completed the same migration first.
|
|
51
|
+
if (!(0, node_fs_1.existsSync)(dir)) {
|
|
52
|
+
const code = error.code ?? 'unknown';
|
|
53
|
+
throw new Error(`cannot migrate CLI config from ${legacy} to ${dir} (${code}); move the directory manually and retry`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { dir, config: (0, node_path_1.join)(dir, 'config.json'), credentials: (0, node_path_1.join)(dir, 'credentials') };
|
|
58
|
+
}
|
|
59
|
+
/** Read config.json; missing/corrupt file → empty config (never throws). */
|
|
60
|
+
function loadConfig(env = process.env) {
|
|
61
|
+
const { config } = configPaths(env);
|
|
62
|
+
if (!(0, node_fs_1.existsSync)(config))
|
|
63
|
+
return {};
|
|
64
|
+
try {
|
|
65
|
+
const c = JSON.parse((0, node_fs_1.readFileSync)(config, 'utf8'));
|
|
66
|
+
return {
|
|
67
|
+
attestorUrl: c.attestorUrl?.replace(/\/$/, ''),
|
|
68
|
+
rpcUrl: c.rpcUrl,
|
|
69
|
+
inferenceProvider: c.inferenceProvider,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Secret-env sticky pins (issue #166): attestor URLs that have advertised
|
|
78
|
+
* `secret_env_scheme` at least once, so a later absence is refused as
|
|
79
|
+
* tampering instead of silently downgrading to a clear-text key — across
|
|
80
|
+
* CLI invocations, not just within one process. One small file so the
|
|
81
|
+
* existing config.json load/save semantics stay untouched.
|
|
82
|
+
*/
|
|
83
|
+
function loadSecretEnvPins(env = process.env) {
|
|
84
|
+
const file = (0, node_path_1.join)(configPaths(env).dir, 'secret-env-pins.json');
|
|
85
|
+
if (!(0, node_fs_1.existsSync)(file))
|
|
86
|
+
return {};
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Record that `attestorUrl` advertises the scheme. Best-effort: a failed
|
|
95
|
+
* write only costs persistence, never the call. */
|
|
96
|
+
function recordSecretEnvPin(attestorUrl, env = process.env) {
|
|
97
|
+
try {
|
|
98
|
+
const { dir } = configPaths(env);
|
|
99
|
+
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
100
|
+
const pins = { ...loadSecretEnvPins(env), [attestorUrl]: true };
|
|
101
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'secret-env-pins.json'), `${JSON.stringify(pins, null, 2)}
|
|
102
|
+
`, { mode: 0o644 });
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
/* best-effort */
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Merge a patch into config.json (creating the dir), 0644. */
|
|
109
|
+
function saveConfig(patch, env = process.env) {
|
|
110
|
+
const { dir, config } = configPaths(env);
|
|
111
|
+
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
112
|
+
const next = { ...loadConfig(env), ...patch };
|
|
113
|
+
// drop empties so the file stays clean
|
|
114
|
+
for (const k of Object.keys(next))
|
|
115
|
+
if (!next[k])
|
|
116
|
+
delete next[k];
|
|
117
|
+
(0, node_fs_1.writeFileSync)(config, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o644 });
|
|
118
|
+
}
|
|
119
|
+
function writeCredentials(next, env) {
|
|
120
|
+
const { dir, credentials } = configPaths(env);
|
|
121
|
+
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
122
|
+
const temporary = `${credentials}.${process.pid}.${(0, node_crypto_1.randomUUID)()}.tmp`;
|
|
123
|
+
try {
|
|
124
|
+
(0, node_fs_1.writeFileSync)(temporary, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
125
|
+
(0, node_fs_1.renameSync)(temporary, credentials);
|
|
126
|
+
(0, node_fs_1.chmodSync)(credentials, 0o600);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
try {
|
|
130
|
+
(0, node_fs_1.unlinkSync)(temporary);
|
|
131
|
+
}
|
|
132
|
+
catch { /* nothing was written */ }
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** Old single API keys are compute keys. Migrate on first read, atomically. */
|
|
137
|
+
function loadCredentials(env = process.env) {
|
|
138
|
+
const { credentials } = configPaths(env);
|
|
139
|
+
if (!(0, node_fs_1.existsSync)(credentials))
|
|
140
|
+
return {};
|
|
141
|
+
let parsed;
|
|
142
|
+
try {
|
|
143
|
+
const text = (0, node_fs_1.readFileSync)(credentials, 'utf8').trim();
|
|
144
|
+
if (!text)
|
|
145
|
+
return {};
|
|
146
|
+
parsed = text.startsWith('{') ? JSON.parse(text) : { privateKey: text };
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return {};
|
|
150
|
+
}
|
|
151
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
152
|
+
return {};
|
|
153
|
+
const privateKey = typeof parsed.privateKey === 'string' ? normalizeKey(parsed.privateKey) : null;
|
|
154
|
+
const inferenceKeys = {};
|
|
155
|
+
if (parsed.inferenceKeys && typeof parsed.inferenceKeys === 'object' && !Array.isArray(parsed.inferenceKeys)) {
|
|
156
|
+
for (const [provider, value] of Object.entries(parsed.inferenceKeys)) {
|
|
157
|
+
if (/^[a-z0-9][a-z0-9-]*$/.test(provider) && typeof value === 'string' && value.trim()) {
|
|
158
|
+
inferenceKeys[provider] = value.trim();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (typeof parsed.apiKey === 'string' && parsed.apiKey.trim() && !inferenceKeys['0g-compute']) {
|
|
163
|
+
inferenceKeys['0g-compute'] = parsed.apiKey.trim();
|
|
164
|
+
}
|
|
165
|
+
const result = {
|
|
166
|
+
...(privateKey ? { privateKey } : {}),
|
|
167
|
+
...(Object.keys(inferenceKeys).length ? { inferenceKeys } : {}),
|
|
168
|
+
};
|
|
169
|
+
// Keep corrupt/empty documents untouched. A legacy key is removed only after
|
|
170
|
+
// the complete normalized replacement has been written successfully.
|
|
171
|
+
if (typeof parsed.apiKey === 'string' && parsed.apiKey.trim())
|
|
172
|
+
writeCredentials(result, env);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
function saveCredentials(patch, env = process.env) {
|
|
176
|
+
const previous = loadCredentials(env);
|
|
177
|
+
const inferenceKeys = { ...previous.inferenceKeys, ...patch.inferenceKeys };
|
|
178
|
+
if (patch.apiKey)
|
|
179
|
+
inferenceKeys['0g-compute'] = patch.apiKey;
|
|
180
|
+
const next = { ...previous, ...patch, ...(Object.keys(inferenceKeys).length ? { inferenceKeys } : {}) };
|
|
181
|
+
delete next.apiKey;
|
|
182
|
+
writeCredentials(next, env);
|
|
183
|
+
}
|
|
184
|
+
/** The owner key, or null. Normalizes on read (old CLI builds saved login
|
|
185
|
+
* input verbatim, so a pre-normalization file may hold a 0x-less key);
|
|
186
|
+
* an un-normalizable value passes through raw so the caller can name it. */
|
|
187
|
+
function loadKey(env = process.env) {
|
|
188
|
+
const raw = loadCredentials(env).privateKey ?? null;
|
|
189
|
+
if (!raw)
|
|
190
|
+
return null;
|
|
191
|
+
return normalizeKey(raw) ?? raw;
|
|
192
|
+
}
|
|
193
|
+
/** Normalize a pasted private key: trims, and prepends the 0x that wallet
|
|
194
|
+
* exports (MetaMask among them) commonly omit. Returns null if it isn't a
|
|
195
|
+
* 64-hex key either way. */
|
|
196
|
+
function normalizeKey(key) {
|
|
197
|
+
const k = key.trim();
|
|
198
|
+
if (/^0x[0-9a-fA-F]{64}$/.test(k))
|
|
199
|
+
return k;
|
|
200
|
+
if (/^[0-9a-fA-F]{64}$/.test(k))
|
|
201
|
+
return `0x${k}`;
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
/** Persist the owner key (accepts 64 hex with or without the 0x prefix). */
|
|
205
|
+
function saveKey(key, env = process.env) {
|
|
206
|
+
const k = normalizeKey(key);
|
|
207
|
+
if (!k)
|
|
208
|
+
throw new Error('private key must be 64 hex chars (0x prefix optional)');
|
|
209
|
+
saveCredentials({ privateKey: k }, env);
|
|
210
|
+
}
|
|
211
|
+
/** No provider argument retains the old compute-only helper signature. */
|
|
212
|
+
function loadApiKey(providerOrEnv = '0g-compute', env = process.env) {
|
|
213
|
+
const provider = typeof providerOrEnv === 'string' ? providerOrEnv : '0g-compute';
|
|
214
|
+
const source = typeof providerOrEnv === 'string' ? env : providerOrEnv;
|
|
215
|
+
return loadCredentials(source).inferenceKeys?.[provider] ?? null;
|
|
216
|
+
}
|
|
217
|
+
function saveApiKey(providerOrKey, keyOrEnv, env = process.env) {
|
|
218
|
+
const provider = typeof keyOrEnv === 'string' ? providerOrKey : '0g-compute';
|
|
219
|
+
const key = (typeof keyOrEnv === 'string' ? keyOrEnv : providerOrKey).trim();
|
|
220
|
+
const source = typeof keyOrEnv === 'string' ? env : keyOrEnv ?? env;
|
|
221
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(provider))
|
|
222
|
+
throw new Error('invalid inference provider');
|
|
223
|
+
if (!key)
|
|
224
|
+
throw new Error('api key is empty');
|
|
225
|
+
saveCredentials({ inferenceKeys: { [provider]: key } }, source);
|
|
226
|
+
}
|
|
227
|
+
/** Global legacy variables only belong to compute; new overrides are bound. */
|
|
228
|
+
function inferenceKeyFromEnv(provider, env = process.env) {
|
|
229
|
+
const key = env.AGENTDNA_API_KEY?.trim();
|
|
230
|
+
const binding = env.AGENTDNA_API_KEY_PROVIDER?.trim();
|
|
231
|
+
if (key && !binding)
|
|
232
|
+
throw new Error('AGENTDNA_API_KEY requires AGENTDNA_API_KEY_PROVIDER');
|
|
233
|
+
if (key && binding === provider)
|
|
234
|
+
return key;
|
|
235
|
+
if (provider === '0g-compute')
|
|
236
|
+
return env.AGENTIC_API_KEY?.trim() || env.API_KEY?.trim() || null;
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAgBH,kCAgBC;AAGD,gCAaC;AASD,8CAQC;AAID,gDAUC;AAGD,gCAOC;AAyBD,0CA8BC;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G,CAAC,CAAC,CAAC,QAAQ,IAAI,GAAG,CAAC;IACpE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC1F,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC9C,eAAe,CAAC,EAAE,aAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,+EAA+E;AAC/E,SAAgB,mBAAmB,CAAC,QAAgB,EAAE,MAAyB,OAAO,CAAC,GAAG;IACxF,MAAM,GAAG,GAAG,GAAG,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,GAAG,CAAC,yBAAyB,EAAE,IAAI,EAAE,CAAC;IACtD,IAAI,GAAG,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAC5F,IAAI,GAAG,IAAI,OAAO,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IAC5C,IAAI,QAAQ,KAAK,YAAY;QAAE,OAAO,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC;IACjG,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file env.ts
|
|
3
|
+
* @description Environment-variable resolution — the ONLY config channel in
|
|
4
|
+
* stage 0 (spec v0.03 §2.1). No config file; and deliberately no
|
|
5
|
+
* `--private-key`-style flag, ever: argv is public (shell history, `ps`,
|
|
6
|
+
* CI logs), env is not.
|
|
7
|
+
*/
|
|
8
|
+
/** Resolved CLI environment. All values come from `process.env`. */
|
|
9
|
+
export interface CliEnv {
|
|
10
|
+
/** `AGENTIC_ATTESTOR_URL` — one URL selects the whole environment
|
|
11
|
+
* (contracts, chain RPC, appIds via the attestor's GET /config). */
|
|
12
|
+
attestorUrl?: string;
|
|
13
|
+
/** `AGENTIC_PRIVATE_KEY` — optional owner key. Enables `--mine`,
|
|
14
|
+
* owner-tier failure reasons, and doctor's owner checks. */
|
|
15
|
+
privateKey?: `0x${string}`;
|
|
16
|
+
/** Where `privateKey` came from — a malformed-key error must name the
|
|
17
|
+
* right place to fix (unset env vs re-run login). */
|
|
18
|
+
privateKeySource?: 'env' | 'file';
|
|
19
|
+
/** `AGENTIC_RPC_URL` — optional RPC override (explicit-wins over the
|
|
20
|
+
* attestor /config's advertised RPC). */
|
|
21
|
+
rpcUrl?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the CLI environment. Environment variables WIN; the persisted
|
|
25
|
+
* config files (config.ts) are the fallback layer, so `0g-agentdna` works
|
|
26
|
+
* across sessions without re-exporting, while a one-off `AGENTIC_*=… ` or CI
|
|
27
|
+
* still overrides without touching disk.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readEnv(env?: NodeJS.ProcessEnv): CliEnv;
|
|
30
|
+
/** Attestor URL or a remediable failure (exit 3) naming the exact fix. */
|
|
31
|
+
export declare function requireAttestorUrl(env: CliEnv): string;
|
|
32
|
+
/** Private key or a remediable failure (exit 3) — for owner-only surfaces.
|
|
33
|
+
* Validates the format here so a malformed key fails with a clear exit-3
|
|
34
|
+
* remedy instead of a deep viem stack trace later. */
|
|
35
|
+
export declare function requirePrivateKey(env: CliEnv): `0x${string}`;
|
|
36
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/cli/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,oEAAoE;AACpE,MAAM,WAAW,MAAM;IACrB;yEACqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;iEAC6D;IAC7D,UAAU,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B;0DACsD;IACtD,gBAAgB,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAClC;8CAC0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAmBpE;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED;;uDAEuD;AACvD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAsB5D"}
|
package/dist/cli/env.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file env.ts
|
|
4
|
+
* @description Environment-variable resolution — the ONLY config channel in
|
|
5
|
+
* stage 0 (spec v0.03 §2.1). No config file; and deliberately no
|
|
6
|
+
* `--private-key`-style flag, ever: argv is public (shell history, `ps`,
|
|
7
|
+
* CI logs), env is not.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.readEnv = readEnv;
|
|
11
|
+
exports.requireAttestorUrl = requireAttestorUrl;
|
|
12
|
+
exports.requirePrivateKey = requirePrivateKey;
|
|
13
|
+
const errors_1 = require("./errors");
|
|
14
|
+
const config_1 = require("./config");
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the CLI environment. Environment variables WIN; the persisted
|
|
17
|
+
* config files (config.ts) are the fallback layer, so `0g-agentdna` works
|
|
18
|
+
* across sessions without re-exporting, while a one-off `AGENTIC_*=… ` or CI
|
|
19
|
+
* still overrides without touching disk.
|
|
20
|
+
*/
|
|
21
|
+
function readEnv(env = process.env) {
|
|
22
|
+
const pick = (name) => {
|
|
23
|
+
const v = env[name]?.trim();
|
|
24
|
+
return v ? v : undefined;
|
|
25
|
+
};
|
|
26
|
+
const file = (0, config_1.loadConfig)(env);
|
|
27
|
+
const fileKey = (0, config_1.loadKey)(env);
|
|
28
|
+
return {
|
|
29
|
+
attestorUrl: (pick('AGENTIC_ATTESTOR_URL') ?? file.attestorUrl)?.replace(/\/$/, ''),
|
|
30
|
+
// env keys are normalized like login input (0x prefix optional); a
|
|
31
|
+
// malformed value passes through so requirePrivateKey can name the problem.
|
|
32
|
+
...(() => {
|
|
33
|
+
const raw = pick('AGENTIC_PRIVATE_KEY');
|
|
34
|
+
if (raw)
|
|
35
|
+
return { privateKey: (0, config_1.normalizeKey)(raw) ?? raw, privateKeySource: 'env' };
|
|
36
|
+
if (fileKey)
|
|
37
|
+
return { privateKey: fileKey, privateKeySource: 'file' };
|
|
38
|
+
return {};
|
|
39
|
+
})(),
|
|
40
|
+
rpcUrl: pick('AGENTIC_RPC_URL') ?? file.rpcUrl,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Attestor URL or a remediable failure (exit 3) naming the exact fix. */
|
|
44
|
+
function requireAttestorUrl(env) {
|
|
45
|
+
if (!env.attestorUrl) {
|
|
46
|
+
throw new errors_1.CliError('MISSING_ATTESTOR_URL', 'AGENTIC_ATTESTOR_URL is not set — the CLI cannot reach an environment without it', {
|
|
47
|
+
remedy: 'export AGENTIC_ATTESTOR_URL=https://agenticid.0g.ai # or your own attestor',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return env.attestorUrl;
|
|
51
|
+
}
|
|
52
|
+
/** Private key or a remediable failure (exit 3) — for owner-only surfaces.
|
|
53
|
+
* Validates the format here so a malformed key fails with a clear exit-3
|
|
54
|
+
* remedy instead of a deep viem stack trace later. */
|
|
55
|
+
function requirePrivateKey(env) {
|
|
56
|
+
if (!env.privateKey) {
|
|
57
|
+
throw new errors_1.CliError('WALLET_REQUIRED', 'this operation needs the owner wallet, and AGENTIC_PRIVATE_KEY is not set', {
|
|
58
|
+
remedy: 'export AGENTIC_PRIVATE_KEY=0x… # env only — there is no flag for this, by design',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(env.privateKey)) {
|
|
62
|
+
// Name the actual source — blaming the env var when the bad value sits in
|
|
63
|
+
// the credentials file sends the user to `unset` something that isn't set.
|
|
64
|
+
throw new errors_1.CliError('WALLET_REQUIRED', env.privateKeySource === 'file'
|
|
65
|
+
? 'the saved owner key (login credentials file) is malformed (expected 64 hex chars, 0x prefix optional)'
|
|
66
|
+
: 'AGENTIC_PRIVATE_KEY is set but malformed (expected 64 hex chars, 0x prefix optional)', {
|
|
67
|
+
remedy: env.privateKeySource === 'file'
|
|
68
|
+
? 'run `login` and re-enter the key'
|
|
69
|
+
: 'export AGENTIC_PRIVATE_KEY=0x<64 hex chars> # or unset it to use the login-saved key',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return env.privateKey;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/cli/env.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AA2BH,0BAmBC;AAGD,gDAOC;AAKD,8CAsBC;AAjFD,qCAAoC;AACpC,qCAA6D;AAkB7D;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC1D,MAAM,IAAI,GAAG,CAAC,IAAY,EAAsB,EAAE;QAChD,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;QAC5B,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3B,CAAC,CAAC;IACF,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,OAAO,GAAG,IAAA,gBAAO,EAAC,GAAG,CAAC,CAAC;IAC7B,OAA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BAAiB,EACjB,GAAG,CAAC,gBAAgB,KAAK,MAAM;YAC7B,CAAC,CAAC,uGAAuG;YACzG,CAAC,CAAC,sFAAsF,EAC1F;YACE,MAAM,EAAE,GAAG,CAAC,gBAAgB,KAAK,MAAM;gBACrC,CAAC,CAAC,kCAAkC;gBACpC,CAAC,CAAC,wFAAwF;SAC7F,CACF,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC,UAAU,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file envelope.ts
|
|
3
|
+
* @description Output discipline for the `0g-agentdna` CLI — the gene-layer
|
|
4
|
+
* contract of spec v0.03 §2.2:
|
|
5
|
+
*
|
|
6
|
+
* - stdout carries DATA ONLY. With `--json` that is exactly one
|
|
7
|
+
* `{ok, data} | {ok, error}` envelope per invocation, so
|
|
8
|
+
* `0g-agentdna … --json | jq` never sees anything else.
|
|
9
|
+
* - Human-facing progress/notes go to stderr, in both modes.
|
|
10
|
+
* - bigint values serialize as strings (JSON numbers lose precision past
|
|
11
|
+
* 2^53 — agentIds are uint256 on chain).
|
|
12
|
+
*
|
|
13
|
+
* Envelope field names are append-only: adding fields is fine, renaming or
|
|
14
|
+
* removing is a breaking change (scripts and the future skill parse these).
|
|
15
|
+
*/
|
|
16
|
+
import type { CliError } from './errors';
|
|
17
|
+
/** JSON.stringify replacer: bigint → decimal string. */
|
|
18
|
+
export declare function bigintReplacer(_key: string, value: unknown): unknown;
|
|
19
|
+
/** Success envelope to stdout (JSON mode). */
|
|
20
|
+
export declare function emitOk(data: unknown): void;
|
|
21
|
+
/**
|
|
22
|
+
* Error → output + exit code, honoring the mode:
|
|
23
|
+
* - JSON mode: the error envelope is DATA — it goes to stdout (a pipeline
|
|
24
|
+
* reading stdout must see why the command failed), stderr stays quiet.
|
|
25
|
+
* - Human mode: everything goes to stderr; stdout stays clean.
|
|
26
|
+
* Returns the exit code for the caller to pass to `process.exit`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function emitError(err: CliError, json: boolean): number;
|
|
29
|
+
/** Human-facing note/progress line — always stderr, never stdout. */
|
|
30
|
+
export declare function note(message: string): void;
|
|
31
|
+
/** Human-mode data line (tables, check lists …) — stdout, non-JSON mode only. */
|
|
32
|
+
export declare function print(line: string): void;
|
|
33
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/cli/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wDAAwD;AACxD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpE;AAED,8CAA8C;AAC9C,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE1C;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAW9D;AAED,qEAAqE;AACrE,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED,iFAAiF;AACjF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAExC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file envelope.ts
|
|
4
|
+
* @description Output discipline for the `0g-agentdna` CLI — the gene-layer
|
|
5
|
+
* contract of spec v0.03 §2.2:
|
|
6
|
+
*
|
|
7
|
+
* - stdout carries DATA ONLY. With `--json` that is exactly one
|
|
8
|
+
* `{ok, data} | {ok, error}` envelope per invocation, so
|
|
9
|
+
* `0g-agentdna … --json | jq` never sees anything else.
|
|
10
|
+
* - Human-facing progress/notes go to stderr, in both modes.
|
|
11
|
+
* - bigint values serialize as strings (JSON numbers lose precision past
|
|
12
|
+
* 2^53 — agentIds are uint256 on chain).
|
|
13
|
+
*
|
|
14
|
+
* Envelope field names are append-only: adding fields is fine, renaming or
|
|
15
|
+
* removing is a breaking change (scripts and the future skill parse these).
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.bigintReplacer = bigintReplacer;
|
|
19
|
+
exports.emitOk = emitOk;
|
|
20
|
+
exports.emitError = emitError;
|
|
21
|
+
exports.note = note;
|
|
22
|
+
exports.print = print;
|
|
23
|
+
/** JSON.stringify replacer: bigint → decimal string. */
|
|
24
|
+
function bigintReplacer(_key, value) {
|
|
25
|
+
return typeof value === 'bigint' ? value.toString() : value;
|
|
26
|
+
}
|
|
27
|
+
/** Success envelope to stdout (JSON mode). */
|
|
28
|
+
function emitOk(data) {
|
|
29
|
+
process.stdout.write(JSON.stringify({ ok: true, data }, bigintReplacer) + '\n');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Error → output + exit code, honoring the mode:
|
|
33
|
+
* - JSON mode: the error envelope is DATA — it goes to stdout (a pipeline
|
|
34
|
+
* reading stdout must see why the command failed), stderr stays quiet.
|
|
35
|
+
* - Human mode: everything goes to stderr; stdout stays clean.
|
|
36
|
+
* Returns the exit code for the caller to pass to `process.exit`.
|
|
37
|
+
*/
|
|
38
|
+
function emitError(err, json) {
|
|
39
|
+
if (json) {
|
|
40
|
+
const error = { code: err.code, message: err.message };
|
|
41
|
+
if (err.remedy !== undefined)
|
|
42
|
+
error.remedy = err.remedy;
|
|
43
|
+
if (err.details !== undefined)
|
|
44
|
+
error.details = err.details;
|
|
45
|
+
process.stdout.write(JSON.stringify({ ok: false, error }, bigintReplacer) + '\n');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
process.stderr.write(`error (${err.code}): ${err.message}\n`);
|
|
49
|
+
if (err.remedy)
|
|
50
|
+
process.stderr.write(` fix: ${err.remedy}\n`);
|
|
51
|
+
}
|
|
52
|
+
return err.exitCode;
|
|
53
|
+
}
|
|
54
|
+
/** Human-facing note/progress line — always stderr, never stdout. */
|
|
55
|
+
function note(message) {
|
|
56
|
+
process.stderr.write(message + '\n');
|
|
57
|
+
}
|
|
58
|
+
/** Human-mode data line (tables, check lists …) — stdout, non-JSON mode only. */
|
|
59
|
+
function print(line) {
|
|
60
|
+
process.stdout.write(line + '\n');
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/cli/envelope.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAKH,wCAEC;AAGD,wBAEC;AASD,8BAWC;AAGD,oBAEC;AAGD,sBAEC;AAtCD,wDAAwD;AACxD,SAAgB,cAAc,CAAC,IAAY,EAAE,KAAc;IACzD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9D,CAAC;AAED,8CAA8C;AAC9C,SAAgB,MAAM,CAAC,IAAa;IAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AAClF,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,GAAa,EAAE,IAAa;IACpD,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,KAAK,GAA4B,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;QAChF,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS;YAAE,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACxD,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS;YAAE,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC3D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;IACpF,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC;QAC9D,IAAI,GAAG,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC;AACtB,CAAC;AAED,qEAAqE;AACrE,SAAgB,IAAI,CAAC,OAAe;IAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;AACvC,CAAC;AAED,iFAAiF;AACjF,SAAgB,KAAK,CAAC,IAAY;IAChC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file errors.ts
|
|
3
|
+
* @description Error codes + exit-code semantics for the `0g-agentdna` CLI —
|
|
4
|
+
* part of the gene-layer contract (spec v0.03 §2.3) consumed by scripts and
|
|
5
|
+
* agents. Both the code strings and the code→exit mapping are APPEND-ONLY:
|
|
6
|
+
* adding a code is fine, renaming or renumbering is a breaking change.
|
|
7
|
+
*
|
|
8
|
+
* Exit-code semantics (what a non-JSON-parsing caller should do next):
|
|
9
|
+
* 0 — success
|
|
10
|
+
* 1 — unknown/internal error: report it, retrying won't help
|
|
11
|
+
* 2 — usage error: fix the arguments and re-run
|
|
12
|
+
* 3 — fixable precondition: run `error.remedy`, then re-run
|
|
13
|
+
* 4 — timeout: the operation may still complete; check status later
|
|
14
|
+
* 5 — auth/ownership: stop; a different key is needed
|
|
15
|
+
*/
|
|
16
|
+
/** Machine-readable error codes. Append-only — never rename. */
|
|
17
|
+
export type ErrorCode = 'UNKNOWN' | 'NOT_IMPLEMENTED' | 'UNKNOWN_COMMAND' | 'BAD_FLAG' | 'BAD_AGENT_REF' | 'AGENT_NOT_FOUND' | 'MISSING_ATTESTOR_URL' | 'ATTESTOR_UNREACHABLE' | 'RPC_UNREACHABLE' | 'WALLET_REQUIRED' | 'PREFLIGHT_GAS' | 'PREFLIGHT_ACK' | 'PREFLIGHT_BALANCE' | 'SETTINGS_CONFLICT' | 'INFERENCE_KEY_REQUIRED' | 'INFERENCE_PROVIDER_UNSUPPORTED' | 'TIMEOUT' | 'AUTH_REJECTED';
|
|
18
|
+
/** Semantic exit codes (see file header for caller guidance). */
|
|
19
|
+
export declare const EXIT: {
|
|
20
|
+
readonly OK: 0;
|
|
21
|
+
readonly UNKNOWN: 1;
|
|
22
|
+
readonly USAGE: 2;
|
|
23
|
+
readonly REMEDIABLE: 3;
|
|
24
|
+
readonly TIMEOUT: 4;
|
|
25
|
+
readonly AUTH: 5;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The one error type every command throws. `main.ts` is the single place that
|
|
29
|
+
* turns it into an envelope (or a stderr line) + `process.exit`.
|
|
30
|
+
*/
|
|
31
|
+
export declare class CliError extends Error {
|
|
32
|
+
/** Stable machine-readable code — the contract field scripts branch on. */
|
|
33
|
+
readonly code: ErrorCode;
|
|
34
|
+
/** How to fix it. For exit-3 errors this is the whole point: a command or
|
|
35
|
+
* instruction the caller (human or agent) can act on directly. */
|
|
36
|
+
readonly remedy?: string;
|
|
37
|
+
/** Structured extras (e.g. doctor's per-check results). Must survive the
|
|
38
|
+
* bigint-safe JSON serializer in envelope.ts. */
|
|
39
|
+
readonly details?: unknown;
|
|
40
|
+
constructor(code: ErrorCode, message: string, opts?: {
|
|
41
|
+
remedy?: string;
|
|
42
|
+
details?: unknown;
|
|
43
|
+
});
|
|
44
|
+
get exitCode(): number;
|
|
45
|
+
}
|
|
46
|
+
/** Wrap any thrown value into a CliError (unknown → exit 1). */
|
|
47
|
+
export declare function toCliError(e: unknown): CliError;
|
|
48
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/cli/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,gEAAgE;AAChE,MAAM,MAAM,SAAS,GAEjB,SAAS,GACT,iBAAiB,GAEjB,iBAAiB,GACjB,UAAU,GACV,eAAe,GACf,iBAAiB,GAEjB,sBAAsB,GACtB,sBAAsB,GACtB,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,mBAAmB,GACnB,wBAAwB,GACxB,gCAAgC,GAEhC,SAAS,GAET,eAAe,CAAC;AAEpB,iEAAiE;AACjE,eAAO,MAAM,IAAI;;;;;;;CAOP,CAAC;AA2BX;;;GAGG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB;uEACmE;IACnE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;sDACkD;IAClD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEf,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE;IAQ3F,IAAI,QAAQ,IAAI,MAAM,CAErB;CACF;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,QAAQ,CAQ/C"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file errors.ts
|
|
4
|
+
* @description Error codes + exit-code semantics for the `0g-agentdna` CLI —
|
|
5
|
+
* part of the gene-layer contract (spec v0.03 §2.3) consumed by scripts and
|
|
6
|
+
* agents. Both the code strings and the code→exit mapping are APPEND-ONLY:
|
|
7
|
+
* adding a code is fine, renaming or renumbering is a breaking change.
|
|
8
|
+
*
|
|
9
|
+
* Exit-code semantics (what a non-JSON-parsing caller should do next):
|
|
10
|
+
* 0 — success
|
|
11
|
+
* 1 — unknown/internal error: report it, retrying won't help
|
|
12
|
+
* 2 — usage error: fix the arguments and re-run
|
|
13
|
+
* 3 — fixable precondition: run `error.remedy`, then re-run
|
|
14
|
+
* 4 — timeout: the operation may still complete; check status later
|
|
15
|
+
* 5 — auth/ownership: stop; a different key is needed
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.CliError = exports.EXIT = void 0;
|
|
19
|
+
exports.toCliError = toCliError;
|
|
20
|
+
/** Semantic exit codes (see file header for caller guidance). */
|
|
21
|
+
exports.EXIT = {
|
|
22
|
+
OK: 0,
|
|
23
|
+
UNKNOWN: 1,
|
|
24
|
+
USAGE: 2,
|
|
25
|
+
REMEDIABLE: 3,
|
|
26
|
+
TIMEOUT: 4,
|
|
27
|
+
AUTH: 5,
|
|
28
|
+
};
|
|
29
|
+
const EXIT_BY_CODE = {
|
|
30
|
+
UNKNOWN: exports.EXIT.UNKNOWN,
|
|
31
|
+
NOT_IMPLEMENTED: exports.EXIT.UNKNOWN,
|
|
32
|
+
UNKNOWN_COMMAND: exports.EXIT.USAGE,
|
|
33
|
+
BAD_FLAG: exports.EXIT.USAGE,
|
|
34
|
+
BAD_AGENT_REF: exports.EXIT.USAGE,
|
|
35
|
+
AGENT_NOT_FOUND: exports.EXIT.USAGE,
|
|
36
|
+
MISSING_ATTESTOR_URL: exports.EXIT.REMEDIABLE,
|
|
37
|
+
ATTESTOR_UNREACHABLE: exports.EXIT.REMEDIABLE,
|
|
38
|
+
RPC_UNREACHABLE: exports.EXIT.REMEDIABLE,
|
|
39
|
+
WALLET_REQUIRED: exports.EXIT.REMEDIABLE,
|
|
40
|
+
PREFLIGHT_GAS: exports.EXIT.REMEDIABLE,
|
|
41
|
+
PREFLIGHT_ACK: exports.EXIT.REMEDIABLE,
|
|
42
|
+
PREFLIGHT_BALANCE: exports.EXIT.REMEDIABLE,
|
|
43
|
+
// Somebody else wrote the settings document between this command's read and
|
|
44
|
+
// its write. Remediable, and the remedy is a re-run — but only after the
|
|
45
|
+
// caller has looked at `details.current`, which is why this is an error and
|
|
46
|
+
// not a silent retry.
|
|
47
|
+
SETTINGS_CONFLICT: exports.EXIT.REMEDIABLE,
|
|
48
|
+
INFERENCE_KEY_REQUIRED: exports.EXIT.REMEDIABLE,
|
|
49
|
+
INFERENCE_PROVIDER_UNSUPPORTED: exports.EXIT.REMEDIABLE,
|
|
50
|
+
TIMEOUT: exports.EXIT.TIMEOUT,
|
|
51
|
+
AUTH_REJECTED: exports.EXIT.AUTH,
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The one error type every command throws. `main.ts` is the single place that
|
|
55
|
+
* turns it into an envelope (or a stderr line) + `process.exit`.
|
|
56
|
+
*/
|
|
57
|
+
class CliError extends Error {
|
|
58
|
+
constructor(code, message, opts) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'CliError';
|
|
61
|
+
this.code = code;
|
|
62
|
+
this.remedy = opts?.remedy;
|
|
63
|
+
this.details = opts?.details;
|
|
64
|
+
}
|
|
65
|
+
get exitCode() {
|
|
66
|
+
return EXIT_BY_CODE[this.code];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.CliError = CliError;
|
|
70
|
+
/** Wrap any thrown value into a CliError (unknown → exit 1). */
|
|
71
|
+
function toCliError(e) {
|
|
72
|
+
if (e instanceof CliError)
|
|
73
|
+
return e;
|
|
74
|
+
if (e instanceof Error && e.code === 'provider_binding_unsupported') {
|
|
75
|
+
return new CliError('INFERENCE_PROVIDER_UNSUPPORTED', e.message, {
|
|
76
|
+
remedy: 'ask the attestor operator to enable provider-bound credentials for this runtime image, then retry',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return new CliError('UNKNOWN', e instanceof Error ? e.message : String(e));
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/cli/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AA2FH,gCAQC;AAvED,iEAAiE;AACpD,QAAA,IAAI,GAAG;IAClB,EAAE,EAAE,CAAC;IACL,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,UAAU,EAAE,CAAC;IACb,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;CACC,CAAC;AAEX,MAAM,YAAY,GAA8B;IAC9C,OAAO,EAAE,YAAI,CAAC,OAAO;IACrB,eAAe,EAAE,YAAI,CAAC,OAAO;IAC7B,eAAe,EAAE,YAAI,CAAC,KAAK;IAC3B,QAAQ,EAAE,YAAI,CAAC,KAAK;IACpB,aAAa,EAAE,YAAI,CAAC,KAAK;IACzB,eAAe,EAAE,YAAI,CAAC,KAAK;IAC3B,oBAAoB,EAAE,YAAI,CAAC,UAAU;IACrC,oBAAoB,EAAE,YAAI,CAAC,UAAU;IACrC,eAAe,EAAE,YAAI,CAAC,UAAU;IAChC,eAAe,EAAE,YAAI,CAAC,UAAU;IAChC,aAAa,EAAE,YAAI,CAAC,UAAU;IAC9B,aAAa,EAAE,YAAI,CAAC,UAAU;IAC9B,iBAAiB,EAAE,YAAI,CAAC,UAAU;IAClC,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,sBAAsB;IACtB,iBAAiB,EAAE,YAAI,CAAC,UAAU;IAClC,sBAAsB,EAAE,YAAI,CAAC,UAAU;IACvC,8BAA8B,EAAE,YAAI,CAAC,UAAU;IAC/C,OAAO,EAAE,YAAI,CAAC,OAAO;IACrB,aAAa,EAAE,YAAI,CAAC,IAAI;CACzB,CAAC;AAEF;;;GAGG;AACH,MAAa,QAAS,SAAQ,KAAK;IAUjC,YAAY,IAAe,EAAE,OAAe,EAAE,IAA6C;QACzF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC;IAC/B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;CACF;AArBD,4BAqBC;AAED,gEAAgE;AAChE,SAAgB,UAAU,CAAC,CAAU;IACnC,IAAI,CAAC,YAAY,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,YAAY,KAAK,IAAK,CAA+B,CAAC,IAAI,KAAK,8BAA8B,EAAE,CAAC;QACnG,OAAO,IAAI,QAAQ,CAAC,gCAAgC,EAAE,CAAC,CAAC,OAAO,EAAE;YAC/D,MAAM,EAAE,mGAAmG;SAC5G,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgenticID } from '../AgenticID';
|
|
2
|
+
import type { Hash } from 'viem';
|
|
3
|
+
/** Deploy using the current registry's routing requirements. Called after
|
|
4
|
+
* the wizard's prompts/preflight so an edited compute route is rechecked. */
|
|
5
|
+
export declare function deployWithInference(ag: AgenticID, params: {
|
|
6
|
+
name: string;
|
|
7
|
+
framework: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
model: string;
|
|
10
|
+
provision: boolean;
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
deployment: import("../AgenticID").DeployAccepted;
|
|
14
|
+
agentId: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function configuredInferenceKey(provider: string, env?: NodeJS.ProcessEnv): string | null;
|
|
17
|
+
export declare function requireConfiguredInferenceKey(provider: string, env?: NodeJS.ProcessEnv): string;
|
|
18
|
+
/** A failed owner settings read must not select a different provider or key. */
|
|
19
|
+
export declare function agentInferenceProvider(ag: AgenticID, sealId: Hash): Promise<string>;
|
|
20
|
+
export declare function requiresProviderReset(error: unknown): boolean;
|
|
21
|
+
//# sourceMappingURL=inference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../src/cli/inference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAKjC;6EAC6E;AAC7E,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE;IAC/D,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IACjE,SAAS,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACrC;;;GAoBA;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,GAAG,IAAI,CAG5G;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAM5G;AAED,gFAAgF;AAChF,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAKzF;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE7D"}
|