IsTextFile determines if a file at the given path is a text file that should be inlined into the message rather than uploaded via a provider's file API. It first checks the file extension against a broad allowlist of known text extensions. For unknown extensions, it falls back to reading the first 8
(filePath string)
| 250 | // extensions. For unknown extensions, it falls back to reading the first 8KB |
| 251 | // and checking if the content is valid UTF-8 with no null bytes. |
| 252 | func IsTextFile(filePath string) bool { |
| 253 | ext := strings.ToLower(filepath.Ext(filePath)) |
| 254 | if isTextExtension(ext) { |
| 255 | return true |
| 256 | } |
| 257 | // For unknown extensions, try byte-sniffing |
| 258 | return isTextByContent(filePath) |
| 259 | } |
| 260 | |
| 261 | // ReadFileForInline reads a text file and wraps it in an XML-like tag with |
| 262 | // the file path for context. Returns the formatted content and any error. |