@hanzo/studio 0.1.11 → 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.
@@ -0,0 +1,34 @@
1
+ import { type Call, type Wire } from '../wire.ts';
2
+ export type RunState = 'queued' | 'running' | 'done' | 'failed';
3
+ /** A submitted graph's state from its work-log row. Only a row the engine closed as done is done; no row is still queued. */
4
+ export declare function runState(row?: {
5
+ status: string;
6
+ }): RunState;
7
+ /**
8
+ * Queue a graph and follow it: `seen` hears each state as it changes, and the
9
+ * last one is answered. A run with no verdict by `wait` ms is still queued or
10
+ * running, never done. Once the job is queued, a work-log that cannot be read
11
+ * is said as such, and is not a failed run. An aborted run says nothing more.
12
+ */
13
+ export declare function run(w: Wire, prompt: object, seen: (state: RunState, note: string) => void, o: {
14
+ signal: AbortSignal;
15
+ every?: number;
16
+ wait?: number;
17
+ }): Promise<RunState>;
18
+ /** The run now in flight: starting another ends the one before, which may then write nothing. */
19
+ export declare function runs(): {
20
+ start(): {
21
+ signal: AbortSignal;
22
+ current: () => boolean;
23
+ };
24
+ stop(): void;
25
+ };
26
+ /** The edit Copilot's tool call asks for, or why there is none. */
27
+ export declare function graphEdit(calls: readonly Call[]): {
28
+ edit: {
29
+ addNodeType?: string;
30
+ autoLayout?: boolean;
31
+ };
32
+ } | {
33
+ why: string;
34
+ };
@@ -0,0 +1,77 @@
1
+ /** What a Flow run and Copilot may say, from what the platform really answered. */
2
+ import { follow } from '../gpu.js';
3
+ import { queuePrompt } from '../wire.js';
4
+ /** A submitted graph's state from its work-log row. Only a row the engine closed as done is done; no row is still queued. */
5
+ export function runState(row) {
6
+ switch (row?.status) {
7
+ case 'done':
8
+ return 'done';
9
+ case 'failed':
10
+ case 'cancelled':
11
+ return 'failed';
12
+ case 'running':
13
+ return 'running';
14
+ default:
15
+ return 'queued';
16
+ }
17
+ }
18
+ /**
19
+ * Queue a graph and follow it: `seen` hears each state as it changes, and the
20
+ * last one is answered. A run with no verdict by `wait` ms is still queued or
21
+ * running, never done. Once the job is queued, a work-log that cannot be read
22
+ * is said as such, and is not a failed run. An aborted run says nothing more.
23
+ */
24
+ export async function run(w, prompt, seen, o) {
25
+ const sent = await queuePrompt(w, prompt, o.signal);
26
+ const id = sent.prompt_id ?? sent.id;
27
+ let last = 'queued';
28
+ if (o.signal.aborted)
29
+ return last;
30
+ seen(last, id ? `Queued as ${id}` : 'Queued, but the platform named no job to follow');
31
+ if (!id)
32
+ return last;
33
+ try {
34
+ await follow(w, id, o, (status, row) => {
35
+ const next = runState({ status });
36
+ if (o.signal.aborted || next === last)
37
+ return;
38
+ seen((last = next), row?.error ?? '');
39
+ });
40
+ }
41
+ catch (e) {
42
+ if (!o.signal.aborted)
43
+ seen(last, `Queued; lost track of progress (${e instanceof Error ? e.message : String(e)})`);
44
+ }
45
+ return last;
46
+ }
47
+ /** The run now in flight: starting another ends the one before, which may then write nothing. */
48
+ export function runs() {
49
+ let now = null;
50
+ return {
51
+ start() {
52
+ now?.abort();
53
+ const ctl = new AbortController();
54
+ now = ctl;
55
+ return { signal: ctl.signal, current: () => now === ctl };
56
+ },
57
+ stop() {
58
+ now?.abort();
59
+ now = null;
60
+ },
61
+ };
62
+ }
63
+ /** The edit Copilot's tool call asks for, or why there is none. */
64
+ export function graphEdit(calls) {
65
+ const call = calls.find((c) => c.name === 'flow_mutate_graph');
66
+ if (!call)
67
+ return { why: 'the model called no graph tool' };
68
+ try {
69
+ const a = JSON.parse(call.args);
70
+ const addNodeType = typeof a.add_node_type === 'string' && a.add_node_type ? a.add_node_type : undefined;
71
+ const autoLayout = a.auto_layout === true ? true : undefined;
72
+ return addNodeType || autoLayout ? { edit: { addNodeType, autoLayout } } : { why: 'the model asked for no edit' };
73
+ }
74
+ catch {
75
+ return { why: 'the model sent an edit that could not be read' };
76
+ }
77
+ }
package/lib/app/flow.d.ts CHANGED
@@ -13,8 +13,8 @@
13
13
  */
14
14
  import type { Host } from '@hanzo/build';
15
15
  import type { RailLink } from '@hanzo/ui/chat';
16
- export type FlowSection = 'canvas' | 'hybrid' | 'comfy' | 'agents' | 'code' | 'publish';
17
- export declare function parseFlowSection(path?: string): FlowSection;
16
+ import { parseFlowSection, type FlowSection } from './sections.ts';
17
+ export { parseFlowSection, type FlowSection };
18
18
  export declare function flowNav(host: Host, go: (path: string) => void): {
19
19
  id: 'make';
20
20
  label: string;