berget 2.0.2 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "berget",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "berget": "dist/index.js"
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "berget",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "berget": "dist/index.js"
@@ -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) {