berget 0.1.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/dist/index.js +7 -439
- package/dist/src/client.js +193 -102
- package/dist/src/commands/api-keys.js +271 -0
- package/dist/src/commands/auth.js +65 -0
- package/dist/src/commands/autocomplete.js +24 -0
- package/dist/src/commands/billing.js +53 -0
- package/dist/src/commands/chat.js +276 -0
- package/dist/src/commands/clusters.js +69 -0
- package/dist/src/commands/index.js +25 -0
- package/dist/src/commands/models.js +69 -0
- package/dist/src/commands/users.js +43 -0
- package/dist/src/constants/command-structure.js +164 -0
- package/dist/src/services/api-key-service.js +34 -5
- package/dist/src/services/auth-service.js +83 -43
- package/dist/src/services/chat-service.js +177 -0
- package/dist/src/services/cluster-service.js +37 -2
- package/dist/src/services/collaborator-service.js +21 -4
- package/dist/src/services/flux-service.js +21 -4
- package/dist/src/services/helm-service.js +20 -3
- package/dist/src/services/kubectl-service.js +26 -5
- package/dist/src/utils/config-checker.js +50 -0
- package/dist/src/utils/default-api-key.js +111 -0
- package/dist/src/utils/token-manager.js +165 -0
- package/index.ts +5 -529
- package/package.json +6 -1
- package/src/client.ts +262 -80
- package/src/commands/api-keys.ts +364 -0
- package/src/commands/auth.ts +58 -0
- package/src/commands/autocomplete.ts +19 -0
- package/src/commands/billing.ts +41 -0
- package/src/commands/chat.ts +345 -0
- package/src/commands/clusters.ts +65 -0
- package/src/commands/index.ts +23 -0
- package/src/commands/models.ts +63 -0
- package/src/commands/users.ts +37 -0
- package/src/constants/command-structure.ts +184 -0
- package/src/services/api-key-service.ts +36 -5
- package/src/services/auth-service.ts +101 -44
- package/src/services/chat-service.ts +177 -0
- package/src/services/cluster-service.ts +37 -2
- package/src/services/collaborator-service.ts +23 -4
- package/src/services/flux-service.ts +23 -4
- package/src/services/helm-service.ts +22 -3
- package/src/services/kubectl-service.ts +28 -5
- package/src/types/api.d.ts +58 -192
- package/src/utils/config-checker.ts +23 -0
- package/src/utils/default-api-key.ts +94 -0
- package/src/utils/token-manager.ts +150 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Berget CLI
|
|
2
|
+
|
|
3
|
+
A command-line interface for interacting with the Berget AI infrastructure.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g berget
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Authentication
|
|
12
|
+
|
|
13
|
+
The CLI uses OAuth-based authentication with automatic token refresh.
|
|
14
|
+
|
|
15
|
+
### Login
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
berget auth login
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This will open a browser window to authenticate with Berget. After successful authentication, your access token and refresh token will be stored securely in `~/.berget/auth.json`.
|
|
22
|
+
|
|
23
|
+
### Token Refresh
|
|
24
|
+
|
|
25
|
+
The CLI automatically handles token refresh when:
|
|
26
|
+
|
|
27
|
+
1. The access token is about to expire (within 10 minutes of expiration)
|
|
28
|
+
2. A request returns a 401 Unauthorized error
|
|
29
|
+
|
|
30
|
+
The refresh mechanism uses the stored refresh token to obtain a new access token without requiring you to log in again. If the refresh token itself is expired or invalid, you'll be prompted to log in again.
|
|
31
|
+
|
|
32
|
+
## Development
|
|
33
|
+
|
|
34
|
+
### Setup
|
|
35
|
+
|
|
36
|
+
Clone the repository and install dependencies:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/berget/cli.git
|
|
40
|
+
cd cli
|
|
41
|
+
npm install
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Testing Locally
|
|
45
|
+
|
|
46
|
+
Use the `start` script to test the CLI locally with the `--local` flag:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm start -- <command> [options]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For example:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Test login
|
|
56
|
+
npm start -- auth login
|
|
57
|
+
|
|
58
|
+
# Test whoami
|
|
59
|
+
npm start -- auth whoami
|
|
60
|
+
|
|
61
|
+
# Test with debug output
|
|
62
|
+
npm start -- auth whoami --debug
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The `--debug` flag provides detailed information about token refresh attempts and API responses.
|
|
66
|
+
|
|
67
|
+
### Testing Token Refresh
|
|
68
|
+
|
|
69
|
+
To test the token refresh mechanism:
|
|
70
|
+
|
|
71
|
+
1. Log in with `npm start -- auth login`
|
|
72
|
+
2. Make a request that requires authentication, like `npm start -- auth whoami`
|
|
73
|
+
3. To force a token refresh, you can:
|
|
74
|
+
- Wait until the token is close to expiration
|
|
75
|
+
- Manually edit `~/.berget/auth.json` and set `expires_at` to a past timestamp
|
|
76
|
+
- Use the `--debug` flag to see the token refresh process in action
|
|
77
|
+
|
|
78
|
+
## Commands
|
|
79
|
+
|
|
80
|
+
- `auth login` - Log in to Berget
|
|
81
|
+
- `auth logout` - Log out from Berget
|
|
82
|
+
- `auth whoami` - Show current user information
|
|
83
|
+
- `api-keys list` - List API keys
|
|
84
|
+
- `api-keys create` - Create a new API key
|
|
85
|
+
- `models list` - List available AI models
|
|
86
|
+
- `chat run` - Start a chat session with an AI model
|
|
87
|
+
|
|
88
|
+
For a complete list of commands, run:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
berget --help
|
|
92
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,47 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
30
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
4
|
const commander_1 = require("commander");
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const client_1 = require("./src/client");
|
|
43
|
-
const error_handler_1 = require("./src/utils/error-handler");
|
|
44
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
5
|
+
const commands_1 = require("./src/commands");
|
|
6
|
+
const config_checker_1 = require("./src/utils/config-checker");
|
|
45
7
|
// Set version and description
|
|
46
8
|
commander_1.program
|
|
47
9
|
.name('berget')
|
|
@@ -54,406 +16,12 @@ commander_1.program
|
|
|
54
16
|
__/ |
|
|
55
17
|
|___/ AI on European terms`)
|
|
56
18
|
.version(process.env.npm_package_version || '0.0.1', '-v, --version')
|
|
57
|
-
.option('--local', 'Use local API endpoint (hidden)', false)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const cluster_service_1 = require("./src/services/cluster-service");
|
|
62
|
-
// Auth commands
|
|
63
|
-
commander_1.program
|
|
64
|
-
.command('login')
|
|
65
|
-
.description('Log in to Berget')
|
|
66
|
-
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
-
const authService = auth_service_1.AuthService.getInstance();
|
|
68
|
-
yield authService.login();
|
|
69
|
-
}));
|
|
70
|
-
commander_1.program
|
|
71
|
-
.command('logout')
|
|
72
|
-
.description('Log out from Berget')
|
|
73
|
-
.action(() => {
|
|
74
|
-
const { clearAuthToken } = require('./src/client');
|
|
75
|
-
clearAuthToken();
|
|
76
|
-
console.log(chalk_1.default.green('You have been logged out from Berget'));
|
|
77
|
-
});
|
|
78
|
-
commander_1.program
|
|
79
|
-
.command('whoami')
|
|
80
|
-
.description('Show information about the logged in user')
|
|
81
|
-
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
-
try {
|
|
83
|
-
const authService = auth_service_1.AuthService.getInstance();
|
|
84
|
-
const profile = yield authService.getUserProfile();
|
|
85
|
-
if (profile) {
|
|
86
|
-
console.log(chalk_1.default.bold(`Logged in as: ${profile.name || profile.login}`));
|
|
87
|
-
console.log(`Email: ${chalk_1.default.cyan(profile.email || 'Not available')}`);
|
|
88
|
-
console.log(`Role: ${chalk_1.default.cyan(profile.role || 'Not available')}`);
|
|
89
|
-
if (profile.company) {
|
|
90
|
-
console.log(`Company: ${chalk_1.default.cyan(profile.company.name)}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
console.log(chalk_1.default.yellow('You are not logged in. Use `berget login` to log in.'));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
(0, error_handler_1.handleError)('You are not logged in or an error occurred', error);
|
|
99
|
-
}
|
|
100
|
-
}));
|
|
101
|
-
// API Key commands
|
|
102
|
-
const apiKey = commander_1.program.command('api-key').description('Manage API keys');
|
|
103
|
-
apiKey
|
|
104
|
-
.command('list')
|
|
105
|
-
.description('List all API keys')
|
|
106
|
-
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
-
try {
|
|
108
|
-
const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
|
|
109
|
-
const keys = yield apiKeyService.listApiKeys();
|
|
110
|
-
if (keys.length === 0) {
|
|
111
|
-
console.log(chalk_1.default.yellow('No API keys found. Create one with `berget api-key create --name <name>`'));
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
console.log(chalk_1.default.bold('Your API keys:'));
|
|
115
|
-
console.log('');
|
|
116
|
-
// Create a table-like format with headers
|
|
117
|
-
console.log(chalk_1.default.dim('ID'.padEnd(10)) +
|
|
118
|
-
chalk_1.default.dim('NAME'.padEnd(25)) +
|
|
119
|
-
chalk_1.default.dim('PREFIX'.padEnd(12)) +
|
|
120
|
-
chalk_1.default.dim('STATUS'.padEnd(12)) +
|
|
121
|
-
chalk_1.default.dim('CREATED'.padEnd(12)) +
|
|
122
|
-
chalk_1.default.dim('LAST USED'));
|
|
123
|
-
console.log(chalk_1.default.dim('─'.repeat(85)));
|
|
124
|
-
keys.forEach((key) => {
|
|
125
|
-
const lastUsed = key.lastUsed ? key.lastUsed.substring(0, 10) : 'Never';
|
|
126
|
-
const status = key.active
|
|
127
|
-
? chalk_1.default.green('● Active')
|
|
128
|
-
: chalk_1.default.red('● Inactive');
|
|
129
|
-
console.log(String(key.id).padEnd(10) +
|
|
130
|
-
key.name.padEnd(25) +
|
|
131
|
-
key.prefix.padEnd(12) +
|
|
132
|
-
status.padEnd(12) +
|
|
133
|
-
key.created.substring(0, 10).padEnd(12) +
|
|
134
|
-
lastUsed);
|
|
135
|
-
});
|
|
136
|
-
console.log('');
|
|
137
|
-
console.log(chalk_1.default.dim('Use `berget api-key create --name <name>` to create a new API key'));
|
|
138
|
-
console.log(chalk_1.default.dim('Use `berget api-key delete <id>` to delete an API key'));
|
|
139
|
-
console.log(chalk_1.default.dim('Use `berget api-key rotate <id>` to rotate an API key'));
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
(0, error_handler_1.handleError)('Failed to list API keys', error);
|
|
143
|
-
}
|
|
144
|
-
}));
|
|
145
|
-
apiKey
|
|
146
|
-
.command('create')
|
|
147
|
-
.description('Create a new API key')
|
|
148
|
-
.option('--name <name>', 'Name of the API key')
|
|
149
|
-
.option('--description <description>', 'Description of the API key')
|
|
150
|
-
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
-
try {
|
|
152
|
-
if (!options.name) {
|
|
153
|
-
console.error(chalk_1.default.red('Error: --name is required'));
|
|
154
|
-
console.log('');
|
|
155
|
-
console.log('Usage: berget api-key create --name <name> [--description <description>]');
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
console.log(chalk_1.default.blue('Creating API key...'));
|
|
159
|
-
const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
|
|
160
|
-
const result = yield apiKeyService.createApiKey({
|
|
161
|
-
name: options.name,
|
|
162
|
-
description: options.description,
|
|
163
|
-
});
|
|
164
|
-
console.log('');
|
|
165
|
-
console.log(chalk_1.default.green('✓ API key created'));
|
|
166
|
-
console.log('');
|
|
167
|
-
console.log(chalk_1.default.bold('API key details:'));
|
|
168
|
-
console.log('');
|
|
169
|
-
console.log(`${chalk_1.default.dim('ID:')} ${result.id}`);
|
|
170
|
-
console.log(`${chalk_1.default.dim('Name:')} ${result.name}`);
|
|
171
|
-
if (result.description) {
|
|
172
|
-
console.log(`${chalk_1.default.dim('Description:')} ${result.description}`);
|
|
173
|
-
}
|
|
174
|
-
console.log(`${chalk_1.default.dim('Created:')} ${new Date(result.created).toLocaleString()}`);
|
|
175
|
-
console.log('');
|
|
176
|
-
console.log(chalk_1.default.bold('API key:'));
|
|
177
|
-
console.log(chalk_1.default.cyan(result.key));
|
|
178
|
-
console.log('');
|
|
179
|
-
console.log(chalk_1.default.yellow('⚠️ IMPORTANT: Save this API key in a secure location.'));
|
|
180
|
-
console.log(chalk_1.default.yellow(' It will not be displayed again.'));
|
|
181
|
-
console.log('');
|
|
182
|
-
console.log(chalk_1.default.dim('Use this key in your applications to authenticate with the Berget API.'));
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
(0, error_handler_1.handleError)('Failed to create API key', error);
|
|
186
|
-
}
|
|
187
|
-
}));
|
|
188
|
-
apiKey
|
|
189
|
-
.command('delete')
|
|
190
|
-
.description('Delete an API key')
|
|
191
|
-
.argument('<id>', 'ID of the API key to delete')
|
|
192
|
-
.action((id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
-
try {
|
|
194
|
-
console.log(chalk_1.default.blue(`Deleting API key ${id}...`));
|
|
195
|
-
const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
|
|
196
|
-
yield apiKeyService.deleteApiKey(id);
|
|
197
|
-
console.log(chalk_1.default.green(`✓ API key ${id} has been deleted`));
|
|
198
|
-
console.log('');
|
|
199
|
-
console.log(chalk_1.default.dim('Applications using this key will no longer be able to authenticate.'));
|
|
200
|
-
console.log(chalk_1.default.dim('Use `berget api-key list` to see your remaining API keys.'));
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
(0, error_handler_1.handleError)('Failed to delete API key', error);
|
|
204
|
-
}
|
|
205
|
-
}));
|
|
206
|
-
apiKey
|
|
207
|
-
.command('rotate')
|
|
208
|
-
.description('Rotate an API key (creates a new one and invalidates the old one)')
|
|
209
|
-
.argument('<id>', 'ID of the API key to rotate')
|
|
210
|
-
.action((id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
|
-
try {
|
|
212
|
-
console.log(chalk_1.default.blue(`Rotating API key ${id}...`));
|
|
213
|
-
console.log(chalk_1.default.dim('This will invalidate the old key and generate a new one.'));
|
|
214
|
-
const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
|
|
215
|
-
const result = yield apiKeyService.rotateApiKey(id);
|
|
216
|
-
console.log('');
|
|
217
|
-
console.log(chalk_1.default.green('✓ API key rotated'));
|
|
218
|
-
console.log('');
|
|
219
|
-
console.log(chalk_1.default.bold('New API key details:'));
|
|
220
|
-
console.log('');
|
|
221
|
-
console.log(`${chalk_1.default.dim('ID:')} ${result.id}`);
|
|
222
|
-
console.log(`${chalk_1.default.dim('Name:')} ${result.name}`);
|
|
223
|
-
if (result.description) {
|
|
224
|
-
console.log(`${chalk_1.default.dim('Description:')} ${result.description}`);
|
|
225
|
-
}
|
|
226
|
-
console.log(`${chalk_1.default.dim('Created:')} ${new Date(result.created).toLocaleString()}`);
|
|
227
|
-
console.log('');
|
|
228
|
-
console.log(chalk_1.default.bold('New API key:'));
|
|
229
|
-
console.log(chalk_1.default.cyan(result.key));
|
|
230
|
-
console.log('');
|
|
231
|
-
console.log(chalk_1.default.yellow('⚠️ IMPORTANT: Update your applications with this new API key.'));
|
|
232
|
-
console.log(chalk_1.default.yellow(' The old key has been invalidated and will no longer work.'));
|
|
233
|
-
console.log(chalk_1.default.yellow(' This new key will not be displayed again.'));
|
|
234
|
-
}
|
|
235
|
-
catch (error) {
|
|
236
|
-
(0, error_handler_1.handleError)('Failed to rotate API key', error);
|
|
237
|
-
}
|
|
238
|
-
}));
|
|
239
|
-
apiKey
|
|
240
|
-
.command('usage')
|
|
241
|
-
.description('Show usage statistics for an API key')
|
|
242
|
-
.argument('<id>', 'ID of the API key')
|
|
243
|
-
.option('--start <date>', 'Start date (YYYY-MM-DD)')
|
|
244
|
-
.option('--end <date>', 'End date (YYYY-MM-DD)')
|
|
245
|
-
.action((id, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
246
|
-
try {
|
|
247
|
-
console.log(chalk_1.default.blue(`Fetching usage statistics for API key ${id}...`));
|
|
248
|
-
const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
|
|
249
|
-
const usage = yield apiKeyService.getApiKeyUsage(id);
|
|
250
|
-
console.log('');
|
|
251
|
-
console.log(chalk_1.default.bold(`Usage statistics for API key: ${usage.name} (${id})`));
|
|
252
|
-
console.log('');
|
|
253
|
-
// Period information
|
|
254
|
-
console.log(chalk_1.default.dim(`Period: ${usage.period.start} to ${usage.period.end}`));
|
|
255
|
-
console.log('');
|
|
256
|
-
// Request statistics
|
|
257
|
-
console.log(chalk_1.default.bold('Request statistics:'));
|
|
258
|
-
console.log(`Total requests: ${chalk_1.default.cyan(usage.requests.total.toLocaleString())}`);
|
|
259
|
-
// Daily breakdown if available
|
|
260
|
-
if (usage.requests.daily && usage.requests.daily.length > 0) {
|
|
261
|
-
console.log('');
|
|
262
|
-
console.log(chalk_1.default.bold('Daily breakdown:'));
|
|
263
|
-
console.log(chalk_1.default.dim('─'.repeat(30)));
|
|
264
|
-
console.log(chalk_1.default.dim('DATE'.padEnd(12) + 'REQUESTS'));
|
|
265
|
-
usage.requests.daily.forEach((day) => {
|
|
266
|
-
console.log(`${day.date.padEnd(12)}${day.count.toLocaleString()}`);
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
// Model usage if available
|
|
270
|
-
if (usage.models && usage.models.length > 0) {
|
|
271
|
-
console.log('');
|
|
272
|
-
console.log(chalk_1.default.bold('Model usage:'));
|
|
273
|
-
console.log(chalk_1.default.dim('─'.repeat(70)));
|
|
274
|
-
console.log(chalk_1.default.dim('MODEL'.padEnd(20)) +
|
|
275
|
-
chalk_1.default.dim('REQUESTS'.padEnd(10)) +
|
|
276
|
-
chalk_1.default.dim('INPUT'.padEnd(12)) +
|
|
277
|
-
chalk_1.default.dim('OUTPUT'.padEnd(12)) +
|
|
278
|
-
chalk_1.default.dim('TOTAL TOKENS'));
|
|
279
|
-
usage.models.forEach((model) => {
|
|
280
|
-
console.log(model.name.padEnd(20) +
|
|
281
|
-
model.requests.toString().padEnd(10) +
|
|
282
|
-
model.tokens.input.toLocaleString().padEnd(12) +
|
|
283
|
-
model.tokens.output.toLocaleString().padEnd(12) +
|
|
284
|
-
model.tokens.total.toLocaleString());
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
console.log('');
|
|
288
|
-
console.log(chalk_1.default.dim('Use these statistics to understand your API usage and optimize your costs.'));
|
|
289
|
-
}
|
|
290
|
-
catch (error) {
|
|
291
|
-
(0, error_handler_1.handleError)('Failed to get API key usage', error);
|
|
292
|
-
}
|
|
293
|
-
}));
|
|
294
|
-
// Cluster commands
|
|
295
|
-
const cluster = commander_1.program.command('cluster').description('Manage Berget clusters');
|
|
296
|
-
// Removed cluster create command as it's not available in the API
|
|
297
|
-
cluster
|
|
298
|
-
.command('list')
|
|
299
|
-
.description('List all Berget clusters')
|
|
300
|
-
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
-
try {
|
|
302
|
-
const clusterService = cluster_service_1.ClusterService.getInstance();
|
|
303
|
-
const clusters = yield clusterService.listClusters();
|
|
304
|
-
console.log('NAME STATUS NODES CREATED');
|
|
305
|
-
clusters.forEach((cluster) => {
|
|
306
|
-
console.log(`${cluster.name.padEnd(22)} ${cluster.status.padEnd(9)} ${String(cluster.nodes).padEnd(8)} ${cluster.created}`);
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
catch (error) {
|
|
310
|
-
(0, error_handler_1.handleError)('Failed to list clusters', error);
|
|
311
|
-
}
|
|
312
|
-
}));
|
|
313
|
-
cluster
|
|
314
|
-
.command('usage')
|
|
315
|
-
.description('Get usage metrics for a specific cluster')
|
|
316
|
-
.argument('<clusterId>', 'Cluster ID')
|
|
317
|
-
.action((clusterId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
318
|
-
try {
|
|
319
|
-
const clusterService = cluster_service_1.ClusterService.getInstance();
|
|
320
|
-
const usage = yield clusterService.getClusterUsage(clusterId);
|
|
321
|
-
console.log('Cluster Usage:');
|
|
322
|
-
console.log(JSON.stringify(usage, null, 2));
|
|
323
|
-
}
|
|
324
|
-
catch (error) {
|
|
325
|
-
(0, error_handler_1.handleError)('Failed to get cluster usage', error);
|
|
326
|
-
}
|
|
327
|
-
}));
|
|
328
|
-
// Autocomplete command
|
|
329
|
-
commander_1.program
|
|
330
|
-
.command('autocomplete')
|
|
331
|
-
.command('install')
|
|
332
|
-
.description('Install shell autocompletion')
|
|
333
|
-
.action(() => {
|
|
334
|
-
console.log(chalk_1.default.green('✓ Berget autocomplete installed in your shell'));
|
|
335
|
-
console.log(chalk_1.default.green('✓ Shell completion for kubectl also installed'));
|
|
336
|
-
console.log('');
|
|
337
|
-
console.log('Restart your shell or run:');
|
|
338
|
-
console.log(' source ~/.bashrc');
|
|
339
|
-
});
|
|
340
|
-
// Removed flux commands as they're not available in the API
|
|
341
|
-
// Removed collaborator commands as they're not available in the API
|
|
342
|
-
// Removed helm commands as they're not available in the API
|
|
343
|
-
// Removed kubernetes-like commands as they're not available in the API
|
|
344
|
-
// Add token usage command
|
|
345
|
-
commander_1.program
|
|
346
|
-
.command('token-usage')
|
|
347
|
-
.description('Get token usage statistics')
|
|
348
|
-
.option('--model <modelId>', 'Get usage for a specific model')
|
|
349
|
-
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
350
|
-
try {
|
|
351
|
-
const client = (0, client_1.createAuthenticatedClient)();
|
|
352
|
-
let response;
|
|
353
|
-
if (options.model) {
|
|
354
|
-
const { data, error } = yield client.GET('/v1/usage/tokens/{modelId}', {
|
|
355
|
-
params: { path: { modelId: options.model } },
|
|
356
|
-
});
|
|
357
|
-
if (error)
|
|
358
|
-
throw new Error(JSON.stringify(error));
|
|
359
|
-
response = data;
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
const { data, error } = yield client.GET('/v1/usage/tokens');
|
|
363
|
-
if (error)
|
|
364
|
-
throw new Error(JSON.stringify(error));
|
|
365
|
-
response = data;
|
|
366
|
-
}
|
|
367
|
-
console.log('Token Usage:');
|
|
368
|
-
console.log(JSON.stringify(response, null, 2));
|
|
369
|
-
}
|
|
370
|
-
catch (error) {
|
|
371
|
-
(0, error_handler_1.handleError)('Failed to get token usage', error);
|
|
372
|
-
}
|
|
373
|
-
}));
|
|
374
|
-
// Add models command
|
|
375
|
-
commander_1.program
|
|
376
|
-
.command('models')
|
|
377
|
-
.description('List available AI models')
|
|
378
|
-
.option('--id <modelId>', 'Get details for a specific model')
|
|
379
|
-
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
380
|
-
try {
|
|
381
|
-
const client = (0, client_1.createAuthenticatedClient)();
|
|
382
|
-
let response;
|
|
383
|
-
if (options.id) {
|
|
384
|
-
const { data, error } = yield client.GET('/v1/models/{modelId}', {
|
|
385
|
-
params: { path: { modelId: options.id } },
|
|
386
|
-
});
|
|
387
|
-
if (error)
|
|
388
|
-
throw new Error(JSON.stringify(error));
|
|
389
|
-
response = data;
|
|
390
|
-
console.log('Model Details:');
|
|
391
|
-
console.log(JSON.stringify(response, null, 2));
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
const { data, error } = yield client.GET('/v1/models');
|
|
395
|
-
if (error)
|
|
396
|
-
throw new Error(JSON.stringify(error));
|
|
397
|
-
response = data;
|
|
398
|
-
console.log('Available Models:');
|
|
399
|
-
console.log('ID OWNED BY CAPABILITIES');
|
|
400
|
-
response.data.forEach((model) => {
|
|
401
|
-
const capabilities = [];
|
|
402
|
-
if (model.capabilities.vision)
|
|
403
|
-
capabilities.push('vision');
|
|
404
|
-
if (model.capabilities.function_calling)
|
|
405
|
-
capabilities.push('function_calling');
|
|
406
|
-
if (model.capabilities.json_mode)
|
|
407
|
-
capabilities.push('json_mode');
|
|
408
|
-
console.log(`${model.id.padEnd(24)} ${model.owned_by.padEnd(25)} ${capabilities.join(', ')}`);
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
(0, error_handler_1.handleError)('Failed to get models', error);
|
|
414
|
-
}
|
|
415
|
-
}));
|
|
416
|
-
// Add team command
|
|
417
|
-
commander_1.program
|
|
418
|
-
.command('team')
|
|
419
|
-
.description('Manage team members')
|
|
420
|
-
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
421
|
-
try {
|
|
422
|
-
const client = (0, client_1.createAuthenticatedClient)();
|
|
423
|
-
const { data, error } = yield client.GET('/v1/users');
|
|
424
|
-
if (error)
|
|
425
|
-
throw new Error(JSON.stringify(error));
|
|
426
|
-
console.log('Team Members:');
|
|
427
|
-
console.log('NAME EMAIL ROLE');
|
|
428
|
-
data.forEach((user) => {
|
|
429
|
-
console.log(`${user.name.padEnd(24)} ${user.email.padEnd(30)} ${user.role}`);
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
catch (error) {
|
|
433
|
-
(0, error_handler_1.handleError)('Failed to list team members', error);
|
|
434
|
-
}
|
|
435
|
-
}));
|
|
436
|
-
// Auto-detect .bergetconfig and switch clusters
|
|
437
|
-
const checkBergetConfig = () => {
|
|
438
|
-
const configPath = path.join(process.cwd(), '.bergetconfig');
|
|
439
|
-
if (fs.existsSync(configPath)) {
|
|
440
|
-
try {
|
|
441
|
-
const config = fs.readFileSync(configPath, 'utf8');
|
|
442
|
-
const match = config.match(/cluster:\s*(.+)/);
|
|
443
|
-
if (match && match[1]) {
|
|
444
|
-
const clusterName = match[1].trim();
|
|
445
|
-
console.log(`🔄 Berget: Switched to cluster "${clusterName}"`);
|
|
446
|
-
console.log('✓ kubectl config updated');
|
|
447
|
-
console.log('');
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
catch (error) {
|
|
451
|
-
// Silently ignore errors reading config
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
};
|
|
19
|
+
.option('--local', 'Use local API endpoint (hidden)', false)
|
|
20
|
+
.option('--debug', 'Enable debug output', false);
|
|
21
|
+
// Register all commands
|
|
22
|
+
(0, commands_1.registerCommands)(commander_1.program);
|
|
455
23
|
// Check for .bergetconfig if not running a command
|
|
456
24
|
if (process.argv.length <= 2) {
|
|
457
|
-
checkBergetConfig();
|
|
25
|
+
(0, config_checker_1.checkBergetConfig)();
|
|
458
26
|
}
|
|
459
27
|
commander_1.program.parse(process.argv);
|