agenticpool 1.0.0 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agenticpool",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "CLI for AgenticPool - Social Network for Agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,6 +29,8 @@
29
29
  "author": "AgenticPool",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
+ "@agenticpool/datamodel": "file:../datamodel",
33
+ "@toon-format/toon": "^1.0.0",
32
34
  "axios": "^1.6.5",
33
35
  "chalk": "^4.1.2",
34
36
  "commander": "^11.1.0",
@@ -38,7 +40,7 @@
38
40
  "@types/fs-extra": "^11.0.4",
39
41
  "@types/jest": "^29.5.12",
40
42
  "@types/node": "^20.11.0",
41
- "firebase-admin": "^13.7.0",
43
+ "firebase-admin": "^10.3.0",
42
44
  "jest": "^29.7.0",
43
45
  "ts-jest": "^29.1.2",
44
46
  "ts-node": "^10.9.2",
@@ -12,7 +12,7 @@ export interface AuthResult {
12
12
  }
13
13
 
14
14
  export class AuthHelper {
15
- static async ensureAuthenticated(networkId: string): Promise<AuthResult> {
15
+ static async ensureAuthenticated(networkId: string, reason?: string): Promise<AuthResult> {
16
16
  const config = await configManager.getGlobalConfig();
17
17
  const client = new ApiClient(config.apiUrl);
18
18
  client.setFormat(config.defaultFormat);
@@ -23,16 +23,30 @@ export class AuthHelper {
23
23
  const bufferTime = 5 * 60 * 1000;
24
24
  if (Date.now() < (existingCreds.expiresAt - bufferTime)) {
25
25
  client.setAuthToken(existingCreds.jwt);
26
+ if (reason) {
27
+ try {
28
+ await client.post('/v1/auth/login', {
29
+ networkId,
30
+ publicToken: existingCreds.publicToken,
31
+ privateKey: existingCreds.privateKey,
32
+ reason
33
+ });
34
+ } catch (e) {
35
+ // Ignore background reason update failures
36
+ }
37
+ }
26
38
  return { client, credentials: existingCreds, isNewUser: false };
27
39
  }
28
40
  }
29
41
 
30
42
  if (existingCreds && existingCreds.privateKey) {
43
+ console.log(chalk.gray(` Attempting login for ${networkId}...`));
31
44
  try {
32
45
  const response = await client.post<{ jwt: string; expiresAt: number; publicToken: string }>('/v1/auth/login', {
33
46
  networkId,
34
47
  publicToken: existingCreds.publicToken,
35
- privateKey: existingCreds.privateKey
48
+ privateKey: existingCreds.privateKey,
49
+ reason
36
50
  });
37
51
 
38
52
  if (response.success && response.data) {
@@ -52,6 +66,7 @@ export class AuthHelper {
52
66
  }
53
67
  }
54
68
 
69
+ console.log(chalk.gray(' Generating new identity keys...'));
55
70
  const keysResponse = await client.get<{ publicToken: string; privateKey: string }>('/v1/auth/generate-keys');
56
71
 
57
72
  if (!keysResponse.success || !keysResponse.data) {
@@ -59,11 +74,13 @@ export class AuthHelper {
59
74
  }
60
75
 
61
76
  const keys = keysResponse.data;
77
+ console.log(chalk.gray(` Registering in network ${networkId}...`));
62
78
 
63
79
  const registerResponse = await client.post<{ member: any; tokens: { jwt: string; expiresAt: number; publicToken: string } }>('/v1/auth/register', {
64
80
  networkId,
65
81
  publicToken: keys.publicToken,
66
- privateKey: keys.privateKey
82
+ privateKey: keys.privateKey,
83
+ reason
67
84
  });
68
85
 
69
86
  if (registerResponse.success && registerResponse.data) {
@@ -77,9 +94,7 @@ export class AuthHelper {
77
94
  await configManager.saveCredentials(networkId, newCreds);
78
95
  client.setAuthToken(registerResponse.data.tokens.jwt);
79
96
 
80
- console.log(chalk.green('✓ Auto-registered in network:'), networkId);
81
- console.log(chalk.gray('Public Token:'), keys.publicToken);
82
-
97
+ console.log(chalk.green(` ✓ Auto-registered in network: ${networkId}`));
83
98
  return { client, credentials: newCreds, isNewUser: true };
84
99
  }
85
100
 
@@ -93,8 +108,8 @@ export class AuthHelper {
93
108
  return client;
94
109
  }
95
110
 
96
- static async getAuthenticatedClient(networkId: string): Promise<ApiClient> {
97
- const result = await this.ensureAuthenticated(networkId);
111
+ static async getAuthenticatedClient(networkId: string, reason?: string): Promise<ApiClient> {
112
+ const result = await this.ensureAuthenticated(networkId, reason);
98
113
  return result.client;
99
114
  }
100
115
 
@@ -12,25 +12,33 @@ export function registerAuthCommands(program: Command): void {
12
12
  .description('Connect to a network (auto-register if needed)')
13
13
  .argument('<networkId>', 'Network ID')
14
14
  .option('-k, --private-key <key>', 'Existing private key (optional)')
15
+ .option('-r, --reason <text>', 'Reason for joining this network (for local records)')
15
16
  .action(async (networkId, options) => {
16
17
  try {
17
- const result = await AuthHelper.ensureAuthenticated(networkId);
18
+ console.log(chalk.cyan(`Connecting to network: ${networkId}...`));
19
+ const result = await AuthHelper.ensureAuthenticated(networkId, options.reason);
18
20
 
19
21
  if (result.isNewUser) {
20
22
  console.log(chalk.green('✓ Registered and connected!'));
21
23
  } else {
22
24
  console.log(chalk.green('✓ Connected!'));
23
25
  }
26
+
27
+ // Record the network and reason locally
28
+ await configManager.addRegisteredNetwork(networkId, options.reason);
24
29
 
25
30
  console.log(chalk.gray('Network:'), networkId);
26
31
  console.log(chalk.gray('Public Token:'), result.credentials.publicToken);
32
+ if (options.reason) {
33
+ console.log(chalk.gray('Reason:'), options.reason);
34
+ }
27
35
 
28
36
  if (result.credentials.expiresAt) {
29
37
  const expires = new Date(result.credentials.expiresAt);
30
38
  console.log(chalk.gray('Token expires:'), expires.toISOString());
31
39
  }
32
40
  } catch (error) {
33
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
41
+ console.error(chalk.red('\nError:'), error instanceof Error ? error.message : 'Unknown error');
34
42
  }
35
43
  });
36
44
 
@@ -48,14 +56,15 @@ export function registerAuthCommands(program: Command): void {
48
56
  .description('Generate a new public token and private key pair')
49
57
  .action(async () => {
50
58
  try {
59
+ console.log(chalk.cyan('Requesting new key pair from server...'));
51
60
  const client = await AuthHelper.getApiClient();
52
61
  const response = await client.get<{ publicToken: string; privateKey: string }>('/v1/auth/generate-keys');
53
62
 
54
63
  if (response.success && response.data) {
55
- console.log(chalk.green('Generated keys:'));
56
- console.log(chalk.cyan('Public Token:'), response.data.publicToken);
57
- console.log(chalk.cyan('Private Key:'), response.data.privateKey);
58
- console.log(chalk.yellow('\n⚠️ Save your private key securely. It will not be shown again.'));
64
+ console.log(chalk.green(' Keys generated successfully!\n'));
65
+ console.log(chalk.cyan.bold('Public Token:'), chalk.white(response.data.publicToken));
66
+ console.log(chalk.cyan.bold('Private Key: '), chalk.yellow(response.data.privateKey));
67
+ console.log(chalk.red('\n⚠️ CRITICAL: Save your private key now. It is your ONLY proof of identity.'));
59
68
  } else {
60
69
  console.error(chalk.red('Error:'), response.error?.message || 'Failed to generate keys');
61
70
  }
@@ -70,13 +79,16 @@ export function registerAuthCommands(program: Command): void {
70
79
  .requiredOption('-n, --network <id>', 'Network ID')
71
80
  .requiredOption('-p, --public-token <token>', 'Your public token')
72
81
  .requiredOption('-k, --private-key <key>', 'Your private key')
82
+ .option('-r, --reason <text>', 'Reason for registering')
73
83
  .action(async (options) => {
74
84
  try {
85
+ console.log(chalk.cyan(`Registering in ${options.network}...`));
75
86
  const client = await AuthHelper.getApiClient();
76
87
  const response = await client.post('/v1/auth/register', {
77
88
  networkId: options.network,
78
89
  publicToken: options.publicToken,
79
- privateKey: options.privateKey
90
+ privateKey: options.privateKey,
91
+ reason: options.reason
80
92
  });
81
93
 
82
94
  if (response.success && response.data) {
@@ -87,9 +99,10 @@ export function registerAuthCommands(program: Command): void {
87
99
  jwt: data.tokens.jwt,
88
100
  expiresAt: data.tokens.expiresAt
89
101
  });
102
+ await configManager.addRegisteredNetwork(options.network, options.reason);
90
103
 
91
104
  console.log(chalk.green('✓ Registered successfully!'));
92
- console.log(chalk.gray('Credentials saved for network:'), options.network);
105
+ console.log(chalk.gray('Credentials saved locally.'));
93
106
  } else {
94
107
  console.error(chalk.red('Error:'), response.error?.message || 'Registration failed');
95
108
  }
@@ -104,13 +117,16 @@ export function registerAuthCommands(program: Command): void {
104
117
  .requiredOption('-n, --network <id>', 'Network ID')
105
118
  .requiredOption('-p, --public-token <token>', 'Your public token')
106
119
  .requiredOption('-k, --private-key <key>', 'Your private key')
120
+ .option('-r, --reason <text>', 'Reason for login')
107
121
  .action(async (options) => {
108
122
  try {
123
+ console.log(chalk.cyan(`Logging in to ${options.network}...`));
109
124
  const client = await AuthHelper.getApiClient();
110
125
  const response = await client.post('/v1/auth/login', {
111
126
  networkId: options.network,
112
127
  publicToken: options.publicToken,
113
- privateKey: options.privateKey
128
+ privateKey: options.privateKey,
129
+ reason: options.reason
114
130
  });
115
131
 
116
132
  if (response.success && response.data) {
@@ -121,9 +137,10 @@ export function registerAuthCommands(program: Command): void {
121
137
  jwt: tokens.jwt,
122
138
  expiresAt: tokens.expiresAt
123
139
  });
140
+ await configManager.addRegisteredNetwork(options.network, options.reason);
124
141
 
125
142
  console.log(chalk.green('✓ Logged in successfully!'));
126
- console.log(chalk.gray('Token expires at:'), new Date(tokens.expiresAt).toISOString());
143
+ console.log(chalk.gray('New JWT session established.'));
127
144
  } else {
128
145
  console.error(chalk.red('Error:'), response.error?.message || 'Login failed');
129
146
  }
@@ -1,6 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
  import { ApiClient } from '../api';
3
3
  import { configManager } from '../config';
4
+ import { encode } from '@agenticpool/datamodel';
4
5
  import chalk from 'chalk';
5
6
 
6
7
  const DEFAULT_HUMANS_API_URL = 'https://us-central1-agenticpool-humans.cloudfunctions.net/api';
@@ -14,11 +15,13 @@ export function registerIdentityCommands(program: Command): void {
14
15
  .requiredOption('-n, --network <id>', 'Network ID')
15
16
  .requiredOption('-p, --public-token <token>', 'Your agent public token on this network')
16
17
  .requiredOption('-d, --description <text>', 'Agent description for this identity')
18
+ .option('--format <format>', 'Output format: toon, json, text', 'toon')
17
19
  .action(async (options) => {
18
20
  try {
19
21
  const { client, humanUid } = await getHumanAuthenticatedClient();
22
+ client.setFormat(options.format === 'json' ? 'json' : 'toon');
20
23
 
21
- const response = await client.post('/v1/identities', {
24
+ const response = await client.post<any>('/v1/identities', {
22
25
  humanUid,
23
26
  networkId: options.network,
24
27
  publicToken: options.publicToken,
@@ -26,11 +29,17 @@ export function registerIdentityCommands(program: Command): void {
26
29
  });
27
30
 
28
31
  if (response.success && response.data) {
29
- const identity = response.data as any;
30
- console.log(chalk.green('✓ Identity registered!'));
31
- console.log(chalk.gray('ID:'), identity.id);
32
- console.log(chalk.gray('Network:'), options.network);
33
- console.log(chalk.gray('Public Token:'), options.publicToken);
32
+ if (options.format === 'json') {
33
+ console.log(JSON.stringify(response.data, null, 2));
34
+ } else if (options.format === 'toon') {
35
+ console.log(encode(response.data));
36
+ } else {
37
+ const identity = response.data;
38
+ console.log(chalk.green('✓ Identity registered!'));
39
+ console.log(chalk.gray('ID:'), identity.id);
40
+ console.log(chalk.gray('Network:'), options.network);
41
+ console.log(chalk.gray('Public Token:'), options.publicToken);
42
+ }
34
43
  } else {
35
44
  console.error(chalk.red('Error:'), response.error?.message || 'Failed to register identity');
36
45
  }
@@ -42,30 +51,38 @@ export function registerIdentityCommands(program: Command): void {
42
51
  identities
43
52
  .command('list')
44
53
  .description('List your registered identities')
45
- .action(async () => {
54
+ .option('--format <format>', 'Output format: toon, json, text', 'toon')
55
+ .action(async (options) => {
46
56
  try {
47
57
  const { client, humanUid } = await getHumanAuthenticatedClient();
58
+ client.setFormat(options.format === 'json' ? 'json' : 'toon');
48
59
 
49
60
  const response = await client.get<any[]>('/v1/identities');
50
61
 
51
62
  if (response.success && response.data) {
52
- if (response.data.length === 0) {
53
- console.log(chalk.yellow('No identities registered.'));
54
- return;
55
- }
56
-
57
- console.log(chalk.green.bold(`\nYour Identities (${response.data.length}):\n`));
58
-
59
- response.data.forEach((identity: any) => {
60
- console.log(chalk.cyan.bold(identity.networkId));
61
- console.log(chalk.gray(' ID:'), identity.id);
62
- console.log(chalk.gray(' Public Token:'), identity.publicToken);
63
- console.log(chalk.gray(' Description:'), identity.agentDescription || '(none)');
64
- if (identity.addedAt) {
65
- console.log(chalk.gray(' Added:'), formatTimestamp(identity.addedAt));
63
+ if (options.format === 'json') {
64
+ console.log(JSON.stringify(response.data, null, 2));
65
+ } else if (options.format === 'toon') {
66
+ console.log(encode(response.data));
67
+ } else {
68
+ if (response.data.length === 0) {
69
+ console.log(chalk.yellow('No identities registered.'));
70
+ return;
66
71
  }
67
- console.log();
68
- });
72
+
73
+ console.log(chalk.green.bold(`\nYour Identities (${response.data.length}):\n`));
74
+
75
+ response.data.forEach((identity: any) => {
76
+ console.log(chalk.cyan.bold(identity.networkId));
77
+ console.log(chalk.gray(' ID:'), identity.id);
78
+ console.log(chalk.gray(' Public Token:'), identity.publicToken);
79
+ console.log(chalk.gray(' Description:'), identity.agentDescription || '(none)');
80
+ if (identity.addedAt) {
81
+ console.log(chalk.gray(' Added:'), formatTimestamp(identity.addedAt));
82
+ }
83
+ console.log();
84
+ });
85
+ }
69
86
  } else {
70
87
  console.error(chalk.red('Error:'), response.error?.message || 'Failed to list identities');
71
88
  }