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 ,
@@ -3909,6 +3934,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
39093934 ) ;
39103935 } else {
39113936 setPrompt ( next . text ) ;
3937+ onTypingGuardDraftChange ( ) ;
39123938 }
39133939 setComposerCursor ( nextCursor ) ;
39143940 setComposerTrigger (
@@ -3931,6 +3957,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
39313957 activePendingUserInput ,
39323958 isLiteralPendingAnswer ,
39333959 onChangeActivePendingUserInputCustomAnswer ,
3960+ onTypingGuardDraftChange ,
39343961 promptRef ,
39353962 setPrompt ,
39363963 setComposerTrigger ,
@@ -4269,6 +4296,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
42694296 } ) ;
42704297 setComposerSubmissionError ( submission . validationMessage ) ;
42714298 if ( ! submission . didDispatch ) return ;
4299+ onTypingGuardSend ( ) ;
42724300 if ( shouldBlurMobileComposerOnSubmit ( ) ) {
42734301 blurMobileComposerAfterSend ( ) ;
42744302 }
@@ -4277,6 +4305,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
42774305 activeThreadId ,
42784306 activePendingProgress ,
42794307 attachmentTargetKey ,
4308+ onTypingGuardSend ,
42804309 blurMobileComposerAfterSend ,
42814310 environmentId ,
42824311 isSendDisabled ,
@@ -6532,6 +6561,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
65326561 } ) ;
65336562 } ,
65346563 getSendContext : ( ) => ( {
6564+ answeringPendingUserInput : activePendingProgress !== null ,
65356565 prompt : promptRef . current ,
65366566 images : composerImagesRef . current ,
65376567 files : composerFilesRef . current ,
@@ -6578,6 +6608,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
65786608 foldPastedText ,
65796609 composerDraftTarget ,
65806610 composerCursor ,
6611+ activePendingProgress ,
65816612 composerTerminalContexts ,
65826613 insertComposerDraftTerminalContext ,
65836614 insertComposerText ,
@@ -6652,6 +6683,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
66526683 } }
66536684 onFocusCapture = { ( event ) => {
66546685 const activeElement = event . target ;
6686+ if (
6687+ activeElement instanceof Element &&
6688+ activeElement . closest ( '[data-testid="composer-editor"]' )
6689+ ) {
6690+ onTypingGuardFocus ( ) ;
6691+ }
66556692 if ( composerControlsCollapsed && isInsideRestingComposerControlScope ( activeElement ) ) {
66566693 return ;
66576694 }
@@ -6670,7 +6707,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
66706707 }
66716708 setIsComposerFocused ( true ) ;
66726709 } }
6673- onBlurCapture = { ( ) => {
6710+ onBlurCapture = { ( event ) => {
6711+ if (
6712+ event . target instanceof Element &&
6713+ event . target . closest ( '[data-testid="composer-editor"]' )
6714+ ) {
6715+ onTypingGuardBlur ( ) ;
6716+ }
66746717 scheduleComposerCollapseCheck ( ) ;
66756718 } }
66766719 onDragEnterCapture = { ( event ) => {
0 commit comments