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)
| 1353 | // file-reference natively, so we convert to a readable text |
| 1354 | // representation. |
| 1355 | func 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. |
no test coverage detected