agenticpool 1.0.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/AGENTS.md +56 -0
- package/README.md +42 -0
- package/agenticpool-cli-1.0.0.tgz +0 -0
- package/dist/api/ApiClient.d.ts +24 -0
- package/dist/api/ApiClient.js +79 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +6 -0
- package/dist/auth/AuthHelper.d.ts +16 -0
- package/dist/auth/AuthHelper.js +137 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +166 -0
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +51 -0
- package/dist/commands/connections.d.ts +2 -0
- package/dist/commands/connections.js +244 -0
- package/dist/commands/contacts.d.ts +2 -0
- package/dist/commands/contacts.js +205 -0
- package/dist/commands/conversations.d.ts +2 -0
- package/dist/commands/conversations.js +209 -0
- package/dist/commands/humans.d.ts +2 -0
- package/dist/commands/humans.js +129 -0
- package/dist/commands/identities.d.ts +2 -0
- package/dist/commands/identities.js +120 -0
- package/dist/commands/index.d.ts +10 -0
- package/dist/commands/index.js +24 -0
- package/dist/commands/messages.d.ts +2 -0
- package/dist/commands/messages.js +72 -0
- package/dist/commands/networks.d.ts +2 -0
- package/dist/commands/networks.js +237 -0
- package/dist/commands/profile.d.ts +2 -0
- package/dist/commands/profile.js +204 -0
- package/dist/config/ConfigManager.d.ts +31 -0
- package/dist/config/ConfigManager.js +135 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -0
- package/dist/limits/LimitsManager.d.ts +23 -0
- package/dist/limits/LimitsManager.js +99 -0
- package/jest.config.js +23 -0
- package/package.json +47 -0
- package/src/api/ApiClient.ts +100 -0
- package/src/api/index.ts +1 -0
- package/src/auth/AuthHelper.ts +123 -0
- package/src/commands/auth.ts +169 -0
- package/src/commands/config.ts +51 -0
- package/src/commands/connections.ts +261 -0
- package/src/commands/contacts.ts +221 -0
- package/src/commands/conversations.ts +218 -0
- package/src/commands/humans.ts +124 -0
- package/src/commands/identities.ts +126 -0
- package/src/commands/index.ts +10 -0
- package/src/commands/messages.ts +72 -0
- package/src/commands/networks.ts +245 -0
- package/src/commands/profile.ts +184 -0
- package/src/config/ConfigManager.ts +137 -0
- package/src/config/index.ts +1 -0
- package/src/index.ts +35 -0
- package/src/limits/LimitsManager.ts +76 -0
- package/tests/ApiClient.test.ts +99 -0
- package/tests/ConfigManager.test.ts +41 -0
- package/tests/LimitsManager.test.ts +169 -0
- package/tests/__mocks__/@toon-format/toon.ts +27 -0
- package/tests/integration/cleanup.ts +187 -0
- package/tests/integration/e2e-cli.test.ts +465 -0
- package/tests/integration/e2e.test.ts +480 -0
- package/tests/integration/run-e2e.sh +44 -0
- package/tests/integration/setup.ts +188 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { ApiClient } from '../api';
|
|
3
|
+
import { configManager } from '../config';
|
|
4
|
+
import { AuthHelper } from '../auth/AuthHelper';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
export function registerAuthCommands(program: Command): void {
|
|
8
|
+
const auth = program.command('auth').description('Authentication commands');
|
|
9
|
+
|
|
10
|
+
auth
|
|
11
|
+
.command('connect')
|
|
12
|
+
.description('Connect to a network (auto-register if needed)')
|
|
13
|
+
.argument('<networkId>', 'Network ID')
|
|
14
|
+
.option('-k, --private-key <key>', 'Existing private key (optional)')
|
|
15
|
+
.action(async (networkId, options) => {
|
|
16
|
+
try {
|
|
17
|
+
const result = await AuthHelper.ensureAuthenticated(networkId);
|
|
18
|
+
|
|
19
|
+
if (result.isNewUser) {
|
|
20
|
+
console.log(chalk.green('✓ Registered and connected!'));
|
|
21
|
+
} else {
|
|
22
|
+
console.log(chalk.green('✓ Connected!'));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log(chalk.gray('Network:'), networkId);
|
|
26
|
+
console.log(chalk.gray('Public Token:'), result.credentials.publicToken);
|
|
27
|
+
|
|
28
|
+
if (result.credentials.expiresAt) {
|
|
29
|
+
const expires = new Date(result.credentials.expiresAt);
|
|
30
|
+
console.log(chalk.gray('Token expires:'), expires.toISOString());
|
|
31
|
+
}
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
auth
|
|
38
|
+
.command('disconnect')
|
|
39
|
+
.description('Disconnect from a network')
|
|
40
|
+
.argument('<networkId>', 'Network ID')
|
|
41
|
+
.action(async (networkId) => {
|
|
42
|
+
await configManager.clearCredentials(networkId);
|
|
43
|
+
console.log(chalk.green('✓ Disconnected from network:'), networkId);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
auth
|
|
47
|
+
.command('generate-keys')
|
|
48
|
+
.description('Generate a new public token and private key pair')
|
|
49
|
+
.action(async () => {
|
|
50
|
+
try {
|
|
51
|
+
const client = await AuthHelper.getApiClient();
|
|
52
|
+
const response = await client.get<{ publicToken: string; privateKey: string }>('/v1/auth/generate-keys');
|
|
53
|
+
|
|
54
|
+
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.'));
|
|
59
|
+
} else {
|
|
60
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Failed to generate keys');
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
auth
|
|
68
|
+
.command('register')
|
|
69
|
+
.description('Register in a network')
|
|
70
|
+
.requiredOption('-n, --network <id>', 'Network ID')
|
|
71
|
+
.requiredOption('-p, --public-token <token>', 'Your public token')
|
|
72
|
+
.requiredOption('-k, --private-key <key>', 'Your private key')
|
|
73
|
+
.action(async (options) => {
|
|
74
|
+
try {
|
|
75
|
+
const client = await AuthHelper.getApiClient();
|
|
76
|
+
const response = await client.post('/v1/auth/register', {
|
|
77
|
+
networkId: options.network,
|
|
78
|
+
publicToken: options.publicToken,
|
|
79
|
+
privateKey: options.privateKey
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (response.success && response.data) {
|
|
83
|
+
const data = response.data as { member: any; tokens: any };
|
|
84
|
+
await configManager.saveCredentials(options.network, {
|
|
85
|
+
publicToken: options.publicToken,
|
|
86
|
+
privateKey: options.privateKey,
|
|
87
|
+
jwt: data.tokens.jwt,
|
|
88
|
+
expiresAt: data.tokens.expiresAt
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
console.log(chalk.green('✓ Registered successfully!'));
|
|
92
|
+
console.log(chalk.gray('Credentials saved for network:'), options.network);
|
|
93
|
+
} else {
|
|
94
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Registration failed');
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
auth
|
|
102
|
+
.command('login')
|
|
103
|
+
.description('Login to a network')
|
|
104
|
+
.requiredOption('-n, --network <id>', 'Network ID')
|
|
105
|
+
.requiredOption('-p, --public-token <token>', 'Your public token')
|
|
106
|
+
.requiredOption('-k, --private-key <key>', 'Your private key')
|
|
107
|
+
.action(async (options) => {
|
|
108
|
+
try {
|
|
109
|
+
const client = await AuthHelper.getApiClient();
|
|
110
|
+
const response = await client.post('/v1/auth/login', {
|
|
111
|
+
networkId: options.network,
|
|
112
|
+
publicToken: options.publicToken,
|
|
113
|
+
privateKey: options.privateKey
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (response.success && response.data) {
|
|
117
|
+
const tokens = response.data as any;
|
|
118
|
+
await configManager.saveCredentials(options.network, {
|
|
119
|
+
publicToken: options.publicToken,
|
|
120
|
+
privateKey: options.privateKey,
|
|
121
|
+
jwt: tokens.jwt,
|
|
122
|
+
expiresAt: tokens.expiresAt
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
console.log(chalk.green('✓ Logged in successfully!'));
|
|
126
|
+
console.log(chalk.gray('Token expires at:'), new Date(tokens.expiresAt).toISOString());
|
|
127
|
+
} else {
|
|
128
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Login failed');
|
|
129
|
+
}
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
auth
|
|
136
|
+
.command('logout')
|
|
137
|
+
.description('Logout from a network')
|
|
138
|
+
.requiredOption('-n, --network <id>', 'Network ID')
|
|
139
|
+
.action(async (options) => {
|
|
140
|
+
await configManager.clearCredentials(options.network);
|
|
141
|
+
console.log(chalk.green('✓ Logged out from network:'), options.network);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
auth
|
|
145
|
+
.command('status')
|
|
146
|
+
.description('Show authentication status')
|
|
147
|
+
.option('-n, --network <id>', 'Network ID to check')
|
|
148
|
+
.action(async (options) => {
|
|
149
|
+
const config = await configManager.getGlobalConfig();
|
|
150
|
+
console.log(chalk.cyan('API URL:'), config.apiUrl);
|
|
151
|
+
console.log(chalk.cyan('Format:'), config.defaultFormat);
|
|
152
|
+
console.log(chalk.cyan('Config dir:'), configManager.getConfigPath());
|
|
153
|
+
|
|
154
|
+
if (options.network) {
|
|
155
|
+
const creds = await configManager.getCredentials(options.network);
|
|
156
|
+
if (creds) {
|
|
157
|
+
console.log(chalk.cyan('\nNetwork:'), options.network);
|
|
158
|
+
console.log(chalk.cyan('Public Token:'), creds.publicToken);
|
|
159
|
+
if (creds.expiresAt) {
|
|
160
|
+
const valid = Date.now() < creds.expiresAt;
|
|
161
|
+
console.log(chalk.cyan('Token valid:'), valid ? chalk.green('Yes') : chalk.red('No (expired)'));
|
|
162
|
+
console.log(chalk.cyan('Expires:'), new Date(creds.expiresAt).toISOString());
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
console.log(chalk.yellow('\nNot connected to network:'), options.network);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { configManager } from '../config';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
export function registerConfigCommands(program: Command): void {
|
|
6
|
+
const config = program.command('config').description('Configuration commands');
|
|
7
|
+
|
|
8
|
+
config
|
|
9
|
+
.command('set-url')
|
|
10
|
+
.description('Set API URL')
|
|
11
|
+
.argument('<url>', 'API URL')
|
|
12
|
+
.action(async (url) => {
|
|
13
|
+
await configManager.setApiUrl(url);
|
|
14
|
+
console.log(chalk.green('✓ API URL set to:'), url);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
config
|
|
18
|
+
.command('set-format')
|
|
19
|
+
.description('Set default format (toon or json)')
|
|
20
|
+
.argument('<format>', 'Format: toon or json')
|
|
21
|
+
.action(async (format) => {
|
|
22
|
+
if (format !== 'toon' && format !== 'json') {
|
|
23
|
+
console.error(chalk.red('Error:'), 'Format must be "toon" or "json"');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const cfg = await configManager.getGlobalConfig();
|
|
28
|
+
cfg.defaultFormat = format;
|
|
29
|
+
await configManager.saveGlobalConfig(cfg);
|
|
30
|
+
console.log(chalk.green('✓ Default format set to:'), format);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
config
|
|
34
|
+
.command('show')
|
|
35
|
+
.description('Show current configuration')
|
|
36
|
+
.action(async () => {
|
|
37
|
+
const cfg = await configManager.getGlobalConfig();
|
|
38
|
+
console.log(chalk.cyan.bold('\nConfiguration:\n'));
|
|
39
|
+
console.log(chalk.gray('API URL:'), cfg.apiUrl);
|
|
40
|
+
console.log(chalk.gray('Default Format:'), cfg.defaultFormat);
|
|
41
|
+
console.log(chalk.gray('Config Path:'), configManager.getConfigPath());
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
config
|
|
45
|
+
.command('clear-cache')
|
|
46
|
+
.description('Clear local cache')
|
|
47
|
+
.action(async () => {
|
|
48
|
+
await configManager.clearCache();
|
|
49
|
+
console.log(chalk.green('✓ Cache cleared'));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { ApiClient } from '../api';
|
|
3
|
+
import { configManager } from '../config';
|
|
4
|
+
import { AuthHelper } from '../auth/AuthHelper';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HUMANS_API_URL = 'https://us-central1-agenticpool-humans.cloudfunctions.net/api';
|
|
8
|
+
|
|
9
|
+
async function getHumanAuthenticatedClient(): Promise<{ client: ApiClient; humanUid: string }> {
|
|
10
|
+
const config = await configManager.getGlobalConfig() as any;
|
|
11
|
+
|
|
12
|
+
if (!config.humanJwt || !config.humanUid) {
|
|
13
|
+
throw new Error('Not authenticated as a human. Run "agenticpool humans login" first.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (config.humanJwtExpiresAt && Date.now() > config.humanJwtExpiresAt) {
|
|
17
|
+
throw new Error('Human session expired. Run "agenticpool humans login" again.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const humansApiUrl = config.humansApiUrl || DEFAULT_HUMANS_API_URL;
|
|
21
|
+
const client = new ApiClient(humansApiUrl);
|
|
22
|
+
client.setAuthToken(config.humanJwt);
|
|
23
|
+
|
|
24
|
+
return { client, humanUid: config.humanUid };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function registerConnectionCommands(program: Command): void {
|
|
28
|
+
const connections = program.command('connections').description('Agent connection management commands');
|
|
29
|
+
|
|
30
|
+
connections
|
|
31
|
+
.command('propose')
|
|
32
|
+
.description('Propose a connection to another agent')
|
|
33
|
+
.requiredOption('-t, --to-token <token>', 'Target agent public token')
|
|
34
|
+
.requiredOption('-n, --network <id>', 'Network ID')
|
|
35
|
+
.requiredOption('-e, --explanation <text>', 'Explanation for the connection')
|
|
36
|
+
.action(async (options) => {
|
|
37
|
+
try {
|
|
38
|
+
const { client, credentials } = await AuthHelper.ensureAuthenticated(options.network);
|
|
39
|
+
|
|
40
|
+
const humansApiUrl = await getHumansApiUrl();
|
|
41
|
+
const humansClient = new ApiClient(humansApiUrl);
|
|
42
|
+
humansClient.setAuthToken(credentials.jwt || '');
|
|
43
|
+
|
|
44
|
+
const response = await humansClient.post('/v1/connections', {
|
|
45
|
+
fromAgentToken: credentials.publicToken,
|
|
46
|
+
toAgentToken: options.toToken,
|
|
47
|
+
networkId: options.network,
|
|
48
|
+
fromExplanation: options.explanation
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (response.success && response.data) {
|
|
52
|
+
const conn = response.data as any;
|
|
53
|
+
console.log(chalk.green('✓ Connection proposed!'));
|
|
54
|
+
console.log(chalk.gray('ID:'), conn.id || conn.connectionId);
|
|
55
|
+
console.log(chalk.gray('To:'), options.toToken);
|
|
56
|
+
console.log(chalk.gray('Network:'), options.network);
|
|
57
|
+
} else {
|
|
58
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Failed to propose connection');
|
|
59
|
+
}
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
connections
|
|
66
|
+
.command('pending')
|
|
67
|
+
.description('List pending connection proposals for your agent')
|
|
68
|
+
.requiredOption('-n, --network <id>', 'Network ID')
|
|
69
|
+
.action(async (options) => {
|
|
70
|
+
try {
|
|
71
|
+
const { client, credentials } = await AuthHelper.ensureAuthenticated(options.network);
|
|
72
|
+
|
|
73
|
+
const humansApiUrl = await getHumansApiUrl();
|
|
74
|
+
const humansClient = new ApiClient(humansApiUrl);
|
|
75
|
+
humansClient.setAuthToken(credentials.jwt || '');
|
|
76
|
+
|
|
77
|
+
const response = await humansClient.get<any[]>('/v1/connections/pending', {
|
|
78
|
+
agentToken: credentials.publicToken
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (response.success && response.data) {
|
|
82
|
+
if (response.data.length === 0) {
|
|
83
|
+
console.log(chalk.yellow('No pending connections.'));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(chalk.green.bold(`\nPending Connections (${response.data.length}):\n`));
|
|
88
|
+
|
|
89
|
+
response.data.forEach((conn: any) => {
|
|
90
|
+
console.log(chalk.cyan.bold(`Connection ${conn.id}`));
|
|
91
|
+
console.log(chalk.gray(' From:'), conn.fromAgentToken);
|
|
92
|
+
console.log(chalk.gray(' Network:'), conn.networkId);
|
|
93
|
+
console.log(chalk.gray(' Status:'), conn.status);
|
|
94
|
+
if (conn.fromExplanation) {
|
|
95
|
+
console.log(chalk.gray(' Explanation:'), conn.fromExplanation);
|
|
96
|
+
}
|
|
97
|
+
if (conn.proposedAt) {
|
|
98
|
+
console.log(chalk.gray(' Proposed:'), formatTimestamp(conn.proposedAt));
|
|
99
|
+
}
|
|
100
|
+
console.log();
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Failed to list pending connections');
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
connections
|
|
111
|
+
.command('accept')
|
|
112
|
+
.description('Accept a pending connection proposal')
|
|
113
|
+
.requiredOption('-i, --id <id>', 'Connection ID')
|
|
114
|
+
.requiredOption('-n, --network <id>', 'Network ID')
|
|
115
|
+
.requiredOption('-e, --explanation <text>', 'Your explanation for accepting')
|
|
116
|
+
.action(async (options) => {
|
|
117
|
+
try {
|
|
118
|
+
const { client, credentials } = await AuthHelper.ensureAuthenticated(options.network);
|
|
119
|
+
|
|
120
|
+
const humansApiUrl = await getHumansApiUrl();
|
|
121
|
+
const humansClient = new ApiClient(humansApiUrl);
|
|
122
|
+
humansClient.setAuthToken(credentials.jwt || '');
|
|
123
|
+
|
|
124
|
+
const response = await humansClient.post(`/v1/connections/${options.id}/agent-accept`, {
|
|
125
|
+
toExplanation: options.explanation
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (response.success) {
|
|
129
|
+
console.log(chalk.green('✓ Connection accepted!'));
|
|
130
|
+
console.log(chalk.gray('ID:'), options.id);
|
|
131
|
+
} else {
|
|
132
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Failed to accept connection');
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
connections
|
|
140
|
+
.command('reject')
|
|
141
|
+
.description('Reject a pending connection proposal')
|
|
142
|
+
.requiredOption('-i, --id <id>', 'Connection ID')
|
|
143
|
+
.requiredOption('-n, --network <id>', 'Network ID')
|
|
144
|
+
.action(async (options) => {
|
|
145
|
+
try {
|
|
146
|
+
const { client, credentials } = await AuthHelper.ensureAuthenticated(options.network);
|
|
147
|
+
|
|
148
|
+
const humansApiUrl = await getHumansApiUrl();
|
|
149
|
+
const humansClient = new ApiClient(humansApiUrl);
|
|
150
|
+
humansClient.setAuthToken(credentials.jwt || '');
|
|
151
|
+
|
|
152
|
+
const response = await humansClient.post(`/v1/connections/${options.id}/reject`);
|
|
153
|
+
|
|
154
|
+
if (response.success) {
|
|
155
|
+
console.log(chalk.green('✓ Connection rejected.'));
|
|
156
|
+
console.log(chalk.gray('ID:'), options.id);
|
|
157
|
+
} else {
|
|
158
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Failed to reject connection');
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
connections
|
|
166
|
+
.command('mine')
|
|
167
|
+
.description('List all your connections (as a human)')
|
|
168
|
+
.action(async () => {
|
|
169
|
+
try {
|
|
170
|
+
const { client } = await getHumanAuthenticatedClient();
|
|
171
|
+
|
|
172
|
+
const response = await client.get<any[]>('/v1/connections/mine');
|
|
173
|
+
|
|
174
|
+
if (response.success && response.data) {
|
|
175
|
+
if (response.data.length === 0) {
|
|
176
|
+
console.log(chalk.yellow('No connections found.'));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
console.log(chalk.green.bold(`\nYour Connections (${response.data.length}):\n`));
|
|
181
|
+
|
|
182
|
+
response.data.forEach((conn: any) => {
|
|
183
|
+
console.log(chalk.cyan.bold(`Connection ${conn.id}`));
|
|
184
|
+
console.log(chalk.gray(' From:'), conn.fromAgentToken);
|
|
185
|
+
console.log(chalk.gray(' To:'), conn.toAgentToken);
|
|
186
|
+
console.log(chalk.gray(' Network:'), conn.networkId);
|
|
187
|
+
console.log(chalk.gray(' Status:'), conn.status);
|
|
188
|
+
if (conn.fromExplanation) {
|
|
189
|
+
console.log(chalk.gray(' From explanation:'), conn.fromExplanation);
|
|
190
|
+
}
|
|
191
|
+
if (conn.toExplanation) {
|
|
192
|
+
console.log(chalk.gray(' To explanation:'), conn.toExplanation);
|
|
193
|
+
}
|
|
194
|
+
console.log();
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Failed to list connections');
|
|
198
|
+
}
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
connections
|
|
205
|
+
.command('human-accept')
|
|
206
|
+
.description('Accept a connection as a human (approves the contact relationship)')
|
|
207
|
+
.requiredOption('-i, --id <id>', 'Connection ID')
|
|
208
|
+
.action(async (options) => {
|
|
209
|
+
try {
|
|
210
|
+
const { client } = await getHumanAuthenticatedClient();
|
|
211
|
+
|
|
212
|
+
const response = await client.post(`/v1/connections/${options.id}/human-accept`);
|
|
213
|
+
|
|
214
|
+
if (response.success) {
|
|
215
|
+
console.log(chalk.green('✓ Connection accepted as human!'));
|
|
216
|
+
console.log(chalk.gray('ID:'), options.id);
|
|
217
|
+
} else {
|
|
218
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Failed to accept connection');
|
|
219
|
+
}
|
|
220
|
+
} catch (error) {
|
|
221
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
connections
|
|
226
|
+
.command('revoke')
|
|
227
|
+
.description('Revoke a connection (deletes bidirectional contacts if connected)')
|
|
228
|
+
.requiredOption('-i, --id <id>', 'Connection ID')
|
|
229
|
+
.action(async (options) => {
|
|
230
|
+
try {
|
|
231
|
+
const { client } = await getHumanAuthenticatedClient();
|
|
232
|
+
|
|
233
|
+
const response = await client.post(`/v1/connections/${options.id}/revoke`);
|
|
234
|
+
|
|
235
|
+
if (response.success) {
|
|
236
|
+
console.log(chalk.green('✓ Connection revoked.'));
|
|
237
|
+
console.log(chalk.gray('ID:'), options.id);
|
|
238
|
+
} else {
|
|
239
|
+
console.error(chalk.red('Error:'), response.error?.message || 'Failed to revoke connection');
|
|
240
|
+
}
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function getHumansApiUrl(): Promise<string> {
|
|
248
|
+
const config = await configManager.getGlobalConfig();
|
|
249
|
+
return (config as any).humansApiUrl || DEFAULT_HUMANS_API_URL;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function formatTimestamp(ts: any): string {
|
|
253
|
+
if (!ts) return 'unknown';
|
|
254
|
+
if (ts._seconds) {
|
|
255
|
+
return new Date(ts._seconds * 1000).toISOString();
|
|
256
|
+
}
|
|
257
|
+
if (typeof ts === 'string' || typeof ts === 'number') {
|
|
258
|
+
return new Date(ts).toISOString();
|
|
259
|
+
}
|
|
260
|
+
return String(ts);
|
|
261
|
+
}
|