@hanzo/studio 0.1.0 → 0.1.2
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/desk.js +1 -1
- package/lib/gpu.js +1 -1
- package/lib/home.js +1 -1
- package/lib/places.js +1 -1
- package/lib/talk.js +3 -2
- package/lib/wire.d.ts +2 -0
- package/lib/wire.js +24 -1
- package/package.json +1 -1
package/lib/desk.js
CHANGED
|
@@ -48,7 +48,7 @@ export function Desk({ made, wire, others, onPick, onEdit, busy, failed }) {
|
|
|
48
48
|
onSelect: () => onPick(i),
|
|
49
49
|
}));
|
|
50
50
|
const compare = against !== null && against !== made.at && made.versions[against] ? made.versions[against] : null;
|
|
51
|
-
return (_jsxs(YStack, { flex: 1, minH: 0, "data-slot": "studio-tab", children: [_jsxs(XStack, { gap: "$1", px: "$2", py: "$1.5", items: "center", borderBottomWidth: 1, borderColor: "$borderColor", shrink: 0, flexWrap: "wrap", children: [_jsxs(XStack, { items: "center", gap: "$2", flex: 1, minW: 0, px: "$1", children: [_jsx(Icon, { size: 14 }), _jsx(SizableText, { size: "$2", fontWeight: "600", numberOfLines: 1, children: made.title })] }), _jsx(DropdownMenu, { trigger: _jsxs(XStack, { render: "button", "aria-label":
|
|
51
|
+
return (_jsxs(YStack, { flex: 1, minH: 0, "data-slot": "studio-tab", children: [_jsxs(XStack, { gap: "$1", px: "$2", py: "$1.5", items: "center", borderBottomWidth: 1, borderColor: "$borderColor", shrink: 0, flexWrap: "wrap", children: [_jsxs(XStack, { items: "center", gap: "$2", flex: 1, minW: 0, px: "$1", children: [_jsx(Icon, { size: 14 }), _jsx(SizableText, { size: "$2", fontWeight: "600", numberOfLines: 1, children: made.title })] }), _jsx(DropdownMenu, { trigger: _jsxs(XStack, { render: "button", "aria-label": `v${made.at + 1} of ${made.versions.length}, versions`, items: "center", gap: "$1", height: 30, px: "$2.5", rounded: "$3", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [_jsx(SizableText, { size: "$2", children: `v${made.at + 1} of ${made.versions.length}` }), _jsx(ChevronDown, { size: 13 })] }), items: [{ type: 'label', key: 'h', label: 'Versions' }, ...versions] }), made.versions.length > 1 ? (_jsx(DropdownMenu, { trigger: _jsxs(XStack, { render: "button", "aria-label": "Compare versions", "aria-pressed": compare ? true : undefined, items: "center", gap: "$1.5", height: 30, px: "$2.5", rounded: "$3", bg: compare ? '$hover' : 'transparent', cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [_jsx(Columns2, { size: 14 }), _jsx(SizableText, { size: "$2", children: compare ? `v${(against ?? 0) + 1} | v${made.at + 1}` : 'Compare' })] }), items: [
|
|
52
52
|
{ type: 'label', key: 'h', label: 'Compare with' },
|
|
53
53
|
...made.versions.map((x, i) => ({ key: x.id, label: `Version ${i + 1}`, description: x.note.slice(0, 60), disabled: i === made.at, onSelect: () => setAgainst(i) })),
|
|
54
54
|
...(compare ? [{ type: 'separator', key: 's' }, { key: 'off', label: 'Stop comparing', onSelect: () => setAgainst(null) }] : []),
|
package/lib/gpu.js
CHANGED
|
@@ -22,7 +22,7 @@ export async function render(w, lane, body, doing, signal) {
|
|
|
22
22
|
for (;;) {
|
|
23
23
|
if (signal.aborted)
|
|
24
24
|
throw new DOMException('aborted', 'AbortError');
|
|
25
|
-
row = (await worklog(w, signal)).find((r) => r.prompt_id === id || r.id === id
|
|
25
|
+
row = (await worklog(w, signal)).find((r) => r.prompt_id === id || r.id === id);
|
|
26
26
|
const status = row?.status ?? 'queued';
|
|
27
27
|
if (status === 'done')
|
|
28
28
|
break;
|
package/lib/home.js
CHANGED
|
@@ -30,7 +30,7 @@ function Card({ s, i, onPress }) {
|
|
|
30
30
|
const Icon = k.icon;
|
|
31
31
|
const look = PRESETS[i % PRESETS.length];
|
|
32
32
|
use(look.display);
|
|
33
|
-
return (_jsxs(YStack, { role: "listitem", width: "calc(50% - 6px)", $sm: { width: 'calc(25% - 9px)' }, gap: "$1.5", children: [_jsxs(YStack, {
|
|
33
|
+
return (_jsxs(YStack, { role: "listitem", width: "calc(50% - 6px)", $sm: { width: 'calc(25% - 9px)' }, gap: "$1.5", children: [_jsxs(YStack, { position: "relative", width: "100%", rounded: 16, overflow: "hidden", style: { aspectRatio: '4 / 5' }, children: [s.thumb ? (_jsx("img", { src: s.thumb, alt: "", style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } })) : (_jsxs("div", { "aria-hidden": true, style: { position: 'absolute', inset: 0, background: look.colors.paper, color: look.colors.ink, padding: '14% 10%', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', textAlign: 'left' }, children: [_jsx("div", { style: { width: '28%', height: 4, background: look.colors.accent, marginBottom: 10 } }), _jsx("div", { style: { fontFamily: stack(look.display), fontWeight: look.weights.display, fontSize: 'clamp(18px, 2.4vw, 30px)', lineHeight: look.leading.display, letterSpacing: `${look.tracking.display}em` }, children: s.title })] })), _jsxs(XStack, { "aria-hidden": true, position: "absolute", t: 8, l: 8, r: 8, justify: "space-between", items: "center", children: [_jsx(XStack, { width: 26, height: 26, rounded: 99, bg: "rgba(0,0,0,0.55)", items: "center", justify: "center", children: _jsx(Icon, { size: 13 }) }), _jsx(XStack, { px: "$2", height: 22, rounded: 99, bg: "rgba(0,0,0,0.55)", items: "center", children: _jsx(SizableText, { size: "$1", color: "#fff", children: RUNTIME[s.kind] }) })] }), _jsx(YStack, { render: "button", "aria-label": `${s.title}: ${s.subtitle}`, onPress: onPress, position: "absolute", t: 0, l: 0, r: 0, b: 0, rounded: 16, cursor: "pointer", hoverStyle: { bg: 'rgba(255,255,255,0.08)' }, focusVisibleStyle: { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' } })] }), _jsx(SizableText, { size: "$2", fontWeight: "600", numberOfLines: 1, children: s.title }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, mt: -4, children: s.subtitle })] }));
|
|
34
34
|
}
|
|
35
35
|
const STATE = { making: 'Making', done: 'Done', failed: 'Failed' };
|
|
36
36
|
/** The last eight conversations, each with what it is doing now. */
|
package/lib/places.js
CHANGED
|
@@ -90,7 +90,7 @@ export function Explore() {
|
|
|
90
90
|
return null;
|
|
91
91
|
return (_jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: c.label }), _jsx(XStack, { flexWrap: "wrap", gap: "$2", children: list.map((s) => {
|
|
92
92
|
const why = kind(s.kind).needs(available);
|
|
93
|
-
return (_jsxs(YStack, { render: "button", "aria-
|
|
93
|
+
return (_jsxs(YStack, { render: "button", "aria-disabled": why ? true : undefined, onPress: () => {
|
|
94
94
|
if (why)
|
|
95
95
|
return;
|
|
96
96
|
queue(s);
|
package/lib/talk.js
CHANGED
|
@@ -352,8 +352,9 @@ function Opening() {
|
|
|
352
352
|
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." })] }));
|
|
353
353
|
}
|
|
354
354
|
/** A composer chip: what it sets, and its value. */
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
/** A menu's trigger: the menu hands it its state and handlers, and they land on the button itself. */
|
|
356
|
+
function Pillish({ label, icon, value, ...trigger }) {
|
|
357
|
+
return (_jsxs(XStack, { ...trigger, render: "button", "aria-label": `${label}: ${value}`, items: "center", gap: "$1.5", height: 32, px: "$2.5", rounded: 999, borderWidth: 1, borderColor: "$borderColor", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [icon, _jsx(SizableText, { size: "$2", numberOfLines: 1, maxW: 120, children: value }), _jsx(ChevronDown, { size: 12 })] }));
|
|
357
358
|
}
|
|
358
359
|
/** What a turn made, as a chip that opens its tab. */
|
|
359
360
|
function Chip({ made, wire, n, onPress }) {
|
package/lib/wire.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ export interface Ask {
|
|
|
44
44
|
type?: string;
|
|
45
45
|
signal?: AbortSignal;
|
|
46
46
|
head?: Record<string, string>;
|
|
47
|
+
/** Reads the headers of an answer that succeeded. */
|
|
48
|
+
heard?: (h: Headers) => void;
|
|
47
49
|
}
|
|
48
50
|
/** One request. JSON in, JSON out, unless the answer is not JSON. */
|
|
49
51
|
export declare function ask<T>(w: Wire, base: Base, path: string, o?: Ask): Promise<T>;
|
package/lib/wire.js
CHANGED
|
@@ -83,6 +83,7 @@ export async function ask(w, base, path, o = {}) {
|
|
|
83
83
|
const [msg, code] = await reason(res);
|
|
84
84
|
throw new Refusal(res.status, msg || `${path.split('?')[0]} answered ${res.status}`, code);
|
|
85
85
|
}
|
|
86
|
+
o.heard?.(res.headers);
|
|
86
87
|
if (res.status === 204)
|
|
87
88
|
return undefined;
|
|
88
89
|
const type = res.headers.get('content-type') ?? '';
|
|
@@ -216,6 +217,7 @@ export function bytes(url) {
|
|
|
216
217
|
* message (`images`) or among its content parts.
|
|
217
218
|
*/
|
|
218
219
|
export async function draw(w, model, prompt, o = {}) {
|
|
220
|
+
let held;
|
|
219
221
|
const content = [{ type: 'text', text: prompt }, ...(o.from ?? []).map((url) => ({ type: 'image_url', image_url: { url } }))];
|
|
220
222
|
const out = await ask(w, 'api', '/v1/chat/completions', {
|
|
221
223
|
body: {
|
|
@@ -225,6 +227,7 @@ export async function draw(w, model, prompt, o = {}) {
|
|
|
225
227
|
...(o.aspect ? { image_config: { aspect_ratio: o.aspect } } : {}),
|
|
226
228
|
},
|
|
227
229
|
signal: o.signal,
|
|
230
|
+
heard: (h) => (held = h),
|
|
228
231
|
});
|
|
229
232
|
const m = out.choices?.[0]?.message;
|
|
230
233
|
const urls = [
|
|
@@ -232,9 +235,29 @@ export async function draw(w, model, prompt, o = {}) {
|
|
|
232
235
|
...(Array.isArray(m?.content) ? m.content.map((p) => (p.type === 'image_url' ? (p.image_url?.url ?? '') : '')) : []),
|
|
233
236
|
].filter((u) => u.startsWith('data:image/'));
|
|
234
237
|
if (!urls.length)
|
|
235
|
-
throw
|
|
238
|
+
throw withheld(model, held);
|
|
236
239
|
return urls.map(bytes);
|
|
237
240
|
}
|
|
241
|
+
/*
|
|
242
|
+
* The gateway answers a request it will not serve with a model it will, in
|
|
243
|
+
* words: X-Hanzo-Usage-Reason says why and X-Hanzo-Upgrade-Url or
|
|
244
|
+
* X-Hanzo-Topup-Url what lifts it. A picture request answered that way is a
|
|
245
|
+
* refusal of the lane, said in the gateway's own reason.
|
|
246
|
+
*/
|
|
247
|
+
const WITHHELD = {
|
|
248
|
+
paid_plan_required: 'Pictures from this model need a paid plan',
|
|
249
|
+
plan_allowance_used: "This plan's pictures are used for now",
|
|
250
|
+
usage_cap_exceeded: "This org's usage cap is reached",
|
|
251
|
+
free_plan_cap: 'The free plan has no more pictures today',
|
|
252
|
+
model_cap: "This model's share is used for now",
|
|
253
|
+
};
|
|
254
|
+
function withheld(model, h) {
|
|
255
|
+
const why = h?.get('X-Hanzo-Usage-Reason') ?? '';
|
|
256
|
+
if (!why)
|
|
257
|
+
return new Refusal(502, `${model} answered with no picture.`);
|
|
258
|
+
const fix = h?.get('X-Hanzo-Upgrade-Url') || h?.get('X-Hanzo-Topup-Url') || '';
|
|
259
|
+
return new Refusal(402, `${WITHHELD[why] ?? `Pictures are withheld (${why})`}${fix ? `: ${fix}` : '.'}`, why);
|
|
260
|
+
}
|
|
238
261
|
/** Speech from words: the platform's voice. */
|
|
239
262
|
export async function speak(w, input, voice, model, signal) {
|
|
240
263
|
return ask(w, 'api', '/v1/audio/speech', { body: { model, input, voice, response_format: 'mp3' }, signal });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/studio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"description": "Hanzo Studio: a chat that makes images, posters, documents, slides, type systems, 3D, video and sound, with every result open in a tab beside it. Mounted by the Hanzo app at hanzo.ai/studio and served whole at studio.hanzo.ai.",
|