Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions ex_app/lib/all_tools/files.py
Original file line number Diff line number Diff line change
@@ -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,
]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down