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:
@@ -1,10 +1,12 @@
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import parseJobJson from "@/src/bots-queue/parse-job-json";
|
||||
import type { ComputerWithStatus } from "@/src/types";
|
||||
import computersSql from "@/src/utils/crew-access/computers-sql";
|
||||
import grabCrewRole from "../access/grab-crew-role";
|
||||
|
||||
type Params = {
|
||||
/**
|
||||
* Every computer of this owner, main first.
|
||||
* Every computer this user sees (`computersSql`), main first.
|
||||
*/
|
||||
user_id?: number | string;
|
||||
/**
|
||||
@@ -22,14 +24,18 @@ export default async function grabUserComputers({
|
||||
}: Params): Promise<ComputerWithStatus[]> {
|
||||
if (!user_id && !computer_id) return [];
|
||||
|
||||
const access = computer_id
|
||||
? { sql: `c.id = ?`, values: [Number(computer_id)] }
|
||||
: computersSql({ role: await grabCrewRole({ user_id: user_id! }), user_id: user_id! });
|
||||
|
||||
const rows =
|
||||
(
|
||||
await BunSQLite.sql<ComputerWithStatus & { metadata?: string | null }>({
|
||||
sql: `SELECT c.*, co.status AS status, co.metadata AS metadata FROM computers c
|
||||
LEFT JOIN containers co ON co.id = c.container_id
|
||||
WHERE ${computer_id ? `c.id = ?` : `c.user_id = ?`}
|
||||
WHERE ${access.sql}
|
||||
ORDER BY c.kind = 'main' DESC, c.id ASC`,
|
||||
values: [computer_id || user_id!],
|
||||
values: access.values,
|
||||
})
|
||||
).payload || [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user