File tree Expand file tree Collapse file tree
packages/trigger-sdk/src/v3 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9476,11 +9476,24 @@ function createChatSession(
94769476
94779477 async complete ( source ?: UIMessageStreamable ) {
94789478 // Head-start final turn: the warm step-1 partial is already spliced
9479- // into the accumulator and IS the response — nothing to pipe.
9479+ // into the accumulator and IS the response — nothing to pipe. Only
9480+ // valid on a final handover; a missing source on any other turn is a
9481+ // mistake (it would silently finalize without an assistant response).
94809482 if ( ! source ) {
9483+ if ( ! handoverThisTurn ?. isFinal ) {
9484+ throw new Error (
9485+ "turn.complete() requires a stream source unless turn.handover.isFinal is true"
9486+ ) ;
9487+ }
9488+ const response = accumulator . uiMessages . at ( - 1 ) ;
9489+ if ( ! response || response . role !== "assistant" ) {
9490+ throw new Error (
9491+ "turn.complete() could not find the spliced handover response"
9492+ ) ;
9493+ }
94819494 sessionMsgSub . off ( ) ;
94829495 await chatWriteTurnComplete ( ) ;
9483- return accumulator . uiMessages . at ( - 1 ) ;
9496+ return response ;
94849497 }
94859498 let response : UIMessage | undefined ;
94869499 try {
You can’t perform that action at this time.
0 commit comments