Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(dashboard): ask the server's flags before an organization's Services and Connectors
Petr Bauch8a325268c9cd
diff --git a/gateway/src/data/api.ts b/gateway/src/data/api.tsindex 61f3e404a..d953d80b9 100644--- a/gateway/src/data/api.ts+++ b/gateway/src/data/api.ts@@ -1420,6 +1420,17 @@ export interface OrganizationServices {services: OrganizationService[];}+interface FeatureFlagsResponse {+ flags: { key: string; enabled: boolean }[];+}++/** The deployment's feature flags, each on or off. Any signed-in caller may+ * read them; they decide which routes the server mounts. */+export async function fetchFeatureFlags(): Promise<Record<string, boolean>> {+ const { flags } = await jsonRequest<FeatureFlagsResponse>("/feature-flags", "GET");+ return Object.fromEntries(flags.map((flag) => [flag.key, flag.enabled]));+}+export async function fetchOrganizationServices(): Promise<OrganizationServices> {return jsonRequest<OrganizationServices>("/organizations/current/services", "GET");}diff --git a/gateway/src/pages/connector-apps/ConnectorAppsPage.tsx b/gateway/src/pages/connector-apps/ConnectorAppsPage.tsxindex fe7cf2de9..66c32333c 100644--- a/gateway/src/pages/connector-apps/ConnectorAppsPage.tsx+++ b/gateway/src/pages/connector-apps/ConnectorAppsPage.tsx@@ -26,23 +26,18 @@ function Heading({ publicUrl }: { publicUrl: string | null }) {);}-const NOT_MOUNTED = "not mounted";-/** Every app of `scope`, a card each, under `heading`. A 404 means the- * routes are not mounted, and shows `notEnabled`, or nothing when it is null. */+ * routes are not mounted, and shows `notEnabled`. */export function ConnectorAppsList({scope,notEnabled,heading: headingOf,}: {scope: ConnectorAppScope;- notEnabled: string | null;+ notEnabled: string;heading: (publicUrl: string | null) => ReactNode;}) {- const { data, loading, error, refetch } = useConnectorApps(- scope,- notEnabled ?? NOT_MOUNTED,- );+ const { data, loading, error, refetch } = useConnectorApps(scope, notEnabled);const [checkFailures, setCheckFailures] = useState<Record<string, string>>({});const [toast, setToast] = useState<string | null>(null);@@ -54,7 +49,6 @@ export function ConnectorAppsList({<CircularProgress /></>);- if (error === NOT_MOUNTED) return null;if (error !== null)return (<>diff --git a/gateway/src/pages/organization/OrganizationConnectorsSection.tsx b/gateway/src/pages/organization/OrganizationConnectorsSection.tsxindex c58c0cd7e..3597aa93f 100644--- a/gateway/src/pages/organization/OrganizationConnectorsSection.tsx+++ b/gateway/src/pages/organization/OrganizationConnectorsSection.tsx@@ -15,13 +15,17 @@ function Heading({ publicUrl }: { publicUrl: string | null }) {);}+/** What an org admin reads if the routes are missing all the same. */+const ORGANIZATION_APPS_NOT_ENABLED =+ "Organizations' own connector apps are not enabled on this server.";+/** The apps the organization's workspaces sign in through, for its admins.- * Shown only where the server lets organizations save their own. */+ * The page shows it only where the server lets organizations save their own. */export default function OrganizationConnectorsSection() {return (<ConnectorAppsListscope="organization"- notEnabled={null}+ notEnabled={ORGANIZATION_APPS_NOT_ENABLED}heading={(publicUrl) => <Heading publicUrl={publicUrl} />}/>);diff --git a/gateway/src/pages/organization/OrganizationPage.test.tsx b/gateway/src/pages/organization/OrganizationPage.test.tsxindex 85ccfa73f..df3c12e2a 100644--- a/gateway/src/pages/organization/OrganizationPage.test.tsx+++ b/gateway/src/pages/organization/OrganizationPage.test.tsx@@ -71,6 +71,14 @@ function signedInAs(current: Session) {return refresh;}+/** `GET /feature-flags`, with organizations' own apps on or off. */+const flags = (organizationApps: boolean) => ({+ flags: [+ { key: "service_connections", enabled: true },+ { key: "organization_connector_apps", enabled: organizationApps },+ ],+});+const workspace = (id: string, name: string) => ({id,slug: id,@@ -126,6 +134,8 @@ describe("OrganizationPage", () => {"GET /organizations/current/workspaces": [workspace("t1", "Acme")],"GET /organizations/current/members": [],"GET /organizations/current/audit-events": [],+ "GET /feature-flags": flags(true),+ "GET /organizations/current/services": { workspaces: 1, services: [] },"GET /organizations/current/connector-apps": {public_url: "https://switch.example.test",apps: [@@ -150,7 +160,7 @@ describe("OrganizationPage", () => {expect(await screen.findByRole("heading", { name: "Connectors" })).toBeTruthy();expect(- screen.getByText(+ await screen.findByText("Your workspaces use the server's Airtable client. Add your organization's own to use that instead.",),).toBeTruthy();@@ -182,6 +192,8 @@ describe("OrganizationPage", () => {"GET /organizations/current/workspaces": [workspace("t1", "Acme")],"GET /organizations/current/members": [],"GET /organizations/current/audit-events": [],+ "GET /feature-flags": flags(true),+ "GET /organizations/current/connector-apps": { public_url: null, apps: [] },"GET /organizations/current/services": { workspaces: 3, services: [github] },"PUT /organizations/current/services/github": { warning: null },});@@ -204,7 +216,7 @@ describe("OrganizationPage", () => {);});- it("shows no connectors where the server keeps them to itself", async () => {+ it("neither shows nor asks for services or connectors where the server keeps them to itself", async () => {signedInAs(session("org_admin", true));const fetchMock = answer({"GET /organizations/current": { id: "o1", slug: "acme", name: "Acme Inc", role: "org_admin" },@@ -212,22 +224,37 @@ describe("OrganizationPage", () => {"GET /organizations/current/members": [],"GET /organizations/current/audit-events": [],"GET /organizations/current/issues": [],+ "GET /feature-flags": flags(false),});render(<OrganizationPage />);expect(await screen.findByRole("heading", { name: "Members" })).toBeTruthy();await waitFor(() =>- expect(fetchMock).toHaveBeenCalledWith(- "/gateway/organizations/current/connector-apps",- expect.anything(),- ),+ expect(fetchMock).toHaveBeenCalledWith("/gateway/feature-flags", expect.anything()),);await waitFor(() => expect(screen.queryByRole("progressbar")).toBeNull());expect(screen.queryByRole("heading", { name: "Connectors" })).toBeNull();+ expect(screen.queryByRole("heading", { name: "Services" })).toBeNull();+ const asked = fetchMock.mock.calls.map(([input]) => String(input));+ expect(asked.filter((url) => /current\/(services|connector-apps)/.test(url))).toEqual([]);expect(screen.queryByText(/unmocked/)).toBeNull();});+ it("asks a member nothing about the server's flags", async () => {+ signedInAs(session("member", false));+ const fetchMock = answer({+ "GET /organizations/current": { id: "o1", slug: "acme", name: "Acme Inc", role: "member" },+ "GET /organizations/current/workspaces": [workspace("t1", "Acme")],+ });++ render(<OrganizationPage />);++ expect(await screen.findByText("Acme (current)")).toBeTruthy();+ const asked = fetchMock.mock.calls.map(([input]) => String(input));+ expect(asked.filter((url) => url.includes("feature-flags"))).toEqual([]);+ });+it("shows what a demotion could not revoke at a vendor", async () => {signedInAs(session("org_admin", true));const bob = {diff --git a/gateway/src/pages/organization/OrganizationPage.tsx b/gateway/src/pages/organization/OrganizationPage.tsxindex 3cb33ffbe..f11ffa468 100644--- a/gateway/src/pages/organization/OrganizationPage.tsx+++ b/gateway/src/pages/organization/OrganizationPage.tsx@@ -1,7 +1,7 @@import { Alert, Box, CircularProgress, Stack, Typography } from "@mui/material";import { useCallback, useState } from "react";import { useAuth } from "../../data/AuthContext";-import { fetchCurrentOrganization } from "../../data/api";+import { fetchCurrentOrganization, fetchFeatureFlags } from "../../data/api";import { administersOrganization } from "../../data/sessionState";import { useLoad } from "../workspace/useLoad";import OrganizationAuditSection from "./OrganizationAuditSection";@@ -18,6 +18,17 @@ export default function OrganizationPage() {const { session } = useAuth();const load = useCallback(() => fetchCurrentOrganization(), []);const { data: organization, error } = useLoad(load);+ const isAdmin = session ? administersOrganization(session) : false;+ // Only an org admin sees the sections the flags decide, so only they ask.+ const loadFlags = useCallback(+ () => (isAdmin ? fetchFeatureFlags() : Promise.resolve(null)),+ [isAdmin],+ );+ const { data: flags } = useLoad(loadFlags);+ // The server mounts the routes behind Services and Connectors only with+ // both flags on; asking a server without them would only be refused.+ const organizationApps =+ flags?.service_connections === true && flags?.organization_connector_apps === true;// A change to the members can make an issue or settle one; the notice is// read again, from scratch, after each.const [membersChanged, setMembersChanged] = useState(0);@@ -27,7 +38,6 @@ export default function OrganizationPage() {if (tenant.organization_id === null) {return <Alert severity="info">This workspace belongs to no organization.</Alert>;}- const isAdmin = administersOrganization(session);return (<Box>@@ -57,8 +67,8 @@ export default function OrganizationPage() {onChanged={onMembersChanged}/>)}- {isAdmin && <OrganizationServicesSection />}- {isAdmin && <OrganizationConnectorsSection />}+ {isAdmin && organizationApps && <OrganizationServicesSection />}+ {isAdmin && organizationApps && <OrganizationConnectorsSection />}{isAdmin && <OrganizationAuditSection />}</Stack></Box>diff --git a/gateway/src/pages/organization/OrganizationServicesSection.tsx b/gateway/src/pages/organization/OrganizationServicesSection.tsxindex d183b4349..2970589aa 100644--- a/gateway/src/pages/organization/OrganizationServicesSection.tsx+++ b/gateway/src/pages/organization/OrganizationServicesSection.tsx@@ -55,10 +55,10 @@ export function reachText(service: OrganizationService, workspaces: number): str/** Each catalog service, on or off for every workspace in the organization,* and whether workspace admins may change it. Unlocked, the setting is the* default each workspace may override; locked, it is out of their reach.- * Shown only where the server lets organizations have this say. */+ * The page shows it only where the server lets organizations have this say. */export default function OrganizationServicesSection() {const load = useCallback(() => fetchOrganizationServices(), []);- const { data, error, errorStatus, loading, refetch } = useLoad(load);+ const { data, error, loading, refetch } = useLoad(load);const [busy, setBusy] = useState<string | null>(null);const [actionError, setActionError] = useState<string | null>(null);const [actionWarning, setActionWarning] = useState<string | null>(null);@@ -81,9 +81,6 @@ export default function OrganizationServicesSection() {[refetch],);- // The routes are mounted only where organizations have this say.- if (errorStatus === 404) return null;-const choose = (service: OrganizationService, choice: Choice) =>act(service.slug, () =>choice === "none"