@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/llms.md
ADDED
|
@@ -0,0 +1,1133 @@
|
|
|
1
|
+
# @hackbuild/ai-views
|
|
2
|
+
|
|
3
|
+
> Put a model picker, a chat, a transcriber, a mask studio or a camera frame on your page, drawn with the hackbuild-ui stylesheet, as custom elements or Vue components.
|
|
4
|
+
|
|
5
|
+
Generated by tools/llms.mjs from the TypeDoc JSON, the README and the examples of hackbuild-browser-ai. Human docs: https://hackbuild.github.io/hackbuild-browser-ai/docs/ai-views/
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
- Gives each job (chat, speech to text, vision, detector, masks, image, voice, depth, embed, face swap, landmarks) a model picker whose rows say whether a model fits this machine and why not.
|
|
10
|
+
- Keeps the state behind every view in node safe objects: a pick, a jobs rack, a chat thread and list, a transcribe queue.
|
|
11
|
+
- Draws the views in light DOM with the page's hackbuild-ui stylesheet and never styles locally.
|
|
12
|
+
- Ships every view as a mount function, a custom element and a Vue 3 component, all on one code path.
|
|
13
|
+
- Replaces @hackbuild/ai-elements.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @hackbuild/ai-views @virgilvox/hackbuild-ui
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
@virgilvox/hackbuild-ui is a required peer; the page also loads its stylesheet. Vue is an optional peer, needed only for the `/vue` entry.
|
|
22
|
+
|
|
23
|
+
| subpath | runtime | pin |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `.` | none; node safe state | none |
|
|
26
|
+
| `./elements` | @virgilvox/hackbuild-ui (peer) | `>=0.10.0 <0.11.0` |
|
|
27
|
+
| `./vue` | vue (optional peer) and @virgilvox/hackbuild-ui | vue `^3.4.0` |
|
|
28
|
+
|
|
29
|
+
Model runtimes are never imported here. A picker loads only through the loader you pass, such as `weightsLoader(store)` or your own that starts a runtime.
|
|
30
|
+
|
|
31
|
+
## Exports
|
|
32
|
+
|
|
33
|
+
### @hackbuild/ai-views/elements
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
interface CameraFeed extends Mounted {
|
|
37
|
+
readonly live: boolean;
|
|
38
|
+
readonly video: HTMLVideoElement;
|
|
39
|
+
dispose(): void;
|
|
40
|
+
start(): Promise<void>;
|
|
41
|
+
stop(): void;
|
|
42
|
+
subscribe(fn: (s: { error: string; live: boolean }) => void): () => void;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
A mounted camera feed: start, stop, the video element, whether it is live, and a subscription to live and error changes.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
interface CameraFeedOptions {
|
|
50
|
+
facingMode?: "user" | "environment";
|
|
51
|
+
fps?: number;
|
|
52
|
+
onFrame?: (video: HTMLVideoElement) => void | Promise<void>;
|
|
53
|
+
tile?: boolean;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Options for `mountCameraFeed`: frames per second, the frame callback, which camera, and whether to draw a tile of its own.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
interface ChatPaneOptions {
|
|
61
|
+
emptyName?: string;
|
|
62
|
+
emptyNote?: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Options for `mountChatPane`: the reply's name and the empty state's words.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
interface ComposerOptions {
|
|
71
|
+
label?: string;
|
|
72
|
+
placeholder?: string;
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Options for `mountComposer`: placeholder and accessible label.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
function define(prefix?: string, registry?: DefineTarget, Base?: Base): string[]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Register the elements, bare (`<model-select>`) or under a prefix (`define("hb")` gives `<hb-model-select>`).
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
interface DefineTarget {
|
|
86
|
+
define(name: string, ctor: CustomElementConstructor): void;
|
|
87
|
+
get(name: string): unknown;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The part of a custom element registry `define` uses; `customElements` satisfies it.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
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"]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The tag names define() registers, before any prefix.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
type ElementName = typeof ELEMENT_NAMES[number]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
A tag name `define` registers, before any prefix.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
interface FoundMask {
|
|
107
|
+
label: string;
|
|
108
|
+
mask: Uint8Array;
|
|
109
|
+
score: number;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
One object a segment model found: a mask in image pixels (0 or 255), its word and score.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
interface FrameView extends Mounted {
|
|
117
|
+
dispose(): void;
|
|
118
|
+
paint(): void;
|
|
119
|
+
setMirror(on: boolean): void;
|
|
120
|
+
setResults(r: FrameResults): void;
|
|
121
|
+
setSource(src: string | Source | null): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
A mounted frame view: set the source, the results to draw, mirroring, and paint again.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
interface FrameViewOptions {
|
|
129
|
+
empty?: string;
|
|
130
|
+
mirror?: boolean;
|
|
131
|
+
palette?: readonly string[];
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Options for `mountFrameView`: empty words, mirroring and the colours of the drawn boxes.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
function gateWords(row: ModelRow | undefined): string
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The words of a gate's one pink button for a pick: "load, 1.7 gb", then "ready".
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
interface MaskModels {
|
|
145
|
+
everything?: (image: MaskPixels) => Promise<FoundMask[]>;
|
|
146
|
+
segment?: (image: MaskPixels, point: { x: number; y: number }) => Promise<Uint8Array<ArrayBufferLike> | null>;
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The segment models a mask studio calls: a click segment for one point and a segment everything.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
interface MaskStudio extends Mounted {
|
|
154
|
+
hasEverything: boolean;
|
|
155
|
+
hasSegment: boolean;
|
|
156
|
+
clear(): void;
|
|
157
|
+
cutAt(x: number, y: number, mode?: MaskMode): Promise<void>;
|
|
158
|
+
dispose(): void;
|
|
159
|
+
everything(): Promise<void>;
|
|
160
|
+
expand(px?: number): void;
|
|
161
|
+
exportAs(kind: MaskOutput): Promise<Blob | null>;
|
|
162
|
+
forget(id: number): void;
|
|
163
|
+
invert(): void;
|
|
164
|
+
mask(kind?: MaskOutput): ImageData | null;
|
|
165
|
+
pick(): void;
|
|
166
|
+
redo(): void;
|
|
167
|
+
restore(id: number): void;
|
|
168
|
+
save(name?: string): void;
|
|
169
|
+
setImage(src: string | HTMLImageElement | HTMLCanvasElement | ImageBitmap | MaskPixels): Promise<void>;
|
|
170
|
+
setMode(m: MaskMode): void;
|
|
171
|
+
setModels(m: MaskModels): void;
|
|
172
|
+
setSize(px: number): void;
|
|
173
|
+
setTolerance(pct: number): void;
|
|
174
|
+
setTool(t: StudioTool): void;
|
|
175
|
+
shrink(px?: number): void;
|
|
176
|
+
smooth(r?: number): void;
|
|
177
|
+
state(): StudioState;
|
|
178
|
+
subscribe(fn: (s: StudioState) => void): () => void;
|
|
179
|
+
toggleFound(index: number): void;
|
|
180
|
+
undo(): void;
|
|
181
|
+
zoom(dir: -1 | 0 | 1): void;
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
A mounted mask studio: image, tools, undo, grow and shrink, saved masks, found objects, export, and a subscription to its state.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
interface MaskStudioOptions {
|
|
189
|
+
models?: MaskModels;
|
|
190
|
+
name?: string;
|
|
191
|
+
note?: string;
|
|
192
|
+
onSample?: () => void;
|
|
193
|
+
sampleLabel?: string;
|
|
194
|
+
title?: string;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Options for `mountMaskStudio`: the segment models, empty state words, a sample button and the export file name.
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
interface MemoryInspector extends Mounted {
|
|
202
|
+
dispose(): void;
|
|
203
|
+
set(rec: RecallLike | null): void;
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
A mounted memory inspector whose `set` shows a new recall.
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
interface ModelSelectElement extends HTMLElement {
|
|
211
|
+
env: Env | undefined;
|
|
212
|
+
loader: Loader | undefined;
|
|
213
|
+
pick: ModelPick;
|
|
214
|
+
records: readonly ModelRecord[] | undefined;
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
The `<model-select>` element: set `pick`, `env`, `loader` or `records` on it before or after it connects.
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
interface ModelSelectOptions {
|
|
222
|
+
go?: boolean;
|
|
223
|
+
variant?: "line" | "chip";
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Options for `mountModelSelect`: the one line or the chip variant, and whether to draw the load button.
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
function mountCameraFeed(host: HTMLElement, o?: CameraFeedOptions): CameraFeed
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Opens the camera into a host and hands the video to `onFrame` at the set rate while it is live.
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
function mountChatList(host: HTMLElement, list: ChatList, o?: { label?: string }): Mounted
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The chat list rail (hackbuild-ui HbConversationList markup): new, open, rename, delete with a second press.
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
function mountChatPane(host: HTMLElement, thread: ChatThread, o?: ChatPaneOptions): Mounted
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The thread over a host, with the empty state inside it.
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
function mountComposer(host: HTMLElement, thread: ChatThread, o?: ComposerOptions): Mounted
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
The composer: Enter sends (Shift Enter adds a line, Escape stops), send is the one pink, stop replaces it while a reply streams.
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
function mountContextMeter(host: HTMLElement, thread: ChatThread, o?: { budget?: number | () => number; system?: string | () => string }): Mounted
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
The context meter (hackbuild-ui `.hb-ctxmeter`): what the next request carries against the model's context.
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
function mountFrameView(host: HTMLElement, o?: FrameViewOptions): FrameView
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Draws a frame in a camera tile on a host, with boxes, landmarks, a corner tag and a caption over it.
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
function mountMaskRack(host: HTMLElement, studio: MaskStudio, part: "found" | "mask" | "saved" | "export", o?: { name?: string }): Mounted
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The rack parts: what was found, the mask tools' settings, and the exports once there is a mask.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
function mountMaskStudio(host: HTMLElement, o?: MaskStudioOptions): MaskStudio
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Mounts a mask studio on a host: drop or open an image, then cut masks with the point, wand, brush and lasso tools or a segment model.
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
function mountMaskTools(host: HTMLElement, studio: MaskStudio): Mounted
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
The tool rail of a studio: point (when a click model is set), wand, brush, lasso, and segment everything (when that model is set).
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
function mountMaskVerbs(host: HTMLElement, studio: MaskStudio): Mounted
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
The verb row on the canvas: undo and redo once there is a change, zoom once there is an image.
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
function mountMemoryInspector(host: HTMLElement, rec?: RecallLike | null): MemoryInspector
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Shows a recall trace as a table on a host.
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
function mountModelJobs(host: HTMLElement, jobs: JobsPick, o?: { go?: boolean }): Mounted
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Several jobs: one line per job, presets with totals, and one pink "load all, <total>".
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
function mountModelSelect(host: HTMLElement, pick: ModelPick, o?: ModelSelectOptions): Mounted
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
The closed picker over a host; pressing it opens the sheet.
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
function mountTranscribeDrop(host: HTMLElement, queue: TranscribeQueue, o?: TranscribeDropOptions): TranscribeDropHandle
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
The drop zone that becomes the transcript.
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
function mountTranscribeQueue(host: HTMLElement, queue: TranscribeQueue): Mounted
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
The queue as hackbuild-ui strips: name, state, figures, progress, remove; run and stop.
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
function mountTranscriptExports(host: HTMLElement, queue: TranscribeQueue, o?: { go?: boolean; save?: (name: string, text: string, type: string) => void }): Mounted
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
`go` makes the first export the one pink action: the next thing to do once there is text.
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
function mountTranscriptView(host: HTMLElement, queue: TranscribeQueue, o?: TranscriptViewOptions): Mounted
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
The selected channel's transcript over a host.
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
function pickSheet(pick: ModelPick): Mounted & { open(): void }
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
The sheet of one pick, in a drawer on the body.
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
interface StudioState {
|
|
339
|
+
busy: string;
|
|
340
|
+
canRedo: boolean;
|
|
341
|
+
canUndo: boolean;
|
|
342
|
+
coverage: number;
|
|
343
|
+
error: string;
|
|
344
|
+
found: (FoundMask & { colour: string; on: boolean })[];
|
|
345
|
+
height: number;
|
|
346
|
+
mode: MaskMode;
|
|
347
|
+
ready: boolean;
|
|
348
|
+
saved: { coverage: number; id: number; name: string; thumb: string }[];
|
|
349
|
+
size: number;
|
|
350
|
+
tolerance: number;
|
|
351
|
+
tool: StudioTool;
|
|
352
|
+
width: number;
|
|
353
|
+
zoom: number;
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
What a mask studio shows: tool, mode, sizes, undo state, coverage, zoom, found and saved masks, image size and the last error.
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
type StudioTool = "point" | MaskTool
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
A mask studio tool: the click segment point or one of the hackbuild-ui mask tools.
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
interface TranscribeDropHandle extends Mounted {
|
|
367
|
+
dispose(): void;
|
|
368
|
+
pick(): void;
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
A mounted drop zone whose `pick` opens the file picker.
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
interface TranscribeDropOptions extends TranscriptViewOptions {
|
|
376
|
+
accept?: string;
|
|
377
|
+
note?: string;
|
|
378
|
+
onSample?: () => void;
|
|
379
|
+
onSeek?: (seconds: number) => void;
|
|
380
|
+
pickLabel?: string;
|
|
381
|
+
sampleLabel?: string;
|
|
382
|
+
showDropped?: boolean;
|
|
383
|
+
speakers?: boolean;
|
|
384
|
+
title?: string;
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Options for `mountTranscribeDrop`: accepted types, empty state words and a sample button, plus the transcript view options.
|
|
389
|
+
|
|
390
|
+
```ts
|
|
391
|
+
function transcriptHtml(c: Channel | undefined, o?: TranscriptViewOptions): string
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
The HTML of one channel's transcript, or an empty note when there is none.
|
|
395
|
+
|
|
396
|
+
```ts
|
|
397
|
+
interface TranscriptViewOptions {
|
|
398
|
+
onSeek?: (seconds: number) => void;
|
|
399
|
+
showDropped?: boolean;
|
|
400
|
+
speakers?: boolean;
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
Options for a transcript: speaker fields, a seek callback for the times, and whether dropped lines show in place.
|
|
405
|
+
|
|
406
|
+
```ts
|
|
407
|
+
function turnHtml(t: Turn, o: { busy: boolean; last: boolean; name: string }): string
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
The HTML of one chat turn, with its reasoning fold, memory used and stats.
|
|
411
|
+
|
|
412
|
+
### @hackbuild/ai-views
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
const ALL_RECORDS: readonly ModelRecord[]
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Every record the views know, the running package's copy of a duplicate first.
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
function backendOf(r: ModelRecord, env?: Env): ModelBackend
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
Where it runs here: the first rung this machine can take, else the record's first.
|
|
425
|
+
|
|
426
|
+
```ts
|
|
427
|
+
function boxWords(b: FrameBox): string
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
"cup 94%", or the label alone, or the score alone.
|
|
431
|
+
|
|
432
|
+
```ts
|
|
433
|
+
interface Channel {
|
|
434
|
+
dropped: Dropped[];
|
|
435
|
+
duration?: number;
|
|
436
|
+
error?: string;
|
|
437
|
+
id: number;
|
|
438
|
+
language?: string;
|
|
439
|
+
meta: StripFigure[];
|
|
440
|
+
model?: string;
|
|
441
|
+
name: string;
|
|
442
|
+
pct: number;
|
|
443
|
+
segments: Seg[];
|
|
444
|
+
size: number;
|
|
445
|
+
status: StripStatus;
|
|
446
|
+
}
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
One file in a transcribe queue: name, size, status, progress, segments, dropped lines and the error if it failed.
|
|
450
|
+
|
|
451
|
+
```ts
|
|
452
|
+
function chatList(o?: ThreadOptions): ChatList
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
Creates a list of chat threads, newest first, with one open; its `thread` always speaks for the open chat.
|
|
456
|
+
|
|
457
|
+
```ts
|
|
458
|
+
interface ChatList {
|
|
459
|
+
readonly thread: ChatThread;
|
|
460
|
+
create(): string;
|
|
461
|
+
open(id: string): void;
|
|
462
|
+
remove(id: string): void;
|
|
463
|
+
rename(id: string, title: string): void;
|
|
464
|
+
setEngine(engine: ChatEngine | null): void;
|
|
465
|
+
snapshot(): ChatListSnapshot;
|
|
466
|
+
subscribe(fn: (s: ChatListSnapshot) => void): () => void;
|
|
467
|
+
}
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
Several chats: a list with the newest first, one open.
|
|
471
|
+
|
|
472
|
+
```ts
|
|
473
|
+
interface ChatListItem {
|
|
474
|
+
count: number;
|
|
475
|
+
id: string;
|
|
476
|
+
title: string;
|
|
477
|
+
updated: number;
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
One chat in a chat list: id, title, last update and turn count.
|
|
482
|
+
|
|
483
|
+
```ts
|
|
484
|
+
interface ChatListSnapshot {
|
|
485
|
+
current: string;
|
|
486
|
+
items: readonly ChatListItem[];
|
|
487
|
+
}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
The chats of a list, newest first, and the id of the open one.
|
|
491
|
+
|
|
492
|
+
```ts
|
|
493
|
+
function chatThread(o?: ThreadOptions): ChatThread
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
Creates a chat thread that streams replies from an engine, with optional memory recall per message.
|
|
497
|
+
|
|
498
|
+
```ts
|
|
499
|
+
interface ChatThread {
|
|
500
|
+
clear(): void;
|
|
501
|
+
markdown(title?: string): string;
|
|
502
|
+
regenerate(): Promise<void>;
|
|
503
|
+
remove(id: number): void;
|
|
504
|
+
send(text: string): Promise<void>;
|
|
505
|
+
setEngine(engine: ChatEngine | null): void;
|
|
506
|
+
snapshot(): ThreadSnapshot;
|
|
507
|
+
stop(): void;
|
|
508
|
+
subscribe(fn: (s: ThreadSnapshot) => void): () => void;
|
|
509
|
+
}
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
A chat thread: send, stop, regenerate, remove and clear turns, set the engine, and export as markdown.
|
|
513
|
+
|
|
514
|
+
```ts
|
|
515
|
+
function contextSegments(s: ThreadSnapshot, system?: string): { key: string; label: string; tokens: number }[]
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
Tokens the next request carries, by source, for a context meter: about 4 characters a token (inferred).
|
|
519
|
+
|
|
520
|
+
```ts
|
|
521
|
+
function defaultPick(records: readonly ModelRecord[], env?: Env, estimate?: StorageEstimate | null): string
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
The row a picker starts on: the first "start here" record that fits this machine, else the first that fits and is fast or steady, else the first that fits, else the first.
|
|
525
|
+
|
|
526
|
+
```ts
|
|
527
|
+
function detailOf(r: ModelRecord): { label: string; value: string }[]
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
The chevron detail: licence, source, context, quant, runtime, and where the size came from.
|
|
531
|
+
|
|
532
|
+
```ts
|
|
533
|
+
type ExportKind = "txt" | "srt" | "vtt" | "json"
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
A transcript export format: txt, srt, vtt or json.
|
|
537
|
+
|
|
538
|
+
```ts
|
|
539
|
+
const FACE_API_BASE: "https://cdn.jsdelivr.net/npm/@vladmandic/face-api@1.7.12/model/"
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
Base URL of the face-api weights (MIT) on the package CDN.
|
|
543
|
+
|
|
544
|
+
```ts
|
|
545
|
+
function fitMap(src: { h: number; w: number }, view: { h: number; w: number }, fit?: "cover" | "contain"): { dx: number; dy: number; scale: number }
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
Source to view pixels for object-fit cover (crop) or contain (bars).
|
|
549
|
+
|
|
550
|
+
```ts
|
|
551
|
+
interface FrameBox {
|
|
552
|
+
h: number;
|
|
553
|
+
label?: string;
|
|
554
|
+
score?: number;
|
|
555
|
+
w: number;
|
|
556
|
+
x: number;
|
|
557
|
+
y: number;
|
|
558
|
+
}
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
What FrameView draws over a frame, as data: boxes from a detector, landmark points from a face, hand or pose model, and a caption from a vision language model.
|
|
562
|
+
|
|
563
|
+
```ts
|
|
564
|
+
interface FrameLandmarks {
|
|
565
|
+
edges?: [number, number][];
|
|
566
|
+
label?: string;
|
|
567
|
+
points: { x: number; y: number }[];
|
|
568
|
+
}
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
Landmark points to draw on a frame, with the index pairs to join and a label.
|
|
572
|
+
|
|
573
|
+
```ts
|
|
574
|
+
interface FrameResults {
|
|
575
|
+
boxes?: FrameBox[];
|
|
576
|
+
caption?: string;
|
|
577
|
+
landmarks?: FrameLandmarks[];
|
|
578
|
+
tag?: string;
|
|
579
|
+
}
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
What to draw on a frame: boxes, landmarks, a caption and a corner tag.
|
|
583
|
+
|
|
584
|
+
```ts
|
|
585
|
+
function frameTag(r: FrameResults): string
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
The corner tag: the caller's words, else how many boxes and landmark sets were found.
|
|
589
|
+
|
|
590
|
+
```ts
|
|
591
|
+
function groupOf(r: ModelRecord, state?: ModelPickState): ModelRowGroup
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
The group a row sits in.
|
|
595
|
+
|
|
596
|
+
```ts
|
|
597
|
+
function inspectorHtml(rec: RecallLike | null): string
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
The HTML of a recall trace table, or an empty note before any recall.
|
|
601
|
+
|
|
602
|
+
```ts
|
|
603
|
+
function isJob(s: string | null | undefined): s is Job
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
Whether a string is a job name.
|
|
607
|
+
|
|
608
|
+
```ts
|
|
609
|
+
function isNoDownload(r: ModelRecord): boolean
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
Whether a record has nothing to download: a built in, system or zero size model.
|
|
613
|
+
|
|
614
|
+
```ts
|
|
615
|
+
function isUncensored(r: ModelRecord): boolean
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
Whether a record's censorship is "uncensored" or "abliterated".
|
|
619
|
+
|
|
620
|
+
```ts
|
|
621
|
+
type Job = "chat" | "transcribe" | "vision" | "detect" | "masks" | "image" | "voice" | "depth" | "embed" | "faceswap" | "landmarks"
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
A job a model picker serves, such as chat, transcribe, vision or masks.
|
|
625
|
+
|
|
626
|
+
```ts
|
|
627
|
+
const JOB_NAMES: Job[]
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
Every job name, in the order of `JOBS`.
|
|
631
|
+
|
|
632
|
+
```ts
|
|
633
|
+
interface JobDef {
|
|
634
|
+
empty: string;
|
|
635
|
+
label: string;
|
|
636
|
+
provides: (caps: readonly string[]) => boolean;
|
|
637
|
+
title: string;
|
|
638
|
+
}
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
A job's words (line label, sheet title, empty line) and which capabilities serve it.
|
|
642
|
+
|
|
643
|
+
```ts
|
|
644
|
+
interface JobLine {
|
|
645
|
+
job: Job;
|
|
646
|
+
label: string;
|
|
647
|
+
required: boolean;
|
|
648
|
+
row: ModelRow | undefined;
|
|
649
|
+
}
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
One line of a jobs rack: the job, its label, whether it is required, and the chosen row.
|
|
653
|
+
|
|
654
|
+
```ts
|
|
655
|
+
function jobRecords(job: Job, records?: readonly ModelRecord[]): ModelRecord[]
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
The records that do a job, catalogue order kept.
|
|
659
|
+
|
|
660
|
+
```ts
|
|
661
|
+
const JOBS: Readonly<Record<Job, JobDef>>
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
The words and capability test of every job.
|
|
665
|
+
|
|
666
|
+
```ts
|
|
667
|
+
interface JobsPick {
|
|
668
|
+
readonly picks: ReadonlyMap<Job, ModelPick>;
|
|
669
|
+
all(): { ids: string[]; label: string };
|
|
670
|
+
applyPreset(id: string): void;
|
|
671
|
+
lines(): JobLine[];
|
|
672
|
+
loadAll(): Promise<void>;
|
|
673
|
+
presets(): { id: string; label: string; total: string }[];
|
|
674
|
+
setPresets(p: readonly PickPreset[]): void;
|
|
675
|
+
subscribe(fn: () => void): () => void;
|
|
676
|
+
update(o: { env?: Env; estimate?: StorageEstimate | null; loader?: Loader; onRemove?: (rec: ModelRecord) => void | Promise<void>; records?: readonly ModelRecord[] }): void;
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
Several pickers as one rack: a line per job, presets with their totals, and load all.
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
function labelColour(label: string | undefined, palette: readonly string[]): string
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
One colour per label, stable across frames, from a palette.
|
|
687
|
+
|
|
688
|
+
```ts
|
|
689
|
+
interface LoadContext {
|
|
690
|
+
onProgress: (fraction: number | null) => void;
|
|
691
|
+
options: Record<string, string>;
|
|
692
|
+
signal: AbortSignal;
|
|
693
|
+
}
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
What a loader gets: an abort signal, a progress callback and the row's options.
|
|
697
|
+
|
|
698
|
+
```ts
|
|
699
|
+
type Loader = (rec: ModelRecord, ctx: LoadContext) => Promise<unknown>
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
Fetches a model's weights (and may start its runtime).
|
|
703
|
+
|
|
704
|
+
```ts
|
|
705
|
+
interface MemoryUsed {
|
|
706
|
+
label: string;
|
|
707
|
+
score?: number;
|
|
708
|
+
}
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
A memory recalled for a reply, with its label and score.
|
|
712
|
+
|
|
713
|
+
```ts
|
|
714
|
+
interface ModelPick {
|
|
715
|
+
readonly job: Job;
|
|
716
|
+
cancel(id?: string): void;
|
|
717
|
+
choose(id: string): void;
|
|
718
|
+
custom(kind: OwnKind, values: Record<string, string>): string;
|
|
719
|
+
error(id: string): string | undefined;
|
|
720
|
+
load(id?: string): Promise<void>;
|
|
721
|
+
option(id: string, key: string, value: string): void;
|
|
722
|
+
optionsOf(id: string): Record<string, string>;
|
|
723
|
+
record(id: string): ModelRecord | undefined;
|
|
724
|
+
remove(id: string): Promise<void>;
|
|
725
|
+
result(id: string): unknown;
|
|
726
|
+
snapshot(): PickSnapshot;
|
|
727
|
+
subscribe(fn: (s: PickSnapshot) => void): () => void;
|
|
728
|
+
update(o: { env?: Env; estimate?: StorageEstimate | null; loader?: Loader; onRemove?: (rec: ModelRecord) => void | Promise<void>; records?: readonly ModelRecord[] }): void;
|
|
729
|
+
}
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
A model picker for one job: choose, load, cancel, remove, set row options, add your own model, and subscribe to its snapshot.
|
|
733
|
+
|
|
734
|
+
```ts
|
|
735
|
+
const NO_ENGINE: "this needs a model. pick one in the bar and load it."
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
What a reply says when no chat engine is set.
|
|
739
|
+
|
|
740
|
+
```ts
|
|
741
|
+
function optionsOf(r: ModelRecord, values?: Record<string, string>, extra?: readonly ModelOption[]): ModelOption[]
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
The options a chosen row offers: backend when the ladder has gpu and cpu, quant when it has several, context for chat.
|
|
745
|
+
|
|
746
|
+
```ts
|
|
747
|
+
function ownRecord(job: Job, kind: OwnKind, v: Record<string, string>): ModelRecord
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
A record for a "your own" form.
|
|
751
|
+
|
|
752
|
+
```ts
|
|
753
|
+
interface PickOptions {
|
|
754
|
+
chosen?: string;
|
|
755
|
+
env?: Env;
|
|
756
|
+
estimate?: StorageEstimate | null;
|
|
757
|
+
extra?: (rec: ModelRecord) => readonly ModelOption[];
|
|
758
|
+
loader?: Loader;
|
|
759
|
+
onRemove?: (rec: ModelRecord) => void | Promise<void>;
|
|
760
|
+
records?: readonly ModelRecord[];
|
|
761
|
+
stored?: Iterable<string, any, any>;
|
|
762
|
+
}
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
Options for `useModelPick`: records, env, storage estimate, loader, remover, stored ids, the chosen id and extra row options.
|
|
766
|
+
|
|
767
|
+
```ts
|
|
768
|
+
interface PickPreset {
|
|
769
|
+
id: string;
|
|
770
|
+
label: string;
|
|
771
|
+
picks: Partial<Record<Job, string>>;
|
|
772
|
+
}
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
A preset for a tool with several jobs: one pick per job.
|
|
776
|
+
|
|
777
|
+
```ts
|
|
778
|
+
interface PickSnapshot {
|
|
779
|
+
chosen: string;
|
|
780
|
+
empty: string;
|
|
781
|
+
job: Job;
|
|
782
|
+
loaded: unknown;
|
|
783
|
+
row: ModelRow | undefined;
|
|
784
|
+
rows: ModelRow[];
|
|
785
|
+
title: string;
|
|
786
|
+
}
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
What a picker shows: its job, title, rows, the chosen id and row, and what the loader returned for it.
|
|
790
|
+
|
|
791
|
+
```ts
|
|
792
|
+
interface QueueSnapshot {
|
|
793
|
+
canRedo: boolean;
|
|
794
|
+
canUndo: boolean;
|
|
795
|
+
channels: readonly Channel[];
|
|
796
|
+
running: boolean;
|
|
797
|
+
selected: number | null;
|
|
798
|
+
}
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
What a transcribe queue shows: channels, the selected one, whether it runs, and undo state.
|
|
802
|
+
|
|
803
|
+
```ts
|
|
804
|
+
type RecallLike = Pick<Recall, "trace" | "hits" | "query" | "mode">
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
The parts of a memory recall the inspector shows: trace, hits, query and mode.
|
|
808
|
+
|
|
809
|
+
```ts
|
|
810
|
+
interface RowContext {
|
|
811
|
+
env?: Env;
|
|
812
|
+
estimate?: StorageEstimate | null;
|
|
813
|
+
extra?: readonly ModelOption[];
|
|
814
|
+
options?: Record<string, string>;
|
|
815
|
+
own?: boolean;
|
|
816
|
+
progress?: number;
|
|
817
|
+
state?: ModelPickState;
|
|
818
|
+
}
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
What a row needs beyond its record: env, storage estimate, load state and progress, option values, job options, and whether the person added it.
|
|
822
|
+
|
|
823
|
+
```ts
|
|
824
|
+
function rowOf(r: ModelRecord, ctx?: RowContext): ModelRow
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
One record as one picker row.
|
|
828
|
+
|
|
829
|
+
```ts
|
|
830
|
+
interface RunContext {
|
|
831
|
+
onProgress: (fraction: number) => void;
|
|
832
|
+
signal: AbortSignal;
|
|
833
|
+
}
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
What a transcriber gets: an abort signal and a progress callback.
|
|
837
|
+
|
|
838
|
+
```ts
|
|
839
|
+
interface RunResult {
|
|
840
|
+
dropped?: Dropped[];
|
|
841
|
+
duration?: number;
|
|
842
|
+
language?: string;
|
|
843
|
+
model?: string;
|
|
844
|
+
segments: Seg[];
|
|
845
|
+
}
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
What a transcriber returns: segments, dropped lines, duration, language and model.
|
|
849
|
+
|
|
850
|
+
```ts
|
|
851
|
+
function sizeWords(r: ModelRecord): string | undefined
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
Download words: "1.7 gb".
|
|
855
|
+
|
|
856
|
+
```ts
|
|
857
|
+
interface ThreadOptions {
|
|
858
|
+
engine?: ChatEngine | null;
|
|
859
|
+
maxTokens?: number;
|
|
860
|
+
noEngine?: string;
|
|
861
|
+
now?: () => number;
|
|
862
|
+
recall?: (query: string) => Promise<MemoryUsed[]>;
|
|
863
|
+
system?: string;
|
|
864
|
+
}
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
Options for `chatThread` and `chatList`: engine, system prompt, memory recall, the no engine reply, clock and reply token cap.
|
|
868
|
+
|
|
869
|
+
```ts
|
|
870
|
+
interface ThreadSnapshot {
|
|
871
|
+
busy: boolean;
|
|
872
|
+
ready: boolean;
|
|
873
|
+
turns: readonly Turn[];
|
|
874
|
+
}
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
What a thread shows: its turns, whether a reply streams, and whether an engine is set.
|
|
878
|
+
|
|
879
|
+
```ts
|
|
880
|
+
function toView(b: FrameBox, m: { dx: number; dy: number; scale: number }, viewW: number, mirror?: boolean): FrameBox
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
A box in view pixels; mirrored for a selfie view.
|
|
884
|
+
|
|
885
|
+
```ts
|
|
886
|
+
interface TraceRow {
|
|
887
|
+
bm25: string;
|
|
888
|
+
cos: string;
|
|
889
|
+
id: number;
|
|
890
|
+
kind: string;
|
|
891
|
+
rank: number;
|
|
892
|
+
rrf: string;
|
|
893
|
+
score: string;
|
|
894
|
+
text: string;
|
|
895
|
+
used: boolean;
|
|
896
|
+
}
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
One row of a recall trace as text: rank, id, kind, text, BM25, cosine, RRF, score, and whether it went to the model.
|
|
900
|
+
|
|
901
|
+
```ts
|
|
902
|
+
function traceRows(r: Pick<Recall, "trace" | "hits">, maxText?: number): TraceRow[]
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
The rows of a recall trace as text, marking the hits handed to the model.
|
|
906
|
+
|
|
907
|
+
```ts
|
|
908
|
+
function transcribeQueue(o: { autostart?: boolean; run: Transcriber }): TranscribeQueue
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
Creates a transcribe queue that runs each file through `run`, one at a time.
|
|
912
|
+
|
|
913
|
+
```ts
|
|
914
|
+
interface TranscribeQueue {
|
|
915
|
+
add(files: Iterable<Blob & { name: string }>): void;
|
|
916
|
+
clear(): void;
|
|
917
|
+
edit(id: number, index: number, patch: { speaker?: string; text?: string }): void;
|
|
918
|
+
exportAs(kind: ExportKind, id?: number): { name: string; text: string; type: string } | null;
|
|
919
|
+
redo(): void;
|
|
920
|
+
remove(id: number): void;
|
|
921
|
+
select(id: number): void;
|
|
922
|
+
setTranscriber(t: Transcriber): void;
|
|
923
|
+
snapshot(): QueueSnapshot;
|
|
924
|
+
start(): Promise<void>;
|
|
925
|
+
stop(): void;
|
|
926
|
+
subscribe(fn: (s: QueueSnapshot) => void): () => void;
|
|
927
|
+
undo(): void;
|
|
928
|
+
}
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
A transcribe queue: add files, start and stop, select, edit lines with undo, and export a channel as txt, srt, vtt or json.
|
|
932
|
+
|
|
933
|
+
```ts
|
|
934
|
+
type Transcriber = (file: Blob & { name: string }, ctx: RunContext) => Promise<RunResult>
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
Turns one file into a transcript.
|
|
938
|
+
|
|
939
|
+
```ts
|
|
940
|
+
interface Turn {
|
|
941
|
+
at: number;
|
|
942
|
+
done: boolean;
|
|
943
|
+
id: number;
|
|
944
|
+
mem?: MemoryUsed[];
|
|
945
|
+
note?: string;
|
|
946
|
+
role: "user" | "assistant";
|
|
947
|
+
stats?: string;
|
|
948
|
+
text: string;
|
|
949
|
+
think: string;
|
|
950
|
+
}
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
One chat turn: role, text, reasoning, time, whether it is done, memory used, stats and a note.
|
|
954
|
+
|
|
955
|
+
```ts
|
|
956
|
+
function useJobsPick(jobs: readonly { job: Job; options?: PickOptions; required?: boolean }[], initialPresets?: readonly PickPreset[], shared?: PickOptions): JobsPick
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
Creates one picker per job and joins them as a rack with presets and load all.
|
|
960
|
+
|
|
961
|
+
```ts
|
|
962
|
+
function useModelPick(job: Job, o?: PickOptions): ModelPick
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
Creates a model picker for a job, with rows that say whether each model fits this machine.
|
|
966
|
+
|
|
967
|
+
```ts
|
|
968
|
+
function weightKeys(rec: ModelRecord): string[]
|
|
969
|
+
```
|
|
970
|
+
|
|
971
|
+
The cache keys of a record's files in a weight store, as weightsLoader writes them.
|
|
972
|
+
|
|
973
|
+
```ts
|
|
974
|
+
function weightsLoader(store: WeightStore): Loader
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
A loader that fetches a record's weight files through a weight store; records that load through their runtime throw.
|
|
978
|
+
|
|
979
|
+
```ts
|
|
980
|
+
function weightsRemover(store: WeightStore): (rec: ModelRecord) => Promise<void>
|
|
981
|
+
```
|
|
982
|
+
|
|
983
|
+
Deletes a stored model's files from a weight store: the remove of a picker.
|
|
984
|
+
|
|
985
|
+
### @hackbuild/ai-views/vue
|
|
986
|
+
|
|
987
|
+
```ts
|
|
988
|
+
const CameraFeed: DefineComponent<{ fps: number }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("feed" | "frame")[], "feed" | "frame", PublicProps, ToResolvedProps<{ fps: number }, ("feed" | "frame")[]>, { fps: number }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
Vue component that opens the camera; emits `feed` with the feed and `frame` with the video at `fps`.
|
|
992
|
+
|
|
993
|
+
```ts
|
|
994
|
+
const ChatList: DefineComponent<{ label: string; list: ChatList }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ label: string; list: ChatList }, {}>, { label: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
Vue component for the chat list rail of a `chatList`.
|
|
998
|
+
|
|
999
|
+
```ts
|
|
1000
|
+
const ChatPane: DefineComponent<{ emptyName: string; emptyNote: string; name: string; thread: ChatThread }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ emptyName: string; emptyNote: string; name: string; thread: ChatThread }, {}>, { emptyName: string; emptyNote: string; name: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
Vue component for the turns of a chat thread.
|
|
1004
|
+
|
|
1005
|
+
```ts
|
|
1006
|
+
const Composer: DefineComponent<{ placeholder: string; thread: ChatThread }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ placeholder: string; thread: ChatThread }, {}>, { placeholder: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
Vue component for the message box of a chat thread.
|
|
1010
|
+
|
|
1011
|
+
```ts
|
|
1012
|
+
const ContextMeter: DefineComponent<{ budget: number; system: string; thread: ChatThread }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ budget: number; system: string; thread: ChatThread }, {}>, { budget: number; system: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1013
|
+
```
|
|
1014
|
+
|
|
1015
|
+
Vue component that shows what the next request carries against the context budget.
|
|
1016
|
+
|
|
1017
|
+
```ts
|
|
1018
|
+
const FrameView: DefineComponent<ExtractPropTypes<{ mirror: { default: boolean; type: BooleanConstructor }; results: { default: () => {}; type: PropType<FrameResults> }; source: { default: null; type: PropType<string | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | null> } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, "view"[], "view", PublicProps, ToResolvedProps<ExtractPropTypes<{ mirror: { default: boolean; type: BooleanConstructor }; results: { default: () => {}; type: PropType<FrameResults> }; source: { default: null; type: PropType<string | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | null> } }>, "view"[]>, { mirror: boolean; results: FrameResults; source: string | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | null }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
Vue component that draws a frame with boxes, landmarks and a caption; emits `view` with the mounted view.
|
|
1022
|
+
|
|
1023
|
+
```ts
|
|
1024
|
+
const MaskRack: DefineComponent<{ name: string; part: "found" | "mask" | "saved" | "export"; studio: MaskStudio }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ name: string; part: "found" | "mask" | "saved" | "export"; studio: MaskStudio }, {}>, { name: string; part: "found" | "mask" | "saved" | "export" }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
Vue component for one rack part of a mask studio: found, mask, saved or export.
|
|
1028
|
+
|
|
1029
|
+
```ts
|
|
1030
|
+
const MaskStudio: DefineComponent<ExtractPropTypes<{ models: { default: () => {}; type: PropType<MaskModels> }; sampleLabel: { default: string; type: StringConstructor } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("sample" | "studio")[], "sample" | "studio", PublicProps, ToResolvedProps<ExtractPropTypes<{ models: { default: () => {}; type: PropType<MaskModels> }; sampleLabel: { default: string; type: StringConstructor } }>, ("sample" | "studio")[]>, { models: MaskModels; sampleLabel: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1031
|
+
```
|
|
1032
|
+
|
|
1033
|
+
Vue component for a mask studio; emits `studio` with the mounted studio and `sample` when the sample button is pressed.
|
|
1034
|
+
|
|
1035
|
+
```ts
|
|
1036
|
+
const MaskTools: DefineComponent<{ studio: MaskStudio }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ studio: MaskStudio }, {}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1037
|
+
```
|
|
1038
|
+
|
|
1039
|
+
Vue component for the tool rail of a mask studio.
|
|
1040
|
+
|
|
1041
|
+
```ts
|
|
1042
|
+
const MaskVerbs: DefineComponent<{ studio: MaskStudio }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ studio: MaskStudio }, {}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1043
|
+
```
|
|
1044
|
+
|
|
1045
|
+
Vue component for the undo, redo and zoom row of a mask studio.
|
|
1046
|
+
|
|
1047
|
+
```ts
|
|
1048
|
+
const MemoryInspector: DefineComponent<ExtractPropTypes<{ recall: { default: null; type: PropType<RecallLike | null> } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<ExtractPropTypes<{ recall: { default: null; type: PropType<RecallLike | null> } }>, {}>, { recall: RecallLike | null }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1049
|
+
```
|
|
1050
|
+
|
|
1051
|
+
Vue component that shows a recall trace as a table.
|
|
1052
|
+
|
|
1053
|
+
```ts
|
|
1054
|
+
const ModelJobs: DefineComponent<{ go: boolean; jobs: JobsPick }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ go: boolean; jobs: JobsPick }, {}>, { go: boolean }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
Vue component for a jobs rack: a line per job, presets and load all.
|
|
1058
|
+
|
|
1059
|
+
```ts
|
|
1060
|
+
const ModelSelect: DefineComponent<{ env?: Env; go: boolean; job: Job; loader?: Loader; pick?: ModelPick; variant: "line" | "chip" }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("choose" | "pick" | "loaded" | "failed")[], "choose" | "pick" | "loaded" | "failed", PublicProps, ToResolvedProps<{ env?: Env; go: boolean; job: Job; loader?: Loader; pick?: ModelPick; variant: "line" | "chip" }, ("choose" | "pick" | "loaded" | "failed")[]>, { env: Env; go: boolean; job: Job; loader: Loader; pick: ModelPick; variant: "line" | "chip" }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1061
|
+
```
|
|
1062
|
+
|
|
1063
|
+
Vue component for a model picker of one job; emits `pick`, `choose`, `loaded` and `failed`.
|
|
1064
|
+
|
|
1065
|
+
```ts
|
|
1066
|
+
const TranscribeDrop: DefineComponent<{ accept: string; queue: TranscribeQueue; sampleLabel: string }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, "sample"[], "sample", PublicProps, ToResolvedProps<{ accept: string; queue: TranscribeQueue; sampleLabel: string }, "sample"[]>, { accept: string; sampleLabel: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
Vue component for the drop zone that becomes the transcript; emits `sample`.
|
|
1070
|
+
|
|
1071
|
+
```ts
|
|
1072
|
+
const TranscribeQueue: DefineComponent<{ queue: TranscribeQueue }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ queue: TranscribeQueue }, {}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
Vue component for the file list of a transcribe queue.
|
|
1076
|
+
|
|
1077
|
+
```ts
|
|
1078
|
+
const TranscriptView: DefineComponent<{ exports: boolean; queue: TranscribeQueue }, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<{ exports: boolean; queue: TranscribeQueue }, {}>, { exports: boolean }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
|
|
1079
|
+
```
|
|
1080
|
+
|
|
1081
|
+
Vue component for the selected transcript, or its export buttons when `exports` is set.
|
|
1082
|
+
|
|
1083
|
+
## Examples
|
|
1084
|
+
|
|
1085
|
+
### quick start
|
|
1086
|
+
|
|
1087
|
+
```ts
|
|
1088
|
+
import { importEsm } from "@hackbuild/ai-env";
|
|
1089
|
+
import { ALL_RECORDS, chatThread, useModelPick, weightsLoader } from "@hackbuild/ai-views";
|
|
1090
|
+
import { mountChatPane, mountComposer, mountModelSelect } from "@hackbuild/ai-views/elements";
|
|
1091
|
+
import { loadWllama, wllamaUrls, type WllamaModule } from "@hackbuild/chat/wllama";
|
|
1092
|
+
import { openWeightStore } from "@hackbuild/weights";
|
|
1093
|
+
|
|
1094
|
+
// a chat picker over the GGUF rows, files through the weight store; Qwen2.5 0.5B Instruct weights are Apache-2.0
|
|
1095
|
+
const fetchFiles = weightsLoader(await openWeightStore());
|
|
1096
|
+
const wllama = await importEsm<WllamaModule>(wllamaUrls().esm); // the runtime is passed in, never bundled
|
|
1097
|
+
const thread = chatThread({ system: "answer in one line." });
|
|
1098
|
+
const pick = useModelPick("chat", {
|
|
1099
|
+
records: ALL_RECORDS.filter((r) => r.provider === "wllama"), chosen: "qwen2.5-0.5b-instruct-gguf",
|
|
1100
|
+
loader: async (rec, ctx) => thread.setEngine(await loadWllama({ module: wllama, blobs: [...((await fetchFiles(rec, ctx)) as Map<string, Blob>).values()] })),
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
// the picker, the turns and the composer, drawn with the page's hackbuild-ui stylesheet
|
|
1104
|
+
mountModelSelect(document.querySelector<HTMLElement>("#model")!, pick);
|
|
1105
|
+
mountChatPane(document.querySelector<HTMLElement>("#chat")!, thread);
|
|
1106
|
+
mountComposer(document.querySelector<HTMLElement>("#composer")!, thread);
|
|
1107
|
+
```
|
|
1108
|
+
|
|
1109
|
+
### from the concepts
|
|
1110
|
+
|
|
1111
|
+
```ts
|
|
1112
|
+
import { ModelSelect, ChatPane, Composer } from "@hackbuild/ai-views/vue";
|
|
1113
|
+
import { chatThread } from "@hackbuild/ai-views";
|
|
1114
|
+
const thread = chatThread({ engine });
|
|
1115
|
+
// <ModelSelect job="chat" variant="chip" /> <ChatPane :thread="thread" /> <Composer :thread="thread" />
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
## Mistakes to avoid
|
|
1119
|
+
|
|
1120
|
+
- You import a model runtime into a view or expect a picker to start one. A pick loads only through the `loader` you pass to `useModelPick`; with none it throws `no loader for <id>: pass one to useModelPick, such as weightsLoader(store)`. Bring the runtime in with `importEsm` from @hackbuild/ai-env and start it inside your loader.
|
|
1121
|
+
- You pass `weightsLoader(store)` for a record that loads through its runtime, such as a WebLLM row. It fetches only records with a `source.url` or a repo and files, under `rec.licence`, and throws `<label> loads through its runtime. the page passes a loader for it.` for the rest; write your own loader for those.
|
|
1122
|
+
- You expect the elements to exist after import. Nothing registers on import; call `define()` once, or `define("hb")` for `<hb-model-select>`, from `@hackbuild/ai-views/elements`.
|
|
1123
|
+
- You style the views locally or leave the stylesheet out. They draw in light DOM with the page's hackbuild-ui stylesheet, so load that stylesheet and install @virgilvox/hackbuild-ui as the required peer.
|
|
1124
|
+
- You import `@hackbuild/ai-views/vue` on a page without Vue. Only that entry imports Vue, an optional peer; the main entry is node safe state and `/elements` needs no framework.
|
|
1125
|
+
|
|
1126
|
+
## Errors this package throws
|
|
1127
|
+
|
|
1128
|
+
- `no loader for <id>: pass one to useModelPick, such as weightsLoader(store)` (a pick has no loader): pass `loader` to `useModelPick`, or set `loader` on `<model-select>`
|
|
1129
|
+
- `<model> loads through its runtime. the page passes a loader for it.` (`weightsLoader` got a record with no files to fetch (WebLLM, MediaPipe and the like)): pass a loader that starts that runtime
|
|
1130
|
+
- `this needs a model. pick one in the bar and load it.` (a reply, `NO_ENGINE`) (the thread has no engine): load a model and call `thread.setEngine`, or set `engine` on `<chat-pane>`
|
|
1131
|
+
- `no speech model loaded. pick one and load it.` (a failed file) (`<transcribe-drop>` has no transcriber): set its transcriber from @hackbuild/transcribe
|
|
1132
|
+
- `no custom elements in this environment` (`define()` ran without `customElements` or `HTMLElement`): call it on a page, or pass a registry and a base class
|
|
1133
|
+
- `the image did not load: ...`, `the cut failed: ...`, `segment everything failed: ...` (studio state) (the image or a segment model failed): read the message; check the model loaded
|