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

ThreadComposer.tsx

821 lines28.5 KB

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