Show a newly created bot in the rail at once
The rail was built from page props and only knew bots it already had, so a bot the coordinator created did not appear until a reload. create_bot and add_bot_to_workspace now push server:bot-created (BotCreatedData) to everyone who sees the bot: its rail row, the workspaces it is in, and whether it belongs in that user's own chat list. useLiveBots inserts it, after the pinned coordinator outside a workspace and only when the open workspace is one it joined. liveRelay pushes created bots too, so a bot added by another process still shows.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import { z } from "zod";
|
||||
import type { BUN_SQLITE_COBBLE_BOTS, BUN_SQLITE_COBBLE_WORKSPACES } from "@/db/types/db";
|
||||
import pushBotCreated from "@/src/bots-queue/push-bot-created";
|
||||
import addBotToWorkspace from "@/src/functions/backend/db/workspaces/add-bot-to-workspace";
|
||||
import type { HarnessTool } from "../../types";
|
||||
|
||||
@@ -74,6 +75,8 @@ export default function addBotToWorkspaceTool({
|
||||
bot_id: worker.id,
|
||||
});
|
||||
|
||||
await pushBotCreated({ bot: worker });
|
||||
|
||||
return `${worker.name} joined ${workspace.name}.`;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import { z } from "zod";
|
||||
import type { BUN_SQLITE_COBBLE_BOTS, BUN_SQLITE_COBBLE_WORKSPACES } from "@/db/types/db";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import pushBotCreated from "@/src/bots-queue/push-bot-created";
|
||||
import createBot from "@/src/functions/backend/db/bots/create-bot";
|
||||
import addBotToWorkspace from "@/src/functions/backend/db/workspaces/add-bot-to-workspace";
|
||||
import pickFreeHue from "@/src/utils/pick-free-hue";
|
||||
@@ -81,6 +82,18 @@ export default function createBotTool({
|
||||
await addBotToWorkspace({ user_id, workspace_id: target.id, bot_id });
|
||||
}
|
||||
|
||||
const created =
|
||||
(
|
||||
await BunSQLite.sql<BUN_SQLITE_COBBLE_BOTS>({
|
||||
sql: `SELECT * FROM bots WHERE id = ?`,
|
||||
values: [bot_id],
|
||||
})
|
||||
).payload?.[0] || null;
|
||||
|
||||
if (created) {
|
||||
await pushBotCreated({ bot: created });
|
||||
}
|
||||
|
||||
const where = target?.name ? ` and joins ${target.name}` : "";
|
||||
|
||||
return `${args.name} is on the crew (bot #${bot_id})${where}.${target ? "" : " It has no workspace yet: put it in one with add_bot_to_workspace, or give it a computer with assign_computer."}`;
|
||||
|
||||
Reference in New Issue
Block a user