@@ -683,20 +683,12 @@ describe('extractReasoningMiddleware', () => {
683
683
"id": "1",
684
684
"type": "text-start",
685
685
},
686
- {
687
- "id": "reasoning-0",
688
- "type": "reasoning-start",
689
- },
690
686
{
691
687
"id": "1",
692
688
"providerMetadata": undefined,
693
689
"text": "ana",
694
690
"type": "text",
695
691
},
696
- {
697
- "id": "reasoning-0",
698
- "type": "reasoning-start",
699
- },
700
692
{
701
693
"id": "1",
702
694
"providerMetadata": undefined,
@@ -705,18 +697,100 @@ describe('extractReasoningMiddleware', () => {
705
697
"type": "text",
706
698
},
707
699
{
708
- "id": "reasoning-0",
709
- "type": "reasoning-start",
700
+ "id": "1",
701
+ "providerMetadata": undefined,
702
+ "text": "</think>",
703
+ "type": "text",
710
704
},
711
705
{
712
706
"id": "1",
713
707
"providerMetadata": undefined,
714
- "text": "</think> ",
708
+ "text": "this is the response ",
715
709
"type": "text",
716
710
},
717
711
{
718
- "id": "reasoning-0",
719
- "type": "reasoning-start",
712
+ "id": "1",
713
+ "type": "text-end",
714
+ },
715
+ {
716
+ "finishReason": "stop",
717
+ "providerMetadata": undefined,
718
+ "response": {
719
+ "headers": undefined,
720
+ "id": "id-0",
721
+ "modelId": "mock-model-id",
722
+ "timestamp": 1970-01-01T00:00:00.000Z,
723
+ },
724
+ "type": "finish-step",
725
+ "usage": {
726
+ "cachedInputTokens": undefined,
727
+ "inputTokens": 5,
728
+ "outputTokens": 10,
729
+ "reasoningTokens": 3,
730
+ "totalTokens": 18,
731
+ },
732
+ },
733
+ {
734
+ "finishReason": "stop",
735
+ "totalUsage": {
736
+ "cachedInputTokens": undefined,
737
+ "inputTokens": 5,
738
+ "outputTokens": 10,
739
+ "reasoningTokens": 3,
740
+ "totalTokens": 18,
741
+ },
742
+ "type": "finish",
743
+ },
744
+ ]
745
+ ` ) ;
746
+ } ) ;
747
+
748
+ it ( 'should keep original text when <think> tag is not present' , async ( ) => {
749
+ const mockModel = new MockLanguageModelV2 ( {
750
+ async doStream ( ) {
751
+ return {
752
+ stream : convertArrayToReadableStream ( [
753
+ {
754
+ type : 'response-metadata' ,
755
+ id : 'id-0' ,
756
+ modelId : 'mock-model-id' ,
757
+ timestamp : new Date ( 0 ) ,
758
+ } ,
759
+ { type : 'text-start' , id : '1' } ,
760
+ { type : 'text-delta' , id : '1' , delta : 'this is the response' } ,
761
+ { type : 'text-end' , id : '1' } ,
762
+ {
763
+ type : 'finish' ,
764
+ finishReason : 'stop' ,
765
+ usage : testUsage ,
766
+ } ,
767
+ ] ) ,
768
+ } ;
769
+ } ,
770
+ } ) ;
771
+
772
+ const result = streamText ( {
773
+ model : wrapLanguageModel ( {
774
+ model : mockModel ,
775
+ middleware : extractReasoningMiddleware ( { tagName : 'think' } ) ,
776
+ } ) ,
777
+ prompt : 'Hello, how can I help?' ,
778
+ } ) ;
779
+
780
+ expect ( await convertAsyncIterableToArray ( result . fullStream ) )
781
+ . toMatchInlineSnapshot ( `
782
+ [
783
+ {
784
+ "type": "start",
785
+ },
786
+ {
787
+ "request": {},
788
+ "type": "start-step",
789
+ "warnings": [],
790
+ },
791
+ {
792
+ "id": "1",
793
+ "type": "text-start",
720
794
},
721
795
{
722
796
"id": "1",
0 commit comments