Open History to see the last commit
1import { isLiquidGlassSupported, LiquidGlassView } from "@callstack/liquid-glass";
2import type {
3 EnvironmentId,
4 ModelSelection,
5 OrchestrationThread,
6 ProviderInteractionMode,
7 RuntimeMode,
8 ServerConfig as T3ServerConfig,
9} from "@t3tools/contracts";
10import {
11 detectComposerTrigger,
12 replaceTextRange,
13 serializeComposerMentionPath,
14 type ComposerTrigger,
15} from "@t3tools/shared/composerTrigger";
16import { TextInputWrapper } from "expo-paste-input";
17import type { ReactNode } from "react";
18import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
19import {
20 Image,
21 Pressable,
22 TextInput as RNTextInput,
23 useColorScheme,
24 View,
25 type NativeSyntheticEvent,
26 type TextInputSelectionChangeEventData,
27 type ViewStyle,
28} from "react-native";
29import ImageViewing from "react-native-image-viewing";
30import { useThemeColor } from "../../lib/useThemeColor";
31
32import { AppText as Text } from "../../components/AppText";
33import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
34import {
35 ComposerToolbarButton,
36 ComposerToolbarRow,
37 ComposerToolbarScroller,
38 ComposerToolbarTrigger,
39} from "../../components/ComposerToolbarTrigger";
40import { ControlPill, ControlPillMenu } from "../../components/ControlPill";
41import { ProviderIcon } from "../../components/ProviderIcon";
42import type { DraftComposerImageAttachment } from "../../lib/composerImages";
43import { buildModelOptions, groupByProvider } from "../../lib/modelOptions";
44import type { RemoteClientConnectionState } from "../../lib/connection";
45import { useNativePaste } from "../../lib/useNativePaste";
46import {
47 insertRankedSearchResult,
48 normalizeSearchQuery,
49 scoreQueryMatch,
50} from "@t3tools/shared/searchRanking";
51import {
52 getModelSelectionBooleanOptionValue,
53 getModelSelectionStringOptionValue,
54} from "@t3tools/shared/model";
55import { useComposerPathSearch } from "../../state/use-composer-path-search";
56import { CLAUDE_AGENT_EFFORT_OPTIONS } from "./claudeEffortOptions";
57import { ComposerCommandPopover, type ComposerCommandItem } from "./ComposerCommandPopover";
58
59/**
60 * Height of the collapsed composer (pill + vertical padding, excluding safe-area inset).
61 * Exported so the parent can compute feed overlap / content insets.
62 */
63export const COMPOSER_COLLAPSED_CHROME = 68;
64
65/**
66 * Height of the expanded composer (card + toolbar + vertical padding, excluding safe-area inset).
67 * Used by the parent to compute the larger feed bottom inset when the composer is focused.
68 */
69export const COMPOSER_EXPANDED_CHROME = 174;
70
71/**
72 * Height of the expanded-only toolbar below the text surface.
73 * Used by the feed inset because KeyboardAvoidingLegendList only accounts for
74 * keyboard height; the floating toolbar remains an additional overlay.
75 */
76export const COMPOSER_EXPANDED_TOOLBAR_CHROME = 60;
77
78export interface ThreadComposerProps {
79 readonly draftMessage: string;
80 readonly draftAttachments: ReadonlyArray<DraftComposerImageAttachment>;
81 readonly placeholder: string;
82 readonly bottomInset?: number;
83 readonly connectionState: RemoteClientConnectionState;
84 readonly selectedThread: OrchestrationThread;
85 readonly serverConfig: T3ServerConfig | null;
86 readonly queueCount: number;
87 readonly activeThreadBusy: boolean;
88 readonly environmentId: EnvironmentId;
89 readonly projectCwd: string | null;
90 readonly onChangeDraftMessage: (value: string) => void;
91 readonly onPickDraftImages: () => Promise<void>;
92 readonly onNativePasteImages: (uris: ReadonlyArray<string>) => Promise<void>;
93 readonly onRemoveDraftImage: (imageId: string) => void;
94 readonly onStopThread: () => Promise<void>;
95 readonly onSendMessage: () => void;
96 readonly onUpdateModelSelection: (modelSelection: ModelSelection) => Promise<void>;
97 readonly onUpdateRuntimeMode: (runtimeMode: RuntimeMode) => Promise<void>;
98 readonly onUpdateInteractionMode: (interactionMode: ProviderInteractionMode) => Promise<void>;
99 readonly onExpandedChange?: (expanded: boolean) => void;
100}
101
102/**
103 * The pill / card container — renders as LiquidGlassView on supported
104 * iOS 26+ devices (progressive blur, native morph), opaque View otherwise.
105 */
106function ComposerSurface(props: {
107 readonly children: ReactNode;
108 readonly style: ViewStyle;
109 readonly isDarkMode: boolean;
110}) {
111 if (isLiquidGlassSupported) {
112 return (
113 <LiquidGlassView
114 effect="clear"
115 interactive
116 tintColor={props.isDarkMode ? "rgba(44,44,46,0.5)" : "rgba(255,255,255,0.45)"}
117 colorScheme={props.isDarkMode ? "dark" : "light"}
118 style={props.style}
119 >
120 {props.children}
121 </LiquidGlassView>
122 );
123 }
124
125 return (
126 <View
127 style={[
128 props.style,
129 {
130 backgroundColor: props.isDarkMode ? "rgba(44,44,46,0.96)" : "rgba(255,255,255,0.96)",
131 borderWidth: 1,
132 borderColor: props.isDarkMode ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.06)",
133 },
134 ]}
135 >
136 {props.children}
137 </View>
138 );
139}
140
141function withModelSelectionOption(
142 selection: ModelSelection,
143 id: string,
144 value: string | boolean | undefined,
145): ModelSelection {
146 const options = (selection.options ?? []).filter((option) => option.id !== id);
147 return {
148 ...selection,
149 options: value === undefined ? options : [...options, { id, value }],
150 };
151}
152
153function formatTitleCase(value: string): string {
154 return value.length === 0 ? value : `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
155}
156
157export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposerProps) {
158 const isDarkMode = useColorScheme() === "dark";
159 const themePlaceholderColor = useThemeColor("--color-placeholder");
160 const placeholderColor = isDarkMode ? "#a1a1aa" : themePlaceholderColor;
161 const foregroundColor = useThemeColor("--color-foreground");
162 const inputRef = useRef<RNTextInput>(null);
163 const [isFocused, setIsFocused] = useState(false);
164 const wasExpandedBeforePreviewRef = useRef(false);
165 const { onExpandedChange } = props;
166
167 const [previewImageUri, setPreviewImageUri] = useState<string | null>(null);
168 const hasContent = props.draftMessage.trim().length > 0 || props.draftAttachments.length > 0;
169 const isExpanded = isFocused;
170 const canSend = props.connectionState === "ready" && hasContent;
171
172 const onPressImage = useCallback(
173 (uri: string) => {
174 wasExpandedBeforePreviewRef.current = isFocused;
175 setPreviewImageUri(uri);
176 },
177 [isFocused],
178 );
179
180 const closePreview = useCallback(() => {
181 setPreviewImageUri(null);
182 if (wasExpandedBeforePreviewRef.current) {
183 setTimeout(() => inputRef.current?.focus(), 100);
184 }
185 }, []);
186
187 useEffect(() => {
188 onExpandedChange?.(isExpanded);
189 }, [isExpanded, onExpandedChange]);
190 const showStopAction =
191 props.selectedThread.session?.status === "running" ||
192 props.selectedThread.session?.status === "starting" ||
193 props.queueCount > 0;
194
195 const sendLabel = props.activeThreadBusy || props.queueCount > 0 ? "Queue" : "Send";
196 const currentModelSelection = props.selectedThread.modelSelection;
197 const currentRuntimeMode = props.selectedThread.runtimeMode;
198 const currentInteractionMode = props.selectedThread.interactionMode ?? "default";
199 const toolbarFadeOpaque = isDarkMode ? "rgba(0,0,0,0.95)" : "rgba(255,255,255,0.95)";
200 const toolbarFadeTransparent = isDarkMode ? "rgba(0,0,0,0)" : "rgba(255,255,255,0)";
201 const selectedProviderStatus = useMemo(() => {
202 if (!props.serverConfig) return null;
203 return (
204 props.serverConfig.providers.find(
205 (p) => p.instanceId === props.selectedThread.modelSelection.instanceId,
206 ) ?? null
207 );
208 }, [props.serverConfig, props.selectedThread.modelSelection.instanceId]);
209
210 // Extract current model options (effort, fastMode, contextWindow)
211 const selectedProviderDriver = selectedProviderStatus?.driver ?? null;
212 const currentEffort =
213 selectedProviderDriver === "claudeAgent"
214 ? (getModelSelectionStringOptionValue(currentModelSelection, "effort") ?? "high")
215 : "high";
216 const currentFastMode =
217 getModelSelectionBooleanOptionValue(currentModelSelection, "fastMode") ?? false;
218 const currentContextWindow =
219 selectedProviderDriver === "claudeAgent"
220 ? (getModelSelectionStringOptionValue(currentModelSelection, "contextWindow") ?? "1M")
221 : "1M";
222
223 const handleNativePaste = useNativePaste((uris) => {
224 void props.onNativePasteImages(uris);
225 });
226
227 // ── Trigger detection ────────────────────────────────────
228 const [cursorPosition, setCursorPosition] = useState(0);
229
230 const handleSelectionChange = useCallback(
231 (event: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
232 const { start } = event.nativeEvent.selection;
233 setCursorPosition(start);
234 },
235 [],
236 );
237
238 const composerTrigger = useMemo<ComposerTrigger | null>(
239 () => detectComposerTrigger(props.draftMessage, cursorPosition),
240 [cursorPosition, props.draftMessage],
241 );
242 const pathSearch = useComposerPathSearch({
243 environmentId: props.environmentId,
244 cwd: composerTrigger?.kind === "path" ? props.projectCwd : null,
245 query: composerTrigger?.kind === "path" ? composerTrigger.query : null,
246 });
247
248 const composerMenuItems: ComposerCommandItem[] = useMemo(() => {
249 if (!composerTrigger) return [];
250
251 if (composerTrigger.kind === "slash-command") {
252 const q = composerTrigger.query.toLowerCase();
253 const allBuiltIn = [
254 {
255 id: "cmd:model",
256 type: "slash-command" as const,
257 command: "model",
258 label: "/model",
259 description: "Switch model",
260 },
261 {
262 id: "cmd:plan",
263 type: "slash-command" as const,
264 command: "plan",
265 label: "/plan",
266 description: "Switch to plan mode",
267 },
268 {
269 id: "cmd:default",
270 type: "slash-command" as const,
271 command: "default",
272 label: "/default",
273 description: "Switch to default mode",
274 },
275 ];
276 const builtIn = allBuiltIn.filter((item) => item.command.includes(q));
277
278 const providerCommands: ComposerCommandItem[] = [];
279 for (const cmd of selectedProviderStatus?.slashCommands ?? []) {
280 if (!cmd.name.toLowerCase().includes(q)) continue;
281 providerCommands.push({
282 id: `pcmd:${cmd.name}`,
283 type: "provider-slash-command" as const,
284 command: cmd,
285 label: `/${cmd.name}`,
286 description: cmd.description ?? "",
287 });
288 }
289
290 return [...builtIn, ...providerCommands];
291 }
292
293 if (composerTrigger.kind === "skill") {
294 const enabledSkills = (selectedProviderStatus?.skills ?? []).filter((s) => s.enabled);
295 const normalizedQuery = normalizeSearchQuery(composerTrigger.query, {
296 trimLeadingPattern: /^\$+/,
297 });
298
299 if (!normalizedQuery) {
300 return enabledSkills.slice(0, 20).map((skill) => ({
301 id: `skill:${skill.name}`,
302 type: "skill" as const,
303 skill,
304 label: skill.displayName ?? skill.name,
305 description: skill.shortDescription ?? skill.description ?? "",
306 }));
307 }
308
309 const ranked: Array<{
310 item: (typeof enabledSkills)[number];
311 score: number;
312 tieBreaker: string;
313 }> = [];
314 for (const skill of enabledSkills) {
315 const displayLabel = (skill.displayName ?? skill.name).toLowerCase();
316 const scores = [
317 scoreQueryMatch({
318 value: skill.name.toLowerCase(),
319 query: normalizedQuery,
320 exactBase: 0,
321 prefixBase: 2,
322 boundaryBase: 4,
323 includesBase: 6,
324 fuzzyBase: 100,
325 boundaryMarkers: ["-", "_", "/"],
326 }),
327 scoreQueryMatch({
328 value: displayLabel,
329 query: normalizedQuery,
330 exactBase: 1,
331 prefixBase: 3,
332 boundaryBase: 5,
333 includesBase: 7,
334 fuzzyBase: 110,
335 }),
336 scoreQueryMatch({
337 value: skill.shortDescription?.toLowerCase() ?? "",
338 query: normalizedQuery,
339 exactBase: 20,
340 prefixBase: 22,
341 boundaryBase: 24,
342 includesBase: 26,
343 }),
344 scoreQueryMatch({
345 value: skill.description?.toLowerCase() ?? "",
346 query: normalizedQuery,
347 exactBase: 30,
348 prefixBase: 32,
349 boundaryBase: 34,
350 includesBase: 36,
351 }),
352 ].filter((s): s is number => s !== null);
353
354 if (scores.length > 0) {
355 insertRankedSearchResult(
356 ranked,
357 {
358 item: skill,
359 score: Math.min(...scores),
360 tieBreaker: `${displayLabel}\u0000${skill.name}`,
361 },
362 20,
363 );
364 }
365 }
366
367 return ranked.map(({ item: skill }) => ({
368 id: `skill:${skill.name}`,
369 type: "skill" as const,
370 skill,
371 label: skill.displayName ?? skill.name,
372 description: skill.shortDescription ?? skill.description ?? "",
373 }));
374 }
375
376 if (composerTrigger.kind === "path") {
377 return pathSearch.entries.map((entry) => {
378 const parts = entry.path.split("/");
379 return {
380 id: `path:${entry.path}`,
381 type: "path" as const,
382 path: entry.path,
383 kind: entry.kind,
384 label: parts[parts.length - 1] ?? entry.path,
385 description: parts.length > 1 ? parts.slice(0, -1).join("/") : "",
386 };
387 });
388 }
389
390 return [];
391 }, [composerTrigger, pathSearch.entries, selectedProviderStatus]);
392
393 // ── Handle command selection ──────────────────────────────
394 const { onChangeDraftMessage, onUpdateInteractionMode, draftMessage, onSendMessage } = props;
395
396 const handleSend = useCallback(() => {
397 onSendMessage();
398 inputRef.current?.blur();
399 }, [onSendMessage]);
400 const handleCommandSelect = useCallback(
401 (item: ComposerCommandItem) => {
402 if (!composerTrigger) return;
403
404 if (
405 item.type === "slash-command" &&
406 (item.command === "plan" || item.command === "default")
407 ) {
408 const result = replaceTextRange(
409 draftMessage,
410 composerTrigger.rangeStart,
411 composerTrigger.rangeEnd,
412 "",
413 );
414 setCursorPosition(result.cursor);
415 onChangeDraftMessage(result.text);
416 void onUpdateInteractionMode(item.command);
417 return;
418 }
419
420 let replacement = "";
421 if (item.type === "path") {
422 replacement = `@${serializeComposerMentionPath(item.path)} `;
423 } else if (item.type === "skill") {
424 replacement = `$${item.skill.name} `;
425 } else if (item.type === "slash-command") {
426 replacement = `/${item.command} `;
427 } else if (item.type === "provider-slash-command") {
428 replacement = `/${item.command.name} `;
429 }
430
431 const result = replaceTextRange(
432 draftMessage,
433 composerTrigger.rangeStart,
434 composerTrigger.rangeEnd,
435 replacement,
436 );
437 setCursorPosition(result.cursor);
438 onChangeDraftMessage(result.text);
439 },
440 [composerTrigger, draftMessage, onChangeDraftMessage, onUpdateInteractionMode],
441 );
442
443 // ── Model menu ───────────────────────────────────────────
444 const modelOptions = useMemo(
445 () => buildModelOptions(props.serverConfig, currentModelSelection),
446 [props.serverConfig, currentModelSelection],
447 );
448 const providerGroups = useMemo(() => groupByProvider(modelOptions), [modelOptions]);
449 const currentModelOption =
450 modelOptions.find(
451 (option) =>
452 option.selection.instanceId === currentModelSelection.instanceId &&
453 option.selection.model === currentModelSelection.model,
454 ) ?? null;
455 const configurationLabel = useMemo(() => {
456 const parts = [
457 formatTitleCase(currentEffort),
458 currentFastMode ? "Fast" : null,
459 currentContextWindow !== "1M" ? currentContextWindow : null,
460 ].filter((part): part is string => Boolean(part));
461 return parts.length > 0 ? parts.join(" · ") : "Configuration";
462 }, [currentContextWindow, currentEffort, currentFastMode]);
463 const modelMenuActions = useMemo(
464 () =>
465 providerGroups.map((group) => ({
466 id: `provider:${group.providerKey}`,
467 title: group.providerLabel,
468 subtitle: group.models.find(
469 (model) =>
470 model.selection.instanceId === currentModelSelection.instanceId &&
471 model.selection.model === currentModelSelection.model,
472 )?.label,
473 subactions: group.models.map((option) => ({
474 id: `model:${option.key}`,
475 title: option.label,
476 state:
477 option.selection.instanceId === currentModelSelection.instanceId &&
478 option.selection.model === currentModelSelection.model
479 ? ("on" as const)
480 : undefined,
481 })),
482 })),
483 [providerGroups, currentModelSelection],
484 );
485
486 // ── Options menu ─────────────────────────────────────────
487 const optionsMenuActions = useMemo(
488 () => [
489 {
490 id: "options-effort",
491 title: "Effort",
492 subtitle: `${currentEffort.charAt(0).toUpperCase()}${currentEffort.slice(1)}`,
493 subactions: CLAUDE_AGENT_EFFORT_OPTIONS.map((level) => ({
494 id: `options:effort:${level}`,
495 title: `${level}${level === "high" ? " (default)" : ""}`,
496 state: currentEffort === level ? ("on" as const) : undefined,
497 })),
498 },
499 {
500 id: "options-fast-mode",
501 title: "Fast Mode",
502 subtitle: currentFastMode ? "On" : "Off",
503 subactions: ([false, true] as const).map((value) => ({
504 id: `options:fast-mode:${value ? "on" : "off"}`,
505 title: value ? "On" : "Off",
506 state: currentFastMode === value ? ("on" as const) : undefined,
507 })),
508 },
509 {
510 id: "options-context-window",
511 title: "Context Window",
512 subtitle: currentContextWindow,
513 subactions: (["200k", "1M"] as const).map((value) => ({
514 id: `options:context-window:${value}`,
515 title: `${value}${value === "1M" ? " (default)" : ""}`,
516 state: currentContextWindow === value ? ("on" as const) : undefined,
517 })),
518 },
519 {
520 id: "options-runtime",
521 title: "Runtime",
522 subtitle:
523 currentRuntimeMode === "approval-required"
524 ? "Approve actions"
525 : currentRuntimeMode === "auto-accept-edits"
526 ? "Auto-accept edits"
527 : "Full access",
528 subactions: [
529 { id: "options:runtime:approval-required", title: "Approve actions" },
530 { id: "options:runtime:auto-accept-edits", title: "Auto-accept edits" },
531 { id: "options:runtime:full-access", title: "Full access" },
532 ].map((option) => {
533 const value = option.id.replace("options:runtime:", "");
534 return {
535 id: option.id,
536 title: option.title,
537 state: currentRuntimeMode === value ? ("on" as const) : undefined,
538 };
539 }),
540 },
541 {
542 id: "options-interaction",
543 title: "Interaction",
544 subtitle: currentInteractionMode === "plan" ? "Plan" : "Default",
545 subactions: [
546 { id: "options:interaction:default", title: "Default" },
547 { id: "options:interaction:plan", title: "Plan" },
548 ].map((option) => {
549 const value = option.id.replace("options:interaction:", "");
550 return {
551 id: option.id,
552 title: option.title,
553 state: currentInteractionMode === value ? ("on" as const) : undefined,
554 };
555 }),
556 },
557 ],
558 [
559 currentEffort,
560 currentFastMode,
561 currentContextWindow,
562 currentRuntimeMode,
563 currentInteractionMode,
564 ],
565 );
566
567 // ── Menu handlers ────────────────────────────────────────
568 function handleModelMenuAction(event: string) {
569 if (!event.startsWith("model:")) {
570 return;
571 }
572 const modelKey = event.slice("model:".length);
573 const option = modelOptions.find((o) => o.key === modelKey);
574 if (option) {
575 void props.onUpdateModelSelection(option.selection);
576 }
577 }
578
579 function handleOptionsMenuAction(event: string) {
580 if (event.startsWith("options:effort:")) {
581 const effort = event.slice("options:effort:".length);
582 const updated: ModelSelection =
583 selectedProviderDriver === "claudeAgent"
584 ? withModelSelectionOption(
585 currentModelSelection,
586 "effort",
587 effort as typeof currentEffort,
588 )
589 : currentModelSelection;
590 void props.onUpdateModelSelection(updated);
591 return;
592 }
593 if (event.startsWith("options:fast-mode:")) {
594 const fastMode = event.endsWith(":on");
595 const nextFast = fastMode || undefined;
596 if (selectedProviderDriver === "opencode") {
597 return;
598 }
599 const updated = withModelSelectionOption(currentModelSelection, "fastMode", nextFast);
600 void props.onUpdateModelSelection(updated);
601 return;
602 }
603 if (event.startsWith("options:context-window:")) {
604 const contextWindow = event.slice("options:context-window:".length);
605 const updated: ModelSelection =
606 selectedProviderDriver === "claudeAgent"
607 ? withModelSelectionOption(currentModelSelection, "contextWindow", contextWindow)
608 : currentModelSelection;
609 void props.onUpdateModelSelection(updated);
610 return;
611 }
612 if (event.startsWith("options:runtime:")) {
613 const runtimeMode = event.slice("options:runtime:".length) as RuntimeMode;
614 void props.onUpdateRuntimeMode(runtimeMode);
615 return;
616 }
617 if (event.startsWith("options:interaction:")) {
618 const interactionMode = event.slice("options:interaction:".length) as ProviderInteractionMode;
619 void props.onUpdateInteractionMode(interactionMode);
620 }
621 }
622
623 return (
624 <View
625 style={{
626 paddingHorizontal: 16,
627 paddingTop: isExpanded ? 12 : 10,
628 paddingBottom: (props.bottomInset ?? 0) + (isExpanded ? 4 : 10),
629 experimental_backgroundImage: isDarkMode
630 ? "linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0.85) 40%, rgba(0,0,0,0.95) 100%)"
631 : "linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,0.85) 40%, rgba(255,255,255,0.95) 100%)",
632 }}
633 >
634 <View className="w-full" style={{ position: "relative" }}>
635 {composerTrigger && composerMenuItems.length > 0 ? (
636 <View
637 style={{
638 position: "absolute",
639 bottom: "100%",
640 left: 0,
641 right: 0,
642 marginBottom: 8,
643 zIndex: 10,
644 }}
645 >
646 <ComposerCommandPopover
647 items={composerMenuItems}
648 triggerKind={composerTrigger.kind}
649 isLoading={pathSearch.isPending}
650 onSelect={handleCommandSelect}
651 />
652 </View>
653 ) : null}
654
655 <ComposerSurface
656 isDarkMode={isDarkMode}
657 style={
658 isExpanded
659 ? {
660 borderRadius: 20,
661 overflow: "hidden" as const,
662 paddingHorizontal: 14,
663 paddingVertical: 12,
664 }
665 : {
666 borderRadius: 999,
667 overflow: "hidden" as const,
668 flexDirection: "row" as const,
669 alignItems: "center" as const,
670 paddingLeft: 18,
671 paddingRight: 5,
672 paddingVertical: 5,
673 }
674 }
675 >
676 {/* Attachment strip — inside the card, above the text input */}
677 {isExpanded ? (
678 <View style={{ paddingBottom: props.draftAttachments.length > 0 ? 10 : 0 }}>
679 <ComposerAttachmentStrip
680 attachments={props.draftAttachments}
681 onRemove={props.onRemoveDraftImage}
682 onPressImage={onPressImage}
683 />
684 </View>
685 ) : null}
686
687 <View style={isExpanded ? undefined : { flex: 1, minWidth: 0 }}>
688 <TextInputWrapper onPaste={handleNativePaste}>
689 <RNTextInput
690 ref={inputRef}
691 multiline
692 value={props.draftMessage}
693 onChangeText={props.onChangeDraftMessage}
694 onSelectionChange={handleSelectionChange}
695 placeholder={props.placeholder}
696 placeholderTextColor={placeholderColor}
697 editable={props.connectionState === "ready"}
698 onFocus={() => setIsFocused(true)}
699 onBlur={() => setIsFocused(false)}
700 textAlignVertical={isExpanded ? "top" : "center"}
701 style={
702 isExpanded
703 ? {
704 minHeight: 80,
705 maxHeight: 160,
706 paddingHorizontal: 4,
707 paddingVertical: 4,
708 fontSize: 15,
709 lineHeight: 22,
710 color: foregroundColor,
711 fontFamily: "DMSans_400Regular",
712 }
713 : {
714 maxHeight: 36,
715 paddingVertical: 6,
716 fontSize: 15,
717 lineHeight: 20,
718 color: foregroundColor,
719 fontFamily: "DMSans_400Regular",
720 }
721 }
722 />
723 </TextInputWrapper>
724 </View>
725 {!isExpanded && props.draftAttachments.length > 0 ? (
726 <View style={{ flexDirection: "row", gap: 4, paddingLeft: 4 }}>
727 {props.draftAttachments.slice(0, 3).map((image) => (
728 <Pressable key={image.id} onPress={() => onPressImage(image.previewUri)}>
729 <Image
730 source={{ uri: image.previewUri }}
731 className="bg-subtle"
732 style={{
733 width: 30,
734 height: 30,
735 borderRadius: 8,
736 }}
737 resizeMode="cover"
738 />
739 </Pressable>
740 ))}
741 {props.draftAttachments.length > 3 ? (
742 <View
743 className="bg-subtle-strong"
744 style={{
745 width: 30,
746 height: 30,
747 borderRadius: 8,
748 alignItems: "center",
749 justifyContent: "center",
750 }}
751 >
752 <Text className="text-foreground-muted text-[11px] font-t3-bold">
753 +{props.draftAttachments.length - 3}
754 </Text>
755 </View>
756 ) : null}
757 </View>
758 ) : null}
759 {!isExpanded ? (
760 showStopAction ? (
761 <ControlPill
762 icon="stop.fill"
763 variant="danger"
764 onPress={() => void props.onStopThread()}
765 />
766 ) : (
767 <ControlPill
768 icon="arrow.up"
769 variant="primary"
770 disabled={!canSend}
771 onPress={handleSend}
772 />
773 )
774 ) : null}
775 </ComposerSurface>
776
777 {/* Toolbar row — matches draft page layout (expanded only) */}
778 {isExpanded ? (
779 <ComposerToolbarRow paddingBottom={8} paddingHorizontal={0} paddingTop={8}>
780 <ComposerToolbarScroller
781 fadeOpaque={toolbarFadeOpaque}
782 fadeTransparent={toolbarFadeTransparent}
783 >
784 <ComposerToolbarButton
785 icon="plus"
786 onPress={() => void props.onPickDraftImages()}
787 showChevron={false}
788 />
789 <ControlPillMenu
790 actions={modelMenuActions}
791 onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
792 >
793 <ComposerToolbarTrigger
794 accessibilityLabel="Model"
795 iconNode={
796 <ProviderIcon provider={currentModelOption?.providerDriver} size={16} />
797 }
798 label={currentModelOption?.label ?? currentModelSelection.model}
799 />
800 </ControlPillMenu>
801 <ControlPillMenu
802 actions={optionsMenuActions}
803 onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
804 >
805 <ComposerToolbarTrigger
806 accessibilityLabel="Configuration"
807 icon="slider.horizontal.3"
808 label={configurationLabel}
809 />
810 </ControlPillMenu>
811 {showStopAction ? (
812 <ComposerToolbarButton
813 icon="stop.fill"
814 variant="danger"
815 onPress={() => void props.onStopThread()}
816 showChevron={false}
817 />
818 ) : null}
819 </ComposerToolbarScroller>
820 <ComposerToolbarButton
821 accessibilityLabel={sendLabel}
822 icon="arrow.up"
823 variant="primary"
824 disabled={!canSend}
825 onPress={handleSend}
826 showChevron={false}
827 />
828 </ComposerToolbarRow>
829 ) : null}
830
831 {/* Queue count */}
832 {props.queueCount > 0 ? (
833 <Text
834 className="text-foreground-muted"
835 style={{
836 fontSize: 12,
837 lineHeight: 18,
838 paddingTop: 8,
839 }}
840 >
841 {props.queueCount} queued message{props.queueCount === 1 ? "" : "s"} will send
842 automatically.
843 </Text>
844 ) : null}
845 </View>
846
847 <ImageViewing
848 images={previewImageUri ? [{ uri: previewImageUri }] : []}
849 imageIndex={0}
850 visible={previewImageUri !== null}
851 onRequestClose={closePreview}
852 swipeToCloseEnabled
853 doubleTapToZoomEnabled
854 />
855 </View>
856 );
857});