From 0166cb6d384f0c39e2bd5c334eb09400b6b3b446 Mon Sep 17 00:00:00 2001 From: Shine1i Date: Tue, 3 Mar 2026 11:37:49 +0100 Subject: [PATCH] feat(recipe-studio): add HF repo ID inference and reset logic for HF state --- .gitignore | 1 + .../hooks/use-recipe-persistence.ts | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/.gitignore b/.gitignore index 8b54712a6c..0d0e7d1133 100755 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ __pycache__/ *$py.class *.so .Python +*.egg-info/ # Virtual environments .venv/ diff --git a/studio/frontend/src/features/recipe-studio/hooks/use-recipe-persistence.ts b/studio/frontend/src/features/recipe-studio/hooks/use-recipe-persistence.ts index 4546deb130..099dfb2f6b 100644 --- a/studio/frontend/src/features/recipe-studio/hooks/use-recipe-persistence.ts +++ b/studio/frontend/src/features/recipe-studio/hooks/use-recipe-persistence.ts @@ -64,6 +64,23 @@ function stripApiKeys(value: unknown): unknown { return output; } +function inferHfRepoIdFromPath(pathValue: unknown): string { + if (typeof pathValue !== "string") { + return ""; + } + const parts = pathValue + .trim() + .split("/") + .filter(Boolean); + if (parts.length >= 3 && parts[0] === "datasets") { + return `${parts[1]}/${parts[2]}`; + } + if (parts.length >= 2) { + return `${parts[0]}/${parts[1]}`; + } + return ""; +} + function sanitizeSeedForShare(payload: unknown): unknown { if (!payload || typeof payload !== "object") { return payload; @@ -95,12 +112,28 @@ function sanitizeSeedForShare(payload: unknown): unknown { typeof ui?.seed_source_type === "string" ? ui.seed_source_type : null; const sourceType = typeof source?.seed_type === "string" ? source.seed_type : null; + const shouldResetHfState = + sourceType === "hf" || uiSourceType === "hf"; const shouldResetLocalState = sourceType === "local" || sourceType === "unstructured" || uiSourceType === "local" || uiSourceType === "unstructured"; + if (shouldResetHfState) { + const repoId = inferHfRepoIdFromPath(source?.path); + if (source && "path" in source) { + source.path = repoId; + } + if (ui) { + ui.seed_columns = []; + ui.seed_drop_columns = []; + ui.seed_preview_rows = []; + ui.local_file_name = ""; + ui.unstructured_file_name = ""; + } + } + if (shouldResetLocalState) { if (source && "path" in source) { source.path = "";