File tree Expand file tree Collapse file tree 1 file changed +7
-15
lines changed
Expand file tree Collapse file tree 1 file changed +7
-15
lines changed Original file line number Diff line number Diff line change @@ -92,21 +92,13 @@ export function serializeStep<TOOLS extends ToolSet>(
9292export function serializeNewMessagesInStep < TOOLS extends ToolSet > (
9393 step : StepResult < TOOLS >
9494) : MessageWithFileAndId [ ] {
95- const messages : MessageWithFileAndId [ ] = [ ] ;
96- if ( step . text ) {
97- messages . push ( serializeMessageWithId ( step . response . messages . at ( - 1 ) ! ) ) ;
98- }
99- // TODO: get ID from regular messages
100- if ( step . toolCalls || step . toolResults ) {
101- messages . push (
102- ...step . response . messages
103- . slice (
104- 0 ,
105- - ( ( step . toolCalls ?. length ?? 0 ) + ( step . toolResults ?. length ?? 0 ) )
106- )
107- . map ( ( m ) => serializeMessageWithId ( m ) )
108- ) ;
109- }
95+ // If there are tool results, there's another message with the tool results
96+ // ref: https://github.com/vercel/ai/blob/main/packages/ai/core/generate-text/to-response-messages.ts
97+ const messages : MessageWithFileAndId [ ] = (
98+ step . toolResults . length > 0
99+ ? step . response . messages . slice ( 0 , - 2 )
100+ : step . response . messages . slice ( 0 , - 1 )
101+ ) . map ( serializeMessageWithId ) ;
110102 return messages ;
111103}
112104
You can’t perform that action at this time.
0 commit comments