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

ThreadComposer.tsx

1,219 lines49.6 KB

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