import { Trans, useLingui } from "@lingui/react/macro"; import { ChatMarkdown } from "@rakazo/chat-ui/web"; import type { ThreadMessage } from "@rakazo/contracts"; import { BotAvatar, Button, Dialog, DialogClose, DialogContent, DialogTitle } from "@rakazo/ui-web"; import { useEffect, useMemo, useState } from "react"; import { loadPeerHistory } from "../lib/peer-history"; import { peerConversations } from "../lib/peer-messages"; import { rpc } from "../lib/rpc"; /** * Full-screen view-only transcript of a bot-to-bot exchange. * Opened from a Messaged / Message from chip in the human thread. */ export function PeerMessagesOverlay({ botId, botName, botColor, peerBotId, peerBotName: initialPeerBotName, peerBotColor, onClose, }: { botId: string; botName: string; botColor: string; peerBotId: string; peerBotName: string; peerBotColor: string; onClose: () => void; }) { const { t } = useLingui(); const [messages, setMessages] = useState([]); const [historyReady, setHistoryReady] = useState(false); const [historyFailed, setHistoryFailed] = useState(false); const [reloadKey, setReloadKey] = useState(0); const conversation = useMemo(() => { if (!historyReady) return null; return peerConversations(messages).find((entry) => entry.peerBotId === peerBotId) ?? null; }, [historyReady, messages, peerBotId]); const peerBotName = conversation?.peerBotName ?? initialPeerBotName; useEffect(() => { const abort = new AbortController(); setHistoryReady(false); setHistoryFailed(false); setMessages([]); void loadPeerHistory({ signal: abort.signal, loadPage: (before, signal) => rpc.threads.messages({ botId, before, includePeerRuns: true }, { signal }), }) .then((loaded) => { if (abort.signal.aborted) return; setMessages(loaded); setHistoryReady(true); }) .catch(() => { if (abort.signal.aborted) return; setHistoryFailed(true); setHistoryReady(true); }); return () => { abort.abort(); }; }, [botId, reloadKey]); const title = `${botName} · ${peerBotName}`; return ( { if (!open) onClose(); }} >
{title}
}> Close
{!historyReady ? (
Loading…
) : historyFailed ? (
Could not load this chat.
) : !conversation || conversation.messages.length === 0 ? (
No messages with {peerBotName} yet.
) : (
{conversation.messages.map((peerMessage, index) => { const sent = peerMessage.direction === "sent"; return (
{sent ? botName : peerBotName}
{peerMessage.text}
); })}
)}

This chat is view-only

); }