|
@@ -25,6 +25,7 @@ const eventConfigDialog = document.querySelector("#event-config-dialog");
|
|
|
const auditDialog = document.querySelector("#audit-dialog");
|
|
const auditDialog = document.querySelector("#audit-dialog");
|
|
|
const toolInvocationMode = document.querySelector("#tool-invocation-mode");
|
|
const toolInvocationMode = document.querySelector("#tool-invocation-mode");
|
|
|
const toolModeHelp = document.querySelector("#tool-mode-help");
|
|
const toolModeHelp = document.querySelector("#tool-mode-help");
|
|
|
|
|
+const eventAgentModelSettings = document.querySelector("#event-agent-model-settings");
|
|
|
const WORKSPACE_SNAPSHOTS_STORAGE_KEY = "agent-lab.workspace-snapshots.v1";
|
|
const WORKSPACE_SNAPSHOTS_STORAGE_KEY = "agent-lab.workspace-snapshots.v1";
|
|
|
const LEGACY_PROMPT_SETS_STORAGE_KEY = "agent-lab.prompt-sets.v1";
|
|
const LEGACY_PROMPT_SETS_STORAGE_KEY = "agent-lab.prompt-sets.v1";
|
|
|
|
|
|
|
@@ -82,7 +83,7 @@ bindClick("#select-all-tools", () => {
|
|
|
bindClick("#clear-tools", () => {
|
|
bindClick("#clear-tools", () => {
|
|
|
setAllTools(false);
|
|
setAllTools(false);
|
|
|
});
|
|
});
|
|
|
-toolInvocationMode.addEventListener("change", updateToolModeHelp);
|
|
|
|
|
|
|
+toolInvocationMode.addEventListener("change", refreshToolModeState);
|
|
|
|
|
|
|
|
chatForm.addEventListener("submit", (event) => {
|
|
chatForm.addEventListener("submit", (event) => {
|
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
@@ -90,7 +91,6 @@ chatForm.addEventListener("submit", (event) => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
initializePromptList();
|
|
initializePromptList();
|
|
|
-updateToolModeHelp();
|
|
|
|
|
refreshWorkspaceSnapshotSelector();
|
|
refreshWorkspaceSnapshotSelector();
|
|
|
loadTools();
|
|
loadTools();
|
|
|
loadSessions({ preserveStatus: true });
|
|
loadSessions({ preserveStatus: true });
|
|
@@ -261,7 +261,7 @@ function renderTools(tools) {
|
|
|
if (!tools.length) {
|
|
if (!tools.length) {
|
|
|
toolList.textContent = "No tools available";
|
|
toolList.textContent = "No tools available";
|
|
|
updateToolCount();
|
|
updateToolCount();
|
|
|
- updateEventPromptItem(tools);
|
|
|
|
|
|
|
+ refreshToolModeState();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -280,7 +280,7 @@ function renderTools(tools) {
|
|
|
checkbox.checked = true;
|
|
checkbox.checked = true;
|
|
|
checkbox.addEventListener("change", () => {
|
|
checkbox.addEventListener("change", () => {
|
|
|
updateToolCount();
|
|
updateToolCount();
|
|
|
- updateEventPromptItem(availableTools);
|
|
|
|
|
|
|
+ refreshToolModeState();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
label.append(checkbox, ` ${tool.name}`);
|
|
label.append(checkbox, ` ${tool.name}`);
|
|
@@ -302,7 +302,7 @@ function renderTools(tools) {
|
|
|
pendingEnabledTools = null;
|
|
pendingEnabledTools = null;
|
|
|
}
|
|
}
|
|
|
updateToolCount();
|
|
updateToolCount();
|
|
|
- updateEventPromptItem(tools);
|
|
|
|
|
|
|
+ refreshToolModeState();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function formatRequiredParameters(tool) {
|
|
function formatRequiredParameters(tool) {
|
|
@@ -317,7 +317,7 @@ function setAllTools(checked) {
|
|
|
checkbox.checked = checked;
|
|
checkbox.checked = checked;
|
|
|
});
|
|
});
|
|
|
updateToolCount();
|
|
updateToolCount();
|
|
|
- updateEventPromptItem(availableTools);
|
|
|
|
|
|
|
+ refreshToolModeState();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function updateToolCount() {
|
|
function updateToolCount() {
|
|
@@ -435,8 +435,21 @@ function restoreWorkspaceSnapshot(snapshot) {
|
|
|
eventAgent.batch_timeout_seconds ?? 15;
|
|
eventAgent.batch_timeout_seconds ?? 15;
|
|
|
const enabledTools = eventAgent.enabled_tools || [];
|
|
const enabledTools = eventAgent.enabled_tools || [];
|
|
|
pendingEnabledTools = applySelectedTools(enabledTools) ? null : enabledTools;
|
|
pendingEnabledTools = applySelectedTools(enabledTools) ? null : enabledTools;
|
|
|
- updateEventPromptItem(availableTools);
|
|
|
|
|
|
|
+ refreshToolModeState();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function refreshToolModeState() {
|
|
|
|
|
+ const isChatAgentTools = toolInvocationMode.value === "chat_agent_tools";
|
|
|
updateToolModeHelp();
|
|
updateToolModeHelp();
|
|
|
|
|
+ eventAgentModelSettings
|
|
|
|
|
+ .querySelectorAll("input, textarea, select, button")
|
|
|
|
|
+ .forEach((control) => {
|
|
|
|
|
+ control.disabled = isChatAgentTools;
|
|
|
|
|
+ });
|
|
|
|
|
+ removeGeneratedEventPromptItems();
|
|
|
|
|
+ if (!isChatAgentTools) {
|
|
|
|
|
+ updateEventPromptItem(availableTools);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function updateToolModeHelp() {
|
|
function updateToolModeHelp() {
|
|
@@ -480,7 +493,6 @@ function restoreSystemPrompts(prompts) {
|
|
|
promptItems.forEach((prompt) => {
|
|
promptItems.forEach((prompt) => {
|
|
|
systemPrompts.append(createSystemPrompt(prompt));
|
|
systemPrompts.append(createSystemPrompt(prompt));
|
|
|
});
|
|
});
|
|
|
- ensureEventPromptItem();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function restorePreMessages(messages) {
|
|
function restorePreMessages(messages) {
|
|
@@ -573,7 +585,7 @@ function applySelectedTools(toolNames) {
|
|
|
checkbox.checked = selected.has(checkbox.value);
|
|
checkbox.checked = selected.has(checkbox.value);
|
|
|
});
|
|
});
|
|
|
updateToolCount();
|
|
updateToolCount();
|
|
|
- updateEventPromptItem(availableTools);
|
|
|
|
|
|
|
+ refreshToolModeState();
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -582,7 +594,7 @@ function initializePromptList() {
|
|
|
bindPromptItemControls(item);
|
|
bindPromptItemControls(item);
|
|
|
bindPromptDrag(item);
|
|
bindPromptDrag(item);
|
|
|
});
|
|
});
|
|
|
- ensureEventPromptItem();
|
|
|
|
|
|
|
+ refreshToolModeState();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function buildPromptItems() {
|
|
function buildPromptItems() {
|
|
@@ -600,7 +612,14 @@ function buildCustomPromptItems() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function collectSystemPrompts() {
|
|
function collectSystemPrompts() {
|
|
|
- return buildPromptItems()
|
|
|
|
|
|
|
+ const promptItems = buildPromptItems();
|
|
|
|
|
+ const serializablePrompts = toolInvocationMode.value === "chat_agent_tools"
|
|
|
|
|
+ ? promptItems.filter((item) => (
|
|
|
|
|
+ item.prompt_kind !== "event_agent_system"
|
|
|
|
|
+ && !isGeneratedEventPromptContent(item.content)
|
|
|
|
|
+ ))
|
|
|
|
|
+ : promptItems;
|
|
|
|
|
+ return serializablePrompts
|
|
|
.map((item) => item.content)
|
|
.map((item) => item.content)
|
|
|
.filter(Boolean);
|
|
.filter(Boolean);
|
|
|
}
|
|
}
|
|
@@ -609,10 +628,11 @@ function normalizePromptItems(prompts) {
|
|
|
const items = Array.isArray(prompts) ? prompts : [];
|
|
const items = Array.isArray(prompts) ? prompts : [];
|
|
|
const normalized = items
|
|
const normalized = items
|
|
|
.map((prompt) => normalizePromptItem(prompt))
|
|
.map((prompt) => normalizePromptItem(prompt))
|
|
|
- .filter((prompt) => prompt.prompt_kind === "event_agent_system" || prompt.content);
|
|
|
|
|
- if (!normalized.some((prompt) => prompt.prompt_kind === "event_agent_system")) {
|
|
|
|
|
- normalized.push({ prompt_kind: "event_agent_system", content: "" });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ .filter((prompt) => (
|
|
|
|
|
+ prompt.prompt_kind !== "event_agent_system"
|
|
|
|
|
+ && prompt.content
|
|
|
|
|
+ && !isGeneratedEventPromptContent(prompt.content)
|
|
|
|
|
+ ));
|
|
|
if (!normalized.some((prompt) => prompt.prompt_kind === "custom")) {
|
|
if (!normalized.some((prompt) => prompt.prompt_kind === "custom")) {
|
|
|
normalized.unshift({ prompt_kind: "custom", role: "system", content: "" });
|
|
normalized.unshift({ prompt_kind: "custom", role: "system", content: "" });
|
|
|
}
|
|
}
|
|
@@ -636,6 +656,18 @@ function normalizePromptItem(prompt) {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function isGeneratedEventPromptContent(content) {
|
|
|
|
|
+ const normalized = typeof content === "string" ? content.trim() : "";
|
|
|
|
|
+ return normalized.startsWith(
|
|
|
|
|
+ "You may request EventAgent work using this text protocol.",
|
|
|
|
|
+ )
|
|
|
|
|
+ && normalized.includes("<agent_events>")
|
|
|
|
|
+ && normalized.includes("</agent_events>")
|
|
|
|
|
+ && normalized.includes(
|
|
|
|
|
+ "Use exact event names only, one per line. Do not include parameters.",
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function buildAvailableEventsPrompt(tools) {
|
|
function buildAvailableEventsPrompt(tools) {
|
|
|
const eventLines = tools.map((tool) => `- ${tool.name}: ${tool.description || "No description"}`);
|
|
const eventLines = tools.map((tool) => `- ${tool.name}: ${tool.description || "No description"}`);
|
|
|
if (!eventLines.length) {
|
|
if (!eventLines.length) {
|
|
@@ -662,6 +694,18 @@ function updateEventPromptItem(tools) {
|
|
|
eventPrompt.querySelector(".system-prompt").value = prompt;
|
|
eventPrompt.querySelector(".system-prompt").value = prompt;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function removeGeneratedEventPromptItems() {
|
|
|
|
|
+ systemPrompts.querySelectorAll(".prompt-item").forEach((item) => {
|
|
|
|
|
+ const content = item.querySelector(".system-prompt").value;
|
|
|
|
|
+ if (
|
|
|
|
|
+ item.dataset.promptKind === "event_agent_system"
|
|
|
|
|
+ || isGeneratedEventPromptContent(content)
|
|
|
|
|
+ ) {
|
|
|
|
|
+ item.remove();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function ensureEventPromptItem() {
|
|
function ensureEventPromptItem() {
|
|
|
const existing = systemPrompts.querySelector('[data-prompt-kind="event_agent_system"]');
|
|
const existing = systemPrompts.querySelector('[data-prompt-kind="event_agent_system"]');
|
|
|
if (existing) {
|
|
if (existing) {
|