@@ -26,8 +26,10 @@ import {
2626 api ,
2727 write ,
2828 attachmentURL ,
29+ attachmentThumbnailURL ,
2930 parseReply ,
3031 collectArtifacts ,
32+ messageOffset ,
3133 visibleText ,
3234 elapsedSeconds ,
3335 formatElapsed ,
@@ -114,6 +116,7 @@ const environmentVisibilityKey = "agentflow.native-chat.environmentVisibility.v1
114116const sessionApprovalScope = ( { id, projectId } ) => `approval.session:${ JSON . stringify ( [ id , projectId || "" ] ) } ` ;
115117const draftApprovalScope = ( slot , projectId ) =>
116118 slot . startsWith ( "issue:" ) ? `approval.${ JSON . stringify ( [ slot , projectId ] ) } ` : `approval.${ slot } ` ;
119+ const maxMessageAttachments = 8 ;
117120const draftSnapshot = ( { text, attachments, references } ) => JSON . stringify ( { text, attachments, references } ) ;
118121const sidebarWidthKey = "agentflow.sidebarWidth" ;
119122const sidebarLayoutKey = "agentflow.sidebarLayoutVersion" ;
@@ -236,19 +239,20 @@ function copiedReply(message, generation, live) {
236239 }
237240 return reply ;
238241}
239- function ReplyHeading ( { message, steps } ) {
242+ function ReplyHeading ( { message, steps, deferredActivity } ) {
240243 return (
241244 < div className = "reply-heading" >
242245 < ActivityTrace
243246 steps = { steps }
244247 startedAt = { message . startedAt }
245248 finishedAt = { message . createdAt }
246249 interrupted = { ! ! message . unfinished }
250+ deferredActivity = { deferredActivity }
247251 />
248252 </ div >
249253 ) ;
250254}
251- function AssistantTurn ( { message, steps, assets, projectId, sessionId, local, readOnly, onCLIInstall } ) {
255+ function AssistantTurn ( { message, steps, deferredActivity , assets, projectId, sessionId, local, readOnly, onCLIInstall } ) {
252256 const reply = parseReply ( message ) ;
253257 const answer = hasTextSegments ( steps )
254258 ? finalReply ( reply . message , steps )
@@ -282,12 +286,13 @@ function AssistantTurn({ message, steps, assets, projectId, sessionId, local, re
282286 steps = { steps }
283287 startedAt = { message . startedAt }
284288 finishedAt = { message . createdAt }
289+ deferredActivity = { deferredActivity }
285290 knowledgeReads = { message . knowledgeReads }
286291 knowledgeSummary = { knowledgeSummary }
287292 onCitationClick = { handleCitationClick }
288293 />
289294 ) : (
290- < ReplyHeading message = { message } steps = { steps } />
295+ < ReplyHeading message = { message } steps = { steps } deferredActivity = { deferredActivity } />
291296 ) }
292297 < div className = "message-body" >
293298 < RichContent
@@ -516,8 +521,14 @@ export default function App() {
516521 draftOrigin = useRef ( null ) ,
517522 savingDraftApproval = useRef ( null ) ,
518523 previousArtifacts = useRef ( { id : null , ids : new Set ( ) , baselined : false } ) ,
519- dialogInput = useRef ( ) ,
520- composerPreviews = useRef ( new Map ( ) ) ;
524+ dialogInput = useRef ( ) ;
525+ const previews = useMemo ( ( ) => ( { uploaded : new Map ( ) , pending : new Set ( ) } ) , [ chat . user ?. id ] ) ;
526+ useEffect ( ( ) => ( ) => {
527+ for ( const url of previews . uploaded . values ( ) ) URL . revokeObjectURL ( url ) ;
528+ for ( const url of previews . pending ) URL . revokeObjectURL ( url ) ;
529+ previews . uploaded . clear ( ) ;
530+ previews . pending . clear ( ) ;
531+ } , [ previews ] ) ;
521532 // A requirement handed over by the workbench drafts in its own slot so the
522533 // project's unsent new-conversation draft and attachments stay untouched.
523534 const newDraftSlot = issueDraft && issueDraft . projectId === chat . projectId ? "issue:" + issueDraft . issueId : "new:" + chat . projectId ;
@@ -717,6 +728,14 @@ export default function App() {
717728 url . searchParams . delete ( "quickAccess" ) ;
718729 history . replaceState ( history . state , "" , url ) ;
719730 }
731+ // The workbench lifts its toasts over the composer only when the composer
732+ // sits at the bottom (an open conversation). On the home page the composer
733+ // is centred and grows downward, so a lifted toast would land on 发送.
734+ const layout = chat . activeId ? "conversation" : "home" ;
735+ useEffect ( ( ) => {
736+ if ( window . parent !== window )
737+ window . parent . postMessage ( { type : "agentflow-chat-layout" , layout } , location . origin ) ;
738+ } , [ layout ] ) ;
720739 useEffect ( ( ) => {
721740 const wide = sidebarViewport ( ) . matchMedia ( "(min-width:1001px)" ) ;
722741 const apply = ( ) => setSidebarWidth ( readSidebarWidth ( ) ) ;
@@ -873,6 +892,10 @@ export default function App() {
873892 previousArtifacts . current = previous ;
874893 }
875894 if ( ! chat . activeId || chat . session ?. id !== chat . activeId ) return ;
895+ // A view=recent tail is still part of restoring the conversation. The
896+ // full transcript adds the artifacts of earlier turns, which are not new,
897+ // so the first complete snapshot is the baseline, as for any other open.
898+ if ( chat . session . messagesPartial ) return ;
876899 const entries = [ ...sidebarArtifacts , ...conversationRuns ] ;
877900 const addedEntries = previous . baselined
878901 ? entries . filter ( ( entry ) => ! previous . ids . has ( entry . id ) ) : [ ] ;
@@ -911,6 +934,7 @@ export default function App() {
911934 } , [
912935 chat . activeId ,
913936 chat . session ?. id ,
937+ chat . session ?. messagesPartial ,
914938 artifactList ,
915939 conversationRuns ,
916940 panel ,
@@ -991,7 +1015,7 @@ export default function App() {
9911015 closeMenu ( ) ;
9921016 }
9931017 async function submit ( ) {
994- if ( ! hasComposerExecutor || uploading || composerLoading || draftReady . current !== draftKey ||
1018+ if ( ! chat . ready || ! hasComposerExecutor || uploading || composerLoading || draftReady . current !== draftKey ||
9951019 ( ! chat . activeId && savingDraftApproval . current ) ) return ;
9961020 follow . current = true ;
9971021 const snapshot = draftSnapshot ( { text, attachments, references } ) ;
@@ -1019,12 +1043,10 @@ export default function App() {
10191043 if ( ok ) {
10201044 const clearedDraft = clearDraftIfUnchanged ( draftKey , snapshot ) ;
10211045 if ( clearedDraft && savedDraftKey ) clearDraftApproval ( draftApproval . scope , savedApprovalMode ) ;
1022- let clearedVisible = clearedDraft && visible . key === draftKey ;
10231046 if ( copiedFrom ?. snapshot === snapshot && / ^ ( n e w | i s s u e ) : / . test ( copiedFrom . slot ) ) {
10241047 const originKey = draftKeyPrefix + copiedFrom . slot ;
10251048 if ( clearDraftIfUnchanged ( originKey , snapshot ) ) {
10261049 if ( copiedFrom . approvalScope ) clearDraftApproval ( copiedFrom . approvalScope , copiedFrom . mode ) ;
1027- clearedVisible ||= visible . key === originKey ;
10281050 }
10291051 }
10301052 if ( ! clearedDraft && copiedFrom ) {
@@ -1039,10 +1061,6 @@ export default function App() {
10391061 persistDraft ( draftKey , { text, attachments, references } ) ;
10401062 }
10411063 }
1042- for ( const attachment of attachments ) {
1043- if ( clearedVisible || ! visible . attachments . some ( ( current ) => current . id === attachment . id ) )
1044- releaseComposerPreview ( attachment . id ) ;
1045- }
10461064 } else if ( visible . key === savedDraftKey && draftReady . current === savedDraftKey &&
10471065 ! visible . text && ! visible . attachments . length && ! visible . references . length ) {
10481066 // The session was saved but the first message was rejected. Keep its
@@ -1074,23 +1092,23 @@ export default function App() {
10741092 }
10751093 function composerPreviewURL ( a ) {
10761094 return (
1077- composerPreviews . current . get ( a . id ) ||
1095+ previews . uploaded . get ( a . id ) ||
10781096 attachmentURL ( a , chat . session ?. id || chat . activeId || "" )
10791097 ) ;
10801098 }
1081- function releaseComposerPreview ( id ) {
1082- const url = composerPreviews . current . get ( id ) ;
1099+ function releaseUploadedPreview ( id ) {
1100+ const url = previews . uploaded . get ( id ) ;
10831101 if ( ! url ) return ;
10841102 URL . revokeObjectURL ( url ) ;
1085- composerPreviews . current . delete ( id ) ;
1103+ previews . uploaded . delete ( id ) ;
10861104 }
10871105 function removeAttachment ( a ) {
1088- releaseComposerPreview ( a . id ) ;
1106+ releaseUploadedPreview ( a . id ) ;
10891107 setAttachments ( ( old ) => old . filter ( ( x ) => x . id !== a . id ) ) ;
10901108 }
10911109 async function upload ( files ) {
10921110 if ( ! files . length ) return ;
1093- if ( files . length + attachments . length > 8 ) {
1111+ if ( files . length + attachments . length > maxMessageAttachments ) {
10941112 chat . setError ( "每轮最多上传 8 个文件。" ) ;
10951113 return ;
10961114 }
@@ -1114,7 +1132,10 @@ export default function App() {
11141132 previewURL,
11151133 }
11161134 : null ;
1117- if ( slot ) setPendingAttachments ( ( old ) => [ ...old , slot ] ) ;
1135+ if ( slot ) {
1136+ previews . pending . add ( previewURL ) ;
1137+ setPendingAttachments ( ( old ) => [ ...old , slot ] ) ;
1138+ }
11181139 try {
11191140 if ( chat . local ) {
11201141 const localDataUrl = await new Promise ( ( resolve , reject ) => {
@@ -1140,10 +1161,18 @@ export default function App() {
11401161 method : "POST" ,
11411162 body,
11421163 } ) ;
1143- if ( previewURL ) composerPreviews . current . set ( uploaded . id , previewURL ) ;
1164+ if ( previewURL ) {
1165+ // A disposed view already revoked its pending URLs.
1166+ if ( ! previews . pending . delete ( previewURL ) ) return ;
1167+ // Keep a full turn of recent screenshots through optimistic sends
1168+ // and transcript refreshes, without persisting browser-local URLs.
1169+ if ( previews . uploaded . size >= maxMessageAttachments )
1170+ releaseUploadedPreview ( previews . uploaded . keys ( ) . next ( ) . value ) ;
1171+ previews . uploaded . set ( uploaded . id , previewURL ) ;
1172+ }
11441173 results . push ( uploaded ) ;
11451174 } catch ( err ) {
1146- if ( previewURL ) URL . revokeObjectURL ( previewURL ) ;
1175+ if ( previews . pending . delete ( previewURL ) ) URL . revokeObjectURL ( previewURL ) ;
11471176 throw err ;
11481177 } finally {
11491178 if ( slot )
@@ -1321,6 +1350,8 @@ export default function App() {
13211350 } ) ) ;
13221351 } , [ chat . activeId , chat . projectId ] ) ;
13231352 const messages = chat . session ?. messages || [ ] ;
1353+ // Stored index of messages[0]; artifacts name messages by that index.
1354+ const messageBase = messageOffset ( chat . session ) ;
13241355 const conversationStarted = Boolean (
13251356 chat . activeId && chat . session ?. id === chat . activeId &&
13261357 ( messages . length || chat . busy || sidebarArtifacts . length || conversationRuns . length ) ,
@@ -2282,6 +2313,7 @@ export default function App() {
22822313 scroll = { scroll }
22832314 follow = { follow }
22842315 loading = { ! chat . session && ! chat . error }
2316+ earlier = { ! ! chat . session ?. messagesPartial }
22852317 renderMessage = { ( message , index ) =>
22862318 isProposalTimeout ( message , messages [ index - 1 ] ) ? null : confirmationCaption ( message , messages [ index - 1 ] ) ? (
22872319 < div
@@ -2301,6 +2333,10 @@ export default function App() {
23012333 { message . role === "assistant" ? (
23022334 < AssistantTurn
23032335 message = { message }
2336+ deferredActivity = { message . activityRef ? {
2337+ sessionId : chat . session . id , index : messageBase + index ,
2338+ activityRef : message . activityRef , loadActivity : chat . loadActivity ,
2339+ } : null }
23042340 steps = { activityForReply (
23052341 message ,
23062342 chat . generation ,
@@ -2356,7 +2392,7 @@ export default function App() {
23562392 < >
23572393 < IconButton
23582394 label = "编辑消息"
2359- disabled = { chat . busy }
2395+ disabled = { chat . busy || ! ! chat . session ?. messagesPartial }
23602396 onClick = { ( ) =>
23612397 setDialog ( {
23622398 type : "edit" ,
@@ -2370,7 +2406,7 @@ export default function App() {
23702406 </ IconButton >
23712407 < IconButton
23722408 label = "从此处创建分支"
2373- disabled = { chat . busy }
2409+ disabled = { chat . busy || ! ! chat . session ?. messagesPartial }
23742410 onClick = { ( ) =>
23752411 setDialog ( {
23762412 type : "edit" ,
@@ -2398,6 +2434,7 @@ export default function App() {
23982434 < Attachment
23992435 key = { a . id }
24002436 attachment = { a }
2437+ localPreviewURL = { previews . uploaded . get ( a . id ) }
24012438 sessionId = { chat . session . id }
24022439 onOpen = { openArtifact }
24032440 />
@@ -2408,7 +2445,7 @@ export default function App() {
24082445 < >
24092446 < div className = "message-drafts" >
24102447 { artifactList
2411- . filter ( ( a ) => a . draft && a . messageIndex === index )
2448+ . filter ( ( a ) => a . draft && a . messageIndex === messageBase + index )
24122449 . map ( ( a ) => (
24132450 < DraftCard
24142451 key = { a . id }
@@ -2636,7 +2673,7 @@ export default function App() {
26362673 setImagePreview ( { src : url , name : a . name } )
26372674 }
26382675 >
2639- < img src = { url } alt = { a . name } />
2676+ < img src = { attachmentThumbnailURL ( url , a . mimeType ) } alt = { a . name } />
26402677 </ button >
26412678 < button
26422679 type = "button"
@@ -2846,6 +2883,7 @@ export default function App() {
28462883 title = { chat . busy ? "当前回复结束后自动发送" : undefined }
28472884 disabled = {
28482885 ! chat . ready ||
2886+ ! ! chat . session ?. messagesPartial ||
28492887 ! hasComposerExecutor ||
28502888 ! ! chat . missingServerCLI ||
28512889 chat . submitting ||
0 commit comments