Skip to content

Commit e43bf26

Browse files
committed
merge upstream v0.1.3-nightly.20261023.3566
merge upstream v0.1.3-nightly.20261023.3566: reconcile
2 parents 5b75678 + 807319c commit e43bf26

77 files changed

Lines changed: 2255 additions & 406 deletions

File tree

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/components/ui/Toast.tsx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MOBILE_SHAPE } from "../../lib/designTokens";
22
import { useEffect } from "react";
3-
import { AccessibilityInfo, Platform, View } from "react-native";
3+
import { AccessibilityInfo, Platform, View, useWindowDimensions } from "react-native";
44

55
import { AppText } from "./AppText";
66
import { Button } from "./Button";
@@ -20,6 +20,13 @@ export interface ToastProps {
2020

2121
/** The owning screen places and dismisses feedback; actions are never implicit. */
2222
export function Toast(props: ToastProps) {
23+
const { fontScale } = useWindowDimensions();
24+
// A one-line message keeps its action on the same row. Descriptions and
25+
// accessibility text sizes need the full width, so the action moves below.
26+
const inlineAction = !props.description && fontScale < 1.5;
27+
const action = props.action ? (
28+
<Button label={props.action.label} onPress={props.action.onPress} />
29+
) : null;
2330
useEffect(() => {
2431
if (Platform.OS === "ios") AccessibilityInfo.announceForAccessibility(props.message);
2532
}, [props.message]);
@@ -47,15 +54,12 @@ export function Toast(props: ToastProps) {
4754
</AppText>
4855
) : null}
4956
</View>
57+
{inlineAction ? action : null}
5058
{props.onDismiss ? (
5159
<IconButton accessibilityLabel="Dismiss message" icon="xmark" onPress={props.onDismiss} />
5260
) : null}
5361
</View>
54-
{props.action ? (
55-
<View className="mt-2 self-end">
56-
<Button label={props.action.label} onPress={props.action.onPress} />
57-
</View>
58-
) : null}
62+
{action && !inlineAction ? <View className="mt-2 self-end">{action}</View> : null}
5963
</GlassSurface>
6064
);
6165
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import { useLayoutEffect, useState } from "react";
2+
import { StyleSheet, View } from "react-native";
3+
import { GestureDetector, usePanGesture } from "react-native-gesture-handler";
4+
import Animated, {
5+
cancelAnimation,
6+
Easing,
7+
FadeOut,
8+
ReduceMotion,
9+
runOnJS,
10+
useAnimatedStyle,
11+
useSharedValue,
12+
withTiming,
13+
type EntryAnimationsValues,
14+
} from "react-native-reanimated";
15+
import { useSafeAreaInsets } from "react-native-safe-area-context";
16+
import { Toast } from "../../components/ui/Toast";
17+
import { MOBILE_MOTION } from "../../lib/designTokens";
18+
import {
19+
dismissThreadUndoNotice,
20+
readThreadUndoNotice,
21+
useThreadUndoNotice,
22+
} from "./thread-undo-notice";
23+
24+
const SWIPE_TIMING = { duration: 160, reduceMotion: ReduceMotion.System };
25+
const ENTER_TIMING = {
26+
duration: MOBILE_MOTION.enter,
27+
easing: Easing.out(Easing.cubic),
28+
reduceMotion: ReduceMotion.System,
29+
};
30+
const NOTICE_EXITING = FadeOut.duration(MOBILE_MOTION.exit).reduceMotion(ReduceMotion.System);
31+
const noticeEntering = (values: EntryAnimationsValues) => {
32+
"worklet";
33+
return {
34+
initialValues: { originY: values.targetOriginY + values.targetHeight + 12 },
35+
animations: { originY: withTiming(values.targetOriginY, ENTER_TIMING) },
36+
};
37+
};
38+
39+
export function ThreadUndoNotice(props: { readonly visible: boolean }) {
40+
const notice = useThreadUndoNotice();
41+
// Replacing a notice must also cancel the native gesture tracking the old one.
42+
const [instance, setInstance] = useState({ notice, key: 0 });
43+
if (instance.notice !== notice) setInstance({ notice, key: instance.key + 1 });
44+
if (!props.visible || notice === null) return null;
45+
return <SwipeableUndoNotice key={instance.key} notice={notice} />;
46+
}
47+
48+
function SwipeableUndoNotice(props: {
49+
readonly notice: NonNullable<ReturnType<typeof useThreadUndoNotice>>;
50+
}) {
51+
const { notice } = props;
52+
const insets = useSafeAreaInsets();
53+
const translation = useSharedValue(0);
54+
const width = useSharedValue(0);
55+
56+
useLayoutEffect(
57+
() => () => {
58+
cancelAnimation(translation);
59+
},
60+
[translation],
61+
);
62+
63+
const dismiss = () => {
64+
// A newer action can replace the notice while the swipe is animating out.
65+
if (readThreadUndoNotice() === notice) dismissThreadUndoNotice();
66+
};
67+
const gesture = usePanGesture({
68+
activeOffsetX: [-10, 10],
69+
failOffsetY: [-12, 12],
70+
onUpdate: (event) => {
71+
translation.set(event.translationX);
72+
},
73+
onDeactivate: (event) => {
74+
if (
75+
!event.canceled &&
76+
(Math.abs(event.translationX) > width.value * 0.25 ||
77+
(Math.abs(event.velocityX) > 800 && event.translationX * event.velocityX > 0))
78+
) {
79+
const direction = Math.sign(event.translationX || event.velocityX);
80+
translation.set(
81+
withTiming(direction * (width.value + 24), SWIPE_TIMING, (finished) => {
82+
if (finished) runOnJS(dismiss)();
83+
}),
84+
);
85+
} else {
86+
translation.set(withTiming(0, SWIPE_TIMING));
87+
}
88+
},
89+
});
90+
const animatedStyle = useAnimatedStyle(() => ({
91+
transform: [{ translateX: translation.value }],
92+
}));
93+
94+
// Clip the entrance above navigation; the notice intentionally covers the anchored FAB.
95+
return (
96+
<Animated.View
97+
className="absolute inset-x-3 z-[100] overflow-hidden"
98+
style={{ bottom: insets.bottom + 12 }}
99+
pointerEvents="box-none"
100+
exiting={NOTICE_EXITING}
101+
onLayout={(event) => {
102+
width.set(event.nativeEvent.layout.width);
103+
}}
104+
>
105+
<GestureDetector gesture={gesture}>
106+
<Animated.View collapsable={false} entering={noticeEntering} style={animatedStyle}>
107+
{/* Keep the dismiss target separate so TalkBack can also focus Undo. */}
108+
<View
109+
accessible
110+
accessibilityRole="alert"
111+
accessibilityLiveRegion="assertive"
112+
accessibilityLabel={`${notice.action} thread`}
113+
accessibilityActions={[{ name: "dismiss", label: "Dismiss message" }]}
114+
onAccessibilityAction={({ nativeEvent }) => {
115+
if (nativeEvent.actionName === "dismiss") dismiss();
116+
}}
117+
pointerEvents="none"
118+
style={StyleSheet.absoluteFill}
119+
/>
120+
<Toast
121+
message={`${notice.action} thread`}
122+
action={{ label: "Undo", onPress: () => void notice.undo() }}
123+
/>
124+
</Animated.View>
125+
</GestureDetector>
126+
</Animated.View>
127+
);
128+
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ export function useCompactComposerEditor(text: ScaledTextRole, value: string) {
147147
const rowWidth = useSharedValue(0);
148148
const editorX = useSharedValue(0);
149149
const editorWidth = useSharedValue(0);
150-
const inset = Platform.OS === "android" ? 0 : collapsedEditorInset(text);
150+
const inset =
151+
Platform.OS === "android" ? COLLAPSED_EDITOR_DEFAULT_INSET : collapsedEditorInset(text);
151152
const minimum = Math.max(INLINE_EDITOR_HEIGHT, Math.ceil(text.lineHeight) + 2 * inset);
152153
const height = Math.max(
153154
minimum,
@@ -216,7 +217,7 @@ export function useCompactComposerEditor(text: ScaledTextRole, value: string) {
216217
}
217218
},
218219
editorProps: {
219-
singleLineCentered: false,
220+
singleLineCentered: !isExpanded,
220221
scrollEnabled: Platform.OS === "android" || contentHeight >= text.lineHeight * 4,
221222
contentInsetVertical: inset,
222223
onContentSizeChange: (size: { width: number; height: number }) => {
@@ -848,8 +849,6 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
848849
</>
849850
) : null;
850851

851-
// The row and the card's toolbar share this picker. It shrinks to the provider
852-
// icon in the row once the draft has text, so the draft keeps the width.
853852
const modelControl = (
854853
<View className="min-w-0 shrink">
855854
<ComposerModelControl
@@ -860,9 +859,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
860859
reportedSelection={props.reportedModelSelection}
861860
prompt={draftMessage}
862861
surfaceColor={composerPanel}
863-
iconOnly={
864-
(draftMessage.length > 0 || stripAttachments.length > 0) && !compactEditor.isExpanded
865-
}
862+
iconOnly={!compactEditor.isExpanded}
866863
onPress={openSettings}
867864
/>
868865
</View>

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
} from "@t3tools/shared/codexArtifactTemplates";
5656
import {
5757
declinePendingApprovals,
58+
sendApprovalFeedback,
5859
type ApprovalResponder,
5960
type ThreadUserInputQuestion,
6061
} from "@t3tools/client-runtime/state/thread-requests";
@@ -258,7 +259,10 @@ export interface ThreadDetailScreenProps {
258259
readonly onResumeQueue: (() => Promise<void>) | null;
259260
readonly onSendMessage: (
260261
followUp?: ActiveTurnComposerAction,
261-
beforeDispatch?: () => Promise<boolean>,
262+
beforeDispatch?: (
263+
text: string,
264+
hasAttachmentsOrContext: boolean,
265+
) => Promise<boolean | "responded">,
262266
) => Promise<MessageId | null>;
263267
readonly onReconnectEnvironment: () => void;
264268
readonly canSwitchThreadProvider: boolean;
@@ -1199,18 +1203,40 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
11991203
const approvalsToDecline = props.activePendingApprovals;
12001204
const declineBeforeDispatch =
12011205
approvalsToDecline.length > 0 && props.activePendingUserInput === null
1202-
? async () =>
1203-
props.respondingApprovalId === null &&
1204-
(await declinePendingApprovals(approvalsToDecline, props.onRespondToApproval)) &&
1205-
selectedThreadKeyRef.current === targetThreadKey &&
1206-
// A draft edited or pasted into during the decline isn't what the user sent.
1207-
stillSendable?.() !== false &&
1208-
// An approval that arrived during the decline would block the redirect; the draft
1209-
// stays so the next send declines it too.
1210-
!activePendingApprovalsRef.current.some(
1211-
(approval) =>
1212-
!approvalsToDecline.some((declined) => declined.requestId === approval.requestId),
1206+
? async (text: string, hasAttachmentsOrContext: boolean) => {
1207+
if (
1208+
selectedThreadKeyRef.current !== targetThreadKey ||
1209+
stillSendable?.() === false ||
1210+
props.respondingApprovalId !== null
12131211
)
1212+
return false;
1213+
const feedbackTarget = approvalsToDecline[0];
1214+
if (feedbackTarget?.supportsFeedback) {
1215+
if (hasAttachmentsOrContext) {
1216+
Dialog.alert(
1217+
"Approval feedback",
1218+
"Send approval feedback without attachments or added context.",
1219+
);
1220+
return false;
1221+
}
1222+
return (await sendApprovalFeedback(feedbackTarget, text, props.onRespondToApproval))
1223+
? ("responded" as const)
1224+
: false;
1225+
}
1226+
return (
1227+
props.respondingApprovalId === null &&
1228+
(await declinePendingApprovals(approvalsToDecline, props.onRespondToApproval)) &&
1229+
selectedThreadKeyRef.current === targetThreadKey &&
1230+
// A draft edited or pasted into during the decline isn't what the user sent.
1231+
stillSendable?.() !== false &&
1232+
// An approval that arrived during the decline would block the redirect; the draft
1233+
// stays so the next send declines it too.
1234+
!activePendingApprovalsRef.current.some(
1235+
(approval) =>
1236+
!approvalsToDecline.some((declined) => declined.requestId === approval.requestId),
1237+
)
1238+
);
1239+
}
12141240
: undefined;
12151241
const messageId = await props.onSendMessage(followUp, declineBeforeDispatch);
12161242
if (messageId === null || selectedThreadKeyRef.current !== targetThreadKey) {
@@ -1642,7 +1668,9 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
16421668
editorRef={composerEditorRef}
16431669
placeholder={
16441670
props.activePendingApproval
1645-
? "Send a message to decline and redirect the agent"
1671+
? props.activePendingApproval.supportsFeedback
1672+
? "Send feedback to decline this request"
1673+
: "Send a message to decline and redirect the agent"
16461674
: "Ask the repo agent, or run a command…"
16471675
}
16481676
contentMaxWidth={contentMaxWidth}

‎apps/mobile/src/state/thread-task-permissions.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "../../../../packages/client-runtime/src/state/orchestrationV2TestFixtures";
1919
import type { DraftComposerImageAttachment } from "../lib/composerImages";
2020
import type { PendingThreadRequests } from "@t3tools/client-runtime/state/thread-requests";
21+
import { sendApprovalFeedback } from "@t3tools/client-runtime/state/thread-requests";
2122
import { AsyncResult, type Atom } from "effect/reactivity";
2223
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2324

@@ -202,6 +203,43 @@ beforeEach(() => {
202203
});
203204

204205
describe("mobile task permissions", () => {
206+
it("consumes an approval reply without queueing a parent message", async () => {
207+
state.grantedEnvironments.add("secondary");
208+
const composer = useThreadComposerState();
209+
const requests = useSelectedThreadRequests();
210+
const approval = { ...state.pendingRequests.approvals[0]!, supportsFeedback: true };
211+
const messageId = await composer.onSendMessage(undefined, async (text) =>
212+
(await sendApprovalFeedback(approval, text, requests.onRespondToApproval))
213+
? "responded"
214+
: false,
215+
);
216+
expect(messageId).toBeNull();
217+
expect(state.approve).toHaveBeenCalledWith({
218+
environmentId: "secondary",
219+
input: {
220+
threadId: "thread",
221+
requestId: "approval",
222+
decision: "decline",
223+
feedback: "Keep my draft",
224+
},
225+
});
226+
expect(state.enqueue).not.toHaveBeenCalled();
227+
expect(state.clearDraft).toHaveBeenCalledOnce();
228+
});
229+
230+
it("preserves a draft changed during an approval reply and never sends it to the parent", async () => {
231+
state.grantedEnvironments.add("secondary");
232+
const composer = useThreadComposerState();
233+
const beforeDispatch = async () => {
234+
state.draft = { ...state.draft, text: "New feedback" };
235+
return "responded" as const;
236+
};
237+
expect(await composer.onSendMessage(undefined, beforeDispatch)).toBeNull();
238+
expect(state.enqueue).not.toHaveBeenCalled();
239+
expect(state.clearDraft).not.toHaveBeenCalled();
240+
expect(state.draft.text).toBe("New feedback");
241+
});
242+
205243
it("keeps a connected read-only task's draft instead of queueing it with another environment's grant", async () => {
206244
const composer = useThreadComposerState();
207245
expect(await composer.onSendMessage()).toBeNull();

‎apps/mobile/src/state/use-selected-thread-requests.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export function useSelectedThreadRequests() {
236236
);
237237

238238
const onRespondToApproval = useCallback(
239-
async (requestId: RuntimeRequestId, decision: ProviderApprovalDecision) => {
239+
async (requestId: RuntimeRequestId, decision: ProviderApprovalDecision, feedback?: string) => {
240240
if (
241241
!selectedThreadShell ||
242242
!readEnvironmentScope(selectedThreadShell.environmentId, AuthOrchestrationOperateScope)
@@ -257,6 +257,7 @@ export function useSelectedThreadRequests() {
257257
threadId: selectedThreadShell.id,
258258
requestId,
259259
decision,
260+
...(feedback === undefined ? {} : { feedback }),
260261
},
261262
});
262263
setRespondingApprovalId((current) => (current === requestId ? null : current));

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,10 @@ export function useThreadComposerState() {
527527

528528
const onSendMessage = async (
529529
followUpOverride?: ActiveTurnComposerAction,
530-
beforeDispatch?: () => Promise<boolean>,
530+
beforeDispatch?: (
531+
text: string,
532+
hasAttachmentsOrContext: boolean,
533+
) => Promise<boolean | "responded">,
531534
) => {
532535
if (
533536
selectedThreadShell &&
@@ -646,7 +649,11 @@ export function useThreadComposerState() {
646649
}
647650

648651
if (beforeDispatch !== undefined) {
649-
if (!(await beforeDispatch())) return null;
652+
const response = await beforeDispatch(
653+
text,
654+
attachments.length > 0 || draft.context !== undefined,
655+
);
656+
if (!response) return null;
650657
// A context paste still landing, or any draft or settings change while approvals were
651658
// declined, means this snapshot is no longer what the user sent.
652659
if (appAtomRegistry.get(composerContextImportsAtom)[threadKey]) return null;
@@ -661,6 +668,10 @@ export function useThreadComposerState() {
661668
current.attachments.some((attachment, index) => attachment.id !== attachments[index]?.id)
662669
)
663670
return null;
671+
if (response === "responded") {
672+
clearComposerDraftContent(threadKey);
673+
return null;
674+
}
664675
}
665676

666677
// Resolved here rather than at drain time: the outbox can deliver minutes

0 commit comments

Comments
 (0)