- {showBackToProjects ? : null} - - - - - - {selectedHost.projectName} - - - - - - + ({ padding: theme.spacing[4], gap: theme.spacing[2], }, - backButton: { - alignSelf: "flex-start", - paddingHorizontal: 0, - }, - headerBlock: { - marginTop: theme.spacing[2], - marginBottom: theme.spacing[4], - gap: theme.spacing[2], - }, - titleRow: { - flexDirection: "row", - alignItems: "center", - gap: theme.spacing[3], - }, - projectTitle: { - color: theme.colors.foreground, - fontSize: theme.fontSize.base, - fontWeight: theme.fontWeight.medium, - flexShrink: 1, - }, editButton: { padding: theme.spacing[1], }, diff --git a/packages/app/src/screens/settings-screen.tsx b/packages/app/src/screens/settings-screen.tsx index 7fc6dbe248..b1966dc04a 100644 --- a/packages/app/src/screens/settings-screen.tsx +++ b/packages/app/src/screens/settings-screen.tsx @@ -118,6 +118,7 @@ import { MetadataGenerationPage } from "@/screens/settings/metadata-generation-p import { HostVoicePage } from "@/screens/settings/voice/voice-page"; import ProjectsScreen from "@/screens/projects-screen"; import ProjectSettingsScreen from "@/screens/project-settings-screen"; +import { ProviderDetailPage } from "@/provider-settings"; import { SETTINGS_DESKTOP_DETAIL_MIN_WIDTH, SETTINGS_DESKTOP_SIDEBAR_WIDTH, @@ -990,6 +991,7 @@ function SettingsSidebar({ let selectedHostSection: HostSectionSlug | null = null; if (view.kind === "host") selectedHostSection = view.section; if (view.kind === "project") selectedHostSection = "projects"; + if (view.kind === "provider") selectedHostSection = "providers"; if (view.kind === "plugin" || view.kind === "pluginListing") selectedHostSection = "plugins"; const sidebarBody = ( @@ -1137,7 +1139,8 @@ export default function SettingsScreen({ view }: SettingsScreenProps) { view.kind === "host" || view.kind === "project" || view.kind === "plugin" || - view.kind === "pluginListing" + view.kind === "pluginListing" || + view.kind === "provider" ) return view.serverId; return resolveActiveHostServerId({ @@ -1216,8 +1219,12 @@ export default function SettingsScreen({ view }: SettingsScreenProps) { const handleSelectHost = useCallback( (serverId: string) => { selectSettingsHost(serverId); - if (view.kind === "project") { - const target = buildSettingsHostSectionRoute(serverId, "projects"); + if (view.kind === "project" || view.kind === "provider") { + // The detail belongs to the old host; open the same list on the new one. + const target = buildSettingsHostSectionRoute( + serverId, + view.kind === "project" ? "projects" : "providers", + ); if (isCompactLayout) { router.push(target); } else { @@ -1296,6 +1303,7 @@ export default function SettingsScreen({ view }: SettingsScreenProps) { if (view.kind === "project") { return t("settings.projects"); } + if (view.kind === "provider") return t("settings.hostSections.providers"); return undefined; })(); @@ -1331,6 +1339,16 @@ export default function SettingsScreen({ view }: SettingsScreenProps) { /> ); } + if (view.kind === "provider") { + return ( + + ); + } if (view.kind === "section") { const item = SIDEBAR_SECTION_ITEMS.find((candidate) => candidate.id === view.section); if (!item || !isSectionAvailable(item, isDesktopApp, hardwareKeyboardPresent)) return null; diff --git a/packages/app/src/screens/settings/host-page.tsx b/packages/app/src/screens/settings/host-page.tsx index 9c0c952488..6e27f70650 100644 --- a/packages/app/src/screens/settings/host-page.tsx +++ b/packages/app/src/screens/settings/host-page.tsx @@ -49,7 +49,8 @@ import { useHostRuntimeSnapshot, useHosts, } from "@/runtime/host-runtime"; -import { ProvidersSection } from "@/screens/settings/providers-section"; +import { ProviderList } from "@/provider-settings"; +import { openProviderSettings } from "@/navigation/settings-navigation"; import { HostUsageSection } from "@/usage"; import { HostAppearanceSection } from "@/screens/settings/host-appearance-section"; import { SettingsSection } from "@/components/settings/headings/settings-section"; @@ -334,6 +335,10 @@ export function HostWorkspacesPage({ serverId }: { serverId: string }) { export function HostProvidersPage({ serverId }: { serverId: string }) { const host = useHostProfile(serverId); + const openProvider = useCallback( + (providerId: string) => openProviderSettings(serverId, providerId), + [serverId], + ); if (!host) { return ; @@ -341,7 +346,7 @@ export function HostProvidersPage({ serverId }: { serverId: string }) { return ( - + ); } diff --git a/packages/app/src/screens/settings/metadata-generation-page.tsx b/packages/app/src/screens/settings/metadata-generation-page.tsx index 0e8d895228..e88c379df6 100644 --- a/packages/app/src/screens/settings/metadata-generation-page.tsx +++ b/packages/app/src/screens/settings/metadata-generation-page.tsx @@ -19,12 +19,15 @@ export function MetadataGenerationPage({ serverId }: { serverId: string }) { const { t } = useTranslation(); const { config, isLoading: isConfigLoading, patchConfig } = useDaemonConfig(serverId); const snapshot = useProvidersSnapshot(serverId); - const providers = useMemo( - () => buildSelectableProviderSelectorProviders(snapshot.entries), - [snapshot.entries], - ); const configuredProviders = config?.metadataGeneration.providers; const configuredProvider = configuredProviders?.[0] ?? null; + const providers = useMemo( + () => + buildSelectableProviderSelectorProviders(snapshot.entries, { + selectedProvider: configuredProvider?.provider ?? null, + }), + [configuredProvider?.provider, snapshot.entries], + ); const savedMode: SelectionMode = configuredProvider ? "preferred" : "automatic"; const [draftMode, setDraftMode] = useState(null); const [isSaving, setIsSaving] = useState(false); diff --git a/packages/app/src/screens/settings/providers-section.test.tsx b/packages/app/src/screens/settings/providers-section.test.tsx deleted file mode 100644 index 3e55134520..0000000000 --- a/packages/app/src/screens/settings/providers-section.test.tsx +++ /dev/null @@ -1,453 +0,0 @@ -/** - * @vitest-environment jsdom - */ -import React, { act } from "react"; -import { createRoot, type Root } from "react-dom/client"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import type { ProviderSnapshotEntry } from "@getpaseo/protocol/agent-types"; -import type { MutableDaemonConfig } from "@getpaseo/protocol/messages"; -import { ToastApiProvider } from "@/contexts/toast-api-context"; - -const { snapshotState, configState, patchConfigMock, openProviderSettingsMock } = vi.hoisted( - () => ({ - snapshotState: { - entries: undefined as ProviderSnapshotEntry[] | undefined, - isLoading: false, - isRefreshing: false, - }, - configState: { - config: null as MutableDaemonConfig | null, - }, - patchConfigMock: vi.fn(async () => undefined), - openProviderSettingsMock: vi.fn(), - }), -); - -vi.mock("react-native", async (importOriginal) => ({ - ...(await importOriginal()), - View: ({ children, testID }: { children?: React.ReactNode; testID?: string }) => - React.createElement("div", { "data-testid": testID }, children), - Text: ({ children }: { children?: React.ReactNode }) => - React.createElement("span", null, children), - Pressable: ({ - children, - onPress, - onHoverIn, - onHoverOut, - accessibilityRole, - accessibilityLabel, - disabled, - testID, - }: { - children?: - | React.ReactNode - | ((state: { pressed: boolean; hovered: boolean }) => React.ReactNode); - onPress?: (event: React.MouseEvent) => void; - onHoverIn?: () => void; - onHoverOut?: () => void; - accessibilityRole?: string; - accessibilityLabel?: string; - disabled?: boolean; - testID?: string; - }) => - React.createElement( - "div", - { - role: accessibilityRole, - "aria-label": accessibilityLabel, - "aria-disabled": disabled ? "true" : undefined, - "data-testid": testID, - onClick: disabled ? undefined : onPress, - onMouseEnter: onHoverIn, - onMouseLeave: onHoverOut, - }, - typeof children === "function" ? children({ pressed: false, hovered: false }) : children, - ), - ActivityIndicator: () => React.createElement("span", { "data-testid": "activity-indicator" }), -})); - -vi.mock("lucide-react-native", () => { - const icon = (name: string) => () => React.createElement("span", { "data-icon": name }); - return { - ChevronRight: icon("ChevronRight"), - MoreHorizontal: icon("MoreHorizontal"), - Trash2: icon("Trash2"), - }; -}); - -vi.mock("react-i18next", () => ({ - useTranslation: () => ({ - t: (key: string, values?: Record) => - ( - ({ - "settings.providers.providerDetails": "{{name}} provider details", - "settings.providers.enableProvider": "Enable {{name}}", - "settings.providers.statuses.disabled": "Disabled", - "settings.providers.statuses.available": "Available", - "settings.providers.statuses.loading": "Loading", - "settings.providers.statuses.error": "Error", - "settings.providers.statuses.notInstalled": "Not installed", - "settings.providers.models.one": "1 model", - "settings.providers.models.many": "{{count}} models", - "settings.providers.addErrorTitle": "Unable to add provider", - "settings.providers.updateErrorTitle": "Unable to update provider", - "settings.providers.actions.menu": "{{name}} actions", - "settings.providers.actions.remove": "Remove provider", - "settings.providers.actions.removing": "Removing...", - "settings.providers.remove.confirmTitle": "Remove {{name}}?", - "settings.providers.remove.confirmMessage": - "This deletes the provider entry from config.json. It cannot be undone.", - "settings.providers.remove.confirm": "Remove", - "settings.providers.remove.errorTitle": "Unable to remove provider", - })[key] ?? key - ) - .replaceAll("{{name}}", String(values?.name ?? "")) - .replaceAll("{{count}}", String(values?.count ?? "")), - }), -})); - -vi.mock("@/components/ui/switch", () => ({ - Switch: ({ - value, - onValueChange, - disabled, - accessibilityLabel, - testID, - }: { - value: boolean; - onValueChange?: (next: boolean) => void; - disabled?: boolean; - accessibilityLabel?: string; - testID?: string; - }) => - React.createElement("div", { - role: "switch", - "aria-checked": value ? "true" : "false", - "aria-disabled": disabled ? "true" : undefined, - "aria-label": accessibilityLabel, - "data-testid": testID ?? "provider-switch", - onClick: (event: React.MouseEvent) => { - event.stopPropagation(); - if (disabled) return; - onValueChange?.(!value); - }, - }), -})); - -vi.mock("@/components/ui/loading-spinner", () => ({ - LoadingSpinner: () => React.createElement("span", { "data-testid": "loading-spinner" }), -})); - -vi.mock("@/components/settings/headings/settings-info-tip", () => ({ - SettingsInfoTip: () => null, -})); - -vi.mock("@/components/ui/external-link", () => ({ - ExternalLink: () => null, - ExternalLinkLabel: () => null, -})); - -vi.mock("@/components/ui/dropdown-menu", () => ({ - DropdownMenu: ({ children }: { children?: React.ReactNode }) => - React.createElement("div", null, children), - DropdownMenuTrigger: ({ - children, - onPressIn, - accessibilityRole, - accessibilityLabel, - testID, - }: { - children?: - | React.ReactNode - | ((state: { pressed: boolean; hovered: boolean; open: boolean }) => React.ReactNode); - onPressIn?: (event: { stopPropagation: () => void }) => void; - accessibilityRole?: string; - accessibilityLabel?: string; - testID?: string; - }) => - React.createElement( - "button", - { - type: "button", - role: accessibilityRole, - "aria-label": accessibilityLabel, - "data-testid": testID, - onMouseDown: (event: React.MouseEvent) => onPressIn?.(event), - onClick: (event: React.MouseEvent) => event.stopPropagation(), - }, - typeof children === "function" - ? children({ pressed: false, hovered: false, open: false }) - : children, - ), - DropdownMenuContent: ({ children }: { children?: React.ReactNode }) => - React.createElement("div", null, children), - DropdownMenuItem: ({ - children, - onSelect, - status, - pendingLabel, - testID, - }: { - children?: React.ReactNode; - onSelect?: () => void; - status?: "idle" | "pending" | "success"; - pendingLabel?: string; - testID?: string; - }) => - React.createElement( - "button", - { - type: "button", - "data-testid": testID, - disabled: status === "pending" || status === "success", - onClick: (event: React.MouseEvent) => { - event.stopPropagation(); - onSelect?.(); - }, - }, - status === "pending" ? pendingLabel : children, - ), -})); - -vi.mock("@/components/provider-icons", () => ({ - useProviderIcon: (provider: string) => () => - React.createElement("span", { "data-icon": `provider-${provider}` }), -})); - -vi.mock("@/stores/provider-settings-store", () => ({ - useProviderSettingsStore: (selector: (state: unknown) => unknown) => - selector({ open: openProviderSettingsMock }), -})); - -vi.mock("@/components/provider-catalog-list", () => ({ - ProviderCatalogList: () => null, -})); - -vi.mock("@/hooks/use-providers-snapshot", () => ({ - useProvidersSnapshot: () => ({ - entries: snapshotState.entries, - isLoading: snapshotState.isLoading, - isFetching: false, - isRefreshing: snapshotState.isRefreshing, - error: null, - supportsSnapshot: true, - refresh: vi.fn(async () => {}), - refetchIfStale: vi.fn(), - }), -})); - -vi.mock("@/hooks/use-daemon-config", () => ({ - useDaemonConfig: () => ({ - config: configState.config, - isLoading: false, - patchConfig: patchConfigMock, - }), -})); - -vi.mock("@/runtime/host-runtime", () => ({ - useHostRuntimeIsConnected: () => true, -})); - -vi.mock("@/runtime/host-features", () => ({ - useHostFeature: () => false, -})); - -vi.mock("@/utils/confirm-dialog", () => ({ - confirmDialog: vi.fn(async () => true), -})); - -import { ProvidersSection } from "./providers-section"; - -function unexpectedToast(): never { - throw new Error("Provider row interactions should not display a toast"); -} - -const toastApi = { show: unexpectedToast, copied: unexpectedToast, error: unexpectedToast }; - -const claudeEntry: ProviderSnapshotEntry = { - provider: "claude", - status: "ready", - enabled: true, - label: "Claude", - description: "Claude Code", - defaultModeId: null, - modes: [], - models: [ - { provider: "claude", id: "claude-opus-4-7", label: "Claude Opus 4.7" }, - { provider: "claude", id: "claude-sonnet-4-6", label: "Claude Sonnet 4.6" }, - { provider: "claude", id: "claude-haiku-4-5", label: "Claude Haiku 4.5" }, - ], -}; - -const disabledCodexEntry: ProviderSnapshotEntry = { - provider: "codex", - status: "unavailable", - enabled: false, - label: "Codex", - description: "OpenAI Codex", - defaultModeId: null, - modes: [], -}; - -function makeConfig(providers: MutableDaemonConfig["providers"] = {}): MutableDaemonConfig { - return { - relay: { enabled: false }, - mcp: { injectIntoAgents: false }, - browserTools: { enabled: false }, - providers, - metadataGeneration: { providers: [] }, - autoArchiveAfterMerge: false, - enableTerminalAgentHooks: false, - appendSystemPrompt: "", - }; -} - -function descendants(el: HTMLElement): HTMLElement[] { - return Array.from(el.querySelectorAll("*")); -} - -function indexOfMatches(nodes: HTMLElement[], selector: string): number { - return nodes.findIndex((node) => node.matches(selector)); -} - -function indexOfText(nodes: HTMLElement[], text: string): number { - return nodes.findIndex((node) => node.textContent?.trim() === text); -} - -describe("ProvidersSection", () => { - let root: Root | null = null; - let container: HTMLElement | null = null; - - beforeEach(() => { - vi.stubGlobal("React", React); - vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); - - container = document.createElement("div"); - document.body.appendChild(container); - root = createRoot(container); - - snapshotState.entries = undefined; - snapshotState.isLoading = false; - snapshotState.isRefreshing = false; - configState.config = null; - patchConfigMock.mockReset(); - patchConfigMock.mockResolvedValue(undefined); - openProviderSettingsMock.mockReset(); - }); - - afterEach(() => { - if (root) { - act(() => { - root?.unmount(); - }); - } - root = null; - container?.remove(); - container = null; - vi.unstubAllGlobals(); - }); - - function render(): void { - act(() => { - root?.render( - - - , - ); - }); - } - - function findRow(accessibilityLabel: string): HTMLElement { - const row = container?.querySelector( - `[role="button"][aria-label="${accessibilityLabel}"]`, - ); - if (!row) throw new Error(`Expected row with aria-label "${accessibilityLabel}"`); - return row; - } - - it("renders the disabled provider with its server-provided label in snapshot order", () => { - snapshotState.entries = [claudeEntry, disabledCodexEntry]; - configState.config = makeConfig({ codex: { enabled: false } }); - - render(); - - const rows = Array.from( - container?.querySelectorAll('[role="button"][aria-label$="provider details"]') ?? - [], - ); - expect(rows.map((row) => row.getAttribute("aria-label"))).toEqual([ - "Claude provider details", - "Codex provider details", - ]); - - const codexRow = findRow("Codex provider details"); - const codexNodes = descendants(codexRow); - expect(indexOfText(codexNodes, "Codex")).toBeGreaterThanOrEqual(0); - expect(indexOfText(codexNodes, "codex")).toBe(-1); - expect(indexOfText(codexNodes, "Disabled")).toBeGreaterThanOrEqual(0); - }); - - it("composes the row as chevron, icon, label, status, model count, then switch", () => { - snapshotState.entries = [claudeEntry]; - configState.config = makeConfig(); - - render(); - - const row = findRow("Claude provider details"); - const nodes = descendants(row); - const chevron = indexOfMatches(nodes, '[data-icon="ChevronRight"]'); - const icon = indexOfMatches(nodes, '[data-icon="provider-claude"]'); - const label = indexOfText(nodes, "Claude"); - const status = indexOfText(nodes, "Available"); - const modelCount = indexOfText(nodes, "3 models"); - const switchEl = indexOfMatches(nodes, '[role="switch"]'); - - expect(chevron).toBeGreaterThanOrEqual(0); - expect(icon).toBeGreaterThan(chevron); - expect(label).toBeGreaterThan(icon); - expect(status).toBeGreaterThan(label); - expect(modelCount).toBeGreaterThan(status); - expect(switchEl).toBeGreaterThan(modelCount); - }); - - it("opens the diagnostic sheet when the outer row is pressed for a disabled provider", () => { - snapshotState.entries = [disabledCodexEntry]; - configState.config = makeConfig({ codex: { enabled: false } }); - - render(); - - expect(openProviderSettingsMock).not.toHaveBeenCalled(); - - const row = findRow("Codex provider details"); - act(() => { - row.dispatchEvent(new window.MouseEvent("click", { bubbles: true })); - }); - - expect(openProviderSettingsMock).toHaveBeenCalledTimes(1); - expect(openProviderSettingsMock).toHaveBeenCalledWith({ - serverId: "server-1", - provider: "codex", - }); - }); - - it("toggles the provider enabled flag through patchConfig when the switch is pressed", async () => { - snapshotState.entries = [claudeEntry]; - configState.config = makeConfig(); - - render(); - - const row = findRow("Claude provider details"); - const switchEl = row.querySelector('[role="switch"]'); - expect(switchEl).not.toBeNull(); - expect(switchEl?.getAttribute("aria-checked")).toBe("true"); - - await act(async () => { - switchEl?.dispatchEvent(new window.MouseEvent("click", { bubbles: true })); - }); - - expect(patchConfigMock).toHaveBeenCalledTimes(1); - expect(patchConfigMock).toHaveBeenCalledWith({ - providers: { claude: { enabled: false } }, - }); - }); -}); diff --git a/packages/app/src/screens/settings/providers-section.tsx b/packages/app/src/screens/settings/providers-section.tsx deleted file mode 100644 index 078cf086f5..0000000000 --- a/packages/app/src/screens/settings/providers-section.tsx +++ /dev/null @@ -1,622 +0,0 @@ -import { useCallback, useMemo, useRef, useState } from "react"; -import type { TFunction } from "i18next"; -import { useTranslation } from "react-i18next"; -import { - Alert, - Pressable, - Text, - View, - type GestureResponderEvent, - type PressableStateCallbackType, -} from "react-native"; -import { StyleSheet, useUnistyles } from "react-native-unistyles"; -import { useIsCompactFormFactor } from "@/constants/layout"; -import { useToast } from "@/contexts/toast-api-context"; -import { settingsStyles } from "@/styles/settings"; -import { useHostRuntimeIsConnected } from "@/runtime/host-runtime"; -import { selectHostFeature, useHostFeature } from "@/runtime/host-features"; -import { useSessionStore } from "@/stores/session-store"; -import { useProvidersSnapshot } from "@/hooks/use-providers-snapshot"; -import { useDaemonConfig } from "@/hooks/use-daemon-config"; -import { buildProviderDefinitions } from "@/utils/provider-definitions"; -import { - buildAcpProviderConfigPatch, - getAcpProviderCatalog, - type AcpProviderCatalogItem, -} from "@/hooks/use-acp-provider-catalog"; -import { ProviderCatalogList } from "@/components/provider-catalog-list"; -import { useProviderIcon } from "@/components/provider-icons"; -import { LoadingSpinner } from "@/components/ui/loading-spinner"; -import { SkeletonPulse, useSkeletonPulse } from "@/components/ui/skeleton"; -import { Switch } from "@/components/ui/switch"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu"; -import { SettingsSection } from "@/components/settings/headings/settings-section"; -import { useProviderSettingsStore } from "@/stores/provider-settings-store"; -import { confirmDialog } from "@/utils/confirm-dialog"; -import { filterSelectableModels } from "@/provider-selection/model-catalog"; -import { ChevronRight, MoreHorizontal, Trash2 } from "lucide-react-native"; - -type ProviderDefinition = ReturnType[number]; -type ProviderEntry = NonNullable["entries"]>[number]; - -type StatusTone = "success" | "warning" | "danger" | "muted" | "loading"; - -interface ProviderStatus { - tone: StatusTone; - label: string; - modelCount: number | null; -} - -function getProviderStatus( - status: string, - enabled: boolean, - modelCount: number, - t: TFunction, -): ProviderStatus { - if (!enabled) - return { tone: "muted", label: t("settings.providers.statuses.disabled"), modelCount: null }; - if (status === "loading") { - return { tone: "loading", label: t("settings.providers.statuses.loading"), modelCount: null }; - } - if (status === "error") { - return { tone: "danger", label: t("settings.providers.statuses.error"), modelCount: null }; - } - if (status === "ready") { - return { - tone: "success", - label: t("settings.providers.statuses.available"), - modelCount: modelCount > 0 ? modelCount : null, - }; - } - return { - tone: "warning", - label: t("settings.providers.statuses.notInstalled"), - modelCount: null, - }; -} - -interface ProviderRowProps { - serverId: string; - def: ProviderDefinition; - entry: ProviderEntry; - enabled: boolean; - isToggling: boolean; - isRemoving: boolean; - canRemove: boolean; - isFirst: boolean; - onPress: (providerId: string) => void; - onToggleEnabled: (providerId: string, enabled: boolean) => void; - onRemove: (providerId: string, providerLabel: string) => void; -} - -function stopPressInPropagation(event: GestureResponderEvent) { - event.stopPropagation(); -} - -interface ProviderActionsMenuProps { - providerId: string; - providerLabel: string; - isRemoving: boolean; - iconSize: number; - foregroundColor: string; - foregroundMutedColor: string; - dangerColor: string; - onRemove: (providerId: string, providerLabel: string) => void; -} - -function ProviderActionsMenu({ - providerId, - providerLabel, - isRemoving, - iconSize, - foregroundColor, - foregroundMutedColor, - dangerColor, - onRemove, -}: ProviderActionsMenuProps) { - const { t } = useTranslation(); - const handleRemove = useCallback(() => { - onRemove(providerId, providerLabel); - }, [onRemove, providerId, providerLabel]); - const triggerStyle = useCallback( - ({ - pressed, - hovered, - open, - }: PressableStateCallbackType & { hovered?: boolean; open?: boolean }) => [ - styles.menuButton, - (hovered || open) && styles.menuButtonHovered, - pressed && styles.menuButtonPressed, - ], - [], - ); - const trashLeading = useMemo(() => , [dangerColor]); - - return ( - - - {({ hovered, open }) => ( - - )} - - - - {t("settings.providers.actions.remove")} - - - - ); -} - -const SKELETON_ROW_KEYS = [0, 1, 2, 3].map((index) => `provider-skeleton-row-${index}`); - -function ProviderRowsSkeleton() { - const { t } = useTranslation(); - const pulse = useSkeletonPulse(); - return ( - - {SKELETON_ROW_KEYS.map((key, index) => ( - 0 && settingsStyles.rowBorder, styles.row]} - > - - - - - - - ))} - - ); -} - -function ProviderRow({ - serverId, - def, - entry, - enabled, - isToggling, - isRemoving, - canRemove, - isFirst, - onPress, - onToggleEnabled, - onRemove, -}: ProviderRowProps) { - const { t } = useTranslation(); - const { theme } = useUnistyles(); - const isCompact = useIsCompactFormFactor(); - const ProviderIcon = useProviderIcon(def.id, serverId); - const providerError = - enabled && - entry.status === "error" && - typeof entry.error === "string" && - entry.error.trim().length > 0 - ? entry.error.trim() - : null; - const modelCount = filterSelectableModels(entry.models ?? null)?.length ?? 0; - const providerStatus = getProviderStatus(entry.status, enabled, modelCount, t); - - const handlePress = useCallback(() => { - onPress(def.id); - }, [def.id, onPress]); - const handleToggleValueChange = useCallback( - (value: boolean) => { - onToggleEnabled(def.id, value); - }, - [def.id, onToggleEnabled], - ); - const rowStyle = useCallback( - ({ pressed, hovered }: PressableStateCallbackType & { hovered?: boolean }) => [ - settingsStyles.row, - !isFirst && settingsStyles.rowBorder, - styles.row, - hovered && styles.rowHovered, - pressed && styles.rowPressed, - ], - [isFirst], - ); - - return ( - - {({ hovered }: PressableStateCallbackType & { hovered?: boolean }) => ( - <> - - - - - - - {def.label} - - {!isCompact ? · : null} - - - {providerError && !isCompact ? ( - - {providerError} - - ) : null} - - - {/* The menu leads the switch, so every switch sits on the row's right edge without - rows that have no menu reserving room for one. */} - - {canRemove ? ( - - ) : null} - - - - )} - - ); -} - -function getDotColor(tone: StatusTone, theme: ReturnType["theme"]): string { - switch (tone) { - case "success": - return theme.colors.statusSuccess; - case "warning": - return theme.colors.statusWarning; - case "danger": - return theme.colors.statusDanger; - default: - return theme.colors.foregroundMuted; - } -} - -function StatusIndicator({ status, compact }: { status: ProviderStatus; compact: boolean }) { - const { t } = useTranslation(); - const { theme } = useUnistyles(); - const dotStyle = useMemo( - () => [styles.statusDot, { backgroundColor: getDotColor(status.tone, theme) }], - [status.tone, theme], - ); - - return ( - - {status.tone === "loading" ? ( - - ) : ( - - )} - {!compact ? ( - <> - {status.label} - {status.modelCount !== null ? ( - <> - · - - {status.modelCount === 1 - ? t("settings.providers.models.one") - : t("settings.providers.models.many", { count: status.modelCount })} - - - ) : null} - - ) : null} - - ); -} - -export interface ProvidersSectionProps { - serverId: string; -} - -export function ProvidersSection({ serverId }: ProvidersSectionProps) { - const { t } = useTranslation(); - const toast = useToast(); - const isConnected = useHostRuntimeIsConnected(serverId); - const supportsProviderRemoval = useHostFeature(serverId, "providerRemoval"); - const { entries, isLoading, refresh } = useProvidersSnapshot(serverId); - const { config, patchConfig } = useDaemonConfig(serverId); - const openProviderSettings = useProviderSettingsStore((state) => state.open); - const [pendingProviderId, setPendingProviderId] = useState(null); - const [removingProviderId, setRemovingProviderId] = useState(null); - const removingProviderIdRef = useRef(null); - const [installingProviderId, setInstallingProviderId] = useState(null); - - const providerDefinitions = useMemo(() => buildProviderDefinitions(entries), [entries]); - const hasServer = serverId.length > 0; - - /** Config owns derived providers and opt-in bundled catalog providers. */ - const isConfigOwnedProvider = useCallback( - (providerId: string) => - Boolean( - config?.providers?.[providerId] && - (config.providers[providerId].extends || - getAcpProviderCatalog().some( - (entry) => entry.id === providerId && entry.bundledProvider, - )), - ), - [config], - ); - - const handleOpenProviderSettings = useCallback( - (providerId: string) => { - openProviderSettings({ serverId, provider: providerId }); - }, - [openProviderSettings, serverId], - ); - - const handleToggleEnabled = useCallback( - async (providerId: string, enabled: boolean) => { - setPendingProviderId(providerId); - try { - await patchConfig({ providers: { [providerId]: { enabled } } }); - } catch (error) { - Alert.alert( - t("settings.providers.updateErrorTitle"), - error instanceof Error ? error.message : String(error), - ); - } finally { - setPendingProviderId((current) => (current === providerId ? null : current)); - } - }, - [patchConfig, t], - ); - - const handleRemoveProvider = useCallback( - async (providerId: string, providerLabel: string) => { - if (removingProviderIdRef.current) return; - removingProviderIdRef.current = providerId; - setRemovingProviderId(providerId); - try { - const confirmed = await confirmDialog({ - title: t("settings.providers.remove.confirmTitle", { name: providerLabel }), - message: t("settings.providers.remove.confirmMessage"), - confirmLabel: t("settings.providers.remove.confirm"), - destructive: true, - }); - if (!confirmed) { - return; - } - - await patchConfig({ removeProviders: [providerId] }); - } catch (error) { - Alert.alert( - t("settings.providers.remove.errorTitle"), - error instanceof Error ? error.message : String(error), - ); - } finally { - if (removingProviderIdRef.current === providerId) { - removingProviderIdRef.current = null; - } - setRemovingProviderId((current) => (current === providerId ? null : current)); - } - }, - [patchConfig, t], - ); - - const handleInstall = useCallback( - async (entry: AcpProviderCatalogItem) => { - if (installingProviderId) return; - setInstallingProviderId(entry.id); - try { - await patchConfig( - buildAcpProviderConfigPatch(entry, (feature) => - selectHostFeature(useSessionStore.getState(), serverId, feature), - ), - ); - await refresh([entry.id]); - } catch (error) { - toast.error(error instanceof Error ? error.message : String(error)); - } finally { - setInstallingProviderId((current) => (current === entry.id ? null : current)); - } - }, - [installingProviderId, patchConfig, refresh, serverId, toast], - ); - - return ( - <> - - {!hasServer || !isConnected ? ( - - {t("settings.providers.unavailable")} - - ) : null} - {hasServer && isConnected && isLoading ? : null} - {hasServer && isConnected && !isLoading && providerDefinitions.length > 0 ? ( - - {providerDefinitions.map((def, index) => { - const entry = entries?.find((candidate) => candidate.provider === def.id); - if (!entry) return null; - return ( - - ); - })} - - ) : null} - - - {hasServer && isConnected ? ( - - - - ) : null} - - ); -} - -const styles = StyleSheet.create((theme) => ({ - sectionSpacing: { - marginBottom: theme.spacing[4], - }, - addProviderSection: { - marginTop: theme.spacing[4], - }, - emptyCard: { - padding: theme.spacing[4], - alignItems: "center", - }, - emptyText: { - color: theme.colors.foregroundMuted, - fontSize: theme.fontSize.base, - }, - row: { - gap: theme.spacing[3], - minHeight: 56, - }, - rowHovered: { - backgroundColor: theme.colors.surface2, - }, - skeletonIcon: { - width: 20, - height: 20, - marginLeft: theme.spacing[6], - borderRadius: theme.borderRadius.md, - backgroundColor: theme.colors.surface2, - }, - skeletonTitle: { - width: 160, - height: 12, - borderRadius: theme.borderRadius.sm, - backgroundColor: theme.colors.surface2, - }, - skeletonSwitch: { - width: 36, - height: 20, - borderRadius: theme.borderRadius.full, - backgroundColor: theme.colors.surface2, - }, - rowPressed: { - backgroundColor: theme.colors.surface3, - }, - rowContent: { - flex: 1, - flexDirection: "row", - alignItems: "center", - gap: theme.spacing[2], - }, - textColumn: { - flex: 1, - minWidth: 0, - }, - titleRow: { - flexDirection: "row", - alignItems: "center", - gap: theme.spacing[2], - }, - statusRow: { - flexDirection: "row", - alignItems: "center", - gap: theme.spacing[1.5], - }, - statusDot: { - width: 8, - height: 8, - borderRadius: 4, - }, - statusLabel: { - color: theme.colors.foregroundMuted, - fontSize: theme.fontSize.base, - }, - separator: { - color: theme.colors.foregroundMuted, - fontSize: theme.fontSize.base, - }, - errorText: { - color: theme.colors.palette.red[300], - fontSize: theme.fontSize.sm, - marginTop: theme.spacing[1], - }, - trailingControls: { - flexDirection: "row", - alignItems: "center", - gap: theme.spacing[1], - }, - menuButton: { - width: 32, - height: 32, - borderRadius: theme.borderRadius.lg, - alignItems: "center", - justifyContent: "center", - }, - menuButtonHovered: { - backgroundColor: theme.colors.surface2, - }, - menuButtonPressed: { - backgroundColor: theme.colors.surface3, - }, -})); diff --git a/packages/app/src/utils/host-routes.test.ts b/packages/app/src/utils/host-routes.test.ts index 1687563603..2defc505f6 100644 --- a/packages/app/src/utils/host-routes.test.ts +++ b/packages/app/src/utils/host-routes.test.ts @@ -17,6 +17,7 @@ import { isSettingsSectionSlug, normalizeHostSectionSlug, normalizeProjectSettingsRouteId, + buildProviderSettingsRoute, parseHostAgentRouteFromPathname, parseHostWorkspaceOpenIntentFromPathname, parseHostWorkspaceRouteFromPathname, @@ -199,6 +200,14 @@ describe("projects settings routes", () => { }); }); +describe("provider settings routes", () => { + it("buildProviderSettingsRoute addresses one provider on a host", () => { + expect(buildProviderSettingsRoute("host a", "acp/gemini")).toBe( + "/settings/hosts/host%20a/providers/acp%2Fgemini", + ); + }); +}); + describe("global routes", () => { it("buildSessionsRoute returns the all-host Sessions route", () => { expect(buildSessionsRoute()).toBe("/sessions"); diff --git a/packages/app/src/utils/host-routes.ts b/packages/app/src/utils/host-routes.ts index f258c6ba5b..14db64125d 100644 --- a/packages/app/src/utils/host-routes.ts +++ b/packages/app/src/utils/host-routes.ts @@ -584,6 +584,13 @@ export function buildProjectSettingsRoute(serverId: string, projectId: string) { return `/settings/hosts/${encodeSegment(serverId)}/projects/${encodeSegment(projectId)}` as const; } +export function buildProviderSettingsRoute(serverId: string, providerId: string) { + if (!serverId.trim() || !providerId.trim()) { + throw new Error("buildProviderSettingsRoute requires a serverId and providerId"); + } + return `/settings/hosts/${encodeSegment(serverId)}/providers/${encodeSegment(providerId)}` as const; +} + export function normalizeProjectSettingsRouteId(value: string | string[] | undefined): string { const id = Array.isArray(value) ? value[0] : value; return typeof id === "string" ? id : ""; diff --git a/packages/app/test-stubs/react-native-unistyles.ts b/packages/app/test-stubs/react-native-unistyles.ts index dfd3b58d93..0b28532b82 100644 --- a/packages/app/test-stubs/react-native-unistyles.ts +++ b/packages/app/test-stubs/react-native-unistyles.ts @@ -4,7 +4,10 @@ import { lightTheme } from "../src/styles/theme"; const pinnedTheme = { colorScheme: "light", + // The light theme's colours, so a `withUnistyles` mapping finds every key it reads, with the + // values below pinned so a test can name the colour it expects. colors: { + ...lightTheme.colors, syntax: lightHighlightColors, foreground: "#111111", foregroundMuted: "#666666", @@ -157,12 +160,16 @@ export const StyleSheet = { type UniPropsMapping = (theme: typeof testTheme, runtime: object) => Record; -/** Applies `uniProps` with the test theme, the way Unistyles maps theme values onto props. */ -export const withUnistyles = (Component: T): T => { +/** + * Applies the theme mapping and `uniProps` with the test theme, the way Unistyles maps theme values + * onto props: mapped props first, then `uniProps`, then the props the caller passed. + */ +export const withUnistyles = (Component: T, mapping?: UniPropsMapping): T => { function ThemedComponent({ uniProps, ...props }: { uniProps?: UniPropsMapping }) { // Explicit props win over mapped ones, as in Unistyles' `deepMergeObjects(mappings, uniProps, props)`. return createElement(Component as ElementType, { - ...(uniProps ? uniProps(testTheme, {}) : {}), + ...mapping?.(testTheme, {}), + ...uniProps?.(testTheme, {}), ...props, }); } diff --git a/public-docs/cli.md b/public-docs/cli.md index 700206e5a5..99e4d4c32a 100644 --- a/public-docs/cli.md +++ b/public-docs/cli.md @@ -99,7 +99,7 @@ paseo provider diagnostic codex --json paseo --host devbox:6767 provider diagnostic opencode ``` -The diagnostic includes the configured command, daemon `PATH` and shell, matching binaries, resolved path, version, model count, and provider status. Use the global `--host` option for a remote daemon. This is the same diagnostic shown under **Settings → your host → Providers → provider → Diagnostic**. +The diagnostic includes the configured command, daemon `PATH` and shell, matching binaries, resolved path, version, model count, and provider status. Use the global `--host` option for a remote daemon. This is the same diagnostic shown under **Settings → your host → Providers → provider → Diagnostic report**. ## Running agents diff --git a/public-docs/cli.zh-CN.md b/public-docs/cli.zh-CN.md index 29b8aec65f..a60c13ed88 100644 --- a/public-docs/cli.zh-CN.md +++ b/public-docs/cli.zh-CN.md @@ -96,7 +96,7 @@ paseo provider diagnostic codex --json paseo --host devbox:6767 provider diagnostic opencode ``` -诊断信息包括配置的命令、daemon 的 `PATH` 和 shell、匹配到的二进制文件、解析出的路径、版本、模型数量和 Provider 状态。对于远程 daemon,请使用全局的 `--host` 选项。这与 **设置 → 你的主机 → Providers → 对应 Provider → 诊断** 下显示的诊断相同。 +诊断信息包括配置的命令、daemon 的 `PATH` 和 shell、匹配到的二进制文件、解析出的路径、版本、模型数量和 Provider 状态。对于远程 daemon,请使用全局的 `--host` 选项。这与 **设置 → 你的主机 → Providers → 对应 Provider → 诊断报告** 下显示的诊断相同。 ## 运行 Agent {#running-agents} diff --git a/public-docs/plugins/reference.md b/public-docs/plugins/reference.md index 265b80b4bb..0a6d56b563 100644 --- a/public-docs/plugins/reference.md +++ b/public-docs/plugins/reference.md @@ -460,7 +460,7 @@ interface ProviderInstallation { | Member | Called | Deadline | Answer kept | | ----------------- | ------------------------------------------------------------ | -------- | ------------------------------------------------ | -| `inspect` | When provider settings open | 20 s | 30 s | +| `inspect` | When the provider list or a provider's page shows | 20 s | 30 s | | `checkForUpdates` | After `inspect` answers `installed`, or without `inspect` | 25 s | 1 hour for `current` or `available`, else 30 s | | `update` | When the user selects **Update**, one at a time per provider | None | Paseo reads both answers again after `succeeded` | diff --git a/public-docs/supported-providers/fx.md b/public-docs/supported-providers/fx.md index e86372a4cc..0b9cd24b6f 100644 --- a/public-docs/supported-providers/fx.md +++ b/public-docs/supported-providers/fx.md @@ -14,7 +14,7 @@ Run fx, the coding agent from Vercel Labs, in Paseo with your existing fx instal 1. [Install fx](https://fx.sh/docs/getting-started/installation) on your daemon host. 2. [Connect fx to a model provider](https://fx.sh/docs/getting-started/authentication), for example with `fx login`. -3. In Paseo, open **Settings → Hosts → your host → Providers**, find **fx** in the catalog, and choose **Add**. +3. In Paseo, open **Settings → Hosts → your host → Providers**, select **+ Provider**, find **fx**, and choose **Add**. Paseo launches `fx acp` and uses your fx credentials and settings. Until fx has credentials, the provider reports the sign-in message from fx. diff --git a/public-docs/supported-providers/fx.zh-CN.md b/public-docs/supported-providers/fx.zh-CN.md index d0fcc799c6..e01edd6f22 100644 --- a/public-docs/supported-providers/fx.zh-CN.md +++ b/public-docs/supported-providers/fx.zh-CN.md @@ -12,7 +12,7 @@ nav: fx 1. 在 daemon 主机上[安装 fx](https://fx.sh/docs/getting-started/installation)。 2. [为 fx 连接一个模型提供方](https://fx.sh/docs/getting-started/authentication),例如运行 `fx login`。 -3. 在 Paseo 中打开 **设置 → Hosts → 你的主机 → Providers**,在目录里找到 **fx** 并选择 **添加**。 +3. 在 Paseo 中打开 **设置 → Hosts → 你的主机 → Providers**,选择 **+ Provider**,找到 **fx** 并选择 **添加**。 Paseo 会启动 `fx acp`,并使用你的 fx 凭据和设置。在 fx 拿到凭据之前,该 Provider 会显示 fx 给出的登录提示。 diff --git a/public-docs/supported-providers/hoplite.md b/public-docs/supported-providers/hoplite.md index 87dd98302a..130d591a9a 100644 --- a/public-docs/supported-providers/hoplite.md +++ b/public-docs/supported-providers/hoplite.md @@ -14,7 +14,7 @@ Run Hoplite's cloud coding agent in Paseo through the Hoplite CLI on your daemon 1. Install the [Hoplite CLI](https://hoplite.sh/docs/cli) on your daemon host. 2. Run `hoplite login`. -3. In Paseo, open **Settings → Hosts → your host → Providers**, find **Hoplite** in the catalog, and choose **Add**. +3. In Paseo, open **Settings → Hosts → your host → Providers**, select **+ Provider**, find **Hoplite**, and choose **Add**. Paseo launches `hoplite acp`. See [Hoplite's ACP guide](https://hoplite.sh/docs/cli/acp) for authentication and project setup. diff --git a/public-docs/supported-providers/hoplite.zh-CN.md b/public-docs/supported-providers/hoplite.zh-CN.md index 8a4627816a..9449a1343f 100644 --- a/public-docs/supported-providers/hoplite.zh-CN.md +++ b/public-docs/supported-providers/hoplite.zh-CN.md @@ -12,7 +12,7 @@ nav: Hoplite 1. 在 daemon 主机上安装 [Hoplite CLI](https://hoplite.sh/docs/cli)。 2. 运行 `hoplite login`。 -3. 在 Paseo 中打开 **设置 → Hosts → 你的主机 → Providers**,在目录里找到 **Hoplite** 并选择 **添加**。 +3. 在 Paseo 中打开 **设置 → Hosts → 你的主机 → Providers**,选择 **+ Provider**,找到 **Hoplite** 并选择 **添加**。 Paseo 会启动 `hoplite acp`。认证和项目设置见 [Hoplite 的 ACP 指南](https://hoplite.sh/docs/cli/acp)。 diff --git a/public-docs/supported-providers/index.md b/public-docs/supported-providers/index.md index 120836ebc3..2c52cc35ac 100644 --- a/public-docs/supported-providers/index.md +++ b/public-docs/supported-providers/index.md @@ -29,7 +29,7 @@ Paseo ships an integration for each of these agents. Paseo runs any agent that speaks the [Agent Client Protocol](https://agentclientprotocol.com) (ACP). The in-app catalog lists the agents below. -To add one, open **Settings → Hosts → your host → Providers**, find the agent in the catalog, and choose **Add**. Entries that launch through `npx` or `uvx` need only that tool on your daemon host. For the other entries, install the CLI of the agent first. Each entry links to its install instructions. +To add one, open **Settings → Hosts → your host → Providers**, select **+ Provider**, find the agent, and choose **Add**. Entries that launch through `npx` or `uvx` need only that tool on your daemon host. For the other entries, install the CLI of the agent first. If the CLI is missing, the page of the provider says **Not installed**, and **Install** opens its install instructions. - [Agoragentic](https://agoragentic.com), agent marketplace with 174+ AI capabilities. - [Amp](https://github.com/tao12345666333/amp-acp), frontier coding agent. diff --git a/public-docs/supported-providers/index.zh-CN.md b/public-docs/supported-providers/index.zh-CN.md index 9fecf4f30c..b81b815a2b 100644 --- a/public-docs/supported-providers/index.zh-CN.md +++ b/public-docs/supported-providers/index.zh-CN.md @@ -27,7 +27,7 @@ Paseo 为以下每个 Agent 都提供了集成。 Paseo 可以运行任何使用 [Agent Client Protocol](https://agentclientprotocol.com)(ACP)的 Agent。应用内目录列出了以下 Agent。 -要添加其中一个,请打开 **设置 → Hosts → 你的主机 → Providers**,在目录里找到该 Agent 并选择 **添加**。通过 `npx` 或 `uvx` 启动的条目只需要 daemon 主机上有该工具。其他条目请先安装该 Agent 的 CLI。每个条目都附有安装说明的链接。 +要添加其中一个,请打开 **设置 → Hosts → 你的主机 → Providers**,选择 **+ Provider**,找到该 Agent 并选择 **添加**。通过 `npx` 或 `uvx` 启动的条目只需要 daemon 主机上有该工具。其他条目请先安装该 Agent 的 CLI。如果缺少 CLI,该 provider 的页面会显示 **未安装**,**安装** 会打开它的安装说明。 - [Agoragentic](https://agoragentic.com):拥有 174 种以上 AI 能力的 Agent 市场。 - [Amp](https://github.com/tao12345666333/amp-acp):前沿的编程 Agent。 diff --git a/public-docs/troubleshooting.md b/public-docs/troubleshooting.md index 420c3363aa..9b4e23464c 100644 --- a/public-docs/troubleshooting.md +++ b/public-docs/troubleshooting.md @@ -33,7 +33,7 @@ Paseo launches the agent CLIs you've already installed, it doesn't bundle them ( ### See what Paseo sees -Open **Settings → your host → Providers**, tap the provider, then tap **Diagnostic**. The rows that matter: +Open **Settings → your host → Providers**, tap the provider, then tap **Diagnostic report**. The rows that matter: - **Resolved path** — where Paseo found the binary, or `not found`. - **Daemon PATH** — the `PATH` Paseo is searching. Compare it to `echo $PATH` in a fresh terminal. diff --git a/public-docs/troubleshooting.zh-CN.md b/public-docs/troubleshooting.zh-CN.md index 739ce46479..0055b53696 100644 --- a/public-docs/troubleshooting.zh-CN.md +++ b/public-docs/troubleshooting.zh-CN.md @@ -31,7 +31,7 @@ Paseo 启动的是你已经安装的 Agent CLI,它并不自带这些 CLI(参 ### 查看 Paseo 看到的内容 {#see-what-paseo-sees} -打开 **设置 → 你的主机 → Providers**,点击该 Provider,然后点击 **诊断**。重要的几行: +打开 **设置 → 你的主机 → Providers**,点击该 Provider,然后点击 **诊断报告**。重要的几行: - **Resolved path**:Paseo 找到二进制文件的位置,或 `not found`。 - **Daemon PATH**:Paseo 正在搜索的 `PATH`。把它和新终端中 `echo $PATH` 的结果进行比较。