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

ThreadSettingsSheet.tsx

1,372 lines47.2 KB

1import type {
2 EnvironmentId,
3 ModelSelection,
4 ProviderInstanceId,
5 ProviderOptionDescriptor,
6 ProviderOptionSelection,
7 RuntimeMode,
8} from "@t3tools/contracts";
9import type { LegendListRenderItemProps } from "@legendapp/list/react-native";
10import { AnimatedLegendList } from "@legendapp/list/reanimated";
11import { HeaderHeightContext } from "@react-navigation/elements";
12import {
13 getProviderOptionCurrentLabel,
14 getProviderOptionCurrentValue,
15 getProviderOptionDescriptors,
16} from "@t3tools/shared/model";
17import { useNavigation, useRoute, type RouteProp } from "@react-navigation/native";
18import {
19 createNativeStackNavigator,
20 type NativeStackNavigationProp,
21} from "@react-navigation/native-stack";
22import * as Haptics from "expo-haptics";
23import {
24 createContext,
25 use,
26 useCallback,
27 useEffect,
28 useMemo,
29 useState,
30 type ReactNode,
31} from "react";
32import { Alert, Platform, Pressable, ScrollView, TextInput, View } from "react-native";
33import Animated, { FadeIn, FadeOut, LinearTransition } from "react-native-reanimated";
34import { useSafeAreaInsets } from "react-native-safe-area-context";
35​
36import { SymbolView } from "../../components/AppSymbol";
37import { AppText as Text } from "../../components/AppText";
38import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
39import { MaterialButton } from "../../components/MaterialButton";
40import { MaterialIconButton } from "../../components/MaterialIconButton";
41import { MaterialRadioIndicator } from "../../components/MaterialRadioIndicator";
42import { ProviderIcon } from "../../components/ProviderIcon";
43import { ThemedSwitch } from "../../components/ThemedSwitch";
44import { cn } from "../../lib/cn";
45import type { ModelOption, ProviderGroup } from "../../lib/modelOptions";
46import { applyProviderOptionSelection } from "../../lib/providerOptions";
47import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
48import { useUniwindTheme } from "../../lib/useUniwindTheme";
49import {
50 NativeHeaderToolbar,
51 NativeStackScreenOptions,
52 nativeHeaderScrollEdgeEffects,
53} from "../../native/StackHeader";
54import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
55import { serverEnvironment } from "../../state/server";
56import { useAtomCommand } from "../../state/use-atom-command";
57import { useNewTaskFlow } from "./new-task-flow-provider";
58import { MaterialScreenContent } from "../../components/MaterialScreenContent";
59import {
60 createProviderCatalogRefreshRunner,
61 providerCatalogRefreshError,
62} from "./provider-catalog-refresh";
63import {
64 createNativeMailSearchToolbarItem,
65 NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET,
66 NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED,
67} from "../layout/native-mail-search-toolbar";
68import { RUNTIME_MODE_CHOICES, selectableChoices } from "./thread-settings-options";
69import {
70 canCommitPendingModel,
71 modelMatchesCatalogQuery,
72 pendingModelAfterPress,
73 providerSectionIsCollapsed,
74} from "./thread-settings-sheet-state";
75​
76/**
77 * Everyday harnesses start expanded; every other provider (OpenRouter catalogs
78 * and friends) starts folded so a 300-model catalog cannot bury the list. All
79 * provider headers remain user-collapsible.
80 */
81const PRIMARY_PROVIDER_DRIVERS: ReadonlySet<string> = new Set([
82 "claudeAgent",
83 "codex",
84 "antigravity",
85]);
86/**
87 * Keep measured row changes stable, but let catalog mutations use the list's
88 * native bounds so a filtered catalog that underflows returns to the top.
89 */
90const THREAD_SETTINGS_MAINTAIN_VISIBLE_CONTENT_POSITION = {
91 data: false,
92 size: true,
93} as const;
94const THREAD_SETTINGS_CATALOG_LAYOUT_TRANSITION = LinearTransition.duration(180);
95const THREAD_SETTINGS_CATALOG_ENTER_TRANSITION = FadeIn.duration(140);
96const THREAD_SETTINGS_CATALOG_EXIT_TRANSITION = FadeOut.duration(120);
97const THREAD_SETTINGS_OPTIONS_LAYOUT_TRANSITION = LinearTransition.duration(180);
98const THREAD_SETTINGS_OPTION_ENTER_TRANSITION = FadeIn.duration(140);
99const THREAD_SETTINGS_OPTION_EXIT_TRANSITION = FadeOut.duration(100);
100const THREAD_SETTINGS_HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(
101 Platform.OS,
102 Platform.Version,
103);
104function ModelRow(props: {
105 readonly option: ModelOption;
106 readonly selected: boolean;
107 readonly onPress: () => void;
108 readonly isFirst: boolean;
109 readonly isLast: boolean;
110}) {
111 const selectedMaterialRow = Platform.OS === "android" && props.selected;
112 return (
113 <Pressable
114 accessibilityLabel={[props.option.label, props.option.subtitle].filter(Boolean).join(", ")}
115 accessibilityRole="radio"
116 accessibilityState={{
117 checked: props.selected,
118 disabled: props.option.isUnavailable === true,
119 }}
120 disabled={props.option.isUnavailable}
121 onPress={props.onPress}
122 style={Platform.OS === "android" ? { minHeight: 56, paddingVertical: 12 } : undefined}
123 className={cn(
124 "mx-4 min-h-11 flex-row items-center gap-2 bg-card px-4 py-2 active:bg-subtle",
125 selectedMaterialRow && "bg-thread-selected",
126 props.isFirst && "rounded-t-2xl",
127 props.isLast ? "rounded-b-2xl" : "border-b border-border-subtle",
128 )}
129 >
130 {Platform.OS === "android" ? <MaterialRadioIndicator selected={props.selected} /> : null}
131 <View className="min-w-0 flex-1">
132 <View className="flex-row items-center gap-2">
133 <Text
134 className="min-w-0 shrink text-base font-t3-medium text-foreground"
135 numberOfLines={Platform.OS === "android" ? 2 : 1}
136 >
137 {props.option.label}
138 </Text>
139 {props.option.isDefault ? (
140 <View className="rounded-md bg-subtle-strong px-1.5 py-0.5">
141 <Text className="text-3xs font-t3-bold text-foreground-muted">Default</Text>
142 </View>
143 ) : null}
144 {props.option.isLegacy ? (
145 <View className="rounded-md bg-subtle px-1.5 py-0.5">
146 <Text className="text-3xs font-t3-bold text-foreground-muted">Legacy</Text>
147 </View>
148 ) : null}
149 {props.option.isUnavailable ? (
150 <Text className="text-xs text-foreground">Unavailable</Text>
151 ) : null}
152 </View>
153 {props.option.subtitle ? (
154 <Text
155 className="text-xs text-foreground-muted"
156 numberOfLines={Platform.OS === "android" ? 2 : 1}
157 >
158 {props.option.subtitle}
159 </Text>
160 ) : null}
161 </View>
162 {props.selected && Platform.OS !== "android" ? (
163 <SymbolView
164 name="checkmark"
165 size={16}
166 tintColorClassName="accent-icon"
167 type="monochrome"
168 weight="semibold"
169 />
170 ) : null}
171 </Pressable>
172 );
174​
175/** Provider catalog header with its harness logo and disclosure state. */
176function ProviderHeader(props: {
177 readonly driver: string | undefined;
178 readonly label: string;
179 readonly collapsible: boolean;
180 readonly collapsed: boolean;
181 readonly modelCount: number;
182 readonly onToggle: () => void;
183}) {
184 const content = (
185 <>
186 <ProviderIcon provider={props.driver} size={15} />
187 <Text className="text-sm font-t3-medium text-foreground-muted">{props.label}</Text>
188 {props.collapsible ? (
189 <>
190 <View className="flex-1" />
191 {props.collapsed ? (
192 <Text className="text-2xs font-t3-medium text-foreground-muted">
193 {props.modelCount}
194 </Text>
195 ) : null}
196 <SymbolView
197 name={props.collapsed ? "chevron.down" : "chevron.up"}
198 size={12}
199 tintColorClassName="accent-icon-subtle"
200 type="monochrome"
201 />
202 </>
203 ) : null}
204 </>
205 );
206​
207 if (props.collapsible) {
208 return (
209 <Pressable
210 accessibilityLabel={`${props.label}, ${props.modelCount} models`}
211 accessibilityRole="button"
212 accessibilityState={{ expanded: !props.collapsed }}
213 className="mx-4 mt-1 min-h-11 flex-row items-center gap-2 rounded-xl px-1 pt-2 active:opacity-60"
214 onPress={props.onToggle}
215 style={Platform.OS === "android" ? { minHeight: 48 } : undefined}
216 >
217 {content}
218 </Pressable>
219 );
220 }
221​
222 return (
223 <View accessibilityRole="header" className="mx-4 min-h-9 flex-row items-center gap-2 px-1 pt-1">
224 {content}
225 </View>
226 );
228​
229/** Compact row that opens a single-choice submenu panel. */
230function DisclosureRow(props: {
231 readonly label: string;
232 readonly value: string | undefined;
233 readonly onPress: () => void;
234 readonly isLast?: boolean;
235}) {
236 return (
237 <Pressable
238 accessibilityRole="button"
239 onPress={props.onPress}
240 style={Platform.OS === "android" ? { minHeight: 56 } : undefined}
241 className={cn(
242 "min-h-11 flex-row items-center gap-2 bg-card px-4 py-2 active:bg-subtle",
243 !props.isLast && "border-b border-border-subtle",
244 )}
245 >
246 <Text className="text-sm font-t3-medium text-foreground">{props.label}</Text>
247 <View className="flex-1" />
248 {props.value ? (
249 <Text className="text-sm text-foreground-muted" numberOfLines={1}>
250 {props.value}
251 </Text>
252 ) : null}
253 <SymbolView
254 name="chevron.right"
255 size={12}
256 tintColorClassName="accent-icon-subtle"
257 type="monochrome"
258 />
259 </Pressable>
260 );
262​
263/** Single option inside a submenu panel. */
264function ChoiceRow(props: {
265 readonly label: string;
266 readonly description?: string;
267 readonly selected: boolean;
268 readonly onPress: () => void;
269 readonly isLast: boolean;
270}) {
271 return (
272 <Pressable
273 accessibilityLabel={props.description ? `${props.label}. ${props.description}` : props.label}
274 accessibilityRole="radio"
275 accessibilityState={{ checked: props.selected }}
276 onPress={props.onPress}
277 style={Platform.OS === "android" ? { minHeight: 56 } : undefined}
278 className={cn(
279 "min-h-14 flex-row items-center gap-3 bg-card px-4 py-3 active:bg-subtle",
280 !props.isLast && "border-b border-border-subtle",
281 )}
282 >
283 {Platform.OS === "android" ? <MaterialRadioIndicator selected={props.selected} /> : null}
284 <View className="min-w-0 flex-1 gap-0.5">
285 <Text className="text-base font-t3-medium text-foreground">{props.label}</Text>
286 {props.description ? (
287 <Text className="text-sm leading-5 text-foreground-muted">{props.description}</Text>
288 ) : null}
289 </View>
290 {props.selected && Platform.OS !== "android" ? (
291 <SymbolView
292 name="checkmark"
293 size={16}
294 tintColorClassName="accent-icon"
295 type="monochrome"
296 weight="semibold"
297 />
298 ) : null}
299 </Pressable>
300 );
302​
303function SwitchRow(props: {
304 readonly label: string;
305 readonly value: boolean;
306 readonly onValueChange: (value: boolean) => void;
307 readonly isLast?: boolean;
308}) {
309 return (
310 <View
311 className={cn(
312 "min-h-11 flex-row items-center justify-between bg-card px-4 py-1",
313 !props.isLast && "border-b border-border-subtle",
314 )}
315 >
316 <Text className="text-sm font-t3-medium text-foreground">{props.label}</Text>
317 <ThemedSwitch
318 accessibilityLabel={props.label}
319 onValueChange={props.onValueChange}
320 value={props.value}
321 />
322 </View>
323 );
325​
326type ThreadSettingsSubmenuPage =
327 | { readonly kind: "descriptor"; readonly id: string }
328 | { readonly kind: "runtime" };
329​
330type ThreadSettingsSessionProps = {
331 readonly environmentId: EnvironmentId | null;
332 readonly providerInstanceId?: ProviderInstanceId;
333 readonly providerGroups: ReadonlyArray<ProviderGroup>;
334 readonly selectedModel: ModelSelection | null;
335 readonly onSelectModel: (option: ModelOption) => void;
336 readonly optionDescriptors: ReadonlyArray<ProviderOptionDescriptor>;
337 readonly onUpdateOptionSelections: (selections: ReadonlyArray<ProviderOptionSelection>) => void;
338 readonly runtimeMode: RuntimeMode;
339 readonly onUpdateRuntimeMode: (mode: RuntimeMode) => void;
340};
341​
342export type ExistingThreadSettingsRouteSession = ThreadSettingsSessionProps & {
343 readonly ownerId: string;
344};
345​
346type ExistingThreadSettingsRouteContextValue = {
347 readonly session: ExistingThreadSettingsRouteSession | null;
348 readonly present: (session: ExistingThreadSettingsRouteSession) => void;
349 readonly clear: (ownerId: string) => void;
350};
351​
352const ExistingThreadSettingsRouteContext =
353 createContext<ExistingThreadSettingsRouteContextValue | null>(null);
354​
355/** Bridges the active thread's settings state into the root native sheet route. */
356export function ExistingThreadSettingsRouteProvider(props: { readonly children: ReactNode }) {
357 const [session, setSession] = useState<ExistingThreadSettingsRouteSession | null>(null);
358 const present = useCallback((nextSession: ExistingThreadSettingsRouteSession) => {
359 setSession(nextSession);
360 }, []);
361 const clear = useCallback((ownerId: string) => {
362 setSession((current) => (current?.ownerId === ownerId ? null : current));
363 }, []);
364 const value = useMemo(() => ({ session, present, clear }), [clear, present, session]);
365​
366 return (
367 <ExistingThreadSettingsRouteContext.Provider value={value}>
368 {props.children}
369 </ExistingThreadSettingsRouteContext.Provider>
370 );
372​
373export function useExistingThreadSettingsRoutePresentation() {
374 const value = use(ExistingThreadSettingsRouteContext);
375 if (!value) {
376 throw new Error(
377 "useExistingThreadSettingsRoutePresentation must be used inside ExistingThreadSettingsRouteProvider.",
378 );
379 }
380 return value;
382​
383type ThreadSettingsSessionValue = {
384 readonly environmentId: EnvironmentId | null;
385 readonly providerInstanceId?: ProviderInstanceId;
386 readonly providerGroups: ReadonlyArray<ProviderGroup>;
387 readonly runtimeMode: RuntimeMode;
388 readonly onUpdateRuntimeMode: (mode: RuntimeMode) => void;
389 readonly displayedDescriptors: ReadonlyArray<ProviderOptionDescriptor>;
390 readonly providerExpansionOverrides: ReadonlySet<string>;
391 readonly hasLegacyModels: boolean;
392 readonly pendingModel: ModelOption | null;
393 readonly providerFilter: string | null;
394 readonly searchQuery: string;
395 readonly showLegacy: boolean;
396 readonly applyOptionChange: (id: string, value: string | boolean) => void;
397 readonly commitPendingModel: () => boolean;
398 readonly isApplied: (option: ModelOption) => boolean;
399 readonly isDisplayed: (option: ModelOption) => boolean;
400 readonly pressModel: (option: ModelOption) => void;
401 readonly setProviderFilter: (providerKey: string | null) => void;
402 readonly setSearchQuery: (query: string) => void;
403 readonly setShowLegacy: (showLegacy: boolean) => void;
404 readonly toggleProvider: (providerKey: string) => void;
405};
406​
407const ThreadSettingsSessionContext = createContext<ThreadSettingsSessionValue | null>(null);
408​
409/** Owns the staged model and option state for one picker presentation. */
410function ThreadSettingsSessionProvider(
411 props: ThreadSettingsSessionProps & { readonly children: ReactNode },
412) {
413 const [showLegacyToggle, setShowLegacyToggle] = useState(false);
414 const [providerFilter, setProviderFilter] = useState<string | null>(null);
415 const [searchQuery, setSearchQuery] = useState("");
416 const [providerExpansionOverrides, setProviderExpansionOverrides] = useState<ReadonlySet<string>>(
417 () => new Set(),
418 );
419 const [pendingModel, setPendingModel] = useState<ModelOption | null>(null);
420​
421 const isApplied = useCallback(
422 (option: ModelOption) =>
423 option.selection.instanceId === props.selectedModel?.instanceId &&
424 option.selection.model === props.selectedModel.model,
425 [props.selectedModel],
426 );
427 // The list highlights the staged pick; Save turns it into the applied one.
428 const isDisplayed = useCallback(
429 (option: ModelOption) => (pendingModel ? option.key === pendingModel.key : isApplied(option)),
430 [isApplied, pendingModel],
431 );
432​
433 // While a model is staged, the settings rows describe and edit the staged
434 // model's options (kept on its pending selection); Save applies model and
435 // options together. Otherwise they edit the applied selection directly.
436 const displayedDescriptors = useMemo(
437 () =>
438 pendingModel
439 ? pendingModel.capabilities
440 ? getProviderOptionDescriptors({
441 caps: pendingModel.capabilities,
442 selections: pendingModel.selection.options,
443 })
444 : []
445 : props.optionDescriptors,
446 [pendingModel, props.optionDescriptors],
447 );
448​
449 const hasLegacyModels = useMemo(
450 () => props.providerGroups.some((group) => group.models.some((model) => model.isLegacy)),
451 [props.providerGroups],
452 );
453 const commitPendingModel = useCallback(() => {
454 if (pendingModel) {
455 if (!canCommitPendingModel(pendingModel, props.providerGroups)) {
456 Alert.alert(
457 "Model unavailable",
458 "Set up this provider on web or desktop, or select another model.",
459 );
460 return false;
461 }
462 void Haptics.selectionAsync();
463 props.onSelectModel(pendingModel);
464 }
465 return true;
466 }, [pendingModel, props.onSelectModel, props.providerGroups]);
467​
468 const applyOptionChange = useCallback(
469 (id: string, value: string | boolean) => {
470 const next = applyProviderOptionSelection(displayedDescriptors, { id, value });
471 if (!next) {
472 return;
473 }
474 if (pendingModel) {
475 setPendingModel({
476 ...pendingModel,
477 selection: { ...pendingModel.selection, options: next },
478 });
479 } else {
480 props.onUpdateOptionSelections(next);
481 }
482 },
483 [displayedDescriptors, pendingModel, props.onUpdateOptionSelections],
484 );
485​
486 const toggleProvider = useCallback((providerKey: string) => {
487 setProviderExpansionOverrides((current) => {
488 const next = new Set(current);
489 if (!next.delete(providerKey)) {
490 next.add(providerKey);
491 }
492 return next;
493 });
494 }, []);
495​
496 const pressModel = useCallback(
497 (option: ModelOption) => {
498 void Haptics.selectionAsync();
499 setPendingModel((current) =>
500 pendingModelAfterPress({
501 current,
502 pressed: option,
503 pressedIsApplied: isApplied(option),
504 }),
505 );
506 },
507 [isApplied],
508 );
509​
510 const value = useMemo<ThreadSettingsSessionValue>(
511 () => ({
512 environmentId: props.environmentId,
513 providerInstanceId: props.providerInstanceId,
514 providerGroups: props.providerGroups,
515 runtimeMode: props.runtimeMode,
516 onUpdateRuntimeMode: props.onUpdateRuntimeMode,
517 displayedDescriptors,
518 providerExpansionOverrides,
519 hasLegacyModels,
520 pendingModel,
521 providerFilter,
522 searchQuery,
523 showLegacy: showLegacyToggle,
524 applyOptionChange,
525 commitPendingModel,
526 isApplied,
527 isDisplayed,
528 pressModel,
529 setProviderFilter,
530 setSearchQuery,
531 setShowLegacy: setShowLegacyToggle,
532 toggleProvider,
533 }),
534 [
535 applyOptionChange,
536 commitPendingModel,
537 displayedDescriptors,
538 providerExpansionOverrides,
539 hasLegacyModels,
540 isApplied,
541 isDisplayed,
542 props.environmentId,
543 props.providerInstanceId,
544 pendingModel,
545 pressModel,
546 providerFilter,
547 props.onUpdateRuntimeMode,
548 props.providerGroups,
549 props.runtimeMode,
550 searchQuery,
551 showLegacyToggle,
552 toggleProvider,
553 ],
554 );
555​
556 return (
557 <ThreadSettingsSessionContext.Provider value={value}>
558 {props.children}
559 </ThreadSettingsSessionContext.Provider>
560 );
562​
563function useThreadSettingsSession() {
564 const value = use(ThreadSettingsSessionContext);
565 if (!value) {
566 throw new Error("useThreadSettingsSession must be used inside ThreadSettingsSessionProvider.");
567 }
568 return value;
570​
571type ThreadSettingsProviderCatalog = {
572 readonly key: string;
573 readonly driver: string | undefined;
574 readonly label: string;
575 readonly collapsible: boolean;
576 readonly collapsed: boolean;
577 readonly modelCount: number;
578 readonly models: ReadonlyArray<ModelOption>;
579};
580​
581type ThreadSettingsCatalogItem =
582 | {
583 readonly kind: "provider";
584 readonly key: string;
585 readonly provider: ThreadSettingsProviderCatalog;
586 }
587 | {
588 readonly kind: "model";
589 readonly key: string;
590 readonly option: ModelOption;
591 readonly isFirst: boolean;
592 readonly isLast: boolean;
593 }
594 | {
595 readonly kind: "empty";
596 readonly key: "empty";
597 }
598 | {
599 readonly kind: "options";
600 readonly key: "options";
601 };
602​
603function ThreadSettingsModelListRow(props: {
604 readonly option: ModelOption;
605 readonly isFirst: boolean;
606 readonly isLast: boolean;
607}) {
608 const session = useThreadSettingsSession();
609 const onPress = useCallback(
610 () => session.pressModel(props.option),
611 [props.option, session.pressModel],
612 );
613​
614 return (
615 <ModelRow
616 isFirst={props.isFirst}
617 isLast={props.isLast}
618 onPress={onPress}
619 option={props.option}
620 selected={session.isDisplayed(props.option)}
621 />
622 );
624​
625function ThreadSettingsProviderListHeader(props: {
626 readonly provider: ThreadSettingsProviderCatalog;
627}) {
628 const session = useThreadSettingsSession();
629 const onToggle = useCallback(
630 () => session.toggleProvider(props.provider.key),
631 [props.provider.key, session.toggleProvider],
632 );
633​
634 return (
635 <ProviderHeader
636 collapsible={props.provider.collapsible}
637 collapsed={props.provider.collapsed}
638 driver={props.provider.driver}
639 label={props.provider.label}
640 modelCount={props.provider.modelCount}
641 onToggle={onToggle}
642 />
643 );
645​
646function useThreadSettingsCatalogItems(
647 session: ThreadSettingsSessionValue,
648): ReadonlyArray<ThreadSettingsCatalogItem> {
649 return useMemo(
650 () =>
651 session.providerGroups.flatMap((group) => {
652 if (session.providerFilter !== null && group.providerKey !== session.providerFilter) {
653 return [];
654 }
655 const driver = group.models[0]?.providerDriver ?? group.providerKey;
656 const catalogModels = session.showLegacy
657 ? group.models
658 : group.models.filter((model) => !model.isLegacy || session.isDisplayed(model));
659 const visibleModels = catalogModels.filter((model) =>
660 modelMatchesCatalogQuery({
661 model,
662 providerLabel: group.providerLabel,
663 query: session.searchQuery,
664 }),
665 );
666 if (visibleModels.length === 0) {
667 return [];
668 }
669 const isPrimary = driver !== undefined && PRIMARY_PROVIDER_DRIVERS.has(driver);
670 // Staging a model must not change disclosure state. The applied model
671 // stays stable for the lifetime of this picker (Save closes it), so it
672 // is safe to use as the initial selected-provider default.
673 const containsAppliedSelection = group.models.some(session.isApplied);
674 const isNarrowed = session.providerFilter !== null || session.searchQuery.trim().length > 0;
675 const collapsible = !isNarrowed;
676 const collapsed = providerSectionIsCollapsed({
677 defaultExpanded: isPrimary || containsAppliedSelection,
678 hasExpansionOverride: session.providerExpansionOverrides.has(group.providerKey),
679 isNarrowed,
680 });
681 const provider: ThreadSettingsProviderCatalog = {
682 key: group.providerKey,
683 driver,
684 label: group.providerLabel,
685 collapsible,
686 collapsed,
687 modelCount: visibleModels.length,
688 models: collapsed ? [] : visibleModels,
689 };
690 return [
691 {
692 kind: "provider" as const,
693 key: `provider:${group.providerKey}`,
694 provider,
695 },
696 ...provider.models.map((option, index) => ({
697 kind: "model" as const,
698 key: `model:${option.key}`,
699 option,
700 isFirst: index === 0,
701 isLast: index === provider.models.length - 1,
702 })),
703 ];
704 }),
705 [
706 session.isApplied,
707 session.isDisplayed,
708 session.providerExpansionOverrides,
709 session.providerFilter,
710 session.providerGroups,
711 session.searchQuery,
712 session.showLegacy,
713 ],
714 );
716​
717function ThreadSettingsOptionsItem(props: {
718 readonly animationsReady: boolean;
719 readonly onOpenSubmenu: (submenu: ThreadSettingsSubmenuPage) => void;
720}) {
721 const insets = useSafeAreaInsets();
722 const session = useThreadSettingsSession();
723 const bottomToolbarInset =
724 Platform.OS === "ios" && NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED
725 ? NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET
726 : 0;
727​
728 return (
729 <View style={{ paddingBottom: insets.bottom + bottomToolbarInset + 12 }}>
730 <Text className="px-5 pb-2 pt-2 text-sm font-t3-medium text-foreground-muted">Options</Text>
731 <Animated.View
732 className="mx-4 overflow-hidden rounded-2xl bg-card"
733 layout={THREAD_SETTINGS_OPTIONS_LAYOUT_TRANSITION}
734 >
735 {session.displayedDescriptors.map((descriptor) => {
736 if (descriptor.type === "select") {
737 return (
738 <Animated.View
739 key={descriptor.id}
740 entering={
741 props.animationsReady ? THREAD_SETTINGS_OPTION_ENTER_TRANSITION : undefined
742 }
743 exiting={props.animationsReady ? THREAD_SETTINGS_OPTION_EXIT_TRANSITION : undefined}
744 layout={THREAD_SETTINGS_OPTIONS_LAYOUT_TRANSITION}
745 >
746 <DisclosureRow
747 label={descriptor.label}
748 value={getProviderOptionCurrentLabel(descriptor)}
749 onPress={() => props.onOpenSubmenu({ kind: "descriptor", id: descriptor.id })}
750 />
751 </Animated.View>
752 );
753 }
754 return (
755 <Animated.View
756 key={descriptor.id}
757 entering={props.animationsReady ? THREAD_SETTINGS_OPTION_ENTER_TRANSITION : undefined}
758 exiting={props.animationsReady ? THREAD_SETTINGS_OPTION_EXIT_TRANSITION : undefined}
759 layout={THREAD_SETTINGS_OPTIONS_LAYOUT_TRANSITION}
760 >
761 <SwitchRow
762 label={descriptor.label}
763 value={descriptor.currentValue ?? false}
764 onValueChange={(value) => session.applyOptionChange(descriptor.id, value)}
765 />
766 </Animated.View>
767 );
768 })}
769 <Animated.View layout={THREAD_SETTINGS_OPTIONS_LAYOUT_TRANSITION}>
770 <DisclosureRow
771 isLast
772 label="Runtime"
773 value={
774 RUNTIME_MODE_CHOICES.find((choice) => choice.mode === session.runtimeMode)?.label
775 }
776 onPress={() => props.onOpenSubmenu({ kind: "runtime" })}
777 />
778 </Animated.View>
779 </Animated.View>
780​
781 {Platform.OS !== "ios" && session.hasLegacyModels ? (
782 <>
783 <Text className="px-5 pb-2 pt-7 text-sm font-t3-medium text-foreground-muted">
784 Catalog
785 </Text>
786 <View className="mx-4 overflow-hidden rounded-2xl bg-card">
787 <SwitchRow
788 isLast
789 label="Legacy models"
790 onValueChange={session.setShowLegacy}
791 value={session.showLegacy}
792 />
793 </View>
794 </>
795 ) : null}
796 </View>
797 );
799​
800/** One native scroll owner for the model catalog and its related settings. */
801function ThreadSettingsMainContent(props: {
802 readonly onOpenSubmenu: (submenu: ThreadSettingsSubmenuPage) => void;
803}) {
804 const session = useThreadSettingsSession();
805 const catalogItems = useThreadSettingsCatalogItems(session);
806 const [animationsReady, setAnimationsReady] = useState(false);
807 const nativeHeaderHeight = use(HeaderHeightContext) ?? 0;
808 const hasActiveCatalogFilter =
809 session.providerFilter !== null || session.searchQuery.trim().length > 0;
810 const usesTransparentNativeHeader = Platform.OS === "ios" && NATIVE_LIQUID_GLASS_SUPPORTED;
811 const listItems = useMemo<ReadonlyArray<ThreadSettingsCatalogItem>>(
812 () => [
813 ...(catalogItems.length === 0 ? ([{ kind: "empty", key: "empty" }] as const) : catalogItems),
814 { kind: "options", key: "options" },
815 ],
816 [catalogItems],
817 );
818 const renderCatalogItem = useCallback(
819 (itemProps: LegendListRenderItemProps<ThreadSettingsCatalogItem>) => {
820 const item = itemProps.item;
821 let content: ReactNode;
822​
823 if (item.kind === "provider") {
824 content = <ThreadSettingsProviderListHeader provider={item.provider} />;
825 } else if (item.kind === "model") {
826 content = (
827 <ThreadSettingsModelListRow
828 isFirst={item.isFirst}
829 isLast={item.isLast}
830 option={item.option}
831 />
832 );
833 } else if (item.kind === "empty") {
834 content = (
835 <View className="items-center px-8 py-14">
836 <Text className="text-center text-sm text-foreground-muted">
837 {hasActiveCatalogFilter ? "No matching models" : "No available models"}
838 </Text>
839 </View>
840 );
841 } else {
842 content = (
843 <ThreadSettingsOptionsItem
844 animationsReady={animationsReady}
845 onOpenSubmenu={props.onOpenSubmenu}
846 />
847 );
848 }
849​
850 return (
851 <Animated.View
852 key={item.key}
853 entering={animationsReady ? THREAD_SETTINGS_CATALOG_ENTER_TRANSITION : undefined}
854 exiting={animationsReady ? THREAD_SETTINGS_CATALOG_EXIT_TRANSITION : undefined}
855 >
856 {content}
857 </Animated.View>
858 );
859 },
860 [animationsReady, hasActiveCatalogFilter, props.onOpenSubmenu],
861 );
862​
863 return (
864 <AnimatedLegendList
865 automaticallyAdjustsScrollIndicatorInsets
866 className="flex-1 bg-sheet"
867 style={
868 Platform.OS === "android"
869 ? { width: "100%", maxWidth: 720, alignSelf: "center" }
870 : undefined
871 }
872 contentContainerStyle={{ paddingTop: 4 }}
873 contentInsetAdjustmentBehavior={usesTransparentNativeHeader ? "never" : "automatic"}
874 data={listItems}
875 estimatedItemSize={Platform.OS === "android" ? 56 : 48}
876 extraData={animationsReady}
877 getItemType={(item) => item.kind}
878 itemLayoutAnimation={THREAD_SETTINGS_CATALOG_LAYOUT_TRANSITION}
879 keyExtractor={(item) => item.key}
880 keyboardDismissMode="on-drag"
881 keyboardShouldPersistTaps="handled"
882 maintainVisibleContentPosition={THREAD_SETTINGS_MAINTAIN_VISIBLE_CONTENT_POSITION}
883 ListHeaderComponent={
884 <>
885 {usesTransparentNativeHeader ? <View style={{ height: nativeHeaderHeight }} /> : null}
886 {Platform.OS === "android" ? (
887 <View className="px-4 pb-2 pt-3">
888 <View
889 className="flex-row items-center rounded-full bg-input px-2"
890 style={{ minHeight: 56 }}
891 >
892 <View pointerEvents="none" className="px-2">
893 <SymbolView
894 name="magnifyingglass"
895 size={24}
896 tintColorClassName="accent-icon-subtle"
897 />
898 </View>
899 <TextInput
900 accessibilityLabel="Find a model"
901 autoCapitalize="none"
902 autoCorrect={false}
903 className="min-w-0 flex-1 px-2 py-0 text-base text-foreground"
904 style={{ minHeight: 56, includeFontPadding: false, textAlignVertical: "center" }}
905 onChangeText={session.setSearchQuery}
906 placeholder="Find a model"
907 placeholderTextColorClassName="accent-placeholder"
908 selectionColorClassName="accent-primary/32"
909 cursorColorClassName="accent-primary"
910 selectionHandleColorClassName="accent-primary"
911 value={session.searchQuery}
912 />
913 {session.searchQuery.length > 0 ? (
914 <MaterialIconButton
915 accessibilityLabel="Clear model search"
916 icon="xmark"
917 onPress={() => session.setSearchQuery("")}
918 />
919 ) : null}
920 </View>
921 </View>
922 ) : null}
923 </>
924 }
925 recycleItems
926 onLoad={() => setAnimationsReady(true)}
927 renderItem={renderCatalogItem}
928 showsVerticalScrollIndicator={false}
929 />
930 );
932​
933/** Compact choice page pushed by the picker navigator. */
934function ThreadSettingsChoiceContent(props: {
935 readonly submenu: ThreadSettingsSubmenuPage;
936 readonly onSelected: () => void;
937}) {
938 const insets = useSafeAreaInsets();
939 const session = useThreadSettingsSession();
940 const descriptorId = props.submenu.kind === "descriptor" ? props.submenu.id : null;
941​
942 const activeDescriptor =
943 descriptorId !== null
944 ? session.displayedDescriptors.find(
945 (descriptor) => descriptor.type === "select" && descriptor.id === descriptorId,
946 )
947 : undefined;
948​
949 const submenuContent =
950 props.submenu.kind === "runtime"
951 ? {
952 rows: RUNTIME_MODE_CHOICES.map((choice) => ({
953 id: choice.mode,
954 label: choice.label,
955 description: choice.description,
956 selected: choice.mode === session.runtimeMode,
957 onPress: () => {
958 void Haptics.selectionAsync();
959 session.onUpdateRuntimeMode(choice.mode);
960 props.onSelected();
961 },
962 })),
963 }
964 : activeDescriptor?.type === "select"
965 ? {
966 rows: selectableChoices(activeDescriptor).map((choice) => ({
967 id: choice.id,
968 label: choice.label,
969 description: undefined,
970 selected: choice.id === getProviderOptionCurrentValue(activeDescriptor),
971 onPress: () => {
972 void Haptics.selectionAsync();
973 session.applyOptionChange(activeDescriptor.id, choice.id);
974 props.onSelected();
975 },
976 })),
977 }
978 : null;
979​
980 if (!submenuContent) {
981 return <View className="flex-1 bg-sheet" />;
982 }
983​
984 return (
985 <ScrollView
986 className="flex-1 bg-sheet"
987 style={
988 Platform.OS === "android"
989 ? { width: "100%", maxWidth: 720, alignSelf: "center" }
990 : undefined
991 }
992 contentContainerStyle={{
993 paddingBottom: insets.bottom + 12,
994 paddingHorizontal: 16,
995 paddingTop: 16,
996 }}
997 contentInsetAdjustmentBehavior="automatic"
998 showsVerticalScrollIndicator={false}
999 >
1000 <View className="overflow-hidden rounded-2xl bg-card">
1001 {submenuContent.rows.map((row, index) => (
1002 <ChoiceRow
1003 key={row.id}
1004 description={row.description}
1005 isLast={index === submenuContent.rows.length - 1}
1006 label={row.label}
1007 selected={row.selected}
1008 onPress={row.onPress}
1009 />
1010 ))}
1011 </View>
1012 </ScrollView>
1013 );
1015​
1016type ThreadSettingsPickerStackParams = {
1017 ThreadSettingsModels: undefined;
1018 ThreadSettingsChoice: ThreadSettingsSubmenuPage & { readonly title: string };
1020​
1021type ThreadSettingsPickerPresentation = {
1022 readonly onClose: () => void;
1024​
1025const ThreadSettingsPickerStack = createNativeStackNavigator<ThreadSettingsPickerStackParams>();
1026const ThreadSettingsPickerPresentationContext =
1027 createContext<ThreadSettingsPickerPresentation | null>(null);
1028​
1029function useThreadSettingsPickerPresentation() {
1030 const value = use(ThreadSettingsPickerPresentationContext);
1031 if (!value) {
1032 throw new Error(
1033 "useThreadSettingsPickerPresentation must be used inside ThreadSettingsPickerNavigator.",
1034 );
1036 return value;
1038​
1039function ThreadSettingsModelsScreen() {
1040 const session = useThreadSettingsSession();
1041 const presentation = useThreadSettingsPickerPresentation();
1042 const navigation = useNavigation<NativeStackNavigationProp<ThreadSettingsPickerStackParams>>();
1043 const usesNativeMailSearchToolbar = Platform.OS === "ios" && NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED;
1044 const hasCustomCatalogFilter = session.providerFilter !== null || session.showLegacy;
1045 const refreshProvidersCommand = useAtomCommand(serverEnvironment.refreshProviders, {
1046 reportFailure: false,
1047 });
1048 const refreshProviderCatalog = useMemo(
1049 () => createProviderCatalogRefreshRunner(refreshProvidersCommand),
1050 [refreshProvidersCommand],
1051 );
1052 const [isRefreshingProviders, setIsRefreshingProviders] = useState(false);
1053 const refreshProviders = useCallback(() => {
1054 if (!session.environmentId || isRefreshingProviders) return;
1055 setIsRefreshingProviders(true);
1056 void refreshProviderCatalog(session.environmentId).then((result) => {
1057 setIsRefreshingProviders(false);
1058 const error = providerCatalogRefreshError(result);
1059 if (error) Alert.alert("Could not refresh models", error);
1060 });
1061 }, [isRefreshingProviders, refreshProviderCatalog, session.environmentId]);
1062 const commitAndClose = useCallback(() => {
1063 if (!session.commitPendingModel()) return;
1064 presentation.onClose();
1065 }, [presentation, session]);
1066 const filterMenu = useMemo(
1067 () => ({
1068 title: "Model filters",
1069 items: [
1071 type: "submenu" as const,
1072 title: "Provider",
1073 items: [
1075 type: "action" as const,
1076 title: "All providers",
1077 state: session.providerFilter === null ? ("on" as const) : ("off" as const),
1078 onPress: () => session.setProviderFilter(null),
1079 },
1080 ...session.providerGroups.map((group) => ({
1081 type: "action" as const,
1082 title: group.providerLabel,
1083 state:
1084 session.providerFilter === group.providerKey ? ("on" as const) : ("off" as const),
1085 onPress: () => session.setProviderFilter(group.providerKey),
1086 })),
1087 ],
1088 },
1089 ...(session.hasLegacyModels
1090 ? [
1092 type: "action" as const,
1093 title: "Show legacy models",
1094 state: session.showLegacy ? ("on" as const) : ("off" as const),
1095 onPress: () => session.setShowLegacy(!session.showLegacy),
1096 },
1098 : []),
1099 ],
1100 }),
1101 [session],
1102 );
1103​
1104 return (
1105 <>
1106 {Platform.OS === "android" ? (
1107 <AndroidScreenHeader
1108 actions={[
1110 accessibilityLabel: "Refresh models",
1111 disabled: isRefreshingProviders || session.environmentId === null,
1112 icon: "arrow.clockwise",
1113 onPress: refreshProviders,
1114 },
1115 ]}
1116 trailing={
1117 session.pendingModel ? (
1118 <MaterialButton label="Save" tone="text" onPress={commitAndClose} />
1119 ) : undefined
1121 onBack={presentation.onClose}
1122 title="Thread settings"
1123 hideBottomBorder
1124 />
1125 ) : null}
1126 <NativeStackScreenOptions
1127 optionsVersion={[
1128 session.providerFilter,
1129 session.providerGroups.map((group) => group.providerKey),
1130 session.showLegacy,
1131 ]}
1132 options={{
1133 unstable_headerToolbarItems: usesNativeMailSearchToolbar
1134 ? () => [
1135 createNativeMailSearchToolbarItem({
1136 filterButtonId: "thread-settings-model-filter",
1137 filterMenu,
1138 filterSystemImageName: hasCustomCatalogFilter
1139 ? "line.3.horizontal.decrease.circle.fill"
1140 : "line.3.horizontal.decrease",
1141 onSearchTextChange: session.setSearchQuery,
1142 placeholder: "Find a model",
1143 searchTextChangeId: "thread-settings-model-search-text",
1144 showsSearchDismissButton: true,
1145 }),
1147 : undefined,
1148 headerShown: Platform.OS !== "android",
1149 headerSearchBarOptions:
1150 Platform.OS === "ios" && !usesNativeMailSearchToolbar
1151 ? {
1152 autoCapitalize: "none",
1153 hideNavigationBar: false,
1154 obscureBackground: false,
1155 onCancelButtonPress: () => session.setSearchQuery(""),
1156 onChangeText: (event) => session.setSearchQuery(event.nativeEvent.text),
1157 placeholder: "Find a model",
1159 : undefined,
1160 }}
1161 />
1162 <MaterialScreenContent>
1163 <ThreadSettingsMainContent
1164 onOpenSubmenu={(submenu) => {
1165 const title =
1166 submenu.kind === "runtime"
1167 ? "Runtime"
1168 : (session.displayedDescriptors.find(
1169 (descriptor) => descriptor.type === "select" && descriptor.id === submenu.id,
1170 )?.label ?? "Option");
1171 navigation.navigate("ThreadSettingsChoice", { ...submenu, title });
1172 }}
1173 />
1174 </MaterialScreenContent>
1175 <NativeHeaderToolbar placement="left">
1176 <NativeHeaderToolbar.Button
1177 accessibilityLabel="Cancel thread settings"
1178 label="Cancel"
1179 onPress={presentation.onClose}
1180 />
1181 </NativeHeaderToolbar>
1182 <NativeHeaderToolbar placement="right">
1183 <NativeHeaderToolbar.Button
1184 accessibilityLabel="Refresh models"
1185 disabled={isRefreshingProviders || session.environmentId === null}
1186 icon="arrow.clockwise"
1187 onPress={refreshProviders}
1188 separateBackground
1189 />
1190 <NativeHeaderToolbar.Button
1191 accessibilityLabel={session.pendingModel ? "Save thread settings" : "Done"}
1192 label={session.pendingModel ? "Save" : "Done"}
1193 onPress={commitAndClose}
1194 />
1195 </NativeHeaderToolbar>
1196 {Platform.OS === "ios" && !usesNativeMailSearchToolbar ? (
1197 <NativeHeaderToolbar placement="bottom">
1198 <NativeHeaderToolbar.Menu
1199 accessibilityLabel="Filter models"
1200 icon={
1201 hasCustomCatalogFilter
1202 ? "line.3.horizontal.decrease.circle.fill"
1203 : "line.3.horizontal.decrease.circle"
1205 separateBackground
1206 title="Model filters"
1208 <NativeHeaderToolbar.Menu title="Provider">
1209 <NativeHeaderToolbar.Label>Provider</NativeHeaderToolbar.Label>
1210 <NativeHeaderToolbar.MenuAction
1211 isOn={session.providerFilter === null}
1212 onPress={() => session.setProviderFilter(null)}
1214 All providers
1215 </NativeHeaderToolbar.MenuAction>
1216 {session.providerGroups.map((group) => (
1217 <NativeHeaderToolbar.MenuAction
1218 key={group.providerKey}
1219 isOn={session.providerFilter === group.providerKey}
1220 onPress={() => session.setProviderFilter(group.providerKey)}
1222 {group.providerLabel}
1223 </NativeHeaderToolbar.MenuAction>
1224 ))}
1225 </NativeHeaderToolbar.Menu>
1226 {session.hasLegacyModels ? (
1227 <NativeHeaderToolbar.MenuAction
1228 isOn={session.showLegacy}
1229 onPress={() => session.setShowLegacy(!session.showLegacy)}
1231 Show legacy models
1232 </NativeHeaderToolbar.MenuAction>
1233 ) : null}
1234 </NativeHeaderToolbar.Menu>
1235 </NativeHeaderToolbar>
1236 ) : null}
1237 </>
1238 );
1240​
1241function ThreadSettingsChoiceScreen() {
1242 const navigation = useNavigation<NativeStackNavigationProp<ThreadSettingsPickerStackParams>>();
1243 const route = useRoute<RouteProp<ThreadSettingsPickerStackParams, "ThreadSettingsChoice">>();
1244​
1245 return (
1246 <>
1247 <NativeStackScreenOptions options={{ headerShown: Platform.OS !== "android" }} />
1248 {Platform.OS === "android" ? (
1249 <AndroidScreenHeader
1250 title={route.params.title}
1251 onBack={() => navigation.goBack()}
1252 hideBottomBorder
1253 />
1254 ) : null}
1255 <MaterialScreenContent>
1256 <ThreadSettingsChoiceContent
1257 submenu={route.params}
1258 onSelected={() => navigation.goBack()}
1259 />
1260 </MaterialScreenContent>
1261 </>
1262 );
1264​
1265function ThreadSettingsPickerNavigator(props: ThreadSettingsPickerPresentation) {
1266 const theme = useUniwindTheme();
1267 const solidSheetBackground = theme["--color-sheet-solid"];
1268 const foreground = theme["--color-foreground"];
1269 const presentation = useMemo(
1270 () => ({
1271 onClose: props.onClose,
1272 }),
1273 [props.onClose],
1274 );
1275​
1276 return (
1277 <ThreadSettingsPickerPresentationContext.Provider value={presentation}>
1278 <ThreadSettingsPickerStack.Navigator
1279 initialRouteName="ThreadSettingsModels"
1280 screenOptions={{
1281 animation: Platform.OS === "android" ? "default" : "slide_from_right",
1282 contentStyle: { backgroundColor: solidSheetBackground },
1283 gestureEnabled: true,
1284 headerBackButtonDisplayMode: "minimal",
1285 headerBackTitle: "",
1286 headerShown: Platform.OS !== "android",
1287 headerShadowVisible: false,
1288 headerStyle: {
1289 backgroundColor: NATIVE_LIQUID_GLASS_SUPPORTED ? "transparent" : solidSheetBackground,
1290 },
1291 headerTransparent: NATIVE_LIQUID_GLASS_SUPPORTED,
1292 headerTintColor: foreground,
1293 headerTitleStyle: { fontSize: 17, fontWeight: "700" },
1294 scrollEdgeEffects: NATIVE_LIQUID_GLASS_SUPPORTED
1295 ? THREAD_SETTINGS_HEADER_SCROLL_EDGE_EFFECTS
1296 : undefined,
1297 }}
1299 <ThreadSettingsPickerStack.Screen
1300 name="ThreadSettingsModels"
1301 component={ThreadSettingsModelsScreen}
1302 options={{ headerBackVisible: false, title: "Thread settings" }}
1303 />
1304 <ThreadSettingsPickerStack.Screen
1305 name="ThreadSettingsChoice"
1306 component={ThreadSettingsChoiceScreen}
1307 options={({ route }) => ({ title: route.params.title })}
1308 />
1309 </ThreadSettingsPickerStack.Navigator>
1310 </ThreadSettingsPickerPresentationContext.Provider>
1311 );
1313​
1314/** Existing-thread model picker hosted by the root RNS form-sheet route. */
1315export function ExistingThreadSettingsRouteScreen() {
1316 const navigation = useNavigation<NativeStackNavigationProp<Record<string, object | undefined>>>();
1317 const presentation = useExistingThreadSettingsRoutePresentation();
1318 const session = presentation.session;
1319​
1320 useEffect(() => {
1321 if (session) {
1322 return;
1324​
1325 navigation.goBack();
1326 }, [navigation, session]);
1327​
1328 if (!session) {
1329 return <View className="flex-1 bg-sheet" />;
1331​
1332 const { ownerId: _ownerId, ...settings } = session;
1333​
1334 return (
1335 <ThreadSettingsSessionProvider {...settings}>
1336 <ThreadSettingsPickerNavigator onClose={() => navigation.goBack()} />
1337 </ThreadSettingsSessionProvider>
1338 );
1340​
1341/**
1342 * Native stack hosted by the New Task navigator's form-sheet route. Keeping
1343 * the sheet presentation in RNS gives UIKit ownership of nested dismissal,
1344 * while Reasoning and Runtime remain regular pushes inside this navigator.
1345 */
1346export function NewTaskThreadSettingsRouteScreen() {
1347 const flow = useNewTaskFlow();
1348 const navigation = useNavigation<NativeStackNavigationProp<Record<string, object | undefined>>>();
1349 const optionDescriptors = useMemo(
1350 () =>
1351 resolveProviderOptionDescriptors({
1352 capabilities: flow.selectedModelOption?.capabilities,
1353 selections: flow.selectedModel?.options,
1354 }),
1355 [flow.selectedModel?.options, flow.selectedModelOption?.capabilities],
1356 );
1357​
1358 return (
1359 <ThreadSettingsSessionProvider
1360 environmentId={flow.selectedEnvironmentId}
1361 providerGroups={flow.providerGroups}
1362 selectedModel={flow.selectedModel}
1363 onSelectModel={(option) => flow.setSelectedModelKey(option.key, option.selection.options)}
1364 optionDescriptors={optionDescriptors}
1365 onUpdateOptionSelections={flow.setSelectedModelOptions}
1366 runtimeMode={flow.runtimeMode}
1367 onUpdateRuntimeMode={flow.setRuntimeMode}
1369 <ThreadSettingsPickerNavigator onClose={() => navigation.goBack()} />
1370 </ThreadSettingsSessionProvider>
1371 );