Skip to main content

Module render

Module render 

Source
Expand description

Renders a session’s live AgentEvent stream into platform messages.

Two rendering modes, chosen from platform.capabilities().edit_message:

  • Legacy (issue #452 MVP): tool-use one-liners and the final assistant text are each sent as separate messages.
  • Streaming edit-in-place (issue #458 phase 2): one status message per run, throttled-edited as tool lines/tokens arrive, replaced by a ✅/❌/⏹ final edit (or a short “done” edit + chunked follow-up when the final text doesn’t fit a single message).

Both modes stop at the same three terminal AgentEvents (Complete/Cancelled/Error) — the phase-1 termination contract — and BOTH now also stop at AgentEvent::NeedClarification, returning RunOutcome::Paused instead of continuing to wait for a terminal event that will never come while the run is genuinely suspended on a pending question. The bridge (bridge::ConnectBridge::render_until_settled) is responsible for turning a Paused outcome into a rendered ask (connect::approvals) and, once answered, calling stream_execution again on the resumed run’s stream.

Structs§

PendingAsk
The pause-worthy subset of AgentEvent::NeedClarification’s fields, decoupled from the wire event so connect::approvals doesn’t need to match on AgentEvent itself.
StreamState
Opaque carrier for the streaming renderer’s state across a pause/resume boundary (see RunOutcome::Paused::stream_state). Fields are private — callers only thread it through, they never inspect it.

Enums§

RunOutcome
What a live run’s event stream settled into.

Constants§

MAX_MESSAGE_CHARS
Telegram’s hard message-length limit (in UTF-16 characters, but ASCII/most text is 1 UTF-8 char == 1 unit; treating it as a char-count chunk size is a safe, conservative approximation other adapters can share too).

Functions§

chunk_message
Split text into chunks of at most limit characters (not bytes), so a multi-byte UTF-8 sequence is never split mid-codepoint. Returns an empty vec for empty input (callers should skip sending in that case).
stream_execution
Consume rx until a terminal AgentEvent or a pause, rendering into platform as it goes. Dispatches to the streaming edit-in-place mode when platform.capabilities().edit_message, else the legacy per-message mode (issue #452’s original behavior, preserved verbatim for adapters that can’t edit).