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:
@@ -0,0 +1,59 @@
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import AppError from "@/src/utils/app-error";
|
||||
import assertPromptLength from "@/src/utils/assert-prompt-length";
|
||||
import grabWorkspaceBot from "./grab-workspace-bot";
|
||||
|
||||
type Params = {
|
||||
user_id: number | string;
|
||||
workspace_id: number | string;
|
||||
bot_id: number | string;
|
||||
/**
|
||||
* Only the fields given are changed: the bot's instructions and memory
|
||||
* for this workspace (markdown, whole-text replace).
|
||||
*/
|
||||
system_prompt?: string;
|
||||
memory?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Rewrites what a bot has for one workspace alone: its instructions there
|
||||
* and its memory there. The bot, the coordinator and the user all can. The
|
||||
* coordinator gets its row on first write.
|
||||
*/
|
||||
export default async function updateWorkspaceBot({
|
||||
user_id,
|
||||
workspace_id,
|
||||
bot_id,
|
||||
system_prompt,
|
||||
memory,
|
||||
}: Params) {
|
||||
assertPromptLength({ label: "Workspace instructions", text: system_prompt });
|
||||
assertPromptLength({ label: "Workspace memory", text: memory });
|
||||
|
||||
const found = await grabWorkspaceBot({ workspace_id, bot_id, user_id });
|
||||
|
||||
if (!found) {
|
||||
throw new AppError(`That bot isn't in this workspace.`);
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
await BunSQLite.sql({
|
||||
sql: `INSERT OR IGNORE INTO workspace_bots (created_at, updated_at, workspace_id, bot_id) VALUES (?, ?, ?, ?)`,
|
||||
values: [now, now, found.workspace.id!, found.bot.id!],
|
||||
});
|
||||
|
||||
if (system_prompt !== undefined) {
|
||||
await BunSQLite.sql({
|
||||
sql: `UPDATE workspace_bots SET system_prompt = ?, updated_at = ? WHERE workspace_id = ? AND bot_id = ?`,
|
||||
values: [system_prompt, now, found.workspace.id!, found.bot.id!],
|
||||
});
|
||||
}
|
||||
|
||||
if (memory !== undefined) {
|
||||
await BunSQLite.sql({
|
||||
sql: `UPDATE workspace_bots SET memory = ?, updated_at = ? WHERE workspace_id = ? AND bot_id = ?`,
|
||||
values: [memory, now, found.workspace.id!, found.bot.id!],
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user