Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 72 additions & 9 deletions dashboard/e2e/agents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { afterAll, beforeAll, beforeEach, expect, test } from 'vitest';
import { closeBrowser, openPage, shoot } from './browser.ts';
import { startOrchestrator, type TestOrchestrator } from './orchestrator.ts';
import { DEFAULT_BOX, startOrchestrator, type TestOrchestrator } from './orchestrator.ts';

/** The orchestrator that the tests in this file share. */
let stub: TestOrchestrator;
Expand Down Expand Up @@ -144,17 +144,80 @@ test('a SKILL.md with no front matter is called out before it is saved', async (
}
});

test('a box is created against a named set, and the global one is not offered', async () => {
const { page, close } = await openPage(stub.url, '/new');
test('a box is created with named sets, and the global one is not offered', async () => {
const { page, errors, close } = await openPage(stub.url, '/new');
try {
await expect.poll(() => page.getByLabel('Agent set').isVisible()).toBe(true);
const add = page.getByRole('combobox', { name: 'Add an agent set' });
await expect.poll(() => add.isVisible()).toBe(true);
await page.getByLabel('Name').fill('a new box');
await page.getByLabel('Agent set').click();
await add.click();
// The global set always applies, so it is not an option.
expect(await page.getByRole('option').allInnerTexts()).toEqual([
'Global set only',
'Go projects',
]);
expect(await page.getByRole('option').allInnerTexts()).toEqual(['Go projects']);
await page.getByRole('option', { name: 'Go projects' }).click();
await expect.poll(() => page.getByRole('listitem').allInnerTexts()).toEqual(['Go projects']);

await page.getByRole('button', { name: 'Create' }).click();
await expect.poll(() => stub.boxCalls.length).toBe(1);
expect(stub.boxCalls[0]).toMatchObject({ name: 'a new box', agentSets: ['as1'] });
expect(errors).toEqual([]);
} finally {
await close();
}
});

test('the box details page adds and removes the agent sets of the box', async () => {
const res = await fetch(`${stub.url}/api/agent-sets`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ name: 'Web' }),
});
const web = ((await res.json()) as { id: string }).id;
const { page, errors, close } = await openPage(stub.url, `/boxes/${DEFAULT_BOX.id}/info`);
try {
const add = page.getByRole('combobox', { name: 'Add an agent set' });
await expect.poll(() => page.getByText('Global set only').isVisible()).toBe(true);

/**
* Changes the sets with one action and gives the body of the request.
*
* @param action The action in the page.
* @returns The JSON body of the PUT request.
*/
const change = async (action: () => Promise<void>): Promise<unknown> => {
const put = page.waitForRequest(
(req) =>
req.method() === 'PUT' && req.url().endsWith(`/api/boxes/${DEFAULT_BOX.id}/agent-sets`),
);
await action();
return (await put).postDataJSON();
};

expect(
await change(async () => {
await add.click();
await page.getByRole('option', { name: 'Go projects' }).click();
}),
).toEqual({ agentSets: ['as1'] });
await expect.poll(() => page.getByRole('listitem').allInnerTexts()).toEqual(['Go projects']);

// A new set goes to the end of the list.
expect(
await change(async () => {
await add.click();
await page.getByRole('option', { name: 'Web' }).click();
}),
).toEqual({ agentSets: ['as1', web] });
await expect
.poll(() => page.getByRole('listitem').allInnerTexts())
.toEqual(['Go projects', 'Web']);
// Each set is in the list, so the page offers no more sets.
await expect.poll(() => add.count()).toBe(0);

expect(
await change(() => page.getByRole('button', { name: 'Remove Go projects' }).click()),
).toEqual({ agentSets: [web] });
await expect.poll(() => page.getByRole('listitem').allInnerTexts()).toEqual(['Web']);
expect(errors).toEqual([]);
} finally {
await close();
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/e2e/dialogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test('the new-box form creates the box and its first thread in one request', asy
await expect.poll(() => stub.boxCalls.length).toBe(1);
expect(stub.boxCalls[0]).toEqual({
name: 'second box',
agentSet: null,
agentSets: [],
// The form preselects the default profile. The orchestrator makes its id.
egressProfile: expect.stringMatching(/^ep[0-9a-f]{10}$/),
thread: {
Expand Down
4 changes: 2 additions & 2 deletions dashboard/e2e/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,9 @@ function createBox(
const now = Date.now();
// A set ready_at marks the setup as done, so a start of the box runs no setup.
db.prepare(
`INSERT INTO boxes (id, name, profile, review_base_rev, status, agent_set_id, ws_token,
`INSERT INTO boxes (id, name, profile, review_base_rev, status, ws_token,
created_at, last_active_at, ready_at)
VALUES (?, ?, 'DEFAULT', NULL, ?, NULL, ?, ?, ?, ?)`,
VALUES (?, ?, 'DEFAULT', NULL, ?, ?, ?, ?, ?)`,
).run(id, spec.name ?? DEFAULT_BOX.name, spec.status ?? 'running', WS_TOKEN, now, now, now);

ws.createWorkspace(cfg.DATA_DIR, id);
Expand Down
12 changes: 12 additions & 0 deletions dashboard/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ export const api = {
*/
deleteReview: (id: string) => request<void>(`/api/boxes/${id}/review`, { method: 'DELETE' }),

/**
* Selects the agent sets of a box.
*
* @param id The id of the box.
* @param agentSets The ids of the sets in the order of the merge, or an empty list for the global set only.
* @returns The box after the change.
*/
setBoxAgentSets: (id: string, agentSets: string[]) =>
request<BoxDetail>(`/api/boxes/${id}/agent-sets`, {
method: 'PUT',
body: JSON.stringify({ agentSets }),
}),
/**
* Selects the egress profile of a box.
*
Expand Down
88 changes: 88 additions & 0 deletions dashboard/src/components/AgentSetPicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { X } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import type { AgentSetSummary } from '../../../shared/types.ts';

/**
* Selects the agent sets of a box as a list in the order of selection. A new set goes to the end of the list, so the
* user changes the order by removing a set and adding it again.
*
* @param sets The named sets of the user, without the global set.
* @param value The ids of the selected sets, in the order of the merge.
* @param onChange Receives the new list of ids after each change.
* @param disabled Disables all controls, for example while a request runs.
* @param id The id of the select that adds a set, for a label.
*/
export function AgentSetPicker({
sets,
value,
onChange,
disabled = false,
id,
}: {
sets: AgentSetSummary[];
value: string[];
onChange: (ids: string[]) => void;
disabled?: boolean;
id?: string;
}) {
const selected = value
.map((setId) => sets.find((s) => s.id === setId))
.filter((s): s is AgentSetSummary => s !== undefined);
const available = sets.filter((s) => !value.includes(s.id));

return (
<div className="flex flex-col gap-2">
{selected.length === 0 ? (
<p className="text-sm text-muted-foreground">Global set only</p>
) : (
<ol className="flex flex-col gap-1">
{selected.map((s) => (
<li
key={s.id}
className="flex items-center gap-2 rounded-md border py-1 pr-1 pl-3 text-sm"
>
<span className="min-w-0 flex-1 truncate">{s.name}</span>
<Button
type="button"
variant="ghost"
size="icon"
aria-label={`Remove ${s.name}`}
disabled={disabled}
onClick={() => onChange(value.filter((setId) => setId !== s.id))}
>
<X />
</Button>
</li>
))}
</ol>
)}
{available.length > 0 ? (
// The empty value keeps the placeholder after each selection.
<Select value="" disabled={disabled} onValueChange={(setId) => onChange([...value, setId])}>
<SelectTrigger id={id} aria-label="Add an agent set" className="w-full">
<SelectValue placeholder="Add a set" />
</SelectTrigger>
<SelectContent>
{available.map((s) => (
<SelectItem key={s.id} value={s.id}>
{s.name}
</SelectItem>
))}
</SelectContent>
</Select>
) : null}
{selected.length > 1 ? (
<p className="text-xs text-muted-foreground">
A later set replaces skills and MCP servers with the same name from an earlier set.
</p>
) : null}
</div>
);
}
30 changes: 11 additions & 19 deletions dashboard/src/views/BoxCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type FormEvent, useEffect, useState } from 'react';
import { Link, useNavigate } from 'react-router';
import { AgentSetPicker } from '@/components/AgentSetPicker';
import { Notice } from '@/components/Notice';
import { ThreadOptions, useThreadOptions } from '@/components/ThreadOptions';
import { Button } from '@/components/ui/button';
Expand All @@ -17,9 +18,6 @@ import type { AgentSetSummary, EgressProfileSummary } from '../../../shared/type
import { api } from '../api.ts';
import { refresh } from '../stores/boxes.ts';

/** Picker value for no extra set. The form sends it as null. */
const NO_SET = 'none';

/** Form that creates a box and then opens its first thread. */
export function BoxCreate() {
const navigate = useNavigate();
Expand All @@ -33,7 +31,8 @@ export function BoxCreate() {
* Null while loading. The form hides the picker while the list is null or empty.
*/
const [agentSets, setAgentSets] = useState<AgentSetSummary[] | null>(null);
const [agentSet, setAgentSet] = useState(NO_SET);
/** The ids of the selected sets, in the order of the merge. */
const [selectedSets, setSelectedSets] = useState<string[]>([]);
/** The egress profiles. Null while loading. The form hides the select while null. */
const [profiles, setProfiles] = useState<EgressProfileSummary[] | null>(null);
/** The id of the selected profile. The empty string sends null, so the box uses the default profile. */
Expand Down Expand Up @@ -70,7 +69,7 @@ export function BoxCreate() {
try {
const created = await api.createBox({
name: name.trim(),
agentSet: agentSet === NO_SET ? null : agentSet,
agentSets: selectedSets,
egressProfile: profile === '' ? null : profile,
...(thread.value ? { thread: thread.value } : {}),
});
Expand Down Expand Up @@ -105,20 +104,13 @@ export function BoxCreate() {

{agentSets && agentSets.length > 0 ? (
<div className="flex flex-col gap-2">
<Label htmlFor="box-agent-set">Agent set</Label>
<Select value={agentSet} onValueChange={setAgentSet}>
<SelectTrigger id="box-agent-set" className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value={NO_SET}>Global set only</SelectItem>
{agentSets.map((s) => (
<SelectItem key={s.id} value={s.id}>
{s.name}
</SelectItem>
))}
</SelectContent>
</Select>
<Label htmlFor="box-agent-sets">Agent sets</Label>
<AgentSetPicker
id="box-agent-sets"
sets={agentSets}
value={selectedSets}
onChange={setSelectedSets}
/>
<p className="text-xs text-muted-foreground">
Merged over the global AGENTS.md and skills, which every box gets.{' '}
<Link to="/agents" className="underline hover:text-foreground">
Expand Down
50 changes: 47 additions & 3 deletions dashboard/src/views/BoxInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useEffect, useState } from 'react';
import { Link, useNavigate, useParams } from 'react-router';
import { AgentSetPicker } from '@/components/AgentSetPicker';
import { BackLink } from '@/components/BackLink';
import { boxBadges } from '@/components/BoxCard';
import { BoxWorkList } from '@/components/BoxWorkList';
Expand All @@ -19,7 +20,12 @@ import {
import { useUp } from '@/hooks/use-up';
import { pollWhileVisible } from '@/lib/poll';
import { shortSize } from '@/lib/rough';
import type { BoxDetail, EgressDenial, EgressProfileSummary } from '../../../shared/types.ts';
import type {
AgentSetSummary,
BoxDetail,
EgressDenial,
EgressProfileSummary,
} from '../../../shared/types.ts';
import { api } from '../api.ts';
import { refresh } from '../stores/boxes.ts';

Expand Down Expand Up @@ -56,6 +62,8 @@ export function BoxInfo() {
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
const [confirmDelete, setConfirmDelete] = useState(false);
/** The named agent sets, for the picker. Null while loading or when the request failed. */
const [agentSets, setAgentSets] = useState<AgentSetSummary[] | null>(null);
/** The egress profiles, for the select. Null while loading or when the request failed. */
const [profiles, setProfiles] = useState<EgressProfileSummary[] | null>(null);
/** The targets that the egress profile refused. Null while loading or when the request failed. */
Expand Down Expand Up @@ -87,6 +95,13 @@ export function BoxInfo() {
}, [load]);

useEffect(() => {
void (async () => {
try {
setAgentSets((await api.listAgentSets()).filter((s) => !s.global));
} catch {
// Without the list, the page shows the names of the sets without the picker.
}
})();
void (async () => {
try {
setProfiles(await api.listEgressProfiles());
Expand Down Expand Up @@ -173,8 +188,6 @@ export function BoxInfo() {
{box.runtimeDetails.map(([label, value]) => (
<Meta key={label} label={label} value={value} />
))}
{/* Every box gets the global set, so a box without a named set shows "global only". */}
<Meta label="Agent set" value={box.agentSetName ?? 'global only'} />
<Meta label="Last active" value={new Date(box.lastActiveAt).toLocaleString()} />
{/* Null before the first measurement. */}
<Meta
Expand All @@ -189,6 +202,37 @@ export function BoxInfo() {
</CardContent>
</Card>

<Card>
<CardHeader>
<CardTitle className="text-sm">Agent sets</CardTitle>
</CardHeader>
<CardContent>
{agentSets ? (
<div className="flex flex-col gap-2">
<AgentSetPicker
sets={agentSets}
value={box.agentSets.map((s) => s.id)}
disabled={busy}
onChange={(ids) => void act(() => api.setBoxAgentSets(id, ids))}
/>
<p className="text-xs text-muted-foreground">
A change applies at the next start of the box.{' '}
<Link to="/agents" className="underline hover:text-foreground">
Edit the sets
</Link>
.
</p>
</div>
) : (
<p className="text-sm">
{box.agentSets.length > 0
? box.agentSets.map((s) => s.name).join(', ')
: 'Global set only'}
</p>
)}
</CardContent>
</Card>

<Card>
<CardHeader>
<CardTitle className="text-sm">Egress</CardTitle>
Expand Down
Loading