chore: remove unused rendering paths

This commit is contained in:
banteg
2025-12-29 02:27:28 +04:00
parent a09d88ee14
commit b58af5517b
3 changed files with 1 additions and 67 deletions
@@ -133,7 +133,6 @@ def _maybe_parse_json(text: str) -> Optional[Any]:
@dataclass @dataclass
class ExecRenderState: class ExecRenderState:
items: dict[str, dict[str, Any]] = field(default_factory=dict)
recent_actions: deque[str] = field(default_factory=lambda: deque(maxlen=5)) recent_actions: deque[str] = field(default_factory=lambda: deque(maxlen=5))
current_action: Optional[str] = None current_action: Optional[str] = None
current_action_id: Optional[int] = None current_action_id: Optional[int] = None
@@ -145,7 +144,6 @@ class ExecRenderState:
def _record_item(state: ExecRenderState, item: dict[str, Any]) -> None: def _record_item(state: ExecRenderState, item: dict[str, Any]) -> None:
item_id = item.get("id") item_id = item.get("id")
if isinstance(item_id, (int, str)): if isinstance(item_id, (int, str)):
state.items[str(item_id)] = item
numeric_id = _extract_numeric_id(item_id) numeric_id = _extract_numeric_id(item_id)
if numeric_id is not None: if numeric_id is not None:
state.last_turn = numeric_id state.last_turn = numeric_id
@@ -186,7 +184,6 @@ def render_event_cli(
event: dict[str, Any], event: dict[str, Any],
state: ExecRenderState, state: ExecRenderState,
*, *,
show_reasoning: bool = False,
show_output: bool = False, show_output: bool = False,
) -> list[str]: ) -> list[str]:
etype = event.get("type") etype = event.get("type")
@@ -225,11 +222,6 @@ def render_event_cli(
lines.append("assistant:") lines.append("assistant:")
lines.extend(indent(text, " ").splitlines() if text else [" (empty)"]) lines.extend(indent(text, " ").splitlines() if text else [" (empty)"])
elif itype == "reasoning" and show_reasoning:
reasoning = _format_reasoning(item.get("text", ""))
if reasoning:
lines.append(reasoning)
elif itype == "command_execution": elif itype == "command_execution":
command = _format_command(item.get("command", "")) command = _format_command(item.get("command", ""))
if etype == "item.started": if etype == "item.started":
@@ -6,9 +6,6 @@ from typing import Any, Dict, List, Tuple
from markdown_it import MarkdownIt from markdown_it import MarkdownIt
from sulguk import transform_html from sulguk import transform_html
from .constants import DEFAULT_CHUNK_LEN
def render_markdown(md: str) -> Tuple[str, List[Dict[str, Any]]]: def render_markdown(md: str) -> Tuple[str, List[Dict[str, Any]]]:
html = MarkdownIt("commonmark", {"html": False}).render(md or "") html = MarkdownIt("commonmark", {"html": False}).render(md or "")
rendered = transform_html(html) rendered = transform_html(html)
@@ -25,41 +22,6 @@ def render_markdown(md: str) -> Tuple[str, List[Dict[str, Any]]]:
return text, entities return text, entities
def chunk_text(text: str, limit: int = DEFAULT_CHUNK_LEN) -> List[str]:
"""
Telegram hard limit is 4096 chars. Chunk at newlines when possible.
"""
text = text or ""
if len(text) <= limit:
return [text]
out: List[str] = []
buf: List[str] = []
size = 0
for line in text.splitlines(keepends=True):
if len(line) > limit:
# flush current buffer
if buf:
out.append("".join(buf))
buf, size = [], 0
# hard-split this long line
for i in range(0, len(line), limit):
out.append(line[i : i + limit])
continue
if size + len(line) > limit:
out.append("".join(buf))
buf, size = [line], len(line)
else:
buf.append(line)
size += len(line)
if buf:
out.append("".join(buf))
return out
def _chunk_text_with_indices(text: str, limit: int) -> List[Tuple[str, int, int]]: def _chunk_text_with_indices(text: str, limit: int) -> List[Tuple[str, int, int]]:
text = text or "" text = text or ""
if len(text) <= limit: if len(text) <= limit:
@@ -6,7 +6,7 @@ import urllib.request
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from .constants import DEFAULT_CHUNK_LEN, TELEGRAM_HARD_LIMIT from .constants import DEFAULT_CHUNK_LEN, TELEGRAM_HARD_LIMIT
from .rendering import chunk_text, render_markdown, _chunk_text_with_indices, _slice_entities from .rendering import render_markdown, _chunk_text_with_indices, _slice_entities
class TelegramClient: class TelegramClient:
@@ -103,26 +103,6 @@ class TelegramClient:
res = self._call("deleteMessage", params) res = self._call("deleteMessage", params)
return bool(res) return bool(res)
def send_message_chunked(
self,
chat_id: int,
text: str,
reply_to_message_id: Optional[int] = None,
disable_notification: bool = False,
chunk_len: int = DEFAULT_CHUNK_LEN,
) -> List[Dict[str, Any]]:
sent: List[Dict[str, Any]] = []
chunks = chunk_text(text, limit=chunk_len)
for i, c in enumerate(chunks):
msg = self.send_message(
chat_id=chat_id,
text=c,
reply_to_message_id=(reply_to_message_id if i == 0 else None),
disable_notification=disable_notification,
)
sent.append(msg)
return sent
def send_message_markdown_chunked( def send_message_markdown_chunked(
self, self,
chat_id: int, chat_id: int,