Give every user their own bot face
A bot's face and status line live in bot_user_faces, one row per bot and user, set by jobs for the user whose conversation they're in. Needs-you and working only show to that user; every bot read overlays the viewer's face (botFaceSql) and pushes go to the user a face change is for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { BUN_SQLITE_COBBLE_BOTS } from "@/db/types/db";
|
||||
import type { BotWithFace } from "@/src/types";
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import chatBotsSql from "@/src/utils/crew-access/chat-bots-sql";
|
||||
import botFaceSql from "@/src/utils/bot-face-sql";
|
||||
import grabCrewRole from "../access/grab-crew-role";
|
||||
|
||||
type Params = {
|
||||
@@ -9,23 +10,26 @@ type Params = {
|
||||
};
|
||||
|
||||
/**
|
||||
* A bot only if the user reaches it somewhere: in its own chat
|
||||
* (`chatBotsSql`) or in a workspace they're in. Super admins and admins
|
||||
* reach every worker; only the super admin reaches the coordinator.
|
||||
* A bot, with the user's own face (`botFaceSql`), only if the user
|
||||
* reaches it somewhere: in its own chat (`chatBotsSql`) or in a workspace
|
||||
* they're in. Super admins and admins reach every worker; only the super
|
||||
* admin reaches the coordinator.
|
||||
*/
|
||||
export default async function grabUserBot({
|
||||
bot_id,
|
||||
user_id,
|
||||
}: Params): Promise<BUN_SQLITE_COBBLE_BOTS | null> {
|
||||
}: Params): Promise<BotWithFace | null> {
|
||||
const access = chatBotsSql({ role: await grabCrewRole({ user_id }), user_id });
|
||||
|
||||
const res = await BunSQLite.sql<BUN_SQLITE_COBBLE_BOTS>({
|
||||
sql: `SELECT b.* FROM bots b WHERE b.id = ? AND (${access.sql} OR (b.kind != 'coordinator' AND b.id IN (
|
||||
const face = botFaceSql({ user_id });
|
||||
|
||||
const res = await BunSQLite.sql<BotWithFace>({
|
||||
sql: `SELECT b.*, ${face.sql} FROM bots b WHERE b.id = ? AND (${access.sql} OR (b.kind != 'coordinator' AND b.id IN (
|
||||
SELECT wb.bot_id FROM workspace_bots wb
|
||||
JOIN workspace_users wu ON wu.workspace_id = wb.workspace_id AND wu.user_id = ?
|
||||
JOIN workspaces w ON w.id = wb.workspace_id AND w.archived = 0
|
||||
))) LIMIT 1`,
|
||||
values: [bot_id, ...access.values, user_id],
|
||||
values: [...face.values, bot_id, ...access.values, user_id],
|
||||
});
|
||||
|
||||
return res.payload?.[0] || null;
|
||||
|
||||
Reference in New Issue
Block a user