117 lines
2.9 KiB
TypeScript
117 lines
2.9 KiB
TypeScript
import {Environment} from "../../common/environment";
|
|
import {AiTool} from "../tool-types";
|
|
import {braveSearchTool, webSearch} from "./brave-search";
|
|
import {getCurrentDateTime, getCurrentDateTimeTool} from "./datetime";
|
|
import {shellExecute, shellExecuteTool} from "./shell";
|
|
import {ToolHandler} from "./types";
|
|
import {getWeather, getWeatherTool} from "./weather";
|
|
import {getMarketRates, getMarketRatesTool} from "./market-rates";
|
|
import {pythonInterpreterTool, runPythonInterpreter} from "./python-interpretator";
|
|
import {
|
|
copyPath,
|
|
copyPathTool,
|
|
createDirectory,
|
|
createDirectoryTool,
|
|
createFile,
|
|
createFileTool,
|
|
deletePath,
|
|
deletePathTool,
|
|
listDirectory,
|
|
listDirectoryTool,
|
|
readFile,
|
|
readFileTool,
|
|
renamePath,
|
|
renamePathTool,
|
|
updateFile,
|
|
updateFileTool
|
|
} from "./file-system";
|
|
|
|
export const getTools = () => {
|
|
const tools: AiTool[] = [
|
|
getCurrentDateTimeTool,
|
|
getMarketRatesTool,
|
|
];
|
|
|
|
if (Environment.ENABLE_PYTHON_INTERPRETER) {
|
|
tools.push(pythonInterpreterTool);
|
|
}
|
|
|
|
if (Environment.ENABLE_UNSAFE_EVAL) {
|
|
tools.push(shellExecuteTool);
|
|
}
|
|
|
|
if (Environment.BRAVE_SEARCH_API_KEY) {
|
|
tools.push(braveSearchTool);
|
|
}
|
|
|
|
if (Environment.OPEN_WEATHER_MAP_API_KEY) {
|
|
tools.push(getWeatherTool);
|
|
}
|
|
|
|
if (Environment.FILE_TOOLS_ROOT_DIR && Environment.ENABLE_FS_TOOLS) {
|
|
tools.push(
|
|
readFileTool,
|
|
listDirectoryTool,
|
|
createFileTool,
|
|
createDirectoryTool,
|
|
updateFileTool,
|
|
renamePathTool,
|
|
copyPathTool,
|
|
deletePathTool,
|
|
);
|
|
}
|
|
|
|
return tools;
|
|
};
|
|
|
|
export const getToolHandlers = () => {
|
|
let handlers: Record<string, ToolHandler> = {
|
|
get_datetime: getCurrentDateTime,
|
|
get_market_rates: getMarketRates,
|
|
};
|
|
|
|
if (Environment.ENABLE_PYTHON_INTERPRETER) {
|
|
handlers = {
|
|
python_interpreter: runPythonInterpreter,
|
|
...handlers
|
|
};
|
|
}
|
|
|
|
if (Environment.ENABLE_UNSAFE_EVAL) {
|
|
handlers = {
|
|
shell_execute: shellExecute,
|
|
...handlers,
|
|
};
|
|
}
|
|
|
|
if (Environment.BRAVE_SEARCH_API_KEY) {
|
|
handlers = {
|
|
web_search: webSearch,
|
|
...handlers,
|
|
};
|
|
}
|
|
|
|
if (Environment.OPEN_WEATHER_MAP_API_KEY) {
|
|
handlers = {
|
|
get_weather: getWeather,
|
|
...handlers,
|
|
};
|
|
}
|
|
|
|
if (Environment.FILE_TOOLS_ROOT_DIR && Environment.ENABLE_FS_TOOLS) {
|
|
handlers = {
|
|
read_file: readFile,
|
|
list_directory: listDirectory,
|
|
create_file: createFile,
|
|
create_directory: createDirectory,
|
|
update_file: updateFile,
|
|
rename_path: renamePath,
|
|
copy_path: copyPath,
|
|
delete_path: deletePath,
|
|
...handlers,
|
|
};
|
|
}
|
|
|
|
return handlers;
|
|
};
|