Files
CatoandClaude 58ee6e8c78 feat(widget): the conversation drawn by the shared chat (chatkit), on Loki's own widget first (#1162)
The widget's chat was the fleet's own hand-rolled chat; with
data-fc-chat="kit" it is now drawn by @bitbaum/chatkit, the thread and
composer Loki's own chat renders, over the same conversation model.

- widget/chat/: a separate lazy chunk (public/widget-chat.js, ~24 KB
  gzipped, Preact standing in for React), fetched on first open, carrying
  the tag's nonce. chatkit's CSS is rewritten for the shadow root (:root ->
  :host, rem -> px) and coloured from the boot theme.
- widget/conversation-kit.ts maps the model's snapshot to what chatkit
  draws; Fix this, the changes, the confirmation card, the About chips and
  Continue in Loki go into chatkit's slots as the widget's own nodes.
- A chunk that cannot load leaves the panel's own view: no dead end.
- /widget-chat.js is public in the auth proxy, like /widget.js.
- Tests: widget-kit-browser (34 checks: ask, card, screenshot, fallback,
  phone width, host hotkeys, weight budget), widget-chat-css, and
  widget-self-contained now guards the chunk/panel seam.


Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-12 05:13:25 -07:00

22 lines
1.0 KiB
TypeScript

/**
* chatkit's stylesheet, made to work inside the widget's Shadow DOM.
*
* Two things in it assume it owns the page, and neither holds on someone
* else's site:
* - its defaults sit on `:where(:root)`, which never matches inside a shadow
* root — every --ck-* would be undefined. They move to `:where(:host)`
* (the widget then sets them from its boot theme, chat/theme.ts);
* - it sizes everything in `rem`, which is the HOST page's root font size.
* A site with `html { font-size: 62.5% }` would shrink the 16px input to
* 10px (iOS zooms the page on focus) and the 44px targets to 27px. The
* widget is drawn at fixed sizes everywhere else; so is this.
*
* Applied at build time (scripts/build-widget-chat.ts), so the chunk ships the
* corrected CSS as a string.
*/
export function shadowChatkitCss(css: string, rootPx = 16): string {
return css
.replace(/:where\(:root\)/g, ":where(:host)")
.replace(/(-?\d*\.?\d+)rem\b/g, (_, n: string) => `${+(Number(n) * rootPx).toFixed(3)}px`);
}