refactor: expand setup wizard flow
This commit is contained in:
parent
da4f82503f
commit
33495f32e9
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user