langmart-gateway-type3 3.0.45 → 3.0.47

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 (58) hide show
  1. package/dist/admin-tools.d.ts +46 -0
  2. package/dist/admin-tools.d.ts.map +1 -0
  3. package/dist/admin-tools.js +933 -0
  4. package/dist/admin-tools.js.map +1 -0
  5. package/dist/agent-tools.d.ts +38 -0
  6. package/dist/agent-tools.d.ts.map +1 -0
  7. package/dist/agent-tools.js +813 -0
  8. package/dist/agent-tools.js.map +1 -0
  9. package/dist/billing-tools.d.ts +25 -0
  10. package/dist/billing-tools.d.ts.map +1 -0
  11. package/dist/billing-tools.js +283 -0
  12. package/dist/billing-tools.js.map +1 -0
  13. package/dist/cli.d.ts +2 -0
  14. package/dist/cli.d.ts.map +1 -0
  15. package/dist/cli.js +792 -0
  16. package/dist/cli.js.map +1 -0
  17. package/dist/collection-tools.d.ts +26 -0
  18. package/dist/collection-tools.d.ts.map +1 -0
  19. package/dist/collection-tools.js +347 -0
  20. package/dist/collection-tools.js.map +1 -0
  21. package/dist/lib/tool-schema-validator.d.ts +35 -0
  22. package/dist/lib/tool-schema-validator.d.ts.map +1 -0
  23. package/dist/lib/tool-schema-validator.js +146 -0
  24. package/dist/lib/tool-schema-validator.js.map +1 -0
  25. package/dist/marketplace-tools.d.ts +116 -0
  26. package/dist/marketplace-tools.d.ts.map +1 -0
  27. package/dist/marketplace-tools.js +3089 -0
  28. package/dist/marketplace-tools.js.map +1 -0
  29. package/dist/organization-tools.d.ts +37 -0
  30. package/dist/organization-tools.d.ts.map +1 -0
  31. package/dist/organization-tools.js +609 -0
  32. package/dist/organization-tools.js.map +1 -0
  33. package/dist/seller-tools.d.ts +28 -0
  34. package/dist/seller-tools.d.ts.map +1 -0
  35. package/dist/seller-tools.js +437 -0
  36. package/dist/seller-tools.js.map +1 -0
  37. package/dist/support-tools.d.ts +23 -0
  38. package/dist/support-tools.d.ts.map +1 -0
  39. package/dist/support-tools.js +292 -0
  40. package/dist/support-tools.js.map +1 -0
  41. package/dist/test-key-redaction-integration.d.ts +7 -0
  42. package/dist/test-key-redaction-integration.d.ts.map +1 -0
  43. package/dist/test-key-redaction-integration.js +80 -0
  44. package/dist/test-key-redaction-integration.js.map +1 -0
  45. package/dist/test-key-redaction.d.ts +6 -0
  46. package/dist/test-key-redaction.d.ts.map +1 -0
  47. package/dist/test-key-redaction.js +115 -0
  48. package/dist/test-key-redaction.js.map +1 -0
  49. package/dist/test-vault-migration.d.ts +2 -0
  50. package/dist/test-vault-migration.d.ts.map +1 -0
  51. package/dist/test-vault-migration.js +130 -0
  52. package/dist/test-vault-migration.js.map +1 -0
  53. package/dist/user-tools.d.ts +40 -0
  54. package/dist/user-tools.d.ts.map +1 -0
  55. package/dist/user-tools.js +685 -0
  56. package/dist/user-tools.js.map +1 -0
  57. package/package.json +2 -70
  58. package/scripts/start.ps1 +24 -3
@@ -0,0 +1,685 @@
1
+ "use strict";
2
+ /**
3
+ * User Tools - MCP Tools for User Account Management
4
+ *
5
+ * Provides tools for:
6
+ * - API key management (list, create, delete, rotate)
7
+ * - Model mappings (aliases)
8
+ * - Account info (balance, usage)
9
+ * - Analytics (request logs, errors)
10
+ * - Alerts management
11
+ * - Quota status
12
+ */
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.UserTools = exports.userToolDefinitions = void 0;
18
+ const axios_1 = __importDefault(require("axios"));
19
+ // ============= TOOL DEFINITIONS =============
20
+ exports.userToolDefinitions = [
21
+ // ===== API KEYS =====
22
+ {
23
+ type: 'function',
24
+ function: {
25
+ name: 'user_api_keys_list',
26
+ description: 'List all API keys for the current user. Response includes key_id (use with user_api_keys_delete or user_api_keys_rotate), organization_id (use organizations_get for org details). Shows key prefix, name, creation date, and last used date.',
27
+ parameters: {
28
+ type: 'object',
29
+ properties: {},
30
+ required: []
31
+ }
32
+ },
33
+ metadata: {
34
+ category: 'api_keys',
35
+ defaultEnabled: false, // Sensitive - user must enable
36
+ adminOnly: false,
37
+ destructive: false,
38
+ requiresConfirmation: false,
39
+ apiEndpoint: '/api/keys',
40
+ apiMethod: 'GET',
41
+ tags: ['api_keys', 'list', 'security']
42
+ }
43
+ },
44
+ {
45
+ type: 'function',
46
+ function: {
47
+ name: 'user_api_keys_create',
48
+ description: 'Create a new API key. The full key is only shown once at creation time - save it immediately. Optionally specify a name and expiration.',
49
+ parameters: {
50
+ type: 'object',
51
+ properties: {
52
+ name: {
53
+ type: 'string',
54
+ description: 'Human-readable name for this API key (e.g., "Production Server", "Dev Laptop")'
55
+ },
56
+ expires_in_days: {
57
+ type: 'number',
58
+ description: 'Number of days until the key expires. Leave empty for no expiration.',
59
+ minimum: 1,
60
+ maximum: 365
61
+ }
62
+ },
63
+ required: []
64
+ }
65
+ },
66
+ metadata: {
67
+ category: 'api_keys',
68
+ defaultEnabled: false,
69
+ adminOnly: false,
70
+ destructive: false,
71
+ requiresConfirmation: true,
72
+ apiEndpoint: '/api/keys',
73
+ apiMethod: 'POST',
74
+ tags: ['api_keys', 'create', 'security']
75
+ }
76
+ },
77
+ {
78
+ type: 'function',
79
+ function: {
80
+ name: 'user_api_keys_delete',
81
+ description: 'Delete an API key permanently. key_id must be obtained from user_api_keys_list first. Any applications using this key will immediately lose access.',
82
+ parameters: {
83
+ type: 'object',
84
+ properties: {
85
+ key_id: {
86
+ type: 'string',
87
+ description: 'The ID of the API key to delete. Use user.api_keys_list to find key IDs.'
88
+ }
89
+ },
90
+ required: ['key_id']
91
+ }
92
+ },
93
+ metadata: {
94
+ category: 'api_keys',
95
+ defaultEnabled: false,
96
+ adminOnly: false,
97
+ destructive: true,
98
+ requiresConfirmation: true,
99
+ apiEndpoint: '/api/keys/:id',
100
+ apiMethod: 'DELETE',
101
+ tags: ['api_keys', 'delete', 'security']
102
+ }
103
+ },
104
+ {
105
+ type: 'function',
106
+ function: {
107
+ name: 'user_api_keys_rotate',
108
+ description: 'Rotate an API key, generating a new key value while keeping the same key ID and settings. The old key becomes invalid immediately.',
109
+ parameters: {
110
+ type: 'object',
111
+ properties: {
112
+ key_id: {
113
+ type: 'string',
114
+ description: 'The ID of the API key to rotate. Use user.api_keys_list to find key IDs.'
115
+ }
116
+ },
117
+ required: ['key_id']
118
+ }
119
+ },
120
+ metadata: {
121
+ category: 'api_keys',
122
+ defaultEnabled: false,
123
+ adminOnly: false,
124
+ destructive: true,
125
+ requiresConfirmation: true,
126
+ apiEndpoint: '/api/keys/:id/rotate',
127
+ apiMethod: 'POST',
128
+ tags: ['api_keys', 'rotate', 'security']
129
+ }
130
+ },
131
+ // ===== MODEL MAPPINGS =====
132
+ {
133
+ type: 'function',
134
+ function: {
135
+ name: 'user_model_mappings_list',
136
+ description: 'List all model mappings (aliases) for the current user. Model mappings let you create aliases for models (e.g., map "gpt-4" to "groq/llama-3.3-70b-versatile").',
137
+ parameters: {
138
+ type: 'object',
139
+ properties: {},
140
+ required: []
141
+ }
142
+ },
143
+ metadata: {
144
+ category: 'mappings',
145
+ defaultEnabled: true,
146
+ adminOnly: false,
147
+ destructive: false,
148
+ requiresConfirmation: false,
149
+ apiEndpoint: '/api/user/model-mappings',
150
+ apiMethod: 'GET',
151
+ tags: ['mappings', 'list']
152
+ }
153
+ },
154
+ {
155
+ type: 'function',
156
+ function: {
157
+ name: 'user_model_mappings_create',
158
+ description: 'Create a model mapping (alias). When you request the alias model, it will be routed to the target model. Useful for using familiar model names with different providers.',
159
+ parameters: {
160
+ type: 'object',
161
+ properties: {
162
+ alias: {
163
+ type: 'string',
164
+ description: 'The alias name to create (e.g., "gpt-4", "my-model", "fast-model")',
165
+ examples: ['gpt-4', 'my-model', 'fast-model']
166
+ },
167
+ target_model_id: {
168
+ type: 'string',
169
+ description: 'The actual model to route to (e.g., "groq/llama-3.3-70b-versatile", "openai/gpt-4o")',
170
+ examples: ['groq/llama-3.3-70b-versatile', 'openai/gpt-4o']
171
+ }
172
+ },
173
+ required: ['alias', 'target_model_id']
174
+ }
175
+ },
176
+ metadata: {
177
+ category: 'mappings',
178
+ defaultEnabled: true,
179
+ adminOnly: false,
180
+ destructive: false,
181
+ requiresConfirmation: false,
182
+ apiEndpoint: '/api/user/model-mappings',
183
+ apiMethod: 'POST',
184
+ tags: ['mappings', 'create']
185
+ }
186
+ },
187
+ {
188
+ type: 'function',
189
+ function: {
190
+ name: 'user_model_mappings_delete',
191
+ description: 'Delete a model mapping. The alias will no longer route to the target model.',
192
+ parameters: {
193
+ type: 'object',
194
+ properties: {
195
+ mapping_id: {
196
+ type: 'string',
197
+ description: 'The ID of the mapping to delete. Use user.model_mappings_list to find IDs.'
198
+ }
199
+ },
200
+ required: ['mapping_id']
201
+ }
202
+ },
203
+ metadata: {
204
+ category: 'mappings',
205
+ defaultEnabled: true,
206
+ adminOnly: false,
207
+ destructive: true,
208
+ requiresConfirmation: true,
209
+ apiEndpoint: '/api/user/model-mappings/:id',
210
+ apiMethod: 'DELETE',
211
+ tags: ['mappings', 'delete']
212
+ }
213
+ },
214
+ // ===== ACCOUNT / BILLING =====
215
+ {
216
+ type: 'function',
217
+ function: {
218
+ name: 'user_account_balance',
219
+ description: 'Get the current account balance and credit information.',
220
+ parameters: {
221
+ type: 'object',
222
+ properties: {},
223
+ required: []
224
+ }
225
+ },
226
+ metadata: {
227
+ category: 'billing',
228
+ defaultEnabled: false,
229
+ adminOnly: false,
230
+ destructive: false,
231
+ requiresConfirmation: false,
232
+ apiEndpoint: '/api/billing/balance',
233
+ apiMethod: 'GET',
234
+ tags: ['billing', 'balance']
235
+ }
236
+ },
237
+ {
238
+ type: 'function',
239
+ function: {
240
+ name: 'user_account_usage',
241
+ description: 'Get usage summary including total requests, tokens, and costs over a time period.',
242
+ parameters: {
243
+ type: 'object',
244
+ properties: {
245
+ period: {
246
+ type: 'string',
247
+ description: 'Time period for usage data',
248
+ enum: ['today', 'week', 'month', 'all'],
249
+ default: 'month'
250
+ }
251
+ },
252
+ required: []
253
+ }
254
+ },
255
+ metadata: {
256
+ category: 'analytics',
257
+ defaultEnabled: true,
258
+ adminOnly: false,
259
+ destructive: false,
260
+ requiresConfirmation: false,
261
+ apiEndpoint: '/api/billing/usage/breakdown',
262
+ apiMethod: 'GET',
263
+ tags: ['analytics', 'usage']
264
+ }
265
+ },
266
+ // ===== ANALYTICS =====
267
+ {
268
+ type: 'function',
269
+ function: {
270
+ name: 'user_analytics_errors',
271
+ description: 'Get error analytics showing error rates, types, and trends. Use to identify and debug API issues.',
272
+ parameters: {
273
+ type: 'object',
274
+ properties: {
275
+ period: {
276
+ type: 'string',
277
+ description: 'Time period for error data',
278
+ enum: ['hour', 'day', 'week', 'month'],
279
+ default: 'day'
280
+ }
281
+ },
282
+ required: []
283
+ }
284
+ },
285
+ metadata: {
286
+ category: 'analytics',
287
+ defaultEnabled: true,
288
+ adminOnly: false,
289
+ destructive: false,
290
+ requiresConfirmation: false,
291
+ apiEndpoint: '/api/account/errors',
292
+ apiMethod: 'GET',
293
+ tags: ['analytics', 'errors']
294
+ }
295
+ },
296
+ // ===== ALERTS =====
297
+ {
298
+ type: 'function',
299
+ function: {
300
+ name: 'user_alerts_list',
301
+ description: 'List all configured alerts for quota limits, error thresholds, cost limits, etc.',
302
+ parameters: {
303
+ type: 'object',
304
+ properties: {},
305
+ required: []
306
+ }
307
+ },
308
+ metadata: {
309
+ category: 'alerts',
310
+ defaultEnabled: true,
311
+ adminOnly: false,
312
+ destructive: false,
313
+ requiresConfirmation: false,
314
+ apiEndpoint: '/api/account/alerts',
315
+ apiMethod: 'GET',
316
+ tags: ['alerts', 'list']
317
+ }
318
+ },
319
+ {
320
+ type: 'function',
321
+ function: {
322
+ name: 'user_alerts_create',
323
+ description: 'Create a new alert to be notified when certain thresholds are reached (quota warning, error rate, latency, cost).',
324
+ parameters: {
325
+ type: 'object',
326
+ properties: {
327
+ type: {
328
+ type: 'string',
329
+ description: 'Type of alert',
330
+ enum: ['quota_warning', 'error_rate', 'latency', 'cost']
331
+ },
332
+ threshold: {
333
+ type: 'number',
334
+ description: 'Threshold value to trigger the alert (e.g., 80 for 80% quota, 5 for 5% error rate)'
335
+ },
336
+ notification_method: {
337
+ type: 'string',
338
+ description: 'How to be notified when alert triggers',
339
+ enum: ['email', 'webhook'],
340
+ default: 'email'
341
+ },
342
+ webhook_url: {
343
+ type: 'string',
344
+ description: 'Webhook URL (required if notification_method is webhook)'
345
+ }
346
+ },
347
+ required: ['type', 'threshold']
348
+ }
349
+ },
350
+ metadata: {
351
+ category: 'alerts',
352
+ defaultEnabled: true,
353
+ adminOnly: false,
354
+ destructive: false,
355
+ requiresConfirmation: false,
356
+ apiEndpoint: '/api/account/alerts',
357
+ apiMethod: 'POST',
358
+ tags: ['alerts', 'create']
359
+ }
360
+ },
361
+ {
362
+ type: 'function',
363
+ function: {
364
+ name: 'user_alerts_delete',
365
+ description: 'Delete an alert. You will no longer receive notifications for this alert.',
366
+ parameters: {
367
+ type: 'object',
368
+ properties: {
369
+ alert_id: {
370
+ type: 'string',
371
+ description: 'The ID of the alert to delete. Use user.alerts_list to find IDs.'
372
+ }
373
+ },
374
+ required: ['alert_id']
375
+ }
376
+ },
377
+ metadata: {
378
+ category: 'alerts',
379
+ defaultEnabled: true,
380
+ adminOnly: false,
381
+ destructive: true,
382
+ requiresConfirmation: true,
383
+ apiEndpoint: '/api/account/alerts/:id',
384
+ apiMethod: 'DELETE',
385
+ tags: ['alerts', 'delete']
386
+ }
387
+ },
388
+ // ===== QUOTA =====
389
+ {
390
+ type: 'function',
391
+ function: {
392
+ name: 'user_quota_status',
393
+ description: 'Get current quota usage status including limits and remaining allowance for requests, tokens, and cost.',
394
+ parameters: {
395
+ type: 'object',
396
+ properties: {},
397
+ required: []
398
+ }
399
+ },
400
+ metadata: {
401
+ category: 'billing',
402
+ defaultEnabled: true,
403
+ adminOnly: false,
404
+ destructive: false,
405
+ requiresConfirmation: false,
406
+ apiEndpoint: '/api/user/quota/status',
407
+ apiMethod: 'GET',
408
+ tags: ['quota', 'status']
409
+ }
410
+ },
411
+ // ===== ORGANIZATION SWITCH =====
412
+ {
413
+ type: 'function',
414
+ function: {
415
+ name: 'user_switch_organization',
416
+ description: 'Switch the primary organization context. This affects which connections and models are visible by default.',
417
+ parameters: {
418
+ type: 'object',
419
+ properties: {
420
+ organization_id: {
421
+ type: 'string',
422
+ description: 'Organization ID to switch to. Use organizations.list to see available organizations.'
423
+ }
424
+ },
425
+ required: ['organization_id']
426
+ }
427
+ },
428
+ metadata: {
429
+ category: 'organizations',
430
+ defaultEnabled: true,
431
+ adminOnly: false,
432
+ destructive: false,
433
+ requiresConfirmation: false,
434
+ apiEndpoint: '/api/user/primary-organization',
435
+ apiMethod: 'PUT',
436
+ tags: ['organizations', 'switch']
437
+ }
438
+ }
439
+ ];
440
+ // ============= TOOL EXECUTOR =============
441
+ class UserTools {
442
+ constructor(registryUrl, apiKey) {
443
+ this.registryUrl = registryUrl;
444
+ this.apiKey = apiKey;
445
+ this.client = axios_1.default.create({
446
+ baseURL: registryUrl,
447
+ timeout: 30000,
448
+ headers: {
449
+ 'Authorization': `Bearer ${apiKey}`,
450
+ 'Content-Type': 'application/json'
451
+ }
452
+ });
453
+ }
454
+ static getInstance(registryUrl, apiKey) {
455
+ if (!UserTools.instance && registryUrl && apiKey) {
456
+ UserTools.instance = new UserTools(registryUrl, apiKey);
457
+ }
458
+ if (!UserTools.instance) {
459
+ throw new Error('UserTools not initialized. Provide registryUrl and apiKey.');
460
+ }
461
+ return UserTools.instance;
462
+ }
463
+ getTools() {
464
+ return exports.userToolDefinitions;
465
+ }
466
+ async executeTool(toolName, args) {
467
+ try {
468
+ switch (toolName) {
469
+ // API Keys
470
+ case 'user_api_keys_list':
471
+ return await this.listApiKeys();
472
+ case 'user_api_keys_create':
473
+ return await this.createApiKey(args);
474
+ case 'user_api_keys_delete':
475
+ return await this.deleteApiKey(args.key_id);
476
+ case 'user_api_keys_rotate':
477
+ return await this.rotateApiKey(args.key_id);
478
+ // Model Mappings
479
+ case 'user_model_mappings_list':
480
+ return await this.listMappings();
481
+ case 'user_model_mappings_create':
482
+ return await this.createMapping(args);
483
+ case 'user_model_mappings_delete':
484
+ return await this.deleteMapping(args.mapping_id);
485
+ // Account
486
+ case 'user_account_balance':
487
+ return await this.getBalance();
488
+ case 'user_account_usage':
489
+ return await this.getUsage(args);
490
+ // Analytics
491
+ case 'user_analytics_errors':
492
+ return await this.getErrors(args);
493
+ // Alerts
494
+ case 'user_alerts_list':
495
+ return await this.listAlerts();
496
+ case 'user_alerts_create':
497
+ return await this.createAlert(args);
498
+ case 'user_alerts_delete':
499
+ return await this.deleteAlert(args.alert_id);
500
+ // Quota
501
+ case 'user_quota_status':
502
+ return await this.getQuotaStatus();
503
+ // Organization
504
+ case 'user_switch_organization':
505
+ return await this.switchOrganization(args.organization_id);
506
+ default:
507
+ return { success: false, error: `Unknown user tool: ${toolName}` };
508
+ }
509
+ }
510
+ catch (error) {
511
+ const message = error.response?.data?.error?.message || error.message;
512
+ return { success: false, error: message };
513
+ }
514
+ }
515
+ // ===== API KEYS =====
516
+ async listApiKeys() {
517
+ const response = await this.client.get('/api/keys');
518
+ const keys = response.data.keys || response.data;
519
+ if (!keys || keys.length === 0) {
520
+ return { success: true, output: 'No API keys found.' };
521
+ }
522
+ const lines = ['**API Keys:**', ''];
523
+ keys.forEach((key, i) => {
524
+ lines.push(`[${i + 1}] ${key.name || 'Unnamed Key'}`);
525
+ lines.push(` ID: ${key.id}`);
526
+ lines.push(` Prefix: ${key.prefix || key.key_prefix}...`);
527
+ lines.push(` Created: ${new Date(key.created_at).toLocaleDateString()}`);
528
+ if (key.last_used_at) {
529
+ lines.push(` Last Used: ${new Date(key.last_used_at).toLocaleDateString()}`);
530
+ }
531
+ lines.push('');
532
+ });
533
+ return { success: true, output: lines.join('\n') };
534
+ }
535
+ async createApiKey(args) {
536
+ const response = await this.client.post('/api/keys', {
537
+ name: args.name,
538
+ expires_in_days: args.expires_in_days
539
+ });
540
+ const key = response.data;
541
+ return {
542
+ success: true,
543
+ output: `✅ API Key Created!\n\n**Key:** ${key.key}\n**ID:** ${key.id}\n**Name:** ${key.name || 'Unnamed'}\n\n⚠️ **Save this key now** - you won't be able to see it again!`
544
+ };
545
+ }
546
+ async deleteApiKey(keyId) {
547
+ await this.client.delete(`/api/keys/${keyId}`);
548
+ return { success: true, output: `✅ API Key ${keyId} deleted successfully.` };
549
+ }
550
+ async rotateApiKey(keyId) {
551
+ const response = await this.client.post(`/api/keys/${keyId}/rotate`);
552
+ const key = response.data;
553
+ return {
554
+ success: true,
555
+ output: `✅ API Key Rotated!\n\n**New Key:** ${key.key}\n**ID:** ${key.id}\n\n⚠️ **Save this key now** - the old key is now invalid!`
556
+ };
557
+ }
558
+ // ===== MODEL MAPPINGS =====
559
+ async listMappings() {
560
+ const response = await this.client.get('/api/user/model-mappings');
561
+ const mappings = response.data.mappings || response.data;
562
+ if (!mappings || mappings.length === 0) {
563
+ return { success: true, output: 'No model mappings configured.' };
564
+ }
565
+ const lines = ['**Model Mappings:**', ''];
566
+ mappings.forEach((m, i) => {
567
+ lines.push(`[${i + 1}] "${m.alias}" → ${m.target_model_id}`);
568
+ lines.push(` ID: ${m.id}`);
569
+ lines.push('');
570
+ });
571
+ return { success: true, output: lines.join('\n') };
572
+ }
573
+ async createMapping(args) {
574
+ const response = await this.client.post('/api/user/model-mappings', {
575
+ alias: args.alias,
576
+ target_model_id: args.target_model_id
577
+ });
578
+ return {
579
+ success: true,
580
+ output: `✅ Model mapping created!\n\n"${args.alias}" → ${args.target_model_id}`
581
+ };
582
+ }
583
+ async deleteMapping(mappingId) {
584
+ await this.client.delete(`/api/user/model-mappings/${mappingId}`);
585
+ return { success: true, output: `✅ Model mapping ${mappingId} deleted.` };
586
+ }
587
+ // ===== ACCOUNT =====
588
+ async getBalance() {
589
+ const response = await this.client.get('/api/account/balance');
590
+ const data = response.data;
591
+ return {
592
+ success: true,
593
+ output: `**Account Balance**\n\nBalance: $${data.balance?.toFixed(2) || '0.00'}\nAvailable: $${data.available?.toFixed(2) || '0.00'}\nCurrency: ${data.currency || 'USD'}`
594
+ };
595
+ }
596
+ async getUsage(args) {
597
+ const response = await this.client.get('/api/billing/usage/breakdown', {
598
+ params: { period: args.period || 'month' }
599
+ });
600
+ const data = response.data;
601
+ const lines = [`**Usage (${args.period || 'month'})**`, ''];
602
+ lines.push(`Total Requests: ${data.total_requests || 0}`);
603
+ lines.push(`Total Tokens: ${data.total_tokens || 0}`);
604
+ lines.push(`Total Cost: $${data.total_cost?.toFixed(4) || '0.00'}`);
605
+ return { success: true, output: lines.join('\n') };
606
+ }
607
+ // ===== ANALYTICS =====
608
+ async getErrors(args) {
609
+ const response = await this.client.get('/api/account/errors', {
610
+ params: { period: args.period || 'day' }
611
+ });
612
+ const data = response.data;
613
+ const lines = [`**Error Analytics (${args.period || 'day'})**`, ''];
614
+ lines.push(`Total Errors: ${data.total_errors || 0}`);
615
+ lines.push(`Error Rate: ${data.error_rate?.toFixed(2) || 0}%`);
616
+ if (data.by_type && Object.keys(data.by_type).length > 0) {
617
+ lines.push('', '**By Type:**');
618
+ Object.entries(data.by_type).forEach(([type, count]) => {
619
+ lines.push(` ${type}: ${count}`);
620
+ });
621
+ }
622
+ return { success: true, output: lines.join('\n') };
623
+ }
624
+ // ===== ALERTS =====
625
+ async listAlerts() {
626
+ const response = await this.client.get('/api/account/alerts');
627
+ const alerts = response.data.alerts || response.data;
628
+ if (!alerts || alerts.length === 0) {
629
+ return { success: true, output: 'No alerts configured.' };
630
+ }
631
+ const lines = ['**Alerts:**', ''];
632
+ alerts.forEach((a, i) => {
633
+ lines.push(`[${i + 1}] ${a.type} (threshold: ${a.threshold})`);
634
+ lines.push(` ID: ${a.id}`);
635
+ lines.push(` Notification: ${a.notification_method}`);
636
+ lines.push(` Status: ${a.enabled ? 'Enabled' : 'Disabled'}`);
637
+ lines.push('');
638
+ });
639
+ return { success: true, output: lines.join('\n') };
640
+ }
641
+ async createAlert(args) {
642
+ const response = await this.client.post('/api/account/alerts', args);
643
+ return {
644
+ success: true,
645
+ output: `✅ Alert created!\n\nType: ${args.type}\nThreshold: ${args.threshold}\nNotification: ${args.notification_method || 'email'}`
646
+ };
647
+ }
648
+ async deleteAlert(alertId) {
649
+ await this.client.delete(`/api/account/alerts/${alertId}`);
650
+ return { success: true, output: `✅ Alert ${alertId} deleted.` };
651
+ }
652
+ // ===== QUOTA =====
653
+ async getQuotaStatus() {
654
+ const response = await this.client.get('/api/user/quota/status');
655
+ const data = response.data;
656
+ const lines = ['**Quota Status**', ''];
657
+ if (data.daily) {
658
+ lines.push('**Daily:**');
659
+ lines.push(` Requests: ${data.daily.requests_used}/${data.daily.requests_limit || '∞'}`);
660
+ lines.push(` Tokens: ${data.daily.tokens_used}/${data.daily.tokens_limit || '∞'}`);
661
+ lines.push(` Cost: $${data.daily.cost_used?.toFixed(4) || 0}/$${data.daily.cost_limit || '∞'}`);
662
+ }
663
+ if (data.monthly) {
664
+ lines.push('', '**Monthly:**');
665
+ lines.push(` Requests: ${data.monthly.requests_used}/${data.monthly.requests_limit || '∞'}`);
666
+ lines.push(` Tokens: ${data.monthly.tokens_used}/${data.monthly.tokens_limit || '∞'}`);
667
+ lines.push(` Cost: $${data.monthly.cost_used?.toFixed(4) || 0}/$${data.monthly.cost_limit || '∞'}`);
668
+ }
669
+ return { success: true, output: lines.join('\n') };
670
+ }
671
+ // ===== ORGANIZATION =====
672
+ async switchOrganization(orgId) {
673
+ await this.client.put('/api/user/primary-organization', {
674
+ organization_id: orgId
675
+ });
676
+ return {
677
+ success: true,
678
+ output: `✅ Switched to organization ${orgId}`
679
+ };
680
+ }
681
+ }
682
+ exports.UserTools = UserTools;
683
+ UserTools.instance = null;
684
+ exports.default = UserTools;
685
+ //# sourceMappingURL=user-tools.js.map