Cite.Provider behaviour (Cite v0.1.0)

Copy Markdown View Source

A decision-model provider: builds a handle, then answers one wire-shaped request at a time.

Cite.client/2 turns a provider into the client, the 1-arity function Cite.judge/4 takes, so the rounds never see the provider's own handle. Implementations: Cite.Provider.TypeSafe.

Requests

The request follows the question schema of TypeSafe's System One API: "state" plus "questions". A value in "state" may be a Cite.Wire.Object, a JSON object that keeps its keys in order. Each question is a map with "type" (noul, score, choice), "instructions" (question, then inspect or compare, and an optional focus), and "criteria".

Cite encodes questions to that schema before they reach a provider, so a provider never sees a policy. A provider for a model that takes the schema sends it as is; one for a model with different inputs converts from it.

Errors

A provider raises on caller error (bad options) and returns {:error, reason} for anything the network did — a failed call, a reply Cite cannot read. Cite.judge/4 records those as Cite.Errors and carries on.

One reason is shared across providers: :request_too_large, meaning the request exceeded the provider's size cap. Round 1 halves its window and retries on it, so a provider must map its own overflow signal to that atom.

Summary

Callbacks

Answers a request of %{"state" => map(), "questions" => map()}, where a value in "state" may be a Cite.Wire.Object.

Builds the provider's handle from options. Bad options are a caller error and raise.

Types

reason()

@type reason() :: :request_too_large | term()

Callbacks

judge(handle, request)

@callback judge(handle :: term(), request :: map()) ::
  {:ok, Cite.verdict()} | {:error, reason()}

Answers a request of %{"state" => map(), "questions" => map()}, where a value in "state" may be a Cite.Wire.Object.

new(keyword)

@callback new(keyword()) :: handle :: term()

Builds the provider's handle from options. Bad options are a caller error and raise.