Skip to content

Class: FileSystem

Overview

The File System module provides comprehensive file and directory operations within the AGB cloud environment. It supports file upload, download, and manipulation.

File system module for reading, writing, listing, and managing files in the session. Supports text and binary files, directory listing, search, upload/download, and file change monitoring.

Hierarchy

  • BaseService

    FileSystem

Table of contents

Properties

Methods

Properties

typescript
delete: (`path`: `string`) => `Promise`<``BoolResult``>
list: (`path`: `string`) => `Promise`<``DirectoryListResult``>
ls: (`path`: `string`) => `Promise`<``DirectoryListResult``>
mkdir: (`path`: `string`) => `Promise`<``BoolResult``>
remove: (`path`: `string`) => `Promise`<``BoolResult``>
rm: (`path`: `string`) => `Promise`<``BoolResult``>
write: (`path`: `string`, `content`: `string`, `mode`: ``"overwrite"`` | ``"append"`` | ``"create_new"``) => `Promise`<``BoolResult``>

DEFAULT_CHUNK_SIZE

Static Readonly DEFAULT_CHUNK_SIZE: number = DEFAULT_CHUNK_SIZE


Type declaration

▸ (path): Promise&lt;BoolResult&gt;

Parameters
NameType
pathstring
Returns

Promise&lt;BoolResult&gt;


Type declaration

▸ (path): Promise&lt;DirectoryListResult&gt;

Parameters
NameType
pathstring
Returns

Promise&lt;DirectoryListResult&gt;


Type declaration

▸ (path): Promise&lt;DirectoryListResult&gt;

Parameters
NameType
pathstring
Returns

Promise&lt;DirectoryListResult&gt;


Type declaration

▸ (path): Promise&lt;BoolResult&gt;

Parameters
NameType
pathstring
Returns

Promise&lt;BoolResult&gt;


Type declaration

▸ (path): Promise&lt;BoolResult&gt;

Parameters
NameType
pathstring
Returns

Promise&lt;BoolResult&gt;


Type declaration

▸ (path): Promise&lt;BoolResult&gt;

Parameters
NameType
pathstring
Returns

Promise&lt;BoolResult&gt;


session

Protected session: SessionLike

Inherited from

BaseService.session


Type declaration

▸ (path, content, mode?): Promise&lt;BoolResult&gt;

Parameters
NameTypeDefault value
pathstringundefined
contentstringundefined
mode"overwrite" | "append" | "create_new""overwrite"
Returns

Promise&lt;BoolResult&gt;

Methods

callMcpTool

callMcpTool(name, args, readTimeout?, connectTimeout?): Promise&lt;OperationResult&gt;

Parameters

NameType
namestring
argsRecord&lt;string, unknown&gt;
readTimeout?number
connectTimeout?number

Returns

Promise&lt;OperationResult&gt;

Inherited from

BaseService.callMcpTool


createDirectory

createDirectory(path): Promise&lt;BoolResult&gt;

Parameters

NameType
pathstring

Returns

Promise&lt;BoolResult&gt;


deleteFile

deleteFile(path): Promise&lt;BoolResult&gt;

Parameters

NameType
pathstring

Returns

Promise&lt;BoolResult&gt;


download

download(remotePath, localPath, options?): Promise&lt;DownloadResult&gt;

Parameters

NameType
remotePathstring
localPathstring
options?Object
options.overwrite?boolean
options.pollInterval?number
options.progressCallback?(bytesReceived: number) => void
options.wait?boolean
options.waitTimeout?number

Returns

Promise&lt;DownloadResult&gt;


editFile

editFile(path, edits, dryRun?): Promise&lt;BoolResult&gt;

Parameters

NameTypeDefault value
pathstringundefined
edits{ newText: string ; oldText: string }[]undefined
dryRunbooleanfalse

Returns

Promise&lt;BoolResult&gt;

handleError

handleError(e): unknown

Parameters

NameType
eunknown

Returns

unknown

Inherited from

BaseService.handleError


listDirectory

listDirectory(path): Promise&lt;DirectoryListResult&gt;

Parameters

NameType
pathstring

Returns

Promise&lt;DirectoryListResult&gt;


moveFile

moveFile(source, destination): Promise&lt;BoolResult&gt;

Parameters

NameType
sourcestring
destinationstring

Returns

Promise&lt;BoolResult&gt;


read

read(path): Promise&lt;FileContentResult&gt;

Parameters

NameType
pathstring

Returns

Promise&lt;FileContentResult&gt;

read(path, opts): Promise&lt;FileContentResult&gt;

Parameters

NameType
pathstring
optsObject
opts.format"text"

Returns

Promise&lt;FileContentResult&gt;

read(path, opts): Promise&lt;BinaryFileContentResult&gt;

Parameters

NameType
pathstring
optsObject
opts.format"bytes"

Returns

Promise&lt;BinaryFileContentResult&gt;


readFile

readFile(path): Promise&lt;FileContentResult&gt;

Parameters

NameType
pathstring

Returns

Promise&lt;FileContentResult&gt;

readFile(path, opts): Promise&lt;FileContentResult&gt;

Parameters

NameType
pathstring
optsObject
opts.format"text"

Returns

Promise&lt;FileContentResult&gt;

readFile(path, opts): Promise&lt;BinaryFileContentResult&gt;

Parameters

NameType
pathstring
optsObject
opts.format"bytes"

Returns

Promise&lt;BinaryFileContentResult&gt;


readMultipleFiles

readMultipleFiles(paths): Promise&lt;MultipleFileContentResult&gt;

Parameters

NameType
pathsstring[]

Returns

Promise&lt;MultipleFileContentResult&gt;


searchFiles

searchFiles(path, pattern, excludePatterns?): Promise&lt;FileSearchResult&gt;

Parameters

NameType
pathstring
patternstring
excludePatterns?string[]

Returns

Promise&lt;FileSearchResult&gt;


toJSON

toJSON(): Record&lt;string, unknown&gt;

Returns

Record&lt;string, unknown&gt;

Inherited from

BaseService.toJSON


transferPath

transferPath(): Promise&lt;undefined | string&gt;

Returns

Promise&lt;undefined | string&gt;


upload

upload(localPath, remotePath, options?): Promise&lt;UploadResult&gt;

Parameters

NameType
localPathstring
remotePathstring
options?Object
options.contentType?string
options.pollInterval?number
options.progressCallback?(bytesSent: number) => void
options.wait?boolean
options.waitTimeout?number

Returns

Promise&lt;UploadResult&gt;


watchDir

watchDir(dirPath, callback, interval?): Object

Parameters

NameTypeDefault value
dirPathstringundefined
callback(events: FileChangeEvent[]) => voidundefined
intervalnumber1000

Returns

Object

NameType
stop() => void

Deprecated

Use watchDirectory instead


watchDirectory

watchDirectory(path, callback, interval?, signal?): Promise&lt;void&gt;

Parameters

NameTypeDefault value
pathstringundefined
callback(events: FileChangeEvent[]) => voidundefined
intervalnumber1000
signal?AbortSignalundefined

Returns

Promise&lt;void&gt;


writeFile

writeFile(path, content, mode?): Promise&lt;BoolResult&gt;

Parameters

NameTypeDefault value
pathstringundefined
contentstringundefined
mode"overwrite" | "append" | "create_new""overwrite"

Returns

Promise&lt;BoolResult&gt;

Best Practices

  1. Always check file permissions before operations
  2. Use appropriate file paths and handle path separators correctly
  3. Clean up temporary files after operations
  4. Handle file operation errors gracefully
  5. Use streaming for large file operations