Skip to Content
AI

Jev

Classifier decisions that always resolve with a safe fallback.

Usage

import { createJev } from "@dapplelight/signet-ai/jev"
import { env } from "./env"
import { log } from "./log"
import { ticket } from "./tickets"
import { route, review } from "./triage"

// Build where env exists (a handler or a CLI main), never at module scope.
const jev = createJev({
  apiKey: env.JEV_API_KEY, // missing: every call returns its fallback
  allowSensitive: false,   // opt in to send private or financial text
  onEvent: (e) => log.info("jev", e), // redacted: no key, state or question
})

const d = await jev.choice({
  question: "Which category fits this support ticket?",
  options: { billing: "Invoices, refunds", shipping: "Delivery, tracking", unsure: null },
  state: ticket.subject,
  fallback: "unsure",
  sensitive: false,
})

if (d.confident) route(d.value)
else review.push({ best: d.answer, confidence: d.confidence, reason: d.reason })

Fetch only, no SDK. It never throws for the failures that matter.

API

ExportWhat it does
createJev(config)Returns { enabled, choice, score, noul, batch }
JEV_DEFAULT_MODEL"jev-1.13.0"
JEV_DEFAULT_MIN_CONFIDENCE0.95
JEV_DEFAULT_TIMEOUT_MS8000
JEV_DEFAULT_BASE_URL"https://api.typesafe.ai"
Jev, JevConfig, JevDecision, JevNoulDecision, JevEvent, JevFallbackReason, JevBatchQuestion, JevBatchResult, JevState, JevJson, JevOptions, ChoiceArgs, ScoreArgs, NoulArgs, BatchArgs, JevFetchTypes

createJev(config)

OptionTypeDefault
apiKeystringnoneSent only in the Authorization header
modelstringJEV_DEFAULT_MODEL
minConfidencenumber0.95Floor, 0 to 1
timeoutMsnumber8000Total per call, no retries
allowSensitivebooleanfalseDecide it once in config, not per caller
baseUrlstringJEV_DEFAULT_BASE_URL
fetchJevFetchglobal fetch
onEvent(event) => voidnoneOne event per decision

Methods

Every call takes state, sensitive (required), fallback, and optionally minConfidence and signal. jev.enabled is false without a key.

MethodExtra argsvalue
choicequestion, options (labels or label to description, up to 255)one of the labels
scorequestion, levels (2 to 10, index is the score)a number
noulquestiona boolean; probability holds the raw yes-probability
batchquestions: named choice, score or noul questions about one statea decision per name

A decision is { value, confident: true, source: "jev", confidence } or { value, confident: false, source: "fallback", reason, confidence?, answer? }.

Fallback reasons

reasonWhen
sensitive_not_allowedsensitive is not false and the instance lacks allowSensitive. Checked first; no request is made
no_keyKey missing or blank
low_confidenceBelow the floor. answer and confidence are kept for review
timeoutOver timeoutMs
http_errorNon-2xx. The event carries status
network_errorFetch rejected
invalid_responseMalformed answer, or a label outside the offered set
invalid_requestNo questions, bad floor, score levels outside 2 to 10, or a fallback not in the options
abortedYour signal fired

A JS caller that omits sensitive is treated as sensitive. Never send private or financial text unless the owner opted in through allowSensitive.

Examples

Batch several questions in one request

import { jev } from "./jev"
import { review } from "./reviews"

const r = await jev.batch({
  state: review.text,
  sensitive: false,
  questions: {
    topic: { type: "choice", question: "What is it about?", options: ["quality", "price"], fallback: "quality" },
    angry: { type: "noul", question: "Is the customer angry?", fallback: false },
  },
})
r.topic.value // "quality" | "price"
r.angry.probability