@hanzo/app 0.3.65 → 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/dist/lib/signout.d.ts +27 -10
- package/dist/lib/signout.js +45 -13
- package/package.json +1 -1
- package/dist/bots/runtime.d.ts +0 -4
- package/dist/bots/runtime.js +0 -388
package/dist/bots/api.js
CHANGED
|
@@ -1,75 +1,36 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
// ── What a Bot owns ─────────────────────────────────────────────────────────
|
|
4
|
-
//
|
|
5
|
-
// A Bot is not a row in a list of prompts; it is a worker with things of its
|
|
6
|
-
// own. Most are fields on the record — the tools it may call, the machine it
|
|
7
|
-
// runs on, the clock it wakes to, the identity it acts as — and two are named
|
|
8
|
-
// spaces derived from its name:
|
|
9
|
-
//
|
|
10
|
-
// its DISK, because a sandbox volume is named per (org, project) and the name
|
|
11
|
-
// is deterministic, so leasing `bot-<name>` twice finds the same disk and the
|
|
12
|
-
// Bot's runtime state survives a lease that ended;
|
|
13
|
-
//
|
|
14
|
-
// its SECRETS, because `/v1/kms/secrets` filters by `path`, so a Bot's
|
|
15
|
-
// credentials sit under a prefix nothing else reads.
|
|
16
|
-
/** The sandbox project that is this Bot's own disk. */
|
|
17
|
-
export const disk = (name) => `bot-${name}`;
|
|
18
|
-
/** The KMS path prefix that is this Bot's own secrets. */
|
|
19
|
-
export const vault = (name) => `bots/${name}`;
|
|
20
|
-
/** Long-running is the platform's word for a Bot that stays up. The set is
|
|
21
|
-
* closed, and long-running is REFUSED without a schedule — measured, 400
|
|
22
|
-
* "a long-running agent requires a 'schedule' (5-field cron)". */
|
|
2
|
+
/** The platform's word for a bot that runs on its own schedule. */
|
|
23
3
|
export const ALWAYS = 'long-running';
|
|
24
4
|
export const ONCE = 'one-shot';
|
|
25
|
-
|
|
5
|
+
/** A bot's name, as the agents route accepts one in a path. */
|
|
6
|
+
export const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
7
|
+
/** The address names the open bot (`?bot=`), so a reload, a link and Share all reopen it. */
|
|
8
|
+
export const PARAM = 'bot';
|
|
9
|
+
/** One US dollar in the platform's unit of money. */
|
|
10
|
+
export const DOLLAR = 1_000_000;
|
|
26
11
|
/**
|
|
27
|
-
*
|
|
12
|
+
* Makes a bot.
|
|
28
13
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* this was wrong once already.
|
|
14
|
+
* The platform refuses an agent without a budget — `cap_micro_usd`,
|
|
15
|
+
* `max_task_micro_usd` and `period`, every field required — and the SDK's create
|
|
16
|
+
* names none of them, so the call is made here. The week's budget is also the
|
|
17
|
+
* ceiling for one run: a single message may use what the week allows, and the
|
|
18
|
+
* cap is what stops it.
|
|
35
19
|
*/
|
|
36
|
-
export const
|
|
37
|
-
.collection('sessions', { path: SESSION, query: { limit }, signal })
|
|
38
|
-
.then((rows) => rows.filter((s) => s.agent === agent));
|
|
39
|
-
/** Opens a session under this Bot's name and answers the row. */
|
|
40
|
-
export const launch = (c, agent, title) => c.http.json({ method: 'POST', path: SESSION, body: { agent, title } });
|
|
41
|
-
/** One session with its children and its most recent turns. */
|
|
42
|
-
export const transcript = (c, id, signal) => c.http.json({ path: `${SESSION}/${encodeURIComponent(id)}`, signal });
|
|
43
|
-
/** Records one turn in a session's log and answers it. */
|
|
44
|
-
export const record = (c, id, kind, text) => c.http.json({ method: 'POST', path: `${SESSION}/${encodeURIComponent(id)}/events`, body: { kind, text } });
|
|
45
|
-
/** The four things you can say to a running session. Each one is recorded as a
|
|
46
|
-
* control turn whether or not a runner is attached to hear it — the reply
|
|
47
|
-
* carries `forwarded`, which says which of the two happened. */
|
|
48
|
-
export const steer = (c, id, command, message) => c.http.json({
|
|
20
|
+
export const make = (c, d) => c.http.json({
|
|
49
21
|
method: 'POST',
|
|
50
|
-
path:
|
|
51
|
-
body:
|
|
22
|
+
path: '/v1/agents',
|
|
23
|
+
body: {
|
|
24
|
+
name: d.name,
|
|
25
|
+
model: d.model,
|
|
26
|
+
instructions: d.instructions,
|
|
27
|
+
description: d.instructions.split('\n')[0].slice(0, 200),
|
|
28
|
+
cap_micro_usd: d.weekly * DOLLAR,
|
|
29
|
+
max_task_micro_usd: d.weekly * DOLLAR,
|
|
30
|
+
period: 'week',
|
|
31
|
+
},
|
|
52
32
|
});
|
|
33
|
+
/** The sandbox project that is a bot's own disk: the same name finds the same disk. */
|
|
34
|
+
export const disk = (name) => `bot-${name}`;
|
|
53
35
|
export const answering = (c, transport, signal) => c.http.json({ path: '/v1/transport/agent', query: { transport }, signal });
|
|
54
|
-
/** Makes this Bot the one that answers on a transport. */
|
|
55
|
-
export const answer = (c, transport, agent) => c.http.json({ method: 'PUT', path: '/v1/transport/agent', body: { transport, default: agent } });
|
|
56
|
-
const rpc = (c, method, params) => c.http
|
|
57
|
-
.json({
|
|
58
|
-
method: 'POST',
|
|
59
|
-
path: '/v1/mcp',
|
|
60
|
-
body: { jsonrpc: '2.0', id: 1, method, params },
|
|
61
|
-
})
|
|
62
|
-
.then((r) => {
|
|
63
|
-
if (r.error)
|
|
64
|
-
throw new Error(r.error.message || 'the tool refused');
|
|
65
|
-
return r.result;
|
|
66
|
-
});
|
|
67
|
-
export const tools = (c) => rpc(c, 'tools/list').then((r) => r.tools ?? []);
|
|
68
|
-
/** Runs one operation of one tool and answers the text it produced. */
|
|
69
|
-
export const call = (c, name, op, input = {}) => rpc(c, 'tools/call', { name, arguments: { op, input } }).then((r) => (r.content ?? []).map((p) => p.text ?? '').join('\n'));
|
|
70
|
-
/** Starts one autonomous coding run against a repo in the caller's org. */
|
|
71
|
-
export const workOn = (c, params) => c.http.json({ method: 'POST', path: '/v1/agents/coding', body: params });
|
|
72
|
-
export const projects = (c, signal) => c.http.json({ path: '/v1/project', signal });
|
|
73
|
-
export const secrets = (c, path, signal) => c.http.collection('secrets', { path: '/v1/kms/secrets', query: { path }, signal });
|
|
74
|
-
export const connectors = (c, signal) => c.http.collection('connectors', { path: '/v1/connection', signal });
|
|
75
36
|
export const grant = (c, id, kind) => c.http.json({ method: 'POST', path: `/v1/sandbox/${encodeURIComponent(id)}/${kind}/ticket` });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The agents route refuses an input over 128 KiB (apps/agents maxInput). */
|
|
2
|
+
export declare const MAX: number;
|
|
3
|
+
/** A text file held beside the draft until it is sent. */
|
|
4
|
+
export interface File {
|
|
5
|
+
name: string;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
/** Whether the bytes read as text: no NUL, which no text file carries. */
|
|
9
|
+
export declare const texty: (text: string) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The file fenced under its name. The fence is one backtick longer than the
|
|
12
|
+
* longest run of backticks inside, so nothing in the file can close it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function fence(file: File): string;
|
|
15
|
+
/** What is sent: the words, then the file. */
|
|
16
|
+
export declare const compose: (draft: string, file: File | null) => string;
|
|
17
|
+
/** Whether a message fits the route's input cap, in bytes as the route counts them. */
|
|
18
|
+
export declare const fits: (message: string) => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// A text file that goes with a message to a bot. A run carries text alone, so the
|
|
2
|
+
// file is fenced under its name in the message the bot reads. Pure, so the fence
|
|
3
|
+
// and the limits are tested as data.
|
|
4
|
+
/** The agents route refuses an input over 128 KiB (apps/agents maxInput). */
|
|
5
|
+
export const MAX = 128 * 1024;
|
|
6
|
+
/** Whether the bytes read as text: no NUL, which no text file carries. */
|
|
7
|
+
export const texty = (text) => !text.includes('\u0000');
|
|
8
|
+
/** The file's name as a fence's info string: one line, no backticks. */
|
|
9
|
+
const label = (name) => name.replace(/[`\r\n]+/g, ' ').trim();
|
|
10
|
+
/**
|
|
11
|
+
* The file fenced under its name. The fence is one backtick longer than the
|
|
12
|
+
* longest run of backticks inside, so nothing in the file can close it.
|
|
13
|
+
*/
|
|
14
|
+
export function fence(file) {
|
|
15
|
+
const longest = Math.max(2, ...(file.text.match(/`+/g) ?? []).map((run) => run.length));
|
|
16
|
+
const ticks = '`'.repeat(longest + 1);
|
|
17
|
+
return `${ticks}${label(file.name)}\n${file.text.replace(/\n$/, '')}\n${ticks}`;
|
|
18
|
+
}
|
|
19
|
+
/** What is sent: the words, then the file. */
|
|
20
|
+
export const compose = (draft, file) => [draft.trim(), file ? fence(file) : ''].filter(Boolean).join('\n\n');
|
|
21
|
+
/** Whether a message fits the route's input cap, in bytes as the route counts them. */
|
|
22
|
+
export const fits = (message) => new TextEncoder().encode(message).length <= MAX;
|
package/dist/bots/face.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Text, YStack } from '@hanzo/gui';
|
|
4
|
-
import { INK
|
|
4
|
+
import { INK } from './ink.js';
|
|
5
5
|
export function Face({ bot, size = 36 }) {
|
|
6
|
-
const round = { width: size, height: size, shrink: 0, rounded: 9999,
|
|
6
|
+
const round = { width: size, height: size, shrink: 0, rounded: 9999, overflow: 'hidden' };
|
|
7
7
|
if (bot.avatar)
|
|
8
8
|
return _jsx(YStack, { render: "img", src: bot.avatar, alt: '', "aria-hidden": true, ...round, objectFit: "cover" });
|
|
9
9
|
// The glyph scales with the disc, so its size is a number of pixels rather
|
|
10
10
|
// than a rung; the leading is the size itself, which centres it.
|
|
11
|
-
const glyph = Math.round(size * (bot.emoji ? 0.5 : 0.
|
|
12
|
-
return (_jsx(YStack, { "aria-hidden": true, ...round, items: "center", justify: "center", bg:
|
|
11
|
+
const glyph = Math.round(size * (bot.emoji ? 0.5 : 0.42));
|
|
12
|
+
return (_jsx(YStack, { "aria-hidden": true, ...round, items: "center", justify: "center", bg: "var(--secondary)", userSelect: 'none', children: _jsx(Text, { color: INK, fontSize: glyph, lineHeight: glyph, fontWeight: "500", children: bot.emoji || (bot.name || '?').trim().charAt(0).toUpperCase() }) }));
|
|
13
13
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Agent, AgentRun } from '@hanzo/ai';
|
|
2
|
+
/** How many bots the grid holds before the rest become rows. */
|
|
3
|
+
export declare const GRID = 12;
|
|
4
|
+
/** What a row says under a bot's name: its newest run's last word. */
|
|
5
|
+
export declare function lastWord(run: AgentRun | undefined): string;
|
|
6
|
+
/** The bots in the grid and the bots in rows. */
|
|
7
|
+
export declare function split(bots: readonly Agent[], last: ReadonlyMap<string, AgentRun>): {
|
|
8
|
+
grid: Agent[];
|
|
9
|
+
rows: Agent[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Which bots are faces in the grid and which are rows, and what a row says.
|
|
2
|
+
// Pure, so the roster's order is tested as data.
|
|
3
|
+
import { instant } from './time.js';
|
|
4
|
+
/** How many bots the grid holds before the rest become rows. */
|
|
5
|
+
export const GRID = 12;
|
|
6
|
+
/** What a row says under a bot's name: its newest run's last word. */
|
|
7
|
+
export function lastWord(run) {
|
|
8
|
+
if (!run)
|
|
9
|
+
return '';
|
|
10
|
+
return (run.output || run.error || run.input || '').replace(/\s+/g, ' ').trim();
|
|
11
|
+
}
|
|
12
|
+
/** The bots in the grid and the bots in rows. */
|
|
13
|
+
export function split(bots, last) {
|
|
14
|
+
const made = [...bots].sort((a, b) => (instant(a.createdAt) ?? 0) - (instant(b.createdAt) ?? 0));
|
|
15
|
+
const grid = made.slice(0, GRID);
|
|
16
|
+
const rows = made
|
|
17
|
+
.slice(GRID)
|
|
18
|
+
.sort((a, b) => (instant(last.get(b.name)?.createdAt) ?? 0) - (instant(last.get(a.name)?.createdAt) ?? 0));
|
|
19
|
+
return { grid, rows };
|
|
20
|
+
}
|
package/dist/bots/ink.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
/** The roster's ground: the window itself. */
|
|
2
|
+
export declare const FLOOR = "var(--background)";
|
|
3
|
+
/** The thread's and the panel's ground. */
|
|
4
|
+
export declare const GROUND = "var(--card)";
|
|
5
|
+
/** What stands on the ground: the pills, the cards, the composer, a bot's message. */
|
|
6
|
+
export declare const RAISED = "var(--surface-card-emphasis)";
|
|
7
|
+
/** The bot that is open, in the roster. */
|
|
8
|
+
export declare const PICKED = "var(--secondary)";
|
|
9
|
+
/** Your own message: lighter than a bot's, in either theme. */
|
|
10
|
+
export declare const MINE = "color-mix(in oklab, var(--foreground) 22%, var(--card))";
|
|
3
11
|
export declare const INK = "var(--foreground)";
|
|
4
12
|
export declare const DIM = "var(--muted-foreground)";
|
|
5
13
|
export declare const FAINT = "$faint";
|
|
6
14
|
export declare const LINE = "var(--border)";
|
|
7
|
-
|
|
15
|
+
/** The composer's edge, the one control drawn a step louder. */
|
|
16
|
+
export declare const EDGE = "var(--border-strong)";
|
package/dist/bots/ink.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
// The ramp
|
|
1
|
+
// The ramp the Bots app is drawn in.
|
|
2
2
|
//
|
|
3
|
-
// Greyscale, because nothing on this screen is a category: a
|
|
4
|
-
// a
|
|
5
|
-
// a colour from a table in the source, which told a reader which of seven
|
|
6
|
-
// fictional workers they were looking at and could not survive the eighth.
|
|
3
|
+
// Greyscale, because nothing on this screen is a category: a bot is not red and
|
|
4
|
+
// a run is not green. Status is said in words.
|
|
7
5
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
6
|
+
// ROLES, NOT VALUES. Each name is a @hanzo/design token, which tunes both
|
|
7
|
+
// grounds; a literal here would read right in one theme by coincidence.
|
|
10
8
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const
|
|
9
|
+
// Two grounds, as the window is drawn: the roster stands on the floor and the
|
|
10
|
+
// thread and the panel on the ground one step above it.
|
|
11
|
+
/** The roster's ground: the window itself. */
|
|
12
|
+
export const FLOOR = 'var(--background)';
|
|
13
|
+
/** The thread's and the panel's ground. */
|
|
14
|
+
export const GROUND = 'var(--card)';
|
|
15
|
+
/** What stands on the ground: the pills, the cards, the composer, a bot's message. */
|
|
16
|
+
export const RAISED = 'var(--surface-card-emphasis)';
|
|
17
|
+
/** The bot that is open, in the roster. */
|
|
18
|
+
export const PICKED = 'var(--secondary)';
|
|
19
|
+
/** Your own message: lighter than a bot's, in either theme. */
|
|
20
|
+
export const MINE = 'color-mix(in oklab, var(--foreground) 22%, var(--card))';
|
|
23
21
|
export const INK = 'var(--foreground)';
|
|
24
22
|
export const DIM = 'var(--muted-foreground)';
|
|
25
|
-
// The dimmest ink is gui's `$faint` rung
|
|
26
|
-
//
|
|
23
|
+
// The dimmest ink is gui's `$faint` rung: design's --text-tertiary is 4.32:1 on
|
|
24
|
+
// the light ground, under text's 4.5.
|
|
27
25
|
export const FAINT = '$faint';
|
|
28
26
|
export const LINE = 'var(--border)';
|
|
29
|
-
|
|
27
|
+
/** The composer's edge, the one control drawn a step louder. */
|
|
28
|
+
export const EDGE = 'var(--border-strong)';
|
package/dist/bots/kit.d.ts
CHANGED
|
@@ -1,92 +1,73 @@
|
|
|
1
|
-
/** A
|
|
2
|
-
|
|
3
|
-
export declare const GHOST: {
|
|
1
|
+
/** A round icon control, 34px: the roster's search and new, the panel's close. */
|
|
2
|
+
export declare const ROUND: {
|
|
4
3
|
readonly render: 'button';
|
|
5
4
|
readonly type: 'button';
|
|
6
|
-
readonly
|
|
7
|
-
readonly
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
5
|
+
readonly width: 34;
|
|
6
|
+
readonly height: 34;
|
|
7
|
+
readonly shrink: 0;
|
|
8
|
+
readonly rounded: 999;
|
|
9
|
+
readonly bg: "var(--surface-card-emphasis)";
|
|
10
|
+
readonly borderWidth: 1;
|
|
11
|
+
readonly borderColor: "var(--border)";
|
|
10
12
|
readonly items: 'center';
|
|
11
13
|
readonly justify: 'center';
|
|
12
14
|
readonly cursor: 'pointer';
|
|
15
|
+
readonly p: 0;
|
|
16
|
+
readonly hoverStyle: {
|
|
17
|
+
readonly bg: 'var(--secondary)';
|
|
18
|
+
};
|
|
19
|
+
readonly focusVisibleStyle: {
|
|
20
|
+
readonly outlineWidth: 2;
|
|
21
|
+
readonly outlineStyle: 'solid';
|
|
22
|
+
readonly outlineColor: '$outlineColor';
|
|
23
|
+
};
|
|
13
24
|
};
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
export declare const TAB: {
|
|
25
|
+
/** A pill: the open bot in the bar, Share, a notice's ways past. */
|
|
26
|
+
export declare const PILL: {
|
|
17
27
|
readonly render: 'button';
|
|
18
28
|
readonly type: 'button';
|
|
19
|
-
readonly display: '
|
|
29
|
+
readonly display: 'flex';
|
|
20
30
|
readonly items: 'center';
|
|
21
|
-
readonly gap:
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
24
|
-
readonly rounded:
|
|
25
|
-
readonly
|
|
26
|
-
readonly fontWeight: '600';
|
|
31
|
+
readonly gap: 8;
|
|
32
|
+
readonly height: 38;
|
|
33
|
+
readonly px: 14;
|
|
34
|
+
readonly rounded: 999;
|
|
35
|
+
readonly bg: "var(--surface-card-emphasis)";
|
|
27
36
|
readonly borderWidth: 1;
|
|
28
37
|
readonly borderColor: "var(--border)";
|
|
29
|
-
readonly bg: 'transparent';
|
|
30
|
-
readonly color: "var(--muted-foreground)";
|
|
31
38
|
readonly cursor: 'pointer';
|
|
39
|
+
readonly shrink: 0;
|
|
40
|
+
readonly hoverStyle: {
|
|
41
|
+
readonly bg: 'var(--secondary)';
|
|
42
|
+
};
|
|
43
|
+
readonly focusVisibleStyle: {
|
|
44
|
+
readonly outlineWidth: 2;
|
|
45
|
+
readonly outlineStyle: 'solid';
|
|
46
|
+
readonly outlineColor: '$outlineColor';
|
|
47
|
+
};
|
|
32
48
|
};
|
|
33
|
-
/** A
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
readonly
|
|
37
|
-
readonly color: "var(--foreground)";
|
|
38
|
-
readonly placeholderTextColor: '$placeholderColor';
|
|
39
|
-
};
|
|
40
|
-
/** A field that draws its own edge. */
|
|
41
|
-
export declare const BOXED: {
|
|
42
|
-
readonly unstyled: true;
|
|
43
|
-
readonly width: '100%';
|
|
44
|
-
readonly px: 10;
|
|
45
|
-
readonly py: 7;
|
|
46
|
-
readonly rounded: 8;
|
|
47
|
-
readonly bg: "var(--surface-card-quiet)";
|
|
48
|
-
readonly borderWidth: 1;
|
|
49
|
-
readonly borderColor: "var(--border)";
|
|
49
|
+
/** A pill's words. */
|
|
50
|
+
export declare const WORD: {
|
|
51
|
+
readonly fontSize: 15;
|
|
52
|
+
readonly lineHeight: 20;
|
|
50
53
|
readonly color: "var(--foreground)";
|
|
51
|
-
readonly
|
|
52
|
-
readonly placeholderTextColor: '$placeholderColor';
|
|
54
|
+
readonly numberOfLines: 1;
|
|
53
55
|
};
|
|
54
|
-
/**
|
|
55
|
-
export declare const
|
|
56
|
-
readonly
|
|
57
|
-
readonly
|
|
58
|
-
readonly
|
|
59
|
-
readonly
|
|
60
|
-
readonly color: "var(--foreground)";
|
|
61
|
-
readonly
|
|
56
|
+
/** A section's heading in the panel. */
|
|
57
|
+
export declare const LABEL: {
|
|
58
|
+
readonly render: 'h3';
|
|
59
|
+
readonly fontSize: 13;
|
|
60
|
+
readonly lineHeight: 18;
|
|
61
|
+
readonly fontWeight: '400';
|
|
62
|
+
readonly color: "var(--muted-foreground)";
|
|
63
|
+
readonly m: 0;
|
|
62
64
|
};
|
|
63
|
-
/** A
|
|
65
|
+
/** A card in the panel. */
|
|
64
66
|
export declare const CARD: {
|
|
65
|
-
readonly bg: "var(--surface-
|
|
67
|
+
readonly bg: "var(--surface-card-emphasis)";
|
|
66
68
|
readonly borderWidth: 1;
|
|
67
69
|
readonly borderColor: "var(--border)";
|
|
68
|
-
readonly rounded:
|
|
69
|
-
readonly p: 16;
|
|
70
|
-
readonly gap: 8;
|
|
71
|
-
readonly maxW: 620;
|
|
72
|
-
};
|
|
73
|
-
/** A section's small-caps heading. */
|
|
74
|
-
export declare const LABEL: {
|
|
75
|
-
readonly render: 'h3';
|
|
76
|
-
readonly fontSize: '$1';
|
|
77
|
-
readonly fontWeight: '600';
|
|
78
|
-
readonly letterSpacing: 0.6;
|
|
79
|
-
readonly color: "$faint";
|
|
80
|
-
readonly textTransform: 'uppercase';
|
|
81
|
-
};
|
|
82
|
-
/** A sentence the app says when it has nothing else to draw. */
|
|
83
|
-
export declare const NOTE: {
|
|
84
|
-
readonly render: 'p';
|
|
85
|
-
readonly px: 12;
|
|
86
|
-
readonly py: 10;
|
|
87
|
-
readonly fontSize: '$2';
|
|
88
|
-
readonly lineHeight: '1.3rem';
|
|
89
|
-
readonly color: "var(--muted-foreground)";
|
|
70
|
+
readonly rounded: 12;
|
|
90
71
|
};
|
|
91
72
|
/** One line, cut with an ellipsis where it runs out of space. */
|
|
92
73
|
export declare const CLIP: {
|
|
@@ -94,20 +75,3 @@ export declare const CLIP: {
|
|
|
94
75
|
readonly overflow: 'hidden';
|
|
95
76
|
readonly textOverflow: 'ellipsis';
|
|
96
77
|
};
|
|
97
|
-
/** What a run printed: a bounded block of mono that scrolls. */
|
|
98
|
-
export declare const OUT: {
|
|
99
|
-
readonly render: 'pre';
|
|
100
|
-
readonly display: 'block';
|
|
101
|
-
readonly maxH: 180;
|
|
102
|
-
readonly overflowY: 'auto';
|
|
103
|
-
readonly p: 10;
|
|
104
|
-
readonly rounded: 8;
|
|
105
|
-
readonly bg: "var(--surface-card-quiet)";
|
|
106
|
-
readonly borderWidth: 1;
|
|
107
|
-
readonly borderColor: "var(--border)";
|
|
108
|
-
readonly fontFamily: '$mono';
|
|
109
|
-
readonly fontSize: '$1';
|
|
110
|
-
readonly lineHeight: '1.03125rem';
|
|
111
|
-
readonly whiteSpace: 'pre-wrap';
|
|
112
|
-
readonly color: "var(--foreground)";
|
|
113
|
-
};
|
package/dist/bots/kit.js
CHANGED
|
@@ -1,43 +1,25 @@
|
|
|
1
|
-
// The controls
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
render: 'button', type: 'button', p: 6, rounded: 6, bg: 'transparent', borderWidth: 0,
|
|
11
|
-
items: 'center', justify: 'center', cursor: 'pointer',
|
|
1
|
+
// The controls the Bots app is drawn from, as gui props, stated once and spread
|
|
2
|
+
// where they are drawn.
|
|
3
|
+
import { DIM, INK, LINE, RAISED } from './ink.js';
|
|
4
|
+
/** A round icon control, 34px: the roster's search and new, the panel's close. */
|
|
5
|
+
export const ROUND = {
|
|
6
|
+
render: 'button', type: 'button', width: 34, height: 34, shrink: 0, rounded: 999, bg: RAISED,
|
|
7
|
+
borderWidth: 1, borderColor: LINE, items: 'center', justify: 'center', cursor: 'pointer', p: 0,
|
|
8
|
+
hoverStyle: { bg: 'var(--secondary)' },
|
|
9
|
+
focusVisibleStyle: { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' },
|
|
12
10
|
};
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
/** A pill: the open bot in the bar, Share, a notice's ways past. */
|
|
12
|
+
export const PILL = {
|
|
13
|
+
render: 'button', type: 'button', display: 'flex', items: 'center', gap: 8, height: 38, px: 14, rounded: 999,
|
|
14
|
+
bg: RAISED, borderWidth: 1, borderColor: LINE, cursor: 'pointer', shrink: 0,
|
|
15
|
+
hoverStyle: { bg: 'var(--secondary)' },
|
|
16
|
+
focusVisibleStyle: { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' },
|
|
18
17
|
};
|
|
19
|
-
/** A
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
color: INK, fontSize: '$2', placeholderTextColor: '$placeholderColor',
|
|
26
|
-
};
|
|
27
|
-
/** The platform's select, wearing the same edge as `BOXED`. */
|
|
28
|
-
export const PICK = { width: '100%', rounded: 8, bg: SURFACE, borderColor: LINE, color: INK, fontSize: '$2' };
|
|
29
|
-
/** A raised card in the stream. */
|
|
30
|
-
export const CARD = { bg: RAISED, borderWidth: 1, borderColor: LINE, rounded: 14, p: 16, gap: 8, maxW: 620 };
|
|
31
|
-
/** A section's small-caps heading. */
|
|
32
|
-
export const LABEL = {
|
|
33
|
-
render: 'h3', fontSize: '$1', fontWeight: '600', letterSpacing: 0.6, color: FAINT, textTransform: 'uppercase',
|
|
34
|
-
};
|
|
35
|
-
/** A sentence the app says when it has nothing else to draw. */
|
|
36
|
-
export const NOTE = { render: 'p', px: 12, py: 10, fontSize: '$2', lineHeight: '1.3rem', color: DIM };
|
|
18
|
+
/** A pill's words. */
|
|
19
|
+
export const WORD = { fontSize: 15, lineHeight: 20, color: INK, numberOfLines: 1 };
|
|
20
|
+
/** A section's heading in the panel. */
|
|
21
|
+
export const LABEL = { render: 'h3', fontSize: 13, lineHeight: 18, fontWeight: '400', color: DIM, m: 0 };
|
|
22
|
+
/** A card in the panel. */
|
|
23
|
+
export const CARD = { bg: RAISED, borderWidth: 1, borderColor: LINE, rounded: 12 };
|
|
37
24
|
/** One line, cut with an ellipsis where it runs out of space. */
|
|
38
25
|
export const CLIP = { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' };
|
|
39
|
-
/** What a run printed: a bounded block of mono that scrolls. */
|
|
40
|
-
export const OUT = {
|
|
41
|
-
render: 'pre', display: 'block', maxH: 180, overflowY: 'auto', p: 10, rounded: 8, bg: SURFACE, borderWidth: 1,
|
|
42
|
-
borderColor: LINE, fontFamily: '$mono', fontSize: '$1', lineHeight: '1.03125rem', whiteSpace: 'pre-wrap', color: INK,
|
|
43
|
-
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Say } from '@hanzo/i18n';
|
|
2
|
+
import type { LimitAction } from '@hanzo/ui/product/limits';
|
|
3
|
+
/** A refusal the platform gave before a run: what it said, when it lifts, the ways past it. */
|
|
4
|
+
export interface Notice {
|
|
5
|
+
message: string;
|
|
6
|
+
resets: string | null;
|
|
7
|
+
actions: readonly LimitAction[];
|
|
8
|
+
}
|
|
9
|
+
/** Monday 00:00 UTC after `now`: a weekly cap's period is the calendar week in UTC. */
|
|
10
|
+
export declare function nextWeek(now: number): string;
|
|
11
|
+
/** When a cap's period after `now` begins: calendar-aligned in UTC, as the platform counts it. */
|
|
12
|
+
export declare function nextPeriod(now: number, period?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* A refusal about money, as a notice: the gateway's billing envelope (its
|
|
15
|
+
* message, when it lifts, its ways past), the bot's own weekly budget spent, or
|
|
16
|
+
* the run's 402 for an org with no balance with the credits page it names (when
|
|
17
|
+
* that page is one of ours). Any other failure is not a notice.
|
|
18
|
+
*/
|
|
19
|
+
export declare function refusal(e: unknown, name: string, now: number, t?: Say, period?: string): Notice | null;
|
|
20
|
+
/**
|
|
21
|
+
* The run a 502 carries: the agents route answers a run that reached its model
|
|
22
|
+
* and failed with the recorded run as the body. A 502 from anything in front of
|
|
23
|
+
* it carries no run, and nothing was recorded.
|
|
24
|
+
*/
|
|
25
|
+
export declare function recordedRun<T extends {
|
|
26
|
+
id: string;
|
|
27
|
+
status: string;
|
|
28
|
+
}>(e: unknown): T | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// A refusal about money, read from what the platform answered.
|
|
2
|
+
import { english } from '@hanzo/i18n';
|
|
3
|
+
import { billed, ours, say } from '../failure.js';
|
|
4
|
+
/** The agents route's code for a bot whose own period cap is spent (apps/agents budget.go). */
|
|
5
|
+
const BUDGET = 'budget_exceeded';
|
|
6
|
+
/** Monday 00:00 UTC after `now`: a weekly cap's period is the calendar week in UTC. */
|
|
7
|
+
export function nextWeek(now) {
|
|
8
|
+
const d = new Date(now);
|
|
9
|
+
const day = d.getUTCDay(); // 0 Sunday … 6 Saturday
|
|
10
|
+
const ahead = ((8 - day) % 7) || 7;
|
|
11
|
+
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + ahead)).toISOString();
|
|
12
|
+
}
|
|
13
|
+
/** When a cap's period after `now` begins: calendar-aligned in UTC, as the platform counts it. */
|
|
14
|
+
export function nextPeriod(now, period = 'week') {
|
|
15
|
+
const d = new Date(now);
|
|
16
|
+
if (period === 'day')
|
|
17
|
+
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + 1)).toISOString();
|
|
18
|
+
if (period === 'month')
|
|
19
|
+
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 1)).toISOString();
|
|
20
|
+
return nextWeek(now);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A refusal about money, as a notice: the gateway's billing envelope (its
|
|
24
|
+
* message, when it lifts, its ways past), the bot's own weekly budget spent, or
|
|
25
|
+
* the run's 402 for an org with no balance with the credits page it names (when
|
|
26
|
+
* that page is one of ours). Any other failure is not a notice.
|
|
27
|
+
*/
|
|
28
|
+
export function refusal(e, name, now, t = english, period = 'week') {
|
|
29
|
+
const no = billed(e);
|
|
30
|
+
if (no)
|
|
31
|
+
return { message: no.message || say(e, t('your message to {name}', { name }), 'save', t), resets: no.resets_at, actions: no.actions };
|
|
32
|
+
const status = e?.status;
|
|
33
|
+
if (status !== 402 && status !== 429)
|
|
34
|
+
return null;
|
|
35
|
+
const raw = e?.body;
|
|
36
|
+
const body = raw && typeof raw.error === 'object' && raw.error ? raw.error : raw ?? {};
|
|
37
|
+
if (body.code === BUDGET) {
|
|
38
|
+
const spent = period === 'day'
|
|
39
|
+
? t('{name} has spent today’s budget.', { name })
|
|
40
|
+
: period === 'month'
|
|
41
|
+
? t('{name} has spent this month’s budget.', { name })
|
|
42
|
+
: t('{name} has spent this week’s budget.', { name });
|
|
43
|
+
return { message: spent, resets: nextPeriod(now, period), actions: [] };
|
|
44
|
+
}
|
|
45
|
+
const url = ours(body.billingUrl);
|
|
46
|
+
return {
|
|
47
|
+
message: typeof body.message === 'string' && body.message ? body.message : say(e, t('your message to {name}', { name }), 'save', t),
|
|
48
|
+
resets: typeof body.resets_at === 'string' ? body.resets_at : null,
|
|
49
|
+
actions: url ? [{ kind: 'topup', label: t('Add credits'), url }] : [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The run a 502 carries: the agents route answers a run that reached its model
|
|
54
|
+
* and failed with the recorded run as the body. A 502 from anything in front of
|
|
55
|
+
* it carries no run, and nothing was recorded.
|
|
56
|
+
*/
|
|
57
|
+
export function recordedRun(e) {
|
|
58
|
+
if (e?.status !== 502)
|
|
59
|
+
return null;
|
|
60
|
+
const body = e.body;
|
|
61
|
+
return body && typeof body.id === 'string' && typeof body.status === 'string' ? body : null;
|
|
62
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Agent, AgentRun } from '@hanzo/ai';
|
|
2
|
+
/** A message that went out and has not come back yet. */
|
|
3
|
+
export interface Pending {
|
|
4
|
+
input: string;
|
|
5
|
+
at: number;
|
|
6
|
+
}
|
|
7
|
+
/** One line of the thread, in the order it happened. */
|
|
8
|
+
export type Line = {
|
|
9
|
+
kind: 'stamp';
|
|
10
|
+
key: string;
|
|
11
|
+
text: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'from';
|
|
14
|
+
key: string;
|
|
15
|
+
bot: Agent;
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'mine';
|
|
18
|
+
key: string;
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'theirs';
|
|
22
|
+
key: string;
|
|
23
|
+
text: string;
|
|
24
|
+
failed?: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'other';
|
|
27
|
+
key: string;
|
|
28
|
+
text: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'thinking';
|
|
31
|
+
key: string;
|
|
32
|
+
};
|
|
33
|
+
/** The thread as lines: stamps where it paused, each run as the messages it holds. */
|
|
34
|
+
export declare function lines(runs: readonly AgentRun[], bots: readonly Agent[], self: string, pending: Pending | null, now: number, locale: string, t: (s: string, v?: Record<string, unknown>) => string): Line[];
|