@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/dist/vue.js ADDED
@@ -0,0 +1,221 @@
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
+ /** Vue component for a model picker of one job; emits `pick`, `choose`, `loaded` and `failed`. */
33
+ export const ModelSelect = defineComponent({
34
+ name: "ModelSelect",
35
+ props: {
36
+ job: { type: String, default: "chat" },
37
+ pick: { type: Object, default: undefined },
38
+ variant: { type: String, default: "line" },
39
+ go: { type: Boolean, default: true },
40
+ env: { type: Object, default: undefined },
41
+ loader: { type: Function, default: undefined },
42
+ },
43
+ emits: ["choose", "pick", "loaded", "failed"],
44
+ setup: hosted((host, p, emit) => {
45
+ const pick = p.pick ?? useModelPick(p.job, { ...(p.env ? { env: p.env } : {}), ...(p.loader ? { loader: p.loader } : {}) });
46
+ emit("pick", pick);
47
+ const was = new Map(pick.snapshot().rows.map((r) => [r.id, r.state]));
48
+ const off = pick.subscribe((s) => {
49
+ emit("choose", s.chosen);
50
+ for (const r of s.rows) {
51
+ if (was.get(r.id) === "loading" && r.state === "loaded")
52
+ emit("loaded", r.id, pick.result(r.id));
53
+ if (was.get(r.id) === "loading" && r.state === "error")
54
+ emit("failed", r.id, pick.error(r.id));
55
+ was.set(r.id, r.state);
56
+ }
57
+ });
58
+ const m = mountModelSelect(host, pick, { variant: p.variant, go: p.go });
59
+ return { dispose: () => (off(), m.dispose()) };
60
+ }, (p) => [p.job, p.pick, p.variant, p.go]),
61
+ });
62
+ /** Vue component for the turns of a chat thread. */
63
+ export const ChatPane = defineComponent({
64
+ name: "ChatPane",
65
+ props: {
66
+ thread: { type: Object, required: true },
67
+ name: { type: String, default: "reply" },
68
+ emptyName: { type: String, default: "what are we working on?" },
69
+ emptyNote: { type: String, default: "" },
70
+ },
71
+ setup: hosted((host, p) => mountChatPane(host, p.thread, { name: p.name, emptyName: p.emptyName, emptyNote: p.emptyNote }), (p) => [p.thread]),
72
+ });
73
+ /** Vue component for the message box of a chat thread. */
74
+ export const Composer = defineComponent({
75
+ name: "Composer",
76
+ props: { thread: { type: Object, required: true }, placeholder: { type: String, default: "say something" } },
77
+ setup: hosted((host, p) => mountComposer(host, p.thread, { placeholder: p.placeholder }), (p) => [p.thread]),
78
+ });
79
+ /** Vue component for the drop zone that becomes the transcript; emits `sample`. */
80
+ export const TranscribeDrop = defineComponent({
81
+ name: "TranscribeDrop",
82
+ props: {
83
+ queue: { type: Object, required: true },
84
+ accept: { type: String, default: "audio/*,video/*" },
85
+ sampleLabel: { type: String, default: "" },
86
+ },
87
+ emits: ["sample"],
88
+ setup: hosted((host, p, emit) => mountTranscribeDrop(host, p.queue, { accept: p.accept, ...(p.sampleLabel ? { sampleLabel: p.sampleLabel, onSample: () => emit("sample") } : {}) }), (p) => [p.queue]),
89
+ });
90
+ /** Vue component for the selected transcript, or its export buttons when `exports` is set. */
91
+ export const TranscriptView = defineComponent({
92
+ name: "TranscriptView",
93
+ props: { queue: { type: Object, required: true }, exports: { type: Boolean, default: false } },
94
+ setup: hosted((host, p) => (p.exports ? mountTranscriptExports(host, p.queue) : mountTranscriptView(host, p.queue)), (p) => [p.queue, p.exports]),
95
+ });
96
+ /**
97
+ * Vue component for a mask studio; emits `studio` with the mounted studio and `sample` when the
98
+ * sample button is pressed.
99
+ */
100
+ export const MaskStudio = defineComponent({
101
+ name: "MaskStudio",
102
+ props: { models: { type: Object, default: () => ({}) }, sampleLabel: { type: String, default: "" } },
103
+ emits: ["studio", "sample"],
104
+ setup(props, { emit }) {
105
+ const el = ref(null);
106
+ const studio = shallowRef(null);
107
+ onMounted(() => {
108
+ studio.value = mountMaskStudio(el.value, { models: props.models, ...(props.sampleLabel ? { sampleLabel: props.sampleLabel, onSample: () => emit("sample") } : {}) });
109
+ emit("studio", studio.value);
110
+ });
111
+ watch(() => props.models, (m) => studio.value?.setModels(m));
112
+ onBeforeUnmount(() => {
113
+ studio.value?.dispose();
114
+ });
115
+ // a page places the rail and verbs with MaskTools on the studio the studio event hands it
116
+ return () => h("div", { ...contents, ref: el });
117
+ },
118
+ });
119
+ /** Vue component for the tool rail of a mask studio. */
120
+ export const MaskTools = defineComponent({
121
+ name: "MaskTools",
122
+ props: { studio: { type: Object, required: true } },
123
+ setup: hosted((host, p) => mountMaskTools(host, p.studio), (p) => [p.studio]),
124
+ });
125
+ /** Vue component for the undo, redo and zoom row of a mask studio. */
126
+ export const MaskVerbs = defineComponent({
127
+ name: "MaskVerbs",
128
+ props: { studio: { type: Object, required: true } },
129
+ setup: hosted((host, p) => mountMaskVerbs(host, p.studio), (p) => [p.studio]),
130
+ });
131
+ /** Vue component for one rack part of a mask studio: found, mask, saved or export. */
132
+ export const MaskRack = defineComponent({
133
+ name: "MaskRack",
134
+ props: {
135
+ studio: { type: Object, required: true },
136
+ part: { type: String, default: "found" },
137
+ name: { type: String, default: "mask" },
138
+ },
139
+ setup: hosted((host, p) => mountMaskRack(host, p.studio, p.part, { name: p.name }), (p) => [p.studio, p.part]),
140
+ });
141
+ /** Vue component for a jobs rack: a line per job, presets and load all. */
142
+ export const ModelJobs = defineComponent({
143
+ name: "ModelJobs",
144
+ props: {
145
+ jobs: { type: Object, required: true },
146
+ go: { type: Boolean, default: true },
147
+ },
148
+ setup: hosted((host, p) => mountModelJobs(host, p.jobs, { go: p.go }), (p) => [p.jobs, p.go]),
149
+ });
150
+ /** Vue component for the file list of a transcribe queue. */
151
+ export const TranscribeQueue = defineComponent({
152
+ name: "TranscribeQueue",
153
+ props: { queue: { type: Object, required: true } },
154
+ setup: hosted((host, p) => mountTranscribeQueue(host, p.queue), (p) => [p.queue]),
155
+ });
156
+ /** Vue component that shows a recall trace as a table. */
157
+ export const MemoryInspector = defineComponent({
158
+ name: "MemoryInspector",
159
+ props: { recall: { type: Object, default: null } },
160
+ setup(props) {
161
+ const el = ref(null);
162
+ let m = null;
163
+ onMounted(() => (m = mountMemoryInspector(el.value, props.recall)));
164
+ watch(() => props.recall, (r) => m?.set(r));
165
+ onBeforeUnmount(() => m?.dispose());
166
+ return () => h("div", { ...contents, ref: el });
167
+ },
168
+ });
169
+ /** Vue component for the chat list rail of a `chatList`. */
170
+ export const ChatList = defineComponent({
171
+ name: "ChatList",
172
+ props: { list: { type: Object, required: true }, label: { type: String, default: "chats" } },
173
+ setup: hosted((host, p) => mountChatList(host, p.list, { label: p.label }), (p) => [p.list]),
174
+ });
175
+ /** Vue component that shows what the next request carries against the context budget. */
176
+ export const ContextMeter = defineComponent({
177
+ name: "ContextMeter",
178
+ props: { thread: { type: Object, required: true }, budget: { type: Number, default: 4096 }, system: { type: String, default: "" } },
179
+ setup: hosted((host, p) => mountContextMeter(host, p.thread, { budget: () => p.budget, system: () => p.system }), (p) => [p.thread]),
180
+ });
181
+ /**
182
+ * Vue component that draws a frame with boxes, landmarks and a caption; emits `view` with the
183
+ * mounted view.
184
+ */
185
+ export const FrameView = defineComponent({
186
+ name: "FrameView",
187
+ props: {
188
+ source: { type: [String, Object], default: null },
189
+ results: { type: Object, default: () => ({}) },
190
+ mirror: { type: Boolean, default: false },
191
+ },
192
+ emits: ["view"],
193
+ setup(props, { emit }) {
194
+ const el = ref(null);
195
+ let view = null;
196
+ onMounted(() => {
197
+ view = mountFrameView(el.value, { mirror: props.mirror });
198
+ emit("view", view);
199
+ if (props.source)
200
+ void view.setSource(props.source).then(() => view?.setResults(props.results));
201
+ else
202
+ view.setResults(props.results);
203
+ });
204
+ watch(() => props.source, (s) => void view?.setSource(s ?? null));
205
+ watch(() => props.results, (r) => view?.setResults(r));
206
+ watch(() => props.mirror, (m) => view?.setMirror(m));
207
+ onBeforeUnmount(() => view?.dispose());
208
+ return () => h("div", { ...contents, ref: el });
209
+ },
210
+ });
211
+ /** Vue component that opens the camera; emits `feed` with the feed and `frame` with the video at `fps`. */
212
+ export const CameraFeed = defineComponent({
213
+ name: "CameraFeed",
214
+ props: { fps: { type: Number, default: 4 } },
215
+ emits: ["feed", "frame"],
216
+ setup: hosted((host, p, emit) => {
217
+ const feed = mountCameraFeed(host, { fps: p.fps, onFrame: (v) => emit("frame", v) });
218
+ emit("feed", feed);
219
+ return feed;
220
+ }, (p) => [p.fps]),
221
+ });
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;