Track pasted images and videos in the current conversation.
MediaTracker(
self,
)Add a media item and return its placeholder text.
Add an image and return its placeholder text.
Add a video and return its placeholder text.
Get all tracked images.
Get all tracked videos.
Clear all tracked media and reset counters.
Return an independent copy of the currently tracked media.
Replace current media state with an independent snapshot copy.
Retain only media still referenced by placeholders in current text.
Re-map tracked placeholder spans onto a transformed copy of the text.
Submission rewrites the draft before the display placeholders are
stripped from the model-facing text: whitespace is trimmed, collapsed
pastes expand back to full content, dropped paths become placeholders,
and a mode prefix may be prepended. Every one of those shifts character
offsets, so a placeholder_span captured against the draft would be
stale by the time strip_media_placeholders consumes it — silently
stripping the wrong occurrence when a user-typed duplicate is present.
Re-mapping each span through the same before/after diff keeps it pointing
at its own display token in text. Spans that cannot be cleanly mapped
become None, degrading to the token-count fallback rather than a wrong
strip.