berget 2.2.7 → 2.2.9
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 +7 -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 +181 -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 +8 -8
- 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 +65 -30
- package/index.ts +30 -31
- package/package.json +7 -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 +180 -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 +170 -171
- 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 +7 -7
- 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
|
@@ -1,86 +1,75 @@
|
|
|
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
|
-
exports.
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const promises_1 = require("fs/promises");
|
|
6
|
+
exports.updateEnvFile = exports.hasEnvKey = void 0;
|
|
19
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
20
8
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
function updateEnvFile(options) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const { envPath = path_1.default.join(process.cwd(), ".env"), key, value, comment, force = false, } = options;
|
|
28
|
-
try {
|
|
29
|
-
let existingContent = "";
|
|
30
|
-
let parsed = {};
|
|
31
|
-
// Read existing .env file if it exists
|
|
32
|
-
if (fs_1.default.existsSync(envPath)) {
|
|
33
|
-
existingContent = fs_1.default.readFileSync(envPath, "utf8");
|
|
34
|
-
parsed = dotenv_1.default.parse(existingContent);
|
|
35
|
-
}
|
|
36
|
-
// Check if key already exists and we're not forcing
|
|
37
|
-
if (parsed[key] && !force) {
|
|
38
|
-
console.log(chalk_1.default.yellow(`⚠ ${key} already exists in .env - leaving unchanged`));
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
// Update the parsed object
|
|
42
|
-
parsed[key] = value;
|
|
43
|
-
// Generate new .env content
|
|
44
|
-
let newContent = "";
|
|
45
|
-
// Add comment at the top if this is a new file
|
|
46
|
-
if (!existingContent && comment) {
|
|
47
|
-
newContent += `# ${comment}\n`;
|
|
48
|
-
}
|
|
49
|
-
// Convert parsed object back to .env format
|
|
50
|
-
for (const [envKey, envValue] of Object.entries(parsed)) {
|
|
51
|
-
newContent += `${envKey}=${envValue}\n`;
|
|
52
|
-
}
|
|
53
|
-
// Write the updated content
|
|
54
|
-
yield (0, promises_1.writeFile)(envPath, newContent.trim() + "\n");
|
|
55
|
-
if (existingContent) {
|
|
56
|
-
console.log(chalk_1.default.green(`✓ Updated .env with ${key}`));
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
console.log(chalk_1.default.green(`✓ Created .env with ${key}`));
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
console.error(chalk_1.default.red(`Failed to update .env file:`));
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
exports.updateEnvFile = updateEnvFile;
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const promises_1 = require("node:fs/promises");
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
70
12
|
/**
|
|
71
13
|
* Checks if a .env file exists and contains a specific key
|
|
72
14
|
*/
|
|
73
|
-
function hasEnvKey(
|
|
74
|
-
if (!
|
|
15
|
+
function hasEnvKey(environmentPath = node_path_1.default.join(process.cwd(), '.env'), key) {
|
|
16
|
+
if (!node_fs_1.default.existsSync(environmentPath)) {
|
|
75
17
|
return false;
|
|
76
18
|
}
|
|
77
19
|
try {
|
|
78
|
-
const content =
|
|
20
|
+
const content = node_fs_1.default.readFileSync(environmentPath, 'utf8');
|
|
79
21
|
const parsed = dotenv_1.default.parse(content);
|
|
80
22
|
return key in parsed;
|
|
81
23
|
}
|
|
82
|
-
catch
|
|
24
|
+
catch {
|
|
83
25
|
return false;
|
|
84
26
|
}
|
|
85
27
|
}
|
|
86
28
|
exports.hasEnvKey = hasEnvKey;
|
|
29
|
+
/**
|
|
30
|
+
* Safely updates .env file without overwriting existing keys
|
|
31
|
+
* Uses dotenv for proper parsing and formatting
|
|
32
|
+
*/
|
|
33
|
+
async function updateEnvFile(options) {
|
|
34
|
+
const { comment, envPath: environmentPath = node_path_1.default.join(process.cwd(), '.env'), force = false, key, value, } = options;
|
|
35
|
+
try {
|
|
36
|
+
let existingContent = '';
|
|
37
|
+
let parsed = {};
|
|
38
|
+
// Read existing .env file if it exists
|
|
39
|
+
if (node_fs_1.default.existsSync(environmentPath)) {
|
|
40
|
+
existingContent = node_fs_1.default.readFileSync(environmentPath, 'utf8');
|
|
41
|
+
parsed = dotenv_1.default.parse(existingContent);
|
|
42
|
+
}
|
|
43
|
+
// Check if key already exists and we're not forcing
|
|
44
|
+
if (parsed[key] && !force) {
|
|
45
|
+
console.log(chalk_1.default.yellow(`⚠ ${key} already exists in .env - leaving unchanged`));
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
// Update the parsed object
|
|
49
|
+
parsed[key] = value;
|
|
50
|
+
// Generate new .env content
|
|
51
|
+
let newContent = '';
|
|
52
|
+
// Add comment at the top if this is a new file
|
|
53
|
+
if (!existingContent && comment) {
|
|
54
|
+
newContent += `# ${comment}\n`;
|
|
55
|
+
}
|
|
56
|
+
// Convert parsed object back to .env format
|
|
57
|
+
for (const [environmentKey, environmentValue] of Object.entries(parsed)) {
|
|
58
|
+
newContent += `${environmentKey}=${environmentValue}\n`;
|
|
59
|
+
}
|
|
60
|
+
// Write the updated content
|
|
61
|
+
await (0, promises_1.writeFile)(environmentPath, newContent.trim() + '\n');
|
|
62
|
+
if (existingContent) {
|
|
63
|
+
console.log(chalk_1.default.green(`✓ Updated .env with ${key}`));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.log(chalk_1.default.green(`✓ Created .env with ${key}`));
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error(chalk_1.default.red(`Failed to update .env file:`));
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.updateEnvFile = updateEnvFile;
|
|
@@ -10,24 +10,24 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
10
10
|
*/
|
|
11
11
|
function handleError(message, error) {
|
|
12
12
|
console.error(chalk_1.default.red(`❌ Error: ${message}`));
|
|
13
|
-
let errorDetails =
|
|
14
|
-
let errorCode =
|
|
15
|
-
let errorType =
|
|
13
|
+
let errorDetails = '';
|
|
14
|
+
let errorCode = '';
|
|
15
|
+
let errorType = '';
|
|
16
16
|
// If the error is a string (like JSON.stringify(error))
|
|
17
|
-
if (typeof error ===
|
|
17
|
+
if (typeof error === 'string') {
|
|
18
18
|
try {
|
|
19
19
|
// Try to parse it as JSON
|
|
20
20
|
const parsedError = JSON.parse(error);
|
|
21
21
|
if (parsedError.error) {
|
|
22
22
|
errorDetails = parsedError.error.message || parsedError.error;
|
|
23
23
|
errorCode = parsedError.error.code || parsedError.code;
|
|
24
|
-
errorType = parsedError.error.type ||
|
|
24
|
+
errorType = parsedError.error.type || '';
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
errorDetails = error;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
catch
|
|
30
|
+
catch {
|
|
31
31
|
// If it's not valid JSON, just print the string
|
|
32
32
|
errorDetails = error;
|
|
33
33
|
}
|
|
@@ -53,75 +53,75 @@ exports.handleError = handleError;
|
|
|
53
53
|
* Provides helpful troubleshooting tips based on error type
|
|
54
54
|
*/
|
|
55
55
|
function provideTroubleshootingTips(errorType, errorCode, errorDetails) {
|
|
56
|
-
console.error(chalk_1.default.blue(
|
|
56
|
+
console.error(chalk_1.default.blue('\n💡 Troubleshooting tips:'));
|
|
57
57
|
// Authentication errors
|
|
58
|
-
if (errorType ===
|
|
59
|
-
errorCode ===
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
console.error(chalk_1.default.yellow(
|
|
63
|
-
console.error(chalk_1.default.white(
|
|
64
|
-
console.error(chalk_1.default.white(
|
|
65
|
-
console.error(chalk_1.default.white(
|
|
58
|
+
if (errorType === 'authentication_error' ||
|
|
59
|
+
errorCode === 'AUTH_FAILED' ||
|
|
60
|
+
errorDetails?.includes('Unauthorized') ||
|
|
61
|
+
errorDetails?.includes('Authentication failed')) {
|
|
62
|
+
console.error(chalk_1.default.yellow(' 🔐 Authentication issue detected:'));
|
|
63
|
+
console.error(chalk_1.default.white(' • Run `berget auth login` to log in'));
|
|
64
|
+
console.error(chalk_1.default.white(' • Check if your session has expired'));
|
|
65
|
+
console.error(chalk_1.default.white(' • Verify you have the correct permissions'));
|
|
66
66
|
}
|
|
67
67
|
// Network/connection errors
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
console.error(chalk_1.default.yellow(
|
|
73
|
-
console.error(chalk_1.default.white(
|
|
74
|
-
console.error(chalk_1.default.white(
|
|
75
|
-
console.error(chalk_1.default.white(
|
|
76
|
-
console.error(chalk_1.default.white(
|
|
68
|
+
if (errorDetails?.includes('fetch failed') ||
|
|
69
|
+
errorDetails?.includes('ECONNREFUSED') ||
|
|
70
|
+
errorDetails?.includes('ENOTFOUND') ||
|
|
71
|
+
errorDetails?.includes('network')) {
|
|
72
|
+
console.error(chalk_1.default.yellow(' 🌐 Network issue detected:'));
|
|
73
|
+
console.error(chalk_1.default.white(' • Check your internet connection'));
|
|
74
|
+
console.error(chalk_1.default.white(' • Verify you can reach api.berget.ai'));
|
|
75
|
+
console.error(chalk_1.default.white(' • Try again in a few minutes'));
|
|
76
|
+
console.error(chalk_1.default.white(' • Check if any firewall is blocking the request'));
|
|
77
77
|
}
|
|
78
78
|
// API key errors
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
errorType ===
|
|
82
|
-
console.error(chalk_1.default.yellow(
|
|
83
|
-
console.error(chalk_1.default.white(
|
|
79
|
+
if (errorCode?.includes('API_KEY') ||
|
|
80
|
+
errorDetails?.includes('API key') ||
|
|
81
|
+
errorType === 'invalid_request_error') {
|
|
82
|
+
console.error(chalk_1.default.yellow(' 🔑 API key issue detected:'));
|
|
83
|
+
console.error(chalk_1.default.white(' • Run `berget api-keys list` to check your keys'));
|
|
84
84
|
console.error(chalk_1.default.white(' • Create a new key with `berget api-keys create --name "My Key"`'));
|
|
85
|
-
console.error(chalk_1.default.white(
|
|
86
|
-
console.error(chalk_1.default.white(
|
|
85
|
+
console.error(chalk_1.default.white(' • Set a default key with `berget api-keys set-default <id>`'));
|
|
86
|
+
console.error(chalk_1.default.white(' • Check if your API key has expired'));
|
|
87
87
|
}
|
|
88
88
|
// Rate limiting
|
|
89
|
-
if (errorCode ===
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.error(chalk_1.default.yellow(
|
|
93
|
-
console.error(chalk_1.default.white(
|
|
94
|
-
console.error(chalk_1.default.white(
|
|
95
|
-
console.error(chalk_1.default.white(
|
|
89
|
+
if (errorCode === 'RATE_LIMIT_EXCEEDED' ||
|
|
90
|
+
errorDetails?.includes('rate limit') ||
|
|
91
|
+
errorDetails?.includes('too many requests')) {
|
|
92
|
+
console.error(chalk_1.default.yellow(' ⏱️ Rate limit exceeded:'));
|
|
93
|
+
console.error(chalk_1.default.white(' • Wait a few minutes before trying again'));
|
|
94
|
+
console.error(chalk_1.default.white(' • Consider upgrading your plan for higher limits'));
|
|
95
|
+
console.error(chalk_1.default.white(' • Use `berget billing get-usage` to check your usage'));
|
|
96
96
|
}
|
|
97
97
|
// Server errors
|
|
98
|
-
if (
|
|
99
|
-
errorType ===
|
|
100
|
-
(errorCode && parseInt(errorCode) >= 500)) {
|
|
101
|
-
console.error(chalk_1.default.yellow(
|
|
102
|
-
console.error(chalk_1.default.white(
|
|
103
|
-
console.error(chalk_1.default.white(
|
|
104
|
-
console.error(chalk_1.default.white(
|
|
105
|
-
console.error(chalk_1.default.white(
|
|
98
|
+
if (errorCode?.includes('SERVER_ERROR') ||
|
|
99
|
+
errorType === 'server_error' ||
|
|
100
|
+
(errorCode && Number.parseInt(errorCode) >= 500)) {
|
|
101
|
+
console.error(chalk_1.default.yellow(' 🖥️ Server issue detected:'));
|
|
102
|
+
console.error(chalk_1.default.white(' • This is a temporary problem on our end'));
|
|
103
|
+
console.error(chalk_1.default.white(' • Try again in a few minutes'));
|
|
104
|
+
console.error(chalk_1.default.white(' • Check status.berget.ai for service status'));
|
|
105
|
+
console.error(chalk_1.default.white(' • Contact support if the problem persists'));
|
|
106
106
|
}
|
|
107
107
|
// Cluster errors
|
|
108
|
-
if (
|
|
109
|
-
console.error(chalk_1.default.yellow(
|
|
110
|
-
console.error(chalk_1.default.white(
|
|
111
|
-
console.error(chalk_1.default.white(
|
|
112
|
-
console.error(chalk_1.default.white(
|
|
108
|
+
if (errorCode?.includes('CLUSTERS') || errorDetails?.includes('cluster')) {
|
|
109
|
+
console.error(chalk_1.default.yellow(' 🏗️ Cluster issue detected:'));
|
|
110
|
+
console.error(chalk_1.default.white(' • Clusters may be temporarily unavailable'));
|
|
111
|
+
console.error(chalk_1.default.white(' • Try again later or contact support'));
|
|
112
|
+
console.error(chalk_1.default.white(' • Check your cluster permissions'));
|
|
113
113
|
}
|
|
114
114
|
// Generic fallback
|
|
115
|
-
if (!
|
|
116
|
-
!
|
|
117
|
-
!
|
|
118
|
-
!
|
|
119
|
-
!
|
|
120
|
-
!
|
|
121
|
-
console.error(chalk_1.default.yellow(
|
|
122
|
-
console.error(chalk_1.default.white(
|
|
123
|
-
console.error(chalk_1.default.white(
|
|
124
|
-
console.error(chalk_1.default.white(
|
|
115
|
+
if (!errorType?.includes('authentication') &&
|
|
116
|
+
!errorDetails?.includes('fetch failed') &&
|
|
117
|
+
!errorCode?.includes('API_KEY') &&
|
|
118
|
+
!errorCode?.includes('RATE_LIMIT') &&
|
|
119
|
+
!errorCode?.includes('SERVER_ERROR') &&
|
|
120
|
+
!errorCode?.includes('CLUSTERS')) {
|
|
121
|
+
console.error(chalk_1.default.yellow(' ❓ General issue:'));
|
|
122
|
+
console.error(chalk_1.default.white(' • Try running the command with --debug for more info'));
|
|
123
|
+
console.error(chalk_1.default.white(' • Check your configuration with `berget auth whoami`'));
|
|
124
|
+
console.error(chalk_1.default.white(' • Contact support if the problem persists'));
|
|
125
125
|
}
|
|
126
|
-
console.error(chalk_1.default.dim(
|
|
126
|
+
console.error(chalk_1.default.dim('\nNeed more help? Visit https://docs.berget.ai or contact support@berget.ai'));
|
|
127
127
|
}
|
package/dist/src/utils/logger.js
CHANGED
|
@@ -20,16 +20,17 @@ var LogLevel;
|
|
|
20
20
|
* Logger class for centralized logging with configurable log levels
|
|
21
21
|
*/
|
|
22
22
|
class Logger {
|
|
23
|
+
static instance;
|
|
24
|
+
logLevel = LogLevel.INFO; // Default log level
|
|
23
25
|
constructor() {
|
|
24
|
-
this.logLevel = LogLevel.INFO; // Default log level
|
|
25
26
|
// Set log level from environment variable or command line argument
|
|
26
27
|
if (process.env.LOG_LEVEL) {
|
|
27
28
|
this.setLogLevelFromString(process.env.LOG_LEVEL);
|
|
28
29
|
}
|
|
29
|
-
else if (process.argv.includes(
|
|
30
|
+
else if (process.argv.includes('--debug')) {
|
|
30
31
|
this.logLevel = LogLevel.DEBUG;
|
|
31
32
|
}
|
|
32
|
-
else if (process.argv.includes(
|
|
33
|
+
else if (process.argv.includes('--quiet')) {
|
|
33
34
|
this.logLevel = LogLevel.ERROR;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -40,35 +41,30 @@ class Logger {
|
|
|
40
41
|
return Logger.instance;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
+
* Log a debug message (only shown at DEBUG level)
|
|
44
45
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
case "warn":
|
|
54
|
-
this.logLevel = LogLevel.WARN;
|
|
55
|
-
break;
|
|
56
|
-
case "info":
|
|
57
|
-
this.logLevel = LogLevel.INFO;
|
|
58
|
-
break;
|
|
59
|
-
case "debug":
|
|
60
|
-
this.logLevel = LogLevel.DEBUG;
|
|
61
|
-
break;
|
|
62
|
-
default:
|
|
63
|
-
// Invalid log level, keep default
|
|
64
|
-
console.warn(`Invalid log level: ${level}. Using default (INFO).`);
|
|
46
|
+
debug(message, ...arguments_) {
|
|
47
|
+
if (this.logLevel >= LogLevel.DEBUG) {
|
|
48
|
+
if (arguments_.length > 0) {
|
|
49
|
+
console.log(chalk_1.default.yellow(`DEBUG: ${message}`), ...arguments_);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log(chalk_1.default.yellow(`DEBUG: ${message}`));
|
|
53
|
+
}
|
|
65
54
|
}
|
|
66
55
|
}
|
|
67
56
|
/**
|
|
68
|
-
*
|
|
57
|
+
* Log an error message (shown at ERROR level and above)
|
|
69
58
|
*/
|
|
70
|
-
|
|
71
|
-
this.logLevel
|
|
59
|
+
error(message, ...arguments_) {
|
|
60
|
+
if (this.logLevel >= LogLevel.ERROR) {
|
|
61
|
+
if (arguments_.length > 0) {
|
|
62
|
+
console.error(chalk_1.default.red(message), ...arguments_);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
console.error(chalk_1.default.red(message));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
72
68
|
}
|
|
73
69
|
/**
|
|
74
70
|
* Get the current log level
|
|
@@ -77,80 +73,91 @@ class Logger {
|
|
|
77
73
|
return this.logLevel;
|
|
78
74
|
}
|
|
79
75
|
/**
|
|
80
|
-
* Log
|
|
76
|
+
* Log an info message (shown at INFO level and above)
|
|
81
77
|
*/
|
|
82
|
-
|
|
83
|
-
if (this.logLevel >= LogLevel.
|
|
84
|
-
if (
|
|
85
|
-
console.log(chalk_1.default.
|
|
78
|
+
info(message, ...arguments_) {
|
|
79
|
+
if (this.logLevel >= LogLevel.INFO) {
|
|
80
|
+
if (arguments_.length > 0) {
|
|
81
|
+
console.log(chalk_1.default.blue(message), ...arguments_);
|
|
86
82
|
}
|
|
87
83
|
else {
|
|
88
|
-
console.log(chalk_1.default.
|
|
84
|
+
console.log(chalk_1.default.blue(message));
|
|
89
85
|
}
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
88
|
/**
|
|
93
|
-
* Log
|
|
89
|
+
* Log a plain message without color (shown at INFO level and above)
|
|
94
90
|
*/
|
|
95
|
-
|
|
91
|
+
log(message, ...arguments_) {
|
|
96
92
|
if (this.logLevel >= LogLevel.INFO) {
|
|
97
|
-
if (
|
|
98
|
-
console.log(
|
|
93
|
+
if (arguments_.length > 0) {
|
|
94
|
+
console.log(message, ...arguments_);
|
|
99
95
|
}
|
|
100
96
|
else {
|
|
101
|
-
console.log(
|
|
97
|
+
console.log(message);
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
100
|
}
|
|
105
101
|
/**
|
|
106
|
-
*
|
|
102
|
+
* Set the log level
|
|
107
103
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (args.length > 0) {
|
|
111
|
-
console.log(chalk_1.default.yellow(message), ...args);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
console.log(chalk_1.default.yellow(message));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
104
|
+
setLogLevel(level) {
|
|
105
|
+
this.logLevel = level;
|
|
117
106
|
}
|
|
118
107
|
/**
|
|
119
|
-
* Log
|
|
108
|
+
* Log a success message (shown at INFO level and above)
|
|
120
109
|
*/
|
|
121
|
-
|
|
122
|
-
if (this.logLevel >= LogLevel.
|
|
123
|
-
if (
|
|
124
|
-
console.
|
|
110
|
+
success(message, ...arguments_) {
|
|
111
|
+
if (this.logLevel >= LogLevel.INFO) {
|
|
112
|
+
if (arguments_.length > 0) {
|
|
113
|
+
console.log(chalk_1.default.green(message), ...arguments_);
|
|
125
114
|
}
|
|
126
115
|
else {
|
|
127
|
-
console.
|
|
116
|
+
console.log(chalk_1.default.green(message));
|
|
128
117
|
}
|
|
129
118
|
}
|
|
130
119
|
}
|
|
131
120
|
/**
|
|
132
|
-
* Log a
|
|
121
|
+
* Log a warning message (shown at WARN level and above)
|
|
133
122
|
*/
|
|
134
|
-
|
|
135
|
-
if (this.logLevel >= LogLevel.
|
|
136
|
-
if (
|
|
137
|
-
console.log(chalk_1.default.
|
|
123
|
+
warn(message, ...arguments_) {
|
|
124
|
+
if (this.logLevel >= LogLevel.WARN) {
|
|
125
|
+
if (arguments_.length > 0) {
|
|
126
|
+
console.log(chalk_1.default.yellow(message), ...arguments_);
|
|
138
127
|
}
|
|
139
128
|
else {
|
|
140
|
-
console.log(chalk_1.default.
|
|
129
|
+
console.log(chalk_1.default.yellow(message));
|
|
141
130
|
}
|
|
142
131
|
}
|
|
143
132
|
}
|
|
144
133
|
/**
|
|
145
|
-
*
|
|
134
|
+
* Set the log level from a string
|
|
146
135
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
136
|
+
setLogLevelFromString(level) {
|
|
137
|
+
switch (level.toLowerCase()) {
|
|
138
|
+
case 'debug': {
|
|
139
|
+
this.logLevel = LogLevel.DEBUG;
|
|
140
|
+
break;
|
|
151
141
|
}
|
|
152
|
-
|
|
153
|
-
|
|
142
|
+
case 'error': {
|
|
143
|
+
this.logLevel = LogLevel.ERROR;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case 'info': {
|
|
147
|
+
this.logLevel = LogLevel.INFO;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 'none': {
|
|
151
|
+
this.logLevel = LogLevel.NONE;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case 'warn': {
|
|
155
|
+
this.logLevel = LogLevel.WARN;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
default: {
|
|
159
|
+
// Invalid log level, keep default
|
|
160
|
+
console.warn(`Invalid log level: ${level}. Using default (INFO).`);
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
}
|
|
@@ -3,48 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.renderMarkdown = exports.containsMarkdown = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
8
|
const marked_1 = require("marked");
|
|
8
9
|
const marked_terminal_1 = __importDefault(require("marked-terminal"));
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
// Configure marked to use the terminal renderer
|
|
11
11
|
marked_1.marked.setOptions({
|
|
12
12
|
renderer: new marked_terminal_1.default({
|
|
13
|
+
blockquote: chalk_1.default.gray.italic,
|
|
13
14
|
// Customize the rendering options
|
|
14
15
|
code: chalk_1.default.cyan,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
listitem: chalk_1.default.yellow,
|
|
18
|
-
strong: chalk_1.default.bold,
|
|
16
|
+
// Customize code block rendering
|
|
17
|
+
codespan: chalk_1.default.cyan,
|
|
19
18
|
em: chalk_1.default.italic,
|
|
20
19
|
heading: chalk_1.default.bold.blueBright,
|
|
21
20
|
hr: chalk_1.default.gray,
|
|
22
21
|
link: chalk_1.default.blue.underline,
|
|
22
|
+
listitem: chalk_1.default.yellow,
|
|
23
|
+
strong: chalk_1.default.bold,
|
|
24
|
+
table: chalk_1.default.white,
|
|
23
25
|
// Adjust the width to fit the terminal
|
|
24
26
|
width: process.stdout.columns || 80,
|
|
25
|
-
// Customize code block rendering
|
|
26
|
-
codespan: chalk_1.default.cyan,
|
|
27
27
|
}),
|
|
28
28
|
});
|
|
29
|
-
/**
|
|
30
|
-
* Render markdown text to terminal-friendly formatted text
|
|
31
|
-
* @param markdown The markdown text to render
|
|
32
|
-
* @returns Formatted text for terminal display
|
|
33
|
-
*/
|
|
34
|
-
function renderMarkdown(markdown) {
|
|
35
|
-
if (!markdown)
|
|
36
|
-
return "";
|
|
37
|
-
try {
|
|
38
|
-
// Convert markdown to terminal-friendly text
|
|
39
|
-
return (0, marked_1.marked)(markdown);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
// If rendering fails, return the original text
|
|
43
|
-
console.error(`Error rendering markdown: ${error}`);
|
|
44
|
-
return markdown;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.renderMarkdown = renderMarkdown;
|
|
48
29
|
/**
|
|
49
30
|
* Check if a string contains markdown formatting
|
|
50
31
|
* @param text The text to check
|
|
@@ -68,6 +49,25 @@ function containsMarkdown(text) {
|
|
|
68
49
|
/^---+$/m, // Horizontal rules
|
|
69
50
|
/^===+$/m, // Alternative headers
|
|
70
51
|
];
|
|
71
|
-
return markdownPatterns.some(pattern => pattern.test(text));
|
|
52
|
+
return markdownPatterns.some((pattern) => pattern.test(text));
|
|
72
53
|
}
|
|
73
54
|
exports.containsMarkdown = containsMarkdown;
|
|
55
|
+
/**
|
|
56
|
+
* Render markdown text to terminal-friendly formatted text
|
|
57
|
+
* @param markdown The markdown text to render
|
|
58
|
+
* @returns Formatted text for terminal display
|
|
59
|
+
*/
|
|
60
|
+
function renderMarkdown(markdown) {
|
|
61
|
+
if (!markdown)
|
|
62
|
+
return '';
|
|
63
|
+
try {
|
|
64
|
+
// Convert markdown to terminal-friendly text
|
|
65
|
+
return (0, marked_1.marked)(markdown);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// If rendering fails, return the original text
|
|
69
|
+
console.error(`Error rendering markdown: ${error}`);
|
|
70
|
+
return markdown;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.renderMarkdown = renderMarkdown;
|