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]>
29 lines
798 B
TypeScript
29 lines
798 B
TypeScript
import { GraphicsPrefix } from "@/src/dict/graphics-dict";
|
|
|
|
type Params = {
|
|
graphic_id: number;
|
|
dark?: boolean;
|
|
/**
|
|
* The version shown, so a changed graphic loads afresh.
|
|
*/
|
|
version?: number;
|
|
};
|
|
|
|
/**
|
|
* Where a graphic's sandboxed document is served, in a theme.
|
|
*/
|
|
export default function graphicUrl({ graphic_id, dark, version }: Params) {
|
|
const query = new URLSearchParams({ theme: dark ? "dark" : "light" });
|
|
|
|
if (version) query.set("v", String(version));
|
|
|
|
return `${GraphicsPrefix}/${graphic_id}?${query.toString()}`;
|
|
}
|
|
|
|
/**
|
|
* The app page that shows a graphic full size, beside the rail.
|
|
*/
|
|
export function graphicPageHref({ graphic_id, bot_id }: { graphic_id: number; bot_id: number }) {
|
|
return `/admin/bots/${bot_id}/graphics/${graphic_id}`;
|
|
}
|