@hackbuild/ai-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 +241 -2
- package/dist/chat.d.ts +107 -0
- package/dist/chat.js +243 -0
- package/dist/dom.d.ts +38 -0
- package/dist/dom.js +67 -0
- package/dist/elements.d.ts +48 -0
- package/dist/elements.js +378 -0
- package/dist/frame.d.ts +57 -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 +31 -0
- package/dist/jobs.js +52 -0
- package/dist/memory.d.ts +35 -0
- package/dist/memory.js +39 -0
- package/dist/mount-chat.d.ts +41 -0
- package/dist/mount-chat.js +178 -0
- package/dist/mount-frame.d.ts +57 -0
- package/dist/mount-frame.js +239 -0
- package/dist/mount-mask.d.ts +127 -0
- package/dist/mount-mask.js +450 -0
- package/dist/mount-model.d.ts +28 -0
- package/dist/mount-model.js +122 -0
- package/dist/mount-transcribe.d.ts +51 -0
- package/dist/mount-transcribe.js +203 -0
- package/dist/pick.d.ts +149 -0
- package/dist/pick.js +260 -0
- package/dist/rows.d.ts +42 -0
- package/dist/rows.js +149 -0
- package/dist/single/elements.iife.js +9599 -0
- package/dist/single/elements.js +9573 -0
- package/dist/single/index.iife.js +6843 -0
- package/dist/single/index.js +6807 -0
- package/dist/single/vue.iife.js +11376 -0
- package/dist/single/vue.js +11359 -0
- package/dist/transcribe.d.ts +92 -0
- package/dist/transcribe.js +175 -0
- package/dist/vue.d.ts +281 -0
- package/dist/vue.js +221 -0
- package/how.ts +26 -0
- package/llms.md +1133 -0
- package/package.json +62 -4
package/dist/dom.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Small DOM helpers shared by the mount functions. Light DOM only: the page's hackbuild-ui stylesheet draws everything. */
|
|
2
|
+
export function esc(s) {
|
|
3
|
+
return s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
4
|
+
}
|
|
5
|
+
/** Shows or hides a part; inside a layout hackbuild-ui's `.hb-lay [hidden]` makes it hold on parts that set display. */
|
|
6
|
+
export function show(el, on) {
|
|
7
|
+
el.hidden = !on;
|
|
8
|
+
}
|
|
9
|
+
/** Listeners that come off together. */
|
|
10
|
+
export function listeners() {
|
|
11
|
+
const offs = [];
|
|
12
|
+
return {
|
|
13
|
+
on(el, type, fn) {
|
|
14
|
+
el.addEventListener(type, fn);
|
|
15
|
+
offs.push(() => el.removeEventListener(type, fn));
|
|
16
|
+
},
|
|
17
|
+
add(off) {
|
|
18
|
+
offs.push(off);
|
|
19
|
+
},
|
|
20
|
+
off() {
|
|
21
|
+
for (const f of offs.splice(0))
|
|
22
|
+
f();
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** The nearest ancestor that scrolls, else the element. */
|
|
27
|
+
export function scroller(el) {
|
|
28
|
+
for (let p = el; p; p = p.parentElement) {
|
|
29
|
+
const o = getComputedStyle(p).overflowY;
|
|
30
|
+
if ((o === "auto" || o === "scroll") && p.scrollHeight > p.clientHeight)
|
|
31
|
+
return p;
|
|
32
|
+
}
|
|
33
|
+
return el.closest(".hb-lay-subject") ?? el;
|
|
34
|
+
}
|
|
35
|
+
/** Saves text as a file through a link press. */
|
|
36
|
+
export function download(name, text, type = "text/plain") {
|
|
37
|
+
const blob = typeof text === "string" ? new Blob([text], { type }) : text;
|
|
38
|
+
const a = document.createElement("a");
|
|
39
|
+
a.href = URL.createObjectURL(blob);
|
|
40
|
+
a.download = name;
|
|
41
|
+
document.body.append(a);
|
|
42
|
+
a.click();
|
|
43
|
+
a.remove();
|
|
44
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 4000);
|
|
45
|
+
}
|
|
46
|
+
/** Inline SVG icons, stroked in currentColor, 16 px. */
|
|
47
|
+
const svg = (d, size = 16) => `<svg class="hb-icon is-stroke" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" aria-hidden="true">${d}</svg>`;
|
|
48
|
+
export const ICON = {
|
|
49
|
+
undo: svg('<path d="M9 14 4 9l5-5"/><path d="M4 9h10a6 6 0 0 1 0 12h-3"/>'),
|
|
50
|
+
redo: svg('<path d="m15 14 5-5-5-5"/><path d="M20 9H10a6 6 0 0 0 0 12h3"/>'),
|
|
51
|
+
zoomIn: svg('<circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3M11 8v6M8 11h6"/>'),
|
|
52
|
+
zoomOut: svg('<circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3M8 11h6"/>'),
|
|
53
|
+
fit: svg('<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>'),
|
|
54
|
+
x: svg('<path d="M6 6l12 12M18 6 6 18"/>', 13),
|
|
55
|
+
copy: svg('<rect x="9" y="9" width="11" height="11"/><path d="M5 15V4h11"/>', 14),
|
|
56
|
+
redoMsg: svg('<path d="M21 12a9 9 0 1 1-3-6.7L21 8"/><path d="M21 3v5h-5"/>', 14),
|
|
57
|
+
point: svg('<circle cx="12" cy="12" r="3"/><path d="M12 2v5M12 17v5M2 12h5M17 12h5"/>', 18),
|
|
58
|
+
wand: svg('<path d="m3 21 12-12M15 3v3M18 6h3M19 2l-1 1M14 9l1 1"/>', 18),
|
|
59
|
+
brush: svg('<path d="M18 3 9 12l3 3 9-9z"/><path d="M9 12c-3 0-5 2-5 5 0 2-1 3-2 4 4 0 8-1 9-4"/>', 18),
|
|
60
|
+
lasso: svg('<ellipse cx="12" cy="9" rx="8" ry="5"/><path d="M7 13c-1 2 0 4 2 4s2 3 0 5"/>', 18),
|
|
61
|
+
all: svg('<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/>', 18),
|
|
62
|
+
camera: svg('<path d="M3 7h4l2-3h6l2 3h4v13H3z"/><circle cx="12" cy="13" r="4"/>'),
|
|
63
|
+
menu: svg('<path d="M4 6h16M4 12h16M4 18h16"/>'),
|
|
64
|
+
plus: svg('<path d="M12 5v14M5 12h14"/>', 14),
|
|
65
|
+
pen: svg('<path d="M4 20h4L19 9l-4-4L4 16z"/>', 13),
|
|
66
|
+
trash: svg('<path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13"/>', 13),
|
|
67
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
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 type { Env } from "@hackbuild/ai-env";
|
|
15
|
+
import type { ModelRecord } from "@hackbuild/models";
|
|
16
|
+
import { type Loader, type ModelPick } from "./pick.js";
|
|
17
|
+
export { mountModelSelect, mountModelJobs, pickSheet, gateWords, type ModelSelectOptions } from "./mount-model.js";
|
|
18
|
+
export { mountChatPane, mountComposer, mountChatList, mountContextMeter, turnHtml, type ChatPaneOptions, type ComposerOptions } from "./mount-chat.js";
|
|
19
|
+
export { mountTranscribeDrop, mountTranscriptView, mountTranscribeQueue, mountTranscriptExports, transcriptHtml, type TranscribeDropOptions, type TranscribeDropHandle, type TranscriptViewOptions } from "./mount-transcribe.js";
|
|
20
|
+
export { mountMaskStudio, mountMaskTools, mountMaskVerbs, mountMaskRack, type MaskStudio, type MaskModels, type MaskStudioOptions, type FoundMask, type StudioState, type StudioTool } from "./mount-mask.js";
|
|
21
|
+
export { mountFrameView, mountCameraFeed, type FrameView, type FrameViewOptions, type CameraFeed, type CameraFeedOptions } from "./mount-frame.js";
|
|
22
|
+
export { mountMemoryInspector, type MemoryInspector } from "./memory.js";
|
|
23
|
+
type Base = new () => HTMLElement;
|
|
24
|
+
/** The tag names define() registers, before any prefix. */
|
|
25
|
+
export declare const ELEMENT_NAMES: readonly ["model-select", "model-jobs", "chat-pane", "chat-composer", "chat-list", "chat-context", "transcribe-drop", "transcript-view", "transcribe-queue", "transcript-exports", "mask-studio", "mask-tools", "mask-verbs", "mask-rack", "frame-view", "camera-feed", "memory-inspector"];
|
|
26
|
+
/** A tag name `define` registers, before any prefix. */
|
|
27
|
+
export type ElementName = (typeof ELEMENT_NAMES)[number];
|
|
28
|
+
/**
|
|
29
|
+
* The `<model-select>` element: set `pick`, `env`, `loader` or `records` on it before or after it
|
|
30
|
+
* connects.
|
|
31
|
+
*/
|
|
32
|
+
export interface ModelSelectElement extends HTMLElement {
|
|
33
|
+
pick: ModelPick;
|
|
34
|
+
env: Env | undefined;
|
|
35
|
+
loader: Loader | undefined;
|
|
36
|
+
records: readonly ModelRecord[] | undefined;
|
|
37
|
+
}
|
|
38
|
+
/** The part of a custom element registry `define` uses; `customElements` satisfies it. */
|
|
39
|
+
export interface DefineTarget {
|
|
40
|
+
get(name: string): unknown;
|
|
41
|
+
define(name: string, ctor: CustomElementConstructor): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Register the elements, bare (`<model-select>`) or under a prefix
|
|
45
|
+
* (`define("hb")` gives `<hb-model-select>`). Names already defined are
|
|
46
|
+
* left alone. Returns the tag names.
|
|
47
|
+
*/
|
|
48
|
+
export declare function define(prefix?: string, registry?: DefineTarget, Base?: Base): string[];
|
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,57 @@
|
|
|
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
|
+
/** Landmark points to draw on a frame, with the index pairs to join and a label. */
|
|
17
|
+
export interface FrameLandmarks {
|
|
18
|
+
points: {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
}[];
|
|
22
|
+
/** Index pairs to join with lines. */
|
|
23
|
+
edges?: [number, number][];
|
|
24
|
+
label?: string;
|
|
25
|
+
}
|
|
26
|
+
/** What to draw on a frame: boxes, landmarks, a caption and a corner tag. */
|
|
27
|
+
export interface FrameResults {
|
|
28
|
+
boxes?: FrameBox[];
|
|
29
|
+
landmarks?: FrameLandmarks[];
|
|
30
|
+
caption?: string;
|
|
31
|
+
/** Short words for a tile corner: "3 found", "12 ms". */
|
|
32
|
+
tag?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Source to view pixels for object-fit cover (crop) or contain (bars). */
|
|
35
|
+
export declare function fitMap(src: {
|
|
36
|
+
w: number;
|
|
37
|
+
h: number;
|
|
38
|
+
}, view: {
|
|
39
|
+
w: number;
|
|
40
|
+
h: number;
|
|
41
|
+
}, fit?: "cover" | "contain"): {
|
|
42
|
+
scale: number;
|
|
43
|
+
dx: number;
|
|
44
|
+
dy: number;
|
|
45
|
+
};
|
|
46
|
+
/** A box in view pixels; mirrored for a selfie view. */
|
|
47
|
+
export declare function toView(b: FrameBox, m: {
|
|
48
|
+
scale: number;
|
|
49
|
+
dx: number;
|
|
50
|
+
dy: number;
|
|
51
|
+
}, viewW: number, mirror?: boolean): FrameBox;
|
|
52
|
+
/** "cup 94%", or the label alone, or the score alone. */
|
|
53
|
+
export declare function boxWords(b: FrameBox): string;
|
|
54
|
+
/** The corner tag: the caller's words, else how many boxes and landmark sets were found. */
|
|
55
|
+
export declare function frameTag(r: FrameResults): string;
|
|
56
|
+
/** One colour per label, stable across frames, from a palette. */
|
|
57
|
+
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,31 @@
|
|
|
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
|
+
/** Base URL of the face-api weights (MIT) on the package CDN. */
|
|
9
|
+
export declare const FACE_API_BASE = "https://cdn.jsdelivr.net/npm/@vladmandic/face-api@1.7.12/model/";
|
|
10
|
+
/** A job a model picker serves, such as chat, transcribe, vision or masks. */
|
|
11
|
+
export type Job = "chat" | "transcribe" | "vision" | "detect" | "masks" | "image" | "voice" | "depth" | "embed" | "faceswap" | "landmarks";
|
|
12
|
+
/** A job's words (line label, sheet title, empty line) and which capabilities serve it. */
|
|
13
|
+
export interface JobDef {
|
|
14
|
+
/** The word on a job line: "brain", "ears". */
|
|
15
|
+
label: string;
|
|
16
|
+
/** The sheet's title: "pick a chat model". */
|
|
17
|
+
title: string;
|
|
18
|
+
/** What the gate or the empty line says with nothing picked. */
|
|
19
|
+
empty: string;
|
|
20
|
+
provides: (caps: readonly string[]) => boolean;
|
|
21
|
+
}
|
|
22
|
+
/** The words and capability test of every job. */
|
|
23
|
+
export declare const JOBS: Readonly<Record<Job, JobDef>>;
|
|
24
|
+
/** Every job name, in the order of `JOBS`. */
|
|
25
|
+
export declare const JOB_NAMES: Job[];
|
|
26
|
+
/** Every record the views know, the running package's copy of a duplicate first. */
|
|
27
|
+
export declare const ALL_RECORDS: readonly ModelRecord[];
|
|
28
|
+
/** The records that do a job, catalogue order kept. */
|
|
29
|
+
export declare function jobRecords(job: Job, records?: readonly ModelRecord[]): ModelRecord[];
|
|
30
|
+
/** Whether a string is a job name. */
|
|
31
|
+
export declare function isJob(s: string | null | undefined): s is Job;
|