11import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills" ;
2+ import { useComposerTypingGuard } from "./useComposerTypingGuard" ;
23import { DESKTOP_PASTE_AS_TEXT_EVENT } from "../../lib/desktopPasteAsText" ;
34import { runtimeModeConfig , runtimeModeOptions as runtimeModes } from "./runtimeModeConfig" ;
45import { isLocalEnvironmentDisabled } from "../../localEnvironment" ;
@@ -1485,6 +1486,7 @@ export interface ChatComposerHandle {
14851486 addTerminalContext : ( selection : TerminalContextSelection ) => void ;
14861487 /** Get the current prompt/effort/model state for use in send. */
14871488 getSendContext : ( ) => {
1489+ answeringPendingUserInput : boolean ;
14881490 prompt : string ;
14891491 images : ComposerImageAttachment [ ] ;
14901492 files : ComposerFileAttachment [ ] ;
@@ -1737,12 +1739,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
17371739 sendDisabledReason : externalSendDisabledReason ,
17381740 isPreparingWorktree,
17391741 environmentUnavailable,
1740- activePendingApproval,
1742+ activePendingApproval : incomingPendingApproval ,
17411743 pendingApprovals,
1742- pendingUserInputs,
1743- activePendingProgress,
1744+ pendingUserInputs : incomingPendingUserInputs ,
1745+ activePendingProgress : incomingPendingProgress ,
17441746 activePendingResolvedAnswers,
1745- activePendingIsResponding,
1747+ activePendingIsResponding : incomingPendingIsResponding ,
17461748 activePendingDraftAnswers,
17471749 activePendingQuestionIndex,
17481750 respondingRequestIds,
@@ -1808,9 +1810,30 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
18081810 editingQueuedAttachments,
18091811 onRemoveEditingQueuedAttachment,
18101812 } = props ;
1811- const isLiteralPendingAnswer = activePendingProgress ?. activeQuestion ?. initialAnswer !== undefined ;
18121813 const primaryEnvironmentId = usePrimaryEnvironmentId ( ) ;
18131814 const composerDraftTargetKey = composerTargetKey ( composerDraftTarget ) ;
1815+ const {
1816+ heldRequestIds,
1817+ onDraftChange : onTypingGuardDraftChange ,
1818+ onFocus : onTypingGuardFocus ,
1819+ onBlur : onTypingGuardBlur ,
1820+ onSend : onTypingGuardSend ,
1821+ } = useComposerTypingGuard ( composerDraftTargetKey , [
1822+ ...pendingApprovals . map ( ( request ) => request . requestId ) ,
1823+ ...incomingPendingUserInputs . map ( ( request ) => request . requestId ) ,
1824+ ] ) ;
1825+ // Hold composer takeover while the user finishes their thread draft.
1826+ const activePendingApproval =
1827+ incomingPendingApproval && ! heldRequestIds . has ( incomingPendingApproval . requestId )
1828+ ? incomingPendingApproval
1829+ : null ;
1830+ const holdingUserInput = incomingPendingUserInputs [ 0 ]
1831+ ? heldRequestIds . has ( incomingPendingUserInputs [ 0 ] . requestId )
1832+ : false ;
1833+ const pendingUserInputs = holdingUserInput ? [ ] : incomingPendingUserInputs ;
1834+ const activePendingProgress = holdingUserInput ? null : incomingPendingProgress ;
1835+ const activePendingIsResponding = ! holdingUserInput && incomingPendingIsResponding ;
1836+ const isLiteralPendingAnswer = activePendingProgress ?. activeQuestion ?. initialAnswer !== undefined ;
18141837 // Opening a running thread resyncs for a few frames. Show the sync row, and
18151838 // hide the tasks row for it, only when the sync lasts. Logic that depends on
18161839 // the real phase keeps reading `props.threadSyncPhase`.
@@ -3712,6 +3735,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
37123735 ) ;
37133736 return ;
37143737 }
3738+ onTypingGuardDraftChange ( ) ;
37153739 promptRef . current = nextPrompt ;
37163740 setPrompt ( nextPrompt ) ;
37173741 // Any edit ends browsing, even one later undone by hand: typing a
@@ -3818,6 +3842,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
38183842 [
38193843 activePendingProgress ?. activeQuestion ,
38203844 expandComposerForEditorChange ,
3845+ onTypingGuardDraftChange ,
38213846 pendingUserInputs . length ,
38223847 onChangeActivePendingUserInputCustomAnswer ,
38233848 promptRef ,
@@ -4269,6 +4294,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
42694294 } ) ;
42704295 setComposerSubmissionError ( submission . validationMessage ) ;
42714296 if ( ! submission . didDispatch ) return ;
4297+ onTypingGuardSend ( ) ;
42724298 if ( shouldBlurMobileComposerOnSubmit ( ) ) {
42734299 blurMobileComposerAfterSend ( ) ;
42744300 }
@@ -4277,6 +4303,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
42774303 activeThreadId ,
42784304 activePendingProgress ,
42794305 attachmentTargetKey ,
4306+ onTypingGuardSend ,
42804307 blurMobileComposerAfterSend ,
42814308 environmentId ,
42824309 isSendDisabled ,
@@ -6532,6 +6559,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
65326559 } ) ;
65336560 } ,
65346561 getSendContext : ( ) => ( {
6562+ answeringPendingUserInput : activePendingProgress !== null ,
65356563 prompt : promptRef . current ,
65366564 images : composerImagesRef . current ,
65376565 files : composerFilesRef . current ,
@@ -6578,6 +6606,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
65786606 foldPastedText ,
65796607 composerDraftTarget ,
65806608 composerCursor ,
6609+ activePendingProgress ,
65816610 composerTerminalContexts ,
65826611 insertComposerDraftTerminalContext ,
65836612 insertComposerText ,
@@ -6652,6 +6681,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
66526681 } }
66536682 onFocusCapture = { ( event ) => {
66546683 const activeElement = event . target ;
6684+ if (
6685+ activeElement instanceof Element &&
6686+ activeElement . closest ( '[data-testid="composer-editor"]' )
6687+ ) {
6688+ onTypingGuardFocus ( ) ;
6689+ }
66556690 if ( composerControlsCollapsed && isInsideRestingComposerControlScope ( activeElement ) ) {
66566691 return ;
66576692 }
@@ -6670,7 +6705,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
66706705 }
66716706 setIsComposerFocused ( true ) ;
66726707 } }
6673- onBlurCapture = { ( ) => {
6708+ onBlurCapture = { ( event ) => {
6709+ if (
6710+ event . target instanceof Element &&
6711+ event . target . closest ( '[data-testid="composer-editor"]' )
6712+ ) {
6713+ onTypingGuardBlur ( ) ;
6714+ }
66746715 scheduleComposerCollapseCheck ( ) ;
66756716 } }
66766717 onDragEnterCapture = { ( event ) => {
0 commit comments