Share one crew across the install, keep user memory per user
Bots, workspaces and computers now belong to the install. Users reach workers only through bot_users (assigned by a super admin or admin) and workspace_users; the coordinator and main computer are one per install, and only the super admin sees the coordinator. Conversations are per user (bot_sessions.user_id), jobs run for the session's user, and live updates go only to who should see them. A bot's core memory is now general knowledge shared by every user it works for; what it learns about a user lives in bot_user_memories. One-off scripts move existing installs over: move-bot-memory-to-owners (run first), then share-crew. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type { BUN_SQLITE_COBBLE_BOTS, BUN_SQLITE_COBBLE_MEDIA, BUN_SQLITE_COBBLE_WORKSPACES } from "@/db/types/db";
|
||||
import grabUserBot from "../bots/grab-user-bot";
|
||||
import grabUserWorkspace from "../workspaces/grab-user-workspace";
|
||||
|
||||
type Params = {
|
||||
media_id: number | string;
|
||||
user_id: number | string;
|
||||
};
|
||||
|
||||
/**
|
||||
* A bot's or workspace's picture (private media, uploaded by whoever set
|
||||
* it) for a user who reaches that bot or workspace, or null. Bots and
|
||||
* workspaces belong to the install, so their pictures show to everyone
|
||||
* who sees them.
|
||||
*/
|
||||
export default async function grabSharedPictureMedia({ media_id, user_id }: Params) {
|
||||
const [bot, workspace] = await Promise.all([
|
||||
BunSQLite.sql<BUN_SQLITE_COBBLE_BOTS>({
|
||||
sql: `SELECT id FROM bots WHERE image_media_id = ? LIMIT 1`,
|
||||
values: [media_id],
|
||||
}).then((res) => res.payload?.[0]),
|
||||
BunSQLite.sql<BUN_SQLITE_COBBLE_WORKSPACES>({
|
||||
sql: `SELECT id FROM workspaces WHERE image_media_id = ? LIMIT 1`,
|
||||
values: [media_id],
|
||||
}).then((res) => res.payload?.[0]),
|
||||
]);
|
||||
|
||||
const allowed =
|
||||
(bot?.id && (await grabUserBot({ bot_id: bot.id, user_id }))?.id) ||
|
||||
(workspace?.id && (await grabUserWorkspace({ workspace_id: workspace.id, user_id }))?.id);
|
||||
|
||||
if (!allowed) return null;
|
||||
|
||||
const res = await BunSQLite.sql<BUN_SQLITE_COBBLE_MEDIA>({
|
||||
sql: `SELECT * FROM media WHERE id = ? LIMIT 1`,
|
||||
values: [media_id],
|
||||
});
|
||||
|
||||
return res.payload?.[0] || null;
|
||||
}
|
||||
Reference in New Issue
Block a user