@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
package/lib/wire.d.ts CHANGED
@@ -117,12 +117,6 @@ export interface Picture {
117
117
  }
118
118
  /** A data: URL's bytes. */
119
119
  export declare function bytes(url: string): Picture;
120
- /**
121
- * An image from a gateway image model: words, and the pictures it starts from
122
- * (an edit). The image models are chat models with an image output, so this is
123
- * a chat completion asking for both modalities; the pictures come back on the
124
- * message (`images`) or among its content parts.
125
- */
126
120
  export declare function draw(w: Wire, model: string, prompt: string, o?: {
127
121
  from?: string[];
128
122
  aspect?: string;
@@ -132,6 +126,15 @@ export declare function draw(w: Wire, model: string, prompt: string, o?: {
132
126
  export declare function speak(w: Wire, input: string, voice: string, model: string, signal?: AbortSignal): Promise<Blob>;
133
127
  /** Whether api.hanzo.ai/v1/library answers for this person. */
134
128
  export declare function libraryLive(w: Wire): Promise<boolean>;
129
+ /** What each kind makes, as the Library files it (`POST /v1/library` `kind`). */
130
+ export declare const LIBRARY: Record<string, string>;
131
+ /**
132
+ * Save one made file to the Library because the person asked. Unlike `put`,
133
+ * which holds the file here when the Library cannot take it, this says why.
134
+ */
135
+ export declare function saveToLibrary(w: Wire, key: string, blob: Blob): Promise<string>;
136
+ /** The bytes at an address a Library item gave, or the reason they did not come. */
137
+ export declare function fileAt(href: string): Promise<Blob>;
135
138
  /** Keep bytes at a key: a made file in the Library, anything else in this browser. Answers the key. */
136
139
  export declare function put(w: Wire, key: string, blob: Blob): Promise<string>;
137
140
  /**
@@ -179,6 +182,8 @@ export interface Node {
179
182
  identity: string;
180
183
  name?: string;
181
184
  online?: boolean;
185
+ /** Jobs waiting on this GPU, when the engine says. */
186
+ depth?: number;
182
187
  /** The lanes this GPU can run now: every file its graph loads is present. */
183
188
  lanes?: string[];
184
189
  }
@@ -208,6 +213,14 @@ export interface Row {
208
213
  error?: string;
209
214
  prompt_id?: string;
210
215
  }
216
+ /** Queue a ComfyUI graph on `/v1/prompt`. It is only queued: its `prompt_id` is followed through the work-log. */
217
+ export declare const queuePrompt: (w: Wire, prompt: object, signal?: AbortSignal) => Promise<Submitted>;
218
+ /** The node types the platform's ComfyUI serves. */
219
+ export declare const objectInfo: (w: Wire, signal?: AbortSignal) => Promise<Record<string, {
220
+ display_name?: string;
221
+ category?: string;
222
+ output?: string[];
223
+ }>>;
211
224
  /** The engine's record of what was dispatched and what landed. */
212
225
  export declare const worklog: (w: Wire, signal?: AbortSignal) => Promise<Row[]>;
213
226
  /** A landed file of the engine library, as bytes. */
package/lib/wire.js CHANGED
@@ -216,8 +216,20 @@ export function bytes(url) {
216
216
  * a chat completion asking for both modalities; the pictures come back on the
217
217
  * message (`images`) or among its content parts.
218
218
  */
219
+ const IMAGE_GEN_MODELS = new Set(['iro', 'iro-1', 'zen-image', 'zen3-image', 'enso-image', 'koma']);
219
220
  export async function draw(w, model, prompt, o = {}) {
220
221
  let held;
222
+ if (!o.from?.length && (IMAGE_GEN_MODELS.has(model) || model.startsWith('black-forest-labs/'))) {
223
+ const gen = await ask(w, 'api', '/v1/images/generations', {
224
+ body: { model, prompt, size: '1024x1024' },
225
+ signal: o.signal,
226
+ heard: (h) => (held = h),
227
+ });
228
+ const b64s = (gen.data ?? []).map((d) => d.b64_json ?? '').filter(Boolean);
229
+ if (!b64s.length)
230
+ throw withheld(model, held);
231
+ return b64s.map((b) => bytes(`data:image/jpeg;base64,${b}`));
232
+ }
221
233
  const content = [{ type: 'text', text: prompt }, ...(o.from ?? []).map((url) => ({ type: 'image_url', image_url: { url } }))];
222
234
  const out = await ask(w, 'api', '/v1/chat/completions', {
223
235
  body: {
@@ -318,7 +330,8 @@ export function libraryLive(w) {
318
330
  }
319
331
  /** The most a browser may send the Library in one save (its inline limit). */
320
332
  const INLINE = 10 * 1024 * 1024;
321
- const KINDS_LIB = { image: 'image', poster: 'image', ad: 'image', video: 'video', voice: 'audio', music: 'audio', document: 'document', slides: 'slides', type: 'type', mesh: 'model' };
333
+ /** What each kind makes, as the Library files it (`POST /v1/library` `kind`). */
334
+ export const LIBRARY = { image: 'image', poster: 'image', ad: 'image', video: 'video', voice: 'audio', music: 'audio', document: 'document', slides: 'slides', type: 'type', mesh: 'model', app: 'app' };
322
335
  /** Whether a key and its bytes belong in the Library: a made file the Library can take from a browser. */
323
336
  const shelvable = (key, blob) => key.startsWith('files/') && key.split('/').length > 3 && blob.size <= INLINE;
324
337
  const base64 = async (b) => {
@@ -337,9 +350,9 @@ async function shelve(w, key, blob) {
337
350
  mime: blob.type || 'application/octet-stream',
338
351
  data: await base64(blob),
339
352
  source: 'studio',
340
- kind: KINDS_LIB[kind] ?? 'file',
353
+ kind: LIBRARY[kind] ?? 'file',
341
354
  ref: chat,
342
- origin: `/studio/c/${chat}`,
355
+ origin: `/design/c/${chat}`,
343
356
  key,
344
357
  },
345
358
  });
@@ -347,6 +360,22 @@ async function shelve(w, key, blob) {
347
360
  throw new Refusal(502, 'The Library took the file and named no item.');
348
361
  return item.id;
349
362
  }
363
+ /**
364
+ * Save one made file to the Library because the person asked. Unlike `put`,
365
+ * which holds the file here when the Library cannot take it, this says why.
366
+ */
367
+ export async function saveToLibrary(w, key, blob) {
368
+ if (blob.size > INLINE)
369
+ throw new Refusal(413, 'This file is over the Library\'s 10 MiB browser limit.');
370
+ return shelve(w, key, blob);
371
+ }
372
+ /** The bytes at an address a Library item gave, or the reason they did not come. */
373
+ export async function fileAt(href) {
374
+ const r = await fetch(href, { credentials: 'omit' });
375
+ if (!r.ok)
376
+ throw new Error(`Download failed (HTTP ${r.status})`);
377
+ return r.blob();
378
+ }
350
379
  /** What this page made or read, held for its life: a file is never fetched twice. */
351
380
  const held = new Map();
352
381
  /** Keep bytes at a key: a made file in the Library, anything else in this browser. Answers the key. */
@@ -480,6 +509,10 @@ export async function discard(w, id) {
480
509
  export const gpus = (w, signal) => ask(w, 'engine', '/v1/gpu-status', { signal });
481
510
  /** Dispatch a lane to the org's GPUs (the engine's one funnel). */
482
511
  export const dispatch = (w, lane, body, signal) => ask(w, 'engine', `/v1/library/${lane}`, { body, signal });
512
+ /** Queue a ComfyUI graph on `/v1/prompt`. It is only queued: its `prompt_id` is followed through the work-log. */
513
+ export const queuePrompt = (w, prompt, signal) => ask(w, 'api', '/v1/prompt', { body: { prompt }, signal });
514
+ /** The node types the platform's ComfyUI serves. */
515
+ export const objectInfo = (w, signal) => ask(w, 'api', '/v1/object_info', { signal });
483
516
  /** The engine's record of what was dispatched and what landed. */
484
517
  export const worklog = (w, signal) => ask(w, 'engine', '/v1/worklog', { signal }).then((r) => r.items ?? []);
485
518
  /** A landed file of the engine library, as bytes. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/studio",
3
- "version": "0.1.8",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "license": "BSD-3-Clause",
6
6
  "description": "Hanzo Studio: a chat that makes images, posters, documents, slides, type systems, 3D, video and sound, with every result open in a tab beside it. Mounted by the Hanzo app at hanzo.ai/studio and served whole at studio.hanzo.ai.",