mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 05:47:38 +01:00
* feat(answers): answers that read like the ChatGPT app's (0.13.0)
Measured screen by screen against the ChatGPT app on a phone, and closed
in the package so every product gets it:
- Headings are signposts: a size up, with air above them, so a long answer
can be scanned and found again.
- Options are cards: a numbered list whose items open with a bold name gets
a tile badge, the name a size up, a hairline between cards, and a pill
for a short tag written right after the name (`[Recommended]`). The
instruction asks the model to mark the option it recommends that way.
- Sources are chips: a `[F2, F1]` handle is drawn after the sentence as
"Fleet AGENTS.md +1", linked when the record has a link, and moved after
the full stop when the model wrote it before.
- Links in the words that leave the site say so: dotted underline, arrow.
- A layered figure, `{"type":"stack"}`: full-width boxes top to bottom, a
row of tiles where a layer has parts (icons from a closed list, never
markup), the words that cross each arrow, an accent tone, a caption.
`diagram` stays for an arbitrary graph.
- "Thought for 3m 38s ›" above an answer from `message.thinking`, closed by
default; `live.steps` shows the same row open while a turn runs, with
the newest step marked. `ThinkingRow` and `formatThinkingDuration` are
exported; `thoughtFor`, `thought`, `thinking` join the thread labels.
Tests: tag and citation placement (core), stack validation and text form
(core), the whole answer rendered on the server (render), and the stack
fitting six tiles on a 390px phone with the thought line above (browser).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE
* fix(markdown): no space before the full stop when a citation chip moves after it
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE
---------
Co-authored-by: Claude <noreply@anthropic.com>
168 lines
6.4 KiB
TypeScript
168 lines
6.4 KiB
TypeScript
import type { ReactNode } from "react";
|
||
import { type CitationMap, type RenderLink } from "./Markdown.js";
|
||
import type { Speaker } from "../speech.js";
|
||
export type ChatSpeaker = {
|
||
/** Shown above the message when more than one agent can answer. */
|
||
name: string;
|
||
/** Stable id for styling (`ck-from-<id>`), e.g. "cat" or "loki". */
|
||
id?: string;
|
||
};
|
||
export type ChatMessageData = {
|
||
id: string;
|
||
role: "user" | "assistant";
|
||
content: string;
|
||
speaker?: ChatSpeaker;
|
||
citations?: CitationMap;
|
||
/** The turn failed: shown as a failure with Retry, never as silence. */
|
||
failed?: boolean;
|
||
/**
|
||
* What the person is likely to say next, as one-tap buttons under the
|
||
* latest answer. Leave it out and a `quick_replies` block in `content` is
|
||
* used instead (see `REPLIES_INSTRUCTION`).
|
||
*/
|
||
replies?: readonly string[];
|
||
/**
|
||
* What the model did before answering — "Thought for 3m 38s ›" with the
|
||
* steps under it, the way the ChatGPT and Claude apps show it. Closed by
|
||
* default; the answer is what the reader came for.
|
||
*/
|
||
thinking?: Thinking;
|
||
};
|
||
export type ThinkingStep = {
|
||
label: string;
|
||
detail?: string;
|
||
};
|
||
export type Thinking = {
|
||
/** How long it took, in milliseconds. */
|
||
durationMs?: number;
|
||
/** The steps, in order: searches, tool calls, reasoning in one line each. */
|
||
steps?: readonly ThinkingStep[];
|
||
/** A short summary of the reasoning, if the model gives one. */
|
||
summary?: string;
|
||
};
|
||
/** "3m 38s", "42s", "1h 02m" — the ChatGPT app's unit words, so a product
|
||
* translating the labels still gets one shape. */
|
||
export declare function formatThinkingDuration(ms: number): string;
|
||
export type ThreadLabels = {
|
||
/** "Thought for {time}" — `{time}` is replaced; without a duration, `thought`. */
|
||
thoughtFor: string;
|
||
thought: string;
|
||
thinking: string;
|
||
copy: string;
|
||
copied: string;
|
||
listen: string;
|
||
share: string;
|
||
retry: string;
|
||
stop: string;
|
||
working: string;
|
||
stopped: string;
|
||
jump: string;
|
||
failed: string;
|
||
loading: string;
|
||
replies: string;
|
||
};
|
||
export declare const DEFAULT_THREAD_LABELS: ThreadLabels;
|
||
/**
|
||
* One turn. The asymmetry is deliberate: the person's own words get a pill —
|
||
* a short aside they already know — and the answer gets the full column with
|
||
* no box, because it is the thing being READ. Copy is on every answer; Retry
|
||
* only on the last one (retrying an older turn would fork the thread).
|
||
*/
|
||
export declare function ChatMessage({ message, onRetry, renderLink, showSpeaker, footer, last, onReply, speaker, share, labels, }: {
|
||
message: ChatMessageData;
|
||
/** The app's voice for Listen (the browser's without it). */
|
||
speaker?: Speaker | null;
|
||
/** What Share hands to the system sheet. `false` hides Share. */
|
||
share?: {
|
||
title?: string;
|
||
url?: string;
|
||
} | false;
|
||
/** Send a suggested reply. Without it no reply buttons are shown. */
|
||
onReply?: (text: string) => void;
|
||
/** The latest answer: its actions stay visible (they are what you want next). */
|
||
last?: boolean;
|
||
onRetry?: () => void;
|
||
renderLink?: RenderLink;
|
||
/** Hide the name when only one agent ever speaks. */
|
||
showSpeaker?: boolean;
|
||
/** Under the answer: provenance, sources, an action card. */
|
||
footer?: ReactNode;
|
||
labels?: ThreadLabels;
|
||
}): import("react").JSX.Element;
|
||
/**
|
||
* The replies under an answer. Exported for apps that render their own
|
||
* thread, so the buttons look and behave the same in every product.
|
||
*/
|
||
export declare function ChatReplies({ replies, onPick, label, disabled, }: {
|
||
replies: readonly string[];
|
||
onPick: (text: string) => void;
|
||
label?: string;
|
||
disabled?: boolean;
|
||
}): import("react").JSX.Element | null;
|
||
export type LiveTurn = {
|
||
/** What has streamed in so far. */
|
||
text?: string;
|
||
/** What it is doing before the first word ("Reading the fleet map"). */
|
||
status?: string;
|
||
/** The steps so far, newest last; shown open while the turn runs. */
|
||
steps?: readonly ThinkingStep[];
|
||
speaker?: ChatSpeaker;
|
||
};
|
||
/**
|
||
* "Thought for 3m 38s ›" above an answer, opening to the steps; while a turn
|
||
* runs, the same row open with the steps arriving and the newest one marked.
|
||
*/
|
||
export declare function ThinkingRow({ thinking, live, labels, }: {
|
||
thinking: Thinking;
|
||
live?: boolean;
|
||
labels?: ThreadLabels;
|
||
}): import("react").JSX.Element | null;
|
||
/**
|
||
* The conversation. Follows new tokens only while the reader is at the
|
||
* bottom, with a button back down once they are not; a turn in flight can be
|
||
* stopped from where it is being written.
|
||
*/
|
||
export declare function ChatThread({ messages, live, loading, stopped, onStop, onRetry, onReply, renderLink, renderFooter, showSpeakers, speaker, share, empty, children, labels: labelOverrides, }: {
|
||
messages: ChatMessageData[];
|
||
/** The app's voice for Listen under every answer (the browser's without it). */
|
||
speaker?: Speaker | null;
|
||
/** What Share hands to the system sheet. `false` hides Share. */
|
||
share?: {
|
||
title?: string;
|
||
url?: string;
|
||
} | false;
|
||
live?: LiveTurn | null;
|
||
loading?: boolean;
|
||
/** The person stopped the last turn themselves. */
|
||
stopped?: boolean;
|
||
onStop?: () => void;
|
||
/** Retry the last answer (offered on it, and on a failed one). */
|
||
onRetry?: () => void;
|
||
/**
|
||
* Send a suggested reply — usually the same function the Composer's
|
||
* `onSend` calls. Buttons appear under the latest answer only, and never
|
||
* while a turn is in flight.
|
||
*/
|
||
onReply?: (text: string) => void;
|
||
renderLink?: RenderLink;
|
||
/** App-specific content under an answer (sources, an action card). */
|
||
renderFooter?: (m: ChatMessageData) => ReactNode;
|
||
/** Default: shown when more than one speaker appears in the thread. */
|
||
showSpeakers?: boolean;
|
||
/** Shown instead of the thread before the first message (starters). */
|
||
empty?: ReactNode;
|
||
/** After the last turn (a note, a picker). */
|
||
children?: ReactNode;
|
||
labels?: Partial<ThreadLabels>;
|
||
}): import("react").JSX.Element;
|
||
export type Starter = string | {
|
||
label: string;
|
||
prompt?: string;
|
||
};
|
||
/** The empty state that starts a conversation. It disappears once one has. */
|
||
export declare function ChatStarters({ starters, onPick, title, }: {
|
||
starters: readonly Starter[];
|
||
onPick: (prompt: string) => void;
|
||
title?: ReactNode;
|
||
}): import("react").JSX.Element;
|
||
//# sourceMappingURL=Thread.d.ts.map
|