Files
chatkit/dist/react/AnswerActions.js
T
CatoandClaude 04dd6f86b8 feat: under every answer — Copy, Listen, Share; sources as a sheet; replies that lead (0.10.0) (#20)
The pieces of the ChatGPT app the owner put beside ours (2026-10-21), done
once here so Loki, OrangeCat and every chat in the fleet get them:

- `AnswerActions`: the row under an answer. Copy; Listen, reading the answer
  as prose (`plainTextForSpeech`, from loki) with the browser's voice or the
  `speaker` an app passes (loki's studio voice), with a small player — Stop
  and the time so far — while it reads; Share through the system sheet
  where one exists. `ChatThread` renders it under every answer.
- Sources on a touch screen are ONE "Sources · n" button that opens a sheet
  with every record (label, detail, link); chips stay on a mouse. `Sheet`
  (the attach sheet's <dialog>, extracted) and `SourcesRow` are exported.
- `AttachMenu` takes `extra` rows under Camera · Photos · Files, and then
  opens the sheet on a mouse too — an app's "one of my things" has no file
  dialog to live in.
- The replies instruction makes the model lead: 2–4 replies on every answer,
  the recommended next step first, drawn as the lead (`ck-reply-lead`).
- An empty box is one row on the narrowest phone: the placeholder is cut at
  the edge, never wrapped into a clipped second line.

Browser checks cover the player, the sources sheet on a touch screen and
chips on a mouse, and the one-row placeholder at 320px.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-21 06:21:21 +02:00

49 lines
3.5 KiB
JavaScript

"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useSyncExternalStore } from "react";
import { formatElapsed } from "../composer.js";
import { plainTextForSpeech } from "../speech.js";
import { useClipboard } from "./hooks.js";
import { useSpeech } from "./use-speech.js";
import { IconCheck, IconCopy, IconRetry, IconShare, IconSpeaker, IconStop } from "./icons.js";
const noSubscribe = () => () => { };
export const DEFAULT_ANSWER_ACTIONS_LABELS = {
copy: "Copy",
copied: "Copied",
listen: "Listen",
stop: "Stop",
share: "Share",
retry: "Try again",
};
/**
* The row under an answer — Copy, Listen, Share, Try again — the same in every
* product, so an answer is handled the same way wherever it was written.
*
* Every button is one that works here: Listen only where something can
* speak, Share only where the system share sheet exists (phones), Try again
* only when the caller can re-ask. A button that does nothing is worse than
* a missing one. While an answer is being read, a small player takes the
* row's place: a stop and the time read so far.
*
* `children` are the app's own buttons after these (loki's thumbs-down).
*/
export function AnswerActions({ text, onRetry, speaker, share, labels: overrides, children, }) {
const labels = { ...DEFAULT_ANSWER_ACTIONS_LABELS, ...overrides };
const { copied, copy } = useClipboard();
const speech = useSpeech(speaker);
const canShare = useSyncExternalStore(noSubscribe, () => typeof navigator !== "undefined" && typeof navigator.share === "function", () => false);
if (speech.speaking) {
return (_jsxs("div", { className: "ck-turn-actions ck-player", role: "status", "aria-live": "polite", children: [_jsxs("button", { type: "button", className: "ck-action ck-action-stop", onClick: speech.stop, "aria-label": labels.stop, children: [_jsx(IconStop, {}), _jsx("span", { children: labels.stop })] }), _jsx("span", { className: "ck-player-wave", "aria-hidden": true, children: Array.from({ length: 7 }).map((_, i) => (_jsx("span", {}, i))) }), _jsx("span", { className: "ck-player-time", children: formatElapsed(speech.elapsed) })] }));
}
return (_jsxs("div", { className: "ck-turn-actions", children: [_jsxs("button", { type: "button", className: "ck-action", onClick: () => copy(text), "aria-label": copied ? labels.copied : labels.copy, children: [copied ? _jsx(IconCheck, {}) : _jsx(IconCopy, {}), _jsx("span", { children: copied ? labels.copied : labels.copy })] }), speech.supported && (_jsxs("button", { type: "button", className: "ck-action", onClick: () => speech.speak(text), "aria-label": labels.listen, children: [_jsx(IconSpeaker, {}), _jsx("span", { children: labels.listen })] })), canShare && share !== false && (_jsxs("button", { type: "button", className: "ck-action",
// A dismissed share sheet rejects; that is the person changing their
// mind, not an error to report.
onClick: () => void navigator
.share({
title: share?.title,
text: share?.text ?? plainTextForSpeech(text),
url: share?.url,
})
.catch(() => { }), "aria-label": labels.share, children: [_jsx(IconShare, {}), _jsx("span", { children: labels.share })] })), onRetry && (_jsxs("button", { type: "button", className: "ck-action", onClick: onRetry, children: [_jsx(IconRetry, {}), _jsx("span", { children: labels.retry })] })), children] }));
}
//# sourceMappingURL=AnswerActions.js.map