Added multi-api support and advanced mode

This commit is contained in:
2026-01-17 16:46:01 -05:00
parent 3bb350f3cf
commit 2638e08453
5 changed files with 809 additions and 166 deletions

View File

@@ -431,6 +431,8 @@ async function handleAnalyze() {
const {
apiKeys = [],
activeApiKeyId = "",
apiConfigs = [],
activeApiConfigId = "",
apiBaseUrl,
apiKeyHeader,
apiKeyPrefix,
@@ -440,6 +442,8 @@ async function handleAnalyze() {
} = await getStorage([
"apiKeys",
"activeApiKeyId",
"apiConfigs",
"activeApiConfigId",
"apiBaseUrl",
"apiKeyHeader",
"apiKeyPrefix",
@@ -448,24 +452,56 @@ async function handleAnalyze() {
"resume"
]);
if (!apiBaseUrl) {
setStatus("Set an API base URL in Settings.");
return;
}
const resolvedConfigs = Array.isArray(apiConfigs) ? apiConfigs : [];
const activeConfig =
resolvedConfigs.find((entry) => entry.id === activeApiConfigId) ||
resolvedConfigs[0];
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 resolvedKeys = Array.isArray(apiKeys) ? apiKeys : [];
const activeKey =
resolvedKeys.find((entry) => entry.id === activeApiKeyId) || resolvedKeys[0];
const resolvedKeyId =
activeConfig?.apiKeyId || activeApiKeyId || resolvedKeys[0]?.id || "";
const activeKey = resolvedKeys.find((entry) => entry.id === resolvedKeyId);
const apiKey = activeKey?.key || "";
if (apiKeyHeader && !apiKey) {
setStatus("Add an API key in Settings.");
return;
}
if (!model) {
setStatus("Set a model name in Settings.");
return;
if (isAdvanced) {
if (!resolvedApiUrl) {
setStatus("Set an API URL in Settings.");
return;
}
if (!resolvedTemplate) {
setStatus("Set a request template in Settings.");
return;
}
if (resolvedTemplate.includes("API_KEY_GOES_HERE") && !apiKey) {
setStatus("Add an API key in Settings.");
return;
}
} else {
if (!resolvedApiBaseUrl) {
setStatus("Set an API base URL in Settings.");
return;
}
if (resolvedApiKeyHeader && !apiKey) {
setStatus("Add an API key in Settings.");
return;
}
if (!resolvedModel) {
setStatus("Set a model name in Settings.");
return;
}
}
const promptText = buildUserMessage(resume || "", task.text || "", state.postingText);
@@ -481,10 +517,13 @@ async function handleAnalyze() {
type: "START_ANALYSIS",
payload: {
apiKey,
apiBaseUrl,
apiKeyHeader,
apiKeyPrefix,
model,
apiMode: isAdvanced ? "advanced" : "basic",
apiUrl: resolvedApiUrl,
requestTemplate: resolvedTemplate,
apiBaseUrl: resolvedApiBaseUrl,
apiKeyHeader: resolvedApiKeyHeader,
apiKeyPrefix: resolvedApiKeyPrefix,
model: resolvedModel,
systemPrompt: systemPrompt || "",
resume: resume || "",
taskText: task.text || "",