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.
161 lines
6.3 KiB
TypeScript
161 lines
6.3 KiB
TypeScript
import { redactSensitiveUrl } from '@/lib/desktopHosts';
|
|
|
|
export type RecoveryVariant =
|
|
| 'local-unavailable'
|
|
| 'remote-unreachable'
|
|
| 'remote-incompatible'
|
|
| 'remote-wrong-service'
|
|
| 'remote-missing'
|
|
| 'missing-default-host';
|
|
|
|
export type DesktopRecoveryConfig = {
|
|
title: string;
|
|
description: string;
|
|
titleKey: string;
|
|
descriptionKey: string;
|
|
descriptionParams?: Record<string, string>;
|
|
iconKey: 'local' | 'remote';
|
|
showRetry: boolean;
|
|
retryLabel?: string;
|
|
retryLabelKey?: string;
|
|
showUseLocal: boolean;
|
|
showUseRemote: boolean;
|
|
/** Label for the "use local" primary action button */
|
|
useLocalLabel: string;
|
|
useLocalLabelKey: string;
|
|
/** Label for the "use remote" primary action button */
|
|
useRemoteLabel: string;
|
|
useRemoteLabelKey: string;
|
|
};
|
|
|
|
function formatHostDisplay(hostLabel?: string, hostUrl?: string): string | undefined {
|
|
if (hostLabel?.trim()) return redactSensitiveUrl(hostLabel.trim());
|
|
if (hostUrl) return redactSensitiveUrl(hostUrl);
|
|
return undefined;
|
|
}
|
|
|
|
export function getDesktopRecoveryConfig(
|
|
variant: RecoveryVariant,
|
|
hostLabel?: string,
|
|
hostUrl?: string,
|
|
): DesktopRecoveryConfig {
|
|
switch (variant) {
|
|
case 'local-unavailable':
|
|
return {
|
|
title: 'Local OpenCode Unavailable',
|
|
description: 'OpenCode CLI could not be started or is not installed. Install OpenCode or connect to a remote server instead.',
|
|
titleKey: 'onboarding.desktopRecovery.localUnavailable.title',
|
|
descriptionKey: 'onboarding.desktopRecovery.localUnavailable.description',
|
|
iconKey: 'local',
|
|
showRetry: true,
|
|
retryLabel: 'Retry Local',
|
|
retryLabelKey: 'onboarding.desktopRecovery.localUnavailable.retry',
|
|
showUseLocal: true,
|
|
showUseRemote: true,
|
|
useLocalLabel: 'Set Up Local',
|
|
useLocalLabelKey: 'onboarding.desktopRecovery.localUnavailable.useLocal',
|
|
useRemoteLabel: 'Use Remote',
|
|
useRemoteLabelKey: 'onboarding.desktopRecovery.common.useRemote',
|
|
};
|
|
|
|
case 'remote-missing':
|
|
return {
|
|
title: 'No Default Connection',
|
|
description: 'Your saved default connection could not be found. Choose how you want to connect.',
|
|
titleKey: 'onboarding.desktopRecovery.noDefaultConnection.title',
|
|
descriptionKey: 'onboarding.desktopRecovery.noDefaultConnection.description',
|
|
iconKey: 'local',
|
|
showRetry: false,
|
|
showUseLocal: true,
|
|
showUseRemote: true,
|
|
useLocalLabel: 'Use Local',
|
|
useLocalLabelKey: 'onboarding.desktopRecovery.common.useLocal',
|
|
useRemoteLabel: 'Use Remote',
|
|
useRemoteLabelKey: 'onboarding.desktopRecovery.common.useRemote',
|
|
};
|
|
|
|
case 'remote-unreachable': {
|
|
const host = formatHostDisplay(hostLabel, hostUrl);
|
|
return {
|
|
title: 'Remote Server Unreachable',
|
|
description: `Could not connect to "${host || 'the remote server'}". Check your network connection and verify the server address.`,
|
|
titleKey: 'onboarding.desktopRecovery.remoteUnreachable.title',
|
|
descriptionKey: 'onboarding.desktopRecovery.remoteUnreachable.description',
|
|
descriptionParams: host ? { host } : undefined,
|
|
iconKey: 'remote',
|
|
showRetry: true,
|
|
retryLabel: 'Retry Connection',
|
|
retryLabelKey: 'onboarding.desktopRecovery.remoteUnreachable.retry',
|
|
showUseLocal: true,
|
|
showUseRemote: true,
|
|
useLocalLabel: 'Use Local',
|
|
useLocalLabelKey: 'onboarding.desktopRecovery.common.useLocal',
|
|
useRemoteLabel: 'Use Remote',
|
|
useRemoteLabelKey: 'onboarding.desktopRecovery.common.useRemote',
|
|
};
|
|
}
|
|
|
|
case 'remote-wrong-service': {
|
|
const host = formatHostDisplay(hostLabel, hostUrl);
|
|
return {
|
|
title: 'Incompatible Server',
|
|
description: `The server at "${host || 'unknown'}" is not running OpenChamber. Verify the address points to an OpenChamber server.`,
|
|
titleKey: 'onboarding.desktopRecovery.incompatibleServer.title',
|
|
descriptionKey: 'onboarding.desktopRecovery.incompatibleServer.description',
|
|
descriptionParams: host ? { host } : undefined,
|
|
iconKey: 'remote',
|
|
showRetry: false,
|
|
showUseLocal: true,
|
|
showUseRemote: true,
|
|
useLocalLabel: 'Use Local',
|
|
useLocalLabelKey: 'onboarding.desktopRecovery.common.useLocal',
|
|
useRemoteLabel: 'Use Remote',
|
|
useRemoteLabelKey: 'onboarding.desktopRecovery.common.useRemote',
|
|
};
|
|
}
|
|
|
|
case 'remote-incompatible': {
|
|
const host = formatHostDisplay(hostLabel, hostUrl);
|
|
return {
|
|
title: 'Server Update Required',
|
|
description: `The OpenChamber server at "${host || 'unknown'}" is not compatible with this app version. Update OpenChamber on the server, then try again.`,
|
|
titleKey: 'onboarding.desktopRecovery.remoteIncompatible.title',
|
|
descriptionKey: 'onboarding.desktopRecovery.remoteIncompatible.description',
|
|
descriptionParams: host ? { host } : undefined,
|
|
iconKey: 'remote',
|
|
showRetry: true,
|
|
retryLabel: 'Retry Connection',
|
|
retryLabelKey: 'onboarding.desktopRecovery.remoteUnreachable.retry',
|
|
showUseLocal: true,
|
|
showUseRemote: true,
|
|
useLocalLabel: 'Use Local',
|
|
useLocalLabelKey: 'onboarding.desktopRecovery.common.useLocal',
|
|
useRemoteLabel: 'Use Remote',
|
|
useRemoteLabelKey: 'onboarding.desktopRecovery.common.useRemote',
|
|
};
|
|
}
|
|
|
|
case 'missing-default-host':
|
|
return {
|
|
title: 'No Default Connection',
|
|
description: 'Your saved default connection could not be found. Choose how you want to connect.',
|
|
titleKey: 'onboarding.desktopRecovery.noDefaultConnection.title',
|
|
descriptionKey: 'onboarding.desktopRecovery.noDefaultConnection.description',
|
|
iconKey: 'local',
|
|
showRetry: false,
|
|
showUseLocal: true,
|
|
showUseRemote: true,
|
|
useLocalLabel: 'Use Local',
|
|
useLocalLabelKey: 'onboarding.desktopRecovery.common.useLocal',
|
|
useRemoteLabel: 'Use Remote',
|
|
useRemoteLabelKey: 'onboarding.desktopRecovery.common.useRemote',
|
|
};
|
|
|
|
default: {
|
|
// TypeScript exhaustive check - this should never be reached
|
|
const exhaustive: never = variant;
|
|
throw new Error(`Unknown recovery variant: ${exhaustive}`);
|
|
}
|
|
}
|
|
}
|