File size: 800 Bytes
7a0b5ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pathlib import Path

from colorama import Fore, Style  # type: ignore[import]
from langchain_core.tools import tool

WORKSPACE_DIR = Path(__file__).resolve().parents[2] / "workspace"


@tool
def list_files() -> str:
    """List all files in the workspace directory.

    Returns:
        A newline-separated list of filenames in the workspace directory,
        or a message indicating the directory is empty or does not exist.
    """
    if not WORKSPACE_DIR.exists():
        return f"Workspace directory does not exist: {WORKSPACE_DIR}"

    files = [f.name for f in WORKSPACE_DIR.iterdir() if f.is_file()]

    if not files:
        return "Workspace directory is empty."

    print(f"{Fore.BLUE}[Workspace] {len(files)} file(s) found{Style.RESET_ALL}")
    return "\n".join(sorted(files))