MCPcopy Index your code
hub / github.com/coder/coder / normalizeMessageParts

Function normalizeMessageParts

coderd/x/chatd/chatdebug/model.go:993–1039  ·  view source on GitHub ↗

normalizeMessageParts extracts type and bounded metadata from each MessagePart. Text-like payloads are bounded to MaxMessagePartTextLength runes so the debug panel can display readable content.

(parts []fantasy.MessagePart)

Source from the content-addressed store, hash-verified

991// MaxMessagePartTextLength runes so the debug panel can display
992// readable content.
993func normalizeMessageParts(parts []fantasy.MessagePart) []normalizedMessagePart {
994 result := make([]normalizedMessagePart, 0, len(parts))
995 for _, p := range parts {
996 if isNilInterfaceValue(p) {
997 continue
998 }
999 np := normalizedMessagePart{
1000 Type: canonicalContentType(string(p.GetType())),
1001 }
1002 switch v := p.(type) {
1003 case fantasy.TextPart:
1004 np.Text = boundText(v.Text)
1005 np.TextLength = utf8.RuneCountInString(v.Text)
1006 case *fantasy.TextPart:
1007 np.Text = boundText(v.Text)
1008 np.TextLength = utf8.RuneCountInString(v.Text)
1009 case fantasy.ReasoningPart:
1010 np.Text = boundText(v.Text)
1011 np.TextLength = utf8.RuneCountInString(v.Text)
1012 case *fantasy.ReasoningPart:
1013 np.Text = boundText(v.Text)
1014 np.TextLength = utf8.RuneCountInString(v.Text)
1015 case fantasy.FilePart:
1016 np.Filename = v.Filename
1017 np.MediaType = v.MediaType
1018 case *fantasy.FilePart:
1019 np.Filename = v.Filename
1020 np.MediaType = v.MediaType
1021 case fantasy.ToolCallPart:
1022 np.ToolCallID = v.ToolCallID
1023 np.ToolName = v.ToolName
1024 np.Arguments = boundText(v.Input)
1025 case *fantasy.ToolCallPart:
1026 np.ToolCallID = v.ToolCallID
1027 np.ToolName = v.ToolName
1028 np.Arguments = boundText(v.Input)
1029 case fantasy.ToolResultPart:
1030 np.ToolCallID = v.ToolCallID
1031 np.Result = normalizeToolResultOutput(v.Output)
1032 case *fantasy.ToolResultPart:
1033 np.ToolCallID = v.ToolCallID
1034 np.Result = normalizeToolResultOutput(v.Output)
1035 }
1036 result = append(result, np)
1037 }
1038 return result
1039}
1040
1041// normalizeTools converts the tool list into lightweight descriptors.
1042// Function tool schemas are preserved so the debug panel can render

Callers 2

normalizeMessagesFunction · 0.85

Calls 5

isNilInterfaceValueFunction · 0.85
canonicalContentTypeFunction · 0.85
boundTextFunction · 0.85
GetTypeMethod · 0.45