Draft: Persist rich tool displays with htmltools - #316
Draft
cpsievert wants to merge 3 commits into
Draft
Conversation
cpsievert
force-pushed
the
draft/use-htmltools-serialized-html
branch
from
August 14, 2026 17:10
a684b12 to
cb12177
Compare
Base automatically changed from
refactor/python-tool-display-json-fallback
to
main
August 14, 2026 17:20
gadenbuie
force-pushed
the
draft/use-htmltools-serialized-html
branch
from
August 14, 2026 17:20
cb12177 to
1246209
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this matters
The immediate serialization fix deliberately keeps shinychat's existing dependency dictionaries so it can ship without waiting for another package release. Those dictionaries are suitable for the browser, but they omit the dependency source needed to register local CSS and JavaScript in a later session.
With the
RenderedHTMLvalue object proposed in posit-dev/py-htmltools#123, the result ofrender()owns its source-preserving durable representation. Shinychat can use that public boundary instead of maintaining a parallel dependency schema.What changes
htmltools.serialize_html(), the convenience API overRenderedHTML.to_serialized().htmltools.deserialize_html().RenderedHTMLthrough its public constructor so the code works with both the current TypedDict and the proposed value object.Compatibility
Old records remain readable. Their HTML and previously resolved dependency URLs are preserved, but local sources cannot be recovered because older shinychat versions did not store them. Once an old value is loaded and written again, it uses the new schema.
Verification
uv run --no-sync pytest -q --ignore=pkg-py/tests/playwright(431 passed)/lib/my-dep-1.0.uv run --no-sync ruff check pkg-py --config pyproject.tomluv run --no-sync pyrightThe repository-wide Ruff format check still reports the inherited formatting difference in
pkg-py/tests/playwright/chat/aside_responsive/test_aside_responsive.py.Before marking ready
uv.lockand verifyuv sync --all-extrasfrom the package index.mainafter Fix Python tool-result display serialization #297 and Refine Python tool-result display serialization #315 merge.