Let workers ask each other through the coordinator in chatrooms
A worker asks for another bot's help with ask_crew. The coordinator reads the request, asks the right bot (in a workspace, only its members), and sends the answer back into the asking bot's conversation, waking it. Each exchange is kept as a read-only chatroom: listed in the main rail after the workspaces, or in the workspace's rail for requests made there, with live status rows for each bot while it's open and a Stop button. Room sessions are hidden from every conversation list, other bots' words reach the model fenced as data, and turns, nesting and open rooms are capped. Closed rooms are pruned after a retention period and past a cap per place (Settings > General). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -8,6 +8,7 @@ import type { BunextPageServerFn } from "@moduletrace/bunext/types";
|
||||
import grabRunLimitsOverview from "@/src/functions/backend/db/app-settings/grab-run-limits";
|
||||
import grabSkillLimitsOverview from "@/src/functions/backend/db/app-settings/grab-skill-limits";
|
||||
import grabHookCallRetentionOverview from "@/src/functions/backend/db/app-settings/grab-hook-events-keep-days";
|
||||
import grabChatroomRetentionOverview from "@/src/functions/backend/db/app-settings/grab-chatroom-retention";
|
||||
import grabSessionLengthOverview from "@/src/functions/backend/db/app-settings/grab-bot-session-max-messages";
|
||||
import grabStorageQuotaOverview from "@/src/functions/backend/db/app-settings/grab-storage-quota-overview";
|
||||
import { grabSystemPromptAppendOverview } from "@/src/functions/backend/db/app-settings/grab-system-prompt-append";
|
||||
@@ -52,6 +53,7 @@ export default async function grabSettingsServerProps({ req }: Params) {
|
||||
run_limits: await grabRunLimitsOverview().catch(() => null),
|
||||
skill_limits: await grabSkillLimitsOverview().catch(() => null),
|
||||
hook_call_retention: await grabHookCallRetentionOverview().catch(() => null),
|
||||
chatroom_retention: await grabChatroomRetentionOverview().catch(() => null),
|
||||
session_length: await grabSessionLengthOverview().catch(() => null),
|
||||
running_version: runningVersion({ env: process.env }),
|
||||
},
|
||||
|
||||
@@ -17,6 +17,12 @@ type Props = {
|
||||
* Controls at the end of the pane header, e.g. a settings link.
|
||||
*/
|
||||
action?: ReactNode;
|
||||
/**
|
||||
* Leave out the breadcrumb trail: inside a workspace it would name the
|
||||
* workspace by its id, and the workspace's rail already says where the
|
||||
* page is.
|
||||
*/
|
||||
no_trail?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -30,6 +36,7 @@ export default function SettingsShell({
|
||||
children,
|
||||
wide,
|
||||
action,
|
||||
no_trail,
|
||||
}: Props) {
|
||||
const { pageProps } = useContext(AppContext);
|
||||
|
||||
@@ -52,10 +59,14 @@ export default function SettingsShell({
|
||||
* address would say the id of a record, or a slug that
|
||||
* differs from the name the page shows.
|
||||
*/}
|
||||
<AdminBreadcrumbs
|
||||
pathname={pageProps?.url?.pathname}
|
||||
title={title}
|
||||
/>
|
||||
{no_trail ? (
|
||||
<Stack className="w-full shrink-0 pt-5" />
|
||||
) : (
|
||||
<AdminBreadcrumbs
|
||||
pathname={pageProps?.url?.pathname}
|
||||
title={title}
|
||||
/>
|
||||
)}
|
||||
{children}
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
import { useState } from "react";
|
||||
import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi";
|
||||
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
||||
import Form from "@moduletrace/twui/form/Form";
|
||||
import Input from "@moduletrace/twui/form/Input";
|
||||
import type { ChatroomRetentionOverview } from "@/src/types";
|
||||
import SettingsSaveBar from "../../(partials)/settings-save-bar";
|
||||
|
||||
type Props = {
|
||||
retention?: ChatroomRetentionOverview | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* How many days closed chatrooms are kept and how many rooms one place
|
||||
* keeps, saved together without a reload. Zero puts a default back.
|
||||
*/
|
||||
export default function ChatroomRetentionForm({ retention }: Props) {
|
||||
const [overview, setOverview] = useState(retention || undefined);
|
||||
const [dirty, setDirty] = useState(false);
|
||||
const [keep_days, setKeepDays] = useState(String(retention?.keep_days ?? ""));
|
||||
const [max_per_place, setMaxPerPlace] = useState(String(retention?.max_per_place ?? ""));
|
||||
/**
|
||||
* The inputs only read `defaultValue` when they mount, so discarding or
|
||||
* saving remounts them with the saved numbers.
|
||||
*/
|
||||
const [form_key, setFormKey] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [status, setStatus] = useState<{
|
||||
msg?: string;
|
||||
error?: boolean;
|
||||
success?: boolean;
|
||||
}>();
|
||||
|
||||
const save = async () => {
|
||||
if (
|
||||
!window.confirm(
|
||||
"Save how long chatrooms are kept? Closed rooms past either limit are deleted, the oldest first.",
|
||||
)
|
||||
)
|
||||
return;
|
||||
|
||||
setLoading(true);
|
||||
setStatus(undefined);
|
||||
|
||||
const res = await fetchApi<{}, APIResponseObject<ChatroomRetentionOverview>>(
|
||||
"/api/admin/settings/chatroom-retention",
|
||||
{
|
||||
method: "POST",
|
||||
body: { keep_days: Number(keep_days) || 0, max_per_place: Number(max_per_place) || 0 },
|
||||
},
|
||||
).catch(() => null);
|
||||
|
||||
setLoading(false);
|
||||
|
||||
if (!res?.success || !res.singleRes) {
|
||||
setStatus({ error: true, msg: res?.msg || `Couldn't save it.` });
|
||||
return;
|
||||
}
|
||||
|
||||
setOverview(res.singleRes);
|
||||
setKeepDays(String(res.singleRes.keep_days));
|
||||
setMaxPerPlace(String(res.singleRes.max_per_place));
|
||||
setFormKey((key) => key + 1);
|
||||
setDirty(false);
|
||||
setStatus({
|
||||
success: true,
|
||||
msg: `Saved: closed chatrooms are kept for ${res.singleRes.keep_days} days, ${res.singleRes.max_per_place} rooms per place.`,
|
||||
});
|
||||
};
|
||||
|
||||
const discard = () => {
|
||||
setKeepDays(String(overview?.keep_days ?? ""));
|
||||
setMaxPerPlace(String(overview?.max_per_place ?? ""));
|
||||
setFormKey((key) => key + 1);
|
||||
setDirty(false);
|
||||
setStatus(undefined);
|
||||
};
|
||||
|
||||
return (
|
||||
<Form
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
save().catch(() => {});
|
||||
}}
|
||||
className="w-full gap-3! items-stretch"
|
||||
>
|
||||
<Input
|
||||
key={`keep-${form_key}`}
|
||||
label="Keep closed chatrooms for"
|
||||
type="number"
|
||||
min={0}
|
||||
max={overview?.max_days}
|
||||
step={1}
|
||||
numberText
|
||||
rawNumber
|
||||
defaultValue={keep_days}
|
||||
onChange={(event) => {
|
||||
setKeepDays(event.target.value);
|
||||
setDirty(true);
|
||||
setStatus(undefined);
|
||||
}}
|
||||
suffix="days"
|
||||
info={`Older closed rooms are deleted once a day. 0 uses the default (${overview?.default_days ?? ""}).`}
|
||||
/>
|
||||
<Input
|
||||
key={`max-${form_key}`}
|
||||
label="Most chatrooms per place"
|
||||
type="number"
|
||||
min={0}
|
||||
max={overview?.max_per_place_ceiling}
|
||||
step={1}
|
||||
numberText
|
||||
rawNumber
|
||||
defaultValue={max_per_place}
|
||||
onChange={(event) => {
|
||||
setMaxPerPlace(event.target.value);
|
||||
setDirty(true);
|
||||
setStatus(undefined);
|
||||
}}
|
||||
suffix="rooms"
|
||||
info={`Each workspace, and bots' own chats, keeps at most this many rooms; past it the oldest closed ones are deleted. 0 uses the default (${overview?.default_per_place ?? ""}).`}
|
||||
/>
|
||||
<SettingsSaveBar
|
||||
dirty={dirty}
|
||||
loading={loading}
|
||||
status={status}
|
||||
save_label="Save"
|
||||
onDiscard={discard}
|
||||
/>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useContext } from "react";
|
||||
import { AppContext } from "@/src/pages/__root";
|
||||
import isPassThroughUser from "@/src/utils/rbac/is-pass-through-user";
|
||||
import SettingsGroup from "../../(partials)/settings-group";
|
||||
import ChatroomRetentionForm from "../(partials)/chatroom-retention-form";
|
||||
|
||||
/**
|
||||
* How long closed chatrooms are kept and how many one place keeps. Only the
|
||||
* super admin sees it, since it changes every user's rooms.
|
||||
*/
|
||||
export default function ChatroomRetentionSection() {
|
||||
const { pageProps } = useContext(AppContext);
|
||||
|
||||
if (!isPassThroughUser({ user_types: pageProps?.user_types })) return null;
|
||||
|
||||
return (
|
||||
<SettingsGroup
|
||||
title="Chatrooms"
|
||||
description="Chatrooms are records of bots asking each other through the coordinator. Closed ones are deleted after a while, and each workspace (and bots' own chats) keeps only so many; open rooms are never deleted. What a room answered stays in the asking bot's conversation."
|
||||
id="chatrooms"
|
||||
>
|
||||
<ChatroomRetentionForm retention={pageProps?.chatroom_retention} />
|
||||
</SettingsGroup>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import AppearanceSection from "./(sections)/appearance-section";
|
||||
import ChatroomRetentionSection from "./(sections)/chatroom-retention-section";
|
||||
import HookCallRetentionSection from "./(sections)/hook-call-retention-section";
|
||||
import InstallIconSection from "./(sections)/install-icon-section";
|
||||
import InstallNameSection from "./(sections)/install-name-section";
|
||||
@@ -27,6 +28,7 @@ export default function AdminSettingsGeneralPage() {
|
||||
<SessionLengthSection />
|
||||
<SkillLimitsSection />
|
||||
<HookCallRetentionSection />
|
||||
<ChatroomRetentionSection />
|
||||
<StorageSection />
|
||||
<VersionSection />
|
||||
</SettingsShell>
|
||||
|
||||
Reference in New Issue
Block a user