diff --git a/chatlas/_content.py b/chatlas/_content.py index b8b17b65..2243343e 100644 --- a/chatlas/_content.py +++ b/chatlas/_content.py @@ -18,6 +18,8 @@ from ._typing_extensions import TypedDict if TYPE_CHECKING: + from htmltools import Tagified + from ._tools import Tool, ToolBuiltIn @@ -316,7 +318,7 @@ def _format_arg(value: object) -> str: def _repr_html_(self) -> str: return str(self.tagify()) - def tagify(self): + def tagify(self) -> Tagified: "Returns an HTML string suitable for passing to htmltools/shiny's `Chat()` component." try: from htmltools import HTML, TagList, head_content, tags @@ -331,7 +333,7 @@ def tagify(self): return TagList( HTML(html), head_content(tags.style(TOOL_CSS)), - ) + ).tagify() class ContentToolResult(Content): @@ -523,7 +525,7 @@ def _to_json(value: Any) -> object: def _repr_html_(self): return str(self.tagify()) - def tagify(self): + def tagify(self) -> Tagified: "A method for rendering this object via htmltools/shiny." try: from htmltools import HTML, html_escape @@ -694,7 +696,7 @@ def __str__(self): def _repr_html_(self): return str(self.tagify()) - def tagify(self): + def tagify(self) -> Tagified: try: from htmltools import HTML except ImportError: diff --git a/pyproject.toml b/pyproject.toml index 9b9ab8d7..004c536e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ dev = [ "matplotlib", "Pillow", "shiny", - "htmltools", + "htmltools>=0.7.0;python_version>='3.10'", "shinychat", "narwhals", "pandas", @@ -208,3 +208,11 @@ skip-magic-trailing-comma = false line-ending = "auto" docstring-code-format = true docstring-code-line-length = "dynamic" + + +# TODO(htmltools-105): remove this source override before merging. +# Pins htmltools to the PR branch that adds the `Tagified` alias +# (posit-dev/py-htmltools#106). Flip back to the released htmltools +# once it ships. +[tool.uv.sources] +htmltools = { git = "https://github.com/posit-dev/py-htmltools.git", branch = "main" }