import type { OpenClawConfig } from "../../config/config.js"; import type { ChannelSetupDmPolicy } from "./setup-wizard-types.js"; import type { ChannelSetupWizard } from "./setup-wizard.js"; type PromptAllowFromParams = Parameters>[0]; type ResolveAllowFromEntriesParams = Parameters< NonNullable["resolveEntries"] >[0]; type ResolveAllowFromEntriesResult = Awaited< ReturnType["resolveEntries"]> >; type ResolveGroupAllowlistParams = Parameters< NonNullable["resolveAllowlist"]> >[0]; export function createAllowlistSetupWizardProxy(params: { loadWizard: () => Promise; createBase: (handlers: { promptAllowFrom: (params: PromptAllowFromParams) => Promise; resolveAllowFromEntries: ( params: ResolveAllowFromEntriesParams, ) => Promise; resolveGroupAllowlist: (params: ResolveGroupAllowlistParams) => Promise; }) => ChannelSetupWizard; fallbackResolvedGroupAllowlist: (entries: string[]) => TGroupResolved; }) { return params.createBase({ promptAllowFrom: async ({ cfg, prompter, accountId }) => { const wizard = await params.loadWizard(); if (!wizard.dmPolicy?.promptAllowFrom) { return cfg; } return await wizard.dmPolicy.promptAllowFrom({ cfg, prompter, accountId }); }, resolveAllowFromEntries: async ({ cfg, accountId, credentialValues, entries }) => { const wizard = await params.loadWizard(); if (!wizard.allowFrom) { return entries.map((input) => ({ input, resolved: false, id: null })); } return await wizard.allowFrom.resolveEntries({ cfg, accountId, credentialValues, entries, }); }, resolveGroupAllowlist: async ({ cfg, accountId, credentialValues, entries, prompter }) => { const wizard = await params.loadWizard(); if (!wizard.groupAccess?.resolveAllowlist) { return params.fallbackResolvedGroupAllowlist(entries); } return (await wizard.groupAccess.resolveAllowlist({ cfg, accountId, credentialValues, entries, prompter, })) as TGroupResolved; }, }); }