@@ -97,6 +97,24 @@ def _kitchen_failure_envelope(
9797 )
9898
9999
100+ def _recipe_validation_error_response (name : str , result : dict ) -> str : # type: ignore[type-arg]
101+ _errs : list [str ] = result .get ("errors" , [])
102+ _error_detail = "; " .join (_errs [:3 ]) if _errs else "unknown structural error"
103+ return json .dumps (
104+ {
105+ "success" : False ,
106+ "kitchen" : "failed" ,
107+ "user_visible_message" : (
108+ f"Recipe '{ name } ' failed structural validation: { _error_detail } "
109+ ),
110+ "error" : f"Recipe '{ name } ' failed validation: { _error_detail } " ,
111+ "stage" : "recipe_validation" ,
112+ "errors" : _errs ,
113+ "suggestions" : result .get ("suggestions" , []),
114+ }
115+ )
116+
117+
100118class QuotaGuardHookPayload (TypedDict ):
101119 cache_max_age : int
102120 cache_path : str
@@ -604,21 +622,7 @@ async def open_kitchen(
604622 tool_ctx .active_recipe_ingredients = None
605623 # Default to False for missing 'valid' so a absent key is treated as invalid
606624 if not result .get ("valid" , False ) or not result .get ("content" , "" ):
607- _errs = result .get ("errors" , [])
608- _error_detail = "; " .join (_errs [:3 ]) if _errs else "unknown structural error"
609- return json .dumps (
610- {
611- "success" : False ,
612- "kitchen" : "failed" ,
613- "user_visible_message" : (
614- f"Recipe '{ name } ' failed structural validation: { _error_detail } "
615- ),
616- "error" : f"Recipe '{ name } ' failed validation: { _error_detail } " ,
617- "stage" : "recipe_validation" ,
618- "errors" : _errs ,
619- "suggestions" : result .get ("suggestions" , []),
620- }
621- )
625+ return _recipe_validation_error_response (name , result )
622626 result ["success" ] = True
623627 result ["kitchen" ] = "open"
624628 result ["version" ] = __version__
@@ -705,21 +709,7 @@ async def open_kitchen(
705709 return _kitchen_failure_envelope (exc , stage = "apply_triage_gate" )
706710
707711 if not result .get ("valid" , False ) or not result .get ("content" , "" ):
708- _errs = result .get ("errors" , [])
709- _error_detail = "; " .join (_errs [:3 ]) if _errs else "unknown structural error"
710- return json .dumps (
711- {
712- "success" : False ,
713- "kitchen" : "failed" ,
714- "user_visible_message" : (
715- f"Recipe '{ name } ' failed structural validation: { _error_detail } "
716- ),
717- "error" : f"Recipe '{ name } ' failed validation: { _error_detail } " ,
718- "stage" : "recipe_validation" ,
719- "errors" : _errs ,
720- "suggestions" : result .get ("suggestions" , []),
721- }
722- )
712+ return _recipe_validation_error_response (name , result )
723713
724714 result ["success" ] = True
725715 result ["kitchen" ] = "open"
0 commit comments