extractErrorString pulls the "error" field from a JSON object if present, returning it as a string. Returns "" if the field is missing or the input is not an object.
(raw json.RawMessage)
| 581 | // present, returning it as a string. Returns "" if the field is |
| 582 | // missing or the input is not an object. |
| 583 | func extractErrorString(raw json.RawMessage) string { |
| 584 | var fields map[string]json.RawMessage |
| 585 | if err := json.Unmarshal(raw, &fields); err != nil { |
| 586 | return "" |
| 587 | } |
| 588 | errField, ok := fields["error"] |
| 589 | if !ok { |
| 590 | return "" |
| 591 | } |
| 592 | var s string |
| 593 | if err := json.Unmarshal(errField, &s); err != nil { |
| 594 | return "" |
| 595 | } |
| 596 | return strings.TrimSpace(s) |
| 597 | } |
| 598 | |
| 599 | func normalizeAssistantToolCallInputs( |
| 600 | parts []fantasy.MessagePart, |
no test coverage detected