From 33495f32e922068544c6e7d4a5d5019c547f64a1 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Mar 2026 17:56:23 -0700 Subject: [PATCH] refactor: expand setup wizard flow --- src/channels/plugins/setup-wizard.ts | 64 +++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/channels/plugins/setup-wizard.ts b/src/channels/plugins/setup-wizard.ts index b9dc4085dc4..f71d1802aa3 100644 --- a/src/channels/plugins/setup-wizard.ts +++ b/src/channels/plugins/setup-wizard.ts @@ -110,6 +110,7 @@ export type ChannelSetupWizardTextInput = { message: string; placeholder?: string; required?: boolean; + applyEmptyValue?: boolean; helpTitle?: string; helpLines?: string[]; confirmCurrentValue?: boolean; @@ -223,15 +224,40 @@ export type ChannelSetupWizardPrepare = (params: { credentialValues?: ChannelSetupWizardCredentialValues; } | void>; +export type ChannelSetupWizardFinalize = (params: { + cfg: OpenClawConfig; + accountId: string; + credentialValues: ChannelSetupWizardCredentialValues; + runtime: ChannelOnboardingConfigureContext["runtime"]; + prompter: WizardPrompter; + options?: ChannelOnboardingConfigureContext["options"]; + forceAllowFrom: boolean; +}) => + | { + cfg?: OpenClawConfig; + credentialValues?: ChannelSetupWizardCredentialValues; + } + | void + | Promise<{ + cfg?: OpenClawConfig; + credentialValues?: ChannelSetupWizardCredentialValues; + } | void>; + export type ChannelSetupWizard = { channel: string; status: ChannelSetupWizardStatus; introNote?: ChannelSetupWizardNote; envShortcut?: ChannelSetupWizardEnvShortcut; + resolveShouldPromptAccountIds?: (params: { + cfg: OpenClawConfig; + options?: ChannelOnboardingConfigureContext["options"]; + shouldPromptAccountIds: boolean; + }) => boolean; prepare?: ChannelSetupWizardPrepare; stepOrder?: "credentials-first" | "text-first"; credentials: ChannelSetupWizardCredential[]; textInputs?: ChannelSetupWizardTextInput[]; + finalize?: ChannelSetupWizardFinalize; completionNote?: ChannelSetupWizardNote; dmPolicy?: ChannelOnboardingDmPolicy; allowFrom?: ChannelSetupWizardAllowFrom; @@ -384,12 +410,18 @@ export function buildChannelOnboardingAdapterFromSetupWizard(params: { plugin.config.defaultAccountId?.(cfg) ?? plugin.config.listAccountIds(cfg)[0] ?? DEFAULT_ACCOUNT_ID; + const resolvedShouldPromptAccountIds = + wizard.resolveShouldPromptAccountIds?.({ + cfg, + options, + shouldPromptAccountIds, + }) ?? shouldPromptAccountIds; const accountId = await resolveAccountIdForConfigure({ cfg, prompter, label: plugin.meta.label, accountOverride: accountOverrides[plugin.id], - shouldPromptAccountIds, + shouldPromptAccountIds: resolvedShouldPromptAccountIds, listAccountIds: plugin.config.listAccountIds, defaultAccountId, }); @@ -650,6 +682,15 @@ export function buildChannelOnboardingAdapterFromSetupWizard(params: { ); const trimmedValue = rawValue.trim(); if (!trimmedValue && textInput.required === false) { + if (textInput.applyEmptyValue) { + next = await applyWizardTextInputValue({ + plugin, + input: textInput, + cfg: next, + accountId, + value: "", + }); + } delete credentialValues[textInput.inputKey]; continue; } @@ -761,6 +802,27 @@ export function buildChannelOnboardingAdapterFromSetupWizard(params: { }); } + if (wizard.finalize) { + const finalized = await wizard.finalize({ + cfg: next, + accountId, + credentialValues, + runtime, + prompter, + options, + forceAllowFrom, + }); + if (finalized?.cfg) { + next = finalized.cfg; + } + if (finalized?.credentialValues) { + credentialValues = { + ...credentialValues, + ...finalized.credentialValues, + }; + } + } + const shouldShowCompletionNote = wizard.completionNote && (wizard.completionNote.shouldShow