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]>
64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
import type { BUN_SQLITE_COBBLE_BOTS, BUN_SQLITE_COBBLE_WORKSPACE_BOTS } from "@/db/types/db";
|
|
import type { BotWorkspace } from "@/src/types";
|
|
import grabUserWorkspaces from "./grab-user-workspaces";
|
|
|
|
type Params = {
|
|
user_id: number | string;
|
|
bot: Pick<BUN_SQLITE_COBBLE_BOTS, "id" | "kind">;
|
|
};
|
|
|
|
/**
|
|
* The workspaces a bot works in, for its settings page. The coordinator
|
|
* works in every workspace; a worker only in the ones it was added to.
|
|
* Each row carries what the bot has for that workspace alone, and whether
|
|
* it's that workspace's admin.
|
|
*/
|
|
export default async function grabBotWorkspaces({
|
|
user_id,
|
|
bot,
|
|
}: Params): Promise<BotWorkspace[]> {
|
|
const workspaces = await grabUserWorkspaces({ user_id });
|
|
|
|
if (bot.kind == "coordinator") {
|
|
return workspaces.map((workspace) => ({
|
|
...workspace,
|
|
workspace_system_prompt: null,
|
|
workspace_memory: null,
|
|
}));
|
|
}
|
|
|
|
const rows =
|
|
(
|
|
await BunSQLite.sql<BUN_SQLITE_COBBLE_WORKSPACE_BOTS>({
|
|
sql: `SELECT workspace_id, system_prompt, memory FROM workspace_bots WHERE bot_id = ?`,
|
|
values: [Number(bot.id)],
|
|
})
|
|
).payload || [];
|
|
|
|
const by_workspace = new Map(rows.map((row) => [Number(row.workspace_id), row]));
|
|
const admin_of = new Set(
|
|
(
|
|
(
|
|
await BunSQLite.sql<{ workspace_id: number }>({
|
|
sql: `SELECT workspace_id FROM bot_types WHERE bot_id = ? AND bot_type = 'admin'`,
|
|
values: [Number(bot.id)],
|
|
})
|
|
).payload || []
|
|
).map((row) => Number(row.workspace_id)),
|
|
);
|
|
|
|
return workspaces
|
|
.filter((workspace) => by_workspace.has(Number(workspace.id)))
|
|
.map((workspace) => {
|
|
const row = by_workspace.get(Number(workspace.id));
|
|
|
|
return {
|
|
...workspace,
|
|
workspace_system_prompt: row?.system_prompt || null,
|
|
workspace_memory: row?.memory || null,
|
|
is_admin: admin_of.has(Number(workspace.id)),
|
|
};
|
|
});
|
|
}
|