MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / copy_path

Function copy_path

functions/function_calling/file.py:638–671  ·  view source on GitHub ↗

Copy a file tree within the workspace.

(
    src: Annotated[str, ParamMeta(description="Source workspace-relative path")],
    dst: Annotated[str, ParamMeta(description="Destination workspace-relative path")],
    *,
    overwrite: Annotated[
        bool,
        ParamMeta(description="Allow replacing destination if it exists"),
    ] = False,
    _context: Dict[str, Any] | None = None,
)

Source from the content-addressed store, hash-verified

636
637
638def copy_path(
639 src: Annotated[str, ParamMeta(description="Source workspace-relative path")],
640 dst: Annotated[str, ParamMeta(description="Destination workspace-relative path")],
641 *,
642 overwrite: Annotated[
643 bool,
644 ParamMeta(description="Allow replacing destination if it exists"),
645 ] = False,
646 _context: Dict[str, Any] | None = None,
647) -> Dict[str, Any]:
648 """Copy a file tree within the workspace."""
649
650 ctx = FileToolContext(_context)
651 source = ctx.resolve_under_workspace(src)
652 destination = ctx.resolve_under_workspace(dst)
653 _check_attachments_not_modified(dst)
654
655 if not source.exists():
656 raise FileNotFoundError(f"Source does not exist: {src}")
657 if destination.exists():
658 if not overwrite:
659 raise FileExistsError(f"Destination already exists: {dst}")
660 _clear_destination(destination, overwrite=True)
661
662 destination.parent.mkdir(parents=True, exist_ok=True)
663 if source.is_dir():
664 shutil.copytree(source, destination)
665 else:
666 shutil.copy2(source, destination)
667 return {
668 "path": ctx.to_workspace_relative(destination),
669 "source": ctx.to_workspace_relative(source),
670 "operation": "copy",
671 }
672
673
674def move_path(

Callers

nothing calls this directly

Calls 6

to_workspace_relativeMethod · 0.95
ParamMetaClass · 0.90
FileToolContextClass · 0.85
_clear_destinationFunction · 0.85

Tested by

no test coverage detected