Reintent

@reintent/lib/jev

Choices asked the way Jev asks (TypeSafe's System One model, `POST /v1/systemone`), on core's `useChoose` (0116): one line a question, its options with what each means.

useChoice(id, question, { a: '…', b: '…' })   one of the options        → Jev's `choice`
useScore(id, question, { low: '…', high: '…' }) a level, in that order  → Jev's `score`
useWhether(id, question)                       whether it holds          → Jev's `noul`
<Ask state={…}>                                what the questions inside read
jev({ apiKey })                                a `judge` that asks Jev, a call for each state
decisionJudge(decide)                          a `judge` that asks a decision model (bass's `/api/ai/decide`)

Underneath each is a choice: a person can decide it, a <World> settles it, and System One's share for none of the options (BEYOND, 0115) escalates as any unmet does.

New.

Type Aliases

BeyondOf

type BeyondOf = BeyondBy | ((r) => BeyondBy | undefined);

Defined in: packages/lib/src/jev.ts

How the share outside K is asked: one way for every choice, or by the request. A choice System Two has nothing to write for is asked without it (false), so it takes the nearest of K and never goes up for what nobody can add.


ChoiceId

type ChoiceId = string | Id | Declared;

Defined in: packages/lib/src/jev.ts

A choice's identity: 'ticket#tone', { of, name }, or an entity's handle.


Criteria

type Criteria<K> = Readonly<Record<K, string | null>>;

Defined in: packages/lib/src/jev.ts

The options of a question, each with what it means (null: its name says it).

Type Parameters

Type Parameter
K extends string

Decide

type Decide = (state, questions) => Promise<{
  answers: Record<string, DecisionAnswer>;
}>;

Defined in: packages/lib/src/jev.ts

One decision: a state and named questions in, an answer for each out (bass's /api/ai/decide).

Parameters

ParameterType
stateRecord<string, unknown>
questionsRecord<string, DecisionQuestion>

Returns

Promise<{ answers: Record<string, DecisionAnswer>; }>


DecisionAnswer

type DecisionAnswer = 
  | {
  choice: string;
  confidence?: number;
  probabilities?: Record<string, number>;
  type: "choice";
}
  | {
  confidence?: number;
  probabilities?: Record<string, number>;
  score: number;
  type: "score";
}
  | {
  probability: number;
  type: "boolean";
}
  | {
  type: "refusal";
};

Defined in: packages/lib/src/jev.ts

A decision's answer to one question.


DecisionQuestion

type DecisionQuestion = 
  | {
  criteria: Record<string, string | null>;
  instructions: string;
  type: "choice";
}
  | {
  criteria: string[];
  instructions: string;
  type: "score";
}
  | {
  criteria?: {
     false?: string;
     true?: string;
  };
  instructions: string;
  type: "boolean";
};

Defined in: packages/lib/src/jev.ts

A decision question (the AI SDK's decision models; bass's /api/ai/decide).


HeardJudgment

Changed in #869 · See the diff →

type HeardJudgment = Judgment & object;

Defined in: packages/lib/src/jev.ts

A judgment, and whether it heard the sentence said last: whether that sentence is part of what was asked of the choice (0133 §3.5). Lab UI's unheard reads it: when none of the choices asked as a sentence is told heard it, the sentence goes to System Two whole, though what was said before still weighs them. Absent (Jev, a recorded answer), a judgment with weights heard it. nearestOnly: it heard the sentence, but what it asks is none of the options, and the question offered no "none of these" to say so (0133 §3.7): it took the nearest, and unheard does not count it as heard.

Type Declaration

NameType
heard?boolean
named?number
nearestOnly?boolean

JevAnswer

Changed in #869 · See the diff →

type JevAnswer = 
  | {
  choice: string;
  confidence: number;
  heard?: boolean;
  is?: boolean;
  named?: number;
  probabilities: Record<string, number>;
  type: "choice";
}
  | {
  confidence: number;
  heard?: boolean;
  is?: boolean;
  probabilities: Record<string, number>;
  score: number;
  type: "score";
}
  | {
  noul: number;
  type: "noul";
}
  | {
  type: "silent";
};

Defined in: packages/lib/src/jev.ts

One Jev answer, as answers in a /v1/systemone response holds it. silent, heard and is are a decision model's (decisionJudge): silent, the state asks nothing of this question, so it says nothing of it; heard, whether what was said last is part of what it asks of it (0133 §3.5); is, whether the option it leans to is what is asked, or only the nearest there is (0133 §3.2).


JevOptions

type JevOptions = object;

Defined in: packages/lib/src/jev.ts

Properties

PropertyTypeDescription
apiKeystring-
baseUrl?stringDefault 'https://api.typesafe.ai'.
beyond?BeyondByHow the share outside K is asked of a choice with no shape (default 'option'), or of any.
fetch?typeof fetch-
model?stringDefault 'jev-latest'.

JevQuestion

type JevQuestion = 
  | {
  criteria: Record<string, string | null>;
  instructions: string;
  type: "choice";
}
  | {
  criteria: string[];
  instructions: string;
  type: "score";
}
  | {
  criteria?: {
     false?: string;
     true?: string;
  };
  instructions: string;
  type: "noul";
};

Defined in: packages/lib/src/jev.ts

One Jev question, as questions in a /v1/systemone request holds it.


QuestionOptions

type QuestionOptions<T> = object;

Defined in: packages/lib/src/jev.ts

What else a question takes: Code's prior, a default while it is open, who answers it, what else it reads.

Type Parameters

Type Parameter
T

Properties

PropertyTypeDescription
ask?readonly Ask[]Who answers it, in order (default ['model']).
askWhenTold?booleanCore's askWhenTold (0114): System One is asked only once a person has told the intent something; until then the prior answers, with no call and no empty answer to realize again.
defaultValue?T-
prior?Readonly<Record<string, number>>Code's prior: a weight for each option, by its tag, in any proportion; one left out weighs nothing (default: all alike).
uses?Record<string, unknown>What System One reads besides the question and the state.

WorldOf

type WorldOf = boolean | ((r) => boolean | undefined);

Defined in: packages/lib/src/jev.ts

Which questions read the world (0133 §3.6): what they are given (uses, the radio) asks of them even when nobody said anything. One answer for every question, or by the request.

Variables

SILENT

const SILENT: Judgment;

Defined in: packages/lib/src/jev.ts

A judgment that says nothing of the choice: no weights. The cascade then rests on the layer below, the program's word or Code's prior, as before anything was said (0008 §4: a belief speaks only with the share it gave), and the request is answered, so it is not asked again.

Functions

Ask()

function Ask(p): Child;

Defined in: packages/lib/src/jev.ts

What the questions inside read, as Jev's state: each asks with it in its uses, so a new state is a new question.

Parameters

ParameterType
p{ children?: Child; state: unknown; }
p.children?Child
p.stateunknown

Returns

Child


decisionJudge()

Changed in #869 · See the diff →

function decisionJudge(decide, o?): (r, call) => 
  | Weights
  | Judgment
| Promise<Weights | Judgment>;

Defined in: packages/lib/src/jev.ts

A judge that asks a decision model (docs/design/0152): the requests one realization sends on the same state, in one decision. Each question is asked as its type (a noul as a boolean), and what a judgment carries besides its weights is asked as booleans beside it: <id>_asks (does the state ask anything of this aspect: no, and the question says nothing, the layer below stands), <id>_now where a sentence was said before or the question reads the world (is the last sentence part of it: heard, 0133 §3.5), and <id>_is where the question has no way to say "none of these" (is what is asked one of the options, or only the nearest: 0133 §3.7). The probabilities are the model's; the confidence is the model's where it gives one (Jev), else as Jev's docs define it.

Parameters

ParameterTypeDescription
decideDecide-
o{ asksBelow?: number | false; beyond?: BeyondOf; named?: boolean; world?: WorldOf; }-
o.asksBelow?number | falseBelow this probability of <id>_asks the question says nothing (SILENT; default 0.5). false: <id>_asks is not asked, and every question answered with weights.
o.beyond?BeyondOf-
o.named?booleanAsk, beside each choice, whether the last sentence names one of its options itself (<id>_named, 0149 §9): the answer is the judgment's named. Off by default: a lab whose sentences can decide a value asks it.
o.world?WorldOfThe questions that read the world (0133 §3.6): what each is given (its uses: the radio, a closure) asks of it too, so it answers though nobody said anything, where every other question says nothing (SILENT). Give it only where the world is reason enough to move the choice; a uses that only says the case a question is asked in (another choice's value) is not.

Returns

(r, call) => | Weights | Judgment | Promise<Weights | Judgment>

Example

import { decisionJudge } from '@reintent/lib/jev';

const judge = decisionJudge(async () => ({
  answers: {
    q0: { type: 'choice', choice: 'calm', probabilities: { angry: 0.1, calm: 0.9 } },
    q0_asks: { type: 'boolean', probability: 0.9 },
  },
}));
const j = await judge(
  {
    type: 'request',
    effect: 'judge',
    id: { of: 'm', name: 'tone' },
    key: 'm#tone',
    stamp: '',
    prompt: 'Tone?',
    kinds: ['angry', 'calm'],
    facts: ['keep it calm'],
  },
  { signal: new AbortController().signal },
);
console.log(j.weights); // → { angry: 0.1, calm: 0.9 }

jev()

function jev(o): (r, call) => 
  | Weights
  | Judgment
| Promise<Weights | Judgment>;

Defined in: packages/lib/src/jev.ts

A judge that asks Jev. The requests one realization sends together, reading the same state, go in one /v1/systemone call, one question each.

Parameters

ParameterType
oJevOptions

Returns

(r, call) => | Weights | Judgment | Promise<Weights | Judgment>


jevJudgment()

function jevJudgment(
   kinds, 
   answer, 
   fits?
): HeardJudgment;

Defined in: packages/lib/src/jev.ts

Jev's answers as a judgment on the request's possibilities: a choice's probabilities by tag, a score's by level, a noul's as true and false. The option for none, or one minus the companion noul, is BEYOND's share; the rest keep their proportions. A noul has no confidence of its own: it is |2p − 1|, as Jev's docs suggest.

Parameters

ParameterType
kindsreadonly string[]
answerJevAnswer
fits?JevAnswer

Returns

HeardJudgment

Example

import { jevJudgment } from '@reintent/lib/jev';

const j = jevJudgment(['later', 'this-week', 'today'], {
  type: 'score',
  score: 1.7,
  confidence: 0.55,
  probabilities: { 0: 0.1, 1: 0.1, 2: 0.8 },
});
console.log(j); // → { weights: { later: 0.1, 'this-week': 0.1, today: 0.8 }, confidence: 0.55 }

jevQuestion()

function jevQuestion(r, o?): object;

Defined in: packages/lib/src/jev.ts

A judge request as the Jev questions that answer it: the question itself, by its shape, and, for beyond: 'noul', a companion noul asking whether any of them fits (0115 §3). The state is the request's inputs.

Parameters

ParameterType
rModelRequest
o{ beyond?: BeyondBy; }
o.beyond?BeyondBy

Returns

object

NameType
fits?JevQuestion
questionJevQuestion

Example

import { jevQuestion } from '@reintent/lib/jev';

const q = jevQuestion({
  type: 'request',
  effect: 'judge',
  id: { of: 'm', name: 'tone' },
  key: 'm#tone',
  stamp: '',
  prompt: 'What is the tone of this message?',
  kinds: ['angry', 'calm'],
  describe: { angry: 'An upset or hostile message' },
});
console.log(q.question.criteria); // → { angry: 'An upset or hostile message', calm: null, 'something else': 'something none of the listed options is' }

useChoice()

function useChoice<K>(
   id, 
   question, 
   criteria, 
   o?
): K;

Defined in: packages/lib/src/jev.ts

One of the options, as System One chooses: Jev's choice.

Type Parameters

Type Parameter
K extends string

Parameters

ParameterType
idChoiceId
questionstring
criteriaCriteria<K>
oQuestionOptions<K>

Returns

K

Example

import { createIntent, host } from '@reintent/core';
import { Ask, useChoice } from '@reintent/lib/jev';

function Ticket() {
  const tone = useChoice('ticket#tone', 'What is the tone of this message?', {
    angry: 'An upset or hostile message',
    calm: 'A neutral or polite message',
  });
  return host('ticket', { tone });
}
const intent = createIntent({
  program: (
    <Ask state="I was charged twice. Please refund the extra charge.">
      <Ticket />
    </Ask>
  ),
  model: { judge: (r) => (console.log(r.uses), { angry: 0.15, calm: 0.85 }) }, // → { state: 'I was charged twice. Please refund the extra charge.' }
});
const connection = intent.connect({ commit() {} });
console.log(intent.realize().reads[0].value); // → 'calm'
connection.disconnect();

useScore()

function useScore<L>(
   id, 
   question, 
   levels, 
   o?
): L;

Defined in: packages/lib/src/jev.ts

A level, as System One scores it: Jev's score. The levels are in the order written.

Type Parameters

Type Parameter
L extends string

Parameters

ParameterType
idChoiceId
questionstring
levelsCriteria<L>
oQuestionOptions<L>

Returns

L

Example

import { createIntent, host, type ModelRequest } from '@reintent/core';
import { useScore } from '@reintent/lib/jev';

let asked: ModelRequest | undefined;
function Ticket() {
  const urgency = useScore('ticket#urgency', 'How urgent is this message?', {
    later: 'Can wait',
    week: 'Needs attention this week',
    today: 'Needs attention today',
  });
  return host('ticket', { urgency });
}
const intent = createIntent({
  program: <Ticket />,
  model: { judge: (r) => ((asked = r), { later: 0.1, week: 0.1, today: 0.8 }) },
});
const connection = intent.connect({ commit() {} });
console.log(asked?.shape, intent.realize().reads[0].value); // → 'ordered' 'today'
connection.disconnect();

useWhether()

function useWhether(
   id, 
   question, 
   o?
): boolean;

Defined in: packages/lib/src/jev.ts

Whether it holds, as System One weighs it: Jev's noul. The question is a yes-or-no question or a statement; true and false may say what each means.

Parameters

ParameterType
idChoiceId
questionstring
oQuestionOptions<boolean> & object

Returns

boolean

Example

import { createIntent, host } from '@reintent/core';
import { useWhether } from '@reintent/lib/jev';

function Ticket() {
  const billing = useWhether('ticket#billing', 'Is this message about billing?');
  return host('ticket', { billing });
}
const intent = createIntent({
  program: <Ticket />,
  model: { judge: () => ({ true: 0.98, false: 0.02 }) },
});
const connection = intent.connect({ commit() {} });
console.log(intent.realize().reads[0].value); // → true
connection.disconnect();

Last updated on

Edit on GitHub