@@ -48,7 +48,7 @@ public struct ConverseReplyStream: Sendable {
4848
4949 switch output {
5050 case . messagestart( let event) :
51- logger. trace ( " Message Start " , metadata: [ " event " : " \( event) " ] )
51+ logger? . trace ( " Message Start " , metadata: [ " event " : " \( event) " ] )
5252
5353 guard let sdkRole = event. role,
5454 let role = try ? Role ( from: sdkRole)
@@ -235,41 +235,13 @@ public struct ConverseReplyStream: Sendable {
235235 state: inout StreamState ,
236236 continuation: AsyncThrowingStream < ConverseStreamElement , any Error > . Continuation
237237 ) throws {
238- guard isToolUseBufferValid ( state) ||
239- isReasoningDataBufferValid ( state) ||
240- isEmptyBufferValid ( state) ||
241- isReasoningBufferValid ( state) ||
242- isTextBufferValid ( state)
238+ guard
239+ isToolUseBufferValid ( state) || isReasoningDataBufferValid ( state) || isEmptyBufferValid ( state)
240+ || isReasoningBufferValid ( state) || isTextBufferValid ( state)
243241 else {
244242 throw BedrockLibraryError . invalidSDKType ( " ContentBlockStop received while multiple buffers are not empty " )
245243 }
246244
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- }
273245 if !state. bufferText. isEmpty {
274246 state. lastContentBlock = ( state. currentBlockId, Content . text ( state. bufferText) )
275247 state. bufferText = " "
@@ -299,6 +271,31 @@ public struct ConverseReplyStream: Sendable {
299271 state. currentBlockId = - 1
300272 }
301273
274+ private static func isToolUseBufferValid( _ state: StreamState ) -> Bool {
275+ state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
276+ && !state. bufferToolUse. isEmpty
277+ }
278+
279+ private static func isReasoningDataBufferValid( _ state: StreamState ) -> Bool {
280+ state. bufferText. isEmpty && state. bufferReasoning. isEmpty && !state. bufferReasoningData. isEmpty
281+ && state. bufferToolUse. isEmpty
282+ }
283+
284+ private static func isEmptyBufferValid( _ state: StreamState ) -> Bool {
285+ state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
286+ && state. bufferToolUse. isEmpty
287+ }
288+
289+ private static func isReasoningBufferValid( _ state: StreamState ) -> Bool {
290+ state. bufferText. isEmpty && !state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
291+ && state. bufferToolUse. isEmpty
292+ }
293+
294+ private static func isTextBufferValid( _ state: StreamState ) -> Bool {
295+ !state. bufferText. isEmpty && state. bufferReasoning. isEmpty && state. bufferReasoningData. isEmpty
296+ && state. bufferToolUse. isEmpty
297+ }
298+
302299 // a simple struct to buffer whatever content we receive from the SDK
303300 // until final message is complete
304301 package struct StreamState {
0 commit comments