buildToolCallFromRaw 尝试把 内的纯文本解析成 ToolCall。 失败时返回 nil(让上层决定是否作为文本回吐)。
(raw string)
| 164 | // buildToolCallFromRaw 尝试把 <tool_call> 内的纯文本解析成 ToolCall。 |
| 165 | // 失败时返回 nil(让上层决定是否作为文本回吐)。 |
| 166 | func buildToolCallFromRaw(raw string) *official.ToolCall { |
| 167 | s := strings.TrimSpace(raw) |
| 168 | if s == "" { |
| 169 | return nil |
| 170 | } |
| 171 | // 去掉 markdown 围栏 |
| 172 | s = stripMarkdownFence(s) |
| 173 | idx := strings.Index(s, "{") |
| 174 | if idx < 0 { |
| 175 | return nil |
| 176 | } |
| 177 | s = s[idx:] |
| 178 | obj, ok := robustJSON(s) |
| 179 | if !ok { |
| 180 | return nil |
| 181 | } |
| 182 | return buildToolCallFromObject(obj) |
| 183 | } |
| 184 | |
| 185 | func stripMarkdownFence(s string) string { |
| 186 | s = fenceOpenRe.ReplaceAllString(s, "") |
no test coverage detected