2323 TargetSignatures ,
2424 ToolOutput ,
2525)
26+ from pyoaev .signatures .types import ExpectationType
2627
2728if TYPE_CHECKING :
2829 from pyoaev .client import OpenAEV
@@ -172,10 +173,11 @@ def _merge_post(
172173
173174 return merged
174175
176+ @staticmethod
175177 def build_payload (
176- self ,
177178 post_signatures : dict [str , Any ] | list [dict [str , Any ]],
178179 expectation_types : list [str ],
180+ extra_signature : dict | None = None ,
179181 ) -> dict [str , Any ]:
180182 """Build the nested wire payload from flat post-execution signatures.
181183
@@ -185,26 +187,54 @@ def build_payload(
185187 Args:
186188 post_signatures: A single post-execution dict or a list (multi-targets).
187189 expectation_types: The 1+ expectation type labels (e.g. ['DETECTION', 'PREVENTION']).
190+ extra_signature: Optional mapping of expectation types to additional signature fields that will be merged
191+ into the base post_signatures.
188192
189193 Returns:
190194 A payload dict ready for send_signatures.
191195 """
192196 if isinstance (post_signatures , dict ):
193197 post_signatures = [post_signatures ]
194198
199+ # Validate expectation types
200+ expectation_types_valid = [
201+ ExpectationType (expectation_type .upper ())
202+ for expectation_type in expectation_types
203+ ]
204+ # Normalize and validate extra_signatures keys
205+ extra_signatures = {
206+ ExpectationType (key .upper ()): value
207+ for key , value in (extra_signature or {}).items ()
208+ }
209+
195210 targets = []
196- for sig in post_signatures :
197- values = [
198- SignatureValue (signature_type = k , signature_value = str (v ))
199- for k , v in sig .items ()
200- ]
201- signature_values = [
202- ExpectationSignatureGroup (
203- expectation_type = expectation_type , values = values
211+ for signature in post_signatures :
212+ signature_values = []
213+
214+ for expectation_type in expectation_types_valid :
215+ signature_data = signature .copy ()
216+ if expectation_type in extra_signatures :
217+ signature_data .update (extra_signatures [expectation_type ])
218+
219+ values = [
220+ SignatureValue (
221+ signature_type = key ,
222+ signature_value = value ,
223+ )
224+ for key , value in signature_data .items ()
225+ ]
226+
227+ signature_values .append (
228+ ExpectationSignatureGroup (
229+ expectation_type = expectation_type .value ,
230+ values = values ,
231+ )
204232 )
205- for expectation_type in expectation_types
206- ]
207- targets .append (TargetSignatures (signature_values = signature_values ))
233+ targets .append (
234+ TargetSignatures (
235+ signature_values = signature_values ,
236+ )
237+ )
208238
209239 return SignaturePayload (targets = targets ).model_dump ()
210240
0 commit comments