Files
CatoandClaude Fable 5.1 b37c3d65ce feat(rich): chart blocks in answers, drawn by an injected renderer (0.15) (#28)
"Who produces gallium?" now carries a ranked bar chart, not a list. chatkit
stays dependency-free: it defines the data contract (`ChartBlock`, mirroring
@bitbaum/chartkit's props for line, bars, share, timeline, tiles) and a
renderer slot (`renderers={{ chart }}` on ChatScreen, ChatThread, ChatMessage,
Markdown and RichAnswerBlock); the app injects the drawing.

- Parser: each kind validated field by field (bounded lists, finite numbers,
  safe links). A malformed block is rejected by the parser and degrades to
  its caption and a table of the safe rows; without a renderer, or when one
  returns null, chatkit draws that table itself. A chart is never a blank.
- Instruction: when to draw (ranked 3+ rows -> bars, shares -> share, 3+
  points over time -> line, 3+ dated events -> timeline, 2-4 figures ->
  tiles), figures only from tool results, hrefs copied from the result.
- Copy and Listen read the figures as lines, never the wire JSON.
- Tests: node tests per kind, the fallback and the renderer paths; the
  browser test renders a bars block through a stub renderer and a line block
  through the fallback in demo/screen.html at 320/390/1280, with the
  broken-word scan and no horizontal overflow.


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

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-23 11:09:15 +02:00

84 lines
2.7 KiB
TypeScript

import { type ChartBlock } from "./chart.js";
export * from "./chart.js";
/** Declarative answer blocks. Model output is data, never HTML or executable SVG. */
export type RichBlock =
/** A figure drawn by the app's injected renderer (see chart.ts). */
ChartBlock | {
type: "audio";
title: string;
src: string;
creator?: string;
caption?: string;
} | {
type: "gallery";
title: string;
images: {
src: string;
alt: string;
caption?: string;
}[];
} | {
type: "diagram";
title: string;
nodes: {
id: string;
label: string;
detail?: string;
}[];
edges: {
from: string;
to: string;
label?: string;
}[];
} | {
type: "callout";
title: string;
body: string;
} | {
type: "choices";
title: string;
options: {
label: string;
reply: string;
}[];
submit: string;
} | {
/**
* A layered figure, the way the ChatGPT app draws an architecture or a
* flow: full-width boxes stacked top to bottom, a row of tiles where one
* layer has several parts, an arrow between layers with the words that
* cross it, and a caption that says what the figure claims.
*/
type: "stack";
title: string;
layers: StackLayer[];
caption?: string;
};
export type StackNode = {
/** A small uppercase line above the label ("USER", "LOKI"). */
kicker?: string;
label: string;
detail?: string;
/** "accent" tints the box with the product's accent; the default is neutral. */
tone?: "neutral" | "accent";
/** One of STACK_ICONS, drawn above the label on a tile. */
icon?: StackIcon;
};
export type StackLayer = {
nodes: StackNode[];
/** The words on the arrow DOWN to the next layer ("Offers, payments"). */
link?: string;
/** The arrow runs both ways. */
both?: boolean;
};
/** The icons a stack tile may carry — a closed set, so a name is never markup. */
export declare const STACK_ICONS: readonly ["agent", "people", "robot", "person", "building", "money", "document", "code", "check", "globe", "wrench", "box", "chat", "flag"];
export type StackIcon = (typeof STACK_ICONS)[number];
/** Web images or same-origin assets only; no embedded markup or protocol-relative URLs. */
export declare function safeImageSrc(value: unknown): string | null;
/** Invalid or oversized blocks are rejected without crashing the answer. */
export declare function parseRichBlock(raw: string): RichBlock | null;
export declare const RICH_ANSWERS_INSTRUCTION: string;
/** Copy, share and voice keep the content of a visual, never its wire JSON. */
export declare function richAnswerText(text: string): string;
//# sourceMappingURL=rich.d.ts.map