Reintent

@reintent/lib/inspect

What an intent holds, in one snapshot for a view.

The choices read (with their distributions), the decisions, the questions, the model calls, the history: it is the same object until the intent changes, so a view, a panel or DevTools can call it on every render (in React, useSyncExternalStore(adapterOf(intent).subscribe, () => inspection(intent))) without asking the intent again.

Nothing is sent: the realization is intent.realize(at), pure (a host that shows λ sends its requests), and questions are asked with no new judge calls.

Interfaces

Inspection

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

What an intent holds now, in a context.

Properties

PropertyTypeDescription
canRedobooleanWhether there is a step to redo.
canUndobooleanWhether there is a step to undo.
decidedstring[]The keys a person decided.
factsreadonly string[]What was said of the whole.
historystring[]The history's notes, oldest first.
pendingRequestState[]The model calls not completed (running, or failed).
questionsQuestion[]What to ask a person, where the answer changes something.
readsChoiceView[]One read per choice, in the order they were read, with dist from intent.explain.
realizationRealizationλ in this context, read (nothing sent).
requestsRequestState[]Every model call.
revisionnumberThe program's place in the history.
versionstringThe program's name.

InspectOptions

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

Where to inspect an intent.

Properties

PropertyTypeDescription
at?ProvideThe context (default: none).
contexts?Provide[]The contexts questions are asked in (default: [at]).

Type Aliases

ChoiceView

type ChoiceView = ChoiceRead & object;

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

A choice as read, with its effective distribution.

Type Declaration

NameType
dist?Weights

RequestView

type RequestView = ReturnType<Intent["inspect"]>["requests"][number];

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

A model call the intent made, and how it went (intent.inspect().requests).

Functions

inspection()

function inspection(intent, opts?): Inspection;

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

The intent, inspected: the same object until the intent changes (a decision, an answer, a new program, a model call that failed). A view calls it whenever the intent changes.

Parameters

ParameterType
intentIntent
optsInspectOptions

Returns

Inspection

Example

import { createIntent, entity, host, recorded, useChoose } from '@reintent/core';
import { inspection } from '@reintent/lib/inspect';

const reply = entity('reply', {
  tone: { kinds: ['formal', 'warm'], default: 'warm', judge: 'Which tone?' },
});
const Reply = reply(() => host('reply', { tone: useChoose(reply.tone) }));
const intent = createIntent({
  program: <Reply />,
  model: recorded([
    { effect: 'judge', id: 'reply#tone', answer: { formal: 0.8, warm: 0.2 } },
  ]),
});
const connection = intent.connect({ commit() {} }); // shown: System One is asked

const now = inspection(intent);
console.log(now.reads[0].value, now.reads[0].dist); // → 'formal' { formal: 0.8, warm: 0.2 }
console.log(inspection(intent) === now); // → true
intent.decide(reply.tone('reply'), 'warm');
console.log(inspection(intent) === now, inspection(intent).decided); // → false [ 'reply#tone' ]
connection.disconnect();

readOf()

function readOf(i, id): ChoiceView | undefined;

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

One choice of an inspection, by identity (a handle, man.hat('m1'), is one).

Parameters

ParameterType
iPick<Inspection, "reads">
idId

Returns

ChoiceView | undefined

Last updated on

Edit on GitHub