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
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ jobs:
# next language the recognizer has, or says which language to add and where. The page's
# language and its names for languages are the engine's own. And the sidebar's edge, dragged in a
# window zoomed in, narrowing the sidebar, which never takes more than two-fifths of the window.
# In the image, as above: WebKit's
# And the terms on OpenBot Cloud: the gate holding a person at them from anywhere until they tick
# the box and agree, asking again when they change, and never shown where there are none, in the
# engine the Mac window draws with too. In the image, as above: WebKit's
# system packages are about 94 MB, which took nine minutes from the mirror on a slow day.
app-browser-webkit:
name: app (real browser, WebKit)
Expand All @@ -410,7 +412,7 @@ jobs:
--volume "$(command -v bun):/usr/local/bin/bun:ro" \
--env OPENBOT_APP_BROWSER=1 --env OPENBOT_APP_ENGINES=chromium,webkit \
"$PLAYWRIGHT_IMAGE" \
bun test app/tests/composer-dictation-language.test.tsx app/tests/sidebar-zoom-drag.test.tsx
bun test app/tests/composer-dictation-language.test.tsx app/tests/sidebar-zoom-drag.test.tsx app/tests/service-terms.test.tsx

# The desktop setup window's, for the same reason as the list above: the AI step's form holding
# still while the install behind it comes and goes. It bundles the window from the desktop's own
Expand Down
6 changes: 5 additions & 1 deletion app/src/components/onboarding/onboarding-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,12 @@ export function OnboardingFrame({
* On a phone, a step taller than the screen scrolls under the buttons rather than being cut
* at them: the fade above says there is more. On a desktop they sit at the bottom of the
* pane, under the row that takes up the space between them and the sentence.
*
* The 32px above the buttons on a phone is the fade's own height. Scrolled to the end there
* is nothing more, so the step's last line (Welcome's carousel dots) stops above the fade
* rather than half hidden in it.
*/}
<footer className="sticky bottom-0 col-start-1 row-start-5 bg-background px-4 pt-3 pb-[max(env(safe-area-inset-bottom),20px)] before:pointer-events-none before:absolute before:inset-x-0 before:-top-8 before:h-8 before:bg-linear-to-t before:from-background before:to-transparent lg:static lg:col-start-1 lg:row-start-4 lg:bg-transparent lg:px-10 lg:pt-8 lg:pb-10 lg:before:hidden">
<footer className="sticky bottom-0 col-start-1 row-start-5 mt-8 bg-background px-4 pt-3 pb-[max(env(safe-area-inset-bottom),20px)] before:pointer-events-none before:absolute before:inset-x-0 before:-top-8 before:h-8 before:bg-linear-to-t before:from-background before:to-transparent lg:static lg:col-start-1 lg:row-start-4 lg:mt-0 lg:bg-transparent lg:px-10 lg:pt-8 lg:pb-10 lg:before:hidden">
<div className="mx-auto flex w-full max-w-md flex-col gap-3 lg:mx-0 lg:max-w-none">
{notice}
{footnote ? (
Expand Down
34 changes: 34 additions & 0 deletions app/src/lib/service-terms/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { mutationOptions, type QueryClient } from "@tanstack/react-query";
import { acceptServiceTerms } from "@/lib/api/generated/people/people";
import { idempotencyKey, organizationId } from "@/lib/api/request";
import { type ServiceTerms, serviceTermsKeys } from "./queries";

const FALLBACK = "Couldn't save that you agreed. Try again.";

/**
* Agree to the terms, by the version the person was shown. A version that is no longer current is
* refused with SERVICE_TERMS_CHANGED, and the screen reads the terms again to show the new one.
*
* Either way the terms are read again, with `refetchType: "all"`: the gate reads them through
* `ensureQueryData`, which takes the cache as it finds it, so a stale "has to agree" would send the
* person straight back to the terms.
*/
export function acceptServiceTermsMutationOptions(queryClient: QueryClient) {
const invalidate = () =>
queryClient.invalidateQueries({
queryKey: serviceTermsKeys.all,
refetchType: "all",
});
return mutationOptions({
mutationFn: (version: string): Promise<ServiceTerms> =>
acceptServiceTerms(
organizationId(),
"me",
{ version },
{ "Idempotency-Key": idempotencyKey() },
{ fallback: FALLBACK },
),
onSuccess: invalidate,
onError: invalidate,
});
}
89 changes: 89 additions & 0 deletions app/src/lib/service-terms/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { type QueryClient, queryOptions } from "@tanstack/react-query";
import type { ServiceTerms } from "@/lib/api/generated/model";
import { getServiceTerms } from "@/lib/api/generated/people/people";
import { organizationId } from "@/lib/api/request";
import { ClientError } from "@/lib/client";

/**
* The terms of service a person agrees to before they use OpenBot (getServiceTerms): the version in
* force, the one they last agreed to, and the server's verdict on whether they have to agree now.
* Only OpenBot Cloud has terms. Everywhere else `current` is null and nobody is asked.
*/
export type { ServiceTerms };

export const serviceTermsKeys = {
all: ["service-terms"] as const,
mine: ["service-terms", "mine"] as const,
};

/** What an OpenBot with no terms answers, and what an OpenBot older than the question reads as. */
const NO_TERMS: ServiceTerms = {
current: null,
accepted: null,
acceptanceNeeded: false,
};

/**
* A 404 that says the person isn't there is about them, and fails like any other refusal. Any
* other 404 is an OpenBot older than this operation, which has no terms. An organization not found
* is read the same way: every other read in it fails too, and the app's own page for that answers
* the person (OrganizationBoundary), where the terms screen would only say it couldn't load.
*/
function olderOpenBot(error: unknown): boolean {
return (
error instanceof ClientError &&
error.status === 404 &&
error.code !== "PERSON_NOT_FOUND"
);
}

/** The person's own terms. An OpenBot without the operation answers as one with no terms. */
export function serviceTermsQueryOptions() {
return queryOptions({
queryKey: serviceTermsKeys.mine,
queryFn: async ({ signal }): Promise<ServiceTerms> => {
try {
return await getServiceTerms(organizationId(), "me", {
signal,
fallback: "Couldn't load the terms.",
});
} catch (error) {
if (olderOpenBot(error)) return NO_TERMS;
throw error;
}
},
});
}

/**
* Whether the person has to see the terms before anything else, for the signed-in gate: the
* server's verdict, never recomputed from the versions.
*
* A read that fails reads as yes. Letting somebody in because the question failed would let an
* OpenBot Cloud person use it without agreeing, so the terms screen takes them instead, says the
* read failed and offers Try again. An OpenBot with no terms answers no without failing, and an
* older one's 404 is read as no terms above, so neither ever shows the screen.
*/
export async function serviceTermsRequired(
queryClient: QueryClient,
): Promise<boolean> {
try {
return (await queryClient.ensureQueryData(serviceTermsQueryOptions()))
.acceptanceNeeded;
} catch {
return true;
}
}

/**
* Where the terms screen sends somebody once they agree: the address they were headed to, when it
* is a page of this app, else home. Only a path on this origin is followed, so the address can't
* send anybody off the app; the terms screen itself is never the destination.
*/
export function afterTerms(next: unknown): string {
if (typeof next !== "string") return "/";
if (!next.startsWith("/") || next.startsWith("//") || next.includes("\\"))
return "/";
if (next === "/terms" || next.startsWith("/terms?")) return "/";
return next;
}
21 changes: 21 additions & 0 deletions app/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Route as AuthedAppRouteImport } from './routes/_authed/_app'
import { Route as AuthedAdminRouteRouteImport } from './routes/_authed/admin/route'
import { Route as AuthedOnboardingRouteImport } from './routes/_authed/onboarding'
import { Route as AuthedSettingsRouteRouteImport } from './routes/_authed/settings/route'
import { Route as AuthedTermsRouteImport } from './routes/_authed/terms'
import { Route as AuthedAppIndexRouteImport } from './routes/_authed/_app/index'
import { Route as AuthedAppApprovalsRouteImport } from './routes/_authed/_app/approvals'
import { Route as AuthedAppBotRouteImport } from './routes/_authed/_app/bot'
Expand Down Expand Up @@ -172,6 +173,11 @@ const AuthedSettingsRouteRoute = AuthedSettingsRouteRouteImport.update({
path: '/settings',
getParentRoute: () => AuthedRoute,
} as any)
const AuthedTermsRoute = AuthedTermsRouteImport.update({
id: '/terms',
path: '/terms',
getParentRoute: () => AuthedRoute,
} as any)
const AuthedAppIndexRoute = AuthedAppIndexRouteImport.update({
id: '/',
path: '/',
Expand Down Expand Up @@ -816,6 +822,7 @@ export interface FileRoutesByFullPath {
'/admin': typeof AuthedAdminRouteRouteWithChildren
'/settings': typeof AuthedSettingsRouteRouteWithChildren
'/onboarding': typeof AuthedOnboardingRoute
'/terms': typeof AuthedTermsRoute
'/approvals': typeof AuthedAppApprovalsRoute
'/bot': typeof AuthedAppBotRoute
'/browser': typeof AuthedAppBrowserRoute
Expand Down Expand Up @@ -937,6 +944,7 @@ export interface FileRoutesByTo {
'/desktop-return': typeof DesktopReturnRoute
'/sign': typeof SignRoute
'/onboarding': typeof AuthedOnboardingRoute
'/terms': typeof AuthedTermsRoute
'/approvals': typeof AuthedAppApprovalsRoute
'/bot': typeof AuthedAppBotRoute
'/browser': typeof AuthedAppBrowserRoute
Expand Down Expand Up @@ -1062,6 +1070,7 @@ export interface FileRoutesById {
'/_authed/settings': typeof AuthedSettingsRouteRouteWithChildren
'/_authed/_app': typeof AuthedAppRouteWithChildren
'/_authed/onboarding': typeof AuthedOnboardingRoute
'/_authed/terms': typeof AuthedTermsRoute
'/_authed/_app/approvals': typeof AuthedAppApprovalsRoute
'/_authed/_app/bot': typeof AuthedAppBotRoute
'/_authed/_app/browser': typeof AuthedAppBrowserRoute
Expand Down Expand Up @@ -1189,6 +1198,7 @@ export interface FileRouteTypes {
| '/admin'
| '/settings'
| '/onboarding'
| '/terms'
| '/approvals'
| '/bot'
| '/browser'
Expand Down Expand Up @@ -1310,6 +1320,7 @@ export interface FileRouteTypes {
| '/desktop-return'
| '/sign'
| '/onboarding'
| '/terms'
| '/approvals'
| '/bot'
| '/browser'
Expand Down Expand Up @@ -1434,6 +1445,7 @@ export interface FileRouteTypes {
| '/_authed/settings'
| '/_authed/_app'
| '/_authed/onboarding'
| '/_authed/terms'
| '/_authed/_app/approvals'
| '/_authed/_app/bot'
| '/_authed/_app/browser'
Expand Down Expand Up @@ -1617,6 +1629,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AuthedSettingsRouteRouteImport
parentRoute: typeof AuthedRoute
}
'/_authed/terms': {
id: '/_authed/terms'
path: '/terms'
fullPath: '/terms'
preLoaderRoute: typeof AuthedTermsRouteImport
parentRoute: typeof AuthedRoute
}
'/_authed/_app/': {
id: '/_authed/_app/'
path: '/'
Expand Down Expand Up @@ -2718,6 +2737,7 @@ interface AuthedRouteChildren {
AuthedSettingsRouteRoute: typeof AuthedSettingsRouteRouteWithChildren
AuthedAppRoute: typeof AuthedAppRouteWithChildren
AuthedOnboardingRoute: typeof AuthedOnboardingRoute
AuthedTermsRoute: typeof AuthedTermsRoute
AuthedSignInRequestIdRoute: typeof AuthedSignInRequestIdRoute
}

Expand All @@ -2726,6 +2746,7 @@ const AuthedRouteChildren: AuthedRouteChildren = {
AuthedSettingsRouteRoute: AuthedSettingsRouteRouteWithChildren,
AuthedAppRoute: AuthedAppRouteWithChildren,
AuthedOnboardingRoute: AuthedOnboardingRoute,
AuthedTermsRoute: AuthedTermsRoute,
AuthedSignInRequestIdRoute: AuthedSignInRequestIdRoute,
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/routes/_authed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ReportedErrorComponent } from "../lib/error-reporting";
import { AppHotkeys } from "../lib/hotkeys/app-hotkeys";
import { rememberInvitationLink } from "../lib/organizations/invitation-link";
import { learnShortenedToolNames } from "../lib/plugins/tool-names";
import { serviceTermsRequired } from "../lib/service-terms/queries";
import { SkinAccountSync } from "../skins/account-sync";
import { useActiveSkin } from "../skins/registry";

Expand All @@ -42,6 +43,15 @@ export const Route = createFileRoute("/_authed")({
}
throw redirect({ to: "/sign" });
}
/*
* Terms to agree to (OpenBot Cloud), before onboarding and everything else: from anywhere to
* the terms screen, which remembers where they were headed. The terms screen itself is let
* through here, past the gates after this one, until they agree.
*/
if (await serviceTermsRequired(context.queryClient)) {
if (location.pathname === "/terms") return;
throw redirect({ to: "/terms", search: { next: location.href } });
}
/*
* Somebody who has not finished onboarding goes there and nowhere else. Here rather than in
* `_app`, so admin and settings are behind the same gate; checked against the destination so
Expand Down
Loading
Loading