A bot's powers came from bots.kind alone, so only the coordinator could hand work to other bots. bot_types now works like user_types: a row with no workspace holds everywhere (the coordinator), one with a workspace only there (a workspace admin), and no row is a worker. bots.kind stays the legacy marker of the one coordinator for who sees it. The matrices in src/dict/bot-types-dict.ts say what each type may do, whom it may direct and who grants it, read by one generic interpreter (rbac/type-assignment.ts) that userTypeAssignment now wraps too. Every run reads its powers once (grabBotRunPowers) and the chat tools, task runs and task tools gate on them instead of kind; a run's powers are its type's and its user's together. In the workspace it leads, an admin hands tasks to the workers there (results relayed back to it), sets their instructions, adds tasks to their lists and keeps the workspace's context when its user may. Super admins and admins grant it from the workspace's settings or the chat header's menu, and the coordinator with set_bot_type. Admins are marked with a filled green shield beside their name across the workspace, kept live by pushBotUpdated's admin_workspace_ids. Co-Authored-By: Claude Opus 5.5 <[email protected]>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
import type { BUN_SQLITE_COBBLE_TASKS } from "@/db/types/db";
|
|
import AppError from "@/src/utils/app-error";
|
|
import botTaskScopesSql from "@/src/utils/task-access/bot-task-scopes-sql";
|
|
|
|
type Params = {
|
|
task_id: number | string;
|
|
/**
|
|
* The bot whose run is asking.
|
|
*/
|
|
bot_id: number | string;
|
|
is_coordinator: boolean;
|
|
/**
|
|
* The workspaces the bot is admin of (`grabBotRunPowers`).
|
|
*/
|
|
admin_workspace_ids?: number[];
|
|
};
|
|
|
|
/**
|
|
* The task, if the bot's run reaches it: its own, a workspace it works in,
|
|
* or anything at all for the coordinator. The gate every task tool makes
|
|
* before reading or changing one, so a tool argument can never widen a
|
|
* run's reach.
|
|
*/
|
|
export default async function grabRunTask({
|
|
task_id,
|
|
bot_id,
|
|
is_coordinator,
|
|
admin_workspace_ids,
|
|
}: Params): Promise<BUN_SQLITE_COBBLE_TASKS> {
|
|
const access = botTaskScopesSql({ bot_id, is_coordinator, admin_workspace_ids });
|
|
|
|
const res = await BunSQLite.sql<BUN_SQLITE_COBBLE_TASKS>({
|
|
sql: `SELECT t.* FROM tasks t WHERE t.id = ? AND ${access.sql} LIMIT 1`,
|
|
values: [Number(task_id), ...access.values],
|
|
});
|
|
|
|
const task = res.payload?.[0];
|
|
|
|
if (!task?.id) {
|
|
throw new AppError(`Task #${task_id} isn't one you can work on.`);
|
|
}
|
|
|
|
return task;
|
|
}
|