fix(dingtalk): 推理正文边界支持「首行即正文」并补齐卡片结构诊断
- BodyStartOffset:内容首个非空行即结构行时正文从头开始,避免收尾裁剪 把标题+首段一起删掉(118 条生产样本中 31 条、最多 526 字) - 语料回归守卫:隐藏前缀不得含结构行、上限 600 字;单测补 suffix 断言 - 卡片诊断新增 body_ok/body_line/body_prefix_runes/banner_pos/first_heading_line (定位流式残留推理末句,只看结构不看文本)
This commit is contained in:
@@ -3,8 +3,12 @@ package dingtalk
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/reasoningmode"
|
||||
)
|
||||
|
||||
const reasoningBannerMarker = "【智能推理模式】"
|
||||
|
||||
type cardContentShape struct {
|
||||
bytes int
|
||||
lines int
|
||||
@@ -13,20 +17,59 @@ type cardContentShape struct {
|
||||
delimiterLines int
|
||||
confirmedTable bool
|
||||
confirmedTablePos int
|
||||
// Structural split state: where the answer body starts inside this exact
|
||||
// payload. bodyPrefixRunes > 0 means the update still carries narration in
|
||||
// front of the body (the reasoning text the card is supposed to hide).
|
||||
bodyOK bool
|
||||
bodyLine int
|
||||
bodyPrefixRunes int
|
||||
bannerPos int
|
||||
firstHeadingLine int
|
||||
}
|
||||
|
||||
func inspectCardContent(content string) cardContentShape {
|
||||
shape := cardContentShape{
|
||||
bytes: len(content),
|
||||
confirmedTablePos: -1,
|
||||
bodyLine: -1,
|
||||
firstHeadingLine: -1,
|
||||
bannerPos: -1,
|
||||
}
|
||||
if content == "" {
|
||||
return shape
|
||||
}
|
||||
shape.lines = strings.Count(content, "\n") + 1
|
||||
|
||||
shape.bannerPos = strings.Index(content, reasoningBannerMarker)
|
||||
// The streaming path decorates every frame with the reasoning banner, so the
|
||||
// prefix in front of the body has to be measured after that banner: only
|
||||
// what remains is narration the card is meant to hide.
|
||||
bannerSkip := 0
|
||||
if shape.bannerPos == 0 {
|
||||
if idx := strings.Index(content, "\n"); idx >= 0 {
|
||||
bannerSkip = idx + 1
|
||||
for bannerSkip < len(content) && content[bannerSkip] == '\n' {
|
||||
bannerSkip++
|
||||
}
|
||||
}
|
||||
}
|
||||
if offset, ok := reasoningmode.BodyStartOffset(content); ok {
|
||||
shape.bodyOK = true
|
||||
shape.bodyLine = strings.Count(content[:offset], "\n")
|
||||
prefix := content[:offset]
|
||||
if bannerSkip > 0 && bannerSkip <= len(prefix) {
|
||||
prefix = prefix[bannerSkip:]
|
||||
}
|
||||
shape.bodyPrefixRunes = len([]rune(prefix))
|
||||
}
|
||||
|
||||
lines := splitMarkdownStreamLines(content)
|
||||
for i, line := range lines {
|
||||
trimmed := strings.TrimSpace(line.text)
|
||||
if shape.firstHeadingLine < 0 && !line.inFence &&
|
||||
strings.HasPrefix(trimmed, "#") && strings.TrimLeft(trimmed, "#") != "" {
|
||||
shape.firstHeadingLine = i
|
||||
}
|
||||
if strings.Contains(line.text, "|") {
|
||||
shape.pipeLines++
|
||||
}
|
||||
@@ -50,7 +93,7 @@ func inspectCardContent(content string) cardContentShape {
|
||||
func formatCardUpdateDiagnostic(content string, isFinalize, isError bool) string {
|
||||
shape := inspectCardContent(content)
|
||||
return fmt.Sprintf(
|
||||
"DingTalk card update shape: finalize=%t error=%t bytes=%d lines=%d pipe_lines=%d leading_pipe_lines=%d delimiter_lines=%d confirmed_table=%t table_start=%d",
|
||||
"DingTalk card update shape: finalize=%t error=%t bytes=%d lines=%d pipe_lines=%d leading_pipe_lines=%d delimiter_lines=%d confirmed_table=%t table_start=%d body_ok=%t body_line=%d body_prefix_runes=%d banner_pos=%d first_heading_line=%d",
|
||||
isFinalize,
|
||||
isError,
|
||||
shape.bytes,
|
||||
@@ -60,5 +103,10 @@ func formatCardUpdateDiagnostic(content string, isFinalize, isError bool) string
|
||||
shape.delimiterLines,
|
||||
shape.confirmedTable,
|
||||
shape.confirmedTablePos,
|
||||
shape.bodyOK,
|
||||
shape.bodyLine,
|
||||
shape.bodyPrefixRunes,
|
||||
shape.bannerPos,
|
||||
shape.firstHeadingLine,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user