@agentsmarket/cli 0.1.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/README.md +1455 -44
- package/dist/commands/balance.js +3 -3
- package/dist/commands/call.d.ts +23 -1
- package/dist/commands/call.js +187 -45
- package/dist/commands/call.js.map +1 -1
- package/dist/commands/info.d.ts +6 -6
- package/dist/commands/info.js +33 -35
- package/dist/commands/info.js.map +1 -1
- package/dist/commands/init.d.ts +11 -7
- package/dist/commands/init.js +71 -42
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/install.js +2 -2
- package/dist/commands/mcp.js +9 -11
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/pipeline/call.d.ts +18 -0
- package/dist/commands/pipeline/call.js +58 -0
- package/dist/commands/pipeline/call.js.map +1 -0
- package/dist/commands/pipeline/install.d.ts +7 -0
- package/dist/commands/pipeline/install.js +16 -0
- package/dist/commands/pipeline/install.js.map +1 -0
- package/dist/commands/pipeline/publish.d.ts +15 -0
- package/dist/commands/pipeline/publish.js +22 -0
- package/dist/commands/pipeline/publish.js.map +1 -0
- package/dist/commands/publish-openapi.d.ts +16 -0
- package/dist/commands/publish-openapi.js +61 -0
- package/dist/commands/publish-openapi.js.map +1 -0
- package/dist/commands/publish-pipeline.d.ts +15 -0
- package/dist/commands/publish-pipeline.js +141 -0
- package/dist/commands/publish-pipeline.js.map +1 -0
- package/dist/commands/publish.js +37 -42
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/refund.js +15 -17
- package/dist/commands/refund.js.map +1 -1
- package/dist/commands/register.js +6 -27
- package/dist/commands/register.js.map +1 -1
- package/dist/commands/run.d.ts +31 -0
- package/dist/commands/run.js +305 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/scan.js +2 -5
- package/dist/commands/scan.js.map +1 -1
- package/dist/commands/search.js +1 -1
- package/dist/commands/skill/call.d.ts +12 -0
- package/dist/commands/skill/call.js +17 -0
- package/dist/commands/skill/call.js.map +1 -0
- package/dist/commands/skill/install.d.ts +7 -0
- package/dist/commands/skill/install.js +13 -0
- package/dist/commands/skill/install.js.map +1 -0
- package/dist/commands/skill/publish.d.ts +18 -0
- package/dist/commands/skill/publish.js +28 -0
- package/dist/commands/skill/publish.js.map +1 -0
- package/dist/commands/validate.d.ts +20 -0
- package/dist/commands/validate.js +91 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/index.d.ts +4 -6
- package/dist/index.js +90 -29
- package/dist/index.js.map +1 -1
- package/dist/lib/config.d.ts +12 -13
- package/dist/lib/config.js +27 -27
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/http.d.ts +23 -8
- package/dist/lib/http.js +28 -48
- package/dist/lib/http.js.map +1 -1
- package/dist/lib/identity.d.ts +29 -0
- package/dist/lib/identity.js +57 -0
- package/dist/lib/identity.js.map +1 -0
- package/dist/lib/mcp-install.d.ts +36 -0
- package/dist/lib/mcp-install.js +149 -0
- package/dist/lib/mcp-install.js.map +1 -0
- package/dist/lib/pipeline-spec.d.ts +66 -0
- package/dist/lib/pipeline-spec.js +273 -0
- package/dist/lib/pipeline-spec.js.map +1 -0
- package/package.json +12 -4
- package/dist/lib/keys.d.ts +0 -69
- package/dist/lib/keys.js +0 -85
- package/dist/lib/keys.js.map +0 -1
- package/dist/lib/payment-keys.d.ts +0 -25
- package/dist/lib/payment-keys.js +0 -55
- package/dist/lib/payment-keys.js.map +0 -1
- package/dist/lib/payment.d.ts +0 -27
- package/dist/lib/payment.js +0 -123
- package/dist/lib/payment.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
* agentsmarket CLI entry point.
|
|
4
4
|
*
|
|
5
5
|
* Commands:
|
|
6
|
-
* init
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* publish Publish your own skill (from SKILL.md)
|
|
11
|
-
* balance Show current wallet balance in USDT
|
|
6
|
+
* init, register, info, search, rate, mcp, scan, refund, rename, balance
|
|
7
|
+
* skill {install, call, publish, search, grant, grant-list}
|
|
8
|
+
* pipeline {install, call, publish, search}
|
|
9
|
+
* publish-openapi, validate
|
|
12
10
|
*
|
|
13
11
|
* More info: https://agentsmarket.world
|
|
14
12
|
*/
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
* agentsmarket CLI entry point.
|
|
4
4
|
*
|
|
5
5
|
* Commands:
|
|
6
|
-
* init
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* publish Publish your own skill (from SKILL.md)
|
|
11
|
-
* balance Show current wallet balance in USDT
|
|
6
|
+
* init, register, info, search, rate, mcp, scan, refund, rename, balance
|
|
7
|
+
* skill {install, call, publish, search, grant, grant-list}
|
|
8
|
+
* pipeline {install, call, publish, search}
|
|
9
|
+
* publish-openapi, validate
|
|
12
10
|
*
|
|
13
11
|
* More info: https://agentsmarket.world
|
|
14
12
|
*/
|
|
@@ -17,29 +15,85 @@ import { initCommand } from './commands/init.js';
|
|
|
17
15
|
import { infoCommand } from './commands/info.js';
|
|
18
16
|
import { registerCommand } from './commands/register.js';
|
|
19
17
|
import { searchCommand } from './commands/search.js';
|
|
20
|
-
import { callCommand } from './commands/call.js';
|
|
21
|
-
import { publishCommand } from './commands/publish.js';
|
|
22
18
|
import { rateCommand } from './commands/rate.js';
|
|
23
19
|
import { mcpCommand } from './commands/mcp.js';
|
|
24
20
|
import { balanceCommand } from './commands/balance.js';
|
|
25
21
|
import { scanCommand } from './commands/scan.js';
|
|
26
22
|
import { refundCommand } from './commands/refund.js';
|
|
27
|
-
import {
|
|
23
|
+
import { skillInstallCommand } from './commands/skill/install.js';
|
|
24
|
+
import { pipelineInstallCommand } from './commands/pipeline/install.js';
|
|
25
|
+
import { skillCallCommand } from './commands/skill/call.js';
|
|
26
|
+
import { pipelineCallCommand } from './commands/pipeline/call.js';
|
|
27
|
+
import { skillPublishCommand } from './commands/skill/publish.js';
|
|
28
|
+
import { pipelinePublishCommand } from './commands/pipeline/publish.js';
|
|
28
29
|
import { renameCommand } from './commands/rename.js';
|
|
30
|
+
import { publishOpenapiCommand } from './commands/publish-openapi.js';
|
|
31
|
+
import { validateCommand } from './commands/validate.js';
|
|
29
32
|
const program = new Command();
|
|
30
33
|
program
|
|
31
34
|
.name('agentsmarket')
|
|
32
35
|
.description('CLI for agentsmarket.world — manage your AI agent identity, wallet, and skill invocations.\n' +
|
|
33
|
-
'Generate
|
|
36
|
+
'Generate a BIP-39 mnemonic + secp256k1 keypair (Trust Wallet compatible), sign messages via EIP-191, browse and invoke skills from the marketplace.')
|
|
34
37
|
.version('0.1.0');
|
|
35
38
|
program
|
|
36
39
|
.command('init')
|
|
37
|
-
.description('Generate a new
|
|
40
|
+
.description('Generate a new BIP-39 mnemonic + secp256k1 keypair, save it locally, and register on server')
|
|
38
41
|
.action(initCommand);
|
|
39
42
|
program
|
|
40
43
|
.command('register')
|
|
41
44
|
.description('Re-register the current agent on the marketplace server')
|
|
42
45
|
.action(registerCommand);
|
|
46
|
+
// v0.5 entity groups: skill <verb> + pipeline <verb>
|
|
47
|
+
const skillCmd = program
|
|
48
|
+
.command('skill')
|
|
49
|
+
.description('Manage skills: install, call, publish, search, grant');
|
|
50
|
+
skillCmd
|
|
51
|
+
.command('install <slug>')
|
|
52
|
+
.description('Download a skill\'s SKILL.md to your agent\'s skill directory (auto-detected). MCP-first: LLMs/agents should call install_skill MCP tool instead.')
|
|
53
|
+
.action(skillInstallCommand);
|
|
54
|
+
skillCmd
|
|
55
|
+
.command('call <slug>')
|
|
56
|
+
.description('Invoke a skill by slug. Auto-signs Variant D on 402 (default). Use --no-auto-sign to fall back to manual --payment-tx-hash flow.')
|
|
57
|
+
.option('--payment-tx-hash <hex>', 'on-chain USDC tx hash (legacy flow; required only with --no-auto-sign)')
|
|
58
|
+
.option('--inputs <json>', 'JSON inputs, e.g. \'{"topic":"x"}\'')
|
|
59
|
+
.option('--no-auto-sign', 'Skip Variant D auto-signing; require manual --payment-tx-hash (default: auto-sign on 402)')
|
|
60
|
+
.action(skillCallCommand);
|
|
61
|
+
skillCmd
|
|
62
|
+
.command('publish <file>')
|
|
63
|
+
.description('Publish a SKILL.md to the marketplace (parses YAML frontmatter). v0.5 auto-detect: same version+hash → metadata update; use --bump-version or --metadata-only to override.')
|
|
64
|
+
.option('--bump-version <level>', 'Force version bump: patch | minor | major (resolves content-hash conflicts)')
|
|
65
|
+
.option('--metadata-only', 'Force metadata-only update (no new row)')
|
|
66
|
+
.action((filePath, opts) => skillPublishCommand(filePath, {
|
|
67
|
+
bumpVersion: opts.bumpVersion,
|
|
68
|
+
metadataOnly: !!opts.metadataOnly,
|
|
69
|
+
}));
|
|
70
|
+
const pipelineCmd = program
|
|
71
|
+
.command('pipeline')
|
|
72
|
+
.description('Manage pipelines: install, call (with --local / --mock), publish, search');
|
|
73
|
+
pipelineCmd
|
|
74
|
+
.command('install <slug>')
|
|
75
|
+
.description('Download a pipeline\'s pipeline.yaml. STUB until R16 ships /v1/pipelines/:id/yaml route.')
|
|
76
|
+
.action(pipelineInstallCommand);
|
|
77
|
+
pipelineCmd
|
|
78
|
+
.command('call <slug>')
|
|
79
|
+
.description('Invoke a pipeline by slug. Server mode (no flag) STUB until R16. --local runs via runCommand; --mock dry-runs without API calls.')
|
|
80
|
+
.option('--local', 'Execute locally via CLI (requires pipeline.yaml in install dir or --file)')
|
|
81
|
+
.option('--mock', 'Dry-run with mock provider (no LLM API calls; implies --local if no --file)')
|
|
82
|
+
.option('--inputs <json>', 'JSON inputs, e.g. \'{"name":"Alice"}\'')
|
|
83
|
+
.option('--model <name>', 'Override default model for all stages (local mode only)')
|
|
84
|
+
.option('--api-key <key>', 'DEPRECATED: pass LLM keys via env (${MINIMAX_API_KEY:-default}); kept for backward compat')
|
|
85
|
+
.option('--file <path>', 'Explicit path to pipeline.yaml (local mode only)')
|
|
86
|
+
.option('--no-color', 'Disable ANSI color output')
|
|
87
|
+
.action(pipelineCallCommand);
|
|
88
|
+
pipelineCmd
|
|
89
|
+
.command('publish <file>')
|
|
90
|
+
.description('Publish a pipeline.yaml to the marketplace (parses # metadata header + stages: body). v0.5 auto-detect: same version+hash → metadata update; use --bump-version or --metadata-only to override.')
|
|
91
|
+
.option('--bump-version <level>', 'Force version bump: patch | minor | major (resolves content-hash conflicts)')
|
|
92
|
+
.option('--metadata-only', 'Force metadata-only update (no new row)')
|
|
93
|
+
.action((filePath, opts) => pipelinePublishCommand(filePath, {
|
|
94
|
+
bumpVersion: opts.bumpVersion,
|
|
95
|
+
metadataOnly: !!opts.metadataOnly,
|
|
96
|
+
}));
|
|
43
97
|
program
|
|
44
98
|
.command('info')
|
|
45
99
|
.description('Show current agent identity, network, and config locations')
|
|
@@ -55,18 +109,6 @@ program
|
|
|
55
109
|
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
56
110
|
});
|
|
57
111
|
});
|
|
58
|
-
program
|
|
59
|
-
.command('call <skill_id>')
|
|
60
|
-
.description('Invoke a skill by ID (handles signing + payment automatically)')
|
|
61
|
-
.action(async (skillId) => {
|
|
62
|
-
await callCommand(skillId, {});
|
|
63
|
-
});
|
|
64
|
-
program
|
|
65
|
-
.command('publish <path>')
|
|
66
|
-
.description('Publish a SKILL.md to the marketplace (parses YAML frontmatter)')
|
|
67
|
-
.action(async (filePath) => {
|
|
68
|
-
await publishCommand(filePath);
|
|
69
|
-
});
|
|
70
112
|
program
|
|
71
113
|
.command('rate <skill_id> <rating>')
|
|
72
114
|
.description('Rate a purchased skill (1-5). Requires prior purchase within 30 days.')
|
|
@@ -92,22 +134,41 @@ program
|
|
|
92
134
|
.action(async (purchaseId) => {
|
|
93
135
|
await refundCommand(purchaseId);
|
|
94
136
|
});
|
|
95
|
-
program
|
|
96
|
-
.command('install <skill_id>')
|
|
97
|
-
.description('Download a skill\'s SKILL.md and write it to your agent\'s skill directory (auto-detected). MCP-first: LLMs/agents should call install_skill MCP tool instead, since they know where they live.')
|
|
98
|
-
.action(async (skillId) => {
|
|
99
|
-
await installCommand(skillId);
|
|
100
|
-
});
|
|
101
137
|
program
|
|
102
138
|
.command('rename <display_name>')
|
|
103
139
|
.description('Set human-readable name for current agent (max 80 chars). Shown in skill listings + author profile.')
|
|
104
140
|
.action(async (newName) => {
|
|
105
141
|
await renameCommand(newName);
|
|
106
142
|
});
|
|
143
|
+
program
|
|
144
|
+
.command('publish-openapi <source>')
|
|
145
|
+
.description('Generate SKILL.md files from an OpenAPI spec (URL or file path). With --publish, auto-publishes all to marketplace.')
|
|
146
|
+
.option('--api-name <name>', 'API name (default: api)')
|
|
147
|
+
.option('--output <dir>', 'Output directory (default: ./generated/<api-name>/)')
|
|
148
|
+
.option('--price <micro-usdc>', 'Default price per child skill in micro-USDC (default: 1000 = $0.001)', '1000')
|
|
149
|
+
.option('--author-name <name>', 'Author display name (default: api-name)')
|
|
150
|
+
.option('--max-endpoints <n>', 'Limit number of endpoints to process')
|
|
151
|
+
.option('--include-tag <tag>', 'Only include endpoints with this OpenAPI tag (repeatable)')
|
|
152
|
+
.option('--exclude-path <regex>', 'Exclude paths matching this regex')
|
|
153
|
+
.option('--publish', 'Auto-publish all generated SKILL.md to the marketplace')
|
|
154
|
+
.option('--publish-dry-run', 'Preview what would be published (no actual network calls)')
|
|
155
|
+
.option('--publish-url <url>', 'Override API base URL (default: env AGENTSMARKET_URL or https://api.agentsmarket.world)')
|
|
156
|
+
.option('--batch-size <n>', 'Concurrent publish requests (default: 5)', '5')
|
|
157
|
+
.option('--skip-on-error', 'Continue on individual publish errors instead of aborting')
|
|
158
|
+
.action(async (source, opts) => {
|
|
159
|
+
await publishOpenapiCommand(source, opts);
|
|
160
|
+
});
|
|
107
161
|
program
|
|
108
162
|
.command('balance')
|
|
109
163
|
.description('Show current wallet balance in USDT')
|
|
110
164
|
.action(balanceCommand);
|
|
165
|
+
program
|
|
166
|
+
.command('validate <pipeline.yaml>')
|
|
167
|
+
.description('Validate pipeline.yaml without executing. Exit 0 if valid, 1 otherwise.')
|
|
168
|
+
.option('--json', 'Output as JSON instead of human-readable')
|
|
169
|
+
.action(async (filePath, opts) => {
|
|
170
|
+
await validateCommand(filePath, { json: !!opts.json });
|
|
171
|
+
});
|
|
111
172
|
program.parseAsync(process.argv).catch((err) => {
|
|
112
173
|
console.error('✗ ' + (err instanceof Error ? err.message : String(err)));
|
|
113
174
|
process.exit(1);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,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AC,CAAC;AAC5C,CAAC,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,qCAAqC,CAAC;KAClD,MAAM,CAAC,cAAc,CAAC,CAAC;AAE1B,OAAO;KACJ,OAAO,CAAC,0BAA0B,CAAC;KACnC,WAAW,CAAC,yEAAyE,CAAC;KACtF,MAAM,CAAC,QAAQ,EAAE,0CAA0C,CAAC;KAC5D,MAAM,CAAC,KAAK,EAAE,QAAgB,EAAE,IAAwB,EAAE,EAAE;IAC3D,MAAM,eAAe,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IAC7C,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -3,35 +3,34 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Stores agent identity + network preference in ~/.config/agentsmarket/
|
|
5
5
|
*
|
|
6
|
+
* Storage layout:
|
|
7
|
+
* mnemonic.txt — 12-word BIP-39 phrase (primary backup, import to Trust Wallet)
|
|
8
|
+
* agent.key — secp256k1 private key hex (convenience, derived from mnemonic)
|
|
9
|
+
* config.json — public info (agent_id, network, created_at)
|
|
10
|
+
*
|
|
6
11
|
* MVP: file-based storage with 0700 dir / 0600 file permissions.
|
|
7
12
|
* Production: migrate to OS keychain (macOS Keychain / Linux libsecret /
|
|
8
13
|
* Windows Credential Manager) via @napi-rs/keyring.
|
|
9
14
|
*/
|
|
10
15
|
export type Network = 'base-sepolia' | 'base-mainnet';
|
|
11
16
|
export interface Config {
|
|
12
|
-
/**
|
|
17
|
+
/** EVM address (0x-prefixed, 40 hex chars). Used for signing + USDC payments. */
|
|
13
18
|
agent_id: string;
|
|
14
|
-
/** secp256k1 payment address (0x-prefixed). Used for EIP-3009 USDC payments. */
|
|
15
|
-
payment_address: string;
|
|
16
19
|
/** Blockchain network. MVP: only base-sepolia supported. */
|
|
17
20
|
network: Network;
|
|
18
21
|
/** ISO 8601 timestamp of agent creation. */
|
|
19
22
|
created_at: string;
|
|
20
23
|
}
|
|
21
|
-
/** Returns ~/.config/agentsmarket (platform-correct home dir). */
|
|
22
24
|
export declare function getConfigDir(): string;
|
|
23
25
|
export declare function getKeyPath(): string;
|
|
24
|
-
export declare function
|
|
26
|
+
export declare function getMnemonicPath(): string;
|
|
25
27
|
export declare function getConfigPath(): string;
|
|
26
|
-
/** Returns existing config or null. */
|
|
27
28
|
export declare function loadConfig(): Config | null;
|
|
28
|
-
/** Save config file with 0600 permissions. Creates parent dir if needed. */
|
|
29
29
|
export declare function saveConfig(config: Config): void;
|
|
30
|
-
|
|
31
|
-
export declare function
|
|
32
|
-
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function loadPaymentKeyPem(): string;
|
|
30
|
+
export declare function savePrivateKey(hexPrivateKey: string): void;
|
|
31
|
+
export declare function loadPrivateKeyHex(): string;
|
|
32
|
+
export declare function saveMnemonic(mnemonic: string): void;
|
|
33
|
+
export declare function loadMnemonic(): string;
|
|
35
34
|
export declare function configExists(): boolean;
|
|
36
35
|
export declare function keyExists(): boolean;
|
|
37
|
-
export declare function
|
|
36
|
+
export declare function mnemonicExists(): boolean;
|
package/dist/lib/config.js
CHANGED
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Stores agent identity + network preference in ~/.config/agentsmarket/
|
|
5
5
|
*
|
|
6
|
+
* Storage layout:
|
|
7
|
+
* mnemonic.txt — 12-word BIP-39 phrase (primary backup, import to Trust Wallet)
|
|
8
|
+
* agent.key — secp256k1 private key hex (convenience, derived from mnemonic)
|
|
9
|
+
* config.json — public info (agent_id, network, created_at)
|
|
10
|
+
*
|
|
6
11
|
* MVP: file-based storage with 0700 dir / 0600 file permissions.
|
|
7
12
|
* Production: migrate to OS keychain (macOS Keychain / Linux libsecret /
|
|
8
13
|
* Windows Credential Manager) via @napi-rs/keyring.
|
|
@@ -12,9 +17,8 @@ import * as path from 'node:path';
|
|
|
12
17
|
import * as os from 'node:os';
|
|
13
18
|
const CONFIG_DIR_NAME = 'agentsmarket';
|
|
14
19
|
const KEY_FILE_NAME = 'agent.key';
|
|
15
|
-
const
|
|
20
|
+
const MNEMONIC_FILE_NAME = 'mnemonic.txt';
|
|
16
21
|
const CONFIG_FILE_NAME = 'config.json';
|
|
17
|
-
/** Returns ~/.config/agentsmarket (platform-correct home dir). */
|
|
18
22
|
export function getConfigDir() {
|
|
19
23
|
const home = os.homedir();
|
|
20
24
|
if (process.platform === 'win32') {
|
|
@@ -23,28 +27,23 @@ export function getConfigDir() {
|
|
|
23
27
|
if (process.platform === 'darwin') {
|
|
24
28
|
return path.join(home, 'Library', 'Application Support', CONFIG_DIR_NAME);
|
|
25
29
|
}
|
|
26
|
-
// Linux / Unix — XDG default
|
|
27
30
|
const xdgConfig = process.env.XDG_CONFIG_HOME ?? path.join(home, '.config');
|
|
28
31
|
return path.join(xdgConfig, CONFIG_DIR_NAME);
|
|
29
32
|
}
|
|
30
33
|
export function getKeyPath() {
|
|
31
34
|
return path.join(getConfigDir(), KEY_FILE_NAME);
|
|
32
35
|
}
|
|
33
|
-
export function
|
|
34
|
-
return path.join(getConfigDir(),
|
|
36
|
+
export function getMnemonicPath() {
|
|
37
|
+
return path.join(getConfigDir(), MNEMONIC_FILE_NAME);
|
|
35
38
|
}
|
|
36
39
|
export function getConfigPath() {
|
|
37
40
|
return path.join(getConfigDir(), CONFIG_FILE_NAME);
|
|
38
41
|
}
|
|
39
|
-
/** Returns existing config or null. */
|
|
40
42
|
export function loadConfig() {
|
|
41
43
|
try {
|
|
42
44
|
const content = fs.readFileSync(getConfigPath(), 'utf-8');
|
|
43
45
|
const parsed = JSON.parse(content);
|
|
44
|
-
if (typeof parsed.agent_id !== 'string' ||
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
if (typeof parsed.payment_address !== 'string' || !/^0x[0-9a-fA-F]{40}$/.test(parsed.payment_address)) {
|
|
46
|
+
if (typeof parsed.agent_id !== 'string' || !/^0x[0-9a-fA-F]{40}$/.test(parsed.agent_id)) {
|
|
48
47
|
return null;
|
|
49
48
|
}
|
|
50
49
|
if (parsed.network !== 'base-sepolia' && parsed.network !== 'base-mainnet') {
|
|
@@ -59,7 +58,6 @@ export function loadConfig() {
|
|
|
59
58
|
return null;
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
|
-
/** Save config file with 0600 permissions. Creates parent dir if needed. */
|
|
63
61
|
export function saveConfig(config) {
|
|
64
62
|
const dir = getConfigDir();
|
|
65
63
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
@@ -68,26 +66,29 @@ export function saveConfig(config) {
|
|
|
68
66
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', { mode: 0o600 });
|
|
69
67
|
setPermissions(configPath, 0o600);
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
export function savePrivateKey(pem) {
|
|
69
|
+
export function savePrivateKey(hexPrivateKey) {
|
|
73
70
|
const dir = getConfigDir();
|
|
74
71
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
75
72
|
setPermissions(dir, 0o700);
|
|
76
73
|
const keyPath = getKeyPath();
|
|
77
|
-
|
|
74
|
+
const normalized = hexPrivateKey.startsWith('0x') ? hexPrivateKey : '0x' + hexPrivateKey;
|
|
75
|
+
fs.writeFileSync(keyPath, normalized + '\n', { mode: 0o600 });
|
|
78
76
|
setPermissions(keyPath, 0o600);
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
export function loadPrivateKeyHex() {
|
|
79
|
+
const content = fs.readFileSync(getKeyPath(), 'utf-8').trim();
|
|
80
|
+
return content.startsWith('0x') ? content : '0x' + content;
|
|
81
|
+
}
|
|
82
|
+
export function saveMnemonic(mnemonic) {
|
|
82
83
|
const dir = getConfigDir();
|
|
83
84
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
84
85
|
setPermissions(dir, 0o700);
|
|
85
|
-
const
|
|
86
|
-
fs.writeFileSync(
|
|
87
|
-
setPermissions(
|
|
86
|
+
const mnemonicPath = getMnemonicPath();
|
|
87
|
+
fs.writeFileSync(mnemonicPath, mnemonic.trim() + '\n', { mode: 0o600 });
|
|
88
|
+
setPermissions(mnemonicPath, 0o600);
|
|
88
89
|
}
|
|
89
|
-
export function
|
|
90
|
-
return fs.readFileSync(
|
|
90
|
+
export function loadMnemonic() {
|
|
91
|
+
return fs.readFileSync(getMnemonicPath(), 'utf-8').trim();
|
|
91
92
|
}
|
|
92
93
|
export function configExists() {
|
|
93
94
|
return fs.existsSync(getConfigPath());
|
|
@@ -95,18 +96,17 @@ export function configExists() {
|
|
|
95
96
|
export function keyExists() {
|
|
96
97
|
return fs.existsSync(getKeyPath());
|
|
97
98
|
}
|
|
98
|
-
export function
|
|
99
|
-
return fs.existsSync(
|
|
99
|
+
export function mnemonicExists() {
|
|
100
|
+
return fs.existsSync(getMnemonicPath());
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
-
function setPermissions(path, mode) {
|
|
102
|
+
function setPermissions(filePath, mode) {
|
|
103
103
|
if (process.platform === 'win32')
|
|
104
104
|
return;
|
|
105
105
|
try {
|
|
106
|
-
fs.chmodSync(
|
|
106
|
+
fs.chmodSync(filePath, mode);
|
|
107
107
|
}
|
|
108
108
|
catch {
|
|
109
|
-
//
|
|
109
|
+
// best effort
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
//# sourceMappingURL=config.js.map
|
package/dist/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAa9B,MAAM,eAAe,GAAG,cAAc,CAAC;AACvC,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAC1C,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAEvC,MAAM,UAAU,YAAY;IAC1B,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC1B,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,qBAAqB,EAAE,eAAe,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC5E,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,aAAa,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU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AAY,GAAG,eAAe,EAAE,CAAC;IACvC,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACxE,cAAc,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,EAAE,CAAC,UAAU,CAAC,eAAe,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,cAAc,CAAC,QAAgB,EAAE,IAAY;IACpD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO;IACzC,IAAI,CAAC;QACH,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,cAAc;IAChB,CAAC;AACH,CAAC"}
|
package/dist/lib/http.d.ts
CHANGED
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Authenticated HTTP client for the marketplace server.
|
|
3
3
|
*
|
|
4
|
-
* Signs
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Signs requests with EIP-191 personal_sign using the agent's secp256k1 key.
|
|
5
|
+
* Server uses ecrecover to determine caller address.
|
|
6
|
+
*
|
|
7
|
+
* Headers (when requireAuth=true, the default):
|
|
8
|
+
* X-Signature: 0x + 130 hex (65-byte EIP-191 sig: r||s||v)
|
|
9
|
+
* X-Timestamp: unix ms (within 5 min drift)
|
|
9
10
|
* Message: METHOD\nPATH\nTIMESTAMP\nSHA256(BODY)
|
|
11
|
+
*
|
|
12
|
+
* Note: caller address is derived from signature on server side
|
|
13
|
+
* (no X-Agent-ID header needed).
|
|
10
14
|
*/
|
|
15
|
+
export interface ErrorBody {
|
|
16
|
+
error?: string;
|
|
17
|
+
code?: string;
|
|
18
|
+
detail?: string;
|
|
19
|
+
recipient?: string;
|
|
20
|
+
price_usdc?: number;
|
|
21
|
+
chain_id?: number;
|
|
22
|
+
token_address?: string;
|
|
23
|
+
mode?: string;
|
|
24
|
+
hint?: string;
|
|
25
|
+
agent_id?: string;
|
|
26
|
+
}
|
|
11
27
|
export declare class HttpError extends Error {
|
|
12
28
|
readonly status: number;
|
|
13
29
|
readonly code: string;
|
|
14
|
-
|
|
30
|
+
readonly body: ErrorBody;
|
|
31
|
+
constructor(status: number, code: string, message: string, body?: ErrorBody);
|
|
15
32
|
}
|
|
16
|
-
/** Make an authenticated request to the marketplace server. */
|
|
17
33
|
export declare function authedFetch(method: string, path: string, body?: unknown, opts?: {
|
|
18
34
|
baseUrl?: string;
|
|
19
35
|
requireAuth?: boolean;
|
|
20
36
|
}): Promise<Response>;
|
|
21
|
-
/** Convenience: authed JSON request, returns parsed body. */
|
|
22
37
|
export declare function authedJson<T>(method: string, path: string, body?: unknown, opts?: {
|
|
23
38
|
baseUrl?: string;
|
|
24
39
|
requireAuth?: boolean;
|
package/dist/lib/http.js
CHANGED
|
@@ -1,66 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Authenticated HTTP client for the marketplace server.
|
|
3
3
|
*
|
|
4
|
-
* Signs
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Signs requests with EIP-191 personal_sign using the agent's secp256k1 key.
|
|
5
|
+
* Server uses ecrecover to determine caller address.
|
|
6
|
+
*
|
|
7
|
+
* Headers (when requireAuth=true, the default):
|
|
8
|
+
* X-Signature: 0x + 130 hex (65-byte EIP-191 sig: r||s||v)
|
|
9
|
+
* X-Timestamp: unix ms (within 5 min drift)
|
|
9
10
|
* Message: METHOD\nPATH\nTIMESTAMP\nSHA256(BODY)
|
|
11
|
+
*
|
|
12
|
+
* Note: caller address is derived from signature on server side
|
|
13
|
+
* (no X-Agent-ID header needed).
|
|
10
14
|
*/
|
|
11
|
-
import * as crypto from 'node:crypto';
|
|
12
15
|
import { createHash } from 'node:crypto';
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import * as path from 'node:path';
|
|
16
|
-
import { loadConfig } from './config.js';
|
|
17
|
-
import { loadPrivateKey, exportPublicKeyRaw } from './keys.js';
|
|
18
|
-
// Override at runtime with AGENTSMARKET_URL env var (used by smoke.sh, tests, dev).
|
|
16
|
+
import { loadConfig, loadPrivateKeyHex } from './config.js';
|
|
17
|
+
import { signEip191 } from './identity.js';
|
|
19
18
|
const DEFAULT_BASE_URL = 'https://api.agentsmarket.world';
|
|
20
19
|
export class HttpError extends Error {
|
|
21
20
|
status;
|
|
22
21
|
code;
|
|
23
|
-
|
|
22
|
+
body;
|
|
23
|
+
constructor(status, code, message, body = {}) {
|
|
24
24
|
super(message);
|
|
25
25
|
this.status = status;
|
|
26
26
|
this.code = code;
|
|
27
27
|
this.name = 'HttpError';
|
|
28
|
+
this.body = body;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
function
|
|
31
|
-
const home = os.homedir();
|
|
32
|
-
if (process.platform === 'win32') {
|
|
33
|
-
return path.join(home, 'AppData', 'Roaming', 'agentsmarket', 'agent.key');
|
|
34
|
-
}
|
|
35
|
-
if (process.platform === 'darwin') {
|
|
36
|
-
return path.join(home, 'Library', 'Application Support', 'agentsmarket', 'agent.key');
|
|
37
|
-
}
|
|
38
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME ?? path.join(home, '.config');
|
|
39
|
-
return path.join(xdgConfig, 'agentsmarket', 'agent.key');
|
|
40
|
-
}
|
|
41
|
-
function getSigningKey() {
|
|
42
|
-
const config = loadConfig();
|
|
43
|
-
if (!config) {
|
|
44
|
-
throw new Error('Agent not initialized. Run `agentsmarket init` first.');
|
|
45
|
-
}
|
|
46
|
-
const pem = fs.readFileSync(getKeyPath(), 'utf-8');
|
|
47
|
-
const privateKey = loadPrivateKey(pem);
|
|
48
|
-
const publicKey = crypto.createPublicKey(privateKey);
|
|
49
|
-
const raw = exportPublicKeyRaw(publicKey);
|
|
50
|
-
const derivedId = 'ed25519:' + raw.toString('base64url');
|
|
51
|
-
if (derivedId !== config.agent_id) {
|
|
52
|
-
throw new Error(`Key file does not match stored agent_id. Stored: ${config.agent_id}, Derived: ${derivedId}`);
|
|
53
|
-
}
|
|
54
|
-
return { privateKey, agentId: config.agent_id };
|
|
55
|
-
}
|
|
56
|
-
function signRequest(privateKey, method, path, body) {
|
|
31
|
+
async function signRequest(privateKeyHex, method, path, body) {
|
|
57
32
|
const timestamp = Date.now().toString();
|
|
58
33
|
const bodyHash = createHash('sha256').update(body || '').digest('hex');
|
|
59
34
|
const message = `${method}\n${path}\n${timestamp}\n${bodyHash}`;
|
|
60
|
-
const
|
|
61
|
-
return { signature
|
|
35
|
+
const { signature, address } = await signEip191(privateKeyHex, message);
|
|
36
|
+
return { signature, timestamp, address };
|
|
62
37
|
}
|
|
63
|
-
/** Make an authenticated request to the marketplace server. */
|
|
64
38
|
export async function authedFetch(method, path, body, opts = {}) {
|
|
65
39
|
const baseUrl = (opts.baseUrl ?? process.env.AGENTSMARKET_URL ?? DEFAULT_BASE_URL).replace(/\/$/, '');
|
|
66
40
|
const bodyStr = body !== undefined ? JSON.stringify(body) : '';
|
|
@@ -69,9 +43,12 @@ export async function authedFetch(method, path, body, opts = {}) {
|
|
|
69
43
|
'Content-Type': 'application/json',
|
|
70
44
|
};
|
|
71
45
|
if (opts.requireAuth !== false) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
46
|
+
const config = loadConfig();
|
|
47
|
+
if (!config) {
|
|
48
|
+
throw new Error('Agent not initialized. Run `agentsmarket init` first.');
|
|
49
|
+
}
|
|
50
|
+
const privateKey = loadPrivateKeyHex();
|
|
51
|
+
const { signature, timestamp } = await signRequest(privateKey, method, path, bodyStr);
|
|
75
52
|
headers['X-Signature'] = signature;
|
|
76
53
|
headers['X-Timestamp'] = timestamp;
|
|
77
54
|
}
|
|
@@ -83,21 +60,24 @@ export async function authedFetch(method, path, body, opts = {}) {
|
|
|
83
60
|
if (!res.ok) {
|
|
84
61
|
let code = 'UNKNOWN';
|
|
85
62
|
let message = `HTTP ${res.status}`;
|
|
63
|
+
const body = {};
|
|
86
64
|
try {
|
|
87
65
|
const parsed = await res.json();
|
|
66
|
+
Object.assign(body, parsed);
|
|
88
67
|
if (parsed.code)
|
|
89
68
|
code = parsed.code;
|
|
90
69
|
if (parsed.error)
|
|
91
70
|
message = `${parsed.code ?? 'UNKNOWN'}: ${parsed.error}`;
|
|
71
|
+
if (parsed.detail)
|
|
72
|
+
message += ` (${parsed.detail})`;
|
|
92
73
|
}
|
|
93
74
|
catch {
|
|
94
75
|
// not JSON
|
|
95
76
|
}
|
|
96
|
-
throw new HttpError(res.status, code, message);
|
|
77
|
+
throw new HttpError(res.status, code, message, body);
|
|
97
78
|
}
|
|
98
79
|
return res;
|
|
99
80
|
}
|
|
100
|
-
/** Convenience: authed JSON request, returns parsed body. */
|
|
101
81
|
export async function authedJson(method, path, body, opts) {
|
|
102
82
|
const res = await authedFetch(method, path, body, opts);
|
|
103
83
|
return await res.json();
|
package/dist/lib/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UA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