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
45 changes: 40 additions & 5 deletions app/src/components/agents/new-bot-sheet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
OPENBOT_HARNESS_NAME,
reachedThroughMastra,
summaryFor,
WEB_HARNESSES,
} from "@openbot/shared/harnesses";
Expand Down Expand Up @@ -124,8 +125,9 @@ type Step = (typeof STEPS)[number];
/**
* Where the Bot runs: on this deployment, or behind a framework somebody hosts.
*
* The framework is kept for its connection instructions and default role description. Every framework is reached the same way and stored the same way — an AG-UI address —
* so the server never hears which was picked.
* The framework is kept for its connection instructions and default role description, and sent with
* the create. Every framework but Mastra is reached the same way, at an AG-UI address. A Mastra
* server is reached through Mastra's own API, which the server picks from the framework sent.
*/
export type Runtime =
| { kind: "builtin" }
Expand Down Expand Up @@ -368,6 +370,25 @@ function NewBotFlow({ onCreated }: { onCreated: (agentId: string) => void }) {
return;
}
setUnreachable(undefined);
/*
* A Mastra server has no AG-UI route, so the AG-UI test could only fail against it. The create
* names the framework and the server proves the address against Mastra's own API before it saves
* anything. What it refused with is shown under the address, as a failed test is.
*/
if (runtime?.kind === "managed" && reachedThroughMastra(runtime.harness)) {
try {
await create(runtime);
} catch (error) {
createAgent.reset();
setUnreachable(
error instanceof Error && error.message
? error.message
: MASTRA_UNREACHABLE,
);
focusAddress();
}
return;
}
setChecking(true);
const verdict = await testAgentConnection(endpoint.trim(), key).finally(
() => setChecking(false),
Expand Down Expand Up @@ -565,6 +586,10 @@ function NewBotFlow({ onCreated }: { onCreated: (agentId: string) => void }) {
);
}

/** Said when a Mastra create failed without a sentence of the server's own. */
export const MASTRA_UNREACHABLE =
"Couldn't reach a Mastra server at that address.";

/** How long the created view holds before handing over to the new Bot's page. */
const CREATED_BEAT_MS = 1600;
/** Shorter with reduced motion: nothing is moving, so the pause is only long enough to read. */
Expand Down Expand Up @@ -993,8 +1018,8 @@ export function RuntimeStep({
* The address of an agent somebody else runs, and the key it sits behind if it has one.
*
* The framework picked on the step before is named at the top so the person can see what they are
* connecting, but nothing below differs by framework: every one of them is an AG-UI address and is
* stored the same way.
* connecting. Nothing below differs by framework but Mastra's: every other one is an AG-UI address,
* and a Mastra one is the address of the Mastra server itself, so its example and its hint say so.
*
* The address takes focus on arrival rather than the heading, as the name does on the first step: it
* is the one thing this step asks for, and its label says what it is.
Expand All @@ -1020,6 +1045,7 @@ export function EndpointStep({
onKey: (value: string) => void;
}) {
const chosen = WEB_HARNESSES.find((entry) => entry.id === harness);
const mastra = reachedThroughMastra(harness);

return (
<div className="flex flex-col gap-6">
Expand All @@ -1045,14 +1071,23 @@ export function EndpointStep({
id="new-bot-endpoint"
inputMode="url"
onChange={(event) => onEndpoint(event.target.value)}
placeholder="https://your-agent.example.com/ag-ui"
placeholder={
mastra
? "https://your-mastra-server.example.com"
: "https://your-agent.example.com/ag-ui"
}
value={endpoint}
/>
{endpointError ? (
<FieldError
className="text-pretty"
errors={[{ message: endpointError }]}
/>
) : mastra ? (
<FieldDescription>
Give the address of your Mastra server. It needs to run one agent,
and OpenBot's server has to be able to reach it.
</FieldDescription>
) : (
<FieldDescription>
Any agent that speaks AG-UI works. OpenBot connects to it, so it
Expand Down
22 changes: 20 additions & 2 deletions app/src/components/bot-agents/agent-sheet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { WEB_HARNESSES } from "@openbot/shared/harnesses";
import {
HARNESSES,
reachedThroughMastra,
WEB_HARNESSES,
} from "@openbot/shared/harnesses";
import { IconLock, IconPlus, IconUsers, IconX } from "@tabler/icons-react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useState } from "react";
Expand Down Expand Up @@ -188,6 +192,19 @@ function AgentFlow({
description: skill.description.trim(),
}));

/**
* Whether this agent is a Mastra server: the framework picked, or for one being changed, the one it
* was added with. A Mastra server has no AG-UI route, so the server proves its address against
* Mastra's own API when it is saved, and the AG-UI test is not run.
*/
const mastra = editing
? HARNESSES.some(
(harness) =>
reachedThroughMastra(harness.id) &&
harness.name === editing.framework,
)
: runtime?.kind === "managed" && reachedThroughMastra(runtime.harness);

/** Dial the address from the server before it is saved, as New Bot does. */
const reachable = async (): Promise<boolean> => {
if (endpointIssue) {
Expand All @@ -196,6 +213,7 @@ function AgentFlow({
return false;
}
setUnreachable(undefined);
if (mastra) return true;
setChecking(true);
const verdict = await testAgentConnection(endpoint.trim(), key).finally(
() => setChecking(false),
Expand Down Expand Up @@ -354,7 +372,7 @@ function AgentFlow({
<EndpointStep
endpoint={endpoint}
endpointError={tried ? endpointIssue : unreachable}
harness={null}
harness={mastra ? "mastra" : null}
onEndpoint={(value) => {
setEndpoint(value);
setTried(false);
Expand Down
63 changes: 63 additions & 0 deletions app/tests/new-bot-sheet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ let given: string[] = [];
/** Every app that is turned on, as listApps lists them, and every path the sheet asked for. */
let servers: TodayServer[] = [];
let requested: string[] = [];
/** A create the server refuses with this sentence, as it refuses an address it couldn't reach. */
let createRefusal: string | undefined;

beforeEach(() => {
createRefusal = undefined;
builtInAvailable = true;
isolationAvailable = true;
mayIsolate = true;
Expand Down Expand Up @@ -149,6 +152,21 @@ beforeEach(() => {
: connectionTestResponse(verdict);
}
if (path === BOTS_PATH && init?.method === "POST") {
if (createRefusal) {
return Response.json(
{
type: "about:blank",
title: "Bad Request",
status: 400,
code: "VALIDATION_ERROR",
detail: createRefusal,
},
{
status: 400,
headers: { "content-type": "application/problem+json" },
},
);
}
creates.push(body);
return Response.json({ bot: { id: "agent_new" } }, { status: 201 });
}
Expand Down Expand Up @@ -643,6 +661,51 @@ test("team: the sheet offers only the apps the person can give, ticked", async (
expect(requested.filter((path) => path.startsWith(APPS_PATH))).toEqual([]);
});

/**
* Mastra is offered beside the others, with its mark, and picking it connects a Mastra server.
*
* A Mastra server has no AG-UI route, so the AG-UI test can only fail against one. The create carries
* the framework instead, and the server proves the address against Mastra's own API before it saves
* anything. What it refused with is shown under the address, as a failed test is.
*/
test("Mastra is offered with its mark, and picking it connects a Mastra server", async () => {
const { view, user } = await customFlow();
const mastra = view.getByRole("button", { name: /^Mastra/ });
const mark = mastra.querySelector("img[data-mark='Mastra']");
expect(mark?.getAttribute("src")).toBe("data:image/svg+xml,mastra");

await user.click(mastra);
expect(view.getByText("Mastra")).toBeTruthy();
await user.type(
await view.findByLabelText("Agent address"),
"https://mastra.example.com",
);
await user.click(view.getByRole("button", { name: "Create Bot" }));
await view.findByText("Expense Review is ready");
expect(tests).toEqual([]);
expect(creates[0]).toMatchObject({
endpoint: "https://mastra.example.com",
title: "Powered by Mastra",
harness: "mastra",
});
});

test("an address the server could not reach as a Mastra server says why, under the address", async () => {
const refusal =
"Couldn't reach a Mastra server at that address. It runs no agents.";
const { view, user } = await customFlow();
await user.click(view.getByRole("button", { name: /^Mastra/ }));
await user.type(
await view.findByLabelText("Agent address"),
"https://mastra.example.com",
);
createRefusal = refusal;
await user.click(view.getByRole("button", { name: "Create Bot" }));
expect(await view.findByText(refusal)).toBeTruthy();
expect(view.getAllByText(refusal)).toHaveLength(1);
expect(view.queryByText("Expense Review is ready")).toBeNull();
});

test("the LangGraph harness is offered as LangChain, the name people know it by", async () => {
const { view } = await customFlow();
const framework = view.getByRole("button", { name: /^LangChain/ });
Expand Down
2 changes: 1 addition & 1 deletion shared/harnesses.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"credential": "any-provider",
"maintainer": "partnership",
"mark": "mastra",
"webCreate": false
"webCreate": true
},
{
"id": "byo-url",
Expand Down
17 changes: 11 additions & 6 deletions shared/harnesses.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from "bun:test";
import {
HARNESSES,
reachedThroughMastra,
starterSubtitle,
WEB_HARNESSES,
withCurrentFrameworkNames,
Expand Down Expand Up @@ -39,6 +40,7 @@ test("leads the web list with the partners people look for, keeping the rest in
"strands",
"ag2",
"langroid",
"mastra",
"byo-url",
]);
});
Expand All @@ -51,13 +53,16 @@ test("the brands with no usable mark carry none", () => {
});

/*
* Mastra is the one row a plain AG-UI endpoint cannot stand in for: the server dials it through the
* `@ag-ui/mastra` bridge as `remote_mastra` and needs a roster id, neither of which the web create
* API can send. Offered there it would make a Bot that answers nothing.
* Mastra is the one row a plain AG-UI address cannot stand in for: the server dials it through the
* `@ag-ui/mastra` bridge. The web create names the framework, and the server proves a Mastra address
* against Mastra's own API and saves it as a Mastra Bot, so the dialog offers it with the rest.
*/
test("marks Mastra as something the web dialog must not offer", () => {
test("offers Mastra on the web, reached through Mastra's own API", () => {
const notOfferable = HARNESSES.filter((h) => !h.webCreate).map((h) => h.id);
expect(notOfferable).toEqual(["mastra"]);
expect(notOfferable).toEqual([]);
expect(
HARNESSES.filter((h) => reachedThroughMastra(h.id)).map((h) => h.id),
).toEqual(["mastra"]);
});

test("gives a web-specific summary only where the installer's is false here", () => {
Expand Down Expand Up @@ -91,7 +96,7 @@ test("CrewAI uses its expected image, health endpoint and port", () => {
* Antigravity only ever runs on Gemini: its README says the harness requires a Gemini API key
* wherever `base_url` points. `any-provider` would let a deployment holding only an OpenAI key
* install it and get a Bot that cannot answer — the shape of failure `webCreate: false` exists to
* stop for Mastra.
* stop.
*/
test("marks Antigravity as needing Google's key rather than any provider's", () => {
const antigravity = HARNESSES.find((h) => h.id === "antigravity");
Expand Down
22 changes: 17 additions & 5 deletions shared/harnesses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export type Harness = {
/** The file stem under `shared/marks/`, or null where no maintained set has one. */
mark: string | null;
/**
* Whether the web create API can actually make this row work.
* Whether the web create API can actually make this row work. A row it can't would make a Bot
* that appears, accepts a grant, and answers nothing, so the dialog leaves it out.
*
* False for Mastra alone: the server reaches it as `remote_mastra` through the `@ag-ui/mastra`
* bridge and needs a roster id to say which agent it means, and the create endpoint can send
* neither. Offered in the dialog it would make a Bot that appears, accepts a grant, and answers
* nothing.
* True for every row today. Mastra was the last to arrive: the server reaches it through the
* `@ag-ui/mastra` bridge, and a create that names it is now proved against Mastra's own API and
* saved as a Mastra Bot. See {@link reachedThroughMastra}.
*/
webCreate: boolean;
};
Expand Down Expand Up @@ -95,6 +95,18 @@ export const WEB_HARNESSES: readonly Harness[] = HARNESSES.filter(
(harness) => harness.webCreate,
).sort((a, b) => webRank(a) - webRank(b));

/**
* Whether OpenBot reaches an agent on this framework through Mastra's own API, by harness id.
*
* Every other framework serves an AG-UI route, and an address for one is tried with a real AG-UI run
* before it is saved. A Mastra server has no such route, so that run can only fail against it. The
* create names the framework instead, and the server proves the address by asking the Mastra server
* which agents it runs. It connects to a server that runs one.
*/
export function reachedThroughMastra(id: string | null | undefined): boolean {
return id === "mastra";
}

/** The sentence to draw on a web surface: the override where there is one, else the installer's. */
export function summaryFor(harness: Harness): string {
return harness.webSummary ?? harness.summary;
Expand Down
Loading