This commit is contained in:
Kent Keirsey
2025-07-08 13:02:23 -04:00
committed by psychedelicious
parent d29f65ed22
commit ed9c090f33

View File

@@ -14,7 +14,8 @@ import {
import { selectAllEntities,selectBboxModelBase } from 'features/controlLayers/store/selectors';
import type {
CanvasEntityState,
RefImageState
RefImageState,
CanvasRegionalGuidanceState
} from 'features/controlLayers/store/types';
import {
getEntityIdentifier,
@@ -28,7 +29,11 @@ import {
selectIPAdapterModels
} from 'services/api/hooks/modelsByType';
import type {
AnyModelConfig
AnyModelConfig,
IPAdapterModelConfig,
FLUXReduxModelConfig,
ChatGPT4oModelConfig,
FLUXKontextModelConfig
} from 'services/api/types';
import {
isChatGPT4oModelConfig,
@@ -52,6 +57,11 @@ const selectGlobalReferenceImageModels = (state: RootState): AnyModelConfig[] =>
);
};
// Type guard to check if entity is a regional guidance entity
const isRegionalGuidanceEntity = (entity: CanvasEntityState): entity is CanvasRegionalGuidanceState => {
return entity.type === 'regional_guidance';
};
export const addModelSelectedListener = (startAppListening: AppStartListening) => {
startAppListening({
actionCreator: modelSelected,
@@ -100,7 +110,24 @@ export const addModelSelectedListener = (startAppListening: AppStartListening) =
// Handle incompatible reference image models - switch to first compatible model
const availableRefImageModels = selectGlobalReferenceImageModels(state).filter((model: AnyModelConfig) => model.base === newBaseModel);
const firstCompatibleModel = availableRefImageModels[0] || null;
// Filter to only include models that are compatible with the actions
const compatibleIPAdapterModels = availableRefImageModels.filter(isIPAdapterModelConfig);
const compatibleFLUXReduxModels = availableRefImageModels.filter(isFluxReduxModelConfig);
const compatibleChatGPT4oModels = availableRefImageModels.filter(isChatGPT4oModelConfig);
const compatibleFLUXKontextModels = availableRefImageModels.filter(isFluxKontextModelConfig);
// For global reference images, we can use any of the compatible model types
const firstCompatibleGlobalModel = compatibleIPAdapterModels[0] ||
compatibleFLUXReduxModels[0] ||
compatibleChatGPT4oModels[0] ||
compatibleFLUXKontextModels[0] ||
null;
// For regional guidance, we can only use IP adapter or FLUX redux models
const firstCompatibleRegionalModel = compatibleIPAdapterModels[0] ||
compatibleFLUXReduxModels[0] ||
null;
// Handle global reference images
const refImageEntities = selectReferenceImageEntities(state);
@@ -108,11 +135,11 @@ export const addModelSelectedListener = (startAppListening: AppStartListening) =
if (entity.config.model && entity.config.model.base !== newBaseModel) {
dispatch(refImageModelChanged({
id: entity.id,
modelConfig: firstCompatibleModel
modelConfig: firstCompatibleGlobalModel as IPAdapterModelConfig | FLUXReduxModelConfig | ChatGPT4oModelConfig | FLUXKontextModelConfig | null
}));
if (firstCompatibleModel) {
if (firstCompatibleGlobalModel) {
log.debug(
{ oldModel: entity.config.model, newModel: firstCompatibleModel },
{ oldModel: entity.config.model, newModel: firstCompatibleGlobalModel },
'Switched global reference image model to compatible model'
);
} else {
@@ -128,17 +155,17 @@ export const addModelSelectedListener = (startAppListening: AppStartListening) =
// Handle regional guidance reference images
const canvasEntities = selectAllEntities(state.canvas.present);
canvasEntities.forEach((entity: CanvasEntityState) => {
if (isRegionalGuidanceEntityIdentifier(getEntityIdentifier(entity))) {
entity.referenceImages.forEach((refImage: any) => {
if (isRegionalGuidanceEntityIdentifier(getEntityIdentifier(entity)) && isRegionalGuidanceEntity(entity)) {
entity.referenceImages.forEach((refImage) => {
if (refImage.config.model && refImage.config.model.base !== newBaseModel) {
dispatch(rgRefImageModelChanged({
entityIdentifier: getEntityIdentifier(entity),
entityIdentifier: getEntityIdentifier(entity) as any, // Type assertion since we've already checked it's regional guidance
referenceImageId: refImage.id,
modelConfig: firstCompatibleModel
modelConfig: firstCompatibleRegionalModel
}));
if (firstCompatibleModel) {
if (firstCompatibleRegionalModel) {
log.debug(
{ oldModel: refImage.config.model, newModel: firstCompatibleModel },
{ oldModel: refImage.config.model, newModel: firstCompatibleRegionalModel },
'Switched regional guidance reference image model to compatible model'
);
} else {