MarshalToolResult encodes a single tool result in the legacy tool-row format. Retained for test fixtures that create legacy-format DB rows. Production write paths use MarshalParts. The stored shape is [{"tool_call_id":…,"tool_name":…,"result":…,"is_error":…,"is_media":…}].
(toolCallID, toolName string, result json.RawMessage, isError bool, isMedia bool, providerExecuted bool, providerMetadata fantasy.ProviderMetadata)
| 703 | // The stored shape is |
| 704 | // [{"tool_call_id":…,"tool_name":…,"result":…,"is_error":…,"is_media":…}]. |
| 705 | func MarshalToolResult(toolCallID, toolName string, result json.RawMessage, isError bool, isMedia bool, providerExecuted bool, providerMetadata fantasy.ProviderMetadata) (pqtype.NullRawMessage, error) { |
| 706 | var metaJSON json.RawMessage |
| 707 | if len(providerMetadata) > 0 { |
| 708 | var err error |
| 709 | metaJSON, err = json.Marshal(providerMetadata) |
| 710 | if err != nil { |
| 711 | return pqtype.NullRawMessage{}, xerrors.Errorf("encode provider metadata: %w", err) |
| 712 | } |
| 713 | } |
| 714 | row := toolResultRaw{ |
| 715 | ToolCallID: toolCallID, |
| 716 | ToolName: toolName, |
| 717 | Result: result, |
| 718 | IsError: isError, |
| 719 | IsMedia: isMedia, |
| 720 | ProviderExecuted: providerExecuted, |
| 721 | ProviderMetadata: metaJSON, |
| 722 | } |
| 723 | data, err := json.Marshal([]toolResultRaw{row}) |
| 724 | if err != nil { |
| 725 | return pqtype.NullRawMessage{}, xerrors.Errorf("encode tool result: %w", err) |
| 726 | } |
| 727 | return pqtype.NullRawMessage{RawMessage: data, Valid: true}, nil |
| 728 | } |
| 729 | |
| 730 | // PartFromContent converts fantasy content into a SDK chat message |
| 731 | // part, preserving ProviderMetadata and ProviderExecuted fields. |