@mynthio/sdk 0.0.47 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -72
- package/dist/convex/index.d.ts +3 -3
- package/dist/convex/index.js +3 -3
- package/dist/handler.d.ts +22 -4
- package/dist/handler.js +36 -3
- package/dist/index.d.ts +2 -221
- package/dist/index.js +14 -277
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +2 -2
- package/dist/{types.d.ts → video-generation-result.d.ts} +296 -23
- package/dist/video-generation-result.js +216 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as AvailableVideoModel, a as ImageRemoveBackgroundResult, b as VideoResolutionTier, c as MynthGeneratedImage, d as MynthCompletedTask, f as MynthTaskFailure, g as AvailableModel, h as AVAILABLE_VIDEO_MODELS, i as ImageReviewResult, l as MynthOutputImage, m as AVAILABLE_MODELS, n as MynthOutputVideo, o as ImageRateResult, p as MynthSDKTypes, r as ImageUpscaleResult, s as ImageGenerationResult, t as VideoGenerationResult, u as ImageAltResult, v as ModelCapability, y as VideoInputRole } from "./video-generation-result.js";
|
|
2
2
|
//#region src/client.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Error thrown when an API request fails.
|
|
@@ -48,179 +48,6 @@ declare class MynthClient {
|
|
|
48
48
|
getOrThrow<DataType>(path: string, options?: MynthClientRequestOptions): Promise<DataType>;
|
|
49
49
|
}
|
|
50
50
|
//#endregion
|
|
51
|
-
//#region src/image-alt-result.d.ts
|
|
52
|
-
/**
|
|
53
|
-
* Represents the result of a completed image alt text task.
|
|
54
|
-
*/
|
|
55
|
-
export declare class ImageAltResult {
|
|
56
|
-
/** The task ID created for this alt text request */
|
|
57
|
-
readonly taskId: string;
|
|
58
|
-
/** Cost charged for the completed task */
|
|
59
|
-
readonly cost: string;
|
|
60
|
-
/** Generated alt text */
|
|
61
|
-
readonly alt: string;
|
|
62
|
-
constructor(data: {
|
|
63
|
-
taskId: string;
|
|
64
|
-
cost: string;
|
|
65
|
-
alt: string;
|
|
66
|
-
});
|
|
67
|
-
static fromTaskData(data: MynthSDKTypes.ImageAltTaskData): ImageAltResult;
|
|
68
|
-
}
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/image-generation-result.d.ts
|
|
71
|
-
type TypedImageResultImageSuccess<RatingT> = Omit<MynthSDKTypes.ImageResultImageSuccess, "rating"> & {
|
|
72
|
-
rating?: RatingT;
|
|
73
|
-
};
|
|
74
|
-
type TypedImageResultImageFailure = MynthSDKTypes.ImageResultImageFailure;
|
|
75
|
-
type TypedImageResultImage<RatingT> = TypedImageResultImageSuccess<RatingT> | TypedImageResultImageFailure;
|
|
76
|
-
type TypedImageResult<RatingT> = Omit<MynthSDKTypes.ImageResult, "images"> & {
|
|
77
|
-
images: TypedImageResultImage<RatingT>[];
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Represents a completed image generation task.
|
|
81
|
-
*
|
|
82
|
-
* @template MetadataT - Type of the metadata attached to the request
|
|
83
|
-
* @template RatingT - Type of the rating response
|
|
84
|
-
*/
|
|
85
|
-
export declare class ImageGenerationResult<MetadataT = Record<string, unknown> | undefined, RatingT = MynthSDKTypes.ImageResultRating | undefined> {
|
|
86
|
-
/** Raw task data from the API */
|
|
87
|
-
readonly data: MynthSDKTypes.ImageGenerationTaskData;
|
|
88
|
-
constructor(data: MynthSDKTypes.ImageGenerationTaskData);
|
|
89
|
-
/** Unique identifier for this task */
|
|
90
|
-
get id(): string;
|
|
91
|
-
/** Current status of the task */
|
|
92
|
-
get status(): MynthSDKTypes.TaskStatus;
|
|
93
|
-
/**
|
|
94
|
-
* The generation result: images, the format each one was delivered in, and the model.
|
|
95
|
-
* Returns `null` if the task hasn't completed yet.
|
|
96
|
-
*/
|
|
97
|
-
get result(): TypedImageResult<RatingT> | null;
|
|
98
|
-
/** Whether the task completed successfully */
|
|
99
|
-
get isCompleted(): boolean;
|
|
100
|
-
/** Whether the task failed */
|
|
101
|
-
get isFailed(): boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Get all successfully generated image URLs.
|
|
104
|
-
* Convenience method that extracts just the URLs from successful images.
|
|
105
|
-
* Images delivered only to a user destination may have a `null` url and are omitted here;
|
|
106
|
-
* use `getImages()` and read `mynth_url` to access the CDN URL directly.
|
|
107
|
-
*/
|
|
108
|
-
get urls(): string[];
|
|
109
|
-
/**
|
|
110
|
-
* Get generated images from the task result.
|
|
111
|
-
*
|
|
112
|
-
* @param options.includeFailed - If true, includes failed image results
|
|
113
|
-
* @returns Array of image results
|
|
114
|
-
*/
|
|
115
|
-
getImages(options: {
|
|
116
|
-
includeFailed: true;
|
|
117
|
-
}): TypedImageResultImage<RatingT>[];
|
|
118
|
-
getImages(options?: {
|
|
119
|
-
includeFailed?: false;
|
|
120
|
-
}): TypedImageResultImageSuccess<RatingT>[];
|
|
121
|
-
/**
|
|
122
|
-
* Get the metadata that was attached to the generation request.
|
|
123
|
-
*/
|
|
124
|
-
getMetadata(): MetadataT;
|
|
125
|
-
}
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/image-rate-result.d.ts
|
|
128
|
-
/**
|
|
129
|
-
* Represents the result of a completed image content rating task.
|
|
130
|
-
*
|
|
131
|
-
* @template LevelT - Union of possible rating level strings (e.g. `"sfw" | "nsfw"`)
|
|
132
|
-
*/
|
|
133
|
-
export declare class ImageRateResult<LevelT extends string = "sfw" | "nsfw"> {
|
|
134
|
-
/** The task ID created for this rating request */
|
|
135
|
-
readonly taskId: string;
|
|
136
|
-
/** Cost charged for the completed task */
|
|
137
|
-
readonly cost: string;
|
|
138
|
-
/** Assigned rating level */
|
|
139
|
-
readonly level: LevelT;
|
|
140
|
-
constructor(data: {
|
|
141
|
-
taskId: string;
|
|
142
|
-
cost: string;
|
|
143
|
-
level: LevelT;
|
|
144
|
-
});
|
|
145
|
-
static fromTaskData<LevelT extends string = "sfw" | "nsfw">(data: MynthSDKTypes.ImageRateTaskData): ImageRateResult<LevelT>;
|
|
146
|
-
}
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/image-remove-background-result.d.ts
|
|
149
|
-
/**
|
|
150
|
-
* Represents the result of a completed image background removal task.
|
|
151
|
-
*
|
|
152
|
-
* @template MetadataT - Type of the metadata attached to the request
|
|
153
|
-
*/
|
|
154
|
-
export declare class ImageRemoveBackgroundResult<MetadataT = Record<string, unknown> | undefined> {
|
|
155
|
-
/** The task ID created for this request */
|
|
156
|
-
readonly taskId: string;
|
|
157
|
-
/** Cost charged for the completed task */
|
|
158
|
-
readonly cost: string;
|
|
159
|
-
/** The image with its background removed */
|
|
160
|
-
readonly image: MynthSDKTypes.ImageRemoveBackgroundResultImage;
|
|
161
|
-
/** Metadata attached to the request */
|
|
162
|
-
readonly metadata: MetadataT;
|
|
163
|
-
constructor(data: {
|
|
164
|
-
taskId: string;
|
|
165
|
-
cost: string;
|
|
166
|
-
image: MynthSDKTypes.ImageRemoveBackgroundResultImage;
|
|
167
|
-
metadata: MetadataT;
|
|
168
|
-
});
|
|
169
|
-
static fromTaskData<MetadataT = Record<string, unknown> | undefined>(data: MynthSDKTypes.ImageRemoveBackgroundTaskData): ImageRemoveBackgroundResult<MetadataT>;
|
|
170
|
-
}
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/image-review-result.d.ts
|
|
173
|
-
/**
|
|
174
|
-
* Represents the result of a completed image quality review task.
|
|
175
|
-
*/
|
|
176
|
-
export declare class ImageReviewResult {
|
|
177
|
-
/** The task ID created for this review request */
|
|
178
|
-
readonly taskId: string;
|
|
179
|
-
/** Cost charged for the completed task */
|
|
180
|
-
readonly cost: string;
|
|
181
|
-
/** Median reviewer score from 1 to 4. Higher is better. */
|
|
182
|
-
readonly score: number;
|
|
183
|
-
/** Review summary */
|
|
184
|
-
readonly summary: string;
|
|
185
|
-
/** Defects found by the reviewer panel */
|
|
186
|
-
readonly findings: MynthSDKTypes.ImageReviewFinding[];
|
|
187
|
-
/** Strengths identified by the reviewer panel */
|
|
188
|
-
readonly strengths: MynthSDKTypes.ImageReviewStrength[];
|
|
189
|
-
constructor(data: {
|
|
190
|
-
taskId: string;
|
|
191
|
-
cost: string;
|
|
192
|
-
score: number;
|
|
193
|
-
summary: string;
|
|
194
|
-
findings: MynthSDKTypes.ImageReviewFinding[];
|
|
195
|
-
strengths: MynthSDKTypes.ImageReviewStrength[];
|
|
196
|
-
});
|
|
197
|
-
static fromTaskData(data: MynthSDKTypes.ImageReviewTaskData): ImageReviewResult;
|
|
198
|
-
}
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/image-upscale-result.d.ts
|
|
201
|
-
/**
|
|
202
|
-
* Represents the result of a completed image upscale task.
|
|
203
|
-
*
|
|
204
|
-
* @template MetadataT - Type of the metadata attached to the request
|
|
205
|
-
*/
|
|
206
|
-
export declare class ImageUpscaleResult<MetadataT = Record<string, unknown> | undefined> {
|
|
207
|
-
/** The task ID created for this request */
|
|
208
|
-
readonly taskId: string;
|
|
209
|
-
/** Cost charged for the completed task */
|
|
210
|
-
readonly cost: string;
|
|
211
|
-
/** The upscaled image */
|
|
212
|
-
readonly image: MynthSDKTypes.ImageUpscaleResultImage;
|
|
213
|
-
/** Metadata attached to the request */
|
|
214
|
-
readonly metadata: MetadataT;
|
|
215
|
-
constructor(data: {
|
|
216
|
-
taskId: string;
|
|
217
|
-
cost: string;
|
|
218
|
-
image: MynthSDKTypes.ImageUpscaleResultImage;
|
|
219
|
-
metadata: MetadataT;
|
|
220
|
-
});
|
|
221
|
-
static fromTaskData<MetadataT = Record<string, unknown> | undefined>(data: MynthSDKTypes.ImageUpscaleTaskData): ImageUpscaleResult<MetadataT>;
|
|
222
|
-
}
|
|
223
|
-
//#endregion
|
|
224
51
|
//#region src/task-async.d.ts
|
|
225
52
|
/**
|
|
226
53
|
* Polling cadence overrides. Anything omitted keeps the image-task default.
|
|
@@ -329,52 +156,6 @@ export declare class TaskAsync<ResultT> {
|
|
|
329
156
|
private sleep;
|
|
330
157
|
}
|
|
331
158
|
//#endregion
|
|
332
|
-
//#region src/video-generation-result.d.ts
|
|
333
|
-
/**
|
|
334
|
-
* Represents a completed video generation task.
|
|
335
|
-
*
|
|
336
|
-
* @template MetadataT - Type of the metadata attached to the request
|
|
337
|
-
*/
|
|
338
|
-
export declare class VideoGenerationResult<MetadataT = Record<string, unknown> | undefined> {
|
|
339
|
-
/** Raw task data from the API */
|
|
340
|
-
readonly data: MynthSDKTypes.VideoGenerationTaskData;
|
|
341
|
-
constructor(data: MynthSDKTypes.VideoGenerationTaskData);
|
|
342
|
-
/** Unique identifier for this task */
|
|
343
|
-
get id(): string;
|
|
344
|
-
/** Current status of the task */
|
|
345
|
-
get status(): MynthSDKTypes.TaskStatus;
|
|
346
|
-
/**
|
|
347
|
-
* The generation result containing videos and model info.
|
|
348
|
-
* Returns `null` if the task hasn't completed yet.
|
|
349
|
-
*/
|
|
350
|
-
get result(): MynthSDKTypes.VideoResult | null;
|
|
351
|
-
/** Whether the task completed successfully */
|
|
352
|
-
get isCompleted(): boolean;
|
|
353
|
-
/** Whether the task failed */
|
|
354
|
-
get isFailed(): boolean;
|
|
355
|
-
/**
|
|
356
|
-
* Get all successfully generated video URLs.
|
|
357
|
-
* Convenience method that extracts just the URLs from successful videos.
|
|
358
|
-
*/
|
|
359
|
-
get urls(): string[];
|
|
360
|
-
/**
|
|
361
|
-
* Get generated videos from the task result.
|
|
362
|
-
*
|
|
363
|
-
* @param options.includeFailed - If true, includes failed video results
|
|
364
|
-
* @returns Array of video results
|
|
365
|
-
*/
|
|
366
|
-
getVideos(options: {
|
|
367
|
-
includeFailed: true;
|
|
368
|
-
}): MynthSDKTypes.VideoResultVideo[];
|
|
369
|
-
getVideos(options?: {
|
|
370
|
-
includeFailed?: false;
|
|
371
|
-
}): MynthSDKTypes.VideoResultVideoSuccess[];
|
|
372
|
-
/**
|
|
373
|
-
* Get the metadata that was attached to the generation request.
|
|
374
|
-
*/
|
|
375
|
-
getMetadata(): MetadataT;
|
|
376
|
-
}
|
|
377
|
-
//#endregion
|
|
378
159
|
//#region src/index.d.ts
|
|
379
160
|
/**
|
|
380
161
|
* Configuration options for the Mynth client.
|
|
@@ -855,4 +636,4 @@ declare class Mynth {
|
|
|
855
636
|
get video(): MynthVideo;
|
|
856
637
|
}
|
|
857
638
|
//#endregion
|
|
858
|
-
export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS, type AvailableModel, type AvailableVideoModel, type ModelCapability, Mynth, Mynth as default, type MynthAPIErrorIssue, MynthImage, type MynthModel, type MynthModelPricing, MynthModels, type MynthOptions, type MynthRequestOptions, type MynthSDKTypes, MynthVideo, type TaskAsyncAccess, type TaskAsyncWaitOptions, type VideoInputRole, type VideoResolutionTier };
|
|
639
|
+
export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS, type AvailableModel, type AvailableVideoModel, type ImageAltResult, type ImageGenerationResult, type ImageRateResult, type ImageRemoveBackgroundResult, type ImageReviewResult, type ImageUpscaleResult, type ModelCapability, Mynth, Mynth as default, type MynthAPIErrorIssue, type MynthCompletedTask, type MynthGeneratedImage, MynthImage, type MynthModel, type MynthModelPricing, MynthModels, type MynthOptions, type MynthOutputImage, type MynthOutputVideo, type MynthRequestOptions, type MynthSDKTypes, type MynthTaskFailure, MynthVideo, type TaskAsyncAccess, type TaskAsyncWaitOptions, type VideoGenerationResult, type VideoInputRole, type VideoResolutionTier };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { a as toImageUpscaleResult, c as toImageRateResult, l as toImageGenerationResult, n as completedTaskFromData, o as toImageReviewResult, s as toImageRemoveBackgroundResult, t as toVideoGenerationResult, u as toImageAltResult } from "./video-generation-result.js";
|
|
1
2
|
//#region src/constants.ts
|
|
2
3
|
/** Base URL for the Mynth API */
|
|
3
4
|
const API_URL = "https://api.mynth.io";
|
|
@@ -108,6 +109,11 @@ const AVAILABLE_MODELS = [
|
|
|
108
109
|
label: "FLUX.2 Klein 4B",
|
|
109
110
|
capabilities: ["inputs"]
|
|
110
111
|
},
|
|
112
|
+
{
|
|
113
|
+
id: "black-forest-labs/flux-3",
|
|
114
|
+
label: "FLUX.3",
|
|
115
|
+
capabilities: ["inputs", "4k"]
|
|
116
|
+
},
|
|
111
117
|
{
|
|
112
118
|
id: "bria/fibo-edit-1.5",
|
|
113
119
|
label: "FIBO Edit 1.5",
|
|
@@ -478,221 +484,6 @@ var MynthClient = class {
|
|
|
478
484
|
}
|
|
479
485
|
};
|
|
480
486
|
//#endregion
|
|
481
|
-
//#region src/image-alt-result.ts
|
|
482
|
-
/**
|
|
483
|
-
* Represents the result of a completed image alt text task.
|
|
484
|
-
*/
|
|
485
|
-
var ImageAltResult = class ImageAltResult {
|
|
486
|
-
/** The task ID created for this alt text request */
|
|
487
|
-
taskId;
|
|
488
|
-
/** Cost charged for the completed task */
|
|
489
|
-
cost;
|
|
490
|
-
/** Generated alt text */
|
|
491
|
-
alt;
|
|
492
|
-
constructor(data) {
|
|
493
|
-
this.taskId = data.taskId;
|
|
494
|
-
this.cost = data.cost;
|
|
495
|
-
this.alt = data.alt;
|
|
496
|
-
}
|
|
497
|
-
static fromTaskData(data) {
|
|
498
|
-
if (data.status !== "completed" || data.result === null) throw new Error(`Image alt task ${data.id} is not completed`);
|
|
499
|
-
if (data.cost === null) throw new Error(`Image alt task ${data.id} is missing cost`);
|
|
500
|
-
return new ImageAltResult({
|
|
501
|
-
taskId: data.id,
|
|
502
|
-
cost: data.cost,
|
|
503
|
-
alt: data.result.alt
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/image-generation-result.ts
|
|
509
|
-
/**
|
|
510
|
-
* Represents a completed image generation task.
|
|
511
|
-
*
|
|
512
|
-
* @template MetadataT - Type of the metadata attached to the request
|
|
513
|
-
* @template RatingT - Type of the rating response
|
|
514
|
-
*/
|
|
515
|
-
var ImageGenerationResult = class {
|
|
516
|
-
/** Raw task data from the API */
|
|
517
|
-
data;
|
|
518
|
-
constructor(data) {
|
|
519
|
-
this.data = data;
|
|
520
|
-
}
|
|
521
|
-
/** Unique identifier for this task */
|
|
522
|
-
get id() {
|
|
523
|
-
return this.data.id;
|
|
524
|
-
}
|
|
525
|
-
/** Current status of the task */
|
|
526
|
-
get status() {
|
|
527
|
-
return this.data.status;
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* The generation result: images, the format each one was delivered in, and the model.
|
|
531
|
-
* Returns `null` if the task hasn't completed yet.
|
|
532
|
-
*/
|
|
533
|
-
get result() {
|
|
534
|
-
return this.data.result;
|
|
535
|
-
}
|
|
536
|
-
/** Whether the task completed successfully */
|
|
537
|
-
get isCompleted() {
|
|
538
|
-
return this.data.status === "completed";
|
|
539
|
-
}
|
|
540
|
-
/** Whether the task failed */
|
|
541
|
-
get isFailed() {
|
|
542
|
-
return this.data.status === "failed";
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Get all successfully generated image URLs.
|
|
546
|
-
* Convenience method that extracts just the URLs from successful images.
|
|
547
|
-
* Images delivered only to a user destination may have a `null` url and are omitted here;
|
|
548
|
-
* use `getImages()` and read `mynth_url` to access the CDN URL directly.
|
|
549
|
-
*/
|
|
550
|
-
get urls() {
|
|
551
|
-
return this.data.result?.images.filter((img) => img.status === "success").map((img) => img.url).filter((url) => url !== null) ?? [];
|
|
552
|
-
}
|
|
553
|
-
getImages(options = {}) {
|
|
554
|
-
if (options.includeFailed) return this.data.result?.images ?? [];
|
|
555
|
-
return this.data.result?.images.filter((image) => image.status === "success") ?? [];
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Get the metadata that was attached to the generation request.
|
|
559
|
-
*/
|
|
560
|
-
getMetadata() {
|
|
561
|
-
return this.data.request?.metadata;
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
//#endregion
|
|
565
|
-
//#region src/image-rate-result.ts
|
|
566
|
-
/**
|
|
567
|
-
* Represents the result of a completed image content rating task.
|
|
568
|
-
*
|
|
569
|
-
* @template LevelT - Union of possible rating level strings (e.g. `"sfw" | "nsfw"`)
|
|
570
|
-
*/
|
|
571
|
-
var ImageRateResult = class ImageRateResult {
|
|
572
|
-
/** The task ID created for this rating request */
|
|
573
|
-
taskId;
|
|
574
|
-
/** Cost charged for the completed task */
|
|
575
|
-
cost;
|
|
576
|
-
/** Assigned rating level */
|
|
577
|
-
level;
|
|
578
|
-
constructor(data) {
|
|
579
|
-
this.taskId = data.taskId;
|
|
580
|
-
this.cost = data.cost;
|
|
581
|
-
this.level = data.level;
|
|
582
|
-
}
|
|
583
|
-
static fromTaskData(data) {
|
|
584
|
-
if (data.status !== "completed" || data.result === null) throw new Error(`Image rate task ${data.id} is not completed`);
|
|
585
|
-
if (data.cost === null) throw new Error(`Image rate task ${data.id} is missing cost`);
|
|
586
|
-
return new ImageRateResult({
|
|
587
|
-
taskId: data.id,
|
|
588
|
-
cost: data.cost,
|
|
589
|
-
level: data.result.level
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
//#endregion
|
|
594
|
-
//#region src/image-remove-background-result.ts
|
|
595
|
-
/**
|
|
596
|
-
* Represents the result of a completed image background removal task.
|
|
597
|
-
*
|
|
598
|
-
* @template MetadataT - Type of the metadata attached to the request
|
|
599
|
-
*/
|
|
600
|
-
var ImageRemoveBackgroundResult = class ImageRemoveBackgroundResult {
|
|
601
|
-
/** The task ID created for this request */
|
|
602
|
-
taskId;
|
|
603
|
-
/** Cost charged for the completed task */
|
|
604
|
-
cost;
|
|
605
|
-
/** The image with its background removed */
|
|
606
|
-
image;
|
|
607
|
-
/** Metadata attached to the request */
|
|
608
|
-
metadata;
|
|
609
|
-
constructor(data) {
|
|
610
|
-
this.taskId = data.taskId;
|
|
611
|
-
this.cost = data.cost;
|
|
612
|
-
this.image = data.image;
|
|
613
|
-
this.metadata = data.metadata;
|
|
614
|
-
}
|
|
615
|
-
static fromTaskData(data) {
|
|
616
|
-
if (data.status !== "completed" || data.result === null) throw new Error(`Image remove background task ${data.id} is not completed`);
|
|
617
|
-
if (data.cost === null) throw new Error(`Image remove background task ${data.id} is missing cost`);
|
|
618
|
-
return new ImageRemoveBackgroundResult({
|
|
619
|
-
taskId: data.id,
|
|
620
|
-
cost: data.cost,
|
|
621
|
-
image: data.result.image,
|
|
622
|
-
metadata: data.request.metadata
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
//#endregion
|
|
627
|
-
//#region src/image-review-result.ts
|
|
628
|
-
/**
|
|
629
|
-
* Represents the result of a completed image quality review task.
|
|
630
|
-
*/
|
|
631
|
-
var ImageReviewResult = class ImageReviewResult {
|
|
632
|
-
/** The task ID created for this review request */
|
|
633
|
-
taskId;
|
|
634
|
-
/** Cost charged for the completed task */
|
|
635
|
-
cost;
|
|
636
|
-
/** Median reviewer score from 1 to 4. Higher is better. */
|
|
637
|
-
score;
|
|
638
|
-
/** Review summary */
|
|
639
|
-
summary;
|
|
640
|
-
/** Defects found by the reviewer panel */
|
|
641
|
-
findings;
|
|
642
|
-
/** Strengths identified by the reviewer panel */
|
|
643
|
-
strengths;
|
|
644
|
-
constructor(data) {
|
|
645
|
-
this.taskId = data.taskId;
|
|
646
|
-
this.cost = data.cost;
|
|
647
|
-
this.score = data.score;
|
|
648
|
-
this.summary = data.summary;
|
|
649
|
-
this.findings = data.findings;
|
|
650
|
-
this.strengths = data.strengths;
|
|
651
|
-
}
|
|
652
|
-
static fromTaskData(data) {
|
|
653
|
-
if (data.status !== "completed" || data.result === null) throw new Error(`Image review task ${data.id} is not completed`);
|
|
654
|
-
if (data.cost === null) throw new Error(`Image review task ${data.id} is missing cost`);
|
|
655
|
-
return new ImageReviewResult({
|
|
656
|
-
taskId: data.id,
|
|
657
|
-
cost: data.cost,
|
|
658
|
-
...data.result
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
//#endregion
|
|
663
|
-
//#region src/image-upscale-result.ts
|
|
664
|
-
/**
|
|
665
|
-
* Represents the result of a completed image upscale task.
|
|
666
|
-
*
|
|
667
|
-
* @template MetadataT - Type of the metadata attached to the request
|
|
668
|
-
*/
|
|
669
|
-
var ImageUpscaleResult = class ImageUpscaleResult {
|
|
670
|
-
/** The task ID created for this request */
|
|
671
|
-
taskId;
|
|
672
|
-
/** Cost charged for the completed task */
|
|
673
|
-
cost;
|
|
674
|
-
/** The upscaled image */
|
|
675
|
-
image;
|
|
676
|
-
/** Metadata attached to the request */
|
|
677
|
-
metadata;
|
|
678
|
-
constructor(data) {
|
|
679
|
-
this.taskId = data.taskId;
|
|
680
|
-
this.cost = data.cost;
|
|
681
|
-
this.image = data.image;
|
|
682
|
-
this.metadata = data.metadata;
|
|
683
|
-
}
|
|
684
|
-
static fromTaskData(data) {
|
|
685
|
-
if (data.status !== "completed" || data.result === null) throw new Error(`Image upscale task ${data.id} is not completed`);
|
|
686
|
-
if (data.cost === null) throw new Error(`Image upscale task ${data.id} is missing cost`);
|
|
687
|
-
return new ImageUpscaleResult({
|
|
688
|
-
taskId: data.id,
|
|
689
|
-
cost: data.cost,
|
|
690
|
-
image: data.result.image,
|
|
691
|
-
metadata: data.request.metadata
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
//#endregion
|
|
696
487
|
//#region src/task-async.ts
|
|
697
488
|
const POLLING_TIMEOUT_MS = 18e5;
|
|
698
489
|
const FAST_POLLING_DURATION_MS = 12e3;
|
|
@@ -1034,60 +825,6 @@ async function resolveInputs(client, inputs, { signal } = {}) {
|
|
|
1034
825
|
});
|
|
1035
826
|
}
|
|
1036
827
|
//#endregion
|
|
1037
|
-
//#region src/video-generation-result.ts
|
|
1038
|
-
/**
|
|
1039
|
-
* Represents a completed video generation task.
|
|
1040
|
-
*
|
|
1041
|
-
* @template MetadataT - Type of the metadata attached to the request
|
|
1042
|
-
*/
|
|
1043
|
-
var VideoGenerationResult = class {
|
|
1044
|
-
/** Raw task data from the API */
|
|
1045
|
-
data;
|
|
1046
|
-
constructor(data) {
|
|
1047
|
-
this.data = data;
|
|
1048
|
-
}
|
|
1049
|
-
/** Unique identifier for this task */
|
|
1050
|
-
get id() {
|
|
1051
|
-
return this.data.id;
|
|
1052
|
-
}
|
|
1053
|
-
/** Current status of the task */
|
|
1054
|
-
get status() {
|
|
1055
|
-
return this.data.status;
|
|
1056
|
-
}
|
|
1057
|
-
/**
|
|
1058
|
-
* The generation result containing videos and model info.
|
|
1059
|
-
* Returns `null` if the task hasn't completed yet.
|
|
1060
|
-
*/
|
|
1061
|
-
get result() {
|
|
1062
|
-
return this.data.result;
|
|
1063
|
-
}
|
|
1064
|
-
/** Whether the task completed successfully */
|
|
1065
|
-
get isCompleted() {
|
|
1066
|
-
return this.data.status === "completed";
|
|
1067
|
-
}
|
|
1068
|
-
/** Whether the task failed */
|
|
1069
|
-
get isFailed() {
|
|
1070
|
-
return this.data.status === "failed";
|
|
1071
|
-
}
|
|
1072
|
-
/**
|
|
1073
|
-
* Get all successfully generated video URLs.
|
|
1074
|
-
* Convenience method that extracts just the URLs from successful videos.
|
|
1075
|
-
*/
|
|
1076
|
-
get urls() {
|
|
1077
|
-
return this.getVideos().map((video) => video.url);
|
|
1078
|
-
}
|
|
1079
|
-
getVideos(options = {}) {
|
|
1080
|
-
if (options.includeFailed) return this.data.result?.videos ?? [];
|
|
1081
|
-
return this.data.result?.videos.filter((video) => video.status === "success") ?? [];
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* Get the metadata that was attached to the generation request.
|
|
1085
|
-
*/
|
|
1086
|
-
getMetadata() {
|
|
1087
|
-
return this.data.request?.metadata;
|
|
1088
|
-
}
|
|
1089
|
-
};
|
|
1090
|
-
//#endregion
|
|
1091
828
|
//#region src/index.ts
|
|
1092
829
|
/**
|
|
1093
830
|
* Attempts to read the API key from environment variables.
|
|
@@ -1209,7 +946,7 @@ var MynthImage = class {
|
|
|
1209
946
|
return new TaskAsync(data.taskId, {
|
|
1210
947
|
client: this.client,
|
|
1211
948
|
pat: data.access?.publicAccessToken,
|
|
1212
|
-
resultFactory: (data) =>
|
|
949
|
+
resultFactory: (data) => toImageGenerationResult(completedTaskFromData(data, "Image generation"))
|
|
1213
950
|
});
|
|
1214
951
|
}
|
|
1215
952
|
/**
|
|
@@ -1278,7 +1015,7 @@ var MynthImage = class {
|
|
|
1278
1015
|
})).data;
|
|
1279
1016
|
return new TaskAsync(data.taskId, {
|
|
1280
1017
|
client: this.client,
|
|
1281
|
-
resultFactory: (taskData) =>
|
|
1018
|
+
resultFactory: (taskData) => toImageRateResult(completedTaskFromData(taskData, "Image rate"))
|
|
1282
1019
|
});
|
|
1283
1020
|
}
|
|
1284
1021
|
/**
|
|
@@ -1320,7 +1057,7 @@ var MynthImage = class {
|
|
|
1320
1057
|
const data = (await this.client.post(ALT_IMAGE_PATH, { url })).data;
|
|
1321
1058
|
return new TaskAsync(data.taskId, {
|
|
1322
1059
|
client: this.client,
|
|
1323
|
-
resultFactory: (taskData) =>
|
|
1060
|
+
resultFactory: (taskData) => toImageAltResult(completedTaskFromData(taskData, "Image alt"))
|
|
1324
1061
|
});
|
|
1325
1062
|
}
|
|
1326
1063
|
/**
|
|
@@ -1357,7 +1094,7 @@ var MynthImage = class {
|
|
|
1357
1094
|
})).data;
|
|
1358
1095
|
return new TaskAsync(data.taskId, {
|
|
1359
1096
|
client: this.client,
|
|
1360
|
-
resultFactory: (taskData) =>
|
|
1097
|
+
resultFactory: (taskData) => toImageReviewResult(completedTaskFromData(taskData, "Image review"))
|
|
1361
1098
|
});
|
|
1362
1099
|
}
|
|
1363
1100
|
/**
|
|
@@ -1405,7 +1142,7 @@ var MynthImage = class {
|
|
|
1405
1142
|
return new TaskAsync(data.taskId, {
|
|
1406
1143
|
client: this.client,
|
|
1407
1144
|
pat: data.access?.publicAccessToken,
|
|
1408
|
-
resultFactory: (taskData) =>
|
|
1145
|
+
resultFactory: (taskData) => toImageRemoveBackgroundResult(completedTaskFromData(taskData, "Image remove background"))
|
|
1409
1146
|
});
|
|
1410
1147
|
}
|
|
1411
1148
|
/**
|
|
@@ -1454,7 +1191,7 @@ var MynthImage = class {
|
|
|
1454
1191
|
return new TaskAsync(data.taskId, {
|
|
1455
1192
|
client: this.client,
|
|
1456
1193
|
pat: data.access?.publicAccessToken,
|
|
1457
|
-
resultFactory: (taskData) =>
|
|
1194
|
+
resultFactory: (taskData) => toImageUpscaleResult(completedTaskFromData(taskData, "Image upscale"))
|
|
1458
1195
|
});
|
|
1459
1196
|
}
|
|
1460
1197
|
};
|
|
@@ -1593,7 +1330,7 @@ var MynthVideo = class {
|
|
|
1593
1330
|
client: this.client,
|
|
1594
1331
|
pat: data.access?.publicAccessToken,
|
|
1595
1332
|
polling: VIDEO_POLLING,
|
|
1596
|
-
resultFactory: (taskData) =>
|
|
1333
|
+
resultFactory: (taskData) => toVideoGenerationResult(completedTaskFromData(taskData, "Video generation"))
|
|
1597
1334
|
});
|
|
1598
1335
|
}
|
|
1599
1336
|
};
|
|
@@ -1670,4 +1407,4 @@ var Mynth = class {
|
|
|
1670
1407
|
}
|
|
1671
1408
|
};
|
|
1672
1409
|
//#endregion
|
|
1673
|
-
export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS,
|
|
1410
|
+
export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS, Mynth, Mynth as default, MynthAPIError, MynthImage, MynthModels, MynthVideo, TaskAsync, TaskAsyncFetchError, TaskAsyncTaskFailedError, TaskAsyncTaskFetchError, TaskAsyncTimeoutError, TaskAsyncUnauthorizedError };
|
package/dist/next/index.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export type MynthWebhookHandlerOptions = WebhookHandlerOptions;
|
|
|
20
20
|
* import { mynthWebhookHandler } from "@mynthio/sdk/next";
|
|
21
21
|
*
|
|
22
22
|
* export const POST = mynthWebhookHandler({
|
|
23
|
-
* imageTaskCompleted: async (
|
|
24
|
-
* console.log(deliveryId,
|
|
23
|
+
* imageTaskCompleted: async (result, { deliveryId }) => {
|
|
24
|
+
* console.log(deliveryId, result.taskId);
|
|
25
25
|
* },
|
|
26
26
|
* });
|
|
27
27
|
* ```
|
package/dist/next/index.js
CHANGED
|
@@ -9,8 +9,8 @@ import { t as handleWebhookRequest } from "../handler.js";
|
|
|
9
9
|
* import { mynthWebhookHandler } from "@mynthio/sdk/next";
|
|
10
10
|
*
|
|
11
11
|
* export const POST = mynthWebhookHandler({
|
|
12
|
-
* imageTaskCompleted: async (
|
|
13
|
-
* console.log(deliveryId,
|
|
12
|
+
* imageTaskCompleted: async (result, { deliveryId }) => {
|
|
13
|
+
* console.log(deliveryId, result.taskId);
|
|
14
14
|
* },
|
|
15
15
|
* });
|
|
16
16
|
* ```
|