diff --git a/ex_app/lib/all_tools/files.py b/ex_app/lib/all_tools/files.py new file mode 100644 index 0000000..2f3a39b --- /dev/null +++ b/ex_app/lib/all_tools/files.py @@ -0,0 +1,61 @@ +# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: AGPL-3.0-or-later +from langchain_core.tools import tool +from nc_py_api import Nextcloud + +from typing import Optional + +from ex_app.lib.all_tools.lib.decorator import safe_tool, dangerous_tool + + +def get_tools(nc: Nextcloud): + + @tool + @safe_tool + def get_file_content(file_path: str): + """ + Get the content of a file + :param file_path: the path of the file + :return: + """ + + user_id = nc.ocs('GET', '/ocs/v2.php/cloud/user')["id"] + + response = nc._session._create_adapter(True).request('GET', f"{nc.app_cfg.endpoint}/remote.php/dav/files/{user_id}/{file_path}", headers={ + "Content-Type": "application/json", + }) + + return response.text + + @tool + @safe_tool + def get_folder_tree(depth: int): + """ + Get the folder tree of the user + :param depth: the depth of the returned folder tree + :return: + """ + + return nc.ocs('GET', '/ocs/v2.php/apps/files/api/v1/folder-tree', json={'depth': depth}, response_type='json') + + @tool + @dangerous_tool + def create_public_sharing_link(path: str): + """ + Creates a public sharing link for a file or folder + :param path: the path of the file or folder + :return: + """ + + response = nc.ocs('POST', '/ocs/v2.php/apps/files_sharing/api/v1/shares', json={ + 'path': path, + 'shareType': 3, + }) + + return response + + return [ + get_file_content, + get_folder_tree, + create_public_sharing_link, + ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3940f72..f2d32ea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors # SPDX-License-Identifier: AGPL-3.0-or-later -nc_py_api[app]>=0.17.1 -nc_py_api[calendar]>=0.17.1 +nc_py_api[app]>=0.19.2 +nc_py_api[calendar]>=0.19.2 langgraph langchain ics