added sidebar for ergonomics and error display of the configuration
This commit is contained in:
@@ -21,6 +21,7 @@ const DEFAULT_SETTINGS = {
|
||||
activeApiConfigId: "",
|
||||
envConfigs: [],
|
||||
activeEnvConfigId: "",
|
||||
profiles: [],
|
||||
apiBaseUrl: "https://api.openai.com/v1",
|
||||
apiKeyHeader: "Authorization",
|
||||
apiKeyPrefix: "Bearer ",
|
||||
@@ -242,12 +243,44 @@ chrome.runtime.onInstalled.addListener(async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const hasProfiles =
|
||||
Array.isArray(stored.profiles) && stored.profiles.length > 0;
|
||||
if (!hasProfiles) {
|
||||
const id = crypto?.randomUUID
|
||||
? crypto.randomUUID()
|
||||
: `profile-${Date.now()}-${Math.random().toString(16).slice(2, 8)}`;
|
||||
updates.profiles = [
|
||||
{
|
||||
id,
|
||||
name: "Default",
|
||||
text: stored.resume || "",
|
||||
type: "Resume"
|
||||
}
|
||||
];
|
||||
} else {
|
||||
const normalizedProfiles = stored.profiles.map((profile) => ({
|
||||
...profile,
|
||||
text: profile.text ?? "",
|
||||
type: profile.type === "Profile" ? "Profile" : "Resume"
|
||||
}));
|
||||
const needsProfileUpdate = normalizedProfiles.some(
|
||||
(profile, index) =>
|
||||
(profile.text || "") !== (stored.profiles[index]?.text || "") ||
|
||||
(profile.type || "Resume") !== (stored.profiles[index]?.type || "Resume")
|
||||
);
|
||||
if (needsProfileUpdate) {
|
||||
updates.profiles = normalizedProfiles;
|
||||
}
|
||||
}
|
||||
|
||||
const resolvedEnvConfigs = updates.envConfigs || stored.envConfigs || [];
|
||||
const defaultEnvId =
|
||||
resolvedEnvConfigs[0]?.id ||
|
||||
updates.activeEnvConfigId ||
|
||||
stored.activeEnvConfigId ||
|
||||
"";
|
||||
const resolvedProfiles = updates.profiles || stored.profiles || [];
|
||||
const defaultProfileId = resolvedProfiles[0]?.id || "";
|
||||
const taskSource = Array.isArray(updates.tasks)
|
||||
? updates.tasks
|
||||
: Array.isArray(stored.tasks)
|
||||
@@ -256,10 +289,13 @@ chrome.runtime.onInstalled.addListener(async () => {
|
||||
if (taskSource.length) {
|
||||
const normalizedTasks = taskSource.map((task) => ({
|
||||
...task,
|
||||
defaultEnvId: task.defaultEnvId || defaultEnvId
|
||||
defaultEnvId: task.defaultEnvId || defaultEnvId,
|
||||
defaultProfileId: task.defaultProfileId || defaultProfileId
|
||||
}));
|
||||
const needsTaskUpdate = normalizedTasks.some(
|
||||
(task, index) => task.defaultEnvId !== taskSource[index]?.defaultEnvId
|
||||
(task, index) =>
|
||||
task.defaultEnvId !== taskSource[index]?.defaultEnvId ||
|
||||
task.defaultProfileId !== taskSource[index]?.defaultProfileId
|
||||
);
|
||||
if (needsTaskUpdate) {
|
||||
updates.tasks = normalizedTasks;
|
||||
@@ -328,9 +364,10 @@ chrome.runtime.onMessage.addListener((message) => {
|
||||
}
|
||||
});
|
||||
|
||||
function buildUserMessage(resume, task, posting) {
|
||||
function buildUserMessage(resume, resumeType, task, posting) {
|
||||
const header = resumeType === "Profile" ? "=== PROFILE ===" : "=== RESUME ===";
|
||||
return [
|
||||
"=== RESUME ===",
|
||||
header,
|
||||
resume || "",
|
||||
"",
|
||||
"=== TASK ===",
|
||||
@@ -370,6 +407,7 @@ async function handleAnalysisRequest(port, payload, signal) {
|
||||
model,
|
||||
systemPrompt,
|
||||
resume,
|
||||
resumeType,
|
||||
taskText,
|
||||
postingText,
|
||||
tabId
|
||||
@@ -416,7 +454,12 @@ async function handleAnalysisRequest(port, payload, signal) {
|
||||
return;
|
||||
}
|
||||
|
||||
const userMessage = buildUserMessage(resume, taskText, postingText);
|
||||
const userMessage = buildUserMessage(
|
||||
resume,
|
||||
resumeType,
|
||||
taskText,
|
||||
postingText
|
||||
);
|
||||
|
||||
await chrome.storage.local.set({ [OUTPUT_STORAGE_KEY]: "" });
|
||||
openKeepalive(tabId);
|
||||
|
||||
Reference in New Issue
Block a user