e2b46faa05
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.
52 lines
2.6 KiB
Go
52 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/channels/dingtalk"
|
|
)
|
|
|
|
// cardPartialUpdatesMode returns the configured card delivery mode for a
|
|
// finished answer (see dingtalk.CardPartialUpdatesMode):
|
|
//
|
|
// unset / on / partial → placeholder card + throttled partial frames (historical)
|
|
// off / final → placeholder card, and only the finished answer
|
|
// direct → no placeholder card; one card with the finished answer
|
|
//
|
|
// The default stays "partial" so an environment without the variable behaves
|
|
// exactly as before; DINGTALK_CARD_PARTIAL_UPDATES selects the other modes. The
|
|
// resolved mode is logged so the startup log always states what is running.
|
|
func cardPartialUpdatesMode() dingtalk.CardPartialUpdatesMode {
|
|
mode := dingtalk.ParseCardPartialUpdatesMode(os.Getenv("DINGTALK_CARD_PARTIAL_UPDATES"))
|
|
log.Printf("DingTalk card partial updates mode=%s", mode)
|
|
return mode
|
|
}
|
|
|
|
// cardFinalWriteMode returns the configured terminal-write mode for a finished
|
|
// answer (see dingtalk.CardFinalWriteMode):
|
|
//
|
|
// 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) 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
|
|
// replayed character by character - and a client that is not in the foreground
|
|
// pauses that animation, which reads as "streaming stopped, it continues when I
|
|
// switch back". The default stays "streaming" so an environment without the
|
|
// variable behaves exactly as before; DINGTALK_CARD_FINAL_WRITE selects the other
|
|
// mode. The resolved mode is logged so the startup log always states what ran.
|
|
func cardFinalWriteMode() dingtalk.CardFinalWriteMode {
|
|
mode := dingtalk.ParseCardFinalWriteMode(os.Getenv("DINGTALK_CARD_FINAL_WRITE"))
|
|
log.Printf("DingTalk card final write mode=%s", mode)
|
|
return mode
|
|
}
|