@hanzo/app 0.3.66 → 0.3.68
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/Bots.d.ts +9 -2
- package/dist/bots/Bots.js +254 -467
- package/dist/bots/Make.d.ts +5 -0
- package/dist/bots/Make.js +60 -0
- package/dist/bots/Panel.d.ts +11 -0
- package/dist/bots/Panel.js +149 -0
- package/dist/bots/Roster.d.ts +11 -0
- package/dist/bots/Roster.js +50 -0
- package/dist/bots/Thread.d.ts +20 -0
- package/dist/bots/Thread.js +148 -0
- package/dist/bots/api.d.ts +27 -102
- package/dist/bots/api.js +26 -65
- package/dist/bots/carry.d.ts +18 -0
- package/dist/bots/carry.js +22 -0
- package/dist/bots/face.js +4 -4
- package/dist/bots/grid.d.ts +10 -0
- package/dist/bots/grid.js +20 -0
- package/dist/bots/ink.d.ts +12 -3
- package/dist/bots/ink.js +21 -22
- package/dist/bots/kit.d.ts +51 -87
- package/dist/bots/kit.js +21 -39
- package/dist/bots/refusal.d.ts +28 -0
- package/dist/bots/refusal.js +62 -0
- package/dist/bots/said.d.ts +34 -0
- package/dist/bots/said.js +43 -0
- package/dist/bots/time.d.ts +16 -0
- package/dist/bots/time.js +86 -0
- package/package.json +1 -1
- package/dist/bots/runtime.d.ts +0 -4
- package/dist/bots/runtime.js +0 -388
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The thread as lines: what each recorded run said, stamped where the
|
|
2
|
+
// conversation paused. Pure, so the order a reader sees is tested as data.
|
|
3
|
+
import { BREAK, instant, stamp } from './time.js';
|
|
4
|
+
/** The bot a run's actor names, when another bot asked for it. */
|
|
5
|
+
function asker(run, bots, self) {
|
|
6
|
+
const who = run.actor?.split('/').pop();
|
|
7
|
+
if (!who)
|
|
8
|
+
return undefined;
|
|
9
|
+
return bots.find((b) => b.name !== self && (b.name === who || b.id === who || b.serviceAccountId === who));
|
|
10
|
+
}
|
|
11
|
+
/** The thread as lines: stamps where it paused, each run as the messages it holds. */
|
|
12
|
+
export function lines(runs, bots, self, pending, now, locale, t) {
|
|
13
|
+
const out = [];
|
|
14
|
+
let prev = null;
|
|
15
|
+
const mark = (at, key) => {
|
|
16
|
+
if (prev === null || at - prev > BREAK)
|
|
17
|
+
out.push({ kind: 'stamp', key: `s-${key}`, text: stamp(at, now, locale, t) });
|
|
18
|
+
prev = at;
|
|
19
|
+
};
|
|
20
|
+
for (const r of runs) {
|
|
21
|
+
const at = instant(r.createdAt) ?? now;
|
|
22
|
+
mark(at, r.id);
|
|
23
|
+
// A run another bot asked for opens with that bot's words, marked as its
|
|
24
|
+
// message; any other run's input is yours.
|
|
25
|
+
const from = asker(r, bots, self);
|
|
26
|
+
if (from) {
|
|
27
|
+
out.push({ kind: 'from', key: `f-${r.id}`, bot: from });
|
|
28
|
+
if (r.input)
|
|
29
|
+
out.push({ kind: 'other', key: `i-${r.id}`, text: r.input });
|
|
30
|
+
}
|
|
31
|
+
else if (r.input)
|
|
32
|
+
out.push({ kind: 'mine', key: `i-${r.id}`, text: r.input });
|
|
33
|
+
const said = r.output || r.error;
|
|
34
|
+
if (said)
|
|
35
|
+
out.push({ kind: 'theirs', key: `o-${r.id}`, text: said, failed: !r.output && Boolean(r.error) });
|
|
36
|
+
}
|
|
37
|
+
if (pending) {
|
|
38
|
+
mark(pending.at, 'pending');
|
|
39
|
+
out.push({ kind: 'mine', key: 'pending', text: pending.input });
|
|
40
|
+
out.push({ kind: 'thinking', key: 'thinking' });
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Say } from '@hanzo/i18n';
|
|
2
|
+
/**
|
|
3
|
+
* The stamp a thread centres above a message: "Today 11:23 AM", "Yesterday
|
|
4
|
+
* 12:11 AM", "Mon, Nov 9 4:47 PM", and the year once it is not this one.
|
|
5
|
+
*/
|
|
6
|
+
export declare function stamp(at: number, now: number, locale: string, t?: Say): string;
|
|
7
|
+
/** A message more than this long after the one before it gets its own stamp. */
|
|
8
|
+
export declare const BREAK: number;
|
|
9
|
+
/** An instant from the platform's RFC 3339 string, or null. */
|
|
10
|
+
export declare const instant: (iso: string | undefined) => number | null;
|
|
11
|
+
/**
|
|
12
|
+
* A 5-field cron as a person reads it. The common shapes are said in words —
|
|
13
|
+
* every n minutes, every n hours, daily or on weekdays at a time — and any other
|
|
14
|
+
* shape is shown as the expression itself rather than guessed at.
|
|
15
|
+
*/
|
|
16
|
+
export declare function cron(expr: string, locale: string, t?: Say): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// When things happened, in the words the thread and the panel have room for.
|
|
2
|
+
import { english } from '@hanzo/i18n';
|
|
3
|
+
const DAY = 86_400_000;
|
|
4
|
+
/** Midnight of the day `at` falls on, in the reader's zone. */
|
|
5
|
+
const midnight = (at) => {
|
|
6
|
+
const d = new Date(at);
|
|
7
|
+
d.setHours(0, 0, 0, 0);
|
|
8
|
+
return d.getTime();
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The stamp a thread centres above a message: "Today 11:23 AM", "Yesterday
|
|
12
|
+
* 12:11 AM", "Mon, Nov 9 4:47 PM", and the year once it is not this one.
|
|
13
|
+
*/
|
|
14
|
+
export function stamp(at, now, locale, t = english) {
|
|
15
|
+
const time = new Date(at).toLocaleTimeString(locale, { hour: 'numeric', minute: '2-digit' });
|
|
16
|
+
const days = Math.round((midnight(now) - midnight(at)) / DAY);
|
|
17
|
+
if (days === 0)
|
|
18
|
+
return t('Today {time}', { time });
|
|
19
|
+
if (days === 1)
|
|
20
|
+
return t('Yesterday {time}', { time });
|
|
21
|
+
const sameYear = new Date(at).getFullYear() === new Date(now).getFullYear();
|
|
22
|
+
const date = new Date(at).toLocaleDateString(locale, {
|
|
23
|
+
weekday: 'short',
|
|
24
|
+
month: 'short',
|
|
25
|
+
day: 'numeric',
|
|
26
|
+
...(sameYear ? {} : { year: 'numeric' }),
|
|
27
|
+
});
|
|
28
|
+
return `${date} ${time}`;
|
|
29
|
+
}
|
|
30
|
+
/** A message more than this long after the one before it gets its own stamp. */
|
|
31
|
+
export const BREAK = 30 * 60_000;
|
|
32
|
+
/** An instant from the platform's RFC 3339 string, or null. */
|
|
33
|
+
export const instant = (iso) => {
|
|
34
|
+
if (!iso)
|
|
35
|
+
return null;
|
|
36
|
+
const n = Date.parse(iso);
|
|
37
|
+
return Number.isNaN(n) ? null : n;
|
|
38
|
+
};
|
|
39
|
+
const WEEKDAYS = '1-5';
|
|
40
|
+
/** "9:00 AM" for an hour and minute, in the reader's locale. */
|
|
41
|
+
const clock = (hour, minute, locale) => new Date(2000, 0, 1, hour, minute).toLocaleTimeString(locale, { hour: 'numeric', minute: '2-digit' });
|
|
42
|
+
/** A whole number from a cron field, or null where the field is anything else. */
|
|
43
|
+
const whole = (field) => (/^\d+$/.test(field) ? Number(field) : null);
|
|
44
|
+
/** The step of a `*\/n` field, or null. */
|
|
45
|
+
const step = (field) => {
|
|
46
|
+
const m = /^\*\/(\d+)$/.exec(field);
|
|
47
|
+
return m ? Number(m[1]) : null;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A 5-field cron as a person reads it. The common shapes are said in words —
|
|
51
|
+
* every n minutes, every n hours, daily or on weekdays at a time — and any other
|
|
52
|
+
* shape is shown as the expression itself rather than guessed at.
|
|
53
|
+
*/
|
|
54
|
+
export function cron(expr, locale, t = english) {
|
|
55
|
+
const parts = expr.trim().split(/\s+/);
|
|
56
|
+
if (parts.length !== 5)
|
|
57
|
+
return expr;
|
|
58
|
+
const [minute, hour, dom, month, dow] = parts;
|
|
59
|
+
if (dom !== '*' || month !== '*')
|
|
60
|
+
return expr;
|
|
61
|
+
const weekdays = dow === WEEKDAYS;
|
|
62
|
+
if (dow !== '*' && !weekdays)
|
|
63
|
+
return expr;
|
|
64
|
+
const everyMinutes = step(minute);
|
|
65
|
+
if (everyMinutes !== null && hour === '*') {
|
|
66
|
+
return weekdays
|
|
67
|
+
? t('Every {n} minutes on weekdays', { n: everyMinutes })
|
|
68
|
+
: t('Every {n} minutes', { n: everyMinutes });
|
|
69
|
+
}
|
|
70
|
+
const m = whole(minute);
|
|
71
|
+
if (m === null)
|
|
72
|
+
return expr;
|
|
73
|
+
if (hour === '*')
|
|
74
|
+
return weekdays ? t('Every hour on weekdays') : t('Every hour');
|
|
75
|
+
const everyHours = step(hour);
|
|
76
|
+
if (everyHours !== null) {
|
|
77
|
+
return weekdays
|
|
78
|
+
? t('Every {n} hours on weekdays', { n: everyHours })
|
|
79
|
+
: t('Every {n} hours', { n: everyHours });
|
|
80
|
+
}
|
|
81
|
+
const h = whole(hour);
|
|
82
|
+
if (h === null || h > 23 || m > 59)
|
|
83
|
+
return expr;
|
|
84
|
+
const at = clock(h, m, locale);
|
|
85
|
+
return weekdays ? t('Weekdays at {time}', { time: at }) : t('Every day at {time}', { time: at });
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.68",
|
|
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",
|
package/dist/bots/runtime.d.ts
DELETED
package/dist/bots/runtime.js
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
// WHAT ONE BOT HAS.
|
|
4
|
-
//
|
|
5
|
-
// A Bot is a worker, and a worker owns things. The platform holds each one
|
|
6
|
-
// somewhere, and this pane is one section per thing:
|
|
7
|
-
//
|
|
8
|
-
// its MACHINE `computeRef`, an id from /v1/agents/targets
|
|
9
|
-
// its COMPUTER a sandbox leased on the project `bot-<name>`, which is this
|
|
10
|
-
// Bot's disk: a volume is named per (org, project) and the name
|
|
11
|
-
// is deterministic, so the same disk comes back after a lease ends
|
|
12
|
-
// its TOOLS `tools[]` — the names this Bot may call, out of the platform's
|
|
13
|
-
// own MCP surface plus whatever the org has registered
|
|
14
|
-
// its TRANSPORTS the networks it answers on, from /v1/transport/agent
|
|
15
|
-
// its CODE an autonomous run against one of the org's repos
|
|
16
|
-
// its SECRETS the KMS names under `bots/<name>`
|
|
17
|
-
//
|
|
18
|
-
// ONE THING A READER WILL LOOK FOR IS NOT THE BOT'S: a connector is held by the
|
|
19
|
-
// PERSON who signed in to it, and the contract publishes no route binding one to
|
|
20
|
-
// an agent. It is listed as what it is, with no switch to press.
|
|
21
|
-
//
|
|
22
|
-
// The screen and the terminal are real or they are absent. Each is a URL the
|
|
23
|
-
// platform mints against a sandbox that exists; where there is no sandbox there
|
|
24
|
-
// is no window, and where the mint is refused the refusal is what is drawn.
|
|
25
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
26
|
-
import { Play, Square, X } from 'lucide-react';
|
|
27
|
-
import { useOrganizations } from '@hanzo/iam/react';
|
|
28
|
-
import { useAi } from '../lib/ai.js';
|
|
29
|
-
import { useI18n } from '@hanzo/i18n/react';
|
|
30
|
-
import { say } from '../failure.js';
|
|
31
|
-
import { Input, Text, XStack, YStack } from '@hanzo/gui';
|
|
32
|
-
import { Picker } from '@hanzo/ui';
|
|
33
|
-
import { DIM, FAINT, GROUND, INK, LINE } from './ink.js';
|
|
34
|
-
import { BOXED, LABEL, OUT, PICK, TAB } from './kit.js';
|
|
35
|
-
import { ALWAYS, ONCE, answer, answering, call, connectors as readConnectors, disk, grant, projects as readProjects, secrets as readSecrets, tools as readTools, vault, workOn, } from './api.js';
|
|
36
|
-
/** The platform's word for how a bot runs, as a person reads it. An unknown mode stays a token. */
|
|
37
|
-
function modeName(mode, t) {
|
|
38
|
-
if (mode === ALWAYS)
|
|
39
|
-
return t('long-running');
|
|
40
|
-
if (!mode || mode === ONCE)
|
|
41
|
-
return t('one-shot');
|
|
42
|
-
return mode;
|
|
43
|
-
}
|
|
44
|
-
/** A computer's status, in the reader's words. An unrecognized status stays a token. */
|
|
45
|
-
function boxStatus(status, t) {
|
|
46
|
-
switch (status) {
|
|
47
|
-
case 'running':
|
|
48
|
-
return t('running');
|
|
49
|
-
case 'pending':
|
|
50
|
-
return t('pending');
|
|
51
|
-
case 'error':
|
|
52
|
-
return t('error');
|
|
53
|
-
case 'unknown':
|
|
54
|
-
return t('unknown');
|
|
55
|
-
default:
|
|
56
|
-
return status;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/** Where a tool was published, and whether the org has turned it on. */
|
|
60
|
-
function toolFrom(from, ready, t) {
|
|
61
|
-
if (from === 'MCP')
|
|
62
|
-
return t(ready ? 'MCP' : 'MCP · not activated');
|
|
63
|
-
if (from === 'skill')
|
|
64
|
-
return t(ready ? 'skill' : 'skill · not activated');
|
|
65
|
-
return t(ready ? 'platform' : 'platform · not activated');
|
|
66
|
-
}
|
|
67
|
-
export function Runtime({ bot }) {
|
|
68
|
-
const { t, locale } = useI18n();
|
|
69
|
-
const { client } = useAi();
|
|
70
|
-
const { currentOrg } = useOrganizations();
|
|
71
|
-
const org = currentOrg?.displayName || currentOrg?.name || '';
|
|
72
|
-
const project = disk(bot.name);
|
|
73
|
-
const [machines, setMachines] = useState([]);
|
|
74
|
-
const [boxes, setBoxes] = useState([]);
|
|
75
|
-
const [servers, setServers] = useState([]);
|
|
76
|
-
const [skills, setSkills] = useState([]);
|
|
77
|
-
const [activated, setActivated] = useState([]);
|
|
78
|
-
const [published, setPublished] = useState([]);
|
|
79
|
-
const [links, setLinks] = useState([]);
|
|
80
|
-
const [transports, setTransports] = useState([]);
|
|
81
|
-
const [keys, setKeys] = useState([]);
|
|
82
|
-
const [repos, setRepos] = useState([]);
|
|
83
|
-
const [why, setWhy] = useState({});
|
|
84
|
-
const blame = useCallback((k, e, subject) => {
|
|
85
|
-
setWhy((w) => ({ ...w, [k]: say(e, subject, 'read', t) }));
|
|
86
|
-
}, [t]);
|
|
87
|
-
const survey = useCallback(async () => {
|
|
88
|
-
if (!client)
|
|
89
|
-
return;
|
|
90
|
-
await Promise.all([
|
|
91
|
-
client.machines.list().then(setMachines).catch((e) => blame('machine', e, t('this org’s machines'))),
|
|
92
|
-
client.sandboxes.list({ project }).then(setBoxes).catch((e) => blame('box', e, t('this bot’s computer'))),
|
|
93
|
-
client.tools.mcp().then(setServers).catch((e) => blame('mcp', e, t('this org’s MCP servers'))),
|
|
94
|
-
client.tools.skills().then((s) => setSkills(s.tools ?? [])).catch((e) => blame('skill', e, t('this org’s skills'))),
|
|
95
|
-
client.tools.activation().then((a) => setActivated(a.enabled ?? [])).catch(() => setActivated([])),
|
|
96
|
-
readTools(client).then(setPublished).catch((e) => blame('served', e, t('the platform’s tools'))),
|
|
97
|
-
readConnectors(client).then(setLinks).catch((e) => blame('link', e, t('your connectors'))),
|
|
98
|
-
client.transports.list().then(setTransports).catch((e) => blame('transport', e, t('this org’s transports'))),
|
|
99
|
-
readSecrets(client, vault(bot.name)).then(setKeys).catch((e) => blame('key', e, t('this bot’s secrets'))),
|
|
100
|
-
readProjects(client).then(setRepos).catch((e) => blame('repo', e, t('this org’s repos'))),
|
|
101
|
-
]);
|
|
102
|
-
}, [client, project, bot.name, blame, t]);
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
void survey();
|
|
105
|
-
}, [survey]);
|
|
106
|
-
return (_jsxs(YStack, { render: "aside", "aria-label": t('{name} runtime', { name: bot.name }), "data-hz": "runtime-pane", width: 360, shrink: 0, overflowY: "auto", borderLeftWidth: 1, borderColor: LINE, bg: GROUND, children: [_jsxs(Part, { title: t('Runtime'), children: [_jsx(Line, { children: t(bot.serviceAccountId
|
|
107
|
-
? '{name} runs for {org} as {id}. Nothing on this panel crosses into another org.'
|
|
108
|
-
: '{name} runs for {org}. Nothing on this panel crosses into another org.', {
|
|
109
|
-
name: bot.name,
|
|
110
|
-
org: _jsx(Text, { color: INK, children: org || t('your org') }),
|
|
111
|
-
id: bot.serviceAccountId ?? '',
|
|
112
|
-
}) }), bot.schedule ? (_jsx(Line, { children: t(bot.executionMode ? 'Wakes on {schedule} ({mode}).' : 'Wakes on {schedule}.', {
|
|
113
|
-
schedule: _jsx(Text, { color: INK, children: bot.schedule }),
|
|
114
|
-
mode: modeName(bot.executionMode, t),
|
|
115
|
-
}) })) : null] }), _jsx(Machine, { bot: bot, machines: machines, why: why.machine }), _jsx(Computer, { bot: bot, box: boxes[0] ?? null, project: project, why: why.box, onChange: survey }), _jsx(Tools, { bot: bot, servers: servers, skills: skills, published: published, activated: activated, why: why.served ?? why.mcp ?? why.skill }), _jsx(Transports, { bot: bot, transports: transports, why: why.transport }), _jsx(Code, { bot: bot, repos: repos, why: why.repo }), _jsx(Secrets, { bot: bot, keys: keys, why: why.key }), _jsx(Held, { links: links, why: why.link })] }));
|
|
116
|
-
}
|
|
117
|
-
/** The machine this Bot runs on. The list is the org's; the binding is the Bot's. */
|
|
118
|
-
function Machine({ bot, machines, why }) {
|
|
119
|
-
const { t, locale } = useI18n();
|
|
120
|
-
const { client } = useAi();
|
|
121
|
-
const [bound, setBound] = useState(bot.computeRef ?? '');
|
|
122
|
-
const [failed, setFailed] = useState(null);
|
|
123
|
-
useEffect(() => setBound(bot.computeRef ?? ''), [bot.computeRef]);
|
|
124
|
-
return (_jsxs(Part, { title: t('Machine'), children: [why ? _jsx(Line, { children: why }) : null, !why && machines.length === 0 ? (_jsx(Line, { children: t('No machine is registered to this org, so this bot runs wherever the platform places it.') })) : null, machines.length > 0 ? (_jsxs(Picker, { ...PICK, value: bound, "aria-label": t('Machine'), onChange: async (e) => {
|
|
125
|
-
const id = e.target.value;
|
|
126
|
-
setBound(id);
|
|
127
|
-
if (!client)
|
|
128
|
-
return;
|
|
129
|
-
try {
|
|
130
|
-
await client.agents.update(bot.name, { computeRef: id });
|
|
131
|
-
setFailed(null);
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
setFailed(say(err, t('this bot'), 'save', t));
|
|
135
|
-
}
|
|
136
|
-
}, children: [_jsx("option", { value: "", children: t('Unbound') }), machines.map((m) => (_jsx("option", { value: m.id, children: m.status
|
|
137
|
-
? t('{name} — {status}', {
|
|
138
|
-
name: m.label || m.host || m.id,
|
|
139
|
-
status: m.status === 'online' ? t('online') : m.status,
|
|
140
|
-
})
|
|
141
|
-
: m.label || m.host || m.id }, m.id)))] })) : null, failed ? _jsx(Line, { children: failed }) : null] }));
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* This Bot's computer.
|
|
145
|
-
*
|
|
146
|
-
* A `desktop` lease has a screen and every lease has a terminal; both are opened
|
|
147
|
-
* through a ticket the platform mints against THIS sandbox, and the iframe points
|
|
148
|
-
* at the URL that came back. There is no other source for either window.
|
|
149
|
-
*
|
|
150
|
-
* MEASURED 2026-09-07: every class of lease is refused by the fleet —
|
|
151
|
-
* `exec` and `desktop` with "pod … not running after 2m0s", `dev` with
|
|
152
|
-
* "admin credentials: DO_API_TOKEN not configured" — and `/v1/exec`, the other
|
|
153
|
-
* door onto the same pool, answers the first of those. So the terminal, the
|
|
154
|
-
* screen and running code are all one outage, and the refusal is the whole of
|
|
155
|
-
* what this section can honestly show until the pool comes back.
|
|
156
|
-
*/
|
|
157
|
-
function Computer({ bot, box, project, why, onChange, }) {
|
|
158
|
-
const { t, locale } = useI18n();
|
|
159
|
-
const { client } = useAi();
|
|
160
|
-
const [busy, setBusy] = useState(false);
|
|
161
|
-
const [failed, setFailed] = useState(null);
|
|
162
|
-
const [command, setCommand] = useState('');
|
|
163
|
-
const [ran, setRan] = useState(null);
|
|
164
|
-
const [window, setWindow] = useState(null);
|
|
165
|
-
const attempt = useCallback(async (what, act) => {
|
|
166
|
-
if (!client || busy)
|
|
167
|
-
return;
|
|
168
|
-
setBusy(true);
|
|
169
|
-
setFailed(null);
|
|
170
|
-
try {
|
|
171
|
-
await act();
|
|
172
|
-
}
|
|
173
|
-
catch (e) {
|
|
174
|
-
// The fleet's own words. A sandbox that will not start is the reader's
|
|
175
|
-
// situation and only the fleet knows why, so it is not translated away.
|
|
176
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
177
|
-
setFailed(t('{what}: {message}', { what, message }));
|
|
178
|
-
}
|
|
179
|
-
finally {
|
|
180
|
-
setBusy(false);
|
|
181
|
-
}
|
|
182
|
-
}, [client, busy, t]);
|
|
183
|
-
const open = (kind) => attempt(t(kind === 'terminal' ? 'Could not open the terminal' : 'Could not open the screen'), async () => {
|
|
184
|
-
if (!client || !box)
|
|
185
|
-
return;
|
|
186
|
-
const g = await grant(client, box.id, kind);
|
|
187
|
-
if (!g.url)
|
|
188
|
-
throw new Error(t('the platform minted no address'));
|
|
189
|
-
setWindow({ kind, url: g.url });
|
|
190
|
-
});
|
|
191
|
-
return (_jsxs(Part, { title: t('Computer'), children: [_jsx(Line, { children: t('Its own disk, {project}. A lease on this project finds the same disk every time, so what this bot writes outlives the lease.', {
|
|
192
|
-
project: _jsx(Text, { render: "code", fontSize: "$1", color: INK, children: project }),
|
|
193
|
-
}) }), why ? _jsx(Line, { children: why }) : null, box ? (_jsxs(_Fragment, { children: [_jsxs(Row, { children: [_jsx(Text, { fontSize: "$2", color: INK, "data-hz": "box", children: t('{class} · {status}', {
|
|
194
|
-
class: box.class ?? t('sandbox'),
|
|
195
|
-
status: box.status ? boxStatus(box.status, t) : t('unknown'),
|
|
196
|
-
}) }), _jsx(Text, { fontSize: "$1", color: FAINT, children: box.id.slice(0, 14) })] }), box.status === 'pending' ? (_jsx(Line, { children: t('Waiting for the fleet to place it. Nothing can be opened on it until it is running.') })) : null, box.status === 'error' ? _jsx(Line, { children: box.error || t('The fleet could not start it.') }) : null, _jsxs(XStack, { gap: 6, flexWrap: "wrap", children: [box.status === 'running' ? (_jsx(Text, { ...TAB, onClick: () => open('terminal'), disabled: busy, children: t('Terminal') })) : null, box.status === 'running' && box.class === 'desktop' ? (_jsx(Text, { ...TAB, onClick: () => open('screen'), disabled: busy, children: t('Screen') })) : null, _jsxs(Text, { ...TAB, disabled: busy, onClick: () => attempt(t('Could not stop it'), async () => {
|
|
197
|
-
await client.sandboxes.stop({ id: box.id });
|
|
198
|
-
}), children: [_jsx(Square, { size: 11, "aria-hidden": true }), t('Stop')] }), _jsxs(Text, { ...TAB, disabled: busy, onClick: () => attempt(t('Could not end the lease'), async () => {
|
|
199
|
-
await client.sandboxes.end({ id: box.id });
|
|
200
|
-
setWindow(null);
|
|
201
|
-
await onChange();
|
|
202
|
-
}), children: [_jsx(X, { size: 11, "aria-hidden": true }), t('End')] })] }), window ? (_jsx(YStack, { render: "iframe", src: window.url, title: t(window.kind === 'terminal' ? '{name} terminal' : '{name} screen', { name: bot.name }), width: "100%", height: 240, borderWidth: 1, borderColor: LINE, rounded: 8, bg: GROUND })) : null, _jsxs(XStack, { render: "form", onSubmit: (e) => {
|
|
203
|
-
e.preventDefault();
|
|
204
|
-
void attempt(t('Could not run it'), async () => {
|
|
205
|
-
setRan(await client.sandboxes.run({ id: box.id, command }));
|
|
206
|
-
});
|
|
207
|
-
}, display: box.status === 'running' ? 'flex' : 'none', gap: 6, children: [_jsx(Input, { ...BOXED, flex: 1, minW: 0, value: command, onChange: (e) => setCommand(e.target.value), placeholder: t('Command'), "aria-label": t("Command to run in this bot's computer") }), _jsxs(Text, { ...TAB, type: 'submit', disabled: busy || !command.trim(), children: [_jsx(Play, { size: 11, "aria-hidden": true }), t('Run')] })] }), ran ? (_jsxs(Text, { ...OUT, children: [(ran.stdout ?? '') + (ran.stderr ?? ''), `\n${t('exit {code}', { code: ran.exitCode ?? 0 })}`] })) : null] })) : (_jsxs(_Fragment, { children: [_jsx(Line, { children: t('No computer is leased. A lease is what a terminal, a screen and a command all hang off, so until one starts there is nothing here to open.') }), _jsxs(XStack, { gap: 6, flexWrap: "wrap", children: [_jsx(Text, { ...TAB, "data-hz": "lease", disabled: busy, onClick: () => attempt(t('Could not lease a computer'), async () => {
|
|
208
|
-
await client.sandboxes.lease({ class: 'dev', project });
|
|
209
|
-
await onChange();
|
|
210
|
-
}), children: t(busy ? 'Leasing…' : 'Lease a computer') }), _jsx(Text, { ...TAB, "data-hz": "lease-desktop", disabled: busy, onClick: () => attempt(t('Could not lease a screen'), async () => {
|
|
211
|
-
await client.sandboxes.lease({ class: 'desktop', project });
|
|
212
|
-
await onChange();
|
|
213
|
-
}), children: t(busy ? 'Leasing…' : 'Lease a screen') })] })] })), failed ? _jsx(Line, { "data-hz": "computer-failed", children: failed }) : null] }));
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* What this Bot may call, and calling one.
|
|
217
|
-
*
|
|
218
|
-
* `tools[]` on the agent record is the Bot's OWN permission set, and it is a
|
|
219
|
-
* PATCH to this Bot and nothing else — another Bot in the same org keeps its
|
|
220
|
-
* own list. The names come from three places, and they are three because the
|
|
221
|
-
* platform keeps them in three:
|
|
222
|
-
*
|
|
223
|
-
* PLATFORM `/v1/mcp` tools/list — every subsystem's operations, projected.
|
|
224
|
-
* 116 for a signed-in caller, with 127 more refused by a stated
|
|
225
|
-
* rule the endpoint publishes. This is the set that can be CALLED.
|
|
226
|
-
* MCP the org's own registered servers, `/v1/tools/mcp/servers`.
|
|
227
|
-
* SKILL the org's authored skills, `/v1/tools/skills`.
|
|
228
|
-
*
|
|
229
|
-
* A name from the last two is dispatchable only once the org ACTIVATES it —
|
|
230
|
-
* `/v1/tools/call` answers 404 "unknown tool" for everything outside the
|
|
231
|
-
* activated set — so an inactive one is labelled rather than drawn as ready.
|
|
232
|
-
*
|
|
233
|
-
* The call below runs against this Bot's granted set and nothing wider, which
|
|
234
|
-
* is what makes the grant mean something on this screen rather than only in
|
|
235
|
-
* the record.
|
|
236
|
-
*/
|
|
237
|
-
function Tools({ bot, servers, skills, published, activated, why, }) {
|
|
238
|
-
const { t, locale } = useI18n();
|
|
239
|
-
const { client } = useAi();
|
|
240
|
-
const [held, setHeld] = useState(bot.tools ?? []);
|
|
241
|
-
const [failed, setFailed] = useState(null);
|
|
242
|
-
const [pick, setPick] = useState('');
|
|
243
|
-
const [op, setOp] = useState('');
|
|
244
|
-
const [ran, setRan] = useState(null);
|
|
245
|
-
const [busy, setBusy] = useState(false);
|
|
246
|
-
useEffect(() => setHeld(bot.tools ?? []), [bot.tools, bot.name]);
|
|
247
|
-
useEffect(() => setPick((p) => (held.includes(p) ? p : (held[0] ?? ''))), [held]);
|
|
248
|
-
const offered = [
|
|
249
|
-
...published.map((tool) => ({ name: tool.name, from: 'platform', ready: true })),
|
|
250
|
-
...servers.map((s) => ({ name: s.name || s.id, from: 'MCP', ready: activated.includes(s.name || s.id) })),
|
|
251
|
-
...skills.map((s) => ({ name: s.name, from: 'skill', ready: activated.includes(s.name) })),
|
|
252
|
-
];
|
|
253
|
-
const flip = async (name) => {
|
|
254
|
-
const next = held.includes(name) ? held.filter((t) => t !== name) : [...held, name];
|
|
255
|
-
setHeld(next);
|
|
256
|
-
if (!client)
|
|
257
|
-
return;
|
|
258
|
-
try {
|
|
259
|
-
await client.agents.update(bot.name, { tools: next });
|
|
260
|
-
setFailed(null);
|
|
261
|
-
}
|
|
262
|
-
catch (e) {
|
|
263
|
-
setFailed(say(e, t('this bot'), 'save', t));
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
return (_jsxs(Part, { title: t('Tools'), children: [why ? _jsx(Line, { children: why }) : null, offered.length === 0 && !why ? (_jsx(Line, { children: t('Nothing publishes a tool for this org yet, so there is nothing to grant.') })) : null, _jsx(YStack, { "data-hz": "tools", maxH: 200, overflowY: "auto", gap: 4, children: offered.map((tool) => (_jsxs(XStack, { render: "label", items: "center", justify: "space-between", gap: 8, cursor: "pointer", children: [_jsx("input", { type: "checkbox", checked: held.includes(tool.name), onChange: () => flip(tool.name), "aria-label": tool.name }), _jsx(Text, { flex: 1, fontSize: "$2", color: INK, children: tool.name }), _jsx(Text, { fontSize: "$1", color: FAINT, children: toolFrom(tool.from, tool.ready, t) })] }, `${tool.from}-${tool.name}`))) }), held.length > 0 ? (_jsxs(YStack, { render: "form", onSubmit: async (e) => {
|
|
267
|
-
e.preventDefault();
|
|
268
|
-
if (!client || busy || !pick || !op.trim())
|
|
269
|
-
return;
|
|
270
|
-
setBusy(true);
|
|
271
|
-
try {
|
|
272
|
-
setRan(await call(client, pick, op.trim()));
|
|
273
|
-
}
|
|
274
|
-
catch (err) {
|
|
275
|
-
setRan(err instanceof Error ? err.message : String(err));
|
|
276
|
-
}
|
|
277
|
-
finally {
|
|
278
|
-
setBusy(false);
|
|
279
|
-
}
|
|
280
|
-
}, gap: 6, children: [_jsx(Picker, { ...PICK, value: pick, onChange: (e) => setPick(e.target.value), "aria-label": t('Tool to call'), children: held.map((h) => (_jsx("option", { value: h, children: h }, h))) }), _jsxs(XStack, { gap: 6, children: [_jsx(Input, { ...BOXED, flex: 1, minW: 0, "data-hz": "op", value: op, onChange: (e) => setOp(e.target.value), placeholder: t('Operation'), "aria-label": t('Operation to run') }), _jsx(Text, { ...TAB, type: 'submit', "data-hz": "call", disabled: busy || !op.trim(), children: t(busy ? 'Calling…' : 'Call') })] })] })) : null, ran ? _jsx(Text, { ...OUT, "data-hz": "called", children: ran }) : null, failed ? _jsx(Line, { children: failed }) : null] }));
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* The transports this Bot answers on.
|
|
284
|
-
*
|
|
285
|
-
* `/v1/transport/agent` binds ONE agent per transport as the org's default
|
|
286
|
-
* answerer, so this is a per-Bot binding and not an account-wide list: pressing
|
|
287
|
-
* Answer here moves that transport from whichever bot holds it to this one.
|
|
288
|
-
*/
|
|
289
|
-
function Transports({ bot, transports, why }) {
|
|
290
|
-
const { t, locale } = useI18n();
|
|
291
|
-
const { client } = useAi();
|
|
292
|
-
const [bound, setBound] = useState({});
|
|
293
|
-
const [failed, setFailed] = useState(null);
|
|
294
|
-
const read = useCallback(async () => {
|
|
295
|
-
if (!client)
|
|
296
|
-
return;
|
|
297
|
-
const pairs = await Promise.all(transports.map(async (r) => {
|
|
298
|
-
try {
|
|
299
|
-
return [r.id, (await answering(client, r.id)).default ?? ''];
|
|
300
|
-
}
|
|
301
|
-
catch {
|
|
302
|
-
return [r.id, ''];
|
|
303
|
-
}
|
|
304
|
-
}));
|
|
305
|
-
setBound(Object.fromEntries(pairs));
|
|
306
|
-
}, [client, transports]);
|
|
307
|
-
useEffect(() => {
|
|
308
|
-
void read();
|
|
309
|
-
}, [read]);
|
|
310
|
-
return (_jsxs(Part, { title: t('Transports'), children: [why ? _jsx(Line, { children: why }) : null, transports.length === 0 && !why ? _jsx(Line, { children: t('This org has no transports.') }) : null, transports.map((r) => {
|
|
311
|
-
const mine = bound[r.id] === bot.name;
|
|
312
|
-
return (_jsxs(Row, { children: [_jsx(Text, { fontSize: "$2", color: INK, children: r.id }), _jsxs(XStack, { items: "center", gap: 8, children: [_jsx(Text, { fontSize: "$1", color: FAINT, children: r.connected ? bound[r.id] || t('unbound') : t('not connected') }), _jsx(Text, { ...TAB, opacity: mine ? 0.5 : 1, disabled: mine, onClick: async () => {
|
|
313
|
-
if (!client)
|
|
314
|
-
return;
|
|
315
|
-
try {
|
|
316
|
-
await answer(client, r.id, bot.name);
|
|
317
|
-
setFailed(null);
|
|
318
|
-
await read();
|
|
319
|
-
}
|
|
320
|
-
catch (e) {
|
|
321
|
-
setFailed(say(e, t('this transport'), 'save', t));
|
|
322
|
-
}
|
|
323
|
-
}, children: t(mine ? 'Answers' : 'Answer') })] })] }, r.id));
|
|
324
|
-
}), failed ? _jsx(Line, { children: failed }) : null] }));
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Work on a repo.
|
|
328
|
-
*
|
|
329
|
-
* `/v1/agents/coding` starts ONE autonomous run against a repo the org owns and
|
|
330
|
-
* hangs a session off it, so this is the door between a Bot and a codebase. The
|
|
331
|
-
* repos offered are the org's own projects that carry one; a name outside that
|
|
332
|
-
* set is refused by the platform naming it, and the refusal is what is shown.
|
|
333
|
-
*/
|
|
334
|
-
function Code({ bot, repos, why }) {
|
|
335
|
-
const { t, locale } = useI18n();
|
|
336
|
-
const { client } = useAi();
|
|
337
|
-
const withRepo = repos.filter((p) => p.repo?.url);
|
|
338
|
-
const [repo, setRepo] = useState('');
|
|
339
|
-
const [task, setTask] = useState('');
|
|
340
|
-
const [busy, setBusy] = useState(false);
|
|
341
|
-
const [said, setSaid] = useState(null);
|
|
342
|
-
useEffect(() => {
|
|
343
|
-
if (!repo && withRepo[0])
|
|
344
|
-
setRepo(withRepo[0].slug);
|
|
345
|
-
}, [repo, withRepo]);
|
|
346
|
-
return (_jsxs(Part, { title: t('Code'), children: [why ? _jsx(Line, { children: why }) : null, withRepo.length === 0 && !why ? (_jsx(Line, { children: t('No project in this org names a repo, so there is nothing for this bot to work on.') })) : (_jsxs(YStack, { render: "form", onSubmit: async (e) => {
|
|
347
|
-
e.preventDefault();
|
|
348
|
-
if (!client || busy || !repo || !task.trim())
|
|
349
|
-
return;
|
|
350
|
-
setBusy(true);
|
|
351
|
-
setSaid(null);
|
|
352
|
-
try {
|
|
353
|
-
const started = await workOn(client, { repo, prompt: task.trim(), agentRef: bot.name, project: repo });
|
|
354
|
-
setSaid(t('Started {run} on {repo}.', { run: started.sessionId || started.id || t('a run'), repo }));
|
|
355
|
-
setTask('');
|
|
356
|
-
}
|
|
357
|
-
catch (err) {
|
|
358
|
-
setSaid(err instanceof Error ? err.message : String(err));
|
|
359
|
-
}
|
|
360
|
-
finally {
|
|
361
|
-
setBusy(false);
|
|
362
|
-
}
|
|
363
|
-
}, gap: 6, children: [_jsx(Picker, { ...PICK, value: repo, onChange: (e) => setRepo(e.target.value), "aria-label": t('Repo'), children: withRepo.map((p) => (_jsx("option", { value: p.slug, children: p.slug }, p.id))) }), _jsx(Input, { ...BOXED, "data-hz": "task", value: task, onChange: (e) => setTask(e.target.value), placeholder: t('What to change'), "aria-label": t('What to change') }), _jsx(Text, { ...TAB, type: 'submit', "data-hz": "code", self: "flex-start", disabled: busy || !task.trim(), children: t(busy ? 'Starting…' : 'Work on it') })] })), said ? _jsx(Line, { children: said }) : null] }));
|
|
364
|
-
}
|
|
365
|
-
/** The names under this Bot's KMS prefix. The values stay in KMS. */
|
|
366
|
-
function Secrets({ bot, keys, why }) {
|
|
367
|
-
const { t, locale } = useI18n();
|
|
368
|
-
return (_jsxs(Part, { title: t('Secrets'), children: [_jsx(Line, { children: t('Held under {path} in KMS. Names are readable here; values are not, by KMS and not by this screen.', {
|
|
369
|
-
path: _jsx(Text, { render: "code", fontSize: "$1", color: INK, children: vault(bot.name) }),
|
|
370
|
-
}) }), why ? _jsx(Line, { children: why }) : null, keys.length === 0 && !why ? _jsx(Line, { children: t('None yet.') }) : null, keys.map((k) => (_jsxs(Row, { children: [_jsx(Text, { fontSize: "$2", color: INK, children: k.name }), _jsx(Text, { fontSize: "$1", color: FAINT, children: k.env })] }, `${k.path}/${k.name}`)))] }));
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* The one thing that is NOT this Bot's.
|
|
374
|
-
*
|
|
375
|
-
* A connector is held by the person who signed in to it.
|
|
376
|
-
* `/v1/connection` answers one set for the caller and no route in
|
|
377
|
-
* the contract narrows it to one agent — so it is listed as what it is, and
|
|
378
|
-
* there is no switch to press.
|
|
379
|
-
*/
|
|
380
|
-
function Held({ links, why }) {
|
|
381
|
-
const { t, locale } = useI18n();
|
|
382
|
-
return (_jsxs(Part, { title: t('Your connectors'), children: [_jsx(Line, { children: t('Signed in by you, reachable by every bot in this org. The platform publishes no per-bot binding for a connector, so nothing here is scoped down to this one.') }), why ? _jsx(Line, { children: why }) : null, links.length === 0 && !why ? _jsx(Line, { children: t('None connected.') }) : null, links.map((l) => (_jsxs(Row, { children: [_jsx(Text, { fontSize: "$1", color: DIM, children: l.label || l.provider }), _jsx(Text, { fontSize: "$1", color: FAINT, children: l.account })] }, l.id)))] }));
|
|
383
|
-
}
|
|
384
|
-
function Part({ title, children }) {
|
|
385
|
-
return (_jsxs(YStack, { render: "section", px: 16, py: 14, borderBottomWidth: 1, borderColor: LINE, gap: 8, children: [_jsx(Text, { ...LABEL, children: title }), children] }));
|
|
386
|
-
}
|
|
387
|
-
const Line = ({ children, ...rest }) => (_jsx(Text, { render: "p", fontSize: "$1", lineHeight: "1.1rem", color: DIM, ...rest, children: children }));
|
|
388
|
-
const Row = ({ children }) => (_jsx(XStack, { items: "center", justify: "space-between", gap: 8, children: children }));
|