@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
| Property | Type | Description |
|---|---|---|
canRedo | boolean | Whether there is a step to redo. |
canUndo | boolean | Whether there is a step to undo. |
decided | string[] | The keys a person decided. |
facts | readonly string[] | What was said of the whole. |
history | string[] | The history's notes, oldest first. |
pending | RequestState[] | The model calls not completed (running, or failed). |
questions | Question[] | What to ask a person, where the answer changes something. |
reads | ChoiceView[] | One read per choice, in the order they were read, with dist from intent.explain. |
realization | Realization | λ in this context, read (nothing sent). |
requests | RequestState[] | Every model call. |
revision | number | The program's place in the history. |
version | string | The program's name. |
InspectOptions
Defined in: packages/lib/src/inspect.ts
Where to inspect an intent.
Properties
| Property | Type | Description |
|---|---|---|
at? | Provide | The 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
| Name | Type |
|---|---|
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
| Parameter | Type |
|---|---|
intent | Intent |
opts | InspectOptions |
Returns
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
| Parameter | Type |
|---|---|
i | Pick<Inspection, "reads"> |
id | Id |
Returns
ChoiceView | undefined
Last updated on
Edit on GitHub