- 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]>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
import AppError from "@/src/utils/app-error";
|
|
import grabWorkspaceComputers from "./grab-workspace-computers";
|
|
import grabUserWorkspace from "./grab-user-workspace";
|
|
|
|
type Params = {
|
|
user_id: number | string;
|
|
workspace_id: number | string;
|
|
computer_id: number | string;
|
|
};
|
|
|
|
/**
|
|
* Makes one of a workspace's computers its default, where its tasks run.
|
|
* Returns the workspace's computers, the new default first.
|
|
*/
|
|
export default async function setWorkspaceComputer({
|
|
user_id,
|
|
workspace_id,
|
|
computer_id,
|
|
}: Params) {
|
|
const workspace = await grabUserWorkspace({ workspace_id, user_id });
|
|
|
|
if (!workspace?.id) {
|
|
throw new AppError(`Workspace not found.`);
|
|
}
|
|
|
|
const linked = await grabWorkspaceComputers({ workspace_id: workspace.id });
|
|
const computer = linked.find((c) => String(c.id) == String(computer_id));
|
|
|
|
if (!computer?.id) {
|
|
throw new AppError(`That computer isn't in ${workspace.name || "this workspace"}.`);
|
|
}
|
|
|
|
await BunSQLite.sql({
|
|
sql: `UPDATE workspaces SET computer_id = ?, updated_at = ? WHERE id = ?`,
|
|
values: [computer.id, Date.now(), workspace.id],
|
|
});
|
|
|
|
return {
|
|
workspace: { ...workspace, computer_id: computer.id },
|
|
computer,
|
|
computers: [computer, ...linked.filter((c) => c.id != computer.id)],
|
|
};
|
|
}
|