feat(dingtalk): deliver the finished answer as a single card

DINGTALK_CARD_PARTIAL_UPDATES selects how much of an answer is written into
the card while it is still being produced:

  partial (default, unset) - placeholder card plus throttled partial answer
                            and progress frames, then the final update
  final                   - placeholder card, no partial frames at all; the
                            finished answer lands in the single final update
  direct                  - no placeholder card; one card with the answer

Both non-default modes drop the 500ms redraw pump for the turn, so the card
only ever shows content that is actually final. handleNonStreaming and the
two new modes share one delivery helper, and the markdown fallback keeps the
existing behaviour when the card cannot be delivered.
This commit is contained in:
姚章浩
2026-09-20 10:48:36 +08:00
parent 30a95ef08a
commit 341b7e3990
7 changed files with 422 additions and 8 deletions
+24
View File
@@ -0,0 +1,24 @@
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
}
+31
View File
@@ -0,0 +1,31 @@
package main
import (
"testing"
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/channels/dingtalk"
)
func TestCardPartialUpdatesMode(t *testing.T) {
tests := []struct {
name string
raw string
want dingtalk.CardPartialUpdatesMode
}{
{"unset keeps streaming", "", dingtalk.CardPartialUpdatesPartial},
{"on keeps streaming", "on", dingtalk.CardPartialUpdatesPartial},
{"partial keeps streaming", "PARTIAL", dingtalk.CardPartialUpdatesPartial},
{"unknown keeps streaming", "hammer", dingtalk.CardPartialUpdatesPartial},
{"final", " final ", dingtalk.CardPartialUpdatesFinal},
{"off maps to final", "off", dingtalk.CardPartialUpdatesFinal},
{"direct", "direct", dingtalk.CardPartialUpdatesDirect},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("DINGTALK_CARD_PARTIAL_UPDATES", tt.raw)
if got := cardPartialUpdatesMode(); got != tt.want {
t.Fatalf("cardPartialUpdatesMode(%q)=%q want %q", tt.raw, got, tt.want)
}
})
}
}
+1
View File
@@ -325,6 +325,7 @@ func main() {
OutboundRewriteTimeout: outboundImages.rewriteTimeout,
WideTableGrouping: cardWideTableGroupingMode(),
PartialUpdates: cardPartialUpdatesMode(),
},
)
if err != nil {