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