@@ -235,21 +235,41 @@ public struct ConverseReplyStream: Sendable {
235235 state: inout StreamState ,
236236 continuation: AsyncThrowingStream < ConverseStreamElement , any Error > . Continuation
237237 ) throws {
238- guard
239- ( state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
240- && !state. bufferToolUse. isEmpty)
241- || ( state. bufferText. isEmpty && state. bufferReasoning. isEmpty && !state. bufferReasoningData. isEmpty
242- && state. bufferToolUse. isEmpty)
243- || ( state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
244- && state. bufferToolUse. isEmpty)
245- || ( state. bufferText. isEmpty && !state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
246- && state. bufferToolUse. isEmpty)
247- || ( !state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
248- && state. bufferToolUse. isEmpty)
238+ guard isToolUseBufferValid ( state) ||
239+ isReasoningDataBufferValid ( state) ||
240+ isEmptyBufferValid ( state) ||
241+ isReasoningBufferValid ( state) ||
242+ isTextBufferValid ( state)
249243 else {
250244 throw BedrockLibraryError . invalidSDKType ( " ContentBlockStop received while multiple buffers are not empty " )
251245 }
252246
247+ }
248+
249+ private static func isToolUseBufferValid( _ state: StreamState ) -> Bool {
250+ return state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
251+ && !state. bufferToolUse. isEmpty
252+ }
253+
254+ private static func isReasoningDataBufferValid( _ state: StreamState ) -> Bool {
255+ return state. bufferText. isEmpty && state. bufferReasoning. isEmpty && !state. bufferReasoningData. isEmpty
256+ && state. bufferToolUse. isEmpty
257+ }
258+
259+ private static func isEmptyBufferValid( _ state: StreamState ) -> Bool {
260+ return state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
261+ && state. bufferToolUse. isEmpty
262+ }
263+
264+ private static func isReasoningBufferValid( _ state: StreamState ) -> Bool {
265+ return state. bufferText. isEmpty && !state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
266+ && state. bufferToolUse. isEmpty
267+ }
268+
269+ private static func isTextBufferValid( _ state: StreamState ) -> Bool {
270+ return !state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
271+ && state. bufferToolUse. isEmpty
272+ }
253273 if !state. bufferText. isEmpty {
254274 state. lastContentBlock = ( state. currentBlockId, Content . text ( state. bufferText) )
255275 state. bufferText = " "
0 commit comments