@hanzo/studio 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +239 -0
  70. package/lib/wire.js +478 -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
@@ -0,0 +1,302 @@
1
+ /**
2
+ * A TYPE SYSTEM: the faces, the scale, the weights, the leading and the colours
3
+ * everything else is drawn in. It is the Brand chip: a poster, a document, a
4
+ * deck or an ad made while one is chosen takes its faces and colours from it.
5
+ *
6
+ * The presets are Studio's design systems as they were (Modernist, Classical,
7
+ * Nocturne, Organic, Broadsheet, Industry) with open faces in place of the
8
+ * commercial ones they named, and Hanzo, the design system Studio ships (Zen).
9
+ *
10
+ * Sizes are not stored: a scale is a base and a ratio, and step n is
11
+ * base x ratio^n, rounded to the pixel. Three exports read the same object:
12
+ * CSS custom properties, design tokens as JSON, and a @hanzo/gui theme.
13
+ */
14
+ import { FAMILIES, font, stack } from './fonts.js';
15
+ /** The named steps, smallest first, and the power of the ratio each is. */
16
+ export const STEPS = [
17
+ ['caption', -2],
18
+ ['small', -1],
19
+ ['body', 0],
20
+ ['lead', 1],
21
+ ['h4', 2],
22
+ ['h3', 3],
23
+ ['h2', 4],
24
+ ['h1', 5],
25
+ ['display', 7],
26
+ ];
27
+ export function size(t, step) {
28
+ const n = STEPS.find((s) => s[0] === step)[1];
29
+ return Math.round(t.scale.base * t.scale.ratio ** n);
30
+ }
31
+ /** The ratios a scale may take, by their musical names. */
32
+ export const RATIOS = [
33
+ [1.125, 'Major second'],
34
+ [1.2, 'Minor third'],
35
+ [1.25, 'Major third'],
36
+ [1.333, 'Perfect fourth'],
37
+ [1.414, 'Augmented fourth'],
38
+ [1.5, 'Perfect fifth'],
39
+ [1.618, 'Golden'],
40
+ ];
41
+ const sys = (s) => s;
42
+ export const PRESETS = [
43
+ sys({
44
+ name: 'Hanzo',
45
+ blurb: 'The Hanzo design system: Zen throughout, black and white, one bright edge.',
46
+ display: 'Zen',
47
+ text: 'Zen',
48
+ mono: 'Zen Mono',
49
+ scale: { base: 16, ratio: 1.25 },
50
+ weights: { display: 220, heading: 606, body: 497, strong: 650 },
51
+ leading: { display: 1.0, heading: 1.15, body: 1.55 },
52
+ tracking: { display: -0.03, caps: 0.08 },
53
+ colors: { ink: '#ededed', paper: '#0a0a0a', accent: '#ffffff', muted: '#8a8a8a', second: '#6aa5ff' },
54
+ }),
55
+ sys({
56
+ name: 'Modernist',
57
+ blurb: 'Swiss grid, generous whitespace, a single decisive accent.',
58
+ display: 'Inter',
59
+ text: 'Inter',
60
+ mono: 'JetBrains Mono',
61
+ scale: { base: 16, ratio: 1.333 },
62
+ weights: { display: 800, heading: 700, body: 400, strong: 600 },
63
+ leading: { display: 0.95, heading: 1.1, body: 1.5 },
64
+ tracking: { display: -0.04, caps: 0.1 },
65
+ colors: { ink: '#0a0a0a', paper: '#f4f4f4', accent: '#e8442a', muted: '#6e6e6e', second: '#1f4fd1' },
66
+ }),
67
+ sys({
68
+ name: 'Classical',
69
+ blurb: 'Serif headlines, warm neutrals, editorial hairlines.',
70
+ display: 'Cormorant Garamond',
71
+ text: 'EB Garamond',
72
+ mono: 'IBM Plex Mono',
73
+ scale: { base: 18, ratio: 1.333 },
74
+ weights: { display: 600, heading: 600, body: 400, strong: 600 },
75
+ leading: { display: 1.05, heading: 1.15, body: 1.6 },
76
+ tracking: { display: -0.01, caps: 0.12 },
77
+ colors: { ink: '#1c1a17', paper: '#f2ead9', accent: '#8a6d3b', muted: '#7d7464', second: '#3f5a4a' },
78
+ }),
79
+ sys({
80
+ name: 'Nocturne',
81
+ blurb: 'Near-black canvas, luminous accents, high contrast.',
82
+ display: 'Zen',
83
+ text: 'Zen',
84
+ mono: 'Zen Mono',
85
+ scale: { base: 16, ratio: 1.414 },
86
+ weights: { display: 300, heading: 600, body: 450, strong: 650 },
87
+ leading: { display: 1.0, heading: 1.12, body: 1.55 },
88
+ tracking: { display: -0.025, caps: 0.1 },
89
+ colors: { ink: '#ededed', paper: '#0a0a0b', accent: '#6aa5ff', muted: '#8b8b93', second: '#b48cff' },
90
+ }),
91
+ sys({
92
+ name: 'Organic',
93
+ blurb: 'Earthy palette, soft forms, humanist type.',
94
+ display: 'Fraunces',
95
+ text: 'Work Sans',
96
+ mono: 'IBM Plex Mono',
97
+ scale: { base: 17, ratio: 1.25 },
98
+ weights: { display: 700, heading: 600, body: 400, strong: 600 },
99
+ leading: { display: 1.02, heading: 1.15, body: 1.6 },
100
+ tracking: { display: -0.02, caps: 0.08 },
101
+ colors: { ink: '#2b2a24', paper: '#efe7d6', accent: '#8fae74', muted: '#857d6c', second: '#d99a6c' },
102
+ }),
103
+ sys({
104
+ name: 'Broadsheet',
105
+ blurb: 'Newsprint columns, tight leading, ink black.',
106
+ display: 'Playfair Display',
107
+ text: 'Source Serif 4',
108
+ mono: 'IBM Plex Mono',
109
+ scale: { base: 17, ratio: 1.5 },
110
+ weights: { display: 900, heading: 700, body: 400, strong: 700 },
111
+ leading: { display: 0.98, heading: 1.08, body: 1.45 },
112
+ tracking: { display: -0.015, caps: 0.14 },
113
+ colors: { ink: '#141414', paper: '#f7f5f0', accent: '#c0392b', muted: '#6b6b6b', second: '#2c3e50' },
114
+ }),
115
+ sys({
116
+ name: 'Industry',
117
+ blurb: 'Utilitarian grotesk and mono, safety accents, hard edges.',
118
+ display: 'Archivo',
119
+ text: 'IBM Plex Sans',
120
+ mono: 'IBM Plex Mono',
121
+ scale: { base: 15, ratio: 1.333 },
122
+ weights: { display: 900, heading: 700, body: 400, strong: 600 },
123
+ leading: { display: 0.92, heading: 1.05, body: 1.5 },
124
+ tracking: { display: -0.01, caps: 0.16 },
125
+ colors: { ink: '#e6e8ea', paper: '#101215', accent: '#ffcf4a', muted: '#8b9096', second: '#ff6b3d' },
126
+ }),
127
+ ];
128
+ const HEX = /^#[0-9a-f]{6}$/i;
129
+ /** A type system as the model or a person wrote it, made safe to draw: unknown faces, bad colours and wild numbers fall back. */
130
+ export function settle(v, base = PRESETS[0]) {
131
+ const pick = (f, or) => (typeof f === 'string' && FAMILIES.includes(f) ? f : or);
132
+ const c = (v.colors ?? {});
133
+ const color = (x, or) => (typeof x === 'string' && HEX.test(x) ? x.toLowerCase() : or);
134
+ const n = (x, or, lo, hi) => (typeof x === 'number' && Number.isFinite(x) ? Math.min(hi, Math.max(lo, x)) : or);
135
+ const w = (v.weights ?? {});
136
+ const l = (v.leading ?? {});
137
+ const t = (v.tracking ?? {});
138
+ const s = (v.scale ?? {});
139
+ const display = pick(v.display, base.display);
140
+ const text = pick(v.text, base.text);
141
+ const mono = font(pick(v.mono, base.mono)).role === 'mono' ? pick(v.mono, base.mono) : base.mono;
142
+ return {
143
+ name: typeof v.name === 'string' && v.name.trim() ? v.name.trim().slice(0, 60) : base.name,
144
+ blurb: typeof v.blurb === 'string' ? v.blurb.trim().slice(0, 200) : base.blurb,
145
+ display,
146
+ text,
147
+ mono,
148
+ scale: { base: Math.round(n(s.base, base.scale.base, 12, 24)), ratio: n(s.ratio, base.scale.ratio, 1.067, 1.618) },
149
+ weights: {
150
+ display: Math.round(n(w.display, base.weights.display, 100, 900)),
151
+ heading: Math.round(n(w.heading, base.weights.heading, 100, 900)),
152
+ body: Math.round(n(w.body, base.weights.body, 100, 900)),
153
+ strong: Math.round(n(w.strong, base.weights.strong, 100, 900)),
154
+ },
155
+ leading: {
156
+ display: n(l.display, base.leading.display, 0.8, 1.4),
157
+ heading: n(l.heading, base.leading.heading, 0.9, 1.6),
158
+ body: n(l.body, base.leading.body, 1.2, 2.0),
159
+ },
160
+ tracking: { display: n(t.display, base.tracking.display, -0.1, 0.1), caps: n(t.caps, base.tracking.caps, 0, 0.3) },
161
+ colors: {
162
+ ink: color(c.ink, base.colors.ink),
163
+ paper: color(c.paper, base.colors.paper),
164
+ accent: color(c.accent, base.colors.accent),
165
+ muted: color(c.muted, base.colors.muted),
166
+ second: color(c.second, base.colors.second),
167
+ },
168
+ };
169
+ }
170
+ /** The JSON Schema a model fills to write one. */
171
+ export const SCHEMA = {
172
+ type: 'object',
173
+ additionalProperties: false,
174
+ required: ['name', 'blurb', 'display', 'text', 'mono', 'scale', 'weights', 'leading', 'tracking', 'colors'],
175
+ properties: {
176
+ name: { type: 'string' },
177
+ blurb: { type: 'string' },
178
+ display: { type: 'string', enum: FAMILIES },
179
+ text: { type: 'string', enum: FAMILIES },
180
+ mono: { type: 'string', enum: FAMILIES.filter((f) => font(f).role === 'mono') },
181
+ scale: {
182
+ type: 'object',
183
+ additionalProperties: false,
184
+ required: ['base', 'ratio'],
185
+ properties: { base: { type: 'number' }, ratio: { type: 'number' } },
186
+ },
187
+ weights: {
188
+ type: 'object',
189
+ additionalProperties: false,
190
+ required: ['display', 'heading', 'body', 'strong'],
191
+ properties: { display: { type: 'number' }, heading: { type: 'number' }, body: { type: 'number' }, strong: { type: 'number' } },
192
+ },
193
+ leading: {
194
+ type: 'object',
195
+ additionalProperties: false,
196
+ required: ['display', 'heading', 'body'],
197
+ properties: { display: { type: 'number' }, heading: { type: 'number' }, body: { type: 'number' } },
198
+ },
199
+ tracking: {
200
+ type: 'object',
201
+ additionalProperties: false,
202
+ required: ['display', 'caps'],
203
+ properties: { display: { type: 'number' }, caps: { type: 'number' } },
204
+ },
205
+ colors: {
206
+ type: 'object',
207
+ additionalProperties: false,
208
+ required: ['ink', 'paper', 'accent', 'muted', 'second'],
209
+ properties: {
210
+ ink: { type: 'string' },
211
+ paper: { type: 'string' },
212
+ accent: { type: 'string' },
213
+ muted: { type: 'string' },
214
+ second: { type: 'string' },
215
+ },
216
+ },
217
+ },
218
+ };
219
+ /** What a writer is told: the faces it may use, and the rules a pairing keeps. */
220
+ export const BRIEF = `You design type systems. Answer with one JSON object.
221
+ Faces: choose display, text and mono ONLY from this list (each is SIL OFL 1.1): ${FAMILIES.join(', ')}.
222
+ Pair with contrast: a characterful display face with a quiet text face, or one family used at two weights. Mono is for code, data and labels.
223
+ scale.base is the body size in px (14 to 20); scale.ratio is one of 1.125, 1.2, 1.25, 1.333, 1.414, 1.5, 1.618 (larger for posters and display-led brands, smaller for dense documents).
224
+ Weights are CSS weights 100 to 900 the faces carry. Leading is unitless line-height: display 0.9 to 1.1, heading 1.05 to 1.25, body 1.4 to 1.7. Tracking is em: display -0.05 to 0, caps 0.05 to 0.2.
225
+ Colours are #rrggbb: ink on paper must read at WCAG AA (contrast 4.5:1 or better); accent is the one decisive colour; muted is for secondary text and must read on paper at 3:1 or better; second is a supporting accent.
226
+ name is two words at most; blurb is one sentence on the feeling.`;
227
+ /** WCAG relative luminance contrast of two #rrggbb colours. */
228
+ export function contrast(a, b) {
229
+ const lum = (hex) => {
230
+ const c = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((v) => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4));
231
+ return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
232
+ };
233
+ const [x, y] = [lum(a), lum(b)].sort((p, q) => q - p);
234
+ return (x + 0.05) / (y + 0.05);
235
+ }
236
+ /** CSS custom properties: the one export every web surface reads. */
237
+ export function css(t) {
238
+ const lines = [
239
+ `/* ${t.name}: ${t.blurb} */`,
240
+ ':root {',
241
+ ` --font-display: ${stack(t.display)};`,
242
+ ` --font-text: ${stack(t.text)};`,
243
+ ` --font-mono: ${stack(t.mono)};`,
244
+ ...STEPS.map(([s]) => ` --text-${s}: ${size(t, s)}px;`),
245
+ ` --weight-display: ${t.weights.display};`,
246
+ ` --weight-heading: ${t.weights.heading};`,
247
+ ` --weight-body: ${t.weights.body};`,
248
+ ` --weight-strong: ${t.weights.strong};`,
249
+ ` --leading-display: ${t.leading.display};`,
250
+ ` --leading-heading: ${t.leading.heading};`,
251
+ ` --leading-body: ${t.leading.body};`,
252
+ ` --tracking-display: ${t.tracking.display}em;`,
253
+ ` --tracking-caps: ${t.tracking.caps}em;`,
254
+ ...Object.entries(t.colors).map(([k, v]) => ` --color-${k}: ${v};`),
255
+ '}',
256
+ ];
257
+ return lines.join('\n') + '\n';
258
+ }
259
+ /** Design tokens in the W3C Design Tokens format ($value / $type). */
260
+ export function tokens(t) {
261
+ const doc = {
262
+ $description: `${t.name}: ${t.blurb}`,
263
+ font: {
264
+ display: { $type: 'fontFamily', $value: [t.display, font(t.display).role === 'serif' ? 'serif' : 'sans-serif'] },
265
+ text: { $type: 'fontFamily', $value: [t.text, font(t.text).role === 'serif' ? 'serif' : 'sans-serif'] },
266
+ mono: { $type: 'fontFamily', $value: [t.mono, 'monospace'] },
267
+ },
268
+ size: Object.fromEntries(STEPS.map(([s]) => [s, { $type: 'dimension', $value: `${size(t, s)}px` }])),
269
+ weight: Object.fromEntries(Object.entries(t.weights).map(([k, v]) => [k, { $type: 'fontWeight', $value: v }])),
270
+ leading: Object.fromEntries(Object.entries(t.leading).map(([k, v]) => [k, { $type: 'number', $value: v }])),
271
+ tracking: Object.fromEntries(Object.entries(t.tracking).map(([k, v]) => [k, { $type: 'dimension', $value: `${v}em` }])),
272
+ color: Object.fromEntries(Object.entries(t.colors).map(([k, v]) => [k, { $type: 'color', $value: v }])),
273
+ };
274
+ return JSON.stringify(doc, null, 2) + '\n';
275
+ }
276
+ /** A @hanzo/gui theme module: the faces as gui fonts, the colours as a theme. */
277
+ export function gui(t) {
278
+ const sizes = Object.fromEntries(STEPS.map(([s], i) => [i + 1, size(t, s)]));
279
+ const lineHeights = Object.fromEntries(STEPS.map(([s], i) => [i + 1, Math.round(size(t, s) * (i >= 6 ? t.leading.display : i >= 3 ? t.leading.heading : t.leading.body))]));
280
+ const fontOf = (family, weight) => `createFont({\n family: ${JSON.stringify(stack(family))},\n size: ${JSON.stringify(sizes)},\n lineHeight: ${JSON.stringify(lineHeights)},\n weight: { 4: '${weight}' },\n letterSpacing: { 4: 0 },\n })`;
281
+ return `// ${t.name}: ${t.blurb}
282
+ // A @hanzo/gui theme: pass \`fonts\` and \`themes\` to createGui alongside your config.
283
+ import { createFont } from '@hanzo/gui'
284
+
285
+ export const fonts = {
286
+ heading: ${fontOf(t.display, t.weights.heading)},
287
+ body: ${fontOf(t.text, t.weights.body)},
288
+ mono: ${fontOf(t.mono, t.weights.body)},
289
+ }
290
+
291
+ export const themes = {
292
+ ${JSON.stringify(t.name.toLowerCase().replace(/[^a-z0-9]+/g, '_'))}: {
293
+ background: '${t.colors.paper}',
294
+ color: '${t.colors.ink}',
295
+ colorMuted: '${t.colors.muted}',
296
+ accent: '${t.colors.accent}',
297
+ accentSecond: '${t.colors.second}',
298
+ borderColor: '${t.colors.muted}',
299
+ },
300
+ }
301
+ `;
302
+ }
@@ -0,0 +1,2 @@
1
+ import { type Kind } from './kind.ts';
2
+ export declare const video: Kind;
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Short video: a clip from words, or from a picture. Two lanes: a gateway video
4
+ * model (the async /v1/videos API, billed to the org) when the catalog serves
5
+ * one, and Wan 2.2 TI2V 5B on the org's GPU while a GPU advertises `video.wan`.
6
+ * Long form (script, storyboard, shots, cut) is Films.
7
+ */
8
+ import { SizableText, YStack } from '@hanzo/gui';
9
+ import { Clapperboard } from '@hanzogui/lucide-icons-2';
10
+ import { render } from '../gpu.js';
11
+ import { current, filename } from '../made.js';
12
+ import { useUrl } from '../use.js';
13
+ import { film, read, stage } from '../wire.js';
14
+ import { lit, maker, num, str } from './kind.js';
15
+ const SIZES = {
16
+ '16:9': { gpu: [832, 480], size: '1280x720' },
17
+ '9:16': { gpu: [480, 832], size: '720x1280' },
18
+ '1:1': { gpu: [640, 640], size: '960x960' },
19
+ };
20
+ /** Frames at the GPU lane's 24 fps for a length in seconds. */
21
+ const frames = (s) => Math.round(s * 24) + 1;
22
+ const lane = (a) => (maker(a, 'video') ? 'gateway' : lit(a.fleet, 'video.wan') ? 'gpu' : null);
23
+ export const video = {
24
+ id: 'video',
25
+ label: 'Video',
26
+ blurb: 'Short clips for ads and social, from words or a picture.',
27
+ icon: Clapperboard,
28
+ tool: {
29
+ name: 'make_video',
30
+ description: 'Make a short video clip (2 to 10 seconds): an ad shot, a social clip, a product in motion. From a description, or starting from a picture in a tab. For a whole film with a script and many shots, say so and the person opens Films.',
31
+ parameters: {
32
+ type: 'object',
33
+ properties: {
34
+ title: { type: 'string', description: 'A short name for the tab.' },
35
+ prompt: { type: 'string', description: 'What happens, the camera move, the light, the style.' },
36
+ aspect: { type: 'string', enum: Object.keys(SIZES) },
37
+ seconds: { type: 'integer', minimum: 2, maximum: 10 },
38
+ image_tab: { type: 'integer', description: 'A tab whose picture the clip starts from.' },
39
+ },
40
+ required: ['title', 'prompt'],
41
+ },
42
+ },
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.'),
44
+ make: async (w, args) => {
45
+ const use = lane(w);
46
+ if (!use)
47
+ throw new Error(video.needs(w));
48
+ const prompt = str(args.prompt);
49
+ const aspect = SIZES[str(args.aspect)] ? str(args.aspect) : '16:9';
50
+ const seconds = num(args.seconds, 5, 2, 10);
51
+ const tab = num(args.image_tab, 0) ? w.find(num(args.image_tab, 0)) : null;
52
+ const from = tab ? current(tab).files.find((f) => f.mime.startsWith('image/')) : undefined;
53
+ let blob;
54
+ let by;
55
+ 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;
59
+ }
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)';
66
+ }
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 } };
69
+ },
70
+ revise: async (w, made, change) => {
71
+ const now = current(made).spec;
72
+ const { draft } = await video.make(w, { title: made.title, ...now, ...(change.patch ?? {}), prompt: change.instruction ? `${now.prompt}. ${change.instruction}` : now.prompt });
73
+ return draft;
74
+ },
75
+ View: Clip,
76
+ exports: [{ label: 'MP4', run: async (w, m, v) => ({ name: filename(m.title, 'mp4'), blob: await read(w, v.files[0].key) }) }],
77
+ };
78
+ function Clip({ version, wire, made }) {
79
+ const { src, error } = useUrl(wire, version.files[0]?.key);
80
+ return (_jsx(YStack, { flex: 1, minH: 0, items: "center", justify: "center", p: "$3", children: error ? _jsx(SizableText, { color: "$soft", children: error }) : src ? _jsx("video", { controls: true, loop: true, playsInline: true, src: src, "aria-label": made.title, style: { maxWidth: '100%', maxHeight: '100%', borderRadius: 12 } }) : null }));
81
+ }
package/lib/live.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * What Studio reads while it is open: the call target from the host, what can
3
+ * run (the org's GPUs and the gateway's makers), and the list of conversations.
4
+ * One reader each, shared by every pane, so the home, the composer and the
5
+ * tools agree about what is on offer.
6
+ */
7
+ import type { Host } from '@hanzo/build';
8
+ import { type Listed } from './chat/store.ts';
9
+ import type { Available } from './kinds/kind.ts';
10
+ import { type Fleet, type Wire } from './wire.ts';
11
+ /**
12
+ * Where the engine is from this page: this origin on studio.hanzo.ai, a dev
13
+ * server's /engine proxy on a laptop, studio.hanzo.ai from anywhere else.
14
+ */
15
+ export declare function engineFrom(hostname: string): string;
16
+ /**
17
+ * The models Studio's own words come from. The chat that decides what to make
18
+ * calls tools; the writer answers JSON a kind asks for (a type system, a deck).
19
+ * Measured 2026-10-16 on api.hanzo.ai: zen5 calls tools in ~3 s and zen5-flash
20
+ * answers a strict schema in ~2 s, where zen5 spent 30 s reasoning over the same
21
+ * schema and zen5-flash answered tools in prose.
22
+ */
23
+ export declare const BRAIN = "zen5";
24
+ export declare const WRITER = "zen5-flash";
25
+ export declare function useWire(host: Host): Wire;
26
+ /** The org's GPUs and the gateway's makers, read every 15 s while a Studio pane is drawn. */
27
+ export declare function useAvailable(w: Wire): Available & {
28
+ error: string;
29
+ };
30
+ export declare function reloadChats(w: Wire): Promise<void>;
31
+ /** A conversation's row changed here: shown at once, before the index is read again. */
32
+ export declare function touch(row: Listed): void;
33
+ export declare function useChats(w: Wire): {
34
+ rows: Listed[];
35
+ error: string;
36
+ };
37
+ /** The words that say where work is kept, while the Library does not answer. */
38
+ export declare const KEPT = "Kept in this browser \u00B7 Saving to Library when it\u2019s available";
39
+ /**
40
+ * Whether the person's Library answers: asked once, and on the first yes
41
+ * whatever was kept only in this browser is carried up to it.
42
+ */
43
+ export declare function useLibrary(w: Wire): boolean | null;
44
+ export type { Fleet };
package/lib/live.js ADDED
@@ -0,0 +1,128 @@
1
+ import { useEffect, useMemo, useState, useSyncExternalStore } from 'react';
2
+ import { index } from './chat/store.js';
3
+ import { ENGINE, gpus, libraryLive, makers, sync } from './wire.js';
4
+ /**
5
+ * Where the engine is from this page: this origin on studio.hanzo.ai, a dev
6
+ * server's /engine proxy on a laptop, studio.hanzo.ai from anywhere else.
7
+ */
8
+ export function engineFrom(hostname) {
9
+ if (hostname === 'studio.hanzo.ai')
10
+ return '';
11
+ if (hostname === 'localhost' || hostname === '127.0.0.1')
12
+ return '/engine';
13
+ return ENGINE;
14
+ }
15
+ /**
16
+ * The models Studio's own words come from. The chat that decides what to make
17
+ * calls tools; the writer answers JSON a kind asks for (a type system, a deck).
18
+ * Measured 2026-10-16 on api.hanzo.ai: zen5 calls tools in ~3 s and zen5-flash
19
+ * answers a strict schema in ~2 s, where zen5 spent 30 s reasoning over the same
20
+ * schema and zen5-flash answered tools in prose.
21
+ */
22
+ export const BRAIN = 'zen5';
23
+ export const WRITER = 'zen5-flash';
24
+ export function useWire(host) {
25
+ const engine = typeof window === 'undefined' ? ENGINE : engineFrom(window.location.hostname);
26
+ return useMemo(() => ({ api: host.api, engine, token: host.token, org: host.org }), [host.api, host.token, host.org, engine]);
27
+ }
28
+ /* One shared read of what can run, refreshed while anyone is looking. */
29
+ let state = { fleet: null, models: [], error: '' };
30
+ const listeners = new Set();
31
+ let users = 0;
32
+ let timer;
33
+ let target = null;
34
+ const tell = () => listeners.forEach((l) => l());
35
+ async function poll() {
36
+ const w = target;
37
+ if (!w || !w.token())
38
+ return;
39
+ const [fleet, models] = await Promise.allSettled([gpus(w), makers(w)]);
40
+ state = {
41
+ fleet: fleet.status === 'fulfilled' ? fleet.value : state.fleet,
42
+ models: models.status === 'fulfilled' ? models.value : state.models,
43
+ error: fleet.status === 'rejected' ? (fleet.reason instanceof Error ? fleet.reason.message : String(fleet.reason)) : '',
44
+ };
45
+ tell();
46
+ }
47
+ /** The org's GPUs and the gateway's makers, read every 15 s while a Studio pane is drawn. */
48
+ export function useAvailable(w) {
49
+ useEffect(() => {
50
+ target = w;
51
+ users++;
52
+ void poll();
53
+ if (users === 1)
54
+ timer = setInterval(() => void poll(), 15_000);
55
+ return () => {
56
+ users--;
57
+ if (!users && timer)
58
+ clearInterval(timer);
59
+ };
60
+ }, [w]);
61
+ return useSyncExternalStore((l) => {
62
+ listeners.add(l);
63
+ return () => listeners.delete(l);
64
+ }, () => state, () => state);
65
+ }
66
+ /* The conversation list, shared the same way. */
67
+ let rows = [];
68
+ let rowsError = '';
69
+ const rowListeners = new Set();
70
+ let reading = null;
71
+ export function reloadChats(w) {
72
+ reading ??= index(w)
73
+ .then((r) => {
74
+ rows = r;
75
+ rowsError = '';
76
+ }, (e) => {
77
+ rowsError = e instanceof Error ? e.message : String(e);
78
+ })
79
+ .finally(() => {
80
+ reading = null;
81
+ rowListeners.forEach((l) => l());
82
+ });
83
+ return reading;
84
+ }
85
+ /** A conversation's row changed here: shown at once, before the index is read again. */
86
+ export function touch(row) {
87
+ rows = [row, ...rows.filter((r) => r.id !== row.id)];
88
+ rowListeners.forEach((l) => l());
89
+ }
90
+ export function useChats(w) {
91
+ const [, bump] = useState(0);
92
+ useEffect(() => {
93
+ const l = () => bump((n) => n + 1);
94
+ rowListeners.add(l);
95
+ if (w.token())
96
+ void reloadChats(w);
97
+ return () => {
98
+ rowListeners.delete(l);
99
+ };
100
+ }, [w]);
101
+ return { rows, error: rowsError };
102
+ }
103
+ /** The words that say where work is kept, while the Library does not answer. */
104
+ export const KEPT = 'Kept in this browser · Saving to Library when it’s available';
105
+ let shelf = null;
106
+ const shelfListeners = new Set();
107
+ /**
108
+ * Whether the person's Library answers: asked once, and on the first yes
109
+ * whatever was kept only in this browser is carried up to it.
110
+ */
111
+ export function useLibrary(w) {
112
+ const [, bump] = useState(0);
113
+ useEffect(() => {
114
+ const l = () => bump((n) => n + 1);
115
+ shelfListeners.add(l);
116
+ if (shelf === null && w.token())
117
+ void libraryLive(w).then((live) => {
118
+ shelf = live;
119
+ shelfListeners.forEach((f) => f());
120
+ if (live)
121
+ void sync(w).catch(() => undefined);
122
+ });
123
+ return () => {
124
+ shelfListeners.delete(l);
125
+ };
126
+ }, [w]);
127
+ return shelf;
128
+ }
package/lib/made.d.ts ADDED
@@ -0,0 +1,75 @@
1
+ export type KindId = 'image' | 'poster' | 'document' | 'slides' | 'type' | 'mesh' | 'video' | 'voice' | 'music' | 'ad';
2
+ export declare const KINDS: readonly KindId[];
3
+ export interface Stored {
4
+ /** The full key in the bucket. */
5
+ key: string;
6
+ mime: string;
7
+ name: string;
8
+ width?: number;
9
+ height?: number;
10
+ }
11
+ export interface Version {
12
+ id: string;
13
+ /** Unix milliseconds. */
14
+ at: number;
15
+ /** The kind's own fields this version was made from. */
16
+ spec: Record<string, unknown>;
17
+ files: Stored[];
18
+ /** What made it, in a line: the ask, or the edit. */
19
+ note: string;
20
+ /** The model or lane that made it, as it named itself. */
21
+ by?: string;
22
+ }
23
+ export interface Made {
24
+ id: string;
25
+ kind: KindId;
26
+ title: string;
27
+ versions: Version[];
28
+ /** The version shown: an index into `versions`. */
29
+ at: number;
30
+ }
31
+ export interface Turn {
32
+ id: string;
33
+ role: 'user' | 'assistant';
34
+ text: string;
35
+ at: number;
36
+ /** Things this turn made or changed, by id. */
37
+ made?: string[];
38
+ /** What it is doing now, while it works. */
39
+ doing?: string;
40
+ /** Why it stopped, when it failed. */
41
+ failed?: string;
42
+ /** The model that answered. */
43
+ by?: string;
44
+ /** Pictures the person attached: stored files. */
45
+ attached?: Stored[];
46
+ }
47
+ export interface Chat {
48
+ id: string;
49
+ title: string;
50
+ created: number;
51
+ updated: number;
52
+ turns: Turn[];
53
+ made: Made[];
54
+ /** The type system every kind is drawn in: a `type` made's file key, or none. */
55
+ brand?: string;
56
+ }
57
+ export declare const blank: (id?: string) => Chat;
58
+ /** The version a made thing shows. */
59
+ export declare const current: (m: Made) => Version;
60
+ /** Where a version's files live. */
61
+ export declare const dir: (chat: string, m: Pick<Made, 'id' | 'kind'>, version: string) => string;
62
+ /** A file name a person reads: the title, slugged, and the extension. */
63
+ export declare function filename(title: string, ext: string): string;
64
+ /** A library entry, read from a key under files/. */
65
+ export interface Shelved {
66
+ kind: KindId;
67
+ chat: string;
68
+ made: string;
69
+ version: string;
70
+ name: string;
71
+ key: string;
72
+ modified: number;
73
+ size: number;
74
+ }
75
+ export declare function shelved(key: string, modified: number, size: number): Shelved | null;
package/lib/made.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * What a conversation is, and what it makes, as kept.
3
+ *
4
+ * A conversation is one JSON document at `chats/<id>.json`, kept for this
5
+ * person alone (wire.ts): its turns, and every thing it made. A thing made has
6
+ * versions; a version is the spec it was made from (the kind's own fields, so
7
+ * an edit is a new spec) and the files it produced, each kept at
8
+ *
9
+ * files/<kind>/<chat>/<made>/<version>/<name>
10
+ *
11
+ * so the library is one listing of `files/`, sorted by kind, and a file names
12
+ * the conversation that made it.
13
+ */
14
+ import { fresh } from './route.js';
15
+ export const KINDS = ['image', 'poster', 'document', 'slides', 'type', 'mesh', 'video', 'voice', 'music', 'ad'];
16
+ export const blank = (id = fresh()) => ({ id, title: 'New creation', created: Date.now(), updated: Date.now(), turns: [], made: [] });
17
+ /** The version a made thing shows. */
18
+ export const current = (m) => m.versions[Math.min(Math.max(0, m.at), m.versions.length - 1)];
19
+ /** Where a version's files live. */
20
+ export const dir = (chat, m, version) => `files/${m.kind}/${chat}/${m.id}/${version}`;
21
+ /** A file name a person reads: the title, slugged, and the extension. */
22
+ export function filename(title, ext) {
23
+ const base = title
24
+ .toLowerCase()
25
+ .replace(/[^a-z0-9]+/g, '-')
26
+ .replace(/^-+|-+$/g, '')
27
+ .slice(0, 60);
28
+ return `${base || 'untitled'}.${ext}`;
29
+ }
30
+ export function shelved(key, modified, size) {
31
+ const [kind, chat, made, version, ...rest] = key.split('/');
32
+ const name = rest.join('/');
33
+ if (!kind || !chat || !made || !version || !name || !KINDS.includes(kind))
34
+ return null;
35
+ return { kind: kind, chat, made, version, name, key: `files/${key}`, modified, size };
36
+ }