|
|
@@ -3,8 +3,8 @@ const statusEl = document.querySelector("#connection-status");
|
|
|
const chatForm = document.querySelector("#chat-form");
|
|
|
const userMessage = document.querySelector("#user-message");
|
|
|
const runButton = document.querySelector("#run-button");
|
|
|
-const promptSetName = document.querySelector("#prompt-set-name");
|
|
|
-const savedPromptSets = document.querySelector("#saved-prompt-sets");
|
|
|
+const snapshotName = document.querySelector("#workspace-snapshot-name");
|
|
|
+const savedSnapshots = document.querySelector("#saved-workspace-snapshots");
|
|
|
const systemPrompts = document.querySelector("#system-prompts");
|
|
|
const preMessages = document.querySelector("#pre-messages");
|
|
|
const preMessageTemplate = document.querySelector("#pre-message-template");
|
|
|
@@ -12,7 +12,8 @@ const toolList = document.querySelector("#tool-list");
|
|
|
const toolCount = document.querySelector("#tool-count");
|
|
|
const chatConfigDialog = document.querySelector("#chat-config-dialog");
|
|
|
const eventConfigDialog = document.querySelector("#event-config-dialog");
|
|
|
-const PROMPT_SETS_STORAGE_KEY = "agent-lab.prompt-sets.v1";
|
|
|
+const WORKSPACE_SNAPSHOTS_STORAGE_KEY = "agent-lab.workspace-snapshots.v1";
|
|
|
+const LEGACY_PROMPT_SETS_STORAGE_KEY = "agent-lab.prompt-sets.v1";
|
|
|
|
|
|
let socket = null;
|
|
|
let activeAssistant = null;
|
|
|
@@ -31,9 +32,9 @@ bindClick("#add-pre-message", () => {
|
|
|
preMessages.append(createPreMessage({ role: "user", content: "" }));
|
|
|
});
|
|
|
|
|
|
-bindClick("#save-prompt-set", savePromptSet);
|
|
|
-bindClick("#load-prompt-set", loadPromptSet);
|
|
|
-bindClick("#delete-prompt-set", deletePromptSet);
|
|
|
+bindClick("#save-workspace-snapshot", saveWorkspaceSnapshot);
|
|
|
+bindClick("#load-workspace-snapshot", loadWorkspaceSnapshot);
|
|
|
+bindClick("#delete-workspace-snapshot", deleteWorkspaceSnapshot);
|
|
|
bindClick("#open-chat-config-panel", openChatConfig);
|
|
|
bindClick("#close-chat-config", () => {
|
|
|
chatConfigDialog.close();
|
|
|
@@ -55,7 +56,7 @@ chatForm.addEventListener("submit", (event) => {
|
|
|
});
|
|
|
|
|
|
initializePromptList();
|
|
|
-refreshPromptSetSelector();
|
|
|
+refreshWorkspaceSnapshotSelector();
|
|
|
loadTools();
|
|
|
|
|
|
function openChatConfig() {
|
|
|
@@ -156,57 +157,57 @@ function updateToolCount() {
|
|
|
toolCount.textContent = `${selected}/${total} selected`;
|
|
|
}
|
|
|
|
|
|
-function savePromptSet() {
|
|
|
- const name = promptSetName.value.trim();
|
|
|
+function saveWorkspaceSnapshot() {
|
|
|
+ const name = snapshotName.value.trim();
|
|
|
if (!name) {
|
|
|
- statusEl.textContent = "Set name required";
|
|
|
+ statusEl.textContent = "Snapshot name required";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const store = readPromptSets();
|
|
|
- store.sets[name] = buildPromptSet();
|
|
|
- writePromptSets(store);
|
|
|
- refreshPromptSetSelector(name);
|
|
|
- statusEl.textContent = "Prompt set saved";
|
|
|
+ const store = readWorkspaceSnapshots();
|
|
|
+ store.snapshots[name] = buildWorkspaceSnapshot();
|
|
|
+ writeWorkspaceSnapshots(store);
|
|
|
+ refreshWorkspaceSnapshotSelector(name);
|
|
|
+ statusEl.textContent = "Workspace snapshot saved";
|
|
|
}
|
|
|
|
|
|
-function loadPromptSet() {
|
|
|
- const name = savedPromptSets.value;
|
|
|
+function loadWorkspaceSnapshot() {
|
|
|
+ const name = savedSnapshots.value;
|
|
|
if (!name) {
|
|
|
- statusEl.textContent = "Select a prompt set";
|
|
|
+ statusEl.textContent = "Select a snapshot";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const promptSet = readPromptSets().sets[name];
|
|
|
- if (!promptSet) {
|
|
|
- statusEl.textContent = "Prompt set not found";
|
|
|
- refreshPromptSetSelector();
|
|
|
+ const snapshot = readWorkspaceSnapshots().snapshots[name];
|
|
|
+ if (!snapshot) {
|
|
|
+ statusEl.textContent = "Snapshot not found";
|
|
|
+ refreshWorkspaceSnapshotSelector();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- promptSetName.value = name;
|
|
|
- restorePromptSet(promptSet);
|
|
|
- statusEl.textContent = "Prompt set loaded";
|
|
|
+ snapshotName.value = name;
|
|
|
+ restoreWorkspaceSnapshot(snapshot);
|
|
|
+ statusEl.textContent = "Workspace snapshot loaded";
|
|
|
}
|
|
|
|
|
|
-function deletePromptSet() {
|
|
|
- const name = savedPromptSets.value;
|
|
|
+function deleteWorkspaceSnapshot() {
|
|
|
+ const name = savedSnapshots.value;
|
|
|
if (!name) {
|
|
|
- statusEl.textContent = "Select a prompt set";
|
|
|
+ statusEl.textContent = "Select a snapshot";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const store = readPromptSets();
|
|
|
- delete store.sets[name];
|
|
|
- writePromptSets(store);
|
|
|
- if (promptSetName.value.trim() === name) {
|
|
|
- promptSetName.value = "";
|
|
|
+ const store = readWorkspaceSnapshots();
|
|
|
+ delete store.snapshots[name];
|
|
|
+ writeWorkspaceSnapshots(store);
|
|
|
+ if (snapshotName.value.trim() === name) {
|
|
|
+ snapshotName.value = "";
|
|
|
}
|
|
|
- refreshPromptSetSelector();
|
|
|
- statusEl.textContent = "Prompt set deleted";
|
|
|
+ refreshWorkspaceSnapshotSelector();
|
|
|
+ statusEl.textContent = "Workspace snapshot deleted";
|
|
|
}
|
|
|
|
|
|
-function buildPromptSet() {
|
|
|
+function buildWorkspaceSnapshot() {
|
|
|
return {
|
|
|
prompt_items: buildPromptItems(),
|
|
|
system_prompts: buildCustomPromptItems()
|
|
|
@@ -237,17 +238,17 @@ function buildPromptSet() {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-function restorePromptSet(promptSet) {
|
|
|
- restoreSystemPrompts(promptSet.prompt_items || promptSet.system_prompts || []);
|
|
|
- restorePreMessages(promptSet.pre_messages || []);
|
|
|
+function restoreWorkspaceSnapshot(snapshot) {
|
|
|
+ restoreSystemPrompts(snapshot.prompt_items || snapshot.system_prompts || []);
|
|
|
+ restorePreMessages(snapshot.pre_messages || []);
|
|
|
|
|
|
- const chatAgent = promptSet.chat_agent || {};
|
|
|
+ const chatAgent = snapshot.chat_agent || {};
|
|
|
document.querySelector("#model").value = chatAgent.model || "";
|
|
|
document.querySelector("#temperature").value = chatAgent.temperature ?? 0.2;
|
|
|
document.querySelector("#max-tokens").value = chatAgent.max_tokens ?? 800;
|
|
|
restoreExtraBody("chat", chatAgent.extra_body);
|
|
|
|
|
|
- const eventAgent = promptSet.event_agent || {};
|
|
|
+ const eventAgent = snapshot.event_agent || {};
|
|
|
document.querySelector("#event-model").value = eventAgent.model || "";
|
|
|
document.querySelector("#event-temperature").value = eventAgent.temperature ?? 0.2;
|
|
|
document.querySelector("#event-max-tokens").value = eventAgent.max_tokens ?? 800;
|
|
|
@@ -529,33 +530,57 @@ function bindPromptDrag(item) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-function refreshPromptSetSelector(selectedName = "") {
|
|
|
- const previousName = selectedName || savedPromptSets.value;
|
|
|
- const names = Object.keys(readPromptSets().sets).sort();
|
|
|
- savedPromptSets.textContent = "";
|
|
|
+function refreshWorkspaceSnapshotSelector(selectedName = "") {
|
|
|
+ const previousName = selectedName || savedSnapshots.value;
|
|
|
+ const names = Object.keys(readWorkspaceSnapshots().snapshots).sort();
|
|
|
+ savedSnapshots.textContent = "";
|
|
|
|
|
|
const placeholder = document.createElement("option");
|
|
|
placeholder.value = "";
|
|
|
- placeholder.textContent = names.length ? "Select a set" : "No saved sets";
|
|
|
- savedPromptSets.append(placeholder);
|
|
|
+ placeholder.textContent = names.length ? "Select a snapshot" : "No saved snapshots";
|
|
|
+ savedSnapshots.append(placeholder);
|
|
|
|
|
|
names.forEach((name) => {
|
|
|
const option = document.createElement("option");
|
|
|
option.value = name;
|
|
|
option.textContent = name;
|
|
|
- savedPromptSets.append(option);
|
|
|
+ savedSnapshots.append(option);
|
|
|
});
|
|
|
|
|
|
if (names.includes(previousName)) {
|
|
|
- savedPromptSets.value = previousName;
|
|
|
+ savedSnapshots.value = previousName;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function readPromptSets() {
|
|
|
+function readWorkspaceSnapshots() {
|
|
|
try {
|
|
|
- const rawValue = localStorage.getItem(PROMPT_SETS_STORAGE_KEY);
|
|
|
+ const rawValue = localStorage.getItem(WORKSPACE_SNAPSHOTS_STORAGE_KEY);
|
|
|
if (!rawValue) {
|
|
|
- return { sets: {} };
|
|
|
+ return readLegacyPromptSets();
|
|
|
+ }
|
|
|
+
|
|
|
+ const parsed = JSON.parse(rawValue);
|
|
|
+ if (
|
|
|
+ !parsed ||
|
|
|
+ typeof parsed !== "object" ||
|
|
|
+ !parsed.snapshots ||
|
|
|
+ typeof parsed.snapshots !== "object" ||
|
|
|
+ Array.isArray(parsed.snapshots)
|
|
|
+ ) {
|
|
|
+ return { snapshots: {} };
|
|
|
+ }
|
|
|
+
|
|
|
+ return parsed;
|
|
|
+ } catch {
|
|
|
+ return { snapshots: {} };
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function readLegacyPromptSets() {
|
|
|
+ try {
|
|
|
+ const rawValue = localStorage.getItem(LEGACY_PROMPT_SETS_STORAGE_KEY);
|
|
|
+ if (!rawValue) {
|
|
|
+ return { snapshots: {} };
|
|
|
}
|
|
|
|
|
|
const parsed = JSON.parse(rawValue);
|
|
|
@@ -566,17 +591,17 @@ function readPromptSets() {
|
|
|
typeof parsed.sets !== "object" ||
|
|
|
Array.isArray(parsed.sets)
|
|
|
) {
|
|
|
- return { sets: {} };
|
|
|
+ return { snapshots: {} };
|
|
|
}
|
|
|
|
|
|
- return parsed;
|
|
|
+ return { snapshots: parsed.sets };
|
|
|
} catch {
|
|
|
- return { sets: {} };
|
|
|
+ return { snapshots: {} };
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function writePromptSets(store) {
|
|
|
- localStorage.setItem(PROMPT_SETS_STORAGE_KEY, JSON.stringify(store));
|
|
|
+function writeWorkspaceSnapshots(store) {
|
|
|
+ localStorage.setItem(WORKSPACE_SNAPSHOTS_STORAGE_KEY, JSON.stringify(store));
|
|
|
}
|
|
|
|
|
|
function runDebugSession() {
|