fix(outbound): keep single-run answers whole and show formulas

The DingTalk binding can point at the quick-answer agent, which publishes the
whole answer as one answer run plus tool_call/tool_result steps. The narration
boundary was rejected for that shape (start=0), so the text-only heuristic ran
and dropped the answer lead-in together with its image.

- answer_observation: a single answer run means there is no narration to cut.
- outboundtext: rewrite LaTeX formulas into plain Unicode text, because
  DingTalk cards render no math typesetting (r = sqrt(X^2 + Y^2) -> r = √(X² + Y²)).
- dingtalk handler: normalize formulas on both the partial and final card paths.
This commit is contained in:
姚章浩
2026-09-18 16:21:37 +08:00
parent dfce8cb9f6
commit 5ccaeb3b96
8 changed files with 439 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
package outboundtext
import "testing"
func TestNormalizeMath(t *testing.T) {
cases := []struct{ name, in, want string }{
{"inline sqrt", `$r = \sqrt{X^2 + Y^2}$`, `r = √(X² + Y²)`},
{"inline inside prose", `计算公式为 $r = \sqrt{X^2 + Y^2}$(单位:cm)`, `计算公式为 r = √(X² + Y²)(单位:cm)`},
{"block frac times", `$$\frac{a}{b} \times c$$`, "\n(a)/(b) × c\n"},
{"paren delimiters", `\(x \leq y\)`, `x ≤ y`},
{"bracket delimiters", `\[ \sum_{i=1}^{n} x_i \]`, ` Σᵢ₌₁ⁿ xᵢ `},
{"nth root", `$\sqrt[3]{V}$`, `√[3](V)`},
{"no math untouched", `C:\new\folder 与 100% 覆盖`, `C:\new\folder 与 100% 覆盖`},
{"dollar free prose", `价格是 5 元, 无公式`, `价格是 5 元, 无公式`},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := NormalizeMath(tc.in)
if got != tc.want {
t.Fatalf("NormalizeMath(%q) = %q, want %q", tc.in, got, tc.want)
}
if again := NormalizeMath(got); again != got {
t.Fatalf("NormalizeMath is not idempotent: %q -> %q", got, again)
}
})
}
}
func TestNormalizeMathKeepsPlainMarkdown(t *testing.T) {
plain := "### 标题\n\n- 项目一\n- 项目二\n\n普通段落,没有公式。"
if got := NormalizeMath(plain); got != plain {
t.Fatalf("plain markdown changed: %q", got)
}
}