Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.0 KB
Raw Blame
import { platform } from 'node:os';

import { createLogger } from '../logger';
import type { ToolDetector } from '../toolDetector';
import { LinuxSearchServiceImpl } from './impl/linux';
import { MacOSSearchServiceImpl } from './impl/macOS';
import { WindowsSearchServiceImpl } from './impl/windows';

const logger = createLogger('fileSearch:factory');

export type {
  FileResult,
  GlobFilesParams,
  GlobFilesResult,
  SearchFilesParams as SearchOptions,
} from '../types';
export { BaseFileSearch } from './base';

export const createFileSearchModule = (toolDetector?: ToolDetector) => {
  const currentPlatform = platform();

  switch (currentPlatform) {
    case 'darwin': {
      return new MacOSSearchServiceImpl(toolDetector);
    }
    case 'win32': {
      return new WindowsSearchServiceImpl(toolDetector);
    }
    case 'linux': {
      return new LinuxSearchServiceImpl(toolDetector);
    }
    default: {
      logger.warn(`Unsupported platform: ${currentPlatform}, using Linux fallback`);
      return new LinuxSearchServiceImpl(toolDetector);
    }
  }
};