@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.
@@ -184,7 +184,7 @@ declare namespace MynthSDKTypes {
184
184
  };
185
185
  type Model = ImageModel | VideoModel;
186
186
  type ModelsListResponse = ApiResponse<Model[]>;
187
- type ImageGenerationModelId = "alibaba/qwen-image-2.0" | "alibaba/qwen-image-2.0-pro" | "alibaba/qwen-image-3.0" | "alibaba/qwen-image-3.0-pro" | "bytedance/seedream-5.0-lite" | "bytedance/seedream-pro" | "bytedance/seedream-v5-flash" | "black-forest-labs/flux.1-dev" | "black-forest-labs/flux-1-schnell" | "black-forest-labs/flux.2-dev" | "black-forest-labs/flux.2-pro" | "black-forest-labs/flux.2-flex" | "black-forest-labs/flux.2-max" | "black-forest-labs/flux.2-klein-4b" | "bria/fibo-edit-1.5" | "bria/fibo-generate-1.5" | "circlestone-labs/anima" | "goofy-ai/prefect-pony-xl-lora" | "google/gemini-3.1-flash-lite-image" | "google/gemini-3.1-flash-image" | "google/gemini-3-pro-image-preview" | "imagineart/imagineart-1.5-pro" | "imagineart/imagineart-2.0" | "ideogram/ideogram-4.5" | "klingai/kling-image-3.0" | "klingai/kling-image-o3" | "krea/krea-2-turbo" | "krea/krea-2-medium" | "krea/krea-2-large" | "luma/uni-1" | "luma/uni-1-max" | "meta/muse-image" | "microsoft/mai-image-2.6" | "microsoft/mai-image-2.6-flash" | "minimax/h3" | "openai/gpt-image-2" | "openai/gpt-image-2.5-flare" | "openai/gpt-image-2.5-sunburst" | "tongyi-mai/z-image" | "tongyi-mai/z-image-turbo" | "john6666/bismuth-illustrious-mix" | "maxfeifei8/one-obsession" | "purplesmartai/pony-diffusion-v6-xl" | "recraft/recraft-v4" | "recraft/recraft-v4.1-flash" | "recraft/recraft-v4-pro" | "reve/reve" | "reve/reve-remix" | "sourceful/riverflow-2.0-pro" | "wan/wan2.6-image" | "wan/wan2.7-image" | "wan/wan2.7-image-pro" | "xai/grok-imagine-image" | "xai/grok-imagine-image-2.0" | "xai/grok-imagine-image-quality";
187
+ type ImageGenerationModelId = "alibaba/qwen-image-2.0" | "alibaba/qwen-image-2.0-pro" | "alibaba/qwen-image-3.0" | "alibaba/qwen-image-3.0-pro" | "bytedance/seedream-5.0-lite" | "bytedance/seedream-pro" | "bytedance/seedream-v5-flash" | "black-forest-labs/flux.1-dev" | "black-forest-labs/flux-1-schnell" | "black-forest-labs/flux.2-dev" | "black-forest-labs/flux.2-pro" | "black-forest-labs/flux.2-flex" | "black-forest-labs/flux.2-max" | "black-forest-labs/flux.2-klein-4b" | "black-forest-labs/flux-3" | "bria/fibo-edit-1.5" | "bria/fibo-generate-1.5" | "circlestone-labs/anima" | "goofy-ai/prefect-pony-xl-lora" | "google/gemini-3.1-flash-lite-image" | "google/gemini-3.1-flash-image" | "google/gemini-3-pro-image-preview" | "imagineart/imagineart-1.5-pro" | "imagineart/imagineart-2.0" | "ideogram/ideogram-4.5" | "klingai/kling-image-3.0" | "klingai/kling-image-o3" | "krea/krea-2-turbo" | "krea/krea-2-medium" | "krea/krea-2-large" | "luma/uni-1" | "luma/uni-1-max" | "meta/muse-image" | "microsoft/mai-image-2.6" | "microsoft/mai-image-2.6-flash" | "minimax/h3" | "openai/gpt-image-2" | "openai/gpt-image-2.5-flare" | "openai/gpt-image-2.5-sunburst" | "tongyi-mai/z-image" | "tongyi-mai/z-image-turbo" | "john6666/bismuth-illustrious-mix" | "maxfeifei8/one-obsession" | "purplesmartai/pony-diffusion-v6-xl" | "recraft/recraft-v4" | "recraft/recraft-v4.1-flash" | "recraft/recraft-v4-pro" | "reve/reve" | "reve/reve-remix" | "sourceful/riverflow-2.0-pro" | "wan/wan2.6-image" | "wan/wan2.7-image" | "wan/wan2.7-image-pro" | "xai/grok-imagine-image" | "xai/grok-imagine-image-2.0" | "xai/grok-imagine-image-quality";
188
188
  type ImageGenerationModel = ImageGenerationModelId | "auto";
189
189
  type GenerateImageOptionsIn = {
190
190
  prompt: string;
@@ -230,6 +230,12 @@ declare namespace MynthSDKTypes {
230
230
  type ImageGenerationRequestSizeAuto = {
231
231
  type: "auto";
232
232
  };
233
+ type ImageFormat = "png" | "jpg" | "webp";
234
+ type ImageMimeType<FormatT extends ImageFormat = ImageFormat> = {
235
+ png: "image/png";
236
+ jpg: "image/jpeg";
237
+ webp: "image/webp";
238
+ }[FormatT];
233
239
  type ImageUploadInput = Blob | File;
234
240
  type ImageUploadResponse = {
235
241
  urls: string[];
@@ -564,10 +570,13 @@ declare namespace MynthSDKTypes {
564
570
  model: VideoGenerationModelId;
565
571
  videos: VideoResultVideo[];
566
572
  };
573
+ type WebhookTaskCompleted = {
574
+ id: string;
575
+ /** USD charged for the task */
576
+ cost: string;
577
+ };
567
578
  type WebhookTaskImageCompletedPayload = {
568
- task: {
569
- id: string;
570
- };
579
+ task: WebhookTaskCompleted;
571
580
  event: "task.image.generate.completed";
572
581
  result: ImageResult;
573
582
  request: ImageGenerationRequest;
@@ -581,9 +590,7 @@ declare namespace MynthSDKTypes {
581
590
  errors: TaskError[];
582
591
  };
583
592
  type WebhookTaskImageRateCompletedPayload<LevelT extends string = string> = {
584
- task: {
585
- id: string;
586
- };
593
+ task: WebhookTaskCompleted;
587
594
  event: "task.image.rate.completed";
588
595
  result: ImageRateTaskResult<LevelT>;
589
596
  request: ImageRateRequest;
@@ -597,9 +604,7 @@ declare namespace MynthSDKTypes {
597
604
  errors: TaskError[];
598
605
  };
599
606
  type WebhookTaskImageAltCompletedPayload = {
600
- task: {
601
- id: string;
602
- };
607
+ task: WebhookTaskCompleted;
603
608
  event: "task.image.alt.completed";
604
609
  result: ImageAltTaskResult;
605
610
  request: ImageAltRequest;
@@ -613,9 +618,7 @@ declare namespace MynthSDKTypes {
613
618
  errors: TaskError[];
614
619
  };
615
620
  type WebhookTaskImageReviewCompletedPayload = {
616
- task: {
617
- id: string;
618
- };
621
+ task: WebhookTaskCompleted;
619
622
  event: "task.image.review.completed";
620
623
  result: ImageReviewTaskResult;
621
624
  request: ImageReviewRequest;
@@ -629,9 +632,7 @@ declare namespace MynthSDKTypes {
629
632
  errors: TaskError[];
630
633
  };
631
634
  type WebhookTaskImageRemoveBackgroundCompletedPayload = {
632
- task: {
633
- id: string;
634
- };
635
+ task: WebhookTaskCompleted;
635
636
  event: "task.image.remove_background.completed";
636
637
  result: ImageRemoveBackgroundTaskResult;
637
638
  request: ImageRemoveBackgroundRequest;
@@ -645,9 +646,7 @@ declare namespace MynthSDKTypes {
645
646
  errors: TaskError[];
646
647
  };
647
648
  type WebhookTaskImageUpscaleCompletedPayload = {
648
- task: {
649
- id: string;
650
- };
649
+ task: WebhookTaskCompleted;
651
650
  event: "task.image.upscale.completed";
652
651
  result: ImageUpscaleTaskResult;
653
652
  request: ImageUpscaleRequest;
@@ -661,9 +660,7 @@ declare namespace MynthSDKTypes {
661
660
  errors: TaskError[];
662
661
  };
663
662
  type WebhookTaskVideoCompletedPayload = {
664
- task: {
665
- id: string;
666
- };
663
+ task: WebhookTaskCompleted;
667
664
  event: "task.video.generate.completed";
668
665
  result: VideoResult;
669
666
  request: VideoGenerationRequest;
@@ -679,4 +676,280 @@ declare namespace MynthSDKTypes {
679
676
  type WebhookPayload = WebhookTaskImageCompletedPayload | WebhookTaskImageFailedPayload | WebhookTaskImageRateCompletedPayload | WebhookTaskImageRateFailedPayload | WebhookTaskImageAltCompletedPayload | WebhookTaskImageAltFailedPayload | WebhookTaskImageReviewCompletedPayload | WebhookTaskImageReviewFailedPayload | WebhookTaskImageRemoveBackgroundCompletedPayload | WebhookTaskImageRemoveBackgroundFailedPayload | WebhookTaskImageUpscaleCompletedPayload | WebhookTaskImageUpscaleFailedPayload | WebhookTaskVideoCompletedPayload | WebhookTaskVideoFailedPayload;
680
677
  }
681
678
  //#endregion
682
- export { AvailableVideoModel as a, VideoResolutionTier as c, AvailableModel as i, AVAILABLE_MODELS as n, ModelCapability as o, AVAILABLE_VIDEO_MODELS as r, VideoInputRole as s, MynthSDKTypes as t };
679
+ //#region src/task-result.d.ts
680
+ /**
681
+ * A completed task, as every result class is built from it. Polled task data
682
+ * and webhook payloads both come down to this shape.
683
+ */
684
+ type MynthCompletedTask<RequestT, ResultT> = {
685
+ taskId: string;
686
+ /** USD charged for the task */
687
+ cost: string;
688
+ request: RequestT;
689
+ result: ResultT;
690
+ };
691
+ type TaskFailureBase<RequestT> = {
692
+ /** The failed task's ID */
693
+ taskId: string;
694
+ /** Why the task failed. At least one entry. */
695
+ errors: MynthSDKTypes.TaskError[];
696
+ /** The request as the API echoed it */
697
+ raw: {
698
+ request: RequestT;
699
+ };
700
+ };
701
+ /** Present only for task types whose request takes `metadata`. */
702
+ type TaskFailureMetadata<RequestT> = RequestT extends {
703
+ metadata?: infer MetadataT;
704
+ } ? "metadata" extends keyof RequestT ? {
705
+ /** Metadata attached to the request */
706
+ metadata: MetadataT | undefined;
707
+ } : unknown : unknown;
708
+ /**
709
+ * A failed task, as a `...Failed` webhook callback receives it.
710
+ *
711
+ * @template RequestT - The task type's request
712
+ */
713
+ type MynthTaskFailure<RequestT = unknown> = TaskFailureBase<RequestT> & TaskFailureMetadata<RequestT>;
714
+ //#endregion
715
+ //#region src/image-alt-result.d.ts
716
+ /**
717
+ * A completed image alt text task.
718
+ */
719
+ type ImageAltResult = {
720
+ /** The task ID created for this alt text request */
721
+ taskId: string;
722
+ /** Cost charged for the completed task */
723
+ cost: string;
724
+ /** Generated alt text */
725
+ alt: string;
726
+ /** The request and result as the API returned them, for fields the SDK does not map yet */
727
+ raw: {
728
+ request: MynthSDKTypes.ImageAltRequest;
729
+ result: MynthSDKTypes.ImageAltTaskResult;
730
+ };
731
+ };
732
+ //#endregion
733
+ //#region src/output-image.d.ts
734
+ /**
735
+ * An image produced by a Mynth task: generated, upscaled, or with its
736
+ * background removed.
737
+ *
738
+ * @template FormatT - Formats the task can deliver
739
+ */
740
+ type MynthOutputImage<FormatT extends MynthSDKTypes.ImageFormat = MynthSDKTypes.ImageFormat> = {
741
+ /** Image ID */
742
+ id: string;
743
+ /**
744
+ * Your destination's public URL for the image, or the Mynth CDN URL when the
745
+ * request named no destination. `null` when the destination upload failed or
746
+ * the destination has no public URL.
747
+ *
748
+ * The SDK never swaps in another URL for you: write `url ?? mynthUrl` where
749
+ * any URL will do.
750
+ */
751
+ url: string | null;
752
+ /** Mynth CDN URL. Always set, and served for 7 days. */
753
+ mynthUrl: string;
754
+ /** Width in pixels */
755
+ width: number;
756
+ /** Height in pixels */
757
+ height: number;
758
+ /** `{width}x{height}`, e.g. `"1024x768"` */
759
+ size: string;
760
+ /** File format the image was delivered in */
761
+ format: FormatT;
762
+ /** MIME type matching `format`, e.g. `"image/webp"` */
763
+ mimeType: MynthSDKTypes.ImageMimeType<FormatT>;
764
+ /** Delivery to your destination. `undefined` when the request named none. */
765
+ destination: MynthSDKTypes.ImageResultDestination | undefined;
766
+ };
767
+ //#endregion
768
+ //#region src/image-generation-result.d.ts
769
+ /**
770
+ * An image produced by image generation: an {@link MynthOutputImage} with its
771
+ * content rating.
772
+ *
773
+ * @template RatingT - Type of the rating, inferred from the request's `rating`
774
+ */
775
+ type MynthGeneratedImage<RatingT = MynthSDKTypes.ImageResultRating | undefined> = MynthOutputImage<MynthSDKTypes.ImageGenerationRequestOutputFormat> & {
776
+ /** Content rating. `undefined` when the request did not ask for one. */
777
+ rating: RatingT;
778
+ };
779
+ /**
780
+ * A completed image generation task.
781
+ *
782
+ * @template MetadataT - Type of the metadata attached to the request
783
+ * @template RatingT - Type of the rating response
784
+ */
785
+ type ImageGenerationResult<MetadataT = Record<string, unknown> | undefined, RatingT = MynthSDKTypes.ImageResultRating | undefined> = {
786
+ /** The task ID created for this request */
787
+ taskId: string;
788
+ /** Cost charged for the completed task */
789
+ cost: string;
790
+ /** Model that generated the images. Resolved to a concrete model when the request used `auto`. */
791
+ model: MynthSDKTypes.ImageGenerationModelId;
792
+ /** Successfully generated images, in order */
793
+ images: MynthGeneratedImage<RatingT>[];
794
+ /**
795
+ * Why images failed. A completed task can hold failed images; they are not
796
+ * in `images`.
797
+ */
798
+ failures: MynthSDKTypes.TaskError[];
799
+ /**
800
+ * The `url` of each successful image. Skips images whose `url` is `null`;
801
+ * read `images` to reach their `mynthUrl`.
802
+ */
803
+ urls: string[];
804
+ /** The prompt Mynth rewrote, when the request enabled `magic_prompt` */
805
+ magicPrompt: MynthSDKTypes.ImageResultMagicPrompt | undefined;
806
+ /** Metadata attached to the request */
807
+ metadata: MetadataT;
808
+ /** The request and result as the API returned them, for fields the SDK does not map yet */
809
+ raw: {
810
+ request: MynthSDKTypes.ImageGenerationRequest;
811
+ result: MynthSDKTypes.ImageResult;
812
+ };
813
+ };
814
+ //#endregion
815
+ //#region src/image-rate-result.d.ts
816
+ /**
817
+ * A completed image content rating task.
818
+ *
819
+ * @template LevelT - Union of possible rating level strings (e.g. `"sfw" | "nsfw"`)
820
+ */
821
+ type ImageRateResult<LevelT extends string = "sfw" | "nsfw"> = {
822
+ /** The task ID created for this rating request */
823
+ taskId: string;
824
+ /** Cost charged for the completed task */
825
+ cost: string;
826
+ /** Assigned rating level */
827
+ level: LevelT;
828
+ /** The request and result as the API returned them, for fields the SDK does not map yet */
829
+ raw: {
830
+ request: MynthSDKTypes.ImageRateRequest;
831
+ result: MynthSDKTypes.ImageRateTaskResult;
832
+ };
833
+ };
834
+ //#endregion
835
+ //#region src/image-remove-background-result.d.ts
836
+ /**
837
+ * A completed image background removal task.
838
+ *
839
+ * @template MetadataT - Type of the metadata attached to the request
840
+ */
841
+ type ImageRemoveBackgroundResult<MetadataT = Record<string, unknown> | undefined> = {
842
+ /** The task ID created for this request */
843
+ taskId: string;
844
+ /** Cost charged for the completed task */
845
+ cost: string;
846
+ /** The image with its background removed */
847
+ image: MynthOutputImage<MynthSDKTypes.ImageRemoveBackgroundOutputFormat>;
848
+ /** Metadata attached to the request */
849
+ metadata: MetadataT;
850
+ /** The request and result as the API returned them, for fields the SDK does not map yet */
851
+ raw: {
852
+ request: MynthSDKTypes.ImageRemoveBackgroundRequest;
853
+ result: MynthSDKTypes.ImageRemoveBackgroundTaskResult;
854
+ };
855
+ };
856
+ //#endregion
857
+ //#region src/image-review-result.d.ts
858
+ /**
859
+ * A completed image quality review task.
860
+ */
861
+ type ImageReviewResult = {
862
+ /** The task ID created for this review request */
863
+ taskId: string;
864
+ /** Cost charged for the completed task */
865
+ cost: string;
866
+ /** Median reviewer score from 1 to 4. Higher is better. */
867
+ score: number;
868
+ /** Review summary */
869
+ summary: string;
870
+ /** Defects found by the reviewer panel */
871
+ findings: MynthSDKTypes.ImageReviewFinding[];
872
+ /** Strengths identified by the reviewer panel */
873
+ strengths: MynthSDKTypes.ImageReviewStrength[];
874
+ /** The request and result as the API returned them, for fields the SDK does not map yet */
875
+ raw: {
876
+ request: MynthSDKTypes.ImageReviewRequest;
877
+ result: MynthSDKTypes.ImageReviewTaskResult;
878
+ };
879
+ };
880
+ //#endregion
881
+ //#region src/image-upscale-result.d.ts
882
+ /**
883
+ * A completed image upscale task.
884
+ *
885
+ * @template MetadataT - Type of the metadata attached to the request
886
+ */
887
+ type ImageUpscaleResult<MetadataT = Record<string, unknown> | undefined> = {
888
+ /** The task ID created for this request */
889
+ taskId: string;
890
+ /** Cost charged for the completed task */
891
+ cost: string;
892
+ /** The upscaled image */
893
+ image: MynthOutputImage<MynthSDKTypes.ImageUpscaleOutputFormat>;
894
+ /** Metadata attached to the request */
895
+ metadata: MetadataT;
896
+ /** The request and result as the API returned them, for fields the SDK does not map yet */
897
+ raw: {
898
+ request: MynthSDKTypes.ImageUpscaleRequest;
899
+ result: MynthSDKTypes.ImageUpscaleTaskResult;
900
+ };
901
+ };
902
+ //#endregion
903
+ //#region src/output-video.d.ts
904
+ /**
905
+ * A video produced by a Mynth video generation task.
906
+ */
907
+ type MynthOutputVideo = {
908
+ /** Video ID */
909
+ id: string;
910
+ /** Public URL of the video */
911
+ url: string;
912
+ /** Mynth CDN URL. Always set, and served for 7 days. */
913
+ mynthUrl: string;
914
+ /** Cost charged for this video */
915
+ cost: string;
916
+ /** Duration in seconds */
917
+ duration: number;
918
+ /** Resolution tier the video was rendered at */
919
+ resolution: MynthSDKTypes.VideoGenerationRequestResolution;
920
+ /** Whether the video has generated audio */
921
+ audio: boolean;
922
+ };
923
+ //#endregion
924
+ //#region src/video-generation-result.d.ts
925
+ /**
926
+ * A completed video generation task.
927
+ *
928
+ * @template MetadataT - Type of the metadata attached to the request
929
+ */
930
+ type VideoGenerationResult<MetadataT = Record<string, unknown> | undefined> = {
931
+ /** The task ID created for this request */
932
+ taskId: string;
933
+ /** Cost charged for the completed task. Failed videos are refunded. */
934
+ cost: string;
935
+ /** Model that generated the videos */
936
+ model: MynthSDKTypes.VideoGenerationModelId;
937
+ /** Successfully generated videos, in order */
938
+ videos: MynthOutputVideo[];
939
+ /**
940
+ * Why videos failed. A completed task can hold failed videos; they are not
941
+ * in `videos`.
942
+ */
943
+ failures: MynthSDKTypes.TaskError[];
944
+ /** The `url` of each successful video */
945
+ urls: string[];
946
+ /** Metadata attached to the request */
947
+ metadata: MetadataT;
948
+ /** The request and result as the API returned them, for fields the SDK does not map yet */
949
+ raw: {
950
+ request: MynthSDKTypes.VideoGenerationRequest;
951
+ result: MynthSDKTypes.VideoResult;
952
+ };
953
+ };
954
+ //#endregion
955
+ export { AvailableVideoModel as _, ImageRemoveBackgroundResult as a, VideoResolutionTier as b, MynthGeneratedImage as c, MynthCompletedTask as d, MynthTaskFailure as f, AvailableModel as g, AVAILABLE_VIDEO_MODELS as h, ImageReviewResult as i, MynthOutputImage as l, AVAILABLE_MODELS as m, MynthOutputVideo as n, ImageRateResult as o, MynthSDKTypes as p, ImageUpscaleResult as r, ImageGenerationResult as s, VideoGenerationResult as t, ImageAltResult as u, ModelCapability as v, VideoInputRole as y };
@@ -0,0 +1,216 @@
1
+ //#region src/image-alt-result.ts
2
+ /** Map a completed image alt text task. */
3
+ function toImageAltResult(task) {
4
+ return {
5
+ taskId: task.taskId,
6
+ cost: task.cost,
7
+ alt: task.result.alt,
8
+ raw: {
9
+ request: task.request,
10
+ result: task.result
11
+ }
12
+ };
13
+ }
14
+ //#endregion
15
+ //#region src/output-image.ts
16
+ const IMAGE_MIME_TYPES = {
17
+ png: "image/png",
18
+ jpg: "image/jpeg",
19
+ webp: "image/webp"
20
+ };
21
+ const SIZE_PATTERN = /^(\d+)x(\d+)$/;
22
+ function parseSize(size) {
23
+ const match = SIZE_PATTERN.exec(size);
24
+ if (!match) throw new Error(`Unexpected image size "${size}", expected {width}x{height}`);
25
+ return {
26
+ width: Number(match[1]),
27
+ height: Number(match[2])
28
+ };
29
+ }
30
+ /**
31
+ * Map an image from the API wire format.
32
+ *
33
+ * @throws {Error} If `size` is not `{width}x{height}`
34
+ */
35
+ function toOutputImage(image) {
36
+ const { width, height } = parseSize(image.size);
37
+ return {
38
+ id: image.id,
39
+ url: image.url,
40
+ mynthUrl: image.mynth_url,
41
+ width,
42
+ height,
43
+ size: image.size,
44
+ format: image.format,
45
+ mimeType: IMAGE_MIME_TYPES[image.format],
46
+ destination: image.destination
47
+ };
48
+ }
49
+ //#endregion
50
+ //#region src/image-generation-result.ts
51
+ /** Map a completed image generation task. */
52
+ function toImageGenerationResult(task) {
53
+ const images = [];
54
+ const failures = [];
55
+ for (const image of task.result.images) if (image.status === "success") images.push({
56
+ ...toOutputImage(image),
57
+ rating: image.rating
58
+ });
59
+ else failures.push(image.error);
60
+ return {
61
+ taskId: task.taskId,
62
+ cost: task.cost,
63
+ model: task.result.model,
64
+ images,
65
+ failures,
66
+ urls: images.flatMap((image) => image.url === null ? [] : [image.url]),
67
+ magicPrompt: task.result.magic_prompt,
68
+ metadata: task.request.metadata,
69
+ raw: {
70
+ request: task.request,
71
+ result: task.result
72
+ }
73
+ };
74
+ }
75
+ //#endregion
76
+ //#region src/image-rate-result.ts
77
+ /** Map a completed image content rating task. */
78
+ function toImageRateResult(task) {
79
+ return {
80
+ taskId: task.taskId,
81
+ cost: task.cost,
82
+ level: task.result.level,
83
+ raw: {
84
+ request: task.request,
85
+ result: task.result
86
+ }
87
+ };
88
+ }
89
+ //#endregion
90
+ //#region src/image-remove-background-result.ts
91
+ /** Map a completed image background removal task. */
92
+ function toImageRemoveBackgroundResult(task) {
93
+ return {
94
+ taskId: task.taskId,
95
+ cost: task.cost,
96
+ image: toOutputImage(task.result.image),
97
+ metadata: task.request.metadata,
98
+ raw: {
99
+ request: task.request,
100
+ result: task.result
101
+ }
102
+ };
103
+ }
104
+ //#endregion
105
+ //#region src/image-review-result.ts
106
+ /** Map a completed image quality review task. */
107
+ function toImageReviewResult(task) {
108
+ return {
109
+ taskId: task.taskId,
110
+ cost: task.cost,
111
+ score: task.result.score,
112
+ summary: task.result.summary,
113
+ findings: task.result.findings,
114
+ strengths: task.result.strengths,
115
+ raw: {
116
+ request: task.request,
117
+ result: task.result
118
+ }
119
+ };
120
+ }
121
+ //#endregion
122
+ //#region src/image-upscale-result.ts
123
+ /** Map a completed image upscale task. */
124
+ function toImageUpscaleResult(task) {
125
+ return {
126
+ taskId: task.taskId,
127
+ cost: task.cost,
128
+ image: toOutputImage(task.result.image),
129
+ metadata: task.request.metadata,
130
+ raw: {
131
+ request: task.request,
132
+ result: task.result
133
+ }
134
+ };
135
+ }
136
+ //#endregion
137
+ //#region src/task-result.ts
138
+ /**
139
+ * Read a completed task from polled task data.
140
+ *
141
+ * @param label - Names the task in errors, e.g. `"Image upscale"`
142
+ * @throws {Error} If the task has not completed, or completed without a cost
143
+ */
144
+ function completedTaskFromData(data, label) {
145
+ if (data.status !== "completed" || data.result === null) throw new Error(`${label} task ${data.id} is not completed`);
146
+ if (data.cost === null) throw new Error(`${label} task ${data.id} is missing cost`);
147
+ return {
148
+ taskId: data.id,
149
+ cost: data.cost,
150
+ request: data.request,
151
+ result: data.result
152
+ };
153
+ }
154
+ /**
155
+ * Read a completed task from a `...Completed` webhook payload.
156
+ *
157
+ * @throws {Error} If the payload has no cost
158
+ */
159
+ function completedTaskFromWebhook(payload) {
160
+ if (typeof payload.task.cost !== "string") throw new Error(`Webhook for task ${payload.task.id} is missing cost`);
161
+ return {
162
+ taskId: payload.task.id,
163
+ cost: payload.task.cost,
164
+ request: payload.request,
165
+ result: payload.result
166
+ };
167
+ }
168
+ /**
169
+ * Read a failed task from a `...Failed` webhook payload. Callers add
170
+ * `metadata` for task types whose request takes it.
171
+ */
172
+ function taskFailureFromWebhook(payload) {
173
+ return {
174
+ taskId: payload.task.id,
175
+ errors: payload.errors,
176
+ raw: { request: payload.request }
177
+ };
178
+ }
179
+ //#endregion
180
+ //#region src/output-video.ts
181
+ /** Map a successful video from the API wire format. */
182
+ function toOutputVideo(video) {
183
+ return {
184
+ id: video.id,
185
+ url: video.url,
186
+ mynthUrl: video.mynth_url,
187
+ cost: video.cost,
188
+ duration: video.duration,
189
+ resolution: video.resolution,
190
+ audio: video.audio
191
+ };
192
+ }
193
+ //#endregion
194
+ //#region src/video-generation-result.ts
195
+ /** Map a completed video generation task. */
196
+ function toVideoGenerationResult(task) {
197
+ const videos = [];
198
+ const failures = [];
199
+ for (const video of task.result.videos) if (video.status === "success") videos.push(toOutputVideo(video));
200
+ else failures.push(video.error);
201
+ return {
202
+ taskId: task.taskId,
203
+ cost: task.cost,
204
+ model: task.result.model,
205
+ videos,
206
+ failures,
207
+ urls: videos.map((video) => video.url),
208
+ metadata: task.request.metadata,
209
+ raw: {
210
+ request: task.request,
211
+ result: task.result
212
+ }
213
+ };
214
+ }
215
+ //#endregion
216
+ export { toImageUpscaleResult as a, toImageRateResult as c, taskFailureFromWebhook as i, toImageGenerationResult as l, completedTaskFromData as n, toImageReviewResult as o, completedTaskFromWebhook as r, toImageRemoveBackgroundResult as s, toVideoGenerationResult as t, toImageAltResult as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mynthio/sdk",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "description": "Official Mynth SDK for image generation and analysis",
5
5
  "keywords": [
6
6
  "ai",