@hanzo/app 0.3.92 → 0.3.93
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/ComputerDialog.js +29 -9
- package/dist/bots/api.d.ts +10 -0
- package/dist/bots/api.js +104 -14
- package/package.json +1 -1
|
@@ -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, opened, parkComputer, updateBotMeta, } from './api.js';
|
|
18
|
+
import { actComputer, bootOrResumeComputer, disk, findBotComputer, grant, opened, parkComputer, runDesktopAgent, 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,
|
|
@@ -61,8 +61,14 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
|
|
|
61
61
|
const [vaultOpen, setVaultOpen] = useState(false);
|
|
62
62
|
const [vaultItems, setVaultItems] = useState([]);
|
|
63
63
|
useEffect(() => {
|
|
64
|
-
if (box)
|
|
65
|
-
|
|
64
|
+
if (!box)
|
|
65
|
+
return;
|
|
66
|
+
setLocalBox((prev) => {
|
|
67
|
+
if (prev?.status === 'running' && box.status !== 'running') {
|
|
68
|
+
return prev;
|
|
69
|
+
}
|
|
70
|
+
return box;
|
|
71
|
+
});
|
|
66
72
|
}, [box]);
|
|
67
73
|
const activeBox = localBox ?? box;
|
|
68
74
|
const awake = activeBox?.status === 'running';
|
|
@@ -326,13 +332,27 @@ export function ComputerDialog({ open, onOpenChange, bot, box, onUpdated, }) {
|
|
|
326
332
|
if (control === 'controlling')
|
|
327
333
|
toggleControl('watching');
|
|
328
334
|
try {
|
|
329
|
-
if (
|
|
330
|
-
await
|
|
335
|
+
if (activeBox?.id) {
|
|
336
|
+
const ran = await runDesktopAgent(activeBox.id, prompt, (step) => {
|
|
337
|
+
setStatusToast(step);
|
|
338
|
+
});
|
|
339
|
+
if (ran.savedCredential) {
|
|
340
|
+
await refreshVault();
|
|
341
|
+
}
|
|
342
|
+
setStatusToast(ran.output || t('Task completed on desktop computer.'));
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
if (!bot.tools?.length) {
|
|
346
|
+
await updateBotMeta(client, bot.name, { tools: ['*'], computeRef: bot.computeRef }).catch(() => null);
|
|
347
|
+
}
|
|
348
|
+
const ran = await client.http.json({
|
|
349
|
+
method: 'POST',
|
|
350
|
+
path: `/v1/agent/${encodeURIComponent(bot.name)}/run`,
|
|
351
|
+
body: { input: prompt },
|
|
352
|
+
});
|
|
353
|
+
setStatusToast(ran.output || ran.error || t('Task completed on desktop computer.'));
|
|
354
|
+
await onUpdated();
|
|
331
355
|
}
|
|
332
|
-
const directive = `[Desktop Computer Use] Use your resumable desktop sandbox computer (computer_in_sandbox — screenshot, click, move, drag, type, key, scroll, navigate, autofill for KMS/1Password/LastPass logins, and shell) to complete this task while I watch live:\n\n${prompt}`;
|
|
333
|
-
const ran = await client.agents.run(bot.name, directive);
|
|
334
|
-
setStatusToast(ran.output || ran.error || t('Task completed on desktop computer.'));
|
|
335
|
-
await onUpdated();
|
|
336
356
|
}
|
|
337
357
|
catch (err) {
|
|
338
358
|
setError(say(err, t('desktop computer task'), 'save', t));
|
package/dist/bots/api.d.ts
CHANGED
|
@@ -190,6 +190,7 @@ export declare function opened(url: string, viewOnly?: boolean): string;
|
|
|
190
190
|
/**
|
|
191
191
|
* Finds the bot's existing desktop sandbox across both named project disks (`bot-<name>`)
|
|
192
192
|
* and Free-tier persistent `disk: true` sandboxes bound via `bot.computeRef`.
|
|
193
|
+
* Always prefers an actively `running` desktop sandbox over a stopped/expired lease.
|
|
193
194
|
*/
|
|
194
195
|
export declare function findBotComputer(c: Client, bot: BotAgent, signal?: AbortSignal): Promise<Sandbox | null>;
|
|
195
196
|
/**
|
|
@@ -236,6 +237,15 @@ export interface ComputerActionOut {
|
|
|
236
237
|
height?: number;
|
|
237
238
|
}
|
|
238
239
|
export declare const actComputer: (c: Client, body: ComputerActionIn) => Promise<ComputerActionOut>;
|
|
240
|
+
/**
|
|
241
|
+
* Streams a live desktop computer-use turn (`POST /v1/sandbox/:id/agent`),
|
|
242
|
+
* executing screenshot, click, type, key, shell, save_credential, and KMS/TOTP
|
|
243
|
+
* autofill directly on the open sandbox while reporting step progress via `onStep`.
|
|
244
|
+
*/
|
|
245
|
+
export declare function runDesktopAgent(id: string, message: string, onStep?: (stepText: string) => void, signal?: AbortSignal): Promise<{
|
|
246
|
+
output: string;
|
|
247
|
+
savedCredential: boolean;
|
|
248
|
+
}>;
|
|
239
249
|
export interface AutomationSchedule {
|
|
240
250
|
kind: 'manual' | 'hourly' | 'daily' | 'weekdays' | 'weekly' | 'cron' | 'once';
|
|
241
251
|
at?: string;
|
package/dist/bots/api.js
CHANGED
|
@@ -70,14 +70,14 @@ export async function bootstrapPrimary(c, name = PRIMARY_BOT, model = 'enso') {
|
|
|
70
70
|
}
|
|
71
71
|
/** Atomically promotes `ref` to be the org's sole Primary Bot (Layer 0). */
|
|
72
72
|
export const setPrimaryBot = (c, ref) => c.http.json({
|
|
73
|
-
method: '
|
|
74
|
-
path: `/v1/
|
|
73
|
+
method: 'PATCH',
|
|
74
|
+
path: `/v1/agent/${encodeURIComponent(ref)}`,
|
|
75
75
|
body: { isPrimary: true, layer: 0 },
|
|
76
76
|
});
|
|
77
77
|
/** Updates hierarchy metadata (`groupId`, `layer`, `computeRef`, `tools`) on an existing bot. */
|
|
78
78
|
export const updateBotMeta = (c, ref, patch) => c.http.json({
|
|
79
|
-
method: '
|
|
80
|
-
path: `/v1/
|
|
79
|
+
method: 'PATCH',
|
|
80
|
+
path: `/v1/agent/${encodeURIComponent(ref)}`,
|
|
81
81
|
body: patch,
|
|
82
82
|
});
|
|
83
83
|
/** Lists all Bot Groups in the caller's org, ordered by layer. */
|
|
@@ -96,7 +96,7 @@ export const createGroup = (c, body) => c.http.json({
|
|
|
96
96
|
body,
|
|
97
97
|
});
|
|
98
98
|
export const updateGroup = (c, ref, body) => c.http.json({
|
|
99
|
-
method: '
|
|
99
|
+
method: 'PATCH',
|
|
100
100
|
path: `/v1/agent/groups/${encodeURIComponent(groupNameOf(ref))}`,
|
|
101
101
|
body,
|
|
102
102
|
});
|
|
@@ -204,30 +204,42 @@ function bestSandbox(boxes) {
|
|
|
204
204
|
/**
|
|
205
205
|
* Finds the bot's existing desktop sandbox across both named project disks (`bot-<name>`)
|
|
206
206
|
* and Free-tier persistent `disk: true` sandboxes bound via `bot.computeRef`.
|
|
207
|
+
* Always prefers an actively `running` desktop sandbox over a stopped/expired lease.
|
|
207
208
|
*/
|
|
208
209
|
export async function findBotComputer(c, bot, signal) {
|
|
209
210
|
const opts = signal ? { signal } : undefined;
|
|
211
|
+
let projectFallback = null;
|
|
210
212
|
try {
|
|
211
213
|
const byProject = await c.sandboxes.list({ project: disk(bot.name) }, opts);
|
|
212
214
|
const found = bestSandbox(byProject);
|
|
213
|
-
if (found)
|
|
215
|
+
if (found?.status === 'running')
|
|
214
216
|
return found;
|
|
217
|
+
projectFallback = found;
|
|
215
218
|
}
|
|
216
219
|
catch {
|
|
217
|
-
// continue to
|
|
220
|
+
// continue to org sandbox lookup
|
|
218
221
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
+
try {
|
|
223
|
+
const all = await c.sandboxes.list(undefined, opts);
|
|
224
|
+
if (bot.computeRef) {
|
|
222
225
|
const exact = all.find((b) => b.id === bot.computeRef);
|
|
223
|
-
if (exact)
|
|
226
|
+
if (exact?.status === 'running')
|
|
224
227
|
return exact;
|
|
228
|
+
if (exact && !projectFallback)
|
|
229
|
+
projectFallback = exact;
|
|
225
230
|
}
|
|
226
|
-
|
|
227
|
-
|
|
231
|
+
// If the Primary Bot has an active desktop sandbox running under the Free-tier
|
|
232
|
+
// fallback (where project name was omitted), prefer that live running desktop!
|
|
233
|
+
if (bot.isPrimary || bot.name === PRIMARY_BOT) {
|
|
234
|
+
const runningDesktop = all.find((b) => b.class === 'desktop' && b.status === 'running');
|
|
235
|
+
if (runningDesktop)
|
|
236
|
+
return runningDesktop;
|
|
228
237
|
}
|
|
229
238
|
}
|
|
230
|
-
|
|
239
|
+
catch {
|
|
240
|
+
// ignore
|
|
241
|
+
}
|
|
242
|
+
return projectFallback;
|
|
231
243
|
}
|
|
232
244
|
function statusOfError(err) {
|
|
233
245
|
if (!err || typeof err !== 'object')
|
|
@@ -311,6 +323,84 @@ export const actComputer = (c, body) => c.http.json({
|
|
|
311
323
|
path: '/v1/sandbox/computer',
|
|
312
324
|
body,
|
|
313
325
|
});
|
|
326
|
+
/**
|
|
327
|
+
* Streams a live desktop computer-use turn (`POST /v1/sandbox/:id/agent`),
|
|
328
|
+
* executing screenshot, click, type, key, shell, save_credential, and KMS/TOTP
|
|
329
|
+
* autofill directly on the open sandbox while reporting step progress via `onStep`.
|
|
330
|
+
*/
|
|
331
|
+
export async function runDesktopAgent(id, message, onStep, signal) {
|
|
332
|
+
const res = await fetch(`${api()}/v1/sandbox/${encodeURIComponent(id)}/agent`, {
|
|
333
|
+
method: 'POST',
|
|
334
|
+
headers: {
|
|
335
|
+
...scope(),
|
|
336
|
+
'Content-Type': 'application/json',
|
|
337
|
+
Accept: 'text/event-stream',
|
|
338
|
+
},
|
|
339
|
+
body: JSON.stringify({ message }),
|
|
340
|
+
signal,
|
|
341
|
+
});
|
|
342
|
+
if (!res.ok) {
|
|
343
|
+
const raw = await res.text().catch(() => '');
|
|
344
|
+
throw new Error(raw || `Desktop agent HTTP ${res.status}`);
|
|
345
|
+
}
|
|
346
|
+
const reader = res.body?.getReader();
|
|
347
|
+
if (!reader) {
|
|
348
|
+
return { output: '', savedCredential: false };
|
|
349
|
+
}
|
|
350
|
+
const dec = new TextDecoder();
|
|
351
|
+
let buf = '';
|
|
352
|
+
const sayings = [];
|
|
353
|
+
let lastResult = '';
|
|
354
|
+
let savedCredential = false;
|
|
355
|
+
while (true) {
|
|
356
|
+
const { value, done } = await reader.read();
|
|
357
|
+
if (done)
|
|
358
|
+
break;
|
|
359
|
+
buf += dec.decode(value, { stream: true });
|
|
360
|
+
let nl = buf.indexOf('\n');
|
|
361
|
+
while (nl >= 0) {
|
|
362
|
+
const line = buf.slice(0, nl).trim();
|
|
363
|
+
buf = buf.slice(nl + 1);
|
|
364
|
+
nl = buf.indexOf('\n');
|
|
365
|
+
if (!line.startsWith('data:'))
|
|
366
|
+
continue;
|
|
367
|
+
const payload = line.slice(5).trim();
|
|
368
|
+
if (!payload)
|
|
369
|
+
continue;
|
|
370
|
+
try {
|
|
371
|
+
const frame = JSON.parse(payload);
|
|
372
|
+
if (frame.type === 'act' && frame.tool) {
|
|
373
|
+
onStep?.(`Running ${frame.tool}…`);
|
|
374
|
+
if (frame.tool === 'save_credential')
|
|
375
|
+
savedCredential = true;
|
|
376
|
+
}
|
|
377
|
+
else if (frame.type === 'result' && frame.text) {
|
|
378
|
+
lastResult = frame.text;
|
|
379
|
+
onStep?.(frame.text);
|
|
380
|
+
if (frame.tool === 'save_credential' && frame.ok !== false) {
|
|
381
|
+
savedCredential = true;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else if (frame.type === 'say' && frame.text) {
|
|
385
|
+
sayings.push(frame.text);
|
|
386
|
+
onStep?.(frame.text);
|
|
387
|
+
}
|
|
388
|
+
else if (frame.type === 'error' && frame.text) {
|
|
389
|
+
throw new Error(frame.text);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
catch (err) {
|
|
393
|
+
if (err instanceof Error && !err.message.includes('JSON')) {
|
|
394
|
+
throw err;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
output: sayings.join(' ').trim() || lastResult,
|
|
401
|
+
savedCredential,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
314
404
|
export async function listBotAutomations(c, botName, signal) {
|
|
315
405
|
try {
|
|
316
406
|
const res = await c.http.json({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.93",
|
|
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",
|