@hanzo/studio 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE +29 -0
  2. package/NOTICE +68 -0
  3. package/lib/chat/store.d.ts +33 -0
  4. package/lib/chat/store.js +56 -0
  5. package/lib/chat/turn.d.ts +51 -0
  6. package/lib/chat/turn.js +274 -0
  7. package/lib/desk.d.ts +14 -0
  8. package/lib/desk.js +72 -0
  9. package/lib/gpu.d.ts +15 -0
  10. package/lib/gpu.js +41 -0
  11. package/lib/home.d.ts +6 -0
  12. package/lib/home.js +48 -0
  13. package/lib/host.d.ts +12 -0
  14. package/lib/host.js +18 -0
  15. package/lib/index.d.ts +12 -0
  16. package/lib/index.js +11 -0
  17. package/lib/kinds/ad.d.ts +51 -0
  18. package/lib/kinds/ad.js +124 -0
  19. package/lib/kinds/document.d.ts +6 -0
  20. package/lib/kinds/document.js +271 -0
  21. package/lib/kinds/image.d.ts +47 -0
  22. package/lib/kinds/image.js +179 -0
  23. package/lib/kinds/index.d.ts +9 -0
  24. package/lib/kinds/index.js +12 -0
  25. package/lib/kinds/kind.d.ts +113 -0
  26. package/lib/kinds/kind.js +13 -0
  27. package/lib/kinds/mesh/index.d.ts +2 -0
  28. package/lib/kinds/mesh/index.js +76 -0
  29. package/lib/kinds/mesh/viewer.d.ts +7 -0
  30. package/lib/kinds/mesh/viewer.js +79 -0
  31. package/lib/kinds/poster/compose.d.ts +40 -0
  32. package/lib/kinds/poster/compose.js +289 -0
  33. package/lib/kinds/poster/index.d.ts +21 -0
  34. package/lib/kinds/poster/index.js +210 -0
  35. package/lib/kinds/sound.d.ts +6 -0
  36. package/lib/kinds/sound.js +100 -0
  37. package/lib/kinds/type/fonts.d.ts +30 -0
  38. package/lib/kinds/type/fonts.js +111 -0
  39. package/lib/kinds/type/index.d.ts +5 -0
  40. package/lib/kinds/type/index.js +117 -0
  41. package/lib/kinds/type/system.d.ts +164 -0
  42. package/lib/kinds/type/system.js +302 -0
  43. package/lib/kinds/video.d.ts +2 -0
  44. package/lib/kinds/video.js +81 -0
  45. package/lib/live.d.ts +44 -0
  46. package/lib/live.js +128 -0
  47. package/lib/made.d.ts +75 -0
  48. package/lib/made.js +36 -0
  49. package/lib/nav.d.ts +17 -0
  50. package/lib/nav.js +29 -0
  51. package/lib/pdf.d.ts +16 -0
  52. package/lib/pdf.js +53 -0
  53. package/lib/places.d.ts +6 -0
  54. package/lib/places.js +121 -0
  55. package/lib/raster.d.ts +7 -0
  56. package/lib/raster.js +53 -0
  57. package/lib/route.d.ts +33 -0
  58. package/lib/route.js +52 -0
  59. package/lib/starters.d.ts +31 -0
  60. package/lib/starters.js +62 -0
  61. package/lib/studio.d.ts +26 -0
  62. package/lib/studio.js +58 -0
  63. package/lib/talk.d.ts +3 -0
  64. package/lib/talk.js +369 -0
  65. package/lib/ui.d.ts +50 -0
  66. package/lib/ui.js +57 -0
  67. package/lib/use.d.ts +11 -0
  68. package/lib/use.js +35 -0
  69. package/lib/wire.d.ts +239 -0
  70. package/lib/wire.js +478 -0
  71. package/lib/zip.d.ts +9 -0
  72. package/lib/zip.js +60 -0
  73. package/package.json +75 -3
  74. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Hanzo AI, Inc.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/NOTICE ADDED
@@ -0,0 +1,68 @@
1
+ Hanzo Studio (@hanzo/studio)
2
+ Copyright (c) 2026 Hanzo AI, Inc.
3
+ Licensed under the BSD 3-Clause License; see LICENSE.
4
+
5
+ Studio talks to the Hanzo Studio engine (hanzoai/studio-v1, a GPL-3.0 fork of
6
+ ComfyUI) only over HTTP, as a separate program. It contains no code from that
7
+ engine, from the ComfyUI frontend, or from LiteGraph.
8
+
9
+ Third-party software in the built site
10
+ --------------------------------------
11
+
12
+ Each of the following is licensed under the MIT License, whose text follows
13
+ the list. Its copyright notices are reproduced as that license requires.
14
+
15
+ @hanzo/gui, @hanzogui/* (Hanzo GUI), derived from Tamagui
16
+ Copyright (c) 2026-present, Hanzo AI, Inc.
17
+ Copyright (c) 2020 Nate Wienert
18
+ Copyright (c) 2015-present, Nicolas Gallagher.
19
+ Copyright (c) 2015-present, Facebook, Inc.
20
+ Copyright (c) 2021 Radix
21
+ Copyright (c) 2017 Carmelo Pullara
22
+ Copyright (c) 2018 Framer B.V.
23
+
24
+ three (three.js), with its GLTFLoader and OrbitControls
25
+ Copyright (c) 2010-2026 three.js authors
26
+
27
+ react, react-dom
28
+ Copyright (c) Meta Platforms, Inc. and affiliates.
29
+
30
+ react-native-web
31
+ Copyright (c) Nicolas Gallagher.
32
+ Copyright (c) Meta Platforms, Inc. and affiliates.
33
+
34
+ next-themes
35
+ Copyright (c) 2022 Paco Coursey
36
+
37
+ MIT License
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining a copy
40
+ of this software and associated documentation files (the "Software"), to deal
41
+ in the Software without restriction, including without limitation the rights
42
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
+ copies of the Software, and to permit persons to whom the Software is
44
+ furnished to do so, subject to the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be included in
47
+ all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
+ SOFTWARE.
56
+
57
+ Fonts
58
+ -----
59
+
60
+ Zen (@hanzo/font)
61
+ Copyright (c) 2023 Vercel, in collaboration with basement.studio
62
+ Copyright (c) 2026 Hanzo AI, Inc.
63
+ Licensed under the SIL Open Font License, Version 1.1; the license text
64
+ ships beside this file as OFL.txt.
65
+
66
+ The open faces a type system may pair (src/kinds/type/fonts.ts) are each
67
+ SIL OFL 1.1, read from their own OFL.txt in github.com/google/fonts, and are
68
+ loaded from their publisher at run time rather than bundled.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Conversations as stored, and the list of them.
3
+ *
4
+ * chats/<id>.json one conversation, whole
5
+ * chats/index.json every conversation's id, title, time, state and
6
+ * the picture to show for it: the list Recent and
7
+ * the rail read without opening each one
8
+ *
9
+ * The index is rewritten on every save of a conversation; a lost race between
10
+ * two tabs loses only a row's freshness, and `rebuild` lists the folder to
11
+ * write it again from the conversations themselves.
12
+ */
13
+ import { type Chat } from '../made.ts';
14
+ import type { Wire } from '../wire.ts';
15
+ export interface Listed {
16
+ id: string;
17
+ title: string;
18
+ updated: number;
19
+ /** making while a turn works, failed when the last turn failed, else done. */
20
+ state: 'making' | 'done' | 'failed';
21
+ /** A stored picture to show for it. */
22
+ cover?: string;
23
+ /** How many things it made. */
24
+ count: number;
25
+ }
26
+ export declare function listed(c: Chat): Listed;
27
+ export declare function index(w: Wire): Promise<Listed[]>;
28
+ /** Save a conversation, and its row in the index. */
29
+ export declare function keep(w: Wire, c: Chat): Promise<void>;
30
+ export declare const open: (w: Wire, id: string) => Promise<Chat | null>;
31
+ /** Write the index again from the conversations stored. */
32
+ export declare function rebuild(w: Wire): Promise<Listed[]>;
33
+ export declare function forget(w: Wire, id: string): Promise<void>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Conversations as stored, and the list of them.
3
+ *
4
+ * chats/<id>.json one conversation, whole
5
+ * chats/index.json every conversation's id, title, time, state and
6
+ * the picture to show for it: the list Recent and
7
+ * the rail read without opening each one
8
+ *
9
+ * The index is rewritten on every save of a conversation; a lost race between
10
+ * two tabs loses only a row's freshness, and `rebuild` lists the folder to
11
+ * write it again from the conversations themselves.
12
+ */
13
+ import { current } from '../made.js';
14
+ import { list, load, save } from '../wire.js';
15
+ const INDEX = 'chats/index.json';
16
+ export function listed(c) {
17
+ const last = c.turns.at(-1);
18
+ const state = last?.doing ? 'making' : last?.failed ? 'failed' : 'done';
19
+ let cover;
20
+ for (const m of [...c.made].reverse()) {
21
+ const f = current(m).files.find((x) => x.mime.startsWith('image/'));
22
+ if (f) {
23
+ cover = f.key;
24
+ break;
25
+ }
26
+ }
27
+ return { id: c.id, title: c.title, updated: c.updated, state, cover, count: c.made.length };
28
+ }
29
+ export async function index(w) {
30
+ const rows = (await load(w, INDEX)) ?? [];
31
+ return rows.sort((a, b) => b.updated - a.updated);
32
+ }
33
+ /** Save a conversation, and its row in the index. */
34
+ export async function keep(w, c) {
35
+ await save(w, `chats/${c.id}.json`, c);
36
+ const rows = (await load(w, INDEX)) ?? [];
37
+ const next = [listed(c), ...rows.filter((r) => r.id !== c.id)].slice(0, 500);
38
+ await save(w, INDEX, next);
39
+ }
40
+ export const open = (w, id) => load(w, `chats/${id}.json`);
41
+ /** Write the index again from the conversations stored. */
42
+ export async function rebuild(w) {
43
+ const entries = (await list(w, 'chats/')).filter((e) => e.key.endsWith('.json') && e.key !== 'index.json');
44
+ const rows = [];
45
+ for (const e of entries) {
46
+ const c = await open(w, e.key.replace(/\.json$/, ''));
47
+ if (c)
48
+ rows.push(listed(c));
49
+ }
50
+ await save(w, INDEX, rows);
51
+ return rows.sort((a, b) => b.updated - a.updated);
52
+ }
53
+ export async function forget(w, id) {
54
+ const rows = (await load(w, INDEX)) ?? [];
55
+ await save(w, INDEX, rows.filter((r) => r.id !== id));
56
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * ONE TURN of the conversation: the person says what to make, the chat calls
3
+ * a kind's tool, the kind makes it, and it opens as a tab.
4
+ *
5
+ * The chat model (api.hanzo.ai) is handed every kind that can run now as a
6
+ * tool, plus `revise` (change a tab), and the list of open tabs by number, so
7
+ * "make the poster in tab 2 warmer" is a call to revise {tab: 2}. Each call is
8
+ * run here, in order; its result goes back to the model as the tool's answer,
9
+ * and the model closes the turn with a line of its own. A kind that cannot run
10
+ * now (no GPU for 3D) is not offered as a tool; the model is told why, so it
11
+ * says so instead of pretending.
12
+ *
13
+ * Nothing a turn makes is held only in memory: each version's files are
14
+ * stored as they are made, and the conversation is saved after every change.
15
+ */
16
+ import { type Wire } from '../wire.ts';
17
+ import type { Available } from '../kinds/kind.ts';
18
+ import { type TypeSystem } from '../kinds/type/system.ts';
19
+ import { type Chat, type KindId, type Made, type Stored } from '../made.ts';
20
+ export interface Asked {
21
+ text: string;
22
+ attached: Stored[];
23
+ /** The kind the person picked (a pill, the Kind chip); none for Auto. */
24
+ kind?: KindId;
25
+ /** Lane and shape choices from the composer's options. */
26
+ options?: {
27
+ model?: string;
28
+ aspect?: string;
29
+ count?: number;
30
+ };
31
+ }
32
+ export interface Context extends Available {
33
+ wire: Wire;
34
+ /** The model the chat runs on: it calls the tools. */
35
+ brain: string;
36
+ /** The model a kind writes words with. */
37
+ writer: string;
38
+ /** The tabs, in their order: made ids. */
39
+ order: () => string[];
40
+ /** Open a made thing's tab and show it. */
41
+ show: (id: string) => void;
42
+ /** The conversation changed: draw it, and keep it. */
43
+ changed: (chat: Chat) => void;
44
+ signal: AbortSignal;
45
+ }
46
+ /** The brand a conversation draws in, read from its type system. */
47
+ export declare function brandOf(chat: Chat): TypeSystem | null;
48
+ /** Run one turn. Answers the conversation as it stands at the end. */
49
+ export declare function turn(start: Chat, asked: Asked, ctx: Context): Promise<Chat>;
50
+ /** An edit in place: a new version of one made thing from a patch to its spec, with no chat turn. */
51
+ export declare function edit(start: Chat, m: Made, patch: Record<string, unknown>, note: string, ctx: Omit<Context, 'show' | 'brain'>): Promise<Chat>;
@@ -0,0 +1,274 @@
1
+ /**
2
+ * ONE TURN of the conversation: the person says what to make, the chat calls
3
+ * a kind's tool, the kind makes it, and it opens as a tab.
4
+ *
5
+ * The chat model (api.hanzo.ai) is handed every kind that can run now as a
6
+ * tool, plus `revise` (change a tab), and the list of open tabs by number, so
7
+ * "make the poster in tab 2 warmer" is a call to revise {tab: 2}. Each call is
8
+ * run here, in order; its result goes back to the model as the tool's answer,
9
+ * and the model closes the turn with a line of its own. A kind that cannot run
10
+ * now (no GPU for 3D) is not offered as a tool; the model is told why, so it
11
+ * says so instead of pretending.
12
+ *
13
+ * Nothing a turn makes is held only in memory: each version's files are
14
+ * stored as they are made, and the conversation is saved after every change.
15
+ */
16
+ import { complete, put, read } from '../wire.js';
17
+ import { ALL, called, kind } from '../kinds/index.js';
18
+ import { settle } from '../kinds/type/system.js';
19
+ import { current, dir } from '../made.js';
20
+ import { data } from '../raster.js';
21
+ import { fresh } from '../route.js';
22
+ const ROUNDS = 4;
23
+ const id = () => fresh().slice(-12);
24
+ const REVISE = {
25
+ type: 'function',
26
+ function: {
27
+ name: 'revise',
28
+ description: 'Change something already made, by its tab number: "warmer", "shorter headline", "make it a story", "add a pricing slide". Makes a new version in the same tab.',
29
+ parameters: {
30
+ type: 'object',
31
+ properties: {
32
+ tab: { type: 'integer', description: 'The tab number, as listed.' },
33
+ instruction: { type: 'string', description: 'What to change, in full.' },
34
+ },
35
+ required: ['tab', 'instruction'],
36
+ },
37
+ },
38
+ };
39
+ const BRAND = {
40
+ type: 'function',
41
+ function: {
42
+ name: 'use_brand',
43
+ description: 'Draw what is made next in the type system in a tab (a brand), or in none.',
44
+ parameters: { type: 'object', properties: { tab: { type: 'integer', description: 'A type system tab, or 0 for none.' } }, required: ['tab'] },
45
+ },
46
+ };
47
+ /** The brand a conversation draws in, read from its type system. */
48
+ export function brandOf(chat) {
49
+ if (!chat.brand)
50
+ return null;
51
+ for (const m of chat.made)
52
+ for (const v of m.versions)
53
+ if (m.kind === 'type' && (m.id === chat.brand || v.id === chat.brand))
54
+ return settle(current(m).spec);
55
+ return null;
56
+ }
57
+ function system(chat, ctx, open, closed) {
58
+ const order = ctx.order();
59
+ const tabs = order
60
+ .map((mid, i) => {
61
+ const m = chat.made.find((x) => x.id === mid);
62
+ return m ? `${i + 1}. ${kind(m.kind).label} "${m.title}" (version ${m.at + 1} of ${m.versions.length}${m.id === chat.brand ? ', the brand' : ''})` : '';
63
+ })
64
+ .filter(Boolean);
65
+ const brand = brandOf(chat);
66
+ return [
67
+ 'You are Hanzo Studio: a creative studio in a chat. You make things by calling tools, and everything you make opens in a numbered tab beside this conversation.',
68
+ 'When the person asks for something, call the tool that makes it at once, with complete, specific, well-written arguments: real words, not placeholders. Ask a question only when you cannot make anything sensible without the answer.',
69
+ 'To change something already made, call revise with its tab number. "The poster in tab 2" is tab 2.',
70
+ 'After the tools have run, answer in one or two short sentences: what you made, and one useful next step. Never paste file contents, links or JSON. If a tool answers with an error, say plainly what went wrong.',
71
+ brand ? `Brand: ${brand.name} (${brand.display} / ${brand.text}; ${brand.blurb}). Posters, documents, slides and ads are drawn in it.` : 'No brand is chosen: things are drawn in the Hanzo type system unless the person asks for a type system.',
72
+ tabs.length ? `Tabs:\n${tabs.join('\n')}` : 'No tabs are open yet.',
73
+ closed.length ? `Not available right now: ${closed.map((k) => `${k.label} (${k.needs(ctx)})`).join('; ')}.` : '',
74
+ `You can make: ${open.map((k) => k.label).join(', ')}.`,
75
+ ]
76
+ .filter(Boolean)
77
+ .join('\n\n');
78
+ }
79
+ /** The conversation so far, as the model reads it: words, and what each turn made. */
80
+ function history(chat, ctx) {
81
+ const order = ctx.order();
82
+ return chat.turns
83
+ .filter((t) => t.text || t.made?.length)
84
+ .map((t) => {
85
+ if (t.role === 'user') {
86
+ const pics = t.attached?.length ? `\n[Attached ${t.attached.length} picture${t.attached.length > 1 ? 's' : ''}, now in tab ${t.made?.map((m) => order.indexOf(m) + 1).join(', ')}]` : '';
87
+ return { role: 'user', content: t.text + pics };
88
+ }
89
+ const made = (t.made ?? [])
90
+ .map((mid) => chat.made.find((m) => m.id === mid))
91
+ .filter((m) => Boolean(m))
92
+ .map((m) => `[tab ${order.indexOf(m.id) + 1}: ${kind(m.kind).label} "${m.title}"]`)
93
+ .join(' ');
94
+ return { role: 'assistant', content: [t.text, made].filter(Boolean).join(' ') || '…' };
95
+ });
96
+ }
97
+ const words = (e) => (e instanceof Error ? e.message : String(e));
98
+ /** Run one turn. Answers the conversation as it stands at the end. */
99
+ export async function turn(start, asked, ctx) {
100
+ let chat = start;
101
+ const put_ = (next) => {
102
+ chat = { ...next, updated: Date.now() };
103
+ ctx.changed(chat);
104
+ };
105
+ const me = { id: id(), role: 'user', text: asked.text, at: Date.now(), attached: asked.attached.length ? asked.attached : undefined };
106
+ const you = { id: id(), role: 'assistant', text: '', at: Date.now(), doing: 'Thinking', made: [] };
107
+ // An attached picture is a thing in the conversation: its own tab, so it can be named.
108
+ const uploads = asked.attached.map((f) => ({
109
+ id: id(),
110
+ kind: 'image',
111
+ title: f.name.replace(/\.[a-z0-9]+$/i, '') || 'Picture',
112
+ at: 0,
113
+ versions: [{ id: id(), at: Date.now(), spec: { prompt: '', uploaded: true }, files: [f], note: 'Attached', by: 'you' }],
114
+ }));
115
+ me.made = uploads.map((u) => u.id);
116
+ put_({
117
+ ...chat,
118
+ title: chat.turns.length ? chat.title : asked.text.slice(0, 60) || chat.title,
119
+ turns: [...chat.turns, me, you],
120
+ made: [...chat.made, ...uploads],
121
+ });
122
+ for (const u of uploads)
123
+ ctx.show(u.id);
124
+ const set = (patch) => {
125
+ put_({ ...chat, turns: chat.turns.map((t) => (t.id === you.id ? { ...t, ...patch } : t)) });
126
+ };
127
+ const mine = () => chat.turns.find((t) => t.id === you.id);
128
+ const open = ALL.filter((k) => !k.needs(ctx));
129
+ const closed = ALL.filter((k) => k.needs(ctx));
130
+ const tools = [...open.map((k) => ({ type: 'function', function: k.tool })), REVISE, BRAND];
131
+ const messages = [{ role: 'system', content: system(chat, ctx, open, closed) }, ...history(start, ctx), { role: 'user', content: me.text + (uploads.length ? `\n[Attached: tab ${uploads.map((u) => ctx.order().indexOf(u.id) + 1).join(', ')}]` : '') }];
132
+ const picked = asked.kind ? kind(asked.kind) : null;
133
+ if (picked && picked.needs(ctx)) {
134
+ set({ doing: undefined, text: `${picked.label} can't run right now. ${picked.needs(ctx)}` });
135
+ return chat;
136
+ }
137
+ if (picked)
138
+ messages.push({ role: 'system', content: `The person chose ${picked.label}: answer by calling ${picked.tool.name}.` });
139
+ try {
140
+ for (let round = 0; round < ROUNDS; round++) {
141
+ const said = await complete(ctx.wire, { model: ctx.brain, messages, tools }, (text) => set({ text, doing: text ? undefined : mine().doing }), ctx.signal);
142
+ set({ text: said.text, by: said.model, doing: said.calls.length ? 'Working' : undefined });
143
+ if (!said.calls.length)
144
+ break;
145
+ messages.push({ role: 'assistant', content: said.text, tool_calls: said.calls.map((c) => ({ id: c.id, type: 'function', function: { name: c.name, arguments: c.args } })) });
146
+ for (const c of said.calls) {
147
+ let args = {};
148
+ try {
149
+ args = c.args ? JSON.parse(c.args) : {};
150
+ }
151
+ catch {
152
+ messages.push({ role: 'tool', tool_call_id: c.id, content: JSON.stringify({ ok: false, error: 'The arguments were not JSON.' }) });
153
+ continue;
154
+ }
155
+ const answer = await call(c.name, args);
156
+ messages.push({ role: 'tool', tool_call_id: c.id, content: JSON.stringify(answer) });
157
+ }
158
+ }
159
+ set({ doing: undefined });
160
+ }
161
+ catch (e) {
162
+ if (e?.name === 'AbortError')
163
+ set({ doing: undefined, failed: 'Stopped.' });
164
+ else
165
+ set({ doing: undefined, failed: words(e) });
166
+ }
167
+ return chat;
168
+ async function call(name, args) {
169
+ if (name === 'use_brand') {
170
+ const tabN = Number(args.tab) || 0;
171
+ const m = tabN ? chat.made.find((x) => x.id === ctx.order()[tabN - 1]) : null;
172
+ if (tabN && (!m || m.kind !== 'type'))
173
+ return { ok: false, error: `Tab ${tabN} is not a type system.` };
174
+ put_({ ...chat, brand: m?.id });
175
+ return { ok: true, brand: m?.title ?? 'none' };
176
+ }
177
+ if (name === 'revise') {
178
+ const tabN = Number(args.tab) || 0;
179
+ const m = chat.made.find((x) => x.id === ctx.order()[tabN - 1]);
180
+ if (!m)
181
+ return { ok: false, error: `There is no tab ${tabN}.` };
182
+ const k = kind(m.kind);
183
+ const why = k.needs(ctx);
184
+ if (why)
185
+ return { ok: false, error: why };
186
+ set({ doing: `Revising ${m.title}` });
187
+ try {
188
+ const v = await version(m, (w) => k.revise(w, m, { instruction: String(args.instruction ?? '') }));
189
+ 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 };
190
+ }
191
+ catch (e) {
192
+ return { ok: false, error: words(e) };
193
+ }
194
+ }
195
+ const k = called(name);
196
+ if (!k)
197
+ return { ok: false, error: `There is no tool called ${name}.` };
198
+ const why = k.needs(ctx);
199
+ if (why)
200
+ return { ok: false, error: why };
201
+ const opts = asked.options ?? {};
202
+ const merged = { ...args, ...(k.id === 'image' && opts.model ? { model: opts.model } : {}), ...(k.id === 'image' && opts.aspect && !args.aspect ? { aspect: opts.aspect } : {}), ...(k.id === 'image' && opts.count ? { count: opts.count } : {}) };
203
+ const m = { id: id(), kind: k.id, title: String(args.title ?? k.label), versions: [], at: 0 };
204
+ set({ doing: `Making ${k.label.toLowerCase()}` });
205
+ try {
206
+ const vid = id();
207
+ const made = await k.make(work(m, vid), merged);
208
+ const v = { ...made.draft, id: vid, at: Date.now() };
209
+ const done = { ...m, title: made.title, versions: [v], at: 0 };
210
+ const brand = k.id === 'type' && !chat.brand ? done.id : chat.brand;
211
+ put_({ ...chat, brand, made: [...chat.made, done], turns: chat.turns.map((t) => (t.id === you.id ? { ...t, made: [...(t.made ?? []), done.id] } : t)) });
212
+ ctx.show(done.id);
213
+ return { ok: true, tab: ctx.order().indexOf(done.id) + 1, title: done.title, kind: k.label, note: v.note };
214
+ }
215
+ catch (e) {
216
+ return { ok: false, error: words(e) };
217
+ }
218
+ }
219
+ /** A new version of `m`, made by `run`, stored and shown. */
220
+ async function version(m, run) {
221
+ const vid = id();
222
+ const draft = await run(work(m, vid));
223
+ const v = { ...draft, id: vid, at: Date.now() };
224
+ const now = chat.made.find((x) => x.id === m.id) ?? m;
225
+ const next = { ...now, versions: [...now.versions, v], at: now.versions.length };
226
+ put_({ ...chat, made: chat.made.map((x) => (x.id === m.id ? next : x)), turns: chat.turns.map((t) => (t.id === you.id ? { ...t, made: [...new Set([...(t.made ?? []), m.id])] } : t)) });
227
+ ctx.show(m.id);
228
+ return next.versions.length;
229
+ }
230
+ function work(m, vid) {
231
+ return {
232
+ wire: ctx.wire,
233
+ signal: ctx.signal,
234
+ doing: (line) => set({ doing: line }),
235
+ keep: async (name, blob, extra) => {
236
+ const key = await put(ctx.wire, `${dir(chat.id, m, vid)}/${name}`, blob);
237
+ return { key, mime: blob.type || 'application/octet-stream', name, ...extra };
238
+ },
239
+ picture: async (f) => data(await read(ctx.wire, f.key)),
240
+ find: (ref) => {
241
+ const order = ctx.order();
242
+ const mid = typeof ref === 'number' ? order[ref - 1] : ref;
243
+ return chat.made.find((x) => x.id === mid) ?? null;
244
+ },
245
+ brand: brandOf(chat),
246
+ fleet: ctx.fleet,
247
+ models: ctx.models,
248
+ writer: ctx.writer,
249
+ };
250
+ }
251
+ }
252
+ /** An edit in place: a new version of one made thing from a patch to its spec, with no chat turn. */
253
+ export async function edit(start, m, patch, note, ctx) {
254
+ const k = kind(m.kind);
255
+ const vid = id();
256
+ const w = {
257
+ wire: ctx.wire,
258
+ signal: ctx.signal,
259
+ doing: () => undefined,
260
+ keep: async (name, blob, extra) => ({ key: await put(ctx.wire, `${dir(start.id, m, vid)}/${name}`, blob), mime: blob.type || 'application/octet-stream', name, ...extra }),
261
+ picture: async (f) => data(await read(ctx.wire, f.key)),
262
+ find: (ref) => start.made.find((x) => x.id === (typeof ref === 'number' ? ctx.order()[ref - 1] : ref)) ?? null,
263
+ brand: brandOf(start),
264
+ fleet: ctx.fleet,
265
+ models: ctx.models,
266
+ writer: ctx.writer,
267
+ };
268
+ const draft = await k.revise(w, m, { patch });
269
+ const v = { ...draft, note, id: vid, at: Date.now() };
270
+ const next = { ...m, versions: [...m.versions, v], at: m.versions.length };
271
+ const chat = { ...start, updated: Date.now(), made: start.made.map((x) => (x.id === m.id ? next : x)) };
272
+ ctx.changed(chat);
273
+ return chat;
274
+ }
package/lib/desk.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { type Made } from './made.ts';
2
+ import type { Wire } from './wire.ts';
3
+ export interface DeskProps {
4
+ made: Made;
5
+ wire: Wire;
6
+ others: readonly Made[];
7
+ /** Show version `at`. */
8
+ onPick: (at: number) => void;
9
+ onEdit: (patch: Record<string, unknown>, note: string) => void;
10
+ busy: boolean;
11
+ /** Why the last edit failed, for this tab. */
12
+ failed?: string;
13
+ }
14
+ export declare function Desk({ made, wire, others, onPick, onEdit, busy, failed }: DeskProps): import("react").JSX.Element;
package/lib/desk.js ADDED
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * One tab: a thing the conversation made. Its bar picks the version shown,
4
+ * compares two, and exports; its body is the kind's own view, which edits in
5
+ * place (a new version, never an overwrite).
6
+ *
7
+ * Compare draws two versions: a wipe for pictures (drag the line), side by
8
+ * side for everything else.
9
+ */
10
+ import { SizableText, XStack, YStack } from '@hanzo/gui';
11
+ import { ChevronDown, Columns2, Download } from '@hanzogui/lucide-icons-2';
12
+ import { DropdownMenu } from '@hanzo/ui';
13
+ import { useState } from 'react';
14
+ import { kind } from './kinds/index.js';
15
+ import { current } from './made.js';
16
+ import { download } from './ui.js';
17
+ import { useUrl } from './use.js';
18
+ const ago = (t) => {
19
+ const s = Math.max(0, Math.round((Date.now() - t) / 1000));
20
+ if (s < 60)
21
+ return 'just now';
22
+ if (s < 3600)
23
+ return `${Math.round(s / 60)}m ago`;
24
+ if (s < 86400)
25
+ return `${Math.round(s / 3600)}h ago`;
26
+ return new Date(t).toLocaleDateString();
27
+ };
28
+ export function Desk({ made, wire, others, onPick, onEdit, busy, failed }) {
29
+ const k = kind(made.kind);
30
+ const v = current(made);
31
+ const [against, setAgainst] = useState(null);
32
+ const [error, setError] = useState('');
33
+ const exporting = async (i) => {
34
+ setError('');
35
+ try {
36
+ const out = await k.exports[i].run(wire, made, v);
37
+ download(out.name, out.blob);
38
+ }
39
+ catch (e) {
40
+ setError(e instanceof Error ? e.message : String(e));
41
+ }
42
+ };
43
+ const Icon = k.icon;
44
+ const versions = made.versions.map((x, i) => ({
45
+ key: x.id,
46
+ label: `Version ${i + 1}${i === made.at ? ' (shown)' : ''}`,
47
+ description: `${x.note.slice(0, 80)} · ${ago(x.at)}${x.by ? ` · ${x.by}` : ''}`,
48
+ onSelect: () => onPick(i),
49
+ }));
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": "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
+ { type: 'label', key: 'h', label: 'Compare with' },
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
+ ...(compare ? [{ type: 'separator', key: 's' }, { key: 'off', label: 'Stop comparing', onSelect: () => setAgainst(null) }] : []),
55
+ ] })) : null, _jsx(DropdownMenu, { trigger: _jsxs(XStack, { render: "button", "aria-label": "Export", items: "center", gap: "$1.5", height: 30, px: "$2.5", rounded: "$3", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [_jsx(Download, { size: 14 }), _jsx(SizableText, { size: "$2", children: "Export" })] }), items: [{ type: 'label', key: 'h', label: 'Export' }, ...k.exports.map((x, i) => ({ key: x.label, label: x.label, onSelect: () => void exporting(i) }))] })] }), error || failed ? (_jsx(XStack, { px: "$3", py: "$2", bg: "$hover", shrink: 0, children: _jsx(SizableText, { size: "$2", color: "$red10", 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 }))] }));
56
+ }
57
+ function Compare({ made, a, b, wire, others }) {
58
+ const pa = a.files.find((f) => f.mime.startsWith('image/'));
59
+ const pb = b.files.find((f) => f.mime.startsWith('image/'));
60
+ if (pa && pb && (made.kind === 'image' || made.kind === 'poster'))
61
+ return _jsx(Wipe, { wire: wire, a: pa.key, b: pb.key, title: made.title });
62
+ const k = kind(made.kind);
63
+ const none = () => undefined;
64
+ return (_jsx(XStack, { flex: 1, minH: 0, children: [a, b].map((v, i) => (_jsxs(YStack, { flex: 1, minW: 0, borderLeftWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsx(SizableText, { size: "$1", color: "$soft", px: "$3", py: "$1", children: `Version ${made.versions.indexOf(v) + 1}` }), _jsx(k.View, { made: made, version: v, wire: wire, edit: none, busy: true, others: others })] }, v.id))) }));
65
+ }
66
+ /** Two pictures, one over the other, the line between them dragged across. */
67
+ function Wipe({ wire, a, b, title }) {
68
+ const left = useUrl(wire, a);
69
+ const right = useUrl(wire, b);
70
+ const [at, setAt] = useState(50);
71
+ return (_jsxs(YStack, { flex: 1, minH: 0, items: "center", justify: "center", p: "$3", gap: "$2", children: [_jsxs("div", { style: { position: 'relative', maxWidth: '100%', maxHeight: 'calc(100% - 40px)', display: 'inline-block' }, children: [right.src ? _jsx("img", { src: right.src, alt: `${title}, the version shown`, style: { display: 'block', maxWidth: '100%', maxHeight: '70vh', borderRadius: 12 } }) : null, left.src ? (_jsx("img", { src: left.src, alt: `${title}, the version compared`, style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'contain', clipPath: `inset(0 ${100 - at}% 0 0)`, borderRadius: 12 } })) : null, _jsx("div", { "aria-hidden": true, style: { position: 'absolute', top: 0, bottom: 0, left: `${at}%`, width: 2, background: '#fff', boxShadow: '0 0 0 1px rgba(0,0,0,.4)' } })] }), _jsx("input", { type: "range", min: 0, max: 100, value: at, "aria-label": "Move the line between the two versions", onChange: (e) => setAt(Number(e.currentTarget.value)), style: { width: 'min(420px, 100%)' } })] }));
72
+ }
package/lib/gpu.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A render on the org's GPUs, start to finish: dispatch through the engine's
3
+ * one funnel, follow its work-log row until the engine's integrity gate says
4
+ * done (or failed), and read back what landed.
5
+ *
6
+ * The engine's word is the only verdict: `done` is the row its gate closed, a
7
+ * `failed` row carries the engine's reason, and a row still `queued` when the
8
+ * wait runs out is said to be still rendering, never called finished.
9
+ */
10
+ import { dispatch, type Wire } from './wire.ts';
11
+ export type Lane = Parameters<typeof dispatch>[1];
12
+ export declare function render(w: Wire, lane: Lane, body: object, doing: (line: string) => void, signal: AbortSignal): Promise<{
13
+ blob: Blob;
14
+ path: string;
15
+ }[]>;