Name the workspace in a bot's task status line

A task running in a workspace shows "Working on a task in <name>
workspace", so the bot's own chat and the main rail say where the work
is. Outside a workspace it stays "Working on a task".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-27 19:22:25 +01:00
co-authored by Claude Opus 5.5
parent 864dcce30a
commit 96d3227bd0
5 changed files with 74 additions and 11 deletions
@@ -1,6 +1,7 @@
import BunSQLite from "@moduletrace/bun-sqlite";
import type { BotFace } from "@/src/dict/bot-dict";
import { BotReplyJobTitle, BotTaskStatusLine } from "@/src/dict/bot-queue-dict";
import { BotReplyJobTitle } from "@/src/dict/bot-queue-dict";
import taskStatusLine from "@/src/utils/task-status-line";
type Params = {
bot_id: number | string;
@@ -13,22 +14,29 @@ type Params = {
/**
* The face a bot should show one user while other jobs for them are
* still running: thinking while a reply runs (it's short, and its chat
* needs the row), else working on a task. Null when none is running.
* needs the row), else working on a task (in its workspace, if it runs in
* one). Null when none is running.
*/
export default async function grabRunningBotJobFace({
bot_id,
user_id,
}: Params): Promise<{ face: BotFace; status_line: string } | null> {
const kinds = (
await BunSQLite.sql<{ kind: string }>({
sql: `SELECT DISTINCT kind FROM bots_queue WHERE bot_id = ? AND status = 'processing'
AND session_id IN (SELECT id FROM bot_sessions WHERE user_id = ?)`,
const jobs = (
await BunSQLite.sql<{ kind: string; workspace_name: string | null }>({
sql: `SELECT q.kind, w.name AS workspace_name FROM bots_queue q
LEFT JOIN workspaces w ON w.id = q.workspace_id
WHERE q.bot_id = ? AND q.status = 'processing'
AND q.session_id IN (SELECT id FROM bot_sessions WHERE user_id = ?)
ORDER BY q.id`,
values: [bot_id, user_id],
})
).payload?.map((row) => row.kind) || [];
).payload || [];
if (kinds.includes("reply")) return { face: "working", status_line: BotReplyJobTitle };
if (kinds.includes("task")) return { face: "working", status_line: BotTaskStatusLine };
if (jobs.some((job) => job.kind == "reply")) return { face: "working", status_line: BotReplyJobTitle };
const task = jobs.find((job) => job.kind == "task");
if (task) return { face: "working", status_line: taskStatusLine({ workspace_name: task.workspace_name }) };
return null;
}