Harvey DU 477c8e04ec
fix(feishu): keep a card's markdown image from failing every update (#8423)
* fix(feishu): keep a card's markdown image from failing every update

A card markdown element only renders a markdown image whose target is an
uploaded `image_key`. An answer that carries `![alt](url)` therefore made Feishu
reject the card with 230099 / 11310 ("the card contains images but no imagekey is
passed in"), and because the same card is patched for each streamed snapshot,
every later update failed too: the reply stopped at the text sent before the
image marker (#8407).

Rewrite the marker as a link before the card is built, which keeps the
reference and its target in a form the element renders. Fenced blocks and
inline code spans stay literal, since a card shows them as code and rewriting
what they contain would misreport the answer.

The rewrite only removes a character, so a card that already fit Feishu's
30 KB body limit still does.

* fix(feishu): rewrite the button card's text and stay literal in an open fence

Review follow-ups on the card markdown rewrite.

The clarification button card builds its own JSON and is delivered with
`raw_card_content=True`, so it never passed through `_build_card_content`: an
agent-authored question carrying `![alt](url)` would still be rejected with
230099 / 11310. `build_button_card` now applies the same rewrite to the text it
puts in its markdown element (imported inside the function, since feishu.py
imports that module).

A snapshot streamed before its closing fence arrives has an open block at the
end, and the closed-fence pattern did not see it, so a marker inside that block
was rewritten in the transient snapshot and then shown as a link in what had
been code. What follows an unterminated opener is now left literal.
2026-11-21 10:33:03 +08:00
..