agenticpool 1.0.3 → 1.0.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.
- package/LICENSE +1 -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/commands/identities.js +2 -2
- package/dist/commands/networks.js +2 -2
- package/dist/config/ConfigManager.js +1 -1
- package/dist/datamodel/index.d.ts +3 -0
- package/dist/datamodel/index.js +20 -0
- package/dist/datamodel/models/humans.d.ts +81 -0
- package/dist/datamodel/models/humans.js +3 -0
- package/dist/datamodel/models/index.d.ts +109 -0
- package/dist/datamodel/models/index.js +3 -0
- package/dist/datamodel/toon/index.d.ts +5 -0
- package/dist/datamodel/toon/index.js +39 -0
- package/dist/index.js +3 -2
- package/package.json +6 -2
- package/AGENTS.md +0 -56
- package/agenticpool-cli-1.0.0.tgz +0 -0
- package/jest.config.js +0 -23
- package/src/auth/AuthHelper.ts +0 -138
- package/src/commands/auth.ts +0 -186
- package/src/commands/config.ts +0 -51
- package/src/commands/connections.ts +0 -261
- package/src/commands/contacts.ts +0 -221
- package/src/commands/conversations.ts +0 -218
- package/src/commands/humans.ts +0 -124
- package/src/commands/identities.ts +0 -143
- package/src/commands/index.ts +0 -10
- package/src/commands/messages.ts +0 -72
- package/src/commands/networks.ts +0 -320
- package/src/commands/profile.ts +0 -184
- package/src/config/ConfigManager.ts +0 -171
- package/src/config/index.ts +0 -1
- package/src/index.ts +0 -35
- package/src/limits/LimitsManager.ts +0 -76
- package/tests/ApiClient.test.ts +0 -99
- package/tests/ConfigManager.test.ts +0 -41
- package/tests/LimitsManager.test.ts +0 -169
- package/tests/__mocks__/@toon-format/toon.ts +0 -27
- package/tests/integration/cleanup.ts +0 -187
- package/tests/integration/e2e-cli.test.ts +0 -465
- package/tests/integration/e2e.test.ts +0 -480
- package/tests/integration/run-e2e.sh +0 -44
- package/tests/integration/setup.ts +0 -188
- package/tsconfig.json +0 -28
|
@@ -1,261 +0,0 @@
|
|
|
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
|
-
}
|
package/src/commands/contacts.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { ApiClient } from '../api';
|
|
3
|
-
import { configManager } from '../config';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
|
|
6
|
-
const DEFAULT_HUMANS_API_URL = 'https://us-central1-agenticpool-humans.cloudfunctions.net/api';
|
|
7
|
-
|
|
8
|
-
export function registerContactCommands(program: Command): void {
|
|
9
|
-
const contacts = program.command('contacts').description('Contact management commands');
|
|
10
|
-
|
|
11
|
-
contacts
|
|
12
|
-
.command('list')
|
|
13
|
-
.description('List your contacts')
|
|
14
|
-
.action(async () => {
|
|
15
|
-
try {
|
|
16
|
-
const { client } = await getHumanAuthenticatedClient();
|
|
17
|
-
|
|
18
|
-
const response = await client.get<any[]>('/v1/contacts');
|
|
19
|
-
|
|
20
|
-
if (response.success && response.data) {
|
|
21
|
-
if (response.data.length === 0) {
|
|
22
|
-
console.log(chalk.yellow('No contacts yet.'));
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
console.log(chalk.green.bold(`\nYour Contacts (${response.data.length}):\n`));
|
|
27
|
-
|
|
28
|
-
response.data.forEach((contact: any) => {
|
|
29
|
-
console.log(chalk.cyan.bold(contact.contactDisplayName || contact.contactUid));
|
|
30
|
-
console.log(chalk.gray(' UID:'), contact.contactUid);
|
|
31
|
-
if (contact.contactEmail) {
|
|
32
|
-
console.log(chalk.gray(' Email:'), contact.contactEmail);
|
|
33
|
-
}
|
|
34
|
-
if (contact.contactPhone) {
|
|
35
|
-
console.log(chalk.gray(' Phone:'), contact.contactPhone);
|
|
36
|
-
}
|
|
37
|
-
if (contact.contactTelegram) {
|
|
38
|
-
console.log(chalk.gray(' Telegram:'), contact.contactTelegram);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (contact.linkedIdentities && contact.linkedIdentities.length > 0) {
|
|
42
|
-
console.log(chalk.gray(' Networks:'));
|
|
43
|
-
contact.linkedIdentities.forEach((id: any) => {
|
|
44
|
-
console.log(chalk.gray(' -'), `${id.networkId} (${id.publicToken})`);
|
|
45
|
-
if (id.agentDescription) {
|
|
46
|
-
console.log(chalk.gray(' '), id.agentDescription);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log(chalk.gray(' Status:'), contact.status);
|
|
52
|
-
console.log();
|
|
53
|
-
});
|
|
54
|
-
} else {
|
|
55
|
-
console.error(chalk.red('Error:'), response.error?.message || 'Failed to list contacts');
|
|
56
|
-
}
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
contacts
|
|
63
|
-
.command('show')
|
|
64
|
-
.description('Show full details of a contact')
|
|
65
|
-
.requiredOption('-u, --uid <uid>', 'Contact user UID')
|
|
66
|
-
.action(async (options) => {
|
|
67
|
-
try {
|
|
68
|
-
const { client } = await getHumanAuthenticatedClient();
|
|
69
|
-
|
|
70
|
-
const response = await client.get<any>(`/v1/contacts/${options.uid}`);
|
|
71
|
-
|
|
72
|
-
if (response.success && response.data) {
|
|
73
|
-
const contact = response.data;
|
|
74
|
-
console.log(chalk.cyan.bold(`\n${contact.contactDisplayName || contact.contactUid}\n`));
|
|
75
|
-
console.log(chalk.gray('UID:'), contact.contactUid);
|
|
76
|
-
|
|
77
|
-
if (contact.contactEmail) {
|
|
78
|
-
console.log(chalk.gray('Email:'), contact.contactEmail);
|
|
79
|
-
}
|
|
80
|
-
if (contact.contactPhone) {
|
|
81
|
-
console.log(chalk.gray('Phone:'), contact.contactPhone);
|
|
82
|
-
}
|
|
83
|
-
if (contact.contactTelegram) {
|
|
84
|
-
console.log(chalk.gray('Telegram:'), contact.contactTelegram);
|
|
85
|
-
}
|
|
86
|
-
if (contact.contactPhotoUrl) {
|
|
87
|
-
console.log(chalk.gray('Photo:'), contact.contactPhotoUrl);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (contact.notes) {
|
|
91
|
-
console.log(chalk.gray('\nNotes:'), contact.notes);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
console.log(chalk.gray('Status:'), contact.status);
|
|
95
|
-
|
|
96
|
-
if (contact.connectionId) {
|
|
97
|
-
console.log(chalk.gray('Connection:'), contact.connectionId);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (contact.linkedIdentities && contact.linkedIdentities.length > 0) {
|
|
101
|
-
console.log(chalk.yellow.bold('\nLinked Identities:\n'));
|
|
102
|
-
contact.linkedIdentities.forEach((id: any) => {
|
|
103
|
-
console.log(chalk.cyan(` ${id.networkId}`));
|
|
104
|
-
console.log(chalk.gray(' Token:'), id.publicToken);
|
|
105
|
-
if (id.agentDescription) {
|
|
106
|
-
console.log(chalk.gray(' Description:'), id.agentDescription);
|
|
107
|
-
}
|
|
108
|
-
console.log();
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (contact.createdAt) {
|
|
113
|
-
console.log(chalk.gray('Added:'), formatTimestamp(contact.createdAt));
|
|
114
|
-
}
|
|
115
|
-
} else {
|
|
116
|
-
console.error(chalk.red('Error:'), response.error?.message || 'Contact not found');
|
|
117
|
-
}
|
|
118
|
-
} catch (error) {
|
|
119
|
-
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
contacts
|
|
124
|
-
.command('update')
|
|
125
|
-
.description('Update contact notes')
|
|
126
|
-
.requiredOption('-u, --uid <uid>', 'Contact user UID')
|
|
127
|
-
.requiredOption('-n, --notes <text>', 'Notes about this contact')
|
|
128
|
-
.action(async (options) => {
|
|
129
|
-
try {
|
|
130
|
-
const { client } = await getHumanAuthenticatedClient();
|
|
131
|
-
|
|
132
|
-
const response = await client.put(`/v1/contacts/${options.uid}`, {
|
|
133
|
-
notes: options.notes
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
if (response.success) {
|
|
137
|
-
console.log(chalk.green('✓ Contact updated!'));
|
|
138
|
-
console.log(chalk.gray('UID:'), options.uid);
|
|
139
|
-
} else {
|
|
140
|
-
console.error(chalk.red('Error:'), response.error?.message || 'Failed to update contact');
|
|
141
|
-
}
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
contacts
|
|
148
|
-
.command('block')
|
|
149
|
-
.description('Block a contact (removes bidirectional contacts)')
|
|
150
|
-
.requiredOption('-u, --uid <uid>', 'Contact user UID')
|
|
151
|
-
.action(async (options) => {
|
|
152
|
-
try {
|
|
153
|
-
const { client } = await getHumanAuthenticatedClient();
|
|
154
|
-
|
|
155
|
-
const response = await client.delete(`/v1/contacts/${options.uid}`);
|
|
156
|
-
|
|
157
|
-
if (response.success) {
|
|
158
|
-
console.log(chalk.green('✓ Contact blocked and removed.'));
|
|
159
|
-
console.log(chalk.gray('UID:'), options.uid);
|
|
160
|
-
} else {
|
|
161
|
-
console.error(chalk.red('Error:'), response.error?.message || 'Failed to block contact');
|
|
162
|
-
}
|
|
163
|
-
} catch (error) {
|
|
164
|
-
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
contacts
|
|
169
|
-
.command('link-identity')
|
|
170
|
-
.description('Link a network identity to a contact')
|
|
171
|
-
.requiredOption('-u, --uid <uid>', 'Contact user UID')
|
|
172
|
-
.requiredOption('-i, --identity-id <id>', 'Identity ID to link')
|
|
173
|
-
.action(async (options) => {
|
|
174
|
-
try {
|
|
175
|
-
const { client } = await getHumanAuthenticatedClient();
|
|
176
|
-
|
|
177
|
-
const response = await client.post(`/v1/contacts/${options.uid}/link-identity`, {
|
|
178
|
-
identityId: options.identityId
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
if (response.success) {
|
|
182
|
-
console.log(chalk.green('✓ Identity linked to contact!'));
|
|
183
|
-
console.log(chalk.gray('Contact UID:'), options.uid);
|
|
184
|
-
console.log(chalk.gray('Identity ID:'), options.identityId);
|
|
185
|
-
} else {
|
|
186
|
-
console.error(chalk.red('Error:'), response.error?.message || 'Failed to link identity');
|
|
187
|
-
}
|
|
188
|
-
} catch (error) {
|
|
189
|
-
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async function getHumanAuthenticatedClient(): Promise<{ client: ApiClient; humanUid: string }> {
|
|
195
|
-
const config = await configManager.getGlobalConfig() as any;
|
|
196
|
-
|
|
197
|
-
if (!config.humanJwt || !config.humanUid) {
|
|
198
|
-
throw new Error('Not authenticated as a human. Please log in at humans.agenticpool.net first.');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (config.humanJwtExpiresAt && Date.now() > config.humanJwtExpiresAt) {
|
|
202
|
-
throw new Error('Human session expired. Please log in again at humans.agenticpool.net.');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const humansApiUrl = config.humansApiUrl || DEFAULT_HUMANS_API_URL;
|
|
206
|
-
const client = new ApiClient(humansApiUrl);
|
|
207
|
-
client.setAuthToken(config.humanJwt);
|
|
208
|
-
|
|
209
|
-
return { client, humanUid: config.humanUid };
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function formatTimestamp(ts: any): string {
|
|
213
|
-
if (!ts) return 'unknown';
|
|
214
|
-
if (ts._seconds) {
|
|
215
|
-
return new Date(ts._seconds * 1000).toISOString();
|
|
216
|
-
}
|
|
217
|
-
if (typeof ts === 'string' || typeof ts === 'number') {
|
|
218
|
-
return new Date(ts).toISOString();
|
|
219
|
-
}
|
|
220
|
-
return String(ts);
|
|
221
|
-
}
|