diff --git a/app/(tabs)/chat.tsx b/app/(tabs)/chat.tsx index 1d00331..f26fe4a 100644 --- a/app/(tabs)/chat.tsx +++ b/app/(tabs)/chat.tsx @@ -8,7 +8,6 @@ import { TouchableOpacity, KeyboardAvoidingView, Platform, - Alert, Modal, ActivityIndicator, } from 'react-native'; @@ -169,39 +168,22 @@ export default function ChatScreen() { } }; - // Send message with full context + // Send message with full context - optimized for speed const sendWithContext = async (question: string): Promise => { const token = await SecureStore.getItemAsync('accessToken'); const userName = await SecureStore.getItemAsync('userName'); if (!token || !userName) throw new Error('Please log in'); - if (!currentBeneficiary?.id) throw new Error('Please select a beneficiary'); - const beneficiaryName = currentBeneficiary.name || 'the patient'; - const deploymentId = currentBeneficiary.id.toString(); + const beneficiaryName = currentBeneficiary?.name || 'the patient'; + const deploymentId = currentBeneficiary?.id?.toString() || ''; - // Get activity context (primary source) - let activityContext = await getActivityContext(token, userName, deploymentId); + // Skip context fetching for faster response - just send directly + const enhancedQuestion = currentBeneficiary?.id + ? `You are a caring assistant helping monitor ${beneficiaryName}'s wellbeing. Please answer: ${question}` + : `You are a helpful AI assistant. Please answer: ${question}`; - // If activity context is empty, try dashboard context as fallback - if (!activityContext) { - activityContext = await getDashboardContext(token, userName, deploymentId); - } - - // Build the question with embedded context - let enhancedQuestion: string; - if (activityContext) { - enhancedQuestion = `You are a caring assistant helping monitor ${beneficiaryName}'s wellbeing. - -Here is the current data about ${beneficiaryName}: -${activityContext} - -Based on this data, please answer the following question: ${question}`; - } else { - enhancedQuestion = `You are a caring assistant helping monitor ${beneficiaryName}'s wellbeing. Please answer: ${question}`; - } - - // Call API + // Call API directly without pre-fetching context const requestBody = new URLSearchParams({ function: 'voice_ask', clientId: '001', @@ -209,7 +191,7 @@ Based on this data, please answer the following question: ${question}`; token: token, question: enhancedQuestion, deployment_id: deploymentId, - context: activityContext || '', + context: '', }).toString(); const response = await fetch(API_URL, { @@ -233,14 +215,10 @@ Based on this data, please answer the following question: ${question}`; const trimmedInput = input.trim(); if (!trimmedInput || isSending) return; - // Require beneficiary to be selected + // If no beneficiary selected, auto-selection should have happened + // but if still none, just proceed without context if (!currentBeneficiary?.id) { - Alert.alert( - 'Select Beneficiary', - 'Please select a beneficiary using the icon in the top right corner.', - [{ text: 'OK' }] - ); - return; + console.log('No beneficiary selected, proceeding without context'); } const userMessage: Message = { @@ -424,7 +402,7 @@ Based on this data, please answer the following question: ${question}`; onChangeText={setInput} multiline maxLength={1000} - editable={!isSending} + editable={true} onSubmitEditing={handleSend} /> { + Linking.openURL(TERMS_URL); + }; + + const openPrivacy = () => { + Linking.openURL(PRIVACY_URL); + }; + const handleLogout = () => { Alert.alert( 'Logout', @@ -100,11 +112,13 @@ export default function ProfileScreen() {