Serve every media file privately at /media/<id>
There is no public media any more. `/media/public/<id>` served a media row with no session at all, so anyone with the id could read a file. The public/private split is gone: the path is `/media/<id>` (and `/media/<id>/thumbnail`), every request is signed in first, and `grabUserMedia` decides whether the user may see it: their own upload, a bot's or workspace's picture or file they reach, or a file on a task they reach. Anything else is a 404 before a path is built. The `media.is_private` column and the two per-user directories went with it: uploads live in `media/<user_id>/` and there is nothing to pick between. The files browser's media volume is now the viewer's own folder whatever their role. Bots also say which of the two things they mean. A `[file:ID]` ref is a saved file and its chip opens the bytes; a folder is a new `[folder:volume:owner:path]` ref (`src/utils/folder-ref.ts`) whose chip opens the files browser there and downloads nothing. The old `[path:...]` ref and the extension sniffing that guessed file from folder are gone, so `import_file` names the folder holding a file it copied rather than the file itself. The prompts say what the Assistant got wrong: list before importing or saving, one copy per artifact, never split a file into parts unless asked, never claim the store is empty without a fresh list, and never invent a size cap. A re-import now says the path already existed instead of silently overwriting and reporting a fresh copy.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { z } from "zod";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import listBotFiles from "@/src/functions/backend/db/bot-files/list-bot-files";
|
||||
import folderRef from "@/src/utils/folder-ref";
|
||||
import type { HarnessTool } from "../../types";
|
||||
import { fileRef, formatBytes, type StorageToolContext } from "./storage-tool-context";
|
||||
|
||||
@@ -13,12 +14,15 @@ type Args = {
|
||||
|
||||
/**
|
||||
* Lists a bot's files: one folder's, or everything under it, or whatever
|
||||
* matches a name. Each file comes with its ref so the bot can read it.
|
||||
* matches a name. Each file comes with its `[file:ID]` ref so the bot can
|
||||
* read it, and the answer names the folder it is in with a folder ref, so a
|
||||
* bot that points at "everything in reports/" writes something the user can
|
||||
* actually open.
|
||||
*/
|
||||
export default function listFilesTool(context: StorageToolContext): HarnessTool<Args> {
|
||||
return {
|
||||
name: "list_files",
|
||||
description: `List the files you have saved, newest first: one folder's with "folder", everything with "recursive", or the ones whose name or path has "search". Each line has its path, size and ref (e.g. [file:12]) to read it.`,
|
||||
description: `List the files you have saved, newest first: one folder's with "folder", everything with "recursive", or the ones whose name or path has "search". Each line has its path, size and [file:ID] ref (e.g. [file:12]) to read it. The answer also names the folder as a folder ref, which opens it in Files without downloading anything: a file is a [file:ID] ref, a folder is a [folder:...] ref.`,
|
||||
schema: z.object({
|
||||
folder: z.string().max(AppData.BotFilePathMaxChars).optional(),
|
||||
search: z.string().max(120).optional(),
|
||||
@@ -56,7 +60,31 @@ export default function listFilesTool(context: StorageToolContext): HarnessTool<
|
||||
? `\n(Showing the first ${AppData.BotFileListMaxItems}. Narrow it with "folder" or "search".)`
|
||||
: "";
|
||||
|
||||
return `${files.length} file(s):\n${lines.join("\n")}${more}`;
|
||||
return `${files.length} file(s):\n${lines.join("\n")}${more}\n\nThe folder: ${folderRefFor({ files, folder, scopes: context.scopes })}`;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The folder the listing is about, as a folder ref the bot can put in a
|
||||
* message: the one it asked for, else the one the first file is in. Its
|
||||
* volume is the scope the file lives in.
|
||||
*/
|
||||
function folderRefFor({
|
||||
files,
|
||||
folder,
|
||||
scopes,
|
||||
}: {
|
||||
files: { scope?: string | null; owner_id?: number | string | null; folder?: string | null }[];
|
||||
folder: string;
|
||||
scopes: StorageToolContext["scopes"];
|
||||
}) {
|
||||
const first = files[0];
|
||||
const scope = first
|
||||
? scopes.find((it) => it.scope == first.scope && Number(it.owner_id) == Number(first.owner_id))
|
||||
: scopes[0];
|
||||
const path = folder || first?.folder || "";
|
||||
const volume = scope?.scope == "workspace" ? "workspace" : "bot";
|
||||
|
||||
return folderRef({ volume, owner_id: scope?.owner_id || 0, path });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user