berget 2.2.6 → 2.2.8

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 (145) hide show
  1. package/.github/workflows/publish.yml +2 -2
  2. package/.github/workflows/test.yml +10 -4
  3. package/.husky/pre-commit +1 -0
  4. package/.prettierignore +15 -0
  5. package/.prettierrc +7 -3
  6. package/CONTRIBUTING.md +38 -0
  7. package/README.md +2 -148
  8. package/dist/index.js +10 -11
  9. package/dist/package.json +30 -2
  10. package/dist/src/agents/app.js +28 -0
  11. package/dist/src/agents/backend.js +25 -0
  12. package/dist/src/agents/devops.js +34 -0
  13. package/dist/src/agents/frontend.js +25 -0
  14. package/dist/src/agents/fullstack.js +25 -0
  15. package/dist/src/agents/index.js +61 -0
  16. package/dist/src/agents/quality.js +70 -0
  17. package/dist/src/agents/security.js +26 -0
  18. package/dist/src/agents/types.js +2 -0
  19. package/dist/src/client.js +97 -117
  20. package/dist/src/commands/api-keys.js +75 -90
  21. package/dist/src/commands/auth.js +7 -16
  22. package/dist/src/commands/autocomplete.js +1 -1
  23. package/dist/src/commands/billing.js +6 -17
  24. package/dist/src/commands/chat.js +68 -101
  25. package/dist/src/commands/clusters.js +9 -18
  26. package/dist/src/commands/code/__tests__/auth-sync.test.js +351 -0
  27. package/dist/src/commands/code/__tests__/fake-api-key-service.js +13 -0
  28. package/dist/src/commands/code/__tests__/fake-auth-service.js +47 -0
  29. package/dist/src/commands/code/__tests__/fake-command-runner.js +21 -34
  30. package/dist/src/commands/code/__tests__/fake-file-store.js +20 -33
  31. package/dist/src/commands/code/__tests__/fake-prompter.js +83 -57
  32. package/dist/src/commands/code/__tests__/setup-flow.test.js +359 -92
  33. package/dist/src/commands/code/adapters/clack-prompter.js +15 -22
  34. package/dist/src/commands/code/adapters/fs-file-store.js +26 -40
  35. package/dist/src/commands/code/adapters/spawn-command-runner.js +27 -37
  36. package/dist/src/commands/code/auth-sync.js +270 -0
  37. package/dist/src/commands/code/errors.js +12 -9
  38. package/dist/src/commands/code/ports/auth-services.js +2 -0
  39. package/dist/src/commands/code/setup.js +387 -281
  40. package/dist/src/commands/code.js +205 -332
  41. package/dist/src/commands/index.js +5 -5
  42. package/dist/src/commands/models.js +6 -17
  43. package/dist/src/commands/users.js +5 -16
  44. package/dist/src/constants/command-structure.js +104 -104
  45. package/dist/src/services/api-key-service.js +132 -157
  46. package/dist/src/services/auth-service.js +89 -342
  47. package/dist/src/services/browser-auth.js +268 -0
  48. package/dist/src/services/chat-service.js +371 -401
  49. package/dist/src/services/cluster-service.js +47 -62
  50. package/dist/src/services/collaborator-service.js +10 -25
  51. package/dist/src/services/flux-service.js +14 -29
  52. package/dist/src/services/helm-service.js +10 -25
  53. package/dist/src/services/kubectl-service.js +16 -33
  54. package/dist/src/utils/config-checker.js +3 -3
  55. package/dist/src/utils/config-loader.js +95 -95
  56. package/dist/src/utils/default-api-key.js +124 -134
  57. package/dist/src/utils/env-manager.js +55 -66
  58. package/dist/src/utils/error-handler.js +20 -21
  59. package/dist/src/utils/logger.js +72 -65
  60. package/dist/src/utils/markdown-renderer.js +27 -27
  61. package/dist/src/utils/opencode-validator.js +63 -68
  62. package/dist/src/utils/token-manager.js +74 -45
  63. package/dist/tests/commands/chat.test.js +16 -25
  64. package/dist/tests/commands/code.test.js +95 -104
  65. package/dist/tests/utils/config-loader.test.js +48 -48
  66. package/dist/tests/utils/env-manager.test.js +43 -52
  67. package/dist/tests/utils/opencode-validator.test.js +22 -21
  68. package/dist/vitest.config.js +1 -1
  69. package/eslint.config.mjs +67 -0
  70. package/index.ts +35 -42
  71. package/package.json +30 -2
  72. package/src/agents/app.ts +27 -0
  73. package/src/agents/backend.ts +24 -0
  74. package/src/agents/devops.ts +33 -0
  75. package/src/agents/frontend.ts +24 -0
  76. package/src/agents/fullstack.ts +24 -0
  77. package/src/agents/index.ts +73 -0
  78. package/src/agents/quality.ts +69 -0
  79. package/src/agents/security.ts +26 -0
  80. package/src/agents/types.ts +17 -0
  81. package/src/client.ts +118 -152
  82. package/src/commands/api-keys.ts +241 -333
  83. package/src/commands/auth.ts +22 -27
  84. package/src/commands/autocomplete.ts +9 -9
  85. package/src/commands/billing.ts +20 -24
  86. package/src/commands/chat.ts +248 -338
  87. package/src/commands/clusters.ts +27 -26
  88. package/src/commands/code/__tests__/auth-sync.test.ts +482 -0
  89. package/src/commands/code/__tests__/fake-api-key-service.ts +13 -0
  90. package/src/commands/code/__tests__/fake-auth-service.ts +50 -0
  91. package/src/commands/code/__tests__/fake-command-runner.ts +45 -42
  92. package/src/commands/code/__tests__/fake-file-store.ts +32 -23
  93. package/src/commands/code/__tests__/fake-prompter.ts +116 -77
  94. package/src/commands/code/__tests__/setup-flow.test.ts +624 -268
  95. package/src/commands/code/adapters/clack-prompter.ts +53 -39
  96. package/src/commands/code/adapters/fs-file-store.ts +32 -27
  97. package/src/commands/code/adapters/spawn-command-runner.ts +38 -29
  98. package/src/commands/code/auth-sync.ts +329 -0
  99. package/src/commands/code/errors.ts +18 -18
  100. package/src/commands/code/ports/auth-services.ts +14 -0
  101. package/src/commands/code/ports/command-runner.ts +8 -4
  102. package/src/commands/code/ports/file-store.ts +5 -4
  103. package/src/commands/code/ports/prompter.ts +24 -18
  104. package/src/commands/code/setup.ts +570 -340
  105. package/src/commands/code.ts +338 -539
  106. package/src/commands/index.ts +20 -19
  107. package/src/commands/models.ts +28 -32
  108. package/src/commands/users.ts +15 -21
  109. package/src/constants/command-structure.ts +134 -157
  110. package/src/services/api-key-service.ts +105 -122
  111. package/src/services/auth-service.ts +99 -345
  112. package/src/services/browser-auth.ts +296 -0
  113. package/src/services/chat-service.ts +265 -299
  114. package/src/services/cluster-service.ts +42 -45
  115. package/src/services/collaborator-service.ts +14 -19
  116. package/src/services/flux-service.ts +23 -25
  117. package/src/services/helm-service.ts +19 -21
  118. package/src/services/kubectl-service.ts +17 -19
  119. package/src/types/api.d.ts +1905 -1907
  120. package/src/types/json.d.ts +2 -2
  121. package/src/utils/config-checker.ts +10 -10
  122. package/src/utils/config-loader.ts +162 -178
  123. package/src/utils/default-api-key.ts +114 -125
  124. package/src/utils/env-manager.ts +53 -57
  125. package/src/utils/error-handler.ts +61 -56
  126. package/src/utils/logger.ts +79 -73
  127. package/src/utils/markdown-renderer.ts +31 -31
  128. package/src/utils/opencode-validator.ts +85 -89
  129. package/src/utils/token-manager.ts +108 -87
  130. package/templates/agents/app.md +1 -0
  131. package/templates/agents/backend.md +1 -0
  132. package/templates/agents/devops.md +2 -0
  133. package/templates/agents/frontend.md +1 -0
  134. package/templates/agents/fullstack.md +1 -0
  135. package/templates/agents/quality.md +45 -40
  136. package/templates/agents/security.md +1 -0
  137. package/tests/commands/chat.test.ts +53 -62
  138. package/tests/commands/code.test.ts +265 -310
  139. package/tests/utils/config-loader.test.ts +189 -188
  140. package/tests/utils/env-manager.test.ts +110 -113
  141. package/tests/utils/opencode-validator.test.ts +52 -56
  142. package/tsconfig.json +4 -3
  143. package/vitest.config.ts +3 -3
  144. package/AGENTS.md +0 -374
  145. package/TODO.md +0 -19
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -15,57 +6,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.registerApiKeyCommands = void 0;
16
7
  const chalk_1 = __importDefault(require("chalk"));
17
8
  const api_key_service_1 = require("../services/api-key-service");
18
- const error_handler_1 = require("../utils/error-handler");
19
9
  const default_api_key_1 = require("../utils/default-api-key");
20
- // Helper functions for better date formatting
21
- function formatDate(dateString) {
22
- const date = new Date(dateString);
23
- const now = new Date();
24
- const diffTime = Math.abs(now.getTime() - date.getTime());
25
- const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
26
- if (diffDays === 0)
27
- return chalk_1.default.green('Today');
28
- if (diffDays === 1)
29
- return chalk_1.default.yellow('Yesterday');
30
- if (diffDays < 7)
31
- return chalk_1.default.yellow(`${diffDays} days ago`);
32
- if (diffDays < 30)
33
- return chalk_1.default.blue(`${Math.floor(diffDays / 7)} weeks ago`);
34
- if (diffDays < 365)
35
- return chalk_1.default.magenta(`${Math.floor(diffDays / 30)} months ago`);
36
- return chalk_1.default.gray(`${Math.floor(diffDays / 365)} years ago`);
37
- }
38
- function formatLastUsed(dateString) {
39
- const date = new Date(dateString);
40
- const now = new Date();
41
- const diffTime = Math.abs(now.getTime() - date.getTime());
42
- const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
43
- if (diffDays === 0)
44
- return chalk_1.default.green('Today');
45
- if (diffDays === 1)
46
- return chalk_1.default.yellow('Yesterday');
47
- if (diffDays < 7)
48
- return chalk_1.default.yellow(`${diffDays} days ago`);
49
- if (diffDays < 30)
50
- return chalk_1.default.blue(`${Math.floor(diffDays / 7)} weeks ago`);
51
- if (diffDays < 365)
52
- return chalk_1.default.magenta(`${Math.floor(diffDays / 30)} months ago`);
53
- return chalk_1.default.gray(`${Math.floor(diffDays / 365)} years ago`);
54
- }
10
+ const error_handler_1 = require("../utils/error-handler");
55
11
  /**
56
12
  * Register API key commands
57
13
  */
58
14
  function registerApiKeyCommands(program) {
59
- const apiKey = program
60
- .command(api_key_service_1.ApiKeyService.COMMAND_GROUP)
61
- .description('Manage API keys');
15
+ const apiKey = program.command(api_key_service_1.ApiKeyService.COMMAND_GROUP).description('Manage API keys');
62
16
  apiKey
63
17
  .command(api_key_service_1.ApiKeyService.COMMANDS.LIST)
64
18
  .description('List all API keys')
65
- .action(() => __awaiter(this, void 0, void 0, function* () {
19
+ .action(async () => {
66
20
  try {
67
21
  const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
68
- const keys = yield apiKeyService.list();
22
+ const keys = await apiKeyService.list();
69
23
  if (keys.length === 0) {
70
24
  console.log(chalk_1.default.yellow('No API keys found. Create one with `berget api-key create --name <name>`'));
71
25
  return;
@@ -87,27 +41,23 @@ function registerApiKeyCommands(program) {
87
41
  chalk_1.default.dim('LAST USED'));
88
42
  console.log(chalk_1.default.dim('─'.repeat(idWidth + nameWidth + prefixWidth + statusWidth + createdWidth + usedWidth + 5)));
89
43
  keys.forEach((key) => {
90
- const lastUsed = key.lastUsed
91
- ? formatLastUsed(key.lastUsed)
92
- : chalk_1.default.yellow('Never used');
93
- const status = key.active
94
- ? chalk_1.default.green('● Active')
95
- : chalk_1.default.red('● Inactive');
44
+ const lastUsed = key.lastUsed ? formatLastUsed(key.lastUsed) : chalk_1.default.yellow('Never used');
45
+ const status = key.active ? chalk_1.default.green('● Active') : chalk_1.default.red('● Inactive');
96
46
  // Show only first 8 characters of ID for easier reading
97
- const shortId = chalk_1.default.cyan(String(key.id).substring(0, 8));
47
+ const shortId = chalk_1.default.cyan(String(key.id).slice(0, 8));
98
48
  // Format the prefix with better truncation
99
- const prefixStr = key.prefix.length > prefixWidth
100
- ? key.prefix.substring(0, prefixWidth - 3) + '...'
49
+ const prefixString = key.prefix.length > prefixWidth
50
+ ? key.prefix.slice(0, Math.max(0, prefixWidth - 3)) + '...'
101
51
  : chalk_1.default.gray(key.prefix);
102
52
  // Truncate name if too long
103
- const nameStr = key.name.length > nameWidth
104
- ? key.name.substring(0, nameWidth - 3) + '...'
53
+ const nameString = key.name.length > nameWidth
54
+ ? key.name.slice(0, Math.max(0, nameWidth - 3)) + '...'
105
55
  : key.name;
106
56
  // Format created date
107
57
  const createdDate = formatDate(key.created);
108
58
  console.log(shortId.padEnd(idWidth) +
109
- nameStr.padEnd(nameWidth) +
110
- prefixStr.padEnd(prefixWidth) +
59
+ nameString.padEnd(nameWidth) +
60
+ prefixString.padEnd(prefixWidth) +
111
61
  status.padEnd(statusWidth) +
112
62
  createdDate.padEnd(createdWidth) +
113
63
  lastUsed);
@@ -120,13 +70,13 @@ function registerApiKeyCommands(program) {
120
70
  catch (error) {
121
71
  (0, error_handler_1.handleError)('Failed to list API keys', error);
122
72
  }
123
- }));
73
+ });
124
74
  apiKey
125
75
  .command(api_key_service_1.ApiKeyService.COMMANDS.CREATE)
126
76
  .description('Create a new API key')
127
77
  .option('--name <name>', 'Name of the API key')
128
78
  .option('--description <description>', 'Description of the API key')
129
- .action((options) => __awaiter(this, void 0, void 0, function* () {
79
+ .action(async (options) => {
130
80
  try {
131
81
  if (!options.name) {
132
82
  console.error(chalk_1.default.red('Error: --name is required'));
@@ -136,9 +86,9 @@ function registerApiKeyCommands(program) {
136
86
  }
137
87
  console.log(chalk_1.default.blue('Creating API key...'));
138
88
  const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
139
- const result = yield apiKeyService.create({
140
- name: options.name,
89
+ const result = await apiKeyService.create({
141
90
  description: options.description,
91
+ name: options.name,
142
92
  });
143
93
  console.log('');
144
94
  console.log(chalk_1.default.green('✓ API key created'));
@@ -163,16 +113,16 @@ function registerApiKeyCommands(program) {
163
113
  catch (error) {
164
114
  (0, error_handler_1.handleError)('Failed to create API key', error);
165
115
  }
166
- }));
116
+ });
167
117
  apiKey
168
118
  .command(api_key_service_1.ApiKeyService.COMMANDS.DELETE)
169
119
  .description('Delete an API key')
170
120
  .argument('<identifier>', 'ID (first 8 chars), full ID, or name of the API key to delete')
171
- .action((identifier) => __awaiter(this, void 0, void 0, function* () {
121
+ .action(async (identifier) => {
172
122
  try {
173
123
  const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
174
124
  // First, get all API keys to find the matching one
175
- const keys = yield apiKeyService.list();
125
+ const keys = await apiKeyService.list();
176
126
  // Try to find the key by:
177
127
  // 1. Full ID match
178
128
  // 2. Short ID (first 8 chars) match
@@ -182,7 +132,7 @@ function registerApiKeyCommands(program) {
182
132
  let exactMatches = keys.filter((key) => String(key.id) === identifier || key.name === identifier);
183
133
  // If no exact matches, check for short ID matches
184
134
  if (exactMatches.length === 0) {
185
- exactMatches = keys.filter((key) => String(key.id).substring(0, 8) === identifier);
135
+ exactMatches = keys.filter((key) => String(key.id).slice(0, 8) === identifier);
186
136
  }
187
137
  // If still no matches, check for partial name matches
188
138
  if (exactMatches.length === 0) {
@@ -193,10 +143,10 @@ function registerApiKeyCommands(program) {
193
143
  console.error(chalk_1.default.red(`Error: Multiple API keys found matching "${identifier}"`));
194
144
  console.log('');
195
145
  console.log('Please be more specific. Matching keys:');
196
- exactMatches.forEach((key) => {
197
- const shortId = String(key.id).substring(0, 8);
146
+ for (const key of exactMatches) {
147
+ const shortId = String(key.id).slice(0, 8);
198
148
  console.log(` ${shortId.padEnd(8)} ${key.name}`);
199
- });
149
+ }
200
150
  console.log('');
201
151
  console.log('Use the first 8 characters of the ID to specify which key to delete.');
202
152
  return;
@@ -206,19 +156,19 @@ function registerApiKeyCommands(program) {
206
156
  console.error(chalk_1.default.red(`Error: No API key found matching "${identifier}"`));
207
157
  console.log('');
208
158
  console.log('Available API keys:');
209
- keys.forEach((key) => {
210
- const shortId = String(key.id).substring(0, 8);
159
+ for (const key of keys) {
160
+ const shortId = String(key.id).slice(0, 8);
211
161
  console.log(` ${shortId.padEnd(8)} ${key.name}`);
212
- });
162
+ }
213
163
  console.log('');
214
164
  console.log('Use the first 8 characters of the ID, full ID, or name to delete.');
215
165
  return;
216
166
  }
217
167
  const matchingKey = exactMatches[0];
218
168
  const keyId = String(matchingKey.id);
219
- const shortId = keyId.substring(0, 8);
169
+ const shortId = keyId.slice(0, 8);
220
170
  console.log(chalk_1.default.blue(`Deleting API key ${shortId} (${matchingKey.name})...`));
221
- yield apiKeyService.delete(keyId);
171
+ await apiKeyService.delete(keyId);
222
172
  console.log(chalk_1.default.green(`✓ API key ${shortId} (${matchingKey.name}) has been deleted`));
223
173
  console.log('');
224
174
  console.log(chalk_1.default.dim('Applications using this key will no longer be able to authenticate.'));
@@ -227,17 +177,17 @@ function registerApiKeyCommands(program) {
227
177
  catch (error) {
228
178
  (0, error_handler_1.handleError)('Failed to delete API key', error);
229
179
  }
230
- }));
180
+ });
231
181
  apiKey
232
182
  .command(api_key_service_1.ApiKeyService.COMMANDS.ROTATE)
233
183
  .description('Rotate an API key (creates a new one and invalidates the old one)')
234
184
  .argument('<id>', 'ID of the API key to rotate')
235
- .action((id) => __awaiter(this, void 0, void 0, function* () {
185
+ .action(async (id) => {
236
186
  try {
237
187
  console.log(chalk_1.default.blue(`Rotating API key ${id}...`));
238
188
  console.log(chalk_1.default.dim('This will invalidate the old key and generate a new one.'));
239
189
  const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
240
- const result = yield apiKeyService.rotate(id);
190
+ const result = await apiKeyService.rotate(id);
241
191
  console.log('');
242
192
  console.log(chalk_1.default.green('✓ API key rotated'));
243
193
  console.log('');
@@ -260,18 +210,18 @@ function registerApiKeyCommands(program) {
260
210
  catch (error) {
261
211
  (0, error_handler_1.handleError)('Failed to rotate API key', error);
262
212
  }
263
- }));
213
+ });
264
214
  apiKey
265
215
  .command(api_key_service_1.ApiKeyService.COMMANDS.DESCRIBE)
266
216
  .description('Show usage statistics for an API key')
267
217
  .argument('<id>', 'ID of the API key')
268
218
  .option('--start <date>', 'Start date (YYYY-MM-DD)')
269
219
  .option('--end <date>', 'End date (YYYY-MM-DD)')
270
- .action((id, options) => __awaiter(this, void 0, void 0, function* () {
220
+ .action(async (id, _options) => {
271
221
  try {
272
222
  console.log(chalk_1.default.blue(`Fetching usage statistics for API key ${id}...`));
273
223
  const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
274
- const usage = yield apiKeyService.describe(id);
224
+ const usage = await apiKeyService.describe(id);
275
225
  console.log('');
276
226
  console.log(chalk_1.default.bold(`Usage statistics for API key: ${usage.name} (${id})`));
277
227
  console.log('');
@@ -315,15 +265,15 @@ function registerApiKeyCommands(program) {
315
265
  catch (error) {
316
266
  (0, error_handler_1.handleError)('Failed to get API key usage', error);
317
267
  }
318
- }));
268
+ });
319
269
  apiKey
320
270
  .command(api_key_service_1.ApiKeyService.COMMANDS.SET_DEFAULT)
321
271
  .description('Set an API key as the default for chat commands')
322
272
  .argument('<id>', 'ID of the API key to set as default')
323
- .action((id) => __awaiter(this, void 0, void 0, function* () {
273
+ .action(async (id) => {
324
274
  try {
325
275
  const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
326
- const keys = yield apiKeyService.list();
276
+ const keys = await apiKeyService.list();
327
277
  const selectedKey = keys.find((key) => key.id.toString() === id);
328
278
  if (!selectedKey) {
329
279
  console.error(chalk_1.default.red(`Error: API key with ID ${id} not found`));
@@ -332,7 +282,7 @@ function registerApiKeyCommands(program) {
332
282
  // Save the default API key
333
283
  const defaultApiKeyManager = default_api_key_1.DefaultApiKeyManager.getInstance();
334
284
  // We need to rotate the key to get the actual key value
335
- const rotatedKey = yield apiKeyService.rotate(id);
285
+ const rotatedKey = await apiKeyService.rotate(id);
336
286
  defaultApiKeyManager.setDefaultApiKey(id, selectedKey.name, selectedKey.prefix, rotatedKey.key);
337
287
  console.log(chalk_1.default.green(`✓ API key "${selectedKey.name}" set as default for chat commands`));
338
288
  console.log('');
@@ -342,7 +292,7 @@ function registerApiKeyCommands(program) {
342
292
  catch (error) {
343
293
  (0, error_handler_1.handleError)('Failed to set default API key', error);
344
294
  }
345
- }));
295
+ });
346
296
  apiKey
347
297
  .command(api_key_service_1.ApiKeyService.COMMANDS.GET_DEFAULT)
348
298
  .description('Show the current default API key')
@@ -372,3 +322,38 @@ function registerApiKeyCommands(program) {
372
322
  });
373
323
  }
374
324
  exports.registerApiKeyCommands = registerApiKeyCommands;
325
+ // Helper functions for better date formatting
326
+ function formatDate(dateString) {
327
+ const date = new Date(dateString);
328
+ const now = new Date();
329
+ const diffTime = Math.abs(now.getTime() - date.getTime());
330
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
331
+ if (diffDays === 0)
332
+ return chalk_1.default.green('Today');
333
+ if (diffDays === 1)
334
+ return chalk_1.default.yellow('Yesterday');
335
+ if (diffDays < 7)
336
+ return chalk_1.default.yellow(`${diffDays} days ago`);
337
+ if (diffDays < 30)
338
+ return chalk_1.default.blue(`${Math.floor(diffDays / 7)} weeks ago`);
339
+ if (diffDays < 365)
340
+ return chalk_1.default.magenta(`${Math.floor(diffDays / 30)} months ago`);
341
+ return chalk_1.default.gray(`${Math.floor(diffDays / 365)} years ago`);
342
+ }
343
+ function formatLastUsed(dateString) {
344
+ const date = new Date(dateString);
345
+ const now = new Date();
346
+ const diffTime = Math.abs(now.getTime() - date.getTime());
347
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
348
+ if (diffDays === 0)
349
+ return chalk_1.default.green('Today');
350
+ if (diffDays === 1)
351
+ return chalk_1.default.yellow('Yesterday');
352
+ if (diffDays < 7)
353
+ return chalk_1.default.yellow(`${diffDays} days ago`);
354
+ if (diffDays < 30)
355
+ return chalk_1.default.blue(`${Math.floor(diffDays / 7)} weeks ago`);
356
+ if (diffDays < 365)
357
+ return chalk_1.default.magenta(`${Math.floor(diffDays / 30)} months ago`);
358
+ return chalk_1.default.gray(`${Math.floor(diffDays / 365)} years ago`);
359
+ }
@@ -1,21 +1,12 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.registerAuthCommands = void 0;
16
7
  const chalk_1 = __importDefault(require("chalk"));
17
- const auth_service_1 = require("../services/auth-service");
18
8
  const client_1 = require("../client");
9
+ const auth_service_1 = require("../services/auth-service");
19
10
  const error_handler_1 = require("../utils/error-handler");
20
11
  /**
21
12
  * Register authentication commands
@@ -27,10 +18,10 @@ function registerAuthCommands(program) {
27
18
  auth
28
19
  .command(auth_service_1.AuthService.COMMANDS.LOGIN)
29
20
  .description('Log in to Berget')
30
- .action(() => __awaiter(this, void 0, void 0, function* () {
21
+ .action(async () => {
31
22
  const authService = auth_service_1.AuthService.getInstance();
32
- yield authService.login();
33
- }));
23
+ await authService.login();
24
+ });
34
25
  auth
35
26
  .command(auth_service_1.AuthService.COMMANDS.LOGOUT)
36
27
  .description('Log out from Berget')
@@ -41,10 +32,10 @@ function registerAuthCommands(program) {
41
32
  auth
42
33
  .command(auth_service_1.AuthService.COMMANDS.WHOAMI)
43
34
  .description('Show information about the logged in user')
44
- .action(() => __awaiter(this, void 0, void 0, function* () {
35
+ .action(async () => {
45
36
  try {
46
37
  const authService = auth_service_1.AuthService.getInstance();
47
- const profile = yield authService.whoami();
38
+ const profile = await authService.whoami();
48
39
  if (profile) {
49
40
  console.log(chalk_1.default.bold(`Logged in as: ${profile.name || profile.login}`));
50
41
  console.log(`Email: ${chalk_1.default.cyan(profile.email || 'Not available')}`);
@@ -60,6 +51,6 @@ function registerAuthCommands(program) {
60
51
  catch (error) {
61
52
  (0, error_handler_1.handleError)('You are not logged in or an error occurred', error);
62
53
  }
63
- }));
54
+ });
64
55
  }
65
56
  exports.registerAuthCommands = registerAuthCommands;
@@ -9,7 +9,7 @@ const chalk_1 = __importDefault(require("chalk"));
9
9
  * Register autocomplete commands
10
10
  */
11
11
  function registerAutocompleteCommands(program) {
12
- const autocomplete = program
12
+ program
13
13
  .command('autocomplete')
14
14
  .command('install')
15
15
  .description('Install shell autocompletion')
@@ -1,35 +1,24 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.registerBillingCommands = void 0;
13
- const command_structure_1 = require("../constants/command-structure");
14
4
  const client_1 = require("../client");
5
+ const command_structure_1 = require("../constants/command-structure");
15
6
  const error_handler_1 = require("../utils/error-handler");
16
7
  /**
17
8
  * Register billing commands
18
9
  */
19
10
  function registerBillingCommands(program) {
20
- const billing = program
21
- .command(command_structure_1.COMMAND_GROUPS.BILLING)
22
- .description('Manage billing and usage');
11
+ const billing = program.command(command_structure_1.COMMAND_GROUPS.BILLING).description('Manage billing and usage');
23
12
  billing
24
13
  .command(command_structure_1.SUBCOMMANDS.BILLING.GET_USAGE)
25
14
  .description('Get token usage statistics')
26
15
  .option('--model <modelId>', 'Get usage for a specific model')
27
- .action((options) => __awaiter(this, void 0, void 0, function* () {
16
+ .action(async (options) => {
28
17
  try {
29
18
  const client = (0, client_1.createAuthenticatedClient)();
30
19
  let response;
31
20
  if (options.model) {
32
- const { data, error } = yield client.GET('/v1/usage/tokens/{modelId}', {
21
+ const { data, error } = await client.GET('/v1/usage/tokens/{modelId}', {
33
22
  params: { path: { modelId: options.model } },
34
23
  });
35
24
  if (error)
@@ -37,7 +26,7 @@ function registerBillingCommands(program) {
37
26
  response = data;
38
27
  }
39
28
  else {
40
- const { data, error } = yield client.GET('/v1/usage/tokens');
29
+ const { data, error } = await client.GET('/v1/usage/tokens');
41
30
  if (error)
42
31
  throw new Error(JSON.stringify(error));
43
32
  response = data;
@@ -48,6 +37,6 @@ function registerBillingCommands(program) {
48
37
  catch (error) {
49
38
  (0, error_handler_1.handleError)('Failed to get token usage', error);
50
39
  }
51
- }));
40
+ });
52
41
  }
53
42
  exports.registerBillingCommands = registerBillingCommands;