com.softinio.verdict4s.algebra

Members list

Grouped members

Errors

final case class ApiErrorBody(kind: Option[String], message: Option[String], field: Option[String], raw: Json)

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
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
enum ApiFailure

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

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Refinements

object 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
class Object
trait Matchable
class Any
Self type

Questions

opaque type Question[A]

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 A is statically known, is what lets Ask project 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

final class ApiKey

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
class Object
trait Matchable
class Any
final case class ClientConfig(model: Model = ..., retry: RetryPolicy = ..., requestTimeout: FiniteDuration = ...)

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
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Defaults

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
class Object
trait Matchable
class Any
Self type
Defaults.type
final case class RetryPolicy

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-After header 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
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Protocol

enum Answer

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

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class ChoiceAnswer[A](choice: A, probabilities: SortedMap[OptionName, Probability], confidence: Confidence)

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
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class Evaluation(model: Model, answers: SortedMap[QuestionKey, Answer], usage: Usage)

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-latest resolves to a pinned version

usage

tokens consumed by the request

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class EvaluationRequest(state: Json, model: Model, questions: Questions)

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
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
opaque type Instructions

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

final class Levels[A]

The ordered rubric of a Score question, plus how to read a level back.

The ordered rubric of a Score question, plus how to read a level back.

Unlike Options this is a List, not a sorted map: the levels are ordered, and their position is their meaning — the service returns level indices as "0", "1", and so on, keyed to this order.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
opaque type Model

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

final case class ModelCard(name: Model, description: String, releaseDate: String)

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
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class NoulAnswer(value: Probability)

A Noul answer: how likely the answer is yes.

A Noul answer: how likely the answer is yes.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class NoulCriteria(ifTrue: Option[Instructions], ifFalse: Option[Instructions])

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
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final class Options[A]

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
class Object
trait Matchable
class Any

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

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class ScoreAnswer(score: Double, legend: SortedMap[Int, String], probabilities: SortedMap[Int, Probability], confidence: Confidence)

A Score answer.

A Score answer.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class Usage(inputTokens: Int, outputTokens: Int)

Token usage reported alongside every evaluation.

Token usage reported alongside every evaluation.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Type members

Classlikes

object Answer

Codecs and instances for Answer.

Codecs and instances for Answer.

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Answer.type
object ApiErrorBody

Reading an error body, and its decoder, which never fails.

Reading an error body, and its decoder, which never fails.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object ApiFailure

Classifying an HTTP status code.

Classifying an HTTP status code.

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
ApiFailure.type
object ApiKey

Validating and wrapping a key.

Validating and wrapping a key.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
ApiKey.type
object ChoiceAnswer

Instances for ChoiceAnswer.

Instances for ChoiceAnswer.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object ClientConfig

The default configuration, and instances.

The default configuration, and instances.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self 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
class Object
trait Matchable
class Any
Self type
Confidence.type
object Evaluation

The response's codecs and instances.

The response's codecs and instances.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
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
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object Instructions

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
class Object
trait Matchable
class Any
Self type
object Levels

Building a Levels rubric: from strings at runtime, or derived from an enum with derives Levels.

Building a Levels rubric: from strings at runtime, or derived from an enum with derives Levels.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Levels.type
object Model

The model aliases, and naming a specific model.

The model aliases, and naming a specific model.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Model.type
object ModelCard

Codecs and instances for ModelCard.

Codecs and instances for ModelCard.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
ModelCard.type
object ModelId extends RefinedType[String, NonBlankC]

A model identifier such as jev-latest or jev-1.13.0.

A model identifier such as jev-latest or jev-1.13.0.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
ModelId.type
object NoulAnswer

Instances for NoulAnswer.

Instances for NoulAnswer.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
NoulAnswer.type
object NoulCriteria

The empty criteria, the encoder, and instances.

The empty criteria, the encoder, and instances.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self 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
class Object
trait Matchable
class Any
Self type
OptionName.type
object Options

Building an Options set: from strings at runtime, or derived from an enum with derives Options.

Building an Options set: from strings at runtime, or derived from an enum with derives Options.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Options.type

A probability, between 0 and 1 inclusive.

A probability, between 0 and 1 inclusive.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
object Question

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
class Object
trait Matchable
class Any
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
class Object
trait Matchable
class Any
Self type
object QuestionSpec

The wire encoding of a question.

The wire encoding of a question.

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
object RetryPolicy

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
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object ScoreAnswer

Instances for ScoreAnswer.

Instances for ScoreAnswer.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object Usage

Codecs and instances for Usage.

Codecs and instances for Usage.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Usage.type

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

type Confidence = T

How certain the model is, between 0 and 1. Distinct from Probability.

How certain the model is, between 0 and 1. Distinct from Probability.

Attributes

type ModelId = T

A non-blank model identifier.

A non-blank model identifier.

Attributes

type NonBlankC = Not[Blank]

Constraint for identifiers that must carry actual content.

Constraint for identifiers that must carry actual content.

Attributes

type OptionName = T

A non-blank Choice option name.

A non-blank Choice option name.

Attributes

type Probability = T

A probability between 0 and 1 inclusive. Build one with Probability.

A probability between 0 and 1 inclusive. Build one with Probability.

Attributes

type QuestionKey = T

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

type UnitIntervalC = GreaterEqual[0.0d] & LessEqual[1.0d]

Constraint shared by Probability and Confidence: the closed unit interval.

Constraint shared by Probability and Confidence: the closed unit interval.

Attributes