Files
loki/widget/panel-views.ts
CatoandClaude Opus 5.5 6be6045295 feat(widget): one conversation with Loki; Watch in the header (#1092)
* feat(widget): one conversation with Loki; Watch is in the header for anyone who owns the site

The panel was three tools sharing a box: Request a change (a form), Ask Loki
(an advisor) and Chat, behind tabs and scope chips, each with a history that
vanished on close - and Watch could only be switched on by arriving through
one link on the project page in Loki, so an owner simply visiting their site
never saw it.

Now:
- One thread (widget/conversation.ts). Type, speak, paste a screenshot or
  point at an element; Loki answers about this page (one tap: whole site).
  Every suggested change, and your own message as written, has Send to
  builder / Build this, which opens a confirmation card in the thread; the
  receipt (building / track link) lands in the thread.
- The thread is kept per tab (widget/thread.ts, validated on restore), so it
  survives the site's own page loads.
- Watch in the header: Review for the owner; for anyone else an explainer
  with "This is my site - sign in with Loki", via GET /api/widget/owner,
  which checks ownership of the widget's project and returns to the same
  page with a pass. The return URL must be on the project's own site
  (ownerReturnUrl), so the route cannot hand a pass to someone else's page;
  a non-owner lands back with a plain explanation.
- data-fc-modes now only picks who answers: advisor (default), the studio
  concierge (chat), or none (report). The owner always gets the advisor.
- widget/loki-api.ts holds the two calls; advise.ts and chat.ts are gone.

Tests: widget-thread (new), owner-note-builds (return-URL guard),
widget-embed-browser 41/41, widget-watch-browser 40/40,
widget-host-avoid-browser 24/24.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(widget): style guard follows the panel's real controls; comment no longer reads as an import

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 08:02:54 -07:00

48 lines
1.8 KiB
TypeScript

/**
* Small, self-contained pieces of the panel that main.ts only places: the
* Watch offer under the header, and the toast shown after a visitor hides the
* launcher. Each returns elements and takes callbacks; none holds panel state.
*/
import { h } from "./dom";
/**
* What "Watch" in the header opens for anyone Loki does not yet know as the
* site's owner: what Watch does, that only the owner can switch it on, and
* the one link that does it (a round trip through Loki's sign-in that lands
* back on this page with Watch on — src/app/api/widget/owner/route.ts).
* Hidden until asked for.
*/
export function watchOfferView(signInUrl: string): HTMLElement {
const box = h("div", "watch-offer");
box.style.display = "none";
box.append(
h("b", undefined, "Let Loki watch you use this site"),
h(
"p",
undefined,
"Loki follows what you tap and what the page does, fixes what breaks, and on Review tells you what to improve — design, speed, errors, the flow itself. A bar at the top shows it is on, and nothing you type is ever recorded.",
),
h("p", "sub", "Only the site's owner can switch it on."),
);
const go = h("a", "track", "This is my site — sign in with Loki →");
go.href = signInUrl;
go.rel = "noopener";
box.append(go);
return box;
}
/** Shown after a visitor hides the launcher: how to undo it, now and later. */
export function showHideToast(root: ShadowRoot, onUndo: () => void): HTMLElement {
const toast = h("div", "toast");
toast.setAttribute("role", "status");
const undo = h("button", "toast-undo", "Undo");
undo.addEventListener("click", onUndo);
toast.append(
h("span", undefined, "Loki is hidden on this site. Add #loki to the address to bring it back."),
undo,
);
root.appendChild(toast);
window.setTimeout(() => toast.remove(), 10_000);
return toast;
}