fix: honor nostr setup default account

This commit is contained in:
Tak Hoffman 2026-04-03 13:12:41 -05:00
parent 13bc70397a
commit a89cb679a2
No known key found for this signature in database
3 changed files with 18 additions and 5 deletions

View File

@ -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", () => {

View File

@ -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,

View File

@ -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,