@techdigger/humanode-agentlink-cli 0.3.3 → 0.3.4

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.
@@ -0,0 +1,23 @@
1
+ import type { Hex } from 'viem';
2
+ import { type EnvSource, type NetworkName } from '../lib/core.js';
3
+ export interface RequestOptions {
4
+ url: string;
5
+ method: string;
6
+ network: NetworkName;
7
+ count: number;
8
+ json: boolean;
9
+ privateKey: Hex;
10
+ }
11
+ export interface RequestResult {
12
+ request: number;
13
+ status: number;
14
+ body: string;
15
+ }
16
+ export interface RequestDeps {
17
+ fetchImpl: typeof fetch;
18
+ }
19
+ export declare function parseRequestOptions(argv: string[], env: EnvSource, overrides?: {
20
+ privateKey?: string;
21
+ }): RequestOptions;
22
+ export declare function runRequest(options: RequestOptions, deps?: Partial<RequestDeps>): Promise<RequestResult[]>;
23
+ export declare function formatRequestOutput(results: RequestResult[], json: boolean): string;
@@ -0,0 +1,89 @@
1
+ import { SiweMessage } from 'siwe';
2
+ import { privateKeyToAccount } from 'viem/accounts';
3
+ import { CliError, NETWORKS, assertNoExtraPositionals, parseFlags, resolveNetwork, resolvePrivateKey, } from '../lib/core.js';
4
+ export function parseRequestOptions(argv, env, overrides = {}) {
5
+ const parsed = parseFlags(argv);
6
+ if (parsed.positionals.length === 0) {
7
+ throw new CliError('Missing URL. Usage: agentlink request <url> [options]');
8
+ }
9
+ assertNoExtraPositionals('request', parsed.positionals.slice(1));
10
+ const url = parsed.positionals[0];
11
+ try {
12
+ new URL(url);
13
+ }
14
+ catch {
15
+ throw new CliError(`Invalid URL: "${url}"`);
16
+ }
17
+ const countRaw = parsed.values.count;
18
+ const count = countRaw ? parseInt(countRaw, 10) : 1;
19
+ if (isNaN(count) || count < 1) {
20
+ throw new CliError(`--count must be a positive integer, got "${countRaw}"`);
21
+ }
22
+ const network = resolveNetwork(parsed.values.network, env);
23
+ return {
24
+ url,
25
+ method: (parsed.values.method ?? 'GET').toUpperCase(),
26
+ network,
27
+ count,
28
+ json: parsed.flags.has('json'),
29
+ privateKey: resolvePrivateKey(parsed.values['private-key'], env, overrides.privateKey),
30
+ };
31
+ }
32
+ async function buildAgentLinkHeader(privateKey, url, network) {
33
+ const account = privateKeyToAccount(privateKey);
34
+ const parsed = new URL(url);
35
+ const chainId = NETWORKS[network].chainId;
36
+ const nonce = Math.random().toString(36).slice(2) + Date.now().toString(36);
37
+ const issuedAt = new Date().toISOString();
38
+ const siwe = new SiweMessage({
39
+ domain: parsed.hostname,
40
+ address: account.address,
41
+ uri: url,
42
+ version: '1',
43
+ chainId,
44
+ nonce,
45
+ issuedAt,
46
+ statement: 'Agentlink access request',
47
+ });
48
+ const message = siwe.prepareMessage();
49
+ const signature = await account.signMessage({ message });
50
+ const payload = {
51
+ domain: parsed.hostname,
52
+ address: account.address,
53
+ statement: 'Agentlink access request',
54
+ uri: url,
55
+ version: '1',
56
+ chainId: `eip155:${chainId}`,
57
+ type: 'eip191',
58
+ nonce,
59
+ issuedAt,
60
+ signature,
61
+ };
62
+ return Buffer.from(JSON.stringify(payload)).toString('base64');
63
+ }
64
+ export async function runRequest(options, deps = {}) {
65
+ const fetchImpl = deps.fetchImpl ?? fetch;
66
+ const results = [];
67
+ for (let i = 1; i <= options.count; i++) {
68
+ const agentlinkHeader = await buildAgentLinkHeader(options.privateKey, options.url, options.network);
69
+ let response;
70
+ try {
71
+ response = await fetchImpl(new Request(options.url, {
72
+ method: options.method,
73
+ headers: { agentlink: agentlinkHeader },
74
+ }));
75
+ }
76
+ catch (error) {
77
+ throw new CliError(`Request ${i} failed: ${error instanceof Error ? error.message : String(error)}`);
78
+ }
79
+ const body = await response.text();
80
+ results.push({ request: i, status: response.status, body });
81
+ }
82
+ return results;
83
+ }
84
+ export function formatRequestOutput(results, json) {
85
+ if (json) {
86
+ return JSON.stringify(results, null, 2);
87
+ }
88
+ return results.map(r => `Request ${r.request} ${r.status} ${r.body.slice(0, 200)}`).join('\n');
89
+ }
package/dist/help.d.ts CHANGED
@@ -3,4 +3,5 @@ export declare function getKeystoreHelpText(): string;
3
3
  export declare function getAuthorizeLinkHelpText(): string;
4
4
  export declare function getStatusHelpText(): string;
5
5
  export declare function getLinkHelpText(): string;
6
+ export declare function getRequestHelpText(): string;
6
7
  export declare function getInitHelpText(): string;
package/dist/help.js CHANGED
@@ -7,6 +7,7 @@ Commands:
7
7
  link Generate consent and open a linker URL for owner approval
8
8
  authorize-link Generate a one-time EIP-712 consent blob for manual linking
9
9
  status Check whether an agent is linked and active
10
+ request Send a signed agentlink request to a protected endpoint
10
11
 
11
12
  Flags:
12
13
  --help, -h Show this help text
@@ -108,6 +109,32 @@ Options:
108
109
  --help Show this help message
109
110
  `;
110
111
  }
112
+ export function getRequestHelpText() {
113
+ return `Usage:
114
+ agentlink request <url> [options]
115
+
116
+ Description:
117
+ Send a signed agentlink request to a URL. Builds a SIWE payload signed with
118
+ your agent wallet, attaches it as the "agentlink" header, and prints the
119
+ response. Use --count to repeat the request (e.g. to test free-trial limits).
120
+
121
+ Options:
122
+ --method HTTP method (default: GET)
123
+ --count Number of times to send the request (default: 1)
124
+ --network base | base-sepolia (default: BIOMAPPER_NETWORK or base-sepolia)
125
+ --private-key-stdin Read the agent private key from stdin
126
+ --private-key Dev-only: pass key directly as 0x-prefixed hex
127
+ --json Output results as JSON
128
+ --help Show this help message
129
+
130
+ Key resolution order: keystore (default) → --private-key-stdin → --private-key → AGENT_PRIVATE_KEY env
131
+
132
+ Examples:
133
+ agentlink request http://localhost:3000/data
134
+ agentlink request http://75.119.141.48:3000/data --count 4
135
+ agentlink request https://api.example.com/resource --method POST --network base
136
+ `;
137
+ }
111
138
  export function getInitHelpText() {
112
139
  return `Usage:
113
140
  agentlink init [dir] [options]
package/dist/index.d.ts CHANGED
@@ -13,5 +13,6 @@ export interface CliRuntime {
13
13
  openUrl: (url: string) => Promise<void>;
14
14
  readStdin: () => Promise<string>;
15
15
  readPassword: (prompt: string) => Promise<string>;
16
+ fetchImpl: typeof fetch;
16
17
  }
17
18
  export declare function runCli(argv?: string[], overrides?: Partial<CliRuntime>): Promise<number>;
package/dist/index.js CHANGED
@@ -6,10 +6,11 @@ import { formatInitOutput, parseInitOptions, runInit } from './commands/init.js'
6
6
  import { formatLinkOutput, parseLinkOptions, runLink } from './commands/link.js';
7
7
  import { formatStatusOutput, parseStatusOptions, runStatus } from './commands/status.js';
8
8
  import { parseAuthorizeLinkOptions, runAuthorizeLink } from './commands/authorize-link.js';
9
+ import { formatRequestOutput, parseRequestOptions, runRequest } from './commands/request.js';
9
10
  import { runKeystoreAddress, runKeystoreDelete, runKeystoreSet } from './commands/keystore.js';
10
11
  import { CliError, formatJson, loadEnvFiles, openUrlInBrowser, parseFlags, readAllFromStdin, readPassword } from './lib/core.js';
11
12
  import { decryptKeystore, keystoreExists, keystorePath } from './lib/keystore.js';
12
- import { getAuthorizeLinkHelpText, getInitHelpText, getKeystoreHelpText, getLinkHelpText, getRootHelpText, getStatusHelpText, } from './help.js';
13
+ import { getAuthorizeLinkHelpText, getInitHelpText, getKeystoreHelpText, getLinkHelpText, getRequestHelpText, getRootHelpText, getStatusHelpText, } from './help.js';
13
14
  import { VERSION } from './version.js';
14
15
  import { buildEmbeddedHostedLinkUrl, createAgentLinkConsent, createBiomapperQueryClient, createLinkSession, } from '@techdigger/humanode-agentlink';
15
16
  function writeLine(write, text) {
@@ -34,6 +35,7 @@ export async function runCli(argv = process.argv.slice(2), overrides = {}) {
34
35
  openUrl: overrides.openUrl ?? openUrlInBrowser,
35
36
  readStdin: overrides.readStdin ?? readAllFromStdin,
36
37
  readPassword: overrides.readPassword ?? readPassword,
38
+ fetchImpl: overrides.fetchImpl ?? fetch,
37
39
  };
38
40
  const [command, ...args] = argv;
39
41
  try {
@@ -183,6 +185,17 @@ export async function runCli(argv = process.argv.slice(2), overrides = {}) {
183
185
  }, runtime.env);
184
186
  return 0;
185
187
  }
188
+ case 'request': {
189
+ if (args.includes('--help') || args.includes('-h')) {
190
+ writeLine(runtime.stdout, getRequestHelpText());
191
+ return 0;
192
+ }
193
+ const requestPrivateKey = await readPrivateKeyFromStdin(args, runtime);
194
+ const requestOptions = parseRequestOptions(args, runtime.env, { privateKey: requestPrivateKey });
195
+ const requestResults = await runRequest(requestOptions, { fetchImpl: runtime.fetchImpl });
196
+ writeLine(runtime.stdout, formatRequestOutput(requestResults, requestOptions.json));
197
+ return 0;
198
+ }
186
199
  default:
187
200
  throw new CliError(`Unknown command "${command}". Run "agentlink --help" for available commands.`);
188
201
  }
@@ -4,11 +4,13 @@ export declare const NETWORKS: {
4
4
  readonly label: "Base mainnet";
5
5
  readonly biomapperAppUrl: string;
6
6
  readonly defaultRegistry: Address;
7
+ readonly chainId: 8453;
7
8
  };
8
9
  readonly 'base-sepolia': {
9
10
  readonly label: "Base Sepolia";
10
11
  readonly biomapperAppUrl: string;
11
12
  readonly defaultRegistry: Address;
13
+ readonly chainId: 84532;
12
14
  };
13
15
  };
14
16
  export type NetworkName = keyof typeof NETWORKS;
package/dist/lib/core.js CHANGED
@@ -12,11 +12,13 @@ export const NETWORKS = {
12
12
  label: 'Base mainnet',
13
13
  biomapperAppUrl: BIOMAPPER_APP_URLS.base,
14
14
  defaultRegistry: '0x', // populated at mainnet launch
15
+ chainId: 8453,
15
16
  },
16
17
  'base-sepolia': {
17
18
  label: 'Base Sepolia',
18
19
  biomapperAppUrl: BIOMAPPER_APP_URLS['base-sepolia'],
19
20
  defaultRegistry: '0xc0fb26BaACe7E1BCb3aFFD547AD5f2cAc4A4F51b',
21
+ chainId: 84532,
20
22
  },
21
23
  };
22
24
  export const TEMPLATE_NAMES = ['langchain', 'vercel-ai-sdk', 'mcp'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techdigger/humanode-agentlink-cli",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Scaffold, link, and inspect Biomapper-ready agent projects.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,8 +23,9 @@
23
23
  "cli": "tsx src/index.ts"
24
24
  },
25
25
  "dependencies": {
26
- "@techdigger/humanode-agentlink": "^0.2.0",
26
+ "@techdigger/humanode-agentlink": "^0.3.0",
27
27
  "posthog-node": "^5.21.2",
28
+ "siwe": "^2.3.2",
28
29
  "viem": "^2.46.2"
29
30
  },
30
31
  "keywords": [