@@ -445,6 +445,12 @@ export namespace SessionPrompt {
445445 log . error ( "subtask execution failed" , { error, agent : task . agent , description : task . description } )
446446 return undefined
447447 } )
448+ const attachments = result ?. attachments ?. map ( ( attachment ) => ( {
449+ ...attachment ,
450+ id : Identifier . ascending ( "part" ) ,
451+ sessionID,
452+ messageID : assistantMessage . id ,
453+ } ) )
448454 await Plugin . trigger (
449455 "tool.execute.after" ,
450456 {
@@ -467,7 +473,7 @@ export namespace SessionPrompt {
467473 title : result . title ,
468474 metadata : result . metadata ,
469475 output : result . output ,
470- attachments : result . attachments ,
476+ attachments,
471477 time : {
472478 ...part . state . time ,
473479 end : Date . now ( ) ,
@@ -797,6 +803,15 @@ export namespace SessionPrompt {
797803 } ,
798804 )
799805 const result = await item . execute ( args , ctx )
806+ const output = {
807+ ...result ,
808+ attachments : result . attachments ?. map ( ( attachment ) => ( {
809+ ...attachment ,
810+ id : Identifier . ascending ( "part" ) ,
811+ sessionID : ctx . sessionID ,
812+ messageID : input . processor . message . id ,
813+ } ) ) ,
814+ }
800815 await Plugin . trigger (
801816 "tool.execute.after" ,
802817 {
@@ -805,9 +820,9 @@ export namespace SessionPrompt {
805820 callID : ctx . callID ,
806821 args,
807822 } ,
808- result ,
823+ output ,
809824 )
810- return result
825+ return output
811826 } ,
812827 } )
813828 }
@@ -855,16 +870,13 @@ export namespace SessionPrompt {
855870 )
856871
857872 const textParts : string [ ] = [ ]
858- const attachments : MessageV2 . FilePart [ ] = [ ]
873+ const attachments : Omit < MessageV2 . FilePart , "id" | "sessionID" | "messageID" > [ ] = [ ]
859874
860875 for ( const contentItem of result . content ) {
861876 if ( contentItem . type === "text" ) {
862877 textParts . push ( contentItem . text )
863878 } else if ( contentItem . type === "image" ) {
864879 attachments . push ( {
865- id : Identifier . ascending ( "part" ) ,
866- sessionID : input . session . id ,
867- messageID : input . processor . message . id ,
868880 type : "file" ,
869881 mime : contentItem . mimeType ,
870882 url : `data:${ contentItem . mimeType } ;base64,${ contentItem . data } ` ,
@@ -876,9 +888,6 @@ export namespace SessionPrompt {
876888 }
877889 if ( resource . blob ) {
878890 attachments . push ( {
879- id : Identifier . ascending ( "part" ) ,
880- sessionID : input . session . id ,
881- messageID : input . processor . message . id ,
882891 type : "file" ,
883892 mime : resource . mimeType ?? "application/octet-stream" ,
884893 url : `data:${ resource . mimeType ?? "application/octet-stream" } ;base64,${ resource . blob } ` ,
@@ -1157,6 +1166,7 @@ export namespace SessionPrompt {
11571166 pieces . push (
11581167 ...result . attachments . map ( ( attachment ) => ( {
11591168 ...attachment ,
1169+ id : Identifier . ascending ( "part" ) ,
11601170 synthetic : true ,
11611171 filename : attachment . filename ?? part . filename ,
11621172 messageID : info . id ,
0 commit comments