fix: quiet switchers and clean chat injection
All checks were successful
BotUI CI/CD / build (push) Successful in 40s
All checks were successful
BotUI CI/CD / build (push) Successful in 40s
This commit is contained in:
parent
1c90e09871
commit
a91b9c604a
1 changed files with 27 additions and 25 deletions
|
|
@ -961,39 +961,41 @@ function finalizeStreaming() {
|
|||
}
|
||||
|
||||
var chip = document.createElement("button");
|
||||
var isSwitcher = action && (action.type === "switch_context" || action.type === "select_context");
|
||||
// More robust switcher detection: check action type or context/switcher fields
|
||||
var isSwitcher = action && (
|
||||
action.type === "switch_context" ||
|
||||
action.type === "select_context" ||
|
||||
suggestion.text.toLowerCase().includes("tabela") || // Heuristic for current bot
|
||||
action.switcher ||
|
||||
action.context
|
||||
);
|
||||
|
||||
chip.className = isSwitcher ? "switcher-chip" : "suggestion-chip";
|
||||
|
||||
if (isSwitcher && action.switcher && activeSwitchers[action.switcher]) {
|
||||
var switcherName = action ? (action.switcher || action.context) : suggestion.text;
|
||||
if (isSwitcher && activeSwitchers[switcherName]) {
|
||||
chip.classList.add("active");
|
||||
}
|
||||
|
||||
chip.textContent = suggestion.text || "Suggestion";
|
||||
|
||||
chip.onclick = (function (sugg, act) {
|
||||
chip.onclick = (function (sugg, act, name) {
|
||||
return function () {
|
||||
console.log("Suggestion clicked:", sugg);
|
||||
if (act) {
|
||||
if (act.type === "switch_context" || act.type === "select_context") {
|
||||
// Toggle switcher logic
|
||||
var name = act.switcher || act.context;
|
||||
if (name) {
|
||||
activeSwitchers[name] = !activeSwitchers[name];
|
||||
console.log("Switcher " + name + " is now " + (activeSwitchers[name] ? "ON" : "OFF"));
|
||||
|
||||
// Update visual state immediately
|
||||
if (activeSwitchers[name]) {
|
||||
chip.classList.add("active");
|
||||
} else {
|
||||
chip.classList.remove("active");
|
||||
}
|
||||
|
||||
// Keep suggestions open when toggling switchers
|
||||
return;
|
||||
}
|
||||
console.log("Suggestion clicked:", sugg, "as switcher:", isSwitcher);
|
||||
if (isSwitcher) {
|
||||
// Toggle switcher logic
|
||||
activeSwitchers[name] = !activeSwitchers[name];
|
||||
console.log("Switcher " + name + " is now " + (activeSwitchers[name] ? "ON" : "OFF"));
|
||||
|
||||
if (activeSwitchers[name]) {
|
||||
chip.classList.add("active");
|
||||
} else {
|
||||
chip.classList.remove("active");
|
||||
}
|
||||
return; // STAY QUIET
|
||||
}
|
||||
|
||||
if (act) {
|
||||
if (act.type === "invoke_tool") {
|
||||
// Direct tool execution via WebSocket (Type 6)
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
|
|
@ -1019,7 +1021,7 @@ function finalizeStreaming() {
|
|||
// Default fallback: send suggestion text
|
||||
window.sendMessage(sugg.text);
|
||||
};
|
||||
})(suggestion, action);
|
||||
})(suggestion, action, switcherName);
|
||||
|
||||
suggestionsEl.appendChild(chip);
|
||||
});
|
||||
|
|
@ -1071,7 +1073,7 @@ function finalizeStreaming() {
|
|||
input.focus();
|
||||
}
|
||||
|
||||
addMessage("user", content);
|
||||
addMessage("user", content); // Original clean content for the UI
|
||||
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(
|
||||
|
|
@ -1080,7 +1082,7 @@ function finalizeStreaming() {
|
|||
user_id: currentUserId,
|
||||
session_id: currentSessionId,
|
||||
channel: "web",
|
||||
content: enhancedContent,
|
||||
content: enhancedContent, // Enhanced content for the LLM
|
||||
message_type: MessageType.USER,
|
||||
timestamp: new Date().toISOString(),
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue