berget 2.1.0 ā 2.1.1
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/dist/package.json +1 -1
- package/dist/src/commands/code.js +34 -66
- package/dist/src/services/auth-service.js +1 -2
- package/package.json +1 -1
- package/src/commands/code.ts +45 -113
- package/src/services/auth-service.ts +1 -4
package/dist/package.json
CHANGED
|
@@ -357,9 +357,8 @@ function loadLatestAgentConfig() {
|
|
|
357
357
|
*/
|
|
358
358
|
function checkOpencodeInstalled() {
|
|
359
359
|
return new Promise((resolve) => {
|
|
360
|
-
const child = (0, child_process_1.spawn)('
|
|
360
|
+
const child = (0, child_process_1.spawn)('which', ['opencode'], {
|
|
361
361
|
stdio: 'pipe',
|
|
362
|
-
shell: true,
|
|
363
362
|
});
|
|
364
363
|
child.on('close', (code) => {
|
|
365
364
|
resolve(code === 0);
|
|
@@ -475,12 +474,9 @@ function registerCodeCommands(program) {
|
|
|
475
474
|
}
|
|
476
475
|
else {
|
|
477
476
|
// Only require authentication if we don't have an API key
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
yield authService.whoami();
|
|
482
|
-
}
|
|
483
|
-
catch (error) {
|
|
477
|
+
const authService = auth_service_1.AuthService.getInstance();
|
|
478
|
+
const profile = yield authService.whoami();
|
|
479
|
+
if (!profile) {
|
|
484
480
|
console.log(chalk_1.default.red('ā Not authenticated with Berget AI.'));
|
|
485
481
|
console.log(chalk_1.default.blue('To get started, you have two options:'));
|
|
486
482
|
console.log('');
|
|
@@ -504,62 +500,35 @@ function registerCodeCommands(program) {
|
|
|
504
500
|
let keyName;
|
|
505
501
|
try {
|
|
506
502
|
const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
|
|
507
|
-
// Check for environment variable first (regardless of automation mode)
|
|
508
503
|
if (process.env.BERGET_API_KEY) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
else {
|
|
514
|
-
// List existing API keys
|
|
515
|
-
if (!options.yes) {
|
|
516
|
-
console.log(chalk_1.default.blue('\nš Checking existing API keys...'));
|
|
504
|
+
if (options.yes) {
|
|
505
|
+
console.log(chalk_1.default.blue('š Using BERGET_API_KEY from environment'));
|
|
506
|
+
apiKey = process.env.BERGET_API_KEY;
|
|
507
|
+
keyName = `env-key-${projectName}`;
|
|
517
508
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
console.log(chalk_1.default.blue('Found existing API keys:'));
|
|
509
|
+
else {
|
|
510
|
+
console.log(chalk_1.default.blue('\nš API key setup:'));
|
|
521
511
|
console.log(chalk_1.default.dim('ā'.repeat(60)));
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
console.log(chalk_1.default.dim(` Last used: ${key.lastUsed
|
|
526
|
-
? new Date(key.lastUsed).toLocaleDateString('sv-SE')
|
|
527
|
-
: 'Never'}`));
|
|
528
|
-
if (index < existingKeys.length - 1)
|
|
529
|
-
console.log();
|
|
530
|
-
});
|
|
512
|
+
console.log(`${chalk_1.default.cyan('1')} ${chalk_1.default.bold('Use existing API key')}`);
|
|
513
|
+
console.log(chalk_1.default.dim(' Uses BERGET_API_KEY from environment'));
|
|
514
|
+
console.log(`${chalk_1.default.cyan('2')} ${chalk_1.default.bold('Create a new API key')}`);
|
|
531
515
|
console.log(chalk_1.default.dim('ā'.repeat(60)));
|
|
532
|
-
console.log(chalk_1.default.cyan(`${existingKeys.length + 1}. Create a new API key`));
|
|
533
|
-
// Get user choice
|
|
534
516
|
const choice = yield new Promise((resolve) => {
|
|
535
517
|
const rl = readline_1.default.createInterface({
|
|
536
518
|
input: process.stdin,
|
|
537
519
|
output: process.stdout,
|
|
538
520
|
});
|
|
539
|
-
rl.question(chalk_1.default.blue('\nSelect an option (1-
|
|
521
|
+
rl.question(chalk_1.default.blue('\nSelect an option (1-2, default: 1): '), (answer) => {
|
|
540
522
|
rl.close();
|
|
541
|
-
resolve(answer.trim());
|
|
523
|
+
resolve(answer.trim() || '1');
|
|
542
524
|
});
|
|
543
525
|
});
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
keyName = selectedKey.name;
|
|
549
|
-
// We need to rotate the key to get the actual key value
|
|
550
|
-
console.log(chalk_1.default.yellow(`\nš Rotating API key "${selectedKey.name}" to get the key value...`));
|
|
551
|
-
if (yield confirm(chalk_1.default.yellow('This will invalidate the current key. Continue? (Y/n): '), options.yes)) {
|
|
552
|
-
const rotatedKey = yield apiKeyService.rotate(selectedKey.id.toString());
|
|
553
|
-
apiKey = rotatedKey.key;
|
|
554
|
-
console.log(chalk_1.default.green(`ā API key rotated successfully`));
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
console.log(chalk_1.default.yellow('Cancelled. Please select a different option or create a new key.'));
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
526
|
+
if (choice === '1') {
|
|
527
|
+
console.log(chalk_1.default.blue('š Using BERGET_API_KEY from environment'));
|
|
528
|
+
apiKey = process.env.BERGET_API_KEY;
|
|
529
|
+
keyName = `env-key-${projectName}`;
|
|
560
530
|
}
|
|
561
|
-
else if (
|
|
562
|
-
// Create new key
|
|
531
|
+
else if (choice === '2') {
|
|
563
532
|
console.log(chalk_1.default.blue('\nš Creating new API key...'));
|
|
564
533
|
const defaultKeyName = `opencode-${projectName}-${Date.now()}`;
|
|
565
534
|
const customName = yield getInput(chalk_1.default.blue(`Enter key name (default: ${defaultKeyName}): `), defaultKeyName, options.yes);
|
|
@@ -574,20 +543,21 @@ function registerCodeCommands(program) {
|
|
|
574
543
|
return;
|
|
575
544
|
}
|
|
576
545
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
const customName = yield getInput(chalk_1.default.blue(`Enter key name (default: ${defaultKeyName}): `), defaultKeyName, options.yes);
|
|
585
|
-
keyName = customName;
|
|
586
|
-
const createOptions = { name: keyName };
|
|
587
|
-
const keyData = yield apiKeyService.create(createOptions);
|
|
588
|
-
apiKey = keyData.key;
|
|
589
|
-
console.log(chalk_1.default.green(`ā Created new API key: ${keyName}`));
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
if (!options.yes) {
|
|
549
|
+
console.log(chalk_1.default.yellow('No BERGET_API_KEY environment variable found.'));
|
|
550
|
+
console.log(chalk_1.default.blue('Creating a new API key...'));
|
|
551
|
+
console.log(chalk_1.default.dim('\nš” Tip: Set BERGET_API_KEY environment variable to reuse an existing key:'));
|
|
552
|
+
console.log(chalk_1.default.dim(' export BERGET_API_KEY=your_api_key_here'));
|
|
590
553
|
}
|
|
554
|
+
const defaultKeyName = `opencode-${projectName}-${Date.now()}`;
|
|
555
|
+
const customName = yield getInput(chalk_1.default.blue(`Enter key name (default: ${defaultKeyName}): `), defaultKeyName, options.yes);
|
|
556
|
+
keyName = customName;
|
|
557
|
+
const createOptions = { name: keyName };
|
|
558
|
+
const keyData = yield apiKeyService.create(createOptions);
|
|
559
|
+
apiKey = keyData.key;
|
|
560
|
+
console.log(chalk_1.default.green(`ā Created new API key: ${keyName}`));
|
|
591
561
|
}
|
|
592
562
|
}
|
|
593
563
|
catch (error) {
|
|
@@ -1050,7 +1020,6 @@ All agents follow these principles:
|
|
|
1050
1020
|
const opencode = (0, child_process_1.spawn)('opencode', opencodeArgs, {
|
|
1051
1021
|
stdio: 'inherit',
|
|
1052
1022
|
env: env,
|
|
1053
|
-
shell: true,
|
|
1054
1023
|
});
|
|
1055
1024
|
opencode.on('close', (code) => {
|
|
1056
1025
|
if (code !== 0) {
|
|
@@ -1090,7 +1059,6 @@ All agents follow these principles:
|
|
|
1090
1059
|
// Spawn opencode serve process
|
|
1091
1060
|
const opencode = (0, child_process_1.spawn)('opencode', serveArgs, {
|
|
1092
1061
|
stdio: 'inherit',
|
|
1093
|
-
shell: true,
|
|
1094
1062
|
});
|
|
1095
1063
|
opencode.on('close', (code) => {
|
|
1096
1064
|
if (code !== 0) {
|
|
@@ -60,12 +60,11 @@ class AuthService {
|
|
|
60
60
|
try {
|
|
61
61
|
const { data: profile, error } = yield this.client.GET('/v1/users/me');
|
|
62
62
|
if (error) {
|
|
63
|
-
|
|
63
|
+
return null;
|
|
64
64
|
}
|
|
65
65
|
return profile;
|
|
66
66
|
}
|
|
67
67
|
catch (error) {
|
|
68
|
-
(0, error_handler_1.handleError)('Failed to get user profile', error);
|
|
69
68
|
return null;
|
|
70
69
|
}
|
|
71
70
|
});
|
package/package.json
CHANGED
package/src/commands/code.ts
CHANGED
|
@@ -376,9 +376,8 @@ async function loadLatestAgentConfig(): Promise<any> {
|
|
|
376
376
|
*/
|
|
377
377
|
function checkOpencodeInstalled(): Promise<boolean> {
|
|
378
378
|
return new Promise((resolve) => {
|
|
379
|
-
const child = spawn('
|
|
379
|
+
const child = spawn('which', ['opencode'], {
|
|
380
380
|
stdio: 'pipe',
|
|
381
|
-
shell: true,
|
|
382
381
|
})
|
|
383
382
|
|
|
384
383
|
child.on('close', (code) => {
|
|
@@ -530,11 +529,10 @@ export function registerCodeCommands(program: Command): void {
|
|
|
530
529
|
)
|
|
531
530
|
} else {
|
|
532
531
|
// Only require authentication if we don't have an API key
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
} catch (error) {
|
|
532
|
+
const authService = AuthService.getInstance()
|
|
533
|
+
const profile = await authService.whoami()
|
|
534
|
+
|
|
535
|
+
if (!profile) {
|
|
538
536
|
console.log(chalk.red('ā Not authenticated with Berget AI.'))
|
|
539
537
|
console.log(chalk.blue('To get started, you have two options:'))
|
|
540
538
|
console.log('')
|
|
@@ -578,104 +576,39 @@ export function registerCodeCommands(program: Command): void {
|
|
|
578
576
|
try {
|
|
579
577
|
const apiKeyService = ApiKeyService.getInstance()
|
|
580
578
|
|
|
581
|
-
// Check for environment variable first (regardless of automation mode)
|
|
582
579
|
if (process.env.BERGET_API_KEY) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
console.log(chalk.blue('\nš Checking existing API keys...'))
|
|
590
|
-
}
|
|
591
|
-
const existingKeys = await apiKeyService.list()
|
|
592
|
-
|
|
593
|
-
if (existingKeys.length > 0 && !options.yes) {
|
|
594
|
-
console.log(chalk.blue('Found existing API keys:'))
|
|
595
|
-
console.log(chalk.dim('ā'.repeat(60)))
|
|
596
|
-
existingKeys.forEach((key, index) => {
|
|
597
|
-
console.log(
|
|
598
|
-
`${chalk.cyan((index + 1).toString())}. ${chalk.bold(
|
|
599
|
-
key.name
|
|
600
|
-
)} (${key.prefix}...)`
|
|
601
|
-
)
|
|
602
|
-
console.log(
|
|
603
|
-
chalk.dim(
|
|
604
|
-
` Created: ${new Date(key.created).toLocaleDateString(
|
|
605
|
-
'sv-SE'
|
|
606
|
-
)}`
|
|
607
|
-
)
|
|
608
|
-
)
|
|
609
|
-
console.log(
|
|
610
|
-
chalk.dim(
|
|
611
|
-
` Last used: ${
|
|
612
|
-
key.lastUsed
|
|
613
|
-
? new Date(key.lastUsed).toLocaleDateString('sv-SE')
|
|
614
|
-
: 'Never'
|
|
615
|
-
}`
|
|
616
|
-
)
|
|
617
|
-
)
|
|
618
|
-
if (index < existingKeys.length - 1) console.log()
|
|
619
|
-
})
|
|
580
|
+
if (options.yes) {
|
|
581
|
+
console.log(chalk.blue('š Using BERGET_API_KEY from environment'))
|
|
582
|
+
apiKey = process.env.BERGET_API_KEY
|
|
583
|
+
keyName = `env-key-${projectName}`
|
|
584
|
+
} else {
|
|
585
|
+
console.log(chalk.blue('\nš API key setup:'))
|
|
620
586
|
console.log(chalk.dim('ā'.repeat(60)))
|
|
621
587
|
console.log(
|
|
622
|
-
chalk.cyan(
|
|
588
|
+
`${chalk.cyan('1')} ${chalk.bold('Use existing API key')}`
|
|
589
|
+
)
|
|
590
|
+
console.log(chalk.dim(' Uses BERGET_API_KEY from environment'))
|
|
591
|
+
console.log(
|
|
592
|
+
`${chalk.cyan('2')} ${chalk.bold('Create a new API key')}`
|
|
623
593
|
)
|
|
594
|
+
console.log(chalk.dim('ā'.repeat(60)))
|
|
624
595
|
|
|
625
|
-
// Get user choice
|
|
626
596
|
const choice = await new Promise<string>((resolve) => {
|
|
627
597
|
const rl = readline.createInterface({
|
|
628
598
|
input: process.stdin,
|
|
629
599
|
output: process.stdout,
|
|
630
600
|
})
|
|
631
|
-
rl.question(
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
(answer) => {
|
|
636
|
-
rl.close()
|
|
637
|
-
resolve(answer.trim())
|
|
638
|
-
}
|
|
639
|
-
)
|
|
601
|
+
rl.question(chalk.blue('\nSelect an option (1-2, default: 1): '), (answer) => {
|
|
602
|
+
rl.close()
|
|
603
|
+
resolve(answer.trim() || '1')
|
|
604
|
+
})
|
|
640
605
|
})
|
|
641
606
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
keyName = selectedKey.name
|
|
648
|
-
|
|
649
|
-
// We need to rotate the key to get the actual key value
|
|
650
|
-
console.log(
|
|
651
|
-
chalk.yellow(
|
|
652
|
-
`\nš Rotating API key "${selectedKey.name}" to get the key value...`
|
|
653
|
-
)
|
|
654
|
-
)
|
|
655
|
-
|
|
656
|
-
if (
|
|
657
|
-
await confirm(
|
|
658
|
-
chalk.yellow(
|
|
659
|
-
'This will invalidate the current key. Continue? (Y/n): '
|
|
660
|
-
),
|
|
661
|
-
options.yes
|
|
662
|
-
)
|
|
663
|
-
) {
|
|
664
|
-
const rotatedKey = await apiKeyService.rotate(
|
|
665
|
-
selectedKey.id.toString()
|
|
666
|
-
)
|
|
667
|
-
apiKey = rotatedKey.key
|
|
668
|
-
console.log(chalk.green(`ā API key rotated successfully`))
|
|
669
|
-
} else {
|
|
670
|
-
console.log(
|
|
671
|
-
chalk.yellow(
|
|
672
|
-
'Cancelled. Please select a different option or create a new key.'
|
|
673
|
-
)
|
|
674
|
-
)
|
|
675
|
-
return
|
|
676
|
-
}
|
|
677
|
-
} else if (choiceIndex === existingKeys.length) {
|
|
678
|
-
// Create new key
|
|
607
|
+
if (choice === '1') {
|
|
608
|
+
console.log(chalk.blue('š Using BERGET_API_KEY from environment'))
|
|
609
|
+
apiKey = process.env.BERGET_API_KEY
|
|
610
|
+
keyName = `env-key-${projectName}`
|
|
611
|
+
} else if (choice === '2') {
|
|
679
612
|
console.log(chalk.blue('\nš Creating new API key...'))
|
|
680
613
|
|
|
681
614
|
const defaultKeyName = `opencode-${projectName}-${Date.now()}`
|
|
@@ -694,26 +627,27 @@ export function registerCodeCommands(program: Command): void {
|
|
|
694
627
|
console.log(chalk.red('Invalid selection.'))
|
|
695
628
|
return
|
|
696
629
|
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
630
|
+
}
|
|
631
|
+
} else {
|
|
632
|
+
if (!options.yes) {
|
|
633
|
+
console.log(chalk.yellow('No BERGET_API_KEY environment variable found.'))
|
|
634
|
+
console.log(chalk.blue('Creating a new API key...'))
|
|
635
|
+
console.log(chalk.dim('\nš” Tip: Set BERGET_API_KEY environment variable to reuse an existing key:'))
|
|
636
|
+
console.log(chalk.dim(' export BERGET_API_KEY=your_api_key_here'))
|
|
637
|
+
}
|
|
703
638
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
639
|
+
const defaultKeyName = `opencode-${projectName}-${Date.now()}`
|
|
640
|
+
const customName = await getInput(
|
|
641
|
+
chalk.blue(`Enter key name (default: ${defaultKeyName}): `),
|
|
642
|
+
defaultKeyName,
|
|
643
|
+
options.yes
|
|
644
|
+
)
|
|
710
645
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
}
|
|
646
|
+
keyName = customName
|
|
647
|
+
const createOptions: CreateApiKeyOptions = { name: keyName }
|
|
648
|
+
const keyData = await apiKeyService.create(createOptions)
|
|
649
|
+
apiKey = keyData.key
|
|
650
|
+
console.log(chalk.green(`ā Created new API key: ${keyName}`))
|
|
717
651
|
}
|
|
718
652
|
} catch (error) {
|
|
719
653
|
if (process.env.BERGET_API_KEY) {
|
|
@@ -1269,7 +1203,6 @@ All agents follow these principles:
|
|
|
1269
1203
|
const opencode = spawn('opencode', opencodeArgs, {
|
|
1270
1204
|
stdio: 'inherit',
|
|
1271
1205
|
env: env,
|
|
1272
|
-
shell: true,
|
|
1273
1206
|
})
|
|
1274
1207
|
|
|
1275
1208
|
opencode.on('close', (code) => {
|
|
@@ -1322,7 +1255,6 @@ All agents follow these principles:
|
|
|
1322
1255
|
// Spawn opencode serve process
|
|
1323
1256
|
const opencode = spawn('opencode', serveArgs, {
|
|
1324
1257
|
stdio: 'inherit',
|
|
1325
|
-
shell: true,
|
|
1326
1258
|
})
|
|
1327
1259
|
|
|
1328
1260
|
opencode.on('close', (code) => {
|
|
@@ -36,13 +36,10 @@ export class AuthService {
|
|
|
36
36
|
try {
|
|
37
37
|
const { data: profile, error } = await this.client.GET('/v1/users/me')
|
|
38
38
|
if (error) {
|
|
39
|
-
|
|
40
|
-
error ? JSON.stringify(error) : 'Failed to get user profile',
|
|
41
|
-
)
|
|
39
|
+
return null
|
|
42
40
|
}
|
|
43
41
|
return profile
|
|
44
42
|
} catch (error) {
|
|
45
|
-
handleError('Failed to get user profile', error)
|
|
46
43
|
return null
|
|
47
44
|
}
|
|
48
45
|
}
|