Something went wrong. Try again.
Your thinking partner.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169/** * 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 ( <View style={styles.userRow}> {item.originLabel ? ( <Text role="sub" ink={3} style={styles.origin}>{item.originLabel}</Text> ) : null} <Touchable accessibilityRole={item.failed ? "button" : "none"} accessibilityLabel={item.failed ? "Message not sent. Retry" : [item.originLabel, item.channelReply, item.text, item.channelAttachments].filter(Boolean).join(". ")} accessibilityHint="Long press to copy" onPress={item.failed ? onRetry : undefined} onLongPress={copy} scaleOnPress={item.failed} style={styles.userTouch} > <View style={[ styles.userBubble, { backgroundColor: colors.ink }, ]} > {item.images?.length ? ( <View style={styles.userImages}> {/* Indexed: the same image can legitimately be attached twice. */} {item.images.map((uri, index) => ( <Image key={`${index}-${uri}`} source={{ uri }} style={styles.userImage} contentFit="cover" /> ))} </View> ) : null} {item.channelReply ? ( <Text role="sub" numberOfLines={3} style={[styles.channelReply, { color: colors.bg, borderLeftColor: colors.bg }]}>{item.channelReply}</Text> ) : null} {item.channelAttachments ? ( <Text role="sub" style={[styles.channelAttachments, { color: colors.bg }]}>{item.channelAttachments}</Text> ) : null} {item.text ? <Text style={[styles.userText, { color: colors.bg }]}>{item.text}</Text> : null} </View> {item.failed ? ( <Text role="sub" tone="danger" style={styles.userMeta}> Not sent · Tap to retry </Text> ) : null} {copied ? ( <Text role="sub" ink={3} style={styles.userMeta}> Copied </Text> ) : null} </Touchable> </View> );});
// ── Assistant ───────────────────────────────────────────────────────────────
export const AssistantBlock = memo(function AssistantBlock({ item }: { item: AssistantItem }) { const { copied, copy } = useCopyFeedback(item.text); return ( <Touchable accessibilityRole="none" accessibilityHint="Long press to copy" // Copy only once the text is final — mid-stream it would be a torn read. onLongPress={item.streaming ? undefined : copy} scaleOnPress={false} pressedOverlay={false} style={styles.assistant} > {item.streaming ? <Text style={styles.assistantText}>{item.text}</Text> : <Markdown text={item.text} />} {item.interrupted ? ( <Text role="sub" ink={3} style={styles.interrupted}> Stopped </Text> ) : null} {copied ? ( <Text role="sub" ink={3}> Copied </Text> ) : null} </Touchable> );});
// ── 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 ( <View accessibilityLabel={`Current action: ${description}`} accessibilityLiveRegion="polite" style={styles.activitySlot} > <Text role="sub" ink={3} numberOfLines={1}> {description} </Text> </View> );});
// ── Error ───────────────────────────────────────────────────────────────────
export const ErrorRow = memo(function ErrorRow({ item, onRetry }: { item: ErrorItem; onRetry?: () => void }) { return ( <View style={styles.errorRow}> <Text role="sub" tone="danger"> {item.message} </Text> {item.retryable ? ( <Touchable accessibilityRole="button" accessibilityLabel="Retry" onPress={onRetry} style={styles.retry}> <Text role="sub" tone="accent"> Retry </Text> </Touchable> ) : null} </View> );});
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 },});