Compare commits

..
1 Commits
Author SHA1 Message Date
tben bf533330b1 Hold the drawer's computer preview until asked, and tell SSH computers apart
CI / check (push) Waiting to run
Release image / image (release) Waiting to run
Release image / computer-image (release) Waiting to run
The Tools section streamed a bot's computer screen the moment the drawer
opened. It now shows the same block with a line and a Preview button, and
streams only once that is clicked.

Also show the bot's memory of the viewer in the drawer's settings tab, space
the panel fields so their labels stop overlapping, and draw an SSH computer
with a server icon instead of the container's monitor.
2026-11-24 16:50:51 +01:00
18 changed files with 208 additions and 72 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cobble",
"version": "0.28.1",
"version": "0.28.2",
"module": "index.ts",
"type": "module",
"private": true,
+16 -1
View File
@@ -22,6 +22,11 @@ type Props = {
* Its height, e.g. `h-24`.
*/
className?: string;
/**
* Shows the text without letting it be edited; `onChange` is then never
* called.
*/
readOnly?: boolean;
onChange: (value: string) => void;
};
@@ -30,7 +35,16 @@ type Props = {
* under it. Loads the editor's scripts when it first shows
* (`loadAceScripts`).
*/
export default function CodeEditor({ title, content, mode, placeholder, info, className, onChange }: Props) {
export default function CodeEditor({
title,
content,
mode,
placeholder,
info,
className,
readOnly,
onChange,
}: Props) {
/**
* The editor keeps the handler it was created with; this keeps it
* calling the latest one.
@@ -50,6 +64,7 @@ export default function CodeEditor({ title, content, mode, placeholder, info, cl
content={content}
mode={mode}
placeholder={placeholder}
readOnly={readOnly}
fontSize="13px"
delay={0}
wrapperProps={{ className: twMerge("h-40", className) }}
+12 -5
View File
@@ -1,9 +1,16 @@
import { Monitor } from "lucide-react";
import computerIcon from "@/src/utils/computer-icon";
import IconTile from "./icon-tile";
/**
* A computer's avatar in lists: the monitor icon on a small tile.
* A computer's avatar in lists: its icon (`computerIcon`) on a small tile.
*/
export default function ComputerIconTile() {
return <IconTile Icon={Monitor} />;
}
export default function ComputerIconTile({
connection,
}: {
/**
* `ssh` wears a server instead of a monitor.
*/
connection?: string | null;
}) {
return <IconTile Icon={computerIcon({ connection })} />;
}
@@ -133,7 +133,7 @@ export default function RailSettingsAside({ pathname }: Props) {
computerStatusLabel({ computer }),
computerResourcesLabel({ computer }),
].join(" · ");
avatar = <ComputerIconTile />;
avatar = <ComputerIconTile connection={computer.connection} />;
}
return (
@@ -3,11 +3,12 @@ import type { APIResponseObject } from "@moduletrace/bunext/types";
import type { BotIdRequest } from "@/src/schemas/bot-schema";
/**
* A bot's core instructions and memory, for its panel.
* A bot's core instructions and memory for its panel, and what it remembers
* about the user reading it.
*/
export default async function fetchBotInstructions({ bot_id }: BotIdRequest) {
return await fetchApi<BotIdRequest, APIResponseObject<{ system_prompt: string; memory: string }>>(
`/api/admin/bots/bot-instructions`,
{ method: "POST", body: { bot_id } },
);
return await fetchApi<
BotIdRequest,
APIResponseObject<{ system_prompt: string; memory: string; user_memory: string }>
>(`/api/admin/bots/bot-instructions`, { method: "POST", body: { bot_id } });
}
@@ -17,12 +17,14 @@ type Params = {
export default function useBotInstructions({ bot_id, enabled }: Params) {
const [system_prompt, setSystemPrompt] = useState<string>();
const [memory, setMemory] = useState<string>();
const [user_memory, setUserMemory] = useState<string>();
const [error, setError] = useState<string>();
useEffect(() => {
/** Cleared on close, so the next open never shows an old copy. */
setSystemPrompt(undefined);
setMemory(undefined);
setUserMemory(undefined);
setError(undefined);
if (!enabled || !bot_id) return;
@@ -36,6 +38,7 @@ export default function useBotInstructions({ bot_id, enabled }: Params) {
if (res.success && res.singleRes) {
setSystemPrompt(res.singleRes.system_prompt);
setMemory(res.singleRes.memory);
setUserMemory(res.singleRes.user_memory);
} else {
setError(res.msg || "Couldn't load the instructions.");
}
@@ -49,5 +52,5 @@ export default function useBotInstructions({ bot_id, enabled }: Params) {
};
}, [enabled, bot_id]);
return { system_prompt, memory, error };
return { system_prompt, memory, user_memory, error };
}
@@ -13,16 +13,15 @@ function render() {
}
describe("BotComputerPreview", () => {
test("it shows the computer's live browser, view only", () => {
/**
* The block is always there, at its usual size; only the live stream
* waits for Preview, since it is a stream nobody asked for.
*/
test("it keeps the block and holds its screen until asked", () => {
const html = render();
expect(html).toContain('src="/computers/7/desktop/"');
expect(html).toContain("pointer-events-none");
});
test("a click opens it in the viewer", () => {
const html = render();
expect(html).toContain('aria-label="Open Dev box in the viewer"');
expect(html).toContain("h-[250px]");
expect(html).toContain("Preview");
expect(html).not.toContain("/computers/7/");
});
});
@@ -1,6 +1,8 @@
import { useState } from "react";
import Button from "@moduletrace/twui/layout/Button";
import Span from "@moduletrace/twui/layout/Span";
import Stack from "@moduletrace/twui/layout/Stack";
import { Maximize2 } from "lucide-react";
import { Eye, Maximize2 } from "lucide-react";
import ComputerViewFrame from "@/src/components/general/computer-view-frame";
type Props = {
@@ -14,30 +16,61 @@ type Props = {
/**
* The bot's computer live and small, in its panel's Tools tab, so the user
* sees what it is doing without leaving the conversation. The frame takes no
* pointer events, or the panel could not be scrolled past it; a click opens
* the viewer instead.
* sees what it is doing without leaving the conversation. The block is always
* there, but the screen is a live stream: it is only shown once Preview is
* clicked. The frame takes no pointer events, or the panel could not be
* scrolled past it; a click opens the viewer instead.
*/
export default function BotComputerPreview({ computer_id, name, onOpen }: Props) {
export default function BotComputerPreview({
computer_id,
name,
onOpen,
}: Props) {
const [previewing, setPreviewing] = useState(false);
return (
<Stack className="relative w-full h-44 mt-2 overflow-hidden rounded-default border border-solid border-hairline bg-sunken">
<Stack className="absolute inset-0 pointer-events-none">
<ComputerViewFrame computer_id={computer_id} name={name} mode="browser" />
</Stack>
<Button
type="button"
variant="ghost"
color="text"
title={`Open ${name} in the viewer`}
aria-label={`Open ${name} in the viewer`}
onClick={onOpen}
className="absolute inset-0 w-full h-full p-0! rounded-none! focus-visible:ring-2 focus-visible:ring-ink"
buttonContentProps={{ className: "absolute right-2 bottom-2" }}
>
<Stack className="p-1.5 rounded-default bg-paper/90 border border-solid border-hairline text-ink-secondary">
<Maximize2 size={14} aria-hidden />
<Stack className="relative w-full h-[250px] mt-2 overflow-hidden rounded-default border border-solid border-hairline bg-sunken">
{previewing ? (
<>
<Stack className="absolute inset-0 pointer-events-none">
<ComputerViewFrame
computer_id={computer_id}
name={name}
mode="browser"
/>
</Stack>
<Button
type="button"
variant="ghost"
color="text"
title={`Open ${name} in the viewer`}
aria-label={`Open ${name} in the viewer`}
onClick={onOpen}
className="absolute inset-0 w-full h-full p-0! rounded-none! focus-visible:ring-2 focus-visible:ring-ink"
buttonContentProps={{
className: "absolute right-2 bottom-2",
}}
>
<Stack className="p-1.5 rounded-default bg-paper/90 border border-solid border-hairline text-ink-secondary">
<Maximize2 size={14} aria-hidden />
</Stack>
</Button>
</>
) : (
<Stack className="absolute inset-0 gap-2! items-center justify-center px-6">
<Span className="text-[13px] leading-[18px] text-ink-secondary text-center">
{`See ${name}'s screen without opening the viewer.`}
</Span>
<Button
type="button"
title={`Preview ${name}'s screen`}
onClick={() => setPreviewing(true)}
beforeIcon={<Eye size={14} aria-hidden />}
>
Preview
</Button>
</Stack>
</Button>
)}
</Stack>
);
}
}
@@ -3,7 +3,7 @@ import Modal from "@moduletrace/twui/elements/Modal";
import H2 from "@moduletrace/twui/layout/H2";
import Span from "@moduletrace/twui/layout/Span";
import Stack from "@moduletrace/twui/layout/Stack";
import { Monitor } from "lucide-react";
import computerIcon from "@/src/utils/computer-icon";
import type { BotWithLastMessage } from "@/src/types";
import { BotComputersContext } from "../(data)/bot-computers-context";
import BotComputerOption from "./bot-computer-option";
@@ -66,6 +66,7 @@ export default function BotComputersModal({
const name = bot.name || "This bot";
const can_switch = computers.length > 1;
const Icon = computerIcon({ connection: current.connection });
const title = can_switch
? `Switch ${name}'s computer`
@@ -76,7 +77,7 @@ export default function BotComputersModal({
target={
meta_text ? (
<HeaderMetaItem
icon={Monitor}
icon={Icon}
label="Computer"
text={meta_text}
title={title}
@@ -84,7 +85,7 @@ export default function BotComputersModal({
/>
) : menu ? (
<HeaderMenuItem
icon={Monitor}
icon={Icon}
title="Computer"
hint={
menu_hint ||
@@ -96,7 +97,7 @@ export default function BotComputersModal({
/>
) : (
<HeaderIconButton
icon={Monitor}
icon={Icon}
title={title}
loading={Boolean(switching_id)}
/>
@@ -26,6 +26,7 @@ import useWorkspaceBotInstructions from "../(hooks)/use-workspace-bot-instructio
import BotMemoryForm from "./bot-memory-form";
import BotPanelTrigger from "./bot-panel-trigger";
import BotToolsTab from "./bot-tools-tab";
import BotUserMemory from "./bot-user-memory";
type Props = {
bot: BotWithLastMessage;
@@ -59,7 +60,7 @@ export default function BotPanel({ bot, workspace, open, on_open, on_close }: Pr
const can_edit = canManageCrew({ user_types: pageProps?.user_types });
const [tab, setTab] = useState<PanelTab>("settings");
const workspace_id = Number(workspace?.id) || 0;
const { system_prompt, memory, error } = useBotInstructions({
const { system_prompt, memory, user_memory, error } = useBotInstructions({
bot_id: Number(bot.id) || 0,
enabled: open && can_edit,
});
@@ -71,6 +72,7 @@ export default function BotPanel({ bot, workspace, open, on_open, on_close }: Pr
const memory_ready =
system_prompt != undefined &&
memory != undefined &&
user_memory != undefined &&
(!workspace_id || Boolean(workspace_instructions.instructions));
const loaded_error = error || workspace_instructions.error;
@@ -135,7 +137,7 @@ export default function BotPanel({ bot, workspace, open, on_open, on_close }: Pr
<TabButton title="Settings" active={tab == "settings"} onPick={() => setTab("settings")} />
<TabButton title="Tools" active={tab == "tools"} onPick={() => setTab("tools")} />
</Row>
<Stack className="grow min-h-0 overflow-y-auto gap-1! items-stretch px-4 pt-4 pb-6">
<Stack className="grow min-h-0 overflow-y-auto gap-4! items-stretch px-4 pt-4 pb-6 [&>*]:shrink-0">
{open && tab == "settings" ? (
<>
<Span className="text-[13px] leading-[18px] text-ink-secondary">
@@ -154,15 +156,19 @@ export default function BotPanel({ bot, workspace, open, on_open, on_close }: Pr
{`What ${name} keeps in mind, and can add to itself as it works.`}
</Span>
{memory_ready ? (
<BotMemoryForm
bot_id={Number(bot.id) || 0}
bot_name={name}
memory={memory || ""}
workspace_id={workspace_id || undefined}
workspace_name={workspace?.name}
workspace_memory={workspace_instructions.instructions?.memory || ""}
onCancel={on_close}
/>
<>
<BotMemoryForm
bot_id={Number(bot.id) || 0}
bot_name={name}
memory={memory || ""}
workspace_id={workspace_id || undefined}
workspace_name={workspace?.name}
workspace_memory={workspace_instructions.instructions?.memory || ""}
onCancel={on_close}
/>
<Divider className="my-2 border-hairline dark:border-hairline" />
<BotUserMemory bot_name={name} memory={user_memory || ""} />
</>
) : loaded_error ? (
<Span className="py-6 text-[13px] leading-[18px] text-ink-secondary">
{loaded_error}
@@ -0,0 +1,34 @@
import Span from "@moduletrace/twui/layout/Span";
import CodeEditor from "@/src/components/general/code-editor";
type Props = {
bot_name: string;
/**
* What the bot has saved about the user reading the panel; empty until
* it saved anything.
*/
memory: string;
};
/**
* What the bot remembers about this user alone (`bot_user_memories`), shown
* in its panel's settings tab. It shapes how the bot works with them, never
* what it does, and only the bot writes it.
*/
export default function BotUserMemory({ bot_name, memory }: Props) {
return (
<>
<Span className="text-[13px] leading-[18px] text-ink-secondary">
{`What ${bot_name} remembers about you, which only shapes how it works with you.`}
</Span>
<CodeEditor
title="About you"
content={memory || "Nothing yet."}
mode="markdown"
className="h-32"
readOnly
onChange={() => {}}
/>
</>
);
}
@@ -1,6 +1,6 @@
import { useContext } from "react";
import Button from "@moduletrace/twui/layout/Button";
import { Monitor } from "lucide-react";
import computerIcon from "@/src/utils/computer-icon";
import { BotComputersContext } from "../(data)/bot-computers-context";
import Span from "@moduletrace/twui/layout/Span";
@@ -16,6 +16,7 @@ export default function ComposerComputerButton() {
if (!computer?.id) return null;
const title = `Open ${computer.name || `computer ${computer.id}`}`;
const Icon = computerIcon({ connection: computer.connection });
return (
<Button
@@ -33,7 +34,7 @@ export default function ComposerComputerButton() {
<Span className="text-[12px] leading-4 text-ink-secondary">
Computer
</Span>
<Monitor size={14} aria-hidden />
<Icon size={14} aria-hidden />
</Button>
);
}
@@ -1,8 +1,9 @@
import { useContext } from "react";
import Button from "@moduletrace/twui/layout/Button";
import Span from "@moduletrace/twui/layout/Span";
import { Check, Monitor } from "lucide-react";
import { Check } from "lucide-react";
import { twMerge } from "tailwind-merge";
import computerIcon from "@/src/utils/computer-icon";
import { BotComputersContext } from "../(data)/bot-computers-context";
type Props = {
@@ -26,6 +27,7 @@ export default function ComputerRefChip({ computer_id }: Props) {
}
const current = computers[0]?.id == computer.id;
const Icon = computerIcon({ connection: computer.connection });
return (
<Button
@@ -45,7 +47,7 @@ export default function ComputerRefChip({ computer_id }: Props) {
: "bg-transparent hover:bg-sunken",
)}
>
<Monitor size={14} aria-hidden className="shrink-0" />
<Icon size={14} aria-hidden className="shrink-0" />
<Span className="min-w-0 truncate">{name}</Span>
{current ? <Check size={14} aria-hidden className="shrink-0" /> : null}
</Button>
@@ -40,7 +40,7 @@ export default function ComputerListRow({
return (
<SettingsListRow
avatar={<ComputerIconTile />}
avatar={<ComputerIconTile connection={computer.connection} />}
href={
linked ? `/admin/settings/computers/${computer.id}` : undefined
}
@@ -31,7 +31,7 @@ export default function ComputerOverviewGroup({ computer }: Props) {
}
>
<Row className="w-full gap-4! flex-nowrap items-center">
<ComputerIconTile />
<ComputerIconTile connection={computer.connection} />
<Stack className="grow min-w-0 gap-0!">
<Row className="gap-2! flex-nowrap items-center">
<Span className="text-sm font-bold leading-5 text-ink truncate">
+14 -5
View File
@@ -1,4 +1,5 @@
import userAuth from "@/src/functions/backend/auth/user-auth";
import grabBotUserMemory from "@/src/functions/backend/db/bots/grab-bot-user-memory";
import grabUserBot from "@/src/functions/backend/db/bots/grab-user-bot";
import { BotIdRequestSchema } from "@/src/schemas/bot-schema";
import AppError from "@/src/utils/app-error";
@@ -11,12 +12,13 @@ import type {
} from "@moduletrace/bunext/types";
/**
* A bot's core instructions and memory, for its panel in the conversation,
* which loads them when it opens (page props leave them out). For super
* admins and admins; only the super admin reaches the coordinator.
* A bot's core instructions and memory for its panel in the conversation,
* which loads them when it opens (page props leave them out), plus what it
* remembers about the user reading it. For super admins and admins; only the
* super admin reaches the coordinator.
*/
export const handler: BunextAPIRouteHandler<
APIResponseObject<{ system_prompt: string; memory: string }>
APIResponseObject<{ system_prompt: string; memory: string; user_memory: string }>
> = async ({ req, body }) => {
try {
if (req.method != "POST") {
@@ -40,7 +42,14 @@ export const handler: BunextAPIRouteHandler<
throw new AppError(`Bot not found.`);
}
return { success: true, singleRes: { system_prompt: bot.system_prompt || "", memory: bot.memory || "" } };
return {
success: true,
singleRes: {
system_prompt: bot.system_prompt || "",
memory: bot.memory || "",
user_memory: (await grabBotUserMemory({ bot_id: bot.id, user_id: user.id })) || "",
},
};
} catch (error: unknown) {
return { success: false, msg: safeErrorMessage({ error }) };
}
+11
View File
@@ -0,0 +1,11 @@
import { describe, expect, test } from "bun:test";
import { Monitor, Server } from "lucide-react";
import computerIcon from "./computer-icon";
describe("computerIcon", () => {
test("a container wears a monitor, an SSH machine a server", () => {
expect(computerIcon({ connection: "docker" })).toBe(Monitor);
expect(computerIcon({ connection: null })).toBe(Monitor);
expect(computerIcon({ connection: "ssh" })).toBe(Server);
});
});
+14
View File
@@ -0,0 +1,14 @@
import { Monitor, Server } from "lucide-react";
/**
* A computer's icon: a monitor for the sandboxed container this app makes
* (a screen and a shell of its own), a server for a remote machine reached
* over SSH, which has no screen here.
*/
export default function computerIcon({
connection,
}: {
connection?: string | null;
}) {
return connection == "ssh" ? Server : Monitor;
}