had
This commit is contained in:
@@ -8,6 +8,7 @@ from agentui.pipeline.defaults import default_pipeline
|
||||
|
||||
PIPELINE_FILE = Path("pipeline.json")
|
||||
PRESETS_DIR = Path("presets")
|
||||
VARS_DIR = Path(".agentui") / "vars"
|
||||
|
||||
|
||||
def load_pipeline() -> Dict[str, Any]:
|
||||
@@ -42,3 +43,51 @@ def save_preset(name: str, pipeline: Dict[str, Any]) -> None:
|
||||
path.write_text(json.dumps(pipeline, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
|
||||
# ---------------- Variable Store (per-pipeline) ----------------
|
||||
|
||||
def _var_store_path(pipeline_id: str) -> Path:
|
||||
pid = pipeline_id or "pipeline_editor"
|
||||
VARS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
# normalize to safe filename
|
||||
safe = "".join(ch if ch.isalnum() or ch in ("-", "_", ".") else "_" for ch in str(pid))
|
||||
return VARS_DIR / f"{safe}.json"
|
||||
|
||||
|
||||
def load_var_store(pipeline_id: str) -> Dict[str, Any]:
|
||||
"""
|
||||
Load variable store dictionary for given pipeline id.
|
||||
Returns {} if not exists or invalid.
|
||||
"""
|
||||
path = _var_store_path(pipeline_id)
|
||||
if not path.exists():
|
||||
return {}
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
return data if isinstance(data, dict) else {}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def save_var_store(pipeline_id: str, data: Dict[str, Any]) -> None:
|
||||
"""
|
||||
Save variable store dictionary for given pipeline id.
|
||||
"""
|
||||
path = _var_store_path(pipeline_id)
|
||||
try:
|
||||
VARS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
except Exception:
|
||||
pass
|
||||
path.write_text(json.dumps(data or {}, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
|
||||
def clear_var_store(pipeline_id: str) -> None:
|
||||
"""
|
||||
Delete/reset variable store for given pipeline id.
|
||||
"""
|
||||
path = _var_store_path(pipeline_id)
|
||||
try:
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
except Exception:
|
||||
# ignore failures
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user