feat(web): per-device provider settings #4479
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 8 commits into
main fromrefs/pull/4479/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/components/settings/ProviderSettingsPanel.logic.ts line 159Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +55,21 @@55+ | "offline"56+ | "connecting"57+ | "reconnecting"58+ | "connected"59+ | "error";60+ readonly hasServerConfig: boolean;61+ readonly canOperate: boolean | null;62+}): ProviderEnvironmentAccess {63+ if (input.connectionPhase === "error") {64+ return { kind: "error" };65+ }66+ if (input.connectionPhase !== "connected") {67+ return { kind: "unavailable" };68+ }69+ if (!input.hasServerConfig) {70+ return { kind: "loading" };71+ }72+ if (input.canOperate === false) {73+ return { kind: "read-only" };74+ }75+ return { kind: "editable" };apps/web/src/components/settings/ProviderSettingsPanel.tsx line 345Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +288,21 @@288+}) {289+ const primarySessionState = usePrimarySessionState();290+ const isPrimary = environment.entry.target._tag === "PrimaryConnectionTarget";291+ // Remote connection brokers request the standard client scopes, which include292+ // orchestration:operate. The environment RPC layer remains authoritative if a293+ // custom remote credential grants less access.294+ const canOperate = isPrimary295+ ? window.desktopBridge296+ ? true297+ : primarySessionState.data?.authenticated298+ ? (primarySessionState.data.scopes ?? []).includes(AuthOrchestrationOperateScope)299+ : null300+ : true;301+ const access = classifyProviderEnvironmentAccess({302+ connectionPhase: environment.connection.phase,303+ hasServerConfig: environment.serverConfig !== null,304+ canOperate,305+ });306+ if (access.kind !== "editable") {307+ return <EnvironmentUnavailableRow environment={environment} accessKind={access.kind} />;308+ }apps/web/src/components/settings/ProviderSettingsPanel.tsx line 228Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +205,21 @@205+ useEffect(() => {206+ if (effectiveEnvironmentId !== selectedEnvironmentId) {207+ setSelectedEnvironmentId(effectiveEnvironmentId);208+ }209+ }, [effectiveEnvironmentId, selectedEnvironmentId]);210+ const selectedEnvironment =211+ options.find((environment) => environment.environmentId === effectiveEnvironmentId) ?? null;212+ const showDeviceList =213+ options.length === 0 ||214+ options.length > 1 ||215+ options[0]?.entry.target._tag !== "PrimaryConnectionTarget";216+217+ return (218+ <SettingsPageContainer>219+ {showDeviceList ? (220+ <SettingsSection title="Devices">221+ {options.length === 0 ? (222+ <SettingsRow223+ title="No connected devices"224+ description="Connect an execution environment before configuring providers."225+ />
- apps/web/src/components/settings/ProviderSettingsPanel.tsx line 303OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +283,21 @@283+ {selectedEnvironment ? (284+ <SelectedEnvironmentProviderSettings285+ key={selectedEnvironment.environmentId}286+ environment={selectedEnvironment}287+ />288+ ) : null}289+ </SettingsPageContainer>290+ );291+}292+293+function SelectedEnvironmentProviderSettings({294+ environment,295+}: {296+ readonly environment: EnvironmentPresentation;297+}) {298+ const primarySessionState = usePrimarySessionState();299+ const isPrimary = environment.entry.target._tag === "PrimaryConnectionTarget";300+ // Remote connection brokers request the standard client scopes, which include301+ // orchestration:operate. The environment RPC layer remains authoritative if a302+ // custom remote credential grants less access.303+ const operateAccess: ProviderOperateAccess = !isPrimary
- apps/web/src/components/settings/ProviderSettingsPanel.tsx line 313OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +293,21 @@293+function SelectedEnvironmentProviderSettings({294+ environment,295+}: {296+ readonly environment: EnvironmentPresentation;297+}) {298+ const primarySessionState = usePrimarySessionState();299+ const isPrimary = environment.entry.target._tag === "PrimaryConnectionTarget";300+ // Remote connection brokers request the standard client scopes, which include301+ // orchestration:operate. The environment RPC layer remains authoritative if a302+ // custom remote credential grants less access.303+ const operateAccess: ProviderOperateAccess = !isPrimary304+ ? "granted"305+ : window.desktopBridge306+ ? "granted"307+ : primarySessionState.isPending308+ ? "pending"309+ : primarySessionState.data?.authenticated310+ ? (primarySessionState.data.scopes ?? []).includes(AuthOrchestrationOperateScope)311+ ? "granted"312+ : "denied"313+ : "denied";apps/web/src/components/settings/ProviderSettingsPanel.tsx line 367OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +347,21 @@347+ <SettingsRow348+ title="Read only"349+ description={`This session can view ${environment.label}, but it cannot change provider configuration.`}350+ />351+ {providers.map((provider) => {352+ const driverOption = getDriverOption(provider.driver);353+ const summary = getProviderSummary(provider);354+ const versionLabel = getProviderVersionLabel(provider.version);355+ return (356+ <SettingsRow357+ key={provider.instanceId}358+ title={359+ <span className="inline-flex items-center gap-2">360+ <span361+ className={cn(362+ "size-2 rounded-full",363+ PROVIDER_STATUS_STYLES[provider.status as ProviderStatusKey].dot,364+ )}365+ aria-hidden366+ />367+ {driverOption?.label ?? String(provider.driver)}apps/web/src/components/settings/ProviderSettingsPanel.tsx line 175OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +155,21 @@155+ return "bg-muted-foreground/40";156+ }157+}158+159+function EnvironmentUnavailableRow({160+ environment,161+ accessKind,162+}: {163+ readonly environment: EnvironmentPresentation;164+ readonly accessKind: "loading" | "unavailable" | "error";165+}) {166+ const title =167+ accessKind === "loading"168+ ? "Loading provider settings"169+ : accessKind === "error"170+ ? "Could not connect to this device"171+ : "Provider settings are unavailable";172+ const description =173+ accessKind === "loading"174+ ? `Waiting for ${environment.label}'s configuration.`175+ : connectionStatusText(environment.connection);
- apps/web/src/components/settings/ProviderSettingsPanel.tsx line 444Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +458,21 @@458+ if (refreshingRef.current) return;459+ refreshingRef.current = true;460+ setIsRefreshingProviders(true);461+ void (async () => {462+ const result = await refreshServerProviders({463+ environmentId,464+ input: {},465+ });466+ refreshingRef.current = false;467+ setIsRefreshingProviders(false);468+ if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {469+ console.warn("Failed to refresh providers", {470+ operation: "refresh-providers",471+ environmentId,472+ ...safeErrorLogAttributes(squashAtomCommandFailure(result)),473+ });474+ }475+ })();476+ }, [environmentId, refreshServerProviders]);477+478+ const runProviderUpdate = useCallback(
- apps/web/src/components/settings/ProviderSettingsPanel.tsx line 342Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +311,21 @@311+ );312+}313+314+function SelectedEnvironmentProviderSettings({315+ environment,316+}: {317+ readonly environment: EnvironmentPresentation;318+}) {319+ const primarySessionState = usePrimarySessionState();320+ const isPrimary = environment.entry.target._tag === "PrimaryConnectionTarget";321+ const operateAccess = resolvePrimaryOperateAccess({322+ isPrimary,323+ hasDesktopBridge: Boolean(window.desktopBridge),324+ session: primarySessionState.data,325+ isPending: primarySessionState.isPending,326+ });327+ const access = classifyProviderEnvironmentAccess({328+ connectionPhase: environment.connection.phase,329+ hasServerConfig: environment.serverConfig !== null,330+ operateAccess,331+ });
- apps/web/src/components/settings/ProviderSettingsPanel.tsx lines 557 to 570OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +550,21 @@550+ for (const providerSettings of visibleProviderSettings) {551+ type LegacyProviderSettings = (typeof settings.providers)[keyof typeof settings.providers];552+ const legacyProviders = settings.providers as Record<string, LegacyProviderSettings>;553+ const defaultLegacyProviders = DEFAULT_UNIFIED_SETTINGS.providers as Record<554+ string,555+ LegacyProviderSettings556+ >;557+ const driver = providerSettings.provider;558+ const defaultInstanceId = defaultInstanceIdForDriver(driver);559+ const explicitInstance = settings.providerInstances?.[defaultInstanceId];560+ const legacyConfig = legacyProviders[providerSettings.provider]!;561+ const defaultLegacyConfig = defaultLegacyProviders[providerSettings.provider]!;562+ const effectiveInstance: ProviderInstanceConfig =563+ explicitInstance ??564+ ({565+ driver,566+ enabled: legacyConfig.enabled,567+ config: legacyConfig,568+ } satisfies ProviderInstanceConfig);569+ const isDirty =570+ explicitInstance !== undefined || !Equal.equals(legacyConfig, defaultLegacyConfig);
- apps/web/src/components/settings/ProviderSettingsPanel.tsx line 360OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -0,0 +340,21 @@340+ environmentLabel={environment.label}341+ />342+ );343+}344+345+/**346+ * Connected devices this session may read but not reconfigure. The provider347+ * catalogue is still worth showing — knowing which providers a box has and348+ * whether they are authenticated is most of the value — so render each one as349+ * a status row and omit every mutation control.350+ */351+function ReadOnlyProviderSettings({352+ environment,353+}: {354+ readonly environment: EnvironmentPresentation;355+}) {356+ // `deriveProviderInstanceEntries` resolves the same per-instance display name357+ // the pickers use, so two instances of one driver stay distinguishable here.358+ const entries = deriveProviderInstanceEntries(359+ environment.serverConfig?.providers ?? EMPTY_SERVER_PROVIDERS,360+ );
- apps/web/src/components/settings/ProviderSettingsPanel.tsx line 553Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +557,21 @@557+ >;558+ const driver = providerSettings.provider;559+ const defaultInstanceId = defaultInstanceIdForDriver(driver);560+ const explicitInstance = settings.providerInstances?.[defaultInstanceId];561+ // A remote device may run a server version whose settings predate this562+ // driver, so the legacy mirror can be absent. Without either an explicit563+ // instance or a legacy blob there is nothing to render for the slot.564+ const legacyConfig = legacyProviders[providerSettings.provider];565+ const defaultLegacyConfig = defaultLegacyProviders[providerSettings.provider];566+ const effectiveInstance: ProviderInstanceConfig | undefined =567+ explicitInstance ??568+ (legacyConfig !== undefined569+ ? ({570+ driver,571+ enabled: legacyConfig.enabled,572+ config: legacyConfig,573+ } satisfies ProviderInstanceConfig)574+ : undefined);575+ if (effectiveInstance === undefined) {576+ continue;577+ }
- @@ -0,0 +872,21 @@872+ modelOrder,873+ })874+ }875+ onRunUpdate={876+ showInlineUpdateButton && updateCandidate877+ ? () => {878+ if (!canRunInlineUpdate) {879+ return;880+ }881+ void runProviderUpdate(updateCandidate);882+ }883+ : undefined884+ }885+ isUpdating={showInlineUpdateButton ? isDriverUpdateRunning : undefined}886+ />887+ );888+ })}889+ </div>890+ </SettingsSection>891+892+ {isAddInstanceDialogOpen ? (
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share