@mynthio/sdk 0.0.44 → 0.0.46

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 CHANGED
@@ -473,6 +473,51 @@ const taskAsync = await mynth.image.removeBackgroundAsync({
473
473
  return { id: taskAsync.id, access: taskAsync.access };
474
474
  ```
475
475
 
476
+ ## Upscale
477
+
478
+ Enlarge an existing image 2x or 4x. Mynth picks the model, so there is no `model` field. `size` and `effort` are both required:
479
+
480
+ ```ts
481
+ const result = await mynth.image.upscale({
482
+ url: "https://example.com/product.jpg",
483
+ size: "2x",
484
+ effort: "low",
485
+ });
486
+
487
+ console.log(result.image.url); // upscaled image
488
+ console.log(result.image.size); // e.g. "2048x1536"
489
+ ```
490
+
491
+ `effort` sets the price: `low` is fast and sharp, `high` rebuilds fine detail such as small text and faces. `size` is `"2x"` or `"4x"`, or `{ type: "scale", factor: 2 | 4 }`. The upscaled image can be at most 4096x4096 pixels; a larger request fails with `OUTPUT_TOO_LARGE` and is not charged.
492
+
493
+ The result keeps the format the provider returned. Set `output.format` to always get `png`, `jpg`, or `webp`.
494
+ `upscale()` also takes a local `file`, plus `destination`, `webhook`, and `metadata` like `generate()`:
495
+
496
+ ```ts
497
+ const result = await mynth.image.upscale({
498
+ file,
499
+ size: "4x",
500
+ effort: "high",
501
+ output: { format: "webp" },
502
+ destination: "bunny-prod",
503
+ metadata: { productId: "sku_1" },
504
+ });
505
+
506
+ console.log(result.metadata.productId);
507
+ ```
508
+
509
+ Use `upscaleAsync()` to create the task without waiting. It returns a public access token, like `generateAsync()`:
510
+
511
+ ```ts
512
+ const taskAsync = await mynth.image.upscaleAsync({
513
+ url: "https://example.com/product.jpg",
514
+ size: "2x",
515
+ effort: "low",
516
+ });
517
+
518
+ return { id: taskAsync.id, access: taskAsync.access };
519
+ ```
520
+
476
521
  ## Working With Image Results
477
522
 
478
523
  Completed generation tasks expose a few helpful accessors:
@@ -839,6 +884,13 @@ export const mynthWebhook = mynthWebhookAction({
839
884
  imageRemoveBackgroundTaskFailed: async (payload) => {
840
885
  console.error("Mynth remove background task failed:", payload.task.id);
841
886
  },
887
+ imageUpscaleTaskCompleted: async (payload) => {
888
+ console.log("Completed upscale task:", payload.task.id);
889
+ console.log(payload.result.image.url);
890
+ },
891
+ imageUpscaleTaskFailed: async (payload) => {
892
+ console.error("Mynth upscale task failed:", payload.task.id);
893
+ },
842
894
  videoTaskCompleted: async (payload) => {
843
895
  console.log("Completed video task:", payload.task.id);
844
896
  console.log(payload.result.videos);
@@ -853,9 +905,9 @@ Set `MYNTH_WEBHOOK_SECRET` in your environment, or pass `webhookSecret` explicit
853
905
 
854
906
  ## Error Handling
855
907
 
856
- `upload()`, `generate()`, `generateAsync()`, `rate()`, `rateAsync()`, `alt()`, `altAsync()`, `review()`, `reviewAsync()`, `removeBackground()`, `removeBackgroundAsync()`, `models.list()`, and the `video` equivalents (`video.generate()`, `video.generateAsync()`, `video.upload()`, `video.estimate()`) may throw `MynthAPIError` if the request fails. Polling can also throw task-specific errors:
908
+ `upload()`, `generate()`, `generateAsync()`, `rate()`, `rateAsync()`, `alt()`, `altAsync()`, `review()`, `reviewAsync()`, `removeBackground()`, `removeBackgroundAsync()`, `upscale()`, `upscaleAsync()`, `models.list()`, and the `video` equivalents (`video.generate()`, `video.generateAsync()`, `video.upload()`, `video.estimate()`) may throw `MynthAPIError` if the request fails. Polling can also throw task-specific errors:
857
909
 
858
- While polling, transient failures (404, 5xx, dropped connections) are retried: a created task is owed an answer, so a cold cache or a brief outage does not lose you the result. Polling gives up after 20 consecutive failures (~100s) with `TaskAsyncFetchError` or `TaskAsyncTaskFetchError`, and immediately on a 401 or 403 with `TaskAsyncUnauthorizedError`. Image waits time out after 30 minutes, video waits after an hour.
910
+ While polling, transient failures (404, 5xx, dropped connections) are retried: a created task is owed an answer, so a cold cache or a brief outage does not lose you the result. A 429 slows polling down, doubling the interval up to 30 seconds, and only the timeout ends it. Polling gives up after 20 consecutive failures (~100s) with `TaskAsyncFetchError` or `TaskAsyncTaskFetchError`, immediately on a 401 or 403 with `TaskAsyncUnauthorizedError`, and immediately on any other 4xx with `TaskAsyncFetchError` or `TaskAsyncTaskFetchError`. Image waits time out after 30 minutes, video waits after an hour.
859
911
 
860
912
  ```ts
861
913
  import {
@@ -892,7 +944,7 @@ try {
892
944
 
893
945
  ## Documentation
894
946
 
895
- For product documentation and API guides, visit [docs.mynth.io](https://docs.mynth.io).
947
+ For product documentation and API guides, visit [mynth.io/docs](https://mynth.io/docs).
896
948
 
897
949
  ## Contributing
898
950
 
package/dist/handler.d.ts CHANGED
@@ -12,6 +12,8 @@ declare const EVENT_HANDLER_NAMES: {
12
12
  readonly "task.image.review.failed": "imageReviewTaskFailed";
13
13
  readonly "task.image.remove_background.completed": "imageRemoveBackgroundTaskCompleted";
14
14
  readonly "task.image.remove_background.failed": "imageRemoveBackgroundTaskFailed";
15
+ readonly "task.image.upscale.completed": "imageUpscaleTaskCompleted";
16
+ readonly "task.image.upscale.failed": "imageUpscaleTaskFailed";
15
17
  readonly "task.video.generate.completed": "videoTaskCompleted";
16
18
  readonly "task.video.generate.failed": "videoTaskFailed";
17
19
  };
package/dist/handler.js CHANGED
@@ -73,6 +73,8 @@ const EVENT_HANDLER_NAMES = {
73
73
  "task.image.review.failed": "imageReviewTaskFailed",
74
74
  "task.image.remove_background.completed": "imageRemoveBackgroundTaskCompleted",
75
75
  "task.image.remove_background.failed": "imageRemoveBackgroundTaskFailed",
76
+ "task.image.upscale.completed": "imageUpscaleTaskCompleted",
77
+ "task.image.upscale.failed": "imageUpscaleTaskFailed",
76
78
  "task.video.generate.completed": "videoTaskCompleted",
77
79
  "task.video.generate.failed": "videoTaskFailed"
78
80
  };
package/dist/index.d.ts CHANGED
@@ -197,6 +197,30 @@ export declare class ImageReviewResult {
197
197
  static fromTaskData(data: MynthSDKTypes.ImageReviewTaskData): ImageReviewResult;
198
198
  }
199
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
200
224
  //#region src/task-async.d.ts
201
225
  /**
202
226
  * Polling cadence overrides. Anything omitted keeps the image-task default.
@@ -224,10 +248,11 @@ export declare class TaskAsyncUnauthorizedError extends Error {
224
248
  constructor(taskId: string);
225
249
  }
226
250
  /**
227
- * Error thrown when fetching task status fails after multiple retries.
251
+ * Error thrown when fetching task status fails after multiple retries, or at
252
+ * once on a response that a retry cannot change (a 400, say).
228
253
  */
229
254
  export declare class TaskAsyncFetchError extends Error {
230
- constructor(taskId: string, cause?: Error);
255
+ constructor(taskId: string, cause?: Error, status?: number);
231
256
  }
232
257
  /**
233
258
  * Error thrown when fetching full task data fails.
@@ -292,7 +317,7 @@ export declare class TaskAsync<ResultT> {
292
317
  * @param options.signal - Stops this wait when aborted (see {@link TaskAsyncWaitOptions})
293
318
  * @throws {TaskAsyncTimeoutError} If polling exceeds the timeout
294
319
  * @throws {TaskAsyncUnauthorizedError} If access is denied
295
- * @throws {TaskAsyncFetchError} If fetching status fails repeatedly
320
+ * @throws {TaskAsyncFetchError} If fetching status fails repeatedly, or with a non-retryable 4xx
296
321
  * @throws {TaskAsyncTaskFetchError} If fetching the completed task fails
297
322
  * @throws {TaskAsyncTaskFailedError} If the task fails before completion
298
323
  */
@@ -386,6 +411,7 @@ type MynthModelPricing = MynthSDKTypes.ModelPricing;
386
411
  type ExtractMetadata<T extends MynthSDKTypes.ImageGenerationClientRequest> = T["metadata"];
387
412
  type ExtractVideoMetadata<T extends MynthSDKTypes.VideoGenerationClientRequest> = T["metadata"];
388
413
  type ExtractRemoveBackgroundMetadata<T extends MynthSDKTypes.ImageRemoveBackgroundClientRequest> = T["metadata"];
414
+ type ExtractUpscaleMetadata<T extends MynthSDKTypes.ImageUpscaleClientRequest> = T["metadata"];
389
415
  type ExtractRatingConfig<T extends MynthSDKTypes.ImageGenerationClientRequest> = T["rating"];
390
416
  type ExtractRatingLevels<T extends MynthSDKTypes.ImageGenerationClientRequest> = ExtractRatingConfig<T> extends {
391
417
  levels: readonly (infer L)[];
@@ -627,6 +653,38 @@ declare class MynthImage {
627
653
  */
628
654
  removeBackgroundAsync<const T extends MynthSDKTypes.ImageRemoveBackgroundClientRequest>(request: T): Promise<TaskAsync<ImageRemoveBackgroundResult<ExtractRemoveBackgroundMetadata<T>>>>;
629
655
  private createRemoveBackgroundTask;
656
+ /**
657
+ * Upscale a single image 2x or 4x.
658
+ *
659
+ * Mynth picks the model. `effort` sets the price, so it has no default. The
660
+ * upscaled image can be at most 4096x4096 pixels; a larger request fails
661
+ * with `OUTPUT_TOO_LARGE` and is not charged.
662
+ *
663
+ * @param request - Image URL or local file, size, and effort, plus optional output, destination, webhook, and metadata
664
+ * @returns An ImageUpscaleResult with the enlarged image
665
+ *
666
+ * @example
667
+ * ```typescript
668
+ * const result = await image.upscale({ url: "https://...", size: "2x", effort: "low" });
669
+ * console.log(result.image.url);
670
+ * ```
671
+ */
672
+ upscale<const T extends MynthSDKTypes.ImageUpscaleClientRequest>(request: T): Promise<ImageUpscaleResult<ExtractUpscaleMetadata<T>>>;
673
+ /**
674
+ * Start an upscale without waiting for completion.
675
+ *
676
+ * @param request - Image URL or local file, size, and effort, plus optional output, destination, webhook, and metadata
677
+ * @returns A TaskAsync that can be polled for completion via `.wait()`
678
+ *
679
+ * @example
680
+ * ```typescript
681
+ * const taskAsync = await image.upscaleAsync({ url: "https://...", size: "2x", effort: "low" });
682
+ *
683
+ * return { id: taskAsync.id, access: taskAsync.access };
684
+ * ```
685
+ */
686
+ upscaleAsync<const T extends MynthSDKTypes.ImageUpscaleClientRequest>(request: T): Promise<TaskAsync<ImageUpscaleResult<ExtractUpscaleMetadata<T>>>>;
687
+ private createUpscaleTask;
630
688
  }
631
689
  /**
632
690
  * Client for interacting with the Mynth video generation API.
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ const RATE_IMAGE_PATH = "/image/rate";
11
11
  const ALT_IMAGE_PATH = "/image/alt";
12
12
  const REVIEW_IMAGE_PATH = "/image/review";
13
13
  const REMOVE_BACKGROUND_IMAGE_PATH = "/image/remove-background";
14
+ const UPSCALE_IMAGE_PATH = "/image/upscale";
14
15
  const GENERATE_VIDEO_PATH = "/video/generate";
15
16
  const ESTIMATE_VIDEO_PATH = "/video/generate/estimate";
16
17
  const MODELS_PATH = "/models";
@@ -654,12 +655,46 @@ var ImageReviewResult = class ImageReviewResult {
654
655
  }
655
656
  };
656
657
  //#endregion
658
+ //#region src/image-upscale-result.ts
659
+ /**
660
+ * Represents the result of a completed image upscale task.
661
+ *
662
+ * @template MetadataT - Type of the metadata attached to the request
663
+ */
664
+ var ImageUpscaleResult = class ImageUpscaleResult {
665
+ /** The task ID created for this request */
666
+ taskId;
667
+ /** Cost charged for the completed task */
668
+ cost;
669
+ /** The upscaled image */
670
+ image;
671
+ /** Metadata attached to the request */
672
+ metadata;
673
+ constructor(data) {
674
+ this.taskId = data.taskId;
675
+ this.cost = data.cost;
676
+ this.image = data.image;
677
+ this.metadata = data.metadata;
678
+ }
679
+ static fromTaskData(data) {
680
+ if (data.status !== "completed" || data.result === null) throw new Error(`Image upscale task ${data.id} is not completed`);
681
+ if (data.cost === null) throw new Error(`Image upscale task ${data.id} is missing cost`);
682
+ return new ImageUpscaleResult({
683
+ taskId: data.id,
684
+ cost: data.cost,
685
+ image: data.result.image,
686
+ metadata: data.request.metadata
687
+ });
688
+ }
689
+ };
690
+ //#endregion
657
691
  //#region src/task-async.ts
658
692
  const POLLING_TIMEOUT_MS = 18e5;
659
693
  const FAST_POLLING_DURATION_MS = 12e3;
660
694
  const FAST_POLLING_INTERVAL_MS = 2500;
661
695
  const SLOW_POLLING_INTERVAL_MS = 5e3;
662
696
  const MAX_RETRY_COUNT = 20;
697
+ const MAX_RATE_LIMITED_INTERVAL_MS = 3e4;
663
698
  /**
664
699
  * Error thrown when task polling exceeds the maximum timeout duration.
665
700
  */
@@ -679,11 +714,12 @@ var TaskAsyncUnauthorizedError = class extends Error {
679
714
  }
680
715
  };
681
716
  /**
682
- * Error thrown when fetching task status fails after multiple retries.
717
+ * Error thrown when fetching task status fails after multiple retries, or at
718
+ * once on a response that a retry cannot change (a 400, say).
683
719
  */
684
720
  var TaskAsyncFetchError = class extends Error {
685
- constructor(taskId, cause) {
686
- super(`Failed to fetch status for task ${taskId} after multiple retries`);
721
+ constructor(taskId, cause, status) {
722
+ super(status ? `Failed to fetch status for task ${taskId} (status ${status})` : `Failed to fetch status for task ${taskId} after multiple retries`);
687
723
  this.name = "TaskAsyncFetchError";
688
724
  this.cause = cause;
689
725
  }
@@ -751,7 +787,7 @@ var TaskAsync = class {
751
787
  * @param options.signal - Stops this wait when aborted (see {@link TaskAsyncWaitOptions})
752
788
  * @throws {TaskAsyncTimeoutError} If polling exceeds the timeout
753
789
  * @throws {TaskAsyncUnauthorizedError} If access is denied
754
- * @throws {TaskAsyncFetchError} If fetching status fails repeatedly
790
+ * @throws {TaskAsyncFetchError} If fetching status fails repeatedly, or with a non-retryable 4xx
755
791
  * @throws {TaskAsyncTaskFetchError} If fetching the completed task fails
756
792
  * @throws {TaskAsyncTaskFailedError} If the task fails before completion
757
793
  */
@@ -797,19 +833,24 @@ var TaskAsync = class {
797
833
  const { timeoutMs, fastDurationMs, fastIntervalMs, intervalMs } = this.polling;
798
834
  const startTime = Date.now();
799
835
  let retryCount = 0;
836
+ let rateLimitedCount = 0;
800
837
  let useApiKeyFallback = false;
801
838
  let lastError;
802
839
  while (true) {
803
840
  const elapsed = Date.now() - startTime;
804
841
  if (elapsed >= timeoutMs) throw new TaskAsyncTimeoutError(this.id, timeoutMs);
805
842
  const result = await this.fetchStatus(useApiKeyFallback, signal);
843
+ let rateLimited = false;
806
844
  if (result.ok) {
807
845
  if (result.status === "completed") {
808
846
  const fetched = await this.fetchTask(signal);
809
847
  if (fetched.ok) return this.resultFactory(fetched.data);
810
848
  if (fetched.unauthorized) throw new TaskAsyncUnauthorizedError(this.id);
811
- retryCount++;
812
- if (!fetched.retryable || retryCount >= MAX_RETRY_COUNT) throw new TaskAsyncTaskFetchError(this.id, fetched.status, fetched.error);
849
+ if (fetched.rateLimited) rateLimited = true;
850
+ else {
851
+ retryCount++;
852
+ if (!fetched.retryable || retryCount >= MAX_RETRY_COUNT) throw new TaskAsyncTaskFetchError(this.id, fetched.status, fetched.error);
853
+ }
813
854
  } else if (result.status === "failed") throw new TaskAsyncTaskFailedError(this.id);
814
855
  else retryCount = 0;
815
856
  } else {
@@ -818,13 +859,17 @@ var TaskAsync = class {
818
859
  continue;
819
860
  }
820
861
  if (result.unauthorized) throw new TaskAsyncUnauthorizedError(this.id);
821
- if (result.retryable) {
862
+ if (!result.retryable) throw new TaskAsyncFetchError(this.id, result.error, result.status);
863
+ if (result.rateLimited) rateLimited = true;
864
+ else {
822
865
  retryCount++;
823
866
  lastError = result.error;
824
867
  if (retryCount >= MAX_RETRY_COUNT) throw new TaskAsyncFetchError(this.id, lastError);
825
868
  }
826
869
  }
827
- const interval = (elapsed < fastDurationMs ? fastIntervalMs : intervalMs) + Math.random() * 500;
870
+ rateLimitedCount = rateLimited ? rateLimitedCount + 1 : 0;
871
+ const baseInterval = elapsed < fastDurationMs ? fastIntervalMs : intervalMs;
872
+ const interval = Math.min(baseInterval * 2 ** rateLimitedCount, Math.max(baseInterval, MAX_RATE_LIMITED_INTERVAL_MS)) + Math.random() * 500;
828
873
  const remainingTime = timeoutMs - elapsed;
829
874
  const waitTime = Math.min(interval, remainingTime);
830
875
  await this.sleep(waitTime, signal);
@@ -852,6 +897,12 @@ var TaskAsync = class {
852
897
  retryable: true,
853
898
  notFound: true
854
899
  };
900
+ if (response.status === 429) return {
901
+ ok: false,
902
+ unauthorized: false,
903
+ retryable: true,
904
+ rateLimited: true
905
+ };
855
906
  if (response.status >= 500) return {
856
907
  ok: false,
857
908
  unauthorized: false,
@@ -860,7 +911,8 @@ var TaskAsync = class {
860
911
  return {
861
912
  ok: false,
862
913
  unauthorized: false,
863
- retryable: false
914
+ retryable: false,
915
+ status: response.status
864
916
  };
865
917
  } catch (error) {
866
918
  signal.throwIfAborted();
@@ -884,6 +936,13 @@ var TaskAsync = class {
884
936
  unauthorized: true,
885
937
  retryable: false
886
938
  };
939
+ if (response.status === 429) return {
940
+ ok: false,
941
+ unauthorized: false,
942
+ retryable: true,
943
+ rateLimited: true,
944
+ status: response.status
945
+ };
887
946
  if (response.status === 404 || response.status >= 500) return {
888
947
  ok: false,
889
948
  unauthorized: false,
@@ -1344,6 +1403,55 @@ var MynthImage = class {
1344
1403
  resultFactory: (taskData) => ImageRemoveBackgroundResult.fromTaskData(taskData)
1345
1404
  });
1346
1405
  }
1406
+ /**
1407
+ * Upscale a single image 2x or 4x.
1408
+ *
1409
+ * Mynth picks the model. `effort` sets the price, so it has no default. The
1410
+ * upscaled image can be at most 4096x4096 pixels; a larger request fails
1411
+ * with `OUTPUT_TOO_LARGE` and is not charged.
1412
+ *
1413
+ * @param request - Image URL or local file, size, and effort, plus optional output, destination, webhook, and metadata
1414
+ * @returns An ImageUpscaleResult with the enlarged image
1415
+ *
1416
+ * @example
1417
+ * ```typescript
1418
+ * const result = await image.upscale({ url: "https://...", size: "2x", effort: "low" });
1419
+ * console.log(result.image.url);
1420
+ * ```
1421
+ */
1422
+ async upscale(request) {
1423
+ return (await this.createUpscaleTask(request)).wait();
1424
+ }
1425
+ /**
1426
+ * Start an upscale without waiting for completion.
1427
+ *
1428
+ * @param request - Image URL or local file, size, and effort, plus optional output, destination, webhook, and metadata
1429
+ * @returns A TaskAsync that can be polled for completion via `.wait()`
1430
+ *
1431
+ * @example
1432
+ * ```typescript
1433
+ * const taskAsync = await image.upscaleAsync({ url: "https://...", size: "2x", effort: "low" });
1434
+ *
1435
+ * return { id: taskAsync.id, access: taskAsync.access };
1436
+ * ```
1437
+ */
1438
+ async upscaleAsync(request) {
1439
+ return this.createUpscaleTask(request);
1440
+ }
1441
+ async createUpscaleTask(request) {
1442
+ const url = await this.resolveUrlOrFile(request);
1443
+ const { file: _, url: __, ...rest } = request;
1444
+ const data = (await this.client.post(UPSCALE_IMAGE_PATH, {
1445
+ ...rest,
1446
+ url,
1447
+ destination: request.destination ?? this.defaultDestination
1448
+ })).data;
1449
+ return new TaskAsync(data.taskId, {
1450
+ client: this.client,
1451
+ pat: data.access?.publicAccessToken,
1452
+ resultFactory: (taskData) => ImageUpscaleResult.fromTaskData(taskData)
1453
+ });
1454
+ }
1347
1455
  };
1348
1456
  /**
1349
1457
  * Client for interacting with the Mynth video generation API.
@@ -1557,4 +1665,4 @@ var Mynth = class {
1557
1665
  }
1558
1666
  };
1559
1667
  //#endregion
1560
- export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS, ImageAltResult, ImageGenerationResult, ImageRateResult, ImageRemoveBackgroundResult, ImageReviewResult, Mynth, Mynth as default, MynthAPIError, MynthImage, MynthModels, MynthVideo, TaskAsync, TaskAsyncFetchError, TaskAsyncTaskFailedError, TaskAsyncTaskFetchError, TaskAsyncTimeoutError, TaskAsyncUnauthorizedError, VideoGenerationResult };
1668
+ export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS, ImageAltResult, ImageGenerationResult, ImageRateResult, ImageRemoveBackgroundResult, ImageReviewResult, ImageUpscaleResult, Mynth, Mynth as default, MynthAPIError, MynthImage, MynthModels, MynthVideo, TaskAsync, TaskAsyncFetchError, TaskAsyncTaskFailedError, TaskAsyncTaskFetchError, TaskAsyncTimeoutError, TaskAsyncUnauthorizedError, VideoGenerationResult };
package/dist/types.d.ts CHANGED
@@ -72,7 +72,7 @@ declare namespace MynthSDKTypes {
72
72
  data: DataT;
73
73
  };
74
74
  type TaskStatus = "pending" | "completed" | "failed";
75
- type TaskType = "image.generate" | "image.rate" | "image.alt" | "image.review" | "image.remove_background" | "video.generate";
75
+ type TaskType = "image.generate" | "image.rate" | "image.alt" | "image.review" | "image.remove_background" | "image.upscale" | "video.generate";
76
76
  type TaskBase = {
77
77
  id: string;
78
78
  status: TaskStatus;
@@ -107,6 +107,10 @@ declare namespace MynthSDKTypes {
107
107
  type: "image.remove_background";
108
108
  request: ImageRemoveBackgroundRequest;
109
109
  result: ImageRemoveBackgroundTaskResult | null;
110
+ }) | (TaskBase & {
111
+ type: "image.upscale";
112
+ request: ImageUpscaleRequest;
113
+ result: ImageUpscaleTaskResult | null;
110
114
  }) | (TaskBase & {
111
115
  type: "video.generate";
112
116
  request: VideoGenerationRequest;
@@ -127,6 +131,9 @@ declare namespace MynthSDKTypes {
127
131
  type ImageRemoveBackgroundTaskData = Extract<TaskData, {
128
132
  type: "image.remove_background";
129
133
  }>;
134
+ type ImageUpscaleTaskData = Extract<TaskData, {
135
+ type: "image.upscale";
136
+ }>;
130
137
  type VideoGenerationTaskData = Extract<TaskData, {
131
138
  type: "video.generate";
132
139
  }>;
@@ -435,6 +442,50 @@ declare namespace MynthSDKTypes {
435
442
  type ImageRemoveBackgroundTaskResult = {
436
443
  image: ImageRemoveBackgroundResultImage;
437
444
  };
445
+ type ImageUpscaleEffort = "low" | "high";
446
+ type ImageUpscaleFactor = 2 | 4;
447
+ type ImageUpscaleSize = "2x" | "4x" | {
448
+ type: "scale";
449
+ factor: ImageUpscaleFactor;
450
+ };
451
+ type ImageUpscaleOutputFormat = "png" | "jpg" | "webp";
452
+ type ImageUpscaleRequestOutput = {
453
+ /** Converts the result to this format. When omitted, the provider's format is kept. */
454
+ format?: ImageUpscaleOutputFormat;
455
+ };
456
+ type ImageUpscaleRequest = {
457
+ /** Image URL to upscale. */
458
+ url: string;
459
+ size: ImageUpscaleSize;
460
+ /** Sets the price, so there is no default. */
461
+ effort: ImageUpscaleEffort;
462
+ output?: ImageUpscaleRequestOutput;
463
+ webhook?: ImageGenerationRequestWebhook;
464
+ access?: ImageGenerationRequestAccess;
465
+ metadata?: Record<string, unknown>;
466
+ destination?: string;
467
+ };
468
+ type ImageUpscaleClientRequest = ImageClientUrlOrFile & Omit<ImageUpscaleRequest, "url">;
469
+ type ImageUpscaleCreatedResponse = {
470
+ taskId: string;
471
+ estimatedCost: string;
472
+ access?: {
473
+ publicAccessToken: string;
474
+ };
475
+ };
476
+ type ImageUpscaleResultImage = {
477
+ id: string;
478
+ /** Destination URL, or the Mynth URL without a destination. `null` when delivery failed. */
479
+ url: string | null;
480
+ mynth_url: string;
481
+ /** `{width}x{height}`. Can be a few pixels off the source times the factor. */
482
+ size: string;
483
+ format: ImageUpscaleOutputFormat;
484
+ destination?: ImageResultDestination;
485
+ };
486
+ type ImageUpscaleTaskResult = {
487
+ image: ImageUpscaleResultImage;
488
+ };
438
489
  type VideoGenerationModelId = "bytedance/seedance-2.0-mini" | "google/gemini-omni-flash-1.1" | "prunaai/p-video" | "xai/grok-imagine-video-1.5";
439
490
  type VideoGenerationModel = VideoGenerationModelId;
440
491
  type VideoGenerationRequestResolution = "480p" | "720p" | "1080p" | "4k";
@@ -593,6 +644,22 @@ declare namespace MynthSDKTypes {
593
644
  request: ImageRemoveBackgroundRequest;
594
645
  errors: TaskError[];
595
646
  };
647
+ type WebhookTaskImageUpscaleCompletedPayload = {
648
+ task: {
649
+ id: string;
650
+ };
651
+ event: "task.image.upscale.completed";
652
+ result: ImageUpscaleTaskResult;
653
+ request: ImageUpscaleRequest;
654
+ };
655
+ type WebhookTaskImageUpscaleFailedPayload = {
656
+ task: {
657
+ id: string;
658
+ };
659
+ event: "task.image.upscale.failed";
660
+ request: ImageUpscaleRequest;
661
+ errors: TaskError[];
662
+ };
596
663
  type WebhookTaskVideoCompletedPayload = {
597
664
  task: {
598
665
  id: string;
@@ -609,7 +676,7 @@ declare namespace MynthSDKTypes {
609
676
  request: VideoGenerationRequest;
610
677
  errors: TaskError[];
611
678
  };
612
- type WebhookPayload = WebhookTaskImageCompletedPayload | WebhookTaskImageFailedPayload | WebhookTaskImageRateCompletedPayload | WebhookTaskImageRateFailedPayload | WebhookTaskImageAltCompletedPayload | WebhookTaskImageAltFailedPayload | WebhookTaskImageReviewCompletedPayload | WebhookTaskImageReviewFailedPayload | WebhookTaskImageRemoveBackgroundCompletedPayload | WebhookTaskImageRemoveBackgroundFailedPayload | WebhookTaskVideoCompletedPayload | WebhookTaskVideoFailedPayload;
679
+ type WebhookPayload = WebhookTaskImageCompletedPayload | WebhookTaskImageFailedPayload | WebhookTaskImageRateCompletedPayload | WebhookTaskImageRateFailedPayload | WebhookTaskImageAltCompletedPayload | WebhookTaskImageAltFailedPayload | WebhookTaskImageReviewCompletedPayload | WebhookTaskImageReviewFailedPayload | WebhookTaskImageRemoveBackgroundCompletedPayload | WebhookTaskImageRemoveBackgroundFailedPayload | WebhookTaskImageUpscaleCompletedPayload | WebhookTaskImageUpscaleFailedPayload | WebhookTaskVideoCompletedPayload | WebhookTaskVideoFailedPayload;
613
680
  }
614
681
  //#endregion
615
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mynthio/sdk",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "description": "Official Mynth SDK for image generation and analysis",
5
5
  "keywords": [
6
6
  "ai",
@@ -45,11 +45,12 @@
45
45
  "devDependencies": {
46
46
  "@arethetypeswrong/core": "^0.18.5",
47
47
  "@types/node": "^22.20.4",
48
+ "@vitest/coverage-v8": "^5.0.2",
48
49
  "convex": "^1.46.0",
49
50
  "publint": "^0.3.24",
50
51
  "tsdown": "^0.23.0",
51
52
  "typescript": "7.0.2",
52
- "vitest": "^5.0.1"
53
+ "vitest": "^5.0.2"
53
54
  },
54
55
  "peerDependencies": {
55
56
  "convex": "^1.27.3"
@@ -62,6 +63,7 @@
62
63
  "scripts": {
63
64
  "build": "tsdown",
64
65
  "test": "vitest run",
66
+ "test:coverage": "vitest run --coverage",
65
67
  "test:watch": "vitest",
66
68
  "typecheck": "tsc"
67
69
  }