@hackbuild/ai-views 0.0.0-stage → 0.1.0
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 +93 -2
- package/dist/chat.d.ts +91 -0
- package/dist/chat.js +237 -0
- package/dist/dom.d.ts +38 -0
- package/dist/dom.js +67 -0
- package/dist/elements.d.ts +42 -0
- package/dist/elements.js +378 -0
- package/dist/frame.d.ts +55 -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 +26 -0
- package/dist/jobs.js +49 -0
- package/dist/memory.d.ts +26 -0
- package/dist/memory.js +36 -0
- package/dist/mount-chat.d.ts +38 -0
- package/dist/mount-chat.js +177 -0
- package/dist/mount-frame.d.ts +45 -0
- package/dist/mount-frame.js +237 -0
- package/dist/mount-mask.d.ts +109 -0
- package/dist/mount-mask.js +446 -0
- package/dist/mount-model.d.ts +27 -0
- package/dist/mount-model.js +122 -0
- package/dist/mount-transcribe.d.ts +42 -0
- package/dist/mount-transcribe.js +203 -0
- package/dist/pick.d.ts +132 -0
- package/dist/pick.js +254 -0
- package/dist/rows.d.ts +36 -0
- package/dist/rows.js +147 -0
- package/dist/single/elements.iife.js +9568 -0
- package/dist/single/elements.js +9542 -0
- package/dist/single/index.iife.js +6814 -0
- package/dist/single/index.js +6778 -0
- package/dist/single/vue.iife.js +11334 -0
- package/dist/single/vue.js +11316 -0
- package/dist/transcribe.d.ts +80 -0
- package/dist/transcribe.js +175 -0
- package/dist/vue.d.ts +259 -0
- package/dist/vue.js +199 -0
- package/how.ts +26 -0
- package/package.json +61 -4
package/dist/vue.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hackbuild/ai-views/vue: the views as Vue 3 components. Each one mounts
|
|
3
|
+
* the same function the custom element does on a host that shows as
|
|
4
|
+
* `.hb-view` (display contents), so the look is one code path; props in, events out.
|
|
5
|
+
* Vue is an optional peer: only this entry imports it.
|
|
6
|
+
*/
|
|
7
|
+
import { defineComponent, h, onBeforeUnmount, onMounted, ref, shallowRef, watch } from "vue";
|
|
8
|
+
import { useModelPick } from "./pick.js";
|
|
9
|
+
import { mountModelJobs, mountModelSelect } from "./mount-model.js";
|
|
10
|
+
import { mountChatList, mountChatPane, mountComposer, mountContextMeter } from "./mount-chat.js";
|
|
11
|
+
import { mountTranscribeDrop, mountTranscribeQueue, mountTranscriptExports, mountTranscriptView } from "./mount-transcribe.js";
|
|
12
|
+
import { mountMaskRack, mountMaskStudio, mountMaskTools, mountMaskVerbs } from "./mount-mask.js";
|
|
13
|
+
import { mountMemoryInspector } from "./memory.js";
|
|
14
|
+
import { mountCameraFeed, mountFrameView } from "./mount-frame.js";
|
|
15
|
+
// .hb-view of hackbuild-ui: display contents, so the parts sit in the layout region
|
|
16
|
+
const contents = { class: "hb-view" };
|
|
17
|
+
function hosted(setupMount, deps = () => []) {
|
|
18
|
+
return (props, { emit }) => {
|
|
19
|
+
const el = ref(null);
|
|
20
|
+
let m = null;
|
|
21
|
+
const run = () => {
|
|
22
|
+
m?.dispose();
|
|
23
|
+
if (el.value)
|
|
24
|
+
m = setupMount(el.value, props, emit);
|
|
25
|
+
};
|
|
26
|
+
onMounted(run);
|
|
27
|
+
watch(() => deps(props), run);
|
|
28
|
+
onBeforeUnmount(() => m?.dispose());
|
|
29
|
+
return () => h("div", { ...contents, ref: el });
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export const ModelSelect = defineComponent({
|
|
33
|
+
name: "ModelSelect",
|
|
34
|
+
props: {
|
|
35
|
+
job: { type: String, default: "chat" },
|
|
36
|
+
pick: { type: Object, default: undefined },
|
|
37
|
+
variant: { type: String, default: "line" },
|
|
38
|
+
go: { type: Boolean, default: true },
|
|
39
|
+
env: { type: Object, default: undefined },
|
|
40
|
+
loader: { type: Function, default: undefined },
|
|
41
|
+
},
|
|
42
|
+
emits: ["choose", "pick", "loaded", "failed"],
|
|
43
|
+
setup: hosted((host, p, emit) => {
|
|
44
|
+
const pick = p.pick ?? useModelPick(p.job, { ...(p.env ? { env: p.env } : {}), ...(p.loader ? { loader: p.loader } : {}) });
|
|
45
|
+
emit("pick", pick);
|
|
46
|
+
const was = new Map(pick.snapshot().rows.map((r) => [r.id, r.state]));
|
|
47
|
+
const off = pick.subscribe((s) => {
|
|
48
|
+
emit("choose", s.chosen);
|
|
49
|
+
for (const r of s.rows) {
|
|
50
|
+
if (was.get(r.id) === "loading" && r.state === "loaded")
|
|
51
|
+
emit("loaded", r.id, pick.result(r.id));
|
|
52
|
+
if (was.get(r.id) === "loading" && r.state === "error")
|
|
53
|
+
emit("failed", r.id, pick.error(r.id));
|
|
54
|
+
was.set(r.id, r.state);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const m = mountModelSelect(host, pick, { variant: p.variant, go: p.go });
|
|
58
|
+
return { dispose: () => (off(), m.dispose()) };
|
|
59
|
+
}, (p) => [p.job, p.pick, p.variant, p.go]),
|
|
60
|
+
});
|
|
61
|
+
export const ChatPane = defineComponent({
|
|
62
|
+
name: "ChatPane",
|
|
63
|
+
props: {
|
|
64
|
+
thread: { type: Object, required: true },
|
|
65
|
+
name: { type: String, default: "reply" },
|
|
66
|
+
emptyName: { type: String, default: "what are we working on?" },
|
|
67
|
+
emptyNote: { type: String, default: "" },
|
|
68
|
+
},
|
|
69
|
+
setup: hosted((host, p) => mountChatPane(host, p.thread, { name: p.name, emptyName: p.emptyName, emptyNote: p.emptyNote }), (p) => [p.thread]),
|
|
70
|
+
});
|
|
71
|
+
export const Composer = defineComponent({
|
|
72
|
+
name: "Composer",
|
|
73
|
+
props: { thread: { type: Object, required: true }, placeholder: { type: String, default: "say something" } },
|
|
74
|
+
setup: hosted((host, p) => mountComposer(host, p.thread, { placeholder: p.placeholder }), (p) => [p.thread]),
|
|
75
|
+
});
|
|
76
|
+
export const TranscribeDrop = defineComponent({
|
|
77
|
+
name: "TranscribeDrop",
|
|
78
|
+
props: {
|
|
79
|
+
queue: { type: Object, required: true },
|
|
80
|
+
accept: { type: String, default: "audio/*,video/*" },
|
|
81
|
+
sampleLabel: { type: String, default: "" },
|
|
82
|
+
},
|
|
83
|
+
emits: ["sample"],
|
|
84
|
+
setup: hosted((host, p, emit) => mountTranscribeDrop(host, p.queue, { accept: p.accept, ...(p.sampleLabel ? { sampleLabel: p.sampleLabel, onSample: () => emit("sample") } : {}) }), (p) => [p.queue]),
|
|
85
|
+
});
|
|
86
|
+
export const TranscriptView = defineComponent({
|
|
87
|
+
name: "TranscriptView",
|
|
88
|
+
props: { queue: { type: Object, required: true }, exports: { type: Boolean, default: false } },
|
|
89
|
+
setup: hosted((host, p) => (p.exports ? mountTranscriptExports(host, p.queue) : mountTranscriptView(host, p.queue)), (p) => [p.queue, p.exports]),
|
|
90
|
+
});
|
|
91
|
+
export const MaskStudio = defineComponent({
|
|
92
|
+
name: "MaskStudio",
|
|
93
|
+
props: { models: { type: Object, default: () => ({}) }, sampleLabel: { type: String, default: "" } },
|
|
94
|
+
emits: ["studio", "sample"],
|
|
95
|
+
setup(props, { emit }) {
|
|
96
|
+
const el = ref(null);
|
|
97
|
+
const studio = shallowRef(null);
|
|
98
|
+
onMounted(() => {
|
|
99
|
+
studio.value = mountMaskStudio(el.value, { models: props.models, ...(props.sampleLabel ? { sampleLabel: props.sampleLabel, onSample: () => emit("sample") } : {}) });
|
|
100
|
+
emit("studio", studio.value);
|
|
101
|
+
});
|
|
102
|
+
watch(() => props.models, (m) => studio.value?.setModels(m));
|
|
103
|
+
onBeforeUnmount(() => {
|
|
104
|
+
studio.value?.dispose();
|
|
105
|
+
});
|
|
106
|
+
// a page places the rail and verbs with MaskTools on the studio the studio event hands it
|
|
107
|
+
return () => h("div", { ...contents, ref: el });
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
export const MaskTools = defineComponent({
|
|
111
|
+
name: "MaskTools",
|
|
112
|
+
props: { studio: { type: Object, required: true } },
|
|
113
|
+
setup: hosted((host, p) => mountMaskTools(host, p.studio), (p) => [p.studio]),
|
|
114
|
+
});
|
|
115
|
+
export const MaskVerbs = defineComponent({
|
|
116
|
+
name: "MaskVerbs",
|
|
117
|
+
props: { studio: { type: Object, required: true } },
|
|
118
|
+
setup: hosted((host, p) => mountMaskVerbs(host, p.studio), (p) => [p.studio]),
|
|
119
|
+
});
|
|
120
|
+
export const MaskRack = defineComponent({
|
|
121
|
+
name: "MaskRack",
|
|
122
|
+
props: {
|
|
123
|
+
studio: { type: Object, required: true },
|
|
124
|
+
part: { type: String, default: "found" },
|
|
125
|
+
name: { type: String, default: "mask" },
|
|
126
|
+
},
|
|
127
|
+
setup: hosted((host, p) => mountMaskRack(host, p.studio, p.part, { name: p.name }), (p) => [p.studio, p.part]),
|
|
128
|
+
});
|
|
129
|
+
export const ModelJobs = defineComponent({
|
|
130
|
+
name: "ModelJobs",
|
|
131
|
+
props: {
|
|
132
|
+
jobs: { type: Object, required: true },
|
|
133
|
+
go: { type: Boolean, default: true },
|
|
134
|
+
},
|
|
135
|
+
setup: hosted((host, p) => mountModelJobs(host, p.jobs, { go: p.go }), (p) => [p.jobs, p.go]),
|
|
136
|
+
});
|
|
137
|
+
export const TranscribeQueue = defineComponent({
|
|
138
|
+
name: "TranscribeQueue",
|
|
139
|
+
props: { queue: { type: Object, required: true } },
|
|
140
|
+
setup: hosted((host, p) => mountTranscribeQueue(host, p.queue), (p) => [p.queue]),
|
|
141
|
+
});
|
|
142
|
+
export const MemoryInspector = defineComponent({
|
|
143
|
+
name: "MemoryInspector",
|
|
144
|
+
props: { recall: { type: Object, default: null } },
|
|
145
|
+
setup(props) {
|
|
146
|
+
const el = ref(null);
|
|
147
|
+
let m = null;
|
|
148
|
+
onMounted(() => (m = mountMemoryInspector(el.value, props.recall)));
|
|
149
|
+
watch(() => props.recall, (r) => m?.set(r));
|
|
150
|
+
onBeforeUnmount(() => m?.dispose());
|
|
151
|
+
return () => h("div", { ...contents, ref: el });
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
export const ChatList = defineComponent({
|
|
155
|
+
name: "ChatList",
|
|
156
|
+
props: { list: { type: Object, required: true }, label: { type: String, default: "chats" } },
|
|
157
|
+
setup: hosted((host, p) => mountChatList(host, p.list, { label: p.label }), (p) => [p.list]),
|
|
158
|
+
});
|
|
159
|
+
export const ContextMeter = defineComponent({
|
|
160
|
+
name: "ContextMeter",
|
|
161
|
+
props: { thread: { type: Object, required: true }, budget: { type: Number, default: 4096 }, system: { type: String, default: "" } },
|
|
162
|
+
setup: hosted((host, p) => mountContextMeter(host, p.thread, { budget: () => p.budget, system: () => p.system }), (p) => [p.thread]),
|
|
163
|
+
});
|
|
164
|
+
export const FrameView = defineComponent({
|
|
165
|
+
name: "FrameView",
|
|
166
|
+
props: {
|
|
167
|
+
source: { type: [String, Object], default: null },
|
|
168
|
+
results: { type: Object, default: () => ({}) },
|
|
169
|
+
mirror: { type: Boolean, default: false },
|
|
170
|
+
},
|
|
171
|
+
emits: ["view"],
|
|
172
|
+
setup(props, { emit }) {
|
|
173
|
+
const el = ref(null);
|
|
174
|
+
let view = null;
|
|
175
|
+
onMounted(() => {
|
|
176
|
+
view = mountFrameView(el.value, { mirror: props.mirror });
|
|
177
|
+
emit("view", view);
|
|
178
|
+
if (props.source)
|
|
179
|
+
void view.setSource(props.source).then(() => view?.setResults(props.results));
|
|
180
|
+
else
|
|
181
|
+
view.setResults(props.results);
|
|
182
|
+
});
|
|
183
|
+
watch(() => props.source, (s) => void view?.setSource(s ?? null));
|
|
184
|
+
watch(() => props.results, (r) => view?.setResults(r));
|
|
185
|
+
watch(() => props.mirror, (m) => view?.setMirror(m));
|
|
186
|
+
onBeforeUnmount(() => view?.dispose());
|
|
187
|
+
return () => h("div", { ...contents, ref: el });
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
export const CameraFeed = defineComponent({
|
|
191
|
+
name: "CameraFeed",
|
|
192
|
+
props: { fps: { type: Number, default: 4 } },
|
|
193
|
+
emits: ["feed", "frame"],
|
|
194
|
+
setup: hosted((host, p, emit) => {
|
|
195
|
+
const feed = mountCameraFeed(host, { fps: p.fps, onFrame: (v) => emit("frame", v) });
|
|
196
|
+
emit("feed", feed);
|
|
197
|
+
return feed;
|
|
198
|
+
}, (p) => [p.fps]),
|
|
199
|
+
});
|
package/how.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// how this works: the fold of the package page and of the suite tool. Plain data, no imports;
|
|
2
|
+
// checked by tsconfig.how.json, shipped in the tarball, never imported by the runtime entry.
|
|
3
|
+
const how: HowDoc = {
|
|
4
|
+
packages: ["@hackbuild/ai-views", "@hackbuild/models", "@hackbuild/chat", "@hackbuild/transcribe", "@hackbuild/vision"],
|
|
5
|
+
what: `views that bind the browser ai packages to hackbuild-ui: a model picker per job, a chat pane and composer, a drop first transcriber, a mask studio, a frame view and a camera feed. each ships as a vue component and a custom element.`,
|
|
6
|
+
how: [
|
|
7
|
+
`model picker: \`useModelPick(job)\` turns the records that do a job into picker rows fitted to this machine (size, gpu memory, where it runs, a speed word, a verdict, the uncensored and non commercial marks, the reason a row does not fit) and loads through @hackbuild/weights with progress. hackbuild-ui draws the closed line, the bar chip and the sheet; the view writes every word.`,
|
|
8
|
+
`chat: a thread streams from a @hackbuild/chat engine, keeps the reasoning in a fold, shows the memory each reply used, and offers copy and redo on the last reply. send is the one pink action and turns into stop while a reply streams.`,
|
|
9
|
+
`transcribe: the drop zone becomes the transcript. files queue and run one at a time; lines carry their time, edit in place with undo, and export as txt, srt, vtt and json once there is text.`,
|
|
10
|
+
`masks and frames: the mask studio adds a click segment model and segment everything to the hackbuild-ui mask editor's wand, brush and lasso, with undo, zoom and png exports. the frame view draws boxes, landmarks and a caption over a frame; the camera feed hands frames to the page.`,
|
|
11
|
+
],
|
|
12
|
+
install: "npm install @hackbuild/ai-views",
|
|
13
|
+
today: `git clone https://github.com/hackbuild/hackbuild-browser-ai
|
|
14
|
+
cd hackbuild-browser-ai && npm ci && npm run build
|
|
15
|
+
npm pack -w @hackbuild/ai-views`,
|
|
16
|
+
code: `import { define } from "@hackbuild/ai-views/elements";
|
|
17
|
+
define();
|
|
18
|
+
// <model-select job="chat" variant="chip"></model-select>
|
|
19
|
+
// <chat-pane id="chat"></chat-pane><chat-composer for="chat"></chat-composer>
|
|
20
|
+
document.querySelector("chat-pane").engine = engine; // a @hackbuild/chat engine
|
|
21
|
+
|
|
22
|
+
// or in vue
|
|
23
|
+
import { ModelSelect, ChatPane, Composer } from "@hackbuild/ai-views/vue";`,
|
|
24
|
+
links: { page: "https://hackbuild.github.io/hackbuild-browser-ai/views/", source: "https://github.com/hackbuild/hackbuild-browser-ai/tree/main/packages/ai-views" },
|
|
25
|
+
};
|
|
26
|
+
export default how;
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/ai-views",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Views that bind the browser AI packages to hackbuild-ui: a model picker per job, a chat pane and composer, a drop first transcriber, a mask studio, a frame view and a camera feed. Each ships as a Vue component and a custom element.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Moheeb Zara <hackbuildvideo@gmail.com>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/hackbuild/hackbuild-browser-ai.git",
|
|
11
|
+
"directory": "packages/ai-views"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./elements": {
|
|
23
|
+
"types": "./dist/elements.d.ts",
|
|
24
|
+
"import": "./dist/elements.js"
|
|
25
|
+
},
|
|
26
|
+
"./vue": {
|
|
27
|
+
"types": "./dist/vue.d.ts",
|
|
28
|
+
"import": "./dist/vue.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"how.ts",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"unpkg": "./dist/single/elements.iife.js",
|
|
38
|
+
"jsdelivr": "./dist/single/elements.iife.js",
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -b"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@hackbuild/ai-env": "0.1.1",
|
|
44
|
+
"@hackbuild/chat": "0.1.1",
|
|
45
|
+
"@hackbuild/embed": "0.1.2",
|
|
46
|
+
"@hackbuild/imagegen": "0.1.2",
|
|
47
|
+
"@hackbuild/memory": "0.1.2",
|
|
48
|
+
"@hackbuild/models": "0.2.0",
|
|
49
|
+
"@hackbuild/speak": "0.1.2",
|
|
50
|
+
"@hackbuild/transcribe": "0.1.2",
|
|
51
|
+
"@hackbuild/vision": "0.1.2",
|
|
52
|
+
"@hackbuild/weights": "0.1.1"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@virgilvox/hackbuild-ui": ">=0.10.0 <0.11.0",
|
|
56
|
+
"vue": "^3.4.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"vue": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|