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
9 changes: 7 additions & 2 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32197,6 +32197,9 @@ components:
mobileConnections:
type: boolean
description: Whether an app's sign-in page can send the person back to OpenBot Mobile (returnTo mobile on connectApp), so the phone can connect their apps. Absent from a server older than it.
windowConnections:
type: boolean
description: Whether an app's sign-in page can send the person back to a page that closes the window it ran in (returnTo window on connectApp, connectSharedApp and authorizeAction), so OpenBot embedded in another app's page can open the sign-in in a window of its own and stay where it is. Absent from a server older than it.
durableHistory:
type: boolean
description: Whether conversations are kept between restarts.
Expand Down Expand Up @@ -36698,8 +36701,9 @@ components:
- apps
- desktop
- mobile
- window
default: connections
description: 'Which of OpenBot''s own pages the app sends the person back to: connections, the person''s own page for the app; apps, the app''s page for administrators; desktop, back to OpenBot Desktop; mobile, back to OpenBot Mobile, which then calls confirmConnection. Never an address. A client sends mobile only where getDeployment says mobileConnections.'
description: 'Which of OpenBot''s own pages the app sends the person back to: connections, the person''s own page for the app; apps, the app''s page for administrators; desktop, back to OpenBot Desktop; mobile, back to OpenBot Mobile, which then calls confirmConnection; window, a page that needs no sign-in and closes the window the sign-in ran in, for OpenBot embedded in another app''s page, which opened that window and reads the connection again once the person is back. Never an address. A client sends mobile only where getDeployment says mobileConnections, and window only where it says windowConnections.'
ConnectionValues:
type: object
description: What the person typed into the boxes a form answer asked for, by each box's name. Sent once to the app and never logged or kept here.
Expand Down Expand Up @@ -37128,8 +37132,9 @@ components:
enum:
- apps
- desktop
- window
default: apps
description: 'Which of OpenBot''s own pages the app sends the administrator back to: apps, the app''s page for administrators; desktop, back to OpenBot Desktop. Never an address.'
description: 'Which of OpenBot''s own pages the app sends the administrator back to: apps, the app''s page for administrators; desktop, back to OpenBot Desktop; window, a page that needs no sign-in and closes the window the sign-in ran in (see ConnectionReturnTo). Never an address. A client sends window only where getDeployment says windowConnections.'
ConnectSharedAppRequest:
type: object
additionalProperties: false
Expand Down
8 changes: 8 additions & 0 deletions api/openapi/admin-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,14 @@ components:
Whether an app's sign-in page can send the person back to OpenBot
Mobile (returnTo mobile on connectApp), so the phone can connect
their apps. Absent from a server older than it.
windowConnections:
type: boolean
description: >-
Whether an app's sign-in page can send the person back to a page
that closes the window it ran in (returnTo window on connectApp,
connectSharedApp and authorizeAction), so OpenBot embedded in
another app's page can open the sign-in in a window of its own and
stay where it is. Absent from a server older than it.
durableHistory:
type: boolean
description: Whether conversations are kept between restarts.
Expand Down
17 changes: 11 additions & 6 deletions api/openapi/connections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1215,23 +1215,28 @@ components:
URL-safe base64, the only form the cursor parameter accepts.
ConnectionReturnTo:
type: string
enum: [connections, apps, desktop, mobile]
enum: [connections, apps, desktop, mobile, window]
default: connections
description: >-
Which of OpenBot's own pages the app sends the person back to:
connections, the person's own page for the app; apps, the app's page
for administrators; desktop, back to OpenBot Desktop; mobile, back to
OpenBot Mobile, which then calls confirmConnection. Never an address.
A client sends mobile only where getDeployment says
mobileConnections.
OpenBot Mobile, which then calls confirmConnection; window, a page that
needs no sign-in and closes the window the sign-in ran in, for OpenBot
embedded in another app's page, which opened that window and reads the
connection again once the person is back. Never an address. A client
sends mobile only where getDeployment says mobileConnections, and
window only where it says windowConnections.
SharedConnectionReturnTo:
type: string
enum: [apps, desktop]
enum: [apps, desktop, window]
default: apps
description: >-
Which of OpenBot's own pages the app sends the administrator back to:
apps, the app's page for administrators; desktop, back to OpenBot
Desktop. Never an address.
Desktop; window, a page that needs no sign-in and closes the window the
sign-in ran in (see ConnectionReturnTo). Never an address. A client
sends window only where getDeployment says windowConnections.
ConnectionValues:
type: object
description: >-
Expand Down
52 changes: 37 additions & 15 deletions app/src/components/connections/add-server-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { currentUserQueryOptions } from "@/lib/auth/queries";
import { isOrganizationAdmin } from "@/lib/auth/roles";
import { deploymentCapabilitiesQueryOptions } from "@/lib/deployment/queries";
import { desktopShell } from "@/lib/desktop/shell";
import { embedConfig } from "@/lib/embed/config";
import { useConsentTab } from "@/lib/plugins/consent-tab";
import { useAppsOpen } from "@/lib/enterprise/apps-open";
import { setEnterpriseSettingMutationOptions } from "@/lib/enterprise/mutations";
import { enterpriseOverviewQueryOptions } from "@/lib/enterprise/queries";
Expand Down Expand Up @@ -106,6 +108,8 @@ export function AddServerPage({
const connect = useMutation(
connectAccountMutationOptions(admin ? "admin" : "settings"),
);
// Embedded in another app's page, the sign-in opens in a tab of its own (lib/plugins/consent-tab.ts).
const consent = useConsentTab();
const approve = useMutation(setEnterpriseSettingMutationOptions(queryClient));
const [refusal, setRefusal] = useState<Refusal | null>(null);
const [signingIn, setSigningIn] = useState<string | null>(null);
Expand All @@ -127,6 +131,7 @@ export function AddServerPage({
try {
start = await connect.mutateAsync(serverId);
} catch (thrown) {
consent.drop();
setSigningIn(null);
// Added, and the sign-in could not start: its page says so and offers Connect again.
setRefusal({
Expand All @@ -137,6 +142,7 @@ export function AddServerPage({
return;
}
if (!start || !("authorizationUrl" in start)) {
consent.drop();
await openServer(serverId);
return;
}
Expand All @@ -147,7 +153,13 @@ export function AddServerPage({
if (desktopShell()) {
await openServer(serverId);
}
window.location.href = start.authorizationUrl;
/*
* Embedded in another app's page, the sign-in opens in the tab claimed on the press, and this
* page goes on to the server's page, where the connection shows once the person is back
* (lib/plugins/consent-tab.ts).
*/
consent.go(start.authorizationUrl);
if (embedConfig()) await openServer(serverId);
}

async function submit(value: AddServerFormValues) {
Expand All @@ -161,13 +173,15 @@ export function AddServerPage({
...(tokenHeader ? { tokenHeader } : {}),
});
if (!outcome.added) {
consent.drop();
setRefusal(outcome);
return;
}
if (outcome.signIn) {
await signIn(outcome.server.id, outcome.server.title);
return;
}
consent.drop();
await added(outcome.server.id);
}

Expand All @@ -185,19 +199,25 @@ export function AddServerPage({

/** The admin's own step for a refused address: put it on the allowlist, then add it. */
async function approveAndAdd() {
const values = form.state.values;
const overview = await queryClient.fetchQuery(
enterpriseOverviewQueryOptions(),
);
const allowlist = overview.settings.mcpAllowlist;
await approve.mutateAsync({
key: "mcpAllowlist",
value: {
...allowlist,
servers: [...allowlist.servers, values.url.trim()],
},
});
await submit(values);
// Claimed on the press, as the sign-in may come after approving and adding; let go once settled.
consent.claim();
try {
const values = form.state.values;
const overview = await queryClient.fetchQuery(
enterpriseOverviewQueryOptions(),
);
const allowlist = overview.settings.mcpAllowlist;
await approve.mutateAsync({
key: "mcpAllowlist",
value: {
...allowlist,
servers: [...allowlist.servers, values.url.trim()],
},
});
await submit(values);
} finally {
consent.drop();
}
}

const busy = add.isPending || connect.isPending || approve.isPending;
Expand Down Expand Up @@ -230,7 +250,9 @@ export function AddServerPage({
noValidate
onSubmit={(event) => {
event.preventDefault();
void form.handleSubmit();
// Claimed on the press, as the sign-in may come after adding it; let go once it settles.
consent.claim();
void form.handleSubmit().finally(() => consent.drop());
}}
>
<PageCard
Expand Down
44 changes: 37 additions & 7 deletions app/src/components/manage/plugin-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import {
grantPlugin,
invalidatePlugins,
} from "@/lib/plugins/mutations";
import { useConsentTab } from "@/lib/plugins/consent-tab";
import {
brokeredConnectionDescription,
brokeredDisconnectNote,
Expand Down Expand Up @@ -467,10 +468,15 @@ export function PluginPage({
if (!listed) await navigate(paths.plugins());
},
});
// Embedded in another app's page, the sign-in opens in a tab of its own (lib/plugins/consent-tab.ts).
const consent = useConsentTab();
const connectSelf = useMutation({
// Back to this page afterwards, not to the personal settings screen.
...connectAccountMutationOptions("admin"),
...report,
onError: (thrown: Error) => {
consent.drop();
setError(thrown);
},
/*
* A full page navigation, not a fetch. The consent screen is the vendor's own and has to be
* shown to this person in their own browser; there is deliberately nothing here that could
Expand All @@ -491,13 +497,14 @@ export function PluginPage({
? start.authorizationUrl
: null;
if (authorizationUrl === null) {
consent.drop();
setError({
message:
"Couldn't start connecting, so nothing was connected. Try again, or check this app's setup if it keeps happening.",
});
return;
}
window.location.href = authorizationUrl;
consent.go(authorizationUrl);
},
});
/*
Expand Down Expand Up @@ -673,12 +680,26 @@ export function PluginPage({
setDialog("instance");
return;
}
if (await add()) await signInOnceAdded();
/*
* Claimed on the click, for an app reached as you: adding it and reading the catalogue come
* before the sign-in. Let go of where nothing opens one, a refusal or a failed read among them.
*/
if (auth === "user-oauth") consent.claim();
try {
if (await add()) await signInOnceAdded();
else consent.drop();
} catch (thrown) {
consent.drop();
throw thrown;
}
};

/** What is left once Connect has added it, for an app reached as you: the sign-in. */
const signInOnceAdded = async () => {
if (auth !== "user-oauth") return;
if (auth !== "user-oauth") {
consent.drop();
return;
}
const fresh = await queryClient.fetchQuery({
...appsQueryOptions(),
staleTime: 0,
Expand All @@ -689,6 +710,7 @@ export function PluginPage({
return;
}
// No client to consent against yet: its form, and the sign-in once it is saved.
consent.drop();
connectAfterClient.current = true;
setDialog("client");
};
Expand Down Expand Up @@ -1398,6 +1420,7 @@ export function PluginPage({
disabled={connectSelf.isPending}
onClick={() => {
setError(null);
consent.claim();
connectSelf.mutate(key);
}}
size="sm"
Expand Down Expand Up @@ -1426,6 +1449,7 @@ export function PluginPage({
disabled={connectSelf.isPending}
onClick={() => {
setError(null);
consent.claim();
connectSelf.mutate(key);
}}
size="sm"
Expand Down Expand Up @@ -1905,20 +1929,26 @@ export function PluginPage({
onClick={() => {
if (!server) {
// Opened by Connect: Save adds it, and an app reached as you goes on to its sign-in.
void add().then((added) =>
added ? signInOnceAdded() : undefined,
);
if (auth === "user-oauth") consent.claim();
void add()
.then((added) => {
if (added) return signInOnceAdded();
consent.drop();
})
.catch(() => consent.drop());
return;
}
if (dialog === "client") {
const thenConnect = connectAfterClient.current;
connectAfterClient.current = false;
if (thenConnect) consent.claim();
registerClient.mutate(
{ serverId: key, ...client },
{
onSuccess: () => {
if (thenConnect) connectSelf.mutate(key);
},
onError: () => consent.drop(),
},
);
}
Expand Down
Loading
Loading