@@ -25,15 +25,12 @@ import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStri |
25 | 25 | import { ControlPill, ControlPillMenu } from "../../components/ControlPill"; |
26 | 26 | import { ProviderIcon } from "../../components/ProviderIcon"; |
27 | 27 | import { ComposerSurface } from "./ThreadComposer"; |
| 28 | +import { ThreadSettingsSheet, threadSettingsSummaryLabel } from "./ThreadSettingsSheet"; |
| 29 | +import { useThreadSettingsSheetPresentation } from "./use-thread-settings-sheet-presentation"; |
28 | 30 |
|
29 | 31 | import { makeTurnCommandMetadata } from "../../lib/commandMetadata"; |
30 | 32 | import { convertPastedImagesToAttachments, pickComposerImages } from "../../lib/composerImages"; |
31 | | -import { |
32 | | - applyProviderOptionMenuEvent, |
33 | | - buildProviderOptionMenuActions, |
34 | | - providerOptionsConfigurationLabel, |
35 | | - resolveProviderOptionDescriptors, |
36 | | -} from "../../lib/providerOptions"; |
| 33 | +import { resolveProviderOptionDescriptors } from "../../lib/providerOptions"; |
37 | 34 | import { useScaledTextRole } from "../settings/appearance/useScaledTextRole"; |
38 | 35 | import { |
39 | 36 | clearComposerDraftContent, |
@@ -45,7 +42,7 @@ import { |
45 | 42 | type ComposerDraftWorkspaceSelection, |
46 | 43 | } from "../../state/use-composer-drafts"; |
47 | 44 | import { useEnvironmentServerConfig, useProjects } from "../../state/entities"; |
48 | | -import { buildModelMenuActions, resolveSelectableModelSelection } from "../../lib/modelOptions"; |
| 45 | +import { resolveSelectableModelSelection } from "../../lib/modelOptions"; |
49 | 46 | import { deriveThreadTitleFromPrompt } from "../../lib/projectThreadStartTurn"; |
50 | 47 | import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/remoteRegistration"; |
51 | 48 | import { enqueueThreadOutboxMessage, removeThreadOutboxMessage } from "../../state/thread-outbox"; |
@@ -103,6 +100,10 @@ export function NewTaskDraftScreen(props: { |
103 | 100 | const promptInputRef = useRef<ComposerEditorHandle>(null); |
104 | 101 | const loadedBranchesProjectKeyRef = useRef<string | null>(null); |
105 | 102 | const [isComposerFocused, setIsComposerFocused] = useState(false); |
| 103 | + const settingsSheetPresentation = useThreadSettingsSheetPresentation({ |
| 104 | + editorRef: promptInputRef, |
| 105 | + isEditorFocused: isComposerFocused, |
| 106 | + }); |
106 | 107 | const [importingShareKey, setImportingShareKey] = useState<string | null>(null); |
107 | 108 | const [isCancellingShareImport, setIsCancellingShareImport] = useState(false); |
108 | 109 | const [cancelledIncomingShareId, setCancelledIncomingShareId] = useState<string | null>(null); |
@@ -548,7 +549,15 @@ export function NewTaskDraftScreen(props: { |
548 | 549 |
|
549 | 550 | let focusFrame: ReturnType<typeof requestAnimationFrame> | null = null; |
550 | 551 | const interaction = InteractionManager.runAfterInteractions(() => { |
551 | | - focusFrame = requestAnimationFrame(() => promptInputRef.current?.focus()); |
| 552 | + focusFrame = requestAnimationFrame(() => { |
| 553 | + // The delayed focus can land after the settings sheet opened, which |
| 554 | + // would pop the keyboard underneath its modal. |
| 555 | + if (!settingsSheetPresentation.isActiveRef.current) { |
| 556 | + promptInputRef.current?.focus(); |
| 557 | + } else { |
| 558 | + settingsSheetPresentation.restoreFocusAfterSave(); |
| 559 | + } |
| 560 | + }); |
552 | 561 | }); |
553 | 562 |
|
554 | 563 | return () => { |
@@ -557,7 +566,11 @@ export function NewTaskDraftScreen(props: { |
557 | 566 | cancelAnimationFrame(focusFrame); |
558 | 567 | } |
559 | 568 | }; |
560 | | - }, [selectedProject]); |
| 569 | + }, [ |
| 570 | + selectedProject, |
| 571 | + settingsSheetPresentation.isActiveRef, |
| 572 | + settingsSheetPresentation.restoreFocusAfterSave, |
| 573 | + ]); |
561 | 574 |
|
562 | 575 | const environmentMenuActions = useMemo( |
563 | 576 | () => |
@@ -571,10 +584,6 @@ export function NewTaskDraftScreen(props: { |
571 | 584 | [flow.environments, flow.selectedEnvironmentId, isIncomingShareTransferPending], |
572 | 585 | ); |
573 | 586 |
|
574 | | - const modelMenuActions = useMemo( |
575 | | - () => buildModelMenuActions(flow.providerGroups, flow.selectedModel), |
576 | | - [flow.providerGroups, flow.selectedModel], |
577 | | - ); |
578 | 587 | const providerOptionDescriptors = useMemo( |
579 | 588 | () => |
580 | 589 | resolveProviderOptionDescriptors({ |
@@ -584,54 +593,6 @@ export function NewTaskDraftScreen(props: { |
584 | 593 | [flow.selectedModel?.options, flow.selectedModelOption?.capabilities], |
585 | 594 | ); |
586 | 595 |
|
587 | | - const optionsMenuActions = useMemo( |
588 | | - () => [ |
589 | | - ...buildProviderOptionMenuActions(providerOptionDescriptors), |
590 | | - { |
591 | | - id: "options-runtime", |
592 | | - title: "Runtime", |
593 | | - subtitle: |
594 | | - flow.runtimeMode === "approval-required" |
595 | | - ? "Approve actions" |
596 | | - : flow.runtimeMode === "auto-accept-edits" |
597 | | - ? "Auto-accept edits" |
598 | | - : flow.runtimeMode === "auto" |
599 | | - ? "Auto" |
600 | | - : "Full access", |
601 | | - subactions: [ |
602 | | - { id: "options:runtime:approval-required", title: "Approve actions" }, |
603 | | - { id: "options:runtime:auto-accept-edits", title: "Auto-accept edits" }, |
604 | | - { id: "options:runtime:auto", title: "Auto" }, |
605 | | - { id: "options:runtime:full-access", title: "Full access" }, |
606 | | - ].map((option) => { |
607 | | - const value = option.id.replace("options:runtime:", ""); |
608 | | - return { |
609 | | - id: option.id, |
610 | | - title: option.title, |
611 | | - state: flow.runtimeMode === value ? ("on" as const) : undefined, |
612 | | - }; |
613 | | - }), |
614 | | - }, |
615 | | - { |
616 | | - id: "options-interaction", |
617 | | - title: "Interaction", |
618 | | - subtitle: flow.interactionMode === "plan" ? "Plan" : "Default", |
619 | | - subactions: [ |
620 | | - { id: "options:interaction:default", title: "Default" }, |
621 | | - { id: "options:interaction:plan", title: "Plan" }, |
622 | | - ].map((option) => { |
623 | | - const value = option.id.replace("options:interaction:", ""); |
624 | | - return { |
625 | | - id: option.id, |
626 | | - title: option.title, |
627 | | - state: flow.interactionMode === value ? ("on" as const) : undefined, |
628 | | - }; |
629 | | - }), |
630 | | - }, |
631 | | - ], |
632 | | - [flow.interactionMode, flow.runtimeMode, providerOptionDescriptors], |
633 | | - ); |
634 | | - |
635 | 596 | const workspaceMenuActions = useMemo(() => { |
636 | 597 | const branchActions = |
637 | 598 | flow.availableBranches.length === 0 |
@@ -702,10 +663,12 @@ export function NewTaskDraftScreen(props: { |
702 | 663 | flow.availableBranches.find((branch) => branch.current)?.name ?? |
703 | 664 | flow.availableBranches.find((branch) => branch.isDefault)?.name ?? |
704 | 665 | null; |
705 | | - const configurationLabel = useMemo( |
706 | | - () => providerOptionsConfigurationLabel(providerOptionDescriptors), |
707 | | - [providerOptionDescriptors], |
708 | | - ); |
| 666 | + const settingsSummaryLabel = threadSettingsSummaryLabel({ |
| 667 | + modelLabel: flow.selectedModelOption?.label ?? "Model", |
| 668 | + optionDescriptors: providerOptionDescriptors, |
| 669 | + runtimeMode: flow.runtimeMode, |
| 670 | + interactionMode: flow.interactionMode, |
| 671 | + }); |
709 | 672 | const workspaceLabel = useMemo( |
710 | 673 | () => |
711 | 674 | formatWorkspaceLabel({ |
@@ -715,42 +678,13 @@ export function NewTaskDraftScreen(props: { |
715 | 678 | }), |
716 | 679 | [currentBranchName, flow.selectedBranchName, flow.workspaceMode], |
717 | 680 | ); |
718 | | - function handleModelMenuAction(event: string) { |
719 | | - if (isIncomingShareTransferPending || !event.startsWith("model:")) { |
720 | | - return; |
721 | | - } |
722 | | - flow.setSelectedModelKey(event.slice("model:".length)); |
723 | | - } |
724 | | - |
725 | 681 | function handleEnvironmentMenuAction(event: string) { |
726 | 682 | if (isIncomingShareTransferPending || !event.startsWith("environment:")) { |
727 | 683 | return; |
728 | 684 | } |
729 | 685 | flow.selectEnvironment(EnvironmentId.make(event.slice("environment:".length))); |
730 | 686 | } |
731 | 687 |
|
732 | | - function handleOptionsMenuAction(event: string) { |
733 | | - if (isIncomingShareTransferPending) { |
734 | | - return; |
735 | | - } |
736 | | - const providerOptions = applyProviderOptionMenuEvent(providerOptionDescriptors, event); |
737 | | - if (providerOptions) { |
738 | | - flow.setSelectedModelOptions(providerOptions); |
739 | | - return; |
740 | | - } |
741 | | - if (event.startsWith("options:runtime:")) { |
742 | | - flow.setRuntimeMode( |
743 | | - event.slice("options:runtime:".length) as Parameters<typeof flow.setRuntimeMode>[0], |
744 | | - ); |
745 | | - return; |
746 | | - } |
747 | | - if (event.startsWith("options:interaction:")) { |
748 | | - flow.setInteractionMode( |
749 | | - event.slice("options:interaction:".length) as Parameters<typeof flow.setInteractionMode>[0], |
750 | | - ); |
751 | | - } |
752 | | - } |
753 | | - |
754 | 688 | function handleWorkspaceMenuAction(event: string) { |
755 | 689 | if (isIncomingShareTransferPending) { |
756 | 690 | return; |
@@ -947,7 +881,9 @@ export function NewTaskDraftScreen(props: { |
947 | 881 | const isDarkMode = colorScheme === "dark"; |
948 | 882 | // Android expansion follows native editor focus so relayout cannot race |
949 | 883 | // the touch gesture that opens the keyboard. |
950 | | - const isExpanded = !isAndroid || isComposerFocused; |
| 884 | + // The settings sheet dismisses the keyboard, so its flag keeps the Android |
| 885 | + // draft composer expanded through the blur (mirrors ThreadComposer). |
| 886 | + const isExpanded = !isAndroid || isComposerFocused || settingsSheetPresentation.isActive; |
951 | 887 | const canStart = |
952 | 888 | Boolean(flow.selectedProject) && |
953 | 889 | Boolean(flow.selectedModel) && |
@@ -1001,28 +937,14 @@ export function NewTaskDraftScreen(props: { |
1001 | 937 | showChevron={false} |
1002 | 938 | disabled={isIncomingShareTransferPending} |
1003 | 939 | /> |
1004 | | - <ControlPillMenu |
1005 | | - actions={modelMenuActions} |
1006 | | - onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)} |
1007 | | - > |
1008 | | - <ComposerToolbarTrigger |
1009 | | - accessibilityLabel="Model" |
1010 | | - disabled={isIncomingShareTransferPending} |
1011 | | - iconNode={<ProviderIcon provider={flow.selectedModelOption?.providerDriver} size={16} />} |
1012 | | - label={flow.selectedModelOption?.label ?? "Model"} |
1013 | | - /> |
1014 | | - </ControlPillMenu> |
1015 | | - <ControlPillMenu |
1016 | | - actions={optionsMenuActions} |
1017 | | - onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)} |
1018 | | - > |
1019 | | - <ComposerToolbarTrigger |
1020 | | - accessibilityLabel="Configuration" |
1021 | | - disabled={isIncomingShareTransferPending} |
1022 | | - icon="slider.horizontal.3" |
1023 | | - label={configurationLabel} |
1024 | | - /> |
1025 | | - </ControlPillMenu> |
| 940 | + <ComposerToolbarTrigger |
| 941 | + accessibilityLabel="Thread settings" |
| 942 | + disabled={isIncomingShareTransferPending} |
| 943 | + iconNode={<ProviderIcon provider={flow.selectedModelOption?.providerDriver} size={16} />} |
| 944 | + label={settingsSummaryLabel} |
| 945 | + maxWidth={320} |
| 946 | + onPress={settingsSheetPresentation.open} |
| 947 | + /> |
1026 | 948 | <ControlPillMenu |
1027 | 949 | actions={environmentMenuActions} |
1028 | 950 | onPressAction={({ nativeEvent }) => handleEnvironmentMenuAction(nativeEvent.event)} |
@@ -1048,6 +970,21 @@ export function NewTaskDraftScreen(props: { |
1048 | 970 | </> |
1049 | 971 | ); |
1050 | 972 |
|
| 973 | + const settingsSheet = ( |
| 974 | + <ThreadSettingsSheet |
| 975 | + visible={settingsSheetPresentation.isVisible} |
| 976 | + onClose={settingsSheetPresentation.close} |
| 977 | + onDismissed={settingsSheetPresentation.onDismissed} |
| 978 | + providerGroups={flow.providerGroups} |
| 979 | + selectedModel={flow.selectedModel} |
| 980 | + onSelectModel={(option) => flow.setSelectedModelKey(option.key, option.selection.options)} |
| 981 | + optionDescriptors={providerOptionDescriptors} |
| 982 | + onUpdateOptionSelections={flow.setSelectedModelOptions} |
| 983 | + runtimeMode={flow.runtimeMode} |
| 984 | + onUpdateRuntimeMode={flow.setRuntimeMode} |
| 985 | + /> |
| 986 | + ); |
| 987 | + |
1051 | 988 | const startButton = ( |
1052 | 989 | <ComposerToolbarButton |
1053 | 990 | accessibilityLabel={ |
@@ -1137,6 +1074,7 @@ export function NewTaskDraftScreen(props: { |
1137 | 1074 | ) : null} |
1138 | 1075 | </View> |
1139 | 1076 | </KeyboardAvoidingView> |
| 1077 | + {settingsSheet} |
1140 | 1078 | </View> |
1141 | 1079 | ); |
1142 | 1080 | } |
@@ -1170,6 +1108,7 @@ export function NewTaskDraftScreen(props: { |
1170 | 1108 | </ComposerToolbarRow> |
1171 | 1109 | </View> |
1172 | 1110 | </KeyboardAvoidingView> |
| 1111 | + {settingsSheet} |
1173 | 1112 | </View> |
1174 | 1113 | ); |
1175 | 1114 | } |