17
17
import { ReadableStream } from 'web-streams-polyfill' ;
18
18
import { mocksLookup } from './mocks-lookup' ;
19
19
20
+ export enum BackendName {
21
+ VertexAI = 'vertexai' ,
22
+ GoogleAI = 'googleai' ,
23
+ }
24
+
20
25
/**
21
26
* Mock native Response.body
22
27
* Streams contents of json file in 20 character chunks
@@ -40,10 +45,16 @@ export function getChunkedStream(input: string, chunkLength = 20): ReadableStrea
40
45
return stream ;
41
46
}
42
47
export function getMockResponseStreaming (
48
+ backendName : BackendName ,
43
49
filename : string ,
44
50
chunkLength : number = 20 ,
45
51
) : Partial < Response > {
46
- const fullText = mocksLookup [ filename ] ;
52
+ // @ts -ignore
53
+ const backendMocksLookup : Record < string , string > = mocksLookup [ backendName ] ;
54
+ if ( ! backendMocksLookup [ filename ] ) {
55
+ throw Error ( `${ backendName } mock response file '${ filename } ' not found.` ) ;
56
+ }
57
+ const fullText = backendMocksLookup [ filename ] as string ;
47
58
48
59
return {
49
60
// Really tangled typescript error here from our transitive dependencies.
@@ -59,11 +70,10 @@ export function getMockResponseStreaming(
59
70
} ;
60
71
}
61
72
62
- type BackendName = 'vertexai' | 'googleai' ;
63
73
export function getMockResponse ( backendName : BackendName , filename : string ) : Partial < Response > {
64
74
// @ts -ignore
65
75
const backendMocksLookup : Record < string , string > = mocksLookup [ backendName ] ;
66
- if ( ! ( filename in backendMocksLookup ) ) {
76
+ if ( ! backendMocksLookup [ filename ] ) {
67
77
throw Error ( `${ backendName } mock response file '${ filename } ' not found.` ) ;
68
78
}
69
79
const fullText = backendMocksLookup [ filename ] as string ;
0 commit comments