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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(api): expose intermediates summaries, previews and operations
Josh Corbett2d18210fe72a
diff --git a/invokeai/app/api/routers/intermediates.py b/invokeai/app/api/routers/intermediates.pynew file mode 100644index 0000000000..3daf07f576--- /dev/null+++ b/invokeai/app/api/routers/intermediates.py@@ -0,0 +1,144 @@+"""Scoped cleanup of intermediate images and videos."""++from typing import Literal, Optional++from fastapi import APIRouter, Body, HTTPException, Path, Query, status++from invokeai.app.api.auth_dependencies import CurrentUserOrDefault+from invokeai.app.api.dependencies import ApiDependencies+from invokeai.app.api.routers.image_move_maintenance import assert_image_move_maintenance_inactive+from invokeai.app.services.intermediates.intermediates_base import IntermediatesCaller+from invokeai.app.services.intermediates.intermediates_common import (+ IntermediatesIdempotencyConflictError,+ IntermediatesOperation,+ IntermediatesOperationNotFoundError,+ IntermediatesOperationRequest,+ IntermediatesPreview,+ IntermediatesPreviewNotFoundError,+ IntermediatesPreviewRequest,+ IntermediatesScopeForbiddenError,+ IntermediatesScopeInvalidError,+ IntermediatesSummary,+ IntermediatesSummarySort,+ IntermediatesUnavailableError,+)+from invokeai.app.services.shared.pagination import MAX_PAGE_SIZE++intermediates_router = APIRouter(prefix="/v1/intermediates", tags=["intermediates"])+++def _caller(current_user: CurrentUserOrDefault) -> IntermediatesCaller:+ return IntermediatesCaller(user_id=current_user.user_id, is_admin=current_user.is_admin)+++def _translate(error: Exception) -> HTTPException:+ if isinstance(error, IntermediatesScopeForbiddenError):+ return HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=str(error))+ if isinstance(error, IntermediatesScopeInvalidError):+ return HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(error))+ if isinstance(error, (IntermediatesPreviewNotFoundError, IntermediatesOperationNotFoundError)):+ return HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(error) or "Not found")+ if isinstance(error, (IntermediatesIdempotencyConflictError, IntermediatesUnavailableError)):+ return HTTPException(status_code=status.HTTP_409_CONFLICT, detail=str(error))+ raise error+++@intermediates_router.get("/summary", operation_id="get_intermediates_summary", response_model=IntermediatesSummary)+def get_intermediates_summary(+ current_user: CurrentUserOrDefault,+ owner_id: Optional[str] = Query(+ default=None, min_length=1, max_length=255, description="Admins only: restrict rows to one account"+ ),+ search: Optional[str] = Query(default=None, max_length=200, description="Project (and, for admins, owner) filter"),+ sort: IntermediatesSummarySort = Query(default="reclaimable_bytes"),+ order: Literal["asc", "desc"] = Query(default="desc"),+ offset: int = Query(default=0, ge=0),+ limit: int = Query(default=50, ge=1, le=MAX_PAGE_SIZE),+) -> IntermediatesSummary:+ """Per-project intermediates with what a cleanup could reclaim. Non-admins see their own rows."""+ try:+ return ApiDependencies.invoker.services.intermediates.get_summary(+ _caller(current_user),+ owner_id=owner_id,+ search=search,+ sort=sort,+ descending=order == "desc",+ offset=offset,+ limit=limit,+ )+ except IntermediatesScopeForbiddenError as error:+ raise _translate(error)+++@intermediates_router.post(+ "/previews",+ operation_id="create_intermediates_preview",+ response_model=IntermediatesPreview,+ status_code=status.HTTP_201_CREATED,+)+def create_intermediates_preview(+ current_user: CurrentUserOrDefault,+ request: IntermediatesPreviewRequest = Body(description="What to clear and how"),+) -> IntermediatesPreview:+ """Freezes the targets a cleanup would act on and reports its impact. Previews expire unused."""+ try:+ return ApiDependencies.invoker.services.intermediates.create_preview(request, _caller(current_user))+ except (IntermediatesScopeForbiddenError, IntermediatesScopeInvalidError) as error:+ raise _translate(error)+++@intermediates_router.post(+ "/operations",+ operation_id="start_intermediates_operation",+ response_model=IntermediatesOperation,+ status_code=status.HTTP_202_ACCEPTED,+)+def start_intermediates_operation(+ current_user: CurrentUserOrDefault,+ request: IntermediatesOperationRequest = Body(description="The confirmed preview"),+) -> IntermediatesOperation:+ """Starts the cleanup a preview described. Repeating a request with its idempotency key returns the same operation."""+ assert_image_move_maintenance_inactive()+ try:+ return ApiDependencies.invoker.services.intermediates.start_operation(request, _caller(current_user))+ except (+ IntermediatesPreviewNotFoundError,+ IntermediatesIdempotencyConflictError,+ IntermediatesUnavailableError,+ ) as error:+ raise _translate(error)+++@intermediates_router.get(+ "/operations/{operation_id}", operation_id="get_intermediates_operation", response_model=IntermediatesOperation+)+def get_intermediates_operation(+ current_user: CurrentUserOrDefault,+ operation_id: str = Path(min_length=1, max_length=64),+) -> IntermediatesOperation:+ try:+ return ApiDependencies.invoker.services.intermediates.get_operation(operation_id, _caller(current_user))+ except IntermediatesOperationNotFoundError as error:+ raise _translate(error)+++@intermediates_router.post(+ "/operations/{operation_id}/retry",+ operation_id="retry_intermediates_operation",+ response_model=IntermediatesOperation,+ status_code=status.HTTP_202_ACCEPTED,+)+def retry_intermediates_operation(+ current_user: CurrentUserOrDefault,+ operation_id: str = Path(min_length=1, max_length=64),+) -> IntermediatesOperation:+ """Retries exactly the targets a finished operation left unresolved, as a new operation."""+ assert_image_move_maintenance_inactive()+ try:+ return ApiDependencies.invoker.services.intermediates.retry_operation(operation_id, _caller(current_user))+ except (+ IntermediatesOperationNotFoundError,+ IntermediatesScopeForbiddenError,+ IntermediatesUnavailableError,+ ) as error:+ raise _translate(error)diff --git a/invokeai/app/api/sockets.py b/invokeai/app/api/sockets.pyindex 02f58d494f..489ceb47c4 100644--- a/invokeai/app/api/sockets.py+++ b/invokeai/app/api/sockets.py@@ -31,6 +31,8 @@ from invokeai.app.services.events.events_common import (ImageIndexUpdatedEvent,ImageMapProjectionReadyEvent,ImageUploadedEvent,+ IntermediatesEventBase,+ IntermediatesOperationChangedEvent,InvocationCompleteEvent,InvocationErrorEvent,InvocationProgressEvent,@@ -136,6 +138,7 @@ WORKFLOW_EVENTS = {WorkflowCreatedEvent, WorkflowUpdatedEvent, WorkflowDeletedEvUSER_EVENTS = {UserAccessChangedEvent}IMAGE_INDEX_EVENTS = {ImageIndexStatusEvent, ImageIndexUpdatedEvent, ImageMapProjectionReadyEvent}+INTERMEDIATES_EVENTS = {IntermediatesOperationChangedEvent}MEDIA_EVENTS = {ImageUploadedEvent, VideoUploadedEvent}MODEL_INSTALL_EVENTS = (@@ -245,6 +248,7 @@ class SocketIO:register_events(LLM_TASK_EVENTS, self._handle_llm_task_event)register_events(WORKFLOW_EVENTS, self._handle_workflow_event)register_events(IMAGE_INDEX_EVENTS, self._handle_image_index_event)+ register_events(INTERMEDIATES_EVENTS, self._handle_intermediates_event)register_events(MEDIA_EVENTS, self._handle_media_event)register_events(USER_EVENTS, self._handle_user_access_changed)@@ -1228,6 +1232,17 @@ class SocketIO:# admins only (single-user mode's sole user is an admin).await self._sio.emit(event=event_name, data=event_data.model_dump(mode="json"), room="admin")+ async def _handle_intermediates_event(self, event: FastAPIEvent[IntermediatesEventBase]) -> None:+ event_name, event_data = event+ payload = event_data.model_dump(mode="json")+ if not self._is_multiuser_enabled():+ await self._sio.emit(event=event_name, data=payload, room="admin")+ return+ # One emit with a room list: python-socketio dedupes, so an admin confirming their own+ # cleanup receives each update once.+ rooms = [f"user:{event_data.user_id}", "admin"]+ await self._sio.emit(event=event_name, data=payload, room=rooms)+async def _handle_media_event(self, event: FastAPIEvent[MediaUploadedEventBase]) -> None:"""Route an upload to the clients whose gallery can show it.diff --git a/invokeai/app/api_app.py b/invokeai/app/api_app.pyindex 6c49be86a9..2da5974ec5 100644--- a/invokeai/app/api_app.py+++ b/invokeai/app/api_app.py@@ -33,6 +33,7 @@ from invokeai.app.api.routers import (image_map,image_moves,images,+ intermediates,model_manager,model_relationships,projects,@@ -720,6 +721,7 @@ app.include_router(model_manager.model_manager_router, prefix="/api")app.include_router(image_moves.image_moves_router, prefix="/api")app.include_router(images.images_router, prefix="/api")app.include_router(image_map.image_map_router, prefix="/api")+app.include_router(intermediates.intermediates_router, prefix="/api")app.include_router(videos.videos_router, prefix="/api")app.include_router(gallery.gallery_router, prefix="/api")app.include_router(boards.boards_router, prefix="/api")diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.jsonindex 9b29b39011..68adc01f0e 100644--- a/invokeai/frontend/web/openapi.json+++ b/invokeai/frontend/web/openapi.json@@ -5484,6 +5484,26 @@},"description": "The session ID associated with this upload, if any"},+ {+ "name": "project_id",+ "in": "query",+ "required": false,+ "schema": {+ "anyOf": [+ {+ "type": "string",+ "minLength": 1,+ "maxLength": 255+ },+ {+ "type": "null"+ }+ ],+ "description": "The caller's project this upload originates in, if any; recorded for intermediates cleanup",+ "title": "Project Id"+ },+ "description": "The caller's project this upload originates in, if any; recorded for intermediates cleanup"+ },{"name": "crop_visible","in": "query",@@ -5981,7 +6001,7 @@"delete": {"tags": ["images"],"summary": "Clear Intermediates",- "description": "Clears all intermediates. Requires admin.",+ "description": "Clears every safe intermediate image, instance-wide. Requires admin.\n\nRuns under the same policy as the intermediates manager: images that active work, a saved\ndocument or the recency window protect are kept. Videos are not touched; use the manager.","operationId": "clear_intermediates","responses": {"200": {@@ -7480,12 +7500,12 @@}}},- "/api/v1/videos/upload": {- "post": {- "tags": ["videos"],- "summary": "Upload Video",- "description": "Uploads a video for the current user.",- "operationId": "upload_video",+ "/api/v1/intermediates/summary": {+ "get": {+ "tags": ["intermediates"],+ "summary": "Get Intermediates Summary",+ "description": "Per-project intermediates with what a cleanup could reclaim. Non-admins see their own rows.",+ "operationId": "get_intermediates_summary","security": [{"HTTPBearer": []@@ -7493,243 +7513,88 @@],"parameters": [{- "name": "video_category",- "in": "query",- "required": true,- "schema": {- "$ref": "#/components/schemas/ImageCategory",- "description": "The category of the video"- },- "description": "The category of the video"- },- {- "name": "is_intermediate",- "in": "query",- "required": true,- "schema": {- "type": "boolean",- "description": "Whether this is an intermediate video",- "title": "Is Intermediate"- },- "description": "Whether this is an intermediate video"- },- {- "name": "board_id",+ "name": "owner_id","in": "query","required": false,"schema": {"anyOf": [{- "type": "string"+ "type": "string",+ "minLength": 1,+ "maxLength": 255},{"type": "null"}],- "description": "The board to add this video to, if any",- "title": "Board Id"+ "description": "Admins only: restrict rows to one account",+ "title": "Owner Id"},- "description": "The board to add this video to, if any"+ "description": "Admins only: restrict rows to one account"},{- "name": "session_id",+ "name": "search","in": "query","required": false,"schema": {"anyOf": [{- "type": "string"+ "type": "string",+ "maxLength": 200},{"type": "null"}],- "description": "The session ID associated with this upload, if any",- "title": "Session Id"+ "description": "Project (and, for admins, owner) filter",+ "title": "Search"},- "description": "The session ID associated with this upload, if any"- }- ],- "responses": {- "201": {- "description": "The video was uploaded successfully",- "content": {- "application/json": {- "schema": {- "$ref": "#/components/schemas/VideoDTO"- }- }- }+ "description": "Project (and, for admins, owner) filter"},- "415": {- "description": "Video upload failed"- },- "422": {- "description": "Validation Error",- "content": {- "application/json": {- "schema": {- "$ref": "#/components/schemas/HTTPValidationError"- }- }- }- }- },- "requestBody": {- "required": true,- "content": {- "multipart/form-data": {- "schema": {- "properties": {- "file": {- "type": "string",- "contentMediaType": "application/octet-stream",- "title": "File"- },- "metadata": {- "anyOf": [- {- "type": "string"- },- {- "type": "null"- }- ],- "title": "Metadata",- "description": "The metadata to associate with the video, must be a stringified JSON dict"- }- },- "type": "object",- "required": ["file"],- "title": "Body_upload_video"- }- }- }- }- }- },- "/api/v1/videos/i/{video_name}": {- "delete": {- "tags": ["videos"],- "summary": "Delete Video",- "operationId": "delete_video",- "security": [- {- "HTTPBearer": []- }- ],- "parameters": [{- "name": "video_name",- "in": "path",- "required": true,+ "name": "sort",+ "in": "query",+ "required": false,"schema": {+ "enum": ["reclaimable_bytes", "project_name"],"type": "string",- "description": "The name of the video to delete",- "title": "Video Name"- },- "description": "The name of the video to delete"- }- ],- "responses": {- "200": {- "description": "Successful Response",- "content": {- "application/json": {- "schema": {- "$ref": "#/components/schemas/DeleteVideosResult"- }- }+ "default": "reclaimable_bytes",+ "title": "Sort"}},- "422": {- "description": "Validation Error",- "content": {- "application/json": {- "schema": {- "$ref": "#/components/schemas/HTTPValidationError"- }- }- }- }- }- },- "patch": {- "tags": ["videos"],- "summary": "Update Video",- "operationId": "update_video",- "security": [{- "HTTPBearer": []- }- ],- "parameters": [- {- "name": "video_name",- "in": "path",- "required": true,+ "name": "order",+ "in": "query",+ "required": false,"schema": {+ "enum": ["asc", "desc"],"type": "string",- "description": "The name of the video to update",- "title": "Video Name"- },- "description": "The name of the video to update"- }- ],- "requestBody": {- "required": true,- "content": {- "application/json": {- "schema": {- "$ref": "#/components/schemas/VideoRecordChanges",- "description": "The changes to apply to the video"- }- }- }- },- "responses": {- "200": {- "description": "Successful Response",- "content": {- "application/json": {- "schema": {- "$ref": "#/components/schemas/VideoDTO"- }- }+ "default": "desc",+ "title": "Order"}},- "422": {- "description": "Validation Error",- "content": {- "application/json": {- "schema": {- "$ref": "#/components/schemas/HTTPValidationError"- }- }- }- }- }- },- "get": {- "tags": ["videos"],- "summary": "Get Video Dto",- "operationId": "get_video_dto",- "security": [{- "HTTPBearer": []- }- ],- "parameters": [+ "name": "offset",+ "in": "query",+ "required": false,+ "schema": {+ "type": "integer",+ "minimum": 0,+ "default": 0,+ "title": "Offset"+ }+ },{- "name": "video_name",- "in": "path",- "required": true,+ "name": "limit",+ "in": "query",+ "required": false,"schema": {- "type": "string",- "description": "The name of video to get",- "title": "Video Name"- },- "description": "The name of video to get"+ "type": "integer",+ "maximum": 1000,+ "minimum": 1,+ "default": 50,+ "title": "Limit"+ }}],"responses": {@@ -7738,7 +7603,7 @@"content": {"application/json": {"schema": {- "$ref": "#/components/schemas/VideoDTO"+ "$ref": "#/components/schemas/IntermediatesSummary"}}}@@ -7756,28 +7621,511 @@}}},- "/api/v1/videos/delete": {+ "/api/v1/intermediates/previews": {"post": {- "tags": ["videos"],- "summary": "Delete Videos From List",- "operationId": "delete_videos_from_list",+ "tags": ["intermediates"],+ "summary": "Create Intermediates Preview",+ "description": "Freezes the targets a cleanup would act on and reports its impact. Previews expire unused.",+ "operationId": "create_intermediates_preview","requestBody": {"content": {"application/json": {"schema": {- "$ref": "#/components/schemas/VideoNamesBatch"+ "$ref": "#/components/schemas/IntermediatesPreviewRequest",+ "description": "What to clear and how"}}},"required": true},"responses": {- "200": {+ "201": {"description": "Successful Response","content": {"application/json": {"schema": {- "$ref": "#/components/schemas/DeleteVideosResult"+ "$ref": "#/components/schemas/IntermediatesPreview"+ }+ }+ }+ },+ "422": {+ "description": "Validation Error",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/HTTPValidationError"+ }+ }+ }+ }+ },+ "security": [+ {+ "HTTPBearer": []+ }+ ]+ }+ },+ "/api/v1/intermediates/operations": {+ "post": {+ "tags": ["intermediates"],+ "summary": "Start Intermediates Operation",+ "description": "Starts the cleanup a preview described. Repeating a request with its idempotency key returns the same operation.",+ "operationId": "start_intermediates_operation",+ "requestBody": {+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/IntermediatesOperationRequest",+ "description": "The confirmed preview"+ }+ }+ },+ "required": true+ },+ "responses": {+ "202": {+ "description": "Successful Response",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/IntermediatesOperation"+ }+ }+ }+ },+ "422": {+ "description": "Validation Error",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/HTTPValidationError"+ }+ }+ }+ }+ },+ "security": [+ {+ "HTTPBearer": []+ }+ ]+ }+ },+ "/api/v1/intermediates/operations/{operation_id}": {+ "get": {+ "tags": ["intermediates"],+ "summary": "Get Intermediates Operation",+ "operationId": "get_intermediates_operation",+ "security": [+ {+ "HTTPBearer": []+ }+ ],+ "parameters": [+ {+ "name": "operation_id",+ "in": "path",+ "required": true,+ "schema": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64,+ "title": "Operation Id"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "Successful Response",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/IntermediatesOperation"+ }+ }+ }+ },+ "422": {+ "description": "Validation Error",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/HTTPValidationError"+ }+ }+ }+ }+ }+ }+ },+ "/api/v1/intermediates/operations/{operation_id}/retry": {+ "post": {+ "tags": ["intermediates"],+ "summary": "Retry Intermediates Operation",+ "description": "Retries exactly the targets a finished operation left unresolved, as a new operation.",+ "operationId": "retry_intermediates_operation",+ "security": [+ {+ "HTTPBearer": []+ }+ ],+ "parameters": [+ {+ "name": "operation_id",+ "in": "path",+ "required": true,+ "schema": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64,+ "title": "Operation Id"+ }+ }+ ],+ "responses": {+ "202": {+ "description": "Successful Response",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/IntermediatesOperation"+ }+ }+ }+ },+ "422": {+ "description": "Validation Error",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/HTTPValidationError"+ }+ }+ }+ }+ }+ }+ },+ "/api/v1/videos/upload": {+ "post": {+ "tags": ["videos"],+ "summary": "Upload Video",+ "description": "Uploads a video for the current user.",+ "operationId": "upload_video",+ "security": [+ {+ "HTTPBearer": []+ }+ ],+ "parameters": [+ {+ "name": "video_category",+ "in": "query",+ "required": true,+ "schema": {+ "$ref": "#/components/schemas/ImageCategory",+ "description": "The category of the video"+ },+ "description": "The category of the video"+ },+ {+ "name": "is_intermediate",+ "in": "query",+ "required": true,+ "schema": {+ "type": "boolean",+ "description": "Whether this is an intermediate video",+ "title": "Is Intermediate"+ },+ "description": "Whether this is an intermediate video"+ },+ {+ "name": "board_id",+ "in": "query",+ "required": false,+ "schema": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "The board to add this video to, if any",+ "title": "Board Id"+ },+ "description": "The board to add this video to, if any"+ },+ {+ "name": "session_id",+ "in": "query",+ "required": false,+ "schema": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "The session ID associated with this upload, if any",+ "title": "Session Id"+ },+ "description": "The session ID associated with this upload, if any"+ },+ {+ "name": "project_id",+ "in": "query",+ "required": false,+ "schema": {+ "anyOf": [+ {+ "type": "string",+ "minLength": 1,+ "maxLength": 255+ },+ {+ "type": "null"+ }+ ],+ "description": "The caller's project this upload originates in, if any; recorded for intermediates cleanup",+ "title": "Project Id"+ },+ "description": "The caller's project this upload originates in, if any; recorded for intermediates cleanup"+ }+ ],+ "responses": {+ "201": {+ "description": "The video was uploaded successfully",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/VideoDTO"+ }+ }+ }+ },+ "415": {+ "description": "Video upload failed"+ },+ "422": {+ "description": "Validation Error",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/HTTPValidationError"+ }+ }+ }+ }+ },+ "requestBody": {+ "required": true,+ "content": {+ "multipart/form-data": {+ "schema": {+ "properties": {+ "file": {+ "type": "string",+ "contentMediaType": "application/octet-stream",+ "title": "File"+ },+ "metadata": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Metadata",+ "description": "The metadata to associate with the video, must be a stringified JSON dict"+ }+ },+ "type": "object",+ "required": ["file"],+ "title": "Body_upload_video"+ }+ }+ }+ }+ }+ },+ "/api/v1/videos/i/{video_name}": {+ "delete": {+ "tags": ["videos"],+ "summary": "Delete Video",+ "operationId": "delete_video",+ "security": [+ {+ "HTTPBearer": []+ }+ ],+ "parameters": [+ {+ "name": "video_name",+ "in": "path",+ "required": true,+ "schema": {+ "type": "string",+ "description": "The name of the video to delete",+ "title": "Video Name"+ },+ "description": "The name of the video to delete"+ }+ ],+ "responses": {+ "200": {+ "description": "Successful Response",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/DeleteVideosResult"+ }+ }+ }+ },+ "422": {+ "description": "Validation Error",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/HTTPValidationError"+ }+ }+ }+ }+ }+ },+ "patch": {+ "tags": ["videos"],+ "summary": "Update Video",+ "operationId": "update_video",+ "security": [+ {+ "HTTPBearer": []+ }+ ],+ "parameters": [+ {+ "name": "video_name",+ "in": "path",+ "required": true,+ "schema": {+ "type": "string",+ "description": "The name of the video to update",+ "title": "Video Name"+ },+ "description": "The name of the video to update"+ }+ ],+ "requestBody": {+ "required": true,+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/VideoRecordChanges",+ "description": "The changes to apply to the video"+ }+ }+ }+ },+ "responses": {+ "200": {+ "description": "Successful Response",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/VideoDTO"+ }+ }+ }+ },+ "422": {+ "description": "Validation Error",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/HTTPValidationError"+ }+ }+ }+ }+ }+ },+ "get": {+ "tags": ["videos"],+ "summary": "Get Video Dto",+ "operationId": "get_video_dto",+ "security": [+ {+ "HTTPBearer": []+ }+ ],+ "parameters": [+ {+ "name": "video_name",+ "in": "path",+ "required": true,+ "schema": {+ "type": "string",+ "description": "The name of video to get",+ "title": "Video Name"+ },+ "description": "The name of video to get"+ }+ ],+ "responses": {+ "200": {+ "description": "Successful Response",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/VideoDTO"+ }+ }+ }+ },+ "422": {+ "description": "Validation Error",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/HTTPValidationError"+ }+ }+ }+ }+ }+ }+ },+ "/api/v1/videos/delete": {+ "post": {+ "tags": ["videos"],+ "summary": "Delete Videos From List",+ "operationId": "delete_videos_from_list",+ "requestBody": {+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/VideoNamesBatch"+ }+ }+ },+ "required": true+ },+ "responses": {+ "200": {+ "description": "Successful Response",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/DeleteVideosResult"}}}@@ -44959,6 +45307,30 @@"description": "The subfolder where the image is stored on disk.","default": ""},+ "project_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Project Id",+ "description": "The project this image originated in, if it was made for one."+ },+ "file_size_bytes": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ],+ "title": "File Size Bytes",+ "description": "Bytes the image and its thumbnail occupy on disk; null until measured."+ },"board_id": {"anyOf": [{@@ -48721,6 +49093,645 @@"title": "IntegerOutput","type": "object"},+ "IntermediatesAffectedDocument": {+ "properties": {+ "kind": {+ "type": "string",+ "enum": ["project", "workflow"],+ "title": "Kind"+ },+ "user_id": {+ "type": "string",+ "title": "User Id"+ },+ "owner_id": {+ "type": "string",+ "title": "Owner Id",+ "description": "The project or workflow id"+ },+ "name": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Name",+ "description": "The document's name, if it still exists"+ },+ "references": {+ "type": "integer",+ "title": "References",+ "description": "How many of the targeted items the document names"+ }+ },+ "type": "object",+ "required": ["kind", "user_id", "owner_id", "references"],+ "title": "IntermediatesAffectedDocument",+ "description": "A saved document a force clear would leave pointing at deleted media."+ },+ "IntermediatesImpact": {+ "properties": {+ "delete_images": {+ "type": "integer",+ "title": "Delete Images",+ "default": 0+ },+ "delete_videos": {+ "type": "integer",+ "title": "Delete Videos",+ "default": 0+ },+ "keep_referenced_images": {+ "type": "integer",+ "title": "Keep Referenced Images",+ "default": 0+ },+ "keep_referenced_videos": {+ "type": "integer",+ "title": "Keep Referenced Videos",+ "default": 0+ },+ "keep_active_images": {+ "type": "integer",+ "title": "Keep Active Images",+ "default": 0+ },+ "keep_active_videos": {+ "type": "integer",+ "title": "Keep Active Videos",+ "default": 0+ },+ "keep_recent_images": {+ "type": "integer",+ "title": "Keep Recent Images",+ "default": 0+ },+ "keep_recent_videos": {+ "type": "integer",+ "title": "Keep Recent Videos",+ "default": 0+ },+ "reclaimable_bytes": {+ "type": "integer",+ "title": "Reclaimable Bytes",+ "description": "Measured size of the items that would be deleted",+ "default": 0+ },+ "unknown_size_count": {+ "type": "integer",+ "title": "Unknown Size Count",+ "description": "Items to delete whose size is not yet measured",+ "default": 0+ }+ },+ "type": "object",+ "title": "IntermediatesImpact"+ },+ "IntermediatesKindCounts": {+ "properties": {+ "safe": {+ "type": "integer",+ "title": "Safe",+ "description": "Unreferenced, inactive and old enough: deleted by either mode",+ "default": 0+ },+ "referenced": {+ "type": "integer",+ "title": "Referenced",+ "description": "Named by a saved project or workflow: kept by safe mode",+ "default": 0+ },+ "active": {+ "type": "integer",+ "title": "Active",+ "description": "Produced or consumed by pending, waiting or running work: always kept",+ "default": 0+ },+ "recent": {+ "type": "integer",+ "title": "Recent",+ "description": "Created inside the grace window: always kept",+ "default": 0+ }+ },+ "type": "object",+ "title": "IntermediatesKindCounts",+ "description": "How one media kind's intermediates split under the cleanup policy."+ },+ "IntermediatesOperation": {+ "properties": {+ "operation_id": {+ "type": "string",+ "title": "Operation Id"+ },+ "user_id": {+ "type": "string",+ "title": "User Id",+ "description": "The account that confirmed the operation"+ },+ "mode": {+ "type": "string",+ "enum": ["safe", "force"],+ "title": "Mode"+ },+ "scope": {+ "$ref": "#/components/schemas/IntermediatesScope"+ },+ "status": {+ "type": "string",+ "enum": ["pending", "running", "completed", "failed"],+ "title": "Status"+ },+ "created_at": {+ "type": "string",+ "format": "date-time",+ "title": "Created At"+ },+ "started_at": {+ "anyOf": [+ {+ "type": "string",+ "format": "date-time"+ },+ {+ "type": "null"+ }+ ],+ "title": "Started At"+ },+ "completed_at": {+ "anyOf": [+ {+ "type": "string",+ "format": "date-time"+ },+ {+ "type": "null"+ }+ ],+ "title": "Completed At"+ },+ "error": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Error",+ "description": "Why the operation stopped, when it failed"+ },+ "target_images": {+ "type": "integer",+ "title": "Target Images",+ "description": "Frozen image targets"+ },+ "target_videos": {+ "type": "integer",+ "title": "Target Videos",+ "description": "Frozen video targets"+ },+ "progress": {+ "$ref": "#/components/schemas/IntermediatesOperationProgress"+ },+ "retried_from_operation_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Retried From Operation Id"+ }+ },+ "type": "object",+ "required": [+ "operation_id",+ "user_id",+ "mode",+ "scope",+ "status",+ "created_at",+ "target_images",+ "target_videos",+ "progress"+ ],+ "title": "IntermediatesOperation"+ },+ "IntermediatesOperationChangedEvent": {+ "description": "Event model for intermediates_operation_changed.\n\nRouted to the confirming account's room and to admins: the operation's progress is that\naccount's business, and admins see every cleanup so open managers refresh their counts.",+ "properties": {+ "timestamp": {+ "description": "The timestamp of the event",+ "title": "Timestamp",+ "type": "integer"+ },+ "user_id": {+ "description": "The account that confirmed the operation",+ "title": "User Id",+ "type": "string"+ },+ "operation": {+ "$ref": "#/components/schemas/IntermediatesOperation",+ "description": "The operation's current state"+ }+ },+ "required": ["timestamp", "user_id", "operation"],+ "title": "IntermediatesOperationChangedEvent",+ "type": "object"+ },+ "IntermediatesOperationProgress": {+ "properties": {+ "processed_images": {+ "type": "integer",+ "title": "Processed Images",+ "default": 0+ },+ "processed_videos": {+ "type": "integer",+ "title": "Processed Videos",+ "default": 0+ },+ "deleted_images": {+ "type": "integer",+ "title": "Deleted Images",+ "default": 0+ },+ "deleted_videos": {+ "type": "integer",+ "title": "Deleted Videos",+ "default": 0+ },+ "retained_images": {+ "type": "integer",+ "title": "Retained Images",+ "description": "Targets the final check kept: promoted, protected or gone",+ "default": 0+ },+ "retained_videos": {+ "type": "integer",+ "title": "Retained Videos",+ "default": 0+ },+ "failed_images": {+ "type": "integer",+ "title": "Failed Images",+ "description": "Targets whose deletion raised; retryable",+ "default": 0+ },+ "failed_videos": {+ "type": "integer",+ "title": "Failed Videos",+ "default": 0+ },+ "reclaimed_bytes": {+ "type": "integer",+ "title": "Reclaimed Bytes",+ "description": "Bytes whose files are confirmed removed",+ "default": 0+ },+ "pending_disk_cleanup": {+ "type": "integer",+ "title": "Pending Disk Cleanup",+ "description": "Deleted records whose files could not be purged yet; the journal retries at startup",+ "default": 0+ }+ },+ "type": "object",+ "title": "IntermediatesOperationProgress"+ },+ "IntermediatesOperationRequest": {+ "properties": {+ "preview_id": {+ "type": "string",+ "maxLength": 64,+ "minLength": 1,+ "title": "Preview Id"+ },+ "idempotency_key": {+ "type": "string",+ "maxLength": 255,+ "minLength": 1,+ "title": "Idempotency Key",+ "description": "Caller-owned retry key"+ }+ },+ "type": "object",+ "required": ["preview_id", "idempotency_key"],+ "title": "IntermediatesOperationRequest"+ },+ "IntermediatesPreview": {+ "properties": {+ "preview_id": {+ "type": "string",+ "title": "Preview Id"+ },+ "mode": {+ "type": "string",+ "enum": ["safe", "force"],+ "title": "Mode"+ },+ "scope": {+ "$ref": "#/components/schemas/IntermediatesScope"+ },+ "created_at": {+ "type": "string",+ "format": "date-time",+ "title": "Created At"+ },+ "expires_at": {+ "type": "string",+ "format": "date-time",+ "title": "Expires At"+ },+ "target_rows": {+ "type": "integer",+ "title": "Target Rows",+ "description": "Rows the scope resolved to"+ },+ "impact": {+ "$ref": "#/components/schemas/IntermediatesImpact"+ },+ "affected_documents": {+ "items": {+ "$ref": "#/components/schemas/IntermediatesAffectedDocument"+ },+ "type": "array",+ "title": "Affected Documents",+ "description": "Documents a force clear would break, limited to those the caller may see"+ },+ "affected_documents_hidden": {+ "type": "integer",+ "title": "Affected Documents Hidden",+ "description": "Affected documents belonging to accounts the caller may not inspect",+ "default": 0+ }+ },+ "type": "object",+ "required": ["preview_id", "mode", "scope", "created_at", "expires_at", "target_rows", "impact"],+ "title": "IntermediatesPreview"+ },+ "IntermediatesPreviewRequest": {+ "properties": {+ "mode": {+ "type": "string",+ "enum": ["safe", "force"],+ "title": "Mode"+ },+ "scope": {+ "$ref": "#/components/schemas/IntermediatesScope"+ }+ },+ "type": "object",+ "required": ["mode", "scope"],+ "title": "IntermediatesPreviewRequest"+ },+ "IntermediatesRow": {+ "properties": {+ "user_id": {+ "type": "string",+ "title": "User Id",+ "description": "The owning account"+ },+ "project_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Project Id",+ "description": "The originating project; null selects the owner's unassigned intermediates"+ },+ "user_display_name": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "User Display Name",+ "description": "The owner's display name, if known"+ },+ "user_email": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "User Email",+ "description": "The owner's email, if known"+ },+ "project_name": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Project Name",+ "description": "The project's name; null for unassigned rows"+ },+ "images": {+ "$ref": "#/components/schemas/IntermediatesKindCounts"+ },+ "videos": {+ "$ref": "#/components/schemas/IntermediatesKindCounts"+ },+ "reclaimable_bytes": {+ "type": "integer",+ "title": "Reclaimable Bytes",+ "description": "Measured size of the safe items",+ "default": 0+ },+ "referenced_bytes": {+ "type": "integer",+ "title": "Referenced Bytes",+ "description": "Measured size of the referenced items a force clear adds",+ "default": 0+ },+ "unknown_size_count": {+ "type": "integer",+ "title": "Unknown Size Count",+ "description": "Safe or referenced items whose size is not yet measured",+ "default": 0+ }+ },+ "type": "object",+ "required": ["user_id"],+ "title": "IntermediatesRow"+ },+ "IntermediatesScope": {+ "properties": {+ "kind": {+ "type": "string",+ "enum": ["selection", "owner", "everyone"],+ "title": "Kind",+ "description": "How the targets were chosen"+ },+ "targets": {+ "items": {+ "$ref": "#/components/schemas/IntermediatesScopeTarget"+ },+ "type": "array",+ "maxItems": 1000,+ "title": "Targets",+ "description": "The selected rows; only read for a `selection` scope"+ },+ "user_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "User Id",+ "description": "The account whose rows are targeted by an `owner` scope"+ }+ },+ "type": "object",+ "required": ["kind"],+ "title": "IntermediatesScope"+ },+ "IntermediatesScopeTarget": {+ "properties": {+ "user_id": {+ "type": "string",+ "title": "User Id",+ "description": "The owning account"+ },+ "project_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Project Id",+ "description": "The originating project; null selects the owner's unassigned intermediates"+ }+ },+ "type": "object",+ "required": ["user_id"],+ "title": "IntermediatesScopeTarget",+ "description": "One row of the manager: an owner's project, or their unassigned intermediates."+ },+ "IntermediatesSummary": {+ "properties": {+ "items": {+ "items": {+ "$ref": "#/components/schemas/IntermediatesRow"+ },+ "type": "array",+ "title": "Items"+ },+ "total": {+ "type": "integer",+ "title": "Total",+ "description": "Rows matching the request"+ },+ "offset": {+ "type": "integer",+ "title": "Offset"+ },+ "limit": {+ "type": "integer",+ "title": "Limit"+ },+ "totals": {+ "$ref": "#/components/schemas/IntermediatesSummaryTotals"+ },+ "recent_grace_seconds": {+ "type": "integer",+ "title": "Recent Grace Seconds",+ "description": "How long a new intermediate is protected"+ },+ "measuring": {+ "type": "boolean",+ "title": "Measuring",+ "description": "Whether sizes are still being measured in the background"+ },+ "can_manage_everyone": {+ "type": "boolean",+ "title": "Can Manage Everyone",+ "description": "Whether the caller may target other accounts"+ }+ },+ "type": "object",+ "required": [+ "items",+ "total",+ "offset",+ "limit",+ "totals",+ "recent_grace_seconds",+ "measuring",+ "can_manage_everyone"+ ],+ "title": "IntermediatesSummary"+ },+ "IntermediatesSummaryTotals": {+ "properties": {+ "rows": {+ "type": "integer",+ "title": "Rows",+ "default": 0+ },+ "safe_images": {+ "type": "integer",+ "title": "Safe Images",+ "default": 0+ },+ "safe_videos": {+ "type": "integer",+ "title": "Safe Videos",+ "default": 0+ },+ "in_use_images": {+ "type": "integer",+ "title": "In Use Images",+ "default": 0+ },+ "in_use_videos": {+ "type": "integer",+ "title": "In Use Videos",+ "default": 0+ },+ "reclaimable_bytes": {+ "type": "integer",+ "title": "Reclaimable Bytes",+ "default": 0+ },+ "unknown_size_count": {+ "type": "integer",+ "title": "Unknown Size Count",+ "default": 0+ }+ },+ "type": "object",+ "title": "IntermediatesSummaryTotals",+ "description": "Totals over every row that matches the request, not just the returned page."+ },"InvertTensorMaskInvocation": {"category": "mask","class": "invocation",@@ -93958,6 +94969,18 @@"description": "The id of the user who created this queue item","default": "system"},+ "project_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Project Id",+ "description": "The project this queue item was enqueued for, if any; its outputs inherit it"+ },"user_display_name": {"anyOf": [{@@ -102743,6 +103766,30 @@"description": "The subfolder where the video is stored on disk.","default": ""},+ "project_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Project Id",+ "description": "The project this video originated in, if it was made for one."+ },+ "file_size_bytes": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ],+ "title": "File Size Bytes",+ "description": "Bytes the video, its thumbnail and sidecar occupy on disk; null until measured."+ },"media_origin": {"anyOf": [{diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.tsindex e400eb0104..6ff1c28951 100644--- a/invokeai/frontend/web/src/services/api/schema.ts+++ b/invokeai/frontend/web/src/services/api/schema.ts@@ -1302,7 +1302,10 @@ export type paths = {post?: never;/*** Clear Intermediates- * @description Clears all intermediates. Requires admin.+ * @description Clears every safe intermediate image, instance-wide. Requires admin.+ *+ * Runs under the same policy as the intermediates manager: images that active work, a saved+ * document or the recency window protect are kept. Videos are not touched; use the manager.*/delete: operations["clear_intermediates"];options?: never;@@ -1817,6 +1820,103 @@ export type paths = {patch?: never;trace?: never;};+ "/api/v1/intermediates/summary": {+ parameters: {+ query?: never;+ header?: never;+ path?: never;+ cookie?: never;+ };+ /**+ * Get Intermediates Summary+ * @description Per-project intermediates with what a cleanup could reclaim. Non-admins see their own rows.+ */+ get: operations["get_intermediates_summary"];+ put?: never;+ post?: never;+ delete?: never;+ options?: never;+ head?: never;+ patch?: never;+ trace?: never;+ };+ "/api/v1/intermediates/previews": {+ parameters: {+ query?: never;+ header?: never;+ path?: never;+ cookie?: never;+ };+ get?: never;+ put?: never;+ /**+ * Create Intermediates Preview+ * @description Freezes the targets a cleanup would act on and reports its impact. Previews expire unused.+ */+ post: operations["create_intermediates_preview"];+ delete?: never;+ options?: never;+ head?: never;+ patch?: never;+ trace?: never;+ };+ "/api/v1/intermediates/operations": {+ parameters: {+ query?: never;+ header?: never;+ path?: never;+ cookie?: never;+ };+ get?: never;+ put?: never;+ /**+ * Start Intermediates Operation+ * @description Starts the cleanup a preview described. Repeating a request with its idempotency key returns the same operation.+ */+ post: operations["start_intermediates_operation"];+ delete?: never;+ options?: never;+ head?: never;+ patch?: never;+ trace?: never;+ };+ "/api/v1/intermediates/operations/{operation_id}": {+ parameters: {+ query?: never;+ header?: never;+ path?: never;+ cookie?: never;+ };+ /** Get Intermediates Operation */+ get: operations["get_intermediates_operation"];+ put?: never;+ post?: never;+ delete?: never;+ options?: never;+ head?: never;+ patch?: never;+ trace?: never;+ };+ "/api/v1/intermediates/operations/{operation_id}/retry": {+ parameters: {+ query?: never;+ header?: never;+ path?: never;+ cookie?: never;+ };+ get?: never;+ put?: never;+ /**+ * Retry Intermediates Operation+ * @description Retries exactly the targets a finished operation left unresolved, as a new operation.+ */+ post: operations["retry_intermediates_operation"];+ delete?: never;+ options?: never;+ head?: never;+ patch?: never;+ trace?: never;+ };"/api/v1/videos/upload": {parameters: {query?: never;@@ -18439,6 +18539,16 @@ export type components = {* @default*/image_subfolder?: string;+ /**+ * Project Id+ * @description The project this image originated in, if it was made for one.+ */+ project_id?: string | null;+ /**+ * File Size Bytes+ * @description Bytes the image and its thumbnail occupy on disk; null until measured.+ */+ file_size_bytes?: number | null;/*** Board Id* @description The id of the board the image belongs to, if one exists.@@ -20490,6 +20600,456 @@ export type components = {*/type: "integer_output";};+ /**+ * IntermediatesAffectedDocument+ * @description A saved document a force clear would leave pointing at deleted media.+ */+ IntermediatesAffectedDocument: {+ /**+ * Kind+ * @enum {string}+ */+ kind: "project" | "workflow";+ /** User Id */+ user_id: string;+ /**+ * Owner Id+ * @description The project or workflow id+ */+ owner_id: string;+ /**+ * Name+ * @description The document's name, if it still exists+ */+ name?: string | null;+ /**+ * References+ * @description How many of the targeted items the document names+ */+ references: number;+ };+ /** IntermediatesImpact */+ IntermediatesImpact: {+ /**+ * Delete Images+ * @default 0+ */+ delete_images?: number;+ /**+ * Delete Videos+ * @default 0+ */+ delete_videos?: number;+ /**+ * Keep Referenced Images+ * @default 0+ */+ keep_referenced_images?: number;+ /**+ * Keep Referenced Videos+ * @default 0+ */+ keep_referenced_videos?: number;+ /**+ * Keep Active Images+ * @default 0+ */+ keep_active_images?: number;+ /**+ * Keep Active Videos+ * @default 0+ */+ keep_active_videos?: number;+ /**+ * Keep Recent Images+ * @default 0+ */+ keep_recent_images?: number;+ /**+ * Keep Recent Videos+ * @default 0+ */+ keep_recent_videos?: number;+ /**+ * Reclaimable Bytes+ * @description Measured size of the items that would be deleted+ * @default 0+ */+ reclaimable_bytes?: number;+ /**+ * Unknown Size Count+ * @description Items to delete whose size is not yet measured+ * @default 0+ */+ unknown_size_count?: number;+ };+ /**+ * IntermediatesKindCounts+ * @description How one media kind's intermediates split under the cleanup policy.+ */+ IntermediatesKindCounts: {+ /**+ * Safe+ * @description Unreferenced, inactive and old enough: deleted by either mode+ * @default 0+ */+ safe?: number;+ /**+ * Referenced+ * @description Named by a saved project or workflow: kept by safe mode+ * @default 0+ */+ referenced?: number;+ /**+ * Active+ * @description Produced or consumed by pending, waiting or running work: always kept+ * @default 0+ */+ active?: number;+ /**+ * Recent+ * @description Created inside the grace window: always kept+ * @default 0+ */+ recent?: number;+ };+ /** IntermediatesOperation */+ IntermediatesOperation: {+ /** Operation Id */+ operation_id: string;+ /**+ * User Id+ * @description The account that confirmed the operation+ */+ user_id: string;+ /**+ * Mode+ * @enum {string}+ */+ mode: "safe" | "force";+ scope: components["schemas"]["IntermediatesScope"];+ /**+ * Status+ * @enum {string}+ */+ status: "pending" | "running" | "completed" | "failed";+ /**+ * Created At+ * Format: date-time+ */+ created_at: string;+ /** Started At */+ started_at?: string | null;+ /** Completed At */+ completed_at?: string | null;+ /**+ * Error+ * @description Why the operation stopped, when it failed+ */+ error?: string | null;+ /**+ * Target Images+ * @description Frozen image targets+ */+ target_images: number;+ /**+ * Target Videos+ * @description Frozen video targets+ */+ target_videos: number;+ progress: components["schemas"]["IntermediatesOperationProgress"];+ /** Retried From Operation Id */+ retried_from_operation_id?: string | null;+ };+ /**+ * IntermediatesOperationChangedEvent+ * @description Event model for intermediates_operation_changed.+ *+ * Routed to the confirming account's room and to admins: the operation's progress is that+ * account's business, and admins see every cleanup so open managers refresh their counts.+ */+ IntermediatesOperationChangedEvent: {+ /**+ * Timestamp+ * @description The timestamp of the event+ */+ timestamp: number;+ /**+ * User Id+ * @description The account that confirmed the operation+ */+ user_id: string;+ /** @description The operation's current state */+ operation: components["schemas"]["IntermediatesOperation"];+ };+ /** IntermediatesOperationProgress */+ IntermediatesOperationProgress: {+ /**+ * Processed Images+ * @default 0+ */+ processed_images?: number;+ /**+ * Processed Videos+ * @default 0+ */+ processed_videos?: number;+ /**+ * Deleted Images+ * @default 0+ */+ deleted_images?: number;+ /**+ * Deleted Videos+ * @default 0+ */+ deleted_videos?: number;+ /**+ * Retained Images+ * @description Targets the final check kept: promoted, protected or gone+ * @default 0+ */+ retained_images?: number;+ /**+ * Retained Videos+ * @default 0+ */+ retained_videos?: number;+ /**+ * Failed Images+ * @description Targets whose deletion raised; retryable+ * @default 0+ */+ failed_images?: number;+ /**+ * Failed Videos+ * @default 0+ */+ failed_videos?: number;+ /**+ * Reclaimed Bytes+ * @description Bytes whose files are confirmed removed+ * @default 0+ */+ reclaimed_bytes?: number;+ /**+ * Pending Disk Cleanup+ * @description Deleted records whose files could not be purged yet; the journal retries at startup+ * @default 0+ */+ pending_disk_cleanup?: number;+ };+ /** IntermediatesOperationRequest */+ IntermediatesOperationRequest: {+ /** Preview Id */+ preview_id: string;+ /**+ * Idempotency Key+ * @description Caller-owned retry key+ */+ idempotency_key: string;+ };+ /** IntermediatesPreview */+ IntermediatesPreview: {+ /** Preview Id */+ preview_id: string;+ /**+ * Mode+ * @enum {string}+ */+ mode: "safe" | "force";+ scope: components["schemas"]["IntermediatesScope"];+ /**+ * Created At+ * Format: date-time+ */+ created_at: string;+ /**+ * Expires At+ * Format: date-time+ */+ expires_at: string;+ /**+ * Target Rows+ * @description Rows the scope resolved to+ */+ target_rows: number;+ impact: components["schemas"]["IntermediatesImpact"];+ /**+ * Affected Documents+ * @description Documents a force clear would break, limited to those the caller may see+ */+ affected_documents?: components["schemas"]["IntermediatesAffectedDocument"][];+ /**+ * Affected Documents Hidden+ * @description Affected documents belonging to accounts the caller may not inspect+ * @default 0+ */+ affected_documents_hidden?: number;+ };+ /** IntermediatesPreviewRequest */+ IntermediatesPreviewRequest: {+ /**+ * Mode+ * @enum {string}+ */+ mode: "safe" | "force";+ scope: components["schemas"]["IntermediatesScope"];+ };+ /** IntermediatesRow */+ IntermediatesRow: {+ /**+ * User Id+ * @description The owning account+ */+ user_id: string;+ /**+ * Project Id+ * @description The originating project; null selects the owner's unassigned intermediates+ */+ project_id?: string | null;+ /**+ * User Display Name+ * @description The owner's display name, if known+ */+ user_display_name?: string | null;+ /**+ * User Email+ * @description The owner's email, if known+ */+ user_email?: string | null;+ /**+ * Project Name+ * @description The project's name; null for unassigned rows+ */+ project_name?: string | null;+ images?: components["schemas"]["IntermediatesKindCounts"];+ videos?: components["schemas"]["IntermediatesKindCounts"];+ /**+ * Reclaimable Bytes+ * @description Measured size of the safe items+ * @default 0+ */+ reclaimable_bytes?: number;+ /**+ * Referenced Bytes+ * @description Measured size of the referenced items a force clear adds+ * @default 0+ */+ referenced_bytes?: number;+ /**+ * Unknown Size Count+ * @description Safe or referenced items whose size is not yet measured+ * @default 0+ */+ unknown_size_count?: number;+ };+ /** IntermediatesScope */+ IntermediatesScope: {+ /**+ * Kind+ * @description How the targets were chosen+ * @enum {string}+ */+ kind: "selection" | "owner" | "everyone";+ /**+ * Targets+ * @description The selected rows; only read for a `selection` scope+ */+ targets?: components["schemas"]["IntermediatesScopeTarget"][];+ /**+ * User Id+ * @description The account whose rows are targeted by an `owner` scope+ */+ user_id?: string | null;+ };+ /**+ * IntermediatesScopeTarget+ * @description One row of the manager: an owner's project, or their unassigned intermediates.+ */+ IntermediatesScopeTarget: {+ /**+ * User Id+ * @description The owning account+ */+ user_id: string;+ /**+ * Project Id+ * @description The originating project; null selects the owner's unassigned intermediates+ */+ project_id?: string | null;+ };+ /** IntermediatesSummary */+ IntermediatesSummary: {+ /** Items */+ items: components["schemas"]["IntermediatesRow"][];+ /**+ * Total+ * @description Rows matching the request+ */+ total: number;+ /** Offset */+ offset: number;+ /** Limit */+ limit: number;+ totals: components["schemas"]["IntermediatesSummaryTotals"];+ /**+ * Recent Grace Seconds+ * @description How long a new intermediate is protected+ */+ recent_grace_seconds: number;+ /**+ * Measuring+ * @description Whether sizes are still being measured in the background+ */+ measuring: boolean;+ /**+ * Can Manage Everyone+ * @description Whether the caller may target other accounts+ */+ can_manage_everyone: boolean;+ };+ /**+ * IntermediatesSummaryTotals+ * @description Totals over every row that matches the request, not just the returned page.+ */+ IntermediatesSummaryTotals: {+ /**+ * Rows+ * @default 0+ */+ rows?: number;+ /**+ * Safe Images+ * @default 0+ */+ safe_images?: number;+ /**+ * Safe Videos+ * @default 0+ */+ safe_videos?: number;+ /**+ * In Use Images+ * @default 0+ */+ in_use_images?: number;+ /**+ * In Use Videos+ * @default 0+ */+ in_use_videos?: number;+ /**+ * Reclaimable Bytes+ * @default 0+ */+ reclaimable_bytes?: number;+ /**+ * Unknown Size Count+ * @default 0+ */+ unknown_size_count?: number;+ };/*** Invert Tensor Mask* @description Inverts a tensor mask.@@ -41133,6 +41693,11 @@ export type components = {* @default system*/user_id?: string;+ /**+ * Project Id+ * @description The project this queue item was enqueued for, if any; its outputs inherit it+ */+ project_id?: string | null;/*** User Display Name* @description The display name of the user who created this queue item, if available@@ -45972,6 +46537,16 @@ export type components = {* @default*/video_subfolder?: string;+ /**+ * Project Id+ * @description The project this video originated in, if it was made for one.+ */+ project_id?: string | null;+ /**+ * File Size Bytes+ * @description Bytes the video, its thumbnail and sidecar occupy on disk; null until measured.+ */+ file_size_bytes?: number | null;/*** Media Origin* @description How this video entered the gallery, if it was marked: 'audio_upload' for an uploaded audio file the server wrapped into a waveform video.@@ -51406,6 +51981,8 @@ export interface operations {board_id?: string | null;/** @description The session ID associated with this upload, if any */session_id?: string | null;+ /** @description The caller's project this upload originates in, if any; recorded for intermediates cleanup */+ project_id?: string | null;/** @description Whether to crop the image */crop_visible?: boolean | null;};@@ -52490,6 +53067,172 @@ export interface operations {};};};+ get_intermediates_summary: {+ parameters: {+ query?: {+ /** @description Admins only: restrict rows to one account */+ owner_id?: string | null;+ /** @description Project (and, for admins, owner) filter */+ search?: string | null;+ sort?: "reclaimable_bytes" | "project_name";+ order?: "asc" | "desc";+ offset?: number;+ limit?: number;+ };+ header?: never;+ path?: never;+ cookie?: never;+ };+ requestBody?: never;+ responses: {+ /** @description Successful Response */+ 200: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["IntermediatesSummary"];+ };+ };+ /** @description Validation Error */+ 422: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["HTTPValidationError"];+ };+ };+ };+ };+ create_intermediates_preview: {+ parameters: {+ query?: never;+ header?: never;+ path?: never;+ cookie?: never;+ };+ requestBody: {+ content: {+ "application/json": components["schemas"]["IntermediatesPreviewRequest"];+ };+ };+ responses: {+ /** @description Successful Response */+ 201: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["IntermediatesPreview"];+ };+ };+ /** @description Validation Error */+ 422: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["HTTPValidationError"];+ };+ };+ };+ };+ start_intermediates_operation: {+ parameters: {+ query?: never;+ header?: never;+ path?: never;+ cookie?: never;+ };+ requestBody: {+ content: {+ "application/json": components["schemas"]["IntermediatesOperationRequest"];+ };+ };+ responses: {+ /** @description Successful Response */+ 202: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["IntermediatesOperation"];+ };+ };+ /** @description Validation Error */+ 422: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["HTTPValidationError"];+ };+ };+ };+ };+ get_intermediates_operation: {+ parameters: {+ query?: never;+ header?: never;+ path: {+ operation_id: string;+ };+ cookie?: never;+ };+ requestBody?: never;+ responses: {+ /** @description Successful Response */+ 200: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["IntermediatesOperation"];+ };+ };+ /** @description Validation Error */+ 422: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["HTTPValidationError"];+ };+ };+ };+ };+ retry_intermediates_operation: {+ parameters: {+ query?: never;+ header?: never;+ path: {+ operation_id: string;+ };+ cookie?: never;+ };+ requestBody?: never;+ responses: {+ /** @description Successful Response */+ 202: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["IntermediatesOperation"];+ };+ };+ /** @description Validation Error */+ 422: {+ headers: {+ [name: string]: unknown;+ };+ content: {+ "application/json": components["schemas"]["HTTPValidationError"];+ };+ };+ };+ };upload_video: {parameters: {query: {@@ -52501,6 +53244,8 @@ export interface operations {board_id?: string | null;/** @description The session ID associated with this upload, if any */session_id?: string | null;+ /** @description The caller's project this upload originates in, if any; recorded for intermediates cleanup */+ project_id?: string | null;};header?: never;path?: never;diff --git a/tests/app/routers/conftest.py b/tests/app/routers/conftest.pyindex 9261f3d8fd..f9ccfe546c 100644--- a/tests/app/routers/conftest.py+++ b/tests/app/routers/conftest.py@@ -58,6 +58,7 @@ _PATCHED_API_DEPENDENCIES_MODULES = ("invokeai.app.api.routers.virtual_boards","invokeai.app.api.routers.gallery","invokeai.app.api.routers.images",+ "invokeai.app.api.routers.intermediates","invokeai.app.api.routers.workflows","invokeai.app.api.routers._access","invokeai.app.api.routers.model_manager",diff --git a/tests/app/routers/test_intermediates.py b/tests/app/routers/test_intermediates.pynew file mode 100644index 0000000000..993cff6d9e--- /dev/null+++ b/tests/app/routers/test_intermediates.py@@ -0,0 +1,204 @@+"""The intermediates API: authorization at the HTTP boundary and the preview → operation flow."""++from pathlib import Path+from typing import Any+from unittest.mock import MagicMock++import pytest+from fastapi import status+from fastapi.testclient import TestClient+from PIL import Image++from invokeai.app.services.image_files.image_files_disk import DiskImageFileStorage+from invokeai.app.services.image_records.image_records_common import ImageCategory, ResourceOrigin+from invokeai.app.services.invoker import Invoker+++def storage_ready(enable_multiuser: Any, mock_invoker: Invoker, tmp_path: Path) -> None:+ services = mock_invoker.services+ services.image_files = DiskImageFileStorage(tmp_path / "outputs")+ services.image_files.start(mock_invoker)+ services.image_moves = MagicMock()+ services.image_moves.is_maintenance_active.return_value = False+ services.videos = MagicMock()+ services.videos.delete_intermediates_by_names.return_value = MagicMock(deleted_names=[], purge_deferred=[])+ services.session_queue = MagicMock()+++def _auth(token: str) -> dict[str, str]:+ return {"Authorization": f"Bearer {token}"}+++def _user_id(mock_invoker: Invoker, email: str) -> str:+ user = mock_invoker.services.users.get_by_email(email)+ assert user is not None+ return user.user_id+++def _seed_intermediate(mock_invoker: Invoker, name: str, user_id: str) -> None:+ mock_invoker.services.image_records.save(+ image_name=name,+ image_origin=ResourceOrigin.INTERNAL,+ image_category=ImageCategory.GENERAL,+ width=8,+ height=8,+ has_workflow=False,+ is_intermediate=True,+ user_id=user_id,+ )+ with mock_invoker.services.image_records._db.transaction() as cursor:+ cursor.execute("UPDATE images SET created_at = '2020-01-01 00:00:00.000' WHERE image_name = ?;", (name,))+ mock_invoker.services.image_files.save(image=Image.new("RGB", (8, 8)), image_name=name)+++def _wait(client: TestClient, token: str, operation_id: str) -> dict:+ import time++ deadline = time.monotonic() + 10+ while time.monotonic() < deadline:+ response = client.get(f"/api/v1/intermediates/operations/{operation_id}", headers=_auth(token))+ assert response.status_code == 200, response.text+ body = response.json()+ if body["status"] in ("completed", "failed"):+ return body+ time.sleep(0.02)+ raise AssertionError("operation did not finish")+++def test_every_route_requires_authentication(enable_multiuser: Any, client: TestClient) -> None:+ assert client.get("/api/v1/intermediates/summary").status_code == status.HTTP_401_UNAUTHORIZED+ assert (+ client.post("/api/v1/intermediates/previews", json={"mode": "safe", "scope": {"kind": "everyone"}}).status_code+ == status.HTTP_401_UNAUTHORIZED+ )+ assert (+ client.post("/api/v1/intermediates/operations", json={"preview_id": "x", "idempotency_key": "k"}).status_code+ == status.HTTP_401_UNAUTHORIZED+ )+ assert client.get("/api/v1/intermediates/operations/x").status_code == status.HTTP_401_UNAUTHORIZED+ assert client.post("/api/v1/intermediates/operations/x/retry").status_code == status.HTTP_401_UNAUTHORIZED+++def test_non_admins_see_only_their_rows_and_cannot_widen_scope(+ storage_ready: None, mock_invoker: Invoker, client: TestClient, user1_token: str, user2_token: str+) -> None:+ _seed_intermediate(mock_invoker, "u1.png", _user_id(mock_invoker, "[email protected]"))+ _seed_intermediate(mock_invoker, "u2.png", _user_id(mock_invoker, "[email protected]"))++ summary = client.get("/api/v1/intermediates/summary", headers=_auth(user1_token))+ assert summary.status_code == 200+ assert [row["user_id"] for row in summary.json()["items"]] == [_user_id(mock_invoker, "[email protected]")]+ assert summary.json()["can_manage_everyone"] is False++ other = _user_id(mock_invoker, "[email protected]")+ assert (+ client.get("/api/v1/intermediates/summary", params={"owner_id": other}, headers=_auth(user1_token)).status_code+ == status.HTTP_403_FORBIDDEN+ )+ for scope in ({"kind": "everyone"}, {"kind": "owner", "user_id": other}):+ response = client.post(+ "/api/v1/intermediates/previews", json={"mode": "safe", "scope": scope}, headers=_auth(user1_token)+ )+ assert response.status_code == status.HTTP_403_FORBIDDEN, response.text+ forged = client.post(+ "/api/v1/intermediates/previews",+ json={"mode": "safe", "scope": {"kind": "selection", "targets": [{"user_id": other, "project_id": None}]}},+ headers=_auth(user1_token),+ )+ assert forged.status_code == status.HTTP_403_FORBIDDEN+ malformed = client.post(+ "/api/v1/intermediates/previews",+ json={"mode": "safe", "scope": {"kind": "owner"}},+ headers=_auth(user1_token),+ )+ assert malformed.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT+++def test_preview_operation_and_retry_flow(+ storage_ready: None, mock_invoker: Invoker, client: TestClient, user1_token: str, user2_token: str, admin_token: str+) -> None:+ user1 = _user_id(mock_invoker, "[email protected]")+ _seed_intermediate(mock_invoker, "u1.png", user1)++ preview = client.post(+ "/api/v1/intermediates/previews",+ json={"mode": "safe", "scope": {"kind": "owner", "user_id": user1}},+ headers=_auth(user1_token),+ )+ assert preview.status_code == status.HTTP_201_CREATED, preview.text+ assert preview.json()["impact"]["delete_images"] == 1+ preview_id = preview.json()["preview_id"]++ stolen = client.post(+ "/api/v1/intermediates/operations",+ json={"preview_id": preview_id, "idempotency_key": "k"},+ headers=_auth(user2_token),+ )+ assert stolen.status_code == status.HTTP_404_NOT_FOUND++ started = client.post(+ "/api/v1/intermediates/operations",+ json={"preview_id": preview_id, "idempotency_key": "k"},+ headers=_auth(user1_token),+ )+ assert started.status_code == status.HTTP_202_ACCEPTED, started.text+ operation_id = started.json()["operation_id"]+ repeated = client.post(+ "/api/v1/intermediates/operations",+ json={"preview_id": preview_id, "idempotency_key": "k"},+ headers=_auth(user1_token),+ )+ assert repeated.status_code == status.HTTP_202_ACCEPTED and repeated.json()["operation_id"] == operation_id++ finished = _wait(client, user1_token, operation_id)+ assert finished["status"] == "completed"+ assert finished["progress"]["deleted_images"] == 1++ assert (+ client.get(f"/api/v1/intermediates/operations/{operation_id}", headers=_auth(user2_token)).status_code+ == status.HTTP_404_NOT_FOUND+ )+ assert client.get(f"/api/v1/intermediates/operations/{operation_id}", headers=_auth(admin_token)).status_code == 200+ nothing_to_retry = client.post(f"/api/v1/intermediates/operations/{operation_id}/retry", headers=_auth(user1_token))+ assert nothing_to_retry.status_code == status.HTTP_409_CONFLICT+++def test_mutations_are_refused_during_image_storage_maintenance(+ storage_ready: None, mock_invoker: Invoker, client: TestClient, user1_token: str+) -> None:+ user1 = _user_id(mock_invoker, "[email protected]")+ preview = client.post(+ "/api/v1/intermediates/previews",+ json={"mode": "safe", "scope": {"kind": "owner", "user_id": user1}},+ headers=_auth(user1_token),+ )+ mock_invoker.services.image_moves.is_maintenance_active.return_value = True++ started = client.post(+ "/api/v1/intermediates/operations",+ json={"preview_id": preview.json()["preview_id"], "idempotency_key": "k"},+ headers=_auth(user1_token),+ )+ assert started.status_code == status.HTTP_409_CONFLICT+ assert started.json()["detail"] == "Image storage maintenance is active"+++def test_legacy_clear_keeps_its_shape_and_the_safety_policy(+ storage_ready: None, mock_invoker: Invoker, client: TestClient, user1_token: str, admin_token: str+) -> None:+ user1 = _user_id(mock_invoker, "[email protected]")+ _seed_intermediate(mock_invoker, "safe.png", user1)+ _seed_intermediate(mock_invoker, "referenced.png", user1)+ mock_invoker.services.project_records.create(user1, "P", {"imageName": "referenced.png"})++ assert client.get("/api/v1/images/intermediates", headers=_auth(user1_token)).json() == 2+ assert (+ client.delete("/api/v1/images/intermediates", headers=_auth(user1_token)).status_code+ == status.HTTP_403_FORBIDDEN+ )++ cleared = client.delete("/api/v1/images/intermediates", headers=_auth(admin_token))+ assert cleared.status_code == 200+ assert cleared.json() == 1+ assert client.get("/api/v1/images/intermediates", headers=_auth(user1_token)).json() == 1diff --git a/tests/app/test_intermediates_socketio.py b/tests/app/test_intermediates_socketio.pynew file mode 100644index 0000000000..ebfefce758--- /dev/null+++ b/tests/app/test_intermediates_socketio.py@@ -0,0 +1,81 @@+"""Intermediates cleanup events reach the confirming account and admins, and nobody else."""++from datetime import datetime, timezone+from types import SimpleNamespace+from unittest.mock import AsyncMock++import pytest+from fastapi import FastAPI++from invokeai.app.api.sockets import SocketIO+from invokeai.app.services.events.events_common import IntermediatesOperationChangedEvent+from invokeai.app.services.intermediates.intermediates_common import (+ IntermediatesOperation,+ IntermediatesOperationProgress,+ IntermediatesScope,+)+++def anyio_backend() -> str:+ return "asyncio"+++def _patch_multiuser(monkeypatch: pytest.MonkeyPatch, enabled: bool) -> None:+ invoker = SimpleNamespace(services=SimpleNamespace(configuration=SimpleNamespace(multiuser=enabled)))+ monkeypatch.setattr("invokeai.app.api.dependencies.ApiDependencies", SimpleNamespace(invoker=invoker))+++def _event() -> IntermediatesOperationChangedEvent:+ return IntermediatesOperationChangedEvent.build(+ IntermediatesOperation(+ operation_id="op-1",+ user_id="user-1",+ mode="safe",+ scope=IntermediatesScope(kind="owner", user_id="user-1"),+ status="running",+ created_at=datetime.now(timezone.utc),+ target_images=3,+ target_videos=0,+ progress=IntermediatesOperationProgress(),+ )+ )+++async def _route(monkeypatch: pytest.MonkeyPatch, multiuser: bool) -> list:+ socketio = SocketIO(FastAPI())+ socketio._sio.emit = AsyncMock()+ _patch_multiuser(monkeypatch, multiuser)+ event = _event()++ await socketio._handle_intermediates_event((event.__event_name__, event))++ return [call.kwargs for call in socketio._sio.emit.await_args_list]+++def test_the_event_is_registered_with_the_socket_handler() -> None:+ SocketIO(FastAPI())++ from fastapi_events.handlers.local import local_handler++ assert any(+ getattr(handler, "__func__", handler).__name__ == "_handle_intermediates_event"+ for handler in local_handler._registry.get("intermediates_operation_changed", [])+ )+++async def test_single_user_events_go_to_the_admin_room(monkeypatch: pytest.MonkeyPatch) -> None:+ emits = await _route(monkeypatch, multiuser=False)++ assert [emit["room"] for emit in emits] == ["admin"]+ assert emits[0]["event"] == "intermediates_operation_changed"+ assert emits[0]["data"]["operation"]["operation_id"] == "op-1"+++async def test_multiuser_events_reach_the_confirming_account_and_admins(monkeypatch: pytest.MonkeyPatch) -> None:+ emits = await _route(monkeypatch, multiuser=True)++ assert len(emits) == 1+ assert emits[0]["room"] == ["user:user-1", "admin"]