@hanzo/build 0.2.126 → 0.2.127

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 (57) hide show
  1. package/lib/api/machines.d.ts +8 -0
  2. package/lib/api/machines.js +16 -5
  3. package/lib/api/places.d.ts +12 -4
  4. package/lib/api/places.js +11 -3
  5. package/lib/automations.js +74 -35
  6. package/lib/awake.d.ts +24 -0
  7. package/lib/awake.js +68 -0
  8. package/lib/clipboard.d.ts +2 -0
  9. package/lib/clipboard.js +10 -0
  10. package/lib/customize/agents.js +149 -31
  11. package/lib/customize/connectors.js +91 -34
  12. package/lib/customize/drafted.js +23 -10
  13. package/lib/customize/index.js +40 -10
  14. package/lib/customize/inventory.d.ts +4 -1
  15. package/lib/customize/inventory.js +66 -17
  16. package/lib/customize/plugins.js +43 -15
  17. package/lib/customize/skills.js +87 -23
  18. package/lib/customize/ui.d.ts +29 -3
  19. package/lib/customize/ui.js +89 -12
  20. package/lib/desk.d.ts +1 -1
  21. package/lib/desk.js +67 -40
  22. package/lib/dev-mode.d.ts +22 -0
  23. package/lib/dev-mode.js +80 -0
  24. package/lib/environment.js +4 -4
  25. package/lib/forge.js +97 -24
  26. package/lib/handoff.d.ts +8 -0
  27. package/lib/handoff.js +22 -0
  28. package/lib/index.d.ts +1 -0
  29. package/lib/index.js +1 -0
  30. package/lib/landing.js +100 -25
  31. package/lib/library.js +108 -39
  32. package/lib/make.js +3 -2
  33. package/lib/mind.d.ts +9 -29
  34. package/lib/mind.js +43 -4
  35. package/lib/pane.d.ts +13 -0
  36. package/lib/pane.js +4 -0
  37. package/lib/panel.d.ts +4 -0
  38. package/lib/panel.js +49 -46
  39. package/lib/plans.js +36 -15
  40. package/lib/project.js +72 -63
  41. package/lib/reply.d.ts +6 -1
  42. package/lib/reply.js +19 -9
  43. package/lib/run.js +23 -41
  44. package/lib/scheduled.js +36 -16
  45. package/lib/settings/account.js +2 -1
  46. package/lib/settings/billing.js +9 -4
  47. package/lib/settings/credits.d.ts +2 -1
  48. package/lib/settings/credits.js +2 -2
  49. package/lib/settings/machines.js +41 -18
  50. package/lib/settings/notifications.js +2 -1
  51. package/lib/shelf.d.ts +4 -1
  52. package/lib/shelf.js +79 -14
  53. package/lib/suggestions.js +2 -1
  54. package/lib/summary.js +3 -2
  55. package/lib/sync.js +3 -3
  56. package/lib/transcript.js +13 -6
  57. package/package.json +11 -1
@@ -1,3 +1,4 @@
1
+ import type { Say } from '@hanzo/i18n/react';
1
2
  import { type Target } from './call.ts';
2
3
  export declare const KINDS: readonly ['laptop', 'gpu', 'cloud', 'cluster', 'machine'];
3
4
  export type Kind = (typeof KINDS)[number];
@@ -68,6 +69,13 @@ export declare function formatBytes(bytes?: number): string;
68
69
  export declare function formatPercent(fraction?: number): string;
69
70
  export declare function formatRelative(isoDate?: string): string;
70
71
  export declare function specSummary(m: Machine): string;
72
+ export declare function displayMachine(m: Machine, opts?: {
73
+ devMode?: boolean;
74
+ say?: Say;
75
+ }): {
76
+ title: string;
77
+ detail?: string;
78
+ };
71
79
  export declare function machine(raw: unknown): Machine;
72
80
  export declare function machines(t: Target): Promise<Machine[]>;
73
81
  /**
@@ -14,6 +14,7 @@
14
14
  * hostname and keeps it online while it runs.
15
15
  */
16
16
  import { phrase } from '@hanzo/i18n';
17
+ import { formatDeviceLabel } from '../dev-mode.js';
17
18
  import { call, Refusal, seg } from './call.js';
18
19
  export const KINDS = ['laptop', 'gpu', 'cloud', 'cluster', 'machine'];
19
20
  const str = (v) => (typeof v === 'string' ? v : '');
@@ -51,19 +52,29 @@ export function formatRelative(isoDate) {
51
52
  export function specSummary(m) {
52
53
  if (m.spec) {
53
54
  const parts = [];
54
- if (m.spec.cpus)
55
- parts.push(`${m.spec.cpus} vCPU`);
56
- if (m.spec.memory)
57
- parts.push(formatBytes(m.spec.memory));
58
55
  if (m.spec.gpus && m.spec.gpus.length > 0) {
59
56
  const g = m.spec.gpus[0];
60
- parts.push(`${m.spec.gpus.length}× ${g.model || g.vendor || 'GPU'}${g.memory ? ` (${formatBytes(g.memory)})` : ''}`);
57
+ const gpuLabel = g.model || g.vendor || 'GPU';
58
+ parts.push(m.spec.gpus.length > 1 ? `${m.spec.gpus.length}× ${gpuLabel}` : gpuLabel);
59
+ }
60
+ else if (m.spec.cpus) {
61
+ parts.push(`${m.spec.cpus} vCPU`);
61
62
  }
63
+ if (m.spec.memory)
64
+ parts.push(formatBytes(m.spec.memory));
62
65
  if (parts.length > 0)
63
66
  return parts.join(' · ');
64
67
  }
65
68
  return m.capacity || '';
66
69
  }
70
+ function hardwareSummary(m) {
71
+ const hw = specSummary(m);
72
+ const host = m.host && m.host !== hw ? m.host : '';
73
+ return [hw, host].filter(Boolean).join(' · ');
74
+ }
75
+ export function displayMachine(m, opts) {
76
+ return formatDeviceLabel(m.label, { hardware: hardwareSummary(m), host: m.host, devMode: opts?.devMode, say: opts?.say });
77
+ }
67
78
  export function machine(raw) {
68
79
  const o = (raw && typeof raw === 'object' ? raw : {});
69
80
  const specObj = obj(o.spec);
@@ -1,17 +1,25 @@
1
+ import type { Say } from '@hanzo/i18n/react';
1
2
  import type { Target } from './call.ts';
2
3
  export interface Place {
3
- /** `tgt_…`, or '' for the sandbox. */
4
+ /** `tgt_…`, or '' for the cloud workspace. */
4
5
  id: string;
5
6
  label: string;
6
- /** laptop | gpu | cloud | … as the platform names it; 'sandbox' for the sandbox. */
7
+ /** laptop | gpu | cloud | … as the platform names it; 'sandbox' for the cloud workspace. */
7
8
  kind: string;
8
- /** online | offline | draining | not seen yet, as machines.ts `state` reads it; the sandbox is always online. */
9
+ /** online | offline | draining | not seen yet, as machines.ts `state` reads it; the cloud workspace is always online. */
9
10
  status: string;
10
11
  /** "10 vCPU / 122G / 1× GB10", when the machine reported one. */
11
12
  capacity: string;
12
13
  }
13
- /** The sandbox, named in English and marked (`phrase`): a screen draws its label through `t`. */
14
+ /** The cloud workspace, named in English and marked (`phrase`): a screen draws its label through `t`. */
14
15
  export declare const SANDBOX: Place;
15
16
  export declare function places(t: Target): Promise<Place[]>;
17
+ export declare function displayPlace(p: Place, opts?: {
18
+ devMode?: boolean;
19
+ say?: Say;
20
+ }): {
21
+ title: string;
22
+ detail?: string;
23
+ };
16
24
  /** Whether a run sent here now would be taken. */
17
25
  export declare const ready: (p: Place) => boolean;
package/lib/api/places.js CHANGED
@@ -1,19 +1,27 @@
1
1
  /**
2
- * Where a run can run: the platform's sandbox, or one of the org's machines.
2
+ * Where a run can run: the platform's cloud workspace, or one of the org's machines.
3
3
  *
4
4
  * GET /v1/agent/targets → {targets: [...]}, newest first (machines.ts)
5
5
  *
6
- * The sandbox is not a row the platform lists — it is what a run gets when it
6
+ * The cloud workspace is not a row the platform lists — it is what a run gets when it
7
7
  * names no target — so it is the first place here and carries no id. A machine
8
8
  * can take a run only while it is online.
9
9
  */
10
10
  import { phrase } from '@hanzo/i18n';
11
+ import { formatDeviceLabel } from '../dev-mode.js';
12
+ import { english } from '../say.js';
11
13
  import { machines, state } from './machines.js';
12
- /** The sandbox, named in English and marked (`phrase`): a screen draws its label through `t`. */
14
+ /** The cloud workspace, named in English and marked (`phrase`): a screen draws its label through `t`. */
13
15
  export const SANDBOX = { id: '', label: phrase('Hanzo sandbox'), kind: 'sandbox', status: 'online', capacity: '' };
14
16
  export async function places(t) {
15
17
  const list = await machines(t);
16
18
  return [SANDBOX, ...list.map((m) => ({ id: m.id, label: m.label, kind: m.kind, status: state(m), capacity: m.capacity }))];
17
19
  }
20
+ export function displayPlace(p, opts) {
21
+ const say = opts?.say ?? english;
22
+ if (!p.id)
23
+ return opts?.devMode ? { title: 'Cloud' } : { title: say('Auto (Cloud)'), detail: say('Runs automatically in your Hanzo cloud workspace') };
24
+ return formatDeviceLabel(p.label, { hardware: p.capacity, devMode: opts?.devMode, say });
25
+ }
18
26
  /** Whether a run sent here now would be taken. */
19
27
  export const ready = (p) => p.status === 'online';
@@ -15,16 +15,17 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
15
  * instructions, a run's summary and post and the platform's refusals are drawn
16
16
  * as given.
17
17
  */
18
- import { SizableText, XStack, YStack } from '@hanzo/gui';
19
- import { ChevronLeft } from '@hanzogui/lucide-icons-2';
18
+ import { SizableText, useMedia, XStack, YStack } from '@hanzo/gui';
19
+ import { ChevronDown, ChevronLeft, ChevronRight, ExternalLink, Play, RotateCcw, SlidersHorizontal, Trash2 } from '@hanzogui/lucide-icons-2';
20
20
  import { phrase } from '@hanzo/i18n';
21
21
  import { useI18n } from '@hanzo/i18n/react';
22
- import { Button, Input, Switch, Textarea } from '@hanzo/ui';
22
+ import { Button, Input, Skeleton, Switch, Textarea, toast } from '@hanzo/ui';
23
23
  import { StatusDot } from '@hanzo/ui/chat';
24
24
  import { ModelPicker } from '@hanzo/ui/models';
25
25
  import { ChipSelect } from '@hanzo/ui/product';
26
26
  import { useLimits } from '@hanzo/ui/product/useLimits';
27
27
  import { useEffect, useMemo, useRef, useState } from 'react';
28
+ import { RING, RING_INSET } from './pane.js';
28
29
  import { automation, changes, create, remove, review, runs, save, start, starters, words } from './api/auto.js';
29
30
  import { current, subscriptions } from './api/billing.js';
30
31
  import { SOCIAL } from './api/provider.js';
@@ -32,7 +33,7 @@ import { Out } from './out.js';
32
33
  import { useSocial } from './settings/integrations.js';
33
34
  import { Refusal, told } from './api/call.js';
34
35
  import { ENSO, limits as readLimits, models } from './api/models.js';
35
- import { Choice, Confirm, Field, Line, Sheet } from './customize/ui.js';
36
+ import { Choice, Confirm, Field, Sheet } from './customize/ui.js';
36
37
  import { useRead } from './data.js';
37
38
  import { useHost, useTarget } from './host.js';
38
39
  import { SOURCE } from './api/library.js';
@@ -178,6 +179,7 @@ export function Editor({ id }) {
178
179
  const host = useHost();
179
180
  const { t } = useI18n();
180
181
  const target = useTarget();
182
+ const desktop = Boolean(useMedia().sm);
181
183
  const signed = Boolean(host.person);
182
184
  const fresh = id === 'new';
183
185
  // `tick` reads the automation again; `beat` reads its runs again.
@@ -193,10 +195,14 @@ export function Editor({ id }) {
193
195
  const [ready, setReady] = useState(fresh);
194
196
  const [busy, setBusy] = useState('');
195
197
  const [note, setNote] = useState('');
198
+ const [noteError, setNoteError] = useState(false);
196
199
  const [asking, setAsking] = useState(false);
197
200
  // Where a move away from unsaved work was headed, while it asks first; '' for nowhere.
198
201
  const [leaving, setLeaving] = useState('');
199
202
  const [upgrade, setUpgrade] = useState(false);
203
+ const [moreStarters, setMoreStarters] = useState(false);
204
+ const [optionsOpen, setOptionsOpen] = useState(null);
205
+ const [allRuns, setAllRuns] = useState(false);
200
206
  const social = useSocial(signed, SOCIAL.filter((p) => p.posts).map((p) => p.id));
201
207
  const subs = useRead(signed ? () => subscriptions(target) : null, [], [target, signed]);
202
208
  // Free is what the platform says when it names no live subscription; a read that failed says nothing.
@@ -243,6 +249,7 @@ export function Editor({ id }) {
243
249
  // An edit answers what the last line asked for, so the line goes with it.
244
250
  const set = (p) => {
245
251
  setNote('');
252
+ setNoteError(false);
246
253
  setUpgrade(false);
247
254
  setD((x) => ({ ...x, ...p }));
248
255
  };
@@ -256,6 +263,7 @@ export function Editor({ id }) {
256
263
  const act = async (what, work) => {
257
264
  setBusy(what);
258
265
  setNote('');
266
+ setNoteError(false);
259
267
  setUpgrade(false);
260
268
  try {
261
269
  await work();
@@ -264,6 +272,7 @@ export function Editor({ id }) {
264
272
  // Wanting a plan is said in these words only where a run was asked for.
265
273
  const run = what === 'run' && unplanned(e);
266
274
  setNote(run ? t(PLAN) : told(e, t));
275
+ setNoteError(true);
267
276
  setUpgrade(run);
268
277
  }
269
278
  finally {
@@ -275,11 +284,13 @@ export function Editor({ id }) {
275
284
  const ask = !d.name.trim() ? [t('Name it first.'), nameRef] : !d.instructions.trim() ? [t('Add instructions first.'), asksRef] : null;
276
285
  if (ask) {
277
286
  setNote(ask[0]);
287
+ setNoteError(true);
278
288
  ask[1].current?.focus();
279
289
  return false;
280
290
  }
281
291
  if (wrong) {
282
292
  setNote(wrong);
293
+ setNoteError(true);
283
294
  return false;
284
295
  }
285
296
  return true;
@@ -301,6 +312,7 @@ export function Editor({ id }) {
301
312
  setBase(drafted(now));
302
313
  setD((cur) => rebase(cur, snap, drafted(now)));
303
314
  setTick((n) => n + 1);
315
+ setNoteError(false);
304
316
  setNote(t('Saved.'));
305
317
  });
306
318
  const flip = (on) => {
@@ -309,13 +321,19 @@ export function Editor({ id }) {
309
321
  void act('switch', async () => {
310
322
  await save(target, id, { enabled: on });
311
323
  setTick((n) => n + 1);
324
+ toast.success(on ? t('Automation turned on') : t('Automation paused'));
312
325
  });
313
326
  };
314
327
  const go = () => act('run', async () => {
315
328
  const run = await start(target, id);
316
329
  setBeat((n) => n + 1);
317
- if (run.status === 'skipped')
330
+ if (run.status === 'skipped') {
318
331
  setNote(t('Not started: the previous run is still going.'));
332
+ setNoteError(true);
333
+ }
334
+ else {
335
+ toast.success(t('Run started'));
336
+ }
319
337
  });
320
338
  const leave = (how) => host.go(path({ kind: 'screen', screen: 'automations' }), how);
321
339
  // A held post is answered once; its buttons go when it is.
@@ -337,9 +355,9 @@ export function Editor({ id }) {
337
355
  if (!signed)
338
356
  return _jsx(Page, { title: t('Automation'), onBack: () => leave(), says: t("Sign in to see this organization's automations.") });
339
357
  if (!fresh && saved.error && !a)
340
- return _jsx(Page, { title: t('Automation'), onBack: () => leave(), says: told(saved.error, t) });
358
+ return _jsx(Page, { title: t('Automation'), onBack: () => leave(), says: told(saved.error, t), error: true, onRetry: () => setTick((n) => n + 1) });
341
359
  if (!ready)
342
- return _jsx(Page, { title: t('Automation'), onBack: () => leave(), says: t('Reading the automation…') });
360
+ return _jsx(Page, { title: t('Automation'), onBack: () => leave(), says: t('Reading the automation…'), loading: true });
343
361
  const s = d.schedule;
344
362
  // An automation that posts speaks for the organization: only an admin changes it.
345
363
  const locked = !host.admin && Boolean(a?.postTo.length);
@@ -349,11 +367,30 @@ export function Editor({ id }) {
349
367
  const says = switchesAlone ? (on ? t('On') : t('Off')) : !can ? t('Add instructions first') : on ? t('On when saved') : t('Off when saved');
350
368
  const state = fresh ? t('Not created yet') : dirty ? t('Unsaved changes') : '';
351
369
  const sayId = `${id}-switch`;
352
- return (_jsxs(YStack, { flex: 1, minH: 0, children: [_jsxs(YStack, { shrink: 0, px: "$6", pt: "$4", pb: "$3", borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsxs(XStack, { width: "100%", maxW: 760, mx: "auto", items: "center", gap: "$3", flexWrap: "wrap", rowGap: "$2", children: [_jsxs(Button, { size: "sm", variant: "ghost", onPress: back, "aria-label": t('All scheduled tasks'), children: [_jsx(ChevronLeft, { size: 14, 'data-i18n-mirror': '' }), t('Scheduled tasks')] }), _jsx(SizableText, { size: "$1", color: "$soft", role: "status", children: state }), _jsx(XStack, { flex: 1 }), _jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { id: sayId, size: "$2", color: "$soft", children: says }), _jsx(Switch, { checked: on, disabled: busy === 'switch' || !can, onCheckedChange: flip, "aria-label": switchesAlone ? t('{name} on', { name: a.name }) : t('On when saved'), "aria-describedby": sayId })] }), a && !a.draft ? (_jsx(Button, { size: "sm", variant: "outline", disabled: Boolean(busy) || dirty, onPress: () => void go(), children: busy === 'run' ? t('Starting…') : t('Run now') })) : null, a && dirty ? (_jsx(Button, { size: "sm", variant: "ghost", disabled: Boolean(busy), onPress: () => {
353
- setBase(drafted(a));
354
- setD(drafted(a));
355
- setNote('');
356
- }, children: t('Discard changes') })) : null, _jsx(Button, { size: "sm", disabled: Boolean(busy) || locked || !(fresh || drafty || dirty), onPress: () => complete() && void keep(), children: busy === 'save' ? t('Saving…') : fresh ? t('Create') : t('Save') })] }), note ? (_jsxs(XStack, { width: "100%", maxW: 760, mx: "auto", items: "center", gap: "$3", pt: "$2", children: [_jsx(Line, { children: note }), upgrade ? (_jsx(Button, { size: "sm", variant: "outline", onPress: () => away(path({ kind: 'screen', screen: 'plans' })), children: t('See plans') })) : null] })) : null] }), _jsxs(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$5", children: [_jsxs(YStack, { width: "100%", maxW: 760, mx: "auto", gap: "$5", children: [locked ? (_jsx(SizableText, { size: "$1", color: "$soft", role: "note", children: t('This automation posts to the organization’s accounts, so only an org admin changes it.') })) : null, free ? (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", flexWrap: "wrap", rowGap: "$2", children: [_jsx(SizableText, { flex: 1, minW: 200, size: "$1", color: "$soft", children: t('Paid plans include automation runs. On the Free plan each run needs $1 of credit.') }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => away(path({ kind: 'screen', screen: 'plans' })), children: t('See plans') })] })) : null, _jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { render: "h1", size: "$6", color: "$ink", numberOfLines: 1, children: fresh ? t('New automation') : a?.name }), _jsx(SizableText, { size: "$2", color: "$soft", children: fresh
370
+ const starterCap = 4;
371
+ const starterOverflow = offered.value.length > starterCap;
372
+ const visibleStarters = !moreStarters && starterOverflow ? offered.value.slice(0, starterCap) : offered.value;
373
+ const showOptions = optionsOpen ?? (desktop || Boolean(d.postTo.length));
374
+ const modelLabel = d.model ? (catalog.value.find((m) => m.id === d.model)?.name ?? d.model) : 'Enso';
375
+ const permLabel = d.permissions === 'auto' ? t('Act on its own') : t('Ask first');
376
+ const optionsSummary = [
377
+ modelLabel,
378
+ permLabel,
379
+ d.postTo.length ? t('Posts to {n}', { n: d.postTo.length }) : '',
380
+ d.notify ? t('Email on') : '',
381
+ ]
382
+ .filter(Boolean)
383
+ .join(' · ');
384
+ const runsCap = 8;
385
+ const runsOverflow = history.value.length > runsCap;
386
+ const visibleHistory = !allRuns && runsOverflow ? history.value.slice(0, runsCap) : history.value;
387
+ return (_jsxs(YStack, { flex: 1, minH: 0, children: [_jsxs(YStack, { shrink: 0, px: "$6", pt: "$4", pb: "$3", "$max-md": { px: '$4' }, borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsxs(XStack, { width: "100%", maxW: 760, mx: "auto", items: "center", justify: "space-between", gap: "$3", flexWrap: "wrap", rowGap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(Button, { size: "sm", variant: "ghost", onPress: back, "aria-label": t('All scheduled tasks'), children: [_jsx(ChevronLeft, { size: 14, 'data-i18n-mirror': '' }), t('Scheduled tasks')] }), state ? (_jsx(SizableText, { size: "$1", color: "$soft", role: "status", children: state })) : null] }), _jsxs(XStack, { items: "center", gap: "$2", flexWrap: "wrap", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { id: sayId, size: "$2", color: "$soft", children: says }), _jsx(Switch, { checked: on, disabled: busy === 'switch' || !can, onCheckedChange: flip, "aria-label": switchesAlone ? t('{name} on', { name: a.name }) : t('On when saved'), "aria-describedby": sayId })] }), a && !a.draft ? (_jsxs(Button, { size: "sm", variant: "outline", disabled: Boolean(busy) || dirty, onPress: () => void go(), children: [_jsx(Play, { size: 14 }), busy === 'run' ? t('Starting…') : t('Run now')] })) : null, a && dirty ? (_jsxs(Button, { size: "sm", variant: "ghost", disabled: Boolean(busy), onPress: () => {
388
+ setBase(drafted(a));
389
+ setD(drafted(a));
390
+ setNote('');
391
+ setNoteError(false);
392
+ toast.info(t('Changes discarded'));
393
+ }, children: [_jsx(RotateCcw, { size: 14 }), t('Discard changes')] })) : null, _jsx(Button, { size: "sm", variant: "primary", disabled: Boolean(busy) || locked || !(fresh || drafty || dirty), onPress: () => complete() && void keep(), children: busy === 'save' ? t('Saving…') : fresh ? t('Create') : t('Save') })] })] }), note ? (_jsxs(XStack, { width: "100%", maxW: 760, mx: "auto", items: "center", gap: "$3", pt: "$2", flexWrap: "wrap", children: [_jsx(SizableText, { size: "$1", color: noteError ? 'var(--state-error)' : '$soft', role: "status", children: note }), upgrade ? (_jsx(Button, { size: "sm", variant: "outline", onPress: () => away(path({ kind: 'screen', screen: 'plans' })), children: t('See plans') })) : null] })) : null] }), _jsxs(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$5", children: [_jsxs(YStack, { width: "100%", maxW: 760, mx: "auto", gap: "$5", children: [locked ? (_jsx(SizableText, { size: "$1", color: "$soft", role: "note", children: t('This automation posts to the organization’s accounts, so only an org admin changes it.') })) : null, free ? (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", flexWrap: "wrap", rowGap: "$2", children: [_jsx(SizableText, { flex: 1, minW: 200, size: "$1", color: "$soft", children: t('Paid plans include automation runs. On the Free plan each run needs $1 of credit.') }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => away(path({ kind: 'screen', screen: 'plans' })), children: t('See plans') })] })) : null, _jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { render: "h1", size: "$6", color: "$ink", numberOfLines: 1, children: fresh ? t('New automation') : a?.name }), _jsx(SizableText, { size: "$2", color: "$soft", children: fresh
357
394
  ? t('Name it, say what it should do, and when. It runs as you, in this organization.')
358
395
  : a?.draft
359
396
  ? t('A draft: say what it should do and save it, and it runs.')
@@ -363,33 +400,35 @@ export function Editor({ id }) {
363
400
  a.next && a.enabled ? t('next {when}', { when: local(a.next) }) : a.schedule.kind === 'manual' ? '' : t('off'),
364
401
  ]
365
402
  .filter(Boolean)
366
- .join(' · ') })] }), fresh && offered.value.length && !d.instructions.trim() ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", rowGap: "$2", items: "center", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Start from') }), offered.value.map((x) => (_jsx(Button, { size: "sm", variant: "outline", onPress: () => begin(x), "aria-label": t('Start from {name}', { name: x.name }), children: x.name }, x.key)))] })) : null, _jsx(Field, { label: t('Name'), children: _jsx(Input, { ref: nameRef, value: d.name, onChangeText: (v) => set({ name: v }), onSubmitEditing: () => asksRef.current?.focus(), placeholder: t('Morning briefing'), "aria-label": t('Automation name'), autoFocus: fresh, disabled: locked }) }), _jsx(Field, { label: t('Instructions (required)'), hint: t("What the agent does each run. It works in a Dev sandbox with this organization's connectors, MCP servers and skills."), children: _jsx(Textarea, { ref: asksRef, disabled: locked, value: d.instructions, onChangeText: (v) => set({ instructions: v }), placeholder: t('What should it do each run? For example: summarize what needs my attention today across calendar, email and messages.'), "aria-label": t('Instructions'), rows: 7 }) }), _jsx(Field, { label: t('When it runs'), hint: s.kind === 'cron' ? t('Five fields: minute, hour, day of month, month, day of week.') : s.kind === 'once' ? t('It runs at that time and then switches itself off.') : undefined, children: _jsx(When, { s: s, onChange: (next) => set({ schedule: next }), disabled: locked }) }), _jsx(Field, { label: t('Model'), children: _jsx(XStack, { children: _jsx(ModelPicker, { size: "sm", name: t('Model'), models: catalog.value, scope: "chat", limits: limits, value: d.model ?? ENSO, onChange: (id) => set({ model: id === ENSO ? null : id }), loading: catalog.loading, error: catalog.error ? told(catalog.error, t) : null }) }) }), _jsx(Field, { label: t('Permissions'), hint: d.permissions === 'auto' ? t('Works and uses connectors without stopping.') : t('Reads and researches, changes nothing, and ends with the actions it would take for you to approve.'), children: _jsx(Choice, { label: t('Permissions'), value: d.permissions, options: PERMISSIONS.map((p) => ({ ...p, label: t(p.label) })), onChange: (p) => set({ permissions: p }) }) }), _jsxs(Field, { label: t('Post to'), hint: !host.admin
367
- ? t('An org admin chooses where automations post: the accounts are the organization’s.')
368
- : !d.postTo.length
369
- ? t('Turn an account on and each run’s answer is a post for it.')
370
- : d.permissions === 'auto'
371
- ? t('Each run posts what the agent writes, as written.')
372
- : t('Each run holds what the agent writes for you to post or discard.'), children: [_jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", overflow: "hidden", children: SOCIAL.filter((p) => p.posts).map((p, i) => {
373
- const c = social.value[p.id];
374
- const on = d.postTo.includes(p.id);
375
- return (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2.5", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsxs(YStack, { flex: 1, minW: 0, gap: "$0.5", children: [_jsx(SizableText, { size: "$2", color: "$ink", children: p.name }), _jsx(SizableText, { size: "$1", color: "$soft", children: social.error
376
- ? told(social.error, t)
377
- : !c
378
- ? t('Reading…')
379
- : c.connected
380
- ? c.account
381
- ? t('Connected as {account}', { account: c.account })
382
- : t('Connected')
383
- : `${c.available ? t('Not connected: an org admin connects it in Settings → Integrations.') : t(p.needs)} ${on || d.permissions === 'ask'
384
- ? t('Runs hold the post for you to read; posting it fails until it is connected.')
385
- : t('Acting on its own, it posts only to a connected account.')}` })] }), _jsx(Switch, { checked: on, disabled: !host.admin || (!on && !c?.connected && d.permissions === 'auto'), onCheckedChange: (v) => set({ postTo: v ? [...d.postTo, p.id].sort() : d.postTo.filter((x) => x !== p.id) }), "aria-label": t('Post to {name}', { name: p.name }) })] }, p.id));
386
- }) }), _jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "ghost", onPress: () => away(path({ kind: 'settings', section: 'integrations' })), children: t('Connect accounts') }) })] }), _jsxs(XStack, { items: "center", gap: "$3", children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", color: "$ink", children: t('Email me when a run ends') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('One line on how it went, with a link to the run.') })] }), _jsx(Switch, { checked: d.notify, onCheckedChange: (v) => set({ notify: v }), "aria-label": t('Email me when a run ends') })] }), dirty && wrong && note !== wrong ? _jsx(Line, { children: wrong }) : null, a ? (_jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "ghost", disabled: Boolean(busy), onPress: () => setAsking(true), children: t('Delete') }) })) : null, a ? (_jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$3", color: "$ink", children: t('Runs') }), history.error && !history.value.length ? (_jsx(Line, { children: told(history.error, t) })) : !history.value.length ? (_jsx(SizableText, { size: "$2", color: "$soft", children: history.loading ? t('Reading its runs…') : a.draft ? t('It runs once its instructions are saved.') : t('No runs yet. Run now starts one.') })) : (_jsx(YStack, { role: "list", borderWidth: 1, borderColor: "$borderColor", rounded: "$3", overflow: "hidden", "aria-label": t('Run history'), children: history.value.map((r, i) => (_jsxs(XStack, { role: "listitem", items: "flex-start", gap: "$3", px: "$3", py: "$2.5", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsx(YStack, { pt: "$1", children: _jsx(StatusDot, { status: DOT[r.status] ?? 'idle' }) }), _jsxs(YStack, { flex: 1, minW: 0, gap: "$0.5", children: [_jsx(SizableText, { size: "$2", color: "$ink", children: `${WORD[r.status] ? t(WORD[r.status]) : r.status} · ${local(r.at)}` }), _jsx(SizableText, { size: "$1", color: "$soft", style: { whiteSpace: 'pre-wrap' }, children: r.summary || (live(r.status) ? t('Working…') : '') }), r.draft ? (_jsx(YStack, { mt: "$1.5", px: "$3", py: "$2", rounded: "$2", bg: "$raised", role: "group", "aria-label": t('The post'), children: _jsx(SizableText, { size: "$2", color: "$ink", style: { whiteSpace: 'pre-wrap' }, children: r.draft }) })) : null, r.outputs.length ? _jsx(Outputs, { ids: r.outputs }) : null, r.posts.map((x) => (_jsxs(XStack, { items: "center", gap: "$2", pt: "$1", children: [_jsx(SizableText, { size: "$1", color: "$ink", children: NAME[x.to] ?? x.to }), x.url ? (_jsx(Out, { href: x.url, label: t('Open the {name} post', { name: NAME[x.to] ?? x.to }), children: _jsx(SizableText, { size: "$1", color: "$ink", textDecorationLine: "underline", children: t('Posted · open') }) })) : (_jsx(SizableText, { size: "$1", color: "$soft", children: x.error }))] }, x.to))), r.status === 'review' && host.admin && !answered.has(r.id) ? (_jsxs(XStack, { gap: "$2", pt: "$2", children: [_jsx(Button, { size: "sm", disabled: Boolean(busy), onPress: () => void answer(r, true), "aria-label": t('Post the post of {when}', { when: local(r.at) }), children: t('Post it') }), _jsx(Button, { size: "sm", variant: "ghost", disabled: Boolean(busy), onPress: () => void answer(r, false), "aria-label": t('Discard the post of {when}', { when: local(r.at) }), children: t('Discard') })] })) : r.status === 'review' && !host.admin ? (_jsx(SizableText, { size: "$1", color: "$soft", pt: "$1", children: t('An org admin posts or discards it.') })) : null] }), r.session ? (_jsx(Button, { size: "sm", variant: "ghost", onPress: () => host.go(r.session), "aria-label": t('Open the Dev run of {when}', { when: local(r.at) }), children: t('Open run') })) : null] }, r.id))) }))] })) : null] }), a ? (_jsx(Confirm, { what: a.name, says: t('It stops running, and its schedule and its runs go with it. A run going now is stopped.'), open: asking, onOpenChange: setAsking, onYes: async () => {
403
+ .join(' · ') })] }), fresh && offered.value.length && !d.instructions.trim() ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", rowGap: "$2", items: "center", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Start from') }), visibleStarters.map((x) => (_jsx(Button, { size: "sm", variant: "outline", onPress: () => begin(x), "aria-label": t('Start from {name}', { name: x.name }), children: x.name }, x.key))), starterOverflow ? (_jsx(XStack, { render: "button", "aria-expanded": moreStarters, onPress: () => setMoreStarters((v) => !v), px: "$2.5", py: "$1", minH: 32, items: "center", focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", fontWeight: "500", color: "$ink", children: moreStarters ? t('Show less') : t('+{n} more', { n: offered.value.length - visibleStarters.length }) }) })) : null] })) : null, _jsx(Field, { label: t('Name'), children: _jsx(Input, { ref: nameRef, value: d.name, onChangeText: (v) => set({ name: v }), onSubmitEditing: () => asksRef.current?.focus(), placeholder: t('Morning briefing'), "aria-label": t('Automation name'), autoFocus: fresh, disabled: locked }) }), _jsx(Field, { label: t('Instructions (required)'), hint: t("What the agent does each run. It works in a Dev sandbox with this organization's connectors, MCP servers and skills."), children: _jsx(Textarea, { ref: asksRef, disabled: locked, value: d.instructions, onChangeText: (v) => set({ instructions: v }), placeholder: t('What should it do each run? For example: summarize what needs my attention today across calendar, email and messages.'), "aria-label": t('Instructions'), rows: 7 }) }), _jsx(Field, { label: t('When it runs'), hint: s.kind === 'cron' ? t('Five fields: minute, hour, day of month, month, day of week.') : s.kind === 'once' ? t('It runs at that time and then switches itself off.') : undefined, children: _jsx(When, { s: s, onChange: (next) => set({ schedule: next }), disabled: locked }) }), _jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", overflow: "hidden", children: [_jsxs(XStack, { render: "button", "aria-expanded": showOptions, onPress: () => setOptionsOpen(!showOptions), items: "center", gap: "$2.5", px: "$4", py: "$3", minH: 44, width: "100%", "$platform-web": { textAlign: 'start' }, focusVisibleStyle: RING_INSET, children: [_jsx(SlidersHorizontal, { size: 15, color: "$soft" }), _jsxs(YStack, { flex: 1, minW: 0, gap: "$0.5", children: [_jsx(SizableText, { size: "$2", fontWeight: "500", color: "$ink", children: t('Options & delivery') }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: optionsSummary })] }), showOptions ? _jsx(ChevronDown, { size: 15, color: "$soft" }) : _jsx(ChevronRight, { size: 15, color: "$soft" })] }), showOptions ? (_jsxs(YStack, { gap: "$4", px: "$4", pb: "$4", pt: "$3", borderTopWidth: 1, borderColor: "$borderColor", children: [_jsxs(XStack, { gap: "$4", items: "flex-start", "$max-sm": { flexDirection: 'column', gap: '$3' }, children: [_jsx(YStack, { flex: 1, minW: 0, "$max-sm": { flexBasis: 'auto', grow: 0, minW: 0, width: '100%' }, children: _jsx(Field, { label: t('Model'), children: _jsx(XStack, { children: _jsx(ModelPicker, { size: "sm", name: t('Model'), models: catalog.value, scope: "chat", limits: limits, value: d.model ?? ENSO, onChange: (id) => set({ model: id === ENSO ? null : id }), loading: catalog.loading, error: catalog.error ? told(catalog.error, t) : null }) }) }) }), _jsx(YStack, { flex: 1, minW: 0, "$max-sm": { flexBasis: 'auto', grow: 0, minW: 0, width: '100%' }, children: _jsx(Field, { label: t('Permissions'), hint: d.permissions === 'auto' ? t('Works and uses connectors without stopping.') : t('Reads and researches, changes nothing, and ends with the actions it would take for you to approve.'), children: _jsx(Choice, { label: t('Permissions'), value: d.permissions, options: PERMISSIONS.map((p) => ({ ...p, label: t(p.label) })), onChange: (p) => set({ permissions: p }) }) }) })] }), _jsxs(Field, { label: t('Post to'), hint: !host.admin
404
+ ? t('An org admin chooses where automations post: the accounts are the organization’s.')
405
+ : !d.postTo.length
406
+ ? t('Turn an account on and each run’s answer is a post for it.')
407
+ : d.permissions === 'auto'
408
+ ? t('Each run posts what the agent writes, as written.')
409
+ : t('Each run holds what the agent writes for you to post or discard.'), children: [_jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$background", overflow: "hidden", children: SOCIAL.filter((p) => p.posts).map((p, i) => {
410
+ const c = social.value[p.id];
411
+ const on = d.postTo.includes(p.id);
412
+ return (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2.5", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsxs(YStack, { flex: 1, minW: 0, gap: "$0.5", children: [_jsx(SizableText, { size: "$2", fontWeight: "500", color: "$ink", children: p.name }), _jsx(SizableText, { size: "$1", color: "$soft", children: social.error
413
+ ? told(social.error, t)
414
+ : !c
415
+ ? t('Reading…')
416
+ : c.connected
417
+ ? c.account
418
+ ? t('Connected as {account}', { account: c.account })
419
+ : t('Connected')
420
+ : `${c.available ? t('Not connected: an org admin connects it in Settings → Integrations.') : t(p.needs)} ${on || d.permissions === 'ask'
421
+ ? t('Runs hold the post for you to read; posting it fails until it is connected.')
422
+ : t('Acting on its own, it posts only to a connected account.')}` })] }), _jsx(Switch, { checked: on, disabled: !host.admin || (!on && !c?.connected && d.permissions === 'auto'), onCheckedChange: (v) => set({ postTo: v ? [...d.postTo, p.id].sort() : d.postTo.filter((x) => x !== p.id) }), "aria-label": t('Post to {name}', { name: p.name }) })] }, p.id));
423
+ }) }), _jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "ghost", onPress: () => away(path({ kind: 'settings', section: 'integrations' })), children: t('Connect accounts') }) })] }), _jsxs(XStack, { items: "center", gap: "$3", pt: "$2", borderTopWidth: 1, borderColor: "$borderColor", children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", fontWeight: "500", color: "$ink", children: t('Email me when a run ends') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('One line on how it went, with a link to the run.') })] }), _jsx(Switch, { checked: d.notify, onCheckedChange: (v) => set({ notify: v }), "aria-label": t('Email me when a run ends') })] })] })) : null] }), dirty && wrong && note !== wrong ? (_jsx(SizableText, { size: "$1", color: "var(--state-error)", role: "status", children: wrong })) : null, a ? (_jsxs(XStack, { items: "center", justify: "space-between", gap: "$3", pt: "$3", borderTopWidth: 1, borderColor: "$borderColor", flexWrap: "wrap", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Stops the schedule and deletes this automation’s run history.') }), _jsxs(Button, { size: "sm", variant: "ghost", tone: "danger", disabled: Boolean(busy), onPress: () => setAsking(true), children: [_jsx(Trash2, { size: 14 }), t('Delete')] })] })) : null, a ? (_jsxs(YStack, { gap: "$2.5", children: [_jsx(SizableText, { render: "h2", size: "$3", fontWeight: "500", color: "$ink", children: t('Runs') }), history.error && !history.value.length ? (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$4", py: "$5", gap: "$2.5", items: "flex-start", children: [_jsx(SizableText, { size: "$2", color: "var(--state-error)", children: told(history.error, t) }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setBeat((n) => n + 1), children: t('Try again') })] })) : history.loading && !history.value.length ? (_jsxs(YStack, { gap: "$2", "aria-busy": true, children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Reading its runs…') }), _jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$panel", overflow: "hidden", children: [0, 1, 2].map((i) => (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2.5", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsx(Skeleton, { layout: "block", width: 10, height: 10, rounded: 999, shrink: 0 }), _jsxs(YStack, { flex: 1, gap: "$1.5", children: [_jsx(Skeleton, { layout: "block", width: "44%", height: 14, rounded: "$2" }), _jsx(Skeleton, { layout: "block", width: "68%", height: 12, rounded: "$2" })] })] }, i))) })] })) : !history.value.length ? (_jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$panel", px: "$4", py: "$5", children: _jsx(SizableText, { size: "$2", color: "$soft", children: a.draft ? t('It runs once its instructions are saved.') : t('No runs yet. Run now starts one.') }) })) : (_jsxs(YStack, { gap: "$2", children: [_jsx(YStack, { role: "list", borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$panel", overflow: "hidden", "aria-label": t('Run history'), children: visibleHistory.map((r, i) => (_jsxs(XStack, { role: "listitem", items: "flex-start", gap: "$3", rowGap: "$2", px: "$3", py: "$2.5", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", flexWrap: "wrap", children: [_jsx(YStack, { pt: "$1", children: _jsx(StatusDot, { status: DOT[r.status] ?? 'idle' }) }), _jsxs(YStack, { flex: 1, minW: 180, gap: "$0.5", children: [_jsx(SizableText, { size: "$2", fontWeight: "500", color: "$ink", children: `${WORD[r.status] ? t(WORD[r.status]) : r.status} · ${local(r.at)}` }), _jsx(SizableText, { size: "$1", color: "$soft", "$platform-web": { whiteSpace: 'pre-wrap' }, children: r.summary || (live(r.status) ? t('Working…') : '') }), r.draft ? (_jsx(YStack, { mt: "$1.5", px: "$3", py: "$2", rounded: "$2", bg: "$raised", borderWidth: 1, borderColor: "$borderColor", role: "group", "aria-label": t('The post'), children: _jsx(SizableText, { size: "$2", color: "$ink", "$platform-web": { whiteSpace: 'pre-wrap' }, children: r.draft }) })) : null, r.outputs.length ? _jsx(Outputs, { ids: r.outputs }) : null, r.posts.map((x) => (_jsxs(XStack, { items: "center", gap: "$2", pt: "$1", children: [_jsx(SizableText, { size: "$1", color: "$ink", children: NAME[x.to] ?? x.to }), x.url ? (_jsxs(Out, { href: x.url, label: t('Open the {name} post', { name: NAME[x.to] ?? x.to }), children: [_jsx(SizableText, { size: "$1", color: "$ink", textDecorationLine: "underline", children: t('Posted · open') }), _jsx(ExternalLink, { size: 11, color: "$soft" })] })) : (_jsx(SizableText, { size: "$1", color: "var(--state-error)", children: x.error }))] }, x.to))), r.status === 'review' && host.admin && !answered.has(r.id) ? (_jsxs(XStack, { gap: "$2", pt: "$2", flexWrap: "wrap", children: [_jsx(Button, { size: "sm", variant: "primary", disabled: Boolean(busy), onPress: () => void answer(r, true), "aria-label": t('Post the post of {when}', { when: local(r.at) }), children: t('Post it') }), _jsx(Button, { size: "sm", variant: "ghost", disabled: Boolean(busy), onPress: () => void answer(r, false), "aria-label": t('Discard the post of {when}', { when: local(r.at) }), children: t('Discard') })] })) : r.status === 'review' && !host.admin ? (_jsx(SizableText, { size: "$1", color: "$soft", pt: "$1", children: t('An org admin posts or discards it.') })) : null] }), r.session ? (_jsxs(Button, { size: "sm", variant: "ghost", onPress: () => host.go(r.session), "aria-label": t('Open the Dev run of {when}', { when: local(r.at) }), children: [_jsx(ExternalLink, { size: 13 }), t('Open run')] })) : null] }, r.id))) }), runsOverflow ? (_jsx(XStack, { children: _jsx(XStack, { render: "button", "aria-expanded": allRuns, onPress: () => setAllRuns((v) => !v), px: "$2.5", py: "$1.5", minH: 32, items: "center", focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", fontWeight: "500", color: "$soft", children: allRuns ? t('Show fewer runs') : t('Show all {n} runs', { n: history.value.length }) }) }) })) : null] }))] })) : null] }), a ? (_jsx(Confirm, { what: a.name, says: t('It stops running, and its schedule and its runs go with it. A run going now is stopped.'), open: asking, onOpenChange: setAsking, onYes: async () => {
424
+ const name = a.name;
387
425
  await remove(target, a.id);
426
+ toast.success(t('{name} deleted', { name }));
388
427
  leave({ replace: true });
389
428
  } })) : null, _jsxs(Sheet, { title: t('Leave without saving?'), open: Boolean(leaving), onOpenChange: (o) => !o && setLeaving(''), width: 420, children: [_jsx(SizableText, { size: "$2", color: "$soft", children: fresh ? t('This automation is not created yet.') : t('Your changes to this automation are not saved.') }), _jsxs(XStack, { gap: "$2", justify: "flex-end", children: [_jsx(Button, { size: "sm", variant: "ghost", onPress: () => setLeaving(''), children: t('Keep editing') }), _jsx(Button, { size: "sm", variant: "destructive", onPress: () => host.go(leaving), children: t('Leave') })] })] })] })] }));
390
429
  }
391
430
  /** A page with nothing to edit yet: its title and what it says come already said. */
392
- function Page({ title, says, onBack }) {
431
+ function Page({ title, says, onBack, loading = false, error = false, onRetry }) {
393
432
  const { t } = useI18n();
394
- return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$6", children: _jsxs(YStack, { width: "100%", maxW: 760, mx: "auto", gap: "$4", children: [_jsx(XStack, { children: _jsxs(Button, { size: "sm", variant: "ghost", onPress: onBack, "aria-label": t('All scheduled tasks'), children: [_jsx(ChevronLeft, { size: 14, 'data-i18n-mirror': '' }), t('Scheduled tasks')] }) }), _jsx(SizableText, { render: "h1", size: "$6", color: "$ink", children: title }), _jsx(SizableText, { size: "$2", color: "$soft", children: says })] }) }));
433
+ return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$6", children: _jsxs(YStack, { width: "100%", maxW: 760, mx: "auto", gap: "$4", children: [_jsx(XStack, { children: _jsxs(Button, { size: "sm", variant: "ghost", onPress: onBack, "aria-label": t('All scheduled tasks'), children: [_jsx(ChevronLeft, { size: 14, 'data-i18n-mirror': '' }), t('Scheduled tasks')] }) }), _jsx(SizableText, { render: "h1", size: "$6", color: "$ink", children: title }), _jsx(SizableText, { size: "$2", color: "$soft", children: says }), loading ? (_jsxs(YStack, { gap: "$3", "aria-busy": true, children: [_jsx(Skeleton, { layout: "block", width: "100%", height: 40, rounded: "$3" }), _jsx(Skeleton, { layout: "block", width: "100%", height: 140, rounded: "$3" }), _jsx(Skeleton, { layout: "block", width: "60%", height: 36, rounded: "$3" })] })) : null, error && onRetry ? (_jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "outline", onPress: onRetry, children: t('Try again') }) })) : null] }) }));
395
434
  }
package/lib/awake.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ export interface Lock {
2
+ release: () => Promise<void>;
3
+ /** The browser fires `release` when it takes the lock back (a hidden tab, low power). */
4
+ addEventListener?: (type: 'release', listener: () => void) => void;
5
+ }
6
+ type Wake = {
7
+ wakeLock?: {
8
+ request: (type: 'screen') => Promise<Lock>;
9
+ };
10
+ };
11
+ /** The lock held after asking for `on`: a new one when it is granted, none when it is refused, unsupported or let go. */
12
+ export declare function hold(nav: Wake, held: Lock | null, on: boolean): Promise<Lock | null>;
13
+ /**
14
+ * Ask for the lock and see it through: a lock granted after the view has closed
15
+ * is let go at once, and one the browser later takes back is reported to `dropped`.
16
+ */
17
+ export declare function grant(nav: Wake, held: Lock | null, on: boolean, closed: () => boolean, dropped: (lock: Lock) => void): Promise<Lock | null>;
18
+ /** [on, set]: `on` follows the lock itself, and the lock goes when the view does. */
19
+ export declare function useKeepAwake(): [boolean, (on: boolean) => Promise<void>];
20
+ export declare function KeepAwake({ on, onToggle }: {
21
+ on: boolean;
22
+ onToggle: (on: boolean) => void;
23
+ }): import("react").JSX.Element;
24
+ export {};
package/lib/awake.js ADDED
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The run menu's "Keep computer awake": a checkbox row (so a screen reader hears
4
+ * on or off) over the browser's screen wake lock. It reads "on" only once the
5
+ * lock is granted, and the lock is let go when the run view closes.
6
+ */
7
+ import { SizableText, YStack } from '@hanzo/gui';
8
+ import { useI18n } from '@hanzo/i18n/react';
9
+ import { DropdownMenuCheckboxItem } from '@hanzo/ui';
10
+ import { useEffect, useRef, useState } from 'react';
11
+ /** The lock held after asking for `on`: a new one when it is granted, none when it is refused, unsupported or let go. */
12
+ export async function hold(nav, held, on) {
13
+ if (!on) {
14
+ await held?.release().catch(() => undefined);
15
+ return null;
16
+ }
17
+ if (held)
18
+ return held;
19
+ try {
20
+ return (await nav.wakeLock?.request('screen')) ?? null;
21
+ }
22
+ catch {
23
+ return null;
24
+ }
25
+ }
26
+ /**
27
+ * Ask for the lock and see it through: a lock granted after the view has closed
28
+ * is let go at once, and one the browser later takes back is reported to `dropped`.
29
+ */
30
+ export async function grant(nav, held, on, closed, dropped) {
31
+ const next = await hold(nav, held, on);
32
+ if (!next || next === held)
33
+ return next;
34
+ if (closed()) {
35
+ await next.release().catch(() => undefined);
36
+ return null;
37
+ }
38
+ next.addEventListener?.('release', () => dropped(next));
39
+ return next;
40
+ }
41
+ /** [on, set]: `on` follows the lock itself, and the lock goes when the view does. */
42
+ export function useKeepAwake() {
43
+ const [on, setOn] = useState(false);
44
+ const lock = useRef(null);
45
+ const closed = useRef(false);
46
+ useEffect(() => {
47
+ closed.current = false;
48
+ return () => {
49
+ closed.current = true;
50
+ void lock.current?.release().catch(() => undefined);
51
+ };
52
+ }, []);
53
+ const set = async (want) => {
54
+ lock.current = await grant(navigator, lock.current, want, () => closed.current, (l) => {
55
+ if (lock.current === l) {
56
+ lock.current = null;
57
+ setOn(false);
58
+ }
59
+ });
60
+ if (!closed.current)
61
+ setOn(lock.current !== null);
62
+ };
63
+ return [on, set];
64
+ }
65
+ export function KeepAwake({ on, onToggle }) {
66
+ const { t } = useI18n();
67
+ return (_jsx(DropdownMenuCheckboxItem, { checked: on, onCheckedChange: onToggle, preventCloseOnSelect: true, children: _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", color: "$ink", children: t('Keep computer awake') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('Only for this session') })] }) }));
68
+ }
@@ -0,0 +1,2 @@
1
+ /** Copy text; true once it is on the clipboard, false where the browser has none or refuses it (nothing is thrown). */
2
+ export declare const copy: (text: string) => Promise<boolean>;
@@ -0,0 +1,10 @@
1
+ /** Copy text; true once it is on the clipboard, false where the browser has none or refuses it (nothing is thrown). */
2
+ export const copy = async (text) => {
3
+ try {
4
+ await navigator.clipboard.writeText(text);
5
+ return true;
6
+ }
7
+ catch {
8
+ return false;
9
+ }
10
+ };