Task #42 — Timmy Harness: Expo Mobile App ## What was built - New Expo artifact at artifacts/mobile, slug `mobile`, preview path `/mobile/` - Three-tab bottom navigation (Face, Matrix, Feed) — NativeTabs with liquid glass on iOS 26+ - Dark wizard theme (#0A0A12 background, #7C3AED accent) ## WebSocket context (context/TimmyContext.tsx) - Full WebSocket connection to /api/ws with exponential backoff reconnect (1s→30s cap) - Sends visitor_enter handshake on connect, handles ping/pong - Derives timmyMood from agent_state events (idle/thinking/working/speaking) - recentEvents list capped at 100 - sendVisitorMessage() sets mood to "thinking" immediately on send (deterministic waiting state) - speaking mood auto-reverts after estimated TTS duration ## Face tab (app/(tabs)/index.tsx) - Animated 2D wizard face via react-native-svg (hat, head, beard, eyes, pupils, mouth arc, magic orb) - AnimatedPupils: pupilScaleAnim drives actual rendered pupil Circle radius (BASE_PUPIL_R * scale) - AnimatedEyelids: eyeScaleYAnim drives top eyelid overlay via Animated.Value listener - AnimatedMouth: smileAnim + mouthOscAnim combined; SVG Path rebuilt on each frame via listener - speaking mood: 1Hz mouth oscillation via Animated.loop; per-mood body bob speed/amplitude - @react-native-voice/voice installed and statically imported; Voice.onSpeechResults wired properly - startMicPulse/stopMicPulse declared before native voice useEffect (correct hook order) - Web Speech API typed with SpeechRecognitionWindow local interface (zero `any` casts) - sendVisitorMessage() called on final transcript (also triggers thinking mood immediately) - expo-speech TTS speaks Timmy's chat replies on native ## Matrix tab (app/(tabs)/matrix.tsx) - URL normalization: strips existing protocol, uses http for localhost, https for all other hosts - Full-screen WebView with loading spinner and error/retry state; iframe fallback for web ## Feed tab (app/(tabs)/feed.tsx) - FlatList<WsEvent> with proper generics; EventConfig discriminated union (Feather|MaterialCommunityIcons) - Icon names typed via React.ComponentProps["name"] (no `any`) - Color-coded events; event count in header; empty state with connection-aware message ## Type safety - TypeScript typecheck passes with 0 errors - No `any` casts anywhere in new code ## Deviations - expo-av removed (not used; voice input handled via @react-native-voice/voice + Web Speech API) - expo-speech/expo-av NOT in app.json plugins (no config plugins — causes PluginError if listed) - app.json extra.apiDomain added for env-driven domain configuration per requirement - expo-speech pinned ~14.0.8, react-native-webview 13.15.0 for Expo SDK 54 compat - artifact.toml ensurePreviewReachable removed (Expo uses expo-domain router) - @react-native-voice/voice works in Expo Go Android; iOS needs native build (graceful fallback) Replit-Task-Id: 0748cbbf-7b84-4149-8fc0-9d697287a0e6
283 lines
6.8 KiB
TypeScript
283 lines
6.8 KiB
TypeScript
import { Feather, MaterialCommunityIcons } from "@expo/vector-icons";
|
|
import React, { useCallback } from "react";
|
|
import {
|
|
FlatList,
|
|
ListRenderItemInfo,
|
|
Platform,
|
|
StyleSheet,
|
|
Text,
|
|
View,
|
|
} from "react-native";
|
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
|
|
import { Colors } from "@/constants/colors";
|
|
import { useTimmy, type WsEvent } from "@/context/TimmyContext";
|
|
|
|
const C = Colors.dark;
|
|
|
|
type FeatherIconName = React.ComponentProps<typeof Feather>["name"];
|
|
type MCIconName = React.ComponentProps<typeof MaterialCommunityIcons>["name"];
|
|
|
|
type EventConfig =
|
|
| {
|
|
color: string;
|
|
iconFamily: "Feather";
|
|
icon: FeatherIconName;
|
|
label: (e: WsEvent) => string;
|
|
}
|
|
| {
|
|
color: string;
|
|
iconFamily: "MaterialCommunityIcons";
|
|
icon: MCIconName;
|
|
label: (e: WsEvent) => string;
|
|
};
|
|
|
|
const EVENT_CONFIG: Record<string, EventConfig> = {
|
|
job_started: {
|
|
color: C.jobStarted,
|
|
icon: "play-circle",
|
|
iconFamily: "Feather",
|
|
label: (e) => `Job started${e.agentId ? ` · ${e.agentId}` : ""}`,
|
|
},
|
|
job_completed: {
|
|
color: C.jobCompleted,
|
|
icon: "check-circle",
|
|
iconFamily: "Feather",
|
|
label: (e) => `Job completed${e.agentId ? ` · ${e.agentId}` : ""}`,
|
|
},
|
|
chat: {
|
|
color: C.chat,
|
|
icon: "message-circle",
|
|
iconFamily: "Feather",
|
|
label: (e) =>
|
|
e.agentId === "timmy"
|
|
? `Timmy: ${e.text ?? ""}`
|
|
: `${e.agentId ?? "visitor"}: ${e.text ?? ""}`,
|
|
},
|
|
agent_state: {
|
|
color: C.agentState,
|
|
icon: "cpu",
|
|
iconFamily: "Feather",
|
|
label: (e) => `${e.agentId ?? "agent"} → ${e.state ?? "?"}`,
|
|
},
|
|
visitor_count: {
|
|
color: "#8B5CF6",
|
|
icon: "users",
|
|
iconFamily: "Feather",
|
|
label: (e) => `${e.count ?? 0} visitor${e.count !== 1 ? "s" : ""} online`,
|
|
},
|
|
};
|
|
|
|
const FALLBACK_CONFIG: EventConfig = {
|
|
color: C.textMuted,
|
|
icon: "radio",
|
|
iconFamily: "Feather",
|
|
label: (e) => e.type,
|
|
};
|
|
|
|
function EventIcon({ config }: { config: EventConfig }) {
|
|
if (config.iconFamily === "MaterialCommunityIcons") {
|
|
return (
|
|
<MaterialCommunityIcons
|
|
name={config.icon}
|
|
size={16}
|
|
color={config.color}
|
|
/>
|
|
);
|
|
}
|
|
return <Feather name={config.icon} size={16} color={config.color} />;
|
|
}
|
|
|
|
function EventRow({ item }: { item: WsEvent }) {
|
|
const config = EVENT_CONFIG[item.type] ?? FALLBACK_CONFIG;
|
|
const label = config.label(item);
|
|
const time = new Date(item.timestamp).toLocaleTimeString([], {
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
second: "2-digit",
|
|
});
|
|
|
|
return (
|
|
<View style={styles.row}>
|
|
<View style={[styles.iconBadge, { backgroundColor: config.color + "22" }]}>
|
|
<EventIcon config={config} />
|
|
</View>
|
|
<View style={styles.rowContent}>
|
|
<Text style={styles.rowLabel} numberOfLines={2}>
|
|
{label}
|
|
</Text>
|
|
<Text style={[styles.rowType, { color: config.color }]}>
|
|
{item.type.replace(/_/g, " ")}
|
|
</Text>
|
|
</View>
|
|
<Text style={styles.rowTime}>{time}</Text>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const keyExtractor = (item: WsEvent) => item.id;
|
|
const renderItem = ({ item }: ListRenderItemInfo<WsEvent>) => (
|
|
<EventRow item={item} />
|
|
);
|
|
|
|
export default function FeedScreen() {
|
|
const { recentEvents, connectionStatus } = useTimmy();
|
|
const insets = useSafeAreaInsets();
|
|
const topPad = Platform.OS === "web" ? 67 : insets.top;
|
|
const bottomPad = Platform.OS === "web" ? 84 + 34 : insets.bottom + 84;
|
|
|
|
const ListEmpty = useCallback(
|
|
() => (
|
|
<View style={styles.emptyContainer}>
|
|
<Feather name="radio" size={48} color={C.textMuted} />
|
|
<Text style={styles.emptyTitle}>Waiting for events</Text>
|
|
<Text style={styles.emptySubtitle}>
|
|
{connectionStatus === "connected"
|
|
? "Events will appear here as Timmy works"
|
|
: "Connect to the API server to see live events"}
|
|
</Text>
|
|
</View>
|
|
),
|
|
[connectionStatus]
|
|
);
|
|
|
|
return (
|
|
<View style={[styles.container, { paddingTop: topPad }]}>
|
|
<View style={styles.header}>
|
|
<View>
|
|
<Text style={styles.title}>Live Feed</Text>
|
|
<Text style={styles.subtitle}>
|
|
{recentEvents.length} event{recentEvents.length !== 1 ? "s" : ""}
|
|
</Text>
|
|
</View>
|
|
<View style={styles.countBadge}>
|
|
<Text style={styles.countText}>{recentEvents.length}</Text>
|
|
</View>
|
|
</View>
|
|
|
|
<FlatList<WsEvent>
|
|
data={recentEvents}
|
|
keyExtractor={keyExtractor}
|
|
renderItem={renderItem}
|
|
ListEmptyComponent={ListEmpty}
|
|
contentContainerStyle={[
|
|
styles.listContent,
|
|
{ paddingBottom: bottomPad },
|
|
]}
|
|
showsVerticalScrollIndicator={false}
|
|
ItemSeparatorComponent={() => <View style={styles.separator} />}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: C.background,
|
|
},
|
|
header: {
|
|
flexDirection: "row",
|
|
justifyContent: "space-between",
|
|
alignItems: "flex-start",
|
|
paddingHorizontal: 24,
|
|
paddingTop: 12,
|
|
paddingBottom: 16,
|
|
},
|
|
title: {
|
|
fontSize: 28,
|
|
fontFamily: "Inter_700Bold",
|
|
color: C.text,
|
|
letterSpacing: -0.5,
|
|
},
|
|
subtitle: {
|
|
fontSize: 13,
|
|
fontFamily: "Inter_400Regular",
|
|
color: C.textSecondary,
|
|
marginTop: 2,
|
|
},
|
|
countBadge: {
|
|
backgroundColor: C.surface,
|
|
borderRadius: 20,
|
|
paddingHorizontal: 12,
|
|
paddingVertical: 4,
|
|
borderWidth: 1,
|
|
borderColor: C.border,
|
|
alignSelf: "flex-start",
|
|
marginTop: 8,
|
|
},
|
|
countText: {
|
|
fontSize: 13,
|
|
fontFamily: "Inter_600SemiBold",
|
|
color: C.textSecondary,
|
|
},
|
|
listContent: {
|
|
paddingHorizontal: 16,
|
|
flexGrow: 1,
|
|
},
|
|
row: {
|
|
flexDirection: "row",
|
|
alignItems: "flex-start",
|
|
gap: 12,
|
|
paddingVertical: 12,
|
|
paddingHorizontal: 4,
|
|
},
|
|
iconBadge: {
|
|
width: 36,
|
|
height: 36,
|
|
borderRadius: 10,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
flexShrink: 0,
|
|
},
|
|
rowContent: {
|
|
flex: 1,
|
|
gap: 3,
|
|
},
|
|
rowLabel: {
|
|
fontSize: 13,
|
|
fontFamily: "Inter_400Regular",
|
|
color: C.text,
|
|
lineHeight: 18,
|
|
},
|
|
rowType: {
|
|
fontSize: 11,
|
|
fontFamily: "Inter_500Medium",
|
|
textTransform: "uppercase",
|
|
letterSpacing: 0.5,
|
|
},
|
|
rowTime: {
|
|
fontSize: 11,
|
|
fontFamily: "Inter_400Regular",
|
|
color: C.textMuted,
|
|
flexShrink: 0,
|
|
marginTop: 2,
|
|
},
|
|
separator: {
|
|
height: 1,
|
|
backgroundColor: C.border,
|
|
opacity: 0.5,
|
|
},
|
|
emptyContainer: {
|
|
flex: 1,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
paddingTop: 80,
|
|
gap: 12,
|
|
paddingHorizontal: 40,
|
|
},
|
|
emptyTitle: {
|
|
fontSize: 18,
|
|
fontFamily: "Inter_600SemiBold",
|
|
color: C.textSecondary,
|
|
marginTop: 8,
|
|
},
|
|
emptySubtitle: {
|
|
fontSize: 14,
|
|
fontFamily: "Inter_400Regular",
|
|
color: C.textMuted,
|
|
textAlign: "center",
|
|
lineHeight: 20,
|
|
},
|
|
});
|