5
5
import * as environments from "./environments" ;
6
6
import * as core from "./core" ;
7
7
import * as Hume from "./api" ;
8
- import { default as URLSearchParams } from "@ungap/url-search-params" ;
9
8
import urlJoin from "url-join" ;
10
9
import * as serializers from "./serialization" ;
11
10
import * as errors from "./errors" ;
@@ -15,62 +14,71 @@ export declare namespace HumeClient {
15
14
environment ?: core . Supplier < environments . HumeEnvironment | string > ;
16
15
apiKey : core . Supplier < string > ;
17
16
}
17
+
18
+ interface RequestOptions {
19
+ timeoutInSeconds ?: number ;
20
+ maxRetries ?: number ;
21
+ }
18
22
}
19
23
20
24
export class HumeClient {
21
- constructor ( protected readonly options : HumeClient . Options ) { }
25
+ constructor ( protected readonly _options : HumeClient . Options ) { }
22
26
23
27
/**
24
28
* Sort and filter jobs.
25
29
*/
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 [ ] > {
27
34
const { limit, status, when, timestampMs, sortBy, direction } = request ;
28
- const _queryParams = new URLSearchParams ( ) ;
35
+ const _queryParams : Record < string , string > = { } ;
29
36
if ( limit != null ) {
30
- _queryParams . append ( "limit" , limit . toString ( ) ) ;
37
+ _queryParams [ "limit" ] = limit . toString ( ) ;
31
38
}
32
39
33
40
if ( status != null ) {
34
41
if ( Array . isArray ( status ) ) {
35
42
for ( const _item of status ) {
36
- _queryParams . append ( "status" , _item ) ;
43
+ _queryParams [ "status" ] = _item ;
37
44
}
38
45
} else {
39
- _queryParams . append ( "status" , status ) ;
46
+ _queryParams [ "status" ] = status ;
40
47
}
41
48
}
42
49
43
50
if ( when != null ) {
44
- _queryParams . append ( "when" , when ) ;
51
+ _queryParams [ "when" ] = when ;
45
52
}
46
53
47
54
if ( timestampMs != null ) {
48
- _queryParams . append ( "timestamp_ms" , timestampMs . toString ( ) ) ;
55
+ _queryParams [ "timestamp_ms" ] = timestampMs . toString ( ) ;
49
56
}
50
57
51
58
if ( sortBy != null ) {
52
- _queryParams . append ( "sort_by" , sortBy ) ;
59
+ _queryParams [ "sort_by" ] = sortBy ;
53
60
}
54
61
55
62
if ( direction != null ) {
56
- _queryParams . append ( "direction" , direction ) ;
63
+ _queryParams [ "direction" ] = direction ;
57
64
}
58
65
59
66
const _response = await core . fetcher ( {
60
67
url : urlJoin (
61
- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
68
+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
62
69
"v0/batch/jobs"
63
70
) ,
64
71
method : "GET" ,
65
72
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 ) ,
67
74
"X-Fern-Language" : "JavaScript" ,
68
75
"X-Fern-SDK-Name" : "@fern-api/hume" ,
69
- "X-Fern-SDK-Version" : "0.0.10 " ,
76
+ "X-Fern-SDK-Version" : "0.1.0 " ,
70
77
} ,
71
78
contentType : "application/json" ,
72
79
queryParameters : _queryParams ,
73
- timeoutMs : 60000 ,
80
+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
81
+ maxRetries : requestOptions ?. maxRetries ,
74
82
} ) ;
75
83
if ( _response . ok ) {
76
84
return await serializers . listJobs . Response . parseOrThrow ( _response . body , {
@@ -106,22 +114,26 @@ export class HumeClient {
106
114
/**
107
115
* Start a new batch job.
108
116
*/
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 > {
110
121
const _response = await core . fetcher ( {
111
122
url : urlJoin (
112
- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
123
+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
113
124
"v0/batch/jobs"
114
125
) ,
115
126
method : "POST" ,
116
127
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 ) ,
118
129
"X-Fern-Language" : "JavaScript" ,
119
130
"X-Fern-SDK-Name" : "@fern-api/hume" ,
120
- "X-Fern-SDK-Version" : "0.0.10 " ,
131
+ "X-Fern-SDK-Version" : "0.1.0 " ,
121
132
} ,
122
133
contentType : "application/json" ,
123
134
body : await serializers . BaseRequest . jsonOrThrow ( request , { unrecognizedObjectKeys : "strip" } ) ,
124
- timeoutMs : 60000 ,
135
+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
136
+ maxRetries : requestOptions ?. maxRetries ,
125
137
} ) ;
126
138
if ( _response . ok ) {
127
139
return await serializers . JobId . parseOrThrow ( _response . body , {
@@ -157,21 +169,25 @@ export class HumeClient {
157
169
/**
158
170
* Get the JSON predictions of a completed job.
159
171
*/
160
- public async getJobPredictions ( id : string ) : Promise < Hume . SourceResult [ ] > {
172
+ public async getJobPredictions (
173
+ id : string ,
174
+ requestOptions ?: HumeClient . RequestOptions
175
+ ) : Promise < Hume . SourceResult [ ] > {
161
176
const _response = await core . fetcher ( {
162
177
url : urlJoin (
163
- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
178
+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
164
179
`v0/batch/jobs/${ id } /predictions`
165
180
) ,
166
181
method : "GET" ,
167
182
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 ) ,
169
184
"X-Fern-Language" : "JavaScript" ,
170
185
"X-Fern-SDK-Name" : "@fern-api/hume" ,
171
- "X-Fern-SDK-Version" : "0.0.10 " ,
186
+ "X-Fern-SDK-Version" : "0.1.0 " ,
172
187
} ,
173
188
contentType : "application/json" ,
174
- timeoutMs : 60000 ,
189
+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
190
+ maxRetries : requestOptions ?. maxRetries ,
175
191
} ) ;
176
192
if ( _response . ok ) {
177
193
return await serializers . getJobPredictions . Response . parseOrThrow ( _response . body , {
@@ -207,22 +223,23 @@ export class HumeClient {
207
223
/**
208
224
* Get the artifacts ZIP of a completed job.
209
225
*/
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 > ( {
212
228
url : urlJoin (
213
- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
229
+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
214
230
`v0/batch/jobs/${ id } /artifacts`
215
231
) ,
216
232
method : "GET" ,
217
233
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 ) ,
219
235
"X-Fern-Language" : "JavaScript" ,
220
236
"X-Fern-SDK-Name" : "@fern-api/hume" ,
221
- "X-Fern-SDK-Version" : "0.0.10 " ,
237
+ "X-Fern-SDK-Version" : "0.1.0 " ,
222
238
} ,
223
239
contentType : "application/json" ,
224
240
responseType : "blob" ,
225
- timeoutMs : 60000 ,
241
+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
242
+ maxRetries : requestOptions ?. maxRetries ,
226
243
} ) ;
227
244
if ( _response . ok ) {
228
245
return _response . body ;
@@ -253,21 +270,22 @@ export class HumeClient {
253
270
/**
254
271
* Get the request details and state of a given job.
255
272
*/
256
- public async getJobDetails ( id : string ) : Promise < Hume . JobRequest > {
273
+ public async getJobDetails ( id : string , requestOptions ?: HumeClient . RequestOptions ) : Promise < Hume . JobRequest > {
257
274
const _response = await core . fetcher ( {
258
275
url : urlJoin (
259
- ( await core . Supplier . get ( this . options . environment ) ) ?? environments . HumeEnvironment . Default ,
276
+ ( await core . Supplier . get ( this . _options . environment ) ) ?? environments . HumeEnvironment . Default ,
260
277
`v0/batch/jobs/${ id } `
261
278
) ,
262
279
method : "GET" ,
263
280
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 ) ,
265
282
"X-Fern-Language" : "JavaScript" ,
266
283
"X-Fern-SDK-Name" : "@fern-api/hume" ,
267
- "X-Fern-SDK-Version" : "0.0.10 " ,
284
+ "X-Fern-SDK-Version" : "0.1.0 " ,
268
285
} ,
269
286
contentType : "application/json" ,
270
- timeoutMs : 60000 ,
287
+ timeoutMs : requestOptions ?. timeoutInSeconds != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
288
+ maxRetries : requestOptions ?. maxRetries ,
271
289
} ) ;
272
290
if ( _response . ok ) {
273
291
return await serializers . JobRequest . parseOrThrow ( _response . body , {
0 commit comments