Package org.machanism.machai.gw.tools
Class FileFunctionTools
java.lang.Object
org.machanism.machai.gw.tools.FileFunctionTools
- All Implemented Interfaces:
FunctionTools
Installs file-system tools into a
Genai.
Tools in this installer are intended for host-integrated use where the host controls the base working directory. All paths provided to these tools are interpreted relative to the working directory supplied by the provider/runtime.
Installed tools
read_file_from_file_system– reads a file as textwrite_file_to_file_system– writes a file (creating parent directories as needed)list_files_in_directory– lists immediate children of a directoryget_recursive_file_list– recursively lists all files under a directory
- Author:
- Viktor Tovstyi
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTools(Genai provider) Registers file read/write/list tools into the provided provider.getRecursiveFiles(com.fasterxml.jackson.databind.JsonNode params, File workingDir) Implementsget_recursive_file_list.static StringgetRelativePath(File dir, File file, boolean addSingleDot) Computes a project-relative path string.Implementslist_files_in_directory.Implementsread_file_from_file_system.Implementswrite_file_to_file_system.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.machanism.machai.ai.tools.FunctionTools
setConfigurator
-
Constructor Details
-
FileFunctionTools
public FileFunctionTools()
-
-
Method Details
-
applyTools
Registers file read/write/list tools into the provided provider.- Specified by:
applyToolsin interfaceFunctionTools- Parameters:
provider- provider instance
-
getRecursiveFiles
Implementsget_recursive_file_list.Expected parameters:
JsonNodeoptionally containingdir_pathFileworking directory
- Parameters:
params- tool arguments- Returns:
- a newline-separated list of project-relative file paths, or a message if no files are found
-
listFiles
Implementslist_files_in_directory.Expected parameters:
JsonNodeoptionally containingdir_pathFileworking directory
- Parameters:
params- tool arguments- Returns:
- a comma-separated list of project-relative paths, or a message if the directory does not exist or is empty
-
writeFile
Implementswrite_file_to_file_system.Expected parameters:
JsonNodecontainingfile_path,text,start_position, andend_positionFileworking directory
- Parameters:
params- tool arguments- Returns:
- success message, or an error message if writing fails
-
readFile
Implementsread_file_from_file_system.Expected parameters:
JsonNodecontainingfile_pathFileworking directory
- Parameters:
params- tool arguments- Returns:
- file content as text, or a message if the file does not exist
- Throws:
IllegalArgumentException- on I/O error
-
getRelativePath
Computes a project-relative path string.The returned path always uses forward slashes (
/) for consistency across platforms.- Parameters:
dir- base directory used to relativize thefilefile- target file or directoryaddSingleDot- whether to prefix relative paths with./- Returns:
- relative path,
.ifdirequalsfile, ornulliffileis not a descendant ofdir
-