-
Notifications
You must be signed in to change notification settings - Fork 5
feat(buddy): Sobers Buddy AI companion — database foundation, feature flag, and tab navigation #426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/implement-feature-for-issue-412
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d3cfb3e
Initial plan
Copilot c3194c9
feat(buddy): add AI Buddy database schema, types, settings toggle, an…
Copilot 990cf07
test(buddy): add tests for AI Buddy types, screen, settings toggle, a…
Copilot cd474db
fix(buddy): address code review - add updated_at to messages, userId …
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // ============================================================================= | ||
| // Imports | ||
| // ============================================================================= | ||
| import React from 'react'; | ||
| import { View, Text, StyleSheet, Platform } from 'react-native'; | ||
| import { useTheme, type ThemeColors } from '@/contexts/ThemeContext'; | ||
| import { useAuth } from '@/contexts/AuthContext'; | ||
| import { useTabBarPadding } from '@/hooks/useTabBarPadding'; | ||
| import SettingsButton from '@/components/navigation/SettingsButton'; | ||
| import { Bot } from 'lucide-react-native'; | ||
| import { hexWithAlpha } from '@/lib/format'; | ||
|
|
||
| // ============================================================================= | ||
| // Component | ||
| // ============================================================================= | ||
|
|
||
| /** | ||
| * Buddy tab screen — placeholder for the Sobers Buddy AI companion. | ||
| * | ||
| * Displays a coming soon message while the full chat interface is being built. | ||
| * This screen is only visible when the user has `ai_buddy_enabled` set to true. | ||
| */ | ||
| export default function BuddyScreen(): React.ReactElement { | ||
| const { theme } = useTheme(); | ||
| const { profile } = useAuth(); | ||
| const tabBarPadding = useTabBarPadding(); | ||
| const styles = createStyles(theme); | ||
|
|
||
| return ( | ||
| <View style={[styles.container, { paddingBottom: tabBarPadding }]}> | ||
| {Platform.OS !== 'web' && <SettingsButton />} | ||
| <View style={styles.content}> | ||
| <View style={styles.iconContainer}> | ||
| <Bot size={48} color={theme.primary} /> | ||
| </View> | ||
| <Text style={styles.title}>Sobers Buddy</Text> | ||
| <Text style={styles.subtitle}>Your AI-powered accountability partner</Text> | ||
| <View style={styles.card}> | ||
| <Text style={styles.cardTitle}>Coming Soon</Text> | ||
| <Text style={styles.cardText}> | ||
| {profile?.display_name ? `Hey ${profile.display_name}! ` : ''}Sobers Buddy is an AI | ||
| companion designed to support your recovery journey. Chat, get encouragement, and | ||
| receive personalized support — all with complete privacy. | ||
| </Text> | ||
| </View> | ||
| <View style={styles.featureList}> | ||
| <Text style={styles.featureItem}>💬 Real-time chat conversations</Text> | ||
| <Text style={styles.featureItem}>🎯 Personalized recovery support</Text> | ||
| <Text style={styles.featureItem}>🔒 Private and secure</Text> | ||
| <Text style={styles.featureItem}>🤝 Non-judgmental, always supportive</Text> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| // ============================================================================= | ||
| // Styles | ||
| // ============================================================================= | ||
|
|
||
| const createStyles = (theme: ThemeColors) => | ||
| StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| backgroundColor: theme.background, | ||
| }, | ||
| content: { | ||
| flex: 1, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| paddingHorizontal: 24, | ||
| }, | ||
| iconContainer: { | ||
| width: 80, | ||
| height: 80, | ||
| borderRadius: 40, | ||
| backgroundColor: hexWithAlpha(theme.primary, 0.1), | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| marginBottom: 16, | ||
| }, | ||
| title: { | ||
| fontSize: 24, | ||
| fontFamily: theme.fontBold, | ||
| color: theme.text, | ||
| marginBottom: 8, | ||
| }, | ||
| subtitle: { | ||
| fontSize: 16, | ||
| fontFamily: theme.fontRegular, | ||
| color: theme.textSecondary, | ||
| marginBottom: 32, | ||
| textAlign: 'center', | ||
| }, | ||
| card: { | ||
| backgroundColor: theme.card, | ||
| borderRadius: 16, | ||
| padding: 20, | ||
| width: '100%', | ||
| marginBottom: 24, | ||
| borderWidth: 1, | ||
| borderColor: theme.border, | ||
| }, | ||
| cardTitle: { | ||
| fontSize: 18, | ||
| fontFamily: theme.fontSemiBold, | ||
| color: theme.primary, | ||
| marginBottom: 8, | ||
| }, | ||
| cardText: { | ||
| fontSize: 14, | ||
| fontFamily: theme.fontRegular, | ||
| color: theme.textSecondary, | ||
| lineHeight: 22, | ||
| }, | ||
| featureList: { | ||
| width: '100%', | ||
| gap: 12, | ||
| }, | ||
| featureItem: { | ||
| fontSize: 15, | ||
| fontFamily: theme.fontMedium, | ||
| color: theme.text, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ import { | |
| Sparkles, | ||
| Calendar, | ||
| BookOpen, | ||
| Bot, | ||
| } from 'lucide-react-native'; | ||
| import * as Clipboard from 'expo-clipboard'; | ||
| import { logger, LogCategory } from '@/lib/logger'; | ||
|
|
@@ -490,6 +491,7 @@ export function SettingsContent({ onDismiss }: SettingsContentProps) { | |
| const [isSavingName, setIsSavingName] = useState(false); | ||
| const [isSavingDashboard, setIsSavingDashboard] = useState(false); | ||
| const [isSavingTwelveStep, setIsSavingTwelveStep] = useState(false); | ||
| const [isSavingAiBuddy, setIsSavingAiBuddy] = useState(false); | ||
| const [showSobrietyDatePicker, setShowSobrietyDatePicker] = useState(false); | ||
| const [selectedSobrietyDate, setSelectedSobrietyDate] = useState<Date>(new Date()); | ||
| const buildInfo = getBuildInfo(); | ||
|
|
@@ -766,6 +768,44 @@ export function SettingsContent({ onDismiss }: SettingsContentProps) { | |
| } | ||
| }, [profile?.id, profile?.show_program_content, isSavingTwelveStep, refreshProfile]); | ||
|
|
||
| /** | ||
| * Handles toggling the AI Buddy feature. | ||
| * Updates profile in Supabase and refreshes profile state. | ||
| */ | ||
| const handleToggleAiBuddy = useCallback(async () => { | ||
| if (!profile?.id || isSavingAiBuddy) return; | ||
|
|
||
| setIsSavingAiBuddy(true); | ||
| try { | ||
| const currentValue = profile.ai_buddy_enabled !== false; | ||
| const newValue = !currentValue; | ||
| const { error } = await supabase | ||
| .from('profiles') | ||
| .update({ ai_buddy_enabled: newValue }) | ||
| .eq('id', profile.id); | ||
|
|
||
| if (error) throw error; | ||
|
|
||
| await refreshProfile(); | ||
|
|
||
| // Track settings change | ||
| trackEvent(newValue ? AnalyticsEvents.AI_BUDDY_ENABLED : AnalyticsEvents.AI_BUDDY_DISABLED, { | ||
| setting: 'ai_buddy_enabled', | ||
| value: newValue, | ||
| }); | ||
|
|
||
| showToast.success(newValue ? 'Sobers Buddy enabled' : 'Sobers Buddy disabled'); | ||
| } catch (error) { | ||
| const err = error instanceof Error ? error : new Error('Failed to update setting'); | ||
| logger.error('Failed to toggle AI Buddy', err, { | ||
| category: LogCategory.DATABASE, | ||
| }); | ||
| showToast.error('Failed to update. Please try again.'); | ||
| } finally { | ||
| setIsSavingAiBuddy(false); | ||
| } | ||
| }, [profile?.id, profile?.ai_buddy_enabled, isSavingAiBuddy, refreshProfile]); | ||
|
|
||
| /** | ||
| * Opens the sobriety date picker with the current sobriety date pre-selected. | ||
| */ | ||
|
|
@@ -1074,6 +1114,37 @@ export function SettingsContent({ onDismiss }: SettingsContentProps) { | |
| </View> | ||
| )} | ||
| </Pressable> | ||
| <View style={styles.separator} /> | ||
| <Pressable | ||
| testID="settings-ai-buddy-toggle" | ||
| style={styles.menuItem} | ||
| onPress={handleToggleAiBuddy} | ||
| disabled={isSavingAiBuddy} | ||
| accessibilityRole="switch" | ||
| accessibilityState={{ checked: profile?.ai_buddy_enabled !== false }} | ||
| accessibilityLabel="Enable Sobers Buddy" | ||
| > | ||
| <View style={styles.menuItemLeft}> | ||
| <Bot size={20} color={theme.textSecondary} /> | ||
| <View> | ||
| <Text style={styles.menuItemText}>Sobers Buddy</Text> | ||
| <Text style={styles.menuItemSubtext}> | ||
| AI-powered accountability partner for your recovery journey | ||
| </Text> | ||
| </View> | ||
| </View> | ||
| {isSavingAiBuddy ? ( | ||
| <ActivityIndicator size="small" color={theme.primary} /> | ||
| ) : ( | ||
| <View | ||
| style={[styles.toggle, profile?.ai_buddy_enabled !== false && styles.toggleActive]} | ||
| > | ||
| <Text style={styles.toggleText}> | ||
| {profile?.ai_buddy_enabled !== false ? 'ON' : 'OFF'} | ||
| </Text> | ||
| </View> | ||
| )} | ||
|
qltysh[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| </Pressable> | ||
| </View> | ||
| </View> | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.