Skip to content

Commit 84c9498

Browse files
fix: reconcile main updates with V2 orchestration
1 parent 183655d commit 84c9498

19 files changed

Lines changed: 476 additions & 195 deletions

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { canSnooze, effectiveSnoozed } from "@t3tools/client-runtime/state/threa
44
import * as Cause from "effect/Cause";
55
import * as Haptics from "expo-haptics";
66
import { useCallback, useRef } from "react";
7-
import { Alert } from "react-native";
7+
import { Alert, Platform } from "react-native";
88

99
import { withThreadDismissal } from "./thread-dismissal";
10-
import { showConfirmDialog } from "../../components/ConfirmDialogHost";
10+
import { showConfirmDialog, showTextInputDialog } from "../../components/ConfirmDialogHost";
1111
import { scopedThreadKey } from "../../lib/scopedEntities";
1212
import { refreshArchivedThreadsForEnvironment } from "../archive/useArchivedThreadSnapshots";
1313
import { pinOrderKeyBetween } from "@t3tools/client-runtime/state/thread-sort";
@@ -28,6 +28,7 @@ import {
2828
} from "../threads/threadOrder";
2929
import { getThreadListV2OrderedSection } from "../threads/threadListV2";
3030
import { threadCanArchive } from "./threadArchive";
31+
import { resolveThreadTitleRename } from "../threads/thread-title-rename";
3132

3233
/** Version skew: never send settle/unsettle to a server that predates them
3334
(capability defaults false on decode for older servers). */
@@ -237,6 +238,7 @@ export function useThreadListActions(): {
237238
thread: EnvironmentThreadShell,
238239
direction: ThreadMoveDestination,
239240
) => Promise<boolean>;
241+
readonly renameThread: (thread: EnvironmentThreadShell) => void;
240242
readonly regenerateThreadTitle: (thread: EnvironmentThreadShell) => Promise<boolean>;
241243
} {
242244
const executeAction = useThreadActionExecutor();
@@ -471,6 +473,50 @@ export function useThreadListActions(): {
471473
},
472474
[updateThreadMetadata],
473475
);
476+
const renameThread = useCallback(
477+
(thread: EnvironmentThreadShell) => {
478+
const commit = (title: string) => {
479+
const resolution = resolveThreadTitleRename({ title, originalTitle: thread.title });
480+
if (resolution.action === "reject-empty") {
481+
Alert.alert("Could not rename thread", "Thread title cannot be empty.");
482+
return;
483+
}
484+
if (resolution.action === "noop") return;
485+
selectionHaptic();
486+
void updateThreadMetadata({
487+
environmentId: thread.environmentId,
488+
input: { threadId: thread.id, title: resolution.title },
489+
}).then((result) => {
490+
if (result._tag === "Success") return;
491+
const error = Cause.squash(result.cause);
492+
Alert.alert(
493+
"Could not rename thread",
494+
error instanceof Error && error.message.trim().length > 0
495+
? error.message
496+
: "The thread could not be renamed.",
497+
);
498+
});
499+
};
500+
501+
if (Platform.OS === "ios") {
502+
Alert.prompt(
503+
"Rename thread",
504+
undefined,
505+
(title) => commit(title ?? ""),
506+
"plain-text",
507+
thread.title,
508+
);
509+
return;
510+
}
511+
showTextInputDialog({
512+
title: "Rename thread",
513+
initialValue: thread.title,
514+
confirmText: "Rename",
515+
onConfirm: commit,
516+
});
517+
},
518+
[updateThreadMetadata],
519+
);
474520

475521
// Plan against the complete section so filtering does not change a move.
476522
const reorderPinnedMutation = useAtomCommand(threadEnvironment.reorderPin, {
@@ -650,6 +696,7 @@ export function useThreadListActions(): {
650696
pinThread,
651697
unpinThread,
652698
moveThread,
699+
renameThread,
653700
regenerateThreadTitle,
654701
};
655702
}

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@ import { isPdfFile } from "../../lib/filePreview";
8787
import { flattenThemeColor } from "../../lib/mobileTheme";
8888
import { PresentationSource } from "../../components/NativePresentation";
8989
import { useSafeAreaInsets } from "react-native-safe-area-context";
90-
import Animated, {
91-
FadeIn,
92-
FadeInUp,
93-
LinearTransition,
94-
type SharedValue,
95-
} from "react-native-reanimated";
90+
import Animated, { FadeIn, FadeInUp, type SharedValue } from "react-native-reanimated";
9691
import { useUniwindTheme } from "../../lib/useUniwindTheme";
9792
import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics";
9893
import { useFontFamily } from "../../lib/useFontFamily";
@@ -231,10 +226,9 @@ function formatMessageTime(input: string): string {
231226
return MESSAGE_TIME_FORMATTER.format(timestamp);
232227
}
233228

234-
const TURN_FOLD_HEIGHT = 42;
235-
236-
const THREAD_FEED_LAYOUT_TRANSITION = LinearTransition.duration(THREAD_DISCLOSURE_TRANSITION_MS);
237-
const THREAD_FEED_IMMEDIATE_TRANSITION = LinearTransition.duration(0);
229+
// Fixed heights mirror renderFeedEntry's classNames and are only used while
230+
// text fits at the current font settings. Larger accessibility text is measured.
231+
const TURN_FOLD_HEIGHT = 42; // min-h-11 (38.5) + mb-1 (3.5), with the mobile 14px rem
238232
// Tailwind spacing on the mobile 14px rem: px-3.5 on the user bubble, px-1 on
239233
// assistant rows. Images size their frame from these before their own layout.
240234
const USER_BUBBLE_HORIZONTAL_PADDING = 3.5 * 3.5;
@@ -2975,17 +2969,8 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
29752969
entry.type === "message" ? `message:${entry.message.role}` : entry.type
29762970
}
29772971
getFixedItemSize={getFixedItemSize}
2978-
// Android can retain stale native row positions when layout transitions
2979-
// race the measurements arriving during sync, even with duration 0.
2980-
// Keep its rows on LegendList's non-animated positioning path. On iOS,
2981-
// keep a transition installed between disclosures so containers don't remount.
2982-
itemLayoutAnimation={
2983-
Platform.OS === "android"
2984-
? undefined
2985-
: disclosureToggleSettling
2986-
? THREAD_FEED_LAYOUT_TRANSITION
2987-
: THREAD_FEED_IMMEDIATE_TRANSITION
2988-
}
2972+
// Virtualized rows must move with their measurements. Native layout
2973+
// transitions can retain stale positions during sync, even at duration 0.
29892974
onItemSizeChanged={handleItemSizeChanged}
29902975
// Measure rows well before they scroll into view so estimate→actual
29912976
// corrections land offscreen instead of under the user's finger.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ function ThreadNavigationSidebarPane(
172172
pinThread,
173173
unpinThread,
174174
moveThread,
175+
renameThread,
175176
regenerateThreadTitle,
176177
} = useThreadListActions();
177178
const threadListV2Enabled = useThreadListV2Enabled();
@@ -945,6 +946,7 @@ function ThreadNavigationSidebarPane(
945946
onSelectThread={handleSelectThread}
946947
onDeleteThread={confirmDeleteThread}
947948
onArchiveThread={archiveThread}
949+
onRenameThread={renameThread}
948950
onRegenerateThreadTitle={regenerateThreadTitle}
949951
titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
950952
settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
@@ -1062,6 +1064,7 @@ function ThreadNavigationSidebarPane(
10621064
fullSwipeWidth={props.width - 20}
10631065
onArchiveThread={archiveThread}
10641066
onDeleteThread={confirmDeleteThread}
1067+
onRenameThread={renameThread}
10651068
onRegenerateThreadTitle={regenerateThreadTitle}
10661069
titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
10671070
onSelectThread={handleSelectThread}
@@ -1104,6 +1107,7 @@ function ThreadNavigationSidebarPane(
11041107
projectByKey,
11051108
projectTitleByProjectKey,
11061109
regenerateThreadTitle,
1110+
renameThread,
11071111
props.onNewThreadInProject,
11081112
props.onNewThreadOnBranch,
11091113
props.searchQuery,

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { Alert, Platform, ScrollView, View } from "react-native";
2222
import { useSafeAreaInsets } from "react-native-safe-area-context";
2323
import { useWorkspaceState } from "../../state/workspace";
24+
import { useEnvironmentShellState } from "../../state/shell";
2425
import { restoredNewTaskDraftKey } from "../../state/new-task-draft-key";
2526
import { clearPendingThreadCreationOutcome } from "../../state/pending-thread-creation";
2627
import { recoverFailedThreadDraft } from "../../state/recover-failed-thread-draft";
@@ -84,6 +85,7 @@ import {
8485
ThreadInspectorContentStack,
8586
type ThreadInspectorMode,
8687
} from "./thread-inspector-content-stack";
88+
import { threadRouteIsHydrating } from "./thread-route-hydration";
8789

8890
interface ThreadInspectorSelection {
8991
readonly routeThreadIdentity: string | null;
@@ -119,7 +121,11 @@ interface ThreadRouteScreenProps extends ThreadRouteScreenRouteProps {
119121
readonly renderInspector?: (headerInset: number) => ReactNode;
120122
}
121123

122-
function ThreadUnavailableScreen() {
124+
/** Shows recovery only after the target route has reached a terminal unavailable state. */
125+
function ThreadUnavailableScreen(props: {
126+
readonly actionLabel: string;
127+
readonly onAction: () => void;
128+
}) {
123129
return (
124130
<ScrollView
125131
contentInsetAdjustmentBehavior="automatic"
@@ -134,6 +140,8 @@ function ThreadUnavailableScreen() {
134140
<EmptyState
135141
title="Thread unavailable"
136142
detail="This thread is not available in the current mobile snapshot."
143+
actionLabel={props.actionLabel}
144+
onAction={props.onAction}
137145
/>
138146
</ScrollView>
139147
);
@@ -148,6 +156,9 @@ export function ThreadRouteScreen(props: ThreadRouteScreenProps) {
148156
const threadIdRaw = firstRouteParam(params.threadId);
149157
const environmentId = environmentIdRaw ? EnvironmentId.make(environmentIdRaw) : null;
150158
const routeEnvironmentRuntime = useRemoteEnvironmentRuntime(environmentId);
159+
const routeEnvironmentShellState = useEnvironmentShellState(environmentId);
160+
const { onReconnectEnvironment } = useRemoteConnections();
161+
const navigation = useNavigation();
151162
const routeConnectionState =
152163
routeEnvironmentRuntime?.connectionState ?? (environmentId ? "available" : connectionState);
153164
const routeThreadKey =
@@ -173,16 +184,36 @@ export function ThreadRouteScreen(props: ThreadRouteScreenProps) {
173184
return <ThreadRouteContent {...props} selectedThreadDetailState={selectedThreadDetailState} />;
174185
}
175186

176-
const stillHydrating =
177-
workspaceState.isLoadingConnections ||
178-
routeConnectionState === "connecting" ||
179-
routeConnectionState === "reconnecting";
187+
const stillHydrating = threadRouteIsHydrating({
188+
isLoadingConnections: workspaceState.isLoadingConnections,
189+
connectionState: routeConnectionState,
190+
shellStatus: routeEnvironmentShellState.status,
191+
shellHasError: Option.isSome(routeEnvironmentShellState.error),
192+
detailStatus: selectedThreadDetailState.status,
193+
detailHasError: Option.isSome(selectedThreadDetailState.error),
194+
});
180195

181196
if (stillHydrating) {
182197
return <OpeningThreadLoadingScreen />;
183198
}
184199

185-
return <ThreadUnavailableScreen />;
200+
return (
201+
<ThreadUnavailableScreen
202+
actionLabel={
203+
routeEnvironmentRuntime === null ? "Manage environments" : "Reconnect environment"
204+
}
205+
onAction={() => {
206+
if (routeEnvironmentRuntime !== null) {
207+
onReconnectEnvironment(environmentId);
208+
return;
209+
}
210+
navigation.navigate("SettingsSheet", {
211+
screen: "SettingsContent",
212+
params: { screen: "SettingsEnvironments" },
213+
});
214+
}}
215+
/>
216+
);
186217
}
187218

188219
function ThreadRouteContent(

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
388388
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
389389
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
390390
readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
391+
readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
391392
readonly onRegenerateThreadTitle: (thread: EnvironmentThreadShell) => void;
392393
readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
393394
readonly onSnoozeThread: (thread: EnvironmentThreadShell, snoozedUntil: string) => void;
@@ -429,6 +430,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
429430
variant,
430431
onSelectThread,
431432
onDeleteThread,
433+
onRenameThread,
432434
onRegenerateThreadTitle,
433435
onNewThreadOnBranch,
434436
onSettleThread,
@@ -475,6 +477,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
475477
settledTimestamp !== null ? relativeTime(settledTimestamp) : threadTimeLabel(thread);
476478

477479
const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
480+
const handleRename = useCallback(() => onRenameThread(thread), [onRenameThread, thread]);
478481
const handleRegenerateTitle = useCallback(
479482
() => onRegenerateThreadTitle(thread),
480483
[onRegenerateThreadTitle, thread],
@@ -567,12 +570,14 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
567570
variant,
568571
],
569572
);
570-
const titleRegenerationMenuItems = useMemo<MenuAction[]>(
571-
() =>
572-
buildThreadTitleRegenerationMenuItems({
573+
const titleMenuItems = useMemo<MenuAction[]>(
574+
() => [
575+
{ id: "rename", title: "Rename", image: "square.and.pencil" },
576+
...buildThreadTitleRegenerationMenuItems({
573577
supported: props.titleRegenerationSupported,
574578
isRegenerating: thread.titleRegeneration != null,
575579
}),
580+
],
576581
[props.titleRegenerationSupported, thread.titleRegeneration],
577582
);
578583
const snoozableCardMenuActions = useMemo<MenuAction[]>(
@@ -585,43 +590,43 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
585590
subactions: snoozePresetActions,
586591
},
587592
...arrangementMenuItems,
588-
...titleRegenerationMenuItems,
593+
...titleMenuItems,
589594
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
590595
],
591-
[arrangementMenuItems, snoozePresetActions, titleRegenerationMenuItems],
596+
[arrangementMenuItems, snoozePresetActions, titleMenuItems],
592597
);
593598
const cardMenuActions = useMemo<MenuAction[]>(
594599
() => [
595600
CARD_MENU_ACTIONS[0]!,
596601
...arrangementMenuItems,
597-
...titleRegenerationMenuItems,
602+
...titleMenuItems,
598603
...CARD_MENU_ACTIONS.slice(1),
599604
],
600-
[arrangementMenuItems, titleRegenerationMenuItems],
605+
[arrangementMenuItems, titleMenuItems],
601606
);
602607
const slimMenuActions = useMemo<MenuAction[]>(
603608
() => [
604609
SLIM_MENU_ACTIONS[0]!,
605610
...arrangementMenuItems.filter(
606611
(action) => action.id !== "move-up" && action.id !== "move-down",
607612
),
608-
...titleRegenerationMenuItems,
613+
...titleMenuItems,
609614
SLIM_MENU_ACTIONS[1]!,
610615
],
611-
[arrangementMenuItems, titleRegenerationMenuItems],
616+
[arrangementMenuItems, titleMenuItems],
612617
);
613618
const snoozedMenuActions = useMemo<MenuAction[]>(
614-
() => [SNOOZED_MENU_ACTIONS[0]!, ...titleRegenerationMenuItems, SNOOZED_MENU_ACTIONS[1]!],
615-
[titleRegenerationMenuItems],
619+
() => [SNOOZED_MENU_ACTIONS[0]!, ...titleMenuItems, SNOOZED_MENU_ACTIONS[1]!],
620+
[titleMenuItems],
616621
);
617622
const legacyMenuActions = useMemo<MenuAction[]>(
618623
() => [
619624
LEGACY_MENU_ACTIONS[0]!,
620625
...arrangementMenuItems,
621-
...titleRegenerationMenuItems,
626+
...titleMenuItems,
622627
LEGACY_MENU_ACTIONS[1]!,
623628
],
624-
[arrangementMenuItems, titleRegenerationMenuItems],
629+
[arrangementMenuItems, titleMenuItems],
625630
);
626631
const handleMenuAction = useCallback(
627632
({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
@@ -635,6 +640,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
635640
if (nativeEvent.event === "move-up") handleMoveUp();
636641
if (nativeEvent.event === "move-down") handleMoveDown();
637642
if (nativeEvent.event === "archive") handleArchive();
643+
if (nativeEvent.event === "rename") handleRename();
638644
if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
639645
if (nativeEvent.event === "delete") handleDelete();
640646
if (nativeEvent.event === "snooze:custom") {
@@ -658,6 +664,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
658664
handleArchive,
659665
handleDelete,
660666
handleRegenerateTitle,
667+
handleRename,
661668
handleMoveDown,
662669
handleMoveUp,
663670
handlePin,

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
ORCHESTRATION_PROTOCOL_VERSION,
32
EnvironmentId,
43
ORCHESTRATION_PROTOCOL_VERSION,
54
PROVIDER_SEND_TURN_MAX_FILE_BYTES,

0 commit comments

Comments
 (0)