@hanzo/build 0.2.121 → 0.2.123

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.
package/lib/data.js CHANGED
@@ -11,6 +11,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
11
11
  import { places } from './api/places.js';
12
12
  import { projects } from './api/projects.js';
13
13
  import { get, list, watch } from './api/sessions.js';
14
+ import { TALK } from './api/talk.js';
14
15
  import { merge } from './api/turn.js';
15
16
  /** Run `load` whenever `key` changes (and on `reload`), keeping the last good value. */
16
17
  export function useRead(load, initial, key) {
@@ -114,13 +115,39 @@ export function useCached(key, load, initial, wait = WAIT) {
114
115
  }, [key, tick, wait]);
115
116
  return { value, error, loading, reload };
116
117
  }
118
+ /** Last coding runs read per `api\norg`, so mounting another rail or switching tabs starts warm. */
119
+ const recentRuns = new Map();
117
120
  /**
118
- * The org's coding runs, newest first, kept current by the org's own session
119
- * stream: a status that moves moves its dot, and a run started anywhere appears.
121
+ * The org's conversations and coding runs, newest first, kept current by the
122
+ * org's own session stream: a status that moves moves its dot, and one started
123
+ * anywhere appears. A conversation's own coding runs are in its tree, not here:
124
+ * the platform lists roots.
120
125
  */
121
126
  export function useRecents(t, signed) {
122
- const read = useRead(signed ? () => list(t, { kind: 'coding', limit: 50 }) : null, [], [t, signed]);
123
- const [rows, setRows] = useState([]);
127
+ const scope = signed ? `${t.api}\n${t.org ?? ''}` : null;
128
+ const warm = scope !== null ? recentRuns.get(scope) : undefined;
129
+ const read = useRead(signed
130
+ ? async () => {
131
+ const [runs, talked] = await Promise.all([list(t, { kind: 'coding', limit: 50 }), list(t, { channel: TALK, limit: 50 })]);
132
+ const seen = new Set();
133
+ const next = [...runs, ...talked]
134
+ .filter((s) => !seen.has(s.id) && Boolean(seen.add(s.id)))
135
+ .sort((a, b) => b.createdAt.localeCompare(a.createdAt))
136
+ .slice(0, 50);
137
+ if (scope !== null)
138
+ recentRuns.set(scope, next);
139
+ return next;
140
+ }
141
+ : null, warm ?? [], [t.api, t.org, signed]);
142
+ const [settled, setSettled] = useState(warm !== undefined);
143
+ useEffect(() => {
144
+ setSettled(scope !== null && recentRuns.has(scope));
145
+ }, [scope]);
146
+ useEffect(() => {
147
+ if (!read.loading)
148
+ setSettled(true);
149
+ }, [read.loading]);
150
+ const [rows, setRows] = useState(() => warm ?? read.value);
124
151
  useEffect(() => setRows(read.value), [read.value]);
125
152
  const last = useRef(0);
126
153
  // useRead's reload is the same function every render, so it never reopens the feed.
@@ -143,7 +170,8 @@ export function useRecents(t, signed) {
143
170
  const i = prev.findIndex((r) => r.id === s.id);
144
171
  if (i === -1) {
145
172
  // A run this list has not seen: re-read rather than guess its kind.
146
- reload();
173
+ if (!s.kind || s.kind === 'coding')
174
+ reload();
147
175
  return prev;
148
176
  }
149
177
  const next = prev.slice();
@@ -159,7 +187,7 @@ export function useRecents(t, signed) {
159
187
  });
160
188
  return () => ctl.abort();
161
189
  }, [t, signed, again]);
162
- return { ...read, value: rows };
190
+ return { ...read, value: rows, loading: read.loading && !settled };
163
191
  }
164
192
  export function usePlaces(t, signed) {
165
193
  return useRead(signed ? () => places(t) : null, [], [t, signed]);
@@ -201,14 +229,17 @@ export function useRun(t, id) {
201
229
  const [refused, setRefused] = useState('');
202
230
  const reload = useRef(detail.reload);
203
231
  reload.current = detail.reload;
232
+ // The stream is followed by the run's tree: a conversation's coding run is in the
233
+ // conversation's (talk.ts), and its frames carry that root.
234
+ const root = (detail.value?.id === id && detail.value.root) || id;
204
235
  useEffect(() => {
205
236
  setLive([]);
206
237
  setPushed(null);
207
238
  setRefused('');
208
- if (!id)
239
+ if (!id || !root)
209
240
  return;
210
241
  const ctl = new AbortController();
211
- void watch(t, id, {
242
+ void watch(t, root, {
212
243
  // A frame from a stream this run has already left is not this run's.
213
244
  event: (e) => {
214
245
  if (!ctl.signal.aborted && e.sessionId === id)
@@ -218,13 +249,15 @@ export function useRun(t, id) {
218
249
  if (!ctl.signal.aborted && s.id === id)
219
250
  setPushed(s);
220
251
  },
252
+ // A reconnect may have missed frames, and so may the move to the run's
253
+ // own tree once its read named one: either is read again.
221
254
  open: (n) => {
222
- if (n > 0)
255
+ if (n > 0 || root !== id)
223
256
  reload.current();
224
257
  },
225
258
  }, ctl.signal).catch((e) => setRefused(e.message));
226
259
  return () => ctl.abort();
227
- }, [t, id]);
260
+ }, [t, id, root]);
228
261
  // The read and the frames describe THIS run or nothing: a read kept from the
229
262
  // run before (it stays until the next one lands, or forever if it fails) must
230
263
  // not lend this run its pull request.
package/lib/index.d.ts CHANGED
@@ -28,7 +28,7 @@ export { Editor } from './automations.tsx';
28
28
  export { library, nav, NEW, own, sections, tabs, useScheduled, type Group } from './nav.tsx';
29
29
  export { MARKS, type Icon, type Mark } from './marks.tsx';
30
30
  export { useFunds, type Funds } from './mind.ts';
31
- export { DevSection, DOTS, useSessions } from './section.tsx';
31
+ export { DevSection, dot, DOTS, useSessions } from './section.tsx';
32
32
  export { HostProvider } from './host.tsx';
33
33
  export { Slack, useWho, Who } from './foot.tsx';
34
34
  export { Grip, type GripProps } from '@hanzo/ui';
@@ -43,6 +43,7 @@ export type { Limits } from './api/limits.ts';
43
43
  export type { Target } from './api/call.ts';
44
44
  export type { Browse, Browser, Host, Person, Shown } from './host.tsx';
45
45
  export type { Session, Status } from './api/sessions.ts';
46
+ export { talks } from './api/talk.ts';
46
47
  export type { Read } from './data.ts';
47
48
  export { href, parse, path, PLACES, route, SESSION, SLUG, type Route, type Screen } from './route.ts';
48
49
  /**
package/lib/index.js CHANGED
@@ -28,7 +28,7 @@ export { Editor } from './automations.js';
28
28
  export { library, nav, NEW, own, sections, tabs, useScheduled } from './nav.js';
29
29
  export { MARKS } from './marks.js';
30
30
  export { useFunds } from './mind.js';
31
- export { DevSection, DOTS, useSessions } from './section.js';
31
+ export { DevSection, dot, DOTS, useSessions } from './section.js';
32
32
  export { HostProvider } from './host.js';
33
33
  export { Slack, useWho, Who } from './foot.js';
34
34
  export { Grip } from '@hanzo/ui';
@@ -39,6 +39,7 @@ export { Plan } from './settings/plan.js';
39
39
  export { Credits, SEPARATE } from './settings/credits.js';
40
40
  export { useStanding, rows, left } from './standing.js';
41
41
  export { kind, label, said, share, spent, ways, when } from './plan.js';
42
+ export { talks } from './api/talk.js';
42
43
  export { href, parse, path, PLACES, route, SESSION, SLUG } from './route.js';
43
44
  /**
44
45
  * What Chat draws the same way (@hanzo/rooms imports these): the model and
package/lib/landing.js CHANGED
@@ -7,10 +7,11 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
7
7
  * composer Chat draws too (@hanzo/ui/chat): Dev hands it the three pills, the
8
8
  * chips that go to its repositories, issues and templates, and its commands.
9
9
  *
10
- * Sending starts a coding run on a project and opens it. A project is a
11
- * repository — the org's on the forge, or one its GitHub grants — so a run
12
- * names one, and an ask with none chosen opens the picker rather than making a
13
- * project up from its words. The choices a person made here are kept in this
10
+ * Sending opens a conversation (api/talk.ts) and goes to it: the agent answers,
11
+ * and decides for itself when the ask needs a sandbox or a coding run — on the
12
+ * repository, branch and machine chosen here, and only planning when Plan is on.
13
+ * A run on one of the org's machines needs a repository, so an ask with none
14
+ * chosen there opens the picker rather than making a project up from its words. The choices a person made here are kept in this
14
15
  * browser, per org, so the next New starts where the last one did — and a kept
15
16
  * repository New can no longer offer is let go, so the next run is not sent
16
17
  * back to it. A repository can also be given by its address (Use a git URL).
@@ -29,6 +30,7 @@ import { useLimits } from '@hanzo/ui/product/useLimits';
29
30
  import { useDictation, useTalk, useVoice } from '@hanzo/voice';
30
31
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
31
32
  import { start, unhonoured } from './api/coding.js';
33
+ import { say } from './api/talk.js';
32
34
  import { asRepo, chosen, codebases, one } from './api/codebases.js';
33
35
  import { heard, repos as githubRepos } from './api/github.js';
34
36
  import { plain, read, SETUP, unset } from './api/environment.js';
@@ -272,19 +274,18 @@ export function Landing({ onStarted }) {
272
274
  setNote(prepped.reply.split('```')[0].trim());
273
275
  return;
274
276
  }
275
- // Manual: the run is asked for before it starts; it edits, commits and pushes on its own once it has.
276
- if (!(await carry.allow({ id: 'run', name: t('Dev to start this run'), note: t('It edits, tests, commits and pushes its own branch') }))) {
277
- setNote(t('Not started.'));
278
- return;
279
- }
280
- const run = await start(target, {
281
- prompt: compose([said.trim(), carry.text, prepped.system ?? ''].filter(Boolean).join('\n\n---\n'), files),
277
+ // The first thing said opens a conversation (api/talk.ts) and starts nothing:
278
+ // the agent answers, and leases a sandbox or starts a coding run only when the
279
+ // ask needs one — on the repository, branch, machine and Plan chosen here.
280
+ const sent = await say(target, {
281
+ input: compose([said.trim(), carry.text, prepped.system ?? ''].filter(Boolean).join('\n\n---\n'), files),
282
282
  // The name alone. The org rides the request, and a slash is not a repo name.
283
283
  // An empty base or place is not sent: the default branch, and the sandbox.
284
284
  repo: repo?.name ?? hub?.full_name,
285
285
  base: repo ? kept.branch : hub ? kept.branch || hub.default_branch : undefined,
286
- targetId: place.id,
287
- mode,
286
+ target: place.id,
287
+ // The mode the composer shows: Auto starts a build, Manual asks first, Plan only plans.
288
+ mode: carry.mode.value === 'manual' ? 'manual' : mode === 'plan' ? 'plan' : 'auto',
288
289
  model: mind.model,
289
290
  effort: level(mind.effort),
290
291
  issue,
@@ -292,7 +293,7 @@ export function Landing({ onStarted }) {
292
293
  setDraft('');
293
294
  setFiles([]);
294
295
  setIssue(0);
295
- onStarted(run.session);
296
+ onStarted(sent.session);
296
297
  }
297
298
  catch (e) {
298
299
  setNote(plain(e, repo?.name ?? hub?.full_name ?? t('a new project'), 'run', t));
package/lib/mind.d.ts CHANGED
@@ -38,6 +38,8 @@ export interface Choice {
38
38
  export declare const FIRST: Choice;
39
39
  /** Whether a plan grants only Enso Auto. An unknown plan is not taken for Free. */
40
40
  export declare const isFree: (plan: string | null | undefined) => boolean;
41
+ /** Whether third-party cloud models are enabled in Settings → Preferences (off by default). */
42
+ export declare function allowThirdPartyModels(): boolean;
41
43
  /** The kept choice, Enso and Auto where nothing is kept. Stable while the stored text is. Low and Medium, offered once, read as Auto. */
42
44
  export declare function kept(): Choice;
43
45
  /** Keep a change, in this browser, for every surface that reads it. */
package/lib/mind.js CHANGED
@@ -14,6 +14,31 @@ export const FIRST = { model: ENSO, effort: 'auto' };
14
14
  export const isFree = (plan) => plan === 'free';
15
15
  const KEY = 'hanzo.mind';
16
16
  const CHANGE = 'hanzo:mind';
17
+ const PREFS_KEY = 'hanzo.chat.preferences';
18
+ const PREFS_EVENT = 'hanzo:chat:preferences';
19
+ /** Whether third-party cloud models are enabled in Settings → Preferences (off by default). */
20
+ export function allowThirdPartyModels() {
21
+ try {
22
+ const v = JSON.parse(store()?.getItem(PREFS_KEY) ?? 'null');
23
+ return v?.thirdPartyChosen ? Boolean(v.allowThirdPartyModels) : v?.allowThirdPartyModels === true;
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ }
29
+ function useAllowThirdPartyModels() {
30
+ const [allowed, setAllowed] = useState(allowThirdPartyModels);
31
+ useEffect(() => {
32
+ const sync = () => setAllowed(allowThirdPartyModels());
33
+ window.addEventListener(PREFS_EVENT, sync);
34
+ window.addEventListener('storage', sync);
35
+ return () => {
36
+ window.removeEventListener(PREFS_EVENT, sync);
37
+ window.removeEventListener('storage', sync);
38
+ };
39
+ }, []);
40
+ return allowed;
41
+ }
17
42
  /** An effort kept, read back: one the ladder still offers, XHigh (which Max replaced) as Max, else Auto. */
18
43
  const effortOf = (v) => (v === 'xhigh' ? 'max' : EFFORTS.some((e) => e.id === v) ? v : FIRST.effort);
19
44
  /** The store, or null where the browser gives none (a server render, blocked site data). */
@@ -233,6 +258,7 @@ function settleReturn() {
233
258
  export function useMind(t, plan, topUp) {
234
259
  const [choice, change] = useChoice();
235
260
  const { models, list, loading, error, note } = useCatalog(t);
261
+ const allowThirdParty = useAllowThirdPartyModels();
236
262
  const free = isFree(plan);
237
263
  const [picked, pick] = usePick(choice.model, (id) => change({ model: id }), list);
238
264
  // Another maker's model is paid from the balance on any plan; Hanzo's own follow the plan.
@@ -240,6 +266,7 @@ export function useMind(t, plan, topUp) {
240
266
  const cents = funds.cents;
241
267
  const may = (id) => sendable(free, models, cents, id);
242
268
  const model = may(picked) ? picked : ENSO;
269
+ const listed = allowThirdParty ? models : models.filter((m) => !thirdParty(m) || m.id === model);
243
270
  // A top-up returns to this address with the model it was for: pick it once the balance can pay.
244
271
  const [back] = useState(returned);
245
272
  useEffect(() => {
@@ -254,7 +281,7 @@ export function useMind(t, plan, topUp) {
254
281
  return {
255
282
  model,
256
283
  effort: choice.effort,
257
- models,
284
+ models: listed,
258
285
  loading,
259
286
  error,
260
287
  note,
package/lib/project.js CHANGED
@@ -49,12 +49,14 @@ import { Attachments, CHAT, Console, DEVICES, Feedback, FileTabs, FileTree, Page
49
49
  import { Composer, Message } from '@hanzo/ui/chat';
50
50
  import { Button, Dialog, DialogContent, DialogTitle } from '@hanzo/ui';
51
51
  import { HanzoMark } from '@hanzo/ui/product';
52
+ import { useLimits } from '@hanzo/ui/product/useLimits';
52
53
  import { useDictation, useVoice } from '@hanzo/voice';
53
54
  import { useEffect, useMemo, useRef, useState } from 'react';
54
55
  import { read as pushed } from './api/changes.js';
55
56
  import { codebases, one } from './api/codebases.js';
56
57
  import { start } from './api/coding.js';
57
58
  import { blob, tree } from './api/git.js';
59
+ import { limits as readLimits } from './api/models.js';
58
60
  import { declare } from './api/platform.js';
59
61
  import { address, deployments, name as repoName, ours, templates } from './api/projects.js';
60
62
  import { list, message, stop } from './api/sessions.js';
@@ -206,7 +208,8 @@ export function Project({ at }) {
206
208
  const [picked, setPicked] = useState([]);
207
209
  const [attached, setAttached] = useState([]);
208
210
  // The model and effort Chat and New share, and dictation into the ask.
209
- const mind = useMind(target);
211
+ const { limits } = useLimits(signed ? (signal) => readLimits(target, signal) : null, target);
212
+ const mind = useMind(target, limits?.plan, host.topUp);
210
213
  const voice = useVoice({ speech: useEar(target), language: useSpoken(), ...useDictation(draft, setDraft) });
211
214
  const [bridge, setBridge] = useState(false);
212
215
  const [editing, setEditing] = useState(false);
package/lib/run.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** One session's page: a conversation (talk.tsx) or one run, as its record says. */
1
2
  export declare function Run({ id }: {
2
3
  id: string;
3
4
  }): import("react").JSX.Element;
package/lib/run.js CHANGED
@@ -39,6 +39,7 @@ import { approve, followUp, headline, retry, start, steer } from './api/coding.j
39
39
  import { limits as readLimits } from './api/models.js';
40
40
  import { list, message, pause, publish, rename, resume, stop, story, took } from './api/sessions.js';
41
41
  import { answer, cards, followed, outcome, pull, settled, steps } from './api/turn.js';
42
+ import { answer as reply, say as talk, talks } from './api/talk.js';
42
43
  import { verdict } from './api/verdict.js';
43
44
  import { useKept, useProjects, useRead, useRun } from './data.js';
44
45
  import { Desk, SEED } from './desk.js';
@@ -54,6 +55,7 @@ import { schedule } from './scheduled.js';
54
55
  import { SideProvider, useSplit } from './side.js';
55
56
  import { PAGE, useDeck, useKey, usePanel } from './tabs.js';
56
57
  import { carrying, compose, pick } from './tools.js';
58
+ import { Talk } from './talk.js';
57
59
  import { Transcript } from './transcript.js';
58
60
  const LIVE = new Set(['running', 'paused', '']);
59
61
  /** A run's status as the line under its title says it; one the service adds later is drawn as it comes. */
@@ -64,13 +66,20 @@ const STATUS = {
64
66
  error: phrase('error'),
65
67
  stopped: phrase('stopped'),
66
68
  };
69
+ /** One session's page: a conversation (talk.tsx) or one run, as its record says. */
67
70
  export function Run({ id }) {
68
- const { t: say } = useI18n();
69
71
  const host = useHost();
70
72
  const t = useTarget();
71
73
  // Signed out, there is nothing to read: the gateway answers a bare run with a refusal.
74
+ const state = useRun(t, host.person ? id : null);
75
+ return talks(state.record) ? _jsx(Talk, { id: id, state: state }) : _jsx(Job, { id: id, state: state });
76
+ }
77
+ function Job({ id, state: read }) {
78
+ const { t: say } = useI18n();
79
+ const host = useHost();
80
+ const t = useTarget();
72
81
  const signed = Boolean(host.person);
73
- const { detail, record, events, status, refused } = useRun(t, signed ? id : null);
82
+ const { detail, record, events, status, refused } = read;
74
83
  const [draft, setDraft] = useState('');
75
84
  const [files, setFiles] = useState([]);
76
85
  const [note, setNote] = useState('');
@@ -100,8 +109,8 @@ export function Run({ id }) {
100
109
  const wakeLockRef = useRef(null);
101
110
  const [nowMs, setNowMs] = useState(() => Date.now());
102
111
  // The model and effort a run started here uses: the one choice Chat and New share.
103
- const mind = useMind(t);
104
112
  const { limits } = useLimits(signed ? (signal) => readLimits(t, signal) : null, t);
113
+ const mind = useMind(t, limits?.plan, host.topUp);
105
114
  const voice = useVoice({ speech: useEar(t), language: useSpoken(), ...useDictation(draft, setDraft) });
106
115
  const listen = useMemo(() => speaker(t), [t]);
107
116
  const mode = record?.mode ?? '';
@@ -240,6 +249,18 @@ export function Run({ id }) {
240
249
  throw new Error(say('This run is still being read'));
241
250
  if (paused)
242
251
  await stop(t, id, 'Continued in a follow-up run').catch(() => undefined);
252
+ // A run a conversation started is carried on by the conversation (talk.ts): the
253
+ // words go there, in its session, and so does the reader.
254
+ if (record?.parent) {
255
+ const words = how === 'approve' ? `Carry out this plan:\n\n${said.trim()}` : said.trim() || 'Continue where the run left off.';
256
+ // Approving the plan is going ahead: the conversation leaves Plan for Auto, so
257
+ // the run it starts builds.
258
+ await talk(t, { session: record.parent, input: words, model: mind.model, effort: level(mind.effort), ...(how === 'approve' ? { mode: 'auto' } : {}) });
259
+ setDraft('');
260
+ setFiles([]);
261
+ host.go(record.parent);
262
+ return '';
263
+ }
243
264
  const ask = how === 'approve' ? approve(earlier, said) : how === 'retry' ? retry(earlier, said) : followUp(earlier, said);
244
265
  const run = await start(t, tuned(ask));
245
266
  setDraft('');
@@ -461,7 +482,9 @@ export function Run({ id }) {
461
482
  ? say('Add a follow up for the setup agent')
462
483
  : say('Add a follow up')
463
484
  : finished
464
- ? say('Follow up — continues in a new run')
485
+ ? record?.parent
486
+ ? say('Follow up — continues the conversation')
487
+ : say('Follow up — continues in a new run')
465
488
  : say('Reading this run…');
466
489
  const desk_ = (sheet) => (_jsx(Desk, { id: id, repo: record?.repo ?? '', branch: record?.branch ?? '', base: record?.base ?? '', environment: record?.environment ?? '', mode: mode, pr: pr, title: title, project: record?.project ?? '', sandbox: record?.sandbox ?? '', site: site, published: end.published, events: events, live: running, menu: [...manage, ...sharing], refused: signed ? refused || (detail.error ? say(detail.error.message) : '') : say('Sign in to follow this run.'), retry: signed ? say('Retry') : say('Sign in'), onRetry: signed ? detail.reload : () => host.signIn?.(), side: side, sheet: sheet, onHide: () => setDesk(false), envColumn: envColumn, splitPanes: splitPanes, onCloseSplitPane: (pid) => setSplitPanes((prev) => prev.filter((k) => k !== pid)), onExpandSplitPane: (pid) => {
467
490
  setSplitPanes([]);
@@ -528,7 +551,9 @@ export function Run({ id }) {
528
551
  ? `${say('This run stopped with an error.')} ${say('Its work so far is on its branch.')}`
529
552
  : `${say('This run stopped with an error.')} ${say('It saved nothing to its branch, so Try again starts over.')}` })) : null,
530
553
  // A paused run's agent was stopped where it stood; what it was running is cut off.
531
- live: running && !paused, header: hidden ? (_jsx(SizableText, { size: "$1", color: "$soft", children: `${hidden === 1 ? say('{n} earlier turn is not shown.', { n: hidden }) : say('{n} earlier turns are not shown.', { n: hidden })} ${say('The run’s Git tab has everything it pushed.')}` })) : null, onApprove: planned && earlier ? (p) => void act(() => carry(p, 'approve')) : undefined, approving: busy, onVerdict: (v) => verdict(t, id, record?.project ?? '', v), empty: signed ? (_jsx(SizableText, { size: "$2", color: "$soft", children: detail.error
554
+ live: running && !paused, header: hidden ? (_jsx(SizableText, { size: "$1", color: "$soft", children: `${hidden === 1 ? say('{n} earlier turn is not shown.', { n: hidden }) : say('{n} earlier turns are not shown.', { n: hidden })} ${say('The run’s Git tab has everything it pushed.')}` })) : null, onApprove: planned && earlier ? (p) => void act(() => carry(p, 'approve')) : undefined,
555
+ // What dev asks its person while it works (its ask tool), answered here.
556
+ onAnswer: signed ? (q, label) => void act(async () => (await reply(t, id, q, label, true), '')) : undefined, approving: busy, onVerdict: (v) => verdict(t, id, record?.project ?? '', v), empty: signed ? (_jsx(SizableText, { size: "$2", color: "$soft", children: detail.error
532
557
  ? say(detail.error.message)
533
558
  : detail.loading
534
559
  ? say('Reading this run…')
package/lib/section.d.ts CHANGED
@@ -5,6 +5,11 @@ import { type Read } from './data.ts';
5
5
  import type { Host } from './host.tsx';
6
6
  /** A run's status, as the rail's dot draws it. Anything else is idle. */
7
7
  export declare const DOTS: Record<string, SessionStatus>;
8
+ /**
9
+ * The dot a row draws. A conversation rests paused between turns (api/talk.ts):
10
+ * it has answered and waits for the person, which reads as done, not as a run held.
11
+ */
12
+ export declare const dot: (s: Pick<Session, 'status' | 'channel' | 'parent'>) => SessionStatus;
8
13
  /** The org's coding runs, newest first, kept live by the org's feed. */
9
14
  export declare function useSessions(host: Host): Read<Session[]>;
10
15
  /**
package/lib/section.js CHANGED
@@ -14,6 +14,7 @@ import { SizableText } from '@hanzo/gui';
14
14
  import { useI18n } from '@hanzo/i18n/react';
15
15
  import { SidebarItem, SidebarSection, StatusDot } from '@hanzo/ui/chat';
16
16
  import { useMemo } from 'react';
17
+ import { talks } from './api/talk.js';
17
18
  import { useRecents } from './data.js';
18
19
  import { nav } from './nav.js';
19
20
  import { route } from './route.js';
@@ -25,6 +26,11 @@ export const DOTS = {
25
26
  stopped: 'stopped',
26
27
  error: 'error',
27
28
  };
29
+ /**
30
+ * The dot a row draws. A conversation rests paused between turns (api/talk.ts):
31
+ * it has answered and waits for the person, which reads as done, not as a run held.
32
+ */
33
+ export const dot = (s) => talks(s) && s.status === 'paused' ? 'done' : (DOTS[s.status] ?? 'idle');
28
34
  /** The org's coding runs, newest first, kept live by the org's feed. */
29
35
  export function useSessions(host) {
30
36
  const t = useMemo(() => ({ api: host.api, token: host.token, org: host.org }), [host.api, host.token, host.org]);
@@ -46,7 +52,7 @@ export function DevSection({ host, onPick, label, children, }) {
46
52
  press?.();
47
53
  onPick?.();
48
54
  };
49
- return (_jsxs(_Fragment, { children: [nav(host, host.go, t).map((g) => (_jsx(SidebarSection, { label: g.label, children: g.links.map((l) => (_jsx(SidebarItem, { icon: l.icon, active: l.active, onPress: then(l.onPress), children: l.label }, l.id))) }, g.id))), children, _jsx(SidebarSection, { label: label ?? t('Runs'), children: !host.person ? (_jsx(Note, { children: t('Sign in to see your runs.') })) : sessions.value.length ? (sessions.value.map((s) => (_jsx(SidebarItem, { icon: _jsx(StatusDot, { status: DOTS[s.status] ?? 'idle' }), active: r.kind === 'run' && r.id === s.id, onPress: then(() => host.go(s.id)), children: s.title || t('Untitled run') }, s.id)))) : (_jsx(Note, { children: sessions.error
55
+ return (_jsxs(_Fragment, { children: [nav(host, host.go, t).map((g) => (_jsx(SidebarSection, { label: g.label, children: g.links.map((l) => (_jsx(SidebarItem, { icon: l.icon, active: l.active, onPress: then(l.onPress), children: l.label }, l.id))) }, g.id))), children, _jsx(SidebarSection, { label: label ?? t('Runs'), children: !host.person ? (_jsx(Note, { children: t('Sign in to see your runs.') })) : sessions.value.length ? (sessions.value.map((s) => (_jsx(SidebarItem, { icon: _jsx(StatusDot, { status: dot(s) }), active: r.kind === 'run' && r.id === s.id, onPress: then(() => host.go(s.id)), children: s.title || t('Untitled run') }, s.id)))) : (_jsx(Note, { children: sessions.error
50
56
  ? t(sessions.error.message)
51
57
  : sessions.loading
52
58
  ? t('Reading…')
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/lib/talk.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { type RunState } from './data.ts';
2
+ export declare function Talk({ id, state }: {
3
+ id: string;
4
+ state: RunState;
5
+ }): import("react").JSX.Element;
package/lib/talk.js ADDED
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A conversation in Dev (api/talk.ts): what the person said and what the agent
4
+ * answered, at one address however many turns it takes — the way Chat reads.
5
+ *
6
+ * Every send continues the same session. While a turn works, what is said is that
7
+ * turn's next input; once it has answered, the next turn. A build is never steered
8
+ * from here — the words are the conversation's, and a build is steered from its
9
+ * own page, which its card opens. The agent decides what a turn needs: an answer,
10
+ * a sandbox (leased on first use and kept for the conversation), or a coding run,
11
+ * whose outcome is said here when it ends. A question a turn asks — in Manual,
12
+ * whether a build may start — is answered on its card. The line under the
13
+ * transcript is what the turn is doing now, from its own progress. The mode pill
14
+ * is the conversation's: Plan, Auto or Manual, kept from the turn it is sent with.
15
+ */
16
+ import { SizableText, XStack, YStack } from '@hanzo/gui';
17
+ import { useI18n } from '@hanzo/i18n/react';
18
+ import { Steer } from '@hanzo/ui/agents';
19
+ import { Composer, measure } from '@hanzo/ui/chat';
20
+ import { useLimits } from '@hanzo/ui/product/useLimits';
21
+ import { useMemo, useState } from 'react';
22
+ import { DEV_MODES, MODES } from './gear.js';
23
+ import { Refusal } from './api/call.js';
24
+ import { limits as readLimits } from './api/models.js';
25
+ import { log, message, stop } from './api/sessions.js';
26
+ import { answer, now, say as talk } from './api/talk.js';
27
+ import { cards, merge } from './api/turn.js';
28
+ import { verdict } from './api/verdict.js';
29
+ import { useRead } from './data.js';
30
+ import { useHost, useTarget } from './host.js';
31
+ import { level, useMind } from './mind.js';
32
+ import { pane } from './pane.js';
33
+ import { speaker } from './reply.js';
34
+ import { carrying, compose, pick } from './tools.js';
35
+ import { Transcript } from './transcript.js';
36
+ export function Talk({ id, state }) {
37
+ const { t: say } = useI18n();
38
+ const host = useHost();
39
+ const t = useTarget();
40
+ const signed = Boolean(host.person);
41
+ const { detail, record, status, refused } = state;
42
+ // The whole conversation from its first word: the detail carries the latest
43
+ // fifty events, and a turn that builds says many. Live frames are added to it.
44
+ const whole = useRead(signed ? () => log(t, id) : null, [], [t, id, signed]);
45
+ const events = useMemo(() => merge(whole.value, state.events), [whole.value, state.events]);
46
+ const [draft, setDraft] = useState('');
47
+ const [files, setFiles] = useState([]);
48
+ const [note, setNote] = useState('');
49
+ const [busy, setBusy] = useState(false);
50
+ const { limits } = useLimits(signed ? (signal) => readLimits(t, signal) : null, t);
51
+ const mind = useMind(t, limits?.plan, host.topUp);
52
+ const listen = useMemo(() => speaker(t), [t]);
53
+ const shown = useMemo(() => cards(events, '', say), [events, say]);
54
+ const working = status === 'running';
55
+ const doing = useMemo(() => now(events), [events]);
56
+ // The conversation's mode, as it keeps it until the person picks another: what
57
+ // they pick is sent with what they say next, and kept for every turn after.
58
+ const [picked, setPicked] = useState(null);
59
+ const mode = picked ?? (DEV_MODES.includes(record?.mode) ? record?.mode : 'auto');
60
+ /** One act at a time; what it answers, or the reason it was refused, is the note. */
61
+ const act = async (work) => {
62
+ if (busy)
63
+ return;
64
+ setBusy(true);
65
+ setNote('');
66
+ try {
67
+ setNote(await work());
68
+ }
69
+ catch (e) {
70
+ setNote(e.message);
71
+ }
72
+ finally {
73
+ setBusy(false);
74
+ }
75
+ };
76
+ const send = () => {
77
+ const words = compose(draft.trim(), files);
78
+ if (!words)
79
+ return;
80
+ const next = () => talk(t, { session: id, input: words, model: mind.model, effort: level(mind.effort), ...(picked ? { mode: picked } : {}) });
81
+ void act(async () => {
82
+ if (!working)
83
+ await next();
84
+ else
85
+ try {
86
+ await message(t, id, words);
87
+ }
88
+ catch (e) {
89
+ // The turn answered as the words were sent: they are the next turn.
90
+ if (!(e instanceof Refusal) || e.status !== 409)
91
+ throw e;
92
+ await next();
93
+ }
94
+ setDraft('');
95
+ setFiles([]);
96
+ return '';
97
+ });
98
+ };
99
+ const empty = (_jsx(SizableText, { size: "$2", color: "$soft", children: !signed ? say('Sign in to follow this conversation.') : detail.error ? say(detail.error.message) : detail.loading ? say('Reading this conversation…') : say('Thinking…') }));
100
+ return (_jsxs(YStack, { "data-slot": "talk", ...pane, display: "grid", gridTemplateRows: "auto minmax(0, 1fr) auto", width: "100%", height: "100%", minH: 0, minW: 0, children: [_jsx(XStack, { px: "$4", pt: "$3", pb: "$2", items: "center", minH: 44, children: _jsx(SizableText, { size: "$4", color: "$ink", numberOfLines: 1, children: record?.title || say('New conversation') }) }), _jsx(Transcript, { cards: shown, live: working, empty: empty, listen: signed ? listen : undefined, onVerdict: (v) => verdict(t, id, '', v), onRun: (session) => host.go(session), onAnswer: (question, label) => void act(async () => (await answer(t, id, question, label, true), '')) }), _jsxs(YStack, { pb: "$3", pt: "$2", gap: "$2", children: [_jsxs(YStack, { ...measure, gap: "$2", children: [note || (signed && refused) ? (_jsx(SizableText, { size: "$1", color: "$soft", role: "status", children: note || refused })) : null, working ? (_jsxs(XStack, { items: "center", gap: "$2", px: "$3", py: "$2", rounded: "$10", borderWidth: 1, borderColor: "$borderColor", children: [_jsx(SizableText, { size: "$2", color: "$soft", flex: 1, minW: 0, numberOfLines: 1, role: "status", children: doing || say('Thinking…') }), _jsx(Steer, { onCommand: (c) => {
101
+ if (c === 'stop')
102
+ void act(async () => (await stop(t, id), say('Stopped')));
103
+ }, withhold: ['pause', 'resume', ...(busy ? ['stop'] : [])] })] })) : null] }), _jsx(Composer, { column: true, value: draft, onChange: setDraft, onSend: send, ready: Boolean(draft.trim()), disabled: !signed || busy || !record, placeholder: !signed ? say('Sign in to reply') : working ? say('Add to what it is doing') : say('Reply'), label: say('Reply to this conversation'), plus: { upload: () => pick(files, setFiles, setNote, say) }, carried: carrying(files, setFiles), mind: signed && !working ? mind : null, mode: signed && !working ? { value: mode, set: (m) => setPicked(m), items: MODES.filter((m) => DEV_MODES.includes(m.id)) } : null })] })] }));
104
+ }
@@ -7,7 +7,7 @@ export interface QueuedMessage {
7
7
  text: string;
8
8
  }
9
9
  export type TranscriptView = 'normal' | 'thinking' | 'verbose';
10
- export declare function Transcript({ cards, live, empty, header, onApprove, approving, onVerdict, onOpen, onDiff, listen, end, view, queued, onSendQueued, }: {
10
+ export declare function Transcript({ cards, live, empty, header, onApprove, approving, onVerdict, onOpen, onDiff, listen, end, view, queued, onSendQueued, onRun, onAnswer, }: {
11
11
  cards: Card[];
12
12
  /** The run is still working: a card still running shows it; otherwise it was cut off. */
13
13
  live: boolean;
@@ -32,4 +32,8 @@ export declare function Transcript({ cards, live, empty, header, onApprove, appr
32
32
  queued?: QueuedMessage[];
33
33
  /** Send a queued message immediately. */
34
34
  onSendQueued?: (id: string) => void;
35
+ /** Open a coding run a conversation started, on its own page. */
36
+ onRun?: (session: string) => void;
37
+ /** Answer a question the run asked with one of its options. Absent, a question has no buttons. */
38
+ onAnswer?: (question: string, label: string) => void;
35
39
  }): import("react").JSX.Element;