feat(rag): honest deflection gate with amber UI state and alternative-question chips
This commit is contained in:
+41
-5
@@ -2,10 +2,11 @@
|
||||
*
|
||||
* Renders suggestions, shows KB health, and runs chat turns against
|
||||
* POST /api/chat (SSE, PLAN §4): deltas render live into the Brain bubble,
|
||||
* the done event appends source chips, errors surface as a red banner.
|
||||
* The full feedback state machine lands with the loading-feedback story;
|
||||
* this keeps the "never stale" contract: the button is busy for the whole
|
||||
* turn and is always re-enabled at the end.
|
||||
* the done event appends source chips (and "Maybe try" chips when the
|
||||
* turn was deflected — honesty gate, phase 04), errors surface as a red
|
||||
* banner. The full feedback state machine lands with the loading-feedback
|
||||
* story; this keeps the "never stale" contract: the button is busy for the
|
||||
* whole turn and is always re-enabled at the end.
|
||||
* All DOM ids match frontend/index.html.
|
||||
*/
|
||||
|
||||
@@ -199,6 +200,38 @@ function appendSources(wrap, sources) {
|
||||
}
|
||||
}
|
||||
|
||||
/* "Maybe try:" chips under a deflected bubble (honesty gate, phase 04).
|
||||
Same .suggestion-chip component as onboarding; clicking wires what
|
||||
exists today — fill the input + focus. One-tap submit lands with the
|
||||
phase 05 chip component. The group is accessible (role=list +
|
||||
aria-label) and wraps cleanly at every width. */
|
||||
function appendMaybeTry(wrap, suggestions) {
|
||||
if (!suggestions || !suggestions.length) return;
|
||||
const body = wrap.querySelector(".msg-body");
|
||||
const group = document.createElement("div");
|
||||
group.className = "maybe-try";
|
||||
group.setAttribute("role", "list");
|
||||
group.setAttribute("aria-label", "Maybe try");
|
||||
const label = document.createElement("span");
|
||||
label.className = "visually-hidden";
|
||||
label.textContent = "Maybe try:";
|
||||
group.appendChild(label);
|
||||
for (const s of suggestions) {
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.className = "suggestion-chip";
|
||||
btn.setAttribute("role", "listitem");
|
||||
btn.textContent = s;
|
||||
btn.addEventListener("click", () => {
|
||||
input.value = s;
|
||||
autoGrow();
|
||||
input.focus();
|
||||
});
|
||||
group.appendChild(btn);
|
||||
}
|
||||
body.appendChild(group);
|
||||
}
|
||||
|
||||
function showErrorBanner(detail) {
|
||||
banner.hidden = false;
|
||||
banner.classList.add("is-error");
|
||||
@@ -258,7 +291,10 @@ async function handleSend(e) {
|
||||
removeTyping();
|
||||
wrap = addMessage("brain", "…");
|
||||
}
|
||||
if (ev.deflected) wrap.classList.add("is-deflected");
|
||||
if (ev.deflected) {
|
||||
wrap.classList.add("is-deflected");
|
||||
appendMaybeTry(wrap, ev.suggestions);
|
||||
}
|
||||
appendSources(wrap, ev.sources);
|
||||
} else if (ev.type === "error") {
|
||||
throw new Error(ev.detail || "Something went wrong on my side.");
|
||||
|
||||
Reference in New Issue
Block a user