import React, { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, type ComponentProps, type ReactNode, } from "react"; import { View, Text, Pressable, Platform, ActivityIndicator, type PressableStateCallbackType, type StyleProp, type ViewStyle, } from "react-native"; import { StyleSheet, withUnistyles } from "react-native-unistyles"; import { MAX_CONTENT_WIDTH, useIsCompactFormFactor } from "@/constants/layout"; import { useMutation } from "@tanstack/react-query"; import Animated, { FadeIn, FadeOut } from "react-native-reanimated"; import { Check, ChevronDown, X } from "lucide-react-native"; import { usePanelStore } from "@/stores/panel-store"; import { AssistantMessage, SpeakMessage, UserMessage, ActivityLog, ToolCall, TodoListCard, CompactionMarker, MessageOuterSpacingProvider, type InlinePathTarget, } from "./message"; import { PlanCard } from "./plan-card"; import type { StreamItem } from "@/types/stream"; import type { PendingPermission } from "@/types/shared"; import type { AgentPermissionAction, AgentPermissionResponse, } from "@server/server/agent/agent-sdk-types"; import type { AgentScreenAgent } from "@/hooks/use-agent-screen-state-machine"; import { useSessionStore } from "@/stores/session-store"; import { useFileExplorerActions } from "@/hooks/use-file-explorer-actions"; import { useLoadOlderAgentHistory } from "@/hooks/use-load-older-agent-history"; import type { ToastApi } from "@/components/toast-host"; import type { DaemonClient } from "@server/client/daemon-client"; import { ToolCallDetailsContent } from "./tool-call-details"; import { QuestionFormCard } from "./question-form-card"; import { ToolCallSheetProvider } from "./tool-call-sheet"; import { buildAgentStreamRenderModel, getStreamNeighborItem, resolveStreamRenderStrategy, type AgentStreamRenderModel, type StreamSegmentRenderers, type StreamViewportHandle, } from "./agent-stream-render-strategy"; import { getAssistantBlockSpacing, getGapBetweenStreamItems } from "./agent-stream-view-data"; import { CompletedTurnFooterRow, resolveBottomTurnFooterHost, shouldRenderCompletedTurnFooter, TurnFooter, type TurnContentStrategy, type TurnFooterHost, } from "./agent-stream-turn-footer"; import { type BottomAnchorLocalRequest, type BottomAnchorRouteRequest, } from "./use-bottom-anchor-controller"; import { AssistantFileLinkResolverProvider, normalizeInlinePathTarget, } from "@/assistant-file-links"; import { createWorkspaceFileTabTarget, normalizeWorkspaceFileLocation, type OpenFileDisposition, type WorkspaceFileOpenRequest, } from "@/workspace/file-open"; import { resolveWorkspaceIdByExecutionDirectory } from "@/utils/workspace-execution"; import { navigateToPreparedWorkspaceTab } from "@/utils/workspace-navigation"; import { useStableEvent } from "@/hooks/use-stable-event"; import { isWeb } from "@/constants/platform"; import type { Theme } from "@/styles/theme"; interface StreamItemBoundarySeams { aboveItem?: StreamItem | null; belowItem?: StreamItem | null; suppressTurnFooter?: boolean; } function renderLiveAuxiliaryNode(input: { pendingPermissions: ReactNode; turnFooter: ReactNode; }): ReactNode { if (!input.pendingPermissions && !input.turnFooter) { return null; } return ( <> {input.turnFooter} {input.pendingPermissions ? ( {input.pendingPermissions} ) : null} ); } function renderPendingPermissionsNode(input: { pendingPermissions: PendingPermission[]; client: DaemonClient | null; }): ReactNode { if (input.pendingPermissions.length === 0) { return null; } return ( {input.pendingPermissions.map((permission) => ( ))} ); } function renderStreamItemWithTurnFooter(input: { content: ReactNode; item: StreamItem; nextItem: StreamItem | undefined; items: StreamItem[]; timing: AgentStreamRenderModel["turnTiming"]["byAssistantId"]; index: number; agentStatus: string; suppressTurnFooter: boolean | undefined; strategy: TurnContentStrategy; }): ReactNode { if (!input.content) { return null; } const showCompletedFooter = shouldRenderCompletedTurnFooter({ item: input.item, belowItem: input.nextItem, agentStatus: input.agentStatus, suppressTurnFooter: input.suppressTurnFooter, }); const gapBelow = showCompletedFooter ? 0 : getGapBetweenStreamItems(input.item, input.nextItem ?? null); return ( <> {input.content} {showCompletedFooter ? ( ) : null} ); } function renderListEmptyComponent(input: { renderModel: AgentStreamRenderModel; emptyStateStyle: StyleProp; }): ReactNode { if ( input.renderModel.boundary.hasVirtualizedHistory || input.renderModel.boundary.hasMountedHistory || input.renderModel.boundary.hasLiveHead || input.renderModel.auxiliary.pendingPermissions || input.renderModel.auxiliary.turnFooter ) { return null; } return ( Start chatting with this agent... ); } function renderHistoryStreamItem(input: { item: StreamItem; historyIndexById: Map; historyItems: StreamItem[]; lastHistoryItem: StreamItem | null; firstLiveHeadItem: StreamItem | null; bottomTurnFooterHost: TurnFooterHost | null; renderStreamItem: ( item: StreamItem, index: number, items: StreamItem[], seams?: StreamItemBoundarySeams, ) => ReactNode; }): ReactNode { const historyIndex = input.historyIndexById.get(input.item.id); if (historyIndex === undefined) { return null; } const seamBelowItem = input.item.id === input.lastHistoryItem?.id ? input.firstLiveHeadItem : null; return input.renderStreamItem(input.item, historyIndex, input.historyItems, { belowItem: seamBelowItem, suppressTurnFooter: input.item.id === input.bottomTurnFooterHost?.itemId, }); } function renderLiveHeadStreamItem(input: { item: StreamItem; index: number; items: StreamItem[]; lastHistoryItem: StreamItem | null; bottomTurnFooterHost: TurnFooterHost | null; renderStreamItem: ( item: StreamItem, index: number, items: StreamItem[], seams?: StreamItemBoundarySeams, ) => ReactNode; }): ReactNode { return input.renderStreamItem(input.item, input.index, input.items, { aboveItem: input.index === 0 ? input.lastHistoryItem : null, suppressTurnFooter: input.item.id === input.bottomTurnFooterHost?.itemId, }); } export interface AgentStreamViewHandle { scrollToBottom(reason?: BottomAnchorLocalRequest["reason"]): void; prepareForViewportChange(): void; } export interface AgentStreamViewProps { agentId: string; serverId?: string; agent: AgentScreenAgent; streamItems: StreamItem[]; pendingPermissions: Map; routeBottomAnchorRequest?: BottomAnchorRouteRequest | null; isAuthoritativeHistoryReady?: boolean; toast?: ToastApi | null; onOpenWorkspaceFile?: (request: WorkspaceFileOpenRequest) => void; } const EMPTY_STREAM_HEAD: StreamItem[] = []; const AgentStreamViewComponent = forwardRef( function AgentStreamView( { agentId, serverId, agent, streamItems, pendingPermissions, routeBottomAnchorRequest = null, isAuthoritativeHistoryReady = true, toast, onOpenWorkspaceFile, }, ref, ) { const viewportRef = useRef(null); const isMobile = useIsCompactFormFactor(); const streamRenderStrategy = useMemo( () => resolveStreamRenderStrategy({ platform: Platform.OS, isMobileBreakpoint: isMobile, }), [isMobile], ); const [isNearBottom, setIsNearBottom] = useState(true); const [expandedInlineToolCallIds, setExpandedInlineToolCallIds] = useState>( new Set(), ); const openFileExplorerForCheckout = usePanelStore((state) => state.openFileExplorerForCheckout); const setExplorerTabForCheckout = usePanelStore((state) => state.setExplorerTabForCheckout); // Get serverId (fallback to agent's serverId if not provided) const resolvedServerId = serverId ?? agent.serverId ?? ""; const client = useSessionStore((state) => state.sessions[resolvedServerId]?.client ?? null); const streamHead = useSessionStore((state) => state.sessions[resolvedServerId]?.agentStreamHead?.get(agentId), ); const workspaceRoot = agent.cwd?.trim() || ""; const workspaceId = resolveWorkspaceIdByExecutionDirectory({ workspaces: useSessionStore.getState().sessions[resolvedServerId]?.workspaces?.values(), workspaceDirectory: workspaceRoot, }); const { requestDirectoryListing } = useFileExplorerActions({ serverId: resolvedServerId, workspaceId: workspaceId ?? undefined, workspaceRoot, }); const { isLoadingOlder, hasOlder, loadOlder } = useLoadOlderAgentHistory({ serverId: resolvedServerId, agentId, toast, }); // Keep entry/exit animations off on Android due to RN dispatchDraw crashes // tracked in react-native-reanimated#8422. const shouldDisableEntryExitAnimations = Platform.OS === "android"; const scrollIndicatorFadeIn = shouldDisableEntryExitAnimations ? undefined : FadeIn.duration(200); const scrollIndicatorFadeOut = shouldDisableEntryExitAnimations ? undefined : FadeOut.duration(200); useEffect(() => { setIsNearBottom(true); setExpandedInlineToolCallIds(new Set()); }, [agentId]); const handleInlinePathPress = useStableEvent( (target: InlinePathTarget, disposition: OpenFileDisposition) => { if (!target.path) { return; } const normalized = normalizeInlinePathTarget(target.path, agent.cwd); if (!normalized) { return; } if (normalized.file) { const location = normalizeWorkspaceFileLocation({ path: normalized.file, lineStart: target.lineStart, lineEnd: target.lineEnd, }); if (!location) { return; } if (onOpenWorkspaceFile) { onOpenWorkspaceFile({ location, disposition, }); return; } if (workspaceId) { navigateToPreparedWorkspaceTab({ serverId: resolvedServerId, workspaceId, target: createWorkspaceFileTabTarget(location), }); } return; } void requestDirectoryListing(normalized.directory, { recordHistory: false, setCurrentPath: false, }); const checkout = { serverId: resolvedServerId, cwd: agent.cwd, isGit: agent.projectPlacement?.checkout?.isGit ?? true, }; setExplorerTabForCheckout({ ...checkout, tab: "files" }); openFileExplorerForCheckout({ isCompact: isMobile, checkout, }); }, ); const handleToolCallOpenFile = useStableEvent((filePath: string) => { handleInlinePathPress({ raw: filePath, path: filePath }, "main"); }); const baseRenderModel = useMemo(() => { return buildAgentStreamRenderModel({ agentStatus: agent.status, tail: streamItems, head: streamHead ?? EMPTY_STREAM_HEAD, platform: isWeb ? "web" : "native", isMobileBreakpoint: isMobile, }); }, [agent.status, isMobile, streamHead, streamItems]); useImperativeHandle( ref, () => ({ scrollToBottom(reason = "jump-to-bottom") { viewportRef.current?.scrollToBottom(reason); }, prepareForViewportChange() { viewportRef.current?.prepareForViewportChange(); }, }), [], ); const scrollToBottom = useCallback(() => { viewportRef.current?.scrollToBottom("jump-to-bottom"); }, []); const setInlineDetailsExpanded = useCallback( (itemId: string, expanded: boolean) => { if (!streamRenderStrategy.shouldDisableParentScrollOnInlineDetailsExpansion()) { return; } setExpandedInlineToolCallIds((previous) => { const next = new Set(previous); if (expanded) { next.add(itemId); } else { next.delete(itemId); } return next; }); }, [streamRenderStrategy], ); const renderUserMessageItem = useCallback( ( item: Extract, index: number, items: StreamItem[], seamAboveItem: StreamItem | null, ) => { const aboveItem = getStreamNeighborItem({ strategy: streamRenderStrategy, items, index, relation: "above", }) ?? seamAboveItem ?? undefined; const belowItem = getStreamNeighborItem({ strategy: streamRenderStrategy, items, index, relation: "below", }); const isFirstInGroup = aboveItem?.kind !== "user_message"; const isLastInGroup = belowItem?.kind !== "user_message"; return ( ); }, [streamRenderStrategy], ); const renderAssistantMessageItem = useCallback( ( item: Extract, index: number, items: StreamItem[], seams: StreamItemBoundarySeams, ) => { const aboveItem = getStreamNeighborItem({ strategy: streamRenderStrategy, items, index, relation: "above", }) ?? seams.aboveItem ?? undefined; const belowItem = getStreamNeighborItem({ strategy: streamRenderStrategy, items, index, relation: "below", }) ?? seams.belowItem ?? undefined; const spacing = getAssistantBlockSpacing({ item, aboveItem, belowItem, }); return ( ); }, [client, handleInlinePathPress, resolvedServerId, streamRenderStrategy, toast, workspaceRoot], ); const renderThoughtItem = useCallback( (item: Extract, index: number, items: StreamItem[]) => { const nextItem = getStreamNeighborItem({ strategy: streamRenderStrategy, items, index, relation: "below", }); const isLastInSequence = nextItem?.kind !== "tool_call" && nextItem?.kind !== "thought"; return ( ); }, [streamRenderStrategy, setInlineDetailsExpanded], ); const renderToolCallItem = useCallback( (item: Extract, index: number, items: StreamItem[]) => { const { payload } = item; const nextItem = getStreamNeighborItem({ strategy: streamRenderStrategy, items, index, relation: "below", }); const isLastInSequence = nextItem?.kind !== "tool_call" && nextItem?.kind !== "thought"; if (payload.source === "agent") { const data = payload.data; if ( data.name === "speak" && data.detail.type === "unknown" && typeof data.detail.input === "string" && data.detail.input.trim() ) { return ( ); } return ( ); } const data = payload.data; return ( ); }, [agent.cwd, streamRenderStrategy, setInlineDetailsExpanded, handleToolCallOpenFile], ); const renderStreamItemContent = useCallback( ( item: StreamItem, index: number, items: StreamItem[], seams: StreamItemBoundarySeams = {}, ) => { switch (item.kind) { case "user_message": return renderUserMessageItem(item, index, items, seams.aboveItem ?? null); case "assistant_message": return renderAssistantMessageItem(item, index, items, seams); case "thought": return renderThoughtItem(item, index, items); case "tool_call": return renderToolCallItem(item, index, items); case "activity_log": return ( ); case "todo_list": return ; case "compaction": return ( ); default: return null; } }, [renderUserMessageItem, renderAssistantMessageItem, renderThoughtItem, renderToolCallItem], ); const bottomTurnFooterHost = useMemo(() => { return resolveBottomTurnFooterHost({ agentStatus: agent.status, history: baseRenderModel.history, liveHead: baseRenderModel.segments.liveHead, isInverted: streamRenderStrategy.getFlatListInverted(), timingByAssistantId: baseRenderModel.turnTiming.byAssistantId, }); }, [ agent.status, baseRenderModel.history, baseRenderModel.segments.liveHead, baseRenderModel.turnTiming.byAssistantId, streamRenderStrategy, ]); const renderStreamItem = useCallback( ( item: StreamItem, index: number, items: StreamItem[], seams: StreamItemBoundarySeams = {}, ) => { const content = renderStreamItemContent(item, index, items, seams); const nextItem = getStreamNeighborItem({ strategy: streamRenderStrategy, items, index, relation: "below", }); return renderStreamItemWithTurnFooter({ content, item, nextItem, items, timing: baseRenderModel.turnTiming.byAssistantId, index, agentStatus: agent.status, suppressTurnFooter: seams.suppressTurnFooter, strategy: streamRenderStrategy, }); }, [ agent.status, baseRenderModel.turnTiming.byAssistantId, renderStreamItemContent, streamRenderStrategy, ], ); const pendingPermissionItems = useMemo( () => Array.from(pendingPermissions.values()).filter((perm) => perm.agentId === agentId), [pendingPermissions, agentId], ); const showRunningTurnFooter = agent.status === "running"; const pendingPermissionsNode = useMemo( () => renderPendingPermissionsNode({ pendingPermissions: pendingPermissionItems, client, }), [client, pendingPermissionItems], ); const turnFooterNode = useMemo( () => showRunningTurnFooter || bottomTurnFooterHost ? ( ) : null, [ showRunningTurnFooter, baseRenderModel.turnTiming.runningStartedAt, bottomTurnFooterHost, streamRenderStrategy, ], ); const renderModel = useMemo(() => { return { ...baseRenderModel, boundary: { ...baseRenderModel.boundary, historyToHeadGap: getGapBetweenStreamItems( baseRenderModel.history.at(-1) ?? null, baseRenderModel.segments.liveHead[0] ?? null, ), }, auxiliary: { pendingPermissions: pendingPermissionsNode, turnFooter: turnFooterNode, }, }; }, [baseRenderModel, pendingPermissionsNode, turnFooterNode]); const emptyStateStyle = useMemo(() => [stylesheet.emptyState, stylesheet.contentWrapper], []); const listEmptyComponent = useMemo( () => renderListEmptyComponent({ renderModel, emptyStateStyle }), [renderModel, emptyStateStyle], ); const historyItems = renderModel.history; const { boundary, auxiliary } = renderModel; const lastHistoryItem = historyItems.at(-1) ?? null; const firstLiveHeadItem = renderModel.segments.liveHead[0] ?? null; const historyIndexById = useMemo(() => { const indexById = new Map(); historyItems.forEach((item, index) => { indexById.set(item.id, index); }); return indexById; }, [historyItems]); const renderHistoryRow = useCallback( (item: StreamItem) => renderHistoryStreamItem({ item, historyIndexById, historyItems, lastHistoryItem, firstLiveHeadItem, bottomTurnFooterHost, renderStreamItem, }), [ bottomTurnFooterHost, firstLiveHeadItem, historyIndexById, historyItems, lastHistoryItem, renderStreamItem, ], ); const renderHistoryVirtualizedRow = useCallback< StreamSegmentRenderers["renderHistoryVirtualizedRow"] >((item) => renderHistoryRow(item), [renderHistoryRow]); const renderHistoryMountedRow = useCallback( (item) => renderHistoryRow(item), [renderHistoryRow], ); const renderLiveHeadRow = useCallback( (item, index, items) => renderLiveHeadStreamItem({ item, index, items, lastHistoryItem, bottomTurnFooterHost, renderStreamItem, }), [bottomTurnFooterHost, lastHistoryItem, renderStreamItem], ); const renderLiveAuxiliary = useCallback(() => { return renderLiveAuxiliaryNode({ pendingPermissions: auxiliary.pendingPermissions, turnFooter: auxiliary.turnFooter, }); }, [auxiliary.pendingPermissions, auxiliary.turnFooter]); const renderers = useMemo( () => ({ renderHistoryVirtualizedRow, renderHistoryMountedRow, renderLiveHeadRow, renderLiveAuxiliary, }), [ renderHistoryVirtualizedRow, renderHistoryMountedRow, renderLiveHeadRow, renderLiveAuxiliary, ], ); const streamScrollEnabled = !streamRenderStrategy.shouldDisableParentScrollOnInlineDetailsExpansion() || expandedInlineToolCallIds.size === 0; return ( {streamRenderStrategy.render({ agentId, segments: renderModel.segments, boundary, renderers, listEmptyComponent, viewportRef, routeBottomAnchorRequest, isAuthoritativeHistoryReady, onNearBottomChange: setIsNearBottom, onNearHistoryStart: loadOlder, isLoadingOlderHistory: isLoadingOlder, hasOlderHistory: hasOlder, scrollEnabled: streamScrollEnabled, listStyle: stylesheet.list, baseListContentContainerStyle: stylesheet.listContentContainer, forwardListContentContainerStyle: stylesheet.forwardListContentContainer, })} {!isNearBottom && ( )} ); }, ); export const AgentStreamView = memo(AgentStreamViewComponent); AgentStreamView.displayName = "AgentStreamView"; interface ToolCallSlotProps extends Omit< ComponentProps, "onInlineDetailsExpandedChange" > { itemId: string; onInlineDetailsExpandedChangeByItemId: (itemId: string, expanded: boolean) => void; } function ToolCallSlot({ itemId, onInlineDetailsExpandedChangeByItemId, ...rest }: ToolCallSlotProps) { const handleExpandedChange = useCallback( (expanded: boolean) => onInlineDetailsExpandedChangeByItemId(itemId, expanded), [onInlineDetailsExpandedChangeByItemId, itemId], ); return ; } const ThemedActivityIndicator = withUnistyles(ActivityIndicator); const ThemedCheckIcon = withUnistyles(Check); const ThemedXIcon = withUnistyles(X); const primaryColorMapping = (theme: Theme) => ({ color: theme.colors.foreground, }); const mutedColorMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted, }); const pressableStyle = ({ pressed, hovered = false, }: PressableStateCallbackType & { hovered?: boolean }) => [ permissionStyles.optionButton, hovered ? permissionStyles.optionButtonHovered : null, pressed ? permissionStyles.optionButtonPressed : null, ]; interface PermissionActionButtonProps { action: AgentPermissionAction; isRespondingAction: boolean; isResponding: boolean; isPrimary: boolean; Icon: typeof ThemedCheckIcon; testID: string; onPress: (action: AgentPermissionAction) => void; } function PermissionActionButton({ action, isRespondingAction, isResponding, isPrimary, Icon, testID, onPress, }: PermissionActionButtonProps) { const handlePress = useCallback(() => onPress(action), [onPress, action]); const optionTextStyle = isPrimary ? optionTextPrimaryStyle : permissionStyles.optionText; const colorMapping = isPrimary ? primaryColorMapping : mutedColorMapping; return ( {isRespondingAction ? ( ) : ( {action.label} )} ); } function PermissionRequestCard({ permission, client, }: { permission: PendingPermission; client: DaemonClient | null; }) { const isMobile = useIsCompactFormFactor(); const { request } = permission; const isPlanRequest = request.kind === "plan"; const title = isPlanRequest ? "Plan" : (request.title ?? request.name ?? "Permission Required"); const description = request.description ?? ""; const resolvedToolCallDetail = useMemo( () => request.detail ?? { type: "unknown" as const, input: request.input ?? null, output: null, }, [request.detail, request.input], ); const resolvedActions = useMemo((): AgentPermissionAction[] => { if (request.kind === "question") { return []; } if (Array.isArray(request.actions) && request.actions.length > 0) { return request.actions; } return [ { id: "reject", label: "Deny", behavior: "deny", variant: "danger", intent: "dismiss", }, { id: "accept", label: isPlanRequest ? "Implement" : "Accept", behavior: "allow", variant: "primary", }, ]; }, [isPlanRequest, request]); const planMarkdown = useMemo(() => { if (!request) { return undefined; } const planFromMetadata = typeof request.metadata?.planText === "string" ? request.metadata.planText : undefined; if (planFromMetadata) { return planFromMetadata; } const candidate = request.input?.["plan"]; if (typeof candidate === "string") { return candidate; } return undefined; }, [request]); const permissionMutation = useMutation({ mutationFn: async (input: { agentId: string; requestId: string; response: AgentPermissionResponse; }) => { if (!client) { throw new Error("Daemon client unavailable"); } return client.respondToPermissionAndWait( input.agentId, input.requestId, input.response, 15000, ); }, }); const { reset: resetPermissionMutation, mutateAsync: respondToPermission, isPending: isResponding, } = permissionMutation; const [respondingActionId, setRespondingActionId] = useState(null); useEffect(() => { resetPermissionMutation(); setRespondingActionId(null); }, [permission.request.id, resetPermissionMutation]); const handleResponse = useCallback( (response: AgentPermissionResponse) => { respondToPermission({ agentId: permission.agentId, requestId: permission.request.id, response, }).catch((error) => { console.error("[PermissionRequestCard] Failed to respond to permission:", error); }); }, [permission.agentId, permission.request.id, respondToPermission], ); const handleActionPress = useCallback( (action: AgentPermissionAction) => { setRespondingActionId(action.id); if (action.behavior === "allow") { handleResponse({ behavior: "allow", selectedActionId: action.id, }); return; } handleResponse({ behavior: "deny", selectedActionId: action.id, message: "Denied by user", }); }, [handleResponse], ); const optionsContainerStyle = useMemo( () => [ permissionStyles.optionsContainer, !isMobile && permissionStyles.optionsContainerDesktop, ], [isMobile], ); if (request.kind === "question") { return ( ); } const footer = ( <> How would you like to proceed? {resolvedActions.map((action) => { const isPrimary = action.variant === "primary"; const isRespondingAction = respondingActionId === action.id; const Icon = action.behavior === "allow" ? ThemedCheckIcon : ThemedXIcon; let testID: string; if (action.behavior === "deny") testID = "permission-request-deny"; else if (action.id === "accept" || action.id === "implement") testID = "permission-request-accept"; else testID = `permission-request-action-${action.id}`; return ( ); })} ); if (isPlanRequest && planMarkdown) { return ( ); } return ( {title} {description ? {description} : null} {planMarkdown ? ( ) : null} {!isPlanRequest ? ( ) : null} {footer} ); } const stylesheet = StyleSheet.create((theme) => ({ container: { flex: 1, backgroundColor: theme.colors.surface0, }, contentWrapper: { width: "100%", maxWidth: MAX_CONTENT_WIDTH, alignSelf: "center", paddingHorizontal: theme.spacing[2], }, listContentContainer: { paddingVertical: 0, flexGrow: 1, paddingHorizontal: { xs: theme.spacing[2], md: theme.spacing[4], }, }, forwardListContentContainer: { paddingTop: theme.spacing[4], paddingBottom: theme.spacing[4], }, list: { flex: 1, }, streamItemWrapper: { width: "100%", maxWidth: MAX_CONTENT_WIDTH, alignSelf: "center", paddingHorizontal: theme.spacing[2], }, emptyState: { flex: 1, alignItems: "center", justifyContent: "center", paddingVertical: theme.spacing[12], }, permissionsContainer: { gap: theme.spacing[2], }, listHeaderContent: { gap: theme.spacing[3], }, syncingIndicator: { flexDirection: "row", alignItems: "center", gap: theme.spacing[2], paddingVertical: theme.spacing[1], paddingLeft: theme.spacing[2], }, syncingIndicatorText: { color: theme.colors.foregroundMuted, fontSize: theme.fontSize.sm, }, invertedWrapper: { transform: [{ scaleY: -1 }], width: "100%", }, emptyStateText: { color: theme.colors.foregroundMuted, fontSize: theme.fontSize.sm, textAlign: "center", }, scrollToBottomContainer: { position: "absolute", bottom: 16, left: 0, right: 0, alignItems: "center", pointerEvents: "box-none", }, scrollToBottomInner: { width: "100%", maxWidth: MAX_CONTENT_WIDTH, alignSelf: "center", alignItems: "center", }, scrollToBottomButton: { width: 48, height: 48, borderRadius: 24, backgroundColor: theme.colors.surface2, alignItems: "center", justifyContent: "center", ...theme.shadow.sm, }, scrollToBottomIcon: { color: theme.colors.foreground, }, })); const permissionStyles = StyleSheet.create((theme) => ({ container: { marginVertical: theme.spacing[3], padding: theme.spacing[3], borderRadius: theme.spacing[2], borderWidth: 1, gap: theme.spacing[2], backgroundColor: theme.colors.surface1, borderColor: theme.colors.border, }, title: { fontSize: theme.fontSize.base, lineHeight: 22, color: theme.colors.foreground, }, description: { fontSize: theme.fontSize.sm, lineHeight: 20, color: theme.colors.foregroundMuted, }, section: { gap: theme.spacing[2], }, sectionTitle: { fontSize: theme.fontSize.xs, }, question: { fontSize: theme.fontSize.sm, marginTop: theme.spacing[1], marginBottom: theme.spacing[1], color: theme.colors.foregroundMuted, }, optionsContainer: { gap: theme.spacing[2], }, optionsContainerDesktop: { flexDirection: "row", justifyContent: "flex-start", alignItems: "center", width: "100%", }, optionButton: { paddingVertical: theme.spacing[2], paddingHorizontal: theme.spacing[3], borderRadius: theme.borderRadius.md, alignItems: "center", borderWidth: theme.borderWidth[1], backgroundColor: theme.colors.surface1, borderColor: theme.colors.borderAccent, }, optionButtonHovered: { backgroundColor: theme.colors.surface2, }, optionButtonPressed: { opacity: 0.9, }, optionContent: { flexDirection: "row", alignItems: "center", gap: theme.spacing[2], }, optionText: { fontSize: theme.fontSize.sm, fontWeight: theme.fontWeight.normal, color: theme.colors.foregroundMuted, }, optionTextPrimary: { color: theme.colors.foreground, }, })); const optionTextPrimaryStyle = [permissionStyles.optionText, permissionStyles.optionTextPrimary]; interface StreamItemWrapperProps { gapBelow: number; children: ReactNode; } function StreamItemWrapper({ gapBelow, children }: StreamItemWrapperProps) { const wrapperStyle = useMemo( () => [stylesheet.streamItemWrapper, { marginBottom: gapBelow }], [gapBelow], ); return {children}; }