@hackbuild/ai-views 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +93 -2
- package/dist/chat.d.ts +91 -0
- package/dist/chat.js +237 -0
- package/dist/dom.d.ts +38 -0
- package/dist/dom.js +67 -0
- package/dist/elements.d.ts +42 -0
- package/dist/elements.js +378 -0
- package/dist/frame.d.ts +55 -0
- package/dist/frame.js +40 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +10 -0
- package/dist/jobs.d.ts +26 -0
- package/dist/jobs.js +49 -0
- package/dist/memory.d.ts +26 -0
- package/dist/memory.js +36 -0
- package/dist/mount-chat.d.ts +38 -0
- package/dist/mount-chat.js +177 -0
- package/dist/mount-frame.d.ts +45 -0
- package/dist/mount-frame.js +237 -0
- package/dist/mount-mask.d.ts +109 -0
- package/dist/mount-mask.js +446 -0
- package/dist/mount-model.d.ts +27 -0
- package/dist/mount-model.js +122 -0
- package/dist/mount-transcribe.d.ts +42 -0
- package/dist/mount-transcribe.js +203 -0
- package/dist/pick.d.ts +132 -0
- package/dist/pick.js +254 -0
- package/dist/rows.d.ts +36 -0
- package/dist/rows.js +147 -0
- package/dist/single/elements.iife.js +9568 -0
- package/dist/single/elements.js +9542 -0
- package/dist/single/index.iife.js +6814 -0
- package/dist/single/index.js +6778 -0
- package/dist/single/vue.iife.js +11334 -0
- package/dist/single/vue.js +11316 -0
- package/dist/transcribe.d.ts +80 -0
- package/dist/transcribe.js +175 -0
- package/dist/vue.d.ts +259 -0
- package/dist/vue.js +199 -0
- package/how.ts +26 -0
- package/package.json +61 -4
package/dist/elements.js
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hackbuild/ai-views/elements: the views as custom elements for a plain
|
|
3
|
+
* HTML page, and the mount functions they sit on. Light DOM, drawn with
|
|
4
|
+
* the page's hackbuild-ui stylesheet; each element carries `.hb-view`
|
|
5
|
+
* (display contents), so a layout region of hackbuild-ui places its parts. Nothing
|
|
6
|
+
* registers on import: the page calls define().
|
|
7
|
+
*
|
|
8
|
+
* <model-select job="chat" variant="chip"></model-select>
|
|
9
|
+
* <chat-pane id="chat"></chat-pane> <chat-composer for="chat"></chat-composer>
|
|
10
|
+
* <transcribe-drop id="t"></transcribe-drop> <transcript-exports for="t"></transcript-exports>
|
|
11
|
+
* <mask-studio id="m"></mask-studio> <mask-tools for="m"></mask-tools>
|
|
12
|
+
* <frame-view id="f"></frame-view> <camera-feed for="f"></camera-feed>
|
|
13
|
+
*/
|
|
14
|
+
import { chatList } from "./chat.js";
|
|
15
|
+
import { isJob } from "./jobs.js";
|
|
16
|
+
import { useJobsPick, useModelPick } from "./pick.js";
|
|
17
|
+
import { mountChatList, mountChatPane, mountComposer, mountContextMeter } from "./mount-chat.js";
|
|
18
|
+
import { mountCameraFeed, mountFrameView } from "./mount-frame.js";
|
|
19
|
+
import { mountMaskRack, mountMaskStudio, mountMaskTools, mountMaskVerbs } from "./mount-mask.js";
|
|
20
|
+
import { mountModelJobs, mountModelSelect } from "./mount-model.js";
|
|
21
|
+
import { mountTranscribeDrop, mountTranscribeQueue, mountTranscriptExports, mountTranscriptView } from "./mount-transcribe.js";
|
|
22
|
+
import { transcribeQueue } from "./transcribe.js";
|
|
23
|
+
import { mountMemoryInspector } from "./memory.js";
|
|
24
|
+
export { mountModelSelect, mountModelJobs, pickSheet, gateWords } from "./mount-model.js";
|
|
25
|
+
export { mountChatPane, mountComposer, mountChatList, mountContextMeter, turnHtml } from "./mount-chat.js";
|
|
26
|
+
export { mountTranscribeDrop, mountTranscriptView, mountTranscribeQueue, mountTranscriptExports, transcriptHtml } from "./mount-transcribe.js";
|
|
27
|
+
export { mountMaskStudio, mountMaskTools, mountMaskVerbs, mountMaskRack } from "./mount-mask.js";
|
|
28
|
+
export { mountFrameView, mountCameraFeed } from "./mount-frame.js";
|
|
29
|
+
export { mountMemoryInspector } from "./memory.js";
|
|
30
|
+
/** The tag names define() registers, before any prefix. */
|
|
31
|
+
export const ELEMENT_NAMES = [
|
|
32
|
+
"model-select",
|
|
33
|
+
"model-jobs",
|
|
34
|
+
"chat-pane",
|
|
35
|
+
"chat-composer",
|
|
36
|
+
"chat-list",
|
|
37
|
+
"chat-context",
|
|
38
|
+
"transcribe-drop",
|
|
39
|
+
"transcript-view",
|
|
40
|
+
"transcribe-queue",
|
|
41
|
+
"transcript-exports",
|
|
42
|
+
"mask-studio",
|
|
43
|
+
"mask-tools",
|
|
44
|
+
"mask-verbs",
|
|
45
|
+
"mask-rack",
|
|
46
|
+
"frame-view",
|
|
47
|
+
"camera-feed",
|
|
48
|
+
"memory-inspector",
|
|
49
|
+
];
|
|
50
|
+
/** The element a `for` attribute names, once it is upgraded. */
|
|
51
|
+
async function target(el, key) {
|
|
52
|
+
const id = el.getAttribute("for");
|
|
53
|
+
const t = id ? el.ownerDocument.getElementById(id) : null;
|
|
54
|
+
if (!t)
|
|
55
|
+
return null;
|
|
56
|
+
if (t.localName.includes("-"))
|
|
57
|
+
await customElements.whenDefined(t.localName);
|
|
58
|
+
return (t[key] ?? null);
|
|
59
|
+
}
|
|
60
|
+
function shell(B) {
|
|
61
|
+
return class extends B {
|
|
62
|
+
mounted = null;
|
|
63
|
+
connectedCallback() {
|
|
64
|
+
// .hb-view: display contents, so a layout region of hackbuild-ui places the view's parts
|
|
65
|
+
this.classList.add("hb-view");
|
|
66
|
+
void this.mount();
|
|
67
|
+
}
|
|
68
|
+
disconnectedCallback() {
|
|
69
|
+
this.mounted?.dispose();
|
|
70
|
+
this.mounted = null;
|
|
71
|
+
}
|
|
72
|
+
async mount() { }
|
|
73
|
+
emit(type, detail) {
|
|
74
|
+
this.dispatchEvent(new CustomEvent(type, { detail, bubbles: true }));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function classes(B) {
|
|
79
|
+
const S = shell(B);
|
|
80
|
+
class ModelSelectEl extends S {
|
|
81
|
+
#pick = null;
|
|
82
|
+
#env;
|
|
83
|
+
#loader;
|
|
84
|
+
#records;
|
|
85
|
+
get pick() {
|
|
86
|
+
if (!this.#pick) {
|
|
87
|
+
const job = this.getAttribute("job");
|
|
88
|
+
this.#pick = useModelPick(isJob(job) ? job : "chat", { ...(this.#env ? { env: this.#env } : {}), ...(this.#loader ? { loader: this.#loader } : {}), ...(this.#records ? { records: this.#records } : {}), ...(this.getAttribute("chosen") ? { chosen: this.getAttribute("chosen") } : {}) });
|
|
89
|
+
this.watch(this.#pick);
|
|
90
|
+
}
|
|
91
|
+
return this.#pick;
|
|
92
|
+
}
|
|
93
|
+
set pick(p) {
|
|
94
|
+
this.#pick = p;
|
|
95
|
+
this.watch(p);
|
|
96
|
+
if (this.isConnected)
|
|
97
|
+
void this.remount();
|
|
98
|
+
}
|
|
99
|
+
#off = null;
|
|
100
|
+
/** choose on a new choice; loaded and failed once per load, when a row leaves loading. */
|
|
101
|
+
watch(p) {
|
|
102
|
+
this.#off?.();
|
|
103
|
+
let chosen = p.snapshot().chosen;
|
|
104
|
+
const was = new Map(p.snapshot().rows.map((r) => [r.id, r.state]));
|
|
105
|
+
this.#off = p.subscribe((s) => {
|
|
106
|
+
if (s.chosen !== chosen)
|
|
107
|
+
this.emit("choose", { id: s.chosen });
|
|
108
|
+
chosen = s.chosen;
|
|
109
|
+
for (const r of s.rows) {
|
|
110
|
+
const before = was.get(r.id);
|
|
111
|
+
if (before === "loading" && r.state === "loaded")
|
|
112
|
+
this.emit("loaded", { id: r.id, result: p.result(r.id) });
|
|
113
|
+
if (before === "loading" && r.state === "error")
|
|
114
|
+
this.emit("failed", { id: r.id, error: p.error(r.id) });
|
|
115
|
+
was.set(r.id, r.state);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
get env() {
|
|
120
|
+
return this.#env;
|
|
121
|
+
}
|
|
122
|
+
set env(v) {
|
|
123
|
+
this.#env = v;
|
|
124
|
+
this.#pick?.update({ env: v });
|
|
125
|
+
}
|
|
126
|
+
get loader() {
|
|
127
|
+
return this.#loader;
|
|
128
|
+
}
|
|
129
|
+
set loader(v) {
|
|
130
|
+
this.#loader = v;
|
|
131
|
+
if (v)
|
|
132
|
+
this.#pick?.update({ loader: v });
|
|
133
|
+
}
|
|
134
|
+
get records() {
|
|
135
|
+
return this.#records;
|
|
136
|
+
}
|
|
137
|
+
set records(v) {
|
|
138
|
+
this.#records = v;
|
|
139
|
+
if (v)
|
|
140
|
+
this.#pick?.update({ records: v });
|
|
141
|
+
}
|
|
142
|
+
async remount() {
|
|
143
|
+
this.mounted?.dispose();
|
|
144
|
+
await this.mount();
|
|
145
|
+
}
|
|
146
|
+
async mount() {
|
|
147
|
+
this.mounted = mountModelSelect(this, this.pick, { variant: this.getAttribute("variant") === "chip" ? "chip" : "line", go: this.getAttribute("go") !== "false" });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
class ModelJobsEl extends S {
|
|
151
|
+
#jobs = null;
|
|
152
|
+
#opts = { presets: [] };
|
|
153
|
+
/** One pick per job in the jobs attribute, built on first use with the properties set so far. */
|
|
154
|
+
get jobs() {
|
|
155
|
+
if (!this.#jobs) {
|
|
156
|
+
const names = (this.getAttribute("jobs") ?? "chat").split(",").map((s) => s.trim()).filter(isJob);
|
|
157
|
+
const required = new Set((this.getAttribute("required") ?? "").split(",").map((s) => s.trim()));
|
|
158
|
+
const { presets, ...shared } = this.#opts;
|
|
159
|
+
this.#jobs = useJobsPick(names.map((job) => ({ job, required: required.has(job) })), presets, shared);
|
|
160
|
+
}
|
|
161
|
+
return this.#jobs;
|
|
162
|
+
}
|
|
163
|
+
set env(v) {
|
|
164
|
+
this.#opts.env = v;
|
|
165
|
+
this.#jobs?.update({ env: v });
|
|
166
|
+
}
|
|
167
|
+
set loader(v) {
|
|
168
|
+
this.#opts.loader = v;
|
|
169
|
+
this.#jobs?.update({ loader: v });
|
|
170
|
+
}
|
|
171
|
+
set records(v) {
|
|
172
|
+
this.#opts.records = v;
|
|
173
|
+
this.#jobs?.update({ records: v });
|
|
174
|
+
}
|
|
175
|
+
set presets(v) {
|
|
176
|
+
this.#opts.presets = v;
|
|
177
|
+
this.#jobs?.setPresets(v);
|
|
178
|
+
}
|
|
179
|
+
async mount() {
|
|
180
|
+
this.mounted = mountModelJobs(this, this.jobs, { go: this.getAttribute("go") !== "false" });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
class ChatPaneEl extends S {
|
|
184
|
+
#thread = null;
|
|
185
|
+
#list = null;
|
|
186
|
+
/** The chats this pane shows, the open one in the pane; a chat-list element switches between them. */
|
|
187
|
+
get list() {
|
|
188
|
+
return (this.#list ??= chatList());
|
|
189
|
+
}
|
|
190
|
+
set list(l) {
|
|
191
|
+
this.#list = l;
|
|
192
|
+
this.thread = l.thread;
|
|
193
|
+
}
|
|
194
|
+
get thread() {
|
|
195
|
+
return (this.#thread ??= this.list.thread);
|
|
196
|
+
}
|
|
197
|
+
set thread(t) {
|
|
198
|
+
this.#thread = t;
|
|
199
|
+
if (this.isConnected) {
|
|
200
|
+
this.mounted?.dispose();
|
|
201
|
+
void this.mount();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
set engine(e) {
|
|
205
|
+
if (this.#list)
|
|
206
|
+
this.#list.setEngine(e);
|
|
207
|
+
else
|
|
208
|
+
this.thread.setEngine(e);
|
|
209
|
+
}
|
|
210
|
+
async mount() {
|
|
211
|
+
const name = this.getAttribute("name");
|
|
212
|
+
const en = this.getAttribute("empty-name");
|
|
213
|
+
const note = this.getAttribute("empty-note");
|
|
214
|
+
this.mounted = mountChatPane(this, this.thread, { ...(name ? { name } : {}), ...(en ? { emptyName: en } : {}), ...(note ? { emptyNote: note } : {}) });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
class ChatListEl extends S {
|
|
218
|
+
async mount() {
|
|
219
|
+
const l = await target(this, "list");
|
|
220
|
+
if (l)
|
|
221
|
+
this.mounted = mountChatList(this, l, this.getAttribute("label") ? { label: this.getAttribute("label") } : {});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
class ChatContextEl extends S {
|
|
225
|
+
async mount() {
|
|
226
|
+
const t = await target(this, "thread");
|
|
227
|
+
const budget = () => Number(this.getAttribute("budget") ?? 4096);
|
|
228
|
+
if (t)
|
|
229
|
+
this.mounted = mountContextMeter(this, t, { budget, system: () => this.system ?? "" });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
class ComposerEl extends S {
|
|
233
|
+
async mount() {
|
|
234
|
+
const t = await target(this, "thread");
|
|
235
|
+
const ph = this.getAttribute("placeholder");
|
|
236
|
+
if (t)
|
|
237
|
+
this.mounted = mountComposer(this, t, ph ? { placeholder: ph } : {});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const stub = async () => {
|
|
241
|
+
throw new Error("no speech model loaded. pick one and load it.");
|
|
242
|
+
};
|
|
243
|
+
class TranscribeDropEl extends S {
|
|
244
|
+
#queue = null;
|
|
245
|
+
get queue() {
|
|
246
|
+
return (this.#queue ??= transcribeQueue({ run: stub }));
|
|
247
|
+
}
|
|
248
|
+
set transcriber(t) {
|
|
249
|
+
this.queue.setTranscriber(t);
|
|
250
|
+
}
|
|
251
|
+
pick() {
|
|
252
|
+
this.mounted?.pick();
|
|
253
|
+
}
|
|
254
|
+
async mount() {
|
|
255
|
+
const sample = this.getAttribute("sample-label");
|
|
256
|
+
const title = this.getAttribute("title-text");
|
|
257
|
+
this.mounted = mountTranscribeDrop(this, this.queue, {
|
|
258
|
+
...(this.getAttribute("accept") ? { accept: this.getAttribute("accept") } : {}),
|
|
259
|
+
...(title ? { title } : {}),
|
|
260
|
+
...(sample ? { sampleLabel: sample, onSample: () => this.emit("sample") } : {}),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const forQueue = (mount) => class extends S {
|
|
265
|
+
async mount() {
|
|
266
|
+
const q = await target(this, "queue");
|
|
267
|
+
if (q)
|
|
268
|
+
this.mounted = mount(this, q);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
class MaskStudioEl extends S {
|
|
272
|
+
#studio = null;
|
|
273
|
+
#models = {};
|
|
274
|
+
get studio() {
|
|
275
|
+
if (!this.#studio) {
|
|
276
|
+
const sample = this.getAttribute("sample-label");
|
|
277
|
+
this.#studio = mountMaskStudio(this, { models: this.#models, ...(sample ? { sampleLabel: sample, onSample: () => this.emit("sample") } : {}) });
|
|
278
|
+
}
|
|
279
|
+
return this.#studio;
|
|
280
|
+
}
|
|
281
|
+
set models(m) {
|
|
282
|
+
this.#models = m;
|
|
283
|
+
this.#studio?.setModels(m);
|
|
284
|
+
}
|
|
285
|
+
async mount() {
|
|
286
|
+
this.mounted = this.studio;
|
|
287
|
+
}
|
|
288
|
+
disconnectedCallback() {
|
|
289
|
+
super.disconnectedCallback();
|
|
290
|
+
this.#studio = null;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const forStudio = (mount) => class extends S {
|
|
294
|
+
async mount() {
|
|
295
|
+
const s = await target(this, "studio");
|
|
296
|
+
if (s)
|
|
297
|
+
this.mounted = mount(this, s, this);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
class FrameViewEl extends S {
|
|
301
|
+
#view = null;
|
|
302
|
+
get view() {
|
|
303
|
+
return (this.#view ??= mountFrameView(this, { mirror: this.hasAttribute("mirror"), ...(this.getAttribute("empty") ? { empty: this.getAttribute("empty") } : {}) }));
|
|
304
|
+
}
|
|
305
|
+
async mount() {
|
|
306
|
+
this.mounted = this.view;
|
|
307
|
+
}
|
|
308
|
+
disconnectedCallback() {
|
|
309
|
+
super.disconnectedCallback();
|
|
310
|
+
this.#view = null;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
class CameraFeedEl extends S {
|
|
314
|
+
#feed = null;
|
|
315
|
+
get feed() {
|
|
316
|
+
return (this.#feed ??= mountCameraFeed(this, { fps: Number(this.getAttribute("fps") ?? 4), tile: !this.hasAttribute("for"), onFrame: (v) => this.emit("frame", { video: v }) }));
|
|
317
|
+
}
|
|
318
|
+
async mount() {
|
|
319
|
+
const feed = this.feed;
|
|
320
|
+
this.mounted = feed;
|
|
321
|
+
// with for, the camera shows in that frame view
|
|
322
|
+
const view = await target(this, "view");
|
|
323
|
+
if (view)
|
|
324
|
+
feed.subscribe((s) => void view.setSource(s.live ? feed.video : null).catch(() => undefined));
|
|
325
|
+
}
|
|
326
|
+
disconnectedCallback() {
|
|
327
|
+
super.disconnectedCallback();
|
|
328
|
+
this.#feed = null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
class MemoryInspectorEl extends S {
|
|
332
|
+
#recall = null;
|
|
333
|
+
set recall(r) {
|
|
334
|
+
this.#recall = r;
|
|
335
|
+
this.mounted?.set(r);
|
|
336
|
+
}
|
|
337
|
+
async mount() {
|
|
338
|
+
this.mounted = mountMemoryInspector(this, this.#recall);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
"model-select": ModelSelectEl,
|
|
343
|
+
"model-jobs": ModelJobsEl,
|
|
344
|
+
"chat-pane": ChatPaneEl,
|
|
345
|
+
"chat-composer": ComposerEl,
|
|
346
|
+
"chat-list": ChatListEl,
|
|
347
|
+
"chat-context": ChatContextEl,
|
|
348
|
+
"transcribe-drop": TranscribeDropEl,
|
|
349
|
+
"transcript-view": forQueue((h, q) => mountTranscriptView(h, q)),
|
|
350
|
+
"transcribe-queue": forQueue(mountTranscribeQueue),
|
|
351
|
+
"transcript-exports": forQueue((h, q) => mountTranscriptExports(h, q, { go: h.hasAttribute("go") })),
|
|
352
|
+
"mask-studio": MaskStudioEl,
|
|
353
|
+
"mask-tools": forStudio(mountMaskTools),
|
|
354
|
+
"mask-verbs": forStudio(mountMaskVerbs),
|
|
355
|
+
"mask-rack": forStudio((h, s, el) => mountMaskRack(h, s, el.getAttribute("part") ?? "found")),
|
|
356
|
+
"frame-view": FrameViewEl,
|
|
357
|
+
"camera-feed": CameraFeedEl,
|
|
358
|
+
"memory-inspector": MemoryInspectorEl,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Register the elements, bare (`<model-select>`) or under a prefix
|
|
363
|
+
* (`define("hb")` gives `<hb-model-select>`). Names already defined are
|
|
364
|
+
* left alone. Returns the tag names.
|
|
365
|
+
*/
|
|
366
|
+
export function define(prefix = "", registry, Base) {
|
|
367
|
+
const reg = registry ?? globalThis.customElements;
|
|
368
|
+
const B = Base ?? globalThis.HTMLElement;
|
|
369
|
+
if (!reg || !B)
|
|
370
|
+
throw new Error("no custom elements in this environment");
|
|
371
|
+
const make = classes(B);
|
|
372
|
+
return ELEMENT_NAMES.map((n) => {
|
|
373
|
+
const tag = prefix ? `${prefix}-${n}` : n;
|
|
374
|
+
if (!reg.get(tag))
|
|
375
|
+
reg.define(tag, make[n]);
|
|
376
|
+
return tag;
|
|
377
|
+
});
|
|
378
|
+
}
|
package/dist/frame.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What FrameView draws over a frame, as data: boxes from a detector,
|
|
3
|
+
* landmark points from a face, hand or pose model, and a caption from a
|
|
4
|
+
* vision language model. Coordinates are in source pixels. Pure, so the
|
|
5
|
+
* mapping onto a tile that crops (object-fit cover) is tested in Node.
|
|
6
|
+
*/
|
|
7
|
+
export interface FrameBox {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
w: number;
|
|
11
|
+
h: number;
|
|
12
|
+
label?: string;
|
|
13
|
+
/** 0 to 1. */
|
|
14
|
+
score?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface FrameLandmarks {
|
|
17
|
+
points: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
}[];
|
|
21
|
+
/** Index pairs to join with lines. */
|
|
22
|
+
edges?: [number, number][];
|
|
23
|
+
label?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface FrameResults {
|
|
26
|
+
boxes?: FrameBox[];
|
|
27
|
+
landmarks?: FrameLandmarks[];
|
|
28
|
+
caption?: string;
|
|
29
|
+
/** Short words for a tile corner: "3 found", "12 ms". */
|
|
30
|
+
tag?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Source to view pixels for object-fit cover (crop) or contain (bars). */
|
|
33
|
+
export declare function fitMap(src: {
|
|
34
|
+
w: number;
|
|
35
|
+
h: number;
|
|
36
|
+
}, view: {
|
|
37
|
+
w: number;
|
|
38
|
+
h: number;
|
|
39
|
+
}, fit?: "cover" | "contain"): {
|
|
40
|
+
scale: number;
|
|
41
|
+
dx: number;
|
|
42
|
+
dy: number;
|
|
43
|
+
};
|
|
44
|
+
/** A box in view pixels; mirrored for a selfie view. */
|
|
45
|
+
export declare function toView(b: FrameBox, m: {
|
|
46
|
+
scale: number;
|
|
47
|
+
dx: number;
|
|
48
|
+
dy: number;
|
|
49
|
+
}, viewW: number, mirror?: boolean): FrameBox;
|
|
50
|
+
/** "cup 94%", or the label alone, or the score alone. */
|
|
51
|
+
export declare function boxWords(b: FrameBox): string;
|
|
52
|
+
/** The corner tag: the caller's words, else how many boxes and landmark sets were found. */
|
|
53
|
+
export declare function frameTag(r: FrameResults): string;
|
|
54
|
+
/** One colour per label, stable across frames, from a palette. */
|
|
55
|
+
export declare function labelColour(label: string | undefined, palette: readonly string[]): string;
|
package/dist/frame.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What FrameView draws over a frame, as data: boxes from a detector,
|
|
3
|
+
* landmark points from a face, hand or pose model, and a caption from a
|
|
4
|
+
* vision language model. Coordinates are in source pixels. Pure, so the
|
|
5
|
+
* mapping onto a tile that crops (object-fit cover) is tested in Node.
|
|
6
|
+
*/
|
|
7
|
+
/** Source to view pixels for object-fit cover (crop) or contain (bars). */
|
|
8
|
+
export function fitMap(src, view, fit = "cover") {
|
|
9
|
+
if (src.w <= 0 || src.h <= 0)
|
|
10
|
+
return { scale: 1, dx: 0, dy: 0 };
|
|
11
|
+
const sx = view.w / src.w;
|
|
12
|
+
const sy = view.h / src.h;
|
|
13
|
+
const scale = fit === "cover" ? Math.max(sx, sy) : Math.min(sx, sy);
|
|
14
|
+
return { scale, dx: (view.w - src.w * scale) / 2, dy: (view.h - src.h * scale) / 2 };
|
|
15
|
+
}
|
|
16
|
+
/** A box in view pixels; mirrored for a selfie view. */
|
|
17
|
+
export function toView(b, m, viewW, mirror = false) {
|
|
18
|
+
const x = b.x * m.scale + m.dx;
|
|
19
|
+
const w = b.w * m.scale;
|
|
20
|
+
return { ...b, x: mirror ? viewW - x - w : x, y: b.y * m.scale + m.dy, w, h: b.h * m.scale };
|
|
21
|
+
}
|
|
22
|
+
/** "cup 94%", or the label alone, or the score alone. */
|
|
23
|
+
export function boxWords(b) {
|
|
24
|
+
const pct = b.score !== undefined ? `${Math.round(Math.min(1, Math.max(0, b.score)) * 100)}%` : "";
|
|
25
|
+
return [b.label ?? "", pct].filter(Boolean).join(" ");
|
|
26
|
+
}
|
|
27
|
+
/** The corner tag: the caller's words, else how many boxes and landmark sets were found. */
|
|
28
|
+
export function frameTag(r) {
|
|
29
|
+
if (r.tag)
|
|
30
|
+
return r.tag;
|
|
31
|
+
const n = (r.boxes?.length ?? 0) + (r.landmarks?.length ?? 0);
|
|
32
|
+
return n ? `${n} found` : "";
|
|
33
|
+
}
|
|
34
|
+
/** One colour per label, stable across frames, from a palette. */
|
|
35
|
+
export function labelColour(label, palette) {
|
|
36
|
+
let h = 0;
|
|
37
|
+
for (const c of label ?? "")
|
|
38
|
+
h = (h * 31 + c.charCodeAt(0)) >>> 0;
|
|
39
|
+
return palette[h % palette.length];
|
|
40
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { JOBS, JOB_NAMES, ALL_RECORDS, FACE_API_BASE, jobRecords, isJob, type Job, type JobDef } from "./jobs.js";
|
|
2
|
+
export { rowOf, groupOf, backendOf, sizeWords, detailOf, optionsOf, isNoDownload, isUncensored, type RowContext } from "./rows.js";
|
|
3
|
+
export { useModelPick, useJobsPick, weightsLoader, weightsRemover, weightKeys, defaultPick, ownRecord, type ModelPick, type PickOptions, type PickSnapshot, type Loader, type LoadContext, type JobsPick, type JobLine, type PickPreset, } from "./pick.js";
|
|
4
|
+
export { chatThread, chatList, contextSegments, NO_ENGINE, type ChatList, type ChatListItem, type ChatListSnapshot, type ChatThread, type ThreadOptions, type ThreadSnapshot, type Turn, type MemoryUsed } from "./chat.js";
|
|
5
|
+
export { transcribeQueue, type TranscribeQueue, type Transcriber, type RunResult, type RunContext, type Channel, type ExportKind, type QueueSnapshot } from "./transcribe.js";
|
|
6
|
+
export { fitMap, toView, boxWords, frameTag, labelColour, type FrameBox, type FrameLandmarks, type FrameResults } from "./frame.js";
|
|
7
|
+
export { traceRows, inspectorHtml, type TraceRow, type RecallLike } from "./memory.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The node safe part of @hackbuild/ai-views: jobs, rows, and the state
|
|
2
|
+
// behind every view. The DOM mounts and custom elements are in
|
|
3
|
+
// "@hackbuild/ai-views/elements"; the Vue components in "@hackbuild/ai-views/vue".
|
|
4
|
+
export { JOBS, JOB_NAMES, ALL_RECORDS, FACE_API_BASE, jobRecords, isJob } from "./jobs.js";
|
|
5
|
+
export { rowOf, groupOf, backendOf, sizeWords, detailOf, optionsOf, isNoDownload, isUncensored } from "./rows.js";
|
|
6
|
+
export { useModelPick, useJobsPick, weightsLoader, weightsRemover, weightKeys, defaultPick, ownRecord, } from "./pick.js";
|
|
7
|
+
export { chatThread, chatList, contextSegments, NO_ENGINE } from "./chat.js";
|
|
8
|
+
export { transcribeQueue } from "./transcribe.js";
|
|
9
|
+
export { fitMap, toView, boxWords, frameTag, labelColour } from "./frame.js";
|
|
10
|
+
export { traceRows, inspectorHtml } from "./memory.js";
|
package/dist/jobs.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jobs: what a person wants a model for, and the records that can do it.
|
|
3
|
+
* A tool asks for a job ("chat", "transcribe"), never for a provider. The
|
|
4
|
+
* records come from the packages that run them; a record listed in more
|
|
5
|
+
* than one place counts once, the running package's copy first.
|
|
6
|
+
*/
|
|
7
|
+
import { type ModelRecord } from "@hackbuild/models";
|
|
8
|
+
/** face-api weights (MIT) as an earlier face swap tool loaded them, from the package CDN. */
|
|
9
|
+
export declare const FACE_API_BASE = "https://cdn.jsdelivr.net/npm/@vladmandic/face-api@1.7.12/model/";
|
|
10
|
+
export type Job = "chat" | "transcribe" | "vision" | "detect" | "masks" | "image" | "voice" | "depth" | "embed" | "faceswap" | "landmarks";
|
|
11
|
+
export interface JobDef {
|
|
12
|
+
/** The word on a job line: "brain", "ears". */
|
|
13
|
+
label: string;
|
|
14
|
+
/** The sheet's title: "pick a chat model". */
|
|
15
|
+
title: string;
|
|
16
|
+
/** What the gate or the empty line says with nothing picked. */
|
|
17
|
+
empty: string;
|
|
18
|
+
provides: (caps: readonly string[]) => boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const JOBS: Readonly<Record<Job, JobDef>>;
|
|
21
|
+
export declare const JOB_NAMES: Job[];
|
|
22
|
+
/** Every record the views know, the running package's copy of a duplicate first. */
|
|
23
|
+
export declare const ALL_RECORDS: readonly ModelRecord[];
|
|
24
|
+
/** The records that do a job, catalogue order kept. */
|
|
25
|
+
export declare function jobRecords(job: Job, records?: readonly ModelRecord[]): ModelRecord[];
|
|
26
|
+
export declare function isJob(s: string | null | undefined): s is Job;
|
package/dist/jobs.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jobs: what a person wants a model for, and the records that can do it.
|
|
3
|
+
* A tool asks for a job ("chat", "transcribe"), never for a provider. The
|
|
4
|
+
* records come from the packages that run them; a record listed in more
|
|
5
|
+
* than one place counts once, the running package's copy first.
|
|
6
|
+
*/
|
|
7
|
+
import { CATALOG } from "@hackbuild/models";
|
|
8
|
+
import { EMBED_RECORDS } from "@hackbuild/embed";
|
|
9
|
+
import { IMAGEGEN_PICKER_RECORDS, IMAGEGEN_RECORDS } from "@hackbuild/imagegen";
|
|
10
|
+
import { SPEAK_RECORDS } from "@hackbuild/speak";
|
|
11
|
+
import { TRANSCRIBE_RECORDS } from "@hackbuild/transcribe";
|
|
12
|
+
import { PICKER_RECORDS, VISION_RECORDS, faceApiRecord } from "@hackbuild/vision";
|
|
13
|
+
/** face-api weights (MIT) as an earlier face swap tool loaded them, from the package CDN. */
|
|
14
|
+
export const FACE_API_BASE = "https://cdn.jsdelivr.net/npm/@vladmandic/face-api@1.7.12/model/";
|
|
15
|
+
const has = (...want) => (caps) => caps.some((c) => want.includes(c));
|
|
16
|
+
export const JOBS = {
|
|
17
|
+
chat: { label: "brain", title: "pick a chat model", empty: "no model", provides: has("chat") },
|
|
18
|
+
transcribe: { label: "ears", title: "pick a speech model", empty: "no speech model", provides: has("transcribe") },
|
|
19
|
+
vision: { label: "eyes", title: "pick a vision model", empty: "no vision model", provides: has("vision.ask", "vision.caption") },
|
|
20
|
+
detect: { label: "detector", title: "pick a detector", empty: "no detector", provides: has("detect") },
|
|
21
|
+
masks: { label: "masks", title: "pick a mask model", empty: "no mask model", provides: has("segment", "segment.everything") },
|
|
22
|
+
image: { label: "image", title: "pick an image model", empty: "no image model", provides: has("imagegen") },
|
|
23
|
+
voice: { label: "voice", title: "pick a voice", empty: "no voice", provides: has("speak") },
|
|
24
|
+
depth: { label: "depth", title: "pick a depth model", empty: "no depth model", provides: has("depth") },
|
|
25
|
+
embed: { label: "memory", title: "pick an embedder", empty: "no embedder", provides: has("embed") },
|
|
26
|
+
faceswap: { label: "face swap", title: "pick the face swap models", empty: "no face model", provides: has("face.detect", "face.embed", "face.swap") },
|
|
27
|
+
landmarks: { label: "landmarks", title: "pick a landmark model", empty: "no landmarks", provides: has("landmarks.face", "landmarks.hand", "landmarks.pose", "landmarks.gesture") },
|
|
28
|
+
};
|
|
29
|
+
export const JOB_NAMES = Object.keys(JOBS);
|
|
30
|
+
/** Every record the views know, the running package's copy of a duplicate first. */
|
|
31
|
+
export const ALL_RECORDS = (() => {
|
|
32
|
+
const seen = new Set();
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const r of [...TRANSCRIBE_RECORDS, ...VISION_RECORDS, ...PICKER_RECORDS, ...SPEAK_RECORDS, ...IMAGEGEN_RECORDS, ...IMAGEGEN_PICKER_RECORDS, ...EMBED_RECORDS, faceApiRecord(FACE_API_BASE), ...CATALOG]) {
|
|
35
|
+
if (seen.has(r.id))
|
|
36
|
+
continue;
|
|
37
|
+
seen.add(r.id);
|
|
38
|
+
out.push(r);
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
})();
|
|
42
|
+
/** The records that do a job, catalogue order kept. */
|
|
43
|
+
export function jobRecords(job, records = ALL_RECORDS) {
|
|
44
|
+
const def = JOBS[job];
|
|
45
|
+
return records.filter((r) => def.provides(r.provides));
|
|
46
|
+
}
|
|
47
|
+
export function isJob(s) {
|
|
48
|
+
return !!s && s in JOBS;
|
|
49
|
+
}
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The memory inspector folded in from ai-elements: what a recall found, one
|
|
3
|
+
* row per fused candidate, best first, with the ones handed to the model
|
|
4
|
+
* marked. Rows are built here; the markup is hackbuild-ui's table.
|
|
5
|
+
*/
|
|
6
|
+
import type { Recall } from "@hackbuild/memory";
|
|
7
|
+
import { type Mounted } from "./dom.js";
|
|
8
|
+
export interface TraceRow {
|
|
9
|
+
rank: number;
|
|
10
|
+
id: number;
|
|
11
|
+
kind: string;
|
|
12
|
+
text: string;
|
|
13
|
+
bm25: string;
|
|
14
|
+
cos: string;
|
|
15
|
+
rrf: string;
|
|
16
|
+
score: string;
|
|
17
|
+
/** Inside the hits handed to the model. */
|
|
18
|
+
used: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function traceRows(r: Pick<Recall, "trace" | "hits">, maxText?: number): TraceRow[];
|
|
21
|
+
export type RecallLike = Pick<Recall, "trace" | "hits" | "query" | "mode">;
|
|
22
|
+
export declare function inspectorHtml(rec: RecallLike | null): string;
|
|
23
|
+
export interface MemoryInspector extends Mounted {
|
|
24
|
+
set(rec: RecallLike | null): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function mountMemoryInspector(host: HTMLElement, rec?: RecallLike | null): MemoryInspector;
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The memory inspector folded in from ai-elements: what a recall found, one
|
|
3
|
+
* row per fused candidate, best first, with the ones handed to the model
|
|
4
|
+
* marked. Rows are built here; the markup is hackbuild-ui's table.
|
|
5
|
+
*/
|
|
6
|
+
import { esc } from "./dom.js";
|
|
7
|
+
const n3 = (x) => (Number.isFinite(x) ? x.toFixed(3) : "none");
|
|
8
|
+
// the core ranks from 0 (best) and uses -1 for absent; shown 1 based
|
|
9
|
+
const rank = (r) => (r >= 0 ? `#${r + 1}` : "none");
|
|
10
|
+
export function traceRows(r, maxText = 80) {
|
|
11
|
+
const used = new Set(r.hits.map((h) => h.item.id));
|
|
12
|
+
return r.trace.map((t, i) => ({
|
|
13
|
+
rank: i + 1,
|
|
14
|
+
id: t.id,
|
|
15
|
+
kind: t.kind,
|
|
16
|
+
text: t.text.length > maxText ? `${t.text.slice(0, maxText - 3)}...` : t.text,
|
|
17
|
+
bm25: `${rank(t.bm25Rank)} ${n3(t.bm25)}`,
|
|
18
|
+
cos: `${rank(t.vecRank)} ${n3(t.cos)}`,
|
|
19
|
+
rrf: n3(t.rrf),
|
|
20
|
+
score: n3(t.score),
|
|
21
|
+
used: used.has(t.id),
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
export function inspectorHtml(rec) {
|
|
25
|
+
if (!rec)
|
|
26
|
+
return `<p class="hb-lay-empty-note">no recall yet. ask something to see what memory finds.</p>`;
|
|
27
|
+
const rows = traceRows(rec);
|
|
28
|
+
return (`<p class="hb-lay-empty-note" role="status">"${esc(rec.query)}", ${esc(rec.mode)} recall, ${rows.length} found, ${rows.filter((x) => x.used).length} used.</p>` +
|
|
29
|
+
`<div class="hb-scroll-x" data-ux="detail"><table class="hb-table"><thead><tr><th class="num">#</th><th>kind</th><th>text</th><th>bm25</th><th>cosine</th><th class="num">rrf</th><th class="num">score</th></tr></thead><tbody>` +
|
|
30
|
+
rows.map((x) => `<tr class="${x.used ? "is-mark" : ""}" data-used="${x.used}"><td class="num">${x.rank}</td><td>${esc(x.kind)}</td><td>${esc(x.text)}</td><td>${esc(x.bm25)}</td><td>${esc(x.cos)}</td><td class="num">${x.rrf}</td><td class="num">${x.score}</td></tr>`).join("") +
|
|
31
|
+
`</tbody></table></div>`);
|
|
32
|
+
}
|
|
33
|
+
export function mountMemoryInspector(host, rec = null) {
|
|
34
|
+
host.innerHTML = inspectorHtml(rec);
|
|
35
|
+
return { set: (r) => void (host.innerHTML = inspectorHtml(r)), dispose() { } };
|
|
36
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatPane and Composer in the DOM, after the earlier chat tools: the
|
|
3
|
+
* thread as hackbuild-ui messages, the reasoning in a fold that is open
|
|
4
|
+
* while it streams, the memory a reply used in a fold under it, copy and
|
|
5
|
+
* redo on the last reply only, and a composer whose send is the one pink
|
|
6
|
+
* action and turns into stop while a reply streams.
|
|
7
|
+
*/
|
|
8
|
+
import { type ChatList, type ChatThread, type Turn } from "./chat.js";
|
|
9
|
+
import { type Mounted } from "./dom.js";
|
|
10
|
+
export interface ChatPaneOptions {
|
|
11
|
+
/** The reply's name in its head. */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** The empty state, in Permanent Marker. */
|
|
14
|
+
emptyName?: string;
|
|
15
|
+
emptyNote?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function turnHtml(t: Turn, o: {
|
|
18
|
+
name: string;
|
|
19
|
+
last: boolean;
|
|
20
|
+
busy: boolean;
|
|
21
|
+
}): string;
|
|
22
|
+
/** The thread over a host, with the empty state inside it. */
|
|
23
|
+
export declare function mountChatPane(host: HTMLElement, thread: ChatThread, o?: ChatPaneOptions): Mounted;
|
|
24
|
+
export interface ComposerOptions {
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
label?: string;
|
|
27
|
+
}
|
|
28
|
+
/** The composer: Enter sends (Shift Enter adds a line, Escape stops), send is the one pink, stop replaces it while a reply streams. */
|
|
29
|
+
export declare function mountComposer(host: HTMLElement, thread: ChatThread, o?: ComposerOptions): Mounted;
|
|
30
|
+
/** The chat list rail (hackbuild-ui HbConversationList markup): new, open, rename, delete with a second press. */
|
|
31
|
+
export declare function mountChatList(host: HTMLElement, list: ChatList, o?: {
|
|
32
|
+
label?: string;
|
|
33
|
+
}): Mounted;
|
|
34
|
+
/** The context meter (hackbuild-ui `.hb-ctxmeter`): what the next request carries against the model's context. */
|
|
35
|
+
export declare function mountContextMeter(host: HTMLElement, thread: ChatThread, o?: {
|
|
36
|
+
budget?: number | (() => number);
|
|
37
|
+
system?: string | (() => string);
|
|
38
|
+
}): Mounted;
|