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]>
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi";
|
|
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
|
import { useEffect, useState } from "react";
|
|
import useServerEvent from "@/src/hooks/use-server-event";
|
|
import type { ChatroomSummary } from "@/src/types";
|
|
import chatroomInPlace from "@/src/utils/chatroom-in-place";
|
|
import mergeChatroom from "@/src/utils/merge-chatroom";
|
|
|
|
type Params = {
|
|
/**
|
|
* The workspace whose rooms the rail lists, or (null) those asked from
|
|
* bots' own chats.
|
|
*/
|
|
workspace_id: number | null;
|
|
};
|
|
|
|
/**
|
|
* One place's latest chatrooms for the rail: loaded by the rail itself (no
|
|
* page carries them), then kept current from `server:chatroom-updated`,
|
|
* which only adds rooms of that place. Null until the first load.
|
|
*/
|
|
export default function useRailChatrooms({ workspace_id }: Params) {
|
|
const [chatrooms, setChatrooms] = useState<ChatroomSummary[] | null>(null);
|
|
|
|
useEffect(() => {
|
|
setChatrooms(null);
|
|
|
|
fetchApi<{}, APIResponseObject<ChatroomSummary>>(
|
|
`/api/admin/chatrooms/list${workspace_id ? `?workspace_id=${workspace_id}` : ""}`,
|
|
{ method: "GET" },
|
|
)
|
|
.then((res) => {
|
|
if (res?.success) setChatrooms(res.payload || []);
|
|
})
|
|
.catch(() => {});
|
|
}, [workspace_id]);
|
|
|
|
useServerEvent({
|
|
event: "server:chatroom-updated",
|
|
onData: (room: ChatroomSummary) => {
|
|
if (!chatroomInPlace({ chatroom: room, workspace_id })) return;
|
|
|
|
setChatrooms((prev) => mergeChatroom({ chatrooms: prev || [], chatroom: room }));
|
|
},
|
|
});
|
|
|
|
return chatrooms;
|
|
}
|