@hackbuild/ai-views 0.1.0 → 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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * ChatPane and Composer in the DOM, after the earlier chat tools: the
2
+ * ChatPane and Composer in the DOM: the
3
3
  * thread as hackbuild-ui messages, the reasoning in a fold that is open
4
4
  * while it streams, the memory a reply used in a fold under it, copy and
5
5
  * redo on the last reply only, and a composer whose send is the one pink
@@ -14,6 +14,7 @@ const paras = (t) => t
14
14
  .filter(Boolean)
15
15
  .map((p) => `<div class="hb-msg-text">${esc(p).replace(/\n/g, "<br>")}</div>`)
16
16
  .join("");
17
+ /** The HTML of one chat turn, with its reasoning fold, memory used and stats. */
17
18
  export function turnHtml(t, o) {
18
19
  if (t.role === "user") {
19
20
  return `<div class="hb-msg is-user" data-turn="${t.id}"><span class="hb-msg-who"><span class="hb-msg-name">you</span></span><div class="hb-msg-parts">${paras(t.text)}</div></div>`;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * FrameView and CameraFeed, after the eyes view of an earlier room: a
2
+ * FrameView and CameraFeed: a
3
3
  * frame in a hackbuild-ui camera tile with what the models found drawn
4
4
  * over it (boxes with their word and score, landmark points and lines),
5
5
  * a count in the corner and the caption under it. CameraFeed opens the
@@ -8,6 +8,7 @@
8
8
  import { type Mounted } from "./dom.js";
9
9
  import { type FrameResults } from "./frame.js";
10
10
  type Source = HTMLImageElement | HTMLVideoElement | HTMLCanvasElement;
11
+ /** A mounted frame view: set the source, the results to draw, mirroring, and paint again. */
11
12
  export interface FrameView extends Mounted {
12
13
  /** An image url, or a live element (a camera video); null shows the empty tile. */
13
14
  setSource(src: string | Source | null): Promise<void>;
@@ -16,13 +17,19 @@ export interface FrameView extends Mounted {
16
17
  /** Draw again, as after a resize or a new video frame. */
17
18
  paint(): void;
18
19
  }
20
+ /** Options for `mountFrameView`: empty words, mirroring and the colours of the drawn boxes. */
19
21
  export interface FrameViewOptions {
20
22
  empty?: string;
21
23
  mirror?: boolean;
22
24
  /** Ink of the drawn boxes' word strip; default the paper token. */
23
25
  palette?: readonly string[];
24
26
  }
27
+ /** Draws a frame in a camera tile on a host, with boxes, landmarks, a corner tag and a caption over it. */
25
28
  export declare function mountFrameView(host: HTMLElement, o?: FrameViewOptions): FrameView;
29
+ /**
30
+ * A mounted camera feed: start, stop, the video element, whether it is live, and a subscription to
31
+ * live and error changes.
32
+ */
26
33
  export interface CameraFeed extends Mounted {
27
34
  start(): Promise<void>;
28
35
  stop(): void;
@@ -33,6 +40,10 @@ export interface CameraFeed extends Mounted {
33
40
  error: string;
34
41
  }) => void): () => void;
35
42
  }
43
+ /**
44
+ * Options for `mountCameraFeed`: frames per second, the frame callback, which camera, and whether
45
+ * to draw a tile of its own.
46
+ */
36
47
  export interface CameraFeedOptions {
37
48
  /** Called with the video this many times a second while live. Default 4. */
38
49
  fps?: number;
@@ -41,5 +52,6 @@ export interface CameraFeedOptions {
41
52
  /** Draw the video in a tile of its own; off when a FrameView shows it. */
42
53
  tile?: boolean;
43
54
  }
55
+ /** Opens the camera into a host and hands the video to `onFrame` at the set rate while it is live. */
44
56
  export declare function mountCameraFeed(host: HTMLElement, o?: CameraFeedOptions): CameraFeed;
45
57
  export {};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * FrameView and CameraFeed, after the eyes view of an earlier room: a
2
+ * FrameView and CameraFeed: a
3
3
  * frame in a hackbuild-ui camera tile with what the models found drawn
4
4
  * over it (boxes with their word and score, landmark points and lines),
5
5
  * a count in the corner and the caption under it. CameraFeed opens the
@@ -16,6 +16,7 @@ const css = (el, name, fb) => {
16
16
  return fb;
17
17
  }
18
18
  };
19
+ /** Draws a frame in a camera tile on a host, with boxes, landmarks, a corner tag and a caption over it. */
19
20
  export function mountFrameView(host, o = {}) {
20
21
  host.innerHTML = `<div class="hb-frameview"><figure class="hb-camtile" aria-label="frame"><div class="hb-camtile-none" role="status">${esc(o.empty ?? "no frame yet")}</div><canvas aria-hidden="true"></canvas><span class="hb-camtile-tag is-tl" hidden></span></figure><p class="hb-frameview-cap" data-caption aria-live="polite" hidden></p></div>`;
21
22
  const fig = host.querySelector("figure");
@@ -161,6 +162,7 @@ export function mountFrameView(host, o = {}) {
161
162
  };
162
163
  return view;
163
164
  }
165
+ /** Opens the camera into a host and hands the video to `onFrame` at the set rate while it is live. */
164
166
  export function mountCameraFeed(host, o = {}) {
165
167
  const video = document.createElement("video");
166
168
  video.autoplay = true;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * MaskStudio, after the earlier mask studio: drop an image, press a thing
2
+ * MaskStudio: drop an image, press a thing
3
3
  * to cut it out (a click segment model such as SlimSAM), fix the mask by
4
4
  * hand with the wand, brush and lasso of hackbuild-ui maskEditor (x swaps
5
5
  * add and erase, [ and ] size the brush, ctrl z undoes), zoom and fit, and
@@ -16,6 +16,7 @@ export interface FoundMask {
16
16
  label: string;
17
17
  score: number;
18
18
  }
19
+ /** The segment models a mask studio calls: a click segment for one point and a segment everything. */
19
20
  export interface MaskModels {
20
21
  /** Click segment: the mask under one point, in image pixels. */
21
22
  segment?: (image: MaskPixels, point: {
@@ -25,7 +26,12 @@ export interface MaskModels {
25
26
  /** Segment everything: every object at once. */
26
27
  everything?: (image: MaskPixels) => Promise<FoundMask[]>;
27
28
  }
29
+ /** A mask studio tool: the click segment point or one of the hackbuild-ui mask tools. */
28
30
  export type StudioTool = "point" | MaskTool;
31
+ /**
32
+ * What a mask studio shows: tool, mode, sizes, undo state, coverage, zoom, found and saved masks,
33
+ * image size and the last error.
34
+ */
29
35
  export interface StudioState {
30
36
  ready: boolean;
31
37
  tool: StudioTool;
@@ -53,6 +59,10 @@ export interface StudioState {
53
59
  /** The last failure, in words. */
54
60
  error: string;
55
61
  }
62
+ /**
63
+ * A mounted mask studio: image, tools, undo, grow and shrink, saved masks, found objects, export,
64
+ * and a subscription to its state.
65
+ */
56
66
  export interface MaskStudio extends Mounted {
57
67
  setImage(src: string | HTMLImageElement | HTMLCanvasElement | ImageBitmap | MaskPixels): Promise<void>;
58
68
  setTool(t: StudioTool): void;
@@ -89,6 +99,10 @@ export interface MaskStudio extends Mounted {
89
99
  /** Open the file picker. */
90
100
  pick(): void;
91
101
  }
102
+ /**
103
+ * Options for `mountMaskStudio`: the segment models, empty state words, a sample button and the
104
+ * export file name.
105
+ */
92
106
  export interface MaskStudioOptions {
93
107
  models?: MaskModels;
94
108
  title?: string;
@@ -98,6 +112,10 @@ export interface MaskStudioOptions {
98
112
  /** Name of exported files, without extension. */
99
113
  name?: string;
100
114
  }
115
+ /**
116
+ * Mounts a mask studio on a host: drop or open an image, then cut masks with the point, wand, brush
117
+ * and lasso tools or a segment model.
118
+ */
101
119
  export declare function mountMaskStudio(host: HTMLElement, o?: MaskStudioOptions): MaskStudio;
102
120
  /** The tool rail of a studio: point (when a click model is set), wand, brush, lasso, and segment everything (when that model is set). */
103
121
  export declare function mountMaskTools(host: HTMLElement, studio: MaskStudio): Mounted;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * MaskStudio, after the earlier mask studio: drop an image, press a thing
2
+ * MaskStudio: drop an image, press a thing
3
3
  * to cut it out (a click segment model such as SlimSAM), fix the mask by
4
4
  * hand with the wand, brush and lasso of hackbuild-ui maskEditor (x swaps
5
5
  * add and erase, [ and ] size the brush, ctrl z undoes), zoom and fit, and
@@ -33,6 +33,10 @@ function thumbOf(img) {
33
33
  t.getContext("2d")?.drawImage(c, 0, 0, t.width, t.height);
34
34
  return t.toDataURL("image/png");
35
35
  }
36
+ /**
37
+ * Mounts a mask studio on a host: drop or open an image, then cut masks with the point, wand, brush
38
+ * and lasso tools or a segment model.
39
+ */
36
40
  export function mountMaskStudio(host, o = {}) {
37
41
  let models = o.models ?? {};
38
42
  const l = listeners();
@@ -11,6 +11,7 @@ import type { JobsPick, ModelPick } from "./pick.js";
11
11
  export declare function pickSheet(pick: ModelPick): Mounted & {
12
12
  open(): void;
13
13
  };
14
+ /** Options for `mountModelSelect`: the one line or the chip variant, and whether to draw the load button. */
14
15
  export interface ModelSelectOptions {
15
16
  /** "line" (default): the one line and the pink load. "chip": the one model chip of the bar. */
16
17
  variant?: "line" | "chip";
@@ -1,11 +1,14 @@
1
1
  /**
2
- * TranscribeDrop, TranscriptView and their rack parts in the DOM, after the
3
- * earlier transcription tool: the drop zone is the page until a file is in
2
+ * TranscribeDrop, TranscriptView and their rack parts in the DOM: the drop zone is the page until a file is in
4
3
  * it, then the transcript is. Lines carry their time, edit in place (one
5
4
  * undo step each), and export as txt, srt, vtt and json once there is text.
6
5
  */
7
6
  import { type Mounted } from "./dom.js";
8
7
  import type { Channel, TranscribeQueue } from "./transcribe.js";
8
+ /**
9
+ * Options for a transcript: speaker fields, a seek callback for the times, and whether dropped
10
+ * lines show in place.
11
+ */
9
12
  export interface TranscriptViewOptions {
10
13
  /** Speaker fields beside each line. Off by default: they are inputs, and a subject keeps few controls. */
11
14
  speakers?: boolean;
@@ -14,9 +17,14 @@ export interface TranscriptViewOptions {
14
17
  /** Show dropped lines in place. */
15
18
  showDropped?: boolean;
16
19
  }
20
+ /** The HTML of one channel's transcript, or an empty note when there is none. */
17
21
  export declare function transcriptHtml(c: Channel | undefined, o?: TranscriptViewOptions): string;
18
22
  /** The selected channel's transcript over a host. */
19
23
  export declare function mountTranscriptView(host: HTMLElement, queue: TranscribeQueue, o?: TranscriptViewOptions): Mounted;
24
+ /**
25
+ * Options for `mountTranscribeDrop`: accepted types, empty state words and a sample button, plus
26
+ * the transcript view options.
27
+ */
20
28
  export interface TranscribeDropOptions extends TranscriptViewOptions {
21
29
  accept?: string;
22
30
  title?: string;
@@ -26,6 +34,7 @@ export interface TranscribeDropOptions extends TranscriptViewOptions {
26
34
  sampleLabel?: string;
27
35
  onSample?: () => void;
28
36
  }
37
+ /** A mounted drop zone whose `pick` opens the file picker. */
29
38
  export interface TranscribeDropHandle extends Mounted {
30
39
  /** Open the file picker: the add files verb. */
31
40
  pick(): void;
@@ -1,11 +1,11 @@
1
1
  /**
2
- * TranscribeDrop, TranscriptView and their rack parts in the DOM, after the
3
- * earlier transcription tool: the drop zone is the page until a file is in
2
+ * TranscribeDrop, TranscriptView and their rack parts in the DOM: the drop zone is the page until a file is in
4
3
  * it, then the transcript is. Lines carry their time, edit in place (one
5
4
  * undo step each), and export as txt, srt, vtt and json once there is text.
6
5
  */
7
6
  import { clockTime, droppedLine, stripStatus } from "@virgilvox/hackbuild-ui/vanilla";
8
7
  import { ICON, download, esc, listeners, show } from "./dom.js";
8
+ /** The HTML of one channel's transcript, or an empty note when there is none. */
9
9
  export function transcriptHtml(c, o = {}) {
10
10
  if (!c)
11
11
  return `<p class="hb-lay-empty-note">nothing yet. drop a file.</p>`;
package/dist/pick.d.ts CHANGED
@@ -10,6 +10,7 @@ import type { ModelRecord, StorageEstimate } from "@hackbuild/models";
10
10
  import { type WeightStore } from "@hackbuild/weights";
11
11
  import { type ModelOption, type ModelRow, type OwnKind } from "@virgilvox/hackbuild-ui/vanilla";
12
12
  import { type Job } from "./jobs.js";
13
+ /** What a loader gets: an abort signal, a progress callback and the row's options. */
13
14
  export interface LoadContext {
14
15
  signal: AbortSignal;
15
16
  /** 0 to 1, or null while the total is unknown. */
@@ -26,9 +27,17 @@ export type Loader = (rec: ModelRecord, ctx: LoadContext) => Promise<unknown>;
26
27
  */
27
28
  /** The cache keys of a record's files in a weight store, as weightsLoader writes them. */
28
29
  export declare function weightKeys(rec: ModelRecord): string[];
30
+ /**
31
+ * A loader that fetches a record's weight files through a weight store; records that load through
32
+ * their runtime throw.
33
+ */
29
34
  export declare function weightsLoader(store: WeightStore): Loader;
30
35
  /** Deletes a stored model's files from a weight store: the remove of a picker. */
31
36
  export declare function weightsRemover(store: WeightStore): (rec: ModelRecord) => Promise<void>;
37
+ /**
38
+ * Options for `useModelPick`: records, env, storage estimate, loader, remover, stored ids, the
39
+ * chosen id and extra row options.
40
+ */
32
41
  export interface PickOptions {
33
42
  /** Records to pick from; default every record the views know. */
34
43
  records?: readonly ModelRecord[];
@@ -44,6 +53,7 @@ export interface PickOptions {
44
53
  /** Options a job adds to every row, like a language select for speech. */
45
54
  extra?: (rec: ModelRecord) => readonly ModelOption[];
46
55
  }
56
+ /** What a picker shows: its job, title, rows, the chosen id and row, and what the loader returned for it. */
47
57
  export interface PickSnapshot {
48
58
  job: Job;
49
59
  title: string;
@@ -54,6 +64,10 @@ export interface PickSnapshot {
54
64
  /** What the loader returned for the chosen model, once it is loaded (an engine, a session). */
55
65
  loaded: unknown;
56
66
  }
67
+ /**
68
+ * A model picker for one job: choose, load, cancel, remove, set row options, add your own model,
69
+ * and subscribe to its snapshot.
70
+ */
57
71
  export interface ModelPick {
58
72
  readonly job: Job;
59
73
  snapshot(): PickSnapshot;
@@ -91,6 +105,7 @@ export declare function ownRecord(job: Job, kind: OwnKind, v: Record<string, str
91
105
  * that fits, else the first.
92
106
  */
93
107
  export declare function defaultPick(records: readonly ModelRecord[], env?: Env, estimate?: StorageEstimate | null): string;
108
+ /** Creates a model picker for a job, with rows that say whether each model fits this machine. */
94
109
  export declare function useModelPick(job: Job, o?: PickOptions): ModelPick;
95
110
  /** A preset for a tool with several jobs: one pick per job. */
96
111
  export interface PickPreset {
@@ -98,6 +113,7 @@ export interface PickPreset {
98
113
  label: string;
99
114
  picks: Partial<Record<Job, string>>;
100
115
  }
116
+ /** One line of a jobs rack: the job, its label, whether it is required, and the chosen row. */
101
117
  export interface JobLine {
102
118
  job: Job;
103
119
  label: string;
@@ -125,6 +141,7 @@ export interface JobsPick {
125
141
  update(o: Parameters<ModelPick["update"]>[0]): void;
126
142
  setPresets(p: readonly PickPreset[]): void;
127
143
  }
144
+ /** Creates one picker per job and joins them as a rack with presets and load all. */
128
145
  export declare function useJobsPick(jobs: readonly {
129
146
  job: Job;
130
147
  required?: boolean;
package/dist/pick.js CHANGED
@@ -24,6 +24,10 @@ export function weightKeys(rec) {
24
24
  const files = s.files?.length ? s.files.map((f) => f.path) : s.file ? [s.file] : [];
25
25
  return base ? files.map((f) => base + f) : [];
26
26
  }
27
+ /**
28
+ * A loader that fetches a record's weight files through a weight store; records that load through
29
+ * their runtime throw.
30
+ */
27
31
  export function weightsLoader(store) {
28
32
  return async (rec, { signal, onProgress }) => {
29
33
  if (rec.noDownload || rec.sizeMB === 0) {
@@ -74,6 +78,7 @@ export function defaultPick(records, env, estimate) {
74
78
  const fits = records.filter((r) => rowOf(r, { env, estimate }).unfit === undefined);
75
79
  return (fits.find((r) => r.group === "start here") ?? fits.find((r) => r.speed === "fast" || r.speed === "steady") ?? fits[0] ?? records[0])?.id ?? "";
76
80
  }
81
+ /** Creates a model picker for a job, with rows that say whether each model fits this machine. */
77
82
  export function useModelPick(job, o = {}) {
78
83
  const def = JOBS[job];
79
84
  let records = jobRecords(job, o.records ?? ALL_RECORDS);
@@ -207,6 +212,7 @@ export function useModelPick(job, o = {}) {
207
212
  };
208
213
  return pick;
209
214
  }
215
+ /** Creates one picker per job and joins them as a rack with presets and load all. */
210
216
  export function useJobsPick(jobs, initialPresets = [], shared = {}) {
211
217
  let presets = initialPresets;
212
218
  const extra = new Set();
package/dist/rows.d.ts CHANGED
@@ -6,7 +6,9 @@
6
6
  import type { Env } from "@hackbuild/ai-env";
7
7
  import { type ModelRecord, type StorageEstimate } from "@hackbuild/models";
8
8
  import { type ModelBackend, type ModelOption, type ModelPickState, type ModelRow, type ModelRowGroup } from "@virgilvox/hackbuild-ui/vanilla";
9
+ /** Whether a record has nothing to download: a built in, system or zero size model. */
9
10
  export declare function isNoDownload(r: ModelRecord): boolean;
11
+ /** Whether a record's censorship is "uncensored" or "abliterated". */
10
12
  export declare function isUncensored(r: ModelRecord): boolean;
11
13
  /** The group a row sits in. A model on this machine leads; else the record's group, else by size. */
12
14
  export declare function groupOf(r: ModelRecord, state?: ModelPickState): ModelRowGroup;
@@ -21,6 +23,10 @@ export declare function detailOf(r: ModelRecord): {
21
23
  }[];
22
24
  /** The options a chosen row offers: backend when the ladder has gpu and cpu, quant when it has several, context for chat. */
23
25
  export declare function optionsOf(r: ModelRecord, values?: Record<string, string>, extra?: readonly ModelOption[]): ModelOption[];
26
+ /**
27
+ * What a row needs beyond its record: env, storage estimate, load state and progress, option
28
+ * values, job options, and whether the person added it.
29
+ */
24
30
  export interface RowContext {
25
31
  env?: Env | undefined;
26
32
  estimate?: StorageEstimate | null | undefined;
package/dist/rows.js CHANGED
@@ -17,9 +17,11 @@ const GROUPS = {
17
17
  "no download": "none",
18
18
  own: "own",
19
19
  };
20
+ /** Whether a record has nothing to download: a built in, system or zero size model. */
20
21
  export function isNoDownload(r) {
21
22
  return !!r.noDownload || r.sizeMB === 0 || r.provider === "prompt-api" || r.provider === "system";
22
23
  }
24
+ /** Whether a record's censorship is "uncensored" or "abliterated". */
23
25
  export function isUncensored(r) {
24
26
  return r.censorship === "uncensored" || r.censorship === "abliterated";
25
27
  }