MCPcopy Create free account
hub / github.com/coder/coder / parseLegacyUserBlocks

Function parseLegacyUserBlocks

coderd/x/chatd/chatprompt/chatprompt.go:477–506  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

475// envelope format, extracting file_id references from the raw
476// envelope for file-type blocks.
477func 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

Callers 1

parseUserRoleFunction · 0.85

Calls 4

PartFromContentFunction · 0.85
ExtractFileIDFunction · 0.85
UnmarshalMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected