@@ -187,52 +187,47 @@ export namespace SessionPrompt {
187187 text : template ,
188188 } ,
189189 ]
190- const matches = ConfigMarkdown . files ( template )
190+ const files = ConfigMarkdown . files ( template )
191191 const seen = new Set < string > ( )
192- const names = matches
193- . map ( ( match ) => match [ 1 ] )
194- . filter ( ( name ) => {
195- if ( seen . has ( name ) ) return false
192+ await Promise . all (
193+ files . map ( async ( match ) => {
194+ const name = match [ 1 ]
195+ if ( seen . has ( name ) ) return
196196 seen . add ( name )
197- return true
198- } )
199- const resolved = await Promise . all (
200- names . map ( async ( name ) => {
201197 const filepath = name . startsWith ( "~/" )
202198 ? path . join ( os . homedir ( ) , name . slice ( 2 ) )
203199 : path . resolve ( Instance . worktree , name )
204200
205201 const stats = await fs . stat ( filepath ) . catch ( ( ) => undefined )
206202 if ( ! stats ) {
207203 const agent = await Agent . get ( name )
208- if ( ! agent ) return undefined
209- return {
210- type : "agent" ,
211- name : agent . name ,
212- } satisfies PromptInput [ "parts" ] [ number ]
204+ if ( agent ) {
205+ parts . push ( {
206+ type : "agent" ,
207+ name : agent . name ,
208+ } )
209+ }
210+ return
213211 }
214212
215213 if ( stats . isDirectory ( ) ) {
216- return {
214+ parts . push ( {
217215 type : "file" ,
218216 url : `file://${ filepath } ` ,
219217 filename : name ,
220218 mime : "application/x-directory" ,
221- } satisfies PromptInput [ "parts" ] [ number ]
219+ } )
220+ return
222221 }
223222
224- return {
223+ parts . push ( {
225224 type : "file" ,
226225 url : `file://${ filepath } ` ,
227226 filename : name ,
228227 mime : "text/plain" ,
229- } satisfies PromptInput [ "parts" ] [ number ]
228+ } )
230229 } ) ,
231230 )
232- for ( const item of resolved ) {
233- if ( ! item ) continue
234- parts . push ( item )
235- }
236231 return parts
237232 }
238233
@@ -432,12 +427,6 @@ export namespace SessionPrompt {
432427 assistantMessage . time . completed = Date . now ( )
433428 await Session . updateMessage ( assistantMessage )
434429 if ( result && part . state . status === "running" ) {
435- const attachments = result . attachments ?. map ( ( attachment ) => ( {
436- ...attachment ,
437- id : Identifier . ascending ( "part" ) ,
438- messageID : assistantMessage . id ,
439- sessionID : assistantMessage . sessionID ,
440- } ) )
441430 await Session . updatePart ( {
442431 ...part ,
443432 state : {
@@ -446,7 +435,7 @@ export namespace SessionPrompt {
446435 title : result . title ,
447436 metadata : result . metadata ,
448437 output : result . output ,
449- attachments,
438+ attachments : result . attachments ,
450439 time : {
451440 ...part . state . time ,
452441 end : Date . now ( ) ,
@@ -785,13 +774,16 @@ export namespace SessionPrompt {
785774 )
786775
787776 const textParts : string [ ] = [ ]
788- const attachments : Omit < MessageV2 . FilePart , "id" | "messageID" | "sessionID" > [ ] = [ ]
777+ const attachments : MessageV2 . FilePart [ ] = [ ]
789778
790779 for ( const contentItem of result . content ) {
791780 if ( contentItem . type === "text" ) {
792781 textParts . push ( contentItem . text )
793782 } else if ( contentItem . type === "image" ) {
794783 attachments . push ( {
784+ id : Identifier . ascending ( "part" ) ,
785+ sessionID : input . session . id ,
786+ messageID : input . processor . message . id ,
795787 type : "file" ,
796788 mime : contentItem . mimeType ,
797789 url : `data:${ contentItem . mimeType } ;base64,${ contentItem . data } ` ,
@@ -803,6 +795,9 @@ export namespace SessionPrompt {
803795 }
804796 if ( resource . blob ) {
805797 attachments . push ( {
798+ id : Identifier . ascending ( "part" ) ,
799+ sessionID : input . session . id ,
800+ messageID : input . processor . message . id ,
806801 type : "file" ,
807802 mime : resource . mimeType ?? "application/octet-stream" ,
808803 url : `data:${ resource . mimeType ?? "application/octet-stream" } ;base64,${ resource . blob } ` ,
@@ -1051,7 +1046,6 @@ export namespace SessionPrompt {
10511046 pieces . push (
10521047 ...result . attachments . map ( ( attachment ) => ( {
10531048 ...attachment ,
1054- id : Identifier . ascending ( "part" ) ,
10551049 synthetic : true ,
10561050 filename : attachment . filename ?? part . filename ,
10571051 messageID : info . id ,
@@ -1189,18 +1183,7 @@ export namespace SessionPrompt {
11891183 } ,
11901184 ]
11911185 } ) ,
1192- )
1193- . then ( ( x ) => x . flat ( ) )
1194- . then ( ( drafts ) =>
1195- drafts . map (
1196- ( part ) : MessageV2 . Part => ( {
1197- ...part ,
1198- id : Identifier . ascending ( "part" ) ,
1199- messageID : info . id ,
1200- sessionID : input . sessionID ,
1201- } ) ,
1202- ) ,
1203- )
1186+ ) . then ( ( x ) => x . flat ( ) )
12041187
12051188 await Plugin . trigger (
12061189 "chat.message" ,
0 commit comments