wriftai 0.54.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/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
- * @param options.method The HTTP method to use
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 request(path, options) {
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
- // handle empty-body responses safely
183
- if (res.status === 204) {
184
- return undefined;
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
- return res.json();
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 signal Optional AbortSignal to cancel the request.
541
+ * @param options Options for the call.
415
542
  * @returns Result of the completed upload.
416
543
  */
417
- async upload(file, signal) {
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
- }, signal);
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 }, signal);
557
+ return await this.uploads.complete(upload.id, { etags, signal });
429
558
  }
430
559
  }
431
560
 
@@ -488,6 +617,13 @@ exports.Status = void 0;
488
617
  * Default wait options.
489
618
  */
490
619
  const DEFAULT_WAIT_OPTIONS = { pollInterval: 1000 };
620
+ /**
621
+ * Default wait options for prediction creation.
622
+ */
623
+ const DEFAULT_CREATE_WAIT_OPTIONS = {
624
+ ...DEFAULT_WAIT_OPTIONS,
625
+ poll: true,
626
+ };
491
627
  /**
492
628
  * Resource class for interacting with predictions.
493
629
  */
@@ -506,25 +642,25 @@ class PredictionsResource extends Resource {
506
642
  /**
507
643
  * Get a prediction by its ID.
508
644
  * @param id The ID of the prediction to fetch.
509
- * @param signal Optional AbortSignal to cancel the request.
645
+ * @param options Options for the call.
510
646
  * @returns The prediction object.
511
647
  */
512
- async get(id, signal) {
648
+ async get(id, options) {
513
649
  const response = await this.api.request(`${this.PREDICTIONS_API_PREFIX}/${id}`, {
514
650
  method: 'GET',
515
- signal,
651
+ signal: options?.signal,
516
652
  });
517
653
  return response;
518
654
  }
519
655
  /**
520
656
  * Cancel a prediction by its ID.
521
657
  * @param id The ID of the prediction to cancel.
522
- * @param signal Optional AbortSignal to cancel the request.
658
+ * @param options Options for the call.
523
659
  */
524
- async cancel(id, signal) {
660
+ async cancel(id, options) {
525
661
  await this.api.request(`${this.PREDICTIONS_API_PREFIX}/${id}/cancel`, {
526
662
  method: 'POST',
527
- signal,
663
+ signal: options?.signal,
528
664
  });
529
665
  }
530
666
  /**
@@ -537,7 +673,7 @@ class PredictionsResource extends Resource {
537
673
  async fileUploader(value, limit) {
538
674
  if (value instanceof FileData) {
539
675
  return limit(async (signal) => {
540
- const uploaded = await this.files.upload(value, signal);
676
+ const uploaded = await this.files.upload(value, { signal });
541
677
  return uploaded.download_url;
542
678
  });
543
679
  }
@@ -550,51 +686,84 @@ class PredictionsResource extends Resource {
550
686
  }
551
687
  return value;
552
688
  }
689
+ /**
690
+ * Build request headers for a prediction create call.
691
+ * @param params Parameters for prediction creation.
692
+ * @param waitOptions Wait options, or undefined if not waiting.
693
+ * @returns The headers to send.
694
+ */
695
+ buildCreateHeaders(params, waitOptions) {
696
+ const headers = {};
697
+ if (params.validateInput !== undefined) {
698
+ headers['Validate-Input'] = String(params.validateInput);
699
+ }
700
+ if (waitOptions) {
701
+ headers['Prefer'] =
702
+ waitOptions.duration === undefined
703
+ ? 'wait'
704
+ : `wait=${String(waitOptions.duration)}`;
705
+ }
706
+ return headers;
707
+ }
708
+ /**
709
+ * Determines whether a prediction status is terminal.
710
+ * @param status The current prediction status.
711
+ * @returns whether the status is terminal.
712
+ */
713
+ static isStatusTerminal(status) {
714
+ return (status === exports.Status.succeeded ||
715
+ status === exports.Status.failed ||
716
+ status === exports.Status.cancelled ||
717
+ status === exports.Status.abandoned);
718
+ }
553
719
  /**
554
720
  * Create a prediction.
555
721
  * This method creates a prediction using either the latest version of a model
556
722
  * or a specific model version. Files in the input are uploaded concurrently
557
723
  * before the prediction is created.
558
- * @param options Options for prediction creation.
559
- * @param wait If True, waits until the prediction reaches a terminal state.
560
- * If False, returns the prediction immediately. Defaults to False.
561
- * @param waitOptions Options for customizing wait behavior. If not provided,
562
- * {@link DEFAULT_WAIT_OPTIONS} are used.
563
- * @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.
564
728
  * @returns The new prediction.
565
729
  */
566
- async create(options, wait = false, waitOptions = DEFAULT_WAIT_OPTIONS, signal) {
567
- const { input, webhook, validate_input, model } = options;
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);
568
739
  const uploadedInput = await this.fileUploader(input, createConcurrencyLimit(16, signal));
569
740
  const body = {
570
741
  model,
571
742
  input: uploadedInput,
572
743
  ...(webhook !== undefined && { webhook }),
573
744
  };
574
- const headers = validate_input !== undefined
575
- ? { 'Validate-Input': String(validate_input) }
576
- : undefined;
577
745
  const prediction = await this.api.request(this.PREDICTIONS_API_PREFIX, {
578
746
  method: 'POST',
579
747
  body,
580
748
  headers,
581
749
  signal,
582
750
  });
583
- if (wait) {
584
- return await this.wait(prediction.id, waitOptions, signal);
751
+ if (waitOptions?.poll &&
752
+ !PredictionsResource.isStatusTerminal(prediction.status)) {
753
+ return await this.wait(prediction.id, { ...waitOptions, signal });
585
754
  }
586
755
  return prediction;
587
756
  }
588
757
  /**
589
758
  * List predictions.
590
- * @param options Optional settings to control pagination behavior.
591
- * @param signal Optional AbortSignal to cancel the request.
759
+ * @param options Options for listing predictions.
592
760
  * @returns Paginated response containing predictions and navigation metadata.
593
761
  */
594
- async list(options, signal) {
762
+ async list(options) {
763
+ const { signal, ...query } = options ?? {};
595
764
  const response = await this.api.request(this.PREDICTIONS_API_PREFIX, {
596
765
  method: 'GET',
597
- params: options,
766
+ params: query,
598
767
  signal,
599
768
  });
600
769
  return response;
@@ -604,13 +773,16 @@ class PredictionsResource extends Resource {
604
773
  * This method uses short polling to check the prediction status at
605
774
  * regular intervals until it reaches a terminal state.
606
775
  * @param predictionID The ID of the prediction.
607
- * @param options Options for customizing wait behavior. If not provided,
608
- * {@link DEFAULT_WAIT_OPTIONS} are used.
609
- * @param signal Optional AbortSignal that can be used to cancel the polling
610
- * operation.
776
+ * @param options Options for waiting. Any omitted values use
777
+ * {@link DEFAULT_WAIT_OPTIONS}.
611
778
  * @returns Prediction after completion.
612
779
  */
613
- async wait(predictionID, options = DEFAULT_WAIT_OPTIONS, signal) {
780
+ async wait(predictionID, options) {
781
+ const { signal, ...waitOptions } = options ?? {};
782
+ const mergedOptions = {
783
+ ...DEFAULT_WAIT_OPTIONS,
784
+ ...waitOptions,
785
+ };
614
786
  const sleep = (delay, signal) => {
615
787
  return new Promise((resolve, reject) => {
616
788
  let timeout = undefined;
@@ -646,17 +818,14 @@ class PredictionsResource extends Resource {
646
818
  });
647
819
  };
648
820
  for (;;) {
649
- const result = await this.get(predictionID, signal);
650
- if (options.onPoll) {
651
- await options.onPoll(result);
821
+ const result = await this.get(predictionID, { signal });
822
+ if (mergedOptions.onPoll) {
823
+ await mergedOptions.onPoll(result);
652
824
  }
653
- if (result.status === exports.Status.failed ||
654
- result.status === exports.Status.succeeded ||
655
- result.status === exports.Status.cancelled ||
656
- result.status === exports.Status.abandoned) {
825
+ if (PredictionsResource.isStatusTerminal(result['status'])) {
657
826
  return result;
658
827
  }
659
- await sleep(options.pollInterval, signal);
828
+ await sleep(mergedOptions.pollInterval, signal);
660
829
  }
661
830
  }
662
831
  }
@@ -701,13 +870,13 @@ class ModelVersions extends Resource {
701
870
  * Get a model version.
702
871
  * @param identifier The model version identifier in owner/name:version-number
703
872
  * format (for example: deepseek-ai/deepseek-r1:2).
704
- * @param signal Optional AbortSignal to cancel the request.
873
+ * @param options Options for the call.
705
874
  * @returns The model version object.
706
875
  */
707
- async get(identifier, signal) {
876
+ async get(identifier, options) {
708
877
  const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
709
878
  const response = await this.api.request(`${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
710
- `${this.MODEL_VERSION_PATH}/${number}`, { method: 'GET', signal });
879
+ `${this.MODEL_VERSION_PATH}/${number}`, { method: 'GET', signal: options?.signal });
711
880
  return response;
712
881
  }
713
882
  /**
@@ -715,16 +884,16 @@ class ModelVersions extends Resource {
715
884
  * @param identifier The model identifier in owner/name format
716
885
  * (for example: deepseek-ai/deepseek-r1).
717
886
  * @param params Model version creation parameters.
718
- * @param signal Optional AbortSignal to cancel the request.
719
887
  * @returns The new version object.
720
888
  */
721
- async create(identifier, params, signal) {
889
+ async create(identifier, params) {
890
+ const { signal, ...body } = params;
722
891
  const [modelOwner, modelName] = this.parseModelIdentifier(identifier);
723
892
  const path = `${this.MODELS_API_PREFIX}/${modelOwner}/` +
724
893
  `${modelName}${this.MODEL_VERSION_PATH}`;
725
894
  const response = await this.api.request(path, {
726
895
  method: 'POST',
727
- body: params,
896
+ body,
728
897
  signal,
729
898
  });
730
899
  return response;
@@ -733,31 +902,31 @@ class ModelVersions extends Resource {
733
902
  * Delete a model version.
734
903
  * @param identifier The model version identifier in owner/name:version-number
735
904
  * format (for example: deepseek-ai/deepseek-r1:2).
736
- * @param signal Optional AbortSignal to cancel the request.
905
+ * @param options Options for the call.
737
906
  */
738
- async delete(identifier, signal) {
907
+ async delete(identifier, options) {
739
908
  const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
740
909
  await this.api.request(`${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
741
910
  `${this.MODEL_VERSION_PATH}/${number}`, {
742
911
  method: 'DELETE',
743
- signal,
912
+ signal: options?.signal,
744
913
  });
745
914
  }
746
915
  /**
747
916
  * List model versions.
748
917
  * @param identifier The model identifier in owner/name format
749
918
  * (for example: deepseek-ai/deepseek-r1).
750
- * @param options Pagination options.
751
- * @param signal Optional AbortSignal to cancel the request.
919
+ * @param options Options for listing model versions.
752
920
  * @returns A paginated response containing model versions.
753
921
  */
754
- async list(identifier, options, signal) {
922
+ async list(identifier, options) {
923
+ const { signal, ...query } = options ?? {};
755
924
  const [modelOwner, modelName] = this.parseModelIdentifier(identifier);
756
925
  const path = `${this.MODELS_API_PREFIX}/${modelOwner}/` +
757
926
  `${modelName}${this.MODEL_VERSION_PATH}`;
758
927
  const response = await this.api.request(path, {
759
928
  method: 'GET',
760
- params: options,
929
+ params: query,
761
930
  signal,
762
931
  });
763
932
  return response;
@@ -767,16 +936,16 @@ class ModelVersions extends Resource {
767
936
  * @param identifier The model version identifier in owner/name:version-number
768
937
  * format (for example: deepseek-ai/deepseek-r1:1).
769
938
  * @param params Parameters for updating the configuration.
770
- * @param signal Optional AbortSignal to cancel the request.
771
939
  * @returns The updated model version configuration.
772
940
  */
773
- async updateConfiguration(identifier, params, signal) {
941
+ async updateConfiguration(identifier, params) {
942
+ const { signal, ...body } = params;
774
943
  const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
775
944
  const path = `${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
776
945
  `${this.MODEL_VERSION_PATH}/${number}${this.CONFIGURATION_PATH}`;
777
946
  const response = await this.api.request(path, {
778
947
  method: 'PATCH',
779
- body: params,
948
+ body,
780
949
  signal,
781
950
  });
782
951
  return response;
@@ -785,16 +954,16 @@ class ModelVersions extends Resource {
785
954
  * Get the configuration of a model version.
786
955
  * @param identifier The model version identifier in owner/name:version-number
787
956
  * format (for example: deepseek-ai/deepseek-r1:1).
788
- * @param signal Optional AbortSignal to cancel the request.
957
+ * @param options Options for the call.
789
958
  * @returns The model version configuration.
790
959
  */
791
- async getConfiguration(identifier, signal) {
960
+ async getConfiguration(identifier, options) {
792
961
  const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
793
962
  const path = `${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
794
963
  `${this.MODEL_VERSION_PATH}/${number}${this.CONFIGURATION_PATH}`;
795
964
  const response = await this.api.request(path, {
796
965
  method: 'GET',
797
- signal,
966
+ signal: options?.signal,
798
967
  });
799
968
  return response;
800
969
  }
@@ -834,25 +1003,25 @@ class Models extends Resource {
834
1003
  * Delete a model.
835
1004
  * @param identifier The model identifier in owner/name format
836
1005
  * (for example: deepseek-ai/deepseek-r1).
837
- * @param signal Optional AbortSignal to cancel the request.
1006
+ * @param options Options for the call.
838
1007
  */
839
- async delete(identifier, signal) {
1008
+ async delete(identifier, options) {
840
1009
  const [owner, name] = this.parseModelIdentifier(identifier);
841
1010
  await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
842
1011
  method: 'DELETE',
843
- signal,
1012
+ signal: options?.signal,
844
1013
  });
845
1014
  }
846
1015
  /**
847
1016
  * Create a model.
848
- * @param options Parameters for creating a model.
849
- * @param signal Optional AbortSignal to cancel the request.
1017
+ * @param params Parameters for creating a model.
850
1018
  * @returns The new model.
851
1019
  */
852
- async create(options, signal) {
1020
+ async create(params) {
1021
+ const { signal, ...body } = params;
853
1022
  const response = await this.api.request(this.MODELS_API_PREFIX, {
854
1023
  method: 'POST',
855
- body: options,
1024
+ body,
856
1025
  signal,
857
1026
  });
858
1027
  return response;
@@ -861,14 +1030,14 @@ class Models extends Resource {
861
1030
  * Get a model.
862
1031
  * @param identifier The model identifier in owner/name format
863
1032
  * (for example: deepseek-ai/deepseek-r1).
864
- * @param signal Optional AbortSignal to cancel the request.
1033
+ * @param options Options for the call.
865
1034
  * @returns A model object.
866
1035
  */
867
- async get(identifier, signal) {
1036
+ async get(identifier, options) {
868
1037
  const [owner, name] = this.parseModelIdentifier(identifier);
869
1038
  const response = await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
870
1039
  method: 'GET',
871
- signal,
1040
+ signal: options?.signal,
872
1041
  });
873
1042
  return response;
874
1043
  }
@@ -885,17 +1054,16 @@ class Models extends Resource {
885
1054
  }
886
1055
  /**
887
1056
  * List models.
888
- * @param options Optional settings to control pagination behavior.
889
- * @param owner Optional name of the model's owner to fetch models for.
890
- * If not passed, all models are fetched.
891
- * @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.
892
1059
  * @returns Paginated response containing models and navigation metadata.
893
1060
  */
894
- async list(options, owner, signal) {
1061
+ async list(options) {
1062
+ const { owner, signal, ...query } = options ?? {};
895
1063
  const path = this.buildListPath(owner);
896
1064
  const response = await this.api.request(path, {
897
1065
  method: 'GET',
898
- params: options,
1066
+ params: query,
899
1067
  signal,
900
1068
  });
901
1069
  return response;
@@ -904,15 +1072,15 @@ class Models extends Resource {
904
1072
  * Update a model.
905
1073
  * @param identifier The model identifier in owner/name format
906
1074
  * (for example: deepseek-ai/deepseek-r1).
907
- * @param params The fields to update.
908
- * @param signal Optional AbortSignal to cancel the request.
1075
+ * @param params Parameters for updating the model.
909
1076
  * @returns The updated model.
910
1077
  */
911
- async update(identifier, params, signal) {
1078
+ async update(identifier, params) {
1079
+ const { signal, ...body } = params;
912
1080
  const [owner, name] = this.parseModelIdentifier(identifier);
913
1081
  const response = await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
914
1082
  method: 'PATCH',
915
- body: params,
1083
+ body,
916
1084
  signal,
917
1085
  });
918
1086
  return response;
@@ -920,15 +1088,12 @@ class Models extends Resource {
920
1088
  /**
921
1089
  * Search models.
922
1090
  * @param q The search query.
923
- * @param options Optional settings to control pagination behavior.
924
- * @param signal Optional AbortSignal to cancel the request.
1091
+ * @param options Options for the search.
925
1092
  * @returns Paginated response containing models and navigation metadata.
926
1093
  */
927
- async search(q, options, signal) {
928
- const params = {
929
- ...(options ?? {}),
930
- q,
931
- };
1094
+ async search(q, options) {
1095
+ const { signal, ...query } = options ?? {};
1096
+ const params = { ...query, q };
932
1097
  const response = await this.api.request(`${this.SEARCH_API_PREFIX}/models`, {
933
1098
  method: 'GET',
934
1099
  params: params,
@@ -953,23 +1118,23 @@ class Users extends Resource {
953
1118
  /**
954
1119
  * Fetch a user by their name.
955
1120
  * @param name The name of the user.
956
- * @param signal Optional AbortSignal to cancel the request.
1121
+ * @param options Options for the call.
957
1122
  * @returns The user object.
958
1123
  */
959
- async get(name, signal) {
960
- 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 });
961
1126
  return response;
962
1127
  }
963
1128
  /**
964
1129
  * List users.
965
- * @param options Optional settings to control pagination behavior.
966
- * @param signal Optional AbortSignal to cancel the request.
1130
+ * @param options Options for listing users.
967
1131
  * @returns Paginated response containing users and navigation metadata.
968
1132
  */
969
- async list(options, signal) {
1133
+ async list(options) {
1134
+ const { signal, ...query } = options ?? {};
970
1135
  const response = await this.api.request(this.API_PREFIX, {
971
1136
  method: 'GET',
972
- params: options,
1137
+ params: query,
973
1138
  signal,
974
1139
  });
975
1140
  return response;
@@ -977,15 +1142,12 @@ class Users extends Resource {
977
1142
  /**
978
1143
  * Search users.
979
1144
  * @param q The search query.
980
- * @param options Optional settings to control pagination behavior.
981
- * @param signal Optional AbortSignal to cancel the request.
1145
+ * @param options Options for the search.
982
1146
  * @returns Paginated response containing users and navigation metadata.
983
1147
  */
984
- async search(q, options, signal) {
985
- const params = {
986
- ...(options ?? {}),
987
- q,
988
- };
1148
+ async search(q, options) {
1149
+ const { signal, ...query } = options ?? {};
1150
+ const params = { ...query, q };
989
1151
  const response = await this.api.request(`${this.SEARCH_API_PREFIX}/users`, {
990
1152
  method: 'GET',
991
1153
  params: params,
@@ -1050,16 +1212,11 @@ class WebhookTimestampOutsideToleranceError extends WebhookSignatureVerification
1050
1212
  }
1051
1213
  /**
1052
1214
  * Verify webhook signature.
1053
- * @param payload Raw webhook request body.
1054
- * @param signature The signature to verify.
1055
- * @param secret The webhook secret.
1056
- * @param tolerance Maximum allowed age of the timestamp in seconds.
1057
- * Defaults to 300.
1058
- * @param scheme Key for signatures in the signature. Defaults to "v1".
1059
- * @param keyCacheSize Maximum number of HMAC keys to keep in the
1060
- * module-scoped cache. When exceeded, the oldest cached key is evicted.
1061
- * This is a performance optimization only. Defaults to 50. Set to 0 or
1062
- * 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.
1063
1220
  * @throws {WebhookNoTimestampError} Error thrown when the timestamp is
1064
1221
  * missing from the signature.
1065
1222
  * @throws {WebhookNoSignatureError} Error thrown when a signature
@@ -1069,7 +1226,8 @@ class WebhookTimestampOutsideToleranceError extends WebhookSignatureVerification
1069
1226
  * @throws {WebhookTimestampOutsideToleranceError} Error thrown when the
1070
1227
  * timestamp is outside the tolerance window.
1071
1228
  */
1072
- async function verify(payload, signature, secret, tolerance = 300, scheme = 'v1', keyCacheSize = 50) {
1229
+ async function verify(params) {
1230
+ const { payload, signature, secret, tolerance = 300, scheme = 'v1', keyCacheSize = 50, } = params;
1073
1231
  const { timestamp, matchedSignature } = parseSignature(signature, scheme);
1074
1232
  verifyTimestamp(timestamp, tolerance);
1075
1233
  const timestampBytes = textEncoder.encode(`${String(timestamp)}.`);
@@ -1251,40 +1409,40 @@ class AuthenticatedUser extends Resource {
1251
1409
  API_PREFIX = '/user';
1252
1410
  /**
1253
1411
  * Get the authenticated user.
1254
- * @param signal - Optional AbortSignal to cancel the request.
1412
+ * @param options - Options for the call.
1255
1413
  * @returns The user object.
1256
1414
  */
1257
- async get(signal) {
1415
+ async get(options) {
1258
1416
  const response = await this.api.request(this.API_PREFIX, {
1259
1417
  method: 'GET',
1260
- signal,
1418
+ signal: options?.signal,
1261
1419
  });
1262
1420
  return response;
1263
1421
  }
1264
1422
  /**
1265
1423
  * Update the authenticated user.
1266
- * @param params - The fields to update.
1267
- * @param signal - Optional AbortSignal to cancel the request.
1424
+ * @param params - Parameters for updating the user.
1268
1425
  * @returns The updated user object.
1269
1426
  */
1270
- async update(params, signal) {
1427
+ async update(params) {
1428
+ const { signal, ...body } = params;
1271
1429
  const response = await this.api.request(this.API_PREFIX, {
1272
1430
  method: 'PATCH',
1273
- body: params,
1431
+ body,
1274
1432
  signal,
1275
1433
  });
1276
1434
  return response;
1277
1435
  }
1278
1436
  /**
1279
1437
  * List models of the authenticated user.
1280
- * @param options - Optional settings to control pagination behavior.
1281
- * @param signal - Optional AbortSignal to cancel the request.
1438
+ * @param options - Options for listing models.
1282
1439
  * @returns A paginated response containing models and navigation metadata.
1283
1440
  */
1284
- async models(options, signal) {
1441
+ async models(options) {
1442
+ const { signal, ...query } = options ?? {};
1285
1443
  const response = await this.api.request(`${this.API_PREFIX}/models`, {
1286
1444
  method: 'GET',
1287
- params: options,
1445
+ params: query,
1288
1446
  signal,
1289
1447
  });
1290
1448
  return response;
@@ -1297,14 +1455,14 @@ class AuthenticatedUser extends Resource {
1297
1455
  class HardwareResource extends Resource {
1298
1456
  /**
1299
1457
  * List hardware.
1300
- * @param options Optional settings to control pagination behavior.
1301
- * @param signal Optional AbortSignal to cancel the request.
1458
+ * @param options Options for listing hardware.
1302
1459
  * @returns Paginated response containing hardware and navigation metadata.
1303
1460
  */
1304
- async list(options, signal) {
1461
+ async list(options) {
1462
+ const { signal, ...query } = options ?? {};
1305
1463
  const response = await this.api.request('/hardware', {
1306
1464
  method: 'GET',
1307
- params: options,
1465
+ params: query,
1308
1466
  signal,
1309
1467
  });
1310
1468
  return response;
@@ -1317,15 +1475,15 @@ class HardwareResource extends Resource {
1317
1475
  class ModelCategories extends Resource {
1318
1476
  /**
1319
1477
  * List model categories.
1320
- * @param options Optional settings to control pagiantion behavior.
1321
- * @param signal Optional AbortSignal to cancel request.
1478
+ * @param options Options for listing model categories.
1322
1479
  * @returns Paginated response containing model categories and
1323
1480
  * navigation metadata.
1324
1481
  */
1325
- async list(options, signal) {
1482
+ async list(options) {
1483
+ const { signal, ...query } = options ?? {};
1326
1484
  const response = await this.api.request('/model_categories', {
1327
1485
  method: 'GET',
1328
- params: options,
1486
+ params: query,
1329
1487
  signal,
1330
1488
  });
1331
1489
  return response;
@@ -1340,13 +1498,13 @@ class Variables extends Resource {
1340
1498
  /**
1341
1499
  * Create a new variable.
1342
1500
  * @param params Parameters for creating the variable.
1343
- * @param signal Optional abort signal.
1344
1501
  * @returns The created variable.
1345
1502
  */
1346
- async create(params, signal) {
1503
+ async create(params) {
1504
+ const { signal, ...body } = params;
1347
1505
  const response = await this.api.request(this.VARIABLES_API_PREFIX, {
1348
1506
  method: 'POST',
1349
- body: params,
1507
+ body,
1350
1508
  signal,
1351
1509
  });
1352
1510
  return response;
@@ -1354,39 +1512,39 @@ class Variables extends Resource {
1354
1512
  /**
1355
1513
  * Delete a variable.
1356
1514
  * @param name The name of the variable to be deleted.
1357
- * @param signal Optional abort signal.
1515
+ * @param options Options for the call.
1358
1516
  */
1359
- async delete(name, signal) {
1517
+ async delete(name, options) {
1360
1518
  await this.api.request(`${this.VARIABLES_API_PREFIX}/${name}`, {
1361
1519
  method: 'DELETE',
1362
- signal,
1520
+ signal: options?.signal,
1363
1521
  });
1364
1522
  }
1365
1523
  /**
1366
1524
  * Update a variable.
1367
1525
  * @param name The name of the variable to be updated.
1368
1526
  * @param params The parameters for updating the variable.
1369
- * @param signal Optional abort signal.
1370
1527
  * @returns The updated variable.
1371
1528
  */
1372
- async update(name, params, signal) {
1529
+ async update(name, params) {
1530
+ const { signal, ...body } = params;
1373
1531
  const response = await this.api.request(`${this.VARIABLES_API_PREFIX}/${name}`, {
1374
1532
  method: 'PATCH',
1375
- body: params,
1533
+ body,
1376
1534
  signal,
1377
1535
  });
1378
1536
  return response;
1379
1537
  }
1380
1538
  /**
1381
1539
  * List variables.
1382
- * @param options Optional settings to control pagination behavior.
1383
- * @param signal Optional abort signal.
1540
+ * @param options Options for listing variables.
1384
1541
  * @returns Paginated response containing variables and navigation metadata.
1385
1542
  */
1386
- async list(options, signal) {
1543
+ async list(options) {
1544
+ const { signal, ...query } = options ?? {};
1387
1545
  const response = await this.api.request(this.VARIABLES_API_PREFIX, {
1388
1546
  method: 'GET',
1389
- params: options,
1547
+ params: query,
1390
1548
  signal,
1391
1549
  });
1392
1550
  return response;
@@ -1401,13 +1559,13 @@ class Uploads extends Resource {
1401
1559
  /**
1402
1560
  * Create an upload.
1403
1561
  * @param params Upload creation parameters.
1404
- * @param signal Optional AbortSignal to cancel the request.
1405
1562
  * @returns The new upload.
1406
1563
  */
1407
- async create(params, signal) {
1564
+ async create(params) {
1565
+ const { signal, ...body } = params;
1408
1566
  const response = await this.api.request(this.UPLOADS_API_PREFIX, {
1409
1567
  method: 'POST',
1410
- body: params,
1568
+ body,
1411
1569
  signal,
1412
1570
  });
1413
1571
  return response;
@@ -1416,13 +1574,13 @@ class Uploads extends Resource {
1416
1574
  * Complete an upload.
1417
1575
  * @param id The unique identifier of the upload.
1418
1576
  * @param params Parameters to complete an upload.
1419
- * @param signal Optional AbortSignal to cancel the request.
1420
1577
  * @returns The completion result.
1421
1578
  */
1422
- async complete(id, params, signal) {
1579
+ async complete(id, params) {
1580
+ const { signal, ...body } = params;
1423
1581
  const response = await this.api.request(`${this.UPLOADS_API_PREFIX}/${id}/complete`, {
1424
1582
  method: 'POST',
1425
- body: params,
1583
+ body,
1426
1584
  signal,
1427
1585
  });
1428
1586
  return response;
@@ -1517,7 +1675,7 @@ class WriftAI {
1517
1675
  // Window" errors).
1518
1676
  const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
1519
1677
  const defaultHeaders = {
1520
- 'User-Agent': 'wriftai-javascript/' + "0.54.0",
1678
+ 'User-Agent': 'wriftai-javascript/' + "0.56.0",
1521
1679
  ...options.headers,
1522
1680
  };
1523
1681
  this.api = new API(apiBaseUrl, fetchImpl, maxRetries, accessToken, defaultHeaders);
@@ -1534,6 +1692,7 @@ class WriftAI {
1534
1692
  }
1535
1693
  }
1536
1694
 
1695
+ exports.DEFAULT_CREATE_WAIT_OPTIONS = DEFAULT_CREATE_WAIT_OPTIONS;
1537
1696
  exports.DEFAULT_WAIT_OPTIONS = DEFAULT_WAIT_OPTIONS;
1538
1697
  exports.FileData = FileData;
1539
1698
  exports.InvalidIdentifierError = InvalidIdentifierError;