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