@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
79 lines • 2.6 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 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;
/**
* Check if a file should be treated as text based on extension.
*/
export declare function isTextFile(filename: 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