Keep only the bot cookie for the last visited bot
CI / check (push) Canceled after 0s

A workspace conversation is never remembered, so /admin/bots always
reopens the bot's own chat.
This commit is contained in:
2026-10-22 13:39:36 +01:00
parent 133e6b87c9
commit 63a93a4262
13 changed files with 48 additions and 147 deletions
+4 -7
View File
@@ -12,8 +12,8 @@ import railWorkspaces from "@/src/utils/rail-workspaces";
import readLastVisitedBot from "@/src/utils/read-last-visited-bot";
/**
* Opens the conversation this browser was last in, from the last-visited
* cookies the conversation pages set, while the user still reaches it.
* Opens the bot's own chat this browser was last in, from the last-visited
* cookie the conversation pages set, while the user still reaches it.
* Otherwise the super admin lands on the coordinator, which (with the main
* computer) is created first if the install has none; anyone else lands on
* the latest bot they chat with, else their first workspace; with neither,
@@ -62,7 +62,7 @@ export const server: BunextPageServerFn<PagePropsType> = async ({ req }) => {
};
/**
* The path of the conversation this browser was last in, if the user still
* The path of the bot's own chat this browser was last in, if the user still
* reaches it (`grabReachableConversation`, the conversation pages' own
* access check). Null sends the page on to its usual fallback.
*/
@@ -74,12 +74,9 @@ async function grabLastVisited({ user_id, req }: { user_id: number | string; req
const conversation = await grabReachableConversation({
user_id,
bot_id: visited.bot_id,
workspace_id: visited.workspace_id,
});
if (!conversation) return null;
return conversation.workspace_id
? `/admin/workspaces/${conversation.workspace_id}/bots/${conversation.bot_id}`
: `/admin/bots/${conversation.bot_id}`;
return `/admin/bots/${conversation.bot_id}`;
}
@@ -9,8 +9,8 @@ import type { BunextPageServerFn } from "@moduletrace/bunext/types";
* A bot's conversation inside a workspace: the bot works with the
* workspace's context, computers and models. Only the coordinator and the
* workspace's bots have one; anyone else goes back to the workspace
* settings (managers) or their bots. Rendering it records the conversation
* in the last-visited cookies, so `/admin/bots` opens it again.
* settings (managers) or their bots. Rendering it records the bot in the
* last-visited cookie, so `/admin/bots` opens its own chat again.
*/
export const server: BunextPageServerFn<PagePropsType> = async (params) => {
const query: PageQueryObject = params.query;
@@ -37,12 +37,11 @@ export const server: BunextPageServerFn<PagePropsType> = async (params) => {
}
const bot_id = props.bot.id;
const workspace_id = props.workspace?.id ?? query.workspace_id;
return {
props,
res_transform(res) {
return withLastVisitedBotCookies({ req: params.req, res, bot_id, workspace_id });
return withLastVisitedBotCookies({ req: params.req, res, bot_id });
},
};
};