Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat: expand file type support in document parser and UI components

dev-miro26aa2b968181dd
diff --git a/src-tauri/plugins/tauri-plugin-rag/src/parser.rs b/src-tauri/plugins/tauri-plugin-rag/src/parser.rs
index fcf4d91c3..9f1604ef2 100644
--- a/src-tauri/plugins/tauri-plugin-rag/src/parser.rs
+++ b/src-tauri/plugins/tauri-plugin-rag/src/parser.rs
@@ -57,7 +57,32 @@ pub fn parse_text(file_path: &str) -> Result<String, RagError> {
pub fn parse_document(file_path: &str, file_type: &str) -> Result<String, RagError> {
match file_type.to_lowercase().as_str() {
"pdf" | "application/pdf" => parse_pdf(file_path),
- "txt" | "text/plain" | "md" | "text/markdown" => parse_text(file_path),
+ "txt" | "text/plain" | "md" | "text/markdown"
+ // JavaScript / TypeScript
+ | "js" | "mjs" | "cjs" | "ts" | "mts" | "cts" | "jsx" | "tsx"
+ // Python
+ | "py" | "pyw" | "pyi"
+ // C / C++
+ | "c" | "h" | "cpp" | "cc" | "cxx" | "hpp" | "hh" | "hxx"
+ // Systems languages
+ | "rs" | "go" | "swift" | "zig"
+ // JVM languages
+ | "java" | "kt" | "kts" | "scala" | "groovy"
+ // Scripting languages
+ | "rb" | "php" | "lua" | "pl" | "pm" | "r" | "jl"
+ // .NET
+ | "cs" | "fs" | "vb"
+ // Shell
+ | "sh" | "bash" | "zsh" | "fish" | "ps1" | "psm1"
+ // Web
+ | "css" | "scss" | "sass" | "less" | "vue" | "svelte" | "astro"
+ // Data / config formats
+ | "json" | "jsonc" | "yaml" | "yml" | "toml" | "xml" | "ini"
+ | "cfg" | "conf" | "config" | "env" | "properties"
+ // Query / markup
+ | "sql" | "graphql" | "gql" | "tex" | "rst" | "adoc"
+ // Misc text
+ | "log" | "diff" | "patch" | "gitignore" | "dockerfile" | "makefile" => parse_text(file_path),
"csv" | "text/csv" => parse_csv(file_path),
// Excel family via calamine
"xlsx"
@@ -77,11 +102,20 @@ pub fn parse_document(file_path: &str, file_type: &str) -> Result<String, RagErr
}
other => {
// Try MIME sniffing when extension or MIME is unknown
- if let Ok(Some(k)) = infer::get_from_path(file_path) {
- let mime = k.mime_type();
- return parse_document(file_path, mime);
+ match infer::get_from_path(file_path) {
+ Ok(Some(k)) => {
+ let mime = k.mime_type();
+ // Guard against infinite recursion if mime matches the unknown extension
+ if mime != other {
+ return parse_document(file_path, mime);
+ }
+ Err(RagError::UnsupportedFileType(other.to_string()))
+ }
+ _ => {
+ // infer returned None → no binary magic bytes detected, treat as plain text
+ parse_text(file_path)
+ }
}
- Err(RagError::UnsupportedFileType(other.to_string()))
}
}
}
diff --git a/web-app/src/containers/ChatInput.tsx b/web-app/src/containers/ChatInput.tsx
index 993f47392..75c6c02eb 100644
--- a/web-app/src/containers/ChatInput.tsx
+++ b/web-app/src/containers/ChatInput.tsx
@@ -745,8 +745,9 @@ const ChatInput = memo(function ChatInput({
multiple: true,
filters: [
{
- name: 'Documents',
+ name: 'Documents & Code',
extensions: [
+ // Documents
'pdf',
'docx',
'txt',
@@ -758,8 +759,90 @@ const ChatInput = memo(function ChatInput({
'pptx',
'html',
'htm',
+ // JavaScript / TypeScript
+ 'js',
+ 'mjs',
+ 'cjs',
+ 'ts',
+ 'mts',
+ 'cts',
+ 'jsx',
+ 'tsx',
+ // Python
+ 'py',
+ 'pyw',
+ 'pyi',
+ // C / C++
+ 'c',
+ 'h',
+ 'cpp',
+ 'cc',
+ 'cxx',
+ 'hpp',
+ 'hh',
+ // Systems languages
+ 'rs',
+ 'go',
+ 'swift',
+ 'zig',
+ // JVM languages
+ 'java',
+ 'kt',
+ 'kts',
+ 'scala',
+ 'groovy',
+ // Scripting languages
+ 'rb',
+ 'php',
+ 'lua',
+ 'pl',
+ 'r',
+ 'jl',
+ // .NET
+ 'cs',
+ 'fs',
+ 'vb',
+ // Shell
+ 'sh',
+ 'bash',
+ 'zsh',
+ 'fish',
+ 'ps1',
+ // Web
+ 'css',
+ 'scss',
+ 'sass',
+ 'less',
+ 'vue',
+ 'svelte',
+ 'astro',
+ // Data / config formats
+ 'json',
+ 'jsonc',
+ 'yaml',
+ 'yml',
+ 'toml',
+ 'xml',
+ 'ini',
+ 'cfg',
+ 'conf',
+ 'env',
+ // Query / markup
+ 'sql',
+ 'graphql',
+ 'gql',
+ 'tex',
+ 'rst',
+ // Misc text
+ 'log',
+ 'diff',
+ 'patch',
],
},
+ {
+ name: 'All Files',
+ extensions: ['*'],
+ },
],
})
if (!selection) return
diff --git a/web-app/src/containers/ProjectFiles.tsx b/web-app/src/containers/ProjectFiles.tsx
index 0f70d182b..66830d42e 100644
--- a/web-app/src/containers/ProjectFiles.tsx
+++ b/web-app/src/containers/ProjectFiles.tsx
@@ -43,6 +43,7 @@ function formatBytes(bytes?: number): string {
}
const SUPPORTED_EXTENSIONS = [
+ // Documents
'pdf',
'docx',
'txt',
@@ -54,6 +55,84 @@ const SUPPORTED_EXTENSIONS = [
'pptx',
'html',
'htm',
+ // JavaScript / TypeScript
+ 'js',
+ 'mjs',
+ 'cjs',
+ 'ts',
+ 'mts',
+ 'cts',
+ 'jsx',
+ 'tsx',
+ // Python
+ 'py',
+ 'pyw',
+ 'pyi',
+ // C / C++
+ 'c',
+ 'h',
+ 'cpp',
+ 'cc',
+ 'cxx',
+ 'hpp',
+ 'hh',
+ // Systems languages
+ 'rs',
+ 'go',
+ 'swift',
+ 'zig',
+ // JVM languages
+ 'java',
+ 'kt',
+ 'kts',
+ 'scala',
+ 'groovy',
+ // Scripting languages
+ 'rb',
+ 'php',
+ 'lua',
+ 'pl',
+ 'r',
+ 'jl',
+ // .NET
+ 'cs',
+ 'fs',
+ 'vb',
+ // Shell
+ 'sh',
+ 'bash',
+ 'zsh',
+ 'fish',
+ 'ps1',
+ // Web
+ 'css',
+ 'scss',
+ 'sass',
+ 'less',
+ 'vue',
+ 'svelte',
+ 'astro',
+ // Data / config formats
+ 'json',
+ 'jsonc',
+ 'yaml',
+ 'yml',
+ 'toml',
+ 'xml',
+ 'ini',
+ 'cfg',
+ 'conf',
+ 'env',
+ // Query / markup
+ 'sql',
+ 'graphql',
+ 'gql',
+ 'tex',
+ 'rst',
+ // Misc text
+ 'log',
+ 'diff',
+ 'patch',
]
async function getFilesFromPaths(paths: string[]): Promise<string[]> {
@@ -264,9 +343,13 @@ export default function ProjectFiles({ projectId, lng }: ProjectFilesProps) {
directory: false,
filters: [
{
- name: 'Documents',
+ name: 'Documents & Code',
extensions: SUPPORTED_EXTENSIONS,
},
+ {
+ name: 'All Files',
+ extensions: ['*'],
+ },
],
})
if (!selection) return