@hanzo/app 0.3.90 → 0.3.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ import { useAi } from '../lib/ai.js';
15
15
  import { say } from '../failure.js';
16
16
  import { called } from '../team.js';
17
17
  import { VaultDialog, readVault } from '../vault.js';
18
- import { actComputer, bootOrResumeComputer, disk, findBotComputer, grant, parkComputer, updateBotMeta, } from './api.js';
18
+ import { actComputer, bootOrResumeComputer, disk, findBotComputer, grant, opened, parkComputer, updateBotMeta, } from './api.js';
19
19
  import { CLIP, PILL, WORD } from './kit.js';
20
20
  import { DIM } from './ink.js';
21
21
  // Always-dark translucent surfaces inside the pure-black desktop window chrome,
@@ -37,27 +37,18 @@ function PulsingCluster({ label }) {
37
37
  return (_jsx(YStack, { width: mid ? 7 : 4, height: mid ? 7 : 4, rounded: 999, bg: "var(--pure-white)", opacity: active ? 1 : 0.35 }, i));
38
38
  }) }), _jsx(Text, { fontSize: 13, lineHeight: 18, fontWeight: "500", color: "var(--pure-white)", opacity: 0.58, children: label })] }));
39
39
  }
40
- function appendViewParam(rawUrl, viewOnly) {
41
- try {
42
- const u = new URL(rawUrl, typeof window !== 'undefined' ? window.location.origin : 'https://api.hanzo.ai');
43
- u.searchParams.set('viewOnly', viewOnly ? '1' : '0');
44
- return u.toString();
45
- }
46
- catch {
47
- const join = rawUrl.includes('?') ? '&' : '?';
48
- return `${rawUrl}${join}viewOnly=${viewOnly ? '1' : '0'}`;
49
- }
50
- }
51
40
  export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
52
41
  const { t } = useI18n();
53
42
  const { client } = useAi();
54
43
  const displayName = called(bot.name);
55
44
  const iframeRef = useRef(null);
56
45
  const autoBootedRef = useRef(false);
46
+ const controlRef = useRef('watching');
57
47
  const [localBox, setLocalBox] = useState(box);
58
48
  const [expanded, setExpanded] = useState(false);
59
49
  const [mode, setMode] = useState('screen');
60
50
  const [control, setControl] = useState('watching');
51
+ controlRef.current = control;
61
52
  const [phase, setPhase] = useState('idle');
62
53
  const [frameUrl, setFrameUrl] = useState(null);
63
54
  const [snapDataUrl, setSnapDataUrl] = useState(null);
@@ -112,7 +103,7 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
112
103
  try {
113
104
  const g = await grant(client, targetId, kind);
114
105
  if (g.url) {
115
- const finalUrl = kind === 'screen' ? appendViewParam(g.url, wantViewOnly) : g.url;
106
+ const finalUrl = opened(g.url, kind === 'screen' ? wantViewOnly : undefined);
116
107
  setFrameUrl(finalUrl);
117
108
  // Terminal or older edge screen page without postMessage transitions smoothly after load
118
109
  window.setTimeout(() => {
@@ -142,7 +133,7 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
142
133
  await onUpdated();
143
134
  if (leased.status === 'running') {
144
135
  const effectiveMode = leased.class === 'desktop' ? mode : 'terminal';
145
- await openStream(leased.id, effectiveMode, control === 'watching');
136
+ await openStream(leased.id, effectiveMode, controlRef.current === 'watching');
146
137
  }
147
138
  else {
148
139
  // Poll up to ~25s while the sandbox container schedules & boots X11
@@ -153,7 +144,7 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
153
144
  setLocalBox(latest);
154
145
  if (latest?.status === 'running') {
155
146
  await onUpdated();
156
- await openStream(latest.id, latest.class === 'desktop' ? mode : 'terminal', control === 'watching');
147
+ await openStream(latest.id, latest.class === 'desktop' ? mode : 'terminal', controlRef.current === 'watching');
157
148
  break;
158
149
  }
159
150
  }
@@ -169,8 +160,10 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
169
160
  finally {
170
161
  setBusy(false);
171
162
  }
172
- }, [client, busy, bot, activeBox, onUpdated, mode, openStream, control, displayName, t]);
163
+ }, [client, busy, bot, activeBox, onUpdated, mode, openStream, displayName, t]);
173
164
  // Auto-open live stream if running, or auto-boot/resume on open!
165
+ // Intentionally reads `controlRef.current` rather than depending on `control` so
166
+ // clicking `Take control` / `Watching` sends instant postMessage without reloading the iframe.
174
167
  useEffect(() => {
175
168
  if (!open) {
176
169
  autoBootedRef.current = false;
@@ -185,14 +178,14 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
185
178
  if (activeBox?.id && activeBox.status === 'running') {
186
179
  autoBootedRef.current = true;
187
180
  const effectiveMode = activeBox.class === 'desktop' ? mode : 'terminal';
188
- void openStream(activeBox.id, effectiveMode, control === 'watching');
181
+ void openStream(activeBox.id, effectiveMode, controlRef.current === 'watching');
189
182
  return;
190
183
  }
191
184
  if (!autoBootedRef.current && client) {
192
185
  autoBootedRef.current = true;
193
186
  void startOrResume(false);
194
187
  }
195
- }, [open, activeBox?.id, activeBox?.status, activeBox?.class, mode, client, openStream, startOrResume, control]);
188
+ }, [open, activeBox?.id, activeBox?.status, activeBox?.class, mode, client, openStream, startOrResume]);
196
189
  const toggleControl = (nextControl) => {
197
190
  setControl(nextControl);
198
191
  const viewOnly = nextControl === 'watching';
@@ -248,16 +241,21 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
248
241
  setError(null);
249
242
  setStatusToast(null);
250
243
  try {
251
- await actComputer(client, {
244
+ const out = await actComputer(client, {
252
245
  id: activeBox.id,
253
246
  action: 'autofill',
254
247
  credential: item.id || item.domain || item.name,
255
248
  field,
256
- submit: field === 'login' || field === 'totp',
249
+ submit: field === 'login' || field === 'login_totp' || field === 'totp',
257
250
  });
258
- setStatusToast(field === 'totp'
259
- ? t('Typed 6-digit 2FA code for {name} via KMS.', { name: item.name })
260
- : t('Autofilled {name} via zero-knowledge KMS.', { name: item.name }));
251
+ if (out.ok === false) {
252
+ setError(out.text || t('Could not autofill {name}.', { name: item.name }));
253
+ return;
254
+ }
255
+ setStatusToast(out.text ||
256
+ (field === 'totp'
257
+ ? t('Typed 6-digit 2FA code for {name} via KMS.', { name: item.name })
258
+ : t('Autofilled {name} via zero-knowledge KMS.', { name: item.name })));
261
259
  }
262
260
  catch (e) {
263
261
  setError(say(e, t('credential autofill'), 'save', t));
@@ -266,6 +264,31 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
266
264
  setRunningTask(false);
267
265
  }
268
266
  };
267
+ const sealStagedAppCredential = async () => {
268
+ if (!client || !activeBox?.id || runningTask)
269
+ return;
270
+ setRunningTask(true);
271
+ setError(null);
272
+ setStatusToast(null);
273
+ try {
274
+ const out = await actComputer(client, {
275
+ id: activeBox.id,
276
+ action: 'save_credential',
277
+ });
278
+ if (out.ok === false) {
279
+ setError(out.text || t('No staged credential found at /dev/shm/.hanzo-credential.json.'));
280
+ return;
281
+ }
282
+ await refreshVault();
283
+ setStatusToast(out.text || t('Sealed sandbox app credential into Hanzo KMS and shredded RAM file.'));
284
+ }
285
+ catch (e) {
286
+ setError(say(e, t('sandbox credential save'), 'save', t));
287
+ }
288
+ finally {
289
+ setRunningTask(false);
290
+ }
291
+ };
269
292
  const captureScreenshot = async () => {
270
293
  if (!client || !activeBox?.id || runningTask)
271
294
  return;
@@ -273,8 +296,12 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
273
296
  setError(null);
274
297
  try {
275
298
  const out = await actComputer(client, { id: activeBox.id, action: 'screenshot' });
299
+ if (out.ok === false) {
300
+ setError(out.text || t('Could not capture desktop screenshot.'));
301
+ return;
302
+ }
276
303
  if (out.image) {
277
- setSnapDataUrl(`data:${out.mimeType || 'image/png'};base64,${out.image}`);
304
+ setSnapDataUrl(out.image.startsWith('data:') ? out.image : `data:${out.mimeType || 'image/jpeg'};base64,${out.image}`);
278
305
  setStatusToast(t('Captured {w}×{h} frame.', { w: out.width || 1280, h: out.height || 800 }));
279
306
  }
280
307
  }
@@ -324,11 +351,16 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
324
351
  : `${displayName} · ${t('Desktop')}` }) })] }), _jsxs(XStack, { items: "center", gap: 6, children: [awake && activeBox?.id ? (_jsxs(_Fragment, { children: [_jsxs(XStack, { render: "button", type: 'button', "aria-label": mode === 'screen' ? t('Switch to Terminal') : t('Switch to Desktop GUI'), onClick: () => {
325
352
  setSnapDataUrl(null);
326
353
  setMode((m) => (m === 'screen' ? 'terminal' : 'screen'));
327
- }, height: 26, px: 9, gap: 5, rounded: 999, items: "center", bg: RAISED, borderWidth: 1, borderColor: LINE, cursor: "pointer", children: [mode === 'screen' ? (_jsx(Terminal, { size: 12, color: "var(--pure-white)", "aria-hidden": true })) : (_jsx(Monitor, { size: 12, color: "var(--pure-white)", "aria-hidden": true })), _jsx(Text, { fontSize: 11, lineHeight: 15, color: "var(--pure-white)", opacity: 0.85, children: mode === 'screen' ? t('Terminal') : t('Desktop') })] }), _jsxs(DropdownMenu, { placement: "bottom-end", offset: 6, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs(XStack, { render: "button", type: 'button', "aria-label": t('Autofill login or secret'), height: 26, px: 9, gap: 5, rounded: 999, items: "center", bg: RAISED, borderWidth: 1, borderColor: LINE, cursor: "pointer", children: [_jsx(KeyRound, { size: 12, color: "var(--pure-white)", "aria-hidden": true }), _jsx(Text, { fontSize: 11, lineHeight: 15, color: "var(--pure-white)", opacity: 0.85, children: t('Autofill') })] }) }), _jsxs(DropdownMenuContent, { minW: 240, children: [logins.map((item) => (_jsx(DropdownMenuItem, { onSelect: () => void runAutofill(item, 'login'), children: _jsxs(YStack, { gap: 1, children: [_jsx(Text, { fontSize: "$3", fontWeight: "500", color: "$ink", children: `${item.name}${item.domain ? ` (${item.domain})` : ''}` }), _jsx(Text, { fontSize: "$1", color: DIM, children: item.username
328
- ? t('Fill {user} + password via {src}', { user: item.username, src: item.source })
354
+ }, height: 26, px: 9, gap: 5, rounded: 999, items: "center", bg: RAISED, borderWidth: 1, borderColor: LINE, cursor: "pointer", children: [mode === 'screen' ? (_jsx(Terminal, { size: 12, color: "var(--pure-white)", "aria-hidden": true })) : (_jsx(Monitor, { size: 12, color: "var(--pure-white)", "aria-hidden": true })), _jsx(Text, { fontSize: 11, lineHeight: 15, color: "var(--pure-white)", opacity: 0.85, children: mode === 'screen' ? t('Terminal') : t('Desktop') })] }), _jsxs(DropdownMenu, { placement: "bottom-end", offset: 6, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs(XStack, { render: "button", type: 'button', "aria-label": t('Autofill login or secret'), height: 26, px: 9, gap: 5, rounded: 999, items: "center", bg: RAISED, borderWidth: 1, borderColor: LINE, cursor: "pointer", children: [_jsx(KeyRound, { size: 12, color: "var(--pure-white)", "aria-hidden": true }), _jsx(Text, { fontSize: 11, lineHeight: 15, color: "var(--pure-white)", opacity: 0.85, children: t('Autofill') })] }) }), _jsxs(DropdownMenuContent, { minW: 260, children: [logins.map((item) => (_jsx(DropdownMenuItem, { onSelect: () => void runAutofill(item, item.totpSecretKey ? 'login_totp' : 'login'), children: _jsxs(YStack, { gap: 1, children: [_jsx(Text, { fontSize: "$3", fontWeight: "500", color: "$ink", children: `${item.name}${item.domain ? ` (${item.domain})` : ''}` }), _jsx(Text, { fontSize: "$1", color: DIM, children: item.username
355
+ ? item.totpSecretKey
356
+ ? t('Fill {user} + password + 2FA via {src}', {
357
+ user: item.username,
358
+ src: item.source,
359
+ })
360
+ : t('Fill {user} + password via {src}', { user: item.username, src: item.source })
329
361
  : t('Fill password via {src}', { src: item.source }) })] }) }, item.id))), logins
330
362
  .filter((i) => Boolean(i.totpSecretKey))
331
- .map((item) => (_jsx(DropdownMenuItem, { onSelect: () => void runAutofill(item, 'totp'), children: _jsx(Text, { fontSize: "$2", color: "$ink", children: t('2FA TOTP code · {name}', { name: item.name }) }) }, `${item.id}-totp`))), otherSecrets.slice(0, 5).map((item) => (_jsx(DropdownMenuItem, { onSelect: () => void runAutofill(item, 'secret'), children: _jsx(Text, { fontSize: "$2", color: "$ink", children: t('Type secret · {name}', { name: item.name }) }) }, item.id))), _jsx(DropdownMenuItem, { onSelect: () => setVaultOpen(true), children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", children: vaultItems.length === 0
363
+ .map((item) => (_jsx(DropdownMenuItem, { onSelect: () => void runAutofill(item, 'totp'), children: _jsx(Text, { fontSize: "$2", color: "$ink", children: t('2FA TOTP code only · {name}', { name: item.name }) }) }, `${item.id}-totp`))), otherSecrets.slice(0, 5).map((item) => (_jsx(DropdownMenuItem, { onSelect: () => void runAutofill(item, 'secret'), children: _jsx(Text, { fontSize: "$2", color: "$ink", children: t('Type secret · {name}', { name: item.name }) }) }, item.id))), _jsx(DropdownMenuItem, { onSelect: () => void sealStagedAppCredential(), children: _jsxs(YStack, { gap: 1, children: [_jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", children: t('Seal staged sandbox app login → KMS') }), _jsx(Text, { fontSize: "$1", color: DIM, children: t('Imports /dev/shm/.hanzo-credential.json & shreds RAM file') })] }) }), _jsx(DropdownMenuItem, { onSelect: () => setVaultOpen(true), children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", children: vaultItems.length === 0
332
364
  ? t('+ Add 1Password, LastPass, or KMS logins…')
333
365
  : t('Manage Vault & Password Managers…') }) })] })] }), _jsx(XStack, { render: "button", type: 'button', "aria-label": t('Paste clipboard to desktop'), onClick: () => void pasteClipboardToDesktop(), width: 26, height: 26, rounded: 999, items: "center", justify: "center", bg: "transparent", borderWidth: 0, cursor: "pointer", hoverStyle: { bg: RAISED }, children: _jsx(ClipboardPaste, { size: 13, color: "var(--pure-white)", opacity: 0.7, "aria-hidden": true }) }), _jsx(XStack, { render: "button", type: 'button', "aria-label": t('Capture screenshot'), onClick: () => void captureScreenshot(), width: 26, height: 26, rounded: 999, items: "center", justify: "center", bg: "transparent", borderWidth: 0, cursor: "pointer", hoverStyle: { bg: RAISED }, children: _jsx(Camera, { size: 13, color: "var(--pure-white)", opacity: 0.7, "aria-hidden": true }) }), _jsx(XStack, { render: "button", type: 'button', "aria-label": t('Reconnect stream'), onClick: () => {
334
366
  setSnapDataUrl(null);
@@ -178,6 +178,15 @@ export interface Grant {
178
178
  expiresIn?: number;
179
179
  }
180
180
  export declare const grant: (c: Client, id: string, kind: 'terminal' | 'screen') => Promise<Grant>;
181
+ /**
182
+ * Where a grant opens: its address on the API host, and for a screen whether it
183
+ * opens to watch or to control. Cloud answers a PATH
184
+ * (`/v1/sandbox/<id>/screen?ticket=…`, cloud apps/sandbox `ticketGrant`), and the
185
+ * API's host serves it, never the page's: on hanzo.bot the page's own host is the
186
+ * static site, which answers that path with a page that refuses to be framed, and
187
+ * a bot's computer read "hanzo.bot refused to connect".
188
+ */
189
+ export declare function opened(url: string, viewOnly?: boolean): string;
181
190
  /**
182
191
  * Finds the bot's existing desktop sandbox across both named project disks (`bot-<name>`)
183
192
  * and Free-tier persistent `disk: true` sandboxes bound via `bot.computeRef`.
@@ -196,7 +205,7 @@ export declare function bootOrResumeComputer(c: Client, bot: BotAgent, existing?
196
205
  export declare function parkComputer(c: Client, id: string): Promise<void>;
197
206
  export interface ComputerActionIn {
198
207
  id: string;
199
- action: 'screenshot' | 'click' | 'double_click' | 'right_click' | 'middle_click' | 'move' | 'drag' | 'scroll' | 'type' | 'key' | 'navigate' | 'wait' | 'shell' | 'autofill';
208
+ action: 'screenshot' | 'click' | 'double_click' | 'right_click' | 'middle_click' | 'move' | 'drag' | 'scroll' | 'type' | 'key' | 'navigate' | 'wait' | 'shell' | 'autofill' | 'save_credential';
200
209
  x?: number;
201
210
  y?: number;
202
211
  toX?: number;
@@ -204,16 +213,20 @@ export interface ComputerActionIn {
204
213
  dx?: number;
205
214
  dy?: number;
206
215
  text?: string;
216
+ keys?: string;
207
217
  key?: string;
208
218
  url?: string;
209
219
  command?: string;
220
+ seconds?: number;
210
221
  ms?: number;
211
222
  credential?: string;
212
- field?: 'login' | 'username' | 'password' | 'totp' | 'secret';
223
+ field?: 'login' | 'login_totp' | 'username' | 'password' | 'totp' | 'secret';
213
224
  submit?: boolean;
214
225
  }
215
226
  export interface ComputerActionOut {
216
- action: string;
227
+ ok?: boolean;
228
+ text?: string;
229
+ action?: string;
217
230
  stdout?: string;
218
231
  stderr?: string;
219
232
  exitCode?: number;
package/dist/bots/api.js CHANGED
@@ -180,6 +180,20 @@ export async function slackChannels(signal) {
180
180
  }
181
181
  }
182
182
  export const grant = (c, id, kind) => c.http.json({ method: 'POST', path: `/v1/sandbox/${encodeURIComponent(id)}/${kind}/ticket` });
183
+ /**
184
+ * Where a grant opens: its address on the API host, and for a screen whether it
185
+ * opens to watch or to control. Cloud answers a PATH
186
+ * (`/v1/sandbox/<id>/screen?ticket=…`, cloud apps/sandbox `ticketGrant`), and the
187
+ * API's host serves it, never the page's: on hanzo.bot the page's own host is the
188
+ * static site, which answers that path with a page that refuses to be framed, and
189
+ * a bot's computer read "hanzo.bot refused to connect".
190
+ */
191
+ export function opened(url, viewOnly) {
192
+ const u = new URL(url, `${api()}/`);
193
+ if (viewOnly !== undefined)
194
+ u.searchParams.set('viewOnly', viewOnly ? '1' : '0');
195
+ return u.toString();
196
+ }
183
197
  function bestSandbox(boxes) {
184
198
  return (boxes.find((b) => b.status === 'running') ??
185
199
  boxes.find((b) => b.status === 'pending') ??
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/app",
3
- "version": "0.3.90",
3
+ "version": "0.3.92",
4
4
  "description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",