@hackbuild/agents-views 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +153 -2
- package/dist/agents-views.iife.js +405 -0
- package/dist/associations-table.d.ts +66 -0
- package/dist/associations-table.js +108 -0
- package/dist/dom.d.ts +11 -0
- package/dist/dom.js +26 -0
- package/dist/drives-bars.d.ts +75 -0
- package/dist/drives-bars.js +99 -0
- package/dist/elements.d.ts +26 -0
- package/dist/elements.js +87 -0
- package/dist/eye-inset.d.ts +54 -0
- package/dist/eye-inset.js +84 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/single.d.ts +1 -0
- package/dist/single.js +6 -0
- package/dist/vue.d.ts +109 -0
- package/dist/vue.js +82 -0
- package/how.ts +24 -0
- package/llms.md +345 -0
- package/package.json +50 -4
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type PropType } from "vue";
|
|
2
|
+
import { type AssociationsState } from "./associations-table.js";
|
|
3
|
+
import { type DrivesBarsState } from "./drives-bars.js";
|
|
4
|
+
import { type EyeWho } from "./eye-inset.js";
|
|
5
|
+
/** The behavior block, utility rows (current in pink) and drive rows. */
|
|
6
|
+
export declare const DrivesBars: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
7
|
+
state: {
|
|
8
|
+
type: PropType<DrivesBarsState>;
|
|
9
|
+
required: true;
|
|
10
|
+
};
|
|
11
|
+
note: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
default: undefined;
|
|
14
|
+
};
|
|
15
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
18
|
+
state: {
|
|
19
|
+
type: PropType<DrivesBarsState>;
|
|
20
|
+
required: true;
|
|
21
|
+
};
|
|
22
|
+
note: {
|
|
23
|
+
type: StringConstructor;
|
|
24
|
+
default: undefined;
|
|
25
|
+
};
|
|
26
|
+
}>> & Readonly<{}>, {
|
|
27
|
+
note: string;
|
|
28
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
29
|
+
/** The cues by acts heat table with attention, the explanation and reset. Emits `reset`. */
|
|
30
|
+
export declare const AssociationsTable: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
31
|
+
state: {
|
|
32
|
+
type: PropType<AssociationsState>;
|
|
33
|
+
required: true;
|
|
34
|
+
};
|
|
35
|
+
limit: {
|
|
36
|
+
type: NumberConstructor;
|
|
37
|
+
default: number;
|
|
38
|
+
};
|
|
39
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "reset"[], "reset", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
42
|
+
state: {
|
|
43
|
+
type: PropType<AssociationsState>;
|
|
44
|
+
required: true;
|
|
45
|
+
};
|
|
46
|
+
limit: {
|
|
47
|
+
type: NumberConstructor;
|
|
48
|
+
default: number;
|
|
49
|
+
};
|
|
50
|
+
}>> & Readonly<{
|
|
51
|
+
onReset?: (...args: any[]) => any;
|
|
52
|
+
}>, {
|
|
53
|
+
limit: number;
|
|
54
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
55
|
+
/**
|
|
56
|
+
* The eye card. `draw` paints a frame of the selected who; call the exposed
|
|
57
|
+
* `frame()` each frame (a template ref). v-model:who is the selected id.
|
|
58
|
+
*/
|
|
59
|
+
export declare const EyeInset: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
60
|
+
who: {
|
|
61
|
+
type: PropType<EyeWho[]>;
|
|
62
|
+
required: true;
|
|
63
|
+
};
|
|
64
|
+
draw: {
|
|
65
|
+
type: PropType<(canvas: HTMLCanvasElement, who: EyeWho) => string | void>;
|
|
66
|
+
required: true;
|
|
67
|
+
};
|
|
68
|
+
selected: {
|
|
69
|
+
type: StringConstructor;
|
|
70
|
+
default: undefined;
|
|
71
|
+
};
|
|
72
|
+
width: {
|
|
73
|
+
type: NumberConstructor;
|
|
74
|
+
default: number;
|
|
75
|
+
};
|
|
76
|
+
height: {
|
|
77
|
+
type: NumberConstructor;
|
|
78
|
+
default: number;
|
|
79
|
+
};
|
|
80
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
81
|
+
[key: string]: any;
|
|
82
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:selected"[], "update:selected", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
83
|
+
who: {
|
|
84
|
+
type: PropType<EyeWho[]>;
|
|
85
|
+
required: true;
|
|
86
|
+
};
|
|
87
|
+
draw: {
|
|
88
|
+
type: PropType<(canvas: HTMLCanvasElement, who: EyeWho) => string | void>;
|
|
89
|
+
required: true;
|
|
90
|
+
};
|
|
91
|
+
selected: {
|
|
92
|
+
type: StringConstructor;
|
|
93
|
+
default: undefined;
|
|
94
|
+
};
|
|
95
|
+
width: {
|
|
96
|
+
type: NumberConstructor;
|
|
97
|
+
default: number;
|
|
98
|
+
};
|
|
99
|
+
height: {
|
|
100
|
+
type: NumberConstructor;
|
|
101
|
+
default: number;
|
|
102
|
+
};
|
|
103
|
+
}>> & Readonly<{
|
|
104
|
+
"onUpdate:selected"?: (...args: any[]) => any;
|
|
105
|
+
}>, {
|
|
106
|
+
selected: string;
|
|
107
|
+
width: number;
|
|
108
|
+
height: number;
|
|
109
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The Vue components: each mounts the vanilla view on its root element and
|
|
2
|
+
// follows its props, so the Vue and plain HTML forms draw the same markup.
|
|
3
|
+
import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
4
|
+
import { associationsTable } from "./associations-table.js";
|
|
5
|
+
import { drivesBars } from "./drives-bars.js";
|
|
6
|
+
import { eyeInset } from "./eye-inset.js";
|
|
7
|
+
/** The behavior block, utility rows (current in pink) and drive rows. */
|
|
8
|
+
export const DrivesBars = defineComponent({
|
|
9
|
+
name: "DrivesBars",
|
|
10
|
+
props: {
|
|
11
|
+
state: { type: Object, required: true },
|
|
12
|
+
note: { type: String, default: undefined },
|
|
13
|
+
},
|
|
14
|
+
setup(props) {
|
|
15
|
+
const root = ref(null);
|
|
16
|
+
let view = null;
|
|
17
|
+
onMounted(() => {
|
|
18
|
+
view = drivesBars(root.value, props.note ? { note: props.note } : {});
|
|
19
|
+
view.update(props.state);
|
|
20
|
+
});
|
|
21
|
+
watch(() => props.state, (s) => view?.update(s), { deep: true });
|
|
22
|
+
onBeforeUnmount(() => view?.dispose());
|
|
23
|
+
return () => h("div", { ref: root });
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
/** The cues by acts heat table with attention, the explanation and reset. Emits `reset`. */
|
|
27
|
+
export const AssociationsTable = defineComponent({
|
|
28
|
+
name: "AssociationsTable",
|
|
29
|
+
props: {
|
|
30
|
+
state: { type: Object, required: true },
|
|
31
|
+
limit: { type: Number, default: 16 },
|
|
32
|
+
},
|
|
33
|
+
emits: ["reset"],
|
|
34
|
+
setup(props, { emit }) {
|
|
35
|
+
const root = ref(null);
|
|
36
|
+
let view = null;
|
|
37
|
+
onMounted(() => {
|
|
38
|
+
view = associationsTable(root.value, { onReset: () => emit("reset"), limit: props.limit });
|
|
39
|
+
view.update(props.state);
|
|
40
|
+
});
|
|
41
|
+
watch(() => props.state, (s) => view?.update(s), { deep: true });
|
|
42
|
+
onBeforeUnmount(() => view?.dispose());
|
|
43
|
+
return () => h("div", { ref: root });
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* The eye card. `draw` paints a frame of the selected who; call the exposed
|
|
48
|
+
* `frame()` each frame (a template ref). v-model:who is the selected id.
|
|
49
|
+
*/
|
|
50
|
+
export const EyeInset = defineComponent({
|
|
51
|
+
name: "EyeInset",
|
|
52
|
+
props: {
|
|
53
|
+
who: { type: Array, required: true },
|
|
54
|
+
draw: { type: Function, required: true },
|
|
55
|
+
selected: { type: String, default: undefined },
|
|
56
|
+
width: { type: Number, default: 320 },
|
|
57
|
+
height: { type: Number, default: 160 },
|
|
58
|
+
},
|
|
59
|
+
emits: ["update:selected"],
|
|
60
|
+
setup(props, { emit, expose }) {
|
|
61
|
+
const root = ref(null);
|
|
62
|
+
let view = null;
|
|
63
|
+
onMounted(() => {
|
|
64
|
+
view = eyeInset(root.value, {
|
|
65
|
+
who: props.who,
|
|
66
|
+
draw: (c, w) => props.draw(c, w),
|
|
67
|
+
width: props.width,
|
|
68
|
+
height: props.height,
|
|
69
|
+
...(props.selected ? { selected: props.selected } : {}),
|
|
70
|
+
onWho: (id) => emit("update:selected", id),
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
watch(() => props.selected, (id) => id && view?.select(id));
|
|
74
|
+
onBeforeUnmount(() => view?.dispose());
|
|
75
|
+
expose({
|
|
76
|
+
frame: () => view?.frame(),
|
|
77
|
+
mode: (t) => view?.mode(t),
|
|
78
|
+
canvas: () => view?.canvas ?? null,
|
|
79
|
+
});
|
|
80
|
+
return () => h("figure", { ref: root });
|
|
81
|
+
},
|
|
82
|
+
});
|
package/how.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// how this works: the fold of the package page and of the suite tool. Plain data, no imports;
|
|
2
|
+
// checked by tsconfig.how.json, shipped in the tarball, never imported by the runtime entry.
|
|
3
|
+
const how: HowDoc = {
|
|
4
|
+
what: "the brain bars, the associations table and the eye card of the dog yard, as views you mount on any page. each is a vue component and a custom element drawn with hackbuild-ui classes.",
|
|
5
|
+
how: [
|
|
6
|
+
"`drivesBars` draws what it is doing in big letters with the why under it, a bar per act for what that act is worth now with the chosen one in pink, and a bar per drive. `drivesBarsState` builds its state from a drives `Chooser` decision and the `Drives` values.",
|
|
7
|
+
"`associationsTable` draws cues by acts: each cell is the net strength, excitation minus inhibition, from 0 to 99 in pink, and the attn column is how much it still pays attention to the cue. `associationsState` reads a `CueLearner`; reset learning calls your `onReset`.",
|
|
8
|
+
"`eyeInset` makes an element the eye card: a canvas, a who switch and a mode line. each frame it calls your draw inside the who's first person eye from @hackbuild/cameras, so its own head is hidden for that render. a draw that returns a string sets the mode line.",
|
|
9
|
+
"`defineViews()` registers `hb-drives-bars`, `hb-associations-table` and `hb-eye-inset`; the vue forms live in `@hackbuild/agents-views/vue`. load hackbuild-ui's hackbuild.css for the look.",
|
|
10
|
+
],
|
|
11
|
+
packages: ["@hackbuild/agents-views", "@hackbuild/drives", "@hackbuild/cameras"],
|
|
12
|
+
install: "npm install @hackbuild/agents-views @hackbuild/drives @hackbuild/cameras @virgilvox/hackbuild-ui",
|
|
13
|
+
today: `git clone https://github.com/hackbuild/hackbuild-agents
|
|
14
|
+
cd hackbuild-agents && npm ci && npm run build -w @hackbuild/agents-views`,
|
|
15
|
+
lang: "ts",
|
|
16
|
+
code: `import { drivesBars, drivesBarsState } from "@hackbuild/agents-views";
|
|
17
|
+
|
|
18
|
+
const bars = drivesBars(document.querySelector("#brain"));
|
|
19
|
+
// each tick, after the chooser decided
|
|
20
|
+
const d = chooser.update(now, utilities);
|
|
21
|
+
bars.update(drivesBarsState(d, drives, { now, seconds: now - since }));`,
|
|
22
|
+
links: { page: "https://hackbuild.github.io/hackbuild-agents/drives-bars/", source: "https://github.com/hackbuild/hackbuild-agents/tree/main/packages/agents-views" },
|
|
23
|
+
};
|
|
24
|
+
export default how;
|
package/llms.md
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
# @hackbuild/agents-views
|
|
2
|
+
|
|
3
|
+
> The brain bars, the associations table and the eye card of a simulated animal, as views you mount on any page with the hackbuild-ui look.
|
|
4
|
+
|
|
5
|
+
Generated by tools/llms.mjs from the TypeDoc JSON, the README and the examples of hackbuild-agents. Human docs: https://hackbuild.github.io/hackbuild-agents/docs/agents-views/
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
- Draws what the animal is doing and why, what each act is worth now with the chosen one in pink, and how much it needs each thing.
|
|
10
|
+
- Draws what it has learned: cues by acts, each cell the net strength from 0 to 99, with how much it still pays attention to each cue.
|
|
11
|
+
- Makes an element the eye card: a canvas drawn from inside the animal's own eye, a switch for whose eyes, and a mode line.
|
|
12
|
+
- Ships each view three ways that draw the same markup: a plain function over a host element, a custom element and a Vue component.
|
|
13
|
+
- Reads @hackbuild/drives and @hackbuild/cameras objects by their shape, so it has no runtime dependency on either.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @hackbuild/agents-views @hackbuild/drives @virgilvox/hackbuild-ui
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`@virgilvox/hackbuild-ui` (0.10 or 0.11) is a peer: the views write its classes and never style themselves, so load its `hackbuild.css` on the page. `vue` (3.5 or later) is an optional peer, needed only for the `@hackbuild/agents-views/vue` entry. @hackbuild/drives is what the quick start feeds the views; @hackbuild/cameras gives the eye card its `FirstPerson` eye. Neither is a dependency of this package.
|
|
22
|
+
|
|
23
|
+
## Exports
|
|
24
|
+
|
|
25
|
+
### @hackbuild/agents-views
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
const ASSOCIATIONS_NOTE: "rows are cues, columns are acts. cells show net strength, excitation minus a separate inhibition that fades faster, so an extinguished cue partly comes back after a break. the attn column is each cue's associability: it rises after surprises and falls as the outcome becomes predictable. credit fades with delay, so a slow treat can reward whatever it is doing when it lands. if nothing is strong it offers tricks it was rewarded for before; teach a new word by praising whatever it does."
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The explanation under the table: how net strength, attention and delayed credit work.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
interface AssociationsHandle {
|
|
35
|
+
readonly root: HTMLElement;
|
|
36
|
+
dispose(): void;
|
|
37
|
+
update(state: AssociationsState): void;
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
What `associationsTable` returns: the host, an update and a dispose.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
interface AssociationsOptions {
|
|
45
|
+
limit?: number;
|
|
46
|
+
note?: string;
|
|
47
|
+
onReset?: () => void;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Options of `associationsTable`.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
interface AssociationsRow {
|
|
55
|
+
attention: number;
|
|
56
|
+
cue: string;
|
|
57
|
+
values: number[];
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
One cue row of the table.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
function associationsState(learner: LearnerLike, o?: { last?: { action: string; cue: string } | null; trial?: string }): AssociationsState
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Builds the table from a CueLearner: net strength is excitation minus inhibition.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
interface AssociationsState {
|
|
71
|
+
actions: string[];
|
|
72
|
+
cues: AssociationsRow[];
|
|
73
|
+
last?: { action: string; cue: string } | null;
|
|
74
|
+
trial?: string;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
What the table draws.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
function associationsTable(host: HTMLElement, o?: AssociationsOptions): AssociationsHandle
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Renders the associations panel into `host`.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
interface AssociationsTableElement extends HTMLElement {
|
|
88
|
+
state: AssociationsState | null;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`<hb-associations-table>`: set `.state`; fires `reset` when reset learning is pressed.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
interface DecisionLike {
|
|
96
|
+
current: string;
|
|
97
|
+
pending: { at: number; id: string; latency: number } | null;
|
|
98
|
+
reason: string;
|
|
99
|
+
utilities: Record<string, number>;
|
|
100
|
+
why: string;
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The parts of a @hackbuild/drives Chooser decision the view reads.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
function defineViews(registry?: CustomElementRegistry): void
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Defines the three elements once; safe to call again.
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const DRIVES_NOTE: "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing."
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The note under the utility rows while no switch is pending.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
function drivesBars(host: HTMLElement, o?: DrivesBarsOptions): DrivesBarsHandle
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Renders the behavior, utility and drives panels into `host`.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
interface DrivesBarsElement extends HTMLElement {
|
|
126
|
+
state: DrivesBarsState | null;
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`<hb-drives-bars>`: set `.state` to a DrivesBarsState.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
interface DrivesBarsFrom {
|
|
134
|
+
behavior?: string;
|
|
135
|
+
now?: number;
|
|
136
|
+
pink?: readonly string[];
|
|
137
|
+
sampled?: boolean;
|
|
138
|
+
seconds?: number;
|
|
139
|
+
why?: string;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Options of `drivesBarsState`: the clock, the seconds in the act and names of your own.
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
interface DrivesBarsHandle {
|
|
147
|
+
readonly root: HTMLElement;
|
|
148
|
+
dispose(): void;
|
|
149
|
+
update(state: DrivesBarsState): void;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
What `drivesBars` returns: the host, an update and a dispose.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
interface DrivesBarsOptions {
|
|
157
|
+
note?: string;
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Options of `drivesBars`.
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
function drivesBarsState(d: DecisionLike, drives: DrivesLike, o?: DrivesBarsFrom): DrivesBarsState
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Builds the view state from a Chooser decision and the drives.
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
interface DrivesBarsState {
|
|
171
|
+
behavior: string;
|
|
172
|
+
current?: string;
|
|
173
|
+
drives: Record<string, number>;
|
|
174
|
+
mode?: string;
|
|
175
|
+
pending?: { id: string; inMs: number } | null;
|
|
176
|
+
pink?: readonly string[];
|
|
177
|
+
seconds?: number;
|
|
178
|
+
utilities: Record<string, number>;
|
|
179
|
+
why?: string;
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
What the view draws.
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
type DrivesLike = Record<string, number> | { readonly values: Record<string, number> }
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Drives values, or a @hackbuild/drives Drives object.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
const ELEMENT_NAMES: { readonly associationsTable: "hb-associations-table"; readonly drivesBars: "hb-drives-bars"; readonly eyeInset: "hb-eye-inset" }
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The tag names `defineViews` registers.
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
function eyeInset(host: HTMLElement, o: EyeInsetOptions): EyeInsetHandle
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Makes `host` the eye card: head with the mode line, the who switch, the canvas.
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
interface EyeInsetElement extends HTMLElement {
|
|
205
|
+
options: EyeInsetOptions | null;
|
|
206
|
+
readonly view: EyeInsetHandle | null;
|
|
207
|
+
frame(): void;
|
|
208
|
+
mode(text: string): void;
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`<hb-eye-inset>`: set `.options` (who and draw), then call `frame()` each frame; fires `who` with the id in `detail`.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
interface EyeInsetHandle {
|
|
216
|
+
readonly canvas: HTMLCanvasElement;
|
|
217
|
+
readonly root: HTMLElement;
|
|
218
|
+
readonly who: EyeWho;
|
|
219
|
+
dispose(): void;
|
|
220
|
+
frame(): void;
|
|
221
|
+
mode(text: string): void;
|
|
222
|
+
select(id: string): void;
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
What `eyeInset` returns: the canvas, the selected who and the frame call.
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
interface EyeInsetOptions {
|
|
230
|
+
canvas?: HTMLCanvasElement;
|
|
231
|
+
draw: (canvas: HTMLCanvasElement, who: EyeWho) => string | void;
|
|
232
|
+
height?: number;
|
|
233
|
+
onWho?: (id: string) => void;
|
|
234
|
+
selected?: string;
|
|
235
|
+
who: readonly EyeWho[];
|
|
236
|
+
width?: number;
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Options of `eyeInset`.
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
interface EyeLike {
|
|
244
|
+
render(draw: () => void): void;
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
A @hackbuild/cameras FirstPerson, or anything that hides a head round a draw.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
interface EyeWho {
|
|
252
|
+
eye?: EyeLike;
|
|
253
|
+
id: string;
|
|
254
|
+
label: string;
|
|
255
|
+
title?: string;
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
One choice of the who switch: whose eyes the card draws.
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
interface LearnerLike {
|
|
263
|
+
readonly actions: readonly string[];
|
|
264
|
+
toJSON(): LearnerStateLike;
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
A @hackbuild/drives CueLearner, or anything with its actions and toJSON.
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
interface LearnerStateLike {
|
|
272
|
+
cues: Record<string, { associability: number; n: Record<string, number>; w: Record<string, number> }>;
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
The @hackbuild/drives LearnerState shape (CueLearner.toJSON()).
|
|
277
|
+
|
|
278
|
+
### @hackbuild/agents-views/vue
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
const AssociationsTable: DefineComponent<ExtractPropTypes<{ limit: { default: number; type: NumberConstructor }; state: { required: true; type: PropType<AssociationsState> } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, "reset"[], "reset", PublicProps, ToResolvedProps<ExtractPropTypes<{ limit: { default: number; type: NumberConstructor }; state: { required: true; type: PropType<AssociationsState> } }>, "reset"[]>, { limit: number }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The cues by acts heat table with attention, the explanation and reset.
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
const DrivesBars: DefineComponent<ExtractPropTypes<{ note: { default: undefined; type: StringConstructor }; state: { required: true; type: PropType<DrivesBarsState> } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<ExtractPropTypes<{ note: { default: undefined; type: StringConstructor }; state: { required: true; type: PropType<DrivesBarsState> } }>, {}>, { note: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
The behavior block, utility rows (current in pink) and drive rows.
|
|
291
|
+
|
|
292
|
+
```ts
|
|
293
|
+
const EyeInset: DefineComponent<ExtractPropTypes<{ draw: { required: true; type: PropType<(canvas: HTMLCanvasElement, who: EyeWho) => string | void> }; height: { default: number; type: NumberConstructor }; selected: { default: undefined; type: StringConstructor }; who: { required: true; type: PropType<EyeWho[]> }; width: { default: number; type: NumberConstructor } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, "update:selected"[], "update:selected", PublicProps, ToResolvedProps<ExtractPropTypes<{ draw: { required: true; type: PropType<(canvas: HTMLCanvasElement, who: EyeWho) => string | void> }; height: { default: number; type: NumberConstructor }; selected: { default: undefined; type: StringConstructor }; who: { required: true; type: PropType<EyeWho[]> }; width: { default: number; type: NumberConstructor } }>, "update:selected"[]>, { height: number; selected: string; width: number }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The eye card.
|
|
297
|
+
|
|
298
|
+
## Examples
|
|
299
|
+
|
|
300
|
+
### quick start
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
import { associationsState, associationsTable, drivesBars, drivesBarsState } from "@hackbuild/agents-views";
|
|
304
|
+
import { Chooser, CueLearner, Drives, load, seededRng } from "@hackbuild/drives";
|
|
305
|
+
|
|
306
|
+
// the brain: two drives, three acts and a learner, all seeded
|
|
307
|
+
await load();
|
|
308
|
+
const rng = seededRng(7);
|
|
309
|
+
const drives = new Drives({ hunger: 1, play: 0.8 });
|
|
310
|
+
const chooser = new Chooser({ rng, options: ["idle", "eat", "fetch"] as const });
|
|
311
|
+
const learner = new CueLearner({ rng, actions: ["sit", "paw"] as const });
|
|
312
|
+
|
|
313
|
+
// the views: mount once, update each tick
|
|
314
|
+
const bars = drivesBars(document.body.appendChild(document.createElement("div")));
|
|
315
|
+
const table = associationsTable(document.body.appendChild(document.createElement("div")), { onReset: () => location.reload() });
|
|
316
|
+
let now = 0;
|
|
317
|
+
setInterval(() => {
|
|
318
|
+
now += 0.5;
|
|
319
|
+
drives.grow(0.5, { hunger: 0.02, play: 0.03 });
|
|
320
|
+
const d = chooser.update(now, { idle: 0.1, eat: drives.rewardOf({ hunger: -0.5 }), fetch: drives.rewardOf({ play: -0.4 }) });
|
|
321
|
+
bars.update(drivesBarsState(d, drives, { now }));
|
|
322
|
+
table.update(associationsState(learner));
|
|
323
|
+
}, 500);
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### from the concepts
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
import { drivesBars } from "@hackbuild/agents-views";
|
|
330
|
+
|
|
331
|
+
const bars = drivesBars(document.querySelector("#brain") as HTMLElement);
|
|
332
|
+
bars.update({ behavior: "fetch", why: "play is high", utilities: { idle: 0.1, fetch: 0.6 }, drives: { play: 0.8, hunger: 0.3 } });
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Mistakes to avoid
|
|
336
|
+
|
|
337
|
+
- Load the hackbuild-ui stylesheet (`hackbuild.css` from @virgilvox/hackbuild-ui) on the page. The views write its classes only and carry no styles, so without it the bars and the table draw as plain text.
|
|
338
|
+
- Mount a view once and call `update(state)` each tick. Calling `drivesBars(host)` again every frame rebuilds the panels and loses the in place bar motion.
|
|
339
|
+
- Call `load()` from @hackbuild/drives before making the `Chooser`, `Drives` or `CueLearner` you pass to `drivesBarsState` or `associationsState`; this package reads them by shape and never loads the wasm itself.
|
|
340
|
+
- Call the eye card's `frame()` from your render loop. `eyeInset` draws nothing by itself, and `draw` runs inside `who.eye.render`, so do not hide or restore the head yourself.
|
|
341
|
+
- Import Vue components from `@hackbuild/agents-views/vue`, not the main entry, and install `vue` for it; the main entry has no Vue code.
|
|
342
|
+
|
|
343
|
+
## Errors this package throws
|
|
344
|
+
|
|
345
|
+
- `@hackbuild/agents-views: eyeInset needs at least one who` (`eyeInset` got an empty `who` list): pass at least one who entry
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/agents-views",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Views that bind the agents packages to the hackbuild-ui class layer: the behaviour, utility and drive bars, the cues by acts associations table, and the eye inset. Each ships as a Vue component and as a custom element.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Moheeb Zara <hackbuildvideo@gmail.com>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/hackbuild/hackbuild-agents.git",
|
|
11
|
+
"directory": "packages/agents-views"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./vue": {
|
|
23
|
+
"types": "./dist/vue.d.ts",
|
|
24
|
+
"import": "./dist/vue.js"
|
|
25
|
+
},
|
|
26
|
+
"./iife": "./dist/agents-views.iife.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md",
|
|
31
|
+
"llms.md",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"how.ts"
|
|
34
|
+
],
|
|
35
|
+
"unpkg": "./dist/agents-views.iife.js",
|
|
36
|
+
"jsdelivr": "./dist/agents-views.iife.js",
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "node ../../tools/build-package.mjs agents-views HackbuildAgentsViews"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@virgilvox/hackbuild-ui": ">=0.10.0 <0.12.0",
|
|
42
|
+
"vue": "^3.5.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@virgilvox/hackbuild-ui": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"vue": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|