diff --git a/app/(drawer)/(tabs)/lifestyle.tsx b/app/(drawer)/(tabs)/lifestyle.tsx index bbf4f11a..125f5c87 100644 --- a/app/(drawer)/(tabs)/lifestyle.tsx +++ b/app/(drawer)/(tabs)/lifestyle.tsx @@ -59,6 +59,12 @@ const SERVICE_MENU_ITEMS: MenuItemData[] = [ navigateTo: 'userMessages', params: { pubkey: SUPPORT_PUBKEY }, }, + { + id: 'routstr', + icon: 'mdi:robot', + label: 'AI Chat', + navigateTo: 'routstr', + }, // Empty placeholders to maintain grid layout { id: 'empty1', empty: true }, { id: 'empty2', empty: true }, @@ -126,7 +132,9 @@ const ServicesSection = () => { {SERVICE_MENU_ITEMS.filter((item) => - ['giftcards', 'vpn', 'esims', 'donate'].includes(item.id) ? settings?.experimental : true + ['giftcards', 'vpn', 'esims', 'donate', 'routstr'].includes(item.id) + ? settings?.experimental + : true ).map((item) => ( { + if (!currentSession) { + const id = Date.now().toString(); + createSession(id); + } + }, []); + + const openSessionSheet = () => { + SheetManager.show('routstr-session', { + payload: { sessions, current: currentSession?.id }, + }); + }; + + const handleNewSession = () => { + const id = Date.now().toString(); + createSession(id); + }; + + const handleSend = async () => { + if (!token) { + Alert.alert('No token found'); + return; + } + if (routstrBalance < MIN_BALANCE) { + Alert.alert('Balance too low, please topup'); + return; + } + if (!currentSession) return; + addMessage(currentSession.id, { role: 'user', content: input }); + setInput(''); + try { + const res = await fetch('https://api.routstr.com/v1/chat/completions', { + method: 'POST', + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + model: 'gpt-4', + messages: [...currentSession.messages, { role: 'user', content: input }], + }), + }); + const data = await res.json(); + const reply = data?.choices?.[0]?.message; + if (reply) { + addMessage(currentSession.id, reply); + } + } catch (e) { + Alert.alert('Error', 'Failed to fetch response'); + } + }; + + const renderItem = ({ item }) => ( + + + {item.role === 'user' ? 'You' : 'AI'}: {item.content} + + + ); + + return ( + + +