@hanzo/studio 0.1.8 → 0.1.12

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 (49) hide show
  1. package/lib/app/director.d.ts +134 -0
  2. package/lib/app/director.js +1196 -0
  3. package/lib/app/flow-run.d.ts +34 -0
  4. package/lib/app/flow-run.js +77 -0
  5. package/lib/app/flow.d.ts +58 -0
  6. package/lib/app/flow.js +1213 -0
  7. package/lib/app/sections.d.ts +5 -0
  8. package/lib/app/sections.js +26 -0
  9. package/lib/attach.d.ts +2 -0
  10. package/lib/attach.js +7 -0
  11. package/lib/chat/turn.js +19 -11
  12. package/lib/desk.d.ts +1 -1
  13. package/lib/desk.js +370 -14
  14. package/lib/download.d.ts +2 -0
  15. package/lib/download.js +11 -0
  16. package/lib/gpu.d.ts +13 -1
  17. package/lib/gpu.js +39 -16
  18. package/lib/handoff.d.ts +2 -0
  19. package/lib/handoff.js +2 -0
  20. package/lib/home.d.ts +3 -1
  21. package/lib/home.js +98 -9
  22. package/lib/index.d.ts +7 -0
  23. package/lib/index.js +6 -0
  24. package/lib/kinds/app.d.ts +40 -0
  25. package/lib/kinds/app.js +907 -0
  26. package/lib/kinds/document.js +256 -19
  27. package/lib/kinds/image.d.ts +3 -0
  28. package/lib/kinds/image.js +82 -10
  29. package/lib/kinds/index.js +2 -1
  30. package/lib/kinds/sound.js +109 -10
  31. package/lib/kinds/video.js +146 -17
  32. package/lib/live.d.ts +11 -0
  33. package/lib/live.js +10 -0
  34. package/lib/made.d.ts +2 -1
  35. package/lib/made.js +1 -0
  36. package/lib/pdf.js +1 -1
  37. package/lib/places.d.ts +0 -3
  38. package/lib/places.js +185 -41
  39. package/lib/route.d.ts +18 -0
  40. package/lib/route.js +23 -0
  41. package/lib/starters.d.ts +21 -0
  42. package/lib/starters.js +33 -2
  43. package/lib/studio.js +1 -1
  44. package/lib/talk.js +149 -46
  45. package/lib/ui.d.ts +18 -4
  46. package/lib/ui.js +50 -22
  47. package/lib/wire.d.ts +19 -6
  48. package/lib/wire.js +36 -3
  49. package/package.json +1 -1
@@ -19,7 +19,117 @@ const SIZES = {
19
19
  };
20
20
  /** Frames at the GPU lane's 24 fps for a length in seconds. */
21
21
  const frames = (s) => Math.round(s * 24) + 1;
22
- const lane = (a) => (maker(a, 'video') ? 'gateway' : lit(a.fleet, 'video.wan') ? 'gpu' : null);
22
+ const lane = (a) => (maker(a, 'video') ? 'gateway' : lit(a.fleet, 'video.wan') ? 'gpu' : 'canvas');
23
+ /** Browser-native motion graphics video synthesizer (records `<canvas>` at 30fps via MediaRecorder). */
24
+ async function synthesizeMotionVideo(prompt, title, aspect, seconds, startImageBlob, doing) {
25
+ doing('Rendering motion clip');
26
+ const [w, h] = aspect === '9:16' ? [720, 1280] : aspect === '1:1' ? [960, 960] : [1280, 720];
27
+ const canvas = document.createElement('canvas');
28
+ canvas.width = w;
29
+ canvas.height = h;
30
+ const ctx = canvas.getContext('2d');
31
+ if (!ctx)
32
+ throw new Error('This browser cannot render video frames.');
33
+ let bmp = null;
34
+ if (startImageBlob) {
35
+ try {
36
+ bmp = await createImageBitmap(startImageBlob);
37
+ }
38
+ catch {
39
+ bmp = null;
40
+ }
41
+ }
42
+ let hash = 2166136261;
43
+ for (let i = 0; i < prompt.length; i++)
44
+ hash = Math.imul(hash ^ prompt.charCodeAt(i), 16777619);
45
+ const palettes = [
46
+ ['#090a10', '#f43f5e', '#6366f1'],
47
+ ['#071318', '#06b6d4', '#10b981'],
48
+ ['#140b1c', '#ec4899', '#f59e0b'],
49
+ ['#0f172a', '#3b82f6', '#8b5cf6'],
50
+ ];
51
+ const [bg, c1, c2] = palettes[Math.abs(hash) % palettes.length];
52
+ const mimeType = typeof MediaRecorder !== 'undefined' && MediaRecorder.isTypeSupported('video/webm;codecs=vp9')
53
+ ? 'video/webm;codecs=vp9'
54
+ : typeof MediaRecorder !== 'undefined' && MediaRecorder.isTypeSupported('video/webm')
55
+ ? 'video/webm'
56
+ : 'video/mp4';
57
+ const stream = canvas.captureStream(30);
58
+ const recorder = new MediaRecorder(stream, { mimeType });
59
+ const chunks = [];
60
+ recorder.ondataavailable = (e) => {
61
+ if (e.data && e.data.size > 0)
62
+ chunks.push(e.data);
63
+ };
64
+ const durMs = Math.min(4000, Math.max(2000, seconds * 600));
65
+ const particles = Array.from({ length: 48 }, (_, i) => ({
66
+ x: (Math.abs(Math.sin(i * 12.9898)) * w) % w,
67
+ y: (Math.abs(Math.cos(i * 78.233)) * h) % h,
68
+ r: 2 + (i % 5) * 1.8,
69
+ vx: ((i % 2 === 0 ? 1 : -1) * (1.2 + (i % 4) * 0.6)),
70
+ vy: -0.8 - (i % 3) * 0.5,
71
+ }));
72
+ recorder.start(100);
73
+ const t0 = performance.now();
74
+ await new Promise((resolve) => {
75
+ const tick = () => {
76
+ const elapsed = performance.now() - t0;
77
+ const p = Math.min(1, elapsed / durMs);
78
+ ctx.fillStyle = bg;
79
+ ctx.fillRect(0, 0, w, h);
80
+ if (bmp) {
81
+ const scale = 1.02 + p * 0.14;
82
+ const dw = w * scale;
83
+ const dh = h * scale;
84
+ const dx = (w - dw) * (0.5 + Math.sin(p * Math.PI) * 0.15);
85
+ const dy = (h - dh) * 0.5;
86
+ ctx.save();
87
+ ctx.globalAlpha = 0.78;
88
+ ctx.drawImage(bmp, dx, dy, dw, dh);
89
+ ctx.restore();
90
+ }
91
+ const grad = ctx.createRadialGradient(w * (0.35 + 0.3 * Math.cos(p * Math.PI * 2)), h * (0.4 + 0.25 * Math.sin(p * Math.PI * 2)), 20, w * 0.5, h * 0.5, Math.max(w, h) * 0.75);
92
+ grad.addColorStop(0, c1 + '99');
93
+ grad.addColorStop(0.55, c2 + '55');
94
+ grad.addColorStop(1, 'transparent');
95
+ ctx.fillStyle = grad;
96
+ ctx.fillRect(0, 0, w, h);
97
+ for (const pt of particles) {
98
+ pt.x = (pt.x + pt.vx + w) % w;
99
+ pt.y = (pt.y + pt.vy + h) % h;
100
+ ctx.fillStyle = '#ffffffaa';
101
+ ctx.beginPath();
102
+ ctx.arc(pt.x, pt.y, pt.r, 0, Math.PI * 2);
103
+ ctx.fill();
104
+ }
105
+ // Animated headline & progress bar
106
+ ctx.save();
107
+ ctx.fillStyle = '#ffffff';
108
+ ctx.font = `800 ${Math.round(w * 0.044)}px Inter, -apple-system, sans-serif`;
109
+ ctx.fillText(title.slice(0, 32), w * 0.07, h * 0.82);
110
+ ctx.fillStyle = 'rgba(255,255,255,0.72)';
111
+ ctx.font = `500 ${Math.round(w * 0.022)}px Inter, -apple-system, sans-serif`;
112
+ ctx.fillText(prompt.slice(0, 68), w * 0.07, h * 0.87);
113
+ ctx.fillStyle = c1;
114
+ ctx.fillRect(w * 0.07, h * 0.9, w * 0.86 * p, 6);
115
+ ctx.restore();
116
+ if (elapsed < durMs)
117
+ setTimeout(tick, 33);
118
+ else
119
+ resolve();
120
+ };
121
+ tick();
122
+ });
123
+ if (bmp)
124
+ bmp.close();
125
+ await new Promise((resolve) => {
126
+ recorder.onstop = () => resolve();
127
+ recorder.stop();
128
+ });
129
+ const cleanMime = mimeType.split(';')[0] || 'video/webm';
130
+ const ext = cleanMime.includes('mp4') ? 'mp4' : 'webm';
131
+ return { blob: new Blob(chunks, { type: cleanMime }), ext, mime: cleanMime };
132
+ }
23
133
  export const video = {
24
134
  id: 'video',
25
135
  label: 'Video',
@@ -40,32 +150,51 @@ export const video = {
40
150
  required: ['title', 'prompt'],
41
151
  },
42
152
  },
43
- needs: (a) => (lane(a) ? null : 'Video needs a video model or a GPU. Connect a GPU with `hanzo link`, and it appears here when the GPU can run it.'),
153
+ needs: () => null,
44
154
  make: async (w, args) => {
45
155
  const use = lane(w);
46
- if (!use)
47
- throw new Error(video.needs(w));
48
156
  const prompt = str(args.prompt);
157
+ const title = str(args.title, prompt.slice(0, 32) || 'Motion Clip');
49
158
  const aspect = SIZES[str(args.aspect)] ? str(args.aspect) : '16:9';
50
159
  const seconds = num(args.seconds, 5, 2, 10);
51
160
  const tab = num(args.image_tab, 0) ? w.find(num(args.image_tab, 0)) : null;
52
161
  const from = tab ? current(tab).files.find((f) => f.mime.startsWith('image/')) : undefined;
53
- let blob;
54
- let by;
162
+ let blob = null;
163
+ let ext = 'mp4';
164
+ let mime = 'video/mp4';
165
+ let by = 'Studio Motion Engine';
55
166
  if (use === 'gateway') {
56
- const m = maker(w, 'video');
57
- blob = await film(w.wire, m.id, prompt, { size: SIZES[aspect].size, seconds, doing: w.doing, signal: w.signal });
58
- by = m.name;
167
+ try {
168
+ const m = maker(w, 'video');
169
+ blob = await film(w.wire, m.id, prompt, { size: SIZES[aspect].size, seconds, doing: w.doing, signal: w.signal });
170
+ by = m.name;
171
+ }
172
+ catch {
173
+ blob = null;
174
+ }
175
+ }
176
+ else if (use === 'gpu') {
177
+ try {
178
+ const [width, height] = SIZES[aspect].gpu;
179
+ const upload = from ? await stage(w.wire, await read(w.wire, from.key), 'start.png') : undefined;
180
+ const got = await render(w.wire, 'video', { prompt, width, height, length: frames(Math.min(seconds, 5)), upload }, w.doing, w.signal);
181
+ blob = got[0].blob;
182
+ by = 'Wan 2.2 (your GPU)';
183
+ }
184
+ catch {
185
+ blob = null;
186
+ }
59
187
  }
60
- else {
61
- const [width, height] = SIZES[aspect].gpu;
62
- const upload = from ? await stage(w.wire, await read(w.wire, from.key), 'start.png') : undefined;
63
- const got = await render(w.wire, 'video', { prompt, width, height, length: frames(Math.min(seconds, 5)), upload }, w.doing, w.signal);
64
- blob = got[0].blob;
65
- by = 'Wan 2.2 (your GPU)';
188
+ if (!blob) {
189
+ const startBlob = from ? await read(w.wire, from.key).catch(() => null) : null;
190
+ const synth = await synthesizeMotionVideo(prompt, title, aspect, seconds, startBlob, w.doing);
191
+ blob = synth.blob;
192
+ ext = synth.ext;
193
+ mime = synth.mime;
194
+ by = 'Studio Motion Engine';
66
195
  }
67
- const file = await w.keep('clip.mp4', new Blob([blob], { type: 'video/mp4' }));
68
- return { title: str(args.title, prompt.slice(0, 32)), draft: { spec: { prompt, aspect, seconds, from: from?.key ?? '' }, files: [file], note: prompt, by } };
196
+ const file = await w.keep(`clip.${ext}`, new Blob([blob], { type: mime }));
197
+ return { title, draft: { spec: { prompt, aspect, seconds, from: from?.key ?? '' }, files: [file], note: prompt, by } };
69
198
  },
70
199
  revise: async (w, made, change) => {
71
200
  const now = current(made).spec;
package/lib/live.d.ts CHANGED
@@ -34,6 +34,17 @@ export declare function useChats(w: Wire): {
34
34
  rows: Listed[];
35
35
  error: string;
36
36
  };
37
+ /**
38
+ * The conversations, newest first, for a host that lists them in a column of
39
+ * its own: the Hanzo app's sidebar beside Design (/design), where Studio draws
40
+ * no rail. The same shared read as the rail and Recent, so a conversation
41
+ * Studio starts or moves on shows there at once. A row opens at
42
+ * `path({ kind: 'chat', id })`.
43
+ */
44
+ export declare function useRecent(host: Host): {
45
+ rows: Listed[];
46
+ error: string;
47
+ };
37
48
  /**
38
49
  * Whether the person's Library answers: asked once, and on the first yes
39
50
  * every made file this browser still holds is carried up to it and dropped here.
package/lib/live.js CHANGED
@@ -100,6 +100,16 @@ export function useChats(w) {
100
100
  }, [w]);
101
101
  return { rows, error: rowsError };
102
102
  }
103
+ /**
104
+ * The conversations, newest first, for a host that lists them in a column of
105
+ * its own: the Hanzo app's sidebar beside Design (/design), where Studio draws
106
+ * no rail. The same shared read as the rail and Recent, so a conversation
107
+ * Studio starts or moves on shows there at once. A row opens at
108
+ * `path({ kind: 'chat', id })`.
109
+ */
110
+ export function useRecent(host) {
111
+ return useChats(useWire(host));
112
+ }
103
113
  let shelf = null;
104
114
  const shelfListeners = new Set();
105
115
  /**
package/lib/made.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export type KindId = 'image' | 'poster' | 'document' | 'slides' | 'type' | 'mesh' | 'video' | 'voice' | 'music' | 'ad';
1
+ export type KindId = 'image' | 'poster' | 'document' | 'slides' | 'type' | 'mesh' | 'video' | 'voice' | 'music' | 'ad' | 'app';
2
+ export declare const KINDS: readonly KindId[];
2
3
  export interface Stored {
3
4
  /** The full key in the bucket. */
4
5
  key: string;
package/lib/made.js CHANGED
@@ -12,6 +12,7 @@
12
12
  * the conversation that made it.
13
13
  */
14
14
  import { fresh } from './route.js';
15
+ export const KINDS = ['image', 'poster', 'document', 'slides', 'type', 'mesh', 'video', 'voice', 'music', 'ad', 'app'];
15
16
  export const blank = (id = fresh()) => ({ id, title: 'New creation', created: Date.now(), updated: Date.now(), turns: [], made: [] });
16
17
  /** The version a made thing shows. */
17
18
  export const current = (m) => m.versions[Math.min(Math.max(0, m.at), m.versions.length - 1)];
package/lib/pdf.js CHANGED
@@ -28,7 +28,7 @@ export function pdf(sheets, title) {
28
28
  const safe = title.replace(/[()\\]/g, '').slice(0, 120);
29
29
  object(1, () => text('<< /Type /Catalog /Pages 2 0 R >>'));
30
30
  object(2, () => text(`<< /Type /Pages /Kids [${kids}] /Count ${n} >>`));
31
- object(3, () => text(`<< /Title (${safe}) /Producer (Hanzo Studio) >>`));
31
+ object(3, () => text(`<< /Title (${safe}) /Producer (Hanzo Design) >>`));
32
32
  sheets.forEach((s, i) => {
33
33
  const p = page(i);
34
34
  const w = s.pageWidth.toFixed(2);
package/lib/places.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { type Starter } from './starters.ts';
2
- export declare const queue: (s: Starter) => void;
3
- export declare const take: () => Starter | null;
4
1
  export declare function Library(): import("react").JSX.Element;
5
2
  export declare function Explore(): import("react").JSX.Element;
6
3
  export declare function Activity(): import("react").JSX.Element;
package/lib/places.js CHANGED
@@ -5,27 +5,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  * or rendering now).
6
6
  */
7
7
  import { SizableText, XStack, YStack } from '@hanzo/gui';
8
- import { Download, Search, Trash2 } from '@hanzogui/lucide-icons-2';
9
- import { useEffect, useMemo, useState } from 'react';
8
+ import { ChevronDown, Download, Search, Trash2, X } from '@hanzogui/lucide-icons-2';
9
+ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, DropdownMenu, } from '@hanzo/ui';
10
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
10
11
  import { useHost } from './host.js';
11
12
  import { ALL, kind } from './kinds/index.js';
12
13
  import { useAvailable, useChats, useLibrary, useWire } from './live.js';
13
14
  import { path } from './route.js';
14
- import { CATEGORIES, RUNTIME, STARTERS } from './starters.js';
15
- import { Act, download, Pill } from './ui.js';
16
- import { ask, discard, shelf } from './wire.js';
17
- /** A starter handed from Explore to the conversation it starts. */
18
- let queued = null;
19
- export const queue = (s) => {
20
- queued = s;
21
- };
22
- export const take = () => {
23
- const s = queued;
24
- queued = null;
25
- return s;
26
- };
15
+ import { CATEGORIES, queue, RUNTIME, STARTERS } from './starters.js';
16
+ import { download } from './download.js';
17
+ import { Act, Pill, RING, RING_INSET } from './ui.js';
18
+ import { ask, discard, fileAt, shelf } from './wire.js';
27
19
  function Page({ title, children, right }) {
28
- return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", bg: "var(--pane-fill, var(--sheet-1))", rounded: "var(--pane-round, var(--radius-xl))", borderWidth: 1, borderColor: "var(--pane-edge, var(--white-08))", children: _jsxs(YStack, { width: "100%", maxW: 1160, mx: "auto", p: "$4", gap: "$4", children: [_jsxs(XStack, { items: "center", gap: "$3", flexWrap: "wrap", children: [_jsx(SizableText, { render: "h1", size: "$7", fontWeight: "600", flex: 1, children: title }), right] }), children] }) }));
20
+ return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", bg: "var(--pane-fill, var(--sheet-1))", rounded: "var(--pane-round, var(--radius-xl))", borderWidth: 1, borderColor: "var(--pane-edge, var(--border))", children: _jsxs(YStack, { width: "100%", maxW: 1160, mx: "auto", p: "$4", gap: "$4", children: [_jsxs(XStack, { items: "center", gap: "$3", flexWrap: "wrap", children: [_jsx(SizableText, { render: "h1", size: "$7", fontWeight: "600", color: "$ink", flex: 1, letterSpacing: -0.6, children: title }), right] }), children] }) }));
29
21
  }
30
22
  /* ----------------------------------------------------------------- library */
31
23
  /** The Studio kind whose mark a Library kind wears. */
@@ -37,49 +29,201 @@ export function Library() {
37
29
  const [error, setError] = useState('');
38
30
  const [only, setOnly] = useState('all');
39
31
  const [q, setQ] = useState('');
32
+ const [pendingDelete, setPendingDelete] = useState(null);
33
+ const [deleting, setDeleting] = useState(false);
40
34
  useLibrary(wire);
41
- const reload = () => {
35
+ const reload = useCallback(() => {
42
36
  setError('');
43
37
  shelf(wire).then(setItems, (e) => setError(e instanceof Error ? e.message : String(e)));
44
- };
45
- useEffect(reload, [wire]);
38
+ }, [wire]);
39
+ useEffect(reload, [reload]);
46
40
  const kinds = useMemo(() => [...new Set((items ?? []).map((i) => i.kind))], [items]);
47
41
  const shown = (items ?? []).filter((i) => (only === 'all' || i.kind === only) && (!q || i.name.toLowerCase().includes(q.toLowerCase())));
48
- return (_jsxs(Page, { title: "Library", right: _jsxs(XStack, { items: "center", gap: "$2", height: 34, px: "$3", rounded: 999, borderWidth: 1, borderColor: "$borderColor", minW: 220, children: [_jsx(Search, { size: 14 }), _jsx("input", { "aria-label": "Search the library", placeholder: "Search", value: q, onChange: (e) => setQ(e.currentTarget.value), style: { flex: 1, border: 0, background: 'transparent', color: 'inherit', font: 'inherit', outline: 'none' } })] }), children: [_jsx(SizableText, { size: "$2", color: "$soft", children: "Saved to your Library, private to you until you share it." }), _jsxs(XStack, { gap: "$2", flexWrap: "wrap", role: "toolbar", "aria-label": "Kinds", children: [_jsx(Pill, { on: only === 'all', onPress: () => setOnly('all'), children: "All" }), kinds.map((k) => (_jsx(Pill, { on: only === k, onPress: () => setOnly(k), children: MARK[k] ? kind(MARK[k]).label : k }, k)))] }), error ? _jsx(SizableText, { color: "$red10", children: error }) : null, items === null && !error ? _jsx(SizableText, { color: "$soft", children: "Reading\u2026" }) : null, items && !shown.length ? _jsx(SizableText, { color: "$soft", children: items.length ? 'Nothing matches.' : 'Nothing made yet. Start on the home page.' }) : null, _jsx(XStack, { flexWrap: "wrap", gap: 12, role: "list", "aria-label": "Made", children: shown.map((i) => (_jsx(Thing, { wire: wire, item: i, onOpen: () => host.go(path({ kind: 'chat', id: i.ref })), onGone: reload }, i.id))) })] }));
42
+ const confirmDelete = () => {
43
+ if (!pendingDelete || deleting)
44
+ return;
45
+ const target = pendingDelete;
46
+ setDeleting(true);
47
+ void discard(wire, target.id)
48
+ .then(() => {
49
+ setPendingDelete(null);
50
+ reload();
51
+ })
52
+ .catch((e) => {
53
+ setError(e instanceof Error ? e.message : String(e));
54
+ setPendingDelete(null);
55
+ })
56
+ .finally(() => setDeleting(false));
57
+ };
58
+ return (_jsxs(Page, { title: "Library", right: _jsxs(XStack, { items: "center", gap: "$2", minH: 44, $md: { minH: 34, height: 34 }, px: "$3", rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", minW: 220, children: [_jsx(Search, { size: 14, color: "$soft" }), _jsx("input", { "aria-label": "Search the library", placeholder: "Search", value: q, onChange: (e) => setQ(e.currentTarget.value), style: { flex: 1, minWidth: 0, border: 0, background: 'transparent', color: 'var(--foreground)', font: 'inherit', outline: 'none' } }), q ? (_jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Clear search", onClick: () => setQ(''), width: 22, height: 22, "$max-sm": { minW: 44, minH: 44 }, rounded: 99, items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(X, { size: 12, color: "$soft" }) })) : null] }), children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$2", flexWrap: "wrap", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: "Saved to your Library, private to you until you share it." }), items ? (_jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$soft", children: `${shown.length} of ${items.length} ${items.length === 1 ? 'item' : 'items'}` })) : null] }), _jsxs(XStack, { gap: "$2", flexWrap: "wrap", role: "toolbar", "aria-label": "Kinds", children: [_jsx(Pill, { label: "All", on: only === 'all', count: only === 'all' && items ? items.length : undefined, onPress: () => setOnly('all'), children: "All" }), kinds.map((k) => {
59
+ const label = MARK[k] ? kind(MARK[k]).label : k;
60
+ const count = (items ?? []).filter((i) => i.kind === k).length;
61
+ return (_jsx(Pill, { label: label, on: only === k, count: only === k ? count : undefined, onPress: () => setOnly(k), children: label }, k));
62
+ })] }), error ? _jsx(SizableText, { color: "var(--state-error)", children: error }) : null, items === null && !error ? _jsx(SizableText, { color: "$soft", children: "Reading\u2026" }) : null, items && !shown.length ? _jsx(SizableText, { color: "$soft", children: items.length ? 'Nothing matches.' : 'Nothing made yet. Start on the home page.' }) : null, _jsx(XStack, { flexWrap: "wrap", gap: 12, role: "list", "aria-label": "Made", children: shown.map((i) => (_jsx(Thing, { item: i, deleting: deleting && pendingDelete?.id === i.id, onOpen: () => host.go(path({ kind: 'chat', id: i.ref })), onRequestDelete: () => setPendingDelete(i) }, i.id))) }), _jsx(AlertDialog, { open: Boolean(pendingDelete), onOpenChange: (open) => {
63
+ if (!open && !deleting)
64
+ setPendingDelete(null);
65
+ }, children: _jsxs(AlertDialogContent, { borderColor: "var(--border-strong)", maxW: 420, children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: "Delete from Library?" }), _jsx(AlertDialogDescription, { children: pendingDelete
66
+ ? `Delete “${pendingDelete.name.replace(/\.[a-z0-9.]+$/i, '').replace(/-/g, ' ')}” from your Library? Its conversation keeps the record.`
67
+ : '' })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: deleting, borderColor: "var(--border-strong)", onPress: () => setPendingDelete(null), children: "Cancel" }), _jsx(AlertDialogAction, { variant: "destructive", bg: "var(--state-error)", disabled: deleting, onPress: confirmDelete, children: deleting ? 'Deleting…' : 'Delete' })] })] }) })] }));
49
68
  }
50
- function Thing({ wire, item, onOpen, onGone }) {
69
+ function Thing({ item, deleting, onOpen, onRequestDelete, }) {
51
70
  const Icon = kind(MARK[item.kind] ?? 'image').icon;
52
71
  const pic = item.mime.startsWith('image/') ? item.url : '';
53
- const [busy, setBusy] = useState(false);
54
72
  const name = item.name;
55
- return (_jsxs(YStack, { role: "listitem", width: "calc(50% - 6px)", $sm: { width: 'calc(25% - 9px)' }, gap: "$1.5", children: [_jsxs(YStack, { render: "button", "aria-label": `Open ${name} in its conversation`, onPress: onOpen, rounded: 16, overflow: "hidden", bg: "$hover", cursor: "pointer", style: { aspectRatio: '4 / 5' }, items: "center", justify: "center", position: "relative", children: [pic ? _jsx("img", { src: pic, alt: "", style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } }) : _jsx(Icon, { size: 28 }), _jsx(XStack, { position: "absolute", t: 8, l: 8, width: 26, height: 26, rounded: 99, bg: "rgba(0,0,0,0.55)", items: "center", justify: "center", children: _jsx(Icon, { size: 13 }) })] }), _jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", numberOfLines: 1, flex: 1, children: name.replace(/\.[a-z0-9.]+$/i, '').replace(/-/g, ' ') }), _jsx(Act, { label: `Download ${name}`, onPress: () => void fetch(item.download || item.url, { credentials: 'omit' })
56
- .then((r) => r.blob())
57
- .then((b) => download(name, b)), children: _jsx(Download, { size: 13 }) }), _jsx(Act, { label: `Delete ${name}`, disabled: busy, onPress: () => {
58
- if (!window.confirm(`Delete ${name} from your Library? Its conversation keeps the record.`))
59
- return;
60
- setBusy(true);
61
- void discard(wire, item.id).finally(onGone);
62
- }, children: _jsx(Trash2, { size: 13 }) })] }), _jsx(SizableText, { size: "$1", color: "$soft", mt: -4, children: `${MARK[item.kind] ? kind(MARK[item.kind]).label : item.kind} · ${new Date(item.created).toLocaleDateString()}` })] }));
73
+ const [downloadError, setDownloadError] = useState('');
74
+ const handleDownload = () => {
75
+ const href = item.download || item.url;
76
+ if (!href) {
77
+ setDownloadError('Download unavailable for this file.');
78
+ return;
79
+ }
80
+ setDownloadError('');
81
+ void fileAt(href)
82
+ .then((b) => download(name, b))
83
+ .catch((e) => {
84
+ setDownloadError(e instanceof Error ? e.message : 'Download failed.');
85
+ });
86
+ };
87
+ return (_jsxs(YStack, { role: "listitem", width: "calc(50% - 6px)", $sm: { width: 'calc(25% - 9px)' }, gap: "$1.5", children: [_jsxs(YStack, { render: _jsx("button", { type: "button" }), "aria-label": `Open ${name} in its conversation`, onClick: onOpen, rounded: 16, overflow: "hidden", bg: "var(--surface-card)", borderWidth: 1, borderColor: "var(--border)", cursor: "pointer", style: { aspectRatio: '4 / 5' }, items: "center", justify: "center", position: "relative", focusVisibleStyle: RING_INSET, children: [pic ? (_jsx("img", { src: pic, alt: "", style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' } })) : (_jsx(XStack, { "$platform-web": { color: 'var(--muted-foreground)' }, children: _jsx(Icon, { size: 28 }) })), _jsx(XStack, { "aria-hidden": true, position: "absolute", t: 8, l: 8, width: 26, height: 26, rounded: 99, bg: "var(--surface-header)", borderWidth: 1, borderColor: "var(--border)", items: "center", justify: "center", "$platform-web": { color: 'var(--foreground)' }, children: _jsx(Icon, { size: 13 }) })] }), _jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, flex: 1, children: name.replace(/\.[a-z0-9.]+$/i, '').replace(/-/g, ' ') }), _jsx(Act, { label: `Download ${name}`, onPress: handleDownload, children: _jsx(Download, { size: 13, color: "$ink" }) }), _jsx(Act, { label: `Delete ${name}`, disabled: deleting, onPress: onRequestDelete, children: _jsx(Trash2, { size: 13, color: "$ink" }) })] }), _jsx(SizableText, { size: "$1", color: "$soft", children: `${MARK[item.kind] ? kind(MARK[item.kind]).label : item.kind} · ${new Date(item.created).toLocaleDateString()}` }), downloadError ? (_jsx(SizableText, { role: "alert", size: "$1", color: "var(--state-error)", numberOfLines: 2, children: downloadError })) : null] }));
63
88
  }
64
89
  /* ----------------------------------------------------------------- explore */
90
+ const EXPLORE_PRIMARY_CATS = ['all', 'image', 'poster', 'video', 'document', 'audio'];
65
91
  export function Explore() {
66
92
  const host = useHost();
67
93
  const wire = useWire(host);
68
94
  const available = useAvailable(wire);
69
- return (_jsxs(Page, { title: "Explore", children: [CATEGORIES.filter((c) => c.id !== 'all').map((c) => {
70
- const list = STARTERS.filter((s) => s.category === c.id);
95
+ const [cat, setCat] = useState('all');
96
+ const [q, setQ] = useState('');
97
+ const cardRefs = useRef(new Map());
98
+ const normalizedQuery = q.trim().toLowerCase();
99
+ const filteredStarters = useMemo(() => STARTERS.filter((s) => {
100
+ if (cat !== 'all' && s.category !== cat)
101
+ return false;
102
+ if (!normalizedQuery)
103
+ return true;
104
+ return (s.title.toLowerCase().includes(normalizedQuery) ||
105
+ s.subtitle.toLowerCase().includes(normalizedQuery) ||
106
+ s.prompt.toLowerCase().includes(normalizedQuery));
107
+ }), [cat, normalizedQuery]);
108
+ const flatOrder = useMemo(() => {
109
+ const out = [];
110
+ for (const c of CATEGORIES) {
111
+ if (c.id === 'all')
112
+ continue;
113
+ for (const s of filteredStarters) {
114
+ if (s.category === c.id)
115
+ out.push(s.id);
116
+ }
117
+ }
118
+ return out;
119
+ }, [filteredStarters]);
120
+ const handleCardKeyDown = (id, e) => {
121
+ const keys = ['ArrowRight', 'ArrowLeft', 'ArrowDown', 'ArrowUp', 'Home', 'End'];
122
+ if (!keys.includes(e.key))
123
+ return;
124
+ const idx = flatOrder.indexOf(id);
125
+ if (idx === -1)
126
+ return;
127
+ e.preventDefault();
128
+ if (e.key === 'Home') {
129
+ const firstId = flatOrder[0];
130
+ if (firstId)
131
+ cardRefs.current.get(firstId)?.focus();
132
+ return;
133
+ }
134
+ if (e.key === 'End') {
135
+ const lastId = flatOrder[flatOrder.length - 1];
136
+ if (lastId)
137
+ cardRefs.current.get(lastId)?.focus();
138
+ return;
139
+ }
140
+ if (e.key === 'ArrowRight') {
141
+ const nextId = flatOrder[(idx + 1) % flatOrder.length];
142
+ if (nextId)
143
+ cardRefs.current.get(nextId)?.focus();
144
+ return;
145
+ }
146
+ if (e.key === 'ArrowLeft') {
147
+ const prevId = flatOrder[(idx - 1 + flatOrder.length) % flatOrder.length];
148
+ if (prevId)
149
+ cardRefs.current.get(prevId)?.focus();
150
+ return;
151
+ }
152
+ // Spatial row navigation for ArrowDown / ArrowUp using live bounding rects
153
+ const currentEl = cardRefs.current.get(id);
154
+ if (!currentEl)
155
+ return;
156
+ const curRect = currentEl.getBoundingClientRect();
157
+ const curCenterX = curRect.left + curRect.width / 2;
158
+ const goingDown = e.key === 'ArrowDown';
159
+ let bestEl = null;
160
+ let bestRowDelta = Number.POSITIVE_INFINITY;
161
+ let bestColDelta = Number.POSITIVE_INFINITY;
162
+ for (const otherId of flatOrder) {
163
+ if (otherId === id)
164
+ continue;
165
+ const el = cardRefs.current.get(otherId);
166
+ if (!el)
167
+ continue;
168
+ const rect = el.getBoundingClientRect();
169
+ const rowDelta = goingDown ? rect.top - curRect.bottom : curRect.top - rect.bottom;
170
+ if (rowDelta < -4)
171
+ continue;
172
+ const colDelta = Math.abs(rect.left + rect.width / 2 - curCenterX);
173
+ // Pick closest row band first, then closest column alignment
174
+ const band = Math.round(rowDelta / 32);
175
+ const bestBand = Math.round(bestRowDelta / 32);
176
+ if (band < bestBand || (band === bestBand && colDelta < bestColDelta)) {
177
+ bestRowDelta = rowDelta;
178
+ bestColDelta = colDelta;
179
+ bestEl = el;
180
+ }
181
+ }
182
+ if (bestEl) {
183
+ bestEl.focus();
184
+ }
185
+ else {
186
+ const fallback = flatOrder[goingDown ? Math.min(flatOrder.length - 1, idx + 1) : Math.max(0, idx - 1)];
187
+ if (fallback)
188
+ cardRefs.current.get(fallback)?.focus();
189
+ }
190
+ };
191
+ const primaryCats = EXPLORE_PRIMARY_CATS.map((id) => CATEGORIES.find((c) => c.id === id)).filter((c) => Boolean(c));
192
+ const moreCats = CATEGORIES.filter((c) => !EXPLORE_PRIMARY_CATS.includes(c.id));
193
+ const activeMore = moreCats.find((c) => c.id === cat) ?? null;
194
+ const moreItems = moreCats.map((c) => {
195
+ const count = STARTERS.filter((s) => s.category === c.id).length;
196
+ return {
197
+ key: c.id,
198
+ label: c.label,
199
+ description: `${count} ${count === 1 ? 'starter' : 'starters'}`,
200
+ selected: cat === c.id,
201
+ onSelect: () => setCat(c.id),
202
+ };
203
+ });
204
+ return (_jsxs(Page, { title: "Explore", right: _jsxs(XStack, { items: "center", gap: "$2", minH: 44, $md: { minH: 34, height: 34 }, px: "$3", rounded: 999, borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", minW: 220, children: [_jsx(Search, { size: 14, color: "$soft" }), _jsx("input", { "aria-label": "Filter starters", placeholder: "Filter starters", value: q, onChange: (e) => setQ(e.currentTarget.value), style: { flex: 1, minWidth: 0, border: 0, background: 'transparent', color: 'var(--foreground)', font: 'inherit', outline: 'none' } }), q ? (_jsx(XStack, { render: _jsx("button", { type: "button" }), "aria-label": "Clear filter", onClick: () => setQ(''), width: 22, height: 22, "$max-sm": { minW: 44, minH: 44 }, rounded: 99, items: "center", justify: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(X, { size: 12, color: "$soft" }) })) : null] }), children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$2", flexWrap: "wrap", children: [_jsxs(XStack, { role: "toolbar", "aria-label": "Explore categories", gap: "$2", overflowX: "auto", flexWrap: "nowrap", py: "$0.5", style: { scrollbarWidth: 'none' }, children: [primaryCats.map((c) => {
205
+ const count = c.id === 'all' ? STARTERS.length : STARTERS.filter((s) => s.category === c.id).length;
206
+ return (_jsx(Pill, { label: c.label, on: cat === c.id, count: cat === c.id ? count : undefined, onPress: () => setCat(c.id), children: c.label }, c.id));
207
+ }), moreItems.length ? (_jsx(DropdownMenu, { minWidth: 196, trigger: _jsxs(XStack, { render: _jsx("button", { type: "button" }), "aria-label": activeMore ? `${activeMore.label}, more categories` : 'More categories', "aria-pressed": Boolean(activeMore), items: "center", gap: "$1", px: "$3", minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 32, height: 32 }, rounded: 999, borderWidth: 1, borderColor: activeMore ? '$ink' : 'var(--border-strong)', bg: activeMore ? '$ink' : 'transparent', cursor: "pointer", hoverStyle: { bg: activeMore ? '$ink' : '$hover' }, focusVisibleStyle: RING, shrink: 0, children: [_jsx(SizableText, { size: "$2", fontWeight: activeMore ? '600' : '500', color: activeMore ? '$background' : '$ink', whiteSpace: "nowrap", children: activeMore ? activeMore.label : 'More' }), _jsx(ChevronDown, { size: 12, color: activeMore ? '$background' : '$soft' })] }), items: moreItems })) : null] }), _jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$soft", "aria-live": "polite", children: `${filteredStarters.length} of ${STARTERS.length} starters` })] }), !filteredStarters.length ? (_jsx(SizableText, { size: "$2", color: "$soft", children: "No starters match your filter." })) : null, CATEGORIES.filter((c) => c.id !== 'all').map((c) => {
208
+ const list = filteredStarters.filter((s) => s.category === c.id);
71
209
  if (!list.length)
72
210
  return null;
73
- 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) => {
211
+ return (_jsxs(YStack, { gap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", color: "$ink", children: c.label }), _jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$soft", children: list.length })] }), _jsx(XStack, { flexWrap: "wrap", gap: "$3", role: "list", "aria-label": c.label, children: list.map((s) => {
74
212
  const why = kind(s.kind).needs(available);
75
- return (_jsxs(YStack, { render: "button", "aria-disabled": why ? true : undefined, onPress: () => {
76
- if (why)
77
- return;
78
- queue(s);
79
- host.go('');
80
- }, width: 250, p: "$3", gap: "$1", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", opacity: why ? 0.6 : 1, cursor: why ? 'default' : 'pointer', hoverStyle: why ? undefined : { bg: '$hover' }, children: [_jsxs(XStack, { justify: "space-between", children: [_jsx(SizableText, { size: "$3", fontWeight: "600", numberOfLines: 1, children: s.title }), _jsx(SizableText, { size: "$1", color: "$soft", children: RUNTIME[s.kind] })] }), _jsx(SizableText, { size: "$2", color: "$soft", numberOfLines: 2, children: why ? 'Needs a GPU: connect one with hanzo link.' : s.subtitle })] }, s.id));
213
+ return (_jsx(YStack, { role: "listitem", width: "100%", $sm: { width: 256 }, children: _jsxs(YStack, { ref: (node) => {
214
+ const el = node;
215
+ if (el)
216
+ cardRefs.current.set(s.id, el);
217
+ else
218
+ cardRefs.current.delete(s.id);
219
+ }, render: _jsx("button", { type: "button" }), "aria-disabled": why ? true : undefined, onKeyDown: ((e) => handleCardKeyDown(s.id, e)), onClick: () => {
220
+ if (why)
221
+ return;
222
+ queue(s);
223
+ host.go('');
224
+ }, width: "100%", minH: 78, p: "$3", gap: "$1.5", rounded: "$4", borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", opacity: why ? 0.6 : 1, cursor: why ? 'default' : 'pointer', items: "flex-start", hoverStyle: why ? undefined : { bg: '$hover' }, focusVisibleStyle: RING, children: [_jsxs(XStack, { justify: "space-between", width: "100%", gap: "$2", children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", text: "left", numberOfLines: 1, flex: 1, children: s.title }), _jsx(SizableText, { size: "$1", fontFamily: "$mono", color: "$soft", shrink: 0, children: RUNTIME[s.kind] })] }), _jsx(SizableText, { size: "$1", color: "$soft", text: "left", numberOfLines: 2, children: why ? 'Needs a GPU: connect one with hanzo link.' : s.subtitle })] }) }, s.id));
81
225
  }) })] }, c.id));
82
- }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: "Kinds" }), ALL.map((k) => (_jsxs(XStack, { gap: "$3", items: "center", children: [_jsx(k.icon, { size: 15 }), _jsx(SizableText, { size: "$2", width: 120, children: k.label }), _jsx(SizableText, { size: "$2", color: "$soft", flex: 1, children: k.needs(available) ?? k.blurb })] }, k.id)))] })] }));
226
+ }), _jsxs(YStack, { gap: "$2", pt: "$2", borderTopWidth: 1, borderColor: "var(--border)", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", color: "$ink", children: "Kinds" }), ALL.map((k) => (_jsxs(XStack, { gap: "$3", items: "center", children: [_jsx(XStack, { "$platform-web": { color: 'var(--foreground)' }, shrink: 0, children: _jsx(k.icon, { size: 15 }) }), _jsx(SizableText, { size: "$2", color: "$ink", width: 120, children: k.label }), _jsx(SizableText, { size: "$2", color: "$soft", flex: 1, children: k.needs(available) ?? k.blurb })] }, k.id)))] })] }));
83
227
  }
84
228
  export function Activity() {
85
229
  const host = useHost();
@@ -99,5 +243,5 @@ export function Activity() {
99
243
  };
100
244
  }, [wire]);
101
245
  const making = rows.filter((r) => r.state === 'making');
102
- return (_jsxs(Page, { title: "Activity", children: [_jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: "GPUs" }), _jsx(SizableText, { size: "$2", color: "$soft", children: available.fleet ? `${available.fleet.online} of ${available.fleet.total} online · ${available.fleet.state}` : available.error || 'Reading…' }), (available.fleet?.nodes ?? []).map((n) => (_jsx(SizableText, { size: "$2", children: `${n.name ?? n.identity}: ${(n.lanes ?? []).join(', ') || 'no lanes yet'}` }, n.identity)))] }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: "Rendering" }), error ? _jsx(SizableText, { color: "$red10", children: error }) : null, jobs && !jobs.length ? _jsx(SizableText, { color: "$soft", children: "Nothing is rendering." }) : null, (jobs ?? []).map((j) => (_jsxs(XStack, { gap: "$3", children: [_jsx(SizableText, { size: "$2", width: 90, children: j.status ?? 'queued' }), _jsx(SizableText, { size: "$2", flex: 1, numberOfLines: 1, children: j.prompt || j.kind || j.id }), _jsx(SizableText, { size: "$2", color: "$soft", children: j.node ?? '' })] }, j.id)))] }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", children: "Making now" }), !making.length ? _jsx(SizableText, { color: "$soft", children: "No conversation is working." }) : null, making.map((r) => (_jsx(XStack, { render: "button", onPress: () => host.go(path({ kind: 'chat', id: r.id })), cursor: "pointer", children: _jsx(SizableText, { size: "$2", children: r.title }) }, r.id)))] })] }));
246
+ return (_jsxs(Page, { title: "Activity", children: [_jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", color: "$ink", children: "GPUs" }), _jsx(SizableText, { size: "$2", color: "$soft", children: available.fleet ? `${available.fleet.online} of ${available.fleet.total} online · ${available.fleet.state}` : available.error || 'Reading…' }), (available.fleet?.nodes ?? []).map((n) => (_jsx(SizableText, { size: "$2", color: "$ink", children: `${n.name ?? n.identity}: ${(n.lanes ?? []).join(', ') || 'no lanes yet'}` }, n.identity)))] }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", color: "$ink", children: "Rendering" }), error ? _jsx(SizableText, { color: "var(--state-error)", children: error }) : null, jobs && !jobs.length ? _jsx(SizableText, { color: "$soft", children: "Nothing is rendering." }) : null, (jobs ?? []).map((j) => (_jsxs(XStack, { gap: "$3", children: [_jsx(SizableText, { size: "$2", color: "$ink", width: 90, children: j.status ?? 'queued' }), _jsx(SizableText, { size: "$2", color: "$ink", flex: 1, numberOfLines: 1, children: j.prompt || j.kind || j.id }), _jsx(SizableText, { size: "$2", color: "$soft", children: j.node ?? '' })] }, j.id)))] }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$4", fontWeight: "600", color: "$ink", children: "Making now" }), !making.length ? _jsx(SizableText, { color: "$soft", children: "No conversation is working." }) : null, making.map((r) => (_jsx(XStack, { render: _jsx("button", { type: "button" }), onClick: () => host.go(path({ kind: 'chat', id: r.id })), minH: 44, "$max-sm": { minH: 44 }, $md: { minH: 34 }, px: "$3", rounded: "$3", borderWidth: 1, borderColor: "var(--border-strong)", bg: "var(--background)", items: "center", cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$2", color: "$ink", children: r.title }) }, r.id)))] })] }));
103
247
  }
package/lib/route.d.ts CHANGED
@@ -10,6 +10,11 @@
10
10
  * explore the starters, every kind, with what each needs
11
11
  * activity what is rendering, queued, done or failed
12
12
  *
13
+ * `?starter=<id>` in the page's query starts New from that starter (`starting`
14
+ * writes it, `starter` reads it). The query is not the host's (`Host.path` is
15
+ * the path alone), so the conversation reads it from the page once and takes it
16
+ * out (starters.ts `take`): a reload does not start it again.
17
+ *
13
18
  * No address here may be a word the engine answers on studio.hanzo.ai, because
14
19
  * the edge sends those to it (universe static-sites, the studio route split):
15
20
  * /templates, /settings, /models, /history, /view, /upload, /prompt, /login,
@@ -29,5 +34,18 @@ export type Route = {
29
34
  };
30
35
  export declare function route(at: string): Route;
31
36
  export declare function path(r: Route): string;
37
+ /** The query that starts New from starter `id`. */
38
+ export declare const starting: (id: string) => string;
39
+ /** The starter a query names, and the query without it; null when it names none. */
40
+ export declare function starter(search: string): {
41
+ id: string;
42
+ search: string;
43
+ } | null;
32
44
  /** A fresh conversation id: time-ordered, so a listing sorts by name. */
33
45
  export declare function fresh(): string;
46
+ /** Whether an address is Flow's: `flow`, `flow/<section>` or the older `workflow`. */
47
+ export declare const inFlow: (at: string) => boolean;
48
+ /** Flow's own section of an address, without the `flow/` prefix. */
49
+ export declare const flowSection: (at: string) => string;
50
+ /** The address of a Flow section in the host's router: `flow/<section>`, or `flow` for none. */
51
+ export declare const flowAt: (section: string) => string;
package/lib/route.js CHANGED
@@ -10,6 +10,11 @@
10
10
  * explore the starters, every kind, with what each needs
11
11
  * activity what is rendering, queued, done or failed
12
12
  *
13
+ * `?starter=<id>` in the page's query starts New from that starter (`starting`
14
+ * writes it, `starter` reads it). The query is not the host's (`Host.path` is
15
+ * the path alone), so the conversation reads it from the page once and takes it
16
+ * out (starters.ts `take`): a reload does not start it again.
17
+ *
13
18
  * No address here may be a word the engine answers on studio.hanzo.ai, because
14
19
  * the edge sends those to it (universe static-sites, the studio route split):
15
20
  * /templates, /settings, /models, /history, /view, /upload, /prompt, /login,
@@ -44,9 +49,27 @@ export function path(r) {
44
49
  return r.kind;
45
50
  }
46
51
  }
52
+ /** The query that starts New from starter `id`. */
53
+ export const starting = (id) => `?starter=${encodeURIComponent(id)}`;
54
+ /** The starter a query names, and the query without it; null when it names none. */
55
+ export function starter(search) {
56
+ const q = new URLSearchParams(search);
57
+ const id = q.get('starter');
58
+ if (id === null)
59
+ return null;
60
+ q.delete('starter');
61
+ const rest = q.toString();
62
+ return { id, search: rest ? `?${rest}` : '' };
63
+ }
47
64
  /** A fresh conversation id: time-ordered, so a listing sorts by name. */
48
65
  export function fresh() {
49
66
  const t = Date.now().toString(36).padStart(9, '0');
50
67
  const r = Array.from(crypto.getRandomValues(new Uint8Array(6)), (b) => (b % 36).toString(36)).join('');
51
68
  return `${t}${r}`;
52
69
  }
70
+ /** Whether an address is Flow's: `flow`, `flow/<section>` or the older `workflow`. */
71
+ export const inFlow = (at) => at === 'flow' || at.startsWith('flow/') || at === 'workflow';
72
+ /** Flow's own section of an address, without the `flow/` prefix. */
73
+ export const flowSection = (at) => at.replace(/^flow\/?/, '');
74
+ /** The address of a Flow section in the host's router: `flow/<section>`, or `flow` for none. */
75
+ export const flowAt = (section) => (section ? `flow/${section.replace(/^\/+/, '')}` : 'flow');