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

Function ParseContent

coderd/x/chatd/chatprompt/chatprompt.go:337–352  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

335// from SDK parts, version 1 (current) unmarshals SDK-format
336// []ChatMessagePart directly.
337func 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

Calls 4

ChatMessageRoleTypeAlias · 0.92
parseLegacyContentFunction · 0.85
parseContentV1Function · 0.85
ErrorfMethod · 0.45