import { View, ScrollView } from "react-native"; import { StyleSheet, useUnistyles } from "react-native-unistyles"; import { forwardRef, useRef, useState } from "react"; import { BottomSheetModal } from "@gorhom/bottom-sheet"; import { UserMessage, AssistantMessage, ActivityLog, ToolCall, } from "@/components/message"; import { ToolCallBottomSheet } from "./tool-call-bottom-sheet"; import type { MessageEntry } from "@/contexts/session-context"; import type { SelectedToolCall } from "@/types/shared"; interface OrchestratorMessagesViewProps { messages: MessageEntry[]; currentAssistantMessage: string; onArtifactClick: (artifactId: string) => void; } export const OrchestratorMessagesView = forwardRef( function OrchestratorMessagesView({ messages, currentAssistantMessage, onArtifactClick }, ref) { const { theme } = useUnistyles(); const bottomSheetRef = useRef(null); const [selectedToolCall, setSelectedToolCall] = useState(null); const [isBottomSheetVisible, setIsBottomSheetVisible] = useState(false); function handleOpenToolCallDetails(toolCall: { toolName: string; status: 'executing' | 'completed' | 'failed'; args: any; result?: any; error?: any; }) { // Wrap orchestrator tool call in payload structure setSelectedToolCall({ payload: { source: 'orchestrator', data: { toolCallId: `orchestrator_${Date.now()}`, // Generate a simple ID toolName: toolCall.toolName, arguments: toolCall.args, result: toolCall.result, error: toolCall.error, status: toolCall.status, }, }, }); setIsBottomSheetVisible(true); // Delay present to next frame to ensure component is mounted setTimeout(() => { bottomSheetRef.current?.present(); }, 0); } function handleBottomSheetDismiss() { setIsBottomSheetVisible(false); setSelectedToolCall(null); } return ( <> {messages.map((msg) => { if (msg.type === "user") { return ( ); } if (msg.type === "assistant") { return ( ); } if (msg.type === "activity") { return ( ); } if (msg.type === "artifact") { return ( ); } if (msg.type === "tool_call") { return ( handleOpenToolCallDetails({ toolName: msg.toolName, status: msg.status, args: msg.args, result: msg.result, error: msg.error, })} /> ); } return null; })} {/* Streaming assistant message */} {currentAssistantMessage && ( )} {isBottomSheetVisible && ( )} ); } ); const styles = StyleSheet.create((theme) => ({ scrollView: { flex: 1, }, scrollContent: { paddingHorizontal: theme.spacing[4], paddingTop: theme.spacing[4], paddingBottom: theme.spacing[6], }, }));