ExtractFileID parses the file_id from a serialized file content block envelope. Returns uuid.Nil and an error when the block is not a file-type block or has no file_id.
(raw json.RawMessage)
| 74 | // block envelope. Returns uuid.Nil and an error when the block is |
| 75 | // not a file-type block or has no file_id. |
| 76 | func ExtractFileID(raw json.RawMessage) (uuid.UUID, error) { |
| 77 | var envelope struct { |
| 78 | Type string `json:"type"` |
| 79 | Data struct { |
| 80 | FileID string `json:"file_id"` |
| 81 | } `json:"data"` |
| 82 | } |
| 83 | if err := json.Unmarshal(raw, &envelope); err != nil { |
| 84 | return uuid.Nil, xerrors.Errorf("unmarshal content block: %w", err) |
| 85 | } |
| 86 | if !strings.EqualFold(envelope.Type, string(fantasy.ContentTypeFile)) { |
| 87 | return uuid.Nil, xerrors.Errorf("not a file content block: %s", envelope.Type) |
| 88 | } |
| 89 | if envelope.Data.FileID == "" { |
| 90 | return uuid.Nil, xerrors.New("no file_id") |
| 91 | } |
| 92 | return uuid.Parse(envelope.Data.FileID) |
| 93 | } |
| 94 | |
| 95 | // ConvertMessagesWithFiles converts persisted chat messages into LLM |
| 96 | // prompt messages, resolving user file references via the provided |
no test coverage detected