feat(dingtalk): per-frame wide-table grouping (stream keeps tables flowing while streaming)

This commit is contained in:
hermes
2026-09-18 11:55:45 +08:00
parent 92324b4242
commit dd229ec0ad
6 changed files with 117 additions and 50 deletions
+16 -12
View File
@@ -6,18 +6,22 @@ import (
"strings"
)
// cardWideTableGroupingDisabled reports whether the DingTalk final-frame
// normalizer must stop rewriting over-wide answer tables into grouped lists.
// Disabling it keeps real tables in the card, which is what the operator wants
// now that the PC client renders wide-screen cards; clients that still cannot
// lay out wide tables need the grouping, so the default stays enabled.
// DINGTALK_CARD_WIDE_TABLE_GROUP=off disables it.
func cardWideTableGroupingDisabled() bool {
switch strings.ToLower(strings.TrimSpace(os.Getenv("DINGTALK_CARD_WIDE_TABLE_GROUP"))) {
case "off", "0", "false", "no":
log.Printf("DingTalk wide-table grouping disabled by configuration")
return true
// cardWideTableGroupingMode returns the configured handling of over-wide answer
// tables (see dingtalk.tableGroupingForMode):
//
// unset / on → grouped list on every frame (historical behaviour)
// off → real tables on every frame
// stream → grouped list while streaming, real table on the final frame
//
// The default stays "on" so an environment without the variable renders exactly
// as before; DINGTALK_CARD_WIDE_TABLE_GROUP selects the other modes.
func cardWideTableGroupingMode() string {
mode := strings.ToLower(strings.TrimSpace(os.Getenv("DINGTALK_CARD_WIDE_TABLE_GROUP")))
switch mode {
case "off", "0", "false", "no", "stream", "streaming", "partial":
log.Printf("DingTalk wide-table grouping mode=%s", mode)
return mode
default:
return false
return ""
}
}
+2 -2
View File
@@ -323,8 +323,8 @@ func main() {
ReasoningRouter: &dingTalkReasoningRouter{service: reasoningService},
LanguageResolver: settingsRuntime.repository,
OutboundRewriteTimeout: outboundImages.rewriteTimeout,
WideTableGroupingDisabled: cardWideTableGroupingDisabled(),
OutboundRewriteTimeout: outboundImages.rewriteTimeout,
WideTableGrouping: cardWideTableGroupingMode(),
},
)
if err != nil {
+12 -8
View File
@@ -215,18 +215,22 @@ func TestOutboundImageBudgetAndCompressionDefaults(t *testing.T) {
}
}
func TestCardWideTableGroupingDisabledToggle(t *testing.T) {
func TestCardWideTableGroupingMode(t *testing.T) {
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", "")
if cardWideTableGroupingDisabled() {
t.Fatal("wide-table grouping must default to enabled")
if got := cardWideTableGroupingMode(); got != "" {
t.Fatalf("unset must keep the historical mode, got %q", got)
}
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", "off")
if !cardWideTableGroupingDisabled() {
t.Fatal("DINGTALK_CARD_WIDE_TABLE_GROUP=off must disable wide-table grouping")
if got := cardWideTableGroupingMode(); got != "off" {
t.Fatalf("off must be passed through, got %q", got)
}
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", "ON")
if cardWideTableGroupingDisabled() {
t.Fatal("any value other than off must keep grouping enabled")
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", " STREAM ")
if got := cardWideTableGroupingMode(); got != "stream" {
t.Fatalf("stream must be normalised, got %q", got)
}
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", "on")
if got := cardWideTableGroupingMode(); got != "" {
t.Fatalf("on is the default and must not be forwarded as a mode, got %q", got)
}
}