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.

feat(webv2): bring System Prompts to the Expand Prompt popover

joshistoast2c00aeb08152
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index 23d502c345..b8243a6e28 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -1,6 +1,6 @@
{
"browserExecutable": "/home/toast/.cache/ms-playwright/chromium-1228/chrome-linux64/chrome",
- "capturedAt": "2026-07-30",
+ "capturedAt": "2026-07-31",
"routes": [
{
"activatedResourceBaseline": {
@@ -25,11 +25,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 109.19999999925494,
+ "domContentLoadedMedianMs": 111.3999999994412,
"id": "launchpad",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 109.30000000074506,
- "longestTaskMaxMs": 67,
+ "loadMedianMs": 111.5,
+ "longestTaskMaxMs": 68,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -39,24 +39,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 0,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 19,
"scriptRawBytes": 1456006,
"scriptRequestCount": 15,
- "totalRawBytes": 1584653
+ "totalRawBytes": 1585335
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 0,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 19,
"scriptRawBytes": 1470567,
"scriptRequestCount": 15,
- "totalRawBytes": 1600500
+ "totalRawBytes": 1601189
},
- "routeReadyMedianMs": 225.69999999925494,
+ "routeReadyMedianMs": 227.5,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "empty"
},
@@ -83,10 +83,10 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 110.20000000298023,
+ "domContentLoadedMedianMs": 109.90000000037253,
"id": "launchpad",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 110.30000000074506,
+ "loadMedianMs": 109.90000000037253,
"longestTaskMaxMs": 69,
"owner": "app",
"projectSwitchMedianMs": 0,
@@ -97,24 +97,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 0,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 19,
"scriptRawBytes": 1456006,
"scriptRequestCount": 15,
- "totalRawBytes": 1584653
+ "totalRawBytes": 1585335
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 0,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 19,
"scriptRawBytes": 1470567,
"scriptRequestCount": 15,
- "totalRawBytes": 1600500
+ "totalRawBytes": 1601189
},
- "routeReadyMedianMs": 281.80000000074506,
+ "routeReadyMedianMs": 281.69999999925494,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "representative"
},
@@ -141,13 +141,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 105.79999999701977,
+ "domContentLoadedMedianMs": 112,
"id": "editor-minimal",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 105.89999999850988,
+ "loadMedianMs": 112,
"longestTaskMaxMs": 113,
"owner": "workbench",
- "projectSwitchMedianMs": 61.23483999999917,
+ "projectSwitchMedianMs": 70.06946200000039,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -155,24 +155,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 94,
- "scriptRawBytes": 3081128,
+ "scriptRawBytes": 3088075,
"scriptRequestCount": 88,
- "totalRawBytes": 3381564
+ "totalRawBytes": 3389193
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 94,
- "scriptRawBytes": 3111940,
+ "scriptRawBytes": 3118956,
"scriptRequestCount": 88,
- "totalRawBytes": 3415380
+ "totalRawBytes": 3423085
},
- "routeReadyMedianMs": 600.5999999977648,
+ "routeReadyMedianMs": 614.7000000001863,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -199,13 +199,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 104.40000000223517,
+ "domContentLoadedMedianMs": 112.59999999962747,
"id": "editor-minimal",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 104.5,
- "longestTaskMaxMs": 118,
+ "loadMedianMs": 112.70000000018626,
+ "longestTaskMaxMs": 123,
"owner": "workbench",
- "projectSwitchMedianMs": 88.15142399999968,
+ "projectSwitchMedianMs": 86.34619100000054,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -213,24 +213,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 94,
- "scriptRawBytes": 3081128,
+ "scriptRawBytes": 3088075,
"scriptRequestCount": 88,
- "totalRawBytes": 3381564
+ "totalRawBytes": 3389193
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 94,
- "scriptRawBytes": 3111940,
+ "scriptRawBytes": 3118956,
"scriptRequestCount": 88,
- "totalRawBytes": 3415380
+ "totalRawBytes": 3423085
},
- "routeReadyMedianMs": 642.2000000029802,
+ "routeReadyMedianMs": 664.9000000003725,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -257,11 +257,11 @@
"scriptRequestCount": 7,
"totalRawBytes": 296005
},
- "domContentLoadedMedianMs": 105.5,
+ "domContentLoadedMedianMs": 112.29999999981374,
"id": "editor-canvas",
- "layoutSwitchMedianMs": 77.89999999850988,
- "loadMedianMs": 105.5,
- "longestTaskMaxMs": 105,
+ "layoutSwitchMedianMs": 79.09999999962747,
+ "loadMedianMs": 112.29999999981374,
+ "longestTaskMaxMs": 113,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -271,24 +271,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 98,
- "scriptRawBytes": 3359645,
+ "scriptRawBytes": 3366592,
"scriptRequestCount": 92,
- "totalRawBytes": 3660081
+ "totalRawBytes": 3667710
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 98,
- "scriptRawBytes": 3393242,
+ "scriptRawBytes": 3400258,
"scriptRequestCount": 92,
- "totalRawBytes": 3696682
+ "totalRawBytes": 3704388
},
- "routeReadyMedianMs": 771.3000000007451,
+ "routeReadyMedianMs": 760.7999999998137,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "empty"
},
@@ -315,11 +315,11 @@
"scriptRequestCount": 7,
"totalRawBytes": 296005
},
- "domContentLoadedMedianMs": 105.69999999925494,
+ "domContentLoadedMedianMs": 110.5,
"id": "editor-canvas",
- "layoutSwitchMedianMs": 323.80000000074506,
- "loadMedianMs": 105.69999999925494,
- "longestTaskMaxMs": 378,
+ "layoutSwitchMedianMs": 328.70000000018626,
+ "loadMedianMs": 110.6000000005588,
+ "longestTaskMaxMs": 384,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -329,24 +329,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 98,
- "scriptRawBytes": 3359645,
+ "scriptRawBytes": 3366592,
"scriptRequestCount": 92,
- "totalRawBytes": 3660081
+ "totalRawBytes": 3667710
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 98,
- "scriptRawBytes": 3393242,
+ "scriptRawBytes": 3400258,
"scriptRequestCount": 92,
- "totalRawBytes": 3696682
+ "totalRawBytes": 3704388
},
- "routeReadyMedianMs": 1090,
+ "routeReadyMedianMs": 1169.6000000005588,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "representative"
},
@@ -373,11 +373,11 @@
"scriptRequestCount": 3,
"totalRawBytes": 14703
},
- "domContentLoadedMedianMs": 105.79999999701977,
+ "domContentLoadedMedianMs": 107.40000000037253,
"id": "editor-workflow",
- "layoutSwitchMedianMs": 65.70000000298023,
- "loadMedianMs": 105.89999999850988,
- "longestTaskMaxMs": 110,
+ "layoutSwitchMedianMs": 71.79999999981374,
+ "loadMedianMs": 107.40000000037253,
+ "longestTaskMaxMs": 109,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -387,24 +387,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 94,
- "scriptRawBytes": 3081128,
+ "scriptRawBytes": 3088075,
"scriptRequestCount": 88,
- "totalRawBytes": 3381564
+ "totalRawBytes": 3389193
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 94,
- "scriptRawBytes": 3111940,
+ "scriptRawBytes": 3118956,
"scriptRequestCount": 88,
- "totalRawBytes": 3415380
+ "totalRawBytes": 3423085
},
- "routeReadyMedianMs": 725.8999999985099,
+ "routeReadyMedianMs": 754.8000000007451,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -431,11 +431,11 @@
"scriptRequestCount": 3,
"totalRawBytes": 14703
},
- "domContentLoadedMedianMs": 105.89999999850988,
+ "domContentLoadedMedianMs": 110.70000000018626,
"id": "editor-workflow",
- "layoutSwitchMedianMs": 119,
- "loadMedianMs": 106,
- "longestTaskMaxMs": 358,
+ "layoutSwitchMedianMs": 127.09999999962747,
+ "loadMedianMs": 110.70000000018626,
+ "longestTaskMaxMs": 412,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -445,24 +445,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 94,
- "scriptRawBytes": 3081128,
+ "scriptRawBytes": 3088075,
"scriptRequestCount": 88,
- "totalRawBytes": 3381564
+ "totalRawBytes": 3389193
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 94,
- "scriptRawBytes": 3111940,
+ "scriptRawBytes": 3118956,
"scriptRequestCount": 88,
- "totalRawBytes": 3415380
+ "totalRawBytes": 3423085
},
- "routeReadyMedianMs": 917.3000000007451,
+ "routeReadyMedianMs": 956.2999999998137,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -489,11 +489,11 @@
"scriptRequestCount": 3,
"totalRawBytes": 14703
},
- "domContentLoadedMedianMs": 104.40000000223517,
+ "domContentLoadedMedianMs": 110.20000000018626,
"id": "editor-gallery",
- "layoutSwitchMedianMs": 25.199999999254942,
- "loadMedianMs": 104.40000000223517,
- "longestTaskMaxMs": 104,
+ "layoutSwitchMedianMs": 28.600000000558794,
+ "loadMedianMs": 110.20000000018626,
+ "longestTaskMaxMs": 115,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -503,24 +503,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 94,
- "scriptRawBytes": 3081128,
+ "scriptRawBytes": 3088075,
"scriptRequestCount": 88,
- "totalRawBytes": 3381564
+ "totalRawBytes": 3389193
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 94,
- "scriptRawBytes": 3111940,
+ "scriptRawBytes": 3118956,
"scriptRequestCount": 88,
- "totalRawBytes": 3415380
+ "totalRawBytes": 3423085
},
- "routeReadyMedianMs": 702.6000000014901,
+ "routeReadyMedianMs": 738.4000000003725,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -547,11 +547,11 @@
"scriptRequestCount": 3,
"totalRawBytes": 14703
},
- "domContentLoadedMedianMs": 105.39999999850988,
+ "domContentLoadedMedianMs": 109.90000000037253,
"id": "editor-gallery",
- "layoutSwitchMedianMs": 36.900000002235174,
- "loadMedianMs": 105.39999999850988,
- "longestTaskMaxMs": 111,
+ "layoutSwitchMedianMs": 39.30000000074506,
+ "loadMedianMs": 109.90000000037253,
+ "longestTaskMaxMs": 121,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -561,24 +561,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737757,
- "otherRawBytes": 102824,
+ "otherRawBytes": 103506,
"requestCount": 94,
- "scriptRawBytes": 3081128,
+ "scriptRawBytes": 3088075,
"scriptRequestCount": 88,
- "totalRawBytes": 3381564
+ "totalRawBytes": 3389193
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745135,
- "otherRawBytes": 103853,
+ "otherRawBytes": 104542,
"requestCount": 94,
- "scriptRawBytes": 3111940,
+ "scriptRawBytes": 3118956,
"scriptRequestCount": 88,
- "totalRawBytes": 3415380
+ "totalRawBytes": 3423085
},
- "routeReadyMedianMs": 815.1999999992549,
+ "routeReadyMedianMs": 866.2000000001863,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
}
@@ -1012,12 +1012,14 @@
"source:src/features/generation/core/referenceImage.ts",
"source:src/features/generation/core/resolveGenerateWidgetValues.ts",
"source:src/features/generation/core/settings.ts",
+ "source:src/features/generation/core/systemPrompts.ts",
"source:src/features/generation/core/wildcardCatalog.ts",
"source:src/features/generation/core/wildcardTransfer.ts",
"source:src/features/generation/data/dynamicPromptsQueries.ts",
"source:src/features/generation/data/promptTemplates.ts",
"source:src/features/generation/data/promptUtilities.ts",
"source:src/features/generation/data/referenceImageUrls.ts",
+ "source:src/features/generation/data/systemPrompts.ts",
"source:src/features/generation/data/wildcards.ts",
"source:src/features/generation/graph.ts",
"source:src/features/generation/prompts.ts",
@@ -1055,6 +1057,7 @@
"source:src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx",
"source:src/features/generation/ui/promptFields/PromptTextarea.tsx",
"source:src/features/generation/ui/promptFields/PromptTriggerAutocomplete.tsx",
+ "source:src/features/generation/ui/promptFields/SystemPromptsField.tsx",
"source:src/features/generation/ui/promptFields/WildcardImportDialog.tsx",
"source:src/features/generation/ui/promptFields/WildcardTransferActions.tsx",
"source:src/features/generation/ui/promptFields/WildcardsPanel.tsx",
@@ -1067,6 +1070,7 @@
"source:src/features/generation/ui/promptFields/useDismissOnViewportChange.ts",
"source:src/features/generation/ui/promptFields/usePromptTriggerAutocomplete.tsx",
"source:src/features/generation/ui/promptFields/usePromptTriggerPicker.ts",
+ "source:src/features/generation/ui/promptFields/useSystemPrompts.ts",
"source:src/features/generation/ui/promptTemplateDraftStore.ts",
"source:src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx",
"source:src/features/generation/ui/reference-images/ReferenceImageCard.tsx",
@@ -1835,12 +1839,14 @@
"source:src/features/generation/core/referenceImage.ts",
"source:src/features/generation/core/resolveGenerateWidgetValues.ts",
"source:src/features/generation/core/settings.ts",
+ "source:src/features/generation/core/systemPrompts.ts",
"source:src/features/generation/core/wildcardCatalog.ts",
"source:src/features/generation/core/wildcardTransfer.ts",
"source:src/features/generation/data/dynamicPromptsQueries.ts",
"source:src/features/generation/data/promptTemplates.ts",
"source:src/features/generation/data/promptUtilities.ts",
"source:src/features/generation/data/referenceImageUrls.ts",
+ "source:src/features/generation/data/systemPrompts.ts",
"source:src/features/generation/data/wildcards.ts",
"source:src/features/generation/graph.ts",
"source:src/features/generation/prompts.ts",
@@ -1878,6 +1884,7 @@
"source:src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx",
"source:src/features/generation/ui/promptFields/PromptTextarea.tsx",
"source:src/features/generation/ui/promptFields/PromptTriggerAutocomplete.tsx",
+ "source:src/features/generation/ui/promptFields/SystemPromptsField.tsx",
"source:src/features/generation/ui/promptFields/WildcardImportDialog.tsx",
"source:src/features/generation/ui/promptFields/WildcardTransferActions.tsx",
"source:src/features/generation/ui/promptFields/WildcardsPanel.tsx",
@@ -1890,6 +1897,7 @@
"source:src/features/generation/ui/promptFields/useDismissOnViewportChange.ts",
"source:src/features/generation/ui/promptFields/usePromptTriggerAutocomplete.tsx",
"source:src/features/generation/ui/promptFields/usePromptTriggerPicker.ts",
+ "source:src/features/generation/ui/promptFields/useSystemPrompts.ts",
"source:src/features/generation/ui/promptTemplateDraftStore.ts",
"source:src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx",
"source:src/features/generation/ui/reference-images/ReferenceImageCard.tsx",
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index ff94c34120..5cd3bf5cff 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -980,6 +980,22 @@
"promptHistory": "Prompt history",
"promptHistoryEntries": "Prompt history entries",
"promptHistoryKeyboardHelp": "Alt+Up/Down switches between prompts while focused.",
+ "systemPrompts": {
+ "title": "System prompt",
+ "manage": "Manage system prompts",
+ "new": "New",
+ "edit": "Edit system prompt",
+ "name": "Name",
+ "namePlaceholder": "Concise and literal",
+ "content": "Instructions",
+ "contentPlaceholder": "Describe how the model should rewrite the prompt.",
+ "none": "No system prompts",
+ "shared": "Shared",
+ "deleteTitle": "Delete system prompt",
+ "deleteBody": "“{{name}}” will be deleted. This cannot be undone.",
+ "couldNotSave": "Could not save this system prompt.",
+ "couldNotDelete": "Could not delete this system prompt."
+ },
"promptTemplates": {
"title": "Prompt templates",
"newTemplate": "New template",
diff --git a/invokeai/frontend/webv2/src/features/generation/core/systemPrompts.test.ts b/invokeai/frontend/webv2/src/features/generation/core/systemPrompts.test.ts
new file mode 100644
index 0000000000..304c9f4f68
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/core/systemPrompts.test.ts
@@ -0,0 +1,87 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ classifySystemPrompts,
+ isOwnedSystemPrompt,
+ requireOwnedSystemPrompt,
+ resolveSelectedSystemPromptId,
+ SystemPromptOwnershipError,
+} from './systemPrompts';
+
+const record = (id: string, userId: string, isPublic: boolean) => ({ id, isPublic, userId });
+
+const MULTIUSER = { currentUserId: 'me', multiuserEnabled: true };
+const SINGLE_USER = { currentUserId: 'system', multiuserEnabled: false };
+
+describe('classifySystemPrompts', () => {
+ it('splits the account owner’s prompts from prompts shared by others', () => {
+ const mine = record('a', 'me', false);
+ const sharedByOther = record('b', 'someone', true);
+ const privateOfOther = record('c', 'someone', false);
+
+ const classified = classifySystemPrompts([mine, sharedByOther, privateOfOther], MULTIUSER);
+
+ expect(classified.personalPrompts).toEqual([mine]);
+ expect(classified.sharedPrompts).toEqual([sharedByOther]);
+ // Another user's private prompt is not visible at all.
+ expect(classified.prompts).toEqual([mine, sharedByOther]);
+ });
+
+ it('treats everything as personal in single-user mode', () => {
+ // The backend seeds built-ins under the user id `system`, which is also the synthetic id
+ // every single-user request carries — so ownership must not be decided by comparing to it.
+ const seeded = record('a', 'system', true);
+ const created = record('b', 'system', false);
+
+ const classified = classifySystemPrompts([seeded, created], SINGLE_USER);
+
+ expect(classified.personalPrompts).toEqual([seeded, created]);
+ expect(classified.sharedPrompts).toEqual([]);
+ });
+
+ it('orders personal prompts ahead of shared ones', () => {
+ const sharedByOther = record('b', 'someone', true);
+ const mine = record('a', 'me', false);
+
+ expect(classifySystemPrompts([sharedByOther, mine], MULTIUSER).prompts).toEqual([mine, sharedByOther]);
+ });
+});
+
+describe('isOwnedSystemPrompt / requireOwnedSystemPrompt', () => {
+ it('allows the owner and refuses another user’s shared prompt', () => {
+ expect(isOwnedSystemPrompt(record('a', 'me', false), MULTIUSER)).toBe(true);
+ expect(isOwnedSystemPrompt(record('b', 'someone', true), MULTIUSER)).toBe(false);
+
+ expect(() => requireOwnedSystemPrompt(record('b', 'someone', true), MULTIUSER)).toThrow(SystemPromptOwnershipError);
+ expect(() => requireOwnedSystemPrompt(record('a', 'me', false), MULTIUSER)).not.toThrow();
+ });
+
+ it('treats an anonymous multiuser session as owning nothing', () => {
+ const account = { currentUserId: null, multiuserEnabled: true };
+
+ expect(isOwnedSystemPrompt(record('a', 'system', true), account)).toBe(false);
+ });
+});
+
+describe('resolveSelectedSystemPromptId', () => {
+ const prompts = [record('a', 'me', false), record('b', 'me', false)];
+
+ it('keeps a selection that still exists', () => {
+ expect(resolveSelectedSystemPromptId(prompts, 'b')).toBe('b');
+ });
+
+ it('falls back to the first prompt when nothing is selected yet', () => {
+ expect(resolveSelectedSystemPromptId(prompts, null)).toBe('a');
+ });
+
+ it('falls back when the stored id no longer exists', () => {
+ // Deleted in another tab, or a shared prompt whose owner unshared it. Resolving on read
+ // means no corrective write is needed to recover.
+ expect(resolveSelectedSystemPromptId(prompts, 'deleted')).toBe('a');
+ });
+
+ it('returns null when there is nothing to select', () => {
+ expect(resolveSelectedSystemPromptId([], 'anything')).toBeNull();
+ expect(resolveSelectedSystemPromptId([], null)).toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/generation/core/systemPrompts.ts b/invokeai/frontend/webv2/src/features/generation/core/systemPrompts.ts
new file mode 100644
index 0000000000..44147a34fd
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/core/systemPrompts.ts
@@ -0,0 +1,81 @@
+/**
+ * System prompts steer the Expand Prompt LLM. They are user-owned named records that may be
+ * shared with everyone on the install.
+ *
+ * Ownership mirrors prompt templates, with one deliberate difference: there is no "default"
+ * flag. The backend seeds its built-ins under the user id `system`, but that same id is what
+ * *every* request carries in single-user mode, so an install that later switched to multiuser
+ * has ordinary user-created prompts owned by `system` too. Visibility and editability are
+ * therefore decided by `is_public` and ownership alone — never by comparing against `system`.
+ */
+
+export interface SystemPromptAccount {
+ currentUserId: string | null;
+ multiuserEnabled: boolean;
+}
+
+interface SystemPromptOwnershipRecord {
+ isPublic: boolean;
+ userId: string;
+}
+
+export interface ClassifiedSystemPrompts<T> {
+ personalPrompts: T[];
+ sharedPrompts: T[];
+ /** The records visible to this account, personal first. */
+ prompts: T[];
+}
+
+export const classifySystemPrompts = <T extends SystemPromptOwnershipRecord>(
+ records: readonly T[],
+ account: SystemPromptAccount
+): ClassifiedSystemPrompts<T> => {
+ const personalPrompts: T[] = [];
+ const sharedPrompts: T[] = [];
+
+ for (const record of records) {
+ if (!account.multiuserEnabled || record.userId === account.currentUserId) {
+ personalPrompts.push(record);
+ } else if (record.isPublic) {
+ sharedPrompts.push(record);
+ }
+ }
+
+ return { personalPrompts, prompts: [...personalPrompts, ...sharedPrompts], sharedPrompts };
+};
+
+export const isOwnedSystemPrompt = (record: SystemPromptOwnershipRecord, account: SystemPromptAccount): boolean =>
+ !account.multiuserEnabled || (account.currentUserId !== null && record.userId === account.currentUserId);
+
+export class SystemPromptOwnershipError extends Error {
+ constructor() {
+ super('Only personal system prompts can be changed.');
+ this.name = 'SystemPromptOwnershipError';
+ }
+}
+
+export const requireOwnedSystemPrompt = (record: SystemPromptOwnershipRecord, account: SystemPromptAccount): void => {
+ if (!isOwnedSystemPrompt(record, account)) {
+ throw new SystemPromptOwnershipError();
+ }
+};
+
+/**
+ * The selection that should actually be in effect.
+ *
+ * The stored id outlives the record it points at — another tab can delete it, and a shared
+ * prompt stops being visible when its owner unshares it. Rather than persist a corrective
+ * write, the selection is resolved on read: a stale id falls back to the first visible prompt,
+ * which is also what an install with no selection yet gets. Returns null only when there is
+ * nothing to select.
+ */
+export const resolveSelectedSystemPromptId = (
+ prompts: readonly { id: string }[],
+ selectedId: string | null
+): string | null => {
+ if (selectedId !== null && prompts.some((prompt) => prompt.id === selectedId)) {
+ return selectedId;
+ }
+
+ return prompts[0]?.id ?? null;
+};
diff --git a/invokeai/frontend/webv2/src/features/generation/data/systemPrompts.ts b/invokeai/frontend/webv2/src/features/generation/data/systemPrompts.ts
new file mode 100644
index 0000000000..1430a21739
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/data/systemPrompts.ts
@@ -0,0 +1,83 @@
+import type { QueryClient } from '@tanstack/react-query';
+
+import { assertAccountScopeCurrent, captureAccountScope } from '@platform/state/accountLifecycle';
+import { apiFetch, apiFetchJson } from '@platform/transport/http';
+import { queryOptions } from '@tanstack/react-query';
+
+const SYSTEM_PROMPTS_BASE = '/api/v1/system_prompts';
+
+interface SystemPromptDTO {
+ id: string;
+ name: string;
+ content: string;
+ user_id: string;
+ is_public: boolean;
+}
+
+export interface SystemPromptRecord {
+ id: string;
+ name: string;
+ content: string;
+ userId: string;
+ isPublic: boolean;
+}
+
+export interface SystemPromptDraft {
+ name: string;
+ content: string;
+}
+
+export const systemPromptKeys = {
+ all: ['generation', 'systemPrompts'] as const,
+ list: () => [...systemPromptKeys.all, 'list'] as const,
+};
+
+const mapSystemPrompt = (dto: SystemPromptDTO): SystemPromptRecord => ({
+ content: dto.content,
+ id: dto.id,
+ isPublic: dto.is_public,
+ name: dto.name,
+ userId: dto.user_id,
+});
+
+export const systemPromptsQueryOptions = () =>
+ (() => {
+ const owner = captureAccountScope();
+
+ return queryOptions({
+ queryFn: async ({ signal }): Promise<SystemPromptRecord[]> => {
+ const prompts = await apiFetchJson<SystemPromptDTO[]>(`${SYSTEM_PROMPTS_BASE}/`, {
+ signal: AbortSignal.any([signal, owner.signal]),
+ });
+
+ assertAccountScopeCurrent(owner);
+ return prompts.map(mapSystemPrompt);
+ },
+ queryKey: systemPromptKeys.list(),
+ staleTime: 30_000,
+ });
+ })();
+
+export const createSystemPrompt = async (draft: SystemPromptDraft): Promise<SystemPromptRecord> =>
+ mapSystemPrompt(
+ await apiFetchJson<SystemPromptDTO>(`${SYSTEM_PROMPTS_BASE}/`, {
+ body: JSON.stringify({ content: draft.content, name: draft.name }),
+ method: 'POST',
+ })
+ );
+
+export const updateSystemPrompt = async (id: string, draft: SystemPromptDraft): Promise<SystemPromptRecord> =>
+ mapSystemPrompt(
+ await apiFetchJson<SystemPromptDTO>(`${SYSTEM_PROMPTS_BASE}/i/${encodeURIComponent(id)}`, {
+ body: JSON.stringify({ content: draft.content, name: draft.name }),
+ method: 'PATCH',
+ })
+ );
+
+export const deleteSystemPrompt = async (id: string): Promise<void> => {
+ await apiFetch(`${SYSTEM_PROMPTS_BASE}/i/${encodeURIComponent(id)}`, { method: 'DELETE' });
+};
+
+export const invalidateSystemPrompts = async (queryClient: QueryClient): Promise<void> => {
+ await queryClient.invalidateQueries({ exact: true, queryKey: systemPromptKeys.list() });
+};
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
index e85581d7ed..fbbc8addc2 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
@@ -7,6 +7,7 @@ import type { ChangeEvent, MouseEvent } from 'react';
import { HStack, Icon, Image, Input, Popover, Portal, Separator, Stack, Text } from '@chakra-ui/react';
import { filterPromptHistory } from '@features/generation/core/promptHistory';
+import { resolveSelectedSystemPromptId } from '@features/generation/core/systemPrompts';
import { expandPrompt, imageToPrompt } from '@features/generation/data/promptUtilities';
import { GenerationModelSelect as ModelSelect, useGenerationUi } from '@features/generation/ui/GenerationUiContext';
import { DynamicPromptsButton } from '@features/generation/ui/promptFields/DynamicPromptsButton';
@@ -19,6 +20,8 @@ import {
type PromptTriggerKind,
type PromptTriggerOption,
} from '@features/generation/ui/promptFields/promptTriggerOptions';
+import { SystemPromptsField } from '@features/generation/ui/promptFields/SystemPromptsField';
+import { useSystemPrompts } from '@features/generation/ui/promptFields/useSystemPrompts';
import { useMountEffect } from '@platform/react/useMountEffect';
import { getApiErrorMessage } from '@platform/transport/http';
import { Button, IconButton, Scrollable, Tooltip } from '@platform/ui';
@@ -355,8 +358,15 @@ const ExpandPromptButton = ({
const [isOpen, setIsOpen] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [selectedModelKey, setSelectedModelKey] = useState<string | null>(null);
+ const [selectedSystemPromptId, setSelectedSystemPromptId] = useState<string | null>(null);
const textLlmModels = models.filter((model) => model.type === 'text_llm');
const selectedModel = selectedModelKey ? textLlmModels.find((model) => model.key === selectedModelKey) : null;
+ // The list is behind the popover, so a closed button has nothing to fetch.
+ const systemPrompts = useSystemPrompts({ isEnabled: isOpen });
+ // Resolved rather than stored: the id outlives the record it points at, and an unselected
+ // picker should still expand with the first available prompt rather than none at all.
+ const effectiveSystemPromptId = resolveSelectedSystemPromptId(systemPrompts.prompts, selectedSystemPromptId);
+ const selectedSystemPrompt = systemPrompts.prompts.find((prompt) => prompt.id === effectiveSystemPromptId);
activeProjectIdRef.current = activeProjectId;
@@ -372,7 +382,11 @@ const ExpandPromptButton = ({
setIsLoading(true);
try {
- const result = await expandPrompt({ model_key: selectedModel.key, prompt: positivePrompt });
+ const result = await expandPrompt({
+ model_key: selectedModel.key,
+ prompt: positivePrompt,
+ system_prompt: selectedSystemPrompt?.content ?? null,
+ });
if (result.expanded_prompt && activeProjectIdRef.current === projectId) {
onPositivePromptChange(result.expanded_prompt);
@@ -389,7 +403,7 @@ const ExpandPromptButton = ({
} finally {
setIsLoading(false);
}
- }, [notifications, onPositivePromptChange, positivePrompt, projectId, selectedModel, t]);
+ }, [notifications, onPositivePromptChange, positivePrompt, projectId, selectedModel, selectedSystemPrompt, t]);
const popoverIds = useMemo(() => ({ trigger: triggerId }), [triggerId]);
const handleOpenChange = useCallback((event: { open: boolean }) => setIsOpen(event.open), []);
@@ -443,6 +457,11 @@ const ExpandPromptButton = ({
value={selectedModelKey}
onChange={handleModelChange}
/>
+ <SystemPromptsField
+ catalog={systemPrompts}
+ selectedId={effectiveSystemPromptId}
+ onSelect={setSelectedSystemPromptId}
+ />
<Button
disabled={!selectedModel || !positivePrompt.trim()}
loading={isLoading}
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/SystemPromptsField.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/SystemPromptsField.tsx
new file mode 100644
index 0000000000..9a59c8ae55
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/SystemPromptsField.tsx
@@ -0,0 +1,308 @@
+import type { SystemPromptRecord } from '@features/generation/data/systemPrompts';
+import type { SystemPromptCatalog } from '@features/generation/ui/promptFields/useSystemPrompts';
+import type { ChangeEvent } from 'react';
+
+import { createListCollection, HStack, Input, Stack, Text, Textarea } from '@chakra-ui/react';
+import { PANEL_HEADER_CONTROL_HEIGHT, PromptPanelHeader } from '@features/generation/ui/promptFields/PromptPanelHeader';
+// Imported by subpath rather than from the `@platform/ui` barrel, which is at its
+// direct-importer budget. See the note in GenerateModelFamilyFields.
+import { getApiErrorMessage } from '@platform/transport/http';
+import { Button, IconButton } from '@platform/ui/Button';
+import { ConfirmDialog } from '@platform/ui/ConfirmDialog';
+import { Field } from '@platform/ui/Field';
+import { Scrollable } from '@platform/ui/Scrollable';
+import { Select } from '@platform/ui/Select';
+import { Tooltip } from '@platform/ui/Tooltip';
+import { PencilIcon, PlusIcon, SettingsIcon, TrashIcon } from 'lucide-react';
+import { useCallback, useId, useMemo, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+interface SystemPromptsFieldProps {
+ catalog: SystemPromptCatalog;
+ selectedId: string | null;
+ onSelect: (id: string | null) => void;
+}
+
+/** `record: null` means the editor is composing a new prompt. */
+type EditorTarget = { record: SystemPromptRecord | null };
+
+interface Draft {
+ name: string;
+ content: string;
+}
+
+const EMPTY_DRAFT: Draft = { content: '', name: '' };
+
+const SystemPromptRow = ({
+ canEdit,
+ onDelete,
+ onEdit,
+ prompt,
+}: {
+ canEdit: boolean;
+ prompt: SystemPromptRecord;
+ onDelete: (prompt: SystemPromptRecord) => void;
+ onEdit: (prompt: SystemPromptRecord) => void;
+}) => {
+ const { t } = useTranslation();
+ const handleEdit = useCallback(() => onEdit(prompt), [onEdit, prompt]);
+ const handleDelete = useCallback(() => onDelete(prompt), [onDelete, prompt]);
+
+ return (
+ <HStack justify="space-between" px="1" py="0.5">
+ <Text fontSize="xs" truncate>
+ {prompt.name}
+ </Text>
+ {canEdit ? (
+ <HStack gap="0.5">
+ <Tooltip content={t('common.edit')}>
+ <IconButton aria-label={t('common.edit')} size="2xs" variant="ghost" onClick={handleEdit}>
+ <PencilIcon />
+ </IconButton>
+ </Tooltip>
+ <Tooltip content={t('common.delete')}>
+ <IconButton aria-label={t('common.delete')} size="2xs" variant="ghost" onClick={handleDelete}>
+ <TrashIcon />
+ </IconButton>
+ </Tooltip>
+ </HStack>
+ ) : (
+ // Shared by someone else. Says why it has no controls without adding colour.
+ <Text color="fg.subtle" fontSize="2xs">
+ {t('widgets.generate.systemPrompts.shared')}
+ </Text>
+ )}
+ </HStack>
+ );
+};
+
+/**
+ * The system-prompt control inside the Expand Prompt popover: a picker over the prompts this
+ * account can see, and — behind the manage toggle — the list that creates, edits and deletes
+ * them. Both live in one component because the popover shows exactly one of them at a time.
+ */
+export const SystemPromptsField = ({ catalog, onSelect, selectedId }: SystemPromptsFieldProps) => {
+ const { canEdit, prompts } = catalog;
+ const { t } = useTranslation();
+ const selectId = useId();
+ const nameFieldId = useId();
+ const [isManaging, setIsManaging] = useState(false);
+ const [editorTarget, setEditorTarget] = useState<EditorTarget | null>(null);
+ const [draft, setDraft] = useState<Draft>(EMPTY_DRAFT);
+ const [pendingDelete, setPendingDelete] = useState<SystemPromptRecord | null>(null);
+ const [isSaving, setIsSaving] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+
+ const collection = useMemo(
+ () => createListCollection({ items: prompts.map(({ id, name }) => ({ label: name, value: id })) }),
+ [prompts]
+ );
+
+ const toggleManaging = useCallback(() => {
+ setIsManaging((managing) => !managing);
+ // Reopening should land on the list, not resume a half-written prompt.
+ setEditorTarget(null);
+ }, []);
+
+ const startCreate = useCallback(() => {
+ setDraft(EMPTY_DRAFT);
+ setEditorTarget({ record: null });
+ }, []);
+
+ const startEdit = useCallback((record: SystemPromptRecord) => {
+ setDraft({ content: record.content, name: record.name });
+ setEditorTarget({ record });
+ }, []);
+
+ const closeEditor = useCallback(() => setEditorTarget(null), []);
+
+ const saveDraft = useCallback(async () => {
+ if (!editorTarget || !draft.name.trim() || !draft.content.trim()) {
+ return;
+ }
+
+ setIsSaving(true);
+ setError(null);
+
+ let saved: SystemPromptRecord;
+
+ try {
+ saved = editorTarget.record ? await catalog.update(editorTarget.record, draft) : await catalog.create(draft);
+ } catch (caught) {
+ // `ApiError.message` is the raw response body, so the backend's own explanation only
+ // reads properly once unwrapped. Reported in place — the popover has no toast surface.
+ setError(getApiErrorMessage(caught, t('widgets.generate.systemPrompts.couldNotSave')));
+ return;
+ } finally {
+ setIsSaving(false);
+ }
+
+ // A newly created prompt becomes the selection — it is almost always why it was written.
+ if (!editorTarget.record) {
+ onSelect(saved.id);
+ }
+
+ setEditorTarget(null);
+ }, [catalog, draft, editorTarget, onSelect, t]);
+
+ const confirmDelete = useCallback(async () => {
+ if (!pendingDelete) {
+ return;
+ }
+
+ setError(null);
+
+ try {
+ await catalog.remove(pendingDelete);
+ } catch (caught) {
+ setError(getApiErrorMessage(caught, t('widgets.generate.systemPrompts.couldNotDelete')));
+ return;
+ } finally {
+ setPendingDelete(null);
+ }
+
+ // The selection resolves against the visible list on read, so a deleted prompt needs no
+ // corrective write here — but clearing it avoids one render with a dangling id.
+ if (selectedId === pendingDelete.id) {
+ onSelect(null);
+ }
+ }, [catalog, onSelect, pendingDelete, selectedId, t]);
+
+ const cancelDelete = useCallback(() => setPendingDelete(null), []);
+ const handleSave = useCallback(() => void saveDraft(), [saveDraft]);
+ const handleConfirmDelete = useCallback(() => void confirmDelete(), [confirmDelete]);
+ const handleNameChange = useCallback(
+ (event: ChangeEvent<HTMLInputElement>) => setDraft((current) => ({ ...current, name: event.target.value })),
+ []
+ );
+ const handleContentChange = useCallback(
+ (event: ChangeEvent<HTMLTextAreaElement>) => setDraft((current) => ({ ...current, content: event.target.value })),
+ []
+ );
+ const handleSelectChange = useCallback(({ value }: { value: string[] }) => onSelect(value[0] ?? null), [onSelect]);
+
+ const selectValue = useMemo(() => (selectedId ? [selectedId] : []), [selectedId]);
+
+ if (isManaging && editorTarget) {
+ return (
+ <Stack gap="2">
+ <PromptPanelHeader
+ label={
+ editorTarget.record ? t('widgets.generate.systemPrompts.edit') : t('widgets.generate.systemPrompts.new')
+ }
+ />
+ <Field id={nameFieldId} label={t('widgets.generate.systemPrompts.name')}>
+ <Input
+ id={nameFieldId}
+ placeholder={t('widgets.generate.systemPrompts.namePlaceholder')}
+ size="xs"
+ value={draft.name}
+ onChange={handleNameChange}
+ />
+ </Field>
+ <Textarea
+ aria-label={t('widgets.generate.systemPrompts.content')}
+ minH="6rem"
+ placeholder={t('widgets.generate.systemPrompts.contentPlaceholder')}
+ size="xs"
+ value={draft.content}
+ onChange={handleContentChange}
+ />
+ {error ? (
+ <Text color="fg.error" fontSize="xs">
+ {error}
+ </Text>
+ ) : null}
+ <HStack justify="flex-end">
+ <Button size="xs" variant="ghost" onClick={closeEditor}>
+ {t('common.cancel')}
+ </Button>
+ <Button
+ disabled={!draft.name.trim() || !draft.content.trim()}
+ loading={isSaving}
+ size="xs"
+ onClick={handleSave}
+ >
+ {t('common.save')}
+ </Button>
+ </HStack>
+ </Stack>
+ );
+ }
+
+ if (isManaging) {
+ return (
+ <Stack gap="2">
+ <PromptPanelHeader label={t('widgets.generate.systemPrompts.title')}>
+ <Button h={PANEL_HEADER_CONTROL_HEIGHT} size="2xs" variant="ghost" onClick={startCreate}>
+ <PlusIcon />
+ {t('widgets.generate.systemPrompts.new')}
+ </Button>
+ </PromptPanelHeader>
+ {prompts.length === 0 ? (
+ <Text color="fg.subtle" fontSize="xs">
+ {t('widgets.generate.systemPrompts.none')}
+ </Text>
+ ) : (
+ <Scrollable maxH="12rem">
+ <Stack gap="0.5">
+ {prompts.map((prompt) => (
+ <SystemPromptRow
+ key={prompt.id}
+ canEdit={canEdit(prompt)}
+ prompt={prompt}
+ onDelete={setPendingDelete}
+ onEdit={startEdit}
+ />
+ ))}
+ </Stack>
+ </Scrollable>
+ )}
+ {error ? (
+ <Text color="fg.error" fontSize="xs">
+ {error}
+ </Text>
+ ) : null}
+ <Button size="xs" variant="ghost" onClick={toggleManaging}>
+ {t('common.done')}
+ </Button>
+ <ConfirmDialog
+ body={t('widgets.generate.systemPrompts.deleteBody', { name: pendingDelete?.name ?? '' })}
+ confirmLabel={t('common.delete')}
+ isOpen={pendingDelete !== null}
+ title={t('widgets.generate.systemPrompts.deleteTitle')}
+ onClose={cancelDelete}
+ onConfirm={handleConfirmDelete}
+ />
+ </Stack>
+ );
+ }
+
+ return (
+ <Field id={selectId} label={t('widgets.generate.systemPrompts.title')}>
+ <HStack gap="1">
+ <Select
+ aria-label={t('widgets.generate.systemPrompts.title')}
+ collection={collection}
+ disabled={prompts.length === 0}
+ flex="1"
+ id={selectId}
+ size="xs"
+ value={selectValue}
+ valueText={t('widgets.generate.systemPrompts.none')}
+ onValueChange={handleSelectChange}
+ />
+ <Tooltip content={t('widgets.generate.systemPrompts.manage')}>
+ <IconButton
+ aria-label={t('widgets.generate.systemPrompts.manage')}
+ size="2xs"
+ variant="ghost"
+ onClick={toggleManaging}
+ >
+ <SettingsIcon />
+ </IconButton>
+ </Tooltip>
+ </HStack>
+ </Field>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/useSystemPrompts.ts b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/useSystemPrompts.ts
new file mode 100644
index 0000000000..3837e442d1
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/useSystemPrompts.ts
@@ -0,0 +1,86 @@
+import type { SystemPromptDraft, SystemPromptRecord } from '@features/generation/data/systemPrompts';
+
+import {
+ classifySystemPrompts,
+ isOwnedSystemPrompt,
+ requireOwnedSystemPrompt,
+} from '@features/generation/core/systemPrompts';
+import {
+ createSystemPrompt,
+ deleteSystemPrompt,
+ invalidateSystemPrompts,
+ systemPromptsQueryOptions,
+ updateSystemPrompt,
+} from '@features/generation/data/systemPrompts';
+import { useGenerationUi } from '@features/generation/ui/GenerationUiContext';
+import { assertAccountScopeCurrent, captureAccountScope } from '@platform/state/accountLifecycle';
+import { useQuery, useQueryClient } from '@tanstack/react-query';
+import { useCallback, useMemo } from 'react';
+
+export interface SystemPromptCatalog {
+ personalPrompts: SystemPromptRecord[];
+ sharedPrompts: SystemPromptRecord[];
+ prompts: SystemPromptRecord[];
+ isLoading: boolean;
+ isLoaded: boolean;
+ canEdit: (prompt: SystemPromptRecord) => boolean;
+ create: (draft: SystemPromptDraft) => Promise<SystemPromptRecord>;
+ update: (prompt: SystemPromptRecord, draft: SystemPromptDraft) => Promise<SystemPromptRecord>;
+ remove: (prompt: SystemPromptRecord) => Promise<void>;
+}
+
+export const useSystemPrompts = ({ isEnabled = true }: { isEnabled?: boolean } = {}): SystemPromptCatalog => {
+ const queryClient = useQueryClient();
+ const { account } = useGenerationUi();
+ const query = useQuery({ ...systemPromptsQueryOptions(), enabled: isEnabled });
+ const classified = useMemo(() => classifySystemPrompts(query.data ?? [], account), [account, query.data]);
+
+ const runAndInvalidate = useCallback(
+ async <T>(run: () => Promise<T>): Promise<T> => {
+ const owner = captureAccountScope();
+ const result = await run();
+
+ assertAccountScopeCurrent(owner);
+ await invalidateSystemPrompts(queryClient);
+ return result;
+ },
+ [queryClient]
+ );
+
+ const create = useCallback(
+ (draft: SystemPromptDraft) => runAndInvalidate(() => createSystemPrompt(draft)),
+ [runAndInvalidate]
+ );
+
+ const update = useCallback(
+ (prompt: SystemPromptRecord, draft: SystemPromptDraft) => {
+ // The backend rejects this too; failing here keeps a shared prompt's disabled edit
+ // affordance from turning into a round-trip 403 if it is ever mis-rendered.
+ requireOwnedSystemPrompt(prompt, account);
+ return runAndInvalidate(() => updateSystemPrompt(prompt.id, draft));
+ },
+ [account, runAndInvalidate]
+ );
+
+ const remove = useCallback(
+ (prompt: SystemPromptRecord) => {
+ requireOwnedSystemPrompt(prompt, account);
+ return runAndInvalidate(() => deleteSystemPrompt(prompt.id));
+ },
+ [account, runAndInvalidate]
+ );
+
+ const canEdit = useCallback((prompt: SystemPromptRecord) => isOwnedSystemPrompt(prompt, account), [account]);
+
+ return {
+ canEdit,
+ create,
+ isLoaded: query.isSuccess,
+ isLoading: query.isPending,
+ personalPrompts: classified.personalPrompts,
+ prompts: classified.prompts,
+ remove,
+ sharedPrompts: classified.sharedPrompts,
+ update,
+ };
+};