parseLegacyFantasyBlocks decodes an assistant message stored in fantasy envelope format, converting each block via PartFromContent which preserves ProviderMetadata.
(role string, raw pqtype.NullRawMessage)
| 509 | // fantasy envelope format, converting each block via PartFromContent |
| 510 | // which preserves ProviderMetadata. |
| 511 | func parseLegacyFantasyBlocks(role string, raw pqtype.NullRawMessage) ([]codersdk.ChatMessagePart, error) { |
| 512 | var rawBlocks []json.RawMessage |
| 513 | if err := json.Unmarshal(raw.RawMessage, &rawBlocks); err != nil { |
| 514 | return nil, xerrors.Errorf("parse %s content: %w", role, err) |
| 515 | } |
| 516 | |
| 517 | parts := make([]codersdk.ChatMessagePart, 0, len(rawBlocks)) |
| 518 | for i, rawBlock := range rawBlocks { |
| 519 | block, err := fantasy.UnmarshalContent(rawBlock) |
| 520 | if err != nil { |
| 521 | return nil, xerrors.Errorf("parse %s content block %d: %w", role, i, err) |
| 522 | } |
| 523 | part := PartFromContent(block) |
| 524 | if part.Type == "" { |
| 525 | continue |
| 526 | } |
| 527 | parts = append(parts, part) |
| 528 | } |
| 529 | return parts, nil |
| 530 | } |
| 531 | |
| 532 | // hasNonEmptyType returns true if at least one part has a non-empty |
| 533 | // Type field, indicating a valid SDK parts array. |
no test coverage detected