removed checks for placeholder API key presence in advanced mode
This commit is contained in:
@@ -414,14 +414,6 @@ async function handleAnalysisRequest(port, payload, signal) {
|
|||||||
safePost(port, { type: "ERROR", message: "Missing API URL." });
|
safePost(port, { type: "ERROR", message: "Missing API URL." });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!requestTemplate) {
|
|
||||||
safePost(port, { type: "ERROR", message: "Missing request template." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (apiKeyHeader && !apiKey) {
|
|
||||||
safePost(port, { type: "ERROR", message: "Missing API key." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!apiBaseUrl) {
|
if (!apiBaseUrl) {
|
||||||
safePost(port, { type: "ERROR", message: "Missing API base URL." });
|
safePost(port, { type: "ERROR", message: "Missing API base URL." });
|
||||||
|
|||||||
@@ -186,6 +186,33 @@ function normalizeConfigList(list) {
|
|||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TEMPLATE_PLACEHOLDERS = [
|
||||||
|
"PROMPT_GOES_HERE",
|
||||||
|
"SYSTEM_PROMPT_GOES_HERE",
|
||||||
|
"API_KEY_GOES_HERE",
|
||||||
|
"MODEL_GOES_HERE",
|
||||||
|
"API_BASE_URL_GOES_HERE"
|
||||||
|
];
|
||||||
|
|
||||||
|
function buildTemplateValidationSource(template) {
|
||||||
|
let output = template || "";
|
||||||
|
for (const token of TEMPLATE_PLACEHOLDERS) {
|
||||||
|
output = output.split(`\"${token}\"`).join(JSON.stringify("PLACEHOLDER"));
|
||||||
|
output = output.split(token).join("null");
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidTemplateJson(template) {
|
||||||
|
if (!template) return false;
|
||||||
|
try {
|
||||||
|
JSON.parse(buildTemplateValidationSource(template));
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function resolveScopedItems(parentItems, localItems, disabledNames) {
|
function resolveScopedItems(parentItems, localItems, disabledNames) {
|
||||||
const parent = Array.isArray(parentItems) ? parentItems : [];
|
const parent = Array.isArray(parentItems) ? parentItems : [];
|
||||||
const local = Array.isArray(localItems) ? localItems : [];
|
const local = Array.isArray(localItems) ? localItems : [];
|
||||||
@@ -1061,15 +1088,8 @@ async function handleAnalyze() {
|
|||||||
setStatus("Set an API URL in Settings.");
|
setStatus("Set an API URL in Settings.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!resolvedTemplate) {
|
if (!isValidTemplateJson(resolvedTemplate)) {
|
||||||
setStatus("Set a request template in Settings.");
|
setStatus("Request template JSON is invalid.");
|
||||||
return;
|
|
||||||
}
|
|
||||||
const needsKey =
|
|
||||||
Boolean(resolvedApiKeyHeader) ||
|
|
||||||
resolvedTemplate.includes("API_KEY_GOES_HERE");
|
|
||||||
if (needsKey && !apiKey) {
|
|
||||||
setStatus("Add an API key in Settings.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -475,6 +475,33 @@ function normalizeConfigList(list) {
|
|||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TEMPLATE_PLACEHOLDERS = [
|
||||||
|
"PROMPT_GOES_HERE",
|
||||||
|
"SYSTEM_PROMPT_GOES_HERE",
|
||||||
|
"API_KEY_GOES_HERE",
|
||||||
|
"MODEL_GOES_HERE",
|
||||||
|
"API_BASE_URL_GOES_HERE"
|
||||||
|
];
|
||||||
|
|
||||||
|
function buildTemplateValidationSource(template) {
|
||||||
|
let output = template || "";
|
||||||
|
for (const token of TEMPLATE_PLACEHOLDERS) {
|
||||||
|
output = output.split(`\"${token}\"`).join(JSON.stringify("PLACEHOLDER"));
|
||||||
|
output = output.split(token).join("null");
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidTemplateJson(template) {
|
||||||
|
if (!template) return false;
|
||||||
|
try {
|
||||||
|
JSON.parse(buildTemplateValidationSource(template));
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeDisabledInherited(source) {
|
function normalizeDisabledInherited(source) {
|
||||||
const data = source && typeof source === "object" ? source : {};
|
const data = source && typeof source === "object" ? source : {};
|
||||||
return {
|
return {
|
||||||
@@ -3440,11 +3467,8 @@ function updateSidebarErrors() {
|
|||||||
if (!defaultApiConfig) {
|
if (!defaultApiConfig) {
|
||||||
errors.push("Default environment is missing an API config.");
|
errors.push("Default environment is missing an API config.");
|
||||||
} else if (defaultApiConfig.advanced) {
|
} else if (defaultApiConfig.advanced) {
|
||||||
if (!defaultApiConfig.apiUrl) {
|
if (!isValidTemplateJson(defaultApiConfig.requestTemplate || "")) {
|
||||||
errors.push("Default API config is missing an API URL.");
|
errors.push("Default API config request template is invalid JSON.");
|
||||||
}
|
|
||||||
if (!defaultApiConfig.requestTemplate) {
|
|
||||||
errors.push("Default API config is missing a request template.");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!defaultApiConfig.apiBaseUrl) {
|
if (!defaultApiConfig.apiBaseUrl) {
|
||||||
@@ -3455,12 +3479,7 @@ function updateSidebarErrors() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const needsKey =
|
if (!defaultApiConfig.advanced && defaultApiConfig?.apiKeyHeader) {
|
||||||
Boolean(defaultApiConfig?.apiKeyHeader) ||
|
|
||||||
Boolean(
|
|
||||||
defaultApiConfig?.requestTemplate?.includes("API_KEY_GOES_HERE")
|
|
||||||
);
|
|
||||||
if (needsKey) {
|
|
||||||
const key = enabledApiKeys.find(
|
const key = enabledApiKeys.find(
|
||||||
(entry) => entry.id === defaultApiConfig?.apiKeyId
|
(entry) => entry.id === defaultApiConfig?.apiKeyId
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user