@hackbuild/ai-views 0.1.0 → 0.1.2

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