@hanzo/studio 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.
Files changed (74) hide show
  1. package/LICENSE +29 -0
  2. package/NOTICE +68 -0
  3. package/lib/chat/store.d.ts +33 -0
  4. package/lib/chat/store.js +56 -0
  5. package/lib/chat/turn.d.ts +51 -0
  6. package/lib/chat/turn.js +274 -0
  7. package/lib/desk.d.ts +14 -0
  8. package/lib/desk.js +72 -0
  9. package/lib/gpu.d.ts +15 -0
  10. package/lib/gpu.js +41 -0
  11. package/lib/home.d.ts +6 -0
  12. package/lib/home.js +48 -0
  13. package/lib/host.d.ts +12 -0
  14. package/lib/host.js +18 -0
  15. package/lib/index.d.ts +12 -0
  16. package/lib/index.js +11 -0
  17. package/lib/kinds/ad.d.ts +51 -0
  18. package/lib/kinds/ad.js +124 -0
  19. package/lib/kinds/document.d.ts +6 -0
  20. package/lib/kinds/document.js +271 -0
  21. package/lib/kinds/image.d.ts +47 -0
  22. package/lib/kinds/image.js +179 -0
  23. package/lib/kinds/index.d.ts +9 -0
  24. package/lib/kinds/index.js +12 -0
  25. package/lib/kinds/kind.d.ts +113 -0
  26. package/lib/kinds/kind.js +13 -0
  27. package/lib/kinds/mesh/index.d.ts +2 -0
  28. package/lib/kinds/mesh/index.js +76 -0
  29. package/lib/kinds/mesh/viewer.d.ts +7 -0
  30. package/lib/kinds/mesh/viewer.js +79 -0
  31. package/lib/kinds/poster/compose.d.ts +40 -0
  32. package/lib/kinds/poster/compose.js +289 -0
  33. package/lib/kinds/poster/index.d.ts +21 -0
  34. package/lib/kinds/poster/index.js +210 -0
  35. package/lib/kinds/sound.d.ts +6 -0
  36. package/lib/kinds/sound.js +100 -0
  37. package/lib/kinds/type/fonts.d.ts +30 -0
  38. package/lib/kinds/type/fonts.js +111 -0
  39. package/lib/kinds/type/index.d.ts +5 -0
  40. package/lib/kinds/type/index.js +117 -0
  41. package/lib/kinds/type/system.d.ts +164 -0
  42. package/lib/kinds/type/system.js +302 -0
  43. package/lib/kinds/video.d.ts +2 -0
  44. package/lib/kinds/video.js +81 -0
  45. package/lib/live.d.ts +44 -0
  46. package/lib/live.js +128 -0
  47. package/lib/made.d.ts +75 -0
  48. package/lib/made.js +36 -0
  49. package/lib/nav.d.ts +17 -0
  50. package/lib/nav.js +29 -0
  51. package/lib/pdf.d.ts +16 -0
  52. package/lib/pdf.js +53 -0
  53. package/lib/places.d.ts +6 -0
  54. package/lib/places.js +121 -0
  55. package/lib/raster.d.ts +7 -0
  56. package/lib/raster.js +53 -0
  57. package/lib/route.d.ts +33 -0
  58. package/lib/route.js +52 -0
  59. package/lib/starters.d.ts +31 -0
  60. package/lib/starters.js +62 -0
  61. package/lib/studio.d.ts +26 -0
  62. package/lib/studio.js +58 -0
  63. package/lib/talk.d.ts +3 -0
  64. package/lib/talk.js +369 -0
  65. package/lib/ui.d.ts +50 -0
  66. package/lib/ui.js +57 -0
  67. package/lib/use.d.ts +11 -0
  68. package/lib/use.js +35 -0
  69. package/lib/wire.d.ts +237 -0
  70. package/lib/wire.js +455 -0
  71. package/lib/zip.d.ts +9 -0
  72. package/lib/zip.js +60 -0
  73. package/package.json +75 -3
  74. package/README.md +0 -3
package/lib/nav.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Studio's places, once, for every rail that lists them: Studio's own rail on
3
+ * studio.hanzo.ai, and the Hanzo app's column at hanzo.ai/studio (the shape
4
+ * @hanzo/build's `nav` gives Dev, so a host draws both one way). Every row
5
+ * moves Studio through `go` with an address `path` writes.
6
+ */
7
+ import type { Host } from '@hanzo/build';
8
+ import type { RailLink } from '@hanzo/ui/chat';
9
+ /** A run of places under one quiet label. */
10
+ export interface Group {
11
+ id: 'make' | 'made' | 'run';
12
+ label: string;
13
+ links: RailLink[];
14
+ }
15
+ /** The id of the row that starts a new conversation: a rail with a New control of its own draws that instead. */
16
+ export declare const NEW = "new";
17
+ export declare function nav(host: Host, go: (path: string) => void): Group[];
package/lib/nav.js ADDED
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Activity, LayoutTemplate, Library, SquarePen } from '@hanzogui/lucide-icons-2';
3
+ import { path, route } from './route.js';
4
+ /** The id of the row that starts a new conversation: a rail with a New control of its own draws that instead. */
5
+ export const NEW = 'new';
6
+ export function nav(host, go) {
7
+ const r = route(host.path);
8
+ const to = (p) => () => go(p);
9
+ return [
10
+ {
11
+ id: 'make',
12
+ label: 'Create',
13
+ links: [
14
+ { id: NEW, label: 'New creation', icon: _jsx(SquarePen, { size: 16 }), onPress: to(''), active: r.kind === 'new' },
15
+ { id: 'explore', label: 'Explore', icon: _jsx(LayoutTemplate, { size: 16 }), onPress: to(path({ kind: 'explore' })), active: r.kind === 'explore' },
16
+ ],
17
+ },
18
+ {
19
+ id: 'made',
20
+ label: 'Made',
21
+ links: [{ id: 'library', label: 'Library', icon: _jsx(Library, { size: 16 }), onPress: to(path({ kind: 'library' })), active: r.kind === 'library' }],
22
+ },
23
+ {
24
+ id: 'run',
25
+ label: 'Run',
26
+ links: [{ id: 'activity', label: 'Activity', icon: _jsx(Activity, { size: 16 }), onPress: to(path({ kind: 'activity' })), active: r.kind === 'activity' }],
27
+ },
28
+ ];
29
+ }
package/lib/pdf.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A PDF of pictures, one per page, each page the physical size asked for.
3
+ * The pictures are JPEG, which PDF carries as they are (DCTDecode), so this is
4
+ * the whole writer: a catalog, the pages, one image each, and the cross
5
+ * reference table. No fonts, no text: what is drawn is the picture.
6
+ */
7
+ export interface Sheet {
8
+ jpeg: Uint8Array;
9
+ /** The picture's pixels. */
10
+ width: number;
11
+ height: number;
12
+ /** The page, in points (1/72 inch). */
13
+ pageWidth: number;
14
+ pageHeight: number;
15
+ }
16
+ export declare function pdf(sheets: readonly Sheet[], title: string): Blob;
package/lib/pdf.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * A PDF of pictures, one per page, each page the physical size asked for.
3
+ * The pictures are JPEG, which PDF carries as they are (DCTDecode), so this is
4
+ * the whole writer: a catalog, the pages, one image each, and the cross
5
+ * reference table. No fonts, no text: what is drawn is the picture.
6
+ */
7
+ const enc = new TextEncoder();
8
+ export function pdf(sheets, title) {
9
+ const parts = [];
10
+ const offsets = [];
11
+ let at = 0;
12
+ const push = (b) => {
13
+ parts.push(b);
14
+ at += b.length;
15
+ };
16
+ const text = (s) => push(enc.encode(s));
17
+ const object = (n, body) => {
18
+ offsets[n] = at;
19
+ text(`${n} 0 obj\n`);
20
+ body();
21
+ text('\nendobj\n');
22
+ };
23
+ text('%PDF-1.4\n%\xE2\xE3\xCF\xD3\n');
24
+ const n = sheets.length;
25
+ // 1 catalog, 2 pages, 3 info; per sheet: page, content, image.
26
+ const page = (i) => 4 + i * 3;
27
+ const kids = sheets.map((_, i) => `${page(i)} 0 R`).join(' ');
28
+ const safe = title.replace(/[()\\]/g, '').slice(0, 120);
29
+ object(1, () => text('<< /Type /Catalog /Pages 2 0 R >>'));
30
+ object(2, () => text(`<< /Type /Pages /Kids [${kids}] /Count ${n} >>`));
31
+ object(3, () => text(`<< /Title (${safe}) /Producer (Hanzo Studio) >>`));
32
+ sheets.forEach((s, i) => {
33
+ const p = page(i);
34
+ const w = s.pageWidth.toFixed(2);
35
+ const h = s.pageHeight.toFixed(2);
36
+ object(p, () => text(`<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${w} ${h}] /Resources << /XObject << /Im0 ${p + 2} 0 R >> >> /Contents ${p + 1} 0 R >>`));
37
+ const draw = `q ${w} 0 0 ${h} 0 0 cm /Im0 Do Q`;
38
+ object(p + 1, () => text(`<< /Length ${draw.length} >>\nstream\n${draw}\nendstream`));
39
+ object(p + 2, () => {
40
+ text(`<< /Type /XObject /Subtype /Image /Width ${s.width} /Height ${s.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${s.jpeg.length} >>\nstream\n`);
41
+ push(s.jpeg);
42
+ text('\nendstream');
43
+ });
44
+ });
45
+ const xref = at;
46
+ const count = 4 + n * 3;
47
+ let table = `xref\n0 ${count}\n0000000000 65535 f \n`;
48
+ for (let i = 1; i < count; i++)
49
+ table += `${String(offsets[i] ?? 0).padStart(10, '0')} 00000 n \n`;
50
+ text(table);
51
+ text(`trailer\n<< /Size ${count} /Root 1 0 R /Info 3 0 R >>\nstartxref\n${xref}\n%%EOF\n`);
52
+ return new Blob(parts, { type: 'application/pdf' });
53
+ }
@@ -0,0 +1,6 @@
1
+ import { type Starter } from './starters.ts';
2
+ export declare const queue: (s: Starter) => void;
3
+ export declare const take: () => Starter | null;
4
+ export declare function Library(): import("react").JSX.Element;
5
+ export declare function Explore(): import("react").JSX.Element;
6
+ export declare function Activity(): import("react").JSX.Element;
package/lib/places.js ADDED
@@ -0,0 +1,121 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The places beside the conversation: the Library (everything this org made),
4
+ * Explore (every starter, and what each needs), and Activity (what is making
5
+ * or rendering now).
6
+ */
7
+ import { SizableText, XStack, YStack } from '@hanzo/gui';
8
+ import { Download, Search, Trash2 } from '@hanzogui/lucide-icons-2';
9
+ import { useEffect, useMemo, useState } from 'react';
10
+ import { useHost } from './host.js';
11
+ import { ALL, kind } from './kinds/index.js';
12
+ import { KEPT, useAvailable, useChats, useLibrary, useWire } from './live.js';
13
+ import { shelved } from './made.js';
14
+ import { path } from './route.js';
15
+ import { CATEGORIES, RUNTIME, STARTERS } from './starters.js';
16
+ import { Act, download, Pill } from './ui.js';
17
+ import { useUrl } from './use.js';
18
+ import { ask, list, read, remove } from './wire.js';
19
+ /** A starter handed from Explore to the conversation it starts. */
20
+ let queued = null;
21
+ export const queue = (s) => {
22
+ queued = s;
23
+ };
24
+ export const take = () => {
25
+ const s = queued;
26
+ queued = null;
27
+ return s;
28
+ };
29
+ function Page({ title, children, right }) {
30
+ 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(--white-08))", 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", flex: 1, children: title }), right] }), children] }) }));
31
+ }
32
+ export function Library() {
33
+ const host = useHost();
34
+ const wire = useWire(host);
35
+ const [items, setItems] = useState(null);
36
+ const [error, setError] = useState('');
37
+ const [only, setOnly] = useState('all');
38
+ const [q, setQ] = useState('');
39
+ const shelf = useLibrary(wire);
40
+ const reload = () => {
41
+ setError('');
42
+ list(wire, 'files/').then((entries) => {
43
+ const by = new Map();
44
+ for (const e of entries) {
45
+ const s = shelved(e.key, e.modified, e.size);
46
+ if (!s || s.made === 'attached')
47
+ continue;
48
+ const id = `${s.chat}/${s.made}`;
49
+ const it = by.get(id) ?? { kind: s.kind, chat: s.chat, made: s.made, files: [], modified: 0 };
50
+ // The newest version's files stand for the thing.
51
+ const newest = it.files[0]?.version;
52
+ if (!newest || s.version > newest)
53
+ it.files = [s, ...it.files.filter((f) => f.version === s.version)];
54
+ else if (s.version === newest)
55
+ it.files.push(s);
56
+ it.modified = Math.max(it.modified, s.modified);
57
+ by.set(id, it);
58
+ }
59
+ setItems([...by.values()].sort((a, b) => b.modified - a.modified));
60
+ }, (e) => setError(e instanceof Error ? e.message : String(e)));
61
+ };
62
+ useEffect(reload, [wire]);
63
+ const kinds = useMemo(() => [...new Set((items ?? []).map((i) => i.kind))], [items]);
64
+ const shown = (items ?? []).filter((i) => (only === 'all' || i.kind === only) && (!q || i.files.some((f) => f.name.toLowerCase().includes(q.toLowerCase()))));
65
+ return (_jsxs(Page, { title: "Library", right: _jsxs(XStack, { items: "center", gap: "$2", height: 34, px: "$3", rounded: 999, borderWidth: 1, borderColor: "$borderColor", minW: 220, children: [_jsx(Search, { size: 14 }), _jsx("input", { "aria-label": "Search the library", placeholder: "Search", value: q, onChange: (e) => setQ(e.currentTarget.value), style: { flex: 1, border: 0, background: 'transparent', color: 'inherit', font: 'inherit', outline: 'none' } })] }), children: [_jsx(SizableText, { size: "$2", color: "$soft", children: shelf ? 'Saved to your Library, private to you until you share it.' : KEPT }), _jsxs(XStack, { gap: "$2", flexWrap: "wrap", role: "toolbar", "aria-label": "Kinds", children: [_jsx(Pill, { on: only === 'all', onPress: () => setOnly('all'), children: "All" }), kinds.map((k) => (_jsx(Pill, { on: only === k, onPress: () => setOnly(k), children: kind(k).label }, k)))] }), error ? _jsx(SizableText, { color: "$red10", 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, { wire: wire, item: i, onOpen: () => host.go(path({ kind: 'chat', id: i.chat })), onGone: reload }, `${i.chat}/${i.made}`))) })] }));
66
+ }
67
+ function Thing({ wire, item, onOpen, onGone }) {
68
+ const k = kind(item.kind);
69
+ const Icon = k.icon;
70
+ const pic = item.files.find((f) => /\.(png|jpe?g|webp)$/i.test(f.name));
71
+ const { src } = useUrl(wire, pic?.key);
72
+ const [busy, setBusy] = useState(false);
73
+ const first = item.files.find((f) => !f.name.endsWith('.json')) ?? item.files[0];
74
+ const name = first.name;
75
+ return (_jsxs(YStack, { role: "listitem", width: "calc(50% - 6px)", $sm: { width: 'calc(25% - 9px)' }, gap: "$1.5", children: [_jsxs(YStack, { render: "button", "aria-label": `Open ${name} in its conversation`, onPress: onOpen, rounded: 16, overflow: "hidden", bg: "$hover", cursor: "pointer", style: { aspectRatio: '4 / 5' }, items: "center", justify: "center", position: "relative", children: [src ? _jsx("img", { src: src, alt: "", style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } }) : _jsx(Icon, { size: 28 }), _jsx(XStack, { position: "absolute", t: 8, l: 8, width: 26, height: 26, rounded: 99, bg: "rgba(0,0,0,0.55)", items: "center", justify: "center", children: _jsx(Icon, { size: 13 }) })] }), _jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", numberOfLines: 1, flex: 1, children: name.replace(/\.[a-z0-9.]+$/i, '').replace(/-/g, ' ') }), _jsx(Act, { label: `Download ${name}`, onPress: () => void read(wire, first.key).then((b) => download(name, b)), children: _jsx(Download, { size: 13 }) }), _jsx(Act, { label: `Delete ${name}`, disabled: busy, onPress: () => {
76
+ if (!window.confirm(`Delete ${name} from the library? Its conversation keeps the record.`))
77
+ return;
78
+ setBusy(true);
79
+ void Promise.all(item.files.map((f) => remove(wire, f.key))).finally(onGone);
80
+ }, children: _jsx(Trash2, { size: 13 }) })] }), _jsx(SizableText, { size: "$1", color: "$soft", mt: -4, children: `${k.label} · ${new Date(item.modified).toLocaleDateString()}` })] }));
81
+ }
82
+ /* ----------------------------------------------------------------- explore */
83
+ export function Explore() {
84
+ const host = useHost();
85
+ const wire = useWire(host);
86
+ const available = useAvailable(wire);
87
+ return (_jsxs(Page, { title: "Explore", children: [CATEGORIES.filter((c) => c.id !== 'all').map((c) => {
88
+ const list = STARTERS.filter((s) => s.category === c.id);
89
+ if (!list.length)
90
+ return null;
91
+ return (_jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: c.label }), _jsx(XStack, { flexWrap: "wrap", gap: "$2", children: list.map((s) => {
92
+ const why = kind(s.kind).needs(available);
93
+ return (_jsxs(YStack, { render: "button", "aria-label": `${s.title}${why ? `, ${why}` : ''}`, "aria-disabled": why ? true : undefined, onPress: () => {
94
+ if (why)
95
+ return;
96
+ queue(s);
97
+ host.go('');
98
+ }, width: 250, p: "$3", gap: "$1", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", opacity: why ? 0.6 : 1, cursor: why ? 'default' : 'pointer', hoverStyle: why ? undefined : { bg: '$hover' }, children: [_jsxs(XStack, { justify: "space-between", children: [_jsx(SizableText, { size: "$3", fontWeight: "600", numberOfLines: 1, children: s.title }), _jsx(SizableText, { size: "$1", color: "$soft", children: RUNTIME[s.kind] })] }), _jsx(SizableText, { size: "$2", color: "$soft", numberOfLines: 2, children: why ? 'Needs a GPU: connect one with hanzo link.' : s.subtitle })] }, s.id));
99
+ }) })] }, c.id));
100
+ }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: "Kinds" }), ALL.map((k) => (_jsxs(XStack, { gap: "$3", items: "center", children: [_jsx(k.icon, { size: 15 }), _jsx(SizableText, { size: "$2", width: 120, children: k.label }), _jsx(SizableText, { size: "$2", color: "$soft", flex: 1, children: k.needs(available) ?? k.blurb })] }, k.id)))] })] }));
101
+ }
102
+ export function Activity() {
103
+ const host = useHost();
104
+ const wire = useWire(host);
105
+ const { rows } = useChats(wire);
106
+ const available = useAvailable(wire);
107
+ const [jobs, setJobs] = useState(null);
108
+ const [error, setError] = useState('');
109
+ useEffect(() => {
110
+ let live = true;
111
+ const read_ = () => ask(wire, 'engine', '/v1/render-queue').then((r) => live && (setJobs(r.jobs ?? []), setError('')), (e) => live && setError(e instanceof Error ? e.message : String(e)));
112
+ void read_();
113
+ const t = setInterval(read_, 5000);
114
+ return () => {
115
+ live = false;
116
+ clearInterval(t);
117
+ };
118
+ }, [wire]);
119
+ const making = rows.filter((r) => r.state === 'making');
120
+ return (_jsxs(Page, { title: "Activity", children: [_jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: "GPUs" }), _jsx(SizableText, { size: "$2", color: "$soft", children: available.fleet ? `${available.fleet.online} of ${available.fleet.total} online · ${available.fleet.state}` : available.error || 'Reading…' }), (available.fleet?.nodes ?? []).map((n) => (_jsx(SizableText, { size: "$2", children: `${n.name ?? n.identity}: ${(n.lanes ?? []).join(', ') || 'no lanes yet'}` }, n.identity)))] }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: "Rendering" }), error ? _jsx(SizableText, { color: "$red10", children: error }) : null, jobs && !jobs.length ? _jsx(SizableText, { color: "$soft", children: "Nothing is rendering." }) : null, (jobs ?? []).map((j) => (_jsxs(XStack, { gap: "$3", children: [_jsx(SizableText, { size: "$2", width: 90, children: j.status ?? 'queued' }), _jsx(SizableText, { size: "$2", flex: 1, numberOfLines: 1, children: j.prompt || j.kind || j.id }), _jsx(SizableText, { size: "$2", color: "$soft", children: j.node ?? '' })] }, j.id)))] }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: "Making now" }), !making.length ? _jsx(SizableText, { color: "$soft", children: "No conversation is working." }) : null, making.map((r) => (_jsx(XStack, { render: "button", onPress: () => host.go(path({ kind: 'chat', id: r.id })), cursor: "pointer", children: _jsx(SizableText, { size: "$2", children: r.title }) }, r.id)))] })] }));
121
+ }
@@ -0,0 +1,7 @@
1
+ export declare function pixels(svg: string, width: number, height: number, type?: 'image/png' | 'image/jpeg', quality?: number): Promise<Blob>;
2
+ /** One page of PDF at a physical size (points), the SVG drawn at `width`x`height` pixels. */
3
+ export declare function page(svg: string, width: number, height: number, points: [number, number], title: string): Promise<Blob>;
4
+ /** A stored picture as a data: URL. */
5
+ export declare function data(blob: Blob): Promise<string>;
6
+ /** A picture as a JPEG data: URL no larger than `side` on its long edge: what a document carries inline. */
7
+ export declare function shrink(blob: Blob, side?: number, quality?: number): Promise<string>;
package/lib/raster.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * An SVG drawn to pixels in the browser: the one rasterizer posters and ads
3
+ * use. The SVG carries its own faces and pictures as data: URLs, because an SVG
4
+ * drawn as an image may load nothing from outside itself.
5
+ */
6
+ import { pdf } from './pdf.js';
7
+ export async function pixels(svg, width, height, type = 'image/png', quality = 0.92) {
8
+ const url = URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
9
+ try {
10
+ const img = new Image();
11
+ img.decoding = 'async';
12
+ img.src = url;
13
+ await img.decode();
14
+ const canvas = document.createElement('canvas');
15
+ canvas.width = width;
16
+ canvas.height = height;
17
+ const ctx = canvas.getContext('2d');
18
+ if (!ctx)
19
+ throw new Error('This browser cannot draw a picture.');
20
+ ctx.drawImage(img, 0, 0, width, height);
21
+ return await new Promise((resolve, reject) => canvas.toBlob((b) => (b ? resolve(b) : reject(new Error('The picture could not be written.'))), type, quality));
22
+ }
23
+ finally {
24
+ URL.revokeObjectURL(url);
25
+ }
26
+ }
27
+ /** One page of PDF at a physical size (points), the SVG drawn at `width`x`height` pixels. */
28
+ export async function page(svg, width, height, points, title) {
29
+ const jpeg = new Uint8Array(await (await pixels(svg, width, height, 'image/jpeg', 0.94)).arrayBuffer());
30
+ return pdf([{ jpeg, width, height, pageWidth: points[0], pageHeight: points[1] }], title);
31
+ }
32
+ /** A stored picture as a data: URL. */
33
+ export async function data(blob) {
34
+ const buf = new Uint8Array(await blob.arrayBuffer());
35
+ let bin = '';
36
+ for (let i = 0; i < buf.length; i += 0x8000)
37
+ bin += String.fromCharCode(...buf.subarray(i, i + 0x8000));
38
+ return `data:${blob.type || 'image/png'};base64,${btoa(bin)}`;
39
+ }
40
+ /** A picture as a JPEG data: URL no larger than `side` on its long edge: what a document carries inline. */
41
+ export async function shrink(blob, side = 1600, quality = 0.86) {
42
+ const bmp = await createImageBitmap(blob);
43
+ const k = Math.min(1, side / Math.max(bmp.width, bmp.height));
44
+ const canvas = document.createElement('canvas');
45
+ canvas.width = Math.round(bmp.width * k);
46
+ canvas.height = Math.round(bmp.height * k);
47
+ const ctx = canvas.getContext('2d');
48
+ if (!ctx)
49
+ throw new Error('This browser cannot draw a picture.');
50
+ ctx.drawImage(bmp, 0, 0, canvas.width, canvas.height);
51
+ bmp.close();
52
+ return canvas.toDataURL('image/jpeg', quality);
53
+ }
package/lib/route.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Studio's addresses, said once. The host hands Studio the path under its
3
+ * mount (`Host.path`, no leading slash) and moves it with `Host.go`; hanzo.ai
4
+ * mounts Studio at /studio and studio.hanzo.ai at its root, so the same
5
+ * grammar reads both.
6
+ *
7
+ * '' New: the composer and the starters
8
+ * c/<id> one conversation, its tabs beside it
9
+ * library everything this org has made
10
+ * explore the starters, every kind, with what each needs
11
+ * activity what is rendering, queued, done or failed
12
+ *
13
+ * No address here may be a word the engine answers on studio.hanzo.ai, because
14
+ * the edge sends those to it (universe static-sites, the studio route split):
15
+ * /templates, /settings, /models, /history, /view, /upload, /prompt, /login,
16
+ * /callback, /logout, /v1, /ws. That is why the starters are `explore`.
17
+ */
18
+ export type Route = {
19
+ kind: 'new';
20
+ } | {
21
+ kind: 'chat';
22
+ id: string;
23
+ } | {
24
+ kind: 'library';
25
+ } | {
26
+ kind: 'explore';
27
+ } | {
28
+ kind: 'activity';
29
+ };
30
+ export declare function route(at: string): Route;
31
+ export declare function path(r: Route): string;
32
+ /** A fresh conversation id: time-ordered, so a listing sorts by name. */
33
+ export declare function fresh(): string;
package/lib/route.js ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Studio's addresses, said once. The host hands Studio the path under its
3
+ * mount (`Host.path`, no leading slash) and moves it with `Host.go`; hanzo.ai
4
+ * mounts Studio at /studio and studio.hanzo.ai at its root, so the same
5
+ * grammar reads both.
6
+ *
7
+ * '' New: the composer and the starters
8
+ * c/<id> one conversation, its tabs beside it
9
+ * library everything this org has made
10
+ * explore the starters, every kind, with what each needs
11
+ * activity what is rendering, queued, done or failed
12
+ *
13
+ * No address here may be a word the engine answers on studio.hanzo.ai, because
14
+ * the edge sends those to it (universe static-sites, the studio route split):
15
+ * /templates, /settings, /models, /history, /view, /upload, /prompt, /login,
16
+ * /callback, /logout, /v1, /ws. That is why the starters are `explore`.
17
+ */
18
+ /** A conversation id: what `fresh` mints, and nothing that could leave the path. */
19
+ const ID = /^[a-z0-9][a-z0-9_-]{0,63}$/;
20
+ export function route(at) {
21
+ const p = at.replace(/^\/+|\/+$/g, '').split('?')[0].split('#')[0];
22
+ if (!p)
23
+ return { kind: 'new' };
24
+ const [head, rest, ...more] = p.split('/');
25
+ if (more.length)
26
+ return { kind: 'new' };
27
+ if (head === 'c' && rest && ID.test(rest))
28
+ return { kind: 'chat', id: rest };
29
+ if (head === 'library' && !rest)
30
+ return { kind: 'library' };
31
+ if (head === 'explore' && !rest)
32
+ return { kind: 'explore' };
33
+ if (head === 'activity' && !rest)
34
+ return { kind: 'activity' };
35
+ return { kind: 'new' };
36
+ }
37
+ export function path(r) {
38
+ switch (r.kind) {
39
+ case 'new':
40
+ return '';
41
+ case 'chat':
42
+ return `c/${r.id}`;
43
+ default:
44
+ return r.kind;
45
+ }
46
+ }
47
+ /** A fresh conversation id: time-ordered, so a listing sorts by name. */
48
+ export function fresh() {
49
+ const t = Date.now().toString(36).padStart(9, '0');
50
+ const r = Array.from(crypto.getRandomValues(new Uint8Array(6)), (b) => (b % 36).toString(36)).join('');
51
+ return `${t}${r}`;
52
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The starters: what the home offers under the composer and Explore lists in
3
+ * full. A starter is a kind and a first message; a press starts a conversation
4
+ * with it. The home shows only starters whose kind can run now; Explore shows
5
+ * every one, and says what each needs.
6
+ *
7
+ * `thumb` is the card's picture, made once by our own models and kept in the
8
+ * public `hanzo-studio` bucket at catalog/<id>/<sha8>.webp (scripts/thumbs.ts);
9
+ * a starter without one is drawn as type.
10
+ */
11
+ import type { KindId } from './made.ts';
12
+ export type Category = 'image' | 'edit' | 'poster' | 'document' | 'slides' | 'type' | 'mesh' | 'video' | 'ad' | 'audio' | 'fashion';
13
+ export declare const CATEGORIES: readonly {
14
+ id: Category | 'all';
15
+ label: string;
16
+ }[];
17
+ export interface Starter {
18
+ id: string;
19
+ kind: KindId;
20
+ category: Category;
21
+ title: string;
22
+ subtitle: string;
23
+ /** The first message. */
24
+ prompt: string;
25
+ /** Whether it starts from a picture the person attaches. */
26
+ picture?: boolean;
27
+ thumb?: string;
28
+ }
29
+ /** Roughly how long one takes, for the card's corner. */
30
+ export declare const RUNTIME: Record<KindId, string>;
31
+ export declare const STARTERS: readonly Starter[];
@@ -0,0 +1,62 @@
1
+ export const CATEGORIES = [
2
+ { id: 'all', label: 'All' },
3
+ { id: 'image', label: 'Image' },
4
+ { id: 'edit', label: 'Edit' },
5
+ { id: 'poster', label: 'Posters' },
6
+ { id: 'document', label: 'Documents' },
7
+ { id: 'slides', label: 'Slides' },
8
+ { id: 'type', label: 'Type' },
9
+ { id: 'mesh', label: '3D' },
10
+ { id: 'video', label: 'Video' },
11
+ { id: 'ad', label: 'Ads' },
12
+ { id: 'audio', label: 'Audio' },
13
+ { id: 'fashion', label: 'Fashion' },
14
+ ];
15
+ /** Roughly how long one takes, for the card's corner. */
16
+ export const RUNTIME = {
17
+ image: '~20s',
18
+ poster: '~30s',
19
+ document: '~40s',
20
+ slides: '~60s',
21
+ type: '~15s',
22
+ mesh: '~2m',
23
+ video: '~3m',
24
+ ad: '~45s',
25
+ voice: '~5s',
26
+ music: '~1m',
27
+ };
28
+ export const STARTERS = [
29
+ { id: 'poster-jazz', kind: 'poster', category: 'poster', title: 'Jazz night poster', subtitle: 'A3, full bleed', prompt: 'A poster for a jazz night this Friday at 9pm at The Blue Room, 14 Canal Street. Smoky, warm, late-night. Free entry before 10.' },
30
+ { id: 'poster-launch', kind: 'poster', category: 'poster', title: 'Product launch poster', subtitle: '18 × 24, framed', prompt: 'An 18x24 launch poster for Aurora, a minimalist desk lamp with a warm dimmable glow. Launching 12 November. Pre-order at aurora.lighting.' },
31
+ { id: 'poster-talk', kind: 'poster', category: 'poster', title: 'Conference talk', subtitle: 'Type only, A2', prompt: 'A type-only A2 poster for a talk called "Small models, big systems" by Dr. Lena Ortiz, Hall B, 3 December, 14:00.' },
32
+ { id: 'poster-story', kind: 'poster', category: 'poster', title: 'Gallery opening story', subtitle: 'Instagram story', prompt: 'An Instagram story poster for the opening of "Salt & Light", a photography show at Gallery Nine, Saturday 6–9pm.' },
33
+ { id: 'image-product', kind: 'image', category: 'image', title: 'Product on marble', subtitle: 'Studio product shot', prompt: 'A studio product photograph of a matte black ceramic coffee cup on white marble, soft window light from the left, shallow depth of field, 4:5.' },
34
+ { id: 'image-portrait', kind: 'image', category: 'image', title: 'Cinematic portrait', subtitle: 'Golden hour, 85mm', prompt: 'A cinematic portrait of an elderly fisherman mending a net at golden hour, 85mm lens, warm rim light, film grain.' },
35
+ { id: 'image-iso', kind: 'image', category: 'image', title: 'Isometric city block', subtitle: 'Illustration', prompt: 'An isometric illustration of a small city block at dusk: a bakery, a bike shop, a rooftop garden, soft pastel palette, clean lines, 1:1.' },
36
+ { id: 'image-food', kind: 'image', category: 'image', title: 'Breakfast flat lay', subtitle: 'Overhead food shot', prompt: 'An overhead flat lay of a breakfast table: sourdough toast, berries, coffee, linen napkin, natural light, 1:1.' },
37
+ { id: 'edit-background', kind: 'image', category: 'edit', title: 'Clean background', subtitle: 'From your photo', prompt: 'Put this product on a clean, seamless light grey studio background with a soft shadow.', picture: true },
38
+ { id: 'edit-season', kind: 'image', category: 'edit', title: 'Change the season', subtitle: 'From your photo', prompt: 'Make this scene winter: fresh snow, cold blue light, breath in the air. Keep everything else the same.', picture: true },
39
+ { id: 'edit-wide', kind: 'image', category: 'edit', title: 'Widen to 16:9', subtitle: 'Expand the frame', prompt: 'Expand this picture to 16:9, continuing the scene naturally on both sides.', picture: true },
40
+ { id: 'doc-proposal', kind: 'document', category: 'document', title: 'Project proposal', subtitle: 'PDF and Word', prompt: 'A two-page proposal from Northwind Studio to redesign the website of Harbor Dental: scope, timeline over six weeks, team, and a fixed price of $18,000.' },
41
+ { id: 'doc-onepager', kind: 'document', category: 'document', title: 'Product one-pager', subtitle: 'With a cover picture', prompt: 'A one-pager for Aurora, a dimmable desk lamp: the problem, three features, specs table, and price. Include a product picture.' },
42
+ { id: 'doc-invoice', kind: 'document', category: 'document', title: 'Invoice', subtitle: 'Line items, totals', prompt: 'An invoice from Northwind Studio to Harbor Dental for website design: discovery $2,000, design $9,000, build $7,000, due in 30 days.' },
43
+ { id: 'doc-press', kind: 'document', category: 'document', title: 'Press release', subtitle: 'Announcement', prompt: 'A press release announcing that Greenline Bikes opens its third store, in Portland, on 1 December, with a quote from the founder.' },
44
+ { id: 'deck-pitch', kind: 'slides', category: 'slides', title: 'Seed pitch deck', subtitle: 'Ten slides, PowerPoint', prompt: 'A ten-slide seed pitch deck for Ledgerly, bookkeeping on autopilot for freelancers: problem, solution, market, traction chart, business model, team, the ask of $2.5M.' },
45
+ { id: 'deck-qbr', kind: 'slides', category: 'slides', title: 'Quarterly review', subtitle: 'With a chart', prompt: 'A quarterly business review deck for Q3: revenue by month July 120k, August 138k, September 151k; highlights, risks, and next-quarter goals.' },
46
+ { id: 'deck-lesson', kind: 'slides', category: 'slides', title: 'Workshop lesson', subtitle: 'Pictures and steps', prompt: 'A short workshop deck teaching beginners how to make cold brew coffee at home, step by step, with pictures.' },
47
+ { id: 'type-roaster', kind: 'type', category: 'type', title: 'Coffee roaster brand', subtitle: 'Warm and crafted', prompt: 'A type system for a small-batch coffee roaster: warm, crafted, a little playful, readable on bags and menus.' },
48
+ { id: 'type-editorial', kind: 'type', category: 'type', title: 'Editorial magazine', subtitle: 'Serif-led', prompt: 'A type system for an independent long-form magazine: serif-led, calm, generous reading text, a confident display face.' },
49
+ { id: 'type-dev', kind: 'type', category: 'type', title: 'Developer tool', subtitle: 'Precise, dark', prompt: 'A type system for a developer tool: precise, dark by default, a grotesk with a mono for code, one electric accent.' },
50
+ { id: 'mesh-sneaker', kind: 'mesh', category: 'mesh', title: 'Sneaker model', subtitle: 'glTF, from words', prompt: 'A 3D model of a white leather low-top sneaker with a gum sole.' },
51
+ { id: 'mesh-vase', kind: 'mesh', category: 'mesh', title: 'Ceramic vase', subtitle: 'glTF, from a picture', prompt: 'Make a 3D model of the object in this picture.', picture: true },
52
+ { id: 'video-turntable', kind: 'video', category: 'video', title: 'Product turntable', subtitle: '5s, 1:1', prompt: 'A 5 second clip: a matte black coffee cup slowly rotating on a turntable, studio light, 1:1.' },
53
+ { id: 'video-ocean', kind: 'video', category: 'video', title: 'Ocean social clip', subtitle: '5s, 9:16', prompt: 'A 5 second vertical clip of waves rolling onto a black sand beach at dawn, slow push in.' },
54
+ { id: 'ad-sale', kind: 'ad', category: 'ad', title: 'Summer sale ad set', subtitle: 'Social + banners', prompt: 'An ad set for a summer sale at Greenline Bikes: 30% off city bikes this weekend only. Shop now.' },
55
+ { id: 'ad-app', kind: 'ad', category: 'ad', title: 'App install ads', subtitle: 'Every size', prompt: 'An ad set for Ledgerly, an app that does bookkeeping for freelancers: "Your books, done while you work". Get the app.' },
56
+ { id: 'voice-intro', kind: 'voice', category: 'audio', title: 'Podcast intro', subtitle: 'Voiceover', prompt: 'A warm 15 second podcast intro voiceover for "Small Hours", a show about people who work nights.' },
57
+ { id: 'voice-ad', kind: 'voice', category: 'audio', title: 'Radio spot', subtitle: '30 second read', prompt: 'A 30 second radio ad read for Greenline Bikes summer sale, upbeat and friendly.' },
58
+ { id: 'music-lofi', kind: 'music', category: 'audio', title: 'Lo-fi bed', subtitle: 'Instrumental', prompt: 'A 60 second lo-fi hip hop instrumental bed, mellow keys, vinyl crackle, 80 bpm.' },
59
+ { id: 'fashion-ghost', kind: 'image', category: 'fashion', title: 'CAD to ghost mannequin', subtitle: 'From a flat drawing', prompt: 'Turn this garment drawing into a photorealistic ghost-mannequin product photo on white, true to its colours, print and proportions.', picture: true },
60
+ { id: 'fashion-product', kind: 'image', category: 'fashion', title: 'Product photo', subtitle: 'From a flat lay', prompt: 'Turn this flat lay into a clean e-commerce product photo on a light grey background with a soft shadow.', picture: true },
61
+ { id: 'fashion-swap', kind: 'image', category: 'fashion', title: 'Outfit swap', subtitle: 'Keep the model', prompt: 'Dress the person in this photo in a camel wool overcoat and a cream turtleneck. Keep their face, pose, light and background exactly.', picture: true },
62
+ ];
@@ -0,0 +1,26 @@
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';
18
+ /**
19
+ * Studio. `rail={false}` leaves the left column to the host, which lists
20
+ * Studio's places with `nav`; Studio is then a pane of the host's and paints
21
+ * no ground of its own.
22
+ */
23
+ export declare function Studio({ host, rail }: {
24
+ host: Host;
25
+ rail?: boolean;
26
+ }): import("react").JSX.Element;
package/lib/studio.js ADDED
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { SizableText, XStack, YStack } from '@hanzo/gui';
3
+ import { SessionRail } from '@hanzo/ui/chat';
4
+ import { useState } from 'react';
5
+ import { StudioHost, useHost } from './host.js';
6
+ import { useChats, useWire } from './live.js';
7
+ import { nav, NEW } from './nav.js';
8
+ import { Activity, Explore, Library } from './places.js';
9
+ import { path, route } from './route.js';
10
+ import { Talk } from './talk.js';
11
+ const DOT = { making: 'running', done: 'done', failed: 'error' };
12
+ function Pane() {
13
+ const host = useHost();
14
+ const r = route(host.path);
15
+ if (!host.person) {
16
+ 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
+ }
18
+ if (r.kind === 'library')
19
+ return _jsx(Library, {});
20
+ if (r.kind === 'explore')
21
+ return _jsx(Explore, {});
22
+ if (r.kind === 'activity')
23
+ return _jsx(Activity, {});
24
+ return _jsx(Talk, { id: r.kind === 'chat' ? r.id : null });
25
+ }
26
+ /** Studio's own rail, on studio.hanzo.ai: New, the places, the conversations, and the account. */
27
+ function Rail() {
28
+ const host = useHost();
29
+ const wire = useWire(host);
30
+ const { rows, error } = useChats(wire);
31
+ const [collapsed, setCollapsed] = useState(false);
32
+ const [drawer, setDrawer] = useState(false);
33
+ const r = route(host.path);
34
+ const go = (p) => {
35
+ setDrawer(false);
36
+ host.go(p);
37
+ };
38
+ const links = nav(host, go)
39
+ .flatMap((g) => g.links)
40
+ .filter((l) => l.id !== NEW);
41
+ const recents = rows.map((row) => ({ id: row.id, title: row.title, status: DOT[row.state] }));
42
+ return (_jsx(SessionRail, { onNew: () => go(''), newLabel: "New creation", fresh: r.kind === 'new', links: links, recents: recents, recentsLabel: "Recent", active: r.kind === 'chat' ? r.id : null, onOpen: (id) => go(path({ kind: 'chat', id })), empty: _jsx(SizableText, { size: "$1", color: "$soft", px: "$2", children: error || 'Nothing made yet.' }), account: host.person
43
+ ? {
44
+ name: host.person.name || host.person.email,
45
+ sub: host.org ?? undefined,
46
+ email: host.person.email,
47
+ onSignOut: host.signOut,
48
+ }
49
+ : { name: 'Sign in', onPress: () => host.signIn?.() }, collapsed: collapsed, onCollapse: setCollapsed, open: drawer, onOpenChange: setDrawer, label: "Studio" }));
50
+ }
51
+ /**
52
+ * Studio. `rail={false}` leaves the left column to the host, which lists
53
+ * Studio's places with `nav`; Studio is then a pane of the host's and paints
54
+ * no ground of its own.
55
+ */
56
+ export function Studio({ host, rail = true }) {
57
+ return (_jsx(StudioHost, { host: host, children: _jsxs(XStack, { flex: 1, minH: 0, minW: 0, height: "100%", bg: rail ? '$background' : undefined, gap: rail ? 'var(--pane-gap, var(--space-2))' : 0, p: rail ? 'var(--pane-gap, var(--space-2))' : 0, children: [rail ? _jsx(Rail, {}) : null, _jsx(YStack, { flex: 1, minW: 0, minH: 0, children: _jsx(Pane, {}) })] }) }));
58
+ }
package/lib/talk.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function Talk({ id }: {
2
+ id: string | null;
3
+ }): import("react").JSX.Element;