Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(canvas): keep SAM results out of gallery

joshistoast2fd03e224e76
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts
index eb7c545fde..47b515cb08 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts
@@ -15,6 +15,7 @@ import {
getSamActionHandlers,
getSamErrorTranslationKey,
getSamStatusTranslationKey,
+ keepSamImageIntermediate,
SamPromptBody,
SamModeToggle,
SamOptionsBar,
@@ -413,6 +414,10 @@ describe('single-row SAM inputs', () => {
});
describe('getSamActionHandlers', () => {
+ it('keeps adopted SAM images intermediate', async () => {
+ await expect(keepSamImageIntermediate('sam-selection.png')).resolves.toBeUndefined();
+ });
+
it('wires every bar action and save target to the engine', () => {
const engine = {
applySelectObjectSession: vi.fn(),
@@ -426,22 +431,28 @@ describe('getSamActionHandlers', () => {
actions.process();
actions.reset();
actions.apply();
+ actions.save('raster');
actions.save('control');
+ actions.save('inpaint_mask');
+ actions.save('regional_guidance');
actions.save('selection');
actions.cancel();
expect(engine.processSelectObjectSession).toHaveBeenCalledOnce();
expect(engine.resetSelectObjectSession).toHaveBeenCalledOnce();
expect(engine.applySelectObjectSession).toHaveBeenCalledOnce();
- expect(engine.applySelectObjectSession).toHaveBeenCalledWith(expect.any(Function));
+ expect(engine.applySelectObjectSession).toHaveBeenCalledWith(keepSamImageIntermediate);
expect(engine.processSelectObjectSession.mock.invocationCallOrder[0]).toBeLessThan(
engine.resetSelectObjectSession.mock.invocationCallOrder[0] as number
);
expect(engine.resetSelectObjectSession.mock.invocationCallOrder[0]).toBeLessThan(
engine.applySelectObjectSession.mock.invocationCallOrder[0] as number
);
- expect(engine.saveSelectObjectSession).toHaveBeenCalledWith('control', expect.any(Function));
- expect(engine.saveSelectObjectSession).toHaveBeenCalledWith('selection', expect.any(Function));
+ expect(engine.saveSelectObjectSession).toHaveBeenCalledWith('raster', keepSamImageIntermediate);
+ expect(engine.saveSelectObjectSession).toHaveBeenCalledWith('control', keepSamImageIntermediate);
+ expect(engine.saveSelectObjectSession).toHaveBeenCalledWith('inpaint_mask', keepSamImageIntermediate);
+ expect(engine.saveSelectObjectSession).toHaveBeenCalledWith('regional_guidance', keepSamImageIntermediate);
+ expect(engine.saveSelectObjectSession).toHaveBeenCalledWith('selection', keepSamImageIntermediate);
expect(engine.cancelSelectObjectSession).toHaveBeenCalledOnce();
});
});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx
index 77193c3575..1fd4e80905 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx
@@ -21,7 +21,6 @@ import {
VisuallyHidden,
} from '@chakra-ui/react';
import { Button, MenuContent, Tooltip } from '@workbench/components/ui';
-import { makeImageDurable } from '@workbench/gallery/api';
import { isSamDocumentInputValid } from '@workbench/generation/canvas/samGraph';
import { CanvasFloatingBar, CanvasFloatingBarDivider } from '@workbench/widgets/canvas/CanvasFloatingBar';
import { useSamSession } from '@workbench/widgets/canvas/engineStoreHooks';
@@ -168,12 +167,15 @@ export const SamStatusSlot = ({
);
};
+/** Legacy parity: canvas adoption keeps the SAM result intermediate and out of the gallery. */
+export const keepSamImageIntermediate = (_imageName: string): Promise<void> => Promise.resolve();
+
export const getSamActionHandlers = (engine: ToolOptionsComponentProps['engine']) => ({
- apply: () => void engine.applySelectObjectSession(makeImageDurable),
+ apply: () => void engine.applySelectObjectSession(keepSamImageIntermediate),
cancel: () => engine.cancelSelectObjectSession(),
process: () => void engine.processSelectObjectSession(),
reset: () => engine.resetSelectObjectSession(),
- save: (target: SelectObjectSaveTarget) => void engine.saveSelectObjectSession(target, makeImageDurable),
+ save: (target: SelectObjectSaveTarget) => void engine.saveSelectObjectSession(target, keepSamImageIntermediate),
});
export const getSamActionEligibility = (