from typesafe_sdk import TypeSafeClient, Choice, Score, Noul

state = {'ticket': {'subject': 'Duplicate subscription charge', 'message': 'I was charged twice this month. Please refund the duplicate before Friday.'}, 'customer_plan': 'pro'}
with TypeSafeClient() as client:
    response = client.system_one(
        model="jev-1.13.0",
        state=state,
        questions={
            "department": Choice(
                instructions="Which team should handle this ticket?",
                criteria={"billing": "Payments and refunds", "technical": "Bugs and outages",
                          "sales": "New purchases", "other": "None of these"}),
            "urgency": Score(
                instructions="How urgent is the request?",
                criteria=["No deadline", "This week", "Within a day", "Immediate harm"]),
            "refund_requested": Noul(
                instructions="Does the customer explicitly request a refund?")
        }
    )

answer = response.choices["department"]
# Educational threshold, not a production recommendation.
queue = answer.choice if answer.confidence >= 0.85 else "manual_review"
print({"queue": queue, "confidence": answer.confidence,
       "urgency": response.scores["urgency"].score,
       "refund_requested": response.nouls["refund_requested"].noul,
       "model": response.model, "usage": response.usage})
