diff --git a/.gitignore b/.gitignore index f67effc..c7153af 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ dist/ *.env /tests/script.ts /tests/script-error.ts -.npmrc \ No newline at end of file +.npmrc +.claude \ No newline at end of file diff --git a/Runware/Runware-client.ts b/Runware/Runware-client.ts index c7f9b09..aaa80fe 100644 --- a/Runware/Runware-client.ts +++ b/Runware/Runware-client.ts @@ -1,14 +1,16 @@ import { RunwareBase } from "./Runware-base"; import ReconnectingWebsocket from "./reconnect"; import { ReconnectingWebsocketProps, RunwareBaseType } from "./types"; +import { buildSdkUrl } from "./utils"; export class RunwareClient extends RunwareBase { constructor(props: RunwareBaseType) { const { shouldReconnect, ...rest } = props; super(rest); + const url = buildSdkUrl(this._url || ""); this._ws = new (ReconnectingWebsocket as any)( - this._url + url ) as ReconnectingWebsocketProps; this.connect(); } diff --git a/Runware/Runware-server.ts b/Runware/Runware-server.ts index 5626b07..1255545 100644 --- a/Runware/Runware-server.ts +++ b/Runware/Runware-server.ts @@ -4,6 +4,7 @@ import WebSocket from "ws"; import { RunwareBase } from "./Runware-base"; import { ETaskType, RunwareBaseType, SdkType } from "./types"; +import { buildSdkUrl, SDK_VERSION } from "./utils"; // let allImages: IImage[] = []; @@ -53,8 +54,13 @@ export class RunwareServer extends RunwareBase { this.resetConnection(); - this._ws = new WebSocket(this._url, { + const url = buildSdkUrl(this._url); + this._ws = new WebSocket(url, { perMessageDeflate: false, + headers: { + "X-SDK-Name": "js", + "X-SDK-Version": SDK_VERSION, + }, }); // delay(1); diff --git a/Runware/async-retry.ts b/Runware/async-retry.ts index 621c177..17a979a 100644 --- a/Runware/async-retry.ts +++ b/Runware/async-retry.ts @@ -22,7 +22,7 @@ export const asyncRetry = async ( maxRetries--; if (maxRetries > 0) { await delay(delayInSeconds); // Delay before the next retry - await asyncRetry(apiCall, { ...options, maxRetries }); + return await asyncRetry(apiCall, { ...options, maxRetries }); } else { throw error; // Throw the error if max retries are reached } diff --git a/Runware/index.ts b/Runware/index.ts index 74b1de6..aff1bee 100644 --- a/Runware/index.ts +++ b/Runware/index.ts @@ -3,3 +3,4 @@ export * from "./types"; export * from "./Runware-server"; export * from "./Runware"; +export { SDK_VERSION } from "./utils"; diff --git a/Runware/utils.ts b/Runware/utils.ts index 7c6a621..d8508b3 100644 --- a/Runware/utils.ts +++ b/Runware/utils.ts @@ -7,6 +7,14 @@ import { IRequestImage, } from "./types"; import { v4 as uuidv4, validate as validateUUID } from "uuid"; +import pkg from "../package.json"; + +export const SDK_VERSION = pkg.version; + +export function buildSdkUrl(baseUrl: string): string { + const separator = baseUrl.includes("?") ? "&" : "?"; + return `${baseUrl}${separator}sdk=js&version=${SDK_VERSION}`; +} export const TIMEOUT_DURATION = 60000; // 120S; export const MINIMUM_TIMEOUT_DURATION = 1000; // 120S; diff --git a/package.json b/package.json index 0b84c8a..62da273 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@runware/sdk-js", - "version": "1.2.6", + "version": "1.2.7", "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 67452aa..c624e2f 100644 --- a/readme.md +++ b/readme.md @@ -739,11 +739,15 @@ export type TImageMaskingResponse = { ## Changelog +### - v1.2.7 + +- Fix in-memory recursive while loop call without returning for async-retry +- Add sdk versioning to connection + ### - v1.2.6 - Update upscale() to accept open-ended payload - ### - v1.2.5 - Fix JS SDK error race condition diff --git a/tsconfig.json b/tsconfig.json index 8daf163..bf6dbd7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "strict": true, "esModuleInterop": true, "allowJs": true, + "resolveJsonModule": true, "skipLibCheck": true }, "exclude": ["node_modules", "dist"],