wriftai 0.37.0 → 0.39.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 +160 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +114 -95
- package/dist/index.mjs +159 -123
- 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.d.ts
CHANGED
|
@@ -267,6 +267,17 @@ declare class API {
|
|
|
267
267
|
}): Promise<T>;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Error thrown when a model identifier is neither in owner/name
|
|
272
|
+
* nor owner/name:version-number format.
|
|
273
|
+
*/
|
|
274
|
+
declare class InvalidModelIdentifierError extends Error {
|
|
275
|
+
/**
|
|
276
|
+
* Creates an instance of the error.
|
|
277
|
+
* @param identifier The model identifier.
|
|
278
|
+
*/
|
|
279
|
+
constructor(identifier: string);
|
|
280
|
+
}
|
|
270
281
|
/**
|
|
271
282
|
* Abstract base class for WriftAI API resources.
|
|
272
283
|
*/
|
|
@@ -281,6 +292,17 @@ declare abstract class Resource {
|
|
|
281
292
|
* communicate with WriftAI's API.
|
|
282
293
|
*/
|
|
283
294
|
constructor(api: API);
|
|
295
|
+
/**
|
|
296
|
+
* Parses model identifier into owner, name, and version number.
|
|
297
|
+
* @param identifier The model identifier in either owner/name or
|
|
298
|
+
* owner/name:version-number format (for example: deepseek-ai/deepseek-r1
|
|
299
|
+
* or deepseek-ai/deepseek-r1:1).
|
|
300
|
+
* @returns A tuple containing owner, name, and version number of the
|
|
301
|
+
* model identifier.
|
|
302
|
+
* @throws {InvalidModelIdentifierError} When the provided model
|
|
303
|
+
* identifier is not in owner/name or owner/name:version-number format.
|
|
304
|
+
*/
|
|
305
|
+
protected parseModelIdentifier(identifier: string): [owner: string, name: string, versionNumber: string | null];
|
|
284
306
|
}
|
|
285
307
|
|
|
286
308
|
/**
|
|
@@ -433,16 +455,6 @@ interface WaitOptions {
|
|
|
433
455
|
declare const DEFAULT_WAIT_OPTIONS: {
|
|
434
456
|
pollInterval: number;
|
|
435
457
|
};
|
|
436
|
-
/**
|
|
437
|
-
* Error thrown when a model reference is not in owner/name format.
|
|
438
|
-
*/
|
|
439
|
-
declare class InvalidModelReferenceError extends Error {
|
|
440
|
-
/**
|
|
441
|
-
* Creates an instance of the error.
|
|
442
|
-
* @param model The model reference.
|
|
443
|
-
*/
|
|
444
|
-
constructor(model: string);
|
|
445
|
-
}
|
|
446
458
|
/**
|
|
447
459
|
* Resource class for interacting with predictions.
|
|
448
460
|
*/
|
|
@@ -455,24 +467,14 @@ declare class PredictionsResource extends Resource {
|
|
|
455
467
|
* @returns The prediction object.
|
|
456
468
|
*/
|
|
457
469
|
get(id: string, signal?: AbortSignal): Promise<PredictionWithIO>;
|
|
458
|
-
/**
|
|
459
|
-
* Parses model reference into owner, name, and version number.
|
|
460
|
-
* @param model The model reference in either owner/name or
|
|
461
|
-
* owner/name:version-number format (for example: deepseek-ai/deepseek-r1
|
|
462
|
-
* or deepseek-ai/deepseek-r1:1).
|
|
463
|
-
* @returns A tuple containing owner, name, and version number of the model.
|
|
464
|
-
* @throws {InvalidModelReferenceError} When the provided model
|
|
465
|
-
* reference is not in owner/name or owner/name:version-number format.
|
|
466
|
-
*/
|
|
467
|
-
private parseModel;
|
|
468
470
|
/**
|
|
469
471
|
* Constructs the API path to create a prediction.
|
|
470
|
-
* @param model The model
|
|
472
|
+
* @param model The model identifier in either owner/name or
|
|
471
473
|
* owner/name:version-number format (for example: deepseek-ai/deepseek-r1
|
|
472
474
|
* or deepseek-ai/deepseek-r1:1).
|
|
473
475
|
* @returns The API path.
|
|
474
|
-
* @throws {
|
|
475
|
-
*
|
|
476
|
+
* @throws {InvalidModelIdentifierError} When the provided model
|
|
477
|
+
* identifier is not in owner/name or owner/name:version_number format.
|
|
476
478
|
*/
|
|
477
479
|
private predictionPath;
|
|
478
480
|
/**
|
|
@@ -486,8 +488,6 @@ declare class PredictionsResource extends Resource {
|
|
|
486
488
|
* {@link DEFAULT_WAIT_OPTIONS} are used.
|
|
487
489
|
* @param signal Optional AbortSignal to cancel the request.
|
|
488
490
|
* @returns The new prediction.
|
|
489
|
-
* @throws {InvalidModelReferenceError} When the provided model
|
|
490
|
-
* reference is not in owner/name or owner/name:version_number format.
|
|
491
491
|
*/
|
|
492
492
|
create(options: CreatePredictionParams, wait?: boolean, waitOptions?: WaitOptions, signal?: AbortSignal): Promise<PredictionWithIO>;
|
|
493
493
|
/**
|
|
@@ -511,6 +511,84 @@ declare class PredictionsResource extends Resource {
|
|
|
511
511
|
wait(predictionID: string, options?: WaitOptions, signal?: AbortSignal): Promise<PredictionWithIO>;
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
+
/**
|
|
515
|
+
* Parameters for creating a version of a model.
|
|
516
|
+
*/
|
|
517
|
+
type CreateModelVersionParams = {
|
|
518
|
+
/**
|
|
519
|
+
* Information about changes such as new features,
|
|
520
|
+
* bug fixes, or optimizations in this model version.
|
|
521
|
+
*/
|
|
522
|
+
release_notes: string;
|
|
523
|
+
/**
|
|
524
|
+
* The schemas of the model version.
|
|
525
|
+
*/
|
|
526
|
+
schemas: Schemas;
|
|
527
|
+
/**
|
|
528
|
+
* A sha256 hash digest of the model version's container image.
|
|
529
|
+
*/
|
|
530
|
+
container_image_digest: string;
|
|
531
|
+
};
|
|
532
|
+
/**
|
|
533
|
+
* Error thrown when a model version identifier is not in
|
|
534
|
+
* owner/name:version-number format.
|
|
535
|
+
*/
|
|
536
|
+
declare class InvalidModelVersionIdentifierError extends Error {
|
|
537
|
+
/**
|
|
538
|
+
* Creates an instance of the error.
|
|
539
|
+
* @param identifier The model version identifier.
|
|
540
|
+
*/
|
|
541
|
+
constructor(identifier: string);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Resource class for interacting with model versions.
|
|
545
|
+
*/
|
|
546
|
+
declare class ModelVersions extends Resource {
|
|
547
|
+
/**
|
|
548
|
+
* Parses model version identifier into owner, name, and version number.
|
|
549
|
+
* @param identifier The model version identifier in owner/name:version-number
|
|
550
|
+
* format (for example: deepseek-ai/deepseek-r1:1).
|
|
551
|
+
* @returns A tuple containing owner, name, and version number of the
|
|
552
|
+
* model version identifier.
|
|
553
|
+
* @throws {InvalidModelVersionIdentifierError} When the provided
|
|
554
|
+
* model version identifier is not owner/name:version-number format.
|
|
555
|
+
*/
|
|
556
|
+
private parseModelVersionIdentifier;
|
|
557
|
+
/**
|
|
558
|
+
* Get a model version.
|
|
559
|
+
* @param identifier The model version identifier in owner/name:version-number
|
|
560
|
+
* format (for example: deepseek-ai/deepseek-r1:2).
|
|
561
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
562
|
+
* @returns The model version object.
|
|
563
|
+
*/
|
|
564
|
+
get(identifier: string, signal?: AbortSignal): Promise<ModelVersionWithDetails>;
|
|
565
|
+
/**
|
|
566
|
+
* Create a version of a model.
|
|
567
|
+
* @param identifier The model identifier in owner/name format
|
|
568
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
569
|
+
* @param params Model version creation parameters.
|
|
570
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
571
|
+
* @returns The new version object.
|
|
572
|
+
*/
|
|
573
|
+
create(identifier: string, params: CreateModelVersionParams, signal?: AbortSignal): Promise<ModelVersionWithDetails>;
|
|
574
|
+
/**
|
|
575
|
+
* Delete a model version.
|
|
576
|
+
* @param identifier The model version identifier in owner/name:version-number
|
|
577
|
+
* format (for example: deepseek-ai/deepseek-r1:2).
|
|
578
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
579
|
+
*/
|
|
580
|
+
delete(identifier: string, signal?: AbortSignal): Promise<void>;
|
|
581
|
+
/**
|
|
582
|
+
* List model versions.
|
|
583
|
+
* @param identifier The model identifier in owner/name format
|
|
584
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
585
|
+
* @param options Pagination options.
|
|
586
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
587
|
+
* @returns A paginated response containing model versions.
|
|
588
|
+
*/
|
|
589
|
+
list(identifier: string, options?: PaginationOptions, signal?: AbortSignal): Promise<PaginatedResponse<ModelVersion>>;
|
|
590
|
+
}
|
|
591
|
+
|
|
514
592
|
/**
|
|
515
593
|
* Parameters for updating a model.
|
|
516
594
|
*/
|
|
@@ -646,11 +724,11 @@ type ModelPaginationOptions = PaginationOptions & {
|
|
|
646
724
|
declare class Models extends Resource {
|
|
647
725
|
/**
|
|
648
726
|
* Delete a model.
|
|
649
|
-
* @param
|
|
650
|
-
*
|
|
727
|
+
* @param identifier The model identifier in owner/name format
|
|
728
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
651
729
|
* @param signal Optional AbortSignal to cancel the request.
|
|
652
730
|
*/
|
|
653
|
-
delete(
|
|
731
|
+
delete(identifier: string, signal?: AbortSignal): Promise<void>;
|
|
654
732
|
/**
|
|
655
733
|
* Create a model.
|
|
656
734
|
* @param options Parameters for creating a model.
|
|
@@ -660,12 +738,12 @@ declare class Models extends Resource {
|
|
|
660
738
|
create(options: CreateModelParams, signal?: AbortSignal): Promise<ModelWithDetails>;
|
|
661
739
|
/**
|
|
662
740
|
* Get a model.
|
|
663
|
-
* @param
|
|
664
|
-
*
|
|
741
|
+
* @param identifier The model identifier in owner/name format
|
|
742
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
665
743
|
* @param signal Optional AbortSignal to cancel the request.
|
|
666
744
|
* @returns A model object.
|
|
667
745
|
*/
|
|
668
|
-
get(
|
|
746
|
+
get(identifier: string, signal?: AbortSignal): Promise<ModelWithDetails>;
|
|
669
747
|
/**
|
|
670
748
|
* Constructs the API path for listing models.
|
|
671
749
|
* @param owner - Username of the model's owner to fetch models for.
|
|
@@ -684,13 +762,13 @@ declare class Models extends Resource {
|
|
|
684
762
|
list(options?: ModelPaginationOptions, owner?: string, signal?: AbortSignal): Promise<PaginatedResponse<Model>>;
|
|
685
763
|
/**
|
|
686
764
|
* Update a model.
|
|
687
|
-
* @param
|
|
688
|
-
*
|
|
765
|
+
* @param identifier The model identifier in owner/name format
|
|
766
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
689
767
|
* @param params The fields to update.
|
|
690
768
|
* @param signal Optional AbortSignal to cancel the request.
|
|
691
769
|
* @returns The updated model.
|
|
692
770
|
*/
|
|
693
|
-
update(
|
|
771
|
+
update(identifier: string, params: UpdateModelParams, signal?: AbortSignal): Promise<ModelWithDetails>;
|
|
694
772
|
/**
|
|
695
773
|
* Search models.
|
|
696
774
|
* @param q The search query.
|
|
@@ -862,65 +940,6 @@ declare class WebhookTimestampOutsideToleranceError extends WebhookSignatureVeri
|
|
|
862
940
|
*/
|
|
863
941
|
declare function verify(payload: Uint8Array, signature: string, secret: string, tolerance?: number, scheme?: string, keyCacheSize?: number): Promise<void>;
|
|
864
942
|
|
|
865
|
-
/**
|
|
866
|
-
* Parameters for creating a version of a model.
|
|
867
|
-
*/
|
|
868
|
-
type CreateModelVersionParams = {
|
|
869
|
-
/**
|
|
870
|
-
* Information about changes such as new features,
|
|
871
|
-
* bug fixes, or optimizations in this model version.
|
|
872
|
-
*/
|
|
873
|
-
release_notes: string;
|
|
874
|
-
/**
|
|
875
|
-
* The schemas of the model version.
|
|
876
|
-
*/
|
|
877
|
-
schemas: Schemas;
|
|
878
|
-
/**
|
|
879
|
-
* A sha256 hash digest of the model version's container image.
|
|
880
|
-
*/
|
|
881
|
-
container_image_digest: string;
|
|
882
|
-
};
|
|
883
|
-
/**
|
|
884
|
-
* Resource class for interacting with model versions.
|
|
885
|
-
*/
|
|
886
|
-
declare class ModelVersions extends Resource {
|
|
887
|
-
/**
|
|
888
|
-
* Get a model version by its owner, name, and version number.
|
|
889
|
-
* @param modelOwner Username of the model's owner.
|
|
890
|
-
* @param modelName Name of the model.
|
|
891
|
-
* @param number The number of the model version.
|
|
892
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
893
|
-
* @returns The model version object.
|
|
894
|
-
*/
|
|
895
|
-
get(modelOwner: string, modelName: string, number: number, signal?: AbortSignal): Promise<ModelVersionWithDetails>;
|
|
896
|
-
/**
|
|
897
|
-
* Create a version of a model.
|
|
898
|
-
* @param modelOwner The username of the model's owner.
|
|
899
|
-
* @param modelName The name of the model.
|
|
900
|
-
* @param params Model version creation parameters.
|
|
901
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
902
|
-
* @returns The new version object.
|
|
903
|
-
*/
|
|
904
|
-
create(modelOwner: string, modelName: string, params: CreateModelVersionParams, signal?: AbortSignal): Promise<ModelVersionWithDetails>;
|
|
905
|
-
/**
|
|
906
|
-
* Delete a model version by its owner, name, and version number.
|
|
907
|
-
* @param modelOwner Username of the model's owner.
|
|
908
|
-
* @param modelName Name of the model.
|
|
909
|
-
* @param number The number of the model version.
|
|
910
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
911
|
-
*/
|
|
912
|
-
delete(modelOwner: string, modelName: string, number: number, signal?: AbortSignal): Promise<void>;
|
|
913
|
-
/**
|
|
914
|
-
* List model versions.
|
|
915
|
-
* @param modelOwner Username of the model's owner.
|
|
916
|
-
* @param modelName Name of the model.
|
|
917
|
-
* @param options Pagination options.
|
|
918
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
919
|
-
* @returns A paginated response containing model versions.
|
|
920
|
-
*/
|
|
921
|
-
list(modelOwner: string, modelName: string, options?: PaginationOptions, signal?: AbortSignal): Promise<PaginatedResponse<ModelVersion>>;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
943
|
/**
|
|
925
944
|
* Parameters for updating a user.
|
|
926
945
|
*/
|
|
@@ -1045,12 +1064,12 @@ declare class WriftAI {
|
|
|
1045
1064
|
* @param options.fetch Fetch implementation to use.
|
|
1046
1065
|
* Defaults to `globalThis.fetch`.
|
|
1047
1066
|
* @param options.accessToken Bearer token used for
|
|
1048
|
-
* authentication. Defaults to `process.env.
|
|
1067
|
+
* authentication. Defaults to `process.env.WRIFTAI_ACCESS_TOKEN`
|
|
1049
1068
|
* if available.
|
|
1050
1069
|
* @param options.headers Optional additional headers (overrides defaults).
|
|
1051
1070
|
*/
|
|
1052
1071
|
constructor(options?: WriftAIClientOptions);
|
|
1053
1072
|
}
|
|
1054
1073
|
|
|
1055
|
-
export { DEFAULT_WAIT_OPTIONS, ErrorSource,
|
|
1074
|
+
export { DEFAULT_WAIT_OPTIONS, ErrorSource, InvalidModelIdentifierError, InvalidModelVersionIdentifierError, ModelVisibility, ModelsSortBy, SortDirection, Status, UsersSortBy, WebhookNoSignatureError, WebhookNoTimestampError, WebhookSignatureMismatchError, WebhookSignatureVerificationError, WebhookTimestampOutsideToleranceError, WriftAI, WriftAIAPIError, verify as verifyWebhook };
|
|
1056
1075
|
export type { BaseUser, HardwareWithDetails, Model, ModelCategory, ModelCategoryWithDetails, ModelVersion, ModelVersionWithDetails, ModelWithDetails, PaginatedResponse, Prediction, PredictionModel, PredictionWithIO, SchemaIO, Schemas, TaskError, User, UserWithDetails, WriftAIClientOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -39,7 +39,7 @@ class API {
|
|
|
39
39
|
// Build default headers
|
|
40
40
|
const defaults = {
|
|
41
41
|
'Content-Type': 'application/json',
|
|
42
|
-
'User-Agent': 'wriftai-javascript/' + "0.
|
|
42
|
+
'User-Agent': 'wriftai-javascript/' + "0.39.0",
|
|
43
43
|
};
|
|
44
44
|
if (accessToken) {
|
|
45
45
|
defaults.Authorization = `Bearer ${accessToken}`;
|
|
@@ -98,6 +98,22 @@ class API {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Error thrown when a model identifier is neither in owner/name
|
|
103
|
+
* nor owner/name:version-number format.
|
|
104
|
+
*/
|
|
105
|
+
class InvalidModelIdentifierError extends Error {
|
|
106
|
+
/**
|
|
107
|
+
* Creates an instance of the error.
|
|
108
|
+
* @param identifier The model identifier.
|
|
109
|
+
*/
|
|
110
|
+
constructor(identifier) {
|
|
111
|
+
super(`Invalid model identifier: "${identifier}". ` +
|
|
112
|
+
`It must be in either owner/name or ` +
|
|
113
|
+
'owner/name:version-number format');
|
|
114
|
+
this.name = 'InvalidModelIdentifierError';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
101
117
|
/**
|
|
102
118
|
* Abstract base class for WriftAI API resources.
|
|
103
119
|
*/
|
|
@@ -114,6 +130,27 @@ class Resource {
|
|
|
114
130
|
constructor(api) {
|
|
115
131
|
this.api = api;
|
|
116
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Parses model identifier into owner, name, and version number.
|
|
135
|
+
* @param identifier The model identifier in either owner/name or
|
|
136
|
+
* owner/name:version-number format (for example: deepseek-ai/deepseek-r1
|
|
137
|
+
* or deepseek-ai/deepseek-r1:1).
|
|
138
|
+
* @returns A tuple containing owner, name, and version number of the
|
|
139
|
+
* model identifier.
|
|
140
|
+
* @throws {InvalidModelIdentifierError} When the provided model
|
|
141
|
+
* identifier is not in owner/name or owner/name:version-number format.
|
|
142
|
+
*/
|
|
143
|
+
parseModelIdentifier(identifier) {
|
|
144
|
+
const [owner, namePart, ...rest] = identifier.split('/');
|
|
145
|
+
if (!owner || !namePart || rest.length > 0) {
|
|
146
|
+
throw new InvalidModelIdentifierError(identifier);
|
|
147
|
+
}
|
|
148
|
+
const [name, versionNumber] = namePart.split(':');
|
|
149
|
+
if (!name || (namePart.includes(':') && !versionNumber)) {
|
|
150
|
+
throw new InvalidModelIdentifierError(identifier);
|
|
151
|
+
}
|
|
152
|
+
return [owner, name, versionNumber || null];
|
|
153
|
+
}
|
|
117
154
|
}
|
|
118
155
|
|
|
119
156
|
/**
|
|
@@ -138,21 +175,6 @@ var Status;
|
|
|
138
175
|
* Default wait options.
|
|
139
176
|
*/
|
|
140
177
|
const DEFAULT_WAIT_OPTIONS = { pollInterval: 1000 };
|
|
141
|
-
/**
|
|
142
|
-
* Error thrown when a model reference is not in owner/name format.
|
|
143
|
-
*/
|
|
144
|
-
class InvalidModelReferenceError extends Error {
|
|
145
|
-
/**
|
|
146
|
-
* Creates an instance of the error.
|
|
147
|
-
* @param model The model reference.
|
|
148
|
-
*/
|
|
149
|
-
constructor(model) {
|
|
150
|
-
super(`Invalid model reference: "${model}". ` +
|
|
151
|
-
`It must be in either owner/name or ` +
|
|
152
|
-
'owner/name:version-number format');
|
|
153
|
-
this.name = 'InvalidModelReferenceError';
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
178
|
/**
|
|
157
179
|
* Resource class for interacting with predictions.
|
|
158
180
|
*/
|
|
@@ -171,37 +193,17 @@ class PredictionsResource extends Resource {
|
|
|
171
193
|
});
|
|
172
194
|
return response;
|
|
173
195
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Parses model reference into owner, name, and version number.
|
|
176
|
-
* @param model The model reference in either owner/name or
|
|
177
|
-
* owner/name:version-number format (for example: deepseek-ai/deepseek-r1
|
|
178
|
-
* or deepseek-ai/deepseek-r1:1).
|
|
179
|
-
* @returns A tuple containing owner, name, and version number of the model.
|
|
180
|
-
* @throws {InvalidModelReferenceError} When the provided model
|
|
181
|
-
* reference is not in owner/name or owner/name:version-number format.
|
|
182
|
-
*/
|
|
183
|
-
parseModel(model) {
|
|
184
|
-
const [owner, namePart, ...rest] = model.split('/');
|
|
185
|
-
if (!owner || !namePart || rest.length > 0) {
|
|
186
|
-
throw new InvalidModelReferenceError(model);
|
|
187
|
-
}
|
|
188
|
-
const [name, versionNumber] = namePart.split(':');
|
|
189
|
-
if (!name || (namePart.includes(':') && !versionNumber)) {
|
|
190
|
-
throw new InvalidModelReferenceError(model);
|
|
191
|
-
}
|
|
192
|
-
return [owner, name, versionNumber || null];
|
|
193
|
-
}
|
|
194
196
|
/**
|
|
195
197
|
* Constructs the API path to create a prediction.
|
|
196
|
-
* @param model The model
|
|
198
|
+
* @param model The model identifier in either owner/name or
|
|
197
199
|
* owner/name:version-number format (for example: deepseek-ai/deepseek-r1
|
|
198
200
|
* or deepseek-ai/deepseek-r1:1).
|
|
199
201
|
* @returns The API path.
|
|
200
|
-
* @throws {
|
|
201
|
-
*
|
|
202
|
+
* @throws {InvalidModelIdentifierError} When the provided model
|
|
203
|
+
* identifier is not in owner/name or owner/name:version_number format.
|
|
202
204
|
*/
|
|
203
205
|
predictionPath(model) {
|
|
204
|
-
const [model_owner, model_name, version_number] = this.
|
|
206
|
+
const [model_owner, model_name, version_number] = this.parseModelIdentifier(model);
|
|
205
207
|
if (version_number) {
|
|
206
208
|
return (`${this.MODELS_API_PREFIX}/${model_owner}/${model_name}` +
|
|
207
209
|
`${this.MODEL_VERSION_PATH}/${version_number}/predictions`);
|
|
@@ -222,8 +224,6 @@ class PredictionsResource extends Resource {
|
|
|
222
224
|
* {@link DEFAULT_WAIT_OPTIONS} are used.
|
|
223
225
|
* @param signal Optional AbortSignal to cancel the request.
|
|
224
226
|
* @returns The new prediction.
|
|
225
|
-
* @throws {InvalidModelReferenceError} When the provided model
|
|
226
|
-
* reference is not in owner/name or owner/name:version_number format.
|
|
227
227
|
*/
|
|
228
228
|
async create(options, wait = false, waitOptions = DEFAULT_WAIT_OPTIONS, signal) {
|
|
229
229
|
const { input, webhook, validate_input, model } = options;
|
|
@@ -320,6 +320,108 @@ class PredictionsResource extends Resource {
|
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Error thrown when a model version identifier is not in
|
|
325
|
+
* owner/name:version-number format.
|
|
326
|
+
*/
|
|
327
|
+
class InvalidModelVersionIdentifierError extends Error {
|
|
328
|
+
/**
|
|
329
|
+
* Creates an instance of the error.
|
|
330
|
+
* @param identifier The model version identifier.
|
|
331
|
+
*/
|
|
332
|
+
constructor(identifier) {
|
|
333
|
+
super(`Invalid model version identifier: "${identifier}". ` +
|
|
334
|
+
'It must be in owner/name:version-number format');
|
|
335
|
+
this.name = 'InvalidModelVersionIdentifierError';
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Resource class for interacting with model versions.
|
|
340
|
+
*/
|
|
341
|
+
class ModelVersions extends Resource {
|
|
342
|
+
/**
|
|
343
|
+
* Parses model version identifier into owner, name, and version number.
|
|
344
|
+
* @param identifier The model version identifier in owner/name:version-number
|
|
345
|
+
* format (for example: deepseek-ai/deepseek-r1:1).
|
|
346
|
+
* @returns A tuple containing owner, name, and version number of the
|
|
347
|
+
* model version identifier.
|
|
348
|
+
* @throws {InvalidModelVersionIdentifierError} When the provided
|
|
349
|
+
* model version identifier is not owner/name:version-number format.
|
|
350
|
+
*/
|
|
351
|
+
parseModelVersionIdentifier(identifier) {
|
|
352
|
+
const [owner, name, number] = this.parseModelIdentifier(identifier);
|
|
353
|
+
if (number === null) {
|
|
354
|
+
throw new InvalidModelVersionIdentifierError(identifier);
|
|
355
|
+
}
|
|
356
|
+
return [owner, name, number];
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Get a model version.
|
|
360
|
+
* @param identifier The model version identifier in owner/name:version-number
|
|
361
|
+
* format (for example: deepseek-ai/deepseek-r1:2).
|
|
362
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
363
|
+
* @returns The model version object.
|
|
364
|
+
*/
|
|
365
|
+
async get(identifier, signal) {
|
|
366
|
+
const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
|
|
367
|
+
const response = await this.api.request(`${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
|
|
368
|
+
`${this.MODEL_VERSION_PATH}/${number}`, { method: 'GET', signal });
|
|
369
|
+
return response;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Create a version of a model.
|
|
373
|
+
* @param identifier The model identifier in owner/name format
|
|
374
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
375
|
+
* @param params Model version creation parameters.
|
|
376
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
377
|
+
* @returns The new version object.
|
|
378
|
+
*/
|
|
379
|
+
async create(identifier, params, signal) {
|
|
380
|
+
const [modelOwner, modelName] = this.parseModelIdentifier(identifier);
|
|
381
|
+
const path = `${this.MODELS_API_PREFIX}/${modelOwner}/` +
|
|
382
|
+
`${modelName}${this.MODEL_VERSION_PATH}`;
|
|
383
|
+
const response = await this.api.request(path, {
|
|
384
|
+
method: 'POST',
|
|
385
|
+
body: params,
|
|
386
|
+
signal,
|
|
387
|
+
});
|
|
388
|
+
return response;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Delete a model version.
|
|
392
|
+
* @param identifier The model version identifier in owner/name:version-number
|
|
393
|
+
* format (for example: deepseek-ai/deepseek-r1:2).
|
|
394
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
395
|
+
*/
|
|
396
|
+
async delete(identifier, signal) {
|
|
397
|
+
const [modelOwner, modelName, number] = this.parseModelVersionIdentifier(identifier);
|
|
398
|
+
await this.api.request(`${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
|
|
399
|
+
`${this.MODEL_VERSION_PATH}/${number}`, {
|
|
400
|
+
method: 'DELETE',
|
|
401
|
+
signal,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* List model versions.
|
|
406
|
+
* @param identifier The model identifier in owner/name format
|
|
407
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
408
|
+
* @param options Pagination options.
|
|
409
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
410
|
+
* @returns A paginated response containing model versions.
|
|
411
|
+
*/
|
|
412
|
+
async list(identifier, options, signal) {
|
|
413
|
+
const [modelOwner, modelName] = this.parseModelIdentifier(identifier);
|
|
414
|
+
const path = `${this.MODELS_API_PREFIX}/${modelOwner}/` +
|
|
415
|
+
`${modelName}${this.MODEL_VERSION_PATH}`;
|
|
416
|
+
const response = await this.api.request(path, {
|
|
417
|
+
method: 'GET',
|
|
418
|
+
params: options,
|
|
419
|
+
signal,
|
|
420
|
+
});
|
|
421
|
+
return response;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
323
425
|
/**
|
|
324
426
|
* Model visibility states.
|
|
325
427
|
*/
|
|
@@ -351,11 +453,12 @@ var ModelsSortBy;
|
|
|
351
453
|
class Models extends Resource {
|
|
352
454
|
/**
|
|
353
455
|
* Delete a model.
|
|
354
|
-
* @param
|
|
355
|
-
*
|
|
456
|
+
* @param identifier The model identifier in owner/name format
|
|
457
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
356
458
|
* @param signal Optional AbortSignal to cancel the request.
|
|
357
459
|
*/
|
|
358
|
-
async delete(
|
|
460
|
+
async delete(identifier, signal) {
|
|
461
|
+
const [owner, name] = this.parseModelIdentifier(identifier);
|
|
359
462
|
await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
|
|
360
463
|
method: 'DELETE',
|
|
361
464
|
signal,
|
|
@@ -377,12 +480,13 @@ class Models extends Resource {
|
|
|
377
480
|
}
|
|
378
481
|
/**
|
|
379
482
|
* Get a model.
|
|
380
|
-
* @param
|
|
381
|
-
*
|
|
483
|
+
* @param identifier The model identifier in owner/name format
|
|
484
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
382
485
|
* @param signal Optional AbortSignal to cancel the request.
|
|
383
486
|
* @returns A model object.
|
|
384
487
|
*/
|
|
385
|
-
async get(
|
|
488
|
+
async get(identifier, signal) {
|
|
489
|
+
const [owner, name] = this.parseModelIdentifier(identifier);
|
|
386
490
|
const response = await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
|
|
387
491
|
method: 'GET',
|
|
388
492
|
signal,
|
|
@@ -419,13 +523,14 @@ class Models extends Resource {
|
|
|
419
523
|
}
|
|
420
524
|
/**
|
|
421
525
|
* Update a model.
|
|
422
|
-
* @param
|
|
423
|
-
*
|
|
526
|
+
* @param identifier The model identifier in owner/name format
|
|
527
|
+
* (for example: deepseek-ai/deepseek-r1).
|
|
424
528
|
* @param params The fields to update.
|
|
425
529
|
* @param signal Optional AbortSignal to cancel the request.
|
|
426
530
|
* @returns The updated model.
|
|
427
531
|
*/
|
|
428
|
-
async update(
|
|
532
|
+
async update(identifier, params, signal) {
|
|
533
|
+
const [owner, name] = this.parseModelIdentifier(identifier);
|
|
429
534
|
const response = await this.api.request(`${this.MODELS_API_PREFIX}/${owner}/${name}`, {
|
|
430
535
|
method: 'PATCH',
|
|
431
536
|
body: params,
|
|
@@ -760,75 +865,6 @@ function verifyTimestamp(timestamp, tolerance) {
|
|
|
760
865
|
}
|
|
761
866
|
}
|
|
762
867
|
|
|
763
|
-
/**
|
|
764
|
-
* Resource class for interacting with model versions.
|
|
765
|
-
*/
|
|
766
|
-
class ModelVersions extends Resource {
|
|
767
|
-
/**
|
|
768
|
-
* Get a model version by its owner, name, and version number.
|
|
769
|
-
* @param modelOwner Username of the model's owner.
|
|
770
|
-
* @param modelName Name of the model.
|
|
771
|
-
* @param number The number of the model version.
|
|
772
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
773
|
-
* @returns The model version object.
|
|
774
|
-
*/
|
|
775
|
-
async get(modelOwner, modelName, number, signal) {
|
|
776
|
-
const response = await this.api.request(`${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
|
|
777
|
-
`${this.MODEL_VERSION_PATH}/${String(number)}`, { method: 'GET', signal });
|
|
778
|
-
return response;
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* Create a version of a model.
|
|
782
|
-
* @param modelOwner The username of the model's owner.
|
|
783
|
-
* @param modelName The name of the model.
|
|
784
|
-
* @param params Model version creation parameters.
|
|
785
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
786
|
-
* @returns The new version object.
|
|
787
|
-
*/
|
|
788
|
-
async create(modelOwner, modelName, params, signal) {
|
|
789
|
-
const path = `${this.MODELS_API_PREFIX}/${modelOwner}/` +
|
|
790
|
-
`${modelName}${this.MODEL_VERSION_PATH}`;
|
|
791
|
-
const response = await this.api.request(path, {
|
|
792
|
-
method: 'POST',
|
|
793
|
-
body: params,
|
|
794
|
-
signal,
|
|
795
|
-
});
|
|
796
|
-
return response;
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* Delete a model version by its owner, name, and version number.
|
|
800
|
-
* @param modelOwner Username of the model's owner.
|
|
801
|
-
* @param modelName Name of the model.
|
|
802
|
-
* @param number The number of the model version.
|
|
803
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
804
|
-
*/
|
|
805
|
-
async delete(modelOwner, modelName, number, signal) {
|
|
806
|
-
await this.api.request(`${this.MODELS_API_PREFIX}/${modelOwner}/${modelName}` +
|
|
807
|
-
`${this.MODEL_VERSION_PATH}/${String(number)}`, {
|
|
808
|
-
method: 'DELETE',
|
|
809
|
-
signal,
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* List model versions.
|
|
814
|
-
* @param modelOwner Username of the model's owner.
|
|
815
|
-
* @param modelName Name of the model.
|
|
816
|
-
* @param options Pagination options.
|
|
817
|
-
* @param signal Optional AbortSignal to cancel the request.
|
|
818
|
-
* @returns A paginated response containing model versions.
|
|
819
|
-
*/
|
|
820
|
-
async list(modelOwner, modelName, options, signal) {
|
|
821
|
-
const path = `${this.MODELS_API_PREFIX}/${modelOwner}/` +
|
|
822
|
-
`${modelName}${this.MODEL_VERSION_PATH}`;
|
|
823
|
-
const response = await this.api.request(path, {
|
|
824
|
-
method: 'GET',
|
|
825
|
-
params: options,
|
|
826
|
-
signal,
|
|
827
|
-
});
|
|
828
|
-
return response;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
|
|
832
868
|
/**
|
|
833
869
|
* Resource for operations related to the authenticated user.
|
|
834
870
|
*/
|
|
@@ -970,7 +1006,7 @@ class WriftAI {
|
|
|
970
1006
|
* @param options.fetch Fetch implementation to use.
|
|
971
1007
|
* Defaults to `globalThis.fetch`.
|
|
972
1008
|
* @param options.accessToken Bearer token used for
|
|
973
|
-
* authentication. Defaults to `process.env.
|
|
1009
|
+
* authentication. Defaults to `process.env.WRIFTAI_ACCESS_TOKEN`
|
|
974
1010
|
* if available.
|
|
975
1011
|
* @param options.headers Optional additional headers (overrides defaults).
|
|
976
1012
|
*/
|
|
@@ -981,7 +1017,7 @@ class WriftAI {
|
|
|
981
1017
|
const accessToken = options.accessToken ??
|
|
982
1018
|
// check if on browser
|
|
983
1019
|
(typeof process !== 'undefined'
|
|
984
|
-
? process.env.
|
|
1020
|
+
? process.env.WRIFTAI_ACCESS_TOKEN
|
|
985
1021
|
: undefined);
|
|
986
1022
|
// Use a custom fetch if provided; otherwise use the global fetch.
|
|
987
1023
|
// Bind globalThis.fetch to ensure correct `this` context in browsers
|
|
@@ -999,5 +1035,5 @@ class WriftAI {
|
|
|
999
1035
|
}
|
|
1000
1036
|
}
|
|
1001
1037
|
|
|
1002
|
-
export { DEFAULT_WAIT_OPTIONS, ErrorSource,
|
|
1038
|
+
export { DEFAULT_WAIT_OPTIONS, ErrorSource, InvalidModelIdentifierError, InvalidModelVersionIdentifierError, ModelVisibility, ModelsSortBy, SortDirection, Status, UsersSortBy, WebhookNoSignatureError, WebhookNoTimestampError, WebhookSignatureMismatchError, WebhookSignatureVerificationError, WebhookTimestampOutsideToleranceError, WriftAI, WriftAIAPIError, verify as verifyWebhook };
|
|
1003
1039
|
//# sourceMappingURL=index.mjs.map
|