fix(remote): group verified instances without dropping authorizations

This commit is contained in:
Xubin Ren committed 2026-10-02 11:36:34 +08:00
1 parent 94c137511a
commit 450e455b57
21 files changed
+496 -27

No files matched your search

@@ -15,7 +15,8 @@ import { useRemoteConnections } from "./RemoteInstances";
import { PairRouteSettings } from "./PairRouteSettings";
type Request = { id: string; command: string; expires: number };
type Preview = { id: string; host: string; hostname: string; fingerprint: string; authorized_until: number; revoke_command: string };
type Preview = { id: string; host: string; hostname: string; fingerprint: string; authorized_until: number; revoke_command: string;
existing_connection?: { id: string; name: string; connected: boolean } };
/** Public invitation → encrypted receipt → explicit confirmation. No private key inputs. */
export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairReturn | null; onSSH: () => void; onClose: () => void }) {
@@ -128,14 +129,14 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
const invalidReturn = ["pair_invalid", "pair_expired", "pair_used"].some((code) => error === `remote.errors.${code}`);
const restartAvailable = !saved && (expired || (!!error && !request?.command && !preview && (!returned || invalidReturn)));
const reviewingReturn = !!returned && !request?.command && !preview && !manual && !restartAvailable;
const title = preview ? "remote.pair.confirmTitle" : reviewingReturn ? "remote.pair.review" : restartAvailable ? "remote.add"
const title = preview ? preview.existing_connection ? "remote.sameInstance.title" : "remote.pair.confirmTitle" : reviewingReturn ? "remote.pair.review" : restartAvailable ? "remote.add"
: manual ? "remote.pair.code" : copied ? "remote.pair.copiedTitle" : "remote.add";
const description = preview || reviewingReturn ? "remote.pair.confirmLinkDescription" : restartAvailable ? "remote.pair.introHint"
: manual ? "remote.pair.codeHint" : copied ? "remote.pair.afterCopyHint" : "remote.pair.introHint";
const showCopied = copied && !manual && !preview && !restartAvailable;
const showIllustration = !preview && !manual && !reviewingReturn && !restartAvailable;
const showBusy = pending && busyVisible;
const actionLabel = restartAvailable ? "remote.pair.restart" : reviewingReturn ? error ? "remote.retry" : "remote.pair.review" : preview ? saved ? "remote.retry" : "remote.connect"
const actionLabel = restartAvailable ? "remote.pair.restart" : reviewingReturn ? error ? "remote.retry" : "remote.pair.review" : preview ? saved ? "remote.retry" : preview.existing_connection ? "remote.sameInstance.saveAndOpen" : "remote.connect"
: manual ? "remote.pair.review" : copied ? "remote.pair.copyAgain" : "remote.pair.copy";
const busyLabel = waitingForLocal ? "remote.pair.waitingForLocal" : preview ? "remote.connecting" : !restartAvailable && (manual || returned)
? "remote.pair.checkingLink" : "remote.pair.preparing";
@@ -154,9 +155,10 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
</DialogHeader>
{preview ? <div className="space-y-4 pt-4">
<div className="rounded-2xl bg-muted/50 p-4">
<p className="font-medium">{preview.hostname}</p>
<p className="font-medium">{preview.existing_connection?.name || preview.hostname}</p>
<p className="mt-1 break-all text-xs text-muted-foreground">{preview.host}</p>
</div>
{preview.existing_connection && <p role="status" className="text-xs leading-5 text-muted-foreground">{t("remote.sameInstance.pairHint")}</p>}
<p className="text-[13px] leading-5">{t("remote.pair.access")}</p>
<p className="text-xs leading-5 text-muted-foreground">{t("remote.pair.expiry", { date: new Date(preview.authorized_until * 1000).toLocaleDateString() })}</p>
<Disclosure className="text-xs text-muted-foreground" summaryClassName="flex min-h-9 items-center gap-2 rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
@@ -8,7 +8,7 @@ import { DisclosureContent } from "@/components/ui/disclosure";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { useClient } from "@/providers/ClientProvider";
import { remoteAction, type RemoteInspection, type RemoteProfile } from "@/lib/remote-instances";
import { groupRemoteProfiles, remoteAction, type RemoteInspection, type RemoteProfile } from "@/lib/remote-instances";
import { cn } from "@/lib/utils";
import { parseSSHAddress } from "@/lib/ssh-address";
import { clearPairReturn, readPairReturn, subscribePairReturn } from "@/lib/remote-pair-return";
@@ -37,6 +37,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
const returnedPair = useSyncExternalStore(subscribePairReturn, readPairReturn);
const [quickOpen, setQuickOpen] = useState(!!returnedPair);
const [pairRoute, setPairRoute] = useState("");
const [details, setDetails] = useState("");
const [editing, setEditing] = useState(false);
const [savedId, setSavedId] = useState("");
const [busy, setBusy] = useState("");
@@ -247,6 +248,16 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
setInspection(null); setManualLocation(false); setInspectBeforeConnect(true);
setError(""); setErrorCode(""); setSSHOptions(true);
};
const groups = groupRemoteProfiles(directory?.profiles || [], connections.activeHostId);
const detailGroup = groups.find((group) => group.id === details);
const detailConnection = detailGroup?.connections.find((profile) => profile.connected || connections.openHostIds.includes(profile.id));
const removalIsShared = groups.some((group) => group.connections.length > 1 && group.connections.some((profile) => profile.id === removalProfile?.id));
const connectionActions = (profile: RemoteProfile, grouped = false) => <>
{!profile.paired && <DropdownMenuItem disabled={profile.connected || connections.openHostIds.includes(profile.id)} onSelect={() => { setDetails(""); beginEditor(profile); }}>{t("remote.edit")}</DropdownMenuItem>}
{profile.paired && <DropdownMenuItem disabled={profile.connected || connections.openHostIds.includes(profile.id)} onSelect={() => { setDetails(""); setPairRoute(profile.id); }}>{t("remote.pair.route")}</DropdownMenuItem>}
{(profile.connected || connections.openHostIds.includes(profile.id)) && <DropdownMenuItem onSelect={() => { setDetails(""); setError(""); setDisconnecting(profile); }}>{t("remote.disconnect")}</DropdownMenuItem>}
<DropdownMenuItem tone="destructive" onSelect={() => { setDetails(""); setError(""); setRemoving(profile); }}>{t(grouped ? "remote.sameInstance.forgetConnection" : "remote.forget")}</DropdownMenuItem>
</>;
return <div ref={page} tabIndex={-1} role="region" aria-label={t("remote.title")} className="flex min-h-0 flex-1 flex-col overflow-hidden bg-settings-canvas outline-none">
<div className="min-w-0 flex-1 overflow-y-auto [scrollbar-gutter:stable]">
@@ -272,7 +283,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
</button>
</SettingsGroup>
{directory.profiles.length > 0 && <SettingsGroup>
{directory.profiles.map((profile) => <div key={profile.id} className="settings-list-row settings-hover flex items-center gap-2 transition-colors">
{groups.map(({ id: groupId, profile, connections: entries }) => <div key={groupId} className="settings-list-row settings-hover flex items-center gap-2 transition-colors">
<button type="button" aria-label={`${profile.name} ${profile.host}`} aria-describedby={`${statusId}-${profile.id}`}
aria-current={connections.activeHostId === profile.id || undefined}
className="flex min-h-[60px] min-w-0 flex-1 items-center gap-3 rounded-xl py-3 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" disabled={!!busy} onClick={(event) => {
@@ -280,6 +291,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
}}>
{busy === profile.id ? <Loader2 className="h-[18px] w-[18px] shrink-0 animate-spin text-muted-foreground" /> : <Server className="h-[18px] w-[18px] shrink-0 text-muted-foreground" />}
<span className="min-w-0 flex-1"><span className="block truncate text-[14px] font-medium">{profile.name}</span><span className="mt-0.5 block truncate text-xs text-muted-foreground">{profile.host}</span>
{groups.some((other) => other.id !== groupId && other.profile.name === profile.name && other.profile.host === profile.host) && <span className="mt-0.5 block truncate text-xs text-muted-foreground" title={profile.config_path}>{profile.port ? `:${profile.port} · ` : ""}{profile.config_path}</span>}
<span id={`${statusId}-${profile.id}`} className="mt-1 block"><HostConnectionStatus state={connections.hostStates[profile.id] || "closed"} /></span>
{profile.paired && typeof profile.authorized_until === "number" && Number.isFinite(profile.authorized_until)
&& profile.authorized_until * 1000 <= Date.now() + 7 * 86_400_000 && <span className="mt-1 block text-xs leading-5 text-muted-foreground">
@@ -295,10 +307,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
onKeyDown={(event) => { editorTrigger.current = event.currentTarget; }}
aria-label={t("remote.manage", { name: profile.name })}><MoreHorizontal className="h-4 w-4" /></Button></DropdownMenuTrigger>
<DropdownMenuContent align="end">
{!profile.paired && <DropdownMenuItem disabled={profile.connected || connections.openHostIds.includes(profile.id)} onSelect={() => beginEditor(profile)}>{t("remote.edit")}</DropdownMenuItem>}
{profile.paired && <DropdownMenuItem disabled={profile.connected || connections.openHostIds.includes(profile.id)} onSelect={() => setPairRoute(profile.id)}>{t("remote.pair.route")}</DropdownMenuItem>}
{(profile.connected || connections.openHostIds.includes(profile.id)) && <DropdownMenuItem onSelect={() => { setError(""); setDisconnecting(profile); }}>{t("remote.disconnect")}</DropdownMenuItem>}
<DropdownMenuItem tone="destructive" onSelect={() => { setError(""); setRemoving(profile); }}>{t("remote.forget")}</DropdownMenuItem>
{entries.length > 1 ? <DropdownMenuItem onSelect={() => setDetails(groupId)}>{t("remote.sameInstance.details")}</DropdownMenuItem> : connectionActions(profile)}
</DropdownMenuContent>
</DropdownMenu>
</div>)}
@@ -323,6 +332,28 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
</div>
</div>
<Dialog open={!!detailGroup} onOpenChange={(open) => { if (!open) setDetails(""); }}>
<DialogContent className="flex max-h-[85dvh] max-w-md flex-col overflow-hidden">
<DialogHeader className="pr-5 text-left"><DialogTitle>{t("remote.sameInstance.details")}</DialogTitle><DialogDescription>{t("remote.sameInstance.detailsHint")}</DialogDescription></DialogHeader>
<div className="min-h-0 space-y-2 overflow-y-auto">
{detailGroup?.connections.map((profile, index) => <div key={profile.id} className="flex items-center gap-2 rounded-2xl bg-muted/40 p-3">
<button type="button" disabled={!!busy || (!!detailConnection && detailConnection.id !== profile.id)} aria-current={connections.activeHostId === profile.id || undefined}
className="min-w-0 flex-1 rounded-xl text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
onClick={() => { setDetails(""); void connect(profile.id); }}>
<span className="flex items-center gap-2 text-[13px] font-medium">{t("remote.sameInstance.connection", { count: index + 1 })}{connections.activeHostId === profile.id && <Check aria-label={t("remote.current")} className="h-3.5 w-3.5" />}</span>
<span className="mt-1 block truncate text-xs text-muted-foreground">{profile.host}</span>
<HostConnectionStatus state={connections.hostStates[profile.id] || "closed"} />
{profile.authorized_until != null && <span className="mt-1 block text-xs text-muted-foreground">{t(profile.authorized_until * 1000 <= Date.now() ? "remote.pair.expiredDevice" : "remote.pair.expiringDevice", { date: new Date(profile.authorized_until * 1000).toLocaleString() })}</span>}
</button>
<DropdownMenu><DropdownMenuTrigger asChild><Button size="icon" variant="ghost" className="h-8 w-8 shrink-0" disabled={!!busy} aria-label={t("remote.sameInstance.manageConnection", { count: index + 1 })}><MoreHorizontal className="h-4 w-4" /></Button></DropdownMenuTrigger>
<DropdownMenuContent align="end">{connectionActions(profile, true)}</DropdownMenuContent>
</DropdownMenu>
</div>)}
</div>
{detailConnection && <p className="text-xs leading-5 text-muted-foreground">{t("remote.sameInstance.switchHint")}</p>}
</DialogContent>
</Dialog>
<Dialog open={quickOpen} onOpenChange={(open) => { setQuickOpen(open); if (!open) clearPairReturn(); }}>
<DialogContent className="flex max-h-[85dvh] max-w-md flex-col overflow-hidden">
{quickOpen && <QuickPairSetup key={returnedPair?.code || "new"} returned={returnedPair} onSSH={() => { clearPairReturn(); setQuickOpen(false); beginEditor(); }} onClose={() => { clearPairReturn(); setQuickOpen(false); }} />}
@@ -437,11 +468,11 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
</DialogContent>
</Dialog>
<Dialog open={!!removing} onOpenChange={(value) => { if (!value && !busy) setRemoving(null); }}>
<DialogContent className="max-h-[85dvh] max-w-sm overflow-y-auto"><DialogHeader className="pr-5 text-left"><DialogTitle className="break-words leading-snug">{t("remote.forgetTitle", { name: removalProfile?.name })}</DialogTitle><DialogDescription>{t("remote.forgetDescription")}</DialogDescription></DialogHeader>
<DialogContent className="max-h-[85dvh] max-w-sm overflow-y-auto"><DialogHeader className="pr-5 text-left"><DialogTitle className="break-words leading-snug">{t(removalIsShared ? "remote.sameInstance.forgetTitle" : "remote.forgetTitle", { name: removalProfile?.name })}</DialogTitle><DialogDescription>{t(removalIsShared ? "remote.sameInstance.forgetHint" : "remote.forgetDescription")}</DialogDescription></DialogHeader>
{removalProfile && (removalProfile.connected || connections.openHostIds.includes(removalProfile.id)) && <p role="note" className="rounded-xl bg-muted/40 p-3 text-xs leading-5">{t("remote.activeForgetWarning")}</p>}
{removalProfile?.paired && <div className="space-y-2 text-xs text-muted-foreground"><p>{t("remote.pair.forgetHint")}</p><code className="block break-all">{removalProfile.revoke_command}</code></div>}
{error && <p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{error}</p>}
<div className="grid grid-cols-2 gap-2"><Button variant="ghost" disabled={!!busy} onClick={() => setRemoving(null)}>{t("common.cancel")}</Button><Button variant="destructive" className="min-w-0" disabled={!!busy} aria-busy={!!busy} onClick={() => { void remove(); }}>{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}<span className="truncate">{t("remote.forget")}</span></Button></div>
<div className="grid grid-cols-2 gap-2"><Button variant="ghost" disabled={!!busy} onClick={() => setRemoving(null)}>{t("common.cancel")}</Button><Button variant="destructive" className="h-auto min-h-10 min-w-0" disabled={!!busy} aria-busy={!!busy} onClick={() => { void remove(); }}>{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}<span className="whitespace-normal break-words">{t(removalIsShared ? "remote.sameInstance.forgetAction" : "remote.forget")}</span></Button></div>
</DialogContent>
</Dialog>
</div>;
@@ -2,7 +2,7 @@ import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState
import { Loader2, PlugZap } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { needsRemoteSetup, type RemoteDirectory } from "@/lib/remote-instances";
import { groupRemoteProfiles, needsRemoteSetup, type RemoteDirectory } from "@/lib/remote-instances";
import { useHostSessions } from "./useHostSessions";
import { HostNavigationContext, HostSwitcher, RemoteHostMenu, type HostPicker } from "./HostSwitcher";
import { useSidebarHostBridge } from "./useSidebarHostBridge";
@@ -101,7 +101,8 @@ export function RemoteInstances({ children }: { children: ReactNode }) {
const picker: HostPicker = {
kind: "shell", name: selected?.name || t("remote.localShort"), hostname: selected?.hostname || directory?.machine_name || "nanobot",
localName: directory?.machine_name || "nanobot", currentId: selected?.id || null, recentIds: hosts.recentIds,
profiles: (directory?.profiles || []).map(({ id, name, host }) => ({ id, name, host, state: hostStates[id] })),
profiles: groupRemoteProfiles(directory?.profiles || [], selected?.id || null)
.map(({ profile: { id, name, host } }) => ({ id, name, host, state: hostStates[id] })),
pending, error: message, offline: !!offline,
select: (id) => {
if (!id) selectLocal();
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "Forget",
"switchHint": "To use another authorization, disconnect the open connection first.",
"title": "This nanobot is already saved",
"saveAndOpen": "Save and open",
"pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
"details": "Connection details",
"detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
"connection": "Connection {{count}}",
"manageConnection": "Manage connection {{count}}",
"forgetConnection": "Forget connection",
"forgetTitle": "Forget this connection?",
"forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
},
"activeForgetWarning": "All tabs using this connection will disconnect. Unsaved work may be lost.",
"saved": "Saved",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "Forget",
"switchHint": "To use another authorization, disconnect the open connection first.",
"title": "This nanobot is already saved",
"saveAndOpen": "Save and open",
"pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
"details": "Connection details",
"detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
"connection": "Connection {{count}}",
"manageConnection": "Manage connection {{count}}",
"forgetConnection": "Forget connection",
"forgetTitle": "Forget this connection?",
"forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
},
"activeForgetWarning": "Se desconectarán todas las pestañas que usen esta conexión. El trabajo sin guardar puede perderse.",
"saved": "Guardado",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "Forget",
"switchHint": "To use another authorization, disconnect the open connection first.",
"title": "This nanobot is already saved",
"saveAndOpen": "Save and open",
"pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
"details": "Connection details",
"detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
"connection": "Connection {{count}}",
"manageConnection": "Manage connection {{count}}",
"forgetConnection": "Forget connection",
"forgetTitle": "Forget this connection?",
"forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
},
"activeForgetWarning": "Tous les onglets utilisant cette connexion seront déconnectés. Le travail non enregistré peut être perdu.",
"saved": "Enregistré",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "Forget",
"switchHint": "To use another authorization, disconnect the open connection first.",
"title": "This nanobot is already saved",
"saveAndOpen": "Save and open",
"pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
"details": "Connection details",
"detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
"connection": "Connection {{count}}",
"manageConnection": "Manage connection {{count}}",
"forgetConnection": "Forget connection",
"forgetTitle": "Forget this connection?",
"forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
},
"activeForgetWarning": "Semua tab yang memakai koneksi ini akan terputus. Pekerjaan yang belum disimpan dapat hilang.",
"saved": "Tersimpan",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "Forget",
"switchHint": "To use another authorization, disconnect the open connection first.",
"title": "This nanobot is already saved",
"saveAndOpen": "Save and open",
"pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
"details": "Connection details",
"detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
"connection": "Connection {{count}}",
"manageConnection": "Manage connection {{count}}",
"forgetConnection": "Forget connection",
"forgetTitle": "Forget this connection?",
"forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
},
"activeForgetWarning": "この接続を使用しているすべてのタブが切断されます。未保存の内容が失われる可能性があります。",
"saved": "保存済み",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "Forget",
"switchHint": "To use another authorization, disconnect the open connection first.",
"title": "This nanobot is already saved",
"saveAndOpen": "Save and open",
"pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
"details": "Connection details",
"detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
"connection": "Connection {{count}}",
"manageConnection": "Manage connection {{count}}",
"forgetConnection": "Forget connection",
"forgetTitle": "Forget this connection?",
"forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
},
"activeForgetWarning": "이 연결을 사용하는 모든 탭의 연결이 끊어집니다. 저장하지 않은 내용이 손실될 수 있습니다.",
"saved": "저장됨",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "Forget",
"switchHint": "To use another authorization, disconnect the open connection first.",
"title": "This nanobot is already saved",
"saveAndOpen": "Save and open",
"pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
"details": "Connection details",
"detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
"connection": "Connection {{count}}",
"manageConnection": "Manage connection {{count}}",
"forgetConnection": "Forget connection",
"forgetTitle": "Forget this connection?",
"forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
},
"activeForgetWarning": "Todas as abas que usam esta conexão serão desconectadas. O trabalho não salvo pode ser perdido.",
"saved": "Salvo",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "Forget",
"switchHint": "To use another authorization, disconnect the open connection first.",
"title": "This nanobot is already saved",
"saveAndOpen": "Save and open",
"pairHint": "Keep one server entry. This authorization will be saved too; existing connections are kept.",
"details": "Connection details",
"detailsHint": "These connections open the same nanobot. Choose one to use, or manage its authorization.",
"connection": "Connection {{count}}",
"manageConnection": "Manage connection {{count}}",
"forgetConnection": "Forget connection",
"forgetTitle": "Forget this connection?",
"forgetHint": "Only this saved connection will be removed. Other connections and data on the server will stay."
},
"activeForgetWarning": "Tất cả thẻ đang dùng kết nối này sẽ bị ngắt. Nội dung chưa lưu có thể bị mất.",
"saved": "Đã lưu",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "You can save up to 20 connections. Remove an unused authorization in Connection details, or forget an unused server.",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "忘记",
"switchHint": "要使用另一份授权,请先断开当前连接。",
"title": "这个 nanobot 已连接过",
"saveAndOpen": "保存并打开",
"pairHint": "服务器列表只保留一条。这次授权也会保存,已有连接不会被删除。",
"details": "连接详情",
"detailsHint": "这些连接指向同一个 nanobot。选择一个使用,或管理它的授权。",
"connection": "连接 {{count}}",
"manageConnection": "管理连接 {{count}}",
"forgetConnection": "忘记此连接",
"forgetTitle": "忘记此连接?",
"forgetHint": "只移除此电脑上的这条连接,其他连接和服务器上的数据会保留。"
},
"activeForgetWarning": "也会断开正在使用此连接的标签页,未保存的内容可能丢失。",
"saved": "已保存",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "无法读取已保存的连接,原文件未被覆盖。",
"invalid_profile": "请检查服务器地址、端口和连接选项。",
"profile_not_found": "这个连接已不存在,请刷新列表。",
"profile_limit": "最多可以保存 20 台服务器。",
"profile_limit": "最多保存 20 条连接。请先在连接详情中移除不再使用的授权,或忘记不再使用的服务器。",
"connection_limit": "请先断开一台服务器,再建立新连接。",
"disconnect_before_edit": "请先断开这个服务器,再编辑连接信息。",
"local_io_error": "无法保存或打开连接,请检查本机文件权限。",
+15 -1
View File
@@ -1,5 +1,19 @@
{
"remote": {
"sameInstance": {
"forgetAction": "忘記",
"switchHint": "若要使用另一份授權,請先中斷目前連線。",
"title": "這個 nanobot 已連線過",
"saveAndOpen": "儲存並開啟",
"pairHint": "伺服器清單只保留一筆。這次授權也會儲存,已有連線不會被刪除。",
"details": "連線詳情",
"detailsHint": "這些連線指向同一個 nanobot。選擇一個使用,或管理它的授權。",
"connection": "連線 {{count}}",
"manageConnection": "管理連線 {{count}}",
"forgetConnection": "忘記此連線",
"forgetTitle": "忘記此連線?",
"forgetHint": "只移除此電腦上的這筆連線,其他連線與伺服器上的資料會保留。"
},
"activeForgetWarning": "也會中斷正在使用此連線的分頁,未儲存的內容可能遺失。",
"saved": "已儲存",
"pair": {
@@ -199,7 +213,7 @@
"profile_store_invalid": "Saved connections couldn't be read. They haven't been overwritten.",
"invalid_profile": "Check the address, port and Connection options fields.",
"profile_not_found": "This saved server no longer exists. Refresh the list.",
"profile_limit": "You can save up to 20 servers.",
"profile_limit": "最多儲存 20 筆連線。請先在連線詳情中移除不再使用的授權,或忘記不再使用的伺服器。",
"connection_limit": "Disconnect an existing server before opening another connection.",
"disconnect_before_edit": "Disconnect this server before editing it.",
"local_io_error": "Couldn't save or open the connection. Check local file permissions.",
+26
View File
@@ -15,10 +15,36 @@ export interface RemoteProfile {
view_id?: string;
connection_error?: string;
paired?: boolean;
/** Opaque grouping ID supplied only after the local backend verifies receipts. */
instance_id?: string;
revoke_command?: string;
authorized_until?: number;
}
export interface RemoteProfileGroup {
id: string;
profile: RemoteProfile;
connections: RemoteProfile[];
}
/** One visible instance; keep every underlying grant available in details. */
export function groupRemoteProfiles(profiles: RemoteProfile[], currentId: string | null): RemoteProfileGroup[] {
const groups = new Map<string, RemoteProfile[]>();
for (const profile of profiles) {
const id = profile.instance_id || profile.id;
const group = groups.get(id) || [];
group.push(profile);
groups.set(id, group);
}
return [...groups].map(([id, connections]) => {
const preferred = connections.find((item) => item.id === currentId)
|| connections.find((item) => item.connected)
|| [...connections].reverse().find((item) => item.authorized_until != null && item.authorized_until * 1000 > Date.now())
|| connections[0];
return { id, profile: { ...preferred, name: connections[0].name }, connections };
});
}
/** Persistent setup problems need a repair path, not an endless Retry button. */
export function needsRemoteSetup(code: string): boolean {
return /^(pair_|host_key_|ssh_auth_failed$|ssh_agent_refused$|ssh_key_permissions$|ssh_config_|local_file_not_found$|remote_auth_failed$|incompatible_gateway$|webui_disabled$|profile_not_found$)/.test(code);
+16
View File
@@ -65,6 +65,22 @@ async function reviewed() {
}
describe("quick pairing", () => {
it("explains an existing instance and saves its additional authorization only on confirmation", async () => {
mocks.action.mockImplementation(async (action: string) => {
if (action === "remote.pair_preview") return { ...preview, existing_connection: { id: "saved-server", name: "My team", connected: true } };
if (action === "remote.pair_finish") return { id: "saved-server" };
return {};
});
returnedView();
await screen.findByRole("heading", { name: "This nanobot is already saved" });
expect(screen.getByText("My team")).toBeVisible();
expect(screen.getByText(i18n.t("remote.sameInstance.pairHint"))).toBeVisible();
expect(mocks.action.mock.calls.some(([action]) => action === "remote.pair_finish")).toBe(false);
expect(mocks.connect).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: "Save and open" }));
await waitFor(() => expect(mocks.connect).toHaveBeenCalledWith("saved-server", expect.any(Function)));
expect(mocks.action).toHaveBeenCalledWith("remote.pair_finish", { id: "request-1", code: "nbpc1.encrypted" }, 65000);
});
it("introduces remote access with the original logo and no duplicate instruction spacer", async () => {
view();
await waitFor(() => expect(screen.getByRole("button", { name: "Copy command" })).toBeEnabled());
+45
View File
@@ -91,6 +91,51 @@ function chooseExistingSSH() {
}
describe("remote instance UX", () => {
it("shows one verified instance in management and the switcher while retaining both grants in details", async () => {
const second = { ...profile, id: "f1b18099-61d5-41d7-9c1d-6f647f7000e5", paired: true, instance_id: profile.id };
mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true, instance_id: profile.id }, second] });
view();
await openDirectory();
expect(screen.getAllByRole("button", { name: "Team server ubuntu@example.test" })).toHaveLength(1);
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
fireEvent.click(screen.getByRole("menuitem", { name: "Connection details" }));
const details = await screen.findByRole("dialog", { name: "Connection details" });
expect(within(details).getByRole("button", { name: /^Connection 1 / })).toBeVisible();
expect(within(details).getByRole("button", { name: /^Connection 2 / })).toBeVisible();
fireEvent.pointerDown(within(details).getByRole("button", { name: "Manage connection 1" }), { button: 0, ctrlKey: false });
fireEvent.click(screen.getByRole("menuitem", { name: "Forget connection" }));
expect(await screen.findByRole("dialog", { name: "Forget this connection?" })).toHaveTextContent(i18n.t("remote.sameInstance.forgetHint"));
expect(screen.getByRole("button", { name: "Forget", exact: true })).toBeVisible();
expect(screen.getByRole("button", { name: "Forget", exact: true }).firstElementChild).not.toHaveClass("truncate");
expect(screen.queryByRole("button", { name: "Forget server", exact: true })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
expect(mocks.request).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
fireEvent.pointerDown(screen.getByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });
expect(await screen.findAllByRole("menuitem", { name: "Team server ubuntu@example.test" })).toHaveLength(1);
});
it("keeps same-address unverified instances separate and shows their config paths", async () => {
mocks.read.mockResolvedValue({ available: true, profiles: [profile, { ...profile, id: "another", config_path: "/srv/other/config.json" }] });
view(); await openDirectory();
expect(screen.getAllByRole("button", { name: "Team server ubuntu@example.test" })).toHaveLength(2);
expect(screen.getByTitle("/srv/other/config.json")).toBeVisible();
expect(screen.getByTitle(profile.config_path)).toBeVisible();
});
it("requires disconnecting before opening another authorization of an already-connected instance", async () => {
const second = { ...profile, id: "second-grant", connected: true, paired: true, instance_id: profile.id };
mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true, instance_id: profile.id }, second] });
view(); await openDirectory();
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
fireEvent.click(screen.getByRole("menuitem", { name: "Connection details" }));
const details = await screen.findByRole("dialog", { name: "Connection details" });
expect(within(details).getByRole("button", { name: /^Connection 1 / })).toBeDisabled();
expect(within(details).getByRole("button", { name: /^Connection 2 / })).toBeEnabled();
expect(within(details).getByText(i18n.t("remote.sameInstance.switchHint"))).toBeVisible();
expect(within(details).getByRole("button", { name: "Manage connection 1" })).toBeEnabled();
expect(mocks.request).not.toHaveBeenCalled();
});
it("manages connections without changing the remote host, route, frame or authorization", async () => {
view();
await chooseHost("Team server ubuntu@example.test");
@@ -0,0 +1,27 @@
import { describe, expect, it } from "vitest";
import { groupRemoteProfiles, type RemoteProfile } from "@/lib/remote-instances";
const profile: RemoteProfile = { id: "one", name: "Team", host: "ubuntu@server", port: 22,
ssh_config: "", identity_file: "", config_path: "/srv/bot/config.json", runtime_user: "", connected: false };
describe("remote instance grouping", () => {
it("does not guess from names, addresses, or restart-scoped gateway IDs", () => {
expect(groupRemoteProfiles([profile, { ...profile, id: "two" }], null)).toHaveLength(2);
expect(groupRemoteProfiles([{ ...profile, gateway_id: "same" }, { ...profile, id: "two", gateway_id: "same" }], null)).toHaveLength(2);
});
it("keeps all grants but selects the current view before a connected or newer grant", () => {
const old = { ...profile, instance_id: "instance" };
const renewed = { ...old, id: "two", name: "auto-generated", connected: true };
const groups = groupRemoteProfiles([old, renewed], "one");
expect(groups).toHaveLength(1);
expect(groups[0].connections).toEqual([old, renewed]);
expect(groups[0].profile.id).toBe("one");
expect(groupRemoteProfiles([old, renewed], null)[0].profile).toMatchObject({ id: "two", name: "Team" });
});
it("prefers a usable grant when none is selected and does not mutate the directory", () => {
const items = [Object.freeze({ ...profile, instance_id: "same", authorized_until: 1 }),
Object.freeze({ ...profile, id: "two", instance_id: "same", authorized_until: Date.now() / 1000 + 1000 })];
expect(groupRemoteProfiles(items, null)[0].profile.id).toBe("two");
expect(items[0].id).toBe("one");
});
});