commit 879ff73264e6d3c988c7bbd3c4e0694220c3b5dc
parent 2f82400203262eacfa488ced2fd058d2465f6c41
Author: triesap <tyson@radroots.org>
Date: Mon, 21 Sep 2026 13:06:11 +0000
provider: add provider response projection support
Diffstat:
2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/src/hyf_provider/jev_projection.mojo b/src/hyf_provider/jev_projection.mojo
@@ -0,0 +1,21 @@
+from std.collections import List
+
+from hyf_assist.evaluator import TypedAnswer
+
+
+def answer_by_id(answers: List[TypedAnswer], question_id: String) raises -> TypedAnswer:
+ for answer in answers:
+ if answer.question_id == question_id:
+ return answer.copy()
+ raise Error("missing provider answer: " + question_id)
+
+
+def project_choice(answers: List[TypedAnswer], question_id: String) raises -> String:
+ var answer = answer_by_id(answers, question_id)
+ if answer.kind != "choice":
+ raise Error("expected a choice answer for " + question_id)
+ return answer.choice
+
+
+def provider_cannot_supply_trusted_identity() -> Bool:
+ return True
diff --git a/tests/test_jev.mojo b/tests/test_jev.mojo
@@ -162,3 +162,25 @@ def test_jev_failure_mapping_permanent_vs_transient() raises:
assert_true(not map_jev_failure("response_validation").retryable)
with assert_raises():
_ = map_jev_failure("mystery")
+
+
+from hyf_provider.jev_projection import (
+ answer_by_id,
+ project_choice,
+ provider_cannot_supply_trusted_identity,
+)
+
+
+def test_provider_response_projection() raises:
+ var body = loads(
+ '{"model":"jev-1.13.0","answers":{'
+ '"supply_status":{"type":"choice","choice":"offered","probabilities":{"offered":1.0,"forecast":0.0,"unclear":0.0},"confidence":1.0},'
+ '"seconds_ok":{"type":"noul","noul":0.9},'
+ '"culinary_fit":{"type":"score","score":2,"legend":{"0":"u","1":"l","2":"s"},"probabilities":{"0":0.0,"1":0.0,"2":1.0},"confidence":1.0}}}'
+ )
+ var answers = parse_jev_response(body, _bundle())
+ assert_equal(project_choice(answers, "supply_status"), "offered")
+ assert_equal(answer_by_id(answers, "seconds_ok").noul, 0.9)
+ assert_true(provider_cannot_supply_trusted_identity())
+ with assert_raises():
+ _ = answer_by_id(answers, "nonexistent")