@@ -427,9 +427,12 @@ export async function listHfRepoGgufFiles(
427427 throw new Error ( 'repoId is required' ) ;
428428 }
429429
430- const url = `https://huggingface.co/api/models/${ encodeURIComponent (
431- trimmed ,
432- ) } /tree/main`;
430+ // Note: repoId should NOT be fully URL-encoded as HF expects the slash unencoded
431+ const [ owner , repo ] = trimmed . split ( '/' ) ;
432+ const encodedRepoPath = owner && repo
433+ ? `${ encodeURIComponent ( owner ) } /${ encodeURIComponent ( repo ) } `
434+ : encodeURIComponent ( trimmed ) ; // fallback for malformed repoId
435+ const url = `https://huggingface.co/api/models/${ encodedRepoPath } /tree/main` ;
433436
434437 const raw = await fetchJson < any [ ] > ( url ) ;
435438
@@ -727,9 +730,13 @@ export async function downloadHfModel(
727730 ensureDirSync ( MODEL_DIR ) ;
728731
729732 const id = `${ repoId } /${ fileName } ` ;
730- const url = `https://huggingface.co/${ encodeURIComponent (
731- repoId ,
732- ) } /resolve/main/${ encodeURIComponent ( fileName ) } ?download=true`;
733+ // Note: repoId should NOT be fully URL-encoded as HF expects the slash unencoded
734+ // Only encode individual parts of the repo path (owner/repo)
735+ const [ owner , repo ] = repoId . split ( '/' ) ;
736+ const encodedRepoPath = owner && repo
737+ ? `${ encodeURIComponent ( owner ) } /${ encodeURIComponent ( repo ) } `
738+ : encodeURIComponent ( repoId ) ; // fallback for malformed repoId
739+ const url = `https://huggingface.co/${ encodedRepoPath } /resolve/main/${ encodeURIComponent ( fileName ) } ?download=true` ;
733740
734741 const destPath = path . join ( MODEL_DIR , fileName ) ;
735742 const tmpPath = destPath + '.download' ;
0 commit comments