From a89cb679a239260ac5b6b8daee393de4bc221aa6 Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Fri, 3 Apr 2026 13:12:41 -0500 Subject: [PATCH] fix: honor nostr setup default account --- extensions/nostr/src/channel.test.ts | 10 ++++++++++ extensions/nostr/src/setup-surface.ts | 6 +++--- src/channels/plugins/setup-wizard-helpers.ts | 7 +++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/extensions/nostr/src/channel.test.ts b/extensions/nostr/src/channel.test.ts index 921f1ab128e..f4ba2f811fb 100644 --- a/extensions/nostr/src/channel.test.ts +++ b/extensions/nostr/src/channel.test.ts @@ -231,6 +231,16 @@ describe("nostr setup wizard", () => { expect(result.cfg.channels?.nostr?.defaultAccount).toBe("work"); expect(result.cfg.channels?.nostr?.privateKey).toBe(TEST_HEX_PRIVATE_KEY); }); + + it("uses configured defaultAccount when setup accountId is omitted", () => { + expect( + nostrPlugin.setup?.resolveAccountId?.({ + cfg: createConfiguredNostrCfg({ defaultAccount: "work" }) as OpenClawConfig, + accountId: undefined, + input: {}, + } as never), + ).toBe("work"); + }); }); describe("nostr account helpers", () => { diff --git a/extensions/nostr/src/setup-surface.ts b/extensions/nostr/src/setup-surface.ts index 83684d7ec03..ff6ff6510a4 100644 --- a/extensions/nostr/src/setup-surface.ts +++ b/extensions/nostr/src/setup-surface.ts @@ -19,7 +19,7 @@ import type { ChannelSetupWizard } from "openclaw/plugin-sdk/setup"; import { formatDocsLink } from "openclaw/plugin-sdk/setup"; import { DEFAULT_RELAYS } from "./default-relays.js"; import { getPublicKeyFromPrivate, normalizePubkey } from "./nostr-bus.js"; -import { resolveNostrAccount } from "./types.js"; +import { resolveDefaultNostrAccountId, resolveNostrAccount } from "./types.js"; const channel = "nostr" as const; @@ -77,7 +77,7 @@ function parseNostrAllowFrom(raw: string): { entries: string[]; error?: string } const promptNostrAllowFrom = createTopLevelChannelParsedAllowFromPrompt({ channel, - defaultAccountId: DEFAULT_ACCOUNT_ID, + defaultAccountId: resolveDefaultNostrAccountId, noteTitle: "Nostr allowlist", noteLines: NOSTR_ALLOW_FROM_HELP_LINES, message: "Nostr allowFrom", @@ -96,7 +96,7 @@ const nostrDmPolicy: ChannelSetupDmPolicy = createTopLevelChannelDmPolicy({ }); export const nostrSetupAdapter: ChannelSetupAdapter = { - resolveAccountId: ({ accountId }) => accountId?.trim() || DEFAULT_ACCOUNT_ID, + resolveAccountId: ({ cfg, accountId }) => accountId?.trim() || resolveDefaultNostrAccountId(cfg), applyAccountName: ({ cfg, accountId, name }) => patchTopLevelChannelConfigSection({ cfg, diff --git a/src/channels/plugins/setup-wizard-helpers.ts b/src/channels/plugins/setup-wizard-helpers.ts index 35d085170dd..683af8c5eb6 100644 --- a/src/channels/plugins/setup-wizard-helpers.ts +++ b/src/channels/plugins/setup-wizard-helpers.ts @@ -1310,7 +1310,7 @@ export async function promptParsedAllowFromForScopedChannel(params: { export function createTopLevelChannelParsedAllowFromPrompt(params: { channel: string; - defaultAccountId: string; + defaultAccountId: string | ((cfg: OpenClawConfig) => string); enabled?: boolean; noteTitle?: string; noteLines?: string[]; @@ -1325,7 +1325,10 @@ export function createTopLevelChannelParsedAllowFromPrompt(params: { ...(params.enabled ? { enabled: true } : {}), }); return createPromptParsedAllowFromForAccount({ - defaultAccountId: params.defaultAccountId, + defaultAccountId: + typeof params.defaultAccountId === "function" + ? params.defaultAccountId + : () => params.defaultAccountId, ...(params.noteTitle ? { noteTitle: params.noteTitle } : {}), ...(params.noteLines ? { noteLines: params.noteLines } : {}), message: params.message,