@0gfoundation/0g-agentdna 0.4.0 → 0.5.0
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 +190 -40
- package/OPERATORS.md +164 -0
- package/OPERATORS.zh.md +141 -0
- package/PROVIDERS.md +6 -0
- package/PROVIDERS.zh.md +3 -1
- package/README.md +84 -11
- package/dist/AgentClient.d.ts +374 -26
- package/dist/AgentClient.d.ts.map +1 -1
- package/dist/AgentClient.js +323 -40
- package/dist/AgentClient.js.map +1 -1
- package/dist/AgenticID.d.ts +170 -80
- package/dist/AgenticID.d.ts.map +1 -1
- package/dist/AgenticID.js +300 -42
- package/dist/AgenticID.js.map +1 -1
- package/dist/AttestorClient.d.ts +115 -31
- package/dist/AttestorClient.d.ts.map +1 -1
- package/dist/AttestorClient.js +276 -56
- package/dist/AttestorClient.js.map +1 -1
- package/dist/Credentials.d.ts +574 -0
- package/dist/Credentials.d.ts.map +1 -0
- package/dist/Credentials.js +838 -0
- package/dist/Credentials.js.map +1 -0
- package/dist/Operators.d.ts +60 -0
- package/dist/Operators.d.ts.map +1 -0
- package/dist/Operators.js +38 -0
- package/dist/Operators.js.map +1 -0
- package/dist/Providers.d.ts +13 -0
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +20 -1
- package/dist/Providers.js.map +1 -1
- package/dist/Releases.d.ts +51 -0
- package/dist/Releases.d.ts.map +1 -0
- package/dist/Releases.js +72 -0
- package/dist/Releases.js.map +1 -0
- package/dist/ReputationClient.d.ts +47 -3
- package/dist/ReputationClient.d.ts.map +1 -1
- package/dist/ReputationClient.js +204 -78
- package/dist/ReputationClient.js.map +1 -1
- package/dist/ServeProof.d.ts +70 -23
- package/dist/ServeProof.d.ts.map +1 -1
- package/dist/ServeProof.js +94 -35
- package/dist/ServeProof.js.map +1 -1
- package/dist/ServeSession.d.ts +17 -2
- package/dist/ServeSession.d.ts.map +1 -1
- package/dist/ServeSession.js +77 -9
- package/dist/ServeSession.js.map +1 -1
- package/dist/Settings.d.ts +25 -1
- package/dist/Settings.d.ts.map +1 -1
- package/dist/Settings.js +53 -1
- package/dist/Settings.js.map +1 -1
- package/dist/TrustRegistry.d.ts +28 -0
- package/dist/TrustRegistry.d.ts.map +1 -0
- package/dist/TrustRegistry.js +67 -0
- package/dist/TrustRegistry.js.map +1 -0
- package/dist/abi.d.ts +346 -34
- package/dist/abi.d.ts.map +1 -1
- package/dist/abi.js +150 -30
- package/dist/abi.js.map +1 -1
- package/dist/cli/attach.d.ts +79 -0
- package/dist/cli/attach.d.ts.map +1 -0
- package/dist/cli/attach.js +253 -0
- package/dist/cli/attach.js.map +1 -0
- package/dist/cli/commands/cells.d.ts +45 -0
- package/dist/cli/commands/cells.d.ts.map +1 -1
- package/dist/cli/commands/cells.js +77 -0
- package/dist/cli/commands/cells.js.map +1 -1
- package/dist/cli/commands/cred.d.ts +12 -0
- package/dist/cli/commands/cred.d.ts.map +1 -0
- package/dist/cli/commands/cred.js +43 -0
- package/dist/cli/commands/cred.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -1
- package/dist/cli/commands/doctor.js +44 -35
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/interactive.d.ts +597 -21
- package/dist/cli/commands/interactive.d.ts.map +1 -1
- package/dist/cli/commands/interactive.js +5082 -1323
- package/dist/cli/commands/interactive.js.map +1 -1
- package/dist/cli/commands/list.d.ts +5 -5
- package/dist/cli/commands/list.d.ts.map +1 -1
- package/dist/cli/commands/list.js +21 -26
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/providers.d.ts +4 -0
- package/dist/cli/commands/providers.d.ts.map +1 -1
- package/dist/cli/commands/providers.js +19 -5
- package/dist/cli/commands/providers.js.map +1 -1
- package/dist/cli/commands/releases.d.ts +13 -0
- package/dist/cli/commands/releases.d.ts.map +1 -0
- package/dist/cli/commands/releases.js +65 -0
- package/dist/cli/commands/releases.js.map +1 -0
- package/dist/cli/commands/settings.d.ts +5 -0
- package/dist/cli/commands/settings.d.ts.map +1 -1
- package/dist/cli/commands/settings.js +70 -24
- package/dist/cli/commands/settings.js.map +1 -1
- package/dist/cli/commands/status.d.ts +2 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +22 -19
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/config.d.ts +48 -1
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +114 -5
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/credentials.d.ts +179 -0
- package/dist/cli/credentials.d.ts.map +1 -0
- package/dist/cli/credentials.js +1443 -0
- package/dist/cli/credentials.js.map +1 -0
- package/dist/cli/download.d.ts +21 -0
- package/dist/cli/download.d.ts.map +1 -0
- package/dist/cli/download.js +89 -0
- package/dist/cli/download.js.map +1 -0
- package/dist/cli/env.d.ts +6 -0
- package/dist/cli/env.d.ts.map +1 -1
- package/dist/cli/env.js +18 -6
- package/dist/cli/env.js.map +1 -1
- package/dist/cli/envelope.d.ts +4 -2
- package/dist/cli/envelope.d.ts.map +1 -1
- package/dist/cli/envelope.js +10 -6
- package/dist/cli/envelope.js.map +1 -1
- package/dist/cli/errors.d.ts +45 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/errors.js +77 -0
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/inference.d.ts.map +1 -1
- package/dist/cli/inference.js +7 -0
- package/dist/cli/inference.js.map +1 -1
- package/dist/cli/inkView.d.ts +341 -0
- package/dist/cli/inkView.d.ts.map +1 -0
- package/dist/cli/inkView.js +1019 -0
- package/dist/cli/inkView.js.map +1 -0
- package/dist/cli/legacy/modelKey.d.ts +24 -0
- package/dist/cli/legacy/modelKey.d.ts.map +1 -0
- package/dist/cli/legacy/modelKey.js +32 -0
- package/dist/cli/legacy/modelKey.js.map +1 -0
- package/dist/cli/livePrompt.d.ts +212 -0
- package/dist/cli/livePrompt.d.ts.map +1 -0
- package/dist/cli/livePrompt.js +576 -0
- package/dist/cli/livePrompt.js.map +1 -0
- package/dist/cli/main.js +206 -72
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/modelkey.d.ts +64 -0
- package/dist/cli/modelkey.d.ts.map +1 -0
- package/dist/cli/modelkey.js +113 -0
- package/dist/cli/modelkey.js.map +1 -0
- package/dist/cli/outboxSync.d.ts +51 -0
- package/dist/cli/outboxSync.d.ts.map +1 -0
- package/dist/cli/outboxSync.js +210 -0
- package/dist/cli/outboxSync.js.map +1 -0
- package/dist/cli/plain.d.ts +46 -0
- package/dist/cli/plain.d.ts.map +1 -0
- package/dist/cli/plain.js +260 -0
- package/dist/cli/plain.js.map +1 -0
- package/dist/cli/proofs.d.ts +5 -0
- package/dist/cli/proofs.d.ts.map +1 -1
- package/dist/cli/proofs.js +20 -0
- package/dist/cli/proofs.js.map +1 -1
- package/dist/cli/ref.d.ts.map +1 -1
- package/dist/cli/ref.js +3 -2
- package/dist/cli/ref.js.map +1 -1
- package/dist/cli/releaseNotice.d.ts +64 -0
- package/dist/cli/releaseNotice.d.ts.map +1 -0
- package/dist/cli/releaseNotice.js +194 -0
- package/dist/cli/releaseNotice.js.map +1 -0
- package/dist/cli/sdk.d.ts +18 -0
- package/dist/cli/sdk.d.ts.map +1 -1
- package/dist/cli/sdk.js +99 -1
- package/dist/cli/sdk.js.map +1 -1
- package/dist/cli/settings.d.ts +87 -6
- package/dist/cli/settings.d.ts.map +1 -1
- package/dist/cli/settings.js +270 -18
- package/dist/cli/settings.js.map +1 -1
- package/dist/cli/textfit.d.ts +28 -0
- package/dist/cli/textfit.d.ts.map +1 -0
- package/dist/cli/textfit.js +111 -0
- package/dist/cli/textfit.js.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/context.d.ts +26 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -0
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +19 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/dist/legacy/modelKey.d.ts +67 -0
- package/dist/legacy/modelKey.d.ts.map +1 -0
- package/dist/legacy/modelKey.js +80 -0
- package/dist/legacy/modelKey.js.map +1 -0
- package/dist/legacy/serveProofV1.d.ts +56 -0
- package/dist/legacy/serveProofV1.d.ts.map +1 -0
- package/dist/legacy/serveProofV1.js +91 -0
- package/dist/legacy/serveProofV1.js.map +1 -0
- package/dist/provider-catalog.json +3 -2
- package/dist/secretEnv.d.ts +18 -3
- package/dist/secretEnv.d.ts.map +1 -1
- package/dist/secretEnv.js +16 -2
- package/dist/secretEnv.js.map +1 -1
- package/dist/types.d.ts +63 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/viemErrors.d.ts +30 -0
- package/dist/viemErrors.d.ts.map +1 -0
- package/dist/viemErrors.js +36 -0
- package/dist/viemErrors.js.map +1 -0
- package/package.json +5 -1
- package/src/AgentClient.ts +622 -68
- package/src/AgenticID.ts +345 -56
- package/src/AttestorClient.ts +330 -83
- package/src/Credentials.ts +1027 -0
- package/src/Operators.ts +71 -0
- package/src/Providers.ts +20 -0
- package/src/Releases.ts +95 -0
- package/src/ReputationClient.ts +231 -79
- package/src/ServeProof.ts +123 -39
- package/src/ServeSession.ts +91 -9
- package/src/Settings.ts +61 -1
- package/src/TrustRegistry.ts +75 -0
- package/src/abi.ts +153 -30
- package/src/cli/attach.ts +257 -0
- package/src/cli/commands/cells.ts +104 -0
- package/src/cli/commands/cred.ts +44 -0
- package/src/cli/commands/doctor.ts +45 -37
- package/src/cli/commands/interactive.ts +4120 -664
- package/src/cli/commands/list.ts +21 -30
- package/src/cli/commands/providers.ts +17 -4
- package/src/cli/commands/releases.ts +60 -0
- package/src/cli/commands/settings.ts +75 -28
- package/src/cli/commands/status.ts +24 -21
- package/src/cli/config.ts +119 -4
- package/src/cli/credentials.ts +1379 -0
- package/src/cli/download.ts +80 -0
- package/src/cli/env.ts +22 -7
- package/src/cli/envelope.ts +10 -6
- package/src/cli/errors.ts +92 -0
- package/src/cli/inference.ts +8 -1
- package/src/cli/inkView.ts +969 -0
- package/src/cli/legacy/modelKey.ts +35 -0
- package/src/cli/livePrompt.ts +615 -0
- package/src/cli/main.ts +206 -76
- package/src/cli/modelkey.ts +124 -0
- package/src/cli/outboxSync.ts +231 -0
- package/src/cli/plain.ts +260 -0
- package/src/cli/proofs.ts +27 -0
- package/src/cli/ref.ts +5 -4
- package/src/cli/releaseNotice.ts +200 -0
- package/src/cli/sdk.ts +87 -7
- package/src/cli/settings.ts +272 -22
- package/src/cli/textfit.ts +95 -0
- package/src/constants.ts +1 -1
- package/src/context.ts +28 -0
- package/src/index.ts +50 -7
- package/src/legacy/modelKey.ts +80 -0
- package/src/legacy/serveProofV1.ts +124 -0
- package/src/provider-catalog.json +3 -2
- package/src/secretEnv.ts +18 -3
- package/src/types.ts +60 -1
- package/src/viemErrors.ts +39 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/files` and `/download` (0g-harness): the files the agent hands over in its
|
|
3
|
+
* `~/outbox`, or the owner's own files in its file inbox `~/inbox`, saved
|
|
4
|
+
* locally. A download never
|
|
5
|
+
* overwrites a local file: a taken name gets "-1", "-2", … before its
|
|
6
|
+
* extension.
|
|
7
|
+
*/
|
|
8
|
+
import { closeSync, existsSync, openSync, statSync, writeSync } from 'node:fs';
|
|
9
|
+
import { basename, extname, join, resolve } from 'node:path';
|
|
10
|
+
import type { AgentFile, AgentFileDir } from '../AgentClient';
|
|
11
|
+
import { expandHome } from './attach';
|
|
12
|
+
|
|
13
|
+
/** The most one download carries (the agent's runtime serves no larger file). */
|
|
14
|
+
export const DOWNLOAD_MAX_BYTES = 50 << 20;
|
|
15
|
+
|
|
16
|
+
/** `/download` argument → where it comes from: `inbox/<name>` names a file in the agent's file inbox (the owner's own), anything else the outbox. */
|
|
17
|
+
export function parseDownloadName(arg: string): { dir: AgentFileDir; name: string } {
|
|
18
|
+
if (arg.startsWith('inbox/')) return { dir: 'inbox', name: arg.slice('inbox/'.length) };
|
|
19
|
+
if (arg.startsWith('outbox/')) return { dir: 'outbox', name: arg.slice('outbox/'.length) };
|
|
20
|
+
return { dir: 'outbox', name: arg };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A local file name for a remote one: its last segment, no control characters, no leading dots. */
|
|
24
|
+
export function localName(name: string): string {
|
|
25
|
+
const n = basename(name.replace(/\\/g, '/')).replace(/[\u0000-\u001f\u007f]/g, '_').replace(/^\.+/, '').trim();
|
|
26
|
+
return n || 'download';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Write bytes to a new local file and return its path. dest: undefined (the
|
|
31
|
+
* current directory), an existing directory, or a file path. Never over an
|
|
32
|
+
* existing file.
|
|
33
|
+
*/
|
|
34
|
+
export function saveDownload(bytes: Uint8Array, name: string, dest?: string, cwd: string = process.cwd()): string {
|
|
35
|
+
let dir: string;
|
|
36
|
+
let file: string;
|
|
37
|
+
if (!dest) {
|
|
38
|
+
dir = cwd;
|
|
39
|
+
file = localName(name);
|
|
40
|
+
} else {
|
|
41
|
+
const p = resolve(cwd, expandHome(dest));
|
|
42
|
+
if (existsSync(p) && statSync(p).isDirectory()) {
|
|
43
|
+
dir = p;
|
|
44
|
+
file = localName(name);
|
|
45
|
+
} else {
|
|
46
|
+
dir = resolve(p, '..');
|
|
47
|
+
file = basename(p) || localName(name);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const ext = extname(file);
|
|
51
|
+
const stem = file.slice(0, file.length - ext.length) || 'download';
|
|
52
|
+
for (let i = 0; i < 10000; i++) {
|
|
53
|
+
const path = join(dir, i === 0 ? file : `${stem}-${i}${ext}`);
|
|
54
|
+
let fd: number;
|
|
55
|
+
try {
|
|
56
|
+
fd = openSync(path, 'wx', 0o600);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
if ((err as NodeJS.ErrnoException).code === 'EEXIST') continue;
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
let off = 0;
|
|
63
|
+
while (off < bytes.length) off += writeSync(fd, bytes, off, bytes.length - off);
|
|
64
|
+
} finally {
|
|
65
|
+
closeSync(fd);
|
|
66
|
+
}
|
|
67
|
+
return path;
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`no free local name for ${file}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A byte count for people: B, KiB, MiB. */
|
|
73
|
+
export const size = (n: number): string =>
|
|
74
|
+
n < 1024 ? `${n} B` : n < 1 << 20 ? `${(n / 1024).toFixed(1)} KiB` : `${(n / (1 << 20)).toFixed(1)} MiB`;
|
|
75
|
+
|
|
76
|
+
/** `/files` lines: name, size, time. */
|
|
77
|
+
export function renderFiles(files: readonly AgentFile[]): string[] {
|
|
78
|
+
const w = Math.max(4, ...files.map((f) => f.name.length));
|
|
79
|
+
return files.map((f) => ` ${f.name.padEnd(w)} ${size(f.bytes).padStart(10)} ${f.mtime.replace('T', ' ').replace(/\.\d+Z$/, 'Z')}`);
|
|
80
|
+
}
|
package/src/cli/env.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* CI logs), env is not.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { CliError } from './errors';
|
|
9
|
+
import { CliError, currentSurface, shellStep, shellTo } from './errors';
|
|
10
10
|
import { loadConfig, loadKey, normalizeKey } from './config';
|
|
11
11
|
|
|
12
12
|
/** Resolved CLI environment. All values come from `process.env`. */
|
|
@@ -14,6 +14,9 @@ export interface CliEnv {
|
|
|
14
14
|
/** `AGENTIC_ATTESTOR_URL` — one URL selects the whole environment
|
|
15
15
|
* (contracts, chain RPC, appIds via the attestor's GET /config). */
|
|
16
16
|
attestorUrl?: string;
|
|
17
|
+
/** Where `attestorUrl` came from — a remedy names the place to fix it
|
|
18
|
+
* (the env var, or `login`). */
|
|
19
|
+
attestorUrlSource?: 'env' | 'file';
|
|
17
20
|
/** `AGENTIC_PRIVATE_KEY` — optional owner key. Enables `--mine`,
|
|
18
21
|
* owner-tier failure reasons, and doctor's owner checks. */
|
|
19
22
|
privateKey?: `0x${string}`;
|
|
@@ -38,8 +41,10 @@ export function readEnv(env: NodeJS.ProcessEnv = process.env): CliEnv {
|
|
|
38
41
|
};
|
|
39
42
|
const file = loadConfig(env);
|
|
40
43
|
const fileKey = loadKey(env);
|
|
44
|
+
const envUrl = pick('AGENTIC_ATTESTOR_URL');
|
|
41
45
|
return {
|
|
42
|
-
attestorUrl: (
|
|
46
|
+
attestorUrl: (envUrl ?? file.attestorUrl)?.replace(/\/$/, ''),
|
|
47
|
+
...(envUrl ? { attestorUrlSource: 'env' as const } : file.attestorUrl ? { attestorUrlSource: 'file' as const } : {}),
|
|
43
48
|
// env keys are normalized like login input (0x prefix optional); a
|
|
44
49
|
// malformed value passes through so requirePrivateKey can name the problem.
|
|
45
50
|
...((): Pick<CliEnv, 'privateKey' | 'privateKeySource'> => {
|
|
@@ -52,11 +57,19 @@ export function readEnv(env: NodeJS.ProcessEnv = process.env): CliEnv {
|
|
|
52
57
|
};
|
|
53
58
|
}
|
|
54
59
|
|
|
60
|
+
/** How to set the attestor URL, from where the owner is: `login` saves it;
|
|
61
|
+
* a one-shot command also takes the env var. */
|
|
62
|
+
export function attestorUrlRemedy(): string {
|
|
63
|
+
return currentSurface() === 'shell'
|
|
64
|
+
? `${shellStep('login')} sets it`
|
|
65
|
+
: `${shellStep('login')}, or export AGENTIC_ATTESTOR_URL=https://agentdna.0g.ai`;
|
|
66
|
+
}
|
|
67
|
+
|
|
55
68
|
/** Attestor URL or a remediable failure (exit 3) naming the exact fix. */
|
|
56
69
|
export function requireAttestorUrl(env: CliEnv): string {
|
|
57
70
|
if (!env.attestorUrl) {
|
|
58
|
-
throw new CliError('MISSING_ATTESTOR_URL', '
|
|
59
|
-
remedy:
|
|
71
|
+
throw new CliError('MISSING_ATTESTOR_URL', 'no attestor URL is set — the CLI cannot reach an environment without it', {
|
|
72
|
+
remedy: attestorUrlRemedy(),
|
|
60
73
|
});
|
|
61
74
|
}
|
|
62
75
|
return env.attestorUrl;
|
|
@@ -67,8 +80,10 @@ export function requireAttestorUrl(env: CliEnv): string {
|
|
|
67
80
|
* remedy instead of a deep viem stack trace later. */
|
|
68
81
|
export function requirePrivateKey(env: CliEnv): `0x${string}` {
|
|
69
82
|
if (!env.privateKey) {
|
|
70
|
-
throw new CliError('WALLET_REQUIRED', 'this
|
|
71
|
-
remedy:
|
|
83
|
+
throw new CliError('WALLET_REQUIRED', 'this needs your owner key, and none is set', {
|
|
84
|
+
remedy: currentSurface() === 'shell'
|
|
85
|
+
? `${shellStep('login')} saves it`
|
|
86
|
+
: `${shellStep('login')}, or export AGENTIC_PRIVATE_KEY=0x… # env only — there is no flag for this, by design`,
|
|
72
87
|
});
|
|
73
88
|
}
|
|
74
89
|
if (!/^0x[0-9a-fA-F]{64}$/.test(env.privateKey)) {
|
|
@@ -81,7 +96,7 @@ export function requirePrivateKey(env: CliEnv): `0x${string}` {
|
|
|
81
96
|
: 'AGENTIC_PRIVATE_KEY is set but malformed (expected 64 hex chars, 0x prefix optional)',
|
|
82
97
|
{
|
|
83
98
|
remedy: env.privateKeySource === 'file'
|
|
84
|
-
? '
|
|
99
|
+
? shellTo('login', 'enter the key again')
|
|
85
100
|
: 'export AGENTIC_PRIVATE_KEY=0x<64 hex chars> # or unset it to use the login-saved key',
|
|
86
101
|
},
|
|
87
102
|
);
|
package/src/cli/envelope.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import type { CliError } from './errors';
|
|
18
|
+
import { fitLines, termWidth } from './textfit';
|
|
18
19
|
|
|
19
20
|
/** JSON.stringify replacer: bigint → decimal string. */
|
|
20
21
|
export function bigintReplacer(_key: string, value: unknown): unknown {
|
|
@@ -40,18 +41,21 @@ export function emitError(err: CliError, json: boolean): number {
|
|
|
40
41
|
if (err.details !== undefined) error.details = err.details;
|
|
41
42
|
process.stdout.write(JSON.stringify({ ok: false, error }, bigintReplacer) + '\n');
|
|
42
43
|
} else {
|
|
43
|
-
process.stderr
|
|
44
|
-
|
|
44
|
+
const w = termWidth(process.stderr);
|
|
45
|
+
process.stderr.write(`${fitLines(`error (${err.code}): ${err.message}`, w)}\n`);
|
|
46
|
+
if (err.remedy) process.stderr.write(`${fitLines(` fix: ${err.remedy}`, w)}\n`);
|
|
45
47
|
}
|
|
46
48
|
return err.exitCode;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
/** Human-facing note/progress line — always stderr, never stdout
|
|
51
|
+
/** Human-facing note/progress line — always stderr, never stdout; on a
|
|
52
|
+
* terminal, wrapped between words at its width (textfit.fitLines). */
|
|
50
53
|
export function note(message: string): void {
|
|
51
|
-
process.stderr.write(message + '\n');
|
|
54
|
+
process.stderr.write(fitLines(message, termWidth(process.stderr)) + '\n');
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
/** Human-mode data line (tables, check lists …) — stdout, non-JSON mode
|
|
57
|
+
/** Human-mode data line (tables, check lists …) — stdout, non-JSON mode
|
|
58
|
+
* only; on a terminal, wrapped between words at its width. */
|
|
55
59
|
export function print(line: string): void {
|
|
56
|
-
process.stdout.write(line + '\n');
|
|
60
|
+
process.stdout.write(fitLines(line, termWidth()) + '\n');
|
|
57
61
|
}
|
package/src/cli/errors.ts
CHANGED
|
@@ -33,8 +33,17 @@ export type ErrorCode =
|
|
|
33
33
|
| 'PREFLIGHT_ACK'
|
|
34
34
|
| 'PREFLIGHT_BALANCE'
|
|
35
35
|
| 'SETTINGS_CONFLICT'
|
|
36
|
+
| 'CREDENTIALS_CONFLICT'
|
|
36
37
|
| 'INFERENCE_KEY_REQUIRED'
|
|
37
38
|
| 'INFERENCE_PROVIDER_UNSUPPORTED'
|
|
39
|
+
/** The agent has no agentId yet (still being minted, or its deploy failed
|
|
40
|
+
* before the mint): what needs one waits, or `retry` resumes it. */
|
|
41
|
+
| 'AGENT_NOT_READY'
|
|
42
|
+
/** The agent's runtime image predates what was asked; a reset moves it to
|
|
43
|
+
* the current image. */
|
|
44
|
+
| 'RUNTIME_TOO_OLD'
|
|
45
|
+
/** What was asked needs the agent running; start (or reset) it. */
|
|
46
|
+
| 'AGENT_NOT_RUNNING'
|
|
38
47
|
// exit 4 — timeout
|
|
39
48
|
| 'TIMEOUT'
|
|
40
49
|
// exit 5 — auth/ownership
|
|
@@ -69,8 +78,13 @@ const EXIT_BY_CODE: Record<ErrorCode, number> = {
|
|
|
69
78
|
// caller has looked at `details.current`, which is why this is an error and
|
|
70
79
|
// not a silent retry.
|
|
71
80
|
SETTINGS_CONFLICT: EXIT.REMEDIABLE,
|
|
81
|
+
// The same for the agent's credential set.
|
|
82
|
+
CREDENTIALS_CONFLICT: EXIT.REMEDIABLE,
|
|
72
83
|
INFERENCE_KEY_REQUIRED: EXIT.REMEDIABLE,
|
|
73
84
|
INFERENCE_PROVIDER_UNSUPPORTED: EXIT.REMEDIABLE,
|
|
85
|
+
AGENT_NOT_READY: EXIT.REMEDIABLE,
|
|
86
|
+
RUNTIME_TOO_OLD: EXIT.REMEDIABLE,
|
|
87
|
+
AGENT_NOT_RUNNING: EXIT.REMEDIABLE,
|
|
74
88
|
TIMEOUT: EXIT.TIMEOUT,
|
|
75
89
|
AUTH_REJECTED: EXIT.AUTH,
|
|
76
90
|
};
|
|
@@ -112,3 +126,81 @@ export function toCliError(e: unknown): CliError {
|
|
|
112
126
|
}
|
|
113
127
|
return new CliError('UNKNOWN', e instanceof Error ? e.message : String(e));
|
|
114
128
|
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Where the owner reads an error: at the shell's prompt (`0g-agentdna>` or an
|
|
132
|
+
* agent's session), or back in their own shell after a one-shot command. A
|
|
133
|
+
* remedy names a command the owner can type THERE: `deposit 0.1` at the
|
|
134
|
+
* prompt, `run \`0g-agentdna\` and type \`deposit 0.1\` there` outside it.
|
|
135
|
+
* The interactive shell switches to 'shell' once it is up; errors are built
|
|
136
|
+
* where they are thrown, so the surface at that moment is the one that counts.
|
|
137
|
+
*/
|
|
138
|
+
export type Surface = 'shell' | 'oneshot';
|
|
139
|
+
let surface: Surface = 'oneshot';
|
|
140
|
+
export function setSurface(s: Surface): void {
|
|
141
|
+
surface = s;
|
|
142
|
+
}
|
|
143
|
+
export function currentSurface(): Surface {
|
|
144
|
+
return surface;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A command that exists only inside the shell, as a remedy. */
|
|
148
|
+
export function shellStep(cmd: string): string {
|
|
149
|
+
return surface === 'shell' ? `\`${cmd}\`` : `run \`0g-agentdna\` and type \`${cmd}\` there`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A shell command and what it is for, as a whole sentence for where the
|
|
154
|
+
* owner is: at the prompt "type `retry 288` to resume it"; outside it "run
|
|
155
|
+
* `0g-agentdna` and type `retry 288` there to resume it". `purpose` is a
|
|
156
|
+
* verb phrase.
|
|
157
|
+
*/
|
|
158
|
+
export function shellTo(cmd: string, purpose: string): string {
|
|
159
|
+
return surface === 'shell'
|
|
160
|
+
? `type \`${cmd}\` to ${purpose}`
|
|
161
|
+
: `run \`0g-agentdna\` and type \`${cmd}\` there to ${purpose}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The agent a command works on, and whether it runs in that agent's session,
|
|
166
|
+
* so a message can name the next command with its id filled in. Set by the
|
|
167
|
+
* cred and settings commands (one-shot, manager, session); null otherwise.
|
|
168
|
+
*/
|
|
169
|
+
let agentAtHand: { ref: string; session: boolean } | null = null;
|
|
170
|
+
export function setAgentAtHand(ref: string | null, session = false): void {
|
|
171
|
+
agentAtHand = ref ? { ref, session } : null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A `cred` or `settings` command for the agent at hand, as typed where the
|
|
176
|
+
* owner is: `/cred ls` in its session, `cred 286 ls` at the manager,
|
|
177
|
+
* `0g-agentdna cred 286 ls` outside the shell (`<agent>` when no agent is
|
|
178
|
+
* at hand).
|
|
179
|
+
*/
|
|
180
|
+
export function agentCmd(kind: 'cred' | 'settings', rest = ''): string {
|
|
181
|
+
const tail = rest ? ` ${rest}` : '';
|
|
182
|
+
if (agentAtHand?.session) return `/${kind}${tail}`;
|
|
183
|
+
const ref = agentAtHand?.ref ?? '<agent>';
|
|
184
|
+
return surface === 'shell' ? `${kind} ${ref}${tail}` : `0g-agentdna ${kind} ${ref}${tail}`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** A shell-only lifecycle step (`start`, `reset`) for the agent at hand, as
|
|
188
|
+
* a whole sentence: `/reset` in its session, else shellTo's form. */
|
|
189
|
+
export function lifecycleTo(kind: 'start' | 'reset', purpose: string): string {
|
|
190
|
+
if (agentAtHand?.session) return `type \`/${kind}\` to ${purpose}`;
|
|
191
|
+
return shellTo(`${kind} ${agentAtHand?.ref ?? '<agent>'}`, purpose);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** A command that exists both in the shell and as a one-shot command. */
|
|
195
|
+
export function cmdStep(cmd: string): string {
|
|
196
|
+
return surface === 'shell' ? `\`${cmd}\`` : `\`0g-agentdna ${cmd}\``;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** What a question the owner cancelled (Ctrl-C or Esc in the shell) rejects with. */
|
|
200
|
+
export function cancelled(): Error {
|
|
201
|
+
return Object.assign(new Error('cancelled'), { code: 'CANCELLED' });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function isCancelled(e: unknown): boolean {
|
|
205
|
+
return !!e && typeof e === 'object' && (e as { code?: unknown }).code === 'CANCELLED';
|
|
206
|
+
}
|
package/src/cli/inference.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Hash } from 'viem';
|
|
|
3
3
|
import { inferenceKeyFromEnv, loadApiKey } from './config';
|
|
4
4
|
import { CliError } from './errors';
|
|
5
5
|
import { requiresMintFirst } from '../Providers';
|
|
6
|
+
import { storeAfterMint } from '../legacy/modelKey';
|
|
6
7
|
import {
|
|
7
8
|
DEFAULT_PERSONA_INFERENCE, deploymentFactsOf, needsDefaultSettings, storeDefaultSettings,
|
|
8
9
|
type DeploymentFacts,
|
|
@@ -23,9 +24,15 @@ export async function deployWithInference(ag: AgenticID, params: {
|
|
|
23
24
|
description: 'deployed from 0g-agentdna',
|
|
24
25
|
framework: params.framework,
|
|
25
26
|
inference: { provider: params.provider, model: params.model },
|
|
26
|
-
...(params.provision && !mintFirst ? { sandbox: { apiKey: params.apiKey
|
|
27
|
+
...(params.provision && !mintFirst ? { sandbox: { apiKey: params.apiKey } } : {}),
|
|
27
28
|
});
|
|
28
29
|
const mint = await ag.agent.waitForMint(deployment.sealId, { timeoutMs: 180000 });
|
|
30
|
+
// deploy stored the key in the set as it created the agent (a mint-first
|
|
31
|
+
// start stores it itself); an older attestor takes it now.
|
|
32
|
+
const apiKey = params.apiKey;
|
|
33
|
+
if (apiKey && params.provision && !mintFirst) {
|
|
34
|
+
await storeAfterMint(deployment, () => ag.credentials.setModelKey(deployment.sealId, params.provider, apiKey, { push: false }).then(() => true, () => false));
|
|
35
|
+
}
|
|
29
36
|
// A mint-only agent also keeps the chosen pin as its settings document, so
|
|
30
37
|
// the container a later reset starts boots on it whatever happens to the
|
|
31
38
|
// copy in the minted persona.
|