wriftai 0.52.0 → 0.54.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.
@@ -97,6 +133,10 @@ interface ModelVersionWithDetails extends ModelVersion {
97
133
  * The total compressed size in bytes of the container image.
98
134
  */
99
135
  size?: number;
136
+ /**
137
+ * A sha256 hash digest of the model version's container image.
138
+ */
139
+ container_image_digest?: string;
100
140
  }
101
141
  /**
102
142
  * Represents a user with basic details.
@@ -408,6 +448,124 @@ declare abstract class Resource {
408
448
  protected parseModelIdentifier(identifier: string): [owner: string, name: string];
409
449
  }
410
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
+
411
569
  /**
412
570
  * Enumeration of possible error sources.
413
571
  */
@@ -532,7 +690,7 @@ interface CreatePredictionParams {
532
690
  /**
533
691
  * Input data provided for the prediction.
534
692
  */
535
- input: Record<string, JsonValue>;
693
+ input: Record<string, JsonValueWithFile>;
536
694
  /**
537
695
  * Details about the webhook to post prediction updates to.
538
696
  */
@@ -579,6 +737,13 @@ type PredictionPaginationOptions = PaginationOptions & {
579
737
  */
580
738
  declare class PredictionsResource extends Resource {
581
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);
582
747
  /**
583
748
  * Get a prediction by its ID.
584
749
  * @param id The ID of the prediction to fetch.
@@ -592,10 +757,19 @@ declare class PredictionsResource extends Resource {
592
757
  * @param signal Optional AbortSignal to cancel the request.
593
758
  */
594
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;
595
768
  /**
596
769
  * Create a prediction.
597
770
  * This method creates a prediction using either the latest version of a model
598
- * or a specific model version.
771
+ * or a specific model version. Files in the input are uploaded concurrently
772
+ * before the prediction is created.
599
773
  * @param options Options for prediction creation.
600
774
  * @param wait If True, waits until the prediction reaches a terminal state.
601
775
  * If False, returns the prediction immediately. Defaults to False.
@@ -1053,37 +1227,6 @@ declare class ModelCategories extends Resource {
1053
1227
  list(options?: PaginationOptions, signal?: AbortSignal): Promise<PaginatedResponse<ModelCategoryWithDetails>>;
1054
1228
  }
1055
1229
 
1056
- /**
1057
- * Represents contents of a file.
1058
- */
1059
- type FileContent = File | Blob | Uint8Array;
1060
- /**
1061
- * Represents a file.
1062
- */
1063
- declare class FileData {
1064
- /** Contents of the file. */
1065
- readonly content: FileContent;
1066
- /** MIME type of the file. */
1067
- readonly mimeType: string;
1068
- /**
1069
- * Initializes a file.
1070
- * @param content Contents of the file.
1071
- * @param mimeType MIME type of the file, overriding the inferred value.
1072
- * If omitted, it is inferred from the file object's `type` property when
1073
- * available, otherwise from the file extension in its `name` property.
1074
- * Falls back to `application/octet-stream` if it cannot be inferred.
1075
- */
1076
- constructor(content: FileContent, mimeType?: string);
1077
- /**
1078
- * Guesses the MIME type.
1079
- * Prefers the file's own type, while falling back to
1080
- * extension lookup.
1081
- * @param file Contents of the file.
1082
- * @returns The resolved mime type.
1083
- */
1084
- private static resolveMimeType;
1085
- }
1086
-
1087
1230
  /**
1088
1231
  * Represents a variable
1089
1232
  */
@@ -1144,6 +1287,10 @@ type UpdateVariableParams = {
1144
1287
  * The new value of the variable.
1145
1288
  */
1146
1289
  value?: string;
1290
+ /**
1291
+ * The new key of the variable.
1292
+ */
1293
+ key?: string;
1147
1294
  };
1148
1295
  /**
1149
1296
  * Resource for operations related to variables.
@@ -1244,73 +1391,6 @@ declare class WebhookTimestampOutsideToleranceError extends WebhookSignatureVeri
1244
1391
  */
1245
1392
  declare function verify(payload: Uint8Array, signature: string, secret: string, tolerance?: number, scheme?: string, keyCacheSize?: number): Promise<void>;
1246
1393
 
1247
- /**
1248
- * Represents an upload.
1249
- */
1250
- interface Upload {
1251
- /**
1252
- * The urls used to upload the file.
1253
- */
1254
- urls: string[];
1255
- /**
1256
- * The identifier for the upload.
1257
- */
1258
- id: string;
1259
- /**
1260
- * The size, in bytes, of each part. All parts
1261
- * are this size except the last one, which may be
1262
- * smaller. If the upload consists of a single part,
1263
- * this value equals the total file size.
1264
- */
1265
- part_size: number;
1266
- }
1267
- /**
1268
- * Parameters for creating an upload.
1269
- */
1270
- type CreateUploadParams = {
1271
- /**
1272
- * The size of the file to upload in bytes.
1273
- * This should be the exact size of the file.
1274
- * Any mismatch will result in an error or a corrupt file being uploaded.
1275
- */
1276
- size: number;
1277
- /**
1278
- * The MIME type of the file.
1279
- */
1280
- mime_type: string;
1281
- };
1282
- /**
1283
- * Parameters for completing an upload.
1284
- */
1285
- type CompleteUploadParams = {
1286
- /**
1287
- * The list of etags of the uploaded parts
1288
- * matching the ordering of urls.
1289
- */
1290
- etags: string[];
1291
- };
1292
- /**
1293
- * Resource for operations related to uploads.
1294
- */
1295
- declare class Uploads extends Resource {
1296
- private readonly UPLOADS_API_PREFIX;
1297
- /**
1298
- * Create an upload.
1299
- * @param params Upload creation parameters.
1300
- * @param signal Optional AbortSignal to cancel the request.
1301
- * @returns The new upload.
1302
- */
1303
- create(params: CreateUploadParams, signal?: AbortSignal): Promise<Upload>;
1304
- /**
1305
- * Complete an upload.
1306
- * @param id The unique identifier of the upload.
1307
- * @param params Parameters to complete an upload.
1308
- * @param signal Optional AbortSignal to cancel the request.
1309
- * @returns The completion result.
1310
- */
1311
- complete(id: string, params: CompleteUploadParams, signal?: AbortSignal): Promise<UploadCompletionResult>;
1312
- }
1313
-
1314
1394
  /**
1315
1395
  * Parameters for updating a user.
1316
1396
  */
@@ -1367,71 +1447,6 @@ declare class AuthenticatedUser extends Resource {
1367
1447
  models(options?: PaginationOptions, signal?: AbortSignal): Promise<PaginatedResponse<Model>>;
1368
1448
  }
1369
1449
 
1370
- /**
1371
- * Resource for operations related to files.
1372
- */
1373
- declare class Files {
1374
- private fetchImpl;
1375
- private headers;
1376
- private uploads;
1377
- private readonly MAX_CONCURRENT_PARTS;
1378
- /**
1379
- * Create a new Files resource.
1380
- * @param fetchImpl Fetch implementation to use.
1381
- * @param headers Additional headers to send with file upload requests.
1382
- * @param uploads An instance of the uploads resource.
1383
- */
1384
- constructor(fetchImpl: typeof fetch, headers: Record<string, string>, uploads: Uploads);
1385
- /**
1386
- * Uploads a single part and returns its etag.
1387
- * @param url The part's upload url.
1388
- * @param part The part's content.
1389
- * @param mimeType Content type for the part.
1390
- * @param signal Optional abort signal.
1391
- * @returns The uploaded part's etag, or null if the response carried
1392
- * no etag header.
1393
- */
1394
- private uploadPart;
1395
- /**
1396
- * Claims and uploads parts by calling `next` until it returns
1397
- * undefined, returning each claimed part's index and etag.
1398
- * @param body File content to upload.
1399
- * @param urls Part upload URLs.
1400
- * @param partSize Size of each part in bytes.
1401
- * @param next Claims the next unclaimed part index, shared across
1402
- * workers; returns undefined once no parts remain.
1403
- * @param mimeType Content type for each part.
1404
- * @param signal Optional abort signal.
1405
- * @returns The index and etag of every part this worker uploaded.
1406
- */
1407
- private uploadWorker;
1408
- /**
1409
- * Uploads a blob in parts concurrently and returns any collected ETags.
1410
- * If any part fails, remaining in-flight parts are aborted rather
1411
- * than left to complete.
1412
- * @param body File content to upload.
1413
- * @param urls Part upload URLs.
1414
- * @param partSize Size of each part in bytes.
1415
- * @param mimeType Content type for uploaded parts.
1416
- * @param signal Optional abort signal.
1417
- * @returns Collected ETags from successful uploads.
1418
- */
1419
- private uploadParts;
1420
- /**
1421
- * Upload a file.
1422
- * The upload is streamed, but the underlying data may already be
1423
- * in memory depending on how `file` was constructed.
1424
- * For example, a browser `File` from an `<input>` or Node's
1425
- * `openAsBlob()` stream from disk, while `new Blob([buffer])` or
1426
- * `Uint8Array` require the data to already be in memory.
1427
- * Large files are split into parts by the server and uploaded concurrently.
1428
- * @param file The file to upload.
1429
- * @param signal Optional AbortSignal to cancel the request.
1430
- * @returns Result of the completed upload.
1431
- */
1432
- upload(file: FileData, signal?: AbortSignal): Promise<UploadCompletionResult>;
1433
- }
1434
-
1435
1450
  interface WriftAIClientOptions {
1436
1451
  /**
1437
1452
  * Optional base URL for the API. It must not contain