@hanzo/studio 0.1.21 → 0.1.23
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/lib/app/director.d.ts +2 -1
- package/lib/app/director.js +51 -47
- package/lib/app/flow-kept.d.ts +22 -0
- package/lib/app/flow-kept.js +32 -0
- package/lib/app/flow.d.ts +6 -9
- package/lib/app/flow.js +50 -138
- package/lib/app/sections.d.ts +1 -3
- package/lib/app/sections.js +1 -8
- package/lib/attach.d.ts +5 -2
- package/lib/attach.js +8 -4
- package/lib/chat/turn.d.ts +3 -0
- package/lib/chat/turn.js +18 -7
- package/lib/desk.js +3 -53
- package/lib/home.d.ts +13 -0
- package/lib/home.js +7 -4
- package/lib/host.d.ts +18 -2
- package/lib/host.js +26 -3
- package/lib/index.d.ts +4 -2
- package/lib/index.js +2 -2
- package/lib/kinds/ad.js +4 -0
- package/lib/kinds/document.d.ts +16 -1
- package/lib/kinds/document.js +20 -7
- package/lib/kinds/image.js +19 -81
- package/lib/kinds/kind.d.ts +5 -2
- package/lib/kinds/mesh/index.js +11 -4
- package/lib/kinds/poster/index.js +6 -0
- package/lib/kinds/sound.d.ts +2 -0
- package/lib/kinds/sound.js +17 -1
- package/lib/kinds/video.d.ts +2 -0
- package/lib/kinds/video.js +26 -136
- package/lib/live.d.ts +3 -2
- package/lib/live.js +10 -3
- package/lib/nav.js +1 -2
- package/lib/places.d.ts +0 -1
- package/lib/places.js +10 -78
- package/lib/route.d.ts +5 -5
- package/lib/route.js +5 -5
- package/lib/spend.d.ts +44 -0
- package/lib/spend.js +68 -0
- package/lib/studio.d.ts +2 -18
- package/lib/studio.js +16 -3
- package/lib/talk.js +20 -9
- package/lib/wire.d.ts +6 -22
- package/lib/wire.js +11 -27
- package/package.json +1 -1
package/lib/places.js
CHANGED
|
@@ -1,91 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
3
|
-
* The places beside the conversation:
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* The places beside the conversation: Explore (every starter, and what each
|
|
4
|
+
* needs) and Activity (what is making or rendering now). What was made is in
|
|
5
|
+
* the app's one Library, which lists every kind (`/v1/library`).
|
|
6
6
|
*/
|
|
7
7
|
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
8
|
-
import { ChevronDown,
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { ChevronDown, Search, X } from '@hanzogui/lucide-icons-2';
|
|
9
|
+
import { DropdownMenu } from '@hanzo/ui';
|
|
10
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
11
11
|
import { useHost } from './host.js';
|
|
12
12
|
import { ALL, kind } from './kinds/index.js';
|
|
13
|
-
import { useAvailable, useChats,
|
|
13
|
+
import { useAvailable, useChats, useWire } from './live.js';
|
|
14
14
|
import { path } from './route.js';
|
|
15
15
|
import { CATEGORIES, queue, RUNTIME, STARTERS } from './starters.js';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { ask, discard, fileAt, shelf } from './wire.js';
|
|
16
|
+
import { Pill, RING } from './ui.js';
|
|
17
|
+
import { ask } from './wire.js';
|
|
19
18
|
function Page({ title, children, right }) {
|
|
20
19
|
return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", bg: "var(--pane-fill, var(--sheet-1))", rounded: "var(--pane-round, var(--radius-xl))", borderWidth: 1, borderColor: "var(--pane-edge, var(--border))", children: _jsxs(YStack, { width: "100%", maxW: 1160, mx: "auto", p: "$4", gap: "$4", children: [_jsxs(XStack, { items: "center", gap: "$3", flexWrap: "wrap", children: [_jsx(SizableText, { render: "h1", size: "$7", fontWeight: "600", color: "$ink", flex: 1, letterSpacing: -0.6, children: title }), right] }), children] }) }));
|
|
21
20
|
}
|
|
22
|
-
/* ----------------------------------------------------------------- library */
|
|
23
|
-
/** The Studio kind whose mark a Library kind wears. */
|
|
24
|
-
const MARK = { image: 'image', video: 'video', audio: 'voice', document: 'document', slides: 'slides', type: 'type', model: 'mesh' };
|
|
25
|
-
export function Library() {
|
|
26
|
-
const host = useHost();
|
|
27
|
-
const wire = useWire(host);
|
|
28
|
-
const [items, setItems] = useState(null);
|
|
29
|
-
const [error, setError] = useState('');
|
|
30
|
-
const [only, setOnly] = useState('all');
|
|
31
|
-
const [q, setQ] = useState('');
|
|
32
|
-
const [pendingDelete, setPendingDelete] = useState(null);
|
|
33
|
-
const [deleting, setDeleting] = useState(false);
|
|
34
|
-
useLibrary(wire);
|
|
35
|
-
const reload = useCallback(() => {
|
|
36
|
-
setError('');
|
|
37
|
-
shelf(wire).then(setItems, (e) => setError(e instanceof Error ? e.message : String(e)));
|
|
38
|
-
}, [wire]);
|
|
39
|
-
useEffect(reload, [reload]);
|
|
40
|
-
const kinds = useMemo(() => [...new Set((items ?? []).map((i) => i.kind))], [items]);
|
|
41
|
-
const shown = (items ?? []).filter((i) => (only === 'all' || i.kind === only) && (!q || i.name.toLowerCase().includes(q.toLowerCase())));
|
|
42
|
-
const confirmDelete = () => {
|
|
43
|
-
if (!pendingDelete || deleting)
|
|
44
|
-
return;
|
|
45
|
-
const target = pendingDelete;
|
|
46
|
-
setDeleting(true);
|
|
47
|
-
void discard(wire, target.id)
|
|
48
|
-
.then(() => {
|
|
49
|
-
setPendingDelete(null);
|
|
50
|
-
reload();
|
|
51
|
-
})
|
|
52
|
-
.catch((e) => {
|
|
53
|
-
setError(e instanceof Error ? e.message : String(e));
|
|
54
|
-
setPendingDelete(null);
|
|
55
|
-
})
|
|
56
|
-
.finally(() => setDeleting(false));
|
|
57
|
-
};
|
|
58
|
-
return (_jsxs(Page, { title: "Library", right: _jsxs(XStack, { items: "center", gap: "$2", minH: 44, $md: { minH: 34, height: 34 }, px: "$3", rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", minW: 220, children: [_jsx(Search, { size: 14, color: "$soft" }), _jsx("input", { "aria-label": "Search the library", placeholder: "Search", value: q, onChange: (e) => setQ(e.currentTarget.value), style: { flex: 1, minWidth: 0, border: 0, background: 'transparent', color: 'var(--foreground)', font: 'inherit', outline: 'none' } }), q ? (_jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Clear search", onClick: () => setQ(''), width: 22, height: 22, "$max-sm": { minW: 44, minH: 44 }, rounded: 99, items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(X, { size: 12, color: "$soft" }) })) : null] }), children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$2", flexWrap: "wrap", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: "Saved to your Library, private to you until you share it." }), items ? (_jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$soft", children: `${shown.length} of ${items.length} ${items.length === 1 ? 'item' : 'items'}` })) : null] }), _jsxs(XStack, { gap: "$2", flexWrap: "wrap", role: "toolbar", "aria-label": "Kinds", children: [_jsx(Pill, { label: "All", on: only === 'all', count: only === 'all' && items ? items.length : undefined, onPress: () => setOnly('all'), children: "All" }), kinds.map((k) => {
|
|
59
|
-
const label = MARK[k] ? kind(MARK[k]).label : k;
|
|
60
|
-
const count = (items ?? []).filter((i) => i.kind === k).length;
|
|
61
|
-
return (_jsx(Pill, { label: label, on: only === k, count: only === k ? count : undefined, onPress: () => setOnly(k), children: label }, k));
|
|
62
|
-
})] }), error ? _jsx(SizableText, { color: "var(--state-error)", children: error }) : null, items === null && !error ? _jsx(SizableText, { color: "$soft", children: "Reading\u2026" }) : null, items && !shown.length ? _jsx(SizableText, { color: "$soft", children: items.length ? 'Nothing matches.' : 'Nothing made yet. Start on the home page.' }) : null, _jsx(XStack, { flexWrap: "wrap", gap: 12, role: "list", "aria-label": "Made", children: shown.map((i) => (_jsx(Thing, { item: i, deleting: deleting && pendingDelete?.id === i.id, onOpen: () => host.go(path({ kind: 'chat', id: i.ref })), onRequestDelete: () => setPendingDelete(i) }, i.id))) }), _jsx(AlertDialog, { open: Boolean(pendingDelete), onOpenChange: (open) => {
|
|
63
|
-
if (!open && !deleting)
|
|
64
|
-
setPendingDelete(null);
|
|
65
|
-
}, children: _jsxs(AlertDialogContent, { borderColor: "var(--border-strong)", maxW: 420, children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: "Delete from Library?" }), _jsx(AlertDialogDescription, { children: pendingDelete
|
|
66
|
-
? `Delete “${pendingDelete.name.replace(/\.[a-z0-9.]+$/i, '').replace(/-/g, ' ')}” from your Library? Its conversation keeps the record.`
|
|
67
|
-
: '' })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: deleting, borderColor: "var(--border-strong)", onPress: () => setPendingDelete(null), children: "Cancel" }), _jsx(AlertDialogAction, { variant: "destructive", bg: "var(--state-error)", disabled: deleting, onPress: confirmDelete, children: deleting ? 'Deleting…' : 'Delete' })] })] }) })] }));
|
|
68
|
-
}
|
|
69
|
-
function Thing({ item, deleting, onOpen, onRequestDelete, }) {
|
|
70
|
-
const Icon = kind(MARK[item.kind] ?? 'image').icon;
|
|
71
|
-
const pic = item.mime.startsWith('image/') ? item.url : '';
|
|
72
|
-
const name = item.name;
|
|
73
|
-
const [downloadError, setDownloadError] = useState('');
|
|
74
|
-
const handleDownload = () => {
|
|
75
|
-
const href = item.download || item.url;
|
|
76
|
-
if (!href) {
|
|
77
|
-
setDownloadError('Download unavailable for this file.');
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
setDownloadError('');
|
|
81
|
-
void fileAt(href)
|
|
82
|
-
.then((b) => download(name, b))
|
|
83
|
-
.catch((e) => {
|
|
84
|
-
setDownloadError(e instanceof Error ? e.message : 'Download failed.');
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
return (_jsxs(YStack, { role: "listitem", width: "calc(50% - 6px)", $sm: { width: 'calc(25% - 9px)' }, gap: "$1.5", children: [_jsxs(YStack, { render: _jsx("button", { type: "button" }), "aria-label": `Open ${name} in its conversation`, onClick: onOpen, rounded: 16, overflow: "hidden", bg: "var(--surface-card)", borderWidth: 1, borderColor: "var(--border)", cursor: "pointer", style: { aspectRatio: '4 / 5' }, items: "center", justify: "center", position: "relative", focusVisibleStyle: RING_INSET, children: [pic ? (_jsx("img", { src: pic, alt: "", style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } })) : (_jsx(XStack, { "$platform-web": { color: 'var(--muted-foreground)' }, children: _jsx(Icon, { size: 28 }) })), _jsx(XStack, { "aria-hidden": true, position: "absolute", t: 8, l: 8, width: 26, height: 26, rounded: 99, bg: "var(--surface-header)", borderWidth: 1, borderColor: "var(--border)", items: "center", justify: "center", "$platform-web": { color: 'var(--foreground)' }, children: _jsx(Icon, { size: 13 }) })] }), _jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, flex: 1, children: name.replace(/\.[a-z0-9.]+$/i, '').replace(/-/g, ' ') }), _jsx(Act, { label: `Download ${name}`, onPress: handleDownload, children: _jsx(Download, { size: 13, color: "$ink" }) }), _jsx(Act, { label: `Delete ${name}`, disabled: deleting, onPress: onRequestDelete, children: _jsx(Trash2, { size: 13, color: "$ink" }) })] }), _jsx(SizableText, { size: "$1", color: "$soft", children: `${MARK[item.kind] ? kind(MARK[item.kind]).label : item.kind} · ${new Date(item.created).toLocaleDateString()}` }), downloadError ? (_jsx(SizableText, { role: "alert", size: "$1", color: "var(--state-error)", numberOfLines: 2, children: downloadError })) : null] }));
|
|
88
|
-
}
|
|
89
21
|
/* ----------------------------------------------------------------- explore */
|
|
90
22
|
const EXPLORE_PRIMARY_CATS = ['all', 'image', 'poster', 'video', 'document', 'audio'];
|
|
91
23
|
export function Explore() {
|
|
@@ -221,7 +153,7 @@ export function Explore() {
|
|
|
221
153
|
return;
|
|
222
154
|
queue(s);
|
|
223
155
|
host.go('');
|
|
224
|
-
}, width: "100%", minH: 78, p: "$3", gap: "$1.5", rounded: "$4", borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", opacity: why ? 0.6 : 1, cursor: why ? 'default' : 'pointer', items: "flex-start", hoverStyle: why ? undefined : { bg: '$hover' }, focusVisibleStyle: RING, children: [_jsxs(XStack, { justify: "space-between", width: "100%", gap: "$2", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", text: "left", numberOfLines: 1, flex: 1, children: s.title }), _jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$soft", shrink: 0, children: RUNTIME[s.kind] })] }), _jsx(SizableText, { size: "$1", color: "$soft", text: "left", numberOfLines: 2, children: why
|
|
156
|
+
}, width: "100%", minH: 78, p: "$3", gap: "$1.5", rounded: "$4", borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", opacity: why ? 0.6 : 1, cursor: why ? 'default' : 'pointer', items: "flex-start", hoverStyle: why ? undefined : { bg: '$hover' }, focusVisibleStyle: RING, children: [_jsxs(XStack, { justify: "space-between", width: "100%", gap: "$2", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", text: "left", numberOfLines: 1, flex: 1, children: s.title }), _jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$soft", shrink: 0, children: RUNTIME[s.kind] })] }), _jsx(SizableText, { size: "$1", color: "$soft", text: "left", numberOfLines: 2, children: why ?? s.subtitle })] }) }, s.id));
|
|
225
157
|
}) })] }, c.id));
|
|
226
158
|
}), _jsxs(YStack, { gap: "$2", pt: "$2", borderTopWidth: 1, borderColor: "var(--border)", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", color: "$ink", children: "Kinds" }), ALL.map((k) => (_jsxs(XStack, { gap: "$3", items: "center", children: [_jsx(XStack, { "$platform-web": { color: 'var(--foreground)' }, shrink: 0, children: _jsx(k.icon, { size: 15 }) }), _jsx(SizableText, { size: "$2", color: "$ink", width: 120, children: k.label }), _jsx(SizableText, { size: "$2", color: "$soft", flex: 1, children: k.needs(available) ?? k.blurb })] }, k.id)))] })] }));
|
|
227
159
|
}
|
package/lib/route.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Studio's addresses, said once. The host hands Studio the path under its
|
|
3
3
|
* mount (`Host.path`, no leading slash) and moves it with `Host.go`; hanzo.ai
|
|
4
|
-
* mounts Studio at /
|
|
5
|
-
* grammar reads both.
|
|
4
|
+
* mounts Studio at /design (its old /studio opens Design there) and
|
|
5
|
+
* studio.hanzo.ai at its root, so the same grammar reads both.
|
|
6
6
|
*
|
|
7
7
|
* '' New: the composer and the starters
|
|
8
8
|
* c/<id> one conversation, its tabs beside it
|
|
9
|
-
* library everything this org has made
|
|
10
9
|
* explore the starters, every kind, with what each needs
|
|
11
10
|
* activity what is rendering, queued, done or failed
|
|
12
11
|
*
|
|
12
|
+
* What was made is in the host's one Library (the Hanzo app's /library, which
|
|
13
|
+
* /design/library also opens there): Design keeps no Library of its own.
|
|
14
|
+
*
|
|
13
15
|
* `?starter=<id>` in the page's query starts New from that starter (`starting`
|
|
14
16
|
* writes it, `starter` reads it). The query is not the host's (`Host.path` is
|
|
15
17
|
* the path alone), so the conversation reads it from the page once and takes it
|
|
@@ -25,8 +27,6 @@ export type Route = {
|
|
|
25
27
|
} | {
|
|
26
28
|
kind: 'chat';
|
|
27
29
|
id: string;
|
|
28
|
-
} | {
|
|
29
|
-
kind: 'library';
|
|
30
30
|
} | {
|
|
31
31
|
kind: 'explore';
|
|
32
32
|
} | {
|
package/lib/route.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Studio's addresses, said once. The host hands Studio the path under its
|
|
3
3
|
* mount (`Host.path`, no leading slash) and moves it with `Host.go`; hanzo.ai
|
|
4
|
-
* mounts Studio at /
|
|
5
|
-
* grammar reads both.
|
|
4
|
+
* mounts Studio at /design (its old /studio opens Design there) and
|
|
5
|
+
* studio.hanzo.ai at its root, so the same grammar reads both.
|
|
6
6
|
*
|
|
7
7
|
* '' New: the composer and the starters
|
|
8
8
|
* c/<id> one conversation, its tabs beside it
|
|
9
|
-
* library everything this org has made
|
|
10
9
|
* explore the starters, every kind, with what each needs
|
|
11
10
|
* activity what is rendering, queued, done or failed
|
|
12
11
|
*
|
|
12
|
+
* What was made is in the host's one Library (the Hanzo app's /library, which
|
|
13
|
+
* /design/library also opens there): Design keeps no Library of its own.
|
|
14
|
+
*
|
|
13
15
|
* `?starter=<id>` in the page's query starts New from that starter (`starting`
|
|
14
16
|
* writes it, `starter` reads it). The query is not the host's (`Host.path` is
|
|
15
17
|
* the path alone), so the conversation reads it from the page once and takes it
|
|
@@ -31,8 +33,6 @@ export function route(at) {
|
|
|
31
33
|
return { kind: 'new' };
|
|
32
34
|
if (head === 'c' && rest && ID.test(rest))
|
|
33
35
|
return { kind: 'chat', id: rest };
|
|
34
|
-
if (head === 'library' && !rest)
|
|
35
|
-
return { kind: 'library' };
|
|
36
36
|
if (head === 'explore' && !rest)
|
|
37
37
|
return { kind: 'explore' };
|
|
38
38
|
if (head === 'activity' && !rest)
|
package/lib/spend.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asking before money is spent. Every paid generation, GPU render, and Flow Run
|
|
3
|
+
* or Mutate asks first: through the host's one spend confirm (`host.spend`, the
|
|
4
|
+
* Hanzo app's) or, on a host that has none, through Studio's own (`asker`, drawn
|
|
5
|
+
* by host.tsx with the kit's AlertDialog). Never silently. A no starts nothing.
|
|
6
|
+
*
|
|
7
|
+
* `kind` is the spend's kind as the Hanzo app files it (one yes never waves
|
|
8
|
+
* another kind through there); `asked` the title and sentence for this one.
|
|
9
|
+
*/
|
|
10
|
+
export interface Asked {
|
|
11
|
+
title?: string;
|
|
12
|
+
what?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Whether the person said yes to this spend. */
|
|
15
|
+
export type Spend = (kind: string, asked?: Asked) => Promise<boolean>;
|
|
16
|
+
/** The person said no to a spend: nothing was started, and nothing is said to have failed. */
|
|
17
|
+
export declare class Declined extends Error {
|
|
18
|
+
constructor();
|
|
19
|
+
}
|
|
20
|
+
/** Ask before a paid call starts. A no throws `Declined`, so nothing starts. */
|
|
21
|
+
export declare function spend(w: {
|
|
22
|
+
spend: Spend;
|
|
23
|
+
}, kind: string, asked?: Asked): Promise<void>;
|
|
24
|
+
/** A question on screen: what it is, the sentence under it, and the word on its yes. */
|
|
25
|
+
export interface Question {
|
|
26
|
+
title: string;
|
|
27
|
+
what: string;
|
|
28
|
+
yes: string;
|
|
29
|
+
}
|
|
30
|
+
/** The spends Studio makes, in the words the Hanzo app's confirm uses for each. A kind not here is never started. */
|
|
31
|
+
export declare const WORDS: Record<string, Question>;
|
|
32
|
+
/**
|
|
33
|
+
* Studio's own confirm, one question at a time: `ask` shows one (`show`) and
|
|
34
|
+
* answers once the person does (`answer`). A new question answers the one
|
|
35
|
+
* still open no, so a second press never leaves a spend waiting behind it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function asker(show: (q: Question | null) => void): {
|
|
38
|
+
ask: Spend;
|
|
39
|
+
answer: (yes: boolean) => void;
|
|
40
|
+
};
|
|
41
|
+
/** Run `run` unless one is already running under `lock`: a second press while the first asks or runs starts nothing. */
|
|
42
|
+
export declare function alone(lock: {
|
|
43
|
+
current: boolean;
|
|
44
|
+
}, run: () => Promise<void>): Promise<void>;
|
package/lib/spend.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asking before money is spent. Every paid generation, GPU render, and Flow Run
|
|
3
|
+
* or Mutate asks first: through the host's one spend confirm (`host.spend`, the
|
|
4
|
+
* Hanzo app's) or, on a host that has none, through Studio's own (`asker`, drawn
|
|
5
|
+
* by host.tsx with the kit's AlertDialog). Never silently. A no starts nothing.
|
|
6
|
+
*
|
|
7
|
+
* `kind` is the spend's kind as the Hanzo app files it (one yes never waves
|
|
8
|
+
* another kind through there); `asked` the title and sentence for this one.
|
|
9
|
+
*/
|
|
10
|
+
/** The person said no to a spend: nothing was started, and nothing is said to have failed. */
|
|
11
|
+
export class Declined extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('Not started.');
|
|
14
|
+
this.name = 'Declined';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Ask before a paid call starts. A no throws `Declined`, so nothing starts. */
|
|
18
|
+
export async function spend(w, kind, asked) {
|
|
19
|
+
if (!(await w.spend(kind, asked)))
|
|
20
|
+
throw new Declined();
|
|
21
|
+
}
|
|
22
|
+
/** The spends Studio makes, in the words the Hanzo app's confirm uses for each. A kind not here is never started. */
|
|
23
|
+
export const WORDS = {
|
|
24
|
+
'design-image': { title: 'Make this picture?', what: 'This makes one picture.', yes: 'Make it' },
|
|
25
|
+
'design-video': { title: 'Make this clip?', what: 'This makes one short video clip, which keeps rendering if you leave this page.', yes: 'Make clip' },
|
|
26
|
+
'design-gpu': { title: 'Render on your GPU?', what: "This renders on your organization's GPU, where it keeps going if you leave this page.", yes: 'Start render' },
|
|
27
|
+
voice: { title: 'Read this aloud?', what: "This makes speech from your words with the platform's voice.", yes: 'Read it' },
|
|
28
|
+
document: { title: 'Make this document?', what: 'This makes one document from your brief.', yes: 'Make it' },
|
|
29
|
+
'flow-run': { title: 'Run this flow?', what: 'This queues the flow on the GPU, where it keeps running if you leave this page.', yes: 'Run flow' },
|
|
30
|
+
'flow-mutate': { title: 'Ask Copilot to change the flow?', what: 'This sends your words and the flow to a model.', yes: 'Ask Copilot' },
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Studio's own confirm, one question at a time: `ask` shows one (`show`) and
|
|
34
|
+
* answers once the person does (`answer`). A new question answers the one
|
|
35
|
+
* still open no, so a second press never leaves a spend waiting behind it.
|
|
36
|
+
*/
|
|
37
|
+
export function asker(show) {
|
|
38
|
+
let open = null;
|
|
39
|
+
const answer = (yes) => {
|
|
40
|
+
const was = open;
|
|
41
|
+
open = null;
|
|
42
|
+
if (!was)
|
|
43
|
+
return;
|
|
44
|
+
show(null);
|
|
45
|
+
was.done(yes);
|
|
46
|
+
};
|
|
47
|
+
const ask = (kind, asked) => new Promise((done) => {
|
|
48
|
+
const words = WORDS[kind];
|
|
49
|
+
if (!words)
|
|
50
|
+
return done(false);
|
|
51
|
+
answer(false);
|
|
52
|
+
open = { done };
|
|
53
|
+
show({ title: asked?.title || words.title, what: `${asked?.what || words.what} It counts against your plan or your credits.`, yes: words.yes });
|
|
54
|
+
});
|
|
55
|
+
return { ask, answer };
|
|
56
|
+
}
|
|
57
|
+
/** Run `run` unless one is already running under `lock`: a second press while the first asks or runs starts nothing. */
|
|
58
|
+
export async function alone(lock, run) {
|
|
59
|
+
if (lock.current)
|
|
60
|
+
return;
|
|
61
|
+
lock.current = true;
|
|
62
|
+
try {
|
|
63
|
+
await run();
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
lock.current = false;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/lib/studio.d.ts
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
* Studio: a chat that makes things, every result in a tab beside it.
|
|
3
|
-
*
|
|
4
|
-
* Mount `<Studio host={…} />` under a gui root, in a box with a height. The
|
|
5
|
-
* host is @hanzo/build's `Host`, the same value Dev takes: where the platform
|
|
6
|
-
* is, who is signed in, the org, the address under the mount and how to move
|
|
7
|
-
* it. studio.hanzo.ai mounts it whole, with its own rail. The Hanzo app mounts
|
|
8
|
-
* it with `rail={false}` at /studio and draws Studio's places (`nav`) in its
|
|
9
|
-
* own column: one left column, never two.
|
|
10
|
-
*
|
|
11
|
-
* '' New: what should we create?, and the starters
|
|
12
|
-
* c/<id> a conversation and its tabs
|
|
13
|
-
* library everything made
|
|
14
|
-
* explore every starter and kind
|
|
15
|
-
* activity what is rendering
|
|
16
|
-
*/
|
|
17
|
-
import type { Host } from '@hanzo/build';
|
|
1
|
+
import { type Hosted } from './host.tsx';
|
|
18
2
|
/**
|
|
19
3
|
* Studio. `rail={false}` leaves the left column to the host, which lists
|
|
20
4
|
* Studio's places with `nav`; Studio is then a pane of the host's and paints
|
|
21
5
|
* no ground of its own.
|
|
22
6
|
*/
|
|
23
7
|
export declare function Studio({ host, rail }: {
|
|
24
|
-
host:
|
|
8
|
+
host: Hosted;
|
|
25
9
|
rail?: boolean;
|
|
26
10
|
}): import("react").JSX.Element;
|
package/lib/studio.js
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Studio: a chat that makes things, every result in a tab beside it.
|
|
4
|
+
*
|
|
5
|
+
* Mount `<Studio host={…} />` under a gui root, in a box with a height. The
|
|
6
|
+
* host is @hanzo/build's `Host`, the same value Dev takes: where the platform
|
|
7
|
+
* is, who is signed in, the org, the address under the mount and how to move
|
|
8
|
+
* it. studio.hanzo.ai mounts it whole, with its own rail. The Hanzo app mounts
|
|
9
|
+
* it with `rail={false}` at /design and draws Studio's places (`nav`) in its
|
|
10
|
+
* own column: one left column, never two.
|
|
11
|
+
*
|
|
12
|
+
* '' New: what should we create?, and the starters
|
|
13
|
+
* c/<id> a conversation and its tabs
|
|
14
|
+
* explore every starter and kind
|
|
15
|
+
* activity what is rendering
|
|
16
|
+
*/
|
|
2
17
|
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
3
18
|
import { SessionRail } from '@hanzo/ui/chat';
|
|
4
19
|
import { useState } from 'react';
|
|
5
20
|
import { StudioHost, useHost } from './host.js';
|
|
6
21
|
import { useChats, useWire } from './live.js';
|
|
7
22
|
import { nav, NEW } from './nav.js';
|
|
8
|
-
import { Activity, Explore
|
|
23
|
+
import { Activity, Explore } from './places.js';
|
|
9
24
|
import { path, route } from './route.js';
|
|
10
25
|
import { Talk } from './talk.js';
|
|
11
26
|
const DOT = { making: 'running', done: 'done', failed: 'error' };
|
|
@@ -15,8 +30,6 @@ function Pane() {
|
|
|
15
30
|
if (!host.person) {
|
|
16
31
|
return (_jsxs(YStack, { flex: 1, items: "center", justify: "center", gap: "$3", p: "$5", children: [_jsx(SizableText, { color: "$soft", children: "Sign in to create." }), host.signIn ? (_jsx(XStack, { render: "button", onPress: () => host.signIn?.(), px: "$4", height: 36, items: "center", rounded: 999, bg: "$ink", cursor: "pointer", children: _jsx(SizableText, { size: "$2", color: "$background", children: "Sign in" }) })) : null] }));
|
|
17
32
|
}
|
|
18
|
-
if (r.kind === 'library')
|
|
19
|
-
return _jsx(Library, {});
|
|
20
33
|
if (r.kind === 'explore')
|
|
21
34
|
return _jsx(Explore, {});
|
|
22
35
|
if (r.kind === 'activity')
|
package/lib/talk.js
CHANGED
|
@@ -29,6 +29,7 @@ import { PRESETS } from './kinds/type/system.js';
|
|
|
29
29
|
import { BRAIN, touch, useAvailable, useLibrary, useWire, WRITER } from './live.js';
|
|
30
30
|
import { blank, current } from './made.js';
|
|
31
31
|
import { path } from './route.js';
|
|
32
|
+
import { alone, Declined } from './spend.js';
|
|
32
33
|
import { take } from './starters.js';
|
|
33
34
|
import { about, bare, named, readPage, shown, sourced } from './source.js';
|
|
34
35
|
import { useUrl } from './use.js';
|
|
@@ -199,7 +200,10 @@ function Conversation({ start, host, wire, available }) {
|
|
|
199
200
|
if (typeof window !== 'undefined')
|
|
200
201
|
window.requestAnimationFrame(() => document.querySelector('[data-slot="source-field"] input')?.focus());
|
|
201
202
|
};
|
|
202
|
-
|
|
203
|
+
// A second press before the first one's render has drawn `working` starts nothing: the lock is synchronous.
|
|
204
|
+
const sending = useRef(false);
|
|
205
|
+
const send = (text, how = {}) => alone(sending, () => sendNow(text, how));
|
|
206
|
+
const sendNow = async (text, how) => {
|
|
203
207
|
const words = text.trim();
|
|
204
208
|
if (!words && !attached.length && !sources.length)
|
|
205
209
|
return;
|
|
@@ -253,6 +257,7 @@ function Conversation({ start, host, wire, available }) {
|
|
|
253
257
|
show,
|
|
254
258
|
changed,
|
|
255
259
|
signal: ctl.signal,
|
|
260
|
+
spend: host.spend,
|
|
256
261
|
});
|
|
257
262
|
persist(end, true);
|
|
258
263
|
}
|
|
@@ -343,8 +348,8 @@ function Conversation({ start, host, wire, available }) {
|
|
|
343
348
|
return;
|
|
344
349
|
setUploadError('');
|
|
345
350
|
setUploading((n) => n + batch.length);
|
|
346
|
-
|
|
347
|
-
|
|
351
|
+
// Six at a time: any past the sixth are named as left out, never dropped in silence.
|
|
352
|
+
const failedNames = files.slice(6).map((f) => f.name || 'file');
|
|
348
353
|
for (const f of batch) {
|
|
349
354
|
try {
|
|
350
355
|
const mime = inferMime(f);
|
|
@@ -356,18 +361,21 @@ function Conversation({ start, host, wire, available }) {
|
|
|
356
361
|
setAttached((a) => [...a, { key, mime, name, width: bmp?.width, height: bmp?.height }]);
|
|
357
362
|
bmp?.close();
|
|
358
363
|
}
|
|
359
|
-
catch
|
|
364
|
+
catch {
|
|
365
|
+
// Said as the file that was left out, never the server's words.
|
|
360
366
|
failedNames.push(f.name || 'file');
|
|
361
|
-
lastReason = e instanceof Error ? e.message : String(e);
|
|
362
367
|
}
|
|
363
368
|
finally {
|
|
364
369
|
setUploading((n) => n - 1);
|
|
365
370
|
}
|
|
366
371
|
}
|
|
367
|
-
setUploadError(uploadFailure(failedNames
|
|
372
|
+
setUploadError(uploadFailure(failedNames));
|
|
368
373
|
};
|
|
369
374
|
const pick = (m, at) => changed({ ...latest.current, made: latest.current.made.map((x) => (x.id === m.id ? { ...x, at } : x)) });
|
|
370
|
-
|
|
375
|
+
// One edit of a tab at a time: Redraw pressed twice starts one.
|
|
376
|
+
const editLocks = useRef({});
|
|
377
|
+
const editOne = (m, patch, note) => alone((editLocks.current[m.id] ??= { current: false }), () => editNow(m, patch, note));
|
|
378
|
+
const editNow = async (m, patch, note) => {
|
|
371
379
|
setEditing((e) => ({ ...e, [m.id]: true }));
|
|
372
380
|
setEditFailed((e) => ({ ...e, [m.id]: '' }));
|
|
373
381
|
try {
|
|
@@ -380,10 +388,13 @@ function Conversation({ start, host, wire, available }) {
|
|
|
380
388
|
order: () => order.current,
|
|
381
389
|
changed,
|
|
382
390
|
signal: new AbortController().signal,
|
|
391
|
+
spend: host.spend,
|
|
383
392
|
});
|
|
384
393
|
}
|
|
385
394
|
catch (e) {
|
|
386
|
-
|
|
395
|
+
// A no to the spend changed nothing, so nothing is said to have failed.
|
|
396
|
+
if (!(e instanceof Declined))
|
|
397
|
+
setEditFailed((x) => ({ ...x, [m.id]: e instanceof Error ? e.message : String(e) }));
|
|
387
398
|
}
|
|
388
399
|
finally {
|
|
389
400
|
setEditing((x) => ({ ...x, [m.id]: false }));
|
|
@@ -431,7 +442,7 @@ function Conversation({ start, host, wire, available }) {
|
|
|
431
442
|
{ key: 'auto', label: 'Auto', description: 'Design picks from what you ask', selected: picked === null, onSelect: () => setPicked(null) },
|
|
432
443
|
...ALL.map((k) => {
|
|
433
444
|
const why = k.needs(available);
|
|
434
|
-
return { key: k.id, label: k.label, description: why ? '
|
|
445
|
+
return { key: k.id, label: k.label, description: why ? 'Not available right now' : k.blurb, selected: picked === k.id, disabled: Boolean(why), onSelect: () => setPicked(k.id) };
|
|
435
446
|
}),
|
|
436
447
|
];
|
|
437
448
|
const brandName = brandOf(chat);
|
package/lib/wire.d.ts
CHANGED
|
@@ -135,8 +135,6 @@ export declare const LIBRARY: Record<string, string>;
|
|
|
135
135
|
* which holds the file here when the Library cannot take it, this says why.
|
|
136
136
|
*/
|
|
137
137
|
export declare function saveToLibrary(w: Wire, key: string, blob: Blob): Promise<string>;
|
|
138
|
-
/** The bytes at an address a Library item gave, or the reason they did not come. */
|
|
139
|
-
export declare function fileAt(href: string): Promise<Blob>;
|
|
140
138
|
/** Keep bytes at a key: a made file in the Library, anything else in this browser. Answers the key. */
|
|
141
139
|
export declare function put(w: Wire, key: string, blob: Blob): Promise<string>;
|
|
142
140
|
/**
|
|
@@ -162,24 +160,6 @@ export declare function remove(w: Wire, key: string): Promise<void>;
|
|
|
162
160
|
/** A kept JSON document, or null when there is none. */
|
|
163
161
|
export declare function load<T>(w: Wire, key: string): Promise<T | null>;
|
|
164
162
|
export declare const save: (w: Wire, key: string, value: unknown) => Promise<string>;
|
|
165
|
-
export interface Shelf {
|
|
166
|
-
id: string;
|
|
167
|
-
kind: string;
|
|
168
|
-
name: string;
|
|
169
|
-
mime: string;
|
|
170
|
-
bytes: number;
|
|
171
|
-
ref: string;
|
|
172
|
-
origin: string;
|
|
173
|
-
url: string;
|
|
174
|
-
download: string;
|
|
175
|
-
preview: string;
|
|
176
|
-
created: string;
|
|
177
|
-
shared: boolean;
|
|
178
|
-
}
|
|
179
|
-
/** Every Studio item in the person's Library, read a page at a time. */
|
|
180
|
-
export declare function shelf(w: Wire, signal?: AbortSignal): Promise<Shelf[]>;
|
|
181
|
-
/** Delete one item from the Library, and this browser's record of it. */
|
|
182
|
-
export declare function discard(w: Wire, id: string): Promise<void>;
|
|
183
163
|
export interface Node {
|
|
184
164
|
identity: string;
|
|
185
165
|
name?: string;
|
|
@@ -195,8 +175,12 @@ export interface Fleet {
|
|
|
195
175
|
total: number;
|
|
196
176
|
nodes: Node[];
|
|
197
177
|
}
|
|
198
|
-
/**
|
|
199
|
-
|
|
178
|
+
/**
|
|
179
|
+
* The org's GPUs and what each can run. A fleet the engine cannot read is an error, never an empty fleet, and
|
|
180
|
+
* so is an answer that is not a fleet: an origin that is not the engine (a dev server, or a desktop window
|
|
181
|
+
* answering /v1/gpu-status with its own page) lights no lane.
|
|
182
|
+
*/
|
|
183
|
+
export declare function gpus(w: Wire, signal?: AbortSignal): Promise<Fleet>;
|
|
200
184
|
export interface Submitted {
|
|
201
185
|
prompt_id?: string;
|
|
202
186
|
id?: string;
|
package/lib/wire.js
CHANGED
|
@@ -417,13 +417,6 @@ export async function saveToLibrary(w, key, blob) {
|
|
|
417
417
|
throw new Refusal(413, 'This file is over the Library\'s 10 MiB browser limit.');
|
|
418
418
|
return shelve(w, key, blob);
|
|
419
419
|
}
|
|
420
|
-
/** The bytes at an address a Library item gave, or the reason they did not come. */
|
|
421
|
-
export async function fileAt(href) {
|
|
422
|
-
const r = await reach(href, { credentials: 'omit' });
|
|
423
|
-
if (!r.ok)
|
|
424
|
-
throw new Error(`Download failed (HTTP ${r.status})`);
|
|
425
|
-
return r.blob();
|
|
426
|
-
}
|
|
427
420
|
/** What this page made or read, held for its life: a file is never fetched twice. */
|
|
428
421
|
const held = new Map();
|
|
429
422
|
/** Keep bytes at a key: a made file in the Library, anything else in this browser. Answers the key. */
|
|
@@ -535,26 +528,17 @@ export async function load(w, key) {
|
|
|
535
528
|
}
|
|
536
529
|
}
|
|
537
530
|
export const save = (w, key, value) => put(w, key, new Blob([JSON.stringify(value)], { type: 'application/json' }));
|
|
538
|
-
/**
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
return
|
|
548
|
-
}
|
|
549
|
-
/** Delete one item from the Library, and this browser's record of it. */
|
|
550
|
-
export async function discard(w, id) {
|
|
551
|
-
await unshelve(w, id);
|
|
552
|
-
for (const r of await all(w))
|
|
553
|
-
if (r.lib === id)
|
|
554
|
-
await tx(await db(w), 'readwrite', (s) => s.delete(r.key));
|
|
555
|
-
}
|
|
556
|
-
/** The org's GPUs and what each can run. A fleet the engine cannot read is an error, never an empty fleet. */
|
|
557
|
-
export const gpus = (w, signal) => ask(w, 'engine', '/v1/gpu-status', { signal });
|
|
531
|
+
/**
|
|
532
|
+
* The org's GPUs and what each can run. A fleet the engine cannot read is an error, never an empty fleet, and
|
|
533
|
+
* so is an answer that is not a fleet: an origin that is not the engine (a dev server, or a desktop window
|
|
534
|
+
* answering /v1/gpu-status with its own page) lights no lane.
|
|
535
|
+
*/
|
|
536
|
+
export async function gpus(w, signal) {
|
|
537
|
+
const got = await ask(w, 'engine', '/v1/gpu-status', { signal });
|
|
538
|
+
if (!Array.isArray(got?.nodes))
|
|
539
|
+
throw new Refusal(502, 'The engine did not answer with its GPUs.');
|
|
540
|
+
return got;
|
|
541
|
+
}
|
|
558
542
|
/** Dispatch a lane to the org's GPUs (the engine's one funnel). */
|
|
559
543
|
export const dispatch = (w, lane, body, signal) => ask(w, 'engine', `/v1/library/${lane}`, { body, signal });
|
|
560
544
|
/** Queue a ComfyUI graph on `/v1/prompt`. It is only queued: its `prompt_id` is followed through the work-log. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/studio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"description": "Hanzo Studio: a chat that makes images, posters, documents, slides, type systems, 3D, video and sound, with every result open in a tab beside it. Mounted by the Hanzo app at hanzo.ai/studio and served whole at studio.hanzo.ai.",
|