@@ -274,14 +274,16 @@ async def requirements(
274274 "max_depth" : max_depth ,
275275 "auto_detect_depth" : auto_detect_depth ,
276276 }
277-
277+
278278 # Add solution storage parameters if requested
279279 if save_solution :
280280 nested_params ["save_solution" ] = True
281281 if solution_ttl_days :
282282 nested_params ["solution_ttl_days" ] = solution_ttl_days
283283 if solution_tags :
284- nested_params ["solution_tags" ] = [tag .strip () for tag in solution_tags .split ("," )]
284+ nested_params ["solution_tags" ] = [
285+ tag .strip () for tag in solution_tags .split ("," )
286+ ]
285287
286288 # Create request data based on domain and input type
287289 if detected_domain == "manufacturing" :
@@ -346,15 +348,18 @@ async def http_match():
346348 import httpx
347349
348350 raise httpx .ConnectError ("Use fallback for local facility file" )
349-
351+
350352 # If nested matching with local file, use fallback (BOM file resolution needs manifest path)
351353 if max_depth > 0 and not is_url :
352354 cli_ctx .log (
353355 "Nested matching with local file - using fallback for BOM file resolution" ,
354356 "info" ,
355357 )
356358 import httpx
357- raise httpx .ConnectError ("Use fallback for nested matching with local file" )
359+
360+ raise httpx .ConnectError (
361+ "Use fallback for nested matching with local file"
362+ )
358363
359364 cli_ctx .log ("Attempting HTTP API matching..." , "info" )
360365 try :
@@ -440,40 +445,57 @@ async def fallback_match():
440445 okh_service = okh_service ,
441446 manifest_path = manifest_path ,
442447 )
443-
448+
444449 # Save solution if requested
445450 solution_id = None
446451 if save_solution :
447452 try :
448453 from ..core .services .storage_service import StorageService
449- from ..config .storage_config import get_default_storage_config
450-
454+ from ..config .storage_config import (
455+ get_default_storage_config ,
456+ )
457+
451458 storage_service = await StorageService .get_instance ()
452- await storage_service .configure (get_default_storage_config ())
453-
459+ await storage_service .configure (
460+ get_default_storage_config ()
461+ )
462+
454463 # Parse tags if provided
455464 tags_list = None
456465 if solution_tags :
457- tags_list = [tag .strip () for tag in solution_tags .split ("," )]
458-
466+ tags_list = [
467+ tag .strip () for tag in solution_tags .split ("," )
468+ ]
469+
459470 # Use default TTL of 30 days if not provided
460- ttl_days = solution_ttl_days if solution_ttl_days is not None else 30
461- solution_id = await storage_service .save_supply_tree_solution (
462- solution ,
463- ttl_days = ttl_days ,
464- tags = tags_list ,
471+ ttl_days = (
472+ solution_ttl_days
473+ if solution_ttl_days is not None
474+ else 30
475+ )
476+ solution_id = (
477+ await storage_service .save_supply_tree_solution (
478+ solution ,
479+ ttl_days = ttl_days ,
480+ tags = tags_list ,
481+ )
482+ )
483+ cli_ctx .log (
484+ f"Solution saved to storage with ID: { solution_id } " ,
485+ "info" ,
465486 )
466- cli_ctx .log (f"Solution saved to storage with ID: { solution_id } " , "info" )
467487 except Exception as e :
468488 cli_ctx .log (f"Failed to save solution: { str (e )} " , "warning" )
469489 # Continue without failing the match
470-
490+
471491 # Convert to response format matching API
472492 # For nested solutions, count trees, not solutions
473493 solution_dict = solution .to_dict ()
474494 num_trees = len (solution .all_trees ) if solution .all_trees else 0
475495 result = {
476- "solutions" : [solution_dict ], # Wrap in array for consistency with display logic
496+ "solutions" : [
497+ solution_dict
498+ ], # Wrap in array for consistency with display logic
477499 "solution" : solution_dict , # Also include singular for API compatibility
478500 "total_solutions" : num_trees , # Count trees found, not solution count
479501 "matching_mode" : "nested" ,
@@ -511,42 +533,64 @@ async def fallback_match():
511533 if save_solution and results_list :
512534 try :
513535 from ..core .services .storage_service import StorageService
514- from ..core .models .supply_trees import SupplyTree , SupplyTreeSolution
515- from ..config .storage_config import get_default_storage_config
516-
536+ from ..core .models .supply_trees import (
537+ SupplyTree ,
538+ SupplyTreeSolution ,
539+ )
540+ from ..config .storage_config import (
541+ get_default_storage_config ,
542+ )
543+
517544 storage_service = await StorageService .get_instance ()
518- await storage_service .configure (get_default_storage_config ())
519-
545+ await storage_service .configure (
546+ get_default_storage_config ()
547+ )
548+
520549 # Convert best result to SupplyTreeSolution
521550 best_result = results_list [0 ] # Already sorted by score
522551 tree = SupplyTree .from_dict (best_result .to_dict ())
523-
552+
524553 solution = SupplyTreeSolution (
525554 all_trees = [tree ],
526555 score = best_result .score ,
527556 metadata = {
528- "okh_id" : str (manifest .id ) if hasattr (manifest , 'id' ) else None ,
557+ "okh_id" : (
558+ str (manifest .id )
559+ if hasattr (manifest , "id" )
560+ else None
561+ ),
529562 "matching_mode" : "single-level" ,
530- }
563+ },
531564 )
532-
565+
533566 # Parse tags if provided
534567 tags_list = None
535568 if solution_tags :
536- tags_list = [tag .strip () for tag in solution_tags .split ("," )]
537-
569+ tags_list = [
570+ tag .strip () for tag in solution_tags .split ("," )
571+ ]
572+
538573 # Use default TTL of 30 days if not provided
539- ttl_days = solution_ttl_days if solution_ttl_days is not None else 30
540- solution_id = await storage_service .save_supply_tree_solution (
541- solution ,
542- ttl_days = ttl_days ,
543- tags = tags_list ,
574+ ttl_days = (
575+ solution_ttl_days
576+ if solution_ttl_days is not None
577+ else 30
578+ )
579+ solution_id = (
580+ await storage_service .save_supply_tree_solution (
581+ solution ,
582+ ttl_days = ttl_days ,
583+ tags = tags_list ,
584+ )
585+ )
586+ cli_ctx .log (
587+ f"Solution saved to storage with ID: { solution_id } " ,
588+ "info" ,
544589 )
545- cli_ctx .log (f"Solution saved to storage with ID: { solution_id } " , "info" )
546590 except Exception as e :
547591 cli_ctx .log (f"Failed to save solution: { str (e )} " , "warning" )
548592 # Continue without failing the match
549-
593+
550594 if results_list :
551595 result = {
552596 "solutions" : [r .to_dict () for r in results_list ],
@@ -1181,7 +1225,7 @@ async def _display_match_results(
11811225 # Handle both old format (matches) and new format (solutions)
11821226 solutions = result .get ("solutions" , result .get ("matches" , []))
11831227 total_solutions = result .get ("total_solutions" , len (solutions ))
1184-
1228+
11851229 # Check if solution was saved (from API response or fallback)
11861230 solution_id = result .get ("solution_id" )
11871231 if solution_id :
0 commit comments