Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/mobile/src/components/ui/ListRowLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ export interface ListRowContentProps {
readonly detail?: string;
/** Rich secondary content under the description, such as scores with emphasized values. */
readonly meta?: ReactNode;
/** Room for a leading mark wider than the default glyph slot, such as a Tot's face. */
readonly leadingSize?: number;
readonly disabled?: boolean;
}

export function ListRowLayout({
icon,
leading,
leadingSize = 24,
label,
description,
detail,
Expand Down Expand Up @@ -49,7 +52,12 @@ export function ListRowLayout({
/>
</View>
) : leading ? (
<View className="size-6 items-center justify-center">{leading}</View>
<View
className="items-center justify-center"
style={{ width: leadingSize, height: leadingSize }}
>
{leading}
</View>
) : null}
<View className="min-w-0 flex-1 gap-1">
<AppText
Expand Down
4 changes: 4 additions & 0 deletions apps/mobile/src/features/threads/ThreadDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ import {
import { ComposerPopoverHost } from "./ComposerPopoverHost";
import { ThreadFeed, type ThreadFeedHistoryControls } from "./ThreadFeed";
import { useTotThemeTokens } from "../tots/useTotThemeTokens";
import { useThreadTot } from "../../state/tots";
import { WorkspaceMutationIdProvider } from "./WorkspaceMutationIdProvider";
import { useThreadTurnSubagents } from "./ThreadAgentsSheet";
import { ComposerQueuedEditBanner } from "./ComposerQueuedEdit";
Expand Down Expand Up @@ -1374,6 +1375,8 @@ function ThreadDetailBody(
const { themeAppearance } = useAppearancePreferences();
const isDarkMode = themeAppearance === "dark";
const totTheme = useTotThemeTokens(props.environmentId, props.selectedThread.id);
// The same shell the list resolves, so a Tot's card and its thread agree on whose it is.
const tot = useThreadTot(props.selectedThread);

const handleFeedTouchStart = (event: GestureResponderEvent) => {
feedTouchStartRef.current = {
Expand Down Expand Up @@ -1452,6 +1455,7 @@ function ThreadDetailBody(
toolCallVisibility={toolCallVisibility}
environmentId={props.environmentId}
threadId={props.selectedThread.id}
tot={tot}
detailRef={props.selectedThreadDetailRef}
workspaceRoot={props.threadCwd}
feed={props.selectedThreadFeed}
Expand Down
9 changes: 5 additions & 4 deletions apps/mobile/src/features/threads/ThreadFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import * as Haptics from "expo-haptics";
import { KeyboardAwareLegendList } from "@legendapp/list/keyboard";
import { useViewabilityAmount, type LegendListRef } from "@legendapp/list/react-native";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import { TOT_FACE_STATE_LABELS } from "@t3tools/client-runtime/tots";
import { TOT_FACE_STATE_LABELS, type EnvironmentTot } from "@t3tools/client-runtime/tots";
import type { HandoffEndpoints } from "@t3tools/client-runtime/handoff";
import {
IDLE_COMPACTING_LABELS,
Expand Down Expand Up @@ -327,7 +327,7 @@ import { ZoomableImagePressable } from "./ZoomableImagePressable";
import { openSettings } from "../settings/settings-navigation";
import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";
import { useMessageTimeFormatter } from "./useMessageTimeFormatter";
import { useAnimateTotAvatars, useThreadTot, useTotFace } from "../../state/tots";
import { useAnimateTotAvatars, useTotFace } from "../../state/tots";
import { totThemeColor, useTotThemeTokens } from "../tots/useTotThemeTokens";
import { TotLiveFace } from "../tots/TotLiveFace";
import { TOT_THREAD_HEADER_HEIGHT, TotThreadHeader } from "../tots/TotThreadHeader";
Expand Down Expand Up @@ -368,6 +368,8 @@ export interface ThreadFeedProps {
readonly onEditPendingMessage: ((message: QueuedThreadMessage) => void) | null;
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
/** The Tot whose thread this is, resolved from the thread shell as the list resolves it. */
readonly tot: EnvironmentTot | null;
/** Null while the thread's creation is queued: reading detail then caches a not-found as deleted. */
readonly detailRef: ScopedThreadRef | null;
readonly threadTitle: string;
Expand Down Expand Up @@ -3062,8 +3064,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
const gt = useGT();
const m = useMessages();
const formatMessageTime = useMessageTimeFormatter();
const { listRef, onIsAtEndChange, onHeaderMaterialVisibilityChange } = props;
const tot = useThreadTot({ environmentId: props.environmentId, id: props.threadId });
const { listRef, onIsAtEndChange, onHeaderMaterialVisibilityChange, tot } = props;
const totTheme = useTotThemeTokens(props.environmentId, props.threadId);
const totFace = useTotFace(tot);
const animateTot = useAnimateTotAvatars();
Expand Down
91 changes: 91 additions & 0 deletions apps/mobile/src/features/tots/TotCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { TOT_FACE_STATE_LABELS, type EnvironmentTot } from "@t3tools/client-runtime/tots";
import type { TotFaceState } from "@t3tools/contracts";
import { Platform, Pressable, View } from "react-native";
import { useResolveClassNames } from "uniwind";

import { AppText } from "../../components/ui/AppText";
import { SymbolView } from "../../components/ui/AppSymbol";
import { RowPressable } from "../../components/ui/RowPressable";
import { TOT_STATE_PRESENTATION } from "./totStatePresentation";
import { TotLiveFace } from "./TotLiveFace";
import { TotStatePill } from "./TotStatePill";
import { TotStillFace } from "./TotStillFace";

/** Big enough that its eyes read at arm's length, on a phone and on a Fold. */
const FACE_SIZE = 64;
export const TOT_CARD_MIN_HEIGHT = 172;

/**
* One Tot in the Tots tab: its face, its name, what it is doing. The whole card opens the Tot;
* the small slider in the corner is the secondary trip to its editor.
*/
export function TotCard(props: {
readonly entry: EnvironmentTot;
readonly state: TotFaceState;
readonly machine: string | null;
readonly width: number;
readonly animate: boolean;
readonly onOpen: () => void;
readonly onEdit: () => void;
}) {
const { tot } = props.entry;
const accent = tot.avatar.color;
const presentation = TOT_STATE_PRESENTATION[props.state];
const rippleStyle = useResolveClassNames("bg-subtle-strong");
// A moving face costs a WebView, so only a Tot that is actually doing something gets one.
const live = props.animate && (props.state === "working" || props.state === "needs-you");
return (
<RowPressable
accessibilityRole="button"
accessibilityLabel={[
tot.name,
TOT_FACE_STATE_LABELS[props.state],
props.machine === null ? null : `on ${props.machine}`,
]
.filter((part) => part !== null)
.join(", ")}
accessibilityHint={tot.threadId === null ? "Opens its editor" : "Opens its conversation"}
onPress={props.onOpen}
android_ripple={{ color: rippleStyle.backgroundColor }}
unstable_pressDelay={Platform.OS === "android" ? 50 : undefined}
className={`rounded-3xl border bg-grouped-card ${presentation.cardClassName}`}
style={{ width: props.width, minHeight: TOT_CARD_MIN_HEIGHT }}
>
<View className="flex-1 items-center justify-center gap-2.5 px-3 pb-4 pt-5">
<View
className="items-center justify-center"
style={{ padding: 6, borderRadius: 30, backgroundColor: `${accent}24` }}
>
{live ? (
<TotLiveFace avatar={tot.avatar} state={props.state} size={FACE_SIZE} animate />
) : (
<TotStillFace avatar={tot.avatar} state={props.state} size={FACE_SIZE} />
)}
</View>
<AppText numberOfLines={1} className="text-[15px] font-t3-semibold text-foreground">
{tot.name}
</AppText>
<TotStatePill state={props.state} accent={accent} />
{props.machine === null ? null : (
<AppText numberOfLines={1} className="text-xs text-foreground-tertiary">
{props.machine}
</AppText>
)}
</View>
<Pressable
accessibilityRole="button"
accessibilityLabel={`Edit ${tot.name}`}
onPress={props.onEdit}
hitSlop={10}
className="absolute right-1.5 top-1.5 size-10 items-center justify-center"
>
<SymbolView
name="slider.horizontal.3"
size={16}
tintColorClassName="accent-foreground-tertiary"
type="monochrome"
/>
</Pressable>
</RowPressable>
);
}
18 changes: 16 additions & 2 deletions apps/mobile/src/features/tots/TotLiveFace.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import totFaceScript from "@t3tools/mobile-totface-stream";
import { TOT_FACE_ACTION, type TotAvatar, type TotFaceState } from "@t3tools/contracts";
import { useEffect, useRef, useState } from "react";
import { View } from "react-native";
import { StyleSheet, View } from "react-native";
import { WebView } from "react-native-webview";

import { TotStillFace } from "./TotStillFace";
Expand Down Expand Up @@ -36,6 +36,8 @@ export function TotLiveFace(props: {
const [source] = useState(() => ({
html: faceDocument(faceMessage(props.avatar, props.state, props.size)),
}));
// The WebView paints nothing until its document loads, which read as a missing face.
const [painted, setPainted] = useState(false);
const message = faceMessage(props.avatar, props.state, props.size);

// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- sends the new face to the WebView
Expand All @@ -48,14 +50,26 @@ export function TotLiveFace(props: {
}
return (
<View style={{ width: props.size, height: props.size }} pointerEvents="none">
{/* The still pose stands in until the WebView has something to show. */}
{painted ? null : (
<View style={StyleSheet.absoluteFill} pointerEvents="none">
<TotStillFace avatar={props.avatar} state={props.state} size={props.size} />
</View>
)}
<WebView<object>
ref={webView}
source={source}
originWhitelist={["about:blank"]}
scrollEnabled={false}
bounces={false}
setSupportMultipleWindows={false}
style={{ width: props.size, height: props.size, backgroundColor: "transparent" }}
onLoadEnd={() => setPainted(true)}
style={{
width: props.size,
height: props.size,
backgroundColor: "transparent",
opacity: painted ? 1 : 0,
}}
containerStyle={{ backgroundColor: "transparent" }}
onShouldStartLoadWithRequest={(request) => request.url === "about:blank"}
/>
Expand Down
34 changes: 34 additions & 0 deletions apps/mobile/src/features/tots/TotStatePill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { TOT_FACE_STATE_LABELS } from "@t3tools/client-runtime/tots";
import type { TotFaceState } from "@t3tools/contracts";
import { View } from "react-native";

import { AppText } from "../../components/ui/AppText";
import { cn } from "../../lib/cn";
import { TOT_STATE_PRESENTATION } from "./totStatePresentation";

/** What a Tot is doing, in the same shape on its card and above its conversation. */
export function TotStatePill(props: {
readonly state: TotFaceState;
/** The Tot's own colour, used for the state it is in most. */
readonly accent: string;
readonly size?: "card" | "band";
}) {
const presentation = TOT_STATE_PRESENTATION[props.state];
return (
<View
className={cn("flex-row items-center rounded-full px-2.5 py-1", presentation.pillClassName)}
>
<AppText
numberOfLines={1}
className={cn(
"font-t3-medium",
props.size === "band" ? "text-[13px]" : "text-xs",
presentation.textClassName,
)}
style={presentation.accentText ? { color: props.accent } : undefined}
>
{TOT_FACE_STATE_LABELS[props.state]}
</AppText>
</View>
);
}
87 changes: 54 additions & 33 deletions apps/mobile/src/features/tots/TotThreadHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { TOT_FACE_STATE_LABELS, type EnvironmentTot } from "@t3tools/client-runtime/tots";
import type { TotThemeTokens } from "@t3tools/shared/totThemeTokens";
import { View } from "react-native";
import { Platform, View } from "react-native";

import { AppText } from "../../components/ui/AppText";
import { cn } from "../../lib/cn";
import { useTotFace } from "../../state/tots";
import { TotLiveFace } from "./TotLiveFace";
import { TotStatePill } from "./TotStatePill";

const FACE_SIZE = 36;
const FACE_RING = 1.5;
const FACE_RING = 6;

/** How tall the pinned identity band is, so the feed can clear it. */
export const TOT_THREAD_HEADER_HEIGHT = 52;
export const TOT_THREAD_HEADER_HEIGHT = 64;
const FACE_SIZE = 42;

/** The Tot you are talking to: its face, name and what it is doing, above its thread. */
/**
* The Tot you are talking to: its face, its name, what it is doing. It sits under the navigation
* bar on the Tot's own wash, so the thread header keeps the title and this keeps the identity.
*/
export function TotThreadHeader(props: {
readonly entry: EnvironmentTot;
readonly animate: boolean;
Expand All @@ -23,47 +28,63 @@ export function TotThreadHeader(props: {
const state = useTotFace(props.entry);
const label = TOT_FACE_STATE_LABELS[state];
const tokens = props.tokens;
const accent = tot.avatar.color;
const bandBackground = tokens["--tot-bg"];
const bandBorder = tokens["--tot-border"];
const textColor = tokens["--tot-text"];
const mutedColor = tokens["--tot-muted"];
return (
<View
accessible
accessibilityRole="header"
accessibilityLabel={`${tot.name}, Tot, ${label}`}
className="flex-row items-center gap-2.5 border-b border-separator bg-screen px-4"
className={cn(
"border-b border-separator",
Platform.OS === "android" ? "bg-thread-canvas" : "bg-screen",
)}
style={{
height: TOT_THREAD_HEADER_HEIGHT,
...(bandBackground === undefined ? null : { backgroundColor: bandBackground }),
...(bandBorder === undefined ? null : { borderBottomColor: bandBorder }),
...(tokens["--tot-border"] === undefined
? null
: { borderBottomColor: tokens["--tot-border"] }),
}}
>
{/* The feed scrolls under this band, so a theme's translucent --tot-bg and the accent wash
both sit over the opaque canvas colour instead of replacing it. */}
{bandBackground === undefined ? null : (
<View
pointerEvents="none"
className="absolute inset-0"
style={{ backgroundColor: bandBackground }}
/>
)}
<View
style={{
padding: FACE_RING,
borderRadius: 12,
borderWidth: FACE_RING,
borderColor: `${tot.avatar.color}73`,
}}
>
<TotLiveFace avatar={tot.avatar} state={state} size={FACE_SIZE} animate={props.animate} />
pointerEvents="none"
className="absolute inset-0"
style={{ backgroundColor: `${accent}14` }}
/>
<View className="flex-1 flex-row items-center gap-3 px-4">
<View
className="items-center justify-center"
style={{
padding: FACE_RING,
borderRadius: 32,
backgroundColor: `${accent}21`,
}}
>
<TotLiveFace avatar={tot.avatar} state={state} size={FACE_SIZE} animate={props.animate} />
</View>
<View className="min-w-0 flex-1 justify-center gap-1">
<AppText
numberOfLines={1}
className="font-t3-semibold text-lg text-foreground"
style={textColor === undefined ? undefined : { color: textColor }}
>
{tot.name}
</AppText>
<View className="flex-row">
<TotStatePill size="band" state={state} accent={accent} />
</View>
</View>
</View>
<AppText
numberOfLines={1}
className="shrink font-t3-bold text-sm text-foreground"
style={textColor === undefined ? undefined : { color: textColor }}
>
{tot.name}
</AppText>
<View className="flex-1" />
<AppText
numberOfLines={1}
className="shrink text-xs text-foreground-muted"
style={mutedColor === undefined ? undefined : { color: mutedColor }}
>
{label}
</AppText>
</View>
);
}
Loading