berget 1.0.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 -471
- 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 +14 -0
- package/dist/src/services/auth-service.js +49 -47
- package/dist/src/services/chat-service.js +177 -0
- 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 -566
- 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 +16 -0
- package/src/services/auth-service.ts +90 -50
- package/src/services/chat-service.ts +177 -0
- 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
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.registerAuthCommands = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const auth_service_1 = require("../services/auth-service");
|
|
18
|
+
const client_1 = require("../client");
|
|
19
|
+
const error_handler_1 = require("../utils/error-handler");
|
|
20
|
+
/**
|
|
21
|
+
* Register authentication commands
|
|
22
|
+
*/
|
|
23
|
+
function registerAuthCommands(program) {
|
|
24
|
+
const auth = program
|
|
25
|
+
.command(auth_service_1.AuthService.COMMAND_GROUP)
|
|
26
|
+
.description('Manage authentication and authorization');
|
|
27
|
+
auth
|
|
28
|
+
.command(auth_service_1.AuthService.COMMANDS.LOGIN)
|
|
29
|
+
.description('Log in to Berget')
|
|
30
|
+
.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const authService = auth_service_1.AuthService.getInstance();
|
|
32
|
+
yield authService.login();
|
|
33
|
+
}));
|
|
34
|
+
auth
|
|
35
|
+
.command(auth_service_1.AuthService.COMMANDS.LOGOUT)
|
|
36
|
+
.description('Log out from Berget')
|
|
37
|
+
.action(() => {
|
|
38
|
+
(0, client_1.clearAuthToken)();
|
|
39
|
+
console.log(chalk_1.default.green('You have been logged out from Berget'));
|
|
40
|
+
});
|
|
41
|
+
auth
|
|
42
|
+
.command(auth_service_1.AuthService.COMMANDS.WHOAMI)
|
|
43
|
+
.description('Show information about the logged in user')
|
|
44
|
+
.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
try {
|
|
46
|
+
const authService = auth_service_1.AuthService.getInstance();
|
|
47
|
+
const profile = yield authService.whoami();
|
|
48
|
+
if (profile) {
|
|
49
|
+
console.log(chalk_1.default.bold(`Logged in as: ${profile.name || profile.login}`));
|
|
50
|
+
console.log(`Email: ${chalk_1.default.cyan(profile.email || 'Not available')}`);
|
|
51
|
+
console.log(`Role: ${chalk_1.default.cyan(profile.role || 'Not available')}`);
|
|
52
|
+
if (profile.company) {
|
|
53
|
+
console.log(`Company: ${chalk_1.default.cyan(profile.company.name)}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log(chalk_1.default.yellow('You are not logged in. Use `berget login` to log in.'));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
(0, error_handler_1.handleError)('You are not logged in or an error occurred', error);
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
exports.registerAuthCommands = registerAuthCommands;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerAutocompleteCommands = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
/**
|
|
9
|
+
* Register autocomplete commands
|
|
10
|
+
*/
|
|
11
|
+
function registerAutocompleteCommands(program) {
|
|
12
|
+
const autocomplete = program
|
|
13
|
+
.command('autocomplete')
|
|
14
|
+
.command('install')
|
|
15
|
+
.description('Install shell autocompletion')
|
|
16
|
+
.action(() => {
|
|
17
|
+
console.log(chalk_1.default.green('✓ Berget autocomplete installed in your shell'));
|
|
18
|
+
console.log(chalk_1.default.green('✓ Shell completion for kubectl also installed'));
|
|
19
|
+
console.log('');
|
|
20
|
+
console.log('Restart your shell or run:');
|
|
21
|
+
console.log(' source ~/.bashrc');
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.registerAutocompleteCommands = registerAutocompleteCommands;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.registerBillingCommands = void 0;
|
|
13
|
+
const command_structure_1 = require("../constants/command-structure");
|
|
14
|
+
const client_1 = require("../client");
|
|
15
|
+
const error_handler_1 = require("../utils/error-handler");
|
|
16
|
+
/**
|
|
17
|
+
* Register billing commands
|
|
18
|
+
*/
|
|
19
|
+
function registerBillingCommands(program) {
|
|
20
|
+
const billing = program
|
|
21
|
+
.command(command_structure_1.COMMAND_GROUPS.BILLING)
|
|
22
|
+
.description('Manage billing and usage');
|
|
23
|
+
billing
|
|
24
|
+
.command(command_structure_1.SUBCOMMANDS.BILLING.GET_USAGE)
|
|
25
|
+
.description('Get token usage statistics')
|
|
26
|
+
.option('--model <modelId>', 'Get usage for a specific model')
|
|
27
|
+
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
try {
|
|
29
|
+
const client = (0, client_1.createAuthenticatedClient)();
|
|
30
|
+
let response;
|
|
31
|
+
if (options.model) {
|
|
32
|
+
const { data, error } = yield client.GET('/v1/usage/tokens/{modelId}', {
|
|
33
|
+
params: { path: { modelId: options.model } },
|
|
34
|
+
});
|
|
35
|
+
if (error)
|
|
36
|
+
throw new Error(JSON.stringify(error));
|
|
37
|
+
response = data;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const { data, error } = yield client.GET('/v1/usage/tokens');
|
|
41
|
+
if (error)
|
|
42
|
+
throw new Error(JSON.stringify(error));
|
|
43
|
+
response = data;
|
|
44
|
+
}
|
|
45
|
+
console.log('Token Usage:');
|
|
46
|
+
console.log(JSON.stringify(response, null, 2));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
(0, error_handler_1.handleError)('Failed to get token usage', error);
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
exports.registerBillingCommands = registerBillingCommands;
|
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.registerChatCommands = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const readline_1 = __importDefault(require("readline"));
|
|
18
|
+
const command_structure_1 = require("../constants/command-structure");
|
|
19
|
+
const chat_service_1 = require("../services/chat-service");
|
|
20
|
+
const api_key_service_1 = require("../services/api-key-service");
|
|
21
|
+
const auth_service_1 = require("../services/auth-service");
|
|
22
|
+
const error_handler_1 = require("../utils/error-handler");
|
|
23
|
+
const default_api_key_1 = require("../utils/default-api-key");
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to get user confirmation
|
|
26
|
+
*/
|
|
27
|
+
function confirm(question) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const rl = readline_1.default.createInterface({
|
|
30
|
+
input: process.stdin,
|
|
31
|
+
output: process.stdout,
|
|
32
|
+
});
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
rl.question(question, (answer) => {
|
|
35
|
+
rl.close();
|
|
36
|
+
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register chat commands
|
|
43
|
+
*/
|
|
44
|
+
function registerChatCommands(program) {
|
|
45
|
+
const chat = program
|
|
46
|
+
.command(command_structure_1.COMMAND_GROUPS.CHAT)
|
|
47
|
+
.description('Interact with AI chat models');
|
|
48
|
+
chat
|
|
49
|
+
.command(command_structure_1.SUBCOMMANDS.CHAT.RUN)
|
|
50
|
+
.description('Run a chat session with a specified model')
|
|
51
|
+
.argument('[model]', 'Model to use (default: berget-70b-instruct)')
|
|
52
|
+
.option('-s, --system <message>', 'System message')
|
|
53
|
+
.option('-t, --temperature <temp>', 'Temperature (0-1)', parseFloat)
|
|
54
|
+
.option('-m, --max-tokens <tokens>', 'Maximum tokens to generate', parseInt)
|
|
55
|
+
.option('-k, --api-key <key>', 'API key to use for this chat session')
|
|
56
|
+
.option('--api-key-id <id>', 'ID of the API key to use from your saved keys')
|
|
57
|
+
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
try {
|
|
59
|
+
const chatService = chat_service_1.ChatService.getInstance();
|
|
60
|
+
// Check if we have an API key or need to get one
|
|
61
|
+
let apiKey = options.apiKey;
|
|
62
|
+
let apiKeyId = options.apiKeyId;
|
|
63
|
+
// If no API key or API key ID provided, check for default API key
|
|
64
|
+
if (!apiKey && !apiKeyId) {
|
|
65
|
+
const defaultApiKeyManager = default_api_key_1.DefaultApiKeyManager.getInstance();
|
|
66
|
+
const defaultApiKey = defaultApiKeyManager.getDefaultApiKey();
|
|
67
|
+
if (defaultApiKey) {
|
|
68
|
+
apiKeyId = defaultApiKey.id;
|
|
69
|
+
console.log(chalk_1.default.dim(`Using default API key: ${defaultApiKey.name}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// If no direct API key, try to get one from API key ID
|
|
73
|
+
if (!apiKey && apiKeyId) {
|
|
74
|
+
try {
|
|
75
|
+
const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
|
|
76
|
+
const keys = yield apiKeyService.list();
|
|
77
|
+
const selectedKey = keys.find((key) => key.id.toString() === options.apiKeyId);
|
|
78
|
+
if (!selectedKey) {
|
|
79
|
+
console.log(chalk_1.default.yellow(`API key with ID ${options.apiKeyId} not found. Using default authentication.`));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log(chalk_1.default.dim(`Using API key: ${selectedKey.name}`));
|
|
83
|
+
// We need to rotate the key to get the actual key value
|
|
84
|
+
if (yield confirm(chalk_1.default.yellow(`To use API key "${selectedKey.name}", it needs to be rotated. This will invalidate the current key. Continue? (y/n)`))) {
|
|
85
|
+
const rotatedKey = yield apiKeyService.rotate(options.apiKeyId);
|
|
86
|
+
apiKey = rotatedKey.key;
|
|
87
|
+
console.log(chalk_1.default.green(`API key "${selectedKey.name}" rotated successfully.`));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
console.log(chalk_1.default.yellow('Using default authentication instead.'));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error(chalk_1.default.red('Error fetching API key:'));
|
|
96
|
+
console.error(error);
|
|
97
|
+
console.log(chalk_1.default.yellow('Using default authentication instead.'));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Verify we have authentication before starting chat
|
|
101
|
+
if (!apiKey) {
|
|
102
|
+
try {
|
|
103
|
+
auth_service_1.AuthService.getInstance();
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.log(chalk_1.default.red('Error: Authentication required for chat'));
|
|
107
|
+
console.log(chalk_1.default.yellow('Please either:'));
|
|
108
|
+
console.log(chalk_1.default.yellow('1. Log in with `berget auth login`'));
|
|
109
|
+
console.log(chalk_1.default.yellow('2. Provide an API key with `--api-key`'));
|
|
110
|
+
console.log(chalk_1.default.yellow('3. Provide an API key ID with `--api-key-id`'));
|
|
111
|
+
console.log(chalk_1.default.yellow('4. Set a default API key with `berget api-keys set-default <id>`'));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Set up readline interface for user input
|
|
116
|
+
const rl = readline_1.default.createInterface({
|
|
117
|
+
input: process.stdin,
|
|
118
|
+
output: process.stdout,
|
|
119
|
+
});
|
|
120
|
+
// Prepare messages array
|
|
121
|
+
const messages = [];
|
|
122
|
+
// Add system message if provided
|
|
123
|
+
if (options.system) {
|
|
124
|
+
messages.push({
|
|
125
|
+
role: 'system',
|
|
126
|
+
content: options.system,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
console.log(chalk_1.default.cyan('Chat with Berget AI (type "exit" to quit)'));
|
|
130
|
+
console.log(chalk_1.default.cyan('----------------------------------------'));
|
|
131
|
+
// Start the conversation loop
|
|
132
|
+
const askQuestion = () => {
|
|
133
|
+
rl.question(chalk_1.default.green('You: '), (input) => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
var _a;
|
|
135
|
+
// Check if user wants to exit
|
|
136
|
+
if (input.toLowerCase() === 'exit') {
|
|
137
|
+
console.log(chalk_1.default.cyan('Goodbye!'));
|
|
138
|
+
rl.close();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// Add user message
|
|
142
|
+
messages.push({
|
|
143
|
+
role: 'user',
|
|
144
|
+
content: input,
|
|
145
|
+
});
|
|
146
|
+
try {
|
|
147
|
+
// Call the API
|
|
148
|
+
const response = yield chatService.createCompletion({
|
|
149
|
+
model: ((_a = options.args) === null || _a === void 0 ? void 0 : _a[0]) || 'berget-70b-instruct',
|
|
150
|
+
messages: messages,
|
|
151
|
+
temperature: options.temperature !== undefined ? options.temperature : 0.7,
|
|
152
|
+
max_tokens: options.maxTokens || 4096,
|
|
153
|
+
apiKey: apiKey,
|
|
154
|
+
});
|
|
155
|
+
// Debug output
|
|
156
|
+
if (program.opts().debug) {
|
|
157
|
+
console.log(chalk_1.default.yellow('DEBUG: Full response:'));
|
|
158
|
+
console.log(chalk_1.default.yellow(JSON.stringify(response, null, 2)));
|
|
159
|
+
}
|
|
160
|
+
// Check if response has the expected structure
|
|
161
|
+
if (!response ||
|
|
162
|
+
!response.choices ||
|
|
163
|
+
!response.choices[0] ||
|
|
164
|
+
!response.choices[0].message) {
|
|
165
|
+
console.error(chalk_1.default.red('Error: Unexpected response format from API'));
|
|
166
|
+
console.error(chalk_1.default.red('Response:', JSON.stringify(response, null, 2)));
|
|
167
|
+
throw new Error('Unexpected response format from API');
|
|
168
|
+
}
|
|
169
|
+
// Get assistant's response
|
|
170
|
+
const assistantMessage = response.choices[0].message.content;
|
|
171
|
+
// Add to messages array
|
|
172
|
+
messages.push({
|
|
173
|
+
role: 'assistant',
|
|
174
|
+
content: assistantMessage,
|
|
175
|
+
});
|
|
176
|
+
// Display the response
|
|
177
|
+
console.log(chalk_1.default.blue('Assistant: ') + assistantMessage);
|
|
178
|
+
console.log(); // Empty line for better readability
|
|
179
|
+
// Continue the conversation
|
|
180
|
+
askQuestion();
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.error(chalk_1.default.red('Error: Failed to get response'));
|
|
184
|
+
if (error instanceof Error) {
|
|
185
|
+
console.error(chalk_1.default.red(error.message));
|
|
186
|
+
}
|
|
187
|
+
// Continue despite error
|
|
188
|
+
askQuestion();
|
|
189
|
+
}
|
|
190
|
+
}));
|
|
191
|
+
};
|
|
192
|
+
// Start the conversation
|
|
193
|
+
askQuestion();
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
(0, error_handler_1.handleError)('Failed to create chat completion', error);
|
|
197
|
+
}
|
|
198
|
+
}));
|
|
199
|
+
chat
|
|
200
|
+
.command(command_structure_1.SUBCOMMANDS.CHAT.LIST)
|
|
201
|
+
.description('List available chat models')
|
|
202
|
+
.option('-k, --api-key <key>', 'API key to use for this request')
|
|
203
|
+
.option('--api-key-id <id>', 'ID of the API key to use from your saved keys')
|
|
204
|
+
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
try {
|
|
206
|
+
// If API key ID is provided, fetch the actual key
|
|
207
|
+
let apiKey = options.apiKey;
|
|
208
|
+
let apiKeyId = options.apiKeyId;
|
|
209
|
+
// If no API key or API key ID provided, check for default API key
|
|
210
|
+
if (!apiKey && !apiKeyId) {
|
|
211
|
+
const defaultApiKeyManager = default_api_key_1.DefaultApiKeyManager.getInstance();
|
|
212
|
+
const defaultApiKey = defaultApiKeyManager.getDefaultApiKey();
|
|
213
|
+
if (defaultApiKey) {
|
|
214
|
+
apiKeyId = defaultApiKey.id;
|
|
215
|
+
console.log(chalk_1.default.dim(`Using default API key: ${defaultApiKey.name}`));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (apiKeyId && !apiKey) {
|
|
219
|
+
try {
|
|
220
|
+
const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
|
|
221
|
+
const keys = yield apiKeyService.list();
|
|
222
|
+
const selectedKey = keys.find((key) => key.id.toString() === options.apiKeyId);
|
|
223
|
+
if (!selectedKey) {
|
|
224
|
+
console.log(chalk_1.default.yellow(`API key with ID ${options.apiKeyId} not found. Using default authentication.`));
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
console.log(chalk_1.default.dim(`Using API key: ${selectedKey.name}`));
|
|
228
|
+
// We need to rotate the key to get the actual key value
|
|
229
|
+
if (yield confirm(chalk_1.default.yellow(`To use API key "${selectedKey.name}", it needs to be rotated. This will invalidate the current key. Continue? (y/n)`))) {
|
|
230
|
+
const rotatedKey = yield apiKeyService.rotate(options.apiKeyId);
|
|
231
|
+
apiKey = rotatedKey.key;
|
|
232
|
+
console.log(chalk_1.default.green(`API key "${selectedKey.name}" rotated successfully.`));
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
console.log(chalk_1.default.yellow('Using default authentication instead.'));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.error(chalk_1.default.red('Error fetching API key:'));
|
|
241
|
+
console.error(error);
|
|
242
|
+
console.log(chalk_1.default.yellow('Using default authentication instead.'));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const chatService = chat_service_1.ChatService.getInstance();
|
|
246
|
+
const models = yield chatService.listModels(apiKey);
|
|
247
|
+
// Debug output
|
|
248
|
+
if (program.opts().debug) {
|
|
249
|
+
console.log(chalk_1.default.yellow('DEBUG: Models response:'));
|
|
250
|
+
console.log(chalk_1.default.yellow(JSON.stringify(models, null, 2)));
|
|
251
|
+
}
|
|
252
|
+
console.log(chalk_1.default.bold('Available Chat Models:'));
|
|
253
|
+
console.log(chalk_1.default.dim('─'.repeat(70)));
|
|
254
|
+
console.log(chalk_1.default.dim('MODEL ID'.padEnd(30)) +
|
|
255
|
+
chalk_1.default.dim('OWNER'.padEnd(25)) +
|
|
256
|
+
chalk_1.default.dim('CAPABILITIES'));
|
|
257
|
+
console.log(chalk_1.default.dim('─'.repeat(70)));
|
|
258
|
+
models.data.forEach((model) => {
|
|
259
|
+
const capabilities = [];
|
|
260
|
+
if (model.capabilities.vision)
|
|
261
|
+
capabilities.push('vision');
|
|
262
|
+
if (model.capabilities.function_calling)
|
|
263
|
+
capabilities.push('function_calling');
|
|
264
|
+
if (model.capabilities.json_mode)
|
|
265
|
+
capabilities.push('json_mode');
|
|
266
|
+
console.log(model.id.padEnd(30) +
|
|
267
|
+
model.owned_by.padEnd(25) +
|
|
268
|
+
capabilities.join(', '));
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
(0, error_handler_1.handleError)('Failed to list chat models', error);
|
|
273
|
+
}
|
|
274
|
+
}));
|
|
275
|
+
}
|
|
276
|
+
exports.registerChatCommands = registerChatCommands;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.registerClusterCommands = void 0;
|
|
13
|
+
const cluster_service_1 = require("../services/cluster-service");
|
|
14
|
+
const error_handler_1 = require("../utils/error-handler");
|
|
15
|
+
/**
|
|
16
|
+
* Register cluster commands
|
|
17
|
+
*/
|
|
18
|
+
function registerClusterCommands(program) {
|
|
19
|
+
const cluster = program
|
|
20
|
+
.command(cluster_service_1.ClusterService.COMMAND_GROUP)
|
|
21
|
+
.description('Manage Berget clusters');
|
|
22
|
+
cluster
|
|
23
|
+
.command(cluster_service_1.ClusterService.COMMANDS.LIST)
|
|
24
|
+
.description('List all Berget clusters')
|
|
25
|
+
.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
const clusterService = cluster_service_1.ClusterService.getInstance();
|
|
28
|
+
const clusters = yield clusterService.list();
|
|
29
|
+
console.log('NAME STATUS NODES CREATED');
|
|
30
|
+
clusters.forEach((cluster) => {
|
|
31
|
+
console.log(`${cluster.name.padEnd(22)} ${cluster.status.padEnd(9)} ${String(cluster.nodes).padEnd(8)} ${cluster.created}`);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
(0, error_handler_1.handleError)('Failed to list clusters', error);
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
cluster
|
|
39
|
+
.command(cluster_service_1.ClusterService.COMMANDS.GET_USAGE)
|
|
40
|
+
.description('Get usage metrics for a specific cluster')
|
|
41
|
+
.argument('<clusterId>', 'Cluster ID')
|
|
42
|
+
.action((clusterId) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
try {
|
|
44
|
+
const clusterService = cluster_service_1.ClusterService.getInstance();
|
|
45
|
+
const usage = yield clusterService.getUsage(clusterId);
|
|
46
|
+
console.log('Cluster Usage:');
|
|
47
|
+
console.log(JSON.stringify(usage, null, 2));
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
(0, error_handler_1.handleError)('Failed to get cluster usage', error);
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
cluster
|
|
54
|
+
.command(cluster_service_1.ClusterService.COMMANDS.DESCRIBE)
|
|
55
|
+
.description('Get detailed information about a cluster')
|
|
56
|
+
.argument('<clusterId>', 'Cluster ID')
|
|
57
|
+
.action((clusterId) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
try {
|
|
59
|
+
const clusterService = cluster_service_1.ClusterService.getInstance();
|
|
60
|
+
const clusterInfo = yield clusterService.describe(clusterId);
|
|
61
|
+
console.log('Cluster Details:');
|
|
62
|
+
console.log(JSON.stringify(clusterInfo, null, 2));
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
(0, error_handler_1.handleError)('Failed to describe cluster', error);
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
exports.registerClusterCommands = registerClusterCommands;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerCommands = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
const api_keys_1 = require("./api-keys");
|
|
6
|
+
const clusters_1 = require("./clusters");
|
|
7
|
+
const billing_1 = require("./billing");
|
|
8
|
+
const models_1 = require("./models");
|
|
9
|
+
const users_1 = require("./users");
|
|
10
|
+
const chat_1 = require("./chat");
|
|
11
|
+
const autocomplete_1 = require("./autocomplete");
|
|
12
|
+
/**
|
|
13
|
+
* Register all command groups with the program
|
|
14
|
+
*/
|
|
15
|
+
function registerCommands(program) {
|
|
16
|
+
(0, auth_1.registerAuthCommands)(program);
|
|
17
|
+
(0, api_keys_1.registerApiKeyCommands)(program);
|
|
18
|
+
(0, clusters_1.registerClusterCommands)(program);
|
|
19
|
+
(0, billing_1.registerBillingCommands)(program);
|
|
20
|
+
(0, models_1.registerModelCommands)(program);
|
|
21
|
+
(0, users_1.registerUserCommands)(program);
|
|
22
|
+
(0, chat_1.registerChatCommands)(program);
|
|
23
|
+
(0, autocomplete_1.registerAutocompleteCommands)(program);
|
|
24
|
+
}
|
|
25
|
+
exports.registerCommands = registerCommands;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.registerModelCommands = void 0;
|
|
13
|
+
const command_structure_1 = require("../constants/command-structure");
|
|
14
|
+
const client_1 = require("../client");
|
|
15
|
+
const error_handler_1 = require("../utils/error-handler");
|
|
16
|
+
/**
|
|
17
|
+
* Register models commands
|
|
18
|
+
*/
|
|
19
|
+
function registerModelCommands(program) {
|
|
20
|
+
const models = program
|
|
21
|
+
.command(command_structure_1.COMMAND_GROUPS.MODELS)
|
|
22
|
+
.description('Manage AI models');
|
|
23
|
+
models
|
|
24
|
+
.command(command_structure_1.SUBCOMMANDS.MODELS.LIST)
|
|
25
|
+
.description('List available AI models')
|
|
26
|
+
.option('--id <modelId>', 'Get details for a specific model')
|
|
27
|
+
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
try {
|
|
29
|
+
const client = (0, client_1.createAuthenticatedClient)();
|
|
30
|
+
let response;
|
|
31
|
+
if (options.id) {
|
|
32
|
+
const { data, error } = yield client.GET('/v1/models/{modelId}', {
|
|
33
|
+
params: { path: { modelId: options.id } },
|
|
34
|
+
});
|
|
35
|
+
if (error)
|
|
36
|
+
throw new Error(JSON.stringify(error));
|
|
37
|
+
response = data;
|
|
38
|
+
console.log('Model Details:');
|
|
39
|
+
console.log(JSON.stringify(response, null, 2));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const { data, error } = yield client.GET('/v1/models');
|
|
43
|
+
if (error)
|
|
44
|
+
throw new Error(JSON.stringify(error));
|
|
45
|
+
response = data;
|
|
46
|
+
console.log('Available Models:');
|
|
47
|
+
console.log('ID OWNED BY CAPABILITIES');
|
|
48
|
+
// Ensure response has the expected structure
|
|
49
|
+
const modelData = response;
|
|
50
|
+
if (modelData.data) {
|
|
51
|
+
modelData.data.forEach((model) => {
|
|
52
|
+
const capabilities = [];
|
|
53
|
+
if (model.capabilities.vision)
|
|
54
|
+
capabilities.push('vision');
|
|
55
|
+
if (model.capabilities.function_calling)
|
|
56
|
+
capabilities.push('function_calling');
|
|
57
|
+
if (model.capabilities.json_mode)
|
|
58
|
+
capabilities.push('json_mode');
|
|
59
|
+
console.log(`${model.id.padEnd(24)} ${model.owned_by.padEnd(25)} ${capabilities.join(', ')}`);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
(0, error_handler_1.handleError)('Failed to get models', error);
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
exports.registerModelCommands = registerModelCommands;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.registerUserCommands = void 0;
|
|
13
|
+
const command_structure_1 = require("../constants/command-structure");
|
|
14
|
+
const client_1 = require("../client");
|
|
15
|
+
const error_handler_1 = require("../utils/error-handler");
|
|
16
|
+
/**
|
|
17
|
+
* Register user commands
|
|
18
|
+
*/
|
|
19
|
+
function registerUserCommands(program) {
|
|
20
|
+
const users = program
|
|
21
|
+
.command(command_structure_1.COMMAND_GROUPS.USERS)
|
|
22
|
+
.description('Manage users');
|
|
23
|
+
users
|
|
24
|
+
.command(command_structure_1.SUBCOMMANDS.USERS.LIST)
|
|
25
|
+
.description('List team members')
|
|
26
|
+
.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
try {
|
|
28
|
+
const client = (0, client_1.createAuthenticatedClient)();
|
|
29
|
+
const { data, error } = yield client.GET('/v1/users');
|
|
30
|
+
if (error)
|
|
31
|
+
throw new Error(JSON.stringify(error));
|
|
32
|
+
console.log('Team Members:');
|
|
33
|
+
console.log('NAME EMAIL ROLE');
|
|
34
|
+
data.forEach((user) => {
|
|
35
|
+
console.log(`${user.name.padEnd(24)} ${user.email.padEnd(30)} ${user.role}`);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
(0, error_handler_1.handleError)('Failed to list team members', error);
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
exports.registerUserCommands = registerUserCommands;
|