feat: mv data folder to root
This commit is contained in:
@@ -6,6 +6,7 @@ from urllib.parse import quote
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.core.data_root import get_data_root, get_reports_root, get_uploads_root, get_workspace_root
|
||||
|
||||
LOCAL_URI_PATTERN = re.compile(r"local://[^\s<>'\"\]\)\}]+")
|
||||
PATH_PATTERN = re.compile(
|
||||
@@ -138,11 +139,11 @@ def _normalize_locator(raw_locator: str) -> str:
|
||||
|
||||
|
||||
def _resolve_locator(locator: str) -> Path | None:
|
||||
backend_root = Path(__file__).resolve().parents[2]
|
||||
data_root = backend_root / "data"
|
||||
workspace_root = data_root / "workspace"
|
||||
uploads_root = data_root / "uploads"
|
||||
reports_root = data_root / "data"
|
||||
data_root = get_data_root()
|
||||
workspace_root = get_workspace_root()
|
||||
uploads_root = get_uploads_root()
|
||||
reports_root = get_reports_root()
|
||||
repo_root = data_root.parent
|
||||
if locator.startswith("local://"):
|
||||
raw_local = locator.replace("local://", "", 1).strip().lstrip("/\\")
|
||||
if not raw_local:
|
||||
@@ -160,11 +161,11 @@ def _resolve_locator(locator: str) -> Path | None:
|
||||
if path.is_absolute():
|
||||
return path
|
||||
if normalized.startswith("data/data/"):
|
||||
return backend_root / normalized
|
||||
return repo_root / normalized
|
||||
checks = [
|
||||
workspace_root / normalized,
|
||||
data_root / normalized,
|
||||
backend_root / normalized,
|
||||
repo_root / normalized,
|
||||
]
|
||||
for candidate in checks:
|
||||
if candidate.exists():
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
BACKEND_ROOT = Path(__file__).resolve().parents[2]
|
||||
REPO_ROOT = BACKEND_ROOT.parent
|
||||
DEFAULT_DATA_ROOT = REPO_ROOT / "data"
|
||||
LEGACY_DATA_ROOT = BACKEND_ROOT / "data"
|
||||
|
||||
|
||||
def get_data_root() -> Path:
|
||||
configured = (os.getenv("DATA_ROOT") or "").strip()
|
||||
if configured:
|
||||
return Path(configured).expanduser().resolve()
|
||||
if DEFAULT_DATA_ROOT.exists():
|
||||
return DEFAULT_DATA_ROOT
|
||||
if LEGACY_DATA_ROOT.exists():
|
||||
print(f"[DATA_ROOT] legacy path detected: {LEGACY_DATA_ROOT}. Please migrate to {DEFAULT_DATA_ROOT}.")
|
||||
return LEGACY_DATA_ROOT
|
||||
return DEFAULT_DATA_ROOT
|
||||
|
||||
|
||||
def get_workspace_root() -> Path:
|
||||
return get_data_root() / "workspace"
|
||||
|
||||
|
||||
def get_uploads_root() -> Path:
|
||||
return get_data_root() / "uploads"
|
||||
|
||||
|
||||
def get_reports_root() -> Path:
|
||||
return get_data_root() / "data"
|
||||
|
||||
|
||||
def ensure_data_layout() -> None:
|
||||
get_data_root().mkdir(parents=True, exist_ok=True)
|
||||
get_workspace_root().mkdir(parents=True, exist_ok=True)
|
||||
get_uploads_root().mkdir(parents=True, exist_ok=True)
|
||||
get_reports_root().mkdir(parents=True, exist_ok=True)
|
||||
@@ -2,12 +2,13 @@ import os
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from app.core.data_root import get_data_root, get_reports_root, get_uploads_root, get_workspace_root
|
||||
|
||||
backend_root = Path(__file__).resolve().parents[2]
|
||||
data_root = backend_root / "data"
|
||||
workspace_root = data_root / "workspace"
|
||||
uploads_root = data_root / "uploads"
|
||||
reports_root = data_root / "data"
|
||||
|
||||
data_root = get_data_root()
|
||||
workspace_root = get_workspace_root()
|
||||
uploads_root = get_uploads_root()
|
||||
reports_root = get_reports_root()
|
||||
allowed_artifact_roots = (workspace_root, uploads_root, reports_root)
|
||||
|
||||
|
||||
@@ -50,7 +51,7 @@ def resolve_artifact_target(target: str) -> Path | None:
|
||||
if path.is_absolute():
|
||||
return path
|
||||
if normalized.startswith("data/data/"):
|
||||
return backend_root / normalized
|
||||
return data_root.parent / normalized
|
||||
checks = (
|
||||
workspace_root / normalized,
|
||||
data_root / normalized,
|
||||
|
||||
@@ -34,6 +34,7 @@ from nanobot.config.schema import Config
|
||||
from app.api.skills import load_skills
|
||||
from app.services.llm_cache import get_llm_configs
|
||||
|
||||
from app.core.data_root import get_workspace_root
|
||||
from app.core.streaming_provider import StreamingLiteLLMProvider
|
||||
|
||||
class NanobotIntegration:
|
||||
@@ -47,8 +48,7 @@ class NanobotIntegration:
|
||||
self._model_agent_lock = asyncio.Lock()
|
||||
|
||||
def initialize(self):
|
||||
# Set workspace path to backend/data/workspace
|
||||
workspace_path = Path(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "data", "workspace"))
|
||||
workspace_path = get_workspace_root()
|
||||
workspace_path.mkdir(parents=True, exist_ok=True)
|
||||
self._sync_builtin_skills_to_workspace(workspace_path)
|
||||
|
||||
|
||||
@@ -5,14 +5,21 @@ from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from app.core.data_root import get_data_root
|
||||
|
||||
|
||||
class SessionAliasStore:
|
||||
def __init__(self) -> None:
|
||||
backend_root = Path(__file__).resolve().parents[2]
|
||||
data_dir = backend_root / "data"
|
||||
data_dir.mkdir(parents=True, exist_ok=True)
|
||||
data_dir = get_data_root()
|
||||
try:
|
||||
data_dir.mkdir(parents=True, exist_ok=True)
|
||||
except PermissionError as exc:
|
||||
raise RuntimeError(f"DATA_ROOT 权限不足: {data_dir}") from exc
|
||||
self.db_path = data_dir / "nanobot_sessions.db"
|
||||
self._init_db()
|
||||
try:
|
||||
self._init_db()
|
||||
except PermissionError as exc:
|
||||
raise RuntimeError(f"DATA_ROOT 权限不足: {data_dir}") from exc
|
||||
|
||||
def _connect(self) -> sqlite3.Connection:
|
||||
conn = sqlite3.connect(str(self.db_path))
|
||||
|
||||
Reference in New Issue
Block a user