@hanzo/studio 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/app/director.d.ts +2 -1
- package/lib/app/director.js +51 -47
- package/lib/app/flow-kept.d.ts +22 -0
- package/lib/app/flow-kept.js +32 -0
- package/lib/app/flow.d.ts +6 -9
- package/lib/app/flow.js +50 -138
- package/lib/app/sections.d.ts +1 -3
- package/lib/app/sections.js +1 -8
- package/lib/attach.d.ts +5 -2
- package/lib/attach.js +8 -4
- package/lib/chat/turn.d.ts +3 -0
- package/lib/chat/turn.js +18 -7
- package/lib/desk.js +3 -53
- package/lib/home.d.ts +13 -0
- package/lib/home.js +7 -4
- package/lib/host.d.ts +18 -2
- package/lib/host.js +26 -3
- package/lib/index.d.ts +4 -2
- package/lib/index.js +2 -2
- package/lib/kinds/ad.js +4 -0
- package/lib/kinds/document.d.ts +16 -1
- package/lib/kinds/document.js +20 -7
- package/lib/kinds/image.js +19 -81
- package/lib/kinds/kind.d.ts +5 -2
- package/lib/kinds/mesh/index.js +11 -4
- package/lib/kinds/poster/index.js +6 -0
- package/lib/kinds/sound.d.ts +2 -0
- package/lib/kinds/sound.js +17 -1
- package/lib/kinds/video.d.ts +2 -0
- package/lib/kinds/video.js +26 -136
- package/lib/live.d.ts +3 -2
- package/lib/live.js +10 -3
- package/lib/nav.js +1 -2
- package/lib/places.d.ts +0 -1
- package/lib/places.js +10 -78
- package/lib/route.d.ts +5 -5
- package/lib/route.js +5 -5
- package/lib/spend.d.ts +44 -0
- package/lib/spend.js +68 -0
- package/lib/studio.d.ts +2 -18
- package/lib/studio.js +16 -3
- package/lib/talk.js +20 -9
- package/lib/wire.d.ts +6 -22
- package/lib/wire.js +11 -27
- package/package.json +1 -1
package/lib/kinds/image.js
CHANGED
|
@@ -14,9 +14,9 @@ import { Image as Picture } from '@hanzogui/lucide-icons-2';
|
|
|
14
14
|
import { useState } from 'react';
|
|
15
15
|
import { render } from '../gpu.js';
|
|
16
16
|
import { current, filename } from '../made.js';
|
|
17
|
-
import { pixels } from '../raster.js';
|
|
18
17
|
import { useUrl } from '../use.js';
|
|
19
18
|
import { draw, read, Refusal, stage } from '../wire.js';
|
|
19
|
+
import { spend } from '../spend.js';
|
|
20
20
|
import { lit, num, str } from './kind.js';
|
|
21
21
|
/** The gateway's image models, best first. */
|
|
22
22
|
export const MODELS = [
|
|
@@ -71,58 +71,16 @@ async function size(blob) {
|
|
|
71
71
|
}
|
|
72
72
|
/** What a person reads when the gateway draws no picture: never a model, a provider or the plumbing between. */
|
|
73
73
|
export const UNDRAWN = "Couldn't draw the picture this time.";
|
|
74
|
-
/** Procedural studio canvas/SVG artwork fallback when all remote image models are unreachable or out of credits. */
|
|
75
|
-
async function proceduralPicture(prompt, aspect, idx) {
|
|
76
|
-
const [width, height] = PIXELS[aspect] ?? PIXELS['1:1'];
|
|
77
|
-
let hash = 2166136261 + idx * 997;
|
|
78
|
-
for (let i = 0; i < prompt.length; i++)
|
|
79
|
-
hash = Math.imul(hash ^ prompt.charCodeAt(i), 16777619);
|
|
80
|
-
const palettes = [
|
|
81
|
-
['#090a10', '#f43f5e', '#6366f1', '#f8fafc'],
|
|
82
|
-
['#071318', '#06b6d4', '#10b981', '#ecfeff'],
|
|
83
|
-
['#140b1c', '#ec4899', '#f59e0b', '#fdf2f8'],
|
|
84
|
-
['#0f172a', '#3b82f6', '#8b5cf6', '#f1f5f9'],
|
|
85
|
-
['#18181b', '#e11d48', '#fb923c', '#fafafa'],
|
|
86
|
-
];
|
|
87
|
-
const [bg, c1, c2, ink] = palettes[Math.abs(hash) % palettes.length];
|
|
88
|
-
const cx1 = Math.round(width * (0.28 + ((Math.abs(hash >> 3) % 44) / 100)));
|
|
89
|
-
const cy1 = Math.round(height * (0.3 + ((Math.abs(hash >> 7) % 40) / 100)));
|
|
90
|
-
const cx2 = Math.round(width * (0.68 - ((Math.abs(hash >> 11) % 36) / 100)));
|
|
91
|
-
const cy2 = Math.round(height * (0.66 - ((Math.abs(hash >> 15) % 36) / 100)));
|
|
92
|
-
const r1 = Math.round(Math.min(width, height) * 0.45);
|
|
93
|
-
const r2 = Math.round(Math.min(width, height) * 0.38);
|
|
94
|
-
const rings = Array.from({ length: 7 }, (_, k) => {
|
|
95
|
-
const rad = Math.round(Math.min(width, height) * (0.12 + k * 0.065));
|
|
96
|
-
return `<circle cx="${Math.round(width / 2)}" cy="${Math.round(height / 2)}" r="${rad}" fill="none" stroke="${ink}" stroke-opacity="${(0.16 - k * 0.018).toFixed(3)}" stroke-width="1.5"/>`;
|
|
97
|
-
}).join('');
|
|
98
|
-
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">
|
|
99
|
-
<defs>
|
|
100
|
-
<radialGradient id="g1" cx="${cx1}" cy="${cy1}" r="${r1}" gradientUnits="userSpaceOnUse">
|
|
101
|
-
<stop offset="0%" stop-color="${c1}" stop-opacity="0.88"/>
|
|
102
|
-
<stop offset="100%" stop-color="${bg}" stop-opacity="0"/>
|
|
103
|
-
</radialGradient>
|
|
104
|
-
<radialGradient id="g2" cx="${cx2}" cy="${cy2}" r="${r2}" gradientUnits="userSpaceOnUse">
|
|
105
|
-
<stop offset="0%" stop-color="${c2}" stop-opacity="0.82"/>
|
|
106
|
-
<stop offset="100%" stop-color="${bg}" stop-opacity="0"/>
|
|
107
|
-
</radialGradient>
|
|
108
|
-
<linearGradient id="diag" x1="0" y1="0" x2="1" y2="1">
|
|
109
|
-
<stop offset="0%" stop-color="${c1}" stop-opacity="0.22"/>
|
|
110
|
-
<stop offset="100%" stop-color="${c2}" stop-opacity="0.22"/>
|
|
111
|
-
</linearGradient>
|
|
112
|
-
</defs>
|
|
113
|
-
<rect width="${width}" height="${height}" fill="${bg}"/>
|
|
114
|
-
<rect width="${width}" height="${height}" fill="url(#diag)"/>
|
|
115
|
-
<circle cx="${cx1}" cy="${cy1}" r="${r1}" fill="url(#g1)"/>
|
|
116
|
-
<circle cx="${cx2}" cy="${cy2}" r="${r2}" fill="url(#g2)"/>
|
|
117
|
-
${rings}
|
|
118
|
-
<path d="M 0 ${Math.round(height * 0.68)} Q ${Math.round(width * 0.35)} ${Math.round(height * 0.48)}, ${Math.round(width * 0.65)} ${Math.round(height * 0.72)} T ${width} ${Math.round(height * 0.58)}" fill="none" stroke="${c1}" stroke-width="3" stroke-opacity="0.55"/>
|
|
119
|
-
<path d="M 0 ${Math.round(height * 0.74)} Q ${Math.round(width * 0.4)} ${Math.round(height * 0.54)}, ${Math.round(width * 0.7)} ${Math.round(height * 0.78)} T ${width} ${Math.round(height * 0.64)}" fill="none" stroke="${c2}" stroke-width="2" stroke-opacity="0.45"/>
|
|
120
|
-
</svg>`;
|
|
121
|
-
return pixels(svg, width, height, 'image/png');
|
|
122
|
-
}
|
|
123
74
|
/** Make pictures from words (and, for an edit, the pictures they start from), and keep them. */
|
|
124
75
|
export async function picture(w, o) {
|
|
125
76
|
const use = o.from?.length ? editing(o.model, w.fleet) : lane(o.model, w.fleet);
|
|
77
|
+
// One ask before anything is drawn, saying how many pictures it makes: a GPU edit makes one per picture it starts from.
|
|
78
|
+
const n = use === ZEN && o.from?.length ? o.from.length : (o.count ?? 1);
|
|
79
|
+
const edit = Boolean(o.from?.length);
|
|
80
|
+
await spend(w, use === ZEN ? 'design-gpu' : 'design-image', {
|
|
81
|
+
title: n === 1 ? (edit ? 'Edit this picture?' : 'Make this picture?') : `Make ${n} pictures?`,
|
|
82
|
+
what: n === 1 ? (edit ? 'This makes one edited picture.' : 'This makes one picture.') : `This makes ${n} pictures.`,
|
|
83
|
+
});
|
|
126
84
|
const files = [];
|
|
127
85
|
if (use === ZEN && o.from?.length) {
|
|
128
86
|
for (const f of o.from) {
|
|
@@ -145,44 +103,24 @@ export async function picture(w, o) {
|
|
|
145
103
|
}
|
|
146
104
|
const from = await Promise.all((o.from ?? []).map((f) => w.picture(f)));
|
|
147
105
|
const ask = from.length ? o.prompt : `${o.prompt}\n\nAspect ratio ${o.aspect}.`;
|
|
148
|
-
const candidates = [use, ...MODELS.map((m) => m.id).filter((id) => id !== use)];
|
|
149
|
-
let usedModel = use;
|
|
150
106
|
for (let i = 0; i < (o.count ?? 1); i++) {
|
|
151
107
|
w.doing(from.length ? 'Editing the picture' : `Drawing${(o.count ?? 1) > 1 ? ` ${i + 1} of ${o.count}` : ''}`);
|
|
152
|
-
let got
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
got = await draw(w.wire, candidate, ask, { from, aspect: o.aspect, signal: w.signal });
|
|
157
|
-
usedModel = candidate;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
lastErr = e;
|
|
162
|
-
if (w.signal.aborted)
|
|
163
|
-
throw e;
|
|
164
|
-
}
|
|
108
|
+
let got;
|
|
109
|
+
try {
|
|
110
|
+
// Only the model the person chose (or Auto's one): trying the others behind their back spends on models they never picked.
|
|
111
|
+
got = await draw(w.wire, use, ask, { from, aspect: o.aspect, signal: w.signal });
|
|
165
112
|
}
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
throw
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
const fallbackBlob = await proceduralPicture(o.prompt, o.aspect, i);
|
|
175
|
-
got = [{ blob: fallbackBlob, mime: 'image/png' }];
|
|
176
|
-
usedModel = 'Studio Vector Synth';
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
throw new Error(UNDRAWN, { cause: lastErr });
|
|
180
|
-
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
if (w.signal.aborted || (e instanceof Refusal && e.status === 402))
|
|
115
|
+
throw e;
|
|
116
|
+
// Nothing stands in for the picture: the failure is said, and nothing is kept.
|
|
117
|
+
w.missed(UNDRAWN);
|
|
118
|
+
throw new Error(UNDRAWN, { cause: e });
|
|
181
119
|
}
|
|
182
120
|
for (const g of got)
|
|
183
121
|
files.push(await w.keep(`image-${files.length + 1}.${ext(g.mime)}`, g.blob, await size(g.blob)));
|
|
184
122
|
}
|
|
185
|
-
return { files, by: MODELS.find((m) => m.id ===
|
|
123
|
+
return { files, by: MODELS.find((m) => m.id === use)?.label ?? use };
|
|
186
124
|
}
|
|
187
125
|
export const image = {
|
|
188
126
|
id: 'image',
|
package/lib/kinds/kind.d.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* through the one client module (wire.ts).
|
|
19
19
|
*/
|
|
20
20
|
import type { ComponentType } from 'react';
|
|
21
|
+
import type { Spend } from '../spend.ts';
|
|
21
22
|
import type { KindId, Made, Stored, Version } from '../made.ts';
|
|
22
23
|
import type { TypeSystem } from './type/system.ts';
|
|
23
24
|
import type { Fleet, Wire } from '../wire.ts';
|
|
@@ -28,8 +29,10 @@ export interface Work {
|
|
|
28
29
|
signal: AbortSignal;
|
|
29
30
|
/** Say what is happening now: drawn under the turn while it works. */
|
|
30
31
|
doing: (line: string) => void;
|
|
31
|
-
/**
|
|
32
|
-
missed: () => void;
|
|
32
|
+
/** What was asked for was not made: the turn ends on this one sentence, offering to try again. */
|
|
33
|
+
missed: (said: string) => void;
|
|
34
|
+
/** Ask before anything paid starts (spend.ts): the host's one confirm, or Studio's own. */
|
|
35
|
+
spend: Spend;
|
|
33
36
|
/** Keep bytes as one of this version's files. */
|
|
34
37
|
keep: (name: string, blob: Blob, extra?: {
|
|
35
38
|
width?: number;
|
package/lib/kinds/mesh/index.js
CHANGED
|
@@ -12,7 +12,8 @@ import { lazy, Suspense } from 'react';
|
|
|
12
12
|
import { render } from '../../gpu.js';
|
|
13
13
|
import { current, filename } from '../../made.js';
|
|
14
14
|
import { read, stage } from '../../wire.js';
|
|
15
|
-
import { picture } from '../image.js';
|
|
15
|
+
import { lane, picture, ZEN } from '../image.js';
|
|
16
|
+
import { spend } from '../../spend.js';
|
|
16
17
|
import { lit, num, str } from '../kind.js';
|
|
17
18
|
const Viewer = lazy(() => import('./viewer.js'));
|
|
18
19
|
export const mesh = {
|
|
@@ -41,10 +42,16 @@ export const mesh = {
|
|
|
41
42
|
const tab = num(args.image_tab, 0) ? w.find(num(args.image_tab, 0)) : null;
|
|
42
43
|
let from = tab ? current(tab).files.find((f) => f.mime.startsWith('image/')) : undefined;
|
|
43
44
|
const prompt = str(args.prompt);
|
|
45
|
+
if (!from && !prompt)
|
|
46
|
+
throw new Error('Say what to model, or name a tab with a picture.');
|
|
47
|
+
// A picture drawn on the GPU is part of the 3D model asked for here; one the gateway draws is asked on its own.
|
|
48
|
+
const drawnHere = !from && lane('', w.fleet) === ZEN;
|
|
49
|
+
await spend(w, 'design-gpu', {
|
|
50
|
+
title: 'Make this 3D model?',
|
|
51
|
+
what: `This makes one 3D model${drawnHere ? ' (and the picture it is modelled from)' : ''} on your organization's GPU, where it keeps going if you leave this page.`,
|
|
52
|
+
});
|
|
44
53
|
if (!from) {
|
|
45
|
-
|
|
46
|
-
throw new Error('Say what to model, or name a tab with a picture.');
|
|
47
|
-
const got = await picture(w, { prompt: `${prompt}, a single object centred on a plain light background, three-quarter view, soft even light`, aspect: '1:1', model: '' });
|
|
54
|
+
const got = await picture(drawnHere ? { ...w, spend: async () => true } : w, { prompt: `${prompt}, a single object centred on a plain light background, three-quarter view, soft even light`, aspect: '1:1', model: '' });
|
|
48
55
|
from = got.files[0];
|
|
49
56
|
}
|
|
50
57
|
if (!from)
|
|
@@ -19,6 +19,7 @@ import { read, structured, url } from '../../wire.js';
|
|
|
19
19
|
import { picture } from '../image.js';
|
|
20
20
|
import { num, str } from '../kind.js';
|
|
21
21
|
import { PRESETS, settle } from '../type/system.js';
|
|
22
|
+
import { Declined } from '../../spend.js';
|
|
22
23
|
import { aspect, compose, format, FORMATS, LAYOUT_NAMES, LAYOUTS } from './compose.js';
|
|
23
24
|
const spec = (v) => {
|
|
24
25
|
const s = v;
|
|
@@ -62,6 +63,9 @@ async function art(w, s, from) {
|
|
|
62
63
|
return { key: got.files[0]?.key ?? '', why: '' };
|
|
63
64
|
}
|
|
64
65
|
catch (e) {
|
|
66
|
+
// A no to the spend ends the turn: nothing is made in its place.
|
|
67
|
+
if (e instanceof Declined)
|
|
68
|
+
throw e;
|
|
65
69
|
return { key: '', why: e instanceof Error ? e.message : String(e) };
|
|
66
70
|
}
|
|
67
71
|
}
|
|
@@ -144,6 +148,8 @@ export const poster = {
|
|
|
144
148
|
next.picture = got.files[0]?.key ?? now.picture;
|
|
145
149
|
}
|
|
146
150
|
catch (e) {
|
|
151
|
+
if (e instanceof Declined)
|
|
152
|
+
throw e;
|
|
147
153
|
why = e instanceof Error ? e.message : String(e);
|
|
148
154
|
}
|
|
149
155
|
}
|
package/lib/kinds/sound.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ import { type Kind } from './kind.ts';
|
|
|
3
3
|
export declare const VOICE = "zen-voice-mini";
|
|
4
4
|
export declare const VOICES: readonly ['alloy', 'ash', 'coral', 'echo', 'fable', 'nova', 'onyx', 'sage', 'shimmer'];
|
|
5
5
|
export declare const voice: Kind;
|
|
6
|
+
/** What a person reads when no music was made: one sentence, and nothing is kept in its place. */
|
|
7
|
+
export declare const UNPLAYED = "Couldn't make the music this time.";
|
|
6
8
|
export declare const music: Kind;
|
package/lib/kinds/sound.js
CHANGED
|
@@ -10,6 +10,7 @@ import { render } from '../gpu.js';
|
|
|
10
10
|
import { current, filename } from '../made.js';
|
|
11
11
|
import { useUrl } from '../use.js';
|
|
12
12
|
import { read, speak } from '../wire.js';
|
|
13
|
+
import { spend } from '../spend.js';
|
|
13
14
|
import { lit, num, str } from './kind.js';
|
|
14
15
|
/** The platform's voice and the voices it reads in. */
|
|
15
16
|
export const VOICE = 'zen-voice-mini';
|
|
@@ -38,6 +39,7 @@ export const voice = {
|
|
|
38
39
|
if (!script)
|
|
39
40
|
throw new Error('Nothing to read.');
|
|
40
41
|
const v = VOICES.includes(str(args.voice)) ? str(args.voice) : 'nova';
|
|
42
|
+
await spend(w, 'voice');
|
|
41
43
|
w.doing('Reading it aloud');
|
|
42
44
|
const file = await w.keep('voice.mp3', await speak(w.wire, script.slice(0, 4000), v, VOICE, w.signal));
|
|
43
45
|
return { title: str(args.title, script.slice(0, 32)), draft: { spec: { script, voice: v }, files: [file], note: script.slice(0, 160), by: VOICE } };
|
|
@@ -47,12 +49,15 @@ export const voice = {
|
|
|
47
49
|
const next = { ...now, ...(change.patch ?? {}) };
|
|
48
50
|
if (change.instruction && !change.patch)
|
|
49
51
|
next.script = change.instruction;
|
|
52
|
+
await spend(w, 'voice');
|
|
50
53
|
const file = await w.keep('voice.mp3', await speak(w.wire, next.script.slice(0, 4000), next.voice, VOICE, w.signal));
|
|
51
54
|
return { spec: next, files: [file], note: change.instruction ?? 'Read again', by: VOICE };
|
|
52
55
|
},
|
|
53
56
|
View: Listen,
|
|
54
57
|
exports: [{ label: 'MP3', run: async (w, m, v) => ({ name: filename(m.title, 'mp3'), blob: await read(w, v.files[0].key) }) }],
|
|
55
58
|
};
|
|
59
|
+
/** What a person reads when no music was made: one sentence, and nothing is kept in its place. */
|
|
60
|
+
export const UNPLAYED = "Couldn't make the music this time.";
|
|
56
61
|
export const music = {
|
|
57
62
|
id: 'music',
|
|
58
63
|
label: 'Music',
|
|
@@ -80,7 +85,18 @@ export const music = {
|
|
|
80
85
|
if (why)
|
|
81
86
|
throw new Error(why);
|
|
82
87
|
const body = { prompt: str(args.prompt), lyrics: str(args.lyrics), seconds: num(args.seconds, 30, 10, 240) };
|
|
83
|
-
|
|
88
|
+
await spend(w, 'design-gpu', { title: 'Make this music?', what: `This makes ${body.seconds} seconds of music on your organization's GPU, where it keeps going if you leave this page.` });
|
|
89
|
+
let got;
|
|
90
|
+
try {
|
|
91
|
+
got = await render(w.wire, 'music', body, w.doing, w.signal);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
if (w.signal.aborted)
|
|
95
|
+
throw e;
|
|
96
|
+
// Nothing stands in for the track: the failure is said, and nothing is kept.
|
|
97
|
+
w.missed(UNPLAYED);
|
|
98
|
+
throw new Error(UNPLAYED, { cause: e });
|
|
99
|
+
}
|
|
84
100
|
const g = got[0];
|
|
85
101
|
const ext = g.path.split('.').pop() || 'mp3';
|
|
86
102
|
const file = await w.keep(`music.${ext}`, g.blob);
|
package/lib/kinds/video.d.ts
CHANGED
package/lib/kinds/video.js
CHANGED
|
@@ -11,6 +11,7 @@ import { render } from '../gpu.js';
|
|
|
11
11
|
import { current, filename } from '../made.js';
|
|
12
12
|
import { useUrl } from '../use.js';
|
|
13
13
|
import { film, read, stage } from '../wire.js';
|
|
14
|
+
import { spend } from '../spend.js';
|
|
14
15
|
import { lit, maker, num, str } from './kind.js';
|
|
15
16
|
const SIZES = {
|
|
16
17
|
'16:9': { gpu: [832, 480], size: '1280x720' },
|
|
@@ -19,117 +20,9 @@ const SIZES = {
|
|
|
19
20
|
};
|
|
20
21
|
/** Frames at the GPU lane's 24 fps for a length in seconds. */
|
|
21
22
|
const frames = (s) => Math.round(s * 24) + 1;
|
|
22
|
-
const lane = (a) => (maker(a, 'video') ? 'gateway' : lit(a.fleet, 'video.wan') ? 'gpu' :
|
|
23
|
-
/**
|
|
24
|
-
|
|
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
|
+
const lane = (a) => (maker(a, 'video') ? 'gateway' : lit(a.fleet, 'video.wan') ? 'gpu' : null);
|
|
24
|
+
/** What a person reads when no clip was made: one sentence, and nothing is kept in its place. */
|
|
25
|
+
export const UNFILMED = "Couldn't make the clip this time.";
|
|
133
26
|
export const video = {
|
|
134
27
|
id: 'video',
|
|
135
28
|
label: 'Video',
|
|
@@ -150,50 +43,47 @@ export const video = {
|
|
|
150
43
|
required: ['title', 'prompt'],
|
|
151
44
|
},
|
|
152
45
|
},
|
|
153
|
-
|
|
46
|
+
// No video model and no GPU that runs Koma: the kind is not offered, and the chat is told why.
|
|
47
|
+
needs: (a) => (lane(a) ? null : 'Video needs a video model or a GPU that runs Koma 2.0, and none is available right now.'),
|
|
154
48
|
make: async (w, args) => {
|
|
49
|
+
const why = video.needs(w);
|
|
50
|
+
if (why)
|
|
51
|
+
throw new Error(why);
|
|
155
52
|
const use = lane(w);
|
|
156
53
|
const prompt = str(args.prompt);
|
|
157
|
-
const title = str(args.title, prompt.slice(0, 32) || '
|
|
54
|
+
const title = str(args.title, prompt.slice(0, 32) || 'Clip');
|
|
158
55
|
const aspect = SIZES[str(args.aspect)] ? str(args.aspect) : '16:9';
|
|
159
56
|
const seconds = num(args.seconds, 5, 2, 10);
|
|
160
57
|
const tab = num(args.image_tab, 0) ? w.find(num(args.image_tab, 0)) : null;
|
|
161
58
|
const from = tab ? current(tab).files.find((f) => f.mime.startsWith('image/')) : undefined;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
59
|
+
await spend(w, use === 'gateway' ? 'design-video' : 'design-gpu', {
|
|
60
|
+
title: 'Make this clip?',
|
|
61
|
+
what: `This makes one ${use === 'gpu' ? Math.min(seconds, 5) : seconds}-second clip, which keeps rendering if you leave this page.`,
|
|
62
|
+
});
|
|
63
|
+
let blob;
|
|
64
|
+
let by;
|
|
65
|
+
try {
|
|
66
|
+
if (use === 'gateway') {
|
|
168
67
|
const m = maker(w, 'video');
|
|
169
68
|
blob = await film(w.wire, m.id, prompt, { size: SIZES[aspect].size, seconds, doing: w.doing, signal: w.signal });
|
|
170
69
|
by = m.name;
|
|
171
70
|
}
|
|
172
|
-
|
|
173
|
-
blob = null;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
else if (use === 'gpu') {
|
|
177
|
-
try {
|
|
71
|
+
else {
|
|
178
72
|
const [width, height] = SIZES[aspect].gpu;
|
|
179
73
|
const upload = from ? await stage(w.wire, await read(w.wire, from.key), 'start.png') : undefined;
|
|
180
74
|
const got = await render(w.wire, 'video', { prompt, width, height, length: frames(Math.min(seconds, 5)), upload }, w.doing, w.signal);
|
|
181
75
|
blob = got[0].blob;
|
|
182
76
|
by = 'Koma 2.0 (your GPU)';
|
|
183
77
|
}
|
|
184
|
-
catch {
|
|
185
|
-
blob = null;
|
|
186
|
-
}
|
|
187
78
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
by = 'Studio Motion Engine';
|
|
79
|
+
catch (e) {
|
|
80
|
+
if (w.signal.aborted)
|
|
81
|
+
throw e;
|
|
82
|
+
// Nothing stands in for the clip: the failure is said, and nothing is kept.
|
|
83
|
+
w.missed(UNFILMED);
|
|
84
|
+
throw new Error(UNFILMED, { cause: e });
|
|
195
85
|
}
|
|
196
|
-
const file = await w.keep(
|
|
86
|
+
const file = await w.keep('clip.mp4', new Blob([blob], { type: blob.type || 'video/mp4' }));
|
|
197
87
|
return { title, draft: { spec: { prompt, aspect, seconds, from: from?.key ?? '' }, files: [file], note: prompt, by } };
|
|
198
88
|
},
|
|
199
89
|
revise: async (w, made, change) => {
|
package/lib/live.d.ts
CHANGED
|
@@ -10,9 +10,10 @@ import type { Available } from './kinds/kind.ts';
|
|
|
10
10
|
import { type Fleet, type Wire } from './wire.ts';
|
|
11
11
|
/**
|
|
12
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
|
|
13
|
+
* server's /engine proxy on a laptop, the Hanzo desktop's hanzo-studio scheme in
|
|
14
|
+
* its window, studio.hanzo.ai from anywhere else.
|
|
14
15
|
*/
|
|
15
|
-
export declare function engineFrom(hostname: string): string;
|
|
16
|
+
export declare function engineFrom(hostname: string, protocol?: string): string;
|
|
16
17
|
/**
|
|
17
18
|
* The models Studio's own words come from. The chat that decides what to make
|
|
18
19
|
* calls tools; the writer answers JSON a kind asks for (a type system, a deck).
|
package/lib/live.js
CHANGED
|
@@ -3,11 +3,18 @@ import { index } from './chat/store.js';
|
|
|
3
3
|
import { ENGINE, gpus, libraryLive, makers, sync } from './wire.js';
|
|
4
4
|
/**
|
|
5
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
|
|
6
|
+
* server's /engine proxy on a laptop, the Hanzo desktop's hanzo-studio scheme in
|
|
7
|
+
* its window, studio.hanzo.ai from anywhere else.
|
|
7
8
|
*/
|
|
8
|
-
export function engineFrom(hostname) {
|
|
9
|
+
export function engineFrom(hostname, protocol = 'https:') {
|
|
9
10
|
if (hostname === 'studio.hanzo.ai')
|
|
10
11
|
return '';
|
|
12
|
+
// The desktop window (tauri://localhost; http://tauri.localhost on Windows): studio.hanzo.ai's CORS admits
|
|
13
|
+
// neither, so the desktop forwards the engine's calls itself through its hanzo-studio scheme.
|
|
14
|
+
if (protocol === 'tauri:')
|
|
15
|
+
return 'hanzo-studio://localhost';
|
|
16
|
+
if (hostname === 'tauri.localhost')
|
|
17
|
+
return `${protocol}//hanzo-studio.localhost`;
|
|
11
18
|
if (hostname === 'localhost' || hostname === '127.0.0.1')
|
|
12
19
|
return '/engine';
|
|
13
20
|
return ENGINE;
|
|
@@ -22,7 +29,7 @@ export function engineFrom(hostname) {
|
|
|
22
29
|
export const BRAIN = 'zen5';
|
|
23
30
|
export const WRITER = 'zen5-flash';
|
|
24
31
|
export function useWire(host) {
|
|
25
|
-
const engine = typeof window === 'undefined' ? ENGINE : engineFrom(window.location.hostname);
|
|
32
|
+
const engine = typeof window === 'undefined' ? ENGINE : engineFrom(window.location.hostname, window.location.protocol);
|
|
26
33
|
return useMemo(() => ({ api: host.api, engine, token: host.token, org: host.org }), [host.api, host.token, host.org, engine]);
|
|
27
34
|
}
|
|
28
35
|
/* One shared read of what can run, refreshed while anyone is looking. */
|
package/lib/nav.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Activity, LayoutTemplate,
|
|
2
|
+
import { Activity, LayoutTemplate, SquarePen } from '@hanzogui/lucide-icons-2';
|
|
3
3
|
import { path, route } from './route.js';
|
|
4
4
|
/** The id of the row that starts a new conversation: a rail with a New control of its own draws that instead. */
|
|
5
5
|
export const NEW = 'new';
|
|
@@ -13,7 +13,6 @@ export function nav(host, go) {
|
|
|
13
13
|
links: [
|
|
14
14
|
{ id: NEW, label: 'New creation', icon: _jsx(SquarePen, { size: 16 }), onPress: to(''), active: r.kind === 'new' },
|
|
15
15
|
{ id: 'explore', label: 'Explore', icon: _jsx(LayoutTemplate, { size: 16 }), onPress: to(path({ kind: 'explore' })), active: r.kind === 'explore' },
|
|
16
|
-
{ id: 'library', label: 'Library', icon: _jsx(Library, { size: 16 }), onPress: to(path({ kind: 'library' })), active: r.kind === 'library' },
|
|
17
16
|
{ id: 'activity', label: 'Activity', icon: _jsx(Activity, { size: 16 }), onPress: to(path({ kind: 'activity' })), active: r.kind === 'activity' },
|
|
18
17
|
],
|
|
19
18
|
},
|
package/lib/places.d.ts
CHANGED