jev

package module
v0.0.0-...-bbe2f66 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

jev

Go SDK, CLI, MCP server and agent skill for TypeSafe's System One API and its model, Jev.

Jev does not write text. You send a state (text or JSON) and named questions, and every answer comes back typed with calibrated probabilities: the probability of yes for a noul, a picked option for a choice, a position on your rubric for a score, or a bounding box for a box.

Not affiliated with TypeSafe. The SDK is written against the official API reference and follows the official SDKs' defaults (environment variables, retry policy).

Install

go install github.com/happyhackingspace/jev/cmd/jev@latest

or download a binary from releases.

Set your API key from the TypeSafe console:

export TYPESAFE_API_KEY=...
Variable Default
TYPESAFE_API_KEY required
TYPESAFE_DEFAULT_MODEL jev-latest
TYPESAFE_BASE_URL https://api.typesafe.ai

CLI

The state comes from -s, -f <file> or stdin. JSON objects and arrays are sent as structured state, so questions can point at fields by path (`ticket.subject`); --raw sends them as a string instead. --json prints the full API response.

jev noul "Is this message spam?" -s "WIN A FREE CRUISE NOW"
jev choice "Which team should handle this ticket?" -f ticket.json \
  -o billing="Payments, invoices, refunds" -o technical -o other
jev score "How urgent is this message?" -s "The site is down for everyone" \
  -l "Can wait" -l "Needs attention this week" -l "Needs attention today"
jev box "Locate the license plate." --image car.jpg
jev models

noul prints the probability of yes. choice prints the picked option and its confidence, then every option's probability, most likely first. score prints the score out of the top level and its confidence, then each level's probability. box prints top bottom left right as fractions of the image.

noul --threshold exits 0 for yes, 1 for no and 2 on errors, so a judgment can gate a script:

git diff | jev noul "Does this diff change authentication logic?" --threshold 0.7 && echo "needs review"

jev ask sends a full request in the API's JSON shape, with any number of questions of any type. Attach images with --image ref=path and write the ref where the image belongs:

jev ask --image photo-1=door.jpg <<'EOF'
{"state": "photo-1", "questions": {
  "person": {"type": "noul", "instructions": "Is there a person in the photo?"},
  "where":  {"type": "box",  "instructions": "Locate the person."}}}
EOF

MCP server

jev mcp serves two tools over stdio:

  • jev_ask: any mix of typed questions about one state, with optional images (local PNG or JPEG paths; other files are refused).
  • jev_models: the models and aliases available to the account.
claude mcp add jev -- jev mcp

Other MCP clients use the same command: jev with the argument mcp.

Claude Code plugin

The plugin bundles the MCP server and a skill that teaches agents when and how to use Jev. It needs the jev binary on PATH.

claude plugin marketplace add happyhackingspace/jev
claude plugin install jev@happyhackingspace-jev

To use the skill alone, copy skills/jev into your agent's skills directory. For designing TypeSafe integrations in depth, TypeSafe's official typesafe-ai skill complements this one.

Go SDK

go get github.com/happyhackingspace/jev
client, err := jev.New() // reads TYPESAFE_API_KEY
if err != nil {
	return err
}
resp, err := client.SystemOne(ctx, jev.Request{
	State: map[string]any{"message": "I was charged twice. Please refund the extra charge."},
	Questions: jev.Questions{
		"billing": jev.Noul{Instructions: "Is `message` about billing?"},
		"tone": jev.Choice{
			Instructions: "What is the tone of `message`?",
			Criteria:     map[string]any{"angry": "Upset or hostile", "calm": nil},
		},
		"urgency": jev.Score{
			Instructions: "How urgent is `message`?",
			Criteria:     []any{"Can wait", "This week", "Today"},
		},
	},
})
if err != nil {
	return err
}
billing, _ := resp.Noul("billing")    // float64, probability of yes
tone, _ := resp.Choice("tone")        // tone.Choice, *tone.Confidence, tone.Probabilities
urgency, _ := resp.Score("urgency")   // *urgency.Score, urgency.Legend

Images go anywhere a string can, by reference:

img, err := jev.ReadImage("door.jpg") // PNG or JPEG only
ref := jev.NewRef()
resp, err := client.SystemOne(ctx, jev.Request{
	State:     ref,
	Images:    map[string]jev.Image{ref: img},
	Questions: jev.Questions{"person": jev.Box{Instructions: "Locate the person."}},
})

Images are uploaded as multipart parts, and the TypeSafe-Danger-Zone-Images header is set automatically when a request has images or box questions. Request.LongContext sets the long context header.

Options: WithAPIKey, WithModel, WithBaseURL, WithTimeout, WithHTTPClient, WithRetry, WithUserAgent. By default the client retries 408, 429 and 5xx (including 529) twice with jittered exponential backoff, honouring Retry-After-Ms and Retry-After. API errors are *jev.APIError.

License

MIT

Documentation

Overview

Package jev is a Go client for TypeSafe's System One API and its model, Jev.

Jev does not generate text. A request carries a state (text or JSON) and one or more named questions, and every answer comes back typed: a probability for a Noul, a picked option for a Choice, a position on a rubric for a Score, or a bounding box for a Box.

client, err := jev.New() // reads TYPESAFE_API_KEY
resp, err := client.SystemOne(ctx, jev.Request{
	State: "I was charged twice. Please refund the extra charge.",
	Questions: jev.Questions{
		"billing": jev.Noul{Instructions: "Is this message about billing?"},
		"urgency": jev.Score{
			Instructions: "How urgent is this message?",
			Criteria:     []any{"Can wait", "This week", "Today"},
		},
	},
})
billing, err := resp.Noul("billing")

The API reference lives at https://docs.typesafe.ai/api.

Index

Constants

View Source
const (
	DefaultBaseURL = "https://api.typesafe.ai"
	DefaultTimeout = 60 * time.Second

	EnvAPIKey  = "TYPESAFE_API_KEY"
	EnvBaseURL = "TYPESAFE_BASE_URL"
	EnvModel   = "TYPESAFE_DEFAULT_MODEL"
)

Defaults and environment variables, shared with TypeSafe's official SDKs.

View Source
const (
	ModelLatest  = "jev-latest"
	ModelPreview = "jev-preview"
)

Model aliases. An alias moves when a new model ships, so pin a versioned name such as "jev-1.14.0" when thresholds were tuned against one version.

View Source
const (
	TypeNoul   = "noul"
	TypeChoice = "choice"
	TypeScore  = "score"
	TypeBox    = "box"
)

Question types as they appear in the type field of questions and answers.

Variables

View Source
var Version = "dev"

Version is the SDK version, sent in the User-Agent header.

Functions

func NewRef

func NewRef() string

NewRef returns a random image reference. References are matched as plain text, so random ones avoid replacing a word in the state by accident.

Types

type APIError

type APIError struct {
	StatusCode int
	// Message is a readable summary of the error body.
	Message string
	// Body is the raw error body.
	Body []byte
}

APIError is a non-2xx response from the API.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Retryable

func (e *APIError) Retryable() bool

Retryable reports whether the same request may succeed later.

type Answer

type Answer struct {
	Type string `json:"type"`
	// Noul is the probability of yes, from 0 to 1.
	Noul *float64 `json:"noul,omitempty"`
	// Choice is the option with the highest probability.
	Choice string `json:"choice,omitempty"`
	// Score is the probability-weighted level and may fall between levels.
	Score *float64 `json:"score,omitempty"`
	// Confidence is how sure the model is of a choice, score or box. It is
	// nil for nouls, and for boxes when the model gives none.
	Confidence *float64 `json:"confidence,omitempty"`
	// Probabilities maps each option, or each level index for a score, to
	// its probability.
	Probabilities map[string]float64 `json:"probabilities,omitempty"`
	// Legend maps each score level index to the criterion it stands for.
	Legend map[string]any  `json:"legend,omitempty"`
	Box    *BoxCoordinates `json:"box,omitempty"`
}

Answer is one typed answer. Type says which fields are set.

type Box

type Box struct {
	Instructions any
}

Box locates what Instructions describe in the request's image. It needs an image in the request and a model that supports boxes (Jev 1.14 or later).

func (Box) MarshalJSON

func (q Box) MarshalJSON() ([]byte, error)

func (Box) Type

func (Box) Type() string

type BoxCoordinates

type BoxCoordinates struct {
	Top    float64 `json:"top"`
	Bottom float64 `json:"bottom"`
	Left   float64 `json:"left"`
	Right  float64 `json:"right"`
}

BoxCoordinates are the edges of a box as fractions of the image, measured from the top and from the left.

type Choice

type Choice struct {
	Instructions any
	Criteria     map[string]any
}

Choice picks one option. Criteria maps each option name to a description of when it applies; a nil description lets the name speak for itself.

func (Choice) MarshalJSON

func (q Choice) MarshalJSON() ([]byte, error)

func (Choice) Type

func (Choice) Type() string

type Client

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

Client calls the System One API. It is safe for concurrent use.

func New

func New(opts ...Option) (*Client, error)

New returns a client configured from options, falling back to the TYPESAFE_* environment variables and then to the defaults.

func (*Client) Models

func (c *Client) Models(ctx context.Context) ([]Model, error)

Models lists the models and aliases available to the account.

func (*Client) SystemOne

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

SystemOne asks every question in the request about its state.

type Image

type Image struct {
	Data []byte
	// Format is "png" or "jpg". [ReadImage] and [NewImage] detect it.
	Format string
}

Image is a PNG or JPEG image to send with a request.

func NewImage

func NewImage(data []byte) (Image, error)

NewImage wraps image bytes, detecting the format. Only PNG and JPEG are accepted, which also keeps arbitrary files from being sent as images.

func ReadImage

func ReadImage(path string) (Image, error)

ReadImage loads a PNG or JPEG image from disk.

type Model

type Model struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	ReleaseDate string `json:"release_date"`
}

Model describes a model or alias available to the account.

type Noul

type Noul struct {
	Instructions any
	// Criteria optionally clarifies what counts as yes and no.
	Criteria *NoulCriteria
}

Noul asks a yes/no question and is answered with the probability of yes.

func (Noul) MarshalJSON

func (q Noul) MarshalJSON() ([]byte, error)

func (Noul) Type

func (Noul) Type() string

type NoulCriteria

type NoulCriteria struct {
	True  any `json:"true,omitempty"`
	False any `json:"false,omitempty"`
}

NoulCriteria describes what counts as a yes (True) and a no (False).

type Option

type Option func(*Client)

Option configures a Client.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the API key instead of reading TYPESAFE_API_KEY.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL points the client at another API host, such as a proxy.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient replaces the HTTP client, for custom transports or proxies.

func WithModel

func WithModel(model string) Option

WithModel sets the default model, used when a request names none.

func WithRetry

func WithRetry(p RetryPolicy) Option

WithRetry replaces the retry policy.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the timeout of each HTTP attempt.

func WithUserAgent

func WithUserAgent(ua string) Option

WithUserAgent prefixes the User-Agent header with your application's name.

type Question

type Question interface {
	Type() string
}

Question is one typed judgment about a request's state. Instructions and criteria accept a string, or any JSON-encodable object or array.

type Questions

type Questions map[string]Question

Questions maps the names you choose to questions. Names key the answers and are never shown to the model, so put the whole question in Instructions.

func (*Questions) UnmarshalJSON

func (qs *Questions) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes questions written in the API's own JSON shape, so a request file can be loaded straight into a Request.

type Request

type Request struct {
	// Model overrides the client's default model for this request.
	Model string `json:"model,omitempty"`
	// State is the content every question refers to: a string, or any
	// JSON-encodable object or array.
	State any `json:"state"`
	// Questions maps your names to the questions to ask.
	Questions Questions `json:"questions"`
	// Images maps a reference string to an image. Write the reference
	// anywhere a string can go in State, Instructions or Criteria and the
	// model sees the image in its place. Use [NewRef] for references that
	// cannot collide with ordinary text.
	Images map[string]Image `json:"-"`
	// LongContext raises the context limits for this request. It is slower
	// and less accurate, so turn it on only when the state needs it.
	LongContext bool `json:"-"`
}

Request is one System One call: a state and the questions to ask about it.

type Response

type Response struct {
	// Model is the versioned model that answered, even when the request
	// named an alias such as jev-latest.
	Model   string            `json:"model"`
	Answers map[string]Answer `json:"answers"`
	Usage   Usage             `json:"usage"`
}

Response holds the answers to one request, keyed by question name.

func (*Response) Answer

func (r *Response) Answer(name, wantType string) (Answer, error)

Answer returns the named answer and checks that it has the wanted type.

func (*Response) Box

func (r *Response) Box(name string) (Answer, error)

Box returns the named box answer.

func (*Response) Choice

func (r *Response) Choice(name string) (Answer, error)

Choice returns the named choice answer.

func (*Response) Noul

func (r *Response) Noul(name string) (float64, error)

Noul returns the probability of yes for the named noul question.

func (*Response) Score

func (r *Response) Score(name string) (Answer, error)

Score returns the named score answer.

type RetryPolicy

type RetryPolicy struct {
	// MaxRetries is the number of retries after the first attempt; 0
	// disables retries.
	MaxRetries int
	// InitialBackoff is the wait before the first retry; it doubles each
	// time up to MaxBackoff.
	InitialBackoff time.Duration
	MaxBackoff     time.Duration
	// Jitter randomizes each wait by up to this fraction, so clients that
	// were throttled together do not retry together.
	Jitter float64
}

RetryPolicy controls retries of rate-limited, overloaded and failed requests. The defaults match TypeSafe's official SDKs.

func DefaultRetryPolicy

func DefaultRetryPolicy() RetryPolicy

DefaultRetryPolicy returns the policy a new client uses.

type Score

type Score struct {
	Instructions any
	Criteria     []any
}

Score rates the state on an ordered rubric. The position of each level in Criteria is its score, starting at zero.

func (Score) MarshalJSON

func (q Score) MarshalJSON() ([]byte, error)

func (Score) Type

func (Score) Type() string

type Usage

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

Usage reports token counts. Only input tokens are billed.

Directories

Path Synopsis
cmd
jev command
Command jev asks TypeSafe's Jev typed questions from the command line and serves them as MCP tools.
Command jev asks TypeSafe's Jev typed questions from the command line and serves them as MCP tools.
internal
cli
Package cli implements the jev command.
Package cli implements the jev command.
mcpserver
Package mcpserver exposes Jev as Model Context Protocol tools.
Package mcpserver exposes Jev as Model Context Protocol tools.

Jump to

Keyboard shortcuts

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