| 925 | } |
| 926 | |
| 927 | func normalizeToolResultOutput(output fantasy.ToolResultOutputContent) string { |
| 928 | switch v := output.(type) { |
| 929 | case fantasy.ToolResultOutputContentText: |
| 930 | return boundText(v.Text) |
| 931 | case *fantasy.ToolResultOutputContentText: |
| 932 | if v == nil { |
| 933 | return "" |
| 934 | } |
| 935 | return boundText(v.Text) |
| 936 | case fantasy.ToolResultOutputContentError: |
| 937 | if v.Error == nil { |
| 938 | return "" |
| 939 | } |
| 940 | return boundText(v.Error.Error()) |
| 941 | case *fantasy.ToolResultOutputContentError: |
| 942 | if v == nil || v.Error == nil { |
| 943 | return "" |
| 944 | } |
| 945 | return boundText(v.Error.Error()) |
| 946 | case fantasy.ToolResultOutputContentMedia: |
| 947 | if v.Text != "" { |
| 948 | return boundText(v.Text) |
| 949 | } |
| 950 | if v.MediaType == "" { |
| 951 | return "[media output]" |
| 952 | } |
| 953 | return fmt.Sprintf("[media output: %s]", v.MediaType) |
| 954 | case *fantasy.ToolResultOutputContentMedia: |
| 955 | if v == nil { |
| 956 | return "" |
| 957 | } |
| 958 | if v.Text != "" { |
| 959 | return boundText(v.Text) |
| 960 | } |
| 961 | if v.MediaType == "" { |
| 962 | return "[media output]" |
| 963 | } |
| 964 | return fmt.Sprintf("[media output: %s]", v.MediaType) |
| 965 | default: |
| 966 | if output == nil { |
| 967 | return "" |
| 968 | } |
| 969 | return boundText(string(safeMarshalJSON("tool result output", output))) |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | // isNilInterfaceValue reports whether v is nil or holds a nil pointer, |
| 974 | // map, slice, channel, or func. |