wriftai 0.55.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -8
- package/dist/index.cjs +288 -175
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +215 -147
- package/dist/index.mjs +288 -175
- package/dist/index.mjs.map +1 -1
- package/dist/wriftai.umd.min.js +2 -2
- package/dist/wriftai.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,71 @@
|
|
|
2
2
|
|
|
3
3
|
var mrmime = require('mrmime');
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Incrementally decodes a server-sent events byte stream.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately not a full WHATWG implementation. Upstream output is
|
|
9
|
+
* validated by the platform, so we only handle what it can emit:
|
|
10
|
+
* `\n` and `\r\n` line endings (no lone `\r`), no leading BOM, and
|
|
11
|
+
* no `retry` field (unknown fields are ignored). `data` is always JSON.
|
|
12
|
+
*
|
|
13
|
+
* Holds the state of one stream, so use a new decoder per connection.
|
|
14
|
+
*/
|
|
15
|
+
class SSEDecoder {
|
|
16
|
+
buffer = '';
|
|
17
|
+
id = '';
|
|
18
|
+
event = '';
|
|
19
|
+
data = [];
|
|
20
|
+
decoder = new TextDecoder('utf-8');
|
|
21
|
+
/**
|
|
22
|
+
* Feeds the next chunk of the stream.
|
|
23
|
+
* @param chunk Raw bytes of any size.
|
|
24
|
+
* @returns The events completed by this chunk, in order.
|
|
25
|
+
*/
|
|
26
|
+
feed(chunk) {
|
|
27
|
+
const text = this.decoder.decode(chunk, { stream: true });
|
|
28
|
+
this.buffer += text;
|
|
29
|
+
// no complete line yet, so don't re-split a long partial line per chunk.
|
|
30
|
+
if (!text.includes('\n'))
|
|
31
|
+
return [];
|
|
32
|
+
const lines = this.buffer.split('\n');
|
|
33
|
+
// split() always returns at least one element.
|
|
34
|
+
this.buffer = lines.pop();
|
|
35
|
+
const events = [];
|
|
36
|
+
for (const rawLine of lines) {
|
|
37
|
+
const line = rawLine.endsWith('\r') ? rawLine.slice(0, -1) : rawLine;
|
|
38
|
+
// blank line ends the event
|
|
39
|
+
if (line === '') {
|
|
40
|
+
if (this.data.length > 0) {
|
|
41
|
+
events.push({
|
|
42
|
+
id: this.id,
|
|
43
|
+
event: this.event,
|
|
44
|
+
data: JSON.parse(this.data.join('\n')),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
this.data = [];
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const colon = line.indexOf(':');
|
|
51
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
52
|
+
let value = colon === -1 ? '' : line.slice(colon + 1);
|
|
53
|
+
if (value.startsWith(' ')) {
|
|
54
|
+
value = value.slice(1);
|
|
55
|
+
}
|
|
56
|
+
if (field === 'id') {
|
|
57
|
+
this.id = value;
|
|
58
|
+
}
|
|
59
|
+
else if (field === 'event') {
|
|
60
|
+
this.event = value;
|
|
61
|
+
}
|
|
62
|
+
else if (field === 'data') {
|
|
63
|
+
this.data.push(value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return events;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
5
70
|
/**
|
|
6
71
|
* Representation of an error from WriftAI's API.
|
|
7
72
|
*/
|
|
@@ -32,6 +97,7 @@ class API {
|
|
|
32
97
|
fetchImpl;
|
|
33
98
|
maxRetries;
|
|
34
99
|
defaultHeaders;
|
|
100
|
+
static SSE_HEADERS = { 'Accept-Encoding': 'identity' };
|
|
35
101
|
/**
|
|
36
102
|
* Create an instance of the API client.
|
|
37
103
|
* @param baseUrl Base URL for the API without trailing slashes.
|
|
@@ -125,23 +191,11 @@ class API {
|
|
|
125
191
|
}
|
|
126
192
|
/**
|
|
127
193
|
* Sends an HTTP request with automatic retries on transient errors.
|
|
128
|
-
* @template T The expected JSON response shape
|
|
129
194
|
* @param path The path relative to `baseUrl` (e.g. `/users`)
|
|
130
195
|
* @param options Request options
|
|
131
|
-
* @
|
|
132
|
-
* @param options.params Optional query parameters. Entries
|
|
133
|
-
* with `undefined` values are silently skipped.
|
|
134
|
-
* @param options.body Optional JSON-serializable body
|
|
135
|
-
* @param options.headers Optional extra request headers
|
|
136
|
-
* @param options.signal Optional AbortSignal to cancel the request.
|
|
137
|
-
* @returns The parsed JSON response
|
|
138
|
-
* @throws {WriftAIAPIError} If the response is not ok (`!res.ok`)
|
|
139
|
-
* @example
|
|
140
|
-
* ```ts
|
|
141
|
-
* const users = await client.request<User[]>("/users", { method: "GET" });
|
|
142
|
-
* ```
|
|
196
|
+
* @returns The successful response with its body not yet read.
|
|
143
197
|
*/
|
|
144
|
-
async
|
|
198
|
+
async send(path, options) {
|
|
145
199
|
const url = new URL(this.baseUrl + path);
|
|
146
200
|
if (options.params) {
|
|
147
201
|
for (const [k, v] of Object.entries(options.params)) {
|
|
@@ -179,11 +233,84 @@ class API {
|
|
|
179
233
|
const errorBody = await res.text();
|
|
180
234
|
throw new WriftAIAPIError(res.status, errorBody, url.toString());
|
|
181
235
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
236
|
+
return res;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Sends an HTTP request with automatic retries on transient errors.
|
|
241
|
+
* @template T The expected JSON response shape
|
|
242
|
+
* @param path The path relative to `baseUrl` (e.g. `/users`)
|
|
243
|
+
* @param options Request options
|
|
244
|
+
* @returns The parsed JSON response
|
|
245
|
+
* @throws {WriftAIAPIError} If the response is not ok (`!res.ok`)
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* const users = await client.request<User[]>("/users", { method: "GET" });
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
async request(path, options) {
|
|
252
|
+
const res = await this.send(path, options);
|
|
253
|
+
// handle empty-body responses safely
|
|
254
|
+
if (res.status === 204) {
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
return res.json();
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Iterates over server-sent events from a streaming HTTP response.
|
|
261
|
+
* Consumes the response body incrementally, decodes SSE messages as
|
|
262
|
+
* chunks arrive, and yields each completed event in order.
|
|
263
|
+
* @param response The streaming HTTP response containing SSE data.
|
|
264
|
+
* @yields Decoded server-sent events from the response stream.
|
|
265
|
+
*/
|
|
266
|
+
static async *iterEvents(response) {
|
|
267
|
+
if (!response.body) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const decoder = new SSEDecoder();
|
|
271
|
+
const reader = response.body.getReader();
|
|
272
|
+
try {
|
|
273
|
+
for (;;) {
|
|
274
|
+
const { done, value } = await reader.read();
|
|
275
|
+
if (done)
|
|
276
|
+
break;
|
|
277
|
+
for (const event of decoder.feed(value)) {
|
|
278
|
+
yield event;
|
|
279
|
+
}
|
|
185
280
|
}
|
|
186
|
-
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
// getReader() creates a reader and locks the stream to it.
|
|
284
|
+
// No other reader can be acquired until the lock is released.
|
|
285
|
+
reader.releaseLock();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Opens a single server-sent events (SSE) connection.
|
|
290
|
+
* The request is sent when iteration begins and the connection remains
|
|
291
|
+
* open until the stream ends, iteration stops, or the consumer cancels
|
|
292
|
+
* the operation. Retries on transient errors apply only while opening
|
|
293
|
+
* the connection.
|
|
294
|
+
* @param path The path relative to `baseUrl` (e.g. `/events`)
|
|
295
|
+
* @param options Request options
|
|
296
|
+
* @yields Decoded server-sent events from the connection in the order
|
|
297
|
+
* they are received.
|
|
298
|
+
*/
|
|
299
|
+
async *streamSSE(path, options) {
|
|
300
|
+
const response = await this.send(path, {
|
|
301
|
+
...options,
|
|
302
|
+
headers: {
|
|
303
|
+
...options.headers,
|
|
304
|
+
...API.SSE_HEADERS,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
try {
|
|
308
|
+
yield* API.iterEvents(response);
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
// Clean up the response stream when consumption stops early
|
|
312
|
+
// or an error is thrown.
|
|
313
|
+
await response.body?.cancel();
|
|
187
314
|
}
|
|
188
315
|
}
|
|
189
316
|
}
|
|
@@ -411,10 +538,11 @@ class Files {
|
|
|
411
538
|
* `Uint8Array` require the data to already be in memory.
|
|
412
539
|
* Large files are split into parts by the server and uploaded concurrently.
|
|
413
540
|
* @param file The file to upload.
|
|
414
|
-
* @param
|
|
541
|
+
* @param options Options for the call.
|
|
415
542
|
* @returns Result of the completed upload.
|
|
416
543
|
*/
|
|
417
|
-
async upload(file,
|
|
544
|
+
async upload(file, options) {
|
|
545
|
+
const signal = options?.signal;
|
|
418
546
|
// wrap Uint8Array in a Blob.
|
|
419
547
|
const body = file.content instanceof Blob
|
|
420
548
|
? file.content
|
|
@@ -423,9 +551,10 @@ class Files {
|
|
|
423
551
|
const upload = await this.uploads.create({
|
|
424
552
|
size,
|
|
425
553
|
mime_type: file.mimeType,
|
|
426
|
-
|
|
554
|
+
signal,
|
|
555
|
+
});
|
|
427
556
|
const etags = await this.uploadParts(body, upload.urls, upload.part_size, file.mimeType, signal);
|
|
428
|
-
return await this.uploads.complete(upload.id, { etags
|
|
557
|
+
return await this.uploads.complete(upload.id, { etags, signal });
|
|
429
558
|
}
|
|
430
559
|
}
|
|
431
560
|
|
|
@@ -513,25 +642,25 @@ class PredictionsResource extends Resource {
|
|
|
513
642
|
/**
|
|
514
643
|
* Get a prediction by its ID.
|
|
515
644
|
* @param id The ID of the prediction to fetch.
|
|
516
|
-
* @param
|
|
645
|
+
* @param options Options for the call.
|
|
517
646
|
* @returns The prediction object.
|
|
518
647
|
*/
|
|
519
|
-
async get(id,
|
|
648
|
+
async get(id, options) {
|
|
520
649
|
const response = await this.api.request(`${this.PREDICTIONS_API_PREFIX}/${id}`, {
|
|
521
650
|
method: 'GET',
|
|
522
|
-
signal,
|
|
651
|
+
signal: options?.signal,
|
|
523
652
|
});
|
|
524
653
|
return response;
|
|
525
654
|
}
|
|
526
655
|
/**
|
|
527
656
|
* Cancel a prediction by its ID.
|
|
528
657
|
* @param id The ID of the prediction to cancel.
|
|
529
|
-
* @param
|
|
658
|
+
* @param options Options for the call.
|
|
530
659
|
*/
|
|
531
|
-
async cancel(id,
|
|
660
|
+
async cancel(id, options) {
|
|
532
661
|
await this.api.request(`${this.PREDICTIONS_API_PREFIX}/${id}/cancel`, {
|
|
533
662
|
method: 'POST',
|
|
534
|
-
signal,
|
|
663
|
+
signal: options?.signal,
|
|
535
664
|
});
|
|
536
665
|
}
|
|
537
666
|
/**
|
|
@@ -544,7 +673,7 @@ class PredictionsResource extends Resource {
|
|
|
544
673
|
async fileUploader(value, limit) {
|
|
545
674
|
if (value instanceof FileData) {
|
|
546
675
|
return limit(async (signal) => {
|
|
547
|
-
const uploaded = await this.files.upload(value, signal);
|
|
676
|
+
const uploaded = await this.files.upload(value, { signal });
|
|
548
677
|
return uploaded.download_url;
|
|
549
678
|
});
|
|
550
679
|
}
|
|
@@ -559,18 +688,16 @@ class PredictionsResource extends Resource {
|
|
|
559
688
|
}
|
|
560
689
|
/**
|
|
561
690
|
* Build request headers for a prediction create call.
|
|
562
|
-
* @param
|
|
563
|
-
* @param
|
|
564
|
-
* @param waitOptions Options for customizing wait behaviour.
|
|
565
|
-
* Only used when wait is true.
|
|
691
|
+
* @param params Parameters for prediction creation.
|
|
692
|
+
* @param waitOptions Wait options, or undefined if not waiting.
|
|
566
693
|
* @returns The headers to send.
|
|
567
694
|
*/
|
|
568
|
-
buildCreateHeaders(
|
|
695
|
+
buildCreateHeaders(params, waitOptions) {
|
|
569
696
|
const headers = {};
|
|
570
|
-
if (
|
|
571
|
-
headers['Validate-Input'] = String(
|
|
697
|
+
if (params.validateInput !== undefined) {
|
|
698
|
+
headers['Validate-Input'] = String(params.validateInput);
|
|
572
699
|
}
|
|
573
|
-
if (
|
|
700
|
+
if (waitOptions) {
|
|
574
701
|
headers['Prefer'] =
|
|
575
702
|
waitOptions.duration === undefined
|
|
576
703
|
? 'wait'
|
|
@@ -594,22 +721,21 @@ class PredictionsResource extends Resource {
|
|
|
594
721
|
* This method creates a prediction using either the latest version of a model
|
|
595
722
|
* or a specific model version. Files in the input are uploaded concurrently
|
|
596
723
|
* before the prediction is created.
|
|
597
|
-
* @param
|
|
598
|
-
*
|
|
599
|
-
|
|
600
|
-
*
|
|
601
|
-
* @param waitOptions Optional overrides for wait behavior. Any omitted values
|
|
602
|
-
* use {@link DEFAULT_CREATE_WAIT_OPTIONS}.
|
|
603
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
724
|
+
* @param params Parameters for prediction creation.
|
|
725
|
+
* If `wait` is set, the prediction is awaited until it finishes; `true`
|
|
726
|
+
* uses {@link DEFAULT_CREATE_WAIT_OPTIONS} and an object overrides
|
|
727
|
+
* individual values. Otherwise it is returned immediately.
|
|
604
728
|
* @returns The new prediction.
|
|
605
729
|
*/
|
|
606
|
-
async create(
|
|
607
|
-
const { input, webhook, model } =
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
730
|
+
async create(params) {
|
|
731
|
+
const { input, webhook, model, wait, signal } = params;
|
|
732
|
+
const waitOptions = wait
|
|
733
|
+
? {
|
|
734
|
+
...DEFAULT_CREATE_WAIT_OPTIONS,
|
|
735
|
+
...(wait === true ? undefined : wait),
|
|
736
|
+
}
|
|
737
|
+
: undefined;
|
|
738
|
+
const headers = this.buildCreateHeaders(params, waitOptions);
|
|
613
739
|
const uploadedInput = await this.fileUploader(input, createConcurrencyLimit(16, signal));
|
|
614
740
|
const body = {
|
|
615
741
|
model,
|
|
@@ -622,23 +748,22 @@ class PredictionsResource extends Resource {
|
|
|
622
748
|
headers,
|
|
623
749
|
signal,
|
|
624
750
|
});
|
|
625
|
-
if (
|
|
626
|
-
mergedWaitOptions.poll &&
|
|
751
|
+
if (waitOptions?.poll &&
|
|
627
752
|
!PredictionsResource.isStatusTerminal(prediction.status)) {
|
|
628
|
-
return await this.wait(prediction.id,
|
|
753
|
+
return await this.wait(prediction.id, { ...waitOptions, signal });
|
|
629
754
|
}
|
|
630
755
|
return prediction;
|
|
631
756
|
}
|
|
632
757
|
/**
|
|
633
758
|
* List predictions.
|
|
634
|
-
* @param options
|
|
635
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
759
|
+
* @param options Options for listing predictions.
|
|
636
760
|
* @returns Paginated response containing predictions and navigation metadata.
|
|
637
761
|
*/
|
|
638
|
-
async list(options
|
|
762
|
+
async list(options) {
|
|
763
|
+
const { signal, ...query } = options ?? {};
|
|
639
764
|
const response = await this.api.request(this.PREDICTIONS_API_PREFIX, {
|
|
640
765
|
method: 'GET',
|
|
641
|
-
params:
|
|
766
|
+
params: query,
|
|
642
767
|
signal,
|
|
643
768
|
});
|
|
644
769
|
return response;
|
|
@@ -648,16 +773,15 @@ class PredictionsResource extends Resource {
|
|
|
648
773
|
* This method uses short polling to check the prediction status at
|
|
649
774
|
* regular intervals until it reaches a terminal state.
|
|
650
775
|
* @param predictionID The ID of the prediction.
|
|
651
|
-
* @param options
|
|
652
|
-
*
|
|
653
|
-
* @param signal Optional AbortSignal that can be used to cancel the polling
|
|
654
|
-
* operation.
|
|
776
|
+
* @param options Options for waiting. Any omitted values use
|
|
777
|
+
* {@link DEFAULT_WAIT_OPTIONS}.
|
|
655
778
|
* @returns Prediction after completion.
|
|
656
779
|
*/
|
|
657
|
-
async wait(predictionID, options
|
|
780
|
+
async wait(predictionID, options) {
|
|
781
|
+
const { signal, ...waitOptions } = options ?? {};
|
|
658
782
|
const mergedOptions = {
|
|
659
783
|
...DEFAULT_WAIT_OPTIONS,
|
|
660
|
-
...
|
|
784
|
+
...waitOptions,
|
|
661
785
|
};
|
|
662
786
|
const sleep = (delay, signal) => {
|
|
663
787
|
return new Promise((resolve, reject) => {
|
|
@@ -694,7 +818,7 @@ class PredictionsResource extends Resource {
|
|
|
694
818
|
});
|
|
695
819
|
};
|
|
696
820
|
for (;;) {
|
|
697
|
-
const result = await this.get(predictionID, signal);
|
|
821
|
+
const result = await this.get(predictionID, { signal });
|
|
698
822
|
if (mergedOptions.onPoll) {
|
|
699
823
|
await mergedOptions.onPoll(result);
|
|
700
824
|
}
|
|
@@ -746,13 +870,13 @@ class ModelVersions extends Resource {
|
|
|
746
870
|
* Get a model version.
|
|
747
871
|
* @param identifier The model version identifier in owner/name:version-number
|
|
748
872
|
* format (for example: deepseek-ai/deepseek-r1:2).
|
|
749
|
-
* @param
|
|
873
|
+
* @param options Options for the call.
|
|
750
874
|
* @returns The model version object.
|
|
751
875
|
*/
|
|
752
|
-
async get(identifier,
|
|
876
|
+
async get(identifier, options) {
|
|
753
877
|
const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
|
|
754
878
|
const response = await this.api.request(`${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
|
|
755
|
-
`${this.MODEL_VERSION_PATH}/${number}`, { method: 'GET', signal });
|
|
879
|
+
`${this.MODEL_VERSION_PATH}/${number}`, { method: 'GET', signal: options?.signal });
|
|
756
880
|
return response;
|
|
757
881
|
}
|
|
758
882
|
/**
|
|
@@ -760,16 +884,16 @@ class ModelVersions extends Resource {
|
|
|
760
884
|
* @param identifier The model identifier in owner/name format
|
|
761
885
|
* (for example: deepseek-ai/deepseek-r1).
|
|
762
886
|
* @param params Model version creation parameters.
|
|
763
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
764
887
|
* @returns The new version object.
|
|
765
888
|
*/
|
|
766
|
-
async create(identifier, params
|
|
889
|
+
async create(identifier, params) {
|
|
890
|
+
const { signal, ...body } = params;
|
|
767
891
|
const [modelOwner, modelName] = this.parseModelIdentifier(identifier);
|
|
768
892
|
const path = `${this.MODELS_API_PREFIX}/${modelOwner}/` +
|
|
769
893
|
`${modelName}${this.MODEL_VERSION_PATH}`;
|
|
770
894
|
const response = await this.api.request(path, {
|
|
771
895
|
method: 'POST',
|
|
772
|
-
body
|
|
896
|
+
body,
|
|
773
897
|
signal,
|
|
774
898
|
});
|
|
775
899
|
return response;
|
|
@@ -778,31 +902,31 @@ class ModelVersions extends Resource {
|
|
|
778
902
|
* Delete a model version.
|
|
779
903
|
* @param identifier The model version identifier in owner/name:version-number
|
|
780
904
|
* format (for example: deepseek-ai/deepseek-r1:2).
|
|
781
|
-
* @param
|
|
905
|
+
* @param options Options for the call.
|
|
782
906
|
*/
|
|
783
|
-
async delete(identifier,
|
|
907
|
+
async delete(identifier, options) {
|
|
784
908
|
const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
|
|
785
909
|
await this.api.request(`${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
|
|
786
910
|
`${this.MODEL_VERSION_PATH}/${number}`, {
|
|
787
911
|
method: 'DELETE',
|
|
788
|
-
signal,
|
|
912
|
+
signal: options?.signal,
|
|
789
913
|
});
|
|
790
914
|
}
|
|
791
915
|
/**
|
|
792
916
|
* List model versions.
|
|
793
917
|
* @param identifier The model identifier in owner/name format
|
|
794
918
|
* (for example: deepseek-ai/deepseek-r1).
|
|
795
|
-
* @param options
|
|
796
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
919
|
+
* @param options Options for listing model versions.
|
|
797
920
|
* @returns A paginated response containing model versions.
|
|
798
921
|
*/
|
|
799
|
-
async list(identifier, options
|
|
922
|
+
async list(identifier, options) {
|
|
923
|
+
const { signal, ...query } = options ?? {};
|
|
800
924
|
const [modelOwner, modelName] = this.parseModelIdentifier(identifier);
|
|
801
925
|
const path = `${this.MODELS_API_PREFIX}/${modelOwner}/` +
|
|
802
926
|
`${modelName}${this.MODEL_VERSION_PATH}`;
|
|
803
927
|
const response = await this.api.request(path, {
|
|
804
928
|
method: 'GET',
|
|
805
|
-
params:
|
|
929
|
+
params: query,
|
|
806
930
|
signal,
|
|
807
931
|
});
|
|
808
932
|
return response;
|
|
@@ -812,16 +936,16 @@ class ModelVersions extends Resource {
|
|
|
812
936
|
* @param identifier The model version identifier in owner/name:version-number
|
|
813
937
|
* format (for example: deepseek-ai/deepseek-r1:1).
|
|
814
938
|
* @param params Parameters for updating the configuration.
|
|
815
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
816
939
|
* @returns The updated model version configuration.
|
|
817
940
|
*/
|
|
818
|
-
async updateConfiguration(identifier, params
|
|
941
|
+
async updateConfiguration(identifier, params) {
|
|
942
|
+
const { signal, ...body } = params;
|
|
819
943
|
const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
|
|
820
944
|
const path = `${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
|
|
821
945
|
`${this.MODEL_VERSION_PATH}/${number}${this.CONFIGURATION_PATH}`;
|
|
822
946
|
const response = await this.api.request(path, {
|
|
823
947
|
method: 'PATCH',
|
|
824
|
-
body
|
|
948
|
+
body,
|
|
825
949
|
signal,
|
|
826
950
|
});
|
|
827
951
|
return response;
|
|
@@ -830,16 +954,16 @@ class ModelVersions extends Resource {
|
|
|
830
954
|
* Get the configuration of a model version.
|
|
831
955
|
* @param identifier The model version identifier in owner/name:version-number
|
|
832
956
|
* format (for example: deepseek-ai/deepseek-r1:1).
|
|
833
|
-
* @param
|
|
957
|
+
* @param options Options for the call.
|
|
834
958
|
* @returns The model version configuration.
|
|
835
959
|
*/
|
|
836
|
-
async getConfiguration(identifier,
|
|
960
|
+
async getConfiguration(identifier, options) {
|
|
837
961
|
const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
|
|
838
962
|
const path = `${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
|
|
839
963
|
`${this.MODEL_VERSION_PATH}/${number}${this.CONFIGURATION_PATH}`;
|
|
840
964
|
const response = await this.api.request(path, {
|
|
841
965
|
method: 'GET',
|
|
842
|
-
signal,
|
|
966
|
+
signal: options?.signal,
|
|
843
967
|
});
|
|
844
968
|
return response;
|
|
845
969
|
}
|
|
@@ -879,25 +1003,25 @@ class Models extends Resource {
|
|
|
879
1003
|
* Delete a model.
|
|
880
1004
|
* @param identifier The model identifier in owner/name format
|
|
881
1005
|
* (for example: deepseek-ai/deepseek-r1).
|
|
882
|
-
* @param
|
|
1006
|
+
* @param options Options for the call.
|
|
883
1007
|
*/
|
|
884
|
-
async delete(identifier,
|
|
1008
|
+
async delete(identifier, options) {
|
|
885
1009
|
const [owner, name] = this.parseModelIdentifier(identifier);
|
|
886
1010
|
await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
|
|
887
1011
|
method: 'DELETE',
|
|
888
|
-
signal,
|
|
1012
|
+
signal: options?.signal,
|
|
889
1013
|
});
|
|
890
1014
|
}
|
|
891
1015
|
/**
|
|
892
1016
|
* Create a model.
|
|
893
|
-
* @param
|
|
894
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1017
|
+
* @param params Parameters for creating a model.
|
|
895
1018
|
* @returns The new model.
|
|
896
1019
|
*/
|
|
897
|
-
async create(
|
|
1020
|
+
async create(params) {
|
|
1021
|
+
const { signal, ...body } = params;
|
|
898
1022
|
const response = await this.api.request(this.MODELS_API_PREFIX, {
|
|
899
1023
|
method: 'POST',
|
|
900
|
-
body
|
|
1024
|
+
body,
|
|
901
1025
|
signal,
|
|
902
1026
|
});
|
|
903
1027
|
return response;
|
|
@@ -906,14 +1030,14 @@ class Models extends Resource {
|
|
|
906
1030
|
* Get a model.
|
|
907
1031
|
* @param identifier The model identifier in owner/name format
|
|
908
1032
|
* (for example: deepseek-ai/deepseek-r1).
|
|
909
|
-
* @param
|
|
1033
|
+
* @param options Options for the call.
|
|
910
1034
|
* @returns A model object.
|
|
911
1035
|
*/
|
|
912
|
-
async get(identifier,
|
|
1036
|
+
async get(identifier, options) {
|
|
913
1037
|
const [owner, name] = this.parseModelIdentifier(identifier);
|
|
914
1038
|
const response = await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
|
|
915
1039
|
method: 'GET',
|
|
916
|
-
signal,
|
|
1040
|
+
signal: options?.signal,
|
|
917
1041
|
});
|
|
918
1042
|
return response;
|
|
919
1043
|
}
|
|
@@ -930,17 +1054,16 @@ class Models extends Resource {
|
|
|
930
1054
|
}
|
|
931
1055
|
/**
|
|
932
1056
|
* List models.
|
|
933
|
-
* @param options
|
|
934
|
-
*
|
|
935
|
-
* If not passed, all models are fetched.
|
|
936
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1057
|
+
* @param options Options for listing models. If no owner is given,
|
|
1058
|
+
* all models are listed.
|
|
937
1059
|
* @returns Paginated response containing models and navigation metadata.
|
|
938
1060
|
*/
|
|
939
|
-
async list(options
|
|
1061
|
+
async list(options) {
|
|
1062
|
+
const { owner, signal, ...query } = options ?? {};
|
|
940
1063
|
const path = this.buildListPath(owner);
|
|
941
1064
|
const response = await this.api.request(path, {
|
|
942
1065
|
method: 'GET',
|
|
943
|
-
params:
|
|
1066
|
+
params: query,
|
|
944
1067
|
signal,
|
|
945
1068
|
});
|
|
946
1069
|
return response;
|
|
@@ -949,15 +1072,15 @@ class Models extends Resource {
|
|
|
949
1072
|
* Update a model.
|
|
950
1073
|
* @param identifier The model identifier in owner/name format
|
|
951
1074
|
* (for example: deepseek-ai/deepseek-r1).
|
|
952
|
-
* @param params
|
|
953
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1075
|
+
* @param params Parameters for updating the model.
|
|
954
1076
|
* @returns The updated model.
|
|
955
1077
|
*/
|
|
956
|
-
async update(identifier, params
|
|
1078
|
+
async update(identifier, params) {
|
|
1079
|
+
const { signal, ...body } = params;
|
|
957
1080
|
const [owner, name] = this.parseModelIdentifier(identifier);
|
|
958
1081
|
const response = await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
|
|
959
1082
|
method: 'PATCH',
|
|
960
|
-
body
|
|
1083
|
+
body,
|
|
961
1084
|
signal,
|
|
962
1085
|
});
|
|
963
1086
|
return response;
|
|
@@ -965,15 +1088,12 @@ class Models extends Resource {
|
|
|
965
1088
|
/**
|
|
966
1089
|
* Search models.
|
|
967
1090
|
* @param q The search query.
|
|
968
|
-
* @param options
|
|
969
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1091
|
+
* @param options Options for the search.
|
|
970
1092
|
* @returns Paginated response containing models and navigation metadata.
|
|
971
1093
|
*/
|
|
972
|
-
async search(q, options
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
q,
|
|
976
|
-
};
|
|
1094
|
+
async search(q, options) {
|
|
1095
|
+
const { signal, ...query } = options ?? {};
|
|
1096
|
+
const params = { ...query, q };
|
|
977
1097
|
const response = await this.api.request(`${this.SEARCH_API_PREFIX}/models`, {
|
|
978
1098
|
method: 'GET',
|
|
979
1099
|
params: params,
|
|
@@ -998,23 +1118,23 @@ class Users extends Resource {
|
|
|
998
1118
|
/**
|
|
999
1119
|
* Fetch a user by their name.
|
|
1000
1120
|
* @param name The name of the user.
|
|
1001
|
-
* @param
|
|
1121
|
+
* @param options Options for the call.
|
|
1002
1122
|
* @returns The user object.
|
|
1003
1123
|
*/
|
|
1004
|
-
async get(name,
|
|
1005
|
-
const response = await this.api.request(`${this.API_PREFIX}/${name}`, { method: 'GET', signal });
|
|
1124
|
+
async get(name, options) {
|
|
1125
|
+
const response = await this.api.request(`${this.API_PREFIX}/${name}`, { method: 'GET', signal: options?.signal });
|
|
1006
1126
|
return response;
|
|
1007
1127
|
}
|
|
1008
1128
|
/**
|
|
1009
1129
|
* List users.
|
|
1010
|
-
* @param options
|
|
1011
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1130
|
+
* @param options Options for listing users.
|
|
1012
1131
|
* @returns Paginated response containing users and navigation metadata.
|
|
1013
1132
|
*/
|
|
1014
|
-
async list(options
|
|
1133
|
+
async list(options) {
|
|
1134
|
+
const { signal, ...query } = options ?? {};
|
|
1015
1135
|
const response = await this.api.request(this.API_PREFIX, {
|
|
1016
1136
|
method: 'GET',
|
|
1017
|
-
params:
|
|
1137
|
+
params: query,
|
|
1018
1138
|
signal,
|
|
1019
1139
|
});
|
|
1020
1140
|
return response;
|
|
@@ -1022,15 +1142,12 @@ class Users extends Resource {
|
|
|
1022
1142
|
/**
|
|
1023
1143
|
* Search users.
|
|
1024
1144
|
* @param q The search query.
|
|
1025
|
-
* @param options
|
|
1026
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1145
|
+
* @param options Options for the search.
|
|
1027
1146
|
* @returns Paginated response containing users and navigation metadata.
|
|
1028
1147
|
*/
|
|
1029
|
-
async search(q, options
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1032
|
-
q,
|
|
1033
|
-
};
|
|
1148
|
+
async search(q, options) {
|
|
1149
|
+
const { signal, ...query } = options ?? {};
|
|
1150
|
+
const params = { ...query, q };
|
|
1034
1151
|
const response = await this.api.request(`${this.SEARCH_API_PREFIX}/users`, {
|
|
1035
1152
|
method: 'GET',
|
|
1036
1153
|
params: params,
|
|
@@ -1095,16 +1212,11 @@ class WebhookTimestampOutsideToleranceError extends WebhookSignatureVerification
|
|
|
1095
1212
|
}
|
|
1096
1213
|
/**
|
|
1097
1214
|
* Verify webhook signature.
|
|
1098
|
-
* @param
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
* @param scheme Key for signatures in the signature. Defaults to "v1".
|
|
1104
|
-
* @param keyCacheSize Maximum number of HMAC keys to keep in the
|
|
1105
|
-
* module-scoped cache. When exceeded, the oldest cached key is evicted.
|
|
1106
|
-
* This is a performance optimization only. Defaults to 50. Set to 0 or
|
|
1107
|
-
* a negative value to disable caching.
|
|
1215
|
+
* @param params Parameters for verifying the webhook signature.
|
|
1216
|
+
* `tolerance` defaults to 300, `scheme` defaults to "v1" and `keyCacheSize`
|
|
1217
|
+
* defaults to 50. When the cache size is exceeded, the oldest cached key is
|
|
1218
|
+
* evicted. The cache is a performance optimization only, and a size of 0 or
|
|
1219
|
+
* a negative value disables caching.
|
|
1108
1220
|
* @throws {WebhookNoTimestampError} Error thrown when the timestamp is
|
|
1109
1221
|
* missing from the signature.
|
|
1110
1222
|
* @throws {WebhookNoSignatureError} Error thrown when a signature
|
|
@@ -1114,7 +1226,8 @@ class WebhookTimestampOutsideToleranceError extends WebhookSignatureVerification
|
|
|
1114
1226
|
* @throws {WebhookTimestampOutsideToleranceError} Error thrown when the
|
|
1115
1227
|
* timestamp is outside the tolerance window.
|
|
1116
1228
|
*/
|
|
1117
|
-
async function verify(
|
|
1229
|
+
async function verify(params) {
|
|
1230
|
+
const { payload, signature, secret, tolerance = 300, scheme = 'v1', keyCacheSize = 50, } = params;
|
|
1118
1231
|
const { timestamp, matchedSignature } = parseSignature(signature, scheme);
|
|
1119
1232
|
verifyTimestamp(timestamp, tolerance);
|
|
1120
1233
|
const timestampBytes = textEncoder.encode(`${String(timestamp)}.`);
|
|
@@ -1296,40 +1409,40 @@ class AuthenticatedUser extends Resource {
|
|
|
1296
1409
|
API_PREFIX = '/user';
|
|
1297
1410
|
/**
|
|
1298
1411
|
* Get the authenticated user.
|
|
1299
|
-
* @param
|
|
1412
|
+
* @param options - Options for the call.
|
|
1300
1413
|
* @returns The user object.
|
|
1301
1414
|
*/
|
|
1302
|
-
async get(
|
|
1415
|
+
async get(options) {
|
|
1303
1416
|
const response = await this.api.request(this.API_PREFIX, {
|
|
1304
1417
|
method: 'GET',
|
|
1305
|
-
signal,
|
|
1418
|
+
signal: options?.signal,
|
|
1306
1419
|
});
|
|
1307
1420
|
return response;
|
|
1308
1421
|
}
|
|
1309
1422
|
/**
|
|
1310
1423
|
* Update the authenticated user.
|
|
1311
|
-
* @param params -
|
|
1312
|
-
* @param signal - Optional AbortSignal to cancel the request.
|
|
1424
|
+
* @param params - Parameters for updating the user.
|
|
1313
1425
|
* @returns The updated user object.
|
|
1314
1426
|
*/
|
|
1315
|
-
async update(params
|
|
1427
|
+
async update(params) {
|
|
1428
|
+
const { signal, ...body } = params;
|
|
1316
1429
|
const response = await this.api.request(this.API_PREFIX, {
|
|
1317
1430
|
method: 'PATCH',
|
|
1318
|
-
body
|
|
1431
|
+
body,
|
|
1319
1432
|
signal,
|
|
1320
1433
|
});
|
|
1321
1434
|
return response;
|
|
1322
1435
|
}
|
|
1323
1436
|
/**
|
|
1324
1437
|
* List models of the authenticated user.
|
|
1325
|
-
* @param options -
|
|
1326
|
-
* @param signal - Optional AbortSignal to cancel the request.
|
|
1438
|
+
* @param options - Options for listing models.
|
|
1327
1439
|
* @returns A paginated response containing models and navigation metadata.
|
|
1328
1440
|
*/
|
|
1329
|
-
async models(options
|
|
1441
|
+
async models(options) {
|
|
1442
|
+
const { signal, ...query } = options ?? {};
|
|
1330
1443
|
const response = await this.api.request(`${this.API_PREFIX}/models`, {
|
|
1331
1444
|
method: 'GET',
|
|
1332
|
-
params:
|
|
1445
|
+
params: query,
|
|
1333
1446
|
signal,
|
|
1334
1447
|
});
|
|
1335
1448
|
return response;
|
|
@@ -1342,14 +1455,14 @@ class AuthenticatedUser extends Resource {
|
|
|
1342
1455
|
class HardwareResource extends Resource {
|
|
1343
1456
|
/**
|
|
1344
1457
|
* List hardware.
|
|
1345
|
-
* @param options
|
|
1346
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1458
|
+
* @param options Options for listing hardware.
|
|
1347
1459
|
* @returns Paginated response containing hardware and navigation metadata.
|
|
1348
1460
|
*/
|
|
1349
|
-
async list(options
|
|
1461
|
+
async list(options) {
|
|
1462
|
+
const { signal, ...query } = options ?? {};
|
|
1350
1463
|
const response = await this.api.request('/hardware', {
|
|
1351
1464
|
method: 'GET',
|
|
1352
|
-
params:
|
|
1465
|
+
params: query,
|
|
1353
1466
|
signal,
|
|
1354
1467
|
});
|
|
1355
1468
|
return response;
|
|
@@ -1362,15 +1475,15 @@ class HardwareResource extends Resource {
|
|
|
1362
1475
|
class ModelCategories extends Resource {
|
|
1363
1476
|
/**
|
|
1364
1477
|
* List model categories.
|
|
1365
|
-
* @param options
|
|
1366
|
-
* @param signal Optional AbortSignal to cancel request.
|
|
1478
|
+
* @param options Options for listing model categories.
|
|
1367
1479
|
* @returns Paginated response containing model categories and
|
|
1368
1480
|
* navigation metadata.
|
|
1369
1481
|
*/
|
|
1370
|
-
async list(options
|
|
1482
|
+
async list(options) {
|
|
1483
|
+
const { signal, ...query } = options ?? {};
|
|
1371
1484
|
const response = await this.api.request('/model_categories', {
|
|
1372
1485
|
method: 'GET',
|
|
1373
|
-
params:
|
|
1486
|
+
params: query,
|
|
1374
1487
|
signal,
|
|
1375
1488
|
});
|
|
1376
1489
|
return response;
|
|
@@ -1385,13 +1498,13 @@ class Variables extends Resource {
|
|
|
1385
1498
|
/**
|
|
1386
1499
|
* Create a new variable.
|
|
1387
1500
|
* @param params Parameters for creating the variable.
|
|
1388
|
-
* @param signal Optional abort signal.
|
|
1389
1501
|
* @returns The created variable.
|
|
1390
1502
|
*/
|
|
1391
|
-
async create(params
|
|
1503
|
+
async create(params) {
|
|
1504
|
+
const { signal, ...body } = params;
|
|
1392
1505
|
const response = await this.api.request(this.VARIABLES_API_PREFIX, {
|
|
1393
1506
|
method: 'POST',
|
|
1394
|
-
body
|
|
1507
|
+
body,
|
|
1395
1508
|
signal,
|
|
1396
1509
|
});
|
|
1397
1510
|
return response;
|
|
@@ -1399,39 +1512,39 @@ class Variables extends Resource {
|
|
|
1399
1512
|
/**
|
|
1400
1513
|
* Delete a variable.
|
|
1401
1514
|
* @param name The name of the variable to be deleted.
|
|
1402
|
-
* @param
|
|
1515
|
+
* @param options Options for the call.
|
|
1403
1516
|
*/
|
|
1404
|
-
async delete(name,
|
|
1517
|
+
async delete(name, options) {
|
|
1405
1518
|
await this.api.request(`${this.VARIABLES_API_PREFIX}/${name}`, {
|
|
1406
1519
|
method: 'DELETE',
|
|
1407
|
-
signal,
|
|
1520
|
+
signal: options?.signal,
|
|
1408
1521
|
});
|
|
1409
1522
|
}
|
|
1410
1523
|
/**
|
|
1411
1524
|
* Update a variable.
|
|
1412
1525
|
* @param name The name of the variable to be updated.
|
|
1413
1526
|
* @param params The parameters for updating the variable.
|
|
1414
|
-
* @param signal Optional abort signal.
|
|
1415
1527
|
* @returns The updated variable.
|
|
1416
1528
|
*/
|
|
1417
|
-
async update(name, params
|
|
1529
|
+
async update(name, params) {
|
|
1530
|
+
const { signal, ...body } = params;
|
|
1418
1531
|
const response = await this.api.request(`${this.VARIABLES_API_PREFIX}/${name}`, {
|
|
1419
1532
|
method: 'PATCH',
|
|
1420
|
-
body
|
|
1533
|
+
body,
|
|
1421
1534
|
signal,
|
|
1422
1535
|
});
|
|
1423
1536
|
return response;
|
|
1424
1537
|
}
|
|
1425
1538
|
/**
|
|
1426
1539
|
* List variables.
|
|
1427
|
-
* @param options
|
|
1428
|
-
* @param signal Optional abort signal.
|
|
1540
|
+
* @param options Options for listing variables.
|
|
1429
1541
|
* @returns Paginated response containing variables and navigation metadata.
|
|
1430
1542
|
*/
|
|
1431
|
-
async list(options
|
|
1543
|
+
async list(options) {
|
|
1544
|
+
const { signal, ...query } = options ?? {};
|
|
1432
1545
|
const response = await this.api.request(this.VARIABLES_API_PREFIX, {
|
|
1433
1546
|
method: 'GET',
|
|
1434
|
-
params:
|
|
1547
|
+
params: query,
|
|
1435
1548
|
signal,
|
|
1436
1549
|
});
|
|
1437
1550
|
return response;
|
|
@@ -1446,13 +1559,13 @@ class Uploads extends Resource {
|
|
|
1446
1559
|
/**
|
|
1447
1560
|
* Create an upload.
|
|
1448
1561
|
* @param params Upload creation parameters.
|
|
1449
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1450
1562
|
* @returns The new upload.
|
|
1451
1563
|
*/
|
|
1452
|
-
async create(params
|
|
1564
|
+
async create(params) {
|
|
1565
|
+
const { signal, ...body } = params;
|
|
1453
1566
|
const response = await this.api.request(this.UPLOADS_API_PREFIX, {
|
|
1454
1567
|
method: 'POST',
|
|
1455
|
-
body
|
|
1568
|
+
body,
|
|
1456
1569
|
signal,
|
|
1457
1570
|
});
|
|
1458
1571
|
return response;
|
|
@@ -1461,13 +1574,13 @@ class Uploads extends Resource {
|
|
|
1461
1574
|
* Complete an upload.
|
|
1462
1575
|
* @param id The unique identifier of the upload.
|
|
1463
1576
|
* @param params Parameters to complete an upload.
|
|
1464
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
1465
1577
|
* @returns The completion result.
|
|
1466
1578
|
*/
|
|
1467
|
-
async complete(id, params
|
|
1579
|
+
async complete(id, params) {
|
|
1580
|
+
const { signal, ...body } = params;
|
|
1468
1581
|
const response = await this.api.request(`${this.UPLOADS_API_PREFIX}/${id}/complete`, {
|
|
1469
1582
|
method: 'POST',
|
|
1470
|
-
body
|
|
1583
|
+
body,
|
|
1471
1584
|
signal,
|
|
1472
1585
|
});
|
|
1473
1586
|
return response;
|
|
@@ -1562,7 +1675,7 @@ class WriftAI {
|
|
|
1562
1675
|
// Window" errors).
|
|
1563
1676
|
const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
1564
1677
|
const defaultHeaders = {
|
|
1565
|
-
'User-Agent': 'wriftai-javascript/' + "0.
|
|
1678
|
+
'User-Agent': 'wriftai-javascript/' + "0.56.0",
|
|
1566
1679
|
...options.headers,
|
|
1567
1680
|
};
|
|
1568
1681
|
this.api = new API(apiBaseUrl, fetchImpl, maxRetries, accessToken, defaultHeaders);
|