Class LocalFiles
java.lang.Object
uno.anahata.ai.tools.spi.LocalFiles
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MultiPartResponseaddToUserPrompt(List<String> absolutePath) Adds the contents of specified files as blobs to the next user feedback message.static FileInfoappendToFile(String path, String content) Appends content to the end of a file.static StringCopies a file.static StringcreateDirectories(String path) Creates a directory structure.static FileInfocreateFile(String path, String content) Creates a new file with the given content.static StringdeleteFile(String path) Deletes a file and prunes it from the context.static booleanfileExists(String path) Checks if a file or directory exists.listDirectory(String path) Lists the contents of a directory.static StringMoves or renames a file.static byte[]readBinaryFile(String path) Reads a binary file and returns its raw bytes.static FileInfoReads a text file and returns aFileInfoobject.static FileInfoWrites content to an existing file, using optimistic locking.
-
Constructor Details
-
LocalFiles
public LocalFiles()
-
-
Method Details
-
addToUserPrompt
Adds the contents of specified files as blobs to the next user feedback message.- Parameters:
absolutePath- A list of absolute file paths.- Returns:
- A MultiPartResponse containing the file paths.
- Throws:
IOException- if an I/O error occurs.
-
readBinaryFile
Reads a binary file and returns its raw bytes.- Parameters:
path- The absolute path to the file.- Returns:
- The file content as a byte array.
- Throws:
IOException- if the file is not found or is a directory.
-
readFile
Reads a text file and returns aFileInfoobject.This method includes a "Redundant Read Check" to prevent reloading files that are already valid in the context.
- Parameters:
path- The absolute path to the file.- Returns:
- A FileInfo object containing content and metadata.
- Throws:
IOException- if the file is not found or is a directory.
-
writeFile
Writes content to an existing file, using optimistic locking.- Parameters:
path- The absolute path to the file.content- The new content to write.lastModified- The expected last modified timestamp for safety.- Returns:
- An updated FileInfo object.
- Throws:
IOException- if a modification conflict occurs or the file is missing.
-
createFile
Creates a new file with the given content.- Parameters:
path- The absolute path to the file.content- The initial content.- Returns:
- A FileInfo object for the new file.
- Throws:
IOException- if the path already exists.
-
appendToFile
Appends content to the end of a file.- Parameters:
path- The absolute path to the file.content- The content to append.- Returns:
- An updated FileInfo object.
- Throws:
IOException- if an I/O error occurs.
-
deleteFile
Deletes a file and prunes it from the context.- Parameters:
path- The absolute path to the file.- Returns:
- A success message.
- Throws:
IOException- if the file is not found.
-
moveFile
Moves or renames a file.- Parameters:
sourcePath- The current path.targetPath- The destination path.- Returns:
- A success message.
- Throws:
IOException- if the source is missing or target exists.
-
copyFile
Copies a file.- Parameters:
sourcePath- The source path.destinationPath- The destination path.- Returns:
- A success message.
- Throws:
IOException- if the source is missing or target exists.
-
createDirectories
Creates a directory structure.- Parameters:
path- The absolute path to create.- Returns:
- A success message.
- Throws:
IOException- if an I/O error occurs.
-
fileExists
Checks if a file or directory exists.- Parameters:
path- The absolute path to check.- Returns:
trueif it exists.
-
listDirectory
Lists the contents of a directory.- Parameters:
path- The absolute path to list.- Returns:
- A list of strings describing the directory entries.
- Throws:
IOException- if the path is not a directory.
-
