@@ -11,70 +11,6 @@ import type { BatchConfig, BatchState, BatchResult } from "@/types/batch";
1111import { DEFAULT_BATCH_CONFIG } from "@/types/batch" ;
1212import { persistentStorage } from "@/lib/storage" ;
1313import { isImageUrl , isVideoUrl } from "@/lib/mediaUtils" ;
14- import {
15- useAssetsStore ,
16- detectAssetType ,
17- } from "@/stores/assetsStore" ;
18-
19- /* ── Store-level auto-save to My Assets ───────────────────────────────── */
20-
21- /**
22- * Track prediction IDs that are currently being auto-saved (or already saved)
23- * from the store layer. Shared between autoSaveToAssets and OutputDisplay
24- * to prevent duplicate saves when both fire concurrently.
25- */
26- export const storeSavedPredictionIds = new Set < string > ( ) ;
27-
28- /**
29- * Auto-save prediction outputs to My Assets from the store layer.
30- * This runs immediately when a prediction completes, regardless of which
31- * tab is currently active — fixing the bug where switching tabs during
32- * generation caused the OutputDisplay useEffect to miss the save.
33- * Fire-and-forget; errors are logged but never thrown.
34- */
35- function autoSaveToAssets (
36- outputs : ( string | Record < string , unknown > ) [ ] ,
37- modelId : string ,
38- predictionId : string | undefined ,
39- ) : void {
40- if ( ! predictionId ) return ;
41- if ( storeSavedPredictionIds . has ( predictionId ) ) return ;
42-
43- const { settings, saveAsset, hasAssetForPrediction } =
44- useAssetsStore . getState ( ) ;
45- if ( ! settings . autoSaveAssets ) return ;
46- if ( hasAssetForPrediction ( predictionId ) ) return ;
47-
48- // Mark immediately to prevent concurrent duplicate from OutputDisplay
49- storeSavedPredictionIds . add ( predictionId ) ;
50-
51- const unsaved : { output : string ; index : number } [ ] = [ ] ;
52- for ( let i = 0 ; i < outputs . length ; i ++ ) {
53- const output = outputs [ i ] ;
54- if ( typeof output !== "string" ) continue ;
55- if ( output . startsWith ( "local-asset://" ) ) continue ;
56- const assetType = detectAssetType ( output ) ;
57- if ( ! assetType ) continue ;
58- unsaved . push ( { output, index : i } ) ;
59- }
60- if ( unsaved . length === 0 ) return ;
61-
62- // Fire-and-forget — save each output
63- ( async ( ) => {
64- for ( const { output, index } of unsaved ) {
65- try {
66- await saveAsset ( output , detectAssetType ( output ) ! , {
67- modelId,
68- predictionId,
69- originalUrl : output ,
70- resultIndex : index ,
71- } ) ;
72- } catch ( err ) {
73- console . error ( "[playgroundStore] auto-save asset failed:" , err ) ;
74- }
75- }
76- } ) ( ) ;
77- }
7814
7915/* ── Playground session persistence ───────────────────────────────────── */
8016
@@ -643,9 +579,6 @@ export const usePlaygroundStore = create<PlaygroundState>((set, get) => ({
643579 : tab ,
644580 ) ,
645581 } ) ) ;
646-
647- // Auto-save outputs to My Assets from store layer (tab-switch safe)
648- autoSaveToAssets ( outputs , selectedModel . model_id , result . id ) ;
649582 } catch ( error ) {
650583 // Don't show error for user-initiated abort
651584 const isAbort =
@@ -912,9 +845,6 @@ export const usePlaygroundStore = create<PlaygroundState>((set, get) => ({
912845 : tab ,
913846 ) ,
914847 } ) ) ;
915-
916- // Auto-save outputs to My Assets from store layer (tab-switch safe)
917- autoSaveToAssets ( batchOutputs , selectedModel . model_id , result . id ) ;
918848 } catch ( error ) {
919849 // Skip state updates for aborted requests
920850 const isAbort =
0 commit comments