@mastra/core
Version:
96 lines • 3.37 kB
TypeScript
/**
* Shared filesystem utilities for LocalFilesystem and LocalSkillSource.
*
* These utilities provide consistent implementations for common fs operations.
*/
/**
* Expand a leading `~` or `~/` to the user's home directory.
* Shell commands handle this automatically, but Node.js path APIs do not.
*/
export declare function expandTilde(p: string): string;
/**
* Full file stat information.
* Used by both WorkspaceFilesystem and SkillSource.
*/
export interface FsStatResult {
/** File or directory name */
name: string;
/** 'file' or 'directory' */
type: 'file' | 'directory';
/** Size in bytes (0 for directories) */
size: number;
/** Creation time */
createdAt: Date;
/** Last modification time */
modifiedAt: Date;
/** MIME type (for files) */
mimeType?: string;
}
/**
* Check if an error is an ENOENT (file not found) error.
*/
export declare function isEnoentError(error: unknown): error is NodeJS.ErrnoException & {
code: 'ENOENT';
};
/**
* Check if an error is an ENOTDIR error (a path component is not a directory,
* e.g. treating a file as a directory). Like ENOENT, this means the requested
* target cannot be resolved.
*/
export declare function isEnotdirError(error: unknown): error is NodeJS.ErrnoException & {
code: 'ENOTDIR';
};
/**
* Check if an error is an EEXIST (file exists) error.
*/
export declare function isEexistError(error: unknown): error is NodeJS.ErrnoException & {
code: 'EEXIST';
};
/**
* Get MIME type for a filename based on extension.
*/
export declare function getMimeType(filename: string): string;
/**
* Normalize a text extension to the internal form: lowercased and dot-prefixed.
* e.g. `SAS` -> `.sas`, `.LOG` -> `.log`.
*/
export declare function normalizeTextExtension(ext: string): string;
/**
* Check if a file should be treated as text based on extension.
*
* @param filename - The filename (or path) to check.
* @param extraExtensions - Optional set of additional normalized extensions
* (lowercased, dot-prefixed) to treat as text, in addition to the built-in set.
*/
export declare function isTextFile(filename: string, extraExtensions?: ReadonlySet<string>): boolean;
/**
* Resolve a path against a base directory.
*
* - Tilde (`~`) is expanded to the user's home directory.
* - Absolute paths are normalized and returned as-is.
* - Relative paths (including `../`) are resolved against `basePath`.
*
* @param basePath - The absolute base path to resolve against
* @param filePath - The path to resolve
* @returns The absolute resolved path
*/
export declare function resolveToBasePath(basePath: string, filePath: string): string;
/**
* Check if a path exists.
* Never throws - returns false on any error.
*
* @param absolutePath - The absolute path to check
* @returns true if path exists and is accessible
*/
export declare function fsExists(absolutePath: string): Promise<boolean>;
/**
* Get file/directory stats.
* Throws FileNotFoundError if path doesn't exist.
*
* @param absolutePath - The absolute path to stat
* @param userPath - The user-facing path for error messages
* @returns File stat information
* @throws {FileNotFoundError} if path doesn't exist
*/
export declare function fsStat(absolutePath: string, userPath: string): Promise<FsStatResult>;
//# sourceMappingURL=fs-utils.d.ts.map