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]>
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { Database } from "bun:sqlite";
|
|
import { describe, expect, test } from "bun:test";
|
|
import pruneChatroomsSql from "./prune-chatrooms-sql";
|
|
|
|
const DAY = 24 * 60 * 60 * 1000;
|
|
const now = 100 * DAY;
|
|
|
|
function seed() {
|
|
const db = new Database(":memory:");
|
|
|
|
db.run(`CREATE TABLE chatrooms (id INTEGER PRIMARY KEY, workspace_id INTEGER, parent_chatroom_id INTEGER,
|
|
status TEXT, created_at INTEGER, last_activity_at INTEGER, closed_at INTEGER)`);
|
|
|
|
const add = (id: number, workspace_id: number | null, status: string, days_ago: number, parent: number | null = null) =>
|
|
db.run(`INSERT INTO chatrooms VALUES (?, ?, ?, ?, ?, ?, ?)`, [
|
|
id,
|
|
workspace_id,
|
|
parent,
|
|
status,
|
|
now - days_ago * DAY,
|
|
now - days_ago * DAY,
|
|
status == "open" ? null : now - days_ago * DAY,
|
|
]);
|
|
|
|
return { db, add };
|
|
}
|
|
|
|
function pruned({ db, ...params }: { db: Database } & Parameters<typeof pruneChatroomsSql>[0]) {
|
|
const { sql, values } = pruneChatroomsSql(params);
|
|
|
|
return (db.query(sql).all(...values) as { id: number }[]).map((row) => row.id).sort((a, b) => a - b);
|
|
}
|
|
|
|
describe("pruneChatroomsSql", () => {
|
|
test("closed rooms past the cutoff go; open ones never do", () => {
|
|
const { db, add } = seed();
|
|
|
|
add(1, null, "answered", 40);
|
|
add(2, null, "open", 40);
|
|
add(3, null, "failed", 5);
|
|
|
|
expect(pruned({ db, cutoff: now - 30 * DAY, max_per_place: 100 })).toEqual([1]);
|
|
});
|
|
|
|
test("past the cap, the oldest closed rooms of that place go, counted per place", () => {
|
|
const { db, add } = seed();
|
|
|
|
add(1, null, "answered", 4);
|
|
add(2, null, "open", 3);
|
|
add(3, null, "answered", 2);
|
|
add(4, null, "answered", 1);
|
|
add(5, 9, "answered", 9);
|
|
add(6, 9, "answered", 8);
|
|
|
|
expect(pruned({ db, cutoff: 0, max_per_place: 2 })).toEqual([1]);
|
|
expect(pruned({ db, cutoff: 0, max_per_place: 2, workspace_id: 9 })).toEqual([]);
|
|
expect(pruned({ db, cutoff: 0, max_per_place: 1, workspace_id: 9 })).toEqual([5]);
|
|
});
|
|
|
|
test("a room an open room was asked from stays", () => {
|
|
const { db, add } = seed();
|
|
|
|
add(1, null, "answered", 40);
|
|
add(2, null, "open", 1, 1);
|
|
|
|
expect(pruned({ db, cutoff: now - 30 * DAY, max_per_place: 100 })).toEqual([]);
|
|
});
|
|
});
|