diff --git a/Runware/Runware-base.ts b/Runware/Runware-base.ts index 60416ea..41e567e 100644 --- a/Runware/Runware-base.ts +++ b/Runware/Runware-base.ts @@ -1111,23 +1111,9 @@ export class RunwareBase { * @since 1.2.0 * @returns {Promise} If called with `inputs.image` or `inputs.video`, returns an object with `mediaUUID` and `mediaURL`. If called with `inputImage`, returns an object with `imageUUID` and `imageURL` (not guaranteed). */ - upscaleGan = async ({ - inputImage, - inputs, - model, - upscaleFactor, - outputType, - outputFormat, - includeCost, - outputQuality, - customTaskUUID, - taskUUID: _taskUUID, - retry, - includeGenerationTime, - includePayload, - skipResponse, - deliveryMethod, - }: IUpscaleGan): Promise => { + upscaleGan = async (payload: IUpscaleGan): Promise => { + const { inputImage, skipResponse, deliveryMethod = "sync", ...rest } = payload; + try { let imageUploaded; @@ -1137,28 +1123,13 @@ export class RunwareBase { imageUploaded = await this.uploadImage(inputImage as File | string); } - const taskUUID = _taskUUID || customTaskUUID || getUUID(); - const payload = { - taskUUID, - inputImage: imageUploaded?.imageUUID, - taskType: ETaskType.UPSCALE, - inputs, - model, - upscaleFactor, - ...evaluateNonTrue({ key: "includeCost", value: includeCost }), - ...(outputType ? { outputType } : {}), - ...(outputQuality ? { outputQuality } : {}), - ...(outputFormat ? { outputFormat } : {}), - includePayload, - includeGenerationTime, - retry, - deliveryMethod, - }; const request = await this.baseSingleRequest({ payload: { - ...payload, + ...rest, + ...(imageUploaded?.imageUUID ? { inputImage: imageUploaded.imageUUID } : {}), taskType: ETaskType.UPSCALE, + deliveryMethod, }, debugKey: "upscale", }); @@ -1166,6 +1137,7 @@ export class RunwareBase { if (skipResponse) { return request; } + if (deliveryMethod === "async") { const taskUUID = request?.taskUUID; diff --git a/Runware/types.ts b/Runware/types.ts index e6d81d5..348a56e 100644 --- a/Runware/types.ts +++ b/Runware/types.ts @@ -511,7 +511,7 @@ export interface IEnhancedPrompt extends IImageToText {} export interface IUpscaleGan extends IAdditionalResponsePayload { inputImage?: File | string; - upscaleFactor: number; + upscaleFactor?: number; outputType?: IOutputType; outputFormat?: IOutputFormat | "MP4" | "WEBM" | "MOV"; includeCost?: boolean; @@ -531,6 +531,8 @@ export interface IUpscaleGan extends IAdditionalResponsePayload { skipResponse?: boolean; deliveryMethod?: string; + + [key: string]: any; } export type ReconnectingWebsocketProps = { diff --git a/package.json b/package.json index 661e72d..0b84c8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@runware/sdk-js", - "version": "1.2.5", + "version": "1.2.6", "description": "The SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.", "main": "dist/index.js", "module": "dist/index.js", diff --git a/readme.md b/readme.md index f20688d..67452aa 100644 --- a/readme.md +++ b/readme.md @@ -739,6 +739,11 @@ export type TImageMaskingResponse = { ## Changelog +### - v1.2.6 + +- Update upscale() to accept open-ended payload + + ### - v1.2.5 - Fix JS SDK error race condition diff --git a/tests/Runware/remove-image-background.test.ts b/tests/Runware/remove-image-background.test.ts index 6c586be..3c33c5a 100644 --- a/tests/Runware/remove-image-background.test.ts +++ b/tests/Runware/remove-image-background.test.ts @@ -1,13 +1,12 @@ import { expect, test, - beforeAll, vi, describe, afterEach, beforeEach, } from "vitest"; -import { mockTaskUUID, mockUploadFile, testExamples } from "../test-utils"; +import { mockTaskUUID, mockUploadFile } from "../test-utils"; import { startMockServer } from "../mockServer"; import { ETaskType } from "../../Runware"; @@ -32,23 +31,15 @@ describe("When user request to remove image background", async () => { mockServer.stop(); }); - beforeAll(async () => { - vi.spyOn(runware as any, "uploadImage").mockReturnValue( - testExamples.imageUploadRes - ); - }); - test("it should remove an image background", async () => { - const imageUploadSpy = vi.spyOn(runware as any, "uploadImage"); const globalListenerSpy = vi.spyOn(runware as any, "globalListener"); const sendSpy = vi.spyOn(runware as any, "send"); - await runware.removeImageBackground({ inputImage: mockUploadFile }); - - expect(imageUploadSpy).toHaveBeenCalled(); + await runware.removeImageBackground({ inputImage: mockUploadFile, model: "runware:110@1" }); expect(sendSpy).toHaveBeenCalledWith({ - inputImage: testExamples.imageUploadRes.imageUUID, + inputImage: mockUploadFile, + model: "runware:110@1", taskUUID: mockTaskUUID, taskType: ETaskType.REMOVE_BACKGROUND, }); @@ -58,7 +49,7 @@ describe("When user request to remove image background", async () => { }); test("removeBackground delegates to removeImageBackground", async () => { - const result = await runware.removeBackground({ inputImage: mockUploadFile }); - expect(result).toEqual(await runware.removeImageBackground({ inputImage: mockUploadFile })); + const result = await runware.removeBackground({ inputImage: mockUploadFile, model: "runware:110@1" }); + expect(result).toEqual(await runware.removeImageBackground({ inputImage: mockUploadFile, model: "runware:110@1" })); }); }); diff --git a/tests/Runware/upscale-gan.test.ts b/tests/Runware/upscale-gan.test.ts index 49457d7..902f2b2 100644 --- a/tests/Runware/upscale-gan.test.ts +++ b/tests/Runware/upscale-gan.test.ts @@ -55,6 +55,7 @@ describe("When user request to upscale gan", async () => { taskUUID: mockTaskUUID, upscaleFactor: 2, taskType: ETaskType.UPSCALE, + deliveryMethod: "sync", }); expect(globalListenerSpy).toHaveBeenCalledWith({ taskUUID: mockTaskUUID,