From 07324844df53b414d10560d71b67c4a9e7ebab58 Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Sat, 13 Jun 2026 18:40:22 -0400 Subject: [PATCH] feat(web): split provider updates per environment when WSL is present The launch popover now renders one row per local environment (e.g. Windows and WSL), each with its own "update all" trigger that targets only that environment's backend, instead of a single button that fanned out to every environment at once. - Defer the popover until every local backend leaves "connecting" (30s safety cap) so it reflects every environment, rather than appearing from the primary alone while WSL is still booting; rows pick up WSL reactively if it connects later. - Label rows by platform ("Windows" / "WSL" / "macOS" / "Linux"), detecting WSL by its backend instance id and otherwise the reported OS, falling back to the environment's own label. - Resolve each row's result from both the dispatch payload and live server state, so it lands correctly whether a secondary backend's config fails to re-sync or the dispatch RPC is lost to a reconnect; a 20s backstop reverts the spinner if the request never reaches the backend. - Gate the entire split behind WSL presence: without a WSL backend the popover keeps the original single-prompt flow, so non-WSL users see no change. --- .../ProviderUpdateEnvironmentRows.tsx | 281 ++++++++++++++ ...erUpdateLaunchNotification.environments.ts | 96 +++++ ...iderUpdateLaunchNotification.logic.test.ts | 156 +++++++- .../ProviderUpdateLaunchNotification.logic.ts | 123 +++++++ .../ProviderUpdateLaunchNotification.tsx | 344 +++++------------- .../ProviderUpdatePrimaryNotification.tsx | 327 +++++++++++++++++ apps/web/src/environmentApi.ts | 71 +++- 7 files changed, 1128 insertions(+), 270 deletions(-) create mode 100644 apps/web/src/components/ProviderUpdateEnvironmentRows.tsx create mode 100644 apps/web/src/components/ProviderUpdateLaunchNotification.environments.ts create mode 100644 apps/web/src/components/ProviderUpdatePrimaryNotification.tsx diff --git a/apps/web/src/components/ProviderUpdateEnvironmentRows.tsx b/apps/web/src/components/ProviderUpdateEnvironmentRows.tsx new file mode 100644 index 0000000000..90aba1abda --- /dev/null +++ b/apps/web/src/components/ProviderUpdateEnvironmentRows.tsx @@ -0,0 +1,281 @@ +import { CheckIcon } from "lucide-react"; +import { type ReactNode, useCallback, useMemo, useRef, useState } from "react"; +import { PROVIDER_DISPLAY_NAMES, type EnvironmentId } from "@t3tools/contracts"; + +import { cn } from "~/lib/utils"; +import { updateProvidersInEnvironment } from "../environmentApi"; +import { useLocalEnvironmentUpdateGroups } from "./ProviderUpdateLaunchNotification.environments"; +import { + collectProviderUpdateOutcomeSnapshots, + firstRejectedProviderUpdateMessage, + getProviderUpdateProgressToastView, + getProviderUpdateSidebarPillView, + type LocalEnvironmentUpdateGroup, + type ProviderUpdateSidebarPillView, + type ProviderUpdateToastView, +} from "./ProviderUpdateLaunchNotification.logic"; +import { Button } from "./ui/button"; +import { Spinner } from "./ui/spinner"; + +// If neither the dispatch result nor server state ever reports the update (e.g. +// the request never reached the backend), stop the spinner after this long so +// the row reverts to its Update button instead of spinning forever. +const PENDING_EXPIRY_MS = 20_000; + +type RowStatusKind = "idle" | "loading" | "success" | "failed" | "unchanged"; + +interface RowStatus { + readonly kind: RowStatusKind; + readonly text: string; +} + +function providerNamesFor(group: LocalEnvironmentUpdateGroup): string { + return group.candidates + .map((candidate) => PROVIDER_DISPLAY_NAMES[candidate.driver] ?? candidate.driver) + .join(", "); +} + +/** + * Resolve a row's display from every available signal, in priority order: + * a transport rejection, then the dispatch's own result payload (reliable even + * when a secondary backend's config does not re-sync), then live server state + * (reliable even when the dispatch RPC is lost to a reconnect), then the + * optimistic pending spinner, then the idle "ready to update" state. + */ +function resolveRowStatus(input: { + readonly group: LocalEnvironmentUpdateGroup; + readonly error: string | undefined; + readonly result: ProviderUpdateToastView | undefined; + readonly pill: ProviderUpdateSidebarPillView | null; + readonly isPending: boolean; +}): RowStatus { + if (input.error) { + return { kind: "failed", text: input.error }; + } + if (input.result) { + switch (input.result.phase) { + case "succeeded": + return { kind: "success", text: "Updated" }; + case "failed": + return { kind: "failed", text: input.result.description }; + case "unchanged": + return { kind: "unchanged", text: input.result.description }; + default: + return { kind: "loading", text: "Updating…" }; + } + } + if (input.pill) { + switch (input.pill.tone) { + case "success": + return { kind: "success", text: "Updated" }; + case "error": + return { kind: "failed", text: input.pill.description }; + case "warning": + return { kind: "unchanged", text: input.pill.description }; + default: + return { kind: "loading", text: "Updating…" }; + } + } + if (input.isPending) { + return { kind: "loading", text: "Updating…" }; + } + return { kind: "idle", text: providerNamesFor(input.group) }; +} + +function rowToneClass(kind: RowStatusKind): string { + switch (kind) { + case "failed": + return "text-destructive"; + case "unchanged": + return "text-warning"; + case "success": + return "text-success"; + default: + return "text-muted-foreground"; + } +} + +function EnvironmentUpdateRow({ + group, + status, + onUpdate, +}: { + readonly group: LocalEnvironmentUpdateGroup; + readonly status: RowStatus; + readonly onUpdate: () => void; +}) { + let trailing: ReactNode; + switch (status.kind) { + case "loading": + trailing = ; + break; + case "success": + trailing =