Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

bots: announce a config edit on the fleet feed (#244)

tournierjca4e7928f854a
diff --git a/src/web/api/bots.test.ts b/src/web/api/bots.test.ts
index fb007f41..b5feb96f 100644
--- a/src/web/api/bots.test.ts
+++ b/src/web/api/bots.test.ts
@@ -6,7 +6,7 @@ import { getDefaultConfig } from '../../utils/config.js';
import { BotManager } from '../../bots/bot-manager.js';
import { BotStore } from '../../bots/store.js';
import { PERMISSION_TIERS } from '../../bots/permission-tiers.js';
-import app, { setBotManager } from './bots.js';
+import app, { registerRosterClient, setBotManager } from './bots.js';
/**
* Web cockpit API — handlers tested directly via the module's own Hono app
@@ -52,6 +52,10 @@ afterEach(() => {
const jreq = (res: Response) => res.json() as Promise<any>;
+/** What a fleet-feed client receives: the event name, and the roster it carries. */
+type RosterBody = { bots: Array<Record<string, unknown>>; queue?: Record<string, number> };
+type RosterFeed = Array<{ event: string; data: RosterBody }>;
+
describe('web bots API — cockpit', () => {
it('GET tiers returns the executable tier catalog', async () => {
const res = await app.request('/api/bots/tiers');
@@ -205,6 +209,46 @@ describe('web bots API — deliverables folder (where results land)', () => {
expect(typeof root.exists).toBe('boolean');
expect((await app.request('/api/bots/ghost/folder')).status).toBe(404);
});
+ it('a config edit the roster shows is announced — a client keeps showing the old value without it', async () => {
+ store.create({ id: 'quiet', name: 'Quiet' });
+ const seen: RosterFeed = [];
+ const unsubscribe = registerRosterClient({ send: (event, data) => seen.push({ event, data: data as RosterBody }) });
+
+ try {
+ await app.request('/api/bots/quiet', {
+ method: 'PATCH',
+ body: JSON.stringify({ enabled: false }),
+ headers: { 'Content-Type': 'application/json' },
+ });
+
+ // The summary carries the flag, not the description: the roster is what a drawer draws, and
+ // the description belongs to the bot's own page.
+ const roster = seen.filter((e) => e.event === 'bot_roster').at(-1);
+ const edited = roster?.data.bots.find((b) => b.id === 'quiet');
+ expect(edited?.enabled).toBe(false);
+ } finally {
+ unsubscribe();
+ }
+ });
+
+ it('a rejected edit is not announced — no phantom refresh on an unknown bot', async () => {
+ const seen: RosterFeed = [];
+ const unsubscribe = registerRosterClient({ send: (event, data) => seen.push({ event, data: data as RosterBody }) });
+
+ try {
+ const res = await app.request('/api/bots/ghost', {
+ method: 'PATCH',
+ body: JSON.stringify({ enabled: false }),
+ headers: { 'Content-Type': 'application/json' },
+ });
+ // The handler answers 400 for an unknown id, the same as the other malformed requests.
+ expect(res.status).toBe(400);
+ expect(seen.filter((e) => e.event === 'bot_roster')).toHaveLength(0);
+ } finally {
+ unsubscribe();
+ }
+ });
+
});
describe('web bots API — avatars', () => {
diff --git a/src/web/api/bots.ts b/src/web/api/bots.ts
index 3eda386c..c637d488 100644
--- a/src/web/api/bots.ts
+++ b/src/web/api/bots.ts
@@ -73,6 +73,17 @@ app.post('/api/bots', async (c: any) => {
/** Open fleet-feed clients — roster mutations (add crew, promote, delete) push fresh snapshots. */
const rosterSseClients = new Set<{ send: (event: string, data: unknown) => void }>();
+/**
+ * Subscribes a client to the fleet feed, and returns its unsubscribe.
+ *
+ * Exported so a test can stand where a browser tab stands: the point of the broadcast below is that
+ * *someone else's* screen updates, which no assertion on the PATCH response can show.
+ */
+export function registerRosterClient(client: { send: (event: string, data: unknown) => void }): () => void {
+ rosterSseClients.add(client);
+ return () => { rosterSseClients.delete(client); };
+}
+
function broadcastRoster(): void {
if (!botManager) return;
for (const client of rosterSseClients) {
@@ -228,6 +239,10 @@ app.patch('/api/bots/:id', async (c: any) => {
if (patch.retention !== undefined) m.retention = patch.retention;
});
botManager.invalidateRuntime(id);
+ // A config edit is roster news: the name, the description, the model, the enabled flag and the
+ // autonomy limits all travel in the summaries. Without this, an open drawer kept the old name
+ // until some unrelated roster change happened — the edit looked like it had not been applied.
+ broadcastRoster();
return c.json({ bot: updated });
} catch (err: any) {
return c.json({ error: err?.message ?? 'Failed to update bot' }, 400);