Added multi-env support

This commit is contained in:
2026-01-17 17:09:47 -05:00
parent 2638e08453
commit e3c7cbba95
5 changed files with 475 additions and 126 deletions

View File

@@ -433,6 +433,8 @@ async function handleAnalyze() {
activeApiKeyId = "",
apiConfigs = [],
activeApiConfigId = "",
envConfigs = [],
activeEnvConfigId = "",
apiBaseUrl,
apiKeyHeader,
apiKeyPrefix,
@@ -444,6 +446,8 @@ async function handleAnalyze() {
"activeApiKeyId",
"apiConfigs",
"activeApiConfigId",
"envConfigs",
"activeEnvConfigId",
"apiBaseUrl",
"apiKeyHeader",
"apiKeyPrefix",
@@ -453,22 +457,28 @@ async function handleAnalyze() {
]);
const resolvedConfigs = Array.isArray(apiConfigs) ? apiConfigs : [];
const resolvedEnvs = Array.isArray(envConfigs) ? envConfigs : [];
const activeEnv =
resolvedEnvs.find((entry) => entry.id === activeEnvConfigId) ||
resolvedEnvs[0];
const resolvedSystemPrompt =
activeEnv?.systemPrompt ?? systemPrompt ?? "";
const resolvedApiConfigId =
activeEnv?.apiConfigId || activeApiConfigId || resolvedConfigs[0]?.id || "";
const activeConfig =
resolvedConfigs.find((entry) => entry.id === activeApiConfigId) ||
resolvedConfigs.find((entry) => entry.id === resolvedApiConfigId) ||
resolvedConfigs[0];
if (!activeConfig) {
setStatus("Add an API configuration in Settings.");
return;
}
const isAdvanced = Boolean(activeConfig?.advanced);
const resolvedApiUrl = activeConfig?.apiUrl || "";
const resolvedTemplate = activeConfig?.requestTemplate || "";
const resolvedApiBaseUrl = isAdvanced
? ""
: activeConfig?.apiBaseUrl || apiBaseUrl || "";
const resolvedApiKeyHeader = isAdvanced
? ""
: activeConfig?.apiKeyHeader ?? apiKeyHeader ?? "";
const resolvedApiKeyPrefix = isAdvanced
? ""
: activeConfig?.apiKeyPrefix ?? apiKeyPrefix ?? "";
const resolvedModel = isAdvanced ? "" : activeConfig?.model || model || "";
const resolvedApiBaseUrl = activeConfig?.apiBaseUrl || apiBaseUrl || "";
const resolvedApiKeyHeader = activeConfig?.apiKeyHeader ?? apiKeyHeader ?? "";
const resolvedApiKeyPrefix = activeConfig?.apiKeyPrefix ?? apiKeyPrefix ?? "";
const resolvedModel = activeConfig?.model || model || "";
const resolvedKeys = Array.isArray(apiKeys) ? apiKeys : [];
const resolvedKeyId =
@@ -485,7 +495,10 @@ async function handleAnalyze() {
setStatus("Set a request template in Settings.");
return;
}
if (resolvedTemplate.includes("API_KEY_GOES_HERE") && !apiKey) {
const needsKey =
Boolean(resolvedApiKeyHeader) ||
resolvedTemplate.includes("API_KEY_GOES_HERE");
if (needsKey && !apiKey) {
setStatus("Add an API key in Settings.");
return;
}
@@ -524,7 +537,7 @@ async function handleAnalyze() {
apiKeyHeader: resolvedApiKeyHeader,
apiKeyPrefix: resolvedApiKeyPrefix,
model: resolvedModel,
systemPrompt: systemPrompt || "",
systemPrompt: resolvedSystemPrompt,
resume: resume || "",
taskText: task.text || "",
postingText: state.postingText,