parseLegacyUserBlocks decodes a user message stored in fantasy envelope format, extracting file_id references from the raw envelope for file-type blocks.
(raw pqtype.NullRawMessage)
| 475 | // envelope format, extracting file_id references from the raw |
| 476 | // envelope for file-type blocks. |
| 477 | func parseLegacyUserBlocks(raw pqtype.NullRawMessage) ([]codersdk.ChatMessagePart, error) { |
| 478 | var rawBlocks []json.RawMessage |
| 479 | if err := json.Unmarshal(raw.RawMessage, &rawBlocks); err != nil { |
| 480 | return nil, xerrors.Errorf("parse user content: %w", err) |
| 481 | } |
| 482 | |
| 483 | parts := make([]codersdk.ChatMessagePart, 0, len(rawBlocks)) |
| 484 | for i, rawBlock := range rawBlocks { |
| 485 | block, err := fantasy.UnmarshalContent(rawBlock) |
| 486 | if err != nil { |
| 487 | return nil, xerrors.Errorf("parse user content block %d: %w", i, err) |
| 488 | } |
| 489 | part := PartFromContent(block) |
| 490 | if part.Type == "" { |
| 491 | continue |
| 492 | } |
| 493 | // For file-type blocks, extract file_id from the raw |
| 494 | // envelope's data sub-object. |
| 495 | if part.Type == codersdk.ChatMessagePartTypeFile { |
| 496 | if fid, err := ExtractFileID(rawBlock); err == nil { |
| 497 | part.FileID = uuid.NullUUID{UUID: fid, Valid: true} |
| 498 | // Clear inline data when file_id is present; |
| 499 | // resolved at LLM dispatch time. |
| 500 | part.Data = nil |
| 501 | } |
| 502 | } |
| 503 | parts = append(parts, part) |
| 504 | } |
| 505 | return parts, nil |
| 506 | } |
| 507 | |
| 508 | // parseLegacyFantasyBlocks decodes an assistant message stored in |
| 509 | // fantasy envelope format, converting each block via PartFromContent |
no test coverage detected