55import * as environments from "./environments" ;
66import * as core from "./core" ;
77import * as Hume from "./api" ;
8- import { default as URLSearchParams } from "@ungap/url-search-params" ;
98import urlJoin from "url-join" ;
109import * as serializers from "./serialization" ;
1110import * as errors from "./errors" ;
@@ -15,62 +14,71 @@ export declare namespace HumeClient {
1514 environment ?: core . Supplier < environments . HumeEnvironment | string > ;
1615 apiKey : core . Supplier < string > ;
1716 }
17+
18+ interface RequestOptions {
19+ timeoutInSeconds ?: number ;
20+ maxRetries ?: number ;
21+ }
1822}
1923
2024export class HumeClient {
21- constructor ( protected readonly options : HumeClient . Options ) { }
25+ constructor ( protected readonly _options : HumeClient . Options ) { }
2226
2327 /**
2428 * Sort and filter jobs.
2529 */
26- public async listJobs ( request : Hume . ListJobsRequest = { } ) : Promise < Hume . JobRequest [ ] > {
30+ public async listJobs (
31+ request : Hume . ListJobsRequest = { } ,
32+ requestOptions ?: HumeClient . RequestOptions
33+ ) : Promise < Hume . JobRequest [ ] > {
2734 const { limit, status, when, timestampMs, sortBy, direction } = request ;
28- const _queryParams = new URLSearchParams ( ) ;
35+ const _queryParams : Record < string , string > = { } ;
2936 if ( limit != null ) {
30- _queryParams . append ( "limit" , limit . toString ( ) ) ;
37+ _queryParams [ "limit" ] = limit . toString ( ) ;
3138 }
3239
3340 if ( status != null ) {
3441 if ( Array . isArray ( status ) ) {
3542 for ( const _item of status ) {
36- _queryParams . append ( "status" , _item ) ;
43+ _queryParams [ "status" ] = _item ;
3744 }
3845 } else {
39- _queryParams . append ( "status" , status ) ;
46+ _queryParams [ "status" ] = status ;
4047 }
4148 }
4249
4350 if ( when != null ) {
44- _queryParams . append ( "when" , when ) ;
51+ _queryParams [ "when" ] = when ;
4552 }
4653
4754 if ( timestampMs != null ) {
48- _queryParams . append ( "timestamp_ms" , timestampMs . toString ( ) ) ;
55+ _queryParams [ "timestamp_ms" ] = timestampMs . toString ( ) ;
4956 }
5057
5158 if ( sortBy != null ) {
52- _queryParams . append ( "sort_by" , sortBy ) ;
59+ _queryParams [ "sort_by" ] = sortBy ;
5360 }
5461
5562 if ( direction != null ) {
56- _queryParams . append ( "direction" , direction ) ;
63+ _queryParams [ "direction" ] = direction ;
5764 }
5865
5966 const _response = await core . fetcher ( {
6067 url : urlJoin (
61- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
68+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
6269 "v0/batch/jobs"
6370 ) ,
6471 method : "GET" ,
6572 headers : {
66- "X-Hume-Api-Key" : await core . Supplier . get ( this . options . apiKey ) ,
73+ "X-Hume-Api-Key" : await core . Supplier . get ( this . _options . apiKey ) ,
6774 "X-Fern-Language" : "JavaScript" ,
6875 "X-Fern-SDK-Name" : "@fern-api/hume" ,
69- "X-Fern-SDK-Version" : "0.0.10 " ,
76+ "X-Fern-SDK-Version" : "0.1.0 " ,
7077 } ,
7178 contentType : "application/json" ,
7279 queryParameters : _queryParams ,
73- timeoutMs : 60000 ,
80+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
81+ maxRetries : requestOptions ?. maxRetries ,
7482 } ) ;
7583 if ( _response . ok ) {
7684 return await serializers . listJobs . Response . parseOrThrow ( _response . body , {
@@ -106,22 +114,26 @@ export class HumeClient {
106114 /**
107115 * Start a new batch job.
108116 */
109- public async submitJob ( request : Hume . BaseRequest = { } ) : Promise < Hume . JobId > {
117+ public async submitJob (
118+ request : Hume . BaseRequest = { } ,
119+ requestOptions ?: HumeClient . RequestOptions
120+ ) : Promise < Hume . JobId > {
110121 const _response = await core . fetcher ( {
111122 url : urlJoin (
112- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
123+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
113124 "v0/batch/jobs"
114125 ) ,
115126 method : "POST" ,
116127 headers : {
117- "X-Hume-Api-Key" : await core . Supplier . get ( this . options . apiKey ) ,
128+ "X-Hume-Api-Key" : await core . Supplier . get ( this . _options . apiKey ) ,
118129 "X-Fern-Language" : "JavaScript" ,
119130 "X-Fern-SDK-Name" : "@fern-api/hume" ,
120- "X-Fern-SDK-Version" : "0.0.10 " ,
131+ "X-Fern-SDK-Version" : "0.1.0 " ,
121132 } ,
122133 contentType : "application/json" ,
123134 body : await serializers . BaseRequest . jsonOrThrow ( request , { unrecognizedObjectKeys : "strip" } ) ,
124- timeoutMs : 60000 ,
135+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
136+ maxRetries : requestOptions ?. maxRetries ,
125137 } ) ;
126138 if ( _response . ok ) {
127139 return await serializers . JobId . parseOrThrow ( _response . body , {
@@ -157,21 +169,25 @@ export class HumeClient {
157169 /**
158170 * Get the JSON predictions of a completed job.
159171 */
160- public async getJobPredictions ( id : string ) : Promise < Hume . SourceResult [ ] > {
172+ public async getJobPredictions (
173+ id : string ,
174+ requestOptions ?: HumeClient . RequestOptions
175+ ) : Promise < Hume . SourceResult [ ] > {
161176 const _response = await core . fetcher ( {
162177 url : urlJoin (
163- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
178+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
164179 `v0/batch/jobs/${ id } /predictions`
165180 ) ,
166181 method : "GET" ,
167182 headers : {
168- "X-Hume-Api-Key" : await core . Supplier . get ( this . options . apiKey ) ,
183+ "X-Hume-Api-Key" : await core . Supplier . get ( this . _options . apiKey ) ,
169184 "X-Fern-Language" : "JavaScript" ,
170185 "X-Fern-SDK-Name" : "@fern-api/hume" ,
171- "X-Fern-SDK-Version" : "0.0.10 " ,
186+ "X-Fern-SDK-Version" : "0.1.0 " ,
172187 } ,
173188 contentType : "application/json" ,
174- timeoutMs : 60000 ,
189+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
190+ maxRetries : requestOptions ?. maxRetries ,
175191 } ) ;
176192 if ( _response . ok ) {
177193 return await serializers . getJobPredictions . Response . parseOrThrow ( _response . body , {
@@ -207,22 +223,23 @@ export class HumeClient {
207223 /**
208224 * Get the artifacts ZIP of a completed job.
209225 */
210- public async getJobArtifacts ( id : string ) : Promise < Blob > {
211- const _response = await core . fetcher ( {
226+ public async getJobArtifacts ( id : string , requestOptions ?: HumeClient . RequestOptions ) : Promise < Blob > {
227+ const _response = await core . fetcher < Blob > ( {
212228 url : urlJoin (
213- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
229+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
214230 `v0/batch/jobs/${ id } /artifacts`
215231 ) ,
216232 method : "GET" ,
217233 headers : {
218- "X-Hume-Api-Key" : await core . Supplier . get ( this . options . apiKey ) ,
234+ "X-Hume-Api-Key" : await core . Supplier . get ( this . _options . apiKey ) ,
219235 "X-Fern-Language" : "JavaScript" ,
220236 "X-Fern-SDK-Name" : "@fern-api/hume" ,
221- "X-Fern-SDK-Version" : "0.0.10 " ,
237+ "X-Fern-SDK-Version" : "0.1.0 " ,
222238 } ,
223239 contentType : "application/json" ,
224240 responseType : "blob" ,
225- timeoutMs : 60000 ,
241+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
242+ maxRetries : requestOptions ?. maxRetries ,
226243 } ) ;
227244 if ( _response . ok ) {
228245 return _response . body ;
@@ -253,21 +270,22 @@ export class HumeClient {
253270 /**
254271 * Get the request details and state of a given job.
255272 */
256- public async getJobDetails ( id : string ) : Promise < Hume . JobRequest > {
273+ public async getJobDetails ( id : string , requestOptions ?: HumeClient . RequestOptions ) : Promise < Hume . JobRequest > {
257274 const _response = await core . fetcher ( {
258275 url : urlJoin (
259- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
276+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
260277 `v0/batch/jobs/${ id } `
261278 ) ,
262279 method : "GET" ,
263280 headers : {
264- "X-Hume-Api-Key" : await core . Supplier . get ( this . options . apiKey ) ,
281+ "X-Hume-Api-Key" : await core . Supplier . get ( this . _options . apiKey ) ,
265282 "X-Fern-Language" : "JavaScript" ,
266283 "X-Fern-SDK-Name" : "@fern-api/hume" ,
267- "X-Fern-SDK-Version" : "0.0.10 " ,
284+ "X-Fern-SDK-Version" : "0.1.0 " ,
268285 } ,
269286 contentType : "application/json" ,
270- timeoutMs : 60000 ,
287+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
288+ maxRetries : requestOptions ?. maxRetries ,
271289 } ) ;
272290 if ( _response . ok ) {
273291 return await serializers . JobRequest . parseOrThrow ( _response . body , {
0 commit comments