From 056870464ab77dff01ccbc7a484db27174c4a0d8 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Mon, 27 Apr 2026 19:25:20 +0200 Subject: [PATCH] Accept optional user_images on regenerate and apply them when resolving the model turn. --- surfsense_backend/app/routes/new_chat_routes.py | 3 +++ surfsense_backend/app/schemas/new_chat.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/surfsense_backend/app/routes/new_chat_routes.py b/surfsense_backend/app/routes/new_chat_routes.py index 854627d4b..cbc660222 100644 --- a/surfsense_backend/app/routes/new_chat_routes.py +++ b/surfsense_backend/app/routes/new_chat_routes.py @@ -1456,6 +1456,9 @@ async def regenerate_response( user_query_to_use ) + if request.user_images is not None: + regenerate_image_urls = [p.as_data_url() for p in request.user_images] + if user_query_to_use is None: raise HTTPException( status_code=400, diff --git a/surfsense_backend/app/schemas/new_chat.py b/surfsense_backend/app/schemas/new_chat.py index e757ce178..477fdf2ca 100644 --- a/surfsense_backend/app/schemas/new_chat.py +++ b/surfsense_backend/app/schemas/new_chat.py @@ -238,6 +238,9 @@ class RegenerateRequest(BaseModel): 2. Reload: Leave user_query empty to regenerate the last AI response with the same query Both operations rewind the LangGraph checkpointer to the appropriate state. + + For edit, optional user_images (when not None) replaces image URLs resolved from + checkpoint/DB so the client can send the full user turn (text and/or images). """ search_space_id: int @@ -250,6 +253,16 @@ class RegenerateRequest(BaseModel): filesystem_mode: Literal["cloud", "desktop_local_folder"] = "cloud" client_platform: Literal["web", "desktop"] = "web" local_filesystem_mounts: list[LocalFilesystemMountPayload] | None = None + user_images: list[NewChatUserImagePart] | None = Field( + default=None, + description="If set, use these images for the regenerated turn (edit); overrides checkpoint/DB", + ) + + @model_validator(mode="after") + def _validate_regenerate_user_images(self) -> Self: + if self.user_images is not None and len(self.user_images) > MAX_NEW_CHAT_IMAGES: + raise ValueError(f"At most {MAX_NEW_CHAT_IMAGES} images allowed") + return self # =============================================================================