UNPKG

mongodb-rag-core

Version:

Common elements used by MongoDB Chatbot Framework components.

61 lines 2.33 kB
import { TaskOptions } from "simple-git"; import { DataSource } from "./DataSource"; import { Page, PageMetadata } from "../contentStore"; /** Function to convert a file in the repo into a `Page` or `Page[]`. @param path - Path to file in repo @param content - Contents of file in repo */ export type HandlePageFunc<SourceType extends string = string> = (path: string, content: string) => Promise<undefined | Omit<Page<SourceType>, "sourceName"> | Omit<Page<SourceType>, "sourceName">[]>; export interface MakeGitDataSourceParams<SourceType extends string = string> { /** Name of project */ name: string; /** URI for git repo @example "https://github.com/mongodb/mongo-java-driver.git" */ repoUri: string; /** Options for `simple-git` clone command. @default { "--depth": 1 } */ repoOptions?: TaskOptions; /** Filter function for selecting files in the repo to parse to pages. @example (path: string) => path.endsWith(".html") */ filter: FilterFunc; /** Source type to be included in pages. Takes precendence over the sourceType set in handlePage's Page constructor. */ sourceType?: SourceType; /** Metadata to be included in all pages. */ metadata?: PageMetadata; handlePage: HandlePageFunc<SourceType>; } /** Loads and processes files from a Git repo (can be hosted anywhere). */ export declare function makeGitDataSource<SourceType extends string = string>({ name, handlePage, filter, sourceType, metadata, repoUri, repoOptions, }: MakeGitDataSourceParams<SourceType>): DataSource; /** @param prefix - prefix for the temporary directory name */ export declare function makeRandomTmp(prefix: string): string; export declare function getRepoLocally({ repoPath, localPath, options, }: { repoPath: string; localPath: string; options?: TaskOptions; }): Promise<void>; export type FilterFunc = (path: string) => boolean; export declare function getRelevantFilePathsInDir(directoryPath: string, filter: FilterFunc, fileList?: string[]): string[]; export declare function getRelevantFilesAsStrings({ directoryPath, filter, }: { directoryPath: string; filter: FilterFunc; }): Promise<Record<string, string>>; //# sourceMappingURL=GitDataSource.d.ts.map