Load a conversation's history on the client

The conversation pages rendered their messages on the server, so a page
the back button restored from the back-forward cache showed an old
thread. The server now renders everything else (rail, header, composer)
and the history (active session, latest messages, active task) loads
from api/admin/bots/conversation-history once the page is on screen,
with a loading line under the header, and again on a pageshow restore.
Messages sent or pushed while it loads are merged with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 03:55:38 +01:00
co-authored by Claude Opus 5.5
parent cdb93ac1bc
commit d542b4e9ad
15 changed files with 485 additions and 63 deletions
@@ -0,0 +1,20 @@
import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi";
import type { APIResponseObject } from "@moduletrace/bunext/types";
import type { BotConversationRequest } from "@/src/schemas/bot-schema";
import type { ConversationHistoryPayload } from "@/src/types";
/**
* A conversation's history, loaded once the page is on screen.
*/
export default async function fetchConversationHistory({
bot_id,
workspace_id,
}: BotConversationRequest) {
return await fetchApi<
BotConversationRequest,
APIResponseObject<ConversationHistoryPayload>
>(`/api/admin/bots/conversation-history`, {
method: "POST",
body: { bot_id, workspace_id },
});
}