Skip to content
TypeScript

fix(web,mobile): queued messages get a simpler Send now row, no reordering (#25846)

Theo Browne92e645032c35
diff --git a/apps/mobile/src/features/threads/ThreadQueueControl.tsx b/apps/mobile/src/features/threads/ThreadQueueControl.tsx
index 3f9ca611312..093966bc2e6 100644
--- a/apps/mobile/src/features/threads/ThreadQueueControl.tsx
+++ b/apps/mobile/src/features/threads/ThreadQueueControl.tsx
@@ -8,15 +8,14 @@ import type { ChatAttachment, EnvironmentId, RunId, ThreadId } from "@t3tools/co
import { Atom } from "effect/reactivity";
import { Image } from "expo-image";
import * as Haptics from "expo-haptics";
-import { useEffect, useEffectEvent, useRef, useState } from "react";
-import { Animated, Platform, Pressable, ScrollView, View } from "react-native";
-import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
+import { useEffect, useRef, useState } from "react";
+import { Platform, Pressable, ScrollView, View } from "react-native";
+import { GestureHandlerRootView } from "react-native-gesture-handler";
import ReanimatedSwipeable, {
type SwipeableMethods,
} from "react-native-gesture-handler/ReanimatedSwipeable";
import { Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
import { useSafeAreaInsets } from "react-native-safe-area-context";
-import Reanimated, { ReduceMotion, useAnimatedStyle, withTiming } from "react-native-reanimated";
import { Button } from "../../components/ui/Button";
import { AndroidSheetHeader } from "../../components/ui/AndroidScreenHeader";
@@ -36,11 +35,8 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
import {
REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
buildCancelQueuedRunCommand,
- resolveQueueDragBeforeRunId,
- resolveQueueDropBeforeRunId,
resolveThreadQueueRowControls,
} from "./threadQueueControlPresentation";
-import { threadDragGapOffset } from "./threadDragGap";
const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
const REMOVE_ACTION_WIDTH = 76;
@@ -50,14 +46,7 @@ const EMPTY_QUEUED_COUNT_ATOM = Atom.make(0).pipe(
);
type QueueTarget = { readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
-type QueueAction = "steer" | "edit" | "up" | "down" | "remove";
-type QueueRowLayout = { readonly id: RunId; readonly y?: number; readonly height?: number };
-type QueueDrag = {
- readonly runId: RunId;
- readonly order: string;
- beforeRunId: RunId | null | undefined;
- readonly rows: ReadonlyArray<QueueRowLayout>;
-};
+type QueueAction = "steer" | "edit" | "remove";
export function useThreadQueueWorkflow(target: QueueTarget) {
return useAtomValue(environmentThreadDetails.queueWorkflowAtom(target));
@@ -82,25 +71,13 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
const editBlockedReason = queuedRunEditBlockedReason({
openQuestionCount: pendingRequests?.userInputs.length ?? 0,
});
- const reorder = useAtomCommand(threadEnvironment.reorderQueuedRun, "reorder queued message");
const promote = useAtomCommand(threadEnvironment.promoteQueuedRun, "promote queued message");
const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun, "remove queued message");
const resume = useAtomCommand(threadEnvironment.resumeThreadQueue, "resume queue");
const [resuming, setResuming] = useState(false);
const [busyRunId, setBusyRunId] = useState<RunId | null>(null);
const busyRef = useRef(false);
- const [dragState, setDragState] = useState<QueueDrag | null>(null);
- const rowLayouts = useRef(new Map<RunId, { y: number; height: number }>());
- const drag = useRef<QueueDrag | null>(null);
- const [translation] = useState(() => new Animated.Value(0));
const queuedRuns = workflow?.queuedRuns ?? [];
- const order = queuedRuns.map(({ run }) => run.id).join(",");
- // A queue that changed under the drag (delivery, another client) ends it:
- // the gesture handlers ignore it from then on and its preview disappears.
- const visibleDrag = dragState?.order === order ? dragState : null;
- const draggedRunId = visibleDrag?.runId ?? null;
- const previewBeforeRunId = visibleDrag?.beforeRunId;
- const dragRows = visibleDrag?.rows ?? null;
const hadQueuedRuns = useRef(queuedRuns.length > 0);
useEffect(() => {
@@ -111,28 +88,10 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
if (hadQueuedRuns.current) navigation.goBack();
}, [navigation, queuedRuns.length]);
- const move = async (runId: RunId, beforeRunId: RunId | null) => {
- if (busyRef.current || !workflow?.canReorder) return;
- busyRef.current = true;
- setBusyRunId(runId);
- void Haptics.selectionAsync();
- await reorder({ ...target, input: { threadId: target.threadId, runId, beforeRunId } });
- busyRef.current = false;
- setBusyRunId(null);
- };
-
const act = async (runId: RunId, action: QueueAction) => {
if (busyRef.current) return;
const index = queuedRuns.findIndex(({ run }) => run.id === runId);
if (index < 0) return;
- if (action === "up" && index > 0) {
- await move(runId, queuedRuns[index - 1]!.run.id);
- return;
- }
- if (action === "down" && index < queuedRuns.length - 1) {
- await move(runId, queuedRuns[index + 2]?.run.id ?? null);
- return;
- }
if (action === "edit") {
if (editBlockedReason !== null) return;
const entry = queuedRuns[index]!;
@@ -180,24 +139,10 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
setBusyRunId(null);
};
- const canReorder = workflow?.canReorder === true && queuedRuns.length > 1;
- const sourceLayout = dragRows?.find((row) => row.id === draggedRunId);
- const lastLayout = dragRows?.at(-1);
- const insertionOffset =
- previewBeforeRunId === undefined
- ? undefined
- : previewBeforeRunId === null
- ? lastLayout?.y === undefined || lastLayout.height === undefined
- ? undefined
- : lastLayout.y + lastLayout.height
- : dragRows?.find((row) => row.id === previewBeforeRunId)?.y;
- const queueRows = () =>
- queuedRuns.map(({ run }) => ({ id: run.id, ...rowLayouts.current.get(run.id) }));
const content = (
<ScrollView
nestedScrollEnabled
className="flex-1"
- scrollEnabled={draggedRunId === null}
// UIKit must inset content beneath the floating translucent iOS header.
contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
contentContainerClassName="px-5 pb-6"
@@ -229,222 +174,118 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
</Text>
) : null}
{queuedRuns.map(({ run, text, attachments, context }, index) => {
- const layout = dragRows?.find((row) => row.id === run.id);
- const offset =
- sourceLayout?.y !== undefined &&
- sourceLayout.height !== undefined &&
- layout?.y !== undefined &&
- insertionOffset !== undefined
- ? threadDragGapOffset(layout.y, sourceLayout.y, sourceLayout.height, insertionOffset)
- : 0;
const controls = resolveThreadQueueRowControls({
- busy: busyRunId !== null || draggedRunId !== null,
+ busy: busyRunId !== null,
canPromoteToSteer: workflow?.canPromoteToSteer ?? false,
canSendNow: workflow?.canSendNow ?? false,
- canReorder: workflow?.canReorder ?? false,
editBlocked: editBlockedReason !== null,
- index,
isEditing: editing?.runId === run.id,
isGuestMessage: context?.guest !== undefined,
- queuedCount: queuedRuns.length,
text,
});
const title =
controls.displayText || (attachments.length > 0 ? "Attachments" : "Queued message");
return (
- <QueueShiftedRow
- key={run.id}
- offset={offset}
- dragging={draggedRunId !== null}
- lifted={draggedRunId === run.id}
- onLayout={({ nativeEvent }) => rowLayouts.current.set(run.id, nativeEvent.layout)}
- >
- <Animated.View
- className="flex-row items-center border-b border-border bg-sheet"
- style={
- draggedRunId === run.id
- ? { transform: [{ translateY: translation }], zIndex: 1, opacity: 0.85 }
- : undefined
- }
+ <View key={run.id} className="flex-row items-center border-b border-border bg-sheet">
+ <QueueRowSwipeable
+ enabled={busyRunId === null && controls.canDismiss}
+ background={theme["--color-sheet"]}
+ onRemove={() => void act(run.id, "remove")}
>
- {canReorder ? (
- // Keep the vertical handle outside the sideways swipeable so their pans do not race.
- <QueueDragHandle
- disabled={busyRunId !== null}
- title={title}
- canMoveUp={controls.canMoveUp}
- canMoveDown={controls.canMoveDown}
- onStep={(action) => void act(run.id, action)}
- onStart={() => {
- const rows = queueRows();
- const beforeRunId = resolveQueueDragBeforeRunId(rows, run.id, 0);
- drag.current = { runId: run.id, order, beforeRunId, rows };
- translation.setValue(0);
- setDragState({ ...drag.current });
- void Haptics.selectionAsync();
- }}
- onMove={(y) => {
- const current = drag.current;
- if (current?.runId !== run.id || current.order !== order) return;
- translation.setValue(y);
- const before = resolveQueueDragBeforeRunId(current.rows, run.id, y);
- if (current.beforeRunId !== before) {
- current.beforeRunId = before;
- setDragState({ ...current });
- }
- }}
- onEnd={(y, success) => {
- const started = drag.current;
- const stop = () => {
- if (drag.current !== started) return;
- drag.current = null;
- setDragState(null);
- translation.setValue(0);
- };
- if (!success || started?.order !== order || started.runId !== run.id) {
- stop();
- return;
- }
- const before = resolveQueueDropBeforeRunId(started.rows, run.id, y);
- if (before === undefined) {
- stop();
- return;
- }
- const source = started.rows.find((row) => row.id === run.id);
- const tail = started.rows.at(-1);
- const insertion =
- before === null
- ? tail?.y !== undefined && tail.height !== undefined
- ? tail.y + tail.height
- : undefined
- : started.rows.find((row) => row.id === before)?.y;
- if (
- source?.y !== undefined &&
- source.height !== undefined &&
- insertion !== undefined
- ) {
- Animated.timing(translation, {
- toValue: insertion - source.y - (insertion > source.y ? source.height : 0),
- duration: 160,
- useNativeDriver: true,
- }).start();
- }
- started.beforeRunId = before;
- setDragState({ ...started });
- void move(run.id, before).finally(stop);
- }}
- />
- ) : null}
- <QueueRowSwipeable
- enabled={draggedRunId === null && busyRunId === null && controls.canDismiss}
- background={theme["--color-sheet"]}
- onRemove={() => void act(run.id, "remove")}
- >
- <View className="flex-row items-center">
- <Menu
- accessibilityLabel={`Actions for queued message ${index + 1}`}
- shouldOpenOnLongPress
- style={{ flex: 1 }}
- actions={[
- ...(workflow?.canPromoteToSteer || workflow?.canSendNow
- ? [
- {
- id: "steer",
- title: workflow?.canSendNow ? "Send now" : "Steer now",
- attributes: { disabled: !controls.canSend },
- image: Platform.OS === "ios" ? "arrow.turn.left.up" : "arrow_upward",
- },
- ]
- : []),
- {
- id: "edit",
- title: "Edit",
- attributes: { disabled: !controls.canEdit },
- image: Platform.OS === "ios" ? "pencil" : "edit",
- },
- { id: "up", title: "Move up", attributes: { disabled: !controls.canMoveUp } },
- {
- id: "down",
- title: "Move down",
- attributes: { disabled: !controls.canMoveDown },
- },
- {
- id: "remove",
- title: "Remove",
- attributes: { disabled: !controls.canDismiss, destructive: true },
- },
- ]}
- onPressAction={({ nativeEvent }) =>
- void act(run.id, nativeEvent.event as QueueAction)
+ <View className="flex-row items-center">
+ <Menu
+ accessibilityLabel={`Actions for queued message ${index + 1}`}
+ shouldOpenOnLongPress
+ style={{ flex: 1 }}
+ actions={[
+ ...(workflow?.canPromoteToSteer || workflow?.canSendNow
+ ? [
+ {
+ id: "steer",
+ title: "Send now",
+ attributes: { disabled: !controls.canSend },
+ image: Platform.OS === "ios" ? "arrow.up" : "arrow_upward",
+ },
+ ]
+ : []),
+ {
+ id: "edit",
+ title: "Edit",
+ attributes: { disabled: !controls.canEdit },
+ image: Platform.OS === "ios" ? "pencil" : "edit",
+ },
+ {
+ id: "remove",
+ title: "Remove",
+ attributes: { disabled: !controls.canDismiss, destructive: true },
+ },
+ ]}
+ onPressAction={({ nativeEvent }) =>
+ void act(run.id, nativeEvent.event as QueueAction)
+ }
+ >
+ <Pressable
+ accessibilityRole="button"
+ accessibilityLabel={title}
+ accessibilityHint={
+ controls.canEdit
+ ? "Opens this message in the composer for editing"
+ : (editBlockedReason ?? undefined)
}
+ disabled={!controls.canEdit}
+ onPress={() => void act(run.id, "edit")}
+ className="min-h-14 flex-row items-center gap-2.5 py-2.5 active:opacity-70"
>
- <Pressable
- accessibilityRole="button"
- accessibilityLabel={title}
- accessibilityHint={
- controls.canEdit
- ? "Opens this message in the composer for editing"
- : (editBlockedReason ?? undefined)
+ <QueueAttachmentThumbnails
+ environmentId={target.environmentId}
+ attachments={attachments}
+ />
+ <Text
+ className={
+ controls.isEditing
+ ? "min-w-0 flex-1 text-sm text-foreground-muted"
+ : "min-w-0 flex-1 text-sm text-foreground"
}
- disabled={!controls.canEdit}
- onPress={() => void act(run.id, "edit")}
- className="min-h-14 flex-row items-center gap-2.5 py-2.5 active:opacity-70"
+ numberOfLines={1}
>
- <QueueAttachmentThumbnails
- environmentId={target.environmentId}
- attachments={attachments}
+ {context?.guest === undefined ? null : (
+ <Text className="font-t3-medium text-adaptive-fuchsia-600-300">
+ {`${context.guest.name} `}
+ </Text>
+ )}
+ {title}
+ </Text>
+ {controls.isEditing ? (
+ <Text className="shrink-0 text-2xs uppercase tracking-wide text-primary">
+ Editing
+ </Text>
+ ) : null}
+ </Pressable>
+ </Menu>
+ {workflow?.canPromoteToSteer || workflow?.canSendNow ? (
+ // Outside the edit row and full row height, so a near miss never opens the editor.
+ <Pressable
+ accessibilityRole="button"
+ accessibilityLabel={`Send now, queued message ${index + 1}`}
+ disabled={!controls.canSend}
+ onPress={() => void act(run.id, "steer")}
+ className="shrink-0 justify-center self-stretch pl-4 active:opacity-70 disabled:opacity-40"
+ >
+ <View className="min-h-9 flex-row items-center gap-1.5 rounded-full bg-primary px-4">
+ <SymbolView
+ name="arrow.up"
+ size={13}
+ tintColorClassName="accent-primary-foreground"
/>
- <Text
- className={
- controls.isEditing
- ? "min-w-0 flex-1 text-sm text-foreground-muted"
- : "min-w-0 flex-1 text-sm text-foreground"
- }
- numberOfLines={1}
- >
- {context?.guest === undefined ? null : (
- <Text className="font-t3-medium text-adaptive-fuchsia-600-300">
- {`${context.guest.name} `}
- </Text>
- )}
- {title}
+ <Text className="font-t3-medium text-sm text-primary-foreground">
+ Send now
</Text>
- {controls.isEditing ? (
- <Text className="shrink-0 text-2xs uppercase tracking-wide text-primary">
- Editing
- </Text>
- ) : null}
- </Pressable>
- </Menu>
- {workflow?.canPromoteToSteer || workflow?.canSendNow ? (
- // Outside the edit row and full row height, so a near miss never opens the editor.
- <Pressable
- accessibilityRole="button"
- accessibilityLabel={
- workflow?.canSendNow
- ? `Send message ${index + 1} now`
- : `Steer with message ${index + 1} now`
- }
- disabled={!controls.canSend}
- onPress={() => void act(run.id, "steer")}
- className="shrink-0 justify-center self-stretch pl-4 active:opacity-70 disabled:opacity-40"
- >
- <View className="min-h-9 flex-row items-center gap-1.5 rounded-full bg-primary px-4">
- <SymbolView
- name={workflow?.canSendNow ? "arrow.up" : "arrow.turn.left.up"}
- size={13}
- tintColorClassName="accent-primary-foreground"
- />
- <Text className="font-t3-medium text-sm text-primary-foreground">
- {workflow?.canSendNow ? "Send now" : "Steer"}
- </Text>
- </View>
- </Pressable>
- ) : null}
- </View>
- </QueueRowSwipeable>
- </Animated.View>
- </QueueShiftedRow>
+ </View>
+ </Pressable>
+ ) : null}
+ </View>
+ </QueueRowSwipeable>
+ </View>
);
})}
</ScrollView>
@@ -494,30 +335,6 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
);
}
-function QueueShiftedRow(props: {
- readonly offset: number;
- readonly dragging: boolean;
- readonly lifted: boolean;
- readonly onLayout: React.ComponentProps<typeof View>["onLayout"];
- readonly children: React.ReactNode;
-}) {
- const { dragging, offset } = props;
- const style = useAnimatedStyle(() => ({
- transform: [
- {
- translateY: dragging
- ? withTiming(offset, { duration: 160, reduceMotion: ReduceMotion.System })
- : offset,
- },
- ],
- }));
- return (
- <Reanimated.View onLayout={props.onLayout} style={[style, { zIndex: props.lifted ? 1 : 0 }]}>
- {props.children}
- </Reanimated.View>
- );
-}
-
function QueueRowSwipeable(props: {
readonly enabled: boolean;
readonly background: string;
@@ -532,7 +349,7 @@ function QueueRowSwipeable(props: {
friction={2}
rightThreshold={40}
overshootRight={false}
- // Require a clearly sideways swipe to avoid competing with sheet scroll and drag handles.
+ // Require a clearly sideways swipe to avoid competing with sheet scroll.
failOffsetY={[-12, 12]}
containerStyle={{ backgroundColor: props.background, flex: 1 }}
childrenContainerStyle={{ backgroundColor: props.background }}
@@ -616,54 +433,3 @@ function QueueAttachmentThumbnail(props: {
/>
);
}
-
-function QueueDragHandle(props: {
- disabled: boolean;
- title: string;
- canMoveUp: boolean;
- canMoveDown: boolean;
- onStep: (action: "up" | "down") => void;
- onStart: () => void;
- onMove: (y: number) => void;
- onEnd: (y: number, success: boolean) => void;
-}) {
- const onStart = useEffectEvent(() => props.onStart());
- const onMove = useEffectEvent((y: number) => props.onMove(y));
- const onEnd = useEffectEvent((y: number, success: boolean) => props.onEnd(y, success));
- // oxlint-disable-next-line react/capitalized-calls -- Gesture.Pan is a gesture factory, not a React component.
- const gesture = Gesture.Pan()
- .enabled(!props.disabled)
- .minDistance(0)
- .shouldCancelWhenOutside(false)
- .runOnJS(true)
- .onStart(() => onStart())
- .onUpdate((event) => onMove(event.translationY))
- .onFinalize((event, success) => onEnd(event.translationY, success));
- return (
- <GestureDetector gesture={gesture}>
- <View
- collapsable={false}
- accessible
- accessibilityRole="adjustable"
- accessibilityLabel={`Reorder ${props.title}`}
- accessibilityState={{ disabled: props.disabled }}
- accessibilityActions={[
- ...(props.canMoveUp ? [{ name: "decrement", label: "Move up" }] : []),
- ...(props.canMoveDown ? [{ name: "increment", label: "Move down" }] : []),
- ]}
- onAccessibilityAction={({ nativeEvent }) => {
- if (props.disabled) return;
- if (nativeEvent.actionName === "decrement" && props.canMoveUp) props.onStep("up");
- if (nativeEvent.actionName === "increment" && props.canMoveDown) props.onStep("down");
- }}
- className="h-12 w-8 items-center justify-center"
- >
- <SymbolView
- name="line.3.horizontal"
- size={16}
- tintColorClassName="accent-foreground-muted"
- />
- </View>
- </GestureDetector>
- );
-}
diff --git a/apps/mobile/src/features/threads/floating-working-control.tsx b/apps/mobile/src/features/threads/floating-working-control.tsx
index 24322aa46d4..2b41da1825b 100644
--- a/apps/mobile/src/features/threads/floating-working-control.tsx
+++ b/apps/mobile/src/features/threads/floating-working-control.tsx
@@ -243,7 +243,7 @@ export function FloatingWorkingControl(props: {
<Pressable
accessibilityRole="button"
accessibilityLabel={`Open queue, ${props.queuedCount} messages`}
- accessibilityHint="Opens queued messages for reordering, steering, or removal"
+ accessibilityHint="Opens queued messages to send now, edit, or remove"
onPress={props.onOpenQueue}
onLayout={(event) => setQueueWidth(settleWidth(event.nativeEvent.layout.width))}
style={{ maxWidth: Math.min(overlayWidth, windowWidth) * 0.45 }}
diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts
index e53753d8511..c29ef5eea7a 100644
--- a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts
+++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts
@@ -1,10 +1,7 @@
import { formatAssistantCitationHref } from "@t3tools/shared/assistantCitations";
import { describe, expect, it } from "vite-plus/test";
-import {
- resolveThreadQueueRowControls,
- resolveQueueDropBeforeRunId,
-} from "./threadQueueControlPresentation";
+import { resolveThreadQueueRowControls } from "./threadQueueControlPresentation";
describe("threadQueueControlPresentation", () => {
it.each([
@@ -19,9 +16,6 @@ describe("threadQueueControlPresentation", () => {
isEditing,
canPromoteToSteer: false,
canSendNow: true,
- canReorder: false,
- index: 0,
- queuedCount: 1,
text: "Queued message",
});
@@ -45,9 +39,6 @@ describe("threadQueueControlPresentation", () => {
busy: false,
canPromoteToSteer: true,
canSendNow: false,
- canReorder: true,
- index: 0,
- queuedCount: 1,
text: `[Assistant quote](${href}) Can we add a backoff here?`,
});
@@ -61,17 +52,13 @@ describe("threadQueueControlPresentation", () => {
busy: false,
canPromoteToSteer: true,
canSendNow: false,
- canReorder: true,
- index: 1,
isEditing: true,
- queuedCount: 3,
text: "Being edited",
});
expect(editing.isEditing).toBe(true);
expect(editing.canEdit).toBe(false);
expect(editing.canSend).toBe(false);
- expect(editing.canMoveUp).toBe(true);
expect(editing.canDismiss).toBe(true);
});
@@ -80,10 +67,7 @@ describe("threadQueueControlPresentation", () => {
busy: false,
canPromoteToSteer: true,
canSendNow: false,
- canReorder: true,
- index: 0,
isGuestMessage: true,
- queuedCount: 1,
text: "Why?",
});
@@ -91,24 +75,3 @@ describe("threadQueueControlPresentation", () => {
expect(guest.canDismiss).toBe(true);
});
});
-
-describe("queue drag insertion", () => {
- const rows = [
- { id: "first" as never, y: 0, height: 80 },
- { id: "second" as never, y: 80, height: 140 },
- { id: "third" as never, y: 220, height: 80 },
- ];
-
- it("moves between variable-height rows and to either end", () => {
- expect(resolveQueueDropBeforeRunId(rows, rows[0]!.id, 140)).toBe("third");
- expect(resolveQueueDropBeforeRunId(rows, rows[0]!.id, 300)).toBeNull();
- expect(resolveQueueDropBeforeRunId(rows, rows[2]!.id, -300)).toBe("first");
- });
-
- it("does not send a reorder for an unchanged or unmeasured drop", () => {
- expect(resolveQueueDropBeforeRunId(rows, rows[1]!.id, 0)).toBeUndefined();
- expect(resolveQueueDropBeforeRunId(rows, rows[2]!.id, 20)).toBeUndefined();
- expect(resolveQueueDropBeforeRunId([{ id: rows[0]!.id }], rows[0]!.id, 10)).toBeUndefined();
- expect(resolveQueueDropBeforeRunId(rows, "missing" as never, 100)).toBeUndefined();
- });
-});
diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts
index 33c313f1d39..444d969176b 100644
--- a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts
+++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts
@@ -6,8 +6,6 @@ export const REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL = "Remove queued message"
export interface ThreadQueueRowControls {
readonly canDismiss: boolean;
readonly canEdit: boolean;
- readonly canMoveDown: boolean;
- readonly canMoveUp: boolean;
readonly canSend: boolean;
readonly dismissAccessibilityLabel: string;
readonly displayText: string;
@@ -18,14 +16,11 @@ export function resolveThreadQueueRowControls(input: {
readonly busy: boolean;
readonly canPromoteToSteer: boolean;
readonly canSendNow: boolean;
- readonly canReorder: boolean;
/** Something else holds the composer, such as an open question. */
readonly editBlocked?: boolean;
- readonly index: number;
readonly isEditing?: boolean;
/** A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. */
readonly isGuestMessage?: boolean;
- readonly queuedCount: number;
readonly text: string;
}): ThreadQueueRowControls {
const mutationEnabled = !input.busy;
@@ -37,8 +32,6 @@ export function resolveThreadQueueRowControls(input: {
// away whatever has been typed since.
canEdit:
mutationEnabled && !isEditing && input.isGuestMessage !== true && input.editBlocked !== true,
- canMoveDown: mutationEnabled && input.canReorder && input.index < input.queuedCount - 1,
- canMoveUp: mutationEnabled && input.canReorder && input.index > 0,
canSend: mutationEnabled && (input.canPromoteToSteer || input.canSendNow) && !isEditing,
dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
// Editing and sending keep the original text so quoted citations stay linked.
@@ -66,27 +59,3 @@ export function buildCancelQueuedRunCommand(input: {
},
};
}
-
-export function resolveQueueDragBeforeRunId(
- rows: ReadonlyArray<{ id: RunId; y?: number; height?: number }>,
- runId: RunId,
- translationY: number,
-): RunId | null | undefined {
- const sourceIndex = rows.findIndex((row) => row.id === runId);
- const source = rows[sourceIndex];
- if (!source || rows.some((row) => row.y === undefined || row.height === undefined)) return;
- const center = source.y! + source.height! / 2 + translationY;
- const remaining = rows.filter((row) => row.id !== runId);
- return remaining.find((row) => center < row.y! + row.height! / 2)?.id ?? null;
-}
-
-export function resolveQueueDropBeforeRunId(
- rows: ReadonlyArray<{ id: RunId; y?: number; height?: number }>,
- runId: RunId,
- translationY: number,
-): RunId | null | undefined {
- const before = resolveQueueDragBeforeRunId(rows, runId, translationY);
- if (before === undefined) return;
- const sourceIndex = rows.findIndex((row) => row.id === runId);
- return before === (rows[sourceIndex + 1]?.id ?? null) ? undefined : before;
-}
diff --git a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx
index c4d51e6a889..5a31db26cf7 100644
--- a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx
+++ b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx
@@ -71,7 +71,6 @@ it("previews assistant quotes as readable text and preserves the citation when e
state.workflow = {
activeRun: { id: "run:active" },
canPromoteToSteer: true,
- canReorder: true,
queuedRuns: [
{
run: { id: "run:quote-only", userMessageId: "message:quote-only" },
diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx
index 3ec2c8b4725..7dff9b19b59 100644
--- a/apps/web/src/components/chat/QueuedRunsControl.tsx
+++ b/apps/web/src/components/chat/QueuedRunsControl.tsx
@@ -9,15 +9,7 @@ import type {
RunId,
ThreadId,
} from "@t3tools/contracts";
-import {
- ChevronDownIcon,
- Clock3Icon,
- CornerUpRightIcon,
- GripVerticalIcon,
- ListOrderedIcon,
- PencilIcon,
- XIcon,
-} from "lucide-react";
+import { ChevronDownIcon, Clock3Icon, ArrowUpIcon, PencilIcon, XIcon } from "lucide-react";
import { useId, useImperativeHandle, useRef, useState, type Ref } from "react";
import { useAssetUrls } from "../../assets/assetUrls";
@@ -27,6 +19,7 @@ import { useAtomCommand } from "../../state/use-atom-command";
import { isImageAttachment, type ChatMessage } from "../../types";
import { cn } from "~/lib/utils";
import { Button, InlineButton } from "../ui/button";
+import { Separator } from "../ui/separator";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
export interface EditQueuedRunRequest {
@@ -42,7 +35,6 @@ interface QueuedRowThumbnail {
readonly url: string | null;
}
-const QUEUED_RUN_DRAG_TYPE = "application/x-t3code-queued-run";
// A longer queue shows its first messages and a button that shows the rest.
const QUEUE_VISIBLE_ROWS = 3;
@@ -85,19 +77,12 @@ export function QueuedRunsControl({
const projection = useThreadProjection(
scopeThreadRef(props.environmentId, props.threadId),
)?.projection;
- const reorder = useAtomCommand(threadEnvironment.reorderQueuedRun);
const promote = useAtomCommand(threadEnvironment.promoteQueuedRun);
const resume = useAtomCommand(threadEnvironment.resumeThreadQueue);
const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun);
const [showAll, setShowAll] = useState(false);
const queueListId = useId();
const [busyRunId, setBusyRunId] = useState<RunId | null>(null);
- const [dragState, setDragState] = useState<{
- readonly runId: RunId;
- readonly insertIndex: number | null;
- } | null>(null);
- // Arm from the grip to prevent accidental text drags from reordering queued runs.
- const dragArmedRunIdRef = useRef<RunId | null>(null);
const steerInFlightRef = useRef(false);
// Run-only acknowledgements can resurrect pending rows after cancellation or startup.
const acknowledgedMessageIds = new Set((projection?.messages ?? []).map((message) => message.id));
@@ -109,7 +94,6 @@ export function QueuedRunsControl({
const workflow = projection ? deriveThreadQueueWorkflowState(projection) : null;
const queued = workflow?.queuedRuns ?? [];
const activeRun = workflow?.activeRun ?? null;
- const canReorder = workflow?.canReorder === true;
const canSend = workflow?.canSendNow === true || workflow?.canPromoteToSteer === true;
const queuedImageUrlById = new Map(
queuedImageAttachmentUrls.flatMap((url, index) => {
@@ -160,25 +144,6 @@ export function QueuedRunsControl({
})),
];
- const move = async (runId: RunId, beforeRunId: RunId | null) => {
- setBusyRunId(runId);
- await reorder({
- environmentId: props.environmentId,
- input: { threadId: props.threadId, runId, beforeRunId },
- });
- setBusyRunId(null);
- };
-
- const completeDrag = (runId: RunId, insertIndex: number | null) => {
- setDragState(null);
- dragArmedRunIdRef.current = null;
- if (insertIndex === null || busyRunId !== null) return;
- const draggedIndex = queued.findIndex(({ run }) => run.id === runId);
- if (draggedIndex === -1) return;
- if (insertIndex === draggedIndex || insertIndex === draggedIndex + 1) return;
- void move(runId, queued[insertIndex]?.run.id ?? null);
- };
-
const sendQueuedMessage = async (queuedRunId: RunId) => {
if (!canSend || steerInFlightRef.current) return;
steerInFlightRef.current = true;
@@ -246,17 +211,13 @@ export function QueuedRunsControl({
return (
<section
- aria-label={`Up next: ${items.length} queued message${items.length === 1 ? "" : "s"}`}
+ aria-label={`${items.length} queued message${items.length === 1 ? "" : "s"}`}
data-thread-queue="true"
className="mx-auto flex w-full max-w-(--chat-content-max-width) flex-col gap-2 pb-4"
>
- <h3 className="flex min-h-5 items-center gap-1.5 px-1 text-xs font-normal text-muted-foreground [&_svg]:size-3.5">
- <ListOrderedIcon aria-hidden />
- Up next
- <span className="tabular-nums" aria-live="polite">
- · {items.length} queued
- </span>
- </h3>
+ <span className="sr-only" aria-live="polite">
+ {items.length} queued
+ </span>
<ol className="flex flex-col items-end gap-3" id={queueListId}>
{visibleItems.map((item, position) => {
const previewText = assistantCitationsToPlainText(
@@ -264,11 +225,7 @@ export function QueuedRunsControl({
reference.kind === "image" && item.thumbnails.length > 0 ? "" : reference.label,
),
).trim();
- const rowRunId = item.runId;
- const rowServerIndex = item.serverIndex;
- const isEditing = rowRunId !== null && rowRunId === props.editingRunId;
- const rowDraggable =
- rowRunId !== null && rowServerIndex !== null && canReorder && busyRunId === null;
+ const isEditing = item.runId !== null && item.runId === props.editingRunId;
return (
<li
key={item.key}
@@ -276,56 +233,8 @@ export function QueuedRunsControl({
aria-posinset={position + 1}
aria-setsize={items.length}
aria-current={isEditing ? "true" : undefined}
- className={cn(
- "group/queued relative flex w-full flex-col items-end gap-1 transition-opacity duration-150 ease-out starting:opacity-0 motion-reduce:transition-none",
- dragState !== null && dragState.runId === item.runId && "opacity-50",
- )}
- draggable={rowDraggable}
- onDragStart={(event) => {
- if (item.runId === null || dragArmedRunIdRef.current !== item.runId) {
- event.preventDefault();
- return;
- }
- event.dataTransfer.setData(QUEUED_RUN_DRAG_TYPE, item.runId);
- event.dataTransfer.effectAllowed = "move";
- setDragState({ runId: item.runId, insertIndex: null });
- }}
- onDragEnd={() => {
- dragArmedRunIdRef.current = null;
- setDragState(null);
- }}
- onDragOver={(event) => {
- if (dragState === null || item.serverIndex === null) return;
- event.preventDefault();
- event.dataTransfer.dropEffect = "move";
- const rect = event.currentTarget.getBoundingClientRect();
- const insertIndex =
- event.clientY < rect.top + rect.height / 2
- ? item.serverIndex
- : item.serverIndex + 1;
- if (dragState.insertIndex !== insertIndex) {
- setDragState({ runId: dragState.runId, insertIndex });
- }
- }}
- onDrop={(event) => {
- if (dragState === null) return;
- event.preventDefault();
- completeDrag(dragState.runId, dragState.insertIndex);
- }}
+ className="flex w-full flex-col items-end gap-1 transition-opacity duration-150 ease-out starting:opacity-0 motion-reduce:transition-none"
>
- {item.serverIndex !== null && dragState?.insertIndex === item.serverIndex ? (
- <span
- aria-hidden
- className="pointer-events-none absolute inset-x-0 -top-1.5 h-0.5 rounded bg-primary/70"
- />
- ) : null}
- {item.serverIndex === queued.length - 1 &&
- dragState?.insertIndex === queued.length ? (
- <span
- aria-hidden
- className="pointer-events-none absolute inset-x-0 -bottom-1.5 h-0.5 rounded bg-primary/70"
- />
- ) : null}
{/* Dashed and unfilled: a turn that has not been sent yet. */}
<div
className={cn(
@@ -369,38 +278,30 @@ export function QueuedRunsControl({
) : null}
</div>
<div className="flex items-center gap-0.5 pe-1 text-xs text-muted-foreground">
- {items.length > 1 && canReorder && rowRunId !== null && rowServerIndex !== null ? (
- <Button
- size="icon-xs"
- variant="ghost-muted"
- aria-label={`Reorder queued message ${position + 1} of ${items.length} (drag, or press the arrow keys)`}
- className="group/grip cursor-grab active:cursor-grabbing"
- // Not `disabled`: that drops keyboard focus mid-move and breaks repeated arrow presses.
- aria-disabled={busyRunId !== null || undefined}
- onPointerDown={() => {
- if (busyRunId === null) dragArmedRunIdRef.current = rowRunId;
- }}
- onKeyDown={(event) => {
- if (busyRunId !== null) return;
- if (event.key === "ArrowUp" && rowServerIndex > 0) {
- event.preventDefault();
- void move(rowRunId, queued[rowServerIndex - 1]?.run.id ?? null);
- }
- if (event.key === "ArrowDown" && rowServerIndex < queued.length - 1) {
- event.preventDefault();
- // Moving into the collapsed rows would unmount the focused grip.
- if (rowServerIndex + 1 >= visibleItems.length) setShowAll(true);
- void move(rowRunId, queued[rowServerIndex + 2]?.run.id ?? null);
- }
- }}
- >
- <span className="text-xs font-medium tabular-nums group-hover/queued:hidden group-focus-visible/grip:hidden">
- {position + 1}
- </span>
- <GripVerticalIcon className="hidden group-hover/queued:block group-focus-visible/grip:block" />
- </Button>
- ) : items.length > 1 ? (
- <span className="px-1.5 font-medium tabular-nums">{position + 1}</span>
+ {canSend && !isEditing ? (
+ <>
+ <Tooltip>
+ <TooltipTrigger render={<span className="flex shrink-0" />}>
+ <Button
+ size="xs"
+ variant="ghost-muted"
+ disabled={item.runId === null || busyRunId !== null}
+ onClick={() => {
+ if (item.runId !== null) {
+ void sendQueuedMessage(item.runId);
+ }
+ }}
+ >
+ <ArrowUpIcon />
+ Send now
+ </Button>
+ </TooltipTrigger>
+ <TooltipPopup>
+ {`${workflow?.canSendNow ? "Start a turn with this message" : "Send into the current turn"}${item.serverIndex === 0 && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`}
+ </TooltipPopup>
+ </Tooltip>
+ <Separator orientation="vertical" className="mx-2 h-4" />
+ </>
) : null}
{item.pending ? (
<span className="flex items-center gap-1 px-1">
@@ -454,26 +355,6 @@ export function QueuedRunsControl({
`Edit in the composer${item.serverIndex === queued.length - 1 && props.editShortcutLabel ? ` (${props.editShortcutLabel})` : ""}`}
</TooltipPopup>
</Tooltip>
- <Tooltip>
- <TooltipTrigger render={<span className="flex shrink-0" />}>
- <Button
- size="xs"
- variant="ghost-muted"
- disabled={item.runId === null || busyRunId !== null || !canSend}
- onClick={() => {
- if (item.runId !== null) {
- void sendQueuedMessage(item.runId);
- }
- }}
- >
- <CornerUpRightIcon />
- {workflow?.canSendNow ? "Send now" : "Steer"}
- </Button>
- </TooltipTrigger>
- <TooltipPopup>
- {`${workflow?.canSendNow ? "Start a turn with this message" : "Send as a steer instead"}${item.serverIndex === 0 && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`}
- </TooltipPopup>
- </Tooltip>
<Tooltip>
<TooltipTrigger
render={
diff --git a/docs/user/composer.md b/docs/user/composer.md
index 35b425faf31..82cc005d061 100644
--- a/docs/user/composer.md
+++ b/docs/user/composer.md
@@ -54,7 +54,7 @@ See [images and videos](#images-and-videos-in-messages) for previewing and savin
On web and desktop, choose **Settings → Chat → Follow-up behavior** to queue
new messages for a later turn or steer the running turn immediately. The setting
applies to this client; already queued messages keep their place. Queued messages
-are saved on the server and can be edited, reordered, or removed before they send.
+are saved on the server and can be edited or removed before they send.
When Enter sends, `Cmd+Enter` on macOS or `Ctrl+Enter` on Windows and Linux uses
the opposite action: it steers when your default is Queue and queues when your
default is Steer.
@@ -204,15 +204,15 @@ Steer. Click it or press your send shortcut to use that action. Hold `Cmd` on ma
Windows and Linux to switch the button to the opposite action, then click, or use the opposite-action
shortcut described above.
-On web and desktop, queued messages appear at the end of the thread under **Up next**, as dashed
-messages that have not been sent yet. On mobile they appear above the composer. Each shows its text
-and any attached images. Drag a message by its handle to reorder it, use the handle's arrow keys,
-promote the message to a steer, or remove it.
+On web and desktop, queued messages appear at the end of the thread as dashed messages that have
+not been sent yet. On mobile they appear above the composer. Each shows its text and any attached
+images. **Send now** sends a message right away, into the running turn if there is one. You can
+also edit or remove it.
If you stop the agent or the server restarts, queued messages keep their order and are held.
Press **Resume** in an empty composer on web and desktop, or **Resume queue** on mobile, to
continue. Sending a new message also resumes the queue, unless it steers a turn that is already
-running. You can edit, reorder, or remove held messages without starting them.
+running. You can edit or remove held messages without starting them.
The pencil on a queued message opens it in the composer for editing. The original message
stays in the queue until you save, and it is highlighted while you edit. The message's
diff --git a/packages/client-runtime/src/operations/commands.ts b/packages/client-runtime/src/operations/commands.ts
index 1f964994707..4ab6a14a87f 100644
--- a/packages/client-runtime/src/operations/commands.ts
+++ b/packages/client-runtime/src/operations/commands.ts
@@ -229,11 +229,6 @@ export interface ResumeThreadQueueInput extends ThreadCommandInput {
readonly runId?: RunId;
}
-export interface ReorderQueuedRunInput extends ThreadCommandInput {
- readonly runId: RunId;
- readonly beforeRunId: RunId | null;
-}
-
export interface PromoteQueuedRunInput extends ThreadCommandInput {
readonly queuedRunId: RunId;
readonly targetRunId: RunId;
@@ -1064,18 +1059,6 @@ export const resumeThreadQueue = Effect.fn("EnvironmentCommands.resumeThreadQueu
});
});
-export const reorderQueuedRun = Effect.fn("EnvironmentCommands.reorderQueuedRun")(function* (
- input: ReorderQueuedRunInput,
-) {
- return yield* dispatch({
- type: "queued-run.reorder",
- commandId: yield* allocateCommandId(input),
- threadId: input.threadId,
- runId: input.runId,
- beforeRunId: input.beforeRunId,
- });
-});
-
export const promoteQueuedRun = Effect.fn("EnvironmentCommands.promoteQueuedRun")(function* (
input: PromoteQueuedRunInput,
) {
diff --git a/packages/client-runtime/src/state/threadCommands.ts b/packages/client-runtime/src/state/threadCommands.ts
index 84a290057f5..ad0cd9ec2a3 100644
--- a/packages/client-runtime/src/state/threadCommands.ts
+++ b/packages/client-runtime/src/state/threadCommands.ts
@@ -29,7 +29,6 @@ import {
type ForkThreadFromRunInput,
type MergeThreadBackInput,
type PromoteQueuedRunInput,
- type ReorderQueuedRunInput,
type ResumeThreadQueueInput,
type LinkThreadPullRequestInput,
type RespondToThreadApprovalInput,
@@ -68,7 +67,6 @@ import {
markThreadUnread,
mergeThreadBack,
promoteQueuedRun,
- reorderQueuedRun,
resumeThreadQueue,
retryWorkspacePreparation,
linkThreadPullRequest,
@@ -115,7 +113,6 @@ export type {
ForkThreadFromRunInput,
MergeThreadBackInput,
PromoteQueuedRunInput,
- ReorderQueuedRunInput,
LinkThreadPullRequestInput,
RespondToThreadApprovalInput,
RespondToThreadUserInputInput,
@@ -398,12 +395,6 @@ export function createThreadEnvironmentAtoms<R, E>(
scheduler,
concurrency,
}),
- reorderQueuedRun: createEnvironmentCommand(runtime, {
- label: "environment-data:commands:thread:reorder-queued-run",
- execute: (input: ReorderQueuedRunInput) => reorderQueuedRun(input),
- scheduler,
- concurrency,
- }),
promoteQueuedRun: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:promote-queued-run",
execute: (input: PromoteQueuedRunInput) => promoteQueuedRun(input),
diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts
index e8e2c766b1e..d22b4c97b38 100644
--- a/packages/client-runtime/src/state/threadWorkflows.test.ts
+++ b/packages/client-runtime/src/state/threadWorkflows.test.ts
@@ -65,7 +65,7 @@ describe("thread workflows", () => {
).toBe(false);
});
- it("sorts queued messages and gates reorder and promotion from capabilities", () => {
+ it("sorts queued messages and gates promotion from capabilities", () => {
const state = deriveThreadQueueWorkflowState({
thread: { id: "thread", activeProviderThreadId: "provider-thread" },
runs: [
@@ -133,7 +133,6 @@ describe("thread workflows", () => {
[],
]);
expect(state.activeRun?.id).toBe("active");
- expect(state.canReorder).toBe(true);
expect(state.canPromoteToSteer).toBe(true);
expect(state.canSendNow).toBe(false);
});
diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts
index 701bd4566ea..1a47d134bf5 100644
--- a/packages/client-runtime/src/state/threadWorkflows.ts
+++ b/packages/client-runtime/src/state/threadWorkflows.ts
@@ -32,7 +32,6 @@ export interface ThreadQueueWorkflowState {
readonly activeRun: Run | null;
readonly queuedRuns: ReadonlyArray<QueuedThreadRun>;
readonly isHeld: boolean;
- readonly canReorder: boolean;
readonly canPromoteToSteer: boolean;
readonly canSendNow: boolean;
}
@@ -155,7 +154,6 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu
activeRun,
queuedRuns,
isHeld: projection.runs.some((run) => run.status === "queued" && run.queueHeld === true),
- canReorder: capabilities?.supportsQueuedMessages === true,
canSendNow:
activeRun === null &&
projection.thread.archivedAt == null &&