@@ -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
@@ -514,8 +519,14 @@ export default function App() {
514519 draftOrigin = useRef ( null ) ,
515520 savingDraftApproval = useRef ( null ) ,
516521 previousArtifacts = useRef ( { id : null , ids : new Set ( ) , baselined : false } ) ,
517- dialogInput = useRef ( ) ,
518- composerPreviews = useRef ( new Map ( ) ) ;
522+ dialogInput = useRef ( ) ;
523+ const previews = useMemo ( ( ) => ( { uploaded : new Map ( ) , pending : new Set ( ) } ) , [ chat . user ?. id ] ) ;
524+ useEffect ( ( ) => ( ) => {
525+ for ( const url of previews . uploaded . values ( ) ) URL . revokeObjectURL ( url ) ;
526+ for ( const url of previews . pending ) URL . revokeObjectURL ( url ) ;
527+ previews . uploaded . clear ( ) ;
528+ previews . pending . clear ( ) ;
529+ } , [ previews ] ) ;
519530 // A requirement handed over by the workbench drafts in its own slot so the
520531 // project's unsent new-conversation draft and attachments stay untouched.
521532 const newDraftSlot = issueDraft && issueDraft . projectId === chat . projectId ? "issue:" + issueDraft . issueId : "new:" + chat . projectId ;
@@ -715,6 +726,14 @@ export default function App() {
715726 url . searchParams . delete ( "quickAccess" ) ;
716727 history . replaceState ( history . state , "" , url ) ;
717728 }
729+ // The workbench lifts its toasts over the composer only when the composer
730+ // sits at the bottom (an open conversation). On the home page the composer
731+ // is centred and grows downward, so a lifted toast would land on 发送.
732+ const layout = chat . activeId ? "conversation" : "home" ;
733+ useEffect ( ( ) => {
734+ if ( window . parent !== window )
735+ window . parent . postMessage ( { type : "agentflow-chat-layout" , layout } , location . origin ) ;
736+ } , [ layout ] ) ;
718737 useEffect ( ( ) => {
719738 const wide = sidebarViewport ( ) . matchMedia ( "(min-width:1001px)" ) ;
720739 const apply = ( ) => setSidebarWidth ( readSidebarWidth ( ) ) ;
@@ -858,6 +877,10 @@ export default function App() {
858877 previousArtifacts . current = previous ;
859878 }
860879 if ( ! chat . activeId || chat . session ?. id !== chat . activeId ) return ;
880+ // A view=recent tail is still part of restoring the conversation. The
881+ // full transcript adds the artifacts of earlier turns, which are not new,
882+ // so the first complete snapshot is the baseline, as for any other open.
883+ if ( chat . session . messagesPartial ) return ;
861884 const entries = [ ...sidebarArtifacts , ...conversationRuns ] ;
862885 const addedEntries = previous . baselined
863886 ? entries . filter ( ( entry ) => ! previous . ids . has ( entry . id ) ) : [ ] ;
@@ -896,6 +919,7 @@ export default function App() {
896919 } , [
897920 chat . activeId ,
898921 chat . session ?. id ,
922+ chat . session ?. messagesPartial ,
899923 artifactList ,
900924 conversationRuns ,
901925 panel ,
@@ -976,7 +1000,7 @@ export default function App() {
9761000 closeMenu ( ) ;
9771001 }
9781002 async function submit ( ) {
979- if ( ! hasComposerExecutor || uploading || composerLoading || draftReady . current !== draftKey ||
1003+ if ( ! chat . ready || ! hasComposerExecutor || uploading || composerLoading || draftReady . current !== draftKey ||
9801004 ( ! chat . activeId && savingDraftApproval . current ) ) return ;
9811005 follow . current = true ;
9821006 const snapshot = draftSnapshot ( { text, attachments, references } ) ;
@@ -1004,12 +1028,10 @@ export default function App() {
10041028 if ( ok ) {
10051029 const clearedDraft = clearDraftIfUnchanged ( draftKey , snapshot ) ;
10061030 if ( clearedDraft && savedDraftKey ) clearDraftApproval ( draftApproval . scope , savedApprovalMode ) ;
1007- let clearedVisible = clearedDraft && visible . key === draftKey ;
10081031 if ( copiedFrom ?. snapshot === snapshot && / ^ ( n e w | i s s u e ) : / . test ( copiedFrom . slot ) ) {
10091032 const originKey = draftKeyPrefix + copiedFrom . slot ;
10101033 if ( clearDraftIfUnchanged ( originKey , snapshot ) ) {
10111034 if ( copiedFrom . approvalScope ) clearDraftApproval ( copiedFrom . approvalScope , copiedFrom . mode ) ;
1012- clearedVisible ||= visible . key === originKey ;
10131035 }
10141036 }
10151037 if ( ! clearedDraft && copiedFrom ) {
@@ -1024,10 +1046,6 @@ export default function App() {
10241046 persistDraft ( draftKey , { text, attachments, references } ) ;
10251047 }
10261048 }
1027- for ( const attachment of attachments ) {
1028- if ( clearedVisible || ! visible . attachments . some ( ( current ) => current . id === attachment . id ) )
1029- releaseComposerPreview ( attachment . id ) ;
1030- }
10311049 } else if ( visible . key === savedDraftKey && draftReady . current === savedDraftKey &&
10321050 ! visible . text && ! visible . attachments . length && ! visible . references . length ) {
10331051 // The session was saved but the first message was rejected. Keep its
@@ -1059,23 +1077,23 @@ export default function App() {
10591077 }
10601078 function composerPreviewURL ( a ) {
10611079 return (
1062- composerPreviews . current . get ( a . id ) ||
1080+ previews . uploaded . get ( a . id ) ||
10631081 attachmentURL ( a , chat . session ?. id || chat . activeId || "" )
10641082 ) ;
10651083 }
1066- function releaseComposerPreview ( id ) {
1067- const url = composerPreviews . current . get ( id ) ;
1084+ function releaseUploadedPreview ( id ) {
1085+ const url = previews . uploaded . get ( id ) ;
10681086 if ( ! url ) return ;
10691087 URL . revokeObjectURL ( url ) ;
1070- composerPreviews . current . delete ( id ) ;
1088+ previews . uploaded . delete ( id ) ;
10711089 }
10721090 function removeAttachment ( a ) {
1073- releaseComposerPreview ( a . id ) ;
1091+ releaseUploadedPreview ( a . id ) ;
10741092 setAttachments ( ( old ) => old . filter ( ( x ) => x . id !== a . id ) ) ;
10751093 }
10761094 async function upload ( files ) {
10771095 if ( ! files . length ) return ;
1078- if ( files . length + attachments . length > 8 ) {
1096+ if ( files . length + attachments . length > maxMessageAttachments ) {
10791097 chat . setError ( "每轮最多上传 8 个文件。" ) ;
10801098 return ;
10811099 }
@@ -1099,7 +1117,10 @@ export default function App() {
10991117 previewURL,
11001118 }
11011119 : null ;
1102- if ( slot ) setPendingAttachments ( ( old ) => [ ...old , slot ] ) ;
1120+ if ( slot ) {
1121+ previews . pending . add ( previewURL ) ;
1122+ setPendingAttachments ( ( old ) => [ ...old , slot ] ) ;
1123+ }
11031124 try {
11041125 if ( chat . local ) {
11051126 const localDataUrl = await new Promise ( ( resolve , reject ) => {
@@ -1125,10 +1146,18 @@ export default function App() {
11251146 method : "POST" ,
11261147 body,
11271148 } ) ;
1128- if ( previewURL ) composerPreviews . current . set ( uploaded . id , previewURL ) ;
1149+ if ( previewURL ) {
1150+ // A disposed view already revoked its pending URLs.
1151+ if ( ! previews . pending . delete ( previewURL ) ) return ;
1152+ // Keep a full turn of recent screenshots through optimistic sends
1153+ // and transcript refreshes, without persisting browser-local URLs.
1154+ if ( previews . uploaded . size >= maxMessageAttachments )
1155+ releaseUploadedPreview ( previews . uploaded . keys ( ) . next ( ) . value ) ;
1156+ previews . uploaded . set ( uploaded . id , previewURL ) ;
1157+ }
11291158 results . push ( uploaded ) ;
11301159 } catch ( err ) {
1131- if ( previewURL ) URL . revokeObjectURL ( previewURL ) ;
1160+ if ( previews . pending . delete ( previewURL ) ) URL . revokeObjectURL ( previewURL ) ;
11321161 throw err ;
11331162 } finally {
11341163 if ( slot )
@@ -1306,6 +1335,8 @@ export default function App() {
13061335 } ) ) ;
13071336 } , [ chat . activeId , chat . projectId ] ) ;
13081337 const messages = chat . session ?. messages || [ ] ;
1338+ // Stored index of messages[0]; artifacts name messages by that index.
1339+ const messageBase = messageOffset ( chat . session ) ;
13091340 const conversationStarted = Boolean (
13101341 chat . activeId && chat . session ?. id === chat . activeId &&
13111342 ( messages . length || chat . busy || sidebarArtifacts . length || conversationRuns . length ) ,
@@ -2257,6 +2288,7 @@ export default function App() {
22572288 scroll = { scroll }
22582289 follow = { follow }
22592290 loading = { ! chat . session && ! chat . error }
2291+ earlier = { ! ! chat . session ?. messagesPartial }
22602292 renderMessage = { ( message , index ) =>
22612293 isProposalTimeout ( message , messages [ index - 1 ] ) ? null : confirmationCaption ( message , messages [ index - 1 ] ) ? (
22622294 < div
@@ -2276,6 +2308,10 @@ export default function App() {
22762308 { message . role === "assistant" ? (
22772309 < AssistantTurn
22782310 message = { message }
2311+ deferredActivity = { message . activityRef ? {
2312+ sessionId : chat . session . id , index : messageBase + index ,
2313+ activityRef : message . activityRef , loadActivity : chat . loadActivity ,
2314+ } : null }
22792315 steps = { activityForReply (
22802316 message ,
22812317 chat . generation ,
@@ -2331,7 +2367,7 @@ export default function App() {
23312367 < >
23322368 < IconButton
23332369 label = "编辑消息"
2334- disabled = { chat . busy }
2370+ disabled = { chat . busy || ! ! chat . session ?. messagesPartial }
23352371 onClick = { ( ) =>
23362372 setDialog ( {
23372373 type : "edit" ,
@@ -2345,7 +2381,7 @@ export default function App() {
23452381 </ IconButton >
23462382 < IconButton
23472383 label = "从此处创建分支"
2348- disabled = { chat . busy }
2384+ disabled = { chat . busy || ! ! chat . session ?. messagesPartial }
23492385 onClick = { ( ) =>
23502386 setDialog ( {
23512387 type : "edit" ,
@@ -2373,6 +2409,7 @@ export default function App() {
23732409 < Attachment
23742410 key = { a . id }
23752411 attachment = { a }
2412+ localPreviewURL = { previews . uploaded . get ( a . id ) }
23762413 sessionId = { chat . session . id }
23772414 onOpen = { openArtifact }
23782415 />
@@ -2383,7 +2420,7 @@ export default function App() {
23832420 < >
23842421 < div className = "message-drafts" >
23852422 { artifactList
2386- . filter ( ( a ) => a . draft && a . messageIndex === index )
2423+ . filter ( ( a ) => a . draft && a . messageIndex === messageBase + index )
23872424 . map ( ( a ) => (
23882425 < DraftCard
23892426 key = { a . id }
@@ -2611,7 +2648,7 @@ export default function App() {
26112648 setImagePreview ( { src : url , name : a . name } )
26122649 }
26132650 >
2614- < img src = { url } alt = { a . name } />
2651+ < img src = { attachmentThumbnailURL ( url , a . mimeType ) } alt = { a . name } />
26152652 </ button >
26162653 < button
26172654 type = "button"
@@ -2821,6 +2858,7 @@ export default function App() {
28212858 title = { chat . busy ? "当前回复结束后自动发送" : undefined }
28222859 disabled = {
28232860 ! chat . ready ||
2861+ ! ! chat . session ?. messagesPartial ||
28242862 ! hasComposerExecutor ||
28252863 ! ! chat . missingServerCLI ||
28262864 chat . submitting ||
0 commit comments