berget 2.2.7 → 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.
- package/.github/workflows/publish.yml +6 -6
- package/.github/workflows/test.yml +1 -1
- package/.prettierrc +5 -3
- package/dist/index.js +24 -25
- package/dist/package.json +5 -3
- package/dist/src/agents/app.js +8 -8
- package/dist/src/agents/backend.js +3 -3
- package/dist/src/agents/devops.js +8 -8
- package/dist/src/agents/frontend.js +3 -3
- package/dist/src/agents/fullstack.js +3 -3
- package/dist/src/agents/index.js +18 -18
- package/dist/src/agents/quality.js +8 -8
- package/dist/src/agents/security.js +8 -8
- package/dist/src/client.js +115 -127
- package/dist/src/commands/api-keys.js +195 -202
- package/dist/src/commands/auth.js +16 -25
- package/dist/src/commands/autocomplete.js +8 -8
- package/dist/src/commands/billing.js +10 -19
- package/dist/src/commands/chat.js +139 -170
- package/dist/src/commands/clusters.js +21 -30
- package/dist/src/commands/code/__tests__/auth-sync.test.js +189 -186
- package/dist/src/commands/code/__tests__/fake-api-key-service.js +3 -13
- package/dist/src/commands/code/__tests__/fake-auth-service.js +21 -29
- package/dist/src/commands/code/__tests__/fake-command-runner.js +22 -33
- package/dist/src/commands/code/__tests__/fake-file-store.js +19 -41
- package/dist/src/commands/code/__tests__/fake-prompter.js +81 -97
- package/dist/src/commands/code/__tests__/setup-flow.test.js +295 -295
- package/dist/src/commands/code/adapters/clack-prompter.js +15 -32
- package/dist/src/commands/code/adapters/fs-file-store.js +25 -44
- package/dist/src/commands/code/adapters/spawn-command-runner.js +27 -41
- package/dist/src/commands/code/auth-sync.js +215 -228
- package/dist/src/commands/code/errors.js +15 -12
- package/dist/src/commands/code/setup.js +390 -425
- package/dist/src/commands/code.js +279 -294
- package/dist/src/commands/index.js +5 -5
- package/dist/src/commands/models.js +16 -25
- package/dist/src/commands/users.js +9 -18
- package/dist/src/constants/command-structure.js +138 -138
- package/dist/src/services/api-key-service.js +132 -152
- package/dist/src/services/auth-service.js +81 -95
- package/dist/src/services/browser-auth.js +121 -131
- package/dist/src/services/chat-service.js +369 -386
- package/dist/src/services/cluster-service.js +47 -62
- package/dist/src/services/collaborator-service.js +9 -21
- package/dist/src/services/flux-service.js +13 -25
- package/dist/src/services/helm-service.js +9 -21
- package/dist/src/services/kubectl-service.js +15 -29
- package/dist/src/utils/config-checker.js +7 -7
- package/dist/src/utils/config-loader.js +109 -109
- package/dist/src/utils/default-api-key.js +129 -139
- package/dist/src/utils/env-manager.js +55 -66
- package/dist/src/utils/error-handler.js +62 -62
- package/dist/src/utils/logger.js +74 -67
- package/dist/src/utils/markdown-renderer.js +28 -28
- package/dist/src/utils/opencode-validator.js +67 -69
- package/dist/src/utils/token-manager.js +67 -65
- package/dist/tests/commands/chat.test.js +30 -39
- package/dist/tests/commands/code.test.js +186 -195
- package/dist/tests/utils/config-loader.test.js +107 -107
- package/dist/tests/utils/env-manager.test.js +81 -90
- package/dist/tests/utils/opencode-validator.test.js +42 -41
- package/dist/vitest.config.js +1 -1
- package/eslint.config.mjs +50 -30
- package/index.ts +30 -31
- package/package.json +5 -3
- package/src/agents/app.ts +9 -9
- package/src/agents/backend.ts +4 -4
- package/src/agents/devops.ts +9 -9
- package/src/agents/frontend.ts +4 -4
- package/src/agents/fullstack.ts +4 -4
- package/src/agents/index.ts +27 -25
- package/src/agents/quality.ts +9 -9
- package/src/agents/security.ts +9 -9
- package/src/agents/types.ts +10 -10
- package/src/client.ts +85 -77
- package/src/commands/api-keys.ts +190 -185
- package/src/commands/auth.ts +15 -14
- package/src/commands/autocomplete.ts +10 -10
- package/src/commands/billing.ts +13 -12
- package/src/commands/chat.ts +145 -142
- package/src/commands/clusters.ts +20 -19
- package/src/commands/code/__tests__/auth-sync.test.ts +176 -175
- package/src/commands/code/__tests__/fake-api-key-service.ts +2 -2
- package/src/commands/code/__tests__/fake-auth-service.ts +18 -18
- package/src/commands/code/__tests__/fake-command-runner.ts +28 -22
- package/src/commands/code/__tests__/fake-file-store.ts +15 -15
- package/src/commands/code/__tests__/fake-prompter.ts +86 -85
- package/src/commands/code/__tests__/setup-flow.test.ts +253 -251
- package/src/commands/code/adapters/clack-prompter.ts +32 -30
- package/src/commands/code/adapters/fs-file-store.ts +18 -17
- package/src/commands/code/adapters/spawn-command-runner.ts +20 -15
- package/src/commands/code/auth-sync.ts +210 -210
- package/src/commands/code/errors.ts +11 -11
- package/src/commands/code/ports/auth-services.ts +7 -7
- package/src/commands/code/ports/command-runner.ts +2 -2
- package/src/commands/code/ports/file-store.ts +3 -3
- package/src/commands/code/ports/prompter.ts +13 -13
- package/src/commands/code/setup.ts +408 -406
- package/src/commands/code.ts +288 -287
- package/src/commands/index.ts +11 -10
- package/src/commands/models.ts +19 -18
- package/src/commands/users.ts +11 -10
- package/src/constants/command-structure.ts +159 -159
- package/src/services/api-key-service.ts +85 -85
- package/src/services/auth-service.ts +55 -54
- package/src/services/browser-auth.ts +62 -62
- package/src/services/chat-service.ts +169 -170
- package/src/services/cluster-service.ts +28 -28
- package/src/services/collaborator-service.ts +6 -6
- package/src/services/flux-service.ts +17 -17
- package/src/services/helm-service.ts +11 -11
- package/src/services/kubectl-service.ts +12 -12
- package/src/types/api.d.ts +1933 -1933
- package/src/types/json.d.ts +1 -1
- package/src/utils/config-checker.ts +6 -6
- package/src/utils/config-loader.ts +130 -129
- package/src/utils/default-api-key.ts +81 -80
- package/src/utils/env-manager.ts +37 -37
- package/src/utils/error-handler.ts +64 -64
- package/src/utils/logger.ts +72 -66
- package/src/utils/markdown-renderer.ts +28 -28
- package/src/utils/opencode-validator.ts +72 -71
- package/src/utils/token-manager.ts +69 -68
- package/tests/commands/chat.test.ts +32 -31
- package/tests/commands/code.test.ts +182 -181
- package/tests/utils/config-loader.test.ts +111 -110
- package/tests/utils/env-manager.test.ts +83 -79
- package/tests/utils/opencode-validator.test.ts +43 -42
- package/tsconfig.json +2 -1
- package/vitest.config.ts +2 -2
package/src/commands/auth.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { clearAuthToken } from
|
|
5
|
-
import {
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
import { clearAuthToken } from '../client';
|
|
5
|
+
import { AuthService } from '../services/auth-service';
|
|
6
|
+
import { handleError } from '../utils/error-handler';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Register authentication commands
|
|
@@ -10,11 +11,11 @@ import { handleError } from "../utils/error-handler";
|
|
|
10
11
|
export function registerAuthCommands(program: Command): void {
|
|
11
12
|
const auth = program
|
|
12
13
|
.command(AuthService.COMMAND_GROUP)
|
|
13
|
-
.description(
|
|
14
|
+
.description('Manage authentication and authorization');
|
|
14
15
|
|
|
15
16
|
auth
|
|
16
17
|
.command(AuthService.COMMANDS.LOGIN)
|
|
17
|
-
.description(
|
|
18
|
+
.description('Log in to Berget')
|
|
18
19
|
.action(async () => {
|
|
19
20
|
const authService = AuthService.getInstance();
|
|
20
21
|
await authService.login();
|
|
@@ -22,15 +23,15 @@ export function registerAuthCommands(program: Command): void {
|
|
|
22
23
|
|
|
23
24
|
auth
|
|
24
25
|
.command(AuthService.COMMANDS.LOGOUT)
|
|
25
|
-
.description(
|
|
26
|
+
.description('Log out from Berget')
|
|
26
27
|
.action(() => {
|
|
27
28
|
clearAuthToken();
|
|
28
|
-
console.log(chalk.green(
|
|
29
|
+
console.log(chalk.green('You have been logged out from Berget'));
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
auth
|
|
32
33
|
.command(AuthService.COMMANDS.WHOAMI)
|
|
33
|
-
.description(
|
|
34
|
+
.description('Show information about the logged in user')
|
|
34
35
|
.action(async () => {
|
|
35
36
|
try {
|
|
36
37
|
const authService = AuthService.getInstance();
|
|
@@ -38,17 +39,17 @@ export function registerAuthCommands(program: Command): void {
|
|
|
38
39
|
|
|
39
40
|
if (profile) {
|
|
40
41
|
console.log(chalk.bold(`Logged in as: ${profile.name || profile.login}`));
|
|
41
|
-
console.log(`Email: ${chalk.cyan(profile.email ||
|
|
42
|
-
console.log(`Role: ${chalk.cyan(profile.role ||
|
|
42
|
+
console.log(`Email: ${chalk.cyan(profile.email || 'Not available')}`);
|
|
43
|
+
console.log(`Role: ${chalk.cyan(profile.role || 'Not available')}`);
|
|
43
44
|
|
|
44
45
|
if (profile.company) {
|
|
45
46
|
console.log(`Company: ${chalk.cyan(profile.company.name)}`);
|
|
46
47
|
}
|
|
47
48
|
} else {
|
|
48
|
-
console.log(chalk.yellow(
|
|
49
|
+
console.log(chalk.yellow('You are not logged in. Use `berget login` to log in.'));
|
|
49
50
|
}
|
|
50
51
|
} catch (error) {
|
|
51
|
-
handleError(
|
|
52
|
+
handleError('You are not logged in or an error occurred', error);
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
55
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Register autocomplete commands
|
|
6
6
|
*/
|
|
7
7
|
export function registerAutocompleteCommands(program: Command): void {
|
|
8
8
|
program
|
|
9
|
-
.command(
|
|
10
|
-
.command(
|
|
11
|
-
.description(
|
|
9
|
+
.command('autocomplete')
|
|
10
|
+
.command('install')
|
|
11
|
+
.description('Install shell autocompletion')
|
|
12
12
|
.action(() => {
|
|
13
|
-
console.log(chalk.green(
|
|
14
|
-
console.log(chalk.green(
|
|
15
|
-
console.log(
|
|
16
|
-
console.log(
|
|
17
|
-
console.log(
|
|
13
|
+
console.log(chalk.green('✓ Berget autocomplete installed in your shell'));
|
|
14
|
+
console.log(chalk.green('✓ Shell completion for kubectl also installed'));
|
|
15
|
+
console.log('');
|
|
16
|
+
console.log('Restart your shell or run:');
|
|
17
|
+
console.log(' source ~/.bashrc');
|
|
18
18
|
});
|
|
19
19
|
}
|
package/src/commands/billing.ts
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
|
|
3
|
-
import { createAuthenticatedClient } from
|
|
4
|
-
import {
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
|
|
3
|
+
import { createAuthenticatedClient } from '../client';
|
|
4
|
+
import { COMMAND_GROUPS, SUBCOMMANDS } from '../constants/command-structure';
|
|
5
|
+
import { handleError } from '../utils/error-handler';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Register billing commands
|
|
8
9
|
*/
|
|
9
10
|
export function registerBillingCommands(program: Command): void {
|
|
10
|
-
const billing = program.command(COMMAND_GROUPS.BILLING).description(
|
|
11
|
+
const billing = program.command(COMMAND_GROUPS.BILLING).description('Manage billing and usage');
|
|
11
12
|
|
|
12
13
|
billing
|
|
13
14
|
.command(SUBCOMMANDS.BILLING.GET_USAGE)
|
|
14
|
-
.description(
|
|
15
|
-
.option(
|
|
16
|
-
.action(async options => {
|
|
15
|
+
.description('Get token usage statistics')
|
|
16
|
+
.option('--model <modelId>', 'Get usage for a specific model')
|
|
17
|
+
.action(async (options) => {
|
|
17
18
|
try {
|
|
18
19
|
const client = createAuthenticatedClient();
|
|
19
20
|
let response;
|
|
20
21
|
|
|
21
22
|
if (options.model) {
|
|
22
|
-
const { data, error } = await client.GET(
|
|
23
|
+
const { data, error } = await client.GET('/v1/usage/tokens/{modelId}', {
|
|
23
24
|
params: { path: { modelId: options.model } },
|
|
24
25
|
});
|
|
25
26
|
if (error) throw new Error(JSON.stringify(error));
|
|
26
27
|
response = data;
|
|
27
28
|
} else {
|
|
28
|
-
const { data, error } = await client.GET(
|
|
29
|
+
const { data, error } = await client.GET('/v1/usage/tokens');
|
|
29
30
|
if (error) throw new Error(JSON.stringify(error));
|
|
30
31
|
response = data;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
console.log(
|
|
34
|
+
console.log('Token Usage:');
|
|
34
35
|
console.log(JSON.stringify(response, null, 2));
|
|
35
36
|
} catch (error) {
|
|
36
|
-
handleError(
|
|
37
|
+
handleError('Failed to get token usage', error);
|
|
37
38
|
}
|
|
38
39
|
});
|
|
39
40
|
}
|