Skip to content

Commit 0d49dec

Browse files
Merge remote-tracking branch 'origin/main' into t3/thread-cache-refresh-20261025
2 parents 013d3aa + b2baf75 commit 0d49dec

46 files changed

Lines changed: 2820 additions & 187 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/Stack.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ import { ThreadPullRequestsSheet } from "./features/threads/ThreadPullRequestsSh
6565
import { ThreadAgentsSheet } from "./features/threads/ThreadAgentsSheet";
6666
import { ThreadBackgroundWorkSheet } from "./features/threads/ThreadBackgroundWorkSheet";
6767
import { ThreadQueueSheet } from "./features/threads/ThreadQueueControl";
68-
import { ThreadRouteScreen } from "./features/threads/ThreadRouteScreen";
68+
import {
69+
FullscreenThreadRouteScreen,
70+
ThreadRouteScreen,
71+
} from "./features/threads/ThreadRouteScreen";
6972
import { McpAppFullscreenScreen } from "./features/threads/McpAppFullscreenScreen";
7073
import { ConnectionsRouteScreen } from "./features/connection/ConnectionsRouteScreen";
7174
import { ConnectionsNewRouteScreen } from "./features/connection/ConnectionsNewRouteScreen";
@@ -813,6 +816,13 @@ const RootStackConfig = createWorkspaceStackNavigator({
813816
linking: `${THREAD_LINKING_PREFIX}/terminal`,
814817
options: SOLID_HEADER_OPTIONS,
815818
}),
819+
ThreadInspectorFullscreen: createNativeStackScreen({
820+
screen: FullscreenThreadRouteScreen,
821+
options: {
822+
...THREAD_HEADER_OPTIONS,
823+
presentation: "fullScreenModal",
824+
},
825+
}),
816826
ThreadDevicePreview: createNativeStackScreen({
817827
screen: DevicePreviewRouteScreen,
818828
linking: `${THREAD_LINKING_PREFIX}/devices`,

‎apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx‎

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { useIsFocused, useNavigation, type StaticScreenProps } from "@react-navigation/native";
1010
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
1111
import * as Cause from "effect/Cause";
12-
import { useEffect, useRef, useState, type RefObject } from "react";
12+
import { useCallback, useEffect, useRef, useState, type RefObject } from "react";
1313
import * as Haptics from "expo-haptics";
1414
import { Accelerometer } from "expo-sensors";
1515
import { AppState, BackHandler, Pressable, StatusBar, View } from "react-native";
@@ -47,6 +47,7 @@ const OVERLAY_EXITING = FadeOut.duration(120).reduceMotion(ReduceMotion.System);
4747
type DevicePreviewRouteScreenProps = StaticScreenProps<{
4848
readonly environmentId: string;
4949
readonly threadId: string;
50+
readonly deviceKey?: string;
5051
}>;
5152

5253
export function DevicePreviewRouteScreen({ route }: DevicePreviewRouteScreenProps) {
@@ -62,27 +63,33 @@ export function DevicePreviewRouteScreen({ route }: DevicePreviewRouteScreenProp
6263
<DevicePreviewScreen
6364
environmentId={EnvironmentId.make(environmentId)}
6465
threadId={ThreadId.make(threadId)}
66+
initialDeviceKey={route.params.deviceKey}
6567
onClose={onClose}
6668
/>
6769
);
6870
}
6971

70-
function DevicePreviewScreen({
72+
export function DevicePreviewScreen({
7173
environmentId,
7274
threadId,
7375
onClose,
76+
onMaximize,
77+
initialDeviceKey,
7478
}: {
7579
readonly environmentId: EnvironmentId;
7680
readonly threadId: ThreadId;
7781
readonly onClose: () => void;
82+
readonly onMaximize?: (deviceKey: string | null) => void;
83+
readonly initialDeviceKey?: string;
7884
}) {
85+
const embedded = onMaximize !== undefined;
7986
const insets = useSafeAreaInsets();
8087
// NativeColumnContent already insets the sides, so only a book fold moves the reveal handle.
8188
const handleBounds = deriveBottomControlInsets(useNativeColumnLayoutMetrics());
8289
const { themeVariables } = useAppearancePreferences();
8390
const focused = useIsFocused();
8491
const [foreground, setForeground] = useState(AppState.currentState !== "background");
85-
const [selectedKey, setSelectedKey] = useState<string | null>(null);
92+
const [selectedKey, setSelectedKey] = useState<string | null>(initialDeviceKey ?? null);
8693
const [inputConnected, setInputConnected] = useState(false);
8794
const [streamAttempt, setStreamAttempt] = useState(0);
8895
const [shuttingDown, setShuttingDown] = useState(false);
@@ -93,10 +100,13 @@ function DevicePreviewScreen({
93100
const state = useEnvironmentQuery(deviceEnvironment.state({ environmentId, input: {} }));
94101
const previews = threadDevicePreviews(state.data, threadId);
95102
const preview = selectedThreadDevicePreview(previews, selectedKey);
96-
const onInputConnected = async (connected: boolean) => {
97-
setInputConnected(connected);
98-
if (connected) setControlsVisible(false);
99-
};
103+
const onInputConnected = useCallback(
104+
async (connected: boolean) => {
105+
setInputConnected(connected);
106+
if (connected && !embedded) setControlsVisible(false);
107+
},
108+
[embedded],
109+
);
100110
useEffect(() => {
101111
const subscription = AppState.addEventListener("change", (state) =>
102112
setForeground(state !== "background"),
@@ -107,7 +117,7 @@ function DevicePreviewScreen({
107117
if (focused && state.data !== null && previews.length === 0) onClose();
108118
}, [focused, state.data, previews.length, onClose]);
109119
useEffect(() => {
110-
if (!focused || !foreground) return;
120+
if (!focused || !foreground || embedded) return;
111121
const shaken = createShakeDetector();
112122
Accelerometer.setUpdateInterval(50);
113123
const subscription = Accelerometer.addListener((sample) => {
@@ -116,7 +126,7 @@ function DevicePreviewScreen({
116126
setControlsVisible((visible) => !visible);
117127
});
118128
return () => subscription.remove();
119-
}, [focused, foreground]);
129+
}, [focused, foreground, embedded]);
120130
useEffect(() => {
121131
if (controlsVisible) return;
122132
const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
@@ -260,7 +270,23 @@ function DevicePreviewScreen({
260270
];
261271
return (
262272
<View className="flex-1" style={{ backgroundColor: themeVariables["--color-sheet-solid"] }}>
263-
<StatusBar hidden animated />
273+
{!embedded ? <StatusBar hidden animated /> : null}
274+
{embedded ? (
275+
<View
276+
className="flex-row items-center gap-1 px-2 pb-2"
277+
style={{ paddingTop: Math.max(insets.top, 8) }}
278+
>
279+
<SheetCloseButton accessibilityLabel="Close device preview" onClose={onClose} />
280+
<AppText numberOfLines={1} className="min-w-0 flex-1 font-t3-medium text-sm">
281+
{preview?.name ?? "Devices"}
282+
</AppText>
283+
<ControlPill
284+
accessibilityLabel="Maximize device"
285+
icon="arrow.up.left.and.arrow.down.right"
286+
onPress={() => onMaximize(preview?.key ?? null)}
287+
/>
288+
</View>
289+
) : null}
264290
{preview && focused && foreground ? (
265291
<OpenDevicePreview
266292
key={`${preview.key}:${streamAttempt}`}
@@ -285,7 +311,20 @@ function DevicePreviewScreen({
285311
) : null}
286312
</View>
287313
)}
288-
{controlsVisible ? (
314+
{embedded ? (
315+
<View
316+
className="flex-row items-center justify-center gap-2 px-3 py-2"
317+
style={{ paddingBottom: Math.max(insets.bottom, 8) }}
318+
>
319+
<ControlPill
320+
accessibilityLabel="Home"
321+
icon="house"
322+
disabled={!inputConnected}
323+
onPress={pressHome}
324+
/>
325+
<DeviceOptionsMenu items={menuItems} />
326+
</View>
327+
) : controlsVisible ? (
289328
<Animated.View
290329
entering={OVERLAY_ENTERING}
291330
exiting={OVERLAY_EXITING}
@@ -321,9 +360,9 @@ function DevicePreviewScreen({
321360
accessibilityLabel="Show device controls"
322361
accessibilityHint="Shaking the phone also shows them"
323362
hitSlop={12}
324-
className="absolute h-6 w-16 items-center justify-center self-center"
363+
className="absolute h-11 w-16 items-center justify-center self-center"
325364
style={{
326-
top: Math.max(insets.top - 18, 4),
365+
top: Math.max(insets.top, 12),
327366
transform: [{ translateX: (handleBounds.left - handleBounds.right) / 2 }],
328367
}}
329368
onPress={() => setControlsVisible(true)}

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ function AdaptiveWorkspaceLayoutContent(
324324
deriveWorkspacePaneLayout({
325325
layout,
326326
viewportWidth: width,
327+
nativeWorkspace,
327328
primarySidebarPreferredVisible: showPrimarySidebar,
328329
auxiliaryPanePreferredVisible,
329330
auxiliaryPaneRole,
@@ -334,6 +335,7 @@ function AdaptiveWorkspaceLayoutContent(
334335
auxiliaryPaneRole,
335336
auxiliaryPanePreferredWidth,
336337
layout,
338+
nativeWorkspace,
337339
showPrimarySidebar,
338340
width,
339341
],

‎apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import {
2929
useState,
3030
type ComponentProps,
3131
} from "react";
32-
import { View } from "react-native";
32+
import { StyleSheet, useWindowDimensions, View } from "react-native";
3333
import { Split, type SplitHostCommands } from "react-native-screens";
34+
import { SafeAreaView } from "react-native-safe-area-context";
35+
import { GestureHandlerRootView } from "react-native-gesture-handler";
3436
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3537
import { scopedThreadKey } from "../../lib/scopedEntities";
3638
import { WorkspaceTabsProvider, useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
@@ -42,6 +44,7 @@ import { setNativelyPoppingWorkspaceRoute } from "../workspace/workspace-detail-
4244
import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
4345

4446
import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";
47+
import { WorkspacePaneDivider } from "./workspace-pane-divider";
4548
import { WorkspaceEmptyDetail } from "./WorkspaceEmptyDetail";
4649
import { NativeColumnContent as ColumnContent } from "../../native/NativeColumnContent.ios";
4750
import {
@@ -185,6 +188,15 @@ function WorkspaceColumns(
185188
sidebarByOrientation,
186189
} = useAdaptiveWorkspaceLayout();
187190
const deviceType = useDeviceType();
191+
const windowDimensions = useWindowDimensions();
192+
const nativeMetrics = useNativeLayoutMetrics();
193+
const viewportWidth = nativeMetrics?.width ?? windowDimensions.width;
194+
const [inspectorWidthFraction, setInspectorWidthFraction] = useState(0.4);
195+
const inspectorWidth = Math.max(
196+
260,
197+
Math.min(viewportWidth * 0.6, viewportWidth * inspectorWidthFraction),
198+
);
199+
const resizeStartWidth = useRef(inspectorWidth);
188200
const settingsDetailIn = (detail: readonly Route[]) =>
189201
layout.usesSplitView && detail[0] && isSettingsRoute(detail[0].name) ? detail[0] : undefined;
190202
// Split screens must remain mounted while UIKit animates a detached route away.
@@ -361,6 +373,10 @@ function WorkspaceColumns(
361373
maximumPrimaryColumnWidth: Math.max(380, layout.listPaneWidth ?? 0),
362374
preferredPrimaryColumnWidthOrFraction: layout.listPaneWidth ?? 320,
363375
minimumSecondaryColumnWidth: 320,
376+
// UIKit can retain its automatic width despite a new preference; constrain both edges.
377+
minimumInspectorColumnWidth: inspectorWidth,
378+
maximumInspectorColumnWidth: inspectorWidth,
379+
preferredInspectorColumnWidthOrFraction: inspectorWidth,
364380
}}
365381
>
366382
<Split.Column>
@@ -433,7 +449,45 @@ function WorkspaceColumns(
433449
{/* Inspector panes host their own native stacks, which UIKit insets for the Duo's
434450
vertical bar wherever they sit, so each pane insets its own content instead. */}
435451
<ColumnContent insetHorizontally={false}>
436-
<View className="flex-1 bg-screen">{inspector.render?.()}</View>
452+
<View className="flex-1 bg-screen">
453+
{inspector.render?.()}
454+
{inspector.visible ? (
455+
<GestureHandlerRootView
456+
style={[StyleSheet.absoluteFill, { zIndex: 100 }]}
457+
pointerEvents="box-none"
458+
collapsable={false}
459+
>
460+
<SafeAreaView
461+
style={{ flex: 1 }}
462+
edges={["left", "right"]}
463+
pointerEvents="box-none"
464+
>
465+
<View className="flex-1" pointerEvents="box-none">
466+
<View
467+
className="absolute inset-y-0 left-0 w-[22px] flex-row"
468+
pointerEvents="box-none"
469+
>
470+
<WorkspacePaneDivider
471+
accessibilityLabel="Resize inspector"
472+
currentWidth={inspectorWidth}
473+
resizeDirection={-1}
474+
onResizeStart={() => {
475+
resizeStartWidth.current = inspectorWidth;
476+
}}
477+
onResizeBy={(delta) => {
478+
const width = Math.max(
479+
260,
480+
Math.min(viewportWidth * 0.6, resizeStartWidth.current + delta),
481+
);
482+
setInspectorWidthFraction(width / viewportWidth);
483+
}}
484+
/>
485+
</View>
486+
</View>
487+
</SafeAreaView>
488+
</GestureHandlerRootView>
489+
) : null}
490+
</View>
437491
</ColumnContent>
438492
</Split.Inspector>
439493
</Split.Host>

‎apps/mobile/src/features/layout/workspace-pane-divider.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function WorkspacePaneDivider(props: WorkspacePaneDividerProps) {
5656
return (
5757
<GestureDetector gesture={resizeGesture}>
5858
<Pressable
59-
className="relative z-[100] -mx-[22px] w-11 self-stretch justify-center"
59+
className="relative z-[100] -mx-[22px] w-[44px] self-stretch justify-center"
6060
accessibilityActions={[
6161
{ name: "increment", label: "Make pane wider" },
6262
{ name: "decrement", label: "Make pane narrower" },

‎apps/mobile/src/features/threads/ThreadAgentsSheet.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { SubagentRow } from "./SubagentRow";
2525
import { ScreenContent } from "../../components/ui/ScreenContent";
2626
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
2727

28+
import { useOpenThreadInspector } from "./thread-inspector-navigation";
29+
2830
const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
2931

3032
type AgentsTarget = { readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
@@ -45,13 +47,22 @@ export function ThreadAgentsSheet({ route }: StaticScreenProps<AgentsTarget>) {
4547
const { layout } = useAdaptiveWorkspaceLayout();
4648
const target = route.params;
4749
const navigation = useNavigation();
50+
const openInspector = useOpenThreadInspector();
4851
const insets = useSafeAreaInsets();
4952
const turn = useThreadTurnSubagents(target);
5053
const subagents = turn?.subagents ?? [];
5154
const hasLiveAgent = (turn?.liveCount ?? 0) > 0;
5255

5356
const openChildThread = (childThreadId: ThreadId) => {
5457
void Haptics.selectionAsync();
58+
if (
59+
openInspector(target, {
60+
type: "thread",
61+
environmentId: target.environmentId,
62+
threadId: childThreadId,
63+
})
64+
)
65+
return;
5566
// Replace this leaf sheet so the child enters the workspace stack expected by Home's Back button.
5667
navigation.dispatch(
5768
StackActions.replace("Thread", {

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useOpenThreadInspector } from "./thread-inspector-navigation";
12
import { useSidebarWorkspaceTabs } from "../workspace/useSystemWorkspaceTabBar";
23
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
34
import {
@@ -15,7 +16,7 @@ import {
1516
} from "../../state/entities";
1617
import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
1718
import { ChatGptUsageLimitNotice } from "./ChatGptUsageLimitNotice";
18-
import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
19+
import { useFocusEffect, useNavigation } from "@react-navigation/native";
1920
import {
2021
effectiveSnoozed,
2122
threadWokeAt,
@@ -515,6 +516,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
515516
if (sidebarSearchActive && composerOwnsKeyboard) setComposerOwnsKeyboard(false);
516517
const navigation = useNavigation();
517518
const openLinkedThread = useOpenLinkedThread();
519+
const openInspector = useOpenThreadInspector();
518520
const { session: voiceInputSession } = useGlobalVoiceInput();
519521
const reportedModelSelection = useThreadReportedModelSelection(props.selectedThreadDetailRef);
520522
const deviceState = useEnvironmentQuery(
@@ -523,6 +525,13 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
523525
const devicePreviews = threadDevicePreviews(deviceState.data, props.selectedThread.id);
524526
const openDevicePreview = () => {
525527
Keyboard.dismiss();
528+
if (
529+
openInspector(
530+
{ environmentId: props.environmentId, threadId: props.selectedThread.id },
531+
{ type: "device", environmentId: props.environmentId, threadId: props.selectedThread.id },
532+
)
533+
)
534+
return;
526535
navigation.navigate("ThreadDevicePreview", {
527536
environmentId: props.environmentId,
528537
threadId: props.selectedThread.id,
@@ -789,12 +798,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
789798
accessibilityLabel: `Open ${childInput.hasPendingApprovals ? "approval" : "question"} from ${childInput.title}`,
790799
onPress: () => {
791800
Keyboard.dismiss();
792-
navigation.dispatch(
793-
StackActions.push("Thread", {
794-
environmentId: props.environmentId,
795-
threadId: childInput.id,
796-
}),
797-
);
801+
openLinkedThread({ environmentId: props.environmentId, threadId: childInput.id });
798802
},
799803
};
800804
}

0 commit comments

Comments
 (0)