mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(app): advance SSH prompts and close the dialog on connection (#63544)
This commit is contained in:
committed by
GitHub
Unverified
parent
b268a4e8b0
commit
96d950178c
@@ -175,6 +175,67 @@ test("adding an SSH server while the SSH plugin is down fails instead of connect
|
||||
await expect(dialog.getByRole("button", { name: "Add server", exact: true })).toBeEnabled()
|
||||
})
|
||||
|
||||
test("adding an SSH server closes the dialog when the connection is ready", async ({ page }) => {
|
||||
await mockOpenCodeServer(page, {
|
||||
directory: "/repo",
|
||||
project: project({ id: "proj_ssh_add", directory: "/repo" }),
|
||||
provider: NO_PROVIDER,
|
||||
sessions: [],
|
||||
pageMessages: () => ({ items: [] }),
|
||||
})
|
||||
await page.goto(`/e2e/utils/settings-wsl.html?${new URLSearchParams({ server: SERVER, mode: "ready" })}`)
|
||||
const settings = page.getByTestId("settings-screen")
|
||||
|
||||
await settings.getByRole("tab", { name: "Servers", exact: true }).click()
|
||||
await settings.getByRole("button", { name: "Add server", exact: true }).press("Enter")
|
||||
await page.getByRole("menuitem", { name: "Add SSH server", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
|
||||
await dialog.getByRole("textbox", { name: "Host or SSH command" }).fill("ssh devbox")
|
||||
await dialog.getByRole("button", { name: "Add server", exact: true }).click()
|
||||
await expect(dialog.getByRole("button", { name: "Connecting over SSH…", exact: true })).toBeDisabled()
|
||||
// The fixture control sits behind the modal.
|
||||
await page.getByText("Finish SSH connection", { exact: true }).dispatchEvent("click")
|
||||
await expect(dialog).toHaveCount(0)
|
||||
await expect(settings.getByRole("region", { name: "devbox", exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test("SSH asks for the account password after a rejected key passphrase", async ({ page }) => {
|
||||
await mockOpenCodeServer(page, {
|
||||
directory: "/repo",
|
||||
project: project({ id: "proj_ssh_fallback", directory: "/repo" }),
|
||||
provider: NO_PROVIDER,
|
||||
sessions: [],
|
||||
pageMessages: () => ({ items: [] }),
|
||||
})
|
||||
await page.goto(`/e2e/utils/settings-wsl.html?${new URLSearchParams({ server: SERVER, mode: "ready" })}`)
|
||||
const settings = page.getByTestId("settings-screen")
|
||||
|
||||
await settings.getByRole("tab", { name: "Servers", exact: true }).click()
|
||||
await settings.getByRole("button", { name: "Add server", exact: true }).press("Enter")
|
||||
await page.getByRole("menuitem", { name: "Add SSH server", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
|
||||
await dialog.getByRole("textbox", { name: "Host or SSH command" }).fill("ssh dev@key-fallback")
|
||||
await dialog.getByRole("button", { name: "Add server", exact: true }).click()
|
||||
const key = dialog.getByRole("textbox", { name: "Enter passphrase for key 'id_ed25519':", exact: true })
|
||||
|
||||
await key.fill("incorrect-passphrase")
|
||||
await dialog.getByRole("button", { name: "Continue", exact: true }).click()
|
||||
// Release main's two snapshots separately, after the response RPC has returned.
|
||||
await page.getByText("Clear SSH passphrase prompt", { exact: true }).dispatchEvent("click")
|
||||
await expect(key).toBeDisabled()
|
||||
await page.getByText("Request SSH account password", { exact: true }).dispatchEvent("click")
|
||||
const account = dialog.getByRole("textbox", { name: "dev@key-fallback's password:", exact: true })
|
||||
|
||||
await expect(account).toBeEditable()
|
||||
await expect(account).toHaveValue("")
|
||||
await account.fill("fixture-password")
|
||||
await dialog.getByRole("button", { name: "Continue", exact: true }).click()
|
||||
await expect(dialog).toHaveCount(0)
|
||||
await expect(settings.getByRole("region", { name: "key-fallback", exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test("WSL session and draft tabs outlive the plugin going away until the server is removed", async ({ page }) => {
|
||||
const directory = "/home/ubuntu/project"
|
||||
const wsl = session({ id: "ses_wsl_tabs", directory, title: "WSL tabs session" })
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ServerConnection } from "../../src/runtime/server/registry"
|
||||
import { usePluginServers } from "../../src/runtime/plugin/servers"
|
||||
|
||||
/** The input of a WSL or SSH method this fixture answers. */
|
||||
type FixtureInput = { id?: string; name?: string }
|
||||
type FixtureInput = { id?: string; name?: string; target?: string; prompt?: string; value?: string }
|
||||
|
||||
/** A main-side method: SSH `start` answers with the state revision, the others with nothing. */
|
||||
type FixtureMethod = (input: FixtureInput) => number | void
|
||||
@@ -64,12 +64,14 @@ export function mount(input: {
|
||||
const [store, setStore] = createStore<{
|
||||
calls: string[]
|
||||
connects: number
|
||||
passphraseAnswered: boolean
|
||||
available: boolean
|
||||
state: WslServersState
|
||||
ssh: SshState
|
||||
}>({
|
||||
calls: [],
|
||||
connects: 0,
|
||||
passphraseAnswered: false,
|
||||
available: true,
|
||||
ssh: {
|
||||
revision: 0,
|
||||
@@ -186,12 +188,41 @@ export function mount(input: {
|
||||
|
||||
const ssh = {
|
||||
// Like main: a connect opens a new tunnel to a remote server with a new password.
|
||||
start() {
|
||||
start(value) {
|
||||
setStore("connects", (count) => count + 1)
|
||||
|
||||
if (!store.ssh.servers.length && value.id && value.target) {
|
||||
const config = { id: value.id, target: value.target, name: value.name ?? "" }
|
||||
|
||||
setStore("ssh", (state) => ({
|
||||
revision: state.revision + 1,
|
||||
servers: [{ config, saved: false, stage: "connecting", detail: "" }],
|
||||
}))
|
||||
|
||||
if (value.target === "ssh dev@key-fallback")
|
||||
setSsh({
|
||||
stage: "authentication",
|
||||
prompt: { id: "key", text: "Enter passphrase for key 'id_ed25519':", confirm: false },
|
||||
})
|
||||
|
||||
return store.ssh.revision
|
||||
}
|
||||
|
||||
setSsh({ stage: "ready", http: { url: input.ssh ?? "", password: `ssh-${store.connects + 1}` } })
|
||||
|
||||
return store.ssh.revision
|
||||
},
|
||||
respond(value) {
|
||||
const server = store.ssh.servers.find((item) => item.config.id === value.id)
|
||||
|
||||
if (!server?.prompt || server.prompt.id !== value.prompt) throw new Error("Unexpected SSH prompt")
|
||||
|
||||
if (value.prompt === "key" && value.value === "incorrect-passphrase")
|
||||
return setStore("passphraseAnswered", true)
|
||||
|
||||
if (value.prompt !== "account" || value.value !== "fixture-password") throw new Error("Unexpected SSH answer")
|
||||
setSsh({ saved: true, stage: "ready", prompt: undefined, http: { url: input.server, password: "ssh-1" } })
|
||||
},
|
||||
} satisfies Readonly<Record<string, FixtureMethod>>
|
||||
|
||||
const methods = new Map<string, Readonly<Record<string, FixtureMethod>>>([
|
||||
@@ -303,6 +334,41 @@ export function mount(input: {
|
||||
/>
|
||||
SSH plugin
|
||||
</label>
|
||||
<Show when={store.ssh.servers.some((item) => !item.saved && item.stage === "connecting")}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setSsh({ saved: true, stage: "ready", http: { url: input.server, password: "ssh-1" } })
|
||||
publish("ssh")
|
||||
}}
|
||||
>
|
||||
Finish SSH connection
|
||||
</button>
|
||||
</Show>
|
||||
{/* askpass accepts the answer before ssh rejects the key and asks for the account password. */}
|
||||
<Show when={store.passphraseAnswered}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setSsh({ stage: "connecting", prompt: undefined })
|
||||
publish("ssh")
|
||||
}}
|
||||
>
|
||||
Clear SSH passphrase prompt
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setSsh({
|
||||
stage: "authentication",
|
||||
prompt: { id: "account", text: "dev@key-fallback's password:", confirm: false },
|
||||
})
|
||||
publish("ssh")
|
||||
}}
|
||||
>
|
||||
Request SSH account password
|
||||
</button>
|
||||
</Show>
|
||||
{/* The SSH tunnel dropping, which only main notices. */}
|
||||
<Show when={input.ssh}>
|
||||
<button
|
||||
|
||||
@@ -509,9 +509,9 @@ function Stage(props: { entry: LabEntry; inspector: HTMLElement; scheme: "dark"
|
||||
>
|
||||
<Workspace>
|
||||
<Plugin file={entry.file}>
|
||||
<DialogProvider container={canvas()}>
|
||||
<Show when={render()} keyed fallback={language.t("lab.empty")}>
|
||||
{(fn) => (
|
||||
<Show when={render()} keyed fallback={language.t("lab.empty")}>
|
||||
{(fn) => (
|
||||
<DialogProvider container={canvas()}>
|
||||
<ErrorBoundary
|
||||
fallback={(error, reset) => {
|
||||
// A failing state does not stick: the next state or edit tries again.
|
||||
@@ -526,9 +526,9 @@ function Stage(props: { entry: LabEntry; inspector: HTMLElement; scheme: "dark"
|
||||
>
|
||||
{untrack(() => fn(args))}
|
||||
</ErrorBoundary>
|
||||
)}
|
||||
</Show>
|
||||
</DialogProvider>
|
||||
</DialogProvider>
|
||||
)}
|
||||
</Show>
|
||||
</Plugin>
|
||||
</Workspace>
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
type ServerOriginal,
|
||||
} from "./machine"
|
||||
import { useRedeemPairing } from "./redeem"
|
||||
import { redeemPairingLink } from "./pairing"
|
||||
|
||||
export type ServerConnectControllerOptions =
|
||||
| { readonly surface: "screen"; readonly target: Extract<ServerConnectTarget, { kind: "connect" }> }
|
||||
@@ -30,14 +31,33 @@ export type ServerConnectControllerOptions =
|
||||
readonly closing?: Accessor<boolean>
|
||||
}
|
||||
|
||||
export function createServerConnectController(options: ServerConnectControllerOptions) {
|
||||
const language = useLanguage()
|
||||
type ServerConnectIO = {
|
||||
camera: ServerCameraSupport
|
||||
probeCamera: () => Promise<boolean>
|
||||
pageHref?: string
|
||||
check: ReturnType<typeof useCheckServerHealth>
|
||||
exchange: typeof redeemPairingLink
|
||||
servers: Pick<ReturnType<typeof useServers>, "list" | "add" | "remove">
|
||||
}
|
||||
|
||||
function useServerConnectIO(): ServerConnectIO {
|
||||
const platform = usePlatform()
|
||||
const servers = useServers()
|
||||
const check = useCheckServerHealth()
|
||||
|
||||
return {
|
||||
camera: cameraSupport(platform.platform),
|
||||
probeCamera,
|
||||
pageHref: platform.platform === "web" ? location.href : undefined,
|
||||
check: useCheckServerHealth(),
|
||||
exchange: redeemPairingLink,
|
||||
servers: useServers(),
|
||||
}
|
||||
}
|
||||
|
||||
export function createServerConnectController(options: ServerConnectControllerOptions, io = useServerConnectIO()) {
|
||||
const language = useLanguage()
|
||||
// Shared with the scanner, so a retry after a failed check reuses the token of a spent one-time code.
|
||||
const redeem = useRedeemPairing()
|
||||
const initial = startServerConnect(options.target, cameraSupport(platform.platform))
|
||||
const redeem = useRedeemPairing(io.exchange, io.pageHref)
|
||||
const initial = startServerConnect(options.target, io.camera)
|
||||
const [machine, setMachine] = createSignal(initial.state)
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
let cameraTimer: ReturnType<typeof setTimeout> | undefined
|
||||
@@ -68,7 +88,7 @@ export function createServerConnectController(options: ServerConnectControllerOp
|
||||
if (effect.type === "camera.probe") {
|
||||
clearTimeout(cameraTimer)
|
||||
cameraTimer = setTimeout(() => dispatch({ type: "camera.timed-out", attempt: effect.attempt }), effect.timeoutMs)
|
||||
void Promise.try(probeCamera).then(
|
||||
void Promise.try(io.probeCamera).then(
|
||||
(available) => dispatch({ type: "camera.settled", attempt: effect.attempt, available }),
|
||||
() => dispatch({ type: "camera.settled", attempt: effect.attempt, available: false }),
|
||||
)
|
||||
@@ -91,7 +111,7 @@ export function createServerConnectController(options: ServerConnectControllerOp
|
||||
error: { type: "connection-failed", url: effect.http.url },
|
||||
})
|
||||
|
||||
void Promise.try(() => check(effect.http)).then(
|
||||
void Promise.try(() => io.check(effect.http)).then(
|
||||
(result) =>
|
||||
result.type === "healthy"
|
||||
? dispatch({ type: "submit.succeeded", attempt: effect.attempt, http: effect.http })
|
||||
@@ -116,6 +136,7 @@ export function createServerConnectController(options: ServerConnectControllerOp
|
||||
|
||||
if (effect.type === "save") {
|
||||
const action = effect.action
|
||||
const servers = io.servers
|
||||
|
||||
if (action.type === "connect") {
|
||||
// Signing in again keeps the name the user gave this server.
|
||||
@@ -153,12 +174,12 @@ export function createServerConnectController(options: ServerConnectControllerOp
|
||||
if (effect.preferredUrl && effect.preferredUrl !== redeemed.pairing.url) {
|
||||
const http = { url: effect.preferredUrl, password }
|
||||
|
||||
if ((await check(http)).type === "healthy") return { type: "submit.succeeded", attempt: effect.attempt, http }
|
||||
if ((await io.check(http)).type === "healthy") return { type: "submit.succeeded", attempt: effect.attempt, http }
|
||||
}
|
||||
|
||||
const http = { url: redeemed.pairing.url, password }
|
||||
|
||||
if ((await check(http)).type === "healthy") return { type: "submit.succeeded", attempt: effect.attempt, http }
|
||||
if ((await io.check(http)).type === "healthy") return { type: "submit.succeeded", attempt: effect.attempt, http }
|
||||
|
||||
return { type: "submit.failed", attempt: effect.attempt, error: { type: "connection-failed", url: http.url } }
|
||||
}
|
||||
@@ -180,7 +201,7 @@ export function createServerConnectController(options: ServerConnectControllerOp
|
||||
const view = createMemo(() =>
|
||||
selectServerConnectView(machine(), {
|
||||
surface: options.surface,
|
||||
pageHref: platform.platform === "web" ? location.href : undefined,
|
||||
pageHref: io.pageHref,
|
||||
t: (key) => language.t(key),
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
import { Button } from "@opencode/ui/button"
|
||||
import { useDialog } from "@opencode/ui/context/dialog"
|
||||
import { createEffect, createSignal, onMount, Show, type ComponentProps } from "solid-js"
|
||||
import { createServerConnectController } from "./controller"
|
||||
import { DialogServer } from "./dialog"
|
||||
import type { ServerCameraSupport, ServerConnectEvent, ServerConnectTarget } from "./machine"
|
||||
import { PairingScanner } from "./scanner"
|
||||
|
||||
export const address = "https://build.example.test"
|
||||
|
||||
export const link = `${address}/auth/connect/example`
|
||||
|
||||
type CameraScene = "ready" | "opening" | "denied" | "invalid" | "decode" | "redeeming" | "timeout"
|
||||
|
||||
type Preset = {
|
||||
camera?: ServerCameraSupport | "probing"
|
||||
target?: Extract<ServerConnectTarget, { kind: "edit" }>
|
||||
events?: Extract<ServerConnectEvent, { type: "field.changed" | "method.changed" | "submitted" }>[]
|
||||
scanner?: CameraScene
|
||||
exchange?: "expired" | "unreachable"
|
||||
check?: "unreachable" | "pending"
|
||||
closed?: boolean
|
||||
}
|
||||
|
||||
export function serverStory(preset: Preset = {}) {
|
||||
return { render: () => <Story preset={preset} /> }
|
||||
}
|
||||
|
||||
function Story(props: { preset: Preset }) {
|
||||
const dialog = useDialog()
|
||||
|
||||
const [saved, setSaved] = createSignal("")
|
||||
|
||||
const open = () => {
|
||||
setSaved("")
|
||||
void dialog.show(() => (
|
||||
<Preview preset={props.preset} onSave={(server) => setSaved(server.displayName ?? server.http.url)} />
|
||||
))
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!props.preset.closed) open()
|
||||
})
|
||||
|
||||
return (
|
||||
<div class="flex flex-col items-start gap-3">
|
||||
<Button variant="neutral" onClick={open}>
|
||||
Open {props.preset.target?.kind ?? "add"} server dialog
|
||||
</Button>
|
||||
<Show when={saved()}>{(name) => <p role="status">Saved {name()} in this preview.</p>}</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Preview(props: { preset: Preset; onSave: ComponentProps<typeof DialogServer>["onSave"] }) {
|
||||
const preset = props.preset
|
||||
|
||||
const createForm: NonNullable<ComponentProps<typeof DialogServer>["createForm"]> = (dialog) => {
|
||||
const pending = new Promise<never>(() => {})
|
||||
|
||||
let check = preset.check
|
||||
|
||||
let exchange = preset.exchange
|
||||
|
||||
const form = createServerConnectController(
|
||||
{ ...dialog, target: preset.target ?? { kind: "add" }, removeTabs() {} },
|
||||
{
|
||||
camera: preset.camera === "probing" ? "probe" : (preset.camera ?? "probe"),
|
||||
probeCamera: () => (preset.camera === "probing" ? pending : Promise.resolve(true)),
|
||||
pageHref: "https://lab.example.test",
|
||||
servers: { list: [], add: (server) => server, remove() {} },
|
||||
exchange: async (request) => {
|
||||
if (request.code === "pending") return pending
|
||||
|
||||
if (exchange) {
|
||||
const type = exchange
|
||||
exchange = undefined
|
||||
|
||||
return { type }
|
||||
}
|
||||
|
||||
return { type: "paired", pairing: { url: request.urls[0], password: "fixture" } }
|
||||
},
|
||||
check: async () => {
|
||||
if (check === "pending") return pending
|
||||
|
||||
if (check === "unreachable") {
|
||||
check = undefined
|
||||
|
||||
return { type: "unreachable" }
|
||||
}
|
||||
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, 700))
|
||||
|
||||
return { type: "healthy" }
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
preset.events?.forEach(form.dispatch)
|
||||
|
||||
if (preset.scanner) {
|
||||
let opened = false
|
||||
createEffect(() => {
|
||||
if (opened || !form.view().canScan) return
|
||||
opened = true
|
||||
form.dispatch({ type: "scan.started" })
|
||||
})
|
||||
}
|
||||
|
||||
return form
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogServer
|
||||
mode={preset.target?.kind ?? "add"}
|
||||
createForm={createForm}
|
||||
onSave={props.onSave}
|
||||
scanner={(props) => <CameraPreview {...props} scene={preset.scanner ?? "ready"} />}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CameraPreview(props: ComponentProps<typeof PairingScanner> & { scene: CameraScene }) {
|
||||
let detect: ((data: string) => void) | undefined
|
||||
|
||||
const camera: NonNullable<ComponentProps<typeof PairingScanner>["camera"]> = (_, read, failed) => {
|
||||
detect = read
|
||||
let frame: ReturnType<typeof requestAnimationFrame>
|
||||
|
||||
return {
|
||||
start: async () => {
|
||||
if (props.scene === "denied") throw new Error("Camera permission denied")
|
||||
|
||||
if (props.scene === "opening") return new Promise<void>(() => {})
|
||||
frame = requestAnimationFrame(() => {
|
||||
if (props.scene === "invalid") read("not a pairing code")
|
||||
|
||||
if (props.scene === "decode") failed()
|
||||
|
||||
if (props.scene === "redeeming" || props.scene === "timeout") read(`${address}/auth/connect/pending`)
|
||||
})
|
||||
},
|
||||
stop() {},
|
||||
destroy: () => cancelAnimationFrame(frame),
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<PairingScanner {...props} camera={camera} />
|
||||
<Show when={props.scene !== "opening" && props.scene !== "denied" && props.scene !== "redeeming"}>
|
||||
<Button variant="neutral" onClick={() => detect?.(link)}>
|
||||
Read fixture QR code
|
||||
</Button>
|
||||
</Show>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import { Button } from "@opencode/ui/button"
|
||||
import { useDialog } from "@opencode/ui/context/dialog"
|
||||
import { onMount } from "solid-js"
|
||||
import { DialogStoryRuntime, STORY_LOCKED_SERVER, STORY_SERVER } from "@/components-lab/dialog-story-runtime"
|
||||
import type { ServerConnection } from "@/runtime/server/registry"
|
||||
import { DialogServer } from "./dialog"
|
||||
|
||||
const editableServer: ServerConnection.Http = {
|
||||
type: "http",
|
||||
displayName: "Build cluster",
|
||||
http: { url: STORY_SERVER.http.url },
|
||||
}
|
||||
|
||||
function ServerDialogStory(props: { mode: "add" | "edit"; server?: ServerConnection.Http }) {
|
||||
const dialog = useDialog()
|
||||
|
||||
const open = () => void dialog.show(() => <DialogServer mode={props.mode} server={props.server} />)
|
||||
|
||||
onMount(open)
|
||||
|
||||
return (
|
||||
<Button variant="neutral" onClick={open}>
|
||||
{props.mode === "add" ? "Open add server dialog" : "Open edit server dialog"}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export default {
|
||||
title: "App/Dialogs/Add Server",
|
||||
id: "app-dialog-add-server",
|
||||
}
|
||||
|
||||
export const PairingLink = {
|
||||
render: () => (
|
||||
<DialogStoryRuntime>
|
||||
<ServerDialogStory mode="add" />
|
||||
</DialogStoryRuntime>
|
||||
),
|
||||
}
|
||||
|
||||
export const Password = {
|
||||
render: () => (
|
||||
<DialogStoryRuntime servers={[editableServer]}>
|
||||
<ServerDialogStory mode="edit" server={editableServer} />
|
||||
</DialogStoryRuntime>
|
||||
),
|
||||
}
|
||||
|
||||
export const SignedOut = {
|
||||
render: () => (
|
||||
<DialogStoryRuntime servers={[STORY_SERVER, STORY_LOCKED_SERVER]}>
|
||||
<ServerDialogStory mode="edit" server={STORY_LOCKED_SERVER} />
|
||||
</DialogStoryRuntime>
|
||||
),
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { address, link, serverStory } from "./dialog.fixture"
|
||||
import type { ServerConnectEvent, ServerConnectField, ServerConnectTarget } from "./machine"
|
||||
|
||||
const field = (field: ServerConnectField, value: string) => ({ type: "field.changed", field, value }) as const
|
||||
|
||||
const password = { type: "method.changed", method: "password" } satisfies ServerConnectEvent
|
||||
|
||||
const submit = { type: "submitted" } satisfies ServerConnectEvent
|
||||
|
||||
const edit = {
|
||||
kind: "edit",
|
||||
original: { url: address, displayName: "Build cluster", password: undefined, unauthorized: false },
|
||||
} satisfies ServerConnectTarget
|
||||
|
||||
export default {
|
||||
title: "App/Dialogs/Add Server",
|
||||
id: "app-dialog-add-server",
|
||||
}
|
||||
|
||||
export const PairingLink = serverStory()
|
||||
|
||||
export const Password = serverStory({ events: [password] })
|
||||
|
||||
export const ReadyToPair = serverStory({ events: [field("link", link), field("name", "Build cluster")] })
|
||||
|
||||
export const InvalidLink = serverStory({ events: [field("link", "incomplete"), submit] })
|
||||
|
||||
export const LegacyLink = serverStory({ events: [field("link", `${address}/connect#example`), submit] })
|
||||
|
||||
export const ExpiredLink = serverStory({ events: [field("link", link), submit], exchange: "expired" })
|
||||
|
||||
export const UnreachableLink = serverStory({ events: [field("link", link), submit], exchange: "unreachable" })
|
||||
|
||||
export const InvalidAddress = serverStory({ events: [password, field("url", "file:///example"), submit] })
|
||||
|
||||
export const ConnectionFailed = serverStory({ events: [password, field("url", address), submit], check: "unreachable" })
|
||||
|
||||
export const MixedContent = serverStory({
|
||||
events: [password, field("url", "http://build.example.test"), submit],
|
||||
check: "unreachable",
|
||||
})
|
||||
|
||||
export const Checking = serverStory({ events: [field("link", link), submit], check: "pending" })
|
||||
|
||||
export const CameraProbing = serverStory({ camera: "probing" })
|
||||
|
||||
export const CameraUnavailable = serverStory({ camera: "unavailable" })
|
||||
|
||||
export const CameraInsecure = serverStory({ camera: "insecure" })
|
||||
|
||||
export const NativePairing = serverStory({ camera: "none" })
|
||||
|
||||
export const Scanning = serverStory({ scanner: "ready" })
|
||||
|
||||
export const OpeningCamera = serverStory({ scanner: "opening" })
|
||||
|
||||
export const RedeemingScan = serverStory({ scanner: "redeeming" })
|
||||
|
||||
export const CameraError = serverStory({ scanner: "denied" })
|
||||
|
||||
export const InvalidQrCode = serverStory({ scanner: "invalid" })
|
||||
|
||||
export const DecodeFailed = serverStory({ scanner: "decode" })
|
||||
|
||||
export const ScanTimedOut = serverStory({ scanner: "timeout" })
|
||||
|
||||
export const EditPassword = serverStory({ target: edit })
|
||||
|
||||
export const SignedOut = serverStory({ target: { ...edit, original: { ...edit.original, unauthorized: true } } })
|
||||
|
||||
export const Closed = serverStory({ closed: true })
|
||||
@@ -4,53 +4,43 @@ import { Divider } from "@opencode/ui/divider"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import { TextInput } from "@opencode/ui/text-input"
|
||||
import { useDialog } from "@opencode/ui/context/dialog"
|
||||
import { type Component, Show, Suspense, createMemo, lazy, untrack } from "solid-js"
|
||||
import { type Component, type ComponentProps, Show, Suspense, createMemo, lazy, untrack } from "solid-js"
|
||||
import { useGlobal } from "@/runtime/server/runtime"
|
||||
import { useLanguage } from "@/runtime/i18n/language"
|
||||
import { ServerConnection, useServers } from "@/runtime/server/registry"
|
||||
import { useTabs } from "@/shell/tabs/tabs"
|
||||
import { isServerUnauthorized } from "@/runtime/server/health-machine"
|
||||
import { createServerConnectController } from "./controller"
|
||||
import { createServerConnectController, type ServerConnectControllerOptions } from "./controller"
|
||||
import type { ServerConnectField, ServerOriginal } from "./machine"
|
||||
import { ConnectMethodSwitch } from "./method"
|
||||
import "@/settings/settings.css"
|
||||
|
||||
const PairingScanner = lazy(() => import("./scanner").then((module) => ({ default: module.PairingScanner })))
|
||||
|
||||
export const DialogServer: Component<{
|
||||
type DialogLifecycle = Pick<
|
||||
Extract<ServerConnectControllerOptions, { surface: "dialog" }>,
|
||||
"surface" | "closing" | "onClose"
|
||||
>
|
||||
|
||||
export function DialogServer(props: {
|
||||
mode: "add" | "edit"
|
||||
server?: ServerConnection.Http
|
||||
onSave?: (server: ServerConnection.Http) => void
|
||||
}> = (props) => {
|
||||
const dialog = useDialog()
|
||||
createForm?: (dialog: DialogLifecycle) => ReturnType<typeof createServerConnectController>
|
||||
scanner?: Component<ComponentProps<typeof PairingScanner>>
|
||||
}) {
|
||||
const language = useLanguage()
|
||||
const servers = useServers()
|
||||
const global = useGlobal()
|
||||
const tabs = useTabs()
|
||||
const edited = props.mode === "edit" ? props.server : undefined
|
||||
const dialog = useDialog()
|
||||
const Scanner = props.scanner ?? PairingScanner
|
||||
|
||||
const originalOf = (server: ServerConnection.Http): ServerOriginal => ({
|
||||
url: server.http.url,
|
||||
displayName: server.displayName,
|
||||
password: server.http.password,
|
||||
unauthorized: isServerUnauthorized(global.servers.health[ServerConnection.key(server)]),
|
||||
})
|
||||
const createForm =
|
||||
props.createForm ??
|
||||
((dialog: DialogLifecycle) => createRegistryForm(dialog, props.mode === "edit" ? props.server : undefined))
|
||||
|
||||
const original = createMemo(() => {
|
||||
const server = servers.list.find(
|
||||
(item): item is ServerConnection.Http => item.type === "http" && item.http.url === edited?.http.url,
|
||||
)
|
||||
|
||||
return server && originalOf(server)
|
||||
})
|
||||
|
||||
const form = createServerConnectController({
|
||||
const form = createForm({
|
||||
surface: "dialog",
|
||||
target: edited ? { kind: "edit", original: untrack(original) ?? originalOf(edited) } : { kind: "add" },
|
||||
original,
|
||||
removeTabs: (key) => tabs.removeServer(key),
|
||||
closing: () => dialog.closing,
|
||||
// Close first: onSave may open the next dialog, such as the folder picker an interrupted action continues with.
|
||||
// onSave may open the next dialog, such as the folder picker an interrupted action continues with.
|
||||
onClose: (saved) => {
|
||||
dialog.close()
|
||||
|
||||
@@ -98,9 +88,9 @@ export const DialogServer: Component<{
|
||||
when={!view().scanning}
|
||||
fallback={
|
||||
<Suspense fallback={<p role="status">{language.t("server.connect.camera.starting")}</p>}>
|
||||
<PairingScanner
|
||||
onCancel={() => form.dispatch({ type: "scan.cancelled" })}
|
||||
<Scanner
|
||||
redeem={form.redeem}
|
||||
onCancel={() => form.dispatch({ type: "scan.cancelled" })}
|
||||
onScan={(link) => form.dispatch({ type: "scan.completed", link })}
|
||||
/>
|
||||
</Suspense>
|
||||
@@ -233,3 +223,31 @@ export const DialogServer: Component<{
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
function createRegistryForm(dialog: DialogLifecycle, edited: ServerConnection.Http | undefined) {
|
||||
const servers = useServers()
|
||||
const global = useGlobal()
|
||||
const tabs = useTabs()
|
||||
|
||||
const originalOf = (server: ServerConnection.Http): ServerOriginal => ({
|
||||
url: server.http.url,
|
||||
displayName: server.displayName,
|
||||
password: server.http.password,
|
||||
unauthorized: isServerUnauthorized(global.servers.health[ServerConnection.key(server)]),
|
||||
})
|
||||
|
||||
const original = createMemo(() => {
|
||||
const server = servers.list.find(
|
||||
(item): item is ServerConnection.Http => item.type === "http" && item.http.url === edited?.http.url,
|
||||
)
|
||||
|
||||
return server && originalOf(server)
|
||||
})
|
||||
|
||||
return createServerConnectController({
|
||||
...dialog,
|
||||
target: edited ? { kind: "edit", original: untrack(original) ?? originalOf(edited) } : { kind: "add" },
|
||||
original,
|
||||
removeTabs: (key) => tabs.removeServer(key),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useLanguage } from "@/runtime/i18n/language"
|
||||
import { usePlatform } from "@/runtime/platform/platform"
|
||||
import { isMixedContent } from "./browser"
|
||||
import { legacyPairingLink, pairingLink, redeemPairingLink, type Pairing } from "./pairing"
|
||||
|
||||
@@ -14,9 +13,8 @@ type Redeemed = { code?: string; pairing?: Pairing }
|
||||
// Pasted and scanned links share one redeem path so every surface explains a failure the same way.
|
||||
// Each form keeps the last token it redeemed: the code is spent, so a retry after a failed connection check reuses it,
|
||||
// whichever form the link takes (a scanned QR payload, or the link the scanner then shows).
|
||||
export function useRedeemPairing(): RedeemPairing {
|
||||
export function useRedeemPairing(exchange: typeof redeemPairingLink, pageHref?: string): RedeemPairing {
|
||||
const language = useLanguage()
|
||||
const platform = usePlatform()
|
||||
const last: Redeemed = {}
|
||||
|
||||
return async (value) => {
|
||||
@@ -32,7 +30,7 @@ export function useRedeemPairing(): RedeemPairing {
|
||||
return { pairing: { url, password: last.pairing.password } }
|
||||
}
|
||||
|
||||
const result = await redeemPairingLink(link)
|
||||
const result = await exchange(link)
|
||||
|
||||
if (result.type === "paired") {
|
||||
last.code = link.code
|
||||
@@ -44,7 +42,7 @@ export function useRedeemPairing(): RedeemPairing {
|
||||
if (result.type === "expired") return { error: language.t("server.connect.link.expired") }
|
||||
|
||||
// A QR code can carry several addresses; the HTTPS page can reach none of them only when every one is plain HTTP.
|
||||
if (platform.platform === "web" && link.urls.every((url) => isMixedContent(location.href, url)))
|
||||
if (pageHref && link.urls.every((url) => isMixedContent(pageHref, url)))
|
||||
return { error: language.t("server.connect.mixedContent") }
|
||||
|
||||
return { error: language.t("server.connect.link.unreachable", { url: link.urls.join(", ") }) }
|
||||
|
||||
@@ -16,7 +16,12 @@ import "./scanner.css"
|
||||
|
||||
// Redeems with the form's own redeem, so the form keeps the token and a failed connection check retries without the
|
||||
// spent code; the form gets back a link it can show, and fills it in.
|
||||
export function PairingScanner(props: { redeem: RedeemPairing; onScan: (link: string) => void; onCancel: () => void }) {
|
||||
export function PairingScanner(props: {
|
||||
redeem: RedeemPairing
|
||||
onScan: (link: string) => void
|
||||
onCancel: () => void
|
||||
camera?: typeof createCamera
|
||||
}) {
|
||||
const language = useLanguage()
|
||||
const [scannerState, setScannerState] = createSignal(createScannerState())
|
||||
const view = createMemo(() => selectScannerView(scannerState()))
|
||||
@@ -103,21 +108,12 @@ export function PairingScanner(props: { redeem: RedeemPairing; onScan: (link: st
|
||||
}
|
||||
|
||||
// QrScanner hides detached videos, so initialize only after this preview is mounted.
|
||||
const scanner = new QrScanner(video, (result) => dispatch({ type: "code.detected", data: result.data }), {
|
||||
preferredCamera: "environment",
|
||||
maxScansPerSecond: 10,
|
||||
returnDetailedScanResult: true,
|
||||
// QrScanner only logs a decoder that fails (for example, a worker the page may not start), so the preview
|
||||
// would look like it is still scanning.
|
||||
onDecodeError: (error) => {
|
||||
// The native BarcodeDetector engine reports an empty frame as "Scanner error: No QR code found".
|
||||
if (String(error).includes(QrScanner.NO_QR_CODE_FOUND)) return
|
||||
dispatch({ type: "decode.failed" })
|
||||
},
|
||||
})
|
||||
const scanner = (props.camera ?? createCamera)(
|
||||
video,
|
||||
(data) => dispatch({ type: "code.detected", data }),
|
||||
() => dispatch({ type: "decode.failed" }),
|
||||
)
|
||||
|
||||
// Terminal QR codes can be light-on-dark depending on the terminal theme.
|
||||
scanner.setInversionMode("both")
|
||||
onCleanup(() => {
|
||||
dispatch({ type: "disposed" })
|
||||
scanner.destroy()
|
||||
@@ -154,3 +150,24 @@ export function PairingScanner(props: { redeem: RedeemPairing; onScan: (link: st
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function createCamera(
|
||||
video: HTMLVideoElement,
|
||||
detect: (data: string) => void,
|
||||
failed: () => void,
|
||||
): Pick<QrScanner, "start" | "stop" | "destroy"> {
|
||||
const scanner = new QrScanner(video, (result) => detect(result.data), {
|
||||
preferredCamera: "environment",
|
||||
maxScansPerSecond: 10,
|
||||
returnDetailedScanResult: true,
|
||||
onDecodeError: (error) => {
|
||||
// The native BarcodeDetector engine reports an empty frame as "Scanner error: No QR code found".
|
||||
if (!String(error).includes(QrScanner.NO_QR_CODE_FOUND)) failed()
|
||||
},
|
||||
})
|
||||
|
||||
// Terminal QR codes can be light-on-dark depending on the terminal theme.
|
||||
scanner.setInversionMode("both")
|
||||
|
||||
return scanner
|
||||
}
|
||||
|
||||
@@ -18,19 +18,36 @@ import {
|
||||
type SshState,
|
||||
} from "../../../stories/mocks/gui-plugins/ssh"
|
||||
|
||||
type FixtureState = { item?: SshItem; before?: SshItem; step: number; timer?: ReturnType<typeof setTimeout> }
|
||||
const challenges = {
|
||||
trust: {
|
||||
id: "host-key",
|
||||
text: "The authenticity of host 'dev.example.com' can't be established.\nED25519 key fingerprint is SHA256:EXAMPLE-FINGERPRINT-FOR-STORY-ONLY.\nAre you sure you want to continue connecting?",
|
||||
confirm: true,
|
||||
},
|
||||
passphrase: { id: "passphrase", text: "Enter passphrase for key '~/.ssh/id_ed25519':", confirm: false },
|
||||
password: { id: "password", text: "brendon@dev.example.com's password:", confirm: false },
|
||||
otp: { id: "otp", text: "Verification code:", confirm: false },
|
||||
}
|
||||
|
||||
type FixtureState = {
|
||||
item?: SshItem
|
||||
before?: SshItem
|
||||
prompts: (keyof typeof challenges)[]
|
||||
timer?: ReturnType<typeof setTimeout>
|
||||
}
|
||||
|
||||
function Fixture(props: {
|
||||
session?: boolean
|
||||
settings?: boolean
|
||||
incompatible?: boolean
|
||||
keyOnly?: boolean
|
||||
incompatible?: true | "failed-update" | "version-mismatch"
|
||||
prompts?: (keyof typeof challenges)[]
|
||||
rejectPassword?: boolean
|
||||
connectionDelay?: number
|
||||
initial?: "connecting" | "password" | "confirmation" | "failure" | "required"
|
||||
initial?: "connecting" | "challenge" | "failure" | "required"
|
||||
responseDelay?: number
|
||||
}) {
|
||||
const state: FixtureState = {
|
||||
step: 0,
|
||||
prompts: [],
|
||||
item:
|
||||
props.initial === "required"
|
||||
? {
|
||||
@@ -52,15 +69,12 @@ function Fixture(props: {
|
||||
listeners.forEach((listener) => listener(snapshot()))
|
||||
}
|
||||
|
||||
const prompts = [
|
||||
{
|
||||
id: "host-key",
|
||||
text: "The authenticity of host 'dev.example.com' can't be established.\nED25519 key fingerprint is SHA256:EXAMPLE-FINGERPRINT-FOR-STORY-ONLY.\nAre you sure you want to continue connecting?",
|
||||
confirm: true,
|
||||
},
|
||||
{ id: "password", text: "brendon@dev.example.com's password:", confirm: false },
|
||||
{ id: "otp", text: "Verification code:", confirm: false },
|
||||
]
|
||||
const nextChallenge = () => {
|
||||
const next = state.prompts.shift()
|
||||
update(
|
||||
next ? { stage: "authentication", prompt: challenges[next] } : { stage: "ready", saved: true, prompt: undefined },
|
||||
)
|
||||
}
|
||||
|
||||
const api: SshPlatform = {
|
||||
getState: async () => snapshot(),
|
||||
@@ -74,8 +88,9 @@ function Fixture(props: {
|
||||
hosts: async () => ["devbox", "staging", "build-host"],
|
||||
start: async (input) => {
|
||||
clearTimeout(state.timer)
|
||||
state.before = state.item
|
||||
state.step = props.initial === "password" || props.initial === "required" ? 1 : 0
|
||||
state.before = state.item?.config.id === input.id ? state.item : undefined
|
||||
state.prompts =
|
||||
props.prompts?.slice() ?? (props.initial === "required" ? ["password", "otp"] : ["trust", "password", "otp"])
|
||||
state.item = {
|
||||
config: input,
|
||||
saved: props.initial === "required",
|
||||
@@ -84,42 +99,30 @@ function Fixture(props: {
|
||||
destination: "brendon@dev.example.com:22",
|
||||
}
|
||||
|
||||
update({ stage: "connecting" })
|
||||
|
||||
if (props.initial === "connecting") return
|
||||
|
||||
if (props.incompatible && !input.replace) {
|
||||
update({ stage: "incompatible", error: "version" })
|
||||
if (props.incompatible && !input.replace) return update({ stage: "incompatible", error: "version" })
|
||||
|
||||
return
|
||||
const connected = () => {
|
||||
if (props.incompatible === "failed-update") return update({ stage: "failed", error: "install" })
|
||||
|
||||
if (props.incompatible === "version-mismatch") return update({ stage: "incompatible", error: "version" })
|
||||
|
||||
if (props.initial === "failure" && state.before?.stage !== "failed")
|
||||
return update({ stage: "failed", error: "connection", detail: "Connection refused" })
|
||||
nextChallenge()
|
||||
}
|
||||
|
||||
if (props.connectionDelay) {
|
||||
update({ stage: "connecting" })
|
||||
state.timer = setTimeout(
|
||||
() => update(props.keyOnly ? { stage: "ready" } : { stage: "authentication", prompt: prompts[state.step] }),
|
||||
props.connectionDelay,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
update(
|
||||
props.initial === "failure"
|
||||
? {
|
||||
stage: "failed",
|
||||
error: "connection",
|
||||
detail: "ssh: connect to host dev.example.com port 22: Connection refused",
|
||||
}
|
||||
: { stage: "authentication", prompt: prompts[state.step] },
|
||||
)
|
||||
if (!props.connectionDelay) return connected()
|
||||
state.timer = setTimeout(connected, props.connectionDelay)
|
||||
},
|
||||
respond: async () => {
|
||||
respond: async (_id, prompt) => {
|
||||
const next = () => {
|
||||
state.step += 1
|
||||
update(
|
||||
state.step < prompts.length
|
||||
? { stage: "authentication", prompt: prompts[state.step] }
|
||||
: { stage: "ready", prompt: undefined },
|
||||
)
|
||||
if (props.rejectPassword && state.before?.stage !== "failed" && prompt === "password")
|
||||
return update({ stage: "failed", error: "connection", detail: "Permission denied", prompt: undefined })
|
||||
nextChallenge()
|
||||
}
|
||||
|
||||
if (!props.responseDelay) return next()
|
||||
@@ -306,15 +309,33 @@ export const Host = { render: () => <Fixture /> }
|
||||
|
||||
export const Connecting = { render: () => <Fixture initial="connecting" /> }
|
||||
|
||||
export const Password = { render: () => <Fixture initial="password" /> }
|
||||
export const KeyOnly = { render: () => <Fixture prompts={[]} connectionDelay={1500} /> }
|
||||
|
||||
export const SlowPassword = { render: () => <Fixture initial="password" responseDelay={5000} /> }
|
||||
export const Password = { render: () => <Fixture initial="challenge" prompts={["password", "otp"]} /> }
|
||||
|
||||
export const Confirmation = { render: () => <Fixture initial="confirmation" /> }
|
||||
export const SlowPassword = {
|
||||
render: () => <Fixture initial="challenge" prompts={["password", "otp"]} responseDelay={5000} />,
|
||||
}
|
||||
|
||||
export const KeyPassphraseRejected = {
|
||||
render: () => <Fixture initial="challenge" prompts={["passphrase", "password", "otp"]} responseDelay={700} />,
|
||||
}
|
||||
|
||||
export const VerificationCode = { render: () => <Fixture initial="challenge" prompts={["otp"]} /> }
|
||||
|
||||
export const Confirmation = { render: () => <Fixture initial="challenge" /> }
|
||||
|
||||
export const Failure = { render: () => <Fixture initial="failure" /> }
|
||||
|
||||
export const IncompatibleHost = { render: () => <Fixture incompatible /> }
|
||||
export const AuthenticationFailureRetry = { render: () => <Fixture prompts={["password"]} rejectPassword /> }
|
||||
|
||||
export const IncompatibleHost = { render: () => <Fixture incompatible prompts={[]} connectionDelay={1500} /> }
|
||||
|
||||
export const FailedUpdate = { render: () => <Fixture incompatible="failed-update" connectionDelay={1500} /> }
|
||||
|
||||
export const StillIncompatibleAfterUpdate = {
|
||||
render: () => <Fixture incompatible="version-mismatch" connectionDelay={1500} />,
|
||||
}
|
||||
|
||||
export const AuthenticationRequired = { render: () => <Fixture initial="required" /> }
|
||||
|
||||
@@ -324,4 +345,4 @@ export const IncompatibleSession = { render: () => <Fixture initial="required" s
|
||||
|
||||
export const InactiveSession = { render: () => <Fixture initial="required" session connectionDelay={3000} /> }
|
||||
|
||||
export const KeyReconnect = { render: () => <Fixture initial="required" session keyOnly connectionDelay={3000} /> }
|
||||
export const KeyReconnect = { render: () => <Fixture initial="required" session prompts={[]} connectionDelay={3000} /> }
|
||||
|
||||
@@ -99,6 +99,16 @@ export function DialogSsh(props: {
|
||||
submit()
|
||||
}
|
||||
|
||||
const ConnectionError = () => (
|
||||
<Show when={view().error}>
|
||||
{(error) => (
|
||||
<span id="ssh-error" class="settings-server-dialog-error !leading-[var(--line-height-compact)]" role="alert">
|
||||
{plugin.t(error())}
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
)
|
||||
|
||||
return (
|
||||
<Dialog fit class="settings-server-dialog">
|
||||
<DialogHeader hideClose={true}>
|
||||
@@ -127,9 +137,11 @@ export function DialogSsh(props: {
|
||||
autocomplete="off"
|
||||
disabled={view().inputsDisabled}
|
||||
invalid={!!view().error}
|
||||
aria-describedby={view().error ? "ssh-error" : undefined}
|
||||
onInput={(event) => dispatch({ type: "target.changed", value: event.currentTarget.value })}
|
||||
onKeyDown={keyDown}
|
||||
/>
|
||||
<ConnectionError />
|
||||
</div>
|
||||
<div class="flex w-full min-w-0 flex-col gap-2">
|
||||
<label class="settings-server-dialog-label" for="ssh-name">
|
||||
@@ -158,9 +170,13 @@ export function DialogSsh(props: {
|
||||
<Show when={prompt()} keyed>
|
||||
{(prompt) => (
|
||||
<div class="flex w-full min-w-0 flex-col gap-2">
|
||||
<pre id="ssh-prompt" class="ssh-prompt" dir="auto">
|
||||
<p
|
||||
id="ssh-prompt"
|
||||
class="settings-server-dialog-label max-h-[200px] overflow-auto whitespace-pre-wrap [overflow-wrap:anywhere] select-text"
|
||||
dir="auto"
|
||||
>
|
||||
{prompt.text}
|
||||
</pre>
|
||||
</p>
|
||||
<Show when={!prompt.confirm}>
|
||||
<TextInput
|
||||
id="ssh-response"
|
||||
@@ -192,12 +208,8 @@ export function DialogSsh(props: {
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
<Show when={view().error}>
|
||||
{(error) => (
|
||||
<span class="settings-server-dialog-error !leading-[var(--line-height-compact)]" role="alert">
|
||||
{plugin.t(error())}
|
||||
</span>
|
||||
)}
|
||||
<Show when={!view().showForm}>
|
||||
<ConnectionError />
|
||||
</Show>
|
||||
</div>
|
||||
</DialogBody>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { showToast } from "@opencode/ui/toast"
|
||||
import { createRoot, createSignal, lazy, onCleanup, Suspense, untrack, type JSX } from "solid-js"
|
||||
import { createMemo, createRoot, createSignal, lazy, on, onCleanup, Suspense, untrack, type JSX } from "solid-js"
|
||||
import { Command, createKeyed, MenuItem, Server, Style, type ServerEntry, type Plugin } from "@opencode/plugin/gui"
|
||||
import { onIdle } from "@opencode/plugin/gui/builtin"
|
||||
import { Ssh, type SshConfig, type SshItem } from "./contract"
|
||||
@@ -38,8 +38,16 @@ const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
||||
|
||||
const state = () => client()?.state()
|
||||
|
||||
// IPC updates rows in place; the controller observes list identity.
|
||||
const items = createMemo(
|
||||
on(
|
||||
() => state()?.revision,
|
||||
() => state()?.servers.slice() ?? [],
|
||||
),
|
||||
)
|
||||
|
||||
const ssh = createSshController({
|
||||
items: () => state()?.servers ?? [],
|
||||
items,
|
||||
api: client,
|
||||
// Resolves once main publishes the revision. Disabling the plugin, the attempt ending, or the main side going away
|
||||
// (a restarted main starts its revisions again) resolves it early.
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
.ssh-prompt {
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
font-family: var(--font-family-mono);
|
||||
font-size: 12px;
|
||||
line-height: var(--line-height-compact);
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
/* The same rules as the app's server dialog in settings.css, which may not be loaded when the palette opens this one. */
|
||||
[data-component="dialog-v2"].settings-server-dialog [data-slot="dialog-container"] {
|
||||
width: 480px;
|
||||
|
||||
Reference in New Issue
Block a user