mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-29 14:48:51 +01:00
* refactor: use new image output format for agents using DALL-E tools * refactor: Enhance image fetching with proxy support and adjust logging placement in DALL-E 3 integration * refactor: Enhance StableDiffusionAPI to support agent-specific return values and display message for generated images * refactor: Add unit test execution for librechat-mcp in backend review workflow * refactor: Update environment variable extraction logic, export from serpate module to avoid circular refs, and remove deprecated tests * refactor: Add unit tests for environment variable extraction and enhance StdioOptionsSchema to process env variables
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
export const envVarRegex = /^\${(.+)}$/;
|
|
|
|
/** Extracts the value of an environment variable from a string. */
|
|
export function extractEnvVariable(value: string) {
|
|
if (!value) {
|
|
return value;
|
|
}
|
|
|
|
// Trim the input
|
|
const trimmed = value.trim();
|
|
|
|
// Special case: if it's just a single environment variable
|
|
const singleMatch = trimmed.match(envVarRegex);
|
|
if (singleMatch) {
|
|
const varName = singleMatch[1];
|
|
return process.env[varName] || trimmed;
|
|
}
|
|
|
|
// For multiple variables, process them using a regex loop
|
|
const regex = /\${([^}]+)}/g;
|
|
let result = trimmed;
|
|
|
|
// First collect all matches and their positions
|
|
const matches = [];
|
|
let match;
|
|
while ((match = regex.exec(trimmed)) !== null) {
|
|
matches.push({
|
|
fullMatch: match[0],
|
|
varName: match[1],
|
|
index: match.index,
|
|
});
|
|
}
|
|
|
|
// Process matches in reverse order to avoid position shifts
|
|
for (let i = matches.length - 1; i >= 0; i--) {
|
|
const { fullMatch, varName, index } = matches[i];
|
|
const envValue = process.env[varName] || fullMatch;
|
|
|
|
// Replace at exact position
|
|
result = result.substring(0, index) + envValue + result.substring(index + fullMatch.length);
|
|
}
|
|
|
|
return result;
|
|
}
|