@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
173 lines (172 loc) • 5.89 kB
TypeScript
/**
* Source Code Processor
*
* Processes source code files for 50+ programming languages.
* Uses extension-based detection as primary method (more reliable than MIME types for code).
*
* Key features:
* - Supports 50+ programming languages via extension detection
* - Handles exact filename matches (Dockerfile, Makefile, etc.)
* - Line count truncation to prevent token overflow
* - Language detection for syntax highlighting metadata
*
* Priority: 120 (lower priority - text-based content, processed after binary/document formats)
*
* @module processors/code/SourceCodeProcessor
*
* @example
* ```typescript
* import { sourceCodeProcessor, processSourceCode, isSourceCodeFile } from "./code/index.js";
*
* // Check if a file is source code
* if (isSourceCodeFile("text/plain", "app.ts")) {
* const result = await processSourceCode({
* id: "file-123",
* name: "app.ts",
* mimetype: "text/plain",
* size: 1024,
* buffer: codeBuffer,
* });
*
* if (result.success) {
* console.log(`Language: ${result.data.language}`);
* console.log(`Lines: ${result.data.lineCount}`);
* }
* }
* ```
*/
import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
import type { FileInfo, ProcessorFileProcessingResult, ProcessOptions, ProcessedSourceCode } from "../../types/index.js";
import { detectLanguageFromFilename } from "../config/languageMap.js";
/**
* Source Code Processor - handles 50+ programming languages.
*
* Uses extension-based detection as the primary method since MIME types
* for source code are often unreliable (many are just "text/plain").
*
* Priority: 120 (lower priority than binary/document formats)
*
* @example
* ```typescript
* const processor = new SourceCodeProcessor();
*
* const result = await processor.processFile({
* id: "file-123",
* name: "main.py",
* mimetype: "text/plain",
* size: 2048,
* buffer: pythonCodeBuffer,
* });
*
* if (result.success) {
* console.log(`Language: ${result.data.language}`); // "Python"
* }
* ```
*/
export declare class SourceCodeProcessor extends BaseFileProcessor<ProcessedSourceCode> {
/**
* Supported file extensions for source code.
* Includes 50+ extensions covering all major programming languages.
*/
private static readonly supportedExtensions;
/**
* Common MIME types for source code files.
* Note: Extension-based detection is preferred as MIME types are often unreliable.
*/
private static readonly supportedMimeTypes;
constructor();
/**
* Override to use extension-based detection as primary method.
* Source code MIME types are often unreliable (e.g., "text/plain" for .ts files),
* so we check extensions first.
*
* Also handles exact filename matches for special files like Dockerfile, Makefile.
*
* @param mimetype - MIME type of the file (often unreliable for source code)
* @param filename - Filename for extension-based detection
* @returns true if the file is a supported source code file
*/
isFileSupported(mimetype: string, filename: string): boolean;
/**
* Build the processed source code result.
* Decodes the buffer as UTF-8, detects language, and truncates if needed.
*
* @param buffer - Raw file content
* @param fileInfo - Original file information
* @returns Processed source code with metadata
*/
protected buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): ProcessedSourceCode;
/**
* Extract file extension from filename.
*
* @param filename - Filename to extract extension from
* @returns Extension with leading dot (e.g., ".ts") or null if no extension
*/
private getExtension;
}
/**
* Singleton instance of the SourceCodeProcessor.
* Use this for all source code processing to share configuration.
*/
export declare const sourceCodeProcessor: SourceCodeProcessor;
/**
* Check if a file is a source code file.
*
* @param mimetype - MIME type of the file
* @param filename - Filename for extension-based detection
* @returns true if the file is a supported source code file
*
* @example
* ```typescript
* if (isSourceCodeFile("text/plain", "app.ts")) {
* console.log("This is a TypeScript file");
* }
* ```
*/
export declare function isSourceCodeFile(mimetype: string, filename: string): boolean;
/**
* Validate source code file size against configured limit.
*
* @param sizeBytes - File size in bytes
* @returns true if the file size is within limits
*/
export declare function validateSourceCodeSize(sizeBytes: number): boolean;
/**
* Process a source code file.
*
* @param fileInfo - File information (can include URL or buffer)
* @param options - Optional processing options
* @returns Processing result with success flag and either data or error
*
* @example
* ```typescript
* const result = await processSourceCode({
* id: "file-123",
* name: "main.py",
* mimetype: "text/plain",
* size: 2048,
* buffer: pythonCodeBuffer,
* });
*
* if (result.success) {
* console.log(`Detected language: ${result.data.language}`);
* console.log(`Line count: ${result.data.lineCount}`);
* console.log(`Truncated: ${result.data.truncated}`);
* }
* ```
*/
export declare function processSourceCode(fileInfo: FileInfo, options?: ProcessOptions): Promise<ProcessorFileProcessingResult<ProcessedSourceCode>>;
/**
* Alias for backward compatibility with Curator codebase.
* Detects programming language from a filename.
*
* @param filename - The filename to detect language from
* @returns The detected language name or 'Unknown'
*
* @example
* ```typescript
* detectLanguage("app.ts") // Returns "TypeScript"
* detectLanguage("Dockerfile") // Returns "Dockerfile"
* ```
*/
export declare const detectLanguage: typeof detectLanguageFromFilename;