refactor(extensions): use scoped pairing helper

This commit is contained in:
Peter Steinberger
2026-02-26 21:55:56 +01:00
parent 36b6ea1446
commit a0c5e28f3b
12 changed files with 135 additions and 32 deletions

View File

@@ -216,6 +216,7 @@ export {
type SenderGroupAccessReason,
} from "./group-access.js";
export { resolveSenderCommandAuthorization } from "./command-auth.js";
export { createScopedPairingAccess } from "./pairing-access.js";
export { handleSlackMessageAction } from "./slack-message-actions.js";
export { extractToolSend } from "./tool-send.js";
export {

View File

@@ -0,0 +1,36 @@
import type { ChannelId } from "../channels/plugins/types.js";
import type { PluginRuntime } from "../plugins/runtime/types.js";
import { normalizeAccountId } from "../routing/session-key.js";
type PairingApi = PluginRuntime["channel"]["pairing"];
type ScopedUpsertInput = Omit<
Parameters<PairingApi["upsertPairingRequest"]>[0],
"channel" | "accountId"
>;
export function createScopedPairingAccess(params: {
core: PluginRuntime;
channel: ChannelId;
accountId: string;
}) {
const resolvedAccountId = normalizeAccountId(params.accountId);
return {
accountId: resolvedAccountId,
readAllowFromStore: () =>
params.core.channel.pairing.readAllowFromStore({
channel: params.channel,
accountId: resolvedAccountId,
}),
readStoreForDmPolicy: (provider: ChannelId, accountId: string) =>
params.core.channel.pairing.readAllowFromStore({
channel: provider,
accountId: normalizeAccountId(accountId),
}),
upsertPairingRequest: (input: ScopedUpsertInput) =>
params.core.channel.pairing.upsertPairingRequest({
channel: params.channel,
accountId: resolvedAccountId,
...input,
}),
};
}