Add workspaces, conversation sessions, app-managed computers and pictures

- Rail: Add icon with stacked form modals (bot, workspace, computer),
  coordinator, recent bots with "See all bots", Workspaces section, and
  a workspace mode listing only its crew
- Workspaces: page for context, bots (per-workspace instructions and
  memory), computers (default, link, unlink), models and delete;
  conversations scoped per bot per workspace
- Sessions: conversations split into searchable, reopenable sessions
  with carry-over summaries; sessions and new-session header icons
- Computers: created and provisioned over the docker socket, home dir
  kept at DATA_DIR/computers/<id> after delete; super admins only
- Models: workspace settings win over a bot's own, then the defaults
- Pictures for bots and workspaces; bots editable from the header
- Coordinator tools: update_workspace, set_bot_workspace_instructions

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-19 08:39:33 +01:00
co-authored by Claude Opus 5.5
parent 56daf0c462
commit 0ce61cdb49
223 changed files with 8166 additions and 585 deletions
@@ -1,10 +1,13 @@
import BunSQLite from "@moduletrace/bun-sqlite";
import type {
BUN_SQLITE_COBBLE_COMPUTERS,
BUN_SQLITE_COBBLE_CONTAINERS,
BunSQLiteTables,
} from "@/db/types/db";
import { MainComputerName } from "@/src/dict/computer-dict";
import ensureMainComputerContainer from "./ensure-main-computer-container";
import grabEnv from "../envs/grab-env";
import createComputer from "./create-computer";
import provisionComputer from "./provision-computer";
type Params = {
user_id: number | string;
@@ -13,30 +16,26 @@ type Params = {
* access to the main computer.
*/
coordinator_id: number | string;
/**
* Wait for a container being set up (a CLI script, which would
* otherwise exit first).
*/
wait?: boolean;
};
/**
* Returns the id of the user's main computer, recording it (and its
* container) first if missing, and makes sure the coordinator has access
* to it. Safe to call on every visit.
* Returns the id of the user's main computer, creating it first if
* missing (`createComputer`, which sets its container up in the
* background), and makes sure the coordinator has access to it. A main
* computer recorded before the app managed containers (no docker id, no
* `MAIN_COMPUTER_URL`) gets its container set up now. Safe to call on
* every visit.
*/
export default async function ensureMainComputer({
user_id,
coordinator_id,
wait,
}: Params) {
const computer_id = await grabOrCreateMainComputer({ user_id });
await BunSQLite.sql({
sql: `INSERT OR IGNORE INTO bot_computers (bot_id, computer_id, created_at, updated_at) VALUES (?, ?, ?, ?)`,
values: [coordinator_id, computer_id, Date.now(), Date.now()],
});
return computer_id;
}
async function grabOrCreateMainComputer({
user_id,
}: Pick<Params, "user_id">) {
const existing = (
await BunSQLite.select<
BUN_SQLITE_COBBLE_COMPUTERS,
@@ -54,32 +53,39 @@ async function grabOrCreateMainComputer({
})
).payload?.[0];
if (existing?.id) {
return existing.id;
let computer_id = existing?.id ? Number(existing.id) : 0;
let provisioning: Promise<void> = Promise.resolve();
if (!computer_id) {
const created = await createComputer({ user_id, name: MainComputerName, kind: "main" });
computer_id = created.computer_id;
provisioning = created.provisioning;
} else if (await needsContainer({ container_id: existing?.container_id })) {
provisioning = provisionComputer({ computer_id });
}
const container_id = await ensureMainComputerContainer();
const res = await BunSQLite.insert<
BUN_SQLITE_COBBLE_COMPUTERS,
(typeof BunSQLiteTables)[number]
>({
table: "computers",
data: [
{
user_id: Number(user_id),
container_id: Number(container_id),
name: MainComputerName,
kind: "main",
},
],
await BunSQLite.sql({
sql: `INSERT OR IGNORE INTO bot_computers (bot_id, computer_id, created_at, updated_at) VALUES (?, ?, ?, ?)`,
values: [coordinator_id, computer_id, Date.now(), Date.now()],
});
const computer_id = res.singleRes?.id || res.postInsertReturn?.insertId;
if (!res.success || !computer_id) {
throw new Error(`Couldn't create the main computer: ${res.msg}`);
}
if (wait) await provisioning;
return computer_id;
}
async function needsContainer({ container_id }: { container_id?: number | "" }) {
if ((await grabEnv({ key: "MAIN_COMPUTER_URL" }))?.trim()) return false;
const container = container_id
? (
await BunSQLite.sql<BUN_SQLITE_COBBLE_CONTAINERS>({
sql: `SELECT docker_id, status FROM containers WHERE id = ? LIMIT 1`,
values: [container_id],
})
).payload?.[0]
: null;
return Boolean(container && !container.docker_id && container.status == "unknown");
}