feat(mobile): modernize composer and model picker
This commit is contained in:
10 files changed
+572
-143
No files matched your search
@@ -50,6 +50,7 @@ import {
|
||||
IconMinus,
|
||||
IconNetwork,
|
||||
IconPalette,
|
||||
IconPaperclip,
|
||||
IconPin,
|
||||
IconPinnedOff,
|
||||
IconPlayerPlay,
|
||||
@@ -61,6 +62,8 @@ import {
|
||||
IconServer,
|
||||
IconSettings,
|
||||
IconSparkles,
|
||||
IconStar,
|
||||
IconStarFilled,
|
||||
IconLayoutSidebarRight,
|
||||
IconTerminal2,
|
||||
IconTextDecrease,
|
||||
@@ -122,6 +125,7 @@ const ANDROID_ICON_BY_SF_SYMBOL: Partial<Record<SFSymbol, Icon>> = {
|
||||
"line.3.horizontal.decrease.circle.fill": IconFilter,
|
||||
magnifyingglass: IconSearch,
|
||||
paintbrush: IconPalette,
|
||||
paperclip: IconPaperclip,
|
||||
"person.crop.circle": IconUserCircle,
|
||||
pin: IconPin,
|
||||
"pin.slash": IconPinnedOff,
|
||||
@@ -137,6 +141,8 @@ const ANDROID_ICON_BY_SF_SYMBOL: Partial<Record<SFSymbol, Icon>> = {
|
||||
"slider.horizontal.3": IconAdjustmentsHorizontal,
|
||||
"square.and.pencil": IconEdit,
|
||||
"square.split.2x1": IconLayoutColumns,
|
||||
star: IconStar,
|
||||
"star.fill": IconStarFilled,
|
||||
"stop.fill": IconPlayerStopFilled,
|
||||
terminal: IconTerminal2,
|
||||
"text.bubble": IconMessage,
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
import type { ModelSelection, ProviderInstanceId } from "@t3tools/contracts";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { FlatList, Keyboard, Modal, Platform, Pressable, TextInput, View } from "react-native";
|
||||
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
|
||||
import {
|
||||
buildModelPickerProviderGroups,
|
||||
type ModelOption,
|
||||
type ProviderGroup,
|
||||
} from "../lib/modelOptions";
|
||||
import { AppText as Text } from "./AppText";
|
||||
import { SymbolView } from "./AppSymbol";
|
||||
import { ProviderIcon } from "./ProviderIcon";
|
||||
|
||||
type ModelPickerListItem =
|
||||
| {
|
||||
readonly key: string;
|
||||
readonly type: "provider";
|
||||
readonly providerLabel: string;
|
||||
}
|
||||
| {
|
||||
readonly key: string;
|
||||
readonly type: "legacy";
|
||||
readonly providerKey: ProviderInstanceId;
|
||||
readonly count: number;
|
||||
readonly expanded: boolean;
|
||||
readonly searching: boolean;
|
||||
}
|
||||
| {
|
||||
readonly key: string;
|
||||
readonly type: "model";
|
||||
readonly option: ModelOption;
|
||||
};
|
||||
|
||||
function selectedModelKey(selection: ModelSelection | null): string | null {
|
||||
return selection ? `${selection.instanceId}:${selection.model}` : null;
|
||||
}
|
||||
|
||||
function favoriteModelsFirst(
|
||||
models: ReadonlyArray<ModelOption>,
|
||||
favoriteModelKeys: ReadonlySet<string>,
|
||||
): ReadonlyArray<ModelOption> {
|
||||
return models
|
||||
.map((model, index) => ({ model, index }))
|
||||
.sort((a, b) => {
|
||||
const favoriteDelta =
|
||||
Number(favoriteModelKeys.has(b.model.key)) - Number(favoriteModelKeys.has(a.model.key));
|
||||
return favoriteDelta === 0 ? a.index - b.index : favoriteDelta;
|
||||
})
|
||||
.map(({ model }) => model);
|
||||
}
|
||||
|
||||
export function ModelPickerSheet(props: {
|
||||
readonly visible: boolean;
|
||||
readonly groups: ReadonlyArray<ProviderGroup>;
|
||||
readonly selectedModel: ModelSelection | null;
|
||||
readonly favoriteModelKeys: ReadonlySet<string>;
|
||||
readonly onClose: () => void;
|
||||
readonly onSelectModel: (option: ModelOption) => void;
|
||||
readonly onToggleFavorite: (option: ModelOption) => void;
|
||||
}) {
|
||||
const insets = useSafeAreaInsets();
|
||||
const [query, setQuery] = useState("");
|
||||
const [expandedLegacyProviders, setExpandedLegacyProviders] = useState(
|
||||
() => new Set<ProviderInstanceId>(),
|
||||
);
|
||||
const selectedKey = selectedModelKey(props.selectedModel);
|
||||
|
||||
useEffect(() => {
|
||||
if (!props.visible) return;
|
||||
setQuery("");
|
||||
const selectedLegacy = props.groups
|
||||
.flatMap((group) => group.models)
|
||||
.find((model) => model.key === selectedKey && model.isLegacy);
|
||||
setExpandedLegacyProviders(selectedLegacy ? new Set([selectedLegacy.providerKey]) : new Set());
|
||||
}, [props.groups, props.visible, selectedKey]);
|
||||
|
||||
const filteredGroups = useMemo(
|
||||
() => buildModelPickerProviderGroups(props.groups, query),
|
||||
[props.groups, query],
|
||||
);
|
||||
const searching = query.trim().length > 0;
|
||||
const listItems = useMemo(() => {
|
||||
const items: ModelPickerListItem[] = [];
|
||||
for (const group of filteredGroups) {
|
||||
items.push({
|
||||
key: `provider:${group.providerKey}`,
|
||||
type: "provider",
|
||||
providerLabel: group.providerLabel,
|
||||
});
|
||||
for (const option of favoriteModelsFirst(group.currentModels, props.favoriteModelKeys)) {
|
||||
items.push({ key: `model:${option.key}`, type: "model", option });
|
||||
}
|
||||
if (group.legacyModels.length > 0) {
|
||||
const expanded = searching || expandedLegacyProviders.has(group.providerKey);
|
||||
items.push({
|
||||
key: `legacy:${group.providerKey}`,
|
||||
type: "legacy",
|
||||
providerKey: group.providerKey,
|
||||
count: group.legacyModels.length,
|
||||
expanded,
|
||||
searching,
|
||||
});
|
||||
if (expanded) {
|
||||
for (const option of favoriteModelsFirst(group.legacyModels, props.favoriteModelKeys)) {
|
||||
items.push({ key: `model:${option.key}`, type: "model", option });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}, [expandedLegacyProviders, filteredGroups, props.favoriteModelKeys, searching]);
|
||||
|
||||
const toggleLegacyProvider = (providerKey: ProviderInstanceId) => {
|
||||
setExpandedLegacyProviders((current) => {
|
||||
const next = new Set(current);
|
||||
if (next.has(providerKey)) next.delete(providerKey);
|
||||
else next.add(providerKey);
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
allowSwipeDismissal
|
||||
animationType="slide"
|
||||
onRequestClose={props.onClose}
|
||||
presentationStyle={Platform.OS === "ios" ? "pageSheet" : "fullScreen"}
|
||||
statusBarTranslucent={Platform.OS === "android"}
|
||||
visible={props.visible}
|
||||
>
|
||||
<SafeAreaView
|
||||
className="flex-1 bg-black"
|
||||
edges={["bottom"]}
|
||||
style={{ paddingTop: Platform.OS === "android" ? insets.top : 0 }}
|
||||
>
|
||||
<View className="items-center pb-1 pt-2">
|
||||
<View className="h-1.5 w-16 rounded-full bg-[#515157]" />
|
||||
</View>
|
||||
|
||||
<View className="h-[68px] flex-row items-center px-5">
|
||||
<Pressable
|
||||
accessibilityLabel="Close model picker"
|
||||
accessibilityRole="button"
|
||||
className="h-12 w-[92px] items-center justify-center rounded-full border border-white/10 bg-[#242426] active:opacity-70"
|
||||
onPress={props.onClose}
|
||||
>
|
||||
<Text className="text-lg font-t3-medium text-[#f4f4f5]">Cancel</Text>
|
||||
</Pressable>
|
||||
<Text className="flex-1 text-center text-xl font-t3-bold text-white">Choose model</Text>
|
||||
<View className="w-[92px]" />
|
||||
</View>
|
||||
|
||||
<View className="px-5 pb-3">
|
||||
<View className="h-[52px] flex-row items-center gap-3 rounded-full border border-white/10 bg-[#202022] px-4">
|
||||
<SymbolView name="magnifyingglass" size={22} tintColor="#f4f4f5" type="monochrome" />
|
||||
<TextInput
|
||||
accessibilityLabel="Search models"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
className="min-w-0 flex-1 text-lg text-white"
|
||||
clearButtonMode="while-editing"
|
||||
onChangeText={setQuery}
|
||||
placeholder="Search models"
|
||||
placeholderTextColor="#85858b"
|
||||
selectionColor="#60a5fa"
|
||||
value={query}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<FlatList
|
||||
data={listItems}
|
||||
keyExtractor={(item) => item.key}
|
||||
keyboardDismissMode="on-drag"
|
||||
keyboardShouldPersistTaps="handled"
|
||||
contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 24) }}
|
||||
ListEmptyComponent={
|
||||
<View className="items-center px-8 py-16">
|
||||
<Text className="text-center text-base text-[#85858b]">
|
||||
{query.trim().length > 0
|
||||
? `No models match “${query.trim()}”.`
|
||||
: "No models found."}
|
||||
</Text>
|
||||
</View>
|
||||
}
|
||||
renderItem={({ item }) => {
|
||||
if (item.type === "provider") {
|
||||
return (
|
||||
<Text className="px-5 pb-3 pt-8 text-lg font-t3-bold text-[#85858b]">
|
||||
{item.providerLabel}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
if (item.type === "legacy") {
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityLabel={`${item.expanded ? "Hide" : "Show"} ${item.count} legacy models`}
|
||||
accessibilityRole="button"
|
||||
className="mx-5 min-h-[58px] flex-row items-center border-b border-white/10 active:opacity-70"
|
||||
disabled={item.searching}
|
||||
onPress={() => toggleLegacyProvider(item.providerKey)}
|
||||
>
|
||||
<SymbolView name="archivebox" size={20} tintColor="#77777d" type="monochrome" />
|
||||
<Text className="ml-3 flex-1 text-base font-t3-medium text-[#a2a2a8]">
|
||||
Legacy models
|
||||
</Text>
|
||||
<Text className="mr-2 text-sm text-[#6f6f75]">{item.count}</Text>
|
||||
{!item.searching ? (
|
||||
<SymbolView
|
||||
name={item.expanded ? "chevron.up" : "chevron.down"}
|
||||
size={14}
|
||||
tintColor="#77777d"
|
||||
type="monochrome"
|
||||
/>
|
||||
) : null}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
const selected = item.option.key === selectedKey;
|
||||
const favorite = props.favoriteModelKeys.has(item.option.key);
|
||||
return (
|
||||
<View className="mx-5 min-h-[82px] flex-row items-center border-b border-white/10">
|
||||
<Pressable
|
||||
accessibilityLabel={`${item.option.label}, ${item.option.selection.model}`}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
className="min-w-0 flex-1 flex-row items-center self-stretch active:opacity-70"
|
||||
onPress={() => {
|
||||
Keyboard.dismiss();
|
||||
props.onSelectModel(item.option);
|
||||
props.onClose();
|
||||
}}
|
||||
>
|
||||
<View className="w-12 items-start">
|
||||
<ProviderIcon provider={item.option.providerDriver} size={28} />
|
||||
</View>
|
||||
<View className="min-w-0 flex-1 py-3">
|
||||
<Text className="text-lg font-t3-bold text-[#f5f5f6]" numberOfLines={1}>
|
||||
{item.option.label}
|
||||
</Text>
|
||||
<Text className="mt-0.5 text-sm text-[#909096]" numberOfLines={1}>
|
||||
{item.option.selection.model}
|
||||
</Text>
|
||||
</View>
|
||||
{selected ? (
|
||||
<SymbolView name="checkmark" size={22} tintColor="#f5f5f6" type="monochrome" />
|
||||
) : null}
|
||||
</Pressable>
|
||||
<Pressable
|
||||
accessibilityLabel={favorite ? "Remove from favorites" : "Add to favorites"}
|
||||
accessibilityRole="button"
|
||||
className="ml-3 h-11 w-11 items-center justify-center active:opacity-60"
|
||||
hitSlop={4}
|
||||
onPress={() => props.onToggleFavorite(item.option)}
|
||||
>
|
||||
<SymbolView
|
||||
name={favorite ? "star.fill" : "star"}
|
||||
size={23}
|
||||
tintColor={favorite ? "#facc15" : "#77777d"}
|
||||
type="monochrome"
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NativeStackScreenOptions } from "../../native/StackHeader";
|
||||
import { StackActions, useNavigation, usePreventRemove } from "@react-navigation/native";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Alert, Pressable, View, useColorScheme } from "react-native";
|
||||
import { Alert, Keyboard, Pressable, View, useColorScheme } from "react-native";
|
||||
import { KeyboardAvoidingView, useKeyboardState } from "react-native-keyboard-controller";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
|
||||
import { ComposerEditor, type ComposerEditorHandle } from "../../components/ComposerEditor";
|
||||
import {
|
||||
ComposerContextRing,
|
||||
ComposerToolbarButton,
|
||||
ComposerToolbarRow,
|
||||
ComposerToolbarScroller,
|
||||
@@ -24,6 +23,7 @@ import { AppText as Text } from "../../components/AppText";
|
||||
import { SymbolView } from "../../components/AppSymbol";
|
||||
import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
|
||||
import { ControlPillMenu } from "../../components/ControlPill";
|
||||
import { ModelPickerSheet } from "../../components/ModelPickerSheet";
|
||||
import { ProviderIcon } from "../../components/ProviderIcon";
|
||||
import { ComposerSurface } from "./ThreadComposer";
|
||||
|
||||
@@ -43,7 +43,7 @@ import {
|
||||
type ComposerDraft,
|
||||
} from "../../state/use-composer-drafts";
|
||||
import { useEnvironmentServerConfig, useProjects } from "../../state/entities";
|
||||
import { buildModelMenuActions, resolveSelectableModelSelection } from "../../lib/modelOptions";
|
||||
import { resolveSelectableModelSelection } from "../../lib/modelOptions";
|
||||
import { deriveThreadTitleFromPrompt } from "../../lib/projectThreadStartTurn";
|
||||
import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/remoteRegistration";
|
||||
import { enqueueThreadOutboxMessage, removeThreadOutboxMessage } from "../../state/thread-outbox";
|
||||
@@ -51,6 +51,7 @@ import { useRemoteConnectionStatus } from "../../state/use-remote-environment-re
|
||||
import { branchBadgeLabel, useNewTaskFlow } from "./new-task-flow-provider";
|
||||
import { useCreateProjectThread } from "./use-project-actions";
|
||||
import { useIncomingShare } from "../sharing/IncomingShareProvider";
|
||||
import { useModelFavorites } from "./useModelFavorites";
|
||||
|
||||
export function NewTaskDraftScreen(props: {
|
||||
readonly initialProjectRef?: {
|
||||
@@ -82,6 +83,9 @@ export function NewTaskDraftScreen(props: {
|
||||
const selectedEnvironmentServerConfig = useEnvironmentServerConfig(
|
||||
selectedProject?.environmentId ?? null,
|
||||
);
|
||||
const { favoriteModelKeys, toggleFavorite } = useModelFavorites(
|
||||
selectedProject?.environmentId ?? null,
|
||||
);
|
||||
const environmentConnected =
|
||||
selectedProject !== null &&
|
||||
connectedEnvironments.find(
|
||||
@@ -94,6 +98,7 @@ export function NewTaskDraftScreen(props: {
|
||||
const [cancelledIncomingShareId, setCancelledIncomingShareId] = useState<string | null>(null);
|
||||
const [isReturningToProjectPicker, setIsReturningToProjectPicker] = useState(false);
|
||||
const [shareImportAttempt, setShareImportAttempt] = useState(0);
|
||||
const [modelPickerVisible, setModelPickerVisible] = useState(false);
|
||||
const startedShareImportKeyRef = useRef<string | null>(null);
|
||||
const cancellingShareImportKeyRef = useRef<string | null>(null);
|
||||
const shareImportDraftBackupRef = useRef(new Map<string, ComposerDraft>());
|
||||
@@ -506,10 +511,6 @@ export function NewTaskDraftScreen(props: {
|
||||
[flow.environments, flow.selectedEnvironmentId, isIncomingShareTransferPending],
|
||||
);
|
||||
|
||||
const modelMenuActions = useMemo(
|
||||
() => buildModelMenuActions(flow.providerGroups, flow.selectedModel),
|
||||
[flow.providerGroups, flow.selectedModel],
|
||||
);
|
||||
const providerOptionDescriptors = useMemo(
|
||||
() =>
|
||||
resolveProviderOptionDescriptors({
|
||||
@@ -633,14 +634,6 @@ export function NewTaskDraftScreen(props: {
|
||||
flow.environments.find(
|
||||
(environment) => environment.environmentId === flow.selectedEnvironmentId,
|
||||
)?.environmentLabel ?? "Environment";
|
||||
const accessModeLabel =
|
||||
flow.runtimeMode === "approval-required"
|
||||
? "Supervised"
|
||||
: flow.runtimeMode === "auto-accept-edits"
|
||||
? "Auto-accept"
|
||||
: flow.runtimeMode === "auto"
|
||||
? "Auto"
|
||||
: "Full access";
|
||||
const configurationMenuActions = useMemo(
|
||||
() => [
|
||||
...optionsMenuActions,
|
||||
@@ -654,13 +647,6 @@ export function NewTaskDraftScreen(props: {
|
||||
],
|
||||
[environmentMenuActions, optionsMenuActions, selectedEnvironmentLabel, workspaceMenuActions],
|
||||
);
|
||||
function handleModelMenuAction(event: string) {
|
||||
if (isIncomingShareTransferPending || !event.startsWith("model:")) {
|
||||
return;
|
||||
}
|
||||
flow.setSelectedModelKey(event.slice("model:".length));
|
||||
}
|
||||
|
||||
function handleEnvironmentMenuAction(event: string) {
|
||||
if (isIncomingShareTransferPending || !event.startsWith("environment:")) {
|
||||
return;
|
||||
@@ -911,11 +897,11 @@ export function NewTaskDraftScreen(props: {
|
||||
skills={flow.selectedProviderSkills}
|
||||
onChangeText={flow.setPrompt}
|
||||
onPasteImages={(uris) => void handleNativePasteImages(uris)}
|
||||
placeholder="Ask anything, @tag files, / for commands"
|
||||
placeholder="Ask anything..."
|
||||
contentInsetVertical={0}
|
||||
style={{
|
||||
minHeight: 84,
|
||||
maxHeight: 176,
|
||||
minHeight: 76,
|
||||
maxHeight: 160,
|
||||
paddingHorizontal: 4,
|
||||
paddingVertical: 4,
|
||||
}}
|
||||
@@ -928,22 +914,22 @@ export function NewTaskDraftScreen(props: {
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel="Add attachment"
|
||||
disabled={isIncomingShareTransferPending}
|
||||
icon="plus"
|
||||
icon="paperclip"
|
||||
onPress={() => void handlePickImages()}
|
||||
showChevron={false}
|
||||
variant="ghost"
|
||||
/>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Choose model"
|
||||
disabled={isIncomingShareTransferPending}
|
||||
iconNode={<ProviderIcon provider={flow.selectedModelOption?.providerDriver} size={18} />}
|
||||
label={flow.selectedModelOption?.label ?? "Model"}
|
||||
onPress={() => {
|
||||
Keyboard.dismiss();
|
||||
setModelPickerVisible(true);
|
||||
}}
|
||||
variant="ghost"
|
||||
/>
|
||||
<ControlPillMenu
|
||||
actions={modelMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Model"
|
||||
disabled={isIncomingShareTransferPending}
|
||||
iconNode={<ProviderIcon provider={flow.selectedModelOption?.providerDriver} size={16} />}
|
||||
label={flow.selectedModelOption?.label ?? "Model"}
|
||||
variant="ghost"
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={configurationMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleConfigurationMenuAction(nativeEvent.event)}
|
||||
@@ -952,7 +938,7 @@ export function NewTaskDraftScreen(props: {
|
||||
accessibilityLabel="Configuration"
|
||||
disabled={isIncomingShareTransferPending}
|
||||
icon="slider.horizontal.3"
|
||||
label={accessModeLabel}
|
||||
showChevron={false}
|
||||
variant="ghost"
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
@@ -976,7 +962,7 @@ export function NewTaskDraftScreen(props: {
|
||||
<View
|
||||
className="flex-1 overflow-hidden"
|
||||
style={{
|
||||
backgroundColor: isDarkMode ? "#060607" : "#f2f2f7",
|
||||
backgroundColor: isDarkMode ? "#000000" : "#f2f2f7",
|
||||
borderColor: isDarkMode ? "rgba(255,255,255,0.14)" : "rgba(0,0,0,0.1)",
|
||||
borderTopLeftRadius: 20,
|
||||
borderTopRightRadius: 20,
|
||||
@@ -1052,10 +1038,11 @@ export function NewTaskDraftScreen(props: {
|
||||
isDarkMode={isDarkMode}
|
||||
style={{
|
||||
backgroundColor: isDarkMode ? "rgba(17,17,19,0.95)" : "rgba(255,255,255,0.95)",
|
||||
borderRadius: 20,
|
||||
borderRadius: 22,
|
||||
overflow: "hidden",
|
||||
paddingHorizontal: 14,
|
||||
paddingTop: 12,
|
||||
paddingBottom: 6,
|
||||
paddingHorizontal: 12,
|
||||
paddingTop: 10,
|
||||
}}
|
||||
>
|
||||
{flow.attachments.length > 0 ? (
|
||||
@@ -1069,19 +1056,27 @@ export function NewTaskDraftScreen(props: {
|
||||
</View>
|
||||
) : null}
|
||||
{promptEditor}
|
||||
<ComposerToolbarRow paddingBottom={8} paddingHorizontal={7} paddingTop={4}>
|
||||
<ComposerToolbarRow paddingBottom={0} paddingHorizontal={0} paddingTop={4}>
|
||||
<ComposerToolbarScroller
|
||||
fadeOpaque={isDarkMode ? "rgba(17,17,19,0.95)" : "rgba(255,255,255,0.95)"}
|
||||
fadeTransparent={isDarkMode ? "rgba(17,17,19,0)" : "rgba(255,255,255,0)"}
|
||||
>
|
||||
{toolbarPills}
|
||||
</ComposerToolbarScroller>
|
||||
<ComposerContextRing />
|
||||
{startButton}
|
||||
</ComposerToolbarRow>
|
||||
</ComposerSurface>
|
||||
</View>
|
||||
</KeyboardAvoidingView>
|
||||
<ModelPickerSheet
|
||||
favoriteModelKeys={favoriteModelKeys}
|
||||
groups={flow.providerGroups}
|
||||
onClose={() => setModelPickerVisible(false)}
|
||||
onSelectModel={(option) => flow.setSelectedModelKey(option.key)}
|
||||
onToggleFavorite={toggleFavorite}
|
||||
selectedModel={flow.selectedModel}
|
||||
visible={modelPickerVisible}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -16,7 +16,15 @@ import {
|
||||
} from "@t3tools/shared/composerTrigger";
|
||||
import type { ReactNode } from "react";
|
||||
import { memo, useCallback, useEffect, useMemo, useRef, useState, type RefObject } from "react";
|
||||
import { Image, Platform, Pressable, useColorScheme, View, type ViewStyle } from "react-native";
|
||||
import {
|
||||
Image,
|
||||
Keyboard,
|
||||
Platform,
|
||||
Pressable,
|
||||
useColorScheme,
|
||||
View,
|
||||
type ViewStyle,
|
||||
} from "react-native";
|
||||
import ImageViewing from "react-native-image-viewing";
|
||||
import Animated, {
|
||||
FadeIn,
|
||||
@@ -37,16 +45,16 @@ import {
|
||||
type ComposerEditorSelection,
|
||||
} from "../../components/ComposerEditor";
|
||||
import {
|
||||
ComposerContextRing,
|
||||
ComposerToolbarButton,
|
||||
ComposerToolbarRow,
|
||||
ComposerToolbarScroller,
|
||||
ComposerToolbarTrigger,
|
||||
} from "../../components/ComposerToolbarTrigger";
|
||||
import { ControlPillMenu } from "../../components/ControlPill";
|
||||
import { ModelPickerSheet } from "../../components/ModelPickerSheet";
|
||||
import { ProviderIcon } from "../../components/ProviderIcon";
|
||||
import type { DraftComposerImageAttachment } from "../../lib/composerImages";
|
||||
import { buildModelMenuActions, buildModelOptions, groupByProvider } from "../../lib/modelOptions";
|
||||
import { buildModelOptions, groupByProvider } from "../../lib/modelOptions";
|
||||
import { useScaledTextRole } from "../settings/appearance/useScaledTextRole";
|
||||
import type { RemoteClientConnectionState } from "../../lib/connection";
|
||||
import {
|
||||
@@ -61,6 +69,7 @@ import {
|
||||
} from "../../lib/providerOptions";
|
||||
import { useComposerPathSearch } from "../../state/use-composer-path-search";
|
||||
import { ComposerCommandPopover, type ComposerCommandItem } from "./ComposerCommandPopover";
|
||||
import { useModelFavorites } from "./useModelFavorites";
|
||||
|
||||
/**
|
||||
* Height of the collapsed composer (pill + vertical padding, excluding safe-area inset).
|
||||
@@ -72,7 +81,7 @@ export const COMPOSER_COLLAPSED_CHROME = 68;
|
||||
* Height of the expanded composer (card + toolbar + vertical padding, excluding safe-area inset).
|
||||
* Used by the parent to compute the larger feed bottom inset when the composer is focused.
|
||||
*/
|
||||
export const COMPOSER_EXPANDED_CHROME = 212;
|
||||
export const COMPOSER_EXPANDED_CHROME = 184;
|
||||
|
||||
export interface ThreadComposerProps {
|
||||
readonly draftMessage: string;
|
||||
@@ -269,6 +278,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
const { onExpandedChange } = props;
|
||||
|
||||
const [previewImageUri, setPreviewImageUri] = useState<string | null>(null);
|
||||
const [modelPickerVisible, setModelPickerVisible] = useState(false);
|
||||
const hasContent = props.draftMessage.trim().length > 0 || props.draftAttachments.length > 0;
|
||||
const isExpanded = isFocused;
|
||||
const canSend = hasContent;
|
||||
@@ -308,14 +318,6 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
const currentModelSelection = props.selectedThread.modelSelection;
|
||||
const currentRuntimeMode = props.selectedThread.runtimeMode;
|
||||
const currentInteractionMode = props.selectedThread.interactionMode ?? "default";
|
||||
const accessModeLabel =
|
||||
currentRuntimeMode === "approval-required"
|
||||
? "Supervised"
|
||||
: currentRuntimeMode === "auto-accept-edits"
|
||||
? "Auto-accept"
|
||||
: currentRuntimeMode === "auto"
|
||||
? "Auto"
|
||||
: "Full access";
|
||||
const connectionStatus = composerConnectionStatus({
|
||||
connectionError: props.connectionError,
|
||||
connectionState: props.connectionState,
|
||||
@@ -601,10 +603,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
}),
|
||||
[currentModelOption?.capabilities, currentModelSelection.options],
|
||||
);
|
||||
const modelMenuActions = useMemo(
|
||||
() => buildModelMenuActions(providerGroups, currentModelSelection),
|
||||
[providerGroups, currentModelSelection],
|
||||
);
|
||||
const { favoriteModelKeys, toggleFavorite } = useModelFavorites(props.environmentId);
|
||||
|
||||
// ── Options menu ─────────────────────────────────────────
|
||||
const optionsMenuActions = useMemo(
|
||||
@@ -656,17 +655,6 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
);
|
||||
|
||||
// ── Menu handlers ────────────────────────────────────────
|
||||
function handleModelMenuAction(event: string) {
|
||||
if (!event.startsWith("model:")) {
|
||||
return;
|
||||
}
|
||||
const modelKey = event.slice("model:".length);
|
||||
const option = modelOptions.find((o) => o.key === modelKey);
|
||||
if (option) {
|
||||
props.onUpdateModelSelection(option.selection);
|
||||
}
|
||||
}
|
||||
|
||||
function handleOptionsMenuAction(event: string) {
|
||||
const providerOptions = applyProviderOptionMenuEvent(providerOptionDescriptors, event);
|
||||
if (providerOptions) {
|
||||
@@ -727,10 +715,11 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
style={
|
||||
isExpanded
|
||||
? {
|
||||
borderRadius: 20,
|
||||
borderRadius: 22,
|
||||
overflow: "hidden" as const,
|
||||
paddingHorizontal: 14,
|
||||
paddingVertical: 12,
|
||||
paddingHorizontal: 12,
|
||||
paddingBottom: 6,
|
||||
paddingTop: 10,
|
||||
backgroundColor: isDarkMode ? "rgba(17,17,19,0.95)" : "rgba(255,255,255,0.95)",
|
||||
}
|
||||
: {
|
||||
@@ -783,8 +772,8 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
style={
|
||||
isExpanded
|
||||
? {
|
||||
minHeight: 84,
|
||||
maxHeight: 176,
|
||||
minHeight: 76,
|
||||
maxHeight: 160,
|
||||
paddingHorizontal: 4,
|
||||
paddingVertical: 4,
|
||||
}
|
||||
@@ -840,67 +829,65 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
)}
|
||||
</Animated.View>
|
||||
) : null}
|
||||
</ComposerSurface>
|
||||
|
||||
{isExpanded ? (
|
||||
<Animated.View entering={FadeIn.duration(160)} exiting={FadeOut.duration(120)}>
|
||||
<ComposerToolbarRow paddingBottom={8} paddingHorizontal={0} paddingTop={8}>
|
||||
<ComposerToolbarScroller
|
||||
fadeOpaque={toolbarFadeOpaque}
|
||||
fadeTransparent={toolbarFadeTransparent}
|
||||
>
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel="Add attachment"
|
||||
icon="plus"
|
||||
onPress={() => void props.onPickDraftImages()}
|
||||
showChevron={false}
|
||||
/>
|
||||
<ControlPillMenu
|
||||
actions={modelMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
|
||||
{isExpanded ? (
|
||||
<Animated.View entering={FadeIn.duration(160)} exiting={FadeOut.duration(120)}>
|
||||
<ComposerToolbarRow paddingBottom={0} paddingHorizontal={0} paddingTop={4}>
|
||||
<ComposerToolbarScroller
|
||||
fadeOpaque={toolbarFadeOpaque}
|
||||
fadeTransparent={toolbarFadeTransparent}
|
||||
>
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel="Add attachment"
|
||||
icon="paperclip"
|
||||
onPress={() => void props.onPickDraftImages()}
|
||||
showChevron={false}
|
||||
variant="ghost"
|
||||
/>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Model"
|
||||
accessibilityLabel="Choose model"
|
||||
iconNode={
|
||||
<ProviderIcon provider={currentModelOption?.providerDriver} size={18} />
|
||||
}
|
||||
label={currentModelOption?.label ?? currentModelSelection.model}
|
||||
onPress={() => {
|
||||
Keyboard.dismiss();
|
||||
setModelPickerVisible(true);
|
||||
}}
|
||||
variant="ghost"
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={optionsMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Configuration"
|
||||
icon="slider.horizontal.3"
|
||||
label={accessModeLabel}
|
||||
variant="ghost"
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ComposerContextRing />
|
||||
{showStopAction ? (
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel="Stop"
|
||||
icon="stop.fill"
|
||||
variant="danger"
|
||||
onPress={props.onStopThread}
|
||||
showChevron={false}
|
||||
/>
|
||||
) : null}
|
||||
</ComposerToolbarScroller>
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel={sendLabel}
|
||||
icon="arrow.up"
|
||||
variant="primary"
|
||||
disabled={!canSend}
|
||||
onPress={handleSend}
|
||||
showChevron={false}
|
||||
/>
|
||||
</ComposerToolbarRow>
|
||||
</Animated.View>
|
||||
) : null}
|
||||
<ControlPillMenu
|
||||
actions={optionsMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Configuration"
|
||||
icon="slider.horizontal.3"
|
||||
showChevron={false}
|
||||
variant="ghost"
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
{showStopAction ? (
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel="Stop"
|
||||
icon="stop.fill"
|
||||
variant="danger"
|
||||
onPress={props.onStopThread}
|
||||
showChevron={false}
|
||||
/>
|
||||
) : null}
|
||||
</ComposerToolbarScroller>
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel={sendLabel}
|
||||
icon="arrow.up"
|
||||
variant="primary"
|
||||
disabled={!canSend}
|
||||
onPress={handleSend}
|
||||
showChevron={false}
|
||||
/>
|
||||
</ComposerToolbarRow>
|
||||
</Animated.View>
|
||||
) : null}
|
||||
</ComposerSurface>
|
||||
|
||||
{props.queueCount > 0 ? (
|
||||
<Animated.View entering={FadeIn.duration(180)} exiting={FadeOut.duration(120)}>
|
||||
@@ -920,6 +907,15 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
swipeToCloseEnabled
|
||||
doubleTapToZoomEnabled
|
||||
/>
|
||||
<ModelPickerSheet
|
||||
favoriteModelKeys={favoriteModelKeys}
|
||||
groups={providerGroups}
|
||||
onClose={() => setModelPickerVisible(false)}
|
||||
onSelectModel={(option) => props.onUpdateModelSelection(option.selection)}
|
||||
onToggleFavorite={toggleFavorite}
|
||||
selectedModel={currentModelSelection}
|
||||
visible={modelPickerVisible}
|
||||
/>
|
||||
</Animated.View>
|
||||
);
|
||||
});
|
||||
@@ -437,7 +437,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
editorRef={composerEditorRef}
|
||||
draftMessage={props.draftMessage}
|
||||
draftAttachments={props.draftAttachments}
|
||||
placeholder="Ask the repo agent, or run a command…"
|
||||
placeholder="Ask anything..."
|
||||
contentMaxWidth={contentMaxWidth}
|
||||
connectionState={props.connectionStateLabel}
|
||||
connectionError={props.connectionError}
|
||||
|
||||
@@ -787,7 +787,7 @@ function ThreadRouteContent(
|
||||
],
|
||||
[navigation],
|
||||
);
|
||||
const statusGitHeaderItem = useMemo(() => {
|
||||
const compactThreadActionItem = useMemo(() => {
|
||||
const gitItem = compactRightHeaderItems.find((item) => item.identifier === "thread-right-git");
|
||||
if (!gitItem) {
|
||||
return null;
|
||||
@@ -797,10 +797,10 @@ function ThreadRouteContent(
|
||||
existingMenu && Array.isArray(existingMenu.items) ? existingMenu.items : [];
|
||||
return {
|
||||
...gitItem,
|
||||
accessibilityLabel: `Thread status: ${threadHeaderStatus.label}. Thread actions`,
|
||||
icon: undefined,
|
||||
identifier: "thread-right-status",
|
||||
label: threadHeaderStatus.nativeLabel,
|
||||
accessibilityLabel: "Thread actions",
|
||||
icon: { name: "ellipsis", type: "sfSymbol" as const },
|
||||
identifier: "thread-right-actions",
|
||||
label: undefined,
|
||||
menu: {
|
||||
...existingMenu,
|
||||
items: [
|
||||
@@ -824,7 +824,9 @@ function ThreadRouteContent(
|
||||
],
|
||||
title: "Thread actions",
|
||||
},
|
||||
tintColor: threadHeaderStatus.tintColor,
|
||||
sharesBackground: false,
|
||||
tintColor: undefined,
|
||||
width: 44,
|
||||
};
|
||||
}, [
|
||||
compactRightHeaderItems,
|
||||
@@ -832,14 +834,45 @@ function ThreadRouteContent(
|
||||
handleOpenTerminal,
|
||||
selectedThreadCwd,
|
||||
selectedThreadProject?.workspaceRoot,
|
||||
threadHeaderStatus,
|
||||
]);
|
||||
const compactThreadStatusItem = useMemo(
|
||||
() => ({
|
||||
accessibilityLabel: `Thread status: ${threadHeaderStatus.label}`,
|
||||
icon: {
|
||||
name:
|
||||
threadHeaderStatus.kind === "done"
|
||||
? "checkmark.circle"
|
||||
: threadHeaderStatus.kind === "working"
|
||||
? "timer"
|
||||
: threadHeaderStatus.kind === "approval"
|
||||
? "exclamationmark.circle"
|
||||
: threadHeaderStatus.kind === "input"
|
||||
? "questionmark.circle"
|
||||
: "xmark.circle",
|
||||
type: "sfSymbol" as const,
|
||||
},
|
||||
identifier: "thread-right-status",
|
||||
label: threadHeaderStatus.nativeLabel,
|
||||
onPress: handleOpenGitInspector,
|
||||
sharesBackground: false,
|
||||
tintColor: threadHeaderStatus.tintColor,
|
||||
type: "button" as const,
|
||||
}),
|
||||
[handleOpenGitInspector, threadHeaderStatus],
|
||||
);
|
||||
const nativeThreadRightHeaderItems = useMemo<NativeHeaderItems>(() => {
|
||||
if (layout.usesSplitView) {
|
||||
return threadCenterHeaderItems;
|
||||
}
|
||||
return statusGitHeaderItem ? [statusGitHeaderItem] : [];
|
||||
}, [layout.usesSplitView, statusGitHeaderItem, threadCenterHeaderItems]);
|
||||
return compactThreadActionItem
|
||||
? [compactThreadStatusItem, compactThreadActionItem]
|
||||
: [compactThreadStatusItem];
|
||||
}, [
|
||||
compactThreadActionItem,
|
||||
compactThreadStatusItem,
|
||||
layout.usesSplitView,
|
||||
threadCenterHeaderItems,
|
||||
]);
|
||||
|
||||
if (!environmentId || !threadId) {
|
||||
return <OpeningThreadLoadingScreen />;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { AsyncResult } from "effect/unstable/reactivity";
|
||||
|
||||
import type { ModelOption } from "../../lib/modelOptions";
|
||||
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
|
||||
|
||||
/** Persists model favorites on this device without inventing a server setting. */
|
||||
export function useModelFavorites(environmentId: EnvironmentId | null) {
|
||||
const preferencesResult = useAtomValue(mobilePreferencesAtom);
|
||||
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
|
||||
const storedKeys = AsyncResult.isSuccess(preferencesResult)
|
||||
? (preferencesResult.value.favoriteModelKeys ?? [])
|
||||
: [];
|
||||
const environmentPrefix = environmentId === null ? null : `${environmentId}:`;
|
||||
|
||||
const favoriteModelKeys = useMemo(() => {
|
||||
if (environmentPrefix === null) return new Set<string>();
|
||||
return new Set(
|
||||
storedKeys.flatMap((key) =>
|
||||
key.startsWith(environmentPrefix) ? [key.slice(environmentPrefix.length)] : [],
|
||||
),
|
||||
);
|
||||
}, [environmentPrefix, storedKeys]);
|
||||
|
||||
const toggleFavorite = useCallback(
|
||||
(option: ModelOption) => {
|
||||
if (environmentPrefix === null) return;
|
||||
const scopedKey = `${environmentPrefix}${option.key}`;
|
||||
const nextKeys = storedKeys.includes(scopedKey)
|
||||
? storedKeys.filter((key) => key !== scopedKey)
|
||||
: [...storedKeys, scopedKey];
|
||||
savePreferences({ favoriteModelKeys: nextKeys });
|
||||
},
|
||||
[environmentPrefix, savePreferences, storedKeys],
|
||||
);
|
||||
|
||||
return { favoriteModelKeys, toggleFavorite };
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { ProviderInstanceId, type ServerConfig } from "@t3tools/contracts";
|
||||
import {
|
||||
buildModelMenuActions,
|
||||
buildModelOptions,
|
||||
buildModelPickerProviderGroups,
|
||||
groupByProvider,
|
||||
resolveSelectableModelSelection,
|
||||
} from "./modelOptions";
|
||||
@@ -88,6 +89,46 @@ describe("mobile model options", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps legacy models folded into their provider while search can reveal them", () => {
|
||||
const config = {
|
||||
providers: [
|
||||
{
|
||||
instanceId: "codex",
|
||||
driver: "codex",
|
||||
displayName: "Codex",
|
||||
enabled: true,
|
||||
installed: true,
|
||||
auth: { status: "authenticated" },
|
||||
models: [
|
||||
{
|
||||
slug: "gpt-current",
|
||||
name: "GPT Current",
|
||||
isCustom: false,
|
||||
capabilities: null,
|
||||
},
|
||||
{
|
||||
slug: "gpt-legacy",
|
||||
name: "GPT Legacy",
|
||||
isCustom: false,
|
||||
isLegacy: true,
|
||||
capabilities: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
} as unknown as ServerConfig;
|
||||
|
||||
const groups = groupByProvider(buildModelOptions(config, null));
|
||||
expect(buildModelPickerProviderGroups(groups, "")[0]).toMatchObject({
|
||||
currentModels: [{ label: "GPT Current" }],
|
||||
legacyModels: [{ label: "GPT Legacy" }],
|
||||
});
|
||||
expect(buildModelPickerProviderGroups(groups, "legacy")[0]).toMatchObject({
|
||||
currentModels: [],
|
||||
legacyModels: [{ label: "GPT Legacy" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes a legacy fallback selection against current capabilities", () => {
|
||||
const config = {
|
||||
providers: [
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type {
|
||||
ModelCapabilities,
|
||||
ModelSelection,
|
||||
ProviderInstanceId,
|
||||
ServerConfig as T3ServerConfig,
|
||||
} from "@t3tools/contracts";
|
||||
import type { MenuAction } from "@react-native-menu/menu";
|
||||
@@ -13,7 +14,7 @@ export type ModelOption = {
|
||||
readonly key: string;
|
||||
readonly label: string;
|
||||
readonly subtitle: string;
|
||||
readonly providerKey: string;
|
||||
readonly providerKey: ProviderInstanceId;
|
||||
readonly providerLabel: string;
|
||||
readonly providerDriver: string;
|
||||
readonly isDefault: boolean;
|
||||
@@ -23,11 +24,16 @@ export type ModelOption = {
|
||||
};
|
||||
|
||||
export type ProviderGroup = {
|
||||
readonly providerKey: string;
|
||||
readonly providerKey: ProviderInstanceId;
|
||||
readonly providerLabel: string;
|
||||
readonly models: ReadonlyArray<ModelOption>;
|
||||
};
|
||||
|
||||
export type ModelPickerProviderGroup = ProviderGroup & {
|
||||
readonly currentModels: ReadonlyArray<ModelOption>;
|
||||
readonly legacyModels: ReadonlyArray<ModelOption>;
|
||||
};
|
||||
|
||||
function providerDisplayLabel(provider: {
|
||||
readonly displayName?: string | undefined;
|
||||
readonly driver: string;
|
||||
@@ -149,7 +155,7 @@ export function buildModelOptions(
|
||||
}
|
||||
|
||||
export function groupByProvider(options: ReadonlyArray<ModelOption>): ReadonlyArray<ProviderGroup> {
|
||||
const groups = new Map<string, { providerLabel: string; models: ModelOption[] }>();
|
||||
const groups = new Map<ProviderInstanceId, { providerLabel: string; models: ModelOption[] }>();
|
||||
for (const option of options) {
|
||||
const existing = groups.get(option.providerKey);
|
||||
if (existing) {
|
||||
@@ -169,6 +175,37 @@ export function groupByProvider(options: ReadonlyArray<ModelOption>): ReadonlyAr
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the provider sections used by the full-screen mobile picker. Legacy
|
||||
* models stay separate so the UI can keep them folded until requested while
|
||||
* search can still reveal a matching legacy model immediately.
|
||||
*/
|
||||
export function buildModelPickerProviderGroups(
|
||||
groups: ReadonlyArray<ProviderGroup>,
|
||||
query: string,
|
||||
): ReadonlyArray<ModelPickerProviderGroup> {
|
||||
const tokens = query.trim().toLocaleLowerCase().split(/\s+/u).filter(Boolean);
|
||||
const matches = (option: ModelOption) => {
|
||||
if (tokens.length === 0) return true;
|
||||
const searchable = [
|
||||
option.label,
|
||||
option.selection.model,
|
||||
option.providerLabel,
|
||||
option.providerDriver,
|
||||
]
|
||||
.join(" ")
|
||||
.toLocaleLowerCase();
|
||||
return tokens.every((token) => searchable.includes(token));
|
||||
};
|
||||
|
||||
return groups.flatMap((group) => {
|
||||
const currentModels = group.models.filter((model) => !model.isLegacy && matches(model));
|
||||
const legacyModels = group.models.filter((model) => model.isLegacy && matches(model));
|
||||
if (currentModels.length === 0 && legacyModels.length === 0) return [];
|
||||
return [{ ...group, currentModels, legacyModels }];
|
||||
});
|
||||
}
|
||||
|
||||
function modelMenuAction(option: ModelOption, selectedModel: ModelSelection | null): MenuAction {
|
||||
return {
|
||||
id: `model:${option.key}`,
|
||||
|
||||
@@ -22,6 +22,8 @@ export interface Preferences {
|
||||
readonly codeWordBreak?: boolean;
|
||||
readonly connectOnboardingOptOutAccounts?: ReadonlyArray<string>;
|
||||
readonly collapsedProjectGroups?: readonly string[];
|
||||
/** Device-local model favorites, scoped as environment:model-option keys. */
|
||||
readonly favoriteModelKeys?: readonly string[];
|
||||
readonly projectGroupingEnabled?: boolean;
|
||||
/**
|
||||
* Device-local mirror of the web beta's `sidebarV2Enabled`. Mobile has no
|
||||
@@ -79,6 +81,7 @@ function sanitizePreferences(parsed: Preferences): Preferences {
|
||||
codeWordBreak?: boolean;
|
||||
connectOnboardingOptOutAccounts?: ReadonlyArray<string>;
|
||||
collapsedProjectGroups?: readonly string[];
|
||||
favoriteModelKeys?: readonly string[];
|
||||
projectGroupingEnabled?: boolean;
|
||||
threadListV2Enabled?: boolean;
|
||||
} = {};
|
||||
@@ -107,6 +110,11 @@ function sanitizePreferences(parsed: Preferences): Preferences {
|
||||
(key): key is string => typeof key === "string",
|
||||
);
|
||||
}
|
||||
if (Array.isArray(parsed.favoriteModelKeys)) {
|
||||
preferences.favoriteModelKeys = parsed.favoriteModelKeys.filter(
|
||||
(key): key is string => typeof key === "string",
|
||||
);
|
||||
}
|
||||
if (typeof parsed.projectGroupingEnabled === "boolean") {
|
||||
preferences.projectGroupingEnabled = parsed.projectGroupingEnabled;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user