Open History to see the last commit
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 { buildModelOptions, isModelSelectionUnavailable } from "../../lib/modelOptions";
90import { useScaledTextRole, type ScaledTextRole } from "../settings/appearance/useScaledTextRole";
91import type { RemoteClientConnectionState } from "../../lib/connection";
92import { MOBILE_TYPOGRAPHY } from "../../lib/typography";
93import { Menu } from "../../components/ui/Menu";
94import type { ActiveTurnComposerAction } from "@t3tools/client-runtime/state/composer-dispatch";
95import type { FollowUpBehavior } from "../../lib/followUpBehavior";
96import {
97 resolveComposerSendPresentation,
98 type ComposerSendPresentation,
99} from "./composerSendPresentation";
100import { compactEditorInsets } from "./compactEditorInsets";
101import { ComposerCommandPopover } from "./ComposerCommandPopover";
102import { ComposerPopoverAnchor } from "./ComposerPopoverAnchor";
103import { ComposerQueuedEditAttachments } from "./ComposerQueuedEdit";
104import { useComposerCommandMenu } from "./use-composer-command-menu";
105import type { ComposerEnvironmentCandidate } from "@t3tools/client-runtime/composerThreadItems";
106import { offersLinkedEnvironments } from "@t3tools/client-runtime/link-request";
107import {
108 ComposerDictationCancelAction,
109 ComposerDictationDraftContent,
110 ComposerDictationError,
111 ComposerDictationPrimaryAction,
112 ComposerDictationStartAction,
113 ComposerDictationStatus,
114 ComposerDictationToolbar,
115} from "../voice-input/ComposerDictationControl";
116import { useVoiceInputController } from "../voice-input/useVoiceInputController";
117import { resolveVoiceComposerPresentation } from "../voice-input/voiceInputPresentation";
118import type { ExistingThreadSettingsRouteParams } from "./ThreadSettingsSheet";
119import {
120 useThreadSettingsSheetPresentation,
121 type NavigationWithFinishTransitioning,
122} from "./use-thread-settings-sheet-presentation";
123
124export const COMPOSER_COLLAPSED_CHROME = 60;
125
126const NO_MACHINES: ReadonlyArray<ComposerEnvironmentCandidate> = [];
127const COLLAPSED_EDITOR_DEFAULT_INSET = 6;
128// iOS puts line-height slack above glyphs. DM Sans's lowercase midline is
129// descender (0.31em) + half x-height (0.504em) above the line bottom.
130const LOWERCASE_MIDLINE_EM = 0.562;
131
132function lowercaseMidline(text: ScaledTextRole): number {
133 return text.lineHeight - LOWERCASE_MIDLINE_EM * text.fontSize;
134}
135
136function collapsedEditorInset(text: ScaledTextRole): number {
137 const shift = lowercaseMidline(text) - lowercaseMidline(MOBILE_TYPOGRAPHY.body);
138 return Math.max(0, Math.round(COLLAPSED_EDITOR_DEFAULT_INSET - shift));
139}
140
141function useCompactComposerEditor(text: ScaledTextRole, value: string) {
142 const [contentSize, setContentSize] = useState({ width: 0, height: 0 });
143 const [compactWidth, setCompactWidth] = useState(0);
144 const contentHeight = contentSize.height;
145 const rowWidth = useSharedValue(0);
146 const editorX = useSharedValue(0);
147 const editorWidth = useSharedValue(0);
148 const inset =
149 Platform.OS === "android" ? COLLAPSED_EDITOR_DEFAULT_INSET : collapsedEditorInset(text);
150 const minimum = Math.max(INLINE_EDITOR_HEIGHT, Math.ceil(text.lineHeight) + 2 * inset);
151 const height = Math.max(
152 minimum,
153 Math.min(text.lineHeight * 4 + 2 * inset, contentHeight + 2 * inset),
154 );
155 // A line that fits the expanded editor may still overflow its compact slot.
156 // Compare its measured width too so widening cannot trigger a collapse loop.
157 const isExpanded =
158 value.length > 0 &&
159 (contentHeight > text.lineHeight * 1.5 ||
160 (compactWidth > 0 && contentSize.width > compactWidth));
161 const compactRowHeight = Math.max(44, minimum);
162 const isRTL = I18nManager.isRTL;
163 const editorStyle = useAnimatedStyle(() => ({
164 position: "absolute",
165 overflow: "hidden",
166 height,
167 ...(isExpanded
168 ? { left: 14, right: 14 }
169 : compactEditorInsets({
170 slotX: editorX.value,
171 slotWidth: editorWidth.value,
172 rowWidth: rowWidth.value,
173 isRTL,
174 })),
175 // The full-width editor must move above the controls in the same frame it widens.
176 bottom: isExpanded ? 52 : (compactRowHeight - minimum) / 2,
177 }));
178 return {
179 isExpanded,
180 containerStyle: { height: isExpanded ? height + 52 : compactRowHeight },
181 editorStyle,
182 onRowLayout: (event: { nativeEvent: { layout: { width: number } } }) => {
183 rowWidth.set(event.nativeEvent.layout.width);
184 },
185 onEditorLayout: (event: { nativeEvent: { layout: { x: number; width: number } } }) => {
186 // The expanded toolbar gives this slot to the model control. Keep the
187 // compact geometry for the return transition, rather than recording zero.
188 if (!isExpanded) {
189 editorX.set(event.nativeEvent.layout.x);
190 editorWidth.set(event.nativeEvent.layout.width);
191 setCompactWidth(Math.max(0, event.nativeEvent.layout.width - 8));
192 }
193 },
194 editorProps: {
195 singleLineCentered: !isExpanded,
196 scrollEnabled: Platform.OS === "android" || contentHeight >= text.lineHeight * 4,
197 contentInsetVertical: inset,
198 onContentSizeChange: (size: { width: number; height: number }) => {
199 setContentSize(size);
200 },
201 style: { flex: 1 },
202 },
203 };
204}
205
206export interface ThreadComposerProps {
207 readonly isDraft?: boolean;
208 readonly canOperateThread: boolean;
209 readonly placeholder: string;
210 readonly contentMaxWidth?: number;
211 readonly draftControls?: ReactNode;
212 readonly bottomInset?: number;
213 readonly connectionState: RemoteClientConnectionState;
214 readonly environmentLabel: string | null;
215 readonly selectedThread: EnvironmentThreadShell;
216 readonly reportedModelSelection?: ModelSelection | null;
217 readonly hasCompactableConversation: boolean;
218 /** Arms a fresh session for the next message; absent where `/clear` is unavailable. */
219 readonly onFreshSession?: () => void;
220 readonly offersSideChat?: boolean;
221 readonly serverConfig: T3ServerConfig | null;
222 readonly queueCount: number;
223 readonly activeThreadBusy: boolean;
224 readonly canStopThread: boolean;
225 readonly environmentId: EnvironmentId;
226 readonly projectCwd: string | null;
227 readonly sendBlockedReason?: string | null;
228 readonly interactionLocked?: boolean;
229 readonly draftKey?: string;
230 readonly queuedEdit?: {
231 readonly existingAttachments: ReadonlyArray<ChatAttachment>;
232 readonly saving: boolean;
233 readonly onRemoveExistingAttachment: (attachmentId: string) => void;
234 } | null;
235 readonly followUpBehavior: FollowUpBehavior;
236 readonly canSteerActiveTurn: boolean;
237 readonly hidden: boolean;
238 readonly editorRef?: RefObject<ComposerEditorHandle | null>;
239 readonly onChangeDraftMessage: (value: string) => void;
240 readonly onPickDraftMedia: () => Promise<void>;
241 readonly onPickDraftFiles: () => Promise<void>;
242 readonly onNativePasteImages: (uris: ReadonlyArray<string>) => Promise<void>;
243 readonly onNativePasteText: (paste: ComposerTextPaste) => Promise<void>;
244 readonly onRemoveDraftImage: (imageId: string) => void;
245 readonly onStopThread: () => void;
246 /** Present while the thread's queue is held. */
247 readonly onResumeQueue: (() => Promise<void>) | null;
248 /** `stillSendable` reports whether the draft is unchanged after any wait before sending. */
249 readonly onSendMessage: (
250 followUp?: ActiveTurnComposerAction,
251 stillSendable?: () => boolean,
252 ) => Promise<MessageId | null>;
253 readonly onShowUsageLimits: (report: UsageLimitsReport | null) => void;
254 readonly canSwitchProvider: boolean;
255 readonly onHeightChange?: (height: number) => void;
256 readonly onEditorFocusChange?: (focused: boolean) => void;
257}
258
259// Android KeyboardStickyView tracks the IME; concurrent timed layout morphs cause jitter.
260const COMPOSER_TRANSITION_DURATION_MS = 220;
261// Side panes animate dock width; nested horizontal transitions would make the surface trail the toolbar.
262const composerHeightTransition: LayoutAnimationFunction = (values) => {
263 "worklet";
264 const timing = {
265 duration: COMPOSER_TRANSITION_DURATION_MS,
266 reduceMotion: ReduceMotion.System,
267 };
268 return {
269 initialValues: {
270 originX: values.targetOriginX,
271 originY: values.currentOriginY,
272 width: values.targetWidth,
273 height: values.currentHeight,
274 },
275 animations: {
276 originX: values.targetOriginX,
277 originY: withTiming(values.targetOriginY, timing),
278 width: values.targetWidth,
279 height: withTiming(values.targetHeight, timing),
280 },
281 };
282};
283const COMPOSER_LAYOUT_TRANSITION = Platform.OS === "android" ? undefined : composerHeightTransition;
284// Share of the one-row composer the draft keeps; a long model name truncates first.
285const INLINE_EDITOR_MIN_WIDTH = "40%";
286const INLINE_EDITOR_HEIGHT = 36;
287
288const COMPOSER_ATTACHMENT_ENTERING =
289 Platform.OS === "android"
290 ? FadeIn.duration(160)
291 : FadeIn.delay(COMPOSER_TRANSITION_DURATION_MS).duration(160).reduceMotion(ReduceMotion.System);
292
293const AnimatedGlassSurface = Animated.createAnimatedComponent(GlassSurface);
294
295const FOLLOW_UP_ACTION_LABEL = {
296 queue: "Queue",
297 steer: "Steer now",
298 restart: "Restart turn",
299} as const;
300
301const FOLLOW_UP_ACTION_SUBTITLE = {
302 queue: "Run after the current turn",
303 steer: "Interrupt what the agent is doing",
304 restart: "Start the turn over with this message",
305} as const;
306
307function SendActionButton(props: {
308 readonly size?: "regular" | "large";
309 readonly accessibilityLabel: string;
310 readonly presentation: ComposerSendPresentation;
311 readonly disabled: boolean;
312 readonly onSend: (followUp?: ActiveTurnComposerAction) => void;
313}) {
314 const { presentation } = props;
315 const button = (
316 <ComposerActionButton
317 accessibilityLabel={props.accessibilityLabel}
318 size={props.size}
319 icon={presentation.icon}
320 variant="primary"
321 disabled={props.disabled}
322 onPress={() => props.onSend()}
323 />
324 );
325 if (!presentation.offersFollowUpChoice || presentation.action === null || props.disabled) {
326 return button;
327 }
328 const actions = [presentation.action, presentation.alternate].filter(
329 (action): action is ActiveTurnComposerAction => action !== null,
330 );
331 return (
332 <Menu
333 accessibilityLabel="Choose how to send this message"
334 shouldOpenOnLongPress
335 actions={actions.map((action) => ({
336 id: action,
337 title: FOLLOW_UP_ACTION_LABEL[action],
338 subtitle: FOLLOW_UP_ACTION_SUBTITLE[action],
339 state: action === presentation.action ? ("on" as const) : ("off" as const),
340 }))}
341 onPressAction={({ nativeEvent }) =>
342 props.onSend(nativeEvent.event as ActiveTurnComposerAction)
343 }
344 >
345 {button}
346 </Menu>
347 );
348}
349
350function ComposerSurface(props: {
351 readonly children: ReactNode;
352 readonly style: ViewStyle;
353 readonly animateLayout?: boolean;
354}) {
355 const colors = useUniwindTheme();
356 const targetBorderRadius =
357 typeof props.style.borderRadius === "number" ? props.style.borderRadius : 0;
358 const shouldAnimate = props.animateLayout !== false && Platform.OS !== "android";
359 const animatedBorderRadius = useDerivedValue(() =>
360 shouldAnimate
361 ? withTiming(targetBorderRadius, {
362 duration: COMPOSER_TRANSITION_DURATION_MS,
363 reduceMotion: ReduceMotion.System,
364 })
365 : targetBorderRadius,
366 );
367 const borderCurve = props.style.borderCurve;
368 const animatedShapeStyle = useAnimatedStyle(() => ({
369 borderRadius: animatedBorderRadius.value,
370 ...(borderCurve ? { borderCurve } : {}),
371 }));
372 const layoutTransition = shouldAnimate ? COMPOSER_LAYOUT_TRANSITION : undefined;
373
374 // Animate every native frame or glass and content jump to final height inside the clip.
375 return (
376 <Animated.View
377 className={
378 Platform.OS === "android" ? undefined : "shadow-[0_6px_28px] shadow-adaptive-black-a15-a35"
379 }
380 layout={layoutTransition}
381 style={[
382 animatedShapeStyle,
383 {
384 overflow: "hidden",
385 },
386 ]}
387 >
388 <AnimatedGlassSurface
389 chrome="none"
390 fallbackColor={colors["--color-composer-surface"]}
391 fallbackClassName="border border-composer-border"
392 glassEffectStyle="regular"
393 pointerEvents="none"
394 tintColor="transparent"
395 layout={layoutTransition}
396 style={[{ position: "absolute", inset: 0 }, animatedShapeStyle]}
397 >
398 {null}
399 </AnimatedGlassSurface>
400 <Animated.View
401 collapsable={false}
402 layout={layoutTransition}
403 style={[props.style, animatedShapeStyle]}
404 >
405 {props.children}
406 </Animated.View>
407 </Animated.View>
408 );
409}
410
411/** Space below the composer pill, inside the bottom inset it is given. */
412export const THREAD_COMPOSER_BOTTOM_GUTTER = 6;
413
414export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps) {
415 const project = useProject(scopeProjectRef(props.environmentId, props.selectedThread.projectId));
416 const { themeVariables: materialTheme } = useAppearancePreferences();
417 const composerPanel = materialTheme["--color-composer-panel"];
418 const navigation = useNavigation();
419 const foregroundColor = useUniwindTheme()["--color-foreground"];
420 const bodyText = useScaledTextRole("body");
421 const fallbackInputRef = useRef<ComposerEditorHandle>(null);
422 const inputRef = props.editorRef ?? fallbackInputRef;
423 const [isFocused, setIsFocused] = useState(false);
424 const pendingPastedTextAttachmentCountRef = useRef(0);
425 const pendingNativeImagePasteCountRef = useRef(0);
426 const [pendingPastedTextAttachmentCount, setPendingPastedTextAttachmentCount] = useState(0);
427 const settingsRoutePresentedRef = useRef(false);
428 const settingsSheetPresentation = useThreadSettingsSheetPresentation({
429 editorRef: inputRef,
430 onPresent: () => {
431 if (settingsRoutePresentedRef.current) return;
432 settingsRoutePresentedRef.current = true;
433 // The draft composer edits the new-task flow, which owns its own settings route.
434 navigation.dispatch(
435 props.isDraft
436 ? StackActions.push("NewTaskThreadSettings")
437 : StackActions.push("ThreadSettingsSheet", {
438 environmentId: props.environmentId,
439 threadId: props.selectedThread.id,
440 draftKey: composerDraftKey,
441 } satisfies ExistingThreadSettingsRouteParams),
442 );
443 },
444 });
445 const disposeSettingsSheetPresentation = useEffectEvent(settingsSheetPresentation.dispose);
446 const wasExpandedBeforePreviewRef = useRef(false);
447 const inFlightThreadIdsRef = useRef(new Set<string>());
448
449 const [previewFile, setPreviewFile] = useState<FilePreviewSource | null>(null);
450 const [previewVideo, setPreviewVideo] = useState<VideoPreviewSource | null>(null);
451 const composerOwnerKey = scopedThreadKey(props.environmentId, props.selectedThread.id);
452 const composerDraftKey = props.draftKey ?? composerOwnerKey;
453 const { text: draftMessage, attachments: draftAttachments } = useComposerDraft(composerDraftKey);
454 const queuedEdit = props.queuedEdit ?? null;
455 const hasContent =
456 draftMessage.trim().length > 0 ||
457 draftAttachments.length > 0 ||
458 (queuedEdit?.existingAttachments.length ?? 0) > 0;
459 const stripAttachments = composerStripAttachments(draftAttachments);
460 const showStopAction = !hasContent && props.canStopThread && queuedEdit === null;
461 const onResumeQueue = props.onResumeQueue;
462 const [resumingQueue, setResumingQueue] = useState(false);
463 const showResumeAction =
464 !hasContent && !showStopAction && queuedEdit === null && onResumeQueue !== null;
465 const handleResumeQueue = async () => {
466 if (resumingQueue || onResumeQueue === null) return;
467 setResumingQueue(true);
468 await onResumeQueue();
469 setResumingQueue(false);
470 };
471
472 const uploadStates = useAtomValue(composerAttachmentUploadsAtom);
473 const attachmentsUploading =
474 props.connectionState === "connected" &&
475 composerAttachmentsStillUploading({
476 environmentId: props.environmentId,
477 attachments: draftAttachments,
478 serverConfig: props.serverConfig,
479 states: uploadStates,
480 });
481 const sendPresentation = resolveComposerSendPresentation({
482 editingQueuedMessage: queuedEdit !== null,
483 running: props.activeThreadBusy,
484 canSteer: props.canSteerActiveTurn,
485 followUpBehavior: props.followUpBehavior,
486 deliveryDeferred:
487 props.connectionState !== "connected" || props.queueCount > 0 || attachmentsUploading,
488 });
489 const sendLabel = sendPresentation.label;
490 const currentModelSelection = props.selectedThread.modelSelection;
491 const modelUnavailable =
492 props.connectionState === "connected" &&
493 isModelSelectionUnavailable(
494 props.serverConfig,
495 currentModelSelection,
496 props.selectedThread.projectId,
497 );
498 const selectedProviderStatus = (() => {
499 if (!props.serverConfig) return null;
500 return (
501 props.serverConfig.providers.find(
502 (p) => p.instanceId === props.selectedThread.modelSelection.instanceId,
503 ) ?? null
504 );
505 })();
506 const openDraftDocument = (attachment: ComposerDocumentAttachment) => {
507 Keyboard.dismiss();
508 navigation.navigate("ThreadAttachment", {
509 environmentId: String(props.environmentId),
510 threadId: String(props.selectedThread.id),
511 attachmentId: attachment.attachmentId,
512 name: attachment.name,
513 mimeType: attachment.mimeType,
514 sizeBytes: String(attachment.sizeBytes),
515 draftKey: composerDraftKey,
516 });
517 };
518 const { onSendMessage, onChangeDraftMessage, onShowUsageLimits } = props;
519 const usageLimitsOffered =
520 selectedProviderStatus !== null &&
521 hasProviderUsageLimits(
522 selectedProviderStatus.driver,
523 props.serverConfig?.providers ?? [],
524 props.serverConfig?.usageLimitSources ?? [],
525 );
526 const openUsageLimits = () => {
527 const report = collectProviderUsageLimits(
528 currentModelSelection.instanceId,
529 props.serverConfig?.providers ?? [],
530 props.serverConfig?.usageLimitSources ?? [],
531 Date.now(),
532 );
533 onShowUsageLimits(report);
534 if (!report) {
535 Dialog.alert("Usage limits unavailable", "This provider does not currently report limits.");
536 }
537 return report !== null;
538 };
539
540 const mentionableEnvironments = useMentionableEnvironments();
541 // Mentions name any model for the agent, so they aren't limited to models this thread can switch to.
542 const mentionModelOptions = buildModelOptions(
543 props.serverConfig,
544 currentModelSelection,
545 undefined,
546 props.selectedThread.projectId,
547 );
548 const composerMenu = useComposerCommandMenu({
549 draftMessage: draftMessage,
550 ownerKey: composerDraftKey,
551 environmentId: props.environmentId,
552 threadShells: useVisibleThreadShells(),
553 environments: offersLinkedEnvironments(props.serverConfig)
554 ? mentionableEnvironments
555 : NO_MACHINES,
556 linkedEnvironments: useLinkedEnvironments(props.environmentId),
557 currentThreadId: props.selectedThread.id,
558 projectCwd: props.projectCwd,
559 pullRequestProjectId: props.serverConfig ? (project?.id ?? null) : null,
560 pullRequestRepository: project?.repositoryIdentity?.displayName ?? null,
561 threadPullRequests: props.selectedThread.pullRequests,
562 selectedProviderStatus,
563 hasThread: !props.isDraft,
564 hasCompactableConversation: props.hasCompactableConversation,
565 onChangeDraftMessage: props.onChangeDraftMessage,
566 offersUsageLimits: usageLimitsOffered,
567 onUsageLimits:
568 usageLimitsOffered && draftAttachments.length === 0 ? openUsageLimits : undefined,
569 modelOptions: mentionModelOptions,
570 modelProviders: props.serverConfig?.providers,
571 ...(props.onFreshSession === undefined ? {} : { onFreshSession: props.onFreshSession }),
572 offersSideChat: props.offersSideChat === true,
573 });
574 const voiceInput = useVoiceInputController({
575 ownerKey: composerDraftKey,
576 label: props.selectedThread.title || "Untitled thread",
577 readDraftMessage: () => getComposerDraftSnapshot(composerDraftKey).text,
578 subscribeToDraftChanges: (onChange) => appAtomRegistry.subscribe(composerDraftsAtom, onChange),
579 selection: composerMenu.selection,
580 onChangeDraftMessage: (text) => setComposerDraftText(composerDraftKey, text),
581 onChangeSelection: composerMenu.onSelectionChange,
582 });
583 const isSubmissionLocked =
584 props.interactionLocked === true || queuedEdit?.saving === true || voiceInput.blocksSubmission;
585 const voicePresentation = resolveVoiceComposerPresentation(
586 voiceInput.state,
587 voiceInput.elapsedSeconds,
588 );
589 const isVoiceInputPresented = voicePresentation.statusKind === "active";
590 const isExpanded = isFocused || settingsSheetPresentation.keepsComposerExpanded;
591 const { layout, setComposerEditing } = useAdaptiveWorkspaceLayout();
592 const floatingSidebarComposer = useAndroidFloatingTabs() && layout.usesSplitView;
593 const sidebarWorkspaceTabs = useSidebarWorkspaceTabs();
594 const deviceType = useDeviceType();
595 const usesLargeControls = sidebarWorkspaceTabs === "picker" || deviceType === "pad";
596 const surfacePaddingVertical = usesLargeControls ? 9 : floatingSidebarComposer ? 6 : 2;
597 const [compactRowWidth, setCompactRowWidth] = useState(0);
598 const compactAttachmentLimit = compactRowWidth >= 500 ? 3 : 1;
599 const compactEditor = useCompactComposerEditor(bodyText, draftMessage);
600 const showsCompactDictation = isVoiceInputPresented;
601 const isToolbarVisible = isVoiceInputPresented;
602 const hasEditingAttachments =
603 (queuedEdit !== null && queuedEdit.existingAttachments.length > 0) ||
604 stripAttachments.length > 0;
605 const attachmentBlockReason = composerAttachmentUploadBlockReason({
606 environmentId: props.environmentId,
607 attachments: draftAttachments,
608 connected: props.connectionState === "connected",
609 serverConfig: props.serverConfig,
610 states: uploadStates,
611 });
612 const contextImports = useAtomValue(composerContextImportsAtom);
613 const sendBlockedReason =
614 (queuedEdit?.saving === true ? "Saving…" : null) ??
615 props.sendBlockedReason ??
616 (pendingPastedTextAttachmentCount > 0 ? "Attaching pasted text" : null) ??
617 attachmentBlockReason;
618 const canSend =
619 (props.canOperateThread || props.connectionState !== "connected") &&
620 hasContent &&
621 !contextImports[composerDraftKey] &&
622 !isSubmissionLocked &&
623 sendBlockedReason === null &&
624 !modelUnavailable;
625
626 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- clears the workspace layout's composer-editing flag when the composer unmounts
627 useEffect(() => () => setComposerEditing(false), [setComposerEditing]);
628 // A pending sheet presentation or focus restore has no composer left to act on.
629 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- disposes the pending settings sheet presentation and focus restore on unmount
630 useEffect(() => () => disposeSettingsSheetPresentation(), []);
631
632 const onPressPreview = (source: FilePreviewSource) => {
633 wasExpandedBeforePreviewRef.current = isFocused;
634 setPreviewVideo(null);
635 setPreviewFile(
636 (current) =>
637 current ?? {
638 ...source,
639 gallery: filePreviewGallery(source, composerImageGallery(draftAttachments)),
640 },
641 );
642 };
643
644 const closePreview = () => {
645 setPreviewFile(null);
646 setPreviewVideo(null);
647 if (wasExpandedBeforePreviewRef.current) {
648 setTimeout(() => {
649 if (navigation.isFocused()) inputRef.current?.focus();
650 }, 100);
651 }
652 };
653
654 const onPressVideo = (attachment: DraftComposerFileAttachment, sourceIdentifier: string) => {
655 wasExpandedBeforePreviewRef.current = isFocused;
656 setPreviewFile(null);
657 setPreviewVideo((current) => current ?? { type: "local", attachment, sourceIdentifier });
658 };
659
660 const onEditorFocusChange = props.onEditorFocusChange;
661 const handleFocus = () => {
662 setIsFocused(true);
663 settingsSheetPresentation.onEditorFocusChange(true);
664 onEditorFocusChange?.(true);
665 setComposerEditing(true);
666 };
667
668 const handleBlur = () => {
669 setIsFocused(false);
670 settingsSheetPresentation.onEditorFocusChange(false);
671 onEditorFocusChange?.(false);
672 setComposerEditing(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 props.serverConfig,
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 );
1042 }
1043 return;
1044 }
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,
1055 )
1056 }
1057 submitTitle={sendPresentation.label}
1058 alternateSubmitTitle={
1059 sendPresentation.alternate === null
1060 ? sendPresentation.label
1061 : FOLLOW_UP_ACTION_LABEL[sendPresentation.alternate]
1062 }
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
1097 }
1098 >
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 }}
1143 >
1144 <ComposerDictationToolbar
1145 showsDictation={isVoiceInputPresented}
1146 visible={isToolbarVisible}
1147 >
1148 <ComposerToolbarRow
1149 paddingBottom={0}
1150 paddingHorizontal={0}
1151 paddingTop={0}
1152 style={{ gap: 0 }}
1153 >
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 );
1219};