@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/attach.js CHANGED
@@ -1,7 +1,11 @@
1
- /** The sentence for files that did not attach: which, and the last reason given. '' when all did. */
2
- export function uploadFailure(names, reason) {
1
+ /**
2
+ * The one sentence for files that did not attach: which, and that they were left out (only what was stored is
3
+ * attached), never the server's own words. '' when all did.
4
+ */
5
+ export function uploadFailure(names) {
3
6
  if (!names.length)
4
7
  return '';
5
- const label = names.length === 1 ? `“${names[0]}”` : `${names.length} files`;
6
- return `Could not attach ${label}${reason ? `: ${reason}` : '.'}`;
8
+ return names.length === 1
9
+ ? `“${names[0]}” could not be attached, so it was left out: attach it again to retry.`
10
+ : `${names.length} files could not be attached, so they were left out: attach them again to retry.`;
7
11
  }
@@ -18,6 +18,7 @@ import type { Available } from '../kinds/kind.ts';
18
18
  import { type TypeSystem } from '../kinds/type/system.ts';
19
19
  import { type Chat, type KindId, type Made, type Stored } from '../made.ts';
20
20
  import { type Page } from '../source.ts';
21
+ import { type Spend } from '../spend.ts';
21
22
  export interface Asked {
22
23
  text: string;
23
24
  attached: Stored[];
@@ -45,6 +46,8 @@ export interface Context extends Available {
45
46
  /** The conversation changed: draw it, and keep it. */
46
47
  changed: (chat: Chat) => void;
47
48
  signal: AbortSignal;
49
+ /** Ask before anything paid starts (spend.ts), handed to every kind. */
50
+ spend: Spend;
48
51
  }
49
52
  /** The brand a conversation draws in, read from its type system. */
50
53
  export declare function brandOf(chat: Chat): TypeSystem | null;
package/lib/chat/turn.js CHANGED
@@ -15,12 +15,12 @@
15
15
  */
16
16
  import { complete, put, read } from '../wire.js';
17
17
  import { ALL, called, kind } from '../kinds/index.js';
18
- import { UNDRAWN } from '../kinds/image.js';
19
18
  import { settle } from '../kinds/type/system.js';
20
19
  import { current, dir } from '../made.js';
21
20
  import { data } from '../raster.js';
22
21
  import { fresh } from '../route.js';
23
22
  import { brief, shown, sourced } from '../source.js';
23
+ import { Declined } from '../spend.js';
24
24
  const ROUNDS = 4;
25
25
  const id = () => fresh().slice(-12);
26
26
  const REVISE = {
@@ -154,8 +154,9 @@ export async function turn(start, asked, ctx) {
154
154
  put_({ ...chat, turns: chat.turns.map((t) => (t.id === you.id ? { ...t, ...patch } : t)) });
155
155
  };
156
156
  const mine = () => chat.turns.find((t) => t.id === you.id);
157
- // A picture the gateway did not draw: the turn ends on one plain sentence and a retry.
158
- let missed = false;
157
+ // What was not made (a picture, a clip, music): the turn ends on that one sentence and a retry, never the
158
+ // model's own line about it, which may say "Here it is" of nothing.
159
+ let missed = '';
159
160
  const open = ALL.filter((k) => !k.needs(ctx));
160
161
  const closed = ALL.filter((k) => k.needs(ctx));
161
162
  const tools = [...open.map((k) => ({ type: 'function', function: k.tool })), REVISE, BRAND];
@@ -188,10 +189,13 @@ export async function turn(start, asked, ctx) {
188
189
  messages.push({ role: 'tool', tool_call_id: c.id, content: JSON.stringify(answer) });
189
190
  }
190
191
  }
191
- set({ doing: undefined, ...(missed ? { failed: `${UNDRAWN} Try again?` } : {}) });
192
+ set({ doing: undefined, ...(missed ? { text: '', failed: missed } : {}) });
192
193
  }
193
194
  catch (e) {
194
- if (e?.name === 'AbortError')
195
+ // A no to a spend: nothing started, and nothing failed.
196
+ if (e instanceof Declined)
197
+ set({ doing: undefined, text: e.message });
198
+ else if (e?.name === 'AbortError')
195
199
  set({ doing: undefined, failed: 'Stopped.' });
196
200
  else {
197
201
  // A round that fails after a tool ran (the closing line, say) leaves what it made standing.
@@ -224,6 +228,9 @@ export async function turn(start, asked, ctx) {
224
228
  return { ok: true, tab: tabN, title: m.title, kind: k.label, version: v, note: chat.made.find((x) => x.id === m.id)?.versions.at(-1)?.note };
225
229
  }
226
230
  catch (e) {
231
+ // A no to the spend ends the turn: the model is not asked to try something else instead.
232
+ if (e instanceof Declined)
233
+ throw e;
227
234
  return { ok: false, error: words(e) };
228
235
  }
229
236
  }
@@ -248,6 +255,8 @@ export async function turn(start, asked, ctx) {
248
255
  return { ok: true, tab: ctx.order().indexOf(done.id) + 1, title: done.title, kind: k.label, note: v.note };
249
256
  }
250
257
  catch (e) {
258
+ if (e instanceof Declined)
259
+ throw e;
251
260
  return { ok: false, error: words(e) };
252
261
  }
253
262
  }
@@ -267,8 +276,8 @@ export async function turn(start, asked, ctx) {
267
276
  wire: ctx.wire,
268
277
  signal: ctx.signal,
269
278
  doing: (line) => set({ doing: line }),
270
- missed: () => {
271
- missed = true;
279
+ missed: (said) => {
280
+ missed = said;
272
281
  },
273
282
  keep: async (name, blob, extra) => {
274
283
  const key = await put(ctx.wire, `${dir(chat.id, m, vid)}/${name}`, blob);
@@ -284,6 +293,7 @@ export async function turn(start, asked, ctx) {
284
293
  fleet: ctx.fleet,
285
294
  models: ctx.models,
286
295
  writer: ctx.writer,
296
+ spend: ctx.spend,
287
297
  };
288
298
  }
289
299
  }
@@ -303,6 +313,7 @@ export async function edit(start, m, patch, note, ctx) {
303
313
  fleet: ctx.fleet,
304
314
  models: ctx.models,
305
315
  writer: ctx.writer,
316
+ spend: ctx.spend,
306
317
  };
307
318
  const draft = await k.revise(w, m, { patch });
308
319
  const v = { ...draft, note, id: vid, at: Date.now() };
package/lib/desk.js CHANGED
@@ -9,7 +9,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
9
  */
10
10
  import { RING } from './ui.js';
11
11
  import { SizableText, XStack, YStack } from '@hanzo/gui';
12
- import { Bookmark, Check, ChevronDown, Columns2, Download, Link2, MessageSquare, MoveHorizontal, Send } from '@hanzogui/lucide-icons-2';
12
+ import { Bookmark, Check, ChevronDown, Columns2, Download, MessageSquare, MoveHorizontal, Send } from '@hanzogui/lucide-icons-2';
13
13
  import { DropdownMenu, Popover, PopoverContent, PopoverTrigger } from '@hanzo/ui';
14
14
  import { useCallback, useEffect, useRef, useState } from 'react';
15
15
  import { kind } from './kinds/index.js';
@@ -20,7 +20,7 @@ import { HANDOFF_CHAT } from './handoff.js';
20
20
  import { useHost } from './host.js';
21
21
  import { post } from './post.js';
22
22
  import { useUrl } from './use.js';
23
- import { read, saveToLibrary, url } from './wire.js';
23
+ import { read, saveToLibrary } from './wire.js';
24
24
  /** Render an image blob onto an offscreen canvas at `scale` (1x or 2x). */
25
25
  async function rasterizeBlob(blob, scale) {
26
26
  if (typeof document === 'undefined')
@@ -60,32 +60,6 @@ async function canvasToPdfBlob(canvas, title) {
60
60
  const jpeg = new Uint8Array(await (await canvasToBlob(canvas, 'image/jpeg', 0.92)).arrayBuffer());
61
61
  return pdf([{ jpeg, width: canvas.width, height: canvas.height, pageWidth: canvas.width * 0.75, pageHeight: canvas.height * 0.75 }], title);
62
62
  }
63
- async function copyText(text) {
64
- try {
65
- if (navigator.clipboard?.writeText) {
66
- await navigator.clipboard.writeText(text);
67
- return true;
68
- }
69
- }
70
- catch {
71
- // Fall through to temporary textarea
72
- }
73
- try {
74
- const ta = document.createElement('textarea');
75
- ta.value = text;
76
- ta.setAttribute('readonly', 'true');
77
- ta.style.position = 'fixed';
78
- ta.style.opacity = '0';
79
- document.body.appendChild(ta);
80
- ta.select();
81
- const ok = document.execCommand('copy');
82
- ta.remove();
83
- return ok;
84
- }
85
- catch {
86
- return false;
87
- }
88
- }
89
63
  const ago = (t) => {
90
64
  const s = Math.max(0, Math.round((Date.now() - t) / 1000));
91
65
  if (s < 60)
@@ -114,7 +88,6 @@ export function Desk({ made, wire, others, onPick, onEdit, busy, failed }) {
114
88
  const [exportScale, setExportScale] = useState(2);
115
89
  const [exportBusy, setExportBusy] = useState(false);
116
90
  const [exportedOnce, setExportedOnce] = useState(false);
117
- const [copiedLink, setCopiedLink] = useState(false);
118
91
  const [savedLibrary, setSavedLibrary] = useState(false);
119
92
  const [savingLibrary, setSavingLibrary] = useState(false);
120
93
  const [sending, setSending] = useState(false);
@@ -296,29 +269,6 @@ export function Desk({ made, wire, others, onPick, onEdit, busy, failed }) {
296
269
  setExportBusy(false);
297
270
  }
298
271
  };
299
- const handleCopyLink = async () => {
300
- setError('');
301
- let link = typeof window !== 'undefined' ? window.location.href : '';
302
- const primaryFile = v.files[0];
303
- if (primaryFile) {
304
- try {
305
- const resolved = await url(wire, primaryFile.key);
306
- if (resolved && /^https?:\/\//i.test(resolved))
307
- link = resolved;
308
- }
309
- catch {
310
- // Keep current page URL fallback
311
- }
312
- }
313
- const ok = await copyText(link);
314
- if (ok) {
315
- setCopiedLink(true);
316
- timersRef.current.push(window.setTimeout(() => setCopiedLink(false), 2000));
317
- }
318
- else {
319
- setError('Could not copy link to clipboard.');
320
- }
321
- };
322
272
  const Icon = k.icon;
323
273
  const versions = made.versions.map((x, i) => ({
324
274
  key: x.id,
@@ -343,7 +293,7 @@ export function Desk({ made, wire, others, onPick, onEdit, busy, failed }) {
343
293
  }) })] }), _jsxs(YStack, { gap: "$1.5", opacity: scaleApplies ? 1 : 0.45, children: [_jsxs(XStack, { items: "center", justify: "space-between", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: "Resolution" }), !scaleApplies ? (_jsx(SizableText, { size: "$1", color: "$hint", children: "Native size" })) : null] }), _jsx(XStack, { role: "radiogroup", "aria-label": "Export resolution", gap: "$1.5", children: [1, 2].map((sc) => {
344
294
  const on = exportScale === sc;
345
295
  return (_jsxs(XStack, { render: _jsx("button", { type: "button" }), role: "radio", "aria-checked": on, disabled: !scaleApplies, onClick: () => scaleApplies && setExportScale(sc), flex: 1, minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 30, height: 30 }, items: "center", justify: "center", gap: "$1", rounded: "$2", borderWidth: 1, borderColor: on && scaleApplies ? '$ink' : 'var(--border-strong)', bg: on && scaleApplies ? 'var(--surface-card-emphasis)' : 'transparent', cursor: scaleApplies ? 'pointer' : 'default', hoverStyle: scaleApplies ? { bg: '$hover' } : undefined, focusVisibleStyle: RING, children: [_jsx(SizableText, { size: "$1", fontFamily: "$mono", fontWeight: on ? '600' : '500', color: on && scaleApplies ? '$ink' : '$soft', children: `${sc}×` }), _jsx(SizableText, { size: "$1", color: "$soft", children: sc === 1 ? 'Standard' : 'Retina' })] }, sc));
346
- }) })] }), _jsxs(XStack, { gap: "$2", children: [_jsxs(XStack, { render: _jsx("button", { type: "button" }), disabled: exportBusy, onClick: () => void runUnifiedExport(), flex: 1, minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 34, height: 34 }, px: "$3", rounded: "$3", bg: "$ink", items: "center", justify: "center", gap: "$1.5", cursor: exportBusy ? 'default' : 'pointer', opacity: exportBusy ? 0.6 : 1, hoverStyle: exportBusy ? undefined : { opacity: 0.9 }, focusVisibleStyle: RING, children: [exportedOnce ? _jsx(Check, { size: 13, color: "$background" }) : _jsx(Download, { size: 13, color: "$background" }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$background", children: exportBusy ? 'Exporting…' : exportedOnce ? 'Downloaded' : 'Download' })] }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": copiedLink ? 'Link copied' : 'Copy link', onClick: () => void handleCopyLink(), minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 34, height: 34 }, px: "$3", rounded: "$3", borderWidth: 1, borderColor: copiedLink ? 'var(--state-success)' : 'var(--border-strong)', bg: copiedLink ? 'var(--state-success-bg)' : 'transparent', items: "center", justify: "center", gap: "$1.5", cursor: "pointer", hoverStyle: { bg: copiedLink ? 'var(--state-success-bg)' : '$hover' }, focusVisibleStyle: RING, children: [copiedLink ? _jsx(Check, { size: 13, color: "var(--state-success)" }) : _jsx(Link2, { size: 13, color: "$ink" }), _jsx(SizableText, { size: "$2", fontWeight: "500", color: copiedLink ? 'var(--state-success)' : '$ink', children: copiedLink ? 'Copied' : 'Copy link' })] })] }), k.exports.length > 1 ? (_jsxs(YStack, { gap: "$1", pt: "$2", borderTopWidth: 1, borderColor: "var(--border)", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: "Kind-specific exports" }), _jsx(XStack, { gap: "$1.5", flexWrap: "wrap", children: k.exports.map((ex, i) => (_jsx(XStack, { render: _jsx("button", { type: "button" }), disabled: exportBusy, onClick: () => void exportingNative(i), minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, px: "$2", rounded: "$2", borderWidth: 1, borderColor: "var(--border-strong)", bg: "transparent", items: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", color: "$ink", children: ex.label }) }, ex.label))) })] })) : null] })] })] }), error || failed ? (_jsx(XStack, { px: "$3", py: "$2", bg: "var(--state-error-bg)", borderBottomWidth: 1, borderColor: "var(--border)", shrink: 0, children: _jsx(SizableText, { size: "$2", color: "var(--state-error)", children: error || failed }) })) : null, compare ? (_jsx(Compare, { made: made, a: compare, b: v, wire: wire, others: others })) : (_jsx(k.View, { made: made, version: v, wire: wire, edit: onEdit, busy: busy, others: others }))] }));
296
+ }) })] }), _jsx(XStack, { gap: "$2", children: _jsxs(XStack, { render: _jsx("button", { type: "button" }), disabled: exportBusy, onClick: () => void runUnifiedExport(), flex: 1, minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 34, height: 34 }, px: "$3", rounded: "$3", bg: "$ink", items: "center", justify: "center", gap: "$1.5", cursor: exportBusy ? 'default' : 'pointer', opacity: exportBusy ? 0.6 : 1, hoverStyle: exportBusy ? undefined : { opacity: 0.9 }, focusVisibleStyle: RING, children: [exportedOnce ? _jsx(Check, { size: 13, color: "$background" }) : _jsx(Download, { size: 13, color: "$background" }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$background", children: exportBusy ? 'Exporting…' : exportedOnce ? 'Downloaded' : 'Download' })] }) }), k.exports.length > 1 ? (_jsxs(YStack, { gap: "$1", pt: "$2", borderTopWidth: 1, borderColor: "var(--border)", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: "Kind-specific exports" }), _jsx(XStack, { gap: "$1.5", flexWrap: "wrap", children: k.exports.map((ex, i) => (_jsx(XStack, { render: _jsx("button", { type: "button" }), disabled: exportBusy, onClick: () => void exportingNative(i), minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, px: "$2", rounded: "$2", borderWidth: 1, borderColor: "var(--border-strong)", bg: "transparent", items: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", color: "$ink", children: ex.label }) }, ex.label))) })] })) : null] })] })] }), error || failed ? (_jsx(XStack, { px: "$3", py: "$2", bg: "var(--state-error-bg)", borderBottomWidth: 1, borderColor: "var(--border)", shrink: 0, children: _jsx(SizableText, { size: "$2", color: "var(--state-error)", children: error || failed }) })) : null, compare ? (_jsx(Compare, { made: made, a: compare, b: v, wire: wire, others: others })) : (_jsx(k.View, { made: made, version: v, wire: wire, edit: onEdit, busy: busy, others: others }))] }));
347
297
  }
348
298
  function Compare({ made, a, b, wire, others }) {
349
299
  const pa = a.files.find((f) => f.mime.startsWith('image/'));
package/lib/home.d.ts CHANGED
@@ -1,6 +1,18 @@
1
1
  import type { Available } from './kinds/kind.ts';
2
2
  import type { KindId } from './made.ts';
3
3
  import { type Starter } from './starters.ts';
4
+ interface UploadAction {
5
+ id: string;
6
+ shortLabel: string;
7
+ label: string;
8
+ description: string;
9
+ accept?: string;
10
+ /** Words put in the composer with the files; none when the files are all it does. */
11
+ prompt?: string;
12
+ kind?: KindId;
13
+ }
14
+ /** What the Upload menu offers: each attaches files, and some also start a request in the composer. */
15
+ export declare const UPLOAD_ACTIONS: readonly UploadAction[];
4
16
  export declare function Home({ available, onStart, onUpload, onSource, }: {
5
17
  available: Available;
6
18
  onStart: (s: Starter) => void;
@@ -8,3 +20,4 @@ export declare function Home({ available, onStart, onUpload, onSource, }: {
8
20
  /** Opens the web-address field: start from a web page (source.ts). */
9
21
  onSource?: () => void;
10
22
  }): import("react").JSX.Element;
23
+ export {};
package/lib/home.js CHANGED
@@ -18,7 +18,8 @@ import { path } from './route.js';
18
18
  import { CATEGORIES, RUNTIME, STARTERS } from './starters.js';
19
19
  import { Pill, RING, RING_INSET } from './ui.js';
20
20
  import { useUrl } from './use.js';
21
- const UPLOAD_ACTIONS = [
21
+ /** What the Upload menu offers: each attaches files, and some also start a request in the composer. */
22
+ export const UPLOAD_ACTIONS = [
22
23
  {
23
24
  id: 'audio',
24
25
  shortLabel: 'Audio',
@@ -32,9 +33,9 @@ const UPLOAD_ACTIONS = [
32
33
  id: 'image',
33
34
  shortLabel: 'Image',
34
35
  label: 'Upload image',
35
- description: 'Create a poster, ad campaign, or visual',
36
+ // Attaches the picture and nothing else: what to make of it is the person's to say.
37
+ description: 'Attach a picture to your message',
36
38
  accept: 'image/*,.png,.jpg,.jpeg,.webp,.svg',
37
- prompt: 'Create a brand poster, multi-format ad campaign, and presentation slide deck featuring this visual.',
38
39
  },
39
40
  {
40
41
  id: 'document',
@@ -128,7 +129,9 @@ function Recent() {
128
129
  const { rows } = useChats(wire);
129
130
  if (!rows.length)
130
131
  return null;
131
- return (_jsxs(YStack, { gap: "$2", pt: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", children: [_jsx(SizableText, { size: "$3", fontWeight: "600", color: "$ink", children: "Recent" }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Open the library", onClick: () => host.go(path({ kind: 'library' })), items: "center", gap: "$1", cursor: "pointer", px: "$2.5", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, rounded: "$3", borderWidth: 1, borderColor: "transparent", hoverStyle: { bg: '$hover', borderColor: 'var(--border-strong)' }, focusVisibleStyle: RING, children: [_jsx(SizableText, { size: "$2", color: "$soft", children: "Library" }), _jsx(ArrowRight, { size: 13, color: "$soft" })] })] }), _jsx(XStack, { role: "list", "aria-label": "Recent conversations", gap: "$3", overflowX: "auto", pb: "$1", width: "100%", style: { scrollbarWidth: 'none' }, children: rows.slice(0, 8).map((r) => (_jsx(YStack, { role: "listitem", width: 152, shrink: 0, children: _jsxs(YStack, { render: _jsx("button", { type: "button" }), "aria-label": `${r.title}, ${STATE[r.state]}`, onClick: () => host.go(path({ kind: 'chat', id: r.id })), width: "100%", gap: "$1.5", items: "flex-start", cursor: "pointer", rounded: "$3", focusVisibleStyle: RING, children: [_jsx(Cover, { wire: wire, cover: r.cover }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", text: "left", numberOfLines: 1, children: r.title }), _jsxs(XStack, { items: "center", gap: "$1.5", children: [_jsx(XStack, { width: 6, height: 6, rounded: 6, bg: r.state === 'failed' ? 'var(--state-error)' : r.state === 'done' ? 'var(--state-success)' : '$ink' }), _jsx(SizableText, { size: "$1", color: "$soft", children: `${STATE[r.state]} · ${r.count} made` })] })] }) }, r.id))) })] }));
132
+ return (_jsxs(YStack, { gap: "$2", pt: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", children: [_jsx(SizableText, { size: "$3", fontWeight: "600", color: "$ink", children: "Recent" }), _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Open the library",
133
+ // The host's one Library lists what Design made, every kind.
134
+ onClick: () => host.open('/library'), items: "center", gap: "$1", cursor: "pointer", px: "$2.5", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 28, height: 28 }, rounded: "$3", borderWidth: 1, borderColor: "transparent", hoverStyle: { bg: '$hover', borderColor: 'var(--border-strong)' }, focusVisibleStyle: RING, children: [_jsx(SizableText, { size: "$2", color: "$soft", children: "Library" }), _jsx(ArrowRight, { size: 13, color: "$soft" })] })] }), _jsx(XStack, { role: "list", "aria-label": "Recent conversations", gap: "$3", overflowX: "auto", pb: "$1", width: "100%", style: { scrollbarWidth: 'none' }, children: rows.slice(0, 8).map((r) => (_jsx(YStack, { role: "listitem", width: 152, shrink: 0, children: _jsxs(YStack, { render: _jsx("button", { type: "button" }), "aria-label": `${r.title}, ${STATE[r.state]}`, onClick: () => host.go(path({ kind: 'chat', id: r.id })), width: "100%", gap: "$1.5", items: "flex-start", cursor: "pointer", rounded: "$3", focusVisibleStyle: RING, children: [_jsx(Cover, { wire: wire, cover: r.cover }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", text: "left", numberOfLines: 1, children: r.title }), _jsxs(XStack, { items: "center", gap: "$1.5", children: [_jsx(XStack, { width: 6, height: 6, rounded: 6, bg: r.state === 'failed' ? 'var(--state-error)' : r.state === 'done' ? 'var(--state-success)' : '$ink' }), _jsx(SizableText, { size: "$1", color: "$soft", children: `${STATE[r.state]} · ${r.count} made` })] })] }) }, r.id))) })] }));
132
135
  }
133
136
  function Cover({ wire, cover }) {
134
137
  const { src } = useUrl(wire, cover);
package/lib/host.d.ts CHANGED
@@ -2,11 +2,27 @@
2
2
  * The host Studio is mounted under, for every pane: @hanzo/build's `Host`, the
3
3
  * same value Dev takes, so hanzo.ai mounts both one way. It is also handed to
4
4
  * @hanzo/build's own provider, which its side panel reads.
5
+ *
6
+ * A host may carry its one spend confirm (`spend`, the Hanzo app's). Every pane
7
+ * reads `useHost().spend`, which is that confirm or, on a host without one,
8
+ * Studio's own (spend.ts `asker`, drawn here with the kit's AlertDialog).
5
9
  */
6
10
  import { type Host } from '@hanzo/build';
7
11
  import { type ReactNode } from 'react';
12
+ import { type Spend } from './spend.ts';
13
+ /** The host as Studio is handed it: its spend confirm when it has one. */
14
+ export type Hosted = Host & {
15
+ spend?: Spend;
16
+ };
8
17
  export declare function StudioHost({ host, children }: {
9
- host: Host;
18
+ host: Hosted;
10
19
  children: ReactNode;
11
20
  }): import("react").JSX.Element;
12
- export declare function useHost(): Host;
21
+ export declare function useHost(): Host & {
22
+ spend: Spend;
23
+ };
24
+ /** The host's spend confirm, else Studio's own and the dialog that asks it: never a spend without a question. */
25
+ export declare function useSpend(host: Hosted): {
26
+ spend: Spend;
27
+ dialog: ReactNode;
28
+ };
package/lib/host.js CHANGED
@@ -1,14 +1,22 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /**
3
3
  * The host Studio is mounted under, for every pane: @hanzo/build's `Host`, the
4
4
  * same value Dev takes, so hanzo.ai mounts both one way. It is also handed to
5
5
  * @hanzo/build's own provider, which its side panel reads.
6
+ *
7
+ * A host may carry its one spend confirm (`spend`, the Hanzo app's). Every pane
8
+ * reads `useHost().spend`, which is that confirm or, on a host without one,
9
+ * Studio's own (spend.ts `asker`, drawn here with the kit's AlertDialog).
6
10
  */
7
11
  import { HostProvider } from '@hanzo/build';
8
- import { createContext, useContext } from 'react';
12
+ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@hanzo/ui';
13
+ import { createContext, useContext, useMemo, useState } from 'react';
14
+ import { asker } from './spend.js';
9
15
  const Ctx = createContext(null);
10
16
  export function StudioHost({ host, children }) {
11
- return (_jsx(HostProvider, { host: host, children: _jsx(Ctx.Provider, { value: host, children: children }) }));
17
+ const { spend, dialog } = useSpend(host);
18
+ const held = useMemo(() => ({ ...host, spend }), [host, spend]);
19
+ return (_jsx(HostProvider, { host: host, children: _jsxs(Ctx.Provider, { value: held, children: [children, dialog] }) }));
12
20
  }
13
21
  export function useHost() {
14
22
  const h = useContext(Ctx);
@@ -16,3 +24,18 @@ export function useHost() {
16
24
  throw new Error('Studio was drawn without a host');
17
25
  return h;
18
26
  }
27
+ /** The host's spend confirm, else Studio's own and the dialog that asks it: never a spend without a question. */
28
+ export function useSpend(host) {
29
+ const [q, setQ] = useState(null);
30
+ const [own] = useState(() => asker(setQ));
31
+ if (host.spend)
32
+ return { spend: host.spend, dialog: null };
33
+ return {
34
+ spend: own.ask,
35
+ dialog: (_jsx(AlertDialog, { open: Boolean(q), onOpenChange: (open) => {
36
+ // Escape or a press outside is a no; deferred, so a yes pressed in the same event is answered first.
37
+ if (!open)
38
+ setTimeout(() => own.answer(false));
39
+ }, children: _jsxs(AlertDialogContent, { borderColor: "var(--border-strong)", maxW: 420, children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: q?.title }), _jsx(AlertDialogDescription, { children: q?.what })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { borderColor: "var(--border-strong)", onPress: () => own.answer(false), children: "Cancel" }), _jsx(AlertDialogAction, { onPress: () => own.answer(true), children: q?.yes })] })] }) })),
40
+ };
41
+ }
package/lib/index.d.ts CHANGED
@@ -3,13 +3,13 @@
3
3
  *
4
4
  * `Studio({host, rail})` under a gui root in a box with a height; `nav(host,
5
5
  * go)` for a host that draws Studio's places in a rail of its own (the Hanzo
6
- * app at hanzo.ai/studio). `host` is @hanzo/build's `Host`, the value Dev
6
+ * app at hanzo.ai/design). `host` is @hanzo/build's `Host`, the value Dev
7
7
  * takes, and `host.path` is Studio's address under its mount (`route`).
8
8
  * `useRecent(host)` for a host that lists the conversations beside it.
9
9
  */
10
10
  export { Studio } from './studio.tsx';
11
11
  export { DirectorStudio, directorNav, parseStudioSection, type StudioSection } from './app/director.tsx';
12
- export { FlowStudio, flowNav, parseFlowSection, type FlowSection } from './app/flow.tsx';
12
+ export { FlowStudio, flowNav } from './app/flow.tsx';
13
13
  export { nav, NEW, type Group } from './nav.tsx';
14
14
  export { path, route, type Route } from './route.ts';
15
15
  export { starters, type Offer } from './starters.ts';
@@ -17,3 +17,5 @@ export { useRecent } from './live.ts';
17
17
  export { HANDOFF_CHAT } from './handoff.ts';
18
18
  export type { Listed } from './chat/store.ts';
19
19
  export type { Host } from '@hanzo/build';
20
+ export type { Hosted } from './host.tsx';
21
+ export type { Asked, Spend } from './spend.ts';
package/lib/index.js CHANGED
@@ -3,13 +3,13 @@
3
3
  *
4
4
  * `Studio({host, rail})` under a gui root in a box with a height; `nav(host,
5
5
  * go)` for a host that draws Studio's places in a rail of its own (the Hanzo
6
- * app at hanzo.ai/studio). `host` is @hanzo/build's `Host`, the value Dev
6
+ * app at hanzo.ai/design). `host` is @hanzo/build's `Host`, the value Dev
7
7
  * takes, and `host.path` is Studio's address under its mount (`route`).
8
8
  * `useRecent(host)` for a host that lists the conversations beside it.
9
9
  */
10
10
  export { Studio } from './studio.js';
11
11
  export { DirectorStudio, directorNav, parseStudioSection } from './app/director.js';
12
- export { FlowStudio, flowNav, parseFlowSection } from './app/flow.js';
12
+ export { FlowStudio, flowNav } from './app/flow.js';
13
13
  export { nav, NEW } from './nav.js';
14
14
  export { path, route } from './route.js';
15
15
  export { starters } from './starters.js';
package/lib/kinds/ad.js CHANGED
@@ -16,6 +16,7 @@ import { zip } from '../zip.js';
16
16
  import { picture } from './image.js';
17
17
  import { num, str } from './kind.js';
18
18
  import { svg } from './poster/index.js';
19
+ import { Declined } from '../spend.js';
19
20
  import { PRESETS, settle } from './type/system.js';
20
21
  export const UNITS = [
21
22
  { id: 'feed', label: 'Feed 1:1', width: 1080, height: 1080, set: 'social' },
@@ -94,6 +95,9 @@ export const ad = {
94
95
  s.picture = (await picture(w, { prompt: s.prompt, aspect: '4:5', model: '' })).files[0]?.key ?? '';
95
96
  }
96
97
  catch (e) {
98
+ // A no to the spend ends the turn: nothing is made in its place.
99
+ if (e instanceof Declined)
100
+ throw e;
97
101
  why = e instanceof Error ? e.message : String(e);
98
102
  }
99
103
  }
@@ -1,6 +1,21 @@
1
- import { type Kind } from './kind.ts';
1
+ import { type Kind, type Work } from './kind.ts';
2
2
  import { type TypeSystem } from './type/system.ts';
3
+ type Arch = 'doc' | 'deck';
4
+ interface Block {
5
+ /** A doc block's type; a slide has a layout instead. */
6
+ type?: string;
7
+ [k: string]: unknown;
8
+ }
9
+ interface Ir {
10
+ title: string;
11
+ blocks?: Block[];
12
+ slides?: Block[];
13
+ theme?: Record<string, string>;
14
+ }
3
15
  /** The brand as the engine's theme. */
4
16
  export declare function theme(t: TypeSystem | null): Record<string, string>;
17
+ /** Draw or take each picture a written IR asks for, and keep it: the IR then names stored keys. */
18
+ export declare function pictures(w: Work, ir: Ir, arch: Arch): Promise<Ir>;
5
19
  export declare const document_: Kind;
6
20
  export declare const slides: Kind;
21
+ export {};
@@ -21,8 +21,9 @@ import { pdf as buildPdf } from '../pdf.js';
21
21
  import { pixels, shrink } from '../raster.js';
22
22
  import { Act } from '../ui.js';
23
23
  import { documents, read, structured } from '../wire.js';
24
- import { picture } from './image.js';
24
+ import { lane, picture, ZEN } from './image.js';
25
25
  import { num, str } from './kind.js';
26
+ import { spend } from '../spend.js';
26
27
  import { PRESETS } from './type/system.js';
27
28
  /** The brand as the engine's theme. */
28
29
  export function theme(t) {
@@ -73,19 +74,31 @@ const BRIEF = {
73
74
  deck: `You write slide decks as JSON slides. Layouts: title (title, subtitle), section (title), bullets (title, 3 to 5 bullets), image (title, prompt or tab), split (title, bullets, prompt or tab), quote (quote, subtitle as the attribution), chart (title, labels, values), closing (title, subtitle). Fill every field of every slide; use "", 0 and [] for fields a layout does not use. Speaker notes in notes. Ten slides or fewer unless asked. Pictures with no words in them.`,
74
75
  };
75
76
  /** Draw or take each picture a written IR asks for, and keep it: the IR then names stored keys. */
76
- async function pictures(w, ir, arch) {
77
+ export async function pictures(w, ir, arch) {
77
78
  const list = (arch === 'doc' ? ir.blocks : ir.slides) ?? [];
79
+ const wants = (b) => (arch === 'doc' ? b.type === 'image' : b.layout === 'image' || b.layout === 'split') && !str(b.src);
80
+ const given = (b) => {
81
+ const tab = num(b.tab, 0) ? w.find(num(b.tab, 0)) : null;
82
+ return tab ? current(tab).files.find((x) => x.mime.startsWith('image/')) : undefined;
83
+ };
84
+ // One ask for every picture the document draws, saying how many, before any is drawn: a no draws none of them.
85
+ const drawing = list.filter((b) => wants(b) && !given(b) && str(b.prompt)).length;
86
+ if (drawing) {
87
+ await spend(w, lane('', w.fleet) === ZEN ? 'design-gpu' : 'design-image', {
88
+ title: drawing === 1 ? 'Make this picture?' : `Make ${drawing} pictures?`,
89
+ what: drawing === 1 ? 'This makes one picture.' : `This makes ${drawing} pictures.`,
90
+ });
91
+ }
92
+ const asked = { ...w, spend: async () => true };
78
93
  let n = 0;
79
94
  const out = [];
80
95
  for (const b of list) {
81
- const wants = arch === 'doc' ? b.type === 'image' : b.layout === 'image' || b.layout === 'split';
82
- if (!wants || str(b.src)) {
96
+ if (!wants(b)) {
83
97
  out.push(b);
84
98
  continue;
85
99
  }
86
100
  n++;
87
- const tab = num(b.tab, 0) ? w.find(num(b.tab, 0)) : null;
88
- const f = tab ? current(tab).files.find((x) => x.mime.startsWith('image/')) : undefined;
101
+ const f = given(b);
89
102
  if (f) {
90
103
  out.push({ ...b, src: f.key });
91
104
  continue;
@@ -96,7 +109,7 @@ async function pictures(w, ir, arch) {
96
109
  }
97
110
  try {
98
111
  w.doing(`Drawing picture ${n}`);
99
- const got = await picture(w, { prompt: str(b.prompt), aspect: arch === 'deck' ? (b.layout === 'split' ? '4:5' : '16:9') : '3:2', model: '' });
112
+ const got = await picture(asked, { prompt: str(b.prompt), aspect: arch === 'deck' ? (b.layout === 'split' ? '4:5' : '16:9') : '3:2', model: '' });
100
113
  out.push({ ...b, src: got.files[0]?.key ?? '' });
101
114
  }
102
115
  catch (e) {