11import { generateText , streamText } from 'ai' ;
22import { describe , expect , test } from 'vitest' ;
3- import { Content } from './content.js' ;
3+ import { Streams } from '../stream.js' ;
4+ import { ContentParts } from './content.js' ;
45import { MockLanguageModel } from './mock-language-model.js' ;
56import { Options } from './options.js' ;
6- import { Stream } from './stream.js' ;
77import { StreamParts } from './stream-parts.js' ;
88
99describe ( 'MockLanguageModel' , ( ) => {
@@ -30,9 +30,9 @@ describe('MockLanguageModel', () => {
3030 await expect ( result ) . rejects . toThrow ( ) ;
3131 } ) ;
3232
33- test ( 'should return explicit content built from Content atoms' , async ( ) => {
33+ test ( 'should return explicit content built from ContentParts atoms' , async ( ) => {
3434 // Arrange
35- const model = MockLanguageModel . from ( { content : [ Content . text ( 'explicit' ) ] } ) ;
35+ const model = MockLanguageModel . from ( { content : [ ContentParts . text ( 'explicit' ) ] } ) ;
3636
3737 // Act
3838 const result = await generateText ( { model, prompt : 'Hi' , ...Options . generate } ) ;
@@ -44,7 +44,7 @@ describe('MockLanguageModel', () => {
4444
4545 test ( 'should accept a unified finish-reason string in the content form' , async ( ) => {
4646 // Arrange
47- const model = MockLanguageModel . from ( { content : [ Content . text ( 'truncated' ) ] , finishReason : 'length' } ) ;
47+ const model = MockLanguageModel . from ( { content : [ ContentParts . text ( 'truncated' ) ] , finishReason : 'length' } ) ;
4848
4949 // Act
5050 const result = await generateText ( { model, prompt : 'Hi' , ...Options . generate } ) ;
@@ -66,10 +66,10 @@ describe('MockLanguageModel', () => {
6666 expect ( result . text ) . toBe ( 'prompt-parts:1' ) ;
6767 } ) ;
6868
69- test ( 'should surface a tool call from Content .toolCall' , async ( ) => {
69+ test ( 'should surface a tool call from ContentParts .toolCall' , async ( ) => {
7070 // Arrange
7171 const model = MockLanguageModel . from ( {
72- content : [ Content . toolCall ( { toolCallId : 'call-1' , toolName : 'weather' , input : { city : 'Tokyo' } } ) ] ,
72+ content : [ ContentParts . toolCall ( { toolCallId : 'call-1' , toolName : 'weather' , input : { city : 'Tokyo' } } ) ] ,
7373 } ) ;
7474
7575 // Act
@@ -88,7 +88,7 @@ describe('MockLanguageModel', () => {
8888
8989 // Act
9090 const result = streamText ( { model, prompt : 'Hi' , ...Options . stream } ) ;
91- const text = ( await Stream . toArray ( result . textStream ) ) . join ( '' ) ;
91+ const text = ( await Streams . toArray ( result . textStream ) ) . join ( '' ) ;
9292
9393 // Assert
9494 expect ( text ) . toBe ( 'Hello World' ) ;
@@ -101,19 +101,19 @@ describe('MockLanguageModel', () => {
101101
102102 // Act
103103 const result = streamText ( { model, prompt : 'Hi' , ...Options . stream } ) ;
104- const text = ( await Stream . toArray ( result . textStream ) ) . join ( '' ) ;
104+ const text = ( await Streams . toArray ( result . textStream ) ) . join ( '' ) ;
105105
106106 // Assert
107107 expect ( text ) . toBe ( 'abcdef' ) ;
108108 } ) ;
109109
110110 test ( 'should derive a stream from content' , async ( ) => {
111111 // Arrange
112- const model = MockLanguageModel . from ( { content : [ Content . text ( 'derived' ) ] } ) ;
112+ const model = MockLanguageModel . from ( { content : [ ContentParts . text ( 'derived' ) ] } ) ;
113113
114114 // Act
115115 const result = streamText ( { model, prompt : 'Hi' , ...Options . stream } ) ;
116- const text = ( await Stream . toArray ( result . textStream ) ) . join ( '' ) ;
116+ const text = ( await Streams . toArray ( result . textStream ) ) . join ( '' ) ;
117117
118118 // Assert
119119 expect ( text ) . toBe ( 'derived' ) ;
@@ -122,12 +122,12 @@ describe('MockLanguageModel', () => {
122122 test ( 'should make a string and the equivalent content stream identically' , async ( ) => {
123123 // Arrange
124124 const fromString = MockLanguageModel . from ( 'Hello' ) ;
125- const fromContent = MockLanguageModel . from ( { content : [ Content . text ( 'Hello' ) ] } ) ;
125+ const fromContent = MockLanguageModel . from ( { content : [ ContentParts . text ( 'Hello' ) ] } ) ;
126126 const callOptions = { prompt : [ ] } as never ;
127127
128128 // Act
129- const stringParts = await Stream . toArray ( ( await fromString . doStream ( callOptions ) ) . stream ) ;
130- const contentParts = await Stream . toArray ( ( await fromContent . doStream ( callOptions ) ) . stream ) ;
129+ const stringParts = await Streams . toArray ( ( await fromString . doStream ( callOptions ) ) . stream ) ;
130+ const contentParts = await Streams . toArray ( ( await fromContent . doStream ( callOptions ) ) . stream ) ;
131131
132132 // Assert
133133 expect ( stringParts ) . toEqual ( contentParts ) ;
@@ -141,7 +141,7 @@ describe('MockLanguageModel', () => {
141141
142142 // Act
143143 const result = streamText ( { model, prompt : 'Hi' , ...Options . stream } ) ;
144- const text = ( await Stream . toArray ( result . textStream ) ) . join ( '' ) ;
144+ const text = ( await Streams . toArray ( result . textStream ) ) . join ( '' ) ;
145145
146146 // Assert
147147 expect ( text ) . toBe ( 'fast' ) ;
@@ -155,7 +155,7 @@ describe('MockLanguageModel', () => {
155155
156156 // Act
157157 const result = streamText ( { model, prompt : 'Hi' , ...Options . stream } ) ;
158- const text = ( await Stream . toArray ( result . textStream ) ) . join ( '' ) ;
158+ const text = ( await Streams . toArray ( result . textStream ) ) . join ( '' ) ;
159159
160160 // Assert
161161 expect ( text ) . toBe ( 'has-prompt' ) ;
@@ -164,11 +164,11 @@ describe('MockLanguageModel', () => {
164164 test ( 'should stream from a bare ReadableStream in the stream form' , async ( ) => {
165165 // Arrange
166166 const parts = [ StreamParts . streamStart ( ) , ...StreamParts . text ( 'piped' ) , StreamParts . finish ( ) ] ;
167- const model = MockLanguageModel . from ( { stream : Stream . from ( parts ) } ) ;
167+ const model = MockLanguageModel . from ( { stream : Streams . from ( parts ) } ) ;
168168
169169 // Act
170170 const result = streamText ( { model, prompt : 'Hi' , ...Options . stream } ) ;
171- const text = ( await Stream . toArray ( result . textStream ) ) . join ( '' ) ;
171+ const text = ( await Streams . toArray ( result . textStream ) ) . join ( '' ) ;
172172
173173 // Assert
174174 expect ( text ) . toBe ( 'piped' ) ;
@@ -315,14 +315,14 @@ describe('MockLanguageModel', () => {
315315 test ( 'streamResult() should wrap a ReadableStream as a stream result' , async ( ) => {
316316 // Arrange
317317 const parts = [ ...StreamParts . text ( 'wrapped' ) , StreamParts . finish ( ) ] ;
318- const stream = Stream . from ( parts ) ;
318+ const stream = Streams . from ( parts ) ;
319319
320320 // Act
321321 const result = MockLanguageModel . streamResult ( stream ) ;
322322
323323 // Assert
324324 expect ( result . stream ) . toBe ( stream ) ;
325- expect ( await Stream . toArray ( result . stream ) ) . toEqual ( parts ) ;
325+ expect ( await Streams . toArray ( result . stream ) ) . toEqual ( parts ) ;
326326 } ) ;
327327 } ) ;
328328
0 commit comments