Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadComposer.tsx

1,234 lines49.7 KB

1import { Button } from "../../components/ui/Button";
2import * as Dialog from "../../components/ui/Dialog";
3import type { ComposerTextPaste } from "../../native/T3ComposerEditor.types";
4import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
5import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
6import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
7import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
8import { AsyncResult } from "effect/reactivity";
9import { useAtomValue } from "@effect/atom-react";
10import { clampFileAttachmentUploadBytes } from "@t3tools/client-runtime/state/attachments";
11import { pastedTextDisposition, replaceTextSelection } from "@t3tools/client-runtime/text-paste";
12import {
13 PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
14 PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
15 type ChatAttachment,
16 type EnvironmentId,
17 type MessageId,
18 type ModelSelection,
19 type ProviderInteractionMode,
20 type RuntimeMode,
21 type ServerConfig as T3ServerConfig,
22 type UsageLimitsReport,
23} from "@t3tools/contracts";
24import {
25 collectProviderUsageLimits,
26 hasProviderUsageLimits,
27 isUsageLimitsCommand,
28} from "@t3tools/shared/usageLimits";
29import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
30import type { ReactNode } from "react";
31import { useEffect, useLayoutEffect, useRef, useState, type RefObject } from "react";
32import { Keyboard, Platform, View, type ViewStyle } from "react-native";
33import { composerImageGallery } from "../../lib/composerImageGallery";
34import { filePreviewGallery } from "../../lib/filePreviewGallery";
35import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
36import {
37 composerAttachmentUploadBlockReason,
38 composerAttachmentsStillUploading,
39 composerAttachmentUploadsAtom,
40} from "../../state/composer-attachment-uploads";
41import Animated, {
42 FadeIn,
43 FadeOut,
44 type LayoutAnimationFunction,
45 ReduceMotion,
46 useAnimatedStyle,
47 useSharedValue,
48 withTiming,
49} from "react-native-reanimated";
50import { useUniwindTheme } from "../../lib/useUniwindTheme";
51import { themeColorWithAlpha } from "../../lib/mobileTheme";
52import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/remoteRegistration";
53import { scopedThreadKey } from "../../lib/scopedEntities";
54import {
55 getComposerDraftSnapshot,
56 composerDraftsAtom,
57 setComposerDraftText,
58 composerContextImportsAtom,
59 countComposerDraftAttachmentsAfterSelection,
60 useComposerDraft,
61} from "../../state/use-composer-drafts";
62import { appAtomRegistry } from "../../state/atom-registry";
63import type { ComposerDocumentAttachment } from "../../lib/composerContext";
64import { useProject, useThreadShells } from "../../state/entities";
65import { scopeProjectRef } from "@t3tools/client-runtime/environment";
66​
67import { AppText as Text } from "../../components/ui/AppText";
68import { ComposerAttachmentButton } from "./ComposerAttachmentButton";
69import {
70 ComposerAttachmentStrip,
71 ComposerAttachmentThumbnail,
72} from "../../components/ComposerAttachmentStrip";
73import { VideoPreviewModal, type VideoPreviewSource } from "../../components/VideoPreviewModal";
74import { GlassSurface } from "../../components/ui/GlassSurface";
75import { ComposerEditor, type ComposerEditorHandle } from "../../components/ComposerEditor";
76import { fileRoutePathSegments } from "../files/filePath";
77import { ComposerActionButton, ComposerToolbarRow } from "../../components/ComposerToolbar";
78import { ComposerModelControl } from "../../components/ComposerModelControl";
79import {
80 composerStripAttachments,
81 type DraftComposerFileAttachment,
82} from "../../lib/composerImages";
83import {
84 buildModelOptions,
85 groupByProvider,
86 isModelSelectionUnavailable,
87} from "../../lib/modelOptions";
88import { useScaledTextRole, type ScaledTextRole } from "../settings/appearance/useScaledTextRole";
89import type { RemoteClientConnectionState } from "../../lib/connection";
90import { MOBILE_TYPOGRAPHY } from "../../lib/typography";
91import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
92import { Menu } from "../../components/ui/Menu";
93import type { ActiveTurnComposerAction } from "@t3tools/client-runtime/state/composer-dispatch";
94import type { FollowUpBehavior } from "../../lib/followUpBehavior";
95import {
96 resolveComposerSendPresentation,
97 type ComposerSendPresentation,
98} from "./composerSendPresentation";
99import { ComposerCommandPopover } from "./ComposerCommandPopover";
100import { ComposerPopoverAnchor } from "./ComposerPopoverAnchor";
101import { ComposerQueuedEditAttachments } from "./ComposerQueuedEdit";
102import { useComposerCommandMenu } from "./use-composer-command-menu";
103import {
104 ComposerDictationCancelAction,
105 ComposerDictationDraftContent,
106 ComposerDictationPrimaryAction,
107 ComposerDictationStartAction,
108 ComposerDictationStatus,
109 ComposerDictationToolbar,
110} from "../voice-input/ComposerDictationControl";
111import { useVoiceInputController } from "../voice-input/useVoiceInputController";
112import { resolveVoiceComposerPresentation } from "../voice-input/voiceInputPresentation";
113import {
114 rememberModelOptions,
115 withRememberedModelOptions,
116} from "../../state/use-model-option-memory";
117import {
118 type ExistingThreadSettingsRouteSession,
119 useExistingThreadSettingsRoutePresentation,
120} from "./ThreadSettingsSheet";
121import {
122 useThreadSettingsSheetPresentation,
123 type NavigationWithFinishTransitioning,
124} from "./use-thread-settings-sheet-presentation";
125​
126export const COMPOSER_COLLAPSED_CHROME = 60;
127​
128const COLLAPSED_EDITOR_DEFAULT_INSET = 6;
129// iOS puts line-height slack above glyphs. DM Sans's lowercase midline is
130// descender (0.31em) + half x-height (0.504em) above the line bottom.
131const LOWERCASE_MIDLINE_EM = 0.562;
132​
133function lowercaseMidline(text: ScaledTextRole): number {
134 return text.lineHeight - LOWERCASE_MIDLINE_EM * text.fontSize;
136​
137function collapsedEditorInset(text: ScaledTextRole): number {
138 const shift = lowercaseMidline(text) - lowercaseMidline(MOBILE_TYPOGRAPHY.body);
139 return Math.max(0, Math.round(COLLAPSED_EDITOR_DEFAULT_INSET - shift));
141​
142export const COMPOSER_EXPANDED_CHROME = 156;
143​
144export interface ThreadComposerProps {
145 readonly canOperateThread: boolean;
146 readonly placeholder: string;
147 readonly contentMaxWidth?: number;
148 readonly bottomInset?: number;
149 readonly connectionState: RemoteClientConnectionState;
150 readonly environmentLabel: string | null;
151 readonly threadSyncPhase?: "loading" | "syncing" | null;
152 readonly selectedThread: EnvironmentThreadShell;
153 readonly reportedModelSelection?: ModelSelection | null;
154 readonly hasCompactableConversation: boolean;
155 readonly serverConfig: T3ServerConfig | null;
156 readonly queueCount: number;
157 readonly activeThreadBusy: boolean;
158 readonly canStopThread: boolean;
159 readonly environmentId: EnvironmentId;
160 readonly projectCwd: string | null;
161 readonly sendBlockedReason?: string | null;
162 readonly draftKey?: string;
163 readonly queuedEdit?: {
164 readonly existingAttachments: ReadonlyArray<ChatAttachment>;
165 readonly saving: boolean;
166 readonly onRemoveExistingAttachment: (attachmentId: string) => void;
167 } | null;
168 readonly followUpBehavior: FollowUpBehavior;
169 readonly canSteerActiveTurn: boolean;
170 readonly hidden: boolean;
171 readonly editorRef?: RefObject<ComposerEditorHandle | null>;
172 readonly onChangeDraftMessage: (value: string) => void;
173 readonly onPickDraftMedia: () => Promise<void>;
174 readonly onPickDraftFiles: () => Promise<void>;
175 readonly onNativePasteImages: (uris: ReadonlyArray<string>) => Promise<void>;
176 readonly onNativePasteText: (paste: ComposerTextPaste) => Promise<void>;
177 readonly onRemoveDraftImage: (imageId: string) => void;
178 readonly onStopThread: () => void;
179 /** Present while the thread's queue is held. */
180 readonly onResumeQueue: (() => Promise<void>) | null;
181 /** `stillSendable` reports whether the draft is unchanged after any wait before sending. */
182 readonly onSendMessage: (
183 followUp?: ActiveTurnComposerAction,
184 stillSendable?: () => boolean,
185 ) => Promise<MessageId | null>;
186 readonly onShowUsageLimits: (report: UsageLimitsReport | null) => void;
187 readonly canSwitchProvider: boolean;
188 readonly onUpdateModelSelection: (modelSelection: ModelSelection) => void;
189 readonly onUpdateRuntimeMode: (runtimeMode: RuntimeMode) => void;
190 readonly onUpdateInteractionMode: (interactionMode: ProviderInteractionMode) => void;
191 /** True while the draft is stacked above the controls rather than in the one-row capsule. */
192 readonly onExpandedChange?: (expanded: boolean) => void;
193 readonly onEditorFocusChange?: (focused: boolean) => void;
195​
196// Android gets NO layout transition: the composer rides the keyboard via KeyboardStickyView
197// (frame-synced to the IME), and a time-based morph running alongside that translate reads as
198// jitter.
199export const COMPOSER_TRANSITION_DURATION_MS = 220;
200// Side panes already animate the dock's width. Nested horizontal layout
201// transitions would leave the surface trailing its toolbar's new position.
202const composerHeightTransition: LayoutAnimationFunction = (values) => {
203 "worklet";
204 const timing = {
205 duration: COMPOSER_TRANSITION_DURATION_MS,
206 reduceMotion: ReduceMotion.System,
207 };
208 return {
209 initialValues: {
210 originX: values.targetOriginX,
211 originY: values.currentOriginY,
212 width: values.targetWidth,
213 height: values.currentHeight,
214 },
215 animations: {
216 originX: values.targetOriginX,
217 originY: withTiming(values.targetOriginY, timing),
218 width: values.targetWidth,
219 height: withTiming(values.targetHeight, timing),
220 },
221 };
222};
223export const COMPOSER_LAYOUT_TRANSITION =
224 Platform.OS === "android" ? undefined : composerHeightTransition;
225// Share of the one-row composer the draft keeps; a long model name truncates first.
226const INLINE_EDITOR_MIN_WIDTH = "40%";
227// The one-row editor's horizontal padding plus room for the caret.
228const INLINE_EDITOR_TEXT_SLACK = 10;
229const INLINE_EDITOR_HEIGHT = 36;
230​
231const COMPOSER_ATTACHMENT_ENTERING =
232 Platform.OS === "android"
233 ? FadeIn.duration(160)
234 : FadeIn.delay(COMPOSER_TRANSITION_DURATION_MS).duration(160).reduceMotion(ReduceMotion.System);
235​
236const AnimatedGlassSurface = Animated.createAnimatedComponent(GlassSurface);
237​
238const FOLLOW_UP_ACTION_LABEL = {
239 queue: "Queue",
240 steer: "Steer now",
241 restart: "Restart turn",
242} as const;
243​
244const FOLLOW_UP_ACTION_SUBTITLE = {
245 queue: "Run after the current turn",
246 steer: "Interrupt what the agent is doing",
247 restart: "Start the turn over with this message",
248} as const;
249​
250function SendActionButton(props: {
251 readonly accessibilityLabel: string;
252 readonly presentation: ComposerSendPresentation;
253 readonly disabled: boolean;
254 readonly onSend: (followUp?: ActiveTurnComposerAction) => void;
255}) {
256 const { presentation } = props;
257 const button = (
258 <ComposerActionButton
259 accessibilityLabel={props.accessibilityLabel}
260 icon={presentation.icon}
261 variant="primary"
262 disabled={props.disabled}
263 onPress={() => props.onSend()}
264 />
265 );
266 if (!presentation.offersFollowUpChoice || presentation.action === null || props.disabled) {
267 return button;
268 }
269 const actions = [presentation.action, presentation.alternate].filter(
270 (action): action is ActiveTurnComposerAction => action !== null,
271 );
272 return (
273 <Menu
274 accessibilityLabel="Choose how to send this message"
275 shouldOpenOnLongPress
276 actions={actions.map((action) => ({
277 id: action,
278 title: FOLLOW_UP_ACTION_LABEL[action],
279 subtitle: FOLLOW_UP_ACTION_SUBTITLE[action],
280 state: action === presentation.action ? ("on" as const) : ("off" as const),
281 }))}
282 onPressAction={({ nativeEvent }) =>
283 props.onSend(nativeEvent.event as ActiveTurnComposerAction)
284 }
285 >
286 {button}
287 </Menu>
288 );
290​
291export function ComposerSurface(props: {
292 readonly children: ReactNode;
293 readonly style: ViewStyle;
294 readonly animateLayout?: boolean;
295}) {
296 const colors = useUniwindTheme();
297 const targetBorderRadius =
298 typeof props.style.borderRadius === "number" ? props.style.borderRadius : 0;
299 const animatedBorderRadius = useSharedValue(targetBorderRadius);
300 const shouldAnimate = props.animateLayout !== false && Platform.OS !== "android";
301 useLayoutEffect(() => {
302 animatedBorderRadius.value = shouldAnimate
303 ? withTiming(targetBorderRadius, {
304 duration: COMPOSER_TRANSITION_DURATION_MS,
305 reduceMotion: ReduceMotion.System,
306 })
307 : targetBorderRadius;
308 }, [animatedBorderRadius, shouldAnimate, targetBorderRadius]);
309 const animatedShapeStyle = useAnimatedStyle(() => ({
310 borderRadius: animatedBorderRadius.value,
311 }));
312 const layoutTransition = shouldAnimate ? COMPOSER_LAYOUT_TRANSITION : undefined;
313​
314 // Each native frame follows the same transition. Animating only the outer
315 // clip leaves the glass and content at their final height on the first frame.
316 return (
317 <Animated.View
318 className={
319 Platform.OS === "android" ? undefined : "shadow-[0_6px_28px] shadow-adaptive-black-a15-a35"
320 }
321 layout={layoutTransition}
322 style={[
323 animatedShapeStyle,
324 {
325 overflow: "hidden",
326 },
327 ]}
328 >
329 <AnimatedGlassSurface
330 chrome="none"
331 fallbackColor={colors["--color-composer-surface"]}
332 fallbackClassName="border border-composer-border"
333 glassEffectStyle="regular"
334 pointerEvents="none"
335 tintColor="transparent"
336 layout={layoutTransition}
337 style={[{ position: "absolute", inset: 0 }, animatedShapeStyle]}
338 >
339 {null}
340 </AnimatedGlassSurface>
341 <Animated.View
342 collapsable={false}
343 layout={layoutTransition}
344 style={[props.style, animatedShapeStyle]}
345 >
346 {props.children}
347 </Animated.View>
348 </Animated.View>
349 );
351​
352/** Space below the composer pill, inside the bottom inset it is given. */
353export const THREAD_COMPOSER_BOTTOM_GUTTER = 6;
354​
355export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps) {
356 const project = useProject(scopeProjectRef(props.environmentId, props.selectedThread.projectId));
357 const { themeVariables: materialTheme } = useAppearancePreferences();
358 const composerPanel = materialTheme["--color-composer-panel"];
359 const navigation = useNavigation();
360 const foregroundColor = useUniwindTheme()["--color-foreground"];
361 const bodyText = useScaledTextRole("body");
362 const fallbackInputRef = useRef<ComposerEditorHandle>(null);
363 const inputRef = props.editorRef ?? fallbackInputRef;
364 const [isFocused, setIsFocused] = useState(false);
365 const pendingPastedTextAttachmentCountRef = useRef(0);
366 const pendingNativeImagePasteCountRef = useRef(0);
367 const [pendingPastedTextAttachmentCount, setPendingPastedTextAttachmentCount] = useState(0);
368 const settingsSheetPresentation = useThreadSettingsSheetPresentation({
369 editorRef: inputRef,
370 isEditorFocused: isFocused,
371 });
372 const settingsRoutePresentation = useExistingThreadSettingsRoutePresentation();
373 const settingsRoutePresentedRef = useRef(false);
374 const wasExpandedBeforePreviewRef = useRef(false);
375 const inFlightThreadIdsRef = useRef(new Set<string>());
376 const { onExpandedChange } = props;
377​
378 const [previewFile, setPreviewFile] = useState<FilePreviewSource | null>(null);
379 const [previewVideo, setPreviewVideo] = useState<VideoPreviewSource | null>(null);
380 const composerOwnerKey = scopedThreadKey(props.environmentId, props.selectedThread.id);
381 const composerDraftKey = props.draftKey ?? composerOwnerKey;
382 const { text: draftMessage, attachments: draftAttachments } = useComposerDraft(composerDraftKey);
383 const queuedEdit = props.queuedEdit ?? null;
384 const hasContent =
385 draftMessage.trim().length > 0 ||
386 draftAttachments.length > 0 ||
387 (queuedEdit?.existingAttachments.length ?? 0) > 0;
388 const stripAttachments = composerStripAttachments(draftAttachments);
389 const showStopAction = !hasContent && props.canStopThread && queuedEdit === null;
390 const onResumeQueue = props.onResumeQueue;
391 const [resumingQueue, setResumingQueue] = useState(false);
392 const showResumeAction =
393 !hasContent && !showStopAction && queuedEdit === null && onResumeQueue !== null;
394 const handleResumeQueue = async () => {
395 if (resumingQueue || onResumeQueue === null) return;
396 setResumingQueue(true);
397 await onResumeQueue();
398 setResumingQueue(false);
399 };
400​
401 const uploadStates = useAtomValue(composerAttachmentUploadsAtom);
402 const attachmentsUploading =
403 props.connectionState === "connected" &&
404 composerAttachmentsStillUploading({
405 environmentId: props.environmentId,
406 attachments: draftAttachments,
407 serverConfig: props.serverConfig,
408 states: uploadStates,
409 });
410 const sendPresentation = resolveComposerSendPresentation({
411 editingQueuedMessage: queuedEdit !== null,
412 running: props.activeThreadBusy,
413 canSteer: props.canSteerActiveTurn,
414 followUpBehavior: props.followUpBehavior,
415 deliveryDeferred:
416 props.connectionState !== "connected" || props.queueCount > 0 || attachmentsUploading,
417 });
418 const sendLabel = sendPresentation.label;
419 const currentModelSelection = props.selectedThread.modelSelection;
420 const currentRuntimeMode = props.selectedThread.runtimeMode;
421 const modelUnavailable =
422 props.connectionState === "connected" &&
423 isModelSelectionUnavailable(
424 props.serverConfig,
425 currentModelSelection,
426 props.selectedThread.projectId,
427 );
428 const selectedProviderStatus = (() => {
429 if (!props.serverConfig) return null;
430 return (
431 props.serverConfig.providers.find(
432 (p) => p.instanceId === props.selectedThread.modelSelection.instanceId,
433 ) ?? null
434 );
435 })();
436 const openDraftDocument = (attachment: ComposerDocumentAttachment) => {
437 Keyboard.dismiss();
438 navigation.navigate("ThreadAttachment", {
439 environmentId: String(props.environmentId),
440 threadId: String(props.selectedThread.id),
441 attachmentId: attachment.attachmentId,
442 name: attachment.name,
443 mimeType: attachment.mimeType,
444 sizeBytes: String(attachment.sizeBytes),
445 draftKey: composerDraftKey,
446 });
447 };
448 const { onSendMessage, onChangeDraftMessage, onShowUsageLimits } = props;
449 const usageLimitsOffered =
450 selectedProviderStatus !== null &&
451 hasProviderUsageLimits(
452 selectedProviderStatus.driver,
453 props.serverConfig?.providers ?? [],
454 props.serverConfig?.usageLimitSources ?? [],
455 );
456 const openUsageLimits = () => {
457 const report = collectProviderUsageLimits(
458 currentModelSelection.instanceId,
459 props.serverConfig?.providers ?? [],
460 props.serverConfig?.usageLimitSources ?? [],
461 Date.now(),
462 );
463 onShowUsageLimits(report);
464 if (!report) {
465 Dialog.alert("Usage limits unavailable", "This provider does not currently report limits.");
466 }
467 return report !== null;
468 };
469​
470 const composerMenu = useComposerCommandMenu({
471 draftMessage: draftMessage,
472 ownerKey: composerDraftKey,
473 environmentId: props.environmentId,
474 threadShells: useThreadShells(),
475 currentThreadId: props.selectedThread.id,
476 projectCwd: props.projectCwd,
477 pullRequestProjectId: props.serverConfig?.environment.capabilities.pullRequests
478 ? (project?.id ?? null)
479 : null,
480 pullRequestRepository: project?.repositoryIdentity?.displayName ?? null,
481 threadPullRequests: props.selectedThread.pullRequests,
482 selectedProviderStatus,
483 hasThread: true,
484 hasCompactableConversation: props.hasCompactableConversation,
485 onChangeDraftMessage: props.onChangeDraftMessage,
486 onUpdateInteractionMode:
487 selectedProviderStatus?.showInteractionModeToggle === false
488 ? undefined
489 : props.onUpdateInteractionMode,
490 offersUsageLimits: usageLimitsOffered,
491 onUsageLimits:
492 usageLimitsOffered && draftAttachments.length === 0 ? openUsageLimits : undefined,
493 });
494 const voiceInput = useVoiceInputController({
495 ownerKey: composerDraftKey,
496 label: props.selectedThread.title || "Untitled thread",
497 readDraftMessage: () => getComposerDraftSnapshot(composerDraftKey).text,
498 subscribeToDraftChanges: (onChange) => appAtomRegistry.subscribe(composerDraftsAtom, onChange),
499 selection: composerMenu.selection,
500 onChangeDraftMessage: (text) => setComposerDraftText(composerDraftKey, text),
501 onChangeSelection: composerMenu.onSelectionChange,
502 });
503 const isSubmissionLocked = queuedEdit?.saving === true || voiceInput.blocksSubmission;
504 const voicePresentation = resolveVoiceComposerPresentation(
505 voiceInput.state,
506 voiceInput.elapsedSeconds,
507 );
508 const isVoiceInputPresented = voicePresentation.statusLabel !== null;
509 const isExpanded = isFocused || settingsSheetPresentation.keepsComposerExpanded;
510 const { setComposerEditing } = useAdaptiveWorkspaceLayout();
511 // The composer stays one row, with the model picker in it, until the draft would
512 // wrap. Then the draft stacks above the controls and returns to the row once it
513 // fits again. The native editor reports its laid-out text size: more than one
514 // line means the draft wrapped where it is, and the widest line is a one-line
515 // draft's natural width, which is compared with the row's text area so a draft
516 // laid out in the wider card still returns to the row when it fits, including
517 // when the pane widens. The measurements live in refs and only the verdict is
518 // state, so a keystroke that keeps the verdict costs no extra render.
519 const draftSizeRef = useRef({ width: 0, height: 0 });
520 const rowGeometryRef = useRef({ surfaceWidth: 0, leadingWidth: 0, trailingWidth: 0 });
521 const [draftOverflowsRow, setDraftOverflowsRow] = useState(false);
522 const lineHeight = bodyText.lineHeight;
523 const updateDraftOverflow = () => {
524 const { width, height } = draftSizeRef.current;
525 const row = rowGeometryRef.current;
526 const rowTextWidth =
527 row.surfaceWidth - row.leadingWidth - row.trailingWidth - INLINE_EDITOR_TEXT_SLACK;
528 setDraftOverflowsRow(
529 height > lineHeight * 1.5 || (row.surfaceWidth > 0 && width > rowTextWidth),
530 );
531 };
532 const measureRow = (key: keyof typeof rowGeometryRef.current, value: number) => {
533 if (rowGeometryRef.current[key] === value) return;
534 rowGeometryRef.current = { ...rowGeometryRef.current, [key]: value };
535 updateDraftOverflow();
536 };
537 const usesCard = isExpanded && draftMessage.length > 0 && draftOverflowsRow;
538 const showsCompactDictation = isVoiceInputPresented && !usesCard;
539 const isToolbarVisible = usesCard || isVoiceInputPresented;
540 const hasEditingAttachments =
541 (queuedEdit !== null && queuedEdit.existingAttachments.length > 0) ||
542 stripAttachments.length > 0;
543 const attachmentBlockReason = composerAttachmentUploadBlockReason({
544 environmentId: props.environmentId,
545 attachments: draftAttachments,
546 connected: props.connectionState === "connected",
547 serverConfig: props.serverConfig,
548 states: uploadStates,
549 });
550 const contextImports = useAtomValue(composerContextImportsAtom);
551 const sendBlockedReason =
552 (queuedEdit?.saving === true ? "Saving…" : null) ??
553 props.sendBlockedReason ??
554 (pendingPastedTextAttachmentCount > 0 ? "Attaching pasted text" : null) ??
555 attachmentBlockReason;
556 const canSend =
557 (props.canOperateThread || props.connectionState !== "connected") &&
558 hasContent &&
559 !contextImports[composerDraftKey] &&
560 !isSubmissionLocked &&
561 sendBlockedReason === null &&
562 !modelUnavailable;
563​
564 useEffect(() => {
565 onExpandedChange?.(usesCard);
566 }, [usesCard, onExpandedChange]);
567 useEffect(() => () => setComposerEditing(false), [setComposerEditing]);
568​
569 const onPressPreview = (source: FilePreviewSource) => {
570 wasExpandedBeforePreviewRef.current = isFocused;
571 setPreviewVideo(null);
572 setPreviewFile(
573 (current) =>
574 current ?? {
575 ...source,
576 gallery: filePreviewGallery(source, composerImageGallery(draftAttachments)),
577 },
578 );
579 };
580​
581 const closePreview = () => {
582 setPreviewFile(null);
583 setPreviewVideo(null);
584 if (wasExpandedBeforePreviewRef.current) {
585 setTimeout(() => {
586 if (navigation.isFocused()) inputRef.current?.focus();
587 }, 100);
588 }
589 };
590​
591 const onPressVideo = (attachment: DraftComposerFileAttachment, sourceIdentifier: string) => {
592 wasExpandedBeforePreviewRef.current = isFocused;
593 setPreviewFile(null);
594 setPreviewVideo((current) => current ?? { type: "local", attachment, sourceIdentifier });
595 };
596​
597 const onEditorFocusChange = props.onEditorFocusChange;
598 const handleFocus = () => {
599 setIsFocused(true);
600 onEditorFocusChange?.(true);
601 setComposerEditing(true);
602 };
603​
604 const handleBlur = () => {
605 setIsFocused(false);
606 onEditorFocusChange?.(false);
607 setComposerEditing(false);
608 };
609 const handleSend = async (followUp?: ActiveTurnComposerAction) => {
610 if (
611 isSubmissionLocked ||
612 pendingPastedTextAttachmentCountRef.current > 0 ||
613 pendingNativeImagePasteCountRef.current > 0
614 )
615 return;
616 if (usageLimitsOffered && isUsageLimitsCommand(draftMessage) && draftAttachments.length === 0) {
617 if (openUsageLimits()) onChangeDraftMessage("");
618 return;
619 }
620 const threadKey = scopedThreadKey(props.environmentId, props.selectedThread.id);
621 if (inFlightThreadIdsRef.current.has(threadKey)) return;
622 inFlightThreadIdsRef.current.add(threadKey);
623 const draftAtSend = getComposerDraftSnapshot(composerDraftKey);
624 const stillSendable = () => {
625 const draft = getComposerDraftSnapshot(composerDraftKey);
626 return (
627 pendingPastedTextAttachmentCountRef.current === 0 &&
628 pendingNativeImagePasteCountRef.current === 0 &&
629 draft.text === draftAtSend.text &&
630 draft.attachments.length === draftAtSend.attachments.length &&
631 draft.attachments.every(
632 (attachment, index) => attachment.id === draftAtSend.attachments[index]?.id,
633 )
634 );
635 };
636 const sent = await settlePromise(() => onSendMessage(followUp, stillSendable));
637 inFlightThreadIdsRef.current.delete(threadKey);
638 if (AsyncResult.isFailure(sent)) {
639 // The composer state already surfaces send errors; only the lock needed releasing.
640 console.error("[composer] send failed", squashAtomCommandFailure(sent));
641 return;
642 }
643 if (sent.value === null) return;
644 // Armed after the send so its preference read and native Activity start don't contend
645 // with the queued-message feedback on the tap frame.
646 armAgentAwarenessLiveActivityForLocalWork({
647 environmentId: props.environmentId,
648 threadTitle: props.selectedThread.title,
649 projectTitle: props.environmentLabel ?? "T3 Code",
650 });
651 };
652​
653 const lockedProviderInstanceId = props.canSwitchProvider
654 ? undefined
655 : currentModelSelection.instanceId;
656 const modelOptions = buildModelOptions(
657 props.serverConfig,
658 currentModelSelection,
659 lockedProviderInstanceId,
660 props.selectedThread.projectId,
661 );
662 const threadProviderGroups = groupByProvider(modelOptions);
663 const currentModelOption =
664 modelOptions.find(
665 (option) =>
666 option.selection.instanceId === currentModelSelection.instanceId &&
667 option.selection.model === currentModelSelection.model,
668 ) ?? null;
669 const providerOptionDescriptors = resolveProviderOptionDescriptors({
670 capabilities: currentModelOption?.capabilities,
671 selections: currentModelSelection.options,
672 });
673 const settingsOwnerId = composerOwnerKey;
674 const settingsRouteSession = {
675 ownerId: settingsOwnerId,
676 environmentId: props.environmentId,
677 projectId: props.selectedThread.projectId,
678 providerInstanceId: currentModelSelection.instanceId,
679 ...(lockedProviderInstanceId ? { lockedProviderInstanceId } : {}),
680 providerGroups: threadProviderGroups,
681 selectedModel: currentModelSelection,
682 prompt: draftMessage,
683 onPromptChange: (text) => setComposerDraftText(composerDraftKey, text),
684 reportedModelSelection: props.reportedModelSelection,
685 onSelectModel: (option) =>
686 props.onUpdateModelSelection(withRememberedModelOptions(option.selection)),
687 restoreSelection: withRememberedModelOptions,
688 optionDescriptors: providerOptionDescriptors,
689 onUpdateOptionSelections: (options) => {
690 rememberModelOptions(
691 currentModelSelection.instanceId,
692 currentModelSelection.model,
693 options ?? [],
694 );
695 props.onUpdateModelSelection({ ...currentModelSelection, options });
696 },
697 runtimeMode: currentRuntimeMode,
698 onUpdateRuntimeMode: props.onUpdateRuntimeMode,
699 } satisfies ExistingThreadSettingsRouteSession;
700 const openSettings = () => {
701 settingsRoutePresentation.present(settingsRouteSession);
702 settingsSheetPresentation.open();
703 };
704​
705 useEffect(() => {
706 if (settingsSheetPresentation.isActive) {
707 settingsRoutePresentation.present(settingsRouteSession);
708 }
709 }, [settingsRoutePresentation.present, settingsRouteSession, settingsSheetPresentation.isActive]);
710​
711 useEffect(() => {
712 if (!settingsSheetPresentation.isVisible || settingsRoutePresentedRef.current) {
713 return;
714 }
715​
716 settingsRoutePresentedRef.current = true;
717 navigation.dispatch(StackActions.push("ThreadSettingsSheet"));
718 }, [navigation, settingsSheetPresentation.isVisible]);
719​
720 useFocusEffect(() => {
721 if (!settingsRoutePresentedRef.current) {
722 return;
723 }
724​
725 settingsRoutePresentedRef.current = false;
726 settingsSheetPresentation.onDismissed();
727 settingsRoutePresentation.clear(settingsOwnerId);
728 });
729​
730 useEffect(
731 () =>
732 // UIKit's completion callback for the sheet dismissal, surfaced by the
733 // native-stack patch. This is when the queued keyboard restore runs.
734 (navigation as unknown as NavigationWithFinishTransitioning).addListener(
735 "finishTransitioning",
736 settingsSheetPresentation.onStackTransitionsFinished,
737 ),
738 [navigation, settingsSheetPresentation.onStackTransitionsFinished],
739 );
740​
741 // Removable attachments: inside the card, or above the focused one-row composer.
742 const editingAttachments = hasEditingAttachments ? (
743 <>
744 {queuedEdit !== null && queuedEdit.existingAttachments.length > 0 ? (
745 <Animated.View
746 className="px-[14px] pb-2.5"
747 entering={COMPOSER_ATTACHMENT_ENTERING}
748 exiting={FadeOut.duration(120)}
749 >
750 <ComposerQueuedEditAttachments
751 environmentId={props.environmentId}
752 attachments={queuedEdit.existingAttachments}
753 disabled={isSubmissionLocked}
754 onRemove={queuedEdit.onRemoveExistingAttachment}
755 />
756 </Animated.View>
757 ) : null}
758 {stripAttachments.length > 0 ? (
759 <Animated.View
760 className="px-[14px] pb-2.5"
761 entering={COMPOSER_ATTACHMENT_ENTERING}
762 exiting={FadeOut.duration(120)}
763 >
764 <ComposerAttachmentStrip
765 environmentId={props.environmentId}
766 attachments={stripAttachments}
767 onRemove={isSubmissionLocked ? () => undefined : props.onRemoveDraftImage}
768 onPressPreview={isSubmissionLocked ? undefined : onPressPreview}
769 onPressVideo={isSubmissionLocked ? undefined : onPressVideo}
770 onPressDocument={
771 isSubmissionLocked
772 ? undefined
773 : (attachment) =>
774 openDraftDocument({
775 attachmentId: attachment.id,
776 name: attachment.name,
777 mimeType: attachment.mimeType,
778 sizeBytes: attachment.sizeBytes,
779 })
780 }
781 />
782 </Animated.View>
783 ) : null}
784 </>
785 ) : null;
786​
787 // The row and the card's toolbar share this picker. It shrinks to the provider
788 // icon in the row once the draft has text, so the draft keeps the width.
789 const modelControl = (
790 <View className="min-w-0 shrink">
791 <ComposerModelControl
792 modelOption={currentModelOption}
793 selection={currentModelSelection}
794 provider={selectedProviderStatus?.driver}
795 reportedSelection={props.reportedModelSelection}
796 prompt={draftMessage}
797 surfaceColor={composerPanel}
798 iconOnly={!usesCard && draftMessage.length > 0}
799 showSummary={usesCard}
800 onPress={openSettings}
801 />
802 </View>
803 );
804​
805 return (
806 <Animated.View
807 className="px-[12px]"
808 style={{
809 paddingTop: usesCard ? 8 : 6,
810 paddingBottom: (props.bottomInset ?? 0) + (usesCard ? 8 : THREAD_COMPOSER_BOTTOM_GUTTER),
811 backgroundColor:
812 Platform.OS === "android" ? themeColorWithAlpha(composerPanel, 1) : undefined,
813 }}
814 >
815 {/* The backdrop gradient lives on a plain View: Reanimated's Animated.View
816 silently drops experimental_backgroundImage on Android, which left this
817 strip fully transparent and the feed text legible through the composer. */}
818 <View
819 className={
820 Platform.OS === "android"
821 ? "hidden"
822 : "absolute inset-0 bg-linear-to-b from-screen/0 via-screen/60 to-screen/90"
823 }
824 pointerEvents="none"
825 />
826 <Animated.View
827 className="relative w-full self-center"
828 style={{ maxWidth: props.contentMaxWidth }}
829 onLayout={(event) => measureRow("surfaceWidth", event.nativeEvent.layout.width)}
830 >
831 {!isSubmissionLocked &&
832 composerMenu.trigger &&
833 (composerMenu.items.length > 0 || composerMenu.trigger.kind === "pull-request") ? (
834 <ComposerPopoverAnchor>
835 <ComposerCommandPopover
836 items={composerMenu.items}
837 triggerKind={composerMenu.trigger.kind}
838 isLoading={composerMenu.isLoading}
839 error={composerMenu.error}
840 onSelect={composerMenu.onSelect}
841 />
842 </ComposerPopoverAnchor>
843 ) : null}
844​
845 {selectedProviderStatus?.compatibilityAdvisory?.message &&
846 (selectedProviderStatus.compatibilityAdvisory.status === "unsupported" ||
847 selectedProviderStatus.compatibilityAdvisory.status === "broken") ? (
848 <Text
849 accessibilityRole={
850 selectedProviderStatus.compatibilityAdvisory.status === "broken" ? "alert" : undefined
851 }
852 accessibilityLiveRegion={
853 selectedProviderStatus.compatibilityAdvisory.status === "broken"
854 ? "assertive"
855 : "polite"
856 }
857 className={
858 selectedProviderStatus.compatibilityAdvisory.status === "broken"
859 ? "bg-danger px-3 py-2 text-xs text-danger-foreground"
860 : "px-3 py-2 text-xs text-foreground"
861 }
862 >
863 {selectedProviderStatus.compatibilityAdvisory.message}
864 </Text>
865 ) : null}
866 {modelUnavailable ? (
867 <Button
868 label="Model unavailable. Open model settings."
869 tone="text"
870 onPress={openSettings}
871 />
872 ) : null}
873​
874 <ComposerSurface
875 style={
876 usesCard
877 ? {
878 borderRadius: 26,
879 overflow: "hidden" as const,
880 paddingBottom: 6,
881 paddingTop: 14,
882 }
883 : {
884 borderRadius: 27,
885 overflow: "hidden" as const,
886 paddingVertical: 2,
887 }
888 }
889 >
890 {isExpanded && !usesCard ? editingAttachments : null}
891 <ComposerDictationDraftContent
892 className={usesCard ? undefined : "flex-row items-center"}
893 compact={!usesCard}
894 hidden={showsCompactDictation}
895 >
896 {!usesCard ? (
897 <ComposerAttachmentButton
898 disabled={isSubmissionLocked}
899 supportsFiles={Boolean(
900 props.serverConfig?.environment.capabilities.fileAttachments,
901 )}
902 onPickMedia={props.onPickDraftMedia}
903 onPickFiles={props.onPickDraftFiles}
904 />
905 ) : null}
906 {usesCard ? editingAttachments : null}
907 <Animated.View
908 className={usesCard ? "px-[14px]" : "min-w-0 flex-1 px-[4px]"}
909 style={usesCard ? undefined : { minWidth: INLINE_EDITOR_MIN_WIDTH }}
910 layout={COMPOSER_LAYOUT_TRANSITION}
911 onLayout={
912 usesCard
913 ? undefined
914 : (event) => measureRow("leadingWidth", event.nativeEvent.layout.x)
915 }
916 >
917 <ComposerEditor
918 hidden={props.hidden}
919 draftKey={composerDraftKey}
920 environmentId={props.environmentId}
921 onOpenMention={(path) => {
922 Keyboard.dismiss();
923 navigation.navigate("ThreadFile", {
924 environmentId: String(props.environmentId),
925 threadId: String(props.selectedThread.id),
926 path: fileRoutePathSegments(path),
927 });
928 }}
929 onOpenAttachment={openDraftDocument}
930 chipsInert={!isExpanded}
931 onInertChipPress={() => inputRef.current?.focus()}
932 ref={inputRef}
933 multiline
934 value={draftMessage}
935 // The save uses a draft snapshot; further typing would be discarded on success.
936 readOnly={isSubmissionLocked}
937 skills={composerMenu.skills}
938 selection={composerMenu.selection}
939 onChangeText={(text) => {
940 if (!isSubmissionLocked) props.onChangeDraftMessage(text);
941 }}
942 onSelectionChange={composerMenu.onSelectionChange}
943 onPasteImages={(uris) => {
944 if (isSubmissionLocked) return;
945 pendingNativeImagePasteCountRef.current += 1;
946 void props.onNativePasteImages(uris).finally(() => {
947 pendingNativeImagePasteCountRef.current -= 1;
948 });
949 }}
950 onPasteText={(paste) => {
951 if (isSubmissionLocked) return;
952 const insertPaste = () => {
953 const insertion = replaceTextSelection({
954 value: paste.value,
955 selection: paste.selection,
956 text: paste.text,
957 });
958 const selection = { start: insertion.cursor, end: insertion.cursor };
959 props.onChangeDraftMessage(insertion.value);
960 composerMenu.onSelectionChange(selection);
961 };
962 const capabilities = props.serverConfig?.environment.capabilities;
963 const advertisedMax =
964 capabilities?.attachmentUploads === true
965 ? capabilities.fileAttachments?.maxUploadBytes
966 : undefined;
967 const maxBytes =
968 advertisedMax === undefined
969 ? null
970 : clampFileAttachmentUploadBytes(advertisedMax);
971 const wouldExceedInputLimit =
972 paste.value.length -
973 Math.max(0, paste.selection.end - paste.selection.start) +
974 paste.text.length >
975 PROVIDER_SEND_TURN_MAX_INPUT_CHARS;
976 const canAttach =
977 maxBytes !== null &&
978 countComposerDraftAttachmentsAfterSelection(composerDraftKey, {
979 text: paste.value,
980 ...paste.selection,
981 }) < PROVIDER_SEND_TURN_MAX_ATTACHMENTS &&
982 new TextEncoder().encode(paste.text).byteLength <= maxBytes;
983 if (
984 pastedTextDisposition({
985 text: paste.text,
986 wouldExceedInputLimit,
987 canAttach: true,
988 }) === "attachment"
989 ) {
990 if (canAttach) {
991 pendingPastedTextAttachmentCountRef.current += 1;
992 setPendingPastedTextAttachmentCount(
993 pendingPastedTextAttachmentCountRef.current,
994 );
995 const finishAttachment = () => {
996 pendingPastedTextAttachmentCountRef.current = Math.max(
997 0,
998 pendingPastedTextAttachmentCountRef.current - 1,
999 );
1000 setPendingPastedTextAttachmentCount(
1001 pendingPastedTextAttachmentCountRef.current,
1002 );
1003 };
1004 void props.onNativePasteText(paste).then(finishAttachment, finishAttachment);
1005 } else if (!wouldExceedInputLimit) {
1006 insertPaste();
1007 } else {
1008 Dialog.alert(
1009 wouldExceedInputLimit
1010 ? "Pasted text is too large for this message"
1011 : "Could not attach pasted text",
1012 wouldExceedInputLimit
1013 ? "Remove some text or an attachment, then paste again."
1014 : "Remove an attachment or use a smaller paste, then try again.",
1015 );
1017 return;
1019 insertPaste();
1020 }}
1021 placeholder={props.placeholder}
1022 onFocus={handleFocus}
1023 onBlur={handleBlur}
1024 onSubmit={(alternate) =>
1025 void handleSend(
1026 alternate && sendPresentation.alternate !== null
1027 ? sendPresentation.alternate
1028 : undefined,
1031 submitTitle={sendPresentation.label}
1032 alternateSubmitTitle={
1033 sendPresentation.alternate === null
1034 ? sendPresentation.label
1035 : FOLLOW_UP_ACTION_LABEL[sendPresentation.alternate]
1037 scrollEnabled={isExpanded}
1038 singleLineCentered={!usesCard}
1039 contentInsetVertical={
1040 usesCard || Platform.OS === "android" ? 0 : collapsedEditorInset(bodyText)
1042 onContentSizeChange={(size) => {
1043 draftSizeRef.current = size;
1044 updateDraftOverflow();
1045 }}
1046 style={
1047 usesCard
1048 ? {
1049 // A stacked draft shows two to four lines, then scrolls.
1050 minHeight: lineHeight * 2 + 8,
1051 maxHeight: lineHeight * 4 + 8,
1052 paddingVertical: 4,
1054 : {
1055 // Large text sizes need room for one full line plus the iOS inset.
1056 height: Math.max(
1057 INLINE_EDITOR_HEIGHT,
1058 Math.ceil(lineHeight) +
1059 (Platform.OS === "android" ? 0 : 2 * collapsedEditorInset(bodyText)),
1060 ),
1063 textStyle={{
1064 ...bodyText,
1065 color: foregroundColor,
1066 }}
1067 />
1068 </Animated.View>
1069 {!isExpanded && stripAttachments.length > 0 ? (
1070 <View className="flex-row gap-1 pl-1">
1071 {stripAttachments.slice(0, 3).map((attachment) => (
1072 <ComposerAttachmentThumbnail
1073 environmentId={props.environmentId}
1074 key={attachment.id}
1075 attachment={attachment}
1076 size={30}
1077 borderRadius={8}
1078 compact
1079 onPressPreview={isSubmissionLocked ? undefined : onPressPreview}
1080 onPressVideo={isSubmissionLocked ? undefined : onPressVideo}
1081 />
1082 ))}
1083 {stripAttachments.length > 3 ? (
1084 <View className="size-[30px] items-center justify-center rounded-lg bg-subtle-strong">
1085 <Text className="text-foreground-muted text-2xs font-t3-bold">
1086 +{stripAttachments.length - 3}
1087 </Text>
1088 </View>
1089 ) : null}
1090 </View>
1091 ) : null}
1092 {!usesCard ? (
1093 <View
1094 className="min-w-0 shrink flex-row items-center"
1095 onLayout={(event) => measureRow("trailingWidth", event.nativeEvent.layout.width)}
1097 {modelControl}
1098 <ComposerDictationStartAction
1099 state={voiceInput.state}
1100 isAvailable={voiceInput.isAvailable}
1101 disabled={isSubmissionLocked}
1102 onStart={voiceInput.start}
1103 onCancel={voiceInput.cancel}
1104 />
1105 {showStopAction ? (
1106 <ComposerActionButton
1107 accessibilityLabel="Stop agent"
1108 icon="stop.fill"
1109 variant="danger"
1110 disabled={!props.canOperateThread}
1111 onPress={props.onStopThread}
1112 />
1113 ) : showResumeAction ? (
1114 <ComposerActionButton
1115 accessibilityLabel="Resume queue"
1116 icon="play"
1117 disabled={!props.canOperateThread || resumingQueue}
1118 onPress={() => void handleResumeQueue()}
1119 />
1120 ) : (
1121 <SendActionButton
1122 accessibilityLabel={sendBlockedReason ?? sendLabel}
1123 presentation={sendPresentation}
1124 disabled={!canSend}
1125 onSend={handleSend}
1126 />
1127 )}
1128 </View>
1129 ) : null}
1130 {usesCard ? <View className="h-1" /> : null}
1131 </ComposerDictationDraftContent>
1132 <Animated.View
1133 accessibilityElementsHidden={!isToolbarVisible}
1134 collapsable={false}
1135 importantForAccessibility={isToolbarVisible ? "auto" : "no-hide-descendants"}
1136 layout={COMPOSER_LAYOUT_TRANSITION}
1137 pointerEvents={isToolbarVisible ? "auto" : "none"}
1138 style={
1139 usesCard
1140 ? undefined
1141 : {
1142 position: "absolute",
1143 bottom: 2,
1144 left: 0,
1145 right: 0,
1149 <ComposerDictationToolbar
1150 showsDictation={isVoiceInputPresented}
1151 visible={isToolbarVisible}
1153 <ComposerToolbarRow
1154 paddingBottom={0}
1155 paddingHorizontal={0}
1156 paddingTop={0}
1157 style={{ gap: 0 }}
1159 <ComposerDictationCancelAction
1160 presentation={voicePresentation}
1161 onCancel={voiceInput.cancel}
1162 />
1163 {isVoiceInputPresented ? (
1164 <ComposerDictationStatus
1165 audioLevels={voiceInput.audioLevels}
1166 elapsedSeconds={voiceInput.elapsedSeconds}
1167 phase={voiceInput.state.phase}
1168 presentation={voicePresentation}
1169 onDismissError={voiceInput.cancel}
1170 />
1171 ) : (
1172 <View className="min-w-0 flex-1 flex-row items-center justify-between">
1173 <ComposerAttachmentButton
1174 disabled={isSubmissionLocked}
1175 supportsFiles={Boolean(
1176 props.serverConfig?.environment.capabilities.fileAttachments,
1177 )}
1178 onPickMedia={props.onPickDraftMedia}
1179 onPickFiles={props.onPickDraftFiles}
1180 />
1181 {modelControl}
1182 </View>
1183 )}
1184 <View className="shrink-0 flex-row items-center">
1185 <ComposerDictationPrimaryAction
1186 state={voiceInput.state}
1187 presentation={voicePresentation}
1188 isAvailable={voiceInput.isAvailable}
1189 disabled={isSubmissionLocked}
1190 onStart={voiceInput.start}
1191 onConfirm={voiceInput.stop}
1192 onCancel={voiceInput.cancel}
1193 />
1194 {showStopAction ? (
1195 <ComposerActionButton
1196 accessibilityLabel="Stop agent"
1197 icon="stop.fill"
1198 variant="danger"
1199 disabled={!props.canOperateThread}
1200 onPress={props.onStopThread}
1201 />
1202 ) : showResumeAction && voicePresentation.showsSend ? (
1203 <ComposerActionButton
1204 accessibilityLabel="Resume queue"
1205 icon="play"
1206 disabled={!props.canOperateThread || resumingQueue}
1207 onPress={() => void handleResumeQueue()}
1208 />
1209 ) : voicePresentation.showsSend ? (
1210 <SendActionButton
1211 accessibilityLabel={sendBlockedReason ?? sendLabel}
1212 presentation={sendPresentation}
1213 disabled={!canSend}
1214 onSend={handleSend}
1215 />
1216 ) : null}
1217 </View>
1218 </ComposerToolbarRow>
1219 </ComposerDictationToolbar>
1220 </Animated.View>
1221 </ComposerSurface>
1222​
1223 {props.connectionState === "connected" && !props.canOperateThread ? (
1224 <Text className="pt-2 text-xs text-foreground-muted">
1225 This connection cannot control this task. You can still edit your draft.
1226 </Text>
1227 ) : null}
1228 </Animated.View>
1229​
1230 <VideoPreviewModal source={previewVideo} onRequestClose={closePreview} />
1231 <FilePreviewModal source={previewFile} onRequestClose={closePreview} />
1232 </Animated.View>
1233 );