@hanzo/app 0.3.85 → 0.3.86

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.
@@ -1,9 +1,5 @@
1
1
  export declare function Bots({ foot, bot: held, onBot, }?: {
2
- /** The reader and the other apps at the roster's foot. A host whose own chrome
3
- * already holds both (hanzo.team's rail and bar) passes false. */
4
2
  foot?: boolean;
5
- /** The open bot, when the host's router holds the address (`?bot=`); with it,
6
- * `onBot` is how a press or Back moves it. Absent, the app keeps the address. */
7
3
  bot?: string | null;
8
4
  onBot?: (name: string | null, step: boolean) => void;
9
5
  }): import("react").JSX.Element;
package/dist/bots/Bots.js CHANGED
@@ -1,37 +1,30 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- // The Bots app: make a bot, open it, talk to it.
4
- //
5
- // Three columns, as the desktop app draws them: the roster (the bots as a grid
6
- // of faces, then the rest with their last word, then you), the thread with the
7
- // open bot, and the panel of what that bot has. Every row, message and switch is
8
- // a platform record — `/v1/agents` and the runs it records — and a section with
9
- // nothing behind it is not drawn.
10
- //
11
- // The same component is the app on hanzo.bot (hanzo.ai's /bots) and on
12
- // hanzo.team, so a bot made in one is in the other: one list, one thread, one
13
- // API, read with the reader's own token.
14
- //
15
- // Below a tablet the columns are one at a time: the roster, then the thread a
16
- // press opens (a step in the history, so Back returns to the roster), with the
17
- // panel over it.
3
+ // The Bots app on hanzo.bot and hanzo.team:
4
+ // - Starts every workspace with up to 1 Primary Bot (default name `"hanzo"`, Layer 0)
5
+ // who directs all subordinate bots (`agent_<name>`) and layered Bot Groups (`group_<name>`).
6
+ // - Supports multi-layer Bot Groups (`?bot=group:<name>`) with pluggable Leader,
7
+ // Lux Quasar (Polaris/Aurora/Pulsar SHA3-384 dual-certificate finality), Majority,
8
+ // Weighted, Unanimous, Kai, and Custom policies.
9
+ // - Connects @hanzo to Slack with channel sync & routing, real Connectors, and
10
+ // dedicated Desktop Sandbox Computers with full GUI Computer Use for every bot.
18
11
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
19
12
  import { useIam } from '@hanzo/iam/react';
20
13
  import { useI18n } from '@hanzo/i18n/react';
21
14
  import { XStack, YStack } from '@hanzo/gui';
22
- import { useAi } from '../lib/ai.js';
15
+ import { ENSO, useAi } from '../lib/ai.js';
23
16
  import { useKept } from '../kept.js';
24
17
  import { say } from '../failure.js';
25
18
  import { Roster } from './Roster.js';
26
19
  import { Thread } from './Thread.js';
20
+ import { GroupPanel, GroupThread, MakeGroupDialog } from './Groups.js';
27
21
  import { recordedRun, refusal } from './refusal.js';
28
22
  import { Panel } from './Panel.js';
29
23
  import { Make } from './Make.js';
30
- import { ALWAYS, ONCE, PARAM } from './api.js';
24
+ import { ALWAYS, ONCE, PARAM, PRIMARY_BOT, bootstrapPrimary, deleteGroup, groupNameOf, isGroupRef, listGroups, toGroupRef, } from './api.js';
31
25
  import { instant } from './time.js';
32
26
  import { FLOOR, GROUND, LINE } from './ink.js';
33
27
  const named = () => typeof window === 'undefined' ? null : new URLSearchParams(window.location.search).get(PARAM);
34
- /** Writes the open bot into the address: a new step when a phone enters a thread, else in place. */
35
28
  function address(name, step) {
36
29
  const url = new URL(window.location.href);
37
30
  if (name)
@@ -39,14 +32,11 @@ function address(name, step) {
39
32
  else
40
33
  url.searchParams.delete(PARAM);
41
34
  const to = `${url.pathname}${url.search}${url.hash}`;
42
- // Null, not the current state: Next's router stamps its own entries and syncs
43
- // only a write that does not carry its stamp.
44
35
  if (step)
45
36
  window.history.pushState(null, '', to);
46
37
  else
47
38
  window.history.replaceState(null, '', to);
48
39
  }
49
- /** The newest run of each bot, from the org's feed (newest first). */
50
40
  function lastOf(feed) {
51
41
  const out = new Map();
52
42
  for (const r of feed)
@@ -54,14 +44,12 @@ function lastOf(feed) {
54
44
  out.set(r.agent, r);
55
45
  return out;
56
46
  }
57
- /** Runs by id, oldest first: a late read never drops a run this page already drew. */
58
47
  function merged(a, b) {
59
48
  const by = new Map();
60
49
  for (const r of [...a, ...b])
61
50
  by.set(r.id, r);
62
51
  return [...by.values()].sort((x, y) => (instant(x.createdAt) ?? 0) - (instant(y.createdAt) ?? 0));
63
52
  }
64
- /** Whether a media query holds, kept current. False until mounted. */
65
53
  function useWide(query) {
66
54
  const [on, setOn] = useState(false);
67
55
  useEffect(() => {
@@ -80,25 +68,25 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
80
68
  const live = Boolean(client && isAuthenticated && ready);
81
69
  const hosted = held !== undefined;
82
70
  const [bots, setBots] = useState(null);
83
- // The roster has been read once, so a name it lacks is not this org's.
71
+ const [groups, setGroups] = useState([]);
84
72
  const [listed, setListed] = useState(false);
85
73
  const [feed, setFeed] = useState([]);
86
74
  const [unread, setUnread] = useState(null);
87
75
  const [own, setOwn] = useState(null);
88
76
  const [making, setMaking] = useState(false);
89
- // The panel beside the thread, kept per browser; over the thread below a laptop.
77
+ const [makingGroup, setMakingGroup] = useState(false);
78
+ const [editingGroup, setEditingGroup] = useState(null);
90
79
  const [side, setSide] = useKept('hanzo.bots.side', true);
91
80
  const [over, setOver] = useState(false);
92
81
  const wide = useWide('(min-width: 768px)');
93
82
  const laptop = useWide('(min-width: 1280px)');
94
- // The address, read on arrival and on every Back and Forward.
95
83
  useEffect(() => {
96
84
  if (hosted)
97
85
  return;
98
- const read = () => setOwn(named());
99
- read();
100
- window.addEventListener('popstate', read);
101
- return () => window.removeEventListener('popstate', read);
86
+ const readAddr = () => setOwn(named());
87
+ readAddr();
88
+ window.addEventListener('popstate', readAddr);
89
+ return () => window.removeEventListener('popstate', readAddr);
102
90
  }, [hosted]);
103
91
  const name = hosted ? (held ?? null) : own;
104
92
  const move = useCallback((next, step) => {
@@ -107,16 +95,38 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
107
95
  setOwn(next);
108
96
  address(next, step);
109
97
  }, [hosted, onBot]);
98
+ const bootstrapped = useRef(false);
110
99
  const reading = useRef(0);
111
100
  const read = useCallback(async () => {
112
101
  if (!client)
113
102
  return;
114
103
  const turn = ++reading.current;
115
- const [list, runs] = await Promise.allSettled([client.agents.list(), client.agents.runs({ limit: 200 })]);
104
+ const [list, runs, grps] = await Promise.allSettled([
105
+ client.agents.list(),
106
+ client.agents.runs({ limit: 200 }),
107
+ listGroups(client),
108
+ ]);
116
109
  if (turn !== reading.current)
117
110
  return;
111
+ if (grps.status === 'fulfilled')
112
+ setGroups(grps.value);
118
113
  if (list.status === 'fulfilled') {
119
- setBots(list.value);
114
+ const loaded = list.value;
115
+ const hasPrimary = loaded.some((b) => b.isPrimary || b.name.toLowerCase() === PRIMARY_BOT);
116
+ if (!hasPrimary && !bootstrapped.current) {
117
+ bootstrapped.current = true;
118
+ const seeded = await bootstrapPrimary(client, PRIMARY_BOT, ENSO).catch(() => null);
119
+ if (seeded?.agent) {
120
+ const mergedBots = [seeded.agent, ...loaded.filter((b) => b.name !== seeded.agent.name)];
121
+ setBots(mergedBots);
122
+ setListed(true);
123
+ setUnread(null);
124
+ if (runs.status === 'fulfilled')
125
+ setFeed(runs.value);
126
+ return;
127
+ }
128
+ }
129
+ setBots(loaded);
120
130
  setListed(true);
121
131
  setUnread(null);
122
132
  }
@@ -132,29 +142,42 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
132
142
  void read();
133
143
  }, [live, read]);
134
144
  const last = useMemo(() => lastOf(feed), [feed]);
135
- // The open bot is the one the address names. With none — or one this org does
136
- // not keep — a laptop opens the one last spoken to (else the first) and writes
137
- // it into the address, so it stays open while the feed moves; a phone stays on
138
- // the roster.
139
- const bot = useMemo(() => (name && bots?.find((b) => b.name === name)) || null, [bots, name]);
145
+ const activeGroup = useMemo(() => {
146
+ if (!isGroupRef(name))
147
+ return null;
148
+ const slug = groupNameOf(name);
149
+ return groups.find((g) => g.name === slug || g.id === slug) ?? null;
150
+ }, [groups, name]);
151
+ const bot = useMemo(() => {
152
+ if (!name || isGroupRef(name))
153
+ return null;
154
+ return bots?.find((b) => b.name === name) ?? null;
155
+ }, [bots, name]);
140
156
  useEffect(() => {
141
- if (!bots || bot)
157
+ if (!bots || bot || activeGroup)
142
158
  return;
143
159
  if (name) {
144
- if (listed && !bots.some((b) => b.name === name))
145
- move(null, false);
160
+ if (listed) {
161
+ if (isGroupRef(name) && !groups.some((g) => g.name === groupNameOf(name) || g.id === groupNameOf(name))) {
162
+ move(null, false);
163
+ }
164
+ else if (!isGroupRef(name) && !bots.some((b) => b.name === name)) {
165
+ move(null, false);
166
+ }
167
+ }
146
168
  return;
147
169
  }
148
170
  if (!wide || !bots.length)
149
171
  return;
172
+ // Start with the workspace's Primary Bot ("hanzo") first so users immediately
173
+ // talk to their primary director bot, falling back to most recent or first bot.
174
+ const primary = bots.find((b) => b.isPrimary) ?? bots.find((b) => b.name.toLowerCase() === PRIMARY_BOT);
150
175
  const recent = feed.find((r) => r.agent && bots.some((b) => b.name === r.agent))?.agent;
151
- move(recent ?? bots[0].name, false);
152
- }, [bots, bot, name, listed, wide, feed, move]);
153
- // Whether this page stepped into the thread, so Back can step out of it.
176
+ move(primary?.name ?? recent ?? bots[0].name, false);
177
+ }, [bots, groups, bot, activeGroup, name, listed, wide, feed, move]);
154
178
  const stepped = useRef(false);
155
179
  const pick = useCallback((next) => {
156
180
  setOver(false);
157
- // A phone steps into the thread, so Back returns to the roster.
158
181
  const step = !wide && !name;
159
182
  if (step)
160
183
  stepped.current = true;
@@ -174,7 +197,8 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
174
197
  const [pending, setPending] = useState(null);
175
198
  const [notice, setNotice] = useState(null);
176
199
  const [wrong, setWrong] = useState(null);
177
- const open = bot?.name ?? null;
200
+ const openRef = activeGroup ? toGroupRef(activeGroup.name) : (bot?.name ?? null);
201
+ const openBotName = bot?.name ?? null;
178
202
  const asking = useRef(0);
179
203
  const history = useCallback(async (who, signal) => {
180
204
  if (!client)
@@ -184,28 +208,22 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
184
208
  setRuns((drawn) => merged(drawn ?? [], rows));
185
209
  }, [client]);
186
210
  useEffect(() => {
187
- // Another bot is open: whatever the last one's run answers, it is not this thread's.
188
211
  asking.current += 1;
189
212
  setRuns(null);
190
213
  setPending(null);
191
214
  setNotice(null);
192
215
  setWrong(null);
193
- if (!client || !open)
216
+ if (!client || !openBotName)
194
217
  return;
195
218
  const stop = new AbortController();
196
- history(open, stop.signal).catch((e) => {
219
+ history(openBotName, stop.signal).catch((e) => {
197
220
  if (stop.signal.aborted)
198
221
  return;
199
222
  setRuns([]);
200
223
  setWrong(say(e, t('this conversation'), 'read', t));
201
224
  });
202
225
  return () => stop.abort();
203
- }, [client, open, history, t]);
204
- /**
205
- * Says `input` to the open bot. Answers whether the platform recorded it: a
206
- * message it refused, or never received, is handed back to the composer so
207
- * the thread holds only what was said.
208
- */
226
+ }, [client, openBotName, history, t]);
209
227
  const send = useCallback(async (input) => {
210
228
  if (!client || !bot)
211
229
  return false;
@@ -222,7 +240,6 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
222
240
  return true;
223
241
  }
224
242
  catch (e) {
225
- // A thread since left: its words are not handed to the one now open.
226
243
  if (!now())
227
244
  return true;
228
245
  const no = refusal(e, who, Date.now(), t, bot.period);
@@ -230,8 +247,6 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
230
247
  setNotice(no);
231
248
  return false;
232
249
  }
233
- // A run that reached its model and failed is recorded and comes back as
234
- // the body; it is drawn with its own error. Anything else never arrived.
235
250
  const ran = recordedRun(e);
236
251
  if (ran) {
237
252
  setRuns((rs) => merged(rs ?? [], [ran]));
@@ -246,12 +261,6 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
246
261
  void read();
247
262
  }
248
263
  }, [client, bot, read, t]);
249
- /**
250
- * Runs on its schedule, or only when asked. The platform keeps no schedule for
251
- * a bot that runs only when asked, so turning it back on states the schedule.
252
- */
253
- // The schedule each bot last had on this page. The platform keeps none for a bot
254
- // that runs only when asked, so a schedule turned off is held here to turn back on.
255
264
  const [kept, setKept] = useState({});
256
265
  const schedule = useCallback(async (on, cron) => {
257
266
  if (!client || !bot)
@@ -260,7 +269,6 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
260
269
  const saved = await client.agents.update(bot.name, on ? { executionMode: ALWAYS, schedule: cron } : { executionMode: ONCE });
261
270
  setBots((all) => (all ?? []).map((b) => (b.name === saved.name ? { ...b, ...saved, schedule: saved.schedule } : b)));
262
271
  }, [client, bot]);
263
- /** Deletes the open bot and every run recorded against it. */
264
272
  const remove = useCallback(async () => {
265
273
  if (!client || !bot)
266
274
  return;
@@ -271,6 +279,16 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
271
279
  move(null, false);
272
280
  await read();
273
281
  }, [client, bot, move, read]);
282
+ const removeGroup = useCallback(async () => {
283
+ if (!client || !activeGroup)
284
+ return;
285
+ await deleteGroup(client, activeGroup.name);
286
+ setGroups((all) => all.filter((g) => g.name !== activeGroup.name));
287
+ setOver(false);
288
+ stepped.current = false;
289
+ move(null, false);
290
+ await read();
291
+ }, [client, activeGroup, move, read]);
274
292
  const made = useCallback(async (agent) => {
275
293
  setMaking(false);
276
294
  setBots((all) => [...(all ?? []).filter((b) => b.name !== agent.name), agent]);
@@ -280,7 +298,17 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
280
298
  move(agent.name, step);
281
299
  await read();
282
300
  }, [move, read, wide, name]);
283
- // Escape closes the panel over the thread, as it closes any dialog.
301
+ const savedGroup = useCallback(async (group) => {
302
+ setMakingGroup(false);
303
+ setEditingGroup(null);
304
+ setGroups((all) => [...all.filter((g) => g.name !== group.name && g.id !== group.id), group]);
305
+ const ref = toGroupRef(group.name);
306
+ const step = !wide && !name;
307
+ if (step)
308
+ stepped.current = true;
309
+ move(ref, step);
310
+ await read();
311
+ }, [move, read, wide, name]);
284
312
  useEffect(() => {
285
313
  if (!over)
286
314
  return;
@@ -293,7 +321,11 @@ export function Bots({ foot = true, bot: held, onBot, } = {}) {
293
321
  setSide(false);
294
322
  setOver(false);
295
323
  };
296
- const panel = bot ? (_jsx(Panel, { bot: bot, runs: runs ?? [], kept: kept[bot.name] ?? '', onClose: close, onSchedule: schedule, onDelete: remove, focus: over && !laptop }, bot.name)) : null;
324
+ const panel = activeGroup ? (_jsx(GroupPanel, { group: activeGroup, groups: groups, bots: bots ?? [], onClose: close, onEdit: () => setEditingGroup(activeGroup), onDelete: removeGroup, onPickBot: pick }, `grp:${activeGroup.name}`)) : bot ? (_jsx(Panel, { bot: bot, groups: groups, runs: runs ?? [], kept: kept[bot.name] ?? '', onClose: close, onSchedule: schedule, onDelete: remove, onBotChanged: read, onPickGroup: pick, focus: over && !laptop }, bot.name)) : null;
297
325
  const shown = laptop ? side : over;
298
- return (_jsxs(XStack, { "data-parity-key": "bots.window", width: "100%", height: "100%", overflow: "hidden", bg: FLOOR, position: "relative", children: [_jsx(YStack, { "data-parity-key": "bots.roster", width: 260, shrink: 0, height: "100%", bg: FLOOR, borderRightWidth: 1, borderColor: LINE, "$max-md": { width: '100%', borderRightWidth: 0, display: bot ? 'none' : 'flex' }, children: _jsx(Roster, { bots: bots, last: last, open: open, unread: unread, me: foot ? user : null, onPick: pick, onMake: () => setMaking(true), disabled: !live }) }), _jsx(YStack, { "data-parity-key": "bots.center", flex: 1, minW: 0, height: "100%", bg: GROUND, "$max-md": { display: bot ? 'flex' : 'none' }, children: _jsx(Thread, { bot: bot, bots: bots ?? [], runs: runs, pending: pending, notice: notice, wrong: wrong, side: shown, live: live, loaded: bots !== null, onSend: send, onDismiss: () => setNotice(null), onSide: () => (laptop ? setSide(!side) : setOver(!over)), onBack: back, onMake: () => setMaking(true) }) }), laptop && side && panel ? (_jsx(YStack, { "data-parity-key": "bots.panel", width: 296, shrink: 0, height: "100%", bg: GROUND, borderLeftWidth: 1, borderColor: LINE, "$max-xl": { display: 'none' }, children: panel })) : null, over && panel && !laptop ? (_jsx(YStack, { "data-parity-key": "bots.panel.over", role: "dialog", "aria-modal": true, "aria-label": bot?.name, position: "absolute", t: 0, r: 0, b: 0, width: 296, maxW: "100%", z: 10, bg: GROUND, borderLeftWidth: 1, borderColor: LINE, boxShadow: "var(--shadow-floating)", children: panel })) : null, making ? _jsx(Make, { onDone: made, onCancel: () => setMaking(false) }) : null] }));
326
+ const hasSelection = Boolean(bot || activeGroup);
327
+ return (_jsxs(XStack, { "data-parity-key": "bots.window", width: "100%", height: "100%", overflow: "hidden", bg: FLOOR, position: "relative", children: [_jsx(YStack, { "data-parity-key": "bots.roster", width: 260, shrink: 0, height: "100%", bg: FLOOR, borderRightWidth: 1, borderColor: LINE, "$max-md": { width: '100%', borderRightWidth: 0, display: hasSelection ? 'none' : 'flex' }, children: _jsx(Roster, { bots: bots, groups: groups, last: last, open: openRef, unread: unread, me: foot ? user : null, onPick: pick, onMake: () => setMaking(true), onMakeGroup: () => setMakingGroup(true), disabled: !live }) }), _jsx(YStack, { "data-parity-key": "bots.center", flex: 1, minW: 0, height: "100%", bg: GROUND, "$max-md": { display: hasSelection ? 'flex' : 'none' }, children: activeGroup ? (_jsx(GroupThread, { group: activeGroup, bots: bots ?? [], side: shown, onSide: () => (laptop ? setSide(!side) : setOver(!over)), onBack: back, onEdit: () => setEditingGroup(activeGroup), onPickBot: pick })) : (_jsx(Thread, { bot: bot, bots: bots ?? [], runs: runs, pending: pending, notice: notice, wrong: wrong, side: shown, live: live, loaded: bots !== null, onSend: send, onDismiss: () => setNotice(null), onSide: () => (laptop ? setSide(!side) : setOver(!over)), onBack: back, onMake: () => setMaking(true) })) }), laptop && side && panel ? (_jsx(YStack, { "data-parity-key": "bots.panel", width: 300, shrink: 0, height: "100%", bg: GROUND, borderLeftWidth: 1, borderColor: LINE, "$max-xl": { display: 'none' }, children: panel })) : null, over && panel && !laptop ? (_jsx(YStack, { "data-parity-key": "bots.panel.over", role: "dialog", "aria-modal": true, "aria-label": activeGroup?.name || bot?.name, position: "absolute", t: 0, r: 0, b: 0, width: 300, maxW: "100%", z: 10, bg: GROUND, borderLeftWidth: 1, borderColor: LINE, boxShadow: "var(--shadow-floating)", children: panel })) : null, making ? _jsx(Make, { groups: groups, onDone: made, onCancel: () => setMaking(false) }) : null, makingGroup || editingGroup ? (_jsx(MakeGroupDialog, { bots: bots ?? [], groups: groups, initial: editingGroup, onDone: savedGroup, onCancel: () => {
328
+ setMakingGroup(false);
329
+ setEditingGroup(null);
330
+ } })) : null] }));
299
331
  }
@@ -0,0 +1,9 @@
1
+ import type { Sandbox } from '@hanzo/ai';
2
+ import { type BotAgent } from './api.js';
3
+ export declare function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }: {
4
+ open: boolean;
5
+ onOpenChange: (open: boolean) => void;
6
+ bot: BotAgent;
7
+ box: Sandbox | null;
8
+ onUpdated: () => void | Promise<void>;
9
+ }): import("react").JSX.Element;
@@ -0,0 +1,175 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Embedded Desktop Sandbox Computer modal for any bot on hanzo.bot:
4
+ // - Live interactive X11 GUI desktop (`screen` ticket -> noVNC) + interactive shell (`terminal` ticket)
5
+ // - Persistent per-bot disk (`bot-<name>`) and `computeRef` binding on the bot record
6
+ // - Full Computer Use task bar so the user can watch the bot click, type, browse,
7
+ // take screenshots, and run commands on its dedicated desktop in real time.
8
+ import { useCallback, useEffect, useState } from 'react';
9
+ import { useI18n } from '@hanzo/i18n/react';
10
+ import { Input, Text, XStack, YStack } from '@hanzo/gui';
11
+ import { Dialog, DialogContent, DialogTitle } from '@hanzo/ui';
12
+ import { Camera, ExternalLink, Monitor, Pause, Play, RefreshCw, Send, Terminal, X } from 'lucide-react';
13
+ import { useAi } from '../lib/ai.js';
14
+ import { say } from '../failure.js';
15
+ import { called } from '../team.js';
16
+ import { Face } from './face.js';
17
+ import { actComputer, disk, grant, parkComputer, updateBotMeta } from './api.js';
18
+ import { CLIP, PILL, ROUND, WORD } from './kit.js';
19
+ import { DIM, FLOOR, GROUND, INK, LINE, PICKED, RAISED } from './ink.js';
20
+ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
21
+ const { t } = useI18n();
22
+ const { client } = useAi();
23
+ const displayName = called(bot.name);
24
+ const [mode, setMode] = useState('screen');
25
+ const [frameUrl, setFrameUrl] = useState(null);
26
+ const [snapDataUrl, setSnapDataUrl] = useState(null);
27
+ const [busy, setBusy] = useState(false);
28
+ const [task, setTask] = useState('');
29
+ const [runningTask, setRunningTask] = useState(false);
30
+ const [lastAnswer, setLastAnswer] = useState(null);
31
+ const [error, setError] = useState(null);
32
+ const awake = box?.status === 'running';
33
+ const waking = box?.status === 'pending';
34
+ const openStream = useCallback(async (targetId, kind) => {
35
+ if (!client)
36
+ return;
37
+ setError(null);
38
+ try {
39
+ const g = await grant(client, targetId, kind);
40
+ if (g.url) {
41
+ setFrameUrl(g.url);
42
+ }
43
+ else {
44
+ setError(t('Desktop stream ticket was minted without a stream URL.'));
45
+ }
46
+ }
47
+ catch (e) {
48
+ setError(say(e, t('{name}’s desktop stream', { name: displayName }), 'read', t));
49
+ }
50
+ }, [client, displayName, t]);
51
+ useEffect(() => {
52
+ if (!open) {
53
+ setFrameUrl(null);
54
+ setSnapDataUrl(null);
55
+ setError(null);
56
+ return;
57
+ }
58
+ if (box?.id && box.status === 'running') {
59
+ const effectiveMode = box.class === 'desktop' ? mode : 'terminal';
60
+ void openStream(box.id, effectiveMode);
61
+ }
62
+ else {
63
+ setFrameUrl(null);
64
+ }
65
+ }, [open, box?.id, box?.status, box?.class, mode, openStream]);
66
+ const startComputer = async () => {
67
+ if (!client || busy)
68
+ return;
69
+ setBusy(true);
70
+ setError(null);
71
+ try {
72
+ const leased = await client.sandboxes.lease({ class: 'desktop', project: disk(bot.name) });
73
+ if (leased?.id && bot.computeRef !== leased.id) {
74
+ await updateBotMeta(client, bot.name, { computeRef: leased.id, tools: ['*'] }).catch(() => null);
75
+ }
76
+ await onUpdated();
77
+ if (leased?.id && leased.status === 'running') {
78
+ await openStream(leased.id, 'screen');
79
+ }
80
+ }
81
+ catch (e) {
82
+ setError(say(e, t('{name}’s desktop computer', { name: displayName }), 'save', t));
83
+ }
84
+ finally {
85
+ setBusy(false);
86
+ }
87
+ };
88
+ const handlePark = async () => {
89
+ if (!client || !box?.id || busy)
90
+ return;
91
+ setBusy(true);
92
+ setError(null);
93
+ try {
94
+ await parkComputer(client, box.id);
95
+ setFrameUrl(null);
96
+ await onUpdated();
97
+ }
98
+ catch (e) {
99
+ setError(say(e, t('{name}’s desktop computer', { name: displayName }), 'save', t));
100
+ }
101
+ finally {
102
+ setBusy(false);
103
+ }
104
+ };
105
+ const captureScreenshot = async () => {
106
+ if (!client || !box?.id || runningTask)
107
+ return;
108
+ setRunningTask(true);
109
+ setError(null);
110
+ try {
111
+ const out = await actComputer(client, { id: box.id, action: 'screenshot' });
112
+ if (out.image) {
113
+ setSnapDataUrl(`data:${out.mimeType || 'image/png'};base64,${out.image}`);
114
+ setLastAnswer(t('Captured live {w}×{h} desktop frame.', { w: out.width || 1280, h: out.height || 800 }));
115
+ }
116
+ }
117
+ catch (e) {
118
+ setError(say(e, t('desktop screenshot'), 'read', t));
119
+ }
120
+ finally {
121
+ setRunningTask(false);
122
+ }
123
+ };
124
+ const submitComputerTask = async (e, preset) => {
125
+ e?.preventDefault();
126
+ const prompt = (preset ?? task).trim();
127
+ if (!client || !prompt || runningTask)
128
+ return;
129
+ setRunningTask(true);
130
+ setError(null);
131
+ setLastAnswer(null);
132
+ if (!preset)
133
+ setTask('');
134
+ try {
135
+ // Ensure the bot has full tool access so `computer_in_sandbox` is active on the run.
136
+ if (!bot.tools?.length) {
137
+ await updateBotMeta(client, bot.name, { tools: ['*'], computeRef: box?.id || bot.computeRef }).catch(() => null);
138
+ }
139
+ const directive = `[Desktop Computer Use] Use your desktop sandbox computer (computer_in_sandbox — screenshot, click, move, drag, type, key, scroll, navigate, shell) to complete this task and report what you did:\n\n${prompt}`;
140
+ const ran = await client.agents.run(bot.name, directive);
141
+ setLastAnswer(ran.output || ran.error || t('Task completed on desktop computer.'));
142
+ await onUpdated();
143
+ }
144
+ catch (err) {
145
+ setError(say(err, t('desktop computer task'), 'save', t));
146
+ }
147
+ finally {
148
+ setRunningTask(false);
149
+ }
150
+ };
151
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsx(DialogContent, { "data-parity-key": "bots.computer.dialog", width: "95vw", maxW: 1060, p: 0, showCloseButton: false, bg: GROUND, borderWidth: 1, borderColor: LINE, rounded: 18, overflow: "hidden", children: _jsxs(YStack, { maxH: "90vh", bg: GROUND, children: [_jsxs(XStack, { px: 18, py: 12, items: "center", justify: "space-between", gap: 12, flexWrap: "wrap", bg: FLOOR, borderBottomWidth: 1, borderColor: LINE, children: [_jsxs(XStack, { items: "center", gap: 10, minW: 0, children: [_jsx(Face, { bot: bot, size: 34, starred: Boolean(bot.isPrimary) }), _jsxs(YStack, { minW: 0, children: [_jsx(DialogTitle, { children: _jsx(Text, { ...CLIP, fontSize: 15, lineHeight: 20, fontWeight: "600", color: INK, children: t('{name}’s Desktop Computer', { name: displayName }) }) }), _jsxs(XStack, { items: "center", gap: 7, children: [_jsx(YStack, { width: 7, height: 7, rounded: 999, bg: awake ? 'var(--state-online)' : waking ? 'var(--chrome-dot-yellow)' : DIM }), _jsx(Text, { fontSize: 12, lineHeight: 16, color: DIM, children: awake
152
+ ? `${t('Awake')} · ${box?.id ?? disk(bot.name)}`
153
+ : waking
154
+ ? t('Starting desktop sandbox…')
155
+ : `${t('Asleep')} · ${disk(bot.name)}` })] })] })] }), _jsxs(XStack, { items: "center", gap: 8, flexWrap: "wrap", children: [_jsx(XStack, { p: 3, rounded: 999, bg: RAISED, borderWidth: 1, borderColor: LINE, gap: 2, children: [
156
+ { id: 'screen', label: t('Desktop GUI'), Icon: Monitor },
157
+ { id: 'terminal', label: t('Terminal'), Icon: Terminal },
158
+ ].map(({ id, label, Icon }) => {
159
+ const active = mode === id;
160
+ return (_jsxs(XStack, { render: "button", type: 'button', onClick: () => {
161
+ setSnapDataUrl(null);
162
+ setMode(id);
163
+ }, height: 28, px: 12, gap: 6, rounded: 999, items: "center", bg: active ? PICKED : 'transparent', borderWidth: 0, cursor: "pointer", children: [_jsx(Icon, { size: 13, color: active ? INK : DIM, "aria-hidden": true }), _jsx(Text, { fontSize: 12, lineHeight: 16, fontWeight: active ? '500' : '400', color: active ? INK : DIM, children: label })] }, id));
164
+ }) }), awake && box?.id ? (_jsxs(_Fragment, { children: [_jsx(XStack, { ...ROUND, width: 32, height: 32, "aria-label": t('Capture screenshot'), onClick: () => void captureScreenshot(), children: _jsx(Camera, { size: 14, color: INK, "aria-hidden": true }) }), _jsx(XStack, { ...ROUND, width: 32, height: 32, "aria-label": t('Refresh desktop stream'), onClick: () => {
165
+ setSnapDataUrl(null);
166
+ void openStream(box.id, mode);
167
+ }, children: _jsx(RefreshCw, { size: 14, color: INK, "aria-hidden": true }) }), frameUrl ? (_jsx(XStack, { ...ROUND, width: 32, height: 32, "aria-label": t('Open in new tab'), onClick: () => window.open(frameUrl, '_blank', 'noopener,noreferrer'), children: _jsx(ExternalLink, { size: 14, color: INK, "aria-hidden": true }) })) : null, _jsxs(XStack, { ...PILL, height: 32, px: 12, disabled: busy, onClick: () => void handlePark(), children: [_jsx(Pause, { size: 12, color: INK, "aria-hidden": true }), _jsx(Text, { fontSize: 12, lineHeight: 16, fontWeight: "500", color: INK, children: t('Park') })] })] })) : (_jsxs(XStack, { ...PILL, height: 32, px: 13, bg: INK, borderColor: INK, disabled: busy || waking, opacity: busy || waking ? 0.5 : 1, onClick: () => void startComputer(), children: [_jsx(Play, { size: 12, color: "var(--background)", "aria-hidden": true }), _jsx(Text, { fontSize: 12, lineHeight: 16, fontWeight: "500", color: "var(--background)", children: busy || waking ? t('Waking…') : t('Wake Desktop') })] })), _jsx(XStack, { ...ROUND, width: 32, height: 32, "aria-label": t('Close'), onClick: () => onOpenChange(false), children: _jsx(X, { size: 15, color: INK, "aria-hidden": true }) })] })] }), _jsx(YStack, { height: 470, bg: "var(--pure-black)", items: "center", justify: "center", position: "relative", overflow: "hidden", children: snapDataUrl ? (_jsxs(YStack, { width: "100%", height: "100%", items: "center", justify: "center", position: "relative", children: [_jsx(YStack, { render: "img", src: snapDataUrl, alt: `${displayName} desktop screenshot`, maxW: "100%", maxH: "100%", objectFit: "contain" }), _jsx(XStack, { position: "absolute", t: 12, r: 12, children: _jsx(XStack, { ...PILL, height: 30, px: 12, onClick: () => setSnapDataUrl(null), children: _jsx(Text, { fontSize: 12, lineHeight: 16, color: INK, children: t('Back to live stream') }) }) })] })) : awake && frameUrl ? (_jsx(YStack, { render: "iframe", src: frameUrl,
168
+ title: `${displayName} desktop ${mode}`,
169
+ allow: 'clipboard-read; clipboard-write; fullscreen', width: "100%", height: "100%", borderWidth: 0 })) : (_jsxs(YStack, { maxW: 460, px: 24, items: "center", gap: 14, children: [_jsx(YStack, { width: 56, height: 56, rounded: 16, bg: RAISED, borderWidth: 1, borderColor: LINE, items: "center", justify: "center", children: _jsx(Monitor, { size: 24, color: INK, "aria-hidden": true }) }), _jsx(Text, { fontSize: 17, lineHeight: 23, fontWeight: "600", color: INK, text: "center", children: waking ? t('Booting X11 Desktop Sandbox…') : t('Dedicated Desktop Sandbox Computer') }), _jsx(Text, { fontSize: 13, lineHeight: 19, color: DIM, text: "center", children: t('Every bot gets its own isolated Linux GUI desktop with Chromium, persistent workspace disk ({disk}), and full Computer Use — mouse clicks, drags, keyboard typing, live screenshots, and shell execution.', { disk: disk(bot.name) }) }), _jsxs(XStack, { ...PILL, bg: INK, borderColor: INK, disabled: busy || waking, opacity: busy || waking ? 0.5 : 1, onClick: () => void startComputer(), children: [_jsx(Play, { size: 14, color: "var(--background)", "aria-hidden": true }), _jsx(Text, { ...WORD, color: "var(--background)", children: busy || waking ? t('Starting computer…') : t('Start Desktop Computer') })] })] })) }), _jsxs(YStack, { px: 18, py: 12, gap: 10, bg: FLOOR, borderTopWidth: 1, borderColor: LINE, children: [error ? (_jsx(Text, { role: "alert", fontSize: 12, lineHeight: 17, color: DIM, children: error })) : null, lastAnswer ? (_jsx(YStack, { px: 12, py: 9, rounded: 10, bg: RAISED, borderWidth: 1, borderColor: LINE, maxH: 96, overflowY: "auto", children: _jsx(Text, { fontSize: 12, lineHeight: 17, color: INK, children: lastAnswer }) })) : null, _jsxs(XStack, { render: "form", onSubmit: (e) => void submitComputerTask(e), gap: 8, items: "center", children: [_jsx(Input, { unstyled: true, value: task, onChange: (e) => setTask(e.target.value), placeholder: t('Ask {name} to use its computer (open a URL, click UI, inspect logs, run tests…)', {
170
+ name: displayName,
171
+ }), "aria-label": t('Computer Use directive'), flex: 1, height: 38, px: 14, rounded: 999, bg: RAISED, borderWidth: 1, borderColor: LINE, color: INK, fontSize: 13, placeholderTextColor: "$placeholderColor" }), _jsxs(XStack, { ...PILL, type: 'submit', height: 38, px: 15, bg: INK, borderColor: INK, disabled: !task.trim() || runningTask, opacity: !task.trim() || runningTask ? 0.45 : 1, children: [_jsx(Send, { size: 13, color: "var(--background)", "aria-hidden": true }), _jsx(Text, { ...WORD, fontSize: 13, color: "var(--background)", children: runningTask ? t('Working…') : t('Computer Use') })] })] }), _jsxs(XStack, { items: "center", gap: 6, flexWrap: "wrap", children: [_jsx(Text, { fontSize: 11, lineHeight: 15, color: DIM, children: t('Quick actions:') }), [
172
+ { label: t('Open hanzo.ai in browser'), prompt: 'Navigate to https://hanzo.ai on the desktop browser, take a screenshot, and summarize what is visible.' },
173
+ { label: t('Inspect workspace & tools'), prompt: 'Run uname -a, check installed browsers and developer tools in your sandbox, and take a desktop screenshot.' },
174
+ ].map((q) => (_jsx(XStack, { render: "button", type: 'button', disabled: runningTask, onClick: () => void submitComputerTask(undefined, q.prompt), height: 25, px: 10, rounded: 999, items: "center", bg: RAISED, borderWidth: 1, borderColor: LINE, cursor: "pointer", hoverStyle: { bg: PICKED }, children: _jsx(Text, { fontSize: 11, lineHeight: 15, color: DIM, children: q.label }) }, q.label)))] })] })] }) }) }));
175
+ }
@@ -2,6 +2,8 @@ export type ConnectorFilter = 'all' | 'personal' | 'channels' | 'business' | 'pr
2
2
  type SectionId = 'popular' | 'channels' | 'business' | 'productivity';
3
3
  interface ConnectorDef {
4
4
  id: string;
5
+ /** Backend provider id when multiple surfaces share one OAuth provider (e.g. gmail -> google). */
6
+ providerId?: string;
5
7
  name: string;
6
8
  description: string;
7
9
  section: SectionId;