cloud / internal-packages / installer / src / Deployments.tsxmain at aacbc74
// YOUR DEPLOYMENTS: each deployment of iterate in the Cloudflare accounts the person connected,
// and what to do with one. Nothing here is stored by iterate Cloud: the Worker reads it from the
// person's account and from the deployments, when the page asks (worker/deployments.js).
import { useEffect, useState } from "react";
import { useNavigate, useRouterState } from "@tanstack/react-router";
import { ExternalLink, LogOut, Plus, RefreshCw } from "lucide-react";
import { AppShell, AppShellBrand } from "@iterate-com/ui/components/app-shell";
import { Badge } from "@iterate-com/ui/components/ui/badge";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@iterate-com/ui/components/ui/card";
import { DropdownMenuItem } from "@iterate-com/ui/components/ui/dropdown-menu";
import { Skeleton } from "@iterate-com/ui/components/ui/skeleton";
import { CloudNav } from "./CloudNav.tsx";
import { onboardingUrl, signOut, stackUrl } from "./api.ts";
import {
appsOf,
askForWizard,
comeBackToList,
startNewDeployment,
dayOf,
openInWizard,
startUpdate,
readingWords,
useDeployments,
useJustDeployed,
useMe,
useReading,
type Deployment,
} from "./your-deployments.ts";
import { eraseAndReplace } from "./erase.ts";
import { Btn, LinkBtn, Notice, WalkthroughOnly } from "./parts.tsx";
import { BOTH_CONSENT, leftOffOf, type Default } from "./update-consent.ts";
/** The wizard's route while its loader goes (main.tsx): it says so when it reads the person's
* account, which takes seconds for an account with hundreds of domains. */
export function Entering() {
const reading = useReading();
return (
<p className="p-8 text-sm text-muted-foreground" data-entering>
{reading ? readingWords(reading.domains) : "Loading…"}
</p>
);
}
export function Deployments() {
const page = useDeploymentsPage();
const { found, connected, user, newDeployment } = page;
return (
<AppShell
app="iterate Cloud"
mind={null}
switcher={<AppShellBrand app="iterate Cloud" />}
commandPalette={false}
searchRow={false}
nav={<CloudNav />}
account={user ? { actor: user.email, email: user.email } : false}
accountActions={
<DropdownMenuItem data-sign-out onClick={signOut}>
<LogOut />
Sign out
</DropdownMenuItem>
}
locationKey="/deployments"
>
<div className="min-h-0 flex-1 overflow-auto bg-page">
<div
data-deployments
className="mx-auto flex w-full max-w-3xl flex-col gap-6 px-4 pt-6 pb-16 lg:px-8 lg:pt-12"
>
<header className="flex flex-wrap items-end justify-between gap-3">
<div className="min-w-0">
<h1 className="text-2xl font-semibold tracking-tight">Your deployments</h1>
<p className="mt-1 text-sm text-muted-foreground">
iterate in your own Cloudflare accounts. iterate Cloud keeps no list of them: this
page reads your accounts each time.
</p>
</div>
<div className="flex flex-wrap items-center gap-2">
{connected && (
<Btn
variant="outline"
size="sm"
onClick={() => void found.refetch()}
loading={found.isFetching}
>
<RefreshCw />
Check again
</Btn>
)}
{/* on the page itself, for everybody: the sidebar is a rail of icons */}
<Btn size="sm" data-new-deployment onClick={newDeployment}>
<Plus />
New deployment
</Btn>
</div>
</header>
<DeploymentsBody page={page} />
</div>
</div>
</AppShell>
);
}
/** What the page reads (who is signed in, their deployments) and the ways from it into the wizard. */
function useDeploymentsPage() {
const { me, asked } = useMe();
const found = useDeployments(me?.connected === true);
// the access to Cloudflare can end while the tab still says it is there: the read says so (401)
const connected = me?.connected === true && found.data?.status !== 401;
const justDeployed = useJustDeployed(!!me && !connected);
const navigate = useNavigate();
const toWizard = () => {
askForWizard();
void navigate({ to: "/" });
};
/** The wizard from its first question: a new Cloudflare account, or one they have. */
const newDeployment = () => void startNewDeployment().then(() => navigate({ to: "/" }));
const open = (deployment: Deployment) => {
openInWizard(deployment);
void navigate({ to: "/" });
};
/** An update asked for here: the run starts, and the wizard's Deploy step shows it go. */
const update = async (deployment: Deployment, recover: boolean) => {
const problem = await startUpdate(deployment, recover);
if (!problem) void navigate({ to: "/" });
return problem;
};
const hash = useRouterState({ select: (state) => state.location.hash });
const count = found.data?.deployments.length || 0;
// the sidebar's row of a deployment leads to its card
useEffect(() => {
if (hash && count) document.getElementById(hash)?.scrollIntoView({ block: "start" });
}, [hash, count]);
return {
me,
asked,
found,
connected,
justDeployed,
toWizard,
newDeployment,
open,
update,
user: me?.user,
};
}
type DeploymentsPage = ReturnType<typeof useDeploymentsPage>;
/** Under the heading: what stops the page (nobody known yet, no access to Cloudflare, a read that
* goes or failed), or the deployments. With no access, the deployment this tab just made stays
* on the page, above the way to connect. */
function DeploymentsBody({ page }: { page: DeploymentsPage }) {
const { me, asked, found, connected, justDeployed } = page;
if (!asked) return <Skeleton className="h-24 w-full" />;
if (!connected)
return (
<>
{justDeployed && <JustDeployedCard domain={justDeployed} open={page.toWizard} />}
<div data-connect>
<Notice
title={me ? "Connect Cloudflare again" : "Connect Cloudflare"}
description={
me
? "iterate keeps no lasting access to your Cloudflare account: it ends after about an hour, and when a deploy starts. Connect again to read your deployments."
: "Your deployments are read from your own Cloudflare account, so sign in to Cloudflare first."
}
action={
<LinkBtn variant="default" href="/connect?level=full" onClick={comeBackToList}>
Connect Cloudflare
</LinkBtn>
}
/>
</div>
</>
);
if (found.isPending)
return (
<>
<p className="text-sm text-muted-foreground" data-reading>
{readingWords(me?.domains)}
</p>
<Skeleton className="h-40 w-full" />
</>
);
if (!found.data?.ok)
return (
<Notice
variant="destructive"
title="We couldn't read your deployments"
description="Cloudflare did not answer. Check again in a moment."
/>
);
return (
<DeploymentsFound page={page} notes={found.data.notes} deployments={found.data.deployments} />
);
}
/** What the read found: its notes, a card for each deployment (or that there is none), and the way
* to one more in the same account. */
function DeploymentsFound({
page,
notes,
deployments,
}: {
page: DeploymentsPage;
notes: string[];
deployments: Deployment[];
}) {
const { me, toWizard, open, update } = page;
const count = deployments.length;
return (
<>
{notes.map((note) => (
<Notice key={note} title={note} />
))}
{/* with no deployment, the wizard stays one press away in the page's header: the walkthrough uses it */}
{count === 0 ? (
<WalkthroughOnly
title="No deployment of iterate yet"
lead="None of the accounts you connected holds one."
/>
) : (
deployments.map((deployment) => (
<DeploymentCard
key={deployment.domain}
deployment={deployment}
mayTurnOnTelemetry={me?.telemetry === true}
mayConnectCloudflare={me?.cloudflareToken === true}
open={open}
update={update}
/>
))
)}
{count > 0 && (
<section data-another className="rounded-lg border border-dashed p-4 text-sm">
<h2 className="font-medium">Another iterate in the same account</h2>
<p className="mt-1 text-muted-foreground">
Not recommended. Deployments in one Cloudflare account are on the same Workers plan and
the same bill.
</p>
<Btn variant="outline" size="sm" className="mt-3" onClick={toWizard}>
Add another iterate to this account
</Btn>
</section>
)}
</>
);
}
/** The deployment this tab just made, while the list cannot be read: what this tab knows of it. */
function JustDeployedCard({ domain, open }: { domain: string; open: () => void }) {
return (
<Card id={domain} data-just-deployed={domain} className="scroll-mt-6">
<CardHeader>
<CardTitle className="min-w-0 truncate">{domain}</CardTitle>
<CardDescription>
You deployed it from this tab. Connect Cloudflare to see what it runs and to update it.
</CardDescription>
</CardHeader>
<CardContent className="flex flex-wrap gap-2 text-sm">
<LinkBtn href={stackUrl(domain, "/")} target="_blank" rel="noreferrer" data-start>
Start page
<ExternalLink />
</LinkBtn>
<Btn variant="outline" size="sm" onClick={open}>
Open in the wizard
</Btn>
</CardContent>
</Card>
);
}
/** What a person can ask for on a card before anything starts. */
type Asking = "update" | "recover" | "telemetry" | "cloudflare";
function DeploymentCard({
deployment,
mayTurnOnTelemetry,
mayConnectCloudflare,
open,
update,
}: {
deployment: Deployment;
/** The person's access to Cloudflare came from the consent for telemetry: an update turns it on. */
mayTurnOnTelemetry: boolean;
/** The person's access came from the consent for a mind's Cloudflare connection: an update
* gives the mind one. */
mayConnectCloudflare: boolean;
/** The wizard's Deploy step on it: for a deployment this Cloud has no run of. */
open: (deployment: Deployment) => void;
/** Starts an update from here; answers what went wrong, or null when the run goes. */
update: (deployment: Deployment, recover: boolean) => Promise<string | null>;
}) {
const { domain } = deployment;
const card = useCardAsking(deployment, update);
// a stack from before the rename and one that is incomplete have one way on: the erase
const onlyErase = deployment.older || deployment.incomplete;
// a deployment that runs an iterate this Cloud does not have is not updated from here, but for
// "Update anyway"
const updatesFromHere = deployment.updatable && !deployment.keyOutside && !deployment.foreign;
const turnsOnTelemetry = mayTurnOnTelemetry && !deployment.telemetry;
const connected = deployment.run?.cloudflareToken === true;
// its token is of an older release, which may change the account, and a mind of this release
// does not use it: an update narrows it
const older = connected && deployment.run?.cloudflareTokenCurrent === false;
const connectsCloudflare = mayConnectCloudflare && (!connected || older);
// what a mind made today has and this update would leave off: its Update offers the consent
const leftOff = updatesFromHere
? leftOffOf({
telemetry: deployment.telemetry,
connected,
older,
mayTurnOnTelemetry,
mayConnectCloudflare,
})
: [];
return (
<Card id={domain} data-deployment={domain} className="scroll-mt-6">
<CardHeader>
<CardTitle className="flex flex-wrap items-center gap-2">
<span className="min-w-0 truncate">{domain}</span>
<AnswersBadge deployment={deployment} />
</CardTitle>
<CardDescription>In the Cloudflare account {deployment.account.name}.</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-4 text-sm">
<dl className="grid gap-x-6 gap-y-3 sm:grid-cols-[9rem_1fr]">
<dt className="text-muted-foreground">It runs</dt>
<dd data-runs>
<WhatRuns deployment={deployment} />
</dd>
<dt className="text-muted-foreground">Open</dt>
<dd className="flex flex-wrap gap-2">
<WaysIn deployment={deployment} />
</dd>
<dt className="text-muted-foreground">Telemetry</dt>
<dd data-telemetry={deployment.telemetry} className="flex flex-wrap items-center gap-2">
<TelemetryState
on={deployment.telemetry}
updatesFromHere={updatesFromHere}
turnsOnTelemetry={turnsOnTelemetry}
asking={card.asking}
ask={card.ask}
/>
</dd>
<dt className="text-muted-foreground">Cloudflare</dt>
<dd data-cloudflare={connected} className="flex flex-wrap items-center gap-2">
<CloudflareState
on={connected}
older={older}
updatesFromHere={updatesFromHere}
connectsCloudflare={connectsCloudflare}
asking={card.asking}
ask={card.ask}
/>
</dd>
<dt className="text-muted-foreground">iterate's shared apps</dt>
<dd className="flex flex-col gap-2">
<SharedApps deployment={deployment} />
</dd>
</dl>
</CardContent>
<CardFooter className="flex flex-col items-start gap-3">
<CardWarnings deployment={deployment} />
<CardButtons deployment={deployment} onlyErase={onlyErase} card={card} open={open} />
{card.asking === "telemetry" && (
<AskTelemetry
domain={domain}
href={consentHref("telemetry", connectsCloudflare)}
cancel={card.cancel}
/>
)}
{card.asking === "cloudflare" && (
<AskCloudflare
domain={domain}
narrows={older}
href={consentHref("cloudflare", turnsOnTelemetry)}
cancel={card.cancel}
/>
)}
{(card.asking === "update" || card.asking === "recover") && (
<AskUpdate
deployment={deployment}
asking={card.asking}
turnsOnTelemetry={turnsOnTelemetry}
connectsCloudflare={connectsCloudflare}
narrowsCloudflare={older}
leftOff={card.asking === "update" ? leftOff : []}
card={card}
/>
)}
<CardFootnotes deployment={deployment} onlyErase={onlyErase} />
</CardFooter>
</Card>
);
}
/** What the person asked for on a card, said there before anything starts, and the start of it. */
function useCardAsking(
deployment: Deployment,
update: (deployment: Deployment, recover: boolean) => Promise<string | null>,
) {
const [asking, setAsking] = useState<Asking | null>(null);
const [starting, setStarting] = useState(false);
const [problem, setProblem] = useState<string | null>(null);
const ask = (what: Asking) => {
setProblem(null);
setAsking((now) => (now === what ? null : what));
};
const start = async () => {
setStarting(true);
setProblem(await update(deployment, asking === "recover"));
setStarting(false);
};
return { asking, starting, problem, ask, start, cancel: () => setAsking(null) };
}
type CardAsking = ReturnType<typeof useCardAsking>;
/** Beside the domain: whether its iterate answers, or that it is incomplete. */
function AnswersBadge({ deployment }: { deployment: Deployment }) {
if (deployment.incomplete)
return (
<Badge data-incomplete variant="destructive">
Incomplete
</Badge>
);
return (
<Badge
data-answers={deployment.answers}
variant={deployment.answers ? "secondary" : "destructive"}
>
{deployment.answers ? "Answers" : "Does not answer"}
</Badge>
);
}
/** Which version it runs: what its own Worker says, else what a deploy from here says. */
function WhatRuns({ deployment }: { deployment: Deployment }) {
const { run, commit } = deployment;
const deployed = dayOf(run?.endedAt || null);
const changed = dayOf(deployment.changedAt);
// its Worker names another commit than this Cloud's last run: somebody deployed it another way
if (commit && commit !== run?.commit)
return (
<>
<code className="font-mono">{commit.slice(0, 9)}</code>, not deployed from here.
{changed ? ` Cloudflare says its Workers last changed on ${changed}.` : ""}
</>
);
if (run?.commit)
return (
<>
<code className="font-mono">{run.commit.slice(0, 9)}</code>
{deployed ? `, deployed from here on ${deployed}` : ", deployed from here"}
</>
);
if (run) return `A deploy from here is ${run.status}.`;
return (
<>
Not deployed from here, so this page cannot say which version.
{changed ? ` Cloudflare says its Workers last changed on ${changed}.` : ""}
</>
);
}
/** The links into the deployment: its start page and its onboarding chat. */
function WaysIn({ deployment }: { deployment: Deployment }) {
const { domain } = deployment;
return (
<>
{deployment.answers ? (
<LinkBtn href={stackUrl(domain, "/")} target="_blank" rel="noreferrer" data-start>
Start page
<ExternalLink />
</LinkBtn>
) : (
<span className="text-muted-foreground">
iterate.{domain} does not answer, so there is nothing to open.
</span>
)}
{deployment.onboarding && (
<LinkBtn href={onboardingUrl(domain)} target="_blank" rel="noreferrer" data-onboarding>
Onboarding
<ExternalLink />
</LinkBtn>
)}
{deployment.answers && !deployment.onboarding && (
<span className="self-center text-muted-foreground" data-no-onboarding>
It has no Dash yet: an update adds it.
</span>
)}
</>
);
}
/** Whether telemetry is on, and the way to turn it on from here. */
function TelemetryState({
on,
updatesFromHere,
turnsOnTelemetry,
asking,
ask,
}: {
on: boolean;
updatesFromHere: boolean;
turnsOnTelemetry: boolean;
asking: Asking | null;
ask: (what: Asking) => void;
}) {
if (on) return "On: its events, logs and traces are kept in this Cloudflare account.";
if (turnsOnTelemetry && updatesFromHere)
return "Off. Your access to Cloudflare now covers it: “Update iterate” turns it on.";
return (
<>
Off.
{updatesFromHere && (
<Btn
variant="outline"
size="sm"
data-turn-on-telemetry
aria-expanded={asking === "telemetry"}
onClick={() => ask("telemetry")}
>
Turn on telemetry
</Btn>
)}
</>
);
}
/** Whether the mind has its Cloudflare connection, and the way to give it one from here, or to
* narrow one whose token an older release made. */
function CloudflareState({
on,
older,
updatesFromHere,
connectsCloudflare,
asking,
ask,
}: {
on: boolean;
older: boolean;
updatesFromHere: boolean;
connectsCloudflare: boolean;
asking: Asking | null;
ask: (what: Asking) => void;
}) {
if (on && !older)
return "On: the mind's agents read this Cloudflare account and query its logs and traces with an API token of its own, which changes nothing in the account.";
const state = on
? "From an older release: the mind's token may do more than this release allows, and a mind of this release does not use it."
: "Off.";
if (connectsCloudflare && updatesFromHere)
return `${state} Your access to Cloudflare now covers it: “Update iterate” ${on ? "narrows the token: it then reads the account and changes nothing in it" : "gives the mind its connection"}.`;
return (
<>
{state}
{updatesFromHere && (
<Btn
variant="outline"
size="sm"
data-connect-cloudflare
aria-expanded={asking === "cloudflare"}
onClick={() => ask("cloudflare")}
>
{on ? "Narrow this mind's Cloudflare token" : "Give this mind a Cloudflare connection"}
</Btn>
)}
</>
);
}
/** iterate's shared apps, each with the accounts it delivers for. */
function SharedApps({ deployment }: { deployment: Deployment }) {
return (
<>
<ul className="flex flex-wrap gap-1.5" data-apps>
{appsOf(deployment).map((app) => (
<li key={app.client}>
<Badge
variant={app.accounts ? "secondary" : "outline"}
data-app={app.client}
data-delivers={app.accounts > 0}
>
{app.label}
{app.accounts
? `: ${app.accounts} ${app.accounts === 1 ? "account" : "accounts"}`
: ": not connected"}
</Badge>
</li>
))}
</ul>
{!deployment.enrolled && (
<span className="text-muted-foreground">
iterate Cloud and this deployment do not know each other yet, so no shared app can deliver
to it.
</span>
)}
</>
);
}
/** Above the buttons: why this deployment has one way on, or none from here. */
function CardWarnings({ deployment }: { deployment: Deployment }) {
const { domain } = deployment;
return (
<>
{deployment.incomplete ? (
<p className="text-sm" data-incomplete-note>
Parts of an iterate for {domain} are in this account, and none of them serves the domain:
a deploy or an erase did not finish. Erase and replace it.
</p>
) : (
deployment.older && (
<p className="text-sm" data-older>
This iterate is from before a large change. It cannot be updated in place. Erase and
replace it: its members, files and config repo are not kept.
</p>
)
)}
{deployment.keyOutside && (
<p className="text-sm" data-key-outside>
This deployment keeps its vault key outside Cloudflare. Update it from a computer that
holds the key.
</p>
)}
{deployment.foreign && !deployment.older && !deployment.incomplete && (
<p className="text-sm" data-foreign>
This deployment runs iterate at{" "}
<code className="font-mono">{deployment.foreign.runs.slice(0, 9)}</code>, which this Cloud
does not have: it is newer than the Cloud, or from another branch. Update is off until the
Cloud is updated.
</p>
)}
</>
);
}
/** What to do with the deployment: update it, erase and replace it, or get back in. */
function CardButtons({
deployment,
onlyErase,
card,
open,
}: {
deployment: Deployment;
onlyErase: boolean;
card: CardAsking;
open: (deployment: Deployment) => void;
}) {
const { asking, ask } = card;
return (
<div className="flex flex-wrap gap-2">
{!onlyErase && !deployment.keyOutside && !deployment.foreign && (
<Btn
size="sm"
data-update
aria-expanded={deployment.updatable ? asking === "update" : undefined}
onClick={() => (deployment.updatable ? ask("update") : open(deployment))}
>
Update iterate
</Btn>
)}
{!onlyErase && deployment.replaceable && (
<Btn
variant="outline"
size="sm"
data-update-anyway
aria-expanded={asking === "update"}
onClick={() => ask("update")}
>
Update anyway
</Btn>
)}
{!deployment.noErase && (
<Btn
variant={onlyErase ? "default" : "outline"}
size="sm"
data-erase
disabled={!eraseAndReplace}
onClick={() => eraseAndReplace?.(deployment)}
>
Erase and replace
</Btn>
)}
{deployment.updatable && deployment.owner && (
<Btn
variant="ghost"
size="sm"
data-recover
aria-expanded={asking === "recover"}
onClick={() => ask("recover")}
>
Lost your passkey?
</Btn>
)}
</div>
);
}
/** Asked to turn on telemetry: what it is, and the consent on Cloudflare's page that it takes. */
/** The consent for `what`. A new consent replaces the sign-in and keeps only what its link asks,
* so it asks again for the other choice when the person's access covers that now. */
const consentHref = (what: "telemetry" | "cloudflare", other: boolean) =>
`/connect?level=full&${what}=1${other ? `&${what === "telemetry" ? "cloudflare" : "telemetry"}=1` : ""}`;
type AskConsent = { domain: string; href: string; cancel: () => void };
/** What the mind's Cloudflare token may do, in the words of a card. */
const CLOUDFLARE_TOKEN_DOES =
"With it, the mind and its agents read the account and its zones, and query its Workers' logs and traces. It changes nothing in the account: no Worker, storage, DNS record, route or setting. It reaches nothing beyond the account: no API token, member, billing or domain purchase. Every member and agent of the mind can use it, so it must not be a way to take the mind's Workers over.";
function AskTelemetry({ domain, href, cancel }: AskConsent) {
return (
<div data-asking="telemetry" className="w-full rounded-lg border bg-card p-4 text-sm">
<p>
Telemetry keeps the events, logs and traces of {domain} in your own Cloudflare account,
where your mind and its Dash read them. The deploy makes two API tokens in the account for
that, so Cloudflare asks you for one more permission.
</p>
<p className="mt-2">
On Cloudflare's page, open <b className="font-medium">Sensitive scopes</b> and turn on{" "}
<b className="font-medium">Account API Tokens Write</b>, then press Authorize. Cloudflare
leaves it off, and gives no access at all without it. Back here, press “Update iterate”.
</p>
<div className="mt-3 flex flex-wrap gap-2">
<LinkBtn
variant="default"
size="sm"
href={href}
data-telemetry-consent
onClick={comeBackToList}
>
Continue to Cloudflare
</LinkBtn>
<Btn variant="ghost" size="sm" onClick={cancel}>
Cancel
</Btn>
</div>
</div>
);
}
/** Asked for the mind's Cloudflare connection, or to narrow it: what the token may do, and the
* consent it takes. */
function AskCloudflare({ domain, narrows, href, cancel }: AskConsent & { narrows: boolean }) {
return (
<div data-asking="cloudflare" className="w-full rounded-lg border bg-card p-4 text-sm">
<p>
{narrows
? `The mind of ${domain} has an API token of your Cloudflare account from an older release, which may do more than this release allows. The update narrows it to what a mind made today has: it reads the account and changes nothing in it. `
: `The mind of ${domain} gets one API token of your Cloudflare account, named after the deployment. `}
{CLOUDFLARE_TOKEN_DOES} The token stays in your account and in the mind's vault; iterate
Cloud does not keep it. The deploy {narrows ? "changes" : "makes"} it, so Cloudflare asks
you for one more permission.
</p>
<p className="mt-2">
On Cloudflare's page, open <b className="font-medium">Sensitive scopes</b> and turn on{" "}
<b className="font-medium">Account API Tokens Write</b>, then press Authorize. Back here,
press “Update iterate”.
</p>
<div className="mt-3 flex flex-wrap gap-2">
<LinkBtn
variant="default"
size="sm"
href={href}
data-cloudflare-consent
onClick={comeBackToList}
>
Continue to Cloudflare
</LinkBtn>
<Btn variant="ghost" size="sm" onClick={cancel}>
Cancel
</Btn>
</div>
</div>
);
}
/** Asked for an update, or for a way back in without a passkey: what it does, and its start. An
* update that leaves off what a mind made today has offers first the consent for it, and then
* the update without it. */
function AskUpdate({
deployment,
asking,
turnsOnTelemetry,
connectsCloudflare,
narrowsCloudflare,
leftOff,
card,
}: {
deployment: Deployment;
asking: "update" | "recover";
turnsOnTelemetry: boolean;
connectsCloudflare: boolean;
/** The mind's token is of an older release, which may change the account. */
narrowsCloudflare: boolean;
/** What a mind made today has and this update would leave off (update-consent.ts). */
leftOff: Default[];
card: CardAsking;
}) {
const { domain, foreign } = deployment;
const { starting, problem, start, cancel } = card;
const replaces = foreign
? `this replaces ${foreign.runs.slice(0, 9)} with ${foreign.cloud.slice(0, 9)}`
: "";
const offers = leftOff.length > 0;
return (
<div data-asking={asking} className="w-full rounded-lg border bg-card p-4 text-sm">
{asking === "recover" ? (
<p>
A passkey is the only way to sign in to {domain}. This updates iterate and gives you a
link that signs you in as <b className="font-medium">{deployment.owner || "its owner"}</b>{" "}
once, to add a new passkey. Your Cloudflare account is the way back in, and mail is not.
</p>
) : (
<p>
This deploys the newest iterate on {domain}, with the settings your deployment keeps
{turnsOnTelemetry ? ", and turns on its telemetry" : ""}
{connectsCloudflare
? narrowsCloudflare
? ", and narrows its mind's Cloudflare token, so that it reads the account and changes nothing in it"
: ", and gives its mind a Cloudflare connection"
: ""}
. It uses your access to Cloudflare, and gives it up when the update ends.
</p>
)}
{offers && <LeftOff domain={domain} leftOff={leftOff} narrows={narrowsCloudflare} />}
{foreign && (
<p className="mt-2" data-replaces>
This deployment runs iterate at{" "}
<code className="font-mono">{foreign.runs.slice(0, 9)}</code>, which iterate Cloud does
not have. The update puts iterate Cloud's own,{" "}
<code className="font-mono">{foreign.cloud.slice(0, 9)}</code>, in its place. If yours is
newer, what it stored since may not work with the older one.
</p>
)}
<div className="mt-3 flex flex-wrap gap-2">
{offers && (
<LinkBtn
variant="default"
size="sm"
href={BOTH_CONSENT}
data-update-consent
onClick={comeBackToList}
>
Continue to Cloudflare
</LinkBtn>
)}
<Btn
size="sm"
variant={offers ? "outline" : "default"}
data-confirm
onClick={() => void start()}
loading={starting}
>
{foreign
? asking === "recover"
? `Update anyway and get a new link: ${replaces}`
: `Update anyway: ${replaces}`
: asking === "recover"
? "Update and get a new link"
: offers
? `Update without ${leftOff.length > 1 ? "them" : "it"}`
: "Update now"}
</Btn>
<Btn variant="ghost" size="sm" onClick={cancel} disabled={starting}>
Cancel
</Btn>
</div>
{problem && (
<p role="alert" className="mt-3 text-destructive" data-update-problem>
{problem}
</p>
)}
</div>
);
}
/** In an update's panel: what a mind made today has and this one does not, and what the person
* ticks on Cloudflare's page so that the update gives it. */
function LeftOff({
domain,
leftOff,
narrows,
}: {
domain: string;
leftOff: Default[];
/** The mind has a connection, with a token from an older release. */
narrows: boolean;
}) {
const telemetry = leftOff.includes("telemetry");
const both = telemetry && leftOff.includes("cloudflare");
const connection = narrows
? "a Cloudflare connection that reads its account and changes nothing in it"
: "its own Cloudflare connection";
const token = narrows
? "one API token, which stays in your account: the mind's own, narrowed to what a mind made today has"
: "one API token, which stays in your account: with it the mind's agents read the account and query its logs and traces";
const [what, tokens] = both
? [
`telemetry and ${connection}`,
`three API tokens, which stay in your account: two for telemetry, and ${token.replace(/^one API token, which stays in your account: /, "")}`,
]
: telemetry
? ["telemetry", "two API tokens for telemetry, which stay in your account"]
: [connection, token];
return (
<div data-left-off={leftOff.join(" ")} className="mt-2 space-y-2">
<p>
A mind made today has {what}, and {domain} does not
{narrows
? ": its token is from an older release and may do more than this release allows"
: ""}
. This update can give it {both ? "both" : "that"}, with one more permission. On
Cloudflare's page, open <b className="font-medium">Sensitive scopes</b> and turn on{" "}
<b className="font-medium">Account API Tokens Write</b>, then press Authorize. Cloudflare
leaves it off, and gives no access at all without it. Back here, press “Update iterate”
again.
</p>
<p className="text-muted-foreground">
The deploy {narrows && !both ? "changes" : "makes"} {tokens}. iterate Cloud keeps none of
them.
</p>
</div>
);
}
/** Under the buttons: why a button is not there, or what one does. */
function CardFootnotes({ deployment, onlyErase }: { deployment: Deployment; onlyErase: boolean }) {
return (
<>
{deployment.noErase && (
<p className="text-sm text-muted-foreground" data-no-erase>
{deployment.noErase}
</p>
)}
{!deployment.updatable && !onlyErase && !deployment.keyOutside && !deployment.foreign && (
<p className="text-sm text-muted-foreground" data-not-from-here>
iterate Cloud has no record of deploying it. “Update iterate” opens the wizard's Deploy
step on this domain.
</p>
)}
{!eraseAndReplace && (
<p className="text-sm text-muted-foreground" data-erase-note>
Coming soon: erase everything on the domain and deploy again.
</p>
)}
</>
);
}