refactor: share onboarding account id resolution prelude

This commit is contained in:
Peter Steinberger
2026-03-07 20:54:47 +00:00
parent 168e4159ad
commit f0b05869fc
18 changed files with 105 additions and 117 deletions

View File

@@ -23,6 +23,10 @@ vi.mock("openclaw/plugin-sdk/bluebubbles", () => ({
);
},
mergeAllowFromEntries: (_existing: unknown, entries: string[]) => entries,
createAccountListHelpers: () => ({
listAccountIds: () => ["default"],
resolveDefaultAccountId: () => "default",
}),
normalizeSecretInputString: (value: unknown) => {
if (typeof value !== "string") {
return undefined;
@@ -33,6 +37,10 @@ vi.mock("openclaw/plugin-sdk/bluebubbles", () => ({
normalizeAccountId: (value?: string | null) =>
value && value.trim().length > 0 ? value : "default",
promptAccountId: vi.fn(),
resolveAccountIdForConfigure: async (params: {
accountOverride?: string;
defaultAccountId: string;
}) => params.accountOverride?.trim() || params.defaultAccountId,
}));
describe("bluebubbles onboarding SecretInput", () => {

View File

@@ -11,7 +11,7 @@ import {
formatDocsLink,
mergeAllowFromEntries,
normalizeAccountId,
promptAccountId,
resolveAccountIdForConfigure,
} from "openclaw/plugin-sdk/bluebubbles";
import {
listBlueBubblesAccountIds,
@@ -160,21 +160,16 @@ export const blueBubblesOnboardingAdapter: ChannelOnboardingAdapter = {
};
},
configure: async ({ cfg, prompter, accountOverrides, shouldPromptAccountIds }) => {
const blueBubblesOverride = accountOverrides.bluebubbles?.trim();
const defaultAccountId = resolveDefaultBlueBubblesAccountId(cfg);
let accountId = blueBubblesOverride
? normalizeAccountId(blueBubblesOverride)
: defaultAccountId;
if (shouldPromptAccountIds && !blueBubblesOverride) {
accountId = await promptAccountId({
cfg,
prompter,
label: "BlueBubbles",
currentId: accountId,
listAccountIds: listBlueBubblesAccountIds,
defaultAccountId,
});
}
const accountId = await resolveAccountIdForConfigure({
cfg,
prompter,
label: "BlueBubbles",
accountOverride: accountOverrides.bluebubbles,
shouldPromptAccountIds,
listAccountIds: listBlueBubblesAccountIds,
defaultAccountId,
});
let next = cfg;
const resolvedAccount = resolveBlueBubblesAccount({ cfg: next, accountId });