From 418e07e6a42ad01b73d51142a4d11928cdf7930c Mon Sep 17 00:00:00 2001 From: Ian Lunn Date: Fri, 27 Mar 2026 11:42:28 +0000 Subject: [PATCH 1/3] Update upscale() to accept open-ended payload --- Runware/Runware-base.ts | 42 +++++++---------------------------------- Runware/types.ts | 4 +++- package.json | 2 +- readme.md | 5 +++++ 4 files changed, 16 insertions(+), 37 deletions(-) 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 From 790053920257e0c5d07b3f3db76347738dd6778f Mon Sep 17 00:00:00 2001 From: Ian Lunn Date: Fri, 27 Mar 2026 11:52:14 +0000 Subject: [PATCH 2/3] Fix tests --- tests/Runware/remove-image-background.test.ts | 5 +---- tests/Runware/upscale-gan.test.ts | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Runware/remove-image-background.test.ts b/tests/Runware/remove-image-background.test.ts index 6c586be..0f7a77c 100644 --- a/tests/Runware/remove-image-background.test.ts +++ b/tests/Runware/remove-image-background.test.ts @@ -39,16 +39,13 @@ describe("When user request to remove image background", async () => { }); 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(); - expect(sendSpy).toHaveBeenCalledWith({ - inputImage: testExamples.imageUploadRes.imageUUID, + inputImage: mockUploadFile, taskUUID: mockTaskUUID, taskType: ETaskType.REMOVE_BACKGROUND, }); 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, From ae5a1da83607d6609916e07128b9b56ca78bf1f1 Mon Sep 17 00:00:00 2001 From: Ian Lunn Date: Fri, 27 Mar 2026 11:54:42 +0000 Subject: [PATCH 3/3] Fix TS issues --- tests/Runware/remove-image-background.test.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/Runware/remove-image-background.test.ts b/tests/Runware/remove-image-background.test.ts index 0f7a77c..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,20 +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 globalListenerSpy = vi.spyOn(runware as any, "globalListener"); const sendSpy = vi.spyOn(runware as any, "send"); - await runware.removeImageBackground({ inputImage: mockUploadFile }); + await runware.removeImageBackground({ inputImage: mockUploadFile, model: "runware:110@1" }); expect(sendSpy).toHaveBeenCalledWith({ inputImage: mockUploadFile, + model: "runware:110@1", taskUUID: mockTaskUUID, taskType: ETaskType.REMOVE_BACKGROUND, }); @@ -55,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" })); }); });