+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
329 lines
12 KiB
TypeScript
329 lines
12 KiB
TypeScript
import {
|
|
isAtomCommandInterrupted,
|
|
squashAtomCommandFailure,
|
|
type AtomCommandResult,
|
|
} from "@t3tools/client-runtime/state/runtime";
|
|
import {
|
|
ANTIGRAVITY_AUTH_METHODS,
|
|
type AntigravityAuthMethod,
|
|
type EnvironmentId,
|
|
type ProviderInstanceId,
|
|
type ServerProvider,
|
|
} from "@t3tools/contracts";
|
|
import { useRef, useState } from "react";
|
|
import { Trash2Icon } from "lucide-react";
|
|
|
|
import { ensureLocalApi } from "../../localApi";
|
|
import { useEnvironmentQuery } from "../../state/query";
|
|
import { serverEnvironment } from "../../state/server";
|
|
import { useAtomCommand } from "../../state/use-atom-command";
|
|
import { Button } from "../ui/button";
|
|
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
|
import { SettingsRow } from "./settingsLayout";
|
|
import { ProviderAuthenticationSection } from "./ProviderAuthenticationSection";
|
|
|
|
interface ProviderSetupSectionProps {
|
|
readonly environmentId: EnvironmentId;
|
|
readonly environmentLabel: string;
|
|
readonly instanceId: ProviderInstanceId;
|
|
readonly provider: ServerProvider | undefined;
|
|
readonly binaryPath?: string | undefined;
|
|
readonly authMethod?: AntigravityAuthMethod | undefined;
|
|
readonly enabled: boolean;
|
|
readonly readOnly: boolean;
|
|
readonly onEnable: () => void;
|
|
}
|
|
|
|
/** Read the configured method from the instance config. Unknown values fall back to personal. */
|
|
export function readAntigravityAuthMethod(config: unknown): AntigravityAuthMethod {
|
|
const value =
|
|
config !== null && typeof config === "object" && "authMethod" in config
|
|
? config.authMethod
|
|
: undefined;
|
|
return (
|
|
ANTIGRAVITY_AUTH_METHODS.find((method) => method.value === value)?.value ?? "oauth-personal"
|
|
);
|
|
}
|
|
|
|
/** Setup state belongs to the selected environment and is never saved in client settings. */
|
|
export function ProviderSetupSection(props: ProviderSetupSectionProps) {
|
|
return (
|
|
<section
|
|
aria-label="Antigravity setup"
|
|
className="@container/setup divide-y divide-border/50 text-xs"
|
|
>
|
|
<SettingsRow
|
|
className="@max-lg/setup:[&>div:first-child]:flex @max-lg/setup:[&>div:first-child]:items-stretch @max-lg/setup:[&>div:first-child]:gap-3"
|
|
title="Environment"
|
|
description="Device that runs this provider."
|
|
control={
|
|
<div className="flex min-w-0 flex-col gap-2 sm:items-end">
|
|
<span className="text-muted-foreground [overflow-wrap:anywhere]">
|
|
{props.environmentLabel}
|
|
</span>
|
|
{!props.enabled && !props.readOnly ? (
|
|
<Button size="sm" variant="outline" onClick={props.onEnable}>
|
|
Enable Antigravity
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
}
|
|
/>
|
|
{props.readOnly ? (
|
|
<SettingsRow title="Setup unavailable" description="Provider setup is read-only." />
|
|
) : props.provider?.setup === undefined ? (
|
|
<SettingsRow
|
|
title="Update required"
|
|
description="Update this environment to manage Antigravity."
|
|
/>
|
|
) : (
|
|
<ProviderSetupActions
|
|
key={`${props.environmentId}:${props.instanceId}`}
|
|
environmentId={props.environmentId}
|
|
environmentLabel={props.environmentLabel}
|
|
instanceId={props.instanceId}
|
|
provider={props.provider}
|
|
binaryPath={props.binaryPath}
|
|
authMethod={props.authMethod ?? "oauth-personal"}
|
|
enabled={props.enabled}
|
|
/>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function ProviderSetupActions({
|
|
environmentId,
|
|
environmentLabel,
|
|
instanceId,
|
|
provider,
|
|
enabled,
|
|
binaryPath,
|
|
}: Pick<
|
|
ProviderSetupSectionProps,
|
|
"environmentId" | "environmentLabel" | "instanceId" | "enabled" | "binaryPath"
|
|
> & {
|
|
readonly provider: ServerProvider;
|
|
readonly authMethod: AntigravityAuthMethod;
|
|
}) {
|
|
const target = { environmentId, input: { instanceId } };
|
|
const authQuery = useEnvironmentQuery(serverEnvironment.providerAuthState(target));
|
|
const installQuery = useEnvironmentQuery(serverEnvironment.providerInstallState(target));
|
|
const auth = authQuery.data;
|
|
const installation = installQuery.data;
|
|
const commandOptions = { reportFailure: false, reportDefect: false };
|
|
const startInstall = useAtomCommand(serverEnvironment.startProviderInstall, commandOptions);
|
|
const cancelInstall = useAtomCommand(serverEnvironment.cancelProviderInstall, commandOptions);
|
|
const removeInstall = useAtomCommand(
|
|
serverEnvironment.removeProviderInstallation,
|
|
commandOptions,
|
|
);
|
|
const [pendingLabel, setPendingLabel] = useState<string | null>(null);
|
|
const pendingRef = useRef(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const authActive =
|
|
auth?.phase === "starting" || auth?.phase === "waiting" || auth?.phase === "verifying";
|
|
const installActive =
|
|
installation?.phase === "downloading" ||
|
|
installation?.phase === "extracting" ||
|
|
installation?.phase === "verifying";
|
|
const usesCustomBinary = Boolean(binaryPath?.trim());
|
|
const installed =
|
|
provider.installed || (!usesCustomBinary && installation?.installedVersion != null);
|
|
const queryError = authQuery.error ?? installQuery.error;
|
|
const actionsDisabled = pendingLabel !== null || queryError !== null;
|
|
const installationStatusMessage =
|
|
installation?.phase === "downloading"
|
|
? `Downloading ${(installation.downloadedBytes / 1_000_000).toFixed(1)} MB${installation.totalBytes === null ? "" : ` of ${(installation.totalBytes / 1_000_000).toFixed(1)} MB`}.`
|
|
: installation?.phase === "extracting"
|
|
? "Extracting Antigravity."
|
|
: installation?.phase === "verifying"
|
|
? "Checking the downloaded runtime."
|
|
: installed
|
|
? "Installed."
|
|
: usesCustomBinary
|
|
? enabled
|
|
? "The configured Antigravity runtime is unavailable."
|
|
: "The configured Antigravity runtime has not been checked."
|
|
: installation?.totalBytes
|
|
? `${Math.ceil(installation.totalBytes / 1_000_000)} MB download.`
|
|
: "Not installed.";
|
|
|
|
async function runCommand<A, E>(
|
|
label: string,
|
|
request: () => Promise<AtomCommandResult<A, E>>,
|
|
): Promise<boolean> {
|
|
if (pendingRef.current) return false;
|
|
pendingRef.current = true;
|
|
setPendingLabel(label);
|
|
setError(null);
|
|
try {
|
|
const result = await request();
|
|
if (result._tag === "Failure") {
|
|
if (!isAtomCommandInterrupted(result)) {
|
|
const failure = squashAtomCommandFailure(result);
|
|
setError(failure instanceof Error ? failure.message : "Provider setup failed.");
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
} catch {
|
|
setError("Provider setup failed. Try again.");
|
|
return false;
|
|
} finally {
|
|
pendingRef.current = false;
|
|
setPendingLabel(null);
|
|
}
|
|
}
|
|
|
|
async function removeRuntime() {
|
|
const confirmed = await ensureLocalApi().dialogs.confirm(
|
|
`Remove the downloaded Antigravity runtime from ${environmentLabel}? Google sign-in and thread history are kept.`,
|
|
);
|
|
if (confirmed) {
|
|
await runCommand("Removing runtime", () => removeInstall(target));
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="divide-y divide-border/50">
|
|
<SettingsRow
|
|
title="Runtime"
|
|
className="@max-lg/setup:[&>div:first-child]:flex @max-lg/setup:[&>div:first-child]:items-stretch @max-lg/setup:[&>div:first-child]:gap-3"
|
|
description="Install and manage Antigravity."
|
|
status={
|
|
<div className="space-y-2">
|
|
{usesCustomBinary ? (
|
|
<p className="text-muted-foreground">
|
|
Uses the custom binary path below. Installation keeps that path.
|
|
</p>
|
|
) : null}
|
|
{!installed && !provider.setup?.canInstall ? (
|
|
<p className="text-muted-foreground">
|
|
Automatic installation unavailable. Set a binary path or use another environment.
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
}
|
|
control={
|
|
<div className="flex w-full min-w-0 flex-col gap-2 sm:w-56 sm:text-right">
|
|
<p role="status" className="min-h-4 text-muted-foreground tabular-nums">
|
|
{installationStatusMessage}
|
|
</p>
|
|
<div className="h-1">
|
|
{installation?.phase === "downloading" &&
|
|
installation.totalBytes !== null &&
|
|
installation.totalBytes > 0 ? (
|
|
<progress
|
|
aria-label="Antigravity download"
|
|
className="block h-1 w-full accent-foreground"
|
|
value={installation.downloadedBytes}
|
|
max={installation.totalBytes}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
{!installActive &&
|
|
installation?.message &&
|
|
installation.message !== installationStatusMessage ? (
|
|
<p className="text-muted-foreground [overflow-wrap:anywhere]">
|
|
{installation.message}
|
|
</p>
|
|
) : null}
|
|
<div className="grid min-h-7 grid-cols-[1.75rem_minmax(0,1fr)] gap-2">
|
|
<div className="col-start-2 row-start-1 grid">
|
|
{installActive && installation.operationId ? (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
disabled={actionsDisabled}
|
|
onClick={() => {
|
|
const operationId = installation.operationId;
|
|
if (!operationId) return;
|
|
void runCommand("Cancelling installation", () =>
|
|
cancelInstall({ environmentId, input: { instanceId, operationId } }),
|
|
);
|
|
}}
|
|
>
|
|
Cancel installation
|
|
</Button>
|
|
) : !installActive && provider.setup?.canInstall ? (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
disabled={actionsDisabled || installation === null || authActive}
|
|
onClick={() =>
|
|
void runCommand("Starting installation", () => startInstall(target))
|
|
}
|
|
>
|
|
{installation?.installedVersion
|
|
? installation.version &&
|
|
installation.version !== installation.installedVersion
|
|
? "Update Antigravity"
|
|
: "Reinstall Antigravity"
|
|
: installation?.phase === "failed" || installation?.phase === "cancelled"
|
|
? "Retry installation"
|
|
: installed
|
|
? "Install managed runtime"
|
|
: "Install Antigravity"}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
{installation?.canRemove && !installActive ? (
|
|
<Tooltip>
|
|
<TooltipTrigger
|
|
render={
|
|
<Button
|
|
size="icon-sm"
|
|
variant="ghost"
|
|
className="col-start-1 row-start-1"
|
|
aria-label="Remove downloaded runtime"
|
|
disabled={actionsDisabled || authActive}
|
|
onClick={() => void removeRuntime()}
|
|
/>
|
|
}
|
|
>
|
|
<Trash2Icon className="size-3.5" />
|
|
</TooltipTrigger>
|
|
<TooltipPopup>Remove downloaded runtime</TooltipPopup>
|
|
</Tooltip>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
}
|
|
/>
|
|
|
|
<ProviderAuthenticationSection
|
|
environmentId={environmentId}
|
|
environmentLabel={environmentLabel}
|
|
instanceId={instanceId}
|
|
provider={provider}
|
|
readOnly={false}
|
|
/>
|
|
|
|
<p className="sr-only" role="status">
|
|
{pendingLabel ? `${pendingLabel}.` : null}
|
|
</p>
|
|
{error || queryError ? (
|
|
<div className="grid gap-2 px-3 py-3 sm:px-4">
|
|
<p role="alert" className="text-destructive [overflow-wrap:anywhere]">
|
|
{error ?? queryError}
|
|
</p>
|
|
{queryError ? (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
className="w-fit"
|
|
onClick={() => {
|
|
authQuery.refresh();
|
|
installQuery.refresh();
|
|
}}
|
|
>
|
|
Retry setup status
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|