Files
cobble/src/functions/backend/db/extensions/assert-bot-extension-manager.ts
T
tben 08d02e6033 Give bots skills: runbooks they load when a job matches
A skill is a runbook: a name, a unique slug, a one-line description of when
it applies, and the markdown body. A run only ever sees the slug and
description (one load_skill tool carries them), and reads the whole body
only when it calls the tool, so a long runbook costs nothing until needed.

Skills are the third extension kind beside MCP servers and custom tools, on
the same botExtensionsSql path, so per-bot, per-workspace and all-bots
grants work the same way, and attachDefaultExtensions hands an every-bot
skill to new bots. load_skill is a reserved tool name, so a custom tool
cannot shadow it, and a built-in wins a clash.

Managed on Settings > Skills; ExtensionRow links each kind to its own page
and a skill never reports a failure, since nothing connects or runs.
2026-10-22 12:31:42 +01:00

32 lines
1001 B
TypeScript

import BunSQLite from "@moduletrace/bun-sqlite";
import AppError from "@/src/utils/app-error";
import grabCrewRole from "../access/grab-crew-role";
type Params = {
user_id: number | string;
bot_id: number | string;
};
/**
* Throws unless the user manages this bot's MCP servers, tools and skills: super
* admins and admins, the super admin alone for the coordinator. Returns
* the bot.
*/
export default async function assertBotExtensionManager({ user_id, bot_id }: Params) {
const role = await grabCrewRole({ user_id });
const bot = (
await BunSQLite.sql<{ id: number; kind: string; name: string }>({
sql: `SELECT id, kind, name FROM bots WHERE id = ?`,
values: [bot_id],
})
).payload?.[0];
if (!bot) throw new AppError(`That bot doesn't exist.`);
if (role == "member" || (bot.kind == "coordinator" && role != "super_admin")) {
throw new AppError(`Only an admin can change a bot's tools.`);
}
return bot;
}