@@ -2,6 +2,7 @@ import type { RunArgs, UvArgs } from '../types.js';
22import  type  {  JobsApiClient  }  from  '../api-client.js' ; 
33import  {  createJobSpec  }  from  './utils.js' ; 
44import  {  fetchJobLogs  }  from  '../sse-handler.js' ; 
5+ import  {  buildUvCommand ,  UV_DEFAULT_IMAGE ,  wrapInlineScript  }  from  './uv-utils.js' ; 
56
67/** 
78 * Execute the 'run' command 
@@ -64,26 +65,18 @@ To inspect: \`hf_jobs("inspect", {"job_id": "${job.id}"})\``;
6465 */ 
6566export  async  function  uvCommand ( args : UvArgs ,  client : JobsApiClient ,  token ?: string ) : Promise < string >  { 
6667	// UV jobs use a standard UV image unless overridden 
67- 	const  image  =  'ghcr.io/astral-sh/uv:latest' ;   // Standard UV image 
68+ 	const  image  =  UV_DEFAULT_IMAGE ; 
6869
6970	// Detect script source and build command 
7071	const  scriptSource  =  args . script ; 
7172	let  command : string  |  string [ ] ; 
7273
73- 	// Check if script is a URL 
7474	if  ( scriptSource . startsWith ( 'http://' )  ||  scriptSource . startsWith ( 'https://' ) )  { 
7575		// URL - download and run 
7676		command  =  buildUvCommand ( scriptSource ,  args ) ; 
7777	}  else  if  ( scriptSource . includes ( '\n' ) )  { 
7878		// Inline multi-line script - encode it 
79- 		const  encoded  =  Buffer . from ( scriptSource ) . toString ( 'base64' ) ; 
80- 		const  depsPart  = 
81- 			args . with_deps  &&  args . with_deps . length  >  0 
82- 				? args . with_deps . map ( dep  =>  `--with ${ dep }  ) . join ( ' ' ) 
83- 				: '' ; 
84- 		const  pythonPart  =  args . python  ? `-p ${ args . python }   : '' ; 
85- 		const  uvArgs  =  [ depsPart ,  pythonPart ] . filter ( Boolean ) . join ( ' ' ) ; 
86- 		const  shellSnippet  =  `echo "${ encoded } ${ uvArgs  ? ` ${ uvArgs }   : '' }  ; 
79+ 		const  shellSnippet  =  wrapInlineScript ( scriptSource ,  args ) ; 
8780		command  =  [ '/bin/sh' ,  '-lc' ,  shellSnippet ] ; 
8881	}  else  { 
8982		// Assume it's a URL or path - UV will handle it 
@@ -104,32 +97,3 @@ export async function uvCommand(args: UvArgs, client: JobsApiClient, token?: str
10497
10598	return  runCommand ( runArgs ,  client ,  token ) ; 
10699} 
107- 
108- /** 
109-  * Build UV command with options 
110-  */ 
111- function  buildUvCommand ( script : string ,  args : UvArgs ) : string  { 
112- 	const  parts : string [ ]  =  [ 'uv' ,  'run' ] ; 
113- 
114- 	// Add dependencies 
115- 	if  ( args . with_deps  &&  args . with_deps . length  >  0 )  { 
116- 		for  ( const  dep  of  args . with_deps )  { 
117- 			parts . push ( '--with' ,  dep ) ; 
118- 		} 
119- 	} 
120- 
121- 	// Add Python version 
122- 	if  ( args . python )  { 
123- 		parts . push ( '-p' ,  args . python ) ; 
124- 	} 
125- 
126- 	// Add script 
127- 	parts . push ( script ) ; 
128- 
129- 	// Add script arguments 
130- 	if  ( args . script_args  &&  args . script_args . length  >  0 )  { 
131- 		parts . push ( ...args . script_args ) ; 
132- 	} 
133- 
134- 	return  parts . join ( ' ' ) ; 
135- } 
0 commit comments