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

Class WorkspaceCommandContext

functions/function_calling/uv_related.py:38–61  ·  view source on GitHub ↗

Resolve the workspace root from the injected runtime context.

Source from the content-addressed store, hash-verified

36
37
38class WorkspaceCommandContext:
39 """Resolve the workspace root from the injected runtime context."""
40
41 def __init__(self, ctx: Dict[str, Any] | None):
42 if ctx is None:
43 raise ValueError("_context is required for uv tools")
44 self.workspace_root = self._require_workspace(ctx.get("python_workspace_root"))
45 self._raw_ctx = ctx
46
47 @staticmethod
48 def _require_workspace(raw_path: Any) -> Path:
49 if raw_path is None:
50 raise ValueError("python_workspace_root missing from _context")
51 path = Path(raw_path).expanduser().resolve()
52 path.mkdir(parents=True, exist_ok=True)
53 return path
54
55 def resolve_under_workspace(self, relative_path: str | Path) -> Path:
56 candidate = Path(relative_path)
57 absolute = candidate if candidate.is_absolute() else self.workspace_root / candidate
58 absolute = absolute.expanduser().resolve()
59 if self.workspace_root not in absolute.parents and absolute != self.workspace_root:
60 raise ValueError("script path is outside workspace root")
61 return absolute
62
63
64def _validate_packages(packages: Sequence[str]) -> List[str]:

Callers 3

install_python_packagesFunction · 0.85
init_python_envFunction · 0.85
uv_runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected