Skip to content

Commit c2370ea

Browse files
klopez4212mahantiTerpwesbillmanCarl
authored
Add Marketplace tab and shared agent profile panels (#1411)
Signed-off-by: klopez4212 <[email protected]> Signed-off-by: Wes <[email protected]> Co-authored-by: Arjun Mahanti <[email protected]> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Co-authored-by: Wes <[email protected]> Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent cf81f71 commit c2370ea

17 files changed

Lines changed: 784 additions & 239 deletions
Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
/* A shared agent's details: who it is, then its instructions. */
22
.details {
3-
display: flex;
4-
flex-direction: column;
5-
gap: var(--space-5);
6-
min-width: 0;
7-
}
8-
.heading {
9-
display: flex;
10-
flex-direction: column;
11-
align-items: flex-start;
12-
gap: var(--space-5);
133
min-width: 0;
14-
overflow-wrap: anywhere;
15-
}
16-
.portrait {
17-
display: block;
18-
flex-shrink: 0;
19-
width: var(--space-16);
20-
height: var(--space-16);
21-
}
22-
.byline {
23-
display: flex;
24-
align-items: center;
25-
flex-wrap: wrap;
26-
gap: var(--space-1);
274
}
285
.fact {
296
display: inline-flex;
@@ -33,18 +10,32 @@
3310
min-width: 0;
3411
}
3512
.instructions {
36-
max-height: 22rem;
37-
overflow: auto;
13+
position: relative;
3814
padding: var(--space-4);
3915
border-radius: var(--radius-container);
4016
background: var(--surface-inset);
4117
white-space: pre-wrap;
4218
overflow-wrap: anywhere;
4319
}
44-
.import {
20+
21+
.instructions[data-collapsed] {
22+
max-height: calc(var(--space-8) * 4);
23+
overflow: hidden;
24+
}
25+
26+
.instructions[data-collapsed]::after {
27+
content: "";
28+
position: absolute;
29+
inset-inline: 0;
30+
bottom: 0;
31+
height: calc(var(--space-5) * 2);
32+
background: linear-gradient(to bottom, transparent, var(--surface-inset));
33+
pointer-events: none;
34+
}
35+
.instructionsAction {
4536
display: flex;
46-
align-items: center;
47-
justify-content: flex-end;
48-
gap: var(--space-3);
49-
min-width: 0;
37+
margin-top: var(--space-3);
38+
}
39+
.instructionsAction > * {
40+
flex: 1;
5041
}

‎src/bundled/agents/AgentBrowse.test.tsx‎

Lines changed: 118 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,52 @@ import type {
2121
RegisteredAgentType,
2222
} from "../../features/agents/service";
2323
import type { Profile } from "../../features/relay/contracts";
24-
import { AgentBrowse } from "./AgentBrowse";
24+
import { useState } from "react";
25+
import {
26+
AgentBrowse as Catalog,
27+
SharedAgentPanel,
28+
type SharedAgentSelection,
29+
} from "./AgentBrowse";
30+
import { PanelWorkspace } from "../../features/panels/PanelWorkspace";
31+
function AgentBrowse(
32+
props: ReturnType<typeof importing> & { relay: RelayData },
33+
) {
34+
const [selection, setSelection] = useState<SharedAgentSelection>();
35+
return (
36+
<>
37+
<Catalog
38+
relay={props.relay}
39+
selectedId={selection?.agent.id}
40+
onSelect={setSelection}
41+
/>
42+
{selection && (
43+
<section aria-label="Shared agent profile">
44+
<PanelWorkspace
45+
value={selection.agent.id}
46+
select={() => {}}
47+
items={[
48+
{
49+
id: selection.agent.id,
50+
label: selection.agent.name,
51+
close: () => setSelection(undefined),
52+
content: <SharedAgentPanel selection={selection} {...props} />,
53+
},
54+
]}
55+
/>
56+
</section>
57+
)}
58+
</>
59+
);
60+
}
2561

2662
afterEach(cleanup);
2763

28-
const echo = { key: "test/echo", title: "Echo" } as RegisteredAgentType;
64+
const echo = {
65+
key: "test/echo",
66+
title: "Echo",
67+
defaults: () => ({ config: { model: "default" } }),
68+
importShared: (source: { model: string }) => ({ model: source.model }),
69+
} as RegisteredAgentType;
2970
const notes = { key: "test/notes", title: "Notes" } as RegisteredAgentType;
3071
/** Import's props: one type, and an `agents` whose `port` resolves. */
3172
const importing = (types: readonly RegisteredAgentType[] = [echo]) => ({
@@ -84,13 +125,13 @@ it("browses shared agents and opens read-only details", async () => {
84125
expect(read).toHaveBeenCalledWith([{ kinds: [30175], limit: 200 }], {
85126
signal: expect.any(AbortSignal),
86127
});
87-
fireEvent.click(screen.getByRole("button", { name: "View details" }));
128+
fireEvent.click(screen.getByRole("button", { name: "Shared helper" }));
88129
expect(
89-
await screen.findByRole("dialog", { name: "Shared helper" }),
130+
await screen.findByRole("region", { name: "Shared agent profile" }),
90131
).toBeVisible();
91132
expect(screen.getByText("Help with tasks.")).toBeVisible();
92133
// Unknown to the profile directory, the sharer shows as their short key.
93-
expect(screen.getByText("By")).toBeVisible();
134+
expect(screen.getByText("Shared by")).toBeVisible();
94135
expect(screen.getByText(/^npub…/)).toBeVisible();
95136
});
96137

@@ -173,9 +214,7 @@ it("shrinks over-budget pages and preserves Load more and explicit retry", async
173214
fireEvent.click(screen.getByRole("button", { name: "Load more" }));
174215
fireEvent.click(await screen.findByRole("button", { name: "Try again" }));
175216
expect(await screen.findByText("Helper 100")).toBeVisible();
176-
expect(
177-
screen.getAllByRole("button", { name: "View details" }),
178-
).toHaveLength(2);
217+
expect(screen.getAllByRole("button", { name: /^Helper / })).toHaveLength(2);
179218
expect(
180219
screen.queryByRole("button", { name: "Load more" }),
181220
).not.toBeInTheDocument();
@@ -242,12 +281,14 @@ it("names the sharer by their profile, with their key on hover", async () => {
242281
const read = vi.fn().mockResolvedValue([shared]);
243282
const profiles = directory({ [shared.pubkey]: { name: "Cora" } });
244283
render(<AgentBrowse relay={community(read, profiles)} {...importing()} />);
245-
fireEvent.click(await screen.findByRole("button", { name: "View details" }));
246-
const dialog = await screen.findByRole("dialog", { name: "Shared helper" });
284+
fireEvent.click(await screen.findByRole("button", { name: "Shared helper" }));
285+
const dialog = await screen.findByRole("region", {
286+
name: "Shared agent profile",
287+
});
247288
expect(within(dialog).getByText("Cora")).toBeVisible();
248289
expect(within(dialog).queryByText(/^npub…/)).not.toBeInTheDocument();
249290
expect(profiles.ensure).toHaveBeenCalledWith([shared.pubkey]);
250-
expect(within(dialog).getByText("Model: test-model")).toBeVisible();
291+
expect(within(dialog).getByText("test-model")).toBeVisible();
251292
});
252293

253294
it("imports a shared agent through the import path, then hands back", async () => {
@@ -264,38 +305,95 @@ it("imports a shared agent through the import path, then hands back", async () =
264305
]);
265306
const props = importing();
266307
render(<AgentBrowse relay={community(read)} {...props} />);
267-
fireEvent.click(await screen.findByRole("button", { name: "View details" }));
268-
const dialog = await screen.findByRole("dialog", { name: "Shared helper" });
308+
fireEvent.click(await screen.findByRole("button", { name: "Shared helper" }));
309+
const dialog = await screen.findByRole("region", {
310+
name: "Shared agent profile",
311+
});
269312
expect(within(dialog).queryByLabelText("Import as")).not.toBeInTheDocument();
270313
fireEvent.click(within(dialog).getByRole("button", { name: "Import" }));
314+
const confirmation = screen.getByRole("dialog", {
315+
name: "Import Shared helper",
316+
});
317+
expect(within(confirmation).queryByRole("combobox")).not.toBeInTheDocument();
318+
expect(props.agents.port).not.toHaveBeenCalled();
319+
fireEvent.click(within(confirmation).getByRole("button", { name: "Import" }));
271320
await vi.waitFor(() => expect(props.onImported).toHaveBeenCalledOnce());
272321
expect(props.agents.port).toHaveBeenCalledExactlyOnceWith({
273322
source: "shared",
274323
type: "test/echo",
275324
name: "Shared helper",
276325
picture: "https://example.test/helper.png",
277326
instructions: "Help with tasks.",
327+
config: { model: "test-model" },
278328
});
279329
});
280330

281-
it("imports as the chosen type, and keeps the dialog open with the error when it fails", async () => {
331+
it("imports as the chosen type, and keeps the panel open with the error when it fails", async () => {
282332
const read = vi.fn().mockResolvedValue([shared]);
283333
const props = importing([echo, notes]);
284334
props.agents.port.mockRejectedValueOnce(
285335
new Error("Connect to a community first"),
286336
);
287337
render(<AgentBrowse relay={community(read)} {...props} />);
288-
fireEvent.click(await screen.findByRole("button", { name: "View details" }));
289-
const dialog = await screen.findByRole("dialog", { name: "Shared helper" });
290-
expect(
291-
within(dialog).getByRole("combobox", { name: "Import as" }),
292-
).toBeVisible();
338+
fireEvent.click(await screen.findByRole("button", { name: "Shared helper" }));
339+
const dialog = await screen.findByRole("region", {
340+
name: "Shared agent profile",
341+
});
293342
fireEvent.click(within(dialog).getByRole("button", { name: "Import" }));
294-
expect(await within(dialog).findByRole("alert")).toHaveTextContent(
343+
const confirmation = screen.getByRole("dialog", {
344+
name: "Import Shared helper",
345+
});
346+
fireEvent.click(
347+
within(confirmation).getByRole("button", { name: "Change settings" }),
348+
);
349+
expect(
350+
within(confirmation).getByRole("combobox", { name: "Import as" }),
351+
).toHaveFocus();
352+
fireEvent.click(within(confirmation).getByRole("button", { name: "Import" }));
353+
expect(await within(confirmation).findByRole("alert")).toHaveTextContent(
295354
"Connect to a community first",
296355
);
297356
expect(props.onImported).not.toHaveBeenCalled();
298357
expect(props.agents.port).toHaveBeenCalledWith(
299358
expect.objectContaining({ source: "shared", type: "test/echo" }),
300359
);
301360
});
361+
362+
it("does not silently replace an unavailable shared runtime", async () => {
363+
const read = vi.fn().mockResolvedValue([shared]);
364+
const props = importing([{ ...echo, importShared: () => undefined }]);
365+
render(<AgentBrowse relay={community(read)} {...props} />);
366+
fireEvent.click(await screen.findByRole("button", { name: "Shared helper" }));
367+
fireEvent.click(screen.getByRole("button", { name: "Import" }));
368+
const dialog = screen.getByRole("dialog", { name: "Import Shared helper" });
369+
expect(within(dialog).getByRole("button", { name: "Import" })).toBeDisabled();
370+
expect(
371+
within(dialog).getByRole("combobox", { name: "Import as" }),
372+
).toBeVisible();
373+
expect(props.agents.port).not.toHaveBeenCalled();
374+
});
375+
376+
it("collapses long instructions and expands them on request", async () => {
377+
const read = vi.fn().mockResolvedValue([
378+
{
379+
...shared,
380+
content: JSON.stringify({
381+
display_name: "Shared helper",
382+
system_prompt: "Long instructions. ".repeat(100),
383+
}),
384+
},
385+
]);
386+
render(<AgentBrowse relay={community(read)} {...importing()} />);
387+
fireEvent.click(await screen.findByRole("button", { name: "Shared helper" }));
388+
expect(screen.getByRole("region", { name: "Instructions" })).toHaveAttribute(
389+
"data-collapsed",
390+
);
391+
fireEvent.click(screen.getByRole("button", { name: "See more" }));
392+
expect(
393+
screen.getByRole("region", { name: "Instructions" }),
394+
).not.toHaveAttribute("data-collapsed");
395+
expect(screen.getByRole("button", { name: "See less" })).toHaveAttribute(
396+
"aria-expanded",
397+
"true",
398+
);
399+
});

0 commit comments

Comments
 (0)