fix(dingtalk): keep streaming frames growing while a table forms

A table that starts forming made stableMarkdownPrefix truncate every
streaming frame at the table start, so the card froze and the whole table
plus tail arrived in the single finalize frame (live: 5.2 KB dump after the
answer had already finished upstream).

Add the DINGTALK_CARD_WIDE_TABLE_GROUP=smooth mode: over-wide tables are
grouped on every frame (as "on") and, while streaming, every table is
grouped so no table block survives into a partial frame. The final frame
keeps the real table whenever it lays out safely.
This commit is contained in:
hermes
2026-09-20 10:07:55 +08:00
parent 1bbaf2f07a
commit 30a95ef08a
6 changed files with 109 additions and 18 deletions
+12 -6
View File
@@ -169,10 +169,12 @@ type HandlerOptions struct {
// delivery timeout, otherwise the remaining images are dropped. Zero keeps
// finalDeliveryTimeout.
OutboundRewriteTimeout time.Duration
// WideTableGrouping selects how over-wide answer tables are adapted, per
// frame: "" or "on" groups on every frame (historical), "off" never groups,
// "stream" groups only while the answer is still streaming and keeps the
// real table on the final frame. See tableGroupingForMode.
// WideTableGrouping selects how answer tables are adapted, per frame: ""
// or "on" groups over-wide tables on every frame (historical), "off" never
// groups, "stream" groups only while the answer is still streaming and
// keeps the real table on the final frame, "smooth" also groups every
// table on streaming frames so a forming table never freezes the card.
// See tableGroupingForMode.
WideTableGrouping string
}
@@ -201,6 +203,9 @@ type Handler struct {
// keep the real table, which the PC wide-screen card lays out itself.
groupTablesPartial bool
groupTablesFinal bool
// groupAllTablesPartial groups every table on streaming frames (mode
// "smooth"): the card keeps growing while a table is still forming.
groupAllTablesPartial bool
}
// NewHandler accepts at most one image downloader. A nil/omitted downloader
@@ -232,7 +237,7 @@ func NewHandlerWithOptions(cfg TenantConfig, qa QAAsker, reply MarkdownSender, o
if reply == nil {
return nil, errors.New("dingtalk handler: markdown sender is required")
}
groupPartial, groupFinal := tableGroupingForMode(opts.WideTableGrouping)
groupPartial, groupFinal, groupAllPartial := tableGroupingForMode(opts.WideTableGrouping)
return &Handler{
cfg: cfg,
@@ -254,6 +259,7 @@ func NewHandlerWithOptions(cfg TenantConfig, qa QAAsker, reply MarkdownSender, o
outboundRewriteTimeout: opts.OutboundRewriteTimeout,
groupTablesPartial: groupPartial,
groupTablesFinal: groupFinal,
groupAllTablesPartial: groupAllPartial,
}, nil
}
@@ -699,7 +705,7 @@ func (h *Handler) sanitizeOutboundPartial(ctx context.Context, content string) s
if ok {
content = sanitizer.SanitizePartial(content)
}
options := tableNormalizeOptions{groupWideTables: h.groupTablesPartial}
options := tableNormalizeOptions{groupWideTables: h.groupTablesPartial, groupAllTables: h.groupAllTablesPartial}
content = normalizeMarkdownTables(sanitizeDisplayAnswer(content), options)
return h.rewriteCardImages(ctx, stableMarkdownPrefix(content), false)
}