com.softinio.verdict4s.algebra
Members list
Grouped members
Errors
A best-effort reading of an error response body.
A best-effort reading of an error response body.
The TypeSafe docs describe error statuses precisely but do not pin the shape of the JSON body, so this parse is deliberately total: every field is optional and raw always holds what actually arrived. A 422 carrying an envelope this version does not recognise must still surface as a Verdict4sError.Api with its body intact — turning it into a decoding failure would hide the very detail the caller needs.
Value parameters
- field
-
the offending field, for validation failures
- kind
-
a machine-readable error type, when the body names one
- message
-
a human-readable description, when the body carries one
- raw
-
the body exactly as received
Attributes
- Companion
- object
- Supertypes
A named classification of an unsuccessful HTTP status.
A named classification of an unsuccessful HTTP status.
Matching on this is steadier than matching on raw status codes: the two statuses that callers most often want to treat alike — 429 and 529 — are numerically unrelated, and 5xx is a range rather than a value.
Attributes
Refinements
Refined primitives shared across the protocol.
Refined primitives shared across the protocol.
Each of these is an Iron io.github.iltotore.iron.RefinedType, so the bound the TypeSafe API documents is carried by the type itself rather than re-checked at each use site. Literals are folded at compile time:
val p = Probability(0.95) // ok
val q = Probability(1.5) // rejected at compile time
Values arriving from JSON are not literals, so decoders use Probability.either, turning an out-of-range number from the service into a typed decoding failure instead of letting it propagate.
RefinedType produces a nominal type: unwrap it with .value. That is deliberate — the alternative, a bare Double :| C alias, is a true Double subtype but prints its whole constraint in signatures and would let Probability and Confidence be passed interchangeably.
Attributes
- Supertypes
- Self type
-
Refinements.type
Questions
A question, together with the way to read its answer back at the right type.
A question, together with the way to read its answer back at the right type.
Two things are bundled here, and both matter:
- the QuestionSpec that goes on the wire, already validated. Every constructor returns
Question[A]whether or not it had a rule to check, so a tuple of questions is uniform in its wrapper. - a decoder. Carrying it here, where
Ais statically known, is what letsAskproject answers back at exact types without a GADT match — and what makes Question.map and Question.emap one-liners.
Validation is accumulated rather than fail-fast, so a request with three malformed questions reports all three:
val q = Question.choiceOfStrings("Which team?", Seq("billing" -> None))
Attributes
Configuration
A TypeSafe API key.
A TypeSafe API key.
Deliberately a real class rather than an opaque type over String. An opaque type erases to its underlying type, so toString would be String.toString and the secret would surface in every failed assertion, every Show of a containing case class, and every stack trace. Here toString and Show both render ApiKey(***), while equals and hashCode still behave, so keys remain usable as map keys and in tests.
The secret itself is reachable only from within com.softinio.verdict4s, which is what lets the client set the Authorization header while keeping the value away from callers.
Attributes
- Companion
- object
- Supertypes
Settings a client applies to every request.
Settings a client applies to every request.
Deliberately carries no base URL. org.http4s.Uri is not available in the effect-free core, and holding the address as a String here would push a parse failure into the happy path at runtime; the client turns Defaults.BaseUrl into a compile-time-checked literal instead.
Value parameters
- model
-
the model used when a request does not name one
- requestTimeout
-
ceiling on one HTTP attempt
- retry
-
how to back off and retry
Attributes
- Companion
- object
- Supertypes
Wire-level constants, kept in the effect-free core so that the client, the environment readers and the documentation all agree on one source of truth.
Wire-level constants, kept in the effect-free core so that the client, the environment readers and the documentation all agree on one source of truth.
The base URL is a String rather than an org.http4s.Uri because core must not depend on http4s. The client turns it into a compile-time-checked literal, so a malformed default can never reach runtime.
Attributes
- Supertypes
- Self type
-
Defaults.type
How to back off and retry when the service asks you to.
How to back off and retry when the service asks you to.
The API documents 429 and 529 with an explicit instruction to retry with exponential backoff, and the official SDKs do so by default; RetryPolicy.default matches their settings.
Everything here is pure. delayFor takes the jitter sample as an argument rather than drawing one, which means the whole schedule is a function of its inputs and can be tested exactly, with no clock, no random source, and no mocking library. Drawing the sample is the client's job.
Value parameters
- backoffInitial
-
the first delay, doubled each attempt
- backoffMax
-
ceiling for the doubling
- jitter
-
0 to 1; the fraction by which a delay may vary, so that many clients retrying at once spread out instead of arriving together
- maxRetries
-
attempts after the first; 0 disables retrying
- respectRetryAfter
-
whether a
Retry-Afterheader wins when it asks for longer than the computed backoff - retryableStatuses
-
which statuses are worth retrying
- totalTimeout
-
ceiling on the whole call, retries included
Attributes
- Companion
- object
- Supertypes
Protocol
One answer, exactly as it comes off the wire.
One answer, exactly as it comes off the wire.
Untyped in the sense that a Choice answer carries the option as a String: this is the honest shape of the response, and it is what Evaluation.answers exposes. The typed views below — NoulAnswer, ChoiceAnswer, ScoreAnswer — are what the question builders project this into once the question's own type is known.
Attributes
A Choice answer, already mapped into the caller's own option type.
A Choice answer, already mapped into the caller's own option type.
Attributes
- Companion
- object
- Supertypes
A complete evaluation response.
A complete evaluation response.
Value parameters
- answers
-
one answer per question, under the keys you supplied
- model
-
the model that actually performed the evaluation, which for an alias such as
jev-latestresolves to a pinned version - usage
-
tokens consumed by the request
Attributes
- Companion
- object
- Supertypes
A complete evaluation request.
A complete evaluation request.
Value parameters
- model
-
the model that handles the request
- questions
-
the typed questions, keyed by names you choose; answers come back under the same keys
- state
-
the content to evaluate: a string for text, or structured data for chat logs, records, or application state
Attributes
- Companion
- object
- Supertypes
The instructions and criteria payload: a string, object, or array.
The instructions and criteria payload: a string, object, or array.
No JSON ADT is invented for this — io.circe.Json already is that type, and circe is already a core dependency. What this adds is the protocol's validity rule: the API accepts a string, an object or an array, so numbers, booleans and null are rejected at construction, and a string must carry actual content.
Structure is useful when a question needs to refer to data. Put the question in one field and the data in others, then reference them by name in backticks:
Instructions.encoded(
Map(
"potential_duplicate" -> "John Smith, Oakland",
"question" -> "Is the resume for the same person as `potential_duplicate`?"
)
)
Attributes
The ordered rubric of a Score question, plus how to read a level back.
The model that handles a request.
The model that handles a request.
Not an enum: the set of models is owned by the service and grows without a library release, so pinning it in a closed sum would make every new model a breaking change. The aliases below are provided as constants instead.
Attributes
Metadata for a model available to the account.
Metadata for a model available to the account.
releaseDate stays a String rather than a date: java.time is not available on Scala.js without scala-java-time, and the effect-free core does not take that dependency for one display field.
Attributes
- Companion
- object
- Supertypes
A Noul answer: how likely the answer is yes.
What a yes and a no mean, for a Noul question. Both sides are optional.
What a yes and a no mean, for a Noul question. Both sides are optional.
Attributes
- Companion
- object
- Supertypes
The option set of a Choice question, plus how to read the answer back.
The option set of a Choice question, plus how to read the answer back.
Holds three things: the rubric map that goes on the wire, and the pair of functions that turn the service's choice string into a value of A and back. Keeping the mapping next to the keys is what lets a Choice question answer in the caller's own type rather than in raw strings.
Build one with Options.strings for options only known at runtime, or derive it from an enum (see derives Options, added alongside the typed question builders).
Attributes
- Companion
- object
- Supertypes
A question exactly as it goes on the wire.
A question exactly as it goes on the wire.
Closed and non-generic on purpose: the service defines these three shapes, so this is the protocol rather than an extension point. Callers who want a question that answers in their own type use Question[A], which pairs one of these with a decoder — see the typed question builders.
QuestionSpec.Raw exists only for forward compatibility: it lets a caller send a question shape a given release does not model yet, rather than wait for a library version.
Attributes
A Score answer.
Type members
Classlikes
Reading an error body, and its decoder, which never fails.
Reading an error body, and its decoder, which never fails.
Attributes
- Companion
- class
- Supertypes
- Self type
-
ApiErrorBody.type
Classifying an HTTP status code.
Instances for ChoiceAnswer.
The default configuration, and instances.
The default configuration, and instances.
Attributes
- Companion
- class
- Supertypes
- Self type
-
ClientConfig.type
How certain the model is, between 0 and 1 inclusive.
How certain the model is, between 0 and 1 inclusive.
Distinct from Probability on purpose: confidence is derived from a whole distribution, and conflating the two is an easy mistake to make.
Attributes
- Supertypes
- Self type
-
Confidence.type
The response's codecs and instances.
The response's codecs and instances.
Attributes
- Companion
- class
- Supertypes
- Self type
-
Evaluation.type
The wire type of the question map, and the request's encoder.
The wire type of the question map, and the request's encoder.
Attributes
- Companion
- class
- Supertypes
- Self type
-
EvaluationRequest.type
Constructors for Instructions: plain text, structured JSON, or any encodable value. Each validates, rejecting what the API would reject.
Constructors for Instructions: plain text, structured JSON, or any encodable value. Each validates, rejecting what the API would reject.
Attributes
- Supertypes
- Self type
-
Instructions.type
A model identifier such as jev-latest or jev-1.13.0.
Instances for NoulAnswer.
The empty criteria, the encoder, and instances.
The empty criteria, the encoder, and instances.
Attributes
- Companion
- class
- Supertypes
- Self type
-
NoulCriteria.type
A Choice option name, as sent in criteria and returned in choice.
A Choice option name, as sent in criteria and returned in choice.
Attributes
- Supertypes
- Self type
-
OptionName.type
A probability, between 0 and 1 inclusive.
Constructors for every question type, and the combinators that change how an answer is read.
Constructors for every question type, and the combinators that change how an answer is read.
Every constructor returns a validated Question[A]: it never throws, and problems accumulate rather than stopping at the first. A is what the answer decodes to -- NoulAnswer, ChoiceAnswer[D] for an option type D, or ScoreAnswer -- and map or emap turn it into a type of your own.
Attributes
- Supertypes
- Self type
-
Question.type
A caller-chosen key in the questions map; answers return under the same key.
A caller-chosen key in the questions map; answers return under the same key.
Attributes
- Supertypes
- Self type
-
QuestionKey.type
The wire encoding of a question.
The default policy, a policy that never retries, and a validated constructor for your own.
The default policy, a policy that never retries, and a validated constructor for your own.
Attributes
- Companion
- class
- Supertypes
- Self type
-
RetryPolicy.type
Instances for ScoreAnswer.
Types
Choice accepts between 1 and 255 options.
Choice accepts between 1 and 255 options.
Iron has no MinLength/MaxLength; cardinality is expressed by applying a numeric constraint to the collection's Length.
Attributes
How certain the model is, between 0 and 1. Distinct from Probability.
Constraint for identifiers that must carry actual content.
Constraint for identifiers that must carry actual content.
Attributes
A non-blank Choice option name.
A non-blank Choice option name.
Attributes
A probability between 0 and 1 inclusive. Build one with Probability.
A probability between 0 and 1 inclusive. Build one with Probability.
Attributes
A non-blank key in the questions map.
A non-blank key in the questions map.
Attributes
A request must carry at least one question.
A request must carry at least one question.
Attributes
Score accepts between 2 and 10 ordered levels.
Score accepts between 2 and 10 ordered levels.
Attributes
Constraint shared by Probability and Confidence: the closed unit interval.