@hanzo/build 0.2.120 → 0.2.122

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.
@@ -15,7 +15,12 @@ export interface Sketch {
15
15
  export declare const SYSTEM: string;
16
16
  /** A model's answer as a draft: the fields that are text, or null where it named no one to draft. */
17
17
  export declare function parse(said: string): Sketch | null;
18
- /** The line they typed, drafted. */
18
+ /**
19
+ * The tokens a draft is allowed: Enso reasons before it answers, and under 4,000 the answer
20
+ * is cut off with nothing said (measured: 1,200 came back empty, 4,000 in full).
21
+ */
22
+ export declare const ROOM = 4000;
23
+ /** The line they typed, drafted; asked a second time when the first answer was not one. */
19
24
  export declare function sketch(t: Target, line: string, signal?: AbortSignal): Promise<Sketch>;
20
25
  /** The instructions as saved: what the model wrote, then the first line it says. */
21
26
  export declare const saved: (s: Pick<Sketch, 'instructions' | 'opening'>) => string;
package/lib/api/draft.js CHANGED
@@ -30,13 +30,19 @@ export function parse(said) {
30
30
  return null;
31
31
  return { name, role: word(o.role), instructions, opening: word(o.opening), emoji: word(o.emoji).slice(0, 8), figure: word(o.figure) };
32
32
  }
33
- /** The line they typed, drafted. */
33
+ /**
34
+ * The tokens a draft is allowed: Enso reasons before it answers, and under 4,000 the answer
35
+ * is cut off with nothing said (measured: 1,200 came back empty, 4,000 in full).
36
+ */
37
+ export const ROOM = 4000;
38
+ /** The line they typed, drafted; asked a second time when the first answer was not one. */
34
39
  export async function sketch(t, line, signal) {
35
- const said = await ask(t, SYSTEM, line.trim(), signal, 1200, ENSO);
36
- const draft = parse(said);
37
- if (!draft)
38
- throw new Error('The draft did not come out. Try again.');
39
- return draft;
40
+ for (let tried = 0; tried < 2; tried++) {
41
+ const draft = parse(await ask(t, SYSTEM, line.trim(), signal, ROOM, ENSO));
42
+ if (draft)
43
+ return draft;
44
+ }
45
+ throw new Error('The draft did not come out. Try again.');
40
46
  }
41
47
  /** The instructions as saved: what the model wrote, then the first line it says. */
42
48
  export const saved = (s) => (s.opening ? `${s.instructions.trim()}\n\nBegin a new conversation with: ${s.opening}` : s.instructions.trim());
package/lib/data.js CHANGED
@@ -114,13 +114,32 @@ export function useCached(key, load, initial, wait = WAIT) {
114
114
  }, [key, tick, wait]);
115
115
  return { value, error, loading, reload };
116
116
  }
117
+ /** Last coding runs read per `api\norg`, so mounting another rail or switching tabs starts warm. */
118
+ const recentRuns = new Map();
117
119
  /**
118
120
  * The org's coding runs, newest first, kept current by the org's own session
119
121
  * stream: a status that moves moves its dot, and a run started anywhere appears.
120
122
  */
121
123
  export function useRecents(t, signed) {
122
- const read = useRead(signed ? () => list(t, { kind: 'coding', limit: 50 }) : null, [], [t, signed]);
123
- const [rows, setRows] = useState([]);
124
+ const scope = signed ? `${t.api}\n${t.org ?? ''}` : null;
125
+ const warm = scope !== null ? recentRuns.get(scope) : undefined;
126
+ const read = useRead(signed
127
+ ? async () => {
128
+ const next = await list(t, { kind: 'coding', limit: 50 });
129
+ if (scope !== null)
130
+ recentRuns.set(scope, next);
131
+ return next;
132
+ }
133
+ : null, warm ?? [], [t.api, t.org, signed]);
134
+ const [settled, setSettled] = useState(warm !== undefined);
135
+ useEffect(() => {
136
+ setSettled(scope !== null && recentRuns.has(scope));
137
+ }, [scope]);
138
+ useEffect(() => {
139
+ if (!read.loading)
140
+ setSettled(true);
141
+ }, [read.loading]);
142
+ const [rows, setRows] = useState(() => warm ?? read.value);
124
143
  useEffect(() => setRows(read.value), [read.value]);
125
144
  const last = useRef(0);
126
145
  // useRead's reload is the same function every render, so it never reopens the feed.
@@ -143,7 +162,8 @@ export function useRecents(t, signed) {
143
162
  const i = prev.findIndex((r) => r.id === s.id);
144
163
  if (i === -1) {
145
164
  // A run this list has not seen: re-read rather than guess its kind.
146
- reload();
165
+ if (!s.kind || s.kind === 'coding')
166
+ reload();
147
167
  return prev;
148
168
  }
149
169
  const next = prev.slice();
@@ -159,7 +179,7 @@ export function useRecents(t, signed) {
159
179
  });
160
180
  return () => ctl.abort();
161
181
  }, [t, signed, again]);
162
- return { ...read, value: rows };
182
+ return { ...read, value: rows, loading: read.loading && !settled };
163
183
  }
164
184
  export function usePlaces(t, signed) {
165
185
  return useRead(signed ? () => places(t) : null, [], [t, signed]);
package/lib/shelf.js CHANGED
@@ -19,7 +19,7 @@ import { Address, Confirm, Rename } from './ask.js';
19
19
  import { useProjects, useRead } from './data.js';
20
20
  import { useHost, useTarget } from './host.js';
21
21
  import { Out } from './out.js';
22
- const SHOTS = 'https://hanzo.ai/templates';
22
+ const SHOTS = ['/templates', 'https://gallery.hanzo.ai/screenshots', 'https://hanzo.ai/templates'];
23
23
  function Head({ title, says }) {
24
24
  return (_jsxs(YStack, { gap: "$1", pb: "$4", children: [_jsx(SizableText, { render: "h1", size: "$6", color: "$ink", children: title }), _jsx(SizableText, { size: "$2", color: "$soft", children: says })] }));
25
25
  }
@@ -134,13 +134,14 @@ export function Sites() {
134
134
  * anchored at its top edge, so nothing of the page's header is cropped away.
135
135
  */
136
136
  function Shot({ slug }) {
137
- const [gone, setGone] = useState(false);
138
- return (_jsxs(YStack, { width: "100%", aspectRatio: 16 / 10, bg: "$hover", items: "center", justify: "center", position: "relative", overflow: "hidden", children: [_jsxs(YStack, { items: "center", gap: "$2", opacity: 0.6, children: [_jsx(Boxes, { size: 24 }), _jsx(SizableText, { size: "$1", color: "$soft", textTransform: "uppercase", letterSpacing: 1, children: slug })] }), gone ? null : (_jsx("img", { src: `${SHOTS}/${encodeURIComponent(slug)}.webp`, alt: "", loading: "lazy", onError: () => setGone(true), style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'top' } }))] }));
137
+ const [step, setStep] = useState(0);
138
+ const base = SHOTS[step];
139
+ return (_jsxs(YStack, { width: "100%", aspectRatio: 16 / 10, bg: "$hover", items: "center", justify: "center", position: "relative", overflow: "hidden", children: [_jsxs(YStack, { items: "center", gap: "$2", opacity: 0.6, children: [_jsx(Boxes, { size: 24 }), _jsx(SizableText, { size: "$1", color: "$soft", textTransform: "uppercase", letterSpacing: 1, children: slug })] }), base ? (_jsx("img", { src: `${base}/${encodeURIComponent(slug)}.webp`, alt: "", loading: "lazy", onError: () => setStep((s) => s + 1), style: { position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'top' } })) : null] }));
139
140
  }
140
141
  export function Templates() {
141
142
  const { t: say } = useI18n();
142
143
  const t = useTarget();
143
144
  const list = useRead(() => templates(t), [], [t.api]);
144
145
  const { busy, failed, take } = useFork();
145
- return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$6", items: "center", children: _jsxs(YStack, { width: "100%", maxW: 1080, children: [_jsx(Head, { title: say('Templates'), says: `${say('Start from a working app.')} ${say('Picking one copies its repository into a project of yours.')}` }), failed ? (_jsx(SizableText, { size: "$2", color: "$soft", role: "status", pb: "$3", children: failed })) : null, list.error ? (_jsx(SizableText, { size: "$2", color: "$soft", children: say(list.error.message) })) : list.loading && !list.value.length ? (_jsx(SizableText, { size: "$2", color: "$soft", children: say('Reading templates…') })) : !list.value.length ? (_jsx(SizableText, { size: "$2", color: "$soft", children: `${say('No templates here right now.')} ${say('The whole catalog has more.')}` })) : (_jsx(XStack, { flexWrap: "wrap", gap: "$3", children: list.value.map((x) => (_jsxs(Card, { label: say('Start from {template}', { template: x.title }), onPress: () => void take(x.slug), children: [_jsx(Shot, { slug: x.slug }), _jsxs(YStack, { p: "$3", gap: "$1", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { size: "$3", color: "$ink", numberOfLines: 1, flex: 1, children: busy === x.slug ? say('Copying…') : x.title }), x.framework ? (_jsx(SizableText, { size: "$1", color: "$soft", children: x.framework })) : null] }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 2, children: x.description })] })] }, x.slug))) })), _jsx(YStack, { pt: "$5", children: _jsxs(Out, { href: "https://gallery.hanzo.ai", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: say('The whole catalog') }), _jsx(ExternalLink, { size: 12, opacity: 0.6 })] }) })] }) }));
146
+ return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$6", items: "center", children: _jsxs(YStack, { width: "100%", maxW: 1080, children: [_jsx(Head, { title: say('Templates'), says: `${say('Start from a working app.')} ${say('Picking one copies its repository into a project of yours.')}` }), failed ? (_jsx(SizableText, { size: "$2", color: "$soft", role: "status", pb: "$3", children: failed })) : null, list.error ? (_jsx(SizableText, { size: "$2", color: "$soft", children: say(list.error.message) })) : list.loading && !list.value.length ? (_jsx(SizableText, { size: "$2", color: "$soft", children: say('Reading templates…') })) : !list.value.length ? (_jsx(SizableText, { size: "$2", color: "$soft", children: `${say('No templates here right now.')} ${say('The whole catalog has more.')}` })) : (_jsx(XStack, { flexWrap: "wrap", gap: "$3", children: list.value.map((x) => (_jsxs(Card, { label: say('Start from {template}', { template: x.title }), onPress: () => void take(x.slug), children: [_jsx(Shot, { slug: x.slug }), _jsxs(YStack, { p: "$3", gap: "$1", children: [_jsx(SizableText, { size: "$3", color: "$ink", numberOfLines: 1, children: busy === x.slug ? say('Copying…') : x.title }), x.framework ? (_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: x.framework })) : null, _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 2, children: x.description })] })] }, x.slug))) })), _jsx(YStack, { pt: "$5", children: _jsxs(Out, { href: "https://gallery.hanzo.ai", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: say('The whole catalog') }), _jsx(ExternalLink, { size: 12, opacity: 0.6 })] }) })] }) }));
146
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/build",
3
- "version": "0.2.120",
3
+ "version": "0.2.122",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "description": "Hanzo Build — say what you want, watch it built, deployed and running. The builder as a component, mounted by the Hanzo app at hanzo.ai.",