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

Function parseLegacyFantasyBlocks

coderd/x/chatd/chatprompt/chatprompt.go:511–530  ·  view source on GitHub ↗

parseLegacyFantasyBlocks decodes an assistant message stored in fantasy envelope format, converting each block via PartFromContent which preserves ProviderMetadata.

(role string, raw pqtype.NullRawMessage)

Source from the content-addressed store, hash-verified

509// fantasy envelope format, converting each block via PartFromContent
510// which preserves ProviderMetadata.
511func 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.

Callers 1

parseAssistantRoleFunction · 0.85

Calls 3

PartFromContentFunction · 0.85
UnmarshalMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected