@@ -71,7 +71,6 @@ export async function main() {
71
71
if ( contentPart . type === "text" ) {
72
72
const textContent = contentPart as MessageDeltaTextContent ;
73
73
const textValue = textContent . text ?. value || "No text" ;
74
- process . stdout . write ( textValue ) ;
75
74
}
76
75
} ) ;
77
76
}
@@ -89,17 +88,18 @@ export async function main() {
89
88
90
89
// 6. Print the messages from the agent
91
90
const messages = await client . agents . listMessages ( thread . id ) ;
92
- console . log ( "Messages:\n----------------------------------------------" ) ;
93
91
94
92
// Messages iterate from oldest to newest
95
93
// messages[0] is the most recent
96
- await messages . data . forEach ( ( m ) => {
97
- console . log ( `Type: ${ m . content [ 0 ] . type } ` ) ;
98
- if ( isOutputOfType < MessageTextContentOutput > ( m . content [ 0 ] , "text" ) ) {
99
- const textContent = m . content [ 0 ] as MessageTextContentOutput ;
100
- console . log ( `Text: ${ textContent . text . value } ` ) ;
101
- }
102
- } ) ;
94
+ const messagesArray = messages . data ;
95
+ for ( let i = messagesArray . length - 1 ; i >= 0 ; i -- ) {
96
+ const m = messagesArray [ i ] ;
97
+ console . log ( `Type: ${ m . content [ 0 ] . type } ` ) ;
98
+ if ( isOutputOfType < MessageTextContentOutput > ( m . content [ 0 ] , "text" ) ) {
99
+ const textContent = m . content [ 0 ] as MessageTextContentOutput ;
100
+ console . log ( `Text: ${ textContent . text . value } ` ) ;
101
+ }
102
+ }
103
103
104
104
// 7. Delete the agent once done
105
105
await client . agents . deleteAgent ( agent . id ) ;
0 commit comments