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]>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
import type { ComputerWithStatus } from "@/src/types";
|
|
import parseJobJson from "@/src/bots-queue/parse-job-json";
|
|
|
|
type Params = {
|
|
workspace_id: number | string;
|
|
};
|
|
|
|
/**
|
|
* The computers linked to a workspace, with their container's state, its
|
|
* default first.
|
|
*/
|
|
export default async function grabWorkspaceComputers({
|
|
workspace_id,
|
|
}: Params): Promise<ComputerWithStatus[]> {
|
|
const res = await BunSQLite.sql<ComputerWithStatus & { metadata?: string | null }>({
|
|
sql: `SELECT c.*, co.status AS status, co.metadata AS metadata FROM computers c
|
|
JOIN workspace_computers wc ON wc.computer_id = c.id AND wc.workspace_id = ?
|
|
JOIN workspaces w ON w.id = wc.workspace_id
|
|
LEFT JOIN containers co ON co.id = c.container_id
|
|
ORDER BY c.id = w.computer_id DESC, wc.id ASC`,
|
|
values: [workspace_id],
|
|
});
|
|
|
|
return (res.payload || []).map(({ metadata, ...computer }) => {
|
|
const error = parseJobJson({ text: metadata })?.error;
|
|
|
|
return {
|
|
...computer,
|
|
error: computer.status == "failed" && typeof error == "string" ? error : null,
|
|
};
|
|
});
|
|
}
|