@hanzo/app 0.3.87 → 0.3.89

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/dist/bots/api.js CHANGED
@@ -19,7 +19,7 @@ export const PARAM = 'bot';
19
19
  export const DOLLAR = 1_000_000;
20
20
  /**
21
21
  * Makes a bot with full tool access (`tools: ['*']`) — including Desktop Sandbox
22
- * Computer Use (`computer_in_sandbox`), bash/files, Connectors, and Bot Coordination.
22
+ * Computer Use (`computer_in_sandbox`), bash/files, Connectors, KMS Autofill, and Bot Coordination.
23
23
  */
24
24
  export const make = (c, d) => c.http.json({
25
25
  method: 'POST',
@@ -63,7 +63,7 @@ export async function bootstrapPrimary(c, name = PRIMARY_BOT, model = 'enso') {
63
63
  weekly: 25,
64
64
  isPrimary: true,
65
65
  layer: 0,
66
- instructions: 'You are hanzo, the Primary Bot (Layer 0) for this workspace. Direct worker bots and Bot Groups across layers, operate your Desktop Sandbox Computer, and answer across Slack and connected tools.',
66
+ instructions: 'You are hanzo, the Primary Bot (Layer 0) for this workspace. Direct worker bots and Bot Groups across layers, operate your resumable Desktop Sandbox Computer (including secure KMS login autofill), and answer across Slack and connected tools.',
67
67
  });
68
68
  return { agent: created, created: true };
69
69
  }
@@ -166,21 +166,212 @@ export async function slackChannels(signal) {
166
166
  if (!r.ok)
167
167
  return [];
168
168
  const j = (await r.json());
169
- return (j.channels ?? []).map((ch) => ({
169
+ return (j.channels ?? [])
170
+ .map((ch) => ({
170
171
  id: String(ch.id ?? ''),
171
172
  name: String(ch.name ?? ''),
172
173
  isMember: Boolean(ch.is_member ?? ch.isMember),
173
174
  isPrivate: Boolean(ch.is_private ?? ch.isPrivate),
174
- })).filter((ch) => Boolean(ch.id && ch.name));
175
+ }))
176
+ .filter((ch) => Boolean(ch.id && ch.name));
175
177
  }
176
178
  catch {
177
179
  return [];
178
180
  }
179
181
  }
180
182
  export const grant = (c, id, kind) => c.http.json({ method: 'POST', path: `/v1/sandbox/${encodeURIComponent(id)}/${kind}/ticket` });
181
- export const parkComputer = (c, id) => c.http.json({ method: 'POST', path: `/v1/sandbox/${encodeURIComponent(id)}/park`, body: {} });
183
+ function bestSandbox(boxes) {
184
+ return (boxes.find((b) => b.status === 'running') ??
185
+ boxes.find((b) => b.status === 'pending') ??
186
+ boxes.find((b) => b.status === 'paused' || b.status === 'parked') ??
187
+ boxes[0] ??
188
+ null);
189
+ }
190
+ /**
191
+ * Finds the bot's existing desktop sandbox across both named project disks (`bot-<name>`)
192
+ * and Free-tier persistent `disk: true` sandboxes bound via `bot.computeRef`.
193
+ */
194
+ export async function findBotComputer(c, bot, signal) {
195
+ const opts = signal ? { signal } : undefined;
196
+ try {
197
+ const byProject = await c.sandboxes.list({ project: disk(bot.name) }, opts);
198
+ const found = bestSandbox(byProject);
199
+ if (found)
200
+ return found;
201
+ }
202
+ catch {
203
+ // continue to computeRef lookup
204
+ }
205
+ if (bot.computeRef) {
206
+ try {
207
+ const all = await c.sandboxes.list(undefined, opts);
208
+ const exact = all.find((b) => b.id === bot.computeRef);
209
+ if (exact)
210
+ return exact;
211
+ }
212
+ catch {
213
+ // ignore
214
+ }
215
+ }
216
+ return null;
217
+ }
218
+ function statusOfError(err) {
219
+ if (!err || typeof err !== 'object')
220
+ return 0;
221
+ const rec = err;
222
+ if (typeof rec.status === 'number')
223
+ return rec.status;
224
+ if (typeof rec.statusCode === 'number')
225
+ return rec.statusCode;
226
+ return 0;
227
+ }
228
+ /**
229
+ * Boots or resumes the bot's persistent Desktop Sandbox Computer:
230
+ * 1. If a parked/existing sandbox id is known (`existing?.id` or `bot.computeRef`), resumes it in place.
231
+ * 2. Otherwise leases `{ class: 'desktop', project: 'bot-<name>', disk: true }`.
232
+ * 3. On `402` or `409` (e.g., Free-tier $0 account where named project volumes require balance),
233
+ * seamlessly falls back to `{ class: 'desktop', disk: true }` (admitted on the Free daily allowance
234
+ * with a persistent 2 GiB resumable disk!).
235
+ */
236
+ export async function bootOrResumeComputer(c, bot, existing) {
237
+ const resumeId = existing?.id || bot.computeRef;
238
+ let leased = null;
239
+ if (resumeId) {
240
+ try {
241
+ leased = await c.http.json({
242
+ method: 'POST',
243
+ path: '/v1/sandbox/lease',
244
+ body: { id: resumeId, class: 'desktop', disk: true },
245
+ });
246
+ }
247
+ catch {
248
+ leased = null;
249
+ }
250
+ }
251
+ if (!leased) {
252
+ try {
253
+ leased = await c.http.json({
254
+ method: 'POST',
255
+ path: '/v1/sandbox/lease',
256
+ body: { class: 'desktop', project: disk(bot.name), disk: true },
257
+ });
258
+ }
259
+ catch (err) {
260
+ const code = statusOfError(err);
261
+ if (code === 402 || code === 409) {
262
+ leased = await c.http.json({
263
+ method: 'POST',
264
+ path: '/v1/sandbox/lease',
265
+ body: { class: 'desktop', disk: true },
266
+ });
267
+ }
268
+ else {
269
+ throw err;
270
+ }
271
+ }
272
+ }
273
+ if (leased?.id && (bot.computeRef !== leased.id || !bot.tools?.length)) {
274
+ await updateBotMeta(c, bot.name, { computeRef: leased.id, tools: ['*'] }).catch(() => null);
275
+ }
276
+ return leased;
277
+ }
278
+ /** Parks a running desktop sandbox while preserving its persistent home volume (`disk: true`). */
279
+ export async function parkComputer(c, id) {
280
+ try {
281
+ await c.http.json({
282
+ method: 'POST',
283
+ path: `/v1/sandbox/${encodeURIComponent(id)}/pause`,
284
+ body: {},
285
+ });
286
+ }
287
+ catch {
288
+ await c.http.json({
289
+ method: 'POST',
290
+ path: '/v1/sandbox/park',
291
+ body: { id },
292
+ });
293
+ }
294
+ }
182
295
  export const actComputer = (c, body) => c.http.json({
183
296
  method: 'POST',
184
297
  path: '/v1/sandbox/computer',
185
298
  body,
186
299
  });
300
+ export async function listBotAutomations(c, botName, signal) {
301
+ try {
302
+ const res = await c.http.json({
303
+ path: '/v1/auto/automations',
304
+ signal,
305
+ });
306
+ const all = res.data ?? [];
307
+ if (!botName)
308
+ return all;
309
+ const tag = `[bot:${botName.toLowerCase()}]`;
310
+ return all.filter((a) => {
311
+ const lower = `${a.name} ${a.instructions}`.toLowerCase();
312
+ if (lower.includes('[bot:'))
313
+ return lower.includes(tag);
314
+ return a.source === 'chat';
315
+ });
316
+ }
317
+ catch {
318
+ return [];
319
+ }
320
+ }
321
+ export async function parseAutomationWhen(c, phrase, tz) {
322
+ try {
323
+ const zone = tz || Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
324
+ const res = await c.http.json({
325
+ method: 'POST',
326
+ path: '/v1/auto/when',
327
+ body: { when: phrase, tz: zone },
328
+ });
329
+ return res.schedule ?? null;
330
+ }
331
+ catch {
332
+ return null;
333
+ }
334
+ }
335
+ export async function createBotAutomation(c, input) {
336
+ const prefix = `[bot:${input.botName}]`;
337
+ const taggedInstructions = input.instructions.includes(prefix)
338
+ ? input.instructions
339
+ : `${prefix} Acting as bot "${input.botName}", carry out this automation using your tools, connectors, and resumable desktop sandbox computer when needed:\n\n${input.instructions}`;
340
+ const body = {
341
+ name: input.name.trim(),
342
+ instructions: taggedInstructions,
343
+ permissions: 'auto',
344
+ notify: input.notify ?? true,
345
+ enabled: true,
346
+ source: 'chat',
347
+ };
348
+ if (input.model)
349
+ body.model = input.model;
350
+ if (input.mode === 'event' && input.event) {
351
+ body.event = input.event;
352
+ body.schedule = { kind: 'manual' };
353
+ }
354
+ else {
355
+ const zone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
356
+ body.schedule = input.schedule ?? { kind: 'daily', at: '09:00', tz: zone };
357
+ }
358
+ return c.http.json({
359
+ method: 'POST',
360
+ path: '/v1/auto/automations',
361
+ body,
362
+ });
363
+ }
364
+ export const toggleBotAutomation = (c, id, enabled) => c.http.json({
365
+ method: 'PATCH',
366
+ path: `/v1/auto/automations/${encodeURIComponent(id)}`,
367
+ body: { enabled },
368
+ });
369
+ export const runBotAutomation = (c, id) => c.http.json({
370
+ method: 'POST',
371
+ path: `/v1/auto/automations/${encodeURIComponent(id)}/run`,
372
+ body: {},
373
+ });
374
+ export const deleteBotAutomation = (c, id) => c.http.json({
375
+ method: 'DELETE',
376
+ path: `/v1/auto/automations/${encodeURIComponent(id)}`,
377
+ });
@@ -1,4 +1,5 @@
1
1
  import type { Agent } from '@hanzo/ai';
2
+ export declare function cleanAvatarUrl(url?: string | null): string | undefined;
2
3
  export declare function Face({ bot, size, person, starred, }: {
3
4
  bot: Pick<Agent, 'name' | 'avatar' | 'emoji'>;
4
5
  size?: number;
package/dist/bots/face.js CHANGED
@@ -1,16 +1,39 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // A bot's face, or a person's.
4
+ //
5
+ // Core team members resolve their memoji portrait via `roleOf(bot.name)` when
6
+ // the agent row itself stores no custom avatar URL; people render their own
7
+ // avatar or crisp initial disc (ignoring auto-generated Gravatar identicons).
8
+ import { useEffect, useState } from 'react';
3
9
  import { Text, YStack } from '@hanzo/gui';
4
10
  import { Star } from 'lucide-react';
5
11
  import { roleOf } from '../cast.js';
6
12
  import { called } from '../team.js';
7
13
  import { FLOOR, INK } from './ink.js';
14
+ export function cleanAvatarUrl(url) {
15
+ if (!url)
16
+ return undefined;
17
+ const u = url.trim();
18
+ if (!u)
19
+ return undefined;
20
+ // Strip auto-generated default Gravatar identicons so Hanzo renders its clean
21
+ // monochrome initial disc without making external gravatar.com requests.
22
+ if (u.includes('gravatar.com/avatar/') && u.includes('d=identicon'))
23
+ return undefined;
24
+ return u;
25
+ }
8
26
  export function Face({ bot, size = 36, person = false, starred = false, }) {
9
27
  const round = { width: size, height: size, shrink: 0, rounded: 9999, overflow: 'hidden' };
10
- const src = bot.avatar || (!person ? roleOf(bot.name)?.portrait : undefined);
28
+ const candidate = cleanAvatarUrl(bot.avatar) || (!person ? roleOf(bot.name)?.portrait : undefined);
29
+ const [failed, setFailed] = useState(false);
30
+ useEffect(() => {
31
+ setFailed(false);
32
+ }, [candidate]);
33
+ const src = failed ? undefined : candidate;
11
34
  const label = person ? (bot.name || '') : called(bot.name || '');
12
35
  const glyph = Math.round(size * (bot.emoji ? 0.5 : 0.42));
13
- const disc = src ? (_jsx(YStack, { render: "img", src, alt: '', "aria-hidden": true, ...round, objectFit: "cover" })) : (_jsx(YStack, { "aria-hidden": true, ...round, items: "center", justify: "center", bg: person ? 'var(--info, var(--secondary))' : 'var(--secondary)', userSelect: 'none', children: _jsx(Text, { color: person ? 'var(--pure-white, var(--foreground))' : INK, fontSize: glyph, lineHeight: glyph, fontWeight: "600", children: bot.emoji || (label || '?').trim().charAt(0).toUpperCase() }) }));
36
+ const disc = src ? (_jsx(YStack, { render: "img", src, alt: '', onError: () => setFailed(true), "aria-hidden": true, ...round, objectFit: "cover" })) : (_jsx(YStack, { "aria-hidden": true, ...round, items: "center", justify: "center", bg: person ? 'var(--info, var(--secondary))' : 'var(--secondary)', userSelect: 'none', children: _jsx(Text, { color: person ? 'var(--pure-white, var(--foreground))' : INK, fontSize: glyph, lineHeight: glyph, fontWeight: "600", children: bot.emoji || (label || '?').trim().charAt(0).toUpperCase() }) }));
14
37
  if (!starred)
15
38
  return disc;
16
39
  return (_jsxs(YStack, { position: "relative", width: size, height: size, shrink: 0, children: [disc, _jsx(YStack, { "aria-hidden": true, position: "absolute", r: -1, b: -1, width: 20, height: 20, rounded: 9999, items: "center", justify: "center", bg: "var(--warning, var(--chrome-dot-yellow))", borderWidth: 2, borderColor: FLOOR, children: _jsx(Star, { size: 10, color: "var(--pure-white, var(--foreground))", fill: "currentColor", strokeWidth: 2 }) })] }));
package/dist/cast.js CHANGED
@@ -245,14 +245,15 @@ export function fallbackMemoji(name) {
245
245
  * column want the same picture at two sizes, not two pictures.
246
246
  */
247
247
  export function Face({ src, emoji, name, title, size = 32, person = false, }) {
248
+ const cleanSrc = src && !(src.includes('gravatar.com/avatar/') && src.includes('d=identicon')) ? src : undefined;
248
249
  const role = person ? undefined : roleOf(name);
249
250
  const cast = person ? undefined : role?.portrait || fallbackMemoji(name);
250
- const [imgSrc, setImgSrc] = useState(src || (emoji ? undefined : cast));
251
+ const [imgSrc, setImgSrc] = useState(cleanSrc || (emoji ? undefined : cast));
251
252
  const [failed, setFailed] = useState(false);
252
253
  useEffect(() => {
253
- setImgSrc(src || (emoji ? undefined : cast));
254
+ setImgSrc(cleanSrc || (emoji ? undefined : cast));
254
255
  setFailed(false);
255
- }, [src, emoji, cast]);
256
+ }, [cleanSrc, emoji, cast]);
256
257
  const handleError = () => {
257
258
  if (failed)
258
259
  return;
@@ -0,0 +1,60 @@
1
+ import { LABEL } from './bots/kit.js';
2
+ export type VaultSource = 'hanzo' | '1password' | 'lastpass';
3
+ export type VaultKind = 'login' | 'api_key' | 'secret';
4
+ export interface VaultItem {
5
+ id: string;
6
+ kind: VaultKind;
7
+ name: string;
8
+ envVar?: string;
9
+ domain?: string;
10
+ url?: string;
11
+ username?: string;
12
+ secretKey: string;
13
+ totpSecretKey?: string;
14
+ source: VaultSource;
15
+ vaultRef?: string;
16
+ updatedAt: string;
17
+ }
18
+ export interface VaultProviders {
19
+ onepassword?: {
20
+ connected: boolean;
21
+ vaultName?: string;
22
+ accountHint?: string;
23
+ secretKey?: string;
24
+ syncedCount?: number;
25
+ updatedAt?: string;
26
+ };
27
+ lastpass?: {
28
+ connected: boolean;
29
+ email?: string;
30
+ secretKey?: string;
31
+ syncedCount?: number;
32
+ updatedAt?: string;
33
+ };
34
+ }
35
+ export interface VaultDoc {
36
+ items: VaultItem[];
37
+ providers: VaultProviders;
38
+ secretKeys: string[];
39
+ }
40
+ export declare function readVault(signal?: AbortSignal): Promise<VaultDoc>;
41
+ export declare function writeVault(config: {
42
+ items: VaultItem[];
43
+ providers: VaultProviders;
44
+ }, secrets?: Record<string, string>): Promise<VaultDoc>;
45
+ export declare function parsePasswordImport(raw: string, source: '1password' | 'lastpass'): {
46
+ items: VaultItem[];
47
+ secrets: Record<string, string>;
48
+ };
49
+ export declare function VaultManager({ compact, onAutofill, onChanged, }: {
50
+ compact?: boolean;
51
+ onAutofill?: (item: VaultItem, field?: 'login' | 'totp') => void;
52
+ onChanged?: (doc: VaultDoc) => void;
53
+ }): import("react").JSX.Element;
54
+ export declare function VaultDialog({ open, onOpenChange, onAutofill, onChanged, }: {
55
+ open: boolean;
56
+ onOpenChange: (open: boolean) => void;
57
+ onAutofill?: (item: VaultItem, field?: 'login' | 'totp') => void;
58
+ onChanged?: (doc: VaultDoc) => void;
59
+ }): import("react").JSX.Element;
60
+ export { LABEL as VAULT_LABEL };