ParseContent decodes persisted chat message content blocks into SDK parts. Dispatches on content version: version 0 (legacy) uses a role-aware heuristic to distinguish fantasy envelope format from SDK parts, version 1 (current) unmarshals SDK-format []ChatMessagePart directly.
(msg database.ChatMessage)
| 335 | // from SDK parts, version 1 (current) unmarshals SDK-format |
| 336 | // []ChatMessagePart directly. |
| 337 | func ParseContent(msg database.ChatMessage) ([]codersdk.ChatMessagePart, error) { |
| 338 | if !msg.Content.Valid || len(msg.Content.RawMessage) == 0 { |
| 339 | return nil, nil |
| 340 | } |
| 341 | |
| 342 | role := codersdk.ChatMessageRole(msg.Role) |
| 343 | |
| 344 | switch msg.ContentVersion { |
| 345 | case ContentVersionV0: |
| 346 | return parseLegacyContent(role, msg.Content) |
| 347 | case ContentVersionV1: |
| 348 | return parseContentV1(role, msg.Content) |
| 349 | default: |
| 350 | return nil, xerrors.Errorf("unsupported content version %d", msg.ContentVersion) |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | // parseLegacyContent handles content version 0, where the format |
| 355 | // varies by role and era. Uses structural heuristics to distinguish |