@@ -39,8 +39,7 @@ class Replicate {
3939 */
4040 constructor ( options = { } ) {
4141 this . auth = options . auth || process . env . REPLICATE_API_TOKEN ;
42- this . userAgent =
43- options . userAgent || `replicate-javascript/${ packageJSON . version } ` ;
42+ this . userAgent = options . userAgent || `replicate-javascript/${ packageJSON . version } ` ;
4443 this . baseUrl = options . baseUrl || 'https://api.replicate.com/v1' ;
4544 this . fetch = options . fetch || globalThis . fetch ;
4645
@@ -51,6 +50,7 @@ class Replicate {
5150
5251 this . models = {
5352 get : models . get . bind ( this ) ,
53+ list : models . list . bind ( this ) ,
5454 versions : {
5555 list : models . versions . list . bind ( this ) ,
5656 get : models . versions . get . bind ( this ) ,
@@ -74,7 +74,7 @@ class Replicate {
7474 this . deployments = {
7575 predictions : {
7676 create : deployments . predictions . create . bind ( this ) ,
77- }
77+ } ,
7878 } ;
7979 }
8080
@@ -103,15 +103,11 @@ class Replicate {
103103
104104 // Define a pattern for "owner/name:version" format with named capturing groups.
105105 // Example: "user123/repo_a:1a2b3c"
106- const pattern = new RegExp (
107- `^(?<owner>${ namePattern . source } )/(?<name>${ namePattern . source } ):(?<version>[0-9a-fA-F]+)$`
108- ) ;
106+ const pattern = new RegExp ( `^(?<owner>${ namePattern . source } )/(?<name>${ namePattern . source } ):(?<version>[0-9a-fA-F]+)$` ) ;
109107
110108 const match = identifier . match ( pattern ) ;
111109 if ( ! match || ! match . groups ) {
112- throw new Error (
113- 'Invalid version. It must be in the format "owner/name:version"'
114- ) ;
110+ throw new Error ( 'Invalid version. It must be in the format "owner/name:version"' ) ;
115111 }
116112
117113 const { version } = match . groups ;
@@ -173,17 +169,10 @@ class Replicate {
173169 if ( route instanceof URL ) {
174170 url = route ;
175171 } else {
176- url = new URL (
177- route . startsWith ( '/' ) ? route . slice ( 1 ) : route ,
178- baseUrl . endsWith ( '/' ) ? baseUrl : `${ baseUrl } /`
179- ) ;
172+ url = new URL ( route . startsWith ( '/' ) ? route . slice ( 1 ) : route , baseUrl . endsWith ( '/' ) ? baseUrl : `${ baseUrl } /` ) ;
180173 }
181174
182- const {
183- method = 'GET' ,
184- params = { } ,
185- data,
186- } = options ;
175+ const { method = 'GET' , params = { } , data } = options ;
187176
188177 Object . entries ( params ) . forEach ( ( [ key , value ] ) => {
189178 url . searchParams . append ( key , value ) ;
@@ -207,19 +196,13 @@ class Replicate {
207196 body : data ? JSON . stringify ( data ) : undefined ,
208197 } ;
209198
210- const shouldRetry = method === 'GET' ?
211- ( response ) => ( response . status === 429 || response . status >= 500 ) :
212- ( response ) => ( response . status === 429 ) ;
199+ const shouldRetry = method === 'GET' ? ( response ) => response . status === 429 || response . status >= 500 : ( response ) => response . status === 429 ;
213200 const response = await withAutomaticRetries ( async ( ) => this . fetch ( url , init ) , { shouldRetry } ) ;
214201
215202 if ( ! response . ok ) {
216203 const request = new Request ( url , init ) ;
217204 const responseText = await response . text ( ) ;
218- throw new ApiError (
219- `Request to ${ url } failed with status ${ response . status } ${ response . statusText } : ${ responseText } .` ,
220- request ,
221- response ,
222- ) ;
205+ throw new ApiError ( `Request to ${ url } failed with status ${ response . status } ${ response . statusText } : ${ responseText } .` , request , response ) ;
223206 }
224207
225208 return response ;
@@ -236,7 +219,7 @@ class Replicate {
236219 * @param {Function } endpoint - Function that returns a promise for the next page of results
237220 * @yields {object[]} Each page of results
238221 */
239- async * paginate ( endpoint ) {
222+ async * paginate ( endpoint ) {
240223 const response = await endpoint ( ) ;
241224 yield response . results ;
242225 if ( response . next ) {
@@ -267,11 +250,7 @@ class Replicate {
267250 throw new Error ( 'Invalid prediction' ) ;
268251 }
269252
270- if (
271- prediction . status === 'succeeded' ||
272- prediction . status === 'failed' ||
273- prediction . status === 'canceled'
274- ) {
253+ if ( prediction . status === 'succeeded' || prediction . status === 'failed' || prediction . status === 'canceled' ) {
275254 return prediction ;
276255 }
277256
@@ -282,13 +261,9 @@ class Replicate {
282261
283262 let updatedPrediction = await this . predictions . get ( id ) ;
284263
285- while (
286- updatedPrediction . status !== 'succeeded' &&
287- updatedPrediction . status !== 'failed' &&
288- updatedPrediction . status !== 'canceled'
289- ) {
264+ while ( updatedPrediction . status !== 'succeeded' && updatedPrediction . status !== 'failed' && updatedPrediction . status !== 'canceled' ) {
290265 /* eslint-disable no-await-in-loop */
291- if ( stop && await stop ( updatedPrediction ) === true ) {
266+ if ( stop && ( await stop ( updatedPrediction ) ) === true ) {
292267 break ;
293268 }
294269
0 commit comments