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
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user