Files
loki/widget/chat/contract.ts
CatoandClaude 8749efd100 feat(widget): say the state on screen, one button to open, a calmer panel (#1279)
The owner on their phone (2026-10-17): it should be clear on screen when
Loki is watching and when it is recording, opening it should be easy, and
the panel was too crowded and intimidating to use.

Watching
- The owner's launcher is ONE button that says its state in a word at
  every width: "● Watching" with a live dot and a ring, or "Paused". A
  tap opens Loki. Its second half, "Point", was the labelled, bigger part
  on a phone, so the obvious tap pointed instead of opening; pointing is
  "Point to area" in the composer.

Recording
- A red edge round the whole screen while Loki listens (it takes no
  taps; grey while it writes it down), a red-bordered dock that says
  "Recording 0:12", and a one-line hint instead of four.

The panel
- One status line instead of two rows: "Watching · 2 to look at · 4 live
  › Pause"; opening it shows what Loki noted and where each change is.
- One microphone: the header's "Voice note" and the composer's "Record"
  did nearly the same thing. "Talk" in the composer is talk-while-
  scrolling, which also covers plain dictation; in chatkit it takes the
  tool row in place of chatkit's own mic.
- "Fix it" and "Ask" instead of "Request a fix" and "Chat with Loki".
- "Continue in Loki" appears once something has been said.
- The visitor's phone launcher is 44px, the minimum tap target.

Docs (widget/README.md, docs/architecture/feedback-widget.md,
docs/development/contextual-voice-feedback.md) and the browser tests
follow the new controls; new pure helpers watchHeadline and
changesHeadline are unit-tested.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-17 20:44:42 +02:00

76 lines
2.8 KiB
TypeScript

/**
* The seam between the widget and its chat chunk (widget/chat/view.tsx).
*
* Types and one string constant — so both bundles can import it without
* either pulling the other in. The widget decides EVERYTHING the
* conversation says and does (conversation-model.ts, conversation.ts): the
* words, the actions, the cards. The chunk only draws it with the shared chat
* (chatkit), the same components Loki's own chat uses. Widget-owned pieces
* that chatkit has no model for (the scope menu, a confirmation card, the
* changes checklist under an answer) travel as ready-built DOM nodes the
* chunk mounts where chatkit leaves a slot.
*/
export type KitMessage = {
id: string;
role: "user" | "assistant";
content: string;
speaker?: { name: string; id: string };
failed?: boolean;
/** Under an answer: its actions (Fix this, the changes, a track link). */
footer?: HTMLElement | null;
};
export type KitMode = { id: string; label: string; send: string; hint?: string };
export type KitState = {
messages: KitMessage[];
/** Loki is working: what it is doing, in words. */
live: null | { status: string };
/** After the last turn: the confirmation card, "send as written". */
after: HTMLElement | null;
/** One-tap questions above the composer. */
starters: { label: string; pick: () => void }[];
placeholder: string;
/** Chat with Loki or save a focused site request.
* One mode: no switch is shown. */
modes: KitMode[];
/** Inside the composer, above the words: the scope menu. */
header: HTMLElement | null;
/** In the composer's tool row: Talk, when the widget offers it in place
* of chatkit's own dictation (one microphone). */
tools?: HTMLElement | null;
/** Under the composer: Continue in Loki. */
footer: HTMLElement | null;
/** Screenshots held for the next note, shown in the composer. */
held: number;
sending: boolean;
/** One focused decision before returning to the conversation. */
reviewingNote?: boolean;
};
export type KitDeps = {
/** Words and the chosen mode's id; images are already with `stage`. */
send: (mode: string, text: string) => void;
/** Screenshots attached in the composer, as data URLs, kept for the next note. */
stage: (images: string[]) => void;
/** The widget's own transcription endpoint (it needs the embed token).
* Absent when the widget offers Talk instead: then chatkit draws no mic. */
transcribe?: (audio: Blob, locale: string) => Promise<string>;
/** --ck-* variables from the widget's boot theme (chat/theme.ts). */
vars: string;
};
export type KitHandle = {
update(state: KitState): void;
focus(): void;
unmount(): void;
};
export type KitModule = {
mount(container: HTMLElement, deps: KitDeps, state: KitState): KitHandle;
};
/** Where the chunk announces itself once loaded (widget/chat-loader.ts). */
export const KIT_GLOBAL = "__lokiWidgetChat";