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

Function fileReferencePartToText

coderd/x/chatd/chatprompt/chatprompt.go:1355–1366  ·  view source on GitHub ↗

fileReferencePartToText formats a file-reference SDK part as plain text for LLM consumption. LLMs don't understand file-reference natively, so we convert to a readable text representation.

(part codersdk.ChatMessagePart)

Source from the content-addressed store, hash-verified

1353// file-reference natively, so we convert to a readable text
1354// representation.
1355func fileReferencePartToText(part codersdk.ChatMessagePart) string {
1356 lineRange := fmt.Sprintf("%d", part.StartLine)
1357 if part.StartLine != part.EndLine {
1358 lineRange = fmt.Sprintf("%d-%d", part.StartLine, part.EndLine)
1359 }
1360 var sb strings.Builder
1361 _, _ = fmt.Fprintf(&sb, "[file-reference] %s:%s", part.FileName, lineRange)
1362 if content := strings.TrimSpace(part.Content); content != "" {
1363 _, _ = fmt.Fprintf(&sb, "\n```%s\n%s\n```", part.FileName, content)
1364 }
1365 return sb.String()
1366}
1367
1368// toolResultPartToMessagePart converts an SDK tool-result part
1369// into a fantasy ToolResultPart for LLM dispatch.

Callers 1

partsToMessagePartsFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected