66import time
77import asyncio
88import itertools
9- from typing import Any
9+ from typing import Any , cast
1010from pathlib import Path
1111
1212import click
@@ -107,13 +107,13 @@ async def spinner_updater(self) -> None:
107107 self .update_progress ()
108108 await asyncio .sleep (0.1 )
109109
110- async def upload_files (self , source_path : Path , volume_name : str ) -> None :
110+ async def upload_files (self , source_path : Path , volume_name : str , content_version : int ) -> None :
111111 """Upload all files from source directory with progress tracking"""
112112 # these require a running event loop
113113 self .semaphore = asyncio .Semaphore (UPLOAD_CONCURRENCY_LIMIT )
114114 self .progress_lock = asyncio .Lock ()
115115
116- source_prefix = f"{ volume_name } /{ source_path . name } "
116+ source_prefix = f"{ volume_name } /{ content_version } "
117117 files_to_upload : list [tuple [Path , str , int ]] = []
118118
119119 for file_path in source_path .rglob ("*" ):
@@ -296,7 +296,8 @@ async def _create_volume(client: Together, name: str, source: str) -> None:
296296 if not source_path .is_dir ():
297297 raise ValueError (f"Source path must be a directory: { source } " )
298298
299- source_prefix = f"{ name } /{ source_path .name } "
299+ content_version = 0
300+ source_prefix = f"{ name } /{ content_version } "
300301
301302 click .echo (f"\N{ROCKET} Creating volume '{ name } ' with source prefix '{ source_prefix } '" )
302303 try :
@@ -310,7 +311,7 @@ async def _create_volume(client: Together, name: str, source: str) -> None:
310311 raise RuntimeError (f"Failed to create volume: { e } " ) from e
311312
312313 try :
313- await Uploader (client ).upload_files (source_path , volume_name = name )
314+ await Uploader (client ).upload_files (source_path , volume_name = name , content_version = content_version )
314315 except Exception as e :
315316 click .echo (f"\N{CROSS MARK} Upload failed: { e } " )
316317 click .echo (f"\N{WASTEBASKET} Cleaning up volume '{ name } '" )
@@ -330,16 +331,20 @@ async def _update_volume(client: Together, name: str, source: str) -> None:
330331 raise ValueError (f"Source path must be a directory: { source } " )
331332
332333 try :
333- client .beta .jig .volumes .retrieve (name )
334+ response = client .beta .jig .volumes .with_raw_response .retrieve (name )
335+ volume_data = response .json ()
334336 except APIStatusError as e :
335337 if hasattr (e , "status_code" ) and e .status_code == 404 :
336338 raise ValueError (f"Volume '{ name } ' does not exist" ) from e
337339 raise
338340
339- source_prefix = f"{ name } /{ source_path .name } "
341+ volume_dict = cast (dict [str , Any ], volume_data )
342+ current_version : int = int (volume_dict .get ("current_version" , 0 ))
343+ version : int = current_version + 1
344+ source_prefix = f"{ name } /{ version } "
340345
341346 click .echo (f"\N{INFORMATION SOURCE} Uploading files for volume '{ name } '" )
342- await Uploader (client ).upload_files (source_path , volume_name = name )
347+ await Uploader (client ).upload_files (source_path , volume_name = name , content_version = version )
343348
344349 click .echo (f"\N{INFORMATION SOURCE} Updating volume '{ name } ' with source prefix '{ source_prefix } '" )
345350 client .beta .jig .volumes .update (
0 commit comments