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:
@@ -17,6 +17,11 @@ type tableNormalizeOptions struct {
|
||||
// lists (bold row heading + "- header:value" lines). Disable it when the
|
||||
// client lays out wide tables itself, so the answer keeps its real table.
|
||||
groupWideTables bool
|
||||
// groupAllTables rewrites every table into a grouped list, compact ones
|
||||
// included. Streaming frames use it so a table that is still forming never
|
||||
// freezes the card; the final frame keeps the real table whenever it lays
|
||||
// out safely.
|
||||
groupAllTables bool
|
||||
}
|
||||
|
||||
func defaultTableNormalizeOptions() tableNormalizeOptions {
|
||||
@@ -30,14 +35,19 @@ func defaultTableNormalizeOptions() tableNormalizeOptions {
|
||||
// ""/"on" group on every frame
|
||||
// "off" never group: real tables everywhere
|
||||
// "stream" group while streaming, real table on the final frame
|
||||
func tableGroupingForMode(mode string) (partial, final bool) {
|
||||
// "smooth" group on every frame and group every table (compact ones too)
|
||||
// while streaming, so a table forming mid-answer keeps the card
|
||||
// growing instead of freezing it until the final frame
|
||||
func tableGroupingForMode(mode string) (partial, final, allPartial bool) {
|
||||
switch strings.ToLower(strings.TrimSpace(mode)) {
|
||||
case "off", "0", "false", "no":
|
||||
return false, false
|
||||
return false, false, false
|
||||
case "stream", "streaming", "partial":
|
||||
return true, false
|
||||
return true, false, false
|
||||
case "smooth":
|
||||
return true, true, true
|
||||
default:
|
||||
return true, true
|
||||
return true, true, false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +108,7 @@ func normalizeTableBlock(rows []markdownStreamLine, options tableNormalizeOption
|
||||
}
|
||||
}
|
||||
header := cells[0]
|
||||
if maxWidth <= maxTableCellVisualWidth || !options.groupWideTables {
|
||||
if !options.groupAllTables && (maxWidth <= maxTableCellVisualWidth || !options.groupWideTables) {
|
||||
// Compact tables keep their exact original bytes unless a cell carries
|
||||
// <br>, which the card renderer mishandles inside cells. The same path
|
||||
// serves over-wide tables when grouping is disabled: the table stays a
|
||||
|
||||
Reference in New Issue
Block a user