2025-06-29 17:09:37 -04:00
|
|
|
const path = require('path');
|
2025-07-07 01:10:08 -04:00
|
|
|
const { logger } = require('@librechat/data-schemas');
|
2025-08-26 12:10:18 -04:00
|
|
|
const { loadServiceKey, isUserProvided } = require('@librechat/api');
|
2024-02-28 14:27:19 -05:00
|
|
|
const { config } = require('./EndpointService');
|
|
|
|
|
|
2025-11-25 15:20:07 -05:00
|
|
|
async function loadAsyncEndpoints() {
|
2023-12-15 02:18:07 -05:00
|
|
|
let serviceKey, googleUserProvides;
|
2025-11-25 15:20:07 -05:00
|
|
|
const { googleKey } = config;
|
2023-12-06 19:36:57 -05:00
|
|
|
|
2025-07-07 01:10:08 -04:00
|
|
|
/** Check if GOOGLE_KEY is provided at all(including 'user_provided') */
|
|
|
|
|
const isGoogleKeyProvided = googleKey && googleKey.trim() !== '';
|
|
|
|
|
|
|
|
|
|
if (isGoogleKeyProvided) {
|
|
|
|
|
/** If GOOGLE_KEY is provided, check if it's user_provided */
|
|
|
|
|
googleUserProvides = isUserProvided(googleKey);
|
|
|
|
|
} else {
|
|
|
|
|
/** Only attempt to load service key if GOOGLE_KEY is not provided */
|
|
|
|
|
const serviceKeyPath =
|
2025-07-08 21:07:33 -04:00
|
|
|
process.env.GOOGLE_SERVICE_KEY_FILE || path.join(__dirname, '../../..', 'data', 'auth.json');
|
2025-07-07 01:10:08 -04:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
serviceKey = await loadServiceKey(serviceKeyPath);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error('Error loading service key', error);
|
|
|
|
|
serviceKey = null;
|
2023-12-06 19:36:57 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 01:10:08 -04:00
|
|
|
const google = serviceKey || isGoogleKeyProvided ? { userProvide: googleUserProvides } : false;
|
2023-12-06 19:36:57 -05:00
|
|
|
|
2025-11-25 15:20:07 -05:00
|
|
|
return { google };
|
2023-12-06 19:36:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = loadAsyncEndpoints;
|