refactor: dedupe extension trimmed readers

This commit is contained in:
Peter Steinberger
2026-04-08 01:07:11 +01:00
parent 08cee3316d
commit bf03babd2b
4 changed files with 60 additions and 48 deletions

View File

@@ -11,6 +11,10 @@ import {
formatDocsLink,
setSetupChannelEnabled,
} from "openclaw/plugin-sdk/setup";
import {
normalizeOptionalString,
normalizeStringifiedOptionalString,
} from "openclaw/plugin-sdk/text-runtime";
import { resolveDefaultIrcAccountId, resolveIrcAccount } from "./accounts.js";
import {
isChannelTarget,
@@ -96,7 +100,7 @@ async function promptIrcNickServConfig(params: {
await params.prompter.text({
message: "NickServ service nick",
initialValue: existing?.service || "NickServ",
validate: (value) => (String(value ?? "").trim() ? undefined : "Required"),
validate: (value) => (normalizeStringifiedOptionalString(value) ? undefined : "Required"),
}),
).trim();
@@ -139,7 +143,7 @@ async function promptIrcNickServConfig(params: {
(params.accountId === DEFAULT_ACCOUNT_ID
? process.env.IRC_NICKSERV_REGISTER_EMAIL
: undefined),
validate: (value) => (String(value ?? "").trim() ? undefined : "Required"),
validate: (value) => (normalizeStringifiedOptionalString(value) ? undefined : "Required"),
}),
).trim()
: undefined;
@@ -199,8 +203,8 @@ export const ircSetupWizard: ChannelSetupWizard = {
prepare: async ({ cfg, accountId, credentialValues, prompter }) => {
const resolved = resolveIrcAccount({ cfg: cfg as CoreConfig, accountId });
const isDefaultAccount = accountId === DEFAULT_ACCOUNT_ID;
const envHost = isDefaultAccount ? process.env.IRC_HOST?.trim() : "";
const envNick = isDefaultAccount ? process.env.IRC_NICK?.trim() : "";
const envHost = isDefaultAccount ? (normalizeOptionalString(process.env.IRC_HOST) ?? "") : "";
const envNick = isDefaultAccount ? (normalizeOptionalString(process.env.IRC_NICK) ?? "") : "";
const envReady = Boolean(envHost && envNick && !resolved.config.host && !resolved.config.nick);
if (envReady) {
@@ -243,8 +247,8 @@ export const ircSetupWizard: ChannelSetupWizard = {
currentValue: ({ cfg, accountId }) =>
resolveIrcAccount({ cfg: cfg as CoreConfig, accountId }).config.host || undefined,
shouldPrompt: ({ credentialValues }) => credentialValues[USE_ENV_FLAG] !== "1",
validate: ({ value }) => (String(value ?? "").trim() ? undefined : "Required"),
normalizeValue: ({ value }) => String(value).trim(),
validate: ({ value }) => (normalizeStringifiedOptionalString(value) ? undefined : "Required"),
normalizeValue: ({ value }) => normalizeStringifiedOptionalString(value) ?? "",
applySet: async ({ cfg, accountId, value }) =>
updateIrcAccountConfig(cfg as CoreConfig, accountId, {
enabled: true,
@@ -264,7 +268,7 @@ export const ircSetupWizard: ChannelSetupWizard = {
return String(defaultPort);
},
validate: ({ value }) => {
const parsed = Number.parseInt(String(value ?? "").trim(), 10);
const parsed = Number.parseInt(normalizeStringifiedOptionalString(value) ?? "", 10);
return Number.isFinite(parsed) && parsed >= 1 && parsed <= 65535
? undefined
: "Use a port between 1 and 65535";
@@ -282,8 +286,8 @@ export const ircSetupWizard: ChannelSetupWizard = {
currentValue: ({ cfg, accountId }) =>
resolveIrcAccount({ cfg: cfg as CoreConfig, accountId }).config.nick || undefined,
shouldPrompt: ({ credentialValues }) => credentialValues[USE_ENV_FLAG] !== "1",
validate: ({ value }) => (String(value ?? "").trim() ? undefined : "Required"),
normalizeValue: ({ value }) => String(value).trim(),
validate: ({ value }) => (normalizeStringifiedOptionalString(value) ? undefined : "Required"),
normalizeValue: ({ value }) => normalizeStringifiedOptionalString(value) ?? "",
applySet: async ({ cfg, accountId, value }) =>
updateIrcAccountConfig(cfg as CoreConfig, accountId, {
enabled: true,
@@ -300,8 +304,8 @@ export const ircSetupWizard: ChannelSetupWizard = {
resolveIrcAccount({ cfg: cfg as CoreConfig, accountId }).config.username ||
credentialValues.token ||
"openclaw",
validate: ({ value }) => (String(value ?? "").trim() ? undefined : "Required"),
normalizeValue: ({ value }) => String(value).trim(),
validate: ({ value }) => (normalizeStringifiedOptionalString(value) ? undefined : "Required"),
normalizeValue: ({ value }) => normalizeStringifiedOptionalString(value) ?? "",
applySet: async ({ cfg, accountId, value }) =>
updateIrcAccountConfig(cfg as CoreConfig, accountId, {
enabled: true,
@@ -316,8 +320,8 @@ export const ircSetupWizard: ChannelSetupWizard = {
shouldPrompt: ({ credentialValues }) => credentialValues[USE_ENV_FLAG] !== "1",
initialValue: ({ cfg, accountId }) =>
resolveIrcAccount({ cfg: cfg as CoreConfig, accountId }).config.realname || "OpenClaw",
validate: ({ value }) => (String(value ?? "").trim() ? undefined : "Required"),
normalizeValue: ({ value }) => String(value).trim(),
validate: ({ value }) => (normalizeStringifiedOptionalString(value) ? undefined : "Required"),
normalizeValue: ({ value }) => normalizeStringifiedOptionalString(value) ?? "",
applySet: async ({ cfg, accountId, value }) =>
updateIrcAccountConfig(cfg as CoreConfig, accountId, {
enabled: true,