feat: tailscale add host and copy ip, fix outbound fetch hang and plugin ESM warning

This commit is contained in:
LukeGus committed 2026-09-25 13:06:33 -05:00
1 parent c21bca8cf0
commit fbe736bc20
70 files changed
+1117 -1139

No files matched your search

+4 -4
View File
@@ -13,12 +13,12 @@
"description": "Let the assistant carry out the changes it suggests."
},
"services.use": {
"title": "Use AI from other plugins",
"description": "Other plugins may call the assistant on your behalf."
"title": "Use AI from other features",
"description": "Other features may call the assistant on your behalf."
},
"secrets.share": {
"title": "Share the API key",
"description": "Other plugins may use the stored AI API key without seeing it."
"description": "Other features may use the stored AI API key without seeing it."
}
},
"settings": {
@@ -98,7 +98,7 @@
"runInTerminal": "Run",
"terminalContextPrefill": "Here is my terminal output:\n\n{{output}}\n\n",
"secrets": {
"shareApiKey": "Let other plugins use your AI provider API key for their own requests. The key is never copied, and you can revoke this at any time."
"shareApiKey": "Let other features use your AI provider API key for their own requests. The key is never copied, and you can revoke this at any time."
}
},
"nav": {
+2
View File
@@ -173,6 +173,8 @@
}
],
"host": {
"editorGroup": "ssh",
"editorOrder": 90,
"fields": [
{
"key": "enableAiAssistant",
+1 -1
View File
@@ -159,7 +159,7 @@
"continue": "Carry on"
},
"needsPlugin": "Needs {{plugin}}",
"needsPluginHint": "This automation is skipped until the plugin it needs is turned on again.",
"needsPluginHint": "This automation is skipped until the feature it needs is available again.",
"offBadge": "Off",
"docsLink": "View docs",
"ago": {
+2
View File
@@ -53,6 +53,8 @@
],
"settings": {
"host": {
"editorGroup": "ssh",
"editorOrder": 30,
"enableKey": "enableDocker",
"enableLabelKey": "settings.host.enable.label",
"fields": [
+2
View File
@@ -71,6 +71,8 @@
],
"settings": {
"host": {
"editorGroup": "ssh",
"editorOrder": 60,
"enableKey": "enableFileManager",
"enableLabelKey": "settings.host.enable.label",
"enableDefault": true,
+1 -1
View File
@@ -183,7 +183,7 @@
"wgHandshakeNever": "Never",
"wgTransfer": "Transfer"
},
"snippetsUnavailable": "The Snippets plugin is off, so quick actions cannot run."
"snippetsUnavailable": "Snippets are turned off, so quick actions cannot run."
},
"metricsHistory": {
"title": "Metrics History",
@@ -32,7 +32,7 @@ export function RedirectUriSetting({ values }: SettingsComponentProps) {
<Input
value={uri}
readOnly
className="rounded-none font-mono text-xs"
className="min-w-0 flex-1 rounded-none font-mono text-xs"
/>
<Button
type="button"
+1
View File
@@ -81,6 +81,7 @@
"nativeRdpFailed": "Failed to open Windows Remote Desktop",
"openNativeRdp": "Open in Windows Remote Desktop",
"guac": {
"toolbar": "Toolbar",
"connection": "Connection",
"authentication": "Authentication",
"storedCredential": "Stored Credential",
+2 -1
View File
@@ -427,7 +427,8 @@
"type": "boolean",
"labelKey": "settings.host.enableToolbar.label",
"descriptionKey": "settings.host.enableToolbar.description",
"default": true
"default": true,
"hidden": true
}
]
}
+32 -1
View File
@@ -14,7 +14,12 @@ import {
type TabProps,
type TermixApp,
} from "@termix/plugin-sdk/frontend";
import { SectionCard, isElectron } from "@termix/plugin-sdk/ui";
import {
FakeSwitch,
SectionCard,
SettingRow,
isElectron,
} from "@termix/plugin-sdk/ui";
import { toast } from "sonner";
import GuacamoleApp, { type GuacamoleAppHandle } from "./GuacamoleApp";
import { GuacamoleDisplay } from "./GuacamoleDisplay";
@@ -146,6 +151,29 @@ function SectionNotes({ protocol }: { protocol: Protocol }) {
);
}
function ToolbarCard({
form,
setField,
}: Pick<ReturnType<typeof remoteDesktopForm>, "form" | "setField">) {
const { t } = useTranslation();
return (
<SectionCard
title={t("hosts.guac.toolbar")}
icon={<MonitorUp className="size-3.5" />}
>
<SettingRow
label={t("settings.host.enableToolbar.label")}
description={t("settings.host.enableToolbar.description")}
>
<FakeSwitch
checked={form.enableToolbar}
onChange={(value) => setField("enableToolbar", value)}
/>
</SettingRow>
</SectionCard>
);
}
function RdpSection(props: HostEditorSectionProps) {
const { form, setField, setGuacField } = remoteDesktopForm(props);
return (
@@ -157,6 +185,7 @@ function RdpSection(props: HostEditorSectionProps) {
host={props.host as { macAddress?: string | null } | undefined}
credentials={props.credentials as never}
/>
<ToolbarCard form={form} setField={setField} />
<SectionNotes protocol="rdp" />
</>
);
@@ -173,6 +202,7 @@ function VncSection(props: HostEditorSectionProps) {
host={props.host as { macAddress?: string | null } | undefined}
credentials={props.credentials as never}
/>
<ToolbarCard form={form} setField={setField} />
<SectionNotes protocol="vnc" />
</>
);
@@ -188,6 +218,7 @@ function TelnetSection(props: HostEditorSectionProps) {
setGuacField={setGuacField}
credentials={props.credentials as never}
/>
<ToolbarCard form={form} setField={setField} />
<SectionNotes protocol="telnet" />
</>
);
@@ -16,6 +16,7 @@ export interface RemoteDesktopForm {
vncPort: number;
telnetPort: number;
guacamoleConfig: Record<string, any>;
enableToolbar: boolean;
rdpAuthType: "direct" | "credential" | "none";
rdpCredentialId: string;
rdpUser: string;
@@ -42,6 +43,7 @@ const SETTING_FOR_FIELD: Partial<Record<keyof RemoteDesktopForm, string>> = {
telnetPort: "telnetPort",
security: "rdpSecurity",
ignoreCert: "rdpIgnoreCert",
enableToolbar: "enableToolbar",
};
type PluginSettingsBag = Record<string, Record<string, unknown>>;
@@ -72,6 +74,7 @@ export function remoteDesktopForm(props: HostEditorSectionProps): {
security: options.rdpSecurity,
ignoreCert: options.rdpIgnoreCert,
guacamoleConfig: options.guacamoleConfig as Record<string, any>,
enableToolbar: options.enableToolbar,
};
const setField: RemoteFormSetField = (key, value) => {
+2
View File
@@ -59,6 +59,8 @@
}
],
"host": {
"editorGroup": "ssh",
"editorOrder": 85,
"enableKey": "enableSessionRecording",
"enableLabelKey": "settings.host.enable.label",
"fields": []
+2
View File
@@ -84,6 +84,8 @@
}
],
"host": {
"editorGroup": "ssh",
"editorOrder": 80,
"fields": [
{
"key": "allowSessionSharing",
+1 -1
View File
@@ -105,7 +105,7 @@
"clearAll": "Clear All",
"noHistoryEntries": "No history entries",
"trackingDisabled": "History tracking is disabled",
"trackingDisabledHint": "Turn on Command History for this host in its SSH Terminal plugin settings.",
"trackingDisabledHint": "Turn on Command History in this host's SSH Terminal tab.",
"commandCount_one": "{{count}} command",
"commandCount_other": "{{count}} commands"
},
+2
View File
@@ -216,6 +216,8 @@
}
],
"host": {
"editorGroup": "ssh",
"editorOrder": 12,
"enableKey": "enableTerminal",
"enableLabelKey": "settings.host.enableTerminal.label",
"enableDefault": true,
@@ -109,7 +109,7 @@ export function TouchInputSettings({
{t("touchInput.advanced")}
</button>
{advancedOpen && (
<div className="grid grid-cols-1 gap-3 pb-3 sm:grid-cols-2">
<div className="grid grid-cols-1 gap-3 pb-3">
{fields.map(({ key, label, unit }) => {
const bounds = TOUCH_INPUT_NUMERIC_BOUNDS[key];
return (
@@ -114,7 +114,7 @@ export function TerminalTabContent({
}
isQuickConnect={String(host.id).startsWith("quick-connect-")}
onSaveQuickConnect={
shell.saveQuickConnect
shell.saveQuickConnect && hostRecord?.quickConnectSavable
? () => shell.saveQuickConnect!(tabRecord, hostRecord!)
: undefined
}
+1 -1
View File
@@ -4,7 +4,7 @@
},
"editor": {
"label": "Step CA",
"description": "Sign in through your identity provider and let your Step CA issue a short-lived SSH certificate for this host. The CA URL, root fingerprint and OIDC provisioner are set by an administrator in the Step CA plugin settings.",
"description": "Sign in through your identity provider and let your Step CA issue a short-lived SSH certificate for this host. The CA URL, root fingerprint and OIDC provisioner are set by an administrator in the Step CA section of Admin Settings.",
"docs": "View docs"
},
"dialog": {
@@ -32,7 +32,7 @@ export function RedirectUriSetting({ values }: SettingsComponentProps) {
<Input
value={uri}
readOnly
className="rounded-none font-mono text-xs"
className="min-w-0 flex-1 rounded-none font-mono text-xs"
/>
<Button
type="button"
+5 -1
View File
@@ -42,7 +42,11 @@
"tailscaleLoadingDevices": "Loading devices...",
"tailscaleDeviceLoadFailed": "Failed to load Tailscale devices. Check the API URL and network connection.",
"tailscaleNoDevices": "No devices found in your tailnet.",
"tailscaleDeviceAutoFill": "Selecting a device will auto-fill the host IP address."
"tailscaleDeviceAutoFill": "Selecting a device will auto-fill the host IP address.",
"tailscaleAddHost": "Add host",
"tailscaleCopyIp": "Copy Tailscale IP",
"tailscaleIpCopied": "IP copied",
"tailscaleIpCopyFailed": "Could not copy the IP"
},
"terminal": {
"tailscaleCheckRequired": "Tailscale Authentication Required",
+1 -1
View File
@@ -76,7 +76,7 @@ export function startTailscaleService(
if (!context) {
return res
.status(503)
.json({ error: "Plugin is not running", devices: [] });
.json({ error: "Tailscale is not available", devices: [] });
}
const apiKey = (await context.settings.get<string>("apiKey")) ?? "";
if (!apiKey) {
@@ -1,6 +1,10 @@
import { useEffect, useState } from "react";
import { useTranslation } from "@termix/plugin-sdk/frontend";
import { Loader2, RefreshCw, Terminal } from "lucide-react";
import {
useToast,
useTranslation,
type HostDraft,
} from "@termix/plugin-sdk/frontend";
import { Copy, Loader2, Plus, RefreshCw, Terminal } from "lucide-react";
import { Button } from "@termix/plugin-sdk/ui";
import { Input } from "@termix/plugin-sdk/ui";
import type { PluginHostRecord as Host } from "@termix/plugin-sdk/frontend";
@@ -18,6 +22,8 @@ interface TailscaleDevice {
interface TailscaleDevicesPanelProps {
onConnect: (host: Host, type: "terminal") => void;
/** Absent when the shell cannot open the host editor. */
onAddHost?: (draft: HostDraft) => void;
}
function deviceIp(device: TailscaleDevice): string {
@@ -30,8 +36,10 @@ function deviceIp(device: TailscaleDevice): string {
export function TailscaleDevicesPanel({
onConnect,
onAddHost,
}: TailscaleDevicesPanelProps) {
const { t } = useTranslation();
const toast = useToast();
const [devices, setDevices] = useState<TailscaleDevice[]>([]);
const [hasApiKey, setHasApiKey] = useState(true);
const [loading, setLoading] = useState(true);
@@ -52,10 +60,33 @@ export function TailscaleDevicesPanel({
useEffect(load, []);
function usernameFor(device: TailscaleDevice): string {
return usernames[device.id]?.trim() || "root";
}
function copyIp(ip: string) {
navigator.clipboard
?.writeText(ip)
.then(() => toast.success(t("hosts.tailscaleIpCopied")))
.catch(() => toast.error(t("hosts.tailscaleIpCopyFailed")));
}
function addHost(device: TailscaleDevice) {
const ip = deviceIp(device);
if (!ip || !onAddHost) return;
onAddHost({
name: device.hostname || device.name,
ip,
port: 22,
username: usernameFor(device),
authType: "tailscale",
});
}
function connect(device: TailscaleDevice) {
const ip = deviceIp(device);
if (!ip) return;
const username = usernames[device.id]?.trim() || "root";
const username = usernameFor(device);
const host = createQuickConnectHost({
ip,
port: 22,
@@ -118,14 +149,33 @@ export function TailscaleDevicesPanel({
key={device.id}
className="flex flex-col gap-1.5 border border-border p-2"
>
<div className="flex flex-col gap-0.5">
<span className="text-xs font-semibold">
<div className="flex items-start justify-between gap-2">
<span className="text-xs font-semibold min-w-0 break-all">
{device.hostname || device.name}
</span>
<span className="text-[10px] text-muted-foreground">
{ip} {device.os ? `· ${device.os}` : ""}
</span>
{device.os && (
<span className="shrink-0 border border-border px-1 text-[10px] text-muted-foreground">
{device.os}
</span>
)}
</div>
{ip && (
<div className="flex items-center gap-1">
<span className="text-[10px] text-muted-foreground font-mono">
{ip}
</span>
<Button
variant="ghost"
size="icon"
className="size-5 text-muted-foreground hover:text-foreground"
title={t("hosts.tailscaleCopyIp")}
aria-label={t("hosts.tailscaleCopyIp")}
onClick={() => copyIp(ip)}
>
<Copy className="size-3" />
</Button>
</div>
)}
<Input
placeholder={t("newUi.sidebar.quickConnect.usernameLabel")}
value={usernames[device.id] ?? "root"}
@@ -140,15 +190,28 @@ export function TailscaleDevicesPanel({
}}
className="h-7 text-xs"
/>
<Button
onClick={() => connect(device)}
disabled={!ip}
className="flex items-center justify-center gap-1.5 h-7 w-full border border-accent-brand/40 bg-accent-brand/10 text-accent-brand text-xs font-semibold hover:bg-accent-brand/20 transition-colors"
variant="outline"
>
<Terminal className="size-3.5" />
{t("newUi.sidebar.quickConnect.connectToTerminal")}
</Button>
<div className="flex gap-1.5">
<Button
onClick={() => connect(device)}
disabled={!ip}
className="flex flex-1 items-center justify-center gap-1.5 h-7 border border-accent-brand/40 bg-accent-brand/10 text-accent-brand text-xs font-semibold hover:bg-accent-brand/20 transition-colors"
variant="outline"
>
<Terminal className="size-3.5" />
{t("newUi.sidebar.quickConnect.connectToTerminal")}
</Button>
{onAddHost && (
<Button
onClick={() => addHost(device)}
disabled={!ip}
variant="outline"
className="h-7 gap-1 text-xs shrink-0"
>
<Plus className="size-3.5" />
{t("hosts.tailscaleAddHost")}
</Button>
)}
</div>
</div>
);
})}
@@ -52,7 +52,7 @@ export function TailscaleDevicesStatus({ running }: SettingsComponentProps) {
const label = (key: string) => t(key);
return (
<div className="flex items-center justify-between gap-3 py-3">
<div className="flex flex-wrap items-center justify-between gap-3 py-3">
<div className="flex flex-col gap-0.5 min-w-0 flex-1">
<span className="text-sm font-medium leading-snug">
{label("settings.devices.label")}
+5
View File
@@ -18,6 +18,11 @@ function Panel({ shell }: PanelProps) {
type,
)
}
onAddHost={
shell.openHostEditor
? (draft) => shell.openHostEditor!(draft)
: undefined
}
/>
);
}
@@ -74,4 +74,75 @@ describe("TailscaleDevicesPanel", () => {
expect(host.authType).toBe("tailscale");
expect(host.username).toBe("root");
});
const device = {
id: "d1",
name: "box.tailnet.ts.net",
hostname: "box",
addresses: ["100.64.0.1", "fd7a::1"],
os: "linux",
lastSeen: "2026-01-01T00:00:00Z",
};
it("opens the host editor with the device filled in", async () => {
const user = userEvent.setup();
getTailscaleDevicesMock.mockResolvedValue({
hasApiKey: true,
devices: [device],
});
const onAddHost = vi.fn();
render(<TailscaleDevicesPanel onConnect={vi.fn()} onAddHost={onAddHost} />);
await waitFor(() => expect(screen.getByText("box")).toBeTruthy());
await user.clear(
screen.getByPlaceholderText("newUi.sidebar.quickConnect.usernameLabel"),
);
await user.type(
screen.getByPlaceholderText("newUi.sidebar.quickConnect.usernameLabel"),
"luke",
);
await user.click(screen.getByText("hosts.tailscaleAddHost"));
expect(onAddHost).toHaveBeenCalledWith({
name: "box",
ip: "100.64.0.1",
port: 22,
username: "luke",
authType: "tailscale",
});
});
it("hides Add host when the shell cannot open the editor", async () => {
getTailscaleDevicesMock.mockResolvedValue({
hasApiKey: true,
devices: [device],
});
render(<TailscaleDevicesPanel onConnect={vi.fn()} />);
await waitFor(() => expect(screen.getByText("box")).toBeTruthy());
expect(screen.queryByText("hosts.tailscaleAddHost")).toBeNull();
});
it("copies the tailnet IP", async () => {
const user = userEvent.setup();
const writeText = vi.fn().mockResolvedValue(undefined);
Object.defineProperty(navigator, "clipboard", {
value: { writeText },
configurable: true,
});
getTailscaleDevicesMock.mockResolvedValue({
hasApiKey: true,
devices: [device],
});
render(<TailscaleDevicesPanel onConnect={vi.fn()} />);
await waitFor(() => expect(screen.getByText("box")).toBeTruthy());
expect(screen.getByText("linux")).toBeTruthy();
await user.click(screen.getByLabelText("hosts.tailscaleCopyIp"));
expect(writeText).toHaveBeenCalledWith("100.64.0.1");
});
});
@@ -32,7 +32,7 @@ export function RedirectUriSetting({ values }: SettingsComponentProps) {
<Input
value={uri}
readOnly
className="rounded-none font-mono text-xs"
className="min-w-0 flex-1 rounded-none font-mono text-xs"
/>
<Button
type="button"
+2
View File
@@ -38,6 +38,8 @@
],
"settings": {
"host": {
"editorGroup": "top",
"editorOrder": 90,
"fields": [
{
"key": "macAddress",
+2
View File
@@ -21,6 +21,8 @@
},
"settings": {
"host": {
"editorGroup": "ssh",
"editorOrder": 95,
"fields": [
{
"key": "useWarpgate",