@@ -55,6 +55,7 @@ import {
5555 setComposerDraftText ,
5656 composerContextImportsAtom ,
5757 countComposerDraftAttachmentsAfterSelection ,
58+ useComposerDraft ,
5859} from "../../state/use-composer-drafts" ;
5960import { appAtomRegistry } from "../../state/atom-registry" ;
6061import type { ComposerDocumentAttachment } from "../../lib/composerContext" ;
@@ -79,7 +80,6 @@ import {
7980import { ProviderIcon } from "../../components/ProviderIcon" ;
8081import {
8182 composerStripAttachments ,
82- type DraftComposerAttachment ,
8383 type DraftComposerFileAttachment ,
8484} from "../../lib/composerImages" ;
8585import {
@@ -130,8 +130,6 @@ export const COMPOSER_EXPANDED_CHROME = 156;
130130
131131export interface ThreadComposerProps {
132132 readonly canOperateThread : boolean ;
133- readonly draftMessage : string ;
134- readonly draftAttachments : ReadonlyArray < DraftComposerAttachment > ;
135133 readonly placeholder : string ;
136134 readonly contentMaxWidth ?: number ;
137135 readonly bottomInset ?: number ;
@@ -349,20 +347,23 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
349347
350348 const [ previewFile , setPreviewFile ] = useState < FilePreviewSource | null > ( null ) ;
351349 const [ previewVideo , setPreviewVideo ] = useState < VideoPreviewSource | null > ( null ) ;
350+ const composerOwnerKey = scopedThreadKey ( props . environmentId , props . selectedThread . id ) ;
351+ const composerDraftKey = props . draftKey ?? composerOwnerKey ;
352+ const { text : draftMessage , attachments : draftAttachments } = useComposerDraft ( composerDraftKey ) ;
352353 const queuedEdit = props . queuedEdit ?? null ;
353354 const hasContent =
354- props . draftMessage . trim ( ) . length > 0 ||
355- props . draftAttachments . length > 0 ||
355+ draftMessage . trim ( ) . length > 0 ||
356+ draftAttachments . length > 0 ||
356357 ( queuedEdit ?. existingAttachments . length ?? 0 ) > 0 ;
357- const stripAttachments = composerStripAttachments ( props . draftAttachments ) ;
358+ const stripAttachments = composerStripAttachments ( draftAttachments ) ;
358359 const showStopAction = ! hasContent && props . canStopThread && queuedEdit === null ;
359360
360361 const uploadStates = useAtomValue ( composerAttachmentUploadsAtom ) ;
361362 const attachmentsUploading =
362363 props . connectionState === "connected" &&
363364 composerAttachmentsStillUploading ( {
364365 environmentId : props . environmentId ,
365- attachments : props . draftAttachments ,
366+ attachments : draftAttachments ,
366367 serverConfig : props . serverConfig ,
367368 states : uploadStates ,
368369 } ) ;
@@ -392,8 +393,6 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
392393 ) ?? null
393394 ) ;
394395 } ) ( ) ;
395- const composerOwnerKey = scopedThreadKey ( props . environmentId , props . selectedThread . id ) ;
396- const composerDraftKey = props . draftKey ?? composerOwnerKey ;
397396 const openDraftDocument = ( attachment : ComposerDocumentAttachment ) => {
398397 Keyboard . dismiss ( ) ;
399398 navigation . navigate ( "ThreadAttachment" , {
@@ -429,7 +428,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
429428 } ;
430429
431430 const composerMenu = useComposerCommandMenu ( {
432- draftMessage : props . draftMessage ,
431+ draftMessage : draftMessage ,
433432 ownerKey : composerOwnerKey ,
434433 environmentId : props . environmentId ,
435434 threadShells : useThreadShells ( ) ,
@@ -450,7 +449,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
450449 : props . onUpdateInteractionMode ,
451450 offersUsageLimits : usageLimitsOffered ,
452451 onUsageLimits :
453- usageLimitsOffered && props . draftAttachments . length === 0 ? openUsageLimits : undefined ,
452+ usageLimitsOffered && draftAttachments . length === 0 ? openUsageLimits : undefined ,
454453 } ) ;
455454 const voiceInput = useVoiceInputController ( {
456455 ownerKey : composerDraftKey ,
@@ -471,7 +470,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
471470 const isToolbarVisible = isExpanded || isVoiceInputPresented ;
472471 const attachmentBlockReason = composerAttachmentUploadBlockReason ( {
473472 environmentId : props . environmentId ,
474- attachments : props . draftAttachments ,
473+ attachments : draftAttachments ,
475474 connected : props . connectionState === "connected" ,
476475 serverConfig : props . serverConfig ,
477476 states : uploadStates ,
@@ -501,7 +500,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
501500 ( current ) =>
502501 current ?? {
503502 ...source ,
504- gallery : filePreviewGallery ( source , composerImageGallery ( props . draftAttachments ) ) ,
503+ gallery : filePreviewGallery ( source , composerImageGallery ( draftAttachments ) ) ,
505504 } ,
506505 ) ;
507506 } ;
@@ -538,11 +537,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
538537 } ;
539538 const handleSend = async ( followUp ?: ActiveTurnComposerAction ) => {
540539 if ( voiceInput . blocksSubmission || pendingPastedTextAttachmentCountRef . current > 0 ) return ;
541- if (
542- usageLimitsOffered &&
543- isUsageLimitsCommand ( props . draftMessage ) &&
544- props . draftAttachments . length === 0
545- ) {
540+ if ( usageLimitsOffered && isUsageLimitsCommand ( draftMessage ) && draftAttachments . length === 0 ) {
546541 if ( openUsageLimits ( ) ) onChangeDraftMessage ( "" ) ;
547542 return ;
548543 }
@@ -808,7 +803,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
808803 onInertChipPress = { ( ) => inputRef . current ?. focus ( ) }
809804 ref = { inputRef }
810805 multiline
811- value = { props . draftMessage }
806+ value = { draftMessage }
812807 readOnly = { voiceInput . freezesEditor }
813808 skills = { composerMenu . skills }
814809 selection = { composerMenu . selection }
0 commit comments