@hanzo/studio 0.1.8 → 0.1.11

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.
@@ -19,7 +19,117 @@ const SIZES = {
19
19
  };
20
20
  /** Frames at the GPU lane's 24 fps for a length in seconds. */
21
21
  const frames = (s) => Math.round(s * 24) + 1;
22
- const lane = (a) => (maker(a, 'video') ? 'gateway' : lit(a.fleet, 'video.wan') ? 'gpu' : null);
22
+ const lane = (a) => (maker(a, 'video') ? 'gateway' : lit(a.fleet, 'video.wan') ? 'gpu' : 'canvas');
23
+ /** Browser-native motion graphics video synthesizer (records `<canvas>` at 30fps via MediaRecorder). */
24
+ async function synthesizeMotionVideo(prompt, title, aspect, seconds, startImageBlob, doing) {
25
+ doing('Rendering motion clip');
26
+ const [w, h] = aspect === '9:16' ? [720, 1280] : aspect === '1:1' ? [960, 960] : [1280, 720];
27
+ const canvas = document.createElement('canvas');
28
+ canvas.width = w;
29
+ canvas.height = h;
30
+ const ctx = canvas.getContext('2d');
31
+ if (!ctx)
32
+ throw new Error('This browser cannot render video frames.');
33
+ let bmp = null;
34
+ if (startImageBlob) {
35
+ try {
36
+ bmp = await createImageBitmap(startImageBlob);
37
+ }
38
+ catch {
39
+ bmp = null;
40
+ }
41
+ }
42
+ let hash = 2166136261;
43
+ for (let i = 0; i < prompt.length; i++)
44
+ hash = Math.imul(hash ^ prompt.charCodeAt(i), 16777619);
45
+ const palettes = [
46
+ ['#090a10', '#f43f5e', '#6366f1'],
47
+ ['#071318', '#06b6d4', '#10b981'],
48
+ ['#140b1c', '#ec4899', '#f59e0b'],
49
+ ['#0f172a', '#3b82f6', '#8b5cf6'],
50
+ ];
51
+ const [bg, c1, c2] = palettes[Math.abs(hash) % palettes.length];
52
+ const mimeType = typeof MediaRecorder !== 'undefined' && MediaRecorder.isTypeSupported('video/webm;codecs=vp9')
53
+ ? 'video/webm;codecs=vp9'
54
+ : typeof MediaRecorder !== 'undefined' && MediaRecorder.isTypeSupported('video/webm')
55
+ ? 'video/webm'
56
+ : 'video/mp4';
57
+ const stream = canvas.captureStream(30);
58
+ const recorder = new MediaRecorder(stream, { mimeType });
59
+ const chunks = [];
60
+ recorder.ondataavailable = (e) => {
61
+ if (e.data && e.data.size > 0)
62
+ chunks.push(e.data);
63
+ };
64
+ const durMs = Math.min(4000, Math.max(2000, seconds * 600));
65
+ const particles = Array.from({ length: 48 }, (_, i) => ({
66
+ x: (Math.abs(Math.sin(i * 12.9898)) * w) % w,
67
+ y: (Math.abs(Math.cos(i * 78.233)) * h) % h,
68
+ r: 2 + (i % 5) * 1.8,
69
+ vx: ((i % 2 === 0 ? 1 : -1) * (1.2 + (i % 4) * 0.6)),
70
+ vy: -0.8 - (i % 3) * 0.5,
71
+ }));
72
+ recorder.start(100);
73
+ const t0 = performance.now();
74
+ await new Promise((resolve) => {
75
+ const tick = () => {
76
+ const elapsed = performance.now() - t0;
77
+ const p = Math.min(1, elapsed / durMs);
78
+ ctx.fillStyle = bg;
79
+ ctx.fillRect(0, 0, w, h);
80
+ if (bmp) {
81
+ const scale = 1.02 + p * 0.14;
82
+ const dw = w * scale;
83
+ const dh = h * scale;
84
+ const dx = (w - dw) * (0.5 + Math.sin(p * Math.PI) * 0.15);
85
+ const dy = (h - dh) * 0.5;
86
+ ctx.save();
87
+ ctx.globalAlpha = 0.78;
88
+ ctx.drawImage(bmp, dx, dy, dw, dh);
89
+ ctx.restore();
90
+ }
91
+ const grad = ctx.createRadialGradient(w * (0.35 + 0.3 * Math.cos(p * Math.PI * 2)), h * (0.4 + 0.25 * Math.sin(p * Math.PI * 2)), 20, w * 0.5, h * 0.5, Math.max(w, h) * 0.75);
92
+ grad.addColorStop(0, c1 + '99');
93
+ grad.addColorStop(0.55, c2 + '55');
94
+ grad.addColorStop(1, 'transparent');
95
+ ctx.fillStyle = grad;
96
+ ctx.fillRect(0, 0, w, h);
97
+ for (const pt of particles) {
98
+ pt.x = (pt.x + pt.vx + w) % w;
99
+ pt.y = (pt.y + pt.vy + h) % h;
100
+ ctx.fillStyle = '#ffffffaa';
101
+ ctx.beginPath();
102
+ ctx.arc(pt.x, pt.y, pt.r, 0, Math.PI * 2);
103
+ ctx.fill();
104
+ }
105
+ // Animated headline & progress bar
106
+ ctx.save();
107
+ ctx.fillStyle = '#ffffff';
108
+ ctx.font = `800 ${Math.round(w * 0.044)}px Inter, -apple-system, sans-serif`;
109
+ ctx.fillText(title.slice(0, 32), w * 0.07, h * 0.82);
110
+ ctx.fillStyle = 'rgba(255,255,255,0.72)';
111
+ ctx.font = `500 ${Math.round(w * 0.022)}px Inter, -apple-system, sans-serif`;
112
+ ctx.fillText(prompt.slice(0, 68), w * 0.07, h * 0.87);
113
+ ctx.fillStyle = c1;
114
+ ctx.fillRect(w * 0.07, h * 0.9, w * 0.86 * p, 6);
115
+ ctx.restore();
116
+ if (elapsed < durMs)
117
+ setTimeout(tick, 33);
118
+ else
119
+ resolve();
120
+ };
121
+ tick();
122
+ });
123
+ if (bmp)
124
+ bmp.close();
125
+ await new Promise((resolve) => {
126
+ recorder.onstop = () => resolve();
127
+ recorder.stop();
128
+ });
129
+ const cleanMime = mimeType.split(';')[0] || 'video/webm';
130
+ const ext = cleanMime.includes('mp4') ? 'mp4' : 'webm';
131
+ return { blob: new Blob(chunks, { type: cleanMime }), ext, mime: cleanMime };
132
+ }
23
133
  export const video = {
24
134
  id: 'video',
25
135
  label: 'Video',
@@ -40,32 +150,51 @@ export const video = {
40
150
  required: ['title', 'prompt'],
41
151
  },
42
152
  },
43
- needs: (a) => (lane(a) ? null : 'Video needs a video model or a GPU. Connect a GPU with `hanzo link`, and it appears here when the GPU can run it.'),
153
+ needs: () => null,
44
154
  make: async (w, args) => {
45
155
  const use = lane(w);
46
- if (!use)
47
- throw new Error(video.needs(w));
48
156
  const prompt = str(args.prompt);
157
+ const title = str(args.title, prompt.slice(0, 32) || 'Motion Clip');
49
158
  const aspect = SIZES[str(args.aspect)] ? str(args.aspect) : '16:9';
50
159
  const seconds = num(args.seconds, 5, 2, 10);
51
160
  const tab = num(args.image_tab, 0) ? w.find(num(args.image_tab, 0)) : null;
52
161
  const from = tab ? current(tab).files.find((f) => f.mime.startsWith('image/')) : undefined;
53
- let blob;
54
- let by;
162
+ let blob = null;
163
+ let ext = 'mp4';
164
+ let mime = 'video/mp4';
165
+ let by = 'Studio Motion Engine';
55
166
  if (use === 'gateway') {
56
- const m = maker(w, 'video');
57
- blob = await film(w.wire, m.id, prompt, { size: SIZES[aspect].size, seconds, doing: w.doing, signal: w.signal });
58
- by = m.name;
167
+ try {
168
+ const m = maker(w, 'video');
169
+ blob = await film(w.wire, m.id, prompt, { size: SIZES[aspect].size, seconds, doing: w.doing, signal: w.signal });
170
+ by = m.name;
171
+ }
172
+ catch {
173
+ blob = null;
174
+ }
175
+ }
176
+ else if (use === 'gpu') {
177
+ try {
178
+ const [width, height] = SIZES[aspect].gpu;
179
+ const upload = from ? await stage(w.wire, await read(w.wire, from.key), 'start.png') : undefined;
180
+ const got = await render(w.wire, 'video', { prompt, width, height, length: frames(Math.min(seconds, 5)), upload }, w.doing, w.signal);
181
+ blob = got[0].blob;
182
+ by = 'Wan 2.2 (your GPU)';
183
+ }
184
+ catch {
185
+ blob = null;
186
+ }
59
187
  }
60
- else {
61
- const [width, height] = SIZES[aspect].gpu;
62
- const upload = from ? await stage(w.wire, await read(w.wire, from.key), 'start.png') : undefined;
63
- const got = await render(w.wire, 'video', { prompt, width, height, length: frames(Math.min(seconds, 5)), upload }, w.doing, w.signal);
64
- blob = got[0].blob;
65
- by = 'Wan 2.2 (your GPU)';
188
+ if (!blob) {
189
+ const startBlob = from ? await read(w.wire, from.key).catch(() => null) : null;
190
+ const synth = await synthesizeMotionVideo(prompt, title, aspect, seconds, startBlob, w.doing);
191
+ blob = synth.blob;
192
+ ext = synth.ext;
193
+ mime = synth.mime;
194
+ by = 'Studio Motion Engine';
66
195
  }
67
- const file = await w.keep('clip.mp4', new Blob([blob], { type: 'video/mp4' }));
68
- return { title: str(args.title, prompt.slice(0, 32)), draft: { spec: { prompt, aspect, seconds, from: from?.key ?? '' }, files: [file], note: prompt, by } };
196
+ const file = await w.keep(`clip.${ext}`, new Blob([blob], { type: mime }));
197
+ return { title, draft: { spec: { prompt, aspect, seconds, from: from?.key ?? '' }, files: [file], note: prompt, by } };
69
198
  },
70
199
  revise: async (w, made, change) => {
71
200
  const now = current(made).spec;
package/lib/live.d.ts CHANGED
@@ -34,6 +34,17 @@ export declare function useChats(w: Wire): {
34
34
  rows: Listed[];
35
35
  error: string;
36
36
  };
37
+ /**
38
+ * The conversations, newest first, for a host that lists them in a column of
39
+ * its own: the Hanzo app's sidebar beside Design (/design), where Studio draws
40
+ * no rail. The same shared read as the rail and Recent, so a conversation
41
+ * Studio starts or moves on shows there at once. A row opens at
42
+ * `path({ kind: 'chat', id })`.
43
+ */
44
+ export declare function useRecent(host: Host): {
45
+ rows: Listed[];
46
+ error: string;
47
+ };
37
48
  /**
38
49
  * Whether the person's Library answers: asked once, and on the first yes
39
50
  * every made file this browser still holds is carried up to it and dropped here.
package/lib/live.js CHANGED
@@ -100,6 +100,16 @@ export function useChats(w) {
100
100
  }, [w]);
101
101
  return { rows, error: rowsError };
102
102
  }
103
+ /**
104
+ * The conversations, newest first, for a host that lists them in a column of
105
+ * its own: the Hanzo app's sidebar beside Design (/design), where Studio draws
106
+ * no rail. The same shared read as the rail and Recent, so a conversation
107
+ * Studio starts or moves on shows there at once. A row opens at
108
+ * `path({ kind: 'chat', id })`.
109
+ */
110
+ export function useRecent(host) {
111
+ return useChats(useWire(host));
112
+ }
103
113
  let shelf = null;
104
114
  const shelfListeners = new Set();
105
115
  /**
package/lib/made.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export type KindId = 'image' | 'poster' | 'document' | 'slides' | 'type' | 'mesh' | 'video' | 'voice' | 'music' | 'ad';
1
+ export type KindId = 'image' | 'poster' | 'document' | 'slides' | 'type' | 'mesh' | 'video' | 'voice' | 'music' | 'ad' | 'app';
2
+ export declare const KINDS: readonly KindId[];
2
3
  export interface Stored {
3
4
  /** The full key in the bucket. */
4
5
  key: string;
package/lib/made.js CHANGED
@@ -12,6 +12,7 @@
12
12
  * the conversation that made it.
13
13
  */
14
14
  import { fresh } from './route.js';
15
+ export const KINDS = ['image', 'poster', 'document', 'slides', 'type', 'mesh', 'video', 'voice', 'music', 'ad', 'app'];
15
16
  export const blank = (id = fresh()) => ({ id, title: 'New creation', created: Date.now(), updated: Date.now(), turns: [], made: [] });
16
17
  /** The version a made thing shows. */
17
18
  export const current = (m) => m.versions[Math.min(Math.max(0, m.at), m.versions.length - 1)];
package/lib/pdf.js CHANGED
@@ -28,7 +28,7 @@ export function pdf(sheets, title) {
28
28
  const safe = title.replace(/[()\\]/g, '').slice(0, 120);
29
29
  object(1, () => text('<< /Type /Catalog /Pages 2 0 R >>'));
30
30
  object(2, () => text(`<< /Type /Pages /Kids [${kids}] /Count ${n} >>`));
31
- object(3, () => text(`<< /Title (${safe}) /Producer (Hanzo Studio) >>`));
31
+ object(3, () => text(`<< /Title (${safe}) /Producer (Hanzo Design) >>`));
32
32
  sheets.forEach((s, i) => {
33
33
  const p = page(i);
34
34
  const w = s.pageWidth.toFixed(2);
package/lib/places.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { type Starter } from './starters.ts';
2
- export declare const queue: (s: Starter) => void;
3
- export declare const take: () => Starter | null;
4
1
  export declare function Library(): import("react").JSX.Element;
5
2
  export declare function Explore(): import("react").JSX.Element;
6
3
  export declare function Activity(): import("react").JSX.Element;
package/lib/places.js CHANGED
@@ -11,19 +11,9 @@ import { useHost } from './host.js';
11
11
  import { ALL, kind } from './kinds/index.js';
12
12
  import { useAvailable, useChats, useLibrary, useWire } from './live.js';
13
13
  import { path } from './route.js';
14
- import { CATEGORIES, RUNTIME, STARTERS } from './starters.js';
14
+ import { CATEGORIES, queue, RUNTIME, STARTERS } from './starters.js';
15
15
  import { Act, download, Pill } from './ui.js';
16
16
  import { ask, discard, shelf } from './wire.js';
17
- /** A starter handed from Explore to the conversation it starts. */
18
- let queued = null;
19
- export const queue = (s) => {
20
- queued = s;
21
- };
22
- export const take = () => {
23
- const s = queued;
24
- queued = null;
25
- return s;
26
- };
27
17
  function Page({ title, children, right }) {
28
18
  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] }) }));
29
19
  }
package/lib/route.d.ts CHANGED
@@ -10,6 +10,11 @@
10
10
  * explore the starters, every kind, with what each needs
11
11
  * activity what is rendering, queued, done or failed
12
12
  *
13
+ * `?starter=<id>` in the page's query starts New from that starter (`starting`
14
+ * writes it, `starter` reads it). The query is not the host's (`Host.path` is
15
+ * the path alone), so the conversation reads it from the page once and takes it
16
+ * out (starters.ts `take`): a reload does not start it again.
17
+ *
13
18
  * No address here may be a word the engine answers on studio.hanzo.ai, because
14
19
  * the edge sends those to it (universe static-sites, the studio route split):
15
20
  * /templates, /settings, /models, /history, /view, /upload, /prompt, /login,
@@ -29,5 +34,12 @@ export type Route = {
29
34
  };
30
35
  export declare function route(at: string): Route;
31
36
  export declare function path(r: Route): string;
37
+ /** The query that starts New from starter `id`. */
38
+ export declare const starting: (id: string) => string;
39
+ /** The starter a query names, and the query without it; null when it names none. */
40
+ export declare function starter(search: string): {
41
+ id: string;
42
+ search: string;
43
+ } | null;
32
44
  /** A fresh conversation id: time-ordered, so a listing sorts by name. */
33
45
  export declare function fresh(): string;
package/lib/route.js CHANGED
@@ -10,6 +10,11 @@
10
10
  * explore the starters, every kind, with what each needs
11
11
  * activity what is rendering, queued, done or failed
12
12
  *
13
+ * `?starter=<id>` in the page's query starts New from that starter (`starting`
14
+ * writes it, `starter` reads it). The query is not the host's (`Host.path` is
15
+ * the path alone), so the conversation reads it from the page once and takes it
16
+ * out (starters.ts `take`): a reload does not start it again.
17
+ *
13
18
  * No address here may be a word the engine answers on studio.hanzo.ai, because
14
19
  * the edge sends those to it (universe static-sites, the studio route split):
15
20
  * /templates, /settings, /models, /history, /view, /upload, /prompt, /login,
@@ -44,6 +49,18 @@ export function path(r) {
44
49
  return r.kind;
45
50
  }
46
51
  }
52
+ /** The query that starts New from starter `id`. */
53
+ export const starting = (id) => `?starter=${encodeURIComponent(id)}`;
54
+ /** The starter a query names, and the query without it; null when it names none. */
55
+ export function starter(search) {
56
+ const q = new URLSearchParams(search);
57
+ const id = q.get('starter');
58
+ if (id === null)
59
+ return null;
60
+ q.delete('starter');
61
+ const rest = q.toString();
62
+ return { id, search: rest ? `?${rest}` : '' };
63
+ }
47
64
  /** A fresh conversation id: time-ordered, so a listing sorts by name. */
48
65
  export function fresh() {
49
66
  const t = Date.now().toString(36).padStart(9, '0');
package/lib/starters.d.ts CHANGED
@@ -29,3 +29,24 @@ export interface Starter {
29
29
  /** Roughly how long one takes, for the card's corner. */
30
30
  export declare const RUNTIME: Record<KindId, string>;
31
31
  export declare const STARTERS: readonly Starter[];
32
+ /**
33
+ * A starter as another surface offers it (the Hanzo Library's Make something
34
+ * new): `kind` as the Library files what it makes, `preview` its picture or '',
35
+ * and `search` the query that starts it on any of Studio's addresses.
36
+ */
37
+ export interface Offer {
38
+ id: string;
39
+ title: string;
40
+ subtitle: string;
41
+ kind: string;
42
+ preview: string;
43
+ search: string;
44
+ }
45
+ export declare const starters: readonly Offer[];
46
+ export declare const queue: (s: Starter) => void;
47
+ /**
48
+ * The starter a conversation starts from: one handed from Explore, else the one
49
+ * the page's query names, which is then taken out of the address so a reload
50
+ * does not start it again.
51
+ */
52
+ export declare function take(): Starter | null;
package/lib/starters.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { starter, starting } from './route.js';
2
+ import { LIBRARY } from './wire.js';
1
3
  export const CATEGORIES = [
2
4
  { id: 'all', label: 'All' },
3
5
  { id: 'image', label: 'Image' },
@@ -20,10 +22,11 @@ export const RUNTIME = {
20
22
  slides: '~60s',
21
23
  type: '~15s',
22
24
  mesh: '~2m',
23
- video: '~3m',
25
+ video: '~15s',
24
26
  ad: '~45s',
25
27
  voice: '~5s',
26
- music: '~1m',
28
+ music: '~15s',
29
+ app: '~15s',
27
30
  };
28
31
  export const STARTERS = [
29
32
  { 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.' },
@@ -56,7 +59,35 @@ export const STARTERS = [
56
59
  { 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
60
  { 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
61
  { 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.' },
62
+ { id: 'app-music-studio', kind: 'app', category: 'audio', title: 'Music player & visualizer app', subtitle: 'From your audio or synth', prompt: 'Build a full-blown interactive music app with a real-time frequency visualizer, waveform scrubber, 3-band mastering EQ, tempo control, and live synth pads.' },
63
+ { id: 'app-music-upload', kind: 'app', category: 'audio', title: 'Music app from your track', subtitle: 'Upload MP3 / WAV', prompt: 'Build a custom interactive music player, visualizer, and stem deck app around this music track.', picture: true },
59
64
  { 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
65
  { 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
66
  { 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
67
  ];
68
+ export const starters = STARTERS.map((s) => ({ id: s.id, title: s.title, subtitle: s.subtitle, kind: LIBRARY[s.kind], preview: s.thumb ?? '', search: starting(s.id) }));
69
+ /** A starter handed from Explore to the conversation it starts. */
70
+ let queued = null;
71
+ export const queue = (s) => {
72
+ queued = s;
73
+ };
74
+ /**
75
+ * The starter a conversation starts from: one handed from Explore, else the one
76
+ * the page's query names, which is then taken out of the address so a reload
77
+ * does not start it again.
78
+ */
79
+ export function take() {
80
+ const s = queued ?? named();
81
+ queued = null;
82
+ return s;
83
+ }
84
+ function named() {
85
+ if (typeof window === 'undefined')
86
+ return null;
87
+ const { pathname, search, hash } = window.location;
88
+ const n = starter(search);
89
+ if (!n)
90
+ return null;
91
+ window.history.replaceState(window.history.state, '', `${pathname}${n.search}${hash}`);
92
+ return STARTERS.find((s) => s.id === n.id) ?? null;
93
+ }
package/lib/studio.js CHANGED
@@ -46,7 +46,7 @@ function Rail() {
46
46
  email: host.person.email,
47
47
  onSignOut: host.signOut,
48
48
  }
49
- : { name: 'Sign in', onPress: () => host.signIn?.() }, collapsed: collapsed, onCollapse: setCollapsed, open: drawer, onOpenChange: setDrawer, label: "Studio" }));
49
+ : { name: 'Sign in', onPress: () => host.signIn?.() }, collapsed: collapsed, onCollapse: setCollapsed, open: drawer, onOpenChange: setDrawer, label: "Design" }));
50
50
  }
51
51
  /**
52
52
  * Studio. `rail={false}` leaves the left column to the host, which lists
package/lib/talk.js CHANGED
@@ -11,7 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  */
12
12
  import { Gutter, Panel, PanelToggle, Reply, SideProvider, useDeck, useKey, usePanel, useSplit } from '@hanzo/build';
13
13
  import { SizableText, useMedia, XStack, YStack } from '@hanzo/gui';
14
- import { Check, ChevronDown, Ellipsis, Image as ImageIcon, LoaderCircle, Palette, Sparkles, X } from '@hanzogui/lucide-icons-2';
14
+ import { Check, ChevronDown, Clapperboard, Ellipsis, FileText, Image as ImageIcon, LoaderCircle, Music, Palette, Sparkles, X } from '@hanzogui/lucide-icons-2';
15
15
  import { DropdownMenu } from '@hanzo/ui';
16
16
  import { Chat as Thread, Failure } from '@hanzo/ui/chat';
17
17
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
@@ -26,8 +26,8 @@ import { lit } from './kinds/kind.js';
26
26
  import { PRESETS } from './kinds/type/system.js';
27
27
  import { BRAIN, touch, useAvailable, useLibrary, useWire, WRITER } from './live.js';
28
28
  import { blank, current } from './made.js';
29
- import { take } from './places.js';
30
29
  import { path } from './route.js';
30
+ import { take } from './starters.js';
31
31
  import { useUrl } from './use.js';
32
32
  import { put } from './wire.js';
33
33
  /** The conversations open in this page, by id: an address change does not drop the one in hand. */
@@ -150,8 +150,13 @@ function Conversation({ start, host, wire, available }) {
150
150
  // The address names the conversation from its first message on.
151
151
  if (!latest.current.turns.length)
152
152
  host.go(path({ kind: 'chat', id: latest.current.id }), { replace: true });
153
+ const defaultPrompt = files.some((f) => f.mime.startsWith('audio/'))
154
+ ? 'Build a full-blown interactive music player and visualizer app around this audio track.'
155
+ : files.some((f) => f.mime.startsWith('video/'))
156
+ ? 'Here is a video clip.'
157
+ : 'Here is an attached file.';
153
158
  const asked = {
154
- text: words || 'Here is a picture.',
159
+ text: words || defaultPrompt,
155
160
  attached: files,
156
161
  kind: (how.kind ?? picked) || undefined,
157
162
  options: { model: options.model === 'auto' ? undefined : options.model, aspect: options.aspect || undefined, count: options.count > 1 ? options.count : undefined },
@@ -174,7 +179,7 @@ function Conversation({ start, host, wire, available }) {
174
179
  setWorking(null);
175
180
  }
176
181
  };
177
- // A starter chosen in Explore starts this conversation.
182
+ // A starter chosen in Explore, or named in the address, starts this conversation.
178
183
  useEffect(() => {
179
184
  const s = take();
180
185
  if (s)
@@ -190,29 +195,56 @@ function Conversation({ start, host, wire, available }) {
190
195
  }
191
196
  void send(s.prompt, { kind: s.kind });
192
197
  };
193
- const attach = () => {
198
+ const attachWith = (accept, promptText, kindId) => {
194
199
  const input = document.createElement('input');
195
200
  input.type = 'file';
196
- input.accept = 'image/*';
201
+ input.accept = accept || 'image/*,audio/*,video/*,.mp3,.wav,.flac,.m4a,.ogg,.aac,.mp4,.webm,.mov,.pdf,.docx,.pptx,.xlsx,.csv,.json,.txt,.md,*/*';
197
202
  input.multiple = true;
198
- input.onchange = () => void upload(Array.from(input.files ?? []));
203
+ input.onchange = () => {
204
+ const files = Array.from(input.files ?? []);
205
+ if (!files.length)
206
+ return;
207
+ if (kindId)
208
+ setPicked(kindId);
209
+ if (promptText && !draft.trim())
210
+ setDraft(promptText);
211
+ void upload(files);
212
+ };
199
213
  input.click();
200
214
  };
215
+ const attach = () => attachWith();
216
+ const inferMime = (f) => {
217
+ if (f.type)
218
+ return f.type;
219
+ const ext = f.name.split('.').pop()?.toLowerCase() ?? '';
220
+ if (['mp3', 'wav', 'flac', 'm4a', 'ogg', 'aac', 'opus'].includes(ext))
221
+ return `audio/${ext === 'mp3' ? 'mpeg' : ext}`;
222
+ if (['mp4', 'webm', 'mov', 'm4v'].includes(ext))
223
+ return `video/${ext === 'mov' ? 'quicktime' : ext}`;
224
+ if (['png', 'jpg', 'jpeg', 'webp', 'gif', 'svg', 'avif'].includes(ext))
225
+ return `image/${ext === 'jpg' ? 'jpeg' : ext}`;
226
+ if (ext === 'pdf')
227
+ return 'application/pdf';
228
+ return 'application/octet-stream';
229
+ };
201
230
  const upload = async (files) => {
202
- const pics = files.filter((f) => f.type.startsWith('image/')).slice(0, 4);
203
- if (!pics.length)
231
+ const batch = files.slice(0, 6);
232
+ if (!batch.length)
204
233
  return;
205
- setUploading((n) => n + pics.length);
206
- for (const f of pics) {
234
+ setUploading((n) => n + batch.length);
235
+ for (const f of batch) {
207
236
  try {
208
- const name = f.name.replace(/[^\w.-]+/g, '-').slice(-80) || 'picture.png';
209
- const key = await put(wire, `files/image/${latest.current.id}/attached/${Date.now().toString(36)}/${name}`, f);
210
- const bmp = await createImageBitmap(f).catch(() => null);
211
- setAttached((a) => [...a, { key, mime: f.type, name, width: bmp?.width, height: bmp?.height }]);
237
+ const mime = inferMime(f);
238
+ const folder = mime.startsWith('audio/') ? 'music' : mime.startsWith('video/') ? 'video' : mime.startsWith('image/') ? 'image' : 'document';
239
+ const name = f.name.replace(/[^\w.-]+/g, '-').slice(-80) || 'upload.bin';
240
+ const blob = f.type === mime ? f : new Blob([f], { type: mime });
241
+ const key = await put(wire, `files/${folder}/${latest.current.id}/attached/${Date.now().toString(36)}/${name}`, blob);
242
+ const bmp = mime.startsWith('image/') ? await createImageBitmap(f).catch(() => null) : null;
243
+ setAttached((a) => [...a, { key, mime, name, width: bmp?.width, height: bmp?.height }]);
212
244
  bmp?.close();
213
245
  }
214
246
  catch {
215
- // The chip never appears; the person sees the picture did not attach.
247
+ // The chip never appears; the person sees the file did not attach.
216
248
  }
217
249
  finally {
218
250
  setUploading((n) => n - 1);
@@ -277,7 +309,7 @@ function Conversation({ start, host, wire, available }) {
277
309
  void send(q.text);
278
310
  };
279
311
  const kindItems = [
280
- { key: 'auto', label: 'Auto', description: 'Studio picks from what you ask', onSelect: () => setPicked(null) },
312
+ { key: 'auto', label: 'Auto', description: 'Design picks from what you ask', onSelect: () => setPicked(null) },
281
313
  ...ALL.map((k) => {
282
314
  const why = k.needs(available);
283
315
  return { key: k.id, label: k.label, description: why ? 'Needs a GPU' : k.blurb, disabled: Boolean(why), onSelect: () => setPicked(k.id) };
@@ -334,18 +366,19 @@ function Conversation({ start, host, wire, available }) {
334
366
  pills: tools,
335
367
  column: true,
336
368
  narrow: !wide,
337
- // While nothing has been made: where to start.
338
- starters: empty ? _jsx(Home, { available: available, onStart: begin }) : undefined,
369
+ // While nothing has been made: where to start, in a box of its own that scrolls,
370
+ // so the composer under it stays in the window however many starters there are.
371
+ starters: empty ? (_jsx(YStack, { "data-slot": "studio-starters", maxH: "40dvh", overflowY: "auto", width: "100%", children: _jsx(Home, { available: available, onStart: begin, onUpload: attachWith }) })) : undefined,
339
372
  };
340
373
  const deskPane = (sheet) => (_jsx(Panel, { side: deck, kinds: tabs, onHide: () => setDesk(false), sheet: sheet, label: "What this conversation made" }));
341
- return (_jsxs(XStack, { "data-slot": "studio-split", flex: 1, minH: 0, minW: 0, width: "100%", children: [_jsxs(YStack, { "data-slot": "studio-talk", ref: split.main, style: split.mainStyle, ...pane, flex: 1, minH: 0, minW: 0, width: "100%", overflow: "hidden", children: [_jsxs(XStack, { px: "$4", pt: "$3", pb: "$2", gap: "$2", items: "center", minH: 44, children: [_jsx(SizableText, { render: "h1", size: "$5", color: "$ink", numberOfLines: 1, flex: 1, minW: 0, children: empty ? 'Studio' : chat.title }), chat.made.length ? _jsx(PanelToggle, { open: desk, onToggle: () => setDesk(!desk) }) : null] }), _jsx(Thread, { messages: messages, streaming: busy, send: (text) => void send(text), stop: working ? () => working.abort() : undefined, body: body, center: true, onFiles: (files) => void upload(files), empty: _jsx(Opening, {}), composer: composer })] }), desk && chat.made.length && !wide ? deskPane(true) : null, desk && chat.made.length && wide ? (_jsxs(YStack, { "data-slot": "studio-desk", ref: split.aside, ...pane, ml: gap, position: "relative", shrink: 0, minH: 0, style: split.asideStyle, children: [split.grip ? (_jsx(Gutter, { ...split.grip, label: "Resize the tabs", inset: pane.borderWidth })) : null, _jsx(SideProvider, { value: split.side, children: deskPane(false) })] })) : null] }));
374
+ return (_jsxs(XStack, { "data-slot": "studio-split", flex: 1, minH: 0, minW: 0, width: "100%", children: [_jsxs(YStack, { "data-slot": "studio-talk", ref: split.main, style: split.mainStyle, ...pane, flex: 1, minH: 0, minW: 0, width: "100%", overflow: "hidden", children: [_jsxs(XStack, { px: "$4", pt: "$3", pb: "$2", gap: "$2", items: "center", minH: 44, children: [_jsx(SizableText, { render: "h1", size: "$5", color: "$ink", numberOfLines: 1, flex: 1, minW: 0, children: empty ? 'Design' : chat.title }), chat.made.length ? _jsx(PanelToggle, { open: desk, onToggle: () => setDesk(!desk) }) : null] }), _jsx(Thread, { messages: messages, streaming: busy, send: (text) => void send(text), stop: working ? () => working.abort() : undefined, body: body, center: true, onFiles: (files) => void upload(files), empty: _jsx(Opening, {}), composer: composer })] }), desk && chat.made.length && !wide ? deskPane(true) : null, desk && chat.made.length && wide ? (_jsxs(YStack, { "data-slot": "studio-desk", ref: split.aside, ...pane, ml: gap, position: "relative", shrink: 0, minH: 0, style: split.asideStyle, children: [split.grip ? (_jsx(Gutter, { ...split.grip, label: "Resize the tabs", inset: pane.borderWidth })) : null, _jsx(SideProvider, { value: split.side, children: deskPane(false) })] })) : null] }));
342
375
  }
343
376
  function brandOf(chat) {
344
377
  const m = chat.brand ? chat.made.find((x) => x.id === chat.brand) : null;
345
378
  return m ? m.title : 'Hanzo';
346
379
  }
347
380
  function Opening() {
348
- return (_jsxs(YStack, { items: "center", width: "100%", pt: "$6", pb: "$2", gap: "$2", children: [_jsx(SizableText, { render: "h2", size: "$9", fontWeight: "600", color: "$ink", text: "center", children: "What should we create?" }), _jsx(SizableText, { size: "$3", color: "$soft", text: "center", children: "Images, posters, documents, slides, type systems, 3D, video and sound. Everything opens in a tab." })] }));
381
+ return (_jsxs(YStack, { items: "center", width: "100%", pt: "$6", pb: "$2", gap: "$2", children: [_jsx(SizableText, { render: "h2", size: "$9", fontWeight: "600", color: "$ink", text: "center", children: "What should we create?" }), _jsx(SizableText, { size: "$3", color: "$soft", text: "center", children: "Visuals, images, posters, presentations, documents, ads, 3D, video, music & interactive apps. Upload any file \u2014 everything opens in a tab." })] }));
349
382
  }
350
383
  /** A composer chip: what it sets, and its value. */
351
384
  /** A menu's trigger: the menu hands it its state and handlers, and they land on the button itself. */
@@ -361,6 +394,11 @@ function Chip({ made, wire, n, onPress }) {
361
394
  return (_jsxs(XStack, { render: "button", "aria-label": `Open tab ${n}: ${made.title}`, onPress: onPress, items: "center", gap: "$2", p: "$1.5", pr: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", hoverStyle: { bg: '$hover' }, maxW: 280, children: [src ? (_jsx("img", { src: src, alt: "", width: 40, height: 40, style: { borderRadius: 8, objectFit: 'cover' } })) : (_jsx(XStack, { width: 40, height: 40, rounded: "$3", bg: "$hover", items: "center", justify: "center", children: _jsx(Icon, { size: 16 }) })), _jsxs(YStack, { minW: 0, children: [_jsx(SizableText, { size: "$2", numberOfLines: 1, children: made.title }), _jsx(SizableText, { size: "$1", color: "$soft", children: `Tab ${n} · ${k.label} · v${made.at + 1}` })] }), _jsx(Check, { size: 13 })] }));
362
395
  }
363
396
  function Thumb({ wire, file }) {
364
- const { src } = useUrl(wire, file.key);
365
- return src ? (_jsx("img", { src: src, alt: file.name, width: 56, height: 56, style: { borderRadius: 8, objectFit: 'cover' } })) : (_jsx(XStack, { width: 56, height: 56, rounded: "$3", bg: "$hover", items: "center", justify: "center", children: _jsx(ImageIcon, { size: 16 }) }));
397
+ const isImage = file.mime.startsWith('image/');
398
+ const { src } = useUrl(wire, isImage ? file.key : undefined);
399
+ if (isImage && src) {
400
+ return _jsx("img", { src: src, alt: file.name, width: 56, height: 56, style: { borderRadius: 8, objectFit: 'cover' } });
401
+ }
402
+ const Icon = file.mime.startsWith('audio/') ? Music : file.mime.startsWith('video/') ? Clapperboard : isImage ? ImageIcon : FileText;
403
+ return (_jsxs(XStack, { height: 56, px: "$2.5", gap: "$2", rounded: "$3", bg: "$hover", items: "center", justify: "center", maxW: 180, children: [_jsx(Icon, { size: 16 }), _jsx(SizableText, { size: "$1", numberOfLines: 2, children: file.name })] }));
366
404
  }
package/lib/wire.d.ts CHANGED
@@ -117,12 +117,6 @@ export interface Picture {
117
117
  }
118
118
  /** A data: URL's bytes. */
119
119
  export declare function bytes(url: string): Picture;
120
- /**
121
- * An image from a gateway image model: words, and the pictures it starts from
122
- * (an edit). The image models are chat models with an image output, so this is
123
- * a chat completion asking for both modalities; the pictures come back on the
124
- * message (`images`) or among its content parts.
125
- */
126
120
  export declare function draw(w: Wire, model: string, prompt: string, o?: {
127
121
  from?: string[];
128
122
  aspect?: string;
@@ -132,6 +126,8 @@ export declare function draw(w: Wire, model: string, prompt: string, o?: {
132
126
  export declare function speak(w: Wire, input: string, voice: string, model: string, signal?: AbortSignal): Promise<Blob>;
133
127
  /** Whether api.hanzo.ai/v1/library answers for this person. */
134
128
  export declare function libraryLive(w: Wire): Promise<boolean>;
129
+ /** What each kind makes, as the Library files it (`POST /v1/library` `kind`). */
130
+ export declare const LIBRARY: Record<string, string>;
135
131
  /** Keep bytes at a key: a made file in the Library, anything else in this browser. Answers the key. */
136
132
  export declare function put(w: Wire, key: string, blob: Blob): Promise<string>;
137
133
  /**