@hackbuild/ai-views 0.1.1 → 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/README.md +25 -5
- package/dist/elements.d.ts +1 -1
- package/dist/elements.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/loaders.d.ts +100 -0
- package/dist/loaders.js +308 -0
- package/dist/mount-model.d.ts +10 -1
- package/dist/mount-model.js +25 -4
- package/dist/single/elements.iife.js +26 -3
- package/dist/single/elements.js +25 -4
- package/dist/single/index.iife.js +17032 -6187
- package/dist/single/index.js +17030 -6188
- package/dist/single/vue.iife.js +24 -3
- package/dist/single/vue.js +24 -3
- package/llms.md +100 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@hackbuild/ai-views) [](../../LICENSE) ](https://www.npmjs.com/package/@hackbuild/ai-views) [](../../LICENSE)  
|
|
6
6
|
|
|
7
7
|
Browser status: no model run of this package has been verified in a real browser yet.
|
|
8
8
|
|
|
@@ -91,7 +91,25 @@ const thread = chatThread({ engine });
|
|
|
91
91
|
|
|
92
92
|
### picks and loaders
|
|
93
93
|
|
|
94
|
-
A pick loads only through its loader (none is an error the row shows), runs it for every row, a no download row included, and keeps its result on `snapshot().loaded`; `remove()` deletes through `onRemove`. It starts on the first "start here" record that fits, else the first fast or steady one. `weightsLoader(store)` fetches a record's files through @hackbuild/weights; a record that loads through its runtime (WebLLM, MediaPipe and the like)
|
|
94
|
+
A pick loads only through its loader (none is an error the row shows), runs it for every row, a no download row included, and keeps its result on `snapshot().loaded`; `remove()` deletes through `onRemove`. It starts on the first "start here" record that fits, else the first fast or steady one. `weightsLoader(store)` fetches a record's files through @hackbuild/weights; a record that loads through its runtime (WebLLM, MediaPipe and the like) takes `jobLoader(job)`. `useJobsPick` joins pickers as a rack with a line per job, presets with their download totals, and load all.
|
|
95
|
+
|
|
96
|
+
### real loads
|
|
97
|
+
|
|
98
|
+
`jobLoader(job, { store?, env?, allowGplPhonemizer? })` is the loader a page passes to `useModelPick(job, { loader })`. A load imports the runtime from its pinned CDN only when the person presses load, fetches weights through @hackbuild/weights where the runtime does not fetch its own, sends progress to the row, stops on the row's stop, and fails in plain words. One models hub serves every loader made with the same options object. Probe the machine with `probe()` from @hackbuild/ai-env and pass it to the pick as `env`.
|
|
99
|
+
|
|
100
|
+
| job | resolves to | runtimes |
|
|
101
|
+
|---|---|---|
|
|
102
|
+
| chat | a @hackbuild/chat `ChatEngine` | WebLLM, wllama (gguf through the weight store), transformers.js, the browser's built in model |
|
|
103
|
+
| transcribe | a `Transcriber` for TranscribeDrop | whisper on transformers.js, the dsp core inlined |
|
|
104
|
+
| detect | `(image) => FrameBox[]` | MediaPipe EfficientDet, YOLO on onnxruntime web |
|
|
105
|
+
| masks | `MaskModels`: click segment, and segment everything from a 4 by 3 grid of points | SlimSAM on transformers.js; FastSAM is refused until it has a decoder |
|
|
106
|
+
| depth | `(image) => { width, height, data }`, 0 to 1, larger is nearer | Depth Anything on transformers.js |
|
|
107
|
+
| vision | `(image, question?) => string`, a caption without a question | SmolVLM, LFM2-VL, Gemma on transformers.js |
|
|
108
|
+
| image | an imagegen `ImageGenerator` with its CLIP `tokenize` and `make(form)` | onnxruntime web; the tokenizer on transformers.js |
|
|
109
|
+
| voice | a loaded @hackbuild/speak `Engine` | the system voice (no download), bellows, pocket tts, kokoro (gpl phonemizer, opt in) |
|
|
110
|
+
| embed | an @hackbuild/embed `Embedder` | static potion files, transformers.js |
|
|
111
|
+
|
|
112
|
+
The bar chip shows the name cut short (`shortName`: "hermes 3 llama 3.2 3b" reads "hermes 3 3b") and the size, then the state once a load moves; the full name is its label.
|
|
95
113
|
|
|
96
114
|
### views
|
|
97
115
|
|
|
@@ -115,6 +133,7 @@ Jobs and their records: chat (the chat rows of the @hackbuild/models catalogue),
|
|
|
115
133
|
| [`useModelPick`](../../docs/api/ai-views/index.md#usemodelpick) | a model picker for one job |
|
|
116
134
|
| [`useJobsPick`](../../docs/api/ai-views/index.md#usejobspick) | pickers for several jobs as one rack |
|
|
117
135
|
| [`weightsLoader`](../../docs/api/ai-views/index.md#weightsloader) | a loader that fetches files through a weight store |
|
|
136
|
+
| [`jobLoader`](../../docs/api/ai-views/index.md#jobloader) | the real loader of a job: runtime and weights at load time |
|
|
118
137
|
| [`chatThread`](../../docs/api/ai-views/index.md#chatthread) | a chat thread over an engine |
|
|
119
138
|
| [`chatList`](../../docs/api/ai-views/index.md#chatlist) | several chats, one open |
|
|
120
139
|
| [`transcribeQueue`](../../docs/api/ai-views/index.md#transcribequeue) | a queue of files to transcribe, with edits and exports |
|
|
@@ -223,10 +242,11 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
223
242
|
|---|---|---|
|
|
224
243
|
| 2026-11-25 | `npx vitest run packages/ai-views` | pass: every job has the records above with a speed word and a verdict; rows carry size, memory, backend, marks, detail and options, and a row that does not fit names why; a pick loads with progress, cancels and keeps a failure's words; presets total their download; the chat thread streams with the reasoning apart and memory used; the queue runs, edits with undo and exports; the frame mapping crops and mirrors; define registers every element |
|
|
225
244
|
| 2026-11-25 | `node tools/smoke-views.mjs`, headless | pass: one smoke per demo page on stub providers with no weights |
|
|
245
|
+
| 2026-11-25 | `npx vitest run packages/ai-views/test/loaders.test.ts` | pass: jobLoader loads a transformers.js chat model and a depth model through fake runtime modules, a WebLLM model through a fake module, refuses kokoro without the opt in and FastSAM in plain words, stops on abort, imports nothing before a load, makes no network request; the chip cuts a name and shows its size |
|
|
226
246
|
|
|
227
247
|
### Not verified by anything
|
|
228
248
|
|
|
229
|
-
- A real model through any view in this package
|
|
249
|
+
- A real model through jobLoader or any view in this package: tests use fake runtime modules and the demos stubs; no weights were fetched. The transcribe, detect, masks, vision, image, voice and embed paths of jobLoader have no test of their own yet.
|
|
230
250
|
- Touch drawing on a phone.
|
|
231
251
|
- Screen readers.
|
|
232
252
|
|
|
@@ -234,8 +254,8 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
234
254
|
|
|
235
255
|
| file | gzip (measured) | ceiling |
|
|
236
256
|
|---|---|---|
|
|
237
|
-
| `dist/index.js` (main entry, imports external) |
|
|
238
|
-
| `dist/single/elements.iife.js` (single file build) | 86,
|
|
257
|
+
| `dist/index.js` (main entry, imports external) | 16,915 bytes | 17,760 bytes |
|
|
258
|
+
| `dist/single/elements.iife.js` (single file build) | 86,306 bytes | 90,621 bytes |
|
|
239
259
|
|
|
240
260
|
Measured 2026-11-25 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
241
261
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
package/dist/elements.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import type { Env } from "@hackbuild/ai-env";
|
|
15
15
|
import type { ModelRecord } from "@hackbuild/models";
|
|
16
16
|
import { type Loader, type ModelPick } from "./pick.js";
|
|
17
|
-
export { mountModelSelect, mountModelJobs, pickSheet, gateWords, type ModelSelectOptions } from "./mount-model.js";
|
|
17
|
+
export { mountModelSelect, mountModelJobs, pickSheet, gateWords, chipWords, shortName, type ModelSelectOptions } from "./mount-model.js";
|
|
18
18
|
export { mountChatPane, mountComposer, mountChatList, mountContextMeter, turnHtml, type ChatPaneOptions, type ComposerOptions } from "./mount-chat.js";
|
|
19
19
|
export { mountTranscribeDrop, mountTranscriptView, mountTranscribeQueue, mountTranscriptExports, transcriptHtml, type TranscribeDropOptions, type TranscribeDropHandle, type TranscriptViewOptions } from "./mount-transcribe.js";
|
|
20
20
|
export { mountMaskStudio, mountMaskTools, mountMaskVerbs, mountMaskRack, type MaskStudio, type MaskModels, type MaskStudioOptions, type FoundMask, type StudioState, type StudioTool } from "./mount-mask.js";
|
package/dist/elements.js
CHANGED
|
@@ -21,7 +21,7 @@ import { mountModelJobs, mountModelSelect } from "./mount-model.js";
|
|
|
21
21
|
import { mountTranscribeDrop, mountTranscribeQueue, mountTranscriptExports, mountTranscriptView } from "./mount-transcribe.js";
|
|
22
22
|
import { transcribeQueue } from "./transcribe.js";
|
|
23
23
|
import { mountMemoryInspector } from "./memory.js";
|
|
24
|
-
export { mountModelSelect, mountModelJobs, pickSheet, gateWords } from "./mount-model.js";
|
|
24
|
+
export { mountModelSelect, mountModelJobs, pickSheet, gateWords, chipWords, shortName } from "./mount-model.js";
|
|
25
25
|
export { mountChatPane, mountComposer, mountChatList, mountContextMeter, turnHtml } from "./mount-chat.js";
|
|
26
26
|
export { mountTranscribeDrop, mountTranscriptView, mountTranscribeQueue, mountTranscriptExports, transcriptHtml } from "./mount-transcribe.js";
|
|
27
27
|
export { mountMaskStudio, mountMaskTools, mountMaskVerbs, mountMaskRack } from "./mount-mask.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export { chatThread, chatList, contextSegments, NO_ENGINE, type ChatList, type C
|
|
|
5
5
|
export { transcribeQueue, type TranscribeQueue, type Transcriber, type RunResult, type RunContext, type Channel, type ExportKind, type QueueSnapshot } from "./transcribe.js";
|
|
6
6
|
export { fitMap, toView, boxWords, frameTag, labelColour, type FrameBox, type FrameLandmarks, type FrameResults } from "./frame.js";
|
|
7
7
|
export { traceRows, inspectorHtml, type TraceRow, type RecallLike } from "./memory.js";
|
|
8
|
+
export { jobLoader, asImage, RUNTIME_URLS, type JobLoaderOptions, type JobValues, type RuntimeModules, type DetectFn, type DepthFn, type AskFn, type ImageJob } from "./loaders.js";
|
package/dist/index.js
CHANGED
|
@@ -8,3 +8,4 @@ export { chatThread, chatList, contextSegments, NO_ENGINE } from "./chat.js";
|
|
|
8
8
|
export { transcribeQueue } from "./transcribe.js";
|
|
9
9
|
export { fitMap, toView, boxWords, frameTag, labelColour } from "./frame.js";
|
|
10
10
|
export { traceRows, inspectorHtml } from "./memory.js";
|
|
11
|
+
export { jobLoader, asImage, RUNTIME_URLS } from "./loaders.js";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jobLoader: the real loader of a pick. Pass it to `useModelPick(job, {
|
|
3
|
+
* loader: jobLoader(job) })` and a load fetches the runtime (transformers.js,
|
|
4
|
+
* onnxruntime web, WebLLM, wllama, MediaPipe, a voice) from its pinned CDN
|
|
5
|
+
* only when the person presses load, fetches the weights through
|
|
6
|
+
* @hackbuild/weights where the runtime does not fetch its own, and resolves
|
|
7
|
+
* to the object a page uses for that job. Nothing loads at import.
|
|
8
|
+
*
|
|
9
|
+
* One models hub is shared by every jobLoader made with the same options
|
|
10
|
+
* object (or with none), so a model loaded for one view is reused by the next
|
|
11
|
+
* and webgpu work takes one gpu lock.
|
|
12
|
+
*/
|
|
13
|
+
import { type Env } from "@hackbuild/ai-env";
|
|
14
|
+
import type { ChatEngine } from "@hackbuild/chat";
|
|
15
|
+
import type { Dsp } from "@hackbuild/audio-dsp";
|
|
16
|
+
import type { OrtModule, TjsModule } from "@hackbuild/devices";
|
|
17
|
+
import type { Embedder } from "@hackbuild/embed";
|
|
18
|
+
import type { ClipTokenize, FormOptions, ImageGenerator } from "@hackbuild/imagegen";
|
|
19
|
+
import type { Engine } from "@hackbuild/speak";
|
|
20
|
+
import type { WeightStore } from "@hackbuild/weights";
|
|
21
|
+
import { type Job } from "./jobs.js";
|
|
22
|
+
import type { FrameBox } from "./frame.js";
|
|
23
|
+
import type { MaskModels } from "./mount-mask.js";
|
|
24
|
+
import type { Loader } from "./pick.js";
|
|
25
|
+
import type { Transcriber } from "./transcribe.js";
|
|
26
|
+
/** Pinned CDN modules jobLoader imports at load time. */
|
|
27
|
+
export declare const RUNTIME_URLS: {
|
|
28
|
+
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"];
|
|
29
|
+
readonly bellows: readonly ["https://cdn.jsdelivr.net/npm/bellows-voice@0.8.0/engine/+esm"];
|
|
30
|
+
readonly kokoro: readonly ["https://cdn.jsdelivr.net/npm/kokoro-js@1.2.1/+esm"];
|
|
31
|
+
};
|
|
32
|
+
/** The runtime modules, each a function that imports it. Tests pass fakes; a page leaves them out. */
|
|
33
|
+
export interface RuntimeModules {
|
|
34
|
+
transformers?: () => Promise<TjsModule>;
|
|
35
|
+
ort?: () => Promise<OrtModule>;
|
|
36
|
+
webllm?: () => Promise<unknown>;
|
|
37
|
+
wllama?: () => Promise<unknown>;
|
|
38
|
+
tasksVision?: () => Promise<unknown>;
|
|
39
|
+
kokoro?: () => Promise<unknown>;
|
|
40
|
+
bellows?: () => Promise<unknown>;
|
|
41
|
+
/** The audio dsp core transcription runs on; default the wasm inlined in @hackbuild/audio-dsp. */
|
|
42
|
+
dsp?: () => Promise<Dsp>;
|
|
43
|
+
}
|
|
44
|
+
/** Options for {@link jobLoader}. Share one object between loaders to share one hub. */
|
|
45
|
+
export interface JobLoaderOptions {
|
|
46
|
+
/** Where weights are kept; default `openWeightStore()`. */
|
|
47
|
+
store?: WeightStore | Promise<WeightStore>;
|
|
48
|
+
/** This machine; default `probe()` from @hackbuild/ai-env. */
|
|
49
|
+
env?: Env;
|
|
50
|
+
/** Runtime modules in place of the pinned CDN imports (tests). */
|
|
51
|
+
modules?: RuntimeModules;
|
|
52
|
+
/** Kokoro's phonemizer is GPL-3.0-or-later; it is fetched only when this is true. */
|
|
53
|
+
allowGplPhonemizer?: boolean;
|
|
54
|
+
/** fetch for files a runtime does not fetch itself (static embedders). */
|
|
55
|
+
fetch?: typeof fetch;
|
|
56
|
+
/** Random numbers for the bellows voice; default a fixed seed. */
|
|
57
|
+
rng?: () => number;
|
|
58
|
+
}
|
|
59
|
+
/** A detector as a page calls it: boxes in image pixels, best first. */
|
|
60
|
+
export type DetectFn = (image: unknown) => Promise<FrameBox[]>;
|
|
61
|
+
/** A depth model as a page calls it: 0 to 1 per pixel, larger is nearer (relative inverse depth). */
|
|
62
|
+
export type DepthFn = (image: unknown) => Promise<{
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
data: Float32Array;
|
|
66
|
+
}>;
|
|
67
|
+
/** A vision language model as a page calls it: a question about an image (a caption without one), answered in words. */
|
|
68
|
+
export type AskFn = (image: unknown, question?: string) => Promise<string>;
|
|
69
|
+
/** An image model with its CLIP tokenizer: `make` generates with the form's defaults filled in. */
|
|
70
|
+
export type ImageJob = ImageGenerator & {
|
|
71
|
+
tokenize: ClipTokenize;
|
|
72
|
+
make(o: FormOptions): ReturnType<ImageGenerator["generate"]>;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* What a jobLoader load resolves to, per job: chat a ChatEngine; transcribe a
|
|
76
|
+
* Transcriber; detect a DetectFn; masks MaskModels; depth a DepthFn; vision an
|
|
77
|
+
* AskFn; image an ImageJob; voice a loaded @hackbuild/speak Engine; embed an
|
|
78
|
+
* Embedder. faceswap and landmarks resolve to the hub's loaded value as is.
|
|
79
|
+
*/
|
|
80
|
+
export interface JobValues {
|
|
81
|
+
chat: ChatEngine;
|
|
82
|
+
transcribe: Transcriber;
|
|
83
|
+
detect: DetectFn;
|
|
84
|
+
masks: MaskModels;
|
|
85
|
+
depth: DepthFn;
|
|
86
|
+
vision: AskFn;
|
|
87
|
+
image: ImageJob;
|
|
88
|
+
voice: Engine;
|
|
89
|
+
embed: Embedder;
|
|
90
|
+
faceswap: unknown;
|
|
91
|
+
landmarks: unknown;
|
|
92
|
+
}
|
|
93
|
+
/** Pixels ({ width, height, data }) as a canvas, which every runtime reads; anything else passes through. */
|
|
94
|
+
export declare function asImage(img: unknown): unknown;
|
|
95
|
+
/**
|
|
96
|
+
* A real Loader for a job. The runtime and weights load only when a pick
|
|
97
|
+
* calls it; progress goes to `ctx.onProgress`, `ctx.signal` stops it, and a
|
|
98
|
+
* failure throws in plain words. Resolves to {@link JobValues}[job].
|
|
99
|
+
*/
|
|
100
|
+
export declare function jobLoader<J extends Job>(job: J, o?: JobLoaderOptions): Loader;
|
package/dist/loaders.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jobLoader: the real loader of a pick. Pass it to `useModelPick(job, {
|
|
3
|
+
* loader: jobLoader(job) })` and a load fetches the runtime (transformers.js,
|
|
4
|
+
* onnxruntime web, WebLLM, wllama, MediaPipe, a voice) from its pinned CDN
|
|
5
|
+
* only when the person presses load, fetches the weights through
|
|
6
|
+
* @hackbuild/weights where the runtime does not fetch its own, and resolves
|
|
7
|
+
* to the object a page uses for that job. Nothing loads at import.
|
|
8
|
+
*
|
|
9
|
+
* One models hub is shared by every jobLoader made with the same options
|
|
10
|
+
* object (or with none), so a model loaded for one view is reused by the next
|
|
11
|
+
* and webgpu work takes one gpu lock.
|
|
12
|
+
*/
|
|
13
|
+
import { importEsm, probe } from "@hackbuild/ai-env";
|
|
14
|
+
import { createHub, createRegistry } from "@hackbuild/models";
|
|
15
|
+
import { hfResolve } from "@hackbuild/weights";
|
|
16
|
+
import { ALL_RECORDS } from "./jobs.js";
|
|
17
|
+
/** Pinned CDN modules jobLoader imports at load time. */
|
|
18
|
+
export const RUNTIME_URLS = {
|
|
19
|
+
webllm: ["https://esm.run/@mlc-ai/web-llm@0.2.84", "https://cdn.jsdelivr.net/npm/@mlc-ai/web-llm@0.2.84/+esm"],
|
|
20
|
+
bellows: ["https://cdn.jsdelivr.net/npm/bellows-voice@0.8.0/engine/+esm"],
|
|
21
|
+
kokoro: ["https://cdn.jsdelivr.net/npm/kokoro-js@1.2.1/+esm"],
|
|
22
|
+
};
|
|
23
|
+
const DEFAULT = {};
|
|
24
|
+
/** Lines a factory throws that already say what to do; they reach the row as they are. */
|
|
25
|
+
const PLAIN = {
|
|
26
|
+
kokoro: "kokoro's phonemizer is gpl. pass allowGplPhonemizer: true to load it, or pick another voice.",
|
|
27
|
+
promptApi: "this browser has no built in model. use chrome with the prompt api on.",
|
|
28
|
+
};
|
|
29
|
+
/** Rejects as soon as the signal aborts, whether or not the work below it stops. */
|
|
30
|
+
function untilAbort(p, signal) {
|
|
31
|
+
if (signal.aborted)
|
|
32
|
+
return Promise.reject(new DOMException("stopped", "AbortError"));
|
|
33
|
+
return new Promise((ok, bad) => {
|
|
34
|
+
const stop = () => bad(new DOMException("stopped", "AbortError"));
|
|
35
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
36
|
+
p.then(ok, bad).finally(() => signal.removeEventListener("abort", stop));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const runtimes = new WeakMap();
|
|
40
|
+
/** The licence of the record a weight url belongs to, for the store's licence line. */
|
|
41
|
+
function licenceFor(url) {
|
|
42
|
+
for (const r of ALL_RECORDS) {
|
|
43
|
+
const id = r.source.modelId ?? r.source.repo;
|
|
44
|
+
if ((id && url.includes(`/${id}/`)) || (r.source.url && url.startsWith(r.source.url)))
|
|
45
|
+
return r.licence;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
async function makeRuntime(o) {
|
|
50
|
+
const [{ loadOrt, loadTransformers, ortProvider, runtimeLoader, tjsProvider }, { openWeightStore, transformersCache }] = await Promise.all([import("@hackbuild/devices"), import("@hackbuild/weights")]);
|
|
51
|
+
const [env, store] = await Promise.all([o.env ?? probe(), o.store ?? openWeightStore()]);
|
|
52
|
+
const hub = createHub({ registry: createRegistry(ALL_RECORDS), env });
|
|
53
|
+
const m = o.modules ?? {};
|
|
54
|
+
const rt = { hub, store, modules: m, tokenizers: new Map() };
|
|
55
|
+
const tjsModule = m.transformers ?? loadTransformers();
|
|
56
|
+
const tjs = tjsProvider({ runtime: tjsModule, cache: transformersCache(store, { licenceFor }) });
|
|
57
|
+
const [vision, chatTjs, embed] = await Promise.all([import("@hackbuild/vision"), import("@hackbuild/chat/transformers"), import("@hackbuild/embed")]);
|
|
58
|
+
tjs.loader("depth", vision.depthLoader);
|
|
59
|
+
tjs.loader("vision.caption", vision.vlmLoader);
|
|
60
|
+
tjs.loader("vision.ask", vision.vlmLoader);
|
|
61
|
+
tjs.loader("segment", vision.samLoader);
|
|
62
|
+
tjs.loader("chat", async (ctx) => {
|
|
63
|
+
const { createEngine } = await import("@hackbuild/chat");
|
|
64
|
+
const generator = await ctx.tjs.pipeline("text-generation", ctx.record.source.modelId ?? ctx.record.id, ctx.options);
|
|
65
|
+
const driver = chatTjs.transformersDriver({ module: ctx.tjs, generator: generator, id: ctx.record.id });
|
|
66
|
+
return createEngine(driver, ctx.record.quirks?.systemRole === false ? { quirks: { systemRole: false } } : {});
|
|
67
|
+
});
|
|
68
|
+
// the embed loaders: transformers.js feature extraction, and the static (potion) files through fetch
|
|
69
|
+
embed.attachEmbed(hub, tjs, o.fetch ? { fetch: o.fetch } : {});
|
|
70
|
+
hub.provide("tjs", tjs.factory);
|
|
71
|
+
hub.provide("ort", ortProvider({ runtime: m.ort ?? loadOrt(), store }).factory);
|
|
72
|
+
hub.provide("mediapipe", vision.mediapipeProvider({ runtime: (m.tasksVision ?? vision.loadTasksVision()), store }));
|
|
73
|
+
hub.provide("webllm", (ctx) => webllmFactory(ctx, m));
|
|
74
|
+
hub.provide("wllama", (ctx) => wllamaFactory(ctx, rt));
|
|
75
|
+
hub.provide("prompt-api", async () => {
|
|
76
|
+
const p = await import("@hackbuild/chat/prompt-api");
|
|
77
|
+
if (!p.getLanguageModel())
|
|
78
|
+
throw new Error(PLAIN.promptApi);
|
|
79
|
+
return p.promptApi();
|
|
80
|
+
});
|
|
81
|
+
const voice = (make) => async (ctx) => {
|
|
82
|
+
const e = make(await import("@hackbuild/speak"));
|
|
83
|
+
await e.load({ ...(ctx.signal ? { signal: ctx.signal } : {}), onStatus: (s) => { if (s.progress !== undefined)
|
|
84
|
+
ctx.report("fetch", s.progress); } });
|
|
85
|
+
return e;
|
|
86
|
+
};
|
|
87
|
+
hub.provide("system", voice((s) => s.webSpeechEngine()));
|
|
88
|
+
hub.provide("pocket-worker", voice((s) => s.pocketEngine({})));
|
|
89
|
+
hub.provide("bellows-voice", voice((s) => s.bellowsEngine({ runtime: (m.bellows ?? runtimeLoader([...RUNTIME_URLS.bellows])), rng: o.rng ?? seeded(1) })));
|
|
90
|
+
hub.provide("kokoro-js", async (ctx) => {
|
|
91
|
+
if (!o.allowGplPhonemizer)
|
|
92
|
+
throw new Error(PLAIN.kokoro);
|
|
93
|
+
return voice((s) => s.kokoroEngine({ runtime: (m.kokoro ?? runtimeLoader([...RUNTIME_URLS.kokoro])), allowGplPhonemizer: true }))(ctx);
|
|
94
|
+
});
|
|
95
|
+
return rt;
|
|
96
|
+
}
|
|
97
|
+
async function webllmFactory(ctx, m) {
|
|
98
|
+
const w = await import("@hackbuild/chat/webllm");
|
|
99
|
+
const mod = (await (m.webllm ?? (() => importEsm(RUNTIME_URLS.webllm)))());
|
|
100
|
+
const id = ctx.record.source.modelId ?? ctx.record.id;
|
|
101
|
+
return w.loadWebLLM({
|
|
102
|
+
module: mod,
|
|
103
|
+
modelId: id,
|
|
104
|
+
contextWindow: ctx.record.ctx ?? 4096,
|
|
105
|
+
nativeTools: /hermes/i.test(id),
|
|
106
|
+
onProgress: (p) => {
|
|
107
|
+
const ph = w.webllmPhase(p);
|
|
108
|
+
if (ph.phase !== "ready")
|
|
109
|
+
ctx.report(ph.phase, ph.fraction, ph.file);
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async function wllamaFactory(ctx, rt) {
|
|
114
|
+
const { repo, file } = ctx.record.source;
|
|
115
|
+
if (!repo || !file)
|
|
116
|
+
throw new Error(`${ctx.record.id} names no gguf repo and file.`);
|
|
117
|
+
const w = await import("@hackbuild/chat/wllama");
|
|
118
|
+
const url = hfResolve(repo, ctx.record.source.revision ?? "main") + file;
|
|
119
|
+
const blob = await rt.store.get({ url, key: `gguf:${repo}/${file}`, licence: ctx.record.licence, ...(ctx.record.source.sha256 ? { sha256: ctx.record.source.sha256 } : {}) }, { ...(ctx.signal ? { signal: ctx.signal } : {}), onProgress: (p) => ctx.report("fetch", p.fraction) });
|
|
120
|
+
ctx.report("compile", null);
|
|
121
|
+
const urls = w.wllamaUrls();
|
|
122
|
+
const module = (await (rt.modules.wllama ?? (() => importEsm(urls.esm)))());
|
|
123
|
+
return w.loadWllama({ module, wasmUrl: urls.wasm, blobs: [blob], id: ctx.record.id, ...(ctx.record.ctx ? { nCtx: ctx.record.ctx } : {}) });
|
|
124
|
+
}
|
|
125
|
+
/** A small seeded random source (mulberry32), so no Math.random runs in library code. */
|
|
126
|
+
function seeded(seed) {
|
|
127
|
+
let a = seed >>> 0;
|
|
128
|
+
return () => {
|
|
129
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
130
|
+
let t = a;
|
|
131
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
132
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
133
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** Pixels ({ width, height, data }) as a canvas, which every runtime reads; anything else passes through. */
|
|
137
|
+
export function asImage(img) {
|
|
138
|
+
const p = img;
|
|
139
|
+
if (!p || typeof p !== "object" || p.getContext || !p.data || !p.width || !p.height || typeof document === "undefined")
|
|
140
|
+
return img;
|
|
141
|
+
const c = document.createElement("canvas");
|
|
142
|
+
c.width = p.width;
|
|
143
|
+
c.height = p.height;
|
|
144
|
+
c.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(p.data), p.width, p.height), 0, 0);
|
|
145
|
+
return c;
|
|
146
|
+
}
|
|
147
|
+
/** A file as 16 kHz mono samples, decoded by the browser. */
|
|
148
|
+
async function pcm16k(file) {
|
|
149
|
+
const bytes = await file.arrayBuffer();
|
|
150
|
+
const probeCtx = new OfflineAudioContext(1, 1, 16000);
|
|
151
|
+
const buf = await probeCtx.decodeAudioData(bytes);
|
|
152
|
+
const off = new OfflineAudioContext(1, Math.max(1, Math.ceil(buf.duration * 16000)), 16000);
|
|
153
|
+
const src = off.createBufferSource();
|
|
154
|
+
src.buffer = buf;
|
|
155
|
+
src.connect(off.destination);
|
|
156
|
+
src.start();
|
|
157
|
+
return (await off.startRendering()).getChannelData(0);
|
|
158
|
+
}
|
|
159
|
+
async function dspOf(rt) {
|
|
160
|
+
rt.dsp ??= rt.modules.dsp
|
|
161
|
+
? rt.modules.dsp()
|
|
162
|
+
: Promise.all([import("@hackbuild/audio-dsp"), import("@hackbuild/audio-dsp/inline")]).then(([a, i]) => a.loadDsp({ base64: i.AUDIO_DSP_WASM_BASE64 }));
|
|
163
|
+
return rt.dsp;
|
|
164
|
+
}
|
|
165
|
+
async function clipTokenizer(rt, id) {
|
|
166
|
+
let p = rt.tokenizers.get(id);
|
|
167
|
+
if (!p) {
|
|
168
|
+
p = (async () => {
|
|
169
|
+
const load = rt.modules.transformers ?? (await import("@hackbuild/devices")).loadTransformers();
|
|
170
|
+
const tjs = (await load());
|
|
171
|
+
const tok = await tjs.AutoTokenizer.from_pretrained(id);
|
|
172
|
+
return async (text) => Int32Array.from((await tok(text, { padding: "max_length", max_length: 77, truncation: true })).input_ids.data, (v) => Number(v));
|
|
173
|
+
})();
|
|
174
|
+
p.catch(() => rt.tokenizers.delete(id));
|
|
175
|
+
rt.tokenizers.set(id, p);
|
|
176
|
+
}
|
|
177
|
+
return p;
|
|
178
|
+
}
|
|
179
|
+
/** Points on a 4 by 3 grid, for segment everything with a point prompted model. */
|
|
180
|
+
const GRID = [0.2, 0.4, 0.6, 0.8].flatMap((x) => [0.25, 0.5, 0.75].map((y) => ({ x, y })));
|
|
181
|
+
async function adapt(job, rec, value, rt, ctx) {
|
|
182
|
+
const hub = rt.hub;
|
|
183
|
+
const vision = () => import("@hackbuild/vision");
|
|
184
|
+
switch (job) {
|
|
185
|
+
case "transcribe": {
|
|
186
|
+
const t = await import("@hackbuild/transcribe");
|
|
187
|
+
const run = async (file, c) => {
|
|
188
|
+
const [dsp, pcm] = await Promise.all([dspOf(rt), pcm16k(file)]);
|
|
189
|
+
const lang = ctx.options.language;
|
|
190
|
+
const out = await t.transcribe(hub, dsp, pcm, {
|
|
191
|
+
model: rec.id,
|
|
192
|
+
signal: c.signal,
|
|
193
|
+
...(lang ? { language: lang } : {}),
|
|
194
|
+
onProgress: (p) => c.onProgress(p.total ? p.done / p.total : 0),
|
|
195
|
+
});
|
|
196
|
+
return { segments: out.segments, dropped: out.dropped, duration: out.stats.dur, language: out.language, model: rec.label ?? rec.id };
|
|
197
|
+
};
|
|
198
|
+
return run;
|
|
199
|
+
}
|
|
200
|
+
case "detect": {
|
|
201
|
+
const v = await vision();
|
|
202
|
+
const fn = async (image) => (await v.detect(hub, asImage(image), { model: rec.id })).map((d) => ({ label: d.label, score: d.score, x: d.box.x, y: d.box.y, w: d.box.w, h: d.box.h }));
|
|
203
|
+
return fn;
|
|
204
|
+
}
|
|
205
|
+
case "depth": {
|
|
206
|
+
const v = await vision();
|
|
207
|
+
const fn = (image) => v.depth(hub, asImage(image), { model: rec.id });
|
|
208
|
+
return fn;
|
|
209
|
+
}
|
|
210
|
+
case "vision": {
|
|
211
|
+
const v = await vision();
|
|
212
|
+
const fn = (image, question) => (question ? v.ask(hub, asImage(image), question, { model: rec.id }) : v.caption(hub, asImage(image), { model: rec.id }));
|
|
213
|
+
return fn;
|
|
214
|
+
}
|
|
215
|
+
case "masks": {
|
|
216
|
+
const v = await vision();
|
|
217
|
+
let key = 0;
|
|
218
|
+
const keys = new WeakMap();
|
|
219
|
+
const keyOf = (img) => keys.get(img) ?? (keys.set(img, `img-${++key}`), `img-${key}`);
|
|
220
|
+
const first = async (image, x, y) => (await v.segment(hub, asImage(image), { points: [{ x, y, label: 1 }] }, { model: rec.id, key: keyOf(image) }))[0];
|
|
221
|
+
const models = {
|
|
222
|
+
segment: async (image, p) => (await first(image, p.x, p.y))?.data ?? null,
|
|
223
|
+
everything: async (image) => {
|
|
224
|
+
const out = [];
|
|
225
|
+
for (const g of GRID) {
|
|
226
|
+
const m = await first(image, g.x * image.width, g.y * image.height);
|
|
227
|
+
if (!m || out.some((o) => overlap(o.mask, m.data) > 0.6))
|
|
228
|
+
continue;
|
|
229
|
+
out.push({ mask: m.data, label: `object ${out.length + 1}`, score: m.score ?? 0 });
|
|
230
|
+
}
|
|
231
|
+
return out;
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
return models;
|
|
235
|
+
}
|
|
236
|
+
case "image": {
|
|
237
|
+
const g = await import("@hackbuild/imagegen");
|
|
238
|
+
const gen = await g.loadImagegen(hub, { id: rec.id }, { ...(ctx.signal ? { signal: ctx.signal } : {}) });
|
|
239
|
+
const tokenize = await clipTokenizer(rt, gen.form.tokenizer);
|
|
240
|
+
const job = Object.assign(gen, { tokenize, make: (o) => gen.generate(tokenize, o) });
|
|
241
|
+
return job;
|
|
242
|
+
}
|
|
243
|
+
default:
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/** Shared area over the smaller area of two 0 or 255 masks of one size. */
|
|
248
|
+
function overlap(a, b) {
|
|
249
|
+
let both = 0;
|
|
250
|
+
let na = 0;
|
|
251
|
+
let nb = 0;
|
|
252
|
+
for (let i = 0; i < a.length; i++) {
|
|
253
|
+
const x = a[i] > 127;
|
|
254
|
+
const y = b[i] > 127;
|
|
255
|
+
if (x)
|
|
256
|
+
na++;
|
|
257
|
+
if (y)
|
|
258
|
+
nb++;
|
|
259
|
+
if (x && y)
|
|
260
|
+
both++;
|
|
261
|
+
}
|
|
262
|
+
return both / Math.max(1, Math.min(na, nb));
|
|
263
|
+
}
|
|
264
|
+
/** Records jobLoader cannot run yet, with the words a row shows. */
|
|
265
|
+
const NOT_YET = {
|
|
266
|
+
"fastsam-s": "fastsam needs its own decoder, which this loader does not have yet. pick slimsam.",
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* A real Loader for a job. The runtime and weights load only when a pick
|
|
270
|
+
* calls it; progress goes to `ctx.onProgress`, `ctx.signal` stops it, and a
|
|
271
|
+
* failure throws in plain words. Resolves to {@link JobValues}[job].
|
|
272
|
+
*/
|
|
273
|
+
export function jobLoader(job, o = {}) {
|
|
274
|
+
const key = Object.keys(o).length ? o : DEFAULT;
|
|
275
|
+
return async (rec, ctx) => {
|
|
276
|
+
if (NOT_YET[rec.id])
|
|
277
|
+
throw new Error(NOT_YET[rec.id]);
|
|
278
|
+
let rt = runtimes.get(key);
|
|
279
|
+
if (!rt) {
|
|
280
|
+
rt = makeRuntime(o);
|
|
281
|
+
runtimes.set(key, rt);
|
|
282
|
+
rt.catch(() => runtimes.delete(key));
|
|
283
|
+
}
|
|
284
|
+
const r = await rt;
|
|
285
|
+
if (!r.hub.registry.get(rec.id))
|
|
286
|
+
r.hub.registry.add(rec);
|
|
287
|
+
const off = r.hub.onLoad((e) => {
|
|
288
|
+
if (e.id === rec.id && (e.phase === "fetch" || e.phase === "compile" || e.phase === "warm"))
|
|
289
|
+
ctx.onProgress(e.fraction);
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
// an image model loads through loadImagegen, which takes its own lease
|
|
293
|
+
const run = async () => adapt(job, rec, job === "image" ? null : (await r.hub.use({ id: rec.id }, { signal: ctx.signal })).value, r, ctx);
|
|
294
|
+
return await untilAbort(run(), ctx.signal);
|
|
295
|
+
}
|
|
296
|
+
catch (e) {
|
|
297
|
+
if (ctx.signal.aborted)
|
|
298
|
+
throw e;
|
|
299
|
+
const failures = e?.failures ?? e?.cause?.failures ?? [];
|
|
300
|
+
const said = [String(e?.message ?? e), ...failures.map((f) => f.error)].join(" ");
|
|
301
|
+
const plain = Object.values(PLAIN).find((l) => said.includes(l));
|
|
302
|
+
throw new Error(plain ?? (await import("@hackbuild/devices")).humanError("model", e));
|
|
303
|
+
}
|
|
304
|
+
finally {
|
|
305
|
+
off();
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
package/dist/mount-model.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type ModelRow } from "@virgilvox/hackbuild-ui/vanilla";
|
|
8
8
|
import { type Mounted } from "./dom.js";
|
|
9
|
-
import type { JobsPick, ModelPick } from "./pick.js";
|
|
9
|
+
import type { JobsPick, ModelPick, PickSnapshot } from "./pick.js";
|
|
10
10
|
/** The sheet of one pick, in a drawer on the body. Opens on `open()`. */
|
|
11
11
|
export declare function pickSheet(pick: ModelPick): Mounted & {
|
|
12
12
|
open(): void;
|
|
@@ -18,6 +18,15 @@ export interface ModelSelectOptions {
|
|
|
18
18
|
/** Draw the pink load. Off on a gate, whose own button is the pink action. */
|
|
19
19
|
go?: boolean;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A model name cut for the bar chip: filler words (instruct, chat, quant tags)
|
|
23
|
+
* go, and a name of more than three words keeps its first two and its last,
|
|
24
|
+
* which is usually the size: "hermes 3 llama 3.2 3b" reads "hermes 3 3b".
|
|
25
|
+
* A note in brackets goes first: "slimsam 77 uniform (point prompts)" reads "slimsam 77".
|
|
26
|
+
*/
|
|
27
|
+
export declare function shortName(name: string): string;
|
|
28
|
+
/** The chip's words: the short name, then the download size, or the state once it moves. */
|
|
29
|
+
export declare function chipWords(s: PickSnapshot): string;
|
|
21
30
|
/** The closed picker over a host; pressing it opens the sheet. */
|
|
22
31
|
export declare function mountModelSelect(host: HTMLElement, pick: ModelPick, o?: ModelSelectOptions): Mounted;
|
|
23
32
|
/** The words of a gate's one pink button for a pick: "load, 1.7 gb", then "ready". */
|
package/dist/mount-model.js
CHANGED
|
@@ -39,9 +39,29 @@ export function pickSheet(pick) {
|
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
// words a model name carries that say nothing to a person choosing it
|
|
43
|
+
const FILLER = /^(instruct|chat|it|mlc|onnx|gguf|hf|q\d\w*|f16|f32|fp16|int8|bf16|uniform)$/i;
|
|
44
|
+
/**
|
|
45
|
+
* A model name cut for the bar chip: filler words (instruct, chat, quant tags)
|
|
46
|
+
* go, and a name of more than three words keeps its first two and its last,
|
|
47
|
+
* which is usually the size: "hermes 3 llama 3.2 3b" reads "hermes 3 3b".
|
|
48
|
+
* A note in brackets goes first: "slimsam 77 uniform (point prompts)" reads "slimsam 77".
|
|
49
|
+
*/
|
|
50
|
+
export function shortName(name) {
|
|
51
|
+
const w = name.replace(/\s*\([^)]*\)/g, "").split(/\s+/).filter((x) => x && !FILLER.test(x));
|
|
52
|
+
const kept = w.length > 3 ? [w[0], w[1], w[w.length - 1]] : w;
|
|
53
|
+
return kept.join(" ") || name;
|
|
54
|
+
}
|
|
55
|
+
/** The chip's words: the short name, then the download size, or the state once it moves. */
|
|
56
|
+
export function chipWords(s) {
|
|
57
|
+
const r = s.row;
|
|
58
|
+
if (!r)
|
|
59
|
+
return s.empty;
|
|
60
|
+
const w = lineWords(r, s.empty);
|
|
61
|
+
const name = shortName(r.name);
|
|
62
|
+
if ((r.state === "loading" || r.state === "loaded" || r.state === "error") && w.state)
|
|
63
|
+
return `${name}, ${w.state}`;
|
|
64
|
+
return `${name}, ${r.noDownload ? "no download" : r.size ?? "size unknown"}`;
|
|
45
65
|
}
|
|
46
66
|
/** The closed picker over a host; pressing it opens the sheet. */
|
|
47
67
|
export function mountModelSelect(host, pick, o = {}) {
|
|
@@ -51,7 +71,8 @@ export function mountModelSelect(host, pick, o = {}) {
|
|
|
51
71
|
if (o.variant === "chip") {
|
|
52
72
|
const draw = (s) => {
|
|
53
73
|
const words = chipWords(s);
|
|
54
|
-
|
|
74
|
+
const full = s.row ? `model: ${s.row.name}${s.row.size ? `, ${s.row.size}` : ""}${lineWords(s.row, s.empty).state ? `, ${lineWords(s.row, s.empty).state}` : ""}` : `model: ${s.empty}`;
|
|
75
|
+
host.innerHTML = `<button type="button" class="hb-msel-chip${s.row?.state ? ` is-${s.row.state}` : ""}" aria-haspopup="dialog" aria-label="${esc(full)}" title="${esc(full)}"><span>${esc(words)}</span></button>`;
|
|
55
76
|
};
|
|
56
77
|
l.on(host, "click", (e) => {
|
|
57
78
|
if (e.target.closest(".hb-msel-chip"))
|
|
@@ -8722,9 +8722,29 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8722
8722
|
}
|
|
8723
8723
|
};
|
|
8724
8724
|
}
|
|
8725
|
+
const FILLER = /^(instruct|chat|it|mlc|onnx|gguf|hf|q\d\w*|f16|f32|fp16|int8|bf16|uniform)$/i;
|
|
8726
|
+
/**
|
|
8727
|
+
* A model name cut for the bar chip: filler words (instruct, chat, quant tags)
|
|
8728
|
+
* go, and a name of more than three words keeps its first two and its last,
|
|
8729
|
+
* which is usually the size: "hermes 3 llama 3.2 3b" reads "hermes 3 3b".
|
|
8730
|
+
* A note in brackets goes first: "slimsam 77 uniform (point prompts)" reads "slimsam 77".
|
|
8731
|
+
*/
|
|
8732
|
+
function shortName(name) {
|
|
8733
|
+
const w = name.replace(/\s*\([^)]*\)/g, "").split(/\s+/).filter((x) => x && !FILLER.test(x));
|
|
8734
|
+
return (w.length > 3 ? [
|
|
8735
|
+
w[0],
|
|
8736
|
+
w[1],
|
|
8737
|
+
w[w.length - 1]
|
|
8738
|
+
] : w).join(" ") || name;
|
|
8739
|
+
}
|
|
8740
|
+
/** The chip's words: the short name, then the download size, or the state once it moves. */
|
|
8725
8741
|
function chipWords(s) {
|
|
8726
|
-
const
|
|
8727
|
-
|
|
8742
|
+
const r = s.row;
|
|
8743
|
+
if (!r) return s.empty;
|
|
8744
|
+
const w = $r(r, s.empty);
|
|
8745
|
+
const name = shortName(r.name);
|
|
8746
|
+
if ((r.state === "loading" || r.state === "loaded" || r.state === "error") && w.state) return `${name}, ${w.state}`;
|
|
8747
|
+
return `${name}, ${r.noDownload ? "no download" : r.size ?? "size unknown"}`;
|
|
8728
8748
|
}
|
|
8729
8749
|
/** The closed picker over a host; pressing it opens the sheet. */
|
|
8730
8750
|
function mountModelSelect(host, pick, o = {}) {
|
|
@@ -8734,7 +8754,8 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8734
8754
|
if (o.variant === "chip") {
|
|
8735
8755
|
const draw = (s) => {
|
|
8736
8756
|
const words = chipWords(s);
|
|
8737
|
-
|
|
8757
|
+
const full = s.row ? `model: ${s.row.name}${s.row.size ? `, ${s.row.size}` : ""}${$r(s.row, s.empty).state ? `, ${$r(s.row, s.empty).state}` : ""}` : `model: ${s.empty}`;
|
|
8758
|
+
host.innerHTML = `<button type="button" class="hb-msel-chip${s.row?.state ? ` is-${s.row.state}` : ""}" aria-haspopup="dialog" aria-label="${esc(full)}" title="${esc(full)}"><span>${esc(words)}</span></button>`;
|
|
8738
8759
|
};
|
|
8739
8760
|
l.on(host, "click", (e) => {
|
|
8740
8761
|
if (e.target.closest(".hb-msel-chip")) sheet.open();
|
|
@@ -9573,6 +9594,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
9573
9594
|
});
|
|
9574
9595
|
}
|
|
9575
9596
|
exports.ELEMENT_NAMES = ELEMENT_NAMES;
|
|
9597
|
+
exports.chipWords = chipWords;
|
|
9576
9598
|
exports.define = define;
|
|
9577
9599
|
exports.gateWords = gateWords;
|
|
9578
9600
|
exports.mountCameraFeed = mountCameraFeed;
|
|
@@ -9593,6 +9615,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
9593
9615
|
exports.mountTranscriptExports = mountTranscriptExports;
|
|
9594
9616
|
exports.mountTranscriptView = mountTranscriptView;
|
|
9595
9617
|
exports.pickSheet = pickSheet;
|
|
9618
|
+
exports.shortName = shortName;
|
|
9596
9619
|
exports.transcriptHtml = transcriptHtml;
|
|
9597
9620
|
exports.turnHtml = turnHtml;
|
|
9598
9621
|
return exports;
|