feat(dingtalk): add card terminal-write order modes (refresh, close-refresh)

A DingTalk AI card replays streamed content with a typewriter animation the
client drives itself, so a finished answer can still be typed out character
by character - and a card that is not in the foreground pauses that replay.

DINGTALK_CARD_FINAL_WRITE now sequences the two terminal writes explicitly:

  streaming (default)  streaming finalize only (unchanged)
  update               finalize, then a plain write (observed to blank the card)
  refresh              plain write of the finished answer, then a zero-delta
                       finalize carrying the same text
  close-refresh        zero-delta finalize on the text the card already shows,
                       then a plain write of the finished answer

The sender remembers the text each live card shows so a terminal write can
close the stream with a frame the client has nothing to animate; a failing
plain write is logged and never fails the delivery.
This commit is contained in:
姚章浩
2026-09-20 18:15:04 +08:00
parent ba35e251be
commit e2b46faa05
4 changed files with 311 additions and 20 deletions
+7 -2
View File
@@ -29,8 +29,13 @@ func cardPartialUpdatesMode() dingtalk.CardPartialUpdatesMode {
// unset / streaming → the finished answer is written with the card streaming
// API and isFinalize=true (historical behaviour)
// update / plain → the same answer is written once more through the plain
// card update API (PUT /v1.0/card/instances), so the
// terminal content carries no client-side typewriter queue
// card update API (PUT /v1.0/card/instances) AFTER the
// streaming finalize (observed to blank the delivered card)
// refresh → the answer goes through the plain card update API FIRST
// and the stream is then closed with the very same text,
// so the client has no delta left to animate
// close-refresh → the stream is closed on the text the card already shows
// (zero delta) and the answer is refreshed afterwards
//
// DingTalk renders streamed card content with a typewriter animation the client
// drives itself, so an answer that is already complete on the server can still be