1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! Unofficial Rust client for [TypeSafe AI](https://typesafe.ai)'s **Jev** model.
//!
//! Jev is a "System One" model: it never generates text. A request carries a `state` plus a map
//! of typed questions (`noul`, `choice`, `score`) and the response carries calibrated
//! probabilities over answers the caller defined.
//!
//! This crate is the library half of the [`jev` command-line tool]. It owns the typed request and
//! answer model, offline validation, the HTTP transport with retries, and typed errors. It
//! deliberately knows nothing about command-line parsing, terminals or configuration files, so it
//! can be used on its own as a Rust client.
//!
//! # The typed model
//!
//! [`Request`] holds a `state` and a map of [`Question`]s ([`Noul`], [`Choice`], [`Score`]);
//! [`Response`] holds one [`Answer`] per question plus [`Usage`]. `state`, `instructions` and
//! criteria values are free-form [`Content`]. [`ModelList`] is the body of `GET /v1/models`, and
//! [`pricing`] turns usage into an estimated cost.
//!
//! ```
//! use jev_client::{Noul, Request, Response, pricing};
//!
//! let request = Request::new("Help! My payouts have been failing for 3 days.", "jev-latest")
//! .question("is_urgent", Noul::new("Does this convey urgency?"));
//! assert!(serde_json::to_string(&request).unwrap().contains(r#""type":"noul""#));
//!
//! let response: Response = serde_json::from_str(
//! r#"{
//! "model": "jev-1.13.0",
//! "answers": { "is_urgent": { "type": "noul", "noul": 0.92 } },
//! "usage": { "input_tokens": 312, "output_tokens": 48 }
//! }"#,
//! )
//! .unwrap();
//!
//! let is_urgent = response.answers.get("is_urgent").and_then(|answer| answer.as_noul());
//! assert_eq!(is_urgent.map(|answer| answer.noul), Some(0.92));
//! assert!(pricing::estimate_cost_usd(&response.model, response.usage).is_some());
//! ```
//!
//! Three properties hold across these types:
//!
//! - **Requests are sent as written.** Key order is preserved, an explicit `null` stays distinct
//! from an absent key, and fields this crate does not know are kept and passed through. They are
//! kept rather than dropped because the API silently accepts an unknown field inside a question,
//! so offline validation needs to see a misspelt `criteria` to report it.
//! - **Responses parse tolerantly.** Unknown fields are ignored, and an answer of an unknown type
//! (or a known type whose shape has changed) is kept as raw JSON in [`Answer::Unknown`] instead
//! of failing the whole response.
//! - **One definition, many uses.** Every type derives [`schemars::JsonSchema`], so the JSON
//! Schemas handed to editors, AI agents and MCP clients cannot drift from what is parsed.
//!
//! # Talking to the API
//!
//! [`Transport`] is the seam: `evaluate` and `list_models`, each returning a [`Reply`] with the
//! parsed body plus the request id, latency and attempt count. [`HttpTransport`] is the real one.
//! Code that needs the API should depend on the trait, so its tests can use an in-memory fake.
//!
//! - **Credentials.** [`ApiKey`] wipes itself on drop and never prints. [`BaseUrl`] insists on
//! `https://` (plain HTTP only for loopback, or by explicit opt-in), and redirects are not
//! followed, so the key cannot be sent somewhere unexpected.
//! - **Retries.** [`RetryPolicy`] defaults to the official SDKs' behaviour: 2 retries with jittered
//! exponential backoff for 408, 429, 5xx, timeouts and connection failures, honouring
//! `Retry-After`. 400, 401, 403, 404 and 422 are never retried. [`Clock`] keeps tests instant.
//! A [`Throttle`] shared by concurrent calls makes a 429 or 529 on one of them slow all of them.
//! - **Errors.** One [`Error`] with an [`ErrorKind`] mirroring the SDKs' error classes, carrying
//! the HTTP status, the API's `error_type`, and the `x-typesafe-request-id`. No error ever
//! contains the API key or a request's `state`.
//! - **Logging.** `tracing` events at `DEBUG` cover method, URL, status, timing, request id and
//! retry decisions. Bodies are traced only on explicit opt-in, and `Authorization` never is.
//!
//! The types describe shapes only. Limits such as 255 choice options or 2 to 10 score levels are
//! enforced by [`validate`], which checks a request offline and reports every problem at once, each
//! with the question it is in, a path, a stable rule id and a suggested fix.
//!
//! This project is not affiliated with, endorsed by, or sponsored by TypeSafe AI.
//!
//! [`jev` command-line tool]: https://github.com/shaharia-lab/jev-cli
pub use ;
pub use ;
pub use ;
pub use Content;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Request;
pub use ;
pub use RetryPolicy;
pub use ;
pub use Throttle;
pub use ;
/// Version of this crate, as published.
///
/// The command-line tool reports it, and the HTTP transport will send it in the `User-Agent`.
pub const VERSION: &str = env!;