mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-05 00:28:55 +01:00
"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>
20 lines
977 B
TypeScript
20 lines
977 B
TypeScript
import { type ReactNode } from "react";
|
|
import type { ChartBlock } from "../chart.js";
|
|
/**
|
|
* The drawing an app injects into answers. chatkit stays dependency-free:
|
|
* it validates the data and leaves the slot; the app fills it.
|
|
*
|
|
* <ChatThread renderers={{ chart: (b) => <Chart {...b} /> }} … />
|
|
*
|
|
* A renderer that returns `null` hands the block back to chatkit's own
|
|
* fallback (the caption and a table of the data), so an app can draw the
|
|
* kinds it has a component for and leave the rest readable.
|
|
*/
|
|
export type RichRenderers = {
|
|
chart?: (block: ChartBlock) => ReactNode;
|
|
};
|
|
/** Set once at the screen (`ChatScreen renderers`), read by every answer in it. */
|
|
export declare const RichRenderersContext: import("react").Context<RichRenderers | undefined>;
|
|
/** The renderers in force: the prop, over what the screen provided. */
|
|
export declare function useRichRenderers(own?: RichRenderers): RichRenderers | undefined;
|
|
//# sourceMappingURL=renderers.d.ts.map
|