/**
* Transcript rows — the chat's visual vocabulary (docs/design-doc.md §4.4).
* Assistant prose is unboxed body text; everything else is progressively
* disclosed and quieter than the prose.
*/
import { memo } from "react";
import { StyleSheet, View } from "react-native";
import { Image } from "expo-image";
import { useTheme } from "../../theme/ThemeProvider";
import { radius, space } from "../../theme/tokens";
import { Text } from "../ui/Text";
import { Touchable } from "../ui/Touchable";
import { Markdown, useCopyFeedback } from "./Markdown";
import type { AssistantItem, ErrorItem, ToolItem, UserItem } from "../../lib/letta/model";
export { ThinkingIndicator as ThinkingRow } from "./ThinkingIndicator";
// ── User ────────────────────────────────────────────────────────────────────
// Row components are memoized: transcript items are immutable (upsertItem
// replaces only the changed item), so during a streaming flush every settled
// row skips its render on reference equality alone.
export const UserBubble = memo(function UserBubble({ item, onRetry }: { item: UserItem; onRetry?: () => void }) {
const { colors } = useTheme();
const { copied, copy } = useCopyFeedback(item.text || item.channelAttachments || "");
return (
{item.originLabel ? (
{item.originLabel}
) : null}
{item.images?.length ? (
{/* Indexed: the same image can legitimately be attached twice. */}
{item.images.map((uri, index) => (
))}
) : null}
{item.channelReply ? (
{item.channelReply}
) : null}
{item.channelAttachments ? (
{item.channelAttachments}
) : null}
{item.text ? {item.text} : null}
{item.failed ? (
Not sent · Tap to retry
) : null}
{copied ? (
Copied
) : null}
);
});
// ── Assistant ───────────────────────────────────────────────────────────────
export const AssistantBlock = memo(function AssistantBlock({ item }: { item: AssistantItem }) {
const { copied, copy } = useCopyFeedback(item.text);
return (
{item.streaming ? {item.text} : }
{item.interrupted ? (
Stopped
) : null}
{copied ? (
Copied
) : null}
);
});
// ── Tool card ───────────────────────────────────────────────────────────────
export const ToolCard = memo(function ToolCard({ item }: { item: ToolItem }) {
const rawSummary = item.summary.trim();
const fallback = item.name
.replace(/[_-]+/g, " ")
.replace(/\b\w/g, (letter) => letter.toUpperCase());
const description = rawSummary && rawSummary !== "{}" && rawSummary !== "[]" ? rawSummary : fallback;
return (
{description}
);
});
// ── Error ───────────────────────────────────────────────────────────────────
export const ErrorRow = memo(function ErrorRow({ item, onRetry }: { item: ErrorItem; onRetry?: () => void }) {
return (
{item.message}
{item.retryable ? (
Retry
) : null}
);
});
const styles = StyleSheet.create({
userRow: { alignItems: "flex-end", gap: 4 },
origin: { fontSize: 11, lineHeight: 16, paddingRight: 8, maxWidth: "88%" },
channelAttachments: { fontSize: 12, lineHeight: 18, marginBottom: 6 },
channelReply: { fontSize: 12, lineHeight: 18, borderLeftWidth: 1, paddingLeft: 8, marginBottom: 10 },
userImages: { flexDirection: "row", flexWrap: "wrap", gap: 4, marginBottom: 6 },
userImage: { width: 96, height: 96, borderRadius: 10 },
userTouch: { borderRadius: radius.bubble, borderBottomRightRadius: 12, maxWidth: "88%" },
activitySlot: { minHeight: 24, justifyContent: "center", paddingHorizontal: 52 },
userBubble: {
borderRadius: radius.bubble,
borderBottomRightRadius: 12,
paddingHorizontal: space.lg,
paddingVertical: 12,
},
userText: { fontSize: 14.5, lineHeight: 21 },
userMeta: { paddingRight: space.xs },
assistant: { gap: 6, paddingBottom: space.sm, justifyContent: "flex-start" },
assistantText: { fontSize: 15, lineHeight: 23 },
interrupted: { marginTop: 2 },
errorRow: { flexDirection: "row", alignItems: "center", gap: space.md },
retry: { minHeight: 32 },
});