wriftai 0.51.0 → 0.53.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.d.ts CHANGED
@@ -1,6 +1,46 @@
1
+ /**
2
+ * Represents contents of a file.
3
+ */
4
+ type FileContent = File | Blob | Uint8Array;
5
+ /**
6
+ * Represents a file.
7
+ */
8
+ declare class FileData {
9
+ /** Contents of the file. */
10
+ readonly content: FileContent;
11
+ /** MIME type of the file. */
12
+ readonly mimeType: string;
13
+ /**
14
+ * Initializes a file.
15
+ * @param content Contents of the file.
16
+ * @param mimeType MIME type of the file, overriding the inferred value.
17
+ * If omitted, it is inferred from the file object's `type` property when
18
+ * available, otherwise from the file extension in its `name` property.
19
+ * Falls back to `application/octet-stream` if it cannot be inferred.
20
+ */
21
+ constructor(content: FileContent, mimeType?: string);
22
+ /**
23
+ * Guesses the MIME type.
24
+ * Prefers the file's own type, while falling back to
25
+ * extension lookup.
26
+ * @param file Contents of the file.
27
+ * @returns The resolved mime type.
28
+ */
29
+ private static resolveMimeType;
30
+ }
31
+
32
+ /**
33
+ * A JSON-compatible value.
34
+ */
1
35
  type JsonValue = string | number | boolean | null | JsonValue[] | {
2
36
  [key: string]: JsonValue;
3
37
  };
38
+ /**
39
+ * A JSON-compatible value that may include files.
40
+ */
41
+ type JsonValueWithFile = JsonValueWithFile[] | {
42
+ [key: string]: JsonValueWithFile;
43
+ } | string | boolean | number | FileData | null;
4
44
  /**
5
45
  * Represents input and output schemas.
6
46
  */
@@ -75,10 +115,6 @@ interface ModelVersion {
75
115
  * The time when the model version was created.
76
116
  */
77
117
  created_at: string;
78
- /**
79
- * A sha256 hash digest of the model version's container image.
80
- */
81
- container_image_digest: string;
82
118
  }
83
119
  /**
84
120
  * Represents a model version with details.
@@ -93,6 +129,14 @@ interface ModelVersionWithDetails extends ModelVersion {
93
129
  * supported by the version.
94
130
  */
95
131
  compatibilities: Compatibilities;
132
+ /**
133
+ * The total compressed size in bytes of the container image.
134
+ */
135
+ size?: number;
136
+ /**
137
+ * A sha256 hash digest of the model version's container image.
138
+ */
139
+ container_image_digest?: string;
96
140
  }
97
141
  /**
98
142
  * Represents a user with basic details.
@@ -197,6 +241,10 @@ interface Model {
197
241
  * The categories associated with the model.
198
242
  */
199
243
  categories: ModelCategory[];
244
+ /**
245
+ * The cover image url of the model.
246
+ */
247
+ cover_image_url: string | null;
200
248
  }
201
249
  /** Pagination options interface */
202
250
  type PaginationOptions = {
@@ -400,6 +448,124 @@ declare abstract class Resource {
400
448
  protected parseModelIdentifier(identifier: string): [owner: string, name: string];
401
449
  }
402
450
 
451
+ /**
452
+ * Represents an upload.
453
+ */
454
+ interface Upload {
455
+ /**
456
+ * The urls used to upload the file.
457
+ */
458
+ urls: string[];
459
+ /**
460
+ * The identifier for the upload.
461
+ */
462
+ id: string;
463
+ /**
464
+ * The size, in bytes, of each part. All parts
465
+ * are this size except the last one, which may be
466
+ * smaller. If the upload consists of a single part,
467
+ * this value equals the total file size.
468
+ */
469
+ part_size: number;
470
+ }
471
+ /**
472
+ * Parameters for creating an upload.
473
+ */
474
+ type CreateUploadParams = {
475
+ /**
476
+ * The size of the file to upload in bytes.
477
+ * This should be the exact size of the file.
478
+ * Any mismatch will result in an error or a corrupt file being uploaded.
479
+ */
480
+ size: number;
481
+ /**
482
+ * The MIME type of the file.
483
+ */
484
+ mime_type: string;
485
+ };
486
+ /**
487
+ * Parameters for completing an upload.
488
+ */
489
+ type CompleteUploadParams = {
490
+ /**
491
+ * The list of etags of the uploaded parts
492
+ * matching the ordering of urls.
493
+ */
494
+ etags: string[];
495
+ };
496
+ /**
497
+ * Resource for operations related to uploads.
498
+ */
499
+ declare class Uploads extends Resource {
500
+ private readonly UPLOADS_API_PREFIX;
501
+ /**
502
+ * Create an upload.
503
+ * @param params Upload creation parameters.
504
+ * @param signal Optional AbortSignal to cancel the request.
505
+ * @returns The new upload.
506
+ */
507
+ create(params: CreateUploadParams, signal?: AbortSignal): Promise<Upload>;
508
+ /**
509
+ * Complete an upload.
510
+ * @param id The unique identifier of the upload.
511
+ * @param params Parameters to complete an upload.
512
+ * @param signal Optional AbortSignal to cancel the request.
513
+ * @returns The completion result.
514
+ */
515
+ complete(id: string, params: CompleteUploadParams, signal?: AbortSignal): Promise<UploadCompletionResult>;
516
+ }
517
+
518
+ /**
519
+ * Resource for operations related to files.
520
+ */
521
+ declare class Files {
522
+ private fetchImpl;
523
+ private headers;
524
+ private uploads;
525
+ /**
526
+ * Create a new Files resource.
527
+ * @param fetchImpl Fetch implementation to use.
528
+ * @param headers Additional headers to send with file upload requests.
529
+ * @param uploads An instance of the uploads resource.
530
+ */
531
+ constructor(fetchImpl: typeof fetch, headers: Record<string, string>, uploads: Uploads);
532
+ /**
533
+ * Uploads a single part and returns its etag.
534
+ * @param url The part's upload url.
535
+ * @param part The part's content.
536
+ * @param mimeType Content type for the part.
537
+ * @param signal Optional abort signal.
538
+ * @returns The uploaded part's etag, or null if the response carried
539
+ * no etag header.
540
+ */
541
+ private uploadPart;
542
+ /**
543
+ * Uploads a blob in parts concurrently and returns any collected ETags.
544
+ * If any part fails, remaining in-flight parts are aborted rather
545
+ * than left to complete.
546
+ * @param body File content to upload.
547
+ * @param urls Part upload URLs.
548
+ * @param partSize Size of each part in bytes.
549
+ * @param mimeType Content type for uploaded parts.
550
+ * @param signal Optional abort signal.
551
+ * @returns Collected ETags from successful uploads.
552
+ */
553
+ private uploadParts;
554
+ /**
555
+ * Upload a file.
556
+ * The upload is streamed, but the underlying data may already be
557
+ * in memory depending on how `file` was constructed.
558
+ * For example, a browser `File` from an `<input>` or Node's
559
+ * `openAsBlob()` stream from disk, while `new Blob([buffer])` or
560
+ * `Uint8Array` require the data to already be in memory.
561
+ * Large files are split into parts by the server and uploaded concurrently.
562
+ * @param file The file to upload.
563
+ * @param signal Optional AbortSignal to cancel the request.
564
+ * @returns Result of the completed upload.
565
+ */
566
+ upload(file: FileData, signal?: AbortSignal): Promise<UploadCompletionResult>;
567
+ }
568
+
403
569
  /**
404
570
  * Enumeration of possible error sources.
405
571
  */
@@ -497,6 +663,12 @@ interface PredictionWithDetails extends Prediction {
497
663
  * Usage metrics returned by the model.
498
664
  */
499
665
  metrics: Record<string, JsonValue> | null;
666
+ /**
667
+ * Whether the prediction supports streaming.
668
+ * This value may change to false if streaming is no longer
669
+ * available for the prediction, such as after it has expired.
670
+ */
671
+ stream: boolean;
500
672
  }
501
673
  /**
502
674
  * Represents webhook details.
@@ -518,7 +690,7 @@ interface CreatePredictionParams {
518
690
  /**
519
691
  * Input data provided for the prediction.
520
692
  */
521
- input: Record<string, JsonValue>;
693
+ input: Record<string, JsonValueWithFile>;
522
694
  /**
523
695
  * Details about the webhook to post prediction updates to.
524
696
  */
@@ -565,6 +737,13 @@ type PredictionPaginationOptions = PaginationOptions & {
565
737
  */
566
738
  declare class PredictionsResource extends Resource {
567
739
  private readonly PREDICTIONS_API_PREFIX;
740
+ private files;
741
+ /**
742
+ * Initializes the Predictions resource.
743
+ * @param api An instance of the API class.
744
+ * @param files An instance of the Files class.
745
+ */
746
+ constructor(api: API, files: Files);
568
747
  /**
569
748
  * Get a prediction by its ID.
570
749
  * @param id The ID of the prediction to fetch.
@@ -578,10 +757,19 @@ declare class PredictionsResource extends Resource {
578
757
  * @param signal Optional AbortSignal to cancel the request.
579
758
  */
580
759
  cancel(id: string, signal?: AbortSignal): Promise<void>;
760
+ /**
761
+ * Recursively uploads FileData instances and
762
+ * replaces them with download URLs.
763
+ * @param value The value to traverse.
764
+ * @param limit Limiter restricting concurrent uploads.
765
+ * @returns The rebuilt input with files replaced by download URLs.
766
+ */
767
+ private fileUploader;
581
768
  /**
582
769
  * Create a prediction.
583
770
  * This method creates a prediction using either the latest version of a model
584
- * or a specific model version.
771
+ * or a specific model version. Files in the input are uploaded concurrently
772
+ * before the prediction is created.
585
773
  * @param options Options for prediction creation.
586
774
  * @param wait If True, waits until the prediction reaches a terminal state.
587
775
  * If False, returns the prediction immediately. Defaults to False.
@@ -1039,37 +1227,6 @@ declare class ModelCategories extends Resource {
1039
1227
  list(options?: PaginationOptions, signal?: AbortSignal): Promise<PaginatedResponse<ModelCategoryWithDetails>>;
1040
1228
  }
1041
1229
 
1042
- /**
1043
- * Represents contents of a file.
1044
- */
1045
- type FileContent = File | Blob | Uint8Array;
1046
- /**
1047
- * Represents a file.
1048
- */
1049
- declare class FileData {
1050
- /** Contents of the file. */
1051
- readonly content: FileContent;
1052
- /** MIME type of the file. */
1053
- readonly mimeType: string;
1054
- /**
1055
- * Initializes a file.
1056
- * @param content Contents of the file.
1057
- * @param mimeType MIME type of the file, overriding the inferred value.
1058
- * If omitted, it is inferred from the file object's `type` property when
1059
- * available, otherwise from the file extension in its `name` property.
1060
- * Falls back to `application/octet-stream` if it cannot be inferred.
1061
- */
1062
- constructor(content: FileContent, mimeType?: string);
1063
- /**
1064
- * Guesses the MIME type.
1065
- * Prefers the file's own type, while falling back to
1066
- * extension lookup.
1067
- * @param file Contents of the file.
1068
- * @returns The resolved mime type.
1069
- */
1070
- private static resolveMimeType;
1071
- }
1072
-
1073
1230
  /**
1074
1231
  * Represents a variable
1075
1232
  */
@@ -1230,73 +1387,6 @@ declare class WebhookTimestampOutsideToleranceError extends WebhookSignatureVeri
1230
1387
  */
1231
1388
  declare function verify(payload: Uint8Array, signature: string, secret: string, tolerance?: number, scheme?: string, keyCacheSize?: number): Promise<void>;
1232
1389
 
1233
- /**
1234
- * Represents an upload.
1235
- */
1236
- interface Upload {
1237
- /**
1238
- * The urls used to upload the file.
1239
- */
1240
- urls: string[];
1241
- /**
1242
- * The identifier for the upload.
1243
- */
1244
- id: string;
1245
- /**
1246
- * The size, in bytes, of each part. All parts
1247
- * are this size except the last one, which may be
1248
- * smaller. If the upload consists of a single part,
1249
- * this value equals the total file size.
1250
- */
1251
- part_size: number;
1252
- }
1253
- /**
1254
- * Parameters for creating an upload.
1255
- */
1256
- type CreateUploadParams = {
1257
- /**
1258
- * The size of the file to upload in bytes.
1259
- * This should be the exact size of the file.
1260
- * Any mismatch will result in an error or a corrupt file being uploaded.
1261
- */
1262
- size: number;
1263
- /**
1264
- * The MIME type of the file.
1265
- */
1266
- mime_type: string;
1267
- };
1268
- /**
1269
- * Parameters for completing an upload.
1270
- */
1271
- type CompleteUploadParams = {
1272
- /**
1273
- * The list of etags of the uploaded parts
1274
- * matching the ordering of urls.
1275
- */
1276
- etags: string[];
1277
- };
1278
- /**
1279
- * Resource for operations related to uploads.
1280
- */
1281
- declare class Uploads extends Resource {
1282
- private readonly UPLOADS_API_PREFIX;
1283
- /**
1284
- * Create an upload.
1285
- * @param params Upload creation parameters.
1286
- * @param signal Optional AbortSignal to cancel the request.
1287
- * @returns The new upload.
1288
- */
1289
- create(params: CreateUploadParams, signal?: AbortSignal): Promise<Upload>;
1290
- /**
1291
- * Complete an upload.
1292
- * @param id The unique identifier of the upload.
1293
- * @param params Parameters to complete an upload.
1294
- * @param signal Optional AbortSignal to cancel the request.
1295
- * @returns The completion result.
1296
- */
1297
- complete(id: string, params: CompleteUploadParams, signal?: AbortSignal): Promise<UploadCompletionResult>;
1298
- }
1299
-
1300
1390
  /**
1301
1391
  * Parameters for updating a user.
1302
1392
  */
@@ -1353,71 +1443,6 @@ declare class AuthenticatedUser extends Resource {
1353
1443
  models(options?: PaginationOptions, signal?: AbortSignal): Promise<PaginatedResponse<Model>>;
1354
1444
  }
1355
1445
 
1356
- /**
1357
- * Resource for operations related to files.
1358
- */
1359
- declare class Files {
1360
- private fetchImpl;
1361
- private headers;
1362
- private uploads;
1363
- private readonly MAX_CONCURRENT_PARTS;
1364
- /**
1365
- * Create a new Files resource.
1366
- * @param fetchImpl Fetch implementation to use.
1367
- * @param headers Additional headers to send with file upload requests.
1368
- * @param uploads An instance of the uploads resource.
1369
- */
1370
- constructor(fetchImpl: typeof fetch, headers: Record<string, string>, uploads: Uploads);
1371
- /**
1372
- * Uploads a single part and returns its etag.
1373
- * @param url The part's upload url.
1374
- * @param part The part's content.
1375
- * @param mimeType Content type for the part.
1376
- * @param signal Optional abort signal.
1377
- * @returns The uploaded part's etag, or null if the response carried
1378
- * no etag header.
1379
- */
1380
- private uploadPart;
1381
- /**
1382
- * Claims and uploads parts by calling `next` until it returns
1383
- * undefined, returning each claimed part's index and etag.
1384
- * @param body File content to upload.
1385
- * @param urls Part upload URLs.
1386
- * @param partSize Size of each part in bytes.
1387
- * @param next Claims the next unclaimed part index, shared across
1388
- * workers; returns undefined once no parts remain.
1389
- * @param mimeType Content type for each part.
1390
- * @param signal Optional abort signal.
1391
- * @returns The index and etag of every part this worker uploaded.
1392
- */
1393
- private uploadWorker;
1394
- /**
1395
- * Uploads a blob in parts concurrently and returns any collected ETags.
1396
- * If any part fails, remaining in-flight parts are aborted rather
1397
- * than left to complete.
1398
- * @param body File content to upload.
1399
- * @param urls Part upload URLs.
1400
- * @param partSize Size of each part in bytes.
1401
- * @param mimeType Content type for uploaded parts.
1402
- * @param signal Optional abort signal.
1403
- * @returns Collected ETags from successful uploads.
1404
- */
1405
- private uploadParts;
1406
- /**
1407
- * Upload a file.
1408
- * The upload is streamed, but the underlying data may already be
1409
- * in memory depending on how `file` was constructed.
1410
- * For example, a browser `File` from an `<input>` or Node's
1411
- * `openAsBlob()` stream from disk, while `new Blob([buffer])` or
1412
- * `Uint8Array` require the data to already be in memory.
1413
- * Large files are split into parts by the server and uploaded concurrently.
1414
- * @param file The file to upload.
1415
- * @param signal Optional AbortSignal to cancel the request.
1416
- * @returns Result of the completed upload.
1417
- */
1418
- upload(file: FileData, signal?: AbortSignal): Promise<UploadCompletionResult>;
1419
- }
1420
-
1421
1446
  interface WriftAIClientOptions {
1422
1447
  /**
1423
1448
  * Optional base URL for the API. It must not contain