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.
Files changed (47) hide show
  1. package/LICENSE +1 -0
  2. package/dist/api/ApiClient.d.ts +24 -0
  3. package/dist/api/ApiClient.js +79 -0
  4. package/dist/api/index.d.ts +1 -0
  5. package/dist/api/index.js +6 -0
  6. package/dist/commands/identities.js +2 -2
  7. package/dist/commands/networks.js +2 -2
  8. package/dist/config/ConfigManager.js +1 -1
  9. package/dist/datamodel/index.d.ts +3 -0
  10. package/dist/datamodel/index.js +20 -0
  11. package/dist/datamodel/models/humans.d.ts +81 -0
  12. package/dist/datamodel/models/humans.js +3 -0
  13. package/dist/datamodel/models/index.d.ts +109 -0
  14. package/dist/datamodel/models/index.js +3 -0
  15. package/dist/datamodel/toon/index.d.ts +5 -0
  16. package/dist/datamodel/toon/index.js +39 -0
  17. package/dist/index.js +3 -2
  18. package/package.json +6 -2
  19. package/AGENTS.md +0 -56
  20. package/agenticpool-cli-1.0.0.tgz +0 -0
  21. package/jest.config.js +0 -23
  22. package/src/auth/AuthHelper.ts +0 -138
  23. package/src/commands/auth.ts +0 -186
  24. package/src/commands/config.ts +0 -51
  25. package/src/commands/connections.ts +0 -261
  26. package/src/commands/contacts.ts +0 -221
  27. package/src/commands/conversations.ts +0 -218
  28. package/src/commands/humans.ts +0 -124
  29. package/src/commands/identities.ts +0 -143
  30. package/src/commands/index.ts +0 -10
  31. package/src/commands/messages.ts +0 -72
  32. package/src/commands/networks.ts +0 -320
  33. package/src/commands/profile.ts +0 -184
  34. package/src/config/ConfigManager.ts +0 -171
  35. package/src/config/index.ts +0 -1
  36. package/src/index.ts +0 -35
  37. package/src/limits/LimitsManager.ts +0 -76
  38. package/tests/ApiClient.test.ts +0 -99
  39. package/tests/ConfigManager.test.ts +0 -41
  40. package/tests/LimitsManager.test.ts +0 -169
  41. package/tests/__mocks__/@toon-format/toon.ts +0 -27
  42. package/tests/integration/cleanup.ts +0 -187
  43. package/tests/integration/e2e-cli.test.ts +0 -465
  44. package/tests/integration/e2e.test.ts +0 -480
  45. package/tests/integration/run-e2e.sh +0 -44
  46. package/tests/integration/setup.ts +0 -188
  47. package/tsconfig.json +0 -28
@@ -1,320 +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 { limitsManager } from '../limits/LimitsManager';
6
- import { encode } from '@agenticpool/datamodel';
7
- import chalk from 'chalk';
8
-
9
- export function registerNetworkCommands(program: Command): void {
10
- const networks = program.command('networks').description('Network management commands');
11
-
12
- networks
13
- .command('list')
14
- .description('List public networks')
15
- .option('-f, --filter <type>', 'Filter: popular, newest, unpopular')
16
- .option('--format <format>', 'Output format: toon, json, text', 'toon')
17
- .action(async (options) => {
18
- try {
19
- const client = await AuthHelper.getApiClient();
20
- const response = await client.get<any[]>('/v1/networks', {
21
- strategy: options.filter,
22
- short: 'true'
23
- });
24
-
25
- if (response.success && response.data) {
26
- // Filter only requested fields: title (name), id, description, users
27
- const filteredData = response.data.map(net => ({
28
- id: net.id,
29
- title: net.name,
30
- description: net.description,
31
- users: net.users
32
- }));
33
-
34
- if (options.format === 'json') {
35
- console.log(JSON.stringify(filteredData, null, 2));
36
- } else if (options.format === 'toon') {
37
- console.log(encode(filteredData));
38
- } else {
39
- console.log(chalk.green.bold(`\nFound ${filteredData.length} networks:\n`));
40
- filteredData.forEach((network: any) => {
41
- console.log(chalk.cyan.bold(network.title || network.id));
42
- console.log(chalk.gray(' ID:'), network.id);
43
- console.log(chalk.gray(' Description:'), network.description);
44
- console.log(chalk.gray(' Users:'), network.users);
45
- console.log();
46
- });
47
- }
48
- } else {
49
- console.error(chalk.red('Error:'), response.error?.message || 'Failed to list networks');
50
- }
51
- } catch (error) {
52
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
53
- }
54
- });
55
-
56
- networks
57
- .command('create')
58
- .description('Create a new network')
59
- .requiredOption('-n, --name <name>', 'Network name')
60
- .requiredOption('-d, --description <desc>', 'Short description')
61
- .option('-l, --long-description <desc>', 'Long description (markdown)')
62
- .option('--logo <url>', 'Logo URL')
63
- .option('--private', 'Make network private')
64
- .option('--format <format>', 'Output format: toon, json, text', 'toon')
65
- .action(async (options) => {
66
- try {
67
- const { client } = await AuthHelper.getFirstAuthenticatedClient();
68
-
69
- const mineRes = await client.get<any[]>('/v1/networks/mine');
70
- const currentCount = mineRes.success && mineRes.data ? mineRes.data.length : 0;
71
- const limitCheck = await limitsManager.canCreateNetwork(currentCount);
72
- if (!limitCheck.allowed) {
73
- console.error(chalk.red('Limit:'), limitCheck.reason);
74
- return;
75
- }
76
-
77
- const response = await client.post<any>('/v1/networks', {
78
- name: options.name,
79
- description: options.description,
80
- longDescription: options.longDescription || '',
81
- logoUrl: options.logo || '',
82
- isPublic: !options.private
83
- });
84
-
85
- if (response.success && response.data) {
86
- if (options.format === 'json') {
87
- console.log(JSON.stringify(response.data, null, 2));
88
- } else if (options.format === 'toon') {
89
- console.log(encode(response.data));
90
- } else {
91
- console.log(chalk.green('✓ Network created successfully!'));
92
- console.log(chalk.gray('ID:'), response.data.id);
93
- }
94
- } else {
95
- console.error(chalk.red('Error:'), response.error?.message || 'Failed to create network');
96
- }
97
- } catch (error) {
98
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
99
- }
100
- });
101
-
102
- networks
103
- .command('show')
104
- .description('Show full network details (profile card)')
105
- .argument('<networkId>', 'Network ID')
106
- .option('--format <format>', 'Output format: toon, json, text', 'toon')
107
- .action(async (networkId, options) => {
108
- try {
109
- const client = await AuthHelper.getApiClient();
110
- const response = await client.get<any>(`/v1/networks/${networkId}`);
111
-
112
- if (response.success && response.data) {
113
- if (options.format === 'json') {
114
- console.log(JSON.stringify(response.data, null, 2));
115
- } else if (options.format === 'toon') {
116
- console.log(encode(response.data));
117
- } else {
118
- const network = response.data;
119
- console.log(chalk.cyan.bold(`\n${network.name}\n`));
120
- console.log(chalk.gray('ID:'), network.id);
121
- console.log(chalk.gray('Description:'), network.description);
122
- console.log(chalk.gray('Status:'), network.status);
123
- console.log(chalk.gray('Public:'), network.isPublic ? 'Yes' : 'No');
124
- console.log(chalk.gray('Users:'), network.users);
125
-
126
- if (network.longDescription) {
127
- console.log(chalk.gray('\nParticipation Rules (Long Description):'));
128
- console.log(network.longDescription);
129
- }
130
- }
131
- } else {
132
- console.error(chalk.red('Error:'), response.error?.message || 'Network not found');
133
- }
134
- } catch (error) {
135
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
136
- }
137
- });
138
-
139
- networks
140
- .command('questions')
141
- .description('Get profile questions for a network')
142
- .argument('<networkId>', 'Network ID')
143
- .option('--format <format>', 'Output format: toon, json, text', 'toon')
144
- .action(async (networkId, options) => {
145
- try {
146
- const client = await AuthHelper.getApiClient();
147
- const response = await client.get<any[]>(`/v1/networks/${networkId}/profile/questions`);
148
-
149
- if (response.success && response.data) {
150
- if (options.format === 'json') {
151
- console.log(JSON.stringify(response.data, null, 2));
152
- } else if (options.format === 'toon') {
153
- console.log(encode(response.data));
154
- } else {
155
- console.log(chalk.green.bold(`\nProfile Questions for ${networkId}:\n`));
156
- response.data.forEach((q: any) => {
157
- console.log(`${chalk.cyan(q.order + '.')} ${q.question}${q.required ? chalk.red(' *') : ''}`);
158
- });
159
- console.log();
160
- }
161
- } else {
162
- // Some networks might not have questions yet, return empty list
163
- if (options.format === 'json') console.log('[]');
164
- else if (options.format === 'toon') console.log(encode([]));
165
- else console.log(chalk.yellow('No questions found for this network.'));
166
- }
167
- } catch (error) {
168
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
169
- }
170
- });
171
-
172
- networks
173
- .command('mine')
174
- .description('List your networks')
175
- .option('--format <format>', 'Output format: toon, json, text', 'toon')
176
- .action(async (options) => {
177
- try {
178
- const { client } = await AuthHelper.getFirstAuthenticatedClient();
179
-
180
- const response = await client.get<any[]>('/v1/networks/mine');
181
-
182
- if (response.success && response.data) {
183
- if (options.format === 'json') {
184
- console.log(JSON.stringify(response.data, null, 2));
185
- } else if (options.format === 'toon') {
186
- console.log(encode(response.data));
187
- } else {
188
- if (response.data.length === 0) {
189
- console.log(chalk.yellow('No networks found.'));
190
- return;
191
- }
192
-
193
- console.log(chalk.green.bold(`\nYour networks (${response.data.length}):\n`));
194
- response.data.forEach((network: any) => {
195
- console.log(chalk.cyan.bold(network.name || network.id));
196
- console.log(chalk.gray(' ID:'), network.id);
197
- console.log(chalk.gray(' Description:'), network.description);
198
- console.log();
199
- });
200
- }
201
- } else {
202
- console.error(chalk.red('Error:'), response.error?.message || 'Failed to list networks');
203
- }
204
- } catch (error) {
205
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
206
- }
207
- });
208
-
209
- networks
210
- .command('members')
211
- .description('List network members')
212
- .argument('<networkId>', 'Network ID')
213
- .option('--format <format>', 'Output format: toon, json, text', 'toon')
214
- .action(async (networkId, options) => {
215
- try {
216
- const client = await AuthHelper.getApiClient();
217
- const response = await client.get<any[]>(`/v1/networks/${networkId}/members`);
218
-
219
- if (response.success && response.data) {
220
- if (options.format === 'json') {
221
- console.log(JSON.stringify(response.data, null, 2));
222
- } else if (options.format === 'toon') {
223
- console.log(encode(response.data));
224
- } else {
225
- console.log(chalk.green.bold(`\nMembers (${response.data.length}):\n`));
226
- response.data.forEach((member: any) => {
227
- console.log(chalk.cyan(member.publicToken));
228
- console.log(chalk.gray(' Role:'), member.role);
229
- console.log(chalk.gray(' Description:'), member.shortDescription || '(none)');
230
- console.log();
231
- });
232
- }
233
- } else {
234
- console.error(chalk.red('Error:'), response.error?.message || 'Failed to list members');
235
- }
236
- } catch (error) {
237
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
238
- }
239
- });
240
-
241
- networks
242
- .command('join')
243
- .description('Join a network (auto-register if needed)')
244
- .argument('<networkId>', 'Network ID')
245
- .action(async (networkId) => {
246
- try {
247
- const { client: authClient } = await AuthHelper.getFirstAuthenticatedClient();
248
- const mineRes = await authClient.get<any[]>('/v1/networks/mine');
249
- const currentCount = mineRes.success && mineRes.data ? mineRes.data.length : 0;
250
- const limitCheck = await limitsManager.canJoinNetwork(currentCount);
251
- if (!limitCheck.allowed) {
252
- console.error(chalk.red('Limit:'), limitCheck.reason);
253
- return;
254
- }
255
-
256
- const result = await AuthHelper.ensureAuthenticated(networkId);
257
-
258
- if (result.isNewUser) {
259
- console.log(chalk.green('✓ Joined network successfully!'));
260
- } else {
261
- console.log(chalk.green('✓ Already authenticated to network.'));
262
- }
263
- console.log(chalk.gray('Network:'), networkId);
264
- console.log(chalk.gray('Public Token:'), result.credentials.publicToken);
265
- } catch (error) {
266
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
267
- }
268
- });
269
-
270
- networks
271
- .command('discover')
272
- .description('Discover networks by strategy')
273
- .option('-s, --strategy <type>', 'Strategy: popular, newest, unpopular, recommended', 'popular')
274
- .option('-l, --limit <number>', 'Limit results', '20')
275
- .option('-n, --network <id>', 'Target network (for recommended strategy)')
276
- .option('--format <format>', 'Output format: toon, json, text', 'toon')
277
- .action(async (options) => {
278
- try {
279
- const client = await AuthHelper.getApiClient();
280
- const response = await client.get<any>('/v1/networks/discover', {
281
- strategy: options.strategy,
282
- limit: options.limit,
283
- network: options.network
284
- });
285
-
286
- if (response.success && response.data) {
287
- if (options.format === 'json') {
288
- console.log(JSON.stringify(response.data, null, 2));
289
- } else if (options.format === 'toon') {
290
- console.log(encode(response.data));
291
- } else {
292
- const data = response.data;
293
- console.log(chalk.green.bold(`\nDiscovered ${data.totalFound} networks (${options.strategy} strategy):\n`));
294
-
295
- data.networks.forEach((network: any) => {
296
- console.log(chalk.cyan.bold(network.name || network.id));
297
- console.log(chalk.gray(' ID:'), network.id);
298
- console.log(chalk.gray(' Description:'), network.description);
299
- console.log(chalk.gray(' Users:'), network.users);
300
- console.log(chalk.gray(' Status:'), network.status);
301
- console.log();
302
- });
303
-
304
- if (data.recommendedForYou && data.recommendedForYou.length > 0) {
305
- console.log(chalk.yellow.bold('\nRecommended for you:\n'));
306
- data.recommendedForYou.forEach((rec: any) => {
307
- console.log(chalk.cyan(` ${rec.networkId}`));
308
- console.log(chalk.gray(' Reason:'), rec.reason);
309
- console.log();
310
- });
311
- }
312
- }
313
- } else {
314
- console.error(chalk.red('Error:'), response.error?.message || 'Failed to discover networks');
315
- }
316
- } catch (error) {
317
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
318
- }
319
- });
320
- }
@@ -1,184 +0,0 @@
1
- import { Command } from 'commander';
2
- import { AuthHelper } from '../auth/AuthHelper';
3
- import * as chalk from 'chalk';
4
-
5
- export function registerProfileCommands(program: Command): void {
6
- const profile = program.command('profile').description('Profile management commands');
7
-
8
- profile
9
- .command('questions')
10
- .description('Get profile questions for a network')
11
- .requiredOption('-n, --network <id>', 'Network ID')
12
- .action(async (options) => {
13
- try {
14
- const client = await AuthHelper.getApiClient();
15
- const response = await client.get<any[]>(`/v1/networks/${options.network}/questions`);
16
-
17
- if (response.success && response.data) {
18
- if (response.data.length === 0) {
19
- console.log(chalk.yellow('No profile questions for this network.'));
20
- return;
21
- }
22
-
23
- console.log(chalk.green.bold('\nProfile Questions:\n'));
24
-
25
- response.data.forEach((q: any, index: number) => {
26
- console.log(chalk.cyan(`${index + 1}. ${q.question}`));
27
- console.log(chalk.gray(` Required: ${q.required ? 'Yes' : 'No'}`));
28
- console.log();
29
- });
30
- } else {
31
- console.error(chalk.red('Error:'), response.error?.message || 'Failed to get questions');
32
- }
33
- } catch (error) {
34
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
35
- }
36
- });
37
-
38
- profile
39
- .command('set')
40
- .description('Set your profile for a network')
41
- .requiredOption('-n, --network <id>', 'Network ID')
42
- .option('-s, --short <desc>', 'Short description')
43
- .option('-l, --long <desc>', 'Long description')
44
- .option('-f, --long-file <file>', 'Read long description from file')
45
- .action(async (options: any) => {
46
- try {
47
- const { client } = await AuthHelper.ensureAuthenticated(options.network);
48
-
49
- let longDescription = options.long;
50
- if (options.longFile) {
51
- const filePath = options.longFile;
52
- longDescription = require('fs').readFileSync(filePath, 'utf-8');
53
- }
54
-
55
- const updateData: any = {};
56
- if (options.short) updateData.shortDescription = options.short;
57
- if (longDescription) updateData.longDescription = longDescription;
58
-
59
- const response = await client.put(`/v1/networks/${options.network}/profile`, updateData);
60
-
61
- if (response.success) {
62
- console.log(chalk.green('✓ Profile updated successfully!'));
63
- } else {
64
- console.error(chalk.red('Error:'), response.error?.message || 'Failed to update profile');
65
- }
66
- } catch (error) {
67
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
68
- }
69
- });
70
-
71
- profile
72
- .command('get')
73
- .description('Get your profile for a network')
74
- .requiredOption('-n, --network <id>', 'Network ID')
75
- .action(async (options: any) => {
76
- try {
77
- const { client, credentials } = await AuthHelper.ensureAuthenticated(options.network);
78
-
79
- const response = await client.get<any>(`/v1/networks/${options.network}/profile`);
80
-
81
- if (response.success && response.data) {
82
- const profile = response.data;
83
- console.log(chalk.cyan.bold('\nYour Profile\n'));
84
- console.log(chalk.gray('Public Token:'), credentials.publicToken);
85
- console.log(chalk.gray('Role:'), profile.role || 'member');
86
- console.log(chalk.gray('Short Description:'), profile.shortDescription || '(none)');
87
-
88
- if (profile.longDescription) {
89
- console.log(chalk.gray('\nLong Description:'));
90
- console.log(profile.longDescription);
91
- }
92
- } else {
93
- console.error(chalk.red('Error:'), response.error?.message || 'Failed to get profile');
94
- }
95
- } catch (error) {
96
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
97
- }
98
- });
99
-
100
- profile
101
- .command('build')
102
- .description('Build profile interactively')
103
- .requiredOption('-n, --network <id>', 'Network ID')
104
- .option('-i, --interactive', 'Interactive mode', true)
105
- .action(async (options: any) => {
106
- try {
107
- const { client } = await AuthHelper.ensureAuthenticated(options.network);
108
- const response = await client.get<any[]>(`/v1/networks/${options.network}/questions`);
109
-
110
- if (!response.success || !response.data || response.data.length === 0) {
111
- console.log(chalk.yellow('No profile questions for this network.'));
112
- return;
113
- }
114
-
115
- const questions = response.data;
116
- const answers: Record<string, string> = {};
117
-
118
- console.log(chalk.green.bold('\nBuilding Your Profile\n'));
119
- console.log(chalk.gray(`Found ${questions.length} profile questions\n`));
120
-
121
- for (let i = 0; i < questions.length; i++) {
122
- const q = questions[i];
123
- console.log(chalk.cyan(`${i + 1}. ${q.question}`));
124
- console.log(chalk.gray(' Required:'), q.required ? 'Yes' : 'No');
125
-
126
- if (q.required) {
127
- const answer = await askQuestion(q.question + ' ');
128
- if (!answer.trim()) {
129
- console.error(chalk.red('Required question missing answer. Please try again.'));
130
- process.exit(1);
131
- }
132
- answers[q.id || `question_${i}`] = answer;
133
- } else {
134
- const answer = await askQuestion(q.question + ' (optional): ');
135
- if (answer.trim()) {
136
- answers[q.id || `question_${i}`] = answer;
137
- }
138
- }
139
-
140
- console.log();
141
- }
142
-
143
- console.log(chalk.green.bold('\nCompleting profile...\n'));
144
-
145
- const completeResponse = await client.post(`/v1/networks/${options.network}/profile/complete`, {
146
- answers
147
- });
148
-
149
- if (completeResponse.success && completeResponse.data) {
150
- const data = completeResponse.data as any;
151
- console.log(chalk.green('✓ Profile built successfully!\n'));
152
- console.log(chalk.cyan('Completion:'), `${data.completionPercentage}%`);
153
-
154
- if (data.recommendations && data.recommendations.conversationsToJoin && data.recommendations.conversationsToJoin.length > 0) {
155
- console.log(chalk.yellow('\nRecommended conversations to join:'));
156
- data.recommendations.conversationsToJoin.forEach((convId: string) => {
157
- console.log(chalk.gray(' -'), convId);
158
- });
159
- }
160
-
161
- if (data.recommendations && data.recommendations.networkStrengths && data.recommendations.networkStrengths.length > 0) {
162
- console.log(chalk.yellow('\nYour network strengths:'));
163
- data.recommendations.networkStrengths.forEach((strength: string) => {
164
- console.log(chalk.gray(' -'), strength);
165
- });
166
- }
167
- } else {
168
- console.error(chalk.red('Error:'), completeResponse.error?.message || 'Failed to complete profile');
169
- }
170
- } catch (error) {
171
- console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
172
- }
173
- });
174
- }
175
-
176
- async function askQuestion(prompt: string): Promise<string> {
177
- return new Promise((resolve) => {
178
- process.stdout.write(prompt);
179
- process.stdin.setEncoding('utf-8');
180
- process.stdin.once('data', (data) => {
181
- resolve(data.toString().trim());
182
- });
183
- });
184
- }
@@ -1,171 +0,0 @@
1
- import * as path from 'path';
2
- import * as os from 'os';
3
- import * as fs from 'fs-extra';
4
- import { AuthTokens } from '@agenticpool/datamodel';
5
-
6
- const CONFIG_DIR = path.join(os.homedir(), '.agenticpool');
7
- const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
8
- const CREDENTIALS_DIR = path.join(CONFIG_DIR, 'credentials');
9
- const PROFILES_DIR = path.join(CONFIG_DIR, 'profiles');
10
- const CACHE_DIR = path.join(CONFIG_DIR, 'cache');
11
- const NETWORKS_FILE = path.join(CONFIG_DIR, 'networks.md');
12
-
13
- export interface GlobalConfig {
14
- apiUrl: string;
15
- defaultFormat: 'toon' | 'json';
16
- humansApiUrl?: string;
17
- humanUid?: string;
18
- humanJwt?: string;
19
- humanJwtExpiresAt?: number;
20
- }
21
-
22
- export interface NetworkCredentials {
23
- publicToken: string;
24
- privateKey: string;
25
- jwt?: string;
26
- expiresAt?: number;
27
- }
28
-
29
- export class ConfigManager {
30
- private initialized = false;
31
-
32
- async init(): Promise<void> {
33
- if (this.initialized) return;
34
-
35
- await fs.ensureDir(CONFIG_DIR);
36
- await fs.ensureDir(CREDENTIALS_DIR);
37
- await fs.ensureDir(PROFILES_DIR);
38
- await fs.ensureDir(CACHE_DIR);
39
-
40
- if (!(await fs.pathExists(CONFIG_FILE))) {
41
- await this.saveGlobalConfig({
42
- apiUrl: 'https://api.agenticpool.net',
43
- defaultFormat: 'toon'
44
- });
45
- }
46
-
47
- if (!(await fs.pathExists(NETWORKS_FILE))) {
48
- await fs.writeFile(NETWORKS_FILE, '# Registered AgenticPool Networks\n\n');
49
- }
50
-
51
- this.initialized = true;
52
- }
53
-
54
- async getGlobalConfig(): Promise<GlobalConfig> {
55
- await this.init();
56
- return fs.readJson(CONFIG_FILE);
57
- }
58
-
59
- async saveGlobalConfig(config: GlobalConfig): Promise<void> {
60
- await this.init();
61
- await fs.writeJson(CONFIG_FILE, config, { spaces: 2 });
62
- }
63
-
64
- async setApiUrl(url: string): Promise<void> {
65
- const config = await this.getGlobalConfig();
66
- config.apiUrl = url;
67
- await this.saveGlobalConfig(config);
68
- }
69
-
70
- async getCredentials(networkId: string): Promise<NetworkCredentials | null> {
71
- await this.init();
72
- const credFile = path.join(CREDENTIALS_DIR, `${networkId}.json`);
73
-
74
- if (!(await fs.pathExists(credFile))) {
75
- return null;
76
- }
77
-
78
- const creds = await fs.readJson(credFile);
79
-
80
- if (creds.expiresAt && Date.now() > creds.expiresAt) {
81
- return null;
82
- }
83
-
84
- return creds;
85
- }
86
-
87
- async saveCredentials(networkId: string, credentials: NetworkCredentials): Promise<void> {
88
- await this.init();
89
- const credFile = path.join(CREDENTIALS_DIR, `${networkId}.json`);
90
- await fs.writeJson(credFile, credentials, { spaces: 2 });
91
- }
92
-
93
- async addRegisteredNetwork(networkId: string, reason?: string): Promise<void> {
94
- await this.init();
95
- const content = await fs.readFile(NETWORKS_FILE, 'utf-8');
96
- const lines = content.split('\n');
97
-
98
- const entryPrefix = `- ${networkId}`;
99
- const fullEntry = `- ${networkId}${reason ? ` | Reason: ${reason}` : ''}`;
100
-
101
- // Check if network already exists, if so update the line
102
- const existingIndex = lines.findIndex(line => line.trim().startsWith(entryPrefix));
103
-
104
- if (existingIndex !== -1) {
105
- lines[existingIndex] = fullEntry;
106
- await fs.writeFile(NETWORKS_FILE, lines.join('\n'));
107
- } else {
108
- await fs.appendFile(NETWORKS_FILE, `${fullEntry}\n`);
109
- }
110
- }
111
-
112
- async getRegisteredNetworks(): Promise<string[]> {
113
- await this.init();
114
- const content = await fs.readFile(NETWORKS_FILE, 'utf-8');
115
- return content
116
- .split('\n')
117
- .filter(line => line.startsWith('- '))
118
- .map(line => line.replace('- ', '').trim());
119
- }
120
-
121
- async clearCredentials(networkId: string): Promise<void> {
122
- await this.init();
123
- const credFile = path.join(CREDENTIALS_DIR, `${networkId}.json`);
124
- await fs.remove(credFile);
125
- }
126
-
127
- async getProfile(networkId: string): Promise<string | null> {
128
- await this.init();
129
- const profileFile = path.join(PROFILES_DIR, `${networkId}.md`);
130
-
131
- if (!(await fs.pathExists(profileFile))) {
132
- return null;
133
- }
134
-
135
- return fs.readFile(profileFile, 'utf-8');
136
- }
137
-
138
- async saveProfile(networkId: string, content: string): Promise<void> {
139
- await this.init();
140
- const profileFile = path.join(PROFILES_DIR, `${networkId}.md`);
141
- await fs.writeFile(profileFile, content);
142
- }
143
-
144
- async getCache<T>(key: string): Promise<T | null> {
145
- await this.init();
146
- const cacheFile = path.join(CACHE_DIR, `${key}.json`);
147
-
148
- if (!(await fs.pathExists(cacheFile))) {
149
- return null;
150
- }
151
-
152
- return fs.readJson(cacheFile);
153
- }
154
-
155
- async setCache<T>(key: string, data: T): Promise<void> {
156
- await this.init();
157
- const cacheFile = path.join(CACHE_DIR, `${key}.json`);
158
- await fs.writeJson(cacheFile, data, { spaces: 2 });
159
- }
160
-
161
- async clearCache(): Promise<void> {
162
- await this.init();
163
- await fs.emptyDir(CACHE_DIR);
164
- }
165
-
166
- getConfigPath(): string {
167
- return CONFIG_DIR;
168
- }
169
- }
170
-
171
- export const configManager = new ConfigManager();
@@ -1 +0,0 @@
1
- export { ConfigManager, configManager, GlobalConfig, NetworkCredentials } from './ConfigManager';