jev

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package jev is a client for System One decision models such as TypeSafe's Jev, served at POST {base}/systemone by OpenRouter and TypeSafe.

Types, validation and wire encoding are adapted from Denkeeper (github.com/Temikus/denkeeper, internal/llm), Apache-2.0.

Index

Constants

View Source
const (
	MaxQuestionTokens = 32_000
	MaxRequestTokens  = 64_000
)

Upstream limits: state plus any one question, and the whole request.

Variables

View Source
var ErrTooLarge = errors.New("decision input exceeds the request token limit")

ErrTooLarge is returned before any call when the input would exceed MaxRequestTokens. Input is never truncated.

View Source
var ErrValidation = errors.New("decision request failed validation")

ErrValidation is returned for HTTP 422: the provider rejected the request shape. Retrying cannot help.

Functions

func BaseURL

func BaseURL(provider, override string) (string, error)

BaseURL resolves the API base for a provider name. A non-empty override (from LGTM_BASE_URL or the Action's base-url input, never from repo config) replaces it and must be https.

func EstimateTokens

func EstimateTokens(state any, qs map[string]Question) (int, error)

EstimateTokens estimates the input size of a call from its wire encoding.

func SortedIDs

func SortedIDs[V any](qs map[string]V) []string

SortedIDs returns the question IDs in a stable order.

func ValidateQuestions

func ValidateQuestions(qs map[string]Question) error

ValidateQuestions checks question shapes against the API limits so a malformed question fails before any call is made.

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError is a non-200 reply. Message is the provider's short error text, capped at maxErrorLen; it is untrusted and must be escaped before display.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

type Answer

type Answer struct {
	Type          QuestionType       `json:"type"`
	Choice        string             `json:"choice,omitempty"`
	Probabilities map[string]float64 `json:"probabilities,omitempty"`
	Confidence    float64            `json:"confidence,omitempty"`
	Noul          float64            `json:"noul,omitempty"`
	Score         float64            `json:"score,omitempty"`
}

Answer is the model's answer to one Question. Probabilities are keyed by option name for choice and by level index ("0", "1", ...) for score. Score is the expected level index, so it lies in [0, len(Levels)-1].

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls the System One endpoint.

func NewClient

func NewClient(baseURL, apiKey string, opts ...ClientOption) *Client

NewClient returns a Client for baseURL (see BaseURL).

func (*Client) Decide

func (c *Client) Decide(ctx context.Context, req Request) (*Response, error)

Decide validates the questions, refuses oversized input, posts the request with bounded retries on 429/529, and checks the response answers every question with the right shape from the requested model.

type ClientOption

type ClientOption func(*Client)

ClientOption configures a Client.

func WithHTTPClient

func WithHTTPClient(h *http.Client) ClientOption

WithHTTPClient replaces the default HTTP client.

type Decider

type Decider interface {
	Decide(ctx context.Context, req Request) (*Response, error)
}

Decider answers decision requests. Client implements it; tests may substitute a scripted fake.

type Option

type Option struct {
	Name       string
	Definition string
}

Option is a named choice and the definition bound to it. The model follows the name over the definition, so the two must never disagree.

type Question

type Question struct {
	Type         QuestionType
	Instructions string
	Choices      []Option // choice options in the order sent; for noul, optional "true"/"false"
	Levels       []string // score levels in order
}

Question is one typed question put to a decision model.

func (Question) Has

func (q Question) Has(name string) bool

Has reports whether name is one of q's options.

type QuestionType

type QuestionType string

QuestionType is the answer shape a decision model is asked for.

const (
	Choice QuestionType = "choice" // one of 2-255 named options
	Noul   QuestionType = "noul"   // probability the statement is true
	Score  QuestionType = "score"  // 2-10 ordered levels
)

type Request

type Request struct {
	Model     string
	State     any
	Questions map[string]Question
}

Request asks Model the Questions about State, which is any JSON value.

type Response

type Response struct {
	ID      string
	Model   string
	Answers map[string]Answer
	Usage   Usage
	CostUSD float64
}

Response carries the answers keyed by question ID.

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Usage is the token usage the provider reported.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL