n8n-nodes-selfhosthub
Version:
Collection of n8n nodes for self-hosted AI services, including Leonardo.ai integration for AI image and content generation capabilities.
1,292 lines • 64.4 kB
JavaScript
"use strict";
// CreateLeonardoImage.node.ts
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateLeonardoImage = void 0;
const models_1 = require("./models");
const parameterUtils_1 = require("./parameterUtils");
// Note: For local development with isolatedModules=true,
// we need a different approach to handle NodeConnectionType
class CreateLeonardoImage {
constructor() {
this.description = {
displayName: 'Self-Host Hub (Leonardo)',
name: 'createLeonardoImage',
icon: 'file:createLeonardoImage.png',
group: ['selfhosthub'],
version: 1,
subtitle: '={{$parameter["operation"]}}',
description: "Generate high-quality AI images using Leonardo's powerful models with advanced options and complete customization",
defaults: {
name: 'Self-Host Hub (Leonardo)',
},
documentationUrl: 'https://docs.leonardo.ai/docs/getting-started',
// We use NodeConnectionType.Main directly because isolatedModules is disabled in tsconfig.json
// If isolatedModules is enabled, these would need to be replaced with string literals and type assertions
// For more details, see docs/DEVELOPMENT_GUIDELINES.md#typescript-configuration
inputs: [
{
type: "main" /* NodeConnectionType.Main */,
displayName: 'Input',
},
],
outputs: [
{
type: "main" /* NodeConnectionType.Main */,
displayName: 'Output',
},
],
credentials: [
{
name: 'createLeonardoImageCredentials',
required: true,
},
],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
options: [
{
name: 'Generate Image',
value: 'createLeonardoImage',
description: 'Generate an image from a prompt',
},
],
default: 'createLeonardoImage',
noDataExpression: true,
},
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
required: true,
default: '',
description: 'The prompt to generate the image from',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
},
},
},
{
displayName: 'Width',
name: 'width',
type: 'number',
typeOptions: {
minValue: 32,
maxValue: 4096,
},
default: 1024,
required: true,
description: 'The width of the generated image (min 32px, max 4096px)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
},
},
},
{
displayName: 'Height',
name: 'height',
type: 'number',
typeOptions: {
minValue: 32,
maxValue: 4096,
},
default: 576,
required: true,
description: 'The height of the generated image (min 32px, max 4096px)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
},
},
},
{
displayName: 'Number of Images',
name: 'numImages',
type: 'number',
typeOptions: {
minValue: 1,
maxValue: 10,
},
default: 1,
required: true,
description: 'The number of images to generate',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
},
},
},
{
displayName: 'Model Selection Method',
name: 'modelSelectionMethod',
type: 'options',
options: [
{
name: 'Select from List',
value: 'list',
},
{
name: 'Custom Model ID',
value: 'custom',
},
],
default: 'list',
description: 'Choose between selecting a model from the list or entering a custom model ID',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
},
},
},
{
displayName: 'Model',
name: 'modelId',
type: 'options',
options: models_1.models,
default: '1e60896f-3c26-4296-8ecc-53e2afecc132', // Leonardo Diffusion XL as default
required: true,
description: 'The model to use for image generation',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
modelSelectionMethod: ['list'],
},
},
},
{
displayName: 'Custom Model ID',
name: 'customModelId',
type: 'string',
default: '',
required: true,
placeholder: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
description: 'Enter the UUID of the model you want to use (found in Leonardo.ai interface or API docs)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
modelSelectionMethod: ['custom'],
},
},
},
{
displayName: 'Advanced Options',
name: 'advancedOptions',
type: 'boolean',
default: false,
description: 'Whether to set advanced image generation options',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
},
},
},
// Image Options
{
displayName: '🔷 Image Options',
name: 'imageOptionsHeading',
type: 'notice',
default: '',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Make Public',
name: 'public',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Yes',
value: 'true',
},
{
name: 'No',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Whether the generated images should show in the community feed',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Tiling',
name: 'tiling',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Whether the generated images should tile on all axes',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Transparency',
name: 'transparency',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Disabled',
value: 'disabled',
},
{
name: 'Foreground Only',
value: 'foreground_only',
},
],
default: 'NO_SELECTION',
description: "Generate images with transparent background. API only accepts 'disabled' or 'foreground_only'.",
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Enable Unzoom',
name: 'unzoom',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Whether the generated images should be unzoomed (requires unzoomAmount)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Unzoom Amount',
name: 'unzoomAmount',
type: 'number',
default: 0.2,
typeOptions: {
minValue: 0.1,
maxValue: 1.0,
numberPrecision: 2,
},
description: 'Amount of unzoom to apply (required when unzoom is enabled)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
unzoom: ['true'],
},
},
},
{
displayName: 'Alchemy',
name: 'alchemy',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'BETA feature for paid users. Brings incredibly high-fidelity image generation and coherence',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'NSFW Filter (⚠️ Read-only)',
name: 'nsfwFilter',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'NOT CURRENTLY SUPPORTED BY API. The NSFW filter is controlled by the API directly. Changing this setting has no effect due to API limitations.',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Weighting',
name: 'weighting',
type: 'number',
default: 0.5,
typeOptions: {
minValue: 0.0,
maxValue: 1.0,
numberPrecision: 2,
},
description: 'How much weighting to use for generation',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Canvas Request',
name: 'canvasRequest',
type: 'options',
options: [
{
name: 'No Selection',
value: '',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: '',
description: 'Whether the generation is for the Canvas Editor feature',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Canvas Request Type',
name: 'canvasRequestType',
type: 'options',
options: [
{
name: 'No Selection',
value: '',
},
{
name: 'INPAINT',
value: 'INPAINT',
},
{
name: 'OUTPAINT',
value: 'OUTPAINT',
},
{
name: 'SKETCH2IMG',
value: 'SKETCH2IMG',
},
{
name: 'IMG2IMG',
value: 'IMG2IMG',
},
],
default: '',
description: 'The type of request for the Canvas Editor',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
canvasRequest: ['true'],
},
},
},
{
displayName: 'High Contrast',
name: 'highContrast',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable (RAW Mode)',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Enable High Contrast feature of Prompt Magic. Setting to false enables RAW mode.',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'High Resolution',
name: 'highResolution',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Enable the High Resolution feature of Prompt Magic',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
// Prompt Engineering
{
displayName: '🔹 Prompt Engineering',
name: 'promptEngineeringHeading',
type: 'notice',
default: '',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Negative Prompt',
name: 'negativePrompt',
type: 'string',
default: '',
description: 'Things to exclude from the generated image',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Enable Prompt Magic',
name: 'promptMagic',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Custom render pipeline for better prompt adherence and higher fidelity (increases token cost)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Prompt Magic Strength',
name: 'promptMagicStrength',
type: 'number',
default: 0.5,
typeOptions: {
minValue: 0.1,
maxValue: 1.0,
numberPrecision: 2,
},
description: 'Controls how strongly Prompt Magic influences the result',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
promptMagic: ['true'],
},
},
},
{
displayName: 'Enhance Prompt',
name: 'enhancePrompt',
type: 'options',
options: [
{
name: 'No Selection',
value: '',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: '',
description: 'When enabled, your prompt is expanded to include more detail',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Enhance Prompt Instruction',
name: 'enhancePromptInstruction',
type: 'string',
default: '',
description: 'When enhancePrompt is enabled, the prompt is enhanced based on the given instructions',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
enhancePrompt: ['true'],
},
},
},
// Generation Parameters
{
displayName: '🔵 Generation Parameters',
name: 'generationParametersHeading',
type: 'notice',
default: '',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Guidance Scale',
name: 'guidanceScale',
type: 'number',
default: 5,
typeOptions: {
minValue: 1,
maxValue: 20,
},
description: 'How closely the image follows the prompt (1-20, higher values increase prompt accuracy but cost more)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Scheduler',
name: 'scheduler',
type: 'options',
options: [
{
name: 'DDIM',
value: 'DDIM',
description: 'Recommended: Most reliable scheduler option',
},
{
name: 'DPM Solver',
value: 'DPM_SOLVER',
},
{
name: 'PNDM',
value: 'PNDM',
},
{
name: 'Euler Discrete',
value: 'EULER_DISCRETE',
},
{
name: 'Euler Ancestral Discrete',
value: 'EULER_ANCESTRAL_DISCRETE',
},
{
name: 'KLMS',
value: 'KLMS',
},
{
name: 'Leonardo',
value: 'LEONARDO',
description: 'When using this scheduler without Alchemy, guidance scale cannot exceed 7',
},
],
default: 'EULER_DISCRETE',
description: 'The sampling scheduler to use',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Seed',
name: 'seed',
type: 'string',
default: '',
description: 'Seed for reproducible generations (leave empty for random)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Inference Steps',
name: 'inferenceSteps',
type: 'number',
default: 20,
typeOptions: {
minValue: 20,
maxValue: 60,
},
description: 'Number of denoising steps (20-60, higher values increase quality but cost more)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
// Image-to-Image
{
displayName: '🔷 Image-to-Image',
name: 'imageToImageHeading',
type: 'notice',
default: '',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Enable Image-to-Image',
name: 'imageToImage',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Generate an image based on a reference image',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Init Image URL',
name: 'initImageUrl',
type: 'string',
default: '',
description: 'URL of the image to use as reference',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
imageToImage: ['true'],
},
},
},
{
displayName: 'Init Strength',
name: 'initStrength',
type: 'number',
default: 0.5,
typeOptions: {
minValue: 0.0,
maxValue: 1.0,
numberPrecision: 2,
},
description: 'How much to preserve from the initial image (lower = more creative)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
imageToImage: ['true'],
},
},
},
{
displayName: '🔷 Additional Settings',
name: 'additionalSettingsHeading',
type: 'notice',
default: '',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'SD Version',
name: 'sdVersion',
type: 'options',
options: [
{
name: 'Default (Auto)',
value: '',
},
{
name: 'SD 1.5',
value: 'v1_5',
},
{
name: 'SD 2.1',
value: 'v2',
},
{
name: 'SD v3',
value: 'v3',
},
{
name: 'SDXL 0.8',
value: 'SDXL_0_8',
},
{
name: 'SDXL 0.9',
value: 'SDXL_0_9',
},
{
name: 'SDXL 1.0',
value: 'SDXL_1_0',
},
{
name: 'SDXL Lightning',
value: 'SDXL_LIGHTNING',
},
{
name: 'Phoenix',
value: 'PHOENIX',
},
{
name: 'Flux',
value: 'FLUX',
},
{
name: 'Flux Dev',
value: 'FLUX_DEV',
},
],
default: '',
description: 'The base version of stable diffusion to use if not using a custom model',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'PhotoReal Version',
name: 'photoRealVersion',
type: 'options',
options: [
{
name: 'None',
value: '',
},
{
name: 'V1',
value: 'v1',
},
{
name: 'V2',
value: 'v2',
},
],
default: '',
description: 'The version of photoReal to use. Must be v1 or v2.',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'PhotoReal Strength',
name: 'photoRealStrength',
type: 'options',
options: [
{
name: 'Low',
value: '0.55',
},
{
name: 'Medium',
value: '0.5',
},
{
name: 'High',
value: '0.45',
},
],
default: '0.55',
description: 'Depth of field for photoReal. 0.55 for low, 0.5 for medium, 0.45 for high.',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
photoRealVersion: ['v1', 'v2'],
},
},
},
{
displayName: 'PhotoReal',
name: 'photoReal',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Enable the photoReal feature (requires alchemy to be enabled)',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Expanded Domain',
name: 'expandedDomain',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Enable the Expanded Domain feature of Alchemy',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Fantasy Avatar',
name: 'fantasyAvatar',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Enable the Fantasy Avatar feature',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Ultra',
name: 'ultra',
type: 'options',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'Enable',
value: 'true',
},
{
name: 'Disable',
value: 'false',
},
],
default: 'NO_SELECTION',
description: 'Enable Ultra mode. ⚠️ Cannot be used with Alchemy.',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Preset Style',
name: 'presetStyle',
type: 'options',
default: 'NO_SELECTION',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'PhotoReal (enabled)',
value: 'PHOTOREAL',
},
{
name: 'Cinematic',
value: 'CINEMATIC',
},
{
name: 'Creative',
value: 'CREATIVE',
},
],
description: 'NOT CURRENTLY SUPPORTED BY API. Style preset to apply to the generated images.',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Contrast',
name: 'contrast',
type: 'options',
options: [
{
name: '1.0',
value: '1.0',
},
{
name: '1.3',
value: '1.3',
},
{
name: '1.8',
value: '1.8',
},
{
name: '2.5',
value: '2.5',
},
{
name: '3.0',
value: '3.0',
},
{
name: '3.5',
value: '3.5',
},
{
name: '4.0',
value: '4.0',
},
{
name: '4.5',
value: '4.5',
},
],
default: '1.0',
description: 'Adjusts contrast level of generated image. For Phoenix, if alchemy is true, must be 2.5 or higher.',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'Preset Style',
name: 'presetStyle',
type: 'options',
default: 'NO_SELECTION',
options: [
{
name: 'No Selection',
value: 'NO_SELECTION',
},
{
name: 'PhotoReal (enabled)',
value: 'PHOTOREAL',
},
{
name: 'Cinematic',
value: 'CINEMATIC',
},
{
name: 'Creative',
value: 'CREATIVE',
},
{
name: 'Vibrant',
value: 'VIBRANT',
},
{
name: 'None',
value: 'NONE',
},
{
name: 'Alchemy (enabled)',
value: 'ALCHEMY',
},
{
name: 'Anime',
value: 'ANIME',
},
{
name: 'Bokeh',
value: 'BOKEH',
},
{
name: 'Cinematic Closeup',
value: 'CINEMATIC_CLOSEUP',
},
{
name: 'Dynamic',
value: 'DYNAMIC',
},
{
name: 'Environment',
value: 'ENVIRONMENT',
},
{
name: 'Fashion',
value: 'FASHION',
},
{
name: 'Film',
value: 'FILM',
},
{
name: 'Food',
value: 'FOOD',
},
{
name: 'General',
value: 'GENERAL',
},
{
name: 'HDR',
value: 'HDR',
},
{
name: 'Illustration',
value: 'ILLUSTRATION',
},
{
name: 'Leonardo',
value: 'LEONARDO',
},
{
name: 'Long Exposure',
value: 'LONG_EXPOSURE',
},
{
name: 'Macro',
value: 'MACRO',
},
{
name: 'Minimalistic',
value: 'MINIMALISTIC',
},
{
name: 'Monochrome',
value: 'MONOCHROME',
},
{
name: 'Moody',
value: 'MOODY',
},
{
name: 'Neutral',
value: 'NEUTRAL',
},
{
name: 'Photography',
value: 'PHOTOGRAPHY',
},
{
name: 'Portrait',
value: 'PORTRAIT',
},
{
name: 'Raytraced',
value: 'RAYTRACED',
},
{
name: 'Render 3D',
value: 'RENDER_3D',
},
{
name: 'Retro',
value: 'RETRO',
},
{
name: 'Sketch B&W',
value: 'SKETCH_BW',
},
{
name: 'Sketch Color',
value: 'SKETCH_COLOR',
},
{
name: 'Stock Photo',
value: 'STOCK_PHOTO',
},
{
name: 'Unprocessed',
value: 'UNPROCESSED',
},
{
name: 'Fantasy Art',
value: 'FANTASY_ART',
},
{
name: 'Line Art',
value: 'LINE_ART',
},
{
name: 'Analog Film',
value: 'ANALOG_FILM',
},
{
name: 'Oil Painting',
value: 'OIL_PAINTING',
},
],
description: 'NOT CURRENTLY SUPPORTED BY API. Style preset to apply to the generated images.',
displayOptions: {
show: {
operation: ['createLeonardoImage'],
advancedOptions: [true],
},
},
},
{
displayName: 'ControlNets',
name: 'controlnets',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
sortable: true,