Image tools: work around OWUI 0.9.x files-event regression

Open WebUI 0.9.0 introduced chat-history virtualization that
unmounts off-screen assistant messages and reconstructs them from
persisted shape; `files` attached mid-stream by a tool don't
survive the round-trip — the image flashes in during streaming
and disappears the moment the message commits.

Both image tools now upload via Open WebUI's file store as before
but surface the result as a markdown image injected into the
assistant message via a `message` event, which is part of the
persisted shape and renders reliably across remounts. Trade-off:
loses the file-attachment chrome (thumbnail + download button).
Each tool has a TODO marking the swap site with the original
`files` payload inlined for one-line revert once upstream fixes
the regression.

smart_image_gen.py 0.7.8 -> 0.7.9
smart_image_pipe.py 0.1.0 -> 0.1.1

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-26 06:05:12 -05:00
co-authored by Claude Opus 4.7
parent 28f370a80b
commit d034700af9
2 changed files with 51 additions and 15 deletions
@@ -1,7 +1,7 @@
"""
title: Smart Image Studio (Pipe)
author: ai-stack
version: 0.1.0
version: 0.1.1
description: Deterministic image-gen / edit / inpaint pipe — no LLM in the
loop for the routing decision. Registers as a model in the chat-model
dropdown ('Image Studio (Pipe)'). Reads the user's message + attached
@@ -420,9 +420,23 @@ async def _push_image_to_chat(raw, prefix, request, user_dict, metadata, event_e
)
file_item = await result if inspect.iscoroutine(result) else result
url = request.app.url_path_for("get_file_content_by_id", id=file_item.id)
# TODO(open-webui virtualization fix): once chat-history
# virtualization survives `files` events from tool calls again,
# swap back to the `files` payload below. The `files` event
# gives proper file-attachment chrome (thumbnail card + download
# button) that the markdown-image path lacks. Verify the fix by
# emitting `files`, then refreshing the page AND scrolling the
# message off-screen and back — both must keep the image
# visible. Track upstream: github.com/open-webui/open-webui
# release notes mentioning tool calls, `files` events, or
# virtualization. To restore, replace the block below with:
# await event_emitter({
# "type": "files",
# "data": {"files": [{"type": "image", "url": url}]},
# })
await event_emitter({
"type": "files",
"data": {"files": [{"type": "image", "url": url}]},
"type": "message",
"data": {"content": f"\n![{prefix}]({url})\n"},
})
return True
except Exception: