mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import type { RootState } from 'app/store/store';
|
|
import type { BoardField } from 'features/nodes/types/common';
|
|
import { buildPresetModifiedPrompt } from 'features/stylePresets/hooks/usePresetModifiedPrompts';
|
|
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
|
import { stylePresetsApi } from 'services/api/endpoints/stylePresets';
|
|
|
|
/**
|
|
* Gets the board field, based on the autoAddBoardId setting.
|
|
*/
|
|
export const getBoardField = (state: RootState): BoardField | undefined => {
|
|
const { autoAddBoardId } = state.gallery;
|
|
if (autoAddBoardId === 'none') {
|
|
return undefined;
|
|
}
|
|
return { board_id: autoAddBoardId };
|
|
};
|
|
|
|
/**
|
|
* Gets the prompts, modified for the active style preset.
|
|
*/
|
|
export const getPresetModifiedPrompts = (
|
|
state: RootState
|
|
): { positivePrompt: string; negativePrompt: string; positiveStylePrompt?: string; negativeStylePrompt?: string } => {
|
|
const { positivePrompt, negativePrompt, positivePrompt2, negativePrompt2, shouldConcatPrompts } =
|
|
state.controlLayers.present;
|
|
const { activeStylePresetId } = state.stylePreset;
|
|
|
|
if (activeStylePresetId) {
|
|
const { data } = stylePresetsApi.endpoints.listStylePresets.select()(state);
|
|
|
|
const activeStylePreset = data?.find((item) => item.id === activeStylePresetId);
|
|
|
|
if (activeStylePreset) {
|
|
const presetModifiedPositivePrompt = buildPresetModifiedPrompt(
|
|
activeStylePreset.preset_data.positive_prompt,
|
|
positivePrompt
|
|
);
|
|
|
|
const presetModifiedNegativePrompt = buildPresetModifiedPrompt(
|
|
activeStylePreset.preset_data.negative_prompt,
|
|
negativePrompt
|
|
);
|
|
|
|
return {
|
|
positivePrompt: presetModifiedPositivePrompt,
|
|
negativePrompt: presetModifiedNegativePrompt,
|
|
positiveStylePrompt: shouldConcatPrompts ? presetModifiedPositivePrompt : positivePrompt2,
|
|
negativeStylePrompt: shouldConcatPrompts ? presetModifiedNegativePrompt : negativePrompt2,
|
|
};
|
|
}
|
|
}
|
|
|
|
return {
|
|
positivePrompt,
|
|
negativePrompt,
|
|
positiveStylePrompt: shouldConcatPrompts ? positivePrompt : positivePrompt2,
|
|
negativeStylePrompt: shouldConcatPrompts ? negativePrompt : negativePrompt2,
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Gets the is_intermediate field, based on the active tab and shouldAutoSave setting.
|
|
*/
|
|
export const getIsIntermediate = (state: RootState) => {
|
|
const activeTabName = activeTabNameSelector(state);
|
|
if (activeTabName === 'canvas') {
|
|
return !state.canvas.shouldAutoSave;
|
|
}
|
|
return false;
|
|
};
|