feat(webui): improve setup flows across chat channels (NAN-112) (#5356)
* feat(webui): improve channel setup flows * fix(webui): refine channel setup interactions (NAN-112) * fix(webui): keep email setup sections channel-owned * fix(webui): remove concrete channel details from shared components * refactor(webui): remove unused channel setup resources * fix(webui): finish channel-owned setup boundaries * fix(webui): update channel switches optimistically * test(channels): remove obsolete absence assertions * fix(webui): flatten channel instance settings disclosure * fix(webui): complete channel setup and connection flows * fix(whatsapp): wait for session database release * fix(webui): preserve scrolling channel controls * fix(webui): stage channel connection checks * fix(channels): align verification actions * fix(email): expose connection checks * fix(webui): align channel field actions * fix(email): verify account credentials * fix(wecom): bypass system proxy for websocket * fix(channels): stabilize async connection cleanup * fix(webui): autosave channel credentials * fix(email): make provider presets non-destructive * test(weixin): isolate persisted QR credentials
This commit is contained in:
1 parent
3cc3012b3a
commit
e8a29a0087
291 files changed
+12194
-3979
No files matched your search
@@ -680,12 +680,16 @@ export function SettingsPage({
|
||||
/>
|
||||
|
||||
<NanobotFeatureInstallDialog
|
||||
feature={nanobotFeatureConfirm}
|
||||
installing={nanobotFeatureAction === `enable:${nanobotFeatureConfirm?.name ?? ""}`}
|
||||
feature={nanobotFeatureConfirm?.feature ?? null}
|
||||
installOnly={nanobotFeatureConfirm?.installOnly ?? false}
|
||||
installing={nanobotFeatureAction === `${nanobotFeatureConfirm?.installOnly ? "install" : "enable"}:${nanobotFeatureConfirm?.feature.name ?? ""}`}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setNanobotFeatureConfirm(null);
|
||||
}}
|
||||
onConfirm={(feature) => handleNanobotFeatureAction("enable", feature.name, true)}
|
||||
onConfirm={(feature) => handleNanobotFeatureAction("enable", feature.name, {
|
||||
confirmed: true,
|
||||
installOnly: nanobotFeatureConfirm?.installOnly,
|
||||
})}
|
||||
/>
|
||||
|
||||
<AutomationDeleteDialog
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { CircleHelp, ExternalLink } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { channelSetup } from "@/components/settings/channels/ChannelIdentity";
|
||||
import { docsUrlWithBase } from "@/components/settings/channels/catalog";
|
||||
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { Tooltip, TooltipProvider, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
|
||||
import type { NanobotFeatureInfo } from "@/lib/types";
|
||||
|
||||
export function ChannelHelpMenu({ feature, chatAppsDocsUrl }: {
|
||||
feature: NanobotFeatureInfo;
|
||||
chatAppsDocsUrl?: string;
|
||||
}) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const setup = channelSetup(feature, i18n.resolvedLanguage ?? i18n.language);
|
||||
const links = [
|
||||
{ url: setup.officialUrl, label: setup.officialLabel },
|
||||
{ url: docsUrlWithBase(setup.docsUrl, chatAppsDocsUrl), label: setup.docsLabel },
|
||||
].filter((link) => link.url);
|
||||
if (!links.length) return null;
|
||||
const label = t("settings.channels.help", { defaultValue: "Help" });
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<DropdownMenu>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button type="button" aria-label={label}
|
||||
className="grid h-8 w-8 place-items-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring">
|
||||
<CircleHelp className="h-4 w-4" aria-hidden />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{label}</TooltipContent>
|
||||
</Tooltip>
|
||||
<DropdownMenuContent align="end">
|
||||
{links.map((link) => (
|
||||
<DropdownMenuItem key={link.url} asChild>
|
||||
<a href={link.url} target="_blank" rel="noreferrer">
|
||||
{link.label ?? label}
|
||||
<ExternalLink className="ml-2 h-3.5 w-3.5 text-muted-foreground" aria-hidden />
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useMemo, type ReactNode } from "react";
|
||||
import type { useTranslation } from "react-i18next";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import {
|
||||
channelFieldMessageKey,
|
||||
@@ -12,14 +12,17 @@ import {
|
||||
} from "@/channel-plugins/registry";
|
||||
import type {
|
||||
ChannelConfigField,
|
||||
ChannelFieldPresentation,
|
||||
ChannelSetupPresentation,
|
||||
} from "@/components/settings/channels/catalog";
|
||||
import { channelValidationMessage } from "@/components/settings/channels/validationMessages";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
import { normalizeLocale } from "@/i18n/config";
|
||||
import { logoFallbackUrls } from "@/lib/provider-brand";
|
||||
import type { ChannelRuntimeStatus, NanobotFeatureInfo } from "@/lib/types";
|
||||
|
||||
export type ChannelFilter = "all" | "on" | "off";
|
||||
export const CHANNEL_SETUP_PANEL_CLASS_NAME =
|
||||
"min-h-full rounded-panel bg-settings-surface p-6";
|
||||
|
||||
export function channelSetup(
|
||||
feature: NanobotFeatureInfo,
|
||||
@@ -35,25 +38,23 @@ export function channelSetup(
|
||||
key,
|
||||
label: copy?.label ?? fieldLabel(key.split(".").at(-1) ?? key),
|
||||
placeholder: copy?.placeholder,
|
||||
help: copy?.help,
|
||||
};
|
||||
};
|
||||
const localizePresentedField = (
|
||||
field: ChannelFieldPresentation,
|
||||
): ChannelConfigField => ({
|
||||
...localizeField(field.key),
|
||||
section: field.section,
|
||||
});
|
||||
const presentation: ChannelSetupPresentation = {
|
||||
...definition,
|
||||
primaryActionLabel: setupMessages?.primaryAction,
|
||||
docsLabel: setupMessages?.docsLabel,
|
||||
officialLabel: setupMessages?.officialLabel,
|
||||
summary:
|
||||
setupMessages?.summary
|
||||
?? "Enable turns on this channel in nanobot, but this integration still needs platform-specific setup before it can receive messages.",
|
||||
tryIt: setupMessages?.tryIt,
|
||||
steps: setupMessages?.steps ?? [
|
||||
`Open ~/.nanobot/config.json and find channels.${feature.name}.`,
|
||||
"Add the credentials required by that platform, using the channel documentation as the source of truth.",
|
||||
"Restart nanobot, then send a small test message from that platform.",
|
||||
],
|
||||
fields: definition?.fields?.map((field) => localizeField(field.key)),
|
||||
manualFields: definition?.manualFields?.map((field) => localizeField(field.key)),
|
||||
presetLabel: setupMessages?.presetLabel,
|
||||
sectionLabels: setupMessages?.sections,
|
||||
fields: definition?.fields?.map(localizePresentedField),
|
||||
manualFields: definition?.manualFields?.map(localizePresentedField),
|
||||
actions: definition?.actions?.map((action) => ({
|
||||
...action,
|
||||
label: setupMessages?.actions?.[action.id] ?? fieldLabel(action.id),
|
||||
@@ -83,9 +84,11 @@ export function channelSetup(
|
||||
...copy,
|
||||
key: field.key,
|
||||
label: copy.label,
|
||||
section: copy.section ?? (field.required ? "credentials" : "advanced"),
|
||||
secret: field.kind === "secret",
|
||||
optional: !field.required,
|
||||
inputType: field.kind === "int" ? "number" : undefined,
|
||||
kind: field.kind,
|
||||
inputType: channelFieldInputType(field.field, field.kind),
|
||||
defaultValue: field.default_value,
|
||||
options:
|
||||
field.kind === "enum" || field.kind === "bool"
|
||||
@@ -106,11 +109,24 @@ export function channelSetup(
|
||||
officialLabel:
|
||||
presentation.officialLabel
|
||||
?? (contract.official_url ? "Open official setup" : undefined),
|
||||
requirements: contract.requirements,
|
||||
fields: fields.length ? fields : undefined,
|
||||
manualFields: manual.length ? manual : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function channelFieldInputType(
|
||||
field: string,
|
||||
kind: string,
|
||||
): ChannelConfigField["inputType"] {
|
||||
if (kind === "int" || kind === "float") return "number";
|
||||
const normalized = field.toLowerCase();
|
||||
if (normalized.includes("url")) return "url";
|
||||
if (normalized.includes("email") || normalized.includes("address")) return "email";
|
||||
if (normalized.includes("phone")) return "tel";
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function fieldLabel(value: string): string {
|
||||
const spaced = value
|
||||
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
||||
@@ -126,21 +142,14 @@ export function ChannelLogo({
|
||||
feature: NanobotFeatureInfo;
|
||||
showBrandLogos: boolean;
|
||||
}) {
|
||||
const presentation = channelUiPresentation(feature.name, feature.webui);
|
||||
const presentation = channelUiPresentation(feature.name, feature.webui)
|
||||
?? channelUiPresentation(feature.name);
|
||||
const initials = presentation?.initials ?? feature.display_name.slice(0, 2).toUpperCase();
|
||||
const color = presentation?.color ?? "#6B7280";
|
||||
const Icon = presentation?.icon;
|
||||
const logoUrls = useMemo(() => logoFallbackUrls(presentation?.logoUrl), [presentation?.logoUrl]);
|
||||
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(logoUrls);
|
||||
|
||||
if (feature.name === "websocket") {
|
||||
return (
|
||||
<span className="grid h-10 w-10 shrink-0 place-items-center rounded-control bg-background">
|
||||
<img src="/brand/nanobot_mark.svg" alt="" className="h-6 w-6 object-contain" draggable={false} />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (showBrandLogos && logoUrl) {
|
||||
return (
|
||||
<span
|
||||
@@ -194,24 +203,6 @@ export function localizedChannelDisplayName(
|
||||
return channelTranslator(t, channelUiOwner(feature.name))("displayName", fallback);
|
||||
}
|
||||
|
||||
export function channelDescription(feature: NanobotFeatureInfo, t: ReturnType<typeof useTranslation>["t"]): string {
|
||||
const fallback =
|
||||
`Use nanobot from ${channelDisplayName(feature)}.`;
|
||||
return channelTranslator(t, channelUiOwner(feature.name))("description", fallback);
|
||||
}
|
||||
|
||||
export function channelRequirements(feature: NanobotFeatureInfo, t: ReturnType<typeof useTranslation>["t"]): string {
|
||||
const fallback =
|
||||
"Channel credentials and gateway settings";
|
||||
return channelTranslator(t, channelUiOwner(feature.name))("requirements", fallback);
|
||||
}
|
||||
|
||||
export function channelMatchesFilter(feature: NanobotFeatureInfo, filter: ChannelFilter): boolean {
|
||||
if (filter === "on") return channelIsRunning(feature);
|
||||
if (filter === "off") return !channelIsRunning(feature);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function channelIsRunning(feature: NanobotFeatureInfo): boolean {
|
||||
return feature.runtime_status === "running";
|
||||
}
|
||||
@@ -232,27 +223,11 @@ export function channelStatusLabel(
|
||||
}
|
||||
if (channelIsRunning(feature)) return tx("settings.values.on", "On");
|
||||
if (feature.enabled) return tx("settings.channels.runtimeStopped", "Not running");
|
||||
if (feature.configured === false) return tx("settings.channels.needsConfig", "Needs setup");
|
||||
if (feature.configured === true) return tx("settings.nanobotFeatures.ready", "Ready");
|
||||
return tx("settings.values.off", "Off");
|
||||
}
|
||||
|
||||
export function channelSearchText(
|
||||
feature: NanobotFeatureInfo,
|
||||
t?: ReturnType<typeof useTranslation>["t"],
|
||||
): string {
|
||||
return [
|
||||
t ? localizedChannelDisplayName(feature, t) : undefined,
|
||||
channelDisplayName(feature),
|
||||
feature.display_name,
|
||||
feature.name,
|
||||
feature.status,
|
||||
t ? channelDescription(feature, t) : undefined,
|
||||
t ? channelRequirements(feature, t) : undefined,
|
||||
]
|
||||
.join(" ")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
export function ChannelStatusBadge({
|
||||
children,
|
||||
status,
|
||||
@@ -281,10 +256,11 @@ export function ChannelRuntimeError({
|
||||
message?: string;
|
||||
className?: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
if (!message) return null;
|
||||
return (
|
||||
<div className={`${className} rounded-control border border-destructive/20 bg-destructive/5 px-3 py-2 text-[12px] leading-5 text-destructive`}>
|
||||
{message}
|
||||
{channelValidationMessage(message, t)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -13,17 +13,12 @@ import {
|
||||
defaultChannelFieldValues,
|
||||
} from "@/components/settings/channels/CredentialForm";
|
||||
import {
|
||||
CHANNEL_SETUP_PANEL_CLASS_NAME,
|
||||
ChannelLogo,
|
||||
ChannelRuntimeError,
|
||||
ChannelStatusBadge,
|
||||
channelSetup,
|
||||
channelStatusLabel,
|
||||
localizedChannelDisplayName,
|
||||
} from "@/components/settings/channels/ChannelIdentity";
|
||||
import {
|
||||
ChannelGuideLink,
|
||||
ChannelSetupSteps,
|
||||
} from "@/components/settings/channels/ChannelSetupParts";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
import {
|
||||
@@ -41,7 +36,6 @@ import { cn } from "@/lib/utils";
|
||||
import { useClient } from "@/providers/ClientProvider";
|
||||
|
||||
export type ChannelInstancesPanelCustomization = {
|
||||
countLabel?: (runningCount: number) => string;
|
||||
toggleAriaLabel?: (instance: NanobotChannelInstanceInfo) => string;
|
||||
configuredLabel?: string;
|
||||
needsSetupLabel?: string;
|
||||
@@ -53,14 +47,12 @@ export type ChannelInstancesPanelCustomization = {
|
||||
export function ChannelInstancesPanel({
|
||||
feature,
|
||||
showBrandLogos,
|
||||
chatAppsDocsUrl,
|
||||
instances: providedInstances,
|
||||
onFeaturesUpdate,
|
||||
customization = {},
|
||||
}: {
|
||||
feature: NanobotFeatureInfo;
|
||||
showBrandLogos: boolean;
|
||||
chatAppsDocsUrl?: string;
|
||||
instances?: NanobotChannelInstanceInfo[];
|
||||
onFeaturesUpdate: (payload: NanobotFeaturesPayload) => void;
|
||||
customization?: ChannelInstancesPanelCustomization;
|
||||
@@ -70,8 +62,9 @@ export function ChannelInstancesPanel({
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
const displayName = localizedChannelDisplayName(feature, t);
|
||||
const instances = providedInstances ?? feature.instances ?? [];
|
||||
const [selectedId, setSelectedId] = useState<string | null>(null);
|
||||
const [busyInstanceId, setBusyInstanceId] = useState<string | null>(null);
|
||||
const [editor, setEditor] = useState<{ id: string; expanded: boolean } | null>(null);
|
||||
const selectedId = editor?.id;
|
||||
const [pendingToggle, setPendingToggle] = useState<{ id: string; checked: boolean } | null>(null);
|
||||
const [notice, setNotice] = useState<string | null>(null);
|
||||
const selected = selectedId ? instances.find((instance) => instance.id === selectedId) : undefined;
|
||||
const setup = useMemo(
|
||||
@@ -87,9 +80,9 @@ export function ChannelInstancesPanel({
|
||||
);
|
||||
const [visibleSecrets, setVisibleSecrets] = useState<Record<string, boolean>>({});
|
||||
const [savingFields, setSavingFields] = useState(false);
|
||||
const configuredCount = instances.filter((instance) => instance.configured).length;
|
||||
const runningCount = instances.filter((instance) => instance.runtime_status === "running").length;
|
||||
const selectedValuesKey = JSON.stringify(selected?.config_values ?? {});
|
||||
const selectedValuesKey = JSON.stringify(
|
||||
defaultChannelFieldValues(instanceFields, selected?.config_values),
|
||||
);
|
||||
const selectedConfiguredFields = useMemo(
|
||||
() => new Set(selected?.configured_fields ?? []),
|
||||
[selected?.configured_fields],
|
||||
@@ -97,17 +90,18 @@ export function ChannelInstancesPanel({
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedId && !instances.some((instance) => instance.id === selectedId)) {
|
||||
setSelectedId(null);
|
||||
setEditor(null);
|
||||
}
|
||||
}, [instances, selectedId]);
|
||||
|
||||
useEffect(() => {
|
||||
setFieldValues(defaultChannelFieldValues(instanceFields, selected?.config_values));
|
||||
setVisibleSecrets({});
|
||||
}, [instanceFields, selected?.id, selectedValuesKey]);
|
||||
}, [selected?.id, selectedValuesKey]);
|
||||
|
||||
const toggleInstance = async (instance: NanobotChannelInstanceInfo, checked: boolean) => {
|
||||
setBusyInstanceId(instance.id);
|
||||
if (pendingToggle || savingFields) return;
|
||||
setPendingToggle({ id: instance.id, checked });
|
||||
setNotice(null);
|
||||
try {
|
||||
const payload = checked
|
||||
@@ -117,12 +111,12 @@ export function ChannelInstancesPanel({
|
||||
} catch (err) {
|
||||
setNotice((err as Error).message);
|
||||
} finally {
|
||||
setBusyInstanceId(null);
|
||||
setPendingToggle(null);
|
||||
}
|
||||
};
|
||||
|
||||
const saveSelectedInstanceSettings = async () => {
|
||||
if (!selected) return;
|
||||
if (!selected || pendingToggle || savingFields) return;
|
||||
setSavingFields(true);
|
||||
setNotice(null);
|
||||
try {
|
||||
@@ -144,35 +138,24 @@ export function ChannelInstancesPanel({
|
||||
};
|
||||
|
||||
return (
|
||||
<aside className="min-h-full rounded-panel bg-settings-surface p-5">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="flex min-w-0 items-start gap-3">
|
||||
<ChannelLogo feature={feature} showBrandLogos={showBrandLogos} />
|
||||
<div className="min-w-0 flex-1">
|
||||
<h3 className="truncate text-[18px] font-semibold leading-6 text-foreground">
|
||||
{displayName}
|
||||
</h3>
|
||||
<p className="mt-1 text-[13px] leading-5 text-muted-foreground">
|
||||
{customization.countLabel?.(runningCount)
|
||||
?? t("settings.channels.configuredInstances", {
|
||||
count: configuredCount,
|
||||
defaultValue: `${configuredCount} instances configured`,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<ChannelStatusBadge status={feature.runtime_status}>
|
||||
{channelStatusLabel(feature, tx)}
|
||||
</ChannelStatusBadge>
|
||||
</div>
|
||||
<aside className={CHANNEL_SETUP_PANEL_CLASS_NAME}>
|
||||
<div className="pe-20">
|
||||
<ChannelLogo feature={feature} showBrandLogos={showBrandLogos} />
|
||||
<h3 className="sr-only">{displayName}</h3>
|
||||
</div>
|
||||
|
||||
<ChannelRuntimeError message={feature.runtime_error} />
|
||||
|
||||
<div className="mt-5 space-y-3">
|
||||
{instances.map((instance) => {
|
||||
const expanded = selected?.id === instance.id;
|
||||
const expanded = selected?.id === instance.id && editor?.expanded === true;
|
||||
const toggling = pendingToggle?.id === instance.id;
|
||||
const checked = toggling ? pendingToggle.checked : instanceToggleChecked(instance);
|
||||
const instanceSummary = customization.renderInstanceSummary
|
||||
? customization.renderInstanceSummary(instance)
|
||||
: instance.id;
|
||||
const instanceAction = customization.renderInstanceAction?.(instance);
|
||||
const hasInstanceOverview = Boolean(instanceSummary || instanceAction);
|
||||
return (
|
||||
<article
|
||||
key={instance.id}
|
||||
@@ -180,18 +163,11 @@ export function ChannelInstancesPanel({
|
||||
"overflow-hidden rounded-floating transition-colors",
|
||||
expanded
|
||||
? "bg-background"
|
||||
: "bg-background/70 settings-hover",
|
||||
: "bg-background/70",
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-3 px-3 py-3">
|
||||
<button
|
||||
type="button"
|
||||
className="flex min-w-0 flex-1 items-center gap-3 text-left"
|
||||
onClick={() =>
|
||||
setSelectedId((current) => (current === instance.id ? null : instance.id))
|
||||
}
|
||||
aria-expanded={expanded}
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 px-3 py-3">
|
||||
<div className="flex min-w-0 flex-[1_1_12rem] items-center gap-3">
|
||||
<ChannelInstanceAvatar
|
||||
feature={feature}
|
||||
instance={instance}
|
||||
@@ -200,22 +176,43 @@ export function ChannelInstancesPanel({
|
||||
<span className="min-w-0 flex-1 truncate text-[13px] font-semibold text-foreground">
|
||||
{channelInstanceDisplayName(instance)}
|
||||
</span>
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
"h-4 w-4 shrink-0 text-muted-foreground transition-transform",
|
||||
expanded && "rotate-180",
|
||||
)}
|
||||
aria-hidden
|
||||
<ChannelInstanceStatusBadge
|
||||
instance={instance}
|
||||
configuredLabel={customization.configuredLabel}
|
||||
needsSetupLabel={customization.needsSetupLabel}
|
||||
/>
|
||||
</button>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
{busyInstanceId === instance.id ? (
|
||||
</div>
|
||||
<div className="ms-auto flex shrink-0 items-center gap-3">
|
||||
{instanceFields.length ? (
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex min-h-8 items-center gap-1.5 rounded px-1 text-[12px] text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-offset-2"
|
||||
onClick={() =>
|
||||
setEditor((current) => ({
|
||||
id: instance.id,
|
||||
expanded: current?.id !== instance.id || !current.expanded,
|
||||
}))
|
||||
}
|
||||
aria-expanded={expanded}
|
||||
>
|
||||
{tx("settings.channels.advanced", "Advanced")}
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
"h-3.5 w-3.5 transition-transform motion-reduce:transition-none",
|
||||
expanded && "rotate-180",
|
||||
)}
|
||||
aria-hidden
|
||||
/>
|
||||
</button>
|
||||
) : null}
|
||||
{toggling ? (
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin text-muted-foreground" aria-hidden />
|
||||
) : null}
|
||||
<ToggleButton
|
||||
checked={instanceToggleChecked(instance)}
|
||||
checked={checked}
|
||||
disabled={
|
||||
busyInstanceId === instance.id
|
||||
Boolean(pendingToggle)
|
||||
|| savingFields
|
||||
|| !instance.configured
|
||||
}
|
||||
ariaLabel={customization.toggleAriaLabel?.(instance)
|
||||
@@ -223,51 +220,28 @@ export function ChannelInstancesPanel({
|
||||
name: channelInstanceDisplayName(instance),
|
||||
defaultValue: "{{name}} instance",
|
||||
})}
|
||||
label={instanceToggleChecked(instance) ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
|
||||
label={checked ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
|
||||
onChange={(checked) => void toggleInstance(instance, checked)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{expanded ? (
|
||||
<div className="space-y-5 px-4 pb-4">
|
||||
<section className="pt-4">
|
||||
<div className="mb-3 flex items-start justify-between gap-3">
|
||||
{hasInstanceOverview || (expanded && instanceFields.length > 0) ? (
|
||||
<div className="space-y-3 px-4 pb-4 pt-1">
|
||||
{hasInstanceOverview ? <section className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
{instanceSummary ? (
|
||||
<p className="min-w-0 flex-1 truncate font-mono text-[11.5px] leading-6 text-muted-foreground">
|
||||
{customization.renderInstanceSummary?.(instance) ?? instance.id}
|
||||
{instanceSummary}
|
||||
</p>
|
||||
<ChannelInstanceStatusBadge
|
||||
instance={instance}
|
||||
configuredLabel={customization.configuredLabel}
|
||||
needsSetupLabel={customization.needsSetupLabel}
|
||||
/>
|
||||
</div>
|
||||
{customization.renderInstanceAction?.(instance)}
|
||||
</section>
|
||||
<ChannelSetupSteps
|
||||
steps={setup.steps}
|
||||
action={
|
||||
<ChannelGuideLink
|
||||
feature={feature}
|
||||
setup={setup}
|
||||
chatAppsDocsUrl={chatAppsDocsUrl}
|
||||
compact
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{instanceFields.length ? (
|
||||
<details className="group text-[12px] leading-5 text-muted-foreground">
|
||||
<summary className="cursor-pointer list-none text-[12px] font-semibold text-foreground">
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
{tx("settings.channels.advanced", "Advanced")}
|
||||
<ChevronDown
|
||||
className="h-3.5 w-3.5 transition-transform group-open:rotate-180"
|
||||
aria-hidden
|
||||
/>
|
||||
</span>
|
||||
</summary>
|
||||
) : <span className="flex-1" />}
|
||||
{instanceAction}
|
||||
</section> : null}
|
||||
{expanded && instanceFields.length > 0 ? (
|
||||
<div className={cn(
|
||||
"text-[12px] leading-5 text-muted-foreground",
|
||||
hasInstanceOverview && "border-t border-border/50 pt-3",
|
||||
)}>
|
||||
<form
|
||||
className="mt-3"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void saveSelectedInstanceSettings();
|
||||
@@ -292,7 +266,7 @@ export function ChannelInstancesPanel({
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
className="h-8 rounded-full bg-muted/70 px-3 text-[12px] font-semibold settings-hover"
|
||||
disabled={savingFields}
|
||||
disabled={savingFields || Boolean(pendingToggle)}
|
||||
>
|
||||
{savingFields ? (
|
||||
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
@@ -301,7 +275,7 @@ export function ChannelInstancesPanel({
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</details>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { channelValidationMessage } from "./validationMessages";
|
||||
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import QRCode from "qrcode";
|
||||
import { Check, Loader2, Network, RotateCcw } from "lucide-react";
|
||||
import { Check, Loader2, RotateCcw } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -28,13 +29,6 @@ export type ChannelQrConnectLabels = {
|
||||
connect: string;
|
||||
};
|
||||
|
||||
export type ChannelConnectStartOptions = {
|
||||
domain?: string;
|
||||
instanceId?: string;
|
||||
mode?: "replace" | "create";
|
||||
force?: boolean;
|
||||
};
|
||||
|
||||
export type ChannelQrConnectPendingContext = {
|
||||
connect: ChannelConnectPayload;
|
||||
busy: boolean;
|
||||
@@ -45,10 +39,12 @@ export type ChannelQrConnectPendingContext = {
|
||||
|
||||
export function ChannelQrConnectFlow({
|
||||
channelName,
|
||||
startOptions = {},
|
||||
startParams = {},
|
||||
idleLabel,
|
||||
connectRequestId,
|
||||
forceOnRepeat = false,
|
||||
autoStart = false,
|
||||
minimalPending = false,
|
||||
labels,
|
||||
onFeaturesUpdate,
|
||||
pausePolling,
|
||||
@@ -58,10 +54,12 @@ export function ChannelQrConnectFlow({
|
||||
}: {
|
||||
token: string;
|
||||
channelName: string;
|
||||
startOptions?: ChannelConnectStartOptions;
|
||||
startParams?: Readonly<Record<string, string | boolean>>;
|
||||
idleLabel?: string;
|
||||
connectRequestId?: number;
|
||||
forceOnRepeat?: boolean;
|
||||
autoStart?: boolean;
|
||||
minimalPending?: boolean;
|
||||
labels: ChannelQrConnectLabels;
|
||||
onFeaturesUpdate: (payload: NanobotFeaturesPayload) => void;
|
||||
pausePolling?: (payload: ChannelConnectPayload) => boolean;
|
||||
@@ -77,19 +75,16 @@ export function ChannelQrConnectFlow({
|
||||
const [qrDataUrl, setQrDataUrl] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [handledRequestId, setHandledRequestId] = useState(0);
|
||||
const handledRequestId = useRef(0);
|
||||
const autoStarted = useRef(false);
|
||||
const pollInFlight = useRef(false);
|
||||
const startDomain = startOptions.domain;
|
||||
const startInstanceId = startOptions.instanceId;
|
||||
const startMode = startOptions.mode;
|
||||
const startForce = startOptions.force;
|
||||
|
||||
const pending = connect?.status === "pending";
|
||||
const succeeded = connect?.status === "succeeded";
|
||||
const canStart = !pending && !busy;
|
||||
const pollingPaused = Boolean(connect && pausePolling?.(connect));
|
||||
const displayMessage = connect
|
||||
? resolveMessage?.(connect) ?? connect.message
|
||||
? resolveMessage?.(connect) ?? (connect.message ? channelValidationMessage(connect.message, t) : undefined)
|
||||
: undefined;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -176,10 +171,8 @@ export function ChannelQrConnectFlow({
|
||||
setError(null);
|
||||
try {
|
||||
const payload = await startChannelConnect(client, channelName, {
|
||||
domain: startDomain,
|
||||
instanceId: startInstanceId,
|
||||
mode: startMode,
|
||||
force: force || startForce,
|
||||
...startParams,
|
||||
...(force ? { force: true } : {}),
|
||||
});
|
||||
setConnect(payload);
|
||||
} catch (err) {
|
||||
@@ -187,13 +180,15 @@ export function ChannelQrConnectFlow({
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}, [channelName, client, startDomain, startForce, startInstanceId, startMode]);
|
||||
}, [channelName, client, startParams]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!connectRequestId || connectRequestId === handledRequestId) return;
|
||||
setHandledRequestId(connectRequestId);
|
||||
const requested = Boolean(connectRequestId && connectRequestId !== handledRequestId.current);
|
||||
if (!requested && !(autoStart && !autoStarted.current)) return;
|
||||
handledRequestId.current = connectRequestId ?? 0;
|
||||
autoStarted.current = true;
|
||||
void start();
|
||||
}, [connectRequestId, handledRequestId, start]);
|
||||
}, [autoStart, connectRequestId, start]);
|
||||
|
||||
const cancel = async () => {
|
||||
if (!connect?.session_id) {
|
||||
@@ -250,7 +245,28 @@ export function ChannelQrConnectFlow({
|
||||
|
||||
return (
|
||||
<div className="mt-3 space-y-3">
|
||||
{pending ? (
|
||||
{autoStart && busy && !connect ? (
|
||||
<div role="status" className="grid min-h-[228px] place-items-center">
|
||||
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" aria-hidden />
|
||||
<span className="sr-only">{labels.connecting}</span>
|
||||
</div>
|
||||
) : null}
|
||||
{pending && minimalPending ? (
|
||||
<div className="flex min-h-[228px] flex-col items-center justify-center gap-4 py-4">
|
||||
<div className="grid h-[196px] w-[196px] place-items-center rounded-control bg-background shadow-[inset_0_0_0_1px_oklch(0_0_0/0.1)] dark:shadow-[inset_0_0_0_1px_oklch(1_0_0/0.1)]">
|
||||
{qrDataUrl ? (
|
||||
<img
|
||||
src={qrDataUrl}
|
||||
alt={labels.qrAlt}
|
||||
className="h-[184px] w-[184px]"
|
||||
/>
|
||||
) : (
|
||||
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" aria-hidden />
|
||||
)}
|
||||
</div>
|
||||
{renderPending?.({ connect, busy, poll: submitPoll })}
|
||||
</div>
|
||||
) : pending ? (
|
||||
<div className="grid gap-4 rounded-control border border-border/70 p-4 sm:grid-cols-[auto_minmax(0,1fr)]">
|
||||
<div className="grid h-[196px] w-[196px] place-items-center rounded-control border border-border/60 bg-background">
|
||||
{qrDataUrl ? (
|
||||
@@ -268,12 +284,12 @@ export function ChannelQrConnectFlow({
|
||||
{labels.scanTitle}
|
||||
</div>
|
||||
<p className="mt-1 text-[12.5px] leading-5 text-muted-foreground">
|
||||
{labels.scanDescription}
|
||||
{qrDataUrl ? labels.scanDescription : null}
|
||||
</p>
|
||||
{renderPending?.({ connect, busy, poll: submitPoll }) ?? (
|
||||
<div className="mt-3 flex items-center gap-2 text-[12px] text-muted-foreground">
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
{labels.waiting}
|
||||
{qrDataUrl ? labels.waiting : labels.connecting}
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-4 flex flex-wrap justify-end gap-2">
|
||||
@@ -311,7 +327,7 @@ export function ChannelQrConnectFlow({
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex flex-wrap justify-end gap-2">
|
||||
{!pending && !(autoStart && busy && !connect) ? <div className="flex flex-wrap justify-end gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
@@ -324,16 +340,14 @@ export function ChannelQrConnectFlow({
|
||||
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
) : succeeded ? (
|
||||
<RotateCcw className="mr-1.5 h-3.5 w-3.5" aria-hidden />
|
||||
) : (
|
||||
<Network className="mr-1.5 h-3.5 w-3.5" aria-hidden />
|
||||
)}
|
||||
) : null}
|
||||
{pending
|
||||
? labels.connecting
|
||||
: succeeded
|
||||
? labels.scanAgain
|
||||
: idleLabel ?? labels.connect}
|
||||
</Button>
|
||||
</div>
|
||||
</div> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,11 +1,11 @@
|
||||
import { useMemo, useState, type ReactNode } from "react";
|
||||
import { channelValidationMessage } from "./validationMessages";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Clipboard, ExternalLink, Loader2 } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { channelUiPresentation } from "@/channel-plugins/registry";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
docsUrlWithBase,
|
||||
type ChannelProviderPreset,
|
||||
type ChannelSetupPresentation,
|
||||
} from "@/components/settings/channels/catalog";
|
||||
@@ -16,154 +16,13 @@ import {
|
||||
channelValidationStatusIcon,
|
||||
channelValidationStatusLabel,
|
||||
} from "@/components/settings/channels/CredentialForm";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
import { logoFallbackUrls } from "@/lib/provider-brand";
|
||||
import type {
|
||||
ChannelValidationPayload,
|
||||
NanobotFeatureInfo,
|
||||
} from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function ChannelGuideLink({
|
||||
feature,
|
||||
setup,
|
||||
chatAppsDocsUrl,
|
||||
compact = false,
|
||||
}: {
|
||||
feature: NanobotFeatureInfo;
|
||||
setup: ChannelSetupPresentation;
|
||||
chatAppsDocsUrl?: string;
|
||||
compact?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
const presentation = channelUiPresentation(feature.name, feature.webui);
|
||||
const logoUrls = useMemo(
|
||||
() => logoFallbackUrls(setup.docsLogoUrl ?? presentation?.logoUrl),
|
||||
[presentation?.logoUrl, setup.docsLogoUrl],
|
||||
);
|
||||
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(logoUrls);
|
||||
const Icon = presentation?.icon;
|
||||
const initials = presentation?.initials ?? feature.display_name.slice(0, 2).toUpperCase();
|
||||
const color = presentation?.color ?? "#6B7280";
|
||||
const docsUrl = docsUrlWithBase(setup.docsUrl, chatAppsDocsUrl);
|
||||
|
||||
if (!docsUrl) return null;
|
||||
|
||||
return (
|
||||
<a
|
||||
href={docsUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className={cn(
|
||||
"inline-flex max-w-full items-center gap-2 bg-background/80 font-semibold text-foreground transition-colors settings-hover",
|
||||
compact
|
||||
? "shrink-0 rounded-full py-1 pl-1 pr-2.5 text-[11.5px]"
|
||||
: "mt-3 rounded-control py-1.5 pl-1.5 pr-3 text-[12px]",
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"grid shrink-0 place-items-center overflow-hidden bg-muted/70 font-bold",
|
||||
compact ? "h-5 w-5 rounded-full text-[9px]" : "h-6 w-6 rounded-compact text-[10px]",
|
||||
)}
|
||||
style={{ color }}
|
||||
aria-hidden
|
||||
>
|
||||
{logoUrl ? (
|
||||
<img
|
||||
src={logoUrl}
|
||||
alt=""
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
className={cn("object-contain", compact ? "h-3.5 w-3.5" : "h-4 w-4")}
|
||||
onLoad={onLogoLoad}
|
||||
onError={onLogoError}
|
||||
/>
|
||||
) : Icon ? (
|
||||
<Icon className={compact ? "h-3 w-3" : "h-3.5 w-3.5"} strokeWidth={2.25} />
|
||||
) : (
|
||||
initials
|
||||
)}
|
||||
</span>
|
||||
<span className="truncate">
|
||||
{setup.docsLabel ?? tx("settings.channels.officialGuide", "Official guide")}
|
||||
</span>
|
||||
<ExternalLink className="h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
export function ChannelSetupLinks({
|
||||
feature,
|
||||
setup,
|
||||
chatAppsDocsUrl,
|
||||
}: {
|
||||
feature: NanobotFeatureInfo;
|
||||
setup: ChannelSetupPresentation;
|
||||
chatAppsDocsUrl?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2">
|
||||
<ChannelOfficialLink feature={feature} setup={setup} />
|
||||
<ChannelGuideLink feature={feature} setup={setup} chatAppsDocsUrl={chatAppsDocsUrl} compact />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ChannelOfficialLink({
|
||||
feature,
|
||||
setup,
|
||||
}: {
|
||||
feature: NanobotFeatureInfo;
|
||||
setup: ChannelSetupPresentation;
|
||||
}) {
|
||||
const presentation = channelUiPresentation(feature.name, feature.webui);
|
||||
const logoUrls = useMemo(
|
||||
() => logoFallbackUrls(setup.docsLogoUrl ?? presentation?.logoUrl),
|
||||
[presentation?.logoUrl, setup.docsLogoUrl],
|
||||
);
|
||||
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(logoUrls);
|
||||
const Icon = presentation?.icon;
|
||||
const initials = presentation?.initials ?? feature.display_name.slice(0, 2).toUpperCase();
|
||||
const color = presentation?.color ?? "#6B7280";
|
||||
const label = setup.officialLabel;
|
||||
if (!setup.officialUrl || !label) return null;
|
||||
return (
|
||||
<a
|
||||
href={setup.officialUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex max-w-full shrink-0 items-center gap-2 rounded-full bg-background/80 py-1 pl-1 pr-2.5 text-[11.5px] font-semibold text-foreground transition-colors settings-hover"
|
||||
>
|
||||
<span
|
||||
className="grid h-5 w-5 shrink-0 place-items-center overflow-hidden rounded-full bg-muted/70"
|
||||
style={{ color }}
|
||||
aria-hidden
|
||||
>
|
||||
{logoUrl ? (
|
||||
<img
|
||||
src={logoUrl}
|
||||
alt=""
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
className="h-3.5 w-3.5 object-contain"
|
||||
onLoad={onLogoLoad}
|
||||
onError={onLogoError}
|
||||
/>
|
||||
) : Icon ? (
|
||||
<Icon className="h-3 w-3" strokeWidth={2.25} />
|
||||
) : (
|
||||
<span className="text-[8px] font-bold">{initials}</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="truncate">{label}</span>
|
||||
<ExternalLink className="h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
export function ChannelSetupActions({
|
||||
feature,
|
||||
setup,
|
||||
@@ -216,48 +75,48 @@ export function ChannelSetupActions({
|
||||
export function ChannelProviderPresets({
|
||||
presets,
|
||||
onApply,
|
||||
label,
|
||||
disabled = false,
|
||||
}: {
|
||||
presets: ChannelProviderPreset[];
|
||||
onApply: (preset: ChannelProviderPreset) => void;
|
||||
label?: string;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [selected, setSelected] = useState("");
|
||||
if (!presets.length) return null;
|
||||
return (
|
||||
<div className="mt-3">
|
||||
<div className="mb-1 text-[11px] font-medium text-foreground/85">
|
||||
{t("settings.channels.providerPreset", { defaultValue: "Provider" })}
|
||||
</div>
|
||||
<div
|
||||
role="radiogroup"
|
||||
aria-label={t("settings.channels.providerPreset", { defaultValue: "Provider" })}
|
||||
className="grid rounded-control bg-muted p-0.5 text-[12px] font-medium text-muted-foreground"
|
||||
style={{ gridTemplateColumns: `repeat(${presets.length}, minmax(0, 1fr))` }}
|
||||
>
|
||||
<fieldset>
|
||||
<legend className="mb-1 text-[11px] font-medium text-foreground/85">
|
||||
{label ?? t("settings.channels.providerPreset", { defaultValue: "Provider" })}
|
||||
</legend>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{presets.map((preset) => (
|
||||
<button
|
||||
<Button
|
||||
key={preset.id}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected === preset.id}
|
||||
onClick={() => {
|
||||
setSelected(preset.id);
|
||||
onApply(preset);
|
||||
}}
|
||||
className={cn(
|
||||
"min-h-8 rounded-compact px-2 py-1.5 transition-colors hover:text-foreground",
|
||||
selected === preset.id && "bg-background text-foreground",
|
||||
)}
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={disabled}
|
||||
className="h-8 rounded-full px-3 text-[12px] font-medium"
|
||||
onClick={() => onApply(preset)}
|
||||
>
|
||||
{preset.label}
|
||||
</button>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
|
||||
export function ChannelValidationBadge({
|
||||
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,
|
||||
@@ -267,118 +126,108 @@ export function ChannelValidationBadge({
|
||||
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 label = validating
|
||||
? t("settings.channels.checking", { defaultValue: "Checking..." })
|
||||
: channelValidationStatusLabel(status, t);
|
||||
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 (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[11.5px] font-medium",
|
||||
channelValidationStatusClass(status),
|
||||
)}
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-atomic="true"
|
||||
className="rounded-control border border-border/60 bg-muted/25 px-3 py-3"
|
||||
>
|
||||
{validating ? (
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
) : (
|
||||
channelValidationStatusIcon(status)
|
||||
)}
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function ChannelValidationDetails({ validation }: { validation: ChannelValidationPayload | null }) {
|
||||
const message = validation?.message;
|
||||
if (!validation?.identity?.name && !message) return null;
|
||||
return (
|
||||
<div className="mt-2 truncate text-[11.5px] text-muted-foreground">
|
||||
{validation?.identity?.name
|
||||
? validation.identity.workspace
|
||||
? `${validation.identity.name} · ${validation.identity.workspace}`
|
||||
: validation.identity.name
|
||||
: message}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ChannelValidationChecks({ validation }: { validation: ChannelValidationPayload }) {
|
||||
const { t } = useTranslation();
|
||||
if (!validation.checks.length) return null;
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-2 text-[12px] font-semibold text-foreground">
|
||||
{t("settings.channels.connectionChecks")}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
{validation.checks.slice(0, 6).map((check) => (
|
||||
<div key={check.id} className="flex gap-2 text-[12px] leading-5">
|
||||
<span className={cn("mt-0.5", channelValidationCheckIconClass(check.status))}>
|
||||
{channelValidationCheckIcon(check.status)}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="font-medium text-foreground/85">{check.label}</div>
|
||||
{check.message ? (
|
||||
<div className="text-muted-foreground">{check.message}</div>
|
||||
) : null}
|
||||
{check.action_url ? (
|
||||
<a
|
||||
href={check.action_url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex items-center gap-1 text-foreground underline decoration-border underline-offset-4"
|
||||
>
|
||||
{t("settings.channels.open")}
|
||||
<ExternalLink className="h-3 w-3" aria-hidden />
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="space-y-2.5">
|
||||
{validating ? (
|
||||
<div className="flex items-center gap-2 px-2.5 text-[12px] font-medium text-foreground/85">
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin text-muted-foreground" aria-hidden />
|
||||
{t("settings.channels.checking", { defaultValue: "Checking..." })}
|
||||
</div>
|
||||
))}
|
||||
) : null}
|
||||
{!validating ? shownChecks.map((check, index) => {
|
||||
const pending = !finished && index === settledCheckCount;
|
||||
return (
|
||||
<div
|
||||
key={check.id}
|
||||
className="flex animate-in gap-2 px-2.5 fade-in-0 slide-in-from-top-1 text-[12px] leading-5 duration-200 motion-reduce:animate-none"
|
||||
>
|
||||
<span className={cn(
|
||||
"mt-0.5",
|
||||
pending ? "text-muted-foreground" : channelValidationCheckIconClass(check.status),
|
||||
)}>
|
||||
{pending
|
||||
? <Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
: channelValidationCheckIcon(check.status)}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex min-w-0 items-center gap-x-2 font-medium text-foreground/85">
|
||||
<span className="min-w-0 truncate">{channelValidationMessage(check.label, t)}</span>
|
||||
{!pending && check.action_url ? (
|
||||
<a
|
||||
href={check.action_url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex shrink-0 items-center gap-1 whitespace-nowrap text-foreground underline decoration-border underline-offset-4"
|
||||
>
|
||||
{t("settings.channels.open")}
|
||||
<ExternalLink className="h-3 w-3" aria-hidden />
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
{!pending && check.status !== "pass" && check.message ? (
|
||||
<div className="text-muted-foreground">
|
||||
{channelValidationMessage(check.message, t)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}) : null}
|
||||
{finished ? (
|
||||
<div
|
||||
className={cn(
|
||||
"flex animate-in items-center gap-2 rounded-control px-2.5 py-2 text-[12px] font-medium fade-in-0 duration-200 motion-reduce:animate-none",
|
||||
channelValidationStatusClass(status),
|
||||
)}
|
||||
>
|
||||
{channelValidationStatusIcon(status)}
|
||||
<span className="min-w-0 truncate font-semibold">{identity}</span>
|
||||
<span className="lowercase">{channelValidationStatusLabel(status, t)}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ChannelSetupSteps({
|
||||
steps,
|
||||
action,
|
||||
tryIt,
|
||||
}: {
|
||||
steps: string[];
|
||||
action?: ReactNode;
|
||||
tryIt?: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
return (
|
||||
<div className="text-[12.5px] leading-5 text-muted-foreground">
|
||||
<div className="mb-2 flex items-center justify-between gap-3">
|
||||
<div className="text-[12px] font-semibold text-foreground">
|
||||
{tx("settings.channels.setupSteps", "Next steps")}
|
||||
</div>
|
||||
{action}
|
||||
</div>
|
||||
<ol className="space-y-1.5">
|
||||
{steps.map((step, index) => (
|
||||
<li key={step} className="flex gap-2">
|
||||
<span className="mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-muted text-[10px] font-semibold text-muted-foreground">
|
||||
{index + 1}
|
||||
</span>
|
||||
<span>{step}</span>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
{tryIt ? (
|
||||
<div className="mt-3 rounded-control bg-background/75 px-3 py-2 text-[12px] text-muted-foreground">
|
||||
<span className="font-medium text-foreground">
|
||||
{tx("settings.channels.tryIt", "Try it")}
|
||||
</span>
|
||||
<span className="ml-2">
|
||||
{tryIt}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { Check, CircleAlert, Eye, EyeOff, X } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import type { ChannelConfigField } from "@/components/settings/channels/catalog";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
@@ -10,6 +11,10 @@ function channelFieldValue(field: ChannelConfigField, values: Record<string, str
|
||||
return values[field.key] ?? field.defaultValue ?? field.options?.[0]?.value ?? "";
|
||||
}
|
||||
|
||||
export function channelFieldInputId(key: string): string {
|
||||
return `channel-field-${key.replace(/[^a-zA-Z0-9_-]/g, "-")}`;
|
||||
}
|
||||
|
||||
export function defaultChannelFieldValues(
|
||||
fields: ChannelConfigField[],
|
||||
configValues: Record<string, string> | undefined = undefined,
|
||||
@@ -39,9 +44,14 @@ export function channelValuesForSubmit(
|
||||
fields: ChannelConfigField[],
|
||||
values: Record<string, string>,
|
||||
touchedFields: Set<string>,
|
||||
): Record<string, string> {
|
||||
const payload: Record<string, string> = {};
|
||||
clearedSecrets: Set<string> = new Set(),
|
||||
): Record<string, string | null> {
|
||||
const payload: Record<string, string | null> = {};
|
||||
for (const field of fields) {
|
||||
if (field.secret && clearedSecrets.has(field.key)) {
|
||||
payload[field.key] = null;
|
||||
continue;
|
||||
}
|
||||
const touched = touchedFields.has(field.key);
|
||||
const value = channelFieldValue(field, values);
|
||||
if (field.secret && !value.trim()) continue;
|
||||
@@ -58,7 +68,7 @@ export function channelValidationStatusLabel(
|
||||
): string {
|
||||
const labels: Record<string, string> = {
|
||||
connected: "Connected",
|
||||
configured: "Configured manually",
|
||||
configured: "Not verified",
|
||||
needs_setup: "Needs setup",
|
||||
invalid: "Invalid",
|
||||
unsupported: "Manual setup",
|
||||
@@ -82,7 +92,7 @@ export function channelValidationStatusClass(status: string): string {
|
||||
}
|
||||
|
||||
export function channelValidationStatusIcon(status: string): ReactNode {
|
||||
if (status === "connected" || status === "configured") {
|
||||
if (status === "connected") {
|
||||
return <Check className="h-3.5 w-3.5" aria-hidden />;
|
||||
}
|
||||
if (status === "invalid") {
|
||||
@@ -111,34 +121,53 @@ export function CredentialForm({
|
||||
configuredFields,
|
||||
visibleSecrets,
|
||||
onChange,
|
||||
onFieldBlur,
|
||||
onToggleSecret,
|
||||
errors = {},
|
||||
clearedSecrets = new Set(),
|
||||
onClearSecret,
|
||||
compact = false,
|
||||
showSecretActions = false,
|
||||
disabled = false,
|
||||
}: {
|
||||
fields: ChannelConfigField[];
|
||||
values: Record<string, string>;
|
||||
configuredFields?: Set<string>;
|
||||
visibleSecrets: Record<string, boolean>;
|
||||
onChange: (key: string, value: string) => void;
|
||||
onFieldBlur?: (key: string) => void;
|
||||
onToggleSecret: (key: string) => void;
|
||||
errors?: Record<string, string>;
|
||||
clearedSecrets?: Set<string>;
|
||||
onClearSecret?: (key: string, clear: boolean) => void;
|
||||
compact?: boolean;
|
||||
showSecretActions?: boolean;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
return (
|
||||
<div className={cn(compact ? "space-y-2.5" : "mt-3 space-y-2.5")}>
|
||||
<div className={cn("grid", compact ? "gap-y-4" : "mt-3 gap-y-2.5")}>
|
||||
{fields.map((field) => {
|
||||
const inputId = channelFieldInputId(field.key);
|
||||
const error = errors[field.key];
|
||||
const errorId = error ? `${inputId}-error` : undefined;
|
||||
const describedBy = errorId;
|
||||
const visible = Boolean(visibleSecrets[field.key]);
|
||||
const value = values[field.key] ?? "";
|
||||
const savedSecret = Boolean(field.secret && configuredFields?.has(field.key) && !value.trim());
|
||||
const clearSecret = clearedSecrets.has(field.key);
|
||||
const savedSecret = Boolean(
|
||||
field.secret && configuredFields?.has(field.key) && !value.trim() && !clearSecret,
|
||||
);
|
||||
const showSecretToggle = Boolean(field.secret && value.trim());
|
||||
const inputType = field.secret && !visible ? "password" : field.inputType ?? "text";
|
||||
const selectedOption = channelFieldValue(field, values);
|
||||
const header = (
|
||||
<span className="flex items-center justify-between gap-2 text-[11px] font-medium text-foreground/85">
|
||||
<span>{field.label}</span>
|
||||
{savedSecret ? (
|
||||
<span className="font-normal text-muted-foreground">
|
||||
{tx("settings.channels.savedSecret", "Saved")}
|
||||
{clearSecret ? (
|
||||
<span className="font-normal text-destructive">
|
||||
{tx("settings.channels.secretWillBeRemoved", "Will be removed")}
|
||||
</span>
|
||||
) : field.optional && !compact ? (
|
||||
<span className="font-normal text-muted-foreground">
|
||||
@@ -147,48 +176,94 @@ export function CredentialForm({
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
const help = field.help ? (
|
||||
<span className="mt-1 block text-[11px] leading-4 text-muted-foreground">
|
||||
{field.help}
|
||||
const errorMessage = error ? (
|
||||
<span id={errorId} className="mt-1 block text-[11px] leading-4 text-destructive">
|
||||
{error}
|
||||
</span>
|
||||
) : null;
|
||||
if (field.options?.length) {
|
||||
return (
|
||||
<div key={field.key} className="block">
|
||||
{header}
|
||||
<fieldset
|
||||
key={field.key}
|
||||
id={`${inputId}-group`}
|
||||
aria-labelledby={`${inputId}-label`}
|
||||
aria-invalid={Boolean(error)}
|
||||
aria-describedby={describedBy}
|
||||
className="block"
|
||||
>
|
||||
<div className="grid grid-cols-[minmax(0,0.8fr)_minmax(0,1.2fr)] items-start gap-x-4">
|
||||
<span id={`${inputId}-label`} className="flex min-h-12 items-center sm:min-h-10">{header}</span>
|
||||
<div className="min-w-0">
|
||||
<span
|
||||
role="radiogroup"
|
||||
aria-label={field.label}
|
||||
className="mt-1 grid rounded-control bg-muted p-0.5 text-[12px] font-medium text-muted-foreground"
|
||||
className="grid rounded-control bg-muted p-0.5 text-[12px] font-medium text-muted-foreground"
|
||||
style={{ gridTemplateColumns: `repeat(${field.options.length}, minmax(0, 1fr))` }}
|
||||
>
|
||||
{field.options.map((option) => (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selectedOption === option.value}
|
||||
onClick={() => onChange(field.key, option.value)}
|
||||
className={cn(
|
||||
"min-h-8 rounded-compact px-2 py-1.5 transition-colors hover:text-foreground",
|
||||
selectedOption === option.value
|
||||
&& "bg-background text-foreground ring-1 ring-inset ring-border/45",
|
||||
)}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
{field.options.map((option, index) => (
|
||||
<label key={option.value} className="relative block">
|
||||
<input
|
||||
id={index === 0 ? inputId : `${inputId}-${index}`}
|
||||
type="radio"
|
||||
name={inputId}
|
||||
value={option.value}
|
||||
checked={selectedOption === option.value}
|
||||
disabled={disabled}
|
||||
aria-invalid={Boolean(error)}
|
||||
aria-describedby={describedBy}
|
||||
onChange={() => onChange(field.key, option.value)}
|
||||
onBlur={() => onFieldBlur?.(field.key)}
|
||||
className="peer sr-only"
|
||||
/>
|
||||
<span className="grid min-h-11 cursor-pointer place-items-center rounded-compact px-2 py-1.5 transition-colors hover:text-foreground peer-checked:bg-background peer-checked:text-foreground peer-checked:ring-1 peer-checked:ring-inset peer-checked:ring-border/45 peer-focus-visible:ring-2 peer-focus-visible:ring-ring sm:min-h-9">
|
||||
{option.label}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</span>
|
||||
{help}
|
||||
{errorMessage}
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
if (field.kind === "json") {
|
||||
return (
|
||||
<div key={field.key} className="grid grid-cols-[minmax(0,0.8fr)_minmax(0,1.2fr)] items-start gap-x-4">
|
||||
<label htmlFor={inputId} className="flex min-h-10 min-w-0 items-center self-start sm:min-h-9">
|
||||
{header}
|
||||
</label>
|
||||
<div className="min-w-0">
|
||||
<Textarea
|
||||
id={inputId}
|
||||
aria-label={field.label}
|
||||
aria-invalid={Boolean(error)}
|
||||
aria-describedby={describedBy}
|
||||
placeholder={field.placeholder}
|
||||
value={value}
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange(field.key, event.target.value)}
|
||||
onBlur={() => onFieldBlur?.(field.key)}
|
||||
rows={4}
|
||||
spellCheck={false}
|
||||
className={cn(
|
||||
"resize-y border-border/40 bg-background font-mono text-[12px]",
|
||||
error && "border-destructive focus-visible:ring-destructive/30",
|
||||
)}
|
||||
/>
|
||||
{errorMessage}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<label key={field.key} className="block">
|
||||
{header}
|
||||
<span className="relative mt-1 block">
|
||||
<div key={field.key} className="grid grid-cols-[minmax(0,0.8fr)_minmax(0,1.2fr)] items-start gap-x-4">
|
||||
<label htmlFor={inputId} className="flex min-h-10 min-w-0 items-center self-start sm:min-h-9">{header}</label>
|
||||
<div className="min-w-0">
|
||||
<span className="relative block">
|
||||
<Input
|
||||
id={inputId}
|
||||
aria-label={field.label}
|
||||
aria-invalid={Boolean(error)}
|
||||
aria-describedby={describedBy}
|
||||
type={inputType}
|
||||
autoComplete={field.secret ? "off" : undefined}
|
||||
inputMode={field.inputType === "number" ? "numeric" : undefined}
|
||||
@@ -198,9 +273,12 @@ export function CredentialForm({
|
||||
: field.placeholder
|
||||
}
|
||||
value={values[field.key] ?? ""}
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange(field.key, event.target.value)}
|
||||
onBlur={() => onFieldBlur?.(field.key)}
|
||||
className={cn(
|
||||
"h-9 rounded-full border-border/60 bg-muted/35 text-[13px]",
|
||||
"h-10 rounded-full border-border/40 bg-background text-base sm:h-9 sm:text-[13px]",
|
||||
error && "border-destructive focus-visible:ring-destructive/30",
|
||||
showSecretToggle && "pr-9",
|
||||
)}
|
||||
/>
|
||||
@@ -213,7 +291,8 @@ export function CredentialForm({
|
||||
: tx("settings.channels.showSecret", "Show secret")
|
||||
}
|
||||
onClick={() => onToggleSecret(field.key)}
|
||||
className="absolute right-2 top-1/2 grid h-6 w-6 -translate-y-1/2 place-items-center rounded-full text-muted-foreground settings-hover hover:text-foreground"
|
||||
disabled={disabled}
|
||||
className="absolute right-0 top-1/2 grid h-10 w-10 -translate-y-1/2 place-items-center rounded-full text-muted-foreground hover:bg-background hover:text-foreground sm:right-1 sm:h-8 sm:w-8"
|
||||
>
|
||||
{visible ? (
|
||||
<EyeOff className="h-3.5 w-3.5" aria-hidden />
|
||||
@@ -223,8 +302,21 @@ export function CredentialForm({
|
||||
</button>
|
||||
) : null}
|
||||
</span>
|
||||
{help}
|
||||
</label>
|
||||
{errorMessage}
|
||||
{showSecretActions && field.secret && configuredFields?.has(field.key) && !value.trim() && onClearSecret ? (
|
||||
<button
|
||||
type="button"
|
||||
className="mt-1 min-h-8 text-[11px] font-medium text-muted-foreground underline-offset-4 hover:text-foreground hover:underline"
|
||||
onClick={() => onClearSecret(field.key, !clearSecret)}
|
||||
disabled={disabled}
|
||||
>
|
||||
{clearSecret
|
||||
? tx("settings.channels.keepSavedSecret", "Keep saved credential")
|
||||
: tx("settings.channels.removeSavedSecret", "Remove saved credential")}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
import type { ComponentType } from "react";
|
||||
|
||||
export type ChannelPresentation = {
|
||||
displayName: string;
|
||||
initials: string;
|
||||
color: string;
|
||||
icon?: LucideIcon;
|
||||
icon?: ComponentType<{ className?: string; strokeWidth?: string | number }>;
|
||||
logoUrl?: string;
|
||||
setup?: ChannelCatalogSetupPresentation;
|
||||
};
|
||||
@@ -15,14 +15,13 @@ export type ChannelSetupPresentation = {
|
||||
command?: string;
|
||||
docsUrl?: string;
|
||||
docsLabel?: string;
|
||||
docsLogoUrl?: string;
|
||||
officialUrl?: string;
|
||||
officialLabel?: string;
|
||||
summary?: string;
|
||||
tryIt?: string;
|
||||
steps: string[];
|
||||
presetLabel?: string;
|
||||
sectionLabels?: Record<string, string>;
|
||||
fields?: ChannelConfigField[];
|
||||
manualFields?: ChannelConfigField[];
|
||||
requirements?: ChannelSetupRequirement[];
|
||||
actions?: ChannelSetupAction[];
|
||||
presets?: ChannelProviderPreset[];
|
||||
};
|
||||
@@ -31,15 +30,28 @@ type ChannelCatalogSetupPresentation = {
|
||||
mode?: "webui" | "credentials" | "connect";
|
||||
command?: string;
|
||||
docsUrl?: string;
|
||||
docsLogoUrl?: string;
|
||||
fields?: ChannelFieldPresentation[];
|
||||
manualFields?: ChannelFieldPresentation[];
|
||||
actions?: ChannelSetupActionDefinition[];
|
||||
presets?: ChannelProviderPresetDefinition[];
|
||||
};
|
||||
|
||||
type ChannelFieldPresentation = {
|
||||
export type ChannelFieldPresentation = {
|
||||
key: string;
|
||||
section?: string;
|
||||
};
|
||||
|
||||
export type ChannelFieldSection =
|
||||
| "account"
|
||||
| "credentials"
|
||||
| "connection"
|
||||
| "access"
|
||||
| "behavior"
|
||||
| "security"
|
||||
| "advanced";
|
||||
|
||||
export type ChannelSetupRequirement = {
|
||||
alternatives: string[][];
|
||||
};
|
||||
|
||||
type ChannelSetupActionDefinition = Omit<ChannelSetupAction, "label">;
|
||||
@@ -66,8 +78,9 @@ export type ChannelConfigField = {
|
||||
placeholder?: string;
|
||||
secret?: boolean;
|
||||
optional?: boolean;
|
||||
help?: string;
|
||||
inputType?: "text" | "number";
|
||||
inputType?: "text" | "number" | "url" | "email" | "tel";
|
||||
kind?: "string" | "secret" | "int" | "bool" | "list" | "enum" | string;
|
||||
section?: string;
|
||||
defaultValue?: string;
|
||||
options?: ChannelConfigOption[];
|
||||
};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
const messages: Record<string, string> = {
|
||||
"Connection verified.": "connected",
|
||||
"Configuration is present, but full verification was not possible.": "unverified",
|
||||
"Required setup is missing.": "missing",
|
||||
"Configuration was checked and looks invalid.": "invalid",
|
||||
"This channel is not supported by the WebUI setup checker.": "unsupported",
|
||||
"Configured.": "present",
|
||||
"Required.": "required",
|
||||
"This channel can be checked from saved fields, but not fully verified in-browser.": "manual",
|
||||
};
|
||||
|
||||
export function channelValidationMessage(message: string, t: TFunction): string {
|
||||
const key = messages[message];
|
||||
return key ? t(`settings.channels.validationMessages.${key}`, { defaultValue: message }) : message;
|
||||
}
|
||||
@@ -48,11 +48,13 @@ export function CapabilityInstallNotice({
|
||||
|
||||
export function NanobotFeatureInstallDialog({
|
||||
feature,
|
||||
installOnly = false,
|
||||
installing,
|
||||
onOpenChange,
|
||||
onConfirm,
|
||||
}: {
|
||||
feature: NanobotFeatureInfo | null;
|
||||
installOnly?: boolean;
|
||||
installing: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onConfirm: (feature: NanobotFeatureInfo) => void | Promise<void>;
|
||||
@@ -72,11 +74,17 @@ export function NanobotFeatureInstallDialog({
|
||||
{tx("settings.nanobotFeatures.installConfirmTitle", "Install support for {{name}}?", { name })}
|
||||
</DialogTitle>
|
||||
<DialogDescription className="mt-3 max-w-[20rem] text-center text-[14px] leading-6 text-muted-foreground">
|
||||
{tx(
|
||||
"settings.nanobotFeatures.installConfirmDescription",
|
||||
"nanobot will add what {{name}} needs, then turn it on. Continue?",
|
||||
{ name },
|
||||
)}
|
||||
{installOnly
|
||||
? tx(
|
||||
"settings.nanobotFeatures.installOnlyConfirmDescription",
|
||||
"nanobot will install what {{name}} needs. You can connect it after installation.",
|
||||
{ name },
|
||||
)
|
||||
: tx(
|
||||
"settings.nanobotFeatures.installConfirmDescription",
|
||||
"nanobot will add what {{name}} needs, then turn it on. Continue?",
|
||||
{ name },
|
||||
)}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter className="mt-7 !grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
@@ -96,7 +104,9 @@ export function NanobotFeatureInstallDialog({
|
||||
className="h-11 w-full min-w-0 !whitespace-normal px-5 text-center text-[15px] font-semibold"
|
||||
>
|
||||
{installing ? <Loader2 className="mr-2 h-4 w-4 animate-spin" aria-hidden /> : null}
|
||||
{tx("settings.nanobotFeatures.installConfirmAction", "Install and enable")}
|
||||
{installOnly
|
||||
? tx("settings.nanobotFeatures.installOnlyConfirmAction", "Install support")
|
||||
: tx("settings.nanobotFeatures.installConfirmAction", "Install and enable")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
@@ -117,6 +127,8 @@ export function DismissibleStatusMessage({
|
||||
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
|
||||
return (
|
||||
<div
|
||||
role={isError ? "alert" : "status"}
|
||||
aria-atomic="true"
|
||||
className={cn(
|
||||
"flex items-center justify-between gap-3 rounded-control border py-2.5 pl-4 pr-2 text-[13px]",
|
||||
isError
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import type { FormEvent, ReactNode } from "react";
|
||||
import type { TFunction } from "i18next";
|
||||
import {
|
||||
ArrowUpDown,
|
||||
Check,
|
||||
@@ -17,7 +18,8 @@ import {
|
||||
} from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { channelUiPresentation } from "@/channel-plugins/registry";
|
||||
import { channelTranslator } from "@/channel-plugins/i18n";
|
||||
import { channelUiOwner, channelUiPresentation } from "@/channel-plugins/registry";
|
||||
import { SETTINGS_SEARCH_INPUT_CLASS } from "@/components/settings/shared/SettingsControls";
|
||||
import { AppsActionButton } from "@/components/settings/system/AppsSettings";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -302,7 +304,7 @@ function AutomationListItem({
|
||||
const tx = (key: string, fallback: string, values?: Record<string, unknown>) =>
|
||||
t(key, { defaultValue: fallback, ...(values ?? {}) });
|
||||
const status = automationStatus(job, tx);
|
||||
const origin = automationOriginLabel(job, tx);
|
||||
const origin = automationOriginLabel(job, t);
|
||||
const nextRun = formatAutomationNext(job, tx);
|
||||
const summary = automationSummary(job, tx);
|
||||
|
||||
@@ -381,7 +383,7 @@ function AutomationDetailPanel({
|
||||
const tx = (key: string, fallback: string, values?: Record<string, unknown>) =>
|
||||
t(key, { defaultValue: fallback, ...(values ?? {}) });
|
||||
const status = automationStatus(job, tx);
|
||||
const origin = automationOriginLabel(job, tx);
|
||||
const origin = automationOriginLabel(job, t);
|
||||
const originHref = job.origin?.channel === "websocket" && job.origin.session_key
|
||||
? `#/chat/${encodeURIComponent(job.origin.session_key)}`
|
||||
: null;
|
||||
@@ -1358,23 +1360,27 @@ function automationStatus(
|
||||
|
||||
function automationOriginLabel(
|
||||
job: SessionAutomationJob,
|
||||
tx: (key: string, fallback: string, values?: Record<string, unknown>) => string,
|
||||
t: TFunction,
|
||||
): string {
|
||||
if (job.protected) return tx("settings.automations.origin.system", "System");
|
||||
if (job.protected) return t("settings.automations.origin.system", { defaultValue: "System" });
|
||||
const origin = job.origin;
|
||||
if (!origin) return tx("settings.automations.origin.unknown", "No linked chat");
|
||||
if (origin.channel !== "websocket") return automationChannelLabel(origin.channel, tx);
|
||||
return origin.title || origin.preview || origin.session_key || automationChannelLabel(origin.channel, tx);
|
||||
if (!origin) return t("settings.automations.origin.unknown", { defaultValue: "No linked chat" });
|
||||
if (origin.channel !== "websocket") return automationChannelLabel(origin.channel, t);
|
||||
return origin.title || origin.preview || origin.session_key || automationChannelLabel(origin.channel, t);
|
||||
}
|
||||
|
||||
function automationChannelLabel(
|
||||
channel: string,
|
||||
tx: (key: string, fallback: string, values?: Record<string, unknown>) => string,
|
||||
t: TFunction,
|
||||
): string {
|
||||
const key = channel.trim().toLowerCase();
|
||||
const displayName = automationChannelDisplayName(key);
|
||||
const presentation = channelUiPresentation(key);
|
||||
if (presentation) {
|
||||
return channelTranslator(t, channelUiOwner(key))("displayName", presentation.displayName);
|
||||
}
|
||||
const displayName = HOST_AUTOMATION_CHANNEL_LABELS[key];
|
||||
return displayName
|
||||
? tx(`settings.automations.channels.${key}`, displayName)
|
||||
? t(`settings.automations.channels.${key}`, { defaultValue: displayName })
|
||||
: channel;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
||||
import { Loader2, Search, X } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
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 { localizedChannelDisplayName } from "@/components/settings/channels/ChannelIdentity";
|
||||
import { ChannelHelpMenu } from "@/components/settings/channels/ChannelHelpMenu";
|
||||
import { ChannelCatalogRow, ChannelSetupPanel } from "@/components/settings/channels/ChannelSetupPanel";
|
||||
import { DismissibleStatusMessage, RestartRequiredNotice, SettingsGroup } from "@/components/settings/shared/SettingsControls";
|
||||
import type { NanobotFeaturesPayload } from "@/lib/types";
|
||||
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Dialog, DialogClose, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||
|
||||
type ChannelFilter = "all" | "enabled";
|
||||
|
||||
export function ChannelsSettings({
|
||||
token, nanobotFeatures, loading, actionKey, chatAppsDocsUrl, showBrandLogos,
|
||||
@@ -21,7 +28,7 @@ export function ChannelsSettings({
|
||||
showBrandLogos: boolean;
|
||||
error: string | null;
|
||||
requiresRestartPending: boolean;
|
||||
onAction: (action: "enable" | "disable", name: string) => void;
|
||||
onAction: ChannelFeatureAction;
|
||||
onFeaturesUpdate: (payload: NanobotFeaturesPayload) => void;
|
||||
onDismissStatus: () => void;
|
||||
onRestart?: () => void;
|
||||
@@ -29,19 +36,83 @@ export function ChannelsSettings({
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [selectedChannelName, setSelectedChannelName] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState("");
|
||||
const [filter, setFilter] = useState<ChannelFilter>("enabled");
|
||||
const [connectRequestId, setConnectRequestId] = useState(0);
|
||||
const filterInitializedRef = useRef(false);
|
||||
const triggerRef = useRef<HTMLElement | null>(null);
|
||||
const dialogRef = useRef<HTMLDivElement | null>(null);
|
||||
const beforeCloseRef = useRef<(() => Promise<boolean>) | null>(null);
|
||||
const closePendingRef = useRef(false);
|
||||
const channels = (nanobotFeatures?.features ?? [])
|
||||
.filter((feature) => feature.type === "channel" && feature.settings_visible !== false)
|
||||
.sort((left, right) => Number(!left.ready) - Number(!right.ready)
|
||||
|| localizedChannelDisplayName(left, t).localeCompare(localizedChannelDisplayName(right, t)));
|
||||
const hasEnabledChannels = channels.some((feature) => feature.enabled);
|
||||
const restartRequired = requiresRestartPending || Boolean(nanobotFeatures?.requires_restart);
|
||||
useLayoutEffect(() => {
|
||||
if (!nanobotFeatures || filterInitializedRef.current) return;
|
||||
filterInitializedRef.current = true;
|
||||
setFilter(hasEnabledChannels ? "enabled" : "all");
|
||||
}, [hasEnabledChannels, nanobotFeatures]);
|
||||
const visibleChannels = channels.filter((feature) =>
|
||||
(filter === "all" || feature.enabled)
|
||||
&& `${feature.name} ${localizedChannelDisplayName(feature, t)}`.toLocaleLowerCase()
|
||||
.includes(query.trim().toLocaleLowerCase()));
|
||||
const channelGroups = filter === "enabled"
|
||||
? [{ key: "enabled", label: null, channels: visibleChannels }]
|
||||
: [
|
||||
{
|
||||
key: "builtin",
|
||||
label: t("settings.channels.noInstallNeeded"),
|
||||
channels: visibleChannels.filter((feature) => !feature.requires_dependencies),
|
||||
},
|
||||
{
|
||||
key: "dependencies",
|
||||
label: t("settings.channels.installNeeded"),
|
||||
channels: visibleChannels.filter((feature) => feature.requires_dependencies),
|
||||
},
|
||||
].filter((group) => group.channels.length);
|
||||
const selectedChannel = channels.find((feature) => feature.name === selectedChannelName);
|
||||
const requestChannelClose = useCallback(() => {
|
||||
if (closePendingRef.current) return;
|
||||
const beforeClose = beforeCloseRef.current;
|
||||
if (!beforeClose) {
|
||||
setSelectedChannelName(null);
|
||||
return;
|
||||
}
|
||||
closePendingRef.current = true;
|
||||
void beforeClose().then((canClose) => {
|
||||
if (canClose) setSelectedChannelName(null);
|
||||
}).finally(() => {
|
||||
closePendingRef.current = false;
|
||||
});
|
||||
}, []);
|
||||
const setBeforeChannelClose = useCallback(
|
||||
(handler: (() => Promise<boolean>) | null) => { beforeCloseRef.current = handler; },
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="settings-stack">
|
||||
{error ? <DismissibleStatusMessage message={error} isError onDismiss={onDismissStatus} /> : null}
|
||||
{requiresRestartPending ? (
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||
<div className="relative min-w-0 flex-1">
|
||||
<Search className="pointer-events-none absolute start-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden />
|
||||
<Input type="search" value={query} onChange={(event) => setQuery(event.target.value)}
|
||||
aria-label={t("settings.channels.search")}
|
||||
placeholder={t("settings.channels.search")}
|
||||
className={`h-12 ps-11 text-[15px] ${SETTINGS_SEARCH_INPUT_CLASS}`} />
|
||||
</div>
|
||||
<SegmentedControl value={filter} onChange={(value) => {
|
||||
filterInitializedRef.current = true;
|
||||
setFilter(value);
|
||||
}} options={[
|
||||
{ value: "all", label: t("settings.channels.filterAll") },
|
||||
{ value: "enabled", label: t("settings.channels.filterEnabled") },
|
||||
]} />
|
||||
</div>
|
||||
{error && !selectedChannel ? <DismissibleStatusMessage message={error} isError onDismiss={onDismissStatus} /> : null}
|
||||
{restartRequired ? (
|
||||
<RestartRequiredNotice message={t("settings.channels.restartRequired")}
|
||||
onRestart={onRestart} isRestarting={isRestarting} />
|
||||
) : null}
|
||||
@@ -50,34 +121,62 @@ export function ChannelsSettings({
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" aria-hidden />
|
||||
{t("settings.channels.loading")}
|
||||
</div>
|
||||
) : channels.length ? (
|
||||
<SettingsGroup>
|
||||
{channels.map((feature) => (
|
||||
) : visibleChannels.length ? (
|
||||
channelGroups.map((group) => (
|
||||
<section
|
||||
key={group.key}
|
||||
aria-labelledby={group.label ? `channel-group-${group.key}` : undefined}
|
||||
aria-label={group.label ? undefined : t("settings.channels.filterEnabled")}
|
||||
className={group.label ? "space-y-2" : undefined}
|
||||
>
|
||||
{group.label ? (
|
||||
<h2 id={`channel-group-${group.key}`} className="px-4 text-[12px] font-medium text-muted-foreground">{group.label}</h2>
|
||||
) : null}
|
||||
<SettingsGroup>
|
||||
<div className="grid grid-cols-1 gap-x-4 gap-y-1 min-[640px]:grid-cols-2">
|
||||
{group.channels.map((feature) => (
|
||||
<ChannelCatalogRow key={feature.name} feature={feature} showBrandLogos={showBrandLogos}
|
||||
actionKey={actionKey} onAction={onAction}
|
||||
actionKey={actionKey} actionsDisabled={restartRequired || Boolean(isRestarting)} onAction={onAction}
|
||||
onSelect={(connect = false) => {
|
||||
triggerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
beforeCloseRef.current = null;
|
||||
setConnectRequestId(connect ? 1 : 0);
|
||||
setSelectedChannelName(feature.name);
|
||||
}} />
|
||||
))}
|
||||
</SettingsGroup>
|
||||
</div>
|
||||
</SettingsGroup>
|
||||
</section>
|
||||
))
|
||||
) : (
|
||||
<div className="px-3 py-12 text-center text-sm text-muted-foreground">
|
||||
{t("settings.channels.empty")}
|
||||
{t(channels.length ? "settings.channels.noResults" : "settings.channels.empty")}
|
||||
</div>
|
||||
)}
|
||||
<Dialog open={Boolean(selectedChannel)} onOpenChange={(open) => { if (!open) setSelectedChannelName(null); }}>
|
||||
<DialogContent ref={dialogRef} aria-describedby={undefined} className="max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-y-auto p-0 outline-none"
|
||||
<Dialog open={Boolean(selectedChannel)} onOpenChange={(open) => { if (!open) requestChannelClose(); }}>
|
||||
<DialogContent ref={dialogRef} showCloseButton={false} aria-describedby={undefined} className="max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-hidden p-0 outline-none"
|
||||
onOpenAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
dialogRef.current?.focus({ preventScroll: true });
|
||||
}}
|
||||
onCloseAutoFocus={(event) => { event.preventDefault(); triggerRef.current?.focus(); }}>
|
||||
<DialogTitle className="sr-only">{t("settings.nav.channels")}</DialogTitle>
|
||||
{selectedChannel ? <ChannelSetupPanel token={token} feature={selectedChannel} actionKey={actionKey}
|
||||
chatAppsDocsUrl={chatAppsDocsUrl} showBrandLogos={showBrandLogos}
|
||||
onAction={onAction} onFeaturesUpdate={onFeaturesUpdate} connectRequestId={connectRequestId} /> : null}
|
||||
<div className="max-h-[85dvh] min-h-0 overflow-y-auto overscroll-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||
<div className="relative">
|
||||
<div className="absolute end-6 top-6 z-10 flex h-10 items-center gap-1">
|
||||
{selectedChannel ? <ChannelHelpMenu feature={selectedChannel} chatAppsDocsUrl={chatAppsDocsUrl} /> : null}
|
||||
<DialogClose className="grid h-8 w-8 place-items-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring">
|
||||
<X className="h-4 w-4" aria-hidden />
|
||||
<span className="sr-only">{t("common.close")}</span>
|
||||
</DialogClose>
|
||||
</div>
|
||||
{error ? <DismissibleStatusMessage message={error} isError onDismiss={onDismissStatus} /> : null}
|
||||
{selectedChannel ? <ChannelSetupPanel token={token} feature={selectedChannel} actionKey={actionKey}
|
||||
showBrandLogos={showBrandLogos}
|
||||
onAction={onAction} onFeaturesUpdate={onFeaturesUpdate} connectRequestId={connectRequestId}
|
||||
onBeforeCloseChange={setBeforeChannelClose} /> : null}
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
@@ -98,6 +98,7 @@ export function createSystemSettingsActions({
|
||||
mcpOAuthFlowRef,
|
||||
mcpOAuthNavigatedUrlRef,
|
||||
mcpOAuthPopupRef,
|
||||
nanobotFeatureActionRef,
|
||||
nanobotFeatures,
|
||||
setApiService,
|
||||
setApiServiceAction,
|
||||
@@ -130,12 +131,26 @@ export function createSystemSettingsActions({
|
||||
setNanobotFeaturesError,
|
||||
} = state;
|
||||
|
||||
const beginNanobotFeatureAction = (key: string) => {
|
||||
if (nanobotFeatureActionRef.current) return false;
|
||||
nanobotFeatureActionRef.current = key;
|
||||
setNanobotFeatureAction(key);
|
||||
return true;
|
||||
};
|
||||
|
||||
const endNanobotFeatureAction = (key: string) => {
|
||||
if (nanobotFeatureActionRef.current !== key) return;
|
||||
nanobotFeatureActionRef.current = null;
|
||||
setNanobotFeatureAction(null);
|
||||
};
|
||||
|
||||
const installCapabilities = async (names: string[]): Promise<boolean> => {
|
||||
const missing = names.filter(
|
||||
(name) => !featureCatalog.find((feature) => feature.name === name)?.installed,
|
||||
);
|
||||
if (!missing.length) return true;
|
||||
setNanobotFeatureAction(`enable:${names.join("+")}`);
|
||||
const key = `enable:${names.join("+")}`;
|
||||
if (!beginNanobotFeatureAction(key)) return false;
|
||||
setNanobotFeaturesError(null);
|
||||
try {
|
||||
let latest = nanobotFeatures;
|
||||
@@ -151,7 +166,7 @@ export function createSystemSettingsActions({
|
||||
setNanobotFeaturesError((err as Error).message);
|
||||
return false;
|
||||
} finally {
|
||||
setNanobotFeatureAction(null);
|
||||
endNanobotFeatureAction(key);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -204,30 +219,42 @@ export function createSystemSettingsActions({
|
||||
const handleNanobotFeatureAction = async (
|
||||
action: "enable" | "disable",
|
||||
name: string,
|
||||
confirmed = false,
|
||||
options: { confirmed?: boolean; installOnly?: boolean } = {},
|
||||
) => {
|
||||
const feature = featureCatalog.find((item) => item.name === name);
|
||||
if (action === "enable" && !confirmed && feature && !feature.installed && feature.install_supported) {
|
||||
if (
|
||||
action === "enable"
|
||||
&& !options.confirmed
|
||||
&& feature
|
||||
&& !feature.installed
|
||||
&& feature.install_supported
|
||||
) {
|
||||
setNanobotFeaturesError(null);
|
||||
setNanobotFeatureConfirm(feature);
|
||||
setNanobotFeatureConfirm({ feature, installOnly: Boolean(options.installOnly) });
|
||||
return;
|
||||
}
|
||||
const key = `${action}:${name}`;
|
||||
setNanobotFeatureAction(key);
|
||||
const key = `${action === "enable" && options.installOnly ? "install" : action}:${name}`;
|
||||
if (!beginNanobotFeatureAction(key)) return;
|
||||
setNanobotFeatureConfirm(null);
|
||||
setNanobotFeaturesError(null);
|
||||
try {
|
||||
const payload = action === "enable"
|
||||
? await enableNanobotFeature(client, name)
|
||||
? await enableNanobotFeature(client, name, { installOnly: options.installOnly })
|
||||
: await disableNanobotFeature(client, name);
|
||||
setNanobotFeatures(payload);
|
||||
if (payload.requires_restart) {
|
||||
setPendingRestartSections((prev) => ({ ...prev, runtime: true }));
|
||||
}
|
||||
} catch (err) {
|
||||
setNanobotFeaturesError((err as Error).message);
|
||||
console.error("nanobot feature action failed", {
|
||||
action,
|
||||
name,
|
||||
installOnly: Boolean(options.installOnly),
|
||||
error: err,
|
||||
});
|
||||
setNanobotFeaturesError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setNanobotFeatureAction(null);
|
||||
endNanobotFeatureAction(key);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20,6 +20,11 @@ import type {
|
||||
SessionAutomationJob,
|
||||
} from "@/lib/types";
|
||||
|
||||
export type NanobotFeatureInstallRequest = {
|
||||
feature: NanobotFeatureInfo;
|
||||
installOnly: boolean;
|
||||
};
|
||||
|
||||
export function useSystemSettingsState() {
|
||||
const [cliApps, setCliApps] = useState<CliAppsPayload | null>(null);
|
||||
const [nanobotFeatures, setNanobotFeatures] = useState<NanobotFeaturesPayload | null>(null);
|
||||
@@ -31,7 +36,9 @@ export function useSystemSettingsState() {
|
||||
const [automationsLoading, setAutomationsLoading] = useState(false);
|
||||
const [cliAppsAction, setCliAppsAction] = useState<string | null>(null);
|
||||
const [nanobotFeatureAction, setNanobotFeatureAction] = useState<string | null>(null);
|
||||
const [nanobotFeatureConfirm, setNanobotFeatureConfirm] = useState<NanobotFeatureInfo | null>(null);
|
||||
const nanobotFeatureActionRef = useRef<string | null>(null);
|
||||
const [nanobotFeatureConfirm, setNanobotFeatureConfirm] =
|
||||
useState<NanobotFeatureInstallRequest | null>(null);
|
||||
const [mcpPresetAction, setMcpPresetAction] = useState<string | null>(null);
|
||||
const [mcpOAuthFlow, setMcpOAuthFlow] = useState<McpOAuthFlowPayload | null>(null);
|
||||
const mcpOAuthFlowRef = useRef<McpOAuthFlowPayload | null>(null);
|
||||
@@ -105,6 +112,7 @@ export function useSystemSettingsState() {
|
||||
mcpPresets,
|
||||
mcpPresetsLoading,
|
||||
nanobotFeatureAction,
|
||||
nanobotFeatureActionRef,
|
||||
nanobotFeatureConfirm,
|
||||
nanobotFeatures,
|
||||
nanobotFeaturesError,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { FloatingPortalContext } from "@/components/ui/floating-portal";
|
||||
|
||||
const Dialog = DialogPrimitive.Root;
|
||||
const DialogTrigger = DialogPrimitive.Trigger;
|
||||
const DialogClose = DialogPrimitive.Close;
|
||||
const DialogPortal = DialogPrimitive.Portal;
|
||||
export const DialogLayoutContext = React.createContext<HTMLElement | null>(null);
|
||||
|
||||
@@ -95,7 +96,7 @@ const DialogContent = React.forwardRef<
|
||||
{children}
|
||||
</FloatingPortalContext.Provider>
|
||||
{showCloseButton ? (
|
||||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none">
|
||||
<DialogPrimitive.Close className="absolute right-2.5 top-2.5 grid h-7 w-7 place-items-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground active:bg-muted/80 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">{t("common.close")}</span>
|
||||
</DialogPrimitive.Close>
|
||||
@@ -165,6 +166,7 @@ DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
||||
export {
|
||||
Dialog,
|
||||
DialogTrigger,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
|
||||
Reference in new issue
Block a user