@hackbuild/agents-views 0.1.1 → 0.2.0
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/README.md +32 -5
- package/dist/agents-views.iife.js +202 -4
- package/dist/eye-inset.d.ts +2 -0
- package/dist/eye-inset.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/map-inset.d.ts +34 -0
- package/dist/map-inset.js +60 -0
- package/dist/plan-log.d.ts +76 -0
- package/dist/plan-log.js +106 -0
- package/dist/vue.d.ts +74 -0
- package/dist/vue.js +58 -0
- package/dist/yard/scope.d.ts +36 -0
- package/dist/yard/scope.js +5132 -0
- package/dist/yard.d.ts +55 -0
- package/dist/yard.js +175 -0
- package/llms.md +193 -1
- package/package.json +40 -4
package/dist/yard.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a yard asset comes from: a URL (fetched), the bytes, a Blob, or a function that returns
|
|
3
|
+
* any of those. A string that starts with `data:` is read as a data URL.
|
|
4
|
+
*/
|
|
5
|
+
export type YardAsset = string | URL | ArrayBuffer | Uint8Array | Blob | (() => Promise<string | URL | ArrayBuffer | Uint8Array | Blob>);
|
|
6
|
+
/** Options of `mountYard`. */
|
|
7
|
+
export interface YardOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Returns the `@dimforge/rapier3d-compat` module (or its default export). The yard calls
|
|
10
|
+
* `init()` on it. It is a function so a host can load the 1.6 MB gzip (measured) core lazily,
|
|
11
|
+
* from its own bundle or from a plain file.
|
|
12
|
+
*/
|
|
13
|
+
physics: () => Promise<unknown>;
|
|
14
|
+
/** The dog model, a binary glTF with the rig the yard expects. */
|
|
15
|
+
dog: YardAsset;
|
|
16
|
+
/** The person model, a binary glTF; null or left out draws a placeholder of capsules. */
|
|
17
|
+
human?: YardAsset | null;
|
|
18
|
+
/** The person's clip pack (JSON with roles, fps and clips), as an object or an asset. */
|
|
19
|
+
anims: YardAsset | object;
|
|
20
|
+
/** His voice reference, a wav for the cloned voice; left out, he speaks in a browser voice. */
|
|
21
|
+
voice?: YardAsset | null;
|
|
22
|
+
/** A model hub base URL for the cortex models in place of https://huggingface.co/. */
|
|
23
|
+
hub?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Where the readout chips, the setup button and the command button go, such as the host's
|
|
26
|
+
* header. Left out, the two buttons join the verb row and the chips are not shown.
|
|
27
|
+
*/
|
|
28
|
+
bar?: HTMLElement | null;
|
|
29
|
+
/**
|
|
30
|
+
* The yard's switches as a query string: `test&seed=N` for lockstep, `seed=N&speed=S`,
|
|
31
|
+
* `cortex=stub`, `stubloads`. Default: the page hash, when `reseed` is also left out.
|
|
32
|
+
*/
|
|
33
|
+
params?: string;
|
|
34
|
+
/** Runs a new seed (the tune tab's seed row). Left out with `params`, the row only reads. */
|
|
35
|
+
reseed?: (params: string) => void;
|
|
36
|
+
/** Opens the setup panel on a first visit (default true); the setup button opens it anyway. */
|
|
37
|
+
setup?: boolean;
|
|
38
|
+
/** The suite's base URL; links into it show only when it is set. */
|
|
39
|
+
suiteUrl?: string;
|
|
40
|
+
}
|
|
41
|
+
/** What `mountYard` returns. */
|
|
42
|
+
export interface YardHandle {
|
|
43
|
+
/** the yard root inside the host */
|
|
44
|
+
readonly root: HTMLElement;
|
|
45
|
+
/** resolves with the scope's test handle once the dog and his person stand in the yard */
|
|
46
|
+
readonly ready: Promise<unknown>;
|
|
47
|
+
/** stops the loop, the workers, the voice and the microphone, and empties the host */
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Mounts the yard in `host`. The yard keeps one instance per page: its parts find each other by
|
|
52
|
+
* id. Its stylesheet goes into the document head once. Load hackbuild-ui's `hackbuild.css` on the
|
|
53
|
+
* page for the look.
|
|
54
|
+
*/
|
|
55
|
+
export declare function mountYard(host: HTMLElement, o: YardOptions): Promise<YardHandle>;
|
package/dist/yard.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Yard: the dog simulator's stage and rack as one view. A dog and his person in a 3D yard, the
|
|
2
|
+
// care verbs on the stage, the dog eye inset, the seven tabs of the rack (brain with the drives
|
|
3
|
+
// bars, body, sense, train with the associations table, human, tune, how), the cortex model
|
|
4
|
+
// select, the setup panel and the command palette. The host passes what the yard loads: the
|
|
5
|
+
// physics module, the dog and person models, the person's clips and voice, and a model hub.
|
|
6
|
+
// Needs three.js (the WebGPU build) and the @hackbuild packages the yard runs on; see README.
|
|
7
|
+
import { runYard, YARD_BAR_HTML, YARD_CSS, YARD_HTML } from "./yard/scope.js";
|
|
8
|
+
const STYLE_ID = "hb-yard-style";
|
|
9
|
+
async function bytes(a) {
|
|
10
|
+
const v = typeof a === "function" ? await a() : a;
|
|
11
|
+
if (v instanceof ArrayBuffer)
|
|
12
|
+
return v;
|
|
13
|
+
if (v instanceof Uint8Array)
|
|
14
|
+
return v.slice().buffer;
|
|
15
|
+
if (v instanceof Blob)
|
|
16
|
+
return v.arrayBuffer();
|
|
17
|
+
const r = await fetch(String(v));
|
|
18
|
+
if (!r.ok)
|
|
19
|
+
throw new Error(`${String(v).slice(0, 80)} http ${r.status}`);
|
|
20
|
+
return r.arrayBuffer();
|
|
21
|
+
}
|
|
22
|
+
function base64(buf) {
|
|
23
|
+
const u = new Uint8Array(buf);
|
|
24
|
+
let s = "";
|
|
25
|
+
for (let i = 0; i < u.length; i += 0x8000)
|
|
26
|
+
s += String.fromCharCode(...u.subarray(i, i + 0x8000));
|
|
27
|
+
return btoa(s);
|
|
28
|
+
}
|
|
29
|
+
const isAsset = (a) => typeof a === "string" || typeof a === "function" || a instanceof URL || a instanceof ArrayBuffer || a instanceof Uint8Array || a instanceof Blob;
|
|
30
|
+
/**
|
|
31
|
+
* Mounts the yard in `host`. The yard keeps one instance per page: its parts find each other by
|
|
32
|
+
* id. Its stylesheet goes into the document head once. Load hackbuild-ui's `hackbuild.css` on the
|
|
33
|
+
* page for the look.
|
|
34
|
+
*/
|
|
35
|
+
export async function mountYard(host, o) {
|
|
36
|
+
if (typeof o.physics !== "function")
|
|
37
|
+
throw new Error("@hackbuild/agents-views: mountYard needs physics, a function returning the rapier3d-compat module");
|
|
38
|
+
if (!o.dog)
|
|
39
|
+
throw new Error("@hackbuild/agents-views: mountYard needs the dog model");
|
|
40
|
+
const doc = host.ownerDocument;
|
|
41
|
+
const win = doc.defaultView ?? window;
|
|
42
|
+
if (doc.querySelector(".hb-yard"))
|
|
43
|
+
throw new Error("@hackbuild/agents-views: a yard is mounted on this page already");
|
|
44
|
+
if (!doc.getElementById(STYLE_ID)) {
|
|
45
|
+
const st = doc.createElement("style");
|
|
46
|
+
st.id = STYLE_ID;
|
|
47
|
+
st.textContent = YARD_CSS;
|
|
48
|
+
doc.head.append(st);
|
|
49
|
+
}
|
|
50
|
+
const root = doc.createElement("div");
|
|
51
|
+
root.className = "hb-yard";
|
|
52
|
+
root.innerHTML = YARD_HTML;
|
|
53
|
+
const barTpl = doc.createElement("div");
|
|
54
|
+
barTpl.innerHTML = YARD_BAR_HTML;
|
|
55
|
+
const barParts = [...barTpl.children];
|
|
56
|
+
if (o.bar) {
|
|
57
|
+
o.bar.classList.add("hb-yard-bar");
|
|
58
|
+
o.bar.append(...barParts);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// no bar: setup and commands sit at the end of the verb row; the chips stay off the page
|
|
62
|
+
const tool = root.querySelector("#tool");
|
|
63
|
+
for (const p of barParts)
|
|
64
|
+
if (p.tagName === "BUTTON")
|
|
65
|
+
tool?.append(p);
|
|
66
|
+
}
|
|
67
|
+
host.replaceChildren(root);
|
|
68
|
+
const cleanups = [];
|
|
69
|
+
const timers = new Set();
|
|
70
|
+
const observers = [];
|
|
71
|
+
const streams = [];
|
|
72
|
+
const disposers = [];
|
|
73
|
+
const lookIn = [root, barTpl, ...(o.bar ? [o.bar] : [])];
|
|
74
|
+
const cache = new Map();
|
|
75
|
+
const byId = (id) => {
|
|
76
|
+
const c = cache.get(id);
|
|
77
|
+
if (c?.isConnected || (c && barTpl.contains(c)))
|
|
78
|
+
return c;
|
|
79
|
+
for (const r of lookIn) {
|
|
80
|
+
const e = r.querySelector(`#${CSS.escape(id)}`);
|
|
81
|
+
if (e) {
|
|
82
|
+
cache.set(id, e);
|
|
83
|
+
return e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return doc.getElementById(id);
|
|
87
|
+
};
|
|
88
|
+
class TrackedObserver extends win.ResizeObserver {
|
|
89
|
+
constructor(cb) {
|
|
90
|
+
super(cb);
|
|
91
|
+
observers.push(this);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const usesHash = o.params == null && !o.reseed;
|
|
95
|
+
let readyOk = () => { };
|
|
96
|
+
let readyErr = () => { };
|
|
97
|
+
const ready = new Promise((res, rej) => { readyOk = res; readyErr = rej; });
|
|
98
|
+
const [rapier, voice] = await Promise.all([o.physics(), o.voice ? bytes(o.voice).then(base64).catch(() => "") : Promise.resolve("")]);
|
|
99
|
+
const env = {
|
|
100
|
+
rapier,
|
|
101
|
+
suiteUrl: o.suiteUrl ?? "",
|
|
102
|
+
params: o.params ?? (usesHash ? win.location.hash.slice(1) : ""),
|
|
103
|
+
canReseed: !!o.reseed || usesHash,
|
|
104
|
+
setup: o.setup ?? true,
|
|
105
|
+
hub: o.hub ?? "",
|
|
106
|
+
voice,
|
|
107
|
+
byId,
|
|
108
|
+
qsa: (sel) => lookIn.flatMap((r) => [...r.querySelectorAll(sel)]),
|
|
109
|
+
docOn(type, fn, opts) {
|
|
110
|
+
doc.addEventListener(type, fn, opts);
|
|
111
|
+
cleanups.push(() => doc.removeEventListener(type, fn, opts));
|
|
112
|
+
},
|
|
113
|
+
on(type, fn, opts) {
|
|
114
|
+
win.addEventListener(type, fn, opts);
|
|
115
|
+
cleanups.push(() => win.removeEventListener(type, fn, opts));
|
|
116
|
+
},
|
|
117
|
+
setTimeout(fn, ms) {
|
|
118
|
+
const id = win.setTimeout(() => { timers.delete(id); fn(); }, ms);
|
|
119
|
+
timers.add(id);
|
|
120
|
+
return id;
|
|
121
|
+
},
|
|
122
|
+
setInterval(fn, ms) {
|
|
123
|
+
const id = win.setInterval(fn, ms);
|
|
124
|
+
timers.add(id);
|
|
125
|
+
return id;
|
|
126
|
+
},
|
|
127
|
+
ResizeObserver: TrackedObserver,
|
|
128
|
+
stream(s) {
|
|
129
|
+
streams.push(s);
|
|
130
|
+
return s;
|
|
131
|
+
},
|
|
132
|
+
dog: () => bytes(o.dog),
|
|
133
|
+
human: () => (o.human ? bytes(o.human) : Promise.resolve(null)),
|
|
134
|
+
anims: async () => (isAsset(o.anims) ? JSON.parse(new TextDecoder().decode(await bytes(o.anims))) : o.anims),
|
|
135
|
+
reseed: o.reseed ?? ((q) => { win.location.hash = q; win.location.reload(); }),
|
|
136
|
+
dispose: (fn) => { disposers.push(fn); },
|
|
137
|
+
ready: (h) => readyOk(h),
|
|
138
|
+
fail: (e) => readyErr(e),
|
|
139
|
+
};
|
|
140
|
+
runYard(env);
|
|
141
|
+
ready.catch(() => { });
|
|
142
|
+
let gone = false;
|
|
143
|
+
return {
|
|
144
|
+
root,
|
|
145
|
+
ready,
|
|
146
|
+
dispose() {
|
|
147
|
+
if (gone)
|
|
148
|
+
return;
|
|
149
|
+
gone = true;
|
|
150
|
+
for (const f of disposers) {
|
|
151
|
+
try {
|
|
152
|
+
f();
|
|
153
|
+
}
|
|
154
|
+
catch { /* keep tearing down */ }
|
|
155
|
+
}
|
|
156
|
+
for (const f of cleanups)
|
|
157
|
+
f();
|
|
158
|
+
for (const t of timers) {
|
|
159
|
+
win.clearTimeout(t);
|
|
160
|
+
win.clearInterval(t);
|
|
161
|
+
}
|
|
162
|
+
for (const ob of observers)
|
|
163
|
+
ob.disconnect();
|
|
164
|
+
for (const s of streams)
|
|
165
|
+
for (const t of s.getTracks())
|
|
166
|
+
t.stop();
|
|
167
|
+
for (const p of barParts)
|
|
168
|
+
p.remove();
|
|
169
|
+
o.bar?.classList.remove("hb-yard-bar");
|
|
170
|
+
root.remove();
|
|
171
|
+
if (!doc.querySelector(".hb-yard"))
|
|
172
|
+
doc.getElementById(STYLE_ID)?.remove();
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
package/llms.md
CHANGED
|
@@ -9,7 +9,8 @@ Generated by tools/llms.mjs from the TypeDoc JSON, the README and the examples o
|
|
|
9
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
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
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
|
-
-
|
|
12
|
+
- Mounts Yard, the dog simulator's whole stage and rack, from `@hackbuild/agents-views/yard`: the dog and his person in a 3D yard, the care verbs, the eye inset, the seven tabs with the drives bars and the associations table, the tune rack, the cortex model select and the setup panel.
|
|
13
|
+
- Ships each small view three ways that draw the same markup: a plain function over a host element, a custom element and a Vue component.
|
|
13
14
|
- Reads @hackbuild/drives and @hackbuild/cameras objects by their shape, so it has no runtime dependency on either.
|
|
14
15
|
|
|
15
16
|
## Install
|
|
@@ -20,6 +21,8 @@ npm install @hackbuild/agents-views @hackbuild/drives @virgilvox/hackbuild-ui
|
|
|
20
21
|
|
|
21
22
|
`@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
|
|
|
24
|
+
The `@hackbuild/agents-views/yard` entry needs `three` (0.186 or 0.187, its WebGPU build) and @hackbuild/motion-net, gait, tunables, senses, drives, cameras and weights, all optional peers so the small views install without them. The host passes the physics core (`@dimforge/rapier3d-compat`) and the models.
|
|
25
|
+
|
|
23
26
|
## Exports
|
|
24
27
|
|
|
25
28
|
### @hackbuild/agents-views
|
|
@@ -109,6 +112,12 @@ function defineViews(registry?: CustomElementRegistry): void
|
|
|
109
112
|
|
|
110
113
|
Defines the three elements once; safe to call again.
|
|
111
114
|
|
|
115
|
+
```ts
|
|
116
|
+
function drawMap(canvas: HTMLCanvasElement, m: MapState): string
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Draws one frame of the map; returns the mode line, as "212 cells seen".
|
|
120
|
+
|
|
112
121
|
```ts
|
|
113
122
|
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
123
|
```
|
|
@@ -232,6 +241,7 @@ interface EyeInsetOptions {
|
|
|
232
241
|
height?: number;
|
|
233
242
|
onWho?: (id: string) => void;
|
|
234
243
|
selected?: string;
|
|
244
|
+
title?: string;
|
|
235
245
|
who: readonly EyeWho[];
|
|
236
246
|
width?: number;
|
|
237
247
|
}
|
|
@@ -275,6 +285,112 @@ interface LearnerStateLike {
|
|
|
275
285
|
|
|
276
286
|
The @hackbuild/drives LearnerState shape (CueLearner.toJSON()).
|
|
277
287
|
|
|
288
|
+
```ts
|
|
289
|
+
interface LogHandle<S> {
|
|
290
|
+
dispose(): void;
|
|
291
|
+
update(state: S): void;
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
What `stepLog` and `planLog` return.
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
function mapInset(host: HTMLElement, o: MapInsetOptions): EyeInsetHandle
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Makes `host` the map card; call `frame()` to draw.
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
interface MapInsetOptions {
|
|
305
|
+
label?: string;
|
|
306
|
+
map: () => MapState;
|
|
307
|
+
size?: number;
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Options of `mapInset`.
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
interface MapState {
|
|
315
|
+
at: { x: number; z: number };
|
|
316
|
+
cells: ArrayLike<number>;
|
|
317
|
+
cols: number;
|
|
318
|
+
half: number;
|
|
319
|
+
rows: number;
|
|
320
|
+
trail: readonly { x: number; z: number }[];
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
The map as the view reads it.
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
function planBook(o?: { max?: number; now?: () => number }): PlanBook
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
A plan book keeping at most `max` steps and thoughts (default 200).
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
interface PlanBook {
|
|
334
|
+
clear(): void;
|
|
335
|
+
push(e: PlanEventLike): boolean;
|
|
336
|
+
setGoals(lines: readonly string[]): void;
|
|
337
|
+
state(): PlanLogState;
|
|
338
|
+
think(kind: string, line: string): void;
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
The book behind PlanLog and StepLog: push agent events, thoughts and goals; read `state()`.
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
type PlanEventLike = { plan: { do: readonly { args: readonly unknown[]; tool: string }[]; think?: string }; type: "plan"; via: string } | { result: { ok: boolean; step: { args: readonly unknown[]; tool: string }; text: string }; type: "step" } | { type: string }
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
The parts of a @hackbuild/agent event the book reads.
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
function planLog(host: HTMLElement, o?: { empty?: string; steps?: boolean }): LogHandle<PlanLogState>
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
The plan log: last plan with who made it, goals, thoughts, and the step log under them.
|
|
355
|
+
|
|
356
|
+
```ts
|
|
357
|
+
interface PlanLogState {
|
|
358
|
+
goals: readonly string[];
|
|
359
|
+
plan: string;
|
|
360
|
+
steps: readonly StepLine[];
|
|
361
|
+
thoughts: readonly ThoughtLine[];
|
|
362
|
+
via: string;
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
What PlanLog draws.
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
interface StepLine {
|
|
370
|
+
line: string;
|
|
371
|
+
ok: boolean;
|
|
372
|
+
t: number;
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
One step as the log shows it.
|
|
377
|
+
|
|
378
|
+
```ts
|
|
379
|
+
function stepLog(host: HTMLElement, o?: { empty?: string; label?: string }): LogHandle<readonly StepLine[]>
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
The step log: one rack log row per tool call.
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
interface ThoughtLine {
|
|
386
|
+
kind: string;
|
|
387
|
+
line: string;
|
|
388
|
+
t: number;
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
A thought it had with no order: a mutter, or a reflection on what it attends to.
|
|
393
|
+
|
|
278
394
|
### @hackbuild/agents-views/vue
|
|
279
395
|
|
|
280
396
|
```ts
|
|
@@ -295,6 +411,66 @@ const EyeInset: DefineComponent<ExtractPropTypes<{ draw: { required: true; type:
|
|
|
295
411
|
|
|
296
412
|
The eye card.
|
|
297
413
|
|
|
414
|
+
```ts
|
|
415
|
+
const MapInset: DefineComponent<ExtractPropTypes<{ map: { required: true; type: PropType<() => MapState> }; size: { default: number; type: NumberConstructor } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<ExtractPropTypes<{ map: { required: true; type: PropType<() => MapState> }; size: { default: number; type: NumberConstructor } }>, {}>, { size: number }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
The map card.
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
const PlanLog: DefineComponent<ExtractPropTypes<{ state: { required: true; type: PropType<PlanLogState> }; steps: { default: boolean; type: BooleanConstructor } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<ExtractPropTypes<{ state: { required: true; type: PropType<PlanLogState> }; steps: { default: boolean; type: BooleanConstructor } }>, {}>, { steps: boolean }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
The plan log: last plan, goals, thoughts and steps.
|
|
425
|
+
|
|
426
|
+
```ts
|
|
427
|
+
const StepLog: DefineComponent<ExtractPropTypes<{ empty: { default: string; type: StringConstructor }; steps: { required: true; type: PropType<readonly StepLine[]> } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<ExtractPropTypes<{ empty: { default: string; type: StringConstructor }; steps: { required: true; type: PropType<readonly StepLine[]> } }>, {}>, { empty: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
The step log: one rack log row per tool call.
|
|
431
|
+
|
|
432
|
+
### @hackbuild/agents-views/yard
|
|
433
|
+
|
|
434
|
+
```ts
|
|
435
|
+
function mountYard(host: HTMLElement, o: YardOptions): Promise<YardHandle>
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
Mounts the yard in `host`.
|
|
439
|
+
|
|
440
|
+
```ts
|
|
441
|
+
type YardAsset = string | URL | ArrayBuffer | Uint8Array | Blob | () => Promise<string | URL | ArrayBuffer | Uint8Array | Blob>
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
Where a yard asset comes from: a URL (fetched), the bytes, a Blob, or a function that returns any of those.
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
interface YardHandle {
|
|
448
|
+
readonly ready: Promise<unknown>;
|
|
449
|
+
readonly root: HTMLElement;
|
|
450
|
+
dispose(): void;
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
What `mountYard` returns.
|
|
455
|
+
|
|
456
|
+
```ts
|
|
457
|
+
interface YardOptions {
|
|
458
|
+
anims: object | YardAsset;
|
|
459
|
+
bar?: HTMLElement | null;
|
|
460
|
+
dog: YardAsset;
|
|
461
|
+
hub?: string;
|
|
462
|
+
human?: YardAsset | null;
|
|
463
|
+
params?: string;
|
|
464
|
+
physics: () => Promise<unknown>;
|
|
465
|
+
reseed?: (params: string) => void;
|
|
466
|
+
setup?: boolean;
|
|
467
|
+
suiteUrl?: string;
|
|
468
|
+
voice?: YardAsset | null;
|
|
469
|
+
}
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
Options of `mountYard`.
|
|
473
|
+
|
|
298
474
|
## Examples
|
|
299
475
|
|
|
300
476
|
### quick start
|
|
@@ -332,6 +508,22 @@ const bars = drivesBars(document.querySelector("#brain") as HTMLElement);
|
|
|
332
508
|
bars.update({ behavior: "fetch", why: "play is high", utilities: { idle: 0.1, fetch: 0.6 }, drives: { play: 0.8, hunger: 0.3 } });
|
|
333
509
|
```
|
|
334
510
|
|
|
511
|
+
### from the concepts
|
|
512
|
+
|
|
513
|
+
```ts
|
|
514
|
+
import * as RAPIER from "@dimforge/rapier3d-compat";
|
|
515
|
+
import { mountYard } from "@hackbuild/agents-views/yard";
|
|
516
|
+
|
|
517
|
+
const yard = await mountYard(document.querySelector("#yard") as HTMLElement, {
|
|
518
|
+
physics: async () => RAPIER,
|
|
519
|
+
dog: "assets/dog.glb",
|
|
520
|
+
human: "assets/human.glb",
|
|
521
|
+
anims: "assets/anims.json",
|
|
522
|
+
bar: document.querySelector("header"),
|
|
523
|
+
});
|
|
524
|
+
await yard.ready;
|
|
525
|
+
```
|
|
526
|
+
|
|
335
527
|
## Mistakes to avoid
|
|
336
528
|
|
|
337
529
|
- 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.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/agents-views",
|
|
3
|
-
"version": "0.
|
|
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
|
|
3
|
+
"version": "0.2.0",
|
|
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, the eye inset, and Yard, the dog simulator's stage and rack as one view. Each small view ships as a Vue component and as a custom element.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Moheeb Zara <hackbuildvideo@gmail.com>",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"import": "./dist/index.js"
|
|
21
21
|
},
|
|
22
|
+
"./yard": {
|
|
23
|
+
"types": "./dist/yard.d.ts",
|
|
24
|
+
"import": "./dist/yard.js"
|
|
25
|
+
},
|
|
22
26
|
"./vue": {
|
|
23
27
|
"types": "./dist/vue.d.ts",
|
|
24
28
|
"import": "./dist/vue.js"
|
|
@@ -35,11 +39,19 @@
|
|
|
35
39
|
"unpkg": "./dist/agents-views.iife.js",
|
|
36
40
|
"jsdelivr": "./dist/agents-views.iife.js",
|
|
37
41
|
"scripts": {
|
|
38
|
-
"build": "node ../../tools/build-package.mjs agents-views HackbuildAgentsViews"
|
|
42
|
+
"build": "node ../../tools/gen-yard.mjs && node ../../tools/build-package.mjs agents-views HackbuildAgentsViews && node ../../tools/gen-yard.mjs --dist"
|
|
39
43
|
},
|
|
40
44
|
"peerDependencies": {
|
|
41
45
|
"@virgilvox/hackbuild-ui": ">=0.10.0 <0.12.0",
|
|
42
|
-
"vue": "^3.5.0"
|
|
46
|
+
"vue": "^3.5.0",
|
|
47
|
+
"three": ">=0.186.0 <0.188.0",
|
|
48
|
+
"@hackbuild/motion-net": "^0.2.0",
|
|
49
|
+
"@hackbuild/gait": "^0.1.0",
|
|
50
|
+
"@hackbuild/tunables": "^0.1.0",
|
|
51
|
+
"@hackbuild/senses": "^0.1.0",
|
|
52
|
+
"@hackbuild/drives": "^0.1.0",
|
|
53
|
+
"@hackbuild/cameras": "^0.1.0",
|
|
54
|
+
"@hackbuild/weights": "^0.1.0"
|
|
43
55
|
},
|
|
44
56
|
"peerDependenciesMeta": {
|
|
45
57
|
"@virgilvox/hackbuild-ui": {
|
|
@@ -47,6 +59,30 @@
|
|
|
47
59
|
},
|
|
48
60
|
"vue": {
|
|
49
61
|
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"three": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"@hackbuild/motion-net": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"@hackbuild/gait": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"@hackbuild/tunables": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@hackbuild/senses": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@hackbuild/drives": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"@hackbuild/cameras": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"@hackbuild/weights": {
|
|
85
|
+
"optional": true
|
|
50
86
|
}
|
|
51
87
|
}
|
|
52
88
|
}
|