|
|
@@ -10,7 +10,6 @@ const preMessages = document.querySelector("#pre-messages");
|
|
|
const preMessageTemplate = document.querySelector("#pre-message-template");
|
|
|
const toolList = document.querySelector("#tool-list");
|
|
|
const toolCount = document.querySelector("#tool-count");
|
|
|
-const promptDialog = document.querySelector("#prompt-dialog");
|
|
|
const chatConfigDialog = document.querySelector("#chat-config-dialog");
|
|
|
const eventConfigDialog = document.querySelector("#event-config-dialog");
|
|
|
const PROMPT_SETS_STORAGE_KEY = "agent-lab.prompt-sets.v1";
|
|
|
@@ -22,6 +21,8 @@ let firstTokenAt = 0;
|
|
|
let elapsedTimer = 0;
|
|
|
let hasBackendRoundStats = false;
|
|
|
let pendingEnabledTools = null;
|
|
|
+let availableTools = [];
|
|
|
+let generatedChatPrompt = "";
|
|
|
|
|
|
bindClick("#add-system-prompt", () => {
|
|
|
systemPrompts.append(createSystemPrompt(""));
|
|
|
@@ -34,12 +35,6 @@ bindClick("#add-pre-message", () => {
|
|
|
bindClick("#save-prompt-set", savePromptSet);
|
|
|
bindClick("#load-prompt-set", loadPromptSet);
|
|
|
bindClick("#delete-prompt-set", deletePromptSet);
|
|
|
-bindClick("#open-prompt-config", () => {
|
|
|
- promptDialog.showModal();
|
|
|
-});
|
|
|
-bindClick("#close-prompt-config", () => {
|
|
|
- promptDialog.close();
|
|
|
-});
|
|
|
bindClick("#open-chat-config-panel", openChatConfig);
|
|
|
bindClick("#close-chat-config", () => {
|
|
|
chatConfigDialog.close();
|
|
|
@@ -91,10 +86,12 @@ async function loadTools() {
|
|
|
}
|
|
|
|
|
|
function renderTools(tools) {
|
|
|
+ availableTools = tools;
|
|
|
toolList.textContent = "";
|
|
|
if (!tools.length) {
|
|
|
toolList.textContent = "No tools available";
|
|
|
updateToolCount();
|
|
|
+ updateChatSystemPromptDefault(tools);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -111,7 +108,10 @@ function renderTools(tools) {
|
|
|
checkbox.className = "tool-toggle";
|
|
|
checkbox.value = tool.name;
|
|
|
checkbox.checked = true;
|
|
|
- checkbox.addEventListener("change", updateToolCount);
|
|
|
+ checkbox.addEventListener("change", () => {
|
|
|
+ updateToolCount();
|
|
|
+ updateChatSystemPromptDefault(availableTools);
|
|
|
+ });
|
|
|
|
|
|
label.append(checkbox, ` ${tool.name}`);
|
|
|
|
|
|
@@ -132,6 +132,7 @@ function renderTools(tools) {
|
|
|
pendingEnabledTools = null;
|
|
|
}
|
|
|
updateToolCount();
|
|
|
+ updateChatSystemPromptDefault(tools);
|
|
|
}
|
|
|
|
|
|
function formatRequiredParameters(tool) {
|
|
|
@@ -146,6 +147,7 @@ function setAllTools(checked) {
|
|
|
checkbox.checked = checked;
|
|
|
});
|
|
|
updateToolCount();
|
|
|
+ updateChatSystemPromptDefault(availableTools);
|
|
|
}
|
|
|
|
|
|
function updateToolCount() {
|
|
|
@@ -254,6 +256,7 @@ function restorePromptSet(promptSet) {
|
|
|
document.querySelector("#max-event-loops").value = eventAgent.max_event_loops ?? 1;
|
|
|
const enabledTools = eventAgent.enabled_tools || [];
|
|
|
pendingEnabledTools = applySelectedTools(enabledTools) ? null : enabledTools;
|
|
|
+ updateChatSystemPromptDefault(availableTools);
|
|
|
}
|
|
|
|
|
|
function buildExtraBody(prefix) {
|
|
|
@@ -322,9 +325,47 @@ function applySelectedTools(toolNames) {
|
|
|
checkbox.checked = selected.has(checkbox.value);
|
|
|
});
|
|
|
updateToolCount();
|
|
|
+ updateChatSystemPromptDefault(availableTools);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+function buildAvailableEventsPrompt(tools) {
|
|
|
+ const eventLines = tools.map((tool) => `- ${tool.name}: ${tool.description || "No description"}`);
|
|
|
+ if (!eventLines.length) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ "You may request EventAgent work using this text protocol.",
|
|
|
+ "Available events:",
|
|
|
+ ...eventLines,
|
|
|
+ "First write the user-facing reply normally. If events are needed, append this block after the visible reply:",
|
|
|
+ "<agent_events>",
|
|
|
+ "event_name",
|
|
|
+ "</agent_events>",
|
|
|
+ "Use exact event names only, one per line. Do not include parameters.",
|
|
|
+ ].join("\n");
|
|
|
+}
|
|
|
+
|
|
|
+function updateChatSystemPromptDefault(tools) {
|
|
|
+ const selected = new Set(selectedTools());
|
|
|
+ const prompt = buildAvailableEventsPrompt(
|
|
|
+ tools.filter((tool) => selected.has(tool.name)),
|
|
|
+ );
|
|
|
+ const systemPrompt = document.querySelector("#chat-system-prompt");
|
|
|
+ const preview = document.querySelector("#chat-event-prompt-preview");
|
|
|
+ if (preview) {
|
|
|
+ preview.value = prompt;
|
|
|
+ }
|
|
|
+ if (!systemPrompt) {
|
|
|
+ generatedChatPrompt = prompt;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!systemPrompt.value.trim() || systemPrompt.value === generatedChatPrompt) {
|
|
|
+ systemPrompt.value = prompt;
|
|
|
+ }
|
|
|
+ generatedChatPrompt = prompt;
|
|
|
+}
|
|
|
+
|
|
|
function refreshPromptSetSelector(selectedName = "") {
|
|
|
const previousName = selectedName || savedPromptSets.value;
|
|
|
const names = Object.keys(readPromptSets().sets).sort();
|