A coordinator asked to set an uploaded logo as a workspace picture could not: the picture tools take a media id, and nothing ever gave the bot one. Attachments reached the model as "[Attached image \"logo.png\"]", every file tool answers with a [file:ID] ref, and an SVG is deliberately stored as a document rather than an image. - copyMediaAsPicture copies an approved image into a new picture row (bot-image/workspace-image). The source keeps its row and bytes, so a message that attached it still loads and changing a picture can never take a file away from a conversation. - grabPictureSource resolves a picture by [file:ID] (the same scope gate every file tool uses) or by the user's own upload; parseFileRef reads the [file:12] form. - The new set_picture tool ships on every run: a bot sets its own face, the coordinator can also dress a worker. update_workspace gained picture_file_id, and setBotPicture/setProfileImage share the copy and the delete. - removeReplacedPicture deletes a replaced picture only when it really is one, never a chat upload. - uploadAndRecordMedia writes images in their own format: PNG stays PNG with its transparency, WebP stays WebP, GIF becomes PNG, everything else JPEG, and the row records the real mime type (it used to say jpeg for every image). - Pictures change live: BotUpdatedData carries image_media_id and a new server:workspace-updated pushes workspace pictures, relayed between processes. - Attachments are labelled with their media id, and BotFilesNote tells a bot that a [file:ID] can become a picture. - grabRunScopes is now the single source of a run's reachable folders, shared by the file tools, imports and the picture tools.
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import type { BUN_SQLITE_COBBLE_BOTS } from "@/db/types/db";
|
|
import grabRunScopes from "@/src/functions/backend/db/bot-files/grab-run-scopes";
|
|
import type { StorageScope } from "@/src/utils/storage-access";
|
|
import type { HarnessTool } from "../../types";
|
|
import generateImageTool from "./generate-image-tool";
|
|
import grabStorageTools from "./grab-storage-tools";
|
|
import makePdfTool from "./make-pdf-tool";
|
|
import storageToolContext from "./storage-tool-context";
|
|
|
|
type Params = {
|
|
bot: Pick<BUN_SQLITE_COBBLE_BOTS, "id" | "kind">;
|
|
user_id: number | string;
|
|
workspace_id?: number | string | null;
|
|
session_id?: number | string;
|
|
/**
|
|
* The files the run reaches, when the caller already read them
|
|
* (`grabRunScopes`); read here otherwise.
|
|
*/
|
|
scopes?: StorageScope[];
|
|
/**
|
|
* Called for a file the bot wrote with "attach" set, so the reply
|
|
* carries it.
|
|
*/
|
|
onAttach?: (params: { media_id: number; name: string }) => void;
|
|
};
|
|
|
|
/**
|
|
* The tools a bot uses to keep and search files (`src/harness/tools/
|
|
* storage/`): listing, reading, writing, moving, deleting and searching
|
|
* its own directory and, in a workspace or as the coordinator, the shared
|
|
* ones, plus making images and PDFs into them. Every run gets them, so a
|
|
* chat reply, a task and a scheduled run all work with the same files.
|
|
*/
|
|
export default async function grabBotFileTools({
|
|
bot,
|
|
user_id,
|
|
workspace_id,
|
|
session_id,
|
|
scopes,
|
|
onAttach,
|
|
}: Params): Promise<HarnessTool[]> {
|
|
const context = storageToolContext({
|
|
bot,
|
|
user_id,
|
|
workspace_id,
|
|
session_id,
|
|
scopes: scopes || (await grabRunScopes({ bot, user_id, workspace_id })),
|
|
onAttach,
|
|
});
|
|
|
|
return [...grabStorageTools(context), generateImageTool(context), makePdfTool(context)];
|
|
}
|