| | export const envVarRegex = /^\${(.+)}$/; |
| |
|
| | |
| | export function extractVariableName(value: string): string | null { |
| | if (!value) { |
| | return null; |
| | } |
| |
|
| | const match = value.trim().match(envVarRegex); |
| | return match ? match[1] : null; |
| | } |
| |
|
| | |
| | export function extractEnvVariable(value: string) { |
| | if (!value) { |
| | return value; |
| | } |
| |
|
| | |
| | const trimmed = value.trim(); |
| |
|
| | |
| | const singleMatch = trimmed.match(envVarRegex); |
| | if (singleMatch) { |
| | const varName = singleMatch[1]; |
| | return process.env[varName] || trimmed; |
| | } |
| |
|
| | |
| | const regex = /\${([^}]+)}/g; |
| | let result = trimmed; |
| |
|
| | |
| | const matches = []; |
| | let match; |
| | while ((match = regex.exec(trimmed)) !== null) { |
| | matches.push({ |
| | fullMatch: match[0], |
| | varName: match[1], |
| | index: match.index, |
| | }); |
| | } |
| |
|
| | |
| | for (let i = matches.length - 1; i >= 0; i--) { |
| | const { fullMatch, varName, index } = matches[i]; |
| | const envValue = process.env[varName] || fullMatch; |
| |
|
| | |
| | result = result.substring(0, index) + envValue + result.substring(index + fullMatch.length); |
| | } |
| |
|
| | return result; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | export function normalizeEndpointName(name = ''): string { |
| | return name.toLowerCase() === 'ollama' ? 'ollama' : name; |
| | } |
| |
|