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:
2026-10-27 08:11:15 +01:00
co-authored by Claude Opus 5.5
parent 51fd4d5538
commit bea656ade8
65 changed files with 1959 additions and 21 deletions
+9
View File
@@ -13,6 +13,7 @@ import migrateBotTypes from "./functions/backend/db/bot-types/migrate-bot-types"
import clearImplicitSessionLinks from "./functions/backend/db/bot-sessions/clear-implicit-session-links";
import syncKnowledgebaseFts from "./functions/backend/db/knowledgebases/fts/sync-knowledgebase-fts";
import handleComputerProxy from "./functions/server/computers/handle-computer-proxy";
import handleGraphicsRequest from "./functions/server/graphics/handle-graphics-request";
import handlePwaFile from "./functions/server/pwa/handle-pwa-file";
import handleInstallIconFile from "./functions/server/pwa/handle-install-icon-file";
import handleBuildInfo from "./functions/server/pwa/handle-build-info";
@@ -106,6 +107,14 @@ const server = Bun.serve({
if (build_info) return build_info;
/**
* Graphics open in a frame inside the app, never as a page of
* it, so the loading page never stands in for one.
*/
const graphic = await handleGraphicsRequest({ req, url });
if (graphic) return await compressResponse({ req, response: graphic });
const loading_page = await handlePrecacheGate({ req, url });
if (loading_page) return loading_page;