@@ -112,14 +112,55 @@ describe('ChromeAdapter', () => {
112
112
it ( 'returns false if mode is only cloud' , async ( ) => {
113
113
const adapter = new ChromeAdapterImpl (
114
114
{ } as LanguageModel ,
115
- 'only_in_cloud'
115
+ InferenceMode . ONLY_IN_CLOUD
116
116
) ;
117
117
expect (
118
118
await adapter . isAvailable ( {
119
119
contents : [ ]
120
120
} )
121
121
) . to . be . false ;
122
122
} ) ;
123
+ it ( 'returns true if mode is only on device and is available' , async ( ) => {
124
+ const adapter = new ChromeAdapterImpl (
125
+ {
126
+ availability : async ( ) => Availability . AVAILABLE
127
+ } as LanguageModel ,
128
+ InferenceMode . ONLY_ON_DEVICE
129
+ ) ;
130
+ expect (
131
+ await adapter . isAvailable ( {
132
+ contents : [ ]
133
+ } )
134
+ ) . to . be . true ;
135
+ } ) ;
136
+ it ( 'throws if mode is only on device and is unavailable' , async ( ) => {
137
+ const adapter = new ChromeAdapterImpl (
138
+ {
139
+ availability : async ( ) => Availability . UNAVAILABLE
140
+ } as LanguageModel ,
141
+ InferenceMode . ONLY_ON_DEVICE
142
+ ) ;
143
+ await expect (
144
+ adapter . isAvailable ( {
145
+ contents : [ ]
146
+ } )
147
+ ) . to . be . rejected ;
148
+ } ) ;
149
+ it ( 'returns true after waiting for download if mode is only on device' , async ( ) => {
150
+ const adapter = new ChromeAdapterImpl (
151
+ {
152
+ availability : async ( ) => Availability . DOWNLOADING ,
153
+ create : ( { } : LanguageModelCreateOptions ) =>
154
+ Promise . resolve ( { } as LanguageModel )
155
+ } as LanguageModel ,
156
+ InferenceMode . ONLY_ON_DEVICE
157
+ ) ;
158
+ expect (
159
+ await adapter . isAvailable ( {
160
+ contents : [ ]
161
+ } )
162
+ ) . to . be . true ;
163
+ } ) ;
123
164
it ( 'returns false if LanguageModel API is undefined' , async ( ) => {
124
165
const adapter = new ChromeAdapterImpl (
125
166
// @ts -expect-error
@@ -301,8 +342,11 @@ describe('ChromeAdapter', () => {
301
342
} ) ;
302
343
describe ( 'generateContent' , ( ) => {
303
344
it ( 'throws if Chrome API is undefined' , async ( ) => {
304
- // @ts -expect-error
305
- const adapter = new ChromeAdapterImpl ( undefined , 'only_on_device' ) ;
345
+ const adapter = new ChromeAdapterImpl (
346
+ // @ts -expect-error
347
+ undefined ,
348
+ InferenceMode . ONLY_ON_DEVICE
349
+ ) ;
306
350
await expect (
307
351
adapter . generateContent ( {
308
352
contents : [ ]
0 commit comments