@hackbuild/ai-views 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +241 -2
- package/dist/chat.d.ts +107 -0
- package/dist/chat.js +243 -0
- package/dist/dom.d.ts +38 -0
- package/dist/dom.js +67 -0
- package/dist/elements.d.ts +48 -0
- package/dist/elements.js +378 -0
- package/dist/frame.d.ts +57 -0
- package/dist/frame.js +40 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +10 -0
- package/dist/jobs.d.ts +31 -0
- package/dist/jobs.js +52 -0
- package/dist/memory.d.ts +35 -0
- package/dist/memory.js +39 -0
- package/dist/mount-chat.d.ts +41 -0
- package/dist/mount-chat.js +178 -0
- package/dist/mount-frame.d.ts +57 -0
- package/dist/mount-frame.js +239 -0
- package/dist/mount-mask.d.ts +127 -0
- package/dist/mount-mask.js +450 -0
- package/dist/mount-model.d.ts +28 -0
- package/dist/mount-model.js +122 -0
- package/dist/mount-transcribe.d.ts +51 -0
- package/dist/mount-transcribe.js +203 -0
- package/dist/pick.d.ts +149 -0
- package/dist/pick.js +260 -0
- package/dist/rows.d.ts +42 -0
- package/dist/rows.js +149 -0
- package/dist/single/elements.iife.js +9599 -0
- package/dist/single/elements.js +9573 -0
- package/dist/single/index.iife.js +6843 -0
- package/dist/single/index.js +6807 -0
- package/dist/single/vue.iife.js +11376 -0
- package/dist/single/vue.js +11359 -0
- package/dist/transcribe.d.ts +92 -0
- package/dist/transcribe.js +175 -0
- package/dist/vue.d.ts +281 -0
- package/dist/vue.js +221 -0
- package/how.ts +26 -0
- package/llms.md +1133 -0
- package/package.json +62 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Moheeb Zara
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,242 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hackbuild/ai-views
|
|
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
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@hackbuild/ai-views) [](../../LICENSE)  
|
|
6
|
+
|
|
7
|
+
Browser status: no model run of this package has been verified in a real browser yet.
|
|
8
|
+
|
|
9
|
+
## What it does
|
|
10
|
+
|
|
11
|
+
- 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.
|
|
12
|
+
- Keeps the state behind every view in node safe objects: a pick, a jobs rack, a chat thread and list, a transcribe queue.
|
|
13
|
+
- Draws the views in light DOM with the page's hackbuild-ui stylesheet and never styles locally.
|
|
14
|
+
- Ships every view as a mount function, a custom element and a Vue 3 component, all on one code path.
|
|
15
|
+
- Replaces @hackbuild/ai-elements.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @hackbuild/ai-views @virgilvox/hackbuild-ui
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
@virgilvox/hackbuild-ui is a required peer; the page also loads its stylesheet. Vue is an optional peer, needed only for the `/vue` entry.
|
|
24
|
+
|
|
25
|
+
| subpath | runtime | pin |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `.` | none; node safe state | none |
|
|
28
|
+
| `./elements` | @virgilvox/hackbuild-ui (peer) | `>=0.10.0 <0.11.0` |
|
|
29
|
+
| `./vue` | vue (optional peer) and @virgilvox/hackbuild-ui | vue `^3.4.0` |
|
|
30
|
+
|
|
31
|
+
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.
|
|
32
|
+
|
|
33
|
+
## Quick start
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { importEsm } from "@hackbuild/ai-env";
|
|
37
|
+
import { ALL_RECORDS, chatThread, useModelPick, weightsLoader } from "@hackbuild/ai-views";
|
|
38
|
+
import { mountChatPane, mountComposer, mountModelSelect } from "@hackbuild/ai-views/elements";
|
|
39
|
+
import { loadWllama, wllamaUrls, type WllamaModule } from "@hackbuild/chat/wllama";
|
|
40
|
+
import { openWeightStore } from "@hackbuild/weights";
|
|
41
|
+
|
|
42
|
+
// a chat picker over the GGUF rows, files through the weight store; Qwen2.5 0.5B Instruct weights are Apache-2.0
|
|
43
|
+
const fetchFiles = weightsLoader(await openWeightStore());
|
|
44
|
+
const wllama = await importEsm<WllamaModule>(wllamaUrls().esm); // the runtime is passed in, never bundled
|
|
45
|
+
const thread = chatThread({ system: "answer in one line." });
|
|
46
|
+
const pick = useModelPick("chat", {
|
|
47
|
+
records: ALL_RECORDS.filter((r) => r.provider === "wllama"), chosen: "qwen2.5-0.5b-instruct-gguf",
|
|
48
|
+
loader: async (rec, ctx) => thread.setEngine(await loadWllama({ module: wllama, blobs: [...((await fetchFiles(rec, ctx)) as Map<string, Blob>).values()] })),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// the picker, the turns and the composer, drawn with the page's hackbuild-ui stylesheet
|
|
52
|
+
mountModelSelect(document.querySelector<HTMLElement>("#model")!, pick);
|
|
53
|
+
mountChatPane(document.querySelector<HTMLElement>("#chat")!, thread);
|
|
54
|
+
mountComposer(document.querySelector<HTMLElement>("#composer")!, thread);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Live example
|
|
58
|
+
|
|
59
|
+
The view demo pages run every view on stub providers with no weights: [hackbuild-browser-ai/views](https://hackbuild.github.io/hackbuild-browser-ai/views/). The package page is at [hackbuild-browser-ai/ai-views](https://hackbuild.github.io/hackbuild-browser-ai/ai-views/).
|
|
60
|
+
|
|
61
|
+
## Concepts
|
|
62
|
+
|
|
63
|
+
### three entries
|
|
64
|
+
|
|
65
|
+
`@hackbuild/ai-views` is node safe: `JOBS`, `jobRecords(job)`, `rowOf` (a record as a hackbuild-ui ModelRow), `useModelPick(job)`, `useJobsPick(jobs, presets)`, `weightsLoader(store)`, `weightsRemover(store)`, `defaultPick`, `chatThread`, `chatList`, `contextSegments`, `transcribeQueue`, the frame geometry and `traceRows`. `@hackbuild/ai-views/elements` holds the mount functions and `define()`. `@hackbuild/ai-views/vue` holds `ModelSelect`, `ModelJobs`, `ChatPane`, `Composer`, `ChatList`, `ContextMeter`, `MemoryInspector`, `TranscribeDrop`, `TranscriptView`, `TranscribeQueue`, `MaskStudio`, `MaskTools`, `MaskVerbs`, `MaskRack`, `FrameView` and `CameraFeed`; only this entry imports Vue.
|
|
66
|
+
|
|
67
|
+
### custom elements
|
|
68
|
+
|
|
69
|
+
Nothing registers on import. `define()` registers the elements bare, and `define("hb")` gives `<hb-model-select>` and so on; names already defined are left alone. Each element carries `.hb-view` (display contents), so a layout region of hackbuild-ui places its parts. A `for` attribute names the element whose state a part binds to:
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<model-select job="chat" variant="chip"></model-select>
|
|
73
|
+
<chat-pane id="chat"></chat-pane> <chat-composer for="chat"></chat-composer>
|
|
74
|
+
<transcribe-drop id="t"></transcribe-drop> <transcript-exports for="t"></transcript-exports>
|
|
75
|
+
<mask-studio id="m"></mask-studio> <mask-tools for="m"></mask-tools>
|
|
76
|
+
<frame-view id="f"></frame-view> <camera-feed for="f"></camera-feed>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Set `engine` on `<chat-pane>` to a @hackbuild/chat engine, or `pick`, `env`, `loader` and `records` on `<model-select>`. `<model-select>` fires `choose`, then `loaded` and `failed` once per load.
|
|
80
|
+
|
|
81
|
+
### vue
|
|
82
|
+
|
|
83
|
+
Each component mounts the same function the custom element does, on a host that shows as `.hb-view`; props in, events out. `ModelSelect` emits `pick`, `choose`, `loaded` and `failed`; `MaskStudio` emits `studio`, `FrameView` emits `view` and `CameraFeed` emits `feed` and `frame`, each handing over the mounted object.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { ModelSelect, ChatPane, Composer } from "@hackbuild/ai-views/vue";
|
|
87
|
+
import { chatThread } from "@hackbuild/ai-views";
|
|
88
|
+
const thread = chatThread({ engine });
|
|
89
|
+
// <ModelSelect job="chat" variant="chip" /> <ChatPane :thread="thread" /> <Composer :thread="thread" />
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### picks and loaders
|
|
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) needs a loader from the page. `useJobsPick` joins pickers as a rack with a line per job, presets with their download totals, and load all.
|
|
95
|
+
|
|
96
|
+
### views
|
|
97
|
+
|
|
98
|
+
| view | element | what it does |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| ModelSelect | `<model-select job variant go>` | one line with the choice and one pink "load, size"; the bar chip; a sheet with search, the fits, uncensored and no download filters, groups, the row detail and the "your own" forms. `<model-jobs jobs>` (properties `env`, `loader`, `records`, `presets`) gives a line per job, presets with totals and "load all" |
|
|
101
|
+
| ChatPane, Composer | `<chat-pane>`, `<chat-composer for>`, `<chat-list for>`, `<chat-context for budget>` | the thread, reasoning in a fold, memory used per reply, copy and redo on the last reply; the chats list (new, open, rename, delete) and the context meter; Enter sends, Shift Enter adds a line, Escape stops |
|
|
102
|
+
| TranscribeDrop, TranscriptView | `<transcribe-drop>`, `<transcript-view for>`, `<transcribe-queue for>`, `<transcript-exports for>` | the drop zone becomes the transcript; a queue of files; lines with their time, edit in place with undo; txt, srt, vtt, json |
|
|
103
|
+
| MaskStudio | `<mask-studio>`, `<mask-tools for>`, `<mask-verbs for>`, `<mask-rack for part>` | click segment, wand, brush, eraser, lasso, polygon, rectangle, ellipse, flood, pan (the hackbuild-ui mask editor's tools), segment everything, smooth, expand, shrink, saved masks, undo, zoom; `mask()` gives ImageData and `exportAs()` a png Blob |
|
|
104
|
+
| FrameView, CameraFeed | `<frame-view>`, `<camera-feed for>` | boxes with word and score, landmarks, a count and the caption over a frame; the camera at a set rate |
|
|
105
|
+
| memory inspector | `<memory-inspector>` | one row per fused recall candidate, the used ones marked |
|
|
106
|
+
|
|
107
|
+
### jobs and records
|
|
108
|
+
|
|
109
|
+
Jobs and their records: chat (the chat rows of the @hackbuild/models catalogue), speech to text (six records), vision language (SmolVLM 256M and 500M, SmolVLM2 256M video, LFM2-VL 450M, Gemma 4 E2B), detector (EfficientDet lite0, YOLOv10 n, s and m), masks (SlimSAM, FastSAM-s), image (SD-Turbo, SD 1.5, and SDXL-Turbo greyed as not run yet), voice (Kokoro, Pocket TTS, the vocal tract, the system voice), depth, embed, landmarks and face swap (scrfd, ArcFace, inswapper). The records come from the packages that run them; a record listed in more than one place counts once. Every record carries its weight licence; the non commercial ones are marked in the picker.
|
|
110
|
+
|
|
111
|
+
## API overview
|
|
112
|
+
|
|
113
|
+
| export | what it does |
|
|
114
|
+
|---|---|
|
|
115
|
+
| [`useModelPick`](../../docs/api/ai-views/index.md#usemodelpick) | a model picker for one job |
|
|
116
|
+
| [`useJobsPick`](../../docs/api/ai-views/index.md#usejobspick) | pickers for several jobs as one rack |
|
|
117
|
+
| [`weightsLoader`](../../docs/api/ai-views/index.md#weightsloader) | a loader that fetches files through a weight store |
|
|
118
|
+
| [`chatThread`](../../docs/api/ai-views/index.md#chatthread) | a chat thread over an engine |
|
|
119
|
+
| [`chatList`](../../docs/api/ai-views/index.md#chatlist) | several chats, one open |
|
|
120
|
+
| [`transcribeQueue`](../../docs/api/ai-views/index.md#transcribequeue) | a queue of files to transcribe, with edits and exports |
|
|
121
|
+
| [`JOBS`](../../docs/api/ai-views/index.md#jobs) | every job's words and capability test |
|
|
122
|
+
| [`ALL_RECORDS`](../../docs/api/ai-views/index.md#all_records) | every record the views know |
|
|
123
|
+
| [`rowOf`](../../docs/api/ai-views/index.md#rowof) | a record as one picker row |
|
|
124
|
+
| [`define`](../../docs/api/ai-views/elements.md#define) | register the custom elements |
|
|
125
|
+
| [`mountModelSelect`](../../docs/api/ai-views/elements.md#mountmodelselect) | the picker on a host |
|
|
126
|
+
| [`mountChatPane`](../../docs/api/ai-views/elements.md#mountchatpane), [`mountComposer`](../../docs/api/ai-views/elements.md#mountcomposer) | the turns and the message box |
|
|
127
|
+
| [`mountTranscribeDrop`](../../docs/api/ai-views/elements.md#mounttranscribedrop) | the drop zone that becomes the transcript |
|
|
128
|
+
| [`mountMaskStudio`](../../docs/api/ai-views/elements.md#mountmaskstudio) | the mask studio |
|
|
129
|
+
| [`mountFrameView`](../../docs/api/ai-views/elements.md#mountframeview), [`mountCameraFeed`](../../docs/api/ai-views/elements.md#mountcamerafeed) | a frame with results drawn over it, and the camera |
|
|
130
|
+
| [`ModelSelect`](../../docs/api/ai-views/vue.md#modelselect), [`ChatPane`](../../docs/api/ai-views/vue.md#chatpane) and the other components | the views as Vue components |
|
|
131
|
+
|
|
132
|
+
The full reference is in [docs/api/ai-views](../../docs/api/ai-views/README.md).
|
|
133
|
+
|
|
134
|
+
## Models and weights
|
|
135
|
+
|
|
136
|
+
This package runs no model; it lists records and loads them through the loader you pass. Weights are never bundled; `weightsLoader(store)` fetches them from the host in the table and @hackbuild/weights caches them. The 40 chat records are listed in [@hackbuild/models](../models/README.md#models-and-weights). Sizes are MiB of download; the source word is in each cell. Licences are as recorded on each record; several are non commercial or AGPL-3.0, and the picker marks them.
|
|
137
|
+
|
|
138
|
+
| model | id | size, MiB (source word in the cell) | licence | loads from |
|
|
139
|
+
|---|---|---|---|---|
|
|
140
|
+
| whisper large-v3-turbo | `whisper-large-v3-turbo` | 1534 (vendor) | MIT | Hugging Face `onnx-community/whisper-large-v3-turbo`, transformers.js |
|
|
141
|
+
| whisper base | `whisper-base` | 77 (vendor) | MIT | Hugging Face `onnx-community/whisper-base`, transformers.js |
|
|
142
|
+
| whisper small.en | `whisper-small.en` | 238 (vendor) | MIT (the OpenAI Whisper release; the Xenova ONNX card says apache-2.0) | Hugging Face `Xenova/whisper-small.en`, transformers.js |
|
|
143
|
+
| whisper base.en | `whisper-base.en` | 90 (inferred) | MIT (the OpenAI Whisper release; the Xenova ONNX card says apache-2.0) | Hugging Face `Xenova/whisper-base.en`, transformers.js |
|
|
144
|
+
| whisper tiny.en | `whisper-tiny.en` | 39 (vendor) | MIT (the OpenAI Whisper release; the Xenova ONNX card says apache-2.0) | Hugging Face `Xenova/whisper-tiny.en`, transformers.js |
|
|
145
|
+
| moonshine base | `moonshine-base` | 60 (vendor) | MIT (english models, per the model card; check before use) | Hugging Face `onnx-community/moonshine-base-ONNX`, transformers.js |
|
|
146
|
+
| depth anything v2 small | `depth-anything-v2-small` | 100 (inferred) | Apache-2.0 | Hugging Face `onnx-community/depth-anything-v2-small`, transformers.js |
|
|
147
|
+
| mediapipe efficientdet lite0 (coco, 80 classes) | `efficientdet-lite0` | 7 (inferred) | Apache-2.0 | `storage.googleapis.com`, MediaPipe |
|
|
148
|
+
| mediapipe selfie segmenter | `selfie-segmenter` | 1 (inferred) | Apache-2.0 | `storage.googleapis.com`, MediaPipe |
|
|
149
|
+
| mediapipe face landmarker with blendshapes | `face-landmarker` | 4 (inferred) | Apache-2.0 | `storage.googleapis.com`, MediaPipe |
|
|
150
|
+
| mediapipe hand landmarker | `hand-landmarker` | 8 (inferred) | Apache-2.0 | `storage.googleapis.com`, MediaPipe |
|
|
151
|
+
| mediapipe gesture recognizer (7 canned gestures) | `gesture-recognizer` | 8 (inferred) | unknown, check the mediapipe model card | `storage.googleapis.com`, MediaPipe |
|
|
152
|
+
| mediapipe pose landmarker lite | `pose-landmarker-lite` | 6 (inferred) | Apache-2.0 | `storage.googleapis.com`, MediaPipe |
|
|
153
|
+
| slimsam 77 uniform (point prompts) | `slimsam-77-uniform` | 38 (vendor) | Apache-2.0 | Hugging Face `Xenova/slimsam-77-uniform`, transformers.js |
|
|
154
|
+
| smolvlm 256m | `smolvlm-256m-instruct` | 260 (inferred) | Apache-2.0 | Hugging Face `HuggingFaceTB/SmolVLM-256M-Instruct`, transformers.js |
|
|
155
|
+
| lfm2-vl 450m | `lfm2-vl-450m` | 320 (inferred) | LFM Open License v1.0 | Hugging Face `onnx-community/LFM2-VL-450M-ONNX`, transformers.js |
|
|
156
|
+
| smolvlm 500m | `smolvlm-500m-instruct` | 463 (vendor) | Apache-2.0 | Hugging Face `HuggingFaceTB/SmolVLM-500M-Instruct`, transformers.js |
|
|
157
|
+
| smolvlm2 256m video | `smolvlm2-256m-video-instruct` | 252 (vendor) | Apache-2.0 | Hugging Face `HuggingFaceTB/SmolVLM2-256M-Video-Instruct`, transformers.js |
|
|
158
|
+
| depth anything v2 base | `depth-anything-v2-base` | 186 (vendor) | CC-BY-NC-4.0 (the model card's licence field) | Hugging Face `onnx-community/depth-anything-v2-base`, transformers.js |
|
|
159
|
+
| depth anything v1 small | `depth-anything-small-v1` | 48 (vendor) | Apache-2.0 (the upstream card; this export's card has no licence field) | Hugging Face `Xenova/depth-anything-small-hf`, transformers.js |
|
|
160
|
+
| gemma 4 e2b | `gemma-4-e2b-vision` | 3566 (vendor) | Apache-2.0 (the model card's licence field) | Hugging Face `onnx-community/gemma-4-E2B-it-ONNX`, transformers.js |
|
|
161
|
+
| yolov10 nano | `yolov10n` | 9 (vendor) | AGPL-3.0 (Ultralytics weights, the model card's licence field) | Hugging Face `onnx-community/yolov10n`, `onnx/model.onnx`, onnxruntime-web |
|
|
162
|
+
| yolov10 small | `yolov10s` | 28 (vendor) | AGPL-3.0 (Ultralytics weights, the model card's licence field) | Hugging Face `onnx-community/yolov10s`, `onnx/model.onnx`, onnxruntime-web |
|
|
163
|
+
| yolov10 medium | `yolov10m` | 59 (vendor) | AGPL-3.0 (Ultralytics weights, the model card's licence field) | Hugging Face `onnx-community/yolov10m`, `onnx/model.onnx`, onnxruntime-web |
|
|
164
|
+
| fastsam s | `fastsam-s` | 45 (vendor) | AGPL-3.0 upstream (Ultralytics FastSAM); the export's card says apache-2.0 | Hugging Face `anakhiu/fastsam-onnx`, `fastsam_s.onnx`, onnxruntime-web |
|
|
165
|
+
| face finder (scrfd 10g) | `scrfd-10g` | 16 (vendor) | InsightFace model pack: non-commercial research only (the buffalo_l pack terms) | Hugging Face `immich-app/buffalo_l`, `detection/model.onnx`, onnxruntime-web |
|
|
166
|
+
| face id (arcface r50) | `arcface-w600k-r50` | 166 (vendor) | InsightFace model pack: non-commercial research only (the buffalo_l pack terms) | Hugging Face `immich-app/buffalo_l`, `recognition/model.onnx`, onnxruntime-web |
|
|
167
|
+
| face swap (inswapper 128) | `inswapper-128` | 529 (vendor) | InsightFace: non-commercial research only; the mirror's card says gpl-3.0 | Hugging Face `hacksider/inswapper_128`, `inswapper_128.onnx`, onnxruntime-web |
|
|
168
|
+
| kokoro 82m | `kokoro-82m` | 310 (vendor) | Apache-2.0 (weights); the kokoro-js runtime phonemizes with eSpeak NG, GPL-3.0-or-later, loaded at run time and opt in | Hugging Face `onnx-community/Kokoro-82M-v1.0-ONNX`, kokoro-js |
|
|
169
|
+
| pocket tts | `pocket-tts` | 189 (inferred) | CC-BY-4.0 (weights), MIT (code) | Hugging Face `kyutai/pocket-tts`, the Pocket TTS worker |
|
|
170
|
+
| bellows voice | `bellows-voice` | 0 (vendor) | none, no weights (code MIT) | nothing to download, the vocal tract code |
|
|
171
|
+
| system voice | `web-speech` | 0 (vendor) | system voices, the platform's terms | nothing to download, the system voice |
|
|
172
|
+
| sd-turbo 512 | `sd-turbo` | 2397 (vendor) | Stability AI Non-Commercial Research Community License (the LICENSE in schmuell/sd-turbo-ort-web; upstream stabilityai/sd-turbo moved to the Community License in July 2024, this export did not) | Hugging Face `schmuell/sd-turbo-ort-web`, onnxruntime-web |
|
|
173
|
+
| stable diffusion 1.5 | `sd-1.5` | 1969 (vendor) | CreativeML OpenRAIL-M (use restrictions in its attachment A) | Hugging Face `microsoft/stable-diffusion-v1.5-webnn`, onnxruntime-web |
|
|
174
|
+
| sdxl-turbo 512 (listed, not run yet) | `sdxl-turbo` | 2548 (vendor) | Stability AI Community License (named in the card text; the repo has no licence field) | Hugging Face `webnn/sdxl-turbo`, onnxruntime-web |
|
|
175
|
+
| potion base 8M (static) | `potion-base-8m` | 30 (inferred) | MIT | Hugging Face `minishlab/potion-base-8M`, the static embedder |
|
|
176
|
+
| all-MiniLM-L6-v2 | `minilm-l6` | 23 (inferred) | Apache-2.0 | Hugging Face `Xenova/all-MiniLM-L6-v2`, transformers.js |
|
|
177
|
+
| bge-small-en-v1.5 | `bge-small-en` | 32 (vendor) | MIT | Hugging Face `Xenova/bge-small-en-v1.5`, transformers.js |
|
|
178
|
+
| face-api tiny landmarks (68 points) | `face-api-tiny` | 1 (inferred) | MIT | `cdn.jsdelivr.net`, face-api |
|
|
179
|
+
| all-minilm-l6-v2 | `all-minilm-l6-v2` | 23 (inferred) | Apache-2.0 | Hugging Face `Xenova/all-MiniLM-L6-v2`, transformers.js |
|
|
180
|
+
| htdemucs-fast | `htdemucs-fast` | 166 (inferred) | MIT | Hugging Face `StemSplitio/htdemucs-onnx`, `htdemucs_fp16weights.onnx`, onnxruntime-web |
|
|
181
|
+
|
|
182
|
+
## Browser support
|
|
183
|
+
|
|
184
|
+
| feature | needs | Chrome | Safari | Firefox | phone |
|
|
185
|
+
|---|---|---|---|---|---|
|
|
186
|
+
| state (`.` entry) | nothing | yes (inferred) | yes (inferred) | yes (inferred) | yes (inferred) |
|
|
187
|
+
| custom elements | `customElements` | yes (measured, headless) | yes (inferred) | yes (inferred) | yes (inferred) |
|
|
188
|
+
| Vue components | Vue 3.4 or later | yes (inferred) | yes (inferred) | yes (inferred) | yes (inferred) |
|
|
189
|
+
| CameraFeed | `getUserMedia` on a secure page | unknown | unknown | unknown | unknown |
|
|
190
|
+
| mask drawing by touch | pointer events | unknown | unknown | unknown | unknown |
|
|
191
|
+
|
|
192
|
+
No WebGPU or wasm here; the model you load brings its own needs, and its row says when it cannot run. The headless smoke runs the demo pages on stub providers; no real model has run through a view (see below).
|
|
193
|
+
|
|
194
|
+
## Errors and troubleshooting
|
|
195
|
+
|
|
196
|
+
| message | cause | what to do |
|
|
197
|
+
|---|---|---|
|
|
198
|
+
| `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>` |
|
|
199
|
+
| `<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 |
|
|
200
|
+
| `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>` |
|
|
201
|
+
| `no speech model loaded. pick one and load it.` (a failed file) | `<transcribe-drop>` has no transcriber | set its transcriber from @hackbuild/transcribe |
|
|
202
|
+
| `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 |
|
|
203
|
+
| `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 |
|
|
204
|
+
|
|
205
|
+
## Works with
|
|
206
|
+
|
|
207
|
+
- [@hackbuild/models](../models/README.md) supplies the records, fit words and budget behind every picker row.
|
|
208
|
+
- [@hackbuild/weights](../weights/README.md) fetches and caches the files through `weightsLoader(store)` and deletes them through `weightsRemover(store)`.
|
|
209
|
+
- [@hackbuild/chat](../chat/README.md) gives the engine a chat thread streams from.
|
|
210
|
+
- [@hackbuild/transcribe](../transcribe/README.md) gives the transcriber a transcribe queue runs, and the txt, srt, vtt and json writers.
|
|
211
|
+
- [@hackbuild/memory](../memory/README.md) gives the recall the memory inspector shows.
|
|
212
|
+
- [@hackbuild/vision](../vision/README.md), [@hackbuild/speak](../speak/README.md), [@hackbuild/embed](../embed/README.md) and [@hackbuild/imagegen](../imagegen/README.md) supply the records of their jobs.
|
|
213
|
+
|
|
214
|
+
## Changelog and licences
|
|
215
|
+
|
|
216
|
+
Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LICENSE](../../LICENSE)); this README is CC-BY-4.0 with its code samples also MIT. No weights ship here. Each record names its weight licence in the table above, among them Apache-2.0, MIT, CC-BY-NC-4.0, AGPL-3.0 (YOLOv10, FastSAM), the InsightFace non-commercial research terms, the Stability AI licences and CreativeML OpenRAIL-M. The quick start loads Qwen2.5 0.5B Instruct GGUF, weights Apache-2.0.
|
|
217
|
+
|
|
218
|
+
## What is verified, and what is not
|
|
219
|
+
|
|
220
|
+
### Verified on this machine
|
|
221
|
+
|
|
222
|
+
| date | check | result |
|
|
223
|
+
|---|---|---|
|
|
224
|
+
| 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
|
+
| 2026-11-25 | `node tools/smoke-views.mjs`, headless | pass: one smoke per demo page on stub providers with no weights |
|
|
226
|
+
|
|
227
|
+
### Not verified by anything
|
|
228
|
+
|
|
229
|
+
- A real model through any view in this package (the demos use stubs).
|
|
230
|
+
- Touch drawing on a phone.
|
|
231
|
+
- Screen readers.
|
|
232
|
+
|
|
233
|
+
## Size budget
|
|
234
|
+
|
|
235
|
+
| file | gzip (measured) | ceiling |
|
|
236
|
+
|---|---|---|
|
|
237
|
+
| `dist/index.js` (main entry, imports external) | 12,413 bytes | 13,033 bytes |
|
|
238
|
+
| `dist/single/elements.iife.js` (single file build) | 86,649 bytes | 90,981 bytes |
|
|
239
|
+
|
|
240
|
+
Measured 2026-11-25 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
241
|
+
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
|
242
|
+
5 percent from its row.
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state behind ChatPane and Composer: a
|
|
3
|
+
* thread of turns, one live reply streamed from a @hackbuild/chat engine
|
|
4
|
+
* with its reasoning kept apart for the think fold, the memory each reply
|
|
5
|
+
* used, stop, regenerate, and a markdown export. Framework free.
|
|
6
|
+
*/
|
|
7
|
+
import type { ChatEngine } from "@hackbuild/chat";
|
|
8
|
+
/** A memory recalled for a reply, with its label and score. */
|
|
9
|
+
export interface MemoryUsed {
|
|
10
|
+
label: string;
|
|
11
|
+
/** 0 to 1, shown beside the label. */
|
|
12
|
+
score?: number;
|
|
13
|
+
}
|
|
14
|
+
/** One chat turn: role, text, reasoning, time, whether it is done, memory used, stats and a note. */
|
|
15
|
+
export interface Turn {
|
|
16
|
+
id: number;
|
|
17
|
+
role: "user" | "assistant";
|
|
18
|
+
text: string;
|
|
19
|
+
/** Reasoning, shown in a fold under the reply. */
|
|
20
|
+
think: string;
|
|
21
|
+
at: number;
|
|
22
|
+
done: boolean;
|
|
23
|
+
/** Memory recalled for this reply. */
|
|
24
|
+
mem?: MemoryUsed[];
|
|
25
|
+
/** "31.2 tok/s, first word 0.64 s, 44 tok (measured)". */
|
|
26
|
+
stats?: string;
|
|
27
|
+
/** "stopped", "failed: ...". */
|
|
28
|
+
note?: string;
|
|
29
|
+
}
|
|
30
|
+
/** What a thread shows: its turns, whether a reply streams, and whether an engine is set. */
|
|
31
|
+
export interface ThreadSnapshot {
|
|
32
|
+
turns: readonly Turn[];
|
|
33
|
+
busy: boolean;
|
|
34
|
+
/** An engine is set; without one a reply says how to get one. */
|
|
35
|
+
ready: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for `chatThread` and `chatList`: engine, system prompt, memory recall, the no engine
|
|
39
|
+
* reply, clock and reply token cap.
|
|
40
|
+
*/
|
|
41
|
+
export interface ThreadOptions {
|
|
42
|
+
engine?: ChatEngine | null;
|
|
43
|
+
system?: string;
|
|
44
|
+
/** Memory for a message; its hits ride along in the system prompt and show under the reply. */
|
|
45
|
+
recall?: (query: string) => Promise<MemoryUsed[]>;
|
|
46
|
+
/** What a reply says with no engine. */
|
|
47
|
+
noEngine?: string;
|
|
48
|
+
now?: () => number;
|
|
49
|
+
/** Reply token cap. */
|
|
50
|
+
maxTokens?: number;
|
|
51
|
+
}
|
|
52
|
+
/** A chat thread: send, stop, regenerate, remove and clear turns, set the engine, and export as markdown. */
|
|
53
|
+
export interface ChatThread {
|
|
54
|
+
snapshot(): ThreadSnapshot;
|
|
55
|
+
subscribe(fn: (s: ThreadSnapshot) => void): () => void;
|
|
56
|
+
send(text: string): Promise<void>;
|
|
57
|
+
stop(): void;
|
|
58
|
+
/** Drop the last reply and ask again. */
|
|
59
|
+
regenerate(): Promise<void>;
|
|
60
|
+
remove(id: number): void;
|
|
61
|
+
clear(): void;
|
|
62
|
+
setEngine(engine: ChatEngine | null): void;
|
|
63
|
+
/** The thread as markdown, for an export. */
|
|
64
|
+
markdown(title?: string): string;
|
|
65
|
+
}
|
|
66
|
+
/** What a reply says when no chat engine is set. */
|
|
67
|
+
export declare const NO_ENGINE = "this needs a model. pick one in the bar and load it.";
|
|
68
|
+
/** Creates a chat thread that streams replies from an engine, with optional memory recall per message. */
|
|
69
|
+
export declare function chatThread(o?: ThreadOptions): ChatThread;
|
|
70
|
+
/** One chat in a chat list: id, title, last update and turn count. */
|
|
71
|
+
export interface ChatListItem {
|
|
72
|
+
id: string;
|
|
73
|
+
title: string;
|
|
74
|
+
updated: number;
|
|
75
|
+
count: number;
|
|
76
|
+
}
|
|
77
|
+
/** The chats of a list, newest first, and the id of the open one. */
|
|
78
|
+
export interface ChatListSnapshot {
|
|
79
|
+
items: readonly ChatListItem[];
|
|
80
|
+
current: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Several chats: a list with the newest first, one
|
|
84
|
+
* open. `thread` always speaks for the open chat, so a pane and a composer
|
|
85
|
+
* bound to it follow a switch.
|
|
86
|
+
*/
|
|
87
|
+
export interface ChatList {
|
|
88
|
+
readonly thread: ChatThread;
|
|
89
|
+
snapshot(): ChatListSnapshot;
|
|
90
|
+
subscribe(fn: (s: ChatListSnapshot) => void): () => void;
|
|
91
|
+
create(): string;
|
|
92
|
+
open(id: string): void;
|
|
93
|
+
rename(id: string, title: string): void;
|
|
94
|
+
remove(id: string): void;
|
|
95
|
+
setEngine(engine: ChatEngine | null): void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Creates a list of chat threads, newest first, with one open; its `thread` always speaks for the
|
|
99
|
+
* open chat.
|
|
100
|
+
*/
|
|
101
|
+
export declare function chatList(o?: ThreadOptions): ChatList;
|
|
102
|
+
/** Tokens the next request carries, by source, for a context meter: about 4 characters a token (inferred). */
|
|
103
|
+
export declare function contextSegments(s: ThreadSnapshot, system?: string): {
|
|
104
|
+
key: string;
|
|
105
|
+
label: string;
|
|
106
|
+
tokens: number;
|
|
107
|
+
}[];
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state behind ChatPane and Composer: a
|
|
3
|
+
* thread of turns, one live reply streamed from a @hackbuild/chat engine
|
|
4
|
+
* with its reasoning kept apart for the think fold, the memory each reply
|
|
5
|
+
* used, stop, regenerate, and a markdown export. Framework free.
|
|
6
|
+
*/
|
|
7
|
+
import { statsText } from "@virgilvox/hackbuild-ui/vanilla";
|
|
8
|
+
/** What a reply says when no chat engine is set. */
|
|
9
|
+
export const NO_ENGINE = "this needs a model. pick one in the bar and load it.";
|
|
10
|
+
/** Creates a chat thread that streams replies from an engine, with optional memory recall per message. */
|
|
11
|
+
export function chatThread(o = {}) {
|
|
12
|
+
let engine = o.engine ?? null;
|
|
13
|
+
const now = o.now ?? (() => Date.now());
|
|
14
|
+
let turns = [];
|
|
15
|
+
let busy = false;
|
|
16
|
+
let ac = null;
|
|
17
|
+
let seq = 0;
|
|
18
|
+
const subs = new Set();
|
|
19
|
+
const snap = () => ({ turns, busy, ready: !!engine });
|
|
20
|
+
const emit = () => {
|
|
21
|
+
const s = snap();
|
|
22
|
+
for (const fn of subs)
|
|
23
|
+
fn(s);
|
|
24
|
+
};
|
|
25
|
+
const patch = (id, p) => {
|
|
26
|
+
turns = turns.map((t) => (t.id === id ? { ...t, ...p } : t));
|
|
27
|
+
emit();
|
|
28
|
+
};
|
|
29
|
+
async function reply() {
|
|
30
|
+
const lastUser = [...turns].reverse().find((t) => t.role === "user");
|
|
31
|
+
const live = { id: ++seq, role: "assistant", text: "", think: "", at: now(), done: false };
|
|
32
|
+
turns = [...turns, live];
|
|
33
|
+
busy = true;
|
|
34
|
+
emit();
|
|
35
|
+
if (!engine) {
|
|
36
|
+
patch(live.id, { text: o.noEngine ?? NO_ENGINE, done: true });
|
|
37
|
+
busy = false;
|
|
38
|
+
emit();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
ac = new AbortController();
|
|
42
|
+
const signal = ac.signal;
|
|
43
|
+
let mem = [];
|
|
44
|
+
try {
|
|
45
|
+
if (o.recall && lastUser)
|
|
46
|
+
mem = await o.recall(lastUser.text);
|
|
47
|
+
if (mem.length)
|
|
48
|
+
patch(live.id, { mem });
|
|
49
|
+
const sys = [o.system, mem.length ? `things you remember:\n${mem.map((m) => `- ${m.label}`).join("\n")}` : ""].filter(Boolean).join("\n\n");
|
|
50
|
+
const history = [
|
|
51
|
+
...(sys ? [{ role: "system", content: sys }] : []),
|
|
52
|
+
...turns.filter((t) => t.id !== live.id && t.text).map((t) => ({ role: t.role, content: t.text })),
|
|
53
|
+
];
|
|
54
|
+
let text = "";
|
|
55
|
+
let think = "";
|
|
56
|
+
const it = engine.stream(history, { signal, ...(o.maxTokens ? { maxTokens: o.maxTokens } : {}) });
|
|
57
|
+
for (;;) {
|
|
58
|
+
const step = await it.next();
|
|
59
|
+
if (step.done) {
|
|
60
|
+
const s = step.value?.stats;
|
|
61
|
+
const stats = s ? statsText({ tokPerSec: s.tokensPerSecond, firstMs: s.firstTokenMs, tokens: s.tokens, source: s.tokensSource }) : "";
|
|
62
|
+
patch(live.id, { done: true, ...(stats ? { stats } : {}) });
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
const ev = step.value;
|
|
66
|
+
if (ev.type === "text")
|
|
67
|
+
text += ev.text;
|
|
68
|
+
else if (ev.type === "think")
|
|
69
|
+
think += ev.text;
|
|
70
|
+
else
|
|
71
|
+
continue;
|
|
72
|
+
patch(live.id, { text, think });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
const stopped = signal.aborted;
|
|
77
|
+
patch(live.id, { done: true, note: stopped ? "stopped" : `failed: ${e instanceof Error ? e.message : String(e)}` });
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
busy = false;
|
|
81
|
+
ac = null;
|
|
82
|
+
emit();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
snapshot: snap,
|
|
87
|
+
subscribe(fn) {
|
|
88
|
+
subs.add(fn);
|
|
89
|
+
fn(snap());
|
|
90
|
+
return () => subs.delete(fn);
|
|
91
|
+
},
|
|
92
|
+
async send(text) {
|
|
93
|
+
const t = text.trim();
|
|
94
|
+
if (!t || busy)
|
|
95
|
+
return;
|
|
96
|
+
turns = [...turns, { id: ++seq, role: "user", text: t, think: "", at: now(), done: true }];
|
|
97
|
+
await reply();
|
|
98
|
+
},
|
|
99
|
+
stop() {
|
|
100
|
+
ac?.abort();
|
|
101
|
+
},
|
|
102
|
+
async regenerate() {
|
|
103
|
+
if (busy)
|
|
104
|
+
return;
|
|
105
|
+
const last = turns[turns.length - 1];
|
|
106
|
+
if (last?.role === "assistant")
|
|
107
|
+
turns = turns.slice(0, -1);
|
|
108
|
+
if (turns[turns.length - 1]?.role !== "user")
|
|
109
|
+
return emit();
|
|
110
|
+
await reply();
|
|
111
|
+
},
|
|
112
|
+
remove(id) {
|
|
113
|
+
turns = turns.filter((t) => t.id !== id);
|
|
114
|
+
emit();
|
|
115
|
+
},
|
|
116
|
+
clear() {
|
|
117
|
+
ac?.abort();
|
|
118
|
+
turns = [];
|
|
119
|
+
emit();
|
|
120
|
+
},
|
|
121
|
+
setEngine(e) {
|
|
122
|
+
engine = e;
|
|
123
|
+
emit();
|
|
124
|
+
},
|
|
125
|
+
markdown(title = "chat") {
|
|
126
|
+
const lines = [`# ${title}`, ""];
|
|
127
|
+
for (const t of turns)
|
|
128
|
+
lines.push(`## ${t.role === "user" ? "you" : "reply"}`, "", t.text, "");
|
|
129
|
+
return lines.join("\n");
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Creates a list of chat threads, newest first, with one open; its `thread` always speaks for the
|
|
135
|
+
* open chat.
|
|
136
|
+
*/
|
|
137
|
+
export function chatList(o = {}) {
|
|
138
|
+
const now = o.now ?? (() => Date.now());
|
|
139
|
+
let engine = o.engine ?? null;
|
|
140
|
+
let seq = 0;
|
|
141
|
+
const chats = new Map();
|
|
142
|
+
let current = "";
|
|
143
|
+
const subs = new Set();
|
|
144
|
+
const threadSubs = new Set();
|
|
145
|
+
let offCurrent = null;
|
|
146
|
+
const snap = () => ({
|
|
147
|
+
items: [...chats].map(([id, c]) => ({ id, title: c.title, updated: c.updated, count: c.t.snapshot().turns.length })).sort((a, b) => b.updated - a.updated),
|
|
148
|
+
current,
|
|
149
|
+
});
|
|
150
|
+
const emit = () => {
|
|
151
|
+
const s = snap();
|
|
152
|
+
for (const fn of subs)
|
|
153
|
+
fn(s);
|
|
154
|
+
};
|
|
155
|
+
const follow = () => {
|
|
156
|
+
offCurrent?.();
|
|
157
|
+
const c = chats.get(current);
|
|
158
|
+
offCurrent = c.t.subscribe((s) => {
|
|
159
|
+
const first = s.turns.find((t) => t.role === "user");
|
|
160
|
+
if (first && !c.named)
|
|
161
|
+
c.title = first.text.length > 40 ? `${first.text.slice(0, 37)}...` : first.text;
|
|
162
|
+
if (s.turns.length)
|
|
163
|
+
c.updated = now();
|
|
164
|
+
for (const fn of threadSubs)
|
|
165
|
+
fn(s);
|
|
166
|
+
emit();
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
const list = {
|
|
170
|
+
thread: {
|
|
171
|
+
snapshot: () => chats.get(current).t.snapshot(),
|
|
172
|
+
subscribe(fn) {
|
|
173
|
+
threadSubs.add(fn);
|
|
174
|
+
fn(chats.get(current).t.snapshot());
|
|
175
|
+
return () => threadSubs.delete(fn);
|
|
176
|
+
},
|
|
177
|
+
send: (text) => chats.get(current).t.send(text),
|
|
178
|
+
stop: () => chats.get(current).t.stop(),
|
|
179
|
+
regenerate: () => chats.get(current).t.regenerate(),
|
|
180
|
+
remove: (id) => chats.get(current).t.remove(id),
|
|
181
|
+
clear: () => chats.get(current).t.clear(),
|
|
182
|
+
setEngine: (e) => list.setEngine(e),
|
|
183
|
+
markdown: (title) => chats.get(current).t.markdown(title ?? chats.get(current).title),
|
|
184
|
+
},
|
|
185
|
+
snapshot: snap,
|
|
186
|
+
subscribe(fn) {
|
|
187
|
+
subs.add(fn);
|
|
188
|
+
fn(snap());
|
|
189
|
+
return () => subs.delete(fn);
|
|
190
|
+
},
|
|
191
|
+
create() {
|
|
192
|
+
const id = `chat-${++seq}`;
|
|
193
|
+
chats.set(id, { t: chatThread({ ...o, engine }), title: "new chat", updated: now(), named: false });
|
|
194
|
+
current = id;
|
|
195
|
+
follow();
|
|
196
|
+
return id;
|
|
197
|
+
},
|
|
198
|
+
open(id) {
|
|
199
|
+
if (!chats.has(id) || id === current)
|
|
200
|
+
return;
|
|
201
|
+
chats.get(current)?.t.stop();
|
|
202
|
+
current = id;
|
|
203
|
+
follow();
|
|
204
|
+
},
|
|
205
|
+
rename(id, title) {
|
|
206
|
+
const c = chats.get(id);
|
|
207
|
+
if (!c || !title.trim())
|
|
208
|
+
return;
|
|
209
|
+
c.title = title.trim();
|
|
210
|
+
c.named = true;
|
|
211
|
+
emit();
|
|
212
|
+
},
|
|
213
|
+
remove(id) {
|
|
214
|
+
chats.get(id)?.t.stop();
|
|
215
|
+
chats.delete(id);
|
|
216
|
+
if (!chats.size)
|
|
217
|
+
return void list.create();
|
|
218
|
+
if (id === current) {
|
|
219
|
+
current = snap().items[0].id;
|
|
220
|
+
follow();
|
|
221
|
+
}
|
|
222
|
+
else
|
|
223
|
+
emit();
|
|
224
|
+
},
|
|
225
|
+
setEngine(e) {
|
|
226
|
+
engine = e;
|
|
227
|
+
for (const c of chats.values())
|
|
228
|
+
c.t.setEngine(e);
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
list.create();
|
|
232
|
+
return list;
|
|
233
|
+
}
|
|
234
|
+
/** Tokens the next request carries, by source, for a context meter: about 4 characters a token (inferred). */
|
|
235
|
+
export function contextSegments(s, system = "") {
|
|
236
|
+
const tok = (t) => Math.ceil(t.length / 4);
|
|
237
|
+
const mem = s.turns.flatMap((t) => t.mem ?? []).reduce((n, m) => n + tok(m.label), 0);
|
|
238
|
+
return [
|
|
239
|
+
{ key: "system", label: "persona", tokens: tok(system) },
|
|
240
|
+
{ key: "memory", label: "memory", tokens: mem },
|
|
241
|
+
{ key: "chat", label: "chat", tokens: s.turns.reduce((n, t) => n + tok(t.text), 0) },
|
|
242
|
+
];
|
|
243
|
+
}
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Small DOM helpers shared by the mount functions. Light DOM only: the page's hackbuild-ui stylesheet draws everything. */
|
|
2
|
+
export declare function esc(s: string): string;
|
|
3
|
+
/** Shows or hides a part; inside a layout hackbuild-ui's `.hb-lay [hidden]` makes it hold on parts that set display. */
|
|
4
|
+
export declare function show(el: HTMLElement, on: boolean): void;
|
|
5
|
+
/** One handle per mount: redraw with new data, then tear down. */
|
|
6
|
+
export interface Mounted {
|
|
7
|
+
dispose(): void;
|
|
8
|
+
}
|
|
9
|
+
/** Listeners that come off together. */
|
|
10
|
+
export declare function listeners(): {
|
|
11
|
+
on<K extends keyof HTMLElementEventMap>(el: EventTarget, type: K | string, fn: (e: HTMLElementEventMap[K]) => void): void;
|
|
12
|
+
add(off: () => void): void;
|
|
13
|
+
off(): void;
|
|
14
|
+
};
|
|
15
|
+
/** The nearest ancestor that scrolls, else the element. */
|
|
16
|
+
export declare function scroller(el: HTMLElement): HTMLElement;
|
|
17
|
+
/** Saves text as a file through a link press. */
|
|
18
|
+
export declare function download(name: string, text: string | Blob, type?: string): void;
|
|
19
|
+
export declare const ICON: {
|
|
20
|
+
readonly undo: string;
|
|
21
|
+
readonly redo: string;
|
|
22
|
+
readonly zoomIn: string;
|
|
23
|
+
readonly zoomOut: string;
|
|
24
|
+
readonly fit: string;
|
|
25
|
+
readonly x: string;
|
|
26
|
+
readonly copy: string;
|
|
27
|
+
readonly redoMsg: string;
|
|
28
|
+
readonly point: string;
|
|
29
|
+
readonly wand: string;
|
|
30
|
+
readonly brush: string;
|
|
31
|
+
readonly lasso: string;
|
|
32
|
+
readonly all: string;
|
|
33
|
+
readonly camera: string;
|
|
34
|
+
readonly menu: string;
|
|
35
|
+
readonly plus: string;
|
|
36
|
+
readonly pen: string;
|
|
37
|
+
readonly trash: string;
|
|
38
|
+
};
|