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,71 @@
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type { BUN_SQLITE_COBBLE_BOT_SESSIONS } from "@/db/types/db";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import { PreviousSessionNote, SessionSummaryPrompt } from "@/src/data/harness-prompts";
|
||||
import grabBotMessages from "@/src/functions/backend/db/bots/grab-bot-messages";
|
||||
import generateText from "@/src/harness/text/generate-text";
|
||||
|
||||
type Params = {
|
||||
session_id: number | string;
|
||||
bot_id: number | string;
|
||||
workspace_id?: number | string | null;
|
||||
signal?: AbortSignal;
|
||||
};
|
||||
|
||||
/**
|
||||
* The previous session's summary for a session's prompt (markdown), or ""
|
||||
* when it doesn't carry on from one. The summary is written the first
|
||||
* time it's needed and kept on that session.
|
||||
*/
|
||||
export default async function grabSessionCarryOver({
|
||||
session_id,
|
||||
bot_id,
|
||||
workspace_id,
|
||||
signal,
|
||||
}: Params) {
|
||||
const previous = (
|
||||
await BunSQLite.sql<BUN_SQLITE_COBBLE_BOT_SESSIONS>({
|
||||
sql: `SELECT p.* FROM bot_sessions s JOIN bot_sessions p ON p.id = s.previous_session_id
|
||||
WHERE s.id = ? AND p.bot_id = s.bot_id LIMIT 1`,
|
||||
values: [session_id],
|
||||
})
|
||||
).payload?.[0];
|
||||
|
||||
if (!previous?.id) return "";
|
||||
|
||||
if (previous.summary?.trim()) {
|
||||
return `${PreviousSessionNote}\n\n${previous.summary.trim()}`;
|
||||
}
|
||||
|
||||
const messages = await grabBotMessages({
|
||||
session_id: previous.id,
|
||||
limit: AppData.BotSessionSummaryMessages,
|
||||
});
|
||||
|
||||
if (!messages.length) return "";
|
||||
|
||||
const transcript = messages
|
||||
.map((message) => `${message.author == "user" ? "User" : "You"}: ${message.text || "(files only)"}`)
|
||||
.join("\n\n");
|
||||
|
||||
const result = await generateText({
|
||||
messages: [
|
||||
{ role: "system", content: SessionSummaryPrompt },
|
||||
{ role: "user", content: transcript },
|
||||
],
|
||||
bot_id,
|
||||
workspace_id,
|
||||
signal,
|
||||
});
|
||||
|
||||
const summary = (result.text || "").trim().slice(0, AppData.BotSessionSummaryMaxChars);
|
||||
|
||||
if (!summary) return "";
|
||||
|
||||
await BunSQLite.sql({
|
||||
sql: `UPDATE bot_sessions SET summary = ?, updated_at = ? WHERE id = ?`,
|
||||
values: [summary, Date.now(), previous.id],
|
||||
});
|
||||
|
||||
return `${PreviousSessionNote}\n\n${summary}`;
|
||||
}
|
||||
Reference in New Issue
Block a user