diff --git a/webui/src/components/settings/channels/ChannelCatalogRow.tsx b/webui/src/components/settings/channels/ChannelCatalogRow.tsx new file mode 100644 index 000000000..2269f2a07 --- /dev/null +++ b/webui/src/components/settings/channels/ChannelCatalogRow.tsx @@ -0,0 +1,128 @@ +import { useEffect, useRef, useState } from "react"; +import { Download, Loader2 } from "lucide-react"; +import { useTranslation } from "react-i18next"; + +import type { ChannelFeatureAction } from "@/channel-plugins/types"; +import { ToggleButton } from "@/components/settings/ToggleButton"; +import { + ChannelLogo, + ChannelStatusBadge, + channelStatusLabel, + channelToggleChecked, + localizedChannelDisplayName, +} from "@/components/settings/channels/ChannelIdentity"; +import { Button } from "@/components/ui/button"; +import type { NanobotFeatureInfo } from "@/lib/types"; +import { cn } from "@/lib/utils"; + +export function ChannelCatalogRow({ + feature, + showBrandLogos, + onSelect, + actionKey, + actionsDisabled = false, + onAction, +}: { + feature: NanobotFeatureInfo; + showBrandLogos: boolean; + onSelect: (connect?: boolean) => void; + actionKey: string | null; + actionsDisabled?: boolean; + onAction: ChannelFeatureAction; +}) { + const { t } = useTranslation(); + const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); + const displayName = localizedChannelDisplayName(feature, t); + const alwaysEnabled = feature.capabilities?.includes("always_enabled") ?? false; + const pendingChecked = actionKey === `enable:${feature.name}` ? true + : actionKey === `disable:${feature.name}` ? false : null; + const ownActionBusy = pendingChecked !== null || actionKey === `install:${feature.name}`; + const checked = alwaysEnabled || (pendingChecked ?? channelToggleChecked(feature)); + const anyActionBusy = Boolean(actionKey); + const installButtonRef = useRef(null); + const [installHint, setInstallHint] = useState(false); + + useEffect(() => { + if (!installHint) return; + const timeout = window.setTimeout(() => setInstallHint(false), 1400); + return () => window.clearTimeout(timeout); + }, [installHint]); + + const pointToInstall = () => { + setInstallHint(true); + installButtonRef.current?.focus(); + }; + const channelIdentity = ( + <> + +
+

+ {displayName} +

+
+ + ); + + return ( +
+ {alwaysEnabled ? ( +
+ {channelIdentity} +
+ ) : ( + + )} + {feature.runtime_status === "failed" ? ( +
+ + {channelStatusLabel(feature, tx)} + +
+ ) : null} +
+ {!feature.installed ? ( + + ) : ( + { + if (enabled && feature.configured === false) onSelect(true); + else onAction(enabled ? "enable" : "disable", feature.name); + }} /> + )} +
+
+ ); +} diff --git a/webui/src/components/settings/channels/ChannelCredentialFields.tsx b/webui/src/components/settings/channels/ChannelCredentialFields.tsx new file mode 100644 index 000000000..89e5e2b28 --- /dev/null +++ b/webui/src/components/settings/channels/ChannelCredentialFields.tsx @@ -0,0 +1,169 @@ +import { useTranslation } from "react-i18next"; + +import type { + ChannelConfigField, + ChannelFieldSection, + ChannelSetupRequirement, +} from "@/components/settings/channels/catalog"; +import { + CredentialForm, + channelFieldInputId, + type CredentialFormProps, +} from "@/components/settings/channels/CredentialForm"; + +const CHANNEL_FIELD_SECTION_ORDER: ChannelFieldSection[] = [ + "account", + "credentials", + "connection", + "access", + "behavior", + "security", +]; + +type ChannelFieldGroupsProps = Omit & { + fields: ChannelConfigField[]; + requirements: ChannelSetupRequirement[]; + sectionLabels?: Record; +}; + +export function ChannelFieldGroups({ + fields, + requirements, + sectionLabels, + ...formProps +}: ChannelFieldGroupsProps) { + const { t } = useTranslation(); + const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); + const labels = new Map(fields.map((field) => [field.key, field.label])); + const compositeRequirements = requirements.filter( + (requirement) => requirement.alternatives.length > 1, + ); + const groups = new Map(); + for (const field of fields) { + const section = field.section ?? "credentials"; + const current = groups.get(section) ?? []; + current.push(field); + groups.set(section, current); + } + const orderedSections = [ + ...CHANNEL_FIELD_SECTION_ORDER, + ...[...groups.keys()].filter( + (section) => !CHANNEL_FIELD_SECTION_ORDER.includes(section as ChannelFieldSection), + ), + ]; + + return ( +
+ {compositeRequirements.map((requirement, index) => ( +
+
+ {tx("settings.channels.chooseCredentialMethod", "Choose one credential method")} +
+
+ {requirement.alternatives.map((alternative, alternativeIndex) => ( + + {alternativeIndex ? {tx("settings.channels.or", "or")} : null} + + {alternative.map((key) => labels.get(key) ?? key.split(".").at(-1)).join(" + ")} + + + ))} +
+
+ ))} + {orderedSections.map((section) => { + const sectionFields = groups.get(section); + if (!sectionFields?.length) return null; + return ( +
+ + {channelFieldSectionLabel(section, tx, sectionLabels)} + +
+ +
+
+ ); + })} +
+ ); +} + +function channelFieldSectionLabel( + section: string, + tx: (key: string, fallback: string) => string, + sectionLabels?: Record, +): string { + const customLabel = sectionLabels?.[section]; + if (customLabel) return customLabel; + + const fallbacks: Record = { + account: "Account", + credentials: "Credentials", + connection: "Connection", + access: "Access", + behavior: "Behavior", + security: "Security", + advanced: "Advanced", + }; + const fallback = fallbacks[section as ChannelFieldSection]; + if (fallback) return tx(`settings.channels.sections.${section}`, fallback); + return section + .replace(/([a-z0-9])([A-Z])/g, "$1 $2") + .replace(/[_-]+/g, " ") + .replace(/\b\w/g, (letter) => letter.toUpperCase()); +} + +export function channelRequirementErrors( + fields: ChannelConfigField[], + requirements: ChannelSetupRequirement[], + values: Record, + configuredFields: Set, + clearedSecrets: Set, + message: string, +): Record { + const fieldByKey = new Map(fields.map((field) => [field.key, field])); + const present = (key: string) => { + const field = fieldByKey.get(key); + if (!field || clearedSecrets.has(key)) return false; + const value = (values[key] ?? "").trim(); + if (field.kind === "bool") return value === "true"; + if (value) return true; + return Boolean(field.secret && configuredFields.has(key)); + }; + const errors: Record = {}; + for (const requirement of requirements) { + if (requirement.alternatives.some((alternative) => alternative.every(present))) continue; + const closest = [...requirement.alternatives].sort( + (left, right) => left.filter((key) => !present(key)).length - right.filter((key) => !present(key)).length, + )[0] ?? []; + for (const key of closest) { + if (!present(key) && fieldByKey.has(key)) errors[key] = message; + } + } + return errors; +} + +export function channelServerValidationErrors( + fields: ChannelConfigField[], + missingFields: string[], + message: string, +): Record { + const missing = new Set(missingFields); + return Object.fromEntries( + fields + .filter((field) => missing.has(field.key) || missing.has(field.key.split(".").at(-1) ?? "")) + .map((field) => [field.key, message]), + ); +} + +export function focusFirstChannelFieldError(errors: Record) { + const key = Object.keys(errors)[0]; + if (!key) return; + window.requestAnimationFrame(() => { + document.getElementById(channelFieldInputId(key))?.focus(); + }); +} diff --git a/webui/src/components/settings/channels/ChannelInstancesPanel.tsx b/webui/src/components/settings/channels/ChannelInstancesPanel.tsx index ece8fd078..186eda421 100644 --- a/webui/src/components/settings/channels/ChannelInstancesPanel.tsx +++ b/webui/src/components/settings/channels/ChannelInstancesPanel.tsx @@ -7,11 +7,13 @@ import { ToggleButton } from "@/components/settings/ToggleButton"; import type { ChannelConfigField } from "@/components/settings/channels/catalog"; import { CredentialForm, - channelValidationStatusClass, - channelValidationStatusIcon, channelValuesForSave, defaultChannelFieldValues, } from "@/components/settings/channels/CredentialForm"; +import { + channelValidationStatusClass, + channelValidationStatusIcon, +} from "@/components/settings/channels/ChannelValidationProgress"; import { CHANNEL_SETUP_PANEL_CLASS_NAME, ChannelLogo, diff --git a/webui/src/components/settings/channels/ChannelSetupPanel.tsx b/webui/src/components/settings/channels/ChannelSetupPanel.tsx index 92d6c65be..3df4af53e 100644 --- a/webui/src/components/settings/channels/ChannelSetupPanel.tsx +++ b/webui/src/components/settings/channels/ChannelSetupPanel.tsx @@ -14,7 +14,6 @@ import { Check, ChevronDown, Clipboard, - Download, Loader2, Plus, } from "lucide-react"; @@ -28,12 +27,15 @@ import type { import { ToggleButton } from "@/components/settings/ToggleButton"; import { useAutoSave } from "@/components/settings/shared/useAutoSave"; import { - type ChannelConfigField, - type ChannelFieldSection, type ChannelProviderPreset, type ChannelSetupPresentation, - type ChannelSetupRequirement, } from "@/components/settings/channels/catalog"; +import { + ChannelFieldGroups, + channelRequirementErrors, + channelServerValidationErrors, + focusFirstChannelFieldError, +} from "@/components/settings/channels/ChannelCredentialFields"; import { CredentialForm, channelValuesForSubmit, @@ -43,17 +45,15 @@ import { ChannelLogo, ChannelRuntimeError, CHANNEL_SETUP_PANEL_CLASS_NAME, - ChannelStatusBadge, channelSetup, - channelStatusLabel, channelToggleChecked, localizedChannelDisplayName, } from "@/components/settings/channels/ChannelIdentity"; import { ChannelProviderPresets, ChannelSetupActions, - ChannelValidationProgress, } from "@/components/settings/channels/ChannelSetupParts"; +import { ChannelValidationProgress } from "@/components/settings/channels/ChannelValidationProgress"; import { ChannelInstancesPanel } from "@/components/settings/channels/ChannelInstancesPanel"; import { Button } from "@/components/ui/button"; import { @@ -70,118 +70,6 @@ import type { import { cn } from "@/lib/utils"; import { useClient } from "@/providers/ClientProvider"; -export function ChannelCatalogRow({ - feature, - showBrandLogos, - onSelect, - actionKey, - actionsDisabled = false, - onAction, -}: { - feature: NanobotFeatureInfo; - showBrandLogos: boolean; - onSelect: (connect?: boolean) => void; - actionKey: string | null; - actionsDisabled?: boolean; - onAction: ChannelFeatureAction; -}) { - const { t } = useTranslation(); - const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); - const displayName = localizedChannelDisplayName(feature, t); - const alwaysEnabled = feature.capabilities?.includes("always_enabled") ?? false; - const pendingChecked = actionKey === `enable:${feature.name}` ? true - : actionKey === `disable:${feature.name}` ? false : null; - const ownActionBusy = pendingChecked !== null || actionKey === `install:${feature.name}`; - const checked = alwaysEnabled || (pendingChecked ?? channelToggleChecked(feature)); - const anyActionBusy = Boolean(actionKey); - const installButtonRef = useRef(null); - const [installHint, setInstallHint] = useState(false); - - useEffect(() => { - if (!installHint) return; - const timeout = window.setTimeout(() => setInstallHint(false), 1400); - return () => window.clearTimeout(timeout); - }, [installHint]); - - const pointToInstall = () => { - setInstallHint(true); - installButtonRef.current?.focus(); - }; - const channelIdentity = ( - <> - -
-

- {displayName} -

-
- - ); - - return ( -
- {alwaysEnabled ? ( -
- {channelIdentity} -
- ) : ( - - )} - {feature.runtime_status === "failed" ? ( -
- - {channelStatusLabel(feature, tx)} - -
- ) : null} -
- {!feature.installed ? ( - - ) : ( - { - if (enabled && feature.configured === false) onSelect(true); - else onAction(enabled ? "enable" : "disable", feature.name); - }} /> - )} -
-
- ); -} - export function ChannelSetupPanel({ token, feature, @@ -272,7 +160,7 @@ export function ChannelSetupPanel({ feature={feature} setup={setup} connectRequestId={connectRequestId} - ConnectFlow={feature.installed ? uiContribution?.ConnectFlow : undefined} + ConnectFlow={uiContribution?.ConnectFlow} onFeaturesUpdate={onFeaturesUpdate} onBeforeCloseChange={onBeforeCloseChange} />} @@ -324,6 +212,10 @@ function ChannelSetupSurface({ ); const mode = setup.mode ?? "credentials"; const fields = setup.fields ?? []; + const secretFieldKeys = useMemo( + () => new Set(fields.filter((field) => field.secret).map((field) => field.key)), + [fields], + ); const requirementKeys = new Set( (setup.requirements ?? []).flatMap((requirement) => requirement.alternatives.flat()), ); @@ -466,6 +358,9 @@ function ChannelSetupSurface({ touchedFields, validating, ]); + const saveSecretOnBlur = (key: string) => { + if (secretFieldKeys.has(key)) void saveCredentialDraft(); + }; useAutoSave( { fieldValues, touchedFields: [...touchedFields], clearedSecrets: [...clearedSecrets] }, @@ -694,7 +589,7 @@ function ChannelSetupSurface({ - {mode === "connect" && !feature.installed ? null : mode === "connect" && ConnectFlow ? ( + {mode === "connect" && ConnectFlow ? ( }> { - if (fields.some((field) => field.key === key && field.secret)) { - void saveCredentialDraft(); - } - }} + onFieldBlur={saveSecretOnBlur} onToggleSecret={toggleSecret} errors={fieldErrors} clearedSecrets={clearedSecrets} @@ -800,11 +691,7 @@ function ChannelSetupSurface({ configuredFields={configuredFields} visibleSecrets={visibleSecrets} onChange={setFieldValue} - onFieldBlur={(key) => { - if (fields.some((field) => field.key === key && field.secret)) { - void saveCredentialDraft(); - } - }} + onFieldBlur={saveSecretOnBlur} onToggleSecret={toggleSecret} errors={fieldErrors} clearedSecrets={clearedSecrets} @@ -842,171 +729,6 @@ function ChannelSetupSurface({ ); } -const CHANNEL_FIELD_SECTION_ORDER: ChannelFieldSection[] = [ - "account", - "credentials", - "connection", - "access", - "behavior", - "security", -]; - -function ChannelFieldGroups({ - fields, - requirements, - sectionLabels, - ...formProps -}: { - fields: ChannelConfigField[]; - requirements: ChannelSetupRequirement[]; - sectionLabels?: Record; - values: Record; - configuredFields: Set; - visibleSecrets: Record; - onChange: (key: string, value: string) => void; - onFieldBlur?: (key: string) => void; - onToggleSecret: (key: string) => void; - errors: Record; - clearedSecrets: Set; - onClearSecret: (key: string, clear: boolean) => void; - disabled?: boolean; -}) { - const { t } = useTranslation(); - const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); - const labels = new Map(fields.map((field) => [field.key, field.label])); - const compositeRequirements = requirements.filter( - (requirement) => requirement.alternatives.length > 1, - ); - const groups = new Map(); - for (const field of fields) { - const section = field.section ?? "credentials"; - const current = groups.get(section) ?? []; - current.push(field); - groups.set(section, current); - } - const orderedSections = [ - ...CHANNEL_FIELD_SECTION_ORDER, - ...[...groups.keys()].filter( - (section) => !CHANNEL_FIELD_SECTION_ORDER.includes(section as ChannelFieldSection), - ), - ]; - - return ( -
- {compositeRequirements.map((requirement, index) => ( -
-
- {tx("settings.channels.chooseCredentialMethod", "Choose one credential method")} -
-
- {requirement.alternatives.map((alternative, alternativeIndex) => ( - - {alternativeIndex ? {tx("settings.channels.or", "or")} : null} - - {alternative.map((key) => labels.get(key) ?? key.split(".").at(-1)).join(" + ")} - - - ))} -
-
- ))} - {orderedSections.map((section) => { - const sectionFields = groups.get(section); - if (!sectionFields?.length) return null; - return ( -
- - {channelFieldSectionLabel(section, tx, sectionLabels)} - -
- -
-
- ); - })} -
- ); -} - -function channelFieldSectionLabel( - section: string, - tx: (key: string, fallback: string) => string, - sectionLabels?: Record, -): string { - const customLabel = sectionLabels?.[section]; - if (customLabel) return customLabel; - - const fallbacks: Record = { - account: "Account", - credentials: "Credentials", - connection: "Connection", - access: "Access", - behavior: "Behavior", - security: "Security", - advanced: "Advanced", - }; - const fallback = fallbacks[section as ChannelFieldSection]; - if (fallback) return tx(`settings.channels.sections.${section}`, fallback); - return section - .replace(/([a-z0-9])([A-Z])/g, "$1 $2") - .replace(/[_-]+/g, " ") - .replace(/\b\w/g, (letter) => letter.toUpperCase()); -} - -function channelRequirementErrors( - fields: ChannelConfigField[], - requirements: ChannelSetupRequirement[], - values: Record, - configuredFields: Set, - clearedSecrets: Set, - message: string, -): Record { - const fieldByKey = new Map(fields.map((field) => [field.key, field])); - const present = (key: string) => { - const field = fieldByKey.get(key); - if (!field || clearedSecrets.has(key)) return false; - const value = (values[key] ?? "").trim(); - if (field.kind === "bool") return value === "true"; - if (value) return true; - return Boolean(field.secret && configuredFields.has(key)); - }; - const errors: Record = {}; - for (const requirement of requirements) { - if (requirement.alternatives.some((alternative) => alternative.every(present))) continue; - const closest = [...requirement.alternatives].sort( - (left, right) => left.filter((key) => !present(key)).length - right.filter((key) => !present(key)).length, - )[0] ?? []; - for (const key of closest) { - if (!present(key) && fieldByKey.has(key)) errors[key] = message; - } - } - return errors; -} - -function channelServerValidationErrors( - fields: ChannelConfigField[], - missingFields: string[], - message: string, -): Record { - const missing = new Set(missingFields); - return Object.fromEntries( - fields - .filter((field) => missing.has(field.key) || missing.has(field.key.split(".").at(-1) ?? "")) - .map((field) => [field.key, message]), - ); -} - -function focusFirstChannelFieldError(errors: Record) { - const key = Object.keys(errors)[0]; - if (!key) return; - window.requestAnimationFrame(() => { - document.getElementById(`channel-field-${key.replace(/[^a-zA-Z0-9_-]/g, "-")}`)?.focus(); - }); -} - function ChannelPluginLoading({ compact = false }: { compact?: boolean }) { const { t } = useTranslation(); return ( diff --git a/webui/src/components/settings/channels/ChannelSetupParts.tsx b/webui/src/components/settings/channels/ChannelSetupParts.tsx index b3d27928b..09123f46b 100644 --- a/webui/src/components/settings/channels/ChannelSetupParts.tsx +++ b/webui/src/components/settings/channels/ChannelSetupParts.tsx @@ -1,6 +1,4 @@ -import { channelValidationMessage } from "./validationMessages"; -import { useEffect, useMemo, useState } from "react"; -import { Clipboard, ExternalLink, Loader2 } from "lucide-react"; +import { Clipboard } from "lucide-react"; import { useTranslation } from "react-i18next"; import { channelUiPresentation } from "@/channel-plugins/registry"; @@ -9,19 +7,8 @@ import { type ChannelProviderPreset, type ChannelSetupPresentation, } from "@/components/settings/channels/catalog"; -import { - channelValidationCheckIcon, - channelValidationCheckIconClass, - channelValidationStatusClass, - channelValidationStatusIcon, - channelValidationStatusLabel, -} from "@/components/settings/channels/CredentialForm"; import { copyTextToClipboard } from "@/lib/clipboard"; -import type { - ChannelValidationPayload, - NanobotFeatureInfo, -} from "@/lib/types"; -import { cn } from "@/lib/utils"; +import type { NanobotFeatureInfo } from "@/lib/types"; export function ChannelSetupActions({ feature, @@ -71,7 +58,6 @@ export function ChannelSetupActions({ ); } - export function ChannelProviderPresets({ presets, onApply, @@ -108,126 +94,3 @@ export function ChannelProviderPresets({ ); } - -function visibleValidationChecks(validation: ChannelValidationPayload | null) { - return (validation?.checks ?? []).filter( - (check) => check.id !== "manual_review" - && !(check.id.startsWith("field:") && check.status === "pass"), - ).slice(0, 6); -} - -export function ChannelValidationProgress({ - validation, - validating, - feature, -}: { - validation: ChannelValidationPayload | null; - validating: boolean; - feature: NanobotFeatureInfo; -}) { - const { t } = useTranslation(); - const checks = useMemo(() => visibleValidationChecks(validation), [validation]); - const [reveal, setReveal] = useState<{ - validation: ChannelValidationPayload | null; - settledCheckCount: number; - }>({ validation: null, settledCheckCount: 0 }); - const settledCheckCount = reveal.validation === validation ? reveal.settledCheckCount : 0; - - useEffect(() => { - if (validating || !validation) { - setReveal({ validation: null, settledCheckCount: 0 }); - return; - } - setReveal({ validation, settledCheckCount: 0 }); - const timers = checks.map((_, index) => window.setTimeout( - () => setReveal((current) => ( - current.validation === validation - ? { validation, settledCheckCount: index + 1 } - : current - )), - (index + 1) * 260, - )); - return () => timers.forEach((timer) => window.clearTimeout(timer)); - }, [checks, validating, validation]); - - if (!validating && !validation) return null; - - const finished = Boolean(validation) && !validating && settledCheckCount >= checks.length; - const shownChecks = finished ? checks : checks.slice(0, settledCheckCount + 1); - const status = validation?.status ?? (feature.configured ? "configured" : "needs_setup"); - const presentation = channelUiPresentation(feature.name, feature.webui); - const identity = validation?.identity?.name - ? validation.identity.workspace - ? `${validation.identity.name} · ${validation.identity.workspace}` - : validation.identity.name - : presentation?.displayName ?? feature.display_name; - - return ( -
-
- {validating ? ( -
- - {t("settings.channels.checking", { defaultValue: "Checking..." })} -
- ) : null} - {!validating ? shownChecks.map((check, index) => { - const pending = !finished && index === settledCheckCount; - return ( -
- - {pending - ? - : channelValidationCheckIcon(check.status)} - -
-
- {channelValidationMessage(check.label, t)} - {!pending && check.action_url ? ( - - {t("settings.channels.open")} - - - ) : null} -
- {!pending && check.status !== "pass" && check.message ? ( -
- {channelValidationMessage(check.message, t)} -
- ) : null} -
-
- ); - }) : null} - {finished ? ( -
- {channelValidationStatusIcon(status)} - {identity} - {channelValidationStatusLabel(status, t)} -
- ) : null} -
-
- ); -} diff --git a/webui/src/components/settings/channels/ChannelValidationProgress.tsx b/webui/src/components/settings/channels/ChannelValidationProgress.tsx new file mode 100644 index 000000000..b81a2f168 --- /dev/null +++ b/webui/src/components/settings/channels/ChannelValidationProgress.tsx @@ -0,0 +1,183 @@ +import { useEffect, useMemo, useState, type ReactNode } from "react"; +import { Check, CircleAlert, ExternalLink, Loader2, X } from "lucide-react"; +import { useTranslation } from "react-i18next"; + +import { channelUiPresentation } from "@/channel-plugins/registry"; +import { channelValidationMessage } from "@/components/settings/channels/validationMessages"; +import type { ChannelValidationPayload, NanobotFeatureInfo } from "@/lib/types"; +import { cn } from "@/lib/utils"; + +export function channelValidationStatusLabel( + status: string, + t: ReturnType["t"], +): string { + const labels: Record = { + connected: "Connected", + configured: "Not verified", + needs_setup: "Needs setup", + invalid: "Invalid", + unsupported: "Manual setup", + }; + return t(`settings.channels.validation.${status}`, { + defaultValue: labels[status] ?? "Checked", + }); +} + +export function channelValidationStatusClass(status: string): string { + if (status === "connected") { + return "bg-emerald-500/10 text-emerald-700 dark:text-emerald-200"; + } + if (status === "configured") { + return "bg-blue-500/10 text-blue-700 dark:text-blue-200"; + } + if (status === "invalid") { + return "bg-destructive/10 text-destructive"; + } + return "bg-muted text-muted-foreground"; +} + +export function channelValidationStatusIcon(status: string): ReactNode { + if (status === "connected") { + return ; + } + if (status === "invalid") { + return ; + } + return ; +} + +function channelValidationCheckIcon(status: string): ReactNode { + if (status === "pass") return ; + if (status === "fail") return ; + return ; +} + +function channelValidationCheckIconClass(status: string): string { + if (status === "pass") return "text-emerald-600"; + if (status === "fail") return "text-destructive"; + if (status === "warn") return "text-amber-600"; + return "text-muted-foreground"; +} + +function visibleValidationChecks(validation: ChannelValidationPayload | null) { + return (validation?.checks ?? []).filter( + (check) => check.id !== "manual_review" + && !(check.id.startsWith("field:") && check.status === "pass"), + ).slice(0, 6); +} + +export function ChannelValidationProgress({ + validation, + validating, + feature, +}: { + validation: ChannelValidationPayload | null; + validating: boolean; + feature: NanobotFeatureInfo; +}) { + const { t } = useTranslation(); + const checks = useMemo(() => visibleValidationChecks(validation), [validation]); + const [reveal, setReveal] = useState<{ + validation: ChannelValidationPayload | null; + settledCheckCount: number; + }>({ validation: null, settledCheckCount: 0 }); + const settledCheckCount = reveal.validation === validation ? reveal.settledCheckCount : 0; + + useEffect(() => { + if (validating || !validation) { + setReveal({ validation: null, settledCheckCount: 0 }); + return; + } + setReveal({ validation, settledCheckCount: 0 }); + const timers = checks.map((_, index) => window.setTimeout( + () => setReveal((current) => ( + current.validation === validation + ? { validation, settledCheckCount: index + 1 } + : current + )), + (index + 1) * 260, + )); + return () => timers.forEach((timer) => window.clearTimeout(timer)); + }, [checks, validating, validation]); + + if (!validating && !validation) return null; + + const finished = Boolean(validation) && !validating && settledCheckCount >= checks.length; + const shownChecks = finished ? checks : checks.slice(0, settledCheckCount + 1); + const status = validation?.status ?? (feature.configured ? "configured" : "needs_setup"); + const presentation = channelUiPresentation(feature.name, feature.webui); + const identity = validation?.identity?.name + ? validation.identity.workspace + ? `${validation.identity.name} · ${validation.identity.workspace}` + : validation.identity.name + : presentation?.displayName ?? feature.display_name; + + return ( +
+
+ {validating ? ( +
+ + {t("settings.channels.checking", { defaultValue: "Checking..." })} +
+ ) : null} + {!validating ? shownChecks.map((check, index) => { + const pending = !finished && index === settledCheckCount; + return ( +
+ + {pending + ? + : channelValidationCheckIcon(check.status)} + +
+
+ {channelValidationMessage(check.label, t)} + {!pending && check.action_url ? ( + + {t("settings.channels.open")} + + + ) : null} +
+ {!pending && check.status !== "pass" && check.message ? ( +
+ {channelValidationMessage(check.message, t)} +
+ ) : null} +
+
+ ); + }) : null} + {finished ? ( +
+ {channelValidationStatusIcon(status)} + {identity} + {channelValidationStatusLabel(status, t)} +
+ ) : null} +
+
+ ); +} diff --git a/webui/src/components/settings/channels/CredentialForm.tsx b/webui/src/components/settings/channels/CredentialForm.tsx index 9952b2991..d8e6a4d1b 100644 --- a/webui/src/components/settings/channels/CredentialForm.tsx +++ b/webui/src/components/settings/channels/CredentialForm.tsx @@ -1,5 +1,4 @@ -import type { ReactNode } from "react"; -import { Check, CircleAlert, Eye, EyeOff, X } from "lucide-react"; +import { Eye, EyeOff } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Input } from "@/components/ui/input"; @@ -62,58 +61,21 @@ export function channelValuesForSubmit( return payload; } -export function channelValidationStatusLabel( - status: string, - t: ReturnType["t"], -): string { - const labels: Record = { - connected: "Connected", - configured: "Not verified", - needs_setup: "Needs setup", - invalid: "Invalid", - unsupported: "Manual setup", - }; - return t(`settings.channels.validation.${status}`, { - defaultValue: labels[status] ?? "Checked", - }); -} - -export function channelValidationStatusClass(status: string): string { - if (status === "connected") { - return "bg-emerald-500/10 text-emerald-700 dark:text-emerald-200"; - } - if (status === "configured") { - return "bg-blue-500/10 text-blue-700 dark:text-blue-200"; - } - if (status === "invalid") { - return "bg-destructive/10 text-destructive"; - } - return "bg-muted text-muted-foreground"; -} - -export function channelValidationStatusIcon(status: string): ReactNode { - if (status === "connected") { - return ; - } - if (status === "invalid") { - return ; - } - return ; -} - -export function channelValidationCheckIcon(status: string): ReactNode { - if (status === "pass") return ; - if (status === "fail") return ; - if (status === "warn") return ; - return ; -} - -export function channelValidationCheckIconClass(status: string): string { - if (status === "pass") return "text-emerald-600"; - if (status === "fail") return "text-destructive"; - if (status === "warn") return "text-amber-600"; - return "text-muted-foreground"; -} +export type CredentialFormProps = { + fields: ChannelConfigField[]; + values: Record; + configuredFields?: Set; + visibleSecrets: Record; + onChange: (key: string, value: string) => void; + onFieldBlur?: (key: string) => void; + onToggleSecret: (key: string) => void; + errors?: Record; + clearedSecrets?: Set; + onClearSecret?: (key: string, clear: boolean) => void; + compact?: boolean; + showSecretActions?: boolean; + disabled?: boolean; +}; export function CredentialForm({ fields, @@ -129,21 +91,7 @@ export function CredentialForm({ compact = false, showSecretActions = false, disabled = false, -}: { - fields: ChannelConfigField[]; - values: Record; - configuredFields?: Set; - visibleSecrets: Record; - onChange: (key: string, value: string) => void; - onFieldBlur?: (key: string) => void; - onToggleSecret: (key: string) => void; - errors?: Record; - clearedSecrets?: Set; - onClearSecret?: (key: string, clear: boolean) => void; - compact?: boolean; - showSecretActions?: boolean; - disabled?: boolean; -}) { +}: CredentialFormProps) { const { t } = useTranslation(); const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); return ( diff --git a/webui/src/components/settings/system/ChannelsSettings.tsx b/webui/src/components/settings/system/ChannelsSettings.tsx index 08c0f2ab7..e809ec75a 100644 --- a/webui/src/components/settings/system/ChannelsSettings.tsx +++ b/webui/src/components/settings/system/ChannelsSettings.tsx @@ -6,9 +6,10 @@ import { Input } from "@/components/ui/input"; import { SegmentedControl } from "@/components/ui/segmented-control"; import { SETTINGS_SEARCH_INPUT_CLASS } from "@/components/settings/shared/SettingsControls"; import type { ChannelFeatureAction } from "@/channel-plugins/types"; +import { ChannelCatalogRow } from "@/components/settings/channels/ChannelCatalogRow"; import { localizedChannelDisplayName } from "@/components/settings/channels/ChannelIdentity"; import { ChannelHelpMenu } from "@/components/settings/channels/ChannelHelpMenu"; -import { ChannelCatalogRow, ChannelSetupPanel } from "@/components/settings/channels/ChannelSetupPanel"; +import { ChannelSetupPanel } from "@/components/settings/channels/ChannelSetupPanel"; import { DismissibleStatusMessage, RestartRequiredNotice, SettingsGroup } from "@/components/settings/shared/SettingsControls"; import type { NanobotFeaturesPayload } from "@/lib/types"; import { Dialog, DialogClose, DialogContent, DialogTitle } from "@/components/ui/dialog";