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]>
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { z } from "zod";
|
|
import listBotGraphics from "@/src/functions/backend/db/bot-graphics/list-bot-graphics";
|
|
import graphicRef from "@/src/utils/graphic-ref";
|
|
import type { HarnessTool } from "../../types";
|
|
import type { GraphicToolContext } from "./graphic-tool-context";
|
|
|
|
type Args = {
|
|
limit?: number;
|
|
};
|
|
|
|
/**
|
|
* Lets a bot find the graphics it made for this user here, newest first,
|
|
* so it changes one rather than making it again.
|
|
*/
|
|
export default function listGraphicsTool(context: GraphicToolContext): HarnessTool<Args> {
|
|
return {
|
|
name: "list_graphics",
|
|
description: `List the graphics you made for this user in this conversation's place, newest first. Check it before making a graphic the user may already have.`,
|
|
schema: z.object({
|
|
limit: z.number().int().min(1).max(50).optional(),
|
|
}),
|
|
run: async ({ args }) => {
|
|
const graphics = await listBotGraphics({
|
|
bot_id: context.bot_id,
|
|
user_id: context.user_id,
|
|
workspace_id: context.workspace_id,
|
|
limit: args.limit,
|
|
});
|
|
|
|
if (!graphics.length) return `You haven't made any graphics for this user here.`;
|
|
|
|
return graphics
|
|
.map(
|
|
(graphic) =>
|
|
`- ${graphicRef({ id: graphic.id })} "${graphic.title}", version ${graphic.version || 1}, ${graphic.chars} characters, updated ${new Date(Number(graphic.updated_at)).toUTCString()}`,
|
|
)
|
|
.join("\n");
|
|
},
|
|
};
|
|
}
|