Skip to content

Commit 5b194ba

Browse files
serodriguez68codex
andauthored
Choose Builderlab agent models at creation and in Settings (#1533)
Signed-off-by: sergior <[email protected]> Co-authored-by: Codex <[email protected]>
1 parent 20a778e commit 5b194ba

15 files changed

Lines changed: 1410 additions & 114 deletions

File tree

‎src/bundled/builderlab/README.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Create agents that Builderlab hosts for you, so they keep working even when Buzz
66

77
1. Go to **Settings → Plugins → Builderlab agents** and choose **Sign in with Builderlab**.
88
2. In **Agents**, choose **New agent** and pick **Builderlab (hosted)** as the **Harness**.
9-
3. Use the agent's **Instructions** tab to tell it what to do.
9+
3. Choose a model and reasoning effort, optionally add instructions, then create the agent.
10+
4. Edit instructions later in **Identity**, and model settings in **Settings**.
1011

1112
---
1213

@@ -67,6 +68,15 @@ The agent's Identity tab reads its current instructions from Builderlab and
6768
saves changes directly to the provider. Loading and saving use the same login;
6869
failed saves keep the draft, and switching accounts requires the original
6970
account before saving. Empty instructions can be saved to clear them.
71+
The Settings tab loads a separate model catalog from Builderlab. Choose a model
72+
and one of that model's reasoning efforts, then save the pair for new tasks.
73+
There is no default or fallback selection. Missing or unavailable saved choices
74+
show the server's setup status and require a supported pair. Changing the model
75+
clears the effort choice. Instructions and model settings save independently.
76+
Creation offers the same catalog choices and optional instructions. The provider
77+
registers and activates the agent before saving the settings together. Unfinished
78+
setup retains these values on this device so retry continues the same agent,
79+
including after a restart. Setup completes only once the settings save succeeds.
7080
Settings shows the fixed remote workspace and per-thread session behavior. Both
7181
tabs link to the configured Builderlab site for remote runtime management.
7282
Activity shows the turns the agent published to its owner while Buzz has been

‎src/bundled/builderlab/adapter-type/Create.test.tsx‎

Lines changed: 168 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,196 @@
22
import "@testing-library/jest-dom/vitest";
33
import { act, cleanup, render, screen } from "@testing-library/react";
44
import userEvent from "@testing-library/user-event";
5-
import { StrictMode } from "react";
6-
import { afterEach, expect, it } from "vitest";
5+
import { StrictMode, useState } from "react";
6+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
7+
import type { Host } from "../../../features/host/service";
8+
import { createAgentClient } from "../agents/client";
79
import { createOAuthSession } from "../oauth/session";
8-
import { deferred } from "../test-helpers";
910
import type { Credential } from "../oauth/browser";
10-
import { createCreatePanel } from "./Create";
11+
import { deferred } from "../test-helpers";
12+
import { createCreationFields, EMPTY_CREATION } from "./Create";
13+
14+
beforeEach(() =>
15+
vi.stubEnv("VITE_BUZZ_BUILDERLAB_URL", "https://builderlab.example"),
16+
);
17+
afterEach(() => {
18+
cleanup();
19+
vi.unstubAllEnvs();
20+
});
21+
const catalog = [
22+
{
23+
id: "one",
24+
display_name: "Model One",
25+
supported_reasoning_efforts: ["low", "high"],
26+
},
27+
{
28+
id: "two",
29+
display_name: "Model Two",
30+
supported_reasoning_efforts: ["none"],
31+
},
32+
];
33+
async function fixture(signedIn = true) {
34+
const acquire = vi.fn(async () => ({
35+
value: "credential",
36+
account: {
37+
subject: "account",
38+
39+
canUseRemoteAgents: true,
40+
},
41+
}));
42+
const session = createOAuthSession(acquire);
43+
if (signedIn) await session.signIn();
44+
let fail = false;
45+
const pending = deferred<void>();
46+
const request = vi.fn<Host["request"]>(async () => {
47+
await pending.promise;
48+
if (fail) throw new Error("offline");
49+
return {
50+
status: 200,
51+
headers: {},
52+
body: JSON.stringify({ models: catalog }),
53+
};
54+
});
55+
const client = createAgentClient(
56+
{ request, runCommand: vi.fn() },
57+
session,
58+
null,
59+
);
60+
const Fields = createCreationFields(client, session);
61+
let draft = { ...EMPTY_CREATION };
62+
function Form() {
63+
const [config, setConfig] = useState(draft);
64+
draft = config;
65+
return (
66+
<form onSubmit={(event) => event.preventDefault()}>
67+
<Fields config={config} onChange={setConfig} disabled={false} />
68+
</form>
69+
);
70+
}
71+
render(<Form />, { wrapper: StrictMode });
72+
return {
73+
session,
74+
acquire,
75+
request,
76+
pending,
77+
draft: () => draft,
78+
fail: (value: boolean) => {
79+
fail = value;
80+
},
81+
};
82+
}
83+
async function choose(label: string, value: string) {
84+
const user = userEvent.setup();
85+
await user.click(await screen.findByRole("combobox", { name: label }));
86+
await user.click(await screen.findByRole("option", { name: value }));
87+
}
88+
89+
it("loads the catalog and keeps instructions alongside explicit model and effort choices", async () => {
90+
const h = await fixture();
91+
expect(screen.getByRole("status")).toHaveTextContent("Loading models");
92+
await act(async () => h.pending.resolve());
93+
const model = await screen.findByRole("combobox", { name: "Model" });
94+
expect(model).toHaveTextContent("Choose a model");
95+
expect(
96+
screen.getByRole("combobox", { name: "Reasoning effort" }),
97+
).toBeDisabled();
98+
await userEvent
99+
.setup()
100+
.type(
101+
screen.getByRole("textbox", { name: "Instructions Optional" }),
102+
"Be precise.",
103+
);
104+
await choose("Model", "Model One");
105+
await choose("Reasoning effort", "high");
106+
await choose("Model", "Model Two");
107+
expect(h.draft().reasoningEffort).toBe("");
108+
expect(
109+
screen.getByRole("textbox", { name: "Instructions Optional" }),
110+
).toHaveValue("Be precise.");
111+
await choose("Reasoning effort", "none");
112+
expect(h.draft()).toEqual({
113+
instructions: "Be precise.",
114+
modelId: "two",
115+
reasoningEffort: "none",
116+
subject: "account",
117+
});
118+
expect(
119+
h.request.mock.calls.every(([input]) =>
120+
input.url.endsWith("/get-model-catalog"),
121+
),
122+
).toBe(true);
123+
});
124+
125+
it("retains instructions when catalog loading fails and is retried", async () => {
126+
const h = await fixture();
127+
h.fail(true);
128+
await userEvent
129+
.setup()
130+
.type(
131+
screen.getByRole("textbox", { name: "Instructions Optional" }),
132+
"Keep this.",
133+
);
134+
await act(async () => h.pending.resolve());
135+
const retry = await screen.findByRole("button", { name: "Retry models" });
136+
expect(screen.getByRole("alert")).toHaveTextContent(
137+
"Could not reach Builderlab",
138+
);
139+
h.fail(false);
140+
await userEvent.setup().click(retry);
141+
await screen.findByRole("combobox", { name: "Model" });
142+
expect(h.draft().instructions).toBe("Keep this.");
143+
expect(h.draft().modelId).toBe("");
144+
});
11145

12-
afterEach(cleanup);
146+
it("waits for explicit sign-in before loading the creation catalog", async () => {
147+
const h = await fixture(false);
148+
expect(h.acquire).not.toHaveBeenCalled();
149+
expect(h.request).not.toHaveBeenCalled();
150+
await act(async () => h.pending.resolve());
151+
await userEvent
152+
.setup()
153+
.click(screen.getByRole("button", { name: "Sign in with Builderlab" }));
154+
await screen.findByRole("combobox", { name: "Model" });
155+
expect(h.acquire).toHaveBeenCalledTimes(1);
156+
});
13157

14-
it("offers Cancel sign-in only while sign-in is pending, then restores the provider copy", async () => {
158+
it("can cancel a pending shared sign-in even while the creation form is disabled", async () => {
15159
const login = deferred<Credential>();
16160
let aborted = false;
17161
const session = createOAuthSession((signal) => {
18162
signal.addEventListener("abort", () => (aborted = true));
19163
return login.promise;
20164
});
21-
const Create = createCreatePanel(session);
22-
render(<Create config={{}} disabled={false} onChange={() => {}} />, {
23-
wrapper: StrictMode,
24-
});
25-
expect(screen.getByText(/Its provider keeps its key/)).toBeInTheDocument();
165+
const request = vi.fn<Host["request"]>();
166+
const client = createAgentClient(
167+
{ request, runCommand: vi.fn() },
168+
session,
169+
null,
170+
);
171+
const Create = createCreationFields(client, session);
172+
render(
173+
<Create config={{ ...EMPTY_CREATION }} disabled onChange={() => {}} />,
174+
{ wrapper: StrictMode },
175+
);
26176
expect(
27177
screen.queryByRole("button", { name: "Cancel sign-in" }),
28178
).not.toBeInTheDocument();
29-
30179
await act(async () => {
31180
void session.signIn();
32181
});
33182
expect(screen.getByRole("status")).toHaveTextContent(
34183
"Finish sign-in in your browser",
35184
);
36-
await userEvent
37-
.setup()
38-
.click(screen.getByRole("button", { name: "Cancel sign-in" }));
185+
const cancel = screen.getByRole("button", { name: "Cancel sign-in" });
186+
expect(cancel).toBeEnabled();
187+
await userEvent.setup().click(cancel);
39188
expect(aborted).toBe(true);
40189
expect(session.snapshot().status).toBe("signed-out");
41-
expect(screen.getByText(/Its provider keeps its key/)).toBeInTheDocument();
42190
expect(
43191
screen.queryByRole("button", { name: "Cancel sign-in" }),
44192
).not.toBeInTheDocument();
193+
expect(screen.getByRole("status")).toHaveTextContent(
194+
"Sign in to choose a model",
195+
);
196+
expect(request).not.toHaveBeenCalled();
45197
});

0 commit comments

Comments
 (0)