Add bot graphics
Bots can now show a concept as a visual: create_graphic (with update_graphic, read_graphic and list_graphics, on every run, no computer needed) stores one HTML document in bot_graphics, per user like the conversation, and the chat renders its [graphic:ID] ref as an inline card sized to fit, with a large view and a page of its own (no rail). Graphic HTML is treated as hostile: it is only served at /graphics/<id> with a CSP sandbox allowing scripts under an origin of its own and no network, loading only the vendored Chart.js and Mermaid from /graphics-lib/. The document carries the app's theme vars and scrollbars, reports its height to the thread, and a frame that navigates away is closed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
type Params = {
|
||||
id: number | string;
|
||||
};
|
||||
|
||||
/**
|
||||
* How a bot names a graphic it made: `[graphic:5]`. The chat turns it
|
||||
* into a link (`linkComputerRefs`) that renders as the graphic itself,
|
||||
* framed in the thread, with ways to open it full size.
|
||||
*/
|
||||
export default function graphicRef({ id }: Params) {
|
||||
return `[graphic:${id}]`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The link target a graphic ref becomes, e.g. `#graphic-5`.
|
||||
*/
|
||||
export const GraphicRefHrefPrefix = "#graphic-";
|
||||
|
||||
/**
|
||||
* The id in a graphic ref's link target, or null.
|
||||
*/
|
||||
export function graphicRefId({ href }: { href?: string | null }) {
|
||||
if (!href?.startsWith(GraphicRefHrefPrefix)) return null;
|
||||
|
||||
const id = Number(href.slice(GraphicRefHrefPrefix.length));
|
||||
|
||||
return Number.isInteger(id) && id > 0 ? id : null;
|
||||
}
|
||||
Reference in New Issue
Block a user