Files
openchamber/packages/ui/src/components/onboarding/DesktopConnectionRecovery.tsx
T
Bohdan Triapitsyn 2031e3b4a8 Decouple bundled UI from runtime API and add remote instance tooling (#1228)
Add a packaged-client runtime boundary so the shared UI can talk to local,
desktop, remote, and VS Code runtimes through the right transport instead of
assuming one same-origin web server.

Centralize OpenChamber-owned API access behind RuntimeAPIs, runtimeFetch, and
runtime URL helpers, while keeping official OpenCode traffic on the SDK path.
Support runtime switching, remote host selection, desktop client credentials,
and headless connection links for pairing packaged clients with remote
OpenChamber servers.

Harden the new auth model by moving long-lived client tokens out of browser
URLs, introducing short-lived scoped URL tokens for browser-owned transports,
restricting URL-token access to explicit readable/realtime routes, and making
client-token management session-scoped or self-scoped as appropriate.

Update browser-owned assets and preview proxy flows to work with the split
runtime model, including authenticated project icons, preview token propagation,
CSP-safe preview bridge injection, and preview proxy auth that survives
short-lived URL-token expiry.

Tighten Electron security boundaries for packaged clients by gating privileged
preload state to trusted origins and requiring explicit confirmation before
connect deep-links import or switch remote runtimes.

Also refresh agent guidance and project skills so future runtime/API, auth,
preview, UI, CLI, settings, locale, and drag-to-reorder work follows the new
architecture.
2026-06-02 00:43:05 +03:00

139 lines
4.7 KiB
TypeScript

import React from 'react';
import { Button } from '@/components/ui/button';
import { Icon } from "@/components/icon/Icon";
import { useI18n } from '@/lib/i18n';
import { cn } from '@/lib/utils';
import { redactSensitiveUrl } from '@/lib/desktopHosts';
import {
getDesktopRecoveryConfig,
type RecoveryVariant,
} from './desktopRecoveryConfig';
export type { RecoveryVariant } from './desktopRecoveryConfig';
export type DesktopConnectionRecoveryProps = {
variant: RecoveryVariant;
hostLabel?: string;
hostUrl?: string;
onRetry?: () => void;
onUseLocal?: () => void;
onUseRemote?: () => void;
isRetrying?: boolean;
};
/** Maps iconKey from config to actual icon component */
function getRecoveryIcon(iconKey: 'local' | 'remote'): React.ReactNode {
switch (iconKey) {
case 'local':
return <Icon name="macbook" className="h-8 w-8" />;
case 'remote':
return <Icon name="server" className="h-8 w-8" />;
}
}
export function DesktopConnectionRecovery({
variant,
hostLabel,
hostUrl,
onRetry,
onUseLocal,
onUseRemote,
isRetrying = false,
}: DesktopConnectionRecoveryProps) {
const { t } = useI18n();
const config = getDesktopRecoveryConfig(variant, hostLabel, hostUrl);
const retryLabelKey = (config.retryLabelKey ?? 'onboarding.desktopRecovery.actions.retryConnection') as Parameters<typeof t>[0];
const descriptionParams = React.useMemo(() => {
if (config.descriptionParams?.host) {
return config.descriptionParams;
}
if (variant === 'remote-unreachable') {
return { host: t('onboarding.desktopRecovery.placeholders.remoteServer') };
}
if (variant === 'remote-wrong-service' || variant === 'remote-incompatible') {
return { host: t('onboarding.desktopRecovery.placeholders.unknownServer') };
}
return undefined;
}, [config.descriptionParams, t, variant]);
return (
<div className="flex flex-col items-center justify-center h-full p-8">
<div className="w-full max-w-md space-y-6">
{/* Icon and title */}
<div className="flex flex-col items-center space-y-3 text-center">
<div
className="p-3 rounded-full"
style={{
backgroundColor: 'var(--status-warning)',
opacity: 0.15,
}}
>
<div style={{ color: 'var(--status-warning)' }}>
{getRecoveryIcon(config.iconKey)}
</div>
</div>
<h1 className="typography-ui-header text-xl font-semibold text-foreground">
{t(config.titleKey as Parameters<typeof t>[0])}
</h1>
<p className="text-muted-foreground text-sm max-w-sm">
{t(
config.descriptionKey as Parameters<typeof t>[0],
descriptionParams
)}
</p>
</div>
{/* Host info if available */}
{hostUrl && (variant === 'remote-unreachable' || variant === 'remote-wrong-service' || variant === 'remote-incompatible') && (
<div className="rounded-lg border border-border bg-background/50 p-3">
<div className="text-xs text-muted-foreground mb-1">{t('onboarding.remoteConnection.field.serverAddress')}</div>
<div className="font-mono text-sm text-foreground truncate">{redactSensitiveUrl(hostUrl)}</div>
</div>
)}
{/* Action buttons */}
<div className="flex flex-col gap-2">
{config.showRetry && onRetry && (
<Button
onClick={onRetry}
disabled={isRetrying}
className="w-full"
>
<Icon name="refresh" className={cn('h-4 w-4', isRetrying && 'animate-spin')} />
{isRetrying
? t('onboarding.desktopRecovery.actions.retrying')
: t(retryLabelKey)}
</Button>
)}
<div className="flex gap-2">
{config.showUseLocal && onUseLocal && (
<Button
variant="outline"
onClick={onUseLocal}
disabled={isRetrying}
className="flex-1"
>
<Icon name="macbook" className="h-4 w-4" />
{t(config.useLocalLabelKey as Parameters<typeof t>[0])}
</Button>
)}
{config.showUseRemote && onUseRemote && (
<Button
variant="outline"
onClick={onUseRemote}
disabled={isRetrying}
className="flex-1"
>
<Icon name="server" className="h-4 w-4" />
{t(config.useRemoteLabelKey as Parameters<typeof t>[0])}
</Button>
)}
</div>
</div>
</div>
</div>
);
}