mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 08:58:37 +00:00
refactor: share onboarding secret prompt flows
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
import {
|
||||
buildSingleChannelSecretPromptState,
|
||||
formatDocsLink,
|
||||
hasConfiguredSecretInput,
|
||||
mapAllowFromEntries,
|
||||
mergeAllowFromEntries,
|
||||
patchScopedAccountConfig,
|
||||
promptSingleChannelSecretInput,
|
||||
runSingleChannelSecretStep,
|
||||
resolveAccountIdForConfigure,
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
normalizeAccountId,
|
||||
setTopLevelChannelDmPolicyWithAllowFrom,
|
||||
type SecretInput,
|
||||
type ChannelOnboardingAdapter,
|
||||
type ChannelOnboardingDmPolicy,
|
||||
type OpenClawConfig,
|
||||
@@ -190,12 +188,6 @@ export const nextcloudTalkOnboardingAdapter: ChannelOnboardingAdapter = {
|
||||
hasConfiguredSecretInput(resolvedAccount.config.botSecret) ||
|
||||
resolvedAccount.config.botSecretFile,
|
||||
);
|
||||
const secretPromptState = buildSingleChannelSecretPromptState({
|
||||
accountConfigured,
|
||||
hasConfigToken: hasConfigSecret,
|
||||
allowEnv,
|
||||
envValue: process.env.NEXTCLOUD_TALK_BOT_SECRET,
|
||||
});
|
||||
|
||||
let baseUrl = resolvedAccount.baseUrl;
|
||||
if (!baseUrl) {
|
||||
@@ -216,32 +208,35 @@ export const nextcloudTalkOnboardingAdapter: ChannelOnboardingAdapter = {
|
||||
).trim();
|
||||
}
|
||||
|
||||
let secret: SecretInput | null = null;
|
||||
if (!accountConfigured) {
|
||||
await noteNextcloudTalkSecretHelp(prompter);
|
||||
}
|
||||
|
||||
const secretResult = await promptSingleChannelSecretInput({
|
||||
const secretStep = await runSingleChannelSecretStep({
|
||||
cfg: next,
|
||||
prompter,
|
||||
providerHint: "nextcloud-talk",
|
||||
credentialLabel: "bot secret",
|
||||
accountConfigured: secretPromptState.accountConfigured,
|
||||
canUseEnv: secretPromptState.canUseEnv,
|
||||
hasConfigToken: secretPromptState.hasConfigToken,
|
||||
accountConfigured,
|
||||
hasConfigToken: hasConfigSecret,
|
||||
allowEnv,
|
||||
envValue: process.env.NEXTCLOUD_TALK_BOT_SECRET,
|
||||
envPrompt: "NEXTCLOUD_TALK_BOT_SECRET detected. Use env var?",
|
||||
keepPrompt: "Nextcloud Talk bot secret already configured. Keep it?",
|
||||
inputPrompt: "Enter Nextcloud Talk bot secret",
|
||||
preferredEnvVar: "NEXTCLOUD_TALK_BOT_SECRET",
|
||||
onMissingConfigured: async () => await noteNextcloudTalkSecretHelp(prompter),
|
||||
applyUseEnv: async (cfg) =>
|
||||
setNextcloudTalkAccountConfig(cfg as CoreConfig, accountId, {
|
||||
baseUrl,
|
||||
}),
|
||||
applySet: async (cfg, value) =>
|
||||
setNextcloudTalkAccountConfig(cfg as CoreConfig, accountId, {
|
||||
baseUrl,
|
||||
botSecret: value,
|
||||
}),
|
||||
});
|
||||
if (secretResult.action === "set") {
|
||||
secret = secretResult.value;
|
||||
}
|
||||
next = secretStep.cfg;
|
||||
|
||||
if (secretResult.action === "use-env" || secret || baseUrl !== resolvedAccount.baseUrl) {
|
||||
if (secretStep.action === "keep" && baseUrl !== resolvedAccount.baseUrl) {
|
||||
next = setNextcloudTalkAccountConfig(next, accountId, {
|
||||
baseUrl,
|
||||
...(secret ? { botSecret: secret } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -262,26 +257,28 @@ export const nextcloudTalkOnboardingAdapter: ChannelOnboardingAdapter = {
|
||||
validate: (value) => (String(value ?? "").trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
const apiPasswordResult = await promptSingleChannelSecretInput({
|
||||
const apiPasswordStep = await runSingleChannelSecretStep({
|
||||
cfg: next,
|
||||
prompter,
|
||||
providerHint: "nextcloud-talk-api",
|
||||
credentialLabel: "API password",
|
||||
...buildSingleChannelSecretPromptState({
|
||||
accountConfigured: Boolean(existingApiUser && existingApiPasswordConfigured),
|
||||
hasConfigToken: existingApiPasswordConfigured,
|
||||
allowEnv: false,
|
||||
}),
|
||||
accountConfigured: Boolean(existingApiUser && existingApiPasswordConfigured),
|
||||
hasConfigToken: existingApiPasswordConfigured,
|
||||
allowEnv: false,
|
||||
envPrompt: "",
|
||||
keepPrompt: "Nextcloud Talk API password already configured. Keep it?",
|
||||
inputPrompt: "Enter Nextcloud Talk API password",
|
||||
preferredEnvVar: "NEXTCLOUD_TALK_API_PASSWORD",
|
||||
applySet: async (cfg, value) =>
|
||||
setNextcloudTalkAccountConfig(cfg as CoreConfig, accountId, {
|
||||
apiUser,
|
||||
apiPassword: value,
|
||||
}),
|
||||
});
|
||||
const apiPassword = apiPasswordResult.action === "set" ? apiPasswordResult.value : undefined;
|
||||
next = setNextcloudTalkAccountConfig(next, accountId, {
|
||||
apiUser,
|
||||
...(apiPassword ? { apiPassword } : {}),
|
||||
});
|
||||
next =
|
||||
apiPasswordStep.action === "keep"
|
||||
? setNextcloudTalkAccountConfig(next, accountId, { apiUser })
|
||||
: apiPasswordStep.cfg;
|
||||
}
|
||||
|
||||
if (forceAllowFrom) {
|
||||
|
||||
Reference in New Issue
Block a user