berget 2.0.1 → 2.0.3
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
CHANGED
|
@@ -677,7 +677,10 @@ function registerCodeCommands(program) {
|
|
|
677
677
|
berget: {
|
|
678
678
|
npm: '@ai-sdk/openai-compatible',
|
|
679
679
|
name: 'Berget AI',
|
|
680
|
-
options: {
|
|
680
|
+
options: {
|
|
681
|
+
baseURL: 'https://api.berget.ai/v1',
|
|
682
|
+
apiKey: '{env:BERGET_API_KEY}',
|
|
683
|
+
},
|
|
681
684
|
models: MODEL_CONFIG.PROVIDER_MODELS,
|
|
682
685
|
},
|
|
683
686
|
},
|
|
@@ -86,6 +86,20 @@ class ChatService {
|
|
|
86
86
|
logger_1.logger.error('Failed to stringify options:', error);
|
|
87
87
|
}
|
|
88
88
|
const headers = {};
|
|
89
|
+
// First try to use the authenticated client (with refresh token support)
|
|
90
|
+
// Only fall back to API key flow if explicitly requested or no auth tokens available
|
|
91
|
+
const { TokenManager } = yield Promise.resolve().then(() => __importStar(require('../utils/token-manager')));
|
|
92
|
+
const tokenManagerInstance = TokenManager.getInstance();
|
|
93
|
+
const hasValidAuth = tokenManagerInstance.getAccessToken() && !tokenManagerInstance.isTokenExpired();
|
|
94
|
+
const envApiKeyForAuth = process.env.BERGET_API_KEY;
|
|
95
|
+
const hasExplicitApiKey = !!optionsCopy.apiKey || !!envApiKeyForAuth;
|
|
96
|
+
// If we have valid auth tokens and no explicit API key, use authenticated client
|
|
97
|
+
if (hasValidAuth && !hasExplicitApiKey) {
|
|
98
|
+
logger_1.logger.debug('Using authenticated client with refresh token support');
|
|
99
|
+
// Create a copy without apiKey to let the authenticated client handle auth automatically
|
|
100
|
+
const { apiKey } = optionsCopy, optionsWithoutKey = __rest(optionsCopy, ["apiKey"]);
|
|
101
|
+
return this.executeCompletion(optionsWithoutKey, {});
|
|
102
|
+
}
|
|
89
103
|
// Check for environment variables first - prioritize this over everything else
|
|
90
104
|
const envApiKey = process.env.BERGET_API_KEY;
|
|
91
105
|
if (envApiKey) {
|
package/package.json
CHANGED
package/src/commands/code.ts
CHANGED
|
@@ -777,7 +777,10 @@ export function registerCodeCommands(program: Command): void {
|
|
|
777
777
|
berget: {
|
|
778
778
|
npm: '@ai-sdk/openai-compatible',
|
|
779
779
|
name: 'Berget AI',
|
|
780
|
-
options: {
|
|
780
|
+
options: {
|
|
781
|
+
baseURL: 'https://api.berget.ai/v1',
|
|
782
|
+
apiKey: '{env:BERGET_API_KEY}',
|
|
783
|
+
},
|
|
781
784
|
models: MODEL_CONFIG.PROVIDER_MODELS,
|
|
782
785
|
},
|
|
783
786
|
},
|
|
@@ -82,6 +82,23 @@ export class ChatService {
|
|
|
82
82
|
|
|
83
83
|
const headers: Record<string, string> = {}
|
|
84
84
|
|
|
85
|
+
// First try to use the authenticated client (with refresh token support)
|
|
86
|
+
// Only fall back to API key flow if explicitly requested or no auth tokens available
|
|
87
|
+
const { TokenManager } = await import('../utils/token-manager')
|
|
88
|
+
const tokenManagerInstance = TokenManager.getInstance()
|
|
89
|
+
const hasValidAuth = tokenManagerInstance.getAccessToken() && !tokenManagerInstance.isTokenExpired()
|
|
90
|
+
|
|
91
|
+
const envApiKeyForAuth = process.env.BERGET_API_KEY
|
|
92
|
+
const hasExplicitApiKey = !!optionsCopy.apiKey || !!envApiKeyForAuth
|
|
93
|
+
|
|
94
|
+
// If we have valid auth tokens and no explicit API key, use authenticated client
|
|
95
|
+
if (hasValidAuth && !hasExplicitApiKey) {
|
|
96
|
+
logger.debug('Using authenticated client with refresh token support')
|
|
97
|
+
// Create a copy without apiKey to let the authenticated client handle auth automatically
|
|
98
|
+
const { apiKey, ...optionsWithoutKey } = optionsCopy
|
|
99
|
+
return this.executeCompletion(optionsWithoutKey, {})
|
|
100
|
+
}
|
|
101
|
+
|
|
85
102
|
// Check for environment variables first - prioritize this over everything else
|
|
86
103
|
const envApiKey = process.env.BERGET_API_KEY
|
|
87
104
|
if (envApiKey) {
|