1111from hmac import new as hmac_new
1212from json import dumps
1313from time import time
14- from typing import Literal , cast , get_args
14+ from typing import Literal , get_args
1515from urllib .parse import urlsplit
1616
1717import httpx
1818from agent_control_models import JSONObject , JSONValue , Step
1919from pydantic import BaseModel , ConfigDict , Field , PrivateAttr , model_validator
2020
21+ from ..records import UnsupportedStepTypeError , record_from_step
2122from .config import ScorerInvokeConfig
2223
2324logger = logging .getLogger (__name__ )
@@ -274,7 +275,7 @@ def to_dict(self) -> JSONObject:
274275 return request
275276
276277
277- def _orbit_record_from_step (
278+ def _scorer_invoke_record_from_step (
278279 step : Step | None ,
279280 * ,
280281 selected_input : JSONValue ,
@@ -299,21 +300,20 @@ def _orbit_record_from_step(
299300 Returns:
300301 An Orbit-compatible record, or ``None`` for absent/unsupported steps.
301302 """
302- if step is None or step . type not in SUPPORTED_SCORER_INVOKE_RECORD_TYPES :
303+ if step is None :
303304 return None
304-
305- # The membership check above narrows the runtime value to Orbit's known
306- # discriminator set, but static type checkers cannot infer that relationship.
307- record_type = cast (ScorerInvokeRecordType , step .type )
308- return ScorerInvokeRecord (
309- type = record_type ,
310- name = step .name ,
311- input = selected_input if selected_input is not None else step .input ,
312- output = selected_output if selected_output is not None else step .output ,
313- context = step .context ,
314- tools = step .tools ,
315- dataset_output = step .ground_truth ,
316- )
305+ try :
306+ record = record_from_step (
307+ step ,
308+ selected_input = selected_input ,
309+ selected_output = selected_output ,
310+ )
311+ except UnsupportedStepTypeError :
312+ return None
313+ canonical_record = record .model_dump (mode = "json" , exclude_none = True )
314+ if canonical_record .get ("type" ) not in SUPPORTED_SCORER_INVOKE_RECORD_TYPES :
315+ return None
316+ return ScorerInvokeRecord .model_validate (canonical_record )
317317
318318
319319class ScorerInvokeResponse (BaseModel ):
@@ -543,7 +543,7 @@ async def invoke(
543543 ground_truth = step .ground_truth if step is not None else None ,
544544 tools = step .tools if step is not None else None ,
545545 ),
546- record = _orbit_record_from_step (
546+ record = _scorer_invoke_record_from_step (
547547 step ,
548548 selected_input = input ,
549549 selected_output = output ,
0 commit comments