Give every user their own bot face
A bot's face and status line live in bot_user_faces, one row per bot and user, set by jobs for the user whose conversation they're in. Needs-you and working only show to that user; every bot read overlays the viewer's face (botFaceSql) and pushes go to the user a face change is for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -14,6 +14,7 @@ import BotJobFatalError from "./bot-job-fatal-error";
|
||||
import describeJobStep from "./describe-job-step";
|
||||
import pushToSessionUser from "./push-to-session-user";
|
||||
import pushBotNotice from "./push-bot-notice";
|
||||
import grabJobUserId from "@/src/functions/backend/db/bots-queue/grab-job-user-id";
|
||||
import runBotJob from "./run-bot-job";
|
||||
import parseJobJson from "./parse-job-json";
|
||||
import type { BotJobUpdateData } from "@/src/types";
|
||||
@@ -58,6 +59,17 @@ export default async function processBotJob({
|
||||
|
||||
const job_id = job.id;
|
||||
const bot_id = job.bot_id;
|
||||
|
||||
/**
|
||||
* Its face changes only for the user it works for.
|
||||
*/
|
||||
const user_id = await grabJobUserId({ job }).catch(() => null);
|
||||
|
||||
const setFace = async (face: Omit<Parameters<typeof setBotFace>[0], "bot_id" | "user_id">) => {
|
||||
if (!user_id) return;
|
||||
|
||||
await pushBotNotice({ bot_id, bot: await setBotFace({ bot_id, user_id, ...face }) });
|
||||
};
|
||||
const controller = new AbortController();
|
||||
|
||||
const update: BotJobContext["update"] = async (params) => {
|
||||
@@ -106,13 +118,9 @@ export default async function processBotJob({
|
||||
* its computer.
|
||||
*/
|
||||
const run = async () => {
|
||||
await pushBotNotice({
|
||||
bot_id,
|
||||
bot: await setBotFace({
|
||||
bot_id,
|
||||
face: "working",
|
||||
status_line: job.kind == "reply" ? BotReplyJobTitle : BotTaskStatusLine,
|
||||
}),
|
||||
await setFace({
|
||||
face: "working",
|
||||
status_line: job.kind == "reply" ? BotReplyJobTitle : BotTaskStatusLine,
|
||||
});
|
||||
|
||||
return await runner({
|
||||
@@ -159,14 +167,7 @@ export default async function processBotJob({
|
||||
refund: true,
|
||||
});
|
||||
|
||||
await pushBotNotice({
|
||||
bot_id,
|
||||
bot: await setBotFace({
|
||||
bot_id,
|
||||
face: "asleep",
|
||||
status_line: BotWaitingStatusLine,
|
||||
}),
|
||||
});
|
||||
await setFace({ face: "asleep", status_line: BotWaitingStatusLine });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user