import { TextAttributes } from "@opentui/core" import { useTerminalDimensions } from "@opentui/solid" import { createMemo, createResource, createSignal, For, Show } from "solid-js" import { renderUnicodeCompact } from "uqr" import { useClient } from "../context/client" import { useTheme } from "../context/theme" import { useDialog } from "../ui/dialog" import { errorMessage } from "../util/error" export type DialogPairCredentials = { readonly username: string readonly password: string } export function DialogPair(props: { credentials?: DialogPairCredentials }) { const client = useClient() const dialog = useDialog() const dimensions = useTerminalDimensions() const { themeV2 } = useTheme().contextual("elevated") const [loadError, setLoadError] = createSignal() const [showPassword, setShowPassword] = createSignal(false) const [passwordHover, setPasswordHover] = createSignal(false) dialog.setSize("large") dialog.setCentered(true) const [server] = createResource(() => client.api.server.get().catch((error) => { setLoadError(error) return undefined }), ) const info = createMemo(() => { const current = server() if (!current) return return { urls: current.urls, username: props.credentials?.username ?? "opencode", password: props.credentials?.password ?? "", } }) const horizontal = createMemo(() => dimensions().width >= 96) const content = () => { const value = info() if (!value) return return ( URLs {(url) => {url}} Username {value.username} Password setPasswordHover(true)} onMouseOut={() => setPasswordHover(false)} onMouseUp={() => setShowPassword((current) => !current)} > {showPassword() ? value.password : "************"} ["localhost", "127.0.0.1", "[::1]"].includes(new URL(url).hostname))}> Run `opencode service set hostname 0.0.0.0` to access the service remotely. {renderUnicodeCompact(JSON.stringify(value), { border: 1 })} ) } return ( Pair dialog.clear()}> esc Loading server information…}> = 36} fallback={ {content()} } > {content()} } > {(error) => ( Could not load server information {errorMessage(error())} Close and reopen Pair to try again. )} ) }