@ldavis9000aws/swarmui-generator
Version:
A Model Context Protocol server for SwarmUI image generation with TypeScript
95 lines (94 loc) • 3.09 kB
TypeScript
/**
* SwarmUI API Client
*
* Handles communication with the SwarmUI API, including session management,
* image generation, model listing, and other API operations.
*/
import { AxiosRequestConfig } from 'axios';
import { ImageGenerationOptions, ModelInfo, SchedulerInfo, EngineStatus, ImageGenerationResponse } from '../types/index.js';
export interface ListModelsOptions {
path?: string;
depth?: number;
subtype?: string;
sortBy?: string;
sortReverse?: boolean;
allowRemote?: boolean;
}
export interface ListModelsResponse {
files: ModelInfo[];
folders: string[];
}
export declare class SwarmUIClient {
private baseUrl;
private client;
private sessionId;
private sessionRefreshTimer;
private readonly sessionRefreshInterval;
/**
* Create a new SwarmUI API client
* @param baseUrl Base URL of the SwarmUI API server
*/
constructor(baseUrl: string);
/**
* Get a new session ID from the SwarmUI API
* @returns Session ID string
*/
private getNewSession;
/**
* Ensure we have a valid session ID
* @returns Valid session ID
*/
private ensureSession;
/**
* Call the SwarmUI API
* @param endpoint API endpoint name (without the /API/ prefix)
* @param data Request data
* @param config Additional Axios request configuration
* @returns API response
*/
callApi<T = unknown>(endpoint: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<T>;
/**
* Download an image from the SwarmUI API
* @param imagePath Image path returned by the API
* @returns Image data as a Buffer
*/
downloadImage(imagePath: string): Promise<Buffer>;
/**
* Download and encode an image to base64
* @param imagePath Image path returned by the API
* @returns Base64 encoded image string (without data URI prefix)
*/
downloadAndEncodeImage(imagePath: string): Promise<string>;
/**
* List available models and folders
* @param options Options for listing models including path, depth, subtype, sortBy, sortReverse, allowRemote.
* @returns Object containing lists of available models (files) and folders
*/
listModels(options?: ListModelsOptions): Promise<ListModelsResponse>;
/**
* List available schedulers
* @returns List of available schedulers
*/
listSchedulers(): Promise<SchedulerInfo[]>;
/**
* Generate an image from a text prompt
* @param prompt Text prompt
* @param options Generation options
* @returns Image generation response with paths to generated images
*/
generateImage(prompt: string, options?: ImageGenerationOptions): Promise<ImageGenerationResponse>;
/**
* Get the status of the text-to-image engine
* @returns Engine status
*/
getEngineStatus(): Promise<EngineStatus>;
/**
* Check server health
* @returns True if server is healthy
*/
checkHealth(): Promise<boolean>;
/**
* Clean up resources
*/
destroy(): void;
}