@@ -147,7 +147,7 @@ void spinStopThen(Action runThis)
147147 Console . WriteLine ( ) ;
148148 }
149149
150- PrintArtifact ( artifactEvent . Artifact ) ;
150+ await PrintArtifactAsync ( artifactEvent . Artifact ) ;
151151
152152 if ( artifactEvent . Artifact . LastChunk is true )
153153 {
@@ -211,7 +211,7 @@ void spinStopThen(Action runThis)
211211 AnsiConsole . Markup ( $ "[bold green]Agent>[/] ") ;
212212 foreach ( var a in task . Result ? . Artifacts ?? [ ] )
213213 {
214- PrintArtifact ( a ) ;
214+ await PrintArtifactAsync ( a ) ;
215215 }
216216 }
217217 else
@@ -235,10 +235,40 @@ void spinStopThen(Action runThis)
235235 }
236236}
237237
238- static void PrintArtifact ( Artifact artifact )
238+ static async System . Threading . Tasks . Task PrintArtifactAsync ( Artifact artifact )
239239{
240240 foreach ( var p in artifact . Parts ?? [ ] )
241241 {
242- AnsiConsole . Markup ( p . ToText ( ) ? . EscapeMarkup ( ) ?? string . Empty ) ;
242+ if ( p is TextPart t )
243+ {
244+ AnsiConsole . Markup ( p . ToText ( ) ? . EscapeMarkup ( ) ?? string . Empty ) ;
245+ }
246+ else if ( p is FilePart f )
247+ {
248+ AnsiConsole . MarkupLineInterpolated ( $ "[darkgreen]File: { f . File . Name } [/]") ;
249+ if ( f . File . Uri is not null )
250+ {
251+ AnsiConsole . MarkupLineInterpolated ( $ "[darkgreen]URI: { f . File . Uri } [/]") ;
252+ }
253+
254+ if ( f . File . Bytes is not null )
255+ {
256+ var filename = Path . Combine ( Path . GetTempPath ( ) , f . File . Name ! ) ;
257+ await System . IO . File . WriteAllBytesAsync ( filename , Convert . FromBase64String ( f . File . Bytes ! ) ) ;
258+ AnsiConsole . MarkupLineInterpolated ( $ "[darkgreen]Downloaded to: { filename } [/]") ;
259+ }
260+ }
261+ else if ( p is DataPart d )
262+ {
263+ AnsiConsole . MarkupLineInterpolated ( $ "[darkgreen]Data: { ( d . Type is null ? "Unknown" : d . Type ) } [/]") ;
264+ foreach ( var i in d . Metadata ?? [ ] )
265+ {
266+ AnsiConsole . MarkupLineInterpolated ( $ "[darkgreen]{ i . Key } : { i . Value } [/]") ;
267+ }
268+ }
269+ else
270+ {
271+ AnsiConsole . MarkupLineInterpolated ( $ "[red]Unknown part type: { p . Type } [/]") ;
272+ }
243273 }
244274}
0 commit comments