fix(translator): 工具输出与 custom input 解包的健壮性改进

采纳 review 意见:responsesToolOutputText 支持纯字符串数组元素,
避免非 content-parts 形态的输出被静默丢弃;unwrapCustomToolInput
在 input 为对象/数组时以原始 JSON 解包,不再仅限字符串。

Ref #4219
This commit is contained in:
辰ing
2026-07-12 20:39:56 +08:00
committed by Luis Pater
parent bd2aafb8fc
commit e9d3dfbce1
@@ -120,6 +120,10 @@ func responsesToolOutputText(output gjson.Result) string {
if output.IsArray() {
var b strings.Builder
output.ForEach(func(_, part gjson.Result) bool {
if part.Type == gjson.String {
b.WriteString(part.String())
return true
}
if text := part.Get("text"); text.Exists() {
b.WriteString(text.String())
}
@@ -168,8 +172,11 @@ func responsesCustomToolNames(requestRawJSON []byte) map[string]struct{} {
// function-call arguments produced for a converted custom tool; it falls back
// to the raw arguments when the wrapper is absent.
func unwrapCustomToolInput(arguments string) string {
if v := gjson.Get(arguments, "input"); v.Exists() && v.Type == gjson.String {
return v.String()
if v := gjson.Get(arguments, "input"); v.Exists() {
if v.Type == gjson.String {
return v.String()
}
return v.Raw
}
return arguments
}